18 #define vl_api_version(n,v) static u32 vpe_api_version = (v); 19 #include <vpp-api/vpe.api.h> 24 #include "org_openvpp_jvpp_VppJNIConnection.h" 25 #include "org_openvpp_jvpp_JVppRegistryImpl.h" 37 #define vl_print(handle, ...) 47 void __stack_chk_guard(
void) __attribute__((weak));
48 void __stack_chk_guard(
void) {
76 mp->
api_versions[0] = clib_host_to_net_u32(vpe_api_version);
86 int getEnvStat = (*jm->
jvm)->GetEnv(jm->
jvm, (
void **) &(jm->
jenv),
88 if (getEnvStat == JNI_EVERSION) {
92 }
else if (getEnvStat != JNI_EDETACHED) {
93 (*jm->
jvm)->DetachCurrentThread(jm->
jvm);
102 char was_thread_connected = 0;
105 int getEnvStat = (*jm->
jvm)->GetEnv(jm->
jvm, (
void **) &(jm->
jenv),
107 if (getEnvStat == JNI_EDETACHED) {
108 if ((*jm->
jvm)->AttachCurrentThread(jm->
jvm, (
void **) &(jm->
jenv),
112 VNET_API_ERROR_FAILED_TO_ATTACH_TO_JAVA_THREAD;
120 was_thread_connected = 1;
121 }
else if (getEnvStat == JNI_EVERSION) {
127 if (was_thread_connected == 0) {
128 JNIEnv *env = jm->
jenv;
134 jmethodID constructor = (*env)->GetMethodID(env,
136 jmethodID callbackMethod = (*env)->GetMethodID(env,
138 "(Lorg/openvpp/jvpp/dto/ControlPingReply;)V");
143 jfieldID contextFieldId = (*env)->GetFieldID(env,
145 (*env)->SetIntField(env, dto, contextFieldId,
146 clib_net_to_host_u32(mp->
context));
148 jfieldID clientIndexFieldId = (*env)->GetFieldID(env,
150 (*env)->SetIntField(env, dto, clientIndexFieldId,
153 jfieldID vpePidFieldId = (*env)->GetFieldID(env,
155 (*env)->SetIntField(env, dto, vpePidFieldId,
156 clib_net_to_host_u32(mp->
vpe_pid));
177 memset(mp, 0,
sizeof(*mp));
178 mp->_vl_msg_id = ntohs(VL_API_CONTROL_PING);
186 int rv = VNET_API_ERROR_RESPONSE_NOT_READY;
195 clib_warning(
"common: first control ping failed: %d", rv);
214 vl_api_control_ping_reply_t_endian,
215 vl_api_control_ping_reply_t_print,
224 JNIEnv *env, jclass obj, jstring clientName) {
226 const char *client_name;
227 void vl_msg_reply_handler_hookup(
void);
231 jclass connectionInfoClass = (*env)->FindClass(env,
232 "org/openvpp/jvpp/VppJNIConnection$ConnectionInfo");
233 jmethodID connectionInfoConstructor = (*env)->GetMethodID(env,
234 connectionInfoClass,
"<init>",
"(JII)V");
239 if (geteuid() != 0) {
240 return (*env)->NewObject(env, connectionInfoClass,
241 connectionInfoConstructor, 0, 0,
242 VNET_API_ERROR_NOT_RUNNING_AS_ROOT);
246 return (*env)->NewObject(env, connectionInfoClass,
247 connectionInfoConstructor, 0, 0,
248 VNET_API_ERROR_ALREADY_CONNECTED);
251 client_name = (*env)->GetStringUTFChars(env, clientName, 0);
253 return (*env)->NewObject(env, connectionInfoClass,
254 connectionInfoConstructor, 0, 0, VNET_API_ERROR_INVALID_VALUE);
262 (*env)->ReleaseStringUTFChars(env, clientName, client_name);
264 return (*env)->NewObject(env, connectionInfoClass,
270 JNIEnv *env, jobject regstryObject) {
281 (*env)->GetObjectClass(env, regstryObject));
285 memset(mp, 0,
sizeof(*mp));
286 mp->_vl_msg_id = ntohs(VL_API_CONTROL_PING);
288 mp->
context = clib_host_to_net_u32(my_context_id);
292 return my_context_id;
296 JNIEnv *env, jclass clazz) {
317 if ((*vm)->GetEnv(vm, (
void**) &env, JNI_VERSION_1_8) != JNI_OK) {
322 (*env)->FindClass(env,
"org/openvpp/jvpp/dto/ControlPingReply"));
323 if ((*env)->ExceptionCheck(env)) {
324 (*env)->ExceptionDescribe(env);
330 (*env)->FindClass(env,
"org/openvpp/jvpp/VppCallbackException"));
331 if ((*env)->ExceptionCheck(env)) {
332 (*env)->ExceptionDescribe(env);
337 return JNI_VERSION_1_8;
343 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)
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)
JNIEXPORT jobject JNICALL Java_org_openvpp_jvpp_VppJNIConnection_clientConnect(JNIEnv *env, jclass obj, jstring clientName)
jint JNI_OnLoad(JavaVM *vm, void *reserved)
#define clib_warning(format, args...)
struct vl_shmem_hdr_ * shmem_hdr
JNIEXPORT jint JNICALL Java_org_openvpp_jvpp_JVppRegistryImpl_controlPing0(JNIEnv *env, jobject regstryObject)
void clib_time_init(clib_time_t *c)
void * vl_msg_api_alloc(int nbytes)
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
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.
JNIEXPORT void JNICALL Java_org_openvpp_jvpp_VppJNIConnection_clientDisconnect(JNIEnv *env, jclass clazz)
pthread_key_t cleanup_rx_thread_key