hs-test: cache docker build in local filesystem
[vpp.git] / src / vnet / devices / pipe / pipe.c
index 29f54e1..9caee2a 100644 (file)
@@ -21,7 +21,7 @@
  * @file
  * @brief Pipe Interfaces.
  *
- * A pipe interface, like the UNIX pipe, is a pair of interfaces
+ * A pipe interface, like the UNIX pipe, is a pair of vpp interfaces
  * that are joined.
  */
 const static pipe_t PIPE_INVALID = {
@@ -30,7 +30,7 @@ const static pipe_t PIPE_INVALID = {
 };
 
 /**
- * Various 'module' lavel variables
+ * Various 'module' level variables
  */
 typedef struct pipe_main_t_
 {
@@ -40,7 +40,7 @@ typedef struct pipe_main_t_
   uword *instances;
 
   /**
-   * the per-swif-index array of pipes. Each end of the pipe is stored againt
+   * the per-swif-index array of pipes. Each end of the pipe is stored against
    * its respective sw_if_index
    */
   pipe_t *pipes;
@@ -51,7 +51,7 @@ static pipe_main_t pipe_main;
 /*
  * The pipe rewrite is the same size as an ethernet header (since it
  * is an ethernet interface and the DP is optimised for writing
- * sizeof(ethernet_header_t) rewirtes. Hwoever, there are no MAC addresses
+ * sizeof(ethernet_header_t) rewrites. However, there are no MAC addresses
  * since pipes don't have them.
  */
 static u8 *
@@ -83,13 +83,11 @@ pipe_build_rewrite (vnet_main_t * vnm,
   return (rewrite);
 }
 
-/* *INDENT-OFF* */
 VNET_HW_INTERFACE_CLASS (pipe_hw_interface_class) = {
   .name = "Pipe",
   .build_rewrite = pipe_build_rewrite,
   .flags = VNET_HW_INTERFACE_CLASS_FLAG_P2P,
 };
-/* *INDENT-ON* */
 
 pipe_t *
 pipe_get (u32 sw_if_index)
@@ -132,15 +130,11 @@ pipe_tx (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
   u32 n_left_from, n_left_to_next, n_copy, *from, *to_next;
   u32 next_index = VNET_PIPE_TX_NEXT_ETHERNET_INPUT;
   u32 i, sw_if_index = 0;
-  u32 n_pkts = 0, n_bytes = 0;
-  u32 thread_index = vm->thread_index;
-  vnet_main_t *vnm = vnet_get_main ();
-  vnet_interface_main_t *im = &vnm->interface_main;
   vlib_buffer_t *b;
   pipe_t *pipe;
 
   n_left_from = frame->n_vectors;
-  from = vlib_frame_args (frame);
+  from = vlib_frame_vector_args (frame);
 
   while (n_left_from > 0)
     {
@@ -148,7 +142,7 @@ pipe_tx (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
 
       n_copy = clib_min (n_left_from, n_left_to_next);
 
-      clib_memcpy (to_next, from, n_copy * sizeof (from[0]));
+      clib_memcpy_fast (to_next, from, n_copy * sizeof (from[0]));
       n_left_to_next -= n_copy;
       n_left_from -= n_copy;
       i = 0;
@@ -163,21 +157,13 @@ pipe_tx (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
          vnet_buffer (b)->sw_if_index[VLIB_TX] = ~0;
 
          i++;
-         n_pkts++;
-         n_bytes += vlib_buffer_length_in_chain (vm, b);
        }
       from += n_copy;
 
       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
-
-      /* increment TX interface stat */
-      vlib_increment_combined_counter (im->combined_sw_if_counters +
-                                      VNET_INTERFACE_COUNTER_TX,
-                                      thread_index, sw_if_index, n_pkts,
-                                      n_bytes);
     }
 
-  return n_left_from;
+  return frame->n_vectors;
 }
 
 static u8 *
@@ -197,25 +183,21 @@ pipe_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
                  VNET_HW_INTERFACE_FLAG_LINK_UP : 0);
   vnet_hw_interface_set_flags (vnm, hw_if_index, hw_flags);
 
-  /* *INDENT-OFF* */
   hi = vnet_get_hw_interface (vnm, hw_if_index);
   hash_foreach (id, sw_if_index, hi->sub_interface_sw_if_index_by_id,
   ({
     vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
   }));
-  /* *INDENT-ON* */
 
   return (NULL);
 }
 
-/* *INDENT-OFF* */
 VNET_DEVICE_CLASS (pipe_device_class) = {
   .name = "Pipe",
   .format_device_name = format_pipe_name,
   .tx_function = pipe_tx,
   .admin_up_down_function = pipe_admin_up_down,
 };
-/* *INDENT-ON* */
 
 #define foreach_pipe_rx_next                    \
   _ (DROP, "error-drop")
@@ -334,8 +316,8 @@ pipe_rx (vlib_main_t * vm,
            p3 = vlib_get_buffer (vm, from[3]);
            vlib_prefetch_buffer_header (p2, STORE);
            vlib_prefetch_buffer_header (p3, STORE);
-           CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, LOAD);
-           CLIB_PREFETCH (p3->data, CLIB_CACHE_LINE_BYTES, LOAD);
+           clib_prefetch_load (p2->data);
+           clib_prefetch_load (p3->data);
          }
 
          bi0 = from[0];
@@ -359,38 +341,40 @@ pipe_rx (vlib_main_t * vm,
          pipe0 = &pipe_main.pipes[sw_if_index0];
          pipe1 = &pipe_main.pipes[sw_if_index1];
 
+         vnet_buffer (b0)->l2_hdr_offset = b0->current_data;
+         vnet_buffer (b1)->l2_hdr_offset = b1->current_data;
+
          vnet_buffer (b0)->l3_hdr_offset =
-           vnet_buffer (b0)->l2_hdr_offset + vnet_buffer (b0)->l2.l2_len;
+           vnet_buffer (b0)->l2_hdr_offset + sizeof (ethernet_header_t);
          vnet_buffer (b1)->l3_hdr_offset =
-           vnet_buffer (b1)->l2_hdr_offset + vnet_buffer (b1)->l2.l2_len;
-         b0->flags |= VNET_BUFFER_F_L3_HDR_OFFSET_VALID;
-         b1->flags |= VNET_BUFFER_F_L3_HDR_OFFSET_VALID;
+           vnet_buffer (b1)->l2_hdr_offset + sizeof (ethernet_header_t);
+         b0->flags |=
+           VNET_BUFFER_F_L2_HDR_OFFSET_VALID |
+           VNET_BUFFER_F_L3_HDR_OFFSET_VALID;
+         b1->flags |=
+           VNET_BUFFER_F_L2_HDR_OFFSET_VALID |
+           VNET_BUFFER_F_L3_HDR_OFFSET_VALID;
 
          is_l20 = pipe0->subint.flags & SUBINT_CONFIG_L2;
          is_l21 = pipe1->subint.flags & SUBINT_CONFIG_L2;
+
+         /*
+          * from discussion with Neale - we do not support the tagged traffic.
+          * So assume a simple ethernet header
+          */
+         vnet_buffer (b0)->l2.l2_len = sizeof (ethernet_header_t);
+         vnet_buffer (b1)->l2.l2_len = sizeof (ethernet_header_t);
+         vlib_buffer_advance (b0, is_l20 ? 0 : sizeof (ethernet_header_t));
+         vlib_buffer_advance (b1, is_l21 ? 0 : sizeof (ethernet_header_t));
+
          pipe_determine_next_node (&ethernet_main, is_l20, type0, b0,
                                    &next0);
          pipe_determine_next_node (&ethernet_main, is_l21, type1, b1,
                                    &next1);
 
-         if (!is_l20)
-           vlib_buffer_advance (b0, sizeof (ethernet_header_t));
-         else
-           {
-             u32 eth_start = vnet_buffer (b0)->l2_hdr_offset;
-             vnet_buffer (b0)->l2.l2_len = b0->current_data - eth_start;
-           }
-         if (!is_l21)
-           vlib_buffer_advance (b1, sizeof (ethernet_header_t));
-         else
-           {
-             u32 eth_start = vnet_buffer (b1)->l2_hdr_offset;
-             vnet_buffer (b1)->l2.l2_len = b1->current_data - eth_start;
-           }
-
          vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
                                           to_next, n_left_to_next,
-                                          bi0, bi1, next0, next0);
+                                          bi0, bi1, next0, next1);
        }
       while (n_left_from > 0 && n_left_to_next > 0)
        {
@@ -416,22 +400,21 @@ pipe_rx (vlib_main_t * vm,
          type0 = clib_net_to_host_u16 (e0->type);
          pipe0 = &pipe_main.pipes[sw_if_index0];
 
+         vnet_buffer (b0)->l2_hdr_offset = b0->current_data;
          vnet_buffer (b0)->l3_hdr_offset =
-           vnet_buffer (b0)->l2_hdr_offset + vnet_buffer (b0)->l2.l2_len;
-         b0->flags |= VNET_BUFFER_F_L3_HDR_OFFSET_VALID;
+           vnet_buffer (b0)->l2_hdr_offset + sizeof (ethernet_header_t);
+         b0->flags |=
+           VNET_BUFFER_F_L2_HDR_OFFSET_VALID |
+           VNET_BUFFER_F_L3_HDR_OFFSET_VALID;
 
          is_l20 = pipe0->subint.flags & SUBINT_CONFIG_L2;
+
+         vnet_buffer (b0)->l2.l2_len = sizeof (ethernet_header_t);
+         vlib_buffer_advance (b0, is_l20 ? 0 : sizeof (ethernet_header_t));
+
          pipe_determine_next_node (&ethernet_main, is_l20, type0, b0,
                                    &next0);
 
-         if (!is_l20)
-           vlib_buffer_advance (b0, sizeof (ethernet_header_t));
-         else
-           {
-             u32 eth_start = vnet_buffer (b0)->l2_hdr_offset;
-             vnet_buffer (b0)->l2.l2_len = b0->current_data - eth_start;
-           }
-
          vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
                                           to_next, n_left_to_next,
                                           bi0, next0);
@@ -443,7 +426,6 @@ pipe_rx (vlib_main_t * vm,
   return from_frame->n_vectors;
 }
 
-/* *INDENT-OFF* */
 VLIB_REGISTER_NODE (pipe_rx_node) = {
   .function = pipe_rx,
   .name = "pipe-rx",
@@ -453,7 +435,6 @@ VLIB_REGISTER_NODE (pipe_rx_node) = {
 
   .sibling_of = "ethernet-input",
 };
-/* *INDENT-ON* */
 
 /*
  * Maintain a bitmap of allocated pipe instance numbers.
@@ -522,11 +503,11 @@ pipe_instance_free (u32 instance)
 
 static clib_error_t *
 pipe_create_sub_interface (vnet_hw_interface_t * hi,
-                          uint32_t sub_id, u32 * sw_if_index)
+                          u32 sub_id, u32 * sw_if_index)
 {
   vnet_sw_interface_t template;
 
-  memset (&template, 0, sizeof (template));
+  clib_memset (&template, 0, sizeof (template));
   template.type = VNET_SW_INTERFACE_TYPE_PIPE;
   template.flood_class = VNET_FLOOD_CLASS_NORMAL;
   template.sup_sw_if_index = hi->sw_if_index;
@@ -543,7 +524,8 @@ vnet_create_pipe_interface (u8 is_specified,
 {
   vnet_main_t *vnm = vnet_get_main ();
   vlib_main_t *vm = vlib_get_main ();
-  uint8_t address[6] = {
+  vnet_eth_interface_registration_t eir = {};
+  u8 address[6] = {
     [0] = 0x22,
     [1] = 0x22,
   };
@@ -556,7 +538,7 @@ vnet_create_pipe_interface (u8 is_specified,
 
   ASSERT (parent_sw_if_index);
 
-  memset (address, 0, sizeof (address));
+  clib_memset (address, 0, sizeof (address));
 
   /*
    * Allocate a pipe instance.  Either select one dynamically
@@ -573,15 +555,10 @@ vnet_create_pipe_interface (u8 is_specified,
    */
   address[5] = instance;
 
-  error = ethernet_register_interface (vnm, pipe_device_class.index,
-                                      instance, address, &hw_if_index,
-                                      /* flag change */ 0);
-
-  if (error)
-    {
-      rv = VNET_API_ERROR_INVALID_REGISTRATION;
-      goto oops;
-    }
+  eir.dev_class_index = pipe_device_class.index;
+  eir.dev_instance = instance;
+  eir.address = address;
+  hw_if_index = vnet_eth_register_interface (vnm, &eir);
 
   hi = vnet_get_hw_interface (vnm, hw_if_index);
   *parent_sw_if_index = hi->sw_if_index;
@@ -640,13 +617,11 @@ pipe_hw_walk (vnet_main_t * vnm, u32 hw_if_index, void *args)
     {
       u32 pipe_sw_if_index[2], id, sw_if_index;
 
-      /* *INDENT-OFF* */
       hash_foreach (id, sw_if_index, hi->sub_interface_sw_if_index_by_id,
       ({
         ASSERT(id < 2);
         pipe_sw_if_index[id] = sw_if_index;
       }));
-      /* *INDENT-ON* */
 
       ctx->cb (hi->sw_if_index, pipe_sw_if_index, hi->dev_instance, ctx->ctx);
     }
@@ -705,13 +680,11 @@ create_pipe_interfaces (vlib_main_t * vm,
  * Example of how to create a pipe interface:
  * @cliexcmd{pipe create}
  ?*/
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (pipe_create_interface_command, static) = {
   .path = "pipe create",
   .short_help = "pipe create [instance <instance>]",
   .function = create_pipe_interfaces,
 };
-/* *INDENT-ON* */
 
 int
 vnet_delete_pipe_interface (u32 sw_if_index)
@@ -735,13 +708,11 @@ vnet_delete_pipe_interface (u32 sw_if_index)
       return VNET_API_ERROR_INVALID_SW_IF_INDEX;
     }
 
-  /* *INDENT-OFF* */
   hash_foreach (id, sw_if_index, hi->sub_interface_sw_if_index_by_id,
   ({
     vnet_delete_sub_interface(sw_if_index);
     pipe_main.pipes[sw_if_index] = PIPE_INVALID;
   }));
-  /* *INDENT-ON* */
 
   ethernet_delete_interface (vnm, hw_if_index);
 
@@ -785,13 +756,11 @@ delete_pipe_interfaces (vlib_main_t * vm,
  * Example of how to delete a pipe interface:
  * @cliexcmd{pipe delete-interface intfc loop0}
  ?*/
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (pipe_delete_interface_command, static) = {
   .path = "pipe delete",
   .short_help = "pipe delete <interface>",
   .function = delete_pipe_interfaces,
 };
-/* *INDENT-ON* */
 
 /*
  * fd.io coding-style-patch-verification: ON