1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
10 #include <rte_common.h>
11 #include <rte_cycles.h>
12 #include <rte_string_fns.h>
13 #include <rte_cryptodev.h>
15 #include "rte_eth_softnic_internals.h"
18 #ifndef CMD_MAX_TOKENS
19 #define CMD_MAX_TOKENS 256
22 #define MSG_OUT_OF_MEMORY "Not enough memory.\n"
23 #define MSG_CMD_UNKNOWN "Unknown command \"%s\".\n"
24 #define MSG_CMD_UNIMPLEM "Command \"%s\" not implemented.\n"
25 #define MSG_ARG_NOT_ENOUGH "Not enough arguments for command \"%s\".\n"
26 #define MSG_ARG_TOO_MANY "Too many arguments for command \"%s\".\n"
27 #define MSG_ARG_MISMATCH "Wrong number of arguments for command \"%s\".\n"
28 #define MSG_ARG_NOT_FOUND "Argument \"%s\" not found.\n"
29 #define MSG_ARG_INVALID "Invalid value for argument \"%s\".\n"
30 #define MSG_FILE_ERR "Error in file \"%s\" at line %u.\n"
31 #define MSG_FILE_NOT_ENOUGH "Not enough rules in file \"%s\".\n"
32 #define MSG_CMD_FAIL "Command \"%s\" failed.\n"
37 if ((strlen(in) && index("!#%;", in[0])) ||
38 (strncmp(in, "//", 2) == 0) ||
39 (strncmp(in, "--", 2) == 0))
46 * mempool <mempool_name>
47 * buffer <buffer_size>
52 cmd_mempool(struct pmd_internals *softnic,
58 struct softnic_mempool_params p;
60 struct softnic_mempool *mempool;
63 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
69 if (strcmp(tokens[2], "buffer") != 0) {
70 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buffer");
74 if (softnic_parser_read_uint32(&p.buffer_size, tokens[3]) != 0) {
75 snprintf(out, out_size, MSG_ARG_INVALID, "buffer_size");
79 if (strcmp(tokens[4], "pool") != 0) {
80 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pool");
84 if (softnic_parser_read_uint32(&p.pool_size, tokens[5]) != 0) {
85 snprintf(out, out_size, MSG_ARG_INVALID, "pool_size");
89 if (strcmp(tokens[6], "cache") != 0) {
90 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cache");
94 if (softnic_parser_read_uint32(&p.cache_size, tokens[7]) != 0) {
95 snprintf(out, out_size, MSG_ARG_INVALID, "cache_size");
99 mempool = softnic_mempool_create(softnic, name, &p);
100 if (mempool == NULL) {
101 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
108 * dev <device_name> | port <port_id>
111 cmd_link(struct pmd_internals *softnic,
117 struct softnic_link_params p;
118 struct softnic_link *link;
121 memset(&p, 0, sizeof(p));
124 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
129 if (strcmp(tokens[2], "dev") == 0) {
130 p.dev_name = tokens[3];
131 } else if (strcmp(tokens[2], "port") == 0) {
134 if (softnic_parser_read_uint16(&p.port_id, tokens[3]) != 0) {
135 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
139 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dev or port");
143 link = softnic_link_create(softnic, name, &p);
145 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
155 cmd_swq(struct pmd_internals *softnic,
161 struct softnic_swq_params p;
163 struct softnic_swq *swq;
166 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
172 if (strcmp(tokens[2], "size") != 0) {
173 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
177 if (softnic_parser_read_uint32(&p.size, tokens[3]) != 0) {
178 snprintf(out, out_size, MSG_ARG_INVALID, "size");
182 swq = softnic_swq_create(softnic, name, &p);
184 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
190 * tmgr shaper profile
192 * rate <tb_rate> size <tb_size>
193 * adj <packet_length_adjust>
196 cmd_tmgr_shaper_profile(struct pmd_internals *softnic,
202 struct rte_tm_shaper_params sp;
203 struct rte_tm_error error;
204 uint32_t shaper_profile_id;
208 memset(&sp, 0, sizeof(struct rte_tm_shaper_params));
210 if (n_tokens != 11) {
211 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
215 if (strcmp(tokens[1], "shaper") != 0) {
216 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "shaper");
220 if (strcmp(tokens[2], "profile") != 0) {
221 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
225 if (strcmp(tokens[3], "id") != 0) {
226 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "id");
230 if (softnic_parser_read_uint32(&shaper_profile_id, tokens[4]) != 0) {
231 snprintf(out, out_size, MSG_ARG_INVALID, "profile_id");
235 if (strcmp(tokens[5], "rate") != 0) {
236 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rate");
240 if (softnic_parser_read_uint64(&sp.peak.rate, tokens[6]) != 0) {
241 snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate");
245 if (strcmp(tokens[7], "size") != 0) {
246 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
250 if (softnic_parser_read_uint64(&sp.peak.size, tokens[8]) != 0) {
251 snprintf(out, out_size, MSG_ARG_INVALID, "tb_size");
255 if (strcmp(tokens[9], "adj") != 0) {
256 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "adj");
260 if (softnic_parser_read_int32(&sp.pkt_length_adjust, tokens[10]) != 0) {
261 snprintf(out, out_size, MSG_ARG_INVALID, "packet_length_adjust");
265 status = rte_eth_dev_get_port_by_name(softnic->params.name, &port_id);
269 status = rte_tm_shaper_profile_add(port_id, shaper_profile_id, &sp, &error);
271 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
278 * id <shared_shaper_id>
279 * profile <shaper_profile_id>
282 cmd_tmgr_shared_shaper(struct pmd_internals *softnic,
288 struct rte_tm_error error;
289 uint32_t shared_shaper_id, shaper_profile_id;
294 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
298 if (strcmp(tokens[1], "shared") != 0) {
299 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "shared");
303 if (strcmp(tokens[2], "shaper") != 0) {
304 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "shaper");
308 if (strcmp(tokens[3], "id") != 0) {
309 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "id");
313 if (softnic_parser_read_uint32(&shared_shaper_id, tokens[4]) != 0) {
314 snprintf(out, out_size, MSG_ARG_INVALID, "shared_shaper_id");
318 if (strcmp(tokens[5], "profile") != 0) {
319 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
323 if (softnic_parser_read_uint32(&shaper_profile_id, tokens[6]) != 0) {
324 snprintf(out, out_size, MSG_ARG_INVALID, "shaper_profile_id");
328 status = rte_eth_dev_get_port_by_name(softnic->params.name, &port_id);
332 status = rte_tm_shared_shaper_add_update(port_id,
337 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
345 * parent <parent_node_id | none>
346 * priority <priority>
348 * [shaper profile <shaper_profile_id>]
349 * [shared shaper <shared_shaper_id>]
350 * [nonleaf sp <n_sp_priorities>]
353 cmd_tmgr_node(struct pmd_internals *softnic,
359 struct rte_tm_error error;
360 struct rte_tm_node_params np;
361 uint32_t node_id, parent_node_id, priority, weight, shared_shaper_id;
365 memset(&np, 0, sizeof(struct rte_tm_node_params));
366 np.shaper_profile_id = RTE_TM_SHAPER_PROFILE_ID_NONE;
367 np.nonleaf.n_sp_priorities = 1;
370 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
374 if (strcmp(tokens[1], "node") != 0) {
375 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "node");
379 if (strcmp(tokens[2], "id") != 0) {
380 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "id");
384 if (softnic_parser_read_uint32(&node_id, tokens[3]) != 0) {
385 snprintf(out, out_size, MSG_ARG_INVALID, "node_id");
389 if (strcmp(tokens[4], "parent") != 0) {
390 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "parent");
394 if (strcmp(tokens[5], "none") == 0)
395 parent_node_id = RTE_TM_NODE_ID_NULL;
397 if (softnic_parser_read_uint32(&parent_node_id, tokens[5]) != 0) {
398 snprintf(out, out_size, MSG_ARG_INVALID, "parent_node_id");
403 if (strcmp(tokens[6], "priority") != 0) {
404 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "priority");
408 if (softnic_parser_read_uint32(&priority, tokens[7]) != 0) {
409 snprintf(out, out_size, MSG_ARG_INVALID, "priority");
413 if (strcmp(tokens[8], "weight") != 0) {
414 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "weight");
418 if (softnic_parser_read_uint32(&weight, tokens[9]) != 0) {
419 snprintf(out, out_size, MSG_ARG_INVALID, "weight");
427 (strcmp(tokens[0], "shaper") == 0) &&
428 (strcmp(tokens[1], "profile") == 0)) {
430 snprintf(out, out_size, MSG_ARG_MISMATCH, "tmgr node");
434 if (strcmp(tokens[2], "none") == 0) {
435 np.shaper_profile_id = RTE_TM_SHAPER_PROFILE_ID_NONE;
437 if (softnic_parser_read_uint32(&np.shaper_profile_id, tokens[2]) != 0) {
438 snprintf(out, out_size, MSG_ARG_INVALID, "shaper_profile_id");
445 } /* shaper profile */
448 (strcmp(tokens[0], "shared") == 0) &&
449 (strcmp(tokens[1], "shaper") == 0)) {
451 snprintf(out, out_size, MSG_ARG_MISMATCH, "tmgr node");
455 if (softnic_parser_read_uint32(&shared_shaper_id, tokens[2]) != 0) {
456 snprintf(out, out_size, MSG_ARG_INVALID, "shared_shaper_id");
460 np.shared_shaper_id = &shared_shaper_id;
461 np.n_shared_shapers = 1;
465 } /* shared shaper */
468 (strcmp(tokens[0], "nonleaf") == 0) &&
469 (strcmp(tokens[1], "sp") == 0)) {
471 snprintf(out, out_size, MSG_ARG_MISMATCH, "tmgr node");
475 if (softnic_parser_read_uint32(&np.nonleaf.n_sp_priorities, tokens[2]) != 0) {
476 snprintf(out, out_size, MSG_ARG_INVALID, "n_sp_priorities");
482 } /* nonleaf sp <n_sp_priorities> */
485 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
489 status = rte_eth_dev_get_port_by_name(softnic->params.name, &port_id);
493 status = rte_tm_node_add(port_id,
498 RTE_TM_NODE_LEVEL_ID_ANY,
502 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
508 root_node_id(uint32_t n_spp,
511 uint32_t n_queues = n_spp * n_pps * RTE_SCHED_QUEUES_PER_PIPE;
512 uint32_t n_tc = n_spp * n_pps * RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE;
513 uint32_t n_pipes = n_spp * n_pps;
515 return n_queues + n_tc + n_pipes + n_spp;
519 subport_node_id(uint32_t n_spp,
523 uint32_t n_pipes = n_spp * n_pps;
524 uint32_t n_tc = n_pipes * RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE;
525 uint32_t n_queues = n_pipes * RTE_SCHED_QUEUES_PER_PIPE;
527 return n_queues + n_tc + n_pipes + subport_id;
531 pipe_node_id(uint32_t n_spp,
536 uint32_t n_pipes = n_spp * n_pps;
537 uint32_t n_tc = n_pipes * RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE;
538 uint32_t n_queues = n_pipes * RTE_SCHED_QUEUES_PER_PIPE;
547 tc_node_id(uint32_t n_spp,
553 uint32_t n_pipes = n_spp * n_pps;
554 uint32_t n_queues = n_pipes * RTE_SCHED_QUEUES_PER_PIPE;
558 (pipe_id + subport_id * n_pps) * RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE;
562 queue_node_id(uint32_t n_spp __rte_unused,
570 tc_id * RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE +
571 (pipe_id + subport_id * n_pps) * RTE_SCHED_QUEUES_PER_PIPE;
574 struct tmgr_hierarchy_default_params {
575 uint32_t n_spp; /**< Number of subports per port. */
576 uint32_t n_pps; /**< Number of pipes per subport. */
582 uint32_t tc[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
586 uint32_t tc[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
587 uint32_t tc_valid[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
591 uint32_t queue[RTE_SCHED_QUEUES_PER_PIPE];
596 tmgr_hierarchy_default(struct pmd_internals *softnic,
597 struct tmgr_hierarchy_default_params *params)
599 struct rte_tm_node_params root_node_params = {
600 .shaper_profile_id = params->shaper_profile_id.port,
602 .n_sp_priorities = 1,
606 struct rte_tm_node_params subport_node_params = {
607 .shaper_profile_id = params->shaper_profile_id.subport,
609 .n_sp_priorities = 1,
613 struct rte_tm_node_params pipe_node_params = {
614 .shaper_profile_id = params->shaper_profile_id.pipe,
616 .n_sp_priorities = RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE,
620 struct rte_tm_node_params tc_node_params[] = {
622 .shaper_profile_id = params->shaper_profile_id.tc[0],
623 .shared_shaper_id = ¶ms->shared_shaper_id.tc[0],
625 (¶ms->shared_shaper_id.tc_valid[0]) ? 1 : 0,
627 .n_sp_priorities = 1,
632 .shaper_profile_id = params->shaper_profile_id.tc[1],
633 .shared_shaper_id = ¶ms->shared_shaper_id.tc[1],
635 (¶ms->shared_shaper_id.tc_valid[1]) ? 1 : 0,
637 .n_sp_priorities = 1,
642 .shaper_profile_id = params->shaper_profile_id.tc[2],
643 .shared_shaper_id = ¶ms->shared_shaper_id.tc[2],
645 (¶ms->shared_shaper_id.tc_valid[2]) ? 1 : 0,
647 .n_sp_priorities = 1,
652 .shaper_profile_id = params->shaper_profile_id.tc[3],
653 .shared_shaper_id = ¶ms->shared_shaper_id.tc[3],
655 (¶ms->shared_shaper_id.tc_valid[3]) ? 1 : 0,
657 .n_sp_priorities = 1,
662 struct rte_tm_node_params queue_node_params = {
663 .shaper_profile_id = RTE_TM_SHAPER_PROFILE_ID_NONE,
666 struct rte_tm_error error;
667 uint32_t n_spp = params->n_spp, n_pps = params->n_pps, s;
671 status = rte_eth_dev_get_port_by_name(softnic->params.name, &port_id);
675 /* Hierarchy level 0: Root node */
676 status = rte_tm_node_add(port_id,
677 root_node_id(n_spp, n_pps),
681 RTE_TM_NODE_LEVEL_ID_ANY,
687 /* Hierarchy level 1: Subport nodes */
688 for (s = 0; s < params->n_spp; s++) {
691 status = rte_tm_node_add(port_id,
692 subport_node_id(n_spp, n_pps, s),
693 root_node_id(n_spp, n_pps),
696 RTE_TM_NODE_LEVEL_ID_ANY,
697 &subport_node_params,
702 /* Hierarchy level 2: Pipe nodes */
703 for (p = 0; p < params->n_pps; p++) {
706 status = rte_tm_node_add(port_id,
707 pipe_node_id(n_spp, n_pps, s, p),
708 subport_node_id(n_spp, n_pps, s),
711 RTE_TM_NODE_LEVEL_ID_ANY,
717 /* Hierarchy level 3: Traffic class nodes */
718 for (t = 0; t < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; t++) {
721 status = rte_tm_node_add(port_id,
722 tc_node_id(n_spp, n_pps, s, p, t),
723 pipe_node_id(n_spp, n_pps, s, p),
726 RTE_TM_NODE_LEVEL_ID_ANY,
732 /* Hierarchy level 4: Queue nodes */
733 for (q = 0; q < RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS; q++) {
734 status = rte_tm_node_add(port_id,
735 queue_node_id(n_spp, n_pps, s, p, t, q),
736 tc_node_id(n_spp, n_pps, s, p, t),
738 params->weight.queue[q],
739 RTE_TM_NODE_LEVEL_ID_ANY,
754 * tmgr hierarchy-default
755 * spp <n_subports_per_port>
756 * pps <n_pipes_per_subport>
759 * subport <profile_id>
771 * queue <q0> ... <q15>
774 cmd_tmgr_hierarchy_default(struct pmd_internals *softnic,
780 struct tmgr_hierarchy_default_params p;
783 memset(&p, 0, sizeof(p));
785 if (n_tokens != 50) {
786 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
790 if (strcmp(tokens[1], "hierarchy-default") != 0) {
791 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "hierarchy-default");
795 if (strcmp(tokens[2], "spp") != 0) {
796 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
800 if (softnic_parser_read_uint32(&p.n_spp, tokens[3]) != 0) {
801 snprintf(out, out_size, MSG_ARG_INVALID, "n_subports_per_port");
805 if (strcmp(tokens[4], "pps") != 0) {
806 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
810 if (softnic_parser_read_uint32(&p.n_pps, tokens[5]) != 0) {
811 snprintf(out, out_size, MSG_ARG_INVALID, "n_pipes_per_subport");
817 if (strcmp(tokens[6], "shaper") != 0) {
818 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "shaper");
822 if (strcmp(tokens[7], "profile") != 0) {
823 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
827 if (strcmp(tokens[8], "port") != 0) {
828 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
832 if (softnic_parser_read_uint32(&p.shaper_profile_id.port, tokens[9]) != 0) {
833 snprintf(out, out_size, MSG_ARG_INVALID, "port profile id");
837 if (strcmp(tokens[10], "subport") != 0) {
838 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "subport");
842 if (softnic_parser_read_uint32(&p.shaper_profile_id.subport, tokens[11]) != 0) {
843 snprintf(out, out_size, MSG_ARG_INVALID, "subport profile id");
847 if (strcmp(tokens[12], "pipe") != 0) {
848 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipe");
852 if (softnic_parser_read_uint32(&p.shaper_profile_id.pipe, tokens[13]) != 0) {
853 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_profile_id");
857 if (strcmp(tokens[14], "tc0") != 0) {
858 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc0");
862 if (softnic_parser_read_uint32(&p.shaper_profile_id.tc[0], tokens[15]) != 0) {
863 snprintf(out, out_size, MSG_ARG_INVALID, "tc0 profile id");
867 if (strcmp(tokens[16], "tc1") != 0) {
868 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc1");
872 if (softnic_parser_read_uint32(&p.shaper_profile_id.tc[1], tokens[17]) != 0) {
873 snprintf(out, out_size, MSG_ARG_INVALID, "tc1 profile id");
877 if (strcmp(tokens[18], "tc2") != 0) {
878 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc2");
882 if (softnic_parser_read_uint32(&p.shaper_profile_id.tc[2], tokens[19]) != 0) {
883 snprintf(out, out_size, MSG_ARG_INVALID, "tc2 profile id");
887 if (strcmp(tokens[20], "tc3") != 0) {
888 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc3");
892 if (softnic_parser_read_uint32(&p.shaper_profile_id.tc[3], tokens[21]) != 0) {
893 snprintf(out, out_size, MSG_ARG_INVALID, "tc3 profile id");
899 if (strcmp(tokens[22], "shared") != 0) {
900 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "shared");
904 if (strcmp(tokens[23], "shaper") != 0) {
905 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "shaper");
909 if (strcmp(tokens[24], "tc0") != 0) {
910 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc0");
914 if (strcmp(tokens[25], "none") == 0)
915 p.shared_shaper_id.tc_valid[0] = 0;
917 if (softnic_parser_read_uint32(&p.shared_shaper_id.tc[0], tokens[25]) != 0) {
918 snprintf(out, out_size, MSG_ARG_INVALID, "shared shaper tc0");
922 p.shared_shaper_id.tc_valid[0] = 1;
925 if (strcmp(tokens[26], "tc1") != 0) {
926 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc1");
930 if (strcmp(tokens[27], "none") == 0)
931 p.shared_shaper_id.tc_valid[1] = 0;
933 if (softnic_parser_read_uint32(&p.shared_shaper_id.tc[1], tokens[27]) != 0) {
934 snprintf(out, out_size, MSG_ARG_INVALID, "shared shaper tc1");
938 p.shared_shaper_id.tc_valid[1] = 1;
941 if (strcmp(tokens[28], "tc2") != 0) {
942 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc2");
946 if (strcmp(tokens[29], "none") == 0)
947 p.shared_shaper_id.tc_valid[2] = 0;
949 if (softnic_parser_read_uint32(&p.shared_shaper_id.tc[2], tokens[29]) != 0) {
950 snprintf(out, out_size, MSG_ARG_INVALID, "shared shaper tc2");
954 p.shared_shaper_id.tc_valid[2] = 1;
957 if (strcmp(tokens[30], "tc3") != 0) {
958 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc3");
962 if (strcmp(tokens[31], "none") == 0)
963 p.shared_shaper_id.tc_valid[3] = 0;
965 if (softnic_parser_read_uint32(&p.shared_shaper_id.tc[3], tokens[31]) != 0) {
966 snprintf(out, out_size, MSG_ARG_INVALID, "shared shaper tc3");
970 p.shared_shaper_id.tc_valid[3] = 1;
975 if (strcmp(tokens[32], "weight") != 0) {
976 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "weight");
980 if (strcmp(tokens[33], "queue") != 0) {
981 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "queue");
985 for (i = 0; i < 16; i++) {
986 if (softnic_parser_read_uint32(&p.weight.queue[i], tokens[34 + i]) != 0) {
987 snprintf(out, out_size, MSG_ARG_INVALID, "weight queue");
992 status = tmgr_hierarchy_default(softnic, &p);
994 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1000 * tmgr hierarchy commit
1003 cmd_tmgr_hierarchy_commit(struct pmd_internals *softnic,
1009 struct rte_tm_error error;
1013 if (n_tokens != 3) {
1014 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1018 if (strcmp(tokens[1], "hierarchy") != 0) {
1019 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "hierarchy");
1023 if (strcmp(tokens[2], "commit") != 0) {
1024 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "commit");
1028 status = rte_eth_dev_get_port_by_name(softnic->params.name, &port_id);
1032 status = rte_tm_hierarchy_commit(port_id, 1, &error);
1034 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1043 cmd_tmgr(struct pmd_internals *softnic,
1050 struct softnic_tmgr_port *tmgr_port;
1052 if (n_tokens != 2) {
1053 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1059 tmgr_port = softnic_tmgr_port_create(softnic, name);
1060 if (tmgr_port == NULL) {
1061 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1070 cmd_tap(struct pmd_internals *softnic,
1077 struct softnic_tap *tap;
1079 if (n_tokens != 2) {
1080 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1086 tap = softnic_tap_create(softnic, name);
1088 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1094 * cryptodev <tap_name> dev <device_name> | dev_id <device_id>
1095 * queue <n_queues> <queue_size>
1099 cmd_cryptodev(struct pmd_internals *softnic,
1105 struct softnic_cryptodev_params params;
1108 memset(¶ms, 0, sizeof(params));
1109 if (n_tokens != 7) {
1110 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1116 if (strcmp(tokens[2], "dev") == 0)
1117 params.dev_name = tokens[3];
1118 else if (strcmp(tokens[2], "dev_id") == 0) {
1119 if (softnic_parser_read_uint32(¶ms.dev_id, tokens[3]) < 0) {
1120 snprintf(out, out_size, MSG_ARG_INVALID,
1125 snprintf(out, out_size, MSG_ARG_INVALID,
1130 if (strcmp(tokens[4], "queue")) {
1131 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1136 if (softnic_parser_read_uint32(¶ms.n_queues, tokens[5]) < 0) {
1137 snprintf(out, out_size, MSG_ARG_INVALID,
1142 if (softnic_parser_read_uint32(¶ms.queue_size, tokens[6]) < 0) {
1143 snprintf(out, out_size, MSG_ARG_INVALID,
1148 if (softnic_cryptodev_create(softnic, name, ¶ms) == NULL) {
1149 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1155 * port in action profile <profile_name>
1156 * [filter match | mismatch offset <key_offset> mask <key_mask> key <key_value> port <port_id>]
1157 * [balance offset <key_offset> mask <key_mask> port <port_id0> ... <port_id15>]
1160 cmd_port_in_action_profile(struct pmd_internals *softnic,
1166 struct softnic_port_in_action_profile_params p;
1167 struct softnic_port_in_action_profile *ap;
1171 memset(&p, 0, sizeof(p));
1174 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1178 if (strcmp(tokens[1], "in") != 0) {
1179 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1183 if (strcmp(tokens[2], "action") != 0) {
1184 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
1188 if (strcmp(tokens[3], "profile") != 0) {
1189 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
1197 if (t0 < n_tokens &&
1198 (strcmp(tokens[t0], "filter") == 0)) {
1201 if (n_tokens < t0 + 10) {
1202 snprintf(out, out_size, MSG_ARG_MISMATCH, "port in action profile filter");
1206 if (strcmp(tokens[t0 + 1], "match") == 0) {
1207 p.fltr.filter_on_match = 1;
1208 } else if (strcmp(tokens[t0 + 1], "mismatch") == 0) {
1209 p.fltr.filter_on_match = 0;
1211 snprintf(out, out_size, MSG_ARG_INVALID, "match or mismatch");
1215 if (strcmp(tokens[t0 + 2], "offset") != 0) {
1216 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1220 if (softnic_parser_read_uint32(&p.fltr.key_offset,
1221 tokens[t0 + 3]) != 0) {
1222 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1226 if (strcmp(tokens[t0 + 4], "mask") != 0) {
1227 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
1231 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
1232 if ((softnic_parse_hex_string(tokens[t0 + 5],
1233 p.fltr.key_mask, &size) != 0) ||
1234 size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE) {
1235 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1239 if (strcmp(tokens[t0 + 6], "key") != 0) {
1240 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
1244 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
1245 if ((softnic_parse_hex_string(tokens[t0 + 7],
1246 p.fltr.key, &size) != 0) ||
1247 size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE) {
1248 snprintf(out, out_size, MSG_ARG_INVALID, "key_value");
1252 if (strcmp(tokens[t0 + 8], "port") != 0) {
1253 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1257 if (softnic_parser_read_uint32(&p.fltr.port_id,
1258 tokens[t0 + 9]) != 0) {
1259 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
1263 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_FLTR;
1267 if (t0 < n_tokens &&
1268 (strcmp(tokens[t0], "balance") == 0)) {
1271 if (n_tokens < t0 + 22) {
1272 snprintf(out, out_size, MSG_ARG_MISMATCH,
1273 "port in action profile balance");
1277 if (strcmp(tokens[t0 + 1], "offset") != 0) {
1278 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1282 if (softnic_parser_read_uint32(&p.lb.key_offset,
1283 tokens[t0 + 2]) != 0) {
1284 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1288 if (strcmp(tokens[t0 + 3], "mask") != 0) {
1289 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
1293 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
1294 if (softnic_parse_hex_string(tokens[t0 + 4],
1295 p.lb.key_mask, &p.lb.key_size) != 0) {
1296 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1300 if (strcmp(tokens[t0 + 5], "port") != 0) {
1301 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1305 for (i = 0; i < 16; i++)
1306 if (softnic_parser_read_uint32(&p.lb.port_id[i],
1307 tokens[t0 + 6 + i]) != 0) {
1308 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
1312 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_LB;
1316 if (t0 < n_tokens) {
1317 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1321 ap = softnic_port_in_action_profile_create(softnic, name, &p);
1323 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1329 * table action profile <profile_name>
1331 * offset <ip_offset>
1333 * [balance offset <key_offset> mask <key_mask> outoffset <out_offset>]
1334 * [meter srtcm | trtcm
1336 * stats none | pkts | bytes | both]
1337 * [tm spp <n_subports_per_port> pps <n_pipes_per_subport>]
1338 * [encap ether | vlan | qinq | mpls | pppoe |
1339 * vxlan offset <ether_offset> ipv4 | ipv6 vlan on | off]
1343 * stats none | pkts]
1344 * [stats pkts | bytes | both]
1351 cmd_table_action_profile(struct pmd_internals *softnic,
1357 struct softnic_table_action_profile_params p;
1358 struct softnic_table_action_profile *ap;
1362 memset(&p, 0, sizeof(p));
1365 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1369 if (strcmp(tokens[1], "action") != 0) {
1370 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
1374 if (strcmp(tokens[2], "profile") != 0) {
1375 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
1381 if (strcmp(tokens[4], "ipv4") == 0) {
1382 p.common.ip_version = 1;
1383 } else if (strcmp(tokens[4], "ipv6") == 0) {
1384 p.common.ip_version = 0;
1386 snprintf(out, out_size, MSG_ARG_INVALID, "ipv4 or ipv6");
1390 if (strcmp(tokens[5], "offset") != 0) {
1391 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1395 if (softnic_parser_read_uint32(&p.common.ip_offset,
1397 snprintf(out, out_size, MSG_ARG_INVALID, "ip_offset");
1401 if (strcmp(tokens[7], "fwd") != 0) {
1402 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fwd");
1406 p.action_mask |= 1LLU << RTE_TABLE_ACTION_FWD;
1409 if (t0 < n_tokens &&
1410 (strcmp(tokens[t0], "balance") == 0)) {
1411 if (n_tokens < t0 + 7) {
1412 snprintf(out, out_size, MSG_ARG_MISMATCH, "table action profile balance");
1416 if (strcmp(tokens[t0 + 1], "offset") != 0) {
1417 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1421 if (softnic_parser_read_uint32(&p.lb.key_offset,
1422 tokens[t0 + 2]) != 0) {
1423 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1427 if (strcmp(tokens[t0 + 3], "mask") != 0) {
1428 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
1432 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
1433 if (softnic_parse_hex_string(tokens[t0 + 4],
1434 p.lb.key_mask, &p.lb.key_size) != 0) {
1435 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1439 if (strcmp(tokens[t0 + 5], "outoffset") != 0) {
1440 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "outoffset");
1444 if (softnic_parser_read_uint32(&p.lb.out_offset,
1445 tokens[t0 + 6]) != 0) {
1446 snprintf(out, out_size, MSG_ARG_INVALID, "out_offset");
1450 p.action_mask |= 1LLU << RTE_TABLE_ACTION_LB;
1454 if (t0 < n_tokens &&
1455 (strcmp(tokens[t0], "meter") == 0)) {
1456 if (n_tokens < t0 + 6) {
1457 snprintf(out, out_size, MSG_ARG_MISMATCH,
1458 "table action profile meter");
1462 if (strcmp(tokens[t0 + 1], "srtcm") == 0) {
1463 p.mtr.alg = RTE_TABLE_ACTION_METER_SRTCM;
1464 } else if (strcmp(tokens[t0 + 1], "trtcm") == 0) {
1465 p.mtr.alg = RTE_TABLE_ACTION_METER_TRTCM;
1467 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1472 if (strcmp(tokens[t0 + 2], "tc") != 0) {
1473 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc");
1477 if (softnic_parser_read_uint32(&p.mtr.n_tc,
1478 tokens[t0 + 3]) != 0) {
1479 snprintf(out, out_size, MSG_ARG_INVALID, "n_tc");
1483 if (strcmp(tokens[t0 + 4], "stats") != 0) {
1484 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1488 if (strcmp(tokens[t0 + 5], "none") == 0) {
1489 p.mtr.n_packets_enabled = 0;
1490 p.mtr.n_bytes_enabled = 0;
1491 } else if (strcmp(tokens[t0 + 5], "pkts") == 0) {
1492 p.mtr.n_packets_enabled = 1;
1493 p.mtr.n_bytes_enabled = 0;
1494 } else if (strcmp(tokens[t0 + 5], "bytes") == 0) {
1495 p.mtr.n_packets_enabled = 0;
1496 p.mtr.n_bytes_enabled = 1;
1497 } else if (strcmp(tokens[t0 + 5], "both") == 0) {
1498 p.mtr.n_packets_enabled = 1;
1499 p.mtr.n_bytes_enabled = 1;
1501 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1502 "none or pkts or bytes or both");
1506 p.action_mask |= 1LLU << RTE_TABLE_ACTION_MTR;
1510 if (t0 < n_tokens &&
1511 (strcmp(tokens[t0], "tm") == 0)) {
1512 if (n_tokens < t0 + 5) {
1513 snprintf(out, out_size, MSG_ARG_MISMATCH,
1514 "table action profile tm");
1518 if (strcmp(tokens[t0 + 1], "spp") != 0) {
1519 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
1523 if (softnic_parser_read_uint32(&p.tm.n_subports_per_port,
1524 tokens[t0 + 2]) != 0) {
1525 snprintf(out, out_size, MSG_ARG_INVALID,
1526 "n_subports_per_port");
1530 if (strcmp(tokens[t0 + 3], "pps") != 0) {
1531 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
1535 if (softnic_parser_read_uint32(&p.tm.n_pipes_per_subport,
1536 tokens[t0 + 4]) != 0) {
1537 snprintf(out, out_size, MSG_ARG_INVALID,
1538 "n_pipes_per_subport");
1542 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TM;
1546 if (t0 < n_tokens &&
1547 (strcmp(tokens[t0], "encap") == 0)) {
1548 uint32_t n_extra_tokens = 0;
1550 if (n_tokens < t0 + 2) {
1551 snprintf(out, out_size, MSG_ARG_MISMATCH,
1552 "action profile encap");
1556 if (strcmp(tokens[t0 + 1], "ether") == 0) {
1557 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_ETHER;
1558 } else if (strcmp(tokens[t0 + 1], "vlan") == 0) {
1559 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VLAN;
1560 } else if (strcmp(tokens[t0 + 1], "qinq") == 0) {
1561 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ;
1562 } else if (strcmp(tokens[t0 + 1], "mpls") == 0) {
1563 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_MPLS;
1564 } else if (strcmp(tokens[t0 + 1], "pppoe") == 0) {
1565 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_PPPOE;
1566 } else if (strcmp(tokens[t0 + 1], "vxlan") == 0) {
1567 if (n_tokens < t0 + 2 + 5) {
1568 snprintf(out, out_size, MSG_ARG_MISMATCH,
1569 "action profile encap vxlan");
1573 if (strcmp(tokens[t0 + 2], "offset") != 0) {
1574 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1579 if (softnic_parser_read_uint32(&p.encap.vxlan.data_offset,
1580 tokens[t0 + 2 + 1]) != 0) {
1581 snprintf(out, out_size, MSG_ARG_INVALID,
1582 "vxlan: ether_offset");
1586 if (strcmp(tokens[t0 + 2 + 2], "ipv4") == 0)
1587 p.encap.vxlan.ip_version = 1;
1588 else if (strcmp(tokens[t0 + 2 + 2], "ipv6") == 0)
1589 p.encap.vxlan.ip_version = 0;
1591 snprintf(out, out_size, MSG_ARG_INVALID,
1592 "vxlan: ipv4 or ipv6");
1596 if (strcmp(tokens[t0 + 2 + 3], "vlan") != 0) {
1597 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1602 if (strcmp(tokens[t0 + 2 + 4], "on") == 0)
1603 p.encap.vxlan.vlan = 1;
1604 else if (strcmp(tokens[t0 + 2 + 4], "off") == 0)
1605 p.encap.vxlan.vlan = 0;
1607 snprintf(out, out_size, MSG_ARG_INVALID,
1608 "vxlan: on or off");
1612 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VXLAN;
1616 snprintf(out, out_size, MSG_ARG_MISMATCH, "encap");
1619 p.action_mask |= 1LLU << RTE_TABLE_ACTION_ENCAP;
1620 t0 += 2 + n_extra_tokens;
1623 if (t0 < n_tokens &&
1624 (strcmp(tokens[t0], "nat") == 0)) {
1625 if (n_tokens < t0 + 4) {
1626 snprintf(out, out_size, MSG_ARG_MISMATCH,
1627 "table action profile nat");
1631 if (strcmp(tokens[t0 + 1], "src") == 0) {
1632 p.nat.source_nat = 1;
1633 } else if (strcmp(tokens[t0 + 1], "dst") == 0) {
1634 p.nat.source_nat = 0;
1636 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1641 if (strcmp(tokens[t0 + 2], "proto") != 0) {
1642 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "proto");
1646 if (strcmp(tokens[t0 + 3], "tcp") == 0) {
1648 } else if (strcmp(tokens[t0 + 3], "udp") == 0) {
1651 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1656 p.action_mask |= 1LLU << RTE_TABLE_ACTION_NAT;
1660 if (t0 < n_tokens &&
1661 (strcmp(tokens[t0], "ttl") == 0)) {
1662 if (n_tokens < t0 + 4) {
1663 snprintf(out, out_size, MSG_ARG_MISMATCH,
1664 "table action profile ttl");
1668 if (strcmp(tokens[t0 + 1], "drop") == 0) {
1670 } else if (strcmp(tokens[t0 + 1], "fwd") == 0) {
1673 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1678 if (strcmp(tokens[t0 + 2], "stats") != 0) {
1679 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1683 if (strcmp(tokens[t0 + 3], "none") == 0) {
1684 p.ttl.n_packets_enabled = 0;
1685 } else if (strcmp(tokens[t0 + 3], "pkts") == 0) {
1686 p.ttl.n_packets_enabled = 1;
1688 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1693 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TTL;
1697 if (t0 < n_tokens &&
1698 (strcmp(tokens[t0], "stats") == 0)) {
1699 if (n_tokens < t0 + 2) {
1700 snprintf(out, out_size, MSG_ARG_MISMATCH,
1701 "table action profile stats");
1705 if (strcmp(tokens[t0 + 1], "pkts") == 0) {
1706 p.stats.n_packets_enabled = 1;
1707 p.stats.n_bytes_enabled = 0;
1708 } else if (strcmp(tokens[t0 + 1], "bytes") == 0) {
1709 p.stats.n_packets_enabled = 0;
1710 p.stats.n_bytes_enabled = 1;
1711 } else if (strcmp(tokens[t0 + 1], "both") == 0) {
1712 p.stats.n_packets_enabled = 1;
1713 p.stats.n_bytes_enabled = 1;
1715 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1716 "pkts or bytes or both");
1720 p.action_mask |= 1LLU << RTE_TABLE_ACTION_STATS;
1724 if (t0 < n_tokens &&
1725 (strcmp(tokens[t0], "time") == 0)) {
1726 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TIME;
1730 if (t0 < n_tokens &&
1731 (strcmp(tokens[t0], "tag") == 0)) {
1732 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TAG;
1736 if (t0 < n_tokens &&
1737 (strcmp(tokens[t0], "decap") == 0)) {
1738 p.action_mask |= 1LLU << RTE_TABLE_ACTION_DECAP;
1742 if (t0 < n_tokens) {
1743 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1747 ap = softnic_table_action_profile_create(softnic, name, &p);
1749 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1755 * pipeline <pipeline_name>
1756 * period <timer_period_ms>
1757 * offset_port_id <offset_port_id>
1760 cmd_pipeline(struct pmd_internals *softnic,
1766 struct pipeline_params p;
1768 struct pipeline *pipeline;
1770 if (n_tokens != 6) {
1771 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1777 if (strcmp(tokens[2], "period") != 0) {
1778 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "period");
1782 if (softnic_parser_read_uint32(&p.timer_period_ms,
1784 snprintf(out, out_size, MSG_ARG_INVALID, "timer_period_ms");
1788 if (strcmp(tokens[4], "offset_port_id") != 0) {
1789 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset_port_id");
1793 if (softnic_parser_read_uint32(&p.offset_port_id,
1795 snprintf(out, out_size, MSG_ARG_INVALID, "offset_port_id");
1799 pipeline = softnic_pipeline_create(softnic, name, &p);
1800 if (pipeline == NULL) {
1801 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1807 * pipeline <pipeline_name> port in
1809 * link <link_name> rxq <queue_id>
1811 * | tmgr <tmgr_name>
1812 * | tap <tap_name> mempool <mempool_name> mtu <mtu>
1813 * | source mempool <mempool_name> file <file_name> bpp <n_bytes_per_pkt>
1814 * | cryptodev <cryptodev_name> rxq <queue_id>
1815 * [action <port_in_action_profile_name>]
1819 cmd_pipeline_port_in(struct pmd_internals *softnic,
1825 struct softnic_port_in_params p;
1826 char *pipeline_name;
1828 int enabled, status;
1830 memset(&p, 0, sizeof(p));
1833 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1837 pipeline_name = tokens[1];
1839 if (strcmp(tokens[2], "port") != 0) {
1840 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1844 if (strcmp(tokens[3], "in") != 0) {
1845 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1849 if (strcmp(tokens[4], "bsz") != 0) {
1850 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1854 if (softnic_parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1855 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1861 if (strcmp(tokens[t0], "link") == 0) {
1862 if (n_tokens < t0 + 4) {
1863 snprintf(out, out_size, MSG_ARG_MISMATCH,
1864 "pipeline port in link");
1868 p.type = PORT_IN_RXQ;
1870 strlcpy(p.dev_name, tokens[t0 + 1], sizeof(p.dev_name));
1872 if (strcmp(tokens[t0 + 2], "rxq") != 0) {
1873 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
1877 if (softnic_parser_read_uint16(&p.rxq.queue_id,
1878 tokens[t0 + 3]) != 0) {
1879 snprintf(out, out_size, MSG_ARG_INVALID,
1884 } else if (strcmp(tokens[t0], "swq") == 0) {
1885 if (n_tokens < t0 + 2) {
1886 snprintf(out, out_size, MSG_ARG_MISMATCH,
1887 "pipeline port in swq");
1891 p.type = PORT_IN_SWQ;
1893 strlcpy(p.dev_name, tokens[t0 + 1], sizeof(p.dev_name));
1896 } else if (strcmp(tokens[t0], "tmgr") == 0) {
1897 if (n_tokens < t0 + 2) {
1898 snprintf(out, out_size, MSG_ARG_MISMATCH,
1899 "pipeline port in tmgr");
1903 p.type = PORT_IN_TMGR;
1905 strlcpy(p.dev_name, tokens[t0 + 1], sizeof(p.dev_name));
1908 } else if (strcmp(tokens[t0], "tap") == 0) {
1909 if (n_tokens < t0 + 6) {
1910 snprintf(out, out_size, MSG_ARG_MISMATCH,
1911 "pipeline port in tap");
1915 p.type = PORT_IN_TAP;
1917 strlcpy(p.dev_name, tokens[t0 + 1], sizeof(p.dev_name));
1919 if (strcmp(tokens[t0 + 2], "mempool") != 0) {
1920 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1925 p.tap.mempool_name = tokens[t0 + 3];
1927 if (strcmp(tokens[t0 + 4], "mtu") != 0) {
1928 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1933 if (softnic_parser_read_uint32(&p.tap.mtu,
1934 tokens[t0 + 5]) != 0) {
1935 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
1940 } else if (strcmp(tokens[t0], "source") == 0) {
1941 if (n_tokens < t0 + 6) {
1942 snprintf(out, out_size, MSG_ARG_MISMATCH,
1943 "pipeline port in source");
1947 p.type = PORT_IN_SOURCE;
1949 if (strcmp(tokens[t0 + 1], "mempool") != 0) {
1950 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1955 p.source.mempool_name = tokens[t0 + 2];
1957 if (strcmp(tokens[t0 + 3], "file") != 0) {
1958 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1963 p.source.file_name = tokens[t0 + 4];
1965 if (strcmp(tokens[t0 + 5], "bpp") != 0) {
1966 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1971 if (softnic_parser_read_uint32(&p.source.n_bytes_per_pkt,
1972 tokens[t0 + 6]) != 0) {
1973 snprintf(out, out_size, MSG_ARG_INVALID,
1979 } else if (strcmp(tokens[t0], "cryptodev") == 0) {
1980 if (n_tokens < t0 + 3) {
1981 snprintf(out, out_size, MSG_ARG_MISMATCH,
1982 "pipeline port in cryptodev");
1986 p.type = PORT_IN_CRYPTODEV;
1988 strlcpy(p.dev_name, tokens[t0 + 1], sizeof(p.dev_name));
1989 if (softnic_parser_read_uint16(&p.rxq.queue_id,
1990 tokens[t0 + 3]) != 0) {
1991 snprintf(out, out_size, MSG_ARG_INVALID,
1996 p.cryptodev.arg_callback = NULL;
1997 p.cryptodev.f_callback = NULL;
2001 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
2005 if (n_tokens > t0 &&
2006 (strcmp(tokens[t0], "action") == 0)) {
2007 if (n_tokens < t0 + 2) {
2008 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
2012 strlcpy(p.action_profile_name, tokens[t0 + 1],
2013 sizeof(p.action_profile_name));
2019 if (n_tokens > t0 &&
2020 (strcmp(tokens[t0], "disabled") == 0)) {
2026 if (n_tokens != t0) {
2027 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2031 status = softnic_pipeline_port_in_create(softnic,
2036 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2042 * pipeline <pipeline_name> port out
2044 * link <link_name> txq <txq_id>
2046 * | tmgr <tmgr_name>
2048 * | sink [file <file_name> pkts <max_n_pkts>]
2049 * | cryptodev <cryptodev_name> txq <txq_id> offset <crypto_op_offset>
2052 cmd_pipeline_port_out(struct pmd_internals *softnic,
2058 struct softnic_port_out_params p;
2059 char *pipeline_name;
2062 memset(&p, 0, sizeof(p));
2065 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2069 pipeline_name = tokens[1];
2071 if (strcmp(tokens[2], "port") != 0) {
2072 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2076 if (strcmp(tokens[3], "out") != 0) {
2077 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
2081 if (strcmp(tokens[4], "bsz") != 0) {
2082 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
2086 if (softnic_parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
2087 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
2091 if (strcmp(tokens[6], "link") == 0) {
2092 if (n_tokens != 10) {
2093 snprintf(out, out_size, MSG_ARG_MISMATCH,
2094 "pipeline port out link");
2098 p.type = PORT_OUT_TXQ;
2100 strlcpy(p.dev_name, tokens[7], sizeof(p.dev_name));
2102 if (strcmp(tokens[8], "txq") != 0) {
2103 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
2107 if (softnic_parser_read_uint16(&p.txq.queue_id,
2109 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
2112 } else if (strcmp(tokens[6], "swq") == 0) {
2113 if (n_tokens != 8) {
2114 snprintf(out, out_size, MSG_ARG_MISMATCH,
2115 "pipeline port out swq");
2119 p.type = PORT_OUT_SWQ;
2121 strlcpy(p.dev_name, tokens[7], sizeof(p.dev_name));
2122 } else if (strcmp(tokens[6], "tmgr") == 0) {
2123 if (n_tokens != 8) {
2124 snprintf(out, out_size, MSG_ARG_MISMATCH,
2125 "pipeline port out tmgr");
2129 p.type = PORT_OUT_TMGR;
2131 strlcpy(p.dev_name, tokens[7], sizeof(p.dev_name));
2132 } else if (strcmp(tokens[6], "tap") == 0) {
2133 if (n_tokens != 8) {
2134 snprintf(out, out_size, MSG_ARG_MISMATCH,
2135 "pipeline port out tap");
2139 p.type = PORT_OUT_TAP;
2141 strlcpy(p.dev_name, tokens[7], sizeof(p.dev_name));
2142 } else if (strcmp(tokens[6], "sink") == 0) {
2143 if ((n_tokens != 7) && (n_tokens != 11)) {
2144 snprintf(out, out_size, MSG_ARG_MISMATCH,
2145 "pipeline port out sink");
2149 p.type = PORT_OUT_SINK;
2151 if (n_tokens == 7) {
2152 p.sink.file_name = NULL;
2153 p.sink.max_n_pkts = 0;
2155 if (strcmp(tokens[7], "file") != 0) {
2156 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2161 p.sink.file_name = tokens[8];
2163 if (strcmp(tokens[9], "pkts") != 0) {
2164 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pkts");
2168 if (softnic_parser_read_uint32(&p.sink.max_n_pkts,
2170 snprintf(out, out_size, MSG_ARG_INVALID, "max_n_pkts");
2174 } else if (strcmp(tokens[6], "cryptodev") == 0) {
2175 if (n_tokens != 12) {
2176 snprintf(out, out_size, MSG_ARG_MISMATCH,
2177 "pipeline port out cryptodev");
2181 p.type = PORT_OUT_CRYPTODEV;
2183 strlcpy(p.dev_name, tokens[7], sizeof(p.dev_name));
2185 if (strcmp(tokens[8], "txq")) {
2186 snprintf(out, out_size, MSG_ARG_MISMATCH,
2187 "pipeline port out cryptodev");
2191 if (softnic_parser_read_uint16(&p.cryptodev.queue_id, tokens[9])
2193 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
2197 if (strcmp(tokens[10], "offset")) {
2198 snprintf(out, out_size, MSG_ARG_MISMATCH,
2199 "pipeline port out cryptodev");
2203 if (softnic_parser_read_uint32(&p.cryptodev.op_offset,
2205 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
2209 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
2213 status = softnic_pipeline_port_out_create(softnic, pipeline_name, &p);
2215 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2221 * pipeline <pipeline_name> table
2225 * offset <ip_header_offset>
2228 * offset <key_offset>
2234 * offset <key_offset>
2235 * buckets <n_buckets>
2239 * offset <ip_header_offset>
2242 * [action <table_action_profile_name>]
2245 cmd_pipeline_table(struct pmd_internals *softnic,
2251 struct softnic_table_params p;
2252 char *pipeline_name;
2256 memset(&p, 0, sizeof(p));
2259 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2263 pipeline_name = tokens[1];
2265 if (strcmp(tokens[2], "table") != 0) {
2266 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2270 if (strcmp(tokens[3], "match") != 0) {
2271 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
2276 if (strcmp(tokens[t0], "acl") == 0) {
2277 if (n_tokens < t0 + 6) {
2278 snprintf(out, out_size, MSG_ARG_MISMATCH,
2279 "pipeline table acl");
2283 p.match_type = TABLE_ACL;
2285 if (strcmp(tokens[t0 + 1], "ipv4") == 0) {
2286 p.match.acl.ip_version = 1;
2287 } else if (strcmp(tokens[t0 + 1], "ipv6") == 0) {
2288 p.match.acl.ip_version = 0;
2290 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2295 if (strcmp(tokens[t0 + 2], "offset") != 0) {
2296 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2300 if (softnic_parser_read_uint32(&p.match.acl.ip_header_offset,
2301 tokens[t0 + 3]) != 0) {
2302 snprintf(out, out_size, MSG_ARG_INVALID,
2303 "ip_header_offset");
2307 if (strcmp(tokens[t0 + 4], "size") != 0) {
2308 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2312 if (softnic_parser_read_uint32(&p.match.acl.n_rules,
2313 tokens[t0 + 5]) != 0) {
2314 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2319 } else if (strcmp(tokens[t0], "array") == 0) {
2320 if (n_tokens < t0 + 5) {
2321 snprintf(out, out_size, MSG_ARG_MISMATCH,
2322 "pipeline table array");
2326 p.match_type = TABLE_ARRAY;
2328 if (strcmp(tokens[t0 + 1], "offset") != 0) {
2329 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2333 if (softnic_parser_read_uint32(&p.match.array.key_offset,
2334 tokens[t0 + 2]) != 0) {
2335 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2339 if (strcmp(tokens[t0 + 3], "size") != 0) {
2340 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2344 if (softnic_parser_read_uint32(&p.match.array.n_keys,
2345 tokens[t0 + 4]) != 0) {
2346 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2351 } else if (strcmp(tokens[t0], "hash") == 0) {
2352 uint32_t key_mask_size = TABLE_RULE_MATCH_SIZE_MAX;
2354 if (n_tokens < t0 + 12) {
2355 snprintf(out, out_size, MSG_ARG_MISMATCH,
2356 "pipeline table hash");
2360 p.match_type = TABLE_HASH;
2362 if (strcmp(tokens[t0 + 1], "ext") == 0) {
2363 p.match.hash.extendable_bucket = 1;
2364 } else if (strcmp(tokens[t0 + 1], "lru") == 0) {
2365 p.match.hash.extendable_bucket = 0;
2367 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2372 if (strcmp(tokens[t0 + 2], "key") != 0) {
2373 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
2377 if ((softnic_parser_read_uint32(&p.match.hash.key_size,
2378 tokens[t0 + 3]) != 0) ||
2379 p.match.hash.key_size == 0 ||
2380 p.match.hash.key_size > TABLE_RULE_MATCH_SIZE_MAX) {
2381 snprintf(out, out_size, MSG_ARG_INVALID, "key_size");
2385 if (strcmp(tokens[t0 + 4], "mask") != 0) {
2386 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
2390 if ((softnic_parse_hex_string(tokens[t0 + 5],
2391 p.match.hash.key_mask, &key_mask_size) != 0) ||
2392 key_mask_size != p.match.hash.key_size) {
2393 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
2397 if (strcmp(tokens[t0 + 6], "offset") != 0) {
2398 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2402 if (softnic_parser_read_uint32(&p.match.hash.key_offset,
2403 tokens[t0 + 7]) != 0) {
2404 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2408 if (strcmp(tokens[t0 + 8], "buckets") != 0) {
2409 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buckets");
2413 if (softnic_parser_read_uint32(&p.match.hash.n_buckets,
2414 tokens[t0 + 9]) != 0) {
2415 snprintf(out, out_size, MSG_ARG_INVALID, "n_buckets");
2419 if (strcmp(tokens[t0 + 10], "size") != 0) {
2420 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2424 if (softnic_parser_read_uint32(&p.match.hash.n_keys,
2425 tokens[t0 + 11]) != 0) {
2426 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2431 } else if (strcmp(tokens[t0], "lpm") == 0) {
2432 if (n_tokens < t0 + 6) {
2433 snprintf(out, out_size, MSG_ARG_MISMATCH,
2434 "pipeline table lpm");
2438 p.match_type = TABLE_LPM;
2440 if (strcmp(tokens[t0 + 1], "ipv4") == 0) {
2441 p.match.lpm.key_size = 4;
2442 } else if (strcmp(tokens[t0 + 1], "ipv6") == 0) {
2443 p.match.lpm.key_size = 16;
2445 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2450 if (strcmp(tokens[t0 + 2], "offset") != 0) {
2451 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2455 if (softnic_parser_read_uint32(&p.match.lpm.key_offset,
2456 tokens[t0 + 3]) != 0) {
2457 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2461 if (strcmp(tokens[t0 + 4], "size") != 0) {
2462 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2466 if (softnic_parser_read_uint32(&p.match.lpm.n_rules,
2467 tokens[t0 + 5]) != 0) {
2468 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2473 } else if (strcmp(tokens[t0], "stub") == 0) {
2474 p.match_type = TABLE_STUB;
2478 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
2482 if (n_tokens > t0 &&
2483 (strcmp(tokens[t0], "action") == 0)) {
2484 if (n_tokens < t0 + 2) {
2485 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
2489 strlcpy(p.action_profile_name, tokens[t0 + 1],
2490 sizeof(p.action_profile_name));
2495 if (n_tokens > t0) {
2496 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2500 status = softnic_pipeline_table_create(softnic, pipeline_name, &p);
2502 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2508 * pipeline <pipeline_name> port in <port_id> table <table_id>
2511 cmd_pipeline_port_in_table(struct pmd_internals *softnic,
2517 char *pipeline_name;
2518 uint32_t port_id, table_id;
2521 if (n_tokens != 7) {
2522 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2526 pipeline_name = tokens[1];
2528 if (strcmp(tokens[2], "port") != 0) {
2529 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2533 if (strcmp(tokens[3], "in") != 0) {
2534 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2538 if (softnic_parser_read_uint32(&port_id, tokens[4]) != 0) {
2539 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2543 if (strcmp(tokens[5], "table") != 0) {
2544 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2548 if (softnic_parser_read_uint32(&table_id, tokens[6]) != 0) {
2549 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2553 status = softnic_pipeline_port_in_connect_to_table(softnic,
2558 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2564 * pipeline <pipeline_name> port in <port_id> stats read [clear]
2567 #define MSG_PIPELINE_PORT_IN_STATS \
2568 "Pkts in: %" PRIu64 "\n" \
2569 "Pkts dropped by AH: %" PRIu64 "\n" \
2570 "Pkts dropped by other: %" PRIu64 "\n"
2573 cmd_pipeline_port_in_stats(struct pmd_internals *softnic,
2579 struct rte_pipeline_port_in_stats stats;
2580 char *pipeline_name;
2584 if (n_tokens != 7 &&
2586 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2590 pipeline_name = tokens[1];
2592 if (strcmp(tokens[2], "port") != 0) {
2593 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2597 if (strcmp(tokens[3], "in") != 0) {
2598 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2602 if (softnic_parser_read_uint32(&port_id, tokens[4]) != 0) {
2603 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2607 if (strcmp(tokens[5], "stats") != 0) {
2608 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2612 if (strcmp(tokens[6], "read") != 0) {
2613 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2618 if (n_tokens == 8) {
2619 if (strcmp(tokens[7], "clear") != 0) {
2620 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2627 status = softnic_pipeline_port_in_stats_read(softnic,
2633 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2637 snprintf(out, out_size, MSG_PIPELINE_PORT_IN_STATS,
2638 stats.stats.n_pkts_in,
2639 stats.n_pkts_dropped_by_ah,
2640 stats.stats.n_pkts_drop);
2644 * pipeline <pipeline_name> port in <port_id> enable
2647 cmd_softnic_pipeline_port_in_enable(struct pmd_internals *softnic,
2653 char *pipeline_name;
2657 if (n_tokens != 6) {
2658 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2662 pipeline_name = tokens[1];
2664 if (strcmp(tokens[2], "port") != 0) {
2665 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2669 if (strcmp(tokens[3], "in") != 0) {
2670 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2674 if (softnic_parser_read_uint32(&port_id, tokens[4]) != 0) {
2675 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2679 if (strcmp(tokens[5], "enable") != 0) {
2680 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
2684 status = softnic_pipeline_port_in_enable(softnic, pipeline_name, port_id);
2686 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2692 * pipeline <pipeline_name> port in <port_id> disable
2695 cmd_softnic_pipeline_port_in_disable(struct pmd_internals *softnic,
2701 char *pipeline_name;
2705 if (n_tokens != 6) {
2706 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2710 pipeline_name = tokens[1];
2712 if (strcmp(tokens[2], "port") != 0) {
2713 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2717 if (strcmp(tokens[3], "in") != 0) {
2718 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2722 if (softnic_parser_read_uint32(&port_id, tokens[4]) != 0) {
2723 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2727 if (strcmp(tokens[5], "disable") != 0) {
2728 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
2732 status = softnic_pipeline_port_in_disable(softnic, pipeline_name, port_id);
2734 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2740 * pipeline <pipeline_name> port out <port_id> stats read [clear]
2742 #define MSG_PIPELINE_PORT_OUT_STATS \
2743 "Pkts in: %" PRIu64 "\n" \
2744 "Pkts dropped by AH: %" PRIu64 "\n" \
2745 "Pkts dropped by other: %" PRIu64 "\n"
2748 cmd_pipeline_port_out_stats(struct pmd_internals *softnic,
2754 struct rte_pipeline_port_out_stats stats;
2755 char *pipeline_name;
2759 if (n_tokens != 7 &&
2761 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2765 pipeline_name = tokens[1];
2767 if (strcmp(tokens[2], "port") != 0) {
2768 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2772 if (strcmp(tokens[3], "out") != 0) {
2773 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
2777 if (softnic_parser_read_uint32(&port_id, tokens[4]) != 0) {
2778 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2782 if (strcmp(tokens[5], "stats") != 0) {
2783 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2787 if (strcmp(tokens[6], "read") != 0) {
2788 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2793 if (n_tokens == 8) {
2794 if (strcmp(tokens[7], "clear") != 0) {
2795 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2802 status = softnic_pipeline_port_out_stats_read(softnic,
2808 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2812 snprintf(out, out_size, MSG_PIPELINE_PORT_OUT_STATS,
2813 stats.stats.n_pkts_in,
2814 stats.n_pkts_dropped_by_ah,
2815 stats.stats.n_pkts_drop);
2819 * pipeline <pipeline_name> table <table_id> stats read [clear]
2821 #define MSG_PIPELINE_TABLE_STATS \
2822 "Pkts in: %" PRIu64 "\n" \
2823 "Pkts in with lookup miss: %" PRIu64 "\n" \
2824 "Pkts in with lookup hit dropped by AH: %" PRIu64 "\n" \
2825 "Pkts in with lookup hit dropped by others: %" PRIu64 "\n" \
2826 "Pkts in with lookup miss dropped by AH: %" PRIu64 "\n" \
2827 "Pkts in with lookup miss dropped by others: %" PRIu64 "\n"
2830 cmd_pipeline_table_stats(struct pmd_internals *softnic,
2836 struct rte_pipeline_table_stats stats;
2837 char *pipeline_name;
2841 if (n_tokens != 6 &&
2843 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2847 pipeline_name = tokens[1];
2849 if (strcmp(tokens[2], "table") != 0) {
2850 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2854 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
2855 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2859 if (strcmp(tokens[4], "stats") != 0) {
2860 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2864 if (strcmp(tokens[5], "read") != 0) {
2865 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2870 if (n_tokens == 7) {
2871 if (strcmp(tokens[6], "clear") != 0) {
2872 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2879 status = softnic_pipeline_table_stats_read(softnic,
2885 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2889 snprintf(out, out_size, MSG_PIPELINE_TABLE_STATS,
2890 stats.stats.n_pkts_in,
2891 stats.stats.n_pkts_lookup_miss,
2892 stats.n_pkts_dropped_by_lkp_hit_ah,
2893 stats.n_pkts_dropped_lkp_hit,
2894 stats.n_pkts_dropped_by_lkp_miss_ah,
2895 stats.n_pkts_dropped_lkp_miss);
2903 * priority <priority>
2904 * ipv4 | ipv6 <sa> <sa_depth> <da> <da_depth>
2905 * <sp0> <sp1> <dp0> <dp1> <proto>
2909 * | ipv4_5tuple <sa> <da> <sp> <dp> <proto>
2910 * | ipv6_5tuple <sa> <da> <sp> <dp> <proto>
2911 * | ipv4_addr <addr>
2912 * | ipv6_addr <addr>
2913 * | qinq <svlan> <cvlan>
2915 * ipv4 | ipv6 <addr> <depth>
2917 struct pkt_key_qinq {
2918 uint16_t ethertype_svlan;
2920 uint16_t ethertype_cvlan;
2922 } __attribute__((__packed__));
2924 struct pkt_key_ipv4_5tuple {
2925 uint8_t time_to_live;
2927 uint16_t hdr_checksum;
2932 } __attribute__((__packed__));
2934 struct pkt_key_ipv6_5tuple {
2935 uint16_t payload_length;
2942 } __attribute__((__packed__));
2944 struct pkt_key_ipv4_addr {
2946 } __attribute__((__packed__));
2948 struct pkt_key_ipv6_addr {
2950 } __attribute__((__packed__));
2953 parse_match(char **tokens,
2957 struct softnic_table_rule_match *m)
2959 memset(m, 0, sizeof(*m));
2964 if (strcmp(tokens[0], "match") != 0) {
2965 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
2969 if (strcmp(tokens[1], "acl") == 0) {
2970 if (n_tokens < 14) {
2971 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2975 m->match_type = TABLE_ACL;
2977 if (strcmp(tokens[2], "priority") != 0) {
2978 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "priority");
2982 if (softnic_parser_read_uint32(&m->match.acl.priority,
2984 snprintf(out, out_size, MSG_ARG_INVALID, "priority");
2988 if (strcmp(tokens[4], "ipv4") == 0) {
2989 struct in_addr saddr, daddr;
2991 m->match.acl.ip_version = 1;
2993 if (softnic_parse_ipv4_addr(tokens[5], &saddr) != 0) {
2994 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2997 m->match.acl.ipv4.sa = rte_be_to_cpu_32(saddr.s_addr);
2999 if (softnic_parse_ipv4_addr(tokens[7], &daddr) != 0) {
3000 snprintf(out, out_size, MSG_ARG_INVALID, "da");
3003 m->match.acl.ipv4.da = rte_be_to_cpu_32(daddr.s_addr);
3004 } else if (strcmp(tokens[4], "ipv6") == 0) {
3005 struct in6_addr saddr, daddr;
3007 m->match.acl.ip_version = 0;
3009 if (softnic_parse_ipv6_addr(tokens[5], &saddr) != 0) {
3010 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
3013 memcpy(m->match.acl.ipv6.sa, saddr.s6_addr, 16);
3015 if (softnic_parse_ipv6_addr(tokens[7], &daddr) != 0) {
3016 snprintf(out, out_size, MSG_ARG_INVALID, "da");
3019 memcpy(m->match.acl.ipv6.da, daddr.s6_addr, 16);
3021 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
3026 if (softnic_parser_read_uint32(&m->match.acl.sa_depth,
3028 snprintf(out, out_size, MSG_ARG_INVALID, "sa_depth");
3032 if (softnic_parser_read_uint32(&m->match.acl.da_depth,
3034 snprintf(out, out_size, MSG_ARG_INVALID, "da_depth");
3038 if (softnic_parser_read_uint16(&m->match.acl.sp0, tokens[9]) != 0) {
3039 snprintf(out, out_size, MSG_ARG_INVALID, "sp0");
3043 if (softnic_parser_read_uint16(&m->match.acl.sp1, tokens[10]) != 0) {
3044 snprintf(out, out_size, MSG_ARG_INVALID, "sp1");
3048 if (softnic_parser_read_uint16(&m->match.acl.dp0, tokens[11]) != 0) {
3049 snprintf(out, out_size, MSG_ARG_INVALID, "dp0");
3053 if (softnic_parser_read_uint16(&m->match.acl.dp1, tokens[12]) != 0) {
3054 snprintf(out, out_size, MSG_ARG_INVALID, "dp1");
3058 if (softnic_parser_read_uint8(&m->match.acl.proto, tokens[13]) != 0) {
3059 snprintf(out, out_size, MSG_ARG_INVALID, "proto");
3063 m->match.acl.proto_mask = 0xff;
3068 if (strcmp(tokens[1], "array") == 0) {
3070 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3074 m->match_type = TABLE_ARRAY;
3076 if (softnic_parser_read_uint32(&m->match.array.pos, tokens[2]) != 0) {
3077 snprintf(out, out_size, MSG_ARG_INVALID, "pos");
3084 if (strcmp(tokens[1], "hash") == 0) {
3086 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3090 m->match_type = TABLE_HASH;
3092 if (strcmp(tokens[2], "raw") == 0) {
3093 uint32_t key_size = TABLE_RULE_MATCH_SIZE_MAX;
3096 snprintf(out, out_size, MSG_ARG_MISMATCH,
3101 if (softnic_parse_hex_string(tokens[3],
3102 m->match.hash.key, &key_size) != 0) {
3103 snprintf(out, out_size, MSG_ARG_INVALID, "key");
3110 if (strcmp(tokens[2], "ipv4_5tuple") == 0) {
3111 struct pkt_key_ipv4_5tuple *ipv4 =
3112 (struct pkt_key_ipv4_5tuple *)m->match.hash.key;
3113 struct in_addr saddr, daddr;
3118 snprintf(out, out_size, MSG_ARG_MISMATCH,
3123 if (softnic_parse_ipv4_addr(tokens[3], &saddr) != 0) {
3124 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
3128 if (softnic_parse_ipv4_addr(tokens[4], &daddr) != 0) {
3129 snprintf(out, out_size, MSG_ARG_INVALID, "da");
3133 if (softnic_parser_read_uint16(&sp, tokens[5]) != 0) {
3134 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
3138 if (softnic_parser_read_uint16(&dp, tokens[6]) != 0) {
3139 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
3143 if (softnic_parser_read_uint8(&proto, tokens[7]) != 0) {
3144 snprintf(out, out_size, MSG_ARG_INVALID,
3149 ipv4->sa = saddr.s_addr;
3150 ipv4->da = daddr.s_addr;
3151 ipv4->sp = rte_cpu_to_be_16(sp);
3152 ipv4->dp = rte_cpu_to_be_16(dp);
3153 ipv4->proto = proto;
3156 } /* hash ipv4_5tuple */
3158 if (strcmp(tokens[2], "ipv6_5tuple") == 0) {
3159 struct pkt_key_ipv6_5tuple *ipv6 =
3160 (struct pkt_key_ipv6_5tuple *)m->match.hash.key;
3161 struct in6_addr saddr, daddr;
3166 snprintf(out, out_size, MSG_ARG_MISMATCH,
3171 if (softnic_parse_ipv6_addr(tokens[3], &saddr) != 0) {
3172 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
3176 if (softnic_parse_ipv6_addr(tokens[4], &daddr) != 0) {
3177 snprintf(out, out_size, MSG_ARG_INVALID, "da");
3181 if (softnic_parser_read_uint16(&sp, tokens[5]) != 0) {
3182 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
3186 if (softnic_parser_read_uint16(&dp, tokens[6]) != 0) {
3187 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
3191 if (softnic_parser_read_uint8(&proto, tokens[7]) != 0) {
3192 snprintf(out, out_size, MSG_ARG_INVALID,
3197 memcpy(ipv6->sa, saddr.s6_addr, 16);
3198 memcpy(ipv6->da, daddr.s6_addr, 16);
3199 ipv6->sp = rte_cpu_to_be_16(sp);
3200 ipv6->dp = rte_cpu_to_be_16(dp);
3201 ipv6->proto = proto;
3204 } /* hash ipv6_5tuple */
3206 if (strcmp(tokens[2], "ipv4_addr") == 0) {
3207 struct pkt_key_ipv4_addr *ipv4_addr =
3208 (struct pkt_key_ipv4_addr *)m->match.hash.key;
3209 struct in_addr addr;
3212 snprintf(out, out_size, MSG_ARG_MISMATCH,
3217 if (softnic_parse_ipv4_addr(tokens[3], &addr) != 0) {
3218 snprintf(out, out_size, MSG_ARG_INVALID,
3223 ipv4_addr->addr = addr.s_addr;
3226 } /* hash ipv4_addr */
3228 if (strcmp(tokens[2], "ipv6_addr") == 0) {
3229 struct pkt_key_ipv6_addr *ipv6_addr =
3230 (struct pkt_key_ipv6_addr *)m->match.hash.key;
3231 struct in6_addr addr;
3234 snprintf(out, out_size, MSG_ARG_MISMATCH,
3239 if (softnic_parse_ipv6_addr(tokens[3], &addr) != 0) {
3240 snprintf(out, out_size, MSG_ARG_INVALID,
3245 memcpy(ipv6_addr->addr, addr.s6_addr, 16);
3248 } /* hash ipv6_5tuple */
3250 if (strcmp(tokens[2], "qinq") == 0) {
3251 struct pkt_key_qinq *qinq =
3252 (struct pkt_key_qinq *)m->match.hash.key;
3253 uint16_t svlan, cvlan;
3256 snprintf(out, out_size, MSG_ARG_MISMATCH,
3261 if ((softnic_parser_read_uint16(&svlan, tokens[3]) != 0) ||
3263 snprintf(out, out_size, MSG_ARG_INVALID,
3268 if ((softnic_parser_read_uint16(&cvlan, tokens[4]) != 0) ||
3270 snprintf(out, out_size, MSG_ARG_INVALID,
3275 qinq->svlan = rte_cpu_to_be_16(svlan);
3276 qinq->cvlan = rte_cpu_to_be_16(cvlan);
3281 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3285 if (strcmp(tokens[1], "lpm") == 0) {
3287 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3291 m->match_type = TABLE_LPM;
3293 if (strcmp(tokens[2], "ipv4") == 0) {
3294 struct in_addr addr;
3296 m->match.lpm.ip_version = 1;
3298 if (softnic_parse_ipv4_addr(tokens[3], &addr) != 0) {
3299 snprintf(out, out_size, MSG_ARG_INVALID,
3304 m->match.lpm.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3305 } else if (strcmp(tokens[2], "ipv6") == 0) {
3306 struct in6_addr addr;
3308 m->match.lpm.ip_version = 0;
3310 if (softnic_parse_ipv6_addr(tokens[3], &addr) != 0) {
3311 snprintf(out, out_size, MSG_ARG_INVALID,
3316 memcpy(m->match.lpm.ipv6, addr.s6_addr, 16);
3318 snprintf(out, out_size, MSG_ARG_MISMATCH,
3323 if (softnic_parser_read_uint8(&m->match.lpm.depth, tokens[4]) != 0) {
3324 snprintf(out, out_size, MSG_ARG_INVALID, "depth");
3331 snprintf(out, out_size, MSG_ARG_MISMATCH,
3332 "acl or array or hash or lpm");
3344 * | table <table_id>
3345 * [balance <out0> ... <out7>]
3347 * tc0 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3348 * [tc1 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3349 * tc2 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3350 * tc3 meter <meter_profile_id> policer g <pa> y <pa> r <pa>]]
3351 * [tm subport <subport_id> pipe <pipe_id>]
3354 * | vlan <da> <sa> <pcp> <dei> <vid>
3355 * | qinq <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid>
3356 * | mpls unicast | multicast
3358 * label0 <label> <tc> <ttl>
3359 * [label1 <label> <tc> <ttl>
3360 * [label2 <label> <tc> <ttl>
3361 * [label3 <label> <tc> <ttl>]]]
3362 * | pppoe <da> <sa> <session_id>]
3363 * | vxlan ether <da> <sa>
3364 * [vlan <pcp> <dei> <vid>]
3365 * ipv4 <sa> <da> <dscp> <ttl>
3366 * | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit>
3369 * [nat ipv4 | ipv6 <addr> <port>]
3379 * cipher_algo <algo> cipher_key <key> cipher_iv <iv>
3381 * cipher_algo <algo> cipher_key <key> cipher_iv <iv>
3382 * auth_algo <algo> auth_key <key> digest_size <size>
3384 * aead_algo <algo> aead_key <key> aead_iv <iv> aead_aad <aad>
3385 * digest_size <size>
3386 * data_offset <data_offset>]
3389 * <pa> ::= g | y | r | drop
3392 parse_table_action_fwd(char **tokens,
3394 struct softnic_table_rule_action *a)
3396 if (n_tokens == 0 ||
3397 (strcmp(tokens[0], "fwd") != 0))
3403 if (n_tokens && (strcmp(tokens[0], "drop") == 0)) {
3404 a->fwd.action = RTE_PIPELINE_ACTION_DROP;
3405 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3409 if (n_tokens && (strcmp(tokens[0], "port") == 0)) {
3413 softnic_parser_read_uint32(&id, tokens[1]))
3416 a->fwd.action = RTE_PIPELINE_ACTION_PORT;
3418 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3422 if (n_tokens && (strcmp(tokens[0], "meta") == 0)) {
3423 a->fwd.action = RTE_PIPELINE_ACTION_PORT_META;
3424 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3428 if (n_tokens && (strcmp(tokens[0], "table") == 0)) {
3432 softnic_parser_read_uint32(&id, tokens[1]))
3435 a->fwd.action = RTE_PIPELINE_ACTION_TABLE;
3437 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3445 parse_table_action_balance(char **tokens,
3447 struct softnic_table_rule_action *a)
3451 if (n_tokens == 0 ||
3452 (strcmp(tokens[0], "balance") != 0))
3458 if (n_tokens < RTE_TABLE_ACTION_LB_TABLE_SIZE)
3461 for (i = 0; i < RTE_TABLE_ACTION_LB_TABLE_SIZE; i++)
3462 if (softnic_parser_read_uint32(&a->lb.out[i], tokens[i]) != 0)
3465 a->action_mask |= 1 << RTE_TABLE_ACTION_LB;
3466 return 1 + RTE_TABLE_ACTION_LB_TABLE_SIZE;
3470 parse_policer_action(char *token, enum rte_table_action_policer *a)
3472 if (strcmp(token, "g") == 0) {
3473 *a = RTE_TABLE_ACTION_POLICER_COLOR_GREEN;
3477 if (strcmp(token, "y") == 0) {
3478 *a = RTE_TABLE_ACTION_POLICER_COLOR_YELLOW;
3482 if (strcmp(token, "r") == 0) {
3483 *a = RTE_TABLE_ACTION_POLICER_COLOR_RED;
3487 if (strcmp(token, "drop") == 0) {
3488 *a = RTE_TABLE_ACTION_POLICER_DROP;
3496 parse_table_action_meter_tc(char **tokens,
3498 struct rte_table_action_mtr_tc_params *mtr)
3501 strcmp(tokens[0], "meter") ||
3502 softnic_parser_read_uint32(&mtr->meter_profile_id, tokens[1]) ||
3503 strcmp(tokens[2], "policer") ||
3504 strcmp(tokens[3], "g") ||
3505 parse_policer_action(tokens[4], &mtr->policer[e_RTE_METER_GREEN]) ||
3506 strcmp(tokens[5], "y") ||
3507 parse_policer_action(tokens[6], &mtr->policer[e_RTE_METER_YELLOW]) ||
3508 strcmp(tokens[7], "r") ||
3509 parse_policer_action(tokens[8], &mtr->policer[e_RTE_METER_RED]))
3516 parse_table_action_meter(char **tokens,
3518 struct softnic_table_rule_action *a)
3520 if (n_tokens == 0 ||
3521 strcmp(tokens[0], "meter"))
3527 if (n_tokens < 10 ||
3528 strcmp(tokens[0], "tc0") ||
3529 (parse_table_action_meter_tc(tokens + 1,
3531 &a->mtr.mtr[0]) == 0))
3537 if (n_tokens == 0 ||
3538 strcmp(tokens[0], "tc1")) {
3540 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3544 if (n_tokens < 30 ||
3545 (parse_table_action_meter_tc(tokens + 1,
3546 n_tokens - 1, &a->mtr.mtr[1]) == 0) ||
3547 strcmp(tokens[10], "tc2") ||
3548 (parse_table_action_meter_tc(tokens + 11,
3549 n_tokens - 11, &a->mtr.mtr[2]) == 0) ||
3550 strcmp(tokens[20], "tc3") ||
3551 (parse_table_action_meter_tc(tokens + 21,
3552 n_tokens - 21, &a->mtr.mtr[3]) == 0))
3555 a->mtr.tc_mask = 0xF;
3556 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3557 return 1 + 10 + 3 * 10;
3561 parse_table_action_tm(char **tokens,
3563 struct softnic_table_rule_action *a)
3565 uint32_t subport_id, pipe_id;
3568 strcmp(tokens[0], "tm") ||
3569 strcmp(tokens[1], "subport") ||
3570 softnic_parser_read_uint32(&subport_id, tokens[2]) ||
3571 strcmp(tokens[3], "pipe") ||
3572 softnic_parser_read_uint32(&pipe_id, tokens[4]))
3575 a->tm.subport_id = subport_id;
3576 a->tm.pipe_id = pipe_id;
3577 a->action_mask |= 1 << RTE_TABLE_ACTION_TM;
3582 parse_table_action_encap(char **tokens,
3584 struct softnic_table_rule_action *a)
3586 if (n_tokens == 0 ||
3587 strcmp(tokens[0], "encap"))
3594 if (n_tokens && (strcmp(tokens[0], "ether") == 0)) {
3596 softnic_parse_mac_addr(tokens[1], &a->encap.ether.ether.da) ||
3597 softnic_parse_mac_addr(tokens[2], &a->encap.ether.ether.sa))
3600 a->encap.type = RTE_TABLE_ACTION_ENCAP_ETHER;
3601 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3606 if (n_tokens && (strcmp(tokens[0], "vlan") == 0)) {
3607 uint32_t pcp, dei, vid;
3610 softnic_parse_mac_addr(tokens[1], &a->encap.vlan.ether.da) ||
3611 softnic_parse_mac_addr(tokens[2], &a->encap.vlan.ether.sa) ||
3612 softnic_parser_read_uint32(&pcp, tokens[3]) ||
3614 softnic_parser_read_uint32(&dei, tokens[4]) ||
3616 softnic_parser_read_uint32(&vid, tokens[5]) ||
3620 a->encap.vlan.vlan.pcp = pcp & 0x7;
3621 a->encap.vlan.vlan.dei = dei & 0x1;
3622 a->encap.vlan.vlan.vid = vid & 0xFFF;
3623 a->encap.type = RTE_TABLE_ACTION_ENCAP_VLAN;
3624 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3629 if (n_tokens && (strcmp(tokens[0], "qinq") == 0)) {
3630 uint32_t svlan_pcp, svlan_dei, svlan_vid;
3631 uint32_t cvlan_pcp, cvlan_dei, cvlan_vid;
3634 softnic_parse_mac_addr(tokens[1], &a->encap.qinq.ether.da) ||
3635 softnic_parse_mac_addr(tokens[2], &a->encap.qinq.ether.sa) ||
3636 softnic_parser_read_uint32(&svlan_pcp, tokens[3]) ||
3638 softnic_parser_read_uint32(&svlan_dei, tokens[4]) ||
3640 softnic_parser_read_uint32(&svlan_vid, tokens[5]) ||
3641 svlan_vid > 0xFFF ||
3642 softnic_parser_read_uint32(&cvlan_pcp, tokens[6]) ||
3644 softnic_parser_read_uint32(&cvlan_dei, tokens[7]) ||
3646 softnic_parser_read_uint32(&cvlan_vid, tokens[8]) ||
3650 a->encap.qinq.svlan.pcp = svlan_pcp & 0x7;
3651 a->encap.qinq.svlan.dei = svlan_dei & 0x1;
3652 a->encap.qinq.svlan.vid = svlan_vid & 0xFFF;
3653 a->encap.qinq.cvlan.pcp = cvlan_pcp & 0x7;
3654 a->encap.qinq.cvlan.dei = cvlan_dei & 0x1;
3655 a->encap.qinq.cvlan.vid = cvlan_vid & 0xFFF;
3656 a->encap.type = RTE_TABLE_ACTION_ENCAP_QINQ;
3657 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3662 if (n_tokens && (strcmp(tokens[0], "mpls") == 0)) {
3663 uint32_t label, tc, ttl;
3668 if (strcmp(tokens[1], "unicast") == 0)
3669 a->encap.mpls.unicast = 1;
3670 else if (strcmp(tokens[1], "multicast") == 0)
3671 a->encap.mpls.unicast = 0;
3675 if (softnic_parse_mac_addr(tokens[2], &a->encap.mpls.ether.da) ||
3676 softnic_parse_mac_addr(tokens[3], &a->encap.mpls.ether.sa) ||
3677 strcmp(tokens[4], "label0") ||
3678 softnic_parser_read_uint32(&label, tokens[5]) ||
3680 softnic_parser_read_uint32(&tc, tokens[6]) ||
3682 softnic_parser_read_uint32(&ttl, tokens[7]) ||
3686 a->encap.mpls.mpls[0].label = label;
3687 a->encap.mpls.mpls[0].tc = tc;
3688 a->encap.mpls.mpls[0].ttl = ttl;
3693 if (n_tokens == 0 ||
3694 strcmp(tokens[0], "label1")) {
3695 a->encap.mpls.mpls_count = 1;
3696 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3697 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3702 softnic_parser_read_uint32(&label, tokens[1]) ||
3704 softnic_parser_read_uint32(&tc, tokens[2]) ||
3706 softnic_parser_read_uint32(&ttl, tokens[3]) ||
3710 a->encap.mpls.mpls[1].label = label;
3711 a->encap.mpls.mpls[1].tc = tc;
3712 a->encap.mpls.mpls[1].ttl = ttl;
3717 if (n_tokens == 0 ||
3718 strcmp(tokens[0], "label2")) {
3719 a->encap.mpls.mpls_count = 2;
3720 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3721 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3726 softnic_parser_read_uint32(&label, tokens[1]) ||
3728 softnic_parser_read_uint32(&tc, tokens[2]) ||
3730 softnic_parser_read_uint32(&ttl, tokens[3]) ||
3734 a->encap.mpls.mpls[2].label = label;
3735 a->encap.mpls.mpls[2].tc = tc;
3736 a->encap.mpls.mpls[2].ttl = ttl;
3741 if (n_tokens == 0 ||
3742 strcmp(tokens[0], "label3")) {
3743 a->encap.mpls.mpls_count = 3;
3744 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3745 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3746 return 1 + 8 + 4 + 4;
3750 softnic_parser_read_uint32(&label, tokens[1]) ||
3752 softnic_parser_read_uint32(&tc, tokens[2]) ||
3754 softnic_parser_read_uint32(&ttl, tokens[3]) ||
3758 a->encap.mpls.mpls[3].label = label;
3759 a->encap.mpls.mpls[3].tc = tc;
3760 a->encap.mpls.mpls[3].ttl = ttl;
3762 a->encap.mpls.mpls_count = 4;
3763 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3764 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3765 return 1 + 8 + 4 + 4 + 4;
3769 if (n_tokens && (strcmp(tokens[0], "pppoe") == 0)) {
3771 softnic_parse_mac_addr(tokens[1], &a->encap.pppoe.ether.da) ||
3772 softnic_parse_mac_addr(tokens[2], &a->encap.pppoe.ether.sa) ||
3773 softnic_parser_read_uint16(&a->encap.pppoe.pppoe.session_id,
3777 a->encap.type = RTE_TABLE_ACTION_ENCAP_PPPOE;
3778 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3783 if (n_tokens && (strcmp(tokens[0], "vxlan") == 0)) {
3790 /* ether <da> <sa> */
3791 if ((n_tokens < 3) ||
3792 strcmp(tokens[0], "ether") ||
3793 softnic_parse_mac_addr(tokens[1], &a->encap.vxlan.ether.da) ||
3794 softnic_parse_mac_addr(tokens[2], &a->encap.vxlan.ether.sa))
3801 /* [vlan <pcp> <dei> <vid>] */
3802 if (strcmp(tokens[0], "vlan") == 0) {
3803 uint32_t pcp, dei, vid;
3805 if ((n_tokens < 4) ||
3806 softnic_parser_read_uint32(&pcp, tokens[1]) ||
3808 softnic_parser_read_uint32(&dei, tokens[2]) ||
3810 softnic_parser_read_uint32(&vid, tokens[3]) ||
3814 a->encap.vxlan.vlan.pcp = pcp;
3815 a->encap.vxlan.vlan.dei = dei;
3816 a->encap.vxlan.vlan.vid = vid;
3823 /* ipv4 <sa> <da> <dscp> <ttl>
3824 | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit> */
3825 if (strcmp(tokens[0], "ipv4") == 0) {
3826 struct in_addr sa, da;
3829 if ((n_tokens < 5) ||
3830 softnic_parse_ipv4_addr(tokens[1], &sa) ||
3831 softnic_parse_ipv4_addr(tokens[2], &da) ||
3832 softnic_parser_read_uint8(&dscp, tokens[3]) ||
3834 softnic_parser_read_uint8(&ttl, tokens[4]))
3837 a->encap.vxlan.ipv4.sa = rte_be_to_cpu_32(sa.s_addr);
3838 a->encap.vxlan.ipv4.da = rte_be_to_cpu_32(da.s_addr);
3839 a->encap.vxlan.ipv4.dscp = dscp;
3840 a->encap.vxlan.ipv4.ttl = ttl;
3845 } else if (strcmp(tokens[0], "ipv6") == 0) {
3846 struct in6_addr sa, da;
3847 uint32_t flow_label;
3848 uint8_t dscp, hop_limit;
3850 if ((n_tokens < 6) ||
3851 softnic_parse_ipv6_addr(tokens[1], &sa) ||
3852 softnic_parse_ipv6_addr(tokens[2], &da) ||
3853 softnic_parser_read_uint32(&flow_label, tokens[3]) ||
3854 softnic_parser_read_uint8(&dscp, tokens[4]) ||
3856 softnic_parser_read_uint8(&hop_limit, tokens[5]))
3859 memcpy(a->encap.vxlan.ipv6.sa, sa.s6_addr, 16);
3860 memcpy(a->encap.vxlan.ipv6.da, da.s6_addr, 16);
3861 a->encap.vxlan.ipv6.flow_label = flow_label;
3862 a->encap.vxlan.ipv6.dscp = dscp;
3863 a->encap.vxlan.ipv6.hop_limit = hop_limit;
3872 if ((n_tokens < 3) ||
3873 strcmp(tokens[0], "udp") ||
3874 softnic_parser_read_uint16(&a->encap.vxlan.udp.sp, tokens[1]) ||
3875 softnic_parser_read_uint16(&a->encap.vxlan.udp.dp, tokens[2]))
3883 if ((n_tokens < 2) ||
3884 strcmp(tokens[0], "vxlan") ||
3885 softnic_parser_read_uint32(&a->encap.vxlan.vxlan.vni, tokens[1]) ||
3886 (a->encap.vxlan.vxlan.vni > 0xFFFFFF))
3893 a->encap.type = RTE_TABLE_ACTION_ENCAP_VXLAN;
3894 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3902 parse_table_action_nat(char **tokens,
3904 struct softnic_table_rule_action *a)
3907 strcmp(tokens[0], "nat"))
3910 if (strcmp(tokens[1], "ipv4") == 0) {
3911 struct in_addr addr;
3914 if (softnic_parse_ipv4_addr(tokens[2], &addr) ||
3915 softnic_parser_read_uint16(&port, tokens[3]))
3918 a->nat.ip_version = 1;
3919 a->nat.addr.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3921 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3925 if (strcmp(tokens[1], "ipv6") == 0) {
3926 struct in6_addr addr;
3929 if (softnic_parse_ipv6_addr(tokens[2], &addr) ||
3930 softnic_parser_read_uint16(&port, tokens[3]))
3933 a->nat.ip_version = 0;
3934 memcpy(a->nat.addr.ipv6, addr.s6_addr, 16);
3936 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3944 parse_table_action_ttl(char **tokens,
3946 struct softnic_table_rule_action *a)
3949 strcmp(tokens[0], "ttl"))
3952 if (strcmp(tokens[1], "dec") == 0)
3953 a->ttl.decrement = 1;
3954 else if (strcmp(tokens[1], "keep") == 0)
3955 a->ttl.decrement = 0;
3959 a->action_mask |= 1 << RTE_TABLE_ACTION_TTL;
3964 parse_table_action_stats(char **tokens,
3966 struct softnic_table_rule_action *a)
3969 strcmp(tokens[0], "stats"))
3972 a->stats.n_packets = 0;
3973 a->stats.n_bytes = 0;
3974 a->action_mask |= 1 << RTE_TABLE_ACTION_STATS;
3979 parse_table_action_time(char **tokens,
3981 struct softnic_table_rule_action *a)
3984 strcmp(tokens[0], "time"))
3987 a->time.time = rte_rdtsc();
3988 a->action_mask |= 1 << RTE_TABLE_ACTION_TIME;
3993 parse_free_sym_crypto_param_data(struct rte_table_action_sym_crypto_params *p)
3995 struct rte_crypto_sym_xform *xform[2] = {NULL};
3998 xform[0] = p->xform;
4000 xform[1] = xform[0]->next;
4002 for (i = 0; i < 2; i++) {
4003 if (xform[i] == NULL)
4006 switch (xform[i]->type) {
4007 case RTE_CRYPTO_SYM_XFORM_CIPHER:
4008 if (xform[i]->cipher.key.data)
4009 free(xform[i]->cipher.key.data);
4010 if (p->cipher_auth.cipher_iv.val)
4011 free(p->cipher_auth.cipher_iv.val);
4012 if (p->cipher_auth.cipher_iv_update.val)
4013 free(p->cipher_auth.cipher_iv_update.val);
4015 case RTE_CRYPTO_SYM_XFORM_AUTH:
4016 if (xform[i]->auth.key.data)
4017 free(xform[i]->cipher.key.data);
4018 if (p->cipher_auth.auth_iv.val)
4019 free(p->cipher_auth.cipher_iv.val);
4020 if (p->cipher_auth.auth_iv_update.val)
4021 free(p->cipher_auth.cipher_iv_update.val);
4023 case RTE_CRYPTO_SYM_XFORM_AEAD:
4024 if (xform[i]->aead.key.data)
4025 free(xform[i]->cipher.key.data);
4027 free(p->aead.iv.val);
4028 if (p->aead.aad.val)
4029 free(p->aead.aad.val);
4038 static struct rte_crypto_sym_xform *
4039 parse_table_action_cipher(struct rte_table_action_sym_crypto_params *p,
4040 char **tokens, uint32_t n_tokens, uint32_t encrypt,
4041 uint32_t *used_n_tokens)
4043 struct rte_crypto_sym_xform *xform_cipher;
4047 if (n_tokens < 7 || strcmp(tokens[1], "cipher_algo") ||
4048 strcmp(tokens[3], "cipher_key") ||
4049 strcmp(tokens[5], "cipher_iv"))
4052 xform_cipher = calloc(1, sizeof(*xform_cipher));
4053 if (xform_cipher == NULL)
4056 xform_cipher->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4057 xform_cipher->cipher.op = encrypt ? RTE_CRYPTO_CIPHER_OP_ENCRYPT :
4058 RTE_CRYPTO_CIPHER_OP_DECRYPT;
4061 status = rte_cryptodev_get_cipher_algo_enum(
4062 &xform_cipher->cipher.algo, tokens[2]);
4067 len = strlen(tokens[4]);
4068 xform_cipher->cipher.key.data = calloc(1, len / 2 + 1);
4069 if (xform_cipher->cipher.key.data == NULL)
4072 status = softnic_parse_hex_string(tokens[4],
4073 xform_cipher->cipher.key.data,
4078 xform_cipher->cipher.key.length = (uint16_t)len;
4081 len = strlen(tokens[6]);
4083 p->cipher_auth.cipher_iv.val = calloc(1, len / 2 + 1);
4084 if (p->cipher_auth.cipher_iv.val == NULL)
4087 status = softnic_parse_hex_string(tokens[6],
4088 p->cipher_auth.cipher_iv.val,
4093 xform_cipher->cipher.iv.length = (uint16_t)len;
4094 xform_cipher->cipher.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
4095 p->cipher_auth.cipher_iv.length = (uint32_t)len;
4098 return xform_cipher;
4101 if (xform_cipher->cipher.key.data)
4102 free(xform_cipher->cipher.key.data);
4104 if (p->cipher_auth.cipher_iv.val) {
4105 free(p->cipher_auth.cipher_iv.val);
4106 p->cipher_auth.cipher_iv.val = NULL;
4114 static struct rte_crypto_sym_xform *
4115 parse_table_action_cipher_auth(struct rte_table_action_sym_crypto_params *p,
4116 char **tokens, uint32_t n_tokens, uint32_t encrypt,
4117 uint32_t *used_n_tokens)
4119 struct rte_crypto_sym_xform *xform_cipher;
4120 struct rte_crypto_sym_xform *xform_auth;
4124 if (n_tokens < 13 ||
4125 strcmp(tokens[7], "auth_algo") ||
4126 strcmp(tokens[9], "auth_key") ||
4127 strcmp(tokens[11], "digest_size"))
4130 xform_auth = calloc(1, sizeof(*xform_auth));
4131 if (xform_auth == NULL)
4134 xform_auth->type = RTE_CRYPTO_SYM_XFORM_AUTH;
4135 xform_auth->auth.op = encrypt ? RTE_CRYPTO_AUTH_OP_GENERATE :
4136 RTE_CRYPTO_AUTH_OP_VERIFY;
4139 status = rte_cryptodev_get_auth_algo_enum(&xform_auth->auth.algo,
4145 len = strlen(tokens[10]);
4146 xform_auth->auth.key.data = calloc(1, len / 2 + 1);
4147 if (xform_auth->auth.key.data == NULL)
4150 status = softnic_parse_hex_string(tokens[10],
4151 xform_auth->auth.key.data, (uint32_t *)&len);
4155 xform_auth->auth.key.length = (uint16_t)len;
4157 if (strcmp(tokens[11], "digest_size"))
4160 status = softnic_parser_read_uint16(&xform_auth->auth.digest_length,
4165 xform_cipher = parse_table_action_cipher(p, tokens, 7, encrypt,
4167 if (xform_cipher == NULL)
4170 *used_n_tokens += 6;
4173 xform_cipher->next = xform_auth;
4174 return xform_cipher;
4176 xform_auth->next = xform_cipher;
4181 if (xform_auth->auth.key.data)
4182 free(xform_auth->auth.key.data);
4183 if (p->cipher_auth.auth_iv.val) {
4184 free(p->cipher_auth.auth_iv.val);
4185 p->cipher_auth.auth_iv.val = 0;
4193 static struct rte_crypto_sym_xform *
4194 parse_table_action_aead(struct rte_table_action_sym_crypto_params *p,
4195 char **tokens, uint32_t n_tokens, uint32_t encrypt,
4196 uint32_t *used_n_tokens)
4198 struct rte_crypto_sym_xform *xform_aead;
4202 if (n_tokens < 11 || strcmp(tokens[1], "aead_algo") ||
4203 strcmp(tokens[3], "aead_key") ||
4204 strcmp(tokens[5], "aead_iv") ||
4205 strcmp(tokens[7], "aead_aad") ||
4206 strcmp(tokens[9], "digest_size"))
4209 xform_aead = calloc(1, sizeof(*xform_aead));
4210 if (xform_aead == NULL)
4213 xform_aead->type = RTE_CRYPTO_SYM_XFORM_AEAD;
4214 xform_aead->aead.op = encrypt ? RTE_CRYPTO_AEAD_OP_ENCRYPT :
4215 RTE_CRYPTO_AEAD_OP_DECRYPT;
4218 status = rte_cryptodev_get_aead_algo_enum(&xform_aead->aead.algo,
4224 len = strlen(tokens[4]);
4225 xform_aead->aead.key.data = calloc(1, len / 2 + 1);
4226 if (xform_aead->aead.key.data == NULL)
4229 status = softnic_parse_hex_string(tokens[4], xform_aead->aead.key.data,
4234 xform_aead->aead.key.length = (uint16_t)len;
4237 len = strlen(tokens[6]);
4238 p->aead.iv.val = calloc(1, len / 2 + 1);
4239 if (p->aead.iv.val == NULL)
4242 status = softnic_parse_hex_string(tokens[6], p->aead.iv.val,
4247 xform_aead->aead.iv.length = (uint16_t)len;
4248 xform_aead->aead.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
4249 p->aead.iv.length = (uint32_t)len;
4252 len = strlen(tokens[8]);
4253 p->aead.aad.val = calloc(1, len / 2 + 1);
4254 if (p->aead.aad.val == NULL)
4257 status = softnic_parse_hex_string(tokens[8], p->aead.aad.val, (uint32_t *)&len);
4261 xform_aead->aead.aad_length = (uint16_t)len;
4262 p->aead.aad.length = (uint32_t)len;
4265 status = softnic_parser_read_uint16(&xform_aead->aead.digest_length,
4270 *used_n_tokens = 11;
4275 if (xform_aead->aead.key.data)
4276 free(xform_aead->aead.key.data);
4277 if (p->aead.iv.val) {
4278 free(p->aead.iv.val);
4279 p->aead.iv.val = NULL;
4281 if (p->aead.aad.val) {
4282 free(p->aead.aad.val);
4283 p->aead.aad.val = NULL;
4293 parse_table_action_sym_crypto(char **tokens,
4295 struct softnic_table_rule_action *a)
4297 struct rte_table_action_sym_crypto_params *p = &a->sym_crypto;
4298 struct rte_crypto_sym_xform *xform = NULL;
4299 uint32_t used_n_tokens;
4303 if ((n_tokens < 12) ||
4304 strcmp(tokens[0], "sym_crypto") ||
4305 strcmp(tokens[2], "type"))
4308 memset(p, 0, sizeof(*p));
4310 if (strcmp(tokens[1], "encrypt") == 0)
4315 status = softnic_parser_read_uint32(&p->data_offset, tokens[n_tokens - 1]);
4319 if (strcmp(tokens[3], "cipher") == 0) {
4323 xform = parse_table_action_cipher(p, tokens, n_tokens, encrypt,
4325 } else if (strcmp(tokens[3], "cipher_auth") == 0) {
4329 xform = parse_table_action_cipher_auth(p, tokens, n_tokens,
4330 encrypt, &used_n_tokens);
4331 } else if (strcmp(tokens[3], "aead") == 0) {
4335 xform = parse_table_action_aead(p, tokens, n_tokens, encrypt,
4344 if (strcmp(tokens[used_n_tokens], "data_offset")) {
4345 parse_free_sym_crypto_param_data(p);
4349 a->action_mask |= 1 << RTE_TABLE_ACTION_SYM_CRYPTO;
4351 return used_n_tokens + 5;
4355 parse_table_action_tag(char **tokens,
4357 struct softnic_table_rule_action *a)
4360 strcmp(tokens[0], "tag"))
4363 if (softnic_parser_read_uint32(&a->tag.tag, tokens[1]))
4366 a->action_mask |= 1 << RTE_TABLE_ACTION_TAG;
4371 parse_table_action_decap(char **tokens,
4373 struct softnic_table_rule_action *a)
4376 strcmp(tokens[0], "decap"))
4379 if (softnic_parser_read_uint16(&a->decap.n, tokens[1]))
4382 a->action_mask |= 1 << RTE_TABLE_ACTION_DECAP;
4387 parse_table_action(char **tokens,
4391 struct softnic_table_rule_action *a)
4393 uint32_t n_tokens0 = n_tokens;
4395 memset(a, 0, sizeof(*a));
4398 strcmp(tokens[0], "action"))
4404 if (n_tokens && (strcmp(tokens[0], "fwd") == 0)) {
4407 n = parse_table_action_fwd(tokens, n_tokens, a);
4409 snprintf(out, out_size, MSG_ARG_INVALID,
4418 if (n_tokens && (strcmp(tokens[0], "balance") == 0)) {
4421 n = parse_table_action_balance(tokens, n_tokens, a);
4423 snprintf(out, out_size, MSG_ARG_INVALID,
4432 if (n_tokens && (strcmp(tokens[0], "meter") == 0)) {
4435 n = parse_table_action_meter(tokens, n_tokens, a);
4437 snprintf(out, out_size, MSG_ARG_INVALID,
4446 if (n_tokens && (strcmp(tokens[0], "tm") == 0)) {
4449 n = parse_table_action_tm(tokens, n_tokens, a);
4451 snprintf(out, out_size, MSG_ARG_INVALID,
4460 if (n_tokens && (strcmp(tokens[0], "encap") == 0)) {
4463 n = parse_table_action_encap(tokens, n_tokens, a);
4465 snprintf(out, out_size, MSG_ARG_INVALID,
4474 if (n_tokens && (strcmp(tokens[0], "nat") == 0)) {
4477 n = parse_table_action_nat(tokens, n_tokens, a);
4479 snprintf(out, out_size, MSG_ARG_INVALID,
4488 if (n_tokens && (strcmp(tokens[0], "ttl") == 0)) {
4491 n = parse_table_action_ttl(tokens, n_tokens, a);
4493 snprintf(out, out_size, MSG_ARG_INVALID,
4502 if (n_tokens && (strcmp(tokens[0], "stats") == 0)) {
4505 n = parse_table_action_stats(tokens, n_tokens, a);
4507 snprintf(out, out_size, MSG_ARG_INVALID,
4516 if (n_tokens && (strcmp(tokens[0], "time") == 0)) {
4519 n = parse_table_action_time(tokens, n_tokens, a);
4521 snprintf(out, out_size, MSG_ARG_INVALID,
4530 if (n_tokens && (strcmp(tokens[0], "tag") == 0)) {
4533 n = parse_table_action_tag(tokens, n_tokens, a);
4535 snprintf(out, out_size, MSG_ARG_INVALID,
4544 if (n_tokens && (strcmp(tokens[0], "decap") == 0)) {
4547 n = parse_table_action_decap(tokens, n_tokens, a);
4549 snprintf(out, out_size, MSG_ARG_INVALID,
4558 if (n_tokens && (strcmp(tokens[0], "sym_crypto") == 0)) {
4561 n = parse_table_action_sym_crypto(tokens, n_tokens, a);
4563 snprintf(out, out_size, MSG_ARG_INVALID,
4564 "action sym_crypto");
4571 if (n_tokens0 - n_tokens == 1) {
4572 snprintf(out, out_size, MSG_ARG_INVALID, "action");
4576 return n_tokens0 - n_tokens;
4580 * pipeline <pipeline_name> table <table_id> rule add
4582 * action <table_action>
4585 cmd_softnic_pipeline_table_rule_add(struct pmd_internals *softnic,
4591 struct softnic_table_rule_match m;
4592 struct softnic_table_rule_action a;
4593 char *pipeline_name;
4595 uint32_t table_id, t0, n_tokens_parsed;
4599 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4603 pipeline_name = tokens[1];
4605 if (strcmp(tokens[2], "table") != 0) {
4606 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4610 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
4611 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4615 if (strcmp(tokens[4], "rule") != 0) {
4616 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4620 if (strcmp(tokens[5], "add") != 0) {
4621 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4628 n_tokens_parsed = parse_match(tokens + t0,
4633 if (n_tokens_parsed == 0)
4635 t0 += n_tokens_parsed;
4638 n_tokens_parsed = parse_table_action(tokens + t0,
4643 if (n_tokens_parsed == 0)
4645 t0 += n_tokens_parsed;
4647 if (t0 != n_tokens) {
4648 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
4652 status = softnic_pipeline_table_rule_add(softnic,
4659 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4665 * pipeline <pipeline_name> table <table_id> rule add
4673 * | table <table_id>
4676 cmd_softnic_pipeline_table_rule_add_default(struct pmd_internals *softnic,
4682 struct softnic_table_rule_action action;
4684 char *pipeline_name;
4688 if (n_tokens != 11 &&
4690 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4694 pipeline_name = tokens[1];
4696 if (strcmp(tokens[2], "table") != 0) {
4697 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4701 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
4702 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4706 if (strcmp(tokens[4], "rule") != 0) {
4707 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4711 if (strcmp(tokens[5], "add") != 0) {
4712 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4716 if (strcmp(tokens[6], "match") != 0) {
4717 snprintf(out, out_size, MSG_ARG_INVALID, "match");
4721 if (strcmp(tokens[7], "default") != 0) {
4722 snprintf(out, out_size, MSG_ARG_INVALID, "default");
4726 if (strcmp(tokens[8], "action") != 0) {
4727 snprintf(out, out_size, MSG_ARG_INVALID, "action");
4731 if (strcmp(tokens[9], "fwd") != 0) {
4732 snprintf(out, out_size, MSG_ARG_INVALID, "fwd");
4736 action.action_mask = 1 << RTE_TABLE_ACTION_FWD;
4738 if (strcmp(tokens[10], "drop") == 0) {
4739 if (n_tokens != 11) {
4740 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4744 action.fwd.action = RTE_PIPELINE_ACTION_DROP;
4745 } else if (strcmp(tokens[10], "port") == 0) {
4748 if (n_tokens != 12) {
4749 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4753 if (softnic_parser_read_uint32(&id, tokens[11]) != 0) {
4754 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
4758 action.fwd.action = RTE_PIPELINE_ACTION_PORT;
4760 } else if (strcmp(tokens[10], "meta") == 0) {
4761 if (n_tokens != 11) {
4762 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4766 action.fwd.action = RTE_PIPELINE_ACTION_PORT_META;
4767 } else if (strcmp(tokens[10], "table") == 0) {
4770 if (n_tokens != 12) {
4771 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4775 if (softnic_parser_read_uint32(&id, tokens[11]) != 0) {
4776 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4780 action.fwd.action = RTE_PIPELINE_ACTION_TABLE;
4783 snprintf(out, out_size, MSG_ARG_INVALID,
4784 "drop or port or meta or table");
4788 status = softnic_pipeline_table_rule_add_default(softnic,
4794 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4800 * pipeline <pipeline_name> table <table_id> rule add bulk <file_name> <n_rules>
4803 * - line format: match <match> action <action>
4806 cli_rule_file_process(const char *file_name,
4807 size_t line_len_max,
4808 struct softnic_table_rule_match *m,
4809 struct softnic_table_rule_action *a,
4811 uint32_t *line_number,
4816 cmd_softnic_pipeline_table_rule_add_bulk(struct pmd_internals *softnic,
4822 struct softnic_table_rule_match *match;
4823 struct softnic_table_rule_action *action;
4825 char *pipeline_name, *file_name;
4826 uint32_t table_id, n_rules, n_rules_parsed, line_number;
4829 if (n_tokens != 9) {
4830 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4834 pipeline_name = tokens[1];
4836 if (strcmp(tokens[2], "table") != 0) {
4837 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4841 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
4842 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4846 if (strcmp(tokens[4], "rule") != 0) {
4847 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4851 if (strcmp(tokens[5], "add") != 0) {
4852 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4856 if (strcmp(tokens[6], "bulk") != 0) {
4857 snprintf(out, out_size, MSG_ARG_INVALID, "bulk");
4861 file_name = tokens[7];
4863 if ((softnic_parser_read_uint32(&n_rules, tokens[8]) != 0) ||
4865 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
4869 /* Memory allocation. */
4870 match = calloc(n_rules, sizeof(struct softnic_table_rule_match));
4871 action = calloc(n_rules, sizeof(struct softnic_table_rule_action));
4872 data = calloc(n_rules, sizeof(void *));
4873 if (match == NULL ||
4876 snprintf(out, out_size, MSG_OUT_OF_MEMORY);
4883 /* Load rule file */
4884 n_rules_parsed = n_rules;
4885 status = cli_rule_file_process(file_name,
4894 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
4900 if (n_rules_parsed != n_rules) {
4901 snprintf(out, out_size, MSG_FILE_NOT_ENOUGH, file_name);
4909 status = softnic_pipeline_table_rule_add_bulk(softnic,
4917 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4931 * pipeline <pipeline_name> table <table_id> rule delete
4935 cmd_softnic_pipeline_table_rule_delete(struct pmd_internals *softnic,
4941 struct softnic_table_rule_match m;
4942 char *pipeline_name;
4943 uint32_t table_id, n_tokens_parsed, t0;
4947 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4951 pipeline_name = tokens[1];
4953 if (strcmp(tokens[2], "table") != 0) {
4954 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4958 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
4959 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4963 if (strcmp(tokens[4], "rule") != 0) {
4964 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4968 if (strcmp(tokens[5], "delete") != 0) {
4969 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
4976 n_tokens_parsed = parse_match(tokens + t0,
4981 if (n_tokens_parsed == 0)
4983 t0 += n_tokens_parsed;
4985 if (n_tokens != t0) {
4986 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4990 status = softnic_pipeline_table_rule_delete(softnic,
4995 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5001 * pipeline <pipeline_name> table <table_id> rule delete
5006 cmd_softnic_pipeline_table_rule_delete_default(struct pmd_internals *softnic,
5012 char *pipeline_name;
5016 if (n_tokens != 8) {
5017 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5021 pipeline_name = tokens[1];
5023 if (strcmp(tokens[2], "table") != 0) {
5024 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5028 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
5029 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5033 if (strcmp(tokens[4], "rule") != 0) {
5034 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5038 if (strcmp(tokens[5], "delete") != 0) {
5039 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
5043 if (strcmp(tokens[6], "match") != 0) {
5044 snprintf(out, out_size, MSG_ARG_INVALID, "match");
5048 if (strcmp(tokens[7], "default") != 0) {
5049 snprintf(out, out_size, MSG_ARG_INVALID, "default");
5053 status = softnic_pipeline_table_rule_delete_default(softnic,
5057 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5063 * pipeline <pipeline_name> table <table_id> rule read stats [clear]
5066 cmd_softnic_pipeline_table_rule_stats_read(struct pmd_internals *softnic __rte_unused,
5068 uint32_t n_tokens __rte_unused,
5072 snprintf(out, out_size, MSG_CMD_UNIMPLEM, tokens[0]);
5076 * pipeline <pipeline_name> table <table_id> meter profile <meter_profile_id>
5077 * add srtcm cir <cir> cbs <cbs> ebs <ebs>
5078 * | trtcm cir <cir> pir <pir> cbs <cbs> pbs <pbs>
5081 cmd_pipeline_table_meter_profile_add(struct pmd_internals *softnic,
5087 struct rte_table_action_meter_profile p;
5088 char *pipeline_name;
5089 uint32_t table_id, meter_profile_id;
5093 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5097 pipeline_name = tokens[1];
5099 if (strcmp(tokens[2], "table") != 0) {
5100 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5104 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
5105 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5109 if (strcmp(tokens[4], "meter") != 0) {
5110 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5114 if (strcmp(tokens[5], "profile") != 0) {
5115 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
5119 if (softnic_parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
5120 snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
5124 if (strcmp(tokens[7], "add") != 0) {
5125 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
5129 if (strcmp(tokens[8], "srtcm") == 0) {
5130 if (n_tokens != 15) {
5131 snprintf(out, out_size, MSG_ARG_MISMATCH,
5136 p.alg = RTE_TABLE_ACTION_METER_SRTCM;
5138 if (strcmp(tokens[9], "cir") != 0) {
5139 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
5143 if (softnic_parser_read_uint64(&p.srtcm.cir, tokens[10]) != 0) {
5144 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
5148 if (strcmp(tokens[11], "cbs") != 0) {
5149 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
5153 if (softnic_parser_read_uint64(&p.srtcm.cbs, tokens[12]) != 0) {
5154 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
5158 if (strcmp(tokens[13], "ebs") != 0) {
5159 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ebs");
5163 if (softnic_parser_read_uint64(&p.srtcm.ebs, tokens[14]) != 0) {
5164 snprintf(out, out_size, MSG_ARG_INVALID, "ebs");
5167 } else if (strcmp(tokens[8], "trtcm") == 0) {
5168 if (n_tokens != 17) {
5169 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5173 p.alg = RTE_TABLE_ACTION_METER_TRTCM;
5175 if (strcmp(tokens[9], "cir") != 0) {
5176 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
5180 if (softnic_parser_read_uint64(&p.trtcm.cir, tokens[10]) != 0) {
5181 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
5185 if (strcmp(tokens[11], "pir") != 0) {
5186 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir");
5190 if (softnic_parser_read_uint64(&p.trtcm.pir, tokens[12]) != 0) {
5191 snprintf(out, out_size, MSG_ARG_INVALID, "pir");
5194 if (strcmp(tokens[13], "cbs") != 0) {
5195 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
5199 if (softnic_parser_read_uint64(&p.trtcm.cbs, tokens[14]) != 0) {
5200 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
5204 if (strcmp(tokens[15], "pbs") != 0) {
5205 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs");
5209 if (softnic_parser_read_uint64(&p.trtcm.pbs, tokens[16]) != 0) {
5210 snprintf(out, out_size, MSG_ARG_INVALID, "pbs");
5214 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5218 status = softnic_pipeline_table_mtr_profile_add(softnic,
5224 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5230 * pipeline <pipeline_name> table <table_id>
5231 * meter profile <meter_profile_id> delete
5234 cmd_pipeline_table_meter_profile_delete(struct pmd_internals *softnic,
5240 char *pipeline_name;
5241 uint32_t table_id, meter_profile_id;
5244 if (n_tokens != 8) {
5245 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5249 pipeline_name = tokens[1];
5251 if (strcmp(tokens[2], "table") != 0) {
5252 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5256 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
5257 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5261 if (strcmp(tokens[4], "meter") != 0) {
5262 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5266 if (strcmp(tokens[5], "profile") != 0) {
5267 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
5271 if (softnic_parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
5272 snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
5276 if (strcmp(tokens[7], "delete") != 0) {
5277 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
5281 status = softnic_pipeline_table_mtr_profile_delete(softnic,
5286 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5292 * pipeline <pipeline_name> table <table_id> rule read meter [clear]
5295 cmd_pipeline_table_rule_meter_read(struct pmd_internals *softnic __rte_unused,
5297 uint32_t n_tokens __rte_unused,
5301 snprintf(out, out_size, MSG_CMD_UNIMPLEM, tokens[0]);
5305 * pipeline <pipeline_name> table <table_id> dscp <file_name>
5308 * - exactly 64 lines
5309 * - line format: <tc_id> <tc_queue_id> <color>, with <color> as: g | y | r
5312 load_dscp_table(struct rte_table_action_dscp_table *dscp_table,
5313 const char *file_name,
5314 uint32_t *line_number)
5319 /* Check input arguments */
5320 if (dscp_table == NULL ||
5321 file_name == NULL ||
5322 line_number == NULL) {
5328 /* Open input file */
5329 f = fopen(file_name, "r");
5336 for (dscp = 0, l = 1; ; l++) {
5339 enum rte_meter_color color;
5340 uint32_t tc_id, tc_queue_id, n_tokens = RTE_DIM(tokens);
5342 if (fgets(line, sizeof(line), f) == NULL)
5345 if (is_comment(line))
5348 if (softnic_parse_tokenize_string(line, tokens, &n_tokens)) {
5357 if (dscp >= RTE_DIM(dscp_table->entry) ||
5358 n_tokens != RTE_DIM(tokens) ||
5359 softnic_parser_read_uint32(&tc_id, tokens[0]) ||
5360 tc_id >= RTE_TABLE_ACTION_TC_MAX ||
5361 softnic_parser_read_uint32(&tc_queue_id, tokens[1]) ||
5362 tc_queue_id >= RTE_TABLE_ACTION_TC_QUEUE_MAX ||
5363 (strlen(tokens[2]) != 1)) {
5369 switch (tokens[2][0]) {
5372 color = e_RTE_METER_GREEN;
5377 color = e_RTE_METER_YELLOW;
5382 color = e_RTE_METER_RED;
5391 dscp_table->entry[dscp].tc_id = tc_id;
5392 dscp_table->entry[dscp].tc_queue_id = tc_queue_id;
5393 dscp_table->entry[dscp].color = color;
5403 cmd_pipeline_table_dscp(struct pmd_internals *softnic,
5409 struct rte_table_action_dscp_table dscp_table;
5410 char *pipeline_name, *file_name;
5411 uint32_t table_id, line_number;
5414 if (n_tokens != 6) {
5415 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5419 pipeline_name = tokens[1];
5421 if (strcmp(tokens[2], "table") != 0) {
5422 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5426 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
5427 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5431 if (strcmp(tokens[4], "dscp") != 0) {
5432 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dscp");
5436 file_name = tokens[5];
5438 status = load_dscp_table(&dscp_table, file_name, &line_number);
5440 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
5444 status = softnic_pipeline_table_dscp_table_update(softnic,
5450 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5456 * pipeline <pipeline_name> table <table_id> rule read ttl [clear]
5459 cmd_softnic_pipeline_table_rule_ttl_read(struct pmd_internals *softnic __rte_unused,
5461 uint32_t n_tokens __rte_unused,
5465 snprintf(out, out_size, MSG_CMD_UNIMPLEM, tokens[0]);
5469 * thread <thread_id> pipeline <pipeline_name> enable
5472 cmd_softnic_thread_pipeline_enable(struct pmd_internals *softnic,
5478 char *pipeline_name;
5482 if (n_tokens != 5) {
5483 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5487 if (softnic_parser_read_uint32(&thread_id, tokens[1]) != 0) {
5488 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
5492 if (strcmp(tokens[2], "pipeline") != 0) {
5493 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
5497 pipeline_name = tokens[3];
5499 if (strcmp(tokens[4], "enable") != 0) {
5500 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
5504 status = softnic_thread_pipeline_enable(softnic, thread_id, pipeline_name);
5506 snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable");
5512 * thread <thread_id> pipeline <pipeline_name> disable
5515 cmd_softnic_thread_pipeline_disable(struct pmd_internals *softnic,
5521 char *pipeline_name;
5525 if (n_tokens != 5) {
5526 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5530 if (softnic_parser_read_uint32(&thread_id, tokens[1]) != 0) {
5531 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
5535 if (strcmp(tokens[2], "pipeline") != 0) {
5536 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
5540 pipeline_name = tokens[3];
5542 if (strcmp(tokens[4], "disable") != 0) {
5543 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
5547 status = softnic_thread_pipeline_disable(softnic, thread_id, pipeline_name);
5549 snprintf(out, out_size, MSG_CMD_FAIL,
5550 "thread pipeline disable");
5559 * pipeline <pipeline_name>
5563 cmd_softnic_flowapi_map(struct pmd_internals *softnic,
5569 char *pipeline_name;
5570 uint32_t group_id, table_id;
5571 int ingress, status;
5573 if (n_tokens != 9) {
5574 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5578 if (strcmp(tokens[1], "map") != 0) {
5579 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "map");
5583 if (strcmp(tokens[2], "group") != 0) {
5584 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group");
5588 if (softnic_parser_read_uint32(&group_id, tokens[3]) != 0) {
5589 snprintf(out, out_size, MSG_ARG_INVALID, "group_id");
5593 if (strcmp(tokens[4], "ingress") == 0) {
5595 } else if (strcmp(tokens[4], "egress") == 0) {
5598 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ingress | egress");
5602 if (strcmp(tokens[5], "pipeline") != 0) {
5603 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
5607 pipeline_name = tokens[6];
5609 if (strcmp(tokens[7], "table") != 0) {
5610 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5614 if (softnic_parser_read_uint32(&table_id, tokens[8]) != 0) {
5615 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5619 status = flow_attr_map_set(softnic,
5625 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5631 softnic_cli_process(char *in, char *out, size_t out_size, void *arg)
5633 char *tokens[CMD_MAX_TOKENS];
5634 uint32_t n_tokens = RTE_DIM(tokens);
5635 struct pmd_internals *softnic = arg;
5641 status = softnic_parse_tokenize_string(in, tokens, &n_tokens);
5643 snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
5650 if (strcmp(tokens[0], "mempool") == 0) {
5651 cmd_mempool(softnic, tokens, n_tokens, out, out_size);
5655 if (strcmp(tokens[0], "link") == 0) {
5656 cmd_link(softnic, tokens, n_tokens, out, out_size);
5660 if (strcmp(tokens[0], "swq") == 0) {
5661 cmd_swq(softnic, tokens, n_tokens, out, out_size);
5665 if (strcmp(tokens[0], "tmgr") == 0) {
5666 if (n_tokens == 2) {
5667 cmd_tmgr(softnic, tokens, n_tokens, out, out_size);
5671 if (n_tokens >= 3 &&
5672 (strcmp(tokens[1], "shaper") == 0) &&
5673 (strcmp(tokens[2], "profile") == 0)) {
5674 cmd_tmgr_shaper_profile(softnic, tokens, n_tokens, out, out_size);
5678 if (n_tokens >= 3 &&
5679 (strcmp(tokens[1], "shared") == 0) &&
5680 (strcmp(tokens[2], "shaper") == 0)) {
5681 cmd_tmgr_shared_shaper(softnic, tokens, n_tokens, out, out_size);
5685 if (n_tokens >= 2 &&
5686 (strcmp(tokens[1], "node") == 0)) {
5687 cmd_tmgr_node(softnic, tokens, n_tokens, out, out_size);
5691 if (n_tokens >= 2 &&
5692 (strcmp(tokens[1], "hierarchy-default") == 0)) {
5693 cmd_tmgr_hierarchy_default(softnic, tokens, n_tokens, out, out_size);
5697 if (n_tokens >= 3 &&
5698 (strcmp(tokens[1], "hierarchy") == 0) &&
5699 (strcmp(tokens[2], "commit") == 0)) {
5700 cmd_tmgr_hierarchy_commit(softnic, tokens, n_tokens, out, out_size);
5705 if (strcmp(tokens[0], "tap") == 0) {
5706 cmd_tap(softnic, tokens, n_tokens, out, out_size);
5710 if (strcmp(tokens[0], "cryptodev") == 0) {
5711 cmd_cryptodev(softnic, tokens, n_tokens, out, out_size);
5715 if (strcmp(tokens[0], "port") == 0) {
5716 cmd_port_in_action_profile(softnic, tokens, n_tokens, out, out_size);
5720 if (strcmp(tokens[0], "table") == 0) {
5721 cmd_table_action_profile(softnic, tokens, n_tokens, out, out_size);
5725 if (strcmp(tokens[0], "pipeline") == 0) {
5726 if (n_tokens >= 3 &&
5727 (strcmp(tokens[2], "period") == 0)) {
5728 cmd_pipeline(softnic, tokens, n_tokens, out, out_size);
5732 if (n_tokens >= 5 &&
5733 (strcmp(tokens[2], "port") == 0) &&
5734 (strcmp(tokens[3], "in") == 0) &&
5735 (strcmp(tokens[4], "bsz") == 0)) {
5736 cmd_pipeline_port_in(softnic, tokens, n_tokens, out, out_size);
5740 if (n_tokens >= 5 &&
5741 (strcmp(tokens[2], "port") == 0) &&
5742 (strcmp(tokens[3], "out") == 0) &&
5743 (strcmp(tokens[4], "bsz") == 0)) {
5744 cmd_pipeline_port_out(softnic, tokens, n_tokens, out, out_size);
5748 if (n_tokens >= 4 &&
5749 (strcmp(tokens[2], "table") == 0) &&
5750 (strcmp(tokens[3], "match") == 0)) {
5751 cmd_pipeline_table(softnic, tokens, n_tokens, out, out_size);
5755 if (n_tokens >= 6 &&
5756 (strcmp(tokens[2], "port") == 0) &&
5757 (strcmp(tokens[3], "in") == 0) &&
5758 (strcmp(tokens[5], "table") == 0)) {
5759 cmd_pipeline_port_in_table(softnic, tokens, n_tokens,
5764 if (n_tokens >= 6 &&
5765 (strcmp(tokens[2], "port") == 0) &&
5766 (strcmp(tokens[3], "in") == 0) &&
5767 (strcmp(tokens[5], "stats") == 0)) {
5768 cmd_pipeline_port_in_stats(softnic, tokens, n_tokens,
5773 if (n_tokens >= 6 &&
5774 (strcmp(tokens[2], "port") == 0) &&
5775 (strcmp(tokens[3], "in") == 0) &&
5776 (strcmp(tokens[5], "enable") == 0)) {
5777 cmd_softnic_pipeline_port_in_enable(softnic, tokens, n_tokens,
5782 if (n_tokens >= 6 &&
5783 (strcmp(tokens[2], "port") == 0) &&
5784 (strcmp(tokens[3], "in") == 0) &&
5785 (strcmp(tokens[5], "disable") == 0)) {
5786 cmd_softnic_pipeline_port_in_disable(softnic, tokens, n_tokens,
5791 if (n_tokens >= 6 &&
5792 (strcmp(tokens[2], "port") == 0) &&
5793 (strcmp(tokens[3], "out") == 0) &&
5794 (strcmp(tokens[5], "stats") == 0)) {
5795 cmd_pipeline_port_out_stats(softnic, tokens, n_tokens,
5800 if (n_tokens >= 5 &&
5801 (strcmp(tokens[2], "table") == 0) &&
5802 (strcmp(tokens[4], "stats") == 0)) {
5803 cmd_pipeline_table_stats(softnic, tokens, n_tokens,
5808 if (n_tokens >= 7 &&
5809 (strcmp(tokens[2], "table") == 0) &&
5810 (strcmp(tokens[4], "rule") == 0) &&
5811 (strcmp(tokens[5], "add") == 0) &&
5812 (strcmp(tokens[6], "match") == 0)) {
5813 if (n_tokens >= 8 &&
5814 (strcmp(tokens[7], "default") == 0)) {
5815 cmd_softnic_pipeline_table_rule_add_default(softnic, tokens,
5816 n_tokens, out, out_size);
5820 cmd_softnic_pipeline_table_rule_add(softnic, tokens, n_tokens,
5825 if (n_tokens >= 7 &&
5826 (strcmp(tokens[2], "table") == 0) &&
5827 (strcmp(tokens[4], "rule") == 0) &&
5828 (strcmp(tokens[5], "add") == 0) &&
5829 (strcmp(tokens[6], "bulk") == 0)) {
5830 cmd_softnic_pipeline_table_rule_add_bulk(softnic, tokens,
5831 n_tokens, out, out_size);
5835 if (n_tokens >= 7 &&
5836 (strcmp(tokens[2], "table") == 0) &&
5837 (strcmp(tokens[4], "rule") == 0) &&
5838 (strcmp(tokens[5], "delete") == 0) &&
5839 (strcmp(tokens[6], "match") == 0)) {
5840 if (n_tokens >= 8 &&
5841 (strcmp(tokens[7], "default") == 0)) {
5842 cmd_softnic_pipeline_table_rule_delete_default(softnic, tokens,
5843 n_tokens, out, out_size);
5847 cmd_softnic_pipeline_table_rule_delete(softnic, tokens, n_tokens,
5852 if (n_tokens >= 7 &&
5853 (strcmp(tokens[2], "table") == 0) &&
5854 (strcmp(tokens[4], "rule") == 0) &&
5855 (strcmp(tokens[5], "read") == 0) &&
5856 (strcmp(tokens[6], "stats") == 0)) {
5857 cmd_softnic_pipeline_table_rule_stats_read(softnic, tokens, n_tokens,
5862 if (n_tokens >= 8 &&
5863 (strcmp(tokens[2], "table") == 0) &&
5864 (strcmp(tokens[4], "meter") == 0) &&
5865 (strcmp(tokens[5], "profile") == 0) &&
5866 (strcmp(tokens[7], "add") == 0)) {
5867 cmd_pipeline_table_meter_profile_add(softnic, tokens, n_tokens,
5872 if (n_tokens >= 8 &&
5873 (strcmp(tokens[2], "table") == 0) &&
5874 (strcmp(tokens[4], "meter") == 0) &&
5875 (strcmp(tokens[5], "profile") == 0) &&
5876 (strcmp(tokens[7], "delete") == 0)) {
5877 cmd_pipeline_table_meter_profile_delete(softnic, tokens,
5878 n_tokens, out, out_size);
5882 if (n_tokens >= 7 &&
5883 (strcmp(tokens[2], "table") == 0) &&
5884 (strcmp(tokens[4], "rule") == 0) &&
5885 (strcmp(tokens[5], "read") == 0) &&
5886 (strcmp(tokens[6], "meter") == 0)) {
5887 cmd_pipeline_table_rule_meter_read(softnic, tokens, n_tokens,
5892 if (n_tokens >= 5 &&
5893 (strcmp(tokens[2], "table") == 0) &&
5894 (strcmp(tokens[4], "dscp") == 0)) {
5895 cmd_pipeline_table_dscp(softnic, tokens, n_tokens,
5900 if (n_tokens >= 7 &&
5901 (strcmp(tokens[2], "table") == 0) &&
5902 (strcmp(tokens[4], "rule") == 0) &&
5903 (strcmp(tokens[5], "read") == 0) &&
5904 (strcmp(tokens[6], "ttl") == 0)) {
5905 cmd_softnic_pipeline_table_rule_ttl_read(softnic, tokens, n_tokens,
5911 if (strcmp(tokens[0], "thread") == 0) {
5912 if (n_tokens >= 5 &&
5913 (strcmp(tokens[4], "enable") == 0)) {
5914 cmd_softnic_thread_pipeline_enable(softnic, tokens, n_tokens,
5919 if (n_tokens >= 5 &&
5920 (strcmp(tokens[4], "disable") == 0)) {
5921 cmd_softnic_thread_pipeline_disable(softnic, tokens, n_tokens,
5927 if (strcmp(tokens[0], "flowapi") == 0) {
5928 cmd_softnic_flowapi_map(softnic, tokens, n_tokens, out,
5933 snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
5937 softnic_cli_script_process(struct pmd_internals *softnic,
5938 const char *file_name,
5939 size_t msg_in_len_max,
5940 size_t msg_out_len_max)
5942 char *msg_in = NULL, *msg_out = NULL;
5945 /* Check input arguments */
5946 if (file_name == NULL ||
5947 (strlen(file_name) == 0) ||
5948 msg_in_len_max == 0 ||
5949 msg_out_len_max == 0)
5952 msg_in = malloc(msg_in_len_max + 1);
5953 msg_out = malloc(msg_out_len_max + 1);
5954 if (msg_in == NULL ||
5961 /* Open input file */
5962 f = fopen(file_name, "r");
5971 if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
5974 printf("%s", msg_in);
5977 softnic_cli_process(msg_in,
5982 if (strlen(msg_out))
5983 printf("%s", msg_out);
5994 cli_rule_file_process(const char *file_name,
5995 size_t line_len_max,
5996 struct softnic_table_rule_match *m,
5997 struct softnic_table_rule_action *a,
5999 uint32_t *line_number,
6005 uint32_t rule_id, line_id;
6008 /* Check input arguments */
6009 if (file_name == NULL ||
6010 (strlen(file_name) == 0) ||
6011 line_len_max == 0) {
6016 /* Memory allocation */
6017 line = malloc(line_len_max + 1);
6024 f = fopen(file_name, "r");
6032 for (line_id = 1, rule_id = 0; rule_id < *n_rules; line_id++) {
6033 char *tokens[CMD_MAX_TOKENS];
6034 uint32_t n_tokens, n_tokens_parsed, t0;
6036 /* Read next line from file. */
6037 if (fgets(line, line_len_max + 1, f) == NULL)
6041 if (is_comment(line))
6045 n_tokens = RTE_DIM(tokens);
6046 status = softnic_parse_tokenize_string(line, tokens, &n_tokens);
6058 n_tokens_parsed = parse_match(tokens + t0,
6063 if (n_tokens_parsed == 0) {
6067 t0 += n_tokens_parsed;
6070 n_tokens_parsed = parse_table_action(tokens + t0,
6075 if (n_tokens_parsed == 0) {
6079 t0 += n_tokens_parsed;
6081 /* Line completed. */
6082 if (t0 < n_tokens) {
6087 /* Increment rule count */
6098 *line_number = line_id;