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) {
80 mp->
api_versions[0] = clib_host_to_net_u32(vpe_api_version);
90 int getEnvStat = (*jm->
jvm)->GetEnv(jm->
jvm, (
void **) &(jm->
jenv),
92 if (getEnvStat == JNI_EVERSION) {
96 }
else if (getEnvStat != JNI_EDETACHED) {
97 (*jm->
jvm)->DetachCurrentThread(jm->
jvm);
106 char was_thread_connected = 0;
109 int getEnvStat = (*jm->
jvm)->GetEnv(jm->
jvm, (
void **) &(jm->
jenv),
111 if (getEnvStat == JNI_EDETACHED) {
112 if ((*jm->
jvm)->AttachCurrentThread(jm->
jvm, (
void **) &(jm->
jenv),
116 VNET_API_ERROR_FAILED_TO_ATTACH_TO_JAVA_THREAD;
124 was_thread_connected = 1;
125 }
else if (getEnvStat == JNI_EVERSION) {
131 if (was_thread_connected == 0) {
132 JNIEnv *env = jm->
jenv;
138 jmethodID constructor = (*env)->GetMethodID(env,
140 jmethodID callbackMethod = (*env)->GetMethodID(env,
142 "(Lio/fd/vpp/jvpp/dto/ControlPingReply;)V");
147 jfieldID contextFieldId = (*env)->GetFieldID(env,
149 (*env)->SetIntField(env, dto, contextFieldId,
150 clib_net_to_host_u32(mp->
context));
152 jfieldID clientIndexFieldId = (*env)->GetFieldID(env,
154 (*env)->SetIntField(env, dto, clientIndexFieldId,
157 jfieldID vpePidFieldId = (*env)->GetFieldID(env,
159 (*env)->SetIntField(env, dto, vpePidFieldId,
160 clib_net_to_host_u32(mp->
vpe_pid));
164 (*env)->DeleteLocalRef(env, dto);
182 memset(mp, 0,
sizeof(*mp));
183 mp->_vl_msg_id = ntohs(VL_API_CONTROL_PING);
191 int rv = VNET_API_ERROR_RESPONSE_NOT_READY;
200 clib_warning(
"common: first control ping failed: %d", rv);
219 vl_api_control_ping_reply_t_endian,
220 vl_api_control_ping_reply_t_print,
227 JNIEnv *env, jclass obj, jstring clientName) {
229 const char *client_name;
230 void vl_msg_reply_handler_hookup(
void);
234 jclass connectionInfoClass = (*env)->FindClass(env,
235 "io/fd/vpp/jvpp/VppJNIConnection$ConnectionInfo");
236 jmethodID connectionInfoConstructor = (*env)->GetMethodID(env,
237 connectionInfoClass,
"<init>",
"(JII)V");
242 if (geteuid() != 0) {
243 return (*env)->NewObject(env, connectionInfoClass,
244 connectionInfoConstructor, 0, 0,
245 VNET_API_ERROR_NOT_RUNNING_AS_ROOT);
249 return (*env)->NewObject(env, connectionInfoClass,
250 connectionInfoConstructor, 0, 0,
251 VNET_API_ERROR_ALREADY_CONNECTED);
254 client_name = (*env)->GetStringUTFChars(env, clientName, 0);
256 return (*env)->NewObject(env, connectionInfoClass,
257 connectionInfoConstructor, 0, 0, VNET_API_ERROR_INVALID_VALUE);
265 (*env)->ReleaseStringUTFChars(env, clientName, client_name);
267 return (*env)->NewObject(env, connectionInfoClass,
273 JNIEnv *env, jobject regstryObject) {
284 (*env)->GetObjectClass(env, regstryObject));
288 memset(mp, 0,
sizeof(*mp));
289 mp->_vl_msg_id = ntohs(VL_API_CONTROL_PING);
291 mp->
context = clib_host_to_net_u32(my_context_id);
295 return my_context_id;
299 JNIEnv *env, jclass clazz) {
320 if ((*vm)->GetEnv(vm, (
void**) &env, JNI_VERSION_1_8) != JNI_OK) {
325 (*env)->FindClass(env,
"io/fd/vpp/jvpp/dto/ControlPingReply"));
326 if ((*env)->ExceptionCheck(env)) {
327 (*env)->ExceptionDescribe(env);
333 (*env)->FindClass(env,
"io/fd/vpp/jvpp/VppCallbackException"));
334 if ((*env)->ExceptionCheck(env)) {
335 (*env)->ExceptionDescribe(env);
340 return JNI_VERSION_1_8;
346 if ((*vm)->GetEnv(vm, (
void**) &env, JNI_VERSION_1_8) != JNI_OK) {
volatile u32 control_ping_result_ready
int vl_client_connect_to_vlib(char *svm_name, char *client_name, int rx_queue_size)
static int connect_to_vpe(char *name)
static void vl_api_control_ping_reply_t_handler(vl_api_control_ping_reply_t *mp)
void vl_msg_api_send_shmem(unix_shared_memory_queue_t *q, u8 *elem)
Control ping from client to api server request.
void vl_client_disconnect_from_vlib(void)
unix_shared_memory_queue_t * vl_input_queue
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 static_always_inline
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)
vlib_main_t ** vlib_mains
jint JNI_OnLoad(JavaVM *vm, void *reserved)
#define clib_warning(format, args...)
struct vl_shmem_hdr_ * shmem_hdr
void clib_time_init(clib_time_t *c)
vlib_main_t vlib_global_main
void * vl_msg_api_alloc(int nbytes)
JNIEXPORT jint JNICALL Java_io_fd_vpp_jvpp_JVppRegistryImpl_controlPing0(JNIEnv *env, jobject regstryObject)
static_always_inline void vppjni_lock(jvpp_main_t *jm, u32 tag)
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
JNIEXPORT jobject JNICALL Java_io_fd_vpp_jvpp_VppJNIConnection_clientConnect(JNIEnv *env, jclass obj, jstring clientName)
jclass controlPingReplyClass
static_always_inline void cleanup_rx_thread(void *arg)
unix_shared_memory_queue_t * vl_input_queue
void vl_noop_handler(void *mp)
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