1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
10 #include <rte_common.h>
11 #include <rte_cycles.h>
13 #include "rte_eth_softnic_internals.h"
16 #ifndef CMD_MAX_TOKENS
17 #define CMD_MAX_TOKENS 256
20 #define MSG_OUT_OF_MEMORY "Not enough memory.\n"
21 #define MSG_CMD_UNKNOWN "Unknown command \"%s\".\n"
22 #define MSG_CMD_UNIMPLEM "Command \"%s\" not implemented.\n"
23 #define MSG_ARG_NOT_ENOUGH "Not enough arguments for command \"%s\".\n"
24 #define MSG_ARG_TOO_MANY "Too many arguments for command \"%s\".\n"
25 #define MSG_ARG_MISMATCH "Wrong number of arguments for command \"%s\".\n"
26 #define MSG_ARG_NOT_FOUND "Argument \"%s\" not found.\n"
27 #define MSG_ARG_INVALID "Invalid value for argument \"%s\".\n"
28 #define MSG_FILE_ERR "Error in file \"%s\" at line %u.\n"
29 #define MSG_FILE_NOT_ENOUGH "Not enough rules in file \"%s\".\n"
30 #define MSG_CMD_FAIL "Command \"%s\" failed.\n"
35 if ((strlen(in) && index("!#%;", in[0])) ||
36 (strncmp(in, "//", 2) == 0) ||
37 (strncmp(in, "--", 2) == 0))
44 * mempool <mempool_name>
45 * buffer <buffer_size>
50 cmd_mempool(struct pmd_internals *softnic,
56 struct softnic_mempool_params p;
58 struct softnic_mempool *mempool;
61 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
67 if (strcmp(tokens[2], "buffer") != 0) {
68 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buffer");
72 if (softnic_parser_read_uint32(&p.buffer_size, tokens[3]) != 0) {
73 snprintf(out, out_size, MSG_ARG_INVALID, "buffer_size");
77 if (strcmp(tokens[4], "pool") != 0) {
78 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pool");
82 if (softnic_parser_read_uint32(&p.pool_size, tokens[5]) != 0) {
83 snprintf(out, out_size, MSG_ARG_INVALID, "pool_size");
87 if (strcmp(tokens[6], "cache") != 0) {
88 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cache");
92 if (softnic_parser_read_uint32(&p.cache_size, tokens[7]) != 0) {
93 snprintf(out, out_size, MSG_ARG_INVALID, "cache_size");
97 mempool = softnic_mempool_create(softnic, name, &p);
98 if (mempool == NULL) {
99 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
106 * dev <device_name> | port <port_id>
109 cmd_link(struct pmd_internals *softnic,
115 struct softnic_link_params p;
116 struct softnic_link *link;
119 memset(&p, 0, sizeof(p));
122 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
127 if (strcmp(tokens[2], "dev") == 0) {
128 p.dev_name = tokens[3];
129 } else if (strcmp(tokens[2], "port") == 0) {
132 if (softnic_parser_read_uint16(&p.port_id, tokens[3]) != 0) {
133 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
137 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dev or port");
141 link = softnic_link_create(softnic, name, &p);
143 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
153 cmd_swq(struct pmd_internals *softnic,
159 struct softnic_swq_params p;
161 struct softnic_swq *swq;
164 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
170 if (strcmp(tokens[2], "size") != 0) {
171 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
175 if (softnic_parser_read_uint32(&p.size, tokens[3]) != 0) {
176 snprintf(out, out_size, MSG_ARG_INVALID, "size");
180 swq = softnic_swq_create(softnic, name, &p);
182 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
191 cmd_tap(struct pmd_internals *softnic,
198 struct softnic_tap *tap;
201 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
207 tap = softnic_tap_create(softnic, name);
209 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
215 * port in action profile <profile_name>
216 * [filter match | mismatch offset <key_offset> mask <key_mask> key <key_value> port <port_id>]
217 * [balance offset <key_offset> mask <key_mask> port <port_id0> ... <port_id15>]
220 cmd_port_in_action_profile(struct pmd_internals *softnic,
226 struct softnic_port_in_action_profile_params p;
227 struct softnic_port_in_action_profile *ap;
231 memset(&p, 0, sizeof(p));
234 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
238 if (strcmp(tokens[1], "in") != 0) {
239 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
243 if (strcmp(tokens[2], "action") != 0) {
244 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
248 if (strcmp(tokens[3], "profile") != 0) {
249 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
258 (strcmp(tokens[t0], "filter") == 0)) {
261 if (n_tokens < t0 + 10) {
262 snprintf(out, out_size, MSG_ARG_MISMATCH, "port in action profile filter");
266 if (strcmp(tokens[t0 + 1], "match") == 0) {
267 p.fltr.filter_on_match = 1;
268 } else if (strcmp(tokens[t0 + 1], "mismatch") == 0) {
269 p.fltr.filter_on_match = 0;
271 snprintf(out, out_size, MSG_ARG_INVALID, "match or mismatch");
275 if (strcmp(tokens[t0 + 2], "offset") != 0) {
276 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
280 if (softnic_parser_read_uint32(&p.fltr.key_offset,
281 tokens[t0 + 3]) != 0) {
282 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
286 if (strcmp(tokens[t0 + 4], "mask") != 0) {
287 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
291 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
292 if ((softnic_parse_hex_string(tokens[t0 + 5],
293 p.fltr.key_mask, &size) != 0) ||
294 size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE) {
295 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
299 if (strcmp(tokens[t0 + 6], "key") != 0) {
300 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
304 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
305 if ((softnic_parse_hex_string(tokens[t0 + 7],
306 p.fltr.key, &size) != 0) ||
307 size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE) {
308 snprintf(out, out_size, MSG_ARG_INVALID, "key_value");
312 if (strcmp(tokens[t0 + 8], "port") != 0) {
313 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
317 if (softnic_parser_read_uint32(&p.fltr.port_id,
318 tokens[t0 + 9]) != 0) {
319 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
323 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_FLTR;
328 (strcmp(tokens[t0], "balance") == 0)) {
331 if (n_tokens < t0 + 22) {
332 snprintf(out, out_size, MSG_ARG_MISMATCH,
333 "port in action profile balance");
337 if (strcmp(tokens[t0 + 1], "offset") != 0) {
338 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
342 if (softnic_parser_read_uint32(&p.lb.key_offset,
343 tokens[t0 + 2]) != 0) {
344 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
348 if (strcmp(tokens[t0 + 3], "mask") != 0) {
349 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
353 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
354 if (softnic_parse_hex_string(tokens[t0 + 4],
355 p.lb.key_mask, &p.lb.key_size) != 0) {
356 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
360 if (strcmp(tokens[t0 + 5], "port") != 0) {
361 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
365 for (i = 0; i < 16; i++)
366 if (softnic_parser_read_uint32(&p.lb.port_id[i],
367 tokens[t0 + 6 + i]) != 0) {
368 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
372 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_LB;
377 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
381 ap = softnic_port_in_action_profile_create(softnic, name, &p);
383 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
389 * table action profile <profile_name>
393 * [balance offset <key_offset> mask <key_mask> outoffset <out_offset>]
394 * [meter srtcm | trtcm
396 * stats none | pkts | bytes | both]
397 * [tm spp <n_subports_per_port> pps <n_pipes_per_subport>]
398 * [encap ether | vlan | qinq | mpls | pppoe]
403 * [stats pkts | bytes | both]
407 cmd_table_action_profile(struct pmd_internals *softnic,
413 struct softnic_table_action_profile_params p;
414 struct softnic_table_action_profile *ap;
418 memset(&p, 0, sizeof(p));
421 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
425 if (strcmp(tokens[1], "action") != 0) {
426 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
430 if (strcmp(tokens[2], "profile") != 0) {
431 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
437 if (strcmp(tokens[4], "ipv4") == 0) {
438 p.common.ip_version = 1;
439 } else if (strcmp(tokens[4], "ipv6") == 0) {
440 p.common.ip_version = 0;
442 snprintf(out, out_size, MSG_ARG_INVALID, "ipv4 or ipv6");
446 if (strcmp(tokens[5], "offset") != 0) {
447 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
451 if (softnic_parser_read_uint32(&p.common.ip_offset,
453 snprintf(out, out_size, MSG_ARG_INVALID, "ip_offset");
457 if (strcmp(tokens[7], "fwd") != 0) {
458 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fwd");
462 p.action_mask |= 1LLU << RTE_TABLE_ACTION_FWD;
466 (strcmp(tokens[t0], "balance") == 0)) {
467 if (n_tokens < t0 + 7) {
468 snprintf(out, out_size, MSG_ARG_MISMATCH, "table action profile balance");
472 if (strcmp(tokens[t0 + 1], "offset") != 0) {
473 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
477 if (softnic_parser_read_uint32(&p.lb.key_offset,
478 tokens[t0 + 2]) != 0) {
479 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
483 if (strcmp(tokens[t0 + 3], "mask") != 0) {
484 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
488 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
489 if (softnic_parse_hex_string(tokens[t0 + 4],
490 p.lb.key_mask, &p.lb.key_size) != 0) {
491 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
495 if (strcmp(tokens[t0 + 5], "outoffset") != 0) {
496 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "outoffset");
500 if (softnic_parser_read_uint32(&p.lb.out_offset,
501 tokens[t0 + 6]) != 0) {
502 snprintf(out, out_size, MSG_ARG_INVALID, "out_offset");
506 p.action_mask |= 1LLU << RTE_TABLE_ACTION_LB;
511 (strcmp(tokens[t0], "meter") == 0)) {
512 if (n_tokens < t0 + 6) {
513 snprintf(out, out_size, MSG_ARG_MISMATCH,
514 "table action profile meter");
518 if (strcmp(tokens[t0 + 1], "srtcm") == 0) {
519 p.mtr.alg = RTE_TABLE_ACTION_METER_SRTCM;
520 } else if (strcmp(tokens[t0 + 1], "trtcm") == 0) {
521 p.mtr.alg = RTE_TABLE_ACTION_METER_TRTCM;
523 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
528 if (strcmp(tokens[t0 + 2], "tc") != 0) {
529 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc");
533 if (softnic_parser_read_uint32(&p.mtr.n_tc,
534 tokens[t0 + 3]) != 0) {
535 snprintf(out, out_size, MSG_ARG_INVALID, "n_tc");
539 if (strcmp(tokens[t0 + 4], "stats") != 0) {
540 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
544 if (strcmp(tokens[t0 + 5], "none") == 0) {
545 p.mtr.n_packets_enabled = 0;
546 p.mtr.n_bytes_enabled = 0;
547 } else if (strcmp(tokens[t0 + 5], "pkts") == 0) {
548 p.mtr.n_packets_enabled = 1;
549 p.mtr.n_bytes_enabled = 0;
550 } else if (strcmp(tokens[t0 + 5], "bytes") == 0) {
551 p.mtr.n_packets_enabled = 0;
552 p.mtr.n_bytes_enabled = 1;
553 } else if (strcmp(tokens[t0 + 5], "both") == 0) {
554 p.mtr.n_packets_enabled = 1;
555 p.mtr.n_bytes_enabled = 1;
557 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
558 "none or pkts or bytes or both");
562 p.action_mask |= 1LLU << RTE_TABLE_ACTION_MTR;
567 (strcmp(tokens[t0], "tm") == 0)) {
568 if (n_tokens < t0 + 5) {
569 snprintf(out, out_size, MSG_ARG_MISMATCH,
570 "table action profile tm");
574 if (strcmp(tokens[t0 + 1], "spp") != 0) {
575 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
579 if (softnic_parser_read_uint32(&p.tm.n_subports_per_port,
580 tokens[t0 + 2]) != 0) {
581 snprintf(out, out_size, MSG_ARG_INVALID,
582 "n_subports_per_port");
586 if (strcmp(tokens[t0 + 3], "pps") != 0) {
587 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
591 if (softnic_parser_read_uint32(&p.tm.n_pipes_per_subport,
592 tokens[t0 + 4]) != 0) {
593 snprintf(out, out_size, MSG_ARG_INVALID,
594 "n_pipes_per_subport");
598 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TM;
603 (strcmp(tokens[t0], "encap") == 0)) {
604 if (n_tokens < t0 + 2) {
605 snprintf(out, out_size, MSG_ARG_MISMATCH,
606 "action profile encap");
610 if (strcmp(tokens[t0 + 1], "ether") == 0) {
611 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_ETHER;
612 } else if (strcmp(tokens[t0 + 1], "vlan") == 0) {
613 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VLAN;
614 } else if (strcmp(tokens[t0 + 1], "qinq") == 0) {
615 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ;
616 } else if (strcmp(tokens[t0 + 1], "mpls") == 0) {
617 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_MPLS;
618 } else if (strcmp(tokens[t0 + 1], "pppoe") == 0) {
619 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_PPPOE;
621 snprintf(out, out_size, MSG_ARG_MISMATCH, "encap");
625 p.action_mask |= 1LLU << RTE_TABLE_ACTION_ENCAP;
630 (strcmp(tokens[t0], "nat") == 0)) {
631 if (n_tokens < t0 + 4) {
632 snprintf(out, out_size, MSG_ARG_MISMATCH,
633 "table action profile nat");
637 if (strcmp(tokens[t0 + 1], "src") == 0) {
638 p.nat.source_nat = 1;
639 } else if (strcmp(tokens[t0 + 1], "dst") == 0) {
640 p.nat.source_nat = 0;
642 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
647 if (strcmp(tokens[t0 + 2], "proto") != 0) {
648 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "proto");
652 if (strcmp(tokens[t0 + 3], "tcp") == 0) {
654 } else if (strcmp(tokens[t0 + 3], "udp") == 0) {
657 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
662 p.action_mask |= 1LLU << RTE_TABLE_ACTION_NAT;
667 (strcmp(tokens[t0], "ttl") == 0)) {
668 if (n_tokens < t0 + 4) {
669 snprintf(out, out_size, MSG_ARG_MISMATCH,
670 "table action profile ttl");
674 if (strcmp(tokens[t0 + 1], "drop") == 0) {
676 } else if (strcmp(tokens[t0 + 1], "fwd") == 0) {
679 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
684 if (strcmp(tokens[t0 + 2], "stats") != 0) {
685 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
689 if (strcmp(tokens[t0 + 3], "none") == 0) {
690 p.ttl.n_packets_enabled = 0;
691 } else if (strcmp(tokens[t0 + 3], "pkts") == 0) {
692 p.ttl.n_packets_enabled = 1;
694 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
699 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TTL;
704 (strcmp(tokens[t0], "stats") == 0)) {
705 if (n_tokens < t0 + 2) {
706 snprintf(out, out_size, MSG_ARG_MISMATCH,
707 "table action profile stats");
711 if (strcmp(tokens[t0 + 1], "pkts") == 0) {
712 p.stats.n_packets_enabled = 1;
713 p.stats.n_bytes_enabled = 0;
714 } else if (strcmp(tokens[t0 + 1], "bytes") == 0) {
715 p.stats.n_packets_enabled = 0;
716 p.stats.n_bytes_enabled = 1;
717 } else if (strcmp(tokens[t0 + 1], "both") == 0) {
718 p.stats.n_packets_enabled = 1;
719 p.stats.n_bytes_enabled = 1;
721 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
722 "pkts or bytes or both");
726 p.action_mask |= 1LLU << RTE_TABLE_ACTION_STATS;
731 (strcmp(tokens[t0], "time") == 0)) {
732 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TIME;
737 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
741 ap = softnic_table_action_profile_create(softnic, name, &p);
743 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
749 * pipeline <pipeline_name>
750 * period <timer_period_ms>
751 * offset_port_id <offset_port_id>
754 cmd_pipeline(struct pmd_internals *softnic,
760 struct pipeline_params p;
762 struct pipeline *pipeline;
765 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
771 if (strcmp(tokens[2], "period") != 0) {
772 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "period");
776 if (softnic_parser_read_uint32(&p.timer_period_ms,
778 snprintf(out, out_size, MSG_ARG_INVALID, "timer_period_ms");
782 if (strcmp(tokens[4], "offset_port_id") != 0) {
783 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset_port_id");
787 if (softnic_parser_read_uint32(&p.offset_port_id,
789 snprintf(out, out_size, MSG_ARG_INVALID, "offset_port_id");
793 pipeline = softnic_pipeline_create(softnic, name, &p);
794 if (pipeline == NULL) {
795 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
801 * pipeline <pipeline_name> port in
803 * link <link_name> rxq <queue_id>
806 * | tap <tap_name> mempool <mempool_name> mtu <mtu>
807 * | source mempool <mempool_name> file <file_name> bpp <n_bytes_per_pkt>
808 * [action <port_in_action_profile_name>]
812 cmd_pipeline_port_in(struct pmd_internals *softnic,
818 struct softnic_port_in_params p;
824 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
828 pipeline_name = tokens[1];
830 if (strcmp(tokens[2], "port") != 0) {
831 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
835 if (strcmp(tokens[3], "in") != 0) {
836 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
840 if (strcmp(tokens[4], "bsz") != 0) {
841 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
845 if (softnic_parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
846 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
852 if (strcmp(tokens[t0], "link") == 0) {
853 if (n_tokens < t0 + 4) {
854 snprintf(out, out_size, MSG_ARG_MISMATCH,
855 "pipeline port in link");
859 p.type = PORT_IN_RXQ;
861 p.dev_name = tokens[t0 + 1];
863 if (strcmp(tokens[t0 + 2], "rxq") != 0) {
864 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
868 if (softnic_parser_read_uint16(&p.rxq.queue_id,
869 tokens[t0 + 3]) != 0) {
870 snprintf(out, out_size, MSG_ARG_INVALID,
875 } else if (strcmp(tokens[t0], "swq") == 0) {
876 if (n_tokens < t0 + 2) {
877 snprintf(out, out_size, MSG_ARG_MISMATCH,
878 "pipeline port in swq");
882 p.type = PORT_IN_SWQ;
884 p.dev_name = tokens[t0 + 1];
887 } else if (strcmp(tokens[t0], "tmgr") == 0) {
888 if (n_tokens < t0 + 2) {
889 snprintf(out, out_size, MSG_ARG_MISMATCH,
890 "pipeline port in tmgr");
894 p.type = PORT_IN_TMGR;
896 p.dev_name = tokens[t0 + 1];
899 } else if (strcmp(tokens[t0], "tap") == 0) {
900 if (n_tokens < t0 + 6) {
901 snprintf(out, out_size, MSG_ARG_MISMATCH,
902 "pipeline port in tap");
906 p.type = PORT_IN_TAP;
908 p.dev_name = tokens[t0 + 1];
910 if (strcmp(tokens[t0 + 2], "mempool") != 0) {
911 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
916 p.tap.mempool_name = tokens[t0 + 3];
918 if (strcmp(tokens[t0 + 4], "mtu") != 0) {
919 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
924 if (softnic_parser_read_uint32(&p.tap.mtu,
925 tokens[t0 + 5]) != 0) {
926 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
931 } else if (strcmp(tokens[t0], "source") == 0) {
932 if (n_tokens < t0 + 6) {
933 snprintf(out, out_size, MSG_ARG_MISMATCH,
934 "pipeline port in source");
938 p.type = PORT_IN_SOURCE;
942 if (strcmp(tokens[t0 + 1], "mempool") != 0) {
943 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
948 p.source.mempool_name = tokens[t0 + 2];
950 if (strcmp(tokens[t0 + 3], "file") != 0) {
951 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
956 p.source.file_name = tokens[t0 + 4];
958 if (strcmp(tokens[t0 + 5], "bpp") != 0) {
959 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
964 if (softnic_parser_read_uint32(&p.source.n_bytes_per_pkt,
965 tokens[t0 + 6]) != 0) {
966 snprintf(out, out_size, MSG_ARG_INVALID,
973 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
977 p.action_profile_name = NULL;
979 (strcmp(tokens[t0], "action") == 0)) {
980 if (n_tokens < t0 + 2) {
981 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
985 p.action_profile_name = tokens[t0 + 1];
992 (strcmp(tokens[t0], "disabled") == 0)) {
998 if (n_tokens != t0) {
999 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1003 status = softnic_pipeline_port_in_create(softnic,
1008 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1014 * pipeline <pipeline_name> port out
1016 * link <link_name> txq <txq_id>
1018 * | tmgr <tmgr_name>
1020 * | sink [file <file_name> pkts <max_n_pkts>]
1023 cmd_pipeline_port_out(struct pmd_internals *softnic,
1029 struct softnic_port_out_params p;
1030 char *pipeline_name;
1033 memset(&p, 0, sizeof(p));
1036 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1040 pipeline_name = tokens[1];
1042 if (strcmp(tokens[2], "port") != 0) {
1043 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1047 if (strcmp(tokens[3], "out") != 0) {
1048 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
1052 if (strcmp(tokens[4], "bsz") != 0) {
1053 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1057 if (softnic_parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1058 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1062 if (strcmp(tokens[6], "link") == 0) {
1063 if (n_tokens != 10) {
1064 snprintf(out, out_size, MSG_ARG_MISMATCH,
1065 "pipeline port out link");
1069 p.type = PORT_OUT_TXQ;
1071 p.dev_name = tokens[7];
1073 if (strcmp(tokens[8], "txq") != 0) {
1074 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
1078 if (softnic_parser_read_uint16(&p.txq.queue_id,
1080 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1083 } else if (strcmp(tokens[6], "swq") == 0) {
1084 if (n_tokens != 8) {
1085 snprintf(out, out_size, MSG_ARG_MISMATCH,
1086 "pipeline port out swq");
1090 p.type = PORT_OUT_SWQ;
1092 p.dev_name = tokens[7];
1093 } else if (strcmp(tokens[6], "tmgr") == 0) {
1094 if (n_tokens != 8) {
1095 snprintf(out, out_size, MSG_ARG_MISMATCH,
1096 "pipeline port out tmgr");
1100 p.type = PORT_OUT_TMGR;
1102 p.dev_name = tokens[7];
1103 } else if (strcmp(tokens[6], "tap") == 0) {
1104 if (n_tokens != 8) {
1105 snprintf(out, out_size, MSG_ARG_MISMATCH,
1106 "pipeline port out tap");
1110 p.type = PORT_OUT_TAP;
1112 p.dev_name = tokens[7];
1113 } else if (strcmp(tokens[6], "sink") == 0) {
1114 if ((n_tokens != 7) && (n_tokens != 11)) {
1115 snprintf(out, out_size, MSG_ARG_MISMATCH,
1116 "pipeline port out sink");
1120 p.type = PORT_OUT_SINK;
1124 if (n_tokens == 7) {
1125 p.sink.file_name = NULL;
1126 p.sink.max_n_pkts = 0;
1128 if (strcmp(tokens[7], "file") != 0) {
1129 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1134 p.sink.file_name = tokens[8];
1136 if (strcmp(tokens[9], "pkts") != 0) {
1137 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pkts");
1141 if (softnic_parser_read_uint32(&p.sink.max_n_pkts,
1143 snprintf(out, out_size, MSG_ARG_INVALID, "max_n_pkts");
1148 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1152 status = softnic_pipeline_port_out_create(softnic, pipeline_name, &p);
1154 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1160 * pipeline <pipeline_name> table
1164 * offset <ip_header_offset>
1167 * offset <key_offset>
1173 * offset <key_offset>
1174 * buckets <n_buckets>
1178 * offset <ip_header_offset>
1181 * [action <table_action_profile_name>]
1184 cmd_pipeline_table(struct pmd_internals *softnic,
1190 uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
1191 struct softnic_table_params p;
1192 char *pipeline_name;
1197 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1201 pipeline_name = tokens[1];
1203 if (strcmp(tokens[2], "table") != 0) {
1204 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
1208 if (strcmp(tokens[3], "match") != 0) {
1209 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
1214 if (strcmp(tokens[t0], "acl") == 0) {
1215 if (n_tokens < t0 + 6) {
1216 snprintf(out, out_size, MSG_ARG_MISMATCH,
1217 "pipeline table acl");
1221 p.match_type = TABLE_ACL;
1223 if (strcmp(tokens[t0 + 1], "ipv4") == 0) {
1224 p.match.acl.ip_version = 1;
1225 } else if (strcmp(tokens[t0 + 1], "ipv6") == 0) {
1226 p.match.acl.ip_version = 0;
1228 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1233 if (strcmp(tokens[t0 + 2], "offset") != 0) {
1234 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1238 if (softnic_parser_read_uint32(&p.match.acl.ip_header_offset,
1239 tokens[t0 + 3]) != 0) {
1240 snprintf(out, out_size, MSG_ARG_INVALID,
1241 "ip_header_offset");
1245 if (strcmp(tokens[t0 + 4], "size") != 0) {
1246 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
1250 if (softnic_parser_read_uint32(&p.match.acl.n_rules,
1251 tokens[t0 + 5]) != 0) {
1252 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
1257 } else if (strcmp(tokens[t0], "array") == 0) {
1258 if (n_tokens < t0 + 5) {
1259 snprintf(out, out_size, MSG_ARG_MISMATCH,
1260 "pipeline table array");
1264 p.match_type = TABLE_ARRAY;
1266 if (strcmp(tokens[t0 + 1], "offset") != 0) {
1267 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1271 if (softnic_parser_read_uint32(&p.match.array.key_offset,
1272 tokens[t0 + 2]) != 0) {
1273 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1277 if (strcmp(tokens[t0 + 3], "size") != 0) {
1278 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
1282 if (softnic_parser_read_uint32(&p.match.array.n_keys,
1283 tokens[t0 + 4]) != 0) {
1284 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
1289 } else if (strcmp(tokens[t0], "hash") == 0) {
1290 uint32_t key_mask_size = TABLE_RULE_MATCH_SIZE_MAX;
1292 if (n_tokens < t0 + 12) {
1293 snprintf(out, out_size, MSG_ARG_MISMATCH,
1294 "pipeline table hash");
1298 p.match_type = TABLE_HASH;
1300 if (strcmp(tokens[t0 + 1], "ext") == 0) {
1301 p.match.hash.extendable_bucket = 1;
1302 } else if (strcmp(tokens[t0 + 1], "lru") == 0) {
1303 p.match.hash.extendable_bucket = 0;
1305 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1310 if (strcmp(tokens[t0 + 2], "key") != 0) {
1311 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
1315 if ((softnic_parser_read_uint32(&p.match.hash.key_size,
1316 tokens[t0 + 3]) != 0) ||
1317 p.match.hash.key_size == 0 ||
1318 p.match.hash.key_size > TABLE_RULE_MATCH_SIZE_MAX) {
1319 snprintf(out, out_size, MSG_ARG_INVALID, "key_size");
1323 if (strcmp(tokens[t0 + 4], "mask") != 0) {
1324 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
1328 if ((softnic_parse_hex_string(tokens[t0 + 5],
1329 key_mask, &key_mask_size) != 0) ||
1330 key_mask_size != p.match.hash.key_size) {
1331 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1334 p.match.hash.key_mask = key_mask;
1336 if (strcmp(tokens[t0 + 6], "offset") != 0) {
1337 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1341 if (softnic_parser_read_uint32(&p.match.hash.key_offset,
1342 tokens[t0 + 7]) != 0) {
1343 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1347 if (strcmp(tokens[t0 + 8], "buckets") != 0) {
1348 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buckets");
1352 if (softnic_parser_read_uint32(&p.match.hash.n_buckets,
1353 tokens[t0 + 9]) != 0) {
1354 snprintf(out, out_size, MSG_ARG_INVALID, "n_buckets");
1358 if (strcmp(tokens[t0 + 10], "size") != 0) {
1359 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
1363 if (softnic_parser_read_uint32(&p.match.hash.n_keys,
1364 tokens[t0 + 11]) != 0) {
1365 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
1370 } else if (strcmp(tokens[t0], "lpm") == 0) {
1371 if (n_tokens < t0 + 6) {
1372 snprintf(out, out_size, MSG_ARG_MISMATCH,
1373 "pipeline table lpm");
1377 p.match_type = TABLE_LPM;
1379 if (strcmp(tokens[t0 + 1], "ipv4") == 0) {
1380 p.match.lpm.key_size = 4;
1381 } else if (strcmp(tokens[t0 + 1], "ipv6") == 0) {
1382 p.match.lpm.key_size = 16;
1384 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1389 if (strcmp(tokens[t0 + 2], "offset") != 0) {
1390 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1394 if (softnic_parser_read_uint32(&p.match.lpm.key_offset,
1395 tokens[t0 + 3]) != 0) {
1396 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1400 if (strcmp(tokens[t0 + 4], "size") != 0) {
1401 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
1405 if (softnic_parser_read_uint32(&p.match.lpm.n_rules,
1406 tokens[t0 + 5]) != 0) {
1407 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
1412 } else if (strcmp(tokens[t0], "stub") == 0) {
1413 p.match_type = TABLE_STUB;
1417 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1421 p.action_profile_name = NULL;
1422 if (n_tokens > t0 &&
1423 (strcmp(tokens[t0], "action") == 0)) {
1424 if (n_tokens < t0 + 2) {
1425 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
1429 p.action_profile_name = tokens[t0 + 1];
1434 if (n_tokens > t0) {
1435 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1439 status = softnic_pipeline_table_create(softnic, pipeline_name, &p);
1441 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1447 * pipeline <pipeline_name> port in <port_id> table <table_id>
1450 cmd_pipeline_port_in_table(struct pmd_internals *softnic,
1456 char *pipeline_name;
1457 uint32_t port_id, table_id;
1460 if (n_tokens != 7) {
1461 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1465 pipeline_name = tokens[1];
1467 if (strcmp(tokens[2], "port") != 0) {
1468 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1472 if (strcmp(tokens[3], "in") != 0) {
1473 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1477 if (softnic_parser_read_uint32(&port_id, tokens[4]) != 0) {
1478 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
1482 if (strcmp(tokens[5], "table") != 0) {
1483 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
1487 if (softnic_parser_read_uint32(&table_id, tokens[6]) != 0) {
1488 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
1492 status = softnic_pipeline_port_in_connect_to_table(softnic,
1497 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1503 * pipeline <pipeline_name> port in <port_id> enable
1506 cmd_softnic_pipeline_port_in_enable(struct pmd_internals *softnic,
1512 char *pipeline_name;
1516 if (n_tokens != 6) {
1517 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1521 pipeline_name = tokens[1];
1523 if (strcmp(tokens[2], "port") != 0) {
1524 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1528 if (strcmp(tokens[3], "in") != 0) {
1529 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1533 if (softnic_parser_read_uint32(&port_id, tokens[4]) != 0) {
1534 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
1538 if (strcmp(tokens[5], "enable") != 0) {
1539 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
1543 status = softnic_pipeline_port_in_enable(softnic, pipeline_name, port_id);
1545 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1551 * pipeline <pipeline_name> port in <port_id> disable
1554 cmd_softnic_pipeline_port_in_disable(struct pmd_internals *softnic,
1560 char *pipeline_name;
1564 if (n_tokens != 6) {
1565 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1569 pipeline_name = tokens[1];
1571 if (strcmp(tokens[2], "port") != 0) {
1572 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1576 if (strcmp(tokens[3], "in") != 0) {
1577 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1581 if (softnic_parser_read_uint32(&port_id, tokens[4]) != 0) {
1582 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
1586 if (strcmp(tokens[5], "disable") != 0) {
1587 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
1591 status = softnic_pipeline_port_in_disable(softnic, pipeline_name, port_id);
1593 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1603 * priority <priority>
1604 * ipv4 | ipv6 <sa> <sa_depth> <da> <da_depth>
1605 * <sp0> <sp1> <dp0> <dp1> <proto>
1609 * | ipv4_5tuple <sa> <da> <sp> <dp> <proto>
1610 * | ipv6_5tuple <sa> <da> <sp> <dp> <proto>
1611 * | ipv4_addr <addr>
1612 * | ipv6_addr <addr>
1613 * | qinq <svlan> <cvlan>
1615 * ipv4 | ipv6 <addr> <depth>
1617 struct pkt_key_qinq {
1618 uint16_t ethertype_svlan;
1620 uint16_t ethertype_cvlan;
1622 } __attribute__((__packed__));
1624 struct pkt_key_ipv4_5tuple {
1625 uint8_t time_to_live;
1627 uint16_t hdr_checksum;
1632 } __attribute__((__packed__));
1634 struct pkt_key_ipv6_5tuple {
1635 uint16_t payload_length;
1642 } __attribute__((__packed__));
1644 struct pkt_key_ipv4_addr {
1646 } __attribute__((__packed__));
1648 struct pkt_key_ipv6_addr {
1650 } __attribute__((__packed__));
1653 parse_match(char **tokens,
1657 struct softnic_table_rule_match *m)
1659 memset(m, 0, sizeof(*m));
1664 if (strcmp(tokens[0], "match") != 0) {
1665 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
1669 if (strcmp(tokens[1], "acl") == 0) {
1670 if (n_tokens < 14) {
1671 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1675 m->match_type = TABLE_ACL;
1677 if (strcmp(tokens[2], "priority") != 0) {
1678 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "priority");
1682 if (softnic_parser_read_uint32(&m->match.acl.priority,
1684 snprintf(out, out_size, MSG_ARG_INVALID, "priority");
1688 if (strcmp(tokens[4], "ipv4") == 0) {
1689 struct in_addr saddr, daddr;
1691 m->match.acl.ip_version = 1;
1693 if (softnic_parse_ipv4_addr(tokens[5], &saddr) != 0) {
1694 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
1697 m->match.acl.ipv4.sa = rte_be_to_cpu_32(saddr.s_addr);
1699 if (softnic_parse_ipv4_addr(tokens[7], &daddr) != 0) {
1700 snprintf(out, out_size, MSG_ARG_INVALID, "da");
1703 m->match.acl.ipv4.da = rte_be_to_cpu_32(daddr.s_addr);
1704 } else if (strcmp(tokens[4], "ipv6") == 0) {
1705 struct in6_addr saddr, daddr;
1707 m->match.acl.ip_version = 0;
1709 if (softnic_parse_ipv6_addr(tokens[5], &saddr) != 0) {
1710 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
1713 memcpy(m->match.acl.ipv6.sa, saddr.s6_addr, 16);
1715 if (softnic_parse_ipv6_addr(tokens[7], &daddr) != 0) {
1716 snprintf(out, out_size, MSG_ARG_INVALID, "da");
1719 memcpy(m->match.acl.ipv6.da, daddr.s6_addr, 16);
1721 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1726 if (softnic_parser_read_uint32(&m->match.acl.sa_depth,
1728 snprintf(out, out_size, MSG_ARG_INVALID, "sa_depth");
1732 if (softnic_parser_read_uint32(&m->match.acl.da_depth,
1734 snprintf(out, out_size, MSG_ARG_INVALID, "da_depth");
1738 if (softnic_parser_read_uint16(&m->match.acl.sp0, tokens[9]) != 0) {
1739 snprintf(out, out_size, MSG_ARG_INVALID, "sp0");
1743 if (softnic_parser_read_uint16(&m->match.acl.sp1, tokens[10]) != 0) {
1744 snprintf(out, out_size, MSG_ARG_INVALID, "sp1");
1748 if (softnic_parser_read_uint16(&m->match.acl.dp0, tokens[11]) != 0) {
1749 snprintf(out, out_size, MSG_ARG_INVALID, "dp0");
1753 if (softnic_parser_read_uint16(&m->match.acl.dp1, tokens[12]) != 0) {
1754 snprintf(out, out_size, MSG_ARG_INVALID, "dp1");
1758 if (softnic_parser_read_uint8(&m->match.acl.proto, tokens[13]) != 0) {
1759 snprintf(out, out_size, MSG_ARG_INVALID, "proto");
1763 m->match.acl.proto_mask = 0xff;
1768 if (strcmp(tokens[1], "array") == 0) {
1770 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1774 m->match_type = TABLE_ARRAY;
1776 if (softnic_parser_read_uint32(&m->match.array.pos, tokens[2]) != 0) {
1777 snprintf(out, out_size, MSG_ARG_INVALID, "pos");
1784 if (strcmp(tokens[1], "hash") == 0) {
1786 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1790 m->match_type = TABLE_HASH;
1792 if (strcmp(tokens[2], "raw") == 0) {
1793 uint32_t key_size = TABLE_RULE_MATCH_SIZE_MAX;
1796 snprintf(out, out_size, MSG_ARG_MISMATCH,
1801 if (softnic_parse_hex_string(tokens[3],
1802 m->match.hash.key, &key_size) != 0) {
1803 snprintf(out, out_size, MSG_ARG_INVALID, "key");
1810 if (strcmp(tokens[2], "ipv4_5tuple") == 0) {
1811 struct pkt_key_ipv4_5tuple *ipv4 =
1812 (struct pkt_key_ipv4_5tuple *)m->match.hash.key;
1813 struct in_addr saddr, daddr;
1818 snprintf(out, out_size, MSG_ARG_MISMATCH,
1823 if (softnic_parse_ipv4_addr(tokens[3], &saddr) != 0) {
1824 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
1828 if (softnic_parse_ipv4_addr(tokens[4], &daddr) != 0) {
1829 snprintf(out, out_size, MSG_ARG_INVALID, "da");
1833 if (softnic_parser_read_uint16(&sp, tokens[5]) != 0) {
1834 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
1838 if (softnic_parser_read_uint16(&dp, tokens[6]) != 0) {
1839 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
1843 if (softnic_parser_read_uint8(&proto, tokens[7]) != 0) {
1844 snprintf(out, out_size, MSG_ARG_INVALID,
1849 ipv4->sa = saddr.s_addr;
1850 ipv4->da = daddr.s_addr;
1851 ipv4->sp = rte_cpu_to_be_16(sp);
1852 ipv4->dp = rte_cpu_to_be_16(dp);
1853 ipv4->proto = proto;
1856 } /* hash ipv4_5tuple */
1858 if (strcmp(tokens[2], "ipv6_5tuple") == 0) {
1859 struct pkt_key_ipv6_5tuple *ipv6 =
1860 (struct pkt_key_ipv6_5tuple *)m->match.hash.key;
1861 struct in6_addr saddr, daddr;
1866 snprintf(out, out_size, MSG_ARG_MISMATCH,
1871 if (softnic_parse_ipv6_addr(tokens[3], &saddr) != 0) {
1872 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
1876 if (softnic_parse_ipv6_addr(tokens[4], &daddr) != 0) {
1877 snprintf(out, out_size, MSG_ARG_INVALID, "da");
1881 if (softnic_parser_read_uint16(&sp, tokens[5]) != 0) {
1882 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
1886 if (softnic_parser_read_uint16(&dp, tokens[6]) != 0) {
1887 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
1891 if (softnic_parser_read_uint8(&proto, tokens[7]) != 0) {
1892 snprintf(out, out_size, MSG_ARG_INVALID,
1897 memcpy(ipv6->sa, saddr.s6_addr, 16);
1898 memcpy(ipv6->da, daddr.s6_addr, 16);
1899 ipv6->sp = rte_cpu_to_be_16(sp);
1900 ipv6->dp = rte_cpu_to_be_16(dp);
1901 ipv6->proto = proto;
1904 } /* hash ipv6_5tuple */
1906 if (strcmp(tokens[2], "ipv4_addr") == 0) {
1907 struct pkt_key_ipv4_addr *ipv4_addr =
1908 (struct pkt_key_ipv4_addr *)m->match.hash.key;
1909 struct in_addr addr;
1912 snprintf(out, out_size, MSG_ARG_MISMATCH,
1917 if (softnic_parse_ipv4_addr(tokens[3], &addr) != 0) {
1918 snprintf(out, out_size, MSG_ARG_INVALID,
1923 ipv4_addr->addr = addr.s_addr;
1926 } /* hash ipv4_addr */
1928 if (strcmp(tokens[2], "ipv6_addr") == 0) {
1929 struct pkt_key_ipv6_addr *ipv6_addr =
1930 (struct pkt_key_ipv6_addr *)m->match.hash.key;
1931 struct in6_addr addr;
1934 snprintf(out, out_size, MSG_ARG_MISMATCH,
1939 if (softnic_parse_ipv6_addr(tokens[3], &addr) != 0) {
1940 snprintf(out, out_size, MSG_ARG_INVALID,
1945 memcpy(ipv6_addr->addr, addr.s6_addr, 16);
1948 } /* hash ipv6_5tuple */
1950 if (strcmp(tokens[2], "qinq") == 0) {
1951 struct pkt_key_qinq *qinq =
1952 (struct pkt_key_qinq *)m->match.hash.key;
1953 uint16_t svlan, cvlan;
1956 snprintf(out, out_size, MSG_ARG_MISMATCH,
1961 if ((softnic_parser_read_uint16(&svlan, tokens[3]) != 0) ||
1963 snprintf(out, out_size, MSG_ARG_INVALID,
1968 if ((softnic_parser_read_uint16(&cvlan, tokens[4]) != 0) ||
1970 snprintf(out, out_size, MSG_ARG_INVALID,
1975 qinq->svlan = rte_cpu_to_be_16(svlan);
1976 qinq->cvlan = rte_cpu_to_be_16(cvlan);
1981 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1985 if (strcmp(tokens[1], "lpm") == 0) {
1987 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1991 m->match_type = TABLE_LPM;
1993 if (strcmp(tokens[2], "ipv4") == 0) {
1994 struct in_addr addr;
1996 m->match.lpm.ip_version = 1;
1998 if (softnic_parse_ipv4_addr(tokens[3], &addr) != 0) {
1999 snprintf(out, out_size, MSG_ARG_INVALID,
2004 m->match.lpm.ipv4 = rte_be_to_cpu_32(addr.s_addr);
2005 } else if (strcmp(tokens[2], "ipv6") == 0) {
2006 struct in6_addr addr;
2008 m->match.lpm.ip_version = 0;
2010 if (softnic_parse_ipv6_addr(tokens[3], &addr) != 0) {
2011 snprintf(out, out_size, MSG_ARG_INVALID,
2016 memcpy(m->match.lpm.ipv6, addr.s6_addr, 16);
2018 snprintf(out, out_size, MSG_ARG_MISMATCH,
2023 if (softnic_parser_read_uint8(&m->match.lpm.depth, tokens[4]) != 0) {
2024 snprintf(out, out_size, MSG_ARG_INVALID, "depth");
2031 snprintf(out, out_size, MSG_ARG_MISMATCH,
2032 "acl or array or hash or lpm");
2044 * | table <table_id>
2045 * [balance <out0> ... <out7>]
2047 * tc0 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
2048 * [tc1 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
2049 * tc2 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
2050 * tc3 meter <meter_profile_id> policer g <pa> y <pa> r <pa>]]
2051 * [tm subport <subport_id> pipe <pipe_id>]
2054 * | vlan <da> <sa> <pcp> <dei> <vid>
2055 * | qinq <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid>
2056 * | mpls unicast | multicast
2058 * label0 <label> <tc> <ttl>
2059 * [label1 <label> <tc> <ttl>
2060 * [label2 <label> <tc> <ttl>
2061 * [label3 <label> <tc> <ttl>]]]
2062 * | pppoe <da> <sa> <session_id>]
2063 * [nat ipv4 | ipv6 <addr> <port>]
2069 * <pa> ::= g | y | r | drop
2072 parse_table_action_fwd(char **tokens,
2074 struct softnic_table_rule_action *a)
2076 if (n_tokens == 0 ||
2077 (strcmp(tokens[0], "fwd") != 0))
2083 if (n_tokens && (strcmp(tokens[0], "drop") == 0)) {
2084 a->fwd.action = RTE_PIPELINE_ACTION_DROP;
2085 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
2089 if (n_tokens && (strcmp(tokens[0], "port") == 0)) {
2093 softnic_parser_read_uint32(&id, tokens[1]))
2096 a->fwd.action = RTE_PIPELINE_ACTION_PORT;
2098 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
2102 if (n_tokens && (strcmp(tokens[0], "meta") == 0)) {
2103 a->fwd.action = RTE_PIPELINE_ACTION_PORT_META;
2104 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
2108 if (n_tokens && (strcmp(tokens[0], "table") == 0)) {
2112 softnic_parser_read_uint32(&id, tokens[1]))
2115 a->fwd.action = RTE_PIPELINE_ACTION_TABLE;
2117 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
2125 parse_table_action_balance(char **tokens,
2127 struct softnic_table_rule_action *a)
2131 if (n_tokens == 0 ||
2132 (strcmp(tokens[0], "balance") != 0))
2138 if (n_tokens < RTE_TABLE_ACTION_LB_TABLE_SIZE)
2141 for (i = 0; i < RTE_TABLE_ACTION_LB_TABLE_SIZE; i++)
2142 if (softnic_parser_read_uint32(&a->lb.out[i], tokens[i]) != 0)
2145 a->action_mask |= 1 << RTE_TABLE_ACTION_LB;
2146 return 1 + RTE_TABLE_ACTION_LB_TABLE_SIZE;
2150 parse_policer_action(char *token, enum rte_table_action_policer *a)
2152 if (strcmp(token, "g") == 0) {
2153 *a = RTE_TABLE_ACTION_POLICER_COLOR_GREEN;
2157 if (strcmp(token, "y") == 0) {
2158 *a = RTE_TABLE_ACTION_POLICER_COLOR_YELLOW;
2162 if (strcmp(token, "r") == 0) {
2163 *a = RTE_TABLE_ACTION_POLICER_COLOR_RED;
2167 if (strcmp(token, "drop") == 0) {
2168 *a = RTE_TABLE_ACTION_POLICER_DROP;
2176 parse_table_action_meter_tc(char **tokens,
2178 struct rte_table_action_mtr_tc_params *mtr)
2181 strcmp(tokens[0], "meter") ||
2182 softnic_parser_read_uint32(&mtr->meter_profile_id, tokens[1]) ||
2183 strcmp(tokens[2], "policer") ||
2184 strcmp(tokens[3], "g") ||
2185 parse_policer_action(tokens[4], &mtr->policer[e_RTE_METER_GREEN]) ||
2186 strcmp(tokens[5], "y") ||
2187 parse_policer_action(tokens[6], &mtr->policer[e_RTE_METER_YELLOW]) ||
2188 strcmp(tokens[7], "r") ||
2189 parse_policer_action(tokens[8], &mtr->policer[e_RTE_METER_RED]))
2196 parse_table_action_meter(char **tokens,
2198 struct softnic_table_rule_action *a)
2200 if (n_tokens == 0 ||
2201 strcmp(tokens[0], "meter"))
2207 if (n_tokens < 10 ||
2208 strcmp(tokens[0], "tc0") ||
2209 (parse_table_action_meter_tc(tokens + 1,
2211 &a->mtr.mtr[0]) == 0))
2217 if (n_tokens == 0 ||
2218 strcmp(tokens[0], "tc1")) {
2220 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
2224 if (n_tokens < 30 ||
2225 (parse_table_action_meter_tc(tokens + 1,
2226 n_tokens - 1, &a->mtr.mtr[1]) == 0) ||
2227 strcmp(tokens[10], "tc2") ||
2228 (parse_table_action_meter_tc(tokens + 11,
2229 n_tokens - 11, &a->mtr.mtr[2]) == 0) ||
2230 strcmp(tokens[20], "tc3") ||
2231 (parse_table_action_meter_tc(tokens + 21,
2232 n_tokens - 21, &a->mtr.mtr[3]) == 0))
2235 a->mtr.tc_mask = 0xF;
2236 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
2237 return 1 + 10 + 3 * 10;
2241 parse_table_action_tm(char **tokens,
2243 struct softnic_table_rule_action *a)
2245 uint32_t subport_id, pipe_id;
2248 strcmp(tokens[0], "tm") ||
2249 strcmp(tokens[1], "subport") ||
2250 softnic_parser_read_uint32(&subport_id, tokens[2]) ||
2251 strcmp(tokens[3], "pipe") ||
2252 softnic_parser_read_uint32(&pipe_id, tokens[4]))
2255 a->tm.subport_id = subport_id;
2256 a->tm.pipe_id = pipe_id;
2257 a->action_mask |= 1 << RTE_TABLE_ACTION_TM;
2262 parse_table_action_encap(char **tokens,
2264 struct softnic_table_rule_action *a)
2266 if (n_tokens == 0 ||
2267 strcmp(tokens[0], "encap"))
2274 if (n_tokens && (strcmp(tokens[0], "ether") == 0)) {
2276 softnic_parse_mac_addr(tokens[1], &a->encap.ether.ether.da) ||
2277 softnic_parse_mac_addr(tokens[2], &a->encap.ether.ether.sa))
2280 a->encap.type = RTE_TABLE_ACTION_ENCAP_ETHER;
2281 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
2286 if (n_tokens && (strcmp(tokens[0], "vlan") == 0)) {
2287 uint32_t pcp, dei, vid;
2290 softnic_parse_mac_addr(tokens[1], &a->encap.vlan.ether.da) ||
2291 softnic_parse_mac_addr(tokens[2], &a->encap.vlan.ether.sa) ||
2292 softnic_parser_read_uint32(&pcp, tokens[3]) ||
2294 softnic_parser_read_uint32(&dei, tokens[4]) ||
2296 softnic_parser_read_uint32(&vid, tokens[5]) ||
2300 a->encap.vlan.vlan.pcp = pcp & 0x7;
2301 a->encap.vlan.vlan.dei = dei & 0x1;
2302 a->encap.vlan.vlan.vid = vid & 0xFFF;
2303 a->encap.type = RTE_TABLE_ACTION_ENCAP_VLAN;
2304 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
2309 if (n_tokens && (strcmp(tokens[0], "qinq") == 0)) {
2310 uint32_t svlan_pcp, svlan_dei, svlan_vid;
2311 uint32_t cvlan_pcp, cvlan_dei, cvlan_vid;
2314 softnic_parse_mac_addr(tokens[1], &a->encap.qinq.ether.da) ||
2315 softnic_parse_mac_addr(tokens[2], &a->encap.qinq.ether.sa) ||
2316 softnic_parser_read_uint32(&svlan_pcp, tokens[3]) ||
2318 softnic_parser_read_uint32(&svlan_dei, tokens[4]) ||
2320 softnic_parser_read_uint32(&svlan_vid, tokens[5]) ||
2321 svlan_vid > 0xFFF ||
2322 softnic_parser_read_uint32(&cvlan_pcp, tokens[6]) ||
2324 softnic_parser_read_uint32(&cvlan_dei, tokens[7]) ||
2326 softnic_parser_read_uint32(&cvlan_vid, tokens[8]) ||
2330 a->encap.qinq.svlan.pcp = svlan_pcp & 0x7;
2331 a->encap.qinq.svlan.dei = svlan_dei & 0x1;
2332 a->encap.qinq.svlan.vid = svlan_vid & 0xFFF;
2333 a->encap.qinq.cvlan.pcp = cvlan_pcp & 0x7;
2334 a->encap.qinq.cvlan.dei = cvlan_dei & 0x1;
2335 a->encap.qinq.cvlan.vid = cvlan_vid & 0xFFF;
2336 a->encap.type = RTE_TABLE_ACTION_ENCAP_QINQ;
2337 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
2342 if (n_tokens && (strcmp(tokens[0], "mpls") == 0)) {
2343 uint32_t label, tc, ttl;
2348 if (strcmp(tokens[1], "unicast") == 0)
2349 a->encap.mpls.unicast = 1;
2350 else if (strcmp(tokens[1], "multicast") == 0)
2351 a->encap.mpls.unicast = 0;
2355 if (softnic_parse_mac_addr(tokens[2], &a->encap.mpls.ether.da) ||
2356 softnic_parse_mac_addr(tokens[3], &a->encap.mpls.ether.sa) ||
2357 strcmp(tokens[4], "label0") ||
2358 softnic_parser_read_uint32(&label, tokens[5]) ||
2360 softnic_parser_read_uint32(&tc, tokens[6]) ||
2362 softnic_parser_read_uint32(&ttl, tokens[7]) ||
2366 a->encap.mpls.mpls[0].label = label;
2367 a->encap.mpls.mpls[0].tc = tc;
2368 a->encap.mpls.mpls[0].ttl = ttl;
2373 if (n_tokens == 0 ||
2374 strcmp(tokens[0], "label1")) {
2375 a->encap.mpls.mpls_count = 1;
2376 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
2377 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
2382 softnic_parser_read_uint32(&label, tokens[1]) ||
2384 softnic_parser_read_uint32(&tc, tokens[2]) ||
2386 softnic_parser_read_uint32(&ttl, tokens[3]) ||
2390 a->encap.mpls.mpls[1].label = label;
2391 a->encap.mpls.mpls[1].tc = tc;
2392 a->encap.mpls.mpls[1].ttl = ttl;
2397 if (n_tokens == 0 ||
2398 strcmp(tokens[0], "label2")) {
2399 a->encap.mpls.mpls_count = 2;
2400 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
2401 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
2406 softnic_parser_read_uint32(&label, tokens[1]) ||
2408 softnic_parser_read_uint32(&tc, tokens[2]) ||
2410 softnic_parser_read_uint32(&ttl, tokens[3]) ||
2414 a->encap.mpls.mpls[2].label = label;
2415 a->encap.mpls.mpls[2].tc = tc;
2416 a->encap.mpls.mpls[2].ttl = ttl;
2421 if (n_tokens == 0 ||
2422 strcmp(tokens[0], "label3")) {
2423 a->encap.mpls.mpls_count = 3;
2424 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
2425 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
2426 return 1 + 8 + 4 + 4;
2430 softnic_parser_read_uint32(&label, tokens[1]) ||
2432 softnic_parser_read_uint32(&tc, tokens[2]) ||
2434 softnic_parser_read_uint32(&ttl, tokens[3]) ||
2438 a->encap.mpls.mpls[3].label = label;
2439 a->encap.mpls.mpls[3].tc = tc;
2440 a->encap.mpls.mpls[3].ttl = ttl;
2442 a->encap.mpls.mpls_count = 4;
2443 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
2444 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
2445 return 1 + 8 + 4 + 4 + 4;
2449 if (n_tokens && (strcmp(tokens[0], "pppoe") == 0)) {
2451 softnic_parse_mac_addr(tokens[1], &a->encap.pppoe.ether.da) ||
2452 softnic_parse_mac_addr(tokens[2], &a->encap.pppoe.ether.sa) ||
2453 softnic_parser_read_uint16(&a->encap.pppoe.pppoe.session_id,
2457 a->encap.type = RTE_TABLE_ACTION_ENCAP_PPPOE;
2458 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
2466 parse_table_action_nat(char **tokens,
2468 struct softnic_table_rule_action *a)
2471 strcmp(tokens[0], "nat"))
2474 if (strcmp(tokens[1], "ipv4") == 0) {
2475 struct in_addr addr;
2478 if (softnic_parse_ipv4_addr(tokens[2], &addr) ||
2479 softnic_parser_read_uint16(&port, tokens[3]))
2482 a->nat.ip_version = 1;
2483 a->nat.addr.ipv4 = rte_be_to_cpu_32(addr.s_addr);
2485 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
2489 if (strcmp(tokens[1], "ipv6") == 0) {
2490 struct in6_addr addr;
2493 if (softnic_parse_ipv6_addr(tokens[2], &addr) ||
2494 softnic_parser_read_uint16(&port, tokens[3]))
2497 a->nat.ip_version = 0;
2498 memcpy(a->nat.addr.ipv6, addr.s6_addr, 16);
2500 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
2508 parse_table_action_ttl(char **tokens,
2510 struct softnic_table_rule_action *a)
2513 strcmp(tokens[0], "ttl"))
2516 if (strcmp(tokens[1], "dec") == 0)
2517 a->ttl.decrement = 1;
2518 else if (strcmp(tokens[1], "keep") == 0)
2519 a->ttl.decrement = 0;
2523 a->action_mask |= 1 << RTE_TABLE_ACTION_TTL;
2528 parse_table_action_stats(char **tokens,
2530 struct softnic_table_rule_action *a)
2533 strcmp(tokens[0], "stats"))
2536 a->stats.n_packets = 0;
2537 a->stats.n_bytes = 0;
2538 a->action_mask |= 1 << RTE_TABLE_ACTION_STATS;
2543 parse_table_action_time(char **tokens,
2545 struct softnic_table_rule_action *a)
2548 strcmp(tokens[0], "time"))
2551 a->time.time = rte_rdtsc();
2552 a->action_mask |= 1 << RTE_TABLE_ACTION_TIME;
2557 parse_table_action(char **tokens,
2561 struct softnic_table_rule_action *a)
2563 uint32_t n_tokens0 = n_tokens;
2565 memset(a, 0, sizeof(*a));
2568 strcmp(tokens[0], "action"))
2574 if (n_tokens && (strcmp(tokens[0], "fwd") == 0)) {
2577 n = parse_table_action_fwd(tokens, n_tokens, a);
2579 snprintf(out, out_size, MSG_ARG_INVALID,
2588 if (n_tokens && (strcmp(tokens[0], "balance") == 0)) {
2591 n = parse_table_action_balance(tokens, n_tokens, a);
2593 snprintf(out, out_size, MSG_ARG_INVALID,
2602 if (n_tokens && (strcmp(tokens[0], "meter") == 0)) {
2605 n = parse_table_action_meter(tokens, n_tokens, a);
2607 snprintf(out, out_size, MSG_ARG_INVALID,
2616 if (n_tokens && (strcmp(tokens[0], "tm") == 0)) {
2619 n = parse_table_action_tm(tokens, n_tokens, a);
2621 snprintf(out, out_size, MSG_ARG_INVALID,
2630 if (n_tokens && (strcmp(tokens[0], "encap") == 0)) {
2633 n = parse_table_action_encap(tokens, n_tokens, a);
2635 snprintf(out, out_size, MSG_ARG_INVALID,
2644 if (n_tokens && (strcmp(tokens[0], "nat") == 0)) {
2647 n = parse_table_action_nat(tokens, n_tokens, a);
2649 snprintf(out, out_size, MSG_ARG_INVALID,
2658 if (n_tokens && (strcmp(tokens[0], "ttl") == 0)) {
2661 n = parse_table_action_ttl(tokens, n_tokens, a);
2663 snprintf(out, out_size, MSG_ARG_INVALID,
2672 if (n_tokens && (strcmp(tokens[0], "stats") == 0)) {
2675 n = parse_table_action_stats(tokens, n_tokens, a);
2677 snprintf(out, out_size, MSG_ARG_INVALID,
2686 if (n_tokens && (strcmp(tokens[0], "time") == 0)) {
2689 n = parse_table_action_time(tokens, n_tokens, a);
2691 snprintf(out, out_size, MSG_ARG_INVALID,
2700 if (n_tokens0 - n_tokens == 1) {
2701 snprintf(out, out_size, MSG_ARG_INVALID, "action");
2705 return n_tokens0 - n_tokens;
2709 * pipeline <pipeline_name> table <table_id> rule add
2711 * action <table_action>
2714 cmd_softnic_pipeline_table_rule_add(struct pmd_internals *softnic,
2720 struct softnic_table_rule_match m;
2721 struct softnic_table_rule_action a;
2722 char *pipeline_name;
2724 uint32_t table_id, t0, n_tokens_parsed;
2728 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2732 pipeline_name = tokens[1];
2734 if (strcmp(tokens[2], "table") != 0) {
2735 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2739 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
2740 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2744 if (strcmp(tokens[4], "rule") != 0) {
2745 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
2749 if (strcmp(tokens[5], "add") != 0) {
2750 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
2757 n_tokens_parsed = parse_match(tokens + t0,
2762 if (n_tokens_parsed == 0)
2764 t0 += n_tokens_parsed;
2767 n_tokens_parsed = parse_table_action(tokens + t0,
2772 if (n_tokens_parsed == 0)
2774 t0 += n_tokens_parsed;
2776 if (t0 != n_tokens) {
2777 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
2781 status = softnic_pipeline_table_rule_add(softnic,
2788 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2794 * pipeline <pipeline_name> table <table_id> rule add
2802 * | table <table_id>
2805 cmd_softnic_pipeline_table_rule_add_default(struct pmd_internals *softnic,
2811 struct softnic_table_rule_action action;
2813 char *pipeline_name;
2817 if (n_tokens != 11 &&
2819 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2823 pipeline_name = tokens[1];
2825 if (strcmp(tokens[2], "table") != 0) {
2826 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2830 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
2831 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2835 if (strcmp(tokens[4], "rule") != 0) {
2836 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
2840 if (strcmp(tokens[5], "add") != 0) {
2841 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
2845 if (strcmp(tokens[6], "match") != 0) {
2846 snprintf(out, out_size, MSG_ARG_INVALID, "match");
2850 if (strcmp(tokens[7], "default") != 0) {
2851 snprintf(out, out_size, MSG_ARG_INVALID, "default");
2855 if (strcmp(tokens[8], "action") != 0) {
2856 snprintf(out, out_size, MSG_ARG_INVALID, "action");
2860 if (strcmp(tokens[9], "fwd") != 0) {
2861 snprintf(out, out_size, MSG_ARG_INVALID, "fwd");
2865 action.action_mask = 1 << RTE_TABLE_ACTION_FWD;
2867 if (strcmp(tokens[10], "drop") == 0) {
2868 if (n_tokens != 11) {
2869 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2873 action.fwd.action = RTE_PIPELINE_ACTION_DROP;
2874 } else if (strcmp(tokens[10], "port") == 0) {
2877 if (n_tokens != 12) {
2878 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2882 if (softnic_parser_read_uint32(&id, tokens[11]) != 0) {
2883 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2887 action.fwd.action = RTE_PIPELINE_ACTION_PORT;
2889 } else if (strcmp(tokens[10], "meta") == 0) {
2890 if (n_tokens != 11) {
2891 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2895 action.fwd.action = RTE_PIPELINE_ACTION_PORT_META;
2896 } else if (strcmp(tokens[10], "table") == 0) {
2899 if (n_tokens != 12) {
2900 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2904 if (softnic_parser_read_uint32(&id, tokens[11]) != 0) {
2905 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2909 action.fwd.action = RTE_PIPELINE_ACTION_TABLE;
2912 snprintf(out, out_size, MSG_ARG_INVALID,
2913 "drop or port or meta or table");
2917 status = softnic_pipeline_table_rule_add_default(softnic,
2923 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2929 * pipeline <pipeline_name> table <table_id> rule add bulk <file_name> <n_rules>
2932 * - line format: match <match> action <action>
2935 cli_rule_file_process(const char *file_name,
2936 size_t line_len_max,
2937 struct softnic_table_rule_match *m,
2938 struct softnic_table_rule_action *a,
2940 uint32_t *line_number,
2945 cmd_softnic_pipeline_table_rule_add_bulk(struct pmd_internals *softnic,
2951 struct softnic_table_rule_match *match;
2952 struct softnic_table_rule_action *action;
2954 char *pipeline_name, *file_name;
2955 uint32_t table_id, n_rules, n_rules_parsed, line_number;
2958 if (n_tokens != 9) {
2959 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2963 pipeline_name = tokens[1];
2965 if (strcmp(tokens[2], "table") != 0) {
2966 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2970 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
2971 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2975 if (strcmp(tokens[4], "rule") != 0) {
2976 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
2980 if (strcmp(tokens[5], "add") != 0) {
2981 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
2985 if (strcmp(tokens[6], "bulk") != 0) {
2986 snprintf(out, out_size, MSG_ARG_INVALID, "bulk");
2990 file_name = tokens[7];
2992 if ((softnic_parser_read_uint32(&n_rules, tokens[8]) != 0) ||
2994 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2998 /* Memory allocation. */
2999 match = calloc(n_rules, sizeof(struct softnic_table_rule_match));
3000 action = calloc(n_rules, sizeof(struct softnic_table_rule_action));
3001 data = calloc(n_rules, sizeof(void *));
3002 if (match == NULL ||
3005 snprintf(out, out_size, MSG_OUT_OF_MEMORY);
3012 /* Load rule file */
3013 n_rules_parsed = n_rules;
3014 status = cli_rule_file_process(file_name,
3023 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
3029 if (n_rules_parsed != n_rules) {
3030 snprintf(out, out_size, MSG_FILE_NOT_ENOUGH, file_name);
3038 status = softnic_pipeline_table_rule_add_bulk(softnic,
3046 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
3060 * pipeline <pipeline_name> table <table_id> rule delete
3064 cmd_softnic_pipeline_table_rule_delete(struct pmd_internals *softnic,
3070 struct softnic_table_rule_match m;
3071 char *pipeline_name;
3072 uint32_t table_id, n_tokens_parsed, t0;
3076 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3080 pipeline_name = tokens[1];
3082 if (strcmp(tokens[2], "table") != 0) {
3083 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
3087 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
3088 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
3092 if (strcmp(tokens[4], "rule") != 0) {
3093 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
3097 if (strcmp(tokens[5], "delete") != 0) {
3098 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
3105 n_tokens_parsed = parse_match(tokens + t0,
3110 if (n_tokens_parsed == 0)
3112 t0 += n_tokens_parsed;
3114 if (n_tokens != t0) {
3115 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3119 status = softnic_pipeline_table_rule_delete(softnic,
3124 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
3130 * pipeline <pipeline_name> table <table_id> rule delete
3135 cmd_softnic_pipeline_table_rule_delete_default(struct pmd_internals *softnic,
3141 char *pipeline_name;
3145 if (n_tokens != 8) {
3146 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3150 pipeline_name = tokens[1];
3152 if (strcmp(tokens[2], "table") != 0) {
3153 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
3157 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
3158 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
3162 if (strcmp(tokens[4], "rule") != 0) {
3163 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
3167 if (strcmp(tokens[5], "delete") != 0) {
3168 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
3172 if (strcmp(tokens[6], "match") != 0) {
3173 snprintf(out, out_size, MSG_ARG_INVALID, "match");
3177 if (strcmp(tokens[7], "default") != 0) {
3178 snprintf(out, out_size, MSG_ARG_INVALID, "default");
3182 status = softnic_pipeline_table_rule_delete_default(softnic,
3186 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
3192 * thread <thread_id> pipeline <pipeline_name> enable
3195 cmd_softnic_thread_pipeline_enable(struct pmd_internals *softnic,
3201 char *pipeline_name;
3205 if (n_tokens != 5) {
3206 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3210 if (softnic_parser_read_uint32(&thread_id, tokens[1]) != 0) {
3211 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
3215 if (strcmp(tokens[2], "pipeline") != 0) {
3216 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
3220 pipeline_name = tokens[3];
3222 if (strcmp(tokens[4], "enable") != 0) {
3223 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
3227 status = softnic_thread_pipeline_enable(softnic, thread_id, pipeline_name);
3229 snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable");
3235 * thread <thread_id> pipeline <pipeline_name> disable
3238 cmd_softnic_thread_pipeline_disable(struct pmd_internals *softnic,
3244 char *pipeline_name;
3248 if (n_tokens != 5) {
3249 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3253 if (softnic_parser_read_uint32(&thread_id, tokens[1]) != 0) {
3254 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
3258 if (strcmp(tokens[2], "pipeline") != 0) {
3259 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
3263 pipeline_name = tokens[3];
3265 if (strcmp(tokens[4], "disable") != 0) {
3266 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
3270 status = softnic_thread_pipeline_disable(softnic, thread_id, pipeline_name);
3272 snprintf(out, out_size, MSG_CMD_FAIL,
3273 "thread pipeline disable");
3279 softnic_cli_process(char *in, char *out, size_t out_size, void *arg)
3281 char *tokens[CMD_MAX_TOKENS];
3282 uint32_t n_tokens = RTE_DIM(tokens);
3283 struct pmd_internals *softnic = arg;
3289 status = softnic_parse_tokenize_string(in, tokens, &n_tokens);
3291 snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
3298 if (strcmp(tokens[0], "mempool") == 0) {
3299 cmd_mempool(softnic, tokens, n_tokens, out, out_size);
3303 if (strcmp(tokens[0], "link") == 0) {
3304 cmd_link(softnic, tokens, n_tokens, out, out_size);
3308 if (strcmp(tokens[0], "swq") == 0) {
3309 cmd_swq(softnic, tokens, n_tokens, out, out_size);
3313 if (strcmp(tokens[0], "tap") == 0) {
3314 cmd_tap(softnic, tokens, n_tokens, out, out_size);
3318 if (strcmp(tokens[0], "port") == 0) {
3319 cmd_port_in_action_profile(softnic, tokens, n_tokens, out, out_size);
3323 if (strcmp(tokens[0], "table") == 0) {
3324 cmd_table_action_profile(softnic, tokens, n_tokens, out, out_size);
3328 if (strcmp(tokens[0], "pipeline") == 0) {
3329 if (n_tokens >= 3 &&
3330 (strcmp(tokens[2], "period") == 0)) {
3331 cmd_pipeline(softnic, tokens, n_tokens, out, out_size);
3335 if (n_tokens >= 5 &&
3336 (strcmp(tokens[2], "port") == 0) &&
3337 (strcmp(tokens[3], "in") == 0) &&
3338 (strcmp(tokens[4], "bsz") == 0)) {
3339 cmd_pipeline_port_in(softnic, tokens, n_tokens, out, out_size);
3343 if (n_tokens >= 5 &&
3344 (strcmp(tokens[2], "port") == 0) &&
3345 (strcmp(tokens[3], "out") == 0) &&
3346 (strcmp(tokens[4], "bsz") == 0)) {
3347 cmd_pipeline_port_out(softnic, tokens, n_tokens, out, out_size);
3351 if (n_tokens >= 4 &&
3352 (strcmp(tokens[2], "table") == 0) &&
3353 (strcmp(tokens[3], "match") == 0)) {
3354 cmd_pipeline_table(softnic, tokens, n_tokens, out, out_size);
3358 if (n_tokens >= 6 &&
3359 (strcmp(tokens[2], "port") == 0) &&
3360 (strcmp(tokens[3], "in") == 0) &&
3361 (strcmp(tokens[5], "table") == 0)) {
3362 cmd_pipeline_port_in_table(softnic, tokens, n_tokens,
3367 if (n_tokens >= 6 &&
3368 (strcmp(tokens[2], "port") == 0) &&
3369 (strcmp(tokens[3], "in") == 0) &&
3370 (strcmp(tokens[5], "enable") == 0)) {
3371 cmd_softnic_pipeline_port_in_enable(softnic, tokens, n_tokens,
3376 if (n_tokens >= 6 &&
3377 (strcmp(tokens[2], "port") == 0) &&
3378 (strcmp(tokens[3], "in") == 0) &&
3379 (strcmp(tokens[5], "disable") == 0)) {
3380 cmd_softnic_pipeline_port_in_disable(softnic, tokens, n_tokens,
3385 if (n_tokens >= 7 &&
3386 (strcmp(tokens[2], "table") == 0) &&
3387 (strcmp(tokens[4], "rule") == 0) &&
3388 (strcmp(tokens[5], "add") == 0) &&
3389 (strcmp(tokens[6], "match") == 0)) {
3390 if (n_tokens >= 8 &&
3391 (strcmp(tokens[7], "default") == 0)) {
3392 cmd_softnic_pipeline_table_rule_add_default(softnic, tokens,
3393 n_tokens, out, out_size);
3397 cmd_softnic_pipeline_table_rule_add(softnic, tokens, n_tokens,
3402 if (n_tokens >= 7 &&
3403 (strcmp(tokens[2], "table") == 0) &&
3404 (strcmp(tokens[4], "rule") == 0) &&
3405 (strcmp(tokens[5], "add") == 0) &&
3406 (strcmp(tokens[6], "bulk") == 0)) {
3407 cmd_softnic_pipeline_table_rule_add_bulk(softnic, tokens,
3408 n_tokens, out, out_size);
3412 if (n_tokens >= 7 &&
3413 (strcmp(tokens[2], "table") == 0) &&
3414 (strcmp(tokens[4], "rule") == 0) &&
3415 (strcmp(tokens[5], "delete") == 0) &&
3416 (strcmp(tokens[6], "match") == 0)) {
3417 if (n_tokens >= 8 &&
3418 (strcmp(tokens[7], "default") == 0)) {
3419 cmd_softnic_pipeline_table_rule_delete_default(softnic, tokens,
3420 n_tokens, out, out_size);
3424 cmd_softnic_pipeline_table_rule_delete(softnic, tokens, n_tokens,
3430 if (strcmp(tokens[0], "thread") == 0) {
3431 if (n_tokens >= 5 &&
3432 (strcmp(tokens[4], "enable") == 0)) {
3433 cmd_softnic_thread_pipeline_enable(softnic, tokens, n_tokens,
3438 if (n_tokens >= 5 &&
3439 (strcmp(tokens[4], "disable") == 0)) {
3440 cmd_softnic_thread_pipeline_disable(softnic, tokens, n_tokens,
3446 snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
3450 softnic_cli_script_process(struct pmd_internals *softnic,
3451 const char *file_name,
3452 size_t msg_in_len_max,
3453 size_t msg_out_len_max)
3455 char *msg_in = NULL, *msg_out = NULL;
3458 /* Check input arguments */
3459 if (file_name == NULL ||
3460 (strlen(file_name) == 0) ||
3461 msg_in_len_max == 0 ||
3462 msg_out_len_max == 0)
3465 msg_in = malloc(msg_in_len_max + 1);
3466 msg_out = malloc(msg_out_len_max + 1);
3467 if (msg_in == NULL ||
3474 /* Open input file */
3475 f = fopen(file_name, "r");
3484 if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
3487 printf("%s", msg_in);
3490 softnic_cli_process(msg_in,
3495 if (strlen(msg_out))
3496 printf("%s", msg_out);
3507 cli_rule_file_process(const char *file_name,
3508 size_t line_len_max,
3509 struct softnic_table_rule_match *m,
3510 struct softnic_table_rule_action *a,
3512 uint32_t *line_number,
3518 uint32_t rule_id, line_id;
3521 /* Check input arguments */
3522 if (file_name == NULL ||
3523 (strlen(file_name) == 0) ||
3524 line_len_max == 0) {
3529 /* Memory allocation */
3530 line = malloc(line_len_max + 1);
3537 f = fopen(file_name, "r");
3545 for (line_id = 1, rule_id = 0; rule_id < *n_rules; line_id++) {
3546 char *tokens[CMD_MAX_TOKENS];
3547 uint32_t n_tokens, n_tokens_parsed, t0;
3549 /* Read next line from file. */
3550 if (fgets(line, line_len_max + 1, f) == NULL)
3554 if (is_comment(line))
3558 n_tokens = RTE_DIM(tokens);
3559 status = softnic_parse_tokenize_string(line, tokens, &n_tokens);
3571 n_tokens_parsed = parse_match(tokens + t0,
3576 if (n_tokens_parsed == 0) {
3580 t0 += n_tokens_parsed;
3583 n_tokens_parsed = parse_table_action(tokens + t0,
3588 if (n_tokens_parsed == 0) {
3592 t0 += n_tokens_parsed;
3594 /* Line completed. */
3595 if (t0 < n_tokens) {
3600 /* Increment rule count */
3611 *line_number = line_id;