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 | qinq_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;
1628 } else if (strcmp(tokens[t0 + 1], "qinq_pppoe") == 0) {
1629 p.encap.encap_mask =
1630 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE;
1632 snprintf(out, out_size, MSG_ARG_MISMATCH, "encap");
1636 p.action_mask |= 1LLU << RTE_TABLE_ACTION_ENCAP;
1637 t0 += 2 + n_extra_tokens;
1640 if (t0 < n_tokens &&
1641 (strcmp(tokens[t0], "nat") == 0)) {
1642 if (n_tokens < t0 + 4) {
1643 snprintf(out, out_size, MSG_ARG_MISMATCH,
1644 "table action profile nat");
1648 if (strcmp(tokens[t0 + 1], "src") == 0) {
1649 p.nat.source_nat = 1;
1650 } else if (strcmp(tokens[t0 + 1], "dst") == 0) {
1651 p.nat.source_nat = 0;
1653 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1658 if (strcmp(tokens[t0 + 2], "proto") != 0) {
1659 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "proto");
1663 if (strcmp(tokens[t0 + 3], "tcp") == 0) {
1665 } else if (strcmp(tokens[t0 + 3], "udp") == 0) {
1668 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1673 p.action_mask |= 1LLU << RTE_TABLE_ACTION_NAT;
1677 if (t0 < n_tokens &&
1678 (strcmp(tokens[t0], "ttl") == 0)) {
1679 if (n_tokens < t0 + 4) {
1680 snprintf(out, out_size, MSG_ARG_MISMATCH,
1681 "table action profile ttl");
1685 if (strcmp(tokens[t0 + 1], "drop") == 0) {
1687 } else if (strcmp(tokens[t0 + 1], "fwd") == 0) {
1690 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1695 if (strcmp(tokens[t0 + 2], "stats") != 0) {
1696 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1700 if (strcmp(tokens[t0 + 3], "none") == 0) {
1701 p.ttl.n_packets_enabled = 0;
1702 } else if (strcmp(tokens[t0 + 3], "pkts") == 0) {
1703 p.ttl.n_packets_enabled = 1;
1705 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1710 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TTL;
1714 if (t0 < n_tokens &&
1715 (strcmp(tokens[t0], "stats") == 0)) {
1716 if (n_tokens < t0 + 2) {
1717 snprintf(out, out_size, MSG_ARG_MISMATCH,
1718 "table action profile stats");
1722 if (strcmp(tokens[t0 + 1], "pkts") == 0) {
1723 p.stats.n_packets_enabled = 1;
1724 p.stats.n_bytes_enabled = 0;
1725 } else if (strcmp(tokens[t0 + 1], "bytes") == 0) {
1726 p.stats.n_packets_enabled = 0;
1727 p.stats.n_bytes_enabled = 1;
1728 } else if (strcmp(tokens[t0 + 1], "both") == 0) {
1729 p.stats.n_packets_enabled = 1;
1730 p.stats.n_bytes_enabled = 1;
1732 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1733 "pkts or bytes or both");
1737 p.action_mask |= 1LLU << RTE_TABLE_ACTION_STATS;
1741 if (t0 < n_tokens &&
1742 (strcmp(tokens[t0], "time") == 0)) {
1743 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TIME;
1747 if (t0 < n_tokens &&
1748 (strcmp(tokens[t0], "tag") == 0)) {
1749 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TAG;
1753 if (t0 < n_tokens &&
1754 (strcmp(tokens[t0], "decap") == 0)) {
1755 p.action_mask |= 1LLU << RTE_TABLE_ACTION_DECAP;
1759 if (t0 < n_tokens && (strcmp(tokens[t0], "sym_crypto") == 0)) {
1760 struct softnic_cryptodev *cryptodev;
1762 if (n_tokens < t0 + 5 ||
1763 strcmp(tokens[t0 + 1], "dev") ||
1764 strcmp(tokens[t0 + 3], "offset")) {
1765 snprintf(out, out_size, MSG_ARG_MISMATCH,
1766 "table action profile sym_crypto");
1770 cryptodev = softnic_cryptodev_find(softnic, tokens[t0 + 2]);
1771 if (cryptodev == NULL) {
1772 snprintf(out, out_size, MSG_ARG_INVALID,
1773 "table action profile sym_crypto");
1777 p.sym_crypto.cryptodev_id = cryptodev->dev_id;
1779 if (softnic_parser_read_uint32(&p.sym_crypto.op_offset,
1780 tokens[t0 + 4]) != 0) {
1781 snprintf(out, out_size, MSG_ARG_INVALID,
1782 "table action profile sym_crypto");
1786 p.sym_crypto.mp_create = cryptodev->mp_create;
1787 p.sym_crypto.mp_init = cryptodev->mp_init;
1789 p.action_mask |= 1LLU << RTE_TABLE_ACTION_SYM_CRYPTO;
1794 if (t0 < n_tokens) {
1795 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1799 ap = softnic_table_action_profile_create(softnic, name, &p);
1801 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1807 * pipeline <pipeline_name>
1808 * period <timer_period_ms>
1809 * offset_port_id <offset_port_id>
1812 cmd_pipeline(struct pmd_internals *softnic,
1818 struct pipeline_params p;
1820 struct pipeline *pipeline;
1822 if (n_tokens != 6) {
1823 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1829 if (strcmp(tokens[2], "period") != 0) {
1830 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "period");
1834 if (softnic_parser_read_uint32(&p.timer_period_ms,
1836 snprintf(out, out_size, MSG_ARG_INVALID, "timer_period_ms");
1840 if (strcmp(tokens[4], "offset_port_id") != 0) {
1841 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset_port_id");
1845 if (softnic_parser_read_uint32(&p.offset_port_id,
1847 snprintf(out, out_size, MSG_ARG_INVALID, "offset_port_id");
1851 pipeline = softnic_pipeline_create(softnic, name, &p);
1852 if (pipeline == NULL) {
1853 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1859 * pipeline <pipeline_name> port in
1861 * link <link_name> rxq <queue_id>
1863 * | tmgr <tmgr_name>
1864 * | tap <tap_name> mempool <mempool_name> mtu <mtu>
1865 * | source mempool <mempool_name> file <file_name> bpp <n_bytes_per_pkt>
1866 * | cryptodev <cryptodev_name> rxq <queue_id>
1867 * [action <port_in_action_profile_name>]
1871 cmd_pipeline_port_in(struct pmd_internals *softnic,
1877 struct softnic_port_in_params p;
1878 char *pipeline_name;
1880 int enabled, status;
1882 memset(&p, 0, sizeof(p));
1885 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1889 pipeline_name = tokens[1];
1891 if (strcmp(tokens[2], "port") != 0) {
1892 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1896 if (strcmp(tokens[3], "in") != 0) {
1897 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1901 if (strcmp(tokens[4], "bsz") != 0) {
1902 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1906 if (softnic_parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1907 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1913 if (strcmp(tokens[t0], "link") == 0) {
1914 if (n_tokens < t0 + 4) {
1915 snprintf(out, out_size, MSG_ARG_MISMATCH,
1916 "pipeline port in link");
1920 p.type = PORT_IN_RXQ;
1922 strlcpy(p.dev_name, tokens[t0 + 1], sizeof(p.dev_name));
1924 if (strcmp(tokens[t0 + 2], "rxq") != 0) {
1925 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
1929 if (softnic_parser_read_uint16(&p.rxq.queue_id,
1930 tokens[t0 + 3]) != 0) {
1931 snprintf(out, out_size, MSG_ARG_INVALID,
1936 } else if (strcmp(tokens[t0], "swq") == 0) {
1937 if (n_tokens < t0 + 2) {
1938 snprintf(out, out_size, MSG_ARG_MISMATCH,
1939 "pipeline port in swq");
1943 p.type = PORT_IN_SWQ;
1945 strlcpy(p.dev_name, tokens[t0 + 1], sizeof(p.dev_name));
1948 } else if (strcmp(tokens[t0], "tmgr") == 0) {
1949 if (n_tokens < t0 + 2) {
1950 snprintf(out, out_size, MSG_ARG_MISMATCH,
1951 "pipeline port in tmgr");
1955 p.type = PORT_IN_TMGR;
1957 strlcpy(p.dev_name, tokens[t0 + 1], sizeof(p.dev_name));
1960 } else if (strcmp(tokens[t0], "tap") == 0) {
1961 if (n_tokens < t0 + 6) {
1962 snprintf(out, out_size, MSG_ARG_MISMATCH,
1963 "pipeline port in tap");
1967 p.type = PORT_IN_TAP;
1969 strlcpy(p.dev_name, tokens[t0 + 1], sizeof(p.dev_name));
1971 if (strcmp(tokens[t0 + 2], "mempool") != 0) {
1972 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1977 p.tap.mempool_name = tokens[t0 + 3];
1979 if (strcmp(tokens[t0 + 4], "mtu") != 0) {
1980 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1985 if (softnic_parser_read_uint32(&p.tap.mtu,
1986 tokens[t0 + 5]) != 0) {
1987 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
1992 } else if (strcmp(tokens[t0], "source") == 0) {
1993 if (n_tokens < t0 + 6) {
1994 snprintf(out, out_size, MSG_ARG_MISMATCH,
1995 "pipeline port in source");
1999 p.type = PORT_IN_SOURCE;
2001 if (strcmp(tokens[t0 + 1], "mempool") != 0) {
2002 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2007 p.source.mempool_name = tokens[t0 + 2];
2009 if (strcmp(tokens[t0 + 3], "file") != 0) {
2010 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2015 p.source.file_name = tokens[t0 + 4];
2017 if (strcmp(tokens[t0 + 5], "bpp") != 0) {
2018 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2023 if (softnic_parser_read_uint32(&p.source.n_bytes_per_pkt,
2024 tokens[t0 + 6]) != 0) {
2025 snprintf(out, out_size, MSG_ARG_INVALID,
2031 } else if (strcmp(tokens[t0], "cryptodev") == 0) {
2032 if (n_tokens < t0 + 3) {
2033 snprintf(out, out_size, MSG_ARG_MISMATCH,
2034 "pipeline port in cryptodev");
2038 p.type = PORT_IN_CRYPTODEV;
2040 strlcpy(p.dev_name, tokens[t0 + 1], sizeof(p.dev_name));
2041 if (softnic_parser_read_uint16(&p.rxq.queue_id,
2042 tokens[t0 + 3]) != 0) {
2043 snprintf(out, out_size, MSG_ARG_INVALID,
2048 p.cryptodev.arg_callback = NULL;
2049 p.cryptodev.f_callback = NULL;
2053 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
2057 if (n_tokens > t0 &&
2058 (strcmp(tokens[t0], "action") == 0)) {
2059 if (n_tokens < t0 + 2) {
2060 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
2064 strlcpy(p.action_profile_name, tokens[t0 + 1],
2065 sizeof(p.action_profile_name));
2071 if (n_tokens > t0 &&
2072 (strcmp(tokens[t0], "disabled") == 0)) {
2078 if (n_tokens != t0) {
2079 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2083 status = softnic_pipeline_port_in_create(softnic,
2088 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2094 * pipeline <pipeline_name> port out
2096 * link <link_name> txq <txq_id>
2098 * | tmgr <tmgr_name>
2100 * | sink [file <file_name> pkts <max_n_pkts>]
2101 * | cryptodev <cryptodev_name> txq <txq_id> offset <crypto_op_offset>
2104 cmd_pipeline_port_out(struct pmd_internals *softnic,
2110 struct softnic_port_out_params p;
2111 char *pipeline_name;
2114 memset(&p, 0, sizeof(p));
2117 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2121 pipeline_name = tokens[1];
2123 if (strcmp(tokens[2], "port") != 0) {
2124 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2128 if (strcmp(tokens[3], "out") != 0) {
2129 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
2133 if (strcmp(tokens[4], "bsz") != 0) {
2134 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
2138 if (softnic_parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
2139 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
2143 if (strcmp(tokens[6], "link") == 0) {
2144 if (n_tokens != 10) {
2145 snprintf(out, out_size, MSG_ARG_MISMATCH,
2146 "pipeline port out link");
2150 p.type = PORT_OUT_TXQ;
2152 strlcpy(p.dev_name, tokens[7], sizeof(p.dev_name));
2154 if (strcmp(tokens[8], "txq") != 0) {
2155 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
2159 if (softnic_parser_read_uint16(&p.txq.queue_id,
2161 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
2164 } else if (strcmp(tokens[6], "swq") == 0) {
2165 if (n_tokens != 8) {
2166 snprintf(out, out_size, MSG_ARG_MISMATCH,
2167 "pipeline port out swq");
2171 p.type = PORT_OUT_SWQ;
2173 strlcpy(p.dev_name, tokens[7], sizeof(p.dev_name));
2174 } else if (strcmp(tokens[6], "tmgr") == 0) {
2175 if (n_tokens != 8) {
2176 snprintf(out, out_size, MSG_ARG_MISMATCH,
2177 "pipeline port out tmgr");
2181 p.type = PORT_OUT_TMGR;
2183 strlcpy(p.dev_name, tokens[7], sizeof(p.dev_name));
2184 } else if (strcmp(tokens[6], "tap") == 0) {
2185 if (n_tokens != 8) {
2186 snprintf(out, out_size, MSG_ARG_MISMATCH,
2187 "pipeline port out tap");
2191 p.type = PORT_OUT_TAP;
2193 strlcpy(p.dev_name, tokens[7], sizeof(p.dev_name));
2194 } else if (strcmp(tokens[6], "sink") == 0) {
2195 if ((n_tokens != 7) && (n_tokens != 11)) {
2196 snprintf(out, out_size, MSG_ARG_MISMATCH,
2197 "pipeline port out sink");
2201 p.type = PORT_OUT_SINK;
2203 if (n_tokens == 7) {
2204 p.sink.file_name = NULL;
2205 p.sink.max_n_pkts = 0;
2207 if (strcmp(tokens[7], "file") != 0) {
2208 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2213 p.sink.file_name = tokens[8];
2215 if (strcmp(tokens[9], "pkts") != 0) {
2216 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pkts");
2220 if (softnic_parser_read_uint32(&p.sink.max_n_pkts,
2222 snprintf(out, out_size, MSG_ARG_INVALID, "max_n_pkts");
2226 } else if (strcmp(tokens[6], "cryptodev") == 0) {
2227 if (n_tokens != 12) {
2228 snprintf(out, out_size, MSG_ARG_MISMATCH,
2229 "pipeline port out cryptodev");
2233 p.type = PORT_OUT_CRYPTODEV;
2235 strlcpy(p.dev_name, tokens[7], sizeof(p.dev_name));
2237 if (strcmp(tokens[8], "txq")) {
2238 snprintf(out, out_size, MSG_ARG_MISMATCH,
2239 "pipeline port out cryptodev");
2243 if (softnic_parser_read_uint16(&p.cryptodev.queue_id, tokens[9])
2245 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
2249 if (strcmp(tokens[10], "offset")) {
2250 snprintf(out, out_size, MSG_ARG_MISMATCH,
2251 "pipeline port out cryptodev");
2255 if (softnic_parser_read_uint32(&p.cryptodev.op_offset,
2257 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
2261 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
2265 status = softnic_pipeline_port_out_create(softnic, pipeline_name, &p);
2267 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2273 * pipeline <pipeline_name> table
2277 * offset <ip_header_offset>
2280 * offset <key_offset>
2286 * offset <key_offset>
2287 * buckets <n_buckets>
2291 * offset <ip_header_offset>
2294 * [action <table_action_profile_name>]
2297 cmd_pipeline_table(struct pmd_internals *softnic,
2303 struct softnic_table_params p;
2304 char *pipeline_name;
2308 memset(&p, 0, sizeof(p));
2311 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2315 pipeline_name = tokens[1];
2317 if (strcmp(tokens[2], "table") != 0) {
2318 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2322 if (strcmp(tokens[3], "match") != 0) {
2323 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
2328 if (strcmp(tokens[t0], "acl") == 0) {
2329 if (n_tokens < t0 + 6) {
2330 snprintf(out, out_size, MSG_ARG_MISMATCH,
2331 "pipeline table acl");
2335 p.match_type = TABLE_ACL;
2337 if (strcmp(tokens[t0 + 1], "ipv4") == 0) {
2338 p.match.acl.ip_version = 1;
2339 } else if (strcmp(tokens[t0 + 1], "ipv6") == 0) {
2340 p.match.acl.ip_version = 0;
2342 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2347 if (strcmp(tokens[t0 + 2], "offset") != 0) {
2348 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2352 if (softnic_parser_read_uint32(&p.match.acl.ip_header_offset,
2353 tokens[t0 + 3]) != 0) {
2354 snprintf(out, out_size, MSG_ARG_INVALID,
2355 "ip_header_offset");
2359 if (strcmp(tokens[t0 + 4], "size") != 0) {
2360 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2364 if (softnic_parser_read_uint32(&p.match.acl.n_rules,
2365 tokens[t0 + 5]) != 0) {
2366 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2371 } else if (strcmp(tokens[t0], "array") == 0) {
2372 if (n_tokens < t0 + 5) {
2373 snprintf(out, out_size, MSG_ARG_MISMATCH,
2374 "pipeline table array");
2378 p.match_type = TABLE_ARRAY;
2380 if (strcmp(tokens[t0 + 1], "offset") != 0) {
2381 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2385 if (softnic_parser_read_uint32(&p.match.array.key_offset,
2386 tokens[t0 + 2]) != 0) {
2387 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2391 if (strcmp(tokens[t0 + 3], "size") != 0) {
2392 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2396 if (softnic_parser_read_uint32(&p.match.array.n_keys,
2397 tokens[t0 + 4]) != 0) {
2398 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2403 } else if (strcmp(tokens[t0], "hash") == 0) {
2404 uint32_t key_mask_size = TABLE_RULE_MATCH_SIZE_MAX;
2406 if (n_tokens < t0 + 12) {
2407 snprintf(out, out_size, MSG_ARG_MISMATCH,
2408 "pipeline table hash");
2412 p.match_type = TABLE_HASH;
2414 if (strcmp(tokens[t0 + 1], "ext") == 0) {
2415 p.match.hash.extendable_bucket = 1;
2416 } else if (strcmp(tokens[t0 + 1], "lru") == 0) {
2417 p.match.hash.extendable_bucket = 0;
2419 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2424 if (strcmp(tokens[t0 + 2], "key") != 0) {
2425 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
2429 if ((softnic_parser_read_uint32(&p.match.hash.key_size,
2430 tokens[t0 + 3]) != 0) ||
2431 p.match.hash.key_size == 0 ||
2432 p.match.hash.key_size > TABLE_RULE_MATCH_SIZE_MAX) {
2433 snprintf(out, out_size, MSG_ARG_INVALID, "key_size");
2437 if (strcmp(tokens[t0 + 4], "mask") != 0) {
2438 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
2442 if ((softnic_parse_hex_string(tokens[t0 + 5],
2443 p.match.hash.key_mask, &key_mask_size) != 0) ||
2444 key_mask_size != p.match.hash.key_size) {
2445 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
2449 if (strcmp(tokens[t0 + 6], "offset") != 0) {
2450 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2454 if (softnic_parser_read_uint32(&p.match.hash.key_offset,
2455 tokens[t0 + 7]) != 0) {
2456 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2460 if (strcmp(tokens[t0 + 8], "buckets") != 0) {
2461 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buckets");
2465 if (softnic_parser_read_uint32(&p.match.hash.n_buckets,
2466 tokens[t0 + 9]) != 0) {
2467 snprintf(out, out_size, MSG_ARG_INVALID, "n_buckets");
2471 if (strcmp(tokens[t0 + 10], "size") != 0) {
2472 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2476 if (softnic_parser_read_uint32(&p.match.hash.n_keys,
2477 tokens[t0 + 11]) != 0) {
2478 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2483 } else if (strcmp(tokens[t0], "lpm") == 0) {
2484 if (n_tokens < t0 + 6) {
2485 snprintf(out, out_size, MSG_ARG_MISMATCH,
2486 "pipeline table lpm");
2490 p.match_type = TABLE_LPM;
2492 if (strcmp(tokens[t0 + 1], "ipv4") == 0) {
2493 p.match.lpm.key_size = 4;
2494 } else if (strcmp(tokens[t0 + 1], "ipv6") == 0) {
2495 p.match.lpm.key_size = 16;
2497 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2502 if (strcmp(tokens[t0 + 2], "offset") != 0) {
2503 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2507 if (softnic_parser_read_uint32(&p.match.lpm.key_offset,
2508 tokens[t0 + 3]) != 0) {
2509 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2513 if (strcmp(tokens[t0 + 4], "size") != 0) {
2514 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2518 if (softnic_parser_read_uint32(&p.match.lpm.n_rules,
2519 tokens[t0 + 5]) != 0) {
2520 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2525 } else if (strcmp(tokens[t0], "stub") == 0) {
2526 p.match_type = TABLE_STUB;
2530 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
2534 if (n_tokens > t0 &&
2535 (strcmp(tokens[t0], "action") == 0)) {
2536 if (n_tokens < t0 + 2) {
2537 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
2541 strlcpy(p.action_profile_name, tokens[t0 + 1],
2542 sizeof(p.action_profile_name));
2547 if (n_tokens > t0) {
2548 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2552 status = softnic_pipeline_table_create(softnic, pipeline_name, &p);
2554 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2560 * pipeline <pipeline_name> port in <port_id> table <table_id>
2563 cmd_pipeline_port_in_table(struct pmd_internals *softnic,
2569 char *pipeline_name;
2570 uint32_t port_id, table_id;
2573 if (n_tokens != 7) {
2574 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2578 pipeline_name = tokens[1];
2580 if (strcmp(tokens[2], "port") != 0) {
2581 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2585 if (strcmp(tokens[3], "in") != 0) {
2586 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2590 if (softnic_parser_read_uint32(&port_id, tokens[4]) != 0) {
2591 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2595 if (strcmp(tokens[5], "table") != 0) {
2596 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2600 if (softnic_parser_read_uint32(&table_id, tokens[6]) != 0) {
2601 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2605 status = softnic_pipeline_port_in_connect_to_table(softnic,
2610 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2616 * pipeline <pipeline_name> port in <port_id> stats read [clear]
2619 #define MSG_PIPELINE_PORT_IN_STATS \
2620 "Pkts in: %" PRIu64 "\n" \
2621 "Pkts dropped by AH: %" PRIu64 "\n" \
2622 "Pkts dropped by other: %" PRIu64 "\n"
2625 cmd_pipeline_port_in_stats(struct pmd_internals *softnic,
2631 struct rte_pipeline_port_in_stats stats;
2632 char *pipeline_name;
2636 if (n_tokens != 7 &&
2638 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2642 pipeline_name = tokens[1];
2644 if (strcmp(tokens[2], "port") != 0) {
2645 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2649 if (strcmp(tokens[3], "in") != 0) {
2650 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2654 if (softnic_parser_read_uint32(&port_id, tokens[4]) != 0) {
2655 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2659 if (strcmp(tokens[5], "stats") != 0) {
2660 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2664 if (strcmp(tokens[6], "read") != 0) {
2665 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2670 if (n_tokens == 8) {
2671 if (strcmp(tokens[7], "clear") != 0) {
2672 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2679 status = softnic_pipeline_port_in_stats_read(softnic,
2685 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2689 snprintf(out, out_size, MSG_PIPELINE_PORT_IN_STATS,
2690 stats.stats.n_pkts_in,
2691 stats.n_pkts_dropped_by_ah,
2692 stats.stats.n_pkts_drop);
2696 * pipeline <pipeline_name> port in <port_id> enable
2699 cmd_softnic_pipeline_port_in_enable(struct pmd_internals *softnic,
2705 char *pipeline_name;
2709 if (n_tokens != 6) {
2710 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2714 pipeline_name = tokens[1];
2716 if (strcmp(tokens[2], "port") != 0) {
2717 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2721 if (strcmp(tokens[3], "in") != 0) {
2722 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2726 if (softnic_parser_read_uint32(&port_id, tokens[4]) != 0) {
2727 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2731 if (strcmp(tokens[5], "enable") != 0) {
2732 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
2736 status = softnic_pipeline_port_in_enable(softnic, pipeline_name, port_id);
2738 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2744 * pipeline <pipeline_name> port in <port_id> disable
2747 cmd_softnic_pipeline_port_in_disable(struct pmd_internals *softnic,
2753 char *pipeline_name;
2757 if (n_tokens != 6) {
2758 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2762 pipeline_name = tokens[1];
2764 if (strcmp(tokens[2], "port") != 0) {
2765 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2769 if (strcmp(tokens[3], "in") != 0) {
2770 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2774 if (softnic_parser_read_uint32(&port_id, tokens[4]) != 0) {
2775 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2779 if (strcmp(tokens[5], "disable") != 0) {
2780 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
2784 status = softnic_pipeline_port_in_disable(softnic, pipeline_name, port_id);
2786 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2792 * pipeline <pipeline_name> port out <port_id> stats read [clear]
2794 #define MSG_PIPELINE_PORT_OUT_STATS \
2795 "Pkts in: %" PRIu64 "\n" \
2796 "Pkts dropped by AH: %" PRIu64 "\n" \
2797 "Pkts dropped by other: %" PRIu64 "\n"
2800 cmd_pipeline_port_out_stats(struct pmd_internals *softnic,
2806 struct rte_pipeline_port_out_stats stats;
2807 char *pipeline_name;
2811 if (n_tokens != 7 &&
2813 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2817 pipeline_name = tokens[1];
2819 if (strcmp(tokens[2], "port") != 0) {
2820 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2824 if (strcmp(tokens[3], "out") != 0) {
2825 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
2829 if (softnic_parser_read_uint32(&port_id, tokens[4]) != 0) {
2830 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2834 if (strcmp(tokens[5], "stats") != 0) {
2835 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2839 if (strcmp(tokens[6], "read") != 0) {
2840 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2845 if (n_tokens == 8) {
2846 if (strcmp(tokens[7], "clear") != 0) {
2847 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2854 status = softnic_pipeline_port_out_stats_read(softnic,
2860 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2864 snprintf(out, out_size, MSG_PIPELINE_PORT_OUT_STATS,
2865 stats.stats.n_pkts_in,
2866 stats.n_pkts_dropped_by_ah,
2867 stats.stats.n_pkts_drop);
2871 * pipeline <pipeline_name> table <table_id> stats read [clear]
2873 #define MSG_PIPELINE_TABLE_STATS \
2874 "Pkts in: %" PRIu64 "\n" \
2875 "Pkts in with lookup miss: %" PRIu64 "\n" \
2876 "Pkts in with lookup hit dropped by AH: %" PRIu64 "\n" \
2877 "Pkts in with lookup hit dropped by others: %" PRIu64 "\n" \
2878 "Pkts in with lookup miss dropped by AH: %" PRIu64 "\n" \
2879 "Pkts in with lookup miss dropped by others: %" PRIu64 "\n"
2882 cmd_pipeline_table_stats(struct pmd_internals *softnic,
2888 struct rte_pipeline_table_stats stats;
2889 char *pipeline_name;
2893 if (n_tokens != 6 &&
2895 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2899 pipeline_name = tokens[1];
2901 if (strcmp(tokens[2], "table") != 0) {
2902 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2906 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
2907 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2911 if (strcmp(tokens[4], "stats") != 0) {
2912 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2916 if (strcmp(tokens[5], "read") != 0) {
2917 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2922 if (n_tokens == 7) {
2923 if (strcmp(tokens[6], "clear") != 0) {
2924 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2931 status = softnic_pipeline_table_stats_read(softnic,
2937 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2941 snprintf(out, out_size, MSG_PIPELINE_TABLE_STATS,
2942 stats.stats.n_pkts_in,
2943 stats.stats.n_pkts_lookup_miss,
2944 stats.n_pkts_dropped_by_lkp_hit_ah,
2945 stats.n_pkts_dropped_lkp_hit,
2946 stats.n_pkts_dropped_by_lkp_miss_ah,
2947 stats.n_pkts_dropped_lkp_miss);
2955 * priority <priority>
2956 * ipv4 | ipv6 <sa> <sa_depth> <da> <da_depth>
2957 * <sp0> <sp1> <dp0> <dp1> <proto>
2961 * | ipv4_5tuple <sa> <da> <sp> <dp> <proto>
2962 * | ipv6_5tuple <sa> <da> <sp> <dp> <proto>
2963 * | ipv4_addr <addr>
2964 * | ipv6_addr <addr>
2965 * | qinq <svlan> <cvlan>
2967 * ipv4 | ipv6 <addr> <depth>
2969 struct pkt_key_qinq {
2970 uint16_t ethertype_svlan;
2972 uint16_t ethertype_cvlan;
2974 } __attribute__((__packed__));
2976 struct pkt_key_ipv4_5tuple {
2977 uint8_t time_to_live;
2979 uint16_t hdr_checksum;
2984 } __attribute__((__packed__));
2986 struct pkt_key_ipv6_5tuple {
2987 uint16_t payload_length;
2994 } __attribute__((__packed__));
2996 struct pkt_key_ipv4_addr {
2998 } __attribute__((__packed__));
3000 struct pkt_key_ipv6_addr {
3002 } __attribute__((__packed__));
3005 parse_match(char **tokens,
3009 struct softnic_table_rule_match *m)
3011 memset(m, 0, sizeof(*m));
3016 if (strcmp(tokens[0], "match") != 0) {
3017 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
3021 if (strcmp(tokens[1], "acl") == 0) {
3022 if (n_tokens < 14) {
3023 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3027 m->match_type = TABLE_ACL;
3029 if (strcmp(tokens[2], "priority") != 0) {
3030 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "priority");
3034 if (softnic_parser_read_uint32(&m->match.acl.priority,
3036 snprintf(out, out_size, MSG_ARG_INVALID, "priority");
3040 if (strcmp(tokens[4], "ipv4") == 0) {
3041 struct in_addr saddr, daddr;
3043 m->match.acl.ip_version = 1;
3045 if (softnic_parse_ipv4_addr(tokens[5], &saddr) != 0) {
3046 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
3049 m->match.acl.ipv4.sa = rte_be_to_cpu_32(saddr.s_addr);
3051 if (softnic_parse_ipv4_addr(tokens[7], &daddr) != 0) {
3052 snprintf(out, out_size, MSG_ARG_INVALID, "da");
3055 m->match.acl.ipv4.da = rte_be_to_cpu_32(daddr.s_addr);
3056 } else if (strcmp(tokens[4], "ipv6") == 0) {
3057 struct in6_addr saddr, daddr;
3059 m->match.acl.ip_version = 0;
3061 if (softnic_parse_ipv6_addr(tokens[5], &saddr) != 0) {
3062 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
3065 memcpy(m->match.acl.ipv6.sa, saddr.s6_addr, 16);
3067 if (softnic_parse_ipv6_addr(tokens[7], &daddr) != 0) {
3068 snprintf(out, out_size, MSG_ARG_INVALID, "da");
3071 memcpy(m->match.acl.ipv6.da, daddr.s6_addr, 16);
3073 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
3078 if (softnic_parser_read_uint32(&m->match.acl.sa_depth,
3080 snprintf(out, out_size, MSG_ARG_INVALID, "sa_depth");
3084 if (softnic_parser_read_uint32(&m->match.acl.da_depth,
3086 snprintf(out, out_size, MSG_ARG_INVALID, "da_depth");
3090 if (softnic_parser_read_uint16(&m->match.acl.sp0, tokens[9]) != 0) {
3091 snprintf(out, out_size, MSG_ARG_INVALID, "sp0");
3095 if (softnic_parser_read_uint16(&m->match.acl.sp1, tokens[10]) != 0) {
3096 snprintf(out, out_size, MSG_ARG_INVALID, "sp1");
3100 if (softnic_parser_read_uint16(&m->match.acl.dp0, tokens[11]) != 0) {
3101 snprintf(out, out_size, MSG_ARG_INVALID, "dp0");
3105 if (softnic_parser_read_uint16(&m->match.acl.dp1, tokens[12]) != 0) {
3106 snprintf(out, out_size, MSG_ARG_INVALID, "dp1");
3110 if (softnic_parser_read_uint8(&m->match.acl.proto, tokens[13]) != 0) {
3111 snprintf(out, out_size, MSG_ARG_INVALID, "proto");
3115 m->match.acl.proto_mask = 0xff;
3120 if (strcmp(tokens[1], "array") == 0) {
3122 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3126 m->match_type = TABLE_ARRAY;
3128 if (softnic_parser_read_uint32(&m->match.array.pos, tokens[2]) != 0) {
3129 snprintf(out, out_size, MSG_ARG_INVALID, "pos");
3136 if (strcmp(tokens[1], "hash") == 0) {
3138 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3142 m->match_type = TABLE_HASH;
3144 if (strcmp(tokens[2], "raw") == 0) {
3145 uint32_t key_size = TABLE_RULE_MATCH_SIZE_MAX;
3148 snprintf(out, out_size, MSG_ARG_MISMATCH,
3153 if (softnic_parse_hex_string(tokens[3],
3154 m->match.hash.key, &key_size) != 0) {
3155 snprintf(out, out_size, MSG_ARG_INVALID, "key");
3162 if (strcmp(tokens[2], "ipv4_5tuple") == 0) {
3163 struct pkt_key_ipv4_5tuple *ipv4 =
3164 (struct pkt_key_ipv4_5tuple *)m->match.hash.key;
3165 struct in_addr saddr, daddr;
3170 snprintf(out, out_size, MSG_ARG_MISMATCH,
3175 if (softnic_parse_ipv4_addr(tokens[3], &saddr) != 0) {
3176 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
3180 if (softnic_parse_ipv4_addr(tokens[4], &daddr) != 0) {
3181 snprintf(out, out_size, MSG_ARG_INVALID, "da");
3185 if (softnic_parser_read_uint16(&sp, tokens[5]) != 0) {
3186 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
3190 if (softnic_parser_read_uint16(&dp, tokens[6]) != 0) {
3191 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
3195 if (softnic_parser_read_uint8(&proto, tokens[7]) != 0) {
3196 snprintf(out, out_size, MSG_ARG_INVALID,
3201 ipv4->sa = saddr.s_addr;
3202 ipv4->da = daddr.s_addr;
3203 ipv4->sp = rte_cpu_to_be_16(sp);
3204 ipv4->dp = rte_cpu_to_be_16(dp);
3205 ipv4->proto = proto;
3208 } /* hash ipv4_5tuple */
3210 if (strcmp(tokens[2], "ipv6_5tuple") == 0) {
3211 struct pkt_key_ipv6_5tuple *ipv6 =
3212 (struct pkt_key_ipv6_5tuple *)m->match.hash.key;
3213 struct in6_addr saddr, daddr;
3218 snprintf(out, out_size, MSG_ARG_MISMATCH,
3223 if (softnic_parse_ipv6_addr(tokens[3], &saddr) != 0) {
3224 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
3228 if (softnic_parse_ipv6_addr(tokens[4], &daddr) != 0) {
3229 snprintf(out, out_size, MSG_ARG_INVALID, "da");
3233 if (softnic_parser_read_uint16(&sp, tokens[5]) != 0) {
3234 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
3238 if (softnic_parser_read_uint16(&dp, tokens[6]) != 0) {
3239 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
3243 if (softnic_parser_read_uint8(&proto, tokens[7]) != 0) {
3244 snprintf(out, out_size, MSG_ARG_INVALID,
3249 memcpy(ipv6->sa, saddr.s6_addr, 16);
3250 memcpy(ipv6->da, daddr.s6_addr, 16);
3251 ipv6->sp = rte_cpu_to_be_16(sp);
3252 ipv6->dp = rte_cpu_to_be_16(dp);
3253 ipv6->proto = proto;
3256 } /* hash ipv6_5tuple */
3258 if (strcmp(tokens[2], "ipv4_addr") == 0) {
3259 struct pkt_key_ipv4_addr *ipv4_addr =
3260 (struct pkt_key_ipv4_addr *)m->match.hash.key;
3261 struct in_addr addr;
3264 snprintf(out, out_size, MSG_ARG_MISMATCH,
3269 if (softnic_parse_ipv4_addr(tokens[3], &addr) != 0) {
3270 snprintf(out, out_size, MSG_ARG_INVALID,
3275 ipv4_addr->addr = addr.s_addr;
3278 } /* hash ipv4_addr */
3280 if (strcmp(tokens[2], "ipv6_addr") == 0) {
3281 struct pkt_key_ipv6_addr *ipv6_addr =
3282 (struct pkt_key_ipv6_addr *)m->match.hash.key;
3283 struct in6_addr addr;
3286 snprintf(out, out_size, MSG_ARG_MISMATCH,
3291 if (softnic_parse_ipv6_addr(tokens[3], &addr) != 0) {
3292 snprintf(out, out_size, MSG_ARG_INVALID,
3297 memcpy(ipv6_addr->addr, addr.s6_addr, 16);
3300 } /* hash ipv6_5tuple */
3302 if (strcmp(tokens[2], "qinq") == 0) {
3303 struct pkt_key_qinq *qinq =
3304 (struct pkt_key_qinq *)m->match.hash.key;
3305 uint16_t svlan, cvlan;
3308 snprintf(out, out_size, MSG_ARG_MISMATCH,
3313 if ((softnic_parser_read_uint16(&svlan, tokens[3]) != 0) ||
3315 snprintf(out, out_size, MSG_ARG_INVALID,
3320 if ((softnic_parser_read_uint16(&cvlan, tokens[4]) != 0) ||
3322 snprintf(out, out_size, MSG_ARG_INVALID,
3327 qinq->svlan = rte_cpu_to_be_16(svlan);
3328 qinq->cvlan = rte_cpu_to_be_16(cvlan);
3333 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3337 if (strcmp(tokens[1], "lpm") == 0) {
3339 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3343 m->match_type = TABLE_LPM;
3345 if (strcmp(tokens[2], "ipv4") == 0) {
3346 struct in_addr addr;
3348 m->match.lpm.ip_version = 1;
3350 if (softnic_parse_ipv4_addr(tokens[3], &addr) != 0) {
3351 snprintf(out, out_size, MSG_ARG_INVALID,
3356 m->match.lpm.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3357 } else if (strcmp(tokens[2], "ipv6") == 0) {
3358 struct in6_addr addr;
3360 m->match.lpm.ip_version = 0;
3362 if (softnic_parse_ipv6_addr(tokens[3], &addr) != 0) {
3363 snprintf(out, out_size, MSG_ARG_INVALID,
3368 memcpy(m->match.lpm.ipv6, addr.s6_addr, 16);
3370 snprintf(out, out_size, MSG_ARG_MISMATCH,
3375 if (softnic_parser_read_uint8(&m->match.lpm.depth, tokens[4]) != 0) {
3376 snprintf(out, out_size, MSG_ARG_INVALID, "depth");
3383 snprintf(out, out_size, MSG_ARG_MISMATCH,
3384 "acl or array or hash or lpm");
3396 * | table <table_id>
3397 * [balance <out0> ... <out7>]
3399 * tc0 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3400 * [tc1 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3401 * tc2 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3402 * tc3 meter <meter_profile_id> policer g <pa> y <pa> r <pa>]]
3403 * [tm subport <subport_id> pipe <pipe_id>]
3406 * | vlan <da> <sa> <pcp> <dei> <vid>
3407 * | qinq <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid>
3408 * | qinq_pppoe <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid> <session_id>
3409 * | mpls unicast | multicast
3411 * label0 <label> <tc> <ttl>
3412 * [label1 <label> <tc> <ttl>
3413 * [label2 <label> <tc> <ttl>
3414 * [label3 <label> <tc> <ttl>]]]
3415 * | pppoe <da> <sa> <session_id>]
3416 * | vxlan ether <da> <sa>
3417 * [vlan <pcp> <dei> <vid>]
3418 * ipv4 <sa> <da> <dscp> <ttl>
3419 * | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit>
3422 * [nat ipv4 | ipv6 <addr> <port>]
3432 * cipher_algo <algo> cipher_key <key> cipher_iv <iv>
3434 * cipher_algo <algo> cipher_key <key> cipher_iv <iv>
3435 * auth_algo <algo> auth_key <key> digest_size <size>
3437 * aead_algo <algo> aead_key <key> aead_iv <iv> aead_aad <aad>
3438 * digest_size <size>
3439 * data_offset <data_offset>]
3442 * <pa> ::= g | y | r | drop
3445 parse_table_action_fwd(char **tokens,
3447 struct softnic_table_rule_action *a)
3449 if (n_tokens == 0 ||
3450 (strcmp(tokens[0], "fwd") != 0))
3456 if (n_tokens && (strcmp(tokens[0], "drop") == 0)) {
3457 a->fwd.action = RTE_PIPELINE_ACTION_DROP;
3458 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3462 if (n_tokens && (strcmp(tokens[0], "port") == 0)) {
3466 softnic_parser_read_uint32(&id, tokens[1]))
3469 a->fwd.action = RTE_PIPELINE_ACTION_PORT;
3471 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3475 if (n_tokens && (strcmp(tokens[0], "meta") == 0)) {
3476 a->fwd.action = RTE_PIPELINE_ACTION_PORT_META;
3477 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3481 if (n_tokens && (strcmp(tokens[0], "table") == 0)) {
3485 softnic_parser_read_uint32(&id, tokens[1]))
3488 a->fwd.action = RTE_PIPELINE_ACTION_TABLE;
3490 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3498 parse_table_action_balance(char **tokens,
3500 struct softnic_table_rule_action *a)
3504 if (n_tokens == 0 ||
3505 (strcmp(tokens[0], "balance") != 0))
3511 if (n_tokens < RTE_TABLE_ACTION_LB_TABLE_SIZE)
3514 for (i = 0; i < RTE_TABLE_ACTION_LB_TABLE_SIZE; i++)
3515 if (softnic_parser_read_uint32(&a->lb.out[i], tokens[i]) != 0)
3518 a->action_mask |= 1 << RTE_TABLE_ACTION_LB;
3519 return 1 + RTE_TABLE_ACTION_LB_TABLE_SIZE;
3523 parse_policer_action(char *token, enum rte_table_action_policer *a)
3525 if (strcmp(token, "g") == 0) {
3526 *a = RTE_TABLE_ACTION_POLICER_COLOR_GREEN;
3530 if (strcmp(token, "y") == 0) {
3531 *a = RTE_TABLE_ACTION_POLICER_COLOR_YELLOW;
3535 if (strcmp(token, "r") == 0) {
3536 *a = RTE_TABLE_ACTION_POLICER_COLOR_RED;
3540 if (strcmp(token, "drop") == 0) {
3541 *a = RTE_TABLE_ACTION_POLICER_DROP;
3549 parse_table_action_meter_tc(char **tokens,
3551 struct rte_table_action_mtr_tc_params *mtr)
3554 strcmp(tokens[0], "meter") ||
3555 softnic_parser_read_uint32(&mtr->meter_profile_id, tokens[1]) ||
3556 strcmp(tokens[2], "policer") ||
3557 strcmp(tokens[3], "g") ||
3558 parse_policer_action(tokens[4], &mtr->policer[RTE_COLOR_GREEN]) ||
3559 strcmp(tokens[5], "y") ||
3560 parse_policer_action(tokens[6], &mtr->policer[RTE_COLOR_YELLOW]) ||
3561 strcmp(tokens[7], "r") ||
3562 parse_policer_action(tokens[8], &mtr->policer[RTE_COLOR_RED]))
3569 parse_table_action_meter(char **tokens,
3571 struct softnic_table_rule_action *a)
3573 if (n_tokens == 0 ||
3574 strcmp(tokens[0], "meter"))
3580 if (n_tokens < 10 ||
3581 strcmp(tokens[0], "tc0") ||
3582 (parse_table_action_meter_tc(tokens + 1,
3584 &a->mtr.mtr[0]) == 0))
3590 if (n_tokens == 0 ||
3591 strcmp(tokens[0], "tc1")) {
3593 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3597 if (n_tokens < 30 ||
3598 (parse_table_action_meter_tc(tokens + 1,
3599 n_tokens - 1, &a->mtr.mtr[1]) == 0) ||
3600 strcmp(tokens[10], "tc2") ||
3601 (parse_table_action_meter_tc(tokens + 11,
3602 n_tokens - 11, &a->mtr.mtr[2]) == 0) ||
3603 strcmp(tokens[20], "tc3") ||
3604 (parse_table_action_meter_tc(tokens + 21,
3605 n_tokens - 21, &a->mtr.mtr[3]) == 0))
3608 a->mtr.tc_mask = 0xF;
3609 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3610 return 1 + 10 + 3 * 10;
3614 parse_table_action_tm(char **tokens,
3616 struct softnic_table_rule_action *a)
3618 uint32_t subport_id, pipe_id;
3621 strcmp(tokens[0], "tm") ||
3622 strcmp(tokens[1], "subport") ||
3623 softnic_parser_read_uint32(&subport_id, tokens[2]) ||
3624 strcmp(tokens[3], "pipe") ||
3625 softnic_parser_read_uint32(&pipe_id, tokens[4]))
3628 a->tm.subport_id = subport_id;
3629 a->tm.pipe_id = pipe_id;
3630 a->action_mask |= 1 << RTE_TABLE_ACTION_TM;
3635 parse_table_action_encap(char **tokens,
3637 struct softnic_table_rule_action *a)
3639 if (n_tokens == 0 ||
3640 strcmp(tokens[0], "encap"))
3647 if (n_tokens && (strcmp(tokens[0], "ether") == 0)) {
3649 softnic_parse_mac_addr(tokens[1], &a->encap.ether.ether.da) ||
3650 softnic_parse_mac_addr(tokens[2], &a->encap.ether.ether.sa))
3653 a->encap.type = RTE_TABLE_ACTION_ENCAP_ETHER;
3654 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3659 if (n_tokens && (strcmp(tokens[0], "vlan") == 0)) {
3660 uint32_t pcp, dei, vid;
3663 softnic_parse_mac_addr(tokens[1], &a->encap.vlan.ether.da) ||
3664 softnic_parse_mac_addr(tokens[2], &a->encap.vlan.ether.sa) ||
3665 softnic_parser_read_uint32(&pcp, tokens[3]) ||
3667 softnic_parser_read_uint32(&dei, tokens[4]) ||
3669 softnic_parser_read_uint32(&vid, tokens[5]) ||
3673 a->encap.vlan.vlan.pcp = pcp & 0x7;
3674 a->encap.vlan.vlan.dei = dei & 0x1;
3675 a->encap.vlan.vlan.vid = vid & 0xFFF;
3676 a->encap.type = RTE_TABLE_ACTION_ENCAP_VLAN;
3677 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3682 if (n_tokens && (strcmp(tokens[0], "qinq") == 0)) {
3683 uint32_t svlan_pcp, svlan_dei, svlan_vid;
3684 uint32_t cvlan_pcp, cvlan_dei, cvlan_vid;
3687 softnic_parse_mac_addr(tokens[1], &a->encap.qinq.ether.da) ||
3688 softnic_parse_mac_addr(tokens[2], &a->encap.qinq.ether.sa) ||
3689 softnic_parser_read_uint32(&svlan_pcp, tokens[3]) ||
3691 softnic_parser_read_uint32(&svlan_dei, tokens[4]) ||
3693 softnic_parser_read_uint32(&svlan_vid, tokens[5]) ||
3694 svlan_vid > 0xFFF ||
3695 softnic_parser_read_uint32(&cvlan_pcp, tokens[6]) ||
3697 softnic_parser_read_uint32(&cvlan_dei, tokens[7]) ||
3699 softnic_parser_read_uint32(&cvlan_vid, tokens[8]) ||
3703 a->encap.qinq.svlan.pcp = svlan_pcp & 0x7;
3704 a->encap.qinq.svlan.dei = svlan_dei & 0x1;
3705 a->encap.qinq.svlan.vid = svlan_vid & 0xFFF;
3706 a->encap.qinq.cvlan.pcp = cvlan_pcp & 0x7;
3707 a->encap.qinq.cvlan.dei = cvlan_dei & 0x1;
3708 a->encap.qinq.cvlan.vid = cvlan_vid & 0xFFF;
3709 a->encap.type = RTE_TABLE_ACTION_ENCAP_QINQ;
3710 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3715 if (n_tokens && (strcmp(tokens[0], "qinq_pppoe") == 0)) {
3716 uint32_t svlan_pcp, svlan_dei, svlan_vid;
3717 uint32_t cvlan_pcp, cvlan_dei, cvlan_vid;
3719 if (n_tokens < 10 ||
3720 softnic_parse_mac_addr(tokens[1],
3721 &a->encap.qinq_pppoe.ether.da) ||
3722 softnic_parse_mac_addr(tokens[2],
3723 &a->encap.qinq_pppoe.ether.sa) ||
3724 softnic_parser_read_uint32(&svlan_pcp, tokens[3]) ||
3726 softnic_parser_read_uint32(&svlan_dei, tokens[4]) ||
3728 softnic_parser_read_uint32(&svlan_vid, tokens[5]) ||
3729 svlan_vid > 0xFFF ||
3730 softnic_parser_read_uint32(&cvlan_pcp, tokens[6]) ||
3732 softnic_parser_read_uint32(&cvlan_dei, tokens[7]) ||
3734 softnic_parser_read_uint32(&cvlan_vid, tokens[8]) ||
3735 cvlan_vid > 0xFFF ||
3736 softnic_parser_read_uint16(&a->encap.qinq_pppoe.pppoe.session_id,
3740 a->encap.qinq_pppoe.svlan.pcp = svlan_pcp & 0x7;
3741 a->encap.qinq_pppoe.svlan.dei = svlan_dei & 0x1;
3742 a->encap.qinq_pppoe.svlan.vid = svlan_vid & 0xFFF;
3743 a->encap.qinq_pppoe.cvlan.pcp = cvlan_pcp & 0x7;
3744 a->encap.qinq_pppoe.cvlan.dei = cvlan_dei & 0x1;
3745 a->encap.qinq_pppoe.cvlan.vid = cvlan_vid & 0xFFF;
3746 a->encap.type = RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE;
3747 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3752 if (n_tokens && (strcmp(tokens[0], "mpls") == 0)) {
3753 uint32_t label, tc, ttl;
3758 if (strcmp(tokens[1], "unicast") == 0)
3759 a->encap.mpls.unicast = 1;
3760 else if (strcmp(tokens[1], "multicast") == 0)
3761 a->encap.mpls.unicast = 0;
3765 if (softnic_parse_mac_addr(tokens[2], &a->encap.mpls.ether.da) ||
3766 softnic_parse_mac_addr(tokens[3], &a->encap.mpls.ether.sa) ||
3767 strcmp(tokens[4], "label0") ||
3768 softnic_parser_read_uint32(&label, tokens[5]) ||
3770 softnic_parser_read_uint32(&tc, tokens[6]) ||
3772 softnic_parser_read_uint32(&ttl, tokens[7]) ||
3776 a->encap.mpls.mpls[0].label = label;
3777 a->encap.mpls.mpls[0].tc = tc;
3778 a->encap.mpls.mpls[0].ttl = ttl;
3783 if (n_tokens == 0 ||
3784 strcmp(tokens[0], "label1")) {
3785 a->encap.mpls.mpls_count = 1;
3786 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3787 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3792 softnic_parser_read_uint32(&label, tokens[1]) ||
3794 softnic_parser_read_uint32(&tc, tokens[2]) ||
3796 softnic_parser_read_uint32(&ttl, tokens[3]) ||
3800 a->encap.mpls.mpls[1].label = label;
3801 a->encap.mpls.mpls[1].tc = tc;
3802 a->encap.mpls.mpls[1].ttl = ttl;
3807 if (n_tokens == 0 ||
3808 strcmp(tokens[0], "label2")) {
3809 a->encap.mpls.mpls_count = 2;
3810 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3811 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3816 softnic_parser_read_uint32(&label, tokens[1]) ||
3818 softnic_parser_read_uint32(&tc, tokens[2]) ||
3820 softnic_parser_read_uint32(&ttl, tokens[3]) ||
3824 a->encap.mpls.mpls[2].label = label;
3825 a->encap.mpls.mpls[2].tc = tc;
3826 a->encap.mpls.mpls[2].ttl = ttl;
3831 if (n_tokens == 0 ||
3832 strcmp(tokens[0], "label3")) {
3833 a->encap.mpls.mpls_count = 3;
3834 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3835 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3836 return 1 + 8 + 4 + 4;
3840 softnic_parser_read_uint32(&label, tokens[1]) ||
3842 softnic_parser_read_uint32(&tc, tokens[2]) ||
3844 softnic_parser_read_uint32(&ttl, tokens[3]) ||
3848 a->encap.mpls.mpls[3].label = label;
3849 a->encap.mpls.mpls[3].tc = tc;
3850 a->encap.mpls.mpls[3].ttl = ttl;
3852 a->encap.mpls.mpls_count = 4;
3853 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3854 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3855 return 1 + 8 + 4 + 4 + 4;
3859 if (n_tokens && (strcmp(tokens[0], "pppoe") == 0)) {
3861 softnic_parse_mac_addr(tokens[1], &a->encap.pppoe.ether.da) ||
3862 softnic_parse_mac_addr(tokens[2], &a->encap.pppoe.ether.sa) ||
3863 softnic_parser_read_uint16(&a->encap.pppoe.pppoe.session_id,
3867 a->encap.type = RTE_TABLE_ACTION_ENCAP_PPPOE;
3868 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3873 if (n_tokens && (strcmp(tokens[0], "vxlan") == 0)) {
3880 /* ether <da> <sa> */
3881 if ((n_tokens < 3) ||
3882 strcmp(tokens[0], "ether") ||
3883 softnic_parse_mac_addr(tokens[1], &a->encap.vxlan.ether.da) ||
3884 softnic_parse_mac_addr(tokens[2], &a->encap.vxlan.ether.sa))
3891 /* [vlan <pcp> <dei> <vid>] */
3892 if (strcmp(tokens[0], "vlan") == 0) {
3893 uint32_t pcp, dei, vid;
3895 if ((n_tokens < 4) ||
3896 softnic_parser_read_uint32(&pcp, tokens[1]) ||
3898 softnic_parser_read_uint32(&dei, tokens[2]) ||
3900 softnic_parser_read_uint32(&vid, tokens[3]) ||
3904 a->encap.vxlan.vlan.pcp = pcp;
3905 a->encap.vxlan.vlan.dei = dei;
3906 a->encap.vxlan.vlan.vid = vid;
3913 /* ipv4 <sa> <da> <dscp> <ttl>
3914 | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit> */
3915 if (strcmp(tokens[0], "ipv4") == 0) {
3916 struct in_addr sa, da;
3919 if ((n_tokens < 5) ||
3920 softnic_parse_ipv4_addr(tokens[1], &sa) ||
3921 softnic_parse_ipv4_addr(tokens[2], &da) ||
3922 softnic_parser_read_uint8(&dscp, tokens[3]) ||
3924 softnic_parser_read_uint8(&ttl, tokens[4]))
3927 a->encap.vxlan.ipv4.sa = rte_be_to_cpu_32(sa.s_addr);
3928 a->encap.vxlan.ipv4.da = rte_be_to_cpu_32(da.s_addr);
3929 a->encap.vxlan.ipv4.dscp = dscp;
3930 a->encap.vxlan.ipv4.ttl = ttl;
3935 } else if (strcmp(tokens[0], "ipv6") == 0) {
3936 struct in6_addr sa, da;
3937 uint32_t flow_label;
3938 uint8_t dscp, hop_limit;
3940 if ((n_tokens < 6) ||
3941 softnic_parse_ipv6_addr(tokens[1], &sa) ||
3942 softnic_parse_ipv6_addr(tokens[2], &da) ||
3943 softnic_parser_read_uint32(&flow_label, tokens[3]) ||
3944 softnic_parser_read_uint8(&dscp, tokens[4]) ||
3946 softnic_parser_read_uint8(&hop_limit, tokens[5]))
3949 memcpy(a->encap.vxlan.ipv6.sa, sa.s6_addr, 16);
3950 memcpy(a->encap.vxlan.ipv6.da, da.s6_addr, 16);
3951 a->encap.vxlan.ipv6.flow_label = flow_label;
3952 a->encap.vxlan.ipv6.dscp = dscp;
3953 a->encap.vxlan.ipv6.hop_limit = hop_limit;
3962 if ((n_tokens < 3) ||
3963 strcmp(tokens[0], "udp") ||
3964 softnic_parser_read_uint16(&a->encap.vxlan.udp.sp, tokens[1]) ||
3965 softnic_parser_read_uint16(&a->encap.vxlan.udp.dp, tokens[2]))
3973 if ((n_tokens < 2) ||
3974 strcmp(tokens[0], "vxlan") ||
3975 softnic_parser_read_uint32(&a->encap.vxlan.vxlan.vni, tokens[1]) ||
3976 (a->encap.vxlan.vxlan.vni > 0xFFFFFF))
3983 a->encap.type = RTE_TABLE_ACTION_ENCAP_VXLAN;
3984 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3992 parse_table_action_nat(char **tokens,
3994 struct softnic_table_rule_action *a)
3997 strcmp(tokens[0], "nat"))
4000 if (strcmp(tokens[1], "ipv4") == 0) {
4001 struct in_addr addr;
4004 if (softnic_parse_ipv4_addr(tokens[2], &addr) ||
4005 softnic_parser_read_uint16(&port, tokens[3]))
4008 a->nat.ip_version = 1;
4009 a->nat.addr.ipv4 = rte_be_to_cpu_32(addr.s_addr);
4011 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
4015 if (strcmp(tokens[1], "ipv6") == 0) {
4016 struct in6_addr addr;
4019 if (softnic_parse_ipv6_addr(tokens[2], &addr) ||
4020 softnic_parser_read_uint16(&port, tokens[3]))
4023 a->nat.ip_version = 0;
4024 memcpy(a->nat.addr.ipv6, addr.s6_addr, 16);
4026 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
4034 parse_table_action_ttl(char **tokens,
4036 struct softnic_table_rule_action *a)
4039 strcmp(tokens[0], "ttl"))
4042 if (strcmp(tokens[1], "dec") == 0)
4043 a->ttl.decrement = 1;
4044 else if (strcmp(tokens[1], "keep") == 0)
4045 a->ttl.decrement = 0;
4049 a->action_mask |= 1 << RTE_TABLE_ACTION_TTL;
4054 parse_table_action_stats(char **tokens,
4056 struct softnic_table_rule_action *a)
4059 strcmp(tokens[0], "stats"))
4062 a->stats.n_packets = 0;
4063 a->stats.n_bytes = 0;
4064 a->action_mask |= 1 << RTE_TABLE_ACTION_STATS;
4069 parse_table_action_time(char **tokens,
4071 struct softnic_table_rule_action *a)
4074 strcmp(tokens[0], "time"))
4077 a->time.time = rte_rdtsc();
4078 a->action_mask |= 1 << RTE_TABLE_ACTION_TIME;
4083 parse_free_sym_crypto_param_data(struct rte_table_action_sym_crypto_params *p)
4085 struct rte_crypto_sym_xform *xform[2] = {NULL};
4088 xform[0] = p->xform;
4090 xform[1] = xform[0]->next;
4092 for (i = 0; i < 2; i++) {
4093 if (xform[i] == NULL)
4096 switch (xform[i]->type) {
4097 case RTE_CRYPTO_SYM_XFORM_CIPHER:
4098 if (xform[i]->cipher.key.data)
4099 free(xform[i]->cipher.key.data);
4100 if (p->cipher_auth.cipher_iv.val)
4101 free(p->cipher_auth.cipher_iv.val);
4102 if (p->cipher_auth.cipher_iv_update.val)
4103 free(p->cipher_auth.cipher_iv_update.val);
4105 case RTE_CRYPTO_SYM_XFORM_AUTH:
4106 if (xform[i]->auth.key.data)
4107 free(xform[i]->cipher.key.data);
4108 if (p->cipher_auth.auth_iv.val)
4109 free(p->cipher_auth.cipher_iv.val);
4110 if (p->cipher_auth.auth_iv_update.val)
4111 free(p->cipher_auth.cipher_iv_update.val);
4113 case RTE_CRYPTO_SYM_XFORM_AEAD:
4114 if (xform[i]->aead.key.data)
4115 free(xform[i]->cipher.key.data);
4117 free(p->aead.iv.val);
4118 if (p->aead.aad.val)
4119 free(p->aead.aad.val);
4128 static struct rte_crypto_sym_xform *
4129 parse_table_action_cipher(struct rte_table_action_sym_crypto_params *p,
4130 char **tokens, uint32_t n_tokens, uint32_t encrypt,
4131 uint32_t *used_n_tokens)
4133 struct rte_crypto_sym_xform *xform_cipher;
4137 if (n_tokens < 7 || strcmp(tokens[1], "cipher_algo") ||
4138 strcmp(tokens[3], "cipher_key") ||
4139 strcmp(tokens[5], "cipher_iv"))
4142 xform_cipher = calloc(1, sizeof(*xform_cipher));
4143 if (xform_cipher == NULL)
4146 xform_cipher->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4147 xform_cipher->cipher.op = encrypt ? RTE_CRYPTO_CIPHER_OP_ENCRYPT :
4148 RTE_CRYPTO_CIPHER_OP_DECRYPT;
4151 status = rte_cryptodev_get_cipher_algo_enum(
4152 &xform_cipher->cipher.algo, tokens[2]);
4157 len = strlen(tokens[4]);
4158 xform_cipher->cipher.key.data = calloc(1, len / 2 + 1);
4159 if (xform_cipher->cipher.key.data == NULL)
4162 status = softnic_parse_hex_string(tokens[4],
4163 xform_cipher->cipher.key.data,
4168 xform_cipher->cipher.key.length = (uint16_t)len;
4171 len = strlen(tokens[6]);
4173 p->cipher_auth.cipher_iv.val = calloc(1, len / 2 + 1);
4174 if (p->cipher_auth.cipher_iv.val == NULL)
4177 status = softnic_parse_hex_string(tokens[6],
4178 p->cipher_auth.cipher_iv.val,
4183 xform_cipher->cipher.iv.length = (uint16_t)len;
4184 xform_cipher->cipher.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
4185 p->cipher_auth.cipher_iv.length = (uint32_t)len;
4188 return xform_cipher;
4191 if (xform_cipher->cipher.key.data)
4192 free(xform_cipher->cipher.key.data);
4194 if (p->cipher_auth.cipher_iv.val) {
4195 free(p->cipher_auth.cipher_iv.val);
4196 p->cipher_auth.cipher_iv.val = NULL;
4204 static struct rte_crypto_sym_xform *
4205 parse_table_action_cipher_auth(struct rte_table_action_sym_crypto_params *p,
4206 char **tokens, uint32_t n_tokens, uint32_t encrypt,
4207 uint32_t *used_n_tokens)
4209 struct rte_crypto_sym_xform *xform_cipher;
4210 struct rte_crypto_sym_xform *xform_auth;
4214 if (n_tokens < 13 ||
4215 strcmp(tokens[7], "auth_algo") ||
4216 strcmp(tokens[9], "auth_key") ||
4217 strcmp(tokens[11], "digest_size"))
4220 xform_auth = calloc(1, sizeof(*xform_auth));
4221 if (xform_auth == NULL)
4224 xform_auth->type = RTE_CRYPTO_SYM_XFORM_AUTH;
4225 xform_auth->auth.op = encrypt ? RTE_CRYPTO_AUTH_OP_GENERATE :
4226 RTE_CRYPTO_AUTH_OP_VERIFY;
4229 status = rte_cryptodev_get_auth_algo_enum(&xform_auth->auth.algo,
4235 len = strlen(tokens[10]);
4236 xform_auth->auth.key.data = calloc(1, len / 2 + 1);
4237 if (xform_auth->auth.key.data == NULL)
4240 status = softnic_parse_hex_string(tokens[10],
4241 xform_auth->auth.key.data, (uint32_t *)&len);
4245 xform_auth->auth.key.length = (uint16_t)len;
4247 if (strcmp(tokens[11], "digest_size"))
4250 status = softnic_parser_read_uint16(&xform_auth->auth.digest_length,
4255 xform_cipher = parse_table_action_cipher(p, tokens, 7, encrypt,
4257 if (xform_cipher == NULL)
4260 *used_n_tokens += 6;
4263 xform_cipher->next = xform_auth;
4264 return xform_cipher;
4266 xform_auth->next = xform_cipher;
4271 if (xform_auth->auth.key.data)
4272 free(xform_auth->auth.key.data);
4273 if (p->cipher_auth.auth_iv.val) {
4274 free(p->cipher_auth.auth_iv.val);
4275 p->cipher_auth.auth_iv.val = 0;
4283 static struct rte_crypto_sym_xform *
4284 parse_table_action_aead(struct rte_table_action_sym_crypto_params *p,
4285 char **tokens, uint32_t n_tokens, uint32_t encrypt,
4286 uint32_t *used_n_tokens)
4288 struct rte_crypto_sym_xform *xform_aead;
4292 if (n_tokens < 11 || strcmp(tokens[1], "aead_algo") ||
4293 strcmp(tokens[3], "aead_key") ||
4294 strcmp(tokens[5], "aead_iv") ||
4295 strcmp(tokens[7], "aead_aad") ||
4296 strcmp(tokens[9], "digest_size"))
4299 xform_aead = calloc(1, sizeof(*xform_aead));
4300 if (xform_aead == NULL)
4303 xform_aead->type = RTE_CRYPTO_SYM_XFORM_AEAD;
4304 xform_aead->aead.op = encrypt ? RTE_CRYPTO_AEAD_OP_ENCRYPT :
4305 RTE_CRYPTO_AEAD_OP_DECRYPT;
4308 status = rte_cryptodev_get_aead_algo_enum(&xform_aead->aead.algo,
4314 len = strlen(tokens[4]);
4315 xform_aead->aead.key.data = calloc(1, len / 2 + 1);
4316 if (xform_aead->aead.key.data == NULL)
4319 status = softnic_parse_hex_string(tokens[4], xform_aead->aead.key.data,
4324 xform_aead->aead.key.length = (uint16_t)len;
4327 len = strlen(tokens[6]);
4328 p->aead.iv.val = calloc(1, len / 2 + 1);
4329 if (p->aead.iv.val == NULL)
4332 status = softnic_parse_hex_string(tokens[6], p->aead.iv.val,
4337 xform_aead->aead.iv.length = (uint16_t)len;
4338 xform_aead->aead.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
4339 p->aead.iv.length = (uint32_t)len;
4342 len = strlen(tokens[8]);
4343 p->aead.aad.val = calloc(1, len / 2 + 1);
4344 if (p->aead.aad.val == NULL)
4347 status = softnic_parse_hex_string(tokens[8], p->aead.aad.val, (uint32_t *)&len);
4351 xform_aead->aead.aad_length = (uint16_t)len;
4352 p->aead.aad.length = (uint32_t)len;
4355 status = softnic_parser_read_uint16(&xform_aead->aead.digest_length,
4360 *used_n_tokens = 11;
4365 if (xform_aead->aead.key.data)
4366 free(xform_aead->aead.key.data);
4367 if (p->aead.iv.val) {
4368 free(p->aead.iv.val);
4369 p->aead.iv.val = NULL;
4371 if (p->aead.aad.val) {
4372 free(p->aead.aad.val);
4373 p->aead.aad.val = NULL;
4383 parse_table_action_sym_crypto(char **tokens,
4385 struct softnic_table_rule_action *a)
4387 struct rte_table_action_sym_crypto_params *p = &a->sym_crypto;
4388 struct rte_crypto_sym_xform *xform = NULL;
4389 uint32_t used_n_tokens;
4393 if ((n_tokens < 12) ||
4394 strcmp(tokens[0], "sym_crypto") ||
4395 strcmp(tokens[2], "type"))
4398 memset(p, 0, sizeof(*p));
4400 if (strcmp(tokens[1], "encrypt") == 0)
4405 status = softnic_parser_read_uint32(&p->data_offset, tokens[n_tokens - 1]);
4409 if (strcmp(tokens[3], "cipher") == 0) {
4413 xform = parse_table_action_cipher(p, tokens, n_tokens, encrypt,
4415 } else if (strcmp(tokens[3], "cipher_auth") == 0) {
4419 xform = parse_table_action_cipher_auth(p, tokens, n_tokens,
4420 encrypt, &used_n_tokens);
4421 } else if (strcmp(tokens[3], "aead") == 0) {
4425 xform = parse_table_action_aead(p, tokens, n_tokens, encrypt,
4434 if (strcmp(tokens[used_n_tokens], "data_offset")) {
4435 parse_free_sym_crypto_param_data(p);
4439 a->action_mask |= 1 << RTE_TABLE_ACTION_SYM_CRYPTO;
4441 return used_n_tokens + 5;
4445 parse_table_action_tag(char **tokens,
4447 struct softnic_table_rule_action *a)
4450 strcmp(tokens[0], "tag"))
4453 if (softnic_parser_read_uint32(&a->tag.tag, tokens[1]))
4456 a->action_mask |= 1 << RTE_TABLE_ACTION_TAG;
4461 parse_table_action_decap(char **tokens,
4463 struct softnic_table_rule_action *a)
4466 strcmp(tokens[0], "decap"))
4469 if (softnic_parser_read_uint16(&a->decap.n, tokens[1]))
4472 a->action_mask |= 1 << RTE_TABLE_ACTION_DECAP;
4477 parse_table_action(char **tokens,
4481 struct softnic_table_rule_action *a)
4483 uint32_t n_tokens0 = n_tokens;
4485 memset(a, 0, sizeof(*a));
4488 strcmp(tokens[0], "action"))
4494 if (n_tokens && (strcmp(tokens[0], "fwd") == 0)) {
4497 n = parse_table_action_fwd(tokens, n_tokens, a);
4499 snprintf(out, out_size, MSG_ARG_INVALID,
4508 if (n_tokens && (strcmp(tokens[0], "balance") == 0)) {
4511 n = parse_table_action_balance(tokens, n_tokens, a);
4513 snprintf(out, out_size, MSG_ARG_INVALID,
4522 if (n_tokens && (strcmp(tokens[0], "meter") == 0)) {
4525 n = parse_table_action_meter(tokens, n_tokens, a);
4527 snprintf(out, out_size, MSG_ARG_INVALID,
4536 if (n_tokens && (strcmp(tokens[0], "tm") == 0)) {
4539 n = parse_table_action_tm(tokens, n_tokens, a);
4541 snprintf(out, out_size, MSG_ARG_INVALID,
4550 if (n_tokens && (strcmp(tokens[0], "encap") == 0)) {
4553 n = parse_table_action_encap(tokens, n_tokens, a);
4555 snprintf(out, out_size, MSG_ARG_INVALID,
4564 if (n_tokens && (strcmp(tokens[0], "nat") == 0)) {
4567 n = parse_table_action_nat(tokens, n_tokens, a);
4569 snprintf(out, out_size, MSG_ARG_INVALID,
4578 if (n_tokens && (strcmp(tokens[0], "ttl") == 0)) {
4581 n = parse_table_action_ttl(tokens, n_tokens, a);
4583 snprintf(out, out_size, MSG_ARG_INVALID,
4592 if (n_tokens && (strcmp(tokens[0], "stats") == 0)) {
4595 n = parse_table_action_stats(tokens, n_tokens, a);
4597 snprintf(out, out_size, MSG_ARG_INVALID,
4606 if (n_tokens && (strcmp(tokens[0], "time") == 0)) {
4609 n = parse_table_action_time(tokens, n_tokens, a);
4611 snprintf(out, out_size, MSG_ARG_INVALID,
4620 if (n_tokens && (strcmp(tokens[0], "tag") == 0)) {
4623 n = parse_table_action_tag(tokens, n_tokens, a);
4625 snprintf(out, out_size, MSG_ARG_INVALID,
4634 if (n_tokens && (strcmp(tokens[0], "decap") == 0)) {
4637 n = parse_table_action_decap(tokens, n_tokens, a);
4639 snprintf(out, out_size, MSG_ARG_INVALID,
4648 if (n_tokens && (strcmp(tokens[0], "sym_crypto") == 0)) {
4651 n = parse_table_action_sym_crypto(tokens, n_tokens, a);
4653 snprintf(out, out_size, MSG_ARG_INVALID,
4654 "action sym_crypto");
4661 if (n_tokens0 - n_tokens == 1) {
4662 snprintf(out, out_size, MSG_ARG_INVALID, "action");
4666 return n_tokens0 - n_tokens;
4670 * pipeline <pipeline_name> table <table_id> rule add
4672 * action <table_action>
4675 cmd_softnic_pipeline_table_rule_add(struct pmd_internals *softnic,
4681 struct softnic_table_rule_match m;
4682 struct softnic_table_rule_action a;
4683 char *pipeline_name;
4685 uint32_t table_id, t0, n_tokens_parsed;
4689 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4693 pipeline_name = tokens[1];
4695 if (strcmp(tokens[2], "table") != 0) {
4696 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4700 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
4701 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4705 if (strcmp(tokens[4], "rule") != 0) {
4706 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4710 if (strcmp(tokens[5], "add") != 0) {
4711 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4718 n_tokens_parsed = parse_match(tokens + t0,
4723 if (n_tokens_parsed == 0)
4725 t0 += n_tokens_parsed;
4728 n_tokens_parsed = parse_table_action(tokens + t0,
4733 if (n_tokens_parsed == 0)
4735 t0 += n_tokens_parsed;
4737 if (t0 != n_tokens) {
4738 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
4742 status = softnic_pipeline_table_rule_add(softnic,
4749 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4755 * pipeline <pipeline_name> table <table_id> rule add
4763 * | table <table_id>
4766 cmd_softnic_pipeline_table_rule_add_default(struct pmd_internals *softnic,
4772 struct softnic_table_rule_action action;
4774 char *pipeline_name;
4778 if (n_tokens != 11 &&
4780 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4784 pipeline_name = tokens[1];
4786 if (strcmp(tokens[2], "table") != 0) {
4787 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4791 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
4792 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4796 if (strcmp(tokens[4], "rule") != 0) {
4797 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4801 if (strcmp(tokens[5], "add") != 0) {
4802 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4806 if (strcmp(tokens[6], "match") != 0) {
4807 snprintf(out, out_size, MSG_ARG_INVALID, "match");
4811 if (strcmp(tokens[7], "default") != 0) {
4812 snprintf(out, out_size, MSG_ARG_INVALID, "default");
4816 if (strcmp(tokens[8], "action") != 0) {
4817 snprintf(out, out_size, MSG_ARG_INVALID, "action");
4821 if (strcmp(tokens[9], "fwd") != 0) {
4822 snprintf(out, out_size, MSG_ARG_INVALID, "fwd");
4826 action.action_mask = 1 << RTE_TABLE_ACTION_FWD;
4828 if (strcmp(tokens[10], "drop") == 0) {
4829 if (n_tokens != 11) {
4830 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4834 action.fwd.action = RTE_PIPELINE_ACTION_DROP;
4835 } else if (strcmp(tokens[10], "port") == 0) {
4838 if (n_tokens != 12) {
4839 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4843 if (softnic_parser_read_uint32(&id, tokens[11]) != 0) {
4844 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
4848 action.fwd.action = RTE_PIPELINE_ACTION_PORT;
4850 } else if (strcmp(tokens[10], "meta") == 0) {
4851 if (n_tokens != 11) {
4852 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4856 action.fwd.action = RTE_PIPELINE_ACTION_PORT_META;
4857 } else if (strcmp(tokens[10], "table") == 0) {
4860 if (n_tokens != 12) {
4861 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4865 if (softnic_parser_read_uint32(&id, tokens[11]) != 0) {
4866 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4870 action.fwd.action = RTE_PIPELINE_ACTION_TABLE;
4873 snprintf(out, out_size, MSG_ARG_INVALID,
4874 "drop or port or meta or table");
4878 status = softnic_pipeline_table_rule_add_default(softnic,
4884 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4890 * pipeline <pipeline_name> table <table_id> rule add bulk <file_name> <n_rules>
4893 * - line format: match <match> action <action>
4896 cli_rule_file_process(const char *file_name,
4897 size_t line_len_max,
4898 struct softnic_table_rule_match *m,
4899 struct softnic_table_rule_action *a,
4901 uint32_t *line_number,
4906 cmd_softnic_pipeline_table_rule_add_bulk(struct pmd_internals *softnic,
4912 struct softnic_table_rule_match *match;
4913 struct softnic_table_rule_action *action;
4915 char *pipeline_name, *file_name;
4916 uint32_t table_id, n_rules, n_rules_parsed, line_number;
4919 if (n_tokens != 9) {
4920 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4924 pipeline_name = tokens[1];
4926 if (strcmp(tokens[2], "table") != 0) {
4927 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4931 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
4932 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4936 if (strcmp(tokens[4], "rule") != 0) {
4937 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4941 if (strcmp(tokens[5], "add") != 0) {
4942 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4946 if (strcmp(tokens[6], "bulk") != 0) {
4947 snprintf(out, out_size, MSG_ARG_INVALID, "bulk");
4951 file_name = tokens[7];
4953 if ((softnic_parser_read_uint32(&n_rules, tokens[8]) != 0) ||
4955 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
4959 /* Memory allocation. */
4960 match = calloc(n_rules, sizeof(struct softnic_table_rule_match));
4961 action = calloc(n_rules, sizeof(struct softnic_table_rule_action));
4962 data = calloc(n_rules, sizeof(void *));
4963 if (match == NULL ||
4966 snprintf(out, out_size, MSG_OUT_OF_MEMORY);
4973 /* Load rule file */
4974 n_rules_parsed = n_rules;
4975 status = cli_rule_file_process(file_name,
4984 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
4990 if (n_rules_parsed != n_rules) {
4991 snprintf(out, out_size, MSG_FILE_NOT_ENOUGH, file_name);
4999 status = softnic_pipeline_table_rule_add_bulk(softnic,
5007 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5021 * pipeline <pipeline_name> table <table_id> rule delete
5025 cmd_softnic_pipeline_table_rule_delete(struct pmd_internals *softnic,
5031 struct softnic_table_rule_match m;
5032 char *pipeline_name;
5033 uint32_t table_id, n_tokens_parsed, t0;
5037 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5041 pipeline_name = tokens[1];
5043 if (strcmp(tokens[2], "table") != 0) {
5044 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5048 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
5049 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5053 if (strcmp(tokens[4], "rule") != 0) {
5054 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5058 if (strcmp(tokens[5], "delete") != 0) {
5059 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
5066 n_tokens_parsed = parse_match(tokens + t0,
5071 if (n_tokens_parsed == 0)
5073 t0 += n_tokens_parsed;
5075 if (n_tokens != t0) {
5076 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5080 status = softnic_pipeline_table_rule_delete(softnic,
5085 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5091 * pipeline <pipeline_name> table <table_id> rule delete
5096 cmd_softnic_pipeline_table_rule_delete_default(struct pmd_internals *softnic,
5102 char *pipeline_name;
5106 if (n_tokens != 8) {
5107 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5111 pipeline_name = tokens[1];
5113 if (strcmp(tokens[2], "table") != 0) {
5114 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5118 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
5119 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5123 if (strcmp(tokens[4], "rule") != 0) {
5124 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5128 if (strcmp(tokens[5], "delete") != 0) {
5129 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
5133 if (strcmp(tokens[6], "match") != 0) {
5134 snprintf(out, out_size, MSG_ARG_INVALID, "match");
5138 if (strcmp(tokens[7], "default") != 0) {
5139 snprintf(out, out_size, MSG_ARG_INVALID, "default");
5143 status = softnic_pipeline_table_rule_delete_default(softnic,
5147 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5153 * pipeline <pipeline_name> table <table_id> rule read stats [clear]
5156 cmd_softnic_pipeline_table_rule_stats_read(struct pmd_internals *softnic __rte_unused,
5158 uint32_t n_tokens __rte_unused,
5162 snprintf(out, out_size, MSG_CMD_UNIMPLEM, tokens[0]);
5166 * pipeline <pipeline_name> table <table_id> meter profile <meter_profile_id>
5167 * add srtcm cir <cir> cbs <cbs> ebs <ebs>
5168 * | trtcm cir <cir> pir <pir> cbs <cbs> pbs <pbs>
5171 cmd_pipeline_table_meter_profile_add(struct pmd_internals *softnic,
5177 struct rte_table_action_meter_profile p;
5178 char *pipeline_name;
5179 uint32_t table_id, meter_profile_id;
5183 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5187 pipeline_name = tokens[1];
5189 if (strcmp(tokens[2], "table") != 0) {
5190 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5194 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
5195 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5199 if (strcmp(tokens[4], "meter") != 0) {
5200 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5204 if (strcmp(tokens[5], "profile") != 0) {
5205 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
5209 if (softnic_parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
5210 snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
5214 if (strcmp(tokens[7], "add") != 0) {
5215 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
5219 if (strcmp(tokens[8], "srtcm") == 0) {
5220 if (n_tokens != 15) {
5221 snprintf(out, out_size, MSG_ARG_MISMATCH,
5226 p.alg = RTE_TABLE_ACTION_METER_SRTCM;
5228 if (strcmp(tokens[9], "cir") != 0) {
5229 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
5233 if (softnic_parser_read_uint64(&p.srtcm.cir, tokens[10]) != 0) {
5234 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
5238 if (strcmp(tokens[11], "cbs") != 0) {
5239 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
5243 if (softnic_parser_read_uint64(&p.srtcm.cbs, tokens[12]) != 0) {
5244 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
5248 if (strcmp(tokens[13], "ebs") != 0) {
5249 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ebs");
5253 if (softnic_parser_read_uint64(&p.srtcm.ebs, tokens[14]) != 0) {
5254 snprintf(out, out_size, MSG_ARG_INVALID, "ebs");
5257 } else if (strcmp(tokens[8], "trtcm") == 0) {
5258 if (n_tokens != 17) {
5259 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5263 p.alg = RTE_TABLE_ACTION_METER_TRTCM;
5265 if (strcmp(tokens[9], "cir") != 0) {
5266 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
5270 if (softnic_parser_read_uint64(&p.trtcm.cir, tokens[10]) != 0) {
5271 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
5275 if (strcmp(tokens[11], "pir") != 0) {
5276 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir");
5280 if (softnic_parser_read_uint64(&p.trtcm.pir, tokens[12]) != 0) {
5281 snprintf(out, out_size, MSG_ARG_INVALID, "pir");
5284 if (strcmp(tokens[13], "cbs") != 0) {
5285 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
5289 if (softnic_parser_read_uint64(&p.trtcm.cbs, tokens[14]) != 0) {
5290 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
5294 if (strcmp(tokens[15], "pbs") != 0) {
5295 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs");
5299 if (softnic_parser_read_uint64(&p.trtcm.pbs, tokens[16]) != 0) {
5300 snprintf(out, out_size, MSG_ARG_INVALID, "pbs");
5304 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5308 status = softnic_pipeline_table_mtr_profile_add(softnic,
5314 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5320 * pipeline <pipeline_name> table <table_id>
5321 * meter profile <meter_profile_id> delete
5324 cmd_pipeline_table_meter_profile_delete(struct pmd_internals *softnic,
5330 char *pipeline_name;
5331 uint32_t table_id, meter_profile_id;
5334 if (n_tokens != 8) {
5335 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5339 pipeline_name = tokens[1];
5341 if (strcmp(tokens[2], "table") != 0) {
5342 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5346 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
5347 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5351 if (strcmp(tokens[4], "meter") != 0) {
5352 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5356 if (strcmp(tokens[5], "profile") != 0) {
5357 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
5361 if (softnic_parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
5362 snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
5366 if (strcmp(tokens[7], "delete") != 0) {
5367 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
5371 status = softnic_pipeline_table_mtr_profile_delete(softnic,
5376 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5382 * pipeline <pipeline_name> table <table_id> rule read meter [clear]
5385 cmd_pipeline_table_rule_meter_read(struct pmd_internals *softnic __rte_unused,
5387 uint32_t n_tokens __rte_unused,
5391 snprintf(out, out_size, MSG_CMD_UNIMPLEM, tokens[0]);
5395 * pipeline <pipeline_name> table <table_id> dscp <file_name>
5398 * - exactly 64 lines
5399 * - line format: <tc_id> <tc_queue_id> <color>, with <color> as: g | y | r
5402 load_dscp_table(struct rte_table_action_dscp_table *dscp_table,
5403 const char *file_name,
5404 uint32_t *line_number)
5409 /* Check input arguments */
5410 if (dscp_table == NULL ||
5411 file_name == NULL ||
5412 line_number == NULL) {
5418 /* Open input file */
5419 f = fopen(file_name, "r");
5426 for (dscp = 0, l = 1; ; l++) {
5429 enum rte_color color;
5430 uint32_t tc_id, tc_queue_id, n_tokens = RTE_DIM(tokens);
5432 if (fgets(line, sizeof(line), f) == NULL)
5435 if (is_comment(line))
5438 if (softnic_parse_tokenize_string(line, tokens, &n_tokens)) {
5447 if (dscp >= RTE_DIM(dscp_table->entry) ||
5448 n_tokens != RTE_DIM(tokens) ||
5449 softnic_parser_read_uint32(&tc_id, tokens[0]) ||
5450 tc_id >= RTE_TABLE_ACTION_TC_MAX ||
5451 softnic_parser_read_uint32(&tc_queue_id, tokens[1]) ||
5452 tc_queue_id >= RTE_TABLE_ACTION_TC_QUEUE_MAX ||
5453 (strlen(tokens[2]) != 1)) {
5459 switch (tokens[2][0]) {
5462 color = RTE_COLOR_GREEN;
5467 color = RTE_COLOR_YELLOW;
5472 color = RTE_COLOR_RED;
5481 dscp_table->entry[dscp].tc_id = tc_id;
5482 dscp_table->entry[dscp].tc_queue_id = tc_queue_id;
5483 dscp_table->entry[dscp].color = color;
5493 cmd_pipeline_table_dscp(struct pmd_internals *softnic,
5499 struct rte_table_action_dscp_table dscp_table;
5500 char *pipeline_name, *file_name;
5501 uint32_t table_id, line_number;
5504 if (n_tokens != 6) {
5505 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5509 pipeline_name = tokens[1];
5511 if (strcmp(tokens[2], "table") != 0) {
5512 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5516 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
5517 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5521 if (strcmp(tokens[4], "dscp") != 0) {
5522 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dscp");
5526 file_name = tokens[5];
5528 status = load_dscp_table(&dscp_table, file_name, &line_number);
5530 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
5534 status = softnic_pipeline_table_dscp_table_update(softnic,
5540 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5546 * pipeline <pipeline_name> table <table_id> rule read ttl [clear]
5549 cmd_softnic_pipeline_table_rule_ttl_read(struct pmd_internals *softnic __rte_unused,
5551 uint32_t n_tokens __rte_unused,
5555 snprintf(out, out_size, MSG_CMD_UNIMPLEM, tokens[0]);
5559 * thread <thread_id> pipeline <pipeline_name> enable
5562 cmd_softnic_thread_pipeline_enable(struct pmd_internals *softnic,
5568 char *pipeline_name;
5572 if (n_tokens != 5) {
5573 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5577 if (softnic_parser_read_uint32(&thread_id, tokens[1]) != 0) {
5578 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
5582 if (strcmp(tokens[2], "pipeline") != 0) {
5583 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
5587 pipeline_name = tokens[3];
5589 if (strcmp(tokens[4], "enable") != 0) {
5590 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
5594 status = softnic_thread_pipeline_enable(softnic, thread_id, pipeline_name);
5596 snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable");
5602 * thread <thread_id> pipeline <pipeline_name> disable
5605 cmd_softnic_thread_pipeline_disable(struct pmd_internals *softnic,
5611 char *pipeline_name;
5615 if (n_tokens != 5) {
5616 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5620 if (softnic_parser_read_uint32(&thread_id, tokens[1]) != 0) {
5621 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
5625 if (strcmp(tokens[2], "pipeline") != 0) {
5626 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
5630 pipeline_name = tokens[3];
5632 if (strcmp(tokens[4], "disable") != 0) {
5633 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
5637 status = softnic_thread_pipeline_disable(softnic, thread_id, pipeline_name);
5639 snprintf(out, out_size, MSG_CMD_FAIL,
5640 "thread pipeline disable");
5649 * pipeline <pipeline_name>
5653 cmd_softnic_flowapi_map(struct pmd_internals *softnic,
5659 char *pipeline_name;
5660 uint32_t group_id, table_id;
5661 int ingress, status;
5663 if (n_tokens != 9) {
5664 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5668 if (strcmp(tokens[1], "map") != 0) {
5669 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "map");
5673 if (strcmp(tokens[2], "group") != 0) {
5674 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group");
5678 if (softnic_parser_read_uint32(&group_id, tokens[3]) != 0) {
5679 snprintf(out, out_size, MSG_ARG_INVALID, "group_id");
5683 if (strcmp(tokens[4], "ingress") == 0) {
5685 } else if (strcmp(tokens[4], "egress") == 0) {
5688 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ingress | egress");
5692 if (strcmp(tokens[5], "pipeline") != 0) {
5693 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
5697 pipeline_name = tokens[6];
5699 if (strcmp(tokens[7], "table") != 0) {
5700 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5704 if (softnic_parser_read_uint32(&table_id, tokens[8]) != 0) {
5705 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5709 status = flow_attr_map_set(softnic,
5715 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5721 softnic_cli_process(char *in, char *out, size_t out_size, void *arg)
5723 char *tokens[CMD_MAX_TOKENS];
5724 uint32_t n_tokens = RTE_DIM(tokens);
5725 struct pmd_internals *softnic = arg;
5731 status = softnic_parse_tokenize_string(in, tokens, &n_tokens);
5733 snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
5740 if (strcmp(tokens[0], "mempool") == 0) {
5741 cmd_mempool(softnic, tokens, n_tokens, out, out_size);
5745 if (strcmp(tokens[0], "link") == 0) {
5746 cmd_link(softnic, tokens, n_tokens, out, out_size);
5750 if (strcmp(tokens[0], "swq") == 0) {
5751 cmd_swq(softnic, tokens, n_tokens, out, out_size);
5755 if (strcmp(tokens[0], "tmgr") == 0) {
5756 if (n_tokens == 2) {
5757 cmd_tmgr(softnic, tokens, n_tokens, out, out_size);
5761 if (n_tokens >= 3 &&
5762 (strcmp(tokens[1], "shaper") == 0) &&
5763 (strcmp(tokens[2], "profile") == 0)) {
5764 cmd_tmgr_shaper_profile(softnic, tokens, n_tokens, out, out_size);
5768 if (n_tokens >= 3 &&
5769 (strcmp(tokens[1], "shared") == 0) &&
5770 (strcmp(tokens[2], "shaper") == 0)) {
5771 cmd_tmgr_shared_shaper(softnic, tokens, n_tokens, out, out_size);
5775 if (n_tokens >= 2 &&
5776 (strcmp(tokens[1], "node") == 0)) {
5777 cmd_tmgr_node(softnic, tokens, n_tokens, out, out_size);
5781 if (n_tokens >= 2 &&
5782 (strcmp(tokens[1], "hierarchy-default") == 0)) {
5783 cmd_tmgr_hierarchy_default(softnic, tokens, n_tokens, out, out_size);
5787 if (n_tokens >= 3 &&
5788 (strcmp(tokens[1], "hierarchy") == 0) &&
5789 (strcmp(tokens[2], "commit") == 0)) {
5790 cmd_tmgr_hierarchy_commit(softnic, tokens, n_tokens, out, out_size);
5795 if (strcmp(tokens[0], "tap") == 0) {
5796 cmd_tap(softnic, tokens, n_tokens, out, out_size);
5800 if (strcmp(tokens[0], "cryptodev") == 0) {
5801 cmd_cryptodev(softnic, tokens, n_tokens, out, out_size);
5805 if (strcmp(tokens[0], "port") == 0) {
5806 cmd_port_in_action_profile(softnic, tokens, n_tokens, out, out_size);
5810 if (strcmp(tokens[0], "table") == 0) {
5811 cmd_table_action_profile(softnic, tokens, n_tokens, out, out_size);
5815 if (strcmp(tokens[0], "pipeline") == 0) {
5816 if (n_tokens >= 3 &&
5817 (strcmp(tokens[2], "period") == 0)) {
5818 cmd_pipeline(softnic, tokens, n_tokens, out, out_size);
5822 if (n_tokens >= 5 &&
5823 (strcmp(tokens[2], "port") == 0) &&
5824 (strcmp(tokens[3], "in") == 0) &&
5825 (strcmp(tokens[4], "bsz") == 0)) {
5826 cmd_pipeline_port_in(softnic, tokens, n_tokens, out, out_size);
5830 if (n_tokens >= 5 &&
5831 (strcmp(tokens[2], "port") == 0) &&
5832 (strcmp(tokens[3], "out") == 0) &&
5833 (strcmp(tokens[4], "bsz") == 0)) {
5834 cmd_pipeline_port_out(softnic, tokens, n_tokens, out, out_size);
5838 if (n_tokens >= 4 &&
5839 (strcmp(tokens[2], "table") == 0) &&
5840 (strcmp(tokens[3], "match") == 0)) {
5841 cmd_pipeline_table(softnic, tokens, n_tokens, out, out_size);
5845 if (n_tokens >= 6 &&
5846 (strcmp(tokens[2], "port") == 0) &&
5847 (strcmp(tokens[3], "in") == 0) &&
5848 (strcmp(tokens[5], "table") == 0)) {
5849 cmd_pipeline_port_in_table(softnic, tokens, n_tokens,
5854 if (n_tokens >= 6 &&
5855 (strcmp(tokens[2], "port") == 0) &&
5856 (strcmp(tokens[3], "in") == 0) &&
5857 (strcmp(tokens[5], "stats") == 0)) {
5858 cmd_pipeline_port_in_stats(softnic, tokens, n_tokens,
5863 if (n_tokens >= 6 &&
5864 (strcmp(tokens[2], "port") == 0) &&
5865 (strcmp(tokens[3], "in") == 0) &&
5866 (strcmp(tokens[5], "enable") == 0)) {
5867 cmd_softnic_pipeline_port_in_enable(softnic, tokens, n_tokens,
5872 if (n_tokens >= 6 &&
5873 (strcmp(tokens[2], "port") == 0) &&
5874 (strcmp(tokens[3], "in") == 0) &&
5875 (strcmp(tokens[5], "disable") == 0)) {
5876 cmd_softnic_pipeline_port_in_disable(softnic, tokens, n_tokens,
5881 if (n_tokens >= 6 &&
5882 (strcmp(tokens[2], "port") == 0) &&
5883 (strcmp(tokens[3], "out") == 0) &&
5884 (strcmp(tokens[5], "stats") == 0)) {
5885 cmd_pipeline_port_out_stats(softnic, tokens, n_tokens,
5890 if (n_tokens >= 5 &&
5891 (strcmp(tokens[2], "table") == 0) &&
5892 (strcmp(tokens[4], "stats") == 0)) {
5893 cmd_pipeline_table_stats(softnic, tokens, n_tokens,
5898 if (n_tokens >= 7 &&
5899 (strcmp(tokens[2], "table") == 0) &&
5900 (strcmp(tokens[4], "rule") == 0) &&
5901 (strcmp(tokens[5], "add") == 0) &&
5902 (strcmp(tokens[6], "match") == 0)) {
5903 if (n_tokens >= 8 &&
5904 (strcmp(tokens[7], "default") == 0)) {
5905 cmd_softnic_pipeline_table_rule_add_default(softnic, tokens,
5906 n_tokens, out, out_size);
5910 cmd_softnic_pipeline_table_rule_add(softnic, tokens, n_tokens,
5915 if (n_tokens >= 7 &&
5916 (strcmp(tokens[2], "table") == 0) &&
5917 (strcmp(tokens[4], "rule") == 0) &&
5918 (strcmp(tokens[5], "add") == 0) &&
5919 (strcmp(tokens[6], "bulk") == 0)) {
5920 cmd_softnic_pipeline_table_rule_add_bulk(softnic, tokens,
5921 n_tokens, out, out_size);
5925 if (n_tokens >= 7 &&
5926 (strcmp(tokens[2], "table") == 0) &&
5927 (strcmp(tokens[4], "rule") == 0) &&
5928 (strcmp(tokens[5], "delete") == 0) &&
5929 (strcmp(tokens[6], "match") == 0)) {
5930 if (n_tokens >= 8 &&
5931 (strcmp(tokens[7], "default") == 0)) {
5932 cmd_softnic_pipeline_table_rule_delete_default(softnic, tokens,
5933 n_tokens, out, out_size);
5937 cmd_softnic_pipeline_table_rule_delete(softnic, tokens, n_tokens,
5942 if (n_tokens >= 7 &&
5943 (strcmp(tokens[2], "table") == 0) &&
5944 (strcmp(tokens[4], "rule") == 0) &&
5945 (strcmp(tokens[5], "read") == 0) &&
5946 (strcmp(tokens[6], "stats") == 0)) {
5947 cmd_softnic_pipeline_table_rule_stats_read(softnic, tokens, n_tokens,
5952 if (n_tokens >= 8 &&
5953 (strcmp(tokens[2], "table") == 0) &&
5954 (strcmp(tokens[4], "meter") == 0) &&
5955 (strcmp(tokens[5], "profile") == 0) &&
5956 (strcmp(tokens[7], "add") == 0)) {
5957 cmd_pipeline_table_meter_profile_add(softnic, tokens, n_tokens,
5962 if (n_tokens >= 8 &&
5963 (strcmp(tokens[2], "table") == 0) &&
5964 (strcmp(tokens[4], "meter") == 0) &&
5965 (strcmp(tokens[5], "profile") == 0) &&
5966 (strcmp(tokens[7], "delete") == 0)) {
5967 cmd_pipeline_table_meter_profile_delete(softnic, tokens,
5968 n_tokens, out, out_size);
5972 if (n_tokens >= 7 &&
5973 (strcmp(tokens[2], "table") == 0) &&
5974 (strcmp(tokens[4], "rule") == 0) &&
5975 (strcmp(tokens[5], "read") == 0) &&
5976 (strcmp(tokens[6], "meter") == 0)) {
5977 cmd_pipeline_table_rule_meter_read(softnic, tokens, n_tokens,
5982 if (n_tokens >= 5 &&
5983 (strcmp(tokens[2], "table") == 0) &&
5984 (strcmp(tokens[4], "dscp") == 0)) {
5985 cmd_pipeline_table_dscp(softnic, tokens, n_tokens,
5990 if (n_tokens >= 7 &&
5991 (strcmp(tokens[2], "table") == 0) &&
5992 (strcmp(tokens[4], "rule") == 0) &&
5993 (strcmp(tokens[5], "read") == 0) &&
5994 (strcmp(tokens[6], "ttl") == 0)) {
5995 cmd_softnic_pipeline_table_rule_ttl_read(softnic, tokens, n_tokens,
6001 if (strcmp(tokens[0], "thread") == 0) {
6002 if (n_tokens >= 5 &&
6003 (strcmp(tokens[4], "enable") == 0)) {
6004 cmd_softnic_thread_pipeline_enable(softnic, tokens, n_tokens,
6009 if (n_tokens >= 5 &&
6010 (strcmp(tokens[4], "disable") == 0)) {
6011 cmd_softnic_thread_pipeline_disable(softnic, tokens, n_tokens,
6017 if (strcmp(tokens[0], "flowapi") == 0) {
6018 cmd_softnic_flowapi_map(softnic, tokens, n_tokens, out,
6023 snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
6027 softnic_cli_script_process(struct pmd_internals *softnic,
6028 const char *file_name,
6029 size_t msg_in_len_max,
6030 size_t msg_out_len_max)
6032 char *msg_in = NULL, *msg_out = NULL;
6035 /* Check input arguments */
6036 if (file_name == NULL ||
6037 (strlen(file_name) == 0) ||
6038 msg_in_len_max == 0 ||
6039 msg_out_len_max == 0)
6042 msg_in = malloc(msg_in_len_max + 1);
6043 msg_out = malloc(msg_out_len_max + 1);
6044 if (msg_in == NULL ||
6051 /* Open input file */
6052 f = fopen(file_name, "r");
6061 if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
6064 printf("%s", msg_in);
6067 softnic_cli_process(msg_in,
6072 if (strlen(msg_out))
6073 printf("%s", msg_out);
6084 cli_rule_file_process(const char *file_name,
6085 size_t line_len_max,
6086 struct softnic_table_rule_match *m,
6087 struct softnic_table_rule_action *a,
6089 uint32_t *line_number,
6095 uint32_t rule_id, line_id;
6098 /* Check input arguments */
6099 if (file_name == NULL ||
6100 (strlen(file_name) == 0) ||
6101 line_len_max == 0) {
6106 /* Memory allocation */
6107 line = malloc(line_len_max + 1);
6114 f = fopen(file_name, "r");
6122 for (line_id = 1, rule_id = 0; rule_id < *n_rules; line_id++) {
6123 char *tokens[CMD_MAX_TOKENS];
6124 uint32_t n_tokens, n_tokens_parsed, t0;
6126 /* Read next line from file. */
6127 if (fgets(line, line_len_max + 1, f) == NULL)
6131 if (is_comment(line))
6135 n_tokens = RTE_DIM(tokens);
6136 status = softnic_parse_tokenize_string(line, tokens, &n_tokens);
6148 n_tokens_parsed = parse_match(tokens + t0,
6153 if (n_tokens_parsed == 0) {
6157 t0 += n_tokens_parsed;
6160 n_tokens_parsed = parse_table_action(tokens + t0,
6165 if (n_tokens_parsed == 0) {
6169 t0 += n_tokens_parsed;
6171 /* Line completed. */
6172 if (t0 < n_tokens) {
6177 /* Increment rule count */
6188 *line_number = line_id;