-
Notifications
You must be signed in to change notification settings - Fork 82
/
doc.go
106 lines (106 loc) · 3.7 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Package core provides connectivity to VPP via the adapter: sends and receives the messages to/from VPP,
// marshalls/unmarshalls them and forwards them between the client Go channels and the VPP.
//
// The interface_plugin APIs the core exposes is tied to a connection: Connect provides a connection, that cane be
// later used to request an API channel via NewAPIChannel / NewAPIChannelBuffered functions:
//
// conn, err := govpp.Connect()
// if err != nil {
// // handle error!
// }
// defer conn.Disconnect()
//
// ch, err := conn.NewAPIChannel()
// if err != nil {
// // handle error!
// }
// defer ch.Close()
//
// Note that one application can open only one connection, that can serve multiple API channels.
//
// The API offers two ways of communication with govpp core: using Go channels, or using convenient function
// wrappers over the Go channels. The latter should be sufficient for most of the use cases.
//
// The entry point to the API is the Channel structure, that can be obtained from the existing connection using
// the NewAPIChannel or NewAPIChannelBuffered functions:
//
// conn, err := govpp.Connect()
// if err != nil {
// // handle error!
// }
// defer conn.Disconnect()
//
// ch, err := conn.NewAPIChannel()
// if err != nil {
// // handle error!
// }
// defer ch.Close()
//
// # Simple Request-Reply API
//
// The simple version of the API is based on blocking SendRequest / ReceiveReply calls, where a single request
// message is sent to VPP and a single reply message is filled in when the reply comes from VPP:
//
// req := &acl.ACLPluginGetVersion{}
// reply := &acl.ACLPluginGetVersionReply{}
//
// err := ch.SendRequest(req).ReceiveReply(reply)
// // process the reply
//
// Note that if the reply message type that comes from VPP does not match with provided one, you'll get an error.
//
// # Multipart Reply API
//
// If multiple messages are expected as a reply to a request, SendMultiRequest API must be used:
//
// req := &interfaces.SwInterfaceDump{}
// reqCtx := ch.SendMultiRequest(req)
//
// for {
// reply := &interfaces.SwInterfaceDetails{}
// stop, err := reqCtx.ReceiveReply(reply)
// if stop {
// break // break out of the loop
// }
// // process the reply
// }
//
// Note that if the last reply has been already consumed, stop boolean return value is set to true.
// Do not use the message itself if stop is true - it won't be filled with actual data.
//
// # Go Channels API
//
// The blocking API introduced above may be not sufficient for some management applications that strongly
// rely on usage of Go channels. In this case, the API allows to access the underlying Go channels directly, e.g.
// the following replacement of the SendRequest / ReceiveReply API:
//
// req := &acl.ACLPluginGetVersion{}
// // send the request to the request go channel
// ch.GetRequestChannel <- &api.VppRequest{Message: req}
//
// // receive a reply from the reply go channel
// vppReply := <-ch.GetReplyChannel
//
// // decode the message
// reply := &acl.ACLPluginGetVersionReply{}
// err := ch.MsgDecoder.DecodeMsg(vppReply.Data, reply)
//
// // process the reply
//
// # Notifications API
//
// to subscribe for receiving of the specified notification messages via provided Go channel, use the
// SubscribeNotification API:
//
// // subscribe for specific notification message
// notifChan := make(chan api.Message, 100)
// subs, _ := ch.SubscribeNotification(notifChan, interfaces.NewSwInterfaceSetFlags)
//
// // receive one notification
// notif := (<-notifChan).(*interfaces.SwInterfaceSetFlags)
//
// ch.UnsubscribeNotification(subs)
//
// Note that the caller is responsible for creating the Go channel with preferred buffer size. If the channel's
// buffer is full, the notifications will not be delivered into it.
package core