fib: fib api updates
[vpp.git] / src / vnet / fib / fib_types.c
index 542cf1d..4b1280f 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <vnet/fib/fib_types.h>
 #include <vnet/fib/fib_internal.h>
+#include <vnet/fib/fib_table.h>
 #include <vnet/mpls/mpls.h>
 
 /*
@@ -338,6 +339,22 @@ fib_forw_chain_type_from_dpo_proto (dpo_proto_t proto)
     return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
 }
 
+fib_forward_chain_type_t
+fib_forw_chain_type_from_fib_proto (fib_protocol_t proto)
+{
+    switch (proto)
+    {
+    case FIB_PROTOCOL_IP4:
+       return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
+    case FIB_PROTOCOL_IP6:
+       return (FIB_FORW_CHAIN_TYPE_UNICAST_IP6);
+    case FIB_PROTOCOL_MPLS:
+       return (FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS);
+    }
+    ASSERT(0);
+    return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
+}
+
 vnet_link_t
 fib_forw_chain_type_to_link_type (fib_forward_chain_type_t fct)
 {
@@ -418,12 +435,12 @@ unformat_fib_route_path (unformat_input_t * input, va_list * args)
 {
     fib_route_path_t *rpath = va_arg (*args, fib_route_path_t *);
     u32 *payload_proto = va_arg (*args, u32*);
-    u32 weight, preference, udp_encap_id;
+    u32 weight, preference, udp_encap_id, fi;
     mpls_label_t out_label;
     vnet_main_t *vnm;
 
     vnm = vnet_get_main ();
-    memset(rpath, 0, sizeof(*rpath));
+    clib_memset(rpath, 0, sizeof(*rpath));
     rpath->frp_weight = 1;
     rpath->frp_sw_if_index = ~0;
 
@@ -460,6 +477,14 @@ unformat_fib_route_path (unformat_input_t * input, va_list * args)
         {
             rpath->frp_sw_if_index = ~0;
             rpath->frp_proto = DPO_PROTO_IP4;
+
+            /*
+             * the user enter table-ids, convert to index
+             */
+            fi = fib_table_find (FIB_PROTOCOL_IP4, rpath->frp_fib_index);
+            if (~0 == fi)
+                return 0;
+            rpath->frp_fib_index = fi;
         }
         else if (unformat (input, "%U next-hop-table %d",
                            unformat_ip6_address,
@@ -468,6 +493,10 @@ unformat_fib_route_path (unformat_input_t * input, va_list * args)
         {
             rpath->frp_sw_if_index = ~0;
             rpath->frp_proto = DPO_PROTO_IP6;
+            fi = fib_table_find (FIB_PROTOCOL_IP6, rpath->frp_fib_index);
+            if (~0 == fi)
+                return 0;
+            rpath->frp_fib_index = fi;
         }
         else if (unformat (input, "%U",
                            unformat_ip4_address,
@@ -514,6 +543,10 @@ unformat_fib_route_path (unformat_input_t * input, va_list * args)
         {
             rpath->frp_proto = DPO_PROTO_IP4;
             *payload_proto = DPO_PROTO_IP4;
+            fi = fib_table_find (FIB_PROTOCOL_IP4, rpath->frp_fib_index);
+            if (~0 == fi)
+                return 0;
+            rpath->frp_fib_index = fi;
         }
         else if (unformat (input,
                            "ip6-lookup-in-table %d",
@@ -521,6 +554,10 @@ unformat_fib_route_path (unformat_input_t * input, va_list * args)
         {
             rpath->frp_proto = DPO_PROTO_IP6;
             *payload_proto = DPO_PROTO_IP6;
+            fi = fib_table_find (FIB_PROTOCOL_IP6, rpath->frp_fib_index);
+            if (~0 == fi)
+                return 0;
+            rpath->frp_fib_index = fi;
         }
         else if (unformat (input,
                            "mpls-lookup-in-table %d",
@@ -528,6 +565,10 @@ unformat_fib_route_path (unformat_input_t * input, va_list * args)
         {
             rpath->frp_proto = DPO_PROTO_MPLS;
             *payload_proto = DPO_PROTO_MPLS;
+            fi = fib_table_find (FIB_PROTOCOL_MPLS, rpath->frp_fib_index);
+            if (~0 == fi)
+                return 0;
+            rpath->frp_fib_index = fi;
         }
         else if (unformat (input, "src-lookup"))
         {
@@ -557,7 +598,14 @@ unformat_fib_route_path (unformat_input_t * input, va_list * args)
             rpath->frp_proto = DPO_PROTO_IP4;
             rpath->frp_flags = FIB_ROUTE_PATH_INTF_RX;
         }
-        else if (unformat (input, "out-labels"))
+      else if (unformat (input, "local"))
+       {
+         clib_memset (&rpath->frp_addr, 0, sizeof (rpath->frp_addr));
+         rpath->frp_sw_if_index = ~0;
+         rpath->frp_weight = 1;
+         rpath->frp_flags |= FIB_ROUTE_PATH_LOCAL;
+        }
+      else if (unformat (input, "out-labels"))
         {
             while (unformat (input, "%U",
                              unformat_mpls_unicast_label, &out_label))
@@ -574,6 +622,15 @@ unformat_fib_route_path (unformat_input_t * input, va_list * args)
         {
             rpath->frp_proto = *payload_proto;
         }
+        else if (unformat (input, "via"))
+        {
+            /* new path, back up and return */
+            unformat_put_input (input);
+            unformat_put_input (input);
+            unformat_put_input (input);
+            unformat_put_input (input);
+            break;
+        }
         else
         {
             return (0);