diff --git a/pkg/networkservice/common/netsvcmonitor/server.go b/pkg/networkservice/common/netsvcmonitor/server.go index b5bbb14c0..5c75f92a9 100644 --- a/pkg/networkservice/common/netsvcmonitor/server.go +++ b/pkg/networkservice/common/netsvcmonitor/server.go @@ -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, ®istry.NetworkServiceEndpointQuery{ NetworkServiceEndpoint: ®istry.NetworkServiceEndpoint{ Name: conn.GetNetworkServiceEndpointName(), diff --git a/pkg/registry/common/connect/ns_server_test.go b/pkg/registry/common/connect/ns_server_test.go index d0968fd46..f2fde5138 100644 --- a/pkg/registry/common/connect/ns_server_test.go +++ b/pkg/registry/common/connect/ns_server_test.go @@ -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"); @@ -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) @@ -147,7 +149,7 @@ func TestConnectNSServer_AllUnregister(t *testing.T) { findSrv = streamchannel.NewNetworkServiceFindServer(clienturlctx.WithClientURL(ctx, url2), ch) err = s.Find(®istry.NetworkServiceQuery{NetworkService: ®istry.NetworkService{ - Name: "ns-1", + Name: "ns-1-1", }}, findSrv) require.NoError(t, err) require.Equal(t, (<-ch).NetworkService.Name, "ns-1-1") diff --git a/pkg/registry/common/connect/nse_server_test.go b/pkg/registry/common/connect/nse_server_test.go index 6a3ce5a99..e087a638d 100644 --- a/pkg/registry/common/connect/nse_server_test.go +++ b/pkg/registry/common/connect/nse_server_test.go @@ -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"); @@ -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) @@ -147,7 +149,7 @@ func TestConnectNSEServer_AllUnregister(t *testing.T) { findSrv = streamchannel.NewNetworkServiceEndpointFindServer(clienturlctx.WithClientURL(ctx, url2), ch) err = s.Find(®istry.NetworkServiceEndpointQuery{NetworkServiceEndpoint: ®istry.NetworkServiceEndpoint{ - Name: "nse-1", + Name: "nse-1-1", }}, findSrv) require.NoError(t, err) require.Equal(t, (<-ch).NetworkServiceEndpoint.Name, "nse-1-1") diff --git a/pkg/registry/common/memory/ns_server_test.go b/pkg/registry/common/memory/ns_server_test.go index e43f33ff5..e5aea9860 100644 --- a/pkg/registry/common/memory/ns_server_test.go +++ b/pkg/registry/common/memory/ns_server_test.go @@ -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"); @@ -142,7 +144,7 @@ func TestNetworkServiceRegistryServer_DataRace(t *testing.T) { go func() { defer close(ch) findErr := s.Find(®istry.NetworkServiceQuery{ - NetworkService: ®istry.NetworkService{Name: "ns"}, + NetworkService: ®istry.NetworkService{}, Watch: true, }, streamchannel.NewNetworkServiceFindServer(findCtx, ch)) assert.NoError(t, findErr) @@ -185,7 +187,7 @@ func TestNetworkServiceRegistryServer_SlowReceiver(t *testing.T) { go func() { defer close(ch) findErr := s.Find(®istry.NetworkServiceQuery{ - NetworkService: ®istry.NetworkService{Name: "ns"}, + NetworkService: ®istry.NetworkService{}, Watch: true, }, streamchannel.NewNetworkServiceFindServer(findCtx, ch)) require.NoError(t, findErr) diff --git a/pkg/registry/common/memory/nse_server_test.go b/pkg/registry/common/memory/nse_server_test.go index 0c860abf0..9c49baf55 100644 --- a/pkg/registry/common/memory/nse_server_test.go +++ b/pkg/registry/common/memory/nse_server_test.go @@ -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"); @@ -212,7 +214,7 @@ func TestNetworkServiceEndpointRegistryServer_DataRace(t *testing.T) { go func() { defer close(ch) findErr := s.Find(®istry.NetworkServiceEndpointQuery{ - NetworkServiceEndpoint: ®istry.NetworkServiceEndpoint{Name: "nse"}, + NetworkServiceEndpoint: ®istry.NetworkServiceEndpoint{}, Watch: true, }, streamchannel.NewNetworkServiceEndpointFindServer(findCtx, ch)) assert.NoError(t, findErr) @@ -255,7 +257,7 @@ func TestNetworkServiceEndpointRegistryServer_SlowReceiver(t *testing.T) { go func() { defer close(ch) findErr := s.Find(®istry.NetworkServiceEndpointQuery{ - NetworkServiceEndpoint: ®istry.NetworkServiceEndpoint{Name: "nse"}, + NetworkServiceEndpoint: ®istry.NetworkServiceEndpoint{}, Watch: true, }, streamchannel.NewNetworkServiceEndpointFindServer(findCtx, ch)) require.NoError(t, findErr) diff --git a/pkg/tools/matchutils/utils.go b/pkg/tools/matchutils/utils.go index 45fb5ebbc..b4ba8fbfa 100644 --- a/pkg/tools/matchutils/utils.go +++ b/pkg/tools/matchutils/utils.go @@ -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)) && diff --git a/pkg/tools/matchutils/utils_test.go b/pkg/tools/matchutils/utils_test.go index bfcf85331..c05e1154e 100644 --- a/pkg/tools/matchutils/utils_test.go +++ b/pkg/tools/matchutils/utils_test.go @@ -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"); @@ -71,13 +73,6 @@ func TestNSMatch(t *testing.T) { }, want: true, }, - { - name: "matchNameSubstring", - svc: ®istry.NetworkService{ - Name: "substring-match", - }, - want: true, - }, { name: "noMatchName", svc: ®istry.NetworkService{ @@ -185,13 +180,6 @@ func TestNSEMatch(t *testing.T) { }, want: true, }, - { - name: "matchNameSubstring", - endpoint: ®istry.NetworkServiceEndpoint{ - Name: "substring-match", - }, - want: true, - }, { name: "noMatchName", endpoint: ®istry.NetworkServiceEndpoint{