1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
10 #include <rte_common.h>
11 #include <rte_cycles.h>
24 #ifndef CMD_MAX_TOKENS
25 #define CMD_MAX_TOKENS 256
28 #define MSG_OUT_OF_MEMORY "Not enough memory.\n"
29 #define MSG_CMD_UNKNOWN "Unknown command \"%s\".\n"
30 #define MSG_CMD_UNIMPLEM "Command \"%s\" not implemented.\n"
31 #define MSG_ARG_NOT_ENOUGH "Not enough arguments for command \"%s\".\n"
32 #define MSG_ARG_TOO_MANY "Too many arguments for command \"%s\".\n"
33 #define MSG_ARG_MISMATCH "Wrong number of arguments for command \"%s\".\n"
34 #define MSG_ARG_NOT_FOUND "Argument \"%s\" not found.\n"
35 #define MSG_ARG_INVALID "Invalid value for argument \"%s\".\n"
36 #define MSG_FILE_ERR "Error in file \"%s\" at line %u.\n"
37 #define MSG_FILE_NOT_ENOUGH "Not enough rules in file \"%s\".\n"
38 #define MSG_CMD_FAIL "Command \"%s\" failed.\n"
43 if ((strlen(in) && index("!#%;", in[0])) ||
44 (strncmp(in, "//", 2) == 0) ||
45 (strncmp(in, "--", 2) == 0))
52 * mempool <mempool_name>
53 * buffer <buffer_size>
59 cmd_mempool(char **tokens,
64 struct mempool_params p;
66 struct mempool *mempool;
69 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
75 if (strcmp(tokens[2], "buffer") != 0) {
76 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buffer");
80 if (parser_read_uint32(&p.buffer_size, tokens[3]) != 0) {
81 snprintf(out, out_size, MSG_ARG_INVALID, "buffer_size");
85 if (strcmp(tokens[4], "pool") != 0) {
86 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pool");
90 if (parser_read_uint32(&p.pool_size, tokens[5]) != 0) {
91 snprintf(out, out_size, MSG_ARG_INVALID, "pool_size");
95 if (strcmp(tokens[6], "cache") != 0) {
96 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cache");
100 if (parser_read_uint32(&p.cache_size, tokens[7]) != 0) {
101 snprintf(out, out_size, MSG_ARG_INVALID, "cache_size");
105 if (strcmp(tokens[8], "cpu") != 0) {
106 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
110 if (parser_read_uint32(&p.cpu_id, tokens[9]) != 0) {
111 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
115 mempool = mempool_create(name, &p);
116 if (mempool == NULL) {
117 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
124 * dev <device_name> | port <port_id>
125 * rxq <n_queues> <queue_size> <mempool_name>
126 * txq <n_queues> <queue_size>
127 * promiscuous on | off
128 * [rss <qid_0> ... <qid_n>]
131 cmd_link(char **tokens,
136 struct link_params p;
137 struct link_params_rss rss;
141 if ((n_tokens < 13) || (n_tokens > 14 + LINK_RXQ_RSS_MAX)) {
142 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
147 if (strcmp(tokens[2], "dev") == 0)
148 p.dev_name = tokens[3];
149 else if (strcmp(tokens[2], "port") == 0) {
152 if (parser_read_uint16(&p.port_id, tokens[3]) != 0) {
153 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
157 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dev or port");
161 if (strcmp(tokens[4], "rxq") != 0) {
162 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
166 if (parser_read_uint32(&p.rx.n_queues, tokens[5]) != 0) {
167 snprintf(out, out_size, MSG_ARG_INVALID, "n_queues");
170 if (parser_read_uint32(&p.rx.queue_size, tokens[6]) != 0) {
171 snprintf(out, out_size, MSG_ARG_INVALID, "queue_size");
175 p.rx.mempool_name = tokens[7];
177 if (strcmp(tokens[8], "txq") != 0) {
178 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
182 if (parser_read_uint32(&p.tx.n_queues, tokens[9]) != 0) {
183 snprintf(out, out_size, MSG_ARG_INVALID, "n_queues");
187 if (parser_read_uint32(&p.tx.queue_size, tokens[10]) != 0) {
188 snprintf(out, out_size, MSG_ARG_INVALID, "queue_size");
192 if (strcmp(tokens[11], "promiscuous") != 0) {
193 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "promiscuous");
197 if (strcmp(tokens[12], "on") == 0)
199 else if (strcmp(tokens[12], "off") == 0)
202 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "on or off");
209 uint32_t queue_id, i;
211 if (strcmp(tokens[13], "rss") != 0) {
212 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rss");
219 for (i = 14; i < n_tokens; i++) {
220 if (parser_read_uint32(&queue_id, tokens[i]) != 0) {
221 snprintf(out, out_size, MSG_ARG_INVALID,
226 rss.queue_id[rss.n_queues] = queue_id;
231 link = link_create(name, &p);
233 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
244 cmd_swq(char **tokens,
254 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
260 if (strcmp(tokens[2], "size") != 0) {
261 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
265 if (parser_read_uint32(&p.size, tokens[3]) != 0) {
266 snprintf(out, out_size, MSG_ARG_INVALID, "size");
270 if (strcmp(tokens[4], "cpu") != 0) {
271 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
275 if (parser_read_uint32(&p.cpu_id, tokens[5]) != 0) {
276 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
280 swq = swq_create(name, &p);
282 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
288 * tmgr subport profile
289 * <tb_rate> <tb_size>
290 * <tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate>
294 cmd_tmgr_subport_profile(char **tokens,
299 struct rte_sched_subport_params p;
302 if (n_tokens != 10) {
303 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
307 if (parser_read_uint32(&p.tb_rate, tokens[3]) != 0) {
308 snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate");
312 if (parser_read_uint32(&p.tb_size, tokens[4]) != 0) {
313 snprintf(out, out_size, MSG_ARG_INVALID, "tb_size");
317 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
318 if (parser_read_uint32(&p.tc_rate[i], tokens[5 + i]) != 0) {
319 snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate");
323 if (parser_read_uint32(&p.tc_period, tokens[9]) != 0) {
324 snprintf(out, out_size, MSG_ARG_INVALID, "tc_period");
328 status = tmgr_subport_profile_add(&p);
330 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
337 * <tb_rate> <tb_size>
338 * <tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate>
344 cmd_tmgr_pipe_profile(char **tokens,
349 struct rte_sched_pipe_params p;
352 if (n_tokens != 27) {
353 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
357 if (parser_read_uint32(&p.tb_rate, tokens[3]) != 0) {
358 snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate");
362 if (parser_read_uint32(&p.tb_size, tokens[4]) != 0) {
363 snprintf(out, out_size, MSG_ARG_INVALID, "tb_size");
367 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
368 if (parser_read_uint32(&p.tc_rate[i], tokens[5 + i]) != 0) {
369 snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate");
373 if (parser_read_uint32(&p.tc_period, tokens[9]) != 0) {
374 snprintf(out, out_size, MSG_ARG_INVALID, "tc_period");
378 #ifdef RTE_SCHED_SUBPORT_TC_OV
379 if (parser_read_uint8(&p.tc_ov_weight, tokens[10]) != 0) {
380 snprintf(out, out_size, MSG_ARG_INVALID, "tc_ov_weight");
385 for (i = 0; i < RTE_SCHED_QUEUES_PER_PIPE; i++)
386 if (parser_read_uint8(&p.wrr_weights[i], tokens[11 + i]) != 0) {
387 snprintf(out, out_size, MSG_ARG_INVALID, "wrr_weights");
391 status = tmgr_pipe_profile_add(&p);
393 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
401 * spp <n_subports_per_port>
402 * pps <n_pipes_per_subport>
403 * qsize <qsize_tc0> <qsize_tc1> <qsize_tc2> <qsize_tc3>
404 * fo <frame_overhead>
409 cmd_tmgr(char **tokens,
414 struct tmgr_port_params p;
416 struct tmgr_port *tmgr_port;
419 if (n_tokens != 19) {
420 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
426 if (strcmp(tokens[2], "rate") != 0) {
427 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rate");
431 if (parser_read_uint32(&p.rate, tokens[3]) != 0) {
432 snprintf(out, out_size, MSG_ARG_INVALID, "rate");
436 if (strcmp(tokens[4], "spp") != 0) {
437 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
441 if (parser_read_uint32(&p.n_subports_per_port, tokens[5]) != 0) {
442 snprintf(out, out_size, MSG_ARG_INVALID, "n_subports_per_port");
446 if (strcmp(tokens[6], "pps") != 0) {
447 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
451 if (parser_read_uint32(&p.n_pipes_per_subport, tokens[7]) != 0) {
452 snprintf(out, out_size, MSG_ARG_INVALID, "n_pipes_per_subport");
456 if (strcmp(tokens[8], "qsize") != 0) {
457 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "qsize");
461 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
462 if (parser_read_uint16(&p.qsize[i], tokens[9 + i]) != 0) {
463 snprintf(out, out_size, MSG_ARG_INVALID, "qsize");
467 if (strcmp(tokens[13], "fo") != 0) {
468 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fo");
472 if (parser_read_uint32(&p.frame_overhead, tokens[14]) != 0) {
473 snprintf(out, out_size, MSG_ARG_INVALID, "frame_overhead");
477 if (strcmp(tokens[15], "mtu") != 0) {
478 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mtu");
482 if (parser_read_uint32(&p.mtu, tokens[16]) != 0) {
483 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
487 if (strcmp(tokens[17], "cpu") != 0) {
488 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
492 if (parser_read_uint32(&p.cpu_id, tokens[18]) != 0) {
493 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
497 tmgr_port = tmgr_port_create(name, &p);
498 if (tmgr_port == NULL) {
499 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
505 * tmgr <tmgr_name> subport <subport_id>
506 * profile <subport_profile_id>
509 cmd_tmgr_subport(char **tokens,
514 uint32_t subport_id, subport_profile_id;
519 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
525 if (parser_read_uint32(&subport_id, tokens[3]) != 0) {
526 snprintf(out, out_size, MSG_ARG_INVALID, "subport_id");
530 if (parser_read_uint32(&subport_profile_id, tokens[5]) != 0) {
531 snprintf(out, out_size, MSG_ARG_INVALID, "subport_profile_id");
535 status = tmgr_subport_config(name, subport_id, subport_profile_id);
537 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
543 * tmgr <tmgr_name> subport <subport_id> pipe
544 * from <pipe_id_first> to <pipe_id_last>
545 * profile <pipe_profile_id>
548 cmd_tmgr_subport_pipe(char **tokens,
553 uint32_t subport_id, pipe_id_first, pipe_id_last, pipe_profile_id;
557 if (n_tokens != 11) {
558 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
564 if (parser_read_uint32(&subport_id, tokens[3]) != 0) {
565 snprintf(out, out_size, MSG_ARG_INVALID, "subport_id");
569 if (strcmp(tokens[4], "pipe") != 0) {
570 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipe");
574 if (strcmp(tokens[5], "from") != 0) {
575 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
579 if (parser_read_uint32(&pipe_id_first, tokens[6]) != 0) {
580 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_id_first");
584 if (strcmp(tokens[7], "to") != 0) {
585 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
589 if (parser_read_uint32(&pipe_id_last, tokens[8]) != 0) {
590 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_id_last");
594 if (strcmp(tokens[9], "profile") != 0) {
595 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
599 if (parser_read_uint32(&pipe_profile_id, tokens[10]) != 0) {
600 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_profile_id");
604 status = tmgr_pipe_config(name, subport_id, pipe_id_first,
605 pipe_id_last, pipe_profile_id);
607 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
616 cmd_tap(char **tokens,
625 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
631 tap = tap_create(name);
633 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
641 * mempool <mempool_name>
642 * [thread <thread_id>]
645 cmd_kni(char **tokens,
654 if ((n_tokens != 6) && (n_tokens != 8)) {
655 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
661 if (strcmp(tokens[2], "link") != 0) {
662 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "link");
666 p.link_name = tokens[3];
668 if (strcmp(tokens[4], "mempool") != 0) {
669 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mempool");
673 p.mempool_name = tokens[5];
676 if (strcmp(tokens[6], "thread") != 0) {
677 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "thread");
681 if (parser_read_uint32(&p.thread_id, tokens[7]) != 0) {
682 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
690 kni = kni_create(name, &p);
692 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
698 * port in action profile <profile_name>
699 * [filter match | mismatch offset <key_offset> mask <key_mask> key <key_value> port <port_id>]
700 * [balance offset <key_offset> mask <key_mask> port <port_id0> ... <port_id15>]
703 cmd_port_in_action_profile(char **tokens,
708 struct port_in_action_profile_params p;
709 struct port_in_action_profile *ap;
713 memset(&p, 0, sizeof(p));
716 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
720 if (strcmp(tokens[1], "in") != 0) {
721 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
725 if (strcmp(tokens[2], "action") != 0) {
726 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
730 if (strcmp(tokens[3], "profile") != 0) {
731 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
739 if ((t0 < n_tokens) && (strcmp(tokens[t0], "filter") == 0)) {
742 if (n_tokens < t0 + 10) {
743 snprintf(out, out_size, MSG_ARG_MISMATCH, "port in action profile filter");
747 if (strcmp(tokens[t0 + 1], "match") == 0)
748 p.fltr.filter_on_match = 1;
749 else if (strcmp(tokens[t0 + 1], "mismatch") == 0)
750 p.fltr.filter_on_match = 0;
752 snprintf(out, out_size, MSG_ARG_INVALID, "match or mismatch");
756 if (strcmp(tokens[t0 + 2], "offset") != 0) {
757 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
761 if (parser_read_uint32(&p.fltr.key_offset, tokens[t0 + 3]) != 0) {
762 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
766 if (strcmp(tokens[t0 + 4], "mask") != 0) {
767 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
771 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
772 if ((parse_hex_string(tokens[t0 + 5], p.fltr.key_mask, &size) != 0) ||
773 (size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE)) {
774 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
778 if (strcmp(tokens[t0 + 6], "key") != 0) {
779 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
783 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
784 if ((parse_hex_string(tokens[t0 + 7], p.fltr.key, &size) != 0) ||
785 (size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE)) {
786 snprintf(out, out_size, MSG_ARG_INVALID, "key_value");
790 if (strcmp(tokens[t0 + 8], "port") != 0) {
791 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
795 if (parser_read_uint32(&p.fltr.port_id, tokens[t0 + 9]) != 0) {
796 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
800 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_FLTR;
804 if ((t0 < n_tokens) && (strcmp(tokens[t0], "balance") == 0)) {
807 if (n_tokens < t0 + 22) {
808 snprintf(out, out_size, MSG_ARG_MISMATCH, "port in action profile balance");
812 if (strcmp(tokens[t0 + 1], "offset") != 0) {
813 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
817 if (parser_read_uint32(&p.lb.key_offset, tokens[t0 + 2]) != 0) {
818 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
822 if (strcmp(tokens[t0 + 3], "mask") != 0) {
823 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
827 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
828 if (parse_hex_string(tokens[t0 + 4], p.lb.key_mask, &p.lb.key_size) != 0) {
829 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
833 if (strcmp(tokens[t0 + 5], "port") != 0) {
834 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
838 for (i = 0; i < 16; i++)
839 if (parser_read_uint32(&p.lb.port_id[i], tokens[t0 + 6 + i]) != 0) {
840 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
844 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_LB;
849 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
853 ap = port_in_action_profile_create(name, &p);
855 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
861 * table action profile <profile_name>
865 * [meter srtcm | trtcm
867 * stats none | pkts | bytes | both]
868 * [tm spp <n_subports_per_port> pps <n_pipes_per_subport>]
869 * [encap ether | vlan | qinq | mpls | pppoe]
874 * [stats pkts | bytes | both]
878 cmd_table_action_profile(char **tokens,
883 struct table_action_profile_params p;
884 struct table_action_profile *ap;
888 memset(&p, 0, sizeof(p));
891 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
895 if (strcmp(tokens[1], "action") != 0) {
896 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
900 if (strcmp(tokens[2], "profile") != 0) {
901 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
907 if (strcmp(tokens[4], "ipv4") == 0)
908 p.common.ip_version = 1;
909 else if (strcmp(tokens[4], "ipv6") == 0)
910 p.common.ip_version = 0;
912 snprintf(out, out_size, MSG_ARG_INVALID, "ipv4 or ipv6");
916 if (strcmp(tokens[5], "offset") != 0) {
917 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
921 if (parser_read_uint32(&p.common.ip_offset, tokens[6]) != 0) {
922 snprintf(out, out_size, MSG_ARG_INVALID, "ip_offset");
926 if (strcmp(tokens[7], "fwd") != 0) {
927 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fwd");
931 p.action_mask |= 1LLU << RTE_TABLE_ACTION_FWD;
934 if ((t0 < n_tokens) && (strcmp(tokens[t0], "meter") == 0)) {
935 if (n_tokens < t0 + 6) {
936 snprintf(out, out_size, MSG_ARG_MISMATCH,
937 "table action profile meter");
941 if (strcmp(tokens[t0 + 1], "srtcm") == 0)
942 p.mtr.alg = RTE_TABLE_ACTION_METER_SRTCM;
943 else if (strcmp(tokens[t0 + 1], "trtcm") == 0)
944 p.mtr.alg = RTE_TABLE_ACTION_METER_TRTCM;
946 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
951 if (strcmp(tokens[t0 + 2], "tc") != 0) {
952 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc");
956 if (parser_read_uint32(&p.mtr.n_tc, tokens[t0 + 3]) != 0) {
957 snprintf(out, out_size, MSG_ARG_INVALID, "n_tc");
961 if (strcmp(tokens[t0 + 4], "stats") != 0) {
962 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
966 if (strcmp(tokens[t0 + 5], "none") == 0) {
967 p.mtr.n_packets_enabled = 0;
968 p.mtr.n_bytes_enabled = 0;
969 } else if (strcmp(tokens[t0 + 5], "pkts") == 0) {
970 p.mtr.n_packets_enabled = 1;
971 p.mtr.n_bytes_enabled = 0;
972 } else if (strcmp(tokens[t0 + 5], "bytes") == 0) {
973 p.mtr.n_packets_enabled = 0;
974 p.mtr.n_bytes_enabled = 1;
975 } else if (strcmp(tokens[t0 + 5], "both") == 0) {
976 p.mtr.n_packets_enabled = 1;
977 p.mtr.n_bytes_enabled = 1;
979 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
980 "none or pkts or bytes or both");
984 p.action_mask |= 1LLU << RTE_TABLE_ACTION_MTR;
988 if ((t0 < n_tokens) && (strcmp(tokens[t0], "tm") == 0)) {
989 if (n_tokens < t0 + 5) {
990 snprintf(out, out_size, MSG_ARG_MISMATCH,
991 "table action profile tm");
995 if (strcmp(tokens[t0 + 1], "spp") != 0) {
996 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
1000 if (parser_read_uint32(&p.tm.n_subports_per_port,
1001 tokens[t0 + 2]) != 0) {
1002 snprintf(out, out_size, MSG_ARG_INVALID,
1003 "n_subports_per_port");
1007 if (strcmp(tokens[t0 + 3], "pps") != 0) {
1008 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
1012 if (parser_read_uint32(&p.tm.n_pipes_per_subport,
1013 tokens[t0 + 4]) != 0) {
1014 snprintf(out, out_size, MSG_ARG_INVALID,
1015 "n_pipes_per_subport");
1019 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TM;
1023 if ((t0 < n_tokens) && (strcmp(tokens[t0], "encap") == 0)) {
1024 if (n_tokens < t0 + 2) {
1025 snprintf(out, out_size, MSG_ARG_MISMATCH,
1026 "action profile encap");
1030 if (strcmp(tokens[t0 + 1], "ether") == 0)
1031 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_ETHER;
1032 else if (strcmp(tokens[t0 + 1], "vlan") == 0)
1033 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VLAN;
1034 else if (strcmp(tokens[t0 + 1], "qinq") == 0)
1035 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ;
1036 else if (strcmp(tokens[t0 + 1], "mpls") == 0)
1037 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_MPLS;
1038 else if (strcmp(tokens[t0 + 1], "pppoe") == 0)
1039 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_PPPOE;
1041 snprintf(out, out_size, MSG_ARG_MISMATCH, "encap");
1045 p.action_mask |= 1LLU << RTE_TABLE_ACTION_ENCAP;
1049 if ((t0 < n_tokens) && (strcmp(tokens[t0], "nat") == 0)) {
1050 if (n_tokens < t0 + 4) {
1051 snprintf(out, out_size, MSG_ARG_MISMATCH,
1052 "table action profile nat");
1056 if (strcmp(tokens[t0 + 1], "src") == 0)
1057 p.nat.source_nat = 1;
1058 else if (strcmp(tokens[t0 + 1], "dst") == 0)
1059 p.nat.source_nat = 0;
1061 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1066 if (strcmp(tokens[t0 + 2], "proto") != 0) {
1067 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "proto");
1071 if (strcmp(tokens[t0 + 3], "tcp") == 0)
1073 else if (strcmp(tokens[t0 + 3], "udp") == 0)
1076 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1081 p.action_mask |= 1LLU << RTE_TABLE_ACTION_NAT;
1085 if ((t0 < n_tokens) && (strcmp(tokens[t0], "ttl") == 0)) {
1086 if (n_tokens < t0 + 4) {
1087 snprintf(out, out_size, MSG_ARG_MISMATCH,
1088 "table action profile ttl");
1092 if (strcmp(tokens[t0 + 1], "drop") == 0)
1094 else if (strcmp(tokens[t0 + 1], "fwd") == 0)
1097 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1102 if (strcmp(tokens[t0 + 2], "stats") != 0) {
1103 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1107 if (strcmp(tokens[t0 + 3], "none") == 0)
1108 p.ttl.n_packets_enabled = 0;
1109 else if (strcmp(tokens[t0 + 3], "pkts") == 0)
1110 p.ttl.n_packets_enabled = 1;
1112 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1117 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TTL;
1121 if ((t0 < n_tokens) && (strcmp(tokens[t0], "stats") == 0)) {
1122 if (n_tokens < t0 + 2) {
1123 snprintf(out, out_size, MSG_ARG_MISMATCH,
1124 "table action profile stats");
1128 if (strcmp(tokens[t0 + 1], "pkts") == 0) {
1129 p.stats.n_packets_enabled = 1;
1130 p.stats.n_bytes_enabled = 0;
1131 } else if (strcmp(tokens[t0 + 1], "bytes") == 0) {
1132 p.stats.n_packets_enabled = 0;
1133 p.stats.n_bytes_enabled = 1;
1134 } else if (strcmp(tokens[t0 + 1], "both") == 0) {
1135 p.stats.n_packets_enabled = 1;
1136 p.stats.n_bytes_enabled = 1;
1138 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1139 "pkts or bytes or both");
1143 p.action_mask |= 1LLU << RTE_TABLE_ACTION_STATS;
1147 if ((t0 < n_tokens) && (strcmp(tokens[t0], "time") == 0)) {
1148 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TIME;
1152 if (t0 < n_tokens) {
1153 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1157 ap = table_action_profile_create(name, &p);
1159 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1165 * pipeline <pipeline_name>
1166 * period <timer_period_ms>
1167 * offset_port_id <offset_port_id>
1171 cmd_pipeline(char **tokens,
1176 struct pipeline_params p;
1178 struct pipeline *pipeline;
1180 if (n_tokens != 8) {
1181 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1187 if (strcmp(tokens[2], "period") != 0) {
1188 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "period");
1192 if (parser_read_uint32(&p.timer_period_ms, tokens[3]) != 0) {
1193 snprintf(out, out_size, MSG_ARG_INVALID, "timer_period_ms");
1197 if (strcmp(tokens[4], "offset_port_id") != 0) {
1198 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset_port_id");
1202 if (parser_read_uint32(&p.offset_port_id, tokens[5]) != 0) {
1203 snprintf(out, out_size, MSG_ARG_INVALID, "offset_port_id");
1207 if (strcmp(tokens[6], "cpu") != 0) {
1208 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
1212 if (parser_read_uint32(&p.cpu_id, tokens[7]) != 0) {
1213 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
1217 pipeline = pipeline_create(name, &p);
1218 if (pipeline == NULL) {
1219 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1225 * pipeline <pipeline_name> port in
1227 * link <link_name> rxq <queue_id>
1229 * | tmgr <tmgr_name>
1230 * | tap <tap_name> mempool <mempool_name> mtu <mtu>
1232 * | source mempool <mempool_name> file <file_name> bpp <n_bytes_per_pkt>
1233 * [action <port_in_action_profile_name>]
1237 cmd_pipeline_port_in(char **tokens,
1242 struct port_in_params p;
1243 char *pipeline_name;
1245 int enabled, status;
1248 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1252 pipeline_name = tokens[1];
1254 if (strcmp(tokens[2], "port") != 0) {
1255 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1259 if (strcmp(tokens[3], "in") != 0) {
1260 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1264 if (strcmp(tokens[4], "bsz") != 0) {
1265 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1269 if (parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1270 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1276 if (strcmp(tokens[t0], "link") == 0) {
1277 if (n_tokens < t0 + 4) {
1278 snprintf(out, out_size, MSG_ARG_MISMATCH,
1279 "pipeline port in link");
1283 p.type = PORT_IN_RXQ;
1285 p.dev_name = tokens[t0 + 1];
1287 if (strcmp(tokens[t0 + 2], "rxq") != 0) {
1288 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
1292 if (parser_read_uint16(&p.rxq.queue_id, tokens[t0 + 3]) != 0) {
1293 snprintf(out, out_size, MSG_ARG_INVALID,
1298 } else if (strcmp(tokens[t0], "swq") == 0) {
1299 if (n_tokens < t0 + 2) {
1300 snprintf(out, out_size, MSG_ARG_MISMATCH,
1301 "pipeline port in swq");
1305 p.type = PORT_IN_SWQ;
1307 p.dev_name = tokens[t0 + 1];
1310 } else if (strcmp(tokens[t0], "tmgr") == 0) {
1311 if (n_tokens < t0 + 2) {
1312 snprintf(out, out_size, MSG_ARG_MISMATCH,
1313 "pipeline port in tmgr");
1317 p.type = PORT_IN_TMGR;
1319 p.dev_name = tokens[t0 + 1];
1322 } else if (strcmp(tokens[t0], "tap") == 0) {
1323 if (n_tokens < t0 + 6) {
1324 snprintf(out, out_size, MSG_ARG_MISMATCH,
1325 "pipeline port in tap");
1329 p.type = PORT_IN_TAP;
1331 p.dev_name = tokens[t0 + 1];
1333 if (strcmp(tokens[t0 + 2], "mempool") != 0) {
1334 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1339 p.tap.mempool_name = tokens[t0 + 3];
1341 if (strcmp(tokens[t0 + 4], "mtu") != 0) {
1342 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1347 if (parser_read_uint32(&p.tap.mtu, tokens[t0 + 5]) != 0) {
1348 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
1353 } else if (strcmp(tokens[t0], "kni") == 0) {
1354 if (n_tokens < t0 + 2) {
1355 snprintf(out, out_size, MSG_ARG_MISMATCH,
1356 "pipeline port in kni");
1360 p.type = PORT_IN_KNI;
1362 p.dev_name = tokens[t0 + 1];
1365 } else if (strcmp(tokens[t0], "source") == 0) {
1366 if (n_tokens < t0 + 6) {
1367 snprintf(out, out_size, MSG_ARG_MISMATCH,
1368 "pipeline port in source");
1372 p.type = PORT_IN_SOURCE;
1376 if (strcmp(tokens[t0 + 1], "mempool") != 0) {
1377 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1382 p.source.mempool_name = tokens[t0 + 2];
1384 if (strcmp(tokens[t0 + 3], "file") != 0) {
1385 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1390 p.source.file_name = tokens[t0 + 4];
1392 if (strcmp(tokens[t0 + 5], "bpp") != 0) {
1393 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1398 if (parser_read_uint32(&p.source.n_bytes_per_pkt, tokens[t0 + 6]) != 0) {
1399 snprintf(out, out_size, MSG_ARG_INVALID,
1406 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1410 p.action_profile_name = NULL;
1411 if ((n_tokens > t0) && (strcmp(tokens[t0], "action") == 0)) {
1412 if (n_tokens < t0 + 2) {
1413 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
1417 p.action_profile_name = tokens[t0 + 1];
1423 if ((n_tokens > t0) &&
1424 (strcmp(tokens[t0], "disabled") == 0)) {
1430 if (n_tokens != t0) {
1431 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1435 status = pipeline_port_in_create(pipeline_name,
1438 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1444 * pipeline <pipeline_name> port out
1446 * link <link_name> txq <txq_id>
1448 * | tmgr <tmgr_name>
1451 * | sink [file <file_name> pkts <max_n_pkts>]
1454 cmd_pipeline_port_out(char **tokens,
1459 struct port_out_params p;
1460 char *pipeline_name;
1463 memset(&p, 0, sizeof(p));
1466 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1470 pipeline_name = tokens[1];
1472 if (strcmp(tokens[2], "port") != 0) {
1473 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1477 if (strcmp(tokens[3], "out") != 0) {
1478 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
1482 if (strcmp(tokens[4], "bsz") != 0) {
1483 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1487 if (parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1488 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1492 if (strcmp(tokens[6], "link") == 0) {
1493 if (n_tokens != 10) {
1494 snprintf(out, out_size, MSG_ARG_MISMATCH,
1495 "pipeline port out link");
1499 p.type = PORT_OUT_TXQ;
1501 p.dev_name = tokens[7];
1503 if (strcmp(tokens[8], "txq") != 0) {
1504 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
1508 if (parser_read_uint16(&p.txq.queue_id, tokens[9]) != 0) {
1509 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1512 } else if (strcmp(tokens[6], "swq") == 0) {
1513 if (n_tokens != 8) {
1514 snprintf(out, out_size, MSG_ARG_MISMATCH,
1515 "pipeline port out swq");
1519 p.type = PORT_OUT_SWQ;
1521 p.dev_name = tokens[7];
1522 } else if (strcmp(tokens[6], "tmgr") == 0) {
1523 if (n_tokens != 8) {
1524 snprintf(out, out_size, MSG_ARG_MISMATCH,
1525 "pipeline port out tmgr");
1529 p.type = PORT_OUT_TMGR;
1531 p.dev_name = tokens[7];
1532 } else if (strcmp(tokens[6], "tap") == 0) {
1533 if (n_tokens != 8) {
1534 snprintf(out, out_size, MSG_ARG_MISMATCH,
1535 "pipeline port out tap");
1539 p.type = PORT_OUT_TAP;
1541 p.dev_name = tokens[7];
1542 } else if (strcmp(tokens[6], "kni") == 0) {
1543 if (n_tokens != 8) {
1544 snprintf(out, out_size, MSG_ARG_MISMATCH,
1545 "pipeline port out kni");
1549 p.type = PORT_OUT_KNI;
1551 p.dev_name = tokens[7];
1552 } else if (strcmp(tokens[6], "sink") == 0) {
1553 if ((n_tokens != 7) && (n_tokens != 11)) {
1554 snprintf(out, out_size, MSG_ARG_MISMATCH,
1555 "pipeline port out sink");
1559 p.type = PORT_OUT_SINK;
1563 if (n_tokens == 7) {
1564 p.sink.file_name = NULL;
1565 p.sink.max_n_pkts = 0;
1567 if (strcmp(tokens[7], "file") != 0) {
1568 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1573 p.sink.file_name = tokens[8];
1575 if (strcmp(tokens[9], "pkts") != 0) {
1576 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pkts");
1580 if (parser_read_uint32(&p.sink.max_n_pkts, tokens[10]) != 0) {
1581 snprintf(out, out_size, MSG_ARG_INVALID, "max_n_pkts");
1586 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1590 status = pipeline_port_out_create(pipeline_name, &p);
1592 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1598 * pipeline <pipeline_name> table
1602 * offset <ip_header_offset>
1605 * offset <key_offset>
1611 * offset <key_offset>
1612 * buckets <n_buckets>
1616 * offset <ip_header_offset>
1619 * [action <table_action_profile_name>]
1622 cmd_pipeline_table(char **tokens,
1627 uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
1628 struct table_params p;
1629 char *pipeline_name;
1634 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1638 pipeline_name = tokens[1];
1640 if (strcmp(tokens[2], "table") != 0) {
1641 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
1645 if (strcmp(tokens[3], "match") != 0) {
1646 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
1651 if (strcmp(tokens[t0], "acl") == 0) {
1652 if (n_tokens < t0 + 6) {
1653 snprintf(out, out_size, MSG_ARG_MISMATCH,
1654 "pipeline table acl");
1658 p.match_type = TABLE_ACL;
1660 if (strcmp(tokens[t0 + 1], "ipv4") == 0)
1661 p.match.acl.ip_version = 1;
1662 else if (strcmp(tokens[t0 + 1], "ipv6") == 0)
1663 p.match.acl.ip_version = 0;
1665 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1670 if (strcmp(tokens[t0 + 2], "offset") != 0) {
1671 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1675 if (parser_read_uint32(&p.match.acl.ip_header_offset,
1676 tokens[t0 + 3]) != 0) {
1677 snprintf(out, out_size, MSG_ARG_INVALID,
1678 "ip_header_offset");
1682 if (strcmp(tokens[t0 + 4], "size") != 0) {
1683 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
1687 if (parser_read_uint32(&p.match.acl.n_rules,
1688 tokens[t0 + 5]) != 0) {
1689 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
1694 } else if (strcmp(tokens[t0], "array") == 0) {
1695 if (n_tokens < t0 + 5) {
1696 snprintf(out, out_size, MSG_ARG_MISMATCH,
1697 "pipeline table array");
1701 p.match_type = TABLE_ARRAY;
1703 if (strcmp(tokens[t0 + 1], "offset") != 0) {
1704 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1708 if (parser_read_uint32(&p.match.array.key_offset,
1709 tokens[t0 + 2]) != 0) {
1710 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1714 if (strcmp(tokens[t0 + 3], "size") != 0) {
1715 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
1719 if (parser_read_uint32(&p.match.array.n_keys,
1720 tokens[t0 + 4]) != 0) {
1721 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
1726 } else if (strcmp(tokens[t0], "hash") == 0) {
1727 uint32_t key_mask_size = TABLE_RULE_MATCH_SIZE_MAX;
1729 if (n_tokens < t0 + 12) {
1730 snprintf(out, out_size, MSG_ARG_MISMATCH,
1731 "pipeline table hash");
1735 p.match_type = TABLE_HASH;
1737 if (strcmp(tokens[t0 + 1], "ext") == 0)
1738 p.match.hash.extendable_bucket = 1;
1739 else if (strcmp(tokens[t0 + 1], "lru") == 0)
1740 p.match.hash.extendable_bucket = 0;
1742 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1747 if (strcmp(tokens[t0 + 2], "key") != 0) {
1748 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
1752 if ((parser_read_uint32(&p.match.hash.key_size,
1753 tokens[t0 + 3]) != 0) ||
1754 (p.match.hash.key_size == 0) ||
1755 (p.match.hash.key_size > TABLE_RULE_MATCH_SIZE_MAX)) {
1756 snprintf(out, out_size, MSG_ARG_INVALID, "key_size");
1760 if (strcmp(tokens[t0 + 4], "mask") != 0) {
1761 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
1765 if ((parse_hex_string(tokens[t0 + 5],
1766 key_mask, &key_mask_size) != 0) ||
1767 (key_mask_size != p.match.hash.key_size)) {
1768 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1771 p.match.hash.key_mask = key_mask;
1773 if (strcmp(tokens[t0 + 6], "offset") != 0) {
1774 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1778 if (parser_read_uint32(&p.match.hash.key_offset,
1779 tokens[t0 + 7]) != 0) {
1780 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1784 if (strcmp(tokens[t0 + 8], "buckets") != 0) {
1785 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buckets");
1789 if (parser_read_uint32(&p.match.hash.n_buckets,
1790 tokens[t0 + 9]) != 0) {
1791 snprintf(out, out_size, MSG_ARG_INVALID, "n_buckets");
1795 if (strcmp(tokens[t0 + 10], "size") != 0) {
1796 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
1800 if (parser_read_uint32(&p.match.hash.n_keys,
1801 tokens[t0 + 11]) != 0) {
1802 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
1807 } else if (strcmp(tokens[t0], "lpm") == 0) {
1808 if (n_tokens < t0 + 6) {
1809 snprintf(out, out_size, MSG_ARG_MISMATCH,
1810 "pipeline table lpm");
1814 p.match_type = TABLE_LPM;
1816 if (strcmp(tokens[t0 + 1], "ipv4") == 0)
1817 p.match.lpm.key_size = 4;
1818 else if (strcmp(tokens[t0 + 1], "ipv6") == 0)
1819 p.match.lpm.key_size = 16;
1821 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1826 if (strcmp(tokens[t0 + 2], "offset") != 0) {
1827 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1831 if (parser_read_uint32(&p.match.lpm.key_offset,
1832 tokens[t0 + 3]) != 0) {
1833 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1837 if (strcmp(tokens[t0 + 4], "size") != 0) {
1838 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
1842 if (parser_read_uint32(&p.match.lpm.n_rules,
1843 tokens[t0 + 5]) != 0) {
1844 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
1849 } else if (strcmp(tokens[t0], "stub") == 0) {
1850 if (n_tokens < t0 + 1) {
1851 snprintf(out, out_size, MSG_ARG_MISMATCH,
1852 "pipeline table stub");
1856 p.match_type = TABLE_STUB;
1860 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1864 p.action_profile_name = NULL;
1865 if ((n_tokens > t0) && (strcmp(tokens[t0], "action") == 0)) {
1866 if (n_tokens < t0 + 2) {
1867 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
1871 p.action_profile_name = tokens[t0 + 1];
1876 if (n_tokens > t0) {
1877 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1881 status = pipeline_table_create(pipeline_name, &p);
1883 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1889 * pipeline <pipeline_name> port in <port_id> table <table_id>
1892 cmd_pipeline_port_in_table(char **tokens,
1897 char *pipeline_name;
1898 uint32_t port_id, table_id;
1901 if (n_tokens != 7) {
1902 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1906 pipeline_name = tokens[1];
1908 if (strcmp(tokens[2], "port") != 0) {
1909 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1913 if (strcmp(tokens[3], "in") != 0) {
1914 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1918 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
1919 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
1923 if (strcmp(tokens[5], "table") != 0) {
1924 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
1928 if (parser_read_uint32(&table_id, tokens[6]) != 0) {
1929 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
1933 status = pipeline_port_in_connect_to_table(pipeline_name,
1937 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1943 * pipeline <pipeline_name> port in <port_id> stats read [clear]
1946 #define MSG_PIPELINE_PORT_IN_STATS \
1947 "Pkts in: %" PRIu64 "\n" \
1948 "Pkts dropped by AH: %" PRIu64 "\n" \
1949 "Pkts dropped by other: %" PRIu64 "\n"
1952 cmd_pipeline_port_in_stats(char **tokens,
1957 struct rte_pipeline_port_in_stats stats;
1958 char *pipeline_name;
1962 if ((n_tokens != 7) && (n_tokens != 8)) {
1963 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1967 pipeline_name = tokens[1];
1969 if (strcmp(tokens[2], "port") != 0) {
1970 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1974 if (strcmp(tokens[3], "in") != 0) {
1975 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1979 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
1980 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
1984 if (strcmp(tokens[5], "stats") != 0) {
1985 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1989 if (strcmp(tokens[6], "read") != 0) {
1990 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
1995 if (n_tokens == 8) {
1996 if (strcmp(tokens[7], "clear") != 0) {
1997 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2004 status = pipeline_port_in_stats_read(pipeline_name,
2009 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2013 snprintf(out, out_size, MSG_PIPELINE_PORT_IN_STATS,
2014 stats.stats.n_pkts_in,
2015 stats.n_pkts_dropped_by_ah,
2016 stats.stats.n_pkts_drop);
2020 * pipeline <pipeline_name> port in <port_id> enable
2023 cmd_pipeline_port_in_enable(char **tokens,
2028 char *pipeline_name;
2032 if (n_tokens != 6) {
2033 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2037 pipeline_name = tokens[1];
2039 if (strcmp(tokens[2], "port") != 0) {
2040 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2044 if (strcmp(tokens[3], "in") != 0) {
2045 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2049 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2050 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2054 if (strcmp(tokens[5], "enable") != 0) {
2055 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
2059 status = pipeline_port_in_enable(pipeline_name, port_id);
2061 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2067 * pipeline <pipeline_name> port in <port_id> disable
2070 cmd_pipeline_port_in_disable(char **tokens,
2075 char *pipeline_name;
2079 if (n_tokens != 6) {
2080 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2084 pipeline_name = tokens[1];
2086 if (strcmp(tokens[2], "port") != 0) {
2087 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2091 if (strcmp(tokens[3], "in") != 0) {
2092 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2096 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2097 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2101 if (strcmp(tokens[5], "disable") != 0) {
2102 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
2106 status = pipeline_port_in_disable(pipeline_name, port_id);
2108 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2114 * pipeline <pipeline_name> port out <port_id> stats read [clear]
2116 #define MSG_PIPELINE_PORT_OUT_STATS \
2117 "Pkts in: %" PRIu64 "\n" \
2118 "Pkts dropped by AH: %" PRIu64 "\n" \
2119 "Pkts dropped by other: %" PRIu64 "\n"
2122 cmd_pipeline_port_out_stats(char **tokens,
2127 struct rte_pipeline_port_out_stats stats;
2128 char *pipeline_name;
2132 if ((n_tokens != 7) && (n_tokens != 8)) {
2133 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2137 pipeline_name = tokens[1];
2139 if (strcmp(tokens[2], "port") != 0) {
2140 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2144 if (strcmp(tokens[3], "out") != 0) {
2145 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
2149 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2150 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2154 if (strcmp(tokens[5], "stats") != 0) {
2155 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2159 if (strcmp(tokens[6], "read") != 0) {
2160 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2165 if (n_tokens == 8) {
2166 if (strcmp(tokens[7], "clear") != 0) {
2167 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2174 status = pipeline_port_out_stats_read(pipeline_name,
2179 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2183 snprintf(out, out_size, MSG_PIPELINE_PORT_OUT_STATS,
2184 stats.stats.n_pkts_in,
2185 stats.n_pkts_dropped_by_ah,
2186 stats.stats.n_pkts_drop);
2190 * pipeline <pipeline_name> table <table_id> stats read [clear]
2192 #define MSG_PIPELINE_TABLE_STATS \
2193 "Pkts in: %" PRIu64 "\n" \
2194 "Pkts in with lookup miss: %" PRIu64 "\n" \
2195 "Pkts in with lookup hit dropped by AH: %" PRIu64 "\n" \
2196 "Pkts in with lookup hit dropped by others: %" PRIu64 "\n" \
2197 "Pkts in with lookup miss dropped by AH: %" PRIu64 "\n" \
2198 "Pkts in with lookup miss dropped by others: %" PRIu64 "\n"
2201 cmd_pipeline_table_stats(char **tokens,
2206 struct rte_pipeline_table_stats stats;
2207 char *pipeline_name;
2211 if ((n_tokens != 6) && (n_tokens != 7)) {
2212 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2216 pipeline_name = tokens[1];
2218 if (strcmp(tokens[2], "table") != 0) {
2219 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2223 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
2224 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2228 if (strcmp(tokens[4], "stats") != 0) {
2229 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2233 if (strcmp(tokens[5], "read") != 0) {
2234 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2239 if (n_tokens == 7) {
2240 if (strcmp(tokens[6], "clear") != 0) {
2241 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2248 status = pipeline_table_stats_read(pipeline_name,
2253 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2257 snprintf(out, out_size, MSG_PIPELINE_TABLE_STATS,
2258 stats.stats.n_pkts_in,
2259 stats.stats.n_pkts_lookup_miss,
2260 stats.n_pkts_dropped_by_lkp_hit_ah,
2261 stats.n_pkts_dropped_lkp_hit,
2262 stats.n_pkts_dropped_by_lkp_miss_ah,
2263 stats.n_pkts_dropped_lkp_miss);
2271 * priority <priority>
2272 * ipv4 | ipv6 <sa> <sa_depth> <da> <da_depth>
2273 * <sp0> <sp1> <dp0> <dp1> <proto>
2278 * | ipv4_5tuple <sa> <da> <sp> <dp> <proto>
2279 * | ipv6_5tuple <sa> <da> <sp> <dp> <proto>
2280 * | ipv4_addr <addr>
2281 * | ipv6_addr <addr>
2282 * | qinq <svlan> <cvlan>
2284 * ipv4 | ipv6 <addr> <depth>
2286 struct pkt_key_qinq {
2287 uint16_t ethertype_svlan;
2289 uint16_t ethertype_cvlan;
2291 } __attribute__((__packed__));
2293 struct pkt_key_ipv4_5tuple {
2294 uint8_t time_to_live;
2296 uint16_t hdr_checksum;
2301 } __attribute__((__packed__));
2303 struct pkt_key_ipv6_5tuple {
2304 uint16_t payload_length;
2311 } __attribute__((__packed__));
2313 struct pkt_key_ipv4_addr {
2315 } __attribute__((__packed__));
2317 struct pkt_key_ipv6_addr {
2319 } __attribute__((__packed__));
2322 parse_match(char **tokens,
2326 struct table_rule_match *m)
2328 memset(m, 0, sizeof(*m));
2333 if (strcmp(tokens[0], "match") != 0) {
2334 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
2338 if (strcmp(tokens[1], "acl") == 0) {
2339 if (n_tokens < 14) {
2340 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2344 m->match_type = TABLE_ACL;
2346 if (strcmp(tokens[2], "priority") != 0) {
2347 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "priority");
2351 if (parser_read_uint32(&m->match.acl.priority,
2353 snprintf(out, out_size, MSG_ARG_INVALID, "priority");
2357 if (strcmp(tokens[4], "ipv4") == 0) {
2358 struct in_addr saddr, daddr;
2360 m->match.acl.ip_version = 1;
2362 if (parse_ipv4_addr(tokens[5], &saddr) != 0) {
2363 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2366 m->match.acl.ipv4.sa = rte_be_to_cpu_32(saddr.s_addr);
2368 if (parse_ipv4_addr(tokens[7], &daddr) != 0) {
2369 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2372 m->match.acl.ipv4.da = rte_be_to_cpu_32(daddr.s_addr);
2373 } else if (strcmp(tokens[4], "ipv6") == 0) {
2374 struct in6_addr saddr, daddr;
2376 m->match.acl.ip_version = 0;
2378 if (parse_ipv6_addr(tokens[5], &saddr) != 0) {
2379 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2382 memcpy(m->match.acl.ipv6.sa, saddr.s6_addr, 16);
2384 if (parse_ipv6_addr(tokens[7], &daddr) != 0) {
2385 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2388 memcpy(m->match.acl.ipv6.da, daddr.s6_addr, 16);
2390 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2395 if (parser_read_uint32(&m->match.acl.sa_depth,
2397 snprintf(out, out_size, MSG_ARG_INVALID, "sa_depth");
2401 if (parser_read_uint32(&m->match.acl.da_depth,
2403 snprintf(out, out_size, MSG_ARG_INVALID, "da_depth");
2407 if (parser_read_uint16(&m->match.acl.sp0, tokens[9]) != 0) {
2408 snprintf(out, out_size, MSG_ARG_INVALID, "sp0");
2412 if (parser_read_uint16(&m->match.acl.sp1, tokens[10]) != 0) {
2413 snprintf(out, out_size, MSG_ARG_INVALID, "sp1");
2417 if (parser_read_uint16(&m->match.acl.dp0, tokens[11]) != 0) {
2418 snprintf(out, out_size, MSG_ARG_INVALID, "dp0");
2422 if (parser_read_uint16(&m->match.acl.dp1, tokens[12]) != 0) {
2423 snprintf(out, out_size, MSG_ARG_INVALID, "dp1");
2427 if (parser_read_uint8(&m->match.acl.proto, tokens[13]) != 0) {
2428 snprintf(out, out_size, MSG_ARG_INVALID, "proto");
2432 m->match.acl.proto_mask = 0xff;
2437 if (strcmp(tokens[1], "array") == 0) {
2439 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2443 m->match_type = TABLE_ARRAY;
2445 if (parser_read_uint32(&m->match.array.pos, tokens[2]) != 0) {
2446 snprintf(out, out_size, MSG_ARG_INVALID, "pos");
2453 if (strcmp(tokens[1], "hash") == 0) {
2455 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2459 m->match_type = TABLE_HASH;
2461 if (strcmp(tokens[2], "raw") == 0) {
2462 uint32_t key_size = TABLE_RULE_MATCH_SIZE_MAX;
2465 snprintf(out, out_size, MSG_ARG_MISMATCH,
2470 if (parse_hex_string(tokens[3],
2471 m->match.hash.key, &key_size) != 0) {
2472 snprintf(out, out_size, MSG_ARG_INVALID, "key");
2479 if (strcmp(tokens[2], "ipv4_5tuple") == 0) {
2480 struct pkt_key_ipv4_5tuple *ipv4 =
2481 (struct pkt_key_ipv4_5tuple *) m->match.hash.key;
2482 struct in_addr saddr, daddr;
2487 snprintf(out, out_size, MSG_ARG_MISMATCH,
2492 if (parse_ipv4_addr(tokens[3], &saddr) != 0) {
2493 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2497 if (parse_ipv4_addr(tokens[4], &daddr) != 0) {
2498 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2502 if (parser_read_uint16(&sp, tokens[5]) != 0) {
2503 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
2507 if (parser_read_uint16(&dp, tokens[6]) != 0) {
2508 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
2512 if (parser_read_uint8(&proto, tokens[7]) != 0) {
2513 snprintf(out, out_size, MSG_ARG_INVALID,
2518 ipv4->sa = saddr.s_addr;
2519 ipv4->da = daddr.s_addr;
2520 ipv4->sp = rte_cpu_to_be_16(sp);
2521 ipv4->dp = rte_cpu_to_be_16(dp);
2522 ipv4->proto = proto;
2525 } /* hash ipv4_5tuple */
2527 if (strcmp(tokens[2], "ipv6_5tuple") == 0) {
2528 struct pkt_key_ipv6_5tuple *ipv6 =
2529 (struct pkt_key_ipv6_5tuple *) m->match.hash.key;
2530 struct in6_addr saddr, daddr;
2535 snprintf(out, out_size, MSG_ARG_MISMATCH,
2540 if (parse_ipv6_addr(tokens[3], &saddr) != 0) {
2541 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2545 if (parse_ipv6_addr(tokens[4], &daddr) != 0) {
2546 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2550 if (parser_read_uint16(&sp, tokens[5]) != 0) {
2551 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
2555 if (parser_read_uint16(&dp, tokens[6]) != 0) {
2556 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
2560 if (parser_read_uint8(&proto, tokens[7]) != 0) {
2561 snprintf(out, out_size, MSG_ARG_INVALID,
2566 memcpy(ipv6->sa, saddr.s6_addr, 16);
2567 memcpy(ipv6->da, daddr.s6_addr, 16);
2568 ipv6->sp = rte_cpu_to_be_16(sp);
2569 ipv6->dp = rte_cpu_to_be_16(dp);
2570 ipv6->proto = proto;
2573 } /* hash ipv6_5tuple */
2575 if (strcmp(tokens[2], "ipv4_addr") == 0) {
2576 struct pkt_key_ipv4_addr *ipv4_addr =
2577 (struct pkt_key_ipv4_addr *) m->match.hash.key;
2578 struct in_addr addr;
2581 snprintf(out, out_size, MSG_ARG_MISMATCH,
2586 if (parse_ipv4_addr(tokens[3], &addr) != 0) {
2587 snprintf(out, out_size, MSG_ARG_INVALID,
2592 ipv4_addr->addr = addr.s_addr;
2595 } /* hash ipv4_addr */
2597 if (strcmp(tokens[2], "ipv6_addr") == 0) {
2598 struct pkt_key_ipv6_addr *ipv6_addr =
2599 (struct pkt_key_ipv6_addr *) m->match.hash.key;
2600 struct in6_addr addr;
2603 snprintf(out, out_size, MSG_ARG_MISMATCH,
2608 if (parse_ipv6_addr(tokens[3], &addr) != 0) {
2609 snprintf(out, out_size, MSG_ARG_INVALID,
2614 memcpy(ipv6_addr->addr, addr.s6_addr, 16);
2617 } /* hash ipv6_5tuple */
2619 if (strcmp(tokens[2], "qinq") == 0) {
2620 struct pkt_key_qinq *qinq =
2621 (struct pkt_key_qinq *) m->match.hash.key;
2622 uint16_t svlan, cvlan;
2625 snprintf(out, out_size, MSG_ARG_MISMATCH,
2630 if ((parser_read_uint16(&svlan, tokens[3]) != 0) ||
2632 snprintf(out, out_size, MSG_ARG_INVALID,
2637 if ((parser_read_uint16(&cvlan, tokens[4]) != 0) ||
2639 snprintf(out, out_size, MSG_ARG_INVALID,
2644 qinq->svlan = rte_cpu_to_be_16(svlan);
2645 qinq->cvlan = rte_cpu_to_be_16(cvlan);
2650 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2654 if (strcmp(tokens[1], "lpm") == 0) {
2656 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2660 m->match_type = TABLE_LPM;
2662 if (strcmp(tokens[2], "ipv4") == 0) {
2663 struct in_addr addr;
2665 m->match.lpm.ip_version = 1;
2667 if (parse_ipv4_addr(tokens[3], &addr) != 0) {
2668 snprintf(out, out_size, MSG_ARG_INVALID,
2673 m->match.lpm.ipv4 = rte_be_to_cpu_32(addr.s_addr);
2674 } else if (strcmp(tokens[2], "ipv6") == 0) {
2675 struct in6_addr addr;
2677 m->match.lpm.ip_version = 0;
2679 if (parse_ipv6_addr(tokens[3], &addr) != 0) {
2680 snprintf(out, out_size, MSG_ARG_INVALID,
2685 memcpy(m->match.lpm.ipv6, addr.s6_addr, 16);
2687 snprintf(out, out_size, MSG_ARG_MISMATCH,
2692 if (parser_read_uint8(&m->match.lpm.depth, tokens[4]) != 0) {
2693 snprintf(out, out_size, MSG_ARG_INVALID, "depth");
2700 snprintf(out, out_size, MSG_ARG_MISMATCH,
2701 "acl or array or hash or lpm");
2713 * | table <table_id>
2714 * [balance <out0> ... <out7>]
2716 * tc0 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
2717 * [tc1 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
2718 * tc2 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
2719 * tc3 meter <meter_profile_id> policer g <pa> y <pa> r <pa>]]
2720 * [tm subport <subport_id> pipe <pipe_id>]
2723 * | vlan <da> <sa> <pcp> <dei> <vid>
2724 * | qinq <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid>
2725 * | mpls unicast | multicast
2727 * label0 <label> <tc> <ttl>
2728 * [label1 <label> <tc> <ttl>
2729 * [label2 <label> <tc> <ttl>
2730 * [label3 <label> <tc> <ttl>]]]
2731 * | pppoe <da> <sa> <session_id>]
2732 * [nat ipv4 | ipv6 <addr> <port>]
2738 * <pa> ::= g | y | r | drop
2741 parse_table_action_fwd(char **tokens,
2743 struct table_rule_action *a)
2745 if ((n_tokens == 0) || (strcmp(tokens[0], "fwd") != 0))
2751 if (n_tokens && (strcmp(tokens[0], "drop") == 0)) {
2752 a->fwd.action = RTE_PIPELINE_ACTION_DROP;
2753 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
2757 if (n_tokens && (strcmp(tokens[0], "port") == 0)) {
2760 if ((n_tokens < 2) ||
2761 parser_read_uint32(&id, tokens[1]))
2764 a->fwd.action = RTE_PIPELINE_ACTION_PORT;
2766 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
2770 if (n_tokens && (strcmp(tokens[0], "meta") == 0)) {
2771 a->fwd.action = RTE_PIPELINE_ACTION_PORT_META;
2772 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
2776 if (n_tokens && (strcmp(tokens[0], "table") == 0)) {
2779 if ((n_tokens < 2) ||
2780 parser_read_uint32(&id, tokens[1]))
2783 a->fwd.action = RTE_PIPELINE_ACTION_TABLE;
2785 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
2793 parse_policer_action(char *token, enum rte_table_action_policer *a)
2795 if (strcmp(token, "g") == 0) {
2796 *a = RTE_TABLE_ACTION_POLICER_COLOR_GREEN;
2800 if (strcmp(token, "y") == 0) {
2801 *a = RTE_TABLE_ACTION_POLICER_COLOR_YELLOW;
2805 if (strcmp(token, "r") == 0) {
2806 *a = RTE_TABLE_ACTION_POLICER_COLOR_RED;
2810 if (strcmp(token, "drop") == 0) {
2811 *a = RTE_TABLE_ACTION_POLICER_DROP;
2819 parse_table_action_meter_tc(char **tokens,
2821 struct rte_table_action_mtr_tc_params *mtr)
2823 if ((n_tokens < 9) ||
2824 strcmp(tokens[0], "meter") ||
2825 parser_read_uint32(&mtr->meter_profile_id, tokens[1]) ||
2826 strcmp(tokens[2], "policer") ||
2827 strcmp(tokens[3], "g") ||
2828 parse_policer_action(tokens[4], &mtr->policer[e_RTE_METER_GREEN]) ||
2829 strcmp(tokens[5], "y") ||
2830 parse_policer_action(tokens[6], &mtr->policer[e_RTE_METER_YELLOW]) ||
2831 strcmp(tokens[7], "r") ||
2832 parse_policer_action(tokens[8], &mtr->policer[e_RTE_METER_RED]))
2839 parse_table_action_meter(char **tokens,
2841 struct table_rule_action *a)
2843 if ((n_tokens == 0) || strcmp(tokens[0], "meter"))
2849 if ((n_tokens < 10) ||
2850 strcmp(tokens[0], "tc0") ||
2851 (parse_table_action_meter_tc(tokens + 1,
2853 &a->mtr.mtr[0]) == 0))
2859 if ((n_tokens == 0) || strcmp(tokens[0], "tc1")) {
2861 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
2865 if ((n_tokens < 30) ||
2866 (parse_table_action_meter_tc(tokens + 1,
2867 n_tokens - 1, &a->mtr.mtr[1]) == 0) ||
2868 strcmp(tokens[10], "tc2") ||
2869 (parse_table_action_meter_tc(tokens + 11,
2870 n_tokens - 11, &a->mtr.mtr[2]) == 0) ||
2871 strcmp(tokens[20], "tc3") ||
2872 (parse_table_action_meter_tc(tokens + 21,
2873 n_tokens - 21, &a->mtr.mtr[3]) == 0))
2876 a->mtr.tc_mask = 0xF;
2877 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
2878 return 1 + 10 + 3 * 10;
2882 parse_table_action_tm(char **tokens,
2884 struct table_rule_action *a)
2886 uint32_t subport_id, pipe_id;
2888 if ((n_tokens < 5) ||
2889 strcmp(tokens[0], "tm") ||
2890 strcmp(tokens[1], "subport") ||
2891 parser_read_uint32(&subport_id, tokens[2]) ||
2892 strcmp(tokens[3], "pipe") ||
2893 parser_read_uint32(&pipe_id, tokens[4]))
2896 a->tm.subport_id = subport_id;
2897 a->tm.pipe_id = pipe_id;
2898 a->action_mask |= 1 << RTE_TABLE_ACTION_TM;
2903 parse_table_action_encap(char **tokens,
2905 struct table_rule_action *a)
2907 if ((n_tokens == 0) || strcmp(tokens[0], "encap"))
2914 if (n_tokens && (strcmp(tokens[0], "ether") == 0)) {
2915 if ((n_tokens < 3) ||
2916 parse_mac_addr(tokens[1], &a->encap.ether.ether.da) ||
2917 parse_mac_addr(tokens[2], &a->encap.ether.ether.sa))
2920 a->encap.type = RTE_TABLE_ACTION_ENCAP_ETHER;
2921 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
2926 if (n_tokens && (strcmp(tokens[0], "vlan") == 0)) {
2927 uint32_t pcp, dei, vid;
2929 if ((n_tokens < 6) ||
2930 parse_mac_addr(tokens[1], &a->encap.vlan.ether.da) ||
2931 parse_mac_addr(tokens[2], &a->encap.vlan.ether.sa) ||
2932 parser_read_uint32(&pcp, tokens[3]) ||
2934 parser_read_uint32(&dei, tokens[4]) ||
2936 parser_read_uint32(&vid, tokens[5]) ||
2940 a->encap.vlan.vlan.pcp = pcp & 0x7;
2941 a->encap.vlan.vlan.dei = dei & 0x1;
2942 a->encap.vlan.vlan.vid = vid & 0xFFF;
2943 a->encap.type = RTE_TABLE_ACTION_ENCAP_VLAN;
2944 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
2949 if (n_tokens && (strcmp(tokens[0], "qinq") == 0)) {
2950 uint32_t svlan_pcp, svlan_dei, svlan_vid;
2951 uint32_t cvlan_pcp, cvlan_dei, cvlan_vid;
2953 if ((n_tokens < 9) ||
2954 parse_mac_addr(tokens[1], &a->encap.qinq.ether.da) ||
2955 parse_mac_addr(tokens[2], &a->encap.qinq.ether.sa) ||
2956 parser_read_uint32(&svlan_pcp, tokens[3]) ||
2957 (svlan_pcp > 0x7) ||
2958 parser_read_uint32(&svlan_dei, tokens[4]) ||
2959 (svlan_dei > 0x1) ||
2960 parser_read_uint32(&svlan_vid, tokens[5]) ||
2961 (svlan_vid > 0xFFF) ||
2962 parser_read_uint32(&cvlan_pcp, tokens[6]) ||
2963 (cvlan_pcp > 0x7) ||
2964 parser_read_uint32(&cvlan_dei, tokens[7]) ||
2965 (cvlan_dei > 0x1) ||
2966 parser_read_uint32(&cvlan_vid, tokens[8]) ||
2967 (cvlan_vid > 0xFFF))
2970 a->encap.qinq.svlan.pcp = svlan_pcp & 0x7;
2971 a->encap.qinq.svlan.dei = svlan_dei & 0x1;
2972 a->encap.qinq.svlan.vid = svlan_vid & 0xFFF;
2973 a->encap.qinq.cvlan.pcp = cvlan_pcp & 0x7;
2974 a->encap.qinq.cvlan.dei = cvlan_dei & 0x1;
2975 a->encap.qinq.cvlan.vid = cvlan_vid & 0xFFF;
2976 a->encap.type = RTE_TABLE_ACTION_ENCAP_QINQ;
2977 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
2982 if (n_tokens && (strcmp(tokens[0], "mpls") == 0)) {
2983 uint32_t label, tc, ttl;
2988 if (strcmp(tokens[1], "unicast") == 0)
2989 a->encap.mpls.unicast = 1;
2990 else if (strcmp(tokens[1], "multicast") == 0)
2991 a->encap.mpls.unicast = 0;
2995 if (parse_mac_addr(tokens[2], &a->encap.mpls.ether.da) ||
2996 parse_mac_addr(tokens[3], &a->encap.mpls.ether.sa) ||
2997 strcmp(tokens[4], "label0") ||
2998 parser_read_uint32(&label, tokens[5]) ||
2999 (label > 0xFFFFF) ||
3000 parser_read_uint32(&tc, tokens[6]) ||
3002 parser_read_uint32(&ttl, tokens[7]) ||
3006 a->encap.mpls.mpls[0].label = label;
3007 a->encap.mpls.mpls[0].tc = tc;
3008 a->encap.mpls.mpls[0].ttl = ttl;
3013 if ((n_tokens == 0) || strcmp(tokens[0], "label1")) {
3014 a->encap.mpls.mpls_count = 1;
3015 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3016 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3020 if ((n_tokens < 4) ||
3021 parser_read_uint32(&label, tokens[1]) ||
3022 (label > 0xFFFFF) ||
3023 parser_read_uint32(&tc, tokens[2]) ||
3025 parser_read_uint32(&ttl, tokens[3]) ||
3029 a->encap.mpls.mpls[1].label = label;
3030 a->encap.mpls.mpls[1].tc = tc;
3031 a->encap.mpls.mpls[1].ttl = ttl;
3036 if ((n_tokens == 0) || strcmp(tokens[0], "label2")) {
3037 a->encap.mpls.mpls_count = 2;
3038 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3039 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3043 if ((n_tokens < 4) ||
3044 parser_read_uint32(&label, tokens[1]) ||
3045 (label > 0xFFFFF) ||
3046 parser_read_uint32(&tc, tokens[2]) ||
3048 parser_read_uint32(&ttl, tokens[3]) ||
3052 a->encap.mpls.mpls[2].label = label;
3053 a->encap.mpls.mpls[2].tc = tc;
3054 a->encap.mpls.mpls[2].ttl = ttl;
3059 if ((n_tokens == 0) || strcmp(tokens[0], "label3")) {
3060 a->encap.mpls.mpls_count = 3;
3061 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3062 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3063 return 1 + 8 + 4 + 4;
3066 if ((n_tokens < 4) ||
3067 parser_read_uint32(&label, tokens[1]) ||
3068 (label > 0xFFFFF) ||
3069 parser_read_uint32(&tc, tokens[2]) ||
3071 parser_read_uint32(&ttl, tokens[3]) ||
3075 a->encap.mpls.mpls[3].label = label;
3076 a->encap.mpls.mpls[3].tc = tc;
3077 a->encap.mpls.mpls[3].ttl = ttl;
3079 a->encap.mpls.mpls_count = 4;
3080 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3081 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3082 return 1 + 8 + 4 + 4 + 4;
3086 if (n_tokens && (strcmp(tokens[0], "pppoe") == 0)) {
3087 if ((n_tokens < 4) ||
3088 parse_mac_addr(tokens[1], &a->encap.pppoe.ether.da) ||
3089 parse_mac_addr(tokens[2], &a->encap.pppoe.ether.sa) ||
3090 parser_read_uint16(&a->encap.pppoe.pppoe.session_id,
3094 a->encap.type = RTE_TABLE_ACTION_ENCAP_PPPOE;
3095 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3103 parse_table_action_nat(char **tokens,
3105 struct table_rule_action *a)
3107 if ((n_tokens < 4) ||
3108 strcmp(tokens[0], "nat"))
3111 if (strcmp(tokens[1], "ipv4") == 0) {
3112 struct in_addr addr;
3115 if (parse_ipv4_addr(tokens[2], &addr) ||
3116 parser_read_uint16(&port, tokens[3]))
3119 a->nat.ip_version = 1;
3120 a->nat.addr.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3122 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3126 if (strcmp(tokens[1], "ipv6") == 0) {
3127 struct in6_addr addr;
3130 if (parse_ipv6_addr(tokens[2], &addr) ||
3131 parser_read_uint16(&port, tokens[3]))
3134 a->nat.ip_version = 0;
3135 memcpy(a->nat.addr.ipv6, addr.s6_addr, 16);
3137 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3145 parse_table_action_ttl(char **tokens,
3147 struct table_rule_action *a)
3149 if ((n_tokens < 2) ||
3150 strcmp(tokens[0], "ttl"))
3153 if (strcmp(tokens[1], "dec") == 0)
3154 a->ttl.decrement = 1;
3155 else if (strcmp(tokens[1], "keep") == 0)
3156 a->ttl.decrement = 0;
3160 a->action_mask |= 1 << RTE_TABLE_ACTION_TTL;
3165 parse_table_action_stats(char **tokens,
3167 struct table_rule_action *a)
3169 if ((n_tokens < 1) ||
3170 strcmp(tokens[0], "stats"))
3173 a->stats.n_packets = 0;
3174 a->stats.n_bytes = 0;
3175 a->action_mask |= 1 << RTE_TABLE_ACTION_STATS;
3180 parse_table_action_time(char **tokens,
3182 struct table_rule_action *a)
3184 if ((n_tokens < 1) ||
3185 strcmp(tokens[0], "time"))
3188 a->time.time = rte_rdtsc();
3189 a->action_mask |= 1 << RTE_TABLE_ACTION_TIME;
3194 parse_table_action(char **tokens,
3198 struct table_rule_action *a)
3200 uint32_t n_tokens0 = n_tokens;
3202 memset(a, 0, sizeof(*a));
3204 if ((n_tokens < 2) ||
3205 strcmp(tokens[0], "action"))
3211 if (n_tokens && (strcmp(tokens[0], "fwd") == 0)) {
3214 n = parse_table_action_fwd(tokens, n_tokens, a);
3216 snprintf(out, out_size, MSG_ARG_INVALID,
3225 if (n_tokens && (strcmp(tokens[0], "meter") == 0)) {
3228 n = parse_table_action_meter(tokens, n_tokens, a);
3230 snprintf(out, out_size, MSG_ARG_INVALID,
3239 if (n_tokens && (strcmp(tokens[0], "tm") == 0)) {
3242 n = parse_table_action_tm(tokens, n_tokens, a);
3244 snprintf(out, out_size, MSG_ARG_INVALID,
3253 if (n_tokens && (strcmp(tokens[0], "encap") == 0)) {
3256 n = parse_table_action_encap(tokens, n_tokens, a);
3258 snprintf(out, out_size, MSG_ARG_INVALID,
3267 if (n_tokens && (strcmp(tokens[0], "nat") == 0)) {
3270 n = parse_table_action_nat(tokens, n_tokens, a);
3272 snprintf(out, out_size, MSG_ARG_INVALID,
3281 if (n_tokens && (strcmp(tokens[0], "ttl") == 0)) {
3284 n = parse_table_action_ttl(tokens, n_tokens, a);
3286 snprintf(out, out_size, MSG_ARG_INVALID,
3295 if (n_tokens && (strcmp(tokens[0], "stats") == 0)) {
3298 n = parse_table_action_stats(tokens, n_tokens, a);
3300 snprintf(out, out_size, MSG_ARG_INVALID,
3309 if (n_tokens && (strcmp(tokens[0], "time") == 0)) {
3312 n = parse_table_action_time(tokens, n_tokens, a);
3314 snprintf(out, out_size, MSG_ARG_INVALID,
3323 if (n_tokens0 - n_tokens == 1) {
3324 snprintf(out, out_size, MSG_ARG_INVALID, "action");
3328 return n_tokens0 - n_tokens;
3332 * pipeline <pipeline_name> table <table_id> rule add
3334 * action <table_action>
3337 cmd_pipeline_table_rule_add(char **tokens,
3342 struct table_rule_match m;
3343 struct table_rule_action a;
3344 char *pipeline_name;
3346 uint32_t table_id, t0, n_tokens_parsed;
3350 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3354 pipeline_name = tokens[1];
3356 if (strcmp(tokens[2], "table") != 0) {
3357 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
3361 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
3362 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
3366 if (strcmp(tokens[4], "rule") != 0) {
3367 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
3371 if (strcmp(tokens[5], "add") != 0) {
3372 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
3379 n_tokens_parsed = parse_match(tokens + t0,
3384 if (n_tokens_parsed == 0)
3386 t0 += n_tokens_parsed;
3389 n_tokens_parsed = parse_table_action(tokens + t0,
3394 if (n_tokens_parsed == 0)
3396 t0 += n_tokens_parsed;
3398 if (t0 != n_tokens) {
3399 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
3403 status = pipeline_table_rule_add(pipeline_name, table_id,
3406 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
3412 * pipeline <pipeline_name> table <table_id> rule add
3420 * | table <table_id>
3423 cmd_pipeline_table_rule_add_default(char **tokens,
3428 struct table_rule_action action;
3430 char *pipeline_name;
3434 if ((n_tokens != 11) && (n_tokens != 12)) {
3435 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3439 pipeline_name = tokens[1];
3441 if (strcmp(tokens[2], "table") != 0) {
3442 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
3446 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
3447 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
3451 if (strcmp(tokens[4], "rule") != 0) {
3452 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
3456 if (strcmp(tokens[5], "add") != 0) {
3457 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
3461 if (strcmp(tokens[6], "match") != 0) {
3462 snprintf(out, out_size, MSG_ARG_INVALID, "match");
3466 if (strcmp(tokens[7], "default") != 0) {
3467 snprintf(out, out_size, MSG_ARG_INVALID, "default");
3471 if (strcmp(tokens[8], "action") != 0) {
3472 snprintf(out, out_size, MSG_ARG_INVALID, "action");
3476 if (strcmp(tokens[9], "fwd") != 0) {
3477 snprintf(out, out_size, MSG_ARG_INVALID, "fwd");
3481 action.action_mask = 1 << RTE_TABLE_ACTION_FWD;
3483 if (strcmp(tokens[10], "drop") == 0) {
3484 if (n_tokens != 11) {
3485 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3489 action.fwd.action = RTE_PIPELINE_ACTION_DROP;
3490 } else if (strcmp(tokens[10], "port") == 0) {
3493 if (n_tokens != 12) {
3494 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3498 if (parser_read_uint32(&id, tokens[11]) != 0) {
3499 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
3503 action.fwd.action = RTE_PIPELINE_ACTION_PORT;
3505 } else if (strcmp(tokens[10], "meta") == 0) {
3506 if (n_tokens != 11) {
3507 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3511 action.fwd.action = RTE_PIPELINE_ACTION_PORT_META;
3512 } else if (strcmp(tokens[10], "table") == 0) {
3515 if (n_tokens != 12) {
3516 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3520 if (parser_read_uint32(&id, tokens[11]) != 0) {
3521 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
3525 action.fwd.action = RTE_PIPELINE_ACTION_TABLE;
3528 snprintf(out, out_size, MSG_ARG_INVALID,
3529 "drop or port or meta or table");
3533 status = pipeline_table_rule_add_default(pipeline_name,
3538 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
3544 * pipeline <pipeline_name> table <table_id> rule add bulk <file_name> <n_rules>
3547 * - line format: match <match> action <action>
3550 cli_rule_file_process(const char *file_name,
3551 size_t line_len_max,
3552 struct table_rule_match *m,
3553 struct table_rule_action *a,
3555 uint32_t *line_number,
3560 cmd_pipeline_table_rule_add_bulk(char **tokens,
3565 struct table_rule_match *match;
3566 struct table_rule_action *action;
3568 char *pipeline_name, *file_name;
3569 uint32_t table_id, n_rules, n_rules_parsed, line_number;
3572 if (n_tokens != 9) {
3573 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3577 pipeline_name = tokens[1];
3579 if (strcmp(tokens[2], "table") != 0) {
3580 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
3584 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
3585 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
3589 if (strcmp(tokens[4], "rule") != 0) {
3590 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
3594 if (strcmp(tokens[5], "add") != 0) {
3595 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
3599 if (strcmp(tokens[6], "bulk") != 0) {
3600 snprintf(out, out_size, MSG_ARG_INVALID, "bulk");
3604 file_name = tokens[7];
3606 if ((parser_read_uint32(&n_rules, tokens[8]) != 0) ||
3608 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
3612 /* Memory allocation. */
3613 match = calloc(n_rules, sizeof(struct table_rule_match));
3614 action = calloc(n_rules, sizeof(struct table_rule_action));
3615 data = calloc(n_rules, sizeof(void *));
3616 if ((match == NULL) || (action == NULL) || (data == NULL)) {
3617 snprintf(out, out_size, MSG_OUT_OF_MEMORY);
3624 /* Load rule file */
3625 n_rules_parsed = n_rules;
3626 status = cli_rule_file_process(file_name,
3635 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
3641 if (n_rules_parsed != n_rules) {
3642 snprintf(out, out_size, MSG_FILE_NOT_ENOUGH, file_name);
3650 status = pipeline_table_rule_add_bulk(pipeline_name,
3657 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
3671 * pipeline <pipeline_name> table <table_id> rule delete
3675 cmd_pipeline_table_rule_delete(char **tokens,
3680 struct table_rule_match m;
3681 char *pipeline_name;
3682 uint32_t table_id, n_tokens_parsed, t0;
3686 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3690 pipeline_name = tokens[1];
3692 if (strcmp(tokens[2], "table") != 0) {
3693 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
3697 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
3698 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
3702 if (strcmp(tokens[4], "rule") != 0) {
3703 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
3707 if (strcmp(tokens[5], "delete") != 0) {
3708 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
3715 n_tokens_parsed = parse_match(tokens + t0,
3720 if (n_tokens_parsed == 0)
3722 t0 += n_tokens_parsed;
3724 if (n_tokens != t0) {
3725 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3729 status = pipeline_table_rule_delete(pipeline_name,
3733 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
3739 * pipeline <pipeline_name> table <table_id> rule delete
3744 cmd_pipeline_table_rule_delete_default(char **tokens,
3749 char *pipeline_name;
3753 if (n_tokens != 8) {
3754 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3758 pipeline_name = tokens[1];
3760 if (strcmp(tokens[2], "table") != 0) {
3761 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
3765 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
3766 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
3770 if (strcmp(tokens[4], "rule") != 0) {
3771 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
3775 if (strcmp(tokens[5], "delete") != 0) {
3776 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
3780 if (strcmp(tokens[6], "match") != 0) {
3781 snprintf(out, out_size, MSG_ARG_INVALID, "match");
3785 if (strcmp(tokens[7], "default") != 0) {
3786 snprintf(out, out_size, MSG_ARG_INVALID, "default");
3790 status = pipeline_table_rule_delete_default(pipeline_name,
3793 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
3799 * thread <thread_id> pipeline <pipeline_name> enable
3802 cmd_thread_pipeline_enable(char **tokens,
3807 char *pipeline_name;
3811 if (n_tokens != 5) {
3812 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3816 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
3817 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
3821 if (strcmp(tokens[2], "pipeline") != 0) {
3822 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
3826 pipeline_name = tokens[3];
3828 if (strcmp(tokens[4], "enable") != 0) {
3829 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
3833 status = thread_pipeline_enable(thread_id, pipeline_name);
3835 snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable");
3841 * thread <thread_id> pipeline <pipeline_name> disable
3844 cmd_thread_pipeline_disable(char **tokens,
3849 char *pipeline_name;
3853 if (n_tokens != 5) {
3854 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3858 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
3859 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
3863 if (strcmp(tokens[2], "pipeline") != 0) {
3864 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
3868 pipeline_name = tokens[3];
3870 if (strcmp(tokens[4], "disable") != 0) {
3871 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
3875 status = thread_pipeline_disable(thread_id, pipeline_name);
3877 snprintf(out, out_size, MSG_CMD_FAIL,
3878 "thread pipeline disable");
3884 cli_process(char *in, char *out, size_t out_size)
3886 char *tokens[CMD_MAX_TOKENS];
3887 uint32_t n_tokens = RTE_DIM(tokens);
3893 status = parse_tokenize_string(in, tokens, &n_tokens);
3895 snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
3902 if (strcmp(tokens[0], "mempool") == 0) {
3903 cmd_mempool(tokens, n_tokens, out, out_size);
3907 if (strcmp(tokens[0], "link") == 0) {
3908 cmd_link(tokens, n_tokens, out, out_size);
3912 if (strcmp(tokens[0], "swq") == 0) {
3913 cmd_swq(tokens, n_tokens, out, out_size);
3917 if (strcmp(tokens[0], "tmgr") == 0) {
3918 if ((n_tokens >= 3) &&
3919 (strcmp(tokens[1], "subport") == 0) &&
3920 (strcmp(tokens[2], "profile") == 0)) {
3921 cmd_tmgr_subport_profile(tokens, n_tokens,
3926 if ((n_tokens >= 3) &&
3927 (strcmp(tokens[1], "pipe") == 0) &&
3928 (strcmp(tokens[2], "profile") == 0)) {
3929 cmd_tmgr_pipe_profile(tokens, n_tokens, out, out_size);
3933 if ((n_tokens >= 5) &&
3934 (strcmp(tokens[2], "subport") == 0) &&
3935 (strcmp(tokens[4], "profile") == 0)) {
3936 cmd_tmgr_subport(tokens, n_tokens, out, out_size);
3940 if ((n_tokens >= 5) &&
3941 (strcmp(tokens[2], "subport") == 0) &&
3942 (strcmp(tokens[4], "pipe") == 0)) {
3943 cmd_tmgr_subport_pipe(tokens, n_tokens, out, out_size);
3947 cmd_tmgr(tokens, n_tokens, out, out_size);
3951 if (strcmp(tokens[0], "tap") == 0) {
3952 cmd_tap(tokens, n_tokens, out, out_size);
3956 if (strcmp(tokens[0], "kni") == 0) {
3957 cmd_kni(tokens, n_tokens, out, out_size);
3961 if (strcmp(tokens[0], "port") == 0) {
3962 cmd_port_in_action_profile(tokens, n_tokens, out, out_size);
3966 if (strcmp(tokens[0], "table") == 0) {
3967 cmd_table_action_profile(tokens, n_tokens, out, out_size);
3971 if (strcmp(tokens[0], "pipeline") == 0) {
3972 if ((n_tokens >= 3) &&
3973 (strcmp(tokens[2], "period") == 0)) {
3974 cmd_pipeline(tokens, n_tokens, out, out_size);
3978 if ((n_tokens >= 5) &&
3979 (strcmp(tokens[2], "port") == 0) &&
3980 (strcmp(tokens[3], "in") == 0) &&
3981 (strcmp(tokens[4], "bsz") == 0)) {
3982 cmd_pipeline_port_in(tokens, n_tokens, out, out_size);
3986 if ((n_tokens >= 5) &&
3987 (strcmp(tokens[2], "port") == 0) &&
3988 (strcmp(tokens[3], "out") == 0) &&
3989 (strcmp(tokens[4], "bsz") == 0)) {
3990 cmd_pipeline_port_out(tokens, n_tokens, out, out_size);
3994 if ((n_tokens >= 4) &&
3995 (strcmp(tokens[2], "table") == 0) &&
3996 (strcmp(tokens[3], "match") == 0)) {
3997 cmd_pipeline_table(tokens, n_tokens, out, out_size);
4001 if ((n_tokens >= 6) &&
4002 (strcmp(tokens[2], "port") == 0) &&
4003 (strcmp(tokens[3], "in") == 0) &&
4004 (strcmp(tokens[5], "table") == 0)) {
4005 cmd_pipeline_port_in_table(tokens, n_tokens,
4010 if ((n_tokens >= 6) &&
4011 (strcmp(tokens[2], "port") == 0) &&
4012 (strcmp(tokens[3], "in") == 0) &&
4013 (strcmp(tokens[5], "stats") == 0)) {
4014 cmd_pipeline_port_in_stats(tokens, n_tokens,
4019 if ((n_tokens >= 6) &&
4020 (strcmp(tokens[2], "port") == 0) &&
4021 (strcmp(tokens[3], "in") == 0) &&
4022 (strcmp(tokens[5], "enable") == 0)) {
4023 cmd_pipeline_port_in_enable(tokens, n_tokens,
4028 if ((n_tokens >= 6) &&
4029 (strcmp(tokens[2], "port") == 0) &&
4030 (strcmp(tokens[3], "in") == 0) &&
4031 (strcmp(tokens[5], "disable") == 0)) {
4032 cmd_pipeline_port_in_disable(tokens, n_tokens,
4037 if ((n_tokens >= 6) &&
4038 (strcmp(tokens[2], "port") == 0) &&
4039 (strcmp(tokens[3], "out") == 0) &&
4040 (strcmp(tokens[5], "stats") == 0)) {
4041 cmd_pipeline_port_out_stats(tokens, n_tokens,
4046 if ((n_tokens >= 5) &&
4047 (strcmp(tokens[2], "table") == 0) &&
4048 (strcmp(tokens[4], "stats") == 0)) {
4049 cmd_pipeline_table_stats(tokens, n_tokens,
4054 if ((n_tokens >= 7) &&
4055 (strcmp(tokens[2], "table") == 0) &&
4056 (strcmp(tokens[4], "rule") == 0) &&
4057 (strcmp(tokens[5], "add") == 0) &&
4058 (strcmp(tokens[6], "match") == 0)) {
4059 if ((n_tokens >= 8) &&
4060 (strcmp(tokens[7], "default") == 0)) {
4061 cmd_pipeline_table_rule_add_default(tokens,
4062 n_tokens, out, out_size);
4066 cmd_pipeline_table_rule_add(tokens, n_tokens,
4071 if ((n_tokens >= 7) &&
4072 (strcmp(tokens[2], "table") == 0) &&
4073 (strcmp(tokens[4], "rule") == 0) &&
4074 (strcmp(tokens[5], "add") == 0) &&
4075 (strcmp(tokens[6], "bulk") == 0)) {
4076 cmd_pipeline_table_rule_add_bulk(tokens,
4077 n_tokens, out, out_size);
4081 if ((n_tokens >= 7) &&
4082 (strcmp(tokens[2], "table") == 0) &&
4083 (strcmp(tokens[4], "rule") == 0) &&
4084 (strcmp(tokens[5], "delete") == 0) &&
4085 (strcmp(tokens[6], "match") == 0)) {
4086 if ((n_tokens >= 8) &&
4087 (strcmp(tokens[7], "default") == 0)) {
4088 cmd_pipeline_table_rule_delete_default(tokens,
4089 n_tokens, out, out_size);
4093 cmd_pipeline_table_rule_delete(tokens, n_tokens,
4099 if (strcmp(tokens[0], "thread") == 0) {
4100 if ((n_tokens >= 5) &&
4101 (strcmp(tokens[4], "enable") == 0)) {
4102 cmd_thread_pipeline_enable(tokens, n_tokens,
4107 if ((n_tokens >= 5) &&
4108 (strcmp(tokens[4], "disable") == 0)) {
4109 cmd_thread_pipeline_disable(tokens, n_tokens,
4115 snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
4119 cli_script_process(const char *file_name,
4120 size_t msg_in_len_max,
4121 size_t msg_out_len_max)
4123 char *msg_in = NULL, *msg_out = NULL;
4126 /* Check input arguments */
4127 if ((file_name == NULL) ||
4128 (strlen(file_name) == 0) ||
4129 (msg_in_len_max == 0) ||
4130 (msg_out_len_max == 0))
4133 msg_in = malloc(msg_in_len_max + 1);
4134 msg_out = malloc(msg_out_len_max + 1);
4135 if ((msg_in == NULL) ||
4136 (msg_out == NULL)) {
4142 /* Open input file */
4143 f = fopen(file_name, "r");
4152 if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
4155 printf("%s", msg_in);
4162 if (strlen(msg_out))
4163 printf("%s", msg_out);
4174 cli_rule_file_process(const char *file_name,
4175 size_t line_len_max,
4176 struct table_rule_match *m,
4177 struct table_rule_action *a,
4179 uint32_t *line_number,
4185 uint32_t rule_id, line_id;
4188 /* Check input arguments */
4189 if ((file_name == NULL) ||
4190 (strlen(file_name) == 0) ||
4191 (line_len_max == 0)) {
4196 /* Memory allocation */
4197 line = malloc(line_len_max + 1);
4204 f = fopen(file_name, "r");
4212 for (line_id = 1, rule_id = 0; rule_id < *n_rules; line_id++) {
4213 char *tokens[CMD_MAX_TOKENS];
4214 uint32_t n_tokens, n_tokens_parsed, t0;
4216 /* Read next line from file. */
4217 if (fgets(line, line_len_max + 1, f) == NULL)
4221 if (is_comment(line))
4225 n_tokens = RTE_DIM(tokens);
4226 status = parse_tokenize_string(line, tokens, &n_tokens);
4238 n_tokens_parsed = parse_match(tokens + t0,
4243 if (n_tokens_parsed == 0) {
4247 t0 += n_tokens_parsed;
4250 n_tokens_parsed = parse_table_action(tokens + t0,
4255 if (n_tokens_parsed == 0) {
4259 t0 += n_tokens_parsed;
4261 /* Line completed. */
4262 if (t0 < n_tokens) {
4267 /* Increment rule count */
4278 *line_number = line_id;