- if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (i, "%U", api_unformat_sw_if_index, vam,
- &rx_sw_if_index))
- rx_sw_if_index_set = 1;
- }
- else
- break;
- }
- else if (unformat (i, "tx"))
- {
- if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (i, "%U", api_unformat_sw_if_index, vam,
- &tx_sw_if_index))
- tx_sw_if_index_set = 1;
- }
- else
- break;
- }
- else if (unformat (i, "enable"))
- enable = 1;
- else if (unformat (i, "disable"))
- enable = 0;
- else
- break;
- }
-
- if (rx_sw_if_index_set == 0)
- {
- errmsg ("missing rx interface name or rx_sw_if_index");
- return -99;
- }
-
- if (enable && (tx_sw_if_index_set == 0))
- {
- errmsg ("missing tx interface name or tx_sw_if_index");
- return -99;
- }
-
- M (SW_INTERFACE_SET_L2_XCONNECT, mp);
-
- mp->rx_sw_if_index = ntohl (rx_sw_if_index);
- mp->tx_sw_if_index = ntohl (tx_sw_if_index);
- mp->enable = enable;
-
- S (mp);
- W (ret);
- return ret;
-}
-
-static int
-api_sw_interface_set_l2_bridge (vat_main_t * vam)
-{
- unformat_input_t *i = vam->input;
- vl_api_sw_interface_set_l2_bridge_t *mp;
- vl_api_l2_port_type_t port_type;
- u32 rx_sw_if_index;
- u8 rx_sw_if_index_set = 0;
- u32 bd_id;
- u8 bd_id_set = 0;
- u32 shg = 0;
- u8 enable = 1;
- int ret;
-
- port_type = L2_API_PORT_TYPE_NORMAL;
-
- /* Parse args required to build the message */
- while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
- rx_sw_if_index_set = 1;
- else if (unformat (i, "bd_id %d", &bd_id))
- bd_id_set = 1;
- else
- if (unformat
- (i, "%U", api_unformat_sw_if_index, vam, &rx_sw_if_index))
- rx_sw_if_index_set = 1;
- else if (unformat (i, "shg %d", &shg))
- ;
- else if (unformat (i, "bvi"))
- port_type = L2_API_PORT_TYPE_BVI;
- else if (unformat (i, "uu-fwd"))
- port_type = L2_API_PORT_TYPE_UU_FWD;
- else if (unformat (i, "enable"))
- enable = 1;
- else if (unformat (i, "disable"))
- enable = 0;
- else
- break;
- }
-
- if (rx_sw_if_index_set == 0)
- {
- errmsg ("missing rx interface name or sw_if_index");
- return -99;
- }
-
- if (enable && (bd_id_set == 0))
- {
- errmsg ("missing bridge domain");
- return -99;
- }
-
- M (SW_INTERFACE_SET_L2_BRIDGE, mp);
-
- mp->rx_sw_if_index = ntohl (rx_sw_if_index);
- mp->bd_id = ntohl (bd_id);
- mp->shg = (u8) shg;
- mp->port_type = ntohl (port_type);
- mp->enable = enable;
-
- S (mp);
- W (ret);
- return ret;
-}
-
-static int
-api_bridge_domain_dump (vat_main_t * vam)
-{
- unformat_input_t *i = vam->input;
- vl_api_bridge_domain_dump_t *mp;
- vl_api_control_ping_t *mp_ping;
- u32 bd_id = ~0;
- int ret;
-
- /* Parse args required to build the message */
- while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (i, "bd_id %d", &bd_id))
- ;
- else
- break;
- }
-
- M (BRIDGE_DOMAIN_DUMP, mp);
- mp->bd_id = ntohl (bd_id);
- S (mp);
-
- /* Use a control ping for synchronization */
- MPING (CONTROL_PING, mp_ping);
- S (mp_ping);
-
- W (ret);
- return ret;
-}
-
-static int
-api_bridge_domain_add_del (vat_main_t * vam)
-{
- unformat_input_t *i = vam->input;
- vl_api_bridge_domain_add_del_t *mp;
- u32 bd_id = ~0;
- u8 is_add = 1;
- u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
- u8 *bd_tag = NULL;
- u32 mac_age = 0;
- int ret;
-
- /* Parse args required to build the message */
- while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (i, "bd_id %d", &bd_id))
- ;
- else if (unformat (i, "flood %d", &flood))
- ;
- else if (unformat (i, "uu-flood %d", &uu_flood))
- ;
- else if (unformat (i, "forward %d", &forward))
- ;
- else if (unformat (i, "learn %d", &learn))
- ;
- else if (unformat (i, "arp-term %d", &arp_term))
- ;
- else if (unformat (i, "mac-age %d", &mac_age))
- ;
- else if (unformat (i, "bd-tag %s", &bd_tag))
- ;
- else if (unformat (i, "del"))
- {
- is_add = 0;
- flood = uu_flood = forward = learn = 0;
- }
- else
- break;
- }
-
- if (bd_id == ~0)
- {
- errmsg ("missing bridge domain");
- ret = -99;
- goto done;
- }
-
- if (mac_age > 255)
- {
- errmsg ("mac age must be less than 256 ");
- ret = -99;
- goto done;
- }
-
- if ((bd_tag) && (vec_len (bd_tag) > 63))
- {
- errmsg ("bd-tag cannot be longer than 63");
- ret = -99;
- goto done;
- }
-
- M (BRIDGE_DOMAIN_ADD_DEL, mp);
-
- mp->bd_id = ntohl (bd_id);
- mp->flood = flood;
- mp->uu_flood = uu_flood;
- mp->forward = forward;
- mp->learn = learn;
- mp->arp_term = arp_term;
- mp->is_add = is_add;
- mp->mac_age = (u8) mac_age;
- if (bd_tag)
- {
- clib_memcpy (mp->bd_tag, bd_tag, vec_len (bd_tag));
- mp->bd_tag[vec_len (bd_tag)] = 0;
- }
- S (mp);
- W (ret);
-
-done:
- vec_free (bd_tag);
- return ret;
-}
-
-static int
-api_l2fib_flush_bd (vat_main_t * vam)
-{
- unformat_input_t *i = vam->input;
- vl_api_l2fib_flush_bd_t *mp;
- u32 bd_id = ~0;
- int ret;
-
- /* Parse args required to build the message */
- while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (i, "bd_id %d", &bd_id));
- else
- break;
- }
-
- if (bd_id == ~0)
- {
- errmsg ("missing bridge domain");
- return -99;
- }
-
- M (L2FIB_FLUSH_BD, mp);
-
- mp->bd_id = htonl (bd_id);
-
- S (mp);
- W (ret);
- return ret;
-}
-
-static int
-api_l2fib_flush_int (vat_main_t * vam)
-{
- unformat_input_t *i = vam->input;
- vl_api_l2fib_flush_int_t *mp;
- u32 sw_if_index = ~0;
- int ret;
-
- /* 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));
- else
- if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index));
- else
- break;
- }
-
- if (sw_if_index == ~0)
- {
- errmsg ("missing interface name or sw_if_index");
- return -99;
- }
-
- M (L2FIB_FLUSH_INT, mp);
-
- mp->sw_if_index = ntohl (sw_if_index);
-
- S (mp);
- W (ret);
- return ret;
-}
-
-static int
-api_l2fib_add_del (vat_main_t * vam)
-{
- unformat_input_t *i = vam->input;
- vl_api_l2fib_add_del_t *mp;
- f64 timeout;
- u8 mac[6] = { 0 };
- u8 mac_set = 0;
- u32 bd_id;
- u8 bd_id_set = 0;
- u32 sw_if_index = 0;
- u8 sw_if_index_set = 0;
- u8 is_add = 1;
- u8 static_mac = 0;
- u8 filter_mac = 0;
- u8 bvi_mac = 0;
- int count = 1;
- f64 before = 0;
- int j;
-
- /* Parse args required to build the message */
- while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (i, "mac %U", unformat_ethernet_address, mac))
- mac_set = 1;
- else if (unformat (i, "bd_id %d", &bd_id))
- bd_id_set = 1;
- else if (unformat (i, "sw_if_index %d", &sw_if_index))
- sw_if_index_set = 1;
- else if (unformat (i, "sw_if"))
- {
- if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat
- (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
- sw_if_index_set = 1;
- }
- else
- break;
- }
- else if (unformat (i, "static"))
- static_mac = 1;
- else if (unformat (i, "filter"))
- {
- filter_mac = 1;
- static_mac = 1;
- }
- else if (unformat (i, "bvi"))
- {
- bvi_mac = 1;
- static_mac = 1;
- }
- else if (unformat (i, "del"))
- is_add = 0;
- else if (unformat (i, "count %d", &count))
- ;
- else
- break;
- }
-
- if (mac_set == 0)
- {
- errmsg ("missing mac address");
- return -99;
- }
-
- if (bd_id_set == 0)
- {
- errmsg ("missing bridge domain");
- return -99;
- }
-
- if (is_add && sw_if_index_set == 0 && filter_mac == 0)
- {
- errmsg ("missing interface name or sw_if_index");
- return -99;
- }
-
- if (count > 1)
- {
- /* Turn on async mode */
- vam->async_mode = 1;
- vam->async_errors = 0;
- before = vat_time_now (vam);
- }
-
- for (j = 0; j < count; j++)
- {
- M (L2FIB_ADD_DEL, mp);
-
- clib_memcpy (mp->mac, mac, 6);
- mp->bd_id = ntohl (bd_id);
- mp->is_add = is_add;
- mp->sw_if_index = ntohl (sw_if_index);
-
- if (is_add)
- {
- mp->static_mac = static_mac;
- mp->filter_mac = filter_mac;
- mp->bvi_mac = bvi_mac;
- }
- increment_mac_address (mac);
- /* send it... */
- S (mp);
- }
-
- if (count > 1)
- {
- vl_api_control_ping_t *mp_ping;
- f64 after;
-
- /* Shut off async mode */
- vam->async_mode = 0;
-
- MPING (CONTROL_PING, mp_ping);
- S (mp_ping);
-
- timeout = vat_time_now (vam) + 1.0;
- while (vat_time_now (vam) < timeout)
- if (vam->result_ready == 1)
- goto out;
- vam->retval = -99;
-
- out:
- if (vam->retval == -99)
- errmsg ("timeout");
-
- if (vam->async_errors > 0)
- {
- errmsg ("%d asynchronous errors", vam->async_errors);
- vam->retval = -98;
- }
- vam->async_errors = 0;
- after = vat_time_now (vam);
-
- print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
- count, after - before, count / (after - before));
- }
- else
- {
- int ret;
-
- /* Wait for a reply... */
- W (ret);
- return ret;
- }
- /* Return the good/bad news */
- return (vam->retval);
-}
-
-static int
-api_bridge_domain_set_mac_age (vat_main_t * vam)
-{
- unformat_input_t *i = vam->input;
- vl_api_bridge_domain_set_mac_age_t *mp;
- u32 bd_id = ~0;
- u32 mac_age = 0;
- int ret;
-
- /* Parse args required to build the message */
- while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (i, "bd_id %d", &bd_id));
- else if (unformat (i, "mac-age %d", &mac_age));
- else
- break;
- }
-
- if (bd_id == ~0)
- {
- errmsg ("missing bridge domain");
- return -99;
- }
-
- if (mac_age > 255)
- {
- errmsg ("mac age must be less than 256 ");
- return -99;
- }
-
- M (BRIDGE_DOMAIN_SET_MAC_AGE, mp);
-
- mp->bd_id = htonl (bd_id);
- mp->mac_age = (u8) mac_age;
-
- S (mp);
- W (ret);
- return ret;
-}
-
-static int
-api_l2_flags (vat_main_t * vam)
-{
- unformat_input_t *i = vam->input;
- vl_api_l2_flags_t *mp;
- u32 sw_if_index;
- u32 flags = 0;
- u8 sw_if_index_set = 0;
- u8 is_set = 0;
- int ret;
-
- /* 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 if (unformat (i, "sw_if"))
- {
- if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat
- (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
- sw_if_index_set = 1;
- }
- else
- break;
- }
- else if (unformat (i, "learn"))
- flags |= L2_LEARN;
- else if (unformat (i, "forward"))
- flags |= L2_FWD;
- else if (unformat (i, "flood"))
- flags |= L2_FLOOD;
- else if (unformat (i, "uu-flood"))
- flags |= L2_UU_FLOOD;
- else if (unformat (i, "arp-term"))
- flags |= L2_ARP_TERM;
- else if (unformat (i, "off"))
- is_set = 0;
- else if (unformat (i, "disable"))
- is_set = 0;
- else
- break;
- }
-
- if (sw_if_index_set == 0)
- {
- errmsg ("missing interface name or sw_if_index");
- return -99;
- }
-
- M (L2_FLAGS, mp);
-
- mp->sw_if_index = ntohl (sw_if_index);
- mp->feature_bitmap = ntohl (flags);
- mp->is_set = is_set;
-
- S (mp);
- W (ret);
- return ret;
-}
-
-static int
-api_bridge_flags (vat_main_t * vam)
-{
- unformat_input_t *i = vam->input;
- vl_api_bridge_flags_t *mp;
- u32 bd_id;
- u8 bd_id_set = 0;
- u8 is_set = 1;
- bd_flags_t flags = 0;
- int ret;
-
- /* Parse args required to build the message */
- while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (i, "bd_id %d", &bd_id))
- bd_id_set = 1;
- else if (unformat (i, "learn"))
- flags |= BRIDGE_API_FLAG_LEARN;
- else if (unformat (i, "forward"))
- flags |= BRIDGE_API_FLAG_FWD;
- else if (unformat (i, "flood"))
- flags |= BRIDGE_API_FLAG_FLOOD;
- else if (unformat (i, "uu-flood"))
- flags |= BRIDGE_API_FLAG_UU_FLOOD;
- else if (unformat (i, "arp-term"))
- flags |= BRIDGE_API_FLAG_ARP_TERM;
- else if (unformat (i, "off"))
- is_set = 0;
- else if (unformat (i, "disable"))
- is_set = 0;
- else
- break;
- }
-
- if (bd_id_set == 0)
- {
- errmsg ("missing bridge domain");
- return -99;
- }
-
- M (BRIDGE_FLAGS, mp);
-
- mp->bd_id = ntohl (bd_id);
- mp->flags = ntohl (flags);
- mp->is_set = is_set;
-
- S (mp);
- W (ret);
- return ret;
-}
-
-static int
-api_bd_ip_mac_add_del (vat_main_t * vam)
-{
- vl_api_address_t ip = VL_API_ZERO_ADDRESS;
- vl_api_mac_address_t mac = { 0 };
- unformat_input_t *i = vam->input;
- vl_api_bd_ip_mac_add_del_t *mp;
- u32 bd_id;
- u8 is_add = 1;
- u8 bd_id_set = 0;
- u8 ip_set = 0;
- u8 mac_set = 0;
- int ret;
-
-
- /* Parse args required to build the message */
- while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (i, "bd_id %d", &bd_id))
- {
- bd_id_set++;
- }
- else if (unformat (i, "%U", unformat_vl_api_address, &ip))
- {
- ip_set++;
- }
- else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
- {
- mac_set++;
- }
- else if (unformat (i, "del"))
- is_add = 0;
- else
- break;
- }
-
- if (bd_id_set == 0)
- {
- errmsg ("missing bridge domain");
- return -99;
- }
- else if (ip_set == 0)
- {
- errmsg ("missing IP address");
- return -99;
- }
- else if (mac_set == 0)
- {
- errmsg ("missing MAC address");
- return -99;
- }
-
- M (BD_IP_MAC_ADD_DEL, mp);
-
- mp->entry.bd_id = ntohl (bd_id);
- mp->is_add = is_add;
-
- clib_memcpy (&mp->entry.ip, &ip, sizeof (ip));
- clib_memcpy (&mp->entry.mac, &mac, sizeof (mac));
-
- S (mp);
- W (ret);
- return ret;
-}
-
-static int
-api_bd_ip_mac_flush (vat_main_t * vam)
-{
- unformat_input_t *i = vam->input;
- vl_api_bd_ip_mac_flush_t *mp;
- u32 bd_id;
- u8 bd_id_set = 0;
- int ret;
-
- while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (i, "bd_id %d", &bd_id))
- {
- bd_id_set++;
- }
- else
- break;
- }
-
- if (bd_id_set == 0)
- {
- errmsg ("missing bridge domain");
- return -99;
- }
-
- M (BD_IP_MAC_FLUSH, mp);
-
- mp->bd_id = ntohl (bd_id);
-
- S (mp);
- W (ret);
- return ret;
-}
-
-static void vl_api_bd_ip_mac_details_t_handler
- (vl_api_bd_ip_mac_details_t * mp)
-{
- vat_main_t *vam = &vat_main;
-
- print (vam->ofp,
- "\n%-5d %U %U",
- ntohl (mp->entry.bd_id),
- format_vl_api_mac_address, mp->entry.mac,
- format_vl_api_address, &mp->entry.ip);
-}
-
-static void vl_api_bd_ip_mac_details_t_handler_json
- (vl_api_bd_ip_mac_details_t * mp)
-{
- vat_main_t *vam = &vat_main;
- vat_json_node_t *node = NULL;
-
- 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, "bd_id", ntohl (mp->entry.bd_id));
- vat_json_object_add_string_copy (node, "mac_address",
- format (0, "%U", format_vl_api_mac_address,
- &mp->entry.mac));
- u8 *ip = 0;
-
- ip = format (0, "%U", format_vl_api_address, &mp->entry.ip);
- vat_json_object_add_string_copy (node, "ip_address", ip);
- vec_free (ip);
-}
-
-static int
-api_bd_ip_mac_dump (vat_main_t * vam)
-{
- unformat_input_t *i = vam->input;
- vl_api_bd_ip_mac_dump_t *mp;
- vl_api_control_ping_t *mp_ping;
- int ret;
- u32 bd_id;
- u8 bd_id_set = 0;
-
- while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (i, "bd_id %d", &bd_id))
- {
- bd_id_set++;
- }
- else
- break;
- }
-
- print (vam->ofp,
- "\n%-5s %-7s %-20s %-30s",
- "bd_id", "is_ipv6", "mac_address", "ip_address");
-
- /* Dump Bridge Domain Ip to Mac entries */
- M (BD_IP_MAC_DUMP, mp);
-
- if (bd_id_set)
- mp->bd_id = htonl (bd_id);
- else
- mp->bd_id = ~0;
-
- S (mp);
-
- /* Use a control ping for synchronization */
- MPING (CONTROL_PING, mp_ping);
- S (mp_ping);
-
- W (ret);
- return ret;
-}
-
-uword
-unformat_vlib_pci_addr (unformat_input_t * input, va_list * args)
-{
- vlib_pci_addr_t *addr = va_arg (*args, vlib_pci_addr_t *);
- u32 x[4];
-
- if (!unformat (input, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3]))
- return 0;
-
- addr->domain = x[0];
- addr->bus = x[1];
- addr->slot = x[2];
- addr->function = x[3];
-
- return 1;
-}
-
-static int
-api_ip_table_add_del (vat_main_t * vam)
-{
- unformat_input_t *i = vam->input;
- vl_api_ip_table_add_del_t *mp;
- u32 table_id = ~0;
- u8 is_ipv6 = 0;
- u8 is_add = 1;
- int ret = 0;
-
- /* Parse args required to build the message */
- while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (i, "ipv6"))
- is_ipv6 = 1;
- else if (unformat (i, "del"))
- is_add = 0;
- else if (unformat (i, "add"))
- is_add = 1;
- else if (unformat (i, "table %d", &table_id))
- ;
- else
- {
- clib_warning ("parse error '%U'", format_unformat_error, i);
- return -99;
- }
- }
-
- if (~0 == table_id)
- {
- errmsg ("missing table-ID");
- return -99;
- }
-
- /* Construct the API message */
- M (IP_TABLE_ADD_DEL, mp);
-
- mp->table.table_id = ntohl (table_id);
- mp->table.is_ip6 = is_ipv6;
- mp->is_add = is_add;
-
- /* send it... */
- S (mp);
-
- /* Wait for a reply... */
- W (ret);
-
- return ret;
-}
-
-uword
-unformat_fib_path (unformat_input_t * input, va_list * args)
-{
- vat_main_t *vam = va_arg (*args, vat_main_t *);
- vl_api_fib_path_t *path = va_arg (*args, vl_api_fib_path_t *);
- u32 weight, preference;
- mpls_label_t out_label;
-
- clib_memset (path, 0, sizeof (*path));
- path->weight = 1;
- path->sw_if_index = ~0;
- path->rpf_id = ~0;
- path->n_labels = 0;
-
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (input, "%U %U",
- unformat_vl_api_ip4_address,
- &path->nh.address.ip4,
- api_unformat_sw_if_index, vam, &path->sw_if_index))
- {
- path->proto = FIB_API_PATH_NH_PROTO_IP4;