-
Notifications
You must be signed in to change notification settings - Fork 36
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
Conversation
ac31b7c
to
b95073d
Compare
Hi @edwarnicke , 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? |
There was a problem hiding this 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{} | ||
} | ||
|
There was a problem hiding this comment.
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")
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.FromContext(ctx).Debugf("ExcludedPrefixesClient: adding new excluded IPs to the request: %v", epc.excludedPrefixes) | |
logger..Debugf("adding new excluded IPs %+v", epc.excludedPrefixes) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Let me summarize the use-case with a buggy endpoint:
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>
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-- | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this public?
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this public?
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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>
srcIPs []string | ||
dstIPs []string | ||
srcRoutes []*networkservice.Route | ||
dstRoutes []*networkservice.Route |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
srcIPs []string | |
dstIPs []string | |
srcRoutes []*networkservice.Route | |
dstRoutes []*networkservice.Route | |
ipContext networkservice.IPContext |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func NewServer(srcIPs, dstIPs []string, srcRoutes, dstRoutes []*networkservice.Route) networkservice.NetworkServiceServer { | |
func NewServer(ipContext networkservice.IPContext) networkservice.NetworkServiceServer { |
There was a problem hiding this comment.
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>
…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>
…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>
…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>
…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>
…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>
…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>
…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>
…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>
…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>
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?
Types of changes