1 // Package core provides connectivity to VPP via the adapter: sends and receives the messages to/from VPP,
2 // marshalls/unmarshalls them and forwards them between the client Go channels and the VPP.
4 // The interface_plugin APIs the core exposes is tied to a connection: Connect provides a connection, that cane be
5 // later used to request an API channel via NewAPIChannel / NewAPIChannelBuffered functions:
7 // conn, err := govpp.Connect()
11 // defer conn.Disconnect()
13 // ch, err := conn.NewAPIChannel()
19 // Note that one application can open only one connection, that can serve multiple API channels.
21 // The API offers two ways of communication with govpp core: using Go channels, or using convenient function
22 // wrappers over the Go channels. The latter should be sufficient for most of the use cases.
24 // The entry point to the API is the Channel structure, that can be obtained from the existing connection using
25 // the NewAPIChannel or NewAPIChannelBuffered functions:
27 // conn, err := govpp.Connect()
31 // defer conn.Disconnect()
33 // ch, err := conn.NewAPIChannel()
40 // Simple Request-Reply API
42 // The simple version of the API is based on blocking SendRequest / ReceiveReply calls, where a single request
43 // message is sent to VPP and a single reply message is filled in when the reply comes from VPP:
45 // req := &acl.ACLPluginGetVersion{}
46 // reply := &acl.ACLPluginGetVersionReply{}
48 // err := ch.SendRequest(req).ReceiveReply(reply)
49 // // process the reply
51 // Note that if the reply message type that comes from VPP does not match with provided one, you'll get an error.
54 // Multipart Reply API
56 // If multiple messages are expected as a reply to a request, SendMultiRequest API must be used:
58 // req := &interfaces.SwInterfaceDump{}
59 // reqCtx := ch.SendMultiRequest(req)
62 // reply := &interfaces.SwInterfaceDetails{}
63 // stop, err := reqCtx.ReceiveReply(reply)
65 // break // break out of the loop
67 // // process the reply
70 // Note that if the last reply has been already consumed, stop boolean return value is set to true.
71 // Do not use the message itself if stop is true - it won't be filled with actual data.
76 // The blocking API introduced above may be not sufficient for some management applications that strongly
77 // rely on usage of Go channels. In this case, the API allows to access the underlying Go channels directly, e.g.
78 // the following replacement of the SendRequest / ReceiveReply API:
80 // req := &acl.ACLPluginGetVersion{}
81 // // send the request to the request go channel
82 // ch.GetRequestChannel <- &api.VppRequest{Message: req}
84 // // receive a reply from the reply go channel
85 // vppReply := <-ch.GetReplyChannel
87 // // decode the message
88 // reply := &acl.ACLPluginGetVersionReply{}
89 // err := ch.MsgDecoder.DecodeMsg(vppReply.Data, reply)
91 // // process the reply
96 // to subscribe for receiving of the specified notification messages via provided Go channel, use the
97 // SubscribeNotification API:
99 // // subscribe for specific notification message
100 // notifChan := make(chan api.Message, 100)
101 // subs, _ := ch.SubscribeNotification(notifChan, interfaces.NewSwInterfaceSetFlags)
103 // // receive one notification
104 // notif := (<-notifChan).(*interfaces.SwInterfaceSetFlags)
106 // ch.UnsubscribeNotification(subs)
108 // Note that the caller is responsible for creating the Go channel with preferred buffer size. If the channel's
109 // buffer is full, the notifications will not be delivered into it.