"git.fd.io/govpp.git/api"
)
+var (
+ ErrNotConnected = errors.New("not connected to VPP, ignoring the request")
+)
+
// watchRequests watches for requests on the request API channel and forwards them as messages to VPP.
func (c *Connection) watchRequests(ch *api.Channel, chMeta *channelMetadata) {
for {
func (c *Connection) processRequest(ch *api.Channel, chMeta *channelMetadata, req *api.VppRequest) error {
// check whether we are connected to VPP
if atomic.LoadUint32(&c.connected) == 0 {
- err := errors.New("not connected to VPP, ignoring the request")
+ err := ErrNotConnected
log.Error(err)
sendReply(ch, &api.VppReply{Error: err})
return err
// messageNameToID returns message ID of a message identified by its name and CRC.
func (c *Connection) messageNameToID(msgName string, msgCrc string) (uint16, error) {
+ msgKey := msgName + "_" + msgCrc
+
// try to get the ID from the map
c.msgIDsLock.RLock()
- id, ok := c.msgIDs[msgName+msgCrc]
+ id, ok := c.msgIDs[msgKey]
c.msgIDsLock.RUnlock()
if ok {
return id, nil
}
c.msgIDsLock.Lock()
- c.msgIDs[msgName+msgCrc] = id
+ c.msgIDs[msgKey] = id
c.msgIDsLock.Unlock()
return id, nil
}
+
+// LookupByID looks up message name and crc by ID.
+func (c *Connection) LookupByID(ID uint16) (string, error) {
+ if c == nil {
+ return "", errors.New("nil connection passed in")
+ }
+
+ for key, id := range c.msgIDs {
+ if id == ID {
+ return key, nil
+ }
+ }
+
+ return "", fmt.Errorf("unknown message ID: %d", ID)
+}