MPLS Mcast
[vpp.git] / src / vnet / ip / ip4_forward.c
index ef6dded..9fdf9b3 100644 (file)
@@ -75,7 +75,7 @@ ip4_lookup_inline (vlib_main_t * vm,
   vlib_combined_counter_main_t *cm = &load_balance_main.lbm_to_counters;
   u32 n_left_from, n_left_to_next, *from, *to_next;
   ip_lookup_next_t next;
-  u32 cpu_index = os_get_cpu_number ();
+  u32 thread_index = vlib_get_thread_index ();
 
   from = vlib_frame_vector_args (frame);
   n_left_from = frame->n_vectors;
@@ -182,7 +182,6 @@ ip4_lookup_inline (vlib_main_t * vm,
              mtrie2 = &ip4_fib_get (fib_index2)->mtrie;
              mtrie3 = &ip4_fib_get (fib_index3)->mtrie;
 
-
              leaf0 = ip4_fib_mtrie_lookup_step_one (mtrie0, dst_addr0);
              leaf1 = ip4_fib_mtrie_lookup_step_one (mtrie1, dst_addr1);
              leaf2 = ip4_fib_mtrie_lookup_step_one (mtrie2, dst_addr2);
@@ -194,14 +193,6 @@ ip4_lookup_inline (vlib_main_t * vm,
          tcp2 = (void *) (ip2 + 1);
          tcp3 = (void *) (ip3 + 1);
 
-         if (!lookup_for_responses_to_locally_received_packets)
-           {
-             leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, dst_addr0, 1);
-             leaf1 = ip4_fib_mtrie_lookup_step (mtrie1, leaf1, dst_addr1, 1);
-             leaf2 = ip4_fib_mtrie_lookup_step (mtrie2, leaf2, dst_addr2, 1);
-             leaf3 = ip4_fib_mtrie_lookup_step (mtrie3, leaf3, dst_addr3, 1);
-           }
-
          if (!lookup_for_responses_to_locally_received_packets)
            {
              leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, dst_addr0, 2);
@@ -301,19 +292,19 @@ ip4_lookup_inline (vlib_main_t * vm,
          vnet_buffer (p3)->ip.adj_index[VLIB_TX] = dpo3->dpoi_index;
 
          vlib_increment_combined_counter
-           (cm, cpu_index, lb_index0, 1,
+           (cm, thread_index, lb_index0, 1,
             vlib_buffer_length_in_chain (vm, p0)
             + sizeof (ethernet_header_t));
          vlib_increment_combined_counter
-           (cm, cpu_index, lb_index1, 1,
+           (cm, thread_index, lb_index1, 1,
             vlib_buffer_length_in_chain (vm, p1)
             + sizeof (ethernet_header_t));
          vlib_increment_combined_counter
-           (cm, cpu_index, lb_index2, 1,
+           (cm, thread_index, lb_index2, 1,
             vlib_buffer_length_in_chain (vm, p2)
             + sizeof (ethernet_header_t));
          vlib_increment_combined_counter
-           (cm, cpu_index, lb_index3, 1,
+           (cm, thread_index, lb_index3, 1,
             vlib_buffer_length_in_chain (vm, p3)
             + sizeof (ethernet_header_t));
 
@@ -363,9 +354,6 @@ ip4_lookup_inline (vlib_main_t * vm,
 
          tcp0 = (void *) (ip0 + 1);
 
-         if (!lookup_for_responses_to_locally_received_packets)
-           leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, dst_addr0, 1);
-
          if (!lookup_for_responses_to_locally_received_packets)
            leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, dst_addr0, 2);
 
@@ -404,7 +392,7 @@ ip4_lookup_inline (vlib_main_t * vm,
          vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
 
          vlib_increment_combined_counter
-           (cm, cpu_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0));
+           (cm, thread_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0));
 
          from += 1;
          to_next += 1;
@@ -491,7 +479,7 @@ ip4_load_balance (vlib_main_t * vm,
   vlib_combined_counter_main_t *cm = &load_balance_main.lbm_via_counters;
   u32 n_left_from, n_left_to_next, *from, *to_next;
   ip_lookup_next_t next;
-  u32 cpu_index = os_get_cpu_number ();
+  u32 thread_index = vlib_get_thread_index ();
 
   from = vlib_frame_vector_args (frame);
   n_left_from = frame->n_vectors;
@@ -596,9 +584,9 @@ ip4_load_balance (vlib_main_t * vm,
          vnet_buffer (p1)->ip.adj_index[VLIB_TX] = dpo1->dpoi_index;
 
          vlib_increment_combined_counter
-           (cm, cpu_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0));
+           (cm, thread_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0));
          vlib_increment_combined_counter
-           (cm, cpu_index, lbi1, 1, vlib_buffer_length_in_chain (vm, p1));
+           (cm, thread_index, lbi1, 1, vlib_buffer_length_in_chain (vm, p1));
 
          vlib_validate_buffer_enqueue_x2 (vm, node, next,
                                           to_next, n_left_to_next,
@@ -651,7 +639,7 @@ ip4_load_balance (vlib_main_t * vm,
          vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
 
          vlib_increment_combined_counter
-           (cm, cpu_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0));
+           (cm, thread_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0));
 
          vlib_validate_buffer_enqueue_x1 (vm, node, next,
                                           to_next, n_left_to_next,
@@ -1622,11 +1610,6 @@ ip4_local_inline (vlib_main_t * vm,
          good_tcp_udp0 |= is_udp0 && udp0->checksum == 0;
          good_tcp_udp1 |= is_udp1 && udp1->checksum == 0;
 
-         leaf0 =
-           ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 1);
-         leaf1 =
-           ip4_fib_mtrie_lookup_step (mtrie1, leaf1, &ip1->src_address, 1);
-
          /* Verify UDP length. */
          ip_len0 = clib_net_to_host_u16 (ip0->length);
          ip_len1 = clib_net_to_host_u16 (ip1->length);
@@ -1812,9 +1795,6 @@ ip4_local_inline (vlib_main_t * vm,
          /* Don't verify UDP checksum for packets with explicit zero checksum. */
          good_tcp_udp0 |= is_udp0 && udp0->checksum == 0;
 
-         leaf0 =
-           ip4_fib_mtrie_lookup_step (mtrie0, leaf0, &ip0->src_address, 1);
-
          /* Verify UDP length. */
          ip_len0 = clib_net_to_host_u16 (ip0->length);
          udp_len0 = clib_net_to_host_u16 (udp0->length);
@@ -2350,7 +2330,7 @@ ip4_rewrite_inline (vlib_main_t * vm,
 
   n_left_from = frame->n_vectors;
   next_index = node->cached_next_index;
-  u32 cpu_index = os_get_cpu_number ();
+  u32 thread_index = vlib_get_thread_index ();
 
   while (n_left_from > 0)
     {
@@ -2399,9 +2379,9 @@ ip4_rewrite_inline (vlib_main_t * vm,
          if (do_counters)
            {
              vlib_prefetch_combined_counter (&adjacency_counters,
-                                             cpu_index, adj_index0);
+                                             thread_index, adj_index0);
              vlib_prefetch_combined_counter (&adjacency_counters,
-                                             cpu_index, adj_index1);
+                                             thread_index, adj_index1);
            }
 
          ip0 = vlib_buffer_get_current (p0);
@@ -2547,13 +2527,13 @@ ip4_rewrite_inline (vlib_main_t * vm,
            {
              vlib_increment_combined_counter
                (&adjacency_counters,
-                cpu_index,
+                thread_index,
                 adj_index0, 1,
                 vlib_buffer_length_in_chain (vm, p0) + rw_len0);
 
              vlib_increment_combined_counter
                (&adjacency_counters,
-                cpu_index,
+                thread_index,
                 adj_index1, 1,
                 vlib_buffer_length_in_chain (vm, p1) + rw_len1);
            }
@@ -2638,7 +2618,7 @@ ip4_rewrite_inline (vlib_main_t * vm,
 
          if (do_counters)
            vlib_prefetch_combined_counter (&adjacency_counters,
-                                           cpu_index, adj_index0);
+                                           thread_index, adj_index0);
 
          /* Guess we are only writing on simple Ethernet header. */
          vnet_rewrite_one_header (adj0[0], ip0, sizeof (ethernet_header_t));
@@ -2657,7 +2637,7 @@ ip4_rewrite_inline (vlib_main_t * vm,
          if (do_counters)
            vlib_increment_combined_counter
              (&adjacency_counters,
-              cpu_index, adj_index0, 1,
+              thread_index, adj_index0, 1,
               vlib_buffer_length_in_chain (vm, p0) + rw_len0);
 
          /* Check MTU of outgoing interface. */
@@ -2772,6 +2752,16 @@ ip4_rewrite_mcast (vlib_main_t * vm,
     return ip4_rewrite_inline (vm, node, frame, 0, 0, 1);
 }
 
+static uword
+ip4_mcast_midchain (vlib_main_t * vm,
+                   vlib_node_runtime_t * node, vlib_frame_t * frame)
+{
+  if (adj_are_counters_enabled ())
+    return ip4_rewrite_inline (vm, node, frame, 1, 1, 1);
+  else
+    return ip4_rewrite_inline (vm, node, frame, 0, 1, 1);
+}
+
 /* *INDENT-OFF* */
 VLIB_REGISTER_NODE (ip4_rewrite_node) = {
   .function = ip4_rewrite,
@@ -2798,6 +2788,16 @@ VLIB_REGISTER_NODE (ip4_rewrite_mcast_node) = {
 };
 VLIB_NODE_FUNCTION_MULTIARCH (ip4_rewrite_mcast_node, ip4_rewrite_mcast)
 
+VLIB_REGISTER_NODE (ip4_mcast_midchain_node, static) = {
+  .function = ip4_mcast_midchain,
+  .name = "ip4-mcast-midchain",
+  .vector_size = sizeof (u32),
+
+  .format_trace = format_ip4_rewrite_trace,
+  .sibling_of = "ip4-rewrite",
+};
+VLIB_NODE_FUNCTION_MULTIARCH (ip4_mcast_midchain_node, ip4_mcast_midchain)
+
 VLIB_REGISTER_NODE (ip4_midchain_node) = {
   .function = ip4_midchain,
   .name = "ip4-midchain",
@@ -2913,7 +2913,6 @@ ip4_lookup_validate (ip4_address_t * a, u32 fib_index0)
   mtrie0 = &ip4_fib_get (fib_index0)->mtrie;
 
   leaf0 = ip4_fib_mtrie_lookup_step_one (mtrie0, a);
-  leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, a, 1);
   leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, a, 2);
   leaf0 = ip4_fib_mtrie_lookup_step (mtrie0, leaf0, a, 3);