aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2016-11-08 16:47:34 -0500
committerDamjan Marion <dmarion.lists@gmail.com>2016-11-09 11:36:02 +0000
commitb7e2f3d312927f2a8f1b2c8030b2e8ffe3288bab (patch)
tree643cc5551d5e265aab996fa615a9f415de459279
parent3a4ed3934585eb841fa36f6f062adf4dce9b4661 (diff)
Update sample plugin and plugin skeletons: use driver feature arc
Change-Id: Ic0a1479e4a0408a4b93f47e50752d07c2bdccdde Signed-off-by: Dave Barach <dave@barachs.net>
-rw-r--r--build-root/emacs-lisp/plugin-main-skel.el22
-rw-r--r--build-root/emacs-lisp/plugin-makefile-skel.el1
-rw-r--r--build-root/emacs-lisp/plugin-node-skel.el27
-rw-r--r--plugins/sample-plugin/sample/node.c29
-rw-r--r--plugins/sample-plugin/sample/sample.c22
5 files changed, 75 insertions, 26 deletions
diff --git a/build-root/emacs-lisp/plugin-main-skel.el b/build-root/emacs-lisp/plugin-main-skel.el
index 0c9cd512..196f8653 100644
--- a/build-root/emacs-lisp/plugin-main-skel.el
+++ b/build-root/emacs-lisp/plugin-main-skel.el
@@ -127,8 +127,7 @@ int " plugin-name "_enable_disable (" plugin-name "_main_t * sm, u32 sw_if_index
int enable_disable)
{
vnet_sw_interface_t * sw;
- int rv;
- u32 node_index = enable_disable ? " plugin-name "_node.index : ~0;
+ int rv = 0;
/* Utterly wrong? */
if (pool_is_free_index (sm->vnet_main->interface_main.sw_interfaces,
@@ -140,15 +139,9 @@ int " plugin-name "_enable_disable (" plugin-name "_main_t * sm, u32 sw_if_index
if (sw->type != VNET_SW_INTERFACE_TYPE_HARDWARE)
return VNET_API_ERROR_INVALID_SW_IF_INDEX;
- /*
- * Redirect pkts from the driver to the macswap node.
- * Returns VNET_API_ERROR_UNIMPLEMENTED if the h/w driver
- * doesn't implement the API.
- *
- * Node_index = ~0 => shut off redirection
- */
- rv = vnet_hw_interface_rx_redirect_to_node (sm->vnet_main, sw_if_index,
- node_index);
+ vnet_feature_enable_disable (\"device-input\", \"" plugin-name "\",
+ sw_if_index, enable_disable, 0, 0);
+
return rv;
}
@@ -258,5 +251,12 @@ static clib_error_t * " plugin-name "_init (vlib_main_t * vm)
}
VLIB_INIT_FUNCTION (" plugin-name "_init);
+
+VNET_FEATURE_INIT (" plugin-name ", static) =
+{
+ .arc_name = \"device-input\",
+ .node_name = \"" plugin-name "\",
+ .runs_before = VNET_FEATURES (\"ethernet-input\"),
+};
")
diff --git a/build-root/emacs-lisp/plugin-makefile-skel.el b/build-root/emacs-lisp/plugin-makefile-skel.el
index dc17ddb9..7cb6cbfd 100644
--- a/build-root/emacs-lisp/plugin-makefile-skel.el
+++ b/build-root/emacs-lisp/plugin-makefile-skel.el
@@ -72,5 +72,4 @@ noinst_HEADERS = \\
install-data-hook:
@(cd $(vpppluginsdir) && $(RM) $(vppplugins_LTLIBRARIES))
@(cd $(vppapitestpluginsdir) && $(RM) $(vppapitestplugins_LTLIBRARIES))
-endif
")
diff --git a/build-root/emacs-lisp/plugin-node-skel.el b/build-root/emacs-lisp/plugin-node-skel.el
index 0d88a2ef..ee745c35 100644
--- a/build-root/emacs-lisp/plugin-node-skel.el
+++ b/build-root/emacs-lisp/plugin-node-skel.el
@@ -47,8 +47,18 @@ nil
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)
{
@@ -56,8 +66,11 @@ static u8 * format_" plugin-name "_trace (u8 * s, va_list * args)
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\",
+ 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;
}
@@ -193,6 +206,10 @@ static uword
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)
{
@@ -200,6 +217,10 @@ static uword
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));
}
}
@@ -257,6 +278,10 @@ static uword
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;
diff --git a/plugins/sample-plugin/sample/node.c b/plugins/sample-plugin/sample/node.c
index 9f8ddc16..94c1706b 100644
--- a/plugins/sample-plugin/sample/node.c
+++ b/plugins/sample-plugin/sample/node.c
@@ -21,8 +21,18 @@
typedef struct {
u32 next_index;
u32 sw_if_index;
+ u8 new_src_mac[6];
+ u8 new_dst_mac[6];
} sample_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_sample_trace (u8 * s, va_list * args)
{
@@ -30,8 +40,12 @@ static u8 * format_sample_trace (u8 * s, va_list * args)
CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
sample_trace_t * t = va_arg (*args, sample_trace_t *);
- s = format (s, "SAMPLE: sw_if_index %d, next index %d",
+ s = format (s, "SAMPLE: 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;
}
@@ -167,6 +181,11 @@ sample_node_fn (vlib_main_t * vm,
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)
{
@@ -174,6 +193,10 @@ sample_node_fn (vlib_main_t * vm,
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));
}
}
@@ -231,6 +254,10 @@ sample_node_fn (vlib_main_t * vm,
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;
diff --git a/plugins/sample-plugin/sample/sample.c b/plugins/sample-plugin/sample/sample.c
index 155c845a..321b66c0 100644
--- a/plugins/sample-plugin/sample/sample.c
+++ b/plugins/sample-plugin/sample/sample.c
@@ -106,8 +106,7 @@ int sample_macswap_enable_disable (sample_main_t * sm, u32 sw_if_index,
int enable_disable)
{
vnet_sw_interface_t * sw;
- int rv;
- u32 node_index = enable_disable ? sample_node.index : ~0;
+ int rv = 0;
/* Utterly wrong? */
if (pool_is_free_index (sm->vnet_main->interface_main.sw_interfaces,
@@ -119,15 +118,9 @@ int sample_macswap_enable_disable (sample_main_t * sm, u32 sw_if_index,
if (sw->type != VNET_SW_INTERFACE_TYPE_HARDWARE)
return VNET_API_ERROR_INVALID_SW_IF_INDEX;
- /*
- * Redirect pkts from the driver to the macswap node.
- * Returns VNET_API_ERROR_UNIMPLEMENTED if the h/w driver
- * doesn't implement the API.
- *
- * Node_index = ~0 => shut off redirection
- */
- rv = vnet_hw_interface_rx_redirect_to_node (sm->vnet_main, sw_if_index,
- node_index);
+ vnet_feature_enable_disable ("device-input", "sample",
+ sw_if_index, enable_disable, 0, 0);
+
return rv;
}
@@ -238,4 +231,9 @@ static clib_error_t * sample_init (vlib_main_t * vm)
VLIB_INIT_FUNCTION (sample_init);
-
+VNET_FEATURE_INIT (sample, static) =
+{
+ .arc_name = "device-input",
+ .node_name = "sample",
+ .runs_before = VNET_FEATURES ("ethernet-input"),
+};