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,
569 return queue_id + tc_id +
570 (pipe_id + subport_id * n_pps) * RTE_SCHED_QUEUES_PER_PIPE;
573 struct tmgr_hierarchy_default_params {
574 uint32_t n_spp; /**< Number of subports per port. */
575 uint32_t n_pps; /**< Number of pipes per subport. */
581 uint32_t tc[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
585 uint32_t tc[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
586 uint32_t tc_valid[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
590 uint32_t queue[RTE_SCHED_QUEUES_PER_PIPE];
595 tmgr_hierarchy_default(struct pmd_internals *softnic,
596 struct tmgr_hierarchy_default_params *params)
598 struct rte_tm_node_params root_node_params = {
599 .shaper_profile_id = params->shaper_profile_id.port,
601 .n_sp_priorities = 1,
605 struct rte_tm_node_params subport_node_params = {
606 .shaper_profile_id = params->shaper_profile_id.subport,
608 .n_sp_priorities = 1,
612 struct rte_tm_node_params pipe_node_params = {
613 .shaper_profile_id = params->shaper_profile_id.pipe,
615 .n_sp_priorities = RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE,
619 uint32_t *shared_shaper_id =
620 (uint32_t *)calloc(RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE,
623 if (shared_shaper_id == NULL)
626 memcpy(shared_shaper_id, params->shared_shaper_id.tc,
627 sizeof(params->shared_shaper_id.tc));
629 struct rte_tm_node_params tc_node_params[] = {
631 .shaper_profile_id = params->shaper_profile_id.tc[0],
632 .shared_shaper_id = &shared_shaper_id[0],
634 (params->shared_shaper_id.tc_valid[0]) ? 1 : 0,
636 .n_sp_priorities = 1,
641 .shaper_profile_id = params->shaper_profile_id.tc[1],
642 .shared_shaper_id = &shared_shaper_id[1],
644 (params->shared_shaper_id.tc_valid[1]) ? 1 : 0,
646 .n_sp_priorities = 1,
651 .shaper_profile_id = params->shaper_profile_id.tc[2],
652 .shared_shaper_id = &shared_shaper_id[2],
654 (params->shared_shaper_id.tc_valid[2]) ? 1 : 0,
656 .n_sp_priorities = 1,
661 .shaper_profile_id = params->shaper_profile_id.tc[3],
662 .shared_shaper_id = &shared_shaper_id[3],
664 (params->shared_shaper_id.tc_valid[3]) ? 1 : 0,
666 .n_sp_priorities = 1,
671 .shaper_profile_id = params->shaper_profile_id.tc[4],
672 .shared_shaper_id = &shared_shaper_id[4],
674 (params->shared_shaper_id.tc_valid[4]) ? 1 : 0,
676 .n_sp_priorities = 1,
681 .shaper_profile_id = params->shaper_profile_id.tc[5],
682 .shared_shaper_id = &shared_shaper_id[5],
684 (params->shared_shaper_id.tc_valid[5]) ? 1 : 0,
686 .n_sp_priorities = 1,
691 .shaper_profile_id = params->shaper_profile_id.tc[6],
692 .shared_shaper_id = &shared_shaper_id[6],
694 (params->shared_shaper_id.tc_valid[6]) ? 1 : 0,
696 .n_sp_priorities = 1,
701 .shaper_profile_id = params->shaper_profile_id.tc[7],
702 .shared_shaper_id = &shared_shaper_id[7],
704 (params->shared_shaper_id.tc_valid[7]) ? 1 : 0,
706 .n_sp_priorities = 1,
711 .shaper_profile_id = params->shaper_profile_id.tc[8],
712 .shared_shaper_id = &shared_shaper_id[8],
714 (params->shared_shaper_id.tc_valid[8]) ? 1 : 0,
716 .n_sp_priorities = 1,
721 .shaper_profile_id = params->shaper_profile_id.tc[9],
722 .shared_shaper_id = &shared_shaper_id[9],
724 (params->shared_shaper_id.tc_valid[9]) ? 1 : 0,
726 .n_sp_priorities = 1,
731 .shaper_profile_id = params->shaper_profile_id.tc[10],
732 .shared_shaper_id = &shared_shaper_id[10],
734 (params->shared_shaper_id.tc_valid[10]) ? 1 : 0,
736 .n_sp_priorities = 1,
741 .shaper_profile_id = params->shaper_profile_id.tc[11],
742 .shared_shaper_id = &shared_shaper_id[11],
744 (params->shared_shaper_id.tc_valid[11]) ? 1 : 0,
746 .n_sp_priorities = 1,
751 .shaper_profile_id = params->shaper_profile_id.tc[12],
752 .shared_shaper_id = &shared_shaper_id[12],
754 (params->shared_shaper_id.tc_valid[12]) ? 1 : 0,
756 .n_sp_priorities = 1,
761 struct rte_tm_node_params queue_node_params = {
762 .shaper_profile_id = RTE_TM_SHAPER_PROFILE_ID_NONE,
765 struct rte_tm_error error;
766 uint32_t n_spp = params->n_spp, n_pps = params->n_pps, s;
770 status = rte_eth_dev_get_port_by_name(softnic->params.name, &port_id);
774 /* Hierarchy level 0: Root node */
775 status = rte_tm_node_add(port_id,
776 root_node_id(n_spp, n_pps),
780 RTE_TM_NODE_LEVEL_ID_ANY,
786 /* Hierarchy level 1: Subport nodes */
787 for (s = 0; s < params->n_spp; s++) {
790 status = rte_tm_node_add(port_id,
791 subport_node_id(n_spp, n_pps, s),
792 root_node_id(n_spp, n_pps),
795 RTE_TM_NODE_LEVEL_ID_ANY,
796 &subport_node_params,
801 /* Hierarchy level 2: Pipe nodes */
802 for (p = 0; p < params->n_pps; p++) {
805 status = rte_tm_node_add(port_id,
806 pipe_node_id(n_spp, n_pps, s, p),
807 subport_node_id(n_spp, n_pps, s),
810 RTE_TM_NODE_LEVEL_ID_ANY,
816 /* Hierarchy level 3: Traffic class nodes */
817 for (t = 0; t < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; t++) {
820 status = rte_tm_node_add(port_id,
821 tc_node_id(n_spp, n_pps, s, p, t),
822 pipe_node_id(n_spp, n_pps, s, p),
825 RTE_TM_NODE_LEVEL_ID_ANY,
831 /* Hierarchy level 4: Queue nodes */
832 if (t < RTE_SCHED_TRAFFIC_CLASS_BE) {
833 /* Strict-priority traffic class queues */
835 status = rte_tm_node_add(port_id,
836 queue_node_id(n_spp, n_pps, s, p, t, q),
837 tc_node_id(n_spp, n_pps, s, p, t),
839 params->weight.queue[q],
840 RTE_TM_NODE_LEVEL_ID_ANY,
848 /* Best-effort traffic class queues */
849 for (q = 0; q < RTE_SCHED_BE_QUEUES_PER_PIPE; q++) {
850 status = rte_tm_node_add(port_id,
851 queue_node_id(n_spp, n_pps, s, p, t, q),
852 tc_node_id(n_spp, n_pps, s, p, t),
854 params->weight.queue[q],
855 RTE_TM_NODE_LEVEL_ID_ANY,
870 * tmgr hierarchy-default
871 * spp <n_subports_per_port>
872 * pps <n_pipes_per_subport>
875 * subport <profile_id>
905 * queue <q12> ... <q15>
908 cmd_tmgr_hierarchy_default(struct pmd_internals *softnic,
914 struct tmgr_hierarchy_default_params p;
917 memset(&p, 0, sizeof(p));
919 if (n_tokens != 74) {
920 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
924 if (strcmp(tokens[1], "hierarchy-default") != 0) {
925 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "hierarchy-default");
929 if (strcmp(tokens[2], "spp") != 0) {
930 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
934 if (softnic_parser_read_uint32(&p.n_spp, tokens[3]) != 0) {
935 snprintf(out, out_size, MSG_ARG_INVALID, "n_subports_per_port");
939 if (strcmp(tokens[4], "pps") != 0) {
940 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
944 if (softnic_parser_read_uint32(&p.n_pps, tokens[5]) != 0) {
945 snprintf(out, out_size, MSG_ARG_INVALID, "n_pipes_per_subport");
951 if (strcmp(tokens[6], "shaper") != 0) {
952 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "shaper");
956 if (strcmp(tokens[7], "profile") != 0) {
957 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
961 if (strcmp(tokens[8], "port") != 0) {
962 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
966 if (softnic_parser_read_uint32(&p.shaper_profile_id.port, tokens[9]) != 0) {
967 snprintf(out, out_size, MSG_ARG_INVALID, "port profile id");
971 if (strcmp(tokens[10], "subport") != 0) {
972 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "subport");
976 if (softnic_parser_read_uint32(&p.shaper_profile_id.subport, tokens[11]) != 0) {
977 snprintf(out, out_size, MSG_ARG_INVALID, "subport profile id");
981 if (strcmp(tokens[12], "pipe") != 0) {
982 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipe");
986 if (softnic_parser_read_uint32(&p.shaper_profile_id.pipe, tokens[13]) != 0) {
987 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_profile_id");
991 if (strcmp(tokens[14], "tc0") != 0) {
992 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc0");
996 if (softnic_parser_read_uint32(&p.shaper_profile_id.tc[0], tokens[15]) != 0) {
997 snprintf(out, out_size, MSG_ARG_INVALID, "tc0 profile id");
1001 if (strcmp(tokens[16], "tc1") != 0) {
1002 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc1");
1006 if (softnic_parser_read_uint32(&p.shaper_profile_id.tc[1], tokens[17]) != 0) {
1007 snprintf(out, out_size, MSG_ARG_INVALID, "tc1 profile id");
1011 if (strcmp(tokens[18], "tc2") != 0) {
1012 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc2");
1016 if (softnic_parser_read_uint32(&p.shaper_profile_id.tc[2], tokens[19]) != 0) {
1017 snprintf(out, out_size, MSG_ARG_INVALID, "tc2 profile id");
1021 if (strcmp(tokens[20], "tc3") != 0) {
1022 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc3");
1026 if (softnic_parser_read_uint32(&p.shaper_profile_id.tc[3], tokens[21]) != 0) {
1027 snprintf(out, out_size, MSG_ARG_INVALID, "tc3 profile id");
1031 if (strcmp(tokens[22], "tc4") != 0) {
1032 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc4");
1036 if (softnic_parser_read_uint32(&p.shaper_profile_id.tc[4], tokens[23]) != 0) {
1037 snprintf(out, out_size, MSG_ARG_INVALID, "tc4 profile id");
1041 if (strcmp(tokens[24], "tc5") != 0) {
1042 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc5");
1046 if (softnic_parser_read_uint32(&p.shaper_profile_id.tc[5], tokens[25]) != 0) {
1047 snprintf(out, out_size, MSG_ARG_INVALID, "tc5 profile id");
1051 if (strcmp(tokens[26], "tc6") != 0) {
1052 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc6");
1056 if (softnic_parser_read_uint32(&p.shaper_profile_id.tc[6], tokens[27]) != 0) {
1057 snprintf(out, out_size, MSG_ARG_INVALID, "tc6 profile id");
1061 if (strcmp(tokens[28], "tc7") != 0) {
1062 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc7");
1066 if (softnic_parser_read_uint32(&p.shaper_profile_id.tc[7], tokens[29]) != 0) {
1067 snprintf(out, out_size, MSG_ARG_INVALID, "tc7 profile id");
1071 if (strcmp(tokens[30], "tc8") != 0) {
1072 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc8");
1076 if (softnic_parser_read_uint32(&p.shaper_profile_id.tc[8], tokens[31]) != 0) {
1077 snprintf(out, out_size, MSG_ARG_INVALID, "tc8 profile id");
1081 if (strcmp(tokens[32], "tc9") != 0) {
1082 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc9");
1086 if (softnic_parser_read_uint32(&p.shaper_profile_id.tc[9], tokens[33]) != 0) {
1087 snprintf(out, out_size, MSG_ARG_INVALID, "tc9 profile id");
1091 if (strcmp(tokens[34], "tc10") != 0) {
1092 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc10");
1096 if (softnic_parser_read_uint32(&p.shaper_profile_id.tc[10], tokens[35]) != 0) {
1097 snprintf(out, out_size, MSG_ARG_INVALID, "tc10 profile id");
1101 if (strcmp(tokens[36], "tc11") != 0) {
1102 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc11");
1106 if (softnic_parser_read_uint32(&p.shaper_profile_id.tc[11], tokens[37]) != 0) {
1107 snprintf(out, out_size, MSG_ARG_INVALID, "tc11 profile id");
1111 if (strcmp(tokens[38], "tc12") != 0) {
1112 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc12");
1116 if (softnic_parser_read_uint32(&p.shaper_profile_id.tc[12], tokens[39]) != 0) {
1117 snprintf(out, out_size, MSG_ARG_INVALID, "tc12 profile id");
1123 if (strcmp(tokens[40], "shared") != 0) {
1124 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "shared");
1128 if (strcmp(tokens[41], "shaper") != 0) {
1129 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "shaper");
1133 if (strcmp(tokens[42], "tc0") != 0) {
1134 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc0");
1138 if (strcmp(tokens[43], "none") == 0)
1139 p.shared_shaper_id.tc_valid[0] = 0;
1141 if (softnic_parser_read_uint32(&p.shared_shaper_id.tc[0],
1143 snprintf(out, out_size, MSG_ARG_INVALID, "shared shaper tc0");
1147 p.shared_shaper_id.tc_valid[0] = 1;
1150 if (strcmp(tokens[44], "tc1") != 0) {
1151 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc1");
1155 if (strcmp(tokens[45], "none") == 0)
1156 p.shared_shaper_id.tc_valid[1] = 0;
1158 if (softnic_parser_read_uint32(&p.shared_shaper_id.tc[1],
1160 snprintf(out, out_size, MSG_ARG_INVALID, "shared shaper tc1");
1164 p.shared_shaper_id.tc_valid[1] = 1;
1167 if (strcmp(tokens[46], "tc2") != 0) {
1168 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc2");
1172 if (strcmp(tokens[47], "none") == 0)
1173 p.shared_shaper_id.tc_valid[2] = 0;
1175 if (softnic_parser_read_uint32(&p.shared_shaper_id.tc[2],
1177 snprintf(out, out_size, MSG_ARG_INVALID, "shared shaper tc2");
1181 p.shared_shaper_id.tc_valid[2] = 1;
1184 if (strcmp(tokens[48], "tc3") != 0) {
1185 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc3");
1189 if (strcmp(tokens[49], "none") == 0)
1190 p.shared_shaper_id.tc_valid[3] = 0;
1192 if (softnic_parser_read_uint32(&p.shared_shaper_id.tc[3],
1194 snprintf(out, out_size, MSG_ARG_INVALID, "shared shaper tc3");
1198 p.shared_shaper_id.tc_valid[3] = 1;
1201 if (strcmp(tokens[50], "tc4") != 0) {
1202 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc4");
1206 if (strcmp(tokens[51], "none") == 0) {
1207 p.shared_shaper_id.tc_valid[4] = 0;
1209 if (softnic_parser_read_uint32(&p.shared_shaper_id.tc[4],
1211 snprintf(out, out_size, MSG_ARG_INVALID, "shared shaper tc4");
1215 p.shared_shaper_id.tc_valid[4] = 1;
1218 if (strcmp(tokens[52], "tc5") != 0) {
1219 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc5");
1223 if (strcmp(tokens[53], "none") == 0) {
1224 p.shared_shaper_id.tc_valid[5] = 0;
1226 if (softnic_parser_read_uint32(&p.shared_shaper_id.tc[5],
1228 snprintf(out, out_size, MSG_ARG_INVALID, "shared shaper tc5");
1232 p.shared_shaper_id.tc_valid[5] = 1;
1235 if (strcmp(tokens[54], "tc6") != 0) {
1236 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc6");
1240 if (strcmp(tokens[55], "none") == 0) {
1241 p.shared_shaper_id.tc_valid[6] = 0;
1243 if (softnic_parser_read_uint32(&p.shared_shaper_id.tc[6],
1245 snprintf(out, out_size, MSG_ARG_INVALID, "shared shaper tc6");
1249 p.shared_shaper_id.tc_valid[6] = 1;
1252 if (strcmp(tokens[56], "tc7") != 0) {
1253 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc7");
1257 if (strcmp(tokens[57], "none") == 0) {
1258 p.shared_shaper_id.tc_valid[7] = 0;
1260 if (softnic_parser_read_uint32(&p.shared_shaper_id.tc[7],
1262 snprintf(out, out_size, MSG_ARG_INVALID, "shared shaper tc7");
1266 p.shared_shaper_id.tc_valid[7] = 1;
1269 if (strcmp(tokens[58], "tc8") != 0) {
1270 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc8");
1274 if (strcmp(tokens[59], "none") == 0) {
1275 p.shared_shaper_id.tc_valid[8] = 0;
1277 if (softnic_parser_read_uint32(&p.shared_shaper_id.tc[8],
1279 snprintf(out, out_size, MSG_ARG_INVALID, "shared shaper tc8");
1283 p.shared_shaper_id.tc_valid[8] = 1;
1286 if (strcmp(tokens[60], "tc9") != 0) {
1287 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc9");
1291 if (strcmp(tokens[61], "none") == 0) {
1292 p.shared_shaper_id.tc_valid[9] = 0;
1294 if (softnic_parser_read_uint32(&p.shared_shaper_id.tc[9],
1296 snprintf(out, out_size, MSG_ARG_INVALID, "shared shaper tc9");
1300 p.shared_shaper_id.tc_valid[9] = 1;
1303 if (strcmp(tokens[62], "tc10") != 0) {
1304 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc10");
1308 if (strcmp(tokens[63], "none") == 0) {
1309 p.shared_shaper_id.tc_valid[10] = 0;
1311 if (softnic_parser_read_uint32(&p.shared_shaper_id.tc[10],
1313 snprintf(out, out_size, MSG_ARG_INVALID, "shared shaper tc10");
1317 p.shared_shaper_id.tc_valid[10] = 1;
1320 if (strcmp(tokens[64], "tc11") != 0) {
1321 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc11");
1325 if (strcmp(tokens[65], "none") == 0) {
1326 p.shared_shaper_id.tc_valid[11] = 0;
1328 if (softnic_parser_read_uint32(&p.shared_shaper_id.tc[11],
1330 snprintf(out, out_size, MSG_ARG_INVALID, "shared shaper tc11");
1334 p.shared_shaper_id.tc_valid[11] = 1;
1337 if (strcmp(tokens[66], "tc12") != 0) {
1338 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc12");
1342 if (strcmp(tokens[67], "none") == 0) {
1343 p.shared_shaper_id.tc_valid[12] = 0;
1345 if (softnic_parser_read_uint32(&p.shared_shaper_id.tc[12],
1347 snprintf(out, out_size, MSG_ARG_INVALID, "shared shaper tc12");
1351 p.shared_shaper_id.tc_valid[12] = 1;
1356 if (strcmp(tokens[68], "weight") != 0) {
1357 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "weight");
1361 if (strcmp(tokens[69], "queue") != 0) {
1362 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "queue");
1366 for (i = 0, j = 0; i < 16; i++) {
1367 if (i < RTE_SCHED_TRAFFIC_CLASS_BE) {
1368 p.weight.queue[i] = 1;
1370 if (softnic_parser_read_uint32(&p.weight.queue[i],
1371 tokens[70 + j]) != 0) {
1372 snprintf(out, out_size, MSG_ARG_INVALID, "weight queue");
1379 status = tmgr_hierarchy_default(softnic, &p);
1381 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1387 * tmgr hierarchy commit
1390 cmd_tmgr_hierarchy_commit(struct pmd_internals *softnic,
1396 struct rte_tm_error error;
1400 if (n_tokens != 3) {
1401 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1405 if (strcmp(tokens[1], "hierarchy") != 0) {
1406 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "hierarchy");
1410 if (strcmp(tokens[2], "commit") != 0) {
1411 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "commit");
1415 status = rte_eth_dev_get_port_by_name(softnic->params.name, &port_id);
1419 status = rte_tm_hierarchy_commit(port_id, 1, &error);
1421 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1430 cmd_tmgr(struct pmd_internals *softnic,
1437 struct softnic_tmgr_port *tmgr_port;
1439 if (n_tokens != 2) {
1440 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1446 tmgr_port = softnic_tmgr_port_create(softnic, name);
1447 if (tmgr_port == NULL) {
1448 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1457 cmd_tap(struct pmd_internals *softnic,
1464 struct softnic_tap *tap;
1466 if (n_tokens != 2) {
1467 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1473 tap = softnic_tap_create(softnic, name);
1475 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1481 * cryptodev <tap_name> dev <device_name> | dev_id <device_id>
1482 * queue <n_queues> <queue_size> max_sessions <n_sessions>
1486 cmd_cryptodev(struct pmd_internals *softnic,
1492 struct softnic_cryptodev_params params;
1495 memset(¶ms, 0, sizeof(params));
1496 if (n_tokens != 9) {
1497 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1503 if (strcmp(tokens[2], "dev") == 0)
1504 params.dev_name = tokens[3];
1505 else if (strcmp(tokens[2], "dev_id") == 0) {
1506 if (softnic_parser_read_uint32(¶ms.dev_id, tokens[3]) < 0) {
1507 snprintf(out, out_size, MSG_ARG_INVALID,
1512 snprintf(out, out_size, MSG_ARG_INVALID,
1517 if (strcmp(tokens[4], "queue")) {
1518 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1523 if (softnic_parser_read_uint32(¶ms.n_queues, tokens[5]) < 0) {
1524 snprintf(out, out_size, MSG_ARG_INVALID,
1529 if (softnic_parser_read_uint32(¶ms.queue_size, tokens[6]) < 0) {
1530 snprintf(out, out_size, MSG_ARG_INVALID,
1535 if (strcmp(tokens[7], "max_sessions")) {
1536 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1541 if (softnic_parser_read_uint32(¶ms.session_pool_size, tokens[8])
1543 snprintf(out, out_size, MSG_ARG_INVALID,
1548 if (softnic_cryptodev_create(softnic, name, ¶ms) == NULL) {
1549 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1555 * port in action profile <profile_name>
1556 * [filter match | mismatch offset <key_offset> mask <key_mask> key <key_value> port <port_id>]
1557 * [balance offset <key_offset> mask <key_mask> port <port_id0> ... <port_id15>]
1560 cmd_port_in_action_profile(struct pmd_internals *softnic,
1566 struct softnic_port_in_action_profile_params p;
1567 struct softnic_port_in_action_profile *ap;
1571 memset(&p, 0, sizeof(p));
1574 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1578 if (strcmp(tokens[1], "in") != 0) {
1579 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1583 if (strcmp(tokens[2], "action") != 0) {
1584 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
1588 if (strcmp(tokens[3], "profile") != 0) {
1589 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
1597 if (t0 < n_tokens &&
1598 (strcmp(tokens[t0], "filter") == 0)) {
1601 if (n_tokens < t0 + 10) {
1602 snprintf(out, out_size, MSG_ARG_MISMATCH, "port in action profile filter");
1606 if (strcmp(tokens[t0 + 1], "match") == 0) {
1607 p.fltr.filter_on_match = 1;
1608 } else if (strcmp(tokens[t0 + 1], "mismatch") == 0) {
1609 p.fltr.filter_on_match = 0;
1611 snprintf(out, out_size, MSG_ARG_INVALID, "match or mismatch");
1615 if (strcmp(tokens[t0 + 2], "offset") != 0) {
1616 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1620 if (softnic_parser_read_uint32(&p.fltr.key_offset,
1621 tokens[t0 + 3]) != 0) {
1622 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1626 if (strcmp(tokens[t0 + 4], "mask") != 0) {
1627 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
1631 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
1632 if ((softnic_parse_hex_string(tokens[t0 + 5],
1633 p.fltr.key_mask, &size) != 0) ||
1634 size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE) {
1635 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1639 if (strcmp(tokens[t0 + 6], "key") != 0) {
1640 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
1644 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
1645 if ((softnic_parse_hex_string(tokens[t0 + 7],
1646 p.fltr.key, &size) != 0) ||
1647 size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE) {
1648 snprintf(out, out_size, MSG_ARG_INVALID, "key_value");
1652 if (strcmp(tokens[t0 + 8], "port") != 0) {
1653 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1657 if (softnic_parser_read_uint32(&p.fltr.port_id,
1658 tokens[t0 + 9]) != 0) {
1659 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
1663 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_FLTR;
1667 if (t0 < n_tokens &&
1668 (strcmp(tokens[t0], "balance") == 0)) {
1671 if (n_tokens < t0 + 22) {
1672 snprintf(out, out_size, MSG_ARG_MISMATCH,
1673 "port in action profile balance");
1677 if (strcmp(tokens[t0 + 1], "offset") != 0) {
1678 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1682 if (softnic_parser_read_uint32(&p.lb.key_offset,
1683 tokens[t0 + 2]) != 0) {
1684 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1688 if (strcmp(tokens[t0 + 3], "mask") != 0) {
1689 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
1693 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
1694 if (softnic_parse_hex_string(tokens[t0 + 4],
1695 p.lb.key_mask, &p.lb.key_size) != 0) {
1696 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1700 if (strcmp(tokens[t0 + 5], "port") != 0) {
1701 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1705 for (i = 0; i < 16; i++)
1706 if (softnic_parser_read_uint32(&p.lb.port_id[i],
1707 tokens[t0 + 6 + i]) != 0) {
1708 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
1712 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_LB;
1716 if (t0 < n_tokens) {
1717 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1721 ap = softnic_port_in_action_profile_create(softnic, name, &p);
1723 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1729 * table action profile <profile_name>
1731 * offset <ip_offset>
1733 * [balance offset <key_offset> mask <key_mask> outoffset <out_offset>]
1734 * [meter srtcm | trtcm
1736 * stats none | pkts | bytes | both]
1737 * [tm spp <n_subports_per_port> pps <n_pipes_per_subport>]
1738 * [encap ether | vlan | qinq | mpls | pppoe | qinq_pppoe |
1739 * vxlan offset <ether_offset> ipv4 | ipv6 vlan on | off]
1743 * stats none | pkts]
1744 * [stats pkts | bytes | both]
1751 cmd_table_action_profile(struct pmd_internals *softnic,
1757 struct softnic_table_action_profile_params p;
1758 struct softnic_table_action_profile *ap;
1762 memset(&p, 0, sizeof(p));
1765 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1769 if (strcmp(tokens[1], "action") != 0) {
1770 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
1774 if (strcmp(tokens[2], "profile") != 0) {
1775 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
1781 if (strcmp(tokens[4], "ipv4") == 0) {
1782 p.common.ip_version = 1;
1783 } else if (strcmp(tokens[4], "ipv6") == 0) {
1784 p.common.ip_version = 0;
1786 snprintf(out, out_size, MSG_ARG_INVALID, "ipv4 or ipv6");
1790 if (strcmp(tokens[5], "offset") != 0) {
1791 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1795 if (softnic_parser_read_uint32(&p.common.ip_offset,
1797 snprintf(out, out_size, MSG_ARG_INVALID, "ip_offset");
1801 if (strcmp(tokens[7], "fwd") != 0) {
1802 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fwd");
1806 p.action_mask |= 1LLU << RTE_TABLE_ACTION_FWD;
1809 if (t0 < n_tokens &&
1810 (strcmp(tokens[t0], "balance") == 0)) {
1811 if (n_tokens < t0 + 7) {
1812 snprintf(out, out_size, MSG_ARG_MISMATCH, "table action profile balance");
1816 if (strcmp(tokens[t0 + 1], "offset") != 0) {
1817 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1821 if (softnic_parser_read_uint32(&p.lb.key_offset,
1822 tokens[t0 + 2]) != 0) {
1823 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1827 if (strcmp(tokens[t0 + 3], "mask") != 0) {
1828 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
1832 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
1833 if (softnic_parse_hex_string(tokens[t0 + 4],
1834 p.lb.key_mask, &p.lb.key_size) != 0) {
1835 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1839 if (strcmp(tokens[t0 + 5], "outoffset") != 0) {
1840 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "outoffset");
1844 if (softnic_parser_read_uint32(&p.lb.out_offset,
1845 tokens[t0 + 6]) != 0) {
1846 snprintf(out, out_size, MSG_ARG_INVALID, "out_offset");
1850 p.action_mask |= 1LLU << RTE_TABLE_ACTION_LB;
1854 if (t0 < n_tokens &&
1855 (strcmp(tokens[t0], "meter") == 0)) {
1856 if (n_tokens < t0 + 6) {
1857 snprintf(out, out_size, MSG_ARG_MISMATCH,
1858 "table action profile meter");
1862 if (strcmp(tokens[t0 + 1], "srtcm") == 0) {
1863 p.mtr.alg = RTE_TABLE_ACTION_METER_SRTCM;
1864 } else if (strcmp(tokens[t0 + 1], "trtcm") == 0) {
1865 p.mtr.alg = RTE_TABLE_ACTION_METER_TRTCM;
1867 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1872 if (strcmp(tokens[t0 + 2], "tc") != 0) {
1873 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc");
1877 if (softnic_parser_read_uint32(&p.mtr.n_tc,
1878 tokens[t0 + 3]) != 0) {
1879 snprintf(out, out_size, MSG_ARG_INVALID, "n_tc");
1883 if (strcmp(tokens[t0 + 4], "stats") != 0) {
1884 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1888 if (strcmp(tokens[t0 + 5], "none") == 0) {
1889 p.mtr.n_packets_enabled = 0;
1890 p.mtr.n_bytes_enabled = 0;
1891 } else if (strcmp(tokens[t0 + 5], "pkts") == 0) {
1892 p.mtr.n_packets_enabled = 1;
1893 p.mtr.n_bytes_enabled = 0;
1894 } else if (strcmp(tokens[t0 + 5], "bytes") == 0) {
1895 p.mtr.n_packets_enabled = 0;
1896 p.mtr.n_bytes_enabled = 1;
1897 } else if (strcmp(tokens[t0 + 5], "both") == 0) {
1898 p.mtr.n_packets_enabled = 1;
1899 p.mtr.n_bytes_enabled = 1;
1901 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1902 "none or pkts or bytes or both");
1906 p.action_mask |= 1LLU << RTE_TABLE_ACTION_MTR;
1910 if (t0 < n_tokens &&
1911 (strcmp(tokens[t0], "tm") == 0)) {
1912 if (n_tokens < t0 + 5) {
1913 snprintf(out, out_size, MSG_ARG_MISMATCH,
1914 "table action profile tm");
1918 if (strcmp(tokens[t0 + 1], "spp") != 0) {
1919 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
1923 if (softnic_parser_read_uint32(&p.tm.n_subports_per_port,
1924 tokens[t0 + 2]) != 0) {
1925 snprintf(out, out_size, MSG_ARG_INVALID,
1926 "n_subports_per_port");
1930 if (strcmp(tokens[t0 + 3], "pps") != 0) {
1931 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
1935 if (softnic_parser_read_uint32(&p.tm.n_pipes_per_subport,
1936 tokens[t0 + 4]) != 0) {
1937 snprintf(out, out_size, MSG_ARG_INVALID,
1938 "n_pipes_per_subport");
1942 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TM;
1946 if (t0 < n_tokens &&
1947 (strcmp(tokens[t0], "encap") == 0)) {
1948 uint32_t n_extra_tokens = 0;
1950 if (n_tokens < t0 + 2) {
1951 snprintf(out, out_size, MSG_ARG_MISMATCH,
1952 "action profile encap");
1956 if (strcmp(tokens[t0 + 1], "ether") == 0) {
1957 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_ETHER;
1958 } else if (strcmp(tokens[t0 + 1], "vlan") == 0) {
1959 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VLAN;
1960 } else if (strcmp(tokens[t0 + 1], "qinq") == 0) {
1961 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ;
1962 } else if (strcmp(tokens[t0 + 1], "mpls") == 0) {
1963 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_MPLS;
1964 } else if (strcmp(tokens[t0 + 1], "pppoe") == 0) {
1965 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_PPPOE;
1966 } else if (strcmp(tokens[t0 + 1], "vxlan") == 0) {
1967 if (n_tokens < t0 + 2 + 5) {
1968 snprintf(out, out_size, MSG_ARG_MISMATCH,
1969 "action profile encap vxlan");
1973 if (strcmp(tokens[t0 + 2], "offset") != 0) {
1974 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1979 if (softnic_parser_read_uint32(&p.encap.vxlan.data_offset,
1980 tokens[t0 + 2 + 1]) != 0) {
1981 snprintf(out, out_size, MSG_ARG_INVALID,
1982 "vxlan: ether_offset");
1986 if (strcmp(tokens[t0 + 2 + 2], "ipv4") == 0)
1987 p.encap.vxlan.ip_version = 1;
1988 else if (strcmp(tokens[t0 + 2 + 2], "ipv6") == 0)
1989 p.encap.vxlan.ip_version = 0;
1991 snprintf(out, out_size, MSG_ARG_INVALID,
1992 "vxlan: ipv4 or ipv6");
1996 if (strcmp(tokens[t0 + 2 + 3], "vlan") != 0) {
1997 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2002 if (strcmp(tokens[t0 + 2 + 4], "on") == 0)
2003 p.encap.vxlan.vlan = 1;
2004 else if (strcmp(tokens[t0 + 2 + 4], "off") == 0)
2005 p.encap.vxlan.vlan = 0;
2007 snprintf(out, out_size, MSG_ARG_INVALID,
2008 "vxlan: on or off");
2012 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VXLAN;
2015 } else if (strcmp(tokens[t0 + 1], "qinq_pppoe") == 0) {
2016 p.encap.encap_mask =
2017 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE;
2019 snprintf(out, out_size, MSG_ARG_MISMATCH, "encap");
2023 p.action_mask |= 1LLU << RTE_TABLE_ACTION_ENCAP;
2024 t0 += 2 + n_extra_tokens;
2027 if (t0 < n_tokens &&
2028 (strcmp(tokens[t0], "nat") == 0)) {
2029 if (n_tokens < t0 + 4) {
2030 snprintf(out, out_size, MSG_ARG_MISMATCH,
2031 "table action profile nat");
2035 if (strcmp(tokens[t0 + 1], "src") == 0) {
2036 p.nat.source_nat = 1;
2037 } else if (strcmp(tokens[t0 + 1], "dst") == 0) {
2038 p.nat.source_nat = 0;
2040 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2045 if (strcmp(tokens[t0 + 2], "proto") != 0) {
2046 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "proto");
2050 if (strcmp(tokens[t0 + 3], "tcp") == 0) {
2052 } else if (strcmp(tokens[t0 + 3], "udp") == 0) {
2055 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2060 p.action_mask |= 1LLU << RTE_TABLE_ACTION_NAT;
2064 if (t0 < n_tokens &&
2065 (strcmp(tokens[t0], "ttl") == 0)) {
2066 if (n_tokens < t0 + 4) {
2067 snprintf(out, out_size, MSG_ARG_MISMATCH,
2068 "table action profile ttl");
2072 if (strcmp(tokens[t0 + 1], "drop") == 0) {
2074 } else if (strcmp(tokens[t0 + 1], "fwd") == 0) {
2077 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2082 if (strcmp(tokens[t0 + 2], "stats") != 0) {
2083 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2087 if (strcmp(tokens[t0 + 3], "none") == 0) {
2088 p.ttl.n_packets_enabled = 0;
2089 } else if (strcmp(tokens[t0 + 3], "pkts") == 0) {
2090 p.ttl.n_packets_enabled = 1;
2092 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2097 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TTL;
2101 if (t0 < n_tokens &&
2102 (strcmp(tokens[t0], "stats") == 0)) {
2103 if (n_tokens < t0 + 2) {
2104 snprintf(out, out_size, MSG_ARG_MISMATCH,
2105 "table action profile stats");
2109 if (strcmp(tokens[t0 + 1], "pkts") == 0) {
2110 p.stats.n_packets_enabled = 1;
2111 p.stats.n_bytes_enabled = 0;
2112 } else if (strcmp(tokens[t0 + 1], "bytes") == 0) {
2113 p.stats.n_packets_enabled = 0;
2114 p.stats.n_bytes_enabled = 1;
2115 } else if (strcmp(tokens[t0 + 1], "both") == 0) {
2116 p.stats.n_packets_enabled = 1;
2117 p.stats.n_bytes_enabled = 1;
2119 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2120 "pkts or bytes or both");
2124 p.action_mask |= 1LLU << RTE_TABLE_ACTION_STATS;
2128 if (t0 < n_tokens &&
2129 (strcmp(tokens[t0], "time") == 0)) {
2130 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TIME;
2134 if (t0 < n_tokens &&
2135 (strcmp(tokens[t0], "tag") == 0)) {
2136 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TAG;
2140 if (t0 < n_tokens &&
2141 (strcmp(tokens[t0], "decap") == 0)) {
2142 p.action_mask |= 1LLU << RTE_TABLE_ACTION_DECAP;
2146 if (t0 < n_tokens && (strcmp(tokens[t0], "sym_crypto") == 0)) {
2147 struct softnic_cryptodev *cryptodev;
2149 if (n_tokens < t0 + 5 ||
2150 strcmp(tokens[t0 + 1], "dev") ||
2151 strcmp(tokens[t0 + 3], "offset")) {
2152 snprintf(out, out_size, MSG_ARG_MISMATCH,
2153 "table action profile sym_crypto");
2157 cryptodev = softnic_cryptodev_find(softnic, tokens[t0 + 2]);
2158 if (cryptodev == NULL) {
2159 snprintf(out, out_size, MSG_ARG_INVALID,
2160 "table action profile sym_crypto");
2164 p.sym_crypto.cryptodev_id = cryptodev->dev_id;
2166 if (softnic_parser_read_uint32(&p.sym_crypto.op_offset,
2167 tokens[t0 + 4]) != 0) {
2168 snprintf(out, out_size, MSG_ARG_INVALID,
2169 "table action profile sym_crypto");
2173 p.sym_crypto.mp_create = cryptodev->mp_create;
2174 p.sym_crypto.mp_init = cryptodev->mp_init;
2176 p.action_mask |= 1LLU << RTE_TABLE_ACTION_SYM_CRYPTO;
2181 if (t0 < n_tokens) {
2182 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2186 ap = softnic_table_action_profile_create(softnic, name, &p);
2188 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2194 * pipeline <pipeline_name>
2195 * period <timer_period_ms>
2196 * offset_port_id <offset_port_id>
2199 cmd_pipeline(struct pmd_internals *softnic,
2205 struct pipeline_params p;
2207 struct pipeline *pipeline;
2209 if (n_tokens != 6) {
2210 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2216 if (strcmp(tokens[2], "period") != 0) {
2217 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "period");
2221 if (softnic_parser_read_uint32(&p.timer_period_ms,
2223 snprintf(out, out_size, MSG_ARG_INVALID, "timer_period_ms");
2227 if (strcmp(tokens[4], "offset_port_id") != 0) {
2228 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset_port_id");
2232 if (softnic_parser_read_uint32(&p.offset_port_id,
2234 snprintf(out, out_size, MSG_ARG_INVALID, "offset_port_id");
2238 pipeline = softnic_pipeline_create(softnic, name, &p);
2239 if (pipeline == NULL) {
2240 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2246 * pipeline <pipeline_name> port in
2248 * link <link_name> rxq <queue_id>
2250 * | tmgr <tmgr_name>
2251 * | tap <tap_name> mempool <mempool_name> mtu <mtu>
2252 * | source mempool <mempool_name> file <file_name> bpp <n_bytes_per_pkt>
2253 * | cryptodev <cryptodev_name> rxq <queue_id>
2254 * [action <port_in_action_profile_name>]
2258 cmd_pipeline_port_in(struct pmd_internals *softnic,
2264 struct softnic_port_in_params p;
2265 char *pipeline_name;
2267 int enabled, status;
2269 memset(&p, 0, sizeof(p));
2272 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2276 pipeline_name = tokens[1];
2278 if (strcmp(tokens[2], "port") != 0) {
2279 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2283 if (strcmp(tokens[3], "in") != 0) {
2284 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2288 if (strcmp(tokens[4], "bsz") != 0) {
2289 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
2293 if (softnic_parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
2294 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
2300 if (strcmp(tokens[t0], "link") == 0) {
2301 if (n_tokens < t0 + 4) {
2302 snprintf(out, out_size, MSG_ARG_MISMATCH,
2303 "pipeline port in link");
2307 p.type = PORT_IN_RXQ;
2309 strlcpy(p.dev_name, tokens[t0 + 1], sizeof(p.dev_name));
2311 if (strcmp(tokens[t0 + 2], "rxq") != 0) {
2312 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
2316 if (softnic_parser_read_uint16(&p.rxq.queue_id,
2317 tokens[t0 + 3]) != 0) {
2318 snprintf(out, out_size, MSG_ARG_INVALID,
2323 } else if (strcmp(tokens[t0], "swq") == 0) {
2324 if (n_tokens < t0 + 2) {
2325 snprintf(out, out_size, MSG_ARG_MISMATCH,
2326 "pipeline port in swq");
2330 p.type = PORT_IN_SWQ;
2332 strlcpy(p.dev_name, tokens[t0 + 1], sizeof(p.dev_name));
2335 } else if (strcmp(tokens[t0], "tmgr") == 0) {
2336 if (n_tokens < t0 + 2) {
2337 snprintf(out, out_size, MSG_ARG_MISMATCH,
2338 "pipeline port in tmgr");
2342 p.type = PORT_IN_TMGR;
2344 strlcpy(p.dev_name, tokens[t0 + 1], sizeof(p.dev_name));
2347 } else if (strcmp(tokens[t0], "tap") == 0) {
2348 if (n_tokens < t0 + 6) {
2349 snprintf(out, out_size, MSG_ARG_MISMATCH,
2350 "pipeline port in tap");
2354 p.type = PORT_IN_TAP;
2356 strlcpy(p.dev_name, tokens[t0 + 1], sizeof(p.dev_name));
2358 if (strcmp(tokens[t0 + 2], "mempool") != 0) {
2359 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2364 p.tap.mempool_name = tokens[t0 + 3];
2366 if (strcmp(tokens[t0 + 4], "mtu") != 0) {
2367 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2372 if (softnic_parser_read_uint32(&p.tap.mtu,
2373 tokens[t0 + 5]) != 0) {
2374 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
2379 } else if (strcmp(tokens[t0], "source") == 0) {
2380 if (n_tokens < t0 + 6) {
2381 snprintf(out, out_size, MSG_ARG_MISMATCH,
2382 "pipeline port in source");
2386 p.type = PORT_IN_SOURCE;
2388 if (strcmp(tokens[t0 + 1], "mempool") != 0) {
2389 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2394 p.source.mempool_name = tokens[t0 + 2];
2396 if (strcmp(tokens[t0 + 3], "file") != 0) {
2397 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2402 p.source.file_name = tokens[t0 + 4];
2404 if (strcmp(tokens[t0 + 5], "bpp") != 0) {
2405 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2410 if (softnic_parser_read_uint32(&p.source.n_bytes_per_pkt,
2411 tokens[t0 + 6]) != 0) {
2412 snprintf(out, out_size, MSG_ARG_INVALID,
2418 } else if (strcmp(tokens[t0], "cryptodev") == 0) {
2419 if (n_tokens < t0 + 3) {
2420 snprintf(out, out_size, MSG_ARG_MISMATCH,
2421 "pipeline port in cryptodev");
2425 p.type = PORT_IN_CRYPTODEV;
2427 strlcpy(p.dev_name, tokens[t0 + 1], sizeof(p.dev_name));
2428 if (softnic_parser_read_uint16(&p.rxq.queue_id,
2429 tokens[t0 + 3]) != 0) {
2430 snprintf(out, out_size, MSG_ARG_INVALID,
2435 p.cryptodev.arg_callback = NULL;
2436 p.cryptodev.f_callback = NULL;
2440 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
2444 if (n_tokens > t0 &&
2445 (strcmp(tokens[t0], "action") == 0)) {
2446 if (n_tokens < t0 + 2) {
2447 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
2451 strlcpy(p.action_profile_name, tokens[t0 + 1],
2452 sizeof(p.action_profile_name));
2458 if (n_tokens > t0 &&
2459 (strcmp(tokens[t0], "disabled") == 0)) {
2465 if (n_tokens != t0) {
2466 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2470 status = softnic_pipeline_port_in_create(softnic,
2475 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2481 * pipeline <pipeline_name> port out
2483 * link <link_name> txq <txq_id>
2485 * | tmgr <tmgr_name>
2487 * | sink [file <file_name> pkts <max_n_pkts>]
2488 * | cryptodev <cryptodev_name> txq <txq_id> offset <crypto_op_offset>
2491 cmd_pipeline_port_out(struct pmd_internals *softnic,
2497 struct softnic_port_out_params p;
2498 char *pipeline_name;
2501 memset(&p, 0, sizeof(p));
2504 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2508 pipeline_name = tokens[1];
2510 if (strcmp(tokens[2], "port") != 0) {
2511 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2515 if (strcmp(tokens[3], "out") != 0) {
2516 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
2520 if (strcmp(tokens[4], "bsz") != 0) {
2521 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
2525 if (softnic_parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
2526 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
2530 if (strcmp(tokens[6], "link") == 0) {
2531 if (n_tokens != 10) {
2532 snprintf(out, out_size, MSG_ARG_MISMATCH,
2533 "pipeline port out link");
2537 p.type = PORT_OUT_TXQ;
2539 strlcpy(p.dev_name, tokens[7], sizeof(p.dev_name));
2541 if (strcmp(tokens[8], "txq") != 0) {
2542 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
2546 if (softnic_parser_read_uint16(&p.txq.queue_id,
2548 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
2551 } else if (strcmp(tokens[6], "swq") == 0) {
2552 if (n_tokens != 8) {
2553 snprintf(out, out_size, MSG_ARG_MISMATCH,
2554 "pipeline port out swq");
2558 p.type = PORT_OUT_SWQ;
2560 strlcpy(p.dev_name, tokens[7], sizeof(p.dev_name));
2561 } else if (strcmp(tokens[6], "tmgr") == 0) {
2562 if (n_tokens != 8) {
2563 snprintf(out, out_size, MSG_ARG_MISMATCH,
2564 "pipeline port out tmgr");
2568 p.type = PORT_OUT_TMGR;
2570 strlcpy(p.dev_name, tokens[7], sizeof(p.dev_name));
2571 } else if (strcmp(tokens[6], "tap") == 0) {
2572 if (n_tokens != 8) {
2573 snprintf(out, out_size, MSG_ARG_MISMATCH,
2574 "pipeline port out tap");
2578 p.type = PORT_OUT_TAP;
2580 strlcpy(p.dev_name, tokens[7], sizeof(p.dev_name));
2581 } else if (strcmp(tokens[6], "sink") == 0) {
2582 if ((n_tokens != 7) && (n_tokens != 11)) {
2583 snprintf(out, out_size, MSG_ARG_MISMATCH,
2584 "pipeline port out sink");
2588 p.type = PORT_OUT_SINK;
2590 if (n_tokens == 7) {
2591 p.sink.file_name = NULL;
2592 p.sink.max_n_pkts = 0;
2594 if (strcmp(tokens[7], "file") != 0) {
2595 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2600 p.sink.file_name = tokens[8];
2602 if (strcmp(tokens[9], "pkts") != 0) {
2603 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pkts");
2607 if (softnic_parser_read_uint32(&p.sink.max_n_pkts,
2609 snprintf(out, out_size, MSG_ARG_INVALID, "max_n_pkts");
2613 } else if (strcmp(tokens[6], "cryptodev") == 0) {
2614 if (n_tokens != 12) {
2615 snprintf(out, out_size, MSG_ARG_MISMATCH,
2616 "pipeline port out cryptodev");
2620 p.type = PORT_OUT_CRYPTODEV;
2622 strlcpy(p.dev_name, tokens[7], sizeof(p.dev_name));
2624 if (strcmp(tokens[8], "txq")) {
2625 snprintf(out, out_size, MSG_ARG_MISMATCH,
2626 "pipeline port out cryptodev");
2630 if (softnic_parser_read_uint16(&p.cryptodev.queue_id, tokens[9])
2632 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
2636 if (strcmp(tokens[10], "offset")) {
2637 snprintf(out, out_size, MSG_ARG_MISMATCH,
2638 "pipeline port out cryptodev");
2642 if (softnic_parser_read_uint32(&p.cryptodev.op_offset,
2644 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
2648 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
2652 status = softnic_pipeline_port_out_create(softnic, pipeline_name, &p);
2654 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2660 * pipeline <pipeline_name> table
2664 * offset <ip_header_offset>
2667 * offset <key_offset>
2673 * offset <key_offset>
2674 * buckets <n_buckets>
2678 * offset <ip_header_offset>
2681 * [action <table_action_profile_name>]
2684 cmd_pipeline_table(struct pmd_internals *softnic,
2690 struct softnic_table_params p;
2691 char *pipeline_name;
2695 memset(&p, 0, sizeof(p));
2698 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2702 pipeline_name = tokens[1];
2704 if (strcmp(tokens[2], "table") != 0) {
2705 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2709 if (strcmp(tokens[3], "match") != 0) {
2710 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
2715 if (strcmp(tokens[t0], "acl") == 0) {
2716 if (n_tokens < t0 + 6) {
2717 snprintf(out, out_size, MSG_ARG_MISMATCH,
2718 "pipeline table acl");
2722 p.match_type = TABLE_ACL;
2724 if (strcmp(tokens[t0 + 1], "ipv4") == 0) {
2725 p.match.acl.ip_version = 1;
2726 } else if (strcmp(tokens[t0 + 1], "ipv6") == 0) {
2727 p.match.acl.ip_version = 0;
2729 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2734 if (strcmp(tokens[t0 + 2], "offset") != 0) {
2735 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2739 if (softnic_parser_read_uint32(&p.match.acl.ip_header_offset,
2740 tokens[t0 + 3]) != 0) {
2741 snprintf(out, out_size, MSG_ARG_INVALID,
2742 "ip_header_offset");
2746 if (strcmp(tokens[t0 + 4], "size") != 0) {
2747 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2751 if (softnic_parser_read_uint32(&p.match.acl.n_rules,
2752 tokens[t0 + 5]) != 0) {
2753 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2758 } else if (strcmp(tokens[t0], "array") == 0) {
2759 if (n_tokens < t0 + 5) {
2760 snprintf(out, out_size, MSG_ARG_MISMATCH,
2761 "pipeline table array");
2765 p.match_type = TABLE_ARRAY;
2767 if (strcmp(tokens[t0 + 1], "offset") != 0) {
2768 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2772 if (softnic_parser_read_uint32(&p.match.array.key_offset,
2773 tokens[t0 + 2]) != 0) {
2774 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2778 if (strcmp(tokens[t0 + 3], "size") != 0) {
2779 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2783 if (softnic_parser_read_uint32(&p.match.array.n_keys,
2784 tokens[t0 + 4]) != 0) {
2785 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2790 } else if (strcmp(tokens[t0], "hash") == 0) {
2791 uint32_t key_mask_size = TABLE_RULE_MATCH_SIZE_MAX;
2793 if (n_tokens < t0 + 12) {
2794 snprintf(out, out_size, MSG_ARG_MISMATCH,
2795 "pipeline table hash");
2799 p.match_type = TABLE_HASH;
2801 if (strcmp(tokens[t0 + 1], "ext") == 0) {
2802 p.match.hash.extendable_bucket = 1;
2803 } else if (strcmp(tokens[t0 + 1], "lru") == 0) {
2804 p.match.hash.extendable_bucket = 0;
2806 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2811 if (strcmp(tokens[t0 + 2], "key") != 0) {
2812 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
2816 if ((softnic_parser_read_uint32(&p.match.hash.key_size,
2817 tokens[t0 + 3]) != 0) ||
2818 p.match.hash.key_size == 0 ||
2819 p.match.hash.key_size > TABLE_RULE_MATCH_SIZE_MAX) {
2820 snprintf(out, out_size, MSG_ARG_INVALID, "key_size");
2824 if (strcmp(tokens[t0 + 4], "mask") != 0) {
2825 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
2829 if ((softnic_parse_hex_string(tokens[t0 + 5],
2830 p.match.hash.key_mask, &key_mask_size) != 0) ||
2831 key_mask_size != p.match.hash.key_size) {
2832 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
2836 if (strcmp(tokens[t0 + 6], "offset") != 0) {
2837 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2841 if (softnic_parser_read_uint32(&p.match.hash.key_offset,
2842 tokens[t0 + 7]) != 0) {
2843 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2847 if (strcmp(tokens[t0 + 8], "buckets") != 0) {
2848 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buckets");
2852 if (softnic_parser_read_uint32(&p.match.hash.n_buckets,
2853 tokens[t0 + 9]) != 0) {
2854 snprintf(out, out_size, MSG_ARG_INVALID, "n_buckets");
2858 if (strcmp(tokens[t0 + 10], "size") != 0) {
2859 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2863 if (softnic_parser_read_uint32(&p.match.hash.n_keys,
2864 tokens[t0 + 11]) != 0) {
2865 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2870 } else if (strcmp(tokens[t0], "lpm") == 0) {
2871 if (n_tokens < t0 + 6) {
2872 snprintf(out, out_size, MSG_ARG_MISMATCH,
2873 "pipeline table lpm");
2877 p.match_type = TABLE_LPM;
2879 if (strcmp(tokens[t0 + 1], "ipv4") == 0) {
2880 p.match.lpm.key_size = 4;
2881 } else if (strcmp(tokens[t0 + 1], "ipv6") == 0) {
2882 p.match.lpm.key_size = 16;
2884 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2889 if (strcmp(tokens[t0 + 2], "offset") != 0) {
2890 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2894 if (softnic_parser_read_uint32(&p.match.lpm.key_offset,
2895 tokens[t0 + 3]) != 0) {
2896 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2900 if (strcmp(tokens[t0 + 4], "size") != 0) {
2901 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2905 if (softnic_parser_read_uint32(&p.match.lpm.n_rules,
2906 tokens[t0 + 5]) != 0) {
2907 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2912 } else if (strcmp(tokens[t0], "stub") == 0) {
2913 p.match_type = TABLE_STUB;
2917 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
2921 if (n_tokens > t0 &&
2922 (strcmp(tokens[t0], "action") == 0)) {
2923 if (n_tokens < t0 + 2) {
2924 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
2928 strlcpy(p.action_profile_name, tokens[t0 + 1],
2929 sizeof(p.action_profile_name));
2934 if (n_tokens > t0) {
2935 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2939 status = softnic_pipeline_table_create(softnic, pipeline_name, &p);
2941 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2947 * pipeline <pipeline_name> port in <port_id> table <table_id>
2950 cmd_pipeline_port_in_table(struct pmd_internals *softnic,
2956 char *pipeline_name;
2957 uint32_t port_id, table_id;
2960 if (n_tokens != 7) {
2961 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2965 pipeline_name = tokens[1];
2967 if (strcmp(tokens[2], "port") != 0) {
2968 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2972 if (strcmp(tokens[3], "in") != 0) {
2973 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2977 if (softnic_parser_read_uint32(&port_id, tokens[4]) != 0) {
2978 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2982 if (strcmp(tokens[5], "table") != 0) {
2983 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2987 if (softnic_parser_read_uint32(&table_id, tokens[6]) != 0) {
2988 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2992 status = softnic_pipeline_port_in_connect_to_table(softnic,
2997 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
3003 * pipeline <pipeline_name> port in <port_id> stats read [clear]
3006 #define MSG_PIPELINE_PORT_IN_STATS \
3007 "Pkts in: %" PRIu64 "\n" \
3008 "Pkts dropped by AH: %" PRIu64 "\n" \
3009 "Pkts dropped by other: %" PRIu64 "\n"
3012 cmd_pipeline_port_in_stats(struct pmd_internals *softnic,
3018 struct rte_pipeline_port_in_stats stats;
3019 char *pipeline_name;
3023 if (n_tokens != 7 &&
3025 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3029 pipeline_name = tokens[1];
3031 if (strcmp(tokens[2], "port") != 0) {
3032 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
3036 if (strcmp(tokens[3], "in") != 0) {
3037 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
3041 if (softnic_parser_read_uint32(&port_id, tokens[4]) != 0) {
3042 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
3046 if (strcmp(tokens[5], "stats") != 0) {
3047 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
3051 if (strcmp(tokens[6], "read") != 0) {
3052 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
3057 if (n_tokens == 8) {
3058 if (strcmp(tokens[7], "clear") != 0) {
3059 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
3066 status = softnic_pipeline_port_in_stats_read(softnic,
3072 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
3076 snprintf(out, out_size, MSG_PIPELINE_PORT_IN_STATS,
3077 stats.stats.n_pkts_in,
3078 stats.n_pkts_dropped_by_ah,
3079 stats.stats.n_pkts_drop);
3083 * pipeline <pipeline_name> port in <port_id> enable
3086 cmd_softnic_pipeline_port_in_enable(struct pmd_internals *softnic,
3092 char *pipeline_name;
3096 if (n_tokens != 6) {
3097 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3101 pipeline_name = tokens[1];
3103 if (strcmp(tokens[2], "port") != 0) {
3104 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
3108 if (strcmp(tokens[3], "in") != 0) {
3109 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
3113 if (softnic_parser_read_uint32(&port_id, tokens[4]) != 0) {
3114 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
3118 if (strcmp(tokens[5], "enable") != 0) {
3119 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
3123 status = softnic_pipeline_port_in_enable(softnic, pipeline_name, port_id);
3125 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
3131 * pipeline <pipeline_name> port in <port_id> disable
3134 cmd_softnic_pipeline_port_in_disable(struct pmd_internals *softnic,
3140 char *pipeline_name;
3144 if (n_tokens != 6) {
3145 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3149 pipeline_name = tokens[1];
3151 if (strcmp(tokens[2], "port") != 0) {
3152 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
3156 if (strcmp(tokens[3], "in") != 0) {
3157 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
3161 if (softnic_parser_read_uint32(&port_id, tokens[4]) != 0) {
3162 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
3166 if (strcmp(tokens[5], "disable") != 0) {
3167 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
3171 status = softnic_pipeline_port_in_disable(softnic, pipeline_name, port_id);
3173 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
3179 * pipeline <pipeline_name> port out <port_id> stats read [clear]
3181 #define MSG_PIPELINE_PORT_OUT_STATS \
3182 "Pkts in: %" PRIu64 "\n" \
3183 "Pkts dropped by AH: %" PRIu64 "\n" \
3184 "Pkts dropped by other: %" PRIu64 "\n"
3187 cmd_pipeline_port_out_stats(struct pmd_internals *softnic,
3193 struct rte_pipeline_port_out_stats stats;
3194 char *pipeline_name;
3198 if (n_tokens != 7 &&
3200 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3204 pipeline_name = tokens[1];
3206 if (strcmp(tokens[2], "port") != 0) {
3207 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
3211 if (strcmp(tokens[3], "out") != 0) {
3212 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
3216 if (softnic_parser_read_uint32(&port_id, tokens[4]) != 0) {
3217 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
3221 if (strcmp(tokens[5], "stats") != 0) {
3222 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
3226 if (strcmp(tokens[6], "read") != 0) {
3227 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
3232 if (n_tokens == 8) {
3233 if (strcmp(tokens[7], "clear") != 0) {
3234 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
3241 status = softnic_pipeline_port_out_stats_read(softnic,
3247 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
3251 snprintf(out, out_size, MSG_PIPELINE_PORT_OUT_STATS,
3252 stats.stats.n_pkts_in,
3253 stats.n_pkts_dropped_by_ah,
3254 stats.stats.n_pkts_drop);
3258 * pipeline <pipeline_name> table <table_id> stats read [clear]
3260 #define MSG_PIPELINE_TABLE_STATS \
3261 "Pkts in: %" PRIu64 "\n" \
3262 "Pkts in with lookup miss: %" PRIu64 "\n" \
3263 "Pkts in with lookup hit dropped by AH: %" PRIu64 "\n" \
3264 "Pkts in with lookup hit dropped by others: %" PRIu64 "\n" \
3265 "Pkts in with lookup miss dropped by AH: %" PRIu64 "\n" \
3266 "Pkts in with lookup miss dropped by others: %" PRIu64 "\n"
3269 cmd_pipeline_table_stats(struct pmd_internals *softnic,
3275 struct rte_pipeline_table_stats stats;
3276 char *pipeline_name;
3280 if (n_tokens != 6 &&
3282 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3286 pipeline_name = tokens[1];
3288 if (strcmp(tokens[2], "table") != 0) {
3289 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
3293 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
3294 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
3298 if (strcmp(tokens[4], "stats") != 0) {
3299 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
3303 if (strcmp(tokens[5], "read") != 0) {
3304 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
3309 if (n_tokens == 7) {
3310 if (strcmp(tokens[6], "clear") != 0) {
3311 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
3318 status = softnic_pipeline_table_stats_read(softnic,
3324 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
3328 snprintf(out, out_size, MSG_PIPELINE_TABLE_STATS,
3329 stats.stats.n_pkts_in,
3330 stats.stats.n_pkts_lookup_miss,
3331 stats.n_pkts_dropped_by_lkp_hit_ah,
3332 stats.n_pkts_dropped_lkp_hit,
3333 stats.n_pkts_dropped_by_lkp_miss_ah,
3334 stats.n_pkts_dropped_lkp_miss);
3342 * priority <priority>
3343 * ipv4 | ipv6 <sa> <sa_depth> <da> <da_depth>
3344 * <sp0> <sp1> <dp0> <dp1> <proto>
3348 * | ipv4_5tuple <sa> <da> <sp> <dp> <proto>
3349 * | ipv6_5tuple <sa> <da> <sp> <dp> <proto>
3350 * | ipv4_addr <addr>
3351 * | ipv6_addr <addr>
3352 * | qinq <svlan> <cvlan>
3354 * ipv4 | ipv6 <addr> <depth>
3356 struct pkt_key_qinq {
3357 uint16_t ethertype_svlan;
3359 uint16_t ethertype_cvlan;
3363 struct pkt_key_ipv4_5tuple {
3364 uint8_t time_to_live;
3366 uint16_t hdr_checksum;
3373 struct pkt_key_ipv6_5tuple {
3374 uint16_t payload_length;
3383 struct pkt_key_ipv4_addr {
3387 struct pkt_key_ipv6_addr {
3392 parse_match(char **tokens,
3396 struct softnic_table_rule_match *m)
3398 memset(m, 0, sizeof(*m));
3403 if (strcmp(tokens[0], "match") != 0) {
3404 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
3408 if (strcmp(tokens[1], "acl") == 0) {
3409 if (n_tokens < 14) {
3410 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3414 m->match_type = TABLE_ACL;
3416 if (strcmp(tokens[2], "priority") != 0) {
3417 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "priority");
3421 if (softnic_parser_read_uint32(&m->match.acl.priority,
3423 snprintf(out, out_size, MSG_ARG_INVALID, "priority");
3427 if (strcmp(tokens[4], "ipv4") == 0) {
3428 struct in_addr saddr, daddr;
3430 m->match.acl.ip_version = 1;
3432 if (softnic_parse_ipv4_addr(tokens[5], &saddr) != 0) {
3433 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
3436 m->match.acl.ipv4.sa = rte_be_to_cpu_32(saddr.s_addr);
3438 if (softnic_parse_ipv4_addr(tokens[7], &daddr) != 0) {
3439 snprintf(out, out_size, MSG_ARG_INVALID, "da");
3442 m->match.acl.ipv4.da = rte_be_to_cpu_32(daddr.s_addr);
3443 } else if (strcmp(tokens[4], "ipv6") == 0) {
3444 struct in6_addr saddr, daddr;
3446 m->match.acl.ip_version = 0;
3448 if (softnic_parse_ipv6_addr(tokens[5], &saddr) != 0) {
3449 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
3452 memcpy(m->match.acl.ipv6.sa, saddr.s6_addr, 16);
3454 if (softnic_parse_ipv6_addr(tokens[7], &daddr) != 0) {
3455 snprintf(out, out_size, MSG_ARG_INVALID, "da");
3458 memcpy(m->match.acl.ipv6.da, daddr.s6_addr, 16);
3460 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
3465 if (softnic_parser_read_uint32(&m->match.acl.sa_depth,
3467 snprintf(out, out_size, MSG_ARG_INVALID, "sa_depth");
3471 if (softnic_parser_read_uint32(&m->match.acl.da_depth,
3473 snprintf(out, out_size, MSG_ARG_INVALID, "da_depth");
3477 if (softnic_parser_read_uint16(&m->match.acl.sp0, tokens[9]) != 0) {
3478 snprintf(out, out_size, MSG_ARG_INVALID, "sp0");
3482 if (softnic_parser_read_uint16(&m->match.acl.sp1, tokens[10]) != 0) {
3483 snprintf(out, out_size, MSG_ARG_INVALID, "sp1");
3487 if (softnic_parser_read_uint16(&m->match.acl.dp0, tokens[11]) != 0) {
3488 snprintf(out, out_size, MSG_ARG_INVALID, "dp0");
3492 if (softnic_parser_read_uint16(&m->match.acl.dp1, tokens[12]) != 0) {
3493 snprintf(out, out_size, MSG_ARG_INVALID, "dp1");
3497 if (softnic_parser_read_uint8(&m->match.acl.proto, tokens[13]) != 0) {
3498 snprintf(out, out_size, MSG_ARG_INVALID, "proto");
3502 m->match.acl.proto_mask = 0xff;
3507 if (strcmp(tokens[1], "array") == 0) {
3509 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3513 m->match_type = TABLE_ARRAY;
3515 if (softnic_parser_read_uint32(&m->match.array.pos, tokens[2]) != 0) {
3516 snprintf(out, out_size, MSG_ARG_INVALID, "pos");
3523 if (strcmp(tokens[1], "hash") == 0) {
3525 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3529 m->match_type = TABLE_HASH;
3531 if (strcmp(tokens[2], "raw") == 0) {
3532 uint32_t key_size = TABLE_RULE_MATCH_SIZE_MAX;
3535 snprintf(out, out_size, MSG_ARG_MISMATCH,
3540 if (softnic_parse_hex_string(tokens[3],
3541 m->match.hash.key, &key_size) != 0) {
3542 snprintf(out, out_size, MSG_ARG_INVALID, "key");
3549 if (strcmp(tokens[2], "ipv4_5tuple") == 0) {
3550 struct pkt_key_ipv4_5tuple *ipv4 =
3551 (struct pkt_key_ipv4_5tuple *)m->match.hash.key;
3552 struct in_addr saddr, daddr;
3557 snprintf(out, out_size, MSG_ARG_MISMATCH,
3562 if (softnic_parse_ipv4_addr(tokens[3], &saddr) != 0) {
3563 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
3567 if (softnic_parse_ipv4_addr(tokens[4], &daddr) != 0) {
3568 snprintf(out, out_size, MSG_ARG_INVALID, "da");
3572 if (softnic_parser_read_uint16(&sp, tokens[5]) != 0) {
3573 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
3577 if (softnic_parser_read_uint16(&dp, tokens[6]) != 0) {
3578 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
3582 if (softnic_parser_read_uint8(&proto, tokens[7]) != 0) {
3583 snprintf(out, out_size, MSG_ARG_INVALID,
3588 ipv4->sa = saddr.s_addr;
3589 ipv4->da = daddr.s_addr;
3590 ipv4->sp = rte_cpu_to_be_16(sp);
3591 ipv4->dp = rte_cpu_to_be_16(dp);
3592 ipv4->proto = proto;
3595 } /* hash ipv4_5tuple */
3597 if (strcmp(tokens[2], "ipv6_5tuple") == 0) {
3598 struct pkt_key_ipv6_5tuple *ipv6 =
3599 (struct pkt_key_ipv6_5tuple *)m->match.hash.key;
3600 struct in6_addr saddr, daddr;
3605 snprintf(out, out_size, MSG_ARG_MISMATCH,
3610 if (softnic_parse_ipv6_addr(tokens[3], &saddr) != 0) {
3611 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
3615 if (softnic_parse_ipv6_addr(tokens[4], &daddr) != 0) {
3616 snprintf(out, out_size, MSG_ARG_INVALID, "da");
3620 if (softnic_parser_read_uint16(&sp, tokens[5]) != 0) {
3621 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
3625 if (softnic_parser_read_uint16(&dp, tokens[6]) != 0) {
3626 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
3630 if (softnic_parser_read_uint8(&proto, tokens[7]) != 0) {
3631 snprintf(out, out_size, MSG_ARG_INVALID,
3636 memcpy(ipv6->sa, saddr.s6_addr, 16);
3637 memcpy(ipv6->da, daddr.s6_addr, 16);
3638 ipv6->sp = rte_cpu_to_be_16(sp);
3639 ipv6->dp = rte_cpu_to_be_16(dp);
3640 ipv6->proto = proto;
3643 } /* hash ipv6_5tuple */
3645 if (strcmp(tokens[2], "ipv4_addr") == 0) {
3646 struct pkt_key_ipv4_addr *ipv4_addr =
3647 (struct pkt_key_ipv4_addr *)m->match.hash.key;
3648 struct in_addr addr;
3651 snprintf(out, out_size, MSG_ARG_MISMATCH,
3656 if (softnic_parse_ipv4_addr(tokens[3], &addr) != 0) {
3657 snprintf(out, out_size, MSG_ARG_INVALID,
3662 ipv4_addr->addr = addr.s_addr;
3665 } /* hash ipv4_addr */
3667 if (strcmp(tokens[2], "ipv6_addr") == 0) {
3668 struct pkt_key_ipv6_addr *ipv6_addr =
3669 (struct pkt_key_ipv6_addr *)m->match.hash.key;
3670 struct in6_addr addr;
3673 snprintf(out, out_size, MSG_ARG_MISMATCH,
3678 if (softnic_parse_ipv6_addr(tokens[3], &addr) != 0) {
3679 snprintf(out, out_size, MSG_ARG_INVALID,
3684 memcpy(ipv6_addr->addr, addr.s6_addr, 16);
3687 } /* hash ipv6_5tuple */
3689 if (strcmp(tokens[2], "qinq") == 0) {
3690 struct pkt_key_qinq *qinq =
3691 (struct pkt_key_qinq *)m->match.hash.key;
3692 uint16_t svlan, cvlan;
3695 snprintf(out, out_size, MSG_ARG_MISMATCH,
3700 if ((softnic_parser_read_uint16(&svlan, tokens[3]) != 0) ||
3702 snprintf(out, out_size, MSG_ARG_INVALID,
3707 if ((softnic_parser_read_uint16(&cvlan, tokens[4]) != 0) ||
3709 snprintf(out, out_size, MSG_ARG_INVALID,
3714 qinq->svlan = rte_cpu_to_be_16(svlan);
3715 qinq->cvlan = rte_cpu_to_be_16(cvlan);
3720 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3724 if (strcmp(tokens[1], "lpm") == 0) {
3726 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3730 m->match_type = TABLE_LPM;
3732 if (strcmp(tokens[2], "ipv4") == 0) {
3733 struct in_addr addr;
3735 m->match.lpm.ip_version = 1;
3737 if (softnic_parse_ipv4_addr(tokens[3], &addr) != 0) {
3738 snprintf(out, out_size, MSG_ARG_INVALID,
3743 m->match.lpm.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3744 } else if (strcmp(tokens[2], "ipv6") == 0) {
3745 struct in6_addr addr;
3747 m->match.lpm.ip_version = 0;
3749 if (softnic_parse_ipv6_addr(tokens[3], &addr) != 0) {
3750 snprintf(out, out_size, MSG_ARG_INVALID,
3755 memcpy(m->match.lpm.ipv6, addr.s6_addr, 16);
3757 snprintf(out, out_size, MSG_ARG_MISMATCH,
3762 if (softnic_parser_read_uint8(&m->match.lpm.depth, tokens[4]) != 0) {
3763 snprintf(out, out_size, MSG_ARG_INVALID, "depth");
3770 snprintf(out, out_size, MSG_ARG_MISMATCH,
3771 "acl or array or hash or lpm");
3783 * | table <table_id>
3784 * [balance <out0> ... <out7>]
3786 * tc0 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3787 * [tc1 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3788 * tc2 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3789 * tc3 meter <meter_profile_id> policer g <pa> y <pa> r <pa>]]
3790 * [tm subport <subport_id> pipe <pipe_id>]
3793 * | vlan <da> <sa> <pcp> <dei> <vid>
3794 * | qinq <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid>
3795 * | qinq_pppoe <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid> <session_id>
3796 * | mpls unicast | multicast
3798 * label0 <label> <tc> <ttl>
3799 * [label1 <label> <tc> <ttl>
3800 * [label2 <label> <tc> <ttl>
3801 * [label3 <label> <tc> <ttl>]]]
3802 * | pppoe <da> <sa> <session_id>]
3803 * | vxlan ether <da> <sa>
3804 * [vlan <pcp> <dei> <vid>]
3805 * ipv4 <sa> <da> <dscp> <ttl>
3806 * | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit>
3809 * [nat ipv4 | ipv6 <addr> <port>]
3819 * cipher_algo <algo> cipher_key <key> cipher_iv <iv>
3821 * cipher_algo <algo> cipher_key <key> cipher_iv <iv>
3822 * auth_algo <algo> auth_key <key> digest_size <size>
3824 * aead_algo <algo> aead_key <key> aead_iv <iv> aead_aad <aad>
3825 * digest_size <size>
3826 * data_offset <data_offset>]
3829 * <pa> ::= g | y | r | drop
3832 parse_table_action_fwd(char **tokens,
3834 struct softnic_table_rule_action *a)
3836 if (n_tokens == 0 ||
3837 (strcmp(tokens[0], "fwd") != 0))
3843 if (n_tokens && (strcmp(tokens[0], "drop") == 0)) {
3844 a->fwd.action = RTE_PIPELINE_ACTION_DROP;
3845 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3849 if (n_tokens && (strcmp(tokens[0], "port") == 0)) {
3853 softnic_parser_read_uint32(&id, tokens[1]))
3856 a->fwd.action = RTE_PIPELINE_ACTION_PORT;
3858 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3862 if (n_tokens && (strcmp(tokens[0], "meta") == 0)) {
3863 a->fwd.action = RTE_PIPELINE_ACTION_PORT_META;
3864 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3868 if (n_tokens && (strcmp(tokens[0], "table") == 0)) {
3872 softnic_parser_read_uint32(&id, tokens[1]))
3875 a->fwd.action = RTE_PIPELINE_ACTION_TABLE;
3877 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3885 parse_table_action_balance(char **tokens,
3887 struct softnic_table_rule_action *a)
3891 if (n_tokens == 0 ||
3892 (strcmp(tokens[0], "balance") != 0))
3898 if (n_tokens < RTE_TABLE_ACTION_LB_TABLE_SIZE)
3901 for (i = 0; i < RTE_TABLE_ACTION_LB_TABLE_SIZE; i++)
3902 if (softnic_parser_read_uint32(&a->lb.out[i], tokens[i]) != 0)
3905 a->action_mask |= 1 << RTE_TABLE_ACTION_LB;
3906 return 1 + RTE_TABLE_ACTION_LB_TABLE_SIZE;
3910 parse_policer_action(char *token, enum rte_table_action_policer *a)
3912 if (strcmp(token, "g") == 0) {
3913 *a = RTE_TABLE_ACTION_POLICER_COLOR_GREEN;
3917 if (strcmp(token, "y") == 0) {
3918 *a = RTE_TABLE_ACTION_POLICER_COLOR_YELLOW;
3922 if (strcmp(token, "r") == 0) {
3923 *a = RTE_TABLE_ACTION_POLICER_COLOR_RED;
3927 if (strcmp(token, "drop") == 0) {
3928 *a = RTE_TABLE_ACTION_POLICER_DROP;
3936 parse_table_action_meter_tc(char **tokens,
3938 struct rte_table_action_mtr_tc_params *mtr)
3941 strcmp(tokens[0], "meter") ||
3942 softnic_parser_read_uint32(&mtr->meter_profile_id, tokens[1]) ||
3943 strcmp(tokens[2], "policer") ||
3944 strcmp(tokens[3], "g") ||
3945 parse_policer_action(tokens[4], &mtr->policer[RTE_COLOR_GREEN]) ||
3946 strcmp(tokens[5], "y") ||
3947 parse_policer_action(tokens[6], &mtr->policer[RTE_COLOR_YELLOW]) ||
3948 strcmp(tokens[7], "r") ||
3949 parse_policer_action(tokens[8], &mtr->policer[RTE_COLOR_RED]))
3956 parse_table_action_meter(char **tokens,
3958 struct softnic_table_rule_action *a)
3960 if (n_tokens == 0 ||
3961 strcmp(tokens[0], "meter"))
3967 if (n_tokens < 10 ||
3968 strcmp(tokens[0], "tc0") ||
3969 (parse_table_action_meter_tc(tokens + 1,
3971 &a->mtr.mtr[0]) == 0))
3977 if (n_tokens == 0 ||
3978 strcmp(tokens[0], "tc1")) {
3980 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3984 if (n_tokens < 30 ||
3985 (parse_table_action_meter_tc(tokens + 1,
3986 n_tokens - 1, &a->mtr.mtr[1]) == 0) ||
3987 strcmp(tokens[10], "tc2") ||
3988 (parse_table_action_meter_tc(tokens + 11,
3989 n_tokens - 11, &a->mtr.mtr[2]) == 0) ||
3990 strcmp(tokens[20], "tc3") ||
3991 (parse_table_action_meter_tc(tokens + 21,
3992 n_tokens - 21, &a->mtr.mtr[3]) == 0))
3995 a->mtr.tc_mask = 0xF;
3996 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3997 return 1 + 10 + 3 * 10;
4001 parse_table_action_tm(char **tokens,
4003 struct softnic_table_rule_action *a)
4005 uint32_t subport_id, pipe_id;
4008 strcmp(tokens[0], "tm") ||
4009 strcmp(tokens[1], "subport") ||
4010 softnic_parser_read_uint32(&subport_id, tokens[2]) ||
4011 strcmp(tokens[3], "pipe") ||
4012 softnic_parser_read_uint32(&pipe_id, tokens[4]))
4015 a->tm.subport_id = subport_id;
4016 a->tm.pipe_id = pipe_id;
4017 a->action_mask |= 1 << RTE_TABLE_ACTION_TM;
4022 parse_table_action_encap(char **tokens,
4024 struct softnic_table_rule_action *a)
4026 if (n_tokens == 0 ||
4027 strcmp(tokens[0], "encap"))
4034 if (n_tokens && (strcmp(tokens[0], "ether") == 0)) {
4036 softnic_parse_mac_addr(tokens[1], &a->encap.ether.ether.da) ||
4037 softnic_parse_mac_addr(tokens[2], &a->encap.ether.ether.sa))
4040 a->encap.type = RTE_TABLE_ACTION_ENCAP_ETHER;
4041 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
4046 if (n_tokens && (strcmp(tokens[0], "vlan") == 0)) {
4047 uint32_t pcp, dei, vid;
4050 softnic_parse_mac_addr(tokens[1], &a->encap.vlan.ether.da) ||
4051 softnic_parse_mac_addr(tokens[2], &a->encap.vlan.ether.sa) ||
4052 softnic_parser_read_uint32(&pcp, tokens[3]) ||
4054 softnic_parser_read_uint32(&dei, tokens[4]) ||
4056 softnic_parser_read_uint32(&vid, tokens[5]) ||
4060 a->encap.vlan.vlan.pcp = pcp & 0x7;
4061 a->encap.vlan.vlan.dei = dei & 0x1;
4062 a->encap.vlan.vlan.vid = vid & 0xFFF;
4063 a->encap.type = RTE_TABLE_ACTION_ENCAP_VLAN;
4064 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
4069 if (n_tokens && (strcmp(tokens[0], "qinq") == 0)) {
4070 uint32_t svlan_pcp, svlan_dei, svlan_vid;
4071 uint32_t cvlan_pcp, cvlan_dei, cvlan_vid;
4074 softnic_parse_mac_addr(tokens[1], &a->encap.qinq.ether.da) ||
4075 softnic_parse_mac_addr(tokens[2], &a->encap.qinq.ether.sa) ||
4076 softnic_parser_read_uint32(&svlan_pcp, tokens[3]) ||
4078 softnic_parser_read_uint32(&svlan_dei, tokens[4]) ||
4080 softnic_parser_read_uint32(&svlan_vid, tokens[5]) ||
4081 svlan_vid > 0xFFF ||
4082 softnic_parser_read_uint32(&cvlan_pcp, tokens[6]) ||
4084 softnic_parser_read_uint32(&cvlan_dei, tokens[7]) ||
4086 softnic_parser_read_uint32(&cvlan_vid, tokens[8]) ||
4090 a->encap.qinq.svlan.pcp = svlan_pcp & 0x7;
4091 a->encap.qinq.svlan.dei = svlan_dei & 0x1;
4092 a->encap.qinq.svlan.vid = svlan_vid & 0xFFF;
4093 a->encap.qinq.cvlan.pcp = cvlan_pcp & 0x7;
4094 a->encap.qinq.cvlan.dei = cvlan_dei & 0x1;
4095 a->encap.qinq.cvlan.vid = cvlan_vid & 0xFFF;
4096 a->encap.type = RTE_TABLE_ACTION_ENCAP_QINQ;
4097 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
4102 if (n_tokens && (strcmp(tokens[0], "qinq_pppoe") == 0)) {
4103 uint32_t svlan_pcp, svlan_dei, svlan_vid;
4104 uint32_t cvlan_pcp, cvlan_dei, cvlan_vid;
4106 if (n_tokens < 10 ||
4107 softnic_parse_mac_addr(tokens[1],
4108 &a->encap.qinq_pppoe.ether.da) ||
4109 softnic_parse_mac_addr(tokens[2],
4110 &a->encap.qinq_pppoe.ether.sa) ||
4111 softnic_parser_read_uint32(&svlan_pcp, tokens[3]) ||
4113 softnic_parser_read_uint32(&svlan_dei, tokens[4]) ||
4115 softnic_parser_read_uint32(&svlan_vid, tokens[5]) ||
4116 svlan_vid > 0xFFF ||
4117 softnic_parser_read_uint32(&cvlan_pcp, tokens[6]) ||
4119 softnic_parser_read_uint32(&cvlan_dei, tokens[7]) ||
4121 softnic_parser_read_uint32(&cvlan_vid, tokens[8]) ||
4122 cvlan_vid > 0xFFF ||
4123 softnic_parser_read_uint16(&a->encap.qinq_pppoe.pppoe.session_id,
4127 a->encap.qinq_pppoe.svlan.pcp = svlan_pcp & 0x7;
4128 a->encap.qinq_pppoe.svlan.dei = svlan_dei & 0x1;
4129 a->encap.qinq_pppoe.svlan.vid = svlan_vid & 0xFFF;
4130 a->encap.qinq_pppoe.cvlan.pcp = cvlan_pcp & 0x7;
4131 a->encap.qinq_pppoe.cvlan.dei = cvlan_dei & 0x1;
4132 a->encap.qinq_pppoe.cvlan.vid = cvlan_vid & 0xFFF;
4133 a->encap.type = RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE;
4134 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
4139 if (n_tokens && (strcmp(tokens[0], "mpls") == 0)) {
4140 uint32_t label, tc, ttl;
4145 if (strcmp(tokens[1], "unicast") == 0)
4146 a->encap.mpls.unicast = 1;
4147 else if (strcmp(tokens[1], "multicast") == 0)
4148 a->encap.mpls.unicast = 0;
4152 if (softnic_parse_mac_addr(tokens[2], &a->encap.mpls.ether.da) ||
4153 softnic_parse_mac_addr(tokens[3], &a->encap.mpls.ether.sa) ||
4154 strcmp(tokens[4], "label0") ||
4155 softnic_parser_read_uint32(&label, tokens[5]) ||
4157 softnic_parser_read_uint32(&tc, tokens[6]) ||
4159 softnic_parser_read_uint32(&ttl, tokens[7]) ||
4163 a->encap.mpls.mpls[0].label = label;
4164 a->encap.mpls.mpls[0].tc = tc;
4165 a->encap.mpls.mpls[0].ttl = ttl;
4170 if (n_tokens == 0 ||
4171 strcmp(tokens[0], "label1")) {
4172 a->encap.mpls.mpls_count = 1;
4173 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
4174 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
4179 softnic_parser_read_uint32(&label, tokens[1]) ||
4181 softnic_parser_read_uint32(&tc, tokens[2]) ||
4183 softnic_parser_read_uint32(&ttl, tokens[3]) ||
4187 a->encap.mpls.mpls[1].label = label;
4188 a->encap.mpls.mpls[1].tc = tc;
4189 a->encap.mpls.mpls[1].ttl = ttl;
4194 if (n_tokens == 0 ||
4195 strcmp(tokens[0], "label2")) {
4196 a->encap.mpls.mpls_count = 2;
4197 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
4198 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
4203 softnic_parser_read_uint32(&label, tokens[1]) ||
4205 softnic_parser_read_uint32(&tc, tokens[2]) ||
4207 softnic_parser_read_uint32(&ttl, tokens[3]) ||
4211 a->encap.mpls.mpls[2].label = label;
4212 a->encap.mpls.mpls[2].tc = tc;
4213 a->encap.mpls.mpls[2].ttl = ttl;
4218 if (n_tokens == 0 ||
4219 strcmp(tokens[0], "label3")) {
4220 a->encap.mpls.mpls_count = 3;
4221 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
4222 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
4223 return 1 + 8 + 4 + 4;
4227 softnic_parser_read_uint32(&label, tokens[1]) ||
4229 softnic_parser_read_uint32(&tc, tokens[2]) ||
4231 softnic_parser_read_uint32(&ttl, tokens[3]) ||
4235 a->encap.mpls.mpls[3].label = label;
4236 a->encap.mpls.mpls[3].tc = tc;
4237 a->encap.mpls.mpls[3].ttl = ttl;
4239 a->encap.mpls.mpls_count = 4;
4240 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
4241 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
4242 return 1 + 8 + 4 + 4 + 4;
4246 if (n_tokens && (strcmp(tokens[0], "pppoe") == 0)) {
4248 softnic_parse_mac_addr(tokens[1], &a->encap.pppoe.ether.da) ||
4249 softnic_parse_mac_addr(tokens[2], &a->encap.pppoe.ether.sa) ||
4250 softnic_parser_read_uint16(&a->encap.pppoe.pppoe.session_id,
4254 a->encap.type = RTE_TABLE_ACTION_ENCAP_PPPOE;
4255 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
4260 if (n_tokens && (strcmp(tokens[0], "vxlan") == 0)) {
4267 /* ether <da> <sa> */
4268 if ((n_tokens < 3) ||
4269 strcmp(tokens[0], "ether") ||
4270 softnic_parse_mac_addr(tokens[1], &a->encap.vxlan.ether.da) ||
4271 softnic_parse_mac_addr(tokens[2], &a->encap.vxlan.ether.sa))
4278 /* [vlan <pcp> <dei> <vid>] */
4279 if (strcmp(tokens[0], "vlan") == 0) {
4280 uint32_t pcp, dei, vid;
4282 if ((n_tokens < 4) ||
4283 softnic_parser_read_uint32(&pcp, tokens[1]) ||
4285 softnic_parser_read_uint32(&dei, tokens[2]) ||
4287 softnic_parser_read_uint32(&vid, tokens[3]) ||
4291 a->encap.vxlan.vlan.pcp = pcp;
4292 a->encap.vxlan.vlan.dei = dei;
4293 a->encap.vxlan.vlan.vid = vid;
4300 /* ipv4 <sa> <da> <dscp> <ttl>
4301 | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit> */
4302 if (strcmp(tokens[0], "ipv4") == 0) {
4303 struct in_addr sa, da;
4306 if ((n_tokens < 5) ||
4307 softnic_parse_ipv4_addr(tokens[1], &sa) ||
4308 softnic_parse_ipv4_addr(tokens[2], &da) ||
4309 softnic_parser_read_uint8(&dscp, tokens[3]) ||
4311 softnic_parser_read_uint8(&ttl, tokens[4]))
4314 a->encap.vxlan.ipv4.sa = rte_be_to_cpu_32(sa.s_addr);
4315 a->encap.vxlan.ipv4.da = rte_be_to_cpu_32(da.s_addr);
4316 a->encap.vxlan.ipv4.dscp = dscp;
4317 a->encap.vxlan.ipv4.ttl = ttl;
4322 } else if (strcmp(tokens[0], "ipv6") == 0) {
4323 struct in6_addr sa, da;
4324 uint32_t flow_label;
4325 uint8_t dscp, hop_limit;
4327 if ((n_tokens < 6) ||
4328 softnic_parse_ipv6_addr(tokens[1], &sa) ||
4329 softnic_parse_ipv6_addr(tokens[2], &da) ||
4330 softnic_parser_read_uint32(&flow_label, tokens[3]) ||
4331 softnic_parser_read_uint8(&dscp, tokens[4]) ||
4333 softnic_parser_read_uint8(&hop_limit, tokens[5]))
4336 memcpy(a->encap.vxlan.ipv6.sa, sa.s6_addr, 16);
4337 memcpy(a->encap.vxlan.ipv6.da, da.s6_addr, 16);
4338 a->encap.vxlan.ipv6.flow_label = flow_label;
4339 a->encap.vxlan.ipv6.dscp = dscp;
4340 a->encap.vxlan.ipv6.hop_limit = hop_limit;
4349 if ((n_tokens < 3) ||
4350 strcmp(tokens[0], "udp") ||
4351 softnic_parser_read_uint16(&a->encap.vxlan.udp.sp, tokens[1]) ||
4352 softnic_parser_read_uint16(&a->encap.vxlan.udp.dp, tokens[2]))
4360 if ((n_tokens < 2) ||
4361 strcmp(tokens[0], "vxlan") ||
4362 softnic_parser_read_uint32(&a->encap.vxlan.vxlan.vni, tokens[1]) ||
4363 (a->encap.vxlan.vxlan.vni > 0xFFFFFF))
4370 a->encap.type = RTE_TABLE_ACTION_ENCAP_VXLAN;
4371 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
4379 parse_table_action_nat(char **tokens,
4381 struct softnic_table_rule_action *a)
4384 strcmp(tokens[0], "nat"))
4387 if (strcmp(tokens[1], "ipv4") == 0) {
4388 struct in_addr addr;
4391 if (softnic_parse_ipv4_addr(tokens[2], &addr) ||
4392 softnic_parser_read_uint16(&port, tokens[3]))
4395 a->nat.ip_version = 1;
4396 a->nat.addr.ipv4 = rte_be_to_cpu_32(addr.s_addr);
4398 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
4402 if (strcmp(tokens[1], "ipv6") == 0) {
4403 struct in6_addr addr;
4406 if (softnic_parse_ipv6_addr(tokens[2], &addr) ||
4407 softnic_parser_read_uint16(&port, tokens[3]))
4410 a->nat.ip_version = 0;
4411 memcpy(a->nat.addr.ipv6, addr.s6_addr, 16);
4413 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
4421 parse_table_action_ttl(char **tokens,
4423 struct softnic_table_rule_action *a)
4426 strcmp(tokens[0], "ttl"))
4429 if (strcmp(tokens[1], "dec") == 0)
4430 a->ttl.decrement = 1;
4431 else if (strcmp(tokens[1], "keep") == 0)
4432 a->ttl.decrement = 0;
4436 a->action_mask |= 1 << RTE_TABLE_ACTION_TTL;
4441 parse_table_action_stats(char **tokens,
4443 struct softnic_table_rule_action *a)
4446 strcmp(tokens[0], "stats"))
4449 a->stats.n_packets = 0;
4450 a->stats.n_bytes = 0;
4451 a->action_mask |= 1 << RTE_TABLE_ACTION_STATS;
4456 parse_table_action_time(char **tokens,
4458 struct softnic_table_rule_action *a)
4461 strcmp(tokens[0], "time"))
4464 a->time.time = rte_rdtsc();
4465 a->action_mask |= 1 << RTE_TABLE_ACTION_TIME;
4470 parse_free_sym_crypto_param_data(struct rte_table_action_sym_crypto_params *p)
4472 struct rte_crypto_sym_xform *xform[2] = {NULL};
4475 xform[0] = p->xform;
4477 xform[1] = xform[0]->next;
4479 for (i = 0; i < 2; i++) {
4480 if (xform[i] == NULL)
4483 switch (xform[i]->type) {
4484 case RTE_CRYPTO_SYM_XFORM_CIPHER:
4485 if (p->cipher_auth.cipher_iv.val)
4486 free(p->cipher_auth.cipher_iv.val);
4487 if (p->cipher_auth.cipher_iv_update.val)
4488 free(p->cipher_auth.cipher_iv_update.val);
4490 case RTE_CRYPTO_SYM_XFORM_AUTH:
4491 if (p->cipher_auth.auth_iv.val)
4492 free(p->cipher_auth.cipher_iv.val);
4493 if (p->cipher_auth.auth_iv_update.val)
4494 free(p->cipher_auth.cipher_iv_update.val);
4496 case RTE_CRYPTO_SYM_XFORM_AEAD:
4498 free(p->aead.iv.val);
4499 if (p->aead.aad.val)
4500 free(p->aead.aad.val);
4509 static struct rte_crypto_sym_xform *
4510 parse_table_action_cipher(struct rte_table_action_sym_crypto_params *p,
4511 uint8_t *key, uint32_t max_key_len, char **tokens,
4512 uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
4514 struct rte_crypto_sym_xform *xform_cipher;
4518 if (n_tokens < 7 || strcmp(tokens[1], "cipher_algo") ||
4519 strcmp(tokens[3], "cipher_key") ||
4520 strcmp(tokens[5], "cipher_iv"))
4523 xform_cipher = calloc(1, sizeof(*xform_cipher));
4524 if (xform_cipher == NULL)
4527 xform_cipher->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4528 xform_cipher->cipher.op = encrypt ? RTE_CRYPTO_CIPHER_OP_ENCRYPT :
4529 RTE_CRYPTO_CIPHER_OP_DECRYPT;
4532 status = rte_cryptodev_get_cipher_algo_enum(
4533 &xform_cipher->cipher.algo, tokens[2]);
4538 len = strlen(tokens[4]);
4539 if (len / 2 > max_key_len) {
4544 status = softnic_parse_hex_string(tokens[4], key, (uint32_t *)&len);
4548 xform_cipher->cipher.key.data = key;
4549 xform_cipher->cipher.key.length = (uint16_t)len;
4552 len = strlen(tokens[6]);
4554 p->cipher_auth.cipher_iv.val = calloc(1, len / 2 + 1);
4555 if (p->cipher_auth.cipher_iv.val == NULL)
4558 status = softnic_parse_hex_string(tokens[6],
4559 p->cipher_auth.cipher_iv.val,
4564 xform_cipher->cipher.iv.length = (uint16_t)len;
4565 xform_cipher->cipher.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
4566 p->cipher_auth.cipher_iv.length = (uint32_t)len;
4569 return xform_cipher;
4572 if (p->cipher_auth.cipher_iv.val) {
4573 free(p->cipher_auth.cipher_iv.val);
4574 p->cipher_auth.cipher_iv.val = NULL;
4582 static struct rte_crypto_sym_xform *
4583 parse_table_action_cipher_auth(struct rte_table_action_sym_crypto_params *p,
4584 uint8_t *key, uint32_t max_key_len, char **tokens,
4585 uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
4587 struct rte_crypto_sym_xform *xform_cipher;
4588 struct rte_crypto_sym_xform *xform_auth;
4592 if (n_tokens < 13 ||
4593 strcmp(tokens[7], "auth_algo") ||
4594 strcmp(tokens[9], "auth_key") ||
4595 strcmp(tokens[11], "digest_size"))
4598 xform_auth = calloc(1, sizeof(*xform_auth));
4599 if (xform_auth == NULL)
4602 xform_auth->type = RTE_CRYPTO_SYM_XFORM_AUTH;
4603 xform_auth->auth.op = encrypt ? RTE_CRYPTO_AUTH_OP_GENERATE :
4604 RTE_CRYPTO_AUTH_OP_VERIFY;
4607 status = rte_cryptodev_get_auth_algo_enum(&xform_auth->auth.algo,
4613 len = strlen(tokens[10]);
4614 if (len / 2 > max_key_len) {
4619 status = softnic_parse_hex_string(tokens[10], key, (uint32_t *)&len);
4623 xform_auth->auth.key.data = key;
4624 xform_auth->auth.key.length = (uint16_t)len;
4626 key += xform_auth->auth.key.length;
4627 max_key_len -= xform_auth->auth.key.length;
4629 if (strcmp(tokens[11], "digest_size"))
4632 status = softnic_parser_read_uint16(&xform_auth->auth.digest_length,
4637 xform_cipher = parse_table_action_cipher(p, key, max_key_len, tokens, 7,
4638 encrypt, used_n_tokens);
4639 if (xform_cipher == NULL)
4642 *used_n_tokens += 6;
4645 xform_cipher->next = xform_auth;
4646 return xform_cipher;
4648 xform_auth->next = xform_cipher;
4653 if (p->cipher_auth.auth_iv.val) {
4654 free(p->cipher_auth.auth_iv.val);
4655 p->cipher_auth.auth_iv.val = 0;
4663 static struct rte_crypto_sym_xform *
4664 parse_table_action_aead(struct rte_table_action_sym_crypto_params *p,
4665 uint8_t *key, uint32_t max_key_len, char **tokens,
4666 uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
4668 struct rte_crypto_sym_xform *xform_aead;
4672 if (n_tokens < 11 || strcmp(tokens[1], "aead_algo") ||
4673 strcmp(tokens[3], "aead_key") ||
4674 strcmp(tokens[5], "aead_iv") ||
4675 strcmp(tokens[7], "aead_aad") ||
4676 strcmp(tokens[9], "digest_size"))
4679 xform_aead = calloc(1, sizeof(*xform_aead));
4680 if (xform_aead == NULL)
4683 xform_aead->type = RTE_CRYPTO_SYM_XFORM_AEAD;
4684 xform_aead->aead.op = encrypt ? RTE_CRYPTO_AEAD_OP_ENCRYPT :
4685 RTE_CRYPTO_AEAD_OP_DECRYPT;
4688 status = rte_cryptodev_get_aead_algo_enum(&xform_aead->aead.algo,
4694 len = strlen(tokens[4]);
4695 if (len / 2 > max_key_len) {
4700 status = softnic_parse_hex_string(tokens[4], key, (uint32_t *)&len);
4704 xform_aead->aead.key.data = key;
4705 xform_aead->aead.key.length = (uint16_t)len;
4708 len = strlen(tokens[6]);
4709 p->aead.iv.val = calloc(1, len / 2 + 1);
4710 if (p->aead.iv.val == NULL)
4713 status = softnic_parse_hex_string(tokens[6], p->aead.iv.val,
4718 xform_aead->aead.iv.length = (uint16_t)len;
4719 xform_aead->aead.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
4720 p->aead.iv.length = (uint32_t)len;
4723 len = strlen(tokens[8]);
4724 p->aead.aad.val = calloc(1, len / 2 + 1);
4725 if (p->aead.aad.val == NULL)
4728 status = softnic_parse_hex_string(tokens[8], p->aead.aad.val, (uint32_t *)&len);
4732 xform_aead->aead.aad_length = (uint16_t)len;
4733 p->aead.aad.length = (uint32_t)len;
4736 status = softnic_parser_read_uint16(&xform_aead->aead.digest_length,
4741 *used_n_tokens = 11;
4746 if (p->aead.iv.val) {
4747 free(p->aead.iv.val);
4748 p->aead.iv.val = NULL;
4750 if (p->aead.aad.val) {
4751 free(p->aead.aad.val);
4752 p->aead.aad.val = NULL;
4762 parse_table_action_sym_crypto(char **tokens,
4764 struct softnic_table_rule_action *a)
4766 struct rte_table_action_sym_crypto_params *p = &a->sym_crypto;
4767 struct rte_crypto_sym_xform *xform = NULL;
4768 uint8_t *key = a->sym_crypto_key;
4769 uint32_t max_key_len = SYM_CRYPTO_MAX_KEY_SIZE;
4770 uint32_t used_n_tokens;
4774 if ((n_tokens < 12) ||
4775 strcmp(tokens[0], "sym_crypto") ||
4776 strcmp(tokens[2], "type"))
4779 memset(p, 0, sizeof(*p));
4781 if (strcmp(tokens[1], "encrypt") == 0)
4786 status = softnic_parser_read_uint32(&p->data_offset, tokens[n_tokens - 1]);
4790 if (strcmp(tokens[3], "cipher") == 0) {
4794 xform = parse_table_action_cipher(p, key, max_key_len, tokens,
4795 n_tokens, encrypt, &used_n_tokens);
4796 } else if (strcmp(tokens[3], "cipher_auth") == 0) {
4800 xform = parse_table_action_cipher_auth(p, key, max_key_len,
4801 tokens, n_tokens, encrypt, &used_n_tokens);
4802 } else if (strcmp(tokens[3], "aead") == 0) {
4806 xform = parse_table_action_aead(p, key, max_key_len, tokens,
4807 n_tokens, encrypt, &used_n_tokens);
4815 if (strcmp(tokens[used_n_tokens], "data_offset")) {
4816 parse_free_sym_crypto_param_data(p);
4820 a->action_mask |= 1 << RTE_TABLE_ACTION_SYM_CRYPTO;
4822 return used_n_tokens + 5;
4826 parse_table_action_tag(char **tokens,
4828 struct softnic_table_rule_action *a)
4831 strcmp(tokens[0], "tag"))
4834 if (softnic_parser_read_uint32(&a->tag.tag, tokens[1]))
4837 a->action_mask |= 1 << RTE_TABLE_ACTION_TAG;
4842 parse_table_action_decap(char **tokens,
4844 struct softnic_table_rule_action *a)
4847 strcmp(tokens[0], "decap"))
4850 if (softnic_parser_read_uint16(&a->decap.n, tokens[1]))
4853 a->action_mask |= 1 << RTE_TABLE_ACTION_DECAP;
4858 parse_table_action(char **tokens,
4862 struct softnic_table_rule_action *a)
4864 uint32_t n_tokens0 = n_tokens;
4866 memset(a, 0, sizeof(*a));
4869 strcmp(tokens[0], "action"))
4875 if (n_tokens && (strcmp(tokens[0], "fwd") == 0)) {
4878 n = parse_table_action_fwd(tokens, n_tokens, a);
4880 snprintf(out, out_size, MSG_ARG_INVALID,
4889 if (n_tokens && (strcmp(tokens[0], "balance") == 0)) {
4892 n = parse_table_action_balance(tokens, n_tokens, a);
4894 snprintf(out, out_size, MSG_ARG_INVALID,
4903 if (n_tokens && (strcmp(tokens[0], "meter") == 0)) {
4906 n = parse_table_action_meter(tokens, n_tokens, a);
4908 snprintf(out, out_size, MSG_ARG_INVALID,
4917 if (n_tokens && (strcmp(tokens[0], "tm") == 0)) {
4920 n = parse_table_action_tm(tokens, n_tokens, a);
4922 snprintf(out, out_size, MSG_ARG_INVALID,
4931 if (n_tokens && (strcmp(tokens[0], "encap") == 0)) {
4934 n = parse_table_action_encap(tokens, n_tokens, a);
4936 snprintf(out, out_size, MSG_ARG_INVALID,
4945 if (n_tokens && (strcmp(tokens[0], "nat") == 0)) {
4948 n = parse_table_action_nat(tokens, n_tokens, a);
4950 snprintf(out, out_size, MSG_ARG_INVALID,
4959 if (n_tokens && (strcmp(tokens[0], "ttl") == 0)) {
4962 n = parse_table_action_ttl(tokens, n_tokens, a);
4964 snprintf(out, out_size, MSG_ARG_INVALID,
4973 if (n_tokens && (strcmp(tokens[0], "stats") == 0)) {
4976 n = parse_table_action_stats(tokens, n_tokens, a);
4978 snprintf(out, out_size, MSG_ARG_INVALID,
4987 if (n_tokens && (strcmp(tokens[0], "time") == 0)) {
4990 n = parse_table_action_time(tokens, n_tokens, a);
4992 snprintf(out, out_size, MSG_ARG_INVALID,
5001 if (n_tokens && (strcmp(tokens[0], "tag") == 0)) {
5004 n = parse_table_action_tag(tokens, n_tokens, a);
5006 snprintf(out, out_size, MSG_ARG_INVALID,
5015 if (n_tokens && (strcmp(tokens[0], "decap") == 0)) {
5018 n = parse_table_action_decap(tokens, n_tokens, a);
5020 snprintf(out, out_size, MSG_ARG_INVALID,
5029 if (n_tokens && (strcmp(tokens[0], "sym_crypto") == 0)) {
5032 n = parse_table_action_sym_crypto(tokens, n_tokens, a);
5034 snprintf(out, out_size, MSG_ARG_INVALID,
5035 "action sym_crypto");
5042 if (n_tokens0 - n_tokens == 1) {
5043 snprintf(out, out_size, MSG_ARG_INVALID, "action");
5047 return n_tokens0 - n_tokens;
5051 * pipeline <pipeline_name> table <table_id> rule add
5053 * action <table_action>
5056 cmd_softnic_pipeline_table_rule_add(struct pmd_internals *softnic,
5062 struct softnic_table_rule_match m;
5063 struct softnic_table_rule_action a;
5064 char *pipeline_name;
5066 uint32_t table_id, t0, n_tokens_parsed;
5070 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5074 pipeline_name = tokens[1];
5076 if (strcmp(tokens[2], "table") != 0) {
5077 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5081 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
5082 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5086 if (strcmp(tokens[4], "rule") != 0) {
5087 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5091 if (strcmp(tokens[5], "add") != 0) {
5092 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
5099 n_tokens_parsed = parse_match(tokens + t0,
5104 if (n_tokens_parsed == 0)
5106 t0 += n_tokens_parsed;
5109 n_tokens_parsed = parse_table_action(tokens + t0,
5114 if (n_tokens_parsed == 0)
5116 t0 += n_tokens_parsed;
5118 if (t0 != n_tokens) {
5119 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5123 status = softnic_pipeline_table_rule_add(softnic,
5130 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5136 * pipeline <pipeline_name> table <table_id> rule add
5144 * | table <table_id>
5147 cmd_softnic_pipeline_table_rule_add_default(struct pmd_internals *softnic,
5153 struct softnic_table_rule_action action;
5155 char *pipeline_name;
5159 if (n_tokens != 11 &&
5161 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5165 pipeline_name = tokens[1];
5167 if (strcmp(tokens[2], "table") != 0) {
5168 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5172 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
5173 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5177 if (strcmp(tokens[4], "rule") != 0) {
5178 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5182 if (strcmp(tokens[5], "add") != 0) {
5183 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
5187 if (strcmp(tokens[6], "match") != 0) {
5188 snprintf(out, out_size, MSG_ARG_INVALID, "match");
5192 if (strcmp(tokens[7], "default") != 0) {
5193 snprintf(out, out_size, MSG_ARG_INVALID, "default");
5197 if (strcmp(tokens[8], "action") != 0) {
5198 snprintf(out, out_size, MSG_ARG_INVALID, "action");
5202 if (strcmp(tokens[9], "fwd") != 0) {
5203 snprintf(out, out_size, MSG_ARG_INVALID, "fwd");
5207 action.action_mask = 1 << RTE_TABLE_ACTION_FWD;
5209 if (strcmp(tokens[10], "drop") == 0) {
5210 if (n_tokens != 11) {
5211 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5215 action.fwd.action = RTE_PIPELINE_ACTION_DROP;
5216 } else if (strcmp(tokens[10], "port") == 0) {
5219 if (n_tokens != 12) {
5220 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5224 if (softnic_parser_read_uint32(&id, tokens[11]) != 0) {
5225 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
5229 action.fwd.action = RTE_PIPELINE_ACTION_PORT;
5231 } else if (strcmp(tokens[10], "meta") == 0) {
5232 if (n_tokens != 11) {
5233 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5237 action.fwd.action = RTE_PIPELINE_ACTION_PORT_META;
5238 } else if (strcmp(tokens[10], "table") == 0) {
5241 if (n_tokens != 12) {
5242 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5246 if (softnic_parser_read_uint32(&id, tokens[11]) != 0) {
5247 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5251 action.fwd.action = RTE_PIPELINE_ACTION_TABLE;
5254 snprintf(out, out_size, MSG_ARG_INVALID,
5255 "drop or port or meta or table");
5259 status = softnic_pipeline_table_rule_add_default(softnic,
5265 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5271 * pipeline <pipeline_name> table <table_id> rule add bulk <file_name> <n_rules>
5274 * - line format: match <match> action <action>
5277 cli_rule_file_process(const char *file_name,
5278 size_t line_len_max,
5279 struct softnic_table_rule_match *m,
5280 struct softnic_table_rule_action *a,
5282 uint32_t *line_number,
5287 cmd_softnic_pipeline_table_rule_add_bulk(struct pmd_internals *softnic,
5293 struct softnic_table_rule_match *match;
5294 struct softnic_table_rule_action *action;
5296 char *pipeline_name, *file_name;
5297 uint32_t table_id, n_rules, n_rules_parsed, line_number;
5300 if (n_tokens != 9) {
5301 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5305 pipeline_name = tokens[1];
5307 if (strcmp(tokens[2], "table") != 0) {
5308 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5312 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
5313 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5317 if (strcmp(tokens[4], "rule") != 0) {
5318 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5322 if (strcmp(tokens[5], "add") != 0) {
5323 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
5327 if (strcmp(tokens[6], "bulk") != 0) {
5328 snprintf(out, out_size, MSG_ARG_INVALID, "bulk");
5332 file_name = tokens[7];
5334 if ((softnic_parser_read_uint32(&n_rules, tokens[8]) != 0) ||
5336 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
5340 /* Memory allocation. */
5341 match = calloc(n_rules, sizeof(struct softnic_table_rule_match));
5342 action = calloc(n_rules, sizeof(struct softnic_table_rule_action));
5343 data = calloc(n_rules, sizeof(void *));
5344 if (match == NULL ||
5347 snprintf(out, out_size, MSG_OUT_OF_MEMORY);
5354 /* Load rule file */
5355 n_rules_parsed = n_rules;
5356 status = cli_rule_file_process(file_name,
5365 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
5371 if (n_rules_parsed != n_rules) {
5372 snprintf(out, out_size, MSG_FILE_NOT_ENOUGH, file_name);
5380 status = softnic_pipeline_table_rule_add_bulk(softnic,
5388 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5402 * pipeline <pipeline_name> table <table_id> rule delete
5406 cmd_softnic_pipeline_table_rule_delete(struct pmd_internals *softnic,
5412 struct softnic_table_rule_match m;
5413 char *pipeline_name;
5414 uint32_t table_id, n_tokens_parsed, t0;
5418 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5422 pipeline_name = tokens[1];
5424 if (strcmp(tokens[2], "table") != 0) {
5425 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5429 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
5430 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5434 if (strcmp(tokens[4], "rule") != 0) {
5435 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5439 if (strcmp(tokens[5], "delete") != 0) {
5440 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
5447 n_tokens_parsed = parse_match(tokens + t0,
5452 if (n_tokens_parsed == 0)
5454 t0 += n_tokens_parsed;
5456 if (n_tokens != t0) {
5457 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5461 status = softnic_pipeline_table_rule_delete(softnic,
5466 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5472 * pipeline <pipeline_name> table <table_id> rule delete
5477 cmd_softnic_pipeline_table_rule_delete_default(struct pmd_internals *softnic,
5483 char *pipeline_name;
5487 if (n_tokens != 8) {
5488 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5492 pipeline_name = tokens[1];
5494 if (strcmp(tokens[2], "table") != 0) {
5495 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5499 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
5500 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5504 if (strcmp(tokens[4], "rule") != 0) {
5505 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5509 if (strcmp(tokens[5], "delete") != 0) {
5510 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
5514 if (strcmp(tokens[6], "match") != 0) {
5515 snprintf(out, out_size, MSG_ARG_INVALID, "match");
5519 if (strcmp(tokens[7], "default") != 0) {
5520 snprintf(out, out_size, MSG_ARG_INVALID, "default");
5524 status = softnic_pipeline_table_rule_delete_default(softnic,
5528 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5534 * pipeline <pipeline_name> table <table_id> rule read stats [clear]
5537 cmd_softnic_pipeline_table_rule_stats_read(struct pmd_internals *softnic __rte_unused,
5539 uint32_t n_tokens __rte_unused,
5543 snprintf(out, out_size, MSG_CMD_UNIMPLEM, tokens[0]);
5547 * pipeline <pipeline_name> table <table_id> meter profile <meter_profile_id>
5548 * add srtcm cir <cir> cbs <cbs> ebs <ebs>
5549 * | trtcm cir <cir> pir <pir> cbs <cbs> pbs <pbs>
5552 cmd_pipeline_table_meter_profile_add(struct pmd_internals *softnic,
5558 struct rte_table_action_meter_profile p;
5559 char *pipeline_name;
5560 uint32_t table_id, meter_profile_id;
5564 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5568 pipeline_name = tokens[1];
5570 if (strcmp(tokens[2], "table") != 0) {
5571 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5575 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
5576 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5580 if (strcmp(tokens[4], "meter") != 0) {
5581 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5585 if (strcmp(tokens[5], "profile") != 0) {
5586 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
5590 if (softnic_parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
5591 snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
5595 if (strcmp(tokens[7], "add") != 0) {
5596 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
5600 if (strcmp(tokens[8], "srtcm") == 0) {
5601 if (n_tokens != 15) {
5602 snprintf(out, out_size, MSG_ARG_MISMATCH,
5607 p.alg = RTE_TABLE_ACTION_METER_SRTCM;
5609 if (strcmp(tokens[9], "cir") != 0) {
5610 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
5614 if (softnic_parser_read_uint64(&p.srtcm.cir, tokens[10]) != 0) {
5615 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
5619 if (strcmp(tokens[11], "cbs") != 0) {
5620 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
5624 if (softnic_parser_read_uint64(&p.srtcm.cbs, tokens[12]) != 0) {
5625 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
5629 if (strcmp(tokens[13], "ebs") != 0) {
5630 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ebs");
5634 if (softnic_parser_read_uint64(&p.srtcm.ebs, tokens[14]) != 0) {
5635 snprintf(out, out_size, MSG_ARG_INVALID, "ebs");
5638 } else if (strcmp(tokens[8], "trtcm") == 0) {
5639 if (n_tokens != 17) {
5640 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5644 p.alg = RTE_TABLE_ACTION_METER_TRTCM;
5646 if (strcmp(tokens[9], "cir") != 0) {
5647 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
5651 if (softnic_parser_read_uint64(&p.trtcm.cir, tokens[10]) != 0) {
5652 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
5656 if (strcmp(tokens[11], "pir") != 0) {
5657 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir");
5661 if (softnic_parser_read_uint64(&p.trtcm.pir, tokens[12]) != 0) {
5662 snprintf(out, out_size, MSG_ARG_INVALID, "pir");
5665 if (strcmp(tokens[13], "cbs") != 0) {
5666 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
5670 if (softnic_parser_read_uint64(&p.trtcm.cbs, tokens[14]) != 0) {
5671 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
5675 if (strcmp(tokens[15], "pbs") != 0) {
5676 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs");
5680 if (softnic_parser_read_uint64(&p.trtcm.pbs, tokens[16]) != 0) {
5681 snprintf(out, out_size, MSG_ARG_INVALID, "pbs");
5685 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5689 status = softnic_pipeline_table_mtr_profile_add(softnic,
5695 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5701 * pipeline <pipeline_name> table <table_id>
5702 * meter profile <meter_profile_id> delete
5705 cmd_pipeline_table_meter_profile_delete(struct pmd_internals *softnic,
5711 char *pipeline_name;
5712 uint32_t table_id, meter_profile_id;
5715 if (n_tokens != 8) {
5716 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5720 pipeline_name = tokens[1];
5722 if (strcmp(tokens[2], "table") != 0) {
5723 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5727 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
5728 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5732 if (strcmp(tokens[4], "meter") != 0) {
5733 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5737 if (strcmp(tokens[5], "profile") != 0) {
5738 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
5742 if (softnic_parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
5743 snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
5747 if (strcmp(tokens[7], "delete") != 0) {
5748 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
5752 status = softnic_pipeline_table_mtr_profile_delete(softnic,
5757 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5763 * pipeline <pipeline_name> table <table_id> rule read meter [clear]
5766 cmd_pipeline_table_rule_meter_read(struct pmd_internals *softnic __rte_unused,
5768 uint32_t n_tokens __rte_unused,
5772 snprintf(out, out_size, MSG_CMD_UNIMPLEM, tokens[0]);
5776 * pipeline <pipeline_name> table <table_id> dscp <file_name>
5779 * - exactly 64 lines
5780 * - line format: <tc_id> <tc_queue_id> <color>, with <color> as: g | y | r
5783 load_dscp_table(struct rte_table_action_dscp_table *dscp_table,
5784 const char *file_name,
5785 uint32_t *line_number)
5790 /* Check input arguments */
5791 if (dscp_table == NULL ||
5792 file_name == NULL ||
5793 line_number == NULL) {
5799 /* Open input file */
5800 f = fopen(file_name, "r");
5807 for (dscp = 0, l = 1; ; l++) {
5810 enum rte_color color;
5811 uint32_t tc_id, tc_queue_id, n_tokens = RTE_DIM(tokens);
5813 if (fgets(line, sizeof(line), f) == NULL)
5816 if (is_comment(line))
5819 if (softnic_parse_tokenize_string(line, tokens, &n_tokens)) {
5828 if (dscp >= RTE_DIM(dscp_table->entry) ||
5829 n_tokens != RTE_DIM(tokens) ||
5830 softnic_parser_read_uint32(&tc_id, tokens[0]) ||
5831 tc_id >= RTE_TABLE_ACTION_TC_MAX ||
5832 softnic_parser_read_uint32(&tc_queue_id, tokens[1]) ||
5833 tc_queue_id >= RTE_TABLE_ACTION_TC_QUEUE_MAX ||
5834 (strlen(tokens[2]) != 1)) {
5840 switch (tokens[2][0]) {
5843 color = RTE_COLOR_GREEN;
5848 color = RTE_COLOR_YELLOW;
5853 color = RTE_COLOR_RED;
5862 dscp_table->entry[dscp].tc_id = tc_id;
5863 dscp_table->entry[dscp].tc_queue_id = tc_queue_id;
5864 dscp_table->entry[dscp].color = color;
5874 cmd_pipeline_table_dscp(struct pmd_internals *softnic,
5880 struct rte_table_action_dscp_table dscp_table;
5881 char *pipeline_name, *file_name;
5882 uint32_t table_id, line_number;
5885 if (n_tokens != 6) {
5886 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5890 pipeline_name = tokens[1];
5892 if (strcmp(tokens[2], "table") != 0) {
5893 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5897 if (softnic_parser_read_uint32(&table_id, tokens[3]) != 0) {
5898 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5902 if (strcmp(tokens[4], "dscp") != 0) {
5903 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dscp");
5907 file_name = tokens[5];
5909 status = load_dscp_table(&dscp_table, file_name, &line_number);
5911 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
5915 status = softnic_pipeline_table_dscp_table_update(softnic,
5921 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5927 * pipeline <pipeline_name> table <table_id> rule read ttl [clear]
5930 cmd_softnic_pipeline_table_rule_ttl_read(struct pmd_internals *softnic __rte_unused,
5932 uint32_t n_tokens __rte_unused,
5936 snprintf(out, out_size, MSG_CMD_UNIMPLEM, tokens[0]);
5940 * thread <thread_id> pipeline <pipeline_name> enable
5943 cmd_softnic_thread_pipeline_enable(struct pmd_internals *softnic,
5949 char *pipeline_name;
5953 if (n_tokens != 5) {
5954 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5958 if (softnic_parser_read_uint32(&thread_id, tokens[1]) != 0) {
5959 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
5963 if (strcmp(tokens[2], "pipeline") != 0) {
5964 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
5968 pipeline_name = tokens[3];
5970 if (strcmp(tokens[4], "enable") != 0) {
5971 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
5975 status = softnic_thread_pipeline_enable(softnic, thread_id, pipeline_name);
5977 snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable");
5983 * thread <thread_id> pipeline <pipeline_name> disable
5986 cmd_softnic_thread_pipeline_disable(struct pmd_internals *softnic,
5992 char *pipeline_name;
5996 if (n_tokens != 5) {
5997 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
6001 if (softnic_parser_read_uint32(&thread_id, tokens[1]) != 0) {
6002 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
6006 if (strcmp(tokens[2], "pipeline") != 0) {
6007 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
6011 pipeline_name = tokens[3];
6013 if (strcmp(tokens[4], "disable") != 0) {
6014 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
6018 status = softnic_thread_pipeline_disable(softnic, thread_id, pipeline_name);
6020 snprintf(out, out_size, MSG_CMD_FAIL,
6021 "thread pipeline disable");
6030 * pipeline <pipeline_name>
6034 cmd_softnic_flowapi_map(struct pmd_internals *softnic,
6040 char *pipeline_name;
6041 uint32_t group_id, table_id;
6042 int ingress, status;
6044 if (n_tokens != 9) {
6045 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
6049 if (strcmp(tokens[1], "map") != 0) {
6050 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "map");
6054 if (strcmp(tokens[2], "group") != 0) {
6055 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group");
6059 if (softnic_parser_read_uint32(&group_id, tokens[3]) != 0) {
6060 snprintf(out, out_size, MSG_ARG_INVALID, "group_id");
6064 if (strcmp(tokens[4], "ingress") == 0) {
6066 } else if (strcmp(tokens[4], "egress") == 0) {
6069 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ingress | egress");
6073 if (strcmp(tokens[5], "pipeline") != 0) {
6074 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
6078 pipeline_name = tokens[6];
6080 if (strcmp(tokens[7], "table") != 0) {
6081 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
6085 if (softnic_parser_read_uint32(&table_id, tokens[8]) != 0) {
6086 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
6090 status = flow_attr_map_set(softnic,
6096 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
6102 softnic_cli_process(char *in, char *out, size_t out_size, void *arg)
6104 char *tokens[CMD_MAX_TOKENS];
6105 uint32_t n_tokens = RTE_DIM(tokens);
6106 struct pmd_internals *softnic = arg;
6112 status = softnic_parse_tokenize_string(in, tokens, &n_tokens);
6114 snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
6121 if (strcmp(tokens[0], "mempool") == 0) {
6122 cmd_mempool(softnic, tokens, n_tokens, out, out_size);
6126 if (strcmp(tokens[0], "link") == 0) {
6127 cmd_link(softnic, tokens, n_tokens, out, out_size);
6131 if (strcmp(tokens[0], "swq") == 0) {
6132 cmd_swq(softnic, tokens, n_tokens, out, out_size);
6136 if (strcmp(tokens[0], "tmgr") == 0) {
6137 if (n_tokens == 2) {
6138 cmd_tmgr(softnic, tokens, n_tokens, out, out_size);
6142 if (n_tokens >= 3 &&
6143 (strcmp(tokens[1], "shaper") == 0) &&
6144 (strcmp(tokens[2], "profile") == 0)) {
6145 cmd_tmgr_shaper_profile(softnic, tokens, n_tokens, out, out_size);
6149 if (n_tokens >= 3 &&
6150 (strcmp(tokens[1], "shared") == 0) &&
6151 (strcmp(tokens[2], "shaper") == 0)) {
6152 cmd_tmgr_shared_shaper(softnic, tokens, n_tokens, out, out_size);
6156 if (n_tokens >= 2 &&
6157 (strcmp(tokens[1], "node") == 0)) {
6158 cmd_tmgr_node(softnic, tokens, n_tokens, out, out_size);
6162 if (n_tokens >= 2 &&
6163 (strcmp(tokens[1], "hierarchy-default") == 0)) {
6164 cmd_tmgr_hierarchy_default(softnic, tokens, n_tokens, out, out_size);
6168 if (n_tokens >= 3 &&
6169 (strcmp(tokens[1], "hierarchy") == 0) &&
6170 (strcmp(tokens[2], "commit") == 0)) {
6171 cmd_tmgr_hierarchy_commit(softnic, tokens, n_tokens, out, out_size);
6176 if (strcmp(tokens[0], "tap") == 0) {
6177 cmd_tap(softnic, tokens, n_tokens, out, out_size);
6181 if (strcmp(tokens[0], "cryptodev") == 0) {
6182 cmd_cryptodev(softnic, tokens, n_tokens, out, out_size);
6186 if (strcmp(tokens[0], "port") == 0) {
6187 cmd_port_in_action_profile(softnic, tokens, n_tokens, out, out_size);
6191 if (strcmp(tokens[0], "table") == 0) {
6192 cmd_table_action_profile(softnic, tokens, n_tokens, out, out_size);
6196 if (strcmp(tokens[0], "pipeline") == 0) {
6197 if (n_tokens >= 3 &&
6198 (strcmp(tokens[2], "period") == 0)) {
6199 cmd_pipeline(softnic, tokens, n_tokens, out, out_size);
6203 if (n_tokens >= 5 &&
6204 (strcmp(tokens[2], "port") == 0) &&
6205 (strcmp(tokens[3], "in") == 0) &&
6206 (strcmp(tokens[4], "bsz") == 0)) {
6207 cmd_pipeline_port_in(softnic, tokens, n_tokens, out, out_size);
6211 if (n_tokens >= 5 &&
6212 (strcmp(tokens[2], "port") == 0) &&
6213 (strcmp(tokens[3], "out") == 0) &&
6214 (strcmp(tokens[4], "bsz") == 0)) {
6215 cmd_pipeline_port_out(softnic, tokens, n_tokens, out, out_size);
6219 if (n_tokens >= 4 &&
6220 (strcmp(tokens[2], "table") == 0) &&
6221 (strcmp(tokens[3], "match") == 0)) {
6222 cmd_pipeline_table(softnic, tokens, n_tokens, out, out_size);
6226 if (n_tokens >= 6 &&
6227 (strcmp(tokens[2], "port") == 0) &&
6228 (strcmp(tokens[3], "in") == 0) &&
6229 (strcmp(tokens[5], "table") == 0)) {
6230 cmd_pipeline_port_in_table(softnic, tokens, n_tokens,
6235 if (n_tokens >= 6 &&
6236 (strcmp(tokens[2], "port") == 0) &&
6237 (strcmp(tokens[3], "in") == 0) &&
6238 (strcmp(tokens[5], "stats") == 0)) {
6239 cmd_pipeline_port_in_stats(softnic, tokens, n_tokens,
6244 if (n_tokens >= 6 &&
6245 (strcmp(tokens[2], "port") == 0) &&
6246 (strcmp(tokens[3], "in") == 0) &&
6247 (strcmp(tokens[5], "enable") == 0)) {
6248 cmd_softnic_pipeline_port_in_enable(softnic, tokens, n_tokens,
6253 if (n_tokens >= 6 &&
6254 (strcmp(tokens[2], "port") == 0) &&
6255 (strcmp(tokens[3], "in") == 0) &&
6256 (strcmp(tokens[5], "disable") == 0)) {
6257 cmd_softnic_pipeline_port_in_disable(softnic, tokens, n_tokens,
6262 if (n_tokens >= 6 &&
6263 (strcmp(tokens[2], "port") == 0) &&
6264 (strcmp(tokens[3], "out") == 0) &&
6265 (strcmp(tokens[5], "stats") == 0)) {
6266 cmd_pipeline_port_out_stats(softnic, tokens, n_tokens,
6271 if (n_tokens >= 5 &&
6272 (strcmp(tokens[2], "table") == 0) &&
6273 (strcmp(tokens[4], "stats") == 0)) {
6274 cmd_pipeline_table_stats(softnic, tokens, n_tokens,
6279 if (n_tokens >= 7 &&
6280 (strcmp(tokens[2], "table") == 0) &&
6281 (strcmp(tokens[4], "rule") == 0) &&
6282 (strcmp(tokens[5], "add") == 0) &&
6283 (strcmp(tokens[6], "match") == 0)) {
6284 if (n_tokens >= 8 &&
6285 (strcmp(tokens[7], "default") == 0)) {
6286 cmd_softnic_pipeline_table_rule_add_default(softnic, tokens,
6287 n_tokens, out, out_size);
6291 cmd_softnic_pipeline_table_rule_add(softnic, tokens, n_tokens,
6296 if (n_tokens >= 7 &&
6297 (strcmp(tokens[2], "table") == 0) &&
6298 (strcmp(tokens[4], "rule") == 0) &&
6299 (strcmp(tokens[5], "add") == 0) &&
6300 (strcmp(tokens[6], "bulk") == 0)) {
6301 cmd_softnic_pipeline_table_rule_add_bulk(softnic, tokens,
6302 n_tokens, out, out_size);
6306 if (n_tokens >= 7 &&
6307 (strcmp(tokens[2], "table") == 0) &&
6308 (strcmp(tokens[4], "rule") == 0) &&
6309 (strcmp(tokens[5], "delete") == 0) &&
6310 (strcmp(tokens[6], "match") == 0)) {
6311 if (n_tokens >= 8 &&
6312 (strcmp(tokens[7], "default") == 0)) {
6313 cmd_softnic_pipeline_table_rule_delete_default(softnic, tokens,
6314 n_tokens, out, out_size);
6318 cmd_softnic_pipeline_table_rule_delete(softnic, tokens, n_tokens,
6323 if (n_tokens >= 7 &&
6324 (strcmp(tokens[2], "table") == 0) &&
6325 (strcmp(tokens[4], "rule") == 0) &&
6326 (strcmp(tokens[5], "read") == 0) &&
6327 (strcmp(tokens[6], "stats") == 0)) {
6328 cmd_softnic_pipeline_table_rule_stats_read(softnic, tokens, n_tokens,
6333 if (n_tokens >= 8 &&
6334 (strcmp(tokens[2], "table") == 0) &&
6335 (strcmp(tokens[4], "meter") == 0) &&
6336 (strcmp(tokens[5], "profile") == 0) &&
6337 (strcmp(tokens[7], "add") == 0)) {
6338 cmd_pipeline_table_meter_profile_add(softnic, tokens, n_tokens,
6343 if (n_tokens >= 8 &&
6344 (strcmp(tokens[2], "table") == 0) &&
6345 (strcmp(tokens[4], "meter") == 0) &&
6346 (strcmp(tokens[5], "profile") == 0) &&
6347 (strcmp(tokens[7], "delete") == 0)) {
6348 cmd_pipeline_table_meter_profile_delete(softnic, tokens,
6349 n_tokens, out, out_size);
6353 if (n_tokens >= 7 &&
6354 (strcmp(tokens[2], "table") == 0) &&
6355 (strcmp(tokens[4], "rule") == 0) &&
6356 (strcmp(tokens[5], "read") == 0) &&
6357 (strcmp(tokens[6], "meter") == 0)) {
6358 cmd_pipeline_table_rule_meter_read(softnic, tokens, n_tokens,
6363 if (n_tokens >= 5 &&
6364 (strcmp(tokens[2], "table") == 0) &&
6365 (strcmp(tokens[4], "dscp") == 0)) {
6366 cmd_pipeline_table_dscp(softnic, tokens, n_tokens,
6371 if (n_tokens >= 7 &&
6372 (strcmp(tokens[2], "table") == 0) &&
6373 (strcmp(tokens[4], "rule") == 0) &&
6374 (strcmp(tokens[5], "read") == 0) &&
6375 (strcmp(tokens[6], "ttl") == 0)) {
6376 cmd_softnic_pipeline_table_rule_ttl_read(softnic, tokens, n_tokens,
6382 if (strcmp(tokens[0], "thread") == 0) {
6383 if (n_tokens >= 5 &&
6384 (strcmp(tokens[4], "enable") == 0)) {
6385 cmd_softnic_thread_pipeline_enable(softnic, tokens, n_tokens,
6390 if (n_tokens >= 5 &&
6391 (strcmp(tokens[4], "disable") == 0)) {
6392 cmd_softnic_thread_pipeline_disable(softnic, tokens, n_tokens,
6398 if (strcmp(tokens[0], "flowapi") == 0) {
6399 cmd_softnic_flowapi_map(softnic, tokens, n_tokens, out,
6404 snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
6408 softnic_cli_script_process(struct pmd_internals *softnic,
6409 const char *file_name,
6410 size_t msg_in_len_max,
6411 size_t msg_out_len_max)
6413 char *msg_in = NULL, *msg_out = NULL;
6416 /* Check input arguments */
6417 if (file_name == NULL ||
6418 (strlen(file_name) == 0) ||
6419 msg_in_len_max == 0 ||
6420 msg_out_len_max == 0)
6423 msg_in = malloc(msg_in_len_max + 1);
6424 msg_out = malloc(msg_out_len_max + 1);
6425 if (msg_in == NULL ||
6432 /* Open input file */
6433 f = fopen(file_name, "r");
6442 if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
6445 printf("%s", msg_in);
6448 softnic_cli_process(msg_in,
6453 if (strlen(msg_out))
6454 printf("%s", msg_out);
6465 cli_rule_file_process(const char *file_name,
6466 size_t line_len_max,
6467 struct softnic_table_rule_match *m,
6468 struct softnic_table_rule_action *a,
6470 uint32_t *line_number,
6476 uint32_t rule_id, line_id;
6479 /* Check input arguments */
6480 if (file_name == NULL ||
6481 (strlen(file_name) == 0) ||
6482 line_len_max == 0) {
6487 /* Memory allocation */
6488 line = malloc(line_len_max + 1);
6495 f = fopen(file_name, "r");
6503 for (line_id = 1, rule_id = 0; rule_id < *n_rules; line_id++) {
6504 char *tokens[CMD_MAX_TOKENS];
6505 uint32_t n_tokens, n_tokens_parsed, t0;
6507 /* Read next line from file. */
6508 if (fgets(line, line_len_max + 1, f) == NULL)
6512 if (is_comment(line))
6516 n_tokens = RTE_DIM(tokens);
6517 status = softnic_parse_tokenize_string(line, tokens, &n_tokens);
6529 n_tokens_parsed = parse_match(tokens + t0,
6534 if (n_tokens_parsed == 0) {
6538 t0 += n_tokens_parsed;
6541 n_tokens_parsed = parse_table_action(tokens + t0,
6546 if (n_tokens_parsed == 0) {
6550 t0 += n_tokens_parsed;
6552 /* Line completed. */
6553 if (t0 < n_tokens) {
6558 /* Increment rule count */
6569 *line_number = line_id;