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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
15 #ifndef __included_vppjni_h__
16 #define __included_vppjni_h__
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>
24 #include <japi/vppjni_bridge_domain.h>
32 u8 valid; // used in a vector of sw_interface_details_t
34 u8 interface_name[64];
37 u32 l2_address_length;
46 u8 sub_number_of_tags;
47 u16 sub_outer_vlan_id;
48 u16 sub_inner_vlan_id;
51 u8 sub_outer_vlan_id_any;
52 u8 sub_inner_vlan_id_any;
57 } sw_interface_details_t;
63 * Subinterface ID. A number 0-N to uniquely identify
64 * this subinterface under the super interface
68 /* 0 = dot1q, 1=dot1ad */
71 /* Number of tags 0-2 */
72 u8 sub_number_of_tags;
73 u16 sub_outer_vlan_id;
74 u16 sub_inner_vlan_id;
77 u8 sub_outer_vlan_id_any;
78 u8 sub_inner_vlan_id_any;
80 /* vlan tag rewrite */
85 } sw_interface_subif_t;
116 packet_counters_t pkts;
124 } sw_interface_stats_t;
131 u32 decap_next_index;
132 } vxlan_tunnel_details_t;
137 volatile u32 context_id_sent;
138 volatile u32 context_id_received;
144 /* To recycle pseudo-synchronous message code from vpp_api_test... */
145 volatile u32 result_ready;
147 volatile u8 *shmem_result;
150 pthread_key_t cleanup_rx_thread_key;
151 /* attachment of rx thread to java thread */
154 uword *callback_hash; // map context_id => jobject
155 uword *ping_hash; // map ping context_id => msg type called
158 clib_time_t clib_time;
160 /* connected indication */
163 /* context -> non-trivial reply hash */
165 u32 saved_reply_count;
167 /* interface name map */
168 uword * sw_if_index_by_interface_name;
170 /* interface counters */
171 sw_interface_stats_t * sw_if_stats_by_sw_if_index;
173 /* interface table */
174 sw_interface_details_t * sw_if_table;
176 uword * sw_if_config_by_sw_if_index;
178 /* interface indices of responses to one sw_if_dump request */
180 u32 * sw_if_dump_if_indices;
182 /* program name, build_dir, version */
184 u8 build_directory[256];
188 /* subinterface table */
189 sw_interface_subif_t * sw_if_subif_table;
191 /* used in ip_address_dump request and response handling */
192 ipv4_address_t *ipv4_addresses;
193 ipv6_address_t *ipv6_addresses;
196 /* used in vxlan_tunnel_dump request and response handling */
197 vxlan_tunnel_details_t *vxlan_tunnel_details;
203 unix_shared_memory_queue_t * vl_input_queue;
204 api_main_t * api_main;
207 vjbd_main_t vjbd_main;
210 vppjni_main_t vppjni_main __attribute__((aligned (64)));
213 static inline u32 vppjni_get_context_id (vppjni_main_t * jm)
216 my_context_id = __sync_add_and_fetch (&jm->context_id_sent, 1);
217 return my_context_id;
220 static inline void vppjni_lock (vppjni_main_t * jm, u32 tag)
222 while (__sync_lock_test_and_set (&jm->lock, 1))
227 static inline void vppjni_unlock (vppjni_main_t * jm)
230 CLIB_MEMORY_BARRIER();
234 static inline f64 vppjni_time_now (vppjni_main_t *jm)
236 return clib_time_now (&jm->clib_time);
239 static inline int vppjni_sanity_check (vppjni_main_t * jm)
241 if (!jm->is_connected)
242 return VNET_API_ERROR_NOT_CONNECTED;
246 #define __PACKED(x) x __attribute__((packed))
248 typedef __PACKED(struct _vl_api_generic_reply {
253 }) vl_api_generic_reply_t;
255 void vl_api_generic_reply_handler (vl_api_generic_reply_t *mp);
257 /* M: construct, but don't yet send a message */
261 jm->result_ready = 0; \
262 mp = vl_msg_api_alloc(sizeof(*mp)); \
263 memset (mp, 0, sizeof (*mp)); \
264 mp->_vl_msg_id = ntohs (VL_API_##T); \
265 mp->client_index = jm->my_client_index; \
270 jm->result_ready = 0; \
271 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
272 memset (mp, 0, sizeof (*mp)); \
273 mp->_vl_msg_id = ntohs (VL_API_##T); \
274 mp->client_index = jm->my_client_index; \
278 /* S: send a message */
279 #define S (vl_msg_api_send_shmem (jm->vl_input_queue, (u8 *)&mp))
281 /* W: wait for results, with timeout */
284 timeout = vppjni_time_now (jm) + 1.0; \
286 while (vppjni_time_now (jm) < timeout) { \
287 if (jm->result_ready == 1) { \
288 return (jm->retval); \
294 /* WNR: wait for results, with timeout (without returning) */
297 timeout = vppjni_time_now (jm) + 1.0; \
300 while (vppjni_time_now (jm) < timeout) { \
301 if (jm->result_ready == 1) { \
308 #endif /* __included_vppjni_h__ */