2 * Copyright (c) 2016 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #include <vnet/vnet.h>
18 #include <ioam/lib-trace/trace_msg_enum.h>
19 #define vl_typedefs /* define message structures */
20 #include <ioam/lib-trace/trace_all_api_h.h>
24 #include <ioam/lib-trace/trace_all_api_h.h>
27 #define vl_print(handle, ...)
29 #include <ioam/lib-trace/trace_all_api_h.h>
32 /* Get the API version number */
33 #define vl_api_version(n,v) static u32 api_version=(v);
34 #include <ioam/lib-trace/trace_all_api_h.h>
37 #include <vnet/api_errno.h>
38 #include <vlibapi/api.h>
39 #include <vlibmemory/api.h>
42 #define DEBUG_LOG(...) clib_warning(__VA_ARGS__)
44 #define DEBUG_LOG(...)
47 #include <jvpp-common/jvpp_common.h>
49 #include "ioam/jvpp/io_fd_vpp_jvpp_ioamtrace_JVppIoamtraceImpl.h"
50 #include "jvpp_ioam_trace.h"
51 #include "ioam/jvpp/jvpp_ioam_trace_gen.h"
54 * Class: io_fd_vpp_jvpp_ioamtrace_JVppIoamtraceImpl
58 JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_ioamtrace_JVppIoamtraceImpl_init0
59 (JNIEnv *env, jclass clazz, jobject callback, jlong queue_address, jint my_client_index) {
60 ioamtrace_main_t * plugin_main = &ioamtrace_main;
62 clib_warning ("Java_io_fd_vpp_jvpp_ioamtrace_JVppIoamtraceImpl_init0");
64 plugin_main->my_client_index = my_client_index;
65 plugin_main->vl_input_queue = (unix_shared_memory_queue_t *)queue_address;
67 name = format (0, "ioam_trace_%08x%c", api_version, 0);
68 plugin_main->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
70 plugin_main->callbackObject = (*env)->NewGlobalRef(env, callback);
71 plugin_main->callbackClass = (jclass)(*env)->NewGlobalRef(env, (*env)->GetObjectClass(env, callback));
74 vl_msg_api_set_handlers(VL_API_##N + plugin_main->msg_id_base, #n, \
75 vl_api_##n##_t_handler, \
77 vl_api_##n##_t_endian, \
78 vl_api_##n##_t_print, \
79 sizeof(vl_api_##n##_t), 1);
80 foreach_api_reply_handler;
84 JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_ioamtrace_JVppIoamtraceImpl_close0
85 (JNIEnv *env, jclass clazz) {
86 ioamtrace_main_t * plugin_main = &ioamtrace_main;
89 (*env)->DeleteGlobalRef(env, plugin_main->callbackClass);
90 (*env)->DeleteGlobalRef(env, plugin_main->callbackObject);
92 plugin_main->callbackClass = NULL;
93 plugin_main->callbackObject = NULL;
96 /* Attach thread to JVM and cache class references when initiating JVPP iOAM Trace */
97 jint JNI_OnLoad(JavaVM *vm, void *reserved) {
100 if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_8) != JNI_OK) {
104 if (cache_class_references(env) != 0) {
105 clib_warning ("Failed to cache class references\n");
109 return JNI_VERSION_1_8;
112 /* Clean up cached references when disposing JVPP iOAM Trace */
113 void JNI_OnUnload(JavaVM *vm, void *reserved) {
115 if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_8) != JNI_OK) {
118 delete_class_references(env);