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

qfix: Use strict name comparison for nse/ns servers #1530

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions pkg/networkservice/common/netsvcmonitor/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ func (m *monitorServer) Request(ctx context.Context, request *networkservice.Net
break
}

// TODO: Remove this condition when https://github.com/networkservicemesh/api/issues/51 will be done
if netsvc.GetNetworkService().GetName() != conn.GetNetworkService() {
continue
}

nseStream, err := m.nseClient.Find(monitorCtx, &registry.NetworkServiceEndpointQuery{
NetworkServiceEndpoint: &registry.NetworkServiceEndpoint{
Name: conn.GetNetworkServiceEndpointName(),
Expand Down
6 changes: 4 additions & 2 deletions pkg/registry/common/connect/ns_server_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2020-2022 Doc.ai and/or its affiliates.
//
// Copyright (c) 2023 Cisco Systems, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -110,7 +112,7 @@ func startTestNSServers(ctx context.Context, t *testing.T) (url1, url2 *url.URL,
func TestConnectNSServer_AllUnregister(t *testing.T) {
t.Cleanup(func() { goleak.VerifyNone(t) })

ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
defer cancel()

url1, url2, cancel1, cancel2 := startTestNSServers(ctx, t)
Expand Down Expand Up @@ -147,7 +149,7 @@ func TestConnectNSServer_AllUnregister(t *testing.T) {

findSrv = streamchannel.NewNetworkServiceFindServer(clienturlctx.WithClientURL(ctx, url2), ch)
err = s.Find(&registry.NetworkServiceQuery{NetworkService: &registry.NetworkService{
Name: "ns-1",
Name: "ns-1-1",
}}, findSrv)
require.NoError(t, err)
require.Equal(t, (<-ch).NetworkService.Name, "ns-1-1")
Expand Down
6 changes: 4 additions & 2 deletions pkg/registry/common/connect/nse_server_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2020-2022 Doc.ai and/or its affiliates.
//
// Copyright (c) 2023 Cisco Systems, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -110,7 +112,7 @@ func startTestNSEServers(ctx context.Context, t *testing.T) (url1, url2 *url.URL
func TestConnectNSEServer_AllUnregister(t *testing.T) {
t.Cleanup(func() { goleak.VerifyNone(t) })

ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
defer cancel()

url1, url2, cancel1, cancel2 := startTestNSEServers(ctx, t)
Expand Down Expand Up @@ -147,7 +149,7 @@ func TestConnectNSEServer_AllUnregister(t *testing.T) {

findSrv = streamchannel.NewNetworkServiceEndpointFindServer(clienturlctx.WithClientURL(ctx, url2), ch)
err = s.Find(&registry.NetworkServiceEndpointQuery{NetworkServiceEndpoint: &registry.NetworkServiceEndpoint{
Name: "nse-1",
Name: "nse-1-1",
}}, findSrv)
require.NoError(t, err)
require.Equal(t, (<-ch).NetworkServiceEndpoint.Name, "nse-1-1")
Expand Down
6 changes: 4 additions & 2 deletions pkg/registry/common/memory/ns_server_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2020-2022 Doc.ai and/or its affiliates.
//
// Copyright (c) 2023 Cisco Systems, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -142,7 +144,7 @@ func TestNetworkServiceRegistryServer_DataRace(t *testing.T) {
go func() {
defer close(ch)
findErr := s.Find(&registry.NetworkServiceQuery{
NetworkService: &registry.NetworkService{Name: "ns"},
NetworkService: &registry.NetworkService{},
Watch: true,
}, streamchannel.NewNetworkServiceFindServer(findCtx, ch))
assert.NoError(t, findErr)
Expand Down Expand Up @@ -185,7 +187,7 @@ func TestNetworkServiceRegistryServer_SlowReceiver(t *testing.T) {
go func() {
defer close(ch)
findErr := s.Find(&registry.NetworkServiceQuery{
NetworkService: &registry.NetworkService{Name: "ns"},
NetworkService: &registry.NetworkService{},
Watch: true,
}, streamchannel.NewNetworkServiceFindServer(findCtx, ch))
require.NoError(t, findErr)
Expand Down
6 changes: 4 additions & 2 deletions pkg/registry/common/memory/nse_server_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2020-2022 Doc.ai and/or its affiliates.
//
// Copyright (c) 2023 Cisco Systems, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -212,7 +214,7 @@ func TestNetworkServiceEndpointRegistryServer_DataRace(t *testing.T) {
go func() {
defer close(ch)
findErr := s.Find(&registry.NetworkServiceEndpointQuery{
NetworkServiceEndpoint: &registry.NetworkServiceEndpoint{Name: "nse"},
NetworkServiceEndpoint: &registry.NetworkServiceEndpoint{},
Watch: true,
}, streamchannel.NewNetworkServiceEndpointFindServer(findCtx, ch))
assert.NoError(t, findErr)
Expand Down Expand Up @@ -255,7 +257,7 @@ func TestNetworkServiceEndpointRegistryServer_SlowReceiver(t *testing.T) {
go func() {
defer close(ch)
findErr := s.Find(&registry.NetworkServiceEndpointQuery{
NetworkServiceEndpoint: &registry.NetworkServiceEndpoint{Name: "nse"},
NetworkServiceEndpoint: &registry.NetworkServiceEndpoint{},
Watch: true,
}, streamchannel.NewNetworkServiceEndpointFindServer(findCtx, ch))
require.NoError(t, findErr)
Expand Down
4 changes: 2 additions & 2 deletions pkg/tools/matchutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ func MatchEndpoint(nsLabels map[string]string, ns *registry.NetworkService, nses

// MatchNetworkServices returns true if two network services are matched
func MatchNetworkServices(left, right *registry.NetworkService) bool {
return (left.Name == "" || strings.Contains(right.Name, left.Name)) &&
return (left.Name == "" || right.Name == left.Name) &&
(left.Payload == "" || left.Payload == right.Payload) &&
(left.Matches == nil || cmp.Equal(left.Matches, right.Matches, cmp.Comparer(proto.Equal)))
}

// MatchNetworkServiceEndpoints returns true if two network service endpoints are matched
func MatchNetworkServiceEndpoints(left, right *registry.NetworkServiceEndpoint) bool {
return (left.Name == "" || strings.Contains(right.Name, left.Name)) &&
return (left.Name == "" || right.Name == left.Name) &&
(left.NetworkServiceLabels == nil || labelsContains(right.NetworkServiceLabels, left.NetworkServiceLabels)) &&
(left.ExpirationTime == nil || left.ExpirationTime.Seconds == right.ExpirationTime.Seconds) &&
(left.NetworkServiceNames == nil || contains(right.NetworkServiceNames, left.NetworkServiceNames)) &&
Expand Down
16 changes: 2 additions & 14 deletions pkg/tools/matchutils/utils_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2020-2021 Doc.ai and/or its affiliates.
//
// Copyright (c) 2023 Cisco Systems, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -71,13 +73,6 @@ func TestNSMatch(t *testing.T) {
},
want: true,
},
{
name: "matchNameSubstring",
svc: &registry.NetworkService{
Name: "substring-match",
},
want: true,
},
{
name: "noMatchName",
svc: &registry.NetworkService{
Expand Down Expand Up @@ -185,13 +180,6 @@ func TestNSEMatch(t *testing.T) {
},
want: true,
},
{
name: "matchNameSubstring",
endpoint: &registry.NetworkServiceEndpoint{
Name: "substring-match",
},
want: true,
},
{
name: "noMatchName",
endpoint: &registry.NetworkServiceEndpoint{
Expand Down
Loading