51 s =
format (s,
"%d", label);
69 else if (
unformat (input,
"%d", label))
90 return (
format(s,
"[%U:%d:%d:%U]",
102 u8 ** result = va_arg (*args,
u8 **);
104 u32 label, label_exp_s_ttl;
106 if (!
unformat (input,
"MPLS %d", &label))
109 label_exp_s_ttl = (label<<12) | (1<<8) | 0xFF;
115 u32 h_n_bytes =
sizeof (h[0]);
132 s =
format (s,
"MPLS: lookup miss");
135 s =
format (s,
"MPLS: tunnel %d labels %U len %d tx_sw_index %d dst %U",
138 clib_net_to_host_u16 (t->
length),
149 u32 max_header_bytes = va_arg (*args,
u32);
152 header_bytes =
sizeof (h[0]);
153 if (max_header_bytes != 0 && header_bytes > max_header_bytes)
154 return format (s,
"ethernet header truncated");
157 (s,
"ETHERNET-MPLS label %d",
167 u32 * result = va_arg (*args,
u32 *);
170 if (!
unformat (input,
"MPLS: label %d", &label))
173 label = (label<<12) | (1<<8) | 0xFF ;
175 *result = clib_host_to_net_u32 (label);
186 key = ((
u64)rx_fib<<32) | ((
u64) dst_address);
197 u32 *labels_host_byte_order,
198 u32 policy_tunnel_index,
199 int no_dst_hash,
u32 * indexp,
int is_add)
204 u32 label_net_byte_order, label_host_byte_order;
212 return VNET_API_ERROR_NO_SUCH_FIB;
221 memset (e, 0,
sizeof (*e));
223 for (i = 0; i <
vec_len (labels_host_byte_order); i++)
226 label_host_byte_order = labels_host_byte_order[
i];
229 label_host_byte_order <<= 12;
233 label_host_byte_order |= 0xff;
234 label_net_byte_order = clib_host_to_net_u32 (label_host_byte_order);
238 if (no_dst_hash == 0)
242 if (policy_tunnel_index != ~0)
249 return VNET_API_ERROR_NO_SUCH_LABEL;
257 if (no_dst_hash == 0)
272 u32 policy_tunnel_index = ~0;
280 if (
unformat (input,
"fib %d", &fib_id))
284 else if (
unformat (input,
"no-dst-hash"))
286 else if (
unformat (input,
"label %d", &this_label))
288 else if (
unformat (input,
"policy-tunnel %d", &policy_tunnel_index))
312 case VNET_API_ERROR_NO_SUCH_FIB:
324 .path =
"mpls encap add",
326 "mpls encap add label <label> ... fib <id> dest <ip4-address>",
335 s =
format (s,
"label %d exp %d, s %d, ttl %d",
363 if (
unformat (input,
"fib %d dest %U", &fib_id,
373 case VNET_API_ERROR_NO_SUCH_FIB:
375 case VNET_API_ERROR_NO_SUCH_ENTRY:
389 .path =
"mpls encap delete",
390 .short_help =
"mpls encap delete fib <id> dest <ip4-address>",
400 return clib_net_to_host_u32(r1->
dest) - clib_net_to_host_u32(r2->
dest);
435 vec_add2 (records, s, 1);
436 s->fib_index = (u32)(key>>32);
437 s->dest = (u32)(key & 0xFFFFFFFF);
438 s->entry_index = (u32) value;
449 vlib_cli_output (vm,
"%=6s%=16s%=16s",
"Table",
"Dest address",
"Labels");
463 .path =
"show mpls encap",
464 .short_help =
"show mpls encap",
476 u32 table_id, is_del, is_ip;
486 memset(&pfx, 0,
sizeof(pfx));
494 memset(&rpath, 0,
sizeof(rpath));
496 if (
unformat (line_input,
"table %d", &table_id))
498 else if (
unformat (line_input,
"del"))
500 else if (
unformat (line_input,
"add"))
502 else if (
unformat (line_input,
"eos"))
504 else if (
unformat (line_input,
"non-eos"))
506 else if (
unformat (line_input,
"%U/%d",
514 else if (
unformat (line_input,
"%U/%d",
522 else if (
unformat (line_input,
"%d", &local_label))
525 "ip4-lookup-in-table %d",
526 &rpath.frp_fib_index))
535 "ip6-lookup-in-table %d",
536 &rpath.frp_fib_index))
545 "mpls-lookup-in-table %d",
546 &rpath.frp_fib_index))
651 .path =
"mpls local-label",
653 .short_help =
"Create/Delete MPL local labels",
669 return VNET_API_ERROR_NO_SUCH_FIB;
675 if (fib_index == (u32)(key>>32)) {
676 vec_add2 (records, s, 1);
677 s->dest = (u32)(key & 0xFFFFFFFF);
678 s->entry_index = (u32) value;
684 key = ((
u64)fib_index<<32) | ((
u64) s->dest);
685 hash_unset (mm->mpls_encap_by_fib_and_dest, key);
u32 fib_table_id_find_fib_index(fib_protocol_t proto, u32 table_id)
fib_protocol_t fp_proto
protocol type
uword unformat_mpls_unicast_label(unformat_input_t *input, va_list *args)
#define hash_set(h, key, value)
sll srl srl sll sra u16x4 i
#define hash_unset(h, key)
A representation of a path as described by a route producer.
u32 mpls_label_t
A label value only, i.e.
#define MPLS_IETF_IMPLICIT_NULL_LABEL
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
#define MPLS_IETF_ROUTER_ALERT_LABEL
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
u8 * format_mpls_unicast_label(u8 *s, va_list *args)
u8 * format_mpls_unicast_header_host_byte_order(u8 *s, va_list *args)
int mpls_dest_cmp(void *a1, void *a2)
uword * mpls_encap_by_fib_and_dest
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
static clib_error_t * mpls_input_init(vlib_main_t *vm)
void fib_table_entry_local_label_remove(u32 fib_index, const fib_prefix_t *prefix, mpls_label_t label)
remove a MPLS local label for the prefix/route.
static clib_error_t * mpls_add_encap_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
dpo_proto_t fp_payload_proto
This protocol determines the payload protocol of packets that will be forwarded by this entry once th...
vnet_main_t * vnet_get_main(void)
u8 * format_mpls_eth_tx_trace(u8 *s, va_list *args)
u8 * format_ethernet_address(u8 *s, va_list *args)
#define MPLS_IETF_ROUTER_ALERT_STRING
#define VLIB_INIT_FUNCTION(x)
int mpls_fib_reset_labels(u32 fib_id)
#define hash_foreach(key_var, value_var, h, body)
Aggregrate type for a prefix.
static clib_error_t * show_mpls_fib_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static const char * mpls_eos_bit_names[]
int vnet_mpls_policy_tunnel_add_rewrite(mpls_main_t *mm, mpls_encap_t *e, u32 policy_tunnel_index)
static u32 vnet_mpls_uc_get_ttl(mpls_label_t label_exp_s_ttl)
u32 fib_table_find(fib_protocol_t proto, u32 table_id)
Get the index of the FIB for a Table-ID.
fib_protocol_t dpo_proto_to_fib(dpo_proto_t dpo_proto)
u16 fp_len
The mask length.
#define vlib_call_init_function(vm, x)
#define MPLS_IETF_GAL_STRING
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
#define MPLS_IETF_ELI_LABEL
uword * fib_index_by_table_id
Hash table mapping table id to fib index.
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
#define pool_put(P, E)
Free an object E in pool P.
static u32 vnet_mpls_uc_get_label(mpls_label_t label_exp_s_ttl)
uword unformat_mpls_header(unformat_input_t *input, va_list *args)
#define MPLS_IETF_IPV4_EXPLICIT_NULL_STRING
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
clib_error_t * ip_main_init(vlib_main_t *vm)
fib_node_index_t fib_table_entry_local_label_add(u32 fib_index, const fib_prefix_t *prefix, mpls_label_t label)
Add a MPLS local label for the prefix/route.
#define MPLS_LABEL_INVALID
#define vec_free(V)
Free vector's memory (no header).
static ip4_fib_t * ip4_fib_get(u32 index)
Get the FIB at the given index.
#define MPLS_IETF_IPV4_EXPLICIT_NULL_LABEL
#define clib_memcpy(a, b, c)
int vnet_mpls_add_del_encap(ip4_address_t *dest, u32 fib_id, u32 *labels_host_byte_order, u32 policy_tunnel_index, int no_dst_hash, u32 *indexp, int is_add)
u32 fib_node_index_t
A typedef of a node index.
u32 mpls_fib_index_from_table_id(u32 table_id)
#define VLIB_CLI_COMMAND(x,...)
#define hash_create(elts, value_bytes)
#define MPLS_IETF_IPV6_EXPLICIT_NULL_STRING
#define pool_put_index(p, i)
Free pool element with given index.
fib_node_index_t fib_table_entry_path_add2(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, const fib_route_path_t *rpath)
Add n paths to an entry (aka route) in the FIB.
static clib_error_t * vnet_mpls_local_label(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define MPLS_IETF_GAL_LABEL
uword unformat_mpls_label_net_byte_order(unformat_input_t *input, va_list *args)
#define MPLS_IETF_ELI_STRING
u8 * format_mpls_eth_header_with_length(u8 *s, va_list *args)
#define MPLS_IETF_IMPLICIT_NULL_STRING
mpls_encap_t * mpls_encap_by_fib_and_dest(mpls_main_t *mm, u32 rx_fib, u32 dst_address)
u8 * format_fib_protocol(u8 *s, va_list ap)
static clib_error_t * mpls_init(vlib_main_t *vm)
u8 * format_mpls_unicast_header_net_byte_order(u8 *s, va_list *args)
#define FIB_NODE_INDEX_INVALID
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static u32 vnet_mpls_uc_get_s(mpls_label_t label_exp_s_ttl)
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
#define MPLS_IETF_IPV6_EXPLICIT_NULL_LABEL
u8 * format_mpls_eos_bit(u8 *s, va_list *args)
mpls_main_t * mpls_get_main(vlib_main_t *vm)
ip4_main_t ip4_main
Global ip4 main structure.
int mpls_label_cmp(void *a1, void *a2)
#define vec_foreach(var, vec)
Vector iterator.
static u32 vnet_mpls_uc_get_exp(mpls_label_t label_exp_s_ttl)
format_function_t format_mpls_encap_index
#define clib_error_return(e, args...)
u32 frp_fib_index
The FIB index to lookup the nexthop Only valid for recursive paths.
int mpls_fib_index_cmp(void *a1, void *a2)
static clib_error_t * mpls_del_encap_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
u8 * format_mpls_header(u8 *s, va_list *args)
mpls_unicast_header_t * labels
enum mpls_eos_bit_t_ mpls_eos_bit_t