aboutsummaryrefslogtreecommitdiffstats
path: root/extras
diff options
context:
space:
mode:
Diffstat (limited to 'extras')
-rw-r--r--extras/emacs/README86
-rw-r--r--extras/emacs/all-skel.el40
-rw-r--r--extras/emacs/cli-cmd-skel.el32
-rw-r--r--extras/emacs/config-skel.el28
-rw-r--r--extras/emacs/dual-loop-skel.el302
-rw-r--r--extras/emacs/elog-4-int-skel.el31
-rw-r--r--extras/emacs/elog-4-int-track-skel.el34
-rw-r--r--extras/emacs/elog-enum-skel.el35
-rw-r--r--extras/emacs/elog-one-datum-skel.el28
-rwxr-xr-xextras/emacs/fix-coding-style.el162
-rwxr-xr-xextras/emacs/make-plugin.sh4
-rw-r--r--extras/emacs/periodic-skel.el86
-rw-r--r--extras/emacs/pipe-skel.el132
-rw-r--r--extras/emacs/plugin-all-apih-skel.el43
-rw-r--r--extras/emacs/plugin-am-skel.el60
-rw-r--r--extras/emacs/plugin-api-skel.el48
-rw-r--r--extras/emacs/plugin-h-skel.el66
-rw-r--r--extras/emacs/plugin-main-skel.el280
-rw-r--r--extras/emacs/plugin-msg-enum-skel.el55
-rw-r--r--extras/emacs/plugin-node-skel.el330
-rw-r--r--extras/emacs/plugin-test-skel.el212
-rw-r--r--extras/emacs/plugin.el32
-rw-r--r--extras/emacs/tunnel-c-skel.el452
-rw-r--r--extras/emacs/tunnel-decap-skel.el299
-rw-r--r--extras/emacs/tunnel-encap-skel.el245
-rw-r--r--extras/emacs/tunnel-h-skel.el128
-rw-r--r--extras/gdb/gdb_cmdfile.vcl_client10
-rw-r--r--extras/gdb/gdb_cmdfile.vcl_server10
-rw-r--r--extras/gdb/gdb_cmdfile.vpp7
-rw-r--r--extras/libmemif/Makefile.am89
-rwxr-xr-xextras/libmemif/bootstrap3
-rw-r--r--extras/libmemif/configure.ac13
-rw-r--r--extras/libmemif/dockerfile19
-rw-r--r--extras/libmemif/docs/architecture.pngbin0 -> 18805 bytes
-rw-r--r--extras/libmemif/docs/buildinstructions_doc.md55
-rw-r--r--extras/libmemif/docs/gettingstarted_doc.md219
-rw-r--r--extras/libmemif/doxygen.conf2427
-rw-r--r--extras/libmemif/examples/example_setup_doc.md207
-rw-r--r--extras/libmemif/examples/examples_doc.md18
-rw-r--r--extras/libmemif/examples/icmp_responder-epoll/main.c791
-rw-r--r--extras/libmemif/examples/icmp_responder-mt/main.c921
-rw-r--r--extras/libmemif/examples/icmp_responder/icmp_proto.c246
-rw-r--r--extras/libmemif/examples/icmp_responder/icmp_proto.h26
-rw-r--r--extras/libmemif/examples/icmp_responder/main.c416
-rw-r--r--extras/libmemif/libmemif_doc.md74
-rw-r--r--extras/libmemif/src/libmemif.h443
-rw-r--r--extras/libmemif/src/main.c2095
-rw-r--r--extras/libmemif/src/memif.h185
-rw-r--r--extras/libmemif/src/memif_private.h266
-rw-r--r--extras/libmemif/src/socket.c881
-rw-r--r--extras/libmemif/src/socket.h89
-rw-r--r--extras/libmemif/test/main_test.c1079
-rw-r--r--extras/libmemif/test/main_test.h25
-rw-r--r--extras/libmemif/test/socket_test.c625
-rw-r--r--extras/libmemif/test/socket_test.h25
-rw-r--r--extras/libmemif/test/unit_test.c63
-rw-r--r--extras/libmemif/test/unit_test.h38
-rw-r--r--extras/rpm/Makefile46
-rw-r--r--extras/rpm/vpp.service14
-rw-r--r--extras/rpm/vpp.spec349
-rwxr-xr-xextras/scripts/coverity-blame36
-rwxr-xr-xextras/scripts/coverity-build70
-rwxr-xr-xextras/scripts/lsnet20
-rwxr-xr-xextras/scripts/pci-nic-bind94
-rwxr-xr-xextras/scripts/pci-nic-bind-to-kernel19
-rw-r--r--extras/vagrant/.gitignore1
-rw-r--r--extras/vagrant/README43
-rw-r--r--extras/vagrant/Vagrantfile112
-rw-r--r--extras/vagrant/Vagrantfile.vcl_test111
-rw-r--r--extras/vagrant/WELCOME61
-rwxr-xr-xextras/vagrant/build.sh85
-rwxr-xr-xextras/vagrant/clearinterfaces.sh17
-rw-r--r--extras/vagrant/env.sh6
-rw-r--r--extras/vagrant/install.sh30
-rwxr-xr-xextras/vagrant/run.sh23
-rwxr-xr-xextras/vagrant/update.sh53
-rwxr-xr-xextras/vagrant/vcl_test.sh25
77 files changed, 15830 insertions, 0 deletions
diff --git a/extras/emacs/README b/extras/emacs/README
new file mode 100644
index 00000000..1f09a3fa
--- /dev/null
+++ b/extras/emacs/README
@@ -0,0 +1,86 @@
+How to construct a complete plugin using the emacs skeletons
+
+0. Install open-vpp, including the development package.
+
+1. Load emacs skeletons
+
+ M-x find-file all-skel.el
+ M-x eval-buffer
+
+2. Pick a single-word, lower-case name for your plugin. For example: macswap.
+Hereafter, we'll refer to the selected name as <plugin-name>.
+
+3. Generate the entire plugin:
+
+ M-x make-plugin
+ Plugin-name: <plugin-name>
+
+Or, generate each file individually:
+
+3. Create the required directories, e.g. under .../vpp
+
+ $ mkdir -p <plugin-name>-plugin/<plugin-name>
+
+4. Create <plugin-name>-plugin/{configure.ac,Makefile.am}
+
+ M-x find-file <plugin-name>-plugin/configure.ac
+ M-x plugin-configure-skel
+
+ M-x find-file <plugin-name>-plugin/Makefile.am
+ M-x skel-plugin-makefile
+
+5. Create the api skeleton
+ M-x find-file <plugin-name>-plugin/<plugin-name>/<plugin-name>.api
+ M-x skel-plugin-api
+
+6. Create the api message enumeration header file
+ M-x find-file <plugin-name>-plugin/<plugin-name>/<plugin-name>_msg_enum.h
+ M-x skel-plugin-msg-enum
+
+7. Create the "all-api" header file
+ M-x find-file <plugin-name>-plugin/<plugin-name>/<plugin-name>_all_api_h.h
+ M-x skel-plugin-all-apih
+
+8. Create the main data structure definition header file
+ M-x find-file <plugin-name>-plugin/<plugin-name>/<plugin-name>.h
+ M-x skel-plugin-h
+
+9. Create the plugin main C file
+ M-x find-file <plugin-name>-plugin/<plugin-name>/<plugin-name>.c
+ M-x skel-plugin-main
+
+10. Create the vpp-api-test plugin main C file
+ M-x find-file <plugin-name>-plugin/<plugin-name>/<plugin-name>_test.c
+ M-x skel-plugin-test
+
+11. Create the data plane packet processing node
+ M-x find-file <plugin-name>-plugin/<plugin-name>/node.c
+ M-x skel-plugin-node
+
+12. Process autotools input files
+
+ $ cd <plugin-name>-plugin
+ $ autoreconf -i -f
+
+13. Build the plugin skeleton
+
+ $ mkdir build
+ $ cd build
+ $ ../configure
+ $ make
+ $ sudo make install
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/extras/emacs/all-skel.el b/extras/emacs/all-skel.el
new file mode 100644
index 00000000..f0cc9fe3
--- /dev/null
+++ b/extras/emacs/all-skel.el
@@ -0,0 +1,40 @@
+;;; 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.
+
+;; plugin all-in-1 program
+
+(load-file "./plugin.el")
+
+;; list of clib / vlib / vnet / vpp skeleton files
+
+(load-file "./cli-cmd-skel.el")
+(load-file "./config-skel.el")
+(load-file "./dual-loop-skel.el")
+(load-file "./periodic-skel.el")
+(load-file "./pipe-skel.el")
+(load-file "./plugin-all-apih-skel.el")
+(load-file "./plugin-am-skel.el")
+(load-file "./plugin-api-skel.el")
+(load-file "./plugin-h-skel.el")
+(load-file "./plugin-main-skel.el")
+(load-file "./plugin-msg-enum-skel.el")
+(load-file "./plugin-node-skel.el")
+(load-file "./plugin-test-skel.el")
+(load-file "./tunnel-c-skel.el")
+(load-file "./tunnel-decap-skel.el")
+(load-file "./tunnel-encap-skel.el")
+(load-file "./tunnel-h-skel.el")
+(load-file "./elog-4-int-skel.el")
+(load-file "./elog-4-int-track-skel.el")
+(load-file "./elog-enum-skel.el")
+(load-file "./elog-one-datum-skel.el")
diff --git a/extras/emacs/cli-cmd-skel.el b/extras/emacs/cli-cmd-skel.el
new file mode 100644
index 00000000..cf8658c4
--- /dev/null
+++ b/extras/emacs/cli-cmd-skel.el
@@ -0,0 +1,32 @@
+;;; cli-cmd-skel.el - cli command skeleton
+
+(require 'skeleton)
+
+(define-skeleton skel-cli-cmd
+"Insert a CLI command "
+nil
+'(setq cmd-name (skeleton-read "Command Name: "))
+'(setq path (skeleton-read "Path: "))
+
+"
+static clib_error_t *
+" cmd-name "_command_fn (vlib_main_t * vm,
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd)
+{
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
+ if (unformat (input, \"whatever %d\", &whatever))
+ ;
+ else
+ return clib_error_return (0, \"unknown input `%U'\",
+ format_unformat_error, input);
+ }
+ return 0;
+}
+
+VLIB_CLI_COMMAND (" cmd-name "_command, static) = {
+ .path = \"" path "\",
+ .short_help = \"" path "\",
+ .function = " cmd-name "_command_fn,
+};
+")
diff --git a/extras/emacs/config-skel.el b/extras/emacs/config-skel.el
new file mode 100644
index 00000000..dc2ec380
--- /dev/null
+++ b/extras/emacs/config-skel.el
@@ -0,0 +1,28 @@
+;;; config-skel.el - config function command skeleton
+
+(require 'skeleton)
+
+(define-skeleton skel-config
+"Insert a vlib config skeleton "
+nil
+'(setq cfg-name (skeleton-read "Config Class Name: "))
+
+"
+static clib_error_t *
+" cfg-name "_config (vlib_main_t * vm, unformat_input_t * input)
+{
+ u32 whatever;
+
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
+ if (unformat (input, \"whatever %d\", &whatever))
+ ;
+ else
+ return clib_error_return (0, \"unknown input `%U'\",
+ format_unformat_error, input);
+ }
+
+ return 0;
+}
+
+VLIB_CONFIG_FUNCTION (" cfg-name "_config, \"" cfg-name "\");
+")
diff --git a/extras/emacs/dual-loop-skel.el b/extras/emacs/dual-loop-skel.el
new file mode 100644
index 00000000..b23d65ac
--- /dev/null
+++ b/extras/emacs/dual-loop-skel.el
@@ -0,0 +1,302 @@
+;;; dual-loop-skel.el - Eliotic dual-loop node skeleton
+
+(require 'skeleton)
+
+(define-skeleton skel-dual-loop
+"Insert a skeleton dual-loop graph node"
+nil
+'(setq node-name (skeleton-read "Node Name: "))
+'(setq uc-node-name (upcase node-name))
+"
+#include <vlib/vlib.h>
+#include <vnet/vnet.h>
+#include <vnet/pg/pg.h>
+
+#include <vnet/ip/ip.h>
+#include <vnet/ethernet/ethernet.h>
+
+#include <vppinfra/hash.h>
+#include <vppinfra/error.h>
+#include <vppinfra/elog.h>
+
+typedef struct {
+ /* convenience */
+ vlib_main_t * vlib_main;
+ vnet_main_t * vnet_main;
+ ethernet_main_t * ethernet_main;
+} " node-name "_main_t;
+
+" node-name "_main_t " node-name "_main;
+
+vlib_node_registration_t " node-name "_node;
+
+typedef struct {
+ u32 next_index;
+ u32 sw_if_index;
+} " node-name "_trace_t;
+
+/* packet trace format function */
+static u8 * format_" node-name "_trace (u8 * s, va_list * args)
+{
+ CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
+ CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
+ " node-name "_trace_t * t = va_arg (*args, " node-name "_trace_t *);
+
+ s = format (s, \"" uc-node-name ": sw_if_index %d, next index %d\",
+ t->sw_if_index, t->next_index);
+ return s;
+}
+
+vlib_node_registration_t " node-name "_node;
+
+#define foreach_" node-name "_error \\
+_(SWAPPED, \"Mac swap packets processed\")
+
+typedef enum {
+#define _(sym,str) " uc-node-name "_ERROR_##sym,
+ foreach_" node-name "_error
+#undef _
+ " uc-node-name "_N_ERROR,
+} " node-name "_error_t;
+
+static char * " node-name "_error_strings[] = {
+#define _(sym,string) string,
+ foreach_" node-name "_error
+#undef _
+};
+
+typedef enum {
+ " uc-node-name "_NEXT_INTERFACE_OUTPUT,
+ " uc-node-name "_N_NEXT,
+} " node-name "_next_t;
+
+#define foreach_mac_address_offset \\
+_(0) \\
+_(1) \\
+_(2) \\
+_(3) \\
+_(4) \\
+_(5)
+
+static uword
+" node-name "_node_fn (vlib_main_t * vm,
+ vlib_node_runtime_t * node,
+ vlib_frame_t * frame)
+{
+ u32 n_left_from, * from, * to_next;
+ " node-name "_next_t next_index;
+ u32 pkts_swapped = 0;
+
+ from = vlib_frame_vector_args (frame);
+ n_left_from = frame->n_vectors;
+ next_index = node->cached_next_index;
+
+ while (n_left_from > 0)
+ {
+ u32 n_left_to_next;
+
+ vlib_get_next_frame (vm, node, next_index,
+ to_next, n_left_to_next);
+
+ while (n_left_from >= 4 && n_left_to_next >= 2)
+ {
+ u32 next0 = " uc-node-name "_NEXT_INTERFACE_OUTPUT;
+ u32 next1 = " uc-node-name "_NEXT_INTERFACE_OUTPUT;
+ u32 sw_if_index0, sw_if_index1;
+ u8 tmp0[6], tmp1[6];
+ ethernet_header_t *en0, *en1;
+ u32 bi0, bi1;
+ vlib_buffer_t * b0, * b1;
+
+ /* Prefetch next iteration. */
+ {
+ vlib_buffer_t * p2, * p3;
+
+ p2 = vlib_get_buffer (vm, from[2]);
+ p3 = vlib_get_buffer (vm, from[3]);
+
+ vlib_prefetch_buffer_header (p2, LOAD);
+ vlib_prefetch_buffer_header (p3, LOAD);
+
+ CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, STORE);
+ CLIB_PREFETCH (p3->data, CLIB_CACHE_LINE_BYTES, STORE);
+ }
+
+ /* speculatively enqueue b0 and b1 to the current next frame */
+ to_next[0] = bi0 = from[0];
+ to_next[1] = bi1 = from[1];
+ from += 2;
+ to_next += 2;
+ n_left_from -= 2;
+ n_left_to_next -= 2;
+
+ b0 = vlib_get_buffer (vm, bi0);
+ b1 = vlib_get_buffer (vm, bi1);
+
+ /* $$$$$ Dual loop: process 2 x packets here $$$$$ */
+ ASSERT (b0->current_data == 0);
+ ASSERT (b1->current_data == 0);
+
+ en0 = vlib_buffer_get_current (b0);
+ en1 = vlib_buffer_get_current (b1);
+
+ /* This is not the fastest way to swap src + dst mac addresses */
+#define _(a) tmp0[a] = en0->src_address[a];
+ foreach_mac_address_offset;
+#undef _
+#define _(a) en0->src_address[a] = en0->dst_address[a];
+ foreach_mac_address_offset;
+#undef _
+#define _(a) en0->dst_address[a] = tmp0[a];
+ foreach_mac_address_offset;
+#undef _
+
+#define _(a) tmp1[a] = en1->src_address[a];
+ foreach_mac_address_offset;
+#undef _
+#define _(a) en1->src_address[a] = en1->dst_address[a];
+ foreach_mac_address_offset;
+#undef _
+#define _(a) en1->dst_address[a] = tmp1[a];
+ foreach_mac_address_offset;
+#undef _
+
+ sw_if_index0 = vnet_buffer(b0)->sw_if_index[VLIB_RX];
+ sw_if_index1 = vnet_buffer(b1)->sw_if_index[VLIB_RX];
+
+ /* Send pkt back out the RX interface */
+ vnet_buffer(b0)->sw_if_index[VLIB_TX] = sw_if_index0;
+ vnet_buffer(b1)->sw_if_index[VLIB_TX] = sw_if_index1;
+
+ pkts_swapped += 2;
+ /* $$$$$ End of processing 2 x packets $$$$$ */
+
+ if (PREDICT_FALSE((node->flags & VLIB_NODE_FLAG_TRACE)))
+ {
+ if (b0->flags & VLIB_BUFFER_IS_TRACED)
+ {
+ " node-name "_trace_t *t =
+ vlib_add_trace (vm, node, b0, sizeof (*t));
+ t->sw_if_index = sw_if_index0;
+ t->next_index = next0;
+ }
+ if (b1->flags & VLIB_BUFFER_IS_TRACED)
+ {
+ " node-name "_trace_t *t =
+ vlib_add_trace (vm, node, b1, sizeof (*t));
+ t->sw_if_index = sw_if_index1;
+ t->next_index = next1;
+ }
+ }
+
+ /* verify speculative enqueues, maybe switch current next frame */
+ vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
+ to_next, n_left_to_next,
+ bi0, bi1, next0, next1);
+ }
+
+ while (n_left_from > 0 && n_left_to_next > 0)
+ {
+ u32 bi0;
+ vlib_buffer_t * b0;
+ u32 next0 = " uc-node-name "_NEXT_INTERFACE_OUTPUT;
+ u32 sw_if_index0;
+ u8 tmp0[6];
+ ethernet_header_t *en0;
+
+ /* speculatively enqueue b0 to the current next frame */
+ bi0 = from[0];
+ to_next[0] = bi0;
+ from += 1;
+ to_next += 1;
+ n_left_from -= 1;
+ n_left_to_next -= 1;
+
+ b0 = vlib_get_buffer (vm, bi0);
+
+ /* $$$$$ Single loop: process 1 packet here $$$$$ */
+
+ /*
+ * Direct from the driver, we should be at offset 0
+ * aka at &b0->data[0]
+ */
+ ASSERT (b0->current_data == 0);
+
+ en0 = vlib_buffer_get_current (b0);
+
+ /* This is not the fastest way to swap src + dst mac addresses */
+#define _(a) tmp0[a] = en0->src_address[a];
+ foreach_mac_address_offset;
+#undef _
+#define _(a) en0->src_address[a] = en0->dst_address[a];
+ foreach_mac_address_offset;
+#undef _
+#define _(a) en0->dst_address[a] = tmp0[a];
+ foreach_mac_address_offset;
+#undef _
+
+ sw_if_index0 = vnet_buffer(b0)->sw_if_index[VLIB_RX];
+
+ /* Send pkt back out the RX interface */
+ vnet_buffer(b0)->sw_if_index[VLIB_TX] = sw_if_index0;
+
+ if (PREDICT_FALSE((node->flags & VLIB_NODE_FLAG_TRACE)
+ && (b0->flags & VLIB_BUFFER_IS_TRACED)))
+ {
+ " node-name "_trace_t *t =
+ vlib_add_trace (vm, node, b0, sizeof (*t));
+ t->sw_if_index = sw_if_index0;
+ t->next_index = next0;
+ }
+
+ pkts_swapped += 1;
+
+ /* $$$$$ Done processing 1 packet here $$$$$ */
+
+ /* verify speculative enqueue, maybe switch current next frame */
+ vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
+ to_next, n_left_to_next,
+ bi0, next0);
+ }
+
+ vlib_put_next_frame (vm, node, next_index, n_left_to_next);
+ }
+
+ vlib_node_increment_counter (vm, " node-name "_node.index,
+ " uc-node-name "_ERROR_SWAPPED, pkts_swapped);
+ return frame->n_vectors;
+}
+
+VLIB_REGISTER_NODE (" node-name "_node) = {
+ .function = " node-name "_node_fn,
+ .name = \"" node-name "\",
+ .vector_size = sizeof (u32),
+ .format_trace = format_" node-name "_trace,
+ .type = VLIB_NODE_TYPE_INTERNAL,
+
+ .n_errors = ARRAY_LEN(" node-name "_error_strings),
+ .error_strings = " node-name "_error_strings,
+
+ .n_next_nodes = " uc-node-name "_N_NEXT,
+
+ /* edit / add dispositions here */
+ .next_nodes = {
+ [" uc-node-name "_NEXT_INTERFACE_OUTPUT] = \"interface-output\",
+ },
+};
+
+clib_error_t *" node-name "_init (vlib_main_t *vm)
+{
+ " node-name "_main_t *msm = &" node-name "_main;
+
+ /* $$$$$ Initialize " node-name "_main_t structure here. $$$$$ */
+ msm->vlib_main = vm;
+ msm->vnet_main = vnet_get_main();
+ msm->ethernet_main = ethernet_get_main(vm);
+
+ return 0;
+}
+
+VLIB_INIT_FUNCTION(" node-name "_init);
+")
+
diff --git a/extras/emacs/elog-4-int-skel.el b/extras/emacs/elog-4-int-skel.el
new file mode 100644
index 00000000..fda412a7
--- /dev/null
+++ b/extras/emacs/elog-4-int-skel.el
@@ -0,0 +1,31 @@
+;;; elog-4-int-skel.el - 4 integer elog skeleton
+
+(require 'skeleton)
+
+(define-skeleton skel-elog-4-int
+"Insert a skeleton 4-integer event definition"
+nil
+'(setq function-name (skeleton-read "Function: "))
+'(setq label (skeleton-read "Label: "))
+
+"
+
+/* $$$ May or may not be needed */
+#include <vlib/vlib.h>
+#include <vppinfra/elog.h>
+
+static inline void " function-name " (u32 *data)
+{
+ ELOG_TYPE_DECLARE(e) =
+ {
+ .format = \"" label ": first %d second %d third %d fourth %d\",
+ .format_args = \"i4i4i4i4\",
+ };
+ struct { u32 data[4];} * ed;
+ ed = ELOG_DATA (&vlib_global_main.elog_main, e);
+ ed->data[0] = data[0];
+ ed->data[1] = data[1];
+ ed->data[2] = data[2];
+ ed->data[3] = data[3];
+}
+")
diff --git a/extras/emacs/elog-4-int-track-skel.el b/extras/emacs/elog-4-int-track-skel.el
new file mode 100644
index 00000000..506cc3a2
--- /dev/null
+++ b/extras/emacs/elog-4-int-track-skel.el
@@ -0,0 +1,34 @@
+;;; elog-4-int-skel.el - 4 integer elog skeleton
+
+(require 'skeleton)
+
+(define-skeleton skel-elog-4-int-track
+"Insert a skeleton 4-integer-with-track event definition"
+nil
+'(setq function-name (skeleton-read "Function: "))
+'(setq track-label (skeleton-read "Track Label: "))
+'(setq label (skeleton-read "Label: "))
+
+"
+
+/* $$$ May or may not be needed */
+#include <vlib/vlib.h>
+#include <vppinfra/elog.h>
+
+static inline void " function-name " (u32 *data)
+{
+ ELOG_TYPE_DECLARE(e) =
+ {
+ .format = \"" label ": first %d second %d third %d fourth %d\",
+ .format_args = \"i4i4i4i4\",
+ };
+ struct { u32 data[4];} * ed;
+ ELOG_TRACK(" track-label ");
+ ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, e, " track-label ");
+ ed->data[0] = data[0];
+ ed->data[1] = data[1];
+ ed->data[2] = data[2];
+ ed->data[3] = data[3];
+}
+
+")
diff --git a/extras/emacs/elog-enum-skel.el b/extras/emacs/elog-enum-skel.el
new file mode 100644
index 00000000..836ce86a
--- /dev/null
+++ b/extras/emacs/elog-enum-skel.el
@@ -0,0 +1,35 @@
+;;; elog-enum-skel.el - enum elog skeleton
+
+(require 'skeleton)
+
+(define-skeleton skel-elog-enum
+"Insert a skeleton enum event definition"
+nil
+'(setq function-name (skeleton-read "Function: "))
+'(setq label (skeleton-read "Label: "))
+
+"
+
+/* $$$ May or may not be needed */
+#include <vlib/vlib.h>
+#include <vppinfra/elog.h>
+
+static inline void " function-name " (u8 which)
+{
+ ELOG_TYPE_DECLARE (e) =
+ {
+ .format = \"" label ": %s\",
+ .format_args = \"t1\",
+ .n_enum_strings = 2,
+ .enum_strings =
+ {
+ \"string 1\",
+ \"string 2\",
+ },
+ };
+ struct { u8 which;} * ed;
+ ed = ELOG_DATA (&vlib_global_main.elog_main, e);
+ ed->which = which;
+}
+
+")
diff --git a/extras/emacs/elog-one-datum-skel.el b/extras/emacs/elog-one-datum-skel.el
new file mode 100644
index 00000000..11f83896
--- /dev/null
+++ b/extras/emacs/elog-one-datum-skel.el
@@ -0,0 +1,28 @@
+;;; elog-one-datum-skel.el - single u32 datum elog skeleton
+
+(require 'skeleton)
+
+(define-skeleton skel-elog-one-datum
+"Insert a skeleton single datum event definition"
+nil
+'(setq function-name (skeleton-read "Function: "))
+'(setq label (skeleton-read "Label: "))
+
+"
+
+/* $$$ May or may not be needed */
+#include <vlib/vlib.h>
+#include <vppinfra/elog.h>
+
+static inline void " function-name " (u32 data)
+{
+ ELOG_TYPE_DECLARE (e) =
+ {
+ .format = \"" label ": %d\",
+ .format_args = \"i4\",
+ };
+
+ elog (&vlib_global_main.elog_main, &e, data);
+}
+
+")
diff --git a/extras/emacs/fix-coding-style.el b/extras/emacs/fix-coding-style.el
new file mode 100755
index 00000000..0bb63483
--- /dev/null
+++ b/extras/emacs/fix-coding-style.el
@@ -0,0 +1,162 @@
+#!/usr/bin/emacs --script
+
+;; Insert style boilerplate if it's not already there
+;;
+;; Breaking the string in half keeps emacs
+;; from trying to interpret the local variable
+;; settings e.g. when it reads the lisp source code
+
+(defun insert-style-boilerplate () (interactive)
+ (save-excursion
+ (goto-char (point-min))
+ (if (eq nil (search-forward "coding-style-patch-verification"
+ (point-max) t))
+ (let ((junk 0)) (goto-char (point-max))
+ (insert "
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Var" "iables:
+ * eval: (c-set-style \"gnu\")
+ * End:
+ */")))))
+
+;; (cons xxx <list>) means insert xxx at the head of <list>
+;; Build a sorted list of *INDENT-OFF* lines, by searching
+;; backwards. The initial (setq indent-offset-list nil)
+;; results in (cdr <last-cell>) nil, which makes it a proper list
+
+(defun find-indent-offs () (interactive)
+ (save-excursion
+ (if (boundp 'indent-offset-list)
+ (makunbound 'indent-offset-list))
+ (setq indent-offset-list nil)
+ (goto-char (point-max))
+ (while (search-backward "*INDENT-OFF*" (point-min) t)
+ (move-beginning-of-line nil)
+ (setq indent-offset-list (cons (point) indent-offset-list))
+ (previous-line))))
+
+;; Insert indent-off ... indent-on brackets around
+;; a certain xxx_foreach macro, etc. which "indent"
+;; completely screws up. Doesn't handle nesting, of which there
+;; are few examples (fortunately).
+
+(defun fix-initializer (what) (interactive)
+ (find-indent-offs)
+ (save-excursion
+ (goto-char (point-min))
+ (while (search-forward-regexp what (point-max) t)
+ (move-beginning-of-line nil)
+ (previous-line)
+ (let ((index 0)(pointval 0))
+ (while (and (< pointval (point))(elt indent-offset-list index))
+ (setq pointval (elt indent-offset-list index))
+ (setq index (1+ index)))
+ (if (not (eq pointval (point)))
+ (let ((junk 0))
+ (next-line)
+ (open-line 1)
+ (c-indent-line-or-region)
+ (insert "/* *INDENT-OFF* */")
+ (search-forward "{")
+ (backward-char)
+ (forward-sexp)
+ (move-end-of-line nil)
+ (newline 1)
+ (c-indent-line-or-region)
+ (insert "/* *INDENT-ON* */")
+ (find-indent-offs))
+ (search-forward "*INDENT-ON*"))))))
+
+(defun fix-pool-foreach () (interactive)
+ (fix-initializer "pool_foreach *("))
+
+(defun fix-pool-foreach-index () (interactive)
+ (fix-initializer "pool_foreach_index *("))
+
+(defun fix-hash-foreach () (interactive)
+ (fix-initializer "hash_foreach *("))
+
+(defun fix-hash-foreach-pair () (interactive)
+ (fix-initializer "hash_foreach_pair *("))
+
+(defun fix-hash-foreach-mem () (interactive)
+ (fix-initializer "hash_foreach_mem *("))
+
+(defun fix-clib-fifo-foreach () (interactive)
+ (fix-initializer "clib_fifo_foreach *("))
+
+(defun fix-clib-bitmap-foreach () (interactive)
+ (fix-initializer "clib_bitmap_foreach *("))
+
+(defun fix-foreach-ip-interface-address () (interactive)
+ (fix-initializer "foreach_ip_interface_address *("))
+
+(defun fix-vlib-register-thread () (interactive)
+ (fix-initializer "VLIB_REGISTER_THREAD *("))
+
+(defun fix-vlib-cli-command () (interactive)
+ (fix-initializer "VLIB_CLI_COMMAND *("))
+
+(defun fix-vlib-register-node () (interactive)
+ (fix-initializer "VLIB_REGISTER_NODE *("))
+
+(defun fix-reply-macro2 () (interactive)
+ (fix-initializer "REPLY_MACRO2 *("))
+
+(defun fix-vnet-device-class () (interactive)
+ (fix-initializer "VNET_DEVICE_CLASS *("))
+
+(defun fix-vnet-hw-interface-class () (interactive)
+ (fix-initializer "VNET_HW_INTERFACE_CLASS *("))
+
+(defun fix-clib-packed () (interactive)
+ (fix-initializer "CLIB_PACKED *("))
+(defun fix-vl-api-packed () (interactive)
+ (fix-initializer "VL_API_PACKED *("))
+
+;; Driver routine which runs the set of functions
+;; defined above, as well as the bottom boilerplate function
+
+(defun fd-io-styleify () (interactive)
+ (fix-pool-foreach)
+ (fix-pool-foreach-index)
+ (fix-hash-foreach)
+ (fix-hash-foreach-pair)
+ (fix-hash-foreach-mem)
+ (fix-foreach-ip-interface-address)
+ (fix-clib-fifo-foreach)
+ (fix-clib-bitmap-foreach)
+ (fix-vlib-register-thread)
+ (fix-vlib-cli-command)
+ (fix-vlib-register-node)
+ (fix-reply-macro2)
+ (fix-vnet-device-class)
+ (fix-vnet-hw-interface-class)
+ (fix-clib-packed)
+ (fix-vl-api-packed)
+ (insert-style-boilerplate)
+ (if (boundp 'indent-offset-list)
+ (makunbound 'indent-offset-list)))
+
+;; When run as a script, this sexp
+;; walks the list of files supplied on the command line.
+;;
+;; (elt argv index) returns nil if you M-x eval-buffer
+;; or M-x load-file the file, so we won't accidentally
+;; evaluate (save-buffers-kill-emacs)...
+
+(let ((file-index 0))
+ (if (elt argv file-index)
+ (while (elt argv file-index)
+ (find-file (elt argv file-index))
+ (fd-io-styleify)
+ (message "Done %s..." (elt argv file-index))
+ (setq file-index (1+ file-index))))
+ (if (> file-index 0)
+ (let ((junk 0))
+ (message "Save and quit...")
+ (save-buffers-kill-emacs t))))
+
+
diff --git a/extras/emacs/make-plugin.sh b/extras/emacs/make-plugin.sh
new file mode 100755
index 00000000..4985974c
--- /dev/null
+++ b/extras/emacs/make-plugin.sh
@@ -0,0 +1,4 @@
+#!/usr/bin/emacs --script
+(load-file "./all-skel.el")
+(make-plugin)
+(save-some-buffers t)
diff --git a/extras/emacs/periodic-skel.el b/extras/emacs/periodic-skel.el
new file mode 100644
index 00000000..a8f3ef6d
--- /dev/null
+++ b/extras/emacs/periodic-skel.el
@@ -0,0 +1,86 @@
+;;; pipe-skel.el - pipelined graph node skeleton
+
+(require 'skeleton)
+
+(define-skeleton skel-periodic
+"Insert a skeleton periodic process node"
+nil
+'(setq node-name (skeleton-read "Name: "))
+'(setq uc-node-name (upcase node-name))
+'(setq poll-period (skeleton-read "Poll period (f64 seconds, e.g. 10.0): "))
+
+"
+#define " uc-node-name "_POLL_PERIOD " poll-period "
+
+static uword
+" node-name "_process (vlib_main_t * vm,
+ vlib_node_runtime_t * rt,
+ vlib_frame_t * f)
+{
+ f64 poll_time_remaining;
+ uword event_type, * event_data = 0;
+
+ poll_time_remaining = " uc-node-name "_POLL_PERIOD;
+ while (1) {
+ int i;
+
+ /*
+ * Sleep until next periodic call due, or until we receive event(s)
+ */
+ poll_time_remaining =
+ vlib_process_wait_for_event_or_clock (vm, poll_time_remaining);
+
+ event_type = vlib_process_get_events (vm, &event_data);
+ switch (event_type) {
+ case ~0: /* no events => timeout */
+ break;
+
+ /*
+ * $$$$ FIXME: add cases / handlers for each event type
+ */
+ case EVENT1:
+ for (i = 0; i < vec_len (event_data); i++)
+ handle_event1 (mm, event_data[i]);
+ break;
+
+ case EVENT2:
+ for (i = 0; i < vec_len (event_data); i++)
+ handle_event2 (vm, event_data[i]);
+ break;
+
+ /* ... and so forth for each event type */
+
+ default:
+ /* This should never happen... */
+ clib_warning (\"BUG: unhandled event type %d\", event_type);
+ break;
+ }
+ if (event_data)
+ _vec_len (event_data) = 0;
+
+ /* Timer expired, call periodic function */
+ if (vlib_process_suspend_time_is_zero (poll_time_remaining)) {
+ " node-name "_periodic (vm);
+ poll_time_remaining = " uc-node-name "_POLL_PERIOD;
+ }
+ }
+
+ return 0;
+}
+
+/*
+ * " node-name " periodic node declaration
+ */
+static VLIB_REGISTER_NODE (" node-name "_node) = {
+ .function = " node-name "_process,
+ .type = VLIB_NODE_TYPE_PROCESS,
+ .name = \"" node-name "-process\",
+};
+
+/*
+ * To signal an event:
+ *
+ * vlib_process_signal_event (vm, " node-name "_node.index, EVENTn, datum);
+ *
+ */
+")
diff --git a/extras/emacs/pipe-skel.el b/extras/emacs/pipe-skel.el
new file mode 100644
index 00000000..911e0d07
--- /dev/null
+++ b/extras/emacs/pipe-skel.el
@@ -0,0 +1,132 @@
+;;; pipe-skel.el - pipelined graph node skeleton
+
+(require 'skeleton)
+
+(define-skeleton skel-pipeline-node
+"Insert a skeleton pipelined graph node"
+nil
+'(setq node-name (skeleton-read "Node Name: "))
+'(setq uc-node-name (upcase node-name))
+'(setq nstages (skeleton-read "Number of pipeline stages: "))
+"
+#include <vlib/vlib.h>
+#include <vppinfra/error.h>
+
+/*
+ * Dump these counters via the \"show error\" CLI command
+ * FIXME: Add packet counter / error strings as desired
+ */
+
+#define foreach_" node-name "_error \\
+_(ERROR1, \"sample counter/ error string\")
+
+static char * " node-name "_error_strings[] = {
+#define _(sym,string) string,
+ foreach_" node-name "_error
+#undef _
+};
+
+/*
+ * packet error / counter enumeration
+ *
+ * To count and drop a vlib_buffer_t *b:
+ *
+ * Set b->error = node->errors[" uc-node-name "_ERROR_xxx];
+ * last_stage returns a disposition index bound to \"error-drop\"
+ *
+ * To manually increment the specific counter " uc-node-name "_ERROR1
+ *
+ * vlib_node_t *n = vlib_get_node (vm, " node-name ".index);
+ * u32 node_counter_base_index = n->error_heap_index;
+ * vlib_error_main_t * em = &vm->error_main;
+ * em->counters[node_counter_base_index + " uc-node-name "_ERROR1] += 1;
+ *
+ */
+
+typedef enum {
+#define _(sym,str) " uc-node-name "_ERROR_##sym,
+ foreach_" node-name "_error
+#undef _
+ " uc-node-name "_N_ERROR,
+} " node-name "_error_t;
+
+/*
+ * enumeration of per-packet dispositions
+ * FIXME: add dispositions as desired
+ */
+
+typedef enum { \n"
+" " uc-node-name "_NEXT_NORMAL,\n"
+" " uc-node-name "_N_NEXT,
+} " node-name "_next_t;
+
+#define NSTAGES " nstages "
+
+/*
+ * Use the generic buffer metadata + first line of packet data prefetch
+ * stage function from <api/pipeline.h>. This is usually a Good Idea.
+ */
+#define stage0 generic_stage0
+
+/*
+ * FIXME: add stage functions. Here is the function prototype:
+ *
+ * static inline void stageN (vlib_main_t * vm,
+ * vlib_node_runtime_t * node,
+ * u32 buffer_index)
+ */
+
+/*
+ * FIXME: the last pipeline stage returns the desired pkt next node index,
+ * from the " node-name "_next_t enum above
+ */
+static inline u32 last_stage (vlib_main_t *vm, vlib_node_runtime_t *node,
+ u32 bi)
+{
+ vlib_buffer_t *b = vlib_get_buffer (vm, bi);
+
+ b->error = node->errors[EXAMPLE_ERROR_ERROR1];
+
+ return " uc-node-name "_NEXT_NORMAL;
+}
+
+#include <api/pipeline.h>
+
+static uword " node-name "_node_fn (vlib_main_t * vm,
+ vlib_node_runtime_t * node,
+ vlib_frame_t * frame)
+{
+ return dispatch_pipeline (vm, node, frame);
+}
+
+static VLIB_REGISTER_NODE (example_node) = {
+ .function = " node-name "_node_fn,
+ .name = \"" node-name "-node\",
+ .vector_size = sizeof (u32),
+ .type = VLIB_NODE_TYPE_INTERNAL,
+
+ .n_errors = ARRAY_LEN(" node-name "_error_strings),
+ .error_strings = " node-name "_error_strings,
+
+ .n_next_nodes = " uc-node-name "_N_NEXT,
+
+ /* edit / add dispositions here */
+ .next_nodes = {
+ [" uc-node-name "_NEXT_NORMAL] = \"error-drop\",
+ },
+};
+
+/*
+ * packet generator definition to push superframes of data into the
+ * new graph node. Cut and paste into <file>, then
+ * \"exec <file>\", \"pa enable test\" at the QVNET prompt...
+ *
+packet-generator new {
+ name test
+ limit 100
+ node " node-name "-node
+ size 374-374
+ data { hex 0x02b46b96000100096978676265000500bf436973636f20494f5320536f6674776172652c2043333735304520536f66747761726520284333373530452d554e4956455253414c2d4d292c2056657273696f6e2031322e32283335295345352c2052454c4541534520534f4654574152452028666331290a436f707972696768742028632920313938362d3230303720627920436973636f2053797374656d732c20496e632e0a436f6d70696c6564205468752031392d4a756c2d30372031363a3137206279206e616368656e00060018636973636f2057532d4333373530452d3234544400020011000000010101cc0004000000000003001b54656e4769676162697445746865726e6574312f302f3100040008000000280008002400000c011200000000ffffffff010221ff000000000000001e7a50f000ff000000090004000a00060001000b0005010012000500001300050000160011000000010101cc000400000000001a00100000000100000000ffffffff }
+}
+ */
+")
diff --git a/extras/emacs/plugin-all-apih-skel.el b/extras/emacs/plugin-all-apih-skel.el
new file mode 100644
index 00000000..0f073f9c
--- /dev/null
+++ b/extras/emacs/plugin-all-apih-skel.el
@@ -0,0 +1,43 @@
+;;; plugin-all-apih-skel.el - vpp engine plug-in "all-apih.c" skeleton
+;;;
+;;; 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.
+
+(require 'skeleton)
+
+(define-skeleton skel-plugin-all-apih
+"Insert a plug-in 'all_api_h.h' skeleton "
+nil
+'(if (not (boundp 'plugin-name))
+ (setq plugin-name (read-string "Plugin name: ")))
+'(setq PLUGIN-NAME (upcase plugin-name))
+"
+/*
+ * " plugin-name "_all_api_h.h - skeleton vpp engine plug-in api #include file
+ *
+ * Copyright (c) <current-year> <your-organization>
+ * 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 the generated file, see BUILT_SOURCES in Makefile.am */
+#include <" plugin-name "/" plugin-name ".api.h>
+")
diff --git a/extras/emacs/plugin-am-skel.el b/extras/emacs/plugin-am-skel.el
new file mode 100644
index 00000000..5a082b4c
--- /dev/null
+++ b/extras/emacs/plugin-am-skel.el
@@ -0,0 +1,60 @@
+;;; plugin-am-skel.el - vpp engine plug-in foo.am skeleton
+;;;
+;;; 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.
+
+(require 'skeleton)
+
+(define-skeleton skel-plugin-makefile-am-fragment
+"Insert a plug-in 'foo.am' skeleton "
+nil
+'(if (not (boundp 'plugin-name))
+ (setq plugin-name (read-string "Plugin name: ")))
+'(setq PLUGIN-NAME (upcase plugin-name))
+"
+# Copyright (c) <current-year> <your-organization>
+# 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.
+
+vppapitestplugins_LTLIBRARIES += " plugin-name "_test_plugin.la
+vppplugins_LTLIBRARIES += " plugin-name "_plugin.la
+
+" plugin-name "_plugin_la_SOURCES = \\
+ " plugin-name "/node.c \\
+ " plugin-name "/" plugin-name ".c \\
+ " plugin-name "/" plugin-name ".h \\
+ " plugin-name "/" plugin-name "_all_api_h.h \\
+ " plugin-name "/" plugin-name "_msg_enum.h
+
+API_FILES += " plugin-name "/" plugin-name ".api
+
+nobase_apiinclude_HEADERS += \\
+ " plugin-name "/" plugin-name "_all_api_h.h \\
+ " plugin-name "/" plugin-name "_msg_enum.h \\
+ " plugin-name "/" plugin-name ".api.h
+
+" plugin-name "_test_plugin_la_SOURCES = \\
+ " plugin-name "/" plugin-name "_test.c \\
+ " plugin-name "/" plugin-name ".api.h
+
+# vi:syntax=automake
+")
diff --git a/extras/emacs/plugin-api-skel.el b/extras/emacs/plugin-api-skel.el
new file mode 100644
index 00000000..74519e70
--- /dev/null
+++ b/extras/emacs/plugin-api-skel.el
@@ -0,0 +1,48 @@
+;;; plugin-api-skel.el - vpp engine plug-in "all-apih.c" skeleton
+;;;
+;;; 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.
+
+(require 'skeleton)
+
+(define-skeleton skel-plugin-api
+"Insert a plug-in '<name>.api' skeleton "
+nil
+'(if (not (boundp 'plugin-name))
+ (setq plugin-name (read-string "Plugin name: ")))
+'(setq PLUGIN-NAME (upcase plugin-name))
+"
+/* Define a simple enable-disable binary API to control the feature */
+
+define " plugin-name "_enable_disable {
+ /* Client identifier, set from api_main.my_client_index */
+ u32 client_index;
+
+ /* Arbitrary context, so client can match reply to request */
+ u32 context;
+
+ /* Enable / disable the feature */
+ u8 enable_disable;
+
+ /* Interface handle */
+ u32 sw_if_index;
+};
+
+define " plugin-name "_enable_disable_reply {
+ /* From the request */
+ u32 context;
+
+ /* Return value, zero means all OK */
+ i32 retval;
+};
+")
diff --git a/extras/emacs/plugin-h-skel.el b/extras/emacs/plugin-h-skel.el
new file mode 100644
index 00000000..8bf9b6fe
--- /dev/null
+++ b/extras/emacs/plugin-h-skel.el
@@ -0,0 +1,66 @@
+;;; plugin-h-skel.el - vpp engine plug-in "main.c" skeleton
+;;;
+;;; 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.
+
+(require 'skeleton)
+
+(define-skeleton skel-plugin-h
+"Insert a plug-in 'main.c' skeleton "
+nil
+'(if (not (boundp 'plugin-name))
+ (setq plugin-name (read-string "Plugin name: ")))
+'(setq PLUGIN-NAME (upcase plugin-name))
+"
+/*
+ * " plugin-name ".h - skeleton vpp engine plug-in header file
+ *
+ * Copyright (c) <current-year> <your-organization>
+ * 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_" plugin-name "_h__
+#define __included_" plugin-name "_h__
+
+#include <vnet/vnet.h>
+#include <vnet/ip/ip.h>
+#include <vnet/ethernet/ethernet.h>
+
+#include <vppinfra/hash.h>
+#include <vppinfra/error.h>
+
+typedef struct {
+ /* API message ID base */
+ u16 msg_id_base;
+
+ /* convenience */
+ vlib_main_t * vlib_main;
+ vnet_main_t * vnet_main;
+ ethernet_main_t * ethernet_main;
+} " plugin-name "_main_t;
+
+" plugin-name "_main_t " plugin-name "_main;
+
+vlib_node_registration_t " plugin-name "_node;
+
+#endif /* __included_" plugin-name "_h__ */
+")
diff --git a/extras/emacs/plugin-main-skel.el b/extras/emacs/plugin-main-skel.el
new file mode 100644
index 00000000..46615c31
--- /dev/null
+++ b/extras/emacs/plugin-main-skel.el
@@ -0,0 +1,280 @@
+;;; plugin-main-skel.el - vpp engine plug-in "main.c" skeleton
+;;;
+;;; 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.
+
+(require 'skeleton)
+
+(define-skeleton skel-plugin-main
+"Insert a plug-in 'main.c' skeleton "
+nil
+'(if (not (boundp 'plugin-name))
+ (setq plugin-name (read-string "Plugin name: ")))
+'(setq PLUGIN-NAME (upcase plugin-name))
+'(setq capital-oh-en "ON")
+"/*
+ * " plugin-name ".c - skeleton vpp engine plug-in
+ *
+ * Copyright (c) <current-year> <your-organization>
+ * 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 <vnet/plugin/plugin.h>
+#include <" plugin-name "/" plugin-name ".h>
+
+#include <vlibapi/api.h>
+#include <vlibmemory/api.h>
+#include <vlibsocket/api.h>
+#include <vpp/app/version.h>
+
+/* define message IDs */
+#include <" plugin-name "/" plugin-name "_msg_enum.h>
+
+/* define message structures */
+#define vl_typedefs
+#include <" plugin-name "/" plugin-name "_all_api_h.h>
+#undef vl_typedefs
+
+/* define generated endian-swappers */
+#define vl_endianfun
+#include <" plugin-name "/" plugin-name "_all_api_h.h>
+#undef vl_endianfun
+
+/* instantiate all the print functions we know about */
+#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
+#define vl_printfun
+#include <" plugin-name "/" plugin-name "_all_api_h.h>
+#undef vl_printfun
+
+/* Get the API version number */
+#define vl_api_version(n,v) static u32 api_version=(v);
+#include <" plugin-name "/" plugin-name "_all_api_h.h>
+#undef vl_api_version
+
+/*
+ * A handy macro to set up a message reply.
+ * Assumes that the following variables are available:
+ * mp - pointer to request message
+ * rmp - pointer to reply message type
+ * rv - return value
+ */
+
+#define REPLY_MACRO(t) \\
+do { \\
+ unix_shared_memory_queue_t * q = \\
+ vl_api_client_index_to_input_queue (mp->client_index); \\
+ if (!q) \\
+ return; \\
+ \\
+ rmp = vl_msg_api_alloc (sizeof (*rmp)); \\
+ rmp->_vl_msg_id = ntohs((t)+sm->msg_id_base); \\
+ rmp->context = mp->context; \\
+ rmp->retval = ntohl(rv); \\
+ \\
+ vl_msg_api_send_shmem (q, (u8 *)&rmp); \\
+} while(0);
+
+
+/* List of message types that this plugin understands */
+
+#define foreach_" plugin-name "_plugin_api_msg \\
+_(" PLUGIN-NAME "_ENABLE_DISABLE, " plugin-name "_enable_disable)
+
+/* Action function shared between message handler and debug CLI */
+
+int " plugin-name "_enable_disable (" plugin-name "_main_t * sm, u32 sw_if_index,
+ int enable_disable)
+{
+ vnet_sw_interface_t * sw;
+ int rv = 0;
+
+ /* Utterly wrong? */
+ if (pool_is_free_index (sm->vnet_main->interface_main.sw_interfaces,
+ sw_if_index))
+ return VNET_API_ERROR_INVALID_SW_IF_INDEX;
+
+ /* Not a physical port? */
+ sw = vnet_get_sw_interface (sm->vnet_main, sw_if_index);
+ if (sw->type != VNET_SW_INTERFACE_TYPE_HARDWARE)
+ return VNET_API_ERROR_INVALID_SW_IF_INDEX;
+
+ vnet_feature_enable_disable (\"device-input\", \"" plugin-name "\",
+ sw_if_index, enable_disable, 0, 0);
+
+ return rv;
+}
+
+static clib_error_t *
+" plugin-name "_enable_disable_command_fn (vlib_main_t * vm,
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd)
+{
+ " plugin-name "_main_t * sm = &" plugin-name "_main;
+ u32 sw_if_index = ~0;
+ int enable_disable = 1;
+
+ int rv;
+
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (input, \"disable\"))
+ enable_disable = 0;
+ else if (unformat (input, \"%U\", unformat_vnet_sw_interface,
+ sm->vnet_main, &sw_if_index))
+ ;
+ else
+ break;
+ }
+
+ if (sw_if_index == ~0)
+ return clib_error_return (0, \"Please specify an interface...\");
+
+ rv = " plugin-name "_enable_disable (sm, sw_if_index, enable_disable);
+
+ switch(rv)
+ {
+ case 0:
+ break;
+
+ case VNET_API_ERROR_INVALID_SW_IF_INDEX:
+ return clib_error_return
+ (0, \"Invalid interface, only works on physical ports\");
+ break;
+
+ case VNET_API_ERROR_UNIMPLEMENTED:
+ return clib_error_return (0, \"Device driver doesn't support redirection\");
+ break;
+
+ default:
+ return clib_error_return (0, \"" plugin-name "_enable_disable returned %d\",
+ rv);
+ }
+ return 0;
+}
+
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (" plugin-name "_enable_disable_command, static) =
+{
+ .path = \"" plugin-name " enable-disable\",
+ .short_help =
+ \"" plugin-name " enable-disable <interface-name> [disable]\",
+ .function = " plugin-name "_enable_disable_command_fn,
+};
+/* *INDENT-ON* */
+
+/* API message handler */
+static void vl_api_" plugin-name "_enable_disable_t_handler
+(vl_api_" plugin-name "_enable_disable_t * mp)
+{
+ vl_api_" plugin-name "_enable_disable_reply_t * rmp;
+ " plugin-name "_main_t * sm = &" plugin-name "_main;
+ int rv;
+
+ rv = " plugin-name "_enable_disable (sm, ntohl(mp->sw_if_index),
+ (int) (mp->enable_disable));
+
+ REPLY_MACRO(VL_API_" PLUGIN-NAME "_ENABLE_DISABLE_REPLY);
+}
+
+/* Set up the API message handling tables */
+static clib_error_t *
+" plugin-name "_plugin_api_hookup (vlib_main_t *vm)
+{
+ " plugin-name "_main_t * sm = &" plugin-name "_main;
+#define _(N,n) \\
+ vl_msg_api_set_handlers((VL_API_##N + sm->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_" plugin-name "_plugin_api_msg;
+#undef _
+
+ return 0;
+}
+
+#define vl_msg_name_crc_list
+#include <" plugin-name "/" plugin-name "_all_api_h.h>
+#undef vl_msg_name_crc_list
+
+static void
+setup_message_id_table (" plugin-name "_main_t * sm, api_main_t * am)
+{
+#define _(id,n,crc) \
+ vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base);
+ foreach_vl_msg_name_crc_" plugin-name" ;
+#undef _
+}
+
+static clib_error_t * " plugin-name "_init (vlib_main_t * vm)
+{
+ " plugin-name "_main_t * sm = &" plugin-name "_main;
+ clib_error_t * error = 0;
+ u8 * name;
+
+ name = format (0, \"" plugin-name "_%08x%c\", api_version, 0);
+
+ /* Ask for a correctly-sized block of API message decode slots */
+ sm->msg_id_base = vl_msg_api_get_msg_ids
+ ((char *) name, VL_MSG_FIRST_AVAILABLE);
+
+ error = " plugin-name "_plugin_api_hookup (vm);
+
+ /* Add our API messages to the global name_crc hash table */
+ setup_message_id_table (sm, &api_main);
+
+ vec_free(name);
+
+ return error;
+}
+
+VLIB_INIT_FUNCTION (" plugin-name "_init);
+
+/* *INDENT-OFF* */
+VNET_FEATURE_INIT (" plugin-name ", static) =
+{
+ .arc_name = \"device-input\",
+ .node_name = \"" plugin-name "\",
+ .runs_before = VNET_FEATURES (\"ethernet-input\"),
+};
+/* *INDENT-ON */
+
+/* *INDENT-OFF* */
+VLIB_PLUGIN_REGISTER () =
+{
+ .version = VPP_BUILD_VER,
+};
+/* *INDENT-ON* */
+
+/*
+ * fd.io coding-style-patch-verification: " capital-oh-en "
+ *
+ * Local Variables:
+ * eval: (c-set-style \"gnu\")
+ * End:
+ */
+")
+
diff --git a/extras/emacs/plugin-msg-enum-skel.el b/extras/emacs/plugin-msg-enum-skel.el
new file mode 100644
index 00000000..c44af051
--- /dev/null
+++ b/extras/emacs/plugin-msg-enum-skel.el
@@ -0,0 +1,55 @@
+;;; plugin-msg-enum-skel.el - vpp engine plug-in message enum skeleton
+;;;
+;;; 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.
+
+(require 'skeleton)
+
+(define-skeleton skel-plugin-msg-enum
+"Insert a plug-in message enumeration skeleton "
+nil
+'(if (not (boundp 'plugin-name))
+ (setq plugin-name (read-string "Plugin name: ")))
+'(setq PLUGIN-NAME (upcase plugin-name))
+"
+/*
+ * " plugin-name "_msg_enum.h - skeleton vpp engine plug-in message enumeration
+ *
+ * Copyright (c) <current-year> <your-organization>
+ * 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_" plugin-name "_msg_enum_h
+#define included_" plugin-name "_msg_enum_h
+
+#include <vppinfra/byte_order.h>
+
+#define vl_msg_id(n,h) n,
+typedef enum {
+#include <" plugin-name "/" plugin-name "_all_api_h.h>
+ /* We'll want to know how many messages IDs we need... */
+ VL_MSG_FIRST_AVAILABLE,
+} vl_msg_id_t;
+#undef vl_msg_id
+
+#endif /* included_" plugin-name "_msg_enum_h */
+")
diff --git a/extras/emacs/plugin-node-skel.el b/extras/emacs/plugin-node-skel.el
new file mode 100644
index 00000000..167519aa
--- /dev/null
+++ b/extras/emacs/plugin-node-skel.el
@@ -0,0 +1,330 @@
+;;; plugin-node-skel.el - vpp engine plug-in "node.c" skeleton
+;;;
+;;; 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.
+
+(require 'skeleton)
+
+(define-skeleton skel-plugin-node
+"Insert a plug-in 'node.c' skeleton "
+nil
+'(if (not (boundp 'plugin-name))
+ (setq plugin-name (read-string "Plugin name: ")))
+'(setq PLUGIN-NAME (upcase plugin-name))
+'(setq capital-oh-en "ON")
+"/*
+ * node.c - skeleton vpp engine plug-in dual-loop node skeleton
+ *
+ * Copyright (c) <current-year> <your-organization>
+ * 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 <vlib/vlib.h>
+#include <vnet/vnet.h>
+#include <vnet/pg/pg.h>
+#include <vppinfra/error.h>
+#include <" plugin-name "/" plugin-name ".h>
+
+typedef struct
+{
+ u32 next_index;
+ u32 sw_if_index;
+ u8 new_src_mac[6];
+ u8 new_dst_mac[6];
+} " plugin-name "_trace_t;
+
+static u8 *
+format_mac_address (u8 * s, va_list * args)
+{
+ u8 *a = va_arg (*args, u8 *);
+ return format (s, \"%02x:%02x:%02x:%02x:%02x:%02x\",
+ a[0], a[1], a[2], a[3], a[4], a[5]);
+}
+
+/* packet trace format function */
+static u8 * format_" plugin-name "_trace (u8 * s, va_list * args)
+{
+ CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
+ CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
+ " plugin-name "_trace_t * t = va_arg (*args, " plugin-name "_trace_t *);
+
+ s = format (s, \"" PLUGIN-NAME ": sw_if_index %d, next index %d\\n\",
+ t->sw_if_index, t->next_index);
+ s = format (s, \" new src %U -> new dst %U\",
+ format_mac_address, t->new_src_mac,
+ format_mac_address, t->new_dst_mac);
+ return s;
+}
+
+vlib_node_registration_t " plugin-name "_node;
+
+#define foreach_" plugin-name "_error \\
+_(SWAPPED, \"Mac swap packets processed\")
+
+typedef enum {
+#define _(sym,str) " PLUGIN-NAME "_ERROR_##sym,
+ foreach_" plugin-name "_error
+#undef _
+ " PLUGIN-NAME "_N_ERROR,
+} " plugin-name "_error_t;
+
+static char * " plugin-name "_error_strings[] = {
+#define _(sym,string) string,
+ foreach_" plugin-name "_error
+#undef _
+};
+
+typedef enum
+{
+ " PLUGIN-NAME "_NEXT_INTERFACE_OUTPUT,
+ " PLUGIN-NAME "_N_NEXT,
+} " plugin-name "_next_t;
+
+#define foreach_mac_address_offset \\
+_(0) \\
+_(1) \\
+_(2) \\
+_(3) \\
+_(4) \\
+_(5)
+
+static uword
+" plugin-name "_node_fn (vlib_main_t * vm,
+ vlib_node_runtime_t * node,
+ vlib_frame_t * frame)
+{
+ u32 n_left_from, * from, * to_next;
+ " plugin-name "_next_t next_index;
+ u32 pkts_swapped = 0;
+
+ from = vlib_frame_vector_args (frame);
+ n_left_from = frame->n_vectors;
+ next_index = node->cached_next_index;
+
+ while (n_left_from > 0)
+ {
+ u32 n_left_to_next;
+
+ vlib_get_next_frame (vm, node, next_index,
+ to_next, n_left_to_next);
+
+ while (n_left_from >= 4 && n_left_to_next >= 2)
+ {
+ u32 next0 = " PLUGIN-NAME "_NEXT_INTERFACE_OUTPUT;
+ u32 next1 = " PLUGIN-NAME "_NEXT_INTERFACE_OUTPUT;
+ u32 sw_if_index0, sw_if_index1;
+ u8 tmp0[6], tmp1[6];
+ ethernet_header_t *en0, *en1;
+ u32 bi0, bi1;
+ vlib_buffer_t * b0, * b1;
+
+ /* Prefetch next iteration. */
+ {
+ vlib_buffer_t * p2, * p3;
+
+ p2 = vlib_get_buffer (vm, from[2]);
+ p3 = vlib_get_buffer (vm, from[3]);
+
+ vlib_prefetch_buffer_header (p2, LOAD);
+ vlib_prefetch_buffer_header (p3, LOAD);
+
+ CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, STORE);
+ CLIB_PREFETCH (p3->data, CLIB_CACHE_LINE_BYTES, STORE);
+ }
+
+ /* speculatively enqueue b0 and b1 to the current next frame */
+ to_next[0] = bi0 = from[0];
+ to_next[1] = bi1 = from[1];
+ from += 2;
+ to_next += 2;
+ n_left_from -= 2;
+ n_left_to_next -= 2;
+
+ b0 = vlib_get_buffer (vm, bi0);
+ b1 = vlib_get_buffer (vm, bi1);
+
+ ASSERT (b0->current_data == 0);
+ ASSERT (b1->current_data == 0);
+
+ en0 = vlib_buffer_get_current (b0);
+ en1 = vlib_buffer_get_current (b1);
+
+ /* This is not the fastest way to swap src + dst mac addresses */
+#define _(a) tmp0[a] = en0->src_address[a];
+ foreach_mac_address_offset;
+#undef _
+#define _(a) en0->src_address[a] = en0->dst_address[a];
+ foreach_mac_address_offset;
+#undef _
+#define _(a) en0->dst_address[a] = tmp0[a];
+ foreach_mac_address_offset;
+#undef _
+
+#define _(a) tmp1[a] = en1->src_address[a];
+ foreach_mac_address_offset;
+#undef _
+#define _(a) en1->src_address[a] = en1->dst_address[a];
+ foreach_mac_address_offset;
+#undef _
+#define _(a) en1->dst_address[a] = tmp1[a];
+ foreach_mac_address_offset;
+#undef _
+
+ sw_if_index0 = vnet_buffer(b0)->sw_if_index[VLIB_RX];
+ sw_if_index1 = vnet_buffer(b1)->sw_if_index[VLIB_RX];
+
+ /* Send pkt back out the RX interface */
+ vnet_buffer(b0)->sw_if_index[VLIB_TX] = sw_if_index0;
+ vnet_buffer(b1)->sw_if_index[VLIB_TX] = sw_if_index1;
+
+ pkts_swapped += 2;
+
+ if (PREDICT_FALSE((node->flags & VLIB_NODE_FLAG_TRACE)))
+ {
+ if (b0->flags & VLIB_BUFFER_IS_TRACED)
+ {
+ " plugin-name "_trace_t *t =
+ vlib_add_trace (vm, node, b0, sizeof (*t));
+ t->sw_if_index = sw_if_index0;
+ t->next_index = next0;
+ clib_memcpy (t->new_src_mac, en0->src_address,
+ sizeof (t->new_src_mac));
+ clib_memcpy (t->new_dst_mac, en0->dst_address,
+ sizeof (t->new_dst_mac));
+ }
+ if (b1->flags & VLIB_BUFFER_IS_TRACED)
+ {
+ " plugin-name "_trace_t *t =
+ vlib_add_trace (vm, node, b1, sizeof (*t));
+ t->sw_if_index = sw_if_index1;
+ t->next_index = next1;
+ clib_memcpy (t->new_src_mac, en1->src_address,
+ sizeof (t->new_src_mac));
+ clib_memcpy (t->new_dst_mac, en1->dst_address,
+ sizeof (t->new_dst_mac));
+ }
+ }
+
+ /* verify speculative enqueues, maybe switch current next frame */
+ vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
+ to_next, n_left_to_next,
+ bi0, bi1, next0, next1);
+ }
+
+ while (n_left_from > 0 && n_left_to_next > 0)
+ {
+ u32 bi0;
+ vlib_buffer_t * b0;
+ u32 next0 = " PLUGIN-NAME "_NEXT_INTERFACE_OUTPUT;
+ u32 sw_if_index0;
+ u8 tmp0[6];
+ ethernet_header_t *en0;
+
+ /* speculatively enqueue b0 to the current next frame */
+ bi0 = from[0];
+ to_next[0] = bi0;
+ from += 1;
+ to_next += 1;
+ n_left_from -= 1;
+ n_left_to_next -= 1;
+
+ b0 = vlib_get_buffer (vm, bi0);
+ /*
+ * Direct from the driver, we should be at offset 0
+ * aka at &b0->data[0]
+ */
+ ASSERT (b0->current_data == 0);
+
+ en0 = vlib_buffer_get_current (b0);
+
+ /* This is not the fastest way to swap src + dst mac addresses */
+#define _(a) tmp0[a] = en0->src_address[a];
+ foreach_mac_address_offset;
+#undef _
+#define _(a) en0->src_address[a] = en0->dst_address[a];
+ foreach_mac_address_offset;
+#undef _
+#define _(a) en0->dst_address[a] = tmp0[a];
+ foreach_mac_address_offset;
+#undef _
+
+ sw_if_index0 = vnet_buffer(b0)->sw_if_index[VLIB_RX];
+
+ /* Send pkt back out the RX interface */
+ vnet_buffer(b0)->sw_if_index[VLIB_TX] = sw_if_index0;
+
+ if (PREDICT_FALSE((node->flags & VLIB_NODE_FLAG_TRACE)
+ && (b0->flags & VLIB_BUFFER_IS_TRACED))) {
+ " plugin-name "_trace_t *t =
+ vlib_add_trace (vm, node, b0, sizeof (*t));
+ t->sw_if_index = sw_if_index0;
+ t->next_index = next0;
+ clib_memcpy (t->new_src_mac, en0->src_address,
+ sizeof (t->new_src_mac));
+ clib_memcpy (t->new_dst_mac, en0->dst_address,
+ sizeof (t->new_dst_mac));
+ }
+
+ pkts_swapped += 1;
+
+ /* verify speculative enqueue, maybe switch current next frame */
+ vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
+ to_next, n_left_to_next,
+ bi0, next0);
+ }
+
+ vlib_put_next_frame (vm, node, next_index, n_left_to_next);
+ }
+
+ vlib_node_increment_counter (vm, " plugin-name "_node.index,
+ " PLUGIN-NAME "_ERROR_SWAPPED, pkts_swapped);
+ return frame->n_vectors;
+}
+
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (" plugin-name "_node) =
+{
+ .function = " plugin-name "_node_fn,
+ .name = \"" plugin-name "\",
+ .vector_size = sizeof (u32),
+ .format_trace = format_" plugin-name "_trace,
+ .type = VLIB_NODE_TYPE_INTERNAL,
+
+ .n_errors = ARRAY_LEN(" plugin-name "_error_strings),
+ .error_strings = " plugin-name "_error_strings,
+
+ .n_next_nodes = " PLUGIN-NAME "_N_NEXT,
+
+ /* edit / add dispositions here */
+ .next_nodes = {
+ [" PLUGIN-NAME "_NEXT_INTERFACE_OUTPUT] = \"interface-output\",
+ },
+};
+/* *INDENT-ON* */
+/*
+ * fd.io coding-style-patch-verification: " capital-oh-en "
+ *
+ * Local Variables:
+ * eval: (c-set-style \"gnu\")
+ * End:
+ */
+")
diff --git a/extras/emacs/plugin-test-skel.el b/extras/emacs/plugin-test-skel.el
new file mode 100644
index 00000000..837cbdaa
--- /dev/null
+++ b/extras/emacs/plugin-test-skel.el
@@ -0,0 +1,212 @@
+;;; plugin-test-skel.el - vpp-api-test plug-in skeleton
+;;;
+;;; 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.
+
+(require 'skeleton)
+
+(define-skeleton skel-plugin-test
+"Insert a plug-in vpp-api-test skeleton "
+nil
+'(if (not (boundp 'plugin-name))
+ (setq plugin-name (read-string "Plugin name: ")))
+'(setq PLUGIN-NAME (upcase plugin-name))
+'(setq capital-oh-en "ON")
+"/*
+ * " plugin-name ".c - skeleton vpp-api-test plug-in
+ *
+ * Copyright (c) <current-year> <your-organization>
+ * 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 <vat/vat.h>
+#include <vlibapi/api.h>
+#include <vlibmemory/api.h>
+#include <vlibsocket/api.h>
+#include <vppinfra/error.h>
+
+uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
+
+/* Declare message IDs */
+#include <" plugin-name "/" plugin-name "_msg_enum.h>
+
+/* define message structures */
+#define vl_typedefs
+#include <" plugin-name "/" plugin-name "_all_api_h.h>
+#undef vl_typedefs
+
+/* declare message handlers for each api */
+
+#define vl_endianfun /* define message structures */
+#include <" plugin-name "/" plugin-name "_all_api_h.h>
+#undef vl_endianfun
+
+/* instantiate all the print functions we know about */
+#define vl_print(handle, ...)
+#define vl_printfun
+#include <" plugin-name "/" plugin-name "_all_api_h.h>
+#undef vl_printfun
+
+/* Get the API version number. */
+#define vl_api_version(n,v) static u32 api_version=(v);
+#include <" plugin-name "/" plugin-name "_all_api_h.h>
+#undef vl_api_version
+
+
+typedef struct
+{
+ /* API message ID base */
+ u16 msg_id_base;
+ vat_main_t *vat_main;
+} " plugin-name "_test_main_t;
+
+" plugin-name "_test_main_t " plugin-name "_test_main;
+
+#define __plugin_msg_base " plugin-name"_test_main.msg_id_base
+#include <vlibapi/vat_helper_macros.h>
+
+#define foreach_standard_reply_retval_handler \\
+_(" plugin-name "_enable_disable_reply)
+
+#define _(n) \\
+ static void vl_api_##n##_t_handler \\
+ (vl_api_##n##_t * mp) \\
+ { \\
+ vat_main_t * vam = " plugin-name "_test_main.vat_main; \\
+ i32 retval = ntohl(mp->retval); \\
+ if (vam->async_mode) { \\
+ vam->async_errors += (retval < 0); \\
+ } else { \\
+ vam->retval = retval; \\
+ vam->result_ready = 1; \\
+ } \\
+ }
+foreach_standard_reply_retval_handler;
+#undef _
+
+/*
+ * Table of message reply handlers, must include boilerplate handlers
+ * we just generated
+ */
+#define foreach_vpe_api_reply_msg \\
+_(" PLUGIN-NAME "_ENABLE_DISABLE_REPLY, " plugin-name "_enable_disable_reply)
+
+
+static int api_" plugin-name "_enable_disable (vat_main_t * vam)
+{
+ unformat_input_t * i = vam->input;
+ int enable_disable = 1;
+ u32 sw_if_index = ~0;
+ vl_api_" plugin-name "_enable_disable_t * mp;
+ int ret;
+
+ /* Parse args required to build the message */
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (i, \"%U\", unformat_sw_if_index, vam, &sw_if_index))
+ ;
+ else if (unformat (i, \"sw_if_index %d\", &sw_if_index))
+ ;
+ else if (unformat (i, \"disable\"))
+ enable_disable = 0;
+ else
+ break;
+ }
+
+ if (sw_if_index == ~0)
+ {
+ errmsg (\"missing interface name / explicit sw_if_index number \\n\");
+ return -99;
+ }
+
+ /* Construct the API message */
+ M(" PLUGIN-NAME "_ENABLE_DISABLE, mp);
+ mp->sw_if_index = ntohl (sw_if_index);
+ mp->enable_disable = enable_disable;
+
+ /* send it... */
+ S(mp);
+
+ /* Wait for a reply... */
+ W (ret);
+ return ret;
+}
+
+/*
+ * List of messages that the api test plugin sends,
+ * and that the data plane plugin processes
+ */
+#define foreach_vpe_api_msg \\
+_(" plugin-name "_enable_disable, \"<intfc> [disable]\")
+
+static void " plugin-name "_api_hookup (vat_main_t *vam)
+{
+ " plugin-name "_test_main_t * sm = &" plugin-name "_test_main;
+ /* Hook up handlers for replies from the data plane plug-in */
+#define _(N,n) \\
+ vl_msg_api_set_handlers((VL_API_##N + sm->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_vpe_api_reply_msg;
+#undef _
+
+ /* API messages we can send */
+#define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
+ foreach_vpe_api_msg;
+#undef _
+
+ /* Help strings */
+#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
+ foreach_vpe_api_msg;
+#undef _
+}
+
+clib_error_t * vat_plugin_register (vat_main_t *vam)
+{
+ " plugin-name "_test_main_t * sm = &" plugin-name "_test_main;
+ u8 * name;
+
+ sm->vat_main = vam;
+
+ /* Ask the vpp engine for the first assigned message-id */
+ name = format (0, \"" plugin-name "_%08x%c\", api_version, 0);
+ sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
+
+ if (sm->msg_id_base != (u16) ~0)
+ " plugin-name "_api_hookup (vam);
+
+ vec_free(name);
+
+ return 0;
+}
+/*
+ * fd.io coding-style-patch-verification: " capital-oh-en "
+ *
+ * Local Variables:
+ * eval: (c-set-style \"gnu\")
+ * End:
+ */
+")
diff --git a/extras/emacs/plugin.el b/extras/emacs/plugin.el
new file mode 100644
index 00000000..4f1361a3
--- /dev/null
+++ b/extras/emacs/plugin.el
@@ -0,0 +1,32 @@
+(defun make-plugin ()
+ "Create a plugin"
+ (interactive)
+ (save-excursion
+ (let (cd-args cmd-args start-dir)
+ (setq start-dir default-directory)
+ (makunbound 'plugin-name)
+ (makunbound 'PLUGIN-NAME)
+ (setq plugin-name (read-string "Plugin name: "))
+ (setq PLUGIN-NAME (upcase plugin-name))
+ (find-file (concat plugin-name ".am"))
+ (skel-plugin-makefile-am-fragment)
+ (setq cmd-args (concat "mkdir -p " plugin-name))
+ (shell-command cmd-args)
+ (setq cd-args (concat start-dir "/" plugin-name))
+ (setq default-directory cd-args)
+ (find-file (concat plugin-name ".api"))
+ (skel-plugin-api)
+ (find-file (concat plugin-name "_all_api_h.h"))
+ (skel-plugin-all-apih)
+ (find-file (concat plugin-name ".h"))
+ (skel-plugin-h)
+ (find-file (concat plugin-name ".c"))
+ (skel-plugin-main)
+ (find-file (concat plugin-name "_msg_enum.h"))
+ (skel-plugin-msg-enum)
+ (find-file "node.c")
+ (skel-plugin-node)
+ (find-file (concat plugin-name "_test.c"))
+ (skel-plugin-test)
+ (cd start-dir))))
+
diff --git a/extras/emacs/tunnel-c-skel.el b/extras/emacs/tunnel-c-skel.el
new file mode 100644
index 00000000..a1b1757d
--- /dev/null
+++ b/extras/emacs/tunnel-c-skel.el
@@ -0,0 +1,452 @@
+;;; tunnel-c-skel.el - tunnel encap cli / api
+
+(require 'skeleton)
+
+(define-skeleton skel-tunnel-c
+"Insert a tunnel cli/api implementation"
+nil
+'(setq encap_stack (skeleton-read "encap_stack (e.g ip4_udp_lisp): "))
+'(setq ENCAP_STACK (upcase encap_stack))
+'(setq encap-stack (replace-regexp-in-string "_" "-" encap_stack))
+"
+#include <vnet/" encap-stack "/" encap_stack" .h>
+
+" encap_stack "_main_t " encap_stack "_main;
+
+static u8 * format_decap_next (u8 * s, va_list * args)
+{
+ u32 next_index = va_arg (*args, u32);
+
+ switch (next_index)
+ {
+ case " ENCAP_STACK "_INPUT_NEXT_DROP:
+ return format (s, \"drop\");
+ case " ENCAP_STACK "_INPUT_NEXT_IP4_INPUT:
+ return format (s, \"ip4\");
+ case " ENCAP_STACK "_INPUT_NEXT_IP6_INPUT:
+ return format (s, \"ip6\");
+ case " ENCAP_STACK "_INPUT_NEXT_" ENCAP_STACK "_ENCAP:
+ return format (s, \"" encap-stack "\");
+ default:
+ return format (s, \"unknown %d\", next_index);
+ }
+ return s;
+}
+
+u8 * format_" encap_stack "_tunnel (u8 * s, va_list * args)
+{
+ " encap_stack "_tunnel_t * t = va_arg (*args, " encap_stack "_tunnel_t *);
+ " encap_stack "_main_t * ngm = &" encap_stack "_main;
+
+ s = format (s,
+ \"[%d] %U (src) %U (dst) fibs: encap %d, decap %d\",
+ t - ngm->tunnels,
+ format_ip4_address, &t->src,
+ format_ip4_address, &t->dst,
+ t->encap_fib_index,
+ t->decap_fib_index);
+
+ s = format (s, \" decap next %U\\n\", format_decap_next, t->decap_next_index);
+ /* FIXME: add protocol details */
+ return s;
+}
+
+static u8 * format_" encap_stack "_name (u8 * s, va_list * args)
+{
+ u32 dev_instance = va_arg (*args, u32);
+ return format (s, \"" encap_stack "_tunnel%d\", dev_instance);
+}
+
+static uword dummy_interface_tx (vlib_main_t * vm,
+ vlib_node_runtime_t * node,
+ vlib_frame_t * frame)
+{
+ clib_warning (\"you shouldn't be here, leaking buffers...\");
+ return frame->n_vectors;
+}
+
+VNET_DEVICE_CLASS (" encap_stack "_device_class,static) = {
+ .name = "" ENCAP_STACK "",
+ .format_device_name = format_" encap_stack "_name,
+ .format_tx_trace = format_" encap_stack "_encap_trace,
+ .tx_function = dummy_interface_tx,
+};
+
+static uword dummy_set_rewrite (vnet_main_t * vnm,
+ u32 sw_if_index,
+ u32 l3_type,
+ void * dst_address,
+ void * rewrite,
+ uword max_rewrite_bytes)
+{
+ return 0;
+}
+
+u8 * format_" encap_stack "_header_with_length (u8 * s, va_list * args)
+{
+ " encap_stack "_header_t * h = va_arg (*args, " encap_stack "_header_t *);
+ u32 max_header_bytes = va_arg (*args, u32);
+ u32 header_bytes;
+
+ header_bytes = sizeof (h[0]);
+ if (max_header_bytes != 0 && header_bytes > max_header_bytes)
+ return format (s, \"" encap-stack "header truncated\");
+
+ /* FIXME: pretty-print an " encap_stack " header */
+
+ return s;
+}
+
+VNET_HW_INTERFACE_CLASS (" encap_stack "_hw_class) = {
+ .name = \"" ENCAP_STACK "\",
+ .format_header = format_" encap_stack "_header_with_length,
+ .set_rewrite = dummy_set_rewrite,
+};
+
+#define foreach_copy_field \
+_(src.as_u32) \
+_(dst.as_u32) \
+_(encap_fib_index) \
+_(decap_fib_index) \
+_(decap_next_index) \
+_(FIXME_ADD_ALL_COPY_FIELDS )
+
+static int " encap_stack "_rewrite (" encap_stack "_tunnel_t * t)
+{
+ u8 *rw = 0;
+ ip4_header_t * ip0;
+ " encap_stack "_header_t * h0;
+ int len;
+
+ len = sizeof (*h0);
+
+ vec_validate_aligned (rw, len-1, CLIB_CACHE_LINE_BYTES);
+
+ h0 = (ip4_udp_" encap_stack "_header_t *) rw;
+
+ /* FIXME: build the actual header here... */
+
+ /* Fixed portion of the (outer) ip4 header */
+ ip0 = &h0->ip4;
+ ip0->ip_version_and_header_length = 0x45;
+ ip0->ttl = 254;
+ ip0->protocol = IP_PROTOCOL_UDP;
+
+ /* we'll fix up the ip4 header length and checksum after-the-fact */
+ ip0->src_address.as_u32 = t->src.as_u32;
+ ip0->dst_address.as_u32 = t->dst.as_u32;
+ ip0->checksum = ip4_header_checksum (ip0);
+
+ /* UDP header, randomize src port on something, maybe? */
+ h0->udp.src_port = clib_host_to_net_u16 (4341);
+ h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_" encap_stack ");
+
+ /* $$$ build a <mumble> tunnel header here */
+
+ t->rewrite = rw;
+ return (0);
+}
+
+int vnet_" encap_stack "_add_del_tunnel
+(vnet_" encap_stack "_add_del_tunnel_args_t *a, u32 * hw_if_indexp)
+{
+ " encap_stack "_main_t * ngm = &" encap_stack "_main;
+ " encap_stack "_tunnel_t *t = 0;
+ vnet_main_t * vnm = ngm->vnet_main;
+ vnet_hw_interface_t * hi;
+ uword * p;
+ u32 hw_if_index = ~0;
+ int rv;
+ " encap_stack "_tunnel_key_t key, *key_copy;
+ hash_pair_t *hp;
+
+ key.FIXME = clib_host_to_net_XXX(FIXME);
+
+ p = hash_get_mem (ngm->" encap_stack "_tunnel_by_key, &key);
+
+ if (a->is_add)
+ {
+ /* adding a tunnel: tunnel must not already exist */
+ if (p)
+ return VNET_API_ERROR_INVALID_VALUE;
+
+ pool_get_aligned (ngm->tunnels, t, CLIB_CACHE_LINE_BYTES);
+ memset (t, 0, sizeof (*t));
+
+ /* copy from arg structure */
+#define _(x) t->x = a->x;
+ foreach_copy_field;
+#undef _
+
+ rv = " encap_stack "_rewrite (t);
+
+ if (rv)
+ {
+ pool_put (ngm->tunnels, t);
+ return rv;
+ }
+
+ /* $$$$ use a simple hash if you can ... */
+ key_copy = clib_mem_alloc (sizeof (*key_copy));
+ clib_memcpy (key_copy, &key, sizeof (*key_copy));
+
+ hash_set_mem (ngm->" encap_stack "_tunnel_by_key, key_copy,
+ t - ngm->tunnels);
+
+ /*
+ * interface freelist / recycle shtik
+ * This simple implementation rapidly reuses freed tunnel interfaces.
+ * Consider whether to refcount, etc. etc.
+ */
+ if (vec_len (ngm->free_" encap_stack "_tunnel_hw_if_indices) > 0)
+ {
+ hw_if_index = ngm->free_" encap_stack "_tunnel_hw_if_indices
+ [vec_len (ngm->free_" encap_stack "_tunnel_hw_if_indices)-1];
+ _vec_len (ngm->free_" encap_stack "_tunnel_hw_if_indices) -= 1;
+
+ hi = vnet_get_hw_interface (vnm, hw_if_index);
+ hi->dev_instance = t - ngm->tunnels;
+ hi->hw_instance = hi->dev_instance;
+ }
+ else
+ {
+ hw_if_index = vnet_register_interface
+ (vnm, " encap_stack "_device_class.index, t - ngm->tunnels,
+ " encap_stack "_hw_class.index, t - ngm->tunnels);
+ hi = vnet_get_hw_interface (vnm, hw_if_index);
+ hi->output_node_index = " encap_stack "_encap_node.index;
+ }
+
+ t->hw_if_index = hw_if_index;
+
+ vnet_sw_interface_set_flags (vnm, hi->sw_if_index,
+ VNET_SW_INTERFACE_FLAG_ADMIN_UP);
+ }
+ else
+ {
+ /* deleting a tunnel: tunnel must exist */
+ if (!p)
+ return VNET_API_ERROR_NO_SUCH_ENTRY;
+
+ t = pool_elt_at_index (ngm->tunnels, p[0]);
+
+ vnet_sw_interface_set_flags (vnm, t->hw_if_index, 0 /* down */);
+ vec_add1 (ngm->free_" encap_stack "_tunnel_hw_if_indices, t->hw_if_index);
+
+ hp = hash_get_pair (ngm->" encap_stack "_tunnel_by_key, &key);
+ key_copy = (void *)(hp->key);
+ hash_unset_mem (ngm->" encap_stack "_tunnel_by_key, &key);
+ clib_mem_free (key_copy);
+
+ vec_free (t->rewrite);
+ pool_put (ngm->tunnels, t);
+ }
+
+ if (hw_if_indexp)
+ *hw_if_indexp = hw_if_index;
+
+ return 0;
+}
+
+static u32 fib_index_from_fib_id (u32 fib_id)
+{
+ ip4_main_t * im = &ip4_main;
+ uword * p;
+
+ p = hash_get (im->fib_index_by_table_id, fib_id);
+ if (!p)
+ return ~0;
+
+ return p[0];
+}
+
+static uword unformat_decap_next (unformat_input_t * input, va_list * args)
+{
+ u32 * result = va_arg (*args, u32 *);
+ u32 tmp;
+
+ if (unformat (input, \"drop\"))
+ *result = " ENCAP_STACK "_INPUT_NEXT_DROP;
+ else if (unformat (input, \"ip4\"))
+ *result = " ENCAP_STACK "_INPUT_NEXT_IP4_INPUT;
+ else if (unformat (input, \"ip6\"))
+ *result = " ENCAP_STACK "_INPUT_NEXT_IP6_INPUT;
+ else if (unformat (input, \"ethernet\"))
+ *result = " ENCAP_STACK "_INPUT_NEXT_IP6_INPUT;
+ else if (unformat (input, \"" encap-stack "\"))
+ *result = " ENCAP_STACK "_INPUT_NEXT_" ENCAP_STACK "_ENCAP;
+ else if (unformat (input, \"%d\", &tmp))
+ *result = tmp;
+ else
+ return 0;
+ return 1;
+}
+
+static clib_error_t *
+" encap_stack "_add_del_tunnel_command_fn (vlib_main_t * vm,
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd)
+{
+ unformat_input_t _line_input, * line_input = &_line_input;
+ clib_error_t *error = 0;
+ ip4_address_t src, dst;
+ u8 is_add = 1;
+ u8 src_set = 0;
+ u8 dst_set = 0;
+ u32 encap_fib_index = 0;
+ u32 decap_fib_index = 0;
+ u8 next_protocol = " ENCAP_STACK "_NEXT_PROTOCOL_IP4;
+ u32 decap_next_index = " ENCAP_STACK "_INPUT_NEXT_IP4_INPUT;
+ u8 flags = " ENCAP_STACK "_FLAGS_P;
+ u8 ver_res = 0;
+ u8 res = 0;
+ u32 iid = 0;
+ u8 iid_set = 0;
+ u32 tmp;
+ int rv;
+ vnet_" encap_stack "_add_del_tunnel_args_t _a, * a = &_a;
+
+ /* Get a line of input. */
+ if (! unformat_user (input, unformat_line_input, line_input))
+ return 0;
+
+ while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
+ if (unformat (line_input, \"del\"))
+ is_add = 0;
+ else if (unformat (line_input, \"src %U\",
+ unformat_ip4_address, &src))
+ src_set = 1;
+ else if (unformat (line_input, \"dst %U\",
+ unformat_ip4_address, &dst))
+ dst_set = 1;
+ else if (unformat (line_input, \"encap-vrf-id %d\", &tmp))
+ {
+ encap_fib_index = fib_index_from_fib_id (tmp);
+ if (encap_fib_index == ~0)
+ {
+ unformat_free (line_input);
+ return clib_error_return (0, \"nonexistent encap fib id %d\", tmp);
+ }
+ }
+ else if (unformat (line_input, \"decap-vrf-id %d\", &tmp))
+ {
+ decap_fib_index = fib_index_from_fib_id (tmp);
+ if (decap_fib_index == ~0)
+ {
+ unformat_free (line_input);
+ return clib_error_return (0, \"nonexistent decap fib id %d\", tmp);
+ }
+ }
+ else if (unformat (line_input, \"decap-next %U\", unformat_decap_next,
+ &decap_next_index))
+ ;
+ else if (unformat(line_input, \"next-ip4\"))
+ next_protocol = 1;
+ else if (unformat(line_input, \"next-ip6\"))
+ next_protocol = 2;
+ else if (unformat(line_input, \"next-ethernet\"))
+ next_protocol = 3;
+ else if (unformat(line_input, \"next-nsh\"))
+ next_protocol = 4;
+ /*
+ * $$$ allow the user to specify anything they want
+ * in the " ENCAP_STACK " header
+ */
+ else
+ {
+ error = clib_error_return (0, \"parse error: '%U'\",
+ format_unformat_error, line_input);
+ unformat_free (line_input);
+ return error;
+ }
+ }
+
+ unformat_free (line_input);
+
+ if (src_set == 0)
+ return clib_error_return (0, \"tunnel src address not specified\");
+
+ if (dst_set == 0)
+ return clib_error_return (0, \"tunnel dst address not specified\");
+
+ memset (a, 0, sizeof (*a));
+
+ a->is_add = is_add;
+
+#define _(x) a->x = x;
+ foreach_copy_field;
+#undef _
+
+ rv = vnet_" encap_stack "_add_del_tunnel (a, 0 /* hw_if_indexp */);
+
+ switch(rv)
+ {
+ case 0:
+ break;
+ case VNET_API_ERROR_INVALID_VALUE:
+ return clib_error_return (0, \"tunnel already exists...\");
+
+ case VNET_API_ERROR_NO_SUCH_ENTRY:
+ return clib_error_return (0, \"tunnel does not exist...\");
+
+ default:
+ return clib_error_return
+ (0, \"vnet_" encap_stack "_add_del_tunnel returned %d\", rv);
+ }
+
+ return 0;
+}
+
+VLIB_CLI_COMMAND (create_" encap_stack "_tunnel_command, static) = {
+ .path = \"lisp gpe tunnel\",
+ .short_help =
+ \"<mumble> tunnel src <ip4-addr> dst <ip4-addr>\\n\"
+ \" [encap-fib-id <nn>] [decap-fib-id <nn>]\\n\"
+ \" [decap-next [ip4|ip6|ethernet|nsh-encap|<nn>]][del]\\n\",
+ .function = " encap_stack "_add_del_tunnel_command_fn,
+};
+
+static clib_error_t *
+show_" encap_stack "_tunnel_command_fn (vlib_main_t * vm,
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd)
+{
+ " encap_stack "_main_t * ngm = &" encap_stack "_main;
+ " encap_stack "_tunnel_t * t;
+
+ if (pool_elts (ngm->tunnels) == 0)
+ vlib_cli_output (vm, \"No lisp-gpe tunnels configured...\");
+
+ pool_foreach (t, ngm->tunnels,
+ ({
+ vlib_cli_output (vm, \"%U\", format_" encap_stack "_tunnel);
+ }));
+
+ return 0;
+}
+
+VLIB_CLI_COMMAND (show_" encap_stack "_tunnel_command, static) = {
+ .path = \"show lisp gpe tunnel\",
+ .function = show_" encap_stack "_tunnel_command_fn,
+};
+
+clib_error_t *" encap_stack "_init (vlib_main_t *vm)
+{
+ " encap_stack "_main_t *ngm = &" encap_stack "_main;
+
+ ngm->vnet_main = vnet_get_main();
+ ngm->vlib_main = vm;
+
+ ngm->" encap_stack "_tunnel_by_key
+ = hash_create_mem (0, sizeof(" encap_stack "_tunnel_key_t), sizeof (uword));
+
+ /* YMMV, register with the local netstack */
+ udp_register_dst_port (vm, UDP_DST_PORT_" encap_stack ",
+ " encap_stack "_input_node.index, 1 /* is_ip4 */);
+ return 0;
+}
+
+VLIB_INIT_FUNCTION(" encap_stack "_init);
+
+")
+
diff --git a/extras/emacs/tunnel-decap-skel.el b/extras/emacs/tunnel-decap-skel.el
new file mode 100644
index 00000000..380273b6
--- /dev/null
+++ b/extras/emacs/tunnel-decap-skel.el
@@ -0,0 +1,299 @@
+;;; tunnel-decap-skel.el - tunnel decapsulation skeleton
+
+(require 'skeleton)
+
+(define-skeleton skel-tunnel-decap
+"Insert a tunnel decap implementation"
+nil
+'(setq encap_stack (skeleton-read "encap_stack (e.g ip4_udp_lisp): "))
+'(setq ENCAP_STACK (upcase encap_stack))
+'(setq encap-stack (replace-regexp-in-string "_" "-" encap_stack))
+'(setq ENCAP-STACK (upcase encap-stack))
+"
+#include <vlib/vlib.h>
+#include <vnet/pg/pg.h>
+#include <vnet/" encap-stack "/" encap_stack ".h>
+
+typedef struct {
+ u32 next_index;
+ u32 tunnel_index;
+ u32 error;
+ " encap_stack "_header_t h;
+} " encap_stack "_rx_trace_t;
+
+static u8 * format_" encap_stack "_rx_trace (u8 * s, va_list * args)
+{
+ CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
+ CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
+ " encap_stack "_rx_trace_t * t = va_arg (*args, " encap_stack "_rx_trace_t *);
+
+ if (t->tunnel_index != ~0)
+ {
+ s = format (s, \"" ENCAP-STACK ": tunnel %d next %d error %d\",
+ t->tunnel_index, t->next_index, t->error);
+ }
+ else
+ {
+ s = format (s, \"" ENCAP-STACK ": no tunnel next %d error %d\\n\",
+ t->next_index, t->error);
+ }
+ s = format (s, \"\\n %U\", format_" encap_stack "_header_with_length, &t->h,
+ (u32) sizeof (t->h) /* max size */);
+ return s;
+}
+
+static uword
+" encap_stack "_input (vlib_main_t * vm,
+ vlib_node_runtime_t * node,
+ vlib_frame_t * from_frame)
+{
+ u32 n_left_from, next_index, * from, * to_next;
+ " encap_stack "_main_t * ngm = &" encap_stack "_main;
+ u32 last_tunnel_index = ~0;
+ " encap_stack "_tunnel_key_t last_key;
+ u32 pkts_decapsulated = 0;
+
+ memset (&last_key, 0xff, sizeof (last_key));
+
+ from = vlib_frame_vector_args (from_frame);
+ n_left_from = from_frame->n_vectors;
+
+ next_index = node->cached_next_index;
+
+ while (n_left_from > 0)
+ {
+ u32 n_left_to_next;
+
+ vlib_get_next_frame (vm, node, next_index,
+ to_next, n_left_to_next);
+
+#if 0 /* $$$ dual loop when the single loop works */
+ while (n_left_from >= 4 && n_left_to_next >= 2)
+ {
+ u32 bi0, bi1;
+ vlib_buffer_t * b0, * b1;
+ nsh_unicast_header_t * h0, * h1;
+ u32 label0, label1;
+ u32 next0, next1;
+ uword * p0, * p1;
+
+ /* Prefetch next iteration. */
+ {
+ vlib_buffer_t * p2, * p3;
+
+ p2 = vlib_get_buffer (vm, from[2]);
+ p3 = vlib_get_buffer (vm, from[3]);
+
+ vlib_prefetch_buffer_header (p2, LOAD);
+ vlib_prefetch_buffer_header (p3, LOAD);
+
+ CLIB_PREFETCH (p2->data, 2*CLIB_CACHE_LINE_BYTES, LOAD);
+ CLIB_PREFETCH (p3->data, 2*CLIB_CACHE_LINE_BYTES, LOAD);
+ }
+
+ bi0 = from[0];
+ bi1 = from[1];
+ to_next[0] = bi0;
+ to_next[1] = bi1;
+ from += 2;
+ to_next += 2;
+ n_left_to_next -= 2;
+ n_left_from -= 2;
+
+ b0 = vlib_get_buffer (vm, bi0);
+ b1 = vlib_get_buffer (vm, bi1);
+
+ h0 = vlib_buffer_get_current (b0);
+ h1 = vlib_buffer_get_current (b1);
+
+ next0 = next1 = " ENCAP_STACK "_INPUT_NEXT_IP4_INPUT;
+
+ label0 = clib_net_to_host_u32 (h0->label_exp_s_ttl);
+ label1 = clib_net_to_host_u32 (h1->label_exp_s_ttl);
+
+ /*
+ * Translate label contents into a fib index.
+ * This is a decent sanity check, and guarantees
+ * a sane FIB for the downstream lookup
+ */
+ label0 = vnet_nsh_uc_get_label (label0);
+ label1 = vnet_nsh_uc_get_label (label1);
+
+ /* If 2xlabels match, and match the 1-wide cache, use it */
+ if (label0 == label1 && rt->last_label == label0)
+ {
+ vnet_buffer(b0)->sw_if_index[VLIB_TX] = rt->last_fib_index;
+ vnet_buffer(b1)->sw_if_index[VLIB_TX] = rt->last_fib_index;
+ }
+ else
+ {
+ p0 = hash_get (rt->mm->fib_index_by_nsh_label, label0);
+ if (PREDICT_FALSE (p0 == 0))
+ {
+ next0 = " ENCAP_STACK "_INPUT_NEXT_DROP;
+ b0->error = node->errors[NSH_ERROR_BAD_LABEL];
+ }
+ else
+ vnet_buffer(b0)->sw_if_index[VLIB_TX] = p0[0];
+
+ p1 = hash_get (rt->mm->fib_index_by_nsh_label, label1);
+ if (PREDICT_FALSE (p1 == 0))
+ {
+ next1 = " ENCAP_STACK "_INPUT_NEXT_DROP;
+ b1->error = node->errors[NSH_ERROR_BAD_LABEL];
+ }
+ else
+ {
+ vnet_buffer(b1)->sw_if_index[VLIB_TX] = p1[0];
+ rt->last_fib_index = p1[0];
+ rt->last_label = label1;
+ }
+ }
+
+ if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ nsh_rx_trace_t *tr = vlib_add_trace (vm, node,
+ b0, sizeof (*tr));
+ tr->label_exp_s_ttl = label0;
+ }
+ if (PREDICT_FALSE(b1->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ nsh_rx_trace_t *tr = vlib_add_trace (vm, node,
+ b1, sizeof (*tr));
+ tr->label_exp_s_ttl = label1;
+ }
+
+ vlib_buffer_advance (b0, sizeof (*h0));
+ vlib_buffer_advance (b1, sizeof (*h1));
+
+ vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
+ to_next, n_left_to_next,
+ bi0, bi1, next0, next1);
+ }
+#endif
+
+ while (n_left_from > 0 && n_left_to_next > 0)
+ {
+ u32 bi0;
+ vlib_buffer_t * b0;
+ u32 next0;
+ " encap_stack "_header_t * iuX0;
+ uword * p0;
+ u32 tunnel_index0;
+ " encap_stack "_tunnel_t * t0;
+ " encap_stack "_tunnel_key_t key0;
+ u32 error0;
+
+ bi0 = from[0];
+ to_next[0] = bi0;
+ from += 1;
+ to_next += 1;
+ n_left_from -= 1;
+ n_left_to_next -= 1;
+
+ b0 = vlib_get_buffer (vm, bi0);
+
+ /*
+ * udp leaves current_data pointing at the tunnel header
+ * $$$$ FIXME
+ */
+ vlib_buffer_advance
+ (b0, -(word)(sizeof(udp_header_t)+sizeof(ip4_header_t)));
+
+ iuX0 = vlib_buffer_get_current (b0);
+
+ /* pop (ip, udp, lisp-gpe) */
+ vlib_buffer_advance (b0, sizeof (*iuX0));
+
+ tunnel_index0 = ~0;
+ error0 = 0;
+ next0 = " ENCAP_STACK "_INPUT_NEXT_DROP;
+
+ key0.src = iuX0->ip4.src_address.as_u32;
+ key0.iid = iuX0->lisp.iid;
+
+ /* $$$ validate key comparison */
+ if (PREDICT_FALSE ((key0.as_u64[0] != last_key.as_u64[0])))
+ {
+ p0 = hash_get_mem (ngm->" encap_stack "_tunnel_by_key, &key0);
+
+ if (p0 == 0)
+ {
+ error0 = " ENCAP_STACK "_ERROR_NO_SUCH_TUNNEL;
+ goto trace0;
+ }
+
+ last_key.as_u64[0] = key0.as_u64[0];
+ tunnel_index0 = last_tunnel_index = p0[0];
+ }
+ else
+ tunnel_index0 = last_tunnel_index;
+
+ t0 = pool_elt_at_index (ngm->tunnels, tunnel_index0);
+
+ next0 = t0->decap_next_index;
+
+ /* Required to make the l2 tag push / pop code work on l2 subifs */
+ vnet_update_l2_len (b0);
+
+ /*
+ * ip[46] lookup in the configured FIB
+ * " encap-stack ", here's the encap tunnel sw_if_index
+ */
+ vnet_buffer(b0)->sw_if_index[VLIB_TX] = t0->decap_fib_index;
+ pkts_decapsulated ++;
+
+ trace0:
+ b0->error = error0 ? node->errors[error0] : 0;
+
+ if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ " encap_stack "_rx_trace_t *tr
+ = vlib_add_trace (vm, node, b0, sizeof (*tr));
+ tr->next_index = next0;
+ tr->error = error0;
+ tr->tunnel_index = tunnel_index0;
+ tr->h = iuX0->lisp;
+ }
+ vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
+ to_next, n_left_to_next,
+ bi0, next0);
+ }
+
+ vlib_put_next_frame (vm, node, next_index, n_left_to_next);
+ }
+ vlib_node_increment_counter (vm, " encap_stack "_input_node.index,
+ " ENCAP_STACK "_ERROR_DECAPSULATED,
+ pkts_decapsulated);
+ return from_frame->n_vectors;
+}
+
+static char * " encap_stack "_error_strings[] = {
+#define " encap_stack "_error(n,s) s,
+#include <vnet/" encap-stack "/" encap_stack "_error.def>
+#undef " encap_stack "_error
+#undef _
+};
+
+VLIB_REGISTER_NODE (" encap_stack "_input_node) = {
+ .function = \"" encap_stack "_input\",
+ .name = \"" encap-stack "-input\",
+ /* Takes a vector of packets. */
+ .vector_size = sizeof (u32),
+
+ .n_errors = " ENCAP_STACK "_N_ERROR,
+ .error_strings = " encap_stack "_error_strings,
+
+ .n_next_nodes = " ENCAP_STACK "_INPUT_N_NEXT,
+ .next_nodes = {
+#define _(s,n) [" ENCAP_STACK "_INPUT_NEXT_##s] = n,
+ foreach_" encap_stack "_input_next
+#undef _
+ },
+
+ .format_buffer = format_" encap_stack "_header_with_length,
+ .format_trace = format_" encap_stack "_rx_trace,
+ // $$$$ .unformat_buffer = unformat_" encap_stack "_header,
+};
+
+")
diff --git a/extras/emacs/tunnel-encap-skel.el b/extras/emacs/tunnel-encap-skel.el
new file mode 100644
index 00000000..9c98a597
--- /dev/null
+++ b/extras/emacs/tunnel-encap-skel.el
@@ -0,0 +1,245 @@
+;;; tunnel-encap-skel.el - tunnel interface output skeleton
+
+(require 'skeleton)
+
+(define-skeleton skel-tunnel-encap
+"Insert a tunnel encap implementation"
+nil
+'(setq encap_stack (skeleton-read "encap_stack (e.g ip4_udp_lisp): "))
+'(setq ENCAP_STACK (upcase encap_stack))
+'(setq encap-stack (replace-regexp-in-string "_" "-" encap_stack))
+'(setq ENCAP-STACK (upcase encap-stack))
+"
+#include <vppinfra/error.h>
+#include <vppinfra/hash.h>
+#include <vnet/vnet.h>
+#include <vnet/ip/ip.h>
+#include <vnet/ethernet/ethernet.h>
+#include <vnet/" encap-stack "/" encap_stack ".h>
+
+/* Statistics (not really errors) */
+#define foreach_" encap_stack "_encap_error \\
+_(ENCAPSULATED, \"good packets encapsulated\")
+
+static char * " encap_stack "_encap_error_strings[] = {
+#define _(sym,string) string,
+ foreach_" encap_stack "_encap_error
+#undef _
+};
+
+typedef enum {
+#define _(sym,str) " ENCAP_STACK "_ENCAP_ERROR_##sym,
+ foreach_" encap_stack "_encap_error
+#undef _
+ " ENCAP_STACK "_ENCAP_N_ERROR,
+} " encap_stack "_encap_error_t;
+
+typedef enum {
+ " ENCAP_STACK "_ENCAP_NEXT_IP4_LOOKUP,
+ " ENCAP_STACK "_ENCAP_NEXT_DROP,
+ " ENCAP_STACK "_ENCAP_N_NEXT,
+} " encap_stack "_encap_next_t;
+
+typedef struct {
+ u32 tunnel_index;
+} " encap_stack "_encap_trace_t;
+
+u8 * format_" encap_stack "_encap_trace (u8 * s, va_list * args)
+{
+ CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
+ CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
+ " encap_stack "_encap_trace_t * t
+ = va_arg (*args, " encap_stack "_encap_trace_t *);
+
+ s = format (s, \"" ENCAP-STACK ": tunnel %d\", t->tunnel_index);
+ return s;
+}
+
+/* $$$$ FIXME adjust to match the rewrite string */
+#define foreach_fixed_header_offset \\
+_(0) _(1) _(2) _(3) _(FIXME)
+
+static uword
+" encap_stack "_encap (vlib_main_t * vm,
+ vlib_node_runtime_t * node,
+ vlib_frame_t * from_frame)
+{
+ u32 n_left_from, next_index, * from, * to_next;
+ " encap_stack "_main_t * ngm = &" encap_stack "_main;
+ vnet_main_t * vnm = ngm->vnet_main;
+ u32 pkts_encapsulated = 0;
+ u16 old_l0 = 0, old_l1 = 0;
+
+ from = vlib_frame_vector_args (from_frame);
+ n_left_from = from_frame->n_vectors;
+
+ next_index = node->cached_next_index;
+
+ while (n_left_from > 0)
+ {
+ u32 n_left_to_next;
+
+ vlib_get_next_frame (vm, node, next_index,
+ to_next, n_left_to_next);
+
+#if 0 /* $$$ dual loop when the single loop works */
+ while (n_left_from >= 4 && n_left_to_next >= 2)
+ {
+ u32 bi0, bi1;
+ vlib_buffer_t * b0, * b1;
+ nsh_unicast_header_t * h0, * h1;
+ u32 label0, label1;
+ u32 next0, next1;
+ uword * p0, * p1;
+
+ /* Prefetch next iteration. */
+ {
+ vlib_buffer_t * p2, * p3;
+
+ p2 = vlib_get_buffer (vm, from[2]);
+ p3 = vlib_get_buffer (vm, from[3]);
+
+ vlib_prefetch_buffer_header (p2, LOAD);
+ vlib_prefetch_buffer_header (p3, LOAD);
+
+ CLIB_PREFETCH (p2->data, 2*CLIB_CACHE_LINE_BYTES, LOAD);
+ CLIB_PREFETCH (p3->data, 2*CLIB_CACHE_LINE_BYTES, LOAD);
+ }
+
+ bi0 = from[0];
+ bi1 = from[1];
+ to_next[0] = bi0;
+ to_next[1] = bi1;
+ from += 2;
+ to_next += 2;
+ n_left_to_next -= 2;
+ n_left_from -= 2;
+
+ b0 = vlib_get_buffer (vm, bi0);
+ b1 = vlib_get_buffer (vm, bi1);
+
+ h0 = vlib_buffer_get_current (b0);
+ h1 = vlib_buffer_get_current (b1);
+
+ next0 = next1 = " ENCAP_STACK "_ENCAP_NEXT_IP4_LOOKUP;
+
+ vlib_buffer_advance (b0, sizeof (*h0));
+ vlib_buffer_advance (b1, sizeof (*h1));
+
+ vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
+ to_next, n_left_to_next,
+ bi0, bi1, next0, next1);
+ }
+#endif
+
+ while (n_left_from > 0 && n_left_to_next > 0)
+ {
+ u32 bi0;
+ vlib_buffer_t * b0;
+ u32 next0 = " ENCAP_STACK "_ENCAP_NEXT_IP4_LOOKUP;
+ vnet_hw_interface_t * hi0;
+ ip4_header_t * ip0;
+ udp_header_t * udp0;
+ u64 * copy_src0, * copy_dst0;
+ u32 * copy_src_last0, * copy_dst_last0;
+ " encap_stack "_tunnel_t * t0;
+ u16 new_l0;
+ ip_csum_t sum0;
+
+ bi0 = from[0];
+ to_next[0] = bi0;
+ from += 1;
+ to_next += 1;
+ n_left_from -= 1;
+ n_left_to_next -= 1;
+
+ b0 = vlib_get_buffer (vm, bi0);
+
+ /* 1-wide cache? */
+ hi0 = vnet_get_sup_hw_interface
+ (vnm, vnet_buffer(b0)->sw_if_index[VLIB_TX]);
+
+ t0 = pool_elt_at_index (ngm->tunnels, hi0->dev_instance);
+
+ ASSERT(vec_len(t0->rewrite) >= 24);
+
+ /* Apply the rewrite string. $$$$ vnet_rewrite? */
+ vlib_buffer_advance (b0, -(word)_vec_len(t0->rewrite));
+
+ ip0 = vlib_buffer_get_current(b0);
+ /* Copy the fixed header */
+ copy_dst0 = (u64 *) ip0;
+ copy_src0 = (u64 *) t0->rewrite;
+
+ ASSERT (sizeof (ip4_udp_" encap_stack "_header_t) == FIXME);
+
+ /* Copy first N octets 8-bytes at a time */
+#define _(offs) copy_dst0[offs] = copy_src0[offs];
+ foreach_fixed_header_offset;
+#undef _
+#if 0 /* needed if encap not a multiple of 8 bytes */
+ /* Last 4 octets. Hopefully gcc will be our friend */
+ copy_dst_last0 = (u32 *)(&copy_dst0[FIXME]);
+ copy_src_last0 = (u32 *)(&copy_src0[FIXME]);
+ copy_dst_last0[0] = copy_src_last0[0];
+
+#endif
+ /* fix the <bleep>ing outer-IP checksum */
+ sum0 = ip0->checksum;
+ /* old_l0 always 0, see the rewrite setup */
+ new_l0 =
+ clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0));
+
+ sum0 = ip_csum_update (sum0, old_l0, new_l0, ip4_header_t,
+ length /* changed member */);
+ ip0->checksum = ip_csum_fold (sum0);
+ ip0->length = new_l0;
+
+ /* Fix UDP length */
+ udp0 = (udp_header_t *)(ip0+1);
+ new_l0 = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0)
+ - sizeof (*ip0));
+
+ udp0->length = new_l0;
+
+ /* Reset to look up tunnel partner in the configured FIB */
+ vnet_buffer(b0)->sw_if_index[VLIB_TX] = t0->encap_fib_index;
+ pkts_encapsulated ++;
+
+ if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ " encap_stack "_encap_trace_t *tr =
+ vlib_add_trace (vm, node, b0, sizeof (*tr));
+ tr->tunnel_index = t0 - ngm->tunnels;
+ }
+ vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
+ to_next, n_left_to_next,
+ bi0, next0);
+ }
+
+ vlib_put_next_frame (vm, node, next_index, n_left_to_next);
+ }
+ vlib_node_increment_counter (vm, node->node_index,
+ " ENCAP_STACK "_ENCAP_ERROR_ENCAPSULATED,
+ pkts_encapsulated);
+ return from_frame->n_vectors;
+}
+
+VLIB_REGISTER_NODE (" encap_stack "_encap_node) = {
+ .function = " encap_stack "_encap,
+ .name = \"" encap-stack "-encap\",
+ .vector_size = sizeof (u32),
+ .format_trace = format_" encap_stack "_encap_trace,
+ .type = VLIB_NODE_TYPE_INTERNAL,
+
+ .n_errors = ARRAY_LEN(" encap_stack "_encap_error_strings),
+ .error_strings = " encap_stack "_encap_error_strings,
+
+ .n_next_nodes = " ENCAP_STACK "_ENCAP_N_NEXT,
+
+ .next_nodes = {
+ [" ENCAP_STACK "_ENCAP_NEXT_IP4_LOOKUP] = \"ip4-lookup\",
+ [" ENCAP_STACK "_ENCAP_NEXT_DROP] = \"error-drop\",
+ },
+};
+")
diff --git a/extras/emacs/tunnel-h-skel.el b/extras/emacs/tunnel-h-skel.el
new file mode 100644
index 00000000..067cf134
--- /dev/null
+++ b/extras/emacs/tunnel-h-skel.el
@@ -0,0 +1,128 @@
+;;; tunnel-h-skel.el - tunnel encap header file skeleton
+
+(require 'skeleton)
+
+(define-skeleton skel-tunnel-h
+"Insert a tunnel encap header file"
+nil
+'(setq encap_stack (skeleton-read "encap_stack (e.g ip4_udp_lisp): "))
+'(setq ENCAP_STACK (upcase encap_stack))
+'(setq encap-stack (replace-regexp-in-string "_" "-" encap_stack))
+"
+#ifndef included_vnet_" encap_stack "_h
+#define included_vnet_" encap_stack "_h
+
+#include <vppinfra/error.h>
+#include <vppinfra/hash.h>
+#include <vnet/vnet.h>
+#include <vnet/ip/ip.h>
+#include <vnet/l2/l2_input.h>
+#include <vnet/ethernet/ethernet.h>
+#include <vnet/" encap-stack "/" encap_stack "_packet.h>
+#include <vnet/ip/ip4_packet.h>
+#include <vnet/ip/udp.h>
+
+/* Encap stack built in encap.c */
+typedef CLIB_PACKED (struct {
+ ip4_header_t ip4; /* 20 bytes */
+ udp_header_t udp; /* 8 bytes */
+ " encap_stack "_header_t lisp; /* 8 bytes */
+}) " encap_stack "_header_t;
+
+typedef CLIB_PACKED(struct {
+ /*
+ * Key fields:
+ * all fields in NET byte order
+ */
+ union {
+ struct {
+ u32 FIXME_NET_BYTE_ORDER;
+ };
+ u64 as_u64[1];
+ };
+}) " encap_stack "_tunnel_key_t;
+
+typedef struct {
+ /* Rewrite string. $$$$ maybe: embed vnet_rewrite header */
+ u8 * rewrite;
+
+ /* decap next index */
+ u32 decap_next_index;
+
+ /* tunnel src and dst addresses */
+ ip4_address_t src;
+ ip4_address_t dst;
+
+ /* FIB indices */
+ u32 encap_fib_index; /* tunnel partner lookup here */
+ u32 decap_fib_index; /* inner IP lookup here */
+
+ /* vnet intfc hw/sw_if_index */
+ u32 hw_if_index;
+
+ /* encap header fields in HOST byte order */
+ u32 FIXME;
+} " encap_stack "_tunnel_t;
+
+#define foreach_" encap_stack "_input_next \\
+_(DROP, \"error-drop\") \\
+_(IP4_INPUT, \"ip4-input\") \\
+_(IP6_INPUT, \"ip6-input\") \\
+_(ETHERNET_INPUT, \"ethernet-input\") \\
+_(" ENCAP_STACK "_ENCAP, \"" encap-stack "-encap\")
+
+typedef enum {
+#define _(s,n) " ENCAP_STACK "_INPUT_NEXT_##s,
+ foreach_" encap_stack "_input_next
+#undef _
+ " ENCAP_STACK "_INPUT_N_NEXT,
+} " encap_stack "_input_next_t;
+
+typedef enum {
+#define " encap_stack "_error(n,s) " ENCAP_STACK "_ERROR_##n,
+#include <vnet/" encap-stack "/" encap_stack "_error.def>
+#undef " encap_stack "_error
+ " ENCAP_STACK "_N_ERROR,
+} " encap_stack "_input_error_t;
+
+typedef struct {
+ /* vector of encap tunnel instances */
+ " encap_stack "_tunnel_t *tunnels;
+
+ /* lookup tunnel by key */
+ uword * " encap_stack "_tunnel_by_key;
+
+ /* Free vlib hw_if_indices */
+ u32 * free_" encap_stack "_tunnel_hw_if_indices;
+
+ /* convenience */
+ vlib_main_t * vlib_main;
+ vnet_main_t * vnet_main;
+} " encap_stack "_main_t;
+
+" encap_stack "_main_t " encap_stack "_main;
+
+vlib_node_registration_t " encap_stack "_input_node;
+vlib_node_registration_t " encap_stack "_encap_node;
+
+u8 * format_" encap_stack "_encap_trace (u8 * s, va_list * args);
+u8 * format_" encap_stack "_header_with_length (u8 * s, va_list * args);
+
+typedef struct {
+ u8 is_add;
+ ip4_address_t src, dst;
+ u32 encap_fib_index;
+ u32 decap_fib_index;
+ u32 decap_next_index;
+ /* encap fields in HOST byte order */
+ u8 FIXME_HOST_BYTE_ORDER;
+} vnet_" encap_stack "_add_del_tunnel_args_t;
+
+int vnet_" encap_stack "_add_del_tunnel
+(vnet_" encap_stack "_add_del_tunnel_args_t *a, u32 * hw_if_indexp);
+
+u8 * format_" encap_stack "_header_with_length (u8 * s, va_list * args);
+
+#endif /* included_vnet_" encap_stack "_h */
+
+")
diff --git a/extras/gdb/gdb_cmdfile.vcl_client b/extras/gdb/gdb_cmdfile.vcl_client
new file mode 100644
index 00000000..9b43ed6a
--- /dev/null
+++ b/extras/gdb/gdb_cmdfile.vcl_client
@@ -0,0 +1,10 @@
+echo \n\n====== gdb_cmdfile.vcl_client ======\n
+
+# Here are some interesting VCL breakpoints...
+# Uncomment them out to set during gdb init.
+#
+#b vppcom_session_connect
+#b vppcom_session_write
+#b vppcom_session_read
+#b vl_api_connect_sock_t_handler
+#b vl_api_connect_session_reply_t_handler
diff --git a/extras/gdb/gdb_cmdfile.vcl_server b/extras/gdb/gdb_cmdfile.vcl_server
new file mode 100644
index 00000000..f3ce4fbc
--- /dev/null
+++ b/extras/gdb/gdb_cmdfile.vcl_server
@@ -0,0 +1,10 @@
+echo \n\n====== gdb_cmdfile.vcl_server ======\n
+
+# Here are some interesting VCL breakpoints...
+# Uncomment them out to set during gdb init.
+#
+#b vppcom_session_accept
+#b vppcom_session_write
+#b vppcom_session_read
+#b vl_api_connect_sock_t_handler
+#b vl_api_connect_session_reply_t_handler
diff --git a/extras/gdb/gdb_cmdfile.vpp b/extras/gdb/gdb_cmdfile.vpp
new file mode 100644
index 00000000..a430ccb3
--- /dev/null
+++ b/extras/gdb/gdb_cmdfile.vpp
@@ -0,0 +1,7 @@
+echo \n\n====== gdb_cmdfile.vpp ======\n
+
+# Here are some interesting vpp-api breakpoints...
+# Uncomment them out to set during gdb init.
+#
+#b vl_api_connect_sock_t_handler
+#b vl_api_connect_sock_reply_t_handler
diff --git a/extras/libmemif/Makefile.am b/extras/libmemif/Makefile.am
new file mode 100644
index 00000000..1ff7e7e5
--- /dev/null
+++ b/extras/libmemif/Makefile.am
@@ -0,0 +1,89 @@
+# Copyright (c) 2017 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.
+
+AUTOMAKE_OPTIONS = foreign subdir-objects
+
+ACLOCAL_AMFLAGS = -I m4
+
+AM_CPPFLAGS = -g -DMEMIF_DBG -DICMP_DBG
+
+SRCS_C := $(shell find . -name "*.c" )
+SRCS_H := $(shell find . -name "*.h" )
+
+.PHONY: release
+release:
+ $(MAKE) AM_CPPFLAGS="-O3"
+
+.PHONY: doc
+doc:
+ @echo Building doxygen documentation...
+ doxygen doxygen.conf
+ @echo Doxygen documentation built in docs directory.
+
+.PHONY: fixstyle
+fixstyle:
+ @echo Fixing code style...
+ indent $(SRCS_C) $(SRCS_H)
+ @echo Code style fixed!
+
+#
+# unit_test
+#
+unit_test_SOURCES = test/unit_test.c \
+ test/main_test.c \
+ test/socket_test.c \
+ src/main.c \
+ src/socket.c
+# macro MEMIF_UNIT_TEST -> compile functions without static keyword
+# and declare them in header files, so they can be called from unit tests
+unit_test_CPPFLAGS = $(AM_CPPFLAGS) -Itest -Isrc -DMEMIF_UNIT_TEST -g $(CHECK_CFLAGS)
+unit_test_LDADD = $(CHECK_LIBS)
+
+#
+# main lib
+#
+libmemif_la_SOURCES = src/main.c src/socket.c
+libmemif_la_CPPFLAGS = $(AM_CPPFLAGS) -Isrc
+
+#
+# ICMP responder example
+#
+icmpr_SOURCES = examples/icmp_responder/main.c examples/icmp_responder/icmp_proto.c
+icmpr_LDADD = libmemif.la
+icmpr_CPPFLAGS = $(AM_CPPFLAGS) -Isrc -Iexamples/icmp_responder
+
+#
+# ICMP responder libmemif event polling example
+#
+icmpr_epoll_SOURCES = examples/icmp_responder-epoll/main.c \
+ examples/icmp_responder/icmp_proto.c
+icmpr_epoll_LDADD = libmemif.la
+icmpr_epoll_CPPFLAGS = $(AM_CPPFLAGS) -Isrc -Iexamples/icmp_responder
+
+#
+# ICMP responder multi-thread example
+#
+icmpr_mt_SOURCES = examples/icmp_responder-mt/main.c \
+ examples/icmp_responder/icmp_proto.c
+icmpr_mt_LDADD = libmemif.la -lpthread
+icmpr_mt_CPPFLAGS = $(AM_CPPFLAGS) -Isrc -Iexamples/icmp_responder
+
+noinst_PROGRAMS = icmpr icmpr-epoll icmpr-mt
+
+check_PROGRAMS = unit_test
+
+include_HEADERS = src/libmemif.h
+
+lib_LTLIBRARIES = libmemif.la
+
+TESTS = $(check_PROGRAMS)
diff --git a/extras/libmemif/bootstrap b/extras/libmemif/bootstrap
new file mode 100755
index 00000000..5613c2b4
--- /dev/null
+++ b/extras/libmemif/bootstrap
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+autoreconf -fis
diff --git a/extras/libmemif/configure.ac b/extras/libmemif/configure.ac
new file mode 100644
index 00000000..30fd3dda
--- /dev/null
+++ b/extras/libmemif/configure.ac
@@ -0,0 +1,13 @@
+AC_INIT(libmemif, 1.0)
+LT_INIT
+AM_INIT_AUTOMAKE
+AM_SILENT_RULES([yes])
+AC_PREFIX_DEFAULT([/usr])
+
+PKG_CHECK_MODULES([CHECK], [check])
+
+AC_PROG_CC
+
+AC_OUTPUT([Makefile])
+
+AC_CONFIG_MACRO_DIR([m4])
diff --git a/extras/libmemif/dockerfile b/extras/libmemif/dockerfile
new file mode 100644
index 00000000..5475c6be
--- /dev/null
+++ b/extras/libmemif/dockerfile
@@ -0,0 +1,19 @@
+FROM ubuntu:xenial
+
+RUN apt-get update && \
+ apt-get install -y git build-essential autoconf pkg-config libtool sudo check
+RUN rm -rf /var/lib/apt/lists/*
+
+RUN git clone https://github.com/JakubGrajciar/libmemif.git /libmemif
+WORKDIR /libmemif
+RUN git checkout master
+RUN ./bootstrap
+RUN ./configure
+RUN make
+RUN make install
+
+RUN mkdir /var/vpp
+
+RUN ulimit -c unlimited
+
+CMD ./.libs/icmpr-epoll
diff --git a/extras/libmemif/docs/architecture.png b/extras/libmemif/docs/architecture.png
new file mode 100644
index 00000000..b196c25c
--- /dev/null
+++ b/extras/libmemif/docs/architecture.png
Binary files differ
diff --git a/extras/libmemif/docs/buildinstructions_doc.md b/extras/libmemif/docs/buildinstructions_doc.md
new file mode 100644
index 00000000..838e835a
--- /dev/null
+++ b/extras/libmemif/docs/buildinstructions_doc.md
@@ -0,0 +1,55 @@
+## Build Instructions {#libmemif_build_doc}
+
+Install dependencies
+```
+# sudo apt-get install -y git autoconf pkg_config libtool check
+```
+
+Clone repository to your local machine.
+```
+# git clone https://github.com/JakubGrajciar/libmemif.git
+```
+
+From root directory execute:
+For debug build:
+```
+# ./bootstrap
+# ./configure
+# make
+# make install
+```
+
+For release build:
+```
+# ./bootstrap
+# ./configure
+# make release
+# make install
+```
+Verify installation:
+```
+# ./.libs/icmpr-epoll
+```
+> Make sure to run the binary file from ./.libs. File ./icmp\_responder in libmemif root directory is script that links the library, so it only verifies successful build. Default install path is /usr/lib.
+Use _help_ command to display build information and commands:
+```
+ICMP_Responder:add_epoll_fd:204: fd 0 added to epoll
+MEMIF_DEBUG:src/main.c:memif_init:383: app name: ICMP_Responder
+ICMP_Responder:add_epoll_fd:204: fd 4 added to epoll
+LIBMEMIF EXAMPLE APP: ICMP_Responder (debug)
+==============================
+libmemif version: 1.0 (debug)
+memif version: 256
+commands:
+ help - prints this help
+ exit - exit app
+ conn <index> - create memif (slave-mode)
+ del <index> - delete memif
+ show - show connection details
+ ip-set <index> <ip-addr> - set interface ip address
+ rx-mode <index> <qid> <polling|interrupt> - set queue rx mode
+```
+
+#### Examples
+
+Once the library is built/installed, refer to @ref libmemif_examples_doc and @ref libmemif_gettingstarted_doc for additional information on basic use cases and API usage.
diff --git a/extras/libmemif/docs/gettingstarted_doc.md b/extras/libmemif/docs/gettingstarted_doc.md
new file mode 100644
index 00000000..e3ae6e56
--- /dev/null
+++ b/extras/libmemif/docs/gettingstarted_doc.md
@@ -0,0 +1,219 @@
+## Getting started {#libmemif_gettingstarted_doc}
+
+#### Concept (Connecting to VPP)
+
+For detailed information on api calls and structures please refer to @ref libmemif.h.
+
+1. Initialize memif
+ - Declare callback function handling file descriptor event polling.
+```C
+int
+control_fd_update (int fd, uint8_t events)
+{
+...
+}
+```
+ - Call memif initialization function. memif\_init
+```C
+err = memif_init (control_fd_update, APP_NAME);
+```
+
+> If event occurres on any file descriptor returned by this callback, call memif\_control\_fd\_handler function.
+```C
+memif_err = memif_control_fd_handler (evt.data.fd, events);
+```
+> If callback function parameter for memif\_init function is set to NULL, libmemif will handle file descriptor event polling.
+ Api call memif\_poll\_event will call epoll\_pwait with user defined timeout to poll event on file descriptors opened by libmemif.
+```C
+/* main loop */
+ while (1)
+ {
+ if (memif_poll_event (-1) < 0)
+ {
+ DBG ("poll_event error!");
+ }
+ }
+```
+
+> Memif initialization function will initialize internal structures and create timer file descriptor, which will be used for sending periodic connection requests. Timer is disarmed if no memif interface is created.
+
+2. Creating interface
+ - Declare memif connction handle.
+```C
+memif_conn_handle_t c;
+```
+> example app uses struct that contains connection handle, rx/tx buffers and other connection specific information.
+
+ - Specify connection arguments.
+```C
+memif_conn_args_t args;
+memset (&args, 0, sizeof (args));
+args.is_master = is_master;
+args.log2_ring_size = 10;
+args.buffer_size = 2048;
+args.num_s2m_rings = 2;
+args.num_m2s_rings = 2;
+strncpy ((char *) args.interface_name, IF_NAME, strlen (IF_NAME));
+strncpy ((char *) args.instance_name, APP_NAME, strlen (APP_NAME));
+args.mode = 0;
+args.interface_id = 0;
+```
+ - Declare callback functions called on connected/disconnected/interrupted status changed.
+```C
+int
+on_connect (memif_conn_handle_t conn, void *private_ctx)
+{
+...
+}
+
+int
+on_disconnect (memif_conn_handle_t conn, void *private_ctx)
+{
+ INFO ("memif connected!");
+ return 0;
+}
+```
+ - Call memif interface create function. memif\_create
+```C
+err = memif_create (&c->conn,
+ &args, on_connect, on_disconnect, on_interrupt, &ctx[index]);
+```
+> If connection is in slave mode, arms timer file descriptor.
+> If on interrupt callback is set to NULL, user will not be notified about interrupt. Use memif\_get\_queue\_efd call to get interrupt file descriptor for specific queue.
+```C
+int fd = -1;
+err = memif_get_queue_efd (c->conn, data->qid, &fd);
+```
+
+3. Connection establishment
+ - User application will poll events on all file descriptors returned in memif\_control\_fd\_update\_t callback.
+ - On event call memif\_control\_fd\_handler.
+ - Everything else regarding connection establishment will be done internally.
+ - Once connection has been established, a callback will inform the user about connection status change.
+
+4. Interrupt packet receive
+ - If event is polled on interrupt file descriptor, libmemif will call memif\_interrupt\_t callback specified for every connection instance.
+```C
+int
+on_interrupt (memif_conn_handle_t conn, void *private_ctx, uint16_t qid)
+{
+...
+}
+```
+
+6. Memif buffers
+ - Packet data are stored in memif\_buffer\_t. Pointer _data_ points to shared memory buffer, and unsigned integer *data\_len* contains packet data length.
+```C
+typedef struct
+{
+ uint16_t desc_index;
+ uint32_t buffer_len;
+ uint32_t data_len;
+ void *data;
+} memif_buffer_t;
+```
+
+5. Packet receive
+ - Api call memif\_rx\_burst will set all required fields in memif buffers provided by user application.
+```C
+err = memif_rx_burst (c->conn, qid, c->rx_bufs, MAX_MEMIF_BUFS, &rx);
+```
+ - User application can then process packets.
+ - Api call memif\_buffer\_free will make supplied memif buffers ready for next receive and mark shared memory buffers as free.
+```C
+err = memif_buffer_free (c->conn, qid, c->rx_bufs, rx, &fb);
+```
+
+6. Packet transmit
+ - Api call memif\_buffer\_alloc will set all required fields in memif buffers provided by user application.
+```C
+err = memif_buffer_alloc (c->conn, qid, c->tx_bufs, n, &r);
+```
+ - User application can populate shared memory buffers with packets.
+ - Api call memif\_tx\_burst will inform peer interface (master memif on VPP) that there are packets ready to receive and mark memif buffers as free.
+```C
+err = memif_tx_burst (c->conn, qid, c->tx_bufs, c->tx_buf_num, &r);
+```
+
+7. Helper functions
+ - Memif details
+ - Api call memif\_get\_details will return details about connection.
+```C
+err = memif_get_details (c->conn, &md, buf, buflen);
+```
+ - Memif error messages
+ - Every api call returns error code (integer value) mapped to error string.
+ - Call memif\_strerror will return error message assigned to specific error code.
+```C
+if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_get_details: %s", memif_strerror (err));
+```
+ - Not all syscall errors are translated to memif error codes. If error code 1 (MEMIF\_ERR\_SYSCALL) is returned then libmemif needs to be compiled with -DMEMIF_DBG flag to print error message. Use _make -B_ to rebuild libmemif in debug mode.
+
+#### Example app (libmemif fd event polling):
+
+- @ref extras/libmemif/examples/icmp_responder
+
+> Optional argument: transmit queue id.
+```
+icmpr 1
+```
+> Set transmit queue id to 1. Default is 0.
+> Application will create memif interface in slave mode and try to connect to VPP. Exit using Ctrl+C. Application will handle SIGINT signal, free allocated memory and exit with EXIT_SUCCESS.
+
+#### Example app:
+
+ICMP Responder custom fd event polling.
+
+- @ref extras/libmemif/examples/icmp_responder-epoll
+
+#### Example app (multi-thread queue polling)
+
+ICMP Responder multi-thread.
+- @ref extras/libmemif/examples/icmp_responder-mt
+
+> Simple example of libmemif multi-thread usage. Connection establishment is handled by main thread. There are two rx queues in this example. One in polling mode and second in interrupt mode.
+
+VPP config:
+```
+# create memif id 0 master
+# set int state memif0 up
+# set int ip address memif0 192.168.1.1/24
+# ping 192.168.1.2
+```
+For multiple rings (queues) support run VPP with worker threads:
+example startup.conf:
+```
+unix {
+ interactive
+ nodaemon
+ full-coredump
+}
+
+cpu {
+ workers 2
+}
+```
+VPP config:
+```
+# create memif id 0 master
+# set int state memif0 up
+# set int ip address memif0 192.168.1.1/24
+# ping 192.168.1.2
+```
+> Master mode queue number is limited by worker threads. Slave mode interface needs to specify number of queues.
+```
+# create memif id 0 slave rx-queues 2 tx-queues 2
+```
+> Example applications use VPP default socket file for memif: /run/vpp/memif.sock
+> For master mode, socket directory must exist prior to memif\_create call.
+
+#### Unit tests
+
+Unit tests use [Check](https://libcheck.github.io/check/index.html) framework. This framework must be installed in order to build *unit\_test* binary.
+Ubuntu/Debian:
+```
+sudo apt-get install check
+```
+[More platforms](https://libcheck.github.io/check/web/install.html)
+
diff --git a/extras/libmemif/doxygen.conf b/extras/libmemif/doxygen.conf
new file mode 100644
index 00000000..503eef50
--- /dev/null
+++ b/extras/libmemif/doxygen.conf
@@ -0,0 +1,2427 @@
+# Doxyfile 1.8.11
+
+# This file describes the settings to be used by the documentation system
+# doxygen (www.doxygen.org) for a project.
+#
+# All text after a double hash (##) is considered a comment and is placed in
+# front of the TAG it is preceding.
+#
+# All text after a single hash (#) is considered a comment and will be ignored.
+# The format is:
+# TAG = value [value, ...]
+# For lists, items can also be appended using:
+# TAG += value [value, ...]
+# Values that contain spaces should be placed between quotes (\" \").
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+
+# This tag specifies the encoding used for all characters in the config file
+# that follow. The default is UTF-8 which is also the encoding used for all text
+# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv
+# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv
+# for the list of possible encodings.
+# The default value is: UTF-8.
+
+DOXYFILE_ENCODING = UTF-8
+
+# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by
+# double-quotes, unless you are using Doxywizard) that should identify the
+# project for which the documentation is generated. This name is used in the
+# title of most generated pages and in a few other places.
+# The default value is: My Project.
+
+PROJECT_NAME = "Libmemif"
+
+# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
+# could be handy for archiving the generated documentation or if some version
+# control system is used.
+
+PROJECT_NUMBER = 1.0
+
+# Using the PROJECT_BRIEF tag one can provide an optional one line description
+# for a project that appears at the top of each page and should give viewer a
+# quick idea about the purpose of the project. Keep the description short.
+
+PROJECT_BRIEF = Shared memory packet interface library
+
+# With the PROJECT_LOGO tag one can specify a logo or an icon that is included
+# in the documentation. The maximum height of the logo should not exceed 55
+# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy
+# the logo to the output directory.
+
+PROJECT_LOGO =
+
+# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path
+# into which the generated documentation will be written. If a relative path is
+# entered, it will be relative to the location where doxygen was started. If
+# left blank the current directory will be used.
+
+OUTPUT_DIRECTORY = ./docs
+
+# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub-
+# directories (in 2 levels) under the output directory of each output format and
+# will distribute the generated files over these directories. Enabling this
+# option can be useful when feeding doxygen a huge amount of source files, where
+# putting all generated files in the same directory would otherwise causes
+# performance problems for the file system.
+# The default value is: NO.
+
+CREATE_SUBDIRS = NO
+
+# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII
+# characters to appear in the names of generated files. If set to NO, non-ASCII
+# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode
+# U+3044.
+# The default value is: NO.
+
+ALLOW_UNICODE_NAMES = NO
+
+# The OUTPUT_LANGUAGE tag is used to specify the language in which all
+# documentation generated by doxygen is written. Doxygen will use this
+# information to generate all constant output in the proper language.
+# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese,
+# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States),
+# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian,
+# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages),
+# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian,
+# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian,
+# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish,
+# Ukrainian and Vietnamese.
+# The default value is: English.
+
+OUTPUT_LANGUAGE = English
+
+# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member
+# descriptions after the members that are listed in the file and class
+# documentation (similar to Javadoc). Set to NO to disable this.
+# The default value is: YES.
+
+BRIEF_MEMBER_DESC = YES
+
+# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief
+# description of a member or function before the detailed description
+#
+# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
+# brief descriptions will be completely suppressed.
+# The default value is: YES.
+
+REPEAT_BRIEF = YES
+
+# This tag implements a quasi-intelligent brief description abbreviator that is
+# used to form the text in various listings. Each string in this list, if found
+# as the leading text of the brief description, will be stripped from the text
+# and the result, after processing the whole list, is used as the annotated
+# text. Otherwise, the brief description is used as-is. If left blank, the
+# following values are used ($name is automatically replaced with the name of
+# the entity):The $name class, The $name widget, The $name file, is, provides,
+# specifies, contains, represents, a, an and the.
+
+ABBREVIATE_BRIEF =
+
+# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then
+# doxygen will generate a detailed section even if there is only a brief
+# description.
+# The default value is: NO.
+
+ALWAYS_DETAILED_SEC = NO
+
+# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
+# inherited members of a class in the documentation of that class as if those
+# members were ordinary class members. Constructors, destructors and assignment
+# operators of the base classes will not be shown.
+# The default value is: NO.
+
+INLINE_INHERITED_MEMB = NO
+
+# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path
+# before files name in the file list and in the header files. If set to NO the
+# shortest path that makes the file name unique will be used
+# The default value is: YES.
+
+FULL_PATH_NAMES = YES
+
+# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path.
+# Stripping is only done if one of the specified strings matches the left-hand
+# part of the path. The tag can be used to show relative paths in the file list.
+# If left blank the directory from which doxygen is run is used as the path to
+# strip.
+#
+# Note that you can specify absolute paths here, but also relative paths, which
+# will be relative from the directory where doxygen is started.
+# This tag requires that the tag FULL_PATH_NAMES is set to YES.
+
+STRIP_FROM_PATH =
+
+# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the
+# path mentioned in the documentation of a class, which tells the reader which
+# header file to include in order to use a class. If left blank only the name of
+# the header file containing the class definition is used. Otherwise one should
+# specify the list of include paths that are normally passed to the compiler
+# using the -I flag.
+
+STRIP_FROM_INC_PATH =
+
+# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but
+# less readable) file names. This can be useful is your file systems doesn't
+# support long names like on DOS, Mac, or CD-ROM.
+# The default value is: NO.
+
+SHORT_NAMES = NO
+
+# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the
+# first line (until the first dot) of a Javadoc-style comment as the brief
+# description. If set to NO, the Javadoc-style will behave just like regular Qt-
+# style comments (thus requiring an explicit @brief command for a brief
+# description.)
+# The default value is: NO.
+
+JAVADOC_AUTOBRIEF = NO
+
+# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first
+# line (until the first dot) of a Qt-style comment as the brief description. If
+# set to NO, the Qt-style will behave just like regular Qt-style comments (thus
+# requiring an explicit \brief command for a brief description.)
+# The default value is: NO.
+
+QT_AUTOBRIEF = NO
+
+# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a
+# multi-line C++ special comment block (i.e. a block of //! or /// comments) as
+# a brief description. This used to be the default behavior. The new default is
+# to treat a multi-line C++ comment block as a detailed description. Set this
+# tag to YES if you prefer the old behavior instead.
+#
+# Note that setting this tag to YES also means that rational rose comments are
+# not recognized any more.
+# The default value is: NO.
+
+MULTILINE_CPP_IS_BRIEF = NO
+
+# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the
+# documentation from any documented member that it re-implements.
+# The default value is: YES.
+
+INHERIT_DOCS = YES
+
+# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new
+# page for each member. If set to NO, the documentation of a member will be part
+# of the file/class/namespace that contains it.
+# The default value is: NO.
+
+SEPARATE_MEMBER_PAGES = NO
+
+# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen
+# uses this value to replace tabs by spaces in code fragments.
+# Minimum value: 1, maximum value: 16, default value: 4.
+
+TAB_SIZE = 4
+
+# This tag can be used to specify a number of aliases that act as commands in
+# the documentation. An alias has the form:
+# name=value
+# For example adding
+# "sideeffect=@par Side Effects:\n"
+# will allow you to put the command \sideeffect (or @sideeffect) in the
+# documentation, which will result in a user-defined paragraph with heading
+# "Side Effects:". You can put \n's in the value part of an alias to insert
+# newlines.
+
+ALIASES =
+
+# This tag can be used to specify a number of word-keyword mappings (TCL only).
+# A mapping has the form "name=value". For example adding "class=itcl::class"
+# will allow you to use the command class in the itcl::class meaning.
+
+TCL_SUBST =
+
+# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources
+# only. Doxygen will then generate output that is more tailored for C. For
+# instance, some of the names that are used will be different. The list of all
+# members will be omitted, etc.
+# The default value is: NO.
+
+OPTIMIZE_OUTPUT_FOR_C = YES
+
+# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or
+# Python sources only. Doxygen will then generate output that is more tailored
+# for that language. For instance, namespaces will be presented as packages,
+# qualified scopes will look different, etc.
+# The default value is: NO.
+
+OPTIMIZE_OUTPUT_JAVA = NO
+
+# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran
+# sources. Doxygen will then generate output that is tailored for Fortran.
+# The default value is: NO.
+
+OPTIMIZE_FOR_FORTRAN = NO
+
+# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL
+# sources. Doxygen will then generate output that is tailored for VHDL.
+# The default value is: NO.
+
+OPTIMIZE_OUTPUT_VHDL = NO
+
+# Doxygen selects the parser to use depending on the extension of the files it
+# parses. With this tag you can assign which parser to use for a given
+# extension. Doxygen has a built-in mapping, but you can override or extend it
+# using this tag. The format is ext=language, where ext is a file extension, and
+# language is one of the parsers supported by doxygen: IDL, Java, Javascript,
+# C#, C, C++, D, PHP, Objective-C, Python, Fortran (fixed format Fortran:
+# FortranFixed, free formatted Fortran: FortranFree, unknown formatted Fortran:
+# Fortran. In the later case the parser tries to guess whether the code is fixed
+# or free formatted code, this is the default for Fortran type files), VHDL. For
+# instance to make doxygen treat .inc files as Fortran files (default is PHP),
+# and .f files as C (default is Fortran), use: inc=Fortran f=C.
+#
+# Note: For files without extension you can use no_extension as a placeholder.
+#
+# Note that for custom extensions you also need to set FILE_PATTERNS otherwise
+# the files are not read by doxygen.
+
+EXTENSION_MAPPING =
+
+# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments
+# according to the Markdown format, which allows for more readable
+# documentation. See http://daringfireball.net/projects/markdown/ for details.
+# The output of markdown processing is further processed by doxygen, so you can
+# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in
+# case of backward compatibilities issues.
+# The default value is: YES.
+
+MARKDOWN_SUPPORT = YES
+
+# When enabled doxygen tries to link words that correspond to documented
+# classes, or namespaces to their corresponding documentation. Such a link can
+# be prevented in individual cases by putting a % sign in front of the word or
+# globally by setting AUTOLINK_SUPPORT to NO.
+# The default value is: YES.
+
+AUTOLINK_SUPPORT = YES
+
+# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want
+# to include (a tag file for) the STL sources as input, then you should set this
+# tag to YES in order to let doxygen match functions declarations and
+# definitions whose arguments contain STL classes (e.g. func(std::string);
+# versus func(std::string) {}). This also make the inheritance and collaboration
+# diagrams that involve STL classes more complete and accurate.
+# The default value is: NO.
+
+BUILTIN_STL_SUPPORT = NO
+
+# If you use Microsoft's C++/CLI language, you should set this option to YES to
+# enable parsing support.
+# The default value is: NO.
+
+CPP_CLI_SUPPORT = NO
+
+# Set the SIP_SUPPORT tag to YES if your project consists of sip (see:
+# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen
+# will parse them like normal C++ but will assume all classes use public instead
+# of private inheritance when no explicit protection keyword is present.
+# The default value is: NO.
+
+SIP_SUPPORT = NO
+
+# For Microsoft's IDL there are propget and propput attributes to indicate
+# getter and setter methods for a property. Setting this option to YES will make
+# doxygen to replace the get and set methods by a property in the documentation.
+# This will only work if the methods are indeed getting or setting a simple
+# type. If this is not the case, or you want to show the methods anyway, you
+# should set this option to NO.
+# The default value is: YES.
+
+IDL_PROPERTY_SUPPORT = YES
+
+# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
+# tag is set to YES then doxygen will reuse the documentation of the first
+# member in the group (if any) for the other members of the group. By default
+# all members of a group must be documented explicitly.
+# The default value is: NO.
+
+DISTRIBUTE_GROUP_DOC = NO
+
+# If one adds a struct or class to a group and this option is enabled, then also
+# any nested class or struct is added to the same group. By default this option
+# is disabled and one has to add nested compounds explicitly via \ingroup.
+# The default value is: NO.
+
+GROUP_NESTED_COMPOUNDS = NO
+
+# Set the SUBGROUPING tag to YES to allow class member groups of the same type
+# (for instance a group of public functions) to be put as a subgroup of that
+# type (e.g. under the Public Functions section). Set it to NO to prevent
+# subgrouping. Alternatively, this can be done per class using the
+# \nosubgrouping command.
+# The default value is: YES.
+
+SUBGROUPING = YES
+
+# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions
+# are shown inside the group in which they are included (e.g. using \ingroup)
+# instead of on a separate page (for HTML and Man pages) or section (for LaTeX
+# and RTF).
+#
+# Note that this feature does not work in combination with
+# SEPARATE_MEMBER_PAGES.
+# The default value is: NO.
+
+INLINE_GROUPED_CLASSES = NO
+
+# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions
+# with only public data fields or simple typedef fields will be shown inline in
+# the documentation of the scope in which they are defined (i.e. file,
+# namespace, or group documentation), provided this scope is documented. If set
+# to NO, structs, classes, and unions are shown on a separate page (for HTML and
+# Man pages) or section (for LaTeX and RTF).
+# The default value is: NO.
+
+INLINE_SIMPLE_STRUCTS = NO
+
+# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or
+# enum is documented as struct, union, or enum with the name of the typedef. So
+# typedef struct TypeS {} TypeT, will appear in the documentation as a struct
+# with name TypeT. When disabled the typedef will appear as a member of a file,
+# namespace, or class. And the struct will be named TypeS. This can typically be
+# useful for C code in case the coding convention dictates that all compound
+# types are typedef'ed and only the typedef is referenced, never the tag name.
+# The default value is: NO.
+
+TYPEDEF_HIDES_STRUCT = NO
+
+# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This
+# cache is used to resolve symbols given their name and scope. Since this can be
+# an expensive process and often the same symbol appears multiple times in the
+# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small
+# doxygen will become slower. If the cache is too large, memory is wasted. The
+# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range
+# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536
+# symbols. At the end of a run doxygen will report the cache usage and suggest
+# the optimal cache size from a speed point of view.
+# Minimum value: 0, maximum value: 9, default value: 0.
+
+LOOKUP_CACHE_SIZE = 0
+
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+
+# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in
+# documentation are documented, even if no documentation was available. Private
+# class members and static file members will be hidden unless the
+# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES.
+# Note: This will also disable the warnings about undocumented members that are
+# normally produced when WARNINGS is set to YES.
+# The default value is: NO.
+
+EXTRACT_ALL = YES
+
+# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will
+# be included in the documentation.
+# The default value is: NO.
+
+EXTRACT_PRIVATE = NO
+
+# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal
+# scope will be included in the documentation.
+# The default value is: NO.
+
+EXTRACT_PACKAGE = NO
+
+# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be
+# included in the documentation.
+# The default value is: NO.
+
+EXTRACT_STATIC = NO
+
+# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined
+# locally in source files will be included in the documentation. If set to NO,
+# only classes defined in header files are included. Does not have any effect
+# for Java sources.
+# The default value is: YES.
+
+EXTRACT_LOCAL_CLASSES = YES
+
+# This flag is only useful for Objective-C code. If set to YES, local methods,
+# which are defined in the implementation section but not in the interface are
+# included in the documentation. If set to NO, only methods in the interface are
+# included.
+# The default value is: NO.
+
+EXTRACT_LOCAL_METHODS = NO
+
+# If this flag is set to YES, the members of anonymous namespaces will be
+# extracted and appear in the documentation as a namespace called
+# 'anonymous_namespace{file}', where file will be replaced with the base name of
+# the file that contains the anonymous namespace. By default anonymous namespace
+# are hidden.
+# The default value is: NO.
+
+EXTRACT_ANON_NSPACES = NO
+
+# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all
+# undocumented members inside documented classes or files. If set to NO these
+# members will be included in the various overviews, but no documentation
+# section is generated. This option has no effect if EXTRACT_ALL is enabled.
+# The default value is: NO.
+
+HIDE_UNDOC_MEMBERS = NO
+
+# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all
+# undocumented classes that are normally visible in the class hierarchy. If set
+# to NO, these classes will be included in the various overviews. This option
+# has no effect if EXTRACT_ALL is enabled.
+# The default value is: NO.
+
+HIDE_UNDOC_CLASSES = NO
+
+# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend
+# (class|struct|union) declarations. If set to NO, these declarations will be
+# included in the documentation.
+# The default value is: NO.
+
+HIDE_FRIEND_COMPOUNDS = NO
+
+# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any
+# documentation blocks found inside the body of a function. If set to NO, these
+# blocks will be appended to the function's detailed documentation block.
+# The default value is: NO.
+
+HIDE_IN_BODY_DOCS = NO
+
+# The INTERNAL_DOCS tag determines if documentation that is typed after a
+# \internal command is included. If the tag is set to NO then the documentation
+# will be excluded. Set it to YES to include the internal documentation.
+# The default value is: NO.
+
+INTERNAL_DOCS = NO
+
+# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file
+# names in lower-case letters. If set to YES, upper-case letters are also
+# allowed. This is useful if you have classes or files whose names only differ
+# in case and if your file system supports case sensitive file names. Windows
+# and Mac users are advised to set this option to NO.
+# The default value is: system dependent.
+
+CASE_SENSE_NAMES = YES
+
+# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with
+# their full class and namespace scopes in the documentation. If set to YES, the
+# scope will be hidden.
+# The default value is: NO.
+
+HIDE_SCOPE_NAMES = NO
+
+# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will
+# append additional text to a page's title, such as Class Reference. If set to
+# YES the compound reference will be hidden.
+# The default value is: NO.
+
+HIDE_COMPOUND_REFERENCE= NO
+
+# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of
+# the files that are included by a file in the documentation of that file.
+# The default value is: YES.
+
+SHOW_INCLUDE_FILES = YES
+
+# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each
+# grouped member an include statement to the documentation, telling the reader
+# which file to include in order to use the member.
+# The default value is: NO.
+
+SHOW_GROUPED_MEMB_INC = NO
+
+# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include
+# files with double quotes in the documentation rather than with sharp brackets.
+# The default value is: NO.
+
+FORCE_LOCAL_INCLUDES = NO
+
+# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the
+# documentation for inline members.
+# The default value is: YES.
+
+INLINE_INFO = YES
+
+# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the
+# (detailed) documentation of file and class members alphabetically by member
+# name. If set to NO, the members will appear in declaration order.
+# The default value is: YES.
+
+SORT_MEMBER_DOCS = YES
+
+# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief
+# descriptions of file, namespace and class members alphabetically by member
+# name. If set to NO, the members will appear in declaration order. Note that
+# this will also influence the order of the classes in the class list.
+# The default value is: NO.
+
+SORT_BRIEF_DOCS = NO
+
+# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the
+# (brief and detailed) documentation of class members so that constructors and
+# destructors are listed first. If set to NO the constructors will appear in the
+# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS.
+# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief
+# member documentation.
+# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting
+# detailed member documentation.
+# The default value is: NO.
+
+SORT_MEMBERS_CTORS_1ST = NO
+
+# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy
+# of group names into alphabetical order. If set to NO the group names will
+# appear in their defined order.
+# The default value is: NO.
+
+SORT_GROUP_NAMES = NO
+
+# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by
+# fully-qualified names, including namespaces. If set to NO, the class list will
+# be sorted only by class name, not including the namespace part.
+# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.
+# Note: This option applies only to the class list, not to the alphabetical
+# list.
+# The default value is: NO.
+
+SORT_BY_SCOPE_NAME = NO
+
+# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper
+# type resolution of all parameters of a function it will reject a match between
+# the prototype and the implementation of a member function even if there is
+# only one candidate or it is obvious which candidate to choose by doing a
+# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still
+# accept a match between prototype and implementation in such cases.
+# The default value is: NO.
+
+STRICT_PROTO_MATCHING = NO
+
+# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo
+# list. This list is created by putting \todo commands in the documentation.
+# The default value is: YES.
+
+GENERATE_TODOLIST = YES
+
+# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test
+# list. This list is created by putting \test commands in the documentation.
+# The default value is: YES.
+
+GENERATE_TESTLIST = YES
+
+# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug
+# list. This list is created by putting \bug commands in the documentation.
+# The default value is: YES.
+
+GENERATE_BUGLIST = YES
+
+# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO)
+# the deprecated list. This list is created by putting \deprecated commands in
+# the documentation.
+# The default value is: YES.
+
+GENERATE_DEPRECATEDLIST= YES
+
+# The ENABLED_SECTIONS tag can be used to enable conditional documentation
+# sections, marked by \if <section_label> ... \endif and \cond <section_label>
+# ... \endcond blocks.
+
+ENABLED_SECTIONS =
+
+# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the
+# initial value of a variable or macro / define can have for it to appear in the
+# documentation. If the initializer consists of more lines than specified here
+# it will be hidden. Use a value of 0 to hide initializers completely. The
+# appearance of the value of individual variables and macros / defines can be
+# controlled using \showinitializer or \hideinitializer command in the
+# documentation regardless of this setting.
+# Minimum value: 0, maximum value: 10000, default value: 30.
+
+MAX_INITIALIZER_LINES = 30
+
+# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at
+# the bottom of the documentation of classes and structs. If set to YES, the
+# list will mention the files that were used to generate the documentation.
+# The default value is: YES.
+
+SHOW_USED_FILES = YES
+
+# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This
+# will remove the Files entry from the Quick Index and from the Folder Tree View
+# (if specified).
+# The default value is: YES.
+
+SHOW_FILES = YES
+
+# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces
+# page. This will remove the Namespaces entry from the Quick Index and from the
+# Folder Tree View (if specified).
+# The default value is: YES.
+
+SHOW_NAMESPACES = YES
+
+# The FILE_VERSION_FILTER tag can be used to specify a program or script that
+# doxygen should invoke to get the current version for each file (typically from
+# the version control system). Doxygen will invoke the program by executing (via
+# popen()) the command command input-file, where command is the value of the
+# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided
+# by doxygen. Whatever the program writes to standard output is used as the file
+# version. For an example see the documentation.
+
+FILE_VERSION_FILTER =
+
+# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed
+# by doxygen. The layout file controls the global structure of the generated
+# output files in an output format independent way. To create the layout file
+# that represents doxygen's defaults, run doxygen with the -l option. You can
+# optionally specify a file name after the option, if omitted DoxygenLayout.xml
+# will be used as the name of the layout file.
+#
+# Note that if you run doxygen from a directory containing a file called
+# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE
+# tag is left empty.
+
+LAYOUT_FILE =
+
+# The CITE_BIB_FILES tag can be used to specify one or more bib files containing
+# the reference definitions. This must be a list of .bib files. The .bib
+# extension is automatically appended if omitted. This requires the bibtex tool
+# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info.
+# For LaTeX the style of the bibliography can be controlled using
+# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the
+# search path. See also \cite for info how to create references.
+
+CITE_BIB_FILES =
+
+#---------------------------------------------------------------------------
+# Configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+
+# The QUIET tag can be used to turn on/off the messages that are generated to
+# standard output by doxygen. If QUIET is set to YES this implies that the
+# messages are off.
+# The default value is: NO.
+
+QUIET = NO
+
+# The WARNINGS tag can be used to turn on/off the warning messages that are
+# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES
+# this implies that the warnings are on.
+#
+# Tip: Turn warnings on while writing the documentation.
+# The default value is: YES.
+
+WARNINGS = YES
+
+# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate
+# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag
+# will automatically be disabled.
+# The default value is: YES.
+
+WARN_IF_UNDOCUMENTED = YES
+
+# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for
+# potential errors in the documentation, such as not documenting some parameters
+# in a documented function, or documenting parameters that don't exist or using
+# markup commands wrongly.
+# The default value is: YES.
+
+WARN_IF_DOC_ERROR = YES
+
+# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that
+# are documented, but have no documentation for their parameters or return
+# value. If set to NO, doxygen will only warn about wrong or incomplete
+# parameter documentation, but not about the absence of documentation.
+# The default value is: NO.
+
+WARN_NO_PARAMDOC = NO
+
+# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when
+# a warning is encountered.
+# The default value is: NO.
+
+WARN_AS_ERROR = NO
+
+# The WARN_FORMAT tag determines the format of the warning messages that doxygen
+# can produce. The string should contain the $file, $line, and $text tags, which
+# will be replaced by the file and line number from which the warning originated
+# and the warning text. Optionally the format may contain $version, which will
+# be replaced by the version of the file (if it could be obtained via
+# FILE_VERSION_FILTER)
+# The default value is: $file:$line: $text.
+
+WARN_FORMAT = "$file:$line: $text"
+
+# The WARN_LOGFILE tag can be used to specify a file to which warning and error
+# messages should be written. If left blank the output is written to standard
+# error (stderr).
+
+WARN_LOGFILE =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the input files
+#---------------------------------------------------------------------------
+
+# The INPUT tag is used to specify the files and/or directories that contain
+# documented source files. You may enter file names like myfile.cpp or
+# directories like /usr/src/myproject. Separate the files or directories with
+# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
+# Note: If this tag is empty the current directory is searched.
+
+INPUT = ./src/libmemif.h
+
+# This tag can be used to specify the character encoding of the source files
+# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
+# libiconv (or the iconv built into libc) for the transcoding. See the libiconv
+# documentation (see: http://www.gnu.org/software/libiconv) for the list of
+# possible encodings.
+# The default value is: UTF-8.
+
+INPUT_ENCODING = UTF-8
+
+# If the value of the INPUT tag contains directories, you can use the
+# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and
+# *.h) to filter out the source-files in the directories.
+#
+# Note that for custom extensions or not directly supported extensions you also
+# need to set EXTENSION_MAPPING for the extension otherwise the files are not
+# read by doxygen.
+#
+# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp,
+# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h,
+# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc,
+# *.m, *.markdown, *.md, *.mm, *.dox, *.py, *.pyw, *.f90, *.f, *.for, *.tcl,
+# *.vhd, *.vhdl, *.ucf, *.qsf, *.as and *.js.
+
+FILE_PATTERNS =
+
+# The RECURSIVE tag can be used to specify whether or not subdirectories should
+# be searched for input files as well.
+# The default value is: NO.
+
+RECURSIVE = NO
+
+# The EXCLUDE tag can be used to specify files and/or directories that should be
+# excluded from the INPUT source files. This way you can easily exclude a
+# subdirectory from a directory tree whose root is specified with the INPUT tag.
+#
+# Note that relative paths are relative to the directory from which doxygen is
+# run.
+
+EXCLUDE =
+
+# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
+# directories that are symbolic links (a Unix file system feature) are excluded
+# from the input.
+# The default value is: NO.
+
+EXCLUDE_SYMLINKS = NO
+
+# If the value of the INPUT tag contains directories, you can use the
+# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
+# certain files from those directories.
+#
+# Note that the wildcards are matched against the file with absolute path, so to
+# exclude all test directories for example use the pattern */test/*
+
+EXCLUDE_PATTERNS =
+
+# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
+# (namespaces, classes, functions, etc.) that should be excluded from the
+# output. The symbol name can be a fully qualified name, a word, or if the
+# wildcard * is used, a substring. Examples: ANamespace, AClass,
+# AClass::ANamespace, ANamespace::*Test
+#
+# Note that the wildcards are matched against the file with absolute path, so to
+# exclude all test directories use the pattern */test/*
+
+EXCLUDE_SYMBOLS =
+
+# The EXAMPLE_PATH tag can be used to specify one or more files or directories
+# that contain example code fragments that are included (see the \include
+# command).
+
+EXAMPLE_PATH =
+
+# If the value of the EXAMPLE_PATH tag contains directories, you can use the
+# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and
+# *.h) to filter out the source-files in the directories. If left blank all
+# files are included.
+
+EXAMPLE_PATTERNS =
+
+# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be
+# searched for input files to be used with the \include or \dontinclude commands
+# irrespective of the value of the RECURSIVE tag.
+# The default value is: NO.
+
+EXAMPLE_RECURSIVE = NO
+
+# The IMAGE_PATH tag can be used to specify one or more files or directories
+# that contain images that are to be included in the documentation (see the
+# \image command).
+
+IMAGE_PATH =
+
+# The INPUT_FILTER tag can be used to specify a program that doxygen should
+# invoke to filter for each input file. Doxygen will invoke the filter program
+# by executing (via popen()) the command:
+#
+# <filter> <input-file>
+#
+# where <filter> is the value of the INPUT_FILTER tag, and <input-file> is the
+# name of an input file. Doxygen will then use the output that the filter
+# program writes to standard output. If FILTER_PATTERNS is specified, this tag
+# will be ignored.
+#
+# Note that the filter must not add or remove lines; it is applied before the
+# code is scanned, but not when the output code is generated. If lines are added
+# or removed, the anchors will not be placed correctly.
+#
+# Note that for custom extensions or not directly supported extensions you also
+# need to set EXTENSION_MAPPING for the extension otherwise the files are not
+# properly processed by doxygen.
+
+INPUT_FILTER =
+
+# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern
+# basis. Doxygen will compare the file name with each pattern and apply the
+# filter if there is a match. The filters are a list of the form: pattern=filter
+# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how
+# filters are used. If the FILTER_PATTERNS tag is empty or if none of the
+# patterns match the file name, INPUT_FILTER is applied.
+#
+# Note that for custom extensions or not directly supported extensions you also
+# need to set EXTENSION_MAPPING for the extension otherwise the files are not
+# properly processed by doxygen.
+
+FILTER_PATTERNS =
+
+# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using
+# INPUT_FILTER) will also be used to filter the input files that are used for
+# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES).
+# The default value is: NO.
+
+FILTER_SOURCE_FILES = NO
+
+# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file
+# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and
+# it is also possible to disable source filtering for a specific pattern using
+# *.ext= (so without naming a filter).
+# This tag requires that the tag FILTER_SOURCE_FILES is set to YES.
+
+FILTER_SOURCE_PATTERNS =
+
+# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that
+# is part of the input, its contents will be placed on the main page
+# (index.html). This can be useful if you have a project on for instance GitHub
+# and want to reuse the introduction page also for the doxygen output.
+
+USE_MDFILE_AS_MAINPAGE =
+
+#---------------------------------------------------------------------------
+# Configuration options related to source browsing
+#---------------------------------------------------------------------------
+
+# If the SOURCE_BROWSER tag is set to YES then a list of source files will be
+# generated. Documented entities will be cross-referenced with these sources.
+#
+# Note: To get rid of all source code in the generated output, make sure that
+# also VERBATIM_HEADERS is set to NO.
+# The default value is: NO.
+
+SOURCE_BROWSER = NO
+
+# Setting the INLINE_SOURCES tag to YES will include the body of functions,
+# classes and enums directly into the documentation.
+# The default value is: NO.
+
+INLINE_SOURCES = NO
+
+# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any
+# special comment blocks from generated source code fragments. Normal C, C++ and
+# Fortran comments will always remain visible.
+# The default value is: YES.
+
+STRIP_CODE_COMMENTS = YES
+
+# If the REFERENCED_BY_RELATION tag is set to YES then for each documented
+# function all documented functions referencing it will be listed.
+# The default value is: NO.
+
+REFERENCED_BY_RELATION = NO
+
+# If the REFERENCES_RELATION tag is set to YES then for each documented function
+# all documented entities called/used by that function will be listed.
+# The default value is: NO.
+
+REFERENCES_RELATION = NO
+
+# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set
+# to YES then the hyperlinks from functions in REFERENCES_RELATION and
+# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will
+# link to the documentation.
+# The default value is: YES.
+
+REFERENCES_LINK_SOURCE = YES
+
+# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the
+# source code will show a tooltip with additional information such as prototype,
+# brief description and links to the definition and documentation. Since this
+# will make the HTML file larger and loading of large files a bit slower, you
+# can opt to disable this feature.
+# The default value is: YES.
+# This tag requires that the tag SOURCE_BROWSER is set to YES.
+
+SOURCE_TOOLTIPS = YES
+
+# If the USE_HTAGS tag is set to YES then the references to source code will
+# point to the HTML generated by the htags(1) tool instead of doxygen built-in
+# source browser. The htags tool is part of GNU's global source tagging system
+# (see http://www.gnu.org/software/global/global.html). You will need version
+# 4.8.6 or higher.
+#
+# To use it do the following:
+# - Install the latest version of global
+# - Enable SOURCE_BROWSER and USE_HTAGS in the config file
+# - Make sure the INPUT points to the root of the source tree
+# - Run doxygen as normal
+#
+# Doxygen will invoke htags (and that will in turn invoke gtags), so these
+# tools must be available from the command line (i.e. in the search path).
+#
+# The result: instead of the source browser generated by doxygen, the links to
+# source code will now point to the output of htags.
+# The default value is: NO.
+# This tag requires that the tag SOURCE_BROWSER is set to YES.
+
+USE_HTAGS = NO
+
+# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a
+# verbatim copy of the header file for each class for which an include is
+# specified. Set to NO to disable this.
+# See also: Section \class.
+# The default value is: YES.
+
+VERBATIM_HEADERS = YES
+
+# If the CLANG_ASSISTED_PARSING tag is set to YES then doxygen will use the
+# clang parser (see: http://clang.llvm.org/) for more accurate parsing at the
+# cost of reduced performance. This can be particularly helpful with template
+# rich C++ code for which doxygen's built-in parser lacks the necessary type
+# information.
+# Note: The availability of this option depends on whether or not doxygen was
+# generated with the -Duse-libclang=ON option for CMake.
+# The default value is: NO.
+
+CLANG_ASSISTED_PARSING = NO
+
+# If clang assisted parsing is enabled you can provide the compiler with command
+# line options that you would normally use when invoking the compiler. Note that
+# the include paths will already be set by doxygen for the files and directories
+# specified with INPUT and INCLUDE_PATH.
+# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES.
+
+CLANG_OPTIONS =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+
+# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all
+# compounds will be generated. Enable this if the project contains a lot of
+# classes, structs, unions or interfaces.
+# The default value is: YES.
+
+ALPHABETICAL_INDEX = YES
+
+# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in
+# which the alphabetical index list will be split.
+# Minimum value: 1, maximum value: 20, default value: 5.
+# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.
+
+COLS_IN_ALPHA_INDEX = 5
+
+# In case all classes in a project start with a common prefix, all classes will
+# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag
+# can be used to specify a prefix (or a list of prefixes) that should be ignored
+# while generating the index headers.
+# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.
+
+IGNORE_PREFIX =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the HTML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output
+# The default value is: YES.
+
+GENERATE_HTML = YES
+
+# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a
+# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
+# it.
+# The default directory is: html.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_OUTPUT = html
+
+# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each
+# generated HTML page (for example: .htm, .php, .asp).
+# The default value is: .html.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_FILE_EXTENSION = .html
+
+# The HTML_HEADER tag can be used to specify a user-defined HTML header file for
+# each generated HTML page. If the tag is left blank doxygen will generate a
+# standard header.
+#
+# To get valid HTML the header file that includes any scripts and style sheets
+# that doxygen needs, which is dependent on the configuration options used (e.g.
+# the setting GENERATE_TREEVIEW). It is highly recommended to start with a
+# default header using
+# doxygen -w html new_header.html new_footer.html new_stylesheet.css
+# YourConfigFile
+# and then modify the file new_header.html. See also section "Doxygen usage"
+# for information on how to generate the default header that doxygen normally
+# uses.
+# Note: The header is subject to change so you typically have to regenerate the
+# default header when upgrading to a newer version of doxygen. For a description
+# of the possible markers and block names see the documentation.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_HEADER =
+
+# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each
+# generated HTML page. If the tag is left blank doxygen will generate a standard
+# footer. See HTML_HEADER for more information on how to generate a default
+# footer and what special commands can be used inside the footer. See also
+# section "Doxygen usage" for information on how to generate the default footer
+# that doxygen normally uses.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_FOOTER =
+
+# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style
+# sheet that is used by each HTML page. It can be used to fine-tune the look of
+# the HTML output. If left blank doxygen will generate a default style sheet.
+# See also section "Doxygen usage" for information on how to generate the style
+# sheet that doxygen normally uses.
+# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as
+# it is more robust and this tag (HTML_STYLESHEET) will in the future become
+# obsolete.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_STYLESHEET =
+
+# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined
+# cascading style sheets that are included after the standard style sheets
+# created by doxygen. Using this option one can overrule certain style aspects.
+# This is preferred over using HTML_STYLESHEET since it does not replace the
+# standard style sheet and is therefore more robust against future updates.
+# Doxygen will copy the style sheet files to the output directory.
+# Note: The order of the extra style sheet files is of importance (e.g. the last
+# style sheet in the list overrules the setting of the previous ones in the
+# list). For an example see the documentation.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_EXTRA_STYLESHEET =
+
+# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
+# other source files which should be copied to the HTML output directory. Note
+# that these files will be copied to the base HTML output directory. Use the
+# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these
+# files. In the HTML_STYLESHEET file, use the file name only. Also note that the
+# files will be copied as-is; there are no commands or markers available.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_EXTRA_FILES =
+
+# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen
+# will adjust the colors in the style sheet and background images according to
+# this color. Hue is specified as an angle on a colorwheel, see
+# http://en.wikipedia.org/wiki/Hue for more information. For instance the value
+# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300
+# purple, and 360 is red again.
+# Minimum value: 0, maximum value: 359, default value: 220.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_COLORSTYLE_HUE = 220
+
+# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors
+# in the HTML output. For a value of 0 the output will use grayscales only. A
+# value of 255 will produce the most vivid colors.
+# Minimum value: 0, maximum value: 255, default value: 100.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_COLORSTYLE_SAT = 100
+
+# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the
+# luminance component of the colors in the HTML output. Values below 100
+# gradually make the output lighter, whereas values above 100 make the output
+# darker. The value divided by 100 is the actual gamma applied, so 80 represents
+# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not
+# change the gamma.
+# Minimum value: 40, maximum value: 240, default value: 80.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_COLORSTYLE_GAMMA = 80
+
+# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML
+# page will contain the date and time when the page was generated. Setting this
+# to YES can help to show when doxygen was last run and thus if the
+# documentation is up to date.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_TIMESTAMP = NO
+
+# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML
+# documentation will contain sections that can be hidden and shown after the
+# page has loaded.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_DYNAMIC_SECTIONS = NO
+
+# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries
+# shown in the various tree structured indices initially; the user can expand
+# and collapse entries dynamically later on. Doxygen will expand the tree to
+# such a level that at most the specified number of entries are visible (unless
+# a fully collapsed tree already exceeds this amount). So setting the number of
+# entries 1 will produce a full collapsed tree by default. 0 is a special value
+# representing an infinite number of entries and will result in a full expanded
+# tree by default.
+# Minimum value: 0, maximum value: 9999, default value: 100.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_INDEX_NUM_ENTRIES = 100
+
+# If the GENERATE_DOCSET tag is set to YES, additional index files will be
+# generated that can be used as input for Apple's Xcode 3 integrated development
+# environment (see: http://developer.apple.com/tools/xcode/), introduced with
+# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a
+# Makefile in the HTML output directory. Running make will produce the docset in
+# that directory and running make install will install the docset in
+# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at
+# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html
+# for more information.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+GENERATE_DOCSET = NO
+
+# This tag determines the name of the docset feed. A documentation feed provides
+# an umbrella under which multiple documentation sets from a single provider
+# (such as a company or product suite) can be grouped.
+# The default value is: Doxygen generated docs.
+# This tag requires that the tag GENERATE_DOCSET is set to YES.
+
+DOCSET_FEEDNAME = "Doxygen generated docs"
+
+# This tag specifies a string that should uniquely identify the documentation
+# set bundle. This should be a reverse domain-name style string, e.g.
+# com.mycompany.MyDocSet. Doxygen will append .docset to the name.
+# The default value is: org.doxygen.Project.
+# This tag requires that the tag GENERATE_DOCSET is set to YES.
+
+DOCSET_BUNDLE_ID = org.doxygen.Project
+
+# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify
+# the documentation publisher. This should be a reverse domain-name style
+# string, e.g. com.mycompany.MyDocSet.documentation.
+# The default value is: org.doxygen.Publisher.
+# This tag requires that the tag GENERATE_DOCSET is set to YES.
+
+DOCSET_PUBLISHER_ID = org.doxygen.Publisher
+
+# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher.
+# The default value is: Publisher.
+# This tag requires that the tag GENERATE_DOCSET is set to YES.
+
+DOCSET_PUBLISHER_NAME = Publisher
+
+# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three
+# additional HTML index files: index.hhp, index.hhc, and index.hhk. The
+# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop
+# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on
+# Windows.
+#
+# The HTML Help Workshop contains a compiler that can convert all HTML output
+# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML
+# files are now used as the Windows 98 help format, and will replace the old
+# Windows help format (.hlp) on all Windows platforms in the future. Compressed
+# HTML files also contain an index, a table of contents, and you can search for
+# words in the documentation. The HTML workshop also contains a viewer for
+# compressed HTML files.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+GENERATE_HTMLHELP = NO
+
+# The CHM_FILE tag can be used to specify the file name of the resulting .chm
+# file. You can add a path in front of the file if the result should not be
+# written to the html output directory.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
+CHM_FILE =
+
+# The HHC_LOCATION tag can be used to specify the location (absolute path
+# including file name) of the HTML help compiler (hhc.exe). If non-empty,
+# doxygen will try to run the HTML help compiler on the generated index.hhp.
+# The file has to be specified with full path.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
+HHC_LOCATION =
+
+# The GENERATE_CHI flag controls if a separate .chi index file is generated
+# (YES) or that it should be included in the master .chm file (NO).
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
+GENERATE_CHI = NO
+
+# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc)
+# and project file content.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
+CHM_INDEX_ENCODING =
+
+# The BINARY_TOC flag controls whether a binary table of contents is generated
+# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it
+# enables the Previous and Next buttons.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
+BINARY_TOC = NO
+
+# The TOC_EXPAND flag can be set to YES to add extra items for group members to
+# the table of contents of the HTML help documentation and to the tree view.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
+TOC_EXPAND = NO
+
+# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and
+# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that
+# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help
+# (.qch) of the generated HTML documentation.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+GENERATE_QHP = NO
+
+# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify
+# the file name of the resulting .qch file. The path specified is relative to
+# the HTML output folder.
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QCH_FILE =
+
+# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help
+# Project output. For more information please see Qt Help Project / Namespace
+# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace).
+# The default value is: org.doxygen.Project.
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHP_NAMESPACE = org.doxygen.Project
+
+# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt
+# Help Project output. For more information please see Qt Help Project / Virtual
+# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual-
+# folders).
+# The default value is: doc.
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHP_VIRTUAL_FOLDER = doc
+
+# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom
+# filter to add. For more information please see Qt Help Project / Custom
+# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom-
+# filters).
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHP_CUST_FILTER_NAME =
+
+# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the
+# custom filter to add. For more information please see Qt Help Project / Custom
+# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom-
+# filters).
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHP_CUST_FILTER_ATTRS =
+
+# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this
+# project's filter section matches. Qt Help Project / Filter Attributes (see:
+# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes).
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHP_SECT_FILTER_ATTRS =
+
+# The QHG_LOCATION tag can be used to specify the location of Qt's
+# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the
+# generated .qhp file.
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHG_LOCATION =
+
+# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be
+# generated, together with the HTML files, they form an Eclipse help plugin. To
+# install this plugin and make it available under the help contents menu in
+# Eclipse, the contents of the directory containing the HTML and XML files needs
+# to be copied into the plugins directory of eclipse. The name of the directory
+# within the plugins directory should be the same as the ECLIPSE_DOC_ID value.
+# After copying Eclipse needs to be restarted before the help appears.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+GENERATE_ECLIPSEHELP = NO
+
+# A unique identifier for the Eclipse help plugin. When installing the plugin
+# the directory name containing the HTML and XML files should also have this
+# name. Each documentation set should have its own identifier.
+# The default value is: org.doxygen.Project.
+# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES.
+
+ECLIPSE_DOC_ID = org.doxygen.Project
+
+# If you want full control over the layout of the generated HTML pages it might
+# be necessary to disable the index and replace it with your own. The
+# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top
+# of each HTML page. A value of NO enables the index and the value YES disables
+# it. Since the tabs in the index contain the same information as the navigation
+# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+DISABLE_INDEX = NO
+
+# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index
+# structure should be generated to display hierarchical information. If the tag
+# value is set to YES, a side panel will be generated containing a tree-like
+# index structure (just like the one that is generated for HTML Help). For this
+# to work a browser that supports JavaScript, DHTML, CSS and frames is required
+# (i.e. any modern browser). Windows users are probably better off using the
+# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can
+# further fine-tune the look of the index. As an example, the default style
+# sheet generated by doxygen has an example that shows how to put an image at
+# the root of the tree instead of the PROJECT_NAME. Since the tree basically has
+# the same information as the tab index, you could consider setting
+# DISABLE_INDEX to YES when enabling this option.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+GENERATE_TREEVIEW = NO
+
+# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that
+# doxygen will group on one line in the generated HTML documentation.
+#
+# Note that a value of 0 will completely suppress the enum values from appearing
+# in the overview section.
+# Minimum value: 0, maximum value: 20, default value: 4.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+ENUM_VALUES_PER_LINE = 4
+
+# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used
+# to set the initial width (in pixels) of the frame in which the tree is shown.
+# Minimum value: 0, maximum value: 1500, default value: 250.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+TREEVIEW_WIDTH = 250
+
+# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to
+# external symbols imported via tag files in a separate window.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+EXT_LINKS_IN_WINDOW = NO
+
+# Use this tag to change the font size of LaTeX formulas included as images in
+# the HTML documentation. When you change the font size after a successful
+# doxygen run you need to manually remove any form_*.png images from the HTML
+# output directory to force them to be regenerated.
+# Minimum value: 8, maximum value: 50, default value: 10.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+FORMULA_FONTSIZE = 10
+
+# Use the FORMULA_TRANPARENT tag to determine whether or not the images
+# generated for formulas are transparent PNGs. Transparent PNGs are not
+# supported properly for IE 6.0, but are supported on all modern browsers.
+#
+# Note that when changing this option you need to delete any form_*.png files in
+# the HTML output directory before the changes have effect.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+FORMULA_TRANSPARENT = YES
+
+# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see
+# http://www.mathjax.org) which uses client side Javascript for the rendering
+# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX
+# installed or if you want to formulas look prettier in the HTML output. When
+# enabled you may also need to install MathJax separately and configure the path
+# to it using the MATHJAX_RELPATH option.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+USE_MATHJAX = NO
+
+# When MathJax is enabled you can set the default output format to be used for
+# the MathJax output. See the MathJax site (see:
+# http://docs.mathjax.org/en/latest/output.html) for more details.
+# Possible values are: HTML-CSS (which is slower, but has the best
+# compatibility), NativeMML (i.e. MathML) and SVG.
+# The default value is: HTML-CSS.
+# This tag requires that the tag USE_MATHJAX is set to YES.
+
+MATHJAX_FORMAT = HTML-CSS
+
+# When MathJax is enabled you need to specify the location relative to the HTML
+# output directory using the MATHJAX_RELPATH option. The destination directory
+# should contain the MathJax.js script. For instance, if the mathjax directory
+# is located at the same level as the HTML output directory, then
+# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax
+# Content Delivery Network so you can quickly see the result without installing
+# MathJax. However, it is strongly recommended to install a local copy of
+# MathJax from http://www.mathjax.org before deployment.
+# The default value is: http://cdn.mathjax.org/mathjax/latest.
+# This tag requires that the tag USE_MATHJAX is set to YES.
+
+MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest
+
+# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax
+# extension names that should be enabled during MathJax rendering. For example
+# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols
+# This tag requires that the tag USE_MATHJAX is set to YES.
+
+MATHJAX_EXTENSIONS =
+
+# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces
+# of code that will be used on startup of the MathJax code. See the MathJax site
+# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an
+# example see the documentation.
+# This tag requires that the tag USE_MATHJAX is set to YES.
+
+MATHJAX_CODEFILE =
+
+# When the SEARCHENGINE tag is enabled doxygen will generate a search box for
+# the HTML output. The underlying search engine uses javascript and DHTML and
+# should work on any modern browser. Note that when using HTML help
+# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET)
+# there is already a search function so this one should typically be disabled.
+# For large projects the javascript based search engine can be slow, then
+# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to
+# search using the keyboard; to jump to the search box use <access key> + S
+# (what the <access key> is depends on the OS and browser, but it is typically
+# <CTRL>, <ALT>/<option>, or both). Inside the search box use the <cursor down
+# key> to jump into the search results window, the results can be navigated
+# using the <cursor keys>. Press <Enter> to select an item or <escape> to cancel
+# the search. The filter options can be selected when the cursor is inside the
+# search box by pressing <Shift>+<cursor down>. Also here use the <cursor keys>
+# to select a filter and <Enter> or <escape> to activate or cancel the filter
+# option.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+SEARCHENGINE = YES
+
+# When the SERVER_BASED_SEARCH tag is enabled the search engine will be
+# implemented using a web server instead of a web client using Javascript. There
+# are two flavors of web server based searching depending on the EXTERNAL_SEARCH
+# setting. When disabled, doxygen will generate a PHP script for searching and
+# an index file used by the script. When EXTERNAL_SEARCH is enabled the indexing
+# and searching needs to be provided by external tools. See the section
+# "External Indexing and Searching" for details.
+# The default value is: NO.
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+SERVER_BASED_SEARCH = NO
+
+# When EXTERNAL_SEARCH tag is enabled doxygen will no longer generate the PHP
+# script for searching. Instead the search results are written to an XML file
+# which needs to be processed by an external indexer. Doxygen will invoke an
+# external search engine pointed to by the SEARCHENGINE_URL option to obtain the
+# search results.
+#
+# Doxygen ships with an example indexer (doxyindexer) and search engine
+# (doxysearch.cgi) which are based on the open source search engine library
+# Xapian (see: http://xapian.org/).
+#
+# See the section "External Indexing and Searching" for details.
+# The default value is: NO.
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+EXTERNAL_SEARCH = NO
+
+# The SEARCHENGINE_URL should point to a search engine hosted by a web server
+# which will return the search results when EXTERNAL_SEARCH is enabled.
+#
+# Doxygen ships with an example indexer (doxyindexer) and search engine
+# (doxysearch.cgi) which are based on the open source search engine library
+# Xapian (see: http://xapian.org/). See the section "External Indexing and
+# Searching" for details.
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+SEARCHENGINE_URL =
+
+# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the unindexed
+# search data is written to a file for indexing by an external tool. With the
+# SEARCHDATA_FILE tag the name of this file can be specified.
+# The default file is: searchdata.xml.
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+SEARCHDATA_FILE = searchdata.xml
+
+# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the
+# EXTERNAL_SEARCH_ID tag can be used as an identifier for the project. This is
+# useful in combination with EXTRA_SEARCH_MAPPINGS to search through multiple
+# projects and redirect the results back to the right project.
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+EXTERNAL_SEARCH_ID =
+
+# The EXTRA_SEARCH_MAPPINGS tag can be used to enable searching through doxygen
+# projects other than the one defined by this configuration file, but that are
+# all added to the same external search index. Each project needs to have a
+# unique id set via EXTERNAL_SEARCH_ID. The search mapping then maps the id of
+# to a relative location where the documentation can be found. The format is:
+# EXTRA_SEARCH_MAPPINGS = tagname1=loc1 tagname2=loc2 ...
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+EXTRA_SEARCH_MAPPINGS =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_LATEX tag is set to YES, doxygen will generate LaTeX output.
+# The default value is: YES.
+
+GENERATE_LATEX = YES
+
+# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. If a
+# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
+# it.
+# The default directory is: latex.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_OUTPUT = latex
+
+# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be
+# invoked.
+#
+# Note that when enabling USE_PDFLATEX this option is only used for generating
+# bitmaps for formulas in the HTML output, but not in the Makefile that is
+# written to the output directory.
+# The default file is: latex.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_CMD_NAME = latex
+
+# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to generate
+# index for LaTeX.
+# The default file is: makeindex.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+MAKEINDEX_CMD_NAME = makeindex
+
+# If the COMPACT_LATEX tag is set to YES, doxygen generates more compact LaTeX
+# documents. This may be useful for small projects and may help to save some
+# trees in general.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+COMPACT_LATEX = NO
+
+# The PAPER_TYPE tag can be used to set the paper type that is used by the
+# printer.
+# Possible values are: a4 (210 x 297 mm), letter (8.5 x 11 inches), legal (8.5 x
+# 14 inches) and executive (7.25 x 10.5 inches).
+# The default value is: a4.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+PAPER_TYPE = a4
+
+# The EXTRA_PACKAGES tag can be used to specify one or more LaTeX package names
+# that should be included in the LaTeX output. The package can be specified just
+# by its name or with the correct syntax as to be used with the LaTeX
+# \usepackage command. To get the times font for instance you can specify :
+# EXTRA_PACKAGES=times or EXTRA_PACKAGES={times}
+# To use the option intlimits with the amsmath package you can specify:
+# EXTRA_PACKAGES=[intlimits]{amsmath}
+# If left blank no extra packages will be included.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+EXTRA_PACKAGES =
+
+# The LATEX_HEADER tag can be used to specify a personal LaTeX header for the
+# generated LaTeX document. The header should contain everything until the first
+# chapter. If it is left blank doxygen will generate a standard header. See
+# section "Doxygen usage" for information on how to let doxygen write the
+# default header to a separate file.
+#
+# Note: Only use a user-defined header if you know what you are doing! The
+# following commands have a special meaning inside the header: $title,
+# $datetime, $date, $doxygenversion, $projectname, $projectnumber,
+# $projectbrief, $projectlogo. Doxygen will replace $title with the empty
+# string, for the replacement values of the other commands the user is referred
+# to HTML_HEADER.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_HEADER =
+
+# The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for the
+# generated LaTeX document. The footer should contain everything after the last
+# chapter. If it is left blank doxygen will generate a standard footer. See
+# LATEX_HEADER for more information on how to generate a default footer and what
+# special commands can be used inside the footer.
+#
+# Note: Only use a user-defined footer if you know what you are doing!
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_FOOTER =
+
+# The LATEX_EXTRA_STYLESHEET tag can be used to specify additional user-defined
+# LaTeX style sheets that are included after the standard style sheets created
+# by doxygen. Using this option one can overrule certain style aspects. Doxygen
+# will copy the style sheet files to the output directory.
+# Note: The order of the extra style sheet files is of importance (e.g. the last
+# style sheet in the list overrules the setting of the previous ones in the
+# list).
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_EXTRA_STYLESHEET =
+
+# The LATEX_EXTRA_FILES tag can be used to specify one or more extra images or
+# other source files which should be copied to the LATEX_OUTPUT output
+# directory. Note that the files will be copied as-is; there are no commands or
+# markers available.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_EXTRA_FILES =
+
+# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated is
+# prepared for conversion to PDF (using ps2pdf or pdflatex). The PDF file will
+# contain links (just like the HTML output) instead of page references. This
+# makes the output suitable for online browsing using a PDF viewer.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+PDF_HYPERLINKS = YES
+
+# If the USE_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate
+# the PDF file directly from the LaTeX files. Set this option to YES, to get a
+# higher quality PDF documentation.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+USE_PDFLATEX = YES
+
+# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \batchmode
+# command to the generated LaTeX files. This will instruct LaTeX to keep running
+# if errors occur, instead of asking the user for help. This option is also used
+# when generating formulas in HTML.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_BATCHMODE = NO
+
+# If the LATEX_HIDE_INDICES tag is set to YES then doxygen will not include the
+# index chapters (such as File Index, Compound Index, etc.) in the output.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_HIDE_INDICES = NO
+
+# If the LATEX_SOURCE_CODE tag is set to YES then doxygen will include source
+# code with syntax highlighting in the LaTeX output.
+#
+# Note that which sources are shown also depends on other settings such as
+# SOURCE_BROWSER.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_SOURCE_CODE = NO
+
+# The LATEX_BIB_STYLE tag can be used to specify the style to use for the
+# bibliography, e.g. plainnat, or ieeetr. See
+# http://en.wikipedia.org/wiki/BibTeX and \cite for more info.
+# The default value is: plain.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_BIB_STYLE = plain
+
+# If the LATEX_TIMESTAMP tag is set to YES then the footer of each generated
+# page will contain the date and time when the page was generated. Setting this
+# to NO can help when comparing the output of multiple runs.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_TIMESTAMP = NO
+
+#---------------------------------------------------------------------------
+# Configuration options related to the RTF output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_RTF tag is set to YES, doxygen will generate RTF output. The
+# RTF output is optimized for Word 97 and may not look too pretty with other RTF
+# readers/editors.
+# The default value is: NO.
+
+GENERATE_RTF = NO
+
+# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. If a
+# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
+# it.
+# The default directory is: rtf.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
+RTF_OUTPUT = rtf
+
+# If the COMPACT_RTF tag is set to YES, doxygen generates more compact RTF
+# documents. This may be useful for small projects and may help to save some
+# trees in general.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
+COMPACT_RTF = NO
+
+# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated will
+# contain hyperlink fields. The RTF file will contain links (just like the HTML
+# output) instead of page references. This makes the output suitable for online
+# browsing using Word or some other Word compatible readers that support those
+# fields.
+#
+# Note: WordPad (write) and others do not support links.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
+RTF_HYPERLINKS = NO
+
+# Load stylesheet definitions from file. Syntax is similar to doxygen's config
+# file, i.e. a series of assignments. You only have to provide replacements,
+# missing definitions are set to their default value.
+#
+# See also section "Doxygen usage" for information on how to generate the
+# default style sheet that doxygen normally uses.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
+RTF_STYLESHEET_FILE =
+
+# Set optional variables used in the generation of an RTF document. Syntax is
+# similar to doxygen's config file. A template extensions file can be generated
+# using doxygen -e rtf extensionFile.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
+RTF_EXTENSIONS_FILE =
+
+# If the RTF_SOURCE_CODE tag is set to YES then doxygen will include source code
+# with syntax highlighting in the RTF output.
+#
+# Note that which sources are shown also depends on other settings such as
+# SOURCE_BROWSER.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
+RTF_SOURCE_CODE = NO
+
+#---------------------------------------------------------------------------
+# Configuration options related to the man page output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_MAN tag is set to YES, doxygen will generate man pages for
+# classes and files.
+# The default value is: NO.
+
+GENERATE_MAN = NO
+
+# The MAN_OUTPUT tag is used to specify where the man pages will be put. If a
+# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
+# it. A directory man3 will be created inside the directory specified by
+# MAN_OUTPUT.
+# The default directory is: man.
+# This tag requires that the tag GENERATE_MAN is set to YES.
+
+MAN_OUTPUT = man
+
+# The MAN_EXTENSION tag determines the extension that is added to the generated
+# man pages. In case the manual section does not start with a number, the number
+# 3 is prepended. The dot (.) at the beginning of the MAN_EXTENSION tag is
+# optional.
+# The default value is: .3.
+# This tag requires that the tag GENERATE_MAN is set to YES.
+
+MAN_EXTENSION = .3
+
+# The MAN_SUBDIR tag determines the name of the directory created within
+# MAN_OUTPUT in which the man pages are placed. If defaults to man followed by
+# MAN_EXTENSION with the initial . removed.
+# This tag requires that the tag GENERATE_MAN is set to YES.
+
+MAN_SUBDIR =
+
+# If the MAN_LINKS tag is set to YES and doxygen generates man output, then it
+# will generate one additional man file for each entity documented in the real
+# man page(s). These additional files only source the real man page, but without
+# them the man command would be unable to find the correct page.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_MAN is set to YES.
+
+MAN_LINKS = NO
+
+#---------------------------------------------------------------------------
+# Configuration options related to the XML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_XML tag is set to YES, doxygen will generate an XML file that
+# captures the structure of the code including all documentation.
+# The default value is: NO.
+
+GENERATE_XML = NO
+
+# The XML_OUTPUT tag is used to specify where the XML pages will be put. If a
+# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
+# it.
+# The default directory is: xml.
+# This tag requires that the tag GENERATE_XML is set to YES.
+
+XML_OUTPUT = xml
+
+# If the XML_PROGRAMLISTING tag is set to YES, doxygen will dump the program
+# listings (including syntax highlighting and cross-referencing information) to
+# the XML output. Note that enabling this will significantly increase the size
+# of the XML output.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_XML is set to YES.
+
+XML_PROGRAMLISTING = YES
+
+#---------------------------------------------------------------------------
+# Configuration options related to the DOCBOOK output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_DOCBOOK tag is set to YES, doxygen will generate Docbook files
+# that can be used to generate PDF.
+# The default value is: NO.
+
+GENERATE_DOCBOOK = NO
+
+# The DOCBOOK_OUTPUT tag is used to specify where the Docbook pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be put in
+# front of it.
+# The default directory is: docbook.
+# This tag requires that the tag GENERATE_DOCBOOK is set to YES.
+
+DOCBOOK_OUTPUT = docbook
+
+# If the DOCBOOK_PROGRAMLISTING tag is set to YES, doxygen will include the
+# program listings (including syntax highlighting and cross-referencing
+# information) to the DOCBOOK output. Note that enabling this will significantly
+# increase the size of the DOCBOOK output.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_DOCBOOK is set to YES.
+
+DOCBOOK_PROGRAMLISTING = NO
+
+#---------------------------------------------------------------------------
+# Configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_AUTOGEN_DEF tag is set to YES, doxygen will generate an
+# AutoGen Definitions (see http://autogen.sf.net) file that captures the
+# structure of the code including all documentation. Note that this feature is
+# still experimental and incomplete at the moment.
+# The default value is: NO.
+
+GENERATE_AUTOGEN_DEF = NO
+
+#---------------------------------------------------------------------------
+# Configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_PERLMOD tag is set to YES, doxygen will generate a Perl module
+# file that captures the structure of the code including all documentation.
+#
+# Note that this feature is still experimental and incomplete at the moment.
+# The default value is: NO.
+
+GENERATE_PERLMOD = NO
+
+# If the PERLMOD_LATEX tag is set to YES, doxygen will generate the necessary
+# Makefile rules, Perl scripts and LaTeX code to be able to generate PDF and DVI
+# output from the Perl module output.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_PERLMOD is set to YES.
+
+PERLMOD_LATEX = NO
+
+# If the PERLMOD_PRETTY tag is set to YES, the Perl module output will be nicely
+# formatted so it can be parsed by a human reader. This is useful if you want to
+# understand what is going on. On the other hand, if this tag is set to NO, the
+# size of the Perl module output will be much smaller and Perl will parse it
+# just the same.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_PERLMOD is set to YES.
+
+PERLMOD_PRETTY = YES
+
+# The names of the make variables in the generated doxyrules.make file are
+# prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. This is useful
+# so different doxyrules.make files included by the same Makefile don't
+# overwrite each other's variables.
+# This tag requires that the tag GENERATE_PERLMOD is set to YES.
+
+PERLMOD_MAKEVAR_PREFIX =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+
+# If the ENABLE_PREPROCESSING tag is set to YES, doxygen will evaluate all
+# C-preprocessor directives found in the sources and include files.
+# The default value is: YES.
+
+ENABLE_PREPROCESSING = YES
+
+# If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names
+# in the source code. If set to NO, only conditional compilation will be
+# performed. Macro expansion can be done in a controlled way by setting
+# EXPAND_ONLY_PREDEF to YES.
+# The default value is: NO.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+MACRO_EXPANSION = YES
+
+# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then
+# the macro expansion is limited to the macros specified with the PREDEFINED and
+# EXPAND_AS_DEFINED tags.
+# The default value is: NO.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+EXPAND_ONLY_PREDEF = YES
+
+# If the SEARCH_INCLUDES tag is set to YES, the include files in the
+# INCLUDE_PATH will be searched if a #include is found.
+# The default value is: YES.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+SEARCH_INCLUDES = YES
+
+# The INCLUDE_PATH tag can be used to specify one or more directories that
+# contain include files that are not input files but should be processed by the
+# preprocessor.
+# This tag requires that the tag SEARCH_INCLUDES is set to YES.
+
+INCLUDE_PATH =
+
+# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
+# patterns (like *.h and *.hpp) to filter out the header-files in the
+# directories. If left blank, the patterns specified with FILE_PATTERNS will be
+# used.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+INCLUDE_FILE_PATTERNS =
+
+# The PREDEFINED tag can be used to specify one or more macro names that are
+# defined before the preprocessor is started (similar to the -D option of e.g.
+# gcc). The argument of the tag is a list of macros of the form: name or
+# name=definition (no spaces). If the definition and the "=" are omitted, "=1"
+# is assumed. To prevent a macro definition from being undefined via #undef or
+# recursively expanded use the := operator instead of the = operator.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+PREDEFINED =
+
+# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
+# tag can be used to specify a list of macro names that should be expanded. The
+# macro definition that is found in the sources will be used. Use the PREDEFINED
+# tag if you want to use a different macro definition that overrules the
+# definition found in the source code.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+EXPAND_AS_DEFINED =
+
+# If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will
+# remove all references to function-like macros that are alone on a line, have
+# an all uppercase name, and do not end with a semicolon. Such function macros
+# are typically used for boiler-plate code, and will confuse the parser if not
+# removed.
+# The default value is: YES.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+SKIP_FUNCTION_MACROS = YES
+
+#---------------------------------------------------------------------------
+# Configuration options related to external references
+#---------------------------------------------------------------------------
+
+# The TAGFILES tag can be used to specify one or more tag files. For each tag
+# file the location of the external documentation should be added. The format of
+# a tag file without this location is as follows:
+# TAGFILES = file1 file2 ...
+# Adding location for the tag files is done as follows:
+# TAGFILES = file1=loc1 "file2 = loc2" ...
+# where loc1 and loc2 can be relative or absolute paths or URLs. See the
+# section "Linking to external documentation" for more information about the use
+# of tag files.
+# Note: Each tag file must have a unique name (where the name does NOT include
+# the path). If a tag file is not located in the directory in which doxygen is
+# run, you must also specify the path to the tagfile here.
+
+TAGFILES =
+
+# When a file name is specified after GENERATE_TAGFILE, doxygen will create a
+# tag file that is based on the input files it reads. See section "Linking to
+# external documentation" for more information about the usage of tag files.
+
+GENERATE_TAGFILE =
+
+# If the ALLEXTERNALS tag is set to YES, all external class will be listed in
+# the class index. If set to NO, only the inherited external classes will be
+# listed.
+# The default value is: NO.
+
+ALLEXTERNALS = NO
+
+# If the EXTERNAL_GROUPS tag is set to YES, all external groups will be listed
+# in the modules index. If set to NO, only the current project's groups will be
+# listed.
+# The default value is: YES.
+
+EXTERNAL_GROUPS = YES
+
+# If the EXTERNAL_PAGES tag is set to YES, all external pages will be listed in
+# the related pages index. If set to NO, only the current project's pages will
+# be listed.
+# The default value is: YES.
+
+EXTERNAL_PAGES = YES
+
+# The PERL_PATH should be the absolute path and name of the perl script
+# interpreter (i.e. the result of 'which perl').
+# The default file (with absolute path) is: /usr/bin/perl.
+
+PERL_PATH = /usr/bin/perl
+
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+
+# If the CLASS_DIAGRAMS tag is set to YES, doxygen will generate a class diagram
+# (in HTML and LaTeX) for classes with base or super classes. Setting the tag to
+# NO turns the diagrams off. Note that this option also works with HAVE_DOT
+# disabled, but it is recommended to install and use dot, since it yields more
+# powerful graphs.
+# The default value is: YES.
+
+CLASS_DIAGRAMS = YES
+
+# You can define message sequence charts within doxygen comments using the \msc
+# command. Doxygen will then run the mscgen tool (see:
+# http://www.mcternan.me.uk/mscgen/)) to produce the chart and insert it in the
+# documentation. The MSCGEN_PATH tag allows you to specify the directory where
+# the mscgen tool resides. If left empty the tool is assumed to be found in the
+# default search path.
+
+MSCGEN_PATH =
+
+# You can include diagrams made with dia in doxygen documentation. Doxygen will
+# then run dia to produce the diagram and insert it in the documentation. The
+# DIA_PATH tag allows you to specify the directory where the dia binary resides.
+# If left empty dia is assumed to be found in the default search path.
+
+DIA_PATH =
+
+# If set to YES the inheritance and collaboration graphs will hide inheritance
+# and usage relations if the target is undocumented or is not a class.
+# The default value is: YES.
+
+HIDE_UNDOC_RELATIONS = YES
+
+# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
+# available from the path. This tool is part of Graphviz (see:
+# http://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent
+# Bell Labs. The other options in this section have no effect if this option is
+# set to NO
+# The default value is: YES.
+
+HAVE_DOT = YES
+
+# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed
+# to run in parallel. When set to 0 doxygen will base this on the number of
+# processors available in the system. You can set it explicitly to a value
+# larger than 0 to get control over the balance between CPU load and processing
+# speed.
+# Minimum value: 0, maximum value: 32, default value: 0.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_NUM_THREADS = 0
+
+# When you want a differently looking font in the dot files that doxygen
+# generates you can specify the font name using DOT_FONTNAME. You need to make
+# sure dot is able to find the font, which can be done by putting it in a
+# standard location or by setting the DOTFONTPATH environment variable or by
+# setting DOT_FONTPATH to the directory containing the font.
+# The default value is: Helvetica.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_FONTNAME = Helvetica
+
+# The DOT_FONTSIZE tag can be used to set the size (in points) of the font of
+# dot graphs.
+# Minimum value: 4, maximum value: 24, default value: 10.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_FONTSIZE = 10
+
+# By default doxygen will tell dot to use the default font as specified with
+# DOT_FONTNAME. If you specify a different font using DOT_FONTNAME you can set
+# the path where dot can find it using this tag.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_FONTPATH =
+
+# If the CLASS_GRAPH tag is set to YES then doxygen will generate a graph for
+# each documented class showing the direct and indirect inheritance relations.
+# Setting this tag to YES will force the CLASS_DIAGRAMS tag to NO.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+CLASS_GRAPH = YES
+
+# If the COLLABORATION_GRAPH tag is set to YES then doxygen will generate a
+# graph for each documented class showing the direct and indirect implementation
+# dependencies (inheritance, containment, and class references variables) of the
+# class with other documented classes.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+COLLABORATION_GRAPH = YES
+
+# If the GROUP_GRAPHS tag is set to YES then doxygen will generate a graph for
+# groups, showing the direct groups dependencies.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+GROUP_GRAPHS = YES
+
+# If the UML_LOOK tag is set to YES, doxygen will generate inheritance and
+# collaboration diagrams in a style similar to the OMG's Unified Modeling
+# Language.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+UML_LOOK = NO
+
+# If the UML_LOOK tag is enabled, the fields and methods are shown inside the
+# class node. If there are many fields or methods and many nodes the graph may
+# become too big to be useful. The UML_LIMIT_NUM_FIELDS threshold limits the
+# number of items for each type to make the size more manageable. Set this to 0
+# for no limit. Note that the threshold may be exceeded by 50% before the limit
+# is enforced. So when you set the threshold to 10, up to 15 fields may appear,
+# but if the number exceeds 15, the total amount of fields shown is limited to
+# 10.
+# Minimum value: 0, maximum value: 100, default value: 10.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+UML_LIMIT_NUM_FIELDS = 10
+
+# If the TEMPLATE_RELATIONS tag is set to YES then the inheritance and
+# collaboration graphs will show the relations between templates and their
+# instances.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+TEMPLATE_RELATIONS = NO
+
+# If the INCLUDE_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are set to
+# YES then doxygen will generate a graph for each documented file showing the
+# direct and indirect include dependencies of the file with other documented
+# files.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+INCLUDE_GRAPH = YES
+
+# If the INCLUDED_BY_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are
+# set to YES then doxygen will generate a graph for each documented file showing
+# the direct and indirect include dependencies of the file with other documented
+# files.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+INCLUDED_BY_GRAPH = YES
+
+# If the CALL_GRAPH tag is set to YES then doxygen will generate a call
+# dependency graph for every global function or class method.
+#
+# Note that enabling this option will significantly increase the time of a run.
+# So in most cases it will be better to enable call graphs for selected
+# functions only using the \callgraph command. Disabling a call graph can be
+# accomplished by means of the command \hidecallgraph.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+CALL_GRAPH = NO
+
+# If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller
+# dependency graph for every global function or class method.
+#
+# Note that enabling this option will significantly increase the time of a run.
+# So in most cases it will be better to enable caller graphs for selected
+# functions only using the \callergraph command. Disabling a caller graph can be
+# accomplished by means of the command \hidecallergraph.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+CALLER_GRAPH = NO
+
+# If the GRAPHICAL_HIERARCHY tag is set to YES then doxygen will graphical
+# hierarchy of all classes instead of a textual one.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+GRAPHICAL_HIERARCHY = YES
+
+# If the DIRECTORY_GRAPH tag is set to YES then doxygen will show the
+# dependencies a directory has on other directories in a graphical way. The
+# dependency relations are determined by the #include relations between the
+# files in the directories.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DIRECTORY_GRAPH = YES
+
+# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
+# generated by dot. For an explanation of the image formats see the section
+# output formats in the documentation of the dot tool (Graphviz (see:
+# http://www.graphviz.org/)).
+# Note: If you choose svg you need to set HTML_FILE_EXTENSION to xhtml in order
+# to make the SVG files visible in IE 9+ (other browsers do not have this
+# requirement).
+# Possible values are: png, png:cairo, png:cairo:cairo, png:cairo:gd, png:gd,
+# png:gd:gd, jpg, jpg:cairo, jpg:cairo:gd, jpg:gd, jpg:gd:gd, gif, gif:cairo,
+# gif:cairo:gd, gif:gd, gif:gd:gd, svg, png:gd, png:gd:gd, png:cairo,
+# png:cairo:gd, png:cairo:cairo, png:cairo:gdiplus, png:gdiplus and
+# png:gdiplus:gdiplus.
+# The default value is: png.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_IMAGE_FORMAT = png
+
+# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to
+# enable generation of interactive SVG images that allow zooming and panning.
+#
+# Note that this requires a modern browser other than Internet Explorer. Tested
+# and working are Firefox, Chrome, Safari, and Opera.
+# Note: For IE 9+ you need to set HTML_FILE_EXTENSION to xhtml in order to make
+# the SVG files visible. Older versions of IE do not have SVG support.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+INTERACTIVE_SVG = NO
+
+# The DOT_PATH tag can be used to specify the path where the dot tool can be
+# found. If left blank, it is assumed the dot tool can be found in the path.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_PATH =
+
+# The DOTFILE_DIRS tag can be used to specify one or more directories that
+# contain dot files that are included in the documentation (see the \dotfile
+# command).
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOTFILE_DIRS =
+
+# The MSCFILE_DIRS tag can be used to specify one or more directories that
+# contain msc files that are included in the documentation (see the \mscfile
+# command).
+
+MSCFILE_DIRS =
+
+# The DIAFILE_DIRS tag can be used to specify one or more directories that
+# contain dia files that are included in the documentation (see the \diafile
+# command).
+
+DIAFILE_DIRS =
+
+# When using plantuml, the PLANTUML_JAR_PATH tag should be used to specify the
+# path where java can find the plantuml.jar file. If left blank, it is assumed
+# PlantUML is not used or called during a preprocessing step. Doxygen will
+# generate a warning when it encounters a \startuml command in this case and
+# will not generate output for the diagram.
+
+PLANTUML_JAR_PATH =
+
+# When using plantuml, the specified paths are searched for files specified by
+# the !include statement in a plantuml block.
+
+PLANTUML_INCLUDE_PATH =
+
+# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of nodes
+# that will be shown in the graph. If the number of nodes in a graph becomes
+# larger than this value, doxygen will truncate the graph, which is visualized
+# by representing a node as a red box. Note that doxygen if the number of direct
+# children of the root node in a graph is already larger than
+# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note that
+# the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH.
+# Minimum value: 0, maximum value: 10000, default value: 50.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_GRAPH_MAX_NODES = 50
+
+# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the graphs
+# generated by dot. A depth value of 3 means that only nodes reachable from the
+# root by following a path via at most 3 edges will be shown. Nodes that lay
+# further from the root node will be omitted. Note that setting this option to 1
+# or 2 may greatly reduce the computation time needed for large code bases. Also
+# note that the size of a graph can be further restricted by
+# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction.
+# Minimum value: 0, maximum value: 1000, default value: 0.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+MAX_DOT_GRAPH_DEPTH = 0
+
+# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent
+# background. This is disabled by default, because dot on Windows does not seem
+# to support this out of the box.
+#
+# Warning: Depending on the platform used, enabling this option may lead to
+# badly anti-aliased labels on the edges of a graph (i.e. they become hard to
+# read).
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_TRANSPARENT = NO
+
+# Set the DOT_MULTI_TARGETS tag to YES to allow dot to generate multiple output
+# files in one run (i.e. multiple -o and -T options on the command line). This
+# makes dot run faster, but since only newer versions of dot (>1.8.10) support
+# this, this feature is disabled by default.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_MULTI_TARGETS = NO
+
+# If the GENERATE_LEGEND tag is set to YES doxygen will generate a legend page
+# explaining the meaning of the various boxes and arrows in the dot generated
+# graphs.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+GENERATE_LEGEND = YES
+
+# If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate dot
+# files that are used to generate the various graphs.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_CLEANUP = YES
diff --git a/extras/libmemif/examples/example_setup_doc.md b/extras/libmemif/examples/example_setup_doc.md
new file mode 100644
index 00000000..89a0b10e
--- /dev/null
+++ b/extras/libmemif/examples/example_setup_doc.md
@@ -0,0 +1,207 @@
+## Example setup {#libmemif_example_setup_doc}
+
+#### VPP-memif master icmp_responder slave
+
+> Libmemif example app(s) use memif default socket file: `/run/vpp/memif.sock`.
+
+Run VPP and icmpr-epoll example (default example when running in container).
+
+> Other examples work similar to icmpr-epoll. Brief explanation can be found in @ref libmemif_examples_doc .
+
+VPP-side config:
+```
+DBGvpp# create memif id 0 master
+DBGvpp# set int state memif0/0 up
+DBGvpp# set int ip address memif0/0 192.168.1.1/24
+```
+icmpr-epoll:
+```
+conn 0 0
+```
+Memif in slave mode will try to connect every 2 seconds. If connection establishment is successfull, a message will show.
+```
+INFO: memif connected!
+```
+> Error messages like "unmatched interface id" are printed only in debug mode.
+
+Check connected status.
+Use show command in icmpr-epoll:
+```
+show
+MEMIF DETAILS
+==============================
+interface index: 0
+ interface ip: 192.168.1.2
+ interface name: memif_connection
+ app name: ICMP_Responder
+ remote interface name: memif0/0
+ remote app name: VPP 17.10-rc0~132-g62f9cdd
+ id: 0
+ secret:
+ role: slave
+ mode: ethernet
+ socket filename: /run/vpp/memif.sock
+ rx queues:
+ queue id: 0
+ ring size: 1024
+ buffer size: 2048
+ tx queues:
+ queue id: 0
+ ring size: 1024
+ buffer size: 2048
+ link: up
+interface index: 1
+ no connection
+
+```
+Use sh memif command in VPP:
+```
+DBGvpp# sh memif
+interface memif0/0
+ remote-name "ICMP_Responder"
+ remote-interface "memif_connection"
+ id 0 mode ethernet file /run/vpp/memif.sock
+ flags admin-up connected
+ listener-fd 12 conn-fd 13
+ num-s2m-rings 1 num-m2s-rings 1 buffer-size 0
+ master-to-slave ring 0:
+ region 0 offset 32896 ring-size 1024 int-fd 16
+ head 0 tail 0 flags 0x0000 interrupts 0
+ master-to-slave ring 0:
+ region 0 offset 0 ring-size 1024 int-fd 15
+ head 0 tail 0 flags 0x0001 interrupts 0
+```
+
+Send ping from VPP to icmpr-epoll:
+```
+DBGvpp# ping 192.168.1.2
+64 bytes from 192.168.1.2: icmp_seq=2 ttl=64 time=.1888 ms
+64 bytes from 192.168.1.2: icmp_seq=3 ttl=64 time=.1985 ms
+64 bytes from 192.168.1.2: icmp_seq=4 ttl=64 time=.1813 ms
+64 bytes from 192.168.1.2: icmp_seq=5 ttl=64 time=.1929 ms
+
+Statistics: 5 sent, 4 received, 20% packet loss
+```
+#### multiple queues VPP-memif slave icmp_responder master
+
+Run icmpr-epoll as in previous example setup.
+Run VPP with startup conf, enabling 2 worker threads.
+Example startup.conf:
+```
+unix {
+ interactive
+ nodaemon
+ full-coredump
+}
+
+cpu {
+ workers 2
+}
+```
+VPP-side config:
+```
+DBGvpp# create memif id 0 slave rx-queues 2 tx-queues 2
+DBGvpp# set int state memif0/0 up
+DBGvpp# set int ip address memif0/0 192.168.1.1/24
+```
+icmpr-epoll:
+```
+conn 0 1
+```
+When connection is established a message will print:
+```
+INFO: memif connected!
+```
+> Error messages like "unmatched interface id" are printed only in debug mode.
+
+Check connected status.
+Use show command in icmpr-epoll:
+```
+show
+MEMIF DETAILS
+==============================
+interface index: 0
+ interface ip: 192.168.1.2
+ interface name: memif_connection
+ app name: ICMP_Responder
+ remote interface name: memif0/0
+ remote app name: VPP 17.10-rc0~132-g62f9cdd
+ id: 0
+ secret:
+ role: master
+ mode: ethernet
+ socket filename: /run/vpp/memif.sock
+ rx queues:
+ queue id: 0
+ ring size: 1024
+ buffer size: 2048
+ queue id: 1
+ ring size: 1024
+ buffer size: 2048
+ tx queues:
+ queue id: 0
+ ring size: 1024
+ buffer size: 2048
+ queue id: 1
+ ring size: 1024
+ buffer size: 2048
+ link: up
+interface index: 1
+ no connection
+
+```
+Use sh memif command in VPP:
+```
+DBGvpp# sh memif
+interface memif0/0
+ remote-name "ICMP_Responder"
+ remote-interface "memif_connection"
+ id 0 mode ethernet file /run/vpp/memif.sock
+ flags admin-up slave connected
+ listener-fd -1 conn-fd 12
+ num-s2m-rings 2 num-m2s-rings 2 buffer-size 2048
+ slave-to-master ring 0:
+ region 0 offset 0 ring-size 1024 int-fd 14
+ head 0 tail 0 flags 0x0000 interrupts 0
+ slave-to-master ring 1:
+ region 0 offset 32896 ring-size 1024 int-fd 15
+ head 0 tail 0 flags 0x0000 interrupts 0
+ slave-to-master ring 0:
+ region 0 offset 65792 ring-size 1024 int-fd 16
+ head 0 tail 0 flags 0x0001 interrupts 0
+ slave-to-master ring 1:
+ region 0 offset 98688 ring-size 1024 int-fd 17
+ head 0 tail 0 flags 0x0001 interrupts 0
+
+```
+Send ping from VPP to icmpr-epoll:
+```
+DBGvpp# ping 192.168.1.2
+64 bytes from 192.168.1.2: icmp_seq=2 ttl=64 time=.1439 ms
+64 bytes from 192.168.1.2: icmp_seq=3 ttl=64 time=.2184 ms
+64 bytes from 192.168.1.2: icmp_seq=4 ttl=64 time=.1458 ms
+64 bytes from 192.168.1.2: icmp_seq=5 ttl=64 time=.1687 ms
+
+Statistics: 5 sent, 4 received, 20% packet loss
+```
+
+#### icmp_responder master icmp_responder slave
+
+> Example apps can only repond to ping. This setup creates connection between two applications using libmemif. Traffic functionality is the same as when connection to VPP. App can receive ARP/ICMP request and transmit response, but can not send ARP/ICMP request.
+
+Run two instances of icmpr-epoll example.
+> If not running in container, make sure folder /run/vpp/ exists before creating memif master.
+Instance 1 will be in master mode, instance 2 in slave mode.
+instance 1:
+```
+conn 0 1
+```
+instance 2:
+```
+conn 0 0
+```
+In 2 seconds, both instances should print connected! message:
+```
+INFO: memif connected!
+```
+Check peer interface names using show command.
diff --git a/extras/libmemif/examples/examples_doc.md b/extras/libmemif/examples/examples_doc.md
new file mode 100644
index 00000000..11937c57
--- /dev/null
+++ b/extras/libmemif/examples/examples_doc.md
@@ -0,0 +1,18 @@
+## Examples {#libmemif_examples_doc}
+
+After build, root folder will contain scripts linking binary examples with library (same name as example apps). These scripts can be executed to run example apps without installing the library. Example apps binaries can be found in _libs_ filder. To run binaries directly, make sure that libmemif library is installed.
+
+#### Run in container
+
+`ligato/libmemif-sample-service` image contains built and installed libmemf. To run different examples, override docker CMD to start container in bash:
+
+```
+# docker run -it --entrypoint=/bin/bash -i --rm --name icmp-responder --hostname icmp-responder --privileged -v "/run/vpp/:/run/vpp/" ligato/libmemif-sample-service
+```
+Current WORKDIR is set to root repository directory. Example apps can be run from this directory (a script linking binary with library), or browse to `./.libs` folder and execute binary directly.
+
+Example app | Description
+------------|------------
+@ref extras/libmemif/examples/icmp_responder | Simplest implementaion. Event polling is handled by libmemif. Single memif conenction in slave mode is created (id 0). Use Ctrl + C to exit app. Memif receive mode: interrupt.
+@ref extras/libmemif/examples/icmp_responder-epoll (run in container by default) | Supports multiple connections and master mode. User can create/delete connections, set ip addresses, print connection information. @ref libmemif_example_setup_doc contains instructions on basic connection use cases setups. Memif receive mode: interrupt. App provides functionality to disable interrupts for specified queue/s for testing purposes. Polling mode is not implemented in this example.
+@ref extras/libmemif/examples/icmp_responder-mt) | Multi-thread example, very similar to icmpr-epoll. Packets are handled in threads assigned to specific queues. Slave mode only. Memif receive mode: polling (memif_rx_poll function), interrupt (memif_rx_interrupt function). Receive modes differ per queue.
diff --git a/extras/libmemif/examples/icmp_responder-epoll/main.c b/extras/libmemif/examples/icmp_responder-epoll/main.c
new file mode 100644
index 00000000..cff944f9
--- /dev/null
+++ b/extras/libmemif/examples/icmp_responder-epoll/main.c
@@ -0,0 +1,791 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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 <stdlib.h>
+#include <stdint.h>
+#include <net/if.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/uio.h>
+#include <sys/mman.h>
+#include <sys/prctl.h>
+#include <inttypes.h>
+#include <string.h>
+#include <stdio.h>
+#include <netdb.h>
+#include <linux/ip.h>
+#include <linux/icmp.h>
+#include <arpa/inet.h>
+#include <stdlib.h>
+#include <netinet/if_ether.h>
+#include <net/if_arp.h>
+#include <asm/byteorder.h>
+#include <byteswap.h>
+#include <string.h>
+#include <sys/epoll.h>
+#include <errno.h>
+#include <unistd.h>
+#include <signal.h>
+
+#include <libmemif.h>
+#include <icmp_proto.h>
+
+#define APP_NAME "ICMP_Responder"
+#define IF_NAME "memif_connection"
+
+
+#ifdef ICMP_DBG
+#define DBG(...) do { \
+ printf (APP_NAME":%s:%d: ", __func__, __LINE__); \
+ printf (__VA_ARGS__); \
+ printf ("\n"); \
+ } while (0)
+#else
+#define DBG(...)
+#endif
+
+#define INFO(...) do { \
+ printf ("INFO: "__VA_ARGS__); \
+ printf ("\n"); \
+ } while (0)
+
+/* maximum tx/rx memif buffers */
+#define MAX_MEMIF_BUFS 256
+#define MAX_CONNS 50
+
+int epfd;
+
+typedef struct
+{
+ uint16_t index;
+ /* memif conenction handle */
+ memif_conn_handle_t conn;
+ /* tx buffers */
+ memif_buffer_t *tx_bufs;
+ /* allocated tx buffers counter */
+ /* number of tx buffers pointing to shared memory */
+ uint16_t tx_buf_num;
+ /* rx buffers */
+ memif_buffer_t *rx_bufs;
+ /* allcoated rx buffers counter */
+ /* number of rx buffers pointing to shared memory */
+ uint16_t rx_buf_num;
+ /* interface ip address */
+ uint8_t ip_addr[4];
+} memif_connection_t;
+
+memif_connection_t memif_connection[MAX_CONNS];
+long ctx[MAX_CONNS];
+
+/* print details for all memif connections */
+static void
+print_memif_details ()
+{
+ memif_details_t md;
+ ssize_t buflen;
+ char *buf;
+ int err, i, e;
+ buflen = 2048;
+ buf = malloc (buflen);
+ printf ("MEMIF DETAILS\n");
+ printf ("==============================\n");
+ for (i = 0; i < MAX_CONNS; i++)
+ {
+ memif_connection_t *c = &memif_connection[i];
+
+ memset (&md, 0, sizeof (md));
+ memset (buf, 0, buflen);
+
+ err = memif_get_details (c->conn, &md, buf, buflen);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ if (err != MEMIF_ERR_NOCONN)
+ INFO ("%s", memif_strerror (err));
+ continue;
+ }
+
+ printf ("interface index: %d\n", i);
+
+ printf ("\tinterface ip: %u.%u.%u.%u\n",
+ c->ip_addr[0], c->ip_addr[1], c->ip_addr[2], c->ip_addr[3]);
+ printf ("\tinterface name: %s\n", (char *) md.if_name);
+ printf ("\tapp name: %s\n", (char *) md.inst_name);
+ printf ("\tremote interface name: %s\n", (char *) md.remote_if_name);
+ printf ("\tremote app name: %s\n", (char *) md.remote_inst_name);
+ printf ("\tid: %u\n", md.id);
+ printf ("\tsecret: %s\n", (char *) md.secret);
+ printf ("\trole: ");
+ if (md.role)
+ printf ("slave\n");
+ else
+ printf ("master\n");
+ printf ("\tmode: ");
+ switch (md.mode)
+ {
+ case 0:
+ printf ("ethernet\n");
+ break;
+ case 1:
+ printf ("ip\n");
+ break;
+ case 2:
+ printf ("punt/inject\n");
+ break;
+ default:
+ printf ("unknown\n");
+ break;
+ }
+ printf ("\tsocket filename: %s\n", (char *) md.socket_filename);
+ printf ("\trx queues:\n");
+ for (e = 0; e < md.rx_queues_num; e++)
+ {
+ printf ("\t\tqueue id: %u\n", md.rx_queues[e].qid);
+ printf ("\t\tring size: %u\n", md.rx_queues[e].ring_size);
+ printf ("\t\tbuffer size: %u\n", md.rx_queues[e].buffer_size);
+ }
+ printf ("\ttx queues:\n");
+ for (e = 0; e < md.tx_queues_num; e++)
+ {
+ printf ("\t\tqueue id: %u\n", md.tx_queues[e].qid);
+ printf ("\t\tring size: %u\n", md.tx_queues[e].ring_size);
+ printf ("\t\tbuffer size: %u\n", md.tx_queues[e].buffer_size);
+ }
+ printf ("\tlink: ");
+ if (md.link_up_down)
+ printf ("up\n");
+ else
+ printf ("down\n");
+ }
+ free (buf);
+}
+
+int
+add_epoll_fd (int fd, uint32_t events)
+{
+ if (fd < 0)
+ {
+ DBG ("invalid fd %d", fd);
+ return -1;
+ }
+ struct epoll_event evt;
+ memset (&evt, 0, sizeof (evt));
+ evt.events = events;
+ evt.data.fd = fd;
+ if (epoll_ctl (epfd, EPOLL_CTL_ADD, fd, &evt) < 0)
+ {
+ DBG ("epoll_ctl: %s fd %d", strerror (errno), fd);
+ return -1;
+ }
+ DBG ("fd %d added to epoll", fd);
+ return 0;
+}
+
+int
+mod_epoll_fd (int fd, uint32_t events)
+{
+ if (fd < 0)
+ {
+ DBG ("invalid fd %d", fd);
+ return -1;
+ }
+ struct epoll_event evt;
+ memset (&evt, 0, sizeof (evt));
+ evt.events = events;
+ evt.data.fd = fd;
+ if (epoll_ctl (epfd, EPOLL_CTL_MOD, fd, &evt) < 0)
+ {
+ DBG ("epoll_ctl: %s fd %d", strerror (errno), fd);
+ return -1;
+ }
+ DBG ("fd %d moddified on epoll", fd);
+ return 0;
+}
+
+int
+del_epoll_fd (int fd)
+{
+ if (fd < 0)
+ {
+ DBG ("invalid fd %d", fd);
+ return -1;
+ }
+ struct epoll_event evt;
+ memset (&evt, 0, sizeof (evt));
+ if (epoll_ctl (epfd, EPOLL_CTL_DEL, fd, &evt) < 0)
+ {
+ DBG ("epoll_ctl: %s fd %d", strerror (errno), fd);
+ return -1;
+ }
+ DBG ("fd %d removed from epoll", fd);
+ return 0;
+}
+
+/* informs user about connected status. private_ctx is used by user to identify connection
+ (multiple connections WIP) */
+int
+on_connect (memif_conn_handle_t conn, void *private_ctx)
+{
+ INFO ("memif connected!");
+ return 0;
+}
+
+/* informs user about disconnected status. private_ctx is used by user to identify connection
+ (multiple connections WIP) */
+int
+on_disconnect (memif_conn_handle_t conn, void *private_ctx)
+{
+ INFO ("memif disconnected!");
+ return 0;
+}
+
+/* user needs to watch new fd or stop watching fd that is about to be closed.
+ control fd will be modified during connection establishment to minimize CPU usage */
+int
+control_fd_update (int fd, uint8_t events)
+{
+ /* convert memif event definitions to epoll events */
+ if (events & MEMIF_FD_EVENT_DEL)
+ return del_epoll_fd (fd);
+
+ uint32_t evt = 0;
+ if (events & MEMIF_FD_EVENT_READ)
+ evt |= EPOLLIN;
+ if (events & MEMIF_FD_EVENT_WRITE)
+ evt |= EPOLLOUT;
+
+ if (events & MEMIF_FD_EVENT_MOD)
+ return mod_epoll_fd (fd, evt);
+
+ return add_epoll_fd (fd, evt);
+}
+
+int
+icmpr_buffer_alloc (long index, long n, uint16_t qid)
+{
+ memif_connection_t *c = &memif_connection[index];
+ int err;
+ uint16_t r;
+ /* set data pointer to shared memory and set buffer_len to shared mmeory buffer len */
+ err = memif_buffer_alloc (c->conn, qid, c->tx_bufs, n, &r, 0);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("memif_buffer_alloc: %s", memif_strerror (err));
+ c->tx_buf_num += r;
+ return -1;
+ }
+ c->tx_buf_num += r;
+ DBG ("allocated %d/%ld buffers, %u free buffers", r, n,
+ MAX_MEMIF_BUFS - c->tx_buf_num);
+ return 0;
+}
+
+int
+icmpr_tx_burst (long index, uint16_t qid)
+{
+ memif_connection_t *c = &memif_connection[index];
+ int err;
+ uint16_t r;
+ /* inform peer memif interface about data in shared memory buffers */
+ /* mark memif buffers as free */
+ err = memif_tx_burst (c->conn, qid, c->tx_bufs, c->tx_buf_num, &r);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_tx_burst: %s", memif_strerror (err));
+ DBG ("tx: %d/%u", r, c->tx_buf_num);
+ c->tx_buf_num -= r;
+ return 0;
+}
+
+/* called when event is polled on interrupt file descriptor.
+ there are packets in shared memory ready to be received */
+int
+on_interrupt (memif_conn_handle_t conn, void *private_ctx, uint16_t qid)
+{
+ long index = *((long *) private_ctx);
+ memif_connection_t *c = &memif_connection[index];
+ if (c->index != index)
+ {
+ INFO ("invalid context: %ld/%u", index, c->index);
+ return 0;
+ }
+ int err;
+ uint16_t rx;
+ uint16_t fb;
+ /* receive data from shared memory buffers */
+ err = memif_rx_burst (c->conn, qid, c->rx_bufs, MAX_MEMIF_BUFS, &rx);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("memif_rx_burst: %s", memif_strerror (err));
+ c->rx_buf_num += rx;
+ goto error;
+ }
+ c->rx_buf_num += rx;
+
+ DBG ("received %d buffers. %u/%u alloc/free buffers",
+ rx, c->rx_buf_num, MAX_MEMIF_BUFS - c->rx_buf_num);
+
+ if (icmpr_buffer_alloc (index, rx, qid) < 0)
+ {
+ INFO ("buffer_alloc error");
+ goto error;
+ }
+ int i;
+ for (i = 0; i < rx; i++)
+ {
+ resolve_packet ((void *) (c->rx_bufs + i)->data,
+ (c->rx_bufs + i)->data_len,
+ (void *) (c->tx_bufs + i)->data,
+ &(c->tx_bufs + i)->data_len, c->ip_addr);
+ }
+
+ /* mark memif buffers and shared memory buffers as free */
+ err = memif_buffer_free (c->conn, qid, c->rx_bufs, rx, &fb);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_buffer_free: %s", memif_strerror (err));
+ c->rx_buf_num -= fb;
+
+ DBG ("freed %d buffers. %u/%u alloc/free buffers",
+ fb, c->rx_buf_num, MAX_MEMIF_BUFS - c->rx_buf_num);
+
+ icmpr_tx_burst (index, qid);
+
+ return 0;
+
+error:
+ err = memif_buffer_free (c->conn, qid, c->rx_bufs, rx, &fb);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_buffer_free: %s", memif_strerror (err));
+ c->rx_buf_num -= fb;
+ DBG ("freed %d buffers. %u/%u alloc/free buffers",
+ fb, c->rx_buf_num, MAX_MEMIF_BUFS - c->rx_buf_num);
+ return 0;
+}
+
+int
+icmpr_memif_create (long index, long mode)
+{
+ if (index >= MAX_CONNS)
+ {
+ INFO ("connection array overflow");
+ return 0;
+ }
+ if (index < 0)
+ {
+ INFO ("don't even try...");
+ return 0;
+ }
+ memif_connection_t *c = &memif_connection[index];
+
+ /* setting memif connection arguments */
+ memif_conn_args_t args;
+ int fd = -1;
+ memset (&args, 0, sizeof (args));
+ args.is_master = mode;
+ args.log2_ring_size = 10;
+ args.buffer_size = 2048;
+ args.num_s2m_rings = 2;
+ args.num_m2s_rings = 2;
+ strncpy ((char *) args.interface_name, IF_NAME, strlen (IF_NAME));
+ strncpy ((char *) args.instance_name, APP_NAME, strlen (APP_NAME));
+ args.mode = 0;
+ /* socket filename is not specified, because this app is supposed to
+ connect to VPP over memif. so default socket filename will be used */
+ /* default socketfile = /run/vpp/memif.sock */
+
+ args.interface_id = index;
+ /* last argument for memif_create (void * private_ctx) is used by user
+ to identify connection. this context is returned with callbacks */
+ int err = memif_create (&c->conn,
+ &args, on_connect, on_disconnect, on_interrupt,
+ &ctx[index]);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("memif_create: %s", memif_strerror (err));
+ return 0;
+ }
+
+ c->index = index;
+ /* alloc memif buffers */
+ c->rx_buf_num = 0;
+ c->rx_bufs =
+ (memif_buffer_t *) malloc (sizeof (memif_buffer_t) * MAX_MEMIF_BUFS);
+ c->tx_buf_num = 0;
+ c->tx_bufs =
+ (memif_buffer_t *) malloc (sizeof (memif_buffer_t) * MAX_MEMIF_BUFS);
+
+ c->ip_addr[0] = 192;
+ c->ip_addr[1] = 168;
+ c->ip_addr[2] = c->index + 1;
+ c->ip_addr[3] = 2;
+ return 0;
+}
+
+int
+icmpr_memif_delete (long index)
+{
+ if (index >= MAX_CONNS)
+ {
+ INFO ("connection array overflow");
+ return 0;
+ }
+ if (index < 0)
+ {
+ INFO ("don't even try...");
+ return 0;
+ }
+ memif_connection_t *c = &memif_connection[index];
+
+ if (c->rx_bufs)
+ free (c->rx_bufs);
+ c->rx_bufs = NULL;
+ c->rx_buf_num = 0;
+ if (c->tx_bufs)
+ free (c->tx_bufs);
+ c->tx_bufs = NULL;
+ c->tx_buf_num = 0;
+
+ int err;
+ /* disconenct then delete memif connection */
+ err = memif_delete (&c->conn);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_delete: %s", memif_strerror (err));
+ if (c->conn != NULL)
+ INFO ("memif delete fail");
+ return 0;
+}
+
+void
+print_help ()
+{
+ printf ("LIBMEMIF EXAMPLE APP: %s", APP_NAME);
+#ifdef ICMP_DBG
+ printf (" (debug)");
+#endif
+ printf ("\n");
+ printf ("==============================\n");
+ printf ("libmemif version: %s", LIBMEMIF_VERSION);
+#ifdef MEMIF_DBG
+ printf (" (debug)");
+#endif
+ printf ("\n");
+ printf ("memif version: %d\n", MEMIF_VERSION);
+ printf ("commands:\n");
+ printf ("\thelp - prints this help\n");
+ printf ("\texit - exit app\n");
+ printf
+ ("\tconn <index> <mode> - create memif. index is also used as interface id, mode 0 = slave 1 = master\n");
+ printf ("\tdel <index> - delete memif\n");
+ printf ("\tshow - show connection details\n");
+ printf ("\tip-set <index> <ip-addr> - set interface ip address\n");
+ printf
+ ("\trx-mode <index> <qid> <polling|interrupt> - set queue rx mode\n");
+}
+
+int
+icmpr_free ()
+{
+ /* application cleanup */
+ int err;
+ long i;
+ for (i = 0; i < MAX_CONNS; i++)
+ {
+ memif_connection_t *c = &memif_connection[i];
+ if (c->conn)
+ icmpr_memif_delete (i);
+ }
+
+ err = memif_cleanup ();
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_delete: %s", memif_strerror (err));
+
+ return 0;
+}
+
+int
+icmpr_set_ip (long index, char *ip)
+{
+ if (index >= MAX_CONNS)
+ {
+ INFO ("connection array overflow");
+ return 0;
+ }
+ if (index < 0)
+ {
+ INFO ("don't even try...");
+ return 0;
+ }
+ memif_connection_t *c = &memif_connection[index];
+ if (c->conn == NULL)
+ {
+ INFO ("no connection at index %ld", index);
+ return 0;
+ }
+
+ char *end;
+ char *ui;
+ uint8_t tmp[4];
+ ui = strtok (ip, ".");
+ if (ui == NULL)
+ goto error;
+ tmp[0] = strtol (ui, &end, 10);
+
+ ui = strtok (NULL, ".");
+ if (ui == NULL)
+ goto error;
+ tmp[1] = strtol (ui, &end, 10);
+
+ ui = strtok (NULL, ".");
+ if (ui == NULL)
+ goto error;
+ tmp[2] = strtol (ui, &end, 10);
+
+ ui = strtok (NULL, ".");
+ if (ui == NULL)
+ goto error;
+ tmp[3] = strtol (ui, &end, 10);
+
+ c->ip_addr[0] = tmp[0];
+ c->ip_addr[1] = tmp[1];
+ c->ip_addr[2] = tmp[2];
+ c->ip_addr[3] = tmp[3];
+
+ INFO ("memif %ld ip address set to %u.%u.%u.%u",
+ index, c->ip_addr[0], c->ip_addr[1], c->ip_addr[2], c->ip_addr[3]);
+
+ return 0;
+
+error:
+ INFO ("invalid ip address");
+ return 0;
+}
+
+int
+icmpr_set_rx_mode (long index, long qid, char *mode)
+{
+ if (index >= MAX_CONNS)
+ {
+ INFO ("connection array overflow");
+ return 0;
+ }
+ if (index < 0)
+ {
+ INFO ("don't even try...");
+ return 0;
+ }
+ memif_connection_t *c = &memif_connection[index];
+
+ if (c->conn == NULL)
+ {
+ INFO ("no connection at index %ld", index);
+ return 0;
+ }
+
+ if (strncmp (mode, "interrupt", 9) == 0)
+ {
+ memif_set_rx_mode (c->conn, MEMIF_RX_MODE_INTERRUPT, qid);
+ }
+
+ else if (strncmp (mode, "polling", 7) == 0)
+ {
+ memif_set_rx_mode (c->conn, MEMIF_RX_MODE_POLLING, qid);
+ }
+ else
+ INFO ("expected rx mode <interrupt|polling>");
+ return 0;
+}
+
+int
+user_input_handler ()
+{
+ int i;
+ char *in = (char *) malloc (256);
+ char *ui = fgets (in, 256, stdin);
+ char *end;
+ long a;
+ if (in[0] == '\n')
+ goto done;
+ ui = strtok (in, " ");
+ if (strncmp (ui, "exit", 4) == 0)
+ {
+ free (in);
+ icmpr_free ();
+ exit (EXIT_SUCCESS);
+ }
+ else if (strncmp (ui, "help", 4) == 0)
+ {
+ print_help ();
+ goto done;
+ }
+ else if (strncmp (ui, "conn", 4) == 0)
+ {
+ ui = strtok (NULL, " ");
+ if (ui != NULL)
+ a = strtol (ui, &end, 10);
+ else
+ {
+ INFO ("expected id");
+ goto done;
+ }
+ ui = strtok (NULL, " ");
+ if (ui != NULL)
+ icmpr_memif_create (a, strtol (ui, &end, 10));
+ else
+ INFO ("expected mode <0|1>");
+ goto done;
+ }
+ else if (strncmp (ui, "del", 3) == 0)
+ {
+ ui = strtok (NULL, " ");
+ if (ui != NULL)
+ icmpr_memif_delete (strtol (ui, &end, 10));
+ else
+ INFO ("expected id");
+ goto done;
+ }
+ else if (strncmp (ui, "show", 4) == 0)
+ {
+ print_memif_details ();
+ goto done;
+ }
+ else if (strncmp (ui, "ip-set", 6) == 0)
+ {
+ ui = strtok (NULL, " ");
+ if (ui != NULL)
+ icmpr_set_ip (strtol (ui, &end, 10), strtok (NULL, " "));
+ else
+ INFO ("expected id");
+ goto done;
+ }
+ else if (strncmp (ui, "rx-mode", 7) == 0)
+ {
+ ui = strtok (NULL, " ");
+ if (ui != NULL)
+ a = strtol (ui, &end, 10);
+ else
+ {
+ INFO ("expected id");
+ goto done;
+ }
+ ui = strtok (NULL, " ");
+ if (ui != NULL)
+ icmpr_set_rx_mode (a, strtol (ui, &end, 10), strtok (NULL, " "));
+ else
+ INFO ("expected qid");
+ goto done;
+ }
+ else
+ {
+ DBG ("unknown command: %s", ui);
+ goto done;
+ }
+
+ return 0;
+done:
+ free (in);
+ return 0;
+}
+
+int
+poll_event (int timeout)
+{
+ struct epoll_event evt, *e;
+ int app_err = 0, memif_err = 0, en = 0;
+ int tmp, nfd;
+ uint32_t events = 0;
+ memset (&evt, 0, sizeof (evt));
+ evt.events = EPOLLIN | EPOLLOUT;
+ sigset_t sigset;
+ sigemptyset (&sigset);
+ en = epoll_pwait (epfd, &evt, 1, timeout, &sigset);
+ if (en < 0)
+ {
+ DBG ("epoll_pwait: %s", strerror (errno));
+ return -1;
+ }
+ if (en > 0)
+ {
+ /* this app does not use any other file descriptors than stds and memif control fds */
+ if (evt.data.fd > 2)
+ {
+ /* event of memif control fd */
+ /* convert epolle events to memif events */
+ if (evt.events & EPOLLIN)
+ events |= MEMIF_FD_EVENT_READ;
+ if (evt.events & EPOLLOUT)
+ events |= MEMIF_FD_EVENT_WRITE;
+ if (evt.events & EPOLLERR)
+ events |= MEMIF_FD_EVENT_ERROR;
+ memif_err = memif_control_fd_handler (evt.data.fd, events);
+ if (memif_err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_control_fd_handler: %s", memif_strerror (memif_err));
+ }
+ else if (evt.data.fd == 0)
+ {
+ app_err = user_input_handler ();
+ }
+ else
+ {
+ DBG ("unexpected event at memif_epfd. fd %d", evt.data.fd);
+ }
+ }
+
+ if ((app_err < 0) || (memif_err < 0))
+ {
+ if (app_err < 0)
+ DBG ("user input handler error");
+ if (memif_err < 0)
+ DBG ("memif control fd handler error");
+ return -1;
+ }
+
+ return 0;
+}
+
+int
+main ()
+{
+ epfd = epoll_create (1);
+ add_epoll_fd (0, EPOLLIN);
+
+ /* initialize memory interface */
+ int err, i;
+ /* if valid callback is passed as argument, fd event polling will be done by user
+ all file descriptors and events will be passed to user in this callback */
+ /* if callback is set to NULL libmemif will handle fd event polling */
+ err = memif_init (control_fd_update, APP_NAME);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_init: %s", memif_strerror (err));
+
+ for (i = 0; i < MAX_CONNS; i++)
+ {
+ memif_connection[i].conn = NULL;
+ ctx[i] = i;
+ }
+
+ print_help ();
+
+ /* main loop */
+ while (1)
+ {
+ if (poll_event (-1) < 0)
+ {
+ DBG ("poll_event error!");
+ }
+ }
+}
diff --git a/extras/libmemif/examples/icmp_responder-mt/main.c b/extras/libmemif/examples/icmp_responder-mt/main.c
new file mode 100644
index 00000000..c47fc53d
--- /dev/null
+++ b/extras/libmemif/examples/icmp_responder-mt/main.c
@@ -0,0 +1,921 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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 <stdlib.h>
+#include <stdint.h>
+#include <net/if.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/uio.h>
+#include <sys/mman.h>
+#include <sys/prctl.h>
+#include <inttypes.h>
+#include <string.h>
+#include <stdio.h>
+#include <netdb.h>
+#include <linux/ip.h>
+#include <linux/icmp.h>
+#include <arpa/inet.h>
+#include <stdlib.h>
+#include <netinet/if_ether.h>
+#include <net/if_arp.h>
+#include <asm/byteorder.h>
+#include <byteswap.h>
+#include <string.h>
+#include <sys/epoll.h>
+#include <errno.h>
+#include <unistd.h>
+#include <signal.h>
+#include <pthread.h>
+
+#include <libmemif.h>
+#include <icmp_proto.h>
+
+#define APP_NAME "ICMP_Responder"
+#define IF_NAME "memif_connection"
+
+
+#ifdef ICMP_DBG
+#define DBG(...) do { \
+ printf (APP_NAME":%s:%d: ", __func__, __LINE__); \
+ printf (__VA_ARGS__); \
+ printf ("\n"); \
+ } while (0)
+#else
+#define DBG(...)
+#endif
+
+#define INFO(...) do { \
+ printf ("INFO: "__VA_ARGS__); \
+ printf ("\n"); \
+ } while (0)
+
+/* maximum tx/rx memif buffers */
+#define MAX_MEMIF_BUFS 256
+#define MAX_CONNS 50
+#define MAX_QUEUES 2
+#define MAX_THREADS ((MAX_CONNS) * (MAX_QUEUES))
+
+int main_epfd;
+
+typedef struct
+{
+ /* thread id */
+ uint8_t id;
+ /* memif connection index */
+ uint16_t index;
+ /* id of queue to be handled by thread */
+ uint8_t qid;
+ uint8_t isRunning;
+
+ uint16_t rx_buf_num;
+ uint16_t tx_buf_num;
+ memif_buffer_t *rx_bufs;
+ memif_buffer_t *tx_bufs;
+} memif_thread_data_t;
+
+typedef struct
+{
+ uint16_t index;
+ /* memif conenction handle */
+ memif_conn_handle_t conn;
+ /* interface ip address */
+ uint8_t ip_addr[4];
+ /* inform pthread about connection termination */
+ uint8_t pending_del;
+} memif_connection_t;
+
+memif_connection_t memif_connection[MAX_CONNS];
+long ctx[MAX_CONNS];
+
+/* thread data specific for each thread */
+memif_thread_data_t thread_data[MAX_THREADS];
+pthread_t thread[MAX_THREADS];
+
+void
+user_signal_handler (int sig)
+{
+ sig = sig;
+}
+
+static void
+print_memif_details ()
+{
+ memif_details_t md;
+ ssize_t buflen;
+ char *buf;
+ int err, i, e, ti;
+ buflen = 2048;
+ buf = malloc (buflen);
+ printf ("MEMIF DETAILS\n");
+ printf ("==============================\n");
+ for (i = 0; i < MAX_CONNS; i++)
+ {
+ memif_connection_t *c = &memif_connection[i];
+
+ memset (&md, 0, sizeof (md));
+ memset (buf, 0, buflen);
+
+ err = memif_get_details (c->conn, &md, buf, buflen);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ if (err != MEMIF_ERR_NOCONN)
+ INFO ("%s", memif_strerror (err));
+ continue;
+ }
+
+ printf ("interface index: %d\n", i);
+
+ printf ("\tinterface ip: %u.%u.%u.%u\n",
+ c->ip_addr[0], c->ip_addr[1], c->ip_addr[2], c->ip_addr[3]);
+ printf ("\tinterface name: %s\n", (char *) md.if_name);
+ printf ("\tapp name: %s\n", (char *) md.inst_name);
+ printf ("\tremote interface name: %s\n", (char *) md.remote_if_name);
+ printf ("\tremote app name: %s\n", (char *) md.remote_inst_name);
+ printf ("\tid: %u\n", md.id);
+ printf ("\tsecret: %s\n", (char *) md.secret);
+ printf ("\trole: ");
+ if (md.role)
+ printf ("slave\n");
+ else
+ printf ("master\n");
+ printf ("\tmode: ");
+ switch (md.mode)
+ {
+ case 0:
+ printf ("ethernet\n");
+ break;
+ case 1:
+ printf ("ip\n");
+ break;
+ case 2:
+ printf ("punt/inject\n");
+ break;
+ default:
+ printf ("unknown\n");
+ break;
+ }
+ printf ("\tsocket filename: %s\n", (char *) md.socket_filename);
+ printf ("\trx queues:\n");
+ for (e = 0; e < md.rx_queues_num; e++)
+ {
+ ti = (i * MAX_QUEUES) + e;
+ printf ("\tqueue id: %u\n", md.rx_queues[e].qid);
+ printf ("\t\tring size: %u\n", md.rx_queues[e].ring_size);
+ printf ("\t\tbuffer size: %u\n", md.rx_queues[e].buffer_size);
+ printf ("\t\tthread id: %u\n", thread_data[ti].id);
+ printf ("\t\tthread connection index: %u\n", thread_data[ti].index);
+ printf ("\t\tthread running: ");
+ if (thread_data[ti].isRunning)
+ printf ("yes\n");
+ else
+ printf ("no");
+ }
+ printf ("\ttx queues:\n");
+ for (e = 0; e < md.tx_queues_num; e++)
+ {
+ printf ("\tqueue id: %u\n", md.tx_queues[e].qid);
+ printf ("\t\tring size: %u\n", md.tx_queues[e].ring_size);
+ printf ("\t\tbuffer size: %u\n", md.tx_queues[e].buffer_size);
+ }
+ printf ("\tlink: ");
+ if (md.link_up_down)
+ printf ("up\n");
+ else
+ printf ("down\n");
+ }
+ free (buf);
+}
+
+int
+add_epoll_fd (int epfd, int fd, uint32_t events)
+{
+ if (fd < 0)
+ {
+ DBG ("invalid fd %d", fd);
+ return -1;
+ }
+ struct epoll_event evt;
+ memset (&evt, 0, sizeof (evt));
+ evt.events = events;
+ evt.data.fd = fd;
+ if (epoll_ctl (epfd, EPOLL_CTL_ADD, fd, &evt) < 0)
+ {
+ DBG ("epoll_ctl: %s fd %d", strerror (errno), fd);
+ return -1;
+ }
+ DBG ("fd %d added to epoll", fd);
+ return 0;
+}
+
+int
+mod_epoll_fd (int epfd, int fd, uint32_t events)
+{
+ if (fd < 0)
+ {
+ DBG ("invalid fd %d", fd);
+ return -1;
+ }
+ struct epoll_event evt;
+ memset (&evt, 0, sizeof (evt));
+ evt.events = events;
+ evt.data.fd = fd;
+ if (epoll_ctl (epfd, EPOLL_CTL_MOD, fd, &evt) < 0)
+ {
+ DBG ("epoll_ctl: %s fd %d", strerror (errno), fd);
+ return -1;
+ }
+ DBG ("fd %d moddified on epoll", fd);
+ return 0;
+}
+
+int
+del_epoll_fd (int epfd, int fd)
+{
+ if (fd < 0)
+ {
+ DBG ("invalid fd %d", fd);
+ return -1;
+ }
+ struct epoll_event evt;
+ memset (&evt, 0, sizeof (evt));
+ if (epoll_ctl (epfd, EPOLL_CTL_DEL, fd, &evt) < 0)
+ {
+ DBG ("epoll_ctl: %s fd %d", strerror (errno), fd);
+ return -1;
+ }
+ DBG ("fd %d removed from epoll", fd);
+ return 0;
+}
+
+void *
+memif_rx_poll (void *ptr)
+{
+ memif_thread_data_t *data = (memif_thread_data_t *) ptr;
+ memif_connection_t *c = &memif_connection[data->index];
+ int err;
+ uint16_t rx = 0, tx = 0, fb = 0;
+
+ data->rx_bufs = malloc (sizeof (memif_buffer_t) * MAX_MEMIF_BUFS);
+ data->tx_bufs = malloc (sizeof (memif_buffer_t) * MAX_MEMIF_BUFS);
+ data->rx_buf_num = 0;
+ data->tx_buf_num = 0;
+
+ data->isRunning = 1;
+ INFO ("pthread id %u starts in polling mode", data->id);
+
+ while (1)
+ {
+ if (c->pending_del)
+ goto close;
+
+ /* receive data from shared memory buffers */
+ err =
+ memif_rx_burst (c->conn, data->qid, data->rx_bufs, MAX_MEMIF_BUFS,
+ &rx);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("memif_rx_burst: %s", memif_strerror (err));
+ data->rx_buf_num += rx;
+ goto error;
+ }
+ data->rx_buf_num += rx;
+ if (rx == 0)
+ {
+ continue;
+ }
+
+ DBG ("thread id: %u", data->id);
+
+ DBG ("received %d buffers. %u/%u alloc/free buffers",
+ rx, data->rx_buf_num, MAX_MEMIF_BUFS - data->rx_buf_num);
+
+ err =
+ memif_buffer_alloc (c->conn, data->qid, data->tx_bufs,
+ data->rx_buf_num, &tx, 0);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("memif_buffer_alloc: %s", memif_strerror (err));
+ data->tx_buf_num += tx;
+ goto error;
+ }
+ data->tx_buf_num += tx;
+ DBG ("allocated %d/%d buffers, %u free buffers",
+ tx, data->rx_buf_num, MAX_MEMIF_BUFS - data->tx_buf_num);
+
+ int i;
+ for (i = 0; i < rx; i++)
+ {
+ resolve_packet ((void *) (data->rx_bufs + i)->data,
+ (data->rx_bufs + i)->data_len,
+ (void *) (data->tx_bufs + i)->data,
+ &(data->tx_bufs + i)->data_len, c->ip_addr);
+ }
+
+ /* mark memif buffers and shared memory buffers as free */
+ err = memif_buffer_free (c->conn, data->qid, data->rx_bufs, rx, &fb);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_buffer_free: %s", memif_strerror (err));
+ data->rx_buf_num -= fb;
+
+ DBG ("freed %d buffers. %u/%u alloc/free buffers",
+ fb, data->rx_buf_num, MAX_MEMIF_BUFS - data->rx_buf_num);
+
+ err =
+ memif_tx_burst (c->conn, data->qid, data->tx_bufs, data->tx_buf_num,
+ &tx);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("memif_tx_burst: %s", memif_strerror (err));
+ goto error;
+ }
+ DBG ("tx: %d/%u", tx, data->tx_buf_num);
+ data->tx_buf_num -= tx;
+ }
+
+error:
+ INFO ("thread %u error!", data->id);
+ goto close;
+
+close:
+ err = memif_buffer_free (c->conn, data->qid, data->rx_bufs, rx, &fb);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_buffer_free: %s", memif_strerror (err));
+ data->rx_buf_num -= fb;
+ DBG ("freed %d buffers. %u/%u alloc/free buffers",
+ fb, data->rx_buf_num, MAX_MEMIF_BUFS - data->rx_buf_num);
+ free (data->rx_bufs);
+ free (data->tx_bufs);
+ data->isRunning = 0;
+ INFO ("pthread id %u exit", data->id);
+ pthread_exit (NULL);
+}
+
+void *
+memif_rx_interrupt (void *ptr)
+{
+ memif_thread_data_t *data = (memif_thread_data_t *) ptr;
+ memif_connection_t *c = &memif_connection[data->index];
+ int err;
+ uint16_t rx = 0, tx = 0, fb = 0;
+ struct epoll_event evt, *e;
+ int en = 0;
+ uint32_t events = 0;
+ sigset_t sigset;
+
+ signal (SIGUSR1, user_signal_handler);
+
+ data->rx_bufs = malloc (sizeof (memif_buffer_t) * MAX_MEMIF_BUFS);
+ data->tx_bufs = malloc (sizeof (memif_buffer_t) * MAX_MEMIF_BUFS);
+ data->rx_buf_num = 0;
+ data->tx_buf_num = 0;
+
+ data->isRunning = 1;
+ INFO ("pthread id %u starts in interrupt mode", data->id);
+ int thread_epfd = epoll_create (1);
+
+ /* get interrupt queue id */
+ int fd = -1;
+ err = memif_get_queue_efd (c->conn, data->qid, &fd);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("memif_get_queue_efd: %s", memif_strerror (err));
+ goto error;
+ }
+ add_epoll_fd (thread_epfd, fd, EPOLLIN);
+
+ while (1)
+ {
+ memset (&evt, 0, sizeof (evt));
+ evt.events = EPOLLIN | EPOLLOUT;
+ sigemptyset (&sigset);
+ en = epoll_pwait (thread_epfd, &evt, 1, -1, &sigset);
+ if (en < 0)
+ {
+ if (errno == EINTR)
+ goto close;
+ DBG ("epoll_pwait: %s", strerror (errno));
+ goto error;
+ }
+ else if (en > 0)
+ {
+ /* receive data from shared memory buffers */
+ err =
+ memif_rx_burst (c->conn, data->qid, data->rx_bufs, MAX_MEMIF_BUFS,
+ &rx);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("memif_rx_burst: %s", memif_strerror (err));
+ data->rx_buf_num += rx;
+ goto error;
+ }
+ data->rx_buf_num += rx;
+ if (rx == 0)
+ {
+ continue;
+ }
+
+ DBG ("thread id: %u", data->id);
+
+ DBG ("received %d buffers. %u/%u alloc/free buffers",
+ rx, data->rx_buf_num, MAX_MEMIF_BUFS - data->rx_buf_num);
+
+ err =
+ memif_buffer_alloc (c->conn, data->qid, data->tx_bufs,
+ data->rx_buf_num, &tx, 0);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("memif_buffer_alloc: %s", memif_strerror (err));
+ data->tx_buf_num += tx;
+ goto error;
+ }
+ data->tx_buf_num += tx;
+ DBG ("allocated %d/%d buffers, %u free buffers",
+ tx, data->rx_buf_num, MAX_MEMIF_BUFS - data->tx_buf_num);
+
+ int i;
+ for (i = 0; i < rx; i++)
+ {
+ resolve_packet ((void *) (data->rx_bufs + i)->data,
+ (data->rx_bufs + i)->data_len,
+ (void *) (data->tx_bufs + i)->data,
+ &(data->tx_bufs + i)->data_len, c->ip_addr);
+ }
+
+ /* mark memif buffers and shared memory buffers as free */
+ err =
+ memif_buffer_free (c->conn, data->qid, data->rx_bufs, rx, &fb);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_buffer_free: %s", memif_strerror (err));
+ data->rx_buf_num -= fb;
+
+ DBG ("freed %d buffers. %u/%u alloc/free buffers",
+ fb, data->rx_buf_num, MAX_MEMIF_BUFS - data->rx_buf_num);
+
+ err =
+ memif_tx_burst (c->conn, data->qid, data->tx_bufs,
+ data->tx_buf_num, &tx);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("memif_tx_burst: %s", memif_strerror (err));
+ goto error;
+ }
+ DBG ("tx: %d/%u", tx, data->tx_buf_num);
+ data->tx_buf_num -= tx;
+ }
+ }
+
+error:
+ INFO ("thread %u error!", data->id);
+ goto close;
+
+close:
+ err = memif_buffer_free (c->conn, data->qid, data->rx_bufs, rx, &fb);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_buffer_free: %s", memif_strerror (err));
+ data->rx_buf_num -= fb;
+ DBG ("freed %d buffers. %u/%u alloc/free buffers",
+ fb, data->rx_buf_num, MAX_MEMIF_BUFS - data->rx_buf_num);
+ free (data->rx_bufs);
+ free (data->tx_bufs);
+ data->isRunning = 0;
+ INFO ("pthread id %u exit", data->id);
+ pthread_exit (NULL);
+
+}
+
+/* informs user about connected status. private_ctx is used by user to identify connection
+ (multiple connections WIP) */
+int
+on_connect (memif_conn_handle_t conn, void *private_ctx)
+{
+ long index = (*(long *) private_ctx);
+ int err, i, ti;
+ INFO ("memif connected! index %ld", index);
+ memif_connection_t *c = &memif_connection[index];
+ c->pending_del = 0;
+
+ for (i = 0; i < MAX_QUEUES; i++)
+ {
+ err = memif_set_rx_mode (c->conn, MEMIF_RX_MODE_POLLING, i);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_set_rx_mode: %s qid: %u", memif_strerror (err), i);
+ else
+ {
+ ti = (index * MAX_QUEUES) + i;
+ if (thread_data[ti].isRunning)
+ {
+ INFO ("thread id: %d already running!", ti);
+ continue;
+ }
+ thread_data[ti].index = index;
+ thread_data[ti].qid = i;
+ thread_data[ti].id = ti;
+ if ((i % 2) == 0)
+ pthread_create (&thread[ti],
+ NULL, memif_rx_poll, (void *) &thread_data[ti]);
+ else
+ pthread_create (&thread[ti],
+ NULL, memif_rx_interrupt,
+ (void *) &thread_data[ti]);
+ }
+
+ }
+ return 0;
+}
+
+/* informs user about disconnected status. private_ctx is used by user to identify connection
+ (multiple connections WIP) */
+int
+on_disconnect (memif_conn_handle_t conn, void *private_ctx)
+{
+ void *ptr;
+ long index = (*(long *) private_ctx);
+ memif_connection_t *c = &memif_connection[index];
+ int i, ti;
+ INFO ("memif disconnected!");
+ /* inform thread in polling mode about memif disconenction */
+ c->pending_del = 1;
+ for (i = 0; i < MAX_QUEUES; i++)
+ {
+ ti = (index * MAX_QUEUES) + i;
+ if (!thread_data[ti].isRunning)
+ continue;
+ if ((i % 2) != 0)
+ pthread_kill (thread[ti], SIGUSR1); /* interrupt thread in interrupt mode */
+ pthread_join (thread[ti], &ptr);
+ }
+ return 0;
+}
+
+/* user needs to watch new fd or stop watching fd that is about to be closed.
+ control fd will be modified during connection establishment to minimize CPU usage */
+int
+control_fd_update (int fd, uint8_t events)
+{
+ /* convert memif event definitions to epoll events */
+ if (events & MEMIF_FD_EVENT_DEL)
+ return del_epoll_fd (main_epfd, fd);
+
+ uint32_t evt = 0;
+ if (events & MEMIF_FD_EVENT_READ)
+ evt |= EPOLLIN;
+ if (events & MEMIF_FD_EVENT_WRITE)
+ evt |= EPOLLOUT;
+
+ if (events & MEMIF_FD_EVENT_MOD)
+ return mod_epoll_fd (main_epfd, fd, evt);
+
+ return add_epoll_fd (main_epfd, fd, evt);
+}
+
+int
+icmpr_memif_create (long index)
+{
+ if (index >= MAX_CONNS)
+ {
+ INFO ("connection array overflow");
+ return 0;
+ }
+ if (index < 0)
+ {
+ INFO ("don't even try...");
+ return 0;
+ }
+ memif_connection_t *c = &memif_connection[index];
+
+ /* setting memif connection arguments */
+ memif_conn_args_t args;
+ int fd = -1;
+ memset (&args, 0, sizeof (args));
+ args.is_master = 0;
+ args.log2_ring_size = 10;
+ args.buffer_size = 2048;
+ args.num_s2m_rings = 2;
+ args.num_m2s_rings = 2;
+ strncpy ((char *) args.interface_name, IF_NAME, strlen (IF_NAME));
+ strncpy ((char *) args.instance_name, APP_NAME, strlen (APP_NAME));
+ args.mode = 0;
+ /* socket filename is not specified, because this app is supposed to
+ connect to VPP over memif. so default socket filename will be used */
+ /* default socketfile = /run/vpp/memif.sock */
+
+ args.interface_id = index;
+ /* last argument for memif_create (void * private_ctx) is used by user
+ to identify connection. this context is returned with callbacks */
+ int err = memif_create (&c->conn,
+ &args, on_connect, on_disconnect, NULL,
+ &ctx[index]);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("memif_create: %s", memif_strerror (err));
+ return 0;
+ }
+
+ c->index = index;
+
+ c->ip_addr[0] = 192;
+ c->ip_addr[1] = 168;
+ c->ip_addr[2] = c->index + 1;
+ c->ip_addr[3] = 2;
+ return 0;
+}
+
+int
+icmpr_memif_delete (long index)
+{
+ if (index >= MAX_CONNS)
+ {
+ INFO ("connection array overflow");
+ return 0;
+ }
+ if (index < 0)
+ {
+ INFO ("don't even try...");
+ return 0;
+ }
+ memif_connection_t *c = &memif_connection[index];
+
+ int err;
+ /* disconenct then delete memif connection */
+ err = memif_delete (&c->conn);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_delete: %s", memif_strerror (err));
+ return 0;
+}
+
+void
+print_help ()
+{
+ printf ("LIBMEMIF EXAMPLE APP: %s", APP_NAME);
+#ifdef ICMP_DBG
+ printf (" (debug)");
+#endif
+ printf ("\n");
+ printf ("==============================\n");
+ printf ("libmemif version: %s", LIBMEMIF_VERSION);
+#ifdef MEMIF_DBG
+ printf (" (debug)");
+#endif
+ printf ("\n");
+ printf ("memif version: %d\n", MEMIF_VERSION);
+ printf ("commands:\n");
+ printf ("\thelp - prints this help\n");
+ printf ("\texit - exit app\n");
+ printf ("\tconn <index> - create memif (slave-mode)\n");
+ printf ("\tdel <index> - delete memif\n");
+ printf ("\tshow - show connection details\n");
+ printf ("\tip-set <index> <ip-addr> - set interface ip address\n");
+}
+
+int
+icmpr_free ()
+{
+ /* application cleanup */
+ int err;
+ long i;
+ for (i = 0; i < MAX_CONNS; i++)
+ {
+ memif_connection_t *c = &memif_connection[i];
+ if (c->conn)
+ icmpr_memif_delete (i);
+ }
+
+ err = memif_cleanup ();
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_delete: %s", memif_strerror (err));
+
+ return 0;
+}
+
+int
+icmpr_set_ip (long index, char *ip)
+{
+ if (index >= MAX_CONNS)
+ {
+ INFO ("connection array overflow");
+ return 0;
+ }
+ if (index < 0)
+ {
+ INFO ("don't even try...");
+ return 0;
+ }
+ memif_connection_t *c = &memif_connection[index];
+ if (c->conn == NULL)
+ {
+ INFO ("no connection at index %ld", index);
+ return 0;
+ }
+
+ char *end;
+ char *ui;
+ uint8_t tmp[4];
+ ui = strtok (ip, ".");
+ if (ui == NULL)
+ goto error;
+ tmp[0] = strtol (ui, &end, 10);
+
+ ui = strtok (NULL, ".");
+ if (ui == NULL)
+ goto error;
+ tmp[1] = strtol (ui, &end, 10);
+
+ ui = strtok (NULL, ".");
+ if (ui == NULL)
+ goto error;
+ tmp[2] = strtol (ui, &end, 10);
+
+ ui = strtok (NULL, ".");
+ if (ui == NULL)
+ goto error;
+ tmp[3] = strtol (ui, &end, 10);
+
+ c->ip_addr[0] = tmp[0];
+ c->ip_addr[1] = tmp[1];
+ c->ip_addr[2] = tmp[2];
+ c->ip_addr[3] = tmp[3];
+
+ INFO ("memif %ld ip address set to %u.%u.%u.%u",
+ index, c->ip_addr[0], c->ip_addr[1], c->ip_addr[2], c->ip_addr[3]);
+
+ return 0;
+
+error:
+ INFO ("invalid ip address");
+ return 0;
+}
+
+
+int
+user_input_handler ()
+{
+ int i;
+ char *in = (char *) malloc (256);
+ char *ui = fgets (in, 256, stdin);
+ char *end;
+ if (in[0] == '\n')
+ goto done;
+ ui = strtok (in, " ");
+ if (strncmp (ui, "exit", 4) == 0)
+ {
+ free (in);
+ icmpr_free ();
+ exit (EXIT_SUCCESS);
+ }
+ else if (strncmp (ui, "help", 4) == 0)
+ {
+ print_help ();
+ goto done;
+ }
+ else if (strncmp (ui, "conn", 4) == 0)
+ {
+ ui = strtok (NULL, " ");
+ if (ui != NULL)
+ icmpr_memif_create (strtol (ui, &end, 10));
+ else
+ INFO ("expected id");
+ goto done;
+ }
+ else if (strncmp (ui, "del", 3) == 0)
+ {
+ ui = strtok (NULL, " ");
+ if (ui != NULL)
+ icmpr_memif_delete (strtol (ui, &end, 10));
+ else
+ INFO ("expected id");
+ goto done;
+ }
+ else if (strncmp (ui, "show", 4) == 0)
+ {
+ print_memif_details ();
+ goto done;
+ }
+ else if (strncmp (ui, "ip-set", 6) == 0)
+ {
+ ui = strtok (NULL, " ");
+ if (ui != NULL)
+ icmpr_set_ip (strtol (ui, &end, 10), strtok (NULL, " "));
+ else
+ INFO ("expected id");
+ goto done;
+ }
+ else
+ {
+ DBG ("unknown command: %s", ui);
+ goto done;
+ }
+
+ return 0;
+done:
+ free (in);
+ return 0;
+}
+
+int
+poll_event (int timeout)
+{
+ struct epoll_event evt, *e;
+ int app_err = 0, memif_err = 0, en = 0;
+ int tmp, nfd;
+ uint32_t events = 0;
+ memset (&evt, 0, sizeof (evt));
+ evt.events = EPOLLIN | EPOLLOUT;
+ sigset_t sigset;
+ sigemptyset (&sigset);
+ en = epoll_pwait (main_epfd, &evt, 1, timeout, &sigset);
+ if (en < 0)
+ {
+ DBG ("epoll_pwait: %s", strerror (errno));
+ return -1;
+ }
+ if (en > 0)
+ {
+ /* this app does not use any other file descriptors than stds and memif control fds */
+ if (evt.data.fd > 2)
+ {
+ /* event of memif control fd */
+ /* convert epolle events to memif events */
+ if (evt.events & EPOLLIN)
+ events |= MEMIF_FD_EVENT_READ;
+ if (evt.events & EPOLLOUT)
+ events |= MEMIF_FD_EVENT_WRITE;
+ if (evt.events & EPOLLERR)
+ events |= MEMIF_FD_EVENT_ERROR;
+ memif_err = memif_control_fd_handler (evt.data.fd, events);
+ if (memif_err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_control_fd_handler: %s", memif_strerror (memif_err));
+ }
+ else if (evt.data.fd == 0)
+ {
+ app_err = user_input_handler ();
+ }
+ else
+ {
+ DBG ("unexpected event at memif_epfd. fd %d", evt.data.fd);
+ }
+ }
+
+ if ((app_err < 0) || (memif_err < 0))
+ {
+ if (app_err < 0)
+ DBG ("user input handler error");
+ if (memif_err < 0)
+ DBG ("memif control fd handler error");
+ return -1;
+ }
+
+ return 0;
+}
+
+int
+main ()
+{
+ main_epfd = epoll_create (1);
+ add_epoll_fd (main_epfd, 0, EPOLLIN);
+
+ /* initialize memory interface */
+ int err, i;
+ /* if valid callback is passed as argument, fd event polling will be done by user
+ all file descriptors and events will be passed to user in this callback */
+ /* if callback is set to NULL libmemif will handle fd event polling */
+ err = memif_init (control_fd_update, APP_NAME);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_init: %s", memif_strerror (err));
+
+ for (i = 0; i < MAX_CONNS; i++)
+ {
+ memif_connection[i].conn = NULL;
+ ctx[i] = i;
+ }
+
+ memset (&thread_data, 0, sizeof (memif_thread_data_t) * MAX_THREADS);
+
+ print_help ();
+
+ /* main loop */
+ while (1)
+ {
+ if (poll_event (-1) < 0)
+ {
+ DBG ("poll_event error!");
+ }
+ }
+}
diff --git a/extras/libmemif/examples/icmp_responder/icmp_proto.c b/extras/libmemif/examples/icmp_responder/icmp_proto.c
new file mode 100644
index 00000000..a923f209
--- /dev/null
+++ b/extras/libmemif/examples/icmp_responder/icmp_proto.c
@@ -0,0 +1,246 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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 <stdint.h>
+#include <net/if.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/uio.h>
+#include <sys/mman.h>
+#include <sys/prctl.h>
+#include <inttypes.h>
+#include <string.h>
+#include <stdio.h>
+#include <netdb.h>
+#include <linux/ip.h>
+#include <linux/icmp.h>
+#include <arpa/inet.h>
+#include <stdlib.h>
+#include <netinet/if_ether.h>
+#include <net/if_arp.h>
+#include <asm/byteorder.h>
+#include <byteswap.h>
+
+#include <icmp_proto.h>
+
+static uint16_t
+cksum (void *addr, ssize_t len)
+{
+ char *data = (char *) addr;
+
+ uint32_t acc = 0xffff;
+
+ ssize_t i;
+ for (i = 0; (i + 1) < len; i += 2)
+ {
+ uint16_t word;
+ memcpy (&word, data + i, 2);
+ acc += ntohs (word);
+ if (acc > 0xffff)
+ acc -= 0xffff;
+ }
+
+ if (len & 1)
+ {
+ uint16_t word = 0;
+ memcpy (&word, data + len - 1, 1);
+ acc += ntohs (word);
+ if (acc > 0xffff)
+ acc -= 0xffff;
+ }
+ return htons (~acc);
+}
+
+int
+print_packet (void *pck)
+{
+ if (pck == NULL)
+ {
+ printf ("ICMP_PROTO: no data\n");
+ return -1;
+ }
+ struct iphdr *ip;
+ struct icmphdr *icmp;
+ ip = (struct iphdr *) pck;
+ icmp = (struct icmphdr *) (pck + sizeof (struct iphdr));
+ printf ("received packet:\n");
+ printf ("\tiphdr:\n");
+ printf ("\t\tihl: %u\n\t\tversion: %u\n\t\tlen: %u\n\t\tid: %u\n",
+ ip->ihl, ip->version, __bswap_16 (ip->tot_len), ip->id);
+ printf ("\t\tprotocol: %u\n", ip->protocol);
+
+ printf ("\t\tsaddr: ");
+ int i;
+ for (i = 0; i < 4; i++)
+ {
+ printf ("%u.", ((uint8_t *) & ip->saddr)[i]);
+ }
+ printf ("\n");
+
+ printf ("\t\tdaddr: ");
+ for (i = 0; i < 4; i++)
+ {
+ printf ("%u.", ((uint8_t *) & ip->daddr)[i]);
+ }
+ printf ("\n");
+ printf ("\ticmphdr:\n");
+ printf ("\t\ttype: %s\n",
+ (icmp->type == ICMP_ECHO) ? "ICMP_ECHO" : "ICMP_ECHOREPLY");
+
+ return 0;
+}
+
+static ssize_t
+resolve_arp (void *arp)
+{
+ struct arphdr *resp = (struct arphdr *) arp;
+
+ resp->ar_hrd = __bswap_16 (ARPHRD_ETHER);
+
+ resp->ar_pro = __bswap_16 (0x0800);
+
+ resp->ar_hln = 6;
+ resp->ar_pln = 4;
+
+ resp->ar_op = __bswap_16 (ARPOP_REPLY);
+
+ return sizeof (struct arphdr);
+}
+
+static ssize_t
+resolve_eth_arp (struct ether_arp *eth_arp, void *eth_arp_resp,
+ uint8_t ip_addr[4])
+{
+ struct ether_arp *resp = (struct ether_arp *) eth_arp_resp;
+
+ resolve_arp (&resp->ea_hdr);
+
+ memcpy (resp->arp_tha, eth_arp->arp_sha, 6);
+ memcpy (resp->arp_tpa, eth_arp->arp_spa, 4);
+
+ memcpy (resp->arp_sha,
+ (((struct ether_header *) (eth_arp_resp -
+ sizeof (struct ether_header)))->
+ ether_shost), 6);
+
+ memcpy (resp->arp_spa, ip_addr, 4);
+
+ return sizeof (struct ether_arp);
+}
+
+static ssize_t
+resolve_eth (struct ether_header *eth, void *eth_resp)
+{
+ struct ether_header *resp = (struct ether_header *) eth_resp;
+ memcpy (resp->ether_dhost, eth->ether_shost, 6);
+
+ uint8_t hw_addr[6];
+ int i;
+ for (i = 0; i < 6; i++)
+ {
+ hw_addr[i] = 'a';
+ }
+ memcpy (resp->ether_shost, hw_addr, 6);
+
+ resp->ether_type = eth->ether_type;
+
+ return sizeof (struct ether_header);
+}
+
+static ssize_t
+resolve_ip (struct iphdr *ip, void *ip_resp, uint8_t ip_addr[4])
+{
+ struct iphdr *resp = (struct iphdr *) ip_resp;
+ resp->ihl = 5;
+ resp->version = 4;
+ resp->tos = 0;
+ /*len updated later */
+ resp->tot_len = 0x5400;
+ resp->id = 0;
+ resp->frag_off = 0;
+ resp->ttl = 0x40;
+ resp->protocol = 1;
+ ((uint8_t *) & resp->saddr)[0] = ip_addr[0];
+ ((uint8_t *) & resp->saddr)[1] = ip_addr[1];
+ ((uint8_t *) & resp->saddr)[2] = ip_addr[2];
+ ((uint8_t *) & resp->saddr)[3] = ip_addr[3];
+ resp->daddr = ip->saddr;
+
+ resp->check = cksum (resp, sizeof (struct iphdr));
+
+ return sizeof (struct iphdr);
+}
+
+static ssize_t
+resolve_icmp (struct icmphdr *icmp, void *icmp_resp)
+{
+ struct icmphdr *resp = (struct icmphdr *) icmp_resp;
+ resp->type = ICMP_ECHOREPLY;
+ resp->code = 0;
+ resp->un.echo.id = icmp->un.echo.id;
+ resp->un.echo.sequence = icmp->un.echo.sequence;
+
+ /*resp->checksum = cksum (resp, sizeof (struct icmphdr)); */
+
+ return sizeof (struct icmphdr);
+}
+
+int
+resolve_packet (void *in_pck, ssize_t in_size,
+ void *out_pck, uint32_t * out_size, uint8_t ip_addr[4])
+{
+ struct ether_header *eh;
+ struct ether_arp *eah;
+ struct iphdr *ip;
+ struct icmphdr *icmp;
+ *out_size = 0;
+
+ eh = (struct ether_header *) in_pck;
+ *out_size = resolve_eth (eh, out_pck);
+
+ if (eh->ether_type == 0x0608)
+ {
+ eah = (struct ether_arp *) (in_pck + *out_size);
+ *out_size += resolve_eth_arp (eah, out_pck + *out_size, ip_addr);
+
+ }
+ else if (eh->ether_type == 0x0008)
+ {
+#ifdef ICMP_DBG
+ print_packet (in_pck + *out_size);
+#endif
+ ip = (struct iphdr *) (in_pck + *out_size);
+ *out_size += resolve_ip (ip, out_pck + *out_size, ip_addr);
+ if (ip->protocol == 1)
+ {
+ icmp = (struct icmphdr *) (in_pck + *out_size);
+ *out_size += resolve_icmp (icmp, out_pck + *out_size);
+ ((struct icmphdr *) (out_pck + *out_size -
+ sizeof (struct icmphdr)))->checksum =
+ cksum (out_pck + *out_size - sizeof (struct icmphdr),
+ sizeof (struct icmphdr));
+ /* payload */
+ memcpy (out_pck + *out_size, in_pck + *out_size,
+ in_size - *out_size);
+ *out_size = in_size;
+ }
+ }
+ return 0;
+}
diff --git a/extras/libmemif/examples/icmp_responder/icmp_proto.h b/extras/libmemif/examples/icmp_responder/icmp_proto.h
new file mode 100644
index 00000000..f2f22ac4
--- /dev/null
+++ b/extras/libmemif/examples/icmp_responder/icmp_proto.h
@@ -0,0 +1,26 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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 _ICMP_PROTO_H_
+#define _ICMP_PROTO_H_
+
+int resolve_packet (void *in_pck, ssize_t in_size, void *out_pck,
+ uint32_t * out_size, uint8_t ip_addr[4]);
+
+int print_packet (void *pck);
+
+#endif /* _ICMP_PROTO_H_ */
diff --git a/extras/libmemif/examples/icmp_responder/main.c b/extras/libmemif/examples/icmp_responder/main.c
new file mode 100644
index 00000000..9e49771e
--- /dev/null
+++ b/extras/libmemif/examples/icmp_responder/main.c
@@ -0,0 +1,416 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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 <stdlib.h>
+#include <stdint.h>
+#include <net/if.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/uio.h>
+#include <sys/mman.h>
+#include <sys/prctl.h>
+#include <inttypes.h>
+#include <string.h>
+#include <stdio.h>
+#include <netdb.h>
+#include <linux/ip.h>
+#include <linux/icmp.h>
+#include <arpa/inet.h>
+#include <stdlib.h>
+#include <netinet/if_ether.h>
+#include <net/if_arp.h>
+#include <asm/byteorder.h>
+#include <byteswap.h>
+#include <string.h>
+#include <sys/epoll.h>
+#include <errno.h>
+#include <unistd.h>
+#include <signal.h>
+
+#include <libmemif.h>
+#include <icmp_proto.h>
+
+#define APP_NAME "ICMP_Responder"
+#define IF_NAME "memif_connection"
+
+
+#ifdef ICMP_DBG
+#define DBG(...) do { \
+ printf (APP_NAME":%s:%d: ", __func__, __LINE__); \
+ printf (__VA_ARGS__); \
+ printf ("\n"); \
+ } while (0)
+#else
+#define DBG(...)
+#endif
+
+#define INFO(...) do { \
+ printf ("INFO: "__VA_ARGS__); \
+ printf ("\n"); \
+ } while (0)
+
+/* maximum tx/rx memif buffers */
+#define MAX_MEMIF_BUFS 256
+
+typedef struct
+{
+ uint16_t index;
+ /* memif conenction handle */
+ memif_conn_handle_t conn;
+ /* transmit queue id */
+ uint16_t tx_qid;
+ /* tx buffers */
+ memif_buffer_t *tx_bufs;
+ /* allocated tx buffers counter */
+ /* number of tx buffers pointing to shared memory */
+ uint16_t tx_buf_num;
+ /* rx buffers */
+ memif_buffer_t *rx_bufs;
+ /* allcoated rx buffers counter */
+ /* number of rx buffers pointing to shared memory */
+ uint16_t rx_buf_num;
+ /* interface ip address */
+ uint8_t ip_addr[4];
+} memif_connection_t;
+
+memif_connection_t memif_connection;
+int epfd;
+
+static void
+print_memif_details ()
+{
+ memif_connection_t *c = &memif_connection;
+ printf ("MEMIF DETAILS\n");
+ printf ("==============================\n");
+
+
+ memif_details_t md;
+ memset (&md, 0, sizeof (md));
+ ssize_t buflen = 2048;
+ char *buf = malloc (buflen);
+ memset (buf, 0, buflen);
+ int err, e;
+
+ err = memif_get_details (c->conn, &md, buf, buflen);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("%s", memif_strerror (err));
+ if (err == MEMIF_ERR_NOCONN)
+ {
+ free (buf);
+ return;
+ }
+ }
+
+ printf ("\tinterface name: %s\n", (char *) md.if_name);
+ printf ("\tapp name: %s\n", (char *) md.inst_name);
+ printf ("\tremote interface name: %s\n", (char *) md.remote_if_name);
+ printf ("\tremote app name: %s\n", (char *) md.remote_inst_name);
+ printf ("\tid: %u\n", md.id);
+ printf ("\tsecret: %s\n", (char *) md.secret);
+ printf ("\trole: ");
+ if (md.role)
+ printf ("slave\n");
+ else
+ printf ("master\n");
+ printf ("\tmode: ");
+ switch (md.mode)
+ {
+ case 0:
+ printf ("ethernet\n");
+ break;
+ case 1:
+ printf ("ip\n");
+ break;
+ case 2:
+ printf ("punt/inject\n");
+ break;
+ default:
+ printf ("unknown\n");
+ break;
+ }
+ printf ("\tsocket filename: %s\n", (char *) md.socket_filename);
+ printf ("\tsocket filename: %s\n", (char *) md.socket_filename);
+ printf ("\trx queues:\n");
+ for (e = 0; e < md.rx_queues_num; e++)
+ {
+ printf ("\t\tqueue id: %u\n", md.rx_queues[e].qid);
+ printf ("\t\tring size: %u\n", md.rx_queues[e].ring_size);
+ printf ("\t\tbuffer size: %u\n", md.rx_queues[e].buffer_size);
+ }
+ printf ("\ttx queues:\n");
+ for (e = 0; e < md.tx_queues_num; e++)
+ {
+ printf ("\t\tqueue id: %u\n", md.tx_queues[e].qid);
+ printf ("\t\tring size: %u\n", md.tx_queues[e].ring_size);
+ printf ("\t\tbuffer size: %u\n", md.tx_queues[e].buffer_size);
+ }
+ printf ("\tlink: ");
+ if (md.link_up_down)
+ printf ("up\n");
+ else
+ printf ("down\n");
+
+ free (buf);
+}
+
+/* informs user about connected status. private_ctx is used by user to identify connection
+ (multiple connections WIP) */
+int
+on_connect (memif_conn_handle_t conn, void *private_ctx)
+{
+ INFO ("memif connected!");
+ return 0;
+}
+
+/* informs user about disconnected status. private_ctx is used by user to identify connection
+ (multiple connections WIP) */
+int
+on_disconnect (memif_conn_handle_t conn, void *private_ctx)
+{
+ INFO ("memif disconnected!");
+ return 0;
+}
+
+int
+icmpr_memif_delete ()
+{
+ int err;
+ /* disconenct then delete memif connection */
+ err = memif_delete (&(&memif_connection)->conn);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_delete: %s", memif_strerror (err));
+ return 0;
+}
+
+void
+print_help ()
+{
+ printf ("LIBMEMIF EXAMPLE APP: %s", APP_NAME);
+#ifdef ICMP_DBG
+ printf (" (debug)");
+#endif
+ printf ("\n");
+ printf ("==============================\n");
+ printf ("libmemif version: %s", LIBMEMIF_VERSION);
+#ifdef MEMIF_DBG
+ printf (" (debug)");
+#endif
+ printf ("\n");
+ printf ("memif version: %d\n", MEMIF_VERSION);
+ printf ("\tuse CTRL+C to exit\n");
+}
+
+int
+icmpr_buffer_alloc (long n, uint16_t qid)
+{
+ memif_connection_t *c = &memif_connection;
+ int err;
+ uint16_t r;
+ /* set data pointer to shared memory and set buffer_len to shared mmeory buffer len */
+ err = memif_buffer_alloc (c->conn, qid, c->tx_bufs, n, &r, 0);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("memif_buffer_alloc: %s", memif_strerror (err));
+ c->tx_buf_num += r;
+ return -1;
+ }
+ c->tx_buf_num += r;
+ DBG ("allocated %d/%ld buffers, %u free buffers", r, n,
+ MAX_MEMIF_BUFS - c->tx_buf_num);
+ return 0;
+}
+
+int
+icmpr_tx_burst (uint16_t qid)
+{
+ memif_connection_t *c = &memif_connection;
+ int err;
+ uint16_t r;
+ /* inform peer memif interface about data in shared memory buffers */
+ /* mark memif buffers as free */
+ err = memif_tx_burst (c->conn, qid, c->tx_bufs, c->tx_buf_num, &r);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_tx_burst: %s", memif_strerror (err));
+ DBG ("tx: %d/%u", r, c->tx_buf_num);
+ c->tx_buf_num -= r;
+ return 0;
+}
+
+int
+icmpr_free ()
+{
+ /* application cleanup */
+ int err;
+ memif_connection_t *c = &memif_connection;
+ free (c->tx_bufs);
+ c->tx_bufs = NULL;
+ free (c->rx_bufs);
+ c->rx_bufs = NULL;
+
+ err = memif_cleanup ();
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_delete: %s", memif_strerror (err));
+
+ return 0;
+}
+
+void
+icmpr_exit (int sig)
+{
+ printf ("\n");
+ icmpr_memif_delete ();
+ icmpr_free ();
+ exit (EXIT_SUCCESS);
+}
+
+/* called when event is polled on interrupt file descriptor.
+ there are packets in shared memory ready to be received */
+int
+on_interrupt (memif_conn_handle_t conn, void *private_ctx, uint16_t qid)
+{
+ DBG ("interrupted");
+ memif_connection_t *c = &memif_connection;
+ int err;
+ uint16_t rx;
+ /* receive data from shared memory buffers */
+ err = memif_rx_burst (c->conn, qid, c->rx_bufs, MAX_MEMIF_BUFS, &rx);
+ c->rx_buf_num += rx;
+
+ DBG ("received %d buffers. %u/%u alloc/free buffers",
+ rx, c->rx_buf_num, MAX_MEMIF_BUFS - c->rx_buf_num);
+
+ if (icmpr_buffer_alloc (rx, c->tx_qid) < 0)
+ {
+ INFO ("buffer_alloc error");
+ goto error;
+ }
+ int i;
+ for (i = 0; i < rx; i++)
+ {
+ resolve_packet ((void *) (c->rx_bufs + i)->data,
+ (c->rx_bufs + i)->data_len,
+ (void *) (c->tx_bufs + i)->data,
+ &(c->tx_bufs + i)->data_len, c->ip_addr);
+ }
+
+ uint16_t fb;
+ /* mark memif buffers and shared memory buffers as free */
+ err = memif_buffer_free (c->conn, qid, c->rx_bufs, rx, &fb);
+ c->rx_buf_num -= fb;
+
+ DBG ("freed %d buffers. %u/%u alloc/free buffers",
+ fb, c->rx_buf_num, MAX_MEMIF_BUFS - c->rx_buf_num);
+
+ icmpr_tx_burst (c->tx_qid);
+
+ return 0;
+
+error:
+ err = memif_buffer_free (c->conn, qid, c->rx_bufs, rx, &fb);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_buffer_free: %s", memif_strerror (err));
+ c->rx_buf_num -= fb;
+ DBG ("freed %d buffers. %u/%u alloc/free buffers",
+ fb, c->rx_buf_num, MAX_MEMIF_BUFS - c->rx_buf_num);
+ return 0;
+}
+
+int
+icmpr_memif_create (int is_master)
+{
+ /* setting memif connection arguments */
+ memif_conn_args_t args;
+ int fd = -1;
+ memset (&args, 0, sizeof (args));
+ args.is_master = is_master;
+ args.log2_ring_size = 10;
+ args.buffer_size = 2048;
+ args.num_s2m_rings = 2;
+ args.num_m2s_rings = 2;
+ strncpy ((char *) args.interface_name, IF_NAME, strlen (IF_NAME));
+ strncpy ((char *) args.instance_name, APP_NAME, strlen (APP_NAME));
+ args.mode = 0;
+ /* socket filename is not specified, because this app is supposed to
+ connect to VPP over memif. so default socket filename will be used */
+ /* default socketfile = /run/vpp/memif.sock */
+
+ args.interface_id = 0;
+ /* last argument for memif_create (void * private_ctx) is used by user
+ to identify connection. this context is returned with callbacks */
+ int err = memif_create (&(&memif_connection)->conn,
+ &args, on_connect, on_disconnect, on_interrupt,
+ NULL);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_create: %s", memif_strerror (err));
+ return 0;
+}
+
+int
+main (int argc, char *argv[])
+{
+ memif_connection_t *c = &memif_connection;
+
+ signal (SIGINT, icmpr_exit);
+
+ /* initialize global memif connection handle */
+ c->conn = NULL;
+ if (argc == 1)
+ c->tx_qid = 0;
+ else
+ {
+ char *end;
+ c->tx_qid = strtol (argv[1], &end, 10);
+ }
+ INFO ("tx qid: %u", c->tx_qid);
+ /* alloc memif buffers */
+ c->rx_buf_num = 0;
+ c->rx_bufs =
+ (memif_buffer_t *) malloc (sizeof (memif_buffer_t) * MAX_MEMIF_BUFS);
+ c->tx_buf_num = 0;
+ c->tx_bufs =
+ (memif_buffer_t *) malloc (sizeof (memif_buffer_t) * MAX_MEMIF_BUFS);
+ c->ip_addr[0] = 192;
+ c->ip_addr[1] = 168;
+ c->ip_addr[2] = 1;
+ c->ip_addr[3] = 2;
+ /* initialize memory interface */
+ int err;
+ /* if valid callback is passed as argument, fd event polling will be done by user
+ all file descriptors and events will be passed to user in this callback */
+ /* if callback is set to NULL libmemif will handle fd event polling */
+ err = memif_init (NULL, APP_NAME);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_init: %s", memif_strerror (err));
+
+ print_help ();
+
+ icmpr_memif_create (0);
+ print_memif_details ();
+
+ /* main loop */
+ while (1)
+ {
+ if (memif_poll_event (-1) < 0)
+ {
+ DBG ("poll_event error!");
+ }
+ }
+}
diff --git a/extras/libmemif/libmemif_doc.md b/extras/libmemif/libmemif_doc.md
new file mode 100644
index 00000000..fb4a18af
--- /dev/null
+++ b/extras/libmemif/libmemif_doc.md
@@ -0,0 +1,74 @@
+Shared Memory Packet Interface (memif) Library {#libmemif_doc}
+==============================================
+
+## Introduction
+
+Shared memory packet interface (memif) provides high performance packet transmit and receive between user application and Vector Packet Processing (VPP) or multiple user applications. Using libmemif, user application can create shared memory interface in master or slave mode and connect to VPP or another application using libmemif. Once the connection is established, user application can receive or transmit packets using libmemif API.
+
+![Architecture](docs/architecture.png)
+
+## Features
+
+- [x] Slave mode
+ - [x] Connect to VPP over memif
+ - [x] ICMP responder example app
+- [x] Transmit/receive packets
+- [x] Interrupt mode support
+- [x] File descriptor event polling in libmemif (optional)
+ - [x] Simplify file descriptor event polling (one handler for control and interrupt channel)
+- [x] Multiple connections
+- [x] Multiple queues
+ - [x] Multi-thread support
+- [x] Master mode
+ - [ ] Multiple regions (TODO)
+- [ ] Performance testing (TODO)
+
+## Quickstart
+
+This setup will run libmemif ICMP responder example app in container. Install [docker](https://docs.docker.com/engine/installation) engine.
+Useful link: [Docker documentation](https://docs.docker.com/get-started).
+
+Pull image:
+```
+# docker pull ligato/libmemif-sample-service
+```
+
+Now you should be able to see ligato/libmemif-sample-service image on your local machine (IMAGE ID in this README may be outdated):
+```
+# docker images
+REPOSITORY TAG IMAGE ID CREATED SIZE
+ligato/libmemif-sample-service latest 32ecc2f9d013 About a minute ago 468MB
+...
+```
+
+Run container:
+```
+# docker run -it --rm --name icmp-responder --hostname icmp-responder --privileged -v "/run/vpp/:/run/vpp/" ligato/libmemif-sample-service
+```
+Example application will start in debug mode. Output should look like this:
+```
+ICMP_Responder:add_epoll_fd:204: fd 0 added to epoll
+MEMIF_DEBUG:src/main.c:memif_init:383: app name: ICMP_Responder
+ICMP_Responder:add_epoll_fd:204: fd 4 added to epoll
+LIBMEMIF EXAMPLE APP: ICMP_Responder (debug)
+==============================
+libmemif version: 1.0 (debug)
+memif version: 256
+commands:
+ help - prints this help
+ exit - exit app
+ conn <index> - create memif (slave-mode)
+ del <index> - delete memif
+ show - show connection details
+ ip-set <index> <ip-addr> - set interface ip address
+ rx-mode <index> <qid> <polling|interrupt> - set queue rx mode
+```
+
+Continue with @ref libmemif_example_setup which contains instructions on how to set up conenction between icmpr-epoll example app and VPP-memif.
+
+#### Next steps
+
+- @subpage libmemif_build_doc
+- @subpage libmemif_examples_doc
+- @subpage libmemif_example_setup_doc
+- @subpage libmemif_gettingstarted_doc
diff --git a/extras/libmemif/src/libmemif.h b/extras/libmemif/src/libmemif.h
new file mode 100644
index 00000000..a2d1a5e2
--- /dev/null
+++ b/extras/libmemif/src/libmemif.h
@@ -0,0 +1,443 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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.
+ *------------------------------------------------------------------
+ */
+
+/** @file */
+
+#ifndef _LIBMEMIF_H_
+#define _LIBMEMIF_H_
+
+/** Libmemif version. */
+#define LIBMEMIF_VERSION "1.0"
+/** Default name of application using libmemif. */
+#define MEMIF_DEFAULT_APP_NAME "libmemif-app"
+
+#include <inttypes.h>
+
+#include <memif.h>
+
+/*! Error codes */
+typedef enum
+{
+ MEMIF_ERR_SUCCESS = 0, /*!< success */
+/* SYSCALL ERRORS */
+ MEMIF_ERR_SYSCALL, /*!< other syscall error */
+ MEMIF_ERR_ACCES, /*!< permission denied */
+ MEMIF_ERR_NO_FILE, /*!< file does not exist */
+ MEMIF_ERR_FILE_LIMIT, /*!< system open file limit */
+ MEMIF_ERR_PROC_FILE_LIMIT, /*!< process open file limit */
+ MEMIF_ERR_ALREADY, /*!< connection already requested */
+ MEMIF_ERR_AGAIN, /*!< fd is not socket, or operation would block */
+ MEMIF_ERR_BAD_FD, /*!< invalid fd */
+ MEMIF_ERR_NOMEM, /*!< out of memory */
+/* LIBMEMIF ERRORS */
+ MEMIF_ERR_INVAL_ARG, /*!< invalid argument */
+ MEMIF_ERR_NOCONN, /*!< handle points to no connection */
+ MEMIF_ERR_CONN, /*!< handle points to existing connection */
+ MEMIF_ERR_CB_FDUPDATE, /*!< user defined callback memif_control_fd_update_t error */
+ MEMIF_ERR_FILE_NOT_SOCK, /*!< file specified by socket filename
+ exists, but it's not socket */
+ MEMIF_ERR_NO_SHMFD, /*!< missing shm fd */
+ MEMIF_ERR_COOKIE, /*!< wrong cookie on ring */
+ MEMIF_ERR_NOBUF_RING, /*!< ring buffer full */
+ MEMIF_ERR_NOBUF, /*!< not enough memif buffers */
+ MEMIF_ERR_NOBUF_DET, /*!< memif details needs larger buffer */
+ MEMIF_ERR_INT_WRITE, /*!< send interrupt error */
+ MEMIF_ERR_MFMSG, /*!< malformed msg received */
+ MEMIF_ERR_QID, /*!< invalid queue id */
+/* MEMIF PROTO ERRORS */
+ MEMIF_ERR_PROTO, /*!< incompatible protocol version */
+ MEMIF_ERR_ID, /*!< unmatched interface id */
+ MEMIF_ERR_ACCSLAVE, /*!< slave cannot accept connection requests */
+ MEMIF_ERR_ALRCONN, /*!< memif is already connected */
+ MEMIF_ERR_MODE, /*!< mode mismatch */
+ MEMIF_ERR_SECRET, /*!< secret mismatch */
+ MEMIF_ERR_NOSECRET, /*!< secret required */
+ MEMIF_ERR_MAXREG, /*!< max region limit reached */
+ MEMIF_ERR_MAXRING, /*!< max ring limit reached */
+ MEMIF_ERR_NO_INTFD, /*!< missing interrupt fd */
+ MEMIF_ERR_DISCONNECT, /*!< disconenct received */
+ MEMIF_ERR_DISCONNECTED, /*!< peer interface disconnected */
+ MEMIF_ERR_UNKNOWN_MSG, /*!< unknown message type */
+} memif_err_t;
+
+/**
+ * @defgroup MEMIF_FD_EVENT Types of events that need to be watched for specific fd.
+ *
+ * @{
+ */
+
+/** user needs to set events that occured on fd and pass them to memif_control_fd_handler */
+#define MEMIF_FD_EVENT_READ (1 << 0)
+#define MEMIF_FD_EVENT_WRITE (1 << 1)
+/** inform libmemif that error occured on fd */
+#define MEMIF_FD_EVENT_ERROR (1 << 2)
+/** if set, informs that fd is going to be closed (user may want to stop watching for events on this fd) */
+#define MEMIF_FD_EVENT_DEL (1 << 3)
+/** update events */
+#define MEMIF_FD_EVENT_MOD (1 << 4)
+/** @} */
+
+/** *brief Memif connection handle
+ pointer of type void, pointing to internal structure
+*/
+typedef void *memif_conn_handle_t;
+/**
+ * @defgroup CALLBACKS Callback functions definitions
+ *
+ * @{
+ */
+
+/** \brief Memif control file descriptor update (callback function)
+ @param fd - new file descriptor to watch
+ @param events - event type(s) to watch for
+
+ This callback is called when there is new fd to watch for events on
+ or if fd is about to be closed (user mey want to stop watching for events on this fd).
+*/
+typedef int (memif_control_fd_update_t) (int fd, uint8_t events);
+
+/** \brief Memif connection status update (callback function)
+ @param conn - memif connection handle
+ @param private_ctx - private context
+
+ Informs user about connection status connected/disconnected.
+ On connected -> start watching for events on interrupt fd (optional).
+*/
+typedef int (memif_connection_update_t) (memif_conn_handle_t conn,
+ void *private_ctx);
+
+/** \brief Memif interrupt occured (callback function)
+ @param conn - memif connection handle
+ @param private_ctx - private context
+ @param qid - queue id on which interrupt occured
+
+ Called when event is received on interrupt fd.
+*/
+typedef int (memif_interrupt_t) (memif_conn_handle_t conn, void *private_ctx,
+ uint16_t qid);
+/** @} */
+
+/**
+ * @defgroup ARGS_N_BUFS Connection arguments and buffers
+ *
+ * @{
+ */
+
+/** \brief Memif connection arguments
+ @param socket_filename - socket filename
+ @param secret - otional parameter used as interface autenthication
+ @param num_s2m_rings - number of slave to master rings
+ @param num_m2s_rings - number of master to slave rings
+ @param buffer_size - size of buffer in shared memory
+ @param log2_ring_size - logarithm base 2 of ring size
+ @param is_master - 0 == master, 1 == slave
+ @param interface_id - id used to identify peer connection
+ @param interface_name - interface name
+ @param instance_name - application name
+ @param mode - 0 == ethernet, 1 == ip , 2 == punt/inject
+*/
+typedef struct
+{
+ uint8_t *socket_filename; /*!< default = /run/vpp/memif.sock */
+ uint8_t secret[24]; /*!< optional (interface authentication) */
+
+ uint8_t num_s2m_rings; /*!< default = 1 */
+ uint8_t num_m2s_rings; /*!< default = 1 */
+ uint16_t buffer_size; /*!< default = 2048 */
+ memif_log2_ring_size_t log2_ring_size; /*!< default = 10 (1024) */
+ uint8_t is_master;
+
+ memif_interface_id_t interface_id;
+ uint8_t interface_name[32];
+ uint8_t instance_name[32];
+ memif_interface_mode_t mode:8;
+} memif_conn_args_t;
+
+/*! memif receive mode */
+typedef enum
+{
+ MEMIF_RX_MODE_INTERRUPT = 0, /*!< interrupt mode */
+ MEMIF_RX_MODE_POLLING /*!< polling mode */
+} memif_rx_mode_t;
+
+/** \brief Memif buffer
+ @param desc_index - ring descriptor index
+ @param buffer_len - shared meory buffer length
+ @param data_len - data length
+ @param data - pointer to shared memory data
+*/
+typedef struct
+{
+ uint16_t desc_index;
+ uint32_t buffer_len;
+ uint32_t data_len;
+ void *data;
+} memif_buffer_t;
+/** @} */
+
+/**
+ * @defgroup MEMIF_DETAILS Memif details structs
+ *
+ * @{
+ */
+
+/** \brief Memif queue details
+ @param qid - queue id
+ @param ring_size - size of ring buffer in sharem memory
+ @param buffer_size - buffer size on sharem memory
+*/
+typedef struct
+{
+ uint8_t qid;
+ uint32_t ring_size;
+ uint16_t buffer_size;
+ /* add ring information */
+} memif_queue_details_t;
+
+/** \brief Memif details
+ @param if_name - interface name
+ @param inst_name - application name
+ @param remote_if_name - peer interface name
+ @param remote_inst_name - peer application name
+ @param id - connection id
+ @param secret - secret
+ @param role - 0 = master, 1 = slave
+ @param mode - 0 = ethernet, 1 = ip , 2 = punt/inject
+ @param socket_filename = socket filename
+ @param rx_queues_num - number of receive queues
+ @param tx_queues_num - number of transmit queues
+ @param rx_queues - struct containing receive queue details
+ @param tx_queues - struct containing transmit queue details
+ @param link_up_down - 1 = up (connected), 2 = down (disconnected)
+*/
+typedef struct
+{
+ uint8_t *if_name;
+ uint8_t *inst_name;
+ uint8_t *remote_if_name;
+ uint8_t *remote_inst_name;
+
+ uint32_t id;
+ uint8_t *secret; /* optional */
+ uint8_t role; /* 0 = master, 1 = slave */
+ uint8_t mode; /* 0 = ethernet, 1 = ip, 2 = punt/inject */
+ uint8_t *socket_filename;
+ uint8_t rx_queues_num;
+ uint8_t tx_queues_num;
+ memif_queue_details_t *rx_queues;
+ memif_queue_details_t *tx_queues;
+
+ uint8_t link_up_down; /* 1 = up, 0 = down */
+} memif_details_t;
+/** @} */
+
+/**
+ * @defgroup API_CALLS Api calls
+ *
+ * @{
+ */
+
+/** \biref Memif get queue event file descriptor
+ @param conn - memif connection handle
+ @param qid - queue id
+ @param[out] fd - returns event file descriptor
+
+ \return memif_err_t
+*/
+
+int memif_get_queue_efd (memif_conn_handle_t conn, uint16_t qid, int *fd);
+
+/** \brief Memif set rx mode
+ @param conn - memif connection handle
+ @param rx_mode - receive mode
+ @param qid - queue id
+
+ \return memif_err_t
+*/
+int memif_set_rx_mode (memif_conn_handle_t conn, memif_rx_mode_t rx_mode,
+ uint16_t qid);
+
+/** \brief Memif strerror
+ @param err_code - error code
+
+ Converts error code to error message.
+
+ \return Error string
+*/
+char *memif_strerror (int err_code);
+
+/** \brief Memif get details
+ @param conn - memif conenction handle
+ @param md - pointer to memif details struct
+ @param buf - buffer containing details strings
+ @param buflen - length of buffer
+
+ \return memif_err_t
+*/
+int memif_get_details (memif_conn_handle_t conn, memif_details_t * md,
+ char *buf, ssize_t buflen);
+
+/** \brief Memif initialization
+ @param on_control_fd_update - if control fd updates inform user to watch new fd
+ @param app_name - application name
+
+ if param on_control_fd_update is set to NULL,
+ libmemif will handle file descriptor event polling
+ if a valid callback is set, file descriptor event polling needs to be done by
+ user application, all file descriptors and event types will be passed in
+ this callback to user application
+
+ Initialize internal libmemif structures. Create timerfd (used to periodically request connection by
+ disconnected memifs in slave mode, with no additional API call). This fd is passed to user with memif_control_fd_update_t
+ timer is inactive at this state. It activates with if there is at least one memif in slave mode.
+
+ \return memif_err_t
+*/
+int memif_init (memif_control_fd_update_t * on_control_fd_update,
+ char *app_name);
+
+/** \brief Memif cleanup
+
+ Free libmemif internal allocations.
+
+ \return 0
+*/
+int memif_cleanup ();
+
+/** \brief Memory interface create function
+ @param conn - connection handle for user app
+ @param args - memory interface connection arguments
+ @param on_connect - inform user about connected status
+ @param on_disconnect - inform user about disconnected status
+ @param on_interrupt - informs user about interrupt, if set to null user will not be notified about interrupt, user can use memif_get_queue_efd call to get interrupt fd to poll for events
+ @param private_ctx - private contex passed back to user with callback
+
+ Creates memory interface.
+
+ SLAVE-MODE -
+ Start timer that will send events to timerfd. If this fd is passed to memif_control_fd_handler
+ every disconnected memif in slave mode will send connection request.
+ On success new fd is passed to user with memif_control_fd_update_t.
+
+ MASTER-MODE -
+ Create listener socket and pass fd to user with memif_cntrol_fd_update_t.
+ If this fd is passed to memif_control_fd_handler accept will be called and
+ new fd will be passed to user with memif_control_fd_update_t.
+
+
+ \return memif_err_t
+*/
+int memif_create (memif_conn_handle_t * conn, memif_conn_args_t * args,
+ memif_connection_update_t * on_connect,
+ memif_connection_update_t * on_disconnect,
+ memif_interrupt_t * on_interrupt, void *private_ctx);
+
+/** \brief Memif control file descriptor handler
+ @param fd - file descriptor on which the event occured
+ @param events - event type(s) that occured
+
+ If event occures on any control fd, call memif_control_fd_handler.
+ Internal - lib will "identify" fd (timerfd, lsitener, control) and handle event accordingly.
+
+ FD-TYPE -
+ TIMERFD -
+ Every disconnected memif in slave mode will request connection.
+ LISTENER or CONTROL -
+ Handle socket messaging (internal connection establishment).
+ INTERRUPT -
+ Call on_interrupt callback (if set).
+
+ \return memif_err_t
+
+*/
+int memif_control_fd_handler (int fd, uint8_t events);
+
+/** \brief Memif delete
+ @param conn - pointer to memif connection handle
+
+
+ disconnect session (free queues and regions, close file descriptors, unmap shared memory)
+ set connection handle to NULL, to avoid possible double free
+
+ \return memif_err_t
+*/
+int memif_delete (memif_conn_handle_t * conn);
+
+/** \brief Memif buffer alloc
+ @param conn - memif conenction handle
+ @param qid - number indentifying queue
+ @param bufs - memif buffers
+ @param count - number of memif buffers to allocate
+ @param count_out - returns number of allocated buffers
+ @param size - minimal buffer size, 0 = standard buffer size
+
+ \return memif_err_t
+*/
+int memif_buffer_alloc (memif_conn_handle_t conn, uint16_t qid,
+ memif_buffer_t * bufs, uint16_t count,
+ uint16_t * count_out, uint16_t size);
+
+/** \brief Memif buffer free
+ @param conn - memif conenction handle
+ @param qid - number indentifying queue
+ @param bufs - memif buffers
+ @param count - number of memif buffers to free
+ @param count_out - returns number of freed buffers
+
+ \return memif_err_t
+*/
+int memif_buffer_free (memif_conn_handle_t conn, uint16_t qid,
+ memif_buffer_t * bufs, uint16_t count,
+ uint16_t * count_out);
+
+/** \brief Memif transmit buffer burst
+ @param conn - memif conenction handle
+ @param qid - number indentifying queue
+ @param bufs - memif buffers
+ @param count - number of memif buffers to transmit
+ @param tx - returns number of transmitted buffers
+
+ \return memif_err_t
+*/
+int memif_tx_burst (memif_conn_handle_t conn, uint16_t qid,
+ memif_buffer_t * bufs, uint16_t count, uint16_t * tx);
+
+/** \brief Memif receive buffer burst
+ @param conn - memif conenction handle
+ @param qid - number indentifying queue
+ @param bufs - memif buffers
+ @param count - number of memif buffers to receive
+ @param rx - returns number of received buffers
+
+ \return memif_err_t
+*/
+int memif_rx_burst (memif_conn_handle_t conn, uint16_t qid,
+ memif_buffer_t * bufs, uint16_t count, uint16_t * rx);
+
+/** \brief Memif poll event
+ @param timeout - timeout in seconds
+
+ Passive event polling -
+ timeout = 0 - dont wait for event, check event queue if there is an event and return.
+ timeout = -1 - wait until event
+
+ \return memif_err_t
+*/
+int memif_poll_event (int timeout);
+/** @} */
+
+#endif /* _LIBMEMIF_H_ */
diff --git a/extras/libmemif/src/main.c b/extras/libmemif/src/main.c
new file mode 100644
index 00000000..49427670
--- /dev/null
+++ b/extras/libmemif/src/main.c
@@ -0,0 +1,2095 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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 <stdint.h>
+#include <net/if.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/uio.h>
+#include <sys/mman.h>
+#include <sys/prctl.h>
+#include <inttypes.h>
+#include <string.h>
+#include <stdio.h>
+#include <netdb.h>
+#include <linux/ip.h>
+#include <linux/icmp.h>
+#include <arpa/inet.h>
+#include <stdlib.h>
+#include <netinet/if_ether.h>
+#include <net/if_arp.h>
+#include <asm/byteorder.h>
+#include <byteswap.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/eventfd.h>
+#include <sys/timerfd.h>
+#include <sys/epoll.h>
+#include <signal.h>
+
+/* memif protocol msg, ring and descriptor definitions */
+#include <memif.h>
+/* memif api */
+#include <libmemif.h>
+/* socket messaging functions */
+#include <socket.h>
+/* private structs and functions */
+#include <memif_private.h>
+
+#define ERRLIST_LEN 36
+#define MAX_ERRBUF_LEN 256
+
+#if __x86_x64__
+#define MEMIF_MEMORY_BARRIER() __builtin_ia32_sfence ()
+#else
+#define MEMIF_MEORY_BARRIER() __sync_synchronize ()
+#endif /* __x86_x64__ */
+
+libmemif_main_t libmemif_main;
+int memif_epfd;
+
+static char memif_buf[MAX_ERRBUF_LEN];
+
+const char *memif_errlist[ERRLIST_LEN] = { /* MEMIF_ERR_SUCCESS */
+ "Success.",
+ /* MEMIF_ERR_SYSCALL */
+ "Unspecified syscall error (build with -DMEMIF_DBG or make debug).",
+ /* MEMIF_ERR_ACCES */
+ "Permission to resoure denied.",
+ /* MEMIF_ERR_NO_FILE */
+ "Socket file does not exist",
+ /* MEMIF_ERR_FILE_LIMIT */
+ "System limit on total numer of open files reached.",
+ /* MEMIF_ERR_PROC_FILE_LIMIT */
+ "Per-process limit on total number of open files reached.",
+ /* MEMIF_ERR_ALREADY */
+ "Connection already requested.",
+ /* MEMIF_ERR_AGAIN */
+ "File descriptor refers to file other than socket, or operation would block.",
+ /* MEMIF_ERR_BAD_FD */
+ "Bad file descriptor.",
+ /* MEMIF_ERR_NOMEM */
+ "Out of memory.",
+ /* MEMIF_ERR_INVAL_ARG */
+ "Invalid argument.",
+ /* MEMIF_ERR_NOCONN */
+ "Memif connection handle does not point to existing conenction",
+ /* MEMIF_ERR_CONN */
+ "Memif connection handle points to existing connection",
+ /* MEMIF_ERR_CB_FDUPDATE */
+ "Callback memif_control_fd_update_t returned error",
+ /* MEMIF_ERR_FILE_NOT_SOCK */
+ "File specified by socket filename exists and is not socket.",
+ /* MEMIF_ERR_NO_SHMFD */
+ "Missing shared memory file descriptor. (internal error)",
+ /* MEMIF_ERR_COOKIE */
+ "Invalid cookie on ring. (internal error)",
+ /* MEMIF_ERR_NOBUF_RING */
+ "Ring buffer full.",
+ /* MEMIF_ERR_NOBUF */
+ "Not enough memif buffers. There are unreceived data in shared memory.",
+ /* MEMIF_ERR_NOBUF_DET */
+ "Not enough space for memif details in suplied buffer. String data might be malformed.",
+ /* MEMIF_ERR_INT_WRITE */
+ "Send interrupt error.",
+ /* MEMIF_ERR_MFMSG */
+ "Malformed message received on control channel.",
+ /* MEMIF_ERR_QID */
+ "Invalid queue id",
+ /* MEMIF_ERR_PROTO */
+ "Incompatible memory interface protocol version.",
+ /* MEMIF_ERR_ID */
+ "Unmatched interface id.",
+ /* MEMIF_ERR_ACCSLAVE */
+ "Slave cannot accept connection reqest.",
+ /* MEMIF_ERR_ALRCONN */
+ "Interface is already connected.",
+ /* MEMIF_ERR_MODE */
+ "Mode mismatch.",
+ /* MEMIF_ERR_SECRET */
+ "Secret mismatch.",
+ /* MEMIF_ERR_NOSECRET */
+ "Secret required.",
+ /* MEMIF_ERR_MAXREG */
+ "Limit on total number of regions reached.",
+ /* MEMIF_ERR_MAXRING */
+ "Limit on total number of ring reached.",
+ /* MEMIF_ERR_NO_INTFD */
+ "Missing interrupt file descriptor. (internal error)",
+ /* MEMIF_ERR_DISCONNECT */
+ "Interface received disconnect request.",
+ /* MEMIF_ERR_DISCONNECTED */
+ "Interface is disconnected.",
+ /* MEMIF_ERR_UNKNOWN_MSG */
+ "Unknown message type received on control channel. (internal error)"
+};
+
+#define MEMIF_ERR_UNDEFINED "undefined error"
+
+char *
+memif_strerror (int err_code)
+{
+ if (err_code >= ERRLIST_LEN)
+ {
+ strncpy (memif_buf, MEMIF_ERR_UNDEFINED, strlen (MEMIF_ERR_UNDEFINED));
+ memif_buf[strlen (MEMIF_ERR_UNDEFINED)] = '\0';
+ }
+ else
+ {
+ strncpy (memif_buf, memif_errlist[err_code],
+ strlen (memif_errlist[err_code]));
+ memif_buf[strlen (memif_errlist[err_code])] = '\0';
+ }
+ return memif_buf;
+}
+
+#define DBG_TX_BUF (0)
+#define DBG_RX_BUF (1)
+
+#ifdef MEMIF_DBG_SHM
+static void
+print_bytes (void *data, uint16_t len, uint8_t q)
+{
+ if (q == DBG_TX_BUF)
+ printf ("\nTX:\n\t");
+ else
+ printf ("\nRX:\n\t");
+ int i;
+ for (i = 0; i < len; i++)
+ {
+ if (i % 8 == 0)
+ printf ("\n%d:\t", i);
+ printf ("%02X ", ((uint8_t *) (data))[i]);
+ }
+ printf ("\n\n");
+}
+#endif /* MEMIF_DBG_SHM */
+
+int
+memif_syscall_error_handler (int err_code)
+{
+ DBG_UNIX ("%s", strerror (err_code));
+
+ if (err_code == 0)
+ return MEMIF_ERR_SUCCESS;
+ if (err_code == EACCES)
+ return MEMIF_ERR_ACCES;
+ if (err_code == ENFILE)
+ return MEMIF_ERR_FILE_LIMIT;
+ if (err_code == EMFILE)
+ return MEMIF_ERR_PROC_FILE_LIMIT;
+ if (err_code == ENOMEM)
+ return MEMIF_ERR_NOMEM;
+/* connection refused if master dows not exist
+ this error would spam the user until master was created */
+ if (err_code == ECONNREFUSED)
+ return MEMIF_ERR_SUCCESS;
+ if (err_code == EALREADY)
+ return MEMIF_ERR_ALREADY;
+ if (err_code == EAGAIN)
+ return MEMIF_ERR_AGAIN;
+ if (err_code == EBADF)
+ return MEMIF_ERR_BAD_FD;
+ if (err_code == ENOENT)
+ return MEMIF_ERR_NO_FILE;
+
+ /* other syscall errors */
+ return MEMIF_ERR_SYSCALL;
+}
+
+static int
+memif_add_epoll_fd (int fd, uint32_t events)
+{
+ if (fd < 0)
+ {
+ DBG ("invalid fd %d", fd);
+ return -1;
+ }
+ struct epoll_event evt;
+ memset (&evt, 0, sizeof (evt));
+ evt.events = events;
+ evt.data.fd = fd;
+ if (epoll_ctl (memif_epfd, EPOLL_CTL_ADD, fd, &evt) < 0)
+ {
+ DBG ("epoll_ctl: %s fd %d", strerror (errno), fd);
+ return -1;
+ }
+ DBG ("fd %d added to epoll", fd);
+ return 0;
+}
+
+static int
+memif_mod_epoll_fd (int fd, uint32_t events)
+{
+ if (fd < 0)
+ {
+ DBG ("invalid fd %d", fd);
+ return -1;
+ }
+ struct epoll_event evt;
+ memset (&evt, 0, sizeof (evt));
+ evt.events = events;
+ evt.data.fd = fd;
+ if (epoll_ctl (memif_epfd, EPOLL_CTL_MOD, fd, &evt) < 0)
+ {
+ DBG ("epoll_ctl: %s fd %d", strerror (errno), fd);
+ return -1;
+ }
+ DBG ("fd %d moddified on epoll", fd);
+ return 0;
+}
+
+static int
+memif_del_epoll_fd (int fd)
+{
+ if (fd < 0)
+ {
+ DBG ("invalid fd %d", fd);
+ return -1;
+ }
+ struct epoll_event evt;
+ memset (&evt, 0, sizeof (evt));
+ if (epoll_ctl (memif_epfd, EPOLL_CTL_DEL, fd, &evt) < 0)
+ {
+ DBG ("epoll_ctl: %s fd %d", strerror (errno), fd);
+ return -1;
+ }
+ DBG ("fd %d removed from epoll", fd);
+ return 0;
+}
+
+int
+memif_control_fd_update (int fd, uint8_t events)
+{
+ if (events & MEMIF_FD_EVENT_DEL)
+ return memif_del_epoll_fd (fd);
+
+ uint32_t evt = 0;
+ if (events & MEMIF_FD_EVENT_READ)
+ evt |= EPOLLIN;
+ if (events & MEMIF_FD_EVENT_WRITE)
+ evt |= EPOLLOUT;
+
+ if (events & MEMIF_FD_EVENT_MOD)
+ return memif_mod_epoll_fd (fd, evt);
+
+ return memif_add_epoll_fd (fd, evt);
+}
+
+int
+add_list_elt (memif_list_elt_t * e, memif_list_elt_t ** list, uint16_t * len)
+{
+ libmemif_main_t *lm = &libmemif_main;
+
+ int i;
+ for (i = 0; i < *len; i++)
+ {
+ if ((*list)[i].data_struct == NULL)
+ {
+ (*list)[i].key = e->key;
+ (*list)[i].data_struct = e->data_struct;
+ return i;
+ }
+ }
+ memif_list_elt_t *tmp;
+ tmp = realloc (*list, sizeof (memif_list_elt_t) * *len * 2);
+ if (tmp == NULL)
+ return -1;
+
+ for (i = *len; i < *len * 2; i++)
+ {
+ tmp[i].key = -1;
+ tmp[i].data_struct = NULL;
+ }
+
+ tmp[*len].key = e->key;
+ tmp[*len].data_struct = e->data_struct;
+ i = *len;
+ *len = *len * 2;
+ *list = tmp;
+
+ return i;
+}
+
+int
+get_list_elt (memif_list_elt_t ** e, memif_list_elt_t * list, uint16_t len,
+ int key)
+{
+ if (key == -1)
+ {
+ *e = NULL;
+ return -1;
+ }
+ int i;
+ for (i = 0; i < len; i++)
+ {
+ if (list[i].key == key)
+ {
+ *e = &list[i];
+ return 0;
+ }
+ }
+ *e = NULL;
+ return -1;
+}
+
+/* does not free memory, only marks element as free */
+int
+free_list_elt (memif_list_elt_t * list, uint16_t len, int key)
+{
+ int i;
+ for (i = 0; i < len; i++)
+ {
+ if (list[i].key == key)
+ {
+ list[i].key = -1;
+ list[i].data_struct = NULL;
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
+int
+free_list_elt_ctx (memif_list_elt_t * list, uint16_t len,
+ memif_connection_t * ctx)
+{
+ int i;
+ for (i = 0; i < len; i++)
+ {
+ if (list[i].key == -1)
+ {
+ if (list[i].data_struct == ctx)
+ {
+ list[i].data_struct = NULL;
+ return 0;
+ }
+ }
+ }
+
+ return -1;
+}
+
+static void
+memif_control_fd_update_register (memif_control_fd_update_t * cb)
+{
+ libmemif_main_t *lm = &libmemif_main;
+ lm->control_fd_update = cb;
+}
+
+int
+memif_init (memif_control_fd_update_t * on_control_fd_update, char *app_name)
+{
+ int err = MEMIF_ERR_SUCCESS; /* 0 */
+ libmemif_main_t *lm = &libmemif_main;
+
+ if (app_name)
+ {
+ lm->app_name = malloc (strlen (app_name) + sizeof (char));
+ memset (lm->app_name, 0, strlen (app_name) + sizeof (char));
+ strncpy ((char *) lm->app_name, app_name, strlen (app_name));
+ }
+ else
+ {
+ lm->app_name = malloc (strlen (MEMIF_DEFAULT_APP_NAME) + sizeof (char));
+ memset (lm->app_name, 0, strlen (app_name) + sizeof (char));
+ strncpy ((char *) lm->app_name, MEMIF_DEFAULT_APP_NAME,
+ strlen (MEMIF_DEFAULT_APP_NAME));
+ }
+
+ /* register control fd update callback */
+ if (on_control_fd_update != NULL)
+ memif_control_fd_update_register (on_control_fd_update);
+ else
+ {
+ memif_epfd = epoll_create (1);
+ memif_control_fd_update_register (memif_control_fd_update);
+ DBG ("libmemif event polling initialized");
+ }
+
+ memset (&lm->ms, 0, sizeof (memif_socket_t));
+
+ lm->control_list_len = 2;
+ lm->interrupt_list_len = 2;
+ lm->listener_list_len = 1;
+ lm->pending_list_len = 1;
+
+ lm->control_list =
+ malloc (sizeof (memif_list_elt_t) * lm->control_list_len);
+ lm->interrupt_list =
+ malloc (sizeof (memif_list_elt_t) * lm->interrupt_list_len);
+ lm->listener_list =
+ malloc (sizeof (memif_list_elt_t) * lm->listener_list_len);
+ lm->pending_list =
+ malloc (sizeof (memif_list_elt_t) * lm->pending_list_len);
+
+ int i;
+ for (i = 0; i < lm->control_list_len; i++)
+ {
+ lm->control_list[i].key = -1;
+ lm->control_list[i].data_struct = NULL;
+ }
+ for (i = 0; i < lm->interrupt_list_len; i++)
+ {
+ lm->interrupt_list[i].key = -1;
+ lm->interrupt_list[i].data_struct = NULL;
+ }
+ for (i = 0; i < lm->listener_list_len; i++)
+ {
+ lm->listener_list[i].key = -1;
+ lm->listener_list[i].data_struct = NULL;
+ }
+ for (i = 0; i < lm->pending_list_len; i++)
+ {
+ lm->pending_list[i].key = -1;
+ lm->pending_list[i].data_struct = NULL;
+ }
+
+ lm->disconn_slaves = 0;
+
+ lm->timerfd = timerfd_create (CLOCK_REALTIME, TFD_NONBLOCK);
+ if (lm->timerfd < 0)
+ {
+ err = errno;
+ DBG ("timerfd: %s", strerror (err));
+ return memif_syscall_error_handler (err);
+ }
+
+ lm->arm.it_value.tv_sec = 2;
+ lm->arm.it_value.tv_nsec = 0;
+ lm->arm.it_interval.tv_sec = 2;
+ lm->arm.it_interval.tv_nsec = 0;
+ memset (&lm->disarm, 0, sizeof (lm->disarm));
+
+ if (lm->control_fd_update (lm->timerfd, MEMIF_FD_EVENT_READ) < 0)
+ {
+ DBG ("callback type memif_control_fd_update_t error!");
+ return MEMIF_ERR_CB_FDUPDATE;
+ }
+
+ return 0;
+}
+
+static inline memif_ring_t *
+memif_get_ring (memif_connection_t * conn, memif_ring_type_t type,
+ uint16_t ring_num)
+{
+ if (&conn->regions[0] == NULL)
+ return NULL;
+ void *p = conn->regions[0].shm;
+ int ring_size =
+ sizeof (memif_ring_t) +
+ sizeof (memif_desc_t) * (1 << conn->run_args.log2_ring_size);
+ p += (ring_num + type * conn->run_args.num_s2m_rings) * ring_size;
+
+ return (memif_ring_t *) p;
+}
+
+int
+memif_set_rx_mode (memif_conn_handle_t c, memif_rx_mode_t rx_mode,
+ uint16_t qid)
+{
+ memif_connection_t *conn = (memif_connection_t *) c;
+ if (conn == NULL)
+ return MEMIF_ERR_NOCONN;
+ uint8_t num =
+ (conn->args.is_master) ? conn->run_args.num_s2m_rings : conn->run_args.
+ num_m2s_rings;
+ if (qid >= num)
+ return MEMIF_ERR_QID;
+
+ conn->rx_queues[qid].ring->flags = rx_mode;
+ DBG ("rx_mode flag: %u", conn->rx_queues[qid].ring->flags);
+ return MEMIF_ERR_SUCCESS;
+}
+
+int
+memif_create (memif_conn_handle_t * c, memif_conn_args_t * args,
+ memif_connection_update_t * on_connect,
+ memif_connection_update_t * on_disconnect,
+ memif_interrupt_t * on_interrupt, void *private_ctx)
+{
+ int err, i, index, sockfd = -1;
+ memif_list_elt_t list_elt;
+ memif_connection_t *conn = (memif_connection_t *) * c;
+ if (conn != NULL)
+ {
+ DBG ("This handle already points to existing memif.");
+ return MEMIF_ERR_CONN;
+ }
+ conn = (memif_connection_t *) malloc (sizeof (memif_connection_t));
+ if (conn == NULL)
+ {
+ err = memif_syscall_error_handler (errno);
+ goto error;
+ }
+ memset (conn, 0, sizeof (memif_connection_t));
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ conn->args.interface_id = args->interface_id;
+
+ if (args->log2_ring_size == 0)
+ args->log2_ring_size = MEMIF_DEFAULT_LOG2_RING_SIZE;
+ if (args->buffer_size == 0)
+ args->buffer_size = MEMIF_DEFAULT_BUFFER_SIZE;
+ if (args->num_s2m_rings == 0)
+ args->num_s2m_rings = MEMIF_DEFAULT_TX_QUEUES;
+ if (args->num_m2s_rings == 0)
+ args->num_m2s_rings = MEMIF_DEFAULT_RX_QUEUES;
+
+ conn->args.num_s2m_rings = args->num_s2m_rings;
+ conn->args.num_m2s_rings = args->num_m2s_rings;
+ conn->args.buffer_size = args->buffer_size;
+ conn->args.log2_ring_size = args->log2_ring_size;
+ conn->args.is_master = args->is_master;
+ conn->args.mode = args->mode;
+ conn->msg_queue = NULL;
+ conn->regions = NULL;
+ conn->tx_queues = NULL;
+ conn->rx_queues = NULL;
+ conn->fd = -1;
+ conn->on_connect = on_connect;
+ conn->on_disconnect = on_disconnect;
+ conn->on_interrupt = on_interrupt;
+ conn->private_ctx = private_ctx;
+ memset (&conn->run_args, 0, sizeof (memif_conn_run_args_t));
+
+ uint8_t l = strlen ((char *) args->interface_name);
+ strncpy ((char *) conn->args.interface_name, (char *) args->interface_name,
+ l);
+
+ l = strlen ((char *) args->instance_name);
+ strncpy ((char *) conn->args.instance_name, (char *) args->instance_name,
+ l);
+
+ /* allocate and initialize socket_filename so it can be copyed to sun_path
+ without memory leaks */
+ conn->args.socket_filename = malloc (sizeof (char *) * 108);
+ memset (conn->args.socket_filename, 0, 108 * sizeof (char *));
+
+ if (args->socket_filename)
+ {
+ if (conn->args.socket_filename == NULL)
+ {
+ err = memif_syscall_error_handler (errno);
+ goto error;
+ }
+ strncpy ((char *) conn->args.socket_filename,
+ (char *) args->socket_filename,
+ strlen ((char *) args->socket_filename));
+ }
+ else
+ {
+ uint16_t sdl = strlen (MEMIF_DEFAULT_SOCKET_DIR);
+ uint16_t sfl = strlen (MEMIF_DEFAULT_SOCKET_FILENAME);
+ if (conn->args.socket_filename == NULL)
+ {
+ err = memif_syscall_error_handler (errno);
+ goto error;
+ }
+ strncpy ((char *) conn->args.socket_filename,
+ MEMIF_DEFAULT_SOCKET_DIR, sdl);
+ conn->args.socket_filename[sdl] = '/';
+ strncpy ((char *) (conn->args.socket_filename + 1 + sdl),
+ MEMIF_DEFAULT_SOCKET_FILENAME, sfl);
+ }
+
+ if (args->secret)
+ {
+ l = strlen ((char *) args->secret);
+ strncpy ((char *) conn->args.secret, (char *) args->secret, l);
+ }
+
+ if (conn->args.is_master)
+ {
+ conn->run_args.buffer_size = conn->args.buffer_size;
+ memif_socket_t *ms;
+ memif_list_elt_t elt;
+ for (i = 0; i < lm->listener_list_len; i++)
+ {
+ if ((ms =
+ (memif_socket_t *) lm->listener_list[i].data_struct) != NULL)
+ {
+ if (strncmp
+ ((char *) ms->filename, (char *) conn->args.socket_filename,
+ strlen ((char *) ms->filename)) == 0)
+ {
+ /* add interface to listener socket */
+ elt.key = conn->args.interface_id;
+ *c = elt.data_struct = conn;
+ add_list_elt (&elt, &ms->interface_list,
+ &ms->interface_list_len);
+ ms->use_count++;
+ conn->listener_fd = ms->fd;
+ break;
+ }
+ }
+ else
+ {
+ struct stat file_stat;
+ if (stat ((char *) conn->args.socket_filename, &file_stat) == 0)
+ {
+ if (S_ISSOCK (file_stat.st_mode))
+ unlink ((char *) conn->args.socket_filename);
+ else
+ return memif_syscall_error_handler (errno);
+ }
+ DBG ("creating socket file");
+ ms = malloc (sizeof (memif_socket_t));
+ ms->filename =
+ malloc (strlen ((char *) conn->args.socket_filename) +
+ sizeof (char));
+ memset (ms->filename, 0,
+ strlen ((char *) conn->args.socket_filename) +
+ sizeof (char));
+ strncpy ((char *) ms->filename,
+ (char *) conn->args.socket_filename,
+ strlen ((char *) conn->args.socket_filename));
+ ms->interface_list_len = 1;
+ ms->interface_list =
+ malloc (sizeof (memif_list_elt_t) * ms->interface_list_len);
+ ms->interface_list[0].key = -1;
+ ms->interface_list[0].data_struct = NULL;
+ struct sockaddr_un un = { 0 };
+ int on = 1;
+
+ ms->fd = socket (AF_UNIX, SOCK_SEQPACKET, 0);
+ if (ms->fd < 0)
+ {
+ err = memif_syscall_error_handler (errno);
+ goto error;
+ }
+ DBG ("socket %d created", ms->fd);
+ un.sun_family = AF_UNIX;
+ strncpy ((char *) un.sun_path, (char *) ms->filename,
+ sizeof (un.sun_path) - 1);
+ DBG ("sockopt");
+ if (setsockopt
+ (ms->fd, SOL_SOCKET, SO_PASSCRED, &on, sizeof (on)) < 0)
+ {
+ err = memif_syscall_error_handler (errno);
+ goto error;
+ }
+ DBG ("bind");
+ if (bind (ms->fd, (struct sockaddr *) &un, sizeof (un)) < 0)
+ {
+ err = memif_syscall_error_handler (errno);
+ goto error;
+ }
+ DBG ("listen");
+ if (listen (ms->fd, 1) < 0)
+ {
+ err = memif_syscall_error_handler (errno);
+ goto error;
+ }
+ DBG ("stat");
+ if (stat ((char *) ms->filename, &file_stat) < 0)
+ {
+ err = memif_syscall_error_handler (errno);
+ goto error;
+ }
+
+ /* add interface to listener socket */
+ elt.key = conn->args.interface_id;
+ *c = elt.data_struct = conn;
+ add_list_elt (&elt, &ms->interface_list,
+ &ms->interface_list_len);
+ ms->use_count = 1;
+ conn->listener_fd = ms->fd;
+
+ /* add listener socket to libmemif main */
+ elt.key = ms->fd;
+ elt.data_struct = ms;
+ add_list_elt (&elt, &lm->listener_list, &lm->listener_list_len);
+ lm->control_fd_update (ms->fd, MEMIF_FD_EVENT_READ);
+ break;
+ }
+ }
+ }
+ else
+ {
+ if (lm->disconn_slaves == 0)
+ {
+ if (timerfd_settime (lm->timerfd, 0, &lm->arm, NULL) < 0)
+ {
+ err = memif_syscall_error_handler (errno);
+ goto error;
+ }
+ }
+
+ lm->disconn_slaves++;
+
+ list_elt.key = -1;
+ *c = list_elt.data_struct = conn;
+ if ((index =
+ add_list_elt (&list_elt, &lm->control_list,
+ &lm->control_list_len)) < 0)
+ {
+ err = MEMIF_ERR_NOMEM;
+ goto error;
+ }
+ }
+
+ conn->index = index;
+
+ return 0;
+
+error:
+ if (sockfd > 0)
+ close (sockfd);
+ sockfd = -1;
+ if (conn->args.socket_filename)
+ free (conn->args.socket_filename);
+ if (conn != NULL)
+ free (conn);
+ *c = conn = NULL;
+ return err;
+}
+
+int
+memif_control_fd_handler (int fd, uint8_t events)
+{
+ int i, rv, sockfd = -1, err = MEMIF_ERR_SUCCESS; /* 0 */
+ uint16_t num;
+ memif_list_elt_t *e = NULL;
+ memif_connection_t *conn;
+ libmemif_main_t *lm = &libmemif_main;
+ if (fd == lm->timerfd)
+ {
+ uint64_t b;
+ ssize_t size;
+ size = read (fd, &b, sizeof (b));
+ for (i = 0; i < lm->control_list_len; i++)
+ {
+ if ((lm->control_list[i].key < 0)
+ && (lm->control_list[i].data_struct != NULL))
+ {
+ conn = lm->control_list[i].data_struct;
+ if (conn->args.is_master)
+ continue;
+
+ struct sockaddr_un sun;
+ sockfd = socket (AF_UNIX, SOCK_SEQPACKET, 0);
+ if (sockfd < 0)
+ {
+ err = memif_syscall_error_handler (errno);
+ goto error;
+ }
+
+ sun.sun_family = AF_UNIX;
+
+ strncpy (sun.sun_path, conn->args.socket_filename,
+ sizeof (sun.sun_path) - 1);
+
+ if (connect (sockfd, (struct sockaddr *) &sun,
+ sizeof (struct sockaddr_un)) == 0)
+ {
+ conn->fd = sockfd;
+ conn->read_fn = memif_conn_fd_read_ready;
+ conn->write_fn = memif_conn_fd_write_ready;
+ conn->error_fn = memif_conn_fd_error;
+
+ lm->control_list[conn->index].key = conn->fd;
+
+ lm->control_fd_update (sockfd,
+ MEMIF_FD_EVENT_READ |
+ MEMIF_FD_EVENT_WRITE);
+
+ lm->disconn_slaves--;
+ if (lm->disconn_slaves == 0)
+ {
+ if (timerfd_settime (lm->timerfd, 0, &lm->disarm, NULL)
+ < 0)
+ {
+ err = memif_syscall_error_handler (errno);
+ goto error;
+ }
+ }
+ }
+ else
+ {
+ err = memif_syscall_error_handler (errno);
+ goto error;
+ }
+ }
+ }
+ }
+ else
+ {
+ get_list_elt (&e, lm->interrupt_list, lm->interrupt_list_len, fd);
+ if (e != NULL)
+ {
+ if (((memif_connection_t *) e->data_struct)->on_interrupt != NULL)
+ {
+ num =
+ (((memif_connection_t *) e->data_struct)->args.
+ is_master) ? ((memif_connection_t *) e->data_struct)->
+ run_args.num_s2m_rings : ((memif_connection_t *) e->
+ data_struct)->run_args.
+ num_m2s_rings;
+ for (i = 0; i < num; i++)
+ {
+ if (((memif_connection_t *) e->data_struct)->rx_queues[i].
+ int_fd == fd)
+ {
+ ((memif_connection_t *) e->
+ data_struct)->on_interrupt ((void *) e->data_struct,
+ ((memif_connection_t *)
+ e->data_struct)->
+ private_ctx, i);
+ return MEMIF_ERR_SUCCESS;
+ }
+ }
+ }
+ return MEMIF_ERR_SUCCESS;
+ }
+ get_list_elt (&e, lm->listener_list, lm->listener_list_len, fd);
+ if (e != NULL)
+ {
+ memif_conn_fd_accept_ready ((memif_socket_t *) e->data_struct);
+ return MEMIF_ERR_SUCCESS;
+ }
+
+ get_list_elt (&e, lm->pending_list, lm->pending_list_len, fd);
+ if (e != NULL)
+ {
+ memif_read_ready (fd);
+ return MEMIF_ERR_SUCCESS;
+ }
+
+ get_list_elt (&e, lm->control_list, lm->control_list_len, fd);
+ if (e != NULL)
+ {
+ if (events & MEMIF_FD_EVENT_READ)
+ {
+ err =
+ ((memif_connection_t *) e->data_struct)->read_fn (e->
+ data_struct);
+ if (err != MEMIF_ERR_SUCCESS)
+ return err;
+ }
+ if (events & MEMIF_FD_EVENT_WRITE)
+ {
+ err =
+ ((memif_connection_t *) e->data_struct)->write_fn (e->
+ data_struct);
+ if (err != MEMIF_ERR_SUCCESS)
+ return err;
+ }
+ if (events & MEMIF_FD_EVENT_ERROR)
+ {
+ err =
+ ((memif_connection_t *) e->data_struct)->error_fn (e->
+ data_struct);
+ if (err != MEMIF_ERR_SUCCESS)
+ return err;
+ }
+ }
+ }
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+
+error:
+ if (sockfd > 0)
+ close (sockfd);
+ sockfd = -1;
+ return err;
+}
+
+int
+memif_poll_event (int timeout)
+{
+ libmemif_main_t *lm = &libmemif_main;
+ memif_list_elt_t *elt;
+ struct epoll_event evt, *e;
+ int en = 0, err = MEMIF_ERR_SUCCESS, i = 0; /* 0 */
+ uint16_t num;
+ uint32_t events = 0;
+ memset (&evt, 0, sizeof (evt));
+ evt.events = EPOLLIN | EPOLLOUT;
+ sigset_t sigset;
+ sigemptyset (&sigset);
+ en = epoll_pwait (memif_epfd, &evt, 1, timeout, &sigset);
+ if (en < 0)
+ {
+ DBG ("epoll_pwait: %s", strerror (errno));
+ return -1;
+ }
+ if (en > 0)
+ {
+ if (evt.events & EPOLLIN)
+ events |= MEMIF_FD_EVENT_READ;
+ if (evt.events & EPOLLOUT)
+ events |= MEMIF_FD_EVENT_WRITE;
+ if (evt.events & EPOLLERR)
+ events |= MEMIF_FD_EVENT_ERROR;
+ err = memif_control_fd_handler (evt.data.fd, events);
+ return err;
+ }
+ return 0;
+}
+
+static void
+memif_msg_queue_free (memif_msg_queue_elt_t ** e)
+{
+ if (*e == NULL)
+ return;
+ memif_msg_queue_free (&(*e)->next);
+ free (*e);
+ *e = NULL;
+ return;
+}
+
+/* send disconnect msg and close interface */
+int
+memif_disconnect_internal (memif_connection_t * c)
+{
+ if (c == NULL)
+ {
+ DBG ("no connection");
+ return MEMIF_ERR_NOCONN;
+ }
+ uint16_t num;
+ int err = MEMIF_ERR_SUCCESS, i; /* 0 */
+ memif_queue_t *mq;
+ libmemif_main_t *lm = &libmemif_main;
+ memif_list_elt_t *e;
+
+ c->on_disconnect ((void *) c, c->private_ctx);
+
+ if (c->fd > 0)
+ {
+ memif_msg_send_disconnect (c->fd, "interface deleted", 0);
+ lm->control_fd_update (c->fd, MEMIF_FD_EVENT_DEL);
+ close (c->fd);
+ }
+ get_list_elt (&e, lm->control_list, lm->control_list_len, c->fd);
+ if (e != NULL)
+ {
+ if (c->args.is_master)
+ free_list_elt (lm->control_list, lm->control_list_len, c->fd);
+ e->key = c->fd = -1;
+ }
+
+ if (c->tx_queues != NULL)
+ {
+ num =
+ (c->args.is_master) ? c->run_args.num_m2s_rings : c->run_args.
+ num_s2m_rings;
+ for (i = 0; i < num; i++)
+ {
+ mq = &c->tx_queues[i];
+ if (mq != NULL)
+ {
+ if (mq->int_fd > 0)
+ close (mq->int_fd);
+ free_list_elt (lm->interrupt_list, lm->interrupt_list_len,
+ mq->int_fd);
+ mq->int_fd = -1;
+ }
+ }
+ free (c->tx_queues);
+ c->tx_queues = NULL;
+ }
+
+ if (c->rx_queues != NULL)
+ {
+ num =
+ (c->args.is_master) ? c->run_args.num_s2m_rings : c->run_args.
+ num_m2s_rings;
+ for (i = 0; i < num; i++)
+ {
+ mq = &c->rx_queues[i];
+ if (mq != NULL)
+ {
+ if (mq->int_fd > 0)
+ {
+ if (c->on_interrupt != NULL)
+ lm->control_fd_update (mq->int_fd, MEMIF_FD_EVENT_DEL);
+ close (mq->int_fd);
+ }
+ free_list_elt (lm->interrupt_list, lm->interrupt_list_len,
+ mq->int_fd);
+ mq->int_fd = -1;
+ }
+ }
+ free (c->rx_queues);
+ c->rx_queues = NULL;
+ }
+
+ if (c->regions != NULL)
+ {
+ if (munmap (c->regions[0].shm, c->regions[0].region_size) < 0)
+ return memif_syscall_error_handler (errno);
+ if (c->regions[0].fd > 0)
+ close (c->regions[0].fd);
+ c->regions[0].fd = -1;
+ free (c->regions);
+ c->regions = NULL;
+ }
+
+ memset (&c->run_args, 0, sizeof (memif_conn_run_args_t));
+
+ memif_msg_queue_free (&c->msg_queue);
+
+ if (!(c->args.is_master))
+ {
+ if (lm->disconn_slaves == 0)
+ {
+ if (timerfd_settime (lm->timerfd, 0, &lm->arm, NULL) < 0)
+ {
+ err = memif_syscall_error_handler (errno);
+ DBG_UNIX ("timerfd_settime: arm");
+ }
+ }
+ lm->disconn_slaves++;
+ }
+
+ return err;
+}
+
+int
+memif_delete (memif_conn_handle_t * conn)
+{
+ memif_connection_t *c = (memif_connection_t *) * conn;
+ if (c == NULL)
+ {
+ DBG ("no connection");
+ return MEMIF_ERR_NOCONN;
+ }
+ libmemif_main_t *lm = &libmemif_main;
+ memif_list_elt_t *e = NULL;
+ memif_socket_t *ms = NULL;
+
+ int err = MEMIF_ERR_SUCCESS;
+
+ if (c->fd > 0)
+ {
+ DBG ("DISCONNECTING");
+ err = memif_disconnect_internal (c);
+ if (err == MEMIF_ERR_NOCONN)
+ return err;
+ }
+
+ free_list_elt_ctx (lm->control_list, lm->control_list_len, c);
+
+ if (c->args.is_master)
+ {
+ get_list_elt (&e, lm->listener_list, lm->listener_list_len,
+ c->listener_fd);
+ if (e != NULL)
+ {
+ ms = (memif_socket_t *) e->data_struct;
+ ms->use_count--;
+ free_list_elt (ms->interface_list, ms->interface_list_len,
+ c->args.interface_id);
+ if (ms->use_count <= 0)
+ {
+ lm->control_fd_update (c->listener_fd, MEMIF_FD_EVENT_DEL);
+ free_list_elt (lm->listener_list, lm->listener_list_len,
+ c->listener_fd);
+ close (c->listener_fd);
+ c->listener_fd = ms->fd = -1;
+ free (ms->interface_list);
+ ms->interface_list = NULL;
+ free (ms->filename);
+ ms->filename = NULL;
+ free (ms);
+ ms = NULL;
+ }
+ }
+ }
+ else
+ {
+ lm->disconn_slaves--;
+ if (lm->disconn_slaves <= 0)
+ {
+ if (timerfd_settime (lm->timerfd, 0, &lm->disarm, NULL) < 0)
+ {
+ err = memif_syscall_error_handler (errno);
+ DBG ("timerfd_settime: disarm");
+ }
+ }
+ }
+
+ if (c->args.socket_filename)
+ free (c->args.socket_filename);
+ c->args.socket_filename = NULL;
+
+ free (c);
+ c = NULL;
+
+ *conn = c;
+ return err;
+}
+
+int
+memif_connect1 (memif_connection_t * c)
+{
+ libmemif_main_t *lm = &libmemif_main;
+ memif_region_t *mr = c->regions;
+ memif_queue_t *mq;
+ int i;
+ uint16_t num;
+
+ if (mr != NULL)
+ {
+ if (!mr->shm)
+ {
+ if (mr->fd < 0)
+ return MEMIF_ERR_NO_SHMFD;
+
+ if ((mr->shm = mmap (NULL, mr->region_size, PROT_READ | PROT_WRITE,
+ MAP_SHARED, mr->fd, 0)) == MAP_FAILED)
+ {
+ return memif_syscall_error_handler (errno);
+ }
+ }
+ }
+
+ num =
+ (c->args.is_master) ? c->run_args.num_m2s_rings : c->run_args.
+ num_s2m_rings;
+ for (i = 0; i < num; i++)
+ {
+ mq = &c->tx_queues[i];
+ if (mq != NULL)
+ {
+ mq->ring = c->regions[mq->region].shm + mq->offset;
+ if (mq->ring->cookie != MEMIF_COOKIE)
+ {
+ DBG ("wrong cookie on tx ring %u", i);
+ return MEMIF_ERR_COOKIE;
+ }
+ mq->ring->head = mq->ring->tail = mq->last_head = mq->alloc_bufs =
+ 0;
+ }
+ }
+ num =
+ (c->args.is_master) ? c->run_args.num_s2m_rings : c->run_args.
+ num_m2s_rings;
+ for (i = 0; i < num; i++)
+ {
+ mq = &c->rx_queues[i];
+ if (mq != NULL)
+ {
+ mq->ring = c->regions[mq->region].shm + mq->offset;
+ if (mq->ring->cookie != MEMIF_COOKIE)
+ {
+ DBG ("wrong cookie on rx ring %u", i);
+ return MEMIF_ERR_COOKIE;
+ }
+ mq->ring->head = mq->ring->tail = mq->last_head = mq->alloc_bufs =
+ 0;
+ }
+ }
+
+ lm->control_fd_update (c->fd, MEMIF_FD_EVENT_READ | MEMIF_FD_EVENT_MOD);
+
+ return 0;
+}
+
+int
+memif_init_regions_and_queues (memif_connection_t * conn)
+{
+ memif_ring_t *ring = NULL;
+ uint64_t buffer_offset;
+ memif_region_t *r;
+ int i, j;
+ libmemif_main_t *lm = &libmemif_main;
+ memif_list_elt_t e;
+
+ conn->regions = (memif_region_t *) malloc (sizeof (memif_region_t));
+ if (conn->regions == NULL)
+ return memif_syscall_error_handler (errno);
+ r = conn->regions;
+
+ buffer_offset =
+ (conn->run_args.num_s2m_rings +
+ conn->run_args.num_m2s_rings) * (sizeof (memif_ring_t) +
+ sizeof (memif_desc_t) *
+ (1 << conn->run_args.log2_ring_size));
+
+ r->region_size = buffer_offset +
+ conn->run_args.buffer_size * (1 << conn->run_args.log2_ring_size) *
+ (conn->run_args.num_s2m_rings + conn->run_args.num_m2s_rings);
+
+ if ((r->fd = memfd_create ("memif region 0", MFD_ALLOW_SEALING)) == -1)
+ return memif_syscall_error_handler (errno);
+/*
+ if ((fcntl (r->fd, F_ADD_SEALS, F_SEAL_SHRINK)) == -1)
+ return memif_syscall_error_handler (errno);
+*/
+ if ((ftruncate (r->fd, r->region_size)) == -1)
+ return memif_syscall_error_handler (errno);
+
+ if ((r->shm = mmap (NULL, r->region_size, PROT_READ | PROT_WRITE,
+ MAP_SHARED, r->fd, 0)) == MAP_FAILED)
+ return memif_syscall_error_handler (errno);
+
+ for (i = 0; i < conn->run_args.num_s2m_rings; i++)
+ {
+ ring = memif_get_ring (conn, MEMIF_RING_S2M, i);
+ DBG ("RING: %p I: %d", ring, i);
+ ring->head = ring->tail = 0;
+ ring->cookie = MEMIF_COOKIE;
+ ring->flags = 0;
+ for (j = 0; j < (1 << conn->run_args.log2_ring_size); j++)
+ {
+ uint16_t slot = i * (1 << conn->run_args.log2_ring_size) + j;
+ ring->desc[j].region = 0;
+ ring->desc[j].offset = buffer_offset +
+ (uint32_t) (slot * conn->run_args.buffer_size);
+ ring->desc[j].buffer_length = conn->run_args.buffer_size;
+ }
+ }
+ for (i = 0; i < conn->run_args.num_m2s_rings; i++)
+ {
+ ring = memif_get_ring (conn, MEMIF_RING_M2S, i);
+ DBG ("RING: %p I: %d", ring, i);
+ ring->head = ring->tail = 0;
+ ring->cookie = MEMIF_COOKIE;
+ ring->flags = 0;
+ for (j = 0; j < (1 << conn->run_args.log2_ring_size); j++)
+ {
+ uint16_t slot =
+ (i +
+ conn->run_args.num_s2m_rings) *
+ (1 << conn->run_args.log2_ring_size) + j;
+ ring->desc[j].region = 0;
+ ring->desc[j].offset = buffer_offset +
+ (uint32_t) (slot * conn->run_args.buffer_size);
+ ring->desc[j].buffer_length = conn->run_args.buffer_size;
+ }
+ }
+ memif_queue_t *mq;
+ mq =
+ (memif_queue_t *) malloc (sizeof (memif_queue_t) *
+ conn->run_args.num_s2m_rings);
+ if (mq == NULL)
+ return memif_syscall_error_handler (errno);
+ int x;
+ for (x = 0; x < conn->run_args.num_s2m_rings; x++)
+ {
+ if ((mq[x].int_fd = eventfd (0, EFD_NONBLOCK)) < 0)
+ return memif_syscall_error_handler (errno);
+ /* add int fd to interrupt fd list */
+ e.key = mq[x].int_fd;
+ e.data_struct = conn;
+ add_list_elt (&e, &lm->interrupt_list, &lm->interrupt_list_len);
+
+ mq[x].ring = memif_get_ring (conn, MEMIF_RING_S2M, x);
+ DBG ("RING: %p I: %d", mq[x].ring, x);
+ mq[x].log2_ring_size = conn->run_args.log2_ring_size;
+ mq[x].region = 0;
+ mq[x].offset =
+ (void *) mq[x].ring - (void *) conn->regions[mq->region].shm;
+ mq[x].last_head = 0;
+ mq[x].alloc_bufs = 0;
+ }
+ conn->tx_queues = mq;
+
+ mq =
+ (memif_queue_t *) malloc (sizeof (memif_queue_t) *
+ conn->run_args.num_m2s_rings);
+ if (mq == NULL)
+ return memif_syscall_error_handler (errno);
+ for (x = 0; x < conn->run_args.num_m2s_rings; x++)
+ {
+ if ((mq[x].int_fd = eventfd (0, EFD_NONBLOCK)) < 0)
+ return memif_syscall_error_handler (errno);
+ /* add int fd to interrupt fd list */
+ e.key = mq[x].int_fd;
+ e.data_struct = conn;
+ add_list_elt (&e, &lm->interrupt_list, &lm->interrupt_list_len);
+
+ mq[x].ring = memif_get_ring (conn, MEMIF_RING_M2S, x);
+ DBG ("RING: %p I: %d", mq[x].ring, x);
+ mq[x].log2_ring_size = conn->run_args.log2_ring_size;
+ mq[x].region = 0;
+ mq[x].offset =
+ (void *) mq[x].ring - (void *) conn->regions[mq->region].shm;
+ mq[x].last_head = 0;
+ mq[x].alloc_bufs = 0;
+ }
+ conn->rx_queues = mq;
+
+ return 0;
+}
+
+int
+memif_buffer_alloc (memif_conn_handle_t conn, uint16_t qid,
+ memif_buffer_t * bufs, uint16_t count,
+ uint16_t * count_out, uint16_t size)
+{
+ memif_connection_t *c = (memif_connection_t *) conn;
+ if (c == NULL)
+ return MEMIF_ERR_NOCONN;
+ if (c->fd < 0)
+ return MEMIF_ERR_DISCONNECTED;
+ uint8_t num =
+ (c->args.is_master) ? c->run_args.num_m2s_rings : c->run_args.
+ num_s2m_rings;
+ if (qid >= num)
+ return MEMIF_ERR_QID;
+ memif_queue_t *mq = &c->tx_queues[qid];
+ memif_ring_t *ring = mq->ring;
+ memif_buffer_t *b0, *b1;
+ uint8_t chain_buf0, chain_buf1;
+ uint16_t mask = (1 << mq->log2_ring_size) - 1;
+ uint16_t s0, s1, ns;
+ *count_out = 0;
+ int i, err = MEMIF_ERR_SUCCESS; /* 0 */
+
+ if (ring->tail != ring->head)
+ {
+ if (ring->head > ring->tail)
+ ns = (1 << mq->log2_ring_size) - ring->head + ring->tail;
+ else
+ ns = ring->tail - ring->head;
+ }
+ else
+ ns = (1 << mq->log2_ring_size);
+
+ /* (head == tail) ? receive function will asume that no packets are available */
+ ns -= 1;
+
+ while (count && ns)
+ {
+ while ((count > 2) && (ns > 2))
+ {
+ s0 = (ring->head + mq->alloc_bufs) & mask;
+ chain_buf0 = size / ring->desc[s0].buffer_length;
+ if (((size % ring->desc[s0].buffer_length) != 0) || (size == 0))
+ chain_buf0++;
+
+ if (chain_buf0 > ns)
+ break;
+
+ s1 = (ring->head + mq->alloc_bufs + chain_buf0) & mask;
+ chain_buf1 = size / ring->desc[s1].buffer_length;
+ if (((size % ring->desc[s1].buffer_length) != 0) || (size == 0))
+ chain_buf1++;
+
+ if ((chain_buf0 + chain_buf1) > ns)
+ break;
+
+ b0 = (bufs + *count_out);
+ b1 = (bufs + *count_out + 1);
+
+ b0->desc_index = s0;
+ b1->desc_index = s1;
+ ring->desc[s0].flags = 0;
+ ring->desc[s1].flags = 0;
+ b0->buffer_len = ring->desc[s0].buffer_length * chain_buf0;
+ b1->buffer_len = ring->desc[s1].buffer_length * chain_buf1;
+ /* TODO: support multiple regions -> ring descriptor contains region index */
+ b0->data = c->regions->shm + ring->desc[s0].offset;
+ b1->data = c->regions->shm + ring->desc[s1].offset;
+
+ for (i = 0; i < (memif_min (chain_buf0, chain_buf1) - 1); i++)
+ {
+ ring->desc[(s0 + i) & mask].flags |= MEMIF_DESC_FLAG_NEXT;
+ ring->desc[(s1 + i) & mask].flags |= MEMIF_DESC_FLAG_NEXT;
+ DBG ("allocating chained buffers");
+ }
+
+ if (chain_buf0 > chain_buf1)
+ {
+ for (; i < (chain_buf0 - 1); i++)
+ ring->desc[(s0 + i) & mask].flags |= MEMIF_DESC_FLAG_NEXT;
+ }
+ else
+ {
+ for (; i < (chain_buf1 - 1); i++)
+ ring->desc[(s1 + i) & mask].flags |= MEMIF_DESC_FLAG_NEXT;
+ }
+
+ mq->alloc_bufs += chain_buf0 + chain_buf1;
+
+ DBG ("allocated ring slots %u, %u", s0, s1);
+ count -= 2;
+ ns -= chain_buf0 + chain_buf1;
+ *count_out += 2;
+ }
+ s0 = (ring->head + mq->alloc_bufs) & mask;
+
+ b0 = (bufs + *count_out);
+
+ chain_buf0 = size / ring->desc[s0].buffer_length;
+ if (((size % ring->desc[s0].buffer_length) != 0) || (size == 0))
+ chain_buf0++;
+
+ if (chain_buf0 > ns)
+ break;
+
+ b0->desc_index = s0;
+ ring->desc[s0].flags = 0;
+ b0->buffer_len = ring->desc[s0].buffer_length * chain_buf0;
+ b0->data = c->regions->shm + ring->desc[s0].offset;
+
+ for (i = 0; i < (chain_buf0 - 1); i++)
+ {
+ ring->desc[(s0 + i) & mask].flags |= MEMIF_DESC_FLAG_NEXT;
+ DBG ("allocating chained buffers");
+ }
+
+ mq->alloc_bufs += chain_buf0;
+
+ DBG ("allocated ring slot %u", s0);
+ count--;
+ ns -= chain_buf0;
+ *count_out += 1;
+ }
+
+ DBG ("allocated: %u/%u bufs. Total %u allocated bufs", *count_out, count,
+ mq->alloc_bufs);
+
+ if (count)
+ {
+ DBG ("ring buffer full! qid: %u", qid);
+ err = MEMIF_ERR_NOBUF_RING;
+ }
+
+ return err;
+}
+
+int
+memif_buffer_free (memif_conn_handle_t conn, uint16_t qid,
+ memif_buffer_t * bufs, uint16_t count,
+ uint16_t * count_out)
+{
+ memif_connection_t *c = (memif_connection_t *) conn;
+ if (c == NULL)
+ return MEMIF_ERR_NOCONN;
+ if (c->fd < 0)
+ return MEMIF_ERR_DISCONNECTED;
+ uint8_t num =
+ (c->args.is_master) ? c->run_args.num_s2m_rings : c->run_args.
+ num_m2s_rings;
+ if (qid >= num)
+ return MEMIF_ERR_QID;
+ libmemif_main_t *lm = &libmemif_main;
+ memif_queue_t *mq = &c->rx_queues[qid];
+ memif_ring_t *ring = mq->ring;
+ uint16_t tail = ring->tail;
+ uint16_t mask = (1 << mq->log2_ring_size) - 1;
+ uint8_t chain_buf0, chain_buf1;
+ memif_buffer_t *b0, *b1;
+ *count_out = 0;
+
+ if (mq->alloc_bufs < count)
+ count = mq->alloc_bufs;
+
+ while (count)
+ {
+ while (count > 2)
+ {
+ b0 = (bufs + *count_out);
+ b1 = (bufs + *count_out + 1);
+ chain_buf0 =
+ b0->buffer_len / ring->desc[b0->desc_index].buffer_length;
+ if ((b0->buffer_len % ring->desc[b0->desc_index].buffer_length) !=
+ 0)
+ chain_buf0++;
+ chain_buf1 =
+ b1->buffer_len / ring->desc[b1->desc_index].buffer_length;
+ if ((b1->buffer_len % ring->desc[b1->desc_index].buffer_length) !=
+ 0)
+ chain_buf1++;
+ tail = (b1->desc_index + chain_buf1) & mask;
+ b0->data = NULL;
+ b1->data = NULL;
+
+ count -= 2;
+ *count_out += 2;
+ mq->alloc_bufs -= chain_buf0 + chain_buf1;
+ }
+ b0 = (bufs + *count_out);
+ chain_buf0 = b0->buffer_len / ring->desc[b0->desc_index].buffer_length;
+ if ((b0->buffer_len % ring->desc[b0->desc_index].buffer_length) != 0)
+ chain_buf0++;
+ tail = (b0->desc_index + chain_buf0) & mask;
+ b0->data = NULL;
+
+ count--;
+ *count_out += 1;
+ mq->alloc_bufs -= chain_buf0;
+ }
+ MEMIF_MEORY_BARRIER ();
+ ring->tail = tail;
+ DBG ("tail: %u", ring->tail);
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
+
+int
+memif_tx_burst (memif_conn_handle_t conn, uint16_t qid,
+ memif_buffer_t * bufs, uint16_t count, uint16_t * tx)
+{
+ memif_connection_t *c = (memif_connection_t *) conn;
+ if (c == NULL)
+ return MEMIF_ERR_NOCONN;
+ if (c->fd < 0)
+ return MEMIF_ERR_DISCONNECTED;
+ uint8_t num =
+ (c->args.is_master) ? c->run_args.num_m2s_rings : c->run_args.
+ num_s2m_rings;
+ if (qid >= num)
+ return MEMIF_ERR_QID;
+ memif_queue_t *mq = &c->tx_queues[qid];
+ memif_ring_t *ring = mq->ring;
+ uint16_t head = ring->head;
+ uint16_t mask = (1 << mq->log2_ring_size) - 1;
+ uint8_t chain_buf0, chain_buf1;
+ *tx = 0;
+ uint16_t curr_buf = 0;
+ memif_buffer_t *b0, *b1;
+ int i;
+
+ while (count)
+ {
+ while (count > 2)
+ {
+ b0 = (bufs + curr_buf);
+ b1 = (bufs + curr_buf + 1);
+ chain_buf0 =
+ b0->buffer_len / ring->desc[b0->desc_index].buffer_length;
+ if ((b0->buffer_len % ring->desc[b0->desc_index].buffer_length) !=
+ 0)
+ chain_buf0++;
+
+ chain_buf1 =
+ b1->buffer_len / ring->desc[b1->desc_index].buffer_length;
+ if ((b1->buffer_len % ring->desc[b1->desc_index].buffer_length) !=
+ 0)
+ chain_buf1++;
+
+ for (i = 0; i < memif_min (chain_buf0, chain_buf1); i++)
+ {
+ /* b0 */
+ if (b0->data_len >
+ ring->desc[(b0->desc_index + i) & mask].buffer_length)
+ {
+ b0->data_len -=
+ ring->desc[(b0->desc_index + i) & mask].length =
+ ring->desc[(b0->desc_index + i) & mask].buffer_length;
+ }
+ else
+ {
+ ring->desc[(b0->desc_index + i) & mask].length =
+ b0->data_len;
+ b0->data_len = 0;
+ }
+ /* b1 */
+ if (b1->data_len >
+ ring->desc[(b1->desc_index + i) & mask].buffer_length)
+ {
+ b1->data_len -=
+ ring->desc[(b1->desc_index + i) & mask].length =
+ ring->desc[(b1->desc_index + i) & mask].buffer_length;
+ }
+ else
+ {
+ ring->desc[(b1->desc_index + i) & mask].length =
+ b1->data_len;
+ b1->data_len = 0;
+ }
+#ifdef MEMIF_DBG_SHM
+ print_bytes (b0->data +
+ ring->desc[(b0->desc_index +
+ i) & mask].buffer_length *
+ (chain_buf0 - 1),
+ ring->desc[(b0->desc_index +
+ i) & mask].buffer_length, DBG_TX_BUF);
+ print_bytes (b1->data +
+ ring->desc[(b1->desc_index +
+ i) & mask].buffer_length *
+ (chain_buf1 - 1),
+ ring->desc[(b1->desc_index +
+ i) & mask].buffer_length, DBG_TX_BUF);
+#endif /* MEMIF_DBG_SHM */
+ }
+
+ if (chain_buf0 > chain_buf1)
+ {
+ for (; i < chain_buf0; i++)
+ {
+ if (b0->data_len >
+ ring->desc[(b0->desc_index + i) & mask].buffer_length)
+ {
+ b0->data_len -=
+ ring->desc[(b0->desc_index + i) & mask].length =
+ ring->desc[(b0->desc_index + i) & mask].buffer_length;
+ }
+ else
+ {
+ ring->desc[(b0->desc_index + i) & mask].length =
+ b0->data_len;
+ b0->data_len = 0;
+ }
+#ifdef MEMIF_DBG_SHM
+ print_bytes (b0->data +
+ ring->desc[(b0->desc_index +
+ i) & mask].buffer_length *
+ (chain_buf0 - 1),
+ ring->desc[(b0->desc_index +
+ i) & mask].buffer_length,
+ DBG_TX_BUF);
+#endif /* MEMIF_DBG_SHM */
+ }
+ }
+ else
+ {
+ for (; i < chain_buf1; i++)
+ {
+ if (b1->data_len >
+ ring->desc[(b1->desc_index + i) & mask].buffer_length)
+ {
+ b1->data_len -=
+ ring->desc[(b1->desc_index + i) & mask].length =
+ ring->desc[(b1->desc_index + i) & mask].buffer_length;
+ }
+ else
+ {
+ ring->desc[(b1->desc_index + i) & mask].length =
+ b1->data_len;
+ b1->data_len = 0;
+ }
+#ifdef MEMIF_DBG_SHM
+ print_bytes (b1->data +
+ ring->desc[(b1->desc_index +
+ i) & mask].buffer_length *
+ (chain_buf1 - 1),
+ ring->desc[(b1->desc_index +
+ i) & mask].buffer_length,
+ DBG_TX_BUF);
+#endif /* MEMIF_DBG_SHM */
+ }
+ }
+
+ head = (b1->desc_index + chain_buf1) & mask;
+
+ b0->data = NULL;
+#ifdef MEMIF_DBG
+ if (b0->data_len != 0)
+ DBG ("invalid b0 data length!");
+#endif /* MEMIF_DBG */
+ b1->data = NULL;
+#ifdef MEMIF_DBG
+ if (b1->data_len != 0)
+ DBG ("invalid b1 data length!");
+#endif /* MEMIF_DBG */
+
+ count -= 2;
+ *tx += chain_buf0 + chain_buf1;
+ curr_buf += 2;
+ }
+
+ b0 = (bufs + curr_buf);
+ chain_buf0 = b0->buffer_len / ring->desc[b0->desc_index].buffer_length;
+ if ((b0->buffer_len % ring->desc[b0->desc_index].buffer_length) != 0)
+ chain_buf0++;
+
+ for (i = 0; i < chain_buf0; i++)
+ {
+ if (b0->data_len >
+ ring->desc[(b0->desc_index + i) & mask].buffer_length)
+ {
+ b0->data_len -= ring->desc[(b0->desc_index + i) & mask].length =
+ ring->desc[(b0->desc_index + i) & mask].buffer_length;
+ }
+ else
+ {
+ ring->desc[(b0->desc_index + i) & mask].length = b0->data_len;
+ b0->data_len = 0;
+ }
+#ifdef MEMIF_DBG_SHM
+ print_bytes (b0->data +
+ ring->desc[(b0->desc_index + i) & mask].buffer_length *
+ (chain_buf0 - 1),
+ ring->desc[(b0->desc_index + i) & mask].buffer_length,
+ DBG_TX_BUF);
+#endif /* MEMIF_DBG_SHM */
+ }
+
+ head = (b0->desc_index + chain_buf0) & mask;
+
+ b0->data = NULL;
+#ifdef MEMIF_DBG
+ if (b0->data_len != 0)
+ DBG ("invalid b0 data length!");
+#endif /* MEMIF_DBG */
+
+ count--;
+ *tx += chain_buf0;
+ curr_buf++;
+ }
+ MEMIF_MEORY_BARRIER ();
+ ring->head = head;
+
+ mq->alloc_bufs -= *tx;
+
+ /* TODO: return num of buffers and packets */
+ *tx = curr_buf;
+
+ if ((ring->flags & MEMIF_RING_FLAG_MASK_INT) == 0)
+ {
+ uint64_t a = 1;
+ int r = write (mq->int_fd, &a, sizeof (a));
+ if (r < 0)
+ return MEMIF_ERR_INT_WRITE;
+ }
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
+
+int
+memif_rx_burst (memif_conn_handle_t conn, uint16_t qid,
+ memif_buffer_t * bufs, uint16_t count, uint16_t * rx)
+{
+ memif_connection_t *c = (memif_connection_t *) conn;
+ if (c == NULL)
+ return MEMIF_ERR_NOCONN;
+ if (c->fd < 0)
+ return MEMIF_ERR_DISCONNECTED;
+ uint8_t num =
+ (c->args.is_master) ? c->run_args.num_s2m_rings : c->run_args.
+ num_m2s_rings;
+ if (qid >= num)
+ return MEMIF_ERR_QID;
+ memif_queue_t *mq = &c->rx_queues[qid];
+ memif_ring_t *ring = mq->ring;
+ uint16_t head = ring->head;
+ uint16_t ns;
+ uint16_t mask = (1 << mq->log2_ring_size) - 1;
+ memif_buffer_t *b0, *b1;
+ uint16_t curr_buf = 0;
+ *rx = 0;
+ int i;
+
+ uint64_t b;
+ ssize_t r = read (mq->int_fd, &b, sizeof (b));
+ if ((r == -1) && (errno != EAGAIN))
+ return memif_syscall_error_handler (errno);
+
+ if (head == mq->last_head)
+ return 0;
+
+ if (head > mq->last_head)
+ ns = head - mq->last_head;
+ else
+ ns = (1 << mq->log2_ring_size) - mq->last_head + head;
+
+ while (ns && count)
+ {
+ DBG ("ns: %u, count: %u", ns, count);
+ while ((ns > 2) && (count > 2))
+ {
+ b0 = (bufs + curr_buf);
+ b1 = (bufs + curr_buf + 1);
+
+ b0->desc_index = mq->last_head;
+ i = 0;
+ b0->data_len = 0;
+ b0->buffer_len = 0;
+
+ b0->data = memif_get_buffer (conn, ring, mq->last_head);
+ b0->data_len += ring->desc[mq->last_head].length;
+ b0->buffer_len += ring->desc[mq->last_head].buffer_length;
+#ifdef MEMIF_DBG_SHM
+ print_bytes (b0->data +
+ ring->desc[b0->desc_index].buffer_length * i++,
+ ring->desc[b0->desc_index].buffer_length, DBG_TX_BUF);
+#endif /* MEMIF_DBG_SHM */
+ ns--;
+ *rx += 1;
+ while (ring->desc[mq->last_head].flags & MEMIF_DESC_FLAG_NEXT)
+ {
+ ring->desc[mq->last_head].flags &= ~MEMIF_DESC_FLAG_NEXT;
+ mq->last_head = (mq->last_head + 1) & mask;
+ b0->data_len += ring->desc[mq->last_head].length;
+ b0->buffer_len += ring->desc[mq->last_head].buffer_length;
+#ifdef MEMIF_DBG_SHM
+ print_bytes (b0->data +
+ ring->desc[b0->desc_index].buffer_length * i++,
+ ring->desc[b0->desc_index].buffer_length,
+ DBG_TX_BUF);
+#endif /* MEMIF_DBG_SHM */
+ ns--;
+ *rx += 1;
+ }
+ mq->last_head = (mq->last_head + 1) & mask;
+
+ b1->desc_index = mq->last_head;
+ i = 0;
+ b0->data_len = 0;
+ b0->buffer_len = 0;
+
+ b1->data = memif_get_buffer (conn, ring, mq->last_head);
+ b1->data_len += ring->desc[mq->last_head].length;
+ b1->buffer_len += ring->desc[mq->last_head].buffer_length;
+#ifdef MEMIF_DBG_SHM
+ print_bytes (b1->data +
+ ring->desc[b1->desc_index].buffer_length * i++,
+ ring->desc[b1->desc_index].buffer_length, DBG_TX_BUF);
+#endif /* MEMIF_DBG_SHM */
+ ns--;
+ *rx += 1;
+ while (ring->desc[mq->last_head].flags & MEMIF_DESC_FLAG_NEXT)
+ {
+ ring->desc[mq->last_head].flags &= ~MEMIF_DESC_FLAG_NEXT;
+ mq->last_head = (mq->last_head + 1) & mask;
+ b1->data_len += ring->desc[mq->last_head].length;
+ b1->buffer_len += ring->desc[mq->last_head].buffer_length;
+#ifdef MEMIF_DBG_SHM
+ print_bytes (b1->data +
+ ring->desc[b1->desc_index].buffer_length * i++,
+ ring->desc[b1->desc_index].buffer_length,
+ DBG_TX_BUF);
+#endif /* MEMIF_DBG_SHM */
+ ns--;
+ *rx += 1;
+ }
+ mq->last_head = (mq->last_head + 1) & mask;
+
+ count -= 2;
+ curr_buf += 2;
+ }
+ b0 = (bufs + curr_buf);
+
+ b0->desc_index = mq->last_head;
+ i = 0;
+ b0->data_len = 0;
+ b0->buffer_len = 0;
+
+ b0->data = memif_get_buffer (conn, ring, mq->last_head);
+ b0->data_len += ring->desc[mq->last_head].length;
+ b0->buffer_len += ring->desc[mq->last_head].buffer_length;
+#ifdef MEMIF_DBG_SHM
+ print_bytes (b0->data +
+ ring->desc[b0->desc_index].buffer_length * i++,
+ ring->desc[b0->desc_index].buffer_length, DBG_TX_BUF);
+#endif /* MEMIF_DBG_SHM */
+ ns--;
+ *rx += 1;
+
+ while (ring->desc[mq->last_head].flags & MEMIF_DESC_FLAG_NEXT)
+ {
+ ring->desc[mq->last_head].flags &= ~MEMIF_DESC_FLAG_NEXT;
+ mq->last_head = (mq->last_head + 1) & mask;
+ b0->data_len += ring->desc[mq->last_head].length;
+ b0->buffer_len += ring->desc[mq->last_head].buffer_length;
+#ifdef MEMIF_DBG_SHM
+ print_bytes (b0->data +
+ ring->desc[b0->desc_index].buffer_length * i++,
+ ring->desc[b0->desc_index].buffer_length, DBG_TX_BUF);
+#endif /* MEMIF_DBG_SHM */
+ ns--;
+ *rx += 1;
+ }
+ mq->last_head = (mq->last_head + 1) & mask;
+
+ count--;
+ curr_buf++;
+ }
+
+ mq->alloc_bufs += *rx;
+
+ /* TODO: return num of buffers and packets */
+ *rx = curr_buf;
+
+ if (ns)
+ {
+ DBG ("not enough buffers!");
+ return MEMIF_ERR_NOBUF;
+ }
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
+
+int
+memif_get_details (memif_conn_handle_t conn, memif_details_t * md,
+ char *buf, ssize_t buflen)
+{
+ memif_connection_t *c = (memif_connection_t *) conn;
+ if (c == NULL)
+ return MEMIF_ERR_NOCONN;
+
+ int err = MEMIF_ERR_SUCCESS, i;
+ ssize_t l0, l1, total_l;
+ l0 = 0;
+
+ l1 = strlen ((char *) c->args.interface_name);
+ if (l0 + l1 <= buflen)
+ {
+ md->if_name = strncpy (buf + l0, (char *) c->args.interface_name, l1);
+ md->if_name[l0 + l1] = '\0';
+ l0 += l1 + 1;
+ }
+ else
+ err = MEMIF_ERR_NOBUF_DET;
+
+ l1 = strlen ((char *) c->args.instance_name);
+ if (l0 + l1 <= buflen)
+ {
+ md->inst_name = strncpy (buf + l0, (char *) c->args.instance_name, l1);
+ md->inst_name[l0 + l1] = '\0';
+ l0 += l1 + 1;
+ }
+ else
+ err = MEMIF_ERR_NOBUF_DET;
+
+ l1 = strlen ((char *) c->remote_if_name);
+ if (l0 + l1 <= buflen)
+ {
+ md->remote_if_name = strncpy (buf + l0, (char *) c->remote_if_name, l1);
+ md->remote_if_name[l0 + l1] = '\0';
+ l0 += l1 + 1;
+ }
+ else
+ err = MEMIF_ERR_NOBUF_DET;
+
+ l1 = strlen ((char *) c->remote_name);
+ if (l0 + l1 <= buflen)
+ {
+ md->remote_inst_name = strncpy (buf + l0, (char *) c->remote_name, l1);
+ md->remote_inst_name[l0 + l1] = '\0';
+ l0 += l1 + 1;
+ }
+ else
+ err = MEMIF_ERR_NOBUF_DET;
+
+ md->id = c->args.interface_id;
+
+ if (c->args.secret)
+ {
+ l1 = strlen ((char *) c->args.secret);
+ md->secret = strncpy (buf + l0, (char *) c->args.secret, l1);
+ md->secret[l0 + l1] = '\0';
+ l0 += l1 + 1;
+ }
+ else
+ err = MEMIF_ERR_NOBUF_DET;
+
+ md->role = (c->args.is_master) ? 0 : 1;
+ md->mode = c->args.mode;
+
+ l1 = strlen ((char *) c->args.socket_filename);
+ if (l0 + l1 <= buflen)
+ {
+ md->socket_filename =
+ strncpy (buf + l0, (char *) c->args.socket_filename, l1);
+ md->socket_filename[l0 + l1] = '\0';
+ l0 += l1 + 1;
+ }
+ else
+ err = MEMIF_ERR_NOBUF_DET;
+
+ md->rx_queues_num =
+ (c->args.is_master) ? c->run_args.num_s2m_rings : c->run_args.
+ num_m2s_rings;
+
+ l1 = sizeof (memif_queue_details_t) * md->rx_queues_num;
+ if (l0 + l1 <= buflen)
+ {
+ md->rx_queues = (memif_queue_details_t *) buf + l0;
+ l0 = l1 + 1;
+ }
+ else
+ err = MEMIF_ERR_NOBUF_DET;
+
+ for (i = 0; i < md->rx_queues_num; i++)
+ {
+ md->rx_queues[i].qid = i;
+ md->rx_queues[i].ring_size = (1 << c->rx_queues[i].log2_ring_size);
+ md->rx_queues[i].buffer_size = c->run_args.buffer_size;
+ }
+
+ md->tx_queues_num =
+ (c->args.is_master) ? c->run_args.num_m2s_rings : c->run_args.
+ num_s2m_rings;
+
+ l1 = sizeof (memif_queue_details_t) * md->tx_queues_num;
+ if (l0 + l1 <= buflen)
+ {
+ md->tx_queues = (memif_queue_details_t *) buf + l0;
+ l0 = l1 + 1;
+ }
+ else
+ err = MEMIF_ERR_NOBUF_DET;
+
+ for (i = 0; i < md->tx_queues_num; i++)
+ {
+ md->tx_queues[i].qid = i;
+ md->tx_queues[i].ring_size = (1 << c->tx_queues[i].log2_ring_size);
+ md->tx_queues[i].buffer_size = c->run_args.buffer_size;
+ }
+
+ md->link_up_down = (c->fd > 0) ? 1 : 0;
+
+ return err; /* 0 */
+}
+
+int
+memif_get_queue_efd (memif_conn_handle_t conn, uint16_t qid, int *efd)
+{
+ memif_connection_t *c = (memif_connection_t *) conn;
+ *efd = -1;
+ if (c == NULL)
+ return MEMIF_ERR_NOCONN;
+ if (c->fd < 0)
+ return MEMIF_ERR_DISCONNECTED;
+ uint8_t num =
+ (c->args.is_master) ? c->run_args.num_s2m_rings : c->run_args.
+ num_m2s_rings;
+ if (qid >= num)
+ return MEMIF_ERR_QID;
+
+ *efd = c->rx_queues[qid].int_fd;
+
+ return MEMIF_ERR_SUCCESS;
+}
+
+int
+memif_cleanup ()
+{
+ libmemif_main_t *lm = &libmemif_main;
+ if (lm->app_name)
+ free (lm->app_name);
+ lm->app_name = NULL;
+ if (lm->control_list)
+ free (lm->control_list);
+ lm->control_list = NULL;
+ if (lm->interrupt_list)
+ free (lm->interrupt_list);
+ lm->interrupt_list = NULL;
+ if (lm->listener_list)
+ free (lm->listener_list);
+ lm->listener_list = NULL;
+ if (lm->pending_list)
+ free (lm->pending_list);
+ lm->pending_list = NULL;
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
diff --git a/extras/libmemif/src/memif.h b/extras/libmemif/src/memif.h
new file mode 100644
index 00000000..11918eab
--- /dev/null
+++ b/extras/libmemif/src/memif.h
@@ -0,0 +1,185 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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 _MEMIF_H_
+#define _MEMIF_H_
+
+#ifndef MEMIF_CACHELINE_SIZE
+#define MEMIF_CACHELINE_SIZE 64
+#endif
+
+#define MEMIF_COOKIE 0x3E31F10
+#define MEMIF_VERSION_MAJOR 1
+#define MEMIF_VERSION_MINOR 0
+#define MEMIF_VERSION ((MEMIF_VERSION_MAJOR << 8) | MEMIF_VERSION_MINOR)
+
+/*
+ * Type definitions
+ */
+
+typedef enum memif_msg_type
+{
+ MEMIF_MSG_TYPE_NONE = 0,
+ MEMIF_MSG_TYPE_ACK = 1,
+ MEMIF_MSG_TYPE_HELLO = 2,
+ MEMIF_MSG_TYPE_INIT = 3,
+ MEMIF_MSG_TYPE_ADD_REGION = 4,
+ MEMIF_MSG_TYPE_ADD_RING = 5,
+ MEMIF_MSG_TYPE_CONNECT = 6,
+ MEMIF_MSG_TYPE_CONNECTED = 7,
+ MEMIF_MSG_TYPE_DISCONNECT = 8,
+} memif_msg_type_t;
+
+typedef enum
+{
+ MEMIF_RING_S2M = 0,
+ MEMIF_RING_M2S = 1
+} memif_ring_type_t;
+
+typedef enum
+{
+ MEMIF_INTERFACE_MODE_ETHERNET = 0,
+ MEMIF_INTERFACE_MODE_IP = 1,
+ MEMIF_INTERFACE_MODE_PUNT_INJECT = 2,
+} memif_interface_mode_t;
+
+typedef uint16_t memif_region_index_t;
+typedef uint64_t memif_region_offset_t;
+typedef uint64_t memif_region_size_t;
+typedef uint16_t memif_ring_index_t;
+typedef uint32_t memif_interface_id_t;
+typedef uint16_t memif_version_t;
+typedef uint8_t memif_log2_ring_size_t;
+
+/*
+ * Socket messages
+ */
+
+typedef struct __attribute__ ((packed))
+{
+ uint8_t name[32];
+ memif_version_t min_version;
+ memif_version_t max_version;
+ memif_region_index_t max_region;
+ memif_ring_index_t max_m2s_ring;
+ memif_ring_index_t max_s2m_ring;
+ memif_log2_ring_size_t max_log2_ring_size;
+} memif_msg_hello_t;
+
+typedef struct __attribute__ ((packed))
+{
+ memif_version_t version;
+ memif_interface_id_t id;
+ memif_interface_mode_t mode:8;
+ uint8_t secret[24];
+ uint8_t name[32];
+} memif_msg_init_t;
+
+typedef struct __attribute__ ((packed))
+{
+ memif_region_index_t index;
+ memif_region_size_t size;
+} memif_msg_add_region_t;
+
+typedef struct __attribute__ ((packed))
+{
+ uint16_t flags;
+#define MEMIF_MSG_ADD_RING_FLAG_S2M (1 << 0)
+ memif_ring_index_t index;
+ memif_region_index_t region;
+ memif_region_offset_t offset;
+ memif_log2_ring_size_t log2_ring_size;
+} memif_msg_add_ring_t;
+
+typedef struct __attribute__ ((packed))
+{
+ uint8_t if_name[32];
+} memif_msg_connect_t;
+
+typedef struct __attribute__ ((packed))
+{
+ uint8_t if_name[32];
+} memif_msg_connected_t;
+
+typedef struct __attribute__ ((packed))
+{
+ uint32_t code;
+ uint8_t string[96];
+} memif_msg_disconnect_t;
+
+typedef struct __attribute__ ((packed, aligned (128)))
+{
+ memif_msg_type_t type:16;
+ union
+ {
+ memif_msg_hello_t hello;
+ memif_msg_init_t init;
+ memif_msg_add_region_t add_region;
+ memif_msg_add_ring_t add_ring;
+ memif_msg_connect_t connect;
+ memif_msg_connected_t connected;
+ memif_msg_disconnect_t disconnect;
+ };
+} memif_msg_t;
+
+_Static_assert (sizeof (memif_msg_t) == 128,
+ "Size of memif_msg_t must be 128");
+
+/*
+ * Ring and Descriptor Layout
+ */
+
+typedef struct __attribute__ ((packed))
+{
+ uint16_t flags;
+#define MEMIF_DESC_FLAG_NEXT (1 << 0)
+ memif_region_index_t region;
+ uint32_t buffer_length;
+ uint32_t length;
+ uint8_t reserved[4];
+ memif_region_offset_t offset;
+ uint64_t metadata;
+} memif_desc_t;
+
+_Static_assert (sizeof (memif_desc_t) == 32,
+ "Size of memif_dsct_t must be 32");
+
+#define MEMIF_CACHELINE_ALIGN_MARK(mark) \
+ uint8_t mark[0] __attribute__((aligned(MEMIF_CACHELINE_SIZE)))
+
+typedef struct
+{
+ MEMIF_CACHELINE_ALIGN_MARK (cacheline0);
+ uint32_t cookie;
+ uint16_t flags;
+#define MEMIF_RING_FLAG_MASK_INT 1
+ volatile uint16_t head;
+ MEMIF_CACHELINE_ALIGN_MARK (cacheline1);
+ volatile uint16_t tail;
+ MEMIF_CACHELINE_ALIGN_MARK (cacheline2);
+ memif_desc_t desc[0];
+} memif_ring_t;
+
+#endif /* _MEMIF_H_ */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/extras/libmemif/src/memif_private.h b/extras/libmemif/src/memif_private.h
new file mode 100644
index 00000000..83962bcf
--- /dev/null
+++ b/extras/libmemif/src/memif_private.h
@@ -0,0 +1,266 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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 _MEMIF_PRIVATE_H_
+#define _MEMIF_PRIVATE_H_
+
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <sys/timerfd.h>
+
+#include <libmemif.h>
+
+#define MEMIF_DEFAULT_SOCKET_DIR "/run/vpp"
+#define MEMIF_DEFAULT_SOCKET_FILENAME "memif.sock"
+#define MEMIF_DEFAULT_RING_SIZE 1024
+#define MEMIF_DEFAULT_LOG2_RING_SIZE 10
+#define MEMIF_DEFAULT_RX_QUEUES 1
+#define MEMIF_DEFAULT_TX_QUEUES 1
+#define MEMIF_DEFAULT_BUFFER_SIZE 2048
+
+#define MEMIF_MAX_M2S_RING 255
+#define MEMIF_MAX_S2M_RING 255
+#define MEMIF_MAX_REGION 255
+#define MEMIF_MAX_LOG2_RING_SIZE 14
+
+#define MEMIF_MAX_FDS 512
+
+#define memif_min(a,b) (((a) < (b)) ? (a) : (b))
+
+#ifdef MEMIF_DBG
+#define DBG(...) do { \
+ printf("MEMIF_DEBUG:%s:%s:%d: ", __FILE__, __func__, __LINE__); \
+ printf(__VA_ARGS__); \
+ printf("\n"); \
+ } while (0)
+
+#define DBG_UNIX(...) do { \
+ printf("MEMIF_DEBUG_UNIX:%s:%s:%d: ", __FILE__, __func__, __LINE__); \
+ printf(__VA_ARGS__); \
+ printf("\n"); \
+ } while (0)
+
+#define error_return_unix(...) do { \
+ DBG_UNIX(__VA_ARGS__); \
+ return -1; \
+ } while (0)
+#define error_return(...) do { \
+ DBG(__VA_ARGS__); \
+ return -1; \
+ } while (0)
+#else
+#define DBG(...)
+#define DBG_UNIX(...)
+#define error_return_unix(...) do { \
+ return -1; \
+ } while (0)
+#define error_return(...) do { \
+ return -1; \
+ } while (0)
+
+#endif /* MEMIF_DBG */
+
+typedef struct
+{
+ void *shm;
+ uint32_t region_size;
+ int fd;
+} memif_region_t;
+
+typedef struct
+{
+ memif_ring_t *ring;
+ uint8_t log2_ring_size;
+ uint8_t region;
+ uint32_t offset;
+
+ uint16_t last_head;
+ uint16_t last_tail;
+
+ int int_fd;
+
+ uint64_t int_count;
+ uint32_t alloc_bufs;
+} memif_queue_t;
+
+typedef struct memif_msg_queue_elt
+{
+ memif_msg_t msg;
+ int fd;
+ struct memif_msg_queue_elt *next;
+} memif_msg_queue_elt_t;
+
+struct memif_connection;
+
+typedef struct memif_connection memif_connection_t;
+
+/* functions called by memif_control_fd_handler */
+typedef int (memif_fn) (memif_connection_t * conn);
+
+typedef struct
+{
+ uint8_t num_s2m_rings;
+ uint8_t num_m2s_rings;
+ uint16_t buffer_size;
+ memif_log2_ring_size_t log2_ring_size;
+} memif_conn_run_args_t;
+
+typedef struct memif_connection
+{
+ uint16_t index;
+ memif_conn_args_t args;
+ memif_conn_run_args_t run_args;
+
+ int fd;
+ int listener_fd;
+
+ memif_fn *write_fn, *read_fn, *error_fn;
+
+ memif_connection_update_t *on_connect, *on_disconnect;
+ memif_interrupt_t *on_interrupt;
+ void *private_ctx;
+
+ /* connection message queue */
+ memif_msg_queue_elt_t *msg_queue;
+
+ uint8_t remote_if_name[32];
+ uint8_t remote_name[32];
+ uint8_t remote_disconnect_string[96];
+
+ memif_region_t *regions;
+
+ memif_queue_t *rx_queues;
+ memif_queue_t *tx_queues;
+
+ uint16_t flags;
+#define MEMIF_CONNECTION_FLAG_WRITE (1 << 0)
+} memif_connection_t;
+
+/*
+ * WIP
+ */
+typedef struct
+{
+ int key; /* fd or id */
+ void *data_struct;
+} memif_list_elt_t;
+
+/*
+ * WIP
+ */
+typedef struct
+{
+ int fd;
+ uint16_t use_count;
+ uint8_t *filename;
+ uint16_t interface_list_len;
+ memif_list_elt_t *interface_list; /* memif master interfaces listening on this socket */
+} memif_socket_t;
+
+/*
+ * WIP
+ */
+/* probably function like memif_cleanup () will need to be called to close timerfd */
+typedef struct
+{
+ memif_control_fd_update_t *control_fd_update;
+ int timerfd;
+ struct itimerspec arm, disarm;
+ uint16_t disconn_slaves;
+ uint8_t *app_name;
+
+ /* master implementation... */
+ memif_socket_t ms;
+
+ uint16_t control_list_len;
+ uint16_t interrupt_list_len;
+ uint16_t listener_list_len;
+ uint16_t pending_list_len;
+ memif_list_elt_t *control_list;
+ memif_list_elt_t *interrupt_list;
+ memif_list_elt_t *listener_list;
+ memif_list_elt_t *pending_list;
+} libmemif_main_t;
+
+extern libmemif_main_t libmemif_main;
+extern int memif_epfd;
+
+/* main.c */
+
+/* if region doesn't contain shared memory, mmap region, check ring cookie */
+int memif_connect1 (memif_connection_t * c);
+
+/* memory map region, initalize rings and queues */
+int memif_init_regions_and_queues (memif_connection_t * c);
+
+int memif_disconnect_internal (memif_connection_t * c);
+
+/* map errno to memif error code */
+int memif_syscall_error_handler (int err_code);
+
+int add_list_elt (memif_list_elt_t * e, memif_list_elt_t ** list,
+ uint16_t * len);
+
+int get_list_elt (memif_list_elt_t ** e, memif_list_elt_t * list,
+ uint16_t len, int key);
+
+int free_list_elt (memif_list_elt_t * list, uint16_t len, int key);
+
+#ifndef __NR_memfd_create
+#if defined __x86_64__
+#define __NR_memfd_create 319
+#elif defined __arm__
+#define __NR_memfd_create 385
+#elif defined __aarch64__
+#define __NR_memfd_create 279
+#else
+#error "__NR_memfd_create unknown for this architecture"
+#endif
+#endif
+
+static inline int
+memfd_create (const char *name, unsigned int flags)
+{
+ return syscall (__NR_memfd_create, name, flags);
+}
+
+static inline void *
+memif_get_buffer (memif_connection_t * conn, memif_ring_t * ring,
+ uint16_t index)
+{
+ return (conn->regions[ring->desc[index].region].shm +
+ ring->desc[index].offset);
+}
+
+#ifndef F_LINUX_SPECIFIC_BASE
+#define F_LINUX_SPECIFIC_BASE 1024
+#endif
+#define MFD_ALLOW_SEALING 0x0002U
+#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
+#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
+
+#define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */
+#define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */
+#define F_SEAL_GROW 0x0004 /* prevent file from growing */
+#define F_SEAL_WRITE 0x0008 /* prevent writes */
+
+#endif /* _MEMIF_PRIVATE_H_ */
diff --git a/extras/libmemif/src/socket.c b/extras/libmemif/src/socket.c
new file mode 100644
index 00000000..ca24d929
--- /dev/null
+++ b/extras/libmemif/src/socket.c
@@ -0,0 +1,881 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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.
+ *------------------------------------------------------------------
+ */
+
+#define _GNU_SOURCE
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <sys/un.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
+#include <sys/uio.h>
+#include <sys/mman.h>
+#include <sys/prctl.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <socket.h>
+#include <memif.h>
+
+/* sends msg to socket */
+static_fn int
+memif_msg_send (int fd, memif_msg_t * msg, int afd)
+{
+ struct msghdr mh = { 0 };
+ struct iovec iov[1];
+ char ctl[CMSG_SPACE (sizeof (int))];
+ int rv, err = MEMIF_ERR_SUCCESS; /* 0 */
+
+ iov[0].iov_base = (void *) msg;
+ iov[0].iov_len = sizeof (memif_msg_t);
+ mh.msg_iov = iov;
+ mh.msg_iovlen = 1;
+
+ if (afd > 0)
+ {
+ struct cmsghdr *cmsg;
+ memset (&ctl, 0, sizeof (ctl));
+ mh.msg_control = ctl;
+ mh.msg_controllen = sizeof (ctl);
+ cmsg = CMSG_FIRSTHDR (&mh);
+ cmsg->cmsg_len = CMSG_LEN (sizeof (int));
+ cmsg->cmsg_level = SOL_SOCKET;
+ cmsg->cmsg_type = SCM_RIGHTS;
+ memcpy (CMSG_DATA (cmsg), &afd, sizeof (int));
+ }
+ rv = sendmsg (fd, &mh, 0);
+ if (rv < 0)
+ err = memif_syscall_error_handler (errno);
+ DBG ("Message type %u sent", msg->type);
+ return err;
+}
+
+/* response from memif master - master is ready to handle next message */
+static_fn int
+memif_msg_enq_ack (memif_connection_t * c)
+{
+ memif_msg_queue_elt_t *e =
+ (memif_msg_queue_elt_t *) malloc (sizeof (memif_msg_queue_elt_t));
+ if (e == NULL)
+ return memif_syscall_error_handler (errno);
+
+ memset (&e->msg, 0, sizeof (e->msg));
+ e->msg.type = MEMIF_MSG_TYPE_ACK;
+ e->fd = -1;
+
+ e->next = NULL;
+ if (c->msg_queue == NULL)
+ {
+ c->msg_queue = e;
+ return MEMIF_ERR_SUCCESS; /* 0 */
+ }
+
+ memif_msg_queue_elt_t *cur = c->msg_queue;
+ while (cur->next != NULL)
+ {
+ cur = cur->next;
+ }
+ cur->next = e;
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
+
+static_fn int
+memif_msg_send_hello (int fd)
+{
+ libmemif_main_t *lm = &libmemif_main;
+ memif_msg_t msg = { 0 };
+ memif_msg_hello_t *h = &msg.hello;
+ msg.type = MEMIF_MSG_TYPE_HELLO;
+ h->min_version = MEMIF_VERSION;
+ h->max_version = MEMIF_VERSION;
+ h->max_s2m_ring = MEMIF_MAX_M2S_RING;
+ h->max_m2s_ring = MEMIF_MAX_M2S_RING;
+ h->max_region = MEMIF_MAX_REGION;
+ h->max_log2_ring_size = MEMIF_MAX_LOG2_RING_SIZE;
+
+ strncpy ((char *) h->name, lm->app_name, strlen (lm->app_name));
+
+ /* msg hello is not enqueued but sent directly,
+ because it is the first msg to be sent */
+ return memif_msg_send (fd, &msg, -1);
+}
+
+/* send id and secret (optional) for interface identification */
+static_fn int
+memif_msg_enq_init (memif_connection_t * c)
+{
+ memif_msg_queue_elt_t *e =
+ (memif_msg_queue_elt_t *) malloc (sizeof (memif_msg_queue_elt_t));
+ if (e == NULL)
+ return memif_syscall_error_handler (errno);
+ memset (e, 0, sizeof (memif_msg_queue_elt_t));
+
+ memset (&e->msg, 0, sizeof (e->msg));
+ memif_msg_init_t *i = &e->msg.init;
+
+ e->msg.type = MEMIF_MSG_TYPE_INIT;
+ e->fd = -1;
+ i->version = MEMIF_VERSION;
+ i->id = c->args.interface_id;
+ i->mode = c->args.mode;
+
+ strncpy ((char *) i->name, (char *) c->args.instance_name,
+ strlen ((char *) c->args.instance_name));
+ if (c->args.secret)
+ strncpy ((char *) i->secret, (char *) c->args.secret, sizeof (i->secret));
+
+ e->next = NULL;
+ if (c->msg_queue == NULL)
+ {
+ c->msg_queue = e;
+ return MEMIF_ERR_SUCCESS; /* 0 */
+ }
+
+ memif_msg_queue_elt_t *cur = c->msg_queue;
+ while (cur->next != NULL)
+ {
+ cur = cur->next;
+ }
+ cur->next = e;
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
+
+/* send information about region specified by region_index */
+static_fn int
+memif_msg_enq_add_region (memif_connection_t * c, uint8_t region_index)
+{
+ /* maybe check if region is valid? */
+ memif_region_t *mr = &c->regions[region_index];
+
+ memif_msg_queue_elt_t *e =
+ (memif_msg_queue_elt_t *) malloc (sizeof (memif_msg_queue_elt_t));
+ if (e == NULL)
+ return memif_syscall_error_handler (errno);
+
+ memset (&e->msg, 0, sizeof (e->msg));
+ memif_msg_add_region_t *ar = &e->msg.add_region;
+
+ e->msg.type = MEMIF_MSG_TYPE_ADD_REGION;
+ e->fd = mr->fd;
+ ar->index = region_index;
+ ar->size = mr->region_size;
+
+ e->next = NULL;
+ if (c->msg_queue == NULL)
+ {
+ c->msg_queue = e;
+ return MEMIF_ERR_SUCCESS; /* 0 */
+ }
+
+ memif_msg_queue_elt_t *cur = c->msg_queue;
+ while (cur->next != NULL)
+ {
+ cur = cur->next;
+ }
+ cur->next = e;
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
+
+/* send information about ring specified by direction (S2M | M2S) and index */
+static_fn int
+memif_msg_enq_add_ring (memif_connection_t * c, uint8_t index, uint8_t dir)
+{
+ memif_msg_queue_elt_t *e =
+ (memif_msg_queue_elt_t *) malloc (sizeof (memif_msg_queue_elt_t));
+ if (e == NULL)
+ return memif_syscall_error_handler (errno);
+
+ memset (&e->msg, 0, sizeof (e->msg));
+ memif_msg_add_ring_t *ar = &e->msg.add_ring;
+
+ e->msg.type = MEMIF_MSG_TYPE_ADD_RING;
+
+ /* TODO: support multiple rings */
+ memif_queue_t *mq;
+ if (dir == MEMIF_RING_M2S)
+ mq = &c->rx_queues[index];
+ else
+ mq = &c->tx_queues[index];
+
+ e->fd = mq->int_fd;
+ ar->index = index;
+ ar->offset = mq->offset;
+ ar->region = mq->region;
+ ar->log2_ring_size = mq->log2_ring_size;
+ ar->flags = (dir == MEMIF_RING_S2M) ? MEMIF_MSG_ADD_RING_FLAG_S2M : 0;
+
+ e->next = NULL;
+ if (c->msg_queue == NULL)
+ {
+ c->msg_queue = e;
+ return MEMIF_ERR_SUCCESS; /* 0 */
+ }
+
+ memif_msg_queue_elt_t *cur = c->msg_queue;
+ while (cur->next != NULL)
+ {
+ cur = cur->next;
+ }
+ cur->next = e;
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
+
+/* used as connection request from slave */
+static_fn int
+memif_msg_enq_connect (memif_connection_t * c)
+{
+ memif_msg_queue_elt_t *e =
+ (memif_msg_queue_elt_t *) malloc (sizeof (memif_msg_queue_elt_t));
+ if (e == NULL)
+ return memif_syscall_error_handler (errno);
+
+ memset (&e->msg, 0, sizeof (e->msg));
+ memif_msg_connect_t *cm = &e->msg.connect;
+
+ e->msg.type = MEMIF_MSG_TYPE_CONNECT;
+ e->fd = -1;
+ strncpy ((char *) cm->if_name, (char *) c->args.interface_name,
+ strlen ((char *) c->args.interface_name));
+
+ e->next = NULL;
+ if (c->msg_queue == NULL)
+ {
+ c->msg_queue = e;
+ return MEMIF_ERR_SUCCESS; /* 0 */
+ }
+
+ memif_msg_queue_elt_t *cur = c->msg_queue;
+ while (cur->next != NULL)
+ {
+ cur = cur->next;
+ }
+ cur->next = e;
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
+
+/* used as confirmation of connection by master */
+static_fn int
+memif_msg_enq_connected (memif_connection_t * c)
+{
+ memif_msg_queue_elt_t *e =
+ (memif_msg_queue_elt_t *) malloc (sizeof (memif_msg_queue_elt_t));
+ if (e == NULL)
+ return memif_syscall_error_handler (errno);
+
+ memset (&e->msg, 0, sizeof (e->msg));
+ memif_msg_connected_t *cm = &e->msg.connected;
+
+ e->msg.type = MEMIF_MSG_TYPE_CONNECTED;
+ e->fd = -1;
+ strncpy ((char *) cm->if_name, (char *) c->args.interface_name,
+ strlen ((char *) c->args.interface_name));
+
+ e->next = NULL;
+ if (c->msg_queue == NULL)
+ {
+ c->msg_queue = e;
+ return MEMIF_ERR_SUCCESS; /* 0 */
+ }
+
+ memif_msg_queue_elt_t *cur = c->msg_queue;
+ while (cur->next != NULL)
+ {
+ cur = cur->next;
+ }
+ cur->next = e;
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
+
+/* immediately send disconnect msg */
+ /* specifie protocol for disconnect msg err_code
+ so that it will be compatible with VPP? (header/doc) */
+int
+memif_msg_send_disconnect (int fd, uint8_t * err_string, uint32_t err_code)
+{
+ memif_msg_t msg = { 0 };
+ memif_msg_disconnect_t *d = &msg.disconnect;
+
+ msg.type = MEMIF_MSG_TYPE_DISCONNECT;
+ d->code = err_code;
+ uint16_t l = strlen ((char *) err_string);
+ if (l > 96)
+ {
+ DBG ("Disconnect string too long. Sending first 96 characters.");
+ l = 96;
+ }
+ strncpy ((char *) d->string, (char *) err_string, l);
+
+ return memif_msg_send (fd, &msg, -1);
+}
+
+static_fn int
+memif_msg_receive_hello (memif_connection_t * c, memif_msg_t * msg)
+{
+ memif_msg_hello_t *h = &msg->hello;
+
+ if (msg->hello.min_version > MEMIF_VERSION ||
+ msg->hello.max_version < MEMIF_VERSION)
+ {
+ DBG ("incompatible protocol version");
+ return MEMIF_ERR_PROTO;
+ }
+
+ c->run_args.num_s2m_rings = memif_min (h->max_s2m_ring + 1,
+ c->args.num_s2m_rings);
+ c->run_args.num_m2s_rings = memif_min (h->max_m2s_ring + 1,
+ c->args.num_m2s_rings);
+ c->run_args.log2_ring_size = memif_min (h->max_log2_ring_size,
+ c->args.log2_ring_size);
+ c->run_args.buffer_size = c->args.buffer_size;
+ strncpy ((char *) c->remote_name, (char *) h->name,
+ strlen ((char *) h->name));
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
+
+/* handle interface identification (id, secret (optional)) */
+static_fn int
+memif_msg_receive_init (memif_socket_t * ms, int fd, memif_msg_t * msg)
+{
+ memif_msg_init_t *i = &msg->init;
+ memif_list_elt_t *elt = NULL;
+ memif_list_elt_t elt2;
+ memif_connection_t *c = NULL;
+ libmemif_main_t *lm = &libmemif_main;
+ uint8_t err_string[96];
+ memset (err_string, 0, sizeof (char) * 96);
+ int err = MEMIF_ERR_SUCCESS; /* 0 */
+ int err_disc;
+ if (i->version != MEMIF_VERSION)
+ {
+ DBG ("MEMIF_VER_ERR");
+ strncpy ((char *) err_string, MEMIF_VER_ERR, strlen (MEMIF_VER_ERR));
+ err = MEMIF_ERR_PROTO;
+ goto error;
+ }
+
+ get_list_elt (&elt, ms->interface_list, ms->interface_list_len, i->id);
+ if (elt == NULL)
+ {
+ DBG ("MEMIF_ID_ERR");
+ strncpy ((char *) err_string, MEMIF_ID_ERR, strlen (MEMIF_ID_ERR));
+ err = MEMIF_ERR_ID;
+ goto error;
+ }
+
+ c = (memif_connection_t *) elt->data_struct;
+
+ if (!(c->args.is_master))
+ {
+ DBG ("MEMIF_SLAVE_ERR");
+ strncpy ((char *) err_string, MEMIF_SLAVE_ERR,
+ strlen (MEMIF_SLAVE_ERR));
+ err = MEMIF_ERR_ACCSLAVE;
+ goto error;
+ }
+ if (c->fd != -1)
+ {
+ DBG ("MEMIF_CONN_ERR");
+ strncpy ((char *) err_string, MEMIF_CONN_ERR, strlen (MEMIF_CONN_ERR));
+ err = MEMIF_ERR_ALRCONN;
+ goto error;
+ }
+
+ c->fd = fd;
+
+ if (i->mode != c->args.mode)
+ {
+ DBG ("MEMIF_MODE_ERR");
+ strncpy ((char *) err_string, MEMIF_MODE_ERR, strlen (MEMIF_MODE_ERR));
+ err = MEMIF_ERR_MODE;
+ goto error;
+ }
+
+ strncpy ((char *) c->remote_name, (char *) i->name,
+ strlen ((char *) i->name));
+
+ if (c->args.secret)
+ {
+ int r;
+ if (i->secret)
+ {
+ if (strlen ((char *) c->args.secret) != strlen ((char *) i->secret))
+ {
+ DBG ("MEMIF_SECRET_ERR");
+ strncpy ((char *) err_string,
+ MEMIF_SECRET_ERR, strlen (MEMIF_SECRET_ERR));
+ err = MEMIF_ERR_SECRET;
+ goto error;
+ }
+ r = strncmp ((char *) i->secret, (char *) c->args.secret,
+ strlen ((char *) c->args.secret));
+ if (r != 0)
+ {
+ DBG ("MEMIF_SECRET_ERR");
+ strncpy ((char *) err_string,
+ MEMIF_SECRET_ERR, strlen (MEMIF_SECRET_ERR));
+ err = MEMIF_ERR_SECRET;
+ goto error;
+ }
+ }
+ else
+ {
+ DBG ("MEMIF_NOSECRET_ERR");
+ strncpy ((char *) err_string,
+ MEMIF_NOSECRET_ERR, strlen (MEMIF_NOSECRET_ERR));
+ err = MEMIF_ERR_NOSECRET;
+ goto error;
+ }
+ }
+
+ c->read_fn = memif_conn_fd_read_ready;
+ c->write_fn = memif_conn_fd_write_ready;
+ c->error_fn = memif_conn_fd_error;
+
+ elt2.key = c->fd;
+ elt2.data_struct = c;
+
+ add_list_elt (&elt2, &lm->control_list, &lm->control_list_len);
+ free_list_elt (lm->pending_list, lm->pending_list_len, fd);
+
+ return err;
+
+error:
+ memif_msg_send_disconnect (fd, err_string, 0);
+ lm->control_fd_update (fd, MEMIF_FD_EVENT_DEL);
+ free_list_elt (lm->pending_list, lm->pending_list_len, fd);
+ close (fd);
+ fd = -1;
+ return err;
+}
+
+/* receive region information and add new region to connection (if possible) */
+static_fn int
+memif_msg_receive_add_region (memif_connection_t * c, memif_msg_t * msg,
+ int fd)
+{
+ memif_msg_add_region_t *ar = &msg->add_region;
+ memif_region_t *mr;
+ if (fd < 0)
+ return MEMIF_ERR_NO_SHMFD;
+
+ if (ar->index > MEMIF_MAX_REGION)
+ return MEMIF_ERR_MAXREG;
+
+ mr =
+ (memif_region_t *) realloc (c->regions,
+ sizeof (memif_region_t) * (ar->index + 1));
+ if (mr == NULL)
+ return memif_syscall_error_handler (errno);
+ c->regions = mr;
+ c->regions[ar->index].fd = fd;
+ c->regions[ar->index].region_size = ar->size;
+ c->regions[ar->index].shm = NULL;
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
+
+/* receive ring information and add new ring to connection queue
+ (based on direction S2M | M2S) */
+static_fn int
+memif_msg_receive_add_ring (memif_connection_t * c, memif_msg_t * msg, int fd)
+{
+ memif_msg_add_ring_t *ar = &msg->add_ring;
+
+ memif_queue_t *mq;
+
+ if (fd < 0)
+ return MEMIF_ERR_NO_INTFD;
+
+ if (ar->flags & MEMIF_MSG_ADD_RING_FLAG_S2M)
+ {
+ if (ar->index > MEMIF_MAX_S2M_RING)
+ return MEMIF_ERR_MAXRING;
+ if (ar->index >= c->args.num_s2m_rings)
+ return MEMIF_ERR_MAXRING;
+
+ mq =
+ (memif_queue_t *) realloc (c->rx_queues,
+ sizeof (memif_queue_t) * (ar->index + 1));
+ if (mq == NULL)
+ return memif_syscall_error_handler (errno);
+ c->rx_queues = mq;
+ c->rx_queues[ar->index].int_fd = fd;
+ c->rx_queues[ar->index].log2_ring_size = ar->log2_ring_size;
+ c->rx_queues[ar->index].region = ar->region;
+ c->rx_queues[ar->index].offset = ar->offset;
+ c->run_args.num_s2m_rings++;
+ }
+ else
+ {
+ if (ar->index > MEMIF_MAX_M2S_RING)
+ return MEMIF_ERR_MAXRING;
+ if (ar->index >= c->args.num_m2s_rings)
+ return MEMIF_ERR_MAXRING;
+
+ mq =
+ (memif_queue_t *) realloc (c->tx_queues,
+ sizeof (memif_queue_t) * (ar->index + 1));
+ if (mq == NULL)
+ return memif_syscall_error_handler (errno);
+ c->tx_queues = mq;
+ c->tx_queues[ar->index].int_fd = fd;
+ c->tx_queues[ar->index].log2_ring_size = ar->log2_ring_size;
+ c->tx_queues[ar->index].region = ar->region;
+ c->tx_queues[ar->index].offset = ar->offset;
+ c->run_args.num_m2s_rings++;
+ }
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
+
+/* slave -> master */
+static_fn int
+memif_msg_receive_connect (memif_connection_t * c, memif_msg_t * msg)
+{
+ memif_msg_connect_t *cm = &msg->connect;
+ libmemif_main_t *lm = &libmemif_main;
+ memif_list_elt_t elt;
+
+ int err;
+ err = memif_connect1 (c);
+ if (err != MEMIF_ERR_SUCCESS)
+ return err;
+
+ strncpy ((char *) c->remote_if_name, (char *) cm->if_name,
+ strlen ((char *) cm->if_name));
+
+ int i;
+ if (c->on_interrupt != NULL)
+ {
+ for (i = 0; i < c->run_args.num_m2s_rings; i++)
+ {
+ elt.key = c->rx_queues[i].int_fd;
+ elt.data_struct = c;
+ add_list_elt (&elt, &lm->interrupt_list, &lm->interrupt_list_len);
+
+ lm->control_fd_update (c->rx_queues[i].int_fd, MEMIF_FD_EVENT_READ);
+ }
+
+ }
+
+ c->on_connect ((void *) c, c->private_ctx);
+
+ return err;
+}
+
+/* master -> slave */
+static_fn int
+memif_msg_receive_connected (memif_connection_t * c, memif_msg_t * msg)
+{
+ memif_msg_connect_t *cm = &msg->connect;
+ libmemif_main_t *lm = &libmemif_main;
+
+ int err;
+ err = memif_connect1 (c);
+ if (err != MEMIF_ERR_SUCCESS)
+ return err;
+
+ strncpy ((char *) c->remote_if_name, (char *) cm->if_name,
+ strlen ((char *) cm->if_name));
+
+ int i;
+ if (c->on_interrupt != NULL)
+ {
+ for (i = 0; i < c->run_args.num_s2m_rings; i++)
+ lm->control_fd_update (c->rx_queues[i].int_fd, MEMIF_FD_EVENT_READ);
+ }
+
+ c->on_connect ((void *) c, c->private_ctx);
+
+ return err;
+}
+
+static_fn int
+memif_msg_receive_disconnect (memif_connection_t * c, memif_msg_t * msg)
+{
+ memif_msg_disconnect_t *d = &msg->disconnect;
+
+ memset (c->remote_disconnect_string, 0,
+ sizeof (c->remote_disconnect_string));
+ strncpy ((char *) c->remote_disconnect_string, (char *) d->string,
+ strlen ((char *) d->string));
+
+ /* on returning error, handle function will call memif_disconnect () */
+ DBG ("disconnect received: %s, mode: %d",
+ c->remote_disconnect_string, c->args.mode);
+ return MEMIF_ERR_DISCONNECT;
+}
+
+static_fn int
+memif_msg_receive (int ifd)
+{
+ char ctl[CMSG_SPACE (sizeof (int)) +
+ CMSG_SPACE (sizeof (struct ucred))] = { 0 };
+ struct msghdr mh = { 0 };
+ struct iovec iov[1];
+ memif_msg_t msg = { 0 };
+ ssize_t size;
+ int err = MEMIF_ERR_SUCCESS; /* 0 */
+ int fd = -1;
+ int i;
+ libmemif_main_t *lm = &libmemif_main;
+ memif_connection_t *c = NULL;
+ memif_socket_t *ms = NULL;
+ memif_list_elt_t *elt = NULL;
+
+ iov[0].iov_base = (void *) &msg;
+ iov[0].iov_len = sizeof (memif_msg_t);
+ mh.msg_iov = iov;
+ mh.msg_iovlen = 1;
+ mh.msg_control = ctl;
+ mh.msg_controllen = sizeof (ctl);
+
+ DBG ("recvmsg fd %d", ifd);
+ size = recvmsg (ifd, &mh, 0);
+ DBG ("done");
+ if (size != sizeof (memif_msg_t))
+ {
+ if (size == 0)
+ return MEMIF_ERR_DISCONNECTED;
+ else
+ return MEMIF_ERR_MFMSG;
+ }
+
+ struct ucred *cr = 0;
+ struct cmsghdr *cmsg;
+
+ cmsg = CMSG_FIRSTHDR (&mh);
+ while (cmsg)
+ {
+ if (cmsg->cmsg_level == SOL_SOCKET)
+ {
+ if (cmsg->cmsg_type == SCM_CREDENTIALS)
+ {
+ cr = (struct ucred *) CMSG_DATA (cmsg);
+ }
+ else if (cmsg->cmsg_type == SCM_RIGHTS)
+ {
+ int *fdp = (int *) CMSG_DATA (cmsg);
+ fd = *fdp;
+ }
+ }
+ cmsg = CMSG_NXTHDR (&mh, cmsg);
+ }
+
+ DBG ("Message type %u received", msg.type);
+
+ get_list_elt (&elt, lm->control_list, lm->control_list_len, ifd);
+ if (elt != NULL)
+ c = (memif_connection_t *) elt->data_struct;
+
+ switch (msg.type)
+ {
+ case MEMIF_MSG_TYPE_ACK:
+ break;
+
+ case MEMIF_MSG_TYPE_HELLO:
+ if ((err = memif_msg_receive_hello (c, &msg)) != MEMIF_ERR_SUCCESS)
+ return err;
+ if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
+ return err;
+ if ((err = memif_msg_enq_init (c)) != MEMIF_ERR_SUCCESS)
+ return err;
+ if ((err = memif_msg_enq_add_region (c, 0)) != MEMIF_ERR_SUCCESS)
+ return err;
+ for (i = 0; i < c->run_args.num_s2m_rings; i++)
+ {
+ if ((err =
+ memif_msg_enq_add_ring (c, i,
+ MEMIF_RING_S2M)) != MEMIF_ERR_SUCCESS)
+ return err;
+ }
+ for (i = 0; i < c->run_args.num_m2s_rings; i++)
+ {
+ if ((err =
+ memif_msg_enq_add_ring (c, i,
+ MEMIF_RING_M2S)) != MEMIF_ERR_SUCCESS)
+ return err;
+ }
+ if ((err = memif_msg_enq_connect (c)) != MEMIF_ERR_SUCCESS)
+ return err;
+ break;
+
+ case MEMIF_MSG_TYPE_INIT:
+ get_list_elt (&elt, lm->pending_list, lm->pending_list_len, ifd);
+ if (elt == NULL)
+ return -1;
+ ms = (memif_socket_t *) elt->data_struct;
+ if ((err = memif_msg_receive_init (ms, ifd, &msg)) != MEMIF_ERR_SUCCESS)
+ return err;
+ /* c->remote_pid = cr->pid */
+ /* c->remote_uid = cr->uid */
+ /* c->remote_gid = cr->gid */
+ get_list_elt (&elt, lm->control_list, lm->control_list_len, ifd);
+ if (elt == NULL)
+ return -1;
+ c = (memif_connection_t *) elt->data_struct;
+ if ((err = memif_msg_enq_ack (c)) != MEMIF_ERR_SUCCESS)
+ return err;
+ break;
+
+ case MEMIF_MSG_TYPE_ADD_REGION:
+ if ((err =
+ memif_msg_receive_add_region (c, &msg, fd)) != MEMIF_ERR_SUCCESS)
+ return err;
+ if ((err = memif_msg_enq_ack (c)) != MEMIF_ERR_SUCCESS)
+ return err;
+ break;
+
+ case MEMIF_MSG_TYPE_ADD_RING:
+ if ((err =
+ memif_msg_receive_add_ring (c, &msg, fd)) != MEMIF_ERR_SUCCESS)
+ return err;
+ if ((err = memif_msg_enq_ack (c)) != MEMIF_ERR_SUCCESS)
+ return err;
+ break;
+
+ case MEMIF_MSG_TYPE_CONNECT:
+ if ((err = memif_msg_receive_connect (c, &msg)) != MEMIF_ERR_SUCCESS)
+ return err;
+ if ((err = memif_msg_enq_connected (c)) != MEMIF_ERR_SUCCESS)
+ return err;
+ break;
+
+ case MEMIF_MSG_TYPE_CONNECTED:
+ if ((err = memif_msg_receive_connected (c, &msg)) != MEMIF_ERR_SUCCESS)
+ return err;
+ break;
+
+ case MEMIF_MSG_TYPE_DISCONNECT:
+ if ((err = memif_msg_receive_disconnect (c, &msg)) != MEMIF_ERR_SUCCESS)
+ return err;
+ break;
+
+ default:
+ return MEMIF_ERR_UNKNOWN_MSG;;
+ break;
+ }
+
+ if (c != NULL)
+ c->flags |= MEMIF_CONNECTION_FLAG_WRITE;
+/* libmemif_main_t *lm = &libmemif_main;
+ lm->control_fd_update (c->fd, MEMIF_FD_EVENT_READ | MEMIF_FD_EVENT_MOD); */
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
+
+int
+memif_conn_fd_error (memif_connection_t * c)
+{
+ DBG ("connection fd error");
+ strncpy ((char *) c->remote_disconnect_string, "connection fd error", 19);
+ int err = memif_disconnect_internal (c);
+ return err;
+}
+
+/* calls memif_msg_receive to handle pending messages on socket */
+int
+memif_conn_fd_read_ready (memif_connection_t * c)
+{
+ int err;
+ err = memif_msg_receive (c->fd);
+ if (err != 0)
+ {
+ err = memif_disconnect_internal (c);
+ }
+ return err;
+}
+
+/* get msg from msg queue buffer and send it to socket */
+int
+memif_conn_fd_write_ready (memif_connection_t * c)
+{
+ int err = MEMIF_ERR_SUCCESS; /* 0 */
+
+
+ if ((c->flags & MEMIF_CONNECTION_FLAG_WRITE) == 0)
+ goto done;
+
+ memif_msg_queue_elt_t *e = c->msg_queue;
+ if (e == NULL)
+ goto done;
+
+ c->msg_queue = c->msg_queue->next;
+
+ c->flags &= ~MEMIF_CONNECTION_FLAG_WRITE;
+/*
+ libmemif_main_t *lm = &libmemif_main;
+
+ lm->control_fd_update (c->fd,
+ MEMIF_FD_EVENT_READ | MEMIF_FD_EVENT_WRITE | MEMIF_FD_EVENT_MOD);
+*/
+ err = memif_msg_send (c->fd, &e->msg, e->fd);
+ free (e);
+ goto done;
+
+done:
+ return err;
+}
+
+int
+memif_conn_fd_accept_ready (memif_socket_t * ms)
+{
+ int addr_len;
+ struct sockaddr_un client;
+ int conn_fd;
+ libmemif_main_t *lm = &libmemif_main;
+
+ DBG ("accept called");
+
+ addr_len = sizeof (client);
+ conn_fd =
+ accept (ms->fd, (struct sockaddr *) &client, (socklen_t *) & addr_len);
+
+ if (conn_fd < 0)
+ {
+ return memif_syscall_error_handler (errno);
+ }
+ DBG ("accept fd %d", ms->fd);
+ DBG ("conn fd %d", conn_fd);
+
+ memif_list_elt_t elt;
+ elt.key = conn_fd;
+ elt.data_struct = ms;
+
+ add_list_elt (&elt, &lm->pending_list, &lm->pending_list_len);
+ lm->control_fd_update (conn_fd, MEMIF_FD_EVENT_READ | MEMIF_FD_EVENT_WRITE);
+
+ return memif_msg_send_hello (conn_fd);
+}
+
+int
+memif_read_ready (int fd)
+{
+ int err;
+ DBG ("call recv");
+ err = memif_msg_receive (fd);
+ DBG ("recv finished");
+ return err;
+}
diff --git a/extras/libmemif/src/socket.h b/extras/libmemif/src/socket.h
new file mode 100644
index 00000000..a8e9fbce
--- /dev/null
+++ b/extras/libmemif/src/socket.h
@@ -0,0 +1,89 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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 _SOCKET_H_
+#define _SOCKET_H
+
+#include <memif_private.h>
+
+/* interface identification errors (disconnect messages)*/
+#define MEMIF_VER_ERR "incompatible version"
+#define MEMIF_ID_ERR "unmatched interface id"
+#define MEMIF_SLAVE_ERR "cannot connect to salve"
+#define MEMIF_CONN_ERR "already connected"
+#define MEMIF_MODE_ERR "mode mismatch"
+#define MEMIF_SECRET_ERR "incorrect secret"
+#define MEMIF_NOSECRET_ERR "secret required"
+
+/* socket.c */
+
+int memif_conn_fd_read_ready (memif_connection_t * c);
+
+int memif_conn_fd_write_ready (memif_connection_t * c);
+
+int memif_conn_fd_error (memif_connection_t * c);
+
+int memif_conn_fd_accept_ready (memif_socket_t * ms);
+
+int memif_read_ready (int fd);
+
+int memif_msg_send_disconnect (int fd, uint8_t * err_string,
+ uint32_t err_code);
+
+/* when compiling unit tests, compile functions without static keyword
+ and declare functions in header file */
+#ifdef MEMIF_UNIT_TEST
+#define static_fn
+
+int memif_msg_send (int fd, memif_msg_t * msg, int afd);
+
+int memif_msg_enq_ack (memif_connection_t * c);
+
+int memif_msg_send_hello (int fd);
+
+int memif_msg_enq_init (memif_connection_t * c);
+
+int memif_msg_enq_add_region (memif_connection_t * c, uint8_t region);
+
+int memif_msg_enq_add_ring (memif_connection_t * c, uint8_t index,
+ uint8_t dir);
+
+int memif_msg_receive_hello (memif_connection_t * c, memif_msg_t * msg);
+
+int memif_msg_receive_init (memif_socket_t * ms, int fd, memif_msg_t * msg);
+
+int memif_msg_receive_add_region (memif_connection_t * c, memif_msg_t * msg,
+ int fd);
+
+int memif_msg_receive_add_ring (memif_connection_t * c, memif_msg_t * msg,
+ int fd);
+
+int memif_msg_enq_connect (memif_connection_t * c);
+
+int memif_msg_enq_connected (memif_connection_t * c);
+
+int memif_msg_receive_connect (memif_connection_t * c, memif_msg_t * msg);
+
+int memif_msg_receive_connected (memif_connection_t * c, memif_msg_t * msg);
+
+int memif_msg_receive_disconnect (memif_connection_t * c, memif_msg_t * msg);
+
+#else
+#define static_fn static
+#endif /* MEMIF_UNIT_TEST */
+
+#endif /* _SOCKET_H_ */
diff --git a/extras/libmemif/test/main_test.c b/extras/libmemif/test/main_test.c
new file mode 100644
index 00000000..deb8acb6
--- /dev/null
+++ b/extras/libmemif/test/main_test.c
@@ -0,0 +1,1079 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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 <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <main_test.h>
+
+#include <memif_private.h>
+
+#define SOCKET_FILENAME "/run/vpp/memif.sock"
+
+uint8_t ready_called;
+#define read_call (1 << 0)
+#define write_call (1 << 1)
+#define error_call (1 << 2)
+
+int
+read_fn (memif_connection_t * c)
+{
+ ready_called |= read_call;
+ return 0;
+}
+
+int
+write_fn (memif_connection_t * c)
+{
+ ready_called |= write_call;
+ return 0;
+}
+
+int
+error_fn (memif_connection_t * c)
+{
+ ready_called |= error_call;
+ return 0;
+}
+
+static void
+register_fd_ready_fn (memif_connection_t * c,
+ memif_fn * read_fn, memif_fn * write_fn,
+ memif_fn * error_fn)
+{
+ c->read_fn = read_fn;
+ c->write_fn = write_fn;
+ c->error_fn = error_fn;
+}
+
+START_TEST (test_init)
+{
+ int err;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ ck_assert_ptr_ne (lm, NULL);
+ ck_assert_ptr_ne (lm->control_fd_update, NULL);
+ ck_assert_int_gt (lm->timerfd, 2);
+
+ if (lm->timerfd > 0)
+ close (lm->timerfd);
+ lm->timerfd = -1;
+}
+
+END_TEST
+START_TEST (test_init_epoll)
+{
+ int err;
+
+ if ((err = memif_init (NULL, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ ck_assert_ptr_ne (lm, NULL);
+ ck_assert_ptr_ne (lm->control_fd_update, NULL);
+ ck_assert_int_gt (lm->timerfd, 2);
+ ck_assert_int_gt (memif_epfd, -1);
+
+ if (lm->timerfd > 0)
+ close (lm->timerfd);
+ lm->timerfd = -1;
+}
+
+END_TEST
+START_TEST (test_create)
+{
+ int err;
+ memif_conn_handle_t conn = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ strncpy ((char *) args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+
+ if ((err = memif_create (&conn, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *c = (memif_connection_t *) conn;
+
+ ck_assert_ptr_ne (c, NULL);
+
+ ck_assert_uint_eq (c->args.interface_id, args.interface_id);
+ ck_assert_uint_eq (c->args.is_master, args.is_master);
+ ck_assert_uint_eq (c->args.mode, args.mode);
+
+ ck_assert_uint_eq (c->args.num_s2m_rings, MEMIF_DEFAULT_TX_QUEUES);
+ ck_assert_uint_eq (c->args.num_m2s_rings, MEMIF_DEFAULT_RX_QUEUES);
+ ck_assert_uint_eq (c->args.buffer_size, MEMIF_DEFAULT_BUFFER_SIZE);
+ ck_assert_uint_eq (c->args.log2_ring_size, MEMIF_DEFAULT_LOG2_RING_SIZE);
+
+ ck_assert_ptr_eq (c->msg_queue, NULL);
+ ck_assert_ptr_eq (c->regions, NULL);
+ ck_assert_ptr_eq (c->tx_queues, NULL);
+ ck_assert_ptr_eq (c->rx_queues, NULL);
+
+ ck_assert_int_eq (c->fd, -1);
+
+ ck_assert_ptr_ne (c->on_connect, NULL);
+ ck_assert_ptr_ne (c->on_disconnect, NULL);
+ ck_assert_ptr_ne (c->on_interrupt, NULL);
+
+ ck_assert_str_eq (c->args.interface_name, args.interface_name);
+ ck_assert_str_eq (c->args.instance_name, args.instance_name);
+ ck_assert_str_eq (c->args.socket_filename, SOCKET_FILENAME);
+
+ struct itimerspec timer;
+ timerfd_gettime (lm->timerfd, &timer);
+
+ ck_assert_msg (timer.it_interval.tv_sec == lm->arm.it_interval.tv_sec,
+ "timerfd not armed!");
+
+ if (lm->timerfd > 0)
+ close (lm->timerfd);
+ lm->timerfd = -1;
+
+ memif_delete (&conn);
+ ck_assert_ptr_eq (conn, NULL);
+}
+
+END_TEST
+START_TEST (test_create_master)
+{
+ int err, rv;
+ memif_conn_handle_t conn = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+ args.is_master = 1;
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ strncpy ((char *) args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+
+ if ((err = memif_create (&conn, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *c = (memif_connection_t *) conn;
+
+ ck_assert_ptr_ne (c, NULL);
+
+ ck_assert_uint_eq (c->args.interface_id, args.interface_id);
+ ck_assert_uint_eq (c->args.is_master, args.is_master);
+ ck_assert_uint_eq (c->args.mode, args.mode);
+
+ ck_assert_uint_eq (c->args.num_s2m_rings, MEMIF_DEFAULT_TX_QUEUES);
+ ck_assert_uint_eq (c->args.num_m2s_rings, MEMIF_DEFAULT_RX_QUEUES);
+ ck_assert_uint_eq (c->args.buffer_size, MEMIF_DEFAULT_BUFFER_SIZE);
+ ck_assert_uint_eq (c->args.log2_ring_size, MEMIF_DEFAULT_LOG2_RING_SIZE);
+
+ ck_assert_ptr_eq (c->msg_queue, NULL);
+ ck_assert_ptr_eq (c->regions, NULL);
+ ck_assert_ptr_eq (c->tx_queues, NULL);
+ ck_assert_ptr_eq (c->rx_queues, NULL);
+
+ ck_assert_int_eq (c->fd, -1);
+
+ ck_assert_ptr_ne (c->on_connect, NULL);
+ ck_assert_ptr_ne (c->on_disconnect, NULL);
+ ck_assert_ptr_ne (c->on_interrupt, NULL);
+
+ ck_assert_str_eq (c->args.interface_name, args.interface_name);
+ ck_assert_str_eq (c->args.instance_name, args.instance_name);
+ ck_assert_str_eq (c->args.socket_filename, SOCKET_FILENAME);
+
+ struct stat file_stat;
+
+ rv = stat (SOCKET_FILENAME, &file_stat);
+ ck_assert_int_eq (rv, 0);
+
+ ck_assert (S_ISSOCK (file_stat.st_mode));
+
+ memif_delete (&conn);
+ ck_assert_ptr_eq (conn, NULL);
+}
+
+END_TEST
+START_TEST (test_create_mult)
+{
+ int err;
+ memif_conn_handle_t conn = NULL;
+ memif_conn_handle_t conn1 = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ strncpy ((char *) args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+
+ if ((err = memif_create (&conn, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ args.interface_id = 1;
+
+ if ((err = memif_create (&conn1, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *c = (memif_connection_t *) conn;
+ memif_connection_t *c1 = (memif_connection_t *) conn1;
+
+ ck_assert_ptr_ne (c, NULL);
+ ck_assert_ptr_ne (c1, NULL);
+
+ ck_assert_uint_eq (c->args.interface_id, 0);
+ ck_assert_uint_eq (c->args.is_master, args.is_master);
+ ck_assert_uint_eq (c->args.mode, args.mode);
+ ck_assert_uint_eq (c1->args.interface_id, 1);
+ ck_assert_uint_eq (c1->args.is_master, args.is_master);
+ ck_assert_uint_eq (c1->args.mode, args.mode);
+
+ ck_assert_uint_eq (c->args.num_s2m_rings, MEMIF_DEFAULT_TX_QUEUES);
+ ck_assert_uint_eq (c->args.num_m2s_rings, MEMIF_DEFAULT_RX_QUEUES);
+ ck_assert_uint_eq (c->args.buffer_size, MEMIF_DEFAULT_BUFFER_SIZE);
+ ck_assert_uint_eq (c->args.log2_ring_size, MEMIF_DEFAULT_LOG2_RING_SIZE);
+ ck_assert_uint_eq (c1->args.num_s2m_rings, MEMIF_DEFAULT_TX_QUEUES);
+ ck_assert_uint_eq (c1->args.num_m2s_rings, MEMIF_DEFAULT_RX_QUEUES);
+ ck_assert_uint_eq (c1->args.buffer_size, MEMIF_DEFAULT_BUFFER_SIZE);
+ ck_assert_uint_eq (c1->args.log2_ring_size, MEMIF_DEFAULT_LOG2_RING_SIZE);
+
+ ck_assert_ptr_eq (c->msg_queue, NULL);
+ ck_assert_ptr_eq (c->regions, NULL);
+ ck_assert_ptr_eq (c->tx_queues, NULL);
+ ck_assert_ptr_eq (c->rx_queues, NULL);
+ ck_assert_ptr_eq (c1->msg_queue, NULL);
+ ck_assert_ptr_eq (c1->regions, NULL);
+ ck_assert_ptr_eq (c1->tx_queues, NULL);
+ ck_assert_ptr_eq (c1->rx_queues, NULL);
+
+ ck_assert_int_eq (c->fd, -1);
+ ck_assert_int_eq (c1->fd, -1);
+
+ ck_assert_ptr_ne (c->on_connect, NULL);
+ ck_assert_ptr_ne (c->on_disconnect, NULL);
+ ck_assert_ptr_ne (c->on_interrupt, NULL);
+ ck_assert_ptr_ne (c1->on_connect, NULL);
+ ck_assert_ptr_ne (c1->on_disconnect, NULL);
+ ck_assert_ptr_ne (c1->on_interrupt, NULL);
+
+ ck_assert_str_eq (c->args.interface_name, args.interface_name);
+ ck_assert_str_eq (c->args.instance_name, args.instance_name);
+ ck_assert_str_eq (c->args.socket_filename, SOCKET_FILENAME);
+ ck_assert_str_eq (c1->args.interface_name, args.interface_name);
+ ck_assert_str_eq (c1->args.instance_name, args.instance_name);
+ ck_assert_str_eq (c1->args.socket_filename, SOCKET_FILENAME);
+
+ struct itimerspec timer;
+ timerfd_gettime (lm->timerfd, &timer);
+
+ ck_assert_msg (timer.it_interval.tv_sec == lm->arm.it_interval.tv_sec,
+ "timerfd not armed!");
+
+ if (lm->timerfd > 0)
+ close (lm->timerfd);
+ lm->timerfd = -1;
+
+ memif_delete (&conn);
+ ck_assert_ptr_eq (conn, NULL);
+}
+
+END_TEST
+START_TEST (test_control_fd_handler)
+{
+ int err;
+ ready_called = 0;
+ memif_conn_handle_t conn = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+ args.num_s2m_rings = 2;
+ args.num_m2s_rings = 2;
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ strncpy ((char *) args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+
+ if ((err = memif_create (&conn, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *c = (memif_connection_t *) conn;
+
+ if ((err =
+ memif_control_fd_handler (lm->timerfd,
+ MEMIF_FD_EVENT_READ)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_NO_FILE, "err code: %u, err msg: %s", err,
+ memif_strerror (err));
+
+ register_fd_ready_fn (c, read_fn, write_fn, error_fn);
+ c->fd = 69;
+ lm->control_list[0].key = c->fd;
+ lm->control_list[0].data_struct = c;
+
+ if ((err =
+ memif_control_fd_handler (c->fd,
+ MEMIF_FD_EVENT_READ)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert (ready_called & read_call);
+
+ if ((err =
+ memif_control_fd_handler (c->fd,
+ MEMIF_FD_EVENT_WRITE)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert (ready_called & write_call);
+
+ if ((err =
+ memif_control_fd_handler (c->fd,
+ MEMIF_FD_EVENT_ERROR)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert (ready_called & error_call);
+
+ if (lm->timerfd > 0)
+ close (lm->timerfd);
+ lm->timerfd = -1;
+
+ memif_delete (&conn);
+ ck_assert_ptr_eq (conn, NULL);
+}
+
+END_TEST
+START_TEST (test_buffer_alloc)
+{
+ int err, i;
+ uint8_t qid;
+ uint16_t buf;
+ memif_buffer_t *bufs;
+ uint16_t max_buf = 10;
+ ready_called = 0;
+ memif_conn_handle_t conn = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+ args.num_s2m_rings = 2;
+ args.num_m2s_rings = 2;
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ strncpy ((char *) args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+
+ if ((err = memif_create (&conn, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *c = (memif_connection_t *) conn;
+
+ c->run_args.num_s2m_rings = 2;
+ c->run_args.num_m2s_rings = 2;
+ c->run_args.log2_ring_size = 10;
+ c->run_args.buffer_size = 2048;
+
+ if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ c->fd = 69;
+
+ /* test buffer allocation qid 0 (positive) */
+
+ bufs = malloc (sizeof (memif_buffer_t) * max_buf);
+
+ qid = 0;
+ if ((err =
+ memif_buffer_alloc (conn, qid, bufs, max_buf,
+ &buf)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_uint_eq (buf, max_buf);
+ for (i = 0; i < max_buf; i++)
+ ck_assert_uint_eq (bufs[i].buffer_len, MEMIF_DEFAULT_BUFFER_SIZE);
+
+ /* test buffer allocation qid 1 (positive) */
+ free (bufs);
+ bufs = malloc (sizeof (memif_buffer_t) * max_buf);
+
+ qid = 1;
+ if ((err =
+ memif_buffer_alloc (conn, qid, bufs, max_buf,
+ &buf)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_uint_eq (buf, max_buf);
+ for (i = 0; i < max_buf; i++)
+ ck_assert_uint_eq (bufs[i].buffer_len, MEMIF_DEFAULT_BUFFER_SIZE);
+
+ /* test buffer allocation qid 2 (negative) */
+
+ free (bufs);
+ bufs = malloc (sizeof (memif_buffer_t) * max_buf);
+
+ qid = 2;
+ if ((err =
+ memif_buffer_alloc (conn, qid, bufs, max_buf,
+ &buf)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_QID, "err code: %u, err msg: %s", err,
+ memif_strerror (err));
+
+ if (lm->timerfd > 0)
+ close (lm->timerfd);
+ lm->timerfd = -1;
+
+ free (bufs);
+ bufs = NULL;
+
+ memif_delete (&conn);
+ ck_assert_ptr_eq (conn, NULL);
+}
+
+END_TEST
+START_TEST (test_tx_burst)
+{
+ int err, i;
+ uint16_t max_buf = 10, buf, tx;
+ uint8_t qid;
+ memif_buffer_t *bufs;
+ ready_called = 0;
+ memif_conn_handle_t conn = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+ args.num_s2m_rings = 2;
+ args.num_m2s_rings = 2;
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ strncpy ((char *) args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+
+ if ((err = memif_create (&conn, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *c = (memif_connection_t *) conn;
+
+ c->run_args.num_s2m_rings = 2;
+ c->run_args.num_m2s_rings = 2;
+ c->run_args.log2_ring_size = 10;
+ c->run_args.buffer_size = 2048;
+
+ if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ c->fd = 69;
+
+ /* test transmit qid 0 (positive) */
+
+ bufs = malloc (sizeof (memif_buffer_t) * max_buf);
+ qid = 0;
+ if ((err =
+ memif_buffer_alloc (conn, qid, bufs, max_buf,
+ &buf)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_uint_eq (buf, max_buf);
+ for (i = 0; i < max_buf; i++)
+ ck_assert_uint_eq (bufs[i].buffer_len, MEMIF_DEFAULT_BUFFER_SIZE);
+
+ if ((err =
+ memif_tx_burst (conn, qid, bufs, max_buf, &tx)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_uint_eq (tx, max_buf);
+ for (i = 0; i < max_buf; i++)
+ ck_assert_ptr_eq (bufs[i].data, NULL);
+
+ /* test transmit qid 1 (positive) */
+ free (bufs);
+ bufs = malloc (sizeof (memif_buffer_t) * max_buf);
+ qid = 1;
+ if ((err =
+ memif_buffer_alloc (conn, qid, bufs, max_buf,
+ &buf)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_uint_eq (buf, max_buf);
+ for (i = 0; i < max_buf; i++)
+ ck_assert_uint_eq (bufs[i].buffer_len, MEMIF_DEFAULT_BUFFER_SIZE);
+
+ if ((err =
+ memif_tx_burst (conn, qid, bufs, max_buf, &tx)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_uint_eq (tx, max_buf);
+ for (i = 0; i < max_buf; i++)
+ ck_assert_ptr_eq (bufs[i].data, NULL);
+
+ /* test transmit qid 2 (negative) */
+ free (bufs);
+ bufs = malloc (sizeof (memif_buffer_t) * max_buf);
+ qid = 2;
+ if ((err =
+ memif_tx_burst (conn, qid, bufs, max_buf, &tx)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_QID, "err code: %u, err msg: %s", err,
+ memif_strerror (err));
+
+ if (lm->timerfd > 0)
+ close (lm->timerfd);
+ lm->timerfd = -1;
+ free (bufs);
+ bufs = NULL;
+
+ memif_delete (&conn);
+ ck_assert_ptr_eq (conn, NULL);
+}
+
+END_TEST
+START_TEST (test_rx_burst)
+{
+ int err, i;
+ uint16_t max_buf = 10, buf, rx;
+ uint8_t qid;
+ memif_buffer_t *bufs;
+ memif_queue_t *mq;
+ memif_ring_t *ring;
+ ready_called = 0;
+ memif_conn_handle_t conn = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+ args.num_s2m_rings = 2;
+ args.num_m2s_rings = 2;
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ strncpy ((char *) args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+
+ if ((err = memif_create (&conn, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *c = (memif_connection_t *) conn;
+
+ c->run_args.num_s2m_rings = 2;
+ c->run_args.num_m2s_rings = 2;
+ c->run_args.log2_ring_size = 10;
+ c->run_args.buffer_size = 2048;
+
+ if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ c->fd = 69;
+
+ /* test receive qid 0 (positive) */
+ qid = 0;
+ mq = &c->rx_queues[qid];
+ ring = mq->ring;
+ ring->head += max_buf;
+
+ bufs = malloc (sizeof (memif_buffer_t) * max_buf);
+
+ if ((err =
+ memif_rx_burst (conn, qid, bufs, max_buf, &rx)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_uint_eq (rx, max_buf);
+ for (i = 0; i < max_buf; i++)
+ ck_assert_ptr_ne (bufs[i].data, NULL);
+
+ /* test receive qid 1 (positive) */
+ qid = 1;
+ mq = &c->rx_queues[qid];
+ ring = mq->ring;
+ ring->head += max_buf;
+
+ free (bufs);
+ bufs = malloc (sizeof (memif_buffer_t) * max_buf);
+
+ if ((err =
+ memif_rx_burst (conn, qid, bufs, max_buf, &rx)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_uint_eq (rx, max_buf);
+ for (i = 0; i < max_buf; i++)
+ ck_assert_ptr_ne (bufs[i].data, NULL);
+
+ /* test receive qid 2 (negative) */
+ free (bufs);
+ bufs = malloc (sizeof (memif_buffer_t) * max_buf);
+
+ if ((err =
+ memif_rx_burst (conn, qid, bufs, max_buf, &rx)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_QID, "err code: %u, err msg: %s", err,
+ memif_strerror (err));
+
+ if (lm->timerfd > 0)
+ close (lm->timerfd);
+ lm->timerfd = -1;
+ free (bufs);
+ bufs = NULL;
+
+ memif_delete (&conn);
+ ck_assert_ptr_eq (conn, NULL);
+}
+
+END_TEST
+START_TEST (test_buffer_free)
+{
+ int err, i;
+ uint16_t max_buf = 10, buf, rx;
+ uint8_t qid;
+ memif_buffer_t *bufs;
+ memif_queue_t *mq;
+ memif_ring_t *ring;
+ ready_called = 0;
+ memif_conn_handle_t conn = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+ args.num_s2m_rings = 2;
+ args.num_m2s_rings = 2;
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ strncpy ((char *) args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+
+ if ((err = memif_create (&conn, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *c = (memif_connection_t *) conn;
+
+ c->run_args.num_s2m_rings = 2;
+ c->run_args.num_m2s_rings = 2;
+ c->run_args.log2_ring_size = 10;
+ c->run_args.buffer_size = 2048;
+
+ if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ c->fd = 69;
+
+ /* test buffer free qid 0 (positive) */
+ qid = 0;
+ mq = &c->rx_queues[qid];
+ ring = mq->ring;
+ ring->head += 10;
+
+ bufs = malloc (sizeof (memif_buffer_t) * max_buf);
+
+ if ((err =
+ memif_rx_burst (conn, qid, bufs, max_buf, &rx)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_uint_eq (rx, max_buf);
+ for (i = 0; i < max_buf; i++)
+ ck_assert_ptr_ne (bufs[i].data, NULL);
+
+ if ((err =
+ memif_buffer_free (conn, qid, bufs, max_buf,
+ &buf)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_uint_eq (buf, max_buf);
+ for (i = 0; i < max_buf; i++)
+ ck_assert_ptr_eq (bufs[i].data, NULL);
+ ck_assert_uint_eq (ring->head, ring->tail);
+
+ /* test buffer free qid 1 (positive) */
+ qid = 1;
+ mq = &c->rx_queues[qid];
+ ring = mq->ring;
+ ring->head += 10;
+
+ free (bufs);
+ bufs = malloc (sizeof (memif_buffer_t) * max_buf);
+
+ if ((err =
+ memif_rx_burst (conn, qid, bufs, max_buf, &rx)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_uint_eq (rx, max_buf);
+ for (i = 0; i < max_buf; i++)
+ ck_assert_ptr_ne (bufs[i].data, NULL);
+
+ if ((err =
+ memif_buffer_free (conn, qid, bufs, max_buf,
+ &buf)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_uint_eq (buf, max_buf);
+ for (i = 0; i < max_buf; i++)
+ ck_assert_ptr_eq (bufs[i].data, NULL);
+ ck_assert_uint_eq (ring->head, ring->tail);
+
+
+ /* test buffer free qid 2 (negative) */
+ qid = 2;
+ free (bufs);
+ bufs = malloc (sizeof (memif_buffer_t) * max_buf);
+
+ if ((err =
+ memif_buffer_free (conn, qid, bufs, max_buf,
+ &buf)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_QID, "err code: %u, err msg: %s", err,
+ memif_strerror (err));
+
+ if (lm->timerfd > 0)
+ close (lm->timerfd);
+ lm->timerfd = -1;
+ free (bufs);
+ bufs = NULL;
+
+ memif_delete (&conn);
+ ck_assert_ptr_eq (conn, NULL);
+}
+
+END_TEST
+START_TEST (test_get_details)
+{
+ int err, i;
+ ready_called = 0;
+ memif_conn_handle_t conn = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+ args.num_s2m_rings = 2;
+ args.num_m2s_rings = 2;
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ strncpy ((char *) args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+
+ if ((err = memif_create (&conn, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *c = (memif_connection_t *) conn;
+
+ c->run_args.num_s2m_rings = 2;
+ c->run_args.num_m2s_rings = 2;
+ c->run_args.log2_ring_size = 10;
+ c->run_args.buffer_size = 2048;
+
+ if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_details_t md;
+ memset (&md, 0, sizeof (md));
+ ssize_t buflen = 2048;
+ char *buf = malloc (buflen);
+ memset (buf, 0, buflen);
+
+ if ((err = memif_get_details (conn, &md, buf, buflen)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_str_eq (md.if_name, c->args.interface_name);
+ ck_assert_str_eq (md.inst_name, c->args.instance_name);
+ ck_assert_str_eq (md.remote_if_name, c->remote_if_name);
+ ck_assert_str_eq (md.remote_inst_name, c->remote_name);
+ ck_assert_str_eq (md.secret, c->args.secret);
+ ck_assert_str_eq (md.socket_filename, c->args.socket_filename);
+
+ ck_assert_uint_eq (md.id, c->args.interface_id);
+ ck_assert_uint_ne (md.role, c->args.is_master);
+ ck_assert_uint_eq (md.mode, c->args.mode);
+ for (i = 0; i < md.rx_queues_num; i++)
+ {
+ ck_assert_uint_eq (md.rx_queues[i].qid, i);
+ ck_assert_uint_eq (md.rx_queues[i].ring_size,
+ (1 << c->args.log2_ring_size));
+ ck_assert_uint_eq (md.rx_queues[i].buffer_size, c->args.buffer_size);
+ }
+ for (i = 0; i < md.tx_queues_num; i++)
+ {
+ ck_assert_uint_eq (md.tx_queues[i].qid, i);
+ ck_assert_uint_eq (md.tx_queues[i].ring_size,
+ (1 << c->args.log2_ring_size));
+ ck_assert_uint_eq (md.tx_queues[i].buffer_size, c->args.buffer_size);
+ }
+ ck_assert_uint_eq (md.link_up_down, 0);
+
+ if (lm->timerfd > 0)
+ close (lm->timerfd);
+ lm->timerfd = -1;
+
+ memif_delete (&conn);
+ ck_assert_ptr_eq (conn, NULL);
+}
+
+END_TEST
+START_TEST (test_init_regions_and_queues)
+{
+ int err;
+ ready_called = 0;
+ memif_conn_handle_t conn = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+ args.num_s2m_rings = 2;
+ args.num_m2s_rings = 2;
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ strncpy ((char *) args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+
+ if ((err = memif_create (&conn, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *c = (memif_connection_t *) conn;
+
+ c->run_args.num_s2m_rings = 2;
+ c->run_args.num_m2s_rings = 2;
+ c->run_args.log2_ring_size = 10;
+ c->run_args.buffer_size = 2048;
+
+ if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_ptr_ne (c->regions, NULL);
+ ck_assert_ptr_ne (c->tx_queues, NULL);
+ ck_assert_ptr_ne (c->rx_queues, NULL);
+
+ ck_assert_ptr_ne (c->regions->shm, NULL);
+ ck_assert_ptr_ne (c->tx_queues->ring, NULL);
+ ck_assert_ptr_ne (c->rx_queues->ring, NULL);
+
+ ck_assert_int_ne (c->regions->fd, -1);
+ ck_assert_uint_eq (c->tx_queues->ring->cookie, MEMIF_COOKIE);
+ ck_assert_uint_eq (c->rx_queues->ring->cookie, MEMIF_COOKIE);
+
+ if (lm->timerfd > 0)
+ close (lm->timerfd);
+ lm->timerfd = -1;
+
+ memif_delete (&conn);
+ ck_assert_ptr_eq (conn, NULL);
+}
+
+END_TEST
+START_TEST (test_connect1)
+{
+ int err;
+ ready_called = 0;
+ memif_conn_handle_t conn = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+ args.num_s2m_rings = 2;
+ args.num_m2s_rings = 2;
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ strncpy ((char *) args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+
+ if ((err = memif_create (&conn, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *c = (memif_connection_t *) conn;
+
+ c->run_args.num_s2m_rings = 2;
+ c->run_args.num_m2s_rings = 2;
+ c->run_args.log2_ring_size = 10;
+ c->run_args.buffer_size = 2048;
+
+ if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ if ((err = memif_connect1 (c)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ if (lm->timerfd > 0)
+ close (lm->timerfd);
+ lm->timerfd = -1;
+
+ memif_delete (&conn);
+ ck_assert_ptr_eq (conn, NULL);
+}
+
+END_TEST
+START_TEST (test_disconnect_internal)
+{
+ int err;
+ ready_called = 0;
+ memif_conn_handle_t conn = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+ args.num_s2m_rings = 2;
+ args.num_m2s_rings = 2;
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ strncpy ((char *) args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+
+ if ((err = memif_create (&conn, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *c = (memif_connection_t *) conn;
+
+ c->run_args.num_s2m_rings = 2;
+ c->run_args.num_m2s_rings = 2;
+ c->run_args.log2_ring_size = 10;
+ c->run_args.buffer_size = 2048;
+
+ if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ if ((err = memif_disconnect_internal (c)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_int_eq (c->fd, -1);
+
+ ck_assert_ptr_eq (c->tx_queues, NULL);
+ ck_assert_ptr_eq (c->rx_queues, NULL);
+ ck_assert_ptr_eq (c->regions, NULL);
+ ck_assert_ptr_eq (c->msg_queue, NULL);
+
+ struct itimerspec timer;
+ timerfd_gettime (lm->timerfd, &timer);
+
+ ck_assert_msg (timer.it_interval.tv_sec == lm->arm.it_interval.tv_sec,
+ "timerfd not armed!");
+
+ if (lm->timerfd > 0)
+ close (lm->timerfd);
+ lm->timerfd = -1;
+
+ memif_delete (&conn);
+ ck_assert_ptr_eq (conn, NULL);
+}
+
+END_TEST Suite * main_suite ()
+{
+ Suite *s;
+
+ TCase *tc_api;
+ TCase *tc_internal;
+
+ /* create main test suite */
+ s = suite_create ("Libmemif main");
+
+ /* create api test case */
+ tc_api = tcase_create ("Api calls");
+ /* add tests to test case */
+ tcase_add_test (tc_api, test_init);
+ tcase_add_test (tc_api, test_init_epoll);
+ tcase_add_test (tc_api, test_create);
+ tcase_add_test (tc_api, test_create_master);
+ tcase_add_test (tc_api, test_create_mult);
+ tcase_add_test (tc_api, test_control_fd_handler);
+ tcase_add_test (tc_api, test_buffer_alloc);
+ tcase_add_test (tc_api, test_tx_burst);
+ tcase_add_test (tc_api, test_rx_burst);
+ tcase_add_test (tc_api, test_buffer_free);
+ tcase_add_test (tc_api, test_get_details);
+
+ /* create internal test case */
+ tc_internal = tcase_create ("Internal");
+ /* add tests to test case */
+ tcase_add_test (tc_internal, test_init_regions_and_queues);
+ tcase_add_test (tc_internal, test_connect1);
+ tcase_add_test (tc_internal, test_disconnect_internal);
+
+ /* add test cases to test suite */
+ suite_add_tcase (s, tc_api);
+ suite_add_tcase (s, tc_internal);
+
+ /* return main test suite to test runner */
+ return s;
+}
diff --git a/extras/libmemif/test/main_test.h b/extras/libmemif/test/main_test.h
new file mode 100644
index 00000000..300d8a8e
--- /dev/null
+++ b/extras/libmemif/test/main_test.h
@@ -0,0 +1,25 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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 _MAIN_TEST_H_
+#define _MAIN_TEST_H_
+
+#include <unit_test.h>
+
+Suite *main_suite ();
+
+#endif /* _MAIN_TEST_H_ */
diff --git a/extras/libmemif/test/socket_test.c b/extras/libmemif/test/socket_test.c
new file mode 100644
index 00000000..f148495a
--- /dev/null
+++ b/extras/libmemif/test/socket_test.c
@@ -0,0 +1,625 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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 <socket_test.h>
+
+#include <memif_private.h>
+#include <socket.h>
+
+static int
+get_queue_len (memif_msg_queue_elt_t * q)
+{
+ int r = 0;
+ memif_msg_queue_elt_t *c = q;
+ while (c != NULL)
+ {
+ r++;
+ c = c->next;
+ }
+ return r;
+}
+
+static void
+queue_free (memif_msg_queue_elt_t ** e)
+{
+ if (*e == NULL)
+ return;
+ queue_free (&(*e)->next);
+ free (*e);
+ *e = NULL;
+ return;
+}
+
+START_TEST (test_msg_queue)
+{
+ memif_connection_t conn;
+ conn.msg_queue = NULL;
+ conn.fd = -1;
+
+ int i, len = 10;
+
+ for (i = 0; i < len; i++)
+ {
+ if (i % 2)
+ memif_msg_enq_ack (&conn);
+ else
+ memif_msg_enq_init (&conn);
+ }
+
+ ck_assert_int_eq (len, get_queue_len (conn.msg_queue));
+
+ int pop = 6;
+
+ for (i = 0; i < pop; i++)
+ {
+ if (i % 2)
+ {
+ ck_assert_uint_eq (conn.msg_queue->msg.type, MEMIF_MSG_TYPE_ACK);
+ }
+ else
+ {
+ ck_assert_uint_eq (conn.msg_queue->msg.type, MEMIF_MSG_TYPE_INIT);
+ }
+ conn.flags |= MEMIF_CONNECTION_FLAG_WRITE;
+ /* function will return -1 because no socket is created */
+ memif_conn_fd_write_ready (&conn);
+ }
+
+ ck_assert_int_eq ((len - pop), get_queue_len (conn.msg_queue));
+
+ queue_free (&conn.msg_queue);
+}
+
+END_TEST
+START_TEST (test_enq_ack)
+{
+ int err;
+ memif_connection_t conn;
+ conn.msg_queue = NULL;
+
+ if ((err = memif_msg_enq_ack (&conn)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+ memif_msg_queue_elt_t *e = conn.msg_queue;
+
+ ck_assert_uint_eq (e->msg.type, MEMIF_MSG_TYPE_ACK);
+ ck_assert_int_eq (e->fd, -1);
+ queue_free (&conn.msg_queue);
+}
+
+END_TEST
+START_TEST (test_enq_init)
+{
+ int err;
+ memif_connection_t conn;
+ conn.msg_queue = NULL;
+
+ conn.args.interface_id = 69;
+ conn.args.mode = 0;
+
+ strncpy ((char *) conn.args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+ strncpy ((char *) conn.args.secret, TEST_SECRET, strlen (TEST_SECRET));
+
+ if ((err = memif_msg_enq_init (&conn)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_msg_queue_elt_t *e = conn.msg_queue;
+
+ ck_assert_uint_eq (e->msg.type, MEMIF_MSG_TYPE_INIT);
+ ck_assert_int_eq (e->fd, -1);
+
+ memif_msg_init_t *i = &e->msg.init;
+
+ ck_assert_uint_eq (i->version, MEMIF_VERSION);
+ ck_assert_uint_eq (i->id, conn.args.interface_id);
+ ck_assert_uint_eq (i->mode, conn.args.mode);
+ ck_assert_str_eq (i->name, conn.args.instance_name);
+ ck_assert_str_eq (i->secret, conn.args.secret);
+ queue_free (&conn.msg_queue);
+}
+
+END_TEST
+START_TEST (test_enq_add_region)
+{
+ int err;
+ memif_connection_t conn;
+ conn.msg_queue = NULL;
+ conn.regions = (memif_region_t *) malloc (sizeof (memif_region_t));
+ memif_region_t *mr = conn.regions;
+ mr->fd = 5;
+ mr->region_size = 2048;
+ uint8_t region_index = 0;
+
+ if ((err =
+ memif_msg_enq_add_region (&conn, region_index)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_msg_queue_elt_t *e = conn.msg_queue;
+
+ ck_assert_uint_eq (e->msg.type, MEMIF_MSG_TYPE_ADD_REGION);
+ ck_assert_int_eq (e->fd, mr->fd);
+
+ memif_msg_add_region_t *ar = &e->msg.add_region;
+
+ ck_assert_uint_eq (ar->index, region_index);
+ ck_assert_uint_eq (ar->size, mr->region_size);
+
+ free (conn.regions);
+ conn.regions = NULL;
+ mr = NULL;
+ queue_free (&conn.msg_queue);
+}
+
+END_TEST
+START_TEST (test_enq_add_ring)
+{
+ int err;
+ memif_connection_t conn;
+ conn.msg_queue = NULL;
+ conn.rx_queues = (memif_queue_t *) malloc (sizeof (memif_queue_t));
+ conn.tx_queues = (memif_queue_t *) malloc (sizeof (memif_queue_t));
+
+ memif_queue_t *mq = conn.tx_queues;
+ uint8_t dir = MEMIF_RING_S2M;
+ mq->int_fd = 5;
+ mq->offset = 0;
+ mq->log2_ring_size = 10;
+
+ if ((err = memif_msg_enq_add_ring (&conn, 0, dir)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_msg_queue_elt_t *e = conn.msg_queue;
+
+ ck_assert_uint_eq (e->msg.type, MEMIF_MSG_TYPE_ADD_RING);
+ ck_assert_int_eq (e->fd, mq->int_fd);
+
+ memif_msg_add_ring_t *ar = &e->msg.add_ring;
+
+ ck_assert_uint_eq (ar->index, 0);
+ ck_assert_uint_eq (ar->offset, mq->offset);
+ ck_assert_uint_eq (ar->log2_ring_size, mq->log2_ring_size);
+ ck_assert (ar->flags & MEMIF_MSG_ADD_RING_FLAG_S2M);
+
+ dir = MEMIF_RING_M2S;
+ if ((err = memif_msg_enq_add_ring (&conn, 0, dir)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+ queue_free (&conn.msg_queue);
+}
+
+END_TEST
+START_TEST (test_enq_connect)
+{
+ int err;
+ memif_connection_t conn;
+ conn.msg_queue = NULL;
+ memset (conn.args.interface_name, 0, sizeof (conn.args.interface_name));
+ strncpy ((char *) conn.args.interface_name, TEST_IF_NAME,
+ strlen (TEST_IF_NAME));
+
+ if ((err = memif_msg_enq_connect (&conn)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_msg_queue_elt_t *e = conn.msg_queue;
+
+ ck_assert_uint_eq (e->msg.type, MEMIF_MSG_TYPE_CONNECT);
+ ck_assert_int_eq (e->fd, -1);
+ ck_assert_str_eq (e->msg.connect.if_name, TEST_IF_NAME);
+ queue_free (&conn.msg_queue);
+}
+
+END_TEST
+START_TEST (test_enq_connected)
+{
+ int err;
+ memif_connection_t conn;
+ conn.msg_queue = NULL;
+ memset (conn.args.interface_name, 0, sizeof (conn.args.interface_name));
+ strncpy ((char *) conn.args.interface_name, TEST_IF_NAME,
+ strlen (TEST_IF_NAME));
+
+ if ((err = memif_msg_enq_connected (&conn)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_msg_queue_elt_t *e = conn.msg_queue;
+
+ ck_assert_uint_eq (e->msg.type, MEMIF_MSG_TYPE_CONNECTED);
+ ck_assert_int_eq (e->fd, -1);
+ ck_assert_str_eq (e->msg.connect.if_name, TEST_IF_NAME);
+ queue_free (&conn.msg_queue);
+}
+
+END_TEST
+START_TEST (test_send)
+{
+ int err;
+ int fd = -1, afd = 5;
+ memif_msg_t msg;
+ memset (&msg, 0, sizeof (msg));
+
+ if ((err = memif_msg_send (fd, &msg, afd)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_BAD_FD,
+ "err code: %u, err msg: %s", err, memif_strerror (err));
+}
+
+END_TEST
+START_TEST (test_send_hello)
+{
+ int err;
+ memif_connection_t conn;
+ conn.fd = -1;
+ memset (conn.args.instance_name, 0, sizeof (conn.args.instance_name));
+ strncpy ((char *) conn.args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ if ((err = memif_msg_send_hello (conn.fd)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_BAD_FD,
+ "err code: %u, err msg: %s", err, memif_strerror (err));
+}
+
+END_TEST
+START_TEST (test_send_disconnect)
+{
+ int err;
+ memif_connection_t conn;
+ conn.fd = -1;
+
+ /* only possible fail if memif_msg_send fails... */
+ /* obsolete without socket */
+ if ((err =
+ memif_msg_send_disconnect (conn.fd, "unit_test_dc",
+ 0)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_BAD_FD, "err code: %u, err msg: %s", err,
+ memif_strerror (err));
+}
+
+END_TEST
+START_TEST (test_recv_hello)
+{
+ int err;
+ memif_connection_t conn;
+ memif_msg_t msg;
+
+ memif_msg_hello_t *h = &msg.hello;
+
+ msg.type = MEMIF_MSG_TYPE_HELLO;
+
+ h->min_version = MEMIF_VERSION;
+ h->max_version = MEMIF_VERSION;
+ h->max_s2m_ring = 1;
+ h->max_m2s_ring = 1;
+ h->max_log2_ring_size = 14;
+ strncpy ((char *) h->name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ memset (conn.remote_name, 0, sizeof (conn.remote_name));
+
+ conn.args.num_s2m_rings = 4;
+ conn.args.num_m2s_rings = 6;
+ conn.args.log2_ring_size = 10;
+
+ if ((err = memif_msg_receive_hello (&conn, &msg)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_uint_eq (conn.run_args.num_s2m_rings, 2);
+ ck_assert_uint_eq (conn.run_args.num_m2s_rings, 2);
+ ck_assert_uint_eq (conn.run_args.log2_ring_size, 10);
+ ck_assert_str_eq (conn.remote_name, TEST_IF_NAME);
+
+ h->max_version = 9;
+ if ((err = memif_msg_receive_hello (&conn, &msg)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_PROTO,
+ "err code: %u, err msg: %s", err, memif_strerror (err));
+}
+
+END_TEST
+START_TEST (test_recv_init)
+{
+ int err;
+ memif_connection_t conn;
+
+ conn.args.interface_id = 69;
+ conn.args.is_master = 1;
+ conn.fd = -1;
+ conn.args.mode = 0;
+ memset (conn.args.secret, '\0', 24);
+ strncpy ((char *) conn.args.secret, TEST_SECRET, strlen (TEST_SECRET));
+
+ memif_msg_t msg;
+
+ memif_msg_init_t *i = &msg.init;
+
+ msg.type = MEMIF_MSG_TYPE_INIT;
+
+ i->version = MEMIF_VERSION;
+ i->id = 69;
+ i->mode = 0;
+ memset (i->name, '\0', 32);
+ memset (i->secret, '\0', 24);
+ strncpy ((char *) i->name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ strncpy ((char *) i->secret, TEST_SECRET, strlen (TEST_SECRET));
+
+ memif_socket_t ms;
+ ms.interface_list_len = 1;
+ ms.interface_list = malloc (sizeof (memif_list_elt_t));
+ memif_list_elt_t elt;
+ elt.key = 69;
+ elt.data_struct = &conn;
+ add_list_elt (&elt, &ms.interface_list, &ms.interface_list_len);
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ if ((err = memif_msg_receive_init (&ms, -1, &msg)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ i->version = 9;
+ if ((err = memif_msg_receive_init (&ms, -1, &msg)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_PROTO,
+ "err code: %u, err msg: %s", err, memif_strerror (err));
+ i->version = MEMIF_VERSION;
+
+ i->id = 78;
+ if ((err = memif_msg_receive_init (&ms, -1, &msg)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_ID,
+ "err code: %u, err msg: %s", err, memif_strerror (err));
+ i->id = 69;
+
+ i->mode = 1;
+ if ((err = memif_msg_receive_init (&ms, -1, &msg)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_MODE,
+ "err code: %u, err msg: %s", err, memif_strerror (err));
+ i->mode = 0;
+
+ i->secret[0] = '\0';
+ if ((err = memif_msg_receive_init (&ms, -1, &msg)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_SECRET,
+ "err code: %u, err msg: %s", err, memif_strerror (err));
+ strncpy ((char *) i->secret, TEST_SECRET, strlen (TEST_SECRET));
+
+ conn.args.is_master = 0;
+ if ((err = memif_msg_receive_init (&ms, -1, &msg)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_ACCSLAVE,
+ "err code: %u, err msg: %s", err, memif_strerror (err));
+ conn.args.is_master = 1;
+
+ conn.fd = 5;
+ if ((err = memif_msg_receive_init (&ms, -1, &msg)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg ((err == MEMIF_ERR_ALRCONN) || (err == MEMIF_ERR_BAD_FD),
+ "err code: %u, err msg: %s", err, memif_strerror (err));
+}
+
+END_TEST
+START_TEST (test_recv_add_region)
+{
+ int err;
+ memif_connection_t conn;
+ conn.regions = NULL;
+ memif_msg_t msg;
+ msg.type = MEMIF_MSG_TYPE_ADD_REGION;
+ msg.add_region.size = 2048;
+ msg.add_region.index = 0;
+
+ int fd = 5;
+
+ if ((err =
+ memif_msg_receive_add_region (&conn, &msg, fd)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_region_t *mr = conn.regions;
+
+ ck_assert_uint_eq (mr->fd, fd);
+ ck_assert_uint_eq (mr->region_size, 2048);
+ ck_assert_ptr_eq (mr->shm, NULL);
+}
+
+END_TEST
+START_TEST (test_recv_add_ring)
+{
+ int err;
+ memif_connection_t conn;
+ int fd = 5;
+ memif_msg_t msg;
+ conn.args.num_s2m_rings = 2;
+ conn.args.num_m2s_rings = 2;
+ conn.rx_queues = NULL;
+ conn.tx_queues = NULL;
+
+ msg.type = MEMIF_MSG_TYPE_ADD_RING;
+ memif_msg_add_ring_t *ar = &msg.add_ring;
+
+ ar->log2_ring_size = 10;
+ ar->region = 0;
+ ar->offset = 0;
+ ar->flags = 0;
+ ar->flags |= MEMIF_MSG_ADD_RING_FLAG_S2M;
+ ar->index = 1;
+
+ if ((err =
+ memif_msg_receive_add_ring (&conn, &msg, fd)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+
+ ar->offset = 2048;
+ ar->flags &= ~MEMIF_MSG_ADD_RING_FLAG_S2M;
+
+ if ((err =
+ memif_msg_receive_add_ring (&conn, &msg, fd)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+}
+
+END_TEST
+START_TEST (test_recv_connect)
+{
+ int err;
+ memif_conn_handle_t c = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+
+ args.interface_id = 0;
+ args.is_master = 0;
+ args.mode = 0;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ if ((err = memif_create (&c, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *conn = (memif_connection_t *) c;
+
+ conn->run_args.num_s2m_rings = 1;
+ conn->run_args.num_m2s_rings = 1;
+ conn->run_args.log2_ring_size = 10;
+ conn->run_args.buffer_size = 2048;
+
+ if ((err = memif_init_regions_and_queues (conn)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_msg_t msg;
+ memset (&msg, 0, sizeof (msg));
+ msg.type = MEMIF_MSG_TYPE_CONNECT;
+
+ memset (msg.connect.if_name, 0, sizeof (msg.connect.if_name));
+ strncpy ((char *) msg.connect.if_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+
+ if ((err = memif_msg_receive_connect (conn, &msg)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_str_eq (conn->remote_if_name, TEST_IF_NAME);
+}
+
+END_TEST
+START_TEST (test_recv_connected)
+{
+ int err;
+ memif_conn_handle_t c = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+
+ args.interface_id = 0;
+ args.is_master = 0;
+ args.mode = 0;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ if ((err = memif_create (&c, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *conn = (memif_connection_t *) c;
+
+ conn->run_args.num_s2m_rings = 1;
+ conn->run_args.num_m2s_rings = 1;
+ conn->run_args.log2_ring_size = 10;
+ conn->run_args.buffer_size = 2048;
+
+ if ((err = memif_init_regions_and_queues (conn)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_msg_t msg;
+ memset (&msg, 0, sizeof (msg));
+ msg.type = MEMIF_MSG_TYPE_CONNECT;
+
+ memset (msg.connect.if_name, 0, sizeof (msg.connect.if_name));
+ strncpy ((char *) msg.connect.if_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+
+ if ((err = memif_msg_receive_connected (conn, &msg)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_str_eq (conn->remote_if_name, TEST_IF_NAME);
+}
+
+END_TEST
+START_TEST (test_recv_disconnect)
+{
+ int err;
+ memif_connection_t conn;
+ memif_msg_t msg;
+ msg.type = MEMIF_MSG_TYPE_DISCONNECT;
+ memset (msg.disconnect.string, 0, sizeof (msg.disconnect.string));
+ strncpy ((char *) msg.disconnect.string, "unit_test_dc", 12);
+
+ if ((err = memif_msg_receive_disconnect (&conn, &msg)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_DISCONNECT,
+ "err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_str_eq (conn.remote_disconnect_string, "unit_test_dc");
+}
+
+END_TEST Suite * socket_suite ()
+{
+ Suite *s;
+ TCase *tc_msg_queue;
+ TCase *tc_msg_enq;
+ TCase *tc_msg_send;
+ TCase *tc_msg_recv;
+
+ /* create socket test suite */
+ s = suite_create ("Socket messaging");
+
+ /* create msg queue test case */
+ tc_msg_queue = tcase_create ("Message queue");
+ /* add tests to test case */
+ tcase_add_test (tc_msg_queue, test_msg_queue);
+
+ /* create msg enq test case */
+ tc_msg_enq = tcase_create ("Message enqueue");
+ /* add tests to test case */
+ tcase_add_test (tc_msg_enq, test_enq_ack);
+ tcase_add_test (tc_msg_enq, test_enq_init);
+ tcase_add_test (tc_msg_enq, test_enq_add_region);
+ tcase_add_test (tc_msg_enq, test_enq_add_ring);
+ tcase_add_test (tc_msg_enq, test_enq_connect);
+ tcase_add_test (tc_msg_enq, test_enq_connected);
+
+ /* create msg send test case */
+ tc_msg_send = tcase_create ("Message send");
+ /* add tests to test case */
+ tcase_add_test (tc_msg_send, test_send);
+ tcase_add_test (tc_msg_send, test_send_hello);
+ tcase_add_test (tc_msg_send, test_send_disconnect);
+
+ /* create msg recv test case */
+ tc_msg_recv = tcase_create ("Message receive");
+ /* add tests to test case */
+ tcase_add_test (tc_msg_recv, test_recv_hello);
+ tcase_add_test (tc_msg_recv, test_recv_init);
+ tcase_add_test (tc_msg_recv, test_recv_add_region);
+ tcase_add_test (tc_msg_recv, test_recv_add_ring);
+ tcase_add_test (tc_msg_recv, test_recv_connect);
+ tcase_add_test (tc_msg_recv, test_recv_connected);
+ tcase_add_test (tc_msg_recv, test_recv_disconnect);
+
+ /* add test cases to test suite */
+ suite_add_tcase (s, tc_msg_queue);
+ suite_add_tcase (s, tc_msg_enq);
+ suite_add_tcase (s, tc_msg_send);
+ suite_add_tcase (s, tc_msg_recv);
+
+ /* return socket test suite to test runner */
+ return s;
+}
diff --git a/extras/libmemif/test/socket_test.h b/extras/libmemif/test/socket_test.h
new file mode 100644
index 00000000..02ec69cf
--- /dev/null
+++ b/extras/libmemif/test/socket_test.h
@@ -0,0 +1,25 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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 _SOCKET_TEST_H_
+#define _SOCKET_TEST_H_
+
+#include <unit_test.h>
+
+Suite *socket_suite ();
+
+#endif /* _SOCKET_TEST_H_ */
diff --git a/extras/libmemif/test/unit_test.c b/extras/libmemif/test/unit_test.c
new file mode 100644
index 00000000..a305de93
--- /dev/null
+++ b/extras/libmemif/test/unit_test.c
@@ -0,0 +1,63 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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 <main_test.h>
+#include <socket_test.h>
+
+int
+on_connect (memif_conn_handle_t conn, void *ctx)
+{
+ return 0;
+}
+
+int
+on_disconnect (memif_conn_handle_t conn, void *ctx)
+{
+ return 0;
+}
+
+int
+on_interrupt (memif_conn_handle_t conn, void *ctx, uint16_t qid)
+{
+ return 0;
+}
+
+int
+control_fd_update (int fd, uint8_t events)
+{
+ return 0;
+}
+
+int
+main (void)
+{
+ int num_fail;
+ Suite *main, *socket;
+ SRunner *sr;
+
+ main = main_suite ();
+ socket = socket_suite ();
+
+ sr = srunner_create (main);
+
+ srunner_add_suite (sr, socket);
+
+ srunner_run_all (sr, CK_VERBOSE);
+ num_fail = srunner_ntests_failed (sr);
+ srunner_free (sr);
+ return (num_fail == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
diff --git a/extras/libmemif/test/unit_test.h b/extras/libmemif/test/unit_test.h
new file mode 100644
index 00000000..fae3cbaa
--- /dev/null
+++ b/extras/libmemif/test/unit_test.h
@@ -0,0 +1,38 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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 _UNIT_TEST_H_
+#define _UNIT_TEST_H_
+
+#include <stdlib.h>
+#include <check.h>
+
+#include <libmemif.h>
+
+#define TEST_APP_NAME "unit_test_app"
+#define TEST_IF_NAME "unit_test_if"
+#define TEST_SECRET "psst"
+
+int on_connect (memif_conn_handle_t conn, void *ctx);
+
+int on_disconnect (memif_conn_handle_t conn, void *ctx);
+
+int on_interrupt (memif_conn_handle_t conn, void *ctx, uint16_t qid);
+
+int control_fd_update (int fd, uint8_t events);
+
+#endif /* _UNIT_TEST_H_ */
diff --git a/extras/rpm/Makefile b/extras/rpm/Makefile
new file mode 100644
index 00000000..534e4d43
--- /dev/null
+++ b/extras/rpm/Makefile
@@ -0,0 +1,46 @@
+# Copyright (c) 2017 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.
+
+
+TARBALL=$(shell realpath ../../build-root/vpp-latest.tar.xz)
+
+BASENAME=$(shell basename $(TARBALL) | sed -e s/.tar.\*//)
+VERSION=$(shell echo $(BASENAME) | cut -f2 -d-)
+RELEASE=$(shell echo $(BASENAME) | cut -f3- -d- | sed -e s/-/_/g)
+PC=%
+
+all: RPM
+
+srpm:
+ @echo $(TARBALL)
+ mkdir -p rpmbuild/{RPMS,SRPMS,BUILD,SOURCES,SPECS}
+ cp $(TARBALL) rpmbuild/SOURCES/vpp-$(VERSION)-$(RELEASE).tar.xz
+ cp vpp.spec rpmbuild/SOURCES
+ sed -i '1s/^/$(PC)define _version $(VERSION)\n/' rpmbuild/SOURCES/vpp.spec
+ sed -i '1s/^/$(PC)define _release $(RELEASE)\n/' rpmbuild/SOURCES/vpp.spec
+ sed -i '/define _topdir/d' rpmbuild/SOURCES/vpp.spec
+ rpmbuild -bs \
+ --define "_topdir rpmbuild" \
+ rpmbuild/SOURCES/vpp.spec
+ mv $$(find rpmbuild/SRPMS -name \*.src.rpm -type f) .
+
+RPM:
+ @echo $(TARBALL)
+ mkdir -p RPMS SOURCES
+ cp $(TARBALL) SOURCES/vpp-$(VERSION)-$(RELEASE).tar.xz
+ rpmbuild -bb \
+ --define "_topdir $(PWD)" \
+ --define "_version $(VERSION)" \
+ --define "_release $(RELEASE)" \
+ vpp.spec
+ mv $$(find RPMS -name \*.rpm -type f) .
diff --git a/extras/rpm/vpp.service b/extras/rpm/vpp.service
new file mode 100644
index 00000000..40bf9d48
--- /dev/null
+++ b/extras/rpm/vpp.service
@@ -0,0 +1,14 @@
+[Unit]
+Description=Vector Packet Processing Process
+After=syslog.target network.target auditd.service
+
+[Service]
+ExecStartPre=-/bin/rm -f /dev/shm/db /dev/shm/global_vm /dev/shm/vpe-api
+ExecStartPre=-/sbin/modprobe uio_pci_generic
+ExecStart=/usr/bin/vpp -c /etc/vpp/startup.conf
+Type=simple
+Restart=on-failure
+RestartSec=5s
+
+[Install]
+WantedBy=multi-user.target
diff --git a/extras/rpm/vpp.spec b/extras/rpm/vpp.spec
new file mode 100644
index 00000000..7490a165
--- /dev/null
+++ b/extras/rpm/vpp.spec
@@ -0,0 +1,349 @@
+%bcond_without aesni
+%define _vpp_build_dir build-tool-native
+%define _unitdir /lib/systemd/system
+%define _topdir %(pwd)
+%define _builddir %{_topdir}
+%define _tmp_build_dir %{name}-%{_version}.0
+%define _mu_build_dir %{_topdir}/%{_tmp_build_dir}/build-root
+%define _vpp_tag %{getenv:TAG}
+%if "%{_vpp_tag}" == ""
+%define _vpp_tag vpp
+%endif
+%define _vpp_install_dir install-%{_vpp_tag}-native
+
+# Failsafe backport of Python2-macros for RHEL <= 6
+%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")}
+%{!?python_sitearch: %global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")}
+%{!?python_version: %global python_version %(%{__python} -c "import sys; sys.stdout.write(sys.version[:3])")}
+%{!?__python2: %global __python2 %{__python}}
+%{!?python2_sitelib: %global python2_sitelib %{python_sitelib}}
+%{!?python2_sitearch: %global python2_sitearch %{python_sitearch}}
+%{!?python2_version: %global python2_version %{python_version}}
+
+%{!?python2_minor_version: %define python2_minor_version %(%{__python} -c "import sys ; print sys.version[2:3]")}
+
+%{?systemd_requires}
+
+Name: vpp
+Summary: Vector Packet Processing
+License: ASL 2.0
+Version: %{_version}
+Release: %{_release}
+Requires: vpp-lib = %{_version}-%{_release}, net-tools, pciutils, python
+BuildRequires: systemd, chrpath
+BuildRequires: check, check-devel
+%if 0%{?fedora} >= 25
+BuildRequires: subunit, subunit-devel
+%endif
+%if 0%{?fedora} >= 26
+BuildRequires: compat-openssl10-devel
+BuildRequires: python2-devel, python2-virtualenv
+%else
+%if 0%{?fedora} == 25
+BuildRequires: openssl-devel
+BuildRequires: python-devel, python2-virtualenv
+%else
+BuildREquires: openssl-devel
+BuildRequires: python-devel, python-virtualenv
+%endif
+%endif
+BuildRequires: libffi-devel
+BuildRequires: glibc-static, java-1.8.0-openjdk, java-1.8.0-openjdk-devel yum-utils, redhat-lsb
+BuildRequires: apr-devel
+%if %{with aesni}
+BuildRequires: nasm
+%endif
+BuildRequires: numactl-devel
+BuildRequires: autoconf automake libtool byacc bison flex
+
+Source: %{name}-%{_version}-%{_release}.tar.xz
+# Source: vpp-latest.tar.xz
+
+%description
+This package provides VPP executables: vpp, vpp_api_test, vpp_json_test
+vpp - the vector packet engine
+vpp_api_test - vector packet engine API test tool
+vpp_json_test - vector packet engine JSON test tool
+
+%package lib
+Summary: VPP libraries
+Group: System Environment/Libraries
+
+%description lib
+This package contains the VPP shared libraries, including:
+vppinfra - foundation library supporting vectors, hashes, bitmaps, pools, and string formatting.
+svm - vm library
+vlib - vector processing library
+vlib-api - binary API library
+vnet - network stack library
+
+%package devel
+Summary: VPP header files, static libraries
+Group: Development/Libraries
+Requires: vpp-lib
+
+%description devel
+This package contains the header files for VPP.
+Install this package if you want to write a
+program for compilation and linking with vpp lib.
+vlib
+vlibmemory
+vnet - devices, classify, dhcp, ethernet flow, gre, ip, etc.
+vpp-api
+vppinfra
+
+%package plugins
+Summary: Vector Packet Processing--runtime plugins
+Group: System Environment/Libraries
+Requires: vpp = %{_version}-%{_release}
+%description plugins
+This package contains VPP plugins
+
+%package api-lua
+Summary: VPP api lua bindings
+Group: Development/Libraries
+Requires: vpp = %{_version}-%{_release}, vpp-lib = %{_version}-%{_release}
+
+%description api-lua
+This package contains the lua bindings for the vpp api
+
+%package api-java
+Summary: VPP api java bindings
+Group: Development/Libraries
+Requires: vpp = %{_version}-%{_release}, vpp-lib = %{_version}-%{_release}
+
+%description api-java
+This package contains the java bindings for the vpp api
+
+%package api-python
+Summary: VPP api python bindings
+Group: Development/Libraries
+Requires: vpp = %{_version}-%{_release}, vpp-lib = %{_version}-%{_release}, python-setuptools libffi-devel
+
+%description api-python
+This package contains the python bindings for the vpp api
+
+%prep
+# Unpack into dir with longer name as work around of debugedit bug in in rpm-build 4.13
+rm -rf %{name}-%{_version}
+rm -rf %{_tmp_build_dir}
+/usr/bin/xz -dc '%{_sourcedir}/%{name}-%{_version}-%{_release}.tar.xz' | /usr/bin/tar -xf -
+mv %{name}-%{_version} %{_tmp_build_dir}
+cd '%{_tmp_build_dir}'
+/usr/bin/chmod -Rf a+rX,u+w,g-w,o-w .
+
+%pre
+# Add the vpp group
+groupadd -f -r vpp
+
+%build
+cd '%{_tmp_build_dir}'
+%if %{with aesni}
+ make bootstrap
+ make -C build-root PLATFORM=vpp TAG=%{_vpp_tag} install-packages
+%else
+ make bootstrap AESNI=n
+ make -C build-root PLATFORM=vpp AESNI=n TAG=%{_vpp_tag} install-packages
+%endif
+cd %{_mu_build_dir}/../src/vpp-api/python && %py2_build
+
+%install
+#
+# binaries
+#
+mkdir -p -m755 %{buildroot}%{_bindir}
+mkdir -p -m755 %{buildroot}%{_unitdir}
+install -p -m 755 %{_mu_build_dir}/%{_vpp_install_dir}/vpp/bin/* %{buildroot}%{_bindir}
+
+# api
+mkdir -p -m755 %{buildroot}/usr/share/vpp/api
+
+#
+# configs
+#
+mkdir -p -m755 %{buildroot}/etc/vpp
+mkdir -p -m755 %{buildroot}/etc/sysctl.d
+install -p -m 644 %{_mu_build_dir}/../extras/rpm/vpp.service %{buildroot}%{_unitdir}
+install -p -m 644 %{_mu_build_dir}/../src/vpp/conf/startup.conf %{buildroot}/etc/vpp/startup.conf
+install -p -m 644 %{_mu_build_dir}/../src/vpp/conf/80-vpp.conf %{buildroot}/etc/sysctl.d
+#
+# libraries
+#
+mkdir -p -m755 %{buildroot}%{_libdir}
+mkdir -p -m755 %{buildroot}/etc/bash_completion.d
+mkdir -p -m755 %{buildroot}/usr/share/vpp
+for file in $(find %{_mu_build_dir}/%{_vpp_install_dir}/*/lib* -type f -name '*.so.*.*.*' -print )
+do
+ install -p -m 755 $file %{buildroot}%{_libdir}
+done
+for file in $(cd %{buildroot}%{_libdir} && find . -type f -print | sed -e 's/^\.\///')
+do
+ # make lib symlinks
+ ( cd %{buildroot}%{_libdir} &&
+ ln -fs $file $(echo $file | sed -e 's/\(\.so\.[0-9]\+\).*/\1/') )
+ ( cd %{buildroot}%{_libdir} &&
+ ln -fs $file $(echo $file | sed -e 's/\(\.so\)\.[0-9]\+.*/\1/') )
+done
+for file in $(find %{_mu_build_dir}/%{_vpp_install_dir}/vpp/share/vpp/api -type f -name '*.api.json' -print )
+do
+ install -p -m 644 $file %{buildroot}/usr/share/vpp/api
+done
+install -p -m 644 %{_mu_build_dir}/../src/scripts/vppctl_completion %{buildroot}/etc/bash_completion.d
+install -p -m 644 %{_mu_build_dir}/../src/scripts/vppctl-cmd-list %{buildroot}/usr/share/vpp
+
+# Lua bindings
+mkdir -p -m755 %{buildroot}/usr/share/doc/vpp/examples/lua/examples/cli
+mkdir -p -m755 %{buildroot}/usr/share/doc/vpp/examples/lua/examples/lute
+# for file in $(cd %{_mu_build_dir}/%{_vpp_install_dir}/../../src/vpp-api/lua && git ls-files .)
+for file in $(cd %{_mu_build_dir}/%{_vpp_install_dir}/../../src/vpp-api/lua && find . -type f -regex '.*/*.[luteamd]' -print | sed -e 's/^\.\///')
+do
+ ( cd %{_mu_build_dir}/%{_vpp_install_dir}/../../src/vpp-api/lua && install -p -m 644 $file \
+ %{buildroot}/usr/share/doc/vpp/examples/lua/$file )
+done
+
+# Java bindings
+mkdir -p -m755 %{buildroot}/usr/share/java
+for file in $(find %{_mu_build_dir}/%{_vpp_install_dir}/vpp/share/java -type f -name '*.jar' -print )
+do
+ install -p -m 644 $file %{buildroot}/usr/share/java
+done
+
+# Python bindings
+cd %{_mu_build_dir}/../src/vpp-api/python && %py2_install
+
+#
+# devel
+#
+for dir in $(find %{_mu_build_dir}/%{_vpp_install_dir}/*/include/ -maxdepth 0 -type d -print | grep -v dpdk)
+do
+ for subdir in $(cd ${dir} && find . -type d -print)
+ do
+ mkdir -p -m755 %{buildroot}/usr/include/${subdir}
+ done
+ for file in $(cd ${dir} && find . -type f -print)
+ do
+ install -p -m 644 $dir/$file %{buildroot}%{_includedir}/$file
+ done
+done
+
+mkdir -p -m755 %{buildroot}%{python2_sitelib}/jvppgen
+install -p -m755 %{_mu_build_dir}/../src/vpp-api/java/jvpp/gen/jvpp_gen.py %{buildroot}/usr/bin
+for i in $(ls %{_mu_build_dir}/../src/vpp-api/java/jvpp/gen/jvppgen/*.py); do
+ install -p -m666 ${i} %{buildroot}%{python2_sitelib}/jvppgen
+done;
+
+# sample plugin
+mkdir -p -m755 %{buildroot}/usr/share/doc/vpp/examples/sample-plugin/sample
+#for file in $(cd %{_mu_build_dir}/%{_vpp_install_dir}/../../src/examples/sample-plugin && git ls-files .)
+for file in $(cd %{_mu_build_dir}/%{_vpp_install_dir}/../../src/examples/sample-plugin && find . -type f -regex '.*/*.[acdhimp]' -print | sed -e 's/^\.\///')
+do
+ ( cd %{_mu_build_dir}/%{_vpp_install_dir}/../../src/examples/sample-plugin && install -p -m 644 $file \
+ %{buildroot}/usr/share/doc/vpp/examples/sample-plugin/$file )
+done
+
+
+#
+# vpp-plugins
+#
+mkdir -p -m755 %{buildroot}/usr/lib/vpp_plugins
+mkdir -p -m755 %{buildroot}/usr/lib/vpp_api_test_plugins
+for file in $(cd %{_mu_build_dir}/%{_vpp_install_dir}/vpp/lib64/vpp_plugins && find -type f -print)
+do
+ install -p -m 644 %{_mu_build_dir}/%{_vpp_install_dir}/vpp/lib64/vpp_plugins/$file \
+ %{buildroot}/usr/lib/vpp_plugins/$file
+done
+
+for file in $(cd %{_mu_build_dir}/%{_vpp_install_dir}/vpp/lib64/vpp_api_test_plugins && find -type f -print)
+do
+ install -p -m 644 %{_mu_build_dir}/%{_vpp_install_dir}/vpp/lib64/vpp_api_test_plugins/$file \
+ %{buildroot}/usr/lib/vpp_api_test_plugins/$file
+done
+
+for file in $(find %{_mu_build_dir}/%{_vpp_install_dir}/plugins -type f -name '*.api.json' -print )
+do
+ install -p -m 644 $file %{buildroot}/usr/share/vpp/api
+done
+
+#
+# remove RPATH from ELF binaries
+#
+%{_mu_build_dir}/scripts/remove-rpath %{buildroot}
+
+%post
+if [ $1 -eq 1 ] ; then
+ sysctl --system
+fi
+%systemd_post vpp.service
+
+%preun
+%systemd_preun vpp.service
+
+%postun
+%systemd_postun
+if [ $1 -eq 0 ] ; then
+ echo "Uninstalling, unbind user-mode PCI drivers"
+ # Unbind user-mode PCI drivers
+ removed=
+ pci_dirs=`find /sys/bus/pci/drivers -type d -name igb_uio -o -name uio_pci_generic -o -name vfio-pci`
+ for d in $pci_dirs; do
+ for f in ${d}/*; do
+ [ -e "${f}/config" ] || continue
+ echo ${f##*/} > ${d}/unbind
+ basename `dirname ${f}` | xargs echo -n "Removing driver"; echo " for PCI ID" `basename ${f}`
+ removed=y
+ done
+ done
+ if [ -n "${removed}" ]; then
+ echo "There are changes in PCI drivers, rescaning"
+ echo 1 > /sys/bus/pci/rescan
+ else
+ echo "There weren't PCI devices binded"
+ fi
+else
+ echo "Upgrading package, dont' unbind interfaces"
+fi
+
+%files
+%defattr(-,bin,bin)
+%{_unitdir}/vpp.service
+/usr/bin/vpp*
+/usr/bin/svm*
+/usr/bin/elftool
+%config(noreplace) /etc/sysctl.d/80-vpp.conf
+%config(noreplace) /etc/vpp/startup.conf
+/usr/share/vpp/api/*
+
+%files lib
+%defattr(-,bin,bin)
+%exclude %{_libdir}/vpp_plugins
+%exclude %{_libdir}/vpp_api_test_plugins
+%{_libdir}/*
+/usr/share/vpp/api/*
+/etc/bash_completion.d/vppctl_completion
+/usr/share/vpp/vppctl-cmd-list
+
+%files api-lua
+%defattr(644,root,root,644)
+/usr/share/doc/vpp/examples/lua
+
+%files api-java
+%defattr(644,root,root)
+/usr/share/java/*
+
+%files api-python
+%defattr(644,root,root)
+%{python2_sitelib}/vpp_papi*
+
+%files devel
+%defattr(-,bin,bin)
+/usr/bin/vppapigen
+/usr/bin/jvpp_gen.py
+%{_includedir}/*
+%{python2_sitelib}/jvppgen/*
+/usr/share/doc/vpp/examples/sample-plugin
+
+%files plugins
+%defattr(-,bin,bin)
+/usr/lib/vpp_plugins/*
+/usr/lib/vpp_api_test_plugins/*
+/usr/share/vpp/api/*
diff --git a/extras/scripts/coverity-blame b/extras/scripts/coverity-blame
new file mode 100755
index 00000000..8775ea48
--- /dev/null
+++ b/extras/scripts/coverity-blame
@@ -0,0 +1,36 @@
+#!/bin/sh
+
+# Read coverity email on stdin
+# whenever we find a filename & line number reference, go git-blame it
+
+file=
+start=
+end=
+
+while read line; do
+ if echo "$line" | grep -q '^/.*: '; then
+ echo "$line"
+ file=$(echo "$line" | cut -d: -f1)
+ elif echo "$line" | grep -q '^[*]'; then
+ echo "$line"
+ file=
+ start=
+ end=
+ elif echo "$line" | grep -q '^[0-9][0-9]*'; then
+ num=$(echo "$line" | awk '{print $1}')
+ [ -z "$start" ] && start=$num
+ #git blame -L "$num,+1" ".$file" | cat
+ elif [ -z "$line" ]; then
+ if [ "$start" -a "$num" -a "$file" ]; then
+ end=$num
+ git blame --date=short -L "$start,$end" ".$file" | cat
+ start=
+ end=
+ num=
+ else
+ echo "$line"
+ fi
+ else
+ echo "$line"
+ fi
+done
diff --git a/extras/scripts/coverity-build b/extras/scripts/coverity-build
new file mode 100755
index 00000000..81680f06
--- /dev/null
+++ b/extras/scripts/coverity-build
@@ -0,0 +1,70 @@
+#!/bin/bash
+
+# FD.io VPP Coverity build script
+#
+# Builds VPP with the Coverity wrapper and if successful submits
+# it to the Coverity scan service for processing.
+#
+# Several environment variables are needed:
+#
+# COVERITY_TOKEN The Coverity Scan API token for this project
+# COVERITY_TOOLS The location of the Coverity tools
+#
+# The coverity tools can be fetched with:
+# wget https://scan.coverity.com/download/linux64 \
+# --post-data "token=${COVERITY_TOKEN}&project=fd.io+VPP" \
+# -O coverity_tool.tgz
+
+set -ex
+
+token=${COVERITY_TOKEN}
+email=vpp-committers@lists.fd.io
+project="fd.io VPP"
+project_encoded="fd.io+VPP"
+url=https://scan.coverity.com
+
+# Cosmetic labels for the Coverity build logs
+export COV_HOST=$(hostname -f)
+export COV_USER=vpp
+
+# Work out where the root and build-root are
+script_dir=$(readlink -f $(dirname $0))
+root_dir=$(readlink -f "${script_dir}/../..")
+build_dir=$(readlink -f "${script_dir}/../../build-root")
+
+# Location for Coverity things
+covdir="${build_dir}/cov-int"
+COVERITY_TOOLS="${COVERITY_TOOLS-/scratch/cov-analysis-latest}"
+
+# Before we run the build, check that we can submit one
+check=$(curl -s --form project="${project}" \
+ --form token="${token}" "${url}/api/upload_permitted")
+if [ "${check}" = "Access denied" ]; then
+ echo "Bad token or project name."
+ exit 1
+fi
+if [ "${check}" != '{"upload_permitted":true}' ]; then
+ echo "Upload not permitted; stop now..."
+ exit 1
+fi
+
+version=$(git describe)
+
+# Run the build
+cd "${root_dir}"
+"${COVERITY_TOOLS}/bin/cov-build" --dir "${covdir}" make bootstrap build-coverity
+cd "${build_dir}"
+
+# Tar the build artifacts that scan wants
+tar -czf fd.io-vpp.tgz "$(basename ${covdir})"
+rm -rf "${covdir}"
+
+# Submit the build
+echo curl --form token="${token}" \
+ --form email="${email}" \
+ --form file=@fd.io-vpp.tgz \
+ --form version="${version}" \
+ --form description="master:${version}" \
+ "${url}/builds?project=${project_encoded}"
+
+# All done!
diff --git a/extras/scripts/lsnet b/extras/scripts/lsnet
new file mode 100755
index 00000000..ed590e53
--- /dev/null
+++ b/extras/scripts/lsnet
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+echo "PCI Address MAC address Device Name Driver State Speed Port Type"
+echo "============ ================= ============== ========== ======== ========== ===================="
+
+for f in /sys/class/net/*; do
+ dev=$(basename ${f})
+ if [ -e $f/device ] ; then
+ dev=$(basename ${f})
+ pci_addr=$(basename $(readlink $f/device))
+ mac=$(cat $f/address)
+ driver=$(basename $(readlink $f/device/driver))
+ oper=$(cat $f/operstate)
+ speed=$(sudo ethtool $dev | grep Speed | cut -d" " -f2)
+ port=$(ethtool $dev 2> /dev/null | sed -ne 's/.*Port: \(.*\)/\1/p')
+ printf "%-12s %-14s %-14s %-10s %-8s %-10s %-20s\n" $pci_addr $mac $dev $driver $oper $speed "$port"
+ # ethtool $dev | grep Port:
+ fi
+done
+
diff --git a/extras/scripts/pci-nic-bind b/extras/scripts/pci-nic-bind
new file mode 100755
index 00000000..f3a0c264
--- /dev/null
+++ b/extras/scripts/pci-nic-bind
@@ -0,0 +1,94 @@
+#!/bin/bash
+
+uio_drivers="igb_uio uio_pci_generic vfio-pci"
+tmpfile=$(mktemp)
+
+
+function bind_drv() {
+ addr=$1
+ modalias=$(cat $selection/modalias)
+ native_drv=$(modprobe -R $modalias)
+ array=()
+
+ for drv in $native_drv $uio_drivers; do
+ if [ -e /sys/bus/pci/drivers/$drv ]; then
+ echo driver $drv
+ drv_desc=$(modinfo $drv | grep description: | sed -e 's/.*:[[:space:]]\+//' )
+ array+=("${drv}")
+ array+=("${drv_desc}")
+ fi
+ done
+ dialog --backtitle "PCI NIC Bind Utility" \
+ --clear \
+ --menu "Select kernel driver" 18 100 12 \
+ "${array[@]}" 2> $tmpfile
+ retval=$?
+ selection=$(cat $tmpfile)
+ rm $tmpfile
+ if [ $retval -ne 0 ]; then
+ return
+ fi
+ vd=$(cat /sys/bus/pci/devices/${addr}/vendor /sys/bus/pci/devices/${addr}/device)
+ echo $addr | tee /sys/bus/pci/devices/${addr}/driver/unbind > /dev/null 2> /dev/null
+ echo $vd | tee /sys/bus/pci/drivers/${selection}/new_id > /dev/null 2> /dev/null
+ echo $addr | tee /sys/bus/pci/drivers/${selection}/bind > /dev/null 2> /dev/null
+}
+
+function find_pci_slot() {
+ addr=$1
+ [ ! "$(ls -A /sys/bus/pci/slots )" ] && echo "No PCI slot data" && return
+ for slot in $(find /sys/bus/pci/slots/* -maxdepth 0 -exec basename {} \;); do
+ slot_addr=$(cat /sys/bus/pci/slots/$slot/address)
+ if [[ "${addr}" == *"${slot_addr}"* ]]; then
+ echo "PCI slot: ${slot}"
+ return
+ fi
+ done
+ echo "Unknown PCI slot"
+}
+
+! type -ap dialog > /dev/null && echo "Please install dialog (apt-get install dialog)" && exit
+if [ $USER != "root" ] ; then
+echo "Restarting script with sudo..."
+ sudo $0 ${*}
+ exit
+fi
+
+cd /sys/bus/pci/devices
+
+while true; do
+ array=()
+ for addr in *; do
+ class=$(cat ${addr}/class)
+ if [ "$class" = "0x020000" ]; then
+ name=$(lspci -s $addr | sed -e 's/.*: //')
+ if [ -e "/sys/bus/pci/devices/$addr/driver" ]; then
+ drv=$(basename $(readlink -f /sys/bus/pci/devices/$addr/driver))
+ else
+ drv=" "
+ fi
+ slot=$(find_pci_slot ${addr})
+ array+=("${addr}")
+ array+=("${drv}|${name}")
+ array+=("${slot}")
+ fi
+ done
+
+ dialog --backtitle "PCI NIC Bind Utility" \
+ --item-help \
+ --clear \
+ --column-separator '|' \
+ --menu "Select NIC" 18 100 12 \
+ "${array[@]}" 2> $tmpfile
+
+ retval=$?
+ selection=$(cat $tmpfile)
+ rm $tmpfile
+ if [ $retval -ne 0 ]; then
+ exit
+ fi
+ bind_drv $selection
+done
+
+
+
diff --git a/extras/scripts/pci-nic-bind-to-kernel b/extras/scripts/pci-nic-bind-to-kernel
new file mode 100755
index 00000000..3d8559e3
--- /dev/null
+++ b/extras/scripts/pci-nic-bind-to-kernel
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+# Bind all unused PCI devices bound to uio drivers
+# back to default kernel driver
+
+if [ $USER != "root" ] ; then
+ echo "Restarting script with sudo..."
+ sudo $0 ${*}
+ exit
+fi
+
+for f in /sys/bus/pci/drivers/{igb_uio,uio_pci_generic,vfio-pci}/*; do
+ [ -e ${f}/config ] || continue
+ fuser -s ${f}/config && continue
+ echo 1 > ${f}/remove
+ removed=y
+done
+
+[ -n ${removed} ] && echo 1 > /sys/bus/pci/rescan
diff --git a/extras/vagrant/.gitignore b/extras/vagrant/.gitignore
new file mode 100644
index 00000000..a977916f
--- /dev/null
+++ b/extras/vagrant/.gitignore
@@ -0,0 +1 @@
+.vagrant/
diff --git a/extras/vagrant/README b/extras/vagrant/README
new file mode 100644
index 00000000..4b7c7aa1
--- /dev/null
+++ b/extras/vagrant/README
@@ -0,0 +1,43 @@
+INTRO:
+
+This is a vagrant environment for VPP.
+
+VPP currently works under Linux and has support for:
+
+- Ubuntu 16.04 and Centos7.2
+
+The VM builds VPP from source which can be located at /vpp
+
+VM PARTICULARS:
+This vagrant environment creates a VM based on environment variables found in ./env.sh
+To customize the vm for your use case, edit env.sh then
+ source ./env.sh
+ vagrant up
+
+By default, the VM created is/has:
+- Ubuntu 16.04
+- 2 vCPUs
+- 4G of RAM
+- 3 NICs (1 x NAT - host access, 2 x VPP DPDK enabled)
+
+PROVIDERS:
+
+Supported vagrant providers are:
+
+- Virtualbox, VMware Fusion/Workstation, Libvirt
+
+ALTERNATE CONFIGURATIONS
+
+The following Vagrantfiles provide alternate configurations for specific testing purposes. To use them,
+
+1. Copy the desired configuration to Vagrantfile
+2. Run "vagrant up"
+3. vagrant ssh <vm name>
+
+When testing is complete
+4. Run "vagrant destroy" to stop the VM's and delete files.
+5. Run "git checkout -- Vagrantfile" to restore the default configuration
+
+Available Vagrantfiles:
+
+Vagrantfile.vcl_test - Create two vm's for multi-host VppCommLib testing
diff --git a/extras/vagrant/Vagrantfile b/extras/vagrant/Vagrantfile
new file mode 100644
index 00000000..714ba94c
--- /dev/null
+++ b/extras/vagrant/Vagrantfile
@@ -0,0 +1,112 @@
+# -*- mode: ruby -*-
+# vi: set ft=ruby :
+
+Vagrant.configure(2) do |config|
+
+ # Pick the right distro and bootstrap, default is ubuntu1604
+ distro = ( ENV['VPP_VAGRANT_DISTRO'] || "ubuntu1604")
+ if distro == 'centos7'
+ config.vm.box = "centos/7"
+ config.vm.box_version = "1708.01"
+ config.ssh.insert_key = false
+ else
+ config.vm.box = "puppetlabs/ubuntu-16.04-64-nocm"
+ end
+ config.vm.box_check_update = false
+
+ config.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"update.sh")
+ config.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"build.sh"), :args => "/vpp vagrant"
+
+ post_build = ( ENV['VPP_VAGRANT_POST_BUILD'] )
+ if post_build == "test"
+ config.vm.provision "shell", inline: "echo Testing VPP; cd /vpp; make test"
+ elsif post_build == "install"
+ config.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"install.sh"), :args => "/vpp"
+ config.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"clearinterfaces.sh")
+ config.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"run.sh")
+ end
+
+ # Add .gnupg dir in so folks can sign patches
+ # Note, as gnupg puts socket files in that dir, we have
+ # to be cautious and make sure we are dealing with a plain file
+ homedir = File.expand_path("~/")
+ Dir["#{homedir}/.gnupg/**/*"].each do |fname|
+ if File.file?(fname)
+ destname = fname.sub(Regexp.escape("#{homedir}/"),'')
+ config.vm.provision "file", source: fname, destination: destname
+ end
+ end
+
+ # Copy in the .gitconfig if it exists
+ if File.file?(File.expand_path("~/.gitconfig"))
+ config.vm.provision "file", source: "~/.gitconfig", destination: ".gitconfig"
+ end
+
+ # vagrant-cachier caches apt/yum etc to speed subsequent
+ # vagrant up
+ # to enable, run
+ # vagrant plugin install vagrant-cachier
+ #
+ if Vagrant.has_plugin?("vagrant-cachier")
+ config.cache.scope = :box
+ end
+
+ # Define some physical ports for your VMs to be used by DPDK
+ nics = (ENV['VPP_VAGRANT_NICS'] || "2").to_i(10)
+ for i in 1..nics
+ config.vm.network "private_network", type: "dhcp"
+ end
+
+ # use http proxy if avaiable
+ if ENV['http_proxy'] && Vagrant.has_plugin?("vagrant-proxyconf")
+ config.proxy.http = ENV['http_proxy']
+ config.proxy.https = ENV['https_proxy']
+ config.proxy.no_proxy = "localhost,127.0.0.1"
+ end
+
+ vmcpu=(ENV['VPP_VAGRANT_VMCPU'] || 2)
+ vmram=(ENV['VPP_VAGRANT_VMRAM'] || 4096)
+
+ config.ssh.forward_agent = true
+ config.ssh.forward_x11 = true
+
+ config.vm.provider "virtualbox" do |vb|
+ vb.customize ["modifyvm", :id, "--ioapic", "on"]
+ vb.memory = "#{vmram}"
+ vb.cpus = "#{vmcpu}"
+
+ # rsync the vpp directory if provision hasn't happened yet
+ unless File.exist? (".vagrant/machines/default/virtualbox/action_provision")
+ config.vm.synced_folder "../../", "/vpp", type: "rsync",
+ rsync__auto: false,
+ rsync__exclude: [
+ "build-root/build*/",
+ "build-root/install*/",
+ "build-root/images*/",
+ "build-root/*.deb",
+ "build-root/*.rpm",
+ "build-root/*.changes",
+ "build-root/python",
+ "build-root/deb/debian/*.dkms",
+ "build-root/deb/debian/*.install",
+ "build-root/deb/debian/changes",
+ "build-root/tools"]
+ end
+
+ #support for the SSE4.x instruction is required in some versions of VB.
+ vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.1", "1"]
+ vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.2", "1"]
+ end
+ config.vm.provider "vmware_fusion" do |fusion,override|
+ fusion.vmx["memsize"] = "#{vmram}"
+ fusion.vmx["numvcpus"] = "#{vmcpu}"
+ end
+ config.vm.provider "libvirt" do |lv|
+ lv.memory = "#{vmram}"
+ lv.cpus = "#{vmcpu}"
+ end
+ config.vm.provider "vmware_workstation" do |vws,override|
+ vws.vmx["memsize"] = "#{vmram}"
+ vws.vmx["numvcpus"] = "#{vmcpu}"
+ end
+end
diff --git a/extras/vagrant/Vagrantfile.vcl_test b/extras/vagrant/Vagrantfile.vcl_test
new file mode 100644
index 00000000..d0559424
--- /dev/null
+++ b/extras/vagrant/Vagrantfile.vcl_test
@@ -0,0 +1,111 @@
+# -*- mode: ruby -*-
+# vi: set ft=ruby :
+
+Vagrant.configure(2) do |config|
+
+ # Pick the right distro and bootstrap, default is ubuntu1604
+ distro = ( ENV['VPP_VAGRANT_DISTRO'] || "ubuntu1604")
+ if distro == 'centos7'
+ config.vm.box = "centos/7"
+ config.vm.box_version = "1708.01"
+ config.ssh.insert_key = false
+ else
+ config.vm.box = "puppetlabs/ubuntu-16.04-64-nocm"
+ end
+ config.vm.box_check_update = false
+
+ config.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"update.sh")
+ config.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"build.sh"), :args => "/vpp vagrant"
+
+ # Create VCL client and server VM's
+ config.vm.define "vcl-server" do |server|
+ server.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"vcl_test.sh"), :args => "/vpp vagrant vcl-server"
+ end
+ config.vm.define "vcl-client" do |client|
+ client.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"vcl_test.sh"), :args => "/vpp vagrant vcl-client"
+ end
+
+ # Add .gnupg dir in so folks can sign patches
+ # Note, as gnupg puts socket files in that dir, we have
+ # to be cautious and make sure we are dealing with a plain file
+ homedir = File.expand_path("~/")
+ Dir["#{homedir}/.gnupg/**/*"].each do |fname|
+ if File.file?(fname)
+ destname = fname.sub(Regexp.escape("#{homedir}/"),'')
+ config.vm.provision "file", source: fname, destination: destname
+ end
+ end
+
+ # Copy in the .gitconfig if it exists
+ if File.file?(File.expand_path("~/.gitconfig"))
+ config.vm.provision "file", source: "~/.gitconfig", destination: ".gitconfig"
+ end
+
+ # vagrant-cachier caches apt/yum etc to speed subsequent
+ # vagrant up
+ # to enable, run
+ # vagrant plugin install vagrant-cachier
+ #
+ if Vagrant.has_plugin?("vagrant-cachier")
+ config.cache.scope = :box
+ end
+
+ # Define some physical ports for your VMs to be used by DPDK
+ nics = (ENV['VPP_VAGRANT_NICS'] || "2").to_i(10)
+ for i in 1..nics
+ config.vm.network "private_network", type: "dhcp"
+ end
+
+ # use http proxy if avaiable
+ if ENV['http_proxy'] && Vagrant.has_plugin?("vagrant-proxyconf")
+ config.proxy.http = ENV['http_proxy']
+ config.proxy.https = ENV['https_proxy']
+ config.proxy.no_proxy = "localhost,127.0.0.1"
+ end
+
+ vmcpu=(ENV['VPP_VAGRANT_VMCPU'] || 2)
+ vmram=(ENV['VPP_VAGRANT_VMRAM'] || 4096)
+
+ config.ssh.forward_agent = true
+ config.ssh.forward_x11 = true
+
+ config.vm.provider "virtualbox" do |vb|
+ vb.customize ["modifyvm", :id, "--ioapic", "on"]
+ vb.memory = "#{vmram}"
+ vb.cpus = "#{vmcpu}"
+
+ # rsync the vpp directory if provision hasn't happened yet
+ unless File.exist? (".vagrant/machines/client/virtualbox/action_provision")
+ config.vm.synced_folder "../../", "/vpp", type: "rsync",
+ rsync__auto: false,
+ rsync__exclude: [
+ "build-root/build*/",
+ "build-root/install*/",
+ "build-root/images*/",
+ "build-root/*.deb",
+ "build-root/*.rpm",
+ "build-root/*.changes",
+ "build-root/python",
+ "build-root/deb/debian/*.dkms",
+ "build-root/deb/debian/*.install",
+ "build-root/deb/debian/changes",
+ "build-root/tools"]
+ end
+
+ #support for the SSE4.x instruction is required in some versions of VB.
+ vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.1", "1"]
+ vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.2", "1"]
+ end
+ config.vm.provider "vmware_fusion" do |fusion,override|
+ fusion.vmx["memsize"] = "#{vmram}"
+ fusion.vmx["numvcpus"] = "#{vmcpu}"
+ end
+ config.vm.provider "libvirt" do |lv|
+ lv.memory = "#{vmram}"
+ lv.cpus = "#{vmcpu}"
+ end
+ config.vm.provider "vmware_workstation" do |vws,override|
+ vws.vmx["memsize"] = "#{vmram}"
+ vws.vmx["numvcpus"] = "#{vmcpu}"
+ end
+end
diff --git a/extras/vagrant/WELCOME b/extras/vagrant/WELCOME
new file mode 100644
index 00000000..eb6aa2fd
--- /dev/null
+++ b/extras/vagrant/WELCOME
@@ -0,0 +1,61 @@
+VPP has now been built, installed, and started.
+
+To give it a spin, we can create a tap interface and try a simple ping
+(with trace).
+
+Make sure you have run:
+
+$ vagrant ssh
+
+To get to the vagrant VM:
+
+vagrant@localhost:~$
+
+Confirm that vpp is running with
+
+vagrant@localhost:~$ sudo status vpp
+vpp start/running, process 25202
+
+To create the tap:
+
+vagrant@localhost:~$ sudo vppctl tap connect foobar
+Created tap-0 for Linux tap 'foobar'
+vagrant@localhost:~$ sudo vppctl show int
+
+To assign it an ip address (and 'up' the interface):
+
+vagrant@localhost:~$ sudo vppctl set int ip address tap-0 192.168.1.1/24
+vagrant@localhost:~$ sudo vppctl set int state tap-0 up
+
+To turn on packet tracing for the tap interface:
+vagrant@localhost:~$ sudo vppctl trace add tapcli-rx 10
+
+Now, to set up and try the other end:
+vagrant@localhost:~$ sudo ip addr add 192.168.1.2/24 dev foobar
+vagrant@localhost:~$ ping -c 3 192.168.1.1
+
+To look at the trace:
+vagrant@localhost:~$ sudo vppctl show trace
+
+And to stop tracing:
+
+vagrant@localhost:~$ sudo vppctl clear trace
+
+Other fun things to look at:
+
+The vlib packet processing graph:
+vagrant@localhost:~$ sudo vppctl show vlib graph
+
+which will produce output like:
+
+ Name Next Previous
+ip4-icmp-input error-punt [0] ip4-local
+ ip4-icmp-echo-request [1]
+ vpe-icmp4-oam [2]
+
+To read this, the first column (Name) is the name of the node.
+The second column (Next) is the name of the children of that node.
+The third column (Previous) is the name of the parents of this node.
+
+To see this README again:
+cat /vagrant/README
diff --git a/extras/vagrant/build.sh b/extras/vagrant/build.sh
new file mode 100755
index 00000000..fcfd52aa
--- /dev/null
+++ b/extras/vagrant/build.sh
@@ -0,0 +1,85 @@
+#!/bin/bash
+
+# Get Command Line arguements if present
+VPP_DIR=$1
+if [ "x$1" != "x" ]; then
+ VPP_DIR=$1
+else
+ VPP_DIR=`dirname $0`/../../
+fi
+
+if [ "x$2" != "x" ]; then
+ SUDOCMD="sudo -H -u $2"
+fi
+echo 0:$0
+echo 1:$1
+echo 2:$2
+echo VPP_DIR: $VPP_DIR
+echo SUDOCMD: $SUDOCMD
+
+# Figure out what system we are running on
+if [ -f /etc/lsb-release ];then
+ . /etc/lsb-release
+elif [ -f /etc/redhat-release ];then
+ sudo yum install -y redhat-lsb
+ DISTRIB_ID=`lsb_release -si`
+ DISTRIB_RELEASE=`lsb_release -sr`
+ DISTRIB_CODENAME=`lsb_release -sc`
+ DISTRIB_DESCRIPTION=`lsb_release -sd`
+elif [ -f /etc/os-release ];then
+ . /etc/os-release
+ DISTRIB_ID=$ID
+ DISTRIB_RELEASE=$VERSION_ID
+ DISTRIB_CODENAME=$VERSION
+ DISTRIB_DESCRIPTION=$PRETTY_NAME
+fi
+KERNEL_OS=`uname -o`
+KERNEL_MACHINE=`uname -m`
+KERNEL_RELEASE=`uname -r`
+KERNEL_VERSION=`uname -v`
+
+echo KERNEL_OS: $KERNEL_OS
+echo KERNEL_MACHINE: $KERNEL_MACHINE
+echo KERNEL_RELEASE: $KERNEL_RELEASE
+echo KERNEL_VERSION: $KERNEL_VERSION
+echo DISTRIB_ID: $DISTRIB_ID
+echo DISTRIB_RELEASE: $DISTRIB_RELEASE
+echo DISTRIB_CODENAME: $DISTRIB_CODENAME
+echo DISTRIB_DESCRIPTION: $DISTRIB_DESCRIPTION
+
+# Install dependencies
+cd $VPP_DIR
+make UNATTENDED=yes install-dep
+
+# Really really clean things up so we can be sure
+# that the build works even when switching distros
+$SUDOCMD make wipe
+(cd build-root/;$SUDOCMD make distclean)
+rm -f build-root/.bootstrap.ok
+
+if [ $DISTRIB_ID == "CentOS" ]; then
+ echo rpm -V apr-devel
+ rpm -V apr-devel
+ if [ $? != 0 ]; then sudo yum reinstall -y apr-devel;fi
+ echo rpm -V ganglia-devel
+ rpm -V ganglia-devel
+ if [ $? != 0 ]; then sudo yum reinstall -y ganglia-devel;fi
+ echo rpm -V libconfuse-devel
+ rpm -V libconfuse-devel
+ if [ $? != 0 ]; then sudo yum reinstall -y libconfuse-devel;fi
+fi
+
+# Build and install packaging
+$SUDOCMD make bootstrap
+
+if [ "$DISTRIB_ID" == "Ubuntu" ]; then
+ $SUDOCMD make pkg-deb
+elif [ "$DISTRIB_ID" == "debian" ]; then
+ $SUDOCMD make pkg-deb
+elif [ "$DISTRIB_ID" == "CentOS" ]; then
+ (cd $VPP_DIR/vnet ;$SUDOCMD aclocal;$SUDOCMD automake -a)
+ $SUDOCMD make pkg-rpm
+elif [ "$DISTRIB_ID" == "opensuse" ]; then
+ $SUDOCMD make build-release
+fi
+
diff --git a/extras/vagrant/clearinterfaces.sh b/extras/vagrant/clearinterfaces.sh
new file mode 100755
index 00000000..78f6705c
--- /dev/null
+++ b/extras/vagrant/clearinterfaces.sh
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+# Capture all the interface IPs, in case we need them later
+ip -o addr show > ~vagrant/ifconfiga
+chown vagrant:vagrant ~vagrant/ifconfiga
+
+# Disable all ethernet interfaces other than the default route
+# interface so VPP will use those interfaces. The VPP auto-blacklist
+# algorithm prevents the use of any physical interface contained in the
+# routing table (i.e. "route --inet --inet6") preventing the theft of
+# the management ethernet interface by VPP from the kernel.
+for intf in $(ls /sys/class/net) ; do
+ if [ -d /sys/class/net/$intf/device ] &&
+ [ "$(route --inet --inet6 | grep default | grep $intf)" == "" ] ; then
+ ifconfig $intf down
+ fi
+done
diff --git a/extras/vagrant/env.sh b/extras/vagrant/env.sh
new file mode 100644
index 00000000..bd329ea7
--- /dev/null
+++ b/extras/vagrant/env.sh
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+
+export VPP_VAGRANT_DISTRO="ubuntu1604"
+export VPP_VAGRANT_NICS=2
+export VPP_VAGRANT_VMCPU=4
+export VPP_VAGRANT_VMRAM=4096
diff --git a/extras/vagrant/install.sh b/extras/vagrant/install.sh
new file mode 100644
index 00000000..a53faa4d
--- /dev/null
+++ b/extras/vagrant/install.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+# Get Command Line arguements if present
+VPP_DIR=$1
+if [ "x$1" != "x" ]; then
+ VPP_DIR=$1
+else
+ VPP_DIR=`dirname $0`/../../
+fi
+
+# Figure out what system we are running on
+if [ -f /etc/lsb-release ];then
+ . /etc/lsb-release
+elif [ -f /etc/redhat-release ];then
+ sudo yum install -y redhat-lsb
+ DISTRIB_ID=`lsb_release -si`
+ DISTRIB_RELEASE=`lsb_release -sr`
+ DISTRIB_CODENAME=`lsb_release -sc`
+ DISTRIB_DESCRIPTION=`lsb_release -sd`
+fi
+echo DISTRIB_ID: $DISTRIB_ID
+echo DISTRIB_RELEASE: $DISTRIB_RELEASE
+echo DISTRIB_CODENAME: $DISTRIB_CODENAME
+echo DISTRIB_DESCRIPTION: $DISTRIB_DESCRIPTION
+
+if [ $DISTRIB_ID == "Ubuntu" ]; then
+ (cd ${VPP_DIR}/build-root/;sudo dpkg -i *.deb)
+elif [ $DISTRIB_ID == "CentOS" ]; then
+ (cd ${VPP_DIR}/build-root/;sudo rpm -Uvh *.rpm)
+fi \ No newline at end of file
diff --git a/extras/vagrant/run.sh b/extras/vagrant/run.sh
new file mode 100755
index 00000000..1cd33826
--- /dev/null
+++ b/extras/vagrant/run.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+# Figure out what system we are running on
+if [ -f /etc/lsb-release ];then
+ . /etc/lsb-release
+elif [ -f /etc/redhat-release ];then
+ yum install -y redhat-lsb
+ DISTRIB_ID=`lsb_release -si`
+ DISTRIB_RELEASE=`lsb_release -sr`
+ DISTRIB_CODENAME=`lsb_release -sc`
+ DISTRIB_DESCRIPTION=`lsb_release -sd`
+fi
+
+if [ $DISTRIB_ID == "CentOS" ]; then
+ # Install uio-pci-generic
+ modprobe uio_pci_generic
+fi
+echo "Starting VPP..."
+if [ $DISTRIB_ID == "Ubuntu" ] && [ $DISTRIB_CODENAME = "trusty" ] ; then
+ start vpp
+else
+ service vpp start
+fi
diff --git a/extras/vagrant/update.sh b/extras/vagrant/update.sh
new file mode 100755
index 00000000..b4962bfc
--- /dev/null
+++ b/extras/vagrant/update.sh
@@ -0,0 +1,53 @@
+#!/bin/bash
+
+# Make sure that we get the hugepages we need on provision boot
+# Note: The package install should take care of this at the end
+# But sometimes after all the work of provisioning, we can't
+# get the requested number of hugepages without rebooting.
+# So do it here just in case
+sysctl -w vm.nr_hugepages=1024
+HUGEPAGES=`sysctl -n vm.nr_hugepages`
+if [ $HUGEPAGES != 1024 ]; then
+ echo "ERROR: Unable to get 1024 hugepages, only got $HUGEPAGES. Cannot finish."
+ exit
+fi
+
+# Figure out what system we are running on
+if [ -f /etc/lsb-release ];then
+ . /etc/lsb-release
+elif [ -f /etc/redhat-release ];then
+ yum install -y redhat-lsb
+ DISTRIB_ID=`lsb_release -si`
+ DISTRIB_RELEASE=`lsb_release -sr`
+ DISTRIB_CODENAME=`lsb_release -sc`
+ DISTRIB_DESCRIPTION=`lsb_release -sd`
+fi
+
+# Do initial setup for the system
+if [ $DISTRIB_ID == "Ubuntu" ]; then
+
+ export DEBIAN_PRIORITY=critical
+ export DEBIAN_FRONTEND=noninteractive
+ export DEBCONF_NONINTERACTIVE_SEEN=true
+ APT_OPTS="--assume-yes --no-install-suggests --no-install-recommends -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\""
+
+ # Standard update + upgrade dance
+ apt-get update ${APT_OPTS} >/dev/null
+ apt-get upgrade ${APT_OPTS} >/dev/null
+
+ # Fix the silly notion that /bin/sh should point to dash by pointing it to bash
+
+ update-alternatives --install /bin/sh sh /bin/bash 100
+
+ # Install useful but non-mandatory tools
+ apt-get install -y emacs x11-utils git-review gdb gdbserver xfce4-terminal iperf3
+elif [ $DISTRIB_ID == "CentOS" ]; then
+ if [ "$(echo $DISTRIB_RELEASE | cut -d'.' -f1)" == "7" ]; then
+ rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
+ yum groupinstall "X Window system" -y
+ yum groupinstall xfce -y
+ fi
+ # Standard update + upgrade dance
+ yum check-update
+ yum update -y
+fi
diff --git a/extras/vagrant/vcl_test.sh b/extras/vagrant/vcl_test.sh
new file mode 100755
index 00000000..3be18517
--- /dev/null
+++ b/extras/vagrant/vcl_test.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+if [ -n "$1" ]; then
+ VPP_DIR=$1
+else
+ VPP_DIR=`dirname $0`/../../
+fi
+
+if [ -n "$2" ]; then
+ SUDOCMD="sudo -H -u $2"
+fi
+
+echo 'Building VCL test apps'
+cd $VPP_DIR
+$SUDOCMD perl -pi -e 's/noinst_PROGRAMS/bin_PROGRAMS/g' $VPP_DIR/src/uri.am
+$SUDOCMD make dpdk-install-dev build-release
+sudo sysctl -p$VPP_DIR/src/vpp/conf/80-vpp.conf
+sudo modprobe uio_pci_generic
+
+if [ "$2" = "vagrant" ] && [ -d "/home/vagrant" ] ; then
+ dot_bash_aliases="/home/$2/.bash_aliases"
+ echo "export WS_ROOT=$VPP_DIR" | $SUDOCMD tee $dot_bash_aliases
+ source $dot_bash_aliases
+fi
+