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

Update forwarder to use it with an external vpp #530

Merged
merged 3 commits into from
Mar 20, 2022
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
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ require (
github.com/edwarnicke/grpcfd v1.1.2
github.com/edwarnicke/vpphelper v0.0.0-20210512223648-f914b171f679
github.com/golang/protobuf v1.5.2
github.com/google/uuid v1.2.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/networkservicemesh/api v1.2.1-0.20220315001249-f33f8c3f2feb
github.com/networkservicemesh/sdk v0.5.1-0.20220316101237-288caa7bbc1c
github.com/networkservicemesh/sdk v0.5.1-0.20220316105041-b88289b9022e
github.com/networkservicemesh/sdk-k8s v0.0.0-20220316102251-ecbf32113a5c
github.com/networkservicemesh/sdk-sriov v0.0.0-20220314174029-8ee6d6181d09
github.com/networkservicemesh/sdk-vpp v0.0.0-20220318000218-652ab0bc2621
github.com/networkservicemesh/sdk-vpp v0.0.0-20220318080418-9984c7c6df6e
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.8.1
github.com/spiffe/go-spiffe/v2 v2.0.0-beta.2
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -382,17 +382,18 @@ github.com/networkservicemesh/api v1.2.1-0.20220314135017-fe3ca7556bdc/go.mod h1
github.com/networkservicemesh/api v1.2.1-0.20220315001249-f33f8c3f2feb h1:5047nbh591kIjLNlFrO0NbpRVkOtCGRSvkKKjQyEDyI=
github.com/networkservicemesh/api v1.2.1-0.20220315001249-f33f8c3f2feb/go.mod h1:B6meq/SWjWR6bGXZdXPfbOeaBK+T1JayLdtEJQCsXKU=
github.com/networkservicemesh/sdk v0.5.1-0.20220314173321-130992f19d87/go.mod h1:f/f0fiMhDclV4yNwsU0r4mc94Onq+EhLKZc5SOhpQgA=
github.com/networkservicemesh/sdk v0.5.1-0.20220316101237-288caa7bbc1c h1:R0DVEMRYMg5SAuPQ48R3lTUD5Dpu+epJfrsmbDMY8mw=
github.com/networkservicemesh/sdk v0.5.1-0.20220316101237-288caa7bbc1c/go.mod h1:fK/G5mfEDIefFXxRSNXqj1jjd8SEUeZMpQUdCuc7owY=
github.com/networkservicemesh/sdk v0.5.1-0.20220316105041-b88289b9022e h1:IXzvAfoU6tCTEZxAGfJGbKjVfome2Iymm1vkiM9MhZ8=
github.com/networkservicemesh/sdk v0.5.1-0.20220316105041-b88289b9022e/go.mod h1:fK/G5mfEDIefFXxRSNXqj1jjd8SEUeZMpQUdCuc7owY=
github.com/networkservicemesh/sdk-k8s v0.0.0-20220316102251-ecbf32113a5c h1:O6PbevWW5ukL/OVSMj3NQXJKPppQTBYs8Jy1esP68iA=
github.com/networkservicemesh/sdk-k8s v0.0.0-20220316102251-ecbf32113a5c/go.mod h1:8B4HAjyuXRA1Uus9Mmmcr3Hzk22e7jqChv7s4vZ+5zU=
github.com/networkservicemesh/sdk-kernel v0.0.0-20220314173549-613436de9ab3/go.mod h1:bQ7VrJlqjSAxF4o8vaeTO82EuUEP+Blfa13XBD9ijq4=
github.com/networkservicemesh/sdk-kernel v0.0.0-20220316101641-0103343013f0 h1:PpT01M2DzAt6vBLbmjbTn3u7vrzHUuLoE6WbUy9pk2M=
github.com/networkservicemesh/sdk-kernel v0.0.0-20220316101641-0103343013f0/go.mod h1:nbwaNH+kCji5C8R0RxdZHqAPTNXvX7St/NUJ+bwmbIs=
github.com/networkservicemesh/sdk-sriov v0.0.0-20220314174029-8ee6d6181d09 h1:uBGp8clCteS/cKsVl2rq5yc5YwLQgan7kLyXEh4mftQ=
github.com/networkservicemesh/sdk-sriov v0.0.0-20220314174029-8ee6d6181d09/go.mod h1:Oa2ZyplOs5wDAHd5X0g7Sn+dlfY04PUlj/57Gfmr1MU=
github.com/networkservicemesh/sdk-vpp v0.0.0-20220318000218-652ab0bc2621 h1:bcQ6rAP38aDzXSLSra0MV/GwsfZgP/7tXrFP4NxEfpY=
github.com/networkservicemesh/sdk-vpp v0.0.0-20220318000218-652ab0bc2621/go.mod h1:NrIe17i36dcoif2L5Ja4s+MDMAQeVF6nELdxOYfpkj8=
github.com/networkservicemesh/sdk-vpp v0.0.0-20220318080418-9984c7c6df6e h1:/HoqC+vuK2IfPI907K/ayKRWH6wlD+gCKfsya11u2aM=
github.com/networkservicemesh/sdk-vpp v0.0.0-20220318080418-9984c7c6df6e/go.mod h1:Un+rRfUnFbRPqIKhM9M73KDhTYnjxRCTdzj05zIkDuo=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
Expand Down
4 changes: 2 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ type Config struct {

TunnelIP net.IP `desc:"IP to use for tunnels" split_words:"true"`
VxlanPort uint16 `default:"0" desc:"VXLAN port to use" split_words:"true"`
VppAPISocket string `default:"" desc:"filename of socket to connect to existing VPP instance. If empty a VPP instance is run in forwarder" split_words:"true"`
VppInit vppinit.Func `default:"AF_PACKET" desc:"type of VPP initialization. Must be AF_PACKET or NONE" split_words:"true"`
VppAPISocket string `default:"/var/run/vpp/vpp-api.sock" desc:"filename of socket to connect to existing VPP instance. If empty a VPP instance is run in forwarder" split_words:"true"`
VppInit vppinit.Func `default:"NONE" desc:"type of VPP initialization. Must be NONE or AF_PACKET" split_words:"true"`

ResourcePollTimeout time.Duration `default:"30s" desc:"device plugin polling timeout" split_words:"true"`
DevicePluginPath string `default:"/var/lib/kubelet/device-plugins/" desc:"path to the device plugin directory" split_words:"true"`
Expand Down
4 changes: 4 additions & 0 deletions internal/imports/imports_linux.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

113 changes: 113 additions & 0 deletions internal/xconnectns/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Copyright (c) 2022 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// +build linux

package xconnectns

import (
"net/url"
"time"

"google.golang.org/grpc"

"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/cleanup"

"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/mechanisms/vxlan"
"github.com/networkservicemesh/sdk-vpp/pkg/networkservice/stats"
)

type xconnOptions struct {
name string
authorizeServer networkservice.NetworkServiceServer
clientURL *url.URL
dialTimeout time.Duration
domain2Device map[string]string
statsOpts []stats.Option
cleanupOpts []cleanup.Option
vxlanOpts []vxlan.Option
dialOpts []grpc.DialOption
}

// Option is an option pattern for forwarder
type Option func(o *xconnOptions)

// WithName - set a forwarder name
func WithName(name string) Option {
return func(o *xconnOptions) {
o.name = name
}
}

// WithAuthorizeServer sets authorization server chain element
func WithAuthorizeServer(authorizeServer networkservice.NetworkServiceServer) Option {
if authorizeServer == nil {
panic("Authorize server cannot be nil")
}
return func(o *xconnOptions) {
o.authorizeServer = authorizeServer
}
}

// WithClientURL sets clientURL.
func WithClientURL(clientURL *url.URL) Option {
return func(c *xconnOptions) {
c.clientURL = clientURL
}
}

// WithDialTimeout sets dial timeout for the client
func WithDialTimeout(dialTimeout time.Duration) Option {
return func(o *xconnOptions) {
o.dialTimeout = dialTimeout
}
}

// WithVlanDomain2Device sets vlan option
func WithVlanDomain2Device(domain2Device map[string]string) Option {
return func(o *xconnOptions) {
o.domain2Device = domain2Device
}
}

// WithStatsOptions sets stats options
func WithStatsOptions(opts ...stats.Option) Option {
return func(o *xconnOptions) {
o.statsOpts = opts
}
}

// WithCleanupOptions sets cleanup options
func WithCleanupOptions(opts ...cleanup.Option) Option {
return func(o *xconnOptions) {
o.cleanupOpts = opts
}
}

// WithVxlanOptions sets vxlan options
func WithVxlanOptions(opts ...vxlan.Option) Option {
return func(o *xconnOptions) {
o.vxlanOpts = opts
}
}

// WithDialOptions sets dial options
func WithDialOptions(opts ...grpc.DialOption) Option {
return func(o *xconnOptions) {
o.dialOpts = opts
}
}
50 changes: 39 additions & 11 deletions internal/xconnectns/server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright (c) 2021 Doc.ai and/or its affiliates.
// Copyright (c) 2021-2022 Doc.ai and/or its affiliates.
//
// Copyright (c) 2022 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -25,7 +27,7 @@ import (
"net/url"
"time"

"google.golang.org/grpc"
"github.com/google/uuid"

"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/kernel"
Expand All @@ -40,6 +42,7 @@ import (
sriovtokens "github.com/networkservicemesh/sdk-sriov/pkg/tools/tokens"
vppforwarder "github.com/networkservicemesh/sdk-vpp/pkg/networkservice/chains/forwarder"
"github.com/networkservicemesh/sdk/pkg/networkservice/chains/endpoint"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/authorize"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/switchcase"
"github.com/networkservicemesh/sdk/pkg/tools/token"
Expand All @@ -48,22 +51,36 @@ import (
// NewServer - returns an implementation of the xconnectns network service
func NewServer(
ctx context.Context,
name string,
authzServer networkservice.NetworkServiceServer,
tokenGenerator token.GeneratorFunc,
vppConn vppforwarder.Connection,
tunnelIP net.IP,
tunnelPort uint16,
pciPool resourcepool.PCIPool,
resourcePool resourcepool.ResourcePool,
sriovConfig *sriovconfig.Config,
deviceMap map[string]string,
vfioDir, cgroupBaseDir string,
clientURL *url.URL,
dialTimeout time.Duration,
clientDialOptions ...grpc.DialOption,
options ...Option,
) endpoint.Endpoint {
vppForwarder := vppforwarder.NewServer(ctx, name, authzServer, tokenGenerator, clientURL, vppConn, tunnelIP, tunnelPort, dialTimeout, deviceMap, clientDialOptions...)
xconnOpts := &xconnOptions{
name: "forwarder-" + uuid.New().String(),
authorizeServer: authorize.NewServer(authorize.Any()),
clientURL: &url.URL{Scheme: "unix", Host: "connect.to.socket"},
dialTimeout: time.Millisecond * 200,
domain2Device: make(map[string]string),
}
for _, opt := range options {
opt(xconnOpts)
}

vppForwarder := vppforwarder.NewServer(ctx, tokenGenerator, vppConn, tunnelIP,
vppforwarder.WithName(xconnOpts.name),
vppforwarder.WithAuthorizeServer(xconnOpts.authorizeServer),
vppforwarder.WithClientURL(xconnOpts.clientURL),
vppforwarder.WithDialTimeout(xconnOpts.dialTimeout),
vppforwarder.WithVlanDomain2Device(xconnOpts.domain2Device),
vppforwarder.WithCleanupOptions(xconnOpts.cleanupOpts...),
vppforwarder.WithStatsOptions(xconnOpts.statsOpts...),
vppforwarder.WithVxlanOptions(xconnOpts.vxlanOpts...),
vppforwarder.WithDialOptions(xconnOpts.dialOpts...))
if sriovConfig == nil {
return vppForwarder
}
Expand Down Expand Up @@ -92,6 +109,17 @@ func NewServer(
})
},
vppForwarder,
sriovforwarder.NewServer(ctx, name, authzServer, tokenGenerator, pciPool, resourcePool, sriovConfig, vfioDir, cgroupBaseDir, clientURL, dialTimeout, clientDialOptions...),
sriovforwarder.NewServer(ctx,
xconnOpts.name,
xconnOpts.authorizeServer,
tokenGenerator,
pciPool,
resourcePool,
sriovConfig,
vfioDir,
cgroupBaseDir,
xconnOpts.clientURL,
xconnOpts.dialTimeout,
xconnOpts.dialOpts...),
)
}
Loading