aboutsummaryrefslogtreecommitdiffstats
path: root/core/connection.go
diff options
context:
space:
mode:
authorOndrej Fabry <ofabry@cisco.com>2019-02-19 13:57:12 +0100
committerOndrej Fabry <ofabry@cisco.com>2019-02-19 14:02:45 +0100
commit45e38494c1d65ad9178ad15f4048c0ab16f98b77 (patch)
treedfbc70131af8faff5fde24fc1bbca8a72a91c102 /core/connection.go
parentdf05a70f90a1486a86a4156b1b0d68c94f2098b4 (diff)
Introduce higer-level API for retrieving statistics
- see stats-api example Change-Id: I11d29d32b60d25238e75cb6b86ee34842348ab38 Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'core/connection.go')
-rw-r--r--core/connection.go25
1 files changed, 20 insertions, 5 deletions
diff --git a/core/connection.go b/core/connection.go
index 14b0af4..a21cc28 100644
--- a/core/connection.go
+++ b/core/connection.go
@@ -41,7 +41,7 @@ var (
HealthCheckThreshold = 1 // number of failed health checks until the error is reported
DefaultReplyTimeout = time.Second * 1 // default timeout for replies from VPP
ReconnectInterval = time.Second * 1 // default interval for reconnect attempts
- MaxReconnectAttempts = 10 // maximum number of reconnect attempts
+ MaxReconnectAttempts = 3 // maximum number of reconnect attempts
)
// ConnectionState represents the current state of the connection to VPP.
@@ -58,6 +58,19 @@ const (
Failed
)
+func (s ConnectionState) String() string {
+ switch s {
+ case Connected:
+ return "Connected"
+ case Disconnected:
+ return "Disconnected"
+ case Failed:
+ return "Failed"
+ default:
+ return fmt.Sprintf("UnknownState(%d)", s)
+ }
+}
+
// ConnectionEvent is a notification about change in the VPP connection state.
type ConnectionEvent struct {
// Timestamp holds the time when the event has been created.
@@ -72,7 +85,8 @@ type ConnectionEvent struct {
// Connection represents a shared memory connection to VPP via vppAdapter.
type Connection struct {
- vppClient adapter.VppAPI // VPP binary API client adapter
+ vppClient adapter.VppAPI // VPP binary API client
+ //statsClient adapter.StatsAPI // VPP stats API client
vppConnected uint32 // non-zero if the adapter is connected to VPP
@@ -107,8 +121,9 @@ func newConnection(binapi adapter.VppAPI) *Connection {
return c
}
-// Connect connects to VPP using specified VPP adapter and returns the connection handle.
-// This call blocks until VPP is connected, or an error occurs. Only one connection attempt will be performed.
+// Connect connects to VPP API using specified adapter and returns a connection handle.
+// This call blocks until it is either connected, or an error occurs.
+// Only one connection attempt will be performed.
func Connect(binapi adapter.VppAPI) (*Connection, error) {
// create new connection handle
c := newConnection(binapi)
@@ -158,7 +173,7 @@ func (c *Connection) connectVPP() error {
return nil
}
-// Disconnect disconnects from VPP and releases all connection-related resources.
+// Disconnect disconnects from VPP API and releases all connection-related resources.
func (c *Connection) Disconnect() {
if c == nil {
return