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" 85 mp->
api_versions[0] = clib_host_to_net_u32(vpe_api_version);
95 int getEnvStat = (*jm->
jvm)->GetEnv(jm->
jvm, (
void **) &(jm->
jenv),
97 if (getEnvStat == JNI_EVERSION) {
101 }
else if (getEnvStat != JNI_EDETACHED) {
102 (*jm->
jvm)->DetachCurrentThread(jm->
jvm);
111 char was_thread_connected = 0;
114 int getEnvStat = (*jm->
jvm)->GetEnv(jm->
jvm, (
void **) &(jm->
jenv),
116 if (getEnvStat == JNI_EDETACHED) {
117 if ((*jm->
jvm)->AttachCurrentThread(jm->
jvm, (
void **) &(jm->
jenv),
121 VNET_API_ERROR_FAILED_TO_ATTACH_TO_JAVA_THREAD;
129 was_thread_connected = 1;
130 }
else if (getEnvStat == JNI_EVERSION) {
136 if (was_thread_connected == 0) {
137 JNIEnv *env = jm->
jenv;
143 jmethodID constructor = (*env)->GetMethodID(env,
145 jmethodID callbackMethod = (*env)->GetMethodID(env,
147 "(Lio/fd/vpp/jvpp/dto/ControlPingReply;)V");
152 jfieldID contextFieldId = (*env)->GetFieldID(env,
154 (*env)->SetIntField(env, dto, contextFieldId,
155 clib_net_to_host_u32(mp->
context));
157 jfieldID clientIndexFieldId = (*env)->GetFieldID(env,
159 (*env)->SetIntField(env, dto, clientIndexFieldId,
162 jfieldID vpePidFieldId = (*env)->GetFieldID(env,
164 (*env)->SetIntField(env, dto, vpePidFieldId,
165 clib_net_to_host_u32(mp->
vpe_pid));
169 (*env)->DeleteLocalRef(env, dto);
189 char *key = (char *)hp->key;
190 int msg_name_len = strlen(key) - 9;
191 if (strlen(CONTROL_PING_MESSAGE) == msg_name_len &&
192 strncmp(CONTROL_PING_MESSAGE, (char *)hp->key, msg_name_len) == 0) {
193 rm->control_ping_msg_id = (u32)hp->value[0];
197 rm->control_ping_reply_msg_id = (u32)hp->value[0];
200 if (rm->control_ping_msg_id == -1) {
204 if (rm->control_ping_reply_msg_id == -1) {
222 memset(mp, 0,
sizeof(*mp));
231 int rv = VNET_API_ERROR_RESPONSE_NOT_READY;
263 vl_api_control_ping_reply_t_endian,
264 vl_api_control_ping_reply_t_print,
271 JNIEnv *env, jclass obj, jstring clientName) {
273 const char *client_name;
274 void vl_msg_reply_handler_hookup(
void);
278 jclass connectionInfoClass = (*env)->FindClass(env,
279 "io/fd/vpp/jvpp/VppJNIConnection$ConnectionInfo");
280 jmethodID connectionInfoConstructor = (*env)->GetMethodID(env,
281 connectionInfoClass,
"<init>",
"(JII)V");
286 if (geteuid() != 0) {
287 return (*env)->NewObject(env, connectionInfoClass,
288 connectionInfoConstructor, 0, 0,
289 VNET_API_ERROR_NOT_RUNNING_AS_ROOT);
293 return (*env)->NewObject(env, connectionInfoClass,
294 connectionInfoConstructor, 0, 0,
295 VNET_API_ERROR_ALREADY_CONNECTED);
298 client_name = (*env)->GetStringUTFChars(env, clientName, 0);
300 return (*env)->NewObject(env, connectionInfoClass,
301 connectionInfoConstructor, 0, 0, VNET_API_ERROR_INVALID_VALUE);
309 (*env)->ReleaseStringUTFChars(env, clientName, client_name);
311 return (*env)->NewObject(env, connectionInfoClass,
317 JNIEnv *env, jobject regstryObject) {
328 (*env)->GetObjectClass(env, regstryObject));
332 memset(mp, 0,
sizeof(*mp));
335 mp->
context = clib_host_to_net_u32(my_context_id);
339 return my_context_id;
343 JNIEnv *env, jclass clazz) {
364 if ((*vm)->GetEnv(vm, (
void**) &env, JNI_VERSION_1_8) != JNI_OK) {
369 (*env)->FindClass(env,
"io/fd/vpp/jvpp/dto/ControlPingReply"));
370 if ((*env)->ExceptionCheck(env)) {
371 (*env)->ExceptionDescribe(env);
377 (*env)->FindClass(env,
"io/fd/vpp/jvpp/VppCallbackException"));
378 if ((*env)->ExceptionCheck(env)) {
379 (*env)->ExceptionDescribe(env);
384 return JNI_VERSION_1_8;
390 if ((*vm)->GetEnv(vm, (
void**) &env, JNI_VERSION_1_8) != JNI_OK) {
volatile u32 control_ping_result_ready
static int connect_to_vpe(char *name)
static void vl_api_control_ping_reply_t_handler(vl_api_control_ping_reply_t *mp)
Control ping from client to api server request.
unix_shared_memory_queue_t * vl_input_queue
int control_ping_reply_msg_id
void vl_client_add_api_signatures(vl_api_memclnt_create_t *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)
jvpp_registry_main_t jvpp_registry_main
#define CONTROL_PING_MESSAGE
#define static_always_inline
int vl_client_connect_to_vlib(const char *svm_name, const char *client_name, int rx_queue_size)
vlib_main_t ** vlib_mains
jint JNI_OnLoad(JavaVM *vm, void *reserved)
struct vl_shmem_hdr_ * shmem_hdr
static uword pointer_to_uword(const void *p)
void * vl_msg_api_alloc(int nbytes)
static int find_ping_id()
void clib_time_init(clib_time_t *c)
vlib_main_t vlib_global_main
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)
JNIEXPORT jint JNICALL Java_io_fd_vpp_jvpp_JVppRegistryImpl_controlPing0(JNIEnv *env, jobject regstryObject)
#define clib_warning(format, args...)
void vl_noop_handler(void *mp)
static_always_inline void vppjni_lock(jvpp_main_t *jm, u32 tag)
jclass callbackExceptionClass
void vl_msg_api_send_shmem(unix_shared_memory_queue_t *q, u8 *elem)
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
JNIEXPORT jobject JNICALL Java_io_fd_vpp_jvpp_VppJNIConnection_clientConnect(JNIEnv *env, jclass obj, jstring clientName)
jclass controlPingReplyClass
#define CONTROL_PING_REPLY_MESSAGE
#define hash_foreach_pair(p, v, body)
Iterate over hash pairs.
void vl_client_disconnect_from_vlib(void)
static_always_inline void cleanup_rx_thread(void *arg)
unix_shared_memory_queue_t * vl_input_queue
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