aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2016-08-09 13:23:08 +0200
committerMaros Marsalek <mmarsale@cisco.com>2016-10-10 09:56:56 +0200
commit4c42e913c4f9723d27f6501f6e1b6a13b9c2f9f8 (patch)
treeda1bcfcab7b07b7b723af6e16820736d9934cdfb
parentcd8e318a7656c84ab1ff02090bf1616ca7513fdc (diff)
HONEYCOMB-228 Snat plugin jvpp support
Change-Id: I5510a0ae3ecfeb5bd41c3a73e6e05465ebd96165 Signed-off-by: Marek Gradzki <mgradzki@cisco.com> Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
-rw-r--r--build-data/packages/plugins.mk3
-rw-r--r--plugins/snat-plugin/Makefile.am55
-rw-r--r--plugins/snat-plugin/configure.ac15
-rw-r--r--plugins/snat-plugin/snat/jvpp/io/fd/vpp/jvpp/snat/test/CallbackApiTest.java70
-rw-r--r--plugins/snat-plugin/snat/jvpp/io/fd/vpp/jvpp/snat/test/Readme.txt1
-rw-r--r--plugins/snat-plugin/snat/jvpp_snat.c119
-rw-r--r--plugins/snat-plugin/snat/jvpp_snat.h45
7 files changed, 307 insertions, 1 deletions
diff --git a/build-data/packages/plugins.mk b/build-data/packages/plugins.mk
index 5d217c75cd4..53040194b89 100644
--- a/build-data/packages/plugins.mk
+++ b/build-data/packages/plugins.mk
@@ -11,7 +11,8 @@ plugins_CPPFLAGS = $(call installed_includes_fn, \
vnet \
svm \
vpp-api-test \
- vlib-api)
+ vlib-api \
+ vpp-api)
plugins_LDFLAGS = $(call installed_libs_fn, \
vppinfra \
diff --git a/plugins/snat-plugin/Makefile.am b/plugins/snat-plugin/Makefile.am
index 91fec414363..081340b5ff1 100644
--- a/plugins/snat-plugin/Makefile.am
+++ b/plugins/snat-plugin/Makefile.am
@@ -58,3 +58,58 @@ snat_test_plugin_la_SOURCES = \
install-data-hook:
@(cd $(vpppluginsdir) && $(RM) $(vppplugins_LTLIBRARIES))
@(cd $(vppapitestpluginsdir) && $(RM) $(vppapitestplugins_LTLIBRARIES))
+
+
+
+#
+# Java code generation
+#
+jvpp_registry_root = ../../vpp-api/java
+jvpp_registry_version = 16.12
+jsnat_jarfile = jvpp-snat-$(PACKAGE_VERSION).jar
+jvpp_package_dir = io/fd/vpp/jvpp/snat
+jvpp_root = snat/jvpp
+jvpp_target_dir = target
+jvpp_target = $(jvpp_root)/$(jvpp_target_dir)
+api_file=$(srcdir)/snat/snat.api
+
+lib_LTLIBRARIES = libjvpp_snat.la
+libjvpp_snat_la_SOURCES = snat/snat.api.h snat/jvpp_snat.c snat/jvpp/io_fd_vpp_jvpp_snat_JVppSnatImpl.h
+libjvpp_snat_la_LIBADD = -lvlibmemoryclient -lvlibapi -lvppinfra \
+ -lpthread -lm -lrt -L$(jvpp_registry_root)/.libs -ljvpp_common
+libjvpp_snat_la_LDFLAGS = -module
+libjvpp_snat_la_CPPFLAGS = -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux -I../ -I$(srcdir)/../
+
+BUILT_SOURCES += $(jvpp_root)/io_fd_vpp_jvpp_snat_JVppSnatImpl.h
+
+$(jvpp_root)/io_fd_vpp_jvpp_snat_JVppSnatImpl.h: defs_snat_papi.py
+ dir=`pwd`; \
+ mkdir -p $(jvpp_target); \
+ mkdir -p $(jvpp_root)/$(jvpp_package_dir); \
+ cd $(jvpp_root)/$(jvpp_package_dir); \
+ mkdir -p dto future callfacade callback notification test; \
+ @srcdir@/$(jvpp_registry_root)/jvpp/gen/jvpp_gen.py -i $${dir}/defs_snat_papi.py --plugin_name snat --control_ping_class SnatControlPing; \
+ cd -; \
+ mv -f $(jvpp_root)/$(jvpp_package_dir)/jvpp_snat_gen.h $(jvpp_root)/jvpp_snat_gen.h; \
+ cp $(srcdir)/$(jvpp_root)/$(jvpp_package_dir)/test/*.java $(jvpp_root)/$(jvpp_package_dir)/test/; \
+ cd $(jvpp_root); \
+ $(JAVAC) -classpath .:$(jvpp_target_dir):../../$(jvpp_registry_root)/jvpp-registry-$(jvpp_registry_version).jar -d $(jvpp_target_dir) $(jvpp_package_dir)/*.java \
+ $(jvpp_package_dir)/dto/*.java \
+ $(jvpp_package_dir)/callback/*.java \
+ $(jvpp_package_dir)/notification/*.java \
+ $(jvpp_package_dir)/future/*.java \
+ $(jvpp_package_dir)/callfacade/*.java \
+ $(jvpp_package_dir)/test/*.java \
+ || (echo "snat jvpp compilation failed: $$?"; exit 1); \
+ $(JAVAH) -classpath .:$(jvpp_target_dir):../../$(jvpp_registry_root)/jvpp-registry-$(jvpp_registry_version).jar -d . io.fd.vpp.jvpp.snat.JVppSnatImpl ;
+
+$(jsnat_jarfile): libjvpp_snat.la
+ cp .libs/libjvpp_snat.so.0.0.0 $(jvpp_target); \
+ cd $(jvpp_target); \
+ $(JAR) cfv $(JARFLAGS) ../../../$@ libjvpp_snat.so.0.0.0 $(jvpp_package_dir)/* ; cd ..;
+
+defs_snat_papi.py:
+ @echo " jSnat_sfc API"; \
+ vppapigen --input $(api_file) --python defs_snat_papi.py;
+
+all-local: $(jsnat_jarfile)
diff --git a/plugins/snat-plugin/configure.ac b/plugins/snat-plugin/configure.ac
index 9af139e4073..e7408b93850 100644
--- a/plugins/snat-plugin/configure.ac
+++ b/plugins/snat-plugin/configure.ac
@@ -1,4 +1,5 @@
AC_INIT(snat_plugin, 1.0)
+AC_CONFIG_MACRO_DIR([../../vpp-api/java/m4])
AM_INIT_AUTOMAKE
AM_SILENT_RULES([yes])
AC_PREFIX_DEFAULT([/usr])
@@ -6,6 +7,20 @@ AC_PREFIX_DEFAULT([/usr])
AC_PROG_LIBTOOL
AC_PROG_CC
+if test -f /usr/bin/lsb_release && test `lsb_release -si` == "Ubuntu" && test `lsb_release -sr` == "14.04" && test -d /usr/lib/jvm/java-8-openjdk-amd64/ ; then
+ JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/
+ JAVAC=${JAVA_HOME}/bin/javac
+ PATH=${JAVA_HOME}/bin/:${PATH}
+ break
+fi
+
+AX_CHECK_JAVA_HOME
+AX_PROG_JAVAC
+AX_PROG_JAVAH
+AX_PROG_JAR
+AX_PROG_JAVADOC
+AX_PROG_JAVA
+
AC_ARG_WITH(dpdk,
AC_HELP_STRING([--with-dpdk],[Use the Intel dpdk]),
[with_dpdk=1],
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
new file mode 100644
index 00000000000..850e1774fbc
--- /dev/null
+++ b/plugins/snat-plugin/snat/jvpp/io/fd/vpp/jvpp/snat/test/CallbackApiTest.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.vpp.jvpp.snat.test;
+
+import io.fd.vpp.jvpp.JVpp;
+import io.fd.vpp.jvpp.JVppRegistry;
+import io.fd.vpp.jvpp.JVppRegistryImpl;
+import io.fd.vpp.jvpp.VppCallbackException;
+import io.fd.vpp.jvpp.snat.JVppSnatImpl;
+import io.fd.vpp.jvpp.snat.callback.SnatInterfaceAddDelFeatureCallback;
+import io.fd.vpp.jvpp.snat.dto.SnatInterfaceAddDelFeature;
+import io.fd.vpp.jvpp.snat.dto.SnatInterfaceAddDelFeatureReply;
+
+public class CallbackApiTest {
+
+ static class TestCallback implements SnatInterfaceAddDelFeatureCallback {
+
+ @Override
+ public void onSnatInterfaceAddDelFeatureReply(final SnatInterfaceAddDelFeatureReply msg) {
+ System.out.printf("Received SnatInterfaceAddDelFeatureReply: context=%d\n",
+ msg.context);
+ }
+
+ @Override
+ public void onError(VppCallbackException ex) {
+ System.out.printf("Received onError exception: call=%s, context=%d, retval=%d\n", ex.getMethodName(),
+ ex.getCtxId(), ex.getErrorCode());
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ testCallbackApi();
+ }
+
+ private static void testCallbackApi() throws Exception {
+ System.out.println("Testing Java callback API for snat plugin");
+ JVppRegistry registry = new JVppRegistryImpl("SnatCallbackApiTest");
+ JVpp jvpp = new JVppSnatImpl();
+
+ registry.register(jvpp, new TestCallback());
+
+ System.out.println("Sending SnatInterfaceAddDelFeature request...");
+ SnatInterfaceAddDelFeature request = new SnatInterfaceAddDelFeature();
+ request.isAdd = 1;
+ request.isInside = 1;
+ request.swIfIndex = 1;
+ final int result = jvpp.send(request);
+ System.out.printf("SnatInterfaceAddDelFeature send result = %d\n", result);
+
+ Thread.sleep(1000);
+
+ System.out.println("Disconnecting...");
+ registry.close();
+ 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
new file mode 100644
index 00000000000..ac1b8f3f787
--- /dev/null
+++ b/plugins/snat-plugin/snat/jvpp/io/fd/vpp/jvpp/snat/test/Readme.txt
@@ -0,0 +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
diff --git a/plugins/snat-plugin/snat/jvpp_snat.c b/plugins/snat-plugin/snat/jvpp_snat.c
new file mode 100644
index 00000000000..537299ae751
--- /dev/null
+++ b/plugins/snat-plugin/snat/jvpp_snat.c
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <vnet/vnet.h>
+
+#include <snat/snat_msg_enum.h>
+#define vl_typedefs /* define message structures */
+#include <snat/snat_all_api_h.h>
+#undef vl_typedefs
+
+#define vl_endianfun
+#include <snat/snat_all_api_h.h>
+#undef vl_endianfun
+
+#define vl_print(handle, ...)
+#define vl_printfun
+#include <snat/snat_all_api_h.h>
+#undef vl_printfun
+
+/* Get the API version number */
+#define vl_api_version(n,v) static u32 api_version=(v);
+#include <snat/snat_all_api_h.h>
+#undef vl_api_version
+
+#include <vnet/api_errno.h>
+#include <vlibapi/api.h>
+#include <vlibmemory/api.h>
+
+#if VPPJNI_DEBUG == 1
+ #define DEBUG_LOG(...) clib_warning(__VA_ARGS__)
+#else
+ #define DEBUG_LOG(...)
+#endif
+
+#include <jvpp-common/jvpp_common.h>
+
+#include "snat/jvpp/io_fd_vpp_jvpp_snat_JVppSnatImpl.h"
+#include "jvpp_snat.h"
+#include "snat/jvpp/jvpp_snat_gen.h"
+
+/*
+ * Class: io_fd_vpp_jvpp_snat_JVppsnatImpl
+ * Method: init0
+ * Signature: (JI)V
+ */
+JNIEXPORT void JNICALL Java_io_fd_vpp_jvpp_snat_JVppSnatImpl_init0
+ (JNIEnv *env, jclass clazz, jobject callback, jlong queue_address, jint my_client_index) {
+ snat_main_t * plugin_main = &snat_main;
+ u8 * name;
+ clib_warning ("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);
+
+ 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, \
+ 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_snat_JVppSnatImpl_close0
+(JNIEnv *env, jclass clazz) {
+ snat_main_t * plugin_main = &snat_main;
+
+ // cleanup:
+ (*env)->DeleteGlobalRef(env, plugin_main->callbackClass);
+ (*env)->DeleteGlobalRef(env, plugin_main->callbackObject);
+
+ plugin_main->callbackClass = NULL;
+ plugin_main->callbackObject = NULL;
+}
+
+/* Attach thread to JVM and cache class references when initiating JVPP SNAT */
+jint JNI_OnLoad(JavaVM *vm, void *reserved) {
+ JNIEnv* env;
+
+ if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_8) != JNI_OK) {
+ return JNI_EVERSION;
+ }
+
+ if (cache_class_references(env) != 0) {
+ clib_warning ("Failed to cache class references\n");
+ return JNI_ERR;
+ }
+
+ return JNI_VERSION_1_8;
+}
+
+/* Clean up cached references when disposing JVPP SNAT */
+void JNI_OnUnload(JavaVM *vm, void *reserved) {
+ JNIEnv* env;
+ if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_8) != JNI_OK) {
+ return;
+ }
+ delete_class_references(env);
+}
diff --git a/plugins/snat-plugin/snat/jvpp_snat.h b/plugins/snat-plugin/snat/jvpp_snat.h
new file mode 100644
index 00000000000..6426bda8834
--- /dev/null
+++ b/plugins/snat-plugin/snat/jvpp_snat.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __included_jvpp_snat_h__
+#define __included_jvpp_snat_h__
+
+#include <vnet/vnet.h>
+#include <vnet/ip/ip.h>
+#include <vnet/api_errno.h>
+#include <vlibapi/api.h>
+#include <vlibmemory/api.h>
+#include <jni.h>
+
+/* Global state for JVPP-SNAT */
+typedef struct {
+ /* Base message index for the nsh plugin */
+ u16 msg_id_base;
+
+ /* Pointer to shared memory queue */
+ unix_shared_memory_queue_t * vl_input_queue;
+
+ /* VPP api client index */
+ u32 my_client_index;
+
+ /* Callback object and class references enabling asynchronous Java calls */
+ jobject callbackObject;
+ jclass callbackClass;
+
+} snat_main_t;
+
+snat_main_t snat_main __attribute__((aligned (64)));
+
+
+#endif /* __included_jvpp_snat_h__ */
har *format; /** Specifies how arguments to format are parsed from event data. String of characters '0' '1' or '2' '3' to specify log2 size of data (e.g. for u8, u16, u32 or u64), 's' means a null-terminated C string 't' means argument is an index into enum string table for this type. 'e' is a float, 'f' is a double. */ char *format_args; /** Function name generating event. */ char *function; /** Number of elements in string enum table. */ u32 n_enum_strings; /** String table for enum/number to string formatting. */ char *enum_strings[]; } elog_event_type_t; typedef struct { /** Track name vector. */ char *name; /** Set to one when track has been added to main structure. */ u32 track_index_plus_one; } elog_track_t; typedef struct { /** CPU cycle counter. */ u64 cpu; /** OS timer in nano secs since epoch 3/30/2017, see elog_time_now() */ u64 os_nsec; } elog_time_stamp_t; typedef struct { /** Total number of events in buffer. */ u32 n_total_events; /** When count reaches limit logging is disabled. This is used for event triggers. */ u32 n_total_events_disable_limit; /** Dummy event to use when logger is disabled. */ elog_event_t placeholder_event; /** Power of 2 number of elements in ring. */ uword event_ring_size; /** Vector of events (circular buffer). Power of 2 size. Used when events are being collected. */ elog_event_t *event_ring; /** Vector of event types. */ elog_event_type_t *event_types; /** Hash table mapping type format to type index. */ uword *event_type_by_format; /** Events may refer to strings in string table. */ char *string_table; uword *string_table_hash; u8 *string_table_tmp; /** Vector of tracks. */ elog_track_t *tracks; /** Default track. */ elog_track_t default_track; /** Place holder for CPU clock frequency. */ clib_time_t cpu_timer; /** Timestamps */ elog_time_stamp_t init_time, serialize_time; /** SMP lock, non-zero means locking required */ uword *lock; /** Use serialize_time and init_time to give estimate for cpu clock frequency. */ f64 nsec_per_cpu_clock; /** Vector of events converted to generic form after collection. */ elog_event_t *events; } elog_main_t; /** @brief Return number of events in the event-log buffer @param em elog_main_t * @return number of events in the buffer */ always_inline uword elog_n_events_in_buffer (elog_main_t * em) { return clib_min (em->n_total_events, em->event_ring_size); } /** @brief Return number of events which can fit in the event buffer @param em elog_main_t * @return number of events which can fit in the buffer */ always_inline uword elog_buffer_capacity (elog_main_t * em) { return em->event_ring_size; } /** @brief Reset the event buffer @param em elog_main_t * */ always_inline void elog_reset_buffer (elog_main_t * em) { em->n_total_events = 0; em->n_total_events_disable_limit = ~0; } /** @brief Enable or disable event logging @param em elog_main_t * */ always_inline void elog_enable_disable (elog_main_t * em, int is_enabled) { em->n_total_events = 0; em->n_total_events_disable_limit = is_enabled ? ~0 : 0; } /** @brief disable logging after specified number of ievents have been logged. This is used as a "debug trigger" when a certain event has occurred. Events will be logged both before and after the "event" but the event will not be lost as long as N < RING_SIZE. @param em elog_main_t * @param n uword number of events before disabling event logging */ always_inline void elog_disable_after_events (elog_main_t * em, uword n) { em->n_total_events_disable_limit = em->n_total_events + n; } /* @brief mid-buffer logic-analyzer trigger Currently, only midpoint triggering is supported, but it's pretty obvious how to generalize the scheme. @param em elog_main_t * */ always_inline void elog_disable_trigger (elog_main_t * em) { em->n_total_events_disable_limit = em->n_total_events + vec_len (em->event_ring) / 2; } /** @brief register an event type @param em elog_main_t * @param t elog_event_type_t * event to register @return type index @warning Typically not called directly */ word elog_event_type_register (elog_main_t * em, elog_event_type_t * t); /** @brief register an event track @param em elog_main_t * @param t elog_track_t * track to register @return track index @note this function is often called directly */ word elog_track_register (elog_main_t * em, elog_track_t * t); /** @brief event logging enabled predicate @param em elog_main_t * @return 1 if enabled, 0 if not enabled */ always_inline uword elog_is_enabled (elog_main_t * em) { return em->n_total_events < em->n_total_events_disable_limit; } /** @brief Allocate an event to be filled in by the caller Not normally called directly; this function underlies the ELOG_DATA and ELOG_TRACK_DATA macros @param em elog_main_t * @param type elog_event_type_t * type @param track elog_track_t * track @param cpu_time u64 current cpu tick value @returns event to be filled in */ always_inline void * elog_event_data_inline (elog_main_t * em, elog_event_type_t * type, elog_track_t * track, u64 cpu_time) { elog_event_t *e; uword ei; word type_index, track_index; /* Return the user placeholder memory to scribble data into. */ if (PREDICT_FALSE (!elog_is_enabled (em))) return em->placeholder_event.data; type_index = (word) type->type_index_plus_one - 1; track_index = (word) track->track_index_plus_one - 1; if (PREDICT_FALSE ((type_index | track_index) < 0)) { if (type_index < 0) type_index = elog_event_type_register (em, type); if (track_index < 0) track_index = elog_track_register (em, track); } ASSERT (track_index < vec_len (em->tracks)); ASSERT (is_pow2 (vec_len (em->event_ring))); if (em->lock) ei = clib_atomic_fetch_add (&em->n_total_events, 1); else ei = em->n_total_events++; ei &= em->event_ring_size - 1; e = vec_elt_at_index (em->event_ring, ei); e->time_cycles = cpu_time; e->event_type = type_index; e->track = track_index; /* Return user data for caller to fill in. */ return e->data; } /* External version of inline. */ void *elog_event_data (elog_main_t * em, elog_event_type_t * type, elog_track_t * track, u64 cpu_time); /** @brief Allocate an event to be filled in by the caller, non-inline Not normally called directly; this function underlies the ELOG_DATA and ELOG_TRACK_DATA macros @param em elog_main_t * @param type elog_event_type_t * type @param track elog_track_t * track @param cpu_time u64 current cpu tick value @returns event to be filled in */ always_inline void * elog_event_data_not_inline (elog_main_t * em, elog_event_type_t * type, elog_track_t * track, u64 cpu_time) { /* Return the user placeholder memory to scribble data into. */ if (PREDICT_FALSE (!elog_is_enabled (em))) return em->placeholder_event.data; return elog_event_data (em, type, track, cpu_time); } /** @brief Log a single-datum event @param em elog_main_t * @param type elog_event_type_t * type @param data u32 single datum to capture */ always_inline void elog (elog_main_t * em, elog_event_type_t * type, u32 data) { u32 *d = elog_event_data_not_inline (em, type, &em->default_track, clib_cpu_time_now ()); d[0] = data; } /** @brief Log a single-datum event, inline version @param em elog_main_t * @param type elog_event_type_t * type @param data u32 single datum to capture */ always_inline void elog_inline (elog_main_t * em, elog_event_type_t * type, u32 data) { u32 *d = elog_event_data_inline (em, type, &em->default_track, clib_cpu_time_now ()); d[0] = data; } /** @brief Log a single-datum event to a specific track, non-inline version @param em elog_main_t * @param type elog_event_type_t * type @param type elog_event_track_t * track @param data u32 single datum to capture */ always_inline void elog_track (elog_main_t * em, elog_event_type_t * type, elog_track_t * track, u32 data) { u32 *d = elog_event_data_not_inline (em, type, track, clib_cpu_time_now ()); d[0] = data; } /** @brief Log a single-datum event to a specific track @param em elog_main_t * @param type elog_event_type_t * type @param type elog_event_track_t * track @param data u32 single datum to capture */ always_inline void elog_track_inline (elog_main_t * em, elog_event_type_t * type, elog_track_t * track, u32 data) { u32 *d = elog_event_data_inline (em, type, track, clib_cpu_time_now ()); d[0] = data; } always_inline void * elog_data (elog_main_t * em, elog_event_type_t * type, elog_track_t * track) { return elog_event_data_not_inline (em, type, track, clib_cpu_time_now ()); } always_inline void * elog_data_inline (elog_main_t * em, elog_event_type_t * type, elog_track_t * track) { return elog_event_data_inline (em, type, track, clib_cpu_time_now ()); } /* Macro shorthands for generating/declaring events. */ #define __ELOG_TYPE_VAR(f) f #define __ELOG_TRACK_VAR(f) f #define ELOG_TYPE_DECLARE(f) static elog_event_type_t __ELOG_TYPE_VAR(f) #define ELOG_TYPE_INIT_FORMAT_AND_FUNCTION(fmt,func) \ { .format = fmt, .function = func, } #define ELOG_TYPE_INIT(fmt) \ ELOG_TYPE_INIT_FORMAT_AND_FUNCTION(fmt,(char *) __FUNCTION__) #define ELOG_TYPE_DECLARE_HELPER(f,fmt,func) \ static elog_event_type_t __ELOG_TYPE_VAR(f) = \ ELOG_TYPE_INIT_FORMAT_AND_FUNCTION (fmt, func) #define ELOG_TYPE_DECLARE_FORMAT_AND_FUNCTION(f,fmt) \ ELOG_TYPE_DECLARE_HELPER (f, fmt, (char *) __FUNCTION__) #define ELOG_TYPE_DECLARE_FORMAT(f,fmt) \ ELOG_TYPE_DECLARE_HELPER (f, fmt, 0) /* Shorthands with and without __FUNCTION__. D for decimal; X for hex. F for __FUNCTION__. */ #define ELOG_TYPE(f,fmt) ELOG_TYPE_DECLARE_FORMAT_AND_FUNCTION(f,fmt) #define ELOG_TYPE_D(f) ELOG_TYPE_DECLARE_FORMAT (f, #f " %d") #define ELOG_TYPE_X(f) ELOG_TYPE_DECLARE_FORMAT (f, #f " 0x%x") #define ELOG_TYPE_DF(f) ELOG_TYPE_DECLARE_FORMAT_AND_FUNCTION (f, #f " %d") #define ELOG_TYPE_XF(f) ELOG_TYPE_DECLARE_FORMAT_AND_FUNCTION (f, #f " 0x%x") #define ELOG_TYPE_FD(f) ELOG_TYPE_DECLARE_FORMAT_AND_FUNCTION (f, #f " %d") #define ELOG_TYPE_FX(f) ELOG_TYPE_DECLARE_FORMAT_AND_FUNCTION (f, #f " 0x%x") #define ELOG_TRACK_DECLARE(f) static elog_track_t __ELOG_TRACK_VAR(f) #define ELOG_TRACK(f) ELOG_TRACK_DECLARE(f) = { .name = #f, } /* Log 32 bits of data. */ #define ELOG(em,f,data) elog ((em), &__ELOG_TYPE_VAR(f), data) #define ELOG_INLINE(em,f,data) elog_inline ((em), &__ELOG_TYPE_VAR(f), data) /* Return data pointer to fill in. */ #define ELOG_TRACK_DATA(em,f,track) \ elog_data ((em), &__ELOG_TYPE_VAR(f), &__ELOG_TRACK_VAR(track)) #define ELOG_TRACK_DATA_INLINE(em,f,track) \ elog_data_inline ((em), &__ELOG_TYPE_VAR(f), &__ELOG_TRACK_VAR(track)) /* Shorthand with default track. */ #define ELOG_DATA(em,f) elog_data ((em), &__ELOG_TYPE_VAR (f), &(em)->default_track) #define ELOG_DATA_INLINE(em,f) elog_data_inline ((em), &__ELOG_TYPE_VAR (f), &(em)->default_track) /** @brief add a string to the event-log string table Often combined with hashing and the T4 elog format specifier to display complex strings in offline tooling @param em elog_main_t * @param format char * @param VARARGS @return u32 index to add to event log */ u32 elog_string (elog_main_t * em, char *format, ...); void elog_time_now (elog_time_stamp_t * et); /** @brief convert event ring events to events, and return them as a vector. @param em elog_main_t * @return event vector with timestamps in f64 seconds @note sets em->events to resulting vector. */ elog_event_t *elog_get_events (elog_main_t * em); /** @brief convert event ring events to events, and return them as a vector. @param em elog_main_t * @return event vector with timestamps in f64 seconds @note no side effects */ elog_event_t *elog_peek_events (elog_main_t * em); /* Merge two logs, add supplied track tags. */ void elog_merge (elog_main_t * dst, u8 * dst_tag, elog_main_t * src, u8 * src_tag, f64 align_tweak); /* 2 arguments elog_main_t and elog_event_t to format event or track name. */ u8 *format_elog_event (u8 * s, va_list * va); u8 *format_elog_track_name (u8 * s, va_list * va); u8 *format_elog_track (u8 * s, va_list * args); void serialize_elog_main (serialize_main_t * m, va_list * va); void unserialize_elog_main (serialize_main_t * m, va_list * va); void elog_init (elog_main_t * em, u32 n_events); void elog_alloc (elog_main_t * em, u32 n_events); void elog_resize (elog_main_t * em, u32 n_events); #ifdef CLIB_UNIX always_inline clib_error_t * elog_write_file (elog_main_t * em, char *clib_file, int flush_ring) { serialize_main_t m; clib_error_t *error; error = serialize_open_clib_file (&m, clib_file); if (error) return error; error = serialize (&m, serialize_elog_main, em, flush_ring); if (!error) serialize_close (&m); return error; } clib_error_t *elog_write_file_not_inline (elog_main_t * em, char *clib_file, int flush_ring); always_inline clib_error_t * elog_read_file (elog_main_t * em, char *clib_file) { serialize_main_t m; clib_error_t *error; error = unserialize_open_clib_file (&m, clib_file); if (error) return error; error = unserialize (&m, unserialize_elog_main, em); if (!error) unserialize_close (&m); return error; } clib_error_t *elog_read_file_not_inline (elog_main_t * em, char *clib_file); char *format_one_elog_event (void *em_arg, void *ep_arg); #endif /* CLIB_UNIX */ #endif /* included_clib_elog_h */ /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */