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