Skip to content

Commit

Permalink
Merge pull request #15 from Bolodya1997/client-chains
Browse files Browse the repository at this point in the history
Rework client to use chain elements
  • Loading branch information
denis-tingaikin authored Nov 20, 2020
2 parents 89051ca + 4a82f8a commit 4457c18
Show file tree
Hide file tree
Showing 9 changed files with 372 additions and 237 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ linters-settings:
- regexpPattern
- singleCaseSwitch
- sloppyLen
- sloppyReassign
# - sloppyReassign
- stringXbytes
- switchTrue
- typeAssertChain
Expand Down
33 changes: 24 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,33 @@ This README will provide directions for building, testing, and debugging that co

* NSM_NAME - A string value of network service client name (default "nsc")
* NSM_CONNECT_TO - A Network service Manager connectTo URL (default "unix:///var/lib/networkservicemesh/nsm.io.sock")
* NSM_MAX_TOKEN_LIFETIME - A token lifetime duration (default 24h)
* NSM_ROUTES - A comma separated list of routes.
* NSM_CONNECT_TIMEOUT - A timeout to connect to Network service Manager (default 5s)
* NSM_MAX_TOKEN_LIFETIME - A token lifetime duration (default 24h)
* NSM_LABELS - A list of client labels with format key1=val1,key2=val2, will be used a primary list for network services
* NSM_MECHANISM - Default Mechanism to use, supported values "kernel","memif"
* NSM_MECHANISM - Default Mechanism to use, supported values "kernel", "vfio"
* NSM_NETWORK_SERVICES - A list of Network Service Requests URLs with inner format
- [{mechanism}]?:${nsName}[@domainName]?/${interfaceName/memIfSocketName}?${label1}=${value1}&${label2}=${value2}
- mechanism one of "kernel", "memif"
- \[kernel://]nsName\[@domainName]/interfaceName?\[label1=value1\*(&labelN=valueN)]
- \[vfio://]nsName\[@domainName]?\[label1=value1\*(&labelN=valueN)]
- nsName - a Network service name requested
- domainName - a interdomain service name
- interfaceName - a kernel interface name prefix, for kernel mechanism.
- memIfSocketName - a memif socket name to use for memif mechanism.
- labelX/valueX - a pairs of labels will be passed as part of request.
- domainName - an interdomain service name
- interfaceName - a kernel interface name, for kernel mechanism
- labelN=valueN - pairs of labels will be passed as a part of the request:
- sriovToken=service.domain/capability - required label for SR-IOV mechanisms
- Examples:
- vpn/if-vpn
- default mechanism
- **vpn** network service
- **if-vpn** kernel interface
- kernel://secure-proxy@cloud2.com/if-proxy?username=jdoe&password=123456
- **kernel** mechanism
- **secure-proxy** network service at **cloud2.com**
- **if-proxy** kernel interface
- **{ username: "jdoe", password: "123456" }** request parameters
- vfio://l2-controller?sriovToken=l2.domain/1G
- **vfio** mechanism
- **l2-controller** network service
- **{ sriovToken: "l2.domain/1G" }** request parameters


# Build

Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ require (
github.com/kelseyhightower/envconfig v1.4.0
github.com/networkservicemesh/api v0.0.0-20201108204718-89d65b3605cf
github.com/networkservicemesh/sdk v0.0.0-20201116135409-a04f342c6d6f
github.com/networkservicemesh/sdk-sriov v0.0.0-20201112170026-a9166adc999f
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.7.0
github.com/spiffe/go-spiffe/v2 v2.0.0-alpha.5
github.com/stretchr/testify v1.6.1
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/sys v0.0.0-20201018230417-eeed37f84f13 // indirect
google.golang.org/genproto v0.0.0-20200615140333-fd031eab31e7 // indirect
google.golang.org/grpc v1.33.2
)
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,13 @@ github.com/nats-io/stan.go v0.6.0/go.mod h1:eIcD5bi3pqbHT/xIIvXMwvzXYElgouBvaVRf
github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d/go.mod h1:o96djdrsSGy3AWPyBgZMAGfxZNfgntdJG+11KU4QvbU=
github.com/networkservicemesh/api v0.0.0-20201108204718-89d65b3605cf h1:+qIW+H1bPwP6EZB7E5yeh8H3Ln78x+8Eo+kY4cmCGaA=
github.com/networkservicemesh/api v0.0.0-20201108204718-89d65b3605cf/go.mod h1:qvxdY1Zt4QTtiG+uH1XmjpegeHjlt5Jj4A8iK55iJPI=
github.com/networkservicemesh/sdk v0.0.0-20201112165252-b96831bc8195/go.mod h1:mVDTKBmkdxe8IiP3Un4qTFOSeBqUoJuCa7LtfEZdlTw=
github.com/networkservicemesh/sdk v0.0.0-20201116135409-a04f342c6d6f h1:Uz08LoLS3XH1pdMnBHkBzZ4BmnzXYib2gMMNbXHF5r8=
github.com/networkservicemesh/sdk v0.0.0-20201116135409-a04f342c6d6f/go.mod h1:mVDTKBmkdxe8IiP3Un4qTFOSeBqUoJuCa7LtfEZdlTw=
github.com/networkservicemesh/sdk-kernel v0.0.0-20201112165623-b7c91e5cd5e8 h1:QgVHS1oyTNiLGo9gTG1SoY7ApSM/ru5GPkRep4D3unk=
github.com/networkservicemesh/sdk-kernel v0.0.0-20201112165623-b7c91e5cd5e8/go.mod h1:1+XPo5xUc4zvEIVFuLIpodRR7qhgapUUyIwMb6kHTTw=
github.com/networkservicemesh/sdk-sriov v0.0.0-20201112170026-a9166adc999f h1:8VMxo4h74eXhZGOzwzWLhRFrK5og8o4tKi6orXhe9Dg=
github.com/networkservicemesh/sdk-sriov v0.0.0-20201112170026-a9166adc999f/go.mod h1:bAjECJzQ6LJUIvYcUPh24kZ2tV//sh9NZzanbrPkpfU=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nishanths/exhaustive v0.0.0-20200811152831-6cf413ae40e0/go.mod h1:wBEpHwM2OdmeNpdCvRPUlkEbBuaFmcK4Wv8Q7FuGW3c=
Expand Down Expand Up @@ -416,6 +421,9 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC
github.com/valyala/fasthttp v1.15.1/go.mod h1:YOKImeEosDdBPnxc0gy7INqi3m1zK6A+xl6TwOBhHCA=
github.com/valyala/quicktemplate v1.6.2/go.mod h1:mtEJpQtUiBV0SHhMX6RtiJtqxncgrfmjcUy5T68X8TM=
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE=
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
github.com/willf/bitset v1.1.10/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
Expand Down Expand Up @@ -527,6 +535,7 @@ golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190523142557-0e01d883c5c5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand All @@ -535,9 +544,11 @@ golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200217220822-9197077df867/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980 h1:OjiUf46hAmXblsZdnoSXsEUSKU8r1UEzcL5RVZ4gO9Y=
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201018230417-eeed37f84f13 h1:5jaG59Zhd+8ZXe8C+lgiAGqkOaZBruqrWclLkgAww34=
golang.org/x/sys v0.0.0-20201018230417-eeed37f84f13/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
41 changes: 25 additions & 16 deletions pkg/config/config.go → internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@ import (
"github.com/pkg/errors"

"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/vfio"
)

var configMechanisms = map[string]string{
"memif": memif.MECHANISM,
"kernel": kernel.MECHANISM,
"vfio": vfio.MECHANISM,
}

// Config - configuration for cmd-nsmgr
type Config struct {
Name string `default:"nsc" desc:"Name of Network Service Client"`
ConnectTo url.URL `default:"unix:///var/lib/networkservicemesh/nsm.io.sock" desc:"url to connect to NSM" split_words:"true"`
ConnectTimeout time.Duration `default:"5s" desc:"timeout to connect to NSMgr" split_words:"true"`
MaxTokenLifetime time.Duration `default:"24h" desc:"maximum lifetime of tokens" split_words:"true"`

Routes []string `default:"" desc:"A list of routes asked by client" split_words:"true"`
Labels []string `default:"" desc:"A list of client labels with format key1=val1,key2=val2, will be used a primary list for network services" split_words:"true"`
Mechanism string `default:"kernel" desc:"Default Mechanism to use, supported values kernel,memif" split_words:"true"`
Mechanism string `default:"kernel" desc:"Default Mechanism to use, supported values: kernel, vfio" split_words:"true"`

NetworkServices []NetworkServiceConfig `default:"" desc:"A list of Network Service Requests with format [{mechanism}]?:${nsName}[@domainName]?/${interfaceName/memIfSocketName}?${label1}=${value1}&${label2}=${value2}" split_words:"true"`
NetworkServices []NetworkServiceConfig `default:"" desc:"A list of Network Service Requests" split_words:"true"`
}

// IsValid - check if configuration is valid
Expand All @@ -52,10 +52,10 @@ func (c *Config) IsValid() error {
return errors.New("no network services are specified")
}
if c.Name == "" {
return errors.New("no cleint name specified")
return errors.New("no client name specified")
}
if c.ConnectTo.String() == "" {
return errors.New("no NSMGr ConnectTO URL are sepecified")
return errors.New("no NSMGr ConnectTO URL are specified")
}
return nil
}
Expand All @@ -74,48 +74,57 @@ func (cfg *NetworkServiceConfig) UnmarshalBinary(text []byte) error {
if err != nil {
return err
}
cfg.Mechanism = u1.Scheme

cfg.Mechanism = u1.Scheme
if cfg.Mechanism != "" {
m, ok := configMechanisms[cfg.Mechanism]
if !ok {
return errors.Errorf("invalid mechanism specified %v. Supported: %v", cfg.Mechanism, configMechanisms)
}
cfg.Mechanism = m
}

cfg.NetworkService = u1.Hostname()
cfg.Path = []string{}

for _, segm := range strings.Split(u1.Path, "/") {
if segm != "" {
cfg.Path = append(cfg.Path, segm)
}
}

for k, v := range u1.Query() {
if cfg.Labels == nil {
cfg.Labels = map[string]string{}
}
cfg.Labels[k] = v[0]
}

if cfg.NetworkService == "" && len(cfg.Path) > 0 {
cfg.NetworkService = cfg.Path[0]
cfg.Path = cfg.Path[1:]
}

return nil
}

// IsValid - check if network service request is correct.
func (cfg *NetworkServiceConfig) IsValid() error {
if cfg.Mechanism == "" {
return errors.New("invalid mechanism specified")
if cfg.NetworkService == "" {
return errors.New("no network service specified")
}
switch cfg.Mechanism {
case memif.MECHANISM:
// Verify folder for memif file exists and writable.
//TODO: Add support of this validation.
case kernel.MECHANISM:
// Verify interface name
if len(cfg.Path) > 1 {
return errors.New("invalid client interface name specified")
return errors.Errorf("invalid client interface name specified: %s", strings.Join(cfg.Path, "/"))
}
if len(cfg.Path[0]) > 15 {
return errors.New("interface part cannot exceed 15 characters")
return errors.Errorf("interface part cannot exceed 15 characters: %s", strings.Join(cfg.Path, "/"))
}
case vfio.MECHANISM:
// There should be no path
if len(cfg.Path) > 0 {
return errors.Errorf("no path supported for the VFIO mechanism: %s", strings.Join(cfg.Path, "/"))
}
}
return nil
Expand Down
Loading

0 comments on commit 4457c18

Please sign in to comment.