18 #define vl_api_version(n,v) static u32 vpe_api_version = (v); 19 #include <vpp/api/vpe.api.h> 25 #include "io_fd_vpp_jvpp_VppJNIConnection.h" 26 #include "io_fd_vpp_jvpp_JVppRegistryImpl.h" 38 #define vl_print(handle, ...) 51 void __stack_chk_guard(
void) __attribute__((weak));
52 void __stack_chk_guard(
void) {
55 #define CONTROL_PING_MESSAGE "control_ping" 56 #define CONTROL_PING_REPLY_MESSAGE "control_ping_reply" 86 mp->
api_versions[0] = clib_host_to_net_u32(vpe_api_version);
96 int getEnvStat = (*jm->
jvm)->GetEnv(jm->
jvm, (
void **) &(jm->
jenv),
98 if (getEnvStat == JNI_EVERSION) {
102 }
else if (getEnvStat != JNI_EDETACHED) {
103 (*jm->
jvm)->DetachCurrentThread(jm->
jvm);
112 char was_thread_connected = 0;
115 int getEnvStat = (*jm->
jvm)->GetEnv(jm->
jvm, (
void **) &(jm->
jenv),
117 if (getEnvStat == JNI_EDETACHED) {
118 if ((*jm->
jvm)->AttachCurrentThread(jm->
jvm, (
void **) &(jm->
jenv),
122 VNET_API_ERROR_FAILED_TO_ATTACH_TO_JAVA_THREAD;
130 was_thread_connected = 1;
131 }
else if (getEnvStat == JNI_EVERSION) {
137 if (was_thread_connected == 0) {
138 JNIEnv *env = jm->
jenv;
144 jmethodID constructor = (*env)->GetMethodID(env,
146 jmethodID callbackMethod = (*env)->GetMethodID(env,
148 "(Lio/fd/vpp/jvpp/dto/ControlPingReply;)V");
153 jfieldID contextFieldId = (*env)->GetFieldID(env,
155 (*env)->SetIntField(env, dto, contextFieldId,
156 clib_net_to_host_u32(mp->
context));
158 jfieldID clientIndexFieldId = (*env)->GetFieldID(env,
160 (*env)->SetIntField(env, dto, clientIndexFieldId,
163 jfieldID vpePidFieldId = (*env)->GetFieldID(env,
165 (*env)->SetIntField(env, dto, vpePidFieldId,
166 clib_net_to_host_u32(mp->
vpe_pid));
170 (*env)->DeleteLocalRef(env, dto);
191 char *key = (char *)hp->key;
192 int msg_name_len = strlen(key) - 9;
193 if (strlen(CONTROL_PING_MESSAGE) == msg_name_len &&
194 strncmp(CONTROL_PING_MESSAGE, (char *)hp->key, msg_name_len) == 0) {
195 rm->control_ping_msg_id = (u32)hp->value[0];
199 rm->control_ping_reply_msg_id = (u32)hp->value[0];
202 if (rm->control_ping_msg_id == -1) {
206 if (rm->control_ping_reply_msg_id == -1) {
224 memset(mp, 0,
sizeof(*mp));
233 int rv = VNET_API_ERROR_RESPONSE_NOT_READY;
248 #if USE_DLMALLOC == 1 257 #if USE_DLMALLOC == 1 272 vl_api_control_ping_reply_t_endian,
273 vl_api_control_ping_reply_t_print,
280 JNIEnv *env, jclass obj, jstring shmPrefix, jstring clientName) {
287 const char *client_name;
288 const char *shm_prefix;
289 void vl_msg_reply_handler_hookup(
void);
293 jclass connectionInfoClass = (*env)->FindClass(env,
294 "io/fd/vpp/jvpp/VppJNIConnection$ConnectionInfo");
295 jmethodID connectionInfoConstructor = (*env)->GetMethodID(env,
296 connectionInfoClass,
"<init>",
"(JIII)V");
299 return (*env)->NewObject(env, connectionInfoClass,
300 connectionInfoConstructor, 0, 0,
301 VNET_API_ERROR_ALREADY_CONNECTED, 0);
304 client_name = (*env)->GetStringUTFChars(env, clientName, 0);
305 shm_prefix = (*env)->GetStringUTFChars(env, shmPrefix, 0);
308 return (*env)->NewObject(env, connectionInfoClass,
309 connectionInfoConstructor, 0, 0, VNET_API_ERROR_INVALID_VALUE, 0, shmPrefix);
313 return (*env)->NewObject(env, connectionInfoClass,
314 connectionInfoConstructor, 0, 0, VNET_API_ERROR_INVALID_VALUE, 0, shmPrefix);
322 (*env)->ReleaseStringUTFChars(env, clientName, client_name);
323 (*env)->ReleaseStringUTFChars(env, shmPrefix, shm_prefix);
325 return (*env)->NewObject(env, connectionInfoClass,
331 JNIEnv *env, jobject regstryObject) {
342 (*env)->GetObjectClass(env, regstryObject));
346 memset(mp, 0,
sizeof(*mp));
349 mp->
context = clib_host_to_net_u32(my_context_id);
353 return my_context_id;
357 JNIEnv *env, jclass clazz) {
378 if ((*vm)->GetEnv(vm, (
void**) &env, JNI_VERSION_1_8) != JNI_OK) {
383 (*env)->FindClass(env,
"io/fd/vpp/jvpp/dto/ControlPingReply"));
384 if ((*env)->ExceptionCheck(env)) {
385 (*env)->ExceptionDescribe(env);
391 (*env)->FindClass(env,
"io/fd/vpp/jvpp/VppCallbackException"));
392 if ((*env)->ExceptionCheck(env)) {
393 (*env)->ExceptionDescribe(env);
398 return JNI_VERSION_1_8;
404 if ((*vm)->GetEnv(vm, (
void**) &env, JNI_VERSION_1_8) != JNI_OK) {
volatile u32 control_ping_result_ready
static int connect_to_vpe(char *shm_prefix, char *name)
static void vl_api_control_ping_reply_t_handler(vl_api_control_ping_reply_t *mp)
int vl_client_connect_to_vlib(const char *svm_name, const char *client_name, int rx_queue_size)
Control ping from client to api server request.
int my_client_index
All VLIB-side message handlers use my_client_index to identify the queue / client.
int control_ping_reply_msg_id
void vl_client_add_api_signatures(vl_api_memclnt_create_t *mp)
void vl_noop_handler(void *mp)
static f64 clib_time_now(clib_time_t *c)
JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_VppJNIConnection_clientDisconnect(JNIEnv *env, jclass clazz)
static int send_initial_control_ping()
static_always_inline u32 vppjni_get_context_id(jvpp_main_t *jm)
void * vl_msg_api_alloc(int nbytes)
jvpp_registry_main_t jvpp_registry_main
#define CONTROL_PING_MESSAGE
#define static_always_inline
vlib_main_t ** vlib_mains
jint JNI_OnLoad(JavaVM *vm, void *reserved)
struct vl_shmem_hdr_ * shmem_hdr
Binary API shared-memory segment header pointer.
static int find_ping_id()
void vl_msg_api_clean_handlers(int msg_id)
void vl_msg_api_set_handlers(int msg_id, char *msg_name, void *handler, void *cleanup, void *endian, void *print, int msg_size, int traced)
void clib_time_init(clib_time_t *c)
vlib_main_t vlib_global_main
API main structure, used by both vpp and binary API clients.
void * clib_mem_init(void *heap, uword size)
void vl_msg_api_send_shmem(svm_queue_t *q, u8 *elem)
JNIEXPORT jint JNICALL Java_io_fd_vpp_jvpp_JVppRegistryImpl_controlPing0(JNIEnv *env, jobject regstryObject)
#define clib_warning(format, args...)
static_always_inline void vppjni_lock(jvpp_main_t *jm, u32 tag)
svm_queue_t * vl_input_queue
JNIEXPORT jobject JNICALL Java_io_fd_vpp_jvpp_VppJNIConnection_clientConnect(JNIEnv *env, jclass obj, jstring shmPrefix, jstring clientName)
jclass callbackExceptionClass
void JNI_OnUnload(JavaVM *vm, void *reserved)
static_always_inline void vppjni_unlock(jvpp_main_t *jm)
Control ping from the client to the server response.
volatile i32 control_ping_retval
static uword pointer_to_uword(const void *p)
jclass controlPingReplyClass
#define CONTROL_PING_REPLY_MESSAGE
#define hash_foreach_pair(p, v, body)
Iterate over hash pairs.
static_always_inline void cleanup_rx_thread(void *arg)
void vl_client_disconnect_from_vlib(void)
void call_on_error(const char *callName, int contextId, int retval, jclass callbackClass, jobject callbackObject, jclass callbackExceptionClass)
Calls onError callback on callbackObject reference.
pthread_key_t cleanup_rx_thread_key
uword * msg_index_by_name_and_crc
client message index hash table
svm_queue_t * vl_input_queue