Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added chain element that excludes already used prefixes #1197

Merged
merged 7 commits into from
Dec 21, 2021

Conversation

sol-0
Copy link
Contributor

@sol-0 sol-0 commented Dec 10, 2021

Signed-off-by: Oleg Solodkov oleg.solodkov@xored.com

Description

Added client chain element that excludes prefixes already used by other network services

Issue link

Fixes #1188

How Has This Been Tested?

  • Added unit testing to cover
  • Tested manually
  • Tested by integration testing
  • Have not tested

Types of changes

  • Bug fix
  • New functionallity
  • Documentation
  • Refactoring
  • CI

@sol-0 sol-0 force-pushed the feature-1188 branch 2 times, most recently from ac31b7c to b95073d Compare December 10, 2021 17:20
@sol-0
Copy link
Contributor Author

sol-0 commented Dec 10, 2021

Hi @edwarnicke ,
This is a suggested solution for #1188, could you please take a look and share your thoughts?

Also you mentioned that endpoints might be buggy in the issue discussion, could you please elaborate more on that?

@edwarnicke
Copy link
Member

Hi @edwarnicke , This is a suggested solution for #1188, could you please take a look and share your thoughts?

Also you mentioned that endpoints might be buggy in the issue discussion, could you please elaborate more on that?

Sure. Say an endpoint receives a set of exclude prefixes. The endpoint shouldn't set Src/Dst IP addresses Routes with Dst prefixes that conflict with those exclude prefixes. But what if it does? What happens then?

@sol-0 sol-0 marked this pull request as ready for review December 13, 2021 08:19
Copy link
Member

@denis-tingaikin denis-tingaikin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks about correct,

I think we need to test it on integration tests and also consider a case with a buggy endpoint as @edwarnicke pointed.

if conn.GetContext().GetIpContext() == nil {
conn.Context.IpContext = &networkservice.IPContext{}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logger = logger.FromContext(ctx).WithField("ExcludedPrefixesClient", "Request")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


if len(epc.excludedPrefixes) > 0 {
<-epc.executor.AsyncExec(func() {
log.FromContext(ctx).Debugf("ExcludedPrefixesClient: adding new excluded IPs to the request: %v", epc.excludedPrefixes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.FromContext(ctx).Debugf("ExcludedPrefixesClient: adding new excluded IPs to the request: %v", epc.excludedPrefixes)
logger..Debugf("adding new excluded IPs %+v", epc.excludedPrefixes)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apply this for similar places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@sol-0
Copy link
Contributor Author

sol-0 commented Dec 13, 2021

Hi @edwarnicke , This is a suggested solution for #1188, could you please take a look and share your thoughts?
Also you mentioned that endpoints might be buggy in the issue discussion, could you please elaborate more on that?

Sure. Say an endpoint receives a set of exclude prefixes. The endpoint shouldn't set Src/Dst IP addresses Routes with Dst prefixes that conflict with those exclude prefixes. But what if it does? What happens then?

@edwarnicke,

Let me summarize the use-case with a buggy endpoint:

  1. We have endpoint A, it has CIDR from env and optional excluded prefixes from a file.
  2. Client makes the first request to endpoint A, gets src/dst IPs allocated by IPAM and optional excluded prefixes; client saves this info using new chain element.
  3. Client makes the second request to endpoint B and adds prefixes saved on step 2 as ExcludedPrefixes for this new request.
  4. If endpoint B is incorrectly configured and it's not using our IPAM, then it might return the same/conflicting IPs.
    • actual: we'll create interfaces with conflicting IPs
    • expected: should we check that in our element, return an error and not create an interface in this case?

Is my understanding correct?

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>
Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>
Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>
Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>
Comment on lines 40 to 48
for i := 0; i < len(source); i++ {
prefix = source[i]
for _, ipCtxPrefix := range exclude {
if prefix == ipCtxPrefix {
source = append(source[:i], source[i+1:]...)
i--
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the map[string]struct{} and reduce the time complexity from O(n*m) to O(n + m)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -18,7 +18,8 @@

package excludedprefixes

func removeDuplicates(elements []string) []string {
// RemoveDuplicates - removes duplicate strings from a slice
func RemoveDuplicates(elements []string) []string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this public?

Copy link
Contributor Author

@sol-0 sol-0 Dec 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was made public to avoid code duplication in test code. Shall we move this to tools?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

@@ -31,3 +32,20 @@ func removeDuplicates(elements []string) []string {
}
return result
}

// Exclude - excludes strings from a slice
func Exclude(source, exclude []string) []string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this public?

Copy link
Contributor Author

@sol-0 sol-0 Dec 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was made public to avoid code duplication in test code. Shall we move this to tools?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

// See the License for the specific language governing permissions and
// limitations under the License.

package injectipam
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

Can we use in tests point2pointipam?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This element emulates a buggy endpoint issuing IPs/routes conflicting with already existing IPs/routes/excluded prefixes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I see. Can we rework it to injectipcontext?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>
Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>
Comment on lines 29 to 32
srcIPs []string
dstIPs []string
srcRoutes []*networkservice.Route
dstRoutes []*networkservice.Route
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
srcIPs []string
dstIPs []string
srcRoutes []*networkservice.Route
dstRoutes []*networkservice.Route
ipContext networkservice.IPContext

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

// NewServer - creates a networkservice.NetworkServiceServer chain element injecting specified routes/IPs on Request into IP context
func NewServer(srcIPs, dstIPs []string, srcRoutes, dstRoutes []*networkservice.Route) networkservice.NetworkServiceServer {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func NewServer(srcIPs, dstIPs []string, srcRoutes, dstRoutes []*networkservice.Route) networkservice.NetworkServiceServer {
func NewServer(ipContext networkservice.IPContext) networkservice.NetworkServiceServer {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>
@denis-tingaikin denis-tingaikin merged commit 218e633 into networkservicemesh:main Dec 21, 2021
nsmbot pushed a commit to networkservicemesh/cmd-nsmgr-proxy that referenced this pull request Dec 21, 2021
…k@main

PR link: networkservicemesh/sdk#1197

Commit: 218e633
Author: Sol-0
Date: 2021-12-21 15:36:53 +0700
Message:
  - Added chain element that excludes already used prefixes (#1197)
* Added client chain element that excludes already used prefixes

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Added IPs/routes validation

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-admission-webhook-k8s that referenced this pull request Dec 21, 2021
…k@main

PR link: networkservicemesh/sdk#1197

Commit: 218e633
Author: Sol-0
Date: 2021-12-21 15:36:53 +0700
Message:
  - Added chain element that excludes already used prefixes (#1197)
* Added client chain element that excludes already used prefixes

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Added IPs/routes validation

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/sdk-kernel that referenced this pull request Dec 21, 2021
…k@main

PR link: networkservicemesh/sdk#1197

Commit: 218e633
Author: Sol-0
Date: 2021-12-21 15:36:53 +0700
Message:
  - Added chain element that excludes already used prefixes (#1197)
* Added client chain element that excludes already used prefixes

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Added IPs/routes validation

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-registry-memory that referenced this pull request Dec 21, 2021
…k@main

PR link: networkservicemesh/sdk#1197

Commit: 218e633
Author: Sol-0
Date: 2021-12-21 15:36:53 +0700
Message:
  - Added chain element that excludes already used prefixes (#1197)
* Added client chain element that excludes already used prefixes

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Added IPs/routes validation

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-nsc-init that referenced this pull request Dec 21, 2021
…k@main

PR link: networkservicemesh/sdk#1197

Commit: 218e633
Author: Sol-0
Date: 2021-12-21 15:36:53 +0700
Message:
  - Added chain element that excludes already used prefixes (#1197)
* Added client chain element that excludes already used prefixes

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Added IPs/routes validation

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/sdk-k8s that referenced this pull request Dec 21, 2021
…k@main

PR link: networkservicemesh/sdk#1197

Commit: 218e633
Author: Sol-0
Date: 2021-12-21 15:36:53 +0700
Message:
  - Added chain element that excludes already used prefixes (#1197)
* Added client chain element that excludes already used prefixes

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Added IPs/routes validation

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-registry-proxy-dns that referenced this pull request Dec 21, 2021
…k@main

PR link: networkservicemesh/sdk#1197

Commit: 218e633
Author: Sol-0
Date: 2021-12-21 15:36:53 +0700
Message:
  - Added chain element that excludes already used prefixes (#1197)
* Added client chain element that excludes already used prefixes

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Added IPs/routes validation

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-nsmgr that referenced this pull request Dec 21, 2021
…k@main

PR link: networkservicemesh/sdk#1197

Commit: 218e633
Author: Sol-0
Date: 2021-12-21 15:36:53 +0700
Message:
  - Added chain element that excludes already used prefixes (#1197)
* Added client chain element that excludes already used prefixes

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Added IPs/routes validation

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-nse-vfio that referenced this pull request Dec 21, 2021
…k@main

PR link: networkservicemesh/sdk#1197

Commit: 218e633
Author: Sol-0
Date: 2021-12-21 15:36:53 +0700
Message:
  - Added chain element that excludes already used prefixes (#1197)
* Added client chain element that excludes already used prefixes

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Added IPs/routes validation

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exclude prefixes already in use in a POD by other Network Services
3 participants