Load Balancer: Use FIB 2.0
[vpp.git] / plugins / lb-plugin / lb / node.c
index 4d59810..77beaac 100644 (file)
@@ -36,27 +36,11 @@ static char *lb_error_strings[] = {
 #undef _
 };
 
-typedef enum {
-  LB_NEXT_LOOKUP,
-  LB_NEXT_DROP,
-  LB_N_NEXT,
-} lb_next_t;
-
 typedef struct {
   u32 vip_index;
   u32 as_index;
 } lb_trace_t;
 
-u8 *lb_format_adjacency(u8 * s,
-                        struct ip_lookup_main_t * lm,
-                        ip_adjacency_t *adj)
-{
-  lb_main_t *lbm = &lb_main;
-  lb_adj_data_t *ad = (lb_adj_data_t *) &adj->opaque;
-  __attribute__((unused)) lb_vip_t *vip = pool_elt_at_index (lbm->vips, ad->vip_index);
-  return format(s, "idx:%d", ad->vip_index);
-}
-
 u8 *
 format_lb_trace (u8 * s, va_list * args)
 {
@@ -107,7 +91,6 @@ lb_node_fn (vlib_main_t * vm,
          u8 is_input_v4, //Compile-time parameter stating that is input is v4 (or v6)
          u8 is_encap_v4) //Compile-time parameter stating that is GRE encap is v4 (or v6)
 {
-  ip_lookup_main_t *lm = (is_input_v4)?&ip4_main.lookup_main:&ip6_main.lookup_main;
   lb_main_t *lbm = &lb_main;
   vlib_node_runtime_t *error_node = node;
   u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
@@ -126,8 +109,6 @@ lb_node_fn (vlib_main_t * vm,
     {
       u32 pi0;
       vlib_buffer_t *p0;
-      ip_adjacency_t *adj0;
-      lb_adj_data_t *ad0;
       lb_vip_t *vip0;
       lb_as_t *as0;
       gre_header_t *gre0;
@@ -135,7 +116,6 @@ lb_node_fn (vlib_main_t * vm,
       u32 value0, available_index0, hash0;
       u64 key0[5];
       lb_error_t error0 = LB_ERROR_NONE;
-      lb_next_t next0 = LB_NEXT_LOOKUP;
 
       if (PREDICT_TRUE(n_left_from > 1))
       {
@@ -153,9 +133,8 @@ lb_node_fn (vlib_main_t * vm,
       n_left_to_next -= 1;
 
       p0 = vlib_get_buffer (vm, pi0);
-      adj0 = ip_get_adjacency (lm, vnet_buffer (p0)->ip.adj_index[VLIB_TX]);
-      ad0 = (lb_adj_data_t *) &adj0->opaque;
-      vip0 = pool_elt_at_index (lbm->vips, ad0->vip_index);
+      vip0 = pool_elt_at_index (lbm->vips,
+                               vnet_buffer (p0)->ip.adj_index[VLIB_TX]);
 
       if (is_input_v4) {
         ip4_header_t *ip40;
@@ -196,7 +175,6 @@ lb_node_fn (vlib_main_t * vm,
         as0 = &lbm->ass[vip0->new_flow_table[hash0 & vip0->new_flow_table_mask].as_index];
         if (PREDICT_FALSE(as0 == lbm->ass)) { //Special first element
           error0 = LB_ERROR_NO_SERVER;
-          next0 = LB_NEXT_DROP;
         } else {
           vlib_increment_simple_counter(&lbm->vip_counters[LB_VIP_COUNTER_TRACKED_SESSION],
                                         cpu_index, vip0 - lbm->vips, 1);
@@ -251,16 +229,19 @@ lb_node_fn (vlib_main_t * vm,
           clib_host_to_net_u16(0x0800):
           clib_host_to_net_u16(0x86DD);
 
+      vnet_buffer (p0)->ip.adj_index[VLIB_TX] = as0->dpo.dpoi_index;
+
       if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
       {
         lb_trace_t *tr = vlib_add_trace (vm, node, p0, sizeof (*tr));
         tr->as_index = as0 - lbm->ass;
-        tr->vip_index = ad0->vip_index;
+        tr->vip_index = vip0 - lbm->vips;
       }
 
       p0->error = error_node->errors[error0];
       vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
-                                       n_left_to_next, pi0, next0);
+                                       n_left_to_next, pi0,
+                                      as0->dpo.dpoi_next_node);
     }
     vlib_put_next_frame (vm, node, next_index, n_left_to_next);
   }
@@ -309,17 +290,10 @@ VLIB_REGISTER_NODE (lb6_gre6_node) =
   .n_next_nodes = LB_N_NEXT,
   .next_nodes =
   {
-      [LB_NEXT_LOOKUP] = "ip6-lookup",
       [LB_NEXT_DROP] = "error-drop"
   },
 };
 
-VNET_IP6_REGISTER_ADJACENCY(lb6_gre6) = {
-  .node_name = "lb6-gre6",
-  .fn = lb_format_adjacency,
-  .next_index = &lb_main.ip_lookup_next_index[LB_VIP_TYPE_IP6_GRE6]
-};
-
 VLIB_REGISTER_NODE (lb6_gre4_node) =
 {
   .function = lb6_gre4_node_fn,
@@ -333,17 +307,10 @@ VLIB_REGISTER_NODE (lb6_gre4_node) =
   .n_next_nodes = LB_N_NEXT,
   .next_nodes =
   {
-      [LB_NEXT_LOOKUP] = "ip4-lookup",
       [LB_NEXT_DROP] = "error-drop"
   },
 };
 
-VNET_IP6_REGISTER_ADJACENCY(lb6_gre4) = {
-  .node_name = "lb6-gre4",
-  .fn = lb_format_adjacency,
-  .next_index = &lb_main.ip_lookup_next_index[LB_VIP_TYPE_IP6_GRE4]
-};
-
 VLIB_REGISTER_NODE (lb4_gre6_node) =
 {
   .function = lb4_gre6_node_fn,
@@ -357,17 +324,10 @@ VLIB_REGISTER_NODE (lb4_gre6_node) =
   .n_next_nodes = LB_N_NEXT,
   .next_nodes =
   {
-      [LB_NEXT_LOOKUP] = "ip6-lookup",
       [LB_NEXT_DROP] = "error-drop"
   },
 };
 
-VNET_IP4_REGISTER_ADJACENCY(lb4_gre6) = {
-  .node_name = "lb4-gre6",
-  .fn = lb_format_adjacency,
-  .next_index = &lb_main.ip_lookup_next_index[LB_VIP_TYPE_IP4_GRE6]
-};
-
 VLIB_REGISTER_NODE (lb4_gre4_node) =
 {
   .function = lb4_gre4_node_fn,
@@ -381,13 +341,7 @@ VLIB_REGISTER_NODE (lb4_gre4_node) =
   .n_next_nodes = LB_N_NEXT,
   .next_nodes =
   {
-      [LB_NEXT_LOOKUP] = "ip4-lookup",
       [LB_NEXT_DROP] = "error-drop"
   },
 };
 
-VNET_IP4_REGISTER_ADJACENCY(lb4_gre4) = {
-  .node_name = "lb4-gre4",
-  .fn = lb_format_adjacency,
-  .next_index = &lb_main.ip_lookup_next_index[LB_VIP_TYPE_IP4_GRE4]
-};