+ num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
+
+ if (num_slaves < 0) {
+ printf("\tFailed to get slave list for port = %d\n", port_id);
+ return;
+ }
+ if (num_slaves > 0) {
+ printf("\tSlaves (%d): [", num_slaves);
+ for (i = 0; i < num_slaves - 1; i++)
+ printf("%d ", slaves[i]);
+
+ printf("%d]\n", slaves[num_slaves - 1]);
+ } else {
+ printf("\tSlaves: []\n");
+
+ }
+
+ num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
+ RTE_MAX_ETHPORTS);
+
+ if (num_active_slaves < 0) {
+ printf("\tFailed to get active slave list for port = %d\n", port_id);
+ return;
+ }
+ if (num_active_slaves > 0) {
+ printf("\tActive Slaves (%d): [", num_active_slaves);
+ for (i = 0; i < num_active_slaves - 1; i++)
+ printf("%d ", slaves[i]);
+
+ printf("%d]\n", slaves[num_active_slaves - 1]);
+
+ } else {
+ printf("\tActive Slaves: []\n");
+
+ }
+
+ primary_id = rte_eth_bond_primary_get(port_id);
+ if (primary_id < 0) {
+ printf("\tFailed to get primary slave for port = %d\n", port_id);
+ return;
+ } else
+ printf("\tPrimary: [%d]\n", primary_id);
+
+}
+
+cmdline_parse_token_string_t cmd_showbonding_config_show =
+TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
+ show, "show");
+cmdline_parse_token_string_t cmd_showbonding_config_bonding =
+TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
+ bonding, "bonding");
+cmdline_parse_token_string_t cmd_showbonding_config_config =
+TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
+ config, "config");
+cmdline_parse_token_num_t cmd_showbonding_config_port =
+TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
+ port_id, UINT8);
+
+cmdline_parse_inst_t cmd_show_bonding_config = {
+ .f = cmd_show_bonding_config_parsed,
+ .help_str = "show bonding config (port_id): Show the bonding config for port_id",
+ .data = NULL,
+ .tokens = {
+ (void *)&cmd_showbonding_config_show,
+ (void *)&cmd_showbonding_config_bonding,
+ (void *)&cmd_showbonding_config_config,
+ (void *)&cmd_showbonding_config_port,
+ NULL
+ }
+};
+
+/* *** SET BONDING PRIMARY *** */
+struct cmd_set_bonding_primary_result {
+ cmdline_fixed_string_t set;
+ cmdline_fixed_string_t bonding;
+ cmdline_fixed_string_t primary;
+ uint8_t slave_id;
+ uint8_t port_id;
+};
+
+static void cmd_set_bonding_primary_parsed(void *parsed_result,
+ __attribute__((unused)) struct cmdline *cl,
+ __attribute__((unused)) void *data)
+{
+ struct cmd_set_bonding_primary_result *res = parsed_result;
+ portid_t master_port_id = res->port_id;
+ portid_t slave_port_id = res->slave_id;
+
+ /* Set the primary slave for a bonded device. */
+ if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
+ printf("\t Failed to set primary slave for port = %d.\n",
+ master_port_id);
+ return;
+ }
+ init_port_config();
+}
+
+cmdline_parse_token_string_t cmd_setbonding_primary_set =
+TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
+ set, "set");
+cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
+TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
+ bonding, "bonding");
+cmdline_parse_token_string_t cmd_setbonding_primary_primary =
+TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
+ primary, "primary");
+cmdline_parse_token_num_t cmd_setbonding_primary_slave =
+TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
+ slave_id, UINT8);
+cmdline_parse_token_num_t cmd_setbonding_primary_port =
+TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
+ port_id, UINT8);
+
+cmdline_parse_inst_t cmd_set_bonding_primary = {
+ .f = cmd_set_bonding_primary_parsed,
+ .help_str = "set bonding primary (slave_id) (port_id): Set the primary slave for port_id",
+ .data = NULL,
+ .tokens = {
+ (void *)&cmd_setbonding_primary_set,
+ (void *)&cmd_setbonding_primary_bonding,
+ (void *)&cmd_setbonding_primary_primary,
+ (void *)&cmd_setbonding_primary_slave,
+ (void *)&cmd_setbonding_primary_port,
+ NULL
+ }
+};
+
+/* *** ADD SLAVE *** */
+struct cmd_add_bonding_slave_result {
+ cmdline_fixed_string_t add;
+ cmdline_fixed_string_t bonding;
+ cmdline_fixed_string_t slave;
+ uint8_t slave_id;
+ uint8_t port_id;
+};
+
+static void cmd_add_bonding_slave_parsed(void *parsed_result,
+ __attribute__((unused)) struct cmdline *cl,
+ __attribute__((unused)) void *data)
+{
+ struct cmd_add_bonding_slave_result *res = parsed_result;
+ portid_t master_port_id = res->port_id;
+ portid_t slave_port_id = res->slave_id;
+
+ /* Set the primary slave for a bonded device. */
+ if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
+ printf("\t Failed to add slave %d to master port = %d.\n",
+ slave_port_id, master_port_id);
+ return;
+ }
+ init_port_config();
+}
+
+cmdline_parse_token_string_t cmd_addbonding_slave_add =
+TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
+ add, "add");
+cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
+TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
+ bonding, "bonding");
+cmdline_parse_token_string_t cmd_addbonding_slave_slave =
+TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
+ slave, "slave");
+cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
+TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
+ slave_id, UINT8);
+cmdline_parse_token_num_t cmd_addbonding_slave_port =
+TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
+ port_id, UINT8);
+
+cmdline_parse_inst_t cmd_add_bonding_slave = {
+ .f = cmd_add_bonding_slave_parsed,
+ .help_str = "add bonding slave (slave_id) (port_id): Add a slave device to a bonded device",
+ .data = NULL,
+ .tokens = {
+ (void *)&cmd_addbonding_slave_add,
+ (void *)&cmd_addbonding_slave_bonding,
+ (void *)&cmd_addbonding_slave_slave,
+ (void *)&cmd_addbonding_slave_slaveid,
+ (void *)&cmd_addbonding_slave_port,
+ NULL
+ }
+};
+
+/* *** REMOVE SLAVE *** */
+struct cmd_remove_bonding_slave_result {
+ cmdline_fixed_string_t remove;
+ cmdline_fixed_string_t bonding;
+ cmdline_fixed_string_t slave;
+ uint8_t slave_id;
+ uint8_t port_id;
+};
+
+static void cmd_remove_bonding_slave_parsed(void *parsed_result,
+ __attribute__((unused)) struct cmdline *cl,
+ __attribute__((unused)) void *data)
+{
+ struct cmd_remove_bonding_slave_result *res = parsed_result;
+ portid_t master_port_id = res->port_id;
+ portid_t slave_port_id = res->slave_id;
+
+ /* Set the primary slave for a bonded device. */
+ if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
+ printf("\t Failed to remove slave %d from master port = %d.\n",
+ slave_port_id, master_port_id);
+ return;
+ }
+ init_port_config();
+}
+
+cmdline_parse_token_string_t cmd_removebonding_slave_remove =
+ TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
+ remove, "remove");
+cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
+ TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
+ bonding, "bonding");
+cmdline_parse_token_string_t cmd_removebonding_slave_slave =
+ TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
+ slave, "slave");
+cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
+ TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
+ slave_id, UINT8);
+cmdline_parse_token_num_t cmd_removebonding_slave_port =
+ TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
+ port_id, UINT8);
+
+cmdline_parse_inst_t cmd_remove_bonding_slave = {
+ .f = cmd_remove_bonding_slave_parsed,
+ .help_str = "remove bonding slave (slave_id) (port_id): Remove a slave device from a bonded device",
+ .data = NULL,
+ .tokens = {
+ (void *)&cmd_removebonding_slave_remove,
+ (void *)&cmd_removebonding_slave_bonding,
+ (void *)&cmd_removebonding_slave_slave,
+ (void *)&cmd_removebonding_slave_slaveid,
+ (void *)&cmd_removebonding_slave_port,
+ NULL
+ }
+};
+
+/* *** CREATE BONDED DEVICE *** */
+struct cmd_create_bonded_device_result {
+ cmdline_fixed_string_t create;
+ cmdline_fixed_string_t bonded;
+ cmdline_fixed_string_t device;
+ uint8_t mode;
+ uint8_t socket;
+};
+
+static int bond_dev_num = 0;
+
+static void cmd_create_bonded_device_parsed(void *parsed_result,
+ __attribute__((unused)) struct cmdline *cl,
+ __attribute__((unused)) void *data)
+{
+ struct cmd_create_bonded_device_result *res = parsed_result;
+ char ethdev_name[RTE_ETH_NAME_MAX_LEN];
+ int port_id;
+
+ if (test_done == 0) {
+ printf("Please stop forwarding first\n");
+ return;
+ }
+
+ snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "eth_bond_testpmd_%d",
+ bond_dev_num++);
+
+ /* Create a new bonded device. */
+ port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
+ if (port_id < 0) {
+ printf("\t Failed to create bonded device.\n");
+ return;
+ } else {
+ printf("Created new bonded device %s on (port %d).\n", ethdev_name,
+ port_id);
+
+ /* Update number of ports */
+ nb_ports = rte_eth_dev_count();
+ reconfig(port_id);
+ rte_eth_promiscuous_enable(port_id);
+ }
+
+}
+
+cmdline_parse_token_string_t cmd_createbonded_device_create =
+ TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
+ create, "create");
+cmdline_parse_token_string_t cmd_createbonded_device_bonded =
+ TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
+ bonded, "bonded");
+cmdline_parse_token_string_t cmd_createbonded_device_device =
+ TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
+ device, "device");
+cmdline_parse_token_num_t cmd_createbonded_device_mode =
+ TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
+ mode, UINT8);
+cmdline_parse_token_num_t cmd_createbonded_device_socket =
+ TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
+ socket, UINT8);
+
+cmdline_parse_inst_t cmd_create_bonded_device = {
+ .f = cmd_create_bonded_device_parsed,
+ .help_str = "create bonded device (mode) (socket): Create a new bonded device with specific bonding mode and socket",
+ .data = NULL,
+ .tokens = {
+ (void *)&cmd_createbonded_device_create,
+ (void *)&cmd_createbonded_device_bonded,
+ (void *)&cmd_createbonded_device_device,
+ (void *)&cmd_createbonded_device_mode,
+ (void *)&cmd_createbonded_device_socket,
+ NULL
+ }
+};
+
+/* *** SET MAC ADDRESS IN BONDED DEVICE *** */
+struct cmd_set_bond_mac_addr_result {
+ cmdline_fixed_string_t set;
+ cmdline_fixed_string_t bonding;
+ cmdline_fixed_string_t mac_addr;
+ uint8_t port_num;
+ struct ether_addr address;
+};
+
+static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
+ __attribute__((unused)) struct cmdline *cl,
+ __attribute__((unused)) void *data)
+{
+ struct cmd_set_bond_mac_addr_result *res = parsed_result;
+ int ret;
+
+ if (res->port_num >= nb_ports) {
+ printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
+ return;
+ }
+
+ ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
+
+ /* check the return value and print it if is < 0 */
+ if (ret < 0)
+ printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
+}
+
+cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
+ TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
+cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
+ TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
+ "bonding");
+cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
+ TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
+ "mac_addr");
+cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
+ TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8);
+cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
+ TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
+
+cmdline_parse_inst_t cmd_set_bond_mac_addr = {
+ .f = cmd_set_bond_mac_addr_parsed,
+ .data = (void *) 0,
+ .help_str = "set bonding mac_addr (port_id) (address): ",
+ .tokens = {
+ (void *)&cmd_set_bond_mac_addr_set,
+ (void *)&cmd_set_bond_mac_addr_bonding,
+ (void *)&cmd_set_bond_mac_addr_mac,
+ (void *)&cmd_set_bond_mac_addr_portnum,
+ (void *)&cmd_set_bond_mac_addr_addr,
+ NULL
+ }
+};
+
+#endif /* RTE_LIBRTE_PMD_BOND */
+
+/* *** SET FORWARDING MODE *** */
+struct cmd_set_fwd_mode_result {
+ cmdline_fixed_string_t set;
+ cmdline_fixed_string_t fwd;
+ cmdline_fixed_string_t mode;
+};
+
+static void cmd_set_fwd_mode_parsed(void *parsed_result,
+ __attribute__((unused)) struct cmdline *cl,
+ __attribute__((unused)) void *data)
+{
+ struct cmd_set_fwd_mode_result *res = parsed_result;
+
+ set_pkt_forwarding_mode(res->mode);
+}
+
+cmdline_parse_token_string_t cmd_setfwd_set =
+ TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
+cmdline_parse_token_string_t cmd_setfwd_fwd =
+ TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
+cmdline_parse_token_string_t cmd_setfwd_mode =
+ TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
+ "" /* defined at init */);
+
+cmdline_parse_inst_t cmd_set_fwd_mode = {
+ .f = cmd_set_fwd_mode_parsed,
+ .data = NULL,
+ .help_str = NULL, /* defined at init */
+ .tokens = {
+ (void *)&cmd_setfwd_set,
+ (void *)&cmd_setfwd_fwd,
+ (void *)&cmd_setfwd_mode,
+ NULL,
+ },
+};
+
+static void cmd_set_fwd_mode_init(void)
+{
+ char *modes, *c;
+ static char token[128];
+ static char help[256];
+ cmdline_parse_token_string_t *token_struct;
+
+ modes = list_pkt_forwarding_modes();
+ snprintf(help, sizeof help, "set fwd %s - "
+ "set packet forwarding mode", modes);
+ cmd_set_fwd_mode.help_str = help;
+
+ /* string token separator is # */
+ for (c = token; *modes != '\0'; modes++)
+ if (*modes == '|')
+ *c++ = '#';
+ else
+ *c++ = *modes;
+ token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
+ token_struct->string_data.str = token;
+}
+
+/* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
+struct cmd_set_burst_tx_retry_result {
+ cmdline_fixed_string_t set;
+ cmdline_fixed_string_t burst;
+ cmdline_fixed_string_t tx;
+ cmdline_fixed_string_t delay;
+ uint32_t time;
+ cmdline_fixed_string_t retry;
+ uint32_t retry_num;
+};
+
+static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
+ __attribute__((unused)) struct cmdline *cl,
+ __attribute__((unused)) void *data)
+{
+ struct cmd_set_burst_tx_retry_result *res = parsed_result;
+
+ if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
+ && !strcmp(res->tx, "tx")) {
+ if (!strcmp(res->delay, "delay"))
+ burst_tx_delay_time = res->time;
+ if (!strcmp(res->retry, "retry"))
+ burst_tx_retry_num = res->retry_num;
+ }
+
+}
+
+cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
+ TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
+cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
+ TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
+ "burst");
+cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
+ TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
+cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
+ TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
+cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
+ TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
+cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
+ TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
+cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
+ TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
+
+cmdline_parse_inst_t cmd_set_burst_tx_retry = {
+ .f = cmd_set_burst_tx_retry_parsed,
+ .help_str = "set burst tx delay (time_by_useconds) retry (retry_num)",
+ .tokens = {
+ (void *)&cmd_set_burst_tx_retry_set,
+ (void *)&cmd_set_burst_tx_retry_burst,
+ (void *)&cmd_set_burst_tx_retry_tx,
+ (void *)&cmd_set_burst_tx_retry_delay,
+ (void *)&cmd_set_burst_tx_retry_time,
+ (void *)&cmd_set_burst_tx_retry_retry,
+ (void *)&cmd_set_burst_tx_retry_retry_num,
+ NULL,
+ },
+};
+
+/* *** SET PROMISC MODE *** */
+struct cmd_set_promisc_mode_result {
+ cmdline_fixed_string_t set;
+ cmdline_fixed_string_t promisc;
+ cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
+ uint8_t port_num; /* valid if "allports" argument == 0 */
+ cmdline_fixed_string_t mode;
+};
+
+static void cmd_set_promisc_mode_parsed(void *parsed_result,
+ __attribute__((unused)) struct cmdline *cl,
+ void *allports)
+{
+ struct cmd_set_promisc_mode_result *res = parsed_result;
+ int enable;
+ portid_t i;
+
+ if (!strcmp(res->mode, "on"))
+ enable = 1;
+ else
+ enable = 0;
+
+ /* all ports */
+ if (allports) {
+ for (i = 0; i < nb_ports; i++) {
+ if (enable)
+ rte_eth_promiscuous_enable(i);
+ else
+ rte_eth_promiscuous_disable(i);
+ }
+ }
+ else {
+ if (enable)
+ rte_eth_promiscuous_enable(res->port_num);
+ else
+ rte_eth_promiscuous_disable(res->port_num);
+ }
+}
+
+cmdline_parse_token_string_t cmd_setpromisc_set =
+ TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
+cmdline_parse_token_string_t cmd_setpromisc_promisc =
+ TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
+ "promisc");
+cmdline_parse_token_string_t cmd_setpromisc_portall =
+ TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
+ "all");
+cmdline_parse_token_num_t cmd_setpromisc_portnum =
+ TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
+ UINT8);
+cmdline_parse_token_string_t cmd_setpromisc_mode =
+ TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
+ "on#off");
+
+cmdline_parse_inst_t cmd_set_promisc_mode_all = {
+ .f = cmd_set_promisc_mode_parsed,
+ .data = (void *)1,
+ .help_str = "set promisc all on|off: set promisc mode for all ports",
+ .tokens = {
+ (void *)&cmd_setpromisc_set,
+ (void *)&cmd_setpromisc_promisc,
+ (void *)&cmd_setpromisc_portall,
+ (void *)&cmd_setpromisc_mode,
+ NULL,
+ },
+};
+
+cmdline_parse_inst_t cmd_set_promisc_mode_one = {
+ .f = cmd_set_promisc_mode_parsed,
+ .data = (void *)0,
+ .help_str = "set promisc X on|off: set promisc mode on port X",
+ .tokens = {
+ (void *)&cmd_setpromisc_set,
+ (void *)&cmd_setpromisc_promisc,
+ (void *)&cmd_setpromisc_portnum,
+ (void *)&cmd_setpromisc_mode,
+ NULL,
+ },
+};
+
+/* *** SET ALLMULTI MODE *** */
+struct cmd_set_allmulti_mode_result {
+ cmdline_fixed_string_t set;
+ cmdline_fixed_string_t allmulti;
+ cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
+ uint8_t port_num; /* valid if "allports" argument == 0 */
+ cmdline_fixed_string_t mode;
+};
+
+static void cmd_set_allmulti_mode_parsed(void *parsed_result,
+ __attribute__((unused)) struct cmdline *cl,
+ void *allports)
+{
+ struct cmd_set_allmulti_mode_result *res = parsed_result;
+ int enable;
+ portid_t i;
+
+ if (!strcmp(res->mode, "on"))
+ enable = 1;
+ else
+ enable = 0;
+
+ /* all ports */
+ if (allports) {
+ for (i = 0; i < nb_ports; i++) {
+ if (enable)
+ rte_eth_allmulticast_enable(i);
+ else
+ rte_eth_allmulticast_disable(i);
+ }
+ }
+ else {
+ if (enable)
+ rte_eth_allmulticast_enable(res->port_num);
+ else
+ rte_eth_allmulticast_disable(res->port_num);
+ }
+}
+
+cmdline_parse_token_string_t cmd_setallmulti_set =
+ TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
+cmdline_parse_token_string_t cmd_setallmulti_allmulti =
+ TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
+ "allmulti");
+cmdline_parse_token_string_t cmd_setallmulti_portall =
+ TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
+ "all");
+cmdline_parse_token_num_t cmd_setallmulti_portnum =
+ TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
+ UINT8);
+cmdline_parse_token_string_t cmd_setallmulti_mode =
+ TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
+ "on#off");
+
+cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
+ .f = cmd_set_allmulti_mode_parsed,
+ .data = (void *)1,
+ .help_str = "set allmulti all on|off: set allmulti mode for all ports",
+ .tokens = {
+ (void *)&cmd_setallmulti_set,
+ (void *)&cmd_setallmulti_allmulti,
+ (void *)&cmd_setallmulti_portall,
+ (void *)&cmd_setallmulti_mode,
+ NULL,
+ },
+};
+
+cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
+ .f = cmd_set_allmulti_mode_parsed,
+ .data = (void *)0,
+ .help_str = "set allmulti X on|off: set allmulti mode on port X",
+ .tokens = {
+ (void *)&cmd_setallmulti_set,
+ (void *)&cmd_setallmulti_allmulti,
+ (void *)&cmd_setallmulti_portnum,
+ (void *)&cmd_setallmulti_mode,
+ NULL,
+ },
+};
+
+/* *** ADD/REMOVE A PKT FILTER *** */
+struct cmd_pkt_filter_result {
+ cmdline_fixed_string_t pkt_filter;
+ uint8_t port_id;
+ cmdline_fixed_string_t protocol;
+ cmdline_fixed_string_t src;
+ cmdline_ipaddr_t ip_src;
+ uint16_t port_src;
+ cmdline_fixed_string_t dst;
+ cmdline_ipaddr_t ip_dst;
+ uint16_t port_dst;
+ cmdline_fixed_string_t flexbytes;
+ uint16_t flexbytes_value;
+ cmdline_fixed_string_t vlan;
+ uint16_t vlan_id;
+ cmdline_fixed_string_t queue;
+ int8_t queue_id;
+ cmdline_fixed_string_t soft;
+ uint8_t soft_id;
+};
+
+static void
+cmd_pkt_filter_parsed(void *parsed_result,
+ __attribute__((unused)) struct cmdline *cl,
+ __attribute__((unused)) void *data)
+{
+ struct rte_fdir_filter fdir_filter;
+ struct cmd_pkt_filter_result *res = parsed_result;
+
+ memset(&fdir_filter, 0, sizeof(struct rte_fdir_filter));
+
+ if (res->ip_src.family == AF_INET)
+ fdir_filter.ip_src.ipv4_addr = res->ip_src.addr.ipv4.s_addr;
+ else
+ memcpy(&(fdir_filter.ip_src.ipv6_addr),
+ &(res->ip_src.addr.ipv6),
+ sizeof(struct in6_addr));
+
+ if (res->ip_dst.family == AF_INET)
+ fdir_filter.ip_dst.ipv4_addr = res->ip_dst.addr.ipv4.s_addr;
+ else
+ memcpy(&(fdir_filter.ip_dst.ipv6_addr),
+ &(res->ip_dst.addr.ipv6),
+ sizeof(struct in6_addr));
+
+ fdir_filter.port_dst = rte_cpu_to_be_16(res->port_dst);
+ fdir_filter.port_src = rte_cpu_to_be_16(res->port_src);
+
+ if (!strcmp(res->protocol, "udp"))
+ fdir_filter.l4type = RTE_FDIR_L4TYPE_UDP;
+ else if (!strcmp(res->protocol, "tcp"))
+ fdir_filter.l4type = RTE_FDIR_L4TYPE_TCP;
+ else if (!strcmp(res->protocol, "sctp"))
+ fdir_filter.l4type = RTE_FDIR_L4TYPE_SCTP;
+ else /* default only IP */
+ fdir_filter.l4type = RTE_FDIR_L4TYPE_NONE;
+
+ if (res->ip_dst.family == AF_INET6)
+ fdir_filter.iptype = RTE_FDIR_IPTYPE_IPV6;
+ else
+ fdir_filter.iptype = RTE_FDIR_IPTYPE_IPV4;
+
+ fdir_filter.vlan_id = rte_cpu_to_be_16(res->vlan_id);
+ fdir_filter.flex_bytes = rte_cpu_to_be_16(res->flexbytes_value);
+
+ if (!strcmp(res->pkt_filter, "add_signature_filter"))
+ fdir_add_signature_filter(res->port_id, res->queue_id,
+ &fdir_filter);
+ else if (!strcmp(res->pkt_filter, "upd_signature_filter"))
+ fdir_update_signature_filter(res->port_id, res->queue_id,
+ &fdir_filter);
+ else if (!strcmp(res->pkt_filter, "rm_signature_filter"))
+ fdir_remove_signature_filter(res->port_id, &fdir_filter);
+ else if (!strcmp(res->pkt_filter, "add_perfect_filter"))
+ fdir_add_perfect_filter(res->port_id, res->soft_id,
+ res->queue_id,
+ (uint8_t) (res->queue_id < 0),
+ &fdir_filter);
+ else if (!strcmp(res->pkt_filter, "upd_perfect_filter"))
+ fdir_update_perfect_filter(res->port_id, res->soft_id,
+ res->queue_id,
+ (uint8_t) (res->queue_id < 0),
+ &fdir_filter);
+ else if (!strcmp(res->pkt_filter, "rm_perfect_filter"))
+ fdir_remove_perfect_filter(res->port_id, res->soft_id,
+ &fdir_filter);
+
+}
+
+
+cmdline_parse_token_num_t cmd_pkt_filter_port_id =
+ TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
+ port_id, UINT8);
+cmdline_parse_token_string_t cmd_pkt_filter_protocol =
+ TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
+ protocol, "ip#tcp#udp#sctp");
+cmdline_parse_token_string_t cmd_pkt_filter_src =
+ TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
+ src, "src");
+cmdline_parse_token_ipaddr_t cmd_pkt_filter_ip_src =
+ TOKEN_IPADDR_INITIALIZER(struct cmd_pkt_filter_result,
+ ip_src);
+cmdline_parse_token_num_t cmd_pkt_filter_port_src =
+ TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
+ port_src, UINT16);
+cmdline_parse_token_string_t cmd_pkt_filter_dst =
+ TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
+ dst, "dst");
+cmdline_parse_token_ipaddr_t cmd_pkt_filter_ip_dst =
+ TOKEN_IPADDR_INITIALIZER(struct cmd_pkt_filter_result,
+ ip_dst);
+cmdline_parse_token_num_t cmd_pkt_filter_port_dst =
+ TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
+ port_dst, UINT16);
+cmdline_parse_token_string_t cmd_pkt_filter_flexbytes =
+ TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
+ flexbytes, "flexbytes");
+cmdline_parse_token_num_t cmd_pkt_filter_flexbytes_value =
+ TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
+ flexbytes_value, UINT16);
+cmdline_parse_token_string_t cmd_pkt_filter_vlan =
+ TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
+ vlan, "vlan");
+cmdline_parse_token_num_t cmd_pkt_filter_vlan_id =
+ TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
+ vlan_id, UINT16);
+cmdline_parse_token_string_t cmd_pkt_filter_queue =
+ TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
+ queue, "queue");
+cmdline_parse_token_num_t cmd_pkt_filter_queue_id =
+ TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
+ queue_id, INT8);
+cmdline_parse_token_string_t cmd_pkt_filter_soft =
+ TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
+ soft, "soft");
+cmdline_parse_token_num_t cmd_pkt_filter_soft_id =
+ TOKEN_NUM_INITIALIZER(struct cmd_pkt_filter_result,
+ soft_id, UINT16);
+
+
+cmdline_parse_token_string_t cmd_pkt_filter_add_signature_filter =
+ TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
+ pkt_filter, "add_signature_filter");
+cmdline_parse_inst_t cmd_add_signature_filter = {
+ .f = cmd_pkt_filter_parsed,
+ .data = NULL,
+ .help_str = "add a signature filter",
+ .tokens = {
+ (void *)&cmd_pkt_filter_add_signature_filter,
+ (void *)&cmd_pkt_filter_port_id,
+ (void *)&cmd_pkt_filter_protocol,
+ (void *)&cmd_pkt_filter_src,
+ (void *)&cmd_pkt_filter_ip_src,
+ (void *)&cmd_pkt_filter_port_src,
+ (void *)&cmd_pkt_filter_dst,
+ (void *)&cmd_pkt_filter_ip_dst,
+ (void *)&cmd_pkt_filter_port_dst,
+ (void *)&cmd_pkt_filter_flexbytes,
+ (void *)&cmd_pkt_filter_flexbytes_value,
+ (void *)&cmd_pkt_filter_vlan,
+ (void *)&cmd_pkt_filter_vlan_id,
+ (void *)&cmd_pkt_filter_queue,
+ (void *)&cmd_pkt_filter_queue_id,
+ NULL,
+ },
+};
+
+
+cmdline_parse_token_string_t cmd_pkt_filter_upd_signature_filter =
+ TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
+ pkt_filter, "upd_signature_filter");
+cmdline_parse_inst_t cmd_upd_signature_filter = {
+ .f = cmd_pkt_filter_parsed,
+ .data = NULL,
+ .help_str = "update a signature filter",
+ .tokens = {
+ (void *)&cmd_pkt_filter_upd_signature_filter,
+ (void *)&cmd_pkt_filter_port_id,
+ (void *)&cmd_pkt_filter_protocol,
+ (void *)&cmd_pkt_filter_src,
+ (void *)&cmd_pkt_filter_ip_src,
+ (void *)&cmd_pkt_filter_port_src,
+ (void *)&cmd_pkt_filter_dst,
+ (void *)&cmd_pkt_filter_ip_dst,
+ (void *)&cmd_pkt_filter_port_dst,
+ (void *)&cmd_pkt_filter_flexbytes,
+ (void *)&cmd_pkt_filter_flexbytes_value,
+ (void *)&cmd_pkt_filter_vlan,
+ (void *)&cmd_pkt_filter_vlan_id,
+ (void *)&cmd_pkt_filter_queue,
+ (void *)&cmd_pkt_filter_queue_id,
+ NULL,
+ },
+};
+
+
+cmdline_parse_token_string_t cmd_pkt_filter_rm_signature_filter =
+ TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
+ pkt_filter, "rm_signature_filter");
+cmdline_parse_inst_t cmd_rm_signature_filter = {
+ .f = cmd_pkt_filter_parsed,
+ .data = NULL,
+ .help_str = "remove a signature filter",
+ .tokens = {
+ (void *)&cmd_pkt_filter_rm_signature_filter,
+ (void *)&cmd_pkt_filter_port_id,
+ (void *)&cmd_pkt_filter_protocol,
+ (void *)&cmd_pkt_filter_src,
+ (void *)&cmd_pkt_filter_ip_src,
+ (void *)&cmd_pkt_filter_port_src,
+ (void *)&cmd_pkt_filter_dst,
+ (void *)&cmd_pkt_filter_ip_dst,
+ (void *)&cmd_pkt_filter_port_dst,
+ (void *)&cmd_pkt_filter_flexbytes,
+ (void *)&cmd_pkt_filter_flexbytes_value,
+ (void *)&cmd_pkt_filter_vlan,
+ (void *)&cmd_pkt_filter_vlan_id,
+ NULL
+ },
+};
+
+
+cmdline_parse_token_string_t cmd_pkt_filter_add_perfect_filter =
+ TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
+ pkt_filter, "add_perfect_filter");
+cmdline_parse_inst_t cmd_add_perfect_filter = {
+ .f = cmd_pkt_filter_parsed,
+ .data = NULL,
+ .help_str = "add a perfect filter",
+ .tokens = {
+ (void *)&cmd_pkt_filter_add_perfect_filter,
+ (void *)&cmd_pkt_filter_port_id,
+ (void *)&cmd_pkt_filter_protocol,
+ (void *)&cmd_pkt_filter_src,
+ (void *)&cmd_pkt_filter_ip_src,
+ (void *)&cmd_pkt_filter_port_src,
+ (void *)&cmd_pkt_filter_dst,
+ (void *)&cmd_pkt_filter_ip_dst,
+ (void *)&cmd_pkt_filter_port_dst,
+ (void *)&cmd_pkt_filter_flexbytes,
+ (void *)&cmd_pkt_filter_flexbytes_value,
+ (void *)&cmd_pkt_filter_vlan,
+ (void *)&cmd_pkt_filter_vlan_id,
+ (void *)&cmd_pkt_filter_queue,
+ (void *)&cmd_pkt_filter_queue_id,
+ (void *)&cmd_pkt_filter_soft,
+ (void *)&cmd_pkt_filter_soft_id,
+ NULL,
+ },
+};
+
+
+cmdline_parse_token_string_t cmd_pkt_filter_upd_perfect_filter =
+ TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
+ pkt_filter, "upd_perfect_filter");
+cmdline_parse_inst_t cmd_upd_perfect_filter = {
+ .f = cmd_pkt_filter_parsed,
+ .data = NULL,
+ .help_str = "update a perfect filter",
+ .tokens = {
+ (void *)&cmd_pkt_filter_upd_perfect_filter,
+ (void *)&cmd_pkt_filter_port_id,
+ (void *)&cmd_pkt_filter_protocol,
+ (void *)&cmd_pkt_filter_src,
+ (void *)&cmd_pkt_filter_ip_src,
+ (void *)&cmd_pkt_filter_port_src,
+ (void *)&cmd_pkt_filter_dst,
+ (void *)&cmd_pkt_filter_ip_dst,
+ (void *)&cmd_pkt_filter_port_dst,
+ (void *)&cmd_pkt_filter_flexbytes,
+ (void *)&cmd_pkt_filter_flexbytes_value,
+ (void *)&cmd_pkt_filter_vlan,
+ (void *)&cmd_pkt_filter_vlan_id,
+ (void *)&cmd_pkt_filter_queue,
+ (void *)&cmd_pkt_filter_queue_id,
+ (void *)&cmd_pkt_filter_soft,
+ (void *)&cmd_pkt_filter_soft_id,
+ NULL,
+ },
+};
+
+
+cmdline_parse_token_string_t cmd_pkt_filter_rm_perfect_filter =
+ TOKEN_STRING_INITIALIZER(struct cmd_pkt_filter_result,
+ pkt_filter, "rm_perfect_filter");
+cmdline_parse_inst_t cmd_rm_perfect_filter = {
+ .f = cmd_pkt_filter_parsed,
+ .data = NULL,
+ .help_str = "remove a perfect filter",
+ .tokens = {
+ (void *)&cmd_pkt_filter_rm_perfect_filter,
+ (void *)&cmd_pkt_filter_port_id,
+ (void *)&cmd_pkt_filter_protocol,
+ (void *)&cmd_pkt_filter_src,
+ (void *)&cmd_pkt_filter_ip_src,
+ (void *)&cmd_pkt_filter_port_src,
+ (void *)&cmd_pkt_filter_dst,
+ (void *)&cmd_pkt_filter_ip_dst,
+ (void *)&cmd_pkt_filter_port_dst,
+ (void *)&cmd_pkt_filter_flexbytes,
+ (void *)&cmd_pkt_filter_flexbytes_value,
+ (void *)&cmd_pkt_filter_vlan,
+ (void *)&cmd_pkt_filter_vlan_id,
+ (void *)&cmd_pkt_filter_soft,
+ (void *)&cmd_pkt_filter_soft_id,
+ NULL,
+ },
+};
+
+/* *** SETUP MASKS FILTER *** */
+struct cmd_pkt_filter_masks_result {
+ cmdline_fixed_string_t filter_mask;
+ uint8_t port_id;
+ cmdline_fixed_string_t src_mask;
+ uint32_t ip_src_mask;
+ uint16_t ipv6_src_mask;
+ uint16_t port_src_mask;
+ cmdline_fixed_string_t dst_mask;
+ uint32_t ip_dst_mask;
+ uint16_t ipv6_dst_mask;
+ uint16_t port_dst_mask;
+ cmdline_fixed_string_t flexbytes;
+ uint8_t flexbytes_value;
+ cmdline_fixed_string_t vlan_id;
+ uint8_t vlan_id_value;
+ cmdline_fixed_string_t vlan_prio;
+ uint8_t vlan_prio_value;
+ cmdline_fixed_string_t only_ip_flow;
+ uint8_t only_ip_flow_value;
+ cmdline_fixed_string_t comp_ipv6_dst;
+ uint8_t comp_ipv6_dst_value;
+};
+
+static void
+cmd_pkt_filter_masks_parsed(void *parsed_result,
+ __attribute__((unused)) struct cmdline *cl,
+ __attribute__((unused)) void *data)
+{
+ struct rte_fdir_masks fdir_masks;
+ struct cmd_pkt_filter_masks_result *res = parsed_result;
+
+ memset(&fdir_masks, 0, sizeof(struct rte_fdir_masks));
+
+ fdir_masks.only_ip_flow = res->only_ip_flow_value;
+ fdir_masks.vlan_id = res->vlan_id_value;
+ fdir_masks.vlan_prio = res->vlan_prio_value;
+ fdir_masks.dst_ipv4_mask = res->ip_dst_mask;
+ fdir_masks.src_ipv4_mask = res->ip_src_mask;
+ fdir_masks.src_port_mask = res->port_src_mask;
+ fdir_masks.dst_port_mask = res->port_dst_mask;
+ fdir_masks.flexbytes = res->flexbytes_value;
+
+ fdir_set_masks(res->port_id, &fdir_masks);
+}
+
+cmdline_parse_token_string_t cmd_pkt_filter_masks_filter_mask =