32 else if (
unformat (input,
"%u/%u", &port, &mask))
34 else if (
unformat (input,
"%u/0x%x", &port, &mask))
36 else if (
unformat (input,
"%u", &port))
41 if (port > 0xffff || mask > 0xffff)
57 if (pm->
mask == 0xffff)
66 int error = va_arg (*args,
int);
69 return format (s,
"no error");
71 #define _(v,n,str) if (error == v) return format (s, #str); 75 return format (s,
"unknown error (%d)", error);
81 u32 actions = va_arg (*args,
u32);
84 #define _(a, b, c) if (actions & (1 << a)) \ 85 t = format (t, "%s%s", t ? " ":"", c); 96 u32 flow_index = va_arg (*args,
u32);
99 return format (s,
"not found");
108 t = format (t,
"%s%U", t ?
", " :
"",
109 format_vnet_hw_if_index_name, vnm, hw_if_index);
134 u32 index = ~0, hw_if_index;
141 if (
unformat (line_input,
"index %u", &index))
161 hi = vnet_get_hw_interface (vnm, hw_if_index);
162 dev_class = vnet_get_device_class (vnm, hi->dev_class_index);
163 vlib_cli_output (vm,
"interface %U\n",
164 format_vnet_hw_if_index_name, vnm, hw_if_index);
165 if (dev_class->format_flow)
166 vlib_cli_output (vm,
" %U\n", dev_class->format_flow,
167 hi->dev_instance, f->index, private_data);
177 vlib_cli_output (vm,
"%U\n", format_flow, f);
186 .path =
"show flow entry",
187 .short_help =
"show flow entry [index <index>]",
212 .path =
"show flow ranges",
213 .short_help =
"show flow ranges",
226 u32 hw_if_index = ~0;
242 if (hw_if_index == ~0)
247 if (dev_class->format_flow == 0)
256 .path =
"show flow interface",
257 .short_help =
"show flow interface <interface name>",
276 }
action = FLOW_UNKNOWN_ACTION;
277 u32 hw_if_index = ~0, flow_index = ~0;
281 bool is_gtpc_set =
false;
282 bool is_gtpu_set =
false;
283 bool is_l2tpv3oip_set =
false;
286 bool outer_ip4_set =
false, inner_ip4_set =
false;
287 bool outer_ip6_set =
false, inner_ip6_set =
false;
299 bool ethernet_set =
false;
300 u8 *rss_type[3] = { };
306 flow.ip4_n_tuple.protocol = ~0;
314 else if (
unformat (line_input,
"del"))
316 else if (
unformat (line_input,
"enable"))
317 action = FLOW_ENABLE;
318 else if (
unformat (line_input,
"disable"))
319 action = FLOW_DISABLE;
320 else if (
unformat (line_input,
"eth-type %U",
323 else if (
unformat (line_input,
"src-ip %U",
325 outer_ip4_set =
true;
326 else if (
unformat (line_input,
"dst-ip %U",
328 outer_ip4_set =
true;
329 else if (
unformat (line_input,
"ip6-src-ip %U",
331 outer_ip6_set =
true;
332 else if (
unformat (line_input,
"ip6-dst-ip %U",
334 outer_ip6_set =
true;
335 else if (
unformat (line_input,
"inner-src-ip %U",
337 inner_ip4_set =
true;
338 else if (
unformat (line_input,
"inner-dst-ip %U",
340 inner_ip4_set =
true;
341 else if (
unformat (line_input,
"inner-ip6-src-ip %U",
343 inner_ip6_set =
true;
344 else if (
unformat (line_input,
"inner-ip6-dst-ip %U",
346 inner_ip6_set =
true;
355 else if (
unformat (line_input,
"proto %u", &prot))
357 else if (
unformat (line_input,
"gtpc teid %u", &teid))
359 else if (
unformat (line_input,
"gtpu teid %u", &teid))
363 if (prot == IP_PROTOCOL_L2TP)
364 is_l2tpv3oip_set =
true;
366 else if (
unformat (line_input,
"index %u", &flow_index))
370 flow.
actions |= VNET_FLOW_ACTION_REDIRECT_TO_NODE;
372 flow.
actions |= VNET_FLOW_ACTION_MARK;
373 else if (
unformat (line_input,
"buffer-advance %d",
375 flow.
actions |= VNET_FLOW_ACTION_BUFFER_ADVANCE;
376 else if (
unformat (line_input,
"redirect-to-queue %d",
378 flow.
actions |= VNET_FLOW_ACTION_REDIRECT_TO_QUEUE;
379 else if (
unformat (line_input,
"drop"))
380 flow.
actions |= VNET_FLOW_ACTION_DROP;
381 else if (
unformat (line_input,
"rss function"))
387 else if (unformat (line_input, s)) \ 388 flow.rss_fun = VNET_RSS_FUNC_##f; 398 flow.
actions |= VNET_FLOW_ACTION_RSS;
400 else if (
unformat (line_input,
"rss types"))
407 if (
unformat (line_input,
"%s use %s and %s",
408 &rss_type[0], &rss_type[1], &rss_type[2]))
412 (line_input,
"%s use %s", &rss_type[0], &rss_type[1]))
414 else if (
unformat (line_input,
"%s", &rss_type[0]))
419 else if (!clib_strcmp(c, (const char *)type_str)) \ 420 flow.rss_types |= (1ULL<<a); 422 #define check_rss_types(_str) \ 427 foreach_flow_rss_types \ 430 return clib_error_return (0, "parse error: '%U'", \ 431 format_unformat_error, line_input); \ 438 flow.
actions |= VNET_FLOW_ACTION_RSS;
450 if (hw_if_index == ~0 && (action == FLOW_ENABLE || action == FLOW_DISABLE))
453 if (flow_index == ~0 && (action == FLOW_ENABLE || action == FLOW_DISABLE ||
464 if (ethernet_set ==
true)
465 outer_type = VNET_FLOW_TYPE_ETHERNET;
466 if (outer_ip4_set ==
true)
467 outer_type = VNET_FLOW_TYPE_IP4_N_TUPLE;
468 else if (outer_ip6_set ==
true)
469 outer_type = VNET_FLOW_TYPE_IP6_N_TUPLE;
470 if (inner_ip4_set ==
true)
471 inner_type = VNET_FLOW_TYPE_IP4_N_TUPLE;
472 else if (inner_ip6_set ==
true)
473 inner_type = VNET_FLOW_TYPE_IP6_N_TUPLE;
478 if (outer_type == VNET_FLOW_TYPE_ETHERNET)
479 type = VNET_FLOW_TYPE_ETHERNET;
480 else if (outer_type == VNET_FLOW_TYPE_IP4_N_TUPLE)
482 type = VNET_FLOW_TYPE_IP4_N_TUPLE;
487 type = VNET_FLOW_TYPE_IP4_GTPC;
488 else if (is_gtpu_set)
489 type = VNET_FLOW_TYPE_IP4_GTPU;
490 else if (is_l2tpv3oip_set)
491 type = VNET_FLOW_TYPE_IP4_L2TPV3OIP;
493 else if (inner_type == VNET_FLOW_TYPE_IP4_N_TUPLE)
496 type = VNET_FLOW_TYPE_IP4_GTPU_IP4;
498 else if (inner_type == VNET_FLOW_TYPE_IP6_N_TUPLE)
501 type = VNET_FLOW_TYPE_IP4_GTPU_IP6;
504 else if (outer_type == VNET_FLOW_TYPE_IP6_N_TUPLE)
506 type = VNET_FLOW_TYPE_IP6_N_TUPLE;
511 type = VNET_FLOW_TYPE_IP6_GTPC;
512 else if (is_gtpu_set)
513 type = VNET_FLOW_TYPE_IP6_GTPU;
515 else if (inner_type == VNET_FLOW_TYPE_IP4_N_TUPLE)
518 type = VNET_FLOW_TYPE_IP6_GTPU_IP4;
520 else if (inner_type == VNET_FLOW_TYPE_IP6_N_TUPLE)
523 type = VNET_FLOW_TYPE_IP6_GTPU_IP6;
530 case VNET_FLOW_TYPE_ETHERNET:
531 memset (&flow.ethernet, 0, sizeof (flow.ethernet));
532 flow.ethernet.eth_hdr.
type = eth_type;
534 case VNET_FLOW_TYPE_IP4_L2TPV3OIP:
539 flow.ip4_l2tpv3oip.protocol = prot;
542 case VNET_FLOW_TYPE_IP4_N_TUPLE:
543 case VNET_FLOW_TYPE_IP4_GTPC:
544 case VNET_FLOW_TYPE_IP4_GTPU:
545 case VNET_FLOW_TYPE_IP4_GTPU_IP4:
546 case VNET_FLOW_TYPE_IP4_GTPU_IP6:
555 flow.ip4_n_tuple.protocol = prot;
557 if (type == VNET_FLOW_TYPE_IP4_GTPC)
558 flow.ip4_gtpc.teid = teid;
559 else if (type == VNET_FLOW_TYPE_IP4_GTPU)
560 flow.ip4_gtpu.teid = teid;
561 else if (type == VNET_FLOW_TYPE_IP4_GTPU_IP4)
563 flow.ip4_gtpu_ip4.teid = teid;
564 clib_memcpy (&flow.ip4_gtpu_ip4.inner_src_addr, &inner_ip4s,
566 clib_memcpy (&flow.ip4_gtpu_ip4.inner_dst_addr, &inner_ip4d,
569 else if (type == VNET_FLOW_TYPE_IP4_GTPU_IP6)
571 flow.ip4_gtpu_ip6.teid = teid;
572 clib_memcpy (&flow.ip4_gtpu_ip6.inner_src_addr, &inner_ip6s,
574 clib_memcpy (&flow.ip4_gtpu_ip6.inner_dst_addr, &inner_ip6d,
580 if ((type != VNET_FLOW_TYPE_IP4_N_TUPLE) &&
581 (flow.ip4_n_tuple.protocol != IP_PROTOCOL_UDP))
583 "For GTP related flow, ip protocol must be UDP");
586 case VNET_FLOW_TYPE_IP6_N_TUPLE:
587 case VNET_FLOW_TYPE_IP6_GTPC:
588 case VNET_FLOW_TYPE_IP6_GTPU:
589 case VNET_FLOW_TYPE_IP6_GTPU_IP4:
590 case VNET_FLOW_TYPE_IP6_GTPU_IP6:
599 flow.ip6_n_tuple.protocol = prot;
601 if (type == VNET_FLOW_TYPE_IP6_GTPC)
602 flow.ip6_gtpc.teid = teid;
603 else if (type == VNET_FLOW_TYPE_IP6_GTPU)
604 flow.ip6_gtpu.teid = teid;
605 else if (type == VNET_FLOW_TYPE_IP6_GTPU_IP4)
607 flow.ip6_gtpu_ip4.teid = teid;
608 clib_memcpy (&flow.ip6_gtpu_ip4.inner_src_addr, &inner_ip4s,
610 clib_memcpy (&flow.ip6_gtpu_ip4.inner_dst_addr, &inner_ip4d,
613 else if (type == VNET_FLOW_TYPE_IP6_GTPU_IP6)
615 flow.ip6_gtpu_ip6.teid = teid;
616 clib_memcpy (&flow.ip6_gtpu_ip6.inner_src_addr, &inner_ip6s,
618 clib_memcpy (&flow.ip6_gtpu_ip6.inner_dst_addr, &inner_ip6d,
624 if ((type != VNET_FLOW_TYPE_IP6_N_TUPLE) &&
625 (flow.ip6_n_tuple.protocol != IP_PROTOCOL_UDP))
627 "For GTP related flow, ip protocol must be UDP");
637 printf (
"flow %u added\n", flow_index);
662 .short_help =
"test flow add [src-ip <ip-addr/mask>] [dst-ip " 663 "<ip-addr/mask>] [src-port <port/mask>] [dst-port <port/mask>] " 673 char *
type = va_arg (*args,
char *);
674 void *ptr = va_arg (*args,
void *);
676 if (strncmp (type,
"u8", 2) == 0)
677 return format (s,
"%d", *(
u8 *) ptr);
679 if (strncmp (type,
"u16", 3) == 0)
682 if (strncmp (type,
"u32", 3) == 0)
685 if (strncmp (type,
"ip4_address_t", 13) == 0)
688 if (strncmp (type,
"ip4_address_and_mask_t", 13) == 0)
691 if (strncmp (type,
"ip6_address_t", 13) == 0)
694 if (strncmp (type,
"ip6_address_and_mask_t", 13) == 0)
697 if (strncmp (type,
"ip_protocol_t", 13) == 0)
700 if (strncmp (type,
"ip_port_and_mask_t", 18) == 0)
703 s =
format (s,
"unknown type '%s'", type);
707 #define _fe(a,b) s2 = format (s2, "%s%s %U", s2 ? ", ":"", #b, \ 708 format_flow_match_element, #a, &f->b); 710 u8 * format_flow_match_##b (u8 * s, va_list * args) \ 712 vnet_flow_##b##_t *f = __builtin_va_arg (*args, vnet_flow_##b##_t *); \ 714 foreach_flow_entry_##b \ 715 s = format (s, "%v", s2);; \ 728 if (f->type == VNET_FLOW_TYPE_##a) \ 729 return format (s, "%U", format_flow_match_##b, &f->b); 744 s =
format (s,
"flow-index %u type %s active %u",
752 if (f->
actions & VNET_FLOW_ACTION_MARK)
755 if (f->
actions & VNET_FLOW_ACTION_REDIRECT_TO_NODE)
756 t =
format (t,
"%snext-node %U", t ?
", " :
"",
759 if (f->
actions & VNET_FLOW_ACTION_BUFFER_ADVANCE)
unformat_function_t unformat_vnet_hw_interface
format_function_t format_vlib_node_name
vnet_main_t * vnet_get_main(void)
#define foreach_rss_function
u8 * format_flow_actions(u8 *s, va_list *args)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
static clib_error_t * test_flow(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd_arg)
vnet_flow_t * global_flow_pool
u8 * format_flow_error(u8 *s, va_list *args)
struct _vnet_device_class vnet_device_class_t
int vnet_flow_disable(vnet_main_t *vnm, u32 flow_index, u32 hw_if_index)
static clib_error_t * show_flow_entry(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd_arg)
#define clib_memcpy(d, s, n)
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
static vnet_device_class_t * vnet_get_device_class(vnet_main_t *vnm, u32 dev_class_index)
static format_function_t format_flow
#define hash_foreach(key_var, value_var, h, body)
static u8 * format_flow_match_element(u8 *s, va_list *args)
#define clib_error_return(e, args...)
vnet_flow_main_t flow_main
vnet_flow_range_t * ranges
vl_api_fib_path_type_t type
int vnet_flow_del(vnet_main_t *vnm, u32 flow_index)
enum ip_protocol ip_protocol_t
static clib_error_t * show_flow_ranges(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd_arg)
vnet_flow_t * vnet_get_flow(u32 flow_index)
u8 * format_ip_port_and_mask(u8 *s, va_list *args)
#define vec_free(V)
Free vector's memory (no header).
u8 * format_flow_enabled_hw(u8 *s, va_list *args)
#define check_rss_types(_str)
#define VLIB_CLI_COMMAND(x,...)
static const char * flow_type_strings[]
static uword hash_elts(void *v)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
uword unformat_ip_port_and_mask(unformat_input_t *input, va_list *args)
static foreach_flow_type u8 * format_flow_match(u8 *s, va_list *args)
int vnet_flow_add(vnet_main_t *vnm, vnet_flow_t *flow, u32 *flow_index)
static vlib_main_t * vlib_get_main(void)
static clib_error_t * show_flow_interface(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd_arg)
uword unformat_ethernet_type_host_byte_order(unformat_input_t *input, va_list *args)
vl_api_mac_event_action_t action
int vnet_flow_enable(vnet_main_t *vnm, u32 flow_index, u32 hw_if_index)
unformat_function_t unformat_vlib_node
#define vec_foreach(var, vec)
Vector iterator.