#define MAX_ITERATIONS 100
#define DEFAULT_RULES_COUNT 4000000
-#define DEFAULT_ITERATION 100000
+#define DEFAULT_RULES_BATCH 100000
+#define DEFAULT_GROUP 0
struct rte_flow *flow;
static uint8_t flow_group;
+static uint64_t encap_data;
+static uint64_t decap_data;
+
static uint64_t flow_items[MAX_ITEMS_NUM];
static uint64_t flow_actions[MAX_ACTIONS_NUM];
static uint64_t flow_attrs[MAX_ATTRS_NUM];
static uint8_t items_idx, actions_idx, attrs_idx;
+static uint64_t ports_mask;
static volatile bool force_quit;
static bool dump_iterations;
static bool delete_flag;
static struct rte_mempool *mbuf_mp;
static uint32_t nb_lcores;
-static uint32_t flows_count;
-static uint32_t iterations_number;
+static uint32_t rules_count;
+static uint32_t rules_batch;
static uint32_t hairpin_queues_num; /* total hairpin q number - default: 0 */
static uint32_t nb_lcores;
{
printf("\nusage: %s\n", progname);
printf("\nControl configurations:\n");
- printf(" --flows-count=N: to set the number of needed"
- " flows to insert, default is 4,000,000\n");
+ printf(" --rules-count=N: to set the number of needed"
+ " rules to insert, default is %d\n", DEFAULT_RULES_COUNT);
+ printf(" --rules-batch=N: set number of batched rules,"
+ " default is %d\n", DEFAULT_RULES_BATCH);
printf(" --dump-iterations: To print rates for each"
" iteration\n");
printf(" --deletion-rate: Enable deletion rate"
printf(" --dump-socket-mem: To dump all socket memory\n");
printf(" --enable-fwd: To enable packets forwarding"
" after insertion\n");
+ printf(" --portmask=N: hexadecimal bitmask of ports used\n");
printf("To set flow attributes:\n");
printf(" --ingress: set ingress attribute in flows\n");
printf(" --egress: set egress attribute in flows\n");
printf(" --transfer: set transfer attribute in flows\n");
printf(" --group=N: set group for all flows,"
- " default is 0\n");
+ " default is %d\n", DEFAULT_GROUP);
printf("To set flow items:\n");
printf(" --ether: add ether layer in flow items\n");
printf(" --gtp: add gtp layer in flow items\n");
printf(" --meta: add meta layer in flow items\n");
printf(" --tag: add tag layer in flow items\n");
+ printf(" --icmpv4: add icmpv4 layer in flow items\n");
+ printf(" --icmpv6: add icmpv6 layer in flow items\n");
printf("To set flow actions:\n");
printf(" --port-id: add port-id action in flow actions\n");
printf(" --drop: add drop action in flow actions\n");
printf(" --hairpin-queue=N: add hairpin-queue action in flow actions\n");
printf(" --hairpin-rss=N: add hairpin-rss action in flow actions\n");
+ printf(" --set-src-mac: add set src mac action to flow actions\n"
+ "Src mac to be set is random each flow\n");
+ printf(" --set-dst-mac: add set dst mac action to flow actions\n"
+ "Dst mac to be set is random each flow\n");
+ printf(" --set-src-ipv4: add set src ipv4 action to flow actions\n"
+ "Src ipv4 to be set is random each flow\n");
+ printf(" --set-dst-ipv4 add set dst ipv4 action to flow actions\n"
+ "Dst ipv4 to be set is random each flow\n");
+ printf(" --set-src-ipv6: add set src ipv6 action to flow actions\n"
+ "Src ipv6 to be set is random each flow\n");
+ printf(" --set-dst-ipv6: add set dst ipv6 action to flow actions\n"
+ "Dst ipv6 to be set is random each flow\n");
+ printf(" --set-src-tp: add set src tp action to flow actions\n"
+ "Src tp to be set is random each flow\n");
+ printf(" --set-dst-tp: add set dst tp action to flow actions\n"
+ "Dst tp to be set is random each flow\n");
+ printf(" --inc-tcp-ack: add inc tcp ack action to flow actions\n"
+ "tcp ack will be increments by 1\n");
+ printf(" --dec-tcp-ack: add dec tcp ack action to flow actions\n"
+ "tcp ack will be decrements by 1\n");
+ printf(" --inc-tcp-seq: add inc tcp seq action to flow actions\n"
+ "tcp seq will be increments by 1\n");
+ printf(" --dec-tcp-seq: add dec tcp seq action to flow actions\n"
+ "tcp seq will be decrements by 1\n");
+ printf(" --set-ttl: add set ttl action to flow actions\n"
+ "L3 ttl to be set is random each flow\n");
+ printf(" --dec-ttl: add dec ttl action to flow actions\n"
+ "L3 ttl will be decrements by 1\n");
+ printf(" --set-ipv4-dscp: add set ipv4 dscp action to flow actions\n"
+ "ipv4 dscp value to be set is random each flow\n");
+ printf(" --set-ipv6-dscp: add set ipv6 dscp action to flow actions\n"
+ "ipv6 dscp value to be set is random each flow\n");
+ printf(" --flag: add flag action to flow actions\n");
+ printf(" --raw-encap=<data>: add raw encap action to flow actions\n"
+ "Data is the data needed to be encaped\n"
+ "Example: raw-encap=ether,ipv4,udp,vxlan\n");
+ printf(" --raw-decap=<data>: add raw decap action to flow actions\n"
+ "Data is the data needed to be decaped\n"
+ "Example: raw-decap=ether,ipv4,udp,vxlan\n");
+ printf(" --vxlan-encap: add vxlan-encap action to flow actions\n"
+ "Encapped data is fixed with pattern: ether,ipv4,udp,vxlan\n"
+ "With fixed values\n");
+ printf(" --vxlan-decap: add vxlan_decap action to flow actions\n");
}
static void
args_parse(int argc, char **argv)
{
+ uint64_t pm;
char **argvopt;
+ char *token;
+ char *end;
int n, opt;
int opt_idx;
size_t i;
.map = &flow_items[0],
.map_idx = &items_idx
},
+ {
+ .str = "icmpv4",
+ .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_ICMP),
+ .map = &flow_items[0],
+ .map_idx = &items_idx
+ },
+ {
+ .str = "icmpv6",
+ .mask = FLOW_ITEM_MASK(RTE_FLOW_ITEM_TYPE_ICMP6),
+ .map = &flow_items[0],
+ .map_idx = &items_idx
+ },
{
.str = "ingress",
.mask = INGRESS,
.mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_DROP),
.map = &flow_actions[0],
.map_idx = &actions_idx
- }
+ },
+ {
+ .str = "set-src-mac",
+ .mask = FLOW_ACTION_MASK(
+ RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
+ ),
+ .map = &flow_actions[0],
+ .map_idx = &actions_idx
+ },
+ {
+ .str = "set-dst-mac",
+ .mask = FLOW_ACTION_MASK(
+ RTE_FLOW_ACTION_TYPE_SET_MAC_DST
+ ),
+ .map = &flow_actions[0],
+ .map_idx = &actions_idx
+ },
+ {
+ .str = "set-src-ipv4",
+ .mask = FLOW_ACTION_MASK(
+ RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC
+ ),
+ .map = &flow_actions[0],
+ .map_idx = &actions_idx
+ },
+ {
+ .str = "set-dst-ipv4",
+ .mask = FLOW_ACTION_MASK(
+ RTE_FLOW_ACTION_TYPE_SET_IPV4_DST
+ ),
+ .map = &flow_actions[0],
+ .map_idx = &actions_idx
+ },
+ {
+ .str = "set-src-ipv6",
+ .mask = FLOW_ACTION_MASK(
+ RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC
+ ),
+ .map = &flow_actions[0],
+ .map_idx = &actions_idx
+ },
+ {
+ .str = "set-dst-ipv6",
+ .mask = FLOW_ACTION_MASK(
+ RTE_FLOW_ACTION_TYPE_SET_IPV6_DST
+ ),
+ .map = &flow_actions[0],
+ .map_idx = &actions_idx
+ },
+ {
+ .str = "set-src-tp",
+ .mask = FLOW_ACTION_MASK(
+ RTE_FLOW_ACTION_TYPE_SET_TP_SRC
+ ),
+ .map = &flow_actions[0],
+ .map_idx = &actions_idx
+ },
+ {
+ .str = "set-dst-tp",
+ .mask = FLOW_ACTION_MASK(
+ RTE_FLOW_ACTION_TYPE_SET_TP_DST
+ ),
+ .map = &flow_actions[0],
+ .map_idx = &actions_idx
+ },
+ {
+ .str = "inc-tcp-ack",
+ .mask = FLOW_ACTION_MASK(
+ RTE_FLOW_ACTION_TYPE_INC_TCP_ACK
+ ),
+ .map = &flow_actions[0],
+ .map_idx = &actions_idx
+ },
+ {
+ .str = "dec-tcp-ack",
+ .mask = FLOW_ACTION_MASK(
+ RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK
+ ),
+ .map = &flow_actions[0],
+ .map_idx = &actions_idx
+ },
+ {
+ .str = "inc-tcp-seq",
+ .mask = FLOW_ACTION_MASK(
+ RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ
+ ),
+ .map = &flow_actions[0],
+ .map_idx = &actions_idx
+ },
+ {
+ .str = "dec-tcp-seq",
+ .mask = FLOW_ACTION_MASK(
+ RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ
+ ),
+ .map = &flow_actions[0],
+ .map_idx = &actions_idx
+ },
+ {
+ .str = "set-ttl",
+ .mask = FLOW_ACTION_MASK(
+ RTE_FLOW_ACTION_TYPE_SET_TTL
+ ),
+ .map = &flow_actions[0],
+ .map_idx = &actions_idx
+ },
+ {
+ .str = "dec-ttl",
+ .mask = FLOW_ACTION_MASK(
+ RTE_FLOW_ACTION_TYPE_DEC_TTL
+ ),
+ .map = &flow_actions[0],
+ .map_idx = &actions_idx
+ },
+ {
+ .str = "set-ipv4-dscp",
+ .mask = FLOW_ACTION_MASK(
+ RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP
+ ),
+ .map = &flow_actions[0],
+ .map_idx = &actions_idx
+ },
+ {
+ .str = "set-ipv6-dscp",
+ .mask = FLOW_ACTION_MASK(
+ RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP
+ ),
+ .map = &flow_actions[0],
+ .map_idx = &actions_idx
+ },
+ {
+ .str = "flag",
+ .mask = FLOW_ACTION_MASK(
+ RTE_FLOW_ACTION_TYPE_FLAG
+ ),
+ .map = &flow_actions[0],
+ .map_idx = &actions_idx
+ },
+ {
+ .str = "vxlan-encap",
+ .mask = FLOW_ACTION_MASK(
+ RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP
+ ),
+ .map = &flow_actions[0],
+ .map_idx = &actions_idx
+ },
+ {
+ .str = "vxlan-decap",
+ .mask = FLOW_ACTION_MASK(
+ RTE_FLOW_ACTION_TYPE_VXLAN_DECAP
+ ),
+ .map = &flow_actions[0],
+ .map_idx = &actions_idx
+ },
};
static const struct option lgopts[] = {
/* Control */
{ "help", 0, 0, 0 },
- { "flows-count", 1, 0, 0 },
+ { "rules-count", 1, 0, 0 },
+ { "rules-batch", 1, 0, 0 },
{ "dump-iterations", 0, 0, 0 },
{ "deletion-rate", 0, 0, 0 },
{ "dump-socket-mem", 0, 0, 0 },
{ "enable-fwd", 0, 0, 0 },
+ { "portmask", 1, 0, 0 },
/* Attributes */
{ "ingress", 0, 0, 0 },
{ "egress", 0, 0, 0 },
{ "gtp", 0, 0, 0 },
{ "meta", 0, 0, 0 },
{ "tag", 0, 0, 0 },
+ { "icmpv4", 0, 0, 0 },
+ { "icmpv6", 0, 0, 0 },
/* Actions */
{ "port-id", 0, 0, 0 },
{ "rss", 0, 0, 0 },
{ "drop", 0, 0, 0 },
{ "hairpin-queue", 1, 0, 0 },
{ "hairpin-rss", 1, 0, 0 },
+ { "set-src-mac", 0, 0, 0 },
+ { "set-dst-mac", 0, 0, 0 },
+ { "set-src-ipv4", 0, 0, 0 },
+ { "set-dst-ipv4", 0, 0, 0 },
+ { "set-src-ipv6", 0, 0, 0 },
+ { "set-dst-ipv6", 0, 0, 0 },
+ { "set-src-tp", 0, 0, 0 },
+ { "set-dst-tp", 0, 0, 0 },
+ { "inc-tcp-ack", 0, 0, 0 },
+ { "dec-tcp-ack", 0, 0, 0 },
+ { "inc-tcp-seq", 0, 0, 0 },
+ { "dec-tcp-seq", 0, 0, 0 },
+ { "set-ttl", 0, 0, 0 },
+ { "dec-ttl", 0, 0, 0 },
+ { "set-ipv4-dscp", 0, 0, 0 },
+ { "set-ipv6-dscp", 0, 0, 0 },
+ { "flag", 0, 0, 0 },
+ { "raw-encap", 1, 0, 0 },
+ { "raw-decap", 1, 0, 0 },
+ { "vxlan-encap", 0, 0, 0 },
+ { "vxlan-decap", 0, 0, 0 },
};
+ RTE_ETH_FOREACH_DEV(i)
+ ports_mask |= 1 << i;
+
hairpin_queues_num = 0;
argvopt = argv;
else
rte_exit(EXIT_SUCCESS,
"flow group should be >= 0\n");
- printf("group %d ", flow_group);
+ printf("group %d / ", flow_group);
}
for (i = 0; i < RTE_DIM(flow_options); i++)
printf("hairpin-queue / ");
}
+ if (strcmp(lgopts[opt_idx].name, "raw-encap") == 0) {
+ printf("raw-encap ");
+ flow_actions[actions_idx++] =
+ FLOW_ITEM_MASK(
+ RTE_FLOW_ACTION_TYPE_RAW_ENCAP
+ );
+
+ token = strtok(optarg, ",");
+ while (token != NULL) {
+ for (i = 0; i < RTE_DIM(flow_options); i++) {
+ if (strcmp(flow_options[i].str, token) == 0) {
+ printf("%s,", token);
+ encap_data |= flow_options[i].mask;
+ break;
+ }
+ /* Reached last item with no match */
+ if (i == (RTE_DIM(flow_options) - 1)) {
+ fprintf(stderr, "Invalid encap item: %s\n", token);
+ usage(argv[0]);
+ rte_exit(EXIT_SUCCESS, "Invalid encap item\n");
+ }
+ }
+ token = strtok(NULL, ",");
+ }
+ printf(" / ");
+ }
+ if (strcmp(lgopts[opt_idx].name, "raw-decap") == 0) {
+ printf("raw-decap ");
+ flow_actions[actions_idx++] =
+ FLOW_ITEM_MASK(
+ RTE_FLOW_ACTION_TYPE_RAW_DECAP
+ );
+
+ token = strtok(optarg, ",");
+ while (token != NULL) {
+ for (i = 0; i < RTE_DIM(flow_options); i++) {
+ if (strcmp(flow_options[i].str, token) == 0) {
+ printf("%s,", token);
+ encap_data |= flow_options[i].mask;
+ break;
+ }
+ /* Reached last item with no match */
+ if (i == (RTE_DIM(flow_options) - 1)) {
+ fprintf(stderr, "Invalid decap item: %s\n", token);
+ usage(argv[0]);
+ rte_exit(EXIT_SUCCESS, "Invalid decap item\n");
+ }
+ }
+ token = strtok(NULL, ",");
+ }
+ printf(" / ");
+ }
/* Control */
if (strcmp(lgopts[opt_idx].name,
- "flows-count") == 0) {
+ "rules-batch") == 0) {
n = atoi(optarg);
- if (n > (int) iterations_number)
- flows_count = n;
+ if (n >= DEFAULT_RULES_BATCH)
+ rules_batch = n;
else {
- printf("\n\nflows_count should be > %d\n",
- iterations_number);
+ printf("\n\nrules_batch should be >= %d\n",
+ DEFAULT_RULES_BATCH);
rte_exit(EXIT_SUCCESS, " ");
}
}
+ if (strcmp(lgopts[opt_idx].name,
+ "rules-count") == 0) {
+ n = atoi(optarg);
+ if (n >= (int) rules_batch)
+ rules_count = n;
+ else {
+ printf("\n\nrules_count should be >= %d\n",
+ rules_batch);
+ }
+ }
if (strcmp(lgopts[opt_idx].name,
"dump-iterations") == 0)
dump_iterations = true;
if (strcmp(lgopts[opt_idx].name,
"enable-fwd") == 0)
enable_fwd = true;
+ if (strcmp(lgopts[opt_idx].name,
+ "portmask") == 0) {
+ /* parse hexadecimal string */
+ end = NULL;
+ pm = strtoull(optarg, &end, 16);
+ if ((optarg[0] == '\0') || (end == NULL) || (*end != '\0'))
+ rte_exit(EXIT_FAILURE, "Invalid fwd port mask\n");
+ ports_mask = pm;
+ }
break;
default:
fprintf(stderr, "Invalid option: %s\n", argv[optind]);
for (i = 0; i < MAX_ITERATIONS; i++)
cpu_time_per_iter[i] = -1;
- if (iterations_number > flows_count)
- iterations_number = flows_count;
+ if (rules_batch > rules_count)
+ rules_batch = rules_count;
/* Deletion Rate */
printf("Flows Deletion on port = %d\n", port_id);
start_iter = clock();
- for (i = 0; i < flows_count; i++) {
+ for (i = 0; i < rules_count; i++) {
if (flow_list[i] == 0)
break;
rte_exit(EXIT_FAILURE, "Error in deleting flow");
}
- if (i && !((i + 1) % iterations_number)) {
+ if (i && !((i + 1) % rules_batch)) {
/* Save the deletion rate of each iter */
end_iter = clock();
delta = (double) (end_iter - start_iter);
- iter_id = ((i + 1) / iterations_number) - 1;
+ iter_id = ((i + 1) / rules_batch) - 1;
cpu_time_per_iter[iter_id] =
delta / CLOCKS_PER_SEC;
cpu_time_used += cpu_time_per_iter[iter_id];
for (i = 0; i < MAX_ITERATIONS; i++) {
if (cpu_time_per_iter[i] == -1)
continue;
- delta = (double)(iterations_number /
+ delta = (double)(rules_batch /
cpu_time_per_iter[i]);
flows_rate = delta / 1000;
printf(":: Iteration #%d: %d flows "
"in %f sec[ Rate = %f K/Sec ]\n",
- i, iterations_number,
+ i, rules_batch,
cpu_time_per_iter[i], flows_rate);
}
/* Deletion rate for all flows */
- flows_rate = ((double) (flows_count / cpu_time_used) / 1000);
+ flows_rate = ((double) (rules_count / cpu_time_used) / 1000);
printf("\n:: Total flow deletion rate -> %f K/Sec\n",
flows_rate);
printf(":: The time for deleting %d in flows %f seconds\n",
- flows_count, cpu_time_used);
+ rules_count, cpu_time_used);
}
static inline void
for (i = 0; i < MAX_ITERATIONS; i++)
cpu_time_per_iter[i] = -1;
- if (iterations_number > flows_count)
- iterations_number = flows_count;
+ if (rules_batch > rules_count)
+ rules_batch = rules_count;
- printf(":: Flows Count per port: %d\n", flows_count);
+ printf(":: Flows Count per port: %d\n", rules_count);
flow_list = rte_zmalloc("flow_list",
- (sizeof(struct rte_flow *) * flows_count) + 1, 0);
+ (sizeof(struct rte_flow *) * rules_count) + 1, 0);
if (flow_list == NULL)
rte_exit(EXIT_FAILURE, "No Memory available!");
for (port_id = 0; port_id < nr_ports; port_id++) {
+ /* If port outside portmask */
+ if (!((ports_mask >> port_id) & 0x1))
+ continue;
cpu_time_used = 0;
flow_index = 0;
if (flow_group > 0) {
*/
flow = generate_flow(port_id, 0, flow_attrs,
global_items, global_actions,
- flow_group, 0, 0, &error);
+ flow_group, 0, 0, 0, 0, &error);
if (flow == NULL) {
print_flow_error(error);
/* Insertion Rate */
printf("Flows insertion on port = %d\n", port_id);
start_iter = clock();
- for (i = 0; i < flows_count; i++) {
+ for (i = 0; i < rules_count; i++) {
flow = generate_flow(port_id, flow_group,
flow_attrs, flow_items, flow_actions,
JUMP_ACTION_TABLE, i,
- hairpin_queues_num, &error);
+ hairpin_queues_num,
+ encap_data, decap_data,
+ &error);
if (force_quit)
- i = flows_count;
+ i = rules_count;
if (!flow) {
print_flow_error(error);
flow_list[flow_index++] = flow;
- if (i && !((i + 1) % iterations_number)) {
+ if (i && !((i + 1) % rules_batch)) {
/* Save the insertion rate of each iter */
end_iter = clock();
delta = (double) (end_iter - start_iter);
- iter_id = ((i + 1) / iterations_number) - 1;
+ iter_id = ((i + 1) / rules_batch) - 1;
cpu_time_per_iter[iter_id] =
delta / CLOCKS_PER_SEC;
cpu_time_used += cpu_time_per_iter[iter_id];
for (i = 0; i < MAX_ITERATIONS; i++) {
if (cpu_time_per_iter[i] == -1)
continue;
- delta = (double)(iterations_number /
+ delta = (double)(rules_batch /
cpu_time_per_iter[i]);
flows_rate = delta / 1000;
printf(":: Iteration #%d: %d flows "
"in %f sec[ Rate = %f K/Sec ]\n",
- i, iterations_number,
+ i, rules_batch,
cpu_time_per_iter[i], flows_rate);
}
/* Insertion rate for all flows */
- flows_rate = ((double) (flows_count / cpu_time_used) / 1000);
+ flows_rate = ((double) (rules_count / cpu_time_used) / 1000);
printf("\n:: Total flow insertion rate -> %f K/Sec\n",
flows_rate);
printf(":: The time for creating %d in flows %f seconds\n",
- flows_count, cpu_time_used);
+ rules_count, cpu_time_used);
if (delete_flag)
destroy_flows(port_id, flow_list);
force_quit = false;
dump_iterations = false;
- flows_count = DEFAULT_RULES_COUNT;
- iterations_number = DEFAULT_ITERATION;
+ rules_count = DEFAULT_RULES_COUNT;
+ rules_batch = DEFAULT_RULES_BATCH;
delete_flag = false;
dump_socket_mem_flag = false;
- flow_group = 0;
+ flow_group = DEFAULT_GROUP;
signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);
if (enable_fwd) {
init_lcore_info();
- rte_eal_mp_remote_launch(start_forwarding, NULL, CALL_MASTER);
+ rte_eal_mp_remote_launch(start_forwarding, NULL, CALL_MAIN);
}
RTE_ETH_FOREACH_DEV(port) {
rte_flow_flush(port, &error);
- rte_eth_dev_stop(port);
+ if (rte_eth_dev_stop(port) != 0)
+ printf("Failed to stop device on port %u\n", port);
rte_eth_dev_close(port);
}
return 0;