A Protocol Independent Hierarchical FIB (VPP-352)
[vpp.git] / vnet / vnet / classify / ip_classify.c
index eff447b..44973ae 100644 (file)
@@ -15,6 +15,7 @@
 #include <vnet/ip/ip.h>
 #include <vnet/ethernet/ethernet.h>    /* for ethernet_header_t */
 #include <vnet/classify/vnet_classify.h>
+#include <vnet/dpo/classify_dpo.h>
 
 typedef struct {
   u32 next_index;
@@ -63,16 +64,17 @@ ip_classify_inline (vlib_main_t * vm,
   u32 n_left_from, * from, * to_next;
   ip_lookup_next_t next_index;
   vnet_classify_main_t * vcm = &vnet_classify_main;
-  ip_lookup_main_t * lm;
   f64 now = vlib_time_now (vm);
   u32 hits = 0;
   u32 misses = 0;
   u32 chain_hits = 0;
+  u32 n_next;
 
-  if (is_ip4)
-    lm = &ip4_main.lookup_main;
-  else
-    lm = &ip6_main.lookup_main;
+  if (is_ip4) {
+    n_next = IP4_LOOKUP_N_NEXT;
+  } else {
+    n_next = IP6_LOOKUP_N_NEXT;
+  }
 
   from = vlib_frame_vector_args (frame);
   n_left_from = frame->n_vectors;
@@ -84,8 +86,8 @@ ip_classify_inline (vlib_main_t * vm,
       vlib_buffer_t * b0, * b1;
       u32 bi0, bi1;
       u8 * h0, * h1;
-      u32 adj_index0, adj_index1;
-      ip_adjacency_t * adj0, * adj1;
+      u32 cd_index0, cd_index1;
+      classify_dpo_t *cd0, * cd1;
       u32 table_index0, table_index1;
       vnet_classify_table_t * t0, * t1;
 
@@ -104,19 +106,21 @@ ip_classify_inline (vlib_main_t * vm,
         
       bi0 = from[0];
       b0 = vlib_get_buffer (vm, bi0);
-      h0 = b0->data;
+      h0 = (void *)vlib_buffer_get_current(b0) -
+                ethernet_buffer_header_size(b0);
 
       bi1 = from[1];
       b1 = vlib_get_buffer (vm, bi1);
-      h1 = b1->data;
+      h1 = (void *)vlib_buffer_get_current(b1) -
+                ethernet_buffer_header_size(b1);
         
-      adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
-      adj0 = ip_get_adjacency (lm, adj_index0);
-      table_index0 = adj0->classify.table_index;
+      cd_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
+      cd0 = classify_dpo_get(cd_index0);
+      table_index0 = cd0->cd_table_index;
 
-      adj_index1 = vnet_buffer (b1)->ip.adj_index[VLIB_TX];
-      adj1 = ip_get_adjacency (lm, adj_index1);
-      table_index1 = adj1->classify.table_index;
+      cd_index1 = vnet_buffer (b1)->ip.adj_index[VLIB_TX];
+      cd1 = classify_dpo_get(cd_index1);
+      table_index1 = cd1->cd_table_index;
 
       t0 = pool_elt_at_index (vcm->tables, table_index0);
 
@@ -145,18 +149,19 @@ ip_classify_inline (vlib_main_t * vm,
       vlib_buffer_t * b0;
       u32 bi0;
       u8 * h0;
-      u32 adj_index0;
-      ip_adjacency_t * adj0;
+      u32 cd_index0;
+      classify_dpo_t *cd0;
       u32 table_index0;
       vnet_classify_table_t * t0;
 
       bi0 = from[0];
       b0 = vlib_get_buffer (vm, bi0);
-      h0 = b0->data;
+      h0 = (void *)vlib_buffer_get_current(b0) -
+                ethernet_buffer_header_size(b0);
         
-      adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
-      adj0 = ip_get_adjacency (lm, adj_index0);
-      table_index0 = adj0->classify.table_index;
+      cd_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
+      cd0 = classify_dpo_get(cd_index0);
+      table_index0 = cd0->cd_table_index;
 
       t0 = pool_elt_at_index (vcm->tables, table_index0);
       vnet_buffer(b0)->l2_classify.hash = 
@@ -185,7 +190,7 @@ ip_classify_inline (vlib_main_t * vm,
        {
           u32 bi0;
          vlib_buffer_t * b0;
-          u32 next0 = IP_LOOKUP_NEXT_MISS;
+          u32 next0 = IP_LOOKUP_NEXT_DROP;
           u32 table_index0;
           vnet_classify_table_t * t0;
           vnet_classify_entry_t * e0;
@@ -237,7 +242,7 @@ ip_classify_inline (vlib_main_t * vm,
                   vnet_buffer(b0)->l2_classify.opaque_index
                     = e0->opaque_index;
                   vlib_buffer_advance (b0, e0->advance);
-                  next0 = (e0->next_index < IP_LOOKUP_N_NEXT)?
+                  next0 = (e0->next_index < node->n_next_nodes)?
                            e0->next_index:next0;
                   hits++;
                 }
@@ -250,8 +255,8 @@ ip_classify_inline (vlib_main_t * vm,
                                                 t0->next_table_index);
                       else
                         {
-                          next0 = (t0->miss_next_index < IP_LOOKUP_N_NEXT)?
-                                   t0->miss_next_index:next0;
+                          next0 = (t0->miss_next_index < n_next) ?
+                                   t0->miss_next_index : next0;
                           misses++;
                           break;
                         }
@@ -264,7 +269,7 @@ ip_classify_inline (vlib_main_t * vm,
                           vnet_buffer(b0)->l2_classify.opaque_index
                             = e0->opaque_index;
                           vlib_buffer_advance (b0, e0->advance);
-                          next0 = (e0->next_index < IP_LOOKUP_N_NEXT)?
+                          next0 = (e0->next_index < node->n_next_nodes)?
                                    e0->next_index:next0;
                           hits++;
                           chain_hits++;
@@ -318,28 +323,16 @@ VLIB_REGISTER_NODE (ip4_classify_node) = {
   .function = ip4_classify,
   .name = "ip4-classify",
   .vector_size = sizeof (u32),
+  .sibling_of = "ip4-lookup",
   .format_trace = format_ip_classify_trace,
   .n_errors = ARRAY_LEN(ip_classify_error_strings),
   .error_strings = ip_classify_error_strings,
 
-  .n_next_nodes = IP_LOOKUP_N_NEXT,
-  .next_nodes = {
-    [IP_LOOKUP_NEXT_MISS] = "ip4-miss",
-    [IP_LOOKUP_NEXT_DROP] = "ip4-drop",
-    [IP_LOOKUP_NEXT_PUNT] = "ip4-punt",
-    [IP_LOOKUP_NEXT_LOCAL] = "ip4-local",
-    [IP_LOOKUP_NEXT_ARP] = "ip4-arp",
-    [IP_LOOKUP_NEXT_REWRITE] = "ip4-rewrite-transit",
-    [IP_LOOKUP_NEXT_CLASSIFY] = "ip4-classify", /* probably not... */
-    [IP_LOOKUP_NEXT_MAP] = "ip4-map",
-    [IP_LOOKUP_NEXT_MAP_T] = "ip4-map-t",
-    [IP_LOOKUP_NEXT_SIXRD] = "ip4-sixrd",
-    [IP_LOOKUP_NEXT_HOP_BY_HOP] = "ip4-hop-by-hop",
-    [IP_LOOKUP_NEXT_ADD_HOP_BY_HOP] = "ip4-add-hop-by-hop", 
-    [IP_LOOKUP_NEXT_POP_HOP_BY_HOP] = "ip4-pop-hop-by-hop", 
-  },
+  .n_next_nodes = 0,
 };
 
+VLIB_NODE_FUNCTION_MULTIARCH (ip4_classify_node, ip4_classify)
+
 static uword
 ip6_classify (vlib_main_t * vm,
               vlib_node_runtime_t * node,
@@ -353,28 +346,16 @@ VLIB_REGISTER_NODE (ip6_classify_node) = {
   .function = ip6_classify,
   .name = "ip6-classify",
   .vector_size = sizeof (u32),
+  .sibling_of = "ip6-lookup",
   .format_trace = format_ip_classify_trace,
   .n_errors = ARRAY_LEN(ip_classify_error_strings),
   .error_strings = ip_classify_error_strings,
 
-  .n_next_nodes = IP_LOOKUP_N_NEXT,
-  .next_nodes = {
-    [IP_LOOKUP_NEXT_MISS] = "ip6-miss",
-    [IP_LOOKUP_NEXT_DROP] = "ip6-drop",
-    [IP_LOOKUP_NEXT_PUNT] = "ip6-punt",
-    [IP_LOOKUP_NEXT_LOCAL] = "ip6-local",
-    [IP_LOOKUP_NEXT_ARP] = "ip6-discover-neighbor",
-    [IP_LOOKUP_NEXT_REWRITE] = "ip6-rewrite",
-    [IP_LOOKUP_NEXT_CLASSIFY] = "ip6-classify", /* probably not... */
-    [IP_LOOKUP_NEXT_MAP] = "ip6-map",
-    [IP_LOOKUP_NEXT_MAP_T] = "ip6-map-t",
-    [IP_LOOKUP_NEXT_SIXRD] = "ip6-sixrd",
-    [IP_LOOKUP_NEXT_HOP_BY_HOP] = "ip6-hop-by-hop",
-    [IP_LOOKUP_NEXT_ADD_HOP_BY_HOP] = "ip6-add-hop-by-hop", 
-    [IP_LOOKUP_NEXT_POP_HOP_BY_HOP] = "ip6-pop-hop-by-hop", 
-  },
+  .n_next_nodes = 0,
 };
 
+VLIB_NODE_FUNCTION_MULTIARCH (ip6_classify_node, ip6_classify)
+
 static clib_error_t *
 ip_classify_init (vlib_main_t * vm)
 {