jvpp: stop plugin intialization on first mismatch 31/8831/2
authorMarek Gradzki <mgradzki@cisco.com>
Mon, 16 Oct 2017 10:33:12 +0000 (12:33 +0200)
committerDave Wallace <dwallacelf@gmail.com>
Mon, 16 Oct 2017 14:18:09 +0000 (14:18 +0000)
Java bindings use get_message_id from jvpp-common
to detect if messages known at compile time
are avaliable at runtime.

In case of missing entry, Java exception is propagated
via JNI using (*env)->ThrowNew.

But this function does not end code execution so,
in order to prevent unexpected behaviour
(e.g. calling vl_msg_api_set_handlers with id == 0),
get_message_id caller should do it manually.

Change-Id: I2edb5013fd3658dcdd77a867b5cdf62e559ee071
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
src/vpp-api/java/jvpp-acl/jvpp_acl.c
src/vpp-api/java/jvpp-common/jvpp_common.c
src/vpp-api/java/jvpp-core/jvpp_core.c
src/vpp-api/java/jvpp-gtpu/jvpp_gtpu.c
src/vpp-api/java/jvpp-ioamexport/jvpp_ioam_export.c
src/vpp-api/java/jvpp-ioampot/jvpp_ioam_pot.c
src/vpp-api/java/jvpp-ioamtrace/jvpp_ioam_trace.c
src/vpp-api/java/jvpp-nat/jvpp_nat.c
src/vpp-api/java/jvpp-pppoe/jvpp_pppoe.c

index f5467e9..82719aa 100644 (file)
@@ -54,7 +54,7 @@ JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_acl_JVppAclImpl_init0
 
   // verify API has not changed since jar generation
   #define _(N)             \
-      get_message_id(env, #N);  \
+      if (get_message_id(env, #N) == 0) return;
       foreach_supported_api_message;
   #undef _
 
index c00298b..2425607 100644 (file)
@@ -83,11 +83,14 @@ u32 get_message_id(JNIEnv *env, const char *key) {
     uword *p = hash_get(jvpp_main.messages_hash, key);
     if (!p) {
         jclass exClass = (*env)->FindClass(env, "java/lang/IllegalStateException");
-        char *msgBuf  = clib_mem_alloc(strlen(key) + 40);
+        char *msgBuf  = clib_mem_alloc(strlen(key) + 70);
         strcpy(msgBuf, "API mismatch detected: ");
         strcat(msgBuf, key);
-        strcat(msgBuf, " is missing");
-        DEBUG_LOG("get_message_id : %s\n", msgBuf);
+        strcat(msgBuf, " is missing in global name_crc hash table.");
+        DEBUG_LOG("%s", msgBuf);
+        DEBUG_LOG("Possible reasons:");
+        DEBUG_LOG("1) incompatible VPP version used");
+        DEBUG_LOG("2) message present in JSON file but not in global name_crc table");
         (*env)->ThrowNew(env, exClass, msgBuf);
         clib_mem_free(msgBuf);
         return 0;
index e57c62a..b12f63a 100644 (file)
@@ -55,9 +55,9 @@ JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_core_JVppCoreImpl_init0
     plugin_main->callbackObject = (*env)->NewGlobalRef(env, callback);
     plugin_main->callbackClass = (jclass)(*env)->NewGlobalRef(env, (*env)->GetObjectClass(env, callback));
 
-    // verify API has not changed since jar generation
+    // verify API has not changed since jar generation (exit on mismatch)
     #define _(N)             \
-        get_message_id(env, #N);  \
+        if (get_message_id(env, #N) == 0) return;
         foreach_supported_api_message;
     #undef _
 
index 12b3090..286a9ce 100644 (file)
@@ -54,7 +54,7 @@ JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_gtpu_JVppGtpuImpl_init0
 
   // verify API has not changed since jar generation
   #define _(N)             \
-      get_message_id(env, #N);  \
+      if (get_message_id(env, #N) == 0) return;
       foreach_supported_api_message;
   #undef _
 
index cf4499d..8d48613 100644 (file)
@@ -54,7 +54,7 @@ JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_ioamexport_JVppIoamexportImpl_init0
 
   // verify API has not changed since jar generation
   #define _(N)             \
-      get_message_id(env, #N);
+      if (get_message_id(env, #N) == 0) return;
       foreach_supported_api_message;
   #undef _
 
index 8f39698..4b9d1a5 100644 (file)
@@ -54,7 +54,7 @@ JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_ioampot_JVppIoampotImpl_init0
 
   // verify API has not changed since jar generation
   #define _(N)             \
-      get_message_id(env, #N);
+         if (get_message_id(env, #N) == 0) return;
       foreach_supported_api_message;
   #undef _
 
index f53937e..f917d1c 100644 (file)
@@ -54,7 +54,7 @@ JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_ioamtrace_JVppIoamtraceImpl_init0
 
   // verify API has not changed since jar generation
   #define _(N)             \
-      get_message_id(env, #N);
+      if (get_message_id(env, #N) == 0) return;
       foreach_supported_api_message;
   #undef _
 
index 85217f0..56c74d2 100644 (file)
@@ -54,7 +54,7 @@ JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_nat_JVppNatImpl_init0
 
   // verify API has not changed since jar generation
   #define _(N)             \
-      get_message_id(env, #N);
+      if (get_message_id(env, #N) == 0) return;
       foreach_supported_api_message;
   #undef _
 
index c9c3030..d339700 100644 (file)
@@ -54,7 +54,7 @@ JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_pppoe_JVppPppoeImpl_init0
 
   // verify API has not changed since jar generation
   #define _(N)             \
-      get_message_id(env, #N);  \
+      if (get_message_id(env, #N) == 0) return;
       foreach_supported_api_message;
   #undef _