aboutsummaryrefslogtreecommitdiffstats
path: root/core/request_handler.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/request_handler.go')
-rw-r--r--core/request_handler.go88
1 files changed, 29 insertions, 59 deletions
diff --git a/core/request_handler.go b/core/request_handler.go
index fc704cb..851ac64 100644
--- a/core/request_handler.go
+++ b/core/request_handler.go
@@ -23,7 +23,7 @@ import (
logger "github.com/sirupsen/logrus"
- "git.fd.io/govpp.git/api"
+ "go.fd.io/govpp/api"
)
var ReplyChannelTimeout = time.Millisecond * 100
@@ -55,51 +55,6 @@ func (c *Connection) watchRequests(ch *Channel) {
}
// processRequest processes a single request received on the request channel.
-func (c *Connection) sendMessage(context uint32, msg api.Message) error {
- // check whether we are connected to VPP
- if atomic.LoadUint32(&c.vppConnected) == 0 {
- return ErrNotConnected
- }
-
- /*log := log.WithFields(logger.Fields{
- "context": context,
- "msg_name": msg.GetMessageName(),
- "msg_crc": msg.GetCrcString(),
- })*/
-
- // retrieve message ID
- msgID, err := c.GetMessageID(msg)
- if err != nil {
- //log.WithError(err).Debugf("unable to retrieve message ID: %#v", msg)
- return err
- }
-
- //log = log.WithField("msg_id", msgID)
-
- // encode the message
- data, err := c.codec.EncodeMsg(msg, msgID)
- if err != nil {
- log.WithError(err).Debugf("unable to encode message: %#v", msg)
- return err
- }
-
- //log = log.WithField("msg_length", len(data))
-
- if log.Level >= logger.DebugLevel {
- log.Debugf("--> SEND: MSG %T %+v", msg, msg)
- }
-
- // send message to VPP
- err = c.vppClient.SendMsg(context, data)
- if err != nil {
- log.WithError(err).Debugf("unable to send message: %#v", msg)
- return err
- }
-
- return nil
-}
-
-// processRequest processes a single request received on the request channel.
func (c *Connection) processRequest(ch *Channel, req *vppRequest) error {
// check whether we are connected to VPP
if atomic.LoadUint32(&c.vppConnected) == 0 {
@@ -157,6 +112,7 @@ func (c *Connection) processRequest(ch *Channel, req *vppRequest) error {
}
// send the request to VPP
+ t := time.Now()
err = c.vppClient.SendMsg(context, data)
if err != nil {
log.WithFields(logger.Fields{
@@ -172,6 +128,7 @@ func (c *Connection) processRequest(ch *Channel, req *vppRequest) error {
}).Warnf("Unable to send message")
return err
}
+ c.trace(req.msg, ch.id, t, false)
if req.multi {
// send a control ping to determine end of the multipart response
@@ -189,6 +146,7 @@ func (c *Connection) processRequest(ch *Channel, req *vppRequest) error {
}).Debugf(" -> SEND MSG: %T", c.msgControlPing)
}
+ t = time.Now()
if err := c.vppClient.SendMsg(context, pingData); err != nil {
log.WithFields(logger.Fields{
"context": context,
@@ -196,6 +154,7 @@ func (c *Connection) processRequest(ch *Channel, req *vppRequest) error {
"error": err,
}).Warnf("unable to send control ping")
}
+ c.trace(c.msgControlPing, ch.id, t, false)
}
return nil
@@ -210,9 +169,9 @@ func (c *Connection) msgCallback(msgID uint16, data []byte) {
return
}
- msg, ok := c.msgMap[msgID]
- if !ok {
- log.Warnf("Unknown message received, ID: %d", msgID)
+ msg, err := c.getMessageByID(msgID)
+ if err != nil {
+ log.Warnln(err)
return
}
@@ -221,7 +180,7 @@ func (c *Connection) msgCallback(msgID uint16, data []byte) {
// - replies that don't have context as first field (comes as zero)
// - events that don't have context at all (comes as non zero)
//
- context, err := c.codec.DecodeMsgContext(data, msg)
+ context, err := c.codec.DecodeMsgContext(data, msg.GetMessageType())
if err != nil {
log.WithField("msg_id", msgID).Warnf("Unable to decode message context: %v", err)
return
@@ -229,15 +188,15 @@ func (c *Connection) msgCallback(msgID uint16, data []byte) {
chanID, isMulti, seqNum := unpackRequestContext(context)
- if log.Level == logger.DebugLevel { // for performance reasons - logrus does some processing even if debugs are disabled
- msg = reflect.New(reflect.TypeOf(msg).Elem()).Interface().(api.Message)
-
- // decode the message
- if err = c.codec.DecodeMsg(data, msg); err != nil {
- err = fmt.Errorf("decoding message failed: %w", err)
- return
- }
+ // decode and trace the message
+ msg = reflect.New(reflect.TypeOf(msg).Elem()).Interface().(api.Message)
+ if err = c.codec.DecodeMsg(data, msg); err != nil {
+ log.WithField("msg", msg).Warnf("Unable to decode message: %v", err)
+ return
+ }
+ c.trace(msg, chanID, time.Now(), true)
+ if log.Level == logger.DebugLevel { // for performance reasons - logrus does some processing even if debugs are disabled
log.WithFields(logger.Fields{
"context": context,
"msg_id": msgID,
@@ -246,7 +205,7 @@ func (c *Connection) msgCallback(msgID uint16, data []byte) {
"is_multi": isMulti,
"seq_num": seqNum,
"msg_crc": msg.GetCrcString(),
- }).Debugf("<-- govpp RECEIVE: %s %+v", msg.GetMessageName(), msg)
+ }).Debugf("<-- govpp RECEIVE: %s", msg.GetMessageName())
}
if context == 0 || c.isNotificationMessage(msgID) {
@@ -419,3 +378,14 @@ func compareSeqNumbers(seqNum1, seqNum2 uint16) int {
}
return 1
}
+
+// Returns message based on the message ID not depending on message path
+func (c *Connection) getMessageByID(msgID uint16) (msg api.Message, err error) {
+ var ok bool
+ for _, messages := range c.msgMapByPath {
+ if msg, ok = messages[msgID]; ok {
+ return msg, nil
+ }
+ }
+ return nil, fmt.Errorf("unknown message received, ID: %d", msgID)
+}