diff --git a/pkg/networkservice/chains/xconnectns/server.go b/pkg/networkservice/chains/xconnectns/server.go index b574b05..97a0774 100644 --- a/pkg/networkservice/chains/xconnectns/server.go +++ b/pkg/networkservice/chains/xconnectns/server.go @@ -44,6 +44,7 @@ import ( "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/recvfd" "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/sendfd" "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanismtranslation" + "github.com/networkservicemesh/sdk/pkg/networkservice/common/null" "github.com/networkservicemesh/sdk/pkg/networkservice/core/adapters" "github.com/networkservicemesh/sdk/pkg/networkservice/core/chain" "github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata" @@ -67,6 +68,16 @@ func NewSriovServer(ctx context.Context, name string, authzServer networkservice pciPool resourcepool.PCIPool, resourcePool resourcepool.ResourcePool, sriovConfig *config.Config, clientDialOptions ...grpc.DialOption) (endpoint.Endpoint, error) { resourceLock := &sync.Mutex{} + resourcePoolClient := resourcepool.NewClient(sriov.KernelDriver, resourceLock, pciPool, resourcePool, sriovConfig) + resourcePoolServer := resourcepool.NewServer(sriov.KernelDriver, resourceLock, pciPool, resourcePool, sriovConfig) + + return newEndPoint(ctx, name, authzServer, resourcePoolServer, resourcePoolClient, tokenGenerator, + clientURL, bridgeName, tunnelIPCidr, clientDialOptions...) +} + +func newEndPoint(ctx context.Context, name string, authzServer, resourcePoolServer networkservice.NetworkServiceServer, + resourcePoolClient networkservice.NetworkServiceClient, tokenGenerator token.GeneratorFunc, clientURL *url.URL, + bridgeName string, tunnelIPCidr net.IP, clientDialOptions ...grpc.DialOption) (endpoint.Endpoint, error) { tunnelIP, err := utils.ParseTunnelIP(tunnelIPCidr) if err != nil { return nil, err @@ -88,7 +99,7 @@ func NewSriovServer(ctx context.Context, name string, authzServer networkservice mechanisms.NewServer(map[string]networkservice.NetworkServiceServer{ kernelmech.MECHANISM: chain.NewNetworkServiceServer( kernel.NewServer(bridgeName), - resourcepool.NewServer(sriov.KernelDriver, resourceLock, pciPool, resourcePool, sriovConfig), + resourcePoolServer, ), vxlanmech.MECHANISM: vxlan.NewServer(tunnelIP, bridgeName, vxlanInterfacesMutex, vxlanInterfaces), }), @@ -104,7 +115,7 @@ func NewSriovServer(ctx context.Context, name string, authzServer networkservice inject.NewClient(), // mechanisms kernel.NewClient(bridgeName), - resourcepool.NewClient(sriov.KernelDriver, resourceLock, pciPool, resourcePool, sriovConfig), + resourcePoolClient, // uncomment when vfconfig client chain element available // vfconfig.NewClient(), vxlan.NewClient(tunnelIP, bridgeName, vxlanInterfacesMutex, vxlanInterfaces), @@ -128,54 +139,6 @@ func NewSriovServer(ctx context.Context, name string, authzServer networkservice func NewKernelServer(ctx context.Context, name string, authzServer networkservice.NetworkServiceServer, tokenGenerator token.GeneratorFunc, clientURL *url.URL, bridgeName string, tunnelIPCidr net.IP, clientDialOptions ...grpc.DialOption) (endpoint.Endpoint, error) { - tunnelIP, err := utils.ParseTunnelIP(tunnelIPCidr) - if err != nil { - return nil, err - } - utils.ConfigureOvS(ctx, bridgeName) - vxlanInterfacesMutex := &sync.Mutex{} - vxlanInterfaces := make(map[string]int) - rv := &ovsConnectNSServer{} - additionalFunctionality := []networkservice.NetworkServiceServer{ - metadata.NewServer(), - recvfd.NewServer(), - sendfd.NewServer(), - // Statically set the url we use to the unix file socket for the NSMgr - clienturl.NewServer(clientURL), - heal.NewServer(ctx, - heal.WithOnHeal(addressof.NetworkServiceClient(adapters.NewServerToClient(rv))), - heal.WithOnRestore(heal.OnRestoreIgnore)), - mechanisms.NewServer(map[string]networkservice.NetworkServiceServer{ - kernelmech.MECHANISM: chain.NewNetworkServiceServer( - kernel.NewServer(bridgeName), - ), - vxlanmech.MECHANISM: vxlan.NewServer(tunnelIP, bridgeName, vxlanInterfacesMutex, vxlanInterfaces), - }), - inject.NewServer(), - connectioncontextkernel.NewServer(), - connect.NewServer(ctx, - client.NewClientFactory( - client.WithName(name), - client.WithAdditionalFunctionality( - mechanismtranslation.NewClient(), - l2ovsconnect.NewClient(bridgeName), - connectioncontextkernel.NewClient(), - inject.NewClient(), - // mechanisms - kernel.NewClient(bridgeName), - vxlan.NewClient(tunnelIP, bridgeName, vxlanInterfacesMutex, vxlanInterfaces), - recvfd.NewClient(), - sendfd.NewClient(), - ), - ), - connect.WithDialOptions(clientDialOptions...), - ), - } - - rv.Endpoint = endpoint.NewServer(ctx, tokenGenerator, - endpoint.WithName(name), - endpoint.WithAuthorizeServer(authzServer), - endpoint.WithAdditionalFunctionality(additionalFunctionality...)) - - return rv, nil + return newEndPoint(ctx, name, authzServer, null.NewServer(), null.NewClient(), tokenGenerator, + clientURL, bridgeName, tunnelIPCidr, clientDialOptions...) }