X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=vpp-api-test%2Fvat%2Fapi_format.c;h=b6f09021d5b9bed99ffdea1d7f3cd87049c86d16;hb=060c6fc0b54c909db56856b4d3e3fa65265f5871;hp=352a78a6a4a604dcd2164d1f8c7186daa72e904c;hpb=317be0349275f1f461028853d936670729591796;p=vpp.git diff --git a/vpp-api-test/vat/api_format.c b/vpp-api-test/vat/api_format.c index 352a78a6a4a..b6f09021d5b 100644 --- a/vpp-api-test/vat/api_format.c +++ b/vpp-api-test/vat/api_format.c @@ -34,8 +34,13 @@ #include #include #include +#if DPDK > 0 #include +#else +#include +#endif #include +#include #include "vat/json_format.h" @@ -228,6 +233,7 @@ uword unformat_ip6_address (unformat_input_t * input, va_list * args) uword unformat_ipsec_policy_action (unformat_input_t * input, va_list * args) { +#if DPDK > 0 u32 * r = va_arg (*args, u32 *); if (0) ; @@ -237,11 +243,15 @@ unformat_ipsec_policy_action (unformat_input_t * input, va_list * args) else return 0; return 1; +#else + return 0; +#endif } uword unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args) { +#if DPDK > 0 u32 * r = va_arg (*args, u32 *); if (0) ; @@ -251,11 +261,15 @@ unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args) else return 0; return 1; +#else + return 0; +#endif } u8 * format_ipsec_crypto_alg (u8 * s, va_list * args) { +#if DPDK > 0 u32 i = va_arg (*args, u32); u8 * t = 0; @@ -268,11 +282,15 @@ format_ipsec_crypto_alg (u8 * s, va_list * args) return format (s, "unknown"); } return format (s, "%s", t); +#else + return format (s, "Unimplemented"); +#endif } uword unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args) { +#if DPDK > 0 u32 * r = va_arg (*args, u32 *); if (0) ; @@ -282,11 +300,15 @@ unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args) else return 0; return 1; +#else + return 0; +#endif } u8 * format_ipsec_integ_alg (u8 * s, va_list * args) { +#if DPDK > 0 u32 i = va_arg (*args, u32); u8 * t = 0; @@ -299,6 +321,9 @@ format_ipsec_integ_alg (u8 * s, va_list * args) return format (s, "unknown"); } return format (s, "%s", t); +#else + return format (s, "Unsupported"); +#endif } u8 * format_ip4_address (u8 * s, va_list * args) @@ -562,6 +587,7 @@ static void vl_api_sw_interface_details_t_handler_json vat_json_object_add_uint(node, "link_up_down", mp->link_up_down); vat_json_object_add_uint(node, "link_duplex", mp->link_duplex); vat_json_object_add_uint(node, "link_speed", mp->link_speed); + vat_json_object_add_uint(node, "mtu", ntohs(mp->link_mtu)); vat_json_object_add_uint(node, "sub_id", ntohl(mp->sub_id)); vat_json_object_add_uint(node, "sub_dot1ad", mp->sub_dot1ad); vat_json_object_add_uint(node, "sub_number_of_tags", mp->sub_number_of_tags); @@ -610,10 +636,23 @@ static void vl_api_cli_reply_t_handler_json { vat_main_t * vam = &vat_main; vat_json_node_t node; + api_main_t * am = &api_main; + void * oldheap; + u8 * reply; vat_json_init_object(&node); vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); - vat_json_object_add_uint(&node, "reply_in_shmem", ntohl(mp->reply_in_shmem)); + vat_json_object_add_uint(&node, "reply_in_shmem", + ntohl(mp->reply_in_shmem)); + /* Toss the shared-memory original... */ + pthread_mutex_lock (&am->vlib_rp->mutex); + oldheap = svm_push_data_heap (am->vlib_rp); + + reply = (u8 *)(mp->reply_in_shmem); + vec_free (reply); + + svm_pop_heap (oldheap); + pthread_mutex_unlock (&am->vlib_rp->mutex); vat_json_print(vam->ofp, &node); vat_json_free(&node); @@ -1698,6 +1737,94 @@ static void vl_api_get_first_msg_id_reply_t_handler_json vam->result_ready = 1; } +static void vl_api_get_node_graph_reply_t_handler +(vl_api_get_node_graph_reply_t * mp) +{ + vat_main_t * vam = &vat_main; + api_main_t * am = &api_main; + i32 retval = ntohl(mp->retval); + u8 * pvt_copy, * reply; + void * oldheap; + vlib_node_t * node; + int i; + + if (vam->async_mode) { + vam->async_errors += (retval < 0); + } else { + vam->retval = retval; + vam->result_ready = 1; + } + + /* "Should never happen..." */ + if (retval != 0) + return; + + reply = (u8 *)(mp->reply_in_shmem); + pvt_copy = vec_dup (reply); + + /* Toss the shared-memory original... */ + pthread_mutex_lock (&am->vlib_rp->mutex); + oldheap = svm_push_data_heap (am->vlib_rp); + + vec_free (reply); + + svm_pop_heap (oldheap); + pthread_mutex_unlock (&am->vlib_rp->mutex); + + if (vam->graph_nodes) { + hash_free (vam->graph_node_index_by_name); + + for (i = 0; i < vec_len (vam->graph_nodes); i++) { + node = vam->graph_nodes[i]; + vec_free (node->name); + vec_free (node->next_nodes); + vec_free (node); + } + vec_free(vam->graph_nodes); + } + + vam->graph_node_index_by_name = hash_create_string (0, sizeof(uword)); + vam->graph_nodes = vlib_node_unserialize (pvt_copy); + vec_free (pvt_copy); + + for (i = 0; i < vec_len (vam->graph_nodes); i++) { + node = vam->graph_nodes[i]; + hash_set_mem (vam->graph_node_index_by_name, node->name, i); + } +} + +static void vl_api_get_node_graph_reply_t_handler_json +(vl_api_get_node_graph_reply_t * mp) +{ + vat_main_t * vam = &vat_main; + api_main_t * am = &api_main; + void * oldheap; + vat_json_node_t node; + u8 * reply; + + /* $$$$ make this real? */ + vat_json_init_object(&node); + vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); + vat_json_object_add_uint(&node, "reply_in_shmem", mp->reply_in_shmem); + + reply = (u8 *)(mp->reply_in_shmem); + + /* Toss the shared-memory original... */ + pthread_mutex_lock (&am->vlib_rp->mutex); + oldheap = svm_push_data_heap (am->vlib_rp); + + vec_free (reply); + + svm_pop_heap (oldheap); + pthread_mutex_unlock (&am->vlib_rp->mutex); + + vat_json_print(vam->ofp, &node); + vat_json_free(&node); + + vam->retval = ntohl(mp->retval); + vam->result_ready = 1; +} + #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 @@ -1767,7 +1894,9 @@ _(bd_ip_mac_add_del_reply) \ _(map_del_domain_reply) \ _(map_add_del_rule_reply) \ _(want_interface_events_reply) \ -_(want_stats_reply) +_(want_stats_reply) \ +_(cop_interface_enable_disable_reply) \ +_(cop_whitelist_enable_disable_reply) #define _(n) \ static void vl_api_##n##_t_handler \ @@ -1880,6 +2009,7 @@ _(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \ _(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \ _(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \ _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \ +_(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \ _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \ _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \ _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \ @@ -1911,12 +2041,15 @@ _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \ _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \ _(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \ _(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \ -_(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \ +_(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \ _(MAP_DOMAIN_DETAILS, map_domain_details) \ _(MAP_RULE_DETAILS, map_rule_details) \ _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \ _(WANT_STATS_REPLY, want_stats_reply) \ -_(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) +_(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \ +_(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \ +_(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \ +_(GET_NODE_GRAPH_REPLY, get_node_graph_reply) /* M: construct, but don't yet send a message */ @@ -2295,7 +2428,8 @@ int exec (vat_main_t * vam) while (vat_time_now (vam) < timeout) { if (vam->result_ready == 1) { u8 * free_me; - fformat (vam->ofp, "%s", vam->shmem_result); + if (vam->shmem_result != NULL) + fformat (vam->ofp, "%s", vam->shmem_result); pthread_mutex_lock (&am->vlib_rp->mutex); oldheap = svm_push_data_heap (am->vlib_rp); @@ -6555,6 +6689,86 @@ static int api_vxlan_add_del_tunnel (vat_main_t * vam) return 0; } +static void vl_api_vxlan_tunnel_details_t_handler +(vl_api_vxlan_tunnel_details_t * mp) +{ + vat_main_t * vam = &vat_main; + + fformat(vam->ofp, "%11d%13U%13U%14d%18d%13d\n", + ntohl(mp->sw_if_index), + format_ip4_address, &mp->src_address, + format_ip4_address, &mp->dst_address, + ntohl(mp->encap_vrf_id), + ntohl(mp->decap_next_index), + ntohl(mp->vni)); +} + +static void vl_api_vxlan_tunnel_details_t_handler_json +(vl_api_vxlan_tunnel_details_t * mp) +{ + vat_main_t * vam = &vat_main; + vat_json_node_t *node = NULL; + struct in_addr ip4; + + 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)); + memcpy(&ip4, &mp->src_address, sizeof(ip4)); + vat_json_object_add_ip4(node, "src_address", ip4); + memcpy(&ip4, &mp->dst_address, sizeof(ip4)); + vat_json_object_add_ip4(node, "dst_address", ip4); + vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id)); + vat_json_object_add_uint(node, "decap_next_index", ntohl(mp->decap_next_index)); + vat_json_object_add_uint(node, "vni", ntohl(mp->vni)); +} + +static int api_vxlan_tunnel_dump (vat_main_t * vam) +{ + unformat_input_t * i = vam->input; + vl_api_vxlan_tunnel_dump_t *mp; + f64 timeout; + u32 sw_if_index; + u8 sw_if_index_set = 0; + + /* Parse args required to build the message */ + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { + if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; + else + break; + } + + if (sw_if_index_set == 0) { + sw_if_index = ~0; + } + + if (!vam->json_output) { + fformat(vam->ofp, "%11s%13s%13s%14s%18s%13s\n", + "sw_if_index", "src_address", "dst_address", + "encap_vrf_id", "decap_next_index", "vni"); + } + + /* Get list of l2tpv3-tunnel interfaces */ + M(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump); + + mp->sw_if_index = htonl(sw_if_index); + + S; + + /* Use a control ping for synchronization */ + { + vl_api_control_ping_t * mp; + M(CONTROL_PING, control_ping); + S; + } + W; +} + static int api_l2_fib_clear_table (vat_main_t * vam) { // unformat_input_t * i = vam->input; @@ -6681,6 +6895,8 @@ static int api_create_vhost_user_if (vat_main_t * vam) u8 is_server = 0; u8 file_name_set = 0; u32 custom_dev_instance = ~0; + u8 hwaddr[6]; + u8 use_custom_mac = 0; while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { if (unformat (i, "socket %s", &file_name)) { @@ -6688,6 +6904,8 @@ static int api_create_vhost_user_if (vat_main_t * vam) } else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance)) ; + else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr)) + use_custom_mac = 1; else if (unformat (i, "server")) is_server = 1; else @@ -6714,6 +6932,8 @@ static int api_create_vhost_user_if (vat_main_t * vam) mp->renumber = 1; mp->custom_dev_instance = ntohl(custom_dev_instance); } + mp->use_custom_mac = use_custom_mac; + memcpy(mp->mac_address, hwaddr, 6); S; W; /* NOTREACHED */ @@ -7640,6 +7860,7 @@ api_ip_dump (vat_main_t * vam) static int api_ipsec_spd_add_del (vat_main_t * vam) { +#if DPDK > 0 unformat_input_t * i = vam->input; vl_api_ipsec_spd_add_del_t *mp; f64 timeout; @@ -7669,11 +7890,16 @@ api_ipsec_spd_add_del (vat_main_t * vam) S; W; /* NOTREACHED */ return 0; +#else + clib_warning ("unsupported (no dpdk)"); + return -99; +#endif } static int api_ipsec_interface_add_del_spd (vat_main_t * vam) { +#if DPDK > 0 unformat_input_t * i = vam->input; vl_api_ipsec_interface_add_del_spd_t *mp; f64 timeout; @@ -7717,11 +7943,16 @@ api_ipsec_interface_add_del_spd (vat_main_t * vam) S; W; /* NOTREACHED */ return 0; +#else + clib_warning ("unsupported (no dpdk)"); + return -99; +#endif } static int api_ipsec_spd_add_del_entry (vat_main_t * vam) { +#if DPDK > 0 unformat_input_t * i = vam->input; vl_api_ipsec_spd_add_del_entry_t *mp; f64 timeout; @@ -7847,11 +8078,16 @@ api_ipsec_spd_add_del_entry (vat_main_t * vam) S; W; /* NOTREACHED */ return 0; +#else + clib_warning ("unsupported (no dpdk)"); + return -99; +#endif } static int api_ipsec_sad_add_del_entry (vat_main_t * vam) { +#if DPDK > 0 unformat_input_t * i = vam->input; vl_api_ipsec_sad_add_del_entry_t *mp; f64 timeout; @@ -7954,11 +8190,16 @@ api_ipsec_sad_add_del_entry (vat_main_t * vam) S; W; /* NOTREACHED */ return 0; +#else + clib_warning ("unsupported (no dpdk)"); + return -99; +#endif } static int api_ipsec_sa_set_key (vat_main_t * vam) { +#if DPDK > 0 unformat_input_t * i = vam->input; vl_api_ipsec_sa_set_key_t *mp; f64 timeout; @@ -7996,6 +8237,10 @@ api_ipsec_sa_set_key (vat_main_t * vam) S; W; /* NOTREACHED */ return 0; +#else + clib_warning ("unsupported (no dpdk)"); + return -99; +#endif } /* @@ -8269,6 +8514,103 @@ api_get_first_msg_id (vat_main_t * vam) return 0; } +static int api_cop_interface_enable_disable (vat_main_t * vam) +{ + unformat_input_t * line_input = vam->input; + vl_api_cop_interface_enable_disable_t * mp; + f64 timeout; + u32 sw_if_index = ~0; + u8 enable_disable = 1; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { + if (unformat (line_input, "disable")) + enable_disable = 0; + if (unformat (line_input, "enable")) + enable_disable = 1; + else if (unformat (line_input, "%U", unformat_sw_if_index, + vam, &sw_if_index)) + ; + else if (unformat (line_input, "sw_if_index %d", &sw_if_index)) + ; + else + break; + } + + if (sw_if_index == ~0) { + errmsg ("missing interface name or sw_if_index\n"); + return -99; + } + + /* Construct the API message */ + M(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable); + mp->sw_if_index = ntohl(sw_if_index); + mp->enable_disable = enable_disable; + + /* send it... */ + S; + /* Wait for the reply */ + W; +} + +static int api_cop_whitelist_enable_disable (vat_main_t * vam) +{ + unformat_input_t * line_input = vam->input; + vl_api_cop_whitelist_enable_disable_t * mp; + f64 timeout; + u32 sw_if_index = ~0; + u8 ip4=0, ip6=0, default_cop=0; + u32 fib_id; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { + if (unformat (line_input, "ip4")) + ip4 = 1; + else if (unformat (line_input, "ip6")) + ip6 = 1; + else if (unformat (line_input, "default")) + default_cop = 1; + else if (unformat (line_input, "%U", unformat_sw_if_index, + vam, &sw_if_index)) + ; + else if (unformat (line_input, "sw_if_index %d", &sw_if_index)) + ; + else if (unformat (line_input, "fib-id %d", &fib_id)) + ; + else + break; + } + + if (sw_if_index == ~0) { + errmsg ("missing interface name or sw_if_index\n"); + return -99; + } + + /* Construct the API message */ + M(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable); + mp->sw_if_index = ntohl(sw_if_index); + mp->fib_id = ntohl(fib_id); + mp->ip4 = ip4; + mp->ip6 = ip6; + mp->default_cop = default_cop; + + /* send it... */ + S; + /* Wait for the reply */ + W; +} + +static int api_get_node_graph (vat_main_t * vam) +{ + vl_api_get_node_graph_t * mp; + f64 timeout; + + M(GET_NODE_GRAPH, get_node_graph); + + /* send it... */ + S; + /* Wait for the reply */ + W; +} + static int q_or_quit (vat_main_t * vam) { longjmp (vam->jump_buf, 1); @@ -8404,6 +8746,75 @@ static int dump_macro_table (vat_main_t * vam) return 0; } +static int dump_node_table (vat_main_t * vam) +{ + int i, j; + vlib_node_t * node, * next_node; + + if (vec_len (vam->graph_nodes) == 0) { + fformat (vam->ofp, "Node table empty, issue get_node_graph...\n"); + return 0; + } + + for (i = 0; i < vec_len (vam->graph_nodes); i++) { + node = vam->graph_nodes[i]; + fformat (vam->ofp, "[%d] %s\n", i, node->name); + for (j = 0; j < vec_len (node->next_nodes); j++) { + if (node->next_nodes[j] != ~0) { + next_node = vam->graph_nodes[node->next_nodes[j]]; + fformat (vam->ofp, " [%d] %s\n", j, next_node->name); + } + } + } + return 0; +} + +static int search_node_table (vat_main_t * vam) +{ + unformat_input_t * line_input = vam->input; + u8 * node_to_find; + int j; + vlib_node_t * node, * next_node; + uword * p; + + if (vam->graph_node_index_by_name == 0) { + fformat (vam->ofp, "Node table empty, issue get_node_graph...\n"); + return 0; + } + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { + if (unformat (line_input, "%s", &node_to_find)) { + vec_add1 (node_to_find, 0); + p = hash_get_mem (vam->graph_node_index_by_name, node_to_find); + if (p == 0) { + fformat (vam->ofp, "%s not found...\n", node_to_find); + goto out; + } + node = vam->graph_nodes[p[0]]; + fformat (vam->ofp, "[%d] %s\n", p[0], node->name); + for (j = 0; j < vec_len (node->next_nodes); j++) { + if (node->next_nodes[j] != ~0) { + next_node = vam->graph_nodes[node->next_nodes[j]]; + fformat (vam->ofp, " [%d] %s\n", j, next_node->name); + } + } + } + + else { + clib_warning ("parse error '%U'", format_unformat_error, + line_input); + return -99; + } + + out: + vec_free(node_to_find); + + } + + return 0; +} + + static int script (vat_main_t * vam) { u8 * s = 0; @@ -8582,6 +8993,7 @@ _(sw_if_l2tpv3_tunnel_dump, "") \ _(vxlan_add_del_tunnel, \ "src dst vni [encap-vrf-id ]\n" \ " [decap-next l2|ip4|ip6] [del]") \ +_(vxlan_tunnel_dump, "[ | sw_if_index ]") \ _(l2_fib_clear_table, "") \ _(l2_interface_efp_filter, "sw_if_index enable | disable") \ _(l2_interface_vlan_tag_rewrite, \ @@ -8589,7 +9001,8 @@ _(l2_interface_vlan_tag_rewrite, \ "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \ "[translate-2-[1|2]] [push_dot1q 0] tag1 tag2 ") \ _(create_vhost_user_if, \ - "socket [server] [renumber ]") \ + "socket [server] [renumber ] " \ + "[mac ]") \ _(modify_vhost_user_if, \ " | sw_if_index socket \n" \ "[server] [renumber ]") \ @@ -8647,7 +9060,11 @@ _(map_domain_dump, "") \ _(map_rule_dump, "index ") \ _(want_interface_events, "enable|disable") \ _(want_stats,"enable|disable") \ -_(get_first_msg_id, "client ") +_(get_first_msg_id, "client ") \ +_(cop_interface_enable_disable, " | sw_if_index [disable]") \ +_(cop_whitelist_enable_disable, " | sw_if_index \n" \ + "fib-id [ip4][ip6][default]") \ +_(get_node_graph, " ") /* List of command functions, CLI names map directly to functions */ #define foreach_cli_function \ @@ -8658,11 +9075,13 @@ _(dump_ipv4_table, "usage: dump_ipv4_table") \ _(dump_ipv6_table, "usage: dump_ipv6_table") \ _(dump_stats_table, "usage: dump_stats_table") \ _(dump_macro_table, "usage: dump_macro_table ") \ +_(dump_node_table, "usage: dump_node_table") \ _(echo, "usage: echo ") \ _(exec, "usage: exec ") \ _(help, "usage: help") \ _(q, "usage: quit") \ _(quit, "usage: quit") \ +_(search_node_table, "usage: search_node_table ...") \ _(set, "usage: set ") \ _(script, "usage: script ") \ _(unset, "usage: unset ")