summaryrefslogtreecommitdiffstats
path: root/src/vnet/fib
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2017-11-15 12:54:46 -0800
committerFlorin Coras <florin.coras@gmail.com>2017-11-18 01:34:22 +0000
commit70ed8aeff30c0eece0e19f0ad26c4cc8957278ae (patch)
treeb09bda6fef287b46dac123949f25972edc41e600 /src/vnet/fib
parent8ac4ce8547d84c2d581f572b4f51fd34dbf1b01f (diff)
unformat function for FIB paths
Change-Id: I32de25890ac0a643314f650591d2479879d9a2a6 Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'src/vnet/fib')
-rw-r--r--src/vnet/fib/fib_types.c161
-rw-r--r--src/vnet/fib/fib_types.h10
2 files changed, 171 insertions, 0 deletions
diff --git a/src/vnet/fib/fib_types.c b/src/vnet/fib/fib_types.c
index 656966b2331..5c70d6c1729 100644
--- a/src/vnet/fib/fib_types.c
+++ b/src/vnet/fib/fib_types.c
@@ -330,3 +330,164 @@ fib_forw_chain_type_to_dpo_proto (fib_forward_chain_type_t fct)
}
return (DPO_PROTO_IP4);
}
+
+uword
+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;
+ mpls_label_t out_label;
+ vnet_main_t *vnm;
+
+ vnm = vnet_get_main ();
+ memset(rpath, 0, sizeof(*rpath));
+ rpath->frp_weight = 1;
+ rpath->frp_sw_if_index = ~0;
+
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (input, "%U %U",
+ unformat_ip4_address,
+ &rpath->frp_addr.ip4,
+ unformat_vnet_sw_interface, vnm,
+ &rpath->frp_sw_if_index))
+ {
+ rpath->frp_proto = DPO_PROTO_IP4;
+ }
+ else if (unformat (input, "%U %U",
+ unformat_ip6_address,
+ &rpath->frp_addr.ip6,
+ unformat_vnet_sw_interface, vnm,
+ &rpath->frp_sw_if_index))
+ {
+ rpath->frp_proto = DPO_PROTO_IP6;
+ }
+ else if (unformat (input, "weight %u", &weight))
+ {
+ rpath->frp_weight = weight;
+ }
+ else if (unformat (input, "preference %u", &preference))
+ {
+ rpath->frp_preference = preference;
+ }
+ else if (unformat (input, "%U next-hop-table %d",
+ unformat_ip4_address,
+ &rpath->frp_addr.ip4,
+ &rpath->frp_fib_index))
+ {
+ rpath->frp_sw_if_index = ~0;
+ rpath->frp_proto = DPO_PROTO_IP4;
+ }
+ else if (unformat (input, "%U next-hop-table %d",
+ unformat_ip6_address,
+ &rpath->frp_addr.ip6,
+ &rpath->frp_fib_index))
+ {
+ rpath->frp_sw_if_index = ~0;
+ rpath->frp_proto = DPO_PROTO_IP6;
+ }
+ else if (unformat (input, "%U",
+ unformat_ip4_address,
+ &rpath->frp_addr.ip4))
+ {
+ /*
+ * the recursive next-hops are by default in the default table
+ */
+ rpath->frp_fib_index = 0;
+ rpath->frp_sw_if_index = ~0;
+ rpath->frp_proto = DPO_PROTO_IP4;
+ }
+ else if (unformat (input, "%U",
+ unformat_ip6_address,
+ &rpath->frp_addr.ip6))
+ {
+ rpath->frp_fib_index = 0;
+ rpath->frp_sw_if_index = ~0;
+ rpath->frp_proto = DPO_PROTO_IP6;
+ }
+ else if (unformat (input, "udp-encap %d", &udp_encap_id))
+ {
+ rpath->frp_udp_encap_id = udp_encap_id;
+ rpath->frp_flags |= FIB_ROUTE_PATH_UDP_ENCAP;
+ rpath->frp_proto = *payload_proto;
+ }
+ else if (unformat (input, "lookup in table %d", &rpath->frp_fib_index))
+ {
+ rpath->frp_proto = *payload_proto;
+ rpath->frp_sw_if_index = ~0;
+ }
+ else if (unformat (input, "via %U",
+ unformat_vnet_sw_interface, vnm,
+ &rpath->frp_sw_if_index))
+ {
+ rpath->frp_proto = *payload_proto;
+ }
+ else if (unformat (input, "resolve-via-host"))
+ {
+ rpath->frp_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST;
+ }
+ else if (unformat (input, "resolve-via-attached"))
+ {
+ rpath->frp_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED;
+ }
+ else if (unformat (input,
+ "ip4-lookup-in-table %d",
+ &rpath->frp_fib_index))
+ {
+ rpath->frp_proto = DPO_PROTO_IP4;
+ *payload_proto = DPO_PROTO_IP4;
+ }
+ else if (unformat (input,
+ "ip6-lookup-in-table %d",
+ &rpath->frp_fib_index))
+ {
+ rpath->frp_proto = DPO_PROTO_IP6;
+ *payload_proto = DPO_PROTO_IP6;
+ }
+ else if (unformat (input,
+ "mpls-lookup-in-table %d",
+ &rpath->frp_fib_index))
+ {
+ rpath->frp_proto = DPO_PROTO_MPLS;
+ *payload_proto = DPO_PROTO_MPLS;
+ }
+ else if (unformat (input,
+ "l2-input-on %U",
+ unformat_vnet_sw_interface, vnm,
+ &rpath->frp_sw_if_index))
+ {
+ rpath->frp_proto = DPO_PROTO_ETHERNET;
+ *payload_proto = DPO_PROTO_ETHERNET;
+ }
+ else if (unformat (input, "via-label %U",
+ unformat_mpls_unicast_label,
+ &rpath->frp_local_label))
+ {
+ rpath->frp_eos = MPLS_NON_EOS;
+ rpath->frp_proto = DPO_PROTO_MPLS;
+ rpath->frp_sw_if_index = ~0;
+ }
+ else if (unformat (input, "rx-ip4 %U",
+ unformat_vnet_sw_interface, vnm,
+ &rpath->frp_sw_if_index))
+ {
+ rpath->frp_proto = DPO_PROTO_IP4;
+ rpath->frp_flags = FIB_ROUTE_PATH_INTF_RX;
+ }
+ else if (unformat (input, "out-labels"))
+ {
+ while (unformat (input, "%U",
+ unformat_mpls_unicast_label, &out_label))
+ {
+ vec_add1(rpath->frp_label_stack, out_label);
+ }
+ }
+ else
+ {
+ return (0);
+ }
+ }
+
+ return (1);
+}
diff --git a/src/vnet/fib/fib_types.h b/src/vnet/fib/fib_types.h
index 0a4b1699609..be6a24ee9cd 100644
--- a/src/vnet/fib/fib_types.h
+++ b/src/vnet/fib/fib_types.h
@@ -461,6 +461,16 @@ typedef struct fib_route_path_t_ {
} fib_route_path_t;
/**
+ * Unformat a fib_route_path_t from CLI input
+ */
+extern uword unformat_fib_route_path(unformat_input_t * input, va_list * args);
+
+/**
+ * A help string to list the FIB path options
+ */
+#define FIB_ROUTE_PATH_HELP "[next-hop-address] [next-hop-interface] [next-hop-table <value>] [weight <value>] [preference <value>] [udp-encap-id <value>] [ip4-lookup-in-table <value>] [ip6-lookup-in-table <value>] [mpls-lookup-in-table <value>] [resolve-via-host] [resolve-via-connected] [rx-ip4 <interface>] [out-labels <value value value>]"
+
+/**
* @brief
* A representation of a fib path for fib_path_encode to convey the information to the caller
*/