Skip to content

Commit

Permalink
Use existing VPP instance if given
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Popov <[email protected]>
  • Loading branch information
Vladimir Popov committed Aug 26, 2021
1 parent 9bb4e31 commit b2670b8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
16 changes: 13 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ 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"`
RequestTimeout time.Duration `default:"15s" desc:"timeout to request NSE" split_words:"true"`
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() {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit b2670b8

Please sign in to comment.