X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Ffib%2Ffib_types.c;h=dcb1c3a659c43f059ccb017682bc828f25fd1a82;hb=ea96e92361b483962fd2a6b027cedc02f3bb6f93;hp=5c70d6c172989e8eb07d829bd575fe7562b17e35;hpb=70ed8aeff30c0eece0e19f0ad26c4cc8957278ae;p=vpp.git diff --git a/src/vnet/fib/fib_types.c b/src/vnet/fib/fib_types.c index 5c70d6c1729..dcb1c3a659c 100644 --- a/src/vnet/fib/fib_types.c +++ b/src/vnet/fib/fib_types.c @@ -17,6 +17,8 @@ #include #include +#include +#include #include /* @@ -25,6 +27,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 +53,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) @@ -62,6 +89,7 @@ fib_prefix_from_ip46_addr (const ip46_address_t *addr, pfx->fp_len = ((ip46_address_is_ip4(addr) ? 32 : 128)); pfx->fp_addr = *addr; + pfx->___fp___pad = 0; } void @@ -73,6 +101,14 @@ fib_prefix_from_mpls_label (mpls_label_t label, pfx->fp_len = 21; pfx->fp_label = label; pfx->fp_eos = eos; + pfx->___fp___pad = 0; +} + +void +fib_prefix_copy (fib_prefix_t *dst, + const fib_prefix_t *src) +{ + clib_memcpy(dst, src, sizeof(*dst)); } int @@ -132,6 +168,21 @@ fib_prefix_is_cover (const fib_prefix_t *p1, return (0); } +u8 +fib_prefix_get_host_length (fib_protocol_t proto) +{ + switch (proto) + { + case FIB_PROTOCOL_IP4: + return (32); + case FIB_PROTOCOL_IP6: + return (128); + case FIB_PROTOCOL_MPLS: + return (21); + } + return (0); +} + int fib_prefix_is_host (const fib_prefix_t *prefix) { @@ -257,6 +308,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) { @@ -279,6 +364,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) { @@ -307,6 +408,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) { @@ -335,13 +459,13 @@ 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; + dpo_proto_t *payload_proto = va_arg (*args, void*); + 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; @@ -378,6 +502,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, @@ -386,6 +518,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, @@ -416,12 +552,7 @@ unformat_fib_route_path (unformat_input_t * input, va_list * args) { 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; + rpath->frp_flags |= FIB_ROUTE_PATH_DEAG; } else if (unformat (input, "resolve-via-host")) { @@ -431,12 +562,20 @@ unformat_fib_route_path (unformat_input_t * input, va_list * args) { rpath->frp_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED; } + else if (unformat (input, "pop-pw-cw")) + { + rpath->frp_flags |= FIB_ROUTE_PATH_POP_PW_CW; + } else if (unformat (input, "ip4-lookup-in-table %d", &rpath->frp_fib_index)) { 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", @@ -444,6 +583,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", @@ -451,6 +594,14 @@ 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")) + { + rpath->frp_flags |= FIB_ROUTE_PATH_SOURCE_LOOKUP; } else if (unformat (input, "l2-input-on %U", @@ -459,6 +610,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,14 +627,42 @@ 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, "%U", + unformat_mfib_itf_flags, &rpath->frp_mitf_flags)) + ; + else if (unformat (input, "out-labels")) { 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", + unformat_vnet_sw_interface, vnm, + &rpath->frp_sw_if_index)) + { + 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);