X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=vpp-api-test%2Fvat%2Fapi_format.c;h=71c6f24136aa13e0eb5e5460a0eece20d2235eb4;hb=69a9b76d648a108e0a7fad4404b218ebdd6a8ea5;hp=c7be4e26db5822c4953a43fb1d7d157c3fc72b07;hpb=4a7e58bf481adb843707eec4a81213776a6d5212;p=vpp.git diff --git a/vpp-api-test/vat/api_format.c b/vpp-api-test/vat/api_format.c index c7be4e26db5..71c6f24136a 100644 --- a/vpp-api-test/vat/api_format.c +++ b/vpp-api-test/vat/api_format.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #if DPDK > 0 #include @@ -456,7 +457,7 @@ unformat_policer_action_type (unformat_input_t * input, va_list * va) } uword -unformat_classify_table_type (unformat_input_t * input, va_list * va) +unformat_policer_classify_table_type (unformat_input_t * input, va_list * va) { u32 *r = va_arg (*va, u32 *); u32 tid; @@ -474,6 +475,23 @@ unformat_classify_table_type (unformat_input_t * input, va_list * va) return 1; } +uword +unformat_flow_classify_table_type (unformat_input_t * input, va_list * va) +{ + u32 *r = va_arg (*va, u32 *); + u32 tid; + + if (unformat (input, "ip4")) + tid = FLOW_CLASSIFY_TABLE_IP4; + else if (unformat (input, "ip6")) + tid = FLOW_CLASSIFY_TABLE_IP6; + else + return 0; + + *r = tid; + return 1; +} + u8 * format_ip4_address (u8 * s, va_list * args) { @@ -2584,6 +2602,78 @@ static void vec_free (next_decap_str); } +static void + vl_api_lisp_adjacencies_get_reply_t_handler + (vl_api_lisp_adjacencies_get_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + u32 i, n; + int retval = clib_net_to_host_u32 (mp->retval); + vl_api_lisp_adjacency_t *a; + + if (retval) + goto end; + + n = clib_net_to_host_u32 (mp->count); + + for (i = 0; i < n; i++) + { + a = &mp->adjacencies[i]; + fformat (vam->ofp, "%U %40U\n", + format_lisp_flat_eid, a->eid_type, a->leid, a->leid_prefix_len, + format_lisp_flat_eid, a->eid_type, a->reid, + a->reid_prefix_len); + } + +end: + vam->retval = retval; + vam->result_ready = 1; +} + +static void + vl_api_lisp_adjacencies_get_reply_t_handler_json + (vl_api_lisp_adjacencies_get_reply_t * mp) +{ + u8 *s = 0; + vat_main_t *vam = &vat_main; + vat_json_node_t *e = 0, root; + u32 i, n; + int retval = clib_net_to_host_u32 (mp->retval); + vl_api_lisp_adjacency_t *a; + + if (retval) + goto end; + + n = clib_net_to_host_u32 (mp->count); + vat_json_init_array (&root); + + for (i = 0; i < n; i++) + { + e = vat_json_array_add (&root); + a = &mp->adjacencies[i]; + + vat_json_init_object (e); + s = format (0, "%U", format_lisp_flat_eid, a->eid_type, a->leid, + a->leid_prefix_len); + vec_add1 (s, 0); + vat_json_object_add_string_copy (e, "leid", s); + vec_free (s); + + s = format (0, "%U", format_lisp_flat_eid, a->eid_type, a->reid, + a->reid_prefix_len); + vec_add1 (s, 0); + vat_json_object_add_string_copy (e, "reid", s); + vec_free (s); + } + + vat_json_print (vam->ofp, &root); + vat_json_free (&root); + +end: + vam->retval = retval; + vam->result_ready = 1; +} + static void vl_api_lisp_map_resolver_details_t_handler (vl_api_lisp_map_resolver_details_t * mp) @@ -3370,10 +3460,41 @@ static void vl_api_ipsec_gre_add_del_tunnel_reply_t_handler_json vam->result_ready = 1; } +static void vl_api_flow_classify_details_t_handler + (vl_api_flow_classify_details_t * mp) +{ + vat_main_t *vam = &vat_main; + + fformat (vam->ofp, "%10d%20d\n", ntohl (mp->sw_if_index), + ntohl (mp->table_index)); +} + +static void vl_api_flow_classify_details_t_handler_json + (vl_api_flow_classify_details_t * mp) +{ + vat_main_t *vam = &vat_main; + vat_json_node_t *node; + + if (VAT_JSON_ARRAY != vam->json_tree.type) + { + ASSERT (VAT_JSON_NONE == vam->json_tree.type); + vat_json_init_array (&vam->json_tree); + } + node = vat_json_array_add (&vam->json_tree); + + vat_json_init_object (node); + vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index)); + vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index)); +} + + + #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler +#define vl_api_lisp_adjacencies_get_reply_t_endian vl_noop_handler +#define vl_api_lisp_adjacencies_get_reply_t_print vl_noop_handler /* * Generate boilerplate reply handlers, which @@ -3477,6 +3598,7 @@ _(netmap_delete_reply) \ _(set_ipfix_exporter_reply) \ _(set_ipfix_classify_stream_reply) \ _(ipfix_classify_table_add_del_reply) \ +_(flow_classify_set_interface_reply) \ _(pg_capture_reply) \ _(pg_enable_disable_reply) \ _(ip_source_and_port_range_check_add_del_reply) \ @@ -3677,6 +3799,7 @@ _(LISP_EID_TABLE_MAP_DETAILS, lisp_eid_table_map_details) \ _(LISP_EID_TABLE_VNI_DETAILS, lisp_eid_table_vni_details) \ _(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details) \ _(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details) \ +_(LISP_ADJACENCIES_GET_REPLY, lisp_adjacencies_get_reply) \ _(SHOW_LISP_STATUS_REPLY, show_lisp_status_reply) \ _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY, \ lisp_add_del_map_request_itr_rlocs_reply) \ @@ -3706,6 +3829,8 @@ _(SET_IPFIX_CLASSIFY_STREAM_REPLY, set_ipfix_classify_stream_reply) \ _(IPFIX_CLASSIFY_STREAM_DETAILS, ipfix_classify_stream_details) \ _(IPFIX_CLASSIFY_TABLE_ADD_DEL_REPLY, ipfix_classify_table_add_del_reply) \ _(IPFIX_CLASSIFY_TABLE_DETAILS, ipfix_classify_table_details) \ +_(FLOW_CLASSIFY_SET_INTERFACE_REPLY, flow_classify_set_interface_reply) \ +_(FLOW_CLASSIFY_DETAILS, flow_classify_details) \ _(GET_NEXT_INDEX_REPLY, get_next_index_reply) \ _(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \ _(PG_CAPTURE_REPLY, pg_capture_reply) \ @@ -5642,7 +5767,7 @@ api_ip_add_del_route (vat_main_t * vam) u32 random_seed = 0xdeaddabe; u32 classify_table_index = ~0; u8 is_classify = 0; - u8 resolve_host, resolve_attached; + u8 resolve_host = 0, resolve_attached = 0; /* Parse args required to build the message */ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) @@ -5829,6 +5954,9 @@ api_ip_add_del_route (vat_main_t * vam) } /* send it... */ S; + /* If we receive SIGTERM, stop now... */ + if (vam->do_exit) + break; } /* When testing multiple add/del ops, use a control-ping to sync */ @@ -5861,6 +5989,10 @@ api_ip_add_del_route (vat_main_t * vam) vam->async_errors = 0; after = vat_time_now (vam); + /* slim chance, but we might have eaten SIGTERM on the first iteration */ + if (j > 0) + count = j; + fformat (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n", count, after - before, count / (after - before)); } @@ -7779,16 +7911,147 @@ api_sr_multicast_map_add_del (vat_main_t * vam) } +#define foreach_tcp_proto_field \ +_(src_port) \ +_(dst_port) + +#define foreach_udp_proto_field \ +_(src_port) \ +_(dst_port) + #define foreach_ip4_proto_field \ _(src_address) \ _(dst_address) \ _(tos) \ -_(length) \ +_(length) \ _(fragment_id) \ _(ttl) \ _(protocol) \ _(checksum) +uword +unformat_tcp_mask (unformat_input_t * input, va_list * args) +{ + u8 **maskp = va_arg (*args, u8 **); + u8 *mask = 0; + u8 found_something = 0; + tcp_header_t *tcp; + +#define _(a) u8 a=0; + foreach_tcp_proto_field; +#undef _ + + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (0); +#define _(a) else if (unformat (input, #a)) a=1; + foreach_tcp_proto_field +#undef _ + else + break; + } + +#define _(a) found_something += a; + foreach_tcp_proto_field; +#undef _ + + if (found_something == 0) + return 0; + + vec_validate (mask, sizeof (*tcp) - 1); + + tcp = (tcp_header_t *) mask; + +#define _(a) if (a) memset (&tcp->a, 0xff, sizeof (tcp->a)); + foreach_tcp_proto_field; +#undef _ + + *maskp = mask; + return 1; +} + +uword +unformat_udp_mask (unformat_input_t * input, va_list * args) +{ + u8 **maskp = va_arg (*args, u8 **); + u8 *mask = 0; + u8 found_something = 0; + udp_header_t *udp; + +#define _(a) u8 a=0; + foreach_udp_proto_field; +#undef _ + + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (0); +#define _(a) else if (unformat (input, #a)) a=1; + foreach_udp_proto_field +#undef _ + else + break; + } + +#define _(a) found_something += a; + foreach_udp_proto_field; +#undef _ + + if (found_something == 0) + return 0; + + vec_validate (mask, sizeof (*udp) - 1); + + udp = (udp_header_t *) mask; + +#define _(a) if (a) memset (&udp->a, 0xff, sizeof (udp->a)); + foreach_udp_proto_field; +#undef _ + + *maskp = mask; + return 1; +} + +typedef struct +{ + u16 src_port, dst_port; +} tcpudp_header_t; + +uword +unformat_l4_mask (unformat_input_t * input, va_list * args) +{ + u8 **maskp = va_arg (*args, u8 **); + u16 src_port = 0, dst_port = 0; + tcpudp_header_t *tcpudp; + + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "tcp %U", unformat_tcp_mask, maskp)) + return 1; + else if (unformat (input, "udp %U", unformat_udp_mask, maskp)) + return 1; + else if (unformat (input, "src_port")) + src_port = 0xFFFF; + else if (unformat (input, "dst_port")) + dst_port = 0xFFFF; + else + return 0; + } + + if (!src_port && !dst_port) + return 0; + + u8 *mask = 0; + vec_validate (mask, sizeof (tcpudp_header_t) - 1); + + tcpudp = (tcpudp_header_t *) mask; + tcpudp->src_port = src_port; + tcpudp->dst_port = dst_port; + + *maskp = mask; + + return 1; +} + uword unformat_ip4_mask (unformat_input_t * input, va_list * args) { @@ -8066,6 +8329,7 @@ unformat_classify_mask (unformat_input_t * input, va_list * args) u8 *mask = 0; u8 *l2 = 0; u8 *l3 = 0; + u8 *l4 = 0; int i; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) @@ -8076,13 +8340,23 @@ unformat_classify_mask (unformat_input_t * input, va_list * args) ; else if (unformat (input, "l3 %U", unformat_l3_mask, &l3)) ; + else if (unformat (input, "l4 %U", unformat_l4_mask, &l4)) + ; else break; } - if (mask || l2 || l3) + if (l4 && !l3) { - if (l2 || l3) + vec_free (mask); + vec_free (l2); + vec_free (l4); + return 0; + } + + if (mask || l2 || l3 || l4) + { + if (l2 || l3 || l4) { /* "With a free Ethernet header in every package" */ if (l2 == 0) @@ -8093,6 +8367,11 @@ unformat_classify_mask (unformat_input_t * input, va_list * args) vec_append (mask, l3); vec_free (l3); } + if (vec_len (l4)) + { + vec_append (mask, l4); + vec_free (l4); + } } /* Scan forward looking for the first significant mask octet */ @@ -8332,6 +8611,37 @@ api_classify_add_del_table (vat_main_t * vam) /* NOTREACHED */ } +uword +unformat_l4_match (unformat_input_t * input, va_list * args) +{ + u8 **matchp = va_arg (*args, u8 **); + + u8 *proto_header = 0; + int src_port = 0; + int dst_port = 0; + + tcpudp_header_t h; + + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "src_port %d", &src_port)) + ; + else if (unformat (input, "dst_port %d", &dst_port)) + ; + else + return 0; + } + + h.src_port = clib_host_to_net_u16 (src_port); + h.dst_port = clib_host_to_net_u16 (dst_port); + vec_validate (proto_header, sizeof (h) - 1); + memcpy (proto_header, &h, sizeof (h)); + + *matchp = proto_header; + + return 1; +} + uword unformat_ip4_match (unformat_input_t * input, va_list * args) { @@ -8416,13 +8726,13 @@ unformat_ip4_match (unformat_input_t * input, va_list * args) ip->tos = tos_val; if (length) - ip->length = length_val; + ip->length = clib_host_to_net_u16 (length_val); if (ttl) ip->ttl = ttl_val; if (checksum) - ip->checksum = checksum_val; + ip->checksum = clib_host_to_net_u16 (checksum_val); *matchp = match; return 1; @@ -8677,6 +8987,7 @@ unformat_classify_match (unformat_input_t * input, va_list * args) u8 *match = 0; u8 *l2 = 0; u8 *l3 = 0; + u8 *l4 = 0; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { @@ -8686,13 +8997,23 @@ unformat_classify_match (unformat_input_t * input, va_list * args) ; else if (unformat (input, "l3 %U", unformat_l3_match, &l3)) ; + else if (unformat (input, "l4 %U", unformat_l4_match, &l4)) + ; else break; } - if (match || l2 || l3) + if (l4 && !l3) + { + vec_free (match); + vec_free (l2); + vec_free (l4); + return 0; + } + + if (match || l2 || l3 || l4) { - if (l2 || l3) + if (l2 || l3 || l4) { /* "Win a free Ethernet header in every packet" */ if (l2 == 0) @@ -8703,6 +9024,11 @@ unformat_classify_match (unformat_input_t * input, va_list * args) vec_append_aligned (match, l3, sizeof (u32x4)); vec_free (l3); } + if (vec_len (l4)) + { + vec_append_aligned (match, l4, sizeof (u32x4)); + vec_free (l4); + } } /* Make sure the vector is big enough even if key is all 0's */ @@ -13634,6 +13960,52 @@ api_lisp_gpe_tunnel_dump (vat_main_t * vam) return 0; } +static int +api_lisp_adjacencies_get (vat_main_t * vam) +{ + unformat_input_t *i = vam->input; + vl_api_lisp_adjacencies_get_t *mp; + f64 timeout = ~0; + u8 vni_set = 0; + u32 vni = ~0; + + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "vni %d", &vni)) + { + vni_set = 1; + } + else + { + errmsg ("parse error '%U'\n", format_unformat_error, i); + return -99; + } + } + + if (!vni_set) + { + errmsg ("vni not set!\n"); + return -99; + } + + if (!vam->json_output) + { + fformat (vam->ofp, "%s %40s\n", "leid", "reid"); + } + + M (LISP_ADJACENCIES_GET, lisp_adjacencies_get); + mp->vni = clib_host_to_net_u32 (vni); + + /* send it... */ + S; + + /* Wait for a reply... */ + W; + + /* NOTREACHED */ + return 0; +} + static int api_lisp_map_resolver_dump (vat_main_t * vam) { @@ -13992,7 +14364,7 @@ api_policer_classify_dump (vat_main_t * vam) f64 timeout = ~0; u8 type = POLICER_CLASSIFY_N_TABLES; - if (unformat (i, "type %U", unformat_classify_table_type, &type)) + if (unformat (i, "type %U", unformat_policer_classify_table_type, &type)) ; else { @@ -15348,6 +15720,95 @@ api_l2_interface_pbb_tag_rewrite (vat_main_t * vam) return 0; } +static int +api_flow_classify_set_interface (vat_main_t * vam) +{ + unformat_input_t *i = vam->input; + vl_api_flow_classify_set_interface_t *mp; + f64 timeout; + u32 sw_if_index; + int sw_if_index_set; + u32 ip4_table_index = ~0; + u32 ip6_table_index = ~0; + u8 is_add = 1; + + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "del")) + is_add = 0; + else if (unformat (i, "ip4-table %d", &ip4_table_index)) + ; + else if (unformat (i, "ip6-table %d", &ip6_table_index)) + ; + else + { + clib_warning ("parse error '%U'", format_unformat_error, i); + return -99; + } + } + + if (sw_if_index_set == 0) + { + errmsg ("missing interface name or sw_if_index\n"); + return -99; + } + + M (FLOW_CLASSIFY_SET_INTERFACE, flow_classify_set_interface); + + mp->sw_if_index = ntohl (sw_if_index); + mp->ip4_table_index = ntohl (ip4_table_index); + mp->ip6_table_index = ntohl (ip6_table_index); + mp->is_add = is_add; + + S; + W; + /* NOTREACHED */ + return 0; +} + +static int +api_flow_classify_dump (vat_main_t * vam) +{ + unformat_input_t *i = vam->input; + vl_api_flow_classify_dump_t *mp; + f64 timeout = ~0; + u8 type = FLOW_CLASSIFY_N_TABLES; + + if (unformat (i, "type %U", unformat_flow_classify_table_type, &type)) + ; + else + { + errmsg ("classify table type must be specified\n"); + return -99; + } + + if (!vam->json_output) + { + fformat (vam->ofp, "%10s%20s\n", "Intfc idx", "Classify table"); + } + + M (FLOW_CLASSIFY_DUMP, flow_classify_dump); + mp->type = type; + /* send it... */ + S; + + /* Use a control ping for synchronization */ + { + vl_api_control_ping_t *mp; + M (CONTROL_PING, control_ping); + S; + } + /* Wait for a reply... */ + W; + + /* NOTREACHED */ + return 0; +} + static int q_or_quit (vat_main_t * vam) { @@ -15897,6 +16358,7 @@ _(lisp_eid_table_vni_dump, "") \ _(lisp_eid_table_map_dump, "l2|l3") \ _(lisp_gpe_tunnel_dump, "") \ _(lisp_map_resolver_dump, "") \ +_(lisp_adjacencies_get, "vni ") \ _(show_lisp_status, "") \ _(lisp_get_map_request_itr_rlocs, "") \ _(show_lisp_pitr, "") \ @@ -15945,7 +16407,10 @@ _(l2_interface_pbb_tag_rewrite, \ " | sw_if_index \n" \ "[disable | push | pop | translate_pbb_stag ] \n" \ "dmac smac sid [vlanid ]") \ -_(punt, "protocol [ip ] [port ] [del]") +_(punt, "protocol [ip ] [port ] [del]") \ +_(flow_classify_set_interface, \ + " | sw_if_index [ip4-table ] [ip6-table ] [del]") \ +_(flow_classify_dump, "type [ip4|ip6]") /* List of command functions, CLI names map directly to functions */ #define foreach_cli_function \