From b2670b8eab9f03cd5678497557c6c6fa850dc080 Mon Sep 17 00:00:00 2001 From: Vladimir Popov Date: Thu, 26 Aug 2021 17:46:18 +0700 Subject: [PATCH 1/2] Use existing VPP instance if given Signed-off-by: Vladimir Popov --- go.mod | 2 +- go.sum | 4 ++-- main.go | 16 +++++++++++++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index c198189..d859cd0 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/antonfisher/nested-logrus-formatter v1.3.0 github.com/edwarnicke/debug v1.0.0 github.com/edwarnicke/grpcfd v0.1.0 - github.com/edwarnicke/vpphelper v0.0.0-20210225052320-b4f1f1aff45d + github.com/edwarnicke/vpphelper v0.0.0-20210512223648-f914b171f679 github.com/kelseyhightower/envconfig v1.4.0 github.com/networkservicemesh/api v1.0.1-0.20210811070028-10403c0f20c8 github.com/networkservicemesh/sdk v0.5.1-0.20210823074050-b1370083e4e1 diff --git a/go.sum b/go.sum index dd23bf7..f63946f 100644 --- a/go.sum +++ b/go.sum @@ -45,8 +45,8 @@ github.com/edwarnicke/log v1.0.0/go.mod h1:eWsQQlQ0IU5wHlJvyXFH3dS8s2g9GzN7JnXod github.com/edwarnicke/serialize v0.0.0-20200705214914-ebc43080eecf/go.mod h1:XvbCO/QGsl3X8RzjBMoRpkm54FIAZH5ChK2j+aox7pw= github.com/edwarnicke/serialize v1.0.7 h1:geX8vmyu8Ij2S5fFIXjy9gBDkKxXnrMIzMoDvV0Ddac= github.com/edwarnicke/serialize v1.0.7/go.mod h1:y79KgU2P7ALH/4j37uTSIdNavHFNttqN7pzO6Y8B2aw= -github.com/edwarnicke/vpphelper v0.0.0-20210225052320-b4f1f1aff45d h1:Okg1uazbTBFvNTrWP5AbTLgG/xMsnZNIobxJYpyvyK8= -github.com/edwarnicke/vpphelper v0.0.0-20210225052320-b4f1f1aff45d/go.mod h1:2KXgJqOUUCh9S4Zs2jAycQLqAcRGge3q+GXV2rN55ZQ= +github.com/edwarnicke/vpphelper v0.0.0-20210512223648-f914b171f679 h1:TQGpOyiM1EZtGzKN5vwN5RLHc0Mskk9uh+aNsdynb1k= +github.com/edwarnicke/vpphelper v0.0.0-20210512223648-f914b171f679/go.mod h1:2KXgJqOUUCh9S4Zs2jAycQLqAcRGge3q+GXV2rN55ZQ= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= diff --git a/main.go b/main.go index b7151b1..d2c11e6 100644 --- a/main.go +++ b/main.go @@ -53,7 +53,7 @@ import ( "github.com/networkservicemesh/sdk/pkg/tools/token" ) -// Config - configuration for cmd-forwarder-vpp +// Config - configuration for cmd-nsc-vpp type Config struct { Name string `default:"cmd-nsc-vpp" desc:"Name of Endpoint"` DialTimeout time.Duration `default:"5s" desc:"timeout to dial NSMgr" split_words:"true"` @@ -61,6 +61,7 @@ type Config struct { ConnectTo url.URL `default:"unix:///var/lib/networkservicemesh/nsm.io.sock" desc:"url to connect to" split_words:"true"` MaxTokenLifetime time.Duration `default:"10m" desc:"maximum lifetime of tokens" split_words:"true"` NetworkServices []url.URL `default:"" desc:"A list of Network Service Requests" split_words:"true"` + VppAPISocket string `default:"" desc:"filename of socket to connect to existing VPP instance. If empty a VPP instance is run in client" split_words:"true"` } func main() { @@ -115,8 +116,17 @@ func main() { // ******************************************************************************** now = time.Now() - vppConn, vppErrCh := vpphelper.StartAndDialContext(ctx) - exitOnErrCh(ctx, cancel, vppErrCh) + var vppConn vpphelper.Connection + var vppErrCh <-chan error + if config.VppAPISocket != "" { // If we have a VppAPISocket, use that + vppConn = vpphelper.DialContext(ctx, config.VppAPISocket) + errCh := make(chan error) + close(errCh) + vppErrCh = errCh + } else { // If we don't have a VPPAPISocket, start VPP and use that + vppConn, vppErrCh = vpphelper.StartAndDialContext(ctx) + exitOnErrCh(ctx, cancel, vppErrCh) + } defer func() { cancel() From d9c1d98befcda1a30c2da69086ba9006dd5696ad Mon Sep 17 00:00:00 2001 From: Vladimir Popov Date: Thu, 26 Aug 2021 19:47:41 +0700 Subject: [PATCH 2/2] Increase golangci funlen limit Signed-off-by: Vladimir Popov --- .golangci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index b187efa..4642c69 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -35,8 +35,8 @@ linters-settings: dupl: threshold: 150 funlen: - Lines: 150 - Statements: 70 + Lines: 170 + Statements: 80 goconst: min-len: 2 min-occurrences: 2