15074e1d5SCristian Dumitrescu /* SPDX-License-Identifier: BSD-3-Clause
25074e1d5SCristian Dumitrescu * Copyright(c) 2020 Intel Corporation
35074e1d5SCristian Dumitrescu */
45074e1d5SCristian Dumitrescu
55074e1d5SCristian Dumitrescu #include <stdio.h>
65074e1d5SCristian Dumitrescu #include <stdint.h>
75074e1d5SCristian Dumitrescu #include <stdlib.h>
85074e1d5SCristian Dumitrescu #include <string.h>
95074e1d5SCristian Dumitrescu
105074e1d5SCristian Dumitrescu #include <rte_common.h>
115074e1d5SCristian Dumitrescu #include <rte_ethdev.h>
125074e1d5SCristian Dumitrescu #include <rte_swx_port_ethdev.h>
1377a41301SCristian Dumitrescu #include <rte_swx_port_ring.h>
145074e1d5SCristian Dumitrescu #include <rte_swx_port_source_sink.h>
15e2b8dc52SVenkata Suresh Kumar P #include <rte_swx_port_fd.h>
165074e1d5SCristian Dumitrescu #include <rte_swx_pipeline.h>
175074e1d5SCristian Dumitrescu #include <rte_swx_ctl.h>
185074e1d5SCristian Dumitrescu
195074e1d5SCristian Dumitrescu #include "cli.h"
205074e1d5SCristian Dumitrescu
215074e1d5SCristian Dumitrescu #include "obj.h"
225074e1d5SCristian Dumitrescu #include "thread.h"
235074e1d5SCristian Dumitrescu
245074e1d5SCristian Dumitrescu #ifndef CMD_MAX_TOKENS
255074e1d5SCristian Dumitrescu #define CMD_MAX_TOKENS 256
265074e1d5SCristian Dumitrescu #endif
275074e1d5SCristian Dumitrescu
285074e1d5SCristian Dumitrescu #define MSG_OUT_OF_MEMORY "Not enough memory.\n"
295074e1d5SCristian Dumitrescu #define MSG_CMD_UNKNOWN "Unknown command \"%s\".\n"
305074e1d5SCristian Dumitrescu #define MSG_CMD_UNIMPLEM "Command \"%s\" not implemented.\n"
315074e1d5SCristian Dumitrescu #define MSG_ARG_NOT_ENOUGH "Not enough arguments for command \"%s\".\n"
325074e1d5SCristian Dumitrescu #define MSG_ARG_TOO_MANY "Too many arguments for command \"%s\".\n"
335074e1d5SCristian Dumitrescu #define MSG_ARG_MISMATCH "Wrong number of arguments for command \"%s\".\n"
345074e1d5SCristian Dumitrescu #define MSG_ARG_NOT_FOUND "Argument \"%s\" not found.\n"
355074e1d5SCristian Dumitrescu #define MSG_ARG_INVALID "Invalid value for argument \"%s\".\n"
365074e1d5SCristian Dumitrescu #define MSG_FILE_ERR "Error in file \"%s\" at line %u.\n"
375074e1d5SCristian Dumitrescu #define MSG_FILE_NOT_ENOUGH "Not enough rules in file \"%s\".\n"
385074e1d5SCristian Dumitrescu #define MSG_CMD_FAIL "Command \"%s\" failed.\n"
395074e1d5SCristian Dumitrescu
405074e1d5SCristian Dumitrescu #define skip_white_spaces(pos) \
415074e1d5SCristian Dumitrescu ({ \
425074e1d5SCristian Dumitrescu __typeof__(pos) _p = (pos); \
435074e1d5SCristian Dumitrescu for ( ; isspace(*_p); _p++) \
445074e1d5SCristian Dumitrescu ; \
455074e1d5SCristian Dumitrescu _p; \
465074e1d5SCristian Dumitrescu })
475074e1d5SCristian Dumitrescu
485074e1d5SCristian Dumitrescu static int
parser_read_uint64(uint64_t * value,const char * p)495074e1d5SCristian Dumitrescu parser_read_uint64(uint64_t *value, const char *p)
505074e1d5SCristian Dumitrescu {
515074e1d5SCristian Dumitrescu char *next;
525074e1d5SCristian Dumitrescu uint64_t val;
535074e1d5SCristian Dumitrescu
545074e1d5SCristian Dumitrescu p = skip_white_spaces(p);
555074e1d5SCristian Dumitrescu if (!isdigit(*p))
565074e1d5SCristian Dumitrescu return -EINVAL;
575074e1d5SCristian Dumitrescu
580d644eb6SChurchill Khangar val = strtoul(p, &next, 0);
595074e1d5SCristian Dumitrescu if (p == next)
605074e1d5SCristian Dumitrescu return -EINVAL;
615074e1d5SCristian Dumitrescu
625074e1d5SCristian Dumitrescu p = next;
635074e1d5SCristian Dumitrescu switch (*p) {
645074e1d5SCristian Dumitrescu case 'T':
655074e1d5SCristian Dumitrescu val *= 1024ULL;
665074e1d5SCristian Dumitrescu /* fall through */
675074e1d5SCristian Dumitrescu case 'G':
685074e1d5SCristian Dumitrescu val *= 1024ULL;
695074e1d5SCristian Dumitrescu /* fall through */
705074e1d5SCristian Dumitrescu case 'M':
715074e1d5SCristian Dumitrescu val *= 1024ULL;
725074e1d5SCristian Dumitrescu /* fall through */
735074e1d5SCristian Dumitrescu case 'k':
745074e1d5SCristian Dumitrescu case 'K':
755074e1d5SCristian Dumitrescu val *= 1024ULL;
765074e1d5SCristian Dumitrescu p++;
775074e1d5SCristian Dumitrescu break;
785074e1d5SCristian Dumitrescu }
795074e1d5SCristian Dumitrescu
805074e1d5SCristian Dumitrescu p = skip_white_spaces(p);
815074e1d5SCristian Dumitrescu if (*p != '\0')
825074e1d5SCristian Dumitrescu return -EINVAL;
835074e1d5SCristian Dumitrescu
845074e1d5SCristian Dumitrescu *value = val;
855074e1d5SCristian Dumitrescu return 0;
865074e1d5SCristian Dumitrescu }
875074e1d5SCristian Dumitrescu
885074e1d5SCristian Dumitrescu static int
parser_read_uint32(uint32_t * value,const char * p)895074e1d5SCristian Dumitrescu parser_read_uint32(uint32_t *value, const char *p)
905074e1d5SCristian Dumitrescu {
915074e1d5SCristian Dumitrescu uint64_t val = 0;
925074e1d5SCristian Dumitrescu int ret = parser_read_uint64(&val, p);
935074e1d5SCristian Dumitrescu
945074e1d5SCristian Dumitrescu if (ret < 0)
955074e1d5SCristian Dumitrescu return ret;
965074e1d5SCristian Dumitrescu
975074e1d5SCristian Dumitrescu if (val > UINT32_MAX)
985074e1d5SCristian Dumitrescu return -ERANGE;
995074e1d5SCristian Dumitrescu
1005074e1d5SCristian Dumitrescu *value = val;
1015074e1d5SCristian Dumitrescu return 0;
1025074e1d5SCristian Dumitrescu }
1035074e1d5SCristian Dumitrescu
1045074e1d5SCristian Dumitrescu static int
parser_read_uint16(uint16_t * value,const char * p)1055074e1d5SCristian Dumitrescu parser_read_uint16(uint16_t *value, const char *p)
1065074e1d5SCristian Dumitrescu {
1075074e1d5SCristian Dumitrescu uint64_t val = 0;
1085074e1d5SCristian Dumitrescu int ret = parser_read_uint64(&val, p);
1095074e1d5SCristian Dumitrescu
1105074e1d5SCristian Dumitrescu if (ret < 0)
1115074e1d5SCristian Dumitrescu return ret;
1125074e1d5SCristian Dumitrescu
1135074e1d5SCristian Dumitrescu if (val > UINT16_MAX)
1145074e1d5SCristian Dumitrescu return -ERANGE;
1155074e1d5SCristian Dumitrescu
1165074e1d5SCristian Dumitrescu *value = val;
1175074e1d5SCristian Dumitrescu return 0;
1185074e1d5SCristian Dumitrescu }
1195074e1d5SCristian Dumitrescu
1205074e1d5SCristian Dumitrescu #define PARSE_DELIMITER " \f\n\r\t\v"
1215074e1d5SCristian Dumitrescu
1225074e1d5SCristian Dumitrescu static int
parse_tokenize_string(char * string,char * tokens[],uint32_t * n_tokens)1235074e1d5SCristian Dumitrescu parse_tokenize_string(char *string, char *tokens[], uint32_t *n_tokens)
1245074e1d5SCristian Dumitrescu {
1255074e1d5SCristian Dumitrescu uint32_t i;
1265074e1d5SCristian Dumitrescu
1275074e1d5SCristian Dumitrescu if ((string == NULL) ||
1285074e1d5SCristian Dumitrescu (tokens == NULL) ||
1295074e1d5SCristian Dumitrescu (*n_tokens < 1))
1305074e1d5SCristian Dumitrescu return -EINVAL;
1315074e1d5SCristian Dumitrescu
1325074e1d5SCristian Dumitrescu for (i = 0; i < *n_tokens; i++) {
1335074e1d5SCristian Dumitrescu tokens[i] = strtok_r(string, PARSE_DELIMITER, &string);
1345074e1d5SCristian Dumitrescu if (tokens[i] == NULL)
1355074e1d5SCristian Dumitrescu break;
1365074e1d5SCristian Dumitrescu }
1375074e1d5SCristian Dumitrescu
1385074e1d5SCristian Dumitrescu if ((i == *n_tokens) && strtok_r(string, PARSE_DELIMITER, &string))
1395074e1d5SCristian Dumitrescu return -E2BIG;
1405074e1d5SCristian Dumitrescu
1415074e1d5SCristian Dumitrescu *n_tokens = i;
1425074e1d5SCristian Dumitrescu return 0;
1435074e1d5SCristian Dumitrescu }
1445074e1d5SCristian Dumitrescu
1455074e1d5SCristian Dumitrescu static int
is_comment(char * in)1465074e1d5SCristian Dumitrescu is_comment(char *in)
1475074e1d5SCristian Dumitrescu {
1485074e1d5SCristian Dumitrescu if ((strlen(in) && index("!#%;", in[0])) ||
1495074e1d5SCristian Dumitrescu (strncmp(in, "//", 2) == 0) ||
1505074e1d5SCristian Dumitrescu (strncmp(in, "--", 2) == 0))
1515074e1d5SCristian Dumitrescu return 1;
1525074e1d5SCristian Dumitrescu
1535074e1d5SCristian Dumitrescu return 0;
1545074e1d5SCristian Dumitrescu }
1555074e1d5SCristian Dumitrescu
1565074e1d5SCristian Dumitrescu static const char cmd_mempool_help[] =
1575074e1d5SCristian Dumitrescu "mempool <mempool_name>\n"
1585074e1d5SCristian Dumitrescu " buffer <buffer_size>\n"
1595074e1d5SCristian Dumitrescu " pool <pool_size>\n"
1605074e1d5SCristian Dumitrescu " cache <cache_size>\n"
1615074e1d5SCristian Dumitrescu " cpu <cpu_id>\n";
1625074e1d5SCristian Dumitrescu
1635074e1d5SCristian Dumitrescu static void
cmd_mempool(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)1645074e1d5SCristian Dumitrescu cmd_mempool(char **tokens,
1655074e1d5SCristian Dumitrescu uint32_t n_tokens,
1665074e1d5SCristian Dumitrescu char *out,
1675074e1d5SCristian Dumitrescu size_t out_size,
1685074e1d5SCristian Dumitrescu void *obj)
1695074e1d5SCristian Dumitrescu {
1705074e1d5SCristian Dumitrescu struct mempool_params p;
1715074e1d5SCristian Dumitrescu char *name;
1725074e1d5SCristian Dumitrescu struct mempool *mempool;
1735074e1d5SCristian Dumitrescu
1745074e1d5SCristian Dumitrescu if (n_tokens != 10) {
1755074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1765074e1d5SCristian Dumitrescu return;
1775074e1d5SCristian Dumitrescu }
1785074e1d5SCristian Dumitrescu
1795074e1d5SCristian Dumitrescu name = tokens[1];
1805074e1d5SCristian Dumitrescu
1815074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "buffer") != 0) {
1825074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buffer");
1835074e1d5SCristian Dumitrescu return;
1845074e1d5SCristian Dumitrescu }
1855074e1d5SCristian Dumitrescu
1865074e1d5SCristian Dumitrescu if (parser_read_uint32(&p.buffer_size, tokens[3]) != 0) {
1875074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "buffer_size");
1885074e1d5SCristian Dumitrescu return;
1895074e1d5SCristian Dumitrescu }
1905074e1d5SCristian Dumitrescu
1915074e1d5SCristian Dumitrescu if (strcmp(tokens[4], "pool") != 0) {
1925074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pool");
1935074e1d5SCristian Dumitrescu return;
1945074e1d5SCristian Dumitrescu }
1955074e1d5SCristian Dumitrescu
1965074e1d5SCristian Dumitrescu if (parser_read_uint32(&p.pool_size, tokens[5]) != 0) {
1975074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pool_size");
1985074e1d5SCristian Dumitrescu return;
1995074e1d5SCristian Dumitrescu }
2005074e1d5SCristian Dumitrescu
2015074e1d5SCristian Dumitrescu if (strcmp(tokens[6], "cache") != 0) {
2025074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cache");
2035074e1d5SCristian Dumitrescu return;
2045074e1d5SCristian Dumitrescu }
2055074e1d5SCristian Dumitrescu
2065074e1d5SCristian Dumitrescu if (parser_read_uint32(&p.cache_size, tokens[7]) != 0) {
2075074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "cache_size");
2085074e1d5SCristian Dumitrescu return;
2095074e1d5SCristian Dumitrescu }
2105074e1d5SCristian Dumitrescu
2115074e1d5SCristian Dumitrescu if (strcmp(tokens[8], "cpu") != 0) {
2125074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
2135074e1d5SCristian Dumitrescu return;
2145074e1d5SCristian Dumitrescu }
2155074e1d5SCristian Dumitrescu
2165074e1d5SCristian Dumitrescu if (parser_read_uint32(&p.cpu_id, tokens[9]) != 0) {
2175074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
2185074e1d5SCristian Dumitrescu return;
2195074e1d5SCristian Dumitrescu }
2205074e1d5SCristian Dumitrescu
2215074e1d5SCristian Dumitrescu mempool = mempool_create(obj, name, &p);
2225074e1d5SCristian Dumitrescu if (mempool == NULL) {
2235074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2245074e1d5SCristian Dumitrescu return;
2255074e1d5SCristian Dumitrescu }
2265074e1d5SCristian Dumitrescu }
2275074e1d5SCristian Dumitrescu
2285074e1d5SCristian Dumitrescu static const char cmd_link_help[] =
2295074e1d5SCristian Dumitrescu "link <link_name>\n"
2305074e1d5SCristian Dumitrescu " dev <device_name> | port <port_id>\n"
2315074e1d5SCristian Dumitrescu " rxq <n_queues> <queue_size> <mempool_name>\n"
2325074e1d5SCristian Dumitrescu " txq <n_queues> <queue_size>\n"
2335074e1d5SCristian Dumitrescu " promiscuous on | off\n"
2345074e1d5SCristian Dumitrescu " [rss <qid_0> ... <qid_n>]\n";
2355074e1d5SCristian Dumitrescu
2365074e1d5SCristian Dumitrescu static void
cmd_link(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)2375074e1d5SCristian Dumitrescu cmd_link(char **tokens,
2385074e1d5SCristian Dumitrescu uint32_t n_tokens,
2395074e1d5SCristian Dumitrescu char *out,
2405074e1d5SCristian Dumitrescu size_t out_size,
2415074e1d5SCristian Dumitrescu void *obj)
2425074e1d5SCristian Dumitrescu {
2435074e1d5SCristian Dumitrescu struct link_params p;
2445074e1d5SCristian Dumitrescu struct link_params_rss rss;
2455074e1d5SCristian Dumitrescu struct link *link;
2465074e1d5SCristian Dumitrescu char *name;
2475074e1d5SCristian Dumitrescu
2485074e1d5SCristian Dumitrescu memset(&p, 0, sizeof(p));
2495074e1d5SCristian Dumitrescu
2505074e1d5SCristian Dumitrescu if ((n_tokens < 13) || (n_tokens > 14 + LINK_RXQ_RSS_MAX)) {
2515074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2525074e1d5SCristian Dumitrescu return;
2535074e1d5SCristian Dumitrescu }
2545074e1d5SCristian Dumitrescu name = tokens[1];
2555074e1d5SCristian Dumitrescu
2565074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "dev") == 0)
2575074e1d5SCristian Dumitrescu p.dev_name = tokens[3];
2585074e1d5SCristian Dumitrescu else if (strcmp(tokens[2], "port") == 0) {
2595074e1d5SCristian Dumitrescu p.dev_name = NULL;
2605074e1d5SCristian Dumitrescu
2615074e1d5SCristian Dumitrescu if (parser_read_uint16(&p.port_id, tokens[3]) != 0) {
2625074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2635074e1d5SCristian Dumitrescu return;
2645074e1d5SCristian Dumitrescu }
2655074e1d5SCristian Dumitrescu } else {
2665074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dev or port");
2675074e1d5SCristian Dumitrescu return;
2685074e1d5SCristian Dumitrescu }
2695074e1d5SCristian Dumitrescu
2705074e1d5SCristian Dumitrescu if (strcmp(tokens[4], "rxq") != 0) {
2715074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
2725074e1d5SCristian Dumitrescu return;
2735074e1d5SCristian Dumitrescu }
2745074e1d5SCristian Dumitrescu
2755074e1d5SCristian Dumitrescu if (parser_read_uint32(&p.rx.n_queues, tokens[5]) != 0) {
2765074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "n_queues");
2775074e1d5SCristian Dumitrescu return;
2785074e1d5SCristian Dumitrescu }
2795074e1d5SCristian Dumitrescu if (parser_read_uint32(&p.rx.queue_size, tokens[6]) != 0) {
2805074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "queue_size");
2815074e1d5SCristian Dumitrescu return;
2825074e1d5SCristian Dumitrescu }
2835074e1d5SCristian Dumitrescu
2845074e1d5SCristian Dumitrescu p.rx.mempool_name = tokens[7];
2855074e1d5SCristian Dumitrescu
2865074e1d5SCristian Dumitrescu if (strcmp(tokens[8], "txq") != 0) {
2875074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
2885074e1d5SCristian Dumitrescu return;
2895074e1d5SCristian Dumitrescu }
2905074e1d5SCristian Dumitrescu
2915074e1d5SCristian Dumitrescu if (parser_read_uint32(&p.tx.n_queues, tokens[9]) != 0) {
2925074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "n_queues");
2935074e1d5SCristian Dumitrescu return;
2945074e1d5SCristian Dumitrescu }
2955074e1d5SCristian Dumitrescu
2965074e1d5SCristian Dumitrescu if (parser_read_uint32(&p.tx.queue_size, tokens[10]) != 0) {
2975074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "queue_size");
2985074e1d5SCristian Dumitrescu return;
2995074e1d5SCristian Dumitrescu }
3005074e1d5SCristian Dumitrescu
3015074e1d5SCristian Dumitrescu if (strcmp(tokens[11], "promiscuous") != 0) {
3025074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "promiscuous");
3035074e1d5SCristian Dumitrescu return;
3045074e1d5SCristian Dumitrescu }
3055074e1d5SCristian Dumitrescu
3065074e1d5SCristian Dumitrescu if (strcmp(tokens[12], "on") == 0)
3075074e1d5SCristian Dumitrescu p.promiscuous = 1;
3085074e1d5SCristian Dumitrescu else if (strcmp(tokens[12], "off") == 0)
3095074e1d5SCristian Dumitrescu p.promiscuous = 0;
3105074e1d5SCristian Dumitrescu else {
3115074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "on or off");
3125074e1d5SCristian Dumitrescu return;
3135074e1d5SCristian Dumitrescu }
3145074e1d5SCristian Dumitrescu
3155074e1d5SCristian Dumitrescu /* RSS */
3165074e1d5SCristian Dumitrescu p.rx.rss = NULL;
3175074e1d5SCristian Dumitrescu if (n_tokens > 13) {
3185074e1d5SCristian Dumitrescu uint32_t queue_id, i;
3195074e1d5SCristian Dumitrescu
3205074e1d5SCristian Dumitrescu if (strcmp(tokens[13], "rss") != 0) {
3215074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rss");
3225074e1d5SCristian Dumitrescu return;
3235074e1d5SCristian Dumitrescu }
3245074e1d5SCristian Dumitrescu
3255074e1d5SCristian Dumitrescu p.rx.rss = &rss;
3265074e1d5SCristian Dumitrescu
3275074e1d5SCristian Dumitrescu rss.n_queues = 0;
3285074e1d5SCristian Dumitrescu for (i = 14; i < n_tokens; i++) {
3295074e1d5SCristian Dumitrescu if (parser_read_uint32(&queue_id, tokens[i]) != 0) {
3305074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID,
3315074e1d5SCristian Dumitrescu "queue_id");
3325074e1d5SCristian Dumitrescu return;
3335074e1d5SCristian Dumitrescu }
3345074e1d5SCristian Dumitrescu
3355074e1d5SCristian Dumitrescu rss.queue_id[rss.n_queues] = queue_id;
3365074e1d5SCristian Dumitrescu rss.n_queues++;
3375074e1d5SCristian Dumitrescu }
3385074e1d5SCristian Dumitrescu }
3395074e1d5SCristian Dumitrescu
3405074e1d5SCristian Dumitrescu link = link_create(obj, name, &p);
3415074e1d5SCristian Dumitrescu if (link == NULL) {
3425074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
3435074e1d5SCristian Dumitrescu return;
3445074e1d5SCristian Dumitrescu }
3455074e1d5SCristian Dumitrescu }
3465074e1d5SCristian Dumitrescu
3475074e1d5SCristian Dumitrescu /* Print the link stats and info */
3485074e1d5SCristian Dumitrescu static void
print_link_info(struct link * link,char * out,size_t out_size)3495074e1d5SCristian Dumitrescu print_link_info(struct link *link, char *out, size_t out_size)
3505074e1d5SCristian Dumitrescu {
3515074e1d5SCristian Dumitrescu struct rte_eth_stats stats;
3525074e1d5SCristian Dumitrescu struct rte_ether_addr mac_addr;
3535074e1d5SCristian Dumitrescu struct rte_eth_link eth_link;
3545074e1d5SCristian Dumitrescu uint16_t mtu;
3555074e1d5SCristian Dumitrescu int ret;
3565074e1d5SCristian Dumitrescu
3575074e1d5SCristian Dumitrescu memset(&stats, 0, sizeof(stats));
3585074e1d5SCristian Dumitrescu rte_eth_stats_get(link->port_id, &stats);
3595074e1d5SCristian Dumitrescu
3605074e1d5SCristian Dumitrescu ret = rte_eth_macaddr_get(link->port_id, &mac_addr);
3615074e1d5SCristian Dumitrescu if (ret != 0) {
3625074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s: MAC address get failed: %s",
3635074e1d5SCristian Dumitrescu link->name, rte_strerror(-ret));
3645074e1d5SCristian Dumitrescu return;
3655074e1d5SCristian Dumitrescu }
3665074e1d5SCristian Dumitrescu
3675074e1d5SCristian Dumitrescu ret = rte_eth_link_get(link->port_id, ð_link);
3685074e1d5SCristian Dumitrescu if (ret < 0) {
3695074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s: link get failed: %s",
3705074e1d5SCristian Dumitrescu link->name, rte_strerror(-ret));
3715074e1d5SCristian Dumitrescu return;
3725074e1d5SCristian Dumitrescu }
3735074e1d5SCristian Dumitrescu
3745074e1d5SCristian Dumitrescu rte_eth_dev_get_mtu(link->port_id, &mtu);
3755074e1d5SCristian Dumitrescu
3765074e1d5SCristian Dumitrescu snprintf(out, out_size,
3775074e1d5SCristian Dumitrescu "\n"
3785074e1d5SCristian Dumitrescu "%s: flags=<%s> mtu %u\n"
379c2c4f87bSAman Deep Singh "\tether " RTE_ETHER_ADDR_PRT_FMT " rxqueues %u txqueues %u\n"
3805074e1d5SCristian Dumitrescu "\tport# %u speed %s\n"
3815074e1d5SCristian Dumitrescu "\tRX packets %" PRIu64" bytes %" PRIu64"\n"
3825074e1d5SCristian Dumitrescu "\tRX errors %" PRIu64" missed %" PRIu64" no-mbuf %" PRIu64"\n"
3835074e1d5SCristian Dumitrescu "\tTX packets %" PRIu64" bytes %" PRIu64"\n"
3845074e1d5SCristian Dumitrescu "\tTX errors %" PRIu64"\n",
3855074e1d5SCristian Dumitrescu link->name,
3865074e1d5SCristian Dumitrescu eth_link.link_status == 0 ? "DOWN" : "UP",
3875074e1d5SCristian Dumitrescu mtu,
388a7db3afcSAman Deep Singh RTE_ETHER_ADDR_BYTES(&mac_addr),
3895074e1d5SCristian Dumitrescu link->n_rxq,
3905074e1d5SCristian Dumitrescu link->n_txq,
3915074e1d5SCristian Dumitrescu link->port_id,
3925074e1d5SCristian Dumitrescu rte_eth_link_speed_to_str(eth_link.link_speed),
3935074e1d5SCristian Dumitrescu stats.ipackets,
3945074e1d5SCristian Dumitrescu stats.ibytes,
3955074e1d5SCristian Dumitrescu stats.ierrors,
3965074e1d5SCristian Dumitrescu stats.imissed,
3975074e1d5SCristian Dumitrescu stats.rx_nombuf,
3985074e1d5SCristian Dumitrescu stats.opackets,
3995074e1d5SCristian Dumitrescu stats.obytes,
4005074e1d5SCristian Dumitrescu stats.oerrors);
4015074e1d5SCristian Dumitrescu }
4025074e1d5SCristian Dumitrescu
4035074e1d5SCristian Dumitrescu /*
4045074e1d5SCristian Dumitrescu * link show [<link_name>]
4055074e1d5SCristian Dumitrescu */
4065074e1d5SCristian Dumitrescu static void
cmd_link_show(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)4075074e1d5SCristian Dumitrescu cmd_link_show(char **tokens,
4085074e1d5SCristian Dumitrescu uint32_t n_tokens,
4095074e1d5SCristian Dumitrescu char *out,
4105074e1d5SCristian Dumitrescu size_t out_size,
4115074e1d5SCristian Dumitrescu void *obj)
4125074e1d5SCristian Dumitrescu {
4135074e1d5SCristian Dumitrescu struct link *link;
4145074e1d5SCristian Dumitrescu char *link_name;
4155074e1d5SCristian Dumitrescu
4165074e1d5SCristian Dumitrescu if (n_tokens != 2 && n_tokens != 3) {
4175074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4185074e1d5SCristian Dumitrescu return;
4195074e1d5SCristian Dumitrescu }
4205074e1d5SCristian Dumitrescu
4215074e1d5SCristian Dumitrescu if (n_tokens == 2) {
4225074e1d5SCristian Dumitrescu link = link_next(obj, NULL);
4235074e1d5SCristian Dumitrescu
4245074e1d5SCristian Dumitrescu while (link != NULL) {
4255074e1d5SCristian Dumitrescu out_size = out_size - strlen(out);
4265074e1d5SCristian Dumitrescu out = &out[strlen(out)];
4275074e1d5SCristian Dumitrescu
4285074e1d5SCristian Dumitrescu print_link_info(link, out, out_size);
4295074e1d5SCristian Dumitrescu link = link_next(obj, link);
4305074e1d5SCristian Dumitrescu }
4315074e1d5SCristian Dumitrescu } else {
4325074e1d5SCristian Dumitrescu out_size = out_size - strlen(out);
4335074e1d5SCristian Dumitrescu out = &out[strlen(out)];
4345074e1d5SCristian Dumitrescu
4355074e1d5SCristian Dumitrescu link_name = tokens[2];
4365074e1d5SCristian Dumitrescu link = link_find(obj, link_name);
4375074e1d5SCristian Dumitrescu
4385074e1d5SCristian Dumitrescu if (link == NULL) {
4395074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID,
4405074e1d5SCristian Dumitrescu "Link does not exist");
4415074e1d5SCristian Dumitrescu return;
4425074e1d5SCristian Dumitrescu }
4435074e1d5SCristian Dumitrescu print_link_info(link, out, out_size);
4445074e1d5SCristian Dumitrescu }
4455074e1d5SCristian Dumitrescu }
4465074e1d5SCristian Dumitrescu
44777a41301SCristian Dumitrescu static const char cmd_ring_help[] =
44877a41301SCristian Dumitrescu "ring <ring_name> size <size> numa <numa_node>\n";
44977a41301SCristian Dumitrescu
45077a41301SCristian Dumitrescu static void
cmd_ring(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)45177a41301SCristian Dumitrescu cmd_ring(char **tokens,
45277a41301SCristian Dumitrescu uint32_t n_tokens,
45377a41301SCristian Dumitrescu char *out,
45477a41301SCristian Dumitrescu size_t out_size,
45577a41301SCristian Dumitrescu void *obj)
45677a41301SCristian Dumitrescu {
45777a41301SCristian Dumitrescu struct ring_params p;
45877a41301SCristian Dumitrescu char *name;
45977a41301SCristian Dumitrescu struct ring *ring;
46077a41301SCristian Dumitrescu
46177a41301SCristian Dumitrescu if (n_tokens != 6) {
46277a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
46377a41301SCristian Dumitrescu return;
46477a41301SCristian Dumitrescu }
46577a41301SCristian Dumitrescu
46677a41301SCristian Dumitrescu name = tokens[1];
46777a41301SCristian Dumitrescu
46877a41301SCristian Dumitrescu if (strcmp(tokens[2], "size") != 0) {
46977a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
47077a41301SCristian Dumitrescu return;
47177a41301SCristian Dumitrescu }
47277a41301SCristian Dumitrescu
47377a41301SCristian Dumitrescu if (parser_read_uint32(&p.size, tokens[3]) != 0) {
47477a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "size");
47577a41301SCristian Dumitrescu return;
47677a41301SCristian Dumitrescu }
47777a41301SCristian Dumitrescu
47877a41301SCristian Dumitrescu if (strcmp(tokens[4], "numa") != 0) {
47977a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "numa");
48077a41301SCristian Dumitrescu return;
48177a41301SCristian Dumitrescu }
48277a41301SCristian Dumitrescu
48377a41301SCristian Dumitrescu if (parser_read_uint32(&p.numa_node, tokens[5]) != 0) {
48477a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "numa_node");
48577a41301SCristian Dumitrescu return;
48677a41301SCristian Dumitrescu }
48777a41301SCristian Dumitrescu
48877a41301SCristian Dumitrescu ring = ring_create(obj, name, &p);
48977a41301SCristian Dumitrescu if (!ring) {
49077a41301SCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
49177a41301SCristian Dumitrescu return;
49277a41301SCristian Dumitrescu }
49377a41301SCristian Dumitrescu }
49477a41301SCristian Dumitrescu
495e2b8dc52SVenkata Suresh Kumar P static const char cmd_tap_help[] =
496e2b8dc52SVenkata Suresh Kumar P "tap <tap_name>\n";
497e2b8dc52SVenkata Suresh Kumar P
498e2b8dc52SVenkata Suresh Kumar P static void
cmd_tap(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)499e2b8dc52SVenkata Suresh Kumar P cmd_tap(char **tokens,
500e2b8dc52SVenkata Suresh Kumar P uint32_t n_tokens,
501e2b8dc52SVenkata Suresh Kumar P char *out,
502e2b8dc52SVenkata Suresh Kumar P size_t out_size,
503e2b8dc52SVenkata Suresh Kumar P void *obj)
504e2b8dc52SVenkata Suresh Kumar P {
505e2b8dc52SVenkata Suresh Kumar P struct tap *tap;
506e2b8dc52SVenkata Suresh Kumar P char *name;
507e2b8dc52SVenkata Suresh Kumar P
508e2b8dc52SVenkata Suresh Kumar P if (n_tokens < 2) {
509e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
510e2b8dc52SVenkata Suresh Kumar P return;
511e2b8dc52SVenkata Suresh Kumar P }
512e2b8dc52SVenkata Suresh Kumar P name = tokens[1];
513e2b8dc52SVenkata Suresh Kumar P
514e2b8dc52SVenkata Suresh Kumar P tap = tap_create(obj, name);
515e2b8dc52SVenkata Suresh Kumar P if (tap == NULL) {
516e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
517e2b8dc52SVenkata Suresh Kumar P return;
518e2b8dc52SVenkata Suresh Kumar P }
519e2b8dc52SVenkata Suresh Kumar P }
520e2b8dc52SVenkata Suresh Kumar P
5215074e1d5SCristian Dumitrescu static const char cmd_pipeline_create_help[] =
5225074e1d5SCristian Dumitrescu "pipeline <pipeline_name> create <numa_node>\n";
5235074e1d5SCristian Dumitrescu
5245074e1d5SCristian Dumitrescu static void
cmd_pipeline_create(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)5255074e1d5SCristian Dumitrescu cmd_pipeline_create(char **tokens,
5265074e1d5SCristian Dumitrescu uint32_t n_tokens,
5275074e1d5SCristian Dumitrescu char *out,
5285074e1d5SCristian Dumitrescu size_t out_size,
5295074e1d5SCristian Dumitrescu void *obj)
5305074e1d5SCristian Dumitrescu {
5315074e1d5SCristian Dumitrescu struct pipeline *p;
5325074e1d5SCristian Dumitrescu char *name;
5335074e1d5SCristian Dumitrescu uint32_t numa_node;
5345074e1d5SCristian Dumitrescu
5355074e1d5SCristian Dumitrescu if (n_tokens != 4) {
5365074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5375074e1d5SCristian Dumitrescu return;
5385074e1d5SCristian Dumitrescu }
5395074e1d5SCristian Dumitrescu
5405074e1d5SCristian Dumitrescu name = tokens[1];
5415074e1d5SCristian Dumitrescu
5425074e1d5SCristian Dumitrescu if (parser_read_uint32(&numa_node, tokens[3]) != 0) {
5435074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "numa_node");
5445074e1d5SCristian Dumitrescu return;
5455074e1d5SCristian Dumitrescu }
5465074e1d5SCristian Dumitrescu
5475074e1d5SCristian Dumitrescu p = pipeline_create(obj, name, (int)numa_node);
5485074e1d5SCristian Dumitrescu if (!p) {
5495074e1d5SCristian Dumitrescu snprintf(out, out_size, "pipeline create error.");
5505074e1d5SCristian Dumitrescu return;
5515074e1d5SCristian Dumitrescu }
5525074e1d5SCristian Dumitrescu }
5535074e1d5SCristian Dumitrescu
5545074e1d5SCristian Dumitrescu static const char cmd_pipeline_port_in_help[] =
5555074e1d5SCristian Dumitrescu "pipeline <pipeline_name> port in <port_id>\n"
5565074e1d5SCristian Dumitrescu " link <link_name> rxq <queue_id> bsz <burst_size>\n"
55777a41301SCristian Dumitrescu " ring <ring_name> bsz <burst_size>\n"
5580317c452SYogesh Jangra " | source <mempool_name> <file_name> loop <n_loops>\n"
559e2b8dc52SVenkata Suresh Kumar P " | tap <tap_name> mempool <mempool_name> mtu <mtu> bsz <burst_size>\n";
5605074e1d5SCristian Dumitrescu
5615074e1d5SCristian Dumitrescu static void
cmd_pipeline_port_in(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)5625074e1d5SCristian Dumitrescu cmd_pipeline_port_in(char **tokens,
5635074e1d5SCristian Dumitrescu uint32_t n_tokens,
5645074e1d5SCristian Dumitrescu char *out,
5655074e1d5SCristian Dumitrescu size_t out_size,
5665074e1d5SCristian Dumitrescu void *obj)
5675074e1d5SCristian Dumitrescu {
5685074e1d5SCristian Dumitrescu struct pipeline *p;
5695074e1d5SCristian Dumitrescu int status;
5705074e1d5SCristian Dumitrescu uint32_t port_id = 0, t0;
5715074e1d5SCristian Dumitrescu
5725074e1d5SCristian Dumitrescu if (n_tokens < 6) {
5735074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5745074e1d5SCristian Dumitrescu return;
5755074e1d5SCristian Dumitrescu }
5765074e1d5SCristian Dumitrescu
5775074e1d5SCristian Dumitrescu p = pipeline_find(obj, tokens[1]);
5785074e1d5SCristian Dumitrescu if (!p || p->ctl) {
5795074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5805074e1d5SCristian Dumitrescu return;
5815074e1d5SCristian Dumitrescu }
5825074e1d5SCristian Dumitrescu
5835074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "port") != 0) {
5845074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5855074e1d5SCristian Dumitrescu return;
5865074e1d5SCristian Dumitrescu }
5875074e1d5SCristian Dumitrescu
5885074e1d5SCristian Dumitrescu if (strcmp(tokens[3], "in") != 0) {
5895074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
5905074e1d5SCristian Dumitrescu return;
5915074e1d5SCristian Dumitrescu }
5925074e1d5SCristian Dumitrescu
5935074e1d5SCristian Dumitrescu if (parser_read_uint32(&port_id, tokens[4]) != 0) {
5945074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
5955074e1d5SCristian Dumitrescu return;
5965074e1d5SCristian Dumitrescu }
5975074e1d5SCristian Dumitrescu
5985074e1d5SCristian Dumitrescu t0 = 5;
5995074e1d5SCristian Dumitrescu
6005074e1d5SCristian Dumitrescu if (strcmp(tokens[t0], "link") == 0) {
6015074e1d5SCristian Dumitrescu struct rte_swx_port_ethdev_reader_params params;
6025074e1d5SCristian Dumitrescu struct link *link;
6035074e1d5SCristian Dumitrescu
6045074e1d5SCristian Dumitrescu if (n_tokens < t0 + 6) {
6055074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH,
6065074e1d5SCristian Dumitrescu "pipeline port in link");
6075074e1d5SCristian Dumitrescu return;
6085074e1d5SCristian Dumitrescu }
6095074e1d5SCristian Dumitrescu
6105074e1d5SCristian Dumitrescu link = link_find(obj, tokens[t0 + 1]);
6115074e1d5SCristian Dumitrescu if (!link) {
6125074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID,
6135074e1d5SCristian Dumitrescu "link_name");
6145074e1d5SCristian Dumitrescu return;
6155074e1d5SCristian Dumitrescu }
6165074e1d5SCristian Dumitrescu params.dev_name = link->dev_name;
6175074e1d5SCristian Dumitrescu
6185074e1d5SCristian Dumitrescu if (strcmp(tokens[t0 + 2], "rxq") != 0) {
6195074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
6205074e1d5SCristian Dumitrescu return;
6215074e1d5SCristian Dumitrescu }
6225074e1d5SCristian Dumitrescu
6235074e1d5SCristian Dumitrescu if (parser_read_uint16(¶ms.queue_id, tokens[t0 + 3]) != 0) {
6245074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID,
6255074e1d5SCristian Dumitrescu "queue_id");
6265074e1d5SCristian Dumitrescu return;
6275074e1d5SCristian Dumitrescu }
6285074e1d5SCristian Dumitrescu
6295074e1d5SCristian Dumitrescu if (strcmp(tokens[t0 + 4], "bsz") != 0) {
6305074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
6315074e1d5SCristian Dumitrescu return;
6325074e1d5SCristian Dumitrescu }
6335074e1d5SCristian Dumitrescu
6345074e1d5SCristian Dumitrescu if (parser_read_uint32(¶ms.burst_size, tokens[t0 + 5])) {
6355074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID,
6365074e1d5SCristian Dumitrescu "burst_size");
6375074e1d5SCristian Dumitrescu return;
6385074e1d5SCristian Dumitrescu }
6395074e1d5SCristian Dumitrescu
6405074e1d5SCristian Dumitrescu t0 += 6;
6415074e1d5SCristian Dumitrescu
6425074e1d5SCristian Dumitrescu status = rte_swx_pipeline_port_in_config(p->p,
6435074e1d5SCristian Dumitrescu port_id,
6445074e1d5SCristian Dumitrescu "ethdev",
6455074e1d5SCristian Dumitrescu ¶ms);
64677a41301SCristian Dumitrescu } else if (strcmp(tokens[t0], "ring") == 0) {
64777a41301SCristian Dumitrescu struct rte_swx_port_ring_reader_params params;
64877a41301SCristian Dumitrescu struct ring *ring;
64977a41301SCristian Dumitrescu
65077a41301SCristian Dumitrescu if (n_tokens < t0 + 4) {
65177a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH,
65277a41301SCristian Dumitrescu "pipeline port in ring");
65377a41301SCristian Dumitrescu return;
65477a41301SCristian Dumitrescu }
65577a41301SCristian Dumitrescu
65677a41301SCristian Dumitrescu ring = ring_find(obj, tokens[t0 + 1]);
65777a41301SCristian Dumitrescu if (!ring) {
65877a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID,
65977a41301SCristian Dumitrescu "ring_name");
66077a41301SCristian Dumitrescu return;
66177a41301SCristian Dumitrescu }
66277a41301SCristian Dumitrescu params.name = ring->name;
66377a41301SCristian Dumitrescu
66477a41301SCristian Dumitrescu if (strcmp(tokens[t0 + 2], "bsz") != 0) {
66577a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
66677a41301SCristian Dumitrescu return;
66777a41301SCristian Dumitrescu }
66877a41301SCristian Dumitrescu
66977a41301SCristian Dumitrescu if (parser_read_uint32(¶ms.burst_size, tokens[t0 + 3])) {
67077a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID,
67177a41301SCristian Dumitrescu "burst_size");
67277a41301SCristian Dumitrescu return;
67377a41301SCristian Dumitrescu }
67477a41301SCristian Dumitrescu
67577a41301SCristian Dumitrescu t0 += 4;
67677a41301SCristian Dumitrescu
67777a41301SCristian Dumitrescu status = rte_swx_pipeline_port_in_config(p->p,
67877a41301SCristian Dumitrescu port_id,
67977a41301SCristian Dumitrescu "ring",
68077a41301SCristian Dumitrescu ¶ms);
6815074e1d5SCristian Dumitrescu } else if (strcmp(tokens[t0], "source") == 0) {
6825074e1d5SCristian Dumitrescu struct rte_swx_port_source_params params;
6835074e1d5SCristian Dumitrescu struct mempool *mp;
6845074e1d5SCristian Dumitrescu
6850317c452SYogesh Jangra if (n_tokens < t0 + 5) {
6865074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH,
6875074e1d5SCristian Dumitrescu "pipeline port in source");
6885074e1d5SCristian Dumitrescu return;
6895074e1d5SCristian Dumitrescu }
6905074e1d5SCristian Dumitrescu
6915074e1d5SCristian Dumitrescu mp = mempool_find(obj, tokens[t0 + 1]);
6925074e1d5SCristian Dumitrescu if (!mp) {
6935074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID,
6945074e1d5SCristian Dumitrescu "mempool_name");
6955074e1d5SCristian Dumitrescu return;
6965074e1d5SCristian Dumitrescu }
6975074e1d5SCristian Dumitrescu params.pool = mp->m;
6985074e1d5SCristian Dumitrescu
6995074e1d5SCristian Dumitrescu params.file_name = tokens[t0 + 2];
7005074e1d5SCristian Dumitrescu
7010317c452SYogesh Jangra if (strcmp(tokens[t0 + 3], "loop") != 0) {
7020317c452SYogesh Jangra snprintf(out, out_size, MSG_ARG_NOT_FOUND, "loop");
7030317c452SYogesh Jangra return;
7040317c452SYogesh Jangra }
7050317c452SYogesh Jangra
7060317c452SYogesh Jangra if (parser_read_uint64(¶ms.n_loops, tokens[t0 + 4])) {
7070317c452SYogesh Jangra snprintf(out, out_size, MSG_ARG_INVALID,
7080317c452SYogesh Jangra "n_loops");
7090317c452SYogesh Jangra return;
7100317c452SYogesh Jangra }
7110317c452SYogesh Jangra
7120317c452SYogesh Jangra t0 += 5;
7135074e1d5SCristian Dumitrescu
7145074e1d5SCristian Dumitrescu status = rte_swx_pipeline_port_in_config(p->p,
7155074e1d5SCristian Dumitrescu port_id,
7165074e1d5SCristian Dumitrescu "source",
7175074e1d5SCristian Dumitrescu ¶ms);
718e2b8dc52SVenkata Suresh Kumar P } else if (strcmp(tokens[t0], "tap") == 0) {
719e2b8dc52SVenkata Suresh Kumar P struct rte_swx_port_fd_reader_params params;
720e2b8dc52SVenkata Suresh Kumar P struct tap *tap;
721e2b8dc52SVenkata Suresh Kumar P struct mempool *mp;
722e2b8dc52SVenkata Suresh Kumar P
723e2b8dc52SVenkata Suresh Kumar P if (n_tokens < t0 + 8) {
724e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_ARG_MISMATCH,
725e2b8dc52SVenkata Suresh Kumar P "pipeline port in tap");
726e2b8dc52SVenkata Suresh Kumar P return;
727e2b8dc52SVenkata Suresh Kumar P }
728e2b8dc52SVenkata Suresh Kumar P
729e2b8dc52SVenkata Suresh Kumar P tap = tap_find(obj, tokens[t0 + 1]);
730e2b8dc52SVenkata Suresh Kumar P if (!tap) {
731e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_ARG_INVALID,
732e2b8dc52SVenkata Suresh Kumar P "tap_name");
733e2b8dc52SVenkata Suresh Kumar P return;
734e2b8dc52SVenkata Suresh Kumar P }
735e2b8dc52SVenkata Suresh Kumar P params.fd = tap->fd;
736e2b8dc52SVenkata Suresh Kumar P
737e2b8dc52SVenkata Suresh Kumar P if (strcmp(tokens[t0 + 2], "mempool") != 0) {
738e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_ARG_NOT_FOUND,
739e2b8dc52SVenkata Suresh Kumar P "mempool");
740e2b8dc52SVenkata Suresh Kumar P return;
741e2b8dc52SVenkata Suresh Kumar P }
742e2b8dc52SVenkata Suresh Kumar P
743e2b8dc52SVenkata Suresh Kumar P mp = mempool_find(obj, tokens[t0 + 3]);
744e2b8dc52SVenkata Suresh Kumar P if (!mp) {
745e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_ARG_INVALID,
746e2b8dc52SVenkata Suresh Kumar P "mempool_name");
747e2b8dc52SVenkata Suresh Kumar P return;
748e2b8dc52SVenkata Suresh Kumar P }
749e2b8dc52SVenkata Suresh Kumar P params.mempool = mp->m;
750e2b8dc52SVenkata Suresh Kumar P
751e2b8dc52SVenkata Suresh Kumar P if (strcmp(tokens[t0 + 4], "mtu") != 0) {
752e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_ARG_NOT_FOUND,
753e2b8dc52SVenkata Suresh Kumar P "mtu");
754e2b8dc52SVenkata Suresh Kumar P return;
755e2b8dc52SVenkata Suresh Kumar P }
756e2b8dc52SVenkata Suresh Kumar P
757e2b8dc52SVenkata Suresh Kumar P if (parser_read_uint32(¶ms.mtu, tokens[t0 + 5]) != 0) {
758e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
759e2b8dc52SVenkata Suresh Kumar P return;
760e2b8dc52SVenkata Suresh Kumar P }
761e2b8dc52SVenkata Suresh Kumar P
762e2b8dc52SVenkata Suresh Kumar P if (strcmp(tokens[t0 + 6], "bsz") != 0) {
763e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
764e2b8dc52SVenkata Suresh Kumar P return;
765e2b8dc52SVenkata Suresh Kumar P }
766e2b8dc52SVenkata Suresh Kumar P
767e2b8dc52SVenkata Suresh Kumar P if (parser_read_uint32(¶ms.burst_size, tokens[t0 + 7])) {
768e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_ARG_INVALID,
769e2b8dc52SVenkata Suresh Kumar P "burst_size");
770e2b8dc52SVenkata Suresh Kumar P return;
771e2b8dc52SVenkata Suresh Kumar P }
772e2b8dc52SVenkata Suresh Kumar P
773e2b8dc52SVenkata Suresh Kumar P t0 += 8;
774e2b8dc52SVenkata Suresh Kumar P
775e2b8dc52SVenkata Suresh Kumar P status = rte_swx_pipeline_port_in_config(p->p,
776e2b8dc52SVenkata Suresh Kumar P port_id,
777e2b8dc52SVenkata Suresh Kumar P "fd",
778e2b8dc52SVenkata Suresh Kumar P ¶ms);
779e2b8dc52SVenkata Suresh Kumar P
7805074e1d5SCristian Dumitrescu } else {
7815074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
7825074e1d5SCristian Dumitrescu return;
7835074e1d5SCristian Dumitrescu }
7845074e1d5SCristian Dumitrescu
7855074e1d5SCristian Dumitrescu if (status) {
7865074e1d5SCristian Dumitrescu snprintf(out, out_size, "port in error.");
7875074e1d5SCristian Dumitrescu return;
7885074e1d5SCristian Dumitrescu }
7895074e1d5SCristian Dumitrescu
7905074e1d5SCristian Dumitrescu if (n_tokens != t0) {
7915074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
7925074e1d5SCristian Dumitrescu return;
7935074e1d5SCristian Dumitrescu }
7945074e1d5SCristian Dumitrescu }
7955074e1d5SCristian Dumitrescu
7965074e1d5SCristian Dumitrescu static const char cmd_pipeline_port_out_help[] =
7975074e1d5SCristian Dumitrescu "pipeline <pipeline_name> port out <port_id>\n"
7985074e1d5SCristian Dumitrescu " link <link_name> txq <txq_id> bsz <burst_size>\n"
79977a41301SCristian Dumitrescu " ring <ring_name> bsz <burst_size>\n"
800e2b8dc52SVenkata Suresh Kumar P " | sink <file_name> | none\n"
801e2b8dc52SVenkata Suresh Kumar P " | tap <tap_name> bsz <burst_size>\n";
8025074e1d5SCristian Dumitrescu
8035074e1d5SCristian Dumitrescu static void
cmd_pipeline_port_out(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)8045074e1d5SCristian Dumitrescu cmd_pipeline_port_out(char **tokens,
8055074e1d5SCristian Dumitrescu uint32_t n_tokens,
8065074e1d5SCristian Dumitrescu char *out,
8075074e1d5SCristian Dumitrescu size_t out_size,
8085074e1d5SCristian Dumitrescu void *obj)
8095074e1d5SCristian Dumitrescu {
8105074e1d5SCristian Dumitrescu struct pipeline *p;
8115074e1d5SCristian Dumitrescu int status;
8125074e1d5SCristian Dumitrescu uint32_t port_id = 0, t0;
8135074e1d5SCristian Dumitrescu
8145074e1d5SCristian Dumitrescu if (n_tokens < 6) {
8155074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
8165074e1d5SCristian Dumitrescu return;
8175074e1d5SCristian Dumitrescu }
8185074e1d5SCristian Dumitrescu
8195074e1d5SCristian Dumitrescu p = pipeline_find(obj, tokens[1]);
8205074e1d5SCristian Dumitrescu if (!p || p->ctl) {
8215074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
8225074e1d5SCristian Dumitrescu return;
8235074e1d5SCristian Dumitrescu }
8245074e1d5SCristian Dumitrescu
8255074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "port") != 0) {
8265074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
8275074e1d5SCristian Dumitrescu return;
8285074e1d5SCristian Dumitrescu }
8295074e1d5SCristian Dumitrescu
8305074e1d5SCristian Dumitrescu if (strcmp(tokens[3], "out") != 0) {
8315074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
8325074e1d5SCristian Dumitrescu return;
8335074e1d5SCristian Dumitrescu }
8345074e1d5SCristian Dumitrescu
8355074e1d5SCristian Dumitrescu if (parser_read_uint32(&port_id, tokens[4]) != 0) {
8365074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
8375074e1d5SCristian Dumitrescu return;
8385074e1d5SCristian Dumitrescu }
8395074e1d5SCristian Dumitrescu
8405074e1d5SCristian Dumitrescu t0 = 5;
8415074e1d5SCristian Dumitrescu
8425074e1d5SCristian Dumitrescu if (strcmp(tokens[t0], "link") == 0) {
8435074e1d5SCristian Dumitrescu struct rte_swx_port_ethdev_writer_params params;
8445074e1d5SCristian Dumitrescu struct link *link;
8455074e1d5SCristian Dumitrescu
8465074e1d5SCristian Dumitrescu if (n_tokens < t0 + 6) {
8475074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH,
8485074e1d5SCristian Dumitrescu "pipeline port out link");
8495074e1d5SCristian Dumitrescu return;
8505074e1d5SCristian Dumitrescu }
8515074e1d5SCristian Dumitrescu
8525074e1d5SCristian Dumitrescu link = link_find(obj, tokens[t0 + 1]);
8535074e1d5SCristian Dumitrescu if (!link) {
8545074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID,
8555074e1d5SCristian Dumitrescu "link_name");
8565074e1d5SCristian Dumitrescu return;
8575074e1d5SCristian Dumitrescu }
8585074e1d5SCristian Dumitrescu params.dev_name = link->dev_name;
8595074e1d5SCristian Dumitrescu
8605074e1d5SCristian Dumitrescu if (strcmp(tokens[t0 + 2], "txq") != 0) {
8615074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
8625074e1d5SCristian Dumitrescu return;
8635074e1d5SCristian Dumitrescu }
8645074e1d5SCristian Dumitrescu
8655074e1d5SCristian Dumitrescu if (parser_read_uint16(¶ms.queue_id, tokens[t0 + 3]) != 0) {
8665074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID,
8675074e1d5SCristian Dumitrescu "queue_id");
8685074e1d5SCristian Dumitrescu return;
8695074e1d5SCristian Dumitrescu }
8705074e1d5SCristian Dumitrescu
8715074e1d5SCristian Dumitrescu if (strcmp(tokens[t0 + 4], "bsz") != 0) {
8725074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
8735074e1d5SCristian Dumitrescu return;
8745074e1d5SCristian Dumitrescu }
8755074e1d5SCristian Dumitrescu
8765074e1d5SCristian Dumitrescu if (parser_read_uint32(¶ms.burst_size, tokens[t0 + 5])) {
8775074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID,
8785074e1d5SCristian Dumitrescu "burst_size");
8795074e1d5SCristian Dumitrescu return;
8805074e1d5SCristian Dumitrescu }
8815074e1d5SCristian Dumitrescu
8825074e1d5SCristian Dumitrescu t0 += 6;
8835074e1d5SCristian Dumitrescu
8845074e1d5SCristian Dumitrescu status = rte_swx_pipeline_port_out_config(p->p,
8855074e1d5SCristian Dumitrescu port_id,
8865074e1d5SCristian Dumitrescu "ethdev",
8875074e1d5SCristian Dumitrescu ¶ms);
88877a41301SCristian Dumitrescu } else if (strcmp(tokens[t0], "ring") == 0) {
88977a41301SCristian Dumitrescu struct rte_swx_port_ring_writer_params params;
89077a41301SCristian Dumitrescu struct ring *ring;
89177a41301SCristian Dumitrescu
89277a41301SCristian Dumitrescu if (n_tokens < t0 + 4) {
89377a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH,
89477a41301SCristian Dumitrescu "pipeline port out link");
89577a41301SCristian Dumitrescu return;
89677a41301SCristian Dumitrescu }
89777a41301SCristian Dumitrescu
89877a41301SCristian Dumitrescu ring = ring_find(obj, tokens[t0 + 1]);
89977a41301SCristian Dumitrescu if (!ring) {
90077a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID,
90177a41301SCristian Dumitrescu "ring_name");
90277a41301SCristian Dumitrescu return;
90377a41301SCristian Dumitrescu }
90477a41301SCristian Dumitrescu params.name = ring->name;
90577a41301SCristian Dumitrescu
90677a41301SCristian Dumitrescu if (strcmp(tokens[t0 + 2], "bsz") != 0) {
90777a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
90877a41301SCristian Dumitrescu return;
90977a41301SCristian Dumitrescu }
91077a41301SCristian Dumitrescu
91177a41301SCristian Dumitrescu if (parser_read_uint32(¶ms.burst_size, tokens[t0 + 3])) {
91277a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID,
91377a41301SCristian Dumitrescu "burst_size");
91477a41301SCristian Dumitrescu return;
91577a41301SCristian Dumitrescu }
91677a41301SCristian Dumitrescu
91777a41301SCristian Dumitrescu t0 += 4;
91877a41301SCristian Dumitrescu
91977a41301SCristian Dumitrescu status = rte_swx_pipeline_port_out_config(p->p,
92077a41301SCristian Dumitrescu port_id,
92177a41301SCristian Dumitrescu "ring",
92277a41301SCristian Dumitrescu ¶ms);
9235074e1d5SCristian Dumitrescu } else if (strcmp(tokens[t0], "sink") == 0) {
9245074e1d5SCristian Dumitrescu struct rte_swx_port_sink_params params;
9255074e1d5SCristian Dumitrescu
9265074e1d5SCristian Dumitrescu params.file_name = strcmp(tokens[t0 + 1], "none") ?
9275074e1d5SCristian Dumitrescu tokens[t0 + 1] : NULL;
9285074e1d5SCristian Dumitrescu
9295074e1d5SCristian Dumitrescu t0 += 2;
9305074e1d5SCristian Dumitrescu
9315074e1d5SCristian Dumitrescu status = rte_swx_pipeline_port_out_config(p->p,
9325074e1d5SCristian Dumitrescu port_id,
9335074e1d5SCristian Dumitrescu "sink",
9345074e1d5SCristian Dumitrescu ¶ms);
935e2b8dc52SVenkata Suresh Kumar P } else if (strcmp(tokens[t0], "tap") == 0) {
936e2b8dc52SVenkata Suresh Kumar P struct rte_swx_port_fd_writer_params params;
937e2b8dc52SVenkata Suresh Kumar P struct tap *tap;
938e2b8dc52SVenkata Suresh Kumar P
939e2b8dc52SVenkata Suresh Kumar P if (n_tokens < t0 + 4) {
940e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_ARG_MISMATCH,
941e2b8dc52SVenkata Suresh Kumar P "pipeline port out tap");
942e2b8dc52SVenkata Suresh Kumar P return;
943e2b8dc52SVenkata Suresh Kumar P }
944e2b8dc52SVenkata Suresh Kumar P
945e2b8dc52SVenkata Suresh Kumar P tap = tap_find(obj, tokens[t0 + 1]);
946e2b8dc52SVenkata Suresh Kumar P if (!tap) {
947e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_ARG_INVALID,
948e2b8dc52SVenkata Suresh Kumar P "tap_name");
949e2b8dc52SVenkata Suresh Kumar P return;
950e2b8dc52SVenkata Suresh Kumar P }
951e2b8dc52SVenkata Suresh Kumar P params.fd = tap->fd;
952e2b8dc52SVenkata Suresh Kumar P
953e2b8dc52SVenkata Suresh Kumar P if (strcmp(tokens[t0 + 2], "bsz") != 0) {
954e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
955e2b8dc52SVenkata Suresh Kumar P return;
956e2b8dc52SVenkata Suresh Kumar P }
957e2b8dc52SVenkata Suresh Kumar P
958e2b8dc52SVenkata Suresh Kumar P if (parser_read_uint32(¶ms.burst_size, tokens[t0 + 3])) {
959e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_ARG_INVALID,
960e2b8dc52SVenkata Suresh Kumar P "burst_size");
961e2b8dc52SVenkata Suresh Kumar P return;
962e2b8dc52SVenkata Suresh Kumar P }
963e2b8dc52SVenkata Suresh Kumar P
964e2b8dc52SVenkata Suresh Kumar P t0 += 4;
965e2b8dc52SVenkata Suresh Kumar P
966e2b8dc52SVenkata Suresh Kumar P status = rte_swx_pipeline_port_out_config(p->p,
967e2b8dc52SVenkata Suresh Kumar P port_id,
968e2b8dc52SVenkata Suresh Kumar P "fd",
969e2b8dc52SVenkata Suresh Kumar P ¶ms);
9705074e1d5SCristian Dumitrescu } else {
9715074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
9725074e1d5SCristian Dumitrescu return;
9735074e1d5SCristian Dumitrescu }
9745074e1d5SCristian Dumitrescu
9755074e1d5SCristian Dumitrescu if (status) {
9765074e1d5SCristian Dumitrescu snprintf(out, out_size, "port out error.");
9775074e1d5SCristian Dumitrescu return;
9785074e1d5SCristian Dumitrescu }
9795074e1d5SCristian Dumitrescu
9805074e1d5SCristian Dumitrescu if (n_tokens != t0) {
9815074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
9825074e1d5SCristian Dumitrescu return;
9835074e1d5SCristian Dumitrescu }
9845074e1d5SCristian Dumitrescu }
9855074e1d5SCristian Dumitrescu
9865074e1d5SCristian Dumitrescu static const char cmd_pipeline_build_help[] =
9875074e1d5SCristian Dumitrescu "pipeline <pipeline_name> build <spec_file>\n";
9885074e1d5SCristian Dumitrescu
9895074e1d5SCristian Dumitrescu static void
cmd_pipeline_build(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)9905074e1d5SCristian Dumitrescu cmd_pipeline_build(char **tokens,
9915074e1d5SCristian Dumitrescu uint32_t n_tokens,
9925074e1d5SCristian Dumitrescu char *out,
9935074e1d5SCristian Dumitrescu size_t out_size,
9945074e1d5SCristian Dumitrescu void *obj)
9955074e1d5SCristian Dumitrescu {
9965074e1d5SCristian Dumitrescu struct pipeline *p = NULL;
9975074e1d5SCristian Dumitrescu FILE *spec = NULL;
9985074e1d5SCristian Dumitrescu uint32_t err_line;
9995074e1d5SCristian Dumitrescu const char *err_msg;
10005074e1d5SCristian Dumitrescu int status;
10015074e1d5SCristian Dumitrescu
10025074e1d5SCristian Dumitrescu if (n_tokens != 4) {
10035074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
10045074e1d5SCristian Dumitrescu return;
10055074e1d5SCristian Dumitrescu }
10065074e1d5SCristian Dumitrescu
10075074e1d5SCristian Dumitrescu p = pipeline_find(obj, tokens[1]);
10085074e1d5SCristian Dumitrescu if (!p || p->ctl) {
10095074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
10105074e1d5SCristian Dumitrescu return;
10115074e1d5SCristian Dumitrescu }
10125074e1d5SCristian Dumitrescu
10135074e1d5SCristian Dumitrescu spec = fopen(tokens[3], "r");
10145074e1d5SCristian Dumitrescu if (!spec) {
10155074e1d5SCristian Dumitrescu snprintf(out, out_size, "Cannot open file %s.\n", tokens[3]);
10165074e1d5SCristian Dumitrescu return;
10175074e1d5SCristian Dumitrescu }
10185074e1d5SCristian Dumitrescu
10195074e1d5SCristian Dumitrescu status = rte_swx_pipeline_build_from_spec(p->p,
10205074e1d5SCristian Dumitrescu spec,
10215074e1d5SCristian Dumitrescu &err_line,
10225074e1d5SCristian Dumitrescu &err_msg);
10235074e1d5SCristian Dumitrescu fclose(spec);
10245074e1d5SCristian Dumitrescu if (status) {
10255074e1d5SCristian Dumitrescu snprintf(out, out_size, "Error %d at line %u: %s\n.",
10265074e1d5SCristian Dumitrescu status, err_line, err_msg);
10275074e1d5SCristian Dumitrescu return;
10285074e1d5SCristian Dumitrescu }
10295074e1d5SCristian Dumitrescu
10305074e1d5SCristian Dumitrescu p->ctl = rte_swx_ctl_pipeline_create(p->p);
10315074e1d5SCristian Dumitrescu if (!p->ctl) {
10325074e1d5SCristian Dumitrescu snprintf(out, out_size, "Pipeline control create failed.");
10335074e1d5SCristian Dumitrescu rte_swx_pipeline_free(p->p);
10345074e1d5SCristian Dumitrescu return;
10355074e1d5SCristian Dumitrescu }
10365074e1d5SCristian Dumitrescu }
10375074e1d5SCristian Dumitrescu
1038275ebefeSCristian Dumitrescu static void
table_entry_free(struct rte_swx_table_entry * entry)1039275ebefeSCristian Dumitrescu table_entry_free(struct rte_swx_table_entry *entry)
1040275ebefeSCristian Dumitrescu {
1041275ebefeSCristian Dumitrescu if (!entry)
1042275ebefeSCristian Dumitrescu return;
1043275ebefeSCristian Dumitrescu
1044275ebefeSCristian Dumitrescu free(entry->key);
1045275ebefeSCristian Dumitrescu free(entry->key_mask);
1046275ebefeSCristian Dumitrescu free(entry->action_data);
1047275ebefeSCristian Dumitrescu free(entry);
1048275ebefeSCristian Dumitrescu }
1049275ebefeSCristian Dumitrescu
105075129cebSChurchill Khangar #ifndef MAX_LINE_SIZE
105175129cebSChurchill Khangar #define MAX_LINE_SIZE 2048
105275129cebSChurchill Khangar #endif
105375129cebSChurchill Khangar
105475129cebSChurchill Khangar static int
pipeline_table_entries_add(struct rte_swx_ctl_pipeline * p,const char * table_name,FILE * file,uint32_t * file_line_number)105575129cebSChurchill Khangar pipeline_table_entries_add(struct rte_swx_ctl_pipeline *p,
105675129cebSChurchill Khangar const char *table_name,
105775129cebSChurchill Khangar FILE *file,
105875129cebSChurchill Khangar uint32_t *file_line_number)
105975129cebSChurchill Khangar {
106075129cebSChurchill Khangar char *line = NULL;
106175129cebSChurchill Khangar uint32_t line_id = 0;
106275129cebSChurchill Khangar int status = 0;
106375129cebSChurchill Khangar
106475129cebSChurchill Khangar /* Buffer allocation. */
106575129cebSChurchill Khangar line = malloc(MAX_LINE_SIZE);
106675129cebSChurchill Khangar if (!line)
106775129cebSChurchill Khangar return -ENOMEM;
106875129cebSChurchill Khangar
106975129cebSChurchill Khangar /* File read. */
107075129cebSChurchill Khangar for (line_id = 1; ; line_id++) {
107175129cebSChurchill Khangar struct rte_swx_table_entry *entry;
107275129cebSChurchill Khangar int is_blank_or_comment;
107375129cebSChurchill Khangar
107475129cebSChurchill Khangar if (fgets(line, MAX_LINE_SIZE, file) == NULL)
107575129cebSChurchill Khangar break;
107675129cebSChurchill Khangar
107775129cebSChurchill Khangar entry = rte_swx_ctl_pipeline_table_entry_read(p,
107875129cebSChurchill Khangar table_name,
107975129cebSChurchill Khangar line,
108075129cebSChurchill Khangar &is_blank_or_comment);
108175129cebSChurchill Khangar if (!entry) {
108275129cebSChurchill Khangar if (is_blank_or_comment)
108375129cebSChurchill Khangar continue;
108475129cebSChurchill Khangar
108575129cebSChurchill Khangar status = -EINVAL;
108675129cebSChurchill Khangar goto error;
108775129cebSChurchill Khangar }
108875129cebSChurchill Khangar
108975129cebSChurchill Khangar status = rte_swx_ctl_pipeline_table_entry_add(p,
109075129cebSChurchill Khangar table_name,
109175129cebSChurchill Khangar entry);
109275129cebSChurchill Khangar table_entry_free(entry);
109375129cebSChurchill Khangar if (status)
109475129cebSChurchill Khangar goto error;
109575129cebSChurchill Khangar }
109675129cebSChurchill Khangar
109775129cebSChurchill Khangar error:
109875129cebSChurchill Khangar free(line);
109975129cebSChurchill Khangar *file_line_number = line_id;
110075129cebSChurchill Khangar return status;
110175129cebSChurchill Khangar }
110275129cebSChurchill Khangar
110375129cebSChurchill Khangar static const char cmd_pipeline_table_add_help[] =
110475129cebSChurchill Khangar "pipeline <pipeline_name> table <table_name> add <file_name>\n";
11055074e1d5SCristian Dumitrescu
11065074e1d5SCristian Dumitrescu static void
cmd_pipeline_table_add(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)110775129cebSChurchill Khangar cmd_pipeline_table_add(char **tokens,
11085074e1d5SCristian Dumitrescu uint32_t n_tokens,
11095074e1d5SCristian Dumitrescu char *out,
11105074e1d5SCristian Dumitrescu size_t out_size,
11115074e1d5SCristian Dumitrescu void *obj)
11125074e1d5SCristian Dumitrescu {
11135074e1d5SCristian Dumitrescu struct pipeline *p;
111475129cebSChurchill Khangar char *pipeline_name, *table_name, *file_name;
111575129cebSChurchill Khangar FILE *file = NULL;
111675129cebSChurchill Khangar uint32_t file_line_number = 0;
11175074e1d5SCristian Dumitrescu int status;
11185074e1d5SCristian Dumitrescu
111975129cebSChurchill Khangar if (n_tokens != 6) {
11205074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
11215074e1d5SCristian Dumitrescu return;
11225074e1d5SCristian Dumitrescu }
11235074e1d5SCristian Dumitrescu
11245074e1d5SCristian Dumitrescu pipeline_name = tokens[1];
11255074e1d5SCristian Dumitrescu p = pipeline_find(obj, pipeline_name);
11265074e1d5SCristian Dumitrescu if (!p || !p->ctl) {
11275074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
11285074e1d5SCristian Dumitrescu return;
11295074e1d5SCristian Dumitrescu }
11305074e1d5SCristian Dumitrescu
113175129cebSChurchill Khangar table_name = tokens[3];
113275129cebSChurchill Khangar
113375129cebSChurchill Khangar file_name = tokens[5];
113475129cebSChurchill Khangar file = fopen(file_name, "r");
113575129cebSChurchill Khangar if (!file) {
113675129cebSChurchill Khangar snprintf(out, out_size, "Cannot open file %s.\n", file_name);
113775129cebSChurchill Khangar return;
113875129cebSChurchill Khangar }
113975129cebSChurchill Khangar
114075129cebSChurchill Khangar status = pipeline_table_entries_add(p->ctl,
114175129cebSChurchill Khangar table_name,
114275129cebSChurchill Khangar file,
114375129cebSChurchill Khangar &file_line_number);
114475129cebSChurchill Khangar if (status)
114575129cebSChurchill Khangar snprintf(out, out_size, "Invalid entry in file %s at line %u\n",
114675129cebSChurchill Khangar file_name,
114775129cebSChurchill Khangar file_line_number);
114875129cebSChurchill Khangar
114975129cebSChurchill Khangar fclose(file);
115075129cebSChurchill Khangar }
115175129cebSChurchill Khangar
115275129cebSChurchill Khangar static int
pipeline_table_entries_delete(struct rte_swx_ctl_pipeline * p,const char * table_name,FILE * file,uint32_t * file_line_number)115375129cebSChurchill Khangar pipeline_table_entries_delete(struct rte_swx_ctl_pipeline *p,
115475129cebSChurchill Khangar const char *table_name,
115575129cebSChurchill Khangar FILE *file,
115675129cebSChurchill Khangar uint32_t *file_line_number)
115775129cebSChurchill Khangar {
115875129cebSChurchill Khangar char *line = NULL;
115975129cebSChurchill Khangar uint32_t line_id = 0;
116075129cebSChurchill Khangar int status = 0;
116175129cebSChurchill Khangar
116275129cebSChurchill Khangar /* Buffer allocation. */
116375129cebSChurchill Khangar line = malloc(MAX_LINE_SIZE);
116475129cebSChurchill Khangar if (!line)
116575129cebSChurchill Khangar return -ENOMEM;
116675129cebSChurchill Khangar
116775129cebSChurchill Khangar /* File read. */
116875129cebSChurchill Khangar for (line_id = 1; ; line_id++) {
116975129cebSChurchill Khangar struct rte_swx_table_entry *entry;
117075129cebSChurchill Khangar int is_blank_or_comment;
117175129cebSChurchill Khangar
117275129cebSChurchill Khangar if (fgets(line, MAX_LINE_SIZE, file) == NULL)
117375129cebSChurchill Khangar break;
117475129cebSChurchill Khangar
117575129cebSChurchill Khangar entry = rte_swx_ctl_pipeline_table_entry_read(p,
117675129cebSChurchill Khangar table_name,
117775129cebSChurchill Khangar line,
117875129cebSChurchill Khangar &is_blank_or_comment);
117975129cebSChurchill Khangar if (!entry) {
118075129cebSChurchill Khangar if (is_blank_or_comment)
118175129cebSChurchill Khangar continue;
118275129cebSChurchill Khangar
118375129cebSChurchill Khangar status = -EINVAL;
118475129cebSChurchill Khangar goto error;
118575129cebSChurchill Khangar }
118675129cebSChurchill Khangar
118775129cebSChurchill Khangar status = rte_swx_ctl_pipeline_table_entry_delete(p,
118875129cebSChurchill Khangar table_name,
118975129cebSChurchill Khangar entry);
119075129cebSChurchill Khangar table_entry_free(entry);
119175129cebSChurchill Khangar if (status)
119275129cebSChurchill Khangar goto error;
119375129cebSChurchill Khangar }
119475129cebSChurchill Khangar
119575129cebSChurchill Khangar error:
119675129cebSChurchill Khangar *file_line_number = line_id;
119775129cebSChurchill Khangar free(line);
119875129cebSChurchill Khangar return status;
119975129cebSChurchill Khangar }
120075129cebSChurchill Khangar
120175129cebSChurchill Khangar static const char cmd_pipeline_table_delete_help[] =
120275129cebSChurchill Khangar "pipeline <pipeline_name> table <table_name> delete <file_name>\n";
120375129cebSChurchill Khangar
120475129cebSChurchill Khangar static void
cmd_pipeline_table_delete(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)120575129cebSChurchill Khangar cmd_pipeline_table_delete(char **tokens,
120675129cebSChurchill Khangar uint32_t n_tokens,
120775129cebSChurchill Khangar char *out,
120875129cebSChurchill Khangar size_t out_size,
120975129cebSChurchill Khangar void *obj)
121075129cebSChurchill Khangar {
121175129cebSChurchill Khangar struct pipeline *p;
121275129cebSChurchill Khangar char *pipeline_name, *table_name, *file_name;
121375129cebSChurchill Khangar FILE *file = NULL;
121475129cebSChurchill Khangar uint32_t file_line_number = 0;
121575129cebSChurchill Khangar int status;
121675129cebSChurchill Khangar
121775129cebSChurchill Khangar if (n_tokens != 6) {
121875129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
121975129cebSChurchill Khangar return;
122075129cebSChurchill Khangar }
122175129cebSChurchill Khangar
122275129cebSChurchill Khangar pipeline_name = tokens[1];
122375129cebSChurchill Khangar p = pipeline_find(obj, pipeline_name);
122475129cebSChurchill Khangar if (!p || !p->ctl) {
122575129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
12265074e1d5SCristian Dumitrescu return;
12275074e1d5SCristian Dumitrescu }
12285074e1d5SCristian Dumitrescu
12295074e1d5SCristian Dumitrescu table_name = tokens[3];
12305074e1d5SCristian Dumitrescu
123175129cebSChurchill Khangar file_name = tokens[5];
123275129cebSChurchill Khangar file = fopen(file_name, "r");
123375129cebSChurchill Khangar if (!file) {
123475129cebSChurchill Khangar snprintf(out, out_size, "Cannot open file %s.\n", file_name);
12355074e1d5SCristian Dumitrescu return;
12365074e1d5SCristian Dumitrescu }
12375074e1d5SCristian Dumitrescu
123875129cebSChurchill Khangar status = pipeline_table_entries_delete(p->ctl,
123975129cebSChurchill Khangar table_name,
124075129cebSChurchill Khangar file,
124175129cebSChurchill Khangar &file_line_number);
124275129cebSChurchill Khangar if (status)
124375129cebSChurchill Khangar snprintf(out, out_size, "Invalid entry in file %s at line %u\n",
124475129cebSChurchill Khangar file_name,
124575129cebSChurchill Khangar file_line_number);
12465074e1d5SCristian Dumitrescu
124775129cebSChurchill Khangar fclose(file);
12485074e1d5SCristian Dumitrescu }
12495074e1d5SCristian Dumitrescu
125075129cebSChurchill Khangar static int
pipeline_table_default_entry_add(struct rte_swx_ctl_pipeline * p,const char * table_name,FILE * file,uint32_t * file_line_number)125175129cebSChurchill Khangar pipeline_table_default_entry_add(struct rte_swx_ctl_pipeline *p,
125275129cebSChurchill Khangar const char *table_name,
125375129cebSChurchill Khangar FILE *file,
125475129cebSChurchill Khangar uint32_t *file_line_number)
125575129cebSChurchill Khangar {
125675129cebSChurchill Khangar char *line = NULL;
125775129cebSChurchill Khangar uint32_t line_id = 0;
125875129cebSChurchill Khangar int status = 0;
12595074e1d5SCristian Dumitrescu
12605074e1d5SCristian Dumitrescu /* Buffer allocation. */
126175129cebSChurchill Khangar line = malloc(MAX_LINE_SIZE);
126275129cebSChurchill Khangar if (!line)
126375129cebSChurchill Khangar return -ENOMEM;
12645074e1d5SCristian Dumitrescu
126575129cebSChurchill Khangar /* File read. */
12665074e1d5SCristian Dumitrescu for (line_id = 1; ; line_id++) {
12675074e1d5SCristian Dumitrescu struct rte_swx_table_entry *entry;
1268cff9a717SCristian Dumitrescu int is_blank_or_comment;
12695074e1d5SCristian Dumitrescu
127075129cebSChurchill Khangar if (fgets(line, MAX_LINE_SIZE, file) == NULL)
12715074e1d5SCristian Dumitrescu break;
12725074e1d5SCristian Dumitrescu
127375129cebSChurchill Khangar entry = rte_swx_ctl_pipeline_table_entry_read(p,
12745074e1d5SCristian Dumitrescu table_name,
1275cff9a717SCristian Dumitrescu line,
1276cff9a717SCristian Dumitrescu &is_blank_or_comment);
12775074e1d5SCristian Dumitrescu if (!entry) {
1278cff9a717SCristian Dumitrescu if (is_blank_or_comment)
1279cff9a717SCristian Dumitrescu continue;
1280cff9a717SCristian Dumitrescu
128175129cebSChurchill Khangar status = -EINVAL;
12825074e1d5SCristian Dumitrescu goto error;
12835074e1d5SCristian Dumitrescu }
12845074e1d5SCristian Dumitrescu
128575129cebSChurchill Khangar status = rte_swx_ctl_pipeline_table_default_entry_add(p,
12865074e1d5SCristian Dumitrescu table_name,
12875074e1d5SCristian Dumitrescu entry);
1288275ebefeSCristian Dumitrescu table_entry_free(entry);
128975129cebSChurchill Khangar if (status)
12905074e1d5SCristian Dumitrescu goto error;
12915074e1d5SCristian Dumitrescu }
129275129cebSChurchill Khangar
129375129cebSChurchill Khangar error:
129475129cebSChurchill Khangar *file_line_number = line_id;
129575129cebSChurchill Khangar free(line);
129675129cebSChurchill Khangar return status;
12975074e1d5SCristian Dumitrescu }
12985074e1d5SCristian Dumitrescu
129975129cebSChurchill Khangar static const char cmd_pipeline_table_default_help[] =
130075129cebSChurchill Khangar "pipeline <pipeline_name> table <table_name> default <file_name>\n";
13015074e1d5SCristian Dumitrescu
130275129cebSChurchill Khangar static void
cmd_pipeline_table_default(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)130375129cebSChurchill Khangar cmd_pipeline_table_default(char **tokens,
130475129cebSChurchill Khangar uint32_t n_tokens,
130575129cebSChurchill Khangar char *out,
130675129cebSChurchill Khangar size_t out_size,
130775129cebSChurchill Khangar void *obj)
130875129cebSChurchill Khangar {
130975129cebSChurchill Khangar struct pipeline *p;
131075129cebSChurchill Khangar char *pipeline_name, *table_name, *file_name;
131175129cebSChurchill Khangar FILE *file = NULL;
131275129cebSChurchill Khangar uint32_t file_line_number = 0;
131375129cebSChurchill Khangar int status;
13145074e1d5SCristian Dumitrescu
131575129cebSChurchill Khangar if (n_tokens != 6) {
131675129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
131775129cebSChurchill Khangar return;
131875129cebSChurchill Khangar }
13195074e1d5SCristian Dumitrescu
132075129cebSChurchill Khangar pipeline_name = tokens[1];
132175129cebSChurchill Khangar p = pipeline_find(obj, pipeline_name);
132275129cebSChurchill Khangar if (!p || !p->ctl) {
132375129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
132475129cebSChurchill Khangar return;
132575129cebSChurchill Khangar }
132675129cebSChurchill Khangar
132775129cebSChurchill Khangar table_name = tokens[3];
132875129cebSChurchill Khangar
132975129cebSChurchill Khangar file_name = tokens[5];
133075129cebSChurchill Khangar file = fopen(file_name, "r");
133175129cebSChurchill Khangar if (!file) {
133275129cebSChurchill Khangar snprintf(out, out_size, "Cannot open file %s.\n", file_name);
133375129cebSChurchill Khangar return;
133475129cebSChurchill Khangar }
133575129cebSChurchill Khangar
133675129cebSChurchill Khangar status = pipeline_table_default_entry_add(p->ctl,
13375074e1d5SCristian Dumitrescu table_name,
133875129cebSChurchill Khangar file,
133975129cebSChurchill Khangar &file_line_number);
134075129cebSChurchill Khangar if (status)
134175129cebSChurchill Khangar snprintf(out, out_size, "Invalid entry in file %s at line %u\n",
134275129cebSChurchill Khangar file_name,
134375129cebSChurchill Khangar file_line_number);
1344cff9a717SCristian Dumitrescu
134575129cebSChurchill Khangar fclose(file);
13465074e1d5SCristian Dumitrescu }
13475074e1d5SCristian Dumitrescu
134875129cebSChurchill Khangar static const char cmd_pipeline_table_show_help[] =
1349*a4c1146cSCristian Dumitrescu "pipeline <pipeline_name> table <table_name> show [filename]\n";
135075129cebSChurchill Khangar
135175129cebSChurchill Khangar static void
cmd_pipeline_table_show(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)135275129cebSChurchill Khangar cmd_pipeline_table_show(char **tokens,
135375129cebSChurchill Khangar uint32_t n_tokens,
135475129cebSChurchill Khangar char *out,
135575129cebSChurchill Khangar size_t out_size,
135675129cebSChurchill Khangar void *obj)
135775129cebSChurchill Khangar {
135875129cebSChurchill Khangar struct pipeline *p;
135975129cebSChurchill Khangar char *pipeline_name, *table_name;
1360*a4c1146cSCristian Dumitrescu FILE *file = NULL;
136175129cebSChurchill Khangar int status;
136275129cebSChurchill Khangar
1363*a4c1146cSCristian Dumitrescu if (n_tokens != 5 && n_tokens != 6) {
136475129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
136575129cebSChurchill Khangar return;
13665074e1d5SCristian Dumitrescu }
13675074e1d5SCristian Dumitrescu
136875129cebSChurchill Khangar pipeline_name = tokens[1];
136975129cebSChurchill Khangar p = pipeline_find(obj, pipeline_name);
137075129cebSChurchill Khangar if (!p || !p->ctl) {
137175129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
137275129cebSChurchill Khangar return;
13735074e1d5SCristian Dumitrescu }
13745074e1d5SCristian Dumitrescu
137575129cebSChurchill Khangar table_name = tokens[3];
1376*a4c1146cSCristian Dumitrescu file = (n_tokens == 6) ? fopen(tokens[5], "w") : stdout;
1377*a4c1146cSCristian Dumitrescu if (!file) {
1378*a4c1146cSCristian Dumitrescu snprintf(out, out_size, "Cannot open file %s.\n", tokens[5]);
1379*a4c1146cSCristian Dumitrescu return;
1380*a4c1146cSCristian Dumitrescu }
1381*a4c1146cSCristian Dumitrescu
1382*a4c1146cSCristian Dumitrescu status = rte_swx_ctl_pipeline_table_fprintf(file, p->ctl, table_name);
138375129cebSChurchill Khangar if (status)
138475129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "table_name");
1385*a4c1146cSCristian Dumitrescu
1386*a4c1146cSCristian Dumitrescu if (file)
1387*a4c1146cSCristian Dumitrescu fclose(file);
13885074e1d5SCristian Dumitrescu }
138975129cebSChurchill Khangar
1390598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_group_add_help[] =
1391598fe0ddSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> group add\n";
1392598fe0ddSCristian Dumitrescu
1393598fe0ddSCristian Dumitrescu static void
cmd_pipeline_selector_group_add(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)1394598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_add(char **tokens,
1395598fe0ddSCristian Dumitrescu uint32_t n_tokens,
1396598fe0ddSCristian Dumitrescu char *out,
1397598fe0ddSCristian Dumitrescu size_t out_size,
1398598fe0ddSCristian Dumitrescu void *obj)
1399598fe0ddSCristian Dumitrescu {
1400598fe0ddSCristian Dumitrescu struct pipeline *p;
1401598fe0ddSCristian Dumitrescu char *pipeline_name, *selector_name;
1402598fe0ddSCristian Dumitrescu uint32_t group_id;
1403598fe0ddSCristian Dumitrescu int status;
1404598fe0ddSCristian Dumitrescu
1405598fe0ddSCristian Dumitrescu if (n_tokens != 6) {
1406598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1407598fe0ddSCristian Dumitrescu return;
1408598fe0ddSCristian Dumitrescu }
1409598fe0ddSCristian Dumitrescu
1410598fe0ddSCristian Dumitrescu pipeline_name = tokens[1];
1411598fe0ddSCristian Dumitrescu p = pipeline_find(obj, pipeline_name);
1412598fe0ddSCristian Dumitrescu if (!p || !p->ctl) {
1413598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1414598fe0ddSCristian Dumitrescu return;
1415598fe0ddSCristian Dumitrescu }
1416598fe0ddSCristian Dumitrescu
1417598fe0ddSCristian Dumitrescu if (strcmp(tokens[2], "selector") != 0) {
1418598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector");
1419598fe0ddSCristian Dumitrescu return;
1420598fe0ddSCristian Dumitrescu }
1421598fe0ddSCristian Dumitrescu
1422598fe0ddSCristian Dumitrescu selector_name = tokens[3];
1423598fe0ddSCristian Dumitrescu
1424598fe0ddSCristian Dumitrescu if (strcmp(tokens[4], "group") ||
1425598fe0ddSCristian Dumitrescu strcmp(tokens[5], "add")) {
1426598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group add");
1427598fe0ddSCristian Dumitrescu return;
1428598fe0ddSCristian Dumitrescu }
1429598fe0ddSCristian Dumitrescu
1430598fe0ddSCristian Dumitrescu status = rte_swx_ctl_pipeline_selector_group_add(p->ctl,
1431598fe0ddSCristian Dumitrescu selector_name,
1432598fe0ddSCristian Dumitrescu &group_id);
1433598fe0ddSCristian Dumitrescu if (status)
1434598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1435598fe0ddSCristian Dumitrescu else
1436598fe0ddSCristian Dumitrescu snprintf(out, out_size, "Group ID: %u\n", group_id);
1437598fe0ddSCristian Dumitrescu }
1438598fe0ddSCristian Dumitrescu
1439598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_group_delete_help[] =
1440598fe0ddSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> group delete <group_id>\n";
1441598fe0ddSCristian Dumitrescu
1442598fe0ddSCristian Dumitrescu static void
cmd_pipeline_selector_group_delete(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)1443598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_delete(char **tokens,
1444598fe0ddSCristian Dumitrescu uint32_t n_tokens,
1445598fe0ddSCristian Dumitrescu char *out,
1446598fe0ddSCristian Dumitrescu size_t out_size,
1447598fe0ddSCristian Dumitrescu void *obj)
1448598fe0ddSCristian Dumitrescu {
1449598fe0ddSCristian Dumitrescu struct pipeline *p;
1450598fe0ddSCristian Dumitrescu char *pipeline_name, *selector_name;
1451598fe0ddSCristian Dumitrescu uint32_t group_id;
1452598fe0ddSCristian Dumitrescu int status;
1453598fe0ddSCristian Dumitrescu
1454598fe0ddSCristian Dumitrescu if (n_tokens != 7) {
1455598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1456598fe0ddSCristian Dumitrescu return;
1457598fe0ddSCristian Dumitrescu }
1458598fe0ddSCristian Dumitrescu
1459598fe0ddSCristian Dumitrescu pipeline_name = tokens[1];
1460598fe0ddSCristian Dumitrescu p = pipeline_find(obj, pipeline_name);
1461598fe0ddSCristian Dumitrescu if (!p || !p->ctl) {
1462598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1463598fe0ddSCristian Dumitrescu return;
1464598fe0ddSCristian Dumitrescu }
1465598fe0ddSCristian Dumitrescu
1466598fe0ddSCristian Dumitrescu if (strcmp(tokens[2], "selector") != 0) {
1467598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector");
1468598fe0ddSCristian Dumitrescu return;
1469598fe0ddSCristian Dumitrescu }
1470598fe0ddSCristian Dumitrescu
1471598fe0ddSCristian Dumitrescu selector_name = tokens[3];
1472598fe0ddSCristian Dumitrescu
1473598fe0ddSCristian Dumitrescu if (strcmp(tokens[4], "group") ||
1474598fe0ddSCristian Dumitrescu strcmp(tokens[5], "delete")) {
1475598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group delete");
1476598fe0ddSCristian Dumitrescu return;
1477598fe0ddSCristian Dumitrescu }
1478598fe0ddSCristian Dumitrescu
1479598fe0ddSCristian Dumitrescu if (parser_read_uint32(&group_id, tokens[6]) != 0) {
1480598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "group_id");
1481598fe0ddSCristian Dumitrescu return;
1482598fe0ddSCristian Dumitrescu }
1483598fe0ddSCristian Dumitrescu
1484598fe0ddSCristian Dumitrescu status = rte_swx_ctl_pipeline_selector_group_delete(p->ctl,
1485598fe0ddSCristian Dumitrescu selector_name,
1486598fe0ddSCristian Dumitrescu group_id);
1487598fe0ddSCristian Dumitrescu if (status)
1488598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1489598fe0ddSCristian Dumitrescu }
1490598fe0ddSCristian Dumitrescu
1491598fe0ddSCristian Dumitrescu #define GROUP_MEMBER_INFO_TOKENS_MAX 6
1492598fe0ddSCristian Dumitrescu
1493598fe0ddSCristian Dumitrescu static int
token_is_comment(const char * token)1494598fe0ddSCristian Dumitrescu token_is_comment(const char *token)
1495598fe0ddSCristian Dumitrescu {
1496598fe0ddSCristian Dumitrescu if ((token[0] == '#') ||
1497598fe0ddSCristian Dumitrescu (token[0] == ';') ||
1498598fe0ddSCristian Dumitrescu ((token[0] == '/') && (token[1] == '/')))
1499598fe0ddSCristian Dumitrescu return 1; /* TRUE. */
1500598fe0ddSCristian Dumitrescu
1501598fe0ddSCristian Dumitrescu return 0; /* FALSE. */
1502598fe0ddSCristian Dumitrescu }
1503598fe0ddSCristian Dumitrescu
1504598fe0ddSCristian Dumitrescu static int
pipeline_selector_group_member_read(const char * string,uint32_t * group_id,uint32_t * member_id,uint32_t * weight,int * is_blank_or_comment)1505598fe0ddSCristian Dumitrescu pipeline_selector_group_member_read(const char *string,
1506598fe0ddSCristian Dumitrescu uint32_t *group_id,
1507598fe0ddSCristian Dumitrescu uint32_t *member_id,
1508598fe0ddSCristian Dumitrescu uint32_t *weight,
1509598fe0ddSCristian Dumitrescu int *is_blank_or_comment)
1510598fe0ddSCristian Dumitrescu {
1511598fe0ddSCristian Dumitrescu char *token_array[GROUP_MEMBER_INFO_TOKENS_MAX], **tokens;
1512598fe0ddSCristian Dumitrescu char *s0 = NULL, *s;
151300b67591SAli Alnubani uint32_t n_tokens = 0, group_id_val = 0, member_id_val = 0, weight_val = 0;
1514598fe0ddSCristian Dumitrescu int blank_or_comment = 0;
1515598fe0ddSCristian Dumitrescu
1516598fe0ddSCristian Dumitrescu /* Check input arguments. */
1517598fe0ddSCristian Dumitrescu if (!string || !string[0])
1518598fe0ddSCristian Dumitrescu goto error;
1519598fe0ddSCristian Dumitrescu
1520598fe0ddSCristian Dumitrescu /* Memory allocation. */
1521598fe0ddSCristian Dumitrescu s0 = strdup(string);
1522598fe0ddSCristian Dumitrescu if (!s0)
1523598fe0ddSCristian Dumitrescu goto error;
1524598fe0ddSCristian Dumitrescu
1525598fe0ddSCristian Dumitrescu /* Parse the string into tokens. */
1526598fe0ddSCristian Dumitrescu for (s = s0; ; ) {
1527598fe0ddSCristian Dumitrescu char *token;
1528598fe0ddSCristian Dumitrescu
1529598fe0ddSCristian Dumitrescu token = strtok_r(s, " \f\n\r\t\v", &s);
1530598fe0ddSCristian Dumitrescu if (!token || token_is_comment(token))
1531598fe0ddSCristian Dumitrescu break;
1532598fe0ddSCristian Dumitrescu
1533cfcc7bf8SCristian Dumitrescu if (n_tokens >= GROUP_MEMBER_INFO_TOKENS_MAX)
1534598fe0ddSCristian Dumitrescu goto error;
1535598fe0ddSCristian Dumitrescu
1536598fe0ddSCristian Dumitrescu token_array[n_tokens] = token;
1537598fe0ddSCristian Dumitrescu n_tokens++;
1538598fe0ddSCristian Dumitrescu }
1539598fe0ddSCristian Dumitrescu
1540598fe0ddSCristian Dumitrescu if (!n_tokens) {
1541598fe0ddSCristian Dumitrescu blank_or_comment = 1;
1542598fe0ddSCristian Dumitrescu goto error;
1543598fe0ddSCristian Dumitrescu }
1544598fe0ddSCristian Dumitrescu
1545598fe0ddSCristian Dumitrescu tokens = token_array;
1546598fe0ddSCristian Dumitrescu
1547598fe0ddSCristian Dumitrescu if (n_tokens < 4 ||
1548598fe0ddSCristian Dumitrescu strcmp(tokens[0], "group") ||
1549598fe0ddSCristian Dumitrescu strcmp(tokens[2], "member"))
1550598fe0ddSCristian Dumitrescu goto error;
1551598fe0ddSCristian Dumitrescu
1552598fe0ddSCristian Dumitrescu /*
1553598fe0ddSCristian Dumitrescu * Group ID.
1554598fe0ddSCristian Dumitrescu */
1555598fe0ddSCristian Dumitrescu if (parser_read_uint32(&group_id_val, tokens[1]) != 0)
1556598fe0ddSCristian Dumitrescu goto error;
1557598fe0ddSCristian Dumitrescu *group_id = group_id_val;
1558598fe0ddSCristian Dumitrescu
1559598fe0ddSCristian Dumitrescu /*
1560598fe0ddSCristian Dumitrescu * Member ID.
1561598fe0ddSCristian Dumitrescu */
1562598fe0ddSCristian Dumitrescu if (parser_read_uint32(&member_id_val, tokens[3]) != 0)
1563598fe0ddSCristian Dumitrescu goto error;
1564598fe0ddSCristian Dumitrescu *member_id = member_id_val;
1565598fe0ddSCristian Dumitrescu
1566598fe0ddSCristian Dumitrescu tokens += 4;
1567598fe0ddSCristian Dumitrescu n_tokens -= 4;
1568598fe0ddSCristian Dumitrescu
1569598fe0ddSCristian Dumitrescu /*
1570598fe0ddSCristian Dumitrescu * Weight.
1571598fe0ddSCristian Dumitrescu */
1572598fe0ddSCristian Dumitrescu if (n_tokens && !strcmp(tokens[0], "weight")) {
1573598fe0ddSCristian Dumitrescu if (n_tokens < 2)
1574598fe0ddSCristian Dumitrescu goto error;
1575598fe0ddSCristian Dumitrescu
1576598fe0ddSCristian Dumitrescu if (parser_read_uint32(&weight_val, tokens[1]) != 0)
1577598fe0ddSCristian Dumitrescu goto error;
1578598fe0ddSCristian Dumitrescu *weight = weight_val;
1579598fe0ddSCristian Dumitrescu
1580598fe0ddSCristian Dumitrescu tokens += 2;
1581598fe0ddSCristian Dumitrescu n_tokens -= 2;
1582598fe0ddSCristian Dumitrescu }
1583598fe0ddSCristian Dumitrescu
1584598fe0ddSCristian Dumitrescu if (n_tokens)
1585598fe0ddSCristian Dumitrescu goto error;
1586598fe0ddSCristian Dumitrescu
1587598fe0ddSCristian Dumitrescu free(s0);
1588598fe0ddSCristian Dumitrescu return 0;
1589598fe0ddSCristian Dumitrescu
1590598fe0ddSCristian Dumitrescu error:
1591598fe0ddSCristian Dumitrescu free(s0);
1592598fe0ddSCristian Dumitrescu if (is_blank_or_comment)
1593598fe0ddSCristian Dumitrescu *is_blank_or_comment = blank_or_comment;
1594598fe0ddSCristian Dumitrescu return -EINVAL;
1595598fe0ddSCristian Dumitrescu }
1596598fe0ddSCristian Dumitrescu
1597598fe0ddSCristian Dumitrescu static int
pipeline_selector_group_members_add(struct rte_swx_ctl_pipeline * p,const char * selector_name,FILE * file,uint32_t * file_line_number)1598598fe0ddSCristian Dumitrescu pipeline_selector_group_members_add(struct rte_swx_ctl_pipeline *p,
1599598fe0ddSCristian Dumitrescu const char *selector_name,
1600598fe0ddSCristian Dumitrescu FILE *file,
1601598fe0ddSCristian Dumitrescu uint32_t *file_line_number)
1602598fe0ddSCristian Dumitrescu {
1603598fe0ddSCristian Dumitrescu char *line = NULL;
1604598fe0ddSCristian Dumitrescu uint32_t line_id = 0;
1605598fe0ddSCristian Dumitrescu int status = 0;
1606598fe0ddSCristian Dumitrescu
1607598fe0ddSCristian Dumitrescu /* Buffer allocation. */
1608598fe0ddSCristian Dumitrescu line = malloc(MAX_LINE_SIZE);
1609598fe0ddSCristian Dumitrescu if (!line)
1610598fe0ddSCristian Dumitrescu return -ENOMEM;
1611598fe0ddSCristian Dumitrescu
1612598fe0ddSCristian Dumitrescu /* File read. */
1613598fe0ddSCristian Dumitrescu for (line_id = 1; ; line_id++) {
1614598fe0ddSCristian Dumitrescu uint32_t group_id, member_id, weight;
1615598fe0ddSCristian Dumitrescu int is_blank_or_comment;
1616598fe0ddSCristian Dumitrescu
1617598fe0ddSCristian Dumitrescu if (fgets(line, MAX_LINE_SIZE, file) == NULL)
1618598fe0ddSCristian Dumitrescu break;
1619598fe0ddSCristian Dumitrescu
1620598fe0ddSCristian Dumitrescu status = pipeline_selector_group_member_read(line,
1621598fe0ddSCristian Dumitrescu &group_id,
1622598fe0ddSCristian Dumitrescu &member_id,
1623598fe0ddSCristian Dumitrescu &weight,
1624598fe0ddSCristian Dumitrescu &is_blank_or_comment);
1625598fe0ddSCristian Dumitrescu if (status) {
1626598fe0ddSCristian Dumitrescu if (is_blank_or_comment)
1627598fe0ddSCristian Dumitrescu continue;
1628598fe0ddSCristian Dumitrescu
1629598fe0ddSCristian Dumitrescu goto error;
1630598fe0ddSCristian Dumitrescu }
1631598fe0ddSCristian Dumitrescu
1632598fe0ddSCristian Dumitrescu status = rte_swx_ctl_pipeline_selector_group_member_add(p,
1633598fe0ddSCristian Dumitrescu selector_name,
1634598fe0ddSCristian Dumitrescu group_id,
1635598fe0ddSCristian Dumitrescu member_id,
1636598fe0ddSCristian Dumitrescu weight);
1637598fe0ddSCristian Dumitrescu if (status)
1638598fe0ddSCristian Dumitrescu goto error;
1639598fe0ddSCristian Dumitrescu }
1640598fe0ddSCristian Dumitrescu
1641598fe0ddSCristian Dumitrescu error:
1642598fe0ddSCristian Dumitrescu free(line);
1643598fe0ddSCristian Dumitrescu *file_line_number = line_id;
1644598fe0ddSCristian Dumitrescu return status;
1645598fe0ddSCristian Dumitrescu }
1646598fe0ddSCristian Dumitrescu
1647598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_group_member_add_help[] =
1648598fe0ddSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> group member add <file_name>";
1649598fe0ddSCristian Dumitrescu
1650598fe0ddSCristian Dumitrescu static void
cmd_pipeline_selector_group_member_add(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)1651598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_add(char **tokens,
1652598fe0ddSCristian Dumitrescu uint32_t n_tokens,
1653598fe0ddSCristian Dumitrescu char *out,
1654598fe0ddSCristian Dumitrescu size_t out_size,
1655598fe0ddSCristian Dumitrescu void *obj)
1656598fe0ddSCristian Dumitrescu {
1657598fe0ddSCristian Dumitrescu struct pipeline *p;
1658598fe0ddSCristian Dumitrescu char *pipeline_name, *selector_name, *file_name;
1659598fe0ddSCristian Dumitrescu FILE *file = NULL;
1660598fe0ddSCristian Dumitrescu uint32_t file_line_number = 0;
1661598fe0ddSCristian Dumitrescu int status;
1662598fe0ddSCristian Dumitrescu
1663598fe0ddSCristian Dumitrescu if (n_tokens != 8) {
1664598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1665598fe0ddSCristian Dumitrescu return;
1666598fe0ddSCristian Dumitrescu }
1667598fe0ddSCristian Dumitrescu
1668598fe0ddSCristian Dumitrescu pipeline_name = tokens[1];
1669598fe0ddSCristian Dumitrescu p = pipeline_find(obj, pipeline_name);
1670598fe0ddSCristian Dumitrescu if (!p || !p->ctl) {
1671598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1672598fe0ddSCristian Dumitrescu return;
1673598fe0ddSCristian Dumitrescu }
1674598fe0ddSCristian Dumitrescu
1675598fe0ddSCristian Dumitrescu if (strcmp(tokens[2], "selector") != 0) {
1676598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector");
1677598fe0ddSCristian Dumitrescu return;
1678598fe0ddSCristian Dumitrescu }
1679598fe0ddSCristian Dumitrescu
1680598fe0ddSCristian Dumitrescu selector_name = tokens[3];
1681598fe0ddSCristian Dumitrescu
1682598fe0ddSCristian Dumitrescu if (strcmp(tokens[4], "group") ||
1683598fe0ddSCristian Dumitrescu strcmp(tokens[5], "member") ||
1684598fe0ddSCristian Dumitrescu strcmp(tokens[6], "add")) {
1685598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group member add");
1686598fe0ddSCristian Dumitrescu return;
1687598fe0ddSCristian Dumitrescu }
1688598fe0ddSCristian Dumitrescu
1689598fe0ddSCristian Dumitrescu file_name = tokens[7];
1690598fe0ddSCristian Dumitrescu file = fopen(file_name, "r");
1691598fe0ddSCristian Dumitrescu if (!file) {
1692598fe0ddSCristian Dumitrescu snprintf(out, out_size, "Cannot open file %s.\n", file_name);
1693598fe0ddSCristian Dumitrescu return;
1694598fe0ddSCristian Dumitrescu }
1695598fe0ddSCristian Dumitrescu
1696598fe0ddSCristian Dumitrescu status = pipeline_selector_group_members_add(p->ctl,
1697598fe0ddSCristian Dumitrescu selector_name,
1698598fe0ddSCristian Dumitrescu file,
1699598fe0ddSCristian Dumitrescu &file_line_number);
1700598fe0ddSCristian Dumitrescu if (status)
1701598fe0ddSCristian Dumitrescu snprintf(out, out_size, "Invalid entry in file %s at line %u\n",
1702598fe0ddSCristian Dumitrescu file_name,
1703598fe0ddSCristian Dumitrescu file_line_number);
1704598fe0ddSCristian Dumitrescu
1705598fe0ddSCristian Dumitrescu fclose(file);
1706598fe0ddSCristian Dumitrescu }
1707598fe0ddSCristian Dumitrescu
1708598fe0ddSCristian Dumitrescu static int
pipeline_selector_group_members_delete(struct rte_swx_ctl_pipeline * p,const char * selector_name,FILE * file,uint32_t * file_line_number)1709598fe0ddSCristian Dumitrescu pipeline_selector_group_members_delete(struct rte_swx_ctl_pipeline *p,
1710598fe0ddSCristian Dumitrescu const char *selector_name,
1711598fe0ddSCristian Dumitrescu FILE *file,
1712598fe0ddSCristian Dumitrescu uint32_t *file_line_number)
1713598fe0ddSCristian Dumitrescu {
1714598fe0ddSCristian Dumitrescu char *line = NULL;
1715598fe0ddSCristian Dumitrescu uint32_t line_id = 0;
1716598fe0ddSCristian Dumitrescu int status = 0;
1717598fe0ddSCristian Dumitrescu
1718598fe0ddSCristian Dumitrescu /* Buffer allocation. */
1719598fe0ddSCristian Dumitrescu line = malloc(MAX_LINE_SIZE);
1720598fe0ddSCristian Dumitrescu if (!line)
1721598fe0ddSCristian Dumitrescu return -ENOMEM;
1722598fe0ddSCristian Dumitrescu
1723598fe0ddSCristian Dumitrescu /* File read. */
1724598fe0ddSCristian Dumitrescu for (line_id = 1; ; line_id++) {
1725598fe0ddSCristian Dumitrescu uint32_t group_id, member_id, weight;
1726598fe0ddSCristian Dumitrescu int is_blank_or_comment;
1727598fe0ddSCristian Dumitrescu
1728598fe0ddSCristian Dumitrescu if (fgets(line, MAX_LINE_SIZE, file) == NULL)
1729598fe0ddSCristian Dumitrescu break;
1730598fe0ddSCristian Dumitrescu
1731598fe0ddSCristian Dumitrescu status = pipeline_selector_group_member_read(line,
1732598fe0ddSCristian Dumitrescu &group_id,
1733598fe0ddSCristian Dumitrescu &member_id,
1734598fe0ddSCristian Dumitrescu &weight,
1735598fe0ddSCristian Dumitrescu &is_blank_or_comment);
1736598fe0ddSCristian Dumitrescu if (status) {
1737598fe0ddSCristian Dumitrescu if (is_blank_or_comment)
1738598fe0ddSCristian Dumitrescu continue;
1739598fe0ddSCristian Dumitrescu
1740598fe0ddSCristian Dumitrescu goto error;
1741598fe0ddSCristian Dumitrescu }
1742598fe0ddSCristian Dumitrescu
1743598fe0ddSCristian Dumitrescu status = rte_swx_ctl_pipeline_selector_group_member_delete(p,
1744598fe0ddSCristian Dumitrescu selector_name,
1745598fe0ddSCristian Dumitrescu group_id,
1746598fe0ddSCristian Dumitrescu member_id);
1747598fe0ddSCristian Dumitrescu if (status)
1748598fe0ddSCristian Dumitrescu goto error;
1749598fe0ddSCristian Dumitrescu }
1750598fe0ddSCristian Dumitrescu
1751598fe0ddSCristian Dumitrescu error:
1752598fe0ddSCristian Dumitrescu free(line);
1753598fe0ddSCristian Dumitrescu *file_line_number = line_id;
1754598fe0ddSCristian Dumitrescu return status;
1755598fe0ddSCristian Dumitrescu }
1756598fe0ddSCristian Dumitrescu
1757598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_group_member_delete_help[] =
1758598fe0ddSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> group member delete <file_name>";
1759598fe0ddSCristian Dumitrescu
1760598fe0ddSCristian Dumitrescu static void
cmd_pipeline_selector_group_member_delete(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)1761598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_delete(char **tokens,
1762598fe0ddSCristian Dumitrescu uint32_t n_tokens,
1763598fe0ddSCristian Dumitrescu char *out,
1764598fe0ddSCristian Dumitrescu size_t out_size,
1765598fe0ddSCristian Dumitrescu void *obj)
1766598fe0ddSCristian Dumitrescu {
1767598fe0ddSCristian Dumitrescu struct pipeline *p;
1768598fe0ddSCristian Dumitrescu char *pipeline_name, *selector_name, *file_name;
1769598fe0ddSCristian Dumitrescu FILE *file = NULL;
1770598fe0ddSCristian Dumitrescu uint32_t file_line_number = 0;
1771598fe0ddSCristian Dumitrescu int status;
1772598fe0ddSCristian Dumitrescu
1773598fe0ddSCristian Dumitrescu if (n_tokens != 8) {
1774598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1775598fe0ddSCristian Dumitrescu return;
1776598fe0ddSCristian Dumitrescu }
1777598fe0ddSCristian Dumitrescu
1778598fe0ddSCristian Dumitrescu pipeline_name = tokens[1];
1779598fe0ddSCristian Dumitrescu p = pipeline_find(obj, pipeline_name);
1780598fe0ddSCristian Dumitrescu if (!p || !p->ctl) {
1781598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1782598fe0ddSCristian Dumitrescu return;
1783598fe0ddSCristian Dumitrescu }
1784598fe0ddSCristian Dumitrescu
1785598fe0ddSCristian Dumitrescu if (strcmp(tokens[2], "selector") != 0) {
1786598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector");
1787598fe0ddSCristian Dumitrescu return;
1788598fe0ddSCristian Dumitrescu }
1789598fe0ddSCristian Dumitrescu
1790598fe0ddSCristian Dumitrescu selector_name = tokens[3];
1791598fe0ddSCristian Dumitrescu
1792598fe0ddSCristian Dumitrescu if (strcmp(tokens[4], "group") ||
1793598fe0ddSCristian Dumitrescu strcmp(tokens[5], "member") ||
1794598fe0ddSCristian Dumitrescu strcmp(tokens[6], "delete")) {
1795598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group member delete");
1796598fe0ddSCristian Dumitrescu return;
1797598fe0ddSCristian Dumitrescu }
1798598fe0ddSCristian Dumitrescu
1799598fe0ddSCristian Dumitrescu file_name = tokens[7];
1800598fe0ddSCristian Dumitrescu file = fopen(file_name, "r");
1801598fe0ddSCristian Dumitrescu if (!file) {
1802598fe0ddSCristian Dumitrescu snprintf(out, out_size, "Cannot open file %s.\n", file_name);
1803598fe0ddSCristian Dumitrescu return;
1804598fe0ddSCristian Dumitrescu }
1805598fe0ddSCristian Dumitrescu
1806598fe0ddSCristian Dumitrescu status = pipeline_selector_group_members_delete(p->ctl,
1807598fe0ddSCristian Dumitrescu selector_name,
1808598fe0ddSCristian Dumitrescu file,
1809598fe0ddSCristian Dumitrescu &file_line_number);
1810598fe0ddSCristian Dumitrescu if (status)
1811598fe0ddSCristian Dumitrescu snprintf(out, out_size, "Invalid entry in file %s at line %u\n",
1812598fe0ddSCristian Dumitrescu file_name,
1813598fe0ddSCristian Dumitrescu file_line_number);
1814598fe0ddSCristian Dumitrescu
1815598fe0ddSCristian Dumitrescu fclose(file);
1816598fe0ddSCristian Dumitrescu }
1817598fe0ddSCristian Dumitrescu
1818598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_show_help[] =
1819*a4c1146cSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> show [filename]\n";
1820598fe0ddSCristian Dumitrescu
1821598fe0ddSCristian Dumitrescu static void
cmd_pipeline_selector_show(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)1822598fe0ddSCristian Dumitrescu cmd_pipeline_selector_show(char **tokens,
1823598fe0ddSCristian Dumitrescu uint32_t n_tokens,
1824598fe0ddSCristian Dumitrescu char *out,
1825598fe0ddSCristian Dumitrescu size_t out_size,
1826598fe0ddSCristian Dumitrescu void *obj)
1827598fe0ddSCristian Dumitrescu {
1828598fe0ddSCristian Dumitrescu struct pipeline *p;
1829598fe0ddSCristian Dumitrescu char *pipeline_name, *selector_name;
1830*a4c1146cSCristian Dumitrescu FILE *file = NULL;
1831598fe0ddSCristian Dumitrescu int status;
1832598fe0ddSCristian Dumitrescu
1833*a4c1146cSCristian Dumitrescu if (n_tokens != 5 && n_tokens != 6) {
1834598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1835598fe0ddSCristian Dumitrescu return;
1836598fe0ddSCristian Dumitrescu }
1837598fe0ddSCristian Dumitrescu
1838598fe0ddSCristian Dumitrescu pipeline_name = tokens[1];
1839598fe0ddSCristian Dumitrescu p = pipeline_find(obj, pipeline_name);
1840598fe0ddSCristian Dumitrescu if (!p || !p->ctl) {
1841598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1842598fe0ddSCristian Dumitrescu return;
1843598fe0ddSCristian Dumitrescu }
1844598fe0ddSCristian Dumitrescu
1845598fe0ddSCristian Dumitrescu selector_name = tokens[3];
1846*a4c1146cSCristian Dumitrescu
1847*a4c1146cSCristian Dumitrescu file = (n_tokens == 6) ? fopen(tokens[5], "w") : stdout;
1848*a4c1146cSCristian Dumitrescu if (!file) {
1849*a4c1146cSCristian Dumitrescu snprintf(out, out_size, "Cannot open file %s.\n", tokens[5]);
1850*a4c1146cSCristian Dumitrescu return;
1851*a4c1146cSCristian Dumitrescu }
1852*a4c1146cSCristian Dumitrescu
1853*a4c1146cSCristian Dumitrescu status = rte_swx_ctl_pipeline_selector_fprintf(file, p->ctl, selector_name);
1854598fe0ddSCristian Dumitrescu if (status)
1855598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "selector_name");
1856*a4c1146cSCristian Dumitrescu
1857*a4c1146cSCristian Dumitrescu if (file)
1858*a4c1146cSCristian Dumitrescu fclose(file);
1859598fe0ddSCristian Dumitrescu }
1860598fe0ddSCristian Dumitrescu
18618bd4862fSCristian Dumitrescu static int
pipeline_learner_default_entry_add(struct rte_swx_ctl_pipeline * p,const char * learner_name,FILE * file,uint32_t * file_line_number)18628bd4862fSCristian Dumitrescu pipeline_learner_default_entry_add(struct rte_swx_ctl_pipeline *p,
18638bd4862fSCristian Dumitrescu const char *learner_name,
18648bd4862fSCristian Dumitrescu FILE *file,
18658bd4862fSCristian Dumitrescu uint32_t *file_line_number)
18668bd4862fSCristian Dumitrescu {
18678bd4862fSCristian Dumitrescu char *line = NULL;
18688bd4862fSCristian Dumitrescu uint32_t line_id = 0;
18698bd4862fSCristian Dumitrescu int status = 0;
18708bd4862fSCristian Dumitrescu
18718bd4862fSCristian Dumitrescu /* Buffer allocation. */
18728bd4862fSCristian Dumitrescu line = malloc(MAX_LINE_SIZE);
18738bd4862fSCristian Dumitrescu if (!line)
18748bd4862fSCristian Dumitrescu return -ENOMEM;
18758bd4862fSCristian Dumitrescu
18768bd4862fSCristian Dumitrescu /* File read. */
18778bd4862fSCristian Dumitrescu for (line_id = 1; ; line_id++) {
18788bd4862fSCristian Dumitrescu struct rte_swx_table_entry *entry;
18798bd4862fSCristian Dumitrescu int is_blank_or_comment;
18808bd4862fSCristian Dumitrescu
18818bd4862fSCristian Dumitrescu if (fgets(line, MAX_LINE_SIZE, file) == NULL)
18828bd4862fSCristian Dumitrescu break;
18838bd4862fSCristian Dumitrescu
18848bd4862fSCristian Dumitrescu entry = rte_swx_ctl_pipeline_learner_default_entry_read(p,
18858bd4862fSCristian Dumitrescu learner_name,
18868bd4862fSCristian Dumitrescu line,
18878bd4862fSCristian Dumitrescu &is_blank_or_comment);
18888bd4862fSCristian Dumitrescu if (!entry) {
18898bd4862fSCristian Dumitrescu if (is_blank_or_comment)
18908bd4862fSCristian Dumitrescu continue;
18918bd4862fSCristian Dumitrescu
18928bd4862fSCristian Dumitrescu status = -EINVAL;
18938bd4862fSCristian Dumitrescu goto error;
18948bd4862fSCristian Dumitrescu }
18958bd4862fSCristian Dumitrescu
18968bd4862fSCristian Dumitrescu status = rte_swx_ctl_pipeline_learner_default_entry_add(p,
18978bd4862fSCristian Dumitrescu learner_name,
18988bd4862fSCristian Dumitrescu entry);
18998bd4862fSCristian Dumitrescu table_entry_free(entry);
19008bd4862fSCristian Dumitrescu if (status)
19018bd4862fSCristian Dumitrescu goto error;
19028bd4862fSCristian Dumitrescu }
19038bd4862fSCristian Dumitrescu
19048bd4862fSCristian Dumitrescu error:
19058bd4862fSCristian Dumitrescu *file_line_number = line_id;
19068bd4862fSCristian Dumitrescu free(line);
19078bd4862fSCristian Dumitrescu return status;
19088bd4862fSCristian Dumitrescu }
19098bd4862fSCristian Dumitrescu
19108bd4862fSCristian Dumitrescu static const char cmd_pipeline_learner_default_help[] =
19118bd4862fSCristian Dumitrescu "pipeline <pipeline_name> learner <learner_name> default <file_name>\n";
19128bd4862fSCristian Dumitrescu
19138bd4862fSCristian Dumitrescu static void
cmd_pipeline_learner_default(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)19148bd4862fSCristian Dumitrescu cmd_pipeline_learner_default(char **tokens,
19158bd4862fSCristian Dumitrescu uint32_t n_tokens,
19168bd4862fSCristian Dumitrescu char *out,
19178bd4862fSCristian Dumitrescu size_t out_size,
19188bd4862fSCristian Dumitrescu void *obj)
19198bd4862fSCristian Dumitrescu {
19208bd4862fSCristian Dumitrescu struct pipeline *p;
19218bd4862fSCristian Dumitrescu char *pipeline_name, *learner_name, *file_name;
19228bd4862fSCristian Dumitrescu FILE *file = NULL;
19238bd4862fSCristian Dumitrescu uint32_t file_line_number = 0;
19248bd4862fSCristian Dumitrescu int status;
19258bd4862fSCristian Dumitrescu
19268bd4862fSCristian Dumitrescu if (n_tokens != 6) {
19278bd4862fSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
19288bd4862fSCristian Dumitrescu return;
19298bd4862fSCristian Dumitrescu }
19308bd4862fSCristian Dumitrescu
19318bd4862fSCristian Dumitrescu pipeline_name = tokens[1];
19328bd4862fSCristian Dumitrescu p = pipeline_find(obj, pipeline_name);
19338bd4862fSCristian Dumitrescu if (!p || !p->ctl) {
19348bd4862fSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
19358bd4862fSCristian Dumitrescu return;
19368bd4862fSCristian Dumitrescu }
19378bd4862fSCristian Dumitrescu
19388bd4862fSCristian Dumitrescu learner_name = tokens[3];
19398bd4862fSCristian Dumitrescu
19408bd4862fSCristian Dumitrescu file_name = tokens[5];
19418bd4862fSCristian Dumitrescu file = fopen(file_name, "r");
19428bd4862fSCristian Dumitrescu if (!file) {
19438bd4862fSCristian Dumitrescu snprintf(out, out_size, "Cannot open file %s.\n", file_name);
19448bd4862fSCristian Dumitrescu return;
19458bd4862fSCristian Dumitrescu }
19468bd4862fSCristian Dumitrescu
19478bd4862fSCristian Dumitrescu status = pipeline_learner_default_entry_add(p->ctl,
19488bd4862fSCristian Dumitrescu learner_name,
19498bd4862fSCristian Dumitrescu file,
19508bd4862fSCristian Dumitrescu &file_line_number);
19518bd4862fSCristian Dumitrescu if (status)
19528bd4862fSCristian Dumitrescu snprintf(out, out_size, "Invalid entry in file %s at line %u\n",
19538bd4862fSCristian Dumitrescu file_name,
19548bd4862fSCristian Dumitrescu file_line_number);
19558bd4862fSCristian Dumitrescu
19568bd4862fSCristian Dumitrescu fclose(file);
19578bd4862fSCristian Dumitrescu }
19588bd4862fSCristian Dumitrescu
195975129cebSChurchill Khangar static const char cmd_pipeline_commit_help[] =
196075129cebSChurchill Khangar "pipeline <pipeline_name> commit\n";
196175129cebSChurchill Khangar
196275129cebSChurchill Khangar static void
cmd_pipeline_commit(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)196375129cebSChurchill Khangar cmd_pipeline_commit(char **tokens,
196475129cebSChurchill Khangar uint32_t n_tokens,
196575129cebSChurchill Khangar char *out,
196675129cebSChurchill Khangar size_t out_size,
196775129cebSChurchill Khangar void *obj)
196875129cebSChurchill Khangar {
196975129cebSChurchill Khangar struct pipeline *p;
197075129cebSChurchill Khangar char *pipeline_name;
197175129cebSChurchill Khangar int status;
197275129cebSChurchill Khangar
197375129cebSChurchill Khangar if (n_tokens != 3) {
197475129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
197575129cebSChurchill Khangar return;
197675129cebSChurchill Khangar }
197775129cebSChurchill Khangar
197875129cebSChurchill Khangar pipeline_name = tokens[1];
197975129cebSChurchill Khangar p = pipeline_find(obj, pipeline_name);
198075129cebSChurchill Khangar if (!p || !p->ctl) {
198175129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
198275129cebSChurchill Khangar return;
19835074e1d5SCristian Dumitrescu }
19845074e1d5SCristian Dumitrescu
19855074e1d5SCristian Dumitrescu status = rte_swx_ctl_pipeline_commit(p->ctl, 1);
198675129cebSChurchill Khangar if (status)
198775129cebSChurchill Khangar snprintf(out, out_size, "Commit failed. "
198875129cebSChurchill Khangar "Use \"commit\" to retry or \"abort\" to discard the pending work.\n");
19895074e1d5SCristian Dumitrescu }
19905074e1d5SCristian Dumitrescu
199175129cebSChurchill Khangar static const char cmd_pipeline_abort_help[] =
199275129cebSChurchill Khangar "pipeline <pipeline_name> abort\n";
19935074e1d5SCristian Dumitrescu
199475129cebSChurchill Khangar static void
cmd_pipeline_abort(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)199575129cebSChurchill Khangar cmd_pipeline_abort(char **tokens,
199675129cebSChurchill Khangar uint32_t n_tokens,
199775129cebSChurchill Khangar char *out,
199875129cebSChurchill Khangar size_t out_size,
199975129cebSChurchill Khangar void *obj)
200075129cebSChurchill Khangar {
200175129cebSChurchill Khangar struct pipeline *p;
200275129cebSChurchill Khangar char *pipeline_name;
20035074e1d5SCristian Dumitrescu
200475129cebSChurchill Khangar if (n_tokens != 3) {
200575129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
20065074e1d5SCristian Dumitrescu return;
200775129cebSChurchill Khangar }
20085074e1d5SCristian Dumitrescu
200975129cebSChurchill Khangar pipeline_name = tokens[1];
201075129cebSChurchill Khangar p = pipeline_find(obj, pipeline_name);
201175129cebSChurchill Khangar if (!p || !p->ctl) {
201275129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
201375129cebSChurchill Khangar return;
201475129cebSChurchill Khangar }
201575129cebSChurchill Khangar
20165074e1d5SCristian Dumitrescu rte_swx_ctl_pipeline_abort(p->ctl);
20175074e1d5SCristian Dumitrescu }
20185074e1d5SCristian Dumitrescu
201964cfcebdSCristian Dumitrescu static const char cmd_pipeline_regrd_help[] =
202064cfcebdSCristian Dumitrescu "pipeline <pipeline_name> regrd <register_array_name> <index>\n";
202164cfcebdSCristian Dumitrescu
202264cfcebdSCristian Dumitrescu static void
cmd_pipeline_regrd(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)202364cfcebdSCristian Dumitrescu cmd_pipeline_regrd(char **tokens,
202464cfcebdSCristian Dumitrescu uint32_t n_tokens,
202564cfcebdSCristian Dumitrescu char *out,
202664cfcebdSCristian Dumitrescu size_t out_size,
202764cfcebdSCristian Dumitrescu void *obj)
202864cfcebdSCristian Dumitrescu {
202964cfcebdSCristian Dumitrescu struct pipeline *p;
203064cfcebdSCristian Dumitrescu const char *name;
203164cfcebdSCristian Dumitrescu uint64_t value;
203264cfcebdSCristian Dumitrescu uint32_t idx;
203364cfcebdSCristian Dumitrescu int status;
203464cfcebdSCristian Dumitrescu
203564cfcebdSCristian Dumitrescu if (n_tokens != 5) {
203664cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
203764cfcebdSCristian Dumitrescu return;
203864cfcebdSCristian Dumitrescu }
203964cfcebdSCristian Dumitrescu
204064cfcebdSCristian Dumitrescu p = pipeline_find(obj, tokens[1]);
204164cfcebdSCristian Dumitrescu if (!p || !p->ctl) {
204264cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
204364cfcebdSCristian Dumitrescu return;
204464cfcebdSCristian Dumitrescu }
204564cfcebdSCristian Dumitrescu
204664cfcebdSCristian Dumitrescu if (strcmp(tokens[2], "regrd")) {
204764cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "regrd");
204864cfcebdSCristian Dumitrescu return;
204964cfcebdSCristian Dumitrescu }
205064cfcebdSCristian Dumitrescu
205164cfcebdSCristian Dumitrescu name = tokens[3];
205264cfcebdSCristian Dumitrescu
205364cfcebdSCristian Dumitrescu if (parser_read_uint32(&idx, tokens[4])) {
205464cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index");
205564cfcebdSCristian Dumitrescu return;
205664cfcebdSCristian Dumitrescu }
205764cfcebdSCristian Dumitrescu
205864cfcebdSCristian Dumitrescu status = rte_swx_ctl_pipeline_regarray_read(p->p, name, idx, &value);
205964cfcebdSCristian Dumitrescu if (status) {
206064cfcebdSCristian Dumitrescu snprintf(out, out_size, "Command failed.\n");
206164cfcebdSCristian Dumitrescu return;
206264cfcebdSCristian Dumitrescu }
206364cfcebdSCristian Dumitrescu
206464cfcebdSCristian Dumitrescu snprintf(out, out_size, "0x%" PRIx64 "\n", value);
206564cfcebdSCristian Dumitrescu }
206664cfcebdSCristian Dumitrescu
206764cfcebdSCristian Dumitrescu static const char cmd_pipeline_regwr_help[] =
206864cfcebdSCristian Dumitrescu "pipeline <pipeline_name> regwr <register_array_name> <index> <value>\n";
206964cfcebdSCristian Dumitrescu
207064cfcebdSCristian Dumitrescu static void
cmd_pipeline_regwr(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)207164cfcebdSCristian Dumitrescu cmd_pipeline_regwr(char **tokens,
207264cfcebdSCristian Dumitrescu uint32_t n_tokens,
207364cfcebdSCristian Dumitrescu char *out,
207464cfcebdSCristian Dumitrescu size_t out_size,
207564cfcebdSCristian Dumitrescu void *obj)
207664cfcebdSCristian Dumitrescu {
207764cfcebdSCristian Dumitrescu struct pipeline *p;
207864cfcebdSCristian Dumitrescu const char *name;
207964cfcebdSCristian Dumitrescu uint64_t value;
208064cfcebdSCristian Dumitrescu uint32_t idx;
208164cfcebdSCristian Dumitrescu int status;
208264cfcebdSCristian Dumitrescu
208364cfcebdSCristian Dumitrescu if (n_tokens != 6) {
208464cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
208564cfcebdSCristian Dumitrescu return;
208664cfcebdSCristian Dumitrescu }
208764cfcebdSCristian Dumitrescu
208864cfcebdSCristian Dumitrescu p = pipeline_find(obj, tokens[1]);
208964cfcebdSCristian Dumitrescu if (!p || !p->ctl) {
209064cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
209164cfcebdSCristian Dumitrescu return;
209264cfcebdSCristian Dumitrescu }
209364cfcebdSCristian Dumitrescu
209464cfcebdSCristian Dumitrescu if (strcmp(tokens[2], "regwr")) {
209564cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "regwr");
209664cfcebdSCristian Dumitrescu return;
209764cfcebdSCristian Dumitrescu }
209864cfcebdSCristian Dumitrescu
209964cfcebdSCristian Dumitrescu name = tokens[3];
210064cfcebdSCristian Dumitrescu
210164cfcebdSCristian Dumitrescu if (parser_read_uint32(&idx, tokens[4])) {
210264cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index");
210364cfcebdSCristian Dumitrescu return;
210464cfcebdSCristian Dumitrescu }
210564cfcebdSCristian Dumitrescu
210664cfcebdSCristian Dumitrescu if (parser_read_uint64(&value, tokens[5])) {
210764cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "value");
210864cfcebdSCristian Dumitrescu return;
210964cfcebdSCristian Dumitrescu }
211064cfcebdSCristian Dumitrescu
211164cfcebdSCristian Dumitrescu status = rte_swx_ctl_pipeline_regarray_write(p->p, name, idx, value);
211264cfcebdSCristian Dumitrescu if (status) {
211364cfcebdSCristian Dumitrescu snprintf(out, out_size, "Command failed.\n");
211464cfcebdSCristian Dumitrescu return;
211564cfcebdSCristian Dumitrescu }
211664cfcebdSCristian Dumitrescu }
211764cfcebdSCristian Dumitrescu
2118f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_profile_add_help[] =
2119f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter profile <profile_name> add "
2120f38913b7SCristian Dumitrescu "cir <cir> pir <pir> cbs <cbs> pbs <pbs>\n";
2121f38913b7SCristian Dumitrescu
2122f38913b7SCristian Dumitrescu static void
cmd_pipeline_meter_profile_add(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)2123f38913b7SCristian Dumitrescu cmd_pipeline_meter_profile_add(char **tokens,
2124f38913b7SCristian Dumitrescu uint32_t n_tokens,
2125f38913b7SCristian Dumitrescu char *out,
2126f38913b7SCristian Dumitrescu size_t out_size,
2127f38913b7SCristian Dumitrescu void *obj)
2128f38913b7SCristian Dumitrescu {
2129f38913b7SCristian Dumitrescu struct rte_meter_trtcm_params params;
2130f38913b7SCristian Dumitrescu struct pipeline *p;
2131f38913b7SCristian Dumitrescu const char *profile_name;
2132f38913b7SCristian Dumitrescu int status;
2133f38913b7SCristian Dumitrescu
2134f38913b7SCristian Dumitrescu if (n_tokens != 14) {
2135f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2136f38913b7SCristian Dumitrescu return;
2137f38913b7SCristian Dumitrescu }
2138f38913b7SCristian Dumitrescu
2139f38913b7SCristian Dumitrescu p = pipeline_find(obj, tokens[1]);
2140f38913b7SCristian Dumitrescu if (!p || !p->ctl) {
2141f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
2142f38913b7SCristian Dumitrescu return;
2143f38913b7SCristian Dumitrescu }
2144f38913b7SCristian Dumitrescu
2145f38913b7SCristian Dumitrescu if (strcmp(tokens[2], "meter")) {
2146f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
2147f38913b7SCristian Dumitrescu return;
2148f38913b7SCristian Dumitrescu }
2149f38913b7SCristian Dumitrescu
2150f38913b7SCristian Dumitrescu if (strcmp(tokens[3], "profile")) {
2151f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
2152f38913b7SCristian Dumitrescu return;
2153f38913b7SCristian Dumitrescu }
2154f38913b7SCristian Dumitrescu
2155f38913b7SCristian Dumitrescu profile_name = tokens[4];
2156f38913b7SCristian Dumitrescu
2157f38913b7SCristian Dumitrescu if (strcmp(tokens[5], "add")) {
2158f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
2159f38913b7SCristian Dumitrescu return;
2160f38913b7SCristian Dumitrescu }
2161f38913b7SCristian Dumitrescu
2162f38913b7SCristian Dumitrescu if (strcmp(tokens[6], "cir")) {
2163f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
2164f38913b7SCristian Dumitrescu return;
2165f38913b7SCristian Dumitrescu }
2166f38913b7SCristian Dumitrescu
2167f38913b7SCristian Dumitrescu if (parser_read_uint64(¶ms.cir, tokens[7])) {
2168f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "cir");
2169f38913b7SCristian Dumitrescu return;
2170f38913b7SCristian Dumitrescu }
2171f38913b7SCristian Dumitrescu
2172f38913b7SCristian Dumitrescu if (strcmp(tokens[8], "pir")) {
2173f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir");
2174f38913b7SCristian Dumitrescu return;
2175f38913b7SCristian Dumitrescu }
2176f38913b7SCristian Dumitrescu
2177f38913b7SCristian Dumitrescu if (parser_read_uint64(¶ms.pir, tokens[9])) {
2178f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pir");
2179f38913b7SCristian Dumitrescu return;
2180f38913b7SCristian Dumitrescu }
2181f38913b7SCristian Dumitrescu
2182f38913b7SCristian Dumitrescu if (strcmp(tokens[10], "cbs")) {
2183f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
2184f38913b7SCristian Dumitrescu return;
2185f38913b7SCristian Dumitrescu }
2186f38913b7SCristian Dumitrescu
2187f38913b7SCristian Dumitrescu if (parser_read_uint64(¶ms.cbs, tokens[11])) {
2188f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
2189f38913b7SCristian Dumitrescu return;
2190f38913b7SCristian Dumitrescu }
2191f38913b7SCristian Dumitrescu
2192f38913b7SCristian Dumitrescu if (strcmp(tokens[12], "pbs")) {
2193f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs");
2194f38913b7SCristian Dumitrescu return;
2195f38913b7SCristian Dumitrescu }
2196f38913b7SCristian Dumitrescu
2197f38913b7SCristian Dumitrescu if (parser_read_uint64(¶ms.pbs, tokens[13])) {
2198f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pbs");
2199f38913b7SCristian Dumitrescu return;
2200f38913b7SCristian Dumitrescu }
2201f38913b7SCristian Dumitrescu
2202f38913b7SCristian Dumitrescu status = rte_swx_ctl_meter_profile_add(p->p, profile_name, ¶ms);
2203f38913b7SCristian Dumitrescu if (status) {
2204f38913b7SCristian Dumitrescu snprintf(out, out_size, "Command failed.\n");
2205f38913b7SCristian Dumitrescu return;
2206f38913b7SCristian Dumitrescu }
2207f38913b7SCristian Dumitrescu }
2208f38913b7SCristian Dumitrescu
2209f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_profile_delete_help[] =
2210f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter profile <profile_name> delete\n";
2211f38913b7SCristian Dumitrescu
2212f38913b7SCristian Dumitrescu static void
cmd_pipeline_meter_profile_delete(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)2213f38913b7SCristian Dumitrescu cmd_pipeline_meter_profile_delete(char **tokens,
2214f38913b7SCristian Dumitrescu uint32_t n_tokens,
2215f38913b7SCristian Dumitrescu char *out,
2216f38913b7SCristian Dumitrescu size_t out_size,
2217f38913b7SCristian Dumitrescu void *obj)
2218f38913b7SCristian Dumitrescu {
2219f38913b7SCristian Dumitrescu struct pipeline *p;
2220f38913b7SCristian Dumitrescu const char *profile_name;
2221f38913b7SCristian Dumitrescu int status;
2222f38913b7SCristian Dumitrescu
2223f38913b7SCristian Dumitrescu if (n_tokens != 6) {
2224f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2225f38913b7SCristian Dumitrescu return;
2226f38913b7SCristian Dumitrescu }
2227f38913b7SCristian Dumitrescu
2228f38913b7SCristian Dumitrescu p = pipeline_find(obj, tokens[1]);
2229f38913b7SCristian Dumitrescu if (!p || !p->ctl) {
2230f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
2231f38913b7SCristian Dumitrescu return;
2232f38913b7SCristian Dumitrescu }
2233f38913b7SCristian Dumitrescu
2234f38913b7SCristian Dumitrescu if (strcmp(tokens[2], "meter")) {
2235f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
2236f38913b7SCristian Dumitrescu return;
2237f38913b7SCristian Dumitrescu }
2238f38913b7SCristian Dumitrescu
2239f38913b7SCristian Dumitrescu if (strcmp(tokens[3], "profile")) {
2240f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
2241f38913b7SCristian Dumitrescu return;
2242f38913b7SCristian Dumitrescu }
2243f38913b7SCristian Dumitrescu
2244f38913b7SCristian Dumitrescu profile_name = tokens[4];
2245f38913b7SCristian Dumitrescu
2246f38913b7SCristian Dumitrescu if (strcmp(tokens[5], "delete")) {
2247f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
2248f38913b7SCristian Dumitrescu return;
2249f38913b7SCristian Dumitrescu }
2250f38913b7SCristian Dumitrescu
2251f38913b7SCristian Dumitrescu status = rte_swx_ctl_meter_profile_delete(p->p, profile_name);
2252f38913b7SCristian Dumitrescu if (status) {
2253f38913b7SCristian Dumitrescu snprintf(out, out_size, "Command failed.\n");
2254f38913b7SCristian Dumitrescu return;
2255f38913b7SCristian Dumitrescu }
2256f38913b7SCristian Dumitrescu }
2257f38913b7SCristian Dumitrescu
2258f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_reset_help[] =
2259f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
2260f38913b7SCristian Dumitrescu "reset\n";
2261f38913b7SCristian Dumitrescu
2262f38913b7SCristian Dumitrescu static void
cmd_pipeline_meter_reset(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)2263f38913b7SCristian Dumitrescu cmd_pipeline_meter_reset(char **tokens,
2264f38913b7SCristian Dumitrescu uint32_t n_tokens,
2265f38913b7SCristian Dumitrescu char *out,
2266f38913b7SCristian Dumitrescu size_t out_size,
2267f38913b7SCristian Dumitrescu void *obj)
2268f38913b7SCristian Dumitrescu {
2269f38913b7SCristian Dumitrescu struct pipeline *p;
2270f38913b7SCristian Dumitrescu const char *name;
227100b67591SAli Alnubani uint32_t idx0 = 0, idx1 = 0;
2272f38913b7SCristian Dumitrescu
2273f38913b7SCristian Dumitrescu if (n_tokens != 9) {
2274f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2275f38913b7SCristian Dumitrescu return;
2276f38913b7SCristian Dumitrescu }
2277f38913b7SCristian Dumitrescu
2278f38913b7SCristian Dumitrescu p = pipeline_find(obj, tokens[1]);
2279f38913b7SCristian Dumitrescu if (!p || !p->ctl) {
2280f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
2281f38913b7SCristian Dumitrescu return;
2282f38913b7SCristian Dumitrescu }
2283f38913b7SCristian Dumitrescu
2284f38913b7SCristian Dumitrescu if (strcmp(tokens[2], "meter")) {
2285f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
2286f38913b7SCristian Dumitrescu return;
2287f38913b7SCristian Dumitrescu }
2288f38913b7SCristian Dumitrescu
2289f38913b7SCristian Dumitrescu name = tokens[3];
2290f38913b7SCristian Dumitrescu
2291f38913b7SCristian Dumitrescu if (strcmp(tokens[4], "from")) {
2292f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
2293f38913b7SCristian Dumitrescu return;
2294f38913b7SCristian Dumitrescu }
2295f38913b7SCristian Dumitrescu
2296f38913b7SCristian Dumitrescu if (parser_read_uint32(&idx0, tokens[5])) {
2297f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index0");
2298f38913b7SCristian Dumitrescu return;
2299f38913b7SCristian Dumitrescu }
2300f38913b7SCristian Dumitrescu
2301f38913b7SCristian Dumitrescu if (strcmp(tokens[6], "to")) {
2302f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
2303f38913b7SCristian Dumitrescu return;
2304f38913b7SCristian Dumitrescu }
2305f38913b7SCristian Dumitrescu
2306f38913b7SCristian Dumitrescu if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
2307f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index1");
2308f38913b7SCristian Dumitrescu return;
2309f38913b7SCristian Dumitrescu }
2310f38913b7SCristian Dumitrescu
2311f38913b7SCristian Dumitrescu if (strcmp(tokens[8], "reset")) {
2312f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "reset");
2313f38913b7SCristian Dumitrescu return;
2314f38913b7SCristian Dumitrescu }
2315f38913b7SCristian Dumitrescu
2316f38913b7SCristian Dumitrescu for ( ; idx0 <= idx1; idx0++) {
2317f38913b7SCristian Dumitrescu int status;
2318f38913b7SCristian Dumitrescu
2319f38913b7SCristian Dumitrescu status = rte_swx_ctl_meter_reset(p->p, name, idx0);
2320f38913b7SCristian Dumitrescu if (status) {
2321f38913b7SCristian Dumitrescu snprintf(out, out_size, "Command failed for index %u.\n", idx0);
2322f38913b7SCristian Dumitrescu return;
2323f38913b7SCristian Dumitrescu }
2324f38913b7SCristian Dumitrescu }
2325f38913b7SCristian Dumitrescu }
2326f38913b7SCristian Dumitrescu
2327f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_set_help[] =
2328f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
2329f38913b7SCristian Dumitrescu "set profile <profile_name>\n";
2330f38913b7SCristian Dumitrescu
2331f38913b7SCristian Dumitrescu static void
cmd_pipeline_meter_set(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)2332f38913b7SCristian Dumitrescu cmd_pipeline_meter_set(char **tokens,
2333f38913b7SCristian Dumitrescu uint32_t n_tokens,
2334f38913b7SCristian Dumitrescu char *out,
2335f38913b7SCristian Dumitrescu size_t out_size,
2336f38913b7SCristian Dumitrescu void *obj)
2337f38913b7SCristian Dumitrescu {
2338f38913b7SCristian Dumitrescu struct pipeline *p;
2339f38913b7SCristian Dumitrescu const char *name, *profile_name;
234000b67591SAli Alnubani uint32_t idx0 = 0, idx1 = 0;
2341f38913b7SCristian Dumitrescu
2342f38913b7SCristian Dumitrescu if (n_tokens != 11) {
2343f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2344f38913b7SCristian Dumitrescu return;
2345f38913b7SCristian Dumitrescu }
2346f38913b7SCristian Dumitrescu
2347f38913b7SCristian Dumitrescu p = pipeline_find(obj, tokens[1]);
2348f38913b7SCristian Dumitrescu if (!p || !p->ctl) {
2349f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
2350f38913b7SCristian Dumitrescu return;
2351f38913b7SCristian Dumitrescu }
2352f38913b7SCristian Dumitrescu
2353f38913b7SCristian Dumitrescu if (strcmp(tokens[2], "meter")) {
2354f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
2355f38913b7SCristian Dumitrescu return;
2356f38913b7SCristian Dumitrescu }
2357f38913b7SCristian Dumitrescu
2358f38913b7SCristian Dumitrescu name = tokens[3];
2359f38913b7SCristian Dumitrescu
2360f38913b7SCristian Dumitrescu if (strcmp(tokens[4], "from")) {
2361f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
2362f38913b7SCristian Dumitrescu return;
2363f38913b7SCristian Dumitrescu }
2364f38913b7SCristian Dumitrescu
2365f38913b7SCristian Dumitrescu if (parser_read_uint32(&idx0, tokens[5])) {
2366f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index0");
2367f38913b7SCristian Dumitrescu return;
2368f38913b7SCristian Dumitrescu }
2369f38913b7SCristian Dumitrescu
2370f38913b7SCristian Dumitrescu if (strcmp(tokens[6], "to")) {
2371f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
2372f38913b7SCristian Dumitrescu return;
2373f38913b7SCristian Dumitrescu }
2374f38913b7SCristian Dumitrescu
2375f38913b7SCristian Dumitrescu if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
2376f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index1");
2377f38913b7SCristian Dumitrescu return;
2378f38913b7SCristian Dumitrescu }
2379f38913b7SCristian Dumitrescu
2380f38913b7SCristian Dumitrescu if (strcmp(tokens[8], "set")) {
2381f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "set");
2382f38913b7SCristian Dumitrescu return;
2383f38913b7SCristian Dumitrescu }
2384f38913b7SCristian Dumitrescu
2385f38913b7SCristian Dumitrescu if (strcmp(tokens[9], "profile")) {
2386f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
2387f38913b7SCristian Dumitrescu return;
2388f38913b7SCristian Dumitrescu }
2389f38913b7SCristian Dumitrescu
2390f38913b7SCristian Dumitrescu profile_name = tokens[10];
2391f38913b7SCristian Dumitrescu
2392f38913b7SCristian Dumitrescu for ( ; idx0 <= idx1; idx0++) {
2393f38913b7SCristian Dumitrescu int status;
2394f38913b7SCristian Dumitrescu
2395f38913b7SCristian Dumitrescu status = rte_swx_ctl_meter_set(p->p, name, idx0, profile_name);
2396f38913b7SCristian Dumitrescu if (status) {
2397f38913b7SCristian Dumitrescu snprintf(out, out_size, "Command failed for index %u.\n", idx0);
2398f38913b7SCristian Dumitrescu return;
2399f38913b7SCristian Dumitrescu }
2400f38913b7SCristian Dumitrescu }
2401f38913b7SCristian Dumitrescu }
2402f38913b7SCristian Dumitrescu
2403f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_stats_help[] =
2404f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
2405f38913b7SCristian Dumitrescu "stats\n";
2406f38913b7SCristian Dumitrescu
2407f38913b7SCristian Dumitrescu static void
cmd_pipeline_meter_stats(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)2408f38913b7SCristian Dumitrescu cmd_pipeline_meter_stats(char **tokens,
2409f38913b7SCristian Dumitrescu uint32_t n_tokens,
2410f38913b7SCristian Dumitrescu char *out,
2411f38913b7SCristian Dumitrescu size_t out_size,
2412f38913b7SCristian Dumitrescu void *obj)
2413f38913b7SCristian Dumitrescu {
2414f38913b7SCristian Dumitrescu struct rte_swx_ctl_meter_stats stats;
2415f38913b7SCristian Dumitrescu struct pipeline *p;
2416f38913b7SCristian Dumitrescu const char *name;
241700b67591SAli Alnubani uint32_t idx0 = 0, idx1 = 0;
2418f38913b7SCristian Dumitrescu
2419f38913b7SCristian Dumitrescu if (n_tokens != 9) {
2420f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2421f38913b7SCristian Dumitrescu return;
2422f38913b7SCristian Dumitrescu }
2423f38913b7SCristian Dumitrescu
2424f38913b7SCristian Dumitrescu p = pipeline_find(obj, tokens[1]);
2425f38913b7SCristian Dumitrescu if (!p || !p->ctl) {
2426f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
2427f38913b7SCristian Dumitrescu return;
2428f38913b7SCristian Dumitrescu }
2429f38913b7SCristian Dumitrescu
2430f38913b7SCristian Dumitrescu if (strcmp(tokens[2], "meter")) {
2431f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
2432f38913b7SCristian Dumitrescu return;
2433f38913b7SCristian Dumitrescu }
2434f38913b7SCristian Dumitrescu
2435f38913b7SCristian Dumitrescu name = tokens[3];
2436f38913b7SCristian Dumitrescu
2437f38913b7SCristian Dumitrescu if (strcmp(tokens[4], "from")) {
2438f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
2439f38913b7SCristian Dumitrescu return;
2440f38913b7SCristian Dumitrescu }
2441f38913b7SCristian Dumitrescu
2442f38913b7SCristian Dumitrescu if (parser_read_uint32(&idx0, tokens[5])) {
2443f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index0");
2444f38913b7SCristian Dumitrescu return;
2445f38913b7SCristian Dumitrescu }
2446f38913b7SCristian Dumitrescu
2447f38913b7SCristian Dumitrescu if (strcmp(tokens[6], "to")) {
2448f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
2449f38913b7SCristian Dumitrescu return;
2450f38913b7SCristian Dumitrescu }
2451f38913b7SCristian Dumitrescu
2452f38913b7SCristian Dumitrescu if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
2453f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index1");
2454f38913b7SCristian Dumitrescu return;
2455f38913b7SCristian Dumitrescu }
2456f38913b7SCristian Dumitrescu
2457f38913b7SCristian Dumitrescu if (strcmp(tokens[8], "stats")) {
2458f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2459f38913b7SCristian Dumitrescu return;
2460f38913b7SCristian Dumitrescu }
2461f38913b7SCristian Dumitrescu
2462f38913b7SCristian Dumitrescu /* Table header. */
2463f38913b7SCristian Dumitrescu snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n",
2464f38913b7SCristian Dumitrescu "-------",
2465f38913b7SCristian Dumitrescu "----------------", "----------------", "----------------",
2466f38913b7SCristian Dumitrescu "----------------", "----------------", "----------------");
2467f38913b7SCristian Dumitrescu out_size -= strlen(out);
2468f38913b7SCristian Dumitrescu out += strlen(out);
2469f38913b7SCristian Dumitrescu
2470f38913b7SCristian Dumitrescu snprintf(out, out_size, "| %4s | %16s | %16s | %16s | %16s | %16s | %16s |\n",
2471f38913b7SCristian Dumitrescu "METER #",
2472f38913b7SCristian Dumitrescu "GREEN (packets)", "YELLOW (packets)", "RED (packets)",
2473f38913b7SCristian Dumitrescu "GREEN (bytes)", "YELLOW (bytes)", "RED (bytes)");
2474f38913b7SCristian Dumitrescu out_size -= strlen(out);
2475f38913b7SCristian Dumitrescu out += strlen(out);
2476f38913b7SCristian Dumitrescu
2477f38913b7SCristian Dumitrescu snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n",
2478f38913b7SCristian Dumitrescu "-------",
2479f38913b7SCristian Dumitrescu "----------------", "----------------", "----------------",
2480f38913b7SCristian Dumitrescu "----------------", "----------------", "----------------");
2481f38913b7SCristian Dumitrescu out_size -= strlen(out);
2482f38913b7SCristian Dumitrescu out += strlen(out);
2483f38913b7SCristian Dumitrescu
2484f38913b7SCristian Dumitrescu /* Table rows. */
2485f38913b7SCristian Dumitrescu for ( ; idx0 <= idx1; idx0++) {
2486f38913b7SCristian Dumitrescu int status;
2487f38913b7SCristian Dumitrescu
2488f38913b7SCristian Dumitrescu status = rte_swx_ctl_meter_stats_read(p->p, name, idx0, &stats);
2489f38913b7SCristian Dumitrescu if (status) {
2490f38913b7SCristian Dumitrescu snprintf(out, out_size, "Pipeline meter stats error at index %u.\n", idx0);
2491f38913b7SCristian Dumitrescu out_size -= strlen(out);
2492f38913b7SCristian Dumitrescu out += strlen(out);
2493f38913b7SCristian Dumitrescu return;
2494f38913b7SCristian Dumitrescu }
2495f38913b7SCristian Dumitrescu
2496f38913b7SCristian Dumitrescu snprintf(out, out_size, "| %7d | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64
2497f38913b7SCristian Dumitrescu " | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 " |\n",
2498f38913b7SCristian Dumitrescu idx0,
2499f38913b7SCristian Dumitrescu stats.n_pkts[RTE_COLOR_GREEN],
2500f38913b7SCristian Dumitrescu stats.n_pkts[RTE_COLOR_YELLOW],
2501f38913b7SCristian Dumitrescu stats.n_pkts[RTE_COLOR_RED],
2502f38913b7SCristian Dumitrescu stats.n_bytes[RTE_COLOR_GREEN],
2503f38913b7SCristian Dumitrescu stats.n_bytes[RTE_COLOR_YELLOW],
2504f38913b7SCristian Dumitrescu stats.n_bytes[RTE_COLOR_RED]);
2505f38913b7SCristian Dumitrescu out_size -= strlen(out);
2506f38913b7SCristian Dumitrescu out += strlen(out);
2507f38913b7SCristian Dumitrescu }
2508f38913b7SCristian Dumitrescu }
2509f38913b7SCristian Dumitrescu
25105074e1d5SCristian Dumitrescu static const char cmd_pipeline_stats_help[] =
25115074e1d5SCristian Dumitrescu "pipeline <pipeline_name> stats\n";
25125074e1d5SCristian Dumitrescu
25135074e1d5SCristian Dumitrescu static void
cmd_pipeline_stats(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)25145074e1d5SCristian Dumitrescu cmd_pipeline_stats(char **tokens,
25155074e1d5SCristian Dumitrescu uint32_t n_tokens,
25165074e1d5SCristian Dumitrescu char *out,
25175074e1d5SCristian Dumitrescu size_t out_size,
25185074e1d5SCristian Dumitrescu void *obj)
25195074e1d5SCristian Dumitrescu {
25205074e1d5SCristian Dumitrescu struct rte_swx_ctl_pipeline_info info;
25215074e1d5SCristian Dumitrescu struct pipeline *p;
25225074e1d5SCristian Dumitrescu uint32_t i;
25235074e1d5SCristian Dumitrescu int status;
25245074e1d5SCristian Dumitrescu
25255074e1d5SCristian Dumitrescu if (n_tokens != 3) {
25265074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
25275074e1d5SCristian Dumitrescu return;
25285074e1d5SCristian Dumitrescu }
25295074e1d5SCristian Dumitrescu
25305074e1d5SCristian Dumitrescu p = pipeline_find(obj, tokens[1]);
25315074e1d5SCristian Dumitrescu if (!p || !p->ctl) {
25325074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
25335074e1d5SCristian Dumitrescu return;
25345074e1d5SCristian Dumitrescu }
25355074e1d5SCristian Dumitrescu
25365074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "stats")) {
25375074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
25385074e1d5SCristian Dumitrescu return;
25395074e1d5SCristian Dumitrescu }
25405074e1d5SCristian Dumitrescu
25415074e1d5SCristian Dumitrescu status = rte_swx_ctl_pipeline_info_get(p->p, &info);
25425074e1d5SCristian Dumitrescu if (status) {
25435074e1d5SCristian Dumitrescu snprintf(out, out_size, "Pipeline info get error.");
25445074e1d5SCristian Dumitrescu return;
25455074e1d5SCristian Dumitrescu }
25465074e1d5SCristian Dumitrescu
25475074e1d5SCristian Dumitrescu snprintf(out, out_size, "Input ports:\n");
25485074e1d5SCristian Dumitrescu out_size -= strlen(out);
25495074e1d5SCristian Dumitrescu out += strlen(out);
25505074e1d5SCristian Dumitrescu
25515074e1d5SCristian Dumitrescu for (i = 0; i < info.n_ports_in; i++) {
25525074e1d5SCristian Dumitrescu struct rte_swx_port_in_stats stats;
25535074e1d5SCristian Dumitrescu
25545074e1d5SCristian Dumitrescu rte_swx_ctl_pipeline_port_in_stats_read(p->p, i, &stats);
25555074e1d5SCristian Dumitrescu
25565074e1d5SCristian Dumitrescu snprintf(out, out_size, "\tPort %u:"
25575074e1d5SCristian Dumitrescu " packets %" PRIu64
25585074e1d5SCristian Dumitrescu " bytes %" PRIu64
25595074e1d5SCristian Dumitrescu " empty %" PRIu64 "\n",
25605074e1d5SCristian Dumitrescu i, stats.n_pkts, stats.n_bytes, stats.n_empty);
25615074e1d5SCristian Dumitrescu out_size -= strlen(out);
25625074e1d5SCristian Dumitrescu out += strlen(out);
25635074e1d5SCristian Dumitrescu }
25645074e1d5SCristian Dumitrescu
2565742b0a57SCristian Dumitrescu snprintf(out, out_size, "\nOutput ports:\n");
25665074e1d5SCristian Dumitrescu out_size -= strlen(out);
25675074e1d5SCristian Dumitrescu out += strlen(out);
25685074e1d5SCristian Dumitrescu
25695074e1d5SCristian Dumitrescu for (i = 0; i < info.n_ports_out; i++) {
25705074e1d5SCristian Dumitrescu struct rte_swx_port_out_stats stats;
25715074e1d5SCristian Dumitrescu
25725074e1d5SCristian Dumitrescu rte_swx_ctl_pipeline_port_out_stats_read(p->p, i, &stats);
25735074e1d5SCristian Dumitrescu
257496b37959SCristian Dumitrescu if (i != info.n_ports_out - 1)
25755074e1d5SCristian Dumitrescu snprintf(out, out_size, "\tPort %u:"
25765074e1d5SCristian Dumitrescu " packets %" PRIu64
25775074e1d5SCristian Dumitrescu " bytes %" PRIu64 "\n",
25785074e1d5SCristian Dumitrescu i, stats.n_pkts, stats.n_bytes);
257996b37959SCristian Dumitrescu else
258096b37959SCristian Dumitrescu snprintf(out, out_size, "\tDROP:"
258196b37959SCristian Dumitrescu " packets %" PRIu64
258296b37959SCristian Dumitrescu " bytes %" PRIu64 "\n",
258396b37959SCristian Dumitrescu stats.n_pkts, stats.n_bytes);
258496b37959SCristian Dumitrescu
25855074e1d5SCristian Dumitrescu out_size -= strlen(out);
25865074e1d5SCristian Dumitrescu out += strlen(out);
25875074e1d5SCristian Dumitrescu }
2588742b0a57SCristian Dumitrescu
2589742b0a57SCristian Dumitrescu snprintf(out, out_size, "\nTables:\n");
2590742b0a57SCristian Dumitrescu out_size -= strlen(out);
2591742b0a57SCristian Dumitrescu out += strlen(out);
2592742b0a57SCristian Dumitrescu
2593742b0a57SCristian Dumitrescu for (i = 0; i < info.n_tables; i++) {
2594742b0a57SCristian Dumitrescu struct rte_swx_ctl_table_info table_info;
2595742b0a57SCristian Dumitrescu uint64_t n_pkts_action[info.n_actions];
2596742b0a57SCristian Dumitrescu struct rte_swx_table_stats stats = {
2597742b0a57SCristian Dumitrescu .n_pkts_hit = 0,
2598742b0a57SCristian Dumitrescu .n_pkts_miss = 0,
2599742b0a57SCristian Dumitrescu .n_pkts_action = n_pkts_action,
2600742b0a57SCristian Dumitrescu };
2601742b0a57SCristian Dumitrescu uint32_t j;
2602742b0a57SCristian Dumitrescu
2603742b0a57SCristian Dumitrescu status = rte_swx_ctl_table_info_get(p->p, i, &table_info);
2604742b0a57SCristian Dumitrescu if (status) {
2605742b0a57SCristian Dumitrescu snprintf(out, out_size, "Table info get error.");
2606742b0a57SCristian Dumitrescu return;
2607742b0a57SCristian Dumitrescu }
2608742b0a57SCristian Dumitrescu
2609742b0a57SCristian Dumitrescu status = rte_swx_ctl_pipeline_table_stats_read(p->p, table_info.name, &stats);
2610742b0a57SCristian Dumitrescu if (status) {
2611742b0a57SCristian Dumitrescu snprintf(out, out_size, "Table stats read error.");
2612742b0a57SCristian Dumitrescu return;
2613742b0a57SCristian Dumitrescu }
2614742b0a57SCristian Dumitrescu
2615742b0a57SCristian Dumitrescu snprintf(out, out_size, "\tTable %s:\n"
2616742b0a57SCristian Dumitrescu "\t\tHit (packets): %" PRIu64 "\n"
2617742b0a57SCristian Dumitrescu "\t\tMiss (packets): %" PRIu64 "\n",
2618742b0a57SCristian Dumitrescu table_info.name,
2619742b0a57SCristian Dumitrescu stats.n_pkts_hit,
2620742b0a57SCristian Dumitrescu stats.n_pkts_miss);
2621742b0a57SCristian Dumitrescu out_size -= strlen(out);
2622742b0a57SCristian Dumitrescu out += strlen(out);
2623742b0a57SCristian Dumitrescu
2624742b0a57SCristian Dumitrescu for (j = 0; j < info.n_actions; j++) {
2625742b0a57SCristian Dumitrescu struct rte_swx_ctl_action_info action_info;
2626742b0a57SCristian Dumitrescu
2627742b0a57SCristian Dumitrescu status = rte_swx_ctl_action_info_get(p->p, j, &action_info);
2628742b0a57SCristian Dumitrescu if (status) {
2629742b0a57SCristian Dumitrescu snprintf(out, out_size, "Action info get error.");
2630742b0a57SCristian Dumitrescu return;
2631742b0a57SCristian Dumitrescu }
2632742b0a57SCristian Dumitrescu
2633742b0a57SCristian Dumitrescu snprintf(out, out_size, "\t\tAction %s (packets): %" PRIu64 "\n",
2634742b0a57SCristian Dumitrescu action_info.name,
2635742b0a57SCristian Dumitrescu stats.n_pkts_action[j]);
2636742b0a57SCristian Dumitrescu out_size -= strlen(out);
2637742b0a57SCristian Dumitrescu out += strlen(out);
2638742b0a57SCristian Dumitrescu }
2639742b0a57SCristian Dumitrescu }
26408bd4862fSCristian Dumitrescu
26418bd4862fSCristian Dumitrescu snprintf(out, out_size, "\nLearner tables:\n");
26428bd4862fSCristian Dumitrescu out_size -= strlen(out);
26438bd4862fSCristian Dumitrescu out += strlen(out);
26448bd4862fSCristian Dumitrescu
26458bd4862fSCristian Dumitrescu for (i = 0; i < info.n_learners; i++) {
26468bd4862fSCristian Dumitrescu struct rte_swx_ctl_learner_info learner_info;
26478bd4862fSCristian Dumitrescu uint64_t n_pkts_action[info.n_actions];
26488bd4862fSCristian Dumitrescu struct rte_swx_learner_stats stats = {
26498bd4862fSCristian Dumitrescu .n_pkts_hit = 0,
26508bd4862fSCristian Dumitrescu .n_pkts_miss = 0,
26518bd4862fSCristian Dumitrescu .n_pkts_action = n_pkts_action,
26528bd4862fSCristian Dumitrescu };
26538bd4862fSCristian Dumitrescu uint32_t j;
26548bd4862fSCristian Dumitrescu
26558bd4862fSCristian Dumitrescu status = rte_swx_ctl_learner_info_get(p->p, i, &learner_info);
26568bd4862fSCristian Dumitrescu if (status) {
26578bd4862fSCristian Dumitrescu snprintf(out, out_size, "Learner table info get error.");
26588bd4862fSCristian Dumitrescu return;
26598bd4862fSCristian Dumitrescu }
26608bd4862fSCristian Dumitrescu
26618bd4862fSCristian Dumitrescu status = rte_swx_ctl_pipeline_learner_stats_read(p->p, learner_info.name, &stats);
26628bd4862fSCristian Dumitrescu if (status) {
26638bd4862fSCristian Dumitrescu snprintf(out, out_size, "Learner table stats read error.");
26648bd4862fSCristian Dumitrescu return;
26658bd4862fSCristian Dumitrescu }
26668bd4862fSCristian Dumitrescu
26678bd4862fSCristian Dumitrescu snprintf(out, out_size, "\tLearner table %s:\n"
26688bd4862fSCristian Dumitrescu "\t\tHit (packets): %" PRIu64 "\n"
26698bd4862fSCristian Dumitrescu "\t\tMiss (packets): %" PRIu64 "\n"
26708bd4862fSCristian Dumitrescu "\t\tLearn OK (packets): %" PRIu64 "\n"
26718bd4862fSCristian Dumitrescu "\t\tLearn error (packets): %" PRIu64 "\n"
26728bd4862fSCristian Dumitrescu "\t\tForget (packets): %" PRIu64 "\n",
26738bd4862fSCristian Dumitrescu learner_info.name,
26748bd4862fSCristian Dumitrescu stats.n_pkts_hit,
26758bd4862fSCristian Dumitrescu stats.n_pkts_miss,
26768bd4862fSCristian Dumitrescu stats.n_pkts_learn_ok,
26778bd4862fSCristian Dumitrescu stats.n_pkts_learn_err,
26788bd4862fSCristian Dumitrescu stats.n_pkts_forget);
26798bd4862fSCristian Dumitrescu out_size -= strlen(out);
26808bd4862fSCristian Dumitrescu out += strlen(out);
26818bd4862fSCristian Dumitrescu
26828bd4862fSCristian Dumitrescu for (j = 0; j < info.n_actions; j++) {
26838bd4862fSCristian Dumitrescu struct rte_swx_ctl_action_info action_info;
26848bd4862fSCristian Dumitrescu
26858bd4862fSCristian Dumitrescu status = rte_swx_ctl_action_info_get(p->p, j, &action_info);
26868bd4862fSCristian Dumitrescu if (status) {
26878bd4862fSCristian Dumitrescu snprintf(out, out_size, "Action info get error.");
26888bd4862fSCristian Dumitrescu return;
26898bd4862fSCristian Dumitrescu }
26908bd4862fSCristian Dumitrescu
26918bd4862fSCristian Dumitrescu snprintf(out, out_size, "\t\tAction %s (packets): %" PRIu64 "\n",
26928bd4862fSCristian Dumitrescu action_info.name,
26938bd4862fSCristian Dumitrescu stats.n_pkts_action[j]);
26948bd4862fSCristian Dumitrescu out_size -= strlen(out);
26958bd4862fSCristian Dumitrescu out += strlen(out);
26968bd4862fSCristian Dumitrescu }
26978bd4862fSCristian Dumitrescu }
26985074e1d5SCristian Dumitrescu }
26995074e1d5SCristian Dumitrescu
27005074e1d5SCristian Dumitrescu static const char cmd_thread_pipeline_enable_help[] =
27015074e1d5SCristian Dumitrescu "thread <thread_id> pipeline <pipeline_name> enable\n";
27025074e1d5SCristian Dumitrescu
27035074e1d5SCristian Dumitrescu static void
cmd_thread_pipeline_enable(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)27045074e1d5SCristian Dumitrescu cmd_thread_pipeline_enable(char **tokens,
27055074e1d5SCristian Dumitrescu uint32_t n_tokens,
27065074e1d5SCristian Dumitrescu char *out,
27075074e1d5SCristian Dumitrescu size_t out_size,
27085074e1d5SCristian Dumitrescu void *obj)
27095074e1d5SCristian Dumitrescu {
27105074e1d5SCristian Dumitrescu char *pipeline_name;
27115074e1d5SCristian Dumitrescu struct pipeline *p;
27125074e1d5SCristian Dumitrescu uint32_t thread_id;
27135074e1d5SCristian Dumitrescu int status;
27145074e1d5SCristian Dumitrescu
27155074e1d5SCristian Dumitrescu if (n_tokens != 5) {
27165074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
27175074e1d5SCristian Dumitrescu return;
27185074e1d5SCristian Dumitrescu }
27195074e1d5SCristian Dumitrescu
27205074e1d5SCristian Dumitrescu if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
27215074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
27225074e1d5SCristian Dumitrescu return;
27235074e1d5SCristian Dumitrescu }
27245074e1d5SCristian Dumitrescu
27255074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "pipeline") != 0) {
27265074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
27275074e1d5SCristian Dumitrescu return;
27285074e1d5SCristian Dumitrescu }
27295074e1d5SCristian Dumitrescu
27305074e1d5SCristian Dumitrescu pipeline_name = tokens[3];
27315074e1d5SCristian Dumitrescu p = pipeline_find(obj, pipeline_name);
27325074e1d5SCristian Dumitrescu if (!p || !p->ctl) {
27335074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
27345074e1d5SCristian Dumitrescu return;
27355074e1d5SCristian Dumitrescu }
27365074e1d5SCristian Dumitrescu
27375074e1d5SCristian Dumitrescu if (strcmp(tokens[4], "enable") != 0) {
27385074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
27395074e1d5SCristian Dumitrescu return;
27405074e1d5SCristian Dumitrescu }
27415074e1d5SCristian Dumitrescu
27425074e1d5SCristian Dumitrescu status = thread_pipeline_enable(thread_id, obj, pipeline_name);
27435074e1d5SCristian Dumitrescu if (status) {
27445074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable");
27455074e1d5SCristian Dumitrescu return;
27465074e1d5SCristian Dumitrescu }
27475074e1d5SCristian Dumitrescu }
27485074e1d5SCristian Dumitrescu
27495074e1d5SCristian Dumitrescu static const char cmd_thread_pipeline_disable_help[] =
27505074e1d5SCristian Dumitrescu "thread <thread_id> pipeline <pipeline_name> disable\n";
27515074e1d5SCristian Dumitrescu
27525074e1d5SCristian Dumitrescu static void
cmd_thread_pipeline_disable(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * obj)27535074e1d5SCristian Dumitrescu cmd_thread_pipeline_disable(char **tokens,
27545074e1d5SCristian Dumitrescu uint32_t n_tokens,
27555074e1d5SCristian Dumitrescu char *out,
27565074e1d5SCristian Dumitrescu size_t out_size,
27575074e1d5SCristian Dumitrescu void *obj)
27585074e1d5SCristian Dumitrescu {
27595074e1d5SCristian Dumitrescu struct pipeline *p;
27605074e1d5SCristian Dumitrescu char *pipeline_name;
27615074e1d5SCristian Dumitrescu uint32_t thread_id;
27625074e1d5SCristian Dumitrescu int status;
27635074e1d5SCristian Dumitrescu
27645074e1d5SCristian Dumitrescu if (n_tokens != 5) {
27655074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
27665074e1d5SCristian Dumitrescu return;
27675074e1d5SCristian Dumitrescu }
27685074e1d5SCristian Dumitrescu
27695074e1d5SCristian Dumitrescu if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
27705074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
27715074e1d5SCristian Dumitrescu return;
27725074e1d5SCristian Dumitrescu }
27735074e1d5SCristian Dumitrescu
27745074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "pipeline") != 0) {
27755074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
27765074e1d5SCristian Dumitrescu return;
27775074e1d5SCristian Dumitrescu }
27785074e1d5SCristian Dumitrescu
27795074e1d5SCristian Dumitrescu pipeline_name = tokens[3];
27805074e1d5SCristian Dumitrescu p = pipeline_find(obj, pipeline_name);
27815074e1d5SCristian Dumitrescu if (!p || !p->ctl) {
27825074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
27835074e1d5SCristian Dumitrescu return;
27845074e1d5SCristian Dumitrescu }
27855074e1d5SCristian Dumitrescu
27865074e1d5SCristian Dumitrescu if (strcmp(tokens[4], "disable") != 0) {
27875074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
27885074e1d5SCristian Dumitrescu return;
27895074e1d5SCristian Dumitrescu }
27905074e1d5SCristian Dumitrescu
27915074e1d5SCristian Dumitrescu status = thread_pipeline_disable(thread_id, obj, pipeline_name);
27925074e1d5SCristian Dumitrescu if (status) {
27935074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL,
27945074e1d5SCristian Dumitrescu "thread pipeline disable");
27955074e1d5SCristian Dumitrescu return;
27965074e1d5SCristian Dumitrescu }
27975074e1d5SCristian Dumitrescu }
27985074e1d5SCristian Dumitrescu
27995074e1d5SCristian Dumitrescu static void
cmd_help(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,void * arg __rte_unused)28005074e1d5SCristian Dumitrescu cmd_help(char **tokens,
28015074e1d5SCristian Dumitrescu uint32_t n_tokens,
28025074e1d5SCristian Dumitrescu char *out,
28035074e1d5SCristian Dumitrescu size_t out_size,
28045074e1d5SCristian Dumitrescu void *arg __rte_unused)
28055074e1d5SCristian Dumitrescu {
28065074e1d5SCristian Dumitrescu tokens++;
28075074e1d5SCristian Dumitrescu n_tokens--;
28085074e1d5SCristian Dumitrescu
28095074e1d5SCristian Dumitrescu if (n_tokens == 0) {
28105074e1d5SCristian Dumitrescu snprintf(out, out_size,
28117fef9ef1SYogesh Jangra "Type 'help <command>' for command details.\n\n"
28127fef9ef1SYogesh Jangra "List of commands:\n"
28137fef9ef1SYogesh Jangra "\tmempool\n"
28147fef9ef1SYogesh Jangra "\tlink\n"
2815e2b8dc52SVenkata Suresh Kumar P "\ttap\n"
28167fef9ef1SYogesh Jangra "\tpipeline create\n"
28177fef9ef1SYogesh Jangra "\tpipeline port in\n"
28187fef9ef1SYogesh Jangra "\tpipeline port out\n"
28197fef9ef1SYogesh Jangra "\tpipeline build\n"
282075129cebSChurchill Khangar "\tpipeline table add\n"
282175129cebSChurchill Khangar "\tpipeline table delete\n"
282275129cebSChurchill Khangar "\tpipeline table default\n"
282375129cebSChurchill Khangar "\tpipeline table show\n"
2824598fe0ddSCristian Dumitrescu "\tpipeline selector group add\n"
2825598fe0ddSCristian Dumitrescu "\tpipeline selector group delete\n"
2826598fe0ddSCristian Dumitrescu "\tpipeline selector group member add\n"
2827598fe0ddSCristian Dumitrescu "\tpipeline selector group member delete\n"
2828598fe0ddSCristian Dumitrescu "\tpipeline selector show\n"
28298bd4862fSCristian Dumitrescu "\tpipeline learner default\n"
283075129cebSChurchill Khangar "\tpipeline commit\n"
283175129cebSChurchill Khangar "\tpipeline abort\n"
283264cfcebdSCristian Dumitrescu "\tpipeline regrd\n"
283364cfcebdSCristian Dumitrescu "\tpipeline regwr\n"
2834f38913b7SCristian Dumitrescu "\tpipeline meter profile add\n"
2835f38913b7SCristian Dumitrescu "\tpipeline meter profile delete\n"
2836f38913b7SCristian Dumitrescu "\tpipeline meter reset\n"
2837f38913b7SCristian Dumitrescu "\tpipeline meter set\n"
2838f38913b7SCristian Dumitrescu "\tpipeline meter stats\n"
28397fef9ef1SYogesh Jangra "\tpipeline stats\n"
28407fef9ef1SYogesh Jangra "\tthread pipeline enable\n"
28417fef9ef1SYogesh Jangra "\tthread pipeline disable\n\n");
28425074e1d5SCristian Dumitrescu return;
28435074e1d5SCristian Dumitrescu }
28445074e1d5SCristian Dumitrescu
28455074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "mempool") == 0) {
28465074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_mempool_help);
28475074e1d5SCristian Dumitrescu return;
28485074e1d5SCristian Dumitrescu }
28495074e1d5SCristian Dumitrescu
28505074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "link") == 0) {
28515074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_link_help);
28525074e1d5SCristian Dumitrescu return;
28535074e1d5SCristian Dumitrescu }
28545074e1d5SCristian Dumitrescu
285577a41301SCristian Dumitrescu if (strcmp(tokens[0], "ring") == 0) {
285677a41301SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_ring_help);
285777a41301SCristian Dumitrescu return;
285877a41301SCristian Dumitrescu }
285977a41301SCristian Dumitrescu
2860e2b8dc52SVenkata Suresh Kumar P if (strcmp(tokens[0], "tap") == 0) {
2861e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, "\n%s\n", cmd_tap_help);
2862e2b8dc52SVenkata Suresh Kumar P return;
2863e2b8dc52SVenkata Suresh Kumar P }
2864e2b8dc52SVenkata Suresh Kumar P
28655074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) &&
28667fef9ef1SYogesh Jangra (n_tokens == 2) && (strcmp(tokens[1], "create") == 0)) {
28675074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_create_help);
28685074e1d5SCristian Dumitrescu return;
28695074e1d5SCristian Dumitrescu }
28705074e1d5SCristian Dumitrescu
28715074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) &&
28727fef9ef1SYogesh Jangra (n_tokens == 3) && (strcmp(tokens[1], "port") == 0)) {
28737fef9ef1SYogesh Jangra if (strcmp(tokens[2], "in") == 0) {
28745074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n",
28755074e1d5SCristian Dumitrescu cmd_pipeline_port_in_help);
28765074e1d5SCristian Dumitrescu return;
28775074e1d5SCristian Dumitrescu }
28785074e1d5SCristian Dumitrescu
28797fef9ef1SYogesh Jangra if (strcmp(tokens[2], "out") == 0) {
28805074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n",
28815074e1d5SCristian Dumitrescu cmd_pipeline_port_out_help);
28825074e1d5SCristian Dumitrescu return;
28835074e1d5SCristian Dumitrescu }
28845074e1d5SCristian Dumitrescu }
28855074e1d5SCristian Dumitrescu
28865074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) &&
28877fef9ef1SYogesh Jangra (n_tokens == 2) && (strcmp(tokens[1], "build") == 0)) {
28885074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_build_help);
28895074e1d5SCristian Dumitrescu return;
28905074e1d5SCristian Dumitrescu }
28915074e1d5SCristian Dumitrescu
28925074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) &&
28937fef9ef1SYogesh Jangra (n_tokens == 3) &&
28947fef9ef1SYogesh Jangra (strcmp(tokens[1], "table") == 0) &&
289575129cebSChurchill Khangar (strcmp(tokens[2], "add") == 0)) {
28965074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n",
289775129cebSChurchill Khangar cmd_pipeline_table_add_help);
289875129cebSChurchill Khangar return;
289975129cebSChurchill Khangar }
290075129cebSChurchill Khangar
290175129cebSChurchill Khangar if ((strcmp(tokens[0], "pipeline") == 0) &&
290275129cebSChurchill Khangar (n_tokens == 3) &&
290375129cebSChurchill Khangar (strcmp(tokens[1], "table") == 0) &&
290475129cebSChurchill Khangar (strcmp(tokens[2], "delete") == 0)) {
290575129cebSChurchill Khangar snprintf(out, out_size, "\n%s\n",
290675129cebSChurchill Khangar cmd_pipeline_table_delete_help);
290775129cebSChurchill Khangar return;
290875129cebSChurchill Khangar }
290975129cebSChurchill Khangar
291075129cebSChurchill Khangar if ((strcmp(tokens[0], "pipeline") == 0) &&
291175129cebSChurchill Khangar (n_tokens == 3) &&
291275129cebSChurchill Khangar (strcmp(tokens[1], "table") == 0) &&
291375129cebSChurchill Khangar (strcmp(tokens[2], "default") == 0)) {
291475129cebSChurchill Khangar snprintf(out, out_size, "\n%s\n",
291575129cebSChurchill Khangar cmd_pipeline_table_default_help);
291675129cebSChurchill Khangar return;
291775129cebSChurchill Khangar }
291875129cebSChurchill Khangar
291975129cebSChurchill Khangar if ((strcmp(tokens[0], "pipeline") == 0) &&
292075129cebSChurchill Khangar (n_tokens == 3) &&
292175129cebSChurchill Khangar (strcmp(tokens[1], "table") == 0) &&
292275129cebSChurchill Khangar (strcmp(tokens[2], "show") == 0)) {
292375129cebSChurchill Khangar snprintf(out, out_size, "\n%s\n",
292475129cebSChurchill Khangar cmd_pipeline_table_show_help);
292575129cebSChurchill Khangar return;
292675129cebSChurchill Khangar }
292775129cebSChurchill Khangar
292875129cebSChurchill Khangar if ((strcmp(tokens[0], "pipeline") == 0) &&
2929598fe0ddSCristian Dumitrescu (n_tokens == 4) &&
2930598fe0ddSCristian Dumitrescu (strcmp(tokens[1], "selector") == 0) &&
2931598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "group") == 0) &&
2932598fe0ddSCristian Dumitrescu (strcmp(tokens[3], "add") == 0)) {
2933598fe0ddSCristian Dumitrescu snprintf(out, out_size, "\n%s\n",
2934598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_add_help);
2935598fe0ddSCristian Dumitrescu return;
2936598fe0ddSCristian Dumitrescu }
2937598fe0ddSCristian Dumitrescu
2938598fe0ddSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) &&
2939598fe0ddSCristian Dumitrescu (n_tokens == 4) &&
2940598fe0ddSCristian Dumitrescu (strcmp(tokens[1], "selector") == 0) &&
2941598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "group") == 0) &&
2942598fe0ddSCristian Dumitrescu (strcmp(tokens[3], "delete") == 0)) {
2943598fe0ddSCristian Dumitrescu snprintf(out, out_size, "\n%s\n",
2944598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_delete_help);
2945598fe0ddSCristian Dumitrescu return;
2946598fe0ddSCristian Dumitrescu }
2947598fe0ddSCristian Dumitrescu
2948598fe0ddSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) &&
2949598fe0ddSCristian Dumitrescu (n_tokens == 5) &&
2950598fe0ddSCristian Dumitrescu (strcmp(tokens[1], "selector") == 0) &&
2951598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "group") == 0) &&
2952598fe0ddSCristian Dumitrescu (strcmp(tokens[3], "member") == 0) &&
2953598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "add") == 0)) {
2954598fe0ddSCristian Dumitrescu snprintf(out, out_size, "\n%s\n",
2955598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_add_help);
2956598fe0ddSCristian Dumitrescu return;
2957598fe0ddSCristian Dumitrescu }
2958598fe0ddSCristian Dumitrescu
2959598fe0ddSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) &&
2960598fe0ddSCristian Dumitrescu (n_tokens == 5) &&
2961598fe0ddSCristian Dumitrescu (strcmp(tokens[1], "selector") == 0) &&
2962598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "group") == 0) &&
2963598fe0ddSCristian Dumitrescu (strcmp(tokens[3], "member") == 0) &&
2964598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "delete") == 0)) {
2965598fe0ddSCristian Dumitrescu snprintf(out, out_size, "\n%s\n",
2966598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_delete_help);
2967598fe0ddSCristian Dumitrescu return;
2968598fe0ddSCristian Dumitrescu }
2969598fe0ddSCristian Dumitrescu
2970598fe0ddSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) &&
2971598fe0ddSCristian Dumitrescu (n_tokens == 3) &&
2972598fe0ddSCristian Dumitrescu (strcmp(tokens[1], "selector") == 0) &&
2973598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "show") == 0)) {
2974598fe0ddSCristian Dumitrescu snprintf(out, out_size, "\n%s\n",
2975598fe0ddSCristian Dumitrescu cmd_pipeline_selector_show_help);
2976598fe0ddSCristian Dumitrescu return;
2977598fe0ddSCristian Dumitrescu }
2978598fe0ddSCristian Dumitrescu
2979598fe0ddSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) &&
29808bd4862fSCristian Dumitrescu (n_tokens == 3) &&
29818bd4862fSCristian Dumitrescu (strcmp(tokens[1], "learner") == 0) &&
29828bd4862fSCristian Dumitrescu (strcmp(tokens[2], "default") == 0)) {
29838bd4862fSCristian Dumitrescu snprintf(out, out_size, "\n%s\n",
29848bd4862fSCristian Dumitrescu cmd_pipeline_learner_default_help);
29858bd4862fSCristian Dumitrescu return;
29868bd4862fSCristian Dumitrescu }
29878bd4862fSCristian Dumitrescu
29888bd4862fSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) &&
298975129cebSChurchill Khangar (n_tokens == 2) &&
299075129cebSChurchill Khangar (strcmp(tokens[1], "commit") == 0)) {
299175129cebSChurchill Khangar snprintf(out, out_size, "\n%s\n",
299275129cebSChurchill Khangar cmd_pipeline_commit_help);
299375129cebSChurchill Khangar return;
299475129cebSChurchill Khangar }
299575129cebSChurchill Khangar
299675129cebSChurchill Khangar if ((strcmp(tokens[0], "pipeline") == 0) &&
299775129cebSChurchill Khangar (n_tokens == 2) &&
299875129cebSChurchill Khangar (strcmp(tokens[1], "abort") == 0)) {
299975129cebSChurchill Khangar snprintf(out, out_size, "\n%s\n",
300075129cebSChurchill Khangar cmd_pipeline_abort_help);
30015074e1d5SCristian Dumitrescu return;
30025074e1d5SCristian Dumitrescu }
30035074e1d5SCristian Dumitrescu
30045074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) &&
300564cfcebdSCristian Dumitrescu (n_tokens == 2) && (strcmp(tokens[1], "regrd") == 0)) {
300664cfcebdSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_regrd_help);
300764cfcebdSCristian Dumitrescu return;
300864cfcebdSCristian Dumitrescu }
300964cfcebdSCristian Dumitrescu
301064cfcebdSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) &&
301164cfcebdSCristian Dumitrescu (n_tokens == 2) && (strcmp(tokens[1], "regwr") == 0)) {
301264cfcebdSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_regwr_help);
301364cfcebdSCristian Dumitrescu return;
301464cfcebdSCristian Dumitrescu }
301564cfcebdSCristian Dumitrescu
3016f38913b7SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") &&
3017f38913b7SCristian Dumitrescu (n_tokens == 4) && !strcmp(tokens[1], "meter")
3018f38913b7SCristian Dumitrescu && !strcmp(tokens[2], "profile")
3019f38913b7SCristian Dumitrescu && !strcmp(tokens[3], "add")) {
3020f38913b7SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_profile_add_help);
3021f38913b7SCristian Dumitrescu return;
3022f38913b7SCristian Dumitrescu }
3023f38913b7SCristian Dumitrescu
3024f38913b7SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") &&
3025f38913b7SCristian Dumitrescu (n_tokens == 4) && !strcmp(tokens[1], "meter")
3026f38913b7SCristian Dumitrescu && !strcmp(tokens[2], "profile")
3027f38913b7SCristian Dumitrescu && !strcmp(tokens[3], "delete")) {
3028f38913b7SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_profile_delete_help);
3029f38913b7SCristian Dumitrescu return;
3030f38913b7SCristian Dumitrescu }
3031f38913b7SCristian Dumitrescu
3032f38913b7SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") &&
3033f38913b7SCristian Dumitrescu (n_tokens == 3) && !strcmp(tokens[1], "meter")
3034f38913b7SCristian Dumitrescu && !strcmp(tokens[2], "reset")) {
3035f38913b7SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_reset_help);
3036f38913b7SCristian Dumitrescu return;
3037f38913b7SCristian Dumitrescu }
3038f38913b7SCristian Dumitrescu
3039f38913b7SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") &&
3040f38913b7SCristian Dumitrescu (n_tokens == 3) && !strcmp(tokens[1], "meter")
3041f38913b7SCristian Dumitrescu && !strcmp(tokens[2], "set")) {
3042f38913b7SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_set_help);
3043f38913b7SCristian Dumitrescu return;
3044f38913b7SCristian Dumitrescu }
3045f38913b7SCristian Dumitrescu
3046f38913b7SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") &&
3047f38913b7SCristian Dumitrescu (n_tokens == 3) && !strcmp(tokens[1], "meter")
3048f38913b7SCristian Dumitrescu && !strcmp(tokens[2], "stats")) {
3049f38913b7SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_stats_help);
3050f38913b7SCristian Dumitrescu return;
3051f38913b7SCristian Dumitrescu }
3052f38913b7SCristian Dumitrescu
305364cfcebdSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) &&
30547fef9ef1SYogesh Jangra (n_tokens == 2) && (strcmp(tokens[1], "stats") == 0)) {
30555074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_stats_help);
30565074e1d5SCristian Dumitrescu return;
30575074e1d5SCristian Dumitrescu }
30585074e1d5SCristian Dumitrescu
30595074e1d5SCristian Dumitrescu if ((n_tokens == 3) &&
30605074e1d5SCristian Dumitrescu (strcmp(tokens[0], "thread") == 0) &&
30615074e1d5SCristian Dumitrescu (strcmp(tokens[1], "pipeline") == 0)) {
30625074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "enable") == 0) {
30635074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n",
30645074e1d5SCristian Dumitrescu cmd_thread_pipeline_enable_help);
30655074e1d5SCristian Dumitrescu return;
30665074e1d5SCristian Dumitrescu }
30675074e1d5SCristian Dumitrescu
30685074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "disable") == 0) {
30695074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n",
30705074e1d5SCristian Dumitrescu cmd_thread_pipeline_disable_help);
30715074e1d5SCristian Dumitrescu return;
30725074e1d5SCristian Dumitrescu }
30735074e1d5SCristian Dumitrescu }
30745074e1d5SCristian Dumitrescu
30755074e1d5SCristian Dumitrescu snprintf(out, out_size, "Invalid command\n");
30765074e1d5SCristian Dumitrescu }
30775074e1d5SCristian Dumitrescu
30785074e1d5SCristian Dumitrescu void
cli_process(char * in,char * out,size_t out_size,void * obj)30795074e1d5SCristian Dumitrescu cli_process(char *in, char *out, size_t out_size, void *obj)
30805074e1d5SCristian Dumitrescu {
30815074e1d5SCristian Dumitrescu char *tokens[CMD_MAX_TOKENS];
30825074e1d5SCristian Dumitrescu uint32_t n_tokens = RTE_DIM(tokens);
30835074e1d5SCristian Dumitrescu int status;
30845074e1d5SCristian Dumitrescu
30855074e1d5SCristian Dumitrescu if (is_comment(in))
30865074e1d5SCristian Dumitrescu return;
30875074e1d5SCristian Dumitrescu
30885074e1d5SCristian Dumitrescu status = parse_tokenize_string(in, tokens, &n_tokens);
30895074e1d5SCristian Dumitrescu if (status) {
30905074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
30915074e1d5SCristian Dumitrescu return;
30925074e1d5SCristian Dumitrescu }
30935074e1d5SCristian Dumitrescu
30945074e1d5SCristian Dumitrescu if (n_tokens == 0)
30955074e1d5SCristian Dumitrescu return;
30965074e1d5SCristian Dumitrescu
30975074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "help") == 0) {
30985074e1d5SCristian Dumitrescu cmd_help(tokens, n_tokens, out, out_size, obj);
30995074e1d5SCristian Dumitrescu return;
31005074e1d5SCristian Dumitrescu }
31015074e1d5SCristian Dumitrescu
31025074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "mempool") == 0) {
31035074e1d5SCristian Dumitrescu cmd_mempool(tokens, n_tokens, out, out_size, obj);
31045074e1d5SCristian Dumitrescu return;
31055074e1d5SCristian Dumitrescu }
31065074e1d5SCristian Dumitrescu
31075074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "link") == 0) {
3108821848f5SCristian Dumitrescu if ((n_tokens >= 2) && (strcmp(tokens[1], "show") == 0)) {
31095074e1d5SCristian Dumitrescu cmd_link_show(tokens, n_tokens, out, out_size, obj);
31105074e1d5SCristian Dumitrescu return;
31115074e1d5SCristian Dumitrescu }
31125074e1d5SCristian Dumitrescu
31135074e1d5SCristian Dumitrescu cmd_link(tokens, n_tokens, out, out_size, obj);
31145074e1d5SCristian Dumitrescu return;
31155074e1d5SCristian Dumitrescu }
31165074e1d5SCristian Dumitrescu
311777a41301SCristian Dumitrescu if (strcmp(tokens[0], "ring") == 0) {
311877a41301SCristian Dumitrescu cmd_ring(tokens, n_tokens, out, out_size, obj);
311977a41301SCristian Dumitrescu return;
312077a41301SCristian Dumitrescu }
312177a41301SCristian Dumitrescu
3122e2b8dc52SVenkata Suresh Kumar P if (strcmp(tokens[0], "tap") == 0) {
3123e2b8dc52SVenkata Suresh Kumar P cmd_tap(tokens, n_tokens, out, out_size, obj);
3124e2b8dc52SVenkata Suresh Kumar P return;
3125e2b8dc52SVenkata Suresh Kumar P }
3126e2b8dc52SVenkata Suresh Kumar P
31275074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "pipeline") == 0) {
31285074e1d5SCristian Dumitrescu if ((n_tokens >= 3) &&
31295074e1d5SCristian Dumitrescu (strcmp(tokens[2], "create") == 0)) {
31305074e1d5SCristian Dumitrescu cmd_pipeline_create(tokens, n_tokens, out, out_size,
31315074e1d5SCristian Dumitrescu obj);
31325074e1d5SCristian Dumitrescu return;
31335074e1d5SCristian Dumitrescu }
31345074e1d5SCristian Dumitrescu
31355074e1d5SCristian Dumitrescu if ((n_tokens >= 4) &&
31365074e1d5SCristian Dumitrescu (strcmp(tokens[2], "port") == 0) &&
31375074e1d5SCristian Dumitrescu (strcmp(tokens[3], "in") == 0)) {
31385074e1d5SCristian Dumitrescu cmd_pipeline_port_in(tokens, n_tokens, out, out_size,
31395074e1d5SCristian Dumitrescu obj);
31405074e1d5SCristian Dumitrescu return;
31415074e1d5SCristian Dumitrescu }
31425074e1d5SCristian Dumitrescu
31435074e1d5SCristian Dumitrescu if ((n_tokens >= 4) &&
31445074e1d5SCristian Dumitrescu (strcmp(tokens[2], "port") == 0) &&
31455074e1d5SCristian Dumitrescu (strcmp(tokens[3], "out") == 0)) {
31465074e1d5SCristian Dumitrescu cmd_pipeline_port_out(tokens, n_tokens, out, out_size,
31475074e1d5SCristian Dumitrescu obj);
31485074e1d5SCristian Dumitrescu return;
31495074e1d5SCristian Dumitrescu }
31505074e1d5SCristian Dumitrescu
31515074e1d5SCristian Dumitrescu if ((n_tokens >= 3) &&
31525074e1d5SCristian Dumitrescu (strcmp(tokens[2], "build") == 0)) {
31535074e1d5SCristian Dumitrescu cmd_pipeline_build(tokens, n_tokens, out, out_size,
31545074e1d5SCristian Dumitrescu obj);
31555074e1d5SCristian Dumitrescu return;
31565074e1d5SCristian Dumitrescu }
31575074e1d5SCristian Dumitrescu
315875129cebSChurchill Khangar if ((n_tokens >= 5) &&
315975129cebSChurchill Khangar (strcmp(tokens[2], "table") == 0) &&
316075129cebSChurchill Khangar (strcmp(tokens[4], "add") == 0)) {
316175129cebSChurchill Khangar cmd_pipeline_table_add(tokens, n_tokens, out,
316275129cebSChurchill Khangar out_size, obj);
316375129cebSChurchill Khangar return;
316475129cebSChurchill Khangar }
316575129cebSChurchill Khangar
316675129cebSChurchill Khangar if ((n_tokens >= 5) &&
316775129cebSChurchill Khangar (strcmp(tokens[2], "table") == 0) &&
316875129cebSChurchill Khangar (strcmp(tokens[4], "delete") == 0)) {
316975129cebSChurchill Khangar cmd_pipeline_table_delete(tokens, n_tokens, out,
317075129cebSChurchill Khangar out_size, obj);
317175129cebSChurchill Khangar return;
317275129cebSChurchill Khangar }
317375129cebSChurchill Khangar
317475129cebSChurchill Khangar if ((n_tokens >= 5) &&
317575129cebSChurchill Khangar (strcmp(tokens[2], "table") == 0) &&
317675129cebSChurchill Khangar (strcmp(tokens[4], "default") == 0)) {
317775129cebSChurchill Khangar cmd_pipeline_table_default(tokens, n_tokens, out,
317875129cebSChurchill Khangar out_size, obj);
317975129cebSChurchill Khangar return;
318075129cebSChurchill Khangar }
318175129cebSChurchill Khangar
318275129cebSChurchill Khangar if ((n_tokens >= 5) &&
318375129cebSChurchill Khangar (strcmp(tokens[2], "table") == 0) &&
318475129cebSChurchill Khangar (strcmp(tokens[4], "show") == 0)) {
318575129cebSChurchill Khangar cmd_pipeline_table_show(tokens, n_tokens, out,
318675129cebSChurchill Khangar out_size, obj);
318775129cebSChurchill Khangar return;
318875129cebSChurchill Khangar }
318975129cebSChurchill Khangar
3190598fe0ddSCristian Dumitrescu if ((n_tokens >= 6) &&
3191598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "selector") == 0) &&
3192598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "group") == 0) &&
3193598fe0ddSCristian Dumitrescu (strcmp(tokens[5], "add") == 0)) {
3194598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_add(tokens, n_tokens, out,
3195598fe0ddSCristian Dumitrescu out_size, obj);
3196598fe0ddSCristian Dumitrescu return;
3197598fe0ddSCristian Dumitrescu }
3198598fe0ddSCristian Dumitrescu
3199598fe0ddSCristian Dumitrescu if ((n_tokens >= 6) &&
3200598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "selector") == 0) &&
3201598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "group") == 0) &&
3202598fe0ddSCristian Dumitrescu (strcmp(tokens[5], "delete") == 0)) {
3203598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_delete(tokens, n_tokens, out,
3204598fe0ddSCristian Dumitrescu out_size, obj);
3205598fe0ddSCristian Dumitrescu return;
3206598fe0ddSCristian Dumitrescu }
3207598fe0ddSCristian Dumitrescu
3208598fe0ddSCristian Dumitrescu if ((n_tokens >= 7) &&
3209598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "selector") == 0) &&
3210598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "group") == 0) &&
3211598fe0ddSCristian Dumitrescu (strcmp(tokens[5], "member") == 0) &&
3212598fe0ddSCristian Dumitrescu (strcmp(tokens[6], "add") == 0)) {
3213598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_add(tokens, n_tokens, out,
3214598fe0ddSCristian Dumitrescu out_size, obj);
3215598fe0ddSCristian Dumitrescu return;
3216598fe0ddSCristian Dumitrescu }
3217598fe0ddSCristian Dumitrescu
3218598fe0ddSCristian Dumitrescu if ((n_tokens >= 7) &&
3219598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "selector") == 0) &&
3220598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "group") == 0) &&
3221598fe0ddSCristian Dumitrescu (strcmp(tokens[5], "member") == 0) &&
3222598fe0ddSCristian Dumitrescu (strcmp(tokens[6], "delete") == 0)) {
3223598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_delete(tokens, n_tokens, out,
3224598fe0ddSCristian Dumitrescu out_size, obj);
3225598fe0ddSCristian Dumitrescu return;
3226598fe0ddSCristian Dumitrescu }
3227598fe0ddSCristian Dumitrescu
3228598fe0ddSCristian Dumitrescu if ((n_tokens >= 5) &&
3229598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "selector") == 0) &&
3230598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "show") == 0)) {
3231598fe0ddSCristian Dumitrescu cmd_pipeline_selector_show(tokens, n_tokens, out,
3232598fe0ddSCristian Dumitrescu out_size, obj);
3233598fe0ddSCristian Dumitrescu return;
3234598fe0ddSCristian Dumitrescu }
3235598fe0ddSCristian Dumitrescu
32368bd4862fSCristian Dumitrescu if ((n_tokens >= 5) &&
32378bd4862fSCristian Dumitrescu (strcmp(tokens[2], "learner") == 0) &&
32388bd4862fSCristian Dumitrescu (strcmp(tokens[4], "default") == 0)) {
32398bd4862fSCristian Dumitrescu cmd_pipeline_learner_default(tokens, n_tokens, out,
32408bd4862fSCristian Dumitrescu out_size, obj);
32418bd4862fSCristian Dumitrescu return;
32428bd4862fSCristian Dumitrescu }
32438bd4862fSCristian Dumitrescu
32445074e1d5SCristian Dumitrescu if ((n_tokens >= 3) &&
324575129cebSChurchill Khangar (strcmp(tokens[2], "commit") == 0)) {
324675129cebSChurchill Khangar cmd_pipeline_commit(tokens, n_tokens, out,
324775129cebSChurchill Khangar out_size, obj);
324875129cebSChurchill Khangar return;
324975129cebSChurchill Khangar }
325075129cebSChurchill Khangar
325175129cebSChurchill Khangar if ((n_tokens >= 3) &&
325275129cebSChurchill Khangar (strcmp(tokens[2], "abort") == 0)) {
325375129cebSChurchill Khangar cmd_pipeline_abort(tokens, n_tokens, out,
32545074e1d5SCristian Dumitrescu out_size, obj);
32555074e1d5SCristian Dumitrescu return;
32565074e1d5SCristian Dumitrescu }
32575074e1d5SCristian Dumitrescu
32585074e1d5SCristian Dumitrescu if ((n_tokens >= 3) &&
325964cfcebdSCristian Dumitrescu (strcmp(tokens[2], "regrd") == 0)) {
326064cfcebdSCristian Dumitrescu cmd_pipeline_regrd(tokens, n_tokens, out, out_size, obj);
326164cfcebdSCristian Dumitrescu return;
326264cfcebdSCristian Dumitrescu }
326364cfcebdSCristian Dumitrescu
326464cfcebdSCristian Dumitrescu if ((n_tokens >= 3) &&
326564cfcebdSCristian Dumitrescu (strcmp(tokens[2], "regwr") == 0)) {
326664cfcebdSCristian Dumitrescu cmd_pipeline_regwr(tokens, n_tokens, out, out_size, obj);
326764cfcebdSCristian Dumitrescu return;
326864cfcebdSCristian Dumitrescu }
326964cfcebdSCristian Dumitrescu
3270f38913b7SCristian Dumitrescu if ((n_tokens >= 6) &&
3271f38913b7SCristian Dumitrescu (strcmp(tokens[2], "meter") == 0) &&
3272f38913b7SCristian Dumitrescu (strcmp(tokens[3], "profile") == 0) &&
3273f38913b7SCristian Dumitrescu (strcmp(tokens[5], "add") == 0)) {
3274f38913b7SCristian Dumitrescu cmd_pipeline_meter_profile_add(tokens, n_tokens, out, out_size, obj);
3275f38913b7SCristian Dumitrescu return;
3276f38913b7SCristian Dumitrescu }
3277f38913b7SCristian Dumitrescu
3278f38913b7SCristian Dumitrescu if ((n_tokens >= 6) &&
3279f38913b7SCristian Dumitrescu (strcmp(tokens[2], "meter") == 0) &&
3280f38913b7SCristian Dumitrescu (strcmp(tokens[3], "profile") == 0) &&
3281f38913b7SCristian Dumitrescu (strcmp(tokens[5], "delete") == 0)) {
3282f38913b7SCristian Dumitrescu cmd_pipeline_meter_profile_delete(tokens, n_tokens, out, out_size, obj);
3283f38913b7SCristian Dumitrescu return;
3284f38913b7SCristian Dumitrescu }
3285f38913b7SCristian Dumitrescu
3286f38913b7SCristian Dumitrescu if ((n_tokens >= 9) &&
3287f38913b7SCristian Dumitrescu (strcmp(tokens[2], "meter") == 0) &&
3288f38913b7SCristian Dumitrescu (strcmp(tokens[8], "reset") == 0)) {
3289f38913b7SCristian Dumitrescu cmd_pipeline_meter_reset(tokens, n_tokens, out, out_size, obj);
3290f38913b7SCristian Dumitrescu return;
3291f38913b7SCristian Dumitrescu }
3292f38913b7SCristian Dumitrescu
3293f38913b7SCristian Dumitrescu if ((n_tokens >= 9) &&
3294f38913b7SCristian Dumitrescu (strcmp(tokens[2], "meter") == 0) &&
3295f38913b7SCristian Dumitrescu (strcmp(tokens[8], "set") == 0)) {
3296f38913b7SCristian Dumitrescu cmd_pipeline_meter_set(tokens, n_tokens, out, out_size, obj);
3297f38913b7SCristian Dumitrescu return;
3298f38913b7SCristian Dumitrescu }
3299f38913b7SCristian Dumitrescu
3300f38913b7SCristian Dumitrescu if ((n_tokens >= 9) &&
3301f38913b7SCristian Dumitrescu (strcmp(tokens[2], "meter") == 0) &&
3302f38913b7SCristian Dumitrescu (strcmp(tokens[8], "stats") == 0)) {
3303f38913b7SCristian Dumitrescu cmd_pipeline_meter_stats(tokens, n_tokens, out, out_size, obj);
3304f38913b7SCristian Dumitrescu return;
3305f38913b7SCristian Dumitrescu }
3306f38913b7SCristian Dumitrescu
330764cfcebdSCristian Dumitrescu if ((n_tokens >= 3) &&
33085074e1d5SCristian Dumitrescu (strcmp(tokens[2], "stats") == 0)) {
33095074e1d5SCristian Dumitrescu cmd_pipeline_stats(tokens, n_tokens, out, out_size,
33105074e1d5SCristian Dumitrescu obj);
33115074e1d5SCristian Dumitrescu return;
33125074e1d5SCristian Dumitrescu }
33135074e1d5SCristian Dumitrescu }
33145074e1d5SCristian Dumitrescu
33155074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "thread") == 0) {
33165074e1d5SCristian Dumitrescu if ((n_tokens >= 5) &&
33175074e1d5SCristian Dumitrescu (strcmp(tokens[4], "enable") == 0)) {
33185074e1d5SCristian Dumitrescu cmd_thread_pipeline_enable(tokens, n_tokens,
33195074e1d5SCristian Dumitrescu out, out_size, obj);
33205074e1d5SCristian Dumitrescu return;
33215074e1d5SCristian Dumitrescu }
33225074e1d5SCristian Dumitrescu
33235074e1d5SCristian Dumitrescu if ((n_tokens >= 5) &&
33245074e1d5SCristian Dumitrescu (strcmp(tokens[4], "disable") == 0)) {
33255074e1d5SCristian Dumitrescu cmd_thread_pipeline_disable(tokens, n_tokens,
33265074e1d5SCristian Dumitrescu out, out_size, obj);
33275074e1d5SCristian Dumitrescu return;
33285074e1d5SCristian Dumitrescu }
33295074e1d5SCristian Dumitrescu }
33305074e1d5SCristian Dumitrescu
33315074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
33325074e1d5SCristian Dumitrescu }
33335074e1d5SCristian Dumitrescu
33345074e1d5SCristian Dumitrescu int
cli_script_process(const char * file_name,size_t msg_in_len_max,size_t msg_out_len_max,void * obj)33355074e1d5SCristian Dumitrescu cli_script_process(const char *file_name,
33365074e1d5SCristian Dumitrescu size_t msg_in_len_max,
33375074e1d5SCristian Dumitrescu size_t msg_out_len_max,
33385074e1d5SCristian Dumitrescu void *obj)
33395074e1d5SCristian Dumitrescu {
33405074e1d5SCristian Dumitrescu char *msg_in = NULL, *msg_out = NULL;
33415074e1d5SCristian Dumitrescu FILE *f = NULL;
33425074e1d5SCristian Dumitrescu
33435074e1d5SCristian Dumitrescu /* Check input arguments */
33445074e1d5SCristian Dumitrescu if ((file_name == NULL) ||
33455074e1d5SCristian Dumitrescu (strlen(file_name) == 0) ||
33465074e1d5SCristian Dumitrescu (msg_in_len_max == 0) ||
33475074e1d5SCristian Dumitrescu (msg_out_len_max == 0))
33485074e1d5SCristian Dumitrescu return -EINVAL;
33495074e1d5SCristian Dumitrescu
33505074e1d5SCristian Dumitrescu msg_in = malloc(msg_in_len_max + 1);
33515074e1d5SCristian Dumitrescu msg_out = malloc(msg_out_len_max + 1);
33525074e1d5SCristian Dumitrescu if ((msg_in == NULL) ||
33535074e1d5SCristian Dumitrescu (msg_out == NULL)) {
33545074e1d5SCristian Dumitrescu free(msg_out);
33555074e1d5SCristian Dumitrescu free(msg_in);
33565074e1d5SCristian Dumitrescu return -ENOMEM;
33575074e1d5SCristian Dumitrescu }
33585074e1d5SCristian Dumitrescu
33595074e1d5SCristian Dumitrescu /* Open input file */
33605074e1d5SCristian Dumitrescu f = fopen(file_name, "r");
33615074e1d5SCristian Dumitrescu if (f == NULL) {
33625074e1d5SCristian Dumitrescu free(msg_out);
33635074e1d5SCristian Dumitrescu free(msg_in);
33645074e1d5SCristian Dumitrescu return -EIO;
33655074e1d5SCristian Dumitrescu }
33665074e1d5SCristian Dumitrescu
33675074e1d5SCristian Dumitrescu /* Read file */
33685074e1d5SCristian Dumitrescu for ( ; ; ) {
33695074e1d5SCristian Dumitrescu if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
33705074e1d5SCristian Dumitrescu break;
33715074e1d5SCristian Dumitrescu
33725074e1d5SCristian Dumitrescu printf("%s", msg_in);
33735074e1d5SCristian Dumitrescu msg_out[0] = 0;
33745074e1d5SCristian Dumitrescu
33755074e1d5SCristian Dumitrescu cli_process(msg_in,
33765074e1d5SCristian Dumitrescu msg_out,
33775074e1d5SCristian Dumitrescu msg_out_len_max,
33785074e1d5SCristian Dumitrescu obj);
33795074e1d5SCristian Dumitrescu
33805074e1d5SCristian Dumitrescu if (strlen(msg_out))
33815074e1d5SCristian Dumitrescu printf("%s", msg_out);
33825074e1d5SCristian Dumitrescu }
33835074e1d5SCristian Dumitrescu
33845074e1d5SCristian Dumitrescu /* Close file */
33855074e1d5SCristian Dumitrescu fclose(f);
33865074e1d5SCristian Dumitrescu free(msg_out);
33875074e1d5SCristian Dumitrescu free(msg_in);
33885074e1d5SCristian Dumitrescu return 0;
33895074e1d5SCristian Dumitrescu }
3390