blob: 6926d74d574e41c11cbacccbcbe47630ef8070fe [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
Marek Gradzki66ea26b2016-07-26 15:28:22 +020013
Marek Gradzki5a5f5aa2016-08-17 12:33:50 +020014=== Plugin support
Marek Gradzki66ea26b2016-07-26 15:28:22 +020015
Marek Gradzki5a5f5aa2016-08-17 12:33:50 +020016 /-------------\ /--------------\ /---------------\
17 | JvppPlugin1 +<-------+ JVppRegistry +--------->+ VppConnection |
18 \-------------/ inits \--+-----------/ uses \---------------/
19 |
20 /-------------\ |
21 | JvppPlugin2 +<----------+ inits
22 \-------------/ |
23 |
24 ... |
25 |
26 /----------\ |
27 | JVppCore +<-------------+
28 \----------/
Maros Marsalek047bf842016-04-26 15:03:26 +020029
30
Marek Gradzki5a5f5aa2016-08-17 12:33:50 +020031VppRegistry opens connection to vpp (VppConnection) and manages jvpp plugins.
32Each plugin needs to be registered in the VppRegistry. Registration involves
33plugin initialization (providing JNI implementation with JVppCallback reference,
34vpp client identifier and vpp shared memory queue address).
35
36API user sends message by calling a method of appropriate plugin interface.
37The call is delegated to JNI implementation provided by the particular plugin.
38When JNI code receives reply, it invokes callback method of JVppCallback
39that corresponds to the received message reply.
40
41=== JVppCore as an example of JVpp plugin architecture
42
Maros Marsalek047bf842016-04-26 15:03:26 +020043 JVpp Java
44
Marek Gradzki5a5f5aa2016-08-17 12:33:50 +020045 /--------------\ /----------\ /------------\ /------\
46 | JVppRegistry | | JVppCore | | Callbacks | | DTOs |
47 \----+---------/ \----+-----/ \------+-----/ \------/
48 ^ ^ ^
49 | implements | implements | implements
50 /----+--------------\ /---+----------\ /-----+---------\
51 | JVppRegistryImpl* +-------->+ JVppCoreImpl | | JVppCallback |
52 \-------+-----------/ inits \---+----------/ \-------+-------/
53 | | ^
54 | | uses | calls back
55 | | |
56----------|--------------------------|-----------------------|---------------------
57 | | |
58 C JNI | +-------------------+ | /-----------------\
59 v | | +-->+ jvpp_core_gen.h |
60 /--------+--------\ | | | \-----------------/
61 | jpp_registry.c* +---+ /--------+----+----\ | | |
62 \-----------------/ | | << shared lib >> | /-+--+---+------\
63 + ->+ jvpp_common* <--------+ jvpp_core.c* |
64 uses \------------------/ uses \---------------/
Maros Marsalek047bf842016-04-26 15:03:26 +020065
Marek Gradzki5a5f5aa2016-08-17 12:33:50 +020066
67* Components marked with an asterisk contain manually crafted code, which in addition
Maros Marsalek047bf842016-04-26 15:03:26 +020068to generated classes form jvpp. Exception applies to Callbacks and DTOs, since there are
69manually crafted marker interfaces in callback and dto package (dto/JVppRequest, dto/JVppReply,
70dto/JVppDump, dto/JVppReplyDump, callback/JVppCallback)
71
Marek Gradzki5a5f5aa2016-08-17 12:33:50 +020072Note: jvpp_core.c calls back the JVppCallback instance with every response. An instance of the
73JVppCallback is provided to jvpp_core.c by JVppRegistryImpl on JVppCoreImpl initialization.
Maros Marsalek047bf842016-04-26 15:03:26 +020074
75Part of the JVpp is also Future facade. It is asynchronous API returning Future objects
Marek Gradzki5a5f5aa2016-08-17 12:33:50 +020076on top of low level JVpp. It wraps dump reply messages in one DTO using control_ping message
77(provided by JVppRegistry).
Maros Marsalek047bf842016-04-26 15:03:26 +020078
79
80Future facade
81
Marek Gradzki5a5f5aa2016-08-17 12:33:50 +020082 /----------------\ /---------------\
83 | FutureJVppCore | +-->+ JVppRegistry* |
84 \-----+----------/ | \---------------/
85 ^ |
86 | implements | uses
87 | |
88 /--------+-------------\ | /------------------------------\
89 | FutureJVppCoreFacade +---+--->+ FutureJVppCoreFacadeCallback |
90 \---------+------------/ uses \-------+----------------------/
Maros Marsalek047bf842016-04-26 15:03:26 +020091 | |
92---------------|-----------------------------|-------------------------------
93 | uses | implements
94JVpp Java | |
95 | |
Marek Gradzki5a5f5aa2016-08-17 12:33:50 +020096 /----------\ | |
97 | JVppCore +<-+ |
98 \----+-----/ |
Maros Marsalek047bf842016-04-26 15:03:26 +020099 ^ |
100 | implements v
Marek Gradzki5a5f5aa2016-08-17 12:33:50 +0200101 /----+---------\ /--------+---------------\
102 | JVppCoreImpl | | JVppCoreGlobalCallback |
103 \--------------/ \------------------------/
Maros Marsalek047bf842016-04-26 15:03:26 +0200104
105
106
107Another useful utility of the JVpp is Callback facade. It is asynchronous API
108capable of calling specific callback instance (provided when performing a call)
109per call.
110
111
112Callback facade
113
Marek Gradzki5a5f5aa2016-08-17 12:33:50 +0200114 /------------------\ /---------------\
115 | CallbackJVppCore | +-->+ JVppRegistry* |
116 \-----+------------/ | \---------------/
117 ^ |
118 | implements | uses
119 | |
120 /--------+---------------\ | /--------------------------\
121 | CallbackJVppCoreFacade +---+--->+ CallbackJVppCoreCallback |
122 \---------+--------------/ uses \-----+--------------------/
Maros Marsalek047bf842016-04-26 15:03:26 +0200123 | |
124---------------|-----------------------------|-------------------------------
125 | uses | implements
126JVpp Java | |
127 | |
Marek Gradzki5a5f5aa2016-08-17 12:33:50 +0200128 /----------\ | |
129 | JVppCore +<-+ |
130 \----+-----/ |
Maros Marsalek047bf842016-04-26 15:03:26 +0200131 ^ |
132 | implements v
Marek Gradzki5a5f5aa2016-08-17 12:33:50 +0200133 /----+---------\ /----------+-------------\
134 | JVppCoreImpl | | JVppCoreGlobalCallback |
135 \--------------/ \------------------------/
Maros Marsalek047bf842016-04-26 15:03:26 +0200136
137
138== Package structure
139
140* *org.openvpp.jvpp* - top level package for generated JVpp interface+ implementation and hand-crafted
Marek Gradzki5a5f5aa2016-08-17 12:33:50 +0200141VppConnection interface + implementation - packaged as jvpp-registry-version.jar
142
143* *org.openvpp.jvpp.[plugin]* - top level package for generated JVpp interface + implementation
144+ plugin's API tests - packaged as jvpp-[plugin]-version.jar
Maros Marsalek047bf842016-04-26 15:03:26 +0200145
146** *dto* - package for DTOs generated from VPP API structures + base/marker hand-crafted interfaces
Marek Gradzki5a5f5aa2016-08-17 12:33:50 +0200147(in case of jvpp-registry)
148** *callback* - package for low-level JVpp callbacks and a global callback interface implementing each of
149the low-level JVppcallbacks
Maros Marsalek047bf842016-04-26 15:03:26 +0200150** *future* - package for future based facade on top of JVpp and callbacks
151** *callfacade* - package for callback based facade on top of JVpp and callbacks. Allowing
152users to provide callback per request
153** *test* - package for JVpp standalone tests. Can also serve as samples for JVpp.
154
Marek Gradzki5a5f5aa2016-08-17 12:33:50 +0200155C code is structured into modules:
Maros Marsalek047bf842016-04-26 15:03:26 +0200156
Marek Gradzki5a5f5aa2016-08-17 12:33:50 +0200157* *jvpp_common* - shared library that provides jvpp_main_t reference used by jvpp_registry and plugins.
158
159* *jvpp_registry* - native library used by JVppRegistryImpl, responsible for:
Maros Marsalek047bf842016-04-26 15:03:26 +0200160
161** VPP connection open/close
162** Rx thread to java thread attach
Marek Gradzki5a5f5aa2016-08-17 12:33:50 +0200163** control ping message handling
164
165* *jvpp_core* - native library used by jvpp core plugin:
166** *jvpp_core.c* - contains hand crafted code for core plugin initialization
167** *jvpp_core_gen.h* - contains generated JNI compatible handlers for all requests and replies defined in vpe.api
Maros Marsalek047bf842016-04-26 15:03:26 +0200168
169== Code generators
170All of the required code except the base/marker interfaces is generated using
171simple python2 code generators. The generators use __defs_vpp_papi.py__ input
172file produced by __vppapigen__ from vpe.api file.
173
174=== JNI compatible C code
Marek Gradzki5a5f5aa2016-08-17 12:33:50 +0200175Produces __jvpp_[plugin]_gen.h__ file containing JNI compatible handlers for each VPP
Maros Marsalek047bf842016-04-26 15:03:26 +0200176request and reply.
177
178[NOTE]
179====
180Source: jvpp_c_gen.py
181====
182
183=== Request/Reply DTOs
184For all the structures in __defs_vpp_papi.py__ a POJO DTO is produced. Logically,
185there are 4 types of DTOs:
186
187* Request - requests that can be sent to VPP and only a single response is expected
188* DumpRequest - requests that can be sent to VPP and a stream of responses is expected
189* Reply - reply to a simple request or a single response from dump triggered response stream
190* ReplyDump - collection of replies from a single dump request
191* Notifications/Events - Not implemented yet
192
193[NOTE]
194====
195Source: dto_gen.py
196====
197
198=== JVpp
199Produces __JVpp.java__ and __JVppImpl.java__. This is the layer right above JNI compatible C
200code.
201
202[NOTE]
203====
204Source: jvpp_impl_gen.py
205====
206
207=== Callbacks
208Produces callback interface for each VPP reply + a global callback interface called
Marek Gradzki5a5f5aa2016-08-17 12:33:50 +0200209__JVpp[plugin]GlobalCallback.java__ aggregating all of the callback interfaces. The JNI
Maros Marsalek047bf842016-04-26 15:03:26 +0200210compatible C code expects only a single instance of this global callback and calls
211it with every reply.
212
213[NOTE]
214====
215Source: callback_gen.py
216====
217
218=== Future facade
219Produces an asynchronous facade on top of JVpp and callbacks, which returns a Future that provides
220matching reply once VPP invocation finishes. Sources produced:
Marek Gradzki5a5f5aa2016-08-17 12:33:50 +0200221__FutureJVpp[plugin].java, FutureJVpp[plugin]Facade.java and FutureJVpp[plugin]Callback.java__
Maros Marsalek047bf842016-04-26 15:03:26 +0200222
223[NOTE]
224====
225Source: jvpp_future_facade_gen.py
226====
227
228=== Callback facade
229Similar to future facade, only this facade takes callback objects as part of the invocation
230and the callback is called with result once VPP invocation finishes. Sources produced:
Marek Gradzki5a5f5aa2016-08-17 12:33:50 +0200231__CallbackJVpp[plugin].java, CallbackJVpp[plugin]Facade.java and CallbackJVpp[plugin]Callback.java__
Maros Marsalek047bf842016-04-26 15:03:26 +0200232
233[NOTE]
234====
235Source: jvpp_callback_facade_gen.py
236====