Skip to content

Commit

Permalink
fix: Filter mechanism chain element works incorrectly in remote case (n…
Browse files Browse the repository at this point in the history
…etworkservicemesh#576)

* Revert "fix: Filter mechanism chain element works incorrectly in remote case (networkservicemesh#575)"

This reverts commit 39537ac.

Signed-off-by: denis-tingajkin <denis.tingajkin@xored.com>

* Fix 573

Signed-off-by: denis-tingajkin <denis.tingajkin@xored.com>

* fix typo

Signed-off-by: denis-tingajkin <denis.tingajkin@xored.com>
Signed-off-by: Sergey Ershov <sergey.ershov@xored.com>
  • Loading branch information
denis-tingaikin authored and Sergey Ershov committed Dec 23, 2020
1 parent 6ff4d56 commit c778e05
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 302 deletions.
94 changes: 0 additions & 94 deletions pkg/networkservice/common/filtermechanisms/README.md

This file was deleted.

23 changes: 0 additions & 23 deletions pkg/networkservice/common/filtermechanisms/const.go

This file was deleted.

27 changes: 0 additions & 27 deletions pkg/networkservice/common/filtermechanisms/options.go

This file was deleted.

26 changes: 10 additions & 16 deletions pkg/networkservice/common/filtermechanisms/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ package filtermechanisms
import (
"context"

"github.com/networkservicemesh/sdk/pkg/registry/common/interpose"

"github.com/networkservicemesh/sdk/pkg/tools/clienturlctx"

"github.com/golang/protobuf/ptypes/empty"
Expand All @@ -33,30 +35,22 @@ import (
)

type filterMechanismsServer struct {
urls endpointurls.Set
localThreshold int
nses endpointurls.Map
}

// NewServer - filters out remote mechanisms if connection is received from a unix file socket, otherwise filters
// out local mechanisms.
func NewServer(registryServer *registry.NetworkServiceEndpointRegistryServer, options ...Option) networkservice.NetworkServiceServer {
result := &filterMechanismsServer{
localThreshold: defaultThreshold,
}
for _, applyOption := range options {
applyOption(result)
}
*registryServer = endpointurls.NewNetworkServiceEndpointRegistryServer(&result.urls)
// out local mechanisms
func NewServer(registryServer *registry.NetworkServiceEndpointRegistryServer) networkservice.NetworkServiceServer {
result := &filterMechanismsServer{}
*registryServer = endpointurls.NewNetworkServiceEndpointRegistryServer(&result.nses)
return result
}

func (f *filterMechanismsServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) {
u := clienturlctx.ClientURL(ctx)

if _, ok := f.urls.Load(*u); ok {
filteredMechanisms := filterMechanismsByCls(request.GetMechanismPreferences(), cls.LOCAL)
if len(filteredMechanisms) > 0 {
request.MechanismPreferences = filteredMechanisms
if name, ok := f.nses.Load(*u); ok {
if !interpose.Is(name) {
request.MechanismPreferences = filterMechanismsByCls(request.GetMechanismPreferences(), cls.LOCAL)
}
} else {
request.MechanismPreferences = filterMechanismsByCls(request.GetMechanismPreferences(), cls.REMOTE)
Expand Down
68 changes: 0 additions & 68 deletions pkg/networkservice/common/filtermechanisms/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"net/url"
"testing"

"github.com/networkservicemesh/sdk/pkg/networkservice/core/next"

"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/cls"
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/kernel"
Expand All @@ -36,72 +34,6 @@ import (
"github.com/networkservicemesh/sdk/pkg/tools/clienturlctx"
)

func TestFilterMechanisms_RemoteExternal(t *testing.T) {
request := &networkservice.NetworkServiceRequest{
MechanismPreferences: []*networkservice.Mechanism{
{
Cls: cls.REMOTE,
Type: vxlan.MECHANISM,
},
{
Cls: cls.LOCAL,
Type: kernel.MECHANISM,
},
},
Connection: &networkservice.Connection{
Path: &networkservice.Path{
PathSegments: make([]*networkservice.PathSegment, 3),
},
},
}

var localRegistryServer registry.NetworkServiceEndpointRegistryServer
localServer := filtermechanisms.NewServer(&localRegistryServer)
var remoteRegistryServer registry.NetworkServiceEndpointRegistryServer
remoteServer := filtermechanisms.NewServer(&remoteRegistryServer, filtermechanisms.WithExternalThreshold())
u := &url.URL{Path: "test"}
_, _ = remoteRegistryServer.Register(context.Background(), &registry.NetworkServiceEndpoint{
Url: u.String(),
})
_, err := next.NewNetworkServiceServer(localServer, remoteServer).Request(clienturlctx.WithClientURL(context.Background(), u), request)
require.NoError(t, err)
require.Len(t, request.MechanismPreferences, 1)
require.Equal(t, cls.REMOTE, request.MechanismPreferences[0].Cls)
}

func TestFilterMechanisms_Remote(t *testing.T) {
request := &networkservice.NetworkServiceRequest{
MechanismPreferences: []*networkservice.Mechanism{
{
Cls: cls.REMOTE,
Type: vxlan.MECHANISM,
},
{
Cls: cls.LOCAL,
Type: kernel.MECHANISM,
},
},
Connection: &networkservice.Connection{
Path: &networkservice.Path{
PathSegments: make([]*networkservice.PathSegment, 5),
},
},
}

var localRegistryServer registry.NetworkServiceEndpointRegistryServer
localServer := filtermechanisms.NewServer(&localRegistryServer)
var remoteRegistryServer registry.NetworkServiceEndpointRegistryServer
remoteServer := filtermechanisms.NewServer(&remoteRegistryServer)
u := &url.URL{Path: "test"}
_, _ = remoteRegistryServer.Register(context.Background(), &registry.NetworkServiceEndpoint{
Url: u.String(),
})
_, err := next.NewNetworkServiceServer(localServer, remoteServer).Request(clienturlctx.WithClientURL(context.Background(), u), request)
require.NoError(t, err)
require.Len(t, request.MechanismPreferences, 1)
require.Equal(t, cls.REMOTE, request.MechanismPreferences[0].Cls)
}

func TestFilterMechanismsServer_Request(t *testing.T) {
request := func() *networkservice.NetworkServiceRequest {
return &networkservice.NetworkServiceRequest{
Expand Down
74 changes: 0 additions & 74 deletions pkg/registry/common/endpointurls/sync_set.gen.go

This file was deleted.

0 comments on commit c778e05

Please sign in to comment.