app/testpmd: show MAC addresses added to a port

Patch adds a runtime function to display the unicast and
multicast MAC addresses added to a port.

Syntax:
	show port (port_id) macs|mcast_macs

Usage:
testpmd> show port 0 macs
Number of MAC address added: 1
  B0:26:28:7F:F5:C1
testpmd>
testpmd> show port 0 mcast_macs
Number of Multicast MAC address added: 0
testpmd>
testpmd> mac_addr add 0 B0:26:28:7F:22:33
testpmd> mac_addr add 0 B0:26:28:7F:22:34
testpmd> show port 0 macs
Number of MAC address added: 3
  B0:26:28:7F:F5:C1
  B0:26:28:7F:22:33
  B0:26:28:7F:22:34
testpmd>
testpmd> mac_addr remove 0 B0:26:28:7F:22:33
testpmd> show port 0 macs
Number of MAC address added: 2
  B0:26:28:7F:F5:C1
  B0:26:28:7F:22:34

Signed-off-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
Reviewed-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
This commit is contained in:
Kalesh AP 2019-11-25 13:57:50 +05:30 committed by Ferruh Yigit
parent 867b6d6180
commit e1d44d0ad6
4 changed files with 129 additions and 0 deletions

View File

@ -241,6 +241,9 @@ static void cmd_help_long_parsed(void *parsed_result,
"show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
" Show status of rx|tx descriptor.\n\n"
"show port (port_id) macs|mcast_macs"
" Display list of mac addresses added to port.\n\n"
);
}
@ -19171,6 +19174,56 @@ cmdline_parse_inst_t cmd_set_port_ptypes = {
},
};
/* *** display mac addresses added to a port *** */
struct cmd_showport_macs_result {
cmdline_fixed_string_t cmd_show;
cmdline_fixed_string_t cmd_port;
cmdline_fixed_string_t cmd_keyword;
portid_t cmd_pid;
};
static void
cmd_showport_macs_parsed(void *parsed_result,
__attribute__((unused)) struct cmdline *cl,
__attribute__((unused)) void *data)
{
struct cmd_showport_macs_result *res = parsed_result;
if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
return;
if (!strcmp(res->cmd_keyword, "macs"))
show_macs(res->cmd_pid);
else if (!strcmp(res->cmd_keyword, "mcast_macs"))
show_mcast_macs(res->cmd_pid);
}
cmdline_parse_token_string_t cmd_showport_macs_show =
TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
cmd_show, "show");
cmdline_parse_token_string_t cmd_showport_macs_port =
TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
cmd_port, "port");
cmdline_parse_token_num_t cmd_showport_macs_pid =
TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
cmd_pid, UINT16);
cmdline_parse_token_string_t cmd_showport_macs_keyword =
TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
cmd_keyword, "macs#mcast_macs");
cmdline_parse_inst_t cmd_showport_macs = {
.f = cmd_showport_macs_parsed,
.data = NULL,
.help_str = "show port <port_id> macs|mcast_macs",
.tokens = {
(void *)&cmd_showport_macs_show,
(void *)&cmd_showport_macs_port,
(void *)&cmd_showport_macs_pid,
(void *)&cmd_showport_macs_keyword,
NULL,
},
};
/* ******************************************************************************** */
/* list of instructions */
@ -19289,6 +19342,7 @@ cmdline_parse_ctx_t main_ctx[] = {
(cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
(cmdline_parse_inst_t *)&cmd_config_rss_reta,
(cmdline_parse_inst_t *)&cmd_showport_reta,
(cmdline_parse_inst_t *)&cmd_showport_macs,
(cmdline_parse_inst_t *)&cmd_config_burst,
(cmdline_parse_inst_t *)&cmd_config_thresh,
(cmdline_parse_inst_t *)&cmd_config_threshold,

View File

@ -3965,3 +3965,60 @@ port_queue_region_info_display(portid_t port_id, void *buf)
printf("\n\n");
}
void
show_macs(portid_t port_id)
{
char buf[RTE_ETHER_ADDR_FMT_SIZE];
struct rte_eth_dev_info dev_info;
struct rte_ether_addr *addr;
uint32_t i, num_macs = 0;
struct rte_eth_dev *dev;
dev = &rte_eth_devices[port_id];
rte_eth_dev_info_get(port_id, &dev_info);
for (i = 0; i < dev_info.max_mac_addrs; i++) {
addr = &dev->data->mac_addrs[i];
/* skip zero address */
if (rte_is_zero_ether_addr(addr))
continue;
num_macs++;
}
printf("Number of MAC address added: %d\n", num_macs);
for (i = 0; i < dev_info.max_mac_addrs; i++) {
addr = &dev->data->mac_addrs[i];
/* skip zero address */
if (rte_is_zero_ether_addr(addr))
continue;
rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
printf(" %s\n", buf);
}
}
void
show_mcast_macs(portid_t port_id)
{
char buf[RTE_ETHER_ADDR_FMT_SIZE];
struct rte_ether_addr *addr;
struct rte_port *port;
uint32_t i;
port = &ports[port_id];
printf("Number of Multicast MAC address added: %d\n", port->mc_addr_nb);
for (i = 0; i < port->mc_addr_nb; i++) {
addr = &port->mc_addr_pool[i];
rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
printf(" %s\n", buf);
}
}

View File

@ -835,6 +835,9 @@ int eth_link_get_nowait_print_err(uint16_t port_id, struct rte_eth_link *link);
int eth_macaddr_get_print_err(uint16_t port_id,
struct rte_ether_addr *mac_addr);
/* Functions to display the set of MAC addresses added to a port*/
void show_macs(portid_t port_id);
void show_mcast_macs(portid_t port_id);
/* Functions to manage the set of filtered Multicast MAC addresses */
void mcast_addr_add(portid_t port_id, struct rte_ether_addr *mc_addr);

View File

@ -487,6 +487,21 @@ set packet types classification for a specific port::
testpmd> set port (port_id) ptypes_mask (mask)
show port mac addresses info
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Show mac addresses added for a specific port::
testpmd> show port (port_id) macs
show port multicast mac addresses info
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Show multicast mac addresses added for a specific port::
testpmd> show port (port_id) mcast_macs
show device info
~~~~~~~~~~~~~~~~