make api.Channel as interface
[govpp.git] / core / doc.go
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.
3 //
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:
6 //
7 //      conn, err := govpp.Connect()
8 //      if err != nil {
9 //              // handle error!
10 //      }
11 //      defer conn.Disconnect()
12 //
13 //      ch, err := conn.NewAPIChannel()
14 //      if err != nil {
15 //              // handle error!
16 //      }
17 //      defer ch.Close()
18 //
19 // Note that one application can open only one connection, that can serve multiple API channels.
20 //
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.
23 //
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:
26 //
27 //      conn, err := govpp.Connect()
28 //      if err != nil {
29 //              // handle error!
30 //      }
31 //      defer conn.Disconnect()
32 //
33 //      ch, err := conn.NewAPIChannel()
34 //      if err != nil {
35 //              // handle error!
36 //      }
37 //      defer ch.Close()
38 //
39 //
40 // Simple Request-Reply API
41 //
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:
44 //
45 //      req := &acl.ACLPluginGetVersion{}
46 //      reply := &acl.ACLPluginGetVersionReply{}
47 //
48 //      err := ch.SendRequest(req).ReceiveReply(reply)
49 //      // process the reply
50 //
51 // Note that if the reply message type that comes from VPP does not match with provided one, you'll get an error.
52 //
53 //
54 // Multipart Reply API
55 //
56 // If multiple messages are expected as a reply to a request, SendMultiRequest API must be used:
57 //
58 //      req := &interfaces.SwInterfaceDump{}
59 //      reqCtx := ch.SendMultiRequest(req)
60 //
61 //      for {
62 //              reply := &interfaces.SwInterfaceDetails{}
63 //              stop, err := reqCtx.ReceiveReply(reply)
64 //              if stop {
65 //                      break // break out of the loop
66 //              }
67 //              // process the reply
68 //      }
69 //
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.
72 //
73 //
74 // Go Channels API
75 //
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:
79 //
80 //      req := &acl.ACLPluginGetVersion{}
81 //      // send the request to the request go channel
82 //      ch.GetRequestChannel <- &api.VppRequest{Message: req}
83 //
84 //      // receive a reply from the reply go channel
85 //      vppReply := <-ch.GetReplyChannel
86 //
87 //      // decode the message
88 //      reply := &acl.ACLPluginGetVersionReply{}
89 //      err := ch.MsgDecoder.DecodeMsg(vppReply.Data, reply)
90 //
91 //      // process the reply
92 //
93 //
94 // Notifications API
95 //
96 // to subscribe for receiving of the specified notification messages via provided Go channel, use the
97 // SubscribeNotification API:
98 //
99 //      // subscribe for specific notification message
100 //      notifChan := make(chan api.Message, 100)
101 //      subs, _ := ch.SubscribeNotification(notifChan, interfaces.NewSwInterfaceSetFlags)
102 //
103 //      // receive one notification
104 //      notif := (<-notifChan).(*interfaces.SwInterfaceSetFlags)
105 //
106 //      ch.UnsubscribeNotification(subs)
107 //
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.
110 //
111 package core