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: Add support for empty routes with metadata #1194

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
113 changes: 113 additions & 0 deletions pkg/networkservice/chains/nsmgr/single_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package nsmgr_test

import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -282,3 +283,115 @@ func Test_UsecasePoint2MultiPoint(t *testing.T) {
require.Equal(t, 4, len(conn.Path.PathSegments))
require.Equal(t, "p2p forwarder", conn.GetPath().GetPathSegments()[2].Name)
}
func Test_RemoteUsecase_Point2MultiPoint(t *testing.T) {
t.Cleanup(func() { goleak.VerifyNone(t) })

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

const nodeCount = 2

domain := sandbox.NewBuilder(ctx, t).
SetNodesCount(nodeCount).
SetRegistryProxySupplier(nil).
SetNodeSetup(func(ctx context.Context, node *sandbox.Node, _ int) {
node.NewNSMgr(ctx, "nsmgr", nil, sandbox.GenerateTestToken, nsmgr.NewServer)
}).
SetRegistryExpiryDuration(sandbox.RegistryExpiryDuration).
Build()

for i := 0; i < nodeCount; i++ {
domain.Nodes[i].NewForwarder(ctx, &registry.NetworkServiceEndpoint{
Name: "p2mp forwarder-" + fmt.Sprint(i),
NetworkServiceNames: []string{"forwarder"},
NetworkServiceLabels: map[string]*registry.NetworkServiceLabels{
"forwarder": {
Labels: map[string]string{
"p2mp": "true",
},
},
},
}, sandbox.GenerateTestToken)

domain.Nodes[i].NewForwarder(ctx, &registry.NetworkServiceEndpoint{
Name: "p2p forwarder-" + fmt.Sprint(i),
NetworkServiceNames: []string{"forwarder"},
NetworkServiceLabels: map[string]*registry.NetworkServiceLabels{
"forwarder": {
Labels: map[string]string{
"p2p": "true",
},
},
},
}, sandbox.GenerateTestToken)

domain.Nodes[i].NewForwarder(ctx, &registry.NetworkServiceEndpoint{
Name: "special forwarder-" + fmt.Sprint(i),
NetworkServiceNames: []string{"forwarder"},
NetworkServiceLabels: map[string]*registry.NetworkServiceLabels{
"forwarder": {
Labels: map[string]string{
"special": "true",
},
},
},
}, sandbox.GenerateTestToken)
}
nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.GenerateTestToken)

_, err := nsRegistryClient.Register(ctx, &registry.NetworkService{
Name: "my-ns",
Matches: []*registry.Match{
{
Metadata: &registry.Metadata{
Labels: map[string]string{
"p2mp": "true",
},
},
},
},
})
require.NoError(t, err)

nseReg := &registry.NetworkServiceEndpoint{
Name: "my-nse-1",
NetworkServiceNames: []string{"my-ns"},
}

domain.Nodes[1].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken)

nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)

request := defaultRequest("my-ns")

conn, err := nsc.Request(ctx, request.Clone())
require.NoError(t, err)
require.NotNil(t, conn)
require.Equal(t, 6, len(conn.Path.PathSegments))
require.Equal(t, "p2mp forwarder-0", conn.GetPath().GetPathSegments()[2].Name)
require.Equal(t, "p2mp forwarder-1", conn.GetPath().GetPathSegments()[4].Name)

_, err = nsRegistryClient.Register(ctx, &registry.NetworkService{
Name: "my-ns",
Matches: []*registry.Match{
{
Metadata: &registry.Metadata{
Labels: map[string]string{
// no labels
},
},
},
},
})
require.NoError(t, err)

_, err = nsc.Close(ctx, conn)
require.NoError(t, err)

conn, err = nsc.Request(ctx, request.Clone())
require.NoError(t, err)
require.NotNil(t, conn)
require.Equal(t, 6, len(conn.Path.PathSegments))
require.Equal(t, "p2p forwarder-0", conn.GetPath().GetPathSegments()[2].Name)
require.Equal(t, "p2p forwarder-1", conn.GetPath().GetPathSegments()[4].Name)
}
4 changes: 4 additions & 0 deletions pkg/networkservice/common/discover/match_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ func matchEndpoint(clockTime clock.Clock, nsLabels map[string]string, ns *regist
continue
}

if match.GetMetadata() != nil && len(match.Routes) == 0 && len(nseCandidates) == 0 {
break
}

return nseCandidates
}

Expand Down
1 change: 1 addition & 0 deletions pkg/networkservice/common/discoverforwarder/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func (d *discoverForwarderServer) Request(ctx context.Context, request *networks
storeForwarderName(ctx, candidate.Name)
return resp, nil
}
logger.Errorf("forwarder=%v url=%v returned error=%v", candidate.Name, candidate.Url, err.Error())
}

return nil, errors.New("all forwarders failed")
Expand Down