aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOndrej Fabry <ofabry@cisco.com>2019-09-09 06:16:18 +0200
committerOndrej Fabry <ofabry@cisco.com>2019-09-09 06:16:26 +0200
commitd06548e4f4492c181f04a5fc9bf994764278e68b (patch)
tree2b47941fe527e727d9039d50859d6c9478401be0
parent56bf21b1a9ecd1096760a5eff70ad8366bf34253 (diff)
Use new default binapi socket with fallback to legacy
Change-Id: I1a6839e3bbb8d599fcbdbc2b1aff7c81f7d263c9 Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
-rw-r--r--adapter/socketclient/socketclient.go78
-rw-r--r--adapter/vpp_api.go2
-rw-r--r--core/connection.go2
-rw-r--r--examples/simple-client/simple_client.go2
4 files changed, 61 insertions, 23 deletions
diff --git a/adapter/socketclient/socketclient.go b/adapter/socketclient/socketclient.go
index 2144d24..1c425ba 100644
--- a/adapter/socketclient/socketclient.go
+++ b/adapter/socketclient/socketclient.go
@@ -38,22 +38,9 @@ import (
const (
// DefaultSocketName is default VPP API socket file path.
DefaultSocketName = adapter.DefaultBinapiSocket
+ legacySocketName = "/run/vpp-api.sock"
)
-const socketMissing = `
-------------------------------------------------------------
- VPP binary API socket file %s is missing!
-
- - is VPP running with socket for binapi enabled?
- - is the correct socket name configured?
-
- To enable it add following section to your VPP config:
- socksvr {
- default
- }
-------------------------------------------------------------
-`
-
var (
// DefaultConnectTimeout is default timeout for connecting
DefaultConnectTimeout = time.Second * 3
@@ -85,6 +72,27 @@ func init() {
}
}
+const socketMissing = `
+------------------------------------------------------------
+ No socket file found at: %s
+ VPP binary API socket file is missing!
+
+ - is VPP running with socket for binapi enabled?
+ - is the correct socket name configured?
+
+ To enable it add following section to your VPP config:
+ socksvr {
+ default
+ }
+------------------------------------------------------------
+`
+
+var warnOnce sync.Once
+
+func (c *vppClient) printMissingSocketMsg() {
+ fmt.Fprintf(os.Stderr, socketMissing, c.sockAddr)
+}
+
type vppClient struct {
sockAddr string
@@ -129,6 +137,32 @@ func (c *vppClient) SetDisconnectTimeout(t time.Duration) {
c.disconnectTimeout = t
}
+func (c *vppClient) SetMsgCallback(cb adapter.MsgCallback) {
+ Log.Debug("SetMsgCallback")
+ c.cb = cb
+}
+
+func (c *vppClient) checkLegacySocket() bool {
+ if c.sockAddr == legacySocketName {
+ return false
+ }
+ Log.Debugf("checking legacy socket: %s", legacySocketName)
+ // check if socket exists
+ if _, err := os.Stat(c.sockAddr); err == nil {
+ return false // socket exists
+ } else if !os.IsNotExist(err) {
+ return false // some other error occurred
+ }
+ // check if legacy socket exists
+ if _, err := os.Stat(legacySocketName); err == nil {
+ // legacy socket exists, update sockAddr
+ c.sockAddr = legacySocketName
+ return true
+ }
+ // no socket socket found
+ return false
+}
+
// WaitReady checks socket file existence and waits for it if necessary
func (c *vppClient) WaitReady() error {
// check if socket already exists
@@ -138,6 +172,10 @@ func (c *vppClient) WaitReady() error {
return err // some other error occurred
}
+ if c.checkLegacySocket() {
+ return nil
+ }
+
// socket does not exist, watch for it
watcher, err := fsnotify.NewWatcher()
if err != nil {
@@ -158,6 +196,9 @@ func (c *vppClient) WaitReady() error {
for {
select {
case <-timeout.C:
+ if c.checkLegacySocket() {
+ return nil
+ }
return fmt.Errorf("timeout waiting (%s) for socket file: %s", MaxWaitReady, c.sockAddr)
case e := <-watcher.Errors:
@@ -173,15 +214,12 @@ func (c *vppClient) WaitReady() error {
}
}
-func (c *vppClient) SetMsgCallback(cb adapter.MsgCallback) {
- Log.Debug("SetMsgCallback")
- c.cb = cb
-}
-
func (c *vppClient) Connect() error {
+ c.checkLegacySocket()
+
// check if socket exists
if _, err := os.Stat(c.sockAddr); os.IsNotExist(err) {
- fmt.Fprintf(os.Stderr, socketMissing, c.sockAddr)
+ warnOnce.Do(c.printMissingSocketMsg)
return fmt.Errorf("VPP API socket file %s does not exist", c.sockAddr)
} else if err != nil {
return fmt.Errorf("VPP API socket error: %v", err)
diff --git a/adapter/vpp_api.go b/adapter/vpp_api.go
index 2391420..71bf7c2 100644
--- a/adapter/vpp_api.go
+++ b/adapter/vpp_api.go
@@ -20,7 +20,7 @@ import (
const (
// DefaultBinapiSocket defines a default socket file path for VPP binary API.
- DefaultBinapiSocket = "/run/vpp-api.sock"
+ DefaultBinapiSocket = "/run/vpp/api.sock"
)
var (
diff --git a/core/connection.go b/core/connection.go
index 605e1ef..8b8c7b1 100644
--- a/core/connection.go
+++ b/core/connection.go
@@ -260,7 +260,7 @@ func (c *Connection) connectLoop(connChan chan ConnectionEvent) {
// loop until connected
for {
if err := c.vppClient.WaitReady(); err != nil {
- log.Warnf("wait ready failed: %v", err)
+ log.Debugf("wait ready failed: %v", err)
}
if err := c.connectVPP(); err == nil {
// signal connected event
diff --git a/examples/simple-client/simple_client.go b/examples/simple-client/simple_client.go
index 609a25d..c857768 100644
--- a/examples/simple-client/simple_client.go
+++ b/examples/simple-client/simple_client.go
@@ -52,7 +52,7 @@ func main() {
select {
case e := <-conev:
if e.State != core.Connected {
- log.Fatalln("ERROR: connecting to VPP failed:", err)
+ log.Fatalln("ERROR: connecting to VPP failed:", e.Error)
}
}