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 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 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 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 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 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 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 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 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 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 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 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 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 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 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[] = 987*68b95704SCristian Dumitrescu "pipeline <pipeline_name> build lib <lib_file> io <iospec_file> numa <numa_node>\n"; 9885074e1d5SCristian Dumitrescu 9895074e1d5SCristian Dumitrescu static void 9905074e1d5SCristian Dumitrescu cmd_pipeline_build(char **tokens, 9915074e1d5SCristian Dumitrescu uint32_t n_tokens, 9925074e1d5SCristian Dumitrescu char *out, 9935074e1d5SCristian Dumitrescu size_t out_size, 994*68b95704SCristian Dumitrescu void *obj __rte_unused) 9955074e1d5SCristian Dumitrescu { 996*68b95704SCristian Dumitrescu struct rte_swx_pipeline *p = NULL; 997*68b95704SCristian Dumitrescu struct rte_swx_ctl_pipeline *ctl = NULL; 998*68b95704SCristian Dumitrescu char *pipeline_name, *lib_file_name, *iospec_file_name; 999*68b95704SCristian Dumitrescu FILE *iospec_file = NULL; 1000*68b95704SCristian Dumitrescu uint32_t numa_node = 0; 1001*68b95704SCristian Dumitrescu int status = 0; 10025074e1d5SCristian Dumitrescu 1003*68b95704SCristian Dumitrescu /* Parsing. */ 1004*68b95704SCristian Dumitrescu if (n_tokens != 9) { 10055074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 10065074e1d5SCristian Dumitrescu return; 10075074e1d5SCristian Dumitrescu } 10085074e1d5SCristian Dumitrescu 1009*68b95704SCristian Dumitrescu pipeline_name = tokens[1]; 1010*68b95704SCristian Dumitrescu 1011*68b95704SCristian Dumitrescu if (strcmp(tokens[2], "build")) { 1012*68b95704SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "build"); 10135074e1d5SCristian Dumitrescu return; 10145074e1d5SCristian Dumitrescu } 10155074e1d5SCristian Dumitrescu 1016*68b95704SCristian Dumitrescu if (strcmp(tokens[3], "lib")) { 1017*68b95704SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "lib"); 10185074e1d5SCristian Dumitrescu return; 10195074e1d5SCristian Dumitrescu } 10205074e1d5SCristian Dumitrescu 1021*68b95704SCristian Dumitrescu lib_file_name = tokens[4]; 1022*68b95704SCristian Dumitrescu 1023*68b95704SCristian Dumitrescu if (strcmp(tokens[5], "io")) { 1024*68b95704SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "io"); 1025*68b95704SCristian Dumitrescu return; 1026*68b95704SCristian Dumitrescu } 1027*68b95704SCristian Dumitrescu 1028*68b95704SCristian Dumitrescu iospec_file_name = tokens[6]; 1029*68b95704SCristian Dumitrescu 1030*68b95704SCristian Dumitrescu if (strcmp(tokens[7], "numa")) { 1031*68b95704SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "numa"); 1032*68b95704SCristian Dumitrescu return; 1033*68b95704SCristian Dumitrescu } 1034*68b95704SCristian Dumitrescu 1035*68b95704SCristian Dumitrescu if (parser_read_uint32(&numa_node, tokens[8])) { 1036*68b95704SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "numa_node"); 1037*68b95704SCristian Dumitrescu return; 1038*68b95704SCristian Dumitrescu } 1039*68b95704SCristian Dumitrescu 1040*68b95704SCristian Dumitrescu /* I/O spec file open. */ 1041*68b95704SCristian Dumitrescu iospec_file = fopen(iospec_file_name, "r"); 1042*68b95704SCristian Dumitrescu if (!iospec_file) { 1043*68b95704SCristian Dumitrescu snprintf(out, out_size, "Cannot open file \"%s\".\n", iospec_file_name); 1044*68b95704SCristian Dumitrescu return; 1045*68b95704SCristian Dumitrescu } 1046*68b95704SCristian Dumitrescu 1047*68b95704SCristian Dumitrescu status = rte_swx_pipeline_build_from_lib(&p, 1048*68b95704SCristian Dumitrescu pipeline_name, 1049*68b95704SCristian Dumitrescu lib_file_name, 1050*68b95704SCristian Dumitrescu iospec_file, 1051*68b95704SCristian Dumitrescu (int)numa_node); 10525074e1d5SCristian Dumitrescu if (status) { 1053*68b95704SCristian Dumitrescu snprintf(out, out_size, "Pipeline build failed (%d).", status); 1054*68b95704SCristian Dumitrescu goto free; 10555074e1d5SCristian Dumitrescu } 10565074e1d5SCristian Dumitrescu 1057*68b95704SCristian Dumitrescu ctl = rte_swx_ctl_pipeline_create(p); 1058*68b95704SCristian Dumitrescu if (!ctl) { 10595074e1d5SCristian Dumitrescu snprintf(out, out_size, "Pipeline control create failed."); 1060*68b95704SCristian Dumitrescu goto free; 10615074e1d5SCristian Dumitrescu } 1062*68b95704SCristian Dumitrescu 1063*68b95704SCristian Dumitrescu free: 1064*68b95704SCristian Dumitrescu if (status) 1065*68b95704SCristian Dumitrescu rte_swx_pipeline_free(p); 1066*68b95704SCristian Dumitrescu 1067*68b95704SCristian Dumitrescu if (iospec_file) 1068*68b95704SCristian Dumitrescu fclose(iospec_file); 10695074e1d5SCristian Dumitrescu } 10705074e1d5SCristian Dumitrescu 1071275ebefeSCristian Dumitrescu static void 1072275ebefeSCristian Dumitrescu table_entry_free(struct rte_swx_table_entry *entry) 1073275ebefeSCristian Dumitrescu { 1074275ebefeSCristian Dumitrescu if (!entry) 1075275ebefeSCristian Dumitrescu return; 1076275ebefeSCristian Dumitrescu 1077275ebefeSCristian Dumitrescu free(entry->key); 1078275ebefeSCristian Dumitrescu free(entry->key_mask); 1079275ebefeSCristian Dumitrescu free(entry->action_data); 1080275ebefeSCristian Dumitrescu free(entry); 1081275ebefeSCristian Dumitrescu } 1082275ebefeSCristian Dumitrescu 108375129cebSChurchill Khangar #ifndef MAX_LINE_SIZE 108475129cebSChurchill Khangar #define MAX_LINE_SIZE 2048 108575129cebSChurchill Khangar #endif 108675129cebSChurchill Khangar 108775129cebSChurchill Khangar static int 108875129cebSChurchill Khangar pipeline_table_entries_add(struct rte_swx_ctl_pipeline *p, 108975129cebSChurchill Khangar const char *table_name, 109075129cebSChurchill Khangar FILE *file, 109175129cebSChurchill Khangar uint32_t *file_line_number) 109275129cebSChurchill Khangar { 109375129cebSChurchill Khangar char *line = NULL; 109475129cebSChurchill Khangar uint32_t line_id = 0; 109575129cebSChurchill Khangar int status = 0; 109675129cebSChurchill Khangar 109775129cebSChurchill Khangar /* Buffer allocation. */ 109875129cebSChurchill Khangar line = malloc(MAX_LINE_SIZE); 109975129cebSChurchill Khangar if (!line) 110075129cebSChurchill Khangar return -ENOMEM; 110175129cebSChurchill Khangar 110275129cebSChurchill Khangar /* File read. */ 110375129cebSChurchill Khangar for (line_id = 1; ; line_id++) { 110475129cebSChurchill Khangar struct rte_swx_table_entry *entry; 110575129cebSChurchill Khangar int is_blank_or_comment; 110675129cebSChurchill Khangar 110775129cebSChurchill Khangar if (fgets(line, MAX_LINE_SIZE, file) == NULL) 110875129cebSChurchill Khangar break; 110975129cebSChurchill Khangar 111075129cebSChurchill Khangar entry = rte_swx_ctl_pipeline_table_entry_read(p, 111175129cebSChurchill Khangar table_name, 111275129cebSChurchill Khangar line, 111375129cebSChurchill Khangar &is_blank_or_comment); 111475129cebSChurchill Khangar if (!entry) { 111575129cebSChurchill Khangar if (is_blank_or_comment) 111675129cebSChurchill Khangar continue; 111775129cebSChurchill Khangar 111875129cebSChurchill Khangar status = -EINVAL; 111975129cebSChurchill Khangar goto error; 112075129cebSChurchill Khangar } 112175129cebSChurchill Khangar 112275129cebSChurchill Khangar status = rte_swx_ctl_pipeline_table_entry_add(p, 112375129cebSChurchill Khangar table_name, 112475129cebSChurchill Khangar entry); 112575129cebSChurchill Khangar table_entry_free(entry); 112675129cebSChurchill Khangar if (status) 112775129cebSChurchill Khangar goto error; 112875129cebSChurchill Khangar } 112975129cebSChurchill Khangar 113075129cebSChurchill Khangar error: 113175129cebSChurchill Khangar free(line); 113275129cebSChurchill Khangar *file_line_number = line_id; 113375129cebSChurchill Khangar return status; 113475129cebSChurchill Khangar } 113575129cebSChurchill Khangar 113675129cebSChurchill Khangar static const char cmd_pipeline_table_add_help[] = 113775129cebSChurchill Khangar "pipeline <pipeline_name> table <table_name> add <file_name>\n"; 11385074e1d5SCristian Dumitrescu 11395074e1d5SCristian Dumitrescu static void 114075129cebSChurchill Khangar cmd_pipeline_table_add(char **tokens, 11415074e1d5SCristian Dumitrescu uint32_t n_tokens, 11425074e1d5SCristian Dumitrescu char *out, 11435074e1d5SCristian Dumitrescu size_t out_size, 11445074e1d5SCristian Dumitrescu void *obj) 11455074e1d5SCristian Dumitrescu { 11465074e1d5SCristian Dumitrescu struct pipeline *p; 114775129cebSChurchill Khangar char *pipeline_name, *table_name, *file_name; 114875129cebSChurchill Khangar FILE *file = NULL; 114975129cebSChurchill Khangar uint32_t file_line_number = 0; 11505074e1d5SCristian Dumitrescu int status; 11515074e1d5SCristian Dumitrescu 115275129cebSChurchill Khangar if (n_tokens != 6) { 11535074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 11545074e1d5SCristian Dumitrescu return; 11555074e1d5SCristian Dumitrescu } 11565074e1d5SCristian Dumitrescu 11575074e1d5SCristian Dumitrescu pipeline_name = tokens[1]; 11585074e1d5SCristian Dumitrescu p = pipeline_find(obj, pipeline_name); 11595074e1d5SCristian Dumitrescu if (!p || !p->ctl) { 11605074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 11615074e1d5SCristian Dumitrescu return; 11625074e1d5SCristian Dumitrescu } 11635074e1d5SCristian Dumitrescu 116475129cebSChurchill Khangar table_name = tokens[3]; 116575129cebSChurchill Khangar 116675129cebSChurchill Khangar file_name = tokens[5]; 116775129cebSChurchill Khangar file = fopen(file_name, "r"); 116875129cebSChurchill Khangar if (!file) { 116975129cebSChurchill Khangar snprintf(out, out_size, "Cannot open file %s.\n", file_name); 117075129cebSChurchill Khangar return; 117175129cebSChurchill Khangar } 117275129cebSChurchill Khangar 117375129cebSChurchill Khangar status = pipeline_table_entries_add(p->ctl, 117475129cebSChurchill Khangar table_name, 117575129cebSChurchill Khangar file, 117675129cebSChurchill Khangar &file_line_number); 117775129cebSChurchill Khangar if (status) 117875129cebSChurchill Khangar snprintf(out, out_size, "Invalid entry in file %s at line %u\n", 117975129cebSChurchill Khangar file_name, 118075129cebSChurchill Khangar file_line_number); 118175129cebSChurchill Khangar 118275129cebSChurchill Khangar fclose(file); 118375129cebSChurchill Khangar } 118475129cebSChurchill Khangar 118575129cebSChurchill Khangar static int 118675129cebSChurchill Khangar pipeline_table_entries_delete(struct rte_swx_ctl_pipeline *p, 118775129cebSChurchill Khangar const char *table_name, 118875129cebSChurchill Khangar FILE *file, 118975129cebSChurchill Khangar uint32_t *file_line_number) 119075129cebSChurchill Khangar { 119175129cebSChurchill Khangar char *line = NULL; 119275129cebSChurchill Khangar uint32_t line_id = 0; 119375129cebSChurchill Khangar int status = 0; 119475129cebSChurchill Khangar 119575129cebSChurchill Khangar /* Buffer allocation. */ 119675129cebSChurchill Khangar line = malloc(MAX_LINE_SIZE); 119775129cebSChurchill Khangar if (!line) 119875129cebSChurchill Khangar return -ENOMEM; 119975129cebSChurchill Khangar 120075129cebSChurchill Khangar /* File read. */ 120175129cebSChurchill Khangar for (line_id = 1; ; line_id++) { 120275129cebSChurchill Khangar struct rte_swx_table_entry *entry; 120375129cebSChurchill Khangar int is_blank_or_comment; 120475129cebSChurchill Khangar 120575129cebSChurchill Khangar if (fgets(line, MAX_LINE_SIZE, file) == NULL) 120675129cebSChurchill Khangar break; 120775129cebSChurchill Khangar 120875129cebSChurchill Khangar entry = rte_swx_ctl_pipeline_table_entry_read(p, 120975129cebSChurchill Khangar table_name, 121075129cebSChurchill Khangar line, 121175129cebSChurchill Khangar &is_blank_or_comment); 121275129cebSChurchill Khangar if (!entry) { 121375129cebSChurchill Khangar if (is_blank_or_comment) 121475129cebSChurchill Khangar continue; 121575129cebSChurchill Khangar 121675129cebSChurchill Khangar status = -EINVAL; 121775129cebSChurchill Khangar goto error; 121875129cebSChurchill Khangar } 121975129cebSChurchill Khangar 122075129cebSChurchill Khangar status = rte_swx_ctl_pipeline_table_entry_delete(p, 122175129cebSChurchill Khangar table_name, 122275129cebSChurchill Khangar entry); 122375129cebSChurchill Khangar table_entry_free(entry); 122475129cebSChurchill Khangar if (status) 122575129cebSChurchill Khangar goto error; 122675129cebSChurchill Khangar } 122775129cebSChurchill Khangar 122875129cebSChurchill Khangar error: 122975129cebSChurchill Khangar *file_line_number = line_id; 123075129cebSChurchill Khangar free(line); 123175129cebSChurchill Khangar return status; 123275129cebSChurchill Khangar } 123375129cebSChurchill Khangar 123475129cebSChurchill Khangar static const char cmd_pipeline_table_delete_help[] = 123575129cebSChurchill Khangar "pipeline <pipeline_name> table <table_name> delete <file_name>\n"; 123675129cebSChurchill Khangar 123775129cebSChurchill Khangar static void 123875129cebSChurchill Khangar cmd_pipeline_table_delete(char **tokens, 123975129cebSChurchill Khangar uint32_t n_tokens, 124075129cebSChurchill Khangar char *out, 124175129cebSChurchill Khangar size_t out_size, 124275129cebSChurchill Khangar void *obj) 124375129cebSChurchill Khangar { 124475129cebSChurchill Khangar struct pipeline *p; 124575129cebSChurchill Khangar char *pipeline_name, *table_name, *file_name; 124675129cebSChurchill Khangar FILE *file = NULL; 124775129cebSChurchill Khangar uint32_t file_line_number = 0; 124875129cebSChurchill Khangar int status; 124975129cebSChurchill Khangar 125075129cebSChurchill Khangar if (n_tokens != 6) { 125175129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 125275129cebSChurchill Khangar return; 125375129cebSChurchill Khangar } 125475129cebSChurchill Khangar 125575129cebSChurchill Khangar pipeline_name = tokens[1]; 125675129cebSChurchill Khangar p = pipeline_find(obj, pipeline_name); 125775129cebSChurchill Khangar if (!p || !p->ctl) { 125875129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 12595074e1d5SCristian Dumitrescu return; 12605074e1d5SCristian Dumitrescu } 12615074e1d5SCristian Dumitrescu 12625074e1d5SCristian Dumitrescu table_name = tokens[3]; 12635074e1d5SCristian Dumitrescu 126475129cebSChurchill Khangar file_name = tokens[5]; 126575129cebSChurchill Khangar file = fopen(file_name, "r"); 126675129cebSChurchill Khangar if (!file) { 126775129cebSChurchill Khangar snprintf(out, out_size, "Cannot open file %s.\n", file_name); 12685074e1d5SCristian Dumitrescu return; 12695074e1d5SCristian Dumitrescu } 12705074e1d5SCristian Dumitrescu 127175129cebSChurchill Khangar status = pipeline_table_entries_delete(p->ctl, 127275129cebSChurchill Khangar table_name, 127375129cebSChurchill Khangar file, 127475129cebSChurchill Khangar &file_line_number); 127575129cebSChurchill Khangar if (status) 127675129cebSChurchill Khangar snprintf(out, out_size, "Invalid entry in file %s at line %u\n", 127775129cebSChurchill Khangar file_name, 127875129cebSChurchill Khangar file_line_number); 12795074e1d5SCristian Dumitrescu 128075129cebSChurchill Khangar fclose(file); 12815074e1d5SCristian Dumitrescu } 12825074e1d5SCristian Dumitrescu 128375129cebSChurchill Khangar static int 128475129cebSChurchill Khangar pipeline_table_default_entry_add(struct rte_swx_ctl_pipeline *p, 128575129cebSChurchill Khangar const char *table_name, 128675129cebSChurchill Khangar FILE *file, 128775129cebSChurchill Khangar uint32_t *file_line_number) 128875129cebSChurchill Khangar { 128975129cebSChurchill Khangar char *line = NULL; 129075129cebSChurchill Khangar uint32_t line_id = 0; 129175129cebSChurchill Khangar int status = 0; 12925074e1d5SCristian Dumitrescu 12935074e1d5SCristian Dumitrescu /* Buffer allocation. */ 129475129cebSChurchill Khangar line = malloc(MAX_LINE_SIZE); 129575129cebSChurchill Khangar if (!line) 129675129cebSChurchill Khangar return -ENOMEM; 12975074e1d5SCristian Dumitrescu 129875129cebSChurchill Khangar /* File read. */ 12995074e1d5SCristian Dumitrescu for (line_id = 1; ; line_id++) { 13005074e1d5SCristian Dumitrescu struct rte_swx_table_entry *entry; 1301cff9a717SCristian Dumitrescu int is_blank_or_comment; 13025074e1d5SCristian Dumitrescu 130375129cebSChurchill Khangar if (fgets(line, MAX_LINE_SIZE, file) == NULL) 13045074e1d5SCristian Dumitrescu break; 13055074e1d5SCristian Dumitrescu 130675129cebSChurchill Khangar entry = rte_swx_ctl_pipeline_table_entry_read(p, 13075074e1d5SCristian Dumitrescu table_name, 1308cff9a717SCristian Dumitrescu line, 1309cff9a717SCristian Dumitrescu &is_blank_or_comment); 13105074e1d5SCristian Dumitrescu if (!entry) { 1311cff9a717SCristian Dumitrescu if (is_blank_or_comment) 1312cff9a717SCristian Dumitrescu continue; 1313cff9a717SCristian Dumitrescu 131475129cebSChurchill Khangar status = -EINVAL; 13155074e1d5SCristian Dumitrescu goto error; 13165074e1d5SCristian Dumitrescu } 13175074e1d5SCristian Dumitrescu 131875129cebSChurchill Khangar status = rte_swx_ctl_pipeline_table_default_entry_add(p, 13195074e1d5SCristian Dumitrescu table_name, 13205074e1d5SCristian Dumitrescu entry); 1321275ebefeSCristian Dumitrescu table_entry_free(entry); 132275129cebSChurchill Khangar if (status) 13235074e1d5SCristian Dumitrescu goto error; 13245074e1d5SCristian Dumitrescu } 132575129cebSChurchill Khangar 132675129cebSChurchill Khangar error: 132775129cebSChurchill Khangar *file_line_number = line_id; 132875129cebSChurchill Khangar free(line); 132975129cebSChurchill Khangar return status; 13305074e1d5SCristian Dumitrescu } 13315074e1d5SCristian Dumitrescu 133275129cebSChurchill Khangar static const char cmd_pipeline_table_default_help[] = 133375129cebSChurchill Khangar "pipeline <pipeline_name> table <table_name> default <file_name>\n"; 13345074e1d5SCristian Dumitrescu 133575129cebSChurchill Khangar static void 133675129cebSChurchill Khangar cmd_pipeline_table_default(char **tokens, 133775129cebSChurchill Khangar uint32_t n_tokens, 133875129cebSChurchill Khangar char *out, 133975129cebSChurchill Khangar size_t out_size, 134075129cebSChurchill Khangar void *obj) 134175129cebSChurchill Khangar { 134275129cebSChurchill Khangar struct pipeline *p; 134375129cebSChurchill Khangar char *pipeline_name, *table_name, *file_name; 134475129cebSChurchill Khangar FILE *file = NULL; 134575129cebSChurchill Khangar uint32_t file_line_number = 0; 134675129cebSChurchill Khangar int status; 13475074e1d5SCristian Dumitrescu 134875129cebSChurchill Khangar if (n_tokens != 6) { 134975129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 135075129cebSChurchill Khangar return; 135175129cebSChurchill Khangar } 13525074e1d5SCristian Dumitrescu 135375129cebSChurchill Khangar pipeline_name = tokens[1]; 135475129cebSChurchill Khangar p = pipeline_find(obj, pipeline_name); 135575129cebSChurchill Khangar if (!p || !p->ctl) { 135675129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 135775129cebSChurchill Khangar return; 135875129cebSChurchill Khangar } 135975129cebSChurchill Khangar 136075129cebSChurchill Khangar table_name = tokens[3]; 136175129cebSChurchill Khangar 136275129cebSChurchill Khangar file_name = tokens[5]; 136375129cebSChurchill Khangar file = fopen(file_name, "r"); 136475129cebSChurchill Khangar if (!file) { 136575129cebSChurchill Khangar snprintf(out, out_size, "Cannot open file %s.\n", file_name); 136675129cebSChurchill Khangar return; 136775129cebSChurchill Khangar } 136875129cebSChurchill Khangar 136975129cebSChurchill Khangar status = pipeline_table_default_entry_add(p->ctl, 13705074e1d5SCristian Dumitrescu table_name, 137175129cebSChurchill Khangar file, 137275129cebSChurchill Khangar &file_line_number); 137375129cebSChurchill Khangar if (status) 137475129cebSChurchill Khangar snprintf(out, out_size, "Invalid entry in file %s at line %u\n", 137575129cebSChurchill Khangar file_name, 137675129cebSChurchill Khangar file_line_number); 1377cff9a717SCristian Dumitrescu 137875129cebSChurchill Khangar fclose(file); 13795074e1d5SCristian Dumitrescu } 13805074e1d5SCristian Dumitrescu 138175129cebSChurchill Khangar static const char cmd_pipeline_table_show_help[] = 1382a4c1146cSCristian Dumitrescu "pipeline <pipeline_name> table <table_name> show [filename]\n"; 138375129cebSChurchill Khangar 138475129cebSChurchill Khangar static void 138575129cebSChurchill Khangar cmd_pipeline_table_show(char **tokens, 138675129cebSChurchill Khangar uint32_t n_tokens, 138775129cebSChurchill Khangar char *out, 138875129cebSChurchill Khangar size_t out_size, 138975129cebSChurchill Khangar void *obj) 139075129cebSChurchill Khangar { 139175129cebSChurchill Khangar struct pipeline *p; 139275129cebSChurchill Khangar char *pipeline_name, *table_name; 1393a4c1146cSCristian Dumitrescu FILE *file = NULL; 139475129cebSChurchill Khangar int status; 139575129cebSChurchill Khangar 1396a4c1146cSCristian Dumitrescu if (n_tokens != 5 && n_tokens != 6) { 139775129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 139875129cebSChurchill Khangar return; 13995074e1d5SCristian Dumitrescu } 14005074e1d5SCristian Dumitrescu 140175129cebSChurchill Khangar pipeline_name = tokens[1]; 140275129cebSChurchill Khangar p = pipeline_find(obj, pipeline_name); 140375129cebSChurchill Khangar if (!p || !p->ctl) { 140475129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 140575129cebSChurchill Khangar return; 14065074e1d5SCristian Dumitrescu } 14075074e1d5SCristian Dumitrescu 140875129cebSChurchill Khangar table_name = tokens[3]; 1409a4c1146cSCristian Dumitrescu file = (n_tokens == 6) ? fopen(tokens[5], "w") : stdout; 1410a4c1146cSCristian Dumitrescu if (!file) { 1411a4c1146cSCristian Dumitrescu snprintf(out, out_size, "Cannot open file %s.\n", tokens[5]); 1412a4c1146cSCristian Dumitrescu return; 1413a4c1146cSCristian Dumitrescu } 1414a4c1146cSCristian Dumitrescu 1415a4c1146cSCristian Dumitrescu status = rte_swx_ctl_pipeline_table_fprintf(file, p->ctl, table_name); 141675129cebSChurchill Khangar if (status) 141775129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "table_name"); 1418a4c1146cSCristian Dumitrescu 1419a4c1146cSCristian Dumitrescu if (file) 1420a4c1146cSCristian Dumitrescu fclose(file); 14215074e1d5SCristian Dumitrescu } 142275129cebSChurchill Khangar 1423598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_group_add_help[] = 1424598fe0ddSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> group add\n"; 1425598fe0ddSCristian Dumitrescu 1426598fe0ddSCristian Dumitrescu static void 1427598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_add(char **tokens, 1428598fe0ddSCristian Dumitrescu uint32_t n_tokens, 1429598fe0ddSCristian Dumitrescu char *out, 1430598fe0ddSCristian Dumitrescu size_t out_size, 1431598fe0ddSCristian Dumitrescu void *obj) 1432598fe0ddSCristian Dumitrescu { 1433598fe0ddSCristian Dumitrescu struct pipeline *p; 1434598fe0ddSCristian Dumitrescu char *pipeline_name, *selector_name; 1435598fe0ddSCristian Dumitrescu uint32_t group_id; 1436598fe0ddSCristian Dumitrescu int status; 1437598fe0ddSCristian Dumitrescu 1438598fe0ddSCristian Dumitrescu if (n_tokens != 6) { 1439598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 1440598fe0ddSCristian Dumitrescu return; 1441598fe0ddSCristian Dumitrescu } 1442598fe0ddSCristian Dumitrescu 1443598fe0ddSCristian Dumitrescu pipeline_name = tokens[1]; 1444598fe0ddSCristian Dumitrescu p = pipeline_find(obj, pipeline_name); 1445598fe0ddSCristian Dumitrescu if (!p || !p->ctl) { 1446598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 1447598fe0ddSCristian Dumitrescu return; 1448598fe0ddSCristian Dumitrescu } 1449598fe0ddSCristian Dumitrescu 1450598fe0ddSCristian Dumitrescu if (strcmp(tokens[2], "selector") != 0) { 1451598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector"); 1452598fe0ddSCristian Dumitrescu return; 1453598fe0ddSCristian Dumitrescu } 1454598fe0ddSCristian Dumitrescu 1455598fe0ddSCristian Dumitrescu selector_name = tokens[3]; 1456598fe0ddSCristian Dumitrescu 1457598fe0ddSCristian Dumitrescu if (strcmp(tokens[4], "group") || 1458598fe0ddSCristian Dumitrescu strcmp(tokens[5], "add")) { 1459598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group add"); 1460598fe0ddSCristian Dumitrescu return; 1461598fe0ddSCristian Dumitrescu } 1462598fe0ddSCristian Dumitrescu 1463598fe0ddSCristian Dumitrescu status = rte_swx_ctl_pipeline_selector_group_add(p->ctl, 1464598fe0ddSCristian Dumitrescu selector_name, 1465598fe0ddSCristian Dumitrescu &group_id); 1466598fe0ddSCristian Dumitrescu if (status) 1467598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]); 1468598fe0ddSCristian Dumitrescu else 1469598fe0ddSCristian Dumitrescu snprintf(out, out_size, "Group ID: %u\n", group_id); 1470598fe0ddSCristian Dumitrescu } 1471598fe0ddSCristian Dumitrescu 1472598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_group_delete_help[] = 1473598fe0ddSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> group delete <group_id>\n"; 1474598fe0ddSCristian Dumitrescu 1475598fe0ddSCristian Dumitrescu static void 1476598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_delete(char **tokens, 1477598fe0ddSCristian Dumitrescu uint32_t n_tokens, 1478598fe0ddSCristian Dumitrescu char *out, 1479598fe0ddSCristian Dumitrescu size_t out_size, 1480598fe0ddSCristian Dumitrescu void *obj) 1481598fe0ddSCristian Dumitrescu { 1482598fe0ddSCristian Dumitrescu struct pipeline *p; 1483598fe0ddSCristian Dumitrescu char *pipeline_name, *selector_name; 1484598fe0ddSCristian Dumitrescu uint32_t group_id; 1485598fe0ddSCristian Dumitrescu int status; 1486598fe0ddSCristian Dumitrescu 1487598fe0ddSCristian Dumitrescu if (n_tokens != 7) { 1488598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 1489598fe0ddSCristian Dumitrescu return; 1490598fe0ddSCristian Dumitrescu } 1491598fe0ddSCristian Dumitrescu 1492598fe0ddSCristian Dumitrescu pipeline_name = tokens[1]; 1493598fe0ddSCristian Dumitrescu p = pipeline_find(obj, pipeline_name); 1494598fe0ddSCristian Dumitrescu if (!p || !p->ctl) { 1495598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 1496598fe0ddSCristian Dumitrescu return; 1497598fe0ddSCristian Dumitrescu } 1498598fe0ddSCristian Dumitrescu 1499598fe0ddSCristian Dumitrescu if (strcmp(tokens[2], "selector") != 0) { 1500598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector"); 1501598fe0ddSCristian Dumitrescu return; 1502598fe0ddSCristian Dumitrescu } 1503598fe0ddSCristian Dumitrescu 1504598fe0ddSCristian Dumitrescu selector_name = tokens[3]; 1505598fe0ddSCristian Dumitrescu 1506598fe0ddSCristian Dumitrescu if (strcmp(tokens[4], "group") || 1507598fe0ddSCristian Dumitrescu strcmp(tokens[5], "delete")) { 1508598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group delete"); 1509598fe0ddSCristian Dumitrescu return; 1510598fe0ddSCristian Dumitrescu } 1511598fe0ddSCristian Dumitrescu 1512598fe0ddSCristian Dumitrescu if (parser_read_uint32(&group_id, tokens[6]) != 0) { 1513598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "group_id"); 1514598fe0ddSCristian Dumitrescu return; 1515598fe0ddSCristian Dumitrescu } 1516598fe0ddSCristian Dumitrescu 1517598fe0ddSCristian Dumitrescu status = rte_swx_ctl_pipeline_selector_group_delete(p->ctl, 1518598fe0ddSCristian Dumitrescu selector_name, 1519598fe0ddSCristian Dumitrescu group_id); 1520598fe0ddSCristian Dumitrescu if (status) 1521598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]); 1522598fe0ddSCristian Dumitrescu } 1523598fe0ddSCristian Dumitrescu 1524598fe0ddSCristian Dumitrescu #define GROUP_MEMBER_INFO_TOKENS_MAX 6 1525598fe0ddSCristian Dumitrescu 1526598fe0ddSCristian Dumitrescu static int 1527598fe0ddSCristian Dumitrescu token_is_comment(const char *token) 1528598fe0ddSCristian Dumitrescu { 1529598fe0ddSCristian Dumitrescu if ((token[0] == '#') || 1530598fe0ddSCristian Dumitrescu (token[0] == ';') || 1531598fe0ddSCristian Dumitrescu ((token[0] == '/') && (token[1] == '/'))) 1532598fe0ddSCristian Dumitrescu return 1; /* TRUE. */ 1533598fe0ddSCristian Dumitrescu 1534598fe0ddSCristian Dumitrescu return 0; /* FALSE. */ 1535598fe0ddSCristian Dumitrescu } 1536598fe0ddSCristian Dumitrescu 1537598fe0ddSCristian Dumitrescu static int 1538598fe0ddSCristian Dumitrescu pipeline_selector_group_member_read(const char *string, 1539598fe0ddSCristian Dumitrescu uint32_t *group_id, 1540598fe0ddSCristian Dumitrescu uint32_t *member_id, 1541598fe0ddSCristian Dumitrescu uint32_t *weight, 1542598fe0ddSCristian Dumitrescu int *is_blank_or_comment) 1543598fe0ddSCristian Dumitrescu { 1544598fe0ddSCristian Dumitrescu char *token_array[GROUP_MEMBER_INFO_TOKENS_MAX], **tokens; 1545598fe0ddSCristian Dumitrescu char *s0 = NULL, *s; 154600b67591SAli Alnubani uint32_t n_tokens = 0, group_id_val = 0, member_id_val = 0, weight_val = 0; 1547598fe0ddSCristian Dumitrescu int blank_or_comment = 0; 1548598fe0ddSCristian Dumitrescu 1549598fe0ddSCristian Dumitrescu /* Check input arguments. */ 1550598fe0ddSCristian Dumitrescu if (!string || !string[0]) 1551598fe0ddSCristian Dumitrescu goto error; 1552598fe0ddSCristian Dumitrescu 1553598fe0ddSCristian Dumitrescu /* Memory allocation. */ 1554598fe0ddSCristian Dumitrescu s0 = strdup(string); 1555598fe0ddSCristian Dumitrescu if (!s0) 1556598fe0ddSCristian Dumitrescu goto error; 1557598fe0ddSCristian Dumitrescu 1558598fe0ddSCristian Dumitrescu /* Parse the string into tokens. */ 1559598fe0ddSCristian Dumitrescu for (s = s0; ; ) { 1560598fe0ddSCristian Dumitrescu char *token; 1561598fe0ddSCristian Dumitrescu 1562598fe0ddSCristian Dumitrescu token = strtok_r(s, " \f\n\r\t\v", &s); 1563598fe0ddSCristian Dumitrescu if (!token || token_is_comment(token)) 1564598fe0ddSCristian Dumitrescu break; 1565598fe0ddSCristian Dumitrescu 1566cfcc7bf8SCristian Dumitrescu if (n_tokens >= GROUP_MEMBER_INFO_TOKENS_MAX) 1567598fe0ddSCristian Dumitrescu goto error; 1568598fe0ddSCristian Dumitrescu 1569598fe0ddSCristian Dumitrescu token_array[n_tokens] = token; 1570598fe0ddSCristian Dumitrescu n_tokens++; 1571598fe0ddSCristian Dumitrescu } 1572598fe0ddSCristian Dumitrescu 1573598fe0ddSCristian Dumitrescu if (!n_tokens) { 1574598fe0ddSCristian Dumitrescu blank_or_comment = 1; 1575598fe0ddSCristian Dumitrescu goto error; 1576598fe0ddSCristian Dumitrescu } 1577598fe0ddSCristian Dumitrescu 1578598fe0ddSCristian Dumitrescu tokens = token_array; 1579598fe0ddSCristian Dumitrescu 1580598fe0ddSCristian Dumitrescu if (n_tokens < 4 || 1581598fe0ddSCristian Dumitrescu strcmp(tokens[0], "group") || 1582598fe0ddSCristian Dumitrescu strcmp(tokens[2], "member")) 1583598fe0ddSCristian Dumitrescu goto error; 1584598fe0ddSCristian Dumitrescu 1585598fe0ddSCristian Dumitrescu /* 1586598fe0ddSCristian Dumitrescu * Group ID. 1587598fe0ddSCristian Dumitrescu */ 1588598fe0ddSCristian Dumitrescu if (parser_read_uint32(&group_id_val, tokens[1]) != 0) 1589598fe0ddSCristian Dumitrescu goto error; 1590598fe0ddSCristian Dumitrescu *group_id = group_id_val; 1591598fe0ddSCristian Dumitrescu 1592598fe0ddSCristian Dumitrescu /* 1593598fe0ddSCristian Dumitrescu * Member ID. 1594598fe0ddSCristian Dumitrescu */ 1595598fe0ddSCristian Dumitrescu if (parser_read_uint32(&member_id_val, tokens[3]) != 0) 1596598fe0ddSCristian Dumitrescu goto error; 1597598fe0ddSCristian Dumitrescu *member_id = member_id_val; 1598598fe0ddSCristian Dumitrescu 1599598fe0ddSCristian Dumitrescu tokens += 4; 1600598fe0ddSCristian Dumitrescu n_tokens -= 4; 1601598fe0ddSCristian Dumitrescu 1602598fe0ddSCristian Dumitrescu /* 1603598fe0ddSCristian Dumitrescu * Weight. 1604598fe0ddSCristian Dumitrescu */ 1605598fe0ddSCristian Dumitrescu if (n_tokens && !strcmp(tokens[0], "weight")) { 1606598fe0ddSCristian Dumitrescu if (n_tokens < 2) 1607598fe0ddSCristian Dumitrescu goto error; 1608598fe0ddSCristian Dumitrescu 1609598fe0ddSCristian Dumitrescu if (parser_read_uint32(&weight_val, tokens[1]) != 0) 1610598fe0ddSCristian Dumitrescu goto error; 1611598fe0ddSCristian Dumitrescu *weight = weight_val; 1612598fe0ddSCristian Dumitrescu 1613598fe0ddSCristian Dumitrescu tokens += 2; 1614598fe0ddSCristian Dumitrescu n_tokens -= 2; 1615598fe0ddSCristian Dumitrescu } 1616598fe0ddSCristian Dumitrescu 1617598fe0ddSCristian Dumitrescu if (n_tokens) 1618598fe0ddSCristian Dumitrescu goto error; 1619598fe0ddSCristian Dumitrescu 1620598fe0ddSCristian Dumitrescu free(s0); 1621598fe0ddSCristian Dumitrescu return 0; 1622598fe0ddSCristian Dumitrescu 1623598fe0ddSCristian Dumitrescu error: 1624598fe0ddSCristian Dumitrescu free(s0); 1625598fe0ddSCristian Dumitrescu if (is_blank_or_comment) 1626598fe0ddSCristian Dumitrescu *is_blank_or_comment = blank_or_comment; 1627598fe0ddSCristian Dumitrescu return -EINVAL; 1628598fe0ddSCristian Dumitrescu } 1629598fe0ddSCristian Dumitrescu 1630598fe0ddSCristian Dumitrescu static int 1631598fe0ddSCristian Dumitrescu pipeline_selector_group_members_add(struct rte_swx_ctl_pipeline *p, 1632598fe0ddSCristian Dumitrescu const char *selector_name, 1633598fe0ddSCristian Dumitrescu FILE *file, 1634598fe0ddSCristian Dumitrescu uint32_t *file_line_number) 1635598fe0ddSCristian Dumitrescu { 1636598fe0ddSCristian Dumitrescu char *line = NULL; 1637598fe0ddSCristian Dumitrescu uint32_t line_id = 0; 1638598fe0ddSCristian Dumitrescu int status = 0; 1639598fe0ddSCristian Dumitrescu 1640598fe0ddSCristian Dumitrescu /* Buffer allocation. */ 1641598fe0ddSCristian Dumitrescu line = malloc(MAX_LINE_SIZE); 1642598fe0ddSCristian Dumitrescu if (!line) 1643598fe0ddSCristian Dumitrescu return -ENOMEM; 1644598fe0ddSCristian Dumitrescu 1645598fe0ddSCristian Dumitrescu /* File read. */ 1646598fe0ddSCristian Dumitrescu for (line_id = 1; ; line_id++) { 1647598fe0ddSCristian Dumitrescu uint32_t group_id, member_id, weight; 1648598fe0ddSCristian Dumitrescu int is_blank_or_comment; 1649598fe0ddSCristian Dumitrescu 1650598fe0ddSCristian Dumitrescu if (fgets(line, MAX_LINE_SIZE, file) == NULL) 1651598fe0ddSCristian Dumitrescu break; 1652598fe0ddSCristian Dumitrescu 1653598fe0ddSCristian Dumitrescu status = pipeline_selector_group_member_read(line, 1654598fe0ddSCristian Dumitrescu &group_id, 1655598fe0ddSCristian Dumitrescu &member_id, 1656598fe0ddSCristian Dumitrescu &weight, 1657598fe0ddSCristian Dumitrescu &is_blank_or_comment); 1658598fe0ddSCristian Dumitrescu if (status) { 1659598fe0ddSCristian Dumitrescu if (is_blank_or_comment) 1660598fe0ddSCristian Dumitrescu continue; 1661598fe0ddSCristian Dumitrescu 1662598fe0ddSCristian Dumitrescu goto error; 1663598fe0ddSCristian Dumitrescu } 1664598fe0ddSCristian Dumitrescu 1665598fe0ddSCristian Dumitrescu status = rte_swx_ctl_pipeline_selector_group_member_add(p, 1666598fe0ddSCristian Dumitrescu selector_name, 1667598fe0ddSCristian Dumitrescu group_id, 1668598fe0ddSCristian Dumitrescu member_id, 1669598fe0ddSCristian Dumitrescu weight); 1670598fe0ddSCristian Dumitrescu if (status) 1671598fe0ddSCristian Dumitrescu goto error; 1672598fe0ddSCristian Dumitrescu } 1673598fe0ddSCristian Dumitrescu 1674598fe0ddSCristian Dumitrescu error: 1675598fe0ddSCristian Dumitrescu free(line); 1676598fe0ddSCristian Dumitrescu *file_line_number = line_id; 1677598fe0ddSCristian Dumitrescu return status; 1678598fe0ddSCristian Dumitrescu } 1679598fe0ddSCristian Dumitrescu 1680598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_group_member_add_help[] = 1681598fe0ddSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> group member add <file_name>"; 1682598fe0ddSCristian Dumitrescu 1683598fe0ddSCristian Dumitrescu static void 1684598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_add(char **tokens, 1685598fe0ddSCristian Dumitrescu uint32_t n_tokens, 1686598fe0ddSCristian Dumitrescu char *out, 1687598fe0ddSCristian Dumitrescu size_t out_size, 1688598fe0ddSCristian Dumitrescu void *obj) 1689598fe0ddSCristian Dumitrescu { 1690598fe0ddSCristian Dumitrescu struct pipeline *p; 1691598fe0ddSCristian Dumitrescu char *pipeline_name, *selector_name, *file_name; 1692598fe0ddSCristian Dumitrescu FILE *file = NULL; 1693598fe0ddSCristian Dumitrescu uint32_t file_line_number = 0; 1694598fe0ddSCristian Dumitrescu int status; 1695598fe0ddSCristian Dumitrescu 1696598fe0ddSCristian Dumitrescu if (n_tokens != 8) { 1697598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 1698598fe0ddSCristian Dumitrescu return; 1699598fe0ddSCristian Dumitrescu } 1700598fe0ddSCristian Dumitrescu 1701598fe0ddSCristian Dumitrescu pipeline_name = tokens[1]; 1702598fe0ddSCristian Dumitrescu p = pipeline_find(obj, pipeline_name); 1703598fe0ddSCristian Dumitrescu if (!p || !p->ctl) { 1704598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 1705598fe0ddSCristian Dumitrescu return; 1706598fe0ddSCristian Dumitrescu } 1707598fe0ddSCristian Dumitrescu 1708598fe0ddSCristian Dumitrescu if (strcmp(tokens[2], "selector") != 0) { 1709598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector"); 1710598fe0ddSCristian Dumitrescu return; 1711598fe0ddSCristian Dumitrescu } 1712598fe0ddSCristian Dumitrescu 1713598fe0ddSCristian Dumitrescu selector_name = tokens[3]; 1714598fe0ddSCristian Dumitrescu 1715598fe0ddSCristian Dumitrescu if (strcmp(tokens[4], "group") || 1716598fe0ddSCristian Dumitrescu strcmp(tokens[5], "member") || 1717598fe0ddSCristian Dumitrescu strcmp(tokens[6], "add")) { 1718598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group member add"); 1719598fe0ddSCristian Dumitrescu return; 1720598fe0ddSCristian Dumitrescu } 1721598fe0ddSCristian Dumitrescu 1722598fe0ddSCristian Dumitrescu file_name = tokens[7]; 1723598fe0ddSCristian Dumitrescu file = fopen(file_name, "r"); 1724598fe0ddSCristian Dumitrescu if (!file) { 1725598fe0ddSCristian Dumitrescu snprintf(out, out_size, "Cannot open file %s.\n", file_name); 1726598fe0ddSCristian Dumitrescu return; 1727598fe0ddSCristian Dumitrescu } 1728598fe0ddSCristian Dumitrescu 1729598fe0ddSCristian Dumitrescu status = pipeline_selector_group_members_add(p->ctl, 1730598fe0ddSCristian Dumitrescu selector_name, 1731598fe0ddSCristian Dumitrescu file, 1732598fe0ddSCristian Dumitrescu &file_line_number); 1733598fe0ddSCristian Dumitrescu if (status) 1734598fe0ddSCristian Dumitrescu snprintf(out, out_size, "Invalid entry in file %s at line %u\n", 1735598fe0ddSCristian Dumitrescu file_name, 1736598fe0ddSCristian Dumitrescu file_line_number); 1737598fe0ddSCristian Dumitrescu 1738598fe0ddSCristian Dumitrescu fclose(file); 1739598fe0ddSCristian Dumitrescu } 1740598fe0ddSCristian Dumitrescu 1741598fe0ddSCristian Dumitrescu static int 1742598fe0ddSCristian Dumitrescu pipeline_selector_group_members_delete(struct rte_swx_ctl_pipeline *p, 1743598fe0ddSCristian Dumitrescu const char *selector_name, 1744598fe0ddSCristian Dumitrescu FILE *file, 1745598fe0ddSCristian Dumitrescu uint32_t *file_line_number) 1746598fe0ddSCristian Dumitrescu { 1747598fe0ddSCristian Dumitrescu char *line = NULL; 1748598fe0ddSCristian Dumitrescu uint32_t line_id = 0; 1749598fe0ddSCristian Dumitrescu int status = 0; 1750598fe0ddSCristian Dumitrescu 1751598fe0ddSCristian Dumitrescu /* Buffer allocation. */ 1752598fe0ddSCristian Dumitrescu line = malloc(MAX_LINE_SIZE); 1753598fe0ddSCristian Dumitrescu if (!line) 1754598fe0ddSCristian Dumitrescu return -ENOMEM; 1755598fe0ddSCristian Dumitrescu 1756598fe0ddSCristian Dumitrescu /* File read. */ 1757598fe0ddSCristian Dumitrescu for (line_id = 1; ; line_id++) { 1758598fe0ddSCristian Dumitrescu uint32_t group_id, member_id, weight; 1759598fe0ddSCristian Dumitrescu int is_blank_or_comment; 1760598fe0ddSCristian Dumitrescu 1761598fe0ddSCristian Dumitrescu if (fgets(line, MAX_LINE_SIZE, file) == NULL) 1762598fe0ddSCristian Dumitrescu break; 1763598fe0ddSCristian Dumitrescu 1764598fe0ddSCristian Dumitrescu status = pipeline_selector_group_member_read(line, 1765598fe0ddSCristian Dumitrescu &group_id, 1766598fe0ddSCristian Dumitrescu &member_id, 1767598fe0ddSCristian Dumitrescu &weight, 1768598fe0ddSCristian Dumitrescu &is_blank_or_comment); 1769598fe0ddSCristian Dumitrescu if (status) { 1770598fe0ddSCristian Dumitrescu if (is_blank_or_comment) 1771598fe0ddSCristian Dumitrescu continue; 1772598fe0ddSCristian Dumitrescu 1773598fe0ddSCristian Dumitrescu goto error; 1774598fe0ddSCristian Dumitrescu } 1775598fe0ddSCristian Dumitrescu 1776598fe0ddSCristian Dumitrescu status = rte_swx_ctl_pipeline_selector_group_member_delete(p, 1777598fe0ddSCristian Dumitrescu selector_name, 1778598fe0ddSCristian Dumitrescu group_id, 1779598fe0ddSCristian Dumitrescu member_id); 1780598fe0ddSCristian Dumitrescu if (status) 1781598fe0ddSCristian Dumitrescu goto error; 1782598fe0ddSCristian Dumitrescu } 1783598fe0ddSCristian Dumitrescu 1784598fe0ddSCristian Dumitrescu error: 1785598fe0ddSCristian Dumitrescu free(line); 1786598fe0ddSCristian Dumitrescu *file_line_number = line_id; 1787598fe0ddSCristian Dumitrescu return status; 1788598fe0ddSCristian Dumitrescu } 1789598fe0ddSCristian Dumitrescu 1790598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_group_member_delete_help[] = 1791598fe0ddSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> group member delete <file_name>"; 1792598fe0ddSCristian Dumitrescu 1793598fe0ddSCristian Dumitrescu static void 1794598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_delete(char **tokens, 1795598fe0ddSCristian Dumitrescu uint32_t n_tokens, 1796598fe0ddSCristian Dumitrescu char *out, 1797598fe0ddSCristian Dumitrescu size_t out_size, 1798598fe0ddSCristian Dumitrescu void *obj) 1799598fe0ddSCristian Dumitrescu { 1800598fe0ddSCristian Dumitrescu struct pipeline *p; 1801598fe0ddSCristian Dumitrescu char *pipeline_name, *selector_name, *file_name; 1802598fe0ddSCristian Dumitrescu FILE *file = NULL; 1803598fe0ddSCristian Dumitrescu uint32_t file_line_number = 0; 1804598fe0ddSCristian Dumitrescu int status; 1805598fe0ddSCristian Dumitrescu 1806598fe0ddSCristian Dumitrescu if (n_tokens != 8) { 1807598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 1808598fe0ddSCristian Dumitrescu return; 1809598fe0ddSCristian Dumitrescu } 1810598fe0ddSCristian Dumitrescu 1811598fe0ddSCristian Dumitrescu pipeline_name = tokens[1]; 1812598fe0ddSCristian Dumitrescu p = pipeline_find(obj, pipeline_name); 1813598fe0ddSCristian Dumitrescu if (!p || !p->ctl) { 1814598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 1815598fe0ddSCristian Dumitrescu return; 1816598fe0ddSCristian Dumitrescu } 1817598fe0ddSCristian Dumitrescu 1818598fe0ddSCristian Dumitrescu if (strcmp(tokens[2], "selector") != 0) { 1819598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector"); 1820598fe0ddSCristian Dumitrescu return; 1821598fe0ddSCristian Dumitrescu } 1822598fe0ddSCristian Dumitrescu 1823598fe0ddSCristian Dumitrescu selector_name = tokens[3]; 1824598fe0ddSCristian Dumitrescu 1825598fe0ddSCristian Dumitrescu if (strcmp(tokens[4], "group") || 1826598fe0ddSCristian Dumitrescu strcmp(tokens[5], "member") || 1827598fe0ddSCristian Dumitrescu strcmp(tokens[6], "delete")) { 1828598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group member delete"); 1829598fe0ddSCristian Dumitrescu return; 1830598fe0ddSCristian Dumitrescu } 1831598fe0ddSCristian Dumitrescu 1832598fe0ddSCristian Dumitrescu file_name = tokens[7]; 1833598fe0ddSCristian Dumitrescu file = fopen(file_name, "r"); 1834598fe0ddSCristian Dumitrescu if (!file) { 1835598fe0ddSCristian Dumitrescu snprintf(out, out_size, "Cannot open file %s.\n", file_name); 1836598fe0ddSCristian Dumitrescu return; 1837598fe0ddSCristian Dumitrescu } 1838598fe0ddSCristian Dumitrescu 1839598fe0ddSCristian Dumitrescu status = pipeline_selector_group_members_delete(p->ctl, 1840598fe0ddSCristian Dumitrescu selector_name, 1841598fe0ddSCristian Dumitrescu file, 1842598fe0ddSCristian Dumitrescu &file_line_number); 1843598fe0ddSCristian Dumitrescu if (status) 1844598fe0ddSCristian Dumitrescu snprintf(out, out_size, "Invalid entry in file %s at line %u\n", 1845598fe0ddSCristian Dumitrescu file_name, 1846598fe0ddSCristian Dumitrescu file_line_number); 1847598fe0ddSCristian Dumitrescu 1848598fe0ddSCristian Dumitrescu fclose(file); 1849598fe0ddSCristian Dumitrescu } 1850598fe0ddSCristian Dumitrescu 1851598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_show_help[] = 1852a4c1146cSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> show [filename]\n"; 1853598fe0ddSCristian Dumitrescu 1854598fe0ddSCristian Dumitrescu static void 1855598fe0ddSCristian Dumitrescu cmd_pipeline_selector_show(char **tokens, 1856598fe0ddSCristian Dumitrescu uint32_t n_tokens, 1857598fe0ddSCristian Dumitrescu char *out, 1858598fe0ddSCristian Dumitrescu size_t out_size, 1859598fe0ddSCristian Dumitrescu void *obj) 1860598fe0ddSCristian Dumitrescu { 1861598fe0ddSCristian Dumitrescu struct pipeline *p; 1862598fe0ddSCristian Dumitrescu char *pipeline_name, *selector_name; 1863a4c1146cSCristian Dumitrescu FILE *file = NULL; 1864598fe0ddSCristian Dumitrescu int status; 1865598fe0ddSCristian Dumitrescu 1866a4c1146cSCristian Dumitrescu if (n_tokens != 5 && n_tokens != 6) { 1867598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 1868598fe0ddSCristian Dumitrescu return; 1869598fe0ddSCristian Dumitrescu } 1870598fe0ddSCristian Dumitrescu 1871598fe0ddSCristian Dumitrescu pipeline_name = tokens[1]; 1872598fe0ddSCristian Dumitrescu p = pipeline_find(obj, pipeline_name); 1873598fe0ddSCristian Dumitrescu if (!p || !p->ctl) { 1874598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 1875598fe0ddSCristian Dumitrescu return; 1876598fe0ddSCristian Dumitrescu } 1877598fe0ddSCristian Dumitrescu 1878598fe0ddSCristian Dumitrescu selector_name = tokens[3]; 1879a4c1146cSCristian Dumitrescu 1880a4c1146cSCristian Dumitrescu file = (n_tokens == 6) ? fopen(tokens[5], "w") : stdout; 1881a4c1146cSCristian Dumitrescu if (!file) { 1882a4c1146cSCristian Dumitrescu snprintf(out, out_size, "Cannot open file %s.\n", tokens[5]); 1883a4c1146cSCristian Dumitrescu return; 1884a4c1146cSCristian Dumitrescu } 1885a4c1146cSCristian Dumitrescu 1886a4c1146cSCristian Dumitrescu status = rte_swx_ctl_pipeline_selector_fprintf(file, p->ctl, selector_name); 1887598fe0ddSCristian Dumitrescu if (status) 1888598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "selector_name"); 1889a4c1146cSCristian Dumitrescu 1890a4c1146cSCristian Dumitrescu if (file) 1891a4c1146cSCristian Dumitrescu fclose(file); 1892598fe0ddSCristian Dumitrescu } 1893598fe0ddSCristian Dumitrescu 18948bd4862fSCristian Dumitrescu static int 18958bd4862fSCristian Dumitrescu pipeline_learner_default_entry_add(struct rte_swx_ctl_pipeline *p, 18968bd4862fSCristian Dumitrescu const char *learner_name, 18978bd4862fSCristian Dumitrescu FILE *file, 18988bd4862fSCristian Dumitrescu uint32_t *file_line_number) 18998bd4862fSCristian Dumitrescu { 19008bd4862fSCristian Dumitrescu char *line = NULL; 19018bd4862fSCristian Dumitrescu uint32_t line_id = 0; 19028bd4862fSCristian Dumitrescu int status = 0; 19038bd4862fSCristian Dumitrescu 19048bd4862fSCristian Dumitrescu /* Buffer allocation. */ 19058bd4862fSCristian Dumitrescu line = malloc(MAX_LINE_SIZE); 19068bd4862fSCristian Dumitrescu if (!line) 19078bd4862fSCristian Dumitrescu return -ENOMEM; 19088bd4862fSCristian Dumitrescu 19098bd4862fSCristian Dumitrescu /* File read. */ 19108bd4862fSCristian Dumitrescu for (line_id = 1; ; line_id++) { 19118bd4862fSCristian Dumitrescu struct rte_swx_table_entry *entry; 19128bd4862fSCristian Dumitrescu int is_blank_or_comment; 19138bd4862fSCristian Dumitrescu 19148bd4862fSCristian Dumitrescu if (fgets(line, MAX_LINE_SIZE, file) == NULL) 19158bd4862fSCristian Dumitrescu break; 19168bd4862fSCristian Dumitrescu 19178bd4862fSCristian Dumitrescu entry = rte_swx_ctl_pipeline_learner_default_entry_read(p, 19188bd4862fSCristian Dumitrescu learner_name, 19198bd4862fSCristian Dumitrescu line, 19208bd4862fSCristian Dumitrescu &is_blank_or_comment); 19218bd4862fSCristian Dumitrescu if (!entry) { 19228bd4862fSCristian Dumitrescu if (is_blank_or_comment) 19238bd4862fSCristian Dumitrescu continue; 19248bd4862fSCristian Dumitrescu 19258bd4862fSCristian Dumitrescu status = -EINVAL; 19268bd4862fSCristian Dumitrescu goto error; 19278bd4862fSCristian Dumitrescu } 19288bd4862fSCristian Dumitrescu 19298bd4862fSCristian Dumitrescu status = rte_swx_ctl_pipeline_learner_default_entry_add(p, 19308bd4862fSCristian Dumitrescu learner_name, 19318bd4862fSCristian Dumitrescu entry); 19328bd4862fSCristian Dumitrescu table_entry_free(entry); 19338bd4862fSCristian Dumitrescu if (status) 19348bd4862fSCristian Dumitrescu goto error; 19358bd4862fSCristian Dumitrescu } 19368bd4862fSCristian Dumitrescu 19378bd4862fSCristian Dumitrescu error: 19388bd4862fSCristian Dumitrescu *file_line_number = line_id; 19398bd4862fSCristian Dumitrescu free(line); 19408bd4862fSCristian Dumitrescu return status; 19418bd4862fSCristian Dumitrescu } 19428bd4862fSCristian Dumitrescu 19438bd4862fSCristian Dumitrescu static const char cmd_pipeline_learner_default_help[] = 19448bd4862fSCristian Dumitrescu "pipeline <pipeline_name> learner <learner_name> default <file_name>\n"; 19458bd4862fSCristian Dumitrescu 19468bd4862fSCristian Dumitrescu static void 19478bd4862fSCristian Dumitrescu cmd_pipeline_learner_default(char **tokens, 19488bd4862fSCristian Dumitrescu uint32_t n_tokens, 19498bd4862fSCristian Dumitrescu char *out, 19508bd4862fSCristian Dumitrescu size_t out_size, 19518bd4862fSCristian Dumitrescu void *obj) 19528bd4862fSCristian Dumitrescu { 19538bd4862fSCristian Dumitrescu struct pipeline *p; 19548bd4862fSCristian Dumitrescu char *pipeline_name, *learner_name, *file_name; 19558bd4862fSCristian Dumitrescu FILE *file = NULL; 19568bd4862fSCristian Dumitrescu uint32_t file_line_number = 0; 19578bd4862fSCristian Dumitrescu int status; 19588bd4862fSCristian Dumitrescu 19598bd4862fSCristian Dumitrescu if (n_tokens != 6) { 19608bd4862fSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 19618bd4862fSCristian Dumitrescu return; 19628bd4862fSCristian Dumitrescu } 19638bd4862fSCristian Dumitrescu 19648bd4862fSCristian Dumitrescu pipeline_name = tokens[1]; 19658bd4862fSCristian Dumitrescu p = pipeline_find(obj, pipeline_name); 19668bd4862fSCristian Dumitrescu if (!p || !p->ctl) { 19678bd4862fSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 19688bd4862fSCristian Dumitrescu return; 19698bd4862fSCristian Dumitrescu } 19708bd4862fSCristian Dumitrescu 19718bd4862fSCristian Dumitrescu learner_name = tokens[3]; 19728bd4862fSCristian Dumitrescu 19738bd4862fSCristian Dumitrescu file_name = tokens[5]; 19748bd4862fSCristian Dumitrescu file = fopen(file_name, "r"); 19758bd4862fSCristian Dumitrescu if (!file) { 19768bd4862fSCristian Dumitrescu snprintf(out, out_size, "Cannot open file %s.\n", file_name); 19778bd4862fSCristian Dumitrescu return; 19788bd4862fSCristian Dumitrescu } 19798bd4862fSCristian Dumitrescu 19808bd4862fSCristian Dumitrescu status = pipeline_learner_default_entry_add(p->ctl, 19818bd4862fSCristian Dumitrescu learner_name, 19828bd4862fSCristian Dumitrescu file, 19838bd4862fSCristian Dumitrescu &file_line_number); 19848bd4862fSCristian Dumitrescu if (status) 19858bd4862fSCristian Dumitrescu snprintf(out, out_size, "Invalid entry in file %s at line %u\n", 19868bd4862fSCristian Dumitrescu file_name, 19878bd4862fSCristian Dumitrescu file_line_number); 19888bd4862fSCristian Dumitrescu 19898bd4862fSCristian Dumitrescu fclose(file); 19908bd4862fSCristian Dumitrescu } 19918bd4862fSCristian Dumitrescu 199275129cebSChurchill Khangar static const char cmd_pipeline_commit_help[] = 199375129cebSChurchill Khangar "pipeline <pipeline_name> commit\n"; 199475129cebSChurchill Khangar 199575129cebSChurchill Khangar static void 199675129cebSChurchill Khangar cmd_pipeline_commit(char **tokens, 199775129cebSChurchill Khangar uint32_t n_tokens, 199875129cebSChurchill Khangar char *out, 199975129cebSChurchill Khangar size_t out_size, 200075129cebSChurchill Khangar void *obj) 200175129cebSChurchill Khangar { 200275129cebSChurchill Khangar struct pipeline *p; 200375129cebSChurchill Khangar char *pipeline_name; 200475129cebSChurchill Khangar int status; 200575129cebSChurchill Khangar 200675129cebSChurchill Khangar if (n_tokens != 3) { 200775129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 200875129cebSChurchill Khangar return; 200975129cebSChurchill Khangar } 201075129cebSChurchill Khangar 201175129cebSChurchill Khangar pipeline_name = tokens[1]; 201275129cebSChurchill Khangar p = pipeline_find(obj, pipeline_name); 201375129cebSChurchill Khangar if (!p || !p->ctl) { 201475129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 201575129cebSChurchill Khangar return; 20165074e1d5SCristian Dumitrescu } 20175074e1d5SCristian Dumitrescu 20185074e1d5SCristian Dumitrescu status = rte_swx_ctl_pipeline_commit(p->ctl, 1); 201975129cebSChurchill Khangar if (status) 202075129cebSChurchill Khangar snprintf(out, out_size, "Commit failed. " 202175129cebSChurchill Khangar "Use \"commit\" to retry or \"abort\" to discard the pending work.\n"); 20225074e1d5SCristian Dumitrescu } 20235074e1d5SCristian Dumitrescu 202475129cebSChurchill Khangar static const char cmd_pipeline_abort_help[] = 202575129cebSChurchill Khangar "pipeline <pipeline_name> abort\n"; 20265074e1d5SCristian Dumitrescu 202775129cebSChurchill Khangar static void 202875129cebSChurchill Khangar cmd_pipeline_abort(char **tokens, 202975129cebSChurchill Khangar uint32_t n_tokens, 203075129cebSChurchill Khangar char *out, 203175129cebSChurchill Khangar size_t out_size, 203275129cebSChurchill Khangar void *obj) 203375129cebSChurchill Khangar { 203475129cebSChurchill Khangar struct pipeline *p; 203575129cebSChurchill Khangar char *pipeline_name; 20365074e1d5SCristian Dumitrescu 203775129cebSChurchill Khangar if (n_tokens != 3) { 203875129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 20395074e1d5SCristian Dumitrescu return; 204075129cebSChurchill Khangar } 20415074e1d5SCristian Dumitrescu 204275129cebSChurchill Khangar pipeline_name = tokens[1]; 204375129cebSChurchill Khangar p = pipeline_find(obj, pipeline_name); 204475129cebSChurchill Khangar if (!p || !p->ctl) { 204575129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 204675129cebSChurchill Khangar return; 204775129cebSChurchill Khangar } 204875129cebSChurchill Khangar 20495074e1d5SCristian Dumitrescu rte_swx_ctl_pipeline_abort(p->ctl); 20505074e1d5SCristian Dumitrescu } 20515074e1d5SCristian Dumitrescu 205264cfcebdSCristian Dumitrescu static const char cmd_pipeline_regrd_help[] = 205364cfcebdSCristian Dumitrescu "pipeline <pipeline_name> regrd <register_array_name> <index>\n"; 205464cfcebdSCristian Dumitrescu 205564cfcebdSCristian Dumitrescu static void 205664cfcebdSCristian Dumitrescu cmd_pipeline_regrd(char **tokens, 205764cfcebdSCristian Dumitrescu uint32_t n_tokens, 205864cfcebdSCristian Dumitrescu char *out, 205964cfcebdSCristian Dumitrescu size_t out_size, 206064cfcebdSCristian Dumitrescu void *obj) 206164cfcebdSCristian Dumitrescu { 206264cfcebdSCristian Dumitrescu struct pipeline *p; 206364cfcebdSCristian Dumitrescu const char *name; 206464cfcebdSCristian Dumitrescu uint64_t value; 206564cfcebdSCristian Dumitrescu uint32_t idx; 206664cfcebdSCristian Dumitrescu int status; 206764cfcebdSCristian Dumitrescu 206864cfcebdSCristian Dumitrescu if (n_tokens != 5) { 206964cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 207064cfcebdSCristian Dumitrescu return; 207164cfcebdSCristian Dumitrescu } 207264cfcebdSCristian Dumitrescu 207364cfcebdSCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 207464cfcebdSCristian Dumitrescu if (!p || !p->ctl) { 207564cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 207664cfcebdSCristian Dumitrescu return; 207764cfcebdSCristian Dumitrescu } 207864cfcebdSCristian Dumitrescu 207964cfcebdSCristian Dumitrescu if (strcmp(tokens[2], "regrd")) { 208064cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "regrd"); 208164cfcebdSCristian Dumitrescu return; 208264cfcebdSCristian Dumitrescu } 208364cfcebdSCristian Dumitrescu 208464cfcebdSCristian Dumitrescu name = tokens[3]; 208564cfcebdSCristian Dumitrescu 208664cfcebdSCristian Dumitrescu if (parser_read_uint32(&idx, tokens[4])) { 208764cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index"); 208864cfcebdSCristian Dumitrescu return; 208964cfcebdSCristian Dumitrescu } 209064cfcebdSCristian Dumitrescu 209164cfcebdSCristian Dumitrescu status = rte_swx_ctl_pipeline_regarray_read(p->p, name, idx, &value); 209264cfcebdSCristian Dumitrescu if (status) { 209364cfcebdSCristian Dumitrescu snprintf(out, out_size, "Command failed.\n"); 209464cfcebdSCristian Dumitrescu return; 209564cfcebdSCristian Dumitrescu } 209664cfcebdSCristian Dumitrescu 209764cfcebdSCristian Dumitrescu snprintf(out, out_size, "0x%" PRIx64 "\n", value); 209864cfcebdSCristian Dumitrescu } 209964cfcebdSCristian Dumitrescu 210064cfcebdSCristian Dumitrescu static const char cmd_pipeline_regwr_help[] = 210164cfcebdSCristian Dumitrescu "pipeline <pipeline_name> regwr <register_array_name> <index> <value>\n"; 210264cfcebdSCristian Dumitrescu 210364cfcebdSCristian Dumitrescu static void 210464cfcebdSCristian Dumitrescu cmd_pipeline_regwr(char **tokens, 210564cfcebdSCristian Dumitrescu uint32_t n_tokens, 210664cfcebdSCristian Dumitrescu char *out, 210764cfcebdSCristian Dumitrescu size_t out_size, 210864cfcebdSCristian Dumitrescu void *obj) 210964cfcebdSCristian Dumitrescu { 211064cfcebdSCristian Dumitrescu struct pipeline *p; 211164cfcebdSCristian Dumitrescu const char *name; 211264cfcebdSCristian Dumitrescu uint64_t value; 211364cfcebdSCristian Dumitrescu uint32_t idx; 211464cfcebdSCristian Dumitrescu int status; 211564cfcebdSCristian Dumitrescu 211664cfcebdSCristian Dumitrescu if (n_tokens != 6) { 211764cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 211864cfcebdSCristian Dumitrescu return; 211964cfcebdSCristian Dumitrescu } 212064cfcebdSCristian Dumitrescu 212164cfcebdSCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 212264cfcebdSCristian Dumitrescu if (!p || !p->ctl) { 212364cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 212464cfcebdSCristian Dumitrescu return; 212564cfcebdSCristian Dumitrescu } 212664cfcebdSCristian Dumitrescu 212764cfcebdSCristian Dumitrescu if (strcmp(tokens[2], "regwr")) { 212864cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "regwr"); 212964cfcebdSCristian Dumitrescu return; 213064cfcebdSCristian Dumitrescu } 213164cfcebdSCristian Dumitrescu 213264cfcebdSCristian Dumitrescu name = tokens[3]; 213364cfcebdSCristian Dumitrescu 213464cfcebdSCristian Dumitrescu if (parser_read_uint32(&idx, tokens[4])) { 213564cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index"); 213664cfcebdSCristian Dumitrescu return; 213764cfcebdSCristian Dumitrescu } 213864cfcebdSCristian Dumitrescu 213964cfcebdSCristian Dumitrescu if (parser_read_uint64(&value, tokens[5])) { 214064cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "value"); 214164cfcebdSCristian Dumitrescu return; 214264cfcebdSCristian Dumitrescu } 214364cfcebdSCristian Dumitrescu 214464cfcebdSCristian Dumitrescu status = rte_swx_ctl_pipeline_regarray_write(p->p, name, idx, value); 214564cfcebdSCristian Dumitrescu if (status) { 214664cfcebdSCristian Dumitrescu snprintf(out, out_size, "Command failed.\n"); 214764cfcebdSCristian Dumitrescu return; 214864cfcebdSCristian Dumitrescu } 214964cfcebdSCristian Dumitrescu } 215064cfcebdSCristian Dumitrescu 2151f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_profile_add_help[] = 2152f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter profile <profile_name> add " 2153f38913b7SCristian Dumitrescu "cir <cir> pir <pir> cbs <cbs> pbs <pbs>\n"; 2154f38913b7SCristian Dumitrescu 2155f38913b7SCristian Dumitrescu static void 2156f38913b7SCristian Dumitrescu cmd_pipeline_meter_profile_add(char **tokens, 2157f38913b7SCristian Dumitrescu uint32_t n_tokens, 2158f38913b7SCristian Dumitrescu char *out, 2159f38913b7SCristian Dumitrescu size_t out_size, 2160f38913b7SCristian Dumitrescu void *obj) 2161f38913b7SCristian Dumitrescu { 2162f38913b7SCristian Dumitrescu struct rte_meter_trtcm_params params; 2163f38913b7SCristian Dumitrescu struct pipeline *p; 2164f38913b7SCristian Dumitrescu const char *profile_name; 2165f38913b7SCristian Dumitrescu int status; 2166f38913b7SCristian Dumitrescu 2167f38913b7SCristian Dumitrescu if (n_tokens != 14) { 2168f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 2169f38913b7SCristian Dumitrescu return; 2170f38913b7SCristian Dumitrescu } 2171f38913b7SCristian Dumitrescu 2172f38913b7SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 2173f38913b7SCristian Dumitrescu if (!p || !p->ctl) { 2174f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 2175f38913b7SCristian Dumitrescu return; 2176f38913b7SCristian Dumitrescu } 2177f38913b7SCristian Dumitrescu 2178f38913b7SCristian Dumitrescu if (strcmp(tokens[2], "meter")) { 2179f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter"); 2180f38913b7SCristian Dumitrescu return; 2181f38913b7SCristian Dumitrescu } 2182f38913b7SCristian Dumitrescu 2183f38913b7SCristian Dumitrescu if (strcmp(tokens[3], "profile")) { 2184f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile"); 2185f38913b7SCristian Dumitrescu return; 2186f38913b7SCristian Dumitrescu } 2187f38913b7SCristian Dumitrescu 2188f38913b7SCristian Dumitrescu profile_name = tokens[4]; 2189f38913b7SCristian Dumitrescu 2190f38913b7SCristian Dumitrescu if (strcmp(tokens[5], "add")) { 2191f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add"); 2192f38913b7SCristian Dumitrescu return; 2193f38913b7SCristian Dumitrescu } 2194f38913b7SCristian Dumitrescu 2195f38913b7SCristian Dumitrescu if (strcmp(tokens[6], "cir")) { 2196f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir"); 2197f38913b7SCristian Dumitrescu return; 2198f38913b7SCristian Dumitrescu } 2199f38913b7SCristian Dumitrescu 2200f38913b7SCristian Dumitrescu if (parser_read_uint64(¶ms.cir, tokens[7])) { 2201f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "cir"); 2202f38913b7SCristian Dumitrescu return; 2203f38913b7SCristian Dumitrescu } 2204f38913b7SCristian Dumitrescu 2205f38913b7SCristian Dumitrescu if (strcmp(tokens[8], "pir")) { 2206f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir"); 2207f38913b7SCristian Dumitrescu return; 2208f38913b7SCristian Dumitrescu } 2209f38913b7SCristian Dumitrescu 2210f38913b7SCristian Dumitrescu if (parser_read_uint64(¶ms.pir, tokens[9])) { 2211f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pir"); 2212f38913b7SCristian Dumitrescu return; 2213f38913b7SCristian Dumitrescu } 2214f38913b7SCristian Dumitrescu 2215f38913b7SCristian Dumitrescu if (strcmp(tokens[10], "cbs")) { 2216f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs"); 2217f38913b7SCristian Dumitrescu return; 2218f38913b7SCristian Dumitrescu } 2219f38913b7SCristian Dumitrescu 2220f38913b7SCristian Dumitrescu if (parser_read_uint64(¶ms.cbs, tokens[11])) { 2221f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "cbs"); 2222f38913b7SCristian Dumitrescu return; 2223f38913b7SCristian Dumitrescu } 2224f38913b7SCristian Dumitrescu 2225f38913b7SCristian Dumitrescu if (strcmp(tokens[12], "pbs")) { 2226f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs"); 2227f38913b7SCristian Dumitrescu return; 2228f38913b7SCristian Dumitrescu } 2229f38913b7SCristian Dumitrescu 2230f38913b7SCristian Dumitrescu if (parser_read_uint64(¶ms.pbs, tokens[13])) { 2231f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pbs"); 2232f38913b7SCristian Dumitrescu return; 2233f38913b7SCristian Dumitrescu } 2234f38913b7SCristian Dumitrescu 2235f38913b7SCristian Dumitrescu status = rte_swx_ctl_meter_profile_add(p->p, profile_name, ¶ms); 2236f38913b7SCristian Dumitrescu if (status) { 2237f38913b7SCristian Dumitrescu snprintf(out, out_size, "Command failed.\n"); 2238f38913b7SCristian Dumitrescu return; 2239f38913b7SCristian Dumitrescu } 2240f38913b7SCristian Dumitrescu } 2241f38913b7SCristian Dumitrescu 2242f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_profile_delete_help[] = 2243f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter profile <profile_name> delete\n"; 2244f38913b7SCristian Dumitrescu 2245f38913b7SCristian Dumitrescu static void 2246f38913b7SCristian Dumitrescu cmd_pipeline_meter_profile_delete(char **tokens, 2247f38913b7SCristian Dumitrescu uint32_t n_tokens, 2248f38913b7SCristian Dumitrescu char *out, 2249f38913b7SCristian Dumitrescu size_t out_size, 2250f38913b7SCristian Dumitrescu void *obj) 2251f38913b7SCristian Dumitrescu { 2252f38913b7SCristian Dumitrescu struct pipeline *p; 2253f38913b7SCristian Dumitrescu const char *profile_name; 2254f38913b7SCristian Dumitrescu int status; 2255f38913b7SCristian Dumitrescu 2256f38913b7SCristian Dumitrescu if (n_tokens != 6) { 2257f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 2258f38913b7SCristian Dumitrescu return; 2259f38913b7SCristian Dumitrescu } 2260f38913b7SCristian Dumitrescu 2261f38913b7SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 2262f38913b7SCristian Dumitrescu if (!p || !p->ctl) { 2263f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 2264f38913b7SCristian Dumitrescu return; 2265f38913b7SCristian Dumitrescu } 2266f38913b7SCristian Dumitrescu 2267f38913b7SCristian Dumitrescu if (strcmp(tokens[2], "meter")) { 2268f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter"); 2269f38913b7SCristian Dumitrescu return; 2270f38913b7SCristian Dumitrescu } 2271f38913b7SCristian Dumitrescu 2272f38913b7SCristian Dumitrescu if (strcmp(tokens[3], "profile")) { 2273f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile"); 2274f38913b7SCristian Dumitrescu return; 2275f38913b7SCristian Dumitrescu } 2276f38913b7SCristian Dumitrescu 2277f38913b7SCristian Dumitrescu profile_name = tokens[4]; 2278f38913b7SCristian Dumitrescu 2279f38913b7SCristian Dumitrescu if (strcmp(tokens[5], "delete")) { 2280f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete"); 2281f38913b7SCristian Dumitrescu return; 2282f38913b7SCristian Dumitrescu } 2283f38913b7SCristian Dumitrescu 2284f38913b7SCristian Dumitrescu status = rte_swx_ctl_meter_profile_delete(p->p, profile_name); 2285f38913b7SCristian Dumitrescu if (status) { 2286f38913b7SCristian Dumitrescu snprintf(out, out_size, "Command failed.\n"); 2287f38913b7SCristian Dumitrescu return; 2288f38913b7SCristian Dumitrescu } 2289f38913b7SCristian Dumitrescu } 2290f38913b7SCristian Dumitrescu 2291f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_reset_help[] = 2292f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> " 2293f38913b7SCristian Dumitrescu "reset\n"; 2294f38913b7SCristian Dumitrescu 2295f38913b7SCristian Dumitrescu static void 2296f38913b7SCristian Dumitrescu cmd_pipeline_meter_reset(char **tokens, 2297f38913b7SCristian Dumitrescu uint32_t n_tokens, 2298f38913b7SCristian Dumitrescu char *out, 2299f38913b7SCristian Dumitrescu size_t out_size, 2300f38913b7SCristian Dumitrescu void *obj) 2301f38913b7SCristian Dumitrescu { 2302f38913b7SCristian Dumitrescu struct pipeline *p; 2303f38913b7SCristian Dumitrescu const char *name; 230400b67591SAli Alnubani uint32_t idx0 = 0, idx1 = 0; 2305f38913b7SCristian Dumitrescu 2306f38913b7SCristian Dumitrescu if (n_tokens != 9) { 2307f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 2308f38913b7SCristian Dumitrescu return; 2309f38913b7SCristian Dumitrescu } 2310f38913b7SCristian Dumitrescu 2311f38913b7SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 2312f38913b7SCristian Dumitrescu if (!p || !p->ctl) { 2313f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 2314f38913b7SCristian Dumitrescu return; 2315f38913b7SCristian Dumitrescu } 2316f38913b7SCristian Dumitrescu 2317f38913b7SCristian Dumitrescu if (strcmp(tokens[2], "meter")) { 2318f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter"); 2319f38913b7SCristian Dumitrescu return; 2320f38913b7SCristian Dumitrescu } 2321f38913b7SCristian Dumitrescu 2322f38913b7SCristian Dumitrescu name = tokens[3]; 2323f38913b7SCristian Dumitrescu 2324f38913b7SCristian Dumitrescu if (strcmp(tokens[4], "from")) { 2325f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from"); 2326f38913b7SCristian Dumitrescu return; 2327f38913b7SCristian Dumitrescu } 2328f38913b7SCristian Dumitrescu 2329f38913b7SCristian Dumitrescu if (parser_read_uint32(&idx0, tokens[5])) { 2330f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index0"); 2331f38913b7SCristian Dumitrescu return; 2332f38913b7SCristian Dumitrescu } 2333f38913b7SCristian Dumitrescu 2334f38913b7SCristian Dumitrescu if (strcmp(tokens[6], "to")) { 2335f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to"); 2336f38913b7SCristian Dumitrescu return; 2337f38913b7SCristian Dumitrescu } 2338f38913b7SCristian Dumitrescu 2339f38913b7SCristian Dumitrescu if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) { 2340f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index1"); 2341f38913b7SCristian Dumitrescu return; 2342f38913b7SCristian Dumitrescu } 2343f38913b7SCristian Dumitrescu 2344f38913b7SCristian Dumitrescu if (strcmp(tokens[8], "reset")) { 2345f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "reset"); 2346f38913b7SCristian Dumitrescu return; 2347f38913b7SCristian Dumitrescu } 2348f38913b7SCristian Dumitrescu 2349f38913b7SCristian Dumitrescu for ( ; idx0 <= idx1; idx0++) { 2350f38913b7SCristian Dumitrescu int status; 2351f38913b7SCristian Dumitrescu 2352f38913b7SCristian Dumitrescu status = rte_swx_ctl_meter_reset(p->p, name, idx0); 2353f38913b7SCristian Dumitrescu if (status) { 2354f38913b7SCristian Dumitrescu snprintf(out, out_size, "Command failed for index %u.\n", idx0); 2355f38913b7SCristian Dumitrescu return; 2356f38913b7SCristian Dumitrescu } 2357f38913b7SCristian Dumitrescu } 2358f38913b7SCristian Dumitrescu } 2359f38913b7SCristian Dumitrescu 2360f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_set_help[] = 2361f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> " 2362f38913b7SCristian Dumitrescu "set profile <profile_name>\n"; 2363f38913b7SCristian Dumitrescu 2364f38913b7SCristian Dumitrescu static void 2365f38913b7SCristian Dumitrescu cmd_pipeline_meter_set(char **tokens, 2366f38913b7SCristian Dumitrescu uint32_t n_tokens, 2367f38913b7SCristian Dumitrescu char *out, 2368f38913b7SCristian Dumitrescu size_t out_size, 2369f38913b7SCristian Dumitrescu void *obj) 2370f38913b7SCristian Dumitrescu { 2371f38913b7SCristian Dumitrescu struct pipeline *p; 2372f38913b7SCristian Dumitrescu const char *name, *profile_name; 237300b67591SAli Alnubani uint32_t idx0 = 0, idx1 = 0; 2374f38913b7SCristian Dumitrescu 2375f38913b7SCristian Dumitrescu if (n_tokens != 11) { 2376f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 2377f38913b7SCristian Dumitrescu return; 2378f38913b7SCristian Dumitrescu } 2379f38913b7SCristian Dumitrescu 2380f38913b7SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 2381f38913b7SCristian Dumitrescu if (!p || !p->ctl) { 2382f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 2383f38913b7SCristian Dumitrescu return; 2384f38913b7SCristian Dumitrescu } 2385f38913b7SCristian Dumitrescu 2386f38913b7SCristian Dumitrescu if (strcmp(tokens[2], "meter")) { 2387f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter"); 2388f38913b7SCristian Dumitrescu return; 2389f38913b7SCristian Dumitrescu } 2390f38913b7SCristian Dumitrescu 2391f38913b7SCristian Dumitrescu name = tokens[3]; 2392f38913b7SCristian Dumitrescu 2393f38913b7SCristian Dumitrescu if (strcmp(tokens[4], "from")) { 2394f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from"); 2395f38913b7SCristian Dumitrescu return; 2396f38913b7SCristian Dumitrescu } 2397f38913b7SCristian Dumitrescu 2398f38913b7SCristian Dumitrescu if (parser_read_uint32(&idx0, tokens[5])) { 2399f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index0"); 2400f38913b7SCristian Dumitrescu return; 2401f38913b7SCristian Dumitrescu } 2402f38913b7SCristian Dumitrescu 2403f38913b7SCristian Dumitrescu if (strcmp(tokens[6], "to")) { 2404f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to"); 2405f38913b7SCristian Dumitrescu return; 2406f38913b7SCristian Dumitrescu } 2407f38913b7SCristian Dumitrescu 2408f38913b7SCristian Dumitrescu if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) { 2409f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index1"); 2410f38913b7SCristian Dumitrescu return; 2411f38913b7SCristian Dumitrescu } 2412f38913b7SCristian Dumitrescu 2413f38913b7SCristian Dumitrescu if (strcmp(tokens[8], "set")) { 2414f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "set"); 2415f38913b7SCristian Dumitrescu return; 2416f38913b7SCristian Dumitrescu } 2417f38913b7SCristian Dumitrescu 2418f38913b7SCristian Dumitrescu if (strcmp(tokens[9], "profile")) { 2419f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile"); 2420f38913b7SCristian Dumitrescu return; 2421f38913b7SCristian Dumitrescu } 2422f38913b7SCristian Dumitrescu 2423f38913b7SCristian Dumitrescu profile_name = tokens[10]; 2424f38913b7SCristian Dumitrescu 2425f38913b7SCristian Dumitrescu for ( ; idx0 <= idx1; idx0++) { 2426f38913b7SCristian Dumitrescu int status; 2427f38913b7SCristian Dumitrescu 2428f38913b7SCristian Dumitrescu status = rte_swx_ctl_meter_set(p->p, name, idx0, profile_name); 2429f38913b7SCristian Dumitrescu if (status) { 2430f38913b7SCristian Dumitrescu snprintf(out, out_size, "Command failed for index %u.\n", idx0); 2431f38913b7SCristian Dumitrescu return; 2432f38913b7SCristian Dumitrescu } 2433f38913b7SCristian Dumitrescu } 2434f38913b7SCristian Dumitrescu } 2435f38913b7SCristian Dumitrescu 2436f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_stats_help[] = 2437f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> " 2438f38913b7SCristian Dumitrescu "stats\n"; 2439f38913b7SCristian Dumitrescu 2440f38913b7SCristian Dumitrescu static void 2441f38913b7SCristian Dumitrescu cmd_pipeline_meter_stats(char **tokens, 2442f38913b7SCristian Dumitrescu uint32_t n_tokens, 2443f38913b7SCristian Dumitrescu char *out, 2444f38913b7SCristian Dumitrescu size_t out_size, 2445f38913b7SCristian Dumitrescu void *obj) 2446f38913b7SCristian Dumitrescu { 2447f38913b7SCristian Dumitrescu struct rte_swx_ctl_meter_stats stats; 2448f38913b7SCristian Dumitrescu struct pipeline *p; 2449f38913b7SCristian Dumitrescu const char *name; 245000b67591SAli Alnubani uint32_t idx0 = 0, idx1 = 0; 2451f38913b7SCristian Dumitrescu 2452f38913b7SCristian Dumitrescu if (n_tokens != 9) { 2453f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 2454f38913b7SCristian Dumitrescu return; 2455f38913b7SCristian Dumitrescu } 2456f38913b7SCristian Dumitrescu 2457f38913b7SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 2458f38913b7SCristian Dumitrescu if (!p || !p->ctl) { 2459f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 2460f38913b7SCristian Dumitrescu return; 2461f38913b7SCristian Dumitrescu } 2462f38913b7SCristian Dumitrescu 2463f38913b7SCristian Dumitrescu if (strcmp(tokens[2], "meter")) { 2464f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter"); 2465f38913b7SCristian Dumitrescu return; 2466f38913b7SCristian Dumitrescu } 2467f38913b7SCristian Dumitrescu 2468f38913b7SCristian Dumitrescu name = tokens[3]; 2469f38913b7SCristian Dumitrescu 2470f38913b7SCristian Dumitrescu if (strcmp(tokens[4], "from")) { 2471f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from"); 2472f38913b7SCristian Dumitrescu return; 2473f38913b7SCristian Dumitrescu } 2474f38913b7SCristian Dumitrescu 2475f38913b7SCristian Dumitrescu if (parser_read_uint32(&idx0, tokens[5])) { 2476f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index0"); 2477f38913b7SCristian Dumitrescu return; 2478f38913b7SCristian Dumitrescu } 2479f38913b7SCristian Dumitrescu 2480f38913b7SCristian Dumitrescu if (strcmp(tokens[6], "to")) { 2481f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to"); 2482f38913b7SCristian Dumitrescu return; 2483f38913b7SCristian Dumitrescu } 2484f38913b7SCristian Dumitrescu 2485f38913b7SCristian Dumitrescu if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) { 2486f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index1"); 2487f38913b7SCristian Dumitrescu return; 2488f38913b7SCristian Dumitrescu } 2489f38913b7SCristian Dumitrescu 2490f38913b7SCristian Dumitrescu if (strcmp(tokens[8], "stats")) { 2491f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats"); 2492f38913b7SCristian Dumitrescu return; 2493f38913b7SCristian Dumitrescu } 2494f38913b7SCristian Dumitrescu 2495f38913b7SCristian Dumitrescu /* Table header. */ 2496f38913b7SCristian Dumitrescu snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n", 2497f38913b7SCristian Dumitrescu "-------", 2498f38913b7SCristian Dumitrescu "----------------", "----------------", "----------------", 2499f38913b7SCristian Dumitrescu "----------------", "----------------", "----------------"); 2500f38913b7SCristian Dumitrescu out_size -= strlen(out); 2501f38913b7SCristian Dumitrescu out += strlen(out); 2502f38913b7SCristian Dumitrescu 2503f38913b7SCristian Dumitrescu snprintf(out, out_size, "| %4s | %16s | %16s | %16s | %16s | %16s | %16s |\n", 2504f38913b7SCristian Dumitrescu "METER #", 2505f38913b7SCristian Dumitrescu "GREEN (packets)", "YELLOW (packets)", "RED (packets)", 2506f38913b7SCristian Dumitrescu "GREEN (bytes)", "YELLOW (bytes)", "RED (bytes)"); 2507f38913b7SCristian Dumitrescu out_size -= strlen(out); 2508f38913b7SCristian Dumitrescu out += strlen(out); 2509f38913b7SCristian Dumitrescu 2510f38913b7SCristian Dumitrescu snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n", 2511f38913b7SCristian Dumitrescu "-------", 2512f38913b7SCristian Dumitrescu "----------------", "----------------", "----------------", 2513f38913b7SCristian Dumitrescu "----------------", "----------------", "----------------"); 2514f38913b7SCristian Dumitrescu out_size -= strlen(out); 2515f38913b7SCristian Dumitrescu out += strlen(out); 2516f38913b7SCristian Dumitrescu 2517f38913b7SCristian Dumitrescu /* Table rows. */ 2518f38913b7SCristian Dumitrescu for ( ; idx0 <= idx1; idx0++) { 2519f38913b7SCristian Dumitrescu int status; 2520f38913b7SCristian Dumitrescu 2521f38913b7SCristian Dumitrescu status = rte_swx_ctl_meter_stats_read(p->p, name, idx0, &stats); 2522f38913b7SCristian Dumitrescu if (status) { 2523f38913b7SCristian Dumitrescu snprintf(out, out_size, "Pipeline meter stats error at index %u.\n", idx0); 2524f38913b7SCristian Dumitrescu out_size -= strlen(out); 2525f38913b7SCristian Dumitrescu out += strlen(out); 2526f38913b7SCristian Dumitrescu return; 2527f38913b7SCristian Dumitrescu } 2528f38913b7SCristian Dumitrescu 2529f38913b7SCristian Dumitrescu snprintf(out, out_size, "| %7d | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 2530f38913b7SCristian Dumitrescu " | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 " |\n", 2531f38913b7SCristian Dumitrescu idx0, 2532f38913b7SCristian Dumitrescu stats.n_pkts[RTE_COLOR_GREEN], 2533f38913b7SCristian Dumitrescu stats.n_pkts[RTE_COLOR_YELLOW], 2534f38913b7SCristian Dumitrescu stats.n_pkts[RTE_COLOR_RED], 2535f38913b7SCristian Dumitrescu stats.n_bytes[RTE_COLOR_GREEN], 2536f38913b7SCristian Dumitrescu stats.n_bytes[RTE_COLOR_YELLOW], 2537f38913b7SCristian Dumitrescu stats.n_bytes[RTE_COLOR_RED]); 2538f38913b7SCristian Dumitrescu out_size -= strlen(out); 2539f38913b7SCristian Dumitrescu out += strlen(out); 2540f38913b7SCristian Dumitrescu } 2541f38913b7SCristian Dumitrescu } 2542f38913b7SCristian Dumitrescu 25435074e1d5SCristian Dumitrescu static const char cmd_pipeline_stats_help[] = 25445074e1d5SCristian Dumitrescu "pipeline <pipeline_name> stats\n"; 25455074e1d5SCristian Dumitrescu 25465074e1d5SCristian Dumitrescu static void 25475074e1d5SCristian Dumitrescu cmd_pipeline_stats(char **tokens, 25485074e1d5SCristian Dumitrescu uint32_t n_tokens, 25495074e1d5SCristian Dumitrescu char *out, 25505074e1d5SCristian Dumitrescu size_t out_size, 25515074e1d5SCristian Dumitrescu void *obj) 25525074e1d5SCristian Dumitrescu { 25535074e1d5SCristian Dumitrescu struct rte_swx_ctl_pipeline_info info; 25545074e1d5SCristian Dumitrescu struct pipeline *p; 25555074e1d5SCristian Dumitrescu uint32_t i; 25565074e1d5SCristian Dumitrescu int status; 25575074e1d5SCristian Dumitrescu 25585074e1d5SCristian Dumitrescu if (n_tokens != 3) { 25595074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 25605074e1d5SCristian Dumitrescu return; 25615074e1d5SCristian Dumitrescu } 25625074e1d5SCristian Dumitrescu 25635074e1d5SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 25645074e1d5SCristian Dumitrescu if (!p || !p->ctl) { 25655074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 25665074e1d5SCristian Dumitrescu return; 25675074e1d5SCristian Dumitrescu } 25685074e1d5SCristian Dumitrescu 25695074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "stats")) { 25705074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats"); 25715074e1d5SCristian Dumitrescu return; 25725074e1d5SCristian Dumitrescu } 25735074e1d5SCristian Dumitrescu 25745074e1d5SCristian Dumitrescu status = rte_swx_ctl_pipeline_info_get(p->p, &info); 25755074e1d5SCristian Dumitrescu if (status) { 25765074e1d5SCristian Dumitrescu snprintf(out, out_size, "Pipeline info get error."); 25775074e1d5SCristian Dumitrescu return; 25785074e1d5SCristian Dumitrescu } 25795074e1d5SCristian Dumitrescu 25805074e1d5SCristian Dumitrescu snprintf(out, out_size, "Input ports:\n"); 25815074e1d5SCristian Dumitrescu out_size -= strlen(out); 25825074e1d5SCristian Dumitrescu out += strlen(out); 25835074e1d5SCristian Dumitrescu 25845074e1d5SCristian Dumitrescu for (i = 0; i < info.n_ports_in; i++) { 25855074e1d5SCristian Dumitrescu struct rte_swx_port_in_stats stats; 25865074e1d5SCristian Dumitrescu 25875074e1d5SCristian Dumitrescu rte_swx_ctl_pipeline_port_in_stats_read(p->p, i, &stats); 25885074e1d5SCristian Dumitrescu 25895074e1d5SCristian Dumitrescu snprintf(out, out_size, "\tPort %u:" 25905074e1d5SCristian Dumitrescu " packets %" PRIu64 25915074e1d5SCristian Dumitrescu " bytes %" PRIu64 25925074e1d5SCristian Dumitrescu " empty %" PRIu64 "\n", 25935074e1d5SCristian Dumitrescu i, stats.n_pkts, stats.n_bytes, stats.n_empty); 25945074e1d5SCristian Dumitrescu out_size -= strlen(out); 25955074e1d5SCristian Dumitrescu out += strlen(out); 25965074e1d5SCristian Dumitrescu } 25975074e1d5SCristian Dumitrescu 2598742b0a57SCristian Dumitrescu snprintf(out, out_size, "\nOutput ports:\n"); 25995074e1d5SCristian Dumitrescu out_size -= strlen(out); 26005074e1d5SCristian Dumitrescu out += strlen(out); 26015074e1d5SCristian Dumitrescu 26025074e1d5SCristian Dumitrescu for (i = 0; i < info.n_ports_out; i++) { 26035074e1d5SCristian Dumitrescu struct rte_swx_port_out_stats stats; 26045074e1d5SCristian Dumitrescu 26055074e1d5SCristian Dumitrescu rte_swx_ctl_pipeline_port_out_stats_read(p->p, i, &stats); 26065074e1d5SCristian Dumitrescu 260796b37959SCristian Dumitrescu if (i != info.n_ports_out - 1) 260817225455SCristian Dumitrescu snprintf(out, out_size, "\tPort %u:", i); 260996b37959SCristian Dumitrescu else 261017225455SCristian Dumitrescu snprintf(out, out_size, "\tDROP:"); 261117225455SCristian Dumitrescu 261217225455SCristian Dumitrescu out_size -= strlen(out); 261317225455SCristian Dumitrescu out += strlen(out); 261417225455SCristian Dumitrescu 261517225455SCristian Dumitrescu snprintf(out, 261617225455SCristian Dumitrescu out_size, 261796b37959SCristian Dumitrescu " packets %" PRIu64 261817225455SCristian Dumitrescu " bytes %" PRIu64 261917225455SCristian Dumitrescu " clone %" PRIu64 262017225455SCristian Dumitrescu " clonerr %" PRIu64 "\n", 262117225455SCristian Dumitrescu stats.n_pkts, 262217225455SCristian Dumitrescu stats.n_bytes, 262317225455SCristian Dumitrescu stats.n_pkts_clone, 262417225455SCristian Dumitrescu stats.n_pkts_clone_err); 262596b37959SCristian Dumitrescu 26265074e1d5SCristian Dumitrescu out_size -= strlen(out); 26275074e1d5SCristian Dumitrescu out += strlen(out); 26285074e1d5SCristian Dumitrescu } 2629742b0a57SCristian Dumitrescu 2630742b0a57SCristian Dumitrescu snprintf(out, out_size, "\nTables:\n"); 2631742b0a57SCristian Dumitrescu out_size -= strlen(out); 2632742b0a57SCristian Dumitrescu out += strlen(out); 2633742b0a57SCristian Dumitrescu 2634742b0a57SCristian Dumitrescu for (i = 0; i < info.n_tables; i++) { 2635742b0a57SCristian Dumitrescu struct rte_swx_ctl_table_info table_info; 2636742b0a57SCristian Dumitrescu uint64_t n_pkts_action[info.n_actions]; 2637742b0a57SCristian Dumitrescu struct rte_swx_table_stats stats = { 2638742b0a57SCristian Dumitrescu .n_pkts_hit = 0, 2639742b0a57SCristian Dumitrescu .n_pkts_miss = 0, 2640742b0a57SCristian Dumitrescu .n_pkts_action = n_pkts_action, 2641742b0a57SCristian Dumitrescu }; 2642742b0a57SCristian Dumitrescu uint32_t j; 2643742b0a57SCristian Dumitrescu 2644742b0a57SCristian Dumitrescu status = rte_swx_ctl_table_info_get(p->p, i, &table_info); 2645742b0a57SCristian Dumitrescu if (status) { 2646742b0a57SCristian Dumitrescu snprintf(out, out_size, "Table info get error."); 2647742b0a57SCristian Dumitrescu return; 2648742b0a57SCristian Dumitrescu } 2649742b0a57SCristian Dumitrescu 2650742b0a57SCristian Dumitrescu status = rte_swx_ctl_pipeline_table_stats_read(p->p, table_info.name, &stats); 2651742b0a57SCristian Dumitrescu if (status) { 2652742b0a57SCristian Dumitrescu snprintf(out, out_size, "Table stats read error."); 2653742b0a57SCristian Dumitrescu return; 2654742b0a57SCristian Dumitrescu } 2655742b0a57SCristian Dumitrescu 2656742b0a57SCristian Dumitrescu snprintf(out, out_size, "\tTable %s:\n" 2657742b0a57SCristian Dumitrescu "\t\tHit (packets): %" PRIu64 "\n" 2658742b0a57SCristian Dumitrescu "\t\tMiss (packets): %" PRIu64 "\n", 2659742b0a57SCristian Dumitrescu table_info.name, 2660742b0a57SCristian Dumitrescu stats.n_pkts_hit, 2661742b0a57SCristian Dumitrescu stats.n_pkts_miss); 2662742b0a57SCristian Dumitrescu out_size -= strlen(out); 2663742b0a57SCristian Dumitrescu out += strlen(out); 2664742b0a57SCristian Dumitrescu 2665742b0a57SCristian Dumitrescu for (j = 0; j < info.n_actions; j++) { 2666742b0a57SCristian Dumitrescu struct rte_swx_ctl_action_info action_info; 2667742b0a57SCristian Dumitrescu 2668742b0a57SCristian Dumitrescu status = rte_swx_ctl_action_info_get(p->p, j, &action_info); 2669742b0a57SCristian Dumitrescu if (status) { 2670742b0a57SCristian Dumitrescu snprintf(out, out_size, "Action info get error."); 2671742b0a57SCristian Dumitrescu return; 2672742b0a57SCristian Dumitrescu } 2673742b0a57SCristian Dumitrescu 2674742b0a57SCristian Dumitrescu snprintf(out, out_size, "\t\tAction %s (packets): %" PRIu64 "\n", 2675742b0a57SCristian Dumitrescu action_info.name, 2676742b0a57SCristian Dumitrescu stats.n_pkts_action[j]); 2677742b0a57SCristian Dumitrescu out_size -= strlen(out); 2678742b0a57SCristian Dumitrescu out += strlen(out); 2679742b0a57SCristian Dumitrescu } 2680742b0a57SCristian Dumitrescu } 26818bd4862fSCristian Dumitrescu 26828bd4862fSCristian Dumitrescu snprintf(out, out_size, "\nLearner tables:\n"); 26838bd4862fSCristian Dumitrescu out_size -= strlen(out); 26848bd4862fSCristian Dumitrescu out += strlen(out); 26858bd4862fSCristian Dumitrescu 26868bd4862fSCristian Dumitrescu for (i = 0; i < info.n_learners; i++) { 26878bd4862fSCristian Dumitrescu struct rte_swx_ctl_learner_info learner_info; 26888bd4862fSCristian Dumitrescu uint64_t n_pkts_action[info.n_actions]; 26898bd4862fSCristian Dumitrescu struct rte_swx_learner_stats stats = { 26908bd4862fSCristian Dumitrescu .n_pkts_hit = 0, 26918bd4862fSCristian Dumitrescu .n_pkts_miss = 0, 26928bd4862fSCristian Dumitrescu .n_pkts_action = n_pkts_action, 26938bd4862fSCristian Dumitrescu }; 26948bd4862fSCristian Dumitrescu uint32_t j; 26958bd4862fSCristian Dumitrescu 26968bd4862fSCristian Dumitrescu status = rte_swx_ctl_learner_info_get(p->p, i, &learner_info); 26978bd4862fSCristian Dumitrescu if (status) { 26988bd4862fSCristian Dumitrescu snprintf(out, out_size, "Learner table info get error."); 26998bd4862fSCristian Dumitrescu return; 27008bd4862fSCristian Dumitrescu } 27018bd4862fSCristian Dumitrescu 27028bd4862fSCristian Dumitrescu status = rte_swx_ctl_pipeline_learner_stats_read(p->p, learner_info.name, &stats); 27038bd4862fSCristian Dumitrescu if (status) { 27048bd4862fSCristian Dumitrescu snprintf(out, out_size, "Learner table stats read error."); 27058bd4862fSCristian Dumitrescu return; 27068bd4862fSCristian Dumitrescu } 27078bd4862fSCristian Dumitrescu 27088bd4862fSCristian Dumitrescu snprintf(out, out_size, "\tLearner table %s:\n" 27098bd4862fSCristian Dumitrescu "\t\tHit (packets): %" PRIu64 "\n" 27108bd4862fSCristian Dumitrescu "\t\tMiss (packets): %" PRIu64 "\n" 27118bd4862fSCristian Dumitrescu "\t\tLearn OK (packets): %" PRIu64 "\n" 27128bd4862fSCristian Dumitrescu "\t\tLearn error (packets): %" PRIu64 "\n" 271380dd28afSCristian Dumitrescu "\t\tRearm (packets): %" PRIu64 "\n" 27148bd4862fSCristian Dumitrescu "\t\tForget (packets): %" PRIu64 "\n", 27158bd4862fSCristian Dumitrescu learner_info.name, 27168bd4862fSCristian Dumitrescu stats.n_pkts_hit, 27178bd4862fSCristian Dumitrescu stats.n_pkts_miss, 27188bd4862fSCristian Dumitrescu stats.n_pkts_learn_ok, 27198bd4862fSCristian Dumitrescu stats.n_pkts_learn_err, 272080dd28afSCristian Dumitrescu stats.n_pkts_rearm, 27218bd4862fSCristian Dumitrescu stats.n_pkts_forget); 27228bd4862fSCristian Dumitrescu out_size -= strlen(out); 27238bd4862fSCristian Dumitrescu out += strlen(out); 27248bd4862fSCristian Dumitrescu 27258bd4862fSCristian Dumitrescu for (j = 0; j < info.n_actions; j++) { 27268bd4862fSCristian Dumitrescu struct rte_swx_ctl_action_info action_info; 27278bd4862fSCristian Dumitrescu 27288bd4862fSCristian Dumitrescu status = rte_swx_ctl_action_info_get(p->p, j, &action_info); 27298bd4862fSCristian Dumitrescu if (status) { 27308bd4862fSCristian Dumitrescu snprintf(out, out_size, "Action info get error."); 27318bd4862fSCristian Dumitrescu return; 27328bd4862fSCristian Dumitrescu } 27338bd4862fSCristian Dumitrescu 27348bd4862fSCristian Dumitrescu snprintf(out, out_size, "\t\tAction %s (packets): %" PRIu64 "\n", 27358bd4862fSCristian Dumitrescu action_info.name, 27368bd4862fSCristian Dumitrescu stats.n_pkts_action[j]); 27378bd4862fSCristian Dumitrescu out_size -= strlen(out); 27388bd4862fSCristian Dumitrescu out += strlen(out); 27398bd4862fSCristian Dumitrescu } 27408bd4862fSCristian Dumitrescu } 27415074e1d5SCristian Dumitrescu } 27425074e1d5SCristian Dumitrescu 274317225455SCristian Dumitrescu static const char cmd_pipeline_mirror_help[] = 274417225455SCristian Dumitrescu "pipeline <pipeline_name> mirror slots <n_slots> sessions <n_sessions>\n"; 274517225455SCristian Dumitrescu 274617225455SCristian Dumitrescu static void 274717225455SCristian Dumitrescu cmd_pipeline_mirror(char **tokens, 274817225455SCristian Dumitrescu uint32_t n_tokens, 274917225455SCristian Dumitrescu char *out, 275017225455SCristian Dumitrescu size_t out_size, 275117225455SCristian Dumitrescu void *obj) 275217225455SCristian Dumitrescu { 275317225455SCristian Dumitrescu struct rte_swx_pipeline_mirroring_params params; 275417225455SCristian Dumitrescu struct pipeline *p; 275517225455SCristian Dumitrescu int status; 275617225455SCristian Dumitrescu 275717225455SCristian Dumitrescu if (n_tokens != 7) { 275817225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 275917225455SCristian Dumitrescu return; 276017225455SCristian Dumitrescu } 276117225455SCristian Dumitrescu 276217225455SCristian Dumitrescu if (strcmp(tokens[0], "pipeline")) { 276317225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline"); 276417225455SCristian Dumitrescu return; 276517225455SCristian Dumitrescu } 276617225455SCristian Dumitrescu 276717225455SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 276817225455SCristian Dumitrescu if (!p) { 276917225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 277017225455SCristian Dumitrescu return; 277117225455SCristian Dumitrescu } 277217225455SCristian Dumitrescu 277317225455SCristian Dumitrescu if (strcmp(tokens[2], "mirror")) { 277417225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mirror"); 277517225455SCristian Dumitrescu return; 277617225455SCristian Dumitrescu } 277717225455SCristian Dumitrescu 277817225455SCristian Dumitrescu if (strcmp(tokens[3], "slots")) { 277917225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "slots"); 278017225455SCristian Dumitrescu return; 278117225455SCristian Dumitrescu } 278217225455SCristian Dumitrescu 278317225455SCristian Dumitrescu if (parser_read_uint32(¶ms.n_slots, tokens[4])) { 278417225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "n_slots"); 278517225455SCristian Dumitrescu return; 278617225455SCristian Dumitrescu } 278717225455SCristian Dumitrescu 278817225455SCristian Dumitrescu if (strcmp(tokens[5], "sessions")) { 278917225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "sessions"); 279017225455SCristian Dumitrescu return; 279117225455SCristian Dumitrescu } 279217225455SCristian Dumitrescu 279317225455SCristian Dumitrescu if (parser_read_uint32(¶ms.n_sessions, tokens[6])) { 279417225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "n_sessions"); 279517225455SCristian Dumitrescu return; 279617225455SCristian Dumitrescu } 279717225455SCristian Dumitrescu 279817225455SCristian Dumitrescu status = rte_swx_pipeline_mirroring_config(p->p, ¶ms); 279917225455SCristian Dumitrescu if (status) { 280017225455SCristian Dumitrescu snprintf(out, out_size, "Command failed!\n"); 280117225455SCristian Dumitrescu return; 280217225455SCristian Dumitrescu } 280317225455SCristian Dumitrescu } 280417225455SCristian Dumitrescu 280517225455SCristian Dumitrescu static const char cmd_pipeline_mirror_session_help[] = 280617225455SCristian Dumitrescu "pipeline <pipeline_name> mirror session <session_id> port <port_id> clone fast | slow " 280717225455SCristian Dumitrescu "truncate <truncation_length>\n"; 280817225455SCristian Dumitrescu 280917225455SCristian Dumitrescu static void 281017225455SCristian Dumitrescu cmd_pipeline_mirror_session(char **tokens, 281117225455SCristian Dumitrescu uint32_t n_tokens, 281217225455SCristian Dumitrescu char *out, 281317225455SCristian Dumitrescu size_t out_size, 281417225455SCristian Dumitrescu void *obj) 281517225455SCristian Dumitrescu { 281617225455SCristian Dumitrescu struct rte_swx_pipeline_mirroring_session_params params; 281717225455SCristian Dumitrescu struct pipeline *p; 281877dd857dSAli Alnubani uint32_t session_id = 0; 281917225455SCristian Dumitrescu int status; 282017225455SCristian Dumitrescu 282117225455SCristian Dumitrescu if (n_tokens != 11) { 282217225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 282317225455SCristian Dumitrescu return; 282417225455SCristian Dumitrescu } 282517225455SCristian Dumitrescu 282617225455SCristian Dumitrescu if (strcmp(tokens[0], "pipeline")) { 282717225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline"); 282817225455SCristian Dumitrescu return; 282917225455SCristian Dumitrescu } 283017225455SCristian Dumitrescu 283117225455SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 283217225455SCristian Dumitrescu if (!p || !p->ctl) { 283317225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 283417225455SCristian Dumitrescu return; 283517225455SCristian Dumitrescu } 283617225455SCristian Dumitrescu 283717225455SCristian Dumitrescu if (strcmp(tokens[2], "mirror")) { 283817225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mirror"); 283917225455SCristian Dumitrescu return; 284017225455SCristian Dumitrescu } 284117225455SCristian Dumitrescu 284217225455SCristian Dumitrescu if (strcmp(tokens[3], "session")) { 284317225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "session"); 284417225455SCristian Dumitrescu return; 284517225455SCristian Dumitrescu } 284617225455SCristian Dumitrescu 284717225455SCristian Dumitrescu if (parser_read_uint32(&session_id, tokens[4])) { 284817225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "session_id"); 284917225455SCristian Dumitrescu return; 285017225455SCristian Dumitrescu } 285117225455SCristian Dumitrescu 285217225455SCristian Dumitrescu if (strcmp(tokens[5], "port")) { 285317225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port"); 285417225455SCristian Dumitrescu return; 285517225455SCristian Dumitrescu } 285617225455SCristian Dumitrescu 285717225455SCristian Dumitrescu if (parser_read_uint32(¶ms.port_id, tokens[6])) { 285817225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "port_id"); 285917225455SCristian Dumitrescu return; 286017225455SCristian Dumitrescu } 286117225455SCristian Dumitrescu 286217225455SCristian Dumitrescu if (strcmp(tokens[7], "clone")) { 286317225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "clone"); 286417225455SCristian Dumitrescu return; 286517225455SCristian Dumitrescu } 286617225455SCristian Dumitrescu 286717225455SCristian Dumitrescu if (!strcmp(tokens[8], "fast")) 286817225455SCristian Dumitrescu params.fast_clone = 1; 286917225455SCristian Dumitrescu else if (!strcmp(tokens[8], "slow")) 287017225455SCristian Dumitrescu params.fast_clone = 0; 287117225455SCristian Dumitrescu else { 287217225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "clone"); 287317225455SCristian Dumitrescu return; 287417225455SCristian Dumitrescu } 287517225455SCristian Dumitrescu 287617225455SCristian Dumitrescu if (strcmp(tokens[9], "truncate")) { 287717225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "truncate"); 287817225455SCristian Dumitrescu return; 287917225455SCristian Dumitrescu } 288017225455SCristian Dumitrescu 288117225455SCristian Dumitrescu if (parser_read_uint32(¶ms.truncation_length, tokens[10])) { 288217225455SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "truncation_length"); 288317225455SCristian Dumitrescu return; 288417225455SCristian Dumitrescu } 288517225455SCristian Dumitrescu 288617225455SCristian Dumitrescu status = rte_swx_ctl_pipeline_mirroring_session_set(p->p, session_id, ¶ms); 288717225455SCristian Dumitrescu if (status) { 288817225455SCristian Dumitrescu snprintf(out, out_size, "Command failed!\n"); 288917225455SCristian Dumitrescu return; 289017225455SCristian Dumitrescu } 289117225455SCristian Dumitrescu } 289217225455SCristian Dumitrescu 28935074e1d5SCristian Dumitrescu static const char cmd_thread_pipeline_enable_help[] = 28945074e1d5SCristian Dumitrescu "thread <thread_id> pipeline <pipeline_name> enable\n"; 28955074e1d5SCristian Dumitrescu 28965074e1d5SCristian Dumitrescu static void 28975074e1d5SCristian Dumitrescu cmd_thread_pipeline_enable(char **tokens, 28985074e1d5SCristian Dumitrescu uint32_t n_tokens, 28995074e1d5SCristian Dumitrescu char *out, 29005074e1d5SCristian Dumitrescu size_t out_size, 29015074e1d5SCristian Dumitrescu void *obj) 29025074e1d5SCristian Dumitrescu { 29035074e1d5SCristian Dumitrescu char *pipeline_name; 29045074e1d5SCristian Dumitrescu struct pipeline *p; 29055074e1d5SCristian Dumitrescu uint32_t thread_id; 29065074e1d5SCristian Dumitrescu int status; 29075074e1d5SCristian Dumitrescu 29085074e1d5SCristian Dumitrescu if (n_tokens != 5) { 29095074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 29105074e1d5SCristian Dumitrescu return; 29115074e1d5SCristian Dumitrescu } 29125074e1d5SCristian Dumitrescu 29135074e1d5SCristian Dumitrescu if (parser_read_uint32(&thread_id, tokens[1]) != 0) { 29145074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "thread_id"); 29155074e1d5SCristian Dumitrescu return; 29165074e1d5SCristian Dumitrescu } 29175074e1d5SCristian Dumitrescu 29185074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "pipeline") != 0) { 29195074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline"); 29205074e1d5SCristian Dumitrescu return; 29215074e1d5SCristian Dumitrescu } 29225074e1d5SCristian Dumitrescu 29235074e1d5SCristian Dumitrescu pipeline_name = tokens[3]; 29245074e1d5SCristian Dumitrescu p = pipeline_find(obj, pipeline_name); 29255074e1d5SCristian Dumitrescu if (!p || !p->ctl) { 29265074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 29275074e1d5SCristian Dumitrescu return; 29285074e1d5SCristian Dumitrescu } 29295074e1d5SCristian Dumitrescu 29305074e1d5SCristian Dumitrescu if (strcmp(tokens[4], "enable") != 0) { 29315074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable"); 29325074e1d5SCristian Dumitrescu return; 29335074e1d5SCristian Dumitrescu } 29345074e1d5SCristian Dumitrescu 29355074e1d5SCristian Dumitrescu status = thread_pipeline_enable(thread_id, obj, pipeline_name); 29365074e1d5SCristian Dumitrescu if (status) { 29375074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable"); 29385074e1d5SCristian Dumitrescu return; 29395074e1d5SCristian Dumitrescu } 29405074e1d5SCristian Dumitrescu } 29415074e1d5SCristian Dumitrescu 29425074e1d5SCristian Dumitrescu static const char cmd_thread_pipeline_disable_help[] = 29435074e1d5SCristian Dumitrescu "thread <thread_id> pipeline <pipeline_name> disable\n"; 29445074e1d5SCristian Dumitrescu 29455074e1d5SCristian Dumitrescu static void 29465074e1d5SCristian Dumitrescu cmd_thread_pipeline_disable(char **tokens, 29475074e1d5SCristian Dumitrescu uint32_t n_tokens, 29485074e1d5SCristian Dumitrescu char *out, 29495074e1d5SCristian Dumitrescu size_t out_size, 29505074e1d5SCristian Dumitrescu void *obj) 29515074e1d5SCristian Dumitrescu { 29525074e1d5SCristian Dumitrescu struct pipeline *p; 29535074e1d5SCristian Dumitrescu char *pipeline_name; 29545074e1d5SCristian Dumitrescu uint32_t thread_id; 29555074e1d5SCristian Dumitrescu int status; 29565074e1d5SCristian Dumitrescu 29575074e1d5SCristian Dumitrescu if (n_tokens != 5) { 29585074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 29595074e1d5SCristian Dumitrescu return; 29605074e1d5SCristian Dumitrescu } 29615074e1d5SCristian Dumitrescu 29625074e1d5SCristian Dumitrescu if (parser_read_uint32(&thread_id, tokens[1]) != 0) { 29635074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "thread_id"); 29645074e1d5SCristian Dumitrescu return; 29655074e1d5SCristian Dumitrescu } 29665074e1d5SCristian Dumitrescu 29675074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "pipeline") != 0) { 29685074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline"); 29695074e1d5SCristian Dumitrescu return; 29705074e1d5SCristian Dumitrescu } 29715074e1d5SCristian Dumitrescu 29725074e1d5SCristian Dumitrescu pipeline_name = tokens[3]; 29735074e1d5SCristian Dumitrescu p = pipeline_find(obj, pipeline_name); 29745074e1d5SCristian Dumitrescu if (!p || !p->ctl) { 29755074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 29765074e1d5SCristian Dumitrescu return; 29775074e1d5SCristian Dumitrescu } 29785074e1d5SCristian Dumitrescu 29795074e1d5SCristian Dumitrescu if (strcmp(tokens[4], "disable") != 0) { 29805074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable"); 29815074e1d5SCristian Dumitrescu return; 29825074e1d5SCristian Dumitrescu } 29835074e1d5SCristian Dumitrescu 29845074e1d5SCristian Dumitrescu status = thread_pipeline_disable(thread_id, obj, pipeline_name); 29855074e1d5SCristian Dumitrescu if (status) { 29865074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, 29875074e1d5SCristian Dumitrescu "thread pipeline disable"); 29885074e1d5SCristian Dumitrescu return; 29895074e1d5SCristian Dumitrescu } 29905074e1d5SCristian Dumitrescu } 29915074e1d5SCristian Dumitrescu 29925074e1d5SCristian Dumitrescu static void 29935074e1d5SCristian Dumitrescu cmd_help(char **tokens, 29945074e1d5SCristian Dumitrescu uint32_t n_tokens, 29955074e1d5SCristian Dumitrescu char *out, 29965074e1d5SCristian Dumitrescu size_t out_size, 29975074e1d5SCristian Dumitrescu void *arg __rte_unused) 29985074e1d5SCristian Dumitrescu { 29995074e1d5SCristian Dumitrescu tokens++; 30005074e1d5SCristian Dumitrescu n_tokens--; 30015074e1d5SCristian Dumitrescu 30025074e1d5SCristian Dumitrescu if (n_tokens == 0) { 30035074e1d5SCristian Dumitrescu snprintf(out, out_size, 30047fef9ef1SYogesh Jangra "Type 'help <command>' for command details.\n\n" 30057fef9ef1SYogesh Jangra "List of commands:\n" 30067fef9ef1SYogesh Jangra "\tmempool\n" 30077fef9ef1SYogesh Jangra "\tlink\n" 3008e2b8dc52SVenkata Suresh Kumar P "\ttap\n" 30097fef9ef1SYogesh Jangra "\tpipeline create\n" 30107fef9ef1SYogesh Jangra "\tpipeline port in\n" 30117fef9ef1SYogesh Jangra "\tpipeline port out\n" 30127fef9ef1SYogesh Jangra "\tpipeline build\n" 301375129cebSChurchill Khangar "\tpipeline table add\n" 301475129cebSChurchill Khangar "\tpipeline table delete\n" 301575129cebSChurchill Khangar "\tpipeline table default\n" 301675129cebSChurchill Khangar "\tpipeline table show\n" 3017598fe0ddSCristian Dumitrescu "\tpipeline selector group add\n" 3018598fe0ddSCristian Dumitrescu "\tpipeline selector group delete\n" 3019598fe0ddSCristian Dumitrescu "\tpipeline selector group member add\n" 3020598fe0ddSCristian Dumitrescu "\tpipeline selector group member delete\n" 3021598fe0ddSCristian Dumitrescu "\tpipeline selector show\n" 30228bd4862fSCristian Dumitrescu "\tpipeline learner default\n" 302375129cebSChurchill Khangar "\tpipeline commit\n" 302475129cebSChurchill Khangar "\tpipeline abort\n" 302564cfcebdSCristian Dumitrescu "\tpipeline regrd\n" 302664cfcebdSCristian Dumitrescu "\tpipeline regwr\n" 3027f38913b7SCristian Dumitrescu "\tpipeline meter profile add\n" 3028f38913b7SCristian Dumitrescu "\tpipeline meter profile delete\n" 3029f38913b7SCristian Dumitrescu "\tpipeline meter reset\n" 3030f38913b7SCristian Dumitrescu "\tpipeline meter set\n" 3031f38913b7SCristian Dumitrescu "\tpipeline meter stats\n" 30327fef9ef1SYogesh Jangra "\tpipeline stats\n" 303317225455SCristian Dumitrescu "\tpipeline mirror\n" 303417225455SCristian Dumitrescu "\tpipeline mirror session\n" 30357fef9ef1SYogesh Jangra "\tthread pipeline enable\n" 30367fef9ef1SYogesh Jangra "\tthread pipeline disable\n\n"); 30375074e1d5SCristian Dumitrescu return; 30385074e1d5SCristian Dumitrescu } 30395074e1d5SCristian Dumitrescu 30405074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "mempool") == 0) { 30415074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_mempool_help); 30425074e1d5SCristian Dumitrescu return; 30435074e1d5SCristian Dumitrescu } 30445074e1d5SCristian Dumitrescu 30455074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "link") == 0) { 30465074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_link_help); 30475074e1d5SCristian Dumitrescu return; 30485074e1d5SCristian Dumitrescu } 30495074e1d5SCristian Dumitrescu 305077a41301SCristian Dumitrescu if (strcmp(tokens[0], "ring") == 0) { 305177a41301SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_ring_help); 305277a41301SCristian Dumitrescu return; 305377a41301SCristian Dumitrescu } 305477a41301SCristian Dumitrescu 3055e2b8dc52SVenkata Suresh Kumar P if (strcmp(tokens[0], "tap") == 0) { 3056e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, "\n%s\n", cmd_tap_help); 3057e2b8dc52SVenkata Suresh Kumar P return; 3058e2b8dc52SVenkata Suresh Kumar P } 3059e2b8dc52SVenkata Suresh Kumar P 30605074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 30617fef9ef1SYogesh Jangra (n_tokens == 2) && (strcmp(tokens[1], "create") == 0)) { 30625074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_create_help); 30635074e1d5SCristian Dumitrescu return; 30645074e1d5SCristian Dumitrescu } 30655074e1d5SCristian Dumitrescu 30665074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 30677fef9ef1SYogesh Jangra (n_tokens == 3) && (strcmp(tokens[1], "port") == 0)) { 30687fef9ef1SYogesh Jangra if (strcmp(tokens[2], "in") == 0) { 30695074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 30705074e1d5SCristian Dumitrescu cmd_pipeline_port_in_help); 30715074e1d5SCristian Dumitrescu return; 30725074e1d5SCristian Dumitrescu } 30735074e1d5SCristian Dumitrescu 30747fef9ef1SYogesh Jangra if (strcmp(tokens[2], "out") == 0) { 30755074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 30765074e1d5SCristian Dumitrescu cmd_pipeline_port_out_help); 30775074e1d5SCristian Dumitrescu return; 30785074e1d5SCristian Dumitrescu } 30795074e1d5SCristian Dumitrescu } 30805074e1d5SCristian Dumitrescu 30815074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 30827fef9ef1SYogesh Jangra (n_tokens == 2) && (strcmp(tokens[1], "build") == 0)) { 30835074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_build_help); 30845074e1d5SCristian Dumitrescu return; 30855074e1d5SCristian Dumitrescu } 30865074e1d5SCristian Dumitrescu 30875074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 30887fef9ef1SYogesh Jangra (n_tokens == 3) && 30897fef9ef1SYogesh Jangra (strcmp(tokens[1], "table") == 0) && 309075129cebSChurchill Khangar (strcmp(tokens[2], "add") == 0)) { 30915074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 309275129cebSChurchill Khangar cmd_pipeline_table_add_help); 309375129cebSChurchill Khangar return; 309475129cebSChurchill Khangar } 309575129cebSChurchill Khangar 309675129cebSChurchill Khangar if ((strcmp(tokens[0], "pipeline") == 0) && 309775129cebSChurchill Khangar (n_tokens == 3) && 309875129cebSChurchill Khangar (strcmp(tokens[1], "table") == 0) && 309975129cebSChurchill Khangar (strcmp(tokens[2], "delete") == 0)) { 310075129cebSChurchill Khangar snprintf(out, out_size, "\n%s\n", 310175129cebSChurchill Khangar cmd_pipeline_table_delete_help); 310275129cebSChurchill Khangar return; 310375129cebSChurchill Khangar } 310475129cebSChurchill Khangar 310575129cebSChurchill Khangar if ((strcmp(tokens[0], "pipeline") == 0) && 310675129cebSChurchill Khangar (n_tokens == 3) && 310775129cebSChurchill Khangar (strcmp(tokens[1], "table") == 0) && 310875129cebSChurchill Khangar (strcmp(tokens[2], "default") == 0)) { 310975129cebSChurchill Khangar snprintf(out, out_size, "\n%s\n", 311075129cebSChurchill Khangar cmd_pipeline_table_default_help); 311175129cebSChurchill Khangar return; 311275129cebSChurchill Khangar } 311375129cebSChurchill Khangar 311475129cebSChurchill Khangar if ((strcmp(tokens[0], "pipeline") == 0) && 311575129cebSChurchill Khangar (n_tokens == 3) && 311675129cebSChurchill Khangar (strcmp(tokens[1], "table") == 0) && 311775129cebSChurchill Khangar (strcmp(tokens[2], "show") == 0)) { 311875129cebSChurchill Khangar snprintf(out, out_size, "\n%s\n", 311975129cebSChurchill Khangar cmd_pipeline_table_show_help); 312075129cebSChurchill Khangar return; 312175129cebSChurchill Khangar } 312275129cebSChurchill Khangar 312375129cebSChurchill Khangar if ((strcmp(tokens[0], "pipeline") == 0) && 3124598fe0ddSCristian Dumitrescu (n_tokens == 4) && 3125598fe0ddSCristian Dumitrescu (strcmp(tokens[1], "selector") == 0) && 3126598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "group") == 0) && 3127598fe0ddSCristian Dumitrescu (strcmp(tokens[3], "add") == 0)) { 3128598fe0ddSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 3129598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_add_help); 3130598fe0ddSCristian Dumitrescu return; 3131598fe0ddSCristian Dumitrescu } 3132598fe0ddSCristian Dumitrescu 3133598fe0ddSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 3134598fe0ddSCristian Dumitrescu (n_tokens == 4) && 3135598fe0ddSCristian Dumitrescu (strcmp(tokens[1], "selector") == 0) && 3136598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "group") == 0) && 3137598fe0ddSCristian Dumitrescu (strcmp(tokens[3], "delete") == 0)) { 3138598fe0ddSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 3139598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_delete_help); 3140598fe0ddSCristian Dumitrescu return; 3141598fe0ddSCristian Dumitrescu } 3142598fe0ddSCristian Dumitrescu 3143598fe0ddSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 3144598fe0ddSCristian Dumitrescu (n_tokens == 5) && 3145598fe0ddSCristian Dumitrescu (strcmp(tokens[1], "selector") == 0) && 3146598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "group") == 0) && 3147598fe0ddSCristian Dumitrescu (strcmp(tokens[3], "member") == 0) && 3148598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "add") == 0)) { 3149598fe0ddSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 3150598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_add_help); 3151598fe0ddSCristian Dumitrescu return; 3152598fe0ddSCristian Dumitrescu } 3153598fe0ddSCristian Dumitrescu 3154598fe0ddSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 3155598fe0ddSCristian Dumitrescu (n_tokens == 5) && 3156598fe0ddSCristian Dumitrescu (strcmp(tokens[1], "selector") == 0) && 3157598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "group") == 0) && 3158598fe0ddSCristian Dumitrescu (strcmp(tokens[3], "member") == 0) && 3159598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "delete") == 0)) { 3160598fe0ddSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 3161598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_delete_help); 3162598fe0ddSCristian Dumitrescu return; 3163598fe0ddSCristian Dumitrescu } 3164598fe0ddSCristian Dumitrescu 3165598fe0ddSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 3166598fe0ddSCristian Dumitrescu (n_tokens == 3) && 3167598fe0ddSCristian Dumitrescu (strcmp(tokens[1], "selector") == 0) && 3168598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "show") == 0)) { 3169598fe0ddSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 3170598fe0ddSCristian Dumitrescu cmd_pipeline_selector_show_help); 3171598fe0ddSCristian Dumitrescu return; 3172598fe0ddSCristian Dumitrescu } 3173598fe0ddSCristian Dumitrescu 3174598fe0ddSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 31758bd4862fSCristian Dumitrescu (n_tokens == 3) && 31768bd4862fSCristian Dumitrescu (strcmp(tokens[1], "learner") == 0) && 31778bd4862fSCristian Dumitrescu (strcmp(tokens[2], "default") == 0)) { 31788bd4862fSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 31798bd4862fSCristian Dumitrescu cmd_pipeline_learner_default_help); 31808bd4862fSCristian Dumitrescu return; 31818bd4862fSCristian Dumitrescu } 31828bd4862fSCristian Dumitrescu 31838bd4862fSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 318475129cebSChurchill Khangar (n_tokens == 2) && 318575129cebSChurchill Khangar (strcmp(tokens[1], "commit") == 0)) { 318675129cebSChurchill Khangar snprintf(out, out_size, "\n%s\n", 318775129cebSChurchill Khangar cmd_pipeline_commit_help); 318875129cebSChurchill Khangar return; 318975129cebSChurchill Khangar } 319075129cebSChurchill Khangar 319175129cebSChurchill Khangar if ((strcmp(tokens[0], "pipeline") == 0) && 319275129cebSChurchill Khangar (n_tokens == 2) && 319375129cebSChurchill Khangar (strcmp(tokens[1], "abort") == 0)) { 319475129cebSChurchill Khangar snprintf(out, out_size, "\n%s\n", 319575129cebSChurchill Khangar cmd_pipeline_abort_help); 31965074e1d5SCristian Dumitrescu return; 31975074e1d5SCristian Dumitrescu } 31985074e1d5SCristian Dumitrescu 31995074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 320064cfcebdSCristian Dumitrescu (n_tokens == 2) && (strcmp(tokens[1], "regrd") == 0)) { 320164cfcebdSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_regrd_help); 320264cfcebdSCristian Dumitrescu return; 320364cfcebdSCristian Dumitrescu } 320464cfcebdSCristian Dumitrescu 320564cfcebdSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 320664cfcebdSCristian Dumitrescu (n_tokens == 2) && (strcmp(tokens[1], "regwr") == 0)) { 320764cfcebdSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_regwr_help); 320864cfcebdSCristian Dumitrescu return; 320964cfcebdSCristian Dumitrescu } 321064cfcebdSCristian Dumitrescu 3211f38913b7SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") && 3212f38913b7SCristian Dumitrescu (n_tokens == 4) && !strcmp(tokens[1], "meter") 3213f38913b7SCristian Dumitrescu && !strcmp(tokens[2], "profile") 3214f38913b7SCristian Dumitrescu && !strcmp(tokens[3], "add")) { 3215f38913b7SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_profile_add_help); 3216f38913b7SCristian Dumitrescu return; 3217f38913b7SCristian Dumitrescu } 3218f38913b7SCristian Dumitrescu 3219f38913b7SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") && 3220f38913b7SCristian Dumitrescu (n_tokens == 4) && !strcmp(tokens[1], "meter") 3221f38913b7SCristian Dumitrescu && !strcmp(tokens[2], "profile") 3222f38913b7SCristian Dumitrescu && !strcmp(tokens[3], "delete")) { 3223f38913b7SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_profile_delete_help); 3224f38913b7SCristian Dumitrescu return; 3225f38913b7SCristian Dumitrescu } 3226f38913b7SCristian Dumitrescu 3227f38913b7SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") && 3228f38913b7SCristian Dumitrescu (n_tokens == 3) && !strcmp(tokens[1], "meter") 3229f38913b7SCristian Dumitrescu && !strcmp(tokens[2], "reset")) { 3230f38913b7SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_reset_help); 3231f38913b7SCristian Dumitrescu return; 3232f38913b7SCristian Dumitrescu } 3233f38913b7SCristian Dumitrescu 3234f38913b7SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") && 3235f38913b7SCristian Dumitrescu (n_tokens == 3) && !strcmp(tokens[1], "meter") 3236f38913b7SCristian Dumitrescu && !strcmp(tokens[2], "set")) { 3237f38913b7SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_set_help); 3238f38913b7SCristian Dumitrescu return; 3239f38913b7SCristian Dumitrescu } 3240f38913b7SCristian Dumitrescu 3241f38913b7SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") && 3242f38913b7SCristian Dumitrescu (n_tokens == 3) && !strcmp(tokens[1], "meter") 3243f38913b7SCristian Dumitrescu && !strcmp(tokens[2], "stats")) { 3244f38913b7SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_stats_help); 3245f38913b7SCristian Dumitrescu return; 3246f38913b7SCristian Dumitrescu } 3247f38913b7SCristian Dumitrescu 324864cfcebdSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 32497fef9ef1SYogesh Jangra (n_tokens == 2) && (strcmp(tokens[1], "stats") == 0)) { 32505074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_stats_help); 32515074e1d5SCristian Dumitrescu return; 32525074e1d5SCristian Dumitrescu } 32535074e1d5SCristian Dumitrescu 325417225455SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") && 325517225455SCristian Dumitrescu (n_tokens == 2) && !strcmp(tokens[1], "mirror")) { 325617225455SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_mirror_help); 325717225455SCristian Dumitrescu return; 325817225455SCristian Dumitrescu } 325917225455SCristian Dumitrescu 326017225455SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") && 326117225455SCristian Dumitrescu (n_tokens == 3) && !strcmp(tokens[1], "mirror") 326217225455SCristian Dumitrescu && !strcmp(tokens[2], "session")) { 326317225455SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_mirror_session_help); 326417225455SCristian Dumitrescu return; 326517225455SCristian Dumitrescu } 326617225455SCristian Dumitrescu 32675074e1d5SCristian Dumitrescu if ((n_tokens == 3) && 32685074e1d5SCristian Dumitrescu (strcmp(tokens[0], "thread") == 0) && 32695074e1d5SCristian Dumitrescu (strcmp(tokens[1], "pipeline") == 0)) { 32705074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "enable") == 0) { 32715074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 32725074e1d5SCristian Dumitrescu cmd_thread_pipeline_enable_help); 32735074e1d5SCristian Dumitrescu return; 32745074e1d5SCristian Dumitrescu } 32755074e1d5SCristian Dumitrescu 32765074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "disable") == 0) { 32775074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 32785074e1d5SCristian Dumitrescu cmd_thread_pipeline_disable_help); 32795074e1d5SCristian Dumitrescu return; 32805074e1d5SCristian Dumitrescu } 32815074e1d5SCristian Dumitrescu } 32825074e1d5SCristian Dumitrescu 32835074e1d5SCristian Dumitrescu snprintf(out, out_size, "Invalid command\n"); 32845074e1d5SCristian Dumitrescu } 32855074e1d5SCristian Dumitrescu 32865074e1d5SCristian Dumitrescu void 32875074e1d5SCristian Dumitrescu cli_process(char *in, char *out, size_t out_size, void *obj) 32885074e1d5SCristian Dumitrescu { 32895074e1d5SCristian Dumitrescu char *tokens[CMD_MAX_TOKENS]; 32905074e1d5SCristian Dumitrescu uint32_t n_tokens = RTE_DIM(tokens); 32915074e1d5SCristian Dumitrescu int status; 32925074e1d5SCristian Dumitrescu 32935074e1d5SCristian Dumitrescu if (is_comment(in)) 32945074e1d5SCristian Dumitrescu return; 32955074e1d5SCristian Dumitrescu 32965074e1d5SCristian Dumitrescu status = parse_tokenize_string(in, tokens, &n_tokens); 32975074e1d5SCristian Dumitrescu if (status) { 32985074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_TOO_MANY, ""); 32995074e1d5SCristian Dumitrescu return; 33005074e1d5SCristian Dumitrescu } 33015074e1d5SCristian Dumitrescu 33025074e1d5SCristian Dumitrescu if (n_tokens == 0) 33035074e1d5SCristian Dumitrescu return; 33045074e1d5SCristian Dumitrescu 33055074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "help") == 0) { 33065074e1d5SCristian Dumitrescu cmd_help(tokens, n_tokens, out, out_size, obj); 33075074e1d5SCristian Dumitrescu return; 33085074e1d5SCristian Dumitrescu } 33095074e1d5SCristian Dumitrescu 33105074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "mempool") == 0) { 33115074e1d5SCristian Dumitrescu cmd_mempool(tokens, n_tokens, out, out_size, obj); 33125074e1d5SCristian Dumitrescu return; 33135074e1d5SCristian Dumitrescu } 33145074e1d5SCristian Dumitrescu 33155074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "link") == 0) { 3316821848f5SCristian Dumitrescu if ((n_tokens >= 2) && (strcmp(tokens[1], "show") == 0)) { 33175074e1d5SCristian Dumitrescu cmd_link_show(tokens, n_tokens, out, out_size, obj); 33185074e1d5SCristian Dumitrescu return; 33195074e1d5SCristian Dumitrescu } 33205074e1d5SCristian Dumitrescu 33215074e1d5SCristian Dumitrescu cmd_link(tokens, n_tokens, out, out_size, obj); 33225074e1d5SCristian Dumitrescu return; 33235074e1d5SCristian Dumitrescu } 33245074e1d5SCristian Dumitrescu 332577a41301SCristian Dumitrescu if (strcmp(tokens[0], "ring") == 0) { 332677a41301SCristian Dumitrescu cmd_ring(tokens, n_tokens, out, out_size, obj); 332777a41301SCristian Dumitrescu return; 332877a41301SCristian Dumitrescu } 332977a41301SCristian Dumitrescu 3330e2b8dc52SVenkata Suresh Kumar P if (strcmp(tokens[0], "tap") == 0) { 3331e2b8dc52SVenkata Suresh Kumar P cmd_tap(tokens, n_tokens, out, out_size, obj); 3332e2b8dc52SVenkata Suresh Kumar P return; 3333e2b8dc52SVenkata Suresh Kumar P } 3334e2b8dc52SVenkata Suresh Kumar P 33355074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "pipeline") == 0) { 33365074e1d5SCristian Dumitrescu if ((n_tokens >= 3) && 33375074e1d5SCristian Dumitrescu (strcmp(tokens[2], "create") == 0)) { 33385074e1d5SCristian Dumitrescu cmd_pipeline_create(tokens, n_tokens, out, out_size, 33395074e1d5SCristian Dumitrescu obj); 33405074e1d5SCristian Dumitrescu return; 33415074e1d5SCristian Dumitrescu } 33425074e1d5SCristian Dumitrescu 33435074e1d5SCristian Dumitrescu if ((n_tokens >= 4) && 33445074e1d5SCristian Dumitrescu (strcmp(tokens[2], "port") == 0) && 33455074e1d5SCristian Dumitrescu (strcmp(tokens[3], "in") == 0)) { 33465074e1d5SCristian Dumitrescu cmd_pipeline_port_in(tokens, n_tokens, out, out_size, 33475074e1d5SCristian Dumitrescu obj); 33485074e1d5SCristian Dumitrescu return; 33495074e1d5SCristian Dumitrescu } 33505074e1d5SCristian Dumitrescu 33515074e1d5SCristian Dumitrescu if ((n_tokens >= 4) && 33525074e1d5SCristian Dumitrescu (strcmp(tokens[2], "port") == 0) && 33535074e1d5SCristian Dumitrescu (strcmp(tokens[3], "out") == 0)) { 33545074e1d5SCristian Dumitrescu cmd_pipeline_port_out(tokens, n_tokens, out, out_size, 33555074e1d5SCristian Dumitrescu obj); 33565074e1d5SCristian Dumitrescu return; 33575074e1d5SCristian Dumitrescu } 33585074e1d5SCristian Dumitrescu 33595074e1d5SCristian Dumitrescu if ((n_tokens >= 3) && 33605074e1d5SCristian Dumitrescu (strcmp(tokens[2], "build") == 0)) { 33615074e1d5SCristian Dumitrescu cmd_pipeline_build(tokens, n_tokens, out, out_size, 33625074e1d5SCristian Dumitrescu obj); 33635074e1d5SCristian Dumitrescu return; 33645074e1d5SCristian Dumitrescu } 33655074e1d5SCristian Dumitrescu 336675129cebSChurchill Khangar if ((n_tokens >= 5) && 336775129cebSChurchill Khangar (strcmp(tokens[2], "table") == 0) && 336875129cebSChurchill Khangar (strcmp(tokens[4], "add") == 0)) { 336975129cebSChurchill Khangar cmd_pipeline_table_add(tokens, n_tokens, out, 337075129cebSChurchill Khangar out_size, obj); 337175129cebSChurchill Khangar return; 337275129cebSChurchill Khangar } 337375129cebSChurchill Khangar 337475129cebSChurchill Khangar if ((n_tokens >= 5) && 337575129cebSChurchill Khangar (strcmp(tokens[2], "table") == 0) && 337675129cebSChurchill Khangar (strcmp(tokens[4], "delete") == 0)) { 337775129cebSChurchill Khangar cmd_pipeline_table_delete(tokens, n_tokens, out, 337875129cebSChurchill Khangar out_size, obj); 337975129cebSChurchill Khangar return; 338075129cebSChurchill Khangar } 338175129cebSChurchill Khangar 338275129cebSChurchill Khangar if ((n_tokens >= 5) && 338375129cebSChurchill Khangar (strcmp(tokens[2], "table") == 0) && 338475129cebSChurchill Khangar (strcmp(tokens[4], "default") == 0)) { 338575129cebSChurchill Khangar cmd_pipeline_table_default(tokens, n_tokens, out, 338675129cebSChurchill Khangar out_size, obj); 338775129cebSChurchill Khangar return; 338875129cebSChurchill Khangar } 338975129cebSChurchill Khangar 339075129cebSChurchill Khangar if ((n_tokens >= 5) && 339175129cebSChurchill Khangar (strcmp(tokens[2], "table") == 0) && 339275129cebSChurchill Khangar (strcmp(tokens[4], "show") == 0)) { 339375129cebSChurchill Khangar cmd_pipeline_table_show(tokens, n_tokens, out, 339475129cebSChurchill Khangar out_size, obj); 339575129cebSChurchill Khangar return; 339675129cebSChurchill Khangar } 339775129cebSChurchill Khangar 3398598fe0ddSCristian Dumitrescu if ((n_tokens >= 6) && 3399598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "selector") == 0) && 3400598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "group") == 0) && 3401598fe0ddSCristian Dumitrescu (strcmp(tokens[5], "add") == 0)) { 3402598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_add(tokens, n_tokens, out, 3403598fe0ddSCristian Dumitrescu out_size, obj); 3404598fe0ddSCristian Dumitrescu return; 3405598fe0ddSCristian Dumitrescu } 3406598fe0ddSCristian Dumitrescu 3407598fe0ddSCristian Dumitrescu if ((n_tokens >= 6) && 3408598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "selector") == 0) && 3409598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "group") == 0) && 3410598fe0ddSCristian Dumitrescu (strcmp(tokens[5], "delete") == 0)) { 3411598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_delete(tokens, n_tokens, out, 3412598fe0ddSCristian Dumitrescu out_size, obj); 3413598fe0ddSCristian Dumitrescu return; 3414598fe0ddSCristian Dumitrescu } 3415598fe0ddSCristian Dumitrescu 3416598fe0ddSCristian Dumitrescu if ((n_tokens >= 7) && 3417598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "selector") == 0) && 3418598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "group") == 0) && 3419598fe0ddSCristian Dumitrescu (strcmp(tokens[5], "member") == 0) && 3420598fe0ddSCristian Dumitrescu (strcmp(tokens[6], "add") == 0)) { 3421598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_add(tokens, n_tokens, out, 3422598fe0ddSCristian Dumitrescu out_size, obj); 3423598fe0ddSCristian Dumitrescu return; 3424598fe0ddSCristian Dumitrescu } 3425598fe0ddSCristian Dumitrescu 3426598fe0ddSCristian Dumitrescu if ((n_tokens >= 7) && 3427598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "selector") == 0) && 3428598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "group") == 0) && 3429598fe0ddSCristian Dumitrescu (strcmp(tokens[5], "member") == 0) && 3430598fe0ddSCristian Dumitrescu (strcmp(tokens[6], "delete") == 0)) { 3431598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_delete(tokens, n_tokens, out, 3432598fe0ddSCristian Dumitrescu out_size, obj); 3433598fe0ddSCristian Dumitrescu return; 3434598fe0ddSCristian Dumitrescu } 3435598fe0ddSCristian Dumitrescu 3436598fe0ddSCristian Dumitrescu if ((n_tokens >= 5) && 3437598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "selector") == 0) && 3438598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "show") == 0)) { 3439598fe0ddSCristian Dumitrescu cmd_pipeline_selector_show(tokens, n_tokens, out, 3440598fe0ddSCristian Dumitrescu out_size, obj); 3441598fe0ddSCristian Dumitrescu return; 3442598fe0ddSCristian Dumitrescu } 3443598fe0ddSCristian Dumitrescu 34448bd4862fSCristian Dumitrescu if ((n_tokens >= 5) && 34458bd4862fSCristian Dumitrescu (strcmp(tokens[2], "learner") == 0) && 34468bd4862fSCristian Dumitrescu (strcmp(tokens[4], "default") == 0)) { 34478bd4862fSCristian Dumitrescu cmd_pipeline_learner_default(tokens, n_tokens, out, 34488bd4862fSCristian Dumitrescu out_size, obj); 34498bd4862fSCristian Dumitrescu return; 34508bd4862fSCristian Dumitrescu } 34518bd4862fSCristian Dumitrescu 34525074e1d5SCristian Dumitrescu if ((n_tokens >= 3) && 345375129cebSChurchill Khangar (strcmp(tokens[2], "commit") == 0)) { 345475129cebSChurchill Khangar cmd_pipeline_commit(tokens, n_tokens, out, 345575129cebSChurchill Khangar out_size, obj); 345675129cebSChurchill Khangar return; 345775129cebSChurchill Khangar } 345875129cebSChurchill Khangar 345975129cebSChurchill Khangar if ((n_tokens >= 3) && 346075129cebSChurchill Khangar (strcmp(tokens[2], "abort") == 0)) { 346175129cebSChurchill Khangar cmd_pipeline_abort(tokens, n_tokens, out, 34625074e1d5SCristian Dumitrescu out_size, obj); 34635074e1d5SCristian Dumitrescu return; 34645074e1d5SCristian Dumitrescu } 34655074e1d5SCristian Dumitrescu 34665074e1d5SCristian Dumitrescu if ((n_tokens >= 3) && 346764cfcebdSCristian Dumitrescu (strcmp(tokens[2], "regrd") == 0)) { 346864cfcebdSCristian Dumitrescu cmd_pipeline_regrd(tokens, n_tokens, out, out_size, obj); 346964cfcebdSCristian Dumitrescu return; 347064cfcebdSCristian Dumitrescu } 347164cfcebdSCristian Dumitrescu 347264cfcebdSCristian Dumitrescu if ((n_tokens >= 3) && 347364cfcebdSCristian Dumitrescu (strcmp(tokens[2], "regwr") == 0)) { 347464cfcebdSCristian Dumitrescu cmd_pipeline_regwr(tokens, n_tokens, out, out_size, obj); 347564cfcebdSCristian Dumitrescu return; 347664cfcebdSCristian Dumitrescu } 347764cfcebdSCristian Dumitrescu 3478f38913b7SCristian Dumitrescu if ((n_tokens >= 6) && 3479f38913b7SCristian Dumitrescu (strcmp(tokens[2], "meter") == 0) && 3480f38913b7SCristian Dumitrescu (strcmp(tokens[3], "profile") == 0) && 3481f38913b7SCristian Dumitrescu (strcmp(tokens[5], "add") == 0)) { 3482f38913b7SCristian Dumitrescu cmd_pipeline_meter_profile_add(tokens, n_tokens, out, out_size, obj); 3483f38913b7SCristian Dumitrescu return; 3484f38913b7SCristian Dumitrescu } 3485f38913b7SCristian Dumitrescu 3486f38913b7SCristian Dumitrescu if ((n_tokens >= 6) && 3487f38913b7SCristian Dumitrescu (strcmp(tokens[2], "meter") == 0) && 3488f38913b7SCristian Dumitrescu (strcmp(tokens[3], "profile") == 0) && 3489f38913b7SCristian Dumitrescu (strcmp(tokens[5], "delete") == 0)) { 3490f38913b7SCristian Dumitrescu cmd_pipeline_meter_profile_delete(tokens, n_tokens, out, out_size, obj); 3491f38913b7SCristian Dumitrescu return; 3492f38913b7SCristian Dumitrescu } 3493f38913b7SCristian Dumitrescu 3494f38913b7SCristian Dumitrescu if ((n_tokens >= 9) && 3495f38913b7SCristian Dumitrescu (strcmp(tokens[2], "meter") == 0) && 3496f38913b7SCristian Dumitrescu (strcmp(tokens[8], "reset") == 0)) { 3497f38913b7SCristian Dumitrescu cmd_pipeline_meter_reset(tokens, n_tokens, out, out_size, obj); 3498f38913b7SCristian Dumitrescu return; 3499f38913b7SCristian Dumitrescu } 3500f38913b7SCristian Dumitrescu 3501f38913b7SCristian Dumitrescu if ((n_tokens >= 9) && 3502f38913b7SCristian Dumitrescu (strcmp(tokens[2], "meter") == 0) && 3503f38913b7SCristian Dumitrescu (strcmp(tokens[8], "set") == 0)) { 3504f38913b7SCristian Dumitrescu cmd_pipeline_meter_set(tokens, n_tokens, out, out_size, obj); 3505f38913b7SCristian Dumitrescu return; 3506f38913b7SCristian Dumitrescu } 3507f38913b7SCristian Dumitrescu 3508f38913b7SCristian Dumitrescu if ((n_tokens >= 9) && 3509f38913b7SCristian Dumitrescu (strcmp(tokens[2], "meter") == 0) && 3510f38913b7SCristian Dumitrescu (strcmp(tokens[8], "stats") == 0)) { 3511f38913b7SCristian Dumitrescu cmd_pipeline_meter_stats(tokens, n_tokens, out, out_size, obj); 3512f38913b7SCristian Dumitrescu return; 3513f38913b7SCristian Dumitrescu } 3514f38913b7SCristian Dumitrescu 351564cfcebdSCristian Dumitrescu if ((n_tokens >= 3) && 35165074e1d5SCristian Dumitrescu (strcmp(tokens[2], "stats") == 0)) { 35175074e1d5SCristian Dumitrescu cmd_pipeline_stats(tokens, n_tokens, out, out_size, 35185074e1d5SCristian Dumitrescu obj); 35195074e1d5SCristian Dumitrescu return; 35205074e1d5SCristian Dumitrescu } 352117225455SCristian Dumitrescu 352217225455SCristian Dumitrescu if ((n_tokens >= 4) && 352317225455SCristian Dumitrescu (strcmp(tokens[2], "mirror") == 0) && 352417225455SCristian Dumitrescu (strcmp(tokens[3], "slots") == 0)) { 352517225455SCristian Dumitrescu cmd_pipeline_mirror(tokens, n_tokens, out, out_size, obj); 352617225455SCristian Dumitrescu return; 352717225455SCristian Dumitrescu } 352817225455SCristian Dumitrescu 352917225455SCristian Dumitrescu if ((n_tokens >= 4) && 353017225455SCristian Dumitrescu (strcmp(tokens[2], "mirror") == 0) && 353117225455SCristian Dumitrescu (strcmp(tokens[3], "session") == 0)) { 353217225455SCristian Dumitrescu cmd_pipeline_mirror_session(tokens, n_tokens, out, out_size, obj); 353317225455SCristian Dumitrescu return; 353417225455SCristian Dumitrescu } 35355074e1d5SCristian Dumitrescu } 35365074e1d5SCristian Dumitrescu 35375074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "thread") == 0) { 35385074e1d5SCristian Dumitrescu if ((n_tokens >= 5) && 35395074e1d5SCristian Dumitrescu (strcmp(tokens[4], "enable") == 0)) { 35405074e1d5SCristian Dumitrescu cmd_thread_pipeline_enable(tokens, n_tokens, 35415074e1d5SCristian Dumitrescu out, out_size, obj); 35425074e1d5SCristian Dumitrescu return; 35435074e1d5SCristian Dumitrescu } 35445074e1d5SCristian Dumitrescu 35455074e1d5SCristian Dumitrescu if ((n_tokens >= 5) && 35465074e1d5SCristian Dumitrescu (strcmp(tokens[4], "disable") == 0)) { 35475074e1d5SCristian Dumitrescu cmd_thread_pipeline_disable(tokens, n_tokens, 35485074e1d5SCristian Dumitrescu out, out_size, obj); 35495074e1d5SCristian Dumitrescu return; 35505074e1d5SCristian Dumitrescu } 35515074e1d5SCristian Dumitrescu } 35525074e1d5SCristian Dumitrescu 35535074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]); 35545074e1d5SCristian Dumitrescu } 35555074e1d5SCristian Dumitrescu 35565074e1d5SCristian Dumitrescu int 35575074e1d5SCristian Dumitrescu cli_script_process(const char *file_name, 35585074e1d5SCristian Dumitrescu size_t msg_in_len_max, 35595074e1d5SCristian Dumitrescu size_t msg_out_len_max, 35605074e1d5SCristian Dumitrescu void *obj) 35615074e1d5SCristian Dumitrescu { 35625074e1d5SCristian Dumitrescu char *msg_in = NULL, *msg_out = NULL; 35635074e1d5SCristian Dumitrescu FILE *f = NULL; 35645074e1d5SCristian Dumitrescu 35655074e1d5SCristian Dumitrescu /* Check input arguments */ 35665074e1d5SCristian Dumitrescu if ((file_name == NULL) || 35675074e1d5SCristian Dumitrescu (strlen(file_name) == 0) || 35685074e1d5SCristian Dumitrescu (msg_in_len_max == 0) || 35695074e1d5SCristian Dumitrescu (msg_out_len_max == 0)) 35705074e1d5SCristian Dumitrescu return -EINVAL; 35715074e1d5SCristian Dumitrescu 35725074e1d5SCristian Dumitrescu msg_in = malloc(msg_in_len_max + 1); 35735074e1d5SCristian Dumitrescu msg_out = malloc(msg_out_len_max + 1); 35745074e1d5SCristian Dumitrescu if ((msg_in == NULL) || 35755074e1d5SCristian Dumitrescu (msg_out == NULL)) { 35765074e1d5SCristian Dumitrescu free(msg_out); 35775074e1d5SCristian Dumitrescu free(msg_in); 35785074e1d5SCristian Dumitrescu return -ENOMEM; 35795074e1d5SCristian Dumitrescu } 35805074e1d5SCristian Dumitrescu 35815074e1d5SCristian Dumitrescu /* Open input file */ 35825074e1d5SCristian Dumitrescu f = fopen(file_name, "r"); 35835074e1d5SCristian Dumitrescu if (f == NULL) { 35845074e1d5SCristian Dumitrescu free(msg_out); 35855074e1d5SCristian Dumitrescu free(msg_in); 35865074e1d5SCristian Dumitrescu return -EIO; 35875074e1d5SCristian Dumitrescu } 35885074e1d5SCristian Dumitrescu 35895074e1d5SCristian Dumitrescu /* Read file */ 35905074e1d5SCristian Dumitrescu for ( ; ; ) { 35915074e1d5SCristian Dumitrescu if (fgets(msg_in, msg_in_len_max + 1, f) == NULL) 35925074e1d5SCristian Dumitrescu break; 35935074e1d5SCristian Dumitrescu 35945074e1d5SCristian Dumitrescu printf("%s", msg_in); 35955074e1d5SCristian Dumitrescu msg_out[0] = 0; 35965074e1d5SCristian Dumitrescu 35975074e1d5SCristian Dumitrescu cli_process(msg_in, 35985074e1d5SCristian Dumitrescu msg_out, 35995074e1d5SCristian Dumitrescu msg_out_len_max, 36005074e1d5SCristian Dumitrescu obj); 36015074e1d5SCristian Dumitrescu 36025074e1d5SCristian Dumitrescu if (strlen(msg_out)) 36035074e1d5SCristian Dumitrescu printf("%s", msg_out); 36045074e1d5SCristian Dumitrescu } 36055074e1d5SCristian Dumitrescu 36065074e1d5SCristian Dumitrescu /* Close file */ 36075074e1d5SCristian Dumitrescu fclose(f); 36085074e1d5SCristian Dumitrescu free(msg_out); 36095074e1d5SCristian Dumitrescu free(msg_in); 36105074e1d5SCristian Dumitrescu return 0; 36115074e1d5SCristian Dumitrescu } 3612