summary |
shortlog |
log |
commit | commitdiff |
review |
tree
raw |
patch |
inline | side by side (from parent 1:
2406041)
Change-Id: Idd651a29d9fc3903f52d6fe8945add3052a28b52
Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
"git.fd.io/govpp.git/core/bin_api/vpe"
)
"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
const (
requestChannelBufSize = 100 // default size of the request channel buffers
replyChannelBufSize = 100 // default size of the reply channel buffers
healthCheckThreshold = threshold
}
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) {
// 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) {
+ // 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 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
}
log.Info("Connected to VPP.")
return nil
}
func (c *Connection) connectLoop(connChan chan ConnectionEvent) {
// loop until connected
for {
func (c *Connection) connectLoop(connChan chan ConnectionEvent) {
// loop until connected
for {
+ 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
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)
}
// send the control ping
}
// send the control ping
- ch.ReqChan <- &api.VppRequest{Message: &vpe.ControlPing{}}
+ ch.ReqChan <- &api.VppRequest{Message: msgControlPing}
// expect response within timeout period
select {
// expect response within timeout period
select {
vppReply := <-ctx.ch.ReplyChan
Expect(vppReply).ShouldNot(BeNil())
vppReply := <-ctx.ch.ReplyChan
Expect(vppReply).ShouldNot(BeNil())
- case vppReply = <-ctx.ch.ReplyChan:
+ case <-ctx.ch.ReplyChan:
received = true // this should not happen
default:
received = false // no reply to be received
received = true // this should not happen
default:
received = false // no reply to be received
logger "github.com/sirupsen/logrus"
"git.fd.io/govpp.git/api"
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.
)
// watchRequests watches for requests on the request API channel and forwards them as messages to VPP.
log.WithFields(logger.Fields{
"msg_name": req.Message.GetMessageName(),
"msg_crc": req.Message.GetCrcString(),
log.WithFields(logger.Fields{
"msg_name": req.Message.GetMessageName(),
"msg_crc": req.Message.GetCrcString(),
sendReply(ch, &api.VppReply{Error: error})
return error
}
sendReply(ch, &api.VppReply{Error: error})
return error
}
if req.Multipart {
// send a control ping to determine end of the multipart response
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,
log.WithFields(logger.Fields{
"context": chMeta.id,
log.WithFields(logger.Fields{
"msg_name": msgName,
"msg_crc": msgCrc,
log.WithFields(logger.Fields{
"msg_name": msgName,
"msg_crc": msgCrc,
- }).Errorf("unable to retrieve message ID: %v", err)