blob: 9b759e09a4449e9750eeddc0a3652b0373e378b5 [file] [log] [blame]
Maros Marsalek047bf842016-04-26 15:03:26 +02001= JVpp
2
3JVpp is JNI based Java API for VPP.
4
5== Features
6It is:
7
8* Asynchronous
9* Fully generated
10* Lightweight
11
12== Architecture
13JVpp and JNI
14
15
16 JVpp Java
17
18 /----------\ /--------\ /------------\ /------\
19 | VppConn* | | JVpp | | Callbacks | | DTOs |
20 \----+-----/ \----+---/ \------+-----/ \------/
21 ^ ^ ^
22 | implements | implements | implements
23 /----+---------\ /----+-------\ /------+-----------\
24 | VppConnImpl* +<--------+ JVppImpl | | GlobalCallback |
25 \--------------/ uses \---+--------/ \-------+----------/
26 | ^
27 | uses | calls back
28 | |
29-------------------------------|-----------------------|---------------------
30 | |
31 | +---------------+
32 C JNI | |
33 v | /------------\
34 /---+-------+--\ +---->+ jvpp.h* |
35 | +-----+ \------------/
36 | jvpp.c* |
37 | +-----+ /------------\
38 \--------------/ +---->+ jvpp_gen.h |
39 \------------/
40
41* Components marked with an asterisk contain manually crafted Java code, which in addition
42to generated classes form jvpp. Exception applies to Callbacks and DTOs, since there are
43manually crafted marker interfaces in callback and dto package (dto/JVppRequest, dto/JVppReply,
44dto/JVppDump, dto/JVppReplyDump, callback/JVppCallback)
45
46Note: jvpp.c calls back the GlobalCallback instance with every response. An instance of the
47GlobalCallback is provided to jvpp.c by VppConnImpl while connecting to VPP.
48
49Part of the JVpp is also Future facade. It is asynchronous API returning Future objects
50on top of low level JVpp.
51
52
53Future facade
54
55 /-------------\ /--------------------\
56 | FutureJVpp* | +-->+ FutureJVppRegistry |
57 \-----+-------/ | \----------+---------/
58 ^ | ^
59 | implements | uses | uses
60 | | |
61 /--------+----------\ | /----------+---------\
62 | FutureJVppFacade* +----+ | FutureJVppCallback |
63 \---------+---------/ \----------+---------/
64 | |
65---------------|-----------------------------|-------------------------------
66 | uses | implements
67JVpp Java | |
68 | |
69 /---------\ | |
70 | JVpp +<--+ |
71 \----+----/ |
72 ^ |
73 | implements v
74 /----+-------\ /----------+-------\
75 | JVppImpl | | GlobalCallback |
76 \------------/ \------------------/
77
78
79
80Another useful utility of the JVpp is Callback facade. It is asynchronous API
81capable of calling specific callback instance (provided when performing a call)
82per call.
83
84
85Callback facade
86
87 /--------------\ /----------------------\
88 | CallbackJVpp | +-->+ CallbackJVppRegistry |
89 \-----+--------/ | \----------+-----------/
90 ^ | ^
91 | implements | uses | uses
92 | | |
93 /--------+-----------\ | /----------+-----------\
94 | CallbackJVppFacade +-----+ | CallbackJVppCallback |
95 \---------+----------/ \----------+-----------/
96 | |
97---------------|-----------------------------|-------------------------------
98 | uses | implements
99JVpp Java | |
100 | |
101 /---------\ | |
102 | JVpp +<--+ |
103 \----+----/ |
104 ^ |
105 | implements v
106 /----+-------\ /----------+-------\
107 | JVppImpl | | GlobalCallback |
108 \------------/ \------------------/
109
110
111
112== Package structure
113
114* *org.openvpp.jvpp* - top level package for generated JVpp interface+ implementation and hand-crafted
115VppConnection interface + implementation
116
117** *dto* - package for DTOs generated from VPP API structures + base/marker hand-crafted interfaces
118** *callback* - package for low-level JVpp callbacks and a global callback interface implementing each of the low-level JVppcallbacks
119** *future* - package for future based facade on top of JVpp and callbacks
120** *callfacade* - package for callback based facade on top of JVpp and callbacks. Allowing
121users to provide callback per request
122** *test* - package for JVpp standalone tests. Can also serve as samples for JVpp.
123
124C code is structured into 3 files:
125
126* *jvpp.c* - includes jvpp.h and jvpp_gen.h + contains hand crafted code for:
127
128** VPP connection open/close
129** Rx thread to java thread attach
130** Callback instance store
131* *jvpp.h* - contains hand-crafted macros and structures used by jvpp.c
132* *jvpp_gen.h* - contains JNI compatible handlers for each VPP request and reply
133
134== Code generators
135All of the required code except the base/marker interfaces is generated using
136simple python2 code generators. The generators use __defs_vpp_papi.py__ input
137file produced by __vppapigen__ from vpe.api file.
138
139=== JNI compatible C code
140Produces __jvpp_gen.h__ file containing JNI compatible handlers for each VPP
141request and reply.
142
143[NOTE]
144====
145Source: jvpp_c_gen.py
146====
147
148=== Request/Reply DTOs
149For all the structures in __defs_vpp_papi.py__ a POJO DTO is produced. Logically,
150there are 4 types of DTOs:
151
152* Request - requests that can be sent to VPP and only a single response is expected
153* DumpRequest - requests that can be sent to VPP and a stream of responses is expected
154* Reply - reply to a simple request or a single response from dump triggered response stream
155* ReplyDump - collection of replies from a single dump request
156* Notifications/Events - Not implemented yet
157
158[NOTE]
159====
160Source: dto_gen.py
161====
162
163=== JVpp
164Produces __JVpp.java__ and __JVppImpl.java__. This is the layer right above JNI compatible C
165code.
166
167[NOTE]
168====
169Source: jvpp_impl_gen.py
170====
171
172=== Callbacks
173Produces callback interface for each VPP reply + a global callback interface called
174__JVppGlobalCallback.java__ aggregating all of the callback interfaces. The JNI
175compatible C code expects only a single instance of this global callback and calls
176it with every reply.
177
178[NOTE]
179====
180Source: callback_gen.py
181====
182
183=== Future facade
184Produces an asynchronous facade on top of JVpp and callbacks, which returns a Future that provides
185matching reply once VPP invocation finishes. Sources produced:
186__FutureJVpp.java, FutureJVppFacade.java and FutureJVppCallback.java__
187
188[NOTE]
189====
190Source: jvpp_future_facade_gen.py
191====
192
193=== Callback facade
194Similar to future facade, only this facade takes callback objects as part of the invocation
195and the callback is called with result once VPP invocation finishes. Sources produced:
196__CallbackJVpp.java, CallbackJVppFacade.java and CallbackJVppCallback.java__
197
198[NOTE]
199====
200Source: jvpp_callback_facade_gen.py
201====