-/* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
-struct cmd_set_mirror_mask_result {
- cmdline_fixed_string_t set;
- cmdline_fixed_string_t port;
- portid_t port_id;
- cmdline_fixed_string_t mirror;
- uint8_t rule_id;
- cmdline_fixed_string_t what;
- cmdline_fixed_string_t value;
- cmdline_fixed_string_t dstpool;
- uint8_t dstpool_id;
- cmdline_fixed_string_t on;
-};
-
-cmdline_parse_token_string_t cmd_mirror_mask_set =
- TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
- set, "set");
-cmdline_parse_token_string_t cmd_mirror_mask_port =
- TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
- port, "port");
-cmdline_parse_token_num_t cmd_mirror_mask_portid =
- TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
- port_id, RTE_UINT16);
-cmdline_parse_token_string_t cmd_mirror_mask_mirror =
- TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
- mirror, "mirror-rule");
-cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
- TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
- rule_id, RTE_UINT8);
-cmdline_parse_token_string_t cmd_mirror_mask_what =
- TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
- what, "pool-mirror-up#pool-mirror-down"
- "#vlan-mirror");
-cmdline_parse_token_string_t cmd_mirror_mask_value =
- TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
- value, NULL);
-cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
- TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
- dstpool, "dst-pool");
-cmdline_parse_token_num_t cmd_mirror_mask_poolid =
- TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
- dstpool_id, RTE_UINT8);
-cmdline_parse_token_string_t cmd_mirror_mask_on =
- TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
- on, "on#off");
-
-static void
-cmd_set_mirror_mask_parsed(void *parsed_result,
- __rte_unused struct cmdline *cl,
- __rte_unused void *data)
-{
- int ret,nb_item,i;
- struct cmd_set_mirror_mask_result *res = parsed_result;
- struct rte_eth_mirror_conf mr_conf;
-
- memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
-
- unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
-
- mr_conf.dst_pool = res->dstpool_id;
-
- if (!strcmp(res->what, "pool-mirror-up")) {
- mr_conf.pool_mask = strtoull(res->value, NULL, 16);
- mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
- } else if (!strcmp(res->what, "pool-mirror-down")) {
- mr_conf.pool_mask = strtoull(res->value, NULL, 16);
- mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
- } else if (!strcmp(res->what, "vlan-mirror")) {
- mr_conf.rule_type = ETH_MIRROR_VLAN;
- nb_item = parse_item_list(res->value, "vlan",
- ETH_MIRROR_MAX_VLANS, vlan_list, 1);
- if (nb_item <= 0)
- return;
-
- for (i = 0; i < nb_item; i++) {
- if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
- printf("Invalid vlan_id: must be < 4096\n");
- return;
- }
-
- mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
- mr_conf.vlan.vlan_mask |= 1ULL << i;
- }
- }
-
- if (!strcmp(res->on, "on"))
- ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
- res->rule_id, 1);
- else
- ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
- res->rule_id, 0);
- if (ret < 0)
- printf("mirror rule add error: (%s)\n", strerror(-ret));
-}
-
-cmdline_parse_inst_t cmd_set_mirror_mask = {
- .f = cmd_set_mirror_mask_parsed,
- .data = NULL,
- .help_str = "set port <port_id> mirror-rule <rule_id> "
- "pool-mirror-up|pool-mirror-down|vlan-mirror "
- "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
- .tokens = {
- (void *)&cmd_mirror_mask_set,
- (void *)&cmd_mirror_mask_port,
- (void *)&cmd_mirror_mask_portid,
- (void *)&cmd_mirror_mask_mirror,
- (void *)&cmd_mirror_mask_ruleid,
- (void *)&cmd_mirror_mask_what,
- (void *)&cmd_mirror_mask_value,
- (void *)&cmd_mirror_mask_dstpool,
- (void *)&cmd_mirror_mask_poolid,
- (void *)&cmd_mirror_mask_on,
- NULL,
- },
-};
-
-/* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
-struct cmd_set_mirror_link_result {
- cmdline_fixed_string_t set;
- cmdline_fixed_string_t port;
- portid_t port_id;
- cmdline_fixed_string_t mirror;
- uint8_t rule_id;
- cmdline_fixed_string_t what;
- cmdline_fixed_string_t dstpool;
- uint8_t dstpool_id;
- cmdline_fixed_string_t on;
-};
-
-cmdline_parse_token_string_t cmd_mirror_link_set =
- TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
- set, "set");
-cmdline_parse_token_string_t cmd_mirror_link_port =
- TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
- port, "port");
-cmdline_parse_token_num_t cmd_mirror_link_portid =
- TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
- port_id, RTE_UINT16);
-cmdline_parse_token_string_t cmd_mirror_link_mirror =
- TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
- mirror, "mirror-rule");
-cmdline_parse_token_num_t cmd_mirror_link_ruleid =
- TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
- rule_id, RTE_UINT8);
-cmdline_parse_token_string_t cmd_mirror_link_what =
- TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
- what, "uplink-mirror#downlink-mirror");
-cmdline_parse_token_string_t cmd_mirror_link_dstpool =
- TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
- dstpool, "dst-pool");
-cmdline_parse_token_num_t cmd_mirror_link_poolid =
- TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
- dstpool_id, RTE_UINT8);
-cmdline_parse_token_string_t cmd_mirror_link_on =
- TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
- on, "on#off");
-
-static void
-cmd_set_mirror_link_parsed(void *parsed_result,
- __rte_unused struct cmdline *cl,
- __rte_unused void *data)
-{
- int ret;
- struct cmd_set_mirror_link_result *res = parsed_result;
- struct rte_eth_mirror_conf mr_conf;
-
- memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
- if (!strcmp(res->what, "uplink-mirror"))
- mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
- else
- mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
-
- mr_conf.dst_pool = res->dstpool_id;
-
- if (!strcmp(res->on, "on"))
- ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
- res->rule_id, 1);
- else
- ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
- res->rule_id, 0);
-
- /* check the return value and print it if is < 0 */
- if (ret < 0)
- printf("mirror rule add error: (%s)\n", strerror(-ret));
-
-}
-
-cmdline_parse_inst_t cmd_set_mirror_link = {
- .f = cmd_set_mirror_link_parsed,
- .data = NULL,
- .help_str = "set port <port_id> mirror-rule <rule_id> "
- "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
- .tokens = {
- (void *)&cmd_mirror_link_set,
- (void *)&cmd_mirror_link_port,
- (void *)&cmd_mirror_link_portid,
- (void *)&cmd_mirror_link_mirror,
- (void *)&cmd_mirror_link_ruleid,
- (void *)&cmd_mirror_link_what,
- (void *)&cmd_mirror_link_dstpool,
- (void *)&cmd_mirror_link_poolid,
- (void *)&cmd_mirror_link_on,
- NULL,
- },
-};
-
-/* *** RESET VM MIRROR RULE *** */
-struct cmd_rm_mirror_rule_result {
- cmdline_fixed_string_t reset;
- cmdline_fixed_string_t port;
- portid_t port_id;
- cmdline_fixed_string_t mirror;
- uint8_t rule_id;
-};
-
-cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
- TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
- reset, "reset");
-cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
- TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
- port, "port");
-cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
- TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
- port_id, RTE_UINT16);
-cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
- TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
- mirror, "mirror-rule");
-cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
- TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
- rule_id, RTE_UINT8);
-
-static void
-cmd_reset_mirror_rule_parsed(void *parsed_result,
- __rte_unused struct cmdline *cl,
- __rte_unused void *data)
-{
- int ret;
- struct cmd_set_mirror_link_result *res = parsed_result;
- /* check rule_id */
- ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
- if(ret < 0)
- printf("mirror rule remove error: (%s)\n", strerror(-ret));
-}
-
-cmdline_parse_inst_t cmd_reset_mirror_rule = {
- .f = cmd_reset_mirror_rule_parsed,
- .data = NULL,
- .help_str = "reset port <port_id> mirror-rule <rule_id>",
- .tokens = {
- (void *)&cmd_rm_mirror_rule_reset,
- (void *)&cmd_rm_mirror_rule_port,
- (void *)&cmd_rm_mirror_rule_portid,
- (void *)&cmd_rm_mirror_rule_mirror,
- (void *)&cmd_rm_mirror_rule_ruleid,
- NULL,
- },
-};
-