aboutsummaryrefslogtreecommitdiffstats
path: root/adapter
diff options
context:
space:
mode:
authorOndrej Fabry <ofabry@cisco.com>2019-07-19 05:42:41 +0200
committerOndrej Fabry <ofabry@cisco.com>2019-07-19 05:42:41 +0200
commitbde85d422c7949ec32fb067e9c36320ccc47fb9e (patch)
tree10203b958ed04f12da7556356b5dcf3f70571bc7 /adapter
parent4dca07c803308611275f78b490ac0352c1052fe2 (diff)
Print info for users to stderr when socket files are missing
Change-Id: Ibdbfcb78b05cf80945a93ed424a7a2a03b6ea06d Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'adapter')
-rw-r--r--adapter/socketclient/socketclient.go26
-rw-r--r--adapter/statsclient/stat_segment.go4
-rw-r--r--adapter/statsclient/statsclient.go35
3 files changed, 47 insertions, 18 deletions
diff --git a/adapter/socketclient/socketclient.go b/adapter/socketclient/socketclient.go
index 96f23e6..2144d24 100644
--- a/adapter/socketclient/socketclient.go
+++ b/adapter/socketclient/socketclient.go
@@ -40,6 +40,20 @@ const (
DefaultSocketName = adapter.DefaultBinapiSocket
)
+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
@@ -165,7 +179,13 @@ func (c *vppClient) SetMsgCallback(cb adapter.MsgCallback) {
}
func (c *vppClient) Connect() error {
- Log.Debugf("Connecting to: %v", c.sockAddr)
+ // check if socket exists
+ if _, err := os.Stat(c.sockAddr); os.IsNotExist(err) {
+ fmt.Fprintf(os.Stderr, socketMissing, c.sockAddr)
+ 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)
+ }
if err := c.connect(c.sockAddr); err != nil {
return err
@@ -212,12 +232,14 @@ func (c *vppClient) Disconnect() error {
func (c *vppClient) connect(sockAddr string) error {
addr := &net.UnixAddr{Name: sockAddr, Net: "unix"}
+ Log.Debugf("Connecting to: %v", c.sockAddr)
+
conn, err := net.DialUnix("unix", nil, addr)
if err != nil {
// we try different type of socket for backwards compatbility with VPP<=19.04
if strings.Contains(err.Error(), "wrong type for socket") {
addr.Net = "unixpacket"
- Log.Warnf("%s, retrying connect with type unixpacket", err)
+ Log.Debugf("%s, retrying connect with type unixpacket", err)
conn, err = net.DialUnix("unixpacket", nil, addr)
}
if err != nil {
diff --git a/adapter/statsclient/stat_segment.go b/adapter/statsclient/stat_segment.go
index 1875f17..e8d20b0 100644
--- a/adapter/statsclient/stat_segment.go
+++ b/adapter/statsclient/stat_segment.go
@@ -117,11 +117,11 @@ func (c *statSegment) connect(sockName string) error {
header := c.readHeader()
Log.Debugf("stat segment header: %+v", header)
- // older VPP (19.04) did not have version in stat segment header
+ // older VPP (<=19.04) did not have version in stat segment header
// we try to provide fallback support by skipping it in header
if header.version > MaxVersion && header.inProgress > 1 && header.epoch == 0 {
h := c.readHeaderOld()
- Log.Warnf("statsclient: falling back to old stat segment version (VPP 19.04): %+v", h)
+ Log.Debugf("statsclient: falling back to old stat segment version (VPP <=19.04): %+v", h)
c.oldHeader = true
}
diff --git a/adapter/statsclient/statsclient.go b/adapter/statsclient/statsclient.go
index f715a70..6381b9f 100644
--- a/adapter/statsclient/statsclient.go
+++ b/adapter/statsclient/statsclient.go
@@ -27,6 +27,25 @@ import (
"git.fd.io/govpp.git/adapter"
)
+const (
+ // DefaultSocketName is default VPP stats socket file path.
+ DefaultSocketName = adapter.DefaultStatsSocket
+)
+
+const socketMissing = `
+------------------------------------------------------------
+ VPP stats socket file %s is missing!
+
+ - is VPP running with stats segment enabled?
+ - is the correct socket name configured?
+
+ To enable it add following section to your VPP config:
+ statseg {
+ default
+ }
+------------------------------------------------------------
+`
+
var (
// Debug is global variable that determines debug mode
Debug = os.Getenv("DEBUG_GOVPP_STATS") != ""
@@ -55,29 +74,17 @@ type StatsClient struct {
// NewStatsClient returns new VPP stats API client.
func NewStatsClient(sockAddr string) *StatsClient {
if sockAddr == "" {
- sockAddr = adapter.DefaultStatsSocket
+ sockAddr = DefaultSocketName
}
return &StatsClient{
sockAddr: sockAddr,
}
}
-const sockNotFoundWarn = `stats socket not found at: %s
-------------------------------------------------------------
- VPP stats socket is missing!
- Is VPP running with stats segment enabled?
-
- To enable it add following section to startup config:
- statseg {
- default
- }
-------------------------------------------------------------
-`
-
func (c *StatsClient) Connect() error {
// check if socket exists
if _, err := os.Stat(c.sockAddr); os.IsNotExist(err) {
- Log.Warnf(sockNotFoundWarn, c.sockAddr)
+ fmt.Fprintf(os.Stderr, socketMissing, c.sockAddr)
return fmt.Errorf("stats socket file %s does not exist", c.sockAddr)
} else if err != nil {
return fmt.Errorf("stats socket error: %v", err)