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> max_sessions <n_sessions>
1099 cmd_cryptodev(struct pmd_internals *softnic,
1105 struct softnic_cryptodev_params params;
1108 memset(¶ms, 0, sizeof(params));
1109 if (n_tokens != 9) {
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 (strcmp(tokens[7], "max_sessions")) {
1149 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1154 if (softnic_parser_read_uint32(¶ms.session_pool_size, tokens[8])
1156 snprintf(out, out_size, MSG_ARG_INVALID,
1161 if (softnic_cryptodev_create(softnic, name, ¶ms) == NULL) {
1162 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1168 * port in action profile <profile_name>
1169 * [filter match | mismatch offset <key_offset> mask <key_mask> key <key_value> port <port_id>]
1170 * [balance offset <key_offset> mask <key_mask> port <port_id0> ... <port_id15>]
1173 cmd_port_in_action_profile(struct pmd_internals *softnic,
1179 struct softnic_port_in_action_profile_params p;
1180 struct softnic_port_in_action_profile *ap;
1184 memset(&p, 0, sizeof(p));
1187 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1191 if (strcmp(tokens[1], "in") != 0) {
1192 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1196 if (strcmp(tokens[2], "action") != 0) {
1197 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
1201 if (strcmp(tokens[3], "profile") != 0) {
1202 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
1210 if (t0 < n_tokens &&
1211 (strcmp(tokens[t0], "filter") == 0)) {
1214 if (n_tokens < t0 + 10) {
1215 snprintf(out, out_size, MSG_ARG_MISMATCH, "port in action profile filter");
1219 if (strcmp(tokens[t0 + 1], "match") == 0) {
1220 p.fltr.filter_on_match = 1;
1221 } else if (strcmp(tokens[t0 + 1], "mismatch") == 0) {
1222 p.fltr.filter_on_match = 0;
1224 snprintf(out, out_size, MSG_ARG_INVALID, "match or mismatch");
1228 if (strcmp(tokens[t0 + 2], "offset") != 0) {
1229 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1233 if (softnic_parser_read_uint32(&p.fltr.key_offset,
1234 tokens[t0 + 3]) != 0) {
1235 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1239 if (strcmp(tokens[t0 + 4], "mask") != 0) {
1240 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
1244 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
1245 if ((softnic_parse_hex_string(tokens[t0 + 5],
1246 p.fltr.key_mask, &size) != 0) ||
1247 size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE) {
1248 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1252 if (strcmp(tokens[t0 + 6], "key") != 0) {
1253 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
1257 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
1258 if ((softnic_parse_hex_string(tokens[t0 + 7],
1259 p.fltr.key, &size) != 0) ||
1260 size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE) {
1261 snprintf(out, out_size, MSG_ARG_INVALID, "key_value");
1265 if (strcmp(tokens[t0 + 8], "port") != 0) {
1266 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1270 if (softnic_parser_read_uint32(&p.fltr.port_id,
1271 tokens[t0 + 9]) != 0) {
1272 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
1276 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_FLTR;
1280 if (t0 < n_tokens &&
1281 (strcmp(tokens[t0], "balance") == 0)) {
1284 if (n_tokens < t0 + 22) {
1285 snprintf(out, out_size, MSG_ARG_MISMATCH,
1286 "port in action profile balance");
1290 if (strcmp(tokens[t0 + 1], "offset") != 0) {
1291 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1295 if (softnic_parser_read_uint32(&p.lb.key_offset,
1296 tokens[t0 + 2]) != 0) {
1297 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1301 if (strcmp(tokens[t0 + 3], "mask") != 0) {
1302 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
1306 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
1307 if (softnic_parse_hex_string(tokens[t0 + 4],
1308 p.lb.key_mask, &p.lb.key_size) != 0) {
1309 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1313 if (strcmp(tokens[t0 + 5], "port") != 0) {
1314 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1318 for (i = 0; i < 16; i++)
1319 if (softnic_parser_read_uint32(&p.lb.port_id[i],
1320 tokens[t0 + 6 + i]) != 0) {
1321 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
1325 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_LB;
1329 if (t0 < n_tokens) {
1330 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1334 ap = softnic_port_in_action_profile_create(softnic, name, &p);
1336 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1342 * table action profile <profile_name>
1344 * offset <ip_offset>
1346 * [balance offset <key_offset> mask <key_mask> outoffset <out_offset>]
1347 * [meter srtcm | trtcm
1349 * stats none | pkts | bytes | both]
1350 * [tm spp <n_subports_per_port> pps <n_pipes_per_subport>]
1351 * [encap ether | vlan | qinq | mpls | pppoe |
1352 * vxlan offset <ether_offset> ipv4 | ipv6 vlan on | off]
1356 * stats none | pkts]
1357 * [stats pkts | bytes | both]
1364 cmd_table_action_profile(struct pmd_internals *softnic,
1370 struct softnic_table_action_profile_params p;
1371 struct softnic_table_action_profile *ap;
1375 memset(&p, 0, sizeof(p));
1378 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1382 if (strcmp(tokens[1], "action") != 0) {
1383 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
1387 if (strcmp(tokens[2], "profile") != 0) {
1388 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
1394 if (strcmp(tokens[4], "ipv4") == 0) {
1395 p.common.ip_version = 1;
1396 } else if (strcmp(tokens[4], "ipv6") == 0) {
1397 p.common.ip_version = 0;
1399 snprintf(out, out_size, MSG_ARG_INVALID, "ipv4 or ipv6");
1403 if (strcmp(tokens[5], "offset") != 0) {
1404 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1408 if (softnic_parser_read_uint32(&p.common.ip_offset,
1410 snprintf(out, out_size, MSG_ARG_INVALID, "ip_offset");
1414 if (strcmp(tokens[7], "fwd") != 0) {
1415 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fwd");
1419 p.action_mask |= 1LLU << RTE_TABLE_ACTION_FWD;
1422 if (t0 < n_tokens &&
1423 (strcmp(tokens[t0], "balance") == 0)) {
1424 if (n_tokens < t0 + 7) {
1425 snprintf(out, out_size, MSG_ARG_MISMATCH, "table action profile balance");
1429 if (strcmp(tokens[t0 + 1], "offset") != 0) {
1430 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1434 if (softnic_parser_read_uint32(&p.lb.key_offset,
1435 tokens[t0 + 2]) != 0) {
1436 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1440 if (strcmp(tokens[t0 + 3], "mask") != 0) {
1441 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
1445 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
1446 if (softnic_parse_hex_string(tokens[t0 + 4],
1447 p.lb.key_mask, &p.lb.key_size) != 0) {
1448 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1452 if (strcmp(tokens[t0 + 5], "outoffset") != 0) {
1453 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "outoffset");
1457 if (softnic_parser_read_uint32(&p.lb.out_offset,
1458 tokens[t0 + 6]) != 0) {
1459 snprintf(out, out_size, MSG_ARG_INVALID, "out_offset");
1463 p.action_mask |= 1LLU << RTE_TABLE_ACTION_LB;
1467 if (t0 < n_tokens &&
1468 (strcmp(tokens[t0], "meter") == 0)) {
1469 if (n_tokens < t0 + 6) {
1470 snprintf(out, out_size, MSG_ARG_MISMATCH,
1471 "table action profile meter");
1475 if (strcmp(tokens[t0 + 1], "srtcm") == 0) {
1476 p.mtr.alg = RTE_TABLE_ACTION_METER_SRTCM;
1477 } else if (strcmp(tokens[t0 + 1], "trtcm") == 0) {
1478 p.mtr.alg = RTE_TABLE_ACTION_METER_TRTCM;
1480 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1485 if (strcmp(tokens[t0 + 2], "tc") != 0) {
1486 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc");
1490 if (softnic_parser_read_uint32(&p.mtr.n_tc,
1491 tokens[t0 + 3]) != 0) {
1492 snprintf(out, out_size, MSG_ARG_INVALID, "n_tc");
1496 if (strcmp(tokens[t0 + 4], "stats") != 0) {
1497 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1501 if (strcmp(tokens[t0 + 5], "none") == 0) {
1502 p.mtr.n_packets_enabled = 0;
1503 p.mtr.n_bytes_enabled = 0;
1504 } else if (strcmp(tokens[t0 + 5], "pkts") == 0) {
1505 p.mtr.n_packets_enabled = 1;
1506 p.mtr.n_bytes_enabled = 0;
1507 } else if (strcmp(tokens[t0 + 5], "bytes") == 0) {
1508 p.mtr.n_packets_enabled = 0;
1509 p.mtr.n_bytes_enabled = 1;
1510 } else if (strcmp(tokens[t0 + 5], "both") == 0) {
1511 p.mtr.n_packets_enabled = 1;
1512 p.mtr.n_bytes_enabled = 1;
1514 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1515 "none or pkts or bytes or both");
1519 p.action_mask |= 1LLU << RTE_TABLE_ACTION_MTR;
1523 if (t0 < n_tokens &&
1524 (strcmp(tokens[t0], "tm") == 0)) {
1525 if (n_tokens < t0 + 5) {
1526 snprintf(out, out_size, MSG_ARG_MISMATCH,
1527 "table action profile tm");
1531 if (strcmp(tokens[t0 + 1], "spp") != 0) {
1532 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
1536 if (softnic_parser_read_uint32(&p.tm.n_subports_per_port,
1537 tokens[t0 + 2]) != 0) {
1538 snprintf(out, out_size, MSG_ARG_INVALID,
1539 "n_subports_per_port");
1543 if (strcmp(tokens[t0 + 3], "pps") != 0) {
1544 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
1548 if (softnic_parser_read_uint32(&p.tm.n_pipes_per_subport,
1549 tokens[t0 + 4]) != 0) {
1550 snprintf(out, out_size, MSG_ARG_INVALID,
1551 "n_pipes_per_subport");
1555 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TM;
1559 if (t0 < n_tokens &&
1560 (strcmp(tokens[t0], "encap") == 0)) {
1561 uint32_t n_extra_tokens = 0;
1563 if (n_tokens < t0 + 2) {
1564 snprintf(out, out_size, MSG_ARG_MISMATCH,
1565 "action profile encap");
1569 if (strcmp(tokens[t0 + 1], "ether") == 0) {
1570 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_ETHER;
1571 } else if (strcmp(tokens[t0 + 1], "vlan") == 0) {
1572 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VLAN;
1573 } else if (strcmp(tokens[t0 + 1], "qinq") == 0) {
1574 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ;
1575 } else if (strcmp(tokens[t0 + 1], "mpls") == 0) {
1576 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_MPLS;
1577 } else if (strcmp(tokens[t0 + 1], "pppoe") == 0) {
1578 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_PPPOE;
1579 } else if (strcmp(tokens[t0 + 1], "vxlan") == 0) {
1580 if (n_tokens < t0 + 2 + 5) {
1581 snprintf(out, out_size, MSG_ARG_MISMATCH,
1582 "action profile encap vxlan");
1586 if (strcmp(tokens[t0 + 2], "offset") != 0) {
1587 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1592 if (softnic_parser_read_uint32(&p.encap.vxlan.data_offset,
1593 tokens[t0 + 2 + 1]) != 0) {
1594 snprintf(out, out_size, MSG_ARG_INVALID,
1595 "vxlan: ether_offset");
1599 if (strcmp(tokens[t0 + 2 + 2], "ipv4") == 0)
1600 p.encap.vxlan.ip_version = 1;
1601 else if (strcmp(tokens[t0 + 2 + 2], "ipv6") == 0)
1602 p.encap.vxlan.ip_version = 0;
1604 snprintf(out, out_size, MSG_ARG_INVALID,
1605 "vxlan: ipv4 or ipv6");
1609 if (strcmp(tokens[t0 + 2 + 3], "vlan") != 0) {
1610 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1615 if (strcmp(tokens[t0 + 2 + 4], "on") == 0)
1616 p.encap.vxlan.vlan = 1;
1617 else if (strcmp(tokens[t0 + 2 + 4], "off") == 0)
1618 p.encap.vxlan.vlan = 0;
1620 snprintf(out, out_size, MSG_ARG_INVALID,
1621 "vxlan: on or off");
1625 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VXLAN;
1629 snprintf(out, out_size, MSG_ARG_MISMATCH, "encap");
1632 p.action_mask |= 1LLU << RTE_TABLE_ACTION_ENCAP;
1633 t0 += 2 + n_extra_tokens;
1636 if (t0 < n_tokens &&
1637 (strcmp(tokens[t0], "nat") == 0)) {
1638 if (n_tokens < t0 + 4) {
1639 snprintf(out, out_size, MSG_ARG_MISMATCH,
1640 "table action profile nat");
1644 if (strcmp(tokens[t0 + 1], "src") == 0) {
1645 p.nat.source_nat = 1;
1646 } else if (strcmp(tokens[t0 + 1], "dst") == 0) {
1647 p.nat.source_nat = 0;
1649 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1654 if (strcmp(tokens[t0 + 2], "proto") != 0) {
1655 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "proto");
1659 if (strcmp(tokens[t0 + 3], "tcp") == 0) {
1661 } else if (strcmp(tokens[t0 + 3], "udp") == 0) {
1664 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1669 p.action_mask |= 1LLU << RTE_TABLE_ACTION_NAT;
1673 if (t0 < n_tokens &&
1674 (strcmp(tokens[t0], "ttl") == 0)) {
1675 if (n_tokens < t0 + 4) {
1676 snprintf(out, out_size, MSG_ARG_MISMATCH,
1677 "table action profile ttl");
1681 if (strcmp(tokens[t0 + 1], "drop") == 0) {
1683 } else if (strcmp(tokens[t0 + 1], "fwd") == 0) {
1686 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1691 if (strcmp(tokens[t0 + 2], "stats") != 0) {
1692 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1696 if (strcmp(tokens[t0 + 3], "none") == 0) {
1697 p.ttl.n_packets_enabled = 0;
1698 } else if (strcmp(tokens[t0 + 3], "pkts") == 0) {
1699 p.ttl.n_packets_enabled = 1;
1701 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1706 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TTL;
1710 if (t0 < n_tokens &&
1711 (strcmp(tokens[t0], "stats") == 0)) {
1712 if (n_tokens < t0 + 2) {
1713 snprintf(out, out_size, MSG_ARG_MISMATCH,
1714 "table action profile stats");
1718 if (strcmp(tokens[t0 + 1], "pkts") == 0) {
1719 p.stats.n_packets_enabled = 1;
1720 p.stats.n_bytes_enabled = 0;
1721 } else if (strcmp(tokens[t0 + 1], "bytes") == 0) {
1722 p.stats.n_packets_enabled = 0;
1723 p.stats.n_bytes_enabled = 1;
1724 } else if (strcmp(tokens[t0 + 1], "both") == 0) {
1725 p.stats.n_packets_enabled = 1;
1726 p.stats.n_bytes_enabled = 1;
1728 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1729 "pkts or bytes or both");
1733 p.action_mask |= 1LLU << RTE_TABLE_ACTION_STATS;
1737 if (t0 < n_tokens &&
1738 (strcmp(tokens[t0], "time") == 0)) {
1739 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TIME;
1743 if (t0 < n_tokens &&
1744 (strcmp(tokens[t0], "tag") == 0)) {
1745 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TAG;
1749 if (t0 < n_tokens &&
1750 (strcmp(tokens[t0], "decap") == 0)) {
1751 p.action_mask |= 1LLU << RTE_TABLE_ACTION_DECAP;
1755 if (t0 < n_tokens && (strcmp(tokens[t0], "sym_crypto") == 0)) {
1756 struct softnic_cryptodev *cryptodev;
1758 if (n_tokens < t0 + 5 ||
1759 strcmp(tokens[t0 + 1], "dev") ||
1760 strcmp(tokens[t0 + 3], "offset")) {
1761 snprintf(out, out_size, MSG_ARG_MISMATCH,
1762 "table action profile sym_crypto");
1766 cryptodev = softnic_cryptodev_find(softnic, tokens[t0 + 2]);
1767 if (cryptodev == NULL) {
1768 snprintf(out, out_size, MSG_ARG_INVALID,
1769 "table action profile sym_crypto");
1773 p.sym_crypto.cryptodev_id = cryptodev->dev_id;
1775 if (softnic_parser_read_uint32(&p.sym_crypto.op_offset,
1776 tokens[t0 + 4]) != 0) {
1777 snprintf(out, out_size, MSG_ARG_INVALID,
1778 "table action profile sym_crypto");
1782 p.sym_crypto.mp_create = cryptodev->mp_create;
1783 p.sym_crypto.mp_init = cryptodev->mp_init;
1785 p.action_mask |= 1LLU << RTE_TABLE_ACTION_SYM_CRYPTO;
1790 if (t0 < n_tokens) {
1791 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1795 ap = softnic_table_action_profile_create(softnic, name, &p);
1797 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1803 * pipeline <pipeline_name>
1804 * period <timer_period_ms>
1805 * offset_port_id <offset_port_id>
1808 cmd_pipeline(struct pmd_internals *softnic,
1814 struct pipeline_params p;
1816 struct pipeline *pipeline;
1818 if (n_tokens != 6) {
1819 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1825 if (strcmp(tokens[2], "period") != 0) {
1826 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "period");
1830 if (softnic_parser_read_uint32(&p.timer_period_ms,
1832 snprintf(out, out_size, MSG_ARG_INVALID, "timer_period_ms");
1836 if (strcmp(tokens[4], "offset_port_id") != 0) {
1837 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset_port_id");
1841 if (softnic_parser_read_uint32(&p.offset_port_id,
1843 snprintf(out, out_size, MSG_ARG_INVALID, "offset_port_id");
1847 pipeline = softnic_pipeline_create(softnic, name, &p);
1848 if (pipeline == NULL) {
1849 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1855 * pipeline <pipeline_name> port in
1857 * link <link_name> rxq <queue_id>
1859 * | tmgr <tmgr_name>
1860 * | tap <tap_name> mempool <mempool_name> mtu <mtu>
1861 * | source mempool <mempool_name> file <file_name> bpp <n_bytes_per_pkt>
1862 * | cryptodev <cryptodev_name> rxq <queue_id>
1863 * [action <port_in_action_profile_name>]
1867 cmd_pipeline_port_in(struct pmd_internals *softnic,
1873 struct softnic_port_in_params p;
1874 char *pipeline_name;
1876 int enabled, status;
1878 memset(&p, 0, sizeof(p));
1881 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1885 pipeline_name = tokens[1];
1887 if (strcmp(tokens[2], "port") != 0) {
1888 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1892 if (strcmp(tokens[3], "in") != 0) {
1893 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1897 if (strcmp(tokens[4], "bsz") != 0) {
1898 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1902 if (softnic_parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1903 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1909 if (strcmp(tokens[t0], "link") == 0) {
1910 if (n_tokens < t0 + 4) {
1911 snprintf(out, out_size, MSG_ARG_MISMATCH,
1912 "pipeline port in link");
1916 p.type = PORT_IN_RXQ;
1918 strlcpy(p.dev_name, tokens[t0 + 1], sizeof(p.dev_name));
1920 if (strcmp(tokens[t0 + 2], "rxq") != 0) {
1921 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
1925 if (softnic_parser_read_uint16(&p.rxq.queue_id,
1926 tokens[t0 + 3]) != 0) {
1927 snprintf(out, out_size, MSG_ARG_INVALID,
1932 } else if (strcmp(tokens[t0], "swq") == 0) {
1933 if (n_tokens < t0 + 2) {
1934 snprintf(out, out_size, MSG_ARG_MISMATCH,
1935 "pipeline port in swq");
1939 p.type = PORT_IN_SWQ;
1941 strlcpy(p.dev_name, tokens[t0 + 1], sizeof(p.dev_name));
1944 } else if (strcmp(tokens[t0], "tmgr") == 0) {
1945 if (n_tokens < t0 + 2) {
1946 snprintf(out, out_size, MSG_ARG_MISMATCH,
1947 "pipeline port in tmgr");
1951 p.type = PORT_IN_TMGR;
1953 strlcpy(p.dev_name, tokens[t0 + 1], sizeof(p.dev_name));
1956 } else if (strcmp(tokens[t0], "tap") == 0) {
1957 if (n_tokens < t0 + 6) {
1958 snprintf(out, out_size, MSG_ARG_MISMATCH,
1959 "pipeline port in tap");
1963 p.type = PORT_IN_TAP;
1965 strlcpy(p.dev_name, tokens[t0 + 1], sizeof(p.dev_name));
1967 if (strcmp(tokens[t0 + 2], "mempool") != 0) {
1968 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1973 p.tap.mempool_name = tokens[t0 + 3];
1975 if (strcmp(tokens[t0 + 4], "mtu") != 0) {
1976 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1981 if (softnic_parser_read_uint32(&p.tap.mtu,
1982 tokens[t0 + 5]) != 0) {
1983 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
1988 } else if (strcmp(tokens[t0], "source") == 0) {
1989 if (n_tokens < t0 + 6) {
1990 snprintf(out, out_size, MSG_ARG_MISMATCH,
1991 "pipeline port in source");
1995 p.type = PORT_IN_SOURCE;
1997 if (strcmp(tokens[t0 + 1], "mempool") != 0) {
1998 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2003 p.source.mempool_name = tokens[t0 + 2];
2005 if (strcmp(tokens[t0 + 3], "file") != 0) {
2006 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2011 p.source.file_name = tokens[t0 + 4];
2013 if (strcmp(tokens[t0 + 5], "bpp") != 0) {
2014 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2019 if (softnic_parser_read_uint32(&p.source.n_bytes_per_pkt,
2020 tokens[t0 + 6]) != 0) {
2021 snprintf(out, out_size, MSG_ARG_INVALID,
2027 } else if (strcmp(tokens[t0], "cryptodev") == 0) {
2028 if (n_tokens < t0 + 3) {
2029 snprintf(out, out_size, MSG_ARG_MISMATCH,
2030 "pipeline port in cryptodev");
2034 p.type = PORT_IN_CRYPTODEV;
2036 strlcpy(p.dev_name, tokens[t0 + 1], sizeof(p.dev_name));
2037 if (softnic_parser_read_uint16(&p.rxq.queue_id,
2038 tokens[t0 + 3]) != 0) {
2039 snprintf(out, out_size, MSG_ARG_INVALID,
2044 p.cryptodev.arg_callback = NULL;
2045 p.cryptodev.f_callback = NULL;
2049 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
2053 if (n_tokens > t0 &&
2054 (strcmp(tokens[t0], "action") == 0)) {
2055 if (n_tokens < t0 + 2) {
2056 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
2060 strlcpy(p.action_profile_name, tokens[t0 + 1],
2061 sizeof(p.action_profile_name));
2067 if (n_tokens > t0 &&
2068 (strcmp(tokens[t0], "disabled") == 0)) {
2074 if (n_tokens != t0) {
2075 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2079 status = softnic_pipeline_port_in_create(softnic,
2084 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2090 * pipeline <pipeline_name> port out
2092 * link <link_name> txq <txq_id>
2094 * | tmgr <tmgr_name>
2096 * | sink [file <file_name> pkts <max_n_pkts>]
2097 * | cryptodev <cryptodev_name> txq <txq_id> offset <crypto_op_offset>
2100 cmd_pipeline_port_out(struct pmd_internals *softnic,
2106 struct softnic_port_out_params p;
2107 char *pipeline_name;
2110 memset(&p, 0, sizeof(p));
2113 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2117 pipeline_name = tokens[1];
2119 if (strcmp(tokens[2], "port") != 0) {
2120 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2124 if (strcmp(tokens[3], "out") != 0) {
2125 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
2129 if (strcmp(tokens[4], "bsz") != 0) {
2130 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
2134 if (softnic_parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
2135 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
2139 if (strcmp(tokens[6], "link") == 0) {
2140 if (n_tokens != 10) {
2141 snprintf(out, out_size, MSG_ARG_MISMATCH,
2142 "pipeline port out link");
2146 p.type = PORT_OUT_TXQ;
2148 strlcpy(p.dev_name, tokens[7], sizeof(p.dev_name));
2150 if (strcmp(tokens[8], "txq") != 0) {
2151 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
2155 if (softnic_parser_read_uint16(&p.txq.queue_id,
2157 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
2160 } else if (strcmp(tokens[6], "swq") == 0) {
2161 if (n_tokens != 8) {
2162 snprintf(out, out_size, MSG_ARG_MISMATCH,
2163 "pipeline port out swq");
2167 p.type = PORT_OUT_SWQ;
2169 strlcpy(p.dev_name, tokens[7], sizeof(p.dev_name));
2170 } else if (strcmp(tokens[6], "tmgr") == 0) {
2171 if (n_tokens != 8) {
2172 snprintf(out, out_size, MSG_ARG_MISMATCH,
2173 "pipeline port out tmgr");
2177 p.type = PORT_OUT_TMGR;
2179 strlcpy(p.dev_name, tokens[7], sizeof(p.dev_name));
2180 } else if (strcmp(tokens[6], "tap") == 0) {
2181 if (n_tokens != 8) {
2182 snprintf(out, out_size, MSG_ARG_MISMATCH,
2183 "pipeline port out tap");
2187 p.type = PORT_OUT_TAP;
2189 strlcpy(p.dev_name, tokens[7], sizeof(p.dev_name));
2190 } else if (strcmp(tokens[6], "sink") == 0) {
2191 if ((n_tokens != 7) && (n_tokens != 11)) {
2192 snprintf(out, out_size, MSG_ARG_MISMATCH,
2193 "pipeline port out sink");
2197 p.type = PORT_OUT_SINK;
2199 if (n_tokens == 7) {
2200 p.sink.file_name = NULL;
2201 p.sink.max_n_pkts = 0;
2203 if (strcmp(tokens[7], "file") != 0) {
2204 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2209 p.sink.file_name = tokens[8];
2211 if (strcmp(tokens[9], "pkts") != 0) {
2212 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pkts");
2216 if (softnic_parser_read_uint32(&p.sink.max_n_pkts,
2218 snprintf(out, out_size, MSG_ARG_INVALID, "max_n_pkts");
2222 } else if (strcmp(tokens[6], "cryptodev") == 0) {
2223 if (n_tokens != 12) {
2224 snprintf(out, out_size, MSG_ARG_MISMATCH,
2225 "pipeline port out cryptodev");
2229 p.type = PORT_OUT_CRYPTODEV;
2231 strlcpy(p.dev_name, tokens[7], sizeof(p.dev_name));
2233 if (strcmp(tokens[8], "txq")) {
2234 snprintf(out, out_size, MSG_ARG_MISMATCH,
2235 "pipeline port out cryptodev");
2239 if (softnic_parser_read_uint16(&p.cryptodev.queue_id, tokens[9])
2241 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
2245 if (strcmp(tokens[10], "offset")) {
2246 snprintf(out, out_size, MSG_ARG_MISMATCH,
2247 "pipeline port out cryptodev");
2251 if (softnic_parser_read_uint32(&p.cryptodev.op_offset,
2253 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
2257 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
2261 status = softnic_pipeline_port_out_create(softnic, pipeline_name, &p);
2263 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2269 * pipeline <pipeline_name> table
2273 * offset <ip_header_offset>
2276 * offset <key_offset>
2282 * offset <key_offset>
2283 * buckets <n_buckets>
2287 * offset <ip_header_offset>
2290 * [action <table_action_profile_name>]
2293 cmd_pipeline_table(struct pmd_internals *softnic,
2299 struct softnic_table_params p;
2300 char *pipeline_name;
2304 memset(&p, 0, sizeof(p));
2307 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2311 pipeline_name = tokens[1];
2313 if (strcmp(tokens[2], "table") != 0) {
2314 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2318 if (strcmp(tokens[3], "match") != 0) {
2319 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
2324 if (strcmp(tokens[t0], "acl") == 0) {
2325 if (n_tokens < t0 + 6) {
2326 snprintf(out, out_size, MSG_ARG_MISMATCH,
2327 "pipeline table acl");
2331 p.match_type = TABLE_ACL;
2333 if (strcmp(tokens[t0 + 1], "ipv4") == 0) {
2334 p.match.acl.ip_version = 1;
2335 } else if (strcmp(tokens[t0 + 1], "ipv6") == 0) {
2336 p.match.acl.ip_version = 0;
2338 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2343 if (strcmp(tokens[t0 + 2], "offset") != 0) {
2344 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2348 if (softnic_parser_read_uint32(&p.match.acl.ip_header_offset,
2349 tokens[t0 + 3]) != 0) {
2350 snprintf(out, out_size, MSG_ARG_INVALID,
2351 "ip_header_offset");
2355 if (strcmp(tokens[t0 + 4], "size") != 0) {
2356 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2360 if (softnic_parser_read_uint32(&p.match.acl.n_rules,
2361 tokens[t0 + 5]) != 0) {
2362 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2367 } else if (strcmp(tokens[t0], "array") == 0) {
2368 if (n_tokens < t0 + 5) {
2369 snprintf(out, out_size, MSG_ARG_MISMATCH,
2370 "pipeline table array");
2374 p.match_type = TABLE_ARRAY;
2376 if (strcmp(tokens[t0 + 1], "offset") != 0) {
2377 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2381 if (softnic_parser_read_uint32(&p.match.array.key_offset,
2382 tokens[t0 + 2]) != 0) {
2383 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2387 if (strcmp(tokens[t0 + 3], "size") != 0) {
2388 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2392 if (softnic_parser_read_uint32(&p.match.array.n_keys,
2393 tokens[t0 + 4]) != 0) {
2394 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2399 } else if (strcmp(tokens[t0], "hash") == 0) {
2400 uint32_t key_mask_size = TABLE_RULE_MATCH_SIZE_MAX;
2402 if (n_tokens < t0 + 12) {
2403 snprintf(out, out_size, MSG_ARG_MISMATCH,
2404 "pipeline table hash");
2408 p.match_type = TABLE_HASH;
2410 if (strcmp(tokens[t0 + 1], "ext") == 0) {
2411 p.match.hash.extendable_bucket = 1;
2412 } else if (strcmp(tokens[t0 + 1], "lru") == 0) {
2413 p.match.hash.extendable_bucket = 0;
2415 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2420 if (strcmp(tokens[t0 + 2], "key") != 0) {
2421 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
2425 if ((softnic_parser_read_uint32(&p.match.hash.key_size,
2426 tokens[t0 + 3]) != 0) ||
2427 p.match.hash.key_size == 0 ||
2428 p.match.hash.key_size > TABLE_RULE_MATCH_SIZE_MAX) {
2429 snprintf(out, out_size, MSG_ARG_INVALID, "key_size");
2433 if (strcmp(tokens[t0 + 4], "mask") != 0) {
2434 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
2438 if ((softnic_parse_hex_string(tokens[t0 + 5],
2439 p.match.hash.key_mask, &key_mask_size) != 0) ||
2440 key_mask_size != p.match.hash.key_size) {
2441 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
2445 if (strcmp(tokens[t0 + 6], "offset") != 0) {
2446 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2450 if (softnic_parser_read_uint32(&p.match.hash.key_offset,
2451 tokens[t0 + 7]) != 0) {
2452 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2456 if (strcmp(tokens[t0 + 8], "buckets") != 0) {
2457 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buckets");
2461 if (softnic_parser_read_uint32(&p.match.hash.n_buckets,
2462 tokens[t0 + 9]) != 0) {
2463 snprintf(out, out_size, MSG_ARG_INVALID, "n_buckets");
2467 if (strcmp(tokens[t0 + 10], "size") != 0) {
2468 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2472 if (softnic_parser_read_uint32(&p.match.hash.n_keys,
2473 tokens[t0 + 11]) != 0) {
2474 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2479 } else if (strcmp(tokens[t0], "lpm") == 0) {
2480 if (n_tokens < t0 + 6) {
2481 snprintf(out, out_size, MSG_ARG_MISMATCH,
2482 "pipeline table lpm");
2486 p.match_type = TABLE_LPM;
2488 if (strcmp(tokens[t0 + 1], "ipv4") == 0) {
2489 p.match.lpm.key_size = 4;
2490 } else if (strcmp(tokens[t0 + 1], "ipv6") == 0) {
2491 p.match.lpm.key_size = 16;
2493 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2498 if (strcmp(tokens[t0 + 2], "offset") != 0) {
2499 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2503 if (softnic_parser_read_uint32(&p.match.lpm.key_offset,
2504 tokens[t0 + 3]) != 0) {
2505 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2509 if (strcmp(tokens[t0 + 4], "size") != 0) {
2510 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2514 if (softnic_parser_read_uint32(&p.match.lpm.n_rules,
2515 tokens[t0 + 5]) != 0) {
2516 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2521 } else if (strcmp(tokens[t0], "stub") == 0) {
2522 p.match_type = TABLE_STUB;
2526 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
2530 if (n_tokens > t0 &&
2531 (strcmp(tokens[t0], "action") == 0)) {
2532 if (n_tokens < t0 + 2) {
2533 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
2537 strlcpy(p.action_profile_name, tokens[t0 + 1],
2538 sizeof(p.action_profile_name));
2543 if (n_tokens > t0) {
2544 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2548 status = softnic_pipeline_table_create(softnic, pipeline_name, &p);
2550 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2556 * pipeline <pipeline_name> port in <port_id> table <table_id>
2559 cmd_pipeline_port_in_table(struct pmd_internals *softnic,
2565 char *pipeline_name;
2566 uint32_t port_id, table_id;
2569 if (n_tokens != 7) {
2570 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2574 pipeline_name = tokens[1];
2576 if (strcmp(tokens[2], "port") != 0) {
2577 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2581 if (strcmp(tokens[3], "in") != 0) {
2582 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2586 if (softnic_parser_read_uint32(&port_id, tokens[4]) != 0) {
2587 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2591 if (strcmp(tokens[5], "table") != 0) {
2592 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2596 if (softnic_parser_read_uint32(&table_id, tokens[6]) != 0) {
2597 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2601 status = softnic_pipeline_port_in_connect_to_table(softnic,
2606 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2612 * pipeline <pipeline_name> port in <port_id> stats read [clear]
2615 #define MSG_PIPELINE_PORT_IN_STATS \
2616 "Pkts in: %" PRIu64 "\n" \
2617 "Pkts dropped by AH: %" PRIu64 "\n" \
2618 "Pkts dropped by other: %" PRIu64 "\n"
2621 cmd_pipeline_port_in_stats(struct pmd_internals *softnic,
2627 struct rte_pipeline_port_in_stats stats;
2628 char *pipeline_name;
2632 if (n_tokens != 7 &&
2634 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2638 pipeline_name = tokens[1];
2640 if (strcmp(tokens[2], "port") != 0) {
2641 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2645 if (strcmp(tokens[3], "in") != 0) {
2646 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2650 if (softnic_parser_read_uint32(&port_id, tokens[4]) != 0) {
2651 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2655 if (strcmp(tokens[5], "stats") != 0) {
2656 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2660 if (strcmp(tokens[6], "read") != 0) {
2661 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2666 if (n_tokens == 8) {
2667 if (strcmp(tokens[7], "clear") != 0) {
2668 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2675 status = softnic_pipeline_port_in_stats_read(softnic,
2681 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2685 snprintf(out, out_size, MSG_PIPELINE_PORT_IN_STATS,
2686 stats.stats.n_pkts_in,
2687 stats.n_pkts_dropped_by_ah,
2688 stats.stats.n_pkts_drop);
2692 * pipeline <pipeline_name> port in <port_id> enable
2695 cmd_softnic_pipeline_port_in_enable(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], "enable") != 0) {
2728 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
2732 status = softnic_pipeline_port_in_enable(softnic, pipeline_name, port_id);
2734 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2740 * pipeline <pipeline_name> port in <port_id> disable
2743 cmd_softnic_pipeline_port_in_disable(struct pmd_internals *softnic,
2749 char *pipeline_name;
2753 if (n_tokens != 6) {
2754 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2758 pipeline_name = tokens[1];
2760 if (strcmp(tokens[2], "port") != 0) {
2761 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2765 if (strcmp(tokens[3], "in") != 0) {
2766 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2770 if (softnic_parser_read_uint32(&port_id, tokens[4]) != 0) {
2771 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2775 if (strcmp(tokens[5], "disable") != 0) {
2776 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
2780 status = softnic_pipeline_port_in_disable(softnic, pipeline_name, port_id);
2782 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2788 * pipeline <pipeline_name> port out <port_id> stats read [clear]
2790 #define MSG_PIPELINE_PORT_OUT_STATS \
2791 "Pkts in: %" PRIu64 "\n" \
2792 "Pkts dropped by AH: %" PRIu64 "\n" \
2793 "Pkts dropped by other: %" PRIu64 "\n"
2796 cmd_pipeline_port_out_stats(struct pmd_internals *softnic,
2802 struct rte_pipeline_port_out_stats stats;
2803 char *pipeline_name;
2807 if (n_tokens != 7 &&
2809 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2813 pipeline_name = tokens[1];
2815 if (strcmp(tokens[2], "port") != 0) {
2816 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2820 if (strcmp(tokens[3], "out") != 0) {
2821 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
2825 if (softnic_parser_read_uint32(&port_id, tokens[4]) != 0) {
2826 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2830 if (strcmp(tokens[5], "stats") != 0) {
2831 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2835 if (strcmp(tokens[6], "read") != 0) {
2836 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2841 if (n_tokens == 8) {
2842 if (strcmp(tokens[7], "clear") != 0) {
2843 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2850 status = softnic_pipeline_port_out_stats_read(softnic,
2856 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2860 snprintf(out, out_size, MSG_PIPELINE_PORT_OUT_STATS,
2861 stats.stats.n_pkts_in,
2862 stats.n_pkts_dropped_by_ah,
2863 stats.stats.n_pkts_drop);
2867 * pipeline <pipeline_name> table <table_id> stats read [clear]
2869 #define MSG_PIPELINE_TABLE_STATS \
2870 "Pkts in: %" PRIu64 "\n" \
2871 "Pkts in with lookup miss: %" PRIu64 "\n" \
2872 "Pkts in with lookup hit dropped by AH: %" PRIu64 "\n" \
2873 "Pkts in with lookup hit dropped by others: %" PRIu64 "\n" \
2874 "Pkts in with lookup miss dropped by AH: %" PRIu64 "\n" \
2875 "Pkts in with lookup miss dropped by others: %" PRIu64 "\n"
2878 cmd_pipeline_table_stats(struct pmd_internals *softnic,
2884 struct rte_pipeline_table_stats stats;
2885 char *pipeline_name;
2889 if (n_tokens != 6 &&
2891 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2895 pipeline_name = tokens[1];
2897 if (strcmp(tokens[2], "table") != 0) {
2898 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2902 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
2903 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2907 if (strcmp(tokens[4], "stats") != 0) {
2908 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2912 if (strcmp(tokens[5], "read") != 0) {
2913 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2918 if (n_tokens == 7) {
2919 if (strcmp(tokens[6], "clear") != 0) {
2920 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2927 status = softnic_pipeline_table_stats_read(softnic,
2933 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2937 snprintf(out, out_size, MSG_PIPELINE_TABLE_STATS,
2938 stats.stats.n_pkts_in,
2939 stats.stats.n_pkts_lookup_miss,
2940 stats.n_pkts_dropped_by_lkp_hit_ah,
2941 stats.n_pkts_dropped_lkp_hit,
2942 stats.n_pkts_dropped_by_lkp_miss_ah,
2943 stats.n_pkts_dropped_lkp_miss);
2951 * priority <priority>
2952 * ipv4 | ipv6 <sa> <sa_depth> <da> <da_depth>
2953 * <sp0> <sp1> <dp0> <dp1> <proto>
2957 * | ipv4_5tuple <sa> <da> <sp> <dp> <proto>
2958 * | ipv6_5tuple <sa> <da> <sp> <dp> <proto>
2959 * | ipv4_addr <addr>
2960 * | ipv6_addr <addr>
2961 * | qinq <svlan> <cvlan>
2963 * ipv4 | ipv6 <addr> <depth>
2965 struct pkt_key_qinq {
2966 uint16_t ethertype_svlan;
2968 uint16_t ethertype_cvlan;
2970 } __attribute__((__packed__));
2972 struct pkt_key_ipv4_5tuple {
2973 uint8_t time_to_live;
2975 uint16_t hdr_checksum;
2980 } __attribute__((__packed__));
2982 struct pkt_key_ipv6_5tuple {
2983 uint16_t payload_length;
2990 } __attribute__((__packed__));
2992 struct pkt_key_ipv4_addr {
2994 } __attribute__((__packed__));
2996 struct pkt_key_ipv6_addr {
2998 } __attribute__((__packed__));
3001 parse_match(char **tokens,
3005 struct softnic_table_rule_match *m)
3007 memset(m, 0, sizeof(*m));
3012 if (strcmp(tokens[0], "match") != 0) {
3013 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
3017 if (strcmp(tokens[1], "acl") == 0) {
3018 if (n_tokens < 14) {
3019 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3023 m->match_type = TABLE_ACL;
3025 if (strcmp(tokens[2], "priority") != 0) {
3026 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "priority");
3030 if (softnic_parser_read_uint32(&m->match.acl.priority,
3032 snprintf(out, out_size, MSG_ARG_INVALID, "priority");
3036 if (strcmp(tokens[4], "ipv4") == 0) {
3037 struct in_addr saddr, daddr;
3039 m->match.acl.ip_version = 1;
3041 if (softnic_parse_ipv4_addr(tokens[5], &saddr) != 0) {
3042 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
3045 m->match.acl.ipv4.sa = rte_be_to_cpu_32(saddr.s_addr);
3047 if (softnic_parse_ipv4_addr(tokens[7], &daddr) != 0) {
3048 snprintf(out, out_size, MSG_ARG_INVALID, "da");
3051 m->match.acl.ipv4.da = rte_be_to_cpu_32(daddr.s_addr);
3052 } else if (strcmp(tokens[4], "ipv6") == 0) {
3053 struct in6_addr saddr, daddr;
3055 m->match.acl.ip_version = 0;
3057 if (softnic_parse_ipv6_addr(tokens[5], &saddr) != 0) {
3058 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
3061 memcpy(m->match.acl.ipv6.sa, saddr.s6_addr, 16);
3063 if (softnic_parse_ipv6_addr(tokens[7], &daddr) != 0) {
3064 snprintf(out, out_size, MSG_ARG_INVALID, "da");
3067 memcpy(m->match.acl.ipv6.da, daddr.s6_addr, 16);
3069 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
3074 if (softnic_parser_read_uint32(&m->match.acl.sa_depth,
3076 snprintf(out, out_size, MSG_ARG_INVALID, "sa_depth");
3080 if (softnic_parser_read_uint32(&m->match.acl.da_depth,
3082 snprintf(out, out_size, MSG_ARG_INVALID, "da_depth");
3086 if (softnic_parser_read_uint16(&m->match.acl.sp0, tokens[9]) != 0) {
3087 snprintf(out, out_size, MSG_ARG_INVALID, "sp0");
3091 if (softnic_parser_read_uint16(&m->match.acl.sp1, tokens[10]) != 0) {
3092 snprintf(out, out_size, MSG_ARG_INVALID, "sp1");
3096 if (softnic_parser_read_uint16(&m->match.acl.dp0, tokens[11]) != 0) {
3097 snprintf(out, out_size, MSG_ARG_INVALID, "dp0");
3101 if (softnic_parser_read_uint16(&m->match.acl.dp1, tokens[12]) != 0) {
3102 snprintf(out, out_size, MSG_ARG_INVALID, "dp1");
3106 if (softnic_parser_read_uint8(&m->match.acl.proto, tokens[13]) != 0) {
3107 snprintf(out, out_size, MSG_ARG_INVALID, "proto");
3111 m->match.acl.proto_mask = 0xff;
3116 if (strcmp(tokens[1], "array") == 0) {
3118 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3122 m->match_type = TABLE_ARRAY;
3124 if (softnic_parser_read_uint32(&m->match.array.pos, tokens[2]) != 0) {
3125 snprintf(out, out_size, MSG_ARG_INVALID, "pos");
3132 if (strcmp(tokens[1], "hash") == 0) {
3134 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3138 m->match_type = TABLE_HASH;
3140 if (strcmp(tokens[2], "raw") == 0) {
3141 uint32_t key_size = TABLE_RULE_MATCH_SIZE_MAX;
3144 snprintf(out, out_size, MSG_ARG_MISMATCH,
3149 if (softnic_parse_hex_string(tokens[3],
3150 m->match.hash.key, &key_size) != 0) {
3151 snprintf(out, out_size, MSG_ARG_INVALID, "key");
3158 if (strcmp(tokens[2], "ipv4_5tuple") == 0) {
3159 struct pkt_key_ipv4_5tuple *ipv4 =
3160 (struct pkt_key_ipv4_5tuple *)m->match.hash.key;
3161 struct in_addr saddr, daddr;
3166 snprintf(out, out_size, MSG_ARG_MISMATCH,
3171 if (softnic_parse_ipv4_addr(tokens[3], &saddr) != 0) {
3172 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
3176 if (softnic_parse_ipv4_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 ipv4->sa = saddr.s_addr;
3198 ipv4->da = daddr.s_addr;
3199 ipv4->sp = rte_cpu_to_be_16(sp);
3200 ipv4->dp = rte_cpu_to_be_16(dp);
3201 ipv4->proto = proto;
3204 } /* hash ipv4_5tuple */
3206 if (strcmp(tokens[2], "ipv6_5tuple") == 0) {
3207 struct pkt_key_ipv6_5tuple *ipv6 =
3208 (struct pkt_key_ipv6_5tuple *)m->match.hash.key;
3209 struct in6_addr saddr, daddr;
3214 snprintf(out, out_size, MSG_ARG_MISMATCH,
3219 if (softnic_parse_ipv6_addr(tokens[3], &saddr) != 0) {
3220 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
3224 if (softnic_parse_ipv6_addr(tokens[4], &daddr) != 0) {
3225 snprintf(out, out_size, MSG_ARG_INVALID, "da");
3229 if (softnic_parser_read_uint16(&sp, tokens[5]) != 0) {
3230 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
3234 if (softnic_parser_read_uint16(&dp, tokens[6]) != 0) {
3235 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
3239 if (softnic_parser_read_uint8(&proto, tokens[7]) != 0) {
3240 snprintf(out, out_size, MSG_ARG_INVALID,
3245 memcpy(ipv6->sa, saddr.s6_addr, 16);
3246 memcpy(ipv6->da, daddr.s6_addr, 16);
3247 ipv6->sp = rte_cpu_to_be_16(sp);
3248 ipv6->dp = rte_cpu_to_be_16(dp);
3249 ipv6->proto = proto;
3252 } /* hash ipv6_5tuple */
3254 if (strcmp(tokens[2], "ipv4_addr") == 0) {
3255 struct pkt_key_ipv4_addr *ipv4_addr =
3256 (struct pkt_key_ipv4_addr *)m->match.hash.key;
3257 struct in_addr addr;
3260 snprintf(out, out_size, MSG_ARG_MISMATCH,
3265 if (softnic_parse_ipv4_addr(tokens[3], &addr) != 0) {
3266 snprintf(out, out_size, MSG_ARG_INVALID,
3271 ipv4_addr->addr = addr.s_addr;
3274 } /* hash ipv4_addr */
3276 if (strcmp(tokens[2], "ipv6_addr") == 0) {
3277 struct pkt_key_ipv6_addr *ipv6_addr =
3278 (struct pkt_key_ipv6_addr *)m->match.hash.key;
3279 struct in6_addr addr;
3282 snprintf(out, out_size, MSG_ARG_MISMATCH,
3287 if (softnic_parse_ipv6_addr(tokens[3], &addr) != 0) {
3288 snprintf(out, out_size, MSG_ARG_INVALID,
3293 memcpy(ipv6_addr->addr, addr.s6_addr, 16);
3296 } /* hash ipv6_5tuple */
3298 if (strcmp(tokens[2], "qinq") == 0) {
3299 struct pkt_key_qinq *qinq =
3300 (struct pkt_key_qinq *)m->match.hash.key;
3301 uint16_t svlan, cvlan;
3304 snprintf(out, out_size, MSG_ARG_MISMATCH,
3309 if ((softnic_parser_read_uint16(&svlan, tokens[3]) != 0) ||
3311 snprintf(out, out_size, MSG_ARG_INVALID,
3316 if ((softnic_parser_read_uint16(&cvlan, tokens[4]) != 0) ||
3318 snprintf(out, out_size, MSG_ARG_INVALID,
3323 qinq->svlan = rte_cpu_to_be_16(svlan);
3324 qinq->cvlan = rte_cpu_to_be_16(cvlan);
3329 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3333 if (strcmp(tokens[1], "lpm") == 0) {
3335 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3339 m->match_type = TABLE_LPM;
3341 if (strcmp(tokens[2], "ipv4") == 0) {
3342 struct in_addr addr;
3344 m->match.lpm.ip_version = 1;
3346 if (softnic_parse_ipv4_addr(tokens[3], &addr) != 0) {
3347 snprintf(out, out_size, MSG_ARG_INVALID,
3352 m->match.lpm.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3353 } else if (strcmp(tokens[2], "ipv6") == 0) {
3354 struct in6_addr addr;
3356 m->match.lpm.ip_version = 0;
3358 if (softnic_parse_ipv6_addr(tokens[3], &addr) != 0) {
3359 snprintf(out, out_size, MSG_ARG_INVALID,
3364 memcpy(m->match.lpm.ipv6, addr.s6_addr, 16);
3366 snprintf(out, out_size, MSG_ARG_MISMATCH,
3371 if (softnic_parser_read_uint8(&m->match.lpm.depth, tokens[4]) != 0) {
3372 snprintf(out, out_size, MSG_ARG_INVALID, "depth");
3379 snprintf(out, out_size, MSG_ARG_MISMATCH,
3380 "acl or array or hash or lpm");
3392 * | table <table_id>
3393 * [balance <out0> ... <out7>]
3395 * tc0 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3396 * [tc1 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3397 * tc2 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3398 * tc3 meter <meter_profile_id> policer g <pa> y <pa> r <pa>]]
3399 * [tm subport <subport_id> pipe <pipe_id>]
3402 * | vlan <da> <sa> <pcp> <dei> <vid>
3403 * | qinq <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid>
3404 * | mpls unicast | multicast
3406 * label0 <label> <tc> <ttl>
3407 * [label1 <label> <tc> <ttl>
3408 * [label2 <label> <tc> <ttl>
3409 * [label3 <label> <tc> <ttl>]]]
3410 * | pppoe <da> <sa> <session_id>]
3411 * | vxlan ether <da> <sa>
3412 * [vlan <pcp> <dei> <vid>]
3413 * ipv4 <sa> <da> <dscp> <ttl>
3414 * | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit>
3417 * [nat ipv4 | ipv6 <addr> <port>]
3427 * cipher_algo <algo> cipher_key <key> cipher_iv <iv>
3429 * cipher_algo <algo> cipher_key <key> cipher_iv <iv>
3430 * auth_algo <algo> auth_key <key> digest_size <size>
3432 * aead_algo <algo> aead_key <key> aead_iv <iv> aead_aad <aad>
3433 * digest_size <size>
3434 * data_offset <data_offset>]
3437 * <pa> ::= g | y | r | drop
3440 parse_table_action_fwd(char **tokens,
3442 struct softnic_table_rule_action *a)
3444 if (n_tokens == 0 ||
3445 (strcmp(tokens[0], "fwd") != 0))
3451 if (n_tokens && (strcmp(tokens[0], "drop") == 0)) {
3452 a->fwd.action = RTE_PIPELINE_ACTION_DROP;
3453 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3457 if (n_tokens && (strcmp(tokens[0], "port") == 0)) {
3461 softnic_parser_read_uint32(&id, tokens[1]))
3464 a->fwd.action = RTE_PIPELINE_ACTION_PORT;
3466 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3470 if (n_tokens && (strcmp(tokens[0], "meta") == 0)) {
3471 a->fwd.action = RTE_PIPELINE_ACTION_PORT_META;
3472 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3476 if (n_tokens && (strcmp(tokens[0], "table") == 0)) {
3480 softnic_parser_read_uint32(&id, tokens[1]))
3483 a->fwd.action = RTE_PIPELINE_ACTION_TABLE;
3485 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3493 parse_table_action_balance(char **tokens,
3495 struct softnic_table_rule_action *a)
3499 if (n_tokens == 0 ||
3500 (strcmp(tokens[0], "balance") != 0))
3506 if (n_tokens < RTE_TABLE_ACTION_LB_TABLE_SIZE)
3509 for (i = 0; i < RTE_TABLE_ACTION_LB_TABLE_SIZE; i++)
3510 if (softnic_parser_read_uint32(&a->lb.out[i], tokens[i]) != 0)
3513 a->action_mask |= 1 << RTE_TABLE_ACTION_LB;
3514 return 1 + RTE_TABLE_ACTION_LB_TABLE_SIZE;
3518 parse_policer_action(char *token, enum rte_table_action_policer *a)
3520 if (strcmp(token, "g") == 0) {
3521 *a = RTE_TABLE_ACTION_POLICER_COLOR_GREEN;
3525 if (strcmp(token, "y") == 0) {
3526 *a = RTE_TABLE_ACTION_POLICER_COLOR_YELLOW;
3530 if (strcmp(token, "r") == 0) {
3531 *a = RTE_TABLE_ACTION_POLICER_COLOR_RED;
3535 if (strcmp(token, "drop") == 0) {
3536 *a = RTE_TABLE_ACTION_POLICER_DROP;
3544 parse_table_action_meter_tc(char **tokens,
3546 struct rte_table_action_mtr_tc_params *mtr)
3549 strcmp(tokens[0], "meter") ||
3550 softnic_parser_read_uint32(&mtr->meter_profile_id, tokens[1]) ||
3551 strcmp(tokens[2], "policer") ||
3552 strcmp(tokens[3], "g") ||
3553 parse_policer_action(tokens[4], &mtr->policer[e_RTE_METER_GREEN]) ||
3554 strcmp(tokens[5], "y") ||
3555 parse_policer_action(tokens[6], &mtr->policer[e_RTE_METER_YELLOW]) ||
3556 strcmp(tokens[7], "r") ||
3557 parse_policer_action(tokens[8], &mtr->policer[e_RTE_METER_RED]))
3564 parse_table_action_meter(char **tokens,
3566 struct softnic_table_rule_action *a)
3568 if (n_tokens == 0 ||
3569 strcmp(tokens[0], "meter"))
3575 if (n_tokens < 10 ||
3576 strcmp(tokens[0], "tc0") ||
3577 (parse_table_action_meter_tc(tokens + 1,
3579 &a->mtr.mtr[0]) == 0))
3585 if (n_tokens == 0 ||
3586 strcmp(tokens[0], "tc1")) {
3588 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3592 if (n_tokens < 30 ||
3593 (parse_table_action_meter_tc(tokens + 1,
3594 n_tokens - 1, &a->mtr.mtr[1]) == 0) ||
3595 strcmp(tokens[10], "tc2") ||
3596 (parse_table_action_meter_tc(tokens + 11,
3597 n_tokens - 11, &a->mtr.mtr[2]) == 0) ||
3598 strcmp(tokens[20], "tc3") ||
3599 (parse_table_action_meter_tc(tokens + 21,
3600 n_tokens - 21, &a->mtr.mtr[3]) == 0))
3603 a->mtr.tc_mask = 0xF;
3604 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3605 return 1 + 10 + 3 * 10;
3609 parse_table_action_tm(char **tokens,
3611 struct softnic_table_rule_action *a)
3613 uint32_t subport_id, pipe_id;
3616 strcmp(tokens[0], "tm") ||
3617 strcmp(tokens[1], "subport") ||
3618 softnic_parser_read_uint32(&subport_id, tokens[2]) ||
3619 strcmp(tokens[3], "pipe") ||
3620 softnic_parser_read_uint32(&pipe_id, tokens[4]))
3623 a->tm.subport_id = subport_id;
3624 a->tm.pipe_id = pipe_id;
3625 a->action_mask |= 1 << RTE_TABLE_ACTION_TM;
3630 parse_table_action_encap(char **tokens,
3632 struct softnic_table_rule_action *a)
3634 if (n_tokens == 0 ||
3635 strcmp(tokens[0], "encap"))
3642 if (n_tokens && (strcmp(tokens[0], "ether") == 0)) {
3644 softnic_parse_mac_addr(tokens[1], &a->encap.ether.ether.da) ||
3645 softnic_parse_mac_addr(tokens[2], &a->encap.ether.ether.sa))
3648 a->encap.type = RTE_TABLE_ACTION_ENCAP_ETHER;
3649 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3654 if (n_tokens && (strcmp(tokens[0], "vlan") == 0)) {
3655 uint32_t pcp, dei, vid;
3658 softnic_parse_mac_addr(tokens[1], &a->encap.vlan.ether.da) ||
3659 softnic_parse_mac_addr(tokens[2], &a->encap.vlan.ether.sa) ||
3660 softnic_parser_read_uint32(&pcp, tokens[3]) ||
3662 softnic_parser_read_uint32(&dei, tokens[4]) ||
3664 softnic_parser_read_uint32(&vid, tokens[5]) ||
3668 a->encap.vlan.vlan.pcp = pcp & 0x7;
3669 a->encap.vlan.vlan.dei = dei & 0x1;
3670 a->encap.vlan.vlan.vid = vid & 0xFFF;
3671 a->encap.type = RTE_TABLE_ACTION_ENCAP_VLAN;
3672 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3677 if (n_tokens && (strcmp(tokens[0], "qinq") == 0)) {
3678 uint32_t svlan_pcp, svlan_dei, svlan_vid;
3679 uint32_t cvlan_pcp, cvlan_dei, cvlan_vid;
3682 softnic_parse_mac_addr(tokens[1], &a->encap.qinq.ether.da) ||
3683 softnic_parse_mac_addr(tokens[2], &a->encap.qinq.ether.sa) ||
3684 softnic_parser_read_uint32(&svlan_pcp, tokens[3]) ||
3686 softnic_parser_read_uint32(&svlan_dei, tokens[4]) ||
3688 softnic_parser_read_uint32(&svlan_vid, tokens[5]) ||
3689 svlan_vid > 0xFFF ||
3690 softnic_parser_read_uint32(&cvlan_pcp, tokens[6]) ||
3692 softnic_parser_read_uint32(&cvlan_dei, tokens[7]) ||
3694 softnic_parser_read_uint32(&cvlan_vid, tokens[8]) ||
3698 a->encap.qinq.svlan.pcp = svlan_pcp & 0x7;
3699 a->encap.qinq.svlan.dei = svlan_dei & 0x1;
3700 a->encap.qinq.svlan.vid = svlan_vid & 0xFFF;
3701 a->encap.qinq.cvlan.pcp = cvlan_pcp & 0x7;
3702 a->encap.qinq.cvlan.dei = cvlan_dei & 0x1;
3703 a->encap.qinq.cvlan.vid = cvlan_vid & 0xFFF;
3704 a->encap.type = RTE_TABLE_ACTION_ENCAP_QINQ;
3705 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3710 if (n_tokens && (strcmp(tokens[0], "mpls") == 0)) {
3711 uint32_t label, tc, ttl;
3716 if (strcmp(tokens[1], "unicast") == 0)
3717 a->encap.mpls.unicast = 1;
3718 else if (strcmp(tokens[1], "multicast") == 0)
3719 a->encap.mpls.unicast = 0;
3723 if (softnic_parse_mac_addr(tokens[2], &a->encap.mpls.ether.da) ||
3724 softnic_parse_mac_addr(tokens[3], &a->encap.mpls.ether.sa) ||
3725 strcmp(tokens[4], "label0") ||
3726 softnic_parser_read_uint32(&label, tokens[5]) ||
3728 softnic_parser_read_uint32(&tc, tokens[6]) ||
3730 softnic_parser_read_uint32(&ttl, tokens[7]) ||
3734 a->encap.mpls.mpls[0].label = label;
3735 a->encap.mpls.mpls[0].tc = tc;
3736 a->encap.mpls.mpls[0].ttl = ttl;
3741 if (n_tokens == 0 ||
3742 strcmp(tokens[0], "label1")) {
3743 a->encap.mpls.mpls_count = 1;
3744 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3745 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
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[1].label = label;
3759 a->encap.mpls.mpls[1].tc = tc;
3760 a->encap.mpls.mpls[1].ttl = ttl;
3765 if (n_tokens == 0 ||
3766 strcmp(tokens[0], "label2")) {
3767 a->encap.mpls.mpls_count = 2;
3768 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3769 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3774 softnic_parser_read_uint32(&label, tokens[1]) ||
3776 softnic_parser_read_uint32(&tc, tokens[2]) ||
3778 softnic_parser_read_uint32(&ttl, tokens[3]) ||
3782 a->encap.mpls.mpls[2].label = label;
3783 a->encap.mpls.mpls[2].tc = tc;
3784 a->encap.mpls.mpls[2].ttl = ttl;
3789 if (n_tokens == 0 ||
3790 strcmp(tokens[0], "label3")) {
3791 a->encap.mpls.mpls_count = 3;
3792 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3793 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3794 return 1 + 8 + 4 + 4;
3798 softnic_parser_read_uint32(&label, tokens[1]) ||
3800 softnic_parser_read_uint32(&tc, tokens[2]) ||
3802 softnic_parser_read_uint32(&ttl, tokens[3]) ||
3806 a->encap.mpls.mpls[3].label = label;
3807 a->encap.mpls.mpls[3].tc = tc;
3808 a->encap.mpls.mpls[3].ttl = ttl;
3810 a->encap.mpls.mpls_count = 4;
3811 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3812 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3813 return 1 + 8 + 4 + 4 + 4;
3817 if (n_tokens && (strcmp(tokens[0], "pppoe") == 0)) {
3819 softnic_parse_mac_addr(tokens[1], &a->encap.pppoe.ether.da) ||
3820 softnic_parse_mac_addr(tokens[2], &a->encap.pppoe.ether.sa) ||
3821 softnic_parser_read_uint16(&a->encap.pppoe.pppoe.session_id,
3825 a->encap.type = RTE_TABLE_ACTION_ENCAP_PPPOE;
3826 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3831 if (n_tokens && (strcmp(tokens[0], "vxlan") == 0)) {
3838 /* ether <da> <sa> */
3839 if ((n_tokens < 3) ||
3840 strcmp(tokens[0], "ether") ||
3841 softnic_parse_mac_addr(tokens[1], &a->encap.vxlan.ether.da) ||
3842 softnic_parse_mac_addr(tokens[2], &a->encap.vxlan.ether.sa))
3849 /* [vlan <pcp> <dei> <vid>] */
3850 if (strcmp(tokens[0], "vlan") == 0) {
3851 uint32_t pcp, dei, vid;
3853 if ((n_tokens < 4) ||
3854 softnic_parser_read_uint32(&pcp, tokens[1]) ||
3856 softnic_parser_read_uint32(&dei, tokens[2]) ||
3858 softnic_parser_read_uint32(&vid, tokens[3]) ||
3862 a->encap.vxlan.vlan.pcp = pcp;
3863 a->encap.vxlan.vlan.dei = dei;
3864 a->encap.vxlan.vlan.vid = vid;
3871 /* ipv4 <sa> <da> <dscp> <ttl>
3872 | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit> */
3873 if (strcmp(tokens[0], "ipv4") == 0) {
3874 struct in_addr sa, da;
3877 if ((n_tokens < 5) ||
3878 softnic_parse_ipv4_addr(tokens[1], &sa) ||
3879 softnic_parse_ipv4_addr(tokens[2], &da) ||
3880 softnic_parser_read_uint8(&dscp, tokens[3]) ||
3882 softnic_parser_read_uint8(&ttl, tokens[4]))
3885 a->encap.vxlan.ipv4.sa = rte_be_to_cpu_32(sa.s_addr);
3886 a->encap.vxlan.ipv4.da = rte_be_to_cpu_32(da.s_addr);
3887 a->encap.vxlan.ipv4.dscp = dscp;
3888 a->encap.vxlan.ipv4.ttl = ttl;
3893 } else if (strcmp(tokens[0], "ipv6") == 0) {
3894 struct in6_addr sa, da;
3895 uint32_t flow_label;
3896 uint8_t dscp, hop_limit;
3898 if ((n_tokens < 6) ||
3899 softnic_parse_ipv6_addr(tokens[1], &sa) ||
3900 softnic_parse_ipv6_addr(tokens[2], &da) ||
3901 softnic_parser_read_uint32(&flow_label, tokens[3]) ||
3902 softnic_parser_read_uint8(&dscp, tokens[4]) ||
3904 softnic_parser_read_uint8(&hop_limit, tokens[5]))
3907 memcpy(a->encap.vxlan.ipv6.sa, sa.s6_addr, 16);
3908 memcpy(a->encap.vxlan.ipv6.da, da.s6_addr, 16);
3909 a->encap.vxlan.ipv6.flow_label = flow_label;
3910 a->encap.vxlan.ipv6.dscp = dscp;
3911 a->encap.vxlan.ipv6.hop_limit = hop_limit;
3920 if ((n_tokens < 3) ||
3921 strcmp(tokens[0], "udp") ||
3922 softnic_parser_read_uint16(&a->encap.vxlan.udp.sp, tokens[1]) ||
3923 softnic_parser_read_uint16(&a->encap.vxlan.udp.dp, tokens[2]))
3931 if ((n_tokens < 2) ||
3932 strcmp(tokens[0], "vxlan") ||
3933 softnic_parser_read_uint32(&a->encap.vxlan.vxlan.vni, tokens[1]) ||
3934 (a->encap.vxlan.vxlan.vni > 0xFFFFFF))
3941 a->encap.type = RTE_TABLE_ACTION_ENCAP_VXLAN;
3942 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3950 parse_table_action_nat(char **tokens,
3952 struct softnic_table_rule_action *a)
3955 strcmp(tokens[0], "nat"))
3958 if (strcmp(tokens[1], "ipv4") == 0) {
3959 struct in_addr addr;
3962 if (softnic_parse_ipv4_addr(tokens[2], &addr) ||
3963 softnic_parser_read_uint16(&port, tokens[3]))
3966 a->nat.ip_version = 1;
3967 a->nat.addr.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3969 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3973 if (strcmp(tokens[1], "ipv6") == 0) {
3974 struct in6_addr addr;
3977 if (softnic_parse_ipv6_addr(tokens[2], &addr) ||
3978 softnic_parser_read_uint16(&port, tokens[3]))
3981 a->nat.ip_version = 0;
3982 memcpy(a->nat.addr.ipv6, addr.s6_addr, 16);
3984 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3992 parse_table_action_ttl(char **tokens,
3994 struct softnic_table_rule_action *a)
3997 strcmp(tokens[0], "ttl"))
4000 if (strcmp(tokens[1], "dec") == 0)
4001 a->ttl.decrement = 1;
4002 else if (strcmp(tokens[1], "keep") == 0)
4003 a->ttl.decrement = 0;
4007 a->action_mask |= 1 << RTE_TABLE_ACTION_TTL;
4012 parse_table_action_stats(char **tokens,
4014 struct softnic_table_rule_action *a)
4017 strcmp(tokens[0], "stats"))
4020 a->stats.n_packets = 0;
4021 a->stats.n_bytes = 0;
4022 a->action_mask |= 1 << RTE_TABLE_ACTION_STATS;
4027 parse_table_action_time(char **tokens,
4029 struct softnic_table_rule_action *a)
4032 strcmp(tokens[0], "time"))
4035 a->time.time = rte_rdtsc();
4036 a->action_mask |= 1 << RTE_TABLE_ACTION_TIME;
4041 parse_free_sym_crypto_param_data(struct rte_table_action_sym_crypto_params *p)
4043 struct rte_crypto_sym_xform *xform[2] = {NULL};
4046 xform[0] = p->xform;
4048 xform[1] = xform[0]->next;
4050 for (i = 0; i < 2; i++) {
4051 if (xform[i] == NULL)
4054 switch (xform[i]->type) {
4055 case RTE_CRYPTO_SYM_XFORM_CIPHER:
4056 if (xform[i]->cipher.key.data)
4057 free(xform[i]->cipher.key.data);
4058 if (p->cipher_auth.cipher_iv.val)
4059 free(p->cipher_auth.cipher_iv.val);
4060 if (p->cipher_auth.cipher_iv_update.val)
4061 free(p->cipher_auth.cipher_iv_update.val);
4063 case RTE_CRYPTO_SYM_XFORM_AUTH:
4064 if (xform[i]->auth.key.data)
4065 free(xform[i]->cipher.key.data);
4066 if (p->cipher_auth.auth_iv.val)
4067 free(p->cipher_auth.cipher_iv.val);
4068 if (p->cipher_auth.auth_iv_update.val)
4069 free(p->cipher_auth.cipher_iv_update.val);
4071 case RTE_CRYPTO_SYM_XFORM_AEAD:
4072 if (xform[i]->aead.key.data)
4073 free(xform[i]->cipher.key.data);
4075 free(p->aead.iv.val);
4076 if (p->aead.aad.val)
4077 free(p->aead.aad.val);
4086 static struct rte_crypto_sym_xform *
4087 parse_table_action_cipher(struct rte_table_action_sym_crypto_params *p,
4088 char **tokens, uint32_t n_tokens, uint32_t encrypt,
4089 uint32_t *used_n_tokens)
4091 struct rte_crypto_sym_xform *xform_cipher;
4095 if (n_tokens < 7 || strcmp(tokens[1], "cipher_algo") ||
4096 strcmp(tokens[3], "cipher_key") ||
4097 strcmp(tokens[5], "cipher_iv"))
4100 xform_cipher = calloc(1, sizeof(*xform_cipher));
4101 if (xform_cipher == NULL)
4104 xform_cipher->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4105 xform_cipher->cipher.op = encrypt ? RTE_CRYPTO_CIPHER_OP_ENCRYPT :
4106 RTE_CRYPTO_CIPHER_OP_DECRYPT;
4109 status = rte_cryptodev_get_cipher_algo_enum(
4110 &xform_cipher->cipher.algo, tokens[2]);
4115 len = strlen(tokens[4]);
4116 xform_cipher->cipher.key.data = calloc(1, len / 2 + 1);
4117 if (xform_cipher->cipher.key.data == NULL)
4120 status = softnic_parse_hex_string(tokens[4],
4121 xform_cipher->cipher.key.data,
4126 xform_cipher->cipher.key.length = (uint16_t)len;
4129 len = strlen(tokens[6]);
4131 p->cipher_auth.cipher_iv.val = calloc(1, len / 2 + 1);
4132 if (p->cipher_auth.cipher_iv.val == NULL)
4135 status = softnic_parse_hex_string(tokens[6],
4136 p->cipher_auth.cipher_iv.val,
4141 xform_cipher->cipher.iv.length = (uint16_t)len;
4142 xform_cipher->cipher.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
4143 p->cipher_auth.cipher_iv.length = (uint32_t)len;
4146 return xform_cipher;
4149 if (xform_cipher->cipher.key.data)
4150 free(xform_cipher->cipher.key.data);
4152 if (p->cipher_auth.cipher_iv.val) {
4153 free(p->cipher_auth.cipher_iv.val);
4154 p->cipher_auth.cipher_iv.val = NULL;
4162 static struct rte_crypto_sym_xform *
4163 parse_table_action_cipher_auth(struct rte_table_action_sym_crypto_params *p,
4164 char **tokens, uint32_t n_tokens, uint32_t encrypt,
4165 uint32_t *used_n_tokens)
4167 struct rte_crypto_sym_xform *xform_cipher;
4168 struct rte_crypto_sym_xform *xform_auth;
4172 if (n_tokens < 13 ||
4173 strcmp(tokens[7], "auth_algo") ||
4174 strcmp(tokens[9], "auth_key") ||
4175 strcmp(tokens[11], "digest_size"))
4178 xform_auth = calloc(1, sizeof(*xform_auth));
4179 if (xform_auth == NULL)
4182 xform_auth->type = RTE_CRYPTO_SYM_XFORM_AUTH;
4183 xform_auth->auth.op = encrypt ? RTE_CRYPTO_AUTH_OP_GENERATE :
4184 RTE_CRYPTO_AUTH_OP_VERIFY;
4187 status = rte_cryptodev_get_auth_algo_enum(&xform_auth->auth.algo,
4193 len = strlen(tokens[10]);
4194 xform_auth->auth.key.data = calloc(1, len / 2 + 1);
4195 if (xform_auth->auth.key.data == NULL)
4198 status = softnic_parse_hex_string(tokens[10],
4199 xform_auth->auth.key.data, (uint32_t *)&len);
4203 xform_auth->auth.key.length = (uint16_t)len;
4205 if (strcmp(tokens[11], "digest_size"))
4208 status = softnic_parser_read_uint16(&xform_auth->auth.digest_length,
4213 xform_cipher = parse_table_action_cipher(p, tokens, 7, encrypt,
4215 if (xform_cipher == NULL)
4218 *used_n_tokens += 6;
4221 xform_cipher->next = xform_auth;
4222 return xform_cipher;
4224 xform_auth->next = xform_cipher;
4229 if (xform_auth->auth.key.data)
4230 free(xform_auth->auth.key.data);
4231 if (p->cipher_auth.auth_iv.val) {
4232 free(p->cipher_auth.auth_iv.val);
4233 p->cipher_auth.auth_iv.val = 0;
4241 static struct rte_crypto_sym_xform *
4242 parse_table_action_aead(struct rte_table_action_sym_crypto_params *p,
4243 char **tokens, uint32_t n_tokens, uint32_t encrypt,
4244 uint32_t *used_n_tokens)
4246 struct rte_crypto_sym_xform *xform_aead;
4250 if (n_tokens < 11 || strcmp(tokens[1], "aead_algo") ||
4251 strcmp(tokens[3], "aead_key") ||
4252 strcmp(tokens[5], "aead_iv") ||
4253 strcmp(tokens[7], "aead_aad") ||
4254 strcmp(tokens[9], "digest_size"))
4257 xform_aead = calloc(1, sizeof(*xform_aead));
4258 if (xform_aead == NULL)
4261 xform_aead->type = RTE_CRYPTO_SYM_XFORM_AEAD;
4262 xform_aead->aead.op = encrypt ? RTE_CRYPTO_AEAD_OP_ENCRYPT :
4263 RTE_CRYPTO_AEAD_OP_DECRYPT;
4266 status = rte_cryptodev_get_aead_algo_enum(&xform_aead->aead.algo,
4272 len = strlen(tokens[4]);
4273 xform_aead->aead.key.data = calloc(1, len / 2 + 1);
4274 if (xform_aead->aead.key.data == NULL)
4277 status = softnic_parse_hex_string(tokens[4], xform_aead->aead.key.data,
4282 xform_aead->aead.key.length = (uint16_t)len;
4285 len = strlen(tokens[6]);
4286 p->aead.iv.val = calloc(1, len / 2 + 1);
4287 if (p->aead.iv.val == NULL)
4290 status = softnic_parse_hex_string(tokens[6], p->aead.iv.val,
4295 xform_aead->aead.iv.length = (uint16_t)len;
4296 xform_aead->aead.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
4297 p->aead.iv.length = (uint32_t)len;
4300 len = strlen(tokens[8]);
4301 p->aead.aad.val = calloc(1, len / 2 + 1);
4302 if (p->aead.aad.val == NULL)
4305 status = softnic_parse_hex_string(tokens[8], p->aead.aad.val, (uint32_t *)&len);
4309 xform_aead->aead.aad_length = (uint16_t)len;
4310 p->aead.aad.length = (uint32_t)len;
4313 status = softnic_parser_read_uint16(&xform_aead->aead.digest_length,
4318 *used_n_tokens = 11;
4323 if (xform_aead->aead.key.data)
4324 free(xform_aead->aead.key.data);
4325 if (p->aead.iv.val) {
4326 free(p->aead.iv.val);
4327 p->aead.iv.val = NULL;
4329 if (p->aead.aad.val) {
4330 free(p->aead.aad.val);
4331 p->aead.aad.val = NULL;
4341 parse_table_action_sym_crypto(char **tokens,
4343 struct softnic_table_rule_action *a)
4345 struct rte_table_action_sym_crypto_params *p = &a->sym_crypto;
4346 struct rte_crypto_sym_xform *xform = NULL;
4347 uint32_t used_n_tokens;
4351 if ((n_tokens < 12) ||
4352 strcmp(tokens[0], "sym_crypto") ||
4353 strcmp(tokens[2], "type"))
4356 memset(p, 0, sizeof(*p));
4358 if (strcmp(tokens[1], "encrypt") == 0)
4363 status = softnic_parser_read_uint32(&p->data_offset, tokens[n_tokens - 1]);
4367 if (strcmp(tokens[3], "cipher") == 0) {
4371 xform = parse_table_action_cipher(p, tokens, n_tokens, encrypt,
4373 } else if (strcmp(tokens[3], "cipher_auth") == 0) {
4377 xform = parse_table_action_cipher_auth(p, tokens, n_tokens,
4378 encrypt, &used_n_tokens);
4379 } else if (strcmp(tokens[3], "aead") == 0) {
4383 xform = parse_table_action_aead(p, tokens, n_tokens, encrypt,
4392 if (strcmp(tokens[used_n_tokens], "data_offset")) {
4393 parse_free_sym_crypto_param_data(p);
4397 a->action_mask |= 1 << RTE_TABLE_ACTION_SYM_CRYPTO;
4399 return used_n_tokens + 5;
4403 parse_table_action_tag(char **tokens,
4405 struct softnic_table_rule_action *a)
4408 strcmp(tokens[0], "tag"))
4411 if (softnic_parser_read_uint32(&a->tag.tag, tokens[1]))
4414 a->action_mask |= 1 << RTE_TABLE_ACTION_TAG;
4419 parse_table_action_decap(char **tokens,
4421 struct softnic_table_rule_action *a)
4424 strcmp(tokens[0], "decap"))
4427 if (softnic_parser_read_uint16(&a->decap.n, tokens[1]))
4430 a->action_mask |= 1 << RTE_TABLE_ACTION_DECAP;
4435 parse_table_action(char **tokens,
4439 struct softnic_table_rule_action *a)
4441 uint32_t n_tokens0 = n_tokens;
4443 memset(a, 0, sizeof(*a));
4446 strcmp(tokens[0], "action"))
4452 if (n_tokens && (strcmp(tokens[0], "fwd") == 0)) {
4455 n = parse_table_action_fwd(tokens, n_tokens, a);
4457 snprintf(out, out_size, MSG_ARG_INVALID,
4466 if (n_tokens && (strcmp(tokens[0], "balance") == 0)) {
4469 n = parse_table_action_balance(tokens, n_tokens, a);
4471 snprintf(out, out_size, MSG_ARG_INVALID,
4480 if (n_tokens && (strcmp(tokens[0], "meter") == 0)) {
4483 n = parse_table_action_meter(tokens, n_tokens, a);
4485 snprintf(out, out_size, MSG_ARG_INVALID,
4494 if (n_tokens && (strcmp(tokens[0], "tm") == 0)) {
4497 n = parse_table_action_tm(tokens, n_tokens, a);
4499 snprintf(out, out_size, MSG_ARG_INVALID,
4508 if (n_tokens && (strcmp(tokens[0], "encap") == 0)) {
4511 n = parse_table_action_encap(tokens, n_tokens, a);
4513 snprintf(out, out_size, MSG_ARG_INVALID,
4522 if (n_tokens && (strcmp(tokens[0], "nat") == 0)) {
4525 n = parse_table_action_nat(tokens, n_tokens, a);
4527 snprintf(out, out_size, MSG_ARG_INVALID,
4536 if (n_tokens && (strcmp(tokens[0], "ttl") == 0)) {
4539 n = parse_table_action_ttl(tokens, n_tokens, a);
4541 snprintf(out, out_size, MSG_ARG_INVALID,
4550 if (n_tokens && (strcmp(tokens[0], "stats") == 0)) {
4553 n = parse_table_action_stats(tokens, n_tokens, a);
4555 snprintf(out, out_size, MSG_ARG_INVALID,
4564 if (n_tokens && (strcmp(tokens[0], "time") == 0)) {
4567 n = parse_table_action_time(tokens, n_tokens, a);
4569 snprintf(out, out_size, MSG_ARG_INVALID,
4578 if (n_tokens && (strcmp(tokens[0], "tag") == 0)) {
4581 n = parse_table_action_tag(tokens, n_tokens, a);
4583 snprintf(out, out_size, MSG_ARG_INVALID,
4592 if (n_tokens && (strcmp(tokens[0], "decap") == 0)) {
4595 n = parse_table_action_decap(tokens, n_tokens, a);
4597 snprintf(out, out_size, MSG_ARG_INVALID,
4606 if (n_tokens && (strcmp(tokens[0], "sym_crypto") == 0)) {
4609 n = parse_table_action_sym_crypto(tokens, n_tokens, a);
4611 snprintf(out, out_size, MSG_ARG_INVALID,
4612 "action sym_crypto");
4619 if (n_tokens0 - n_tokens == 1) {
4620 snprintf(out, out_size, MSG_ARG_INVALID, "action");
4624 return n_tokens0 - n_tokens;
4628 * pipeline <pipeline_name> table <table_id> rule add
4630 * action <table_action>
4633 cmd_softnic_pipeline_table_rule_add(struct pmd_internals *softnic,
4639 struct softnic_table_rule_match m;
4640 struct softnic_table_rule_action a;
4641 char *pipeline_name;
4643 uint32_t table_id, t0, n_tokens_parsed;
4647 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4651 pipeline_name = tokens[1];
4653 if (strcmp(tokens[2], "table") != 0) {
4654 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4658 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
4659 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4663 if (strcmp(tokens[4], "rule") != 0) {
4664 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4668 if (strcmp(tokens[5], "add") != 0) {
4669 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4676 n_tokens_parsed = parse_match(tokens + t0,
4681 if (n_tokens_parsed == 0)
4683 t0 += n_tokens_parsed;
4686 n_tokens_parsed = parse_table_action(tokens + t0,
4691 if (n_tokens_parsed == 0)
4693 t0 += n_tokens_parsed;
4695 if (t0 != n_tokens) {
4696 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
4700 status = softnic_pipeline_table_rule_add(softnic,
4707 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4713 * pipeline <pipeline_name> table <table_id> rule add
4721 * | table <table_id>
4724 cmd_softnic_pipeline_table_rule_add_default(struct pmd_internals *softnic,
4730 struct softnic_table_rule_action action;
4732 char *pipeline_name;
4736 if (n_tokens != 11 &&
4738 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4742 pipeline_name = tokens[1];
4744 if (strcmp(tokens[2], "table") != 0) {
4745 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4749 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
4750 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4754 if (strcmp(tokens[4], "rule") != 0) {
4755 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4759 if (strcmp(tokens[5], "add") != 0) {
4760 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4764 if (strcmp(tokens[6], "match") != 0) {
4765 snprintf(out, out_size, MSG_ARG_INVALID, "match");
4769 if (strcmp(tokens[7], "default") != 0) {
4770 snprintf(out, out_size, MSG_ARG_INVALID, "default");
4774 if (strcmp(tokens[8], "action") != 0) {
4775 snprintf(out, out_size, MSG_ARG_INVALID, "action");
4779 if (strcmp(tokens[9], "fwd") != 0) {
4780 snprintf(out, out_size, MSG_ARG_INVALID, "fwd");
4784 action.action_mask = 1 << RTE_TABLE_ACTION_FWD;
4786 if (strcmp(tokens[10], "drop") == 0) {
4787 if (n_tokens != 11) {
4788 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4792 action.fwd.action = RTE_PIPELINE_ACTION_DROP;
4793 } else if (strcmp(tokens[10], "port") == 0) {
4796 if (n_tokens != 12) {
4797 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4801 if (softnic_parser_read_uint32(&id, tokens[11]) != 0) {
4802 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
4806 action.fwd.action = RTE_PIPELINE_ACTION_PORT;
4808 } else if (strcmp(tokens[10], "meta") == 0) {
4809 if (n_tokens != 11) {
4810 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4814 action.fwd.action = RTE_PIPELINE_ACTION_PORT_META;
4815 } else if (strcmp(tokens[10], "table") == 0) {
4818 if (n_tokens != 12) {
4819 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4823 if (softnic_parser_read_uint32(&id, tokens[11]) != 0) {
4824 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4828 action.fwd.action = RTE_PIPELINE_ACTION_TABLE;
4831 snprintf(out, out_size, MSG_ARG_INVALID,
4832 "drop or port or meta or table");
4836 status = softnic_pipeline_table_rule_add_default(softnic,
4842 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4848 * pipeline <pipeline_name> table <table_id> rule add bulk <file_name> <n_rules>
4851 * - line format: match <match> action <action>
4854 cli_rule_file_process(const char *file_name,
4855 size_t line_len_max,
4856 struct softnic_table_rule_match *m,
4857 struct softnic_table_rule_action *a,
4859 uint32_t *line_number,
4864 cmd_softnic_pipeline_table_rule_add_bulk(struct pmd_internals *softnic,
4870 struct softnic_table_rule_match *match;
4871 struct softnic_table_rule_action *action;
4873 char *pipeline_name, *file_name;
4874 uint32_t table_id, n_rules, n_rules_parsed, line_number;
4877 if (n_tokens != 9) {
4878 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4882 pipeline_name = tokens[1];
4884 if (strcmp(tokens[2], "table") != 0) {
4885 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4889 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
4890 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4894 if (strcmp(tokens[4], "rule") != 0) {
4895 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4899 if (strcmp(tokens[5], "add") != 0) {
4900 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4904 if (strcmp(tokens[6], "bulk") != 0) {
4905 snprintf(out, out_size, MSG_ARG_INVALID, "bulk");
4909 file_name = tokens[7];
4911 if ((softnic_parser_read_uint32(&n_rules, tokens[8]) != 0) ||
4913 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
4917 /* Memory allocation. */
4918 match = calloc(n_rules, sizeof(struct softnic_table_rule_match));
4919 action = calloc(n_rules, sizeof(struct softnic_table_rule_action));
4920 data = calloc(n_rules, sizeof(void *));
4921 if (match == NULL ||
4924 snprintf(out, out_size, MSG_OUT_OF_MEMORY);
4931 /* Load rule file */
4932 n_rules_parsed = n_rules;
4933 status = cli_rule_file_process(file_name,
4942 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
4948 if (n_rules_parsed != n_rules) {
4949 snprintf(out, out_size, MSG_FILE_NOT_ENOUGH, file_name);
4957 status = softnic_pipeline_table_rule_add_bulk(softnic,
4965 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4979 * pipeline <pipeline_name> table <table_id> rule delete
4983 cmd_softnic_pipeline_table_rule_delete(struct pmd_internals *softnic,
4989 struct softnic_table_rule_match m;
4990 char *pipeline_name;
4991 uint32_t table_id, n_tokens_parsed, t0;
4995 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4999 pipeline_name = tokens[1];
5001 if (strcmp(tokens[2], "table") != 0) {
5002 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5006 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
5007 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5011 if (strcmp(tokens[4], "rule") != 0) {
5012 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5016 if (strcmp(tokens[5], "delete") != 0) {
5017 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
5024 n_tokens_parsed = parse_match(tokens + t0,
5029 if (n_tokens_parsed == 0)
5031 t0 += n_tokens_parsed;
5033 if (n_tokens != t0) {
5034 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5038 status = softnic_pipeline_table_rule_delete(softnic,
5043 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5049 * pipeline <pipeline_name> table <table_id> rule delete
5054 cmd_softnic_pipeline_table_rule_delete_default(struct pmd_internals *softnic,
5060 char *pipeline_name;
5064 if (n_tokens != 8) {
5065 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5069 pipeline_name = tokens[1];
5071 if (strcmp(tokens[2], "table") != 0) {
5072 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5076 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
5077 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5081 if (strcmp(tokens[4], "rule") != 0) {
5082 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5086 if (strcmp(tokens[5], "delete") != 0) {
5087 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
5091 if (strcmp(tokens[6], "match") != 0) {
5092 snprintf(out, out_size, MSG_ARG_INVALID, "match");
5096 if (strcmp(tokens[7], "default") != 0) {
5097 snprintf(out, out_size, MSG_ARG_INVALID, "default");
5101 status = softnic_pipeline_table_rule_delete_default(softnic,
5105 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5111 * pipeline <pipeline_name> table <table_id> rule read stats [clear]
5114 cmd_softnic_pipeline_table_rule_stats_read(struct pmd_internals *softnic __rte_unused,
5116 uint32_t n_tokens __rte_unused,
5120 snprintf(out, out_size, MSG_CMD_UNIMPLEM, tokens[0]);
5124 * pipeline <pipeline_name> table <table_id> meter profile <meter_profile_id>
5125 * add srtcm cir <cir> cbs <cbs> ebs <ebs>
5126 * | trtcm cir <cir> pir <pir> cbs <cbs> pbs <pbs>
5129 cmd_pipeline_table_meter_profile_add(struct pmd_internals *softnic,
5135 struct rte_table_action_meter_profile p;
5136 char *pipeline_name;
5137 uint32_t table_id, meter_profile_id;
5141 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5145 pipeline_name = tokens[1];
5147 if (strcmp(tokens[2], "table") != 0) {
5148 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5152 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
5153 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5157 if (strcmp(tokens[4], "meter") != 0) {
5158 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5162 if (strcmp(tokens[5], "profile") != 0) {
5163 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
5167 if (softnic_parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
5168 snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
5172 if (strcmp(tokens[7], "add") != 0) {
5173 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
5177 if (strcmp(tokens[8], "srtcm") == 0) {
5178 if (n_tokens != 15) {
5179 snprintf(out, out_size, MSG_ARG_MISMATCH,
5184 p.alg = RTE_TABLE_ACTION_METER_SRTCM;
5186 if (strcmp(tokens[9], "cir") != 0) {
5187 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
5191 if (softnic_parser_read_uint64(&p.srtcm.cir, tokens[10]) != 0) {
5192 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
5196 if (strcmp(tokens[11], "cbs") != 0) {
5197 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
5201 if (softnic_parser_read_uint64(&p.srtcm.cbs, tokens[12]) != 0) {
5202 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
5206 if (strcmp(tokens[13], "ebs") != 0) {
5207 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ebs");
5211 if (softnic_parser_read_uint64(&p.srtcm.ebs, tokens[14]) != 0) {
5212 snprintf(out, out_size, MSG_ARG_INVALID, "ebs");
5215 } else if (strcmp(tokens[8], "trtcm") == 0) {
5216 if (n_tokens != 17) {
5217 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5221 p.alg = RTE_TABLE_ACTION_METER_TRTCM;
5223 if (strcmp(tokens[9], "cir") != 0) {
5224 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
5228 if (softnic_parser_read_uint64(&p.trtcm.cir, tokens[10]) != 0) {
5229 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
5233 if (strcmp(tokens[11], "pir") != 0) {
5234 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir");
5238 if (softnic_parser_read_uint64(&p.trtcm.pir, tokens[12]) != 0) {
5239 snprintf(out, out_size, MSG_ARG_INVALID, "pir");
5242 if (strcmp(tokens[13], "cbs") != 0) {
5243 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
5247 if (softnic_parser_read_uint64(&p.trtcm.cbs, tokens[14]) != 0) {
5248 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
5252 if (strcmp(tokens[15], "pbs") != 0) {
5253 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs");
5257 if (softnic_parser_read_uint64(&p.trtcm.pbs, tokens[16]) != 0) {
5258 snprintf(out, out_size, MSG_ARG_INVALID, "pbs");
5262 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5266 status = softnic_pipeline_table_mtr_profile_add(softnic,
5272 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5278 * pipeline <pipeline_name> table <table_id>
5279 * meter profile <meter_profile_id> delete
5282 cmd_pipeline_table_meter_profile_delete(struct pmd_internals *softnic,
5288 char *pipeline_name;
5289 uint32_t table_id, meter_profile_id;
5292 if (n_tokens != 8) {
5293 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5297 pipeline_name = tokens[1];
5299 if (strcmp(tokens[2], "table") != 0) {
5300 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5304 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
5305 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5309 if (strcmp(tokens[4], "meter") != 0) {
5310 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5314 if (strcmp(tokens[5], "profile") != 0) {
5315 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
5319 if (softnic_parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
5320 snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
5324 if (strcmp(tokens[7], "delete") != 0) {
5325 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
5329 status = softnic_pipeline_table_mtr_profile_delete(softnic,
5334 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5340 * pipeline <pipeline_name> table <table_id> rule read meter [clear]
5343 cmd_pipeline_table_rule_meter_read(struct pmd_internals *softnic __rte_unused,
5345 uint32_t n_tokens __rte_unused,
5349 snprintf(out, out_size, MSG_CMD_UNIMPLEM, tokens[0]);
5353 * pipeline <pipeline_name> table <table_id> dscp <file_name>
5356 * - exactly 64 lines
5357 * - line format: <tc_id> <tc_queue_id> <color>, with <color> as: g | y | r
5360 load_dscp_table(struct rte_table_action_dscp_table *dscp_table,
5361 const char *file_name,
5362 uint32_t *line_number)
5367 /* Check input arguments */
5368 if (dscp_table == NULL ||
5369 file_name == NULL ||
5370 line_number == NULL) {
5376 /* Open input file */
5377 f = fopen(file_name, "r");
5384 for (dscp = 0, l = 1; ; l++) {
5387 enum rte_meter_color color;
5388 uint32_t tc_id, tc_queue_id, n_tokens = RTE_DIM(tokens);
5390 if (fgets(line, sizeof(line), f) == NULL)
5393 if (is_comment(line))
5396 if (softnic_parse_tokenize_string(line, tokens, &n_tokens)) {
5405 if (dscp >= RTE_DIM(dscp_table->entry) ||
5406 n_tokens != RTE_DIM(tokens) ||
5407 softnic_parser_read_uint32(&tc_id, tokens[0]) ||
5408 tc_id >= RTE_TABLE_ACTION_TC_MAX ||
5409 softnic_parser_read_uint32(&tc_queue_id, tokens[1]) ||
5410 tc_queue_id >= RTE_TABLE_ACTION_TC_QUEUE_MAX ||
5411 (strlen(tokens[2]) != 1)) {
5417 switch (tokens[2][0]) {
5420 color = e_RTE_METER_GREEN;
5425 color = e_RTE_METER_YELLOW;
5430 color = e_RTE_METER_RED;
5439 dscp_table->entry[dscp].tc_id = tc_id;
5440 dscp_table->entry[dscp].tc_queue_id = tc_queue_id;
5441 dscp_table->entry[dscp].color = color;
5451 cmd_pipeline_table_dscp(struct pmd_internals *softnic,
5457 struct rte_table_action_dscp_table dscp_table;
5458 char *pipeline_name, *file_name;
5459 uint32_t table_id, line_number;
5462 if (n_tokens != 6) {
5463 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5467 pipeline_name = tokens[1];
5469 if (strcmp(tokens[2], "table") != 0) {
5470 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5474 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
5475 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5479 if (strcmp(tokens[4], "dscp") != 0) {
5480 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dscp");
5484 file_name = tokens[5];
5486 status = load_dscp_table(&dscp_table, file_name, &line_number);
5488 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
5492 status = softnic_pipeline_table_dscp_table_update(softnic,
5498 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5504 * pipeline <pipeline_name> table <table_id> rule read ttl [clear]
5507 cmd_softnic_pipeline_table_rule_ttl_read(struct pmd_internals *softnic __rte_unused,
5509 uint32_t n_tokens __rte_unused,
5513 snprintf(out, out_size, MSG_CMD_UNIMPLEM, tokens[0]);
5517 * thread <thread_id> pipeline <pipeline_name> enable
5520 cmd_softnic_thread_pipeline_enable(struct pmd_internals *softnic,
5526 char *pipeline_name;
5530 if (n_tokens != 5) {
5531 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5535 if (softnic_parser_read_uint32(&thread_id, tokens[1]) != 0) {
5536 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
5540 if (strcmp(tokens[2], "pipeline") != 0) {
5541 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
5545 pipeline_name = tokens[3];
5547 if (strcmp(tokens[4], "enable") != 0) {
5548 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
5552 status = softnic_thread_pipeline_enable(softnic, thread_id, pipeline_name);
5554 snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable");
5560 * thread <thread_id> pipeline <pipeline_name> disable
5563 cmd_softnic_thread_pipeline_disable(struct pmd_internals *softnic,
5569 char *pipeline_name;
5573 if (n_tokens != 5) {
5574 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5578 if (softnic_parser_read_uint32(&thread_id, tokens[1]) != 0) {
5579 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
5583 if (strcmp(tokens[2], "pipeline") != 0) {
5584 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
5588 pipeline_name = tokens[3];
5590 if (strcmp(tokens[4], "disable") != 0) {
5591 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
5595 status = softnic_thread_pipeline_disable(softnic, thread_id, pipeline_name);
5597 snprintf(out, out_size, MSG_CMD_FAIL,
5598 "thread pipeline disable");
5607 * pipeline <pipeline_name>
5611 cmd_softnic_flowapi_map(struct pmd_internals *softnic,
5617 char *pipeline_name;
5618 uint32_t group_id, table_id;
5619 int ingress, status;
5621 if (n_tokens != 9) {
5622 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5626 if (strcmp(tokens[1], "map") != 0) {
5627 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "map");
5631 if (strcmp(tokens[2], "group") != 0) {
5632 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group");
5636 if (softnic_parser_read_uint32(&group_id, tokens[3]) != 0) {
5637 snprintf(out, out_size, MSG_ARG_INVALID, "group_id");
5641 if (strcmp(tokens[4], "ingress") == 0) {
5643 } else if (strcmp(tokens[4], "egress") == 0) {
5646 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ingress | egress");
5650 if (strcmp(tokens[5], "pipeline") != 0) {
5651 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
5655 pipeline_name = tokens[6];
5657 if (strcmp(tokens[7], "table") != 0) {
5658 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5662 if (softnic_parser_read_uint32(&table_id, tokens[8]) != 0) {
5663 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5667 status = flow_attr_map_set(softnic,
5673 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5679 softnic_cli_process(char *in, char *out, size_t out_size, void *arg)
5681 char *tokens[CMD_MAX_TOKENS];
5682 uint32_t n_tokens = RTE_DIM(tokens);
5683 struct pmd_internals *softnic = arg;
5689 status = softnic_parse_tokenize_string(in, tokens, &n_tokens);
5691 snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
5698 if (strcmp(tokens[0], "mempool") == 0) {
5699 cmd_mempool(softnic, tokens, n_tokens, out, out_size);
5703 if (strcmp(tokens[0], "link") == 0) {
5704 cmd_link(softnic, tokens, n_tokens, out, out_size);
5708 if (strcmp(tokens[0], "swq") == 0) {
5709 cmd_swq(softnic, tokens, n_tokens, out, out_size);
5713 if (strcmp(tokens[0], "tmgr") == 0) {
5714 if (n_tokens == 2) {
5715 cmd_tmgr(softnic, tokens, n_tokens, out, out_size);
5719 if (n_tokens >= 3 &&
5720 (strcmp(tokens[1], "shaper") == 0) &&
5721 (strcmp(tokens[2], "profile") == 0)) {
5722 cmd_tmgr_shaper_profile(softnic, tokens, n_tokens, out, out_size);
5726 if (n_tokens >= 3 &&
5727 (strcmp(tokens[1], "shared") == 0) &&
5728 (strcmp(tokens[2], "shaper") == 0)) {
5729 cmd_tmgr_shared_shaper(softnic, tokens, n_tokens, out, out_size);
5733 if (n_tokens >= 2 &&
5734 (strcmp(tokens[1], "node") == 0)) {
5735 cmd_tmgr_node(softnic, tokens, n_tokens, out, out_size);
5739 if (n_tokens >= 2 &&
5740 (strcmp(tokens[1], "hierarchy-default") == 0)) {
5741 cmd_tmgr_hierarchy_default(softnic, tokens, n_tokens, out, out_size);
5745 if (n_tokens >= 3 &&
5746 (strcmp(tokens[1], "hierarchy") == 0) &&
5747 (strcmp(tokens[2], "commit") == 0)) {
5748 cmd_tmgr_hierarchy_commit(softnic, tokens, n_tokens, out, out_size);
5753 if (strcmp(tokens[0], "tap") == 0) {
5754 cmd_tap(softnic, tokens, n_tokens, out, out_size);
5758 if (strcmp(tokens[0], "cryptodev") == 0) {
5759 cmd_cryptodev(softnic, tokens, n_tokens, out, out_size);
5763 if (strcmp(tokens[0], "port") == 0) {
5764 cmd_port_in_action_profile(softnic, tokens, n_tokens, out, out_size);
5768 if (strcmp(tokens[0], "table") == 0) {
5769 cmd_table_action_profile(softnic, tokens, n_tokens, out, out_size);
5773 if (strcmp(tokens[0], "pipeline") == 0) {
5774 if (n_tokens >= 3 &&
5775 (strcmp(tokens[2], "period") == 0)) {
5776 cmd_pipeline(softnic, tokens, n_tokens, out, out_size);
5780 if (n_tokens >= 5 &&
5781 (strcmp(tokens[2], "port") == 0) &&
5782 (strcmp(tokens[3], "in") == 0) &&
5783 (strcmp(tokens[4], "bsz") == 0)) {
5784 cmd_pipeline_port_in(softnic, tokens, n_tokens, out, out_size);
5788 if (n_tokens >= 5 &&
5789 (strcmp(tokens[2], "port") == 0) &&
5790 (strcmp(tokens[3], "out") == 0) &&
5791 (strcmp(tokens[4], "bsz") == 0)) {
5792 cmd_pipeline_port_out(softnic, tokens, n_tokens, out, out_size);
5796 if (n_tokens >= 4 &&
5797 (strcmp(tokens[2], "table") == 0) &&
5798 (strcmp(tokens[3], "match") == 0)) {
5799 cmd_pipeline_table(softnic, tokens, n_tokens, out, out_size);
5803 if (n_tokens >= 6 &&
5804 (strcmp(tokens[2], "port") == 0) &&
5805 (strcmp(tokens[3], "in") == 0) &&
5806 (strcmp(tokens[5], "table") == 0)) {
5807 cmd_pipeline_port_in_table(softnic, tokens, n_tokens,
5812 if (n_tokens >= 6 &&
5813 (strcmp(tokens[2], "port") == 0) &&
5814 (strcmp(tokens[3], "in") == 0) &&
5815 (strcmp(tokens[5], "stats") == 0)) {
5816 cmd_pipeline_port_in_stats(softnic, tokens, n_tokens,
5821 if (n_tokens >= 6 &&
5822 (strcmp(tokens[2], "port") == 0) &&
5823 (strcmp(tokens[3], "in") == 0) &&
5824 (strcmp(tokens[5], "enable") == 0)) {
5825 cmd_softnic_pipeline_port_in_enable(softnic, tokens, n_tokens,
5830 if (n_tokens >= 6 &&
5831 (strcmp(tokens[2], "port") == 0) &&
5832 (strcmp(tokens[3], "in") == 0) &&
5833 (strcmp(tokens[5], "disable") == 0)) {
5834 cmd_softnic_pipeline_port_in_disable(softnic, tokens, n_tokens,
5839 if (n_tokens >= 6 &&
5840 (strcmp(tokens[2], "port") == 0) &&
5841 (strcmp(tokens[3], "out") == 0) &&
5842 (strcmp(tokens[5], "stats") == 0)) {
5843 cmd_pipeline_port_out_stats(softnic, tokens, n_tokens,
5848 if (n_tokens >= 5 &&
5849 (strcmp(tokens[2], "table") == 0) &&
5850 (strcmp(tokens[4], "stats") == 0)) {
5851 cmd_pipeline_table_stats(softnic, tokens, n_tokens,
5856 if (n_tokens >= 7 &&
5857 (strcmp(tokens[2], "table") == 0) &&
5858 (strcmp(tokens[4], "rule") == 0) &&
5859 (strcmp(tokens[5], "add") == 0) &&
5860 (strcmp(tokens[6], "match") == 0)) {
5861 if (n_tokens >= 8 &&
5862 (strcmp(tokens[7], "default") == 0)) {
5863 cmd_softnic_pipeline_table_rule_add_default(softnic, tokens,
5864 n_tokens, out, out_size);
5868 cmd_softnic_pipeline_table_rule_add(softnic, tokens, n_tokens,
5873 if (n_tokens >= 7 &&
5874 (strcmp(tokens[2], "table") == 0) &&
5875 (strcmp(tokens[4], "rule") == 0) &&
5876 (strcmp(tokens[5], "add") == 0) &&
5877 (strcmp(tokens[6], "bulk") == 0)) {
5878 cmd_softnic_pipeline_table_rule_add_bulk(softnic, tokens,
5879 n_tokens, out, out_size);
5883 if (n_tokens >= 7 &&
5884 (strcmp(tokens[2], "table") == 0) &&
5885 (strcmp(tokens[4], "rule") == 0) &&
5886 (strcmp(tokens[5], "delete") == 0) &&
5887 (strcmp(tokens[6], "match") == 0)) {
5888 if (n_tokens >= 8 &&
5889 (strcmp(tokens[7], "default") == 0)) {
5890 cmd_softnic_pipeline_table_rule_delete_default(softnic, tokens,
5891 n_tokens, out, out_size);
5895 cmd_softnic_pipeline_table_rule_delete(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], "stats") == 0)) {
5905 cmd_softnic_pipeline_table_rule_stats_read(softnic, tokens, n_tokens,
5910 if (n_tokens >= 8 &&
5911 (strcmp(tokens[2], "table") == 0) &&
5912 (strcmp(tokens[4], "meter") == 0) &&
5913 (strcmp(tokens[5], "profile") == 0) &&
5914 (strcmp(tokens[7], "add") == 0)) {
5915 cmd_pipeline_table_meter_profile_add(softnic, tokens, n_tokens,
5920 if (n_tokens >= 8 &&
5921 (strcmp(tokens[2], "table") == 0) &&
5922 (strcmp(tokens[4], "meter") == 0) &&
5923 (strcmp(tokens[5], "profile") == 0) &&
5924 (strcmp(tokens[7], "delete") == 0)) {
5925 cmd_pipeline_table_meter_profile_delete(softnic, tokens,
5926 n_tokens, out, out_size);
5930 if (n_tokens >= 7 &&
5931 (strcmp(tokens[2], "table") == 0) &&
5932 (strcmp(tokens[4], "rule") == 0) &&
5933 (strcmp(tokens[5], "read") == 0) &&
5934 (strcmp(tokens[6], "meter") == 0)) {
5935 cmd_pipeline_table_rule_meter_read(softnic, tokens, n_tokens,
5940 if (n_tokens >= 5 &&
5941 (strcmp(tokens[2], "table") == 0) &&
5942 (strcmp(tokens[4], "dscp") == 0)) {
5943 cmd_pipeline_table_dscp(softnic, tokens, n_tokens,
5948 if (n_tokens >= 7 &&
5949 (strcmp(tokens[2], "table") == 0) &&
5950 (strcmp(tokens[4], "rule") == 0) &&
5951 (strcmp(tokens[5], "read") == 0) &&
5952 (strcmp(tokens[6], "ttl") == 0)) {
5953 cmd_softnic_pipeline_table_rule_ttl_read(softnic, tokens, n_tokens,
5959 if (strcmp(tokens[0], "thread") == 0) {
5960 if (n_tokens >= 5 &&
5961 (strcmp(tokens[4], "enable") == 0)) {
5962 cmd_softnic_thread_pipeline_enable(softnic, tokens, n_tokens,
5967 if (n_tokens >= 5 &&
5968 (strcmp(tokens[4], "disable") == 0)) {
5969 cmd_softnic_thread_pipeline_disable(softnic, tokens, n_tokens,
5975 if (strcmp(tokens[0], "flowapi") == 0) {
5976 cmd_softnic_flowapi_map(softnic, tokens, n_tokens, out,
5981 snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
5985 softnic_cli_script_process(struct pmd_internals *softnic,
5986 const char *file_name,
5987 size_t msg_in_len_max,
5988 size_t msg_out_len_max)
5990 char *msg_in = NULL, *msg_out = NULL;
5993 /* Check input arguments */
5994 if (file_name == NULL ||
5995 (strlen(file_name) == 0) ||
5996 msg_in_len_max == 0 ||
5997 msg_out_len_max == 0)
6000 msg_in = malloc(msg_in_len_max + 1);
6001 msg_out = malloc(msg_out_len_max + 1);
6002 if (msg_in == NULL ||
6009 /* Open input file */
6010 f = fopen(file_name, "r");
6019 if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
6022 printf("%s", msg_in);
6025 softnic_cli_process(msg_in,
6030 if (strlen(msg_out))
6031 printf("%s", msg_out);
6042 cli_rule_file_process(const char *file_name,
6043 size_t line_len_max,
6044 struct softnic_table_rule_match *m,
6045 struct softnic_table_rule_action *a,
6047 uint32_t *line_number,
6053 uint32_t rule_id, line_id;
6056 /* Check input arguments */
6057 if (file_name == NULL ||
6058 (strlen(file_name) == 0) ||
6059 line_len_max == 0) {
6064 /* Memory allocation */
6065 line = malloc(line_len_max + 1);
6072 f = fopen(file_name, "r");
6080 for (line_id = 1, rule_id = 0; rule_id < *n_rules; line_id++) {
6081 char *tokens[CMD_MAX_TOKENS];
6082 uint32_t n_tokens, n_tokens_parsed, t0;
6084 /* Read next line from file. */
6085 if (fgets(line, line_len_max + 1, f) == NULL)
6089 if (is_comment(line))
6093 n_tokens = RTE_DIM(tokens);
6094 status = softnic_parse_tokenize_string(line, tokens, &n_tokens);
6106 n_tokens_parsed = parse_match(tokens + t0,
6111 if (n_tokens_parsed == 0) {
6115 t0 += n_tokens_parsed;
6118 n_tokens_parsed = parse_table_action(tokens + t0,
6123 if (n_tokens_parsed == 0) {
6127 t0 += n_tokens_parsed;
6129 /* Line completed. */
6130 if (t0 < n_tokens) {
6135 /* Increment rule count */
6146 *line_number = line_id;