summaryrefslogtreecommitdiffstats
path: root/nsh-plugin
diff options
context:
space:
mode:
authorHongjun Ni <hongjun.ni@intel.com>2017-03-16 00:07:36 +0800
committerHongjun Ni <hongjun.ni@intel.com>2017-03-23 22:45:52 +0800
commitaa609dfe9072323483c8c0a95460b1be4ca05383 (patch)
treeacb406b260e824fcb444be7b82b878820b9d2a38 /nsh-plugin
parent48473a840103b7f75a0749d371d0493337bd173b (diff)
Hc2vpp failed to load libjvpp_nsh.so
Modify code to adapt new API registration mechanism Change-Id: I968199e86278a01ff01267e55468099886689d12 Signed-off-by: Hongjun Ni <hongjun.ni@intel.com>
Diffstat (limited to 'nsh-plugin')
-rw-r--r--nsh-plugin/java/Makefile.am25
-rw-r--r--nsh-plugin/java/jvpp/jvpp_nsh.c50
-rw-r--r--nsh-plugin/java/jvpp/jvpp_nsh.h5
-rw-r--r--nsh-plugin/nsh/nsh.c18
4 files changed, 46 insertions, 52 deletions
diff --git a/nsh-plugin/java/Makefile.am b/nsh-plugin/java/Makefile.am
index 3a30bdd..416a0e4 100644
--- a/nsh-plugin/java/Makefile.am
+++ b/nsh-plugin/java/Makefile.am
@@ -16,15 +16,15 @@ ACLOCAL_AMFLAGS = -I m4
AM_CFLAGS = -Wall
-noinst_PROGRAMS =
+noinst_PROGRAMS =
BUILT_SOURCES =
-bin_PROGRAMS =
-CLEANFILES =
+bin_PROGRAMS =
+CLEANFILES =
nobase_include_HEADERS = jvpp/io_fd_vpp_jvpp_nsh_JVppNshImpl.h
jarfile_jnsh_sfc = jnsh_sfc-$(PACKAGE_VERSION).jar
-java_packagedir = io/fd/nsh_sfc/jvpp
+java_packagedir = io/fd/vpp/jvpp/nsh
java_gendir = jvpp/src/main/java
resourcesdir = jvpp/src/main/resources
api_file=$(srcdir)/../nsh/nsh.api
@@ -36,23 +36,18 @@ lib_LTLIBRARIES = libjvpp_nsh.la
libjvpp_nsh_la_SOURCES = $(srcdir)/../java/nsh.api.h jvpp/jvpp_nsh.c jvpp/io_fd_vpp_jvpp_nsh_JVppNshImpl.h
libjvpp_nsh_la_LIBADD = -lvlibmemoryclient -lvlibapi -lsvm -lvppinfra \
- -lpthread -lm -lrt
-libjvpp_nsh_la_LIBAD = libjvpp_common.la
+ -lpthread -lm -lrt -ljvpp_common
libjvpp_nsh_la_LDFLAGS = -module
libjvpp_nsh_la_CPPFLAGS = -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux -I../ -I$(srcdir)/../
BUILT_SOURCES = jvpp/io_fd_vpp_jvpp_nsh_JVppNshImpl.h
jvpp/io_fd_vpp_jvpp_nsh_JVppNshImpl.h: nsh.api.json
- dir=`pwd`; \
- mkdir -p $(java_gendir)/$(java_packagedir); \
- cd $(java_gendir)/$(java_packagedir); \
- mkdir -p dto future callfacade callback notification test; \
- cd -; \
$(jvpp_gen) -i nsh.api.json --plugin_name nsh --root_dir $(java_gendir)/$(java_packagedir) > /dev/null; \
- mv -f $(java_gendir)/$(java_packagedir)/target/io/fd/vpp/jvpp/nsh/ $(java_gendir)/$(java_packagedir)/; \
- mv -f $(java_gendir)/$(java_packagedir)/jvpp_nsh_gen.h jvpp/jvpp_nsh_gen.h; \
+ mv -f $(java_gendir)/$(java_packagedir)/target/io/fd/vpp/jvpp/nsh/* $(java_gendir)/$(java_packagedir)/; \
+ mv -f $(java_gendir)/$(java_packagedir)/jvpp_nsh_gen.h jvpp/jvpp_nsh_gen.h; \
cp $(srcdir)/pom.xml jvpp/; \
+ mkdir -p $(java_gendir)/$(java_packagedir)/test;
cp $(srcdir)/jvpp/test/*.java $(java_gendir)/$(java_packagedir)/test/; \
cd jvpp; \
mvn $${MAVEN_SETTINGS_OPTIONS} -v; \
@@ -60,12 +55,12 @@ jvpp/io_fd_vpp_jvpp_nsh_JVppNshImpl.h: nsh.api.json
$(jarfile_jnsh_sfc): libjvpp_nsh.la
mkdir -p $(resourcesdir); \
- cp .libs/libjvpp_nsh.so.0.0.0 $(resourcesdir); \
+ cp .libs/libjvpp_nsh.so $(resourcesdir)/libjvpp_nsh.so; \
cd jvpp; \
mvn $${MAVEN_SETTINGS_OPTIONS} -v; \
mvn $${MAVEN_SETTINGS_OPTIONS} package;
-nsh.api.json:
+nsh.api.json: $(api_file)
@echo " jNsh_sfc API"; \
$(CC) $(CPPFLAGS) -E -P -C -x c $^ \
| vppapigen --input $(api_file) --json $@
diff --git a/nsh-plugin/java/jvpp/jvpp_nsh.c b/nsh-plugin/java/jvpp/jvpp_nsh.c
index 9dd5bf7..bea330b 100644
--- a/nsh-plugin/java/jvpp/jvpp_nsh.c
+++ b/nsh-plugin/java/jvpp/jvpp_nsh.c
@@ -29,11 +29,6 @@
#include <vpp-api/nsh_all_api_h.h>
#undef vl_printfun
-/* Get the API version number */
-#define vl_api_version(n,v) static u32 api_version=(v);
-#include <vpp-api/nsh_all_api_h.h>
-#undef vl_api_version
-
#include <vnet/api_errno.h>
#include <vlibapi/api.h>
#include <vlibmemory/api.h>
@@ -53,38 +48,29 @@
JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_nsh_JVppNshImpl_init0
(JNIEnv *env, jclass clazz, jobject callback, jlong queue_address, jint my_client_index) {
nsh_main_t * plugin_main = &nsh_main;
- u8 * name;
clib_warning ("Java_io_fd_vpp_jvpp_nsh_JVppNshImpl_init0");
plugin_main->my_client_index = my_client_index;
plugin_main->vl_input_queue = (unix_shared_memory_queue_t *)queue_address;
- name = format (0, "nsh_%08x%c", api_version, 0);
- plugin_main->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
-
- if (plugin_main->msg_id_base == (u16) ~0) {
- jclass exClass = (*env)->FindClass(env, "java/lang/IllegalStateException");
- (*env)->ThrowNew(env, exClass, "nsh 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));
-
- // verify API has not changed since jar generation
- #define _(N) \
- get_message_id(env, #N);
- foreach_supported_api_message;
- #undef _
-
- #define _(N,n) \
- vl_msg_api_set_handlers(get_message_id(env, #N), #n, \
- vl_api_##n##_t_handler, \
- vl_noop_handler, \
- vl_api_##n##_t_endian, \
- vl_api_##n##_t_print, \
- sizeof(vl_api_##n##_t), 1);
- foreach_api_reply_handler;
- #undef _
- }
+ 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
+ #define _(N) \
+ get_message_id(env, #N);
+ foreach_supported_api_message;
+ #undef _
+
+ #define _(N,n) \
+ vl_msg_api_set_handlers(get_message_id(env, #N), #n, \
+ vl_api_##n##_t_handler, \
+ vl_noop_handler, \
+ vl_api_##n##_t_endian, \
+ vl_api_##n##_t_print, \
+ sizeof(vl_api_##n##_t), 1);
+ foreach_api_reply_handler;
+ #undef _
}
JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_nsh_JVppNshImpl_close0
diff --git a/nsh-plugin/java/jvpp/jvpp_nsh.h b/nsh-plugin/java/jvpp/jvpp_nsh.h
index 1f9ab58..8cd6a44 100644
--- a/nsh-plugin/java/jvpp/jvpp_nsh.h
+++ b/nsh-plugin/java/jvpp/jvpp_nsh.h
@@ -23,10 +23,7 @@
#include <jni.h>
typedef struct {
- /* Base message index for the nsh plugin */
- u16 msg_id_base;
-
- /* Pointer to shared memory queue */
+ /* Pointer to shared memory queue */
unix_shared_memory_queue_t * vl_input_queue;
/* VPP api client index */
diff --git a/nsh-plugin/nsh/nsh.c b/nsh-plugin/nsh/nsh.c
index 67ddaba..6ff60c8 100644
--- a/nsh-plugin/nsh/nsh.c
+++ b/nsh-plugin/nsh/nsh.c
@@ -51,6 +51,10 @@
#include <vpp-api/nsh_all_api_h.h>
#undef vl_api_version
+#define vl_msg_name_crc_list
+#include <vpp-api/nsh_all_api_h.h>
+#undef vl_msg_name_crc_list
+
/*
* A handy macro to set up a message reply.
* Assumes that the following variables are available:
@@ -1378,7 +1382,7 @@ VLIB_CLI_COMMAND (show_nsh_entry_command, static) = {
static clib_error_t *
nsh_plugin_api_hookup (vlib_main_t *vm)
{
- nsh_main_t * nm = &nsh_main;
+ nsh_main_t * nm __attribute__ ((unused)) = &nsh_main;
#define _(N,n) \
vl_msg_api_set_handlers((VL_API_##N + nm->msg_id_base), \
#n, \
@@ -1393,6 +1397,15 @@ nsh_plugin_api_hookup (vlib_main_t *vm)
return 0;
}
+static void
+setup_message_id_table (nsh_main_t * nm, api_main_t * am)
+{
+#define _(id,n,crc) \
+ vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + nm->msg_id_base);
+ foreach_vl_msg_name_crc_nsh;
+#undef _
+}
+
always_inline void
nsh_md2_encap (vlib_buffer_t * b, nsh_base_header_t *hdr,
nsh_entry_t * nsh_entry)
@@ -2304,6 +2317,9 @@ clib_error_t *nsh_init (vlib_main_t *vm)
error = nsh_plugin_api_hookup (vm);
+ /* Add our API messages to the global name_crc hash table */
+ setup_message_id_table (nm, &api_main);
+
/* Add dispositions to nodes that feed nsh-input */
//alagalah - validate we don't really need to use the node value
next_node = vlib_node_add_next (vm, vxlan4_gpe_input_node.index, nsh_input_node.index);