Update plugin templates
[vpp.git] / build-root / emacs-lisp / plugin-node-skel.el
index 03ebedd..167519a 100644 (file)
 
 (require 'skeleton)
 
-(define-skeleton plugin-node-skel
+(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>
@@ -44,11 +44,22 @@ nil
 #include <vppinfra/error.h>
 #include <" plugin-name "/" plugin-name ".h>
 
-typedef struct {
+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 +67,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;
 }
 
@@ -79,7 +93,8 @@ static char * " plugin-name "_error_strings[] = {
 #undef _
 };
 
-typedef enum {
+typedef enum 
+{
   " PLUGIN-NAME "_NEXT_INTERFACE_OUTPUT,
   " PLUGIN-NAME "_N_NEXT,
 } " plugin-name "_next_t;
@@ -174,8 +189,6 @@ static uword
           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];
 
@@ -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;
@@ -275,7 +300,9 @@ static uword
   return frame->n_vectors;
 }
 
-VLIB_REGISTER_NODE (" plugin-name "_node) = {
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (" plugin-name "_node) = 
+{
   .function = " plugin-name "_node_fn,
   .name = \"" plugin-name "\",
   .vector_size = sizeof (u32),
@@ -292,4 +319,12 @@ VLIB_REGISTER_NODE (" plugin-name "_node) = {
         [" 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:
+ */
 ")