generated from networkservicemesh/cmd-template
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> Signed-off-by: Ed Warnicke <hagbard@gmail.com>
- Loading branch information
Vladimir Popov
authored
Sep 21, 2021
1 parent
4fa0446
commit 31e9be1
Showing
9 changed files
with
828 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) 2020-2021 Cisco and/or its affiliates. | ||
// | ||
// Copyright (c) 2021 Doc.ai 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 config - contain environment variables used by cmd-forwarder-vpp | ||
package config | ||
|
||
import ( | ||
"net" | ||
"net/url" | ||
"time" | ||
|
||
"github.com/kelseyhightower/envconfig" | ||
|
||
"github.com/networkservicemesh/cmd-forwarder-vpp/internal/vppinit" | ||
) | ||
|
||
// Config - configuration for cmd-forwarder-vpp | ||
type Config struct { | ||
Name string `default:"forwarder" desc:"Name of Endpoint"` | ||
NSName string `default:"xconnectns" desc:"Name of Network Service to Register with Registry"` | ||
ConnectTo url.URL `default:"unix:///connect.to.socket" desc:"url to connect to" split_words:"true"` | ||
ListenOn url.URL `default:"unix:///listen.on.socket" desc:"url to listen on" split_words:"true"` | ||
MaxTokenLifetime time.Duration `default:"10m" desc:"maximum lifetime of tokens" split_words:"true"` | ||
LogLevel string `default:"INFO" desc:"Log level" split_words:"true"` | ||
|
||
TunnelIP net.IP `desc:"IP to use for tunnels" 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"` | ||
|
||
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"` | ||
PodResourcesPath string `default:"/var/lib/kubelet/pod-resources/" desc:"path to the pod resources directory" split_words:"true"` | ||
SRIOVConfigFile string `default:"pci.config" desc:"PCI resources config path" split_words:"true"` | ||
PCIDevicesPath string `default:"/sys/bus/pci/devices" desc:"path to the PCI devices directory" split_words:"true"` | ||
PCIDriversPath string `default:"/sys/bus/pci/drivers" desc:"path to the PCI drivers directory" split_words:"true"` | ||
CgroupPath string `default:"/host/sys/fs/cgroup/devices" desc:"path to the host cgroup directory" split_words:"true"` | ||
VFIOPath string `default:"/host/dev/vfio" desc:"path to the host VFIO directory" split_words:"true"` | ||
} | ||
|
||
// Process reads config from env | ||
func (c *Config) Process() error { | ||
if err := envconfig.Usage("nsm", c); err != nil { | ||
return err | ||
} | ||
return envconfig.Process("nsm", c) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright (c) 2021 Doc.ai 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 provides an endpoint implementing xconnectns | ||
package xconnectns | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"net/url" | ||
|
||
"google.golang.org/grpc" | ||
|
||
"github.com/networkservicemesh/api/pkg/api/networkservice" | ||
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/kernel" | ||
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/memif" | ||
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/noop" | ||
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/vfio" | ||
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/vxlan" | ||
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/wireguard" | ||
sriovxconnectns "github.com/networkservicemesh/sdk-sriov/pkg/networkservice/chains/xconnectns" | ||
"github.com/networkservicemesh/sdk-sriov/pkg/networkservice/common/resourcepool" | ||
sriovconfig "github.com/networkservicemesh/sdk-sriov/pkg/sriov/config" | ||
sriovtokens "github.com/networkservicemesh/sdk-sriov/pkg/tools/tokens" | ||
vppxconnectns "github.com/networkservicemesh/sdk-vpp/pkg/networkservice/chains/xconnectns" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/chains/endpoint" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/common/switchcase" | ||
"github.com/networkservicemesh/sdk/pkg/tools/token" | ||
) | ||
|
||
// NewServer - returns an implementation of the xconnectns network service | ||
func NewServer( | ||
ctx context.Context, | ||
name string, | ||
authzServer networkservice.NetworkServiceServer, | ||
tokenGenerator token.GeneratorFunc, | ||
vppConn vppxconnectns.Connection, | ||
tunnelIP net.IP, | ||
pciPool resourcepool.PCIPool, | ||
resourcePool resourcepool.ResourcePool, | ||
sriovConfig *sriovconfig.Config, | ||
vfioDir, cgroupBaseDir string, | ||
clientURL *url.URL, | ||
clientDialOptions ...grpc.DialOption, | ||
) endpoint.Endpoint { | ||
return endpoint.Combine(func(servers []networkservice.NetworkServiceServer) networkservice.NetworkServiceServer { | ||
vppForwarder := servers[0] | ||
sriovForwarder := servers[1] | ||
return mechanisms.NewServer(map[string]networkservice.NetworkServiceServer{ | ||
kernel.MECHANISM: switchcase.NewServer( | ||
&switchcase.ServerCase{ | ||
Condition: func(_ context.Context, conn *networkservice.Connection) bool { | ||
return sriovtokens.IsTokenID(kernel.ToMechanism(conn.GetMechanism()).GetDeviceTokenID()) | ||
}, | ||
Server: sriovForwarder, | ||
}, | ||
&switchcase.ServerCase{ | ||
Condition: switchcase.Default, | ||
Server: vppForwarder, | ||
}, | ||
), | ||
vfio.MECHANISM: sriovForwarder, | ||
memif.MECHANISM: vppForwarder, | ||
vxlan.MECHANISM: vppForwarder, | ||
wireguard.MECHANISM: vppForwarder, | ||
noop.MECHANISM: sriovForwarder, | ||
}) | ||
}, | ||
vppxconnectns.NewServer(ctx, name, authzServer, tokenGenerator, clientURL, vppConn, tunnelIP, clientDialOptions...), | ||
sriovxconnectns.NewServer(ctx, name, authzServer, tokenGenerator, pciPool, resourcePool, sriovConfig, vfioDir, cgroupBaseDir, clientURL, clientDialOptions...), | ||
) | ||
} |
Oops, something went wrong.