summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOndrej Fabry <ofabry@cisco.com>2018-03-13 13:02:39 +0100
committerOndrej Fabry <ofabry@cisco.com>2018-03-13 13:02:39 +0100
commit4df448ad6cdfa2e60fa0167e5f70cc1127fbd3bf (patch)
tree3f203ea2d5395c814072c3507d151af03f758f3a
parent2406041faa197799c7715f815cbd391a5c0e9ad3 (diff)
Add API to set ControlPing msg and fail connect on unknown ID
Change-Id: Idd651a29d9fc3903f52d6fe8945add3052a28b52 Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
-rw-r--r--core/core.go34
-rw-r--r--core/core_test.go4
-rw-r--r--core/request_handler.go8
3 files changed, 33 insertions, 13 deletions
diff --git a/core/core.go b/core/core.go
index 86cdd73..b912715 100644
--- a/core/core.go
+++ b/core/core.go
@@ -30,6 +30,11 @@ import (
"git.fd.io/govpp.git/core/bin_api/vpe"
)
+var (
+ msgControlPing api.Message = &vpe.ControlPing{}
+ msgControlPingReply api.Message = &vpe.ControlPingReply{}
+)
+
const (
requestChannelBufSize = 100 // default size of the request channel buffers
replyChannelBufSize = 100 // default size of the reply channel buffers
@@ -128,6 +133,12 @@ func SetHealthCheckThreshold(threshold int) {
healthCheckThreshold = threshold
}
+// SetControlPingMessages sets the messages for ControlPing and ControlPingReply
+func SetControlPingMessages(controPing, controlPingReply api.Message) {
+ msgControlPing = controPing
+ msgControlPingReply = controlPingReply
+}
+
// 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.
func Connect(vppAdapter adapter.VppAdapter) (*Connection, error) {
@@ -210,13 +221,19 @@ func (c *Connection) connectVPP() error {
return err
}
+ // store control ping IDs
+ if c.pingReqID, err = c.GetMessageID(msgControlPing); err != nil {
+ c.vpp.Disconnect()
+ return err
+ }
+ if c.pingReplyID, err = c.GetMessageID(msgControlPingReply); err != nil {
+ c.vpp.Disconnect()
+ return err
+ }
+
// store connected state
atomic.StoreUint32(&c.connected, 1)
- // store control ping IDs
- c.pingReqID, _ = c.GetMessageID(&vpe.ControlPing{})
- c.pingReplyID, _ = c.GetMessageID(&vpe.ControlPingReply{})
-
log.Info("Connected to VPP.")
return nil
}
@@ -233,11 +250,16 @@ func (c *Connection) disconnectVPP() {
func (c *Connection) connectLoop(connChan chan ConnectionEvent) {
// loop until connected
for {
- c.vpp.WaitReady()
+ if err := c.vpp.WaitReady(); err != nil {
+ log.Warnf("wait ready failed: %v", err)
+ }
if err := c.connectVPP(); err == nil {
// signal connected event
connChan <- ConnectionEvent{Timestamp: time.Now(), State: Connected}
break
+ } else {
+ log.Errorf("connecting to VPP failed: %v", err)
+ time.Sleep(time.Second)
}
}
@@ -268,7 +290,7 @@ func (c *Connection) healthCheckLoop(connChan chan ConnectionEvent) {
}
// send the control ping
- ch.ReqChan <- &api.VppRequest{Message: &vpe.ControlPing{}}
+ ch.ReqChan <- &api.VppRequest{Message: msgControlPing}
// expect response within timeout period
select {
diff --git a/core/core_test.go b/core/core_test.go
index 682309d..e80f97c 100644
--- a/core/core_test.go
+++ b/core/core_test.go
@@ -207,9 +207,9 @@ func TestFullBuffer(t *testing.T) {
vppReply := <-ctx.ch.ReplyChan
Expect(vppReply).ShouldNot(BeNil())
- received := false
+ var received bool
select {
- case vppReply = <-ctx.ch.ReplyChan:
+ case <-ctx.ch.ReplyChan:
received = true // this should not happen
default:
received = false // no reply to be received
diff --git a/core/request_handler.go b/core/request_handler.go
index c1683d3..dc02ee7 100644
--- a/core/request_handler.go
+++ b/core/request_handler.go
@@ -22,7 +22,6 @@ import (
logger "github.com/sirupsen/logrus"
"git.fd.io/govpp.git/api"
- "git.fd.io/govpp.git/core/bin_api/vpe"
)
// watchRequests watches for requests on the request API channel and forwards them as messages to VPP.
@@ -62,7 +61,7 @@ func (c *Connection) processRequest(ch *api.Channel, chMeta *channelMetadata, re
log.WithFields(logger.Fields{
"msg_name": req.Message.GetMessageName(),
"msg_crc": req.Message.GetCrcString(),
- }).Error(err)
+ }).Error(error)
sendReply(ch, &api.VppReply{Error: error})
return error
}
@@ -98,8 +97,7 @@ func (c *Connection) processRequest(ch *api.Channel, chMeta *channelMetadata, re
if req.Multipart {
// send a control ping to determine end of the multipart response
- ping := &vpe.ControlPing{}
- pingData, _ := c.codec.EncodeMsg(ping, c.pingReqID)
+ pingData, _ := c.codec.EncodeMsg(msgControlPing, c.pingReqID)
log.WithFields(logger.Fields{
"context": chMeta.id,
@@ -205,7 +203,7 @@ func (c *Connection) messageNameToID(msgName string, msgCrc string) (uint16, err
log.WithFields(logger.Fields{
"msg_name": msgName,
"msg_crc": msgCrc,
- }).Errorf("unable to retrieve message ID: %v", err)
+ }).Error(error)
return id, error
}