FD.io VPP  v16.06
Vector Packet Processing
vppjni.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef __included_vppjni_h__
16 #define __included_vppjni_h__
17 
18 #include <vnet/vnet.h>
19 #include <vnet/ip/ip.h>
20 #include <vnet/api_errno.h>
21 #include <vlibapi/api.h>
22 #include <vlibmemory/api.h>
23 #include <jni.h>
25 
26 typedef struct {
27  u8 * name;
29 } name_sort_t;
30 
31 typedef struct {
32  u8 valid; // used in a vector of sw_interface_details_t
33 
34  u8 interface_name[64];
38  u8 l2_address[8];
58 
59 typedef struct {
62  /*
63  * Subinterface ID. A number 0-N to uniquely identify
64  * this subinterface under the super interface
65  */
67 
68  /* 0 = dot1q, 1=dot1ad */
70 
71  /* Number of tags 0-2 */
79 
80  /* vlan tag rewrite */
86 
87 typedef struct {
88  u8 *desc;
90 
91 typedef struct {
95 
96 typedef struct {
97  u8 ip[16];
100 
101 typedef struct {
113 
114 typedef struct {
117 } if_counters_t;
118 
119 typedef struct {
125 
126 typedef struct {
127  u8 src_address[16];
128  u8 dst_address[16];
134 
135 
136 typedef struct {
137  /* Context IDs */
140 
141  /* Spinlock */
142  volatile u32 lock;
144 
145  /* To recycle pseudo-synchronous message code from vpp_api_test... */
146  volatile u32 result_ready;
147  volatile i32 retval;
148  volatile u8 *shmem_result;
149 
150  /* thread cleanup */
151  pthread_key_t cleanup_rx_thread_key;
152  /* attachment of rx thread to java thread */
153  JNIEnv *jenv;
154  JavaVM *jvm;
155  uword *callback_hash; // map context_id => jobject
156  uword *ping_hash; // map ping context_id => msg type called
157 
158  /* Timestamp */
160 
161  /* connected indication */
163 
164  /* context -> non-trivial reply hash */
167 
168  /* interface name map */
170 
171  /* interface counters */
173 
174  /* interface table */
176 
178 
179  /* interface indices of responses to one sw_if_dump request */
182 
183  /* program name, build_dir, version */
184  u8 program_name[32];
185  u8 build_directory[256];
186  u8 version[32];
187  u8 build_date[32];
188 
189  /* subinterface table */
191 
192  /* used in ip_address_dump request and response handling */
196 
197  /* used in vxlan_tunnel_dump request and response handling */
199 
200  /* main heap */
201  u8 * heap;
202 
203  /* convenience */
207 
209 } vppjni_main_t;
210 
211 vppjni_main_t vppjni_main __attribute__((aligned (64)));
212 
213 
215 {
216  u32 my_context_id;
217  my_context_id = __sync_add_and_fetch (&jm->context_id_sent, 1);
218  return my_context_id;
219 }
220 
221 static inline void vppjni_lock (vppjni_main_t * jm, u32 tag)
222 {
223  while (__sync_lock_test_and_set (&jm->lock, 1))
224  ;
225  jm->tag = tag;
226 }
227 
228 static inline void vppjni_unlock (vppjni_main_t * jm)
229 {
230  jm->tag = 0;
232  jm->lock = 0;
233 }
234 
235 static inline f64 vppjni_time_now (vppjni_main_t *jm)
236 {
237  return clib_time_now (&jm->clib_time);
238 }
239 
240 static inline int vppjni_sanity_check (vppjni_main_t * jm)
241 {
242  if (!jm->is_connected)
243  return VNET_API_ERROR_NOT_CONNECTED;
244  return 0;
245 }
246 
247 #define __PACKED(x) x __attribute__((packed))
248 
249 typedef __PACKED(struct _vl_api_generic_reply {
250  u16 _vl_msg_id;
251  u32 context;
252  i32 retval;
253  u8 data[0];
254 }) vl_api_generic_reply_t;
255 
256 void vl_api_generic_reply_handler (vl_api_generic_reply_t *mp);
257 
258 /* M: construct, but don't yet send a message */
259 
260 #define M(T,t) \
261 do { \
262  jm->result_ready = 0; \
263  mp = vl_msg_api_alloc(sizeof(*mp)); \
264  memset (mp, 0, sizeof (*mp)); \
265  mp->_vl_msg_id = ntohs (VL_API_##T); \
266  mp->client_index = jm->my_client_index; \
267  } while(0);
268 
269 #define M2(T,t,n) \
270 do { \
271  jm->result_ready = 0; \
272  mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
273  memset (mp, 0, sizeof (*mp)); \
274  mp->_vl_msg_id = ntohs (VL_API_##T); \
275  mp->client_index = jm->my_client_index; \
276  } while(0);
277 
278 
279 /* S: send a message */
280 #define S (vl_msg_api_send_shmem (jm->vl_input_queue, (u8 *)&mp))
281 
282 /* W: wait for results, with timeout */
283 #define W \
284  do { \
285  timeout = vppjni_time_now (jm) + 1.0; \
286  \
287  while (vppjni_time_now (jm) < timeout) { \
288  if (jm->result_ready == 1) { \
289  return (jm->retval); \
290  } \
291  } \
292  return -99; \
293 } while(0);
294 
295 /* WNR: wait for results, with timeout (without returning) */
296 #define WNR \
297  do { \
298  timeout = vppjni_time_now (jm) + 1.0; \
299  \
300  rv = -99; \
301  while (vppjni_time_now (jm) < timeout) { \
302  if (jm->result_ready == 1) { \
303  rv = (jm->retval); \
304  break; \
305  } \
306  } \
307 } while(0);
308 
309 #endif /* __included_vppjni_h__ */
sw_interface_details_t * sw_if_table
Definition: vppjni.h:175
volatile u32 context_id_sent
Definition: vppjni.h:138
volatile u8 * shmem_result
Definition: vppjni.h:148
ipv4_address_t * ipv4_addresses
Definition: vppjni.h:193
vxlan_tunnel_details_t * vxlan_tunnel_details
Definition: vppjni.h:198
pthread_key_t cleanup_rx_thread_key
Definition: vppjni.h:151
vjbd_main_t vjbd_main
Definition: vppjni.h:208
vppjni_main_t vppjni_main
Definition: vppjni.h:211
static void vppjni_unlock(vppjni_main_t *jm)
Definition: vppjni.h:228
clib_time_t clib_time
Definition: vppjni.h:159
u8 * heap
Definition: vppjni.h:201
static int vppjni_sanity_check(vppjni_main_t *jm)
Definition: vppjni.h:240
u32 saved_reply_count
Definition: vppjni.h:166
sw_interface_stats_t * sw_if_stats_by_sw_if_index
Definition: vppjni.h:172
int i32
Definition: types.h:81
uword * ping_hash
Definition: vppjni.h:156
void vl_api_generic_reply_handler(vl_api_generic_reply_t *mp)
Definition: vppjni.c:395
uword * callback_hash
Definition: vppjni.h:155
packet_counters_t pkts
Definition: vppjni.h:116
unsigned long u64
Definition: types.h:89
always_inline f64 clib_time_now(clib_time_t *c)
Definition: time.h:185
u32 value
Definition: vppjni.h:28
static void vppjni_lock(vppjni_main_t *jm, u32 tag)
Definition: vppjni.h:221
static f64 vppjni_time_now(vppjni_main_t *jm)
Definition: vppjni.h:235
u8 prefix_length
Definition: vppjni.h:98
JNIEnv * jenv
Definition: vppjni.h:153
volatile u32 result_ready
Definition: vppjni.h:146
api_main_t * api_main
Definition: vppjni.h:205
volatile u32 context_id_received
Definition: vppjni.h:139
uword * sw_if_config_by_sw_if_index
Definition: vppjni.h:177
u8 sub_inner_vlan_id_any
Definition: vppjni.h:78
u32 * sw_if_dump_if_indices
Definition: vppjni.h:181
volatile i32 retval
Definition: vppjni.h:147
JavaVM * jvm
Definition: vppjni.h:154
volatile u32 lock
Definition: vppjni.h:142
if_counters_t rx
Definition: vppjni.h:122
unsigned int u32
Definition: types.h:88
static u32 vppjni_get_context_id(vppjni_main_t *jm)
Definition: vppjni.h:214
u64 octets
Definition: vppjni.h:115
u64 uword
Definition: types.h:112
uword * sw_if_index_by_interface_name
Definition: vppjni.h:169
u8 * desc
Definition: vppjni.h:88
unsigned short u16
Definition: types.h:57
u8 is_connected
Definition: vppjni.h:162
sw_interface_subif_t * sw_if_subif_table
Definition: vppjni.h:190
double f64
Definition: types.h:140
unsigned char u8
Definition: types.h:56
u8 prefix_length
Definition: vppjni.h:93
unix_shared_memory_queue_t * vl_input_queue
Definition: vppjni.h:204
if_counters_t tx
Definition: vppjni.h:123
uword * reply_hash
Definition: vppjni.h:165
#define CLIB_MEMORY_BARRIER()
Definition: clib.h:101
u8 collect_indices
Definition: vppjni.h:180
ipv6_address_t * ipv6_addresses
Definition: vppjni.h:194
u8 * name
Definition: vppjni.h:27
u8 sub_outer_vlan_id_any
Definition: vppjni.h:77
struct _unix_shared_memory_queue unix_shared_memory_queue_t
u32 my_client_index
Definition: vppjni.h:206