31 s =
format (s,
"MPLS: lookup miss");
34 s =
format (s,
"MPLS: tunnel %d labels %U len %d src %U dst %U",
37 clib_net_to_host_u16 (t->
length),
52 s =
format (s,
"MPLS: lookup miss");
55 s =
format (s,
"MPLS: tunnel %d labels %U len %d tx_sw_index %d dst %U",
58 clib_net_to_host_u16 (t->
length),
69 u32 max_header_bytes = va_arg (*args,
u32);
72 header_bytes =
sizeof (h[0]);
73 if (max_header_bytes != 0 && header_bytes > max_header_bytes)
74 return format (s,
"ethernet header truncated");
77 (s,
"ETHERNET-MPLS label %d",
87 u32 max_header_bytes = va_arg (*args,
u32);
90 header_bytes =
sizeof (h[0]);
91 if (max_header_bytes != 0 && header_bytes > max_header_bytes)
92 return format (s,
"gre header truncated");
95 (s,
"GRE-MPLS label %d",
110 u8 ** result = va_arg (*args,
u8 **);
113 u32 label, label_exp_s_ttl;
115 if (!
unformat (input,
"MPLS %d", &label))
118 g->
protocol = clib_host_to_net_u16 (GRE_PROTOCOL_mpls_unicast);
120 label_exp_s_ttl = (label<<12) | (1<<8) | 0xFF;
126 u32 g_n_bytes =
sizeof (g[0]);
127 u32 h_n_bytes =
sizeof (h[0]);
143 u32 * result = va_arg (*args,
u32 *);
146 if (!
unformat (input,
"MPLS: label %d", &label))
149 label = (label<<12) | (1<<8) | 0xFF ;
151 *result = clib_host_to_net_u32 (label);
162 key = ((
u64)rx_fib<<32) | ((
u64) dst_address);
173 u32 *labels_host_byte_order,
174 u32 policy_tunnel_index,
175 int no_dst_hash,
u32 * indexp,
int is_add)
180 u32 label_net_byte_order, label_host_byte_order;
188 return VNET_API_ERROR_NO_SUCH_FIB;
197 memset (e, 0,
sizeof (*e));
199 for (i = 0; i <
vec_len (labels_host_byte_order); i++)
202 label_host_byte_order = labels_host_byte_order[
i];
205 label_host_byte_order <<= 12;
206 if (i ==
vec_len(labels_host_byte_order) - 1)
207 label_host_byte_order |= 1<<8;
208 label_host_byte_order |= 0xff;
209 label_net_byte_order = clib_host_to_net_u32 (label_host_byte_order);
213 if (no_dst_hash == 0)
217 if (policy_tunnel_index != ~0)
224 return VNET_API_ERROR_NO_SUCH_LABEL;
232 if (no_dst_hash == 0)
247 u32 policy_tunnel_index = ~0;
255 if (
unformat (input,
"fib %d", &fib_id))
259 else if (
unformat (input,
"no-dst-hash"))
261 else if (
unformat (input,
"label %d", &this_label))
263 else if (
unformat (input,
"policy-tunnel %d", &policy_tunnel_index))
287 case VNET_API_ERROR_NO_SUCH_FIB:
299 .path =
"mpls encap add",
301 "mpls encap add label <label> ... fib <id> dest <ip4-address>",
310 s =
format (s,
"label %d exp %d, s %d, ttl %d",
338 if (
unformat (input,
"fib %d dest %U", &fib_id,
348 case VNET_API_ERROR_NO_SUCH_FIB:
350 case VNET_API_ERROR_NO_SUCH_ENTRY:
364 .path =
"mpls encap delete",
365 .short_help =
"mpls encap delete fib <id> dest <ip4-address>",
371 u32 label_host_byte_order,
372 int s_bit,
int next_index,
int is_add)
377 u32 rx_fib_index, tx_fib_index_or_output_swif_index;
383 return VNET_API_ERROR_NO_SUCH_FIB;
388 if (next_index == MPLS_INPUT_NEXT_IP4_INPUT)
392 return VNET_API_ERROR_NO_SUCH_INNER_FIB;
394 tx_fib_index_or_output_swif_index = p[0];
399 tx_fib_index_or_output_swif_index = tx_fib_id;
402 key = ((
u64) rx_fib_index<<32) | ((
u64) label_host_byte_order<<12)
408 if (is_add == 0 || p)
410 if (is_add == 0 && p == 0)
411 return VNET_API_ERROR_NO_SUCH_LABEL;
423 memset (d, 0,
sizeof (*d));
435 u32 * result = va_arg (*args,
u32 *);
440 *result = MPLS_INPUT_NEXT_IP4_INPUT;
443 else if (
unformat (input,
"output"))
445 *result = MPLS_INPUT_NEXT_L2_OUTPUT;
458 u32 tx_fib_or_sw_if_index;
462 int tx_fib_id_set = 0;
468 if (
unformat (input,
"fib %d", &tx_fib_or_sw_if_index))
470 else if (
unformat (input,
"sw_if_index %d", &tx_fib_or_sw_if_index))
473 &tx_fib_or_sw_if_index))
475 else if (
unformat (input,
"rx-fib %d", &rx_fib_id))
477 else if (
unformat (input,
"label %d", &label))
479 else if (
unformat (input,
"s-bit-clear"))
488 if (tx_fib_id_set == 0)
494 label, s_bit, next_index, 1 );
500 case VNET_API_ERROR_NO_SUCH_FIB:
503 case VNET_API_ERROR_NO_SUCH_INNER_FIB:
505 tx_fib_or_sw_if_index);
515 .path =
"mpls decap add",
517 "mpls decap add fib <id> label <nn> [s-bit-clear] [next-index <nn>]",
535 if (
unformat (input,
"rx-fib %d", &rx_fib_id))
537 else if (
unformat (input,
"label %d", &label))
539 else if (
unformat (input,
"s-bit-clear"))
556 case VNET_API_ERROR_NO_SUCH_FIB:
559 case VNET_API_ERROR_NO_SUCH_INNER_FIB:
562 case VNET_API_ERROR_NO_SUCH_LABEL:
575 .path =
"mpls decap delete",
576 .short_help =
"mpls decap delete label <label> rx-fib <id> [s-bit-clear]",
586 return clib_net_to_host_u32(r1->
dest) - clib_net_to_host_u32(r2->
dest);
624 vec_add2 (records, s, 1);
625 s->fib_index = (u32)(key>>32);
626 s->dest = (u32)(key & 0xFFFFFFFF);
627 s->entry_index = (u32) value;
639 vlib_cli_output (vm,
"%=6s%=16s%=16s",
"Table",
"Dest address",
"Labels");
653 vec_add2 (records, s, 1);
654 s->fib_index = (u32)(key>>32);
655 s->entry_index = (u32) value;
656 s->label = ((u32) key)>>12;
657 s->s_bit = (key & (1<<8)) != 0;
669 vlib_cli_output (vm,
"%=10s%=15s%=6s%=6s",
"RX Table",
"TX Table/Intfc",
675 if (d->
next_index == MPLS_INPUT_NEXT_IP4_INPUT)
698 .path =
"show mpls fib",
699 .short_help =
"show mpls fib",
716 return VNET_API_ERROR_NO_SUCH_FIB;
722 if (fib_index == (u32)(key>>32)) {
723 vec_add2 (records, s, 1);
724 s->dest = (u32)(key & 0xFFFFFFFF);
725 s->entry_index = (u32) value;
731 key = ((
u64)fib_index<<32) | ((
u64) s->dest);
732 hash_unset (mm->mpls_encap_by_fib_and_dest, key);
738 hash_foreach (key, value, mm->mpls_decap_by_rx_fib_and_label,
740 if (fib_index == (u32) (key>>32)) {
741 vec_add2 (records, s, 1);
742 s->entry_index = value;
743 s->fib_index = fib_index;
744 s->s_bit = key & (1<<8);
745 s->dest = (u32)((key & 0xFFFFFFFF)>>12);
751 key = ((
u64) fib_index <<32) | ((
u64) s->dest<<12) |
754 hash_unset (mm->mpls_decap_by_rx_fib_and_label, key);
767 memset (mm, 0,
sizeof (mm[0]));
#define hash_set(h, key, value)
sll srl srl sll sra u16x4 i
static clib_error_t * mpls_del_decap_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static u32 vnet_mpls_uc_get_label(u32 label_exp_s_ttl)
#define hash_unset(h, key)
static clib_error_t * mpls_input_init(vlib_main_t *vm)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
#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_header_host_byte_order(u8 *s, va_list *args)
unformat_function_t unformat_vnet_sw_interface
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 u32 vnet_mpls_uc_get_s(u32 label_exp_s_ttl)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
uword unformat_mpls_gre_input_next(unformat_input_t *input, va_list *args)
static clib_error_t * mpls_add_encap_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
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 VLIB_INIT_FUNCTION(x)
int mpls_fib_reset_labels(u32 fib_id)
#define hash_foreach(key_var, value_var, h, body)
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
static clib_error_t * show_mpls_fib_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define vlib_call_init_function(vm, x)
static u32 vnet_mpls_uc_get_exp(u32 label_exp_s_ttl)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
uword * fib_index_by_table_id
Hash table mapping table id to fib index.
static u32 vnet_mpls_uc_get_ttl(u32 label_exp_s_ttl)
#define pool_put(P, E)
Free an object E in pool P.
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
clib_error_t * ip_main_init(vlib_main_t *vm)
#define vec_free(V)
Free vector's memory (no header).
#define clib_memcpy(a, b, c)
int vnet_mpls_add_del_decap(u32 rx_fib_id, u32 tx_fib_id, u32 label_host_byte_order, int s_bit, int next_index, int is_add)
u8 * format_mpls_gre_header_with_length(u8 *s, va_list *args)
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)
#define hash_create(elts, value_bytes)
#define pool_put_index(p, i)
Free pool element with given index.
ip4_fib_t * fibs
Vector of FIBs.
uword unformat_mpls_label_net_byte_order(unformat_input_t *input, va_list *args)
uword * mpls_decap_by_rx_fib_and_label
uword unformat_mpls_gre_header(unformat_input_t *input, va_list *args)
int vnet_mpls_policy_tunnel_add_rewrite(mpls_main_t *mm, mpls_encap_t *e, u32 policy_tunnel_index)
u8 * format_mpls_eth_header_with_length(u8 *s, va_list *args)
mpls_encap_t * mpls_encap_by_fib_and_dest(mpls_main_t *mm, u32 rx_fib, u32 dst_address)
static clib_error_t * mpls_init(vlib_main_t *vm)
u8 * format_mpls_unicast_header_net_byte_order(u8 *s, va_list *args)
VLIB_CLI_COMMAND(set_interface_ip_source_and_port_range_check_command, static)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
u8 * format_mpls_gre_header(u8 *s, va_list *args)
u8 * format_mpls_gre_tx_trace(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.
format_function_t format_mpls_encap_index
#define clib_error_return(e, args...)
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)
static clib_error_t * mpls_add_decap_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
mpls_unicast_header_t * labels