Use IP address types on UDP encap API
[vpp.git] / src / vnet / fib / fib_types.c
index f38c815..542cf1d 100644 (file)
@@ -25,6 +25,7 @@
 static const char* fib_protocol_names[] = FIB_PROTOCOLS;
 static const char* vnet_link_names[] = VNET_LINKS;
 static const char* fib_forw_chain_names[] = FIB_FORW_CHAINS;
+static const char* fib_mpls_lsp_mode_names[] = FIB_MPLS_LSP_MODES;
 
 u8 *
 format_fib_protocol (u8 * s, va_list * ap)
@@ -50,6 +51,30 @@ format_fib_forw_chain_type (u8 * s, va_list * args)
     return (format (s, "%s", fib_forw_chain_names[fct]));
 }
 
+u8 *
+format_fib_mpls_lsp_mode(u8 *s, va_list *ap)
+{
+    fib_mpls_lsp_mode_t mode = va_arg(*ap, int);
+
+    return (format (s, "%s", fib_mpls_lsp_mode_names[mode])); 
+}
+
+u8 *
+format_fib_mpls_label (u8 *s, va_list *ap)
+{
+    fib_mpls_label_t *label = va_arg(*ap, fib_mpls_label_t *);
+
+    s = format(s, "%U %U ttl:%d exp:%d",
+               format_mpls_unicast_label,
+               label->fml_value,
+               format_fib_mpls_lsp_mode,
+               label->fml_mode,
+               label->fml_ttl,
+               label->fml_exp);
+
+    return (s);
+}
+
 void
 fib_prefix_from_ip46_addr (const ip46_address_t *addr,
                           fib_prefix_t *pfx)
@@ -257,6 +282,40 @@ fib_proto_to_link (fib_protocol_t proto)
     return (0);
 }
 
+ip46_type_t
+fib_proto_to_ip46 (fib_protocol_t fproto)
+{
+    switch (fproto)
+    {
+    case FIB_PROTOCOL_IP4:
+       return (IP46_TYPE_IP4);
+    case FIB_PROTOCOL_IP6:
+       return (IP46_TYPE_IP6);
+    case FIB_PROTOCOL_MPLS:
+       return (IP46_TYPE_ANY);
+    }
+    ASSERT(0);
+    return (IP46_TYPE_ANY);
+}
+
+fib_protocol_t
+fib_proto_from_ip46 (ip46_type_t iproto)
+{
+    switch (iproto)
+    {
+    case IP46_TYPE_IP4:
+        return FIB_PROTOCOL_IP4;
+    case IP46_TYPE_IP6:
+        return FIB_PROTOCOL_IP6;
+    case IP46_TYPE_ANY:
+        ASSERT(0);
+        return FIB_PROTOCOL_IP4;
+    }
+
+    ASSERT(0);
+    return FIB_PROTOCOL_IP4;
+}
+
 fib_forward_chain_type_t
 fib_forw_chain_type_from_dpo_proto (dpo_proto_t proto)
 {
@@ -307,6 +366,29 @@ fib_forw_chain_type_to_link_type (fib_forward_chain_type_t fct)
     return (VNET_LINK_IP4);
 }
 
+fib_forward_chain_type_t
+fib_forw_chain_type_from_link_type (vnet_link_t link_type)
+{
+    switch (link_type)
+    {
+    case VNET_LINK_IP4:
+        return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
+    case VNET_LINK_IP6:
+        return (FIB_FORW_CHAIN_TYPE_UNICAST_IP6);
+    case VNET_LINK_MPLS:
+        return (FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS);
+    case VNET_LINK_ETHERNET:
+        return (FIB_FORW_CHAIN_TYPE_ETHERNET);
+    case VNET_LINK_NSH:
+        return (FIB_FORW_CHAIN_TYPE_NSH);
+    case VNET_LINK_ARP:
+        break;
+    }
+
+    ASSERT(0);
+    return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
+}
+
 dpo_proto_t
 fib_forw_chain_type_to_dpo_proto (fib_forward_chain_type_t fct)
 {
@@ -447,6 +529,10 @@ unformat_fib_route_path (unformat_input_t * input, va_list * args)
             rpath->frp_proto = DPO_PROTO_MPLS;
             *payload_proto = DPO_PROTO_MPLS;
         }
+        else if (unformat (input, "src-lookup"))
+        {
+            rpath->frp_flags |= FIB_ROUTE_PATH_SOURCE_LOOKUP;
+        }
         else if (unformat (input,
                            "l2-input-on %U",
                            unformat_vnet_sw_interface, vnm,
@@ -454,6 +540,7 @@ unformat_fib_route_path (unformat_input_t * input, va_list * args)
         {
             rpath->frp_proto = DPO_PROTO_ETHERNET;
             *payload_proto = DPO_PROTO_ETHERNET;
+            rpath->frp_flags |= FIB_ROUTE_PATH_INTF_RX;
         }
         else if (unformat (input, "via-label %U",
                            unformat_mpls_unicast_label,
@@ -475,7 +562,10 @@ unformat_fib_route_path (unformat_input_t * input, va_list * args)
             while (unformat (input, "%U",
                              unformat_mpls_unicast_label, &out_label))
             {
-                vec_add1(rpath->frp_label_stack, out_label);
+                fib_mpls_label_t fml = {
+                    .fml_value = out_label,
+                };
+                vec_add1(rpath->frp_label_stack, fml);
             }
         }
         else if (unformat (input, "%U",