- NewAPIChannelBuffered() (*Channel, error)
-}
-
-// MessageDecoder provides functionality for decoding binary data to generated API messages.
-type MessageDecoder interface {
- // DecodeMsg decodes binary-encoded data of a message into provided Message structure.
- DecodeMsg(data []byte, msg Message) error
-}
-
-// MessageIdentifier provides identification of generated API messages.
-type MessageIdentifier interface {
- // GetMessageID returns message identifier of given API message.
- GetMessageID(msg Message) (uint16, error)
- // LookupByID looks up message name and crc by ID
- LookupByID(ID uint16) (string, error)
-}
-
-// Channel is the main communication interface with govpp core. It contains two Go channels, one for sending the requests
-// to VPP and one for receiving the replies from it. The user can access the Go channels directly, or use the helper
-// methods provided inside of this package. Do not use the same channel from multiple goroutines concurrently,
-// otherwise the responses could mix! Use multiple channels instead.
-type Channel struct {
- ID uint16 // channel ID
-
- ReqChan chan *VppRequest // channel for sending the requests to VPP, closing this channel releases all resources in the ChannelProvider
- ReplyChan chan *VppReply // channel where VPP replies are delivered to
-
- NotifSubsChan chan *NotifSubscribeRequest // channel for sending notification subscribe requests
- NotifSubsReplyChan chan error // channel where replies to notification subscribe requests are delivered to
-
- MsgDecoder MessageDecoder // used to decode binary data to generated API messages
- MsgIdentifier MessageIdentifier // used to retrieve message ID of a message
-
- lastSeqNum uint16 // sequence number of the last sent request
-
- delayedReply *VppReply // reply already taken from ReplyChan, buffered for later delivery
- replyTimeout time.Duration // maximum time that the API waits for a reply from VPP before returning an error, can be set with SetReplyTimeout
-}
-
-// VppRequest is a request that will be sent to VPP.
-type VppRequest struct {
- SeqNum uint16 // sequence number
- Message Message // binary API message to be send to VPP
- Multipart bool // true if multipart response is expected, false otherwise
-}
-
-// VppReply is a reply received from VPP.
-type VppReply struct {
- MessageID uint16 // ID of the message
- SeqNum uint16 // sequence number
- Data []byte // encoded data with the message - MessageDecoder can be used for decoding
- LastReplyReceived bool // in case of multipart replies, true if the last reply has been already received and this one should be ignored
- Error error // in case of error, data is nil and this member contains error description
-}
-
-// NotifSubscribeRequest is a request to subscribe for delivery of specific notification messages.
-type NotifSubscribeRequest struct {
- Subscription *NotifSubscription // subscription details
- Subscribe bool // true if this is a request to subscribe, false if unsubscribe
-}
-
-// NotifSubscription represents a subscription for delivery of specific notification messages.
-type NotifSubscription struct {
- NotifChan chan Message // channel where notification messages will be delivered to
- MsgFactory func() Message // function that returns a new instance of the specific message that is expected as a notification
-}
-
-// RequestCtx is a context of a ongoing request (simple one - only one response is expected).
-type RequestCtx struct {
- ch *Channel
- seqNum uint16
-}
-
-// MultiRequestCtx is a context of a ongoing multipart request (multiple responses are expected).
-type MultiRequestCtx struct {
- ch *Channel
- seqNum uint16
-}
-
-const defaultReplyTimeout = time.Second * 1 // default timeout for replies from VPP, can be changed with SetReplyTimeout
-
-// NewChannelInternal returns a new channel structure.
-// Note that this is just a raw channel not yet connected to VPP, it is not intended to be used directly.
-// Use ChannelProvider to get an API channel ready for communication with VPP.
-func NewChannelInternal(id uint16) *Channel {
- return &Channel{
- ID: id,
- replyTimeout: defaultReplyTimeout,
- }
-}
-
-// SetReplyTimeout sets the timeout for replies from VPP. It represents the maximum time the API waits for a reply
-// from VPP before returning an error.
-func (ch *Channel) SetReplyTimeout(timeout time.Duration) {
- ch.replyTimeout = timeout