+#define _(n) \
+ static void vl_api_##n##_t_handler \
+ (vl_api_##n##_t * mp) \
+ { \
+ vat_main_t * vam = &vat_main; \
+ i32 retval = ntohl(mp->retval); \
+ if (vam->async_mode) { \
+ vam->async_errors += (retval < 0); \
+ } else { \
+ vam->retval = retval; \
+ vam->result_ready = 1; \
+ } \
+ }
+foreach_standard_reply_retval_handler;
+#undef _
+
+#define _(n) \
+ static void vl_api_##n##_t_handler_json \
+ (vl_api_##n##_t * mp) \
+ { \
+ vat_main_t * vam = &vat_main; \
+ vat_json_node_t node; \
+ vat_json_init_object(&node); \
+ vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
+ vat_json_print(vam->ofp, &node); \
+ vam->retval = ntohl(mp->retval); \
+ vam->result_ready = 1; \
+ }
+foreach_standard_reply_retval_handler;
+#undef _
+
+/*
+ * Table of message reply handlers, must include boilerplate handlers
+ * we just generated
+ */
+
+#define foreach_vpe_api_reply_msg \
+_(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
+_(SW_INTERFACE_DETAILS, sw_interface_details) \
+_(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
+_(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
+_(CONTROL_PING_REPLY, control_ping_reply) \
+_(CLI_REPLY, cli_reply) \
+_(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
+ sw_interface_add_del_address_reply) \
+_(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
+_(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
+_(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
+ sw_interface_set_l2_xconnect_reply) \
+_(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
+ sw_interface_set_l2_bridge_reply) \
+_(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
+_(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
+_(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
+_(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
+_(L2_FLAGS_REPLY, l2_flags_reply) \
+_(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
+_(TAP_CONNECT_REPLY, tap_connect_reply) \
+_(TAP_MODIFY_REPLY, tap_modify_reply) \
+_(TAP_DELETE_REPLY, tap_delete_reply) \
+_(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
+_(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
+_(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
+_(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
+ proxy_arp_intfc_enable_disable_reply) \
+_(MPLS_ADD_DEL_ENCAP_REPLY, mpls_add_del_encap_reply) \
+_(MPLS_ADD_DEL_DECAP_REPLY, mpls_add_del_decap_reply) \
+_(MPLS_GRE_ADD_DEL_TUNNEL_REPLY, mpls_gre_add_del_tunnel_reply) \
+_(MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY, \
+ mpls_ethernet_add_del_tunnel_reply) \
+_(MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY, \
+ mpls_ethernet_add_del_tunnel_2_reply) \
+_(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
+ sw_interface_set_unnumbered_reply) \
+_(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
+_(RESET_VRF_REPLY, reset_vrf_reply) \
+_(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
+_(CREATE_SUBIF_REPLY, create_subif_reply) \
+_(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
+_(RESET_FIB_REPLY, reset_fib_reply) \
+_(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
+_(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
+_(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
+_(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
+_(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
+_(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
+ sw_interface_ip6_enable_disable_reply) \
+_(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
+ sw_interface_ip6_set_link_local_address_reply) \
+_(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
+ sw_interface_ip6nd_ra_prefix_reply) \
+_(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
+ sw_interface_ip6nd_ra_config_reply) \
+_(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
+_(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
+_(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
+_(SR_POLICY_ADD_DEL_REPLY, sr_policy_add_del_reply) \
+_(SR_MULTICAST_MAP_ADD_DEL_REPLY, sr_multicast_map_add_del_reply) \
+_(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
+_(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
+_(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
+classify_set_interface_ip_table_reply) \
+_(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
+ classify_set_interface_l2_tables_reply) \
+_(GET_NODE_INDEX_REPLY, get_node_index_reply) \
+_(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
+_(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
+_(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
+_(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
+ 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) \
+_(GRE_ADD_DEL_TUNNEL_REPLY, gre_add_del_tunnel_reply) \
+_(GRE_TUNNEL_DETAILS, gre_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) \
+_(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
+_(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
+_(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
+_(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
+_(SHOW_VERSION_REPLY, show_version_reply) \
+_(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
+_(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
+_(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
+_(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
+_(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
+_(IP4_ARP_EVENT, ip4_arp_event) \
+_(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
+_(IP_ADDRESS_DETAILS, ip_address_details) \
+_(IP_DETAILS, ip_details) \
+_(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
+_(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
+_(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
+_(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
+_(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
+_(IKEV2_PROFILE_ADD_DEL_REPLY, ikev2_profile_add_del_reply) \
+_(IKEV2_PROFILE_SET_AUTH_REPLY, ikev2_profile_set_auth_reply) \
+_(IKEV2_PROFILE_SET_ID_REPLY, ikev2_profile_set_id_reply) \
+_(IKEV2_PROFILE_SET_TS_REPLY, ikev2_profile_set_ts_reply) \
+_(IKEV2_SET_LOCAL_KEY_REPLY, ikev2_set_local_key_reply) \
+_(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
+_(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
+_(DHCP_COMPL_EVENT, dhcp_compl_event) \
+_(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
+_(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_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) \
+_(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) \
+_(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
+_(TRACE_PROFILE_ADD_REPLY, trace_profile_add_reply) \
+_(TRACE_PROFILE_APPLY_REPLY, trace_profile_apply_reply) \
+_(TRACE_PROFILE_DEL_REPLY, trace_profile_del_reply) \
+_(LISP_ADD_DEL_LOCATOR_SET_REPLY, lisp_add_del_locator_set_reply) \
+_(LISP_ADD_DEL_LOCATOR_REPLY, lisp_add_del_locator_reply) \
+_(LISP_ADD_DEL_LOCAL_EID_REPLY, lisp_add_del_local_eid_reply) \
+_(LISP_ADD_DEL_REMOTE_MAPPING_REPLY, lisp_add_del_remote_mapping_reply) \
+_(LISP_ADD_DEL_ADJACENCY_REPLY, lisp_add_del_adjacency_reply) \
+_(LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY, lisp_gpe_add_del_fwd_entry_reply) \
+_(LISP_ADD_DEL_MAP_RESOLVER_REPLY, lisp_add_del_map_resolver_reply) \
+_(LISP_GPE_ENABLE_DISABLE_REPLY, lisp_gpe_enable_disable_reply) \
+_(LISP_ENABLE_DISABLE_REPLY, lisp_enable_disable_reply) \
+_(LISP_PITR_SET_LOCATOR_SET_REPLY, lisp_pitr_set_locator_set_reply) \
+_(LISP_EID_TABLE_ADD_DEL_MAP_REPLY, lisp_eid_table_add_del_map_reply) \
+_(LISP_GPE_ADD_DEL_IFACE_REPLY, lisp_gpe_add_del_iface_reply) \
+_(LISP_LOCATOR_SET_DETAILS, lisp_locator_set_details) \
+_(LISP_LOCAL_EID_TABLE_DETAILS, lisp_local_eid_table_details) \
+_(LISP_EID_TABLE_MAP_DETAILS, lisp_eid_table_map_details) \
+_(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details) \
+_(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details) \
+_(LISP_ENABLE_DISABLE_STATUS_DETAILS, \
+ lisp_enable_disable_status_details) \
+_(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY, \
+ lisp_add_del_map_request_itr_rlocs_reply) \
+_(LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY, \
+ lisp_get_map_request_itr_rlocs_reply) \
+_(SHOW_LISP_PITR_REPLY, show_lisp_pitr_reply) \
+_(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
+_(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
+_(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
+_(POLICER_DETAILS, policer_details) \
+_(NETMAP_CREATE_REPLY, netmap_create_reply) \
+_(NETMAP_DELETE_REPLY, netmap_delete_reply) \
+_(MPLS_GRE_TUNNEL_DETAILS, mpls_gre_tunnel_details) \
+_(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
+_(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
+_(MPLS_FIB_DECAP_DETAILS, mpls_fib_decap_details) \
+_(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \
+_(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
+_(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \
+_(CLASSIFY_SESSION_DETAILS, classify_session_details) \
+_(IPFIX_ENABLE_REPLY, ipfix_enable_reply) \
+_(IPFIX_DETAILS, ipfix_details) \
+_(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
+_(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \
+_(PG_CAPTURE_REPLY, pg_capture_reply) \
+_(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply)
+
+/* M: construct, but don't yet send a message */
+
+#define M(T,t) \
+do { \
+ vam->result_ready = 0; \
+ mp = vl_msg_api_alloc(sizeof(*mp)); \
+ memset (mp, 0, sizeof (*mp)); \
+ mp->_vl_msg_id = ntohs (VL_API_##T); \
+ mp->client_index = vam->my_client_index; \
+} while(0);
+
+#define M2(T,t,n) \
+do { \
+ vam->result_ready = 0; \
+ mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
+ memset (mp, 0, sizeof (*mp)); \
+ mp->_vl_msg_id = ntohs (VL_API_##T); \
+ mp->client_index = vam->my_client_index; \
+} while(0);
+
+
+/* S: send a message */
+#define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
+
+/* W: wait for results, with timeout */
+#define W \
+do { \
+ timeout = vat_time_now (vam) + 1.0; \
+ \
+ while (vat_time_now (vam) < timeout) { \
+ if (vam->result_ready == 1) { \
+ return (vam->retval); \
+ } \
+ } \
+ return -99; \
+} while(0);
+
+/* W2: wait for results, with timeout */
+#define W2(body) \
+do { \
+ timeout = vat_time_now (vam) + 1.0; \
+ \
+ while (vat_time_now (vam) < timeout) { \
+ if (vam->result_ready == 1) { \
+ (body); \
+ return (vam->retval); \
+ } \
+ } \
+ return -99; \
+} while(0);
+
+typedef struct {
+ u8 * name;
+ u32 value;
+} name_sort_t;
+
+
+#define STR_VTR_OP_CASE(op) \
+ case L2_VTR_ ## op: \
+ return "" # op;
+
+static const char *str_vtr_op(u32 vtr_op)
+{
+ switch(vtr_op) {
+ STR_VTR_OP_CASE(DISABLED);
+ STR_VTR_OP_CASE(PUSH_1);
+ STR_VTR_OP_CASE(PUSH_2);
+ STR_VTR_OP_CASE(POP_1);
+ STR_VTR_OP_CASE(POP_2);
+ STR_VTR_OP_CASE(TRANSLATE_1_1);
+ STR_VTR_OP_CASE(TRANSLATE_1_2);
+ STR_VTR_OP_CASE(TRANSLATE_2_1);
+ STR_VTR_OP_CASE(TRANSLATE_2_2);
+ }
+
+ return "UNKNOWN";
+}
+
+static int dump_sub_interface_table (vat_main_t * vam)
+{
+ const sw_interface_subif_t * sub = NULL;
+
+ if (vam->json_output) {
+ clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
+ return -99;
+ }
+
+ fformat (vam->ofp,
+ "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
+ "Interface", "sw_if_index",
+ "sub id", "dot1ad", "tags", "outer id",
+ "inner id", "exact", "default",
+ "outer any", "inner any");
+
+ vec_foreach (sub, vam->sw_if_subif_table) {
+ fformat (vam->ofp,
+ "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
+ sub->interface_name,
+ sub->sw_if_index,
+ sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
+ sub->sub_number_of_tags, sub->sub_outer_vlan_id,
+ sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
+ sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
+ if (sub->vtr_op != L2_VTR_DISABLED) {
+ fformat (vam->ofp,
+ " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
+ "tag1: %d tag2: %d ]\n",
+ str_vtr_op(sub->vtr_op), sub->vtr_push_dot1q,
+ sub->vtr_tag1, sub->vtr_tag2);
+ }
+ }
+
+ return 0;
+}
+
+static int name_sort_cmp (void * a1, void * a2)
+{
+ name_sort_t * n1 = a1;
+ name_sort_t * n2 = a2;
+
+ return strcmp ((char *)n1->name, (char *)n2->name);
+}
+
+static int dump_interface_table (vat_main_t * vam)
+{
+ hash_pair_t * p;
+ name_sort_t * nses = 0, * ns;
+
+ if (vam->json_output) {
+ clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
+ return -99;
+ }
+
+ hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
+ ({
+ vec_add2 (nses, ns, 1);
+ ns->name = (u8 *)(p->key);
+ ns->value = (u32) p->value[0];
+ }));
+
+ vec_sort_with_function (nses, name_sort_cmp);
+
+ fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
+ vec_foreach (ns, nses) {
+ fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
+ }
+ vec_free (nses);
+ return 0;
+}
+
+static int dump_ip_table (vat_main_t * vam, int is_ipv6)
+{
+ const ip_details_t * det = NULL;
+ const ip_address_details_t * address = NULL;
+ u32 i = ~0;
+
+ fformat (vam->ofp,
+ "%-12s\n",
+ "sw_if_index");
+
+ if (0 == vam) {
+ return 0;
+ }
+
+ vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6]) {
+ i++;
+ if (!det->present) {
+ continue;
+ }
+ fformat (vam->ofp,
+ "%-12d\n",
+ i);
+ fformat (vam->ofp,
+ " %-30s%-13s\n",
+ "Address", "Prefix length");
+ if (!det->addr) {
+ continue;
+ }
+ vec_foreach (address, det->addr) {
+ fformat (vam->ofp,
+ " %-30U%-13d\n",
+ is_ipv6 ? format_ip6_address : format_ip4_address,
+ address->ip,
+ address->prefix_length);
+ }
+ }
+
+ return 0;
+}
+
+static int dump_ipv4_table (vat_main_t * vam)
+{
+ if (vam->json_output) {
+ clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
+ return -99;
+ }
+
+ return dump_ip_table (vam, 0);
+}
+
+static int dump_ipv6_table (vat_main_t * vam)
+{
+ if (vam->json_output) {
+ clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
+ return -99;
+ }
+
+ return dump_ip_table (vam, 1);
+}
+
+static char* counter_type_to_str (u8 counter_type, u8 is_combined)
+{
+ if (!is_combined) {
+ switch(counter_type) {
+ case VNET_INTERFACE_COUNTER_DROP:
+ return "drop";
+ case VNET_INTERFACE_COUNTER_PUNT:
+ return "punt";
+ case VNET_INTERFACE_COUNTER_IP4:
+ return "ip4";
+ case VNET_INTERFACE_COUNTER_IP6:
+ return "ip6";
+ case VNET_INTERFACE_COUNTER_RX_NO_BUF:
+ return "rx-no-buf";
+ case VNET_INTERFACE_COUNTER_RX_MISS:
+ return "rx-miss";
+ case VNET_INTERFACE_COUNTER_RX_ERROR:
+ return "rx-error";
+ case VNET_INTERFACE_COUNTER_TX_ERROR:
+ return "tx-error";
+ default:
+ return "INVALID-COUNTER-TYPE";
+ }
+ } else {
+ switch(counter_type) {
+ case VNET_INTERFACE_COUNTER_RX:
+ return "rx";
+ case VNET_INTERFACE_COUNTER_TX:
+ return "tx";
+ default:
+ return "INVALID-COUNTER-TYPE";
+ }
+ }
+}
+
+static int dump_stats_table (vat_main_t * vam)
+{
+ vat_json_node_t node;
+ vat_json_node_t *msg_array;
+ vat_json_node_t *msg;
+ vat_json_node_t *counter_array;
+ vat_json_node_t *counter;
+ interface_counter_t c;
+ u64 packets;
+ ip4_fib_counter_t *c4;
+ ip6_fib_counter_t *c6;
+ int i, j;
+
+ if (!vam->json_output) {
+ clib_warning ("dump_stats_table supported only in JSON format");
+ return -99;
+ }
+
+ vat_json_init_object(&node);
+
+ /* interface counters */
+ msg_array = vat_json_object_add(&node, "interface_counters");
+ vat_json_init_array(msg_array);
+ for (i = 0; i < vec_len(vam->simple_interface_counters); i++) {
+ msg = vat_json_array_add(msg_array);
+ vat_json_init_object(msg);
+ vat_json_object_add_string_copy(msg, "vnet_counter_type",
+ (u8*)counter_type_to_str(i, 0));
+ vat_json_object_add_int(msg, "is_combined", 0);
+ counter_array = vat_json_object_add(msg, "data");
+ vat_json_init_array(counter_array);
+ for (j = 0; j < vec_len(vam->simple_interface_counters[i]); j++) {
+ packets = vam->simple_interface_counters[i][j];
+ vat_json_array_add_uint(counter_array, packets);
+ }
+ }
+ for (i = 0; i < vec_len(vam->combined_interface_counters); i++) {
+ msg = vat_json_array_add(msg_array);
+ vat_json_init_object(msg);
+ vat_json_object_add_string_copy(msg, "vnet_counter_type",
+ (u8*)counter_type_to_str(i, 1));
+ vat_json_object_add_int(msg, "is_combined", 1);
+ counter_array = vat_json_object_add(msg, "data");
+ vat_json_init_array(counter_array);
+ for (j = 0; j < vec_len(vam->combined_interface_counters[i]); j++) {
+ c = vam->combined_interface_counters[i][j];
+ counter = vat_json_array_add(counter_array);
+ vat_json_init_object(counter);
+ vat_json_object_add_uint(counter, "packets", c.packets);
+ vat_json_object_add_uint(counter, "bytes", c.bytes);
+ }
+ }
+
+ /* ip4 fib counters */
+ msg_array = vat_json_object_add(&node, "ip4_fib_counters");
+ vat_json_init_array(msg_array);
+ for (i = 0; i < vec_len(vam->ip4_fib_counters); i++) {
+ msg = vat_json_array_add(msg_array);
+ vat_json_init_object(msg);
+ vat_json_object_add_uint(msg, "vrf_id", vam->ip4_fib_counters_vrf_id_by_index[i]);
+ counter_array = vat_json_object_add(msg, "c");
+ vat_json_init_array(counter_array);
+ for (j = 0; j < vec_len(vam->ip4_fib_counters[i]); j++) {
+ counter = vat_json_array_add(counter_array);
+ vat_json_init_object(counter);
+ c4 = &vam->ip4_fib_counters[i][j];
+ vat_json_object_add_ip4(counter, "address", c4->address);
+ vat_json_object_add_uint(counter, "address_length", c4->address_length);
+ vat_json_object_add_uint(counter, "packets", c4->packets);
+ vat_json_object_add_uint(counter, "bytes", c4->bytes);
+ }
+ }
+
+ /* ip6 fib counters */
+ msg_array = vat_json_object_add(&node, "ip6_fib_counters");
+ vat_json_init_array(msg_array);
+ for (i = 0; i < vec_len(vam->ip6_fib_counters); i++) {
+ msg = vat_json_array_add(msg_array);
+ vat_json_init_object(msg);
+ vat_json_object_add_uint(msg, "vrf_id", vam->ip6_fib_counters_vrf_id_by_index[i]);
+ counter_array = vat_json_object_add(msg, "c");
+ vat_json_init_array(counter_array);
+ for (j = 0; j < vec_len(vam->ip6_fib_counters[i]); j++) {
+ counter = vat_json_array_add(counter_array);
+ vat_json_init_object(counter);
+ c6 = &vam->ip6_fib_counters[i][j];
+ vat_json_object_add_ip6(counter, "address", c6->address);
+ vat_json_object_add_uint(counter, "address_length", c6->address_length);
+ vat_json_object_add_uint(counter, "packets", c6->packets);
+ vat_json_object_add_uint(counter, "bytes", c6->bytes);
+ }
+ }
+
+ vat_json_print(vam->ofp, &node);
+ vat_json_free(&node);
+
+ return 0;
+}
+
+int exec (vat_main_t * vam)
+{
+ api_main_t * am = &api_main;
+ vl_api_cli_request_t *mp;
+ f64 timeout;
+ void * oldheap;
+ u8 * cmd = 0;
+ unformat_input_t * i = vam->input;
+
+ if (vec_len(i->buffer) == 0)
+ return -1;
+
+ if (vam->exec_mode == 0 && unformat (i, "mode")) {
+ vam->exec_mode = 1;
+ return 0;
+ }
+ if (vam->exec_mode == 1 &&
+ (unformat (i, "exit") || unformat (i, "quit"))) {
+ vam->exec_mode = 0;
+ return 0;
+ }
+
+
+ M(CLI_REQUEST, cli_request);
+
+ /*
+ * Copy cmd into shared memory.
+ * In order for the CLI command to work, it
+ * must be a vector ending in \n, not a C-string ending
+ * in \n\0.
+ */
+ pthread_mutex_lock (&am->vlib_rp->mutex);
+ oldheap = svm_push_data_heap (am->vlib_rp);
+
+ vec_validate (cmd, vec_len(vam->input->buffer)-1);
+ clib_memcpy (cmd, vam->input->buffer, vec_len(vam->input->buffer));
+
+ svm_pop_heap (oldheap);
+ pthread_mutex_unlock (&am->vlib_rp->mutex);
+
+ mp->cmd_in_shmem = (u64) cmd;
+ S;
+ timeout = vat_time_now (vam) + 10.0;
+
+ while (vat_time_now (vam) < timeout) {
+ if (vam->result_ready == 1) {
+ u8 * free_me;
+ 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);
+
+ free_me = (u8 *)vam->shmem_result;
+ vec_free (free_me);
+
+ svm_pop_heap (oldheap);
+ pthread_mutex_unlock (&am->vlib_rp->mutex);
+ return 0;
+ }
+ }
+ return -99;
+}
+
+static int api_create_loopback (vat_main_t * vam)
+{
+ unformat_input_t * i = vam->input;
+ vl_api_create_loopback_t *mp;
+ f64 timeout;
+ u8 mac_address[6];
+ u8 mac_set = 0;
+
+ memset (mac_address, 0, sizeof (mac_address));
+
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
+ mac_set = 1;
+ else
+ break;
+ }
+
+ /* Construct the API message */
+ M(CREATE_LOOPBACK, create_loopback);
+ if (mac_set)
+ clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
+
+ S; W;
+}
+
+static int api_delete_loopback (vat_main_t * vam)
+{
+ unformat_input_t * i = vam->input;
+ vl_api_delete_loopback_t *mp;
+ f64 timeout;
+ u32 sw_if_index = ~0;
+
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (i, "sw_if_index %d", &sw_if_index))
+ ;
+ else
+ break;
+ }
+
+ if (sw_if_index == ~0)
+ {
+ errmsg ("missing sw_if_index\n");
+ return -99;
+ }
+
+ /* Construct the API message */
+ M(DELETE_LOOPBACK, delete_loopback);
+ mp->sw_if_index = ntohl (sw_if_index);
+
+ S; W;
+}
+
+static int api_want_stats (vat_main_t * vam)
+{
+ unformat_input_t * i = vam->input;
+ vl_api_want_stats_t * mp;
+ f64 timeout;
+ int enable = -1;
+
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (i, "enable"))
+ enable = 1;
+ else if (unformat (i, "disable"))
+ enable = 0;
+ else
+ break;
+ }
+
+ if (enable == -1)
+ {
+ errmsg ("missing enable|disable\n");
+ return -99;
+ }
+
+ M(WANT_STATS, want_stats);
+ mp->enable_disable = enable;
+
+ S; W;
+}
+
+static int api_want_interface_events (vat_main_t * vam)