aboutsummaryrefslogtreecommitdiffstats
path: root/api/doc.go
blob: e1abffe738a151e5013513c00eaab5cb4a67adeb (plain)
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
// Package api provides API for communication with govpp core using Go channels,
// without the need of importing the govpp core package itself.
//
// 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.ReqChan <- &api.VppRequest{Message: req}
//
// 	// receive a reply from the reply go channel
// 	vppReply := <-ch.ReplyChan
//
// 	// 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 api