diff options
author | Marek Gradzki <mgradzki@cisco.com> | 2016-11-03 10:52:43 +0100 |
---|---|---|
committer | Damjan Marion <dmarion.lists@gmail.com> | 2016-11-03 16:42:41 +0000 |
commit | bdb1f8193736c0c63429d049397d4783959c1148 (patch) | |
tree | 48df00eab6d0315a91b67cd81286ae5536f1f81f /plugins/snat-plugin | |
parent | e7637e701717f24172cdbdbf89ba71bdef5125de (diff) |
Fail to register Java API for plugin that was not loaded (VPP-522)
Change-Id: Idb95888ae6fc7a9df197a919e3d3283f915f4a4c
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'plugins/snat-plugin')
3 files changed, 10 insertions, 6 deletions
diff --git a/plugins/snat-plugin/snat/jvpp/io/fd/vpp/jvpp/snat/test/CallbackApiTest.java b/plugins/snat-plugin/snat/jvpp/io/fd/vpp/jvpp/snat/test/CallbackApiTest.java index e168d0560e7..32165d962ba 100644 --- a/plugins/snat-plugin/snat/jvpp/io/fd/vpp/jvpp/snat/test/CallbackApiTest.java +++ b/plugins/snat-plugin/snat/jvpp/io/fd/vpp/jvpp/snat/test/CallbackApiTest.java @@ -64,6 +64,5 @@ public class CallbackApiTest { System.out.println("Disconnecting..."); } - Thread.sleep(1000); } } diff --git a/plugins/snat-plugin/snat/jvpp/io/fd/vpp/jvpp/snat/test/Readme.txt b/plugins/snat-plugin/snat/jvpp/io/fd/vpp/jvpp/snat/test/Readme.txt index ac1b8f3f787..dbd4c996265 100644 --- a/plugins/snat-plugin/snat/jvpp/io/fd/vpp/jvpp/snat/test/Readme.txt +++ b/plugins/snat-plugin/snat/jvpp/io/fd/vpp/jvpp/snat/test/Readme.txt @@ -1 +1 @@ -sudo java -cp build-vpp-native/vpp-api/java/jvpp-registry-16.12.jar:build-vpp-native/vpp-api/java/jvpp-core-16.12.jar:build-vpp-native/plugins/snat-plugin/jvpp-snat-1.0.jar io.fd.vpp.jvpp.snat.test.CallbackApiTest +sudo java -cp build-vpp-native/vpp-api/java/jvpp-registry-16.12.jar:build-vpp-native/plugins/snat-plugin/jvpp-snat-1.0.jar io.fd.vpp.jvpp.snat.test.CallbackApiTest diff --git a/plugins/snat-plugin/snat/jvpp_snat.c b/plugins/snat-plugin/snat/jvpp_snat.c index 537299ae751..fd72ddb14b2 100644 --- a/plugins/snat-plugin/snat/jvpp_snat.c +++ b/plugins/snat-plugin/snat/jvpp_snat.c @@ -64,11 +64,15 @@ JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_snat_JVppSnatImpl_init0 plugin_main->my_client_index = my_client_index; plugin_main->vl_input_queue = (unix_shared_memory_queue_t *)queue_address; - name = format (0, "snat_%08x%c", api_version, 0); - plugin_main->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name); + name = format (0, "snat_%08x%c", api_version, 0); + plugin_main->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name); - plugin_main->callbackObject = (*env)->NewGlobalRef(env, callback); - plugin_main->callbackClass = (jclass)(*env)->NewGlobalRef(env, (*env)->GetObjectClass(env, callback)); + if (plugin_main->msg_id_base == (u16) ~0) { + jclass exClass = (*env)->FindClass(env, "java/lang/IllegalStateException"); + (*env)->ThrowNew(env, exClass, "snat plugin is not loaded in VPP"); + } else { + plugin_main->callbackObject = (*env)->NewGlobalRef(env, callback); + plugin_main->callbackClass = (jclass)(*env)->NewGlobalRef(env, (*env)->GetObjectClass(env, callback)); #define _(N,n) \ vl_msg_api_set_handlers(VL_API_##N + plugin_main->msg_id_base, #n, \ @@ -79,6 +83,7 @@ JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_snat_JVppSnatImpl_init0 sizeof(vl_api_##n##_t), 1); foreach_api_reply_handler; #undef _ + } } JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_snat_JVppSnatImpl_close0 |