Skip to content

Commit

Permalink
Set back nse@domain name on return from interdomainURLServer (network…
Browse files Browse the repository at this point in the history
…servicemesh#605)

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
Signed-off-by: Sergey Ershov <sergey.ershov@xored.com>
  • Loading branch information
Vladimir Popov authored and Sergey Ershov committed Dec 20, 2020
1 parent 46d321e commit 0142c73
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 27 deletions.
4 changes: 1 addition & 3 deletions pkg/networkservice/chains/nsmgrproxy/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ func TestNSMGR_InterdomainUseCase(t *testing.T) {
// Simulate refresh from client.

refreshRequest := request.Clone()
refreshRequest.GetConnection().Context = conn.Context
refreshRequest.GetConnection().Mechanism = conn.Mechanism
refreshRequest.GetConnection().NetworkServiceEndpointName = conn.NetworkServiceEndpointName
refreshRequest.Connection = conn.Clone()

conn, err = nsc.Request(ctx, refreshRequest)
require.NoError(t, err)
Expand Down
57 changes: 36 additions & 21 deletions pkg/networkservice/common/interdomainurl/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,45 +22,60 @@ import (
"net/url"

"github.com/golang/protobuf/ptypes/empty"
"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/pkg/errors"

"github.com/networkservicemesh/api/pkg/api/networkservice"

"github.com/networkservicemesh/sdk/pkg/networkservice/core/next"
"github.com/networkservicemesh/sdk/pkg/tools/clienturlctx"
"github.com/networkservicemesh/sdk/pkg/tools/interdomain"
)

type interdomainURLServer struct{}

// NewServer creates new interdomainurl chain element
func NewServer() networkservice.NetworkServiceServer {
return &interdomainURLServer{}
}

func (i *interdomainURLServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) {
nseName := request.GetConnection().GetNetworkServiceEndpointName()
if nseName == "" {
return nil, errors.New("NSE is not selected")
interDomainNSEName := request.GetConnection().GetNetworkServiceEndpointName()
nseName, domainURL, err := parseInterDomainNSEName(interDomainNSEName)
if err != nil {
return nil, err
}
remoteURL := interdomain.Domain(nseName)
u, err := url.Parse(remoteURL)
request.GetConnection().NetworkServiceEndpointName = nseName

conn, err := next.Server(ctx).Request(clienturlctx.WithClientURL(ctx, domainURL), request)
if err != nil {
return nil, errors.Wrap(err, "selected NSE has wrong name. Make sure that proxy-registry has handled NSE")
return nil, err
}
request.GetConnection().NetworkServiceEndpointName = interdomain.Target(nseName)
return next.Server(ctx).Request(clienturlctx.WithClientURL(ctx, u), request)
conn.NetworkServiceEndpointName = interDomainNSEName

return conn, nil
}

func (i *interdomainURLServer) Close(ctx context.Context, conn *networkservice.Connection) (*empty.Empty, error) {
interDomainNSEName := conn.GetNetworkServiceEndpointName()
nseName, domainURL, err := parseInterDomainNSEName(interDomainNSEName)
if err != nil {
return nil, err
}
conn.NetworkServiceEndpointName = nseName

return next.Server(ctx).Close(clienturlctx.WithClientURL(ctx, domainURL), conn)
}

func (i *interdomainURLServer) Close(ctx context.Context, connection *networkservice.Connection) (*empty.Empty, error) {
nseName := connection.GetNetworkServiceEndpointName()
if nseName == "" {
return nil, errors.New("NSE is not selected")
func parseInterDomainNSEName(interDomainNSEName string) (string, *url.URL, error) {
if interDomainNSEName == "" {
return "", nil, errors.New("NSE is not selected")
}
remoteURL := interdomain.Domain(nseName)

remoteURL := interdomain.Domain(interDomainNSEName)
u, err := url.Parse(remoteURL)
if err != nil {
return nil, errors.Wrap(err, "selected NSE has wrong name. Make sure that proxy-registry has handled NSE")
return "", nil, errors.Wrap(err, "selected NSE has wrong name. Make sure that proxy-registry has handled NSE")
}
connection.NetworkServiceEndpointName = interdomain.Target(nseName)
return next.Server(ctx).Close(clienturlctx.WithClientURL(ctx, u), connection)
}

// NewServer creates new interdomainurl chain element
func NewServer() networkservice.NetworkServiceServer {
return &interdomainURLServer{}
return interdomain.Target(interDomainNSEName), u, nil
}
20 changes: 17 additions & 3 deletions pkg/networkservice/common/interdomainurl/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package interdomainurl_test

import (
"context"
"fmt"
"net/url"
"testing"

Expand All @@ -27,23 +28,36 @@ import (
"github.com/networkservicemesh/sdk/pkg/networkservice/common/interdomainurl"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/next"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/checks/checkcontext"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/checks/checkrequest"
"github.com/networkservicemesh/sdk/pkg/tools/clienturlctx"
)

const (
nseName = "nse1"
domainURL = "tcp://127.0.0.1:5000"
)

func TestInterdomainURLServer_Register(t *testing.T) {
expected, err := url.Parse("tcp://127.0.0.1:5000")
expected, err := url.Parse(domainURL)
require.NoError(t, err)

s := next.NewNetworkServiceServer(
interdomainurl.NewServer(),
checkcontext.NewServer(t, func(t *testing.T, ctx context.Context) {
require.Equal(t, *expected, *clienturlctx.ClientURL(ctx))
}),
checkrequest.NewServer(t, func(t *testing.T, request *networkservice.NetworkServiceRequest) {
require.Equal(t, nseName, request.Connection.NetworkServiceEndpointName)
}),
)
_, err = s.Request(context.Background(), &networkservice.NetworkServiceRequest{

conn, err := s.Request(context.Background(), &networkservice.NetworkServiceRequest{
Connection: &networkservice.Connection{
NetworkServiceEndpointName: "nse1@" + expected.String(),
NetworkServiceEndpointName: fmt.Sprintf("%s@%s", nseName, domainURL),
},
})
require.NoError(t, err)
require.NotNil(t, conn)

require.Equal(t, fmt.Sprintf("%s@%s", nseName, domainURL), conn.NetworkServiceEndpointName)
}

0 comments on commit 0142c73

Please sign in to comment.