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" 3795074e1d5SCristian Dumitrescu "\tether %02X:%02X:%02X:%02X:%02X:%02X 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, 3885074e1d5SCristian Dumitrescu mac_addr.addr_bytes[0], mac_addr.addr_bytes[1], 3895074e1d5SCristian Dumitrescu mac_addr.addr_bytes[2], mac_addr.addr_bytes[3], 3905074e1d5SCristian Dumitrescu mac_addr.addr_bytes[4], mac_addr.addr_bytes[5], 3915074e1d5SCristian Dumitrescu link->n_rxq, 3925074e1d5SCristian Dumitrescu link->n_txq, 3935074e1d5SCristian Dumitrescu link->port_id, 3945074e1d5SCristian Dumitrescu rte_eth_link_speed_to_str(eth_link.link_speed), 3955074e1d5SCristian Dumitrescu stats.ipackets, 3965074e1d5SCristian Dumitrescu stats.ibytes, 3975074e1d5SCristian Dumitrescu stats.ierrors, 3985074e1d5SCristian Dumitrescu stats.imissed, 3995074e1d5SCristian Dumitrescu stats.rx_nombuf, 4005074e1d5SCristian Dumitrescu stats.opackets, 4015074e1d5SCristian Dumitrescu stats.obytes, 4025074e1d5SCristian Dumitrescu stats.oerrors); 4035074e1d5SCristian Dumitrescu } 4045074e1d5SCristian Dumitrescu 4055074e1d5SCristian Dumitrescu /* 4065074e1d5SCristian Dumitrescu * link show [<link_name>] 4075074e1d5SCristian Dumitrescu */ 4085074e1d5SCristian Dumitrescu static void 4095074e1d5SCristian Dumitrescu cmd_link_show(char **tokens, 4105074e1d5SCristian Dumitrescu uint32_t n_tokens, 4115074e1d5SCristian Dumitrescu char *out, 4125074e1d5SCristian Dumitrescu size_t out_size, 4135074e1d5SCristian Dumitrescu void *obj) 4145074e1d5SCristian Dumitrescu { 4155074e1d5SCristian Dumitrescu struct link *link; 4165074e1d5SCristian Dumitrescu char *link_name; 4175074e1d5SCristian Dumitrescu 4185074e1d5SCristian Dumitrescu if (n_tokens != 2 && n_tokens != 3) { 4195074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 4205074e1d5SCristian Dumitrescu return; 4215074e1d5SCristian Dumitrescu } 4225074e1d5SCristian Dumitrescu 4235074e1d5SCristian Dumitrescu if (n_tokens == 2) { 4245074e1d5SCristian Dumitrescu link = link_next(obj, NULL); 4255074e1d5SCristian Dumitrescu 4265074e1d5SCristian Dumitrescu while (link != NULL) { 4275074e1d5SCristian Dumitrescu out_size = out_size - strlen(out); 4285074e1d5SCristian Dumitrescu out = &out[strlen(out)]; 4295074e1d5SCristian Dumitrescu 4305074e1d5SCristian Dumitrescu print_link_info(link, out, out_size); 4315074e1d5SCristian Dumitrescu link = link_next(obj, link); 4325074e1d5SCristian Dumitrescu } 4335074e1d5SCristian Dumitrescu } else { 4345074e1d5SCristian Dumitrescu out_size = out_size - strlen(out); 4355074e1d5SCristian Dumitrescu out = &out[strlen(out)]; 4365074e1d5SCristian Dumitrescu 4375074e1d5SCristian Dumitrescu link_name = tokens[2]; 4385074e1d5SCristian Dumitrescu link = link_find(obj, link_name); 4395074e1d5SCristian Dumitrescu 4405074e1d5SCristian Dumitrescu if (link == NULL) { 4415074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, 4425074e1d5SCristian Dumitrescu "Link does not exist"); 4435074e1d5SCristian Dumitrescu return; 4445074e1d5SCristian Dumitrescu } 4455074e1d5SCristian Dumitrescu print_link_info(link, out, out_size); 4465074e1d5SCristian Dumitrescu } 4475074e1d5SCristian Dumitrescu } 4485074e1d5SCristian Dumitrescu 44977a41301SCristian Dumitrescu static const char cmd_ring_help[] = 45077a41301SCristian Dumitrescu "ring <ring_name> size <size> numa <numa_node>\n"; 45177a41301SCristian Dumitrescu 45277a41301SCristian Dumitrescu static void 45377a41301SCristian Dumitrescu cmd_ring(char **tokens, 45477a41301SCristian Dumitrescu uint32_t n_tokens, 45577a41301SCristian Dumitrescu char *out, 45677a41301SCristian Dumitrescu size_t out_size, 45777a41301SCristian Dumitrescu void *obj) 45877a41301SCristian Dumitrescu { 45977a41301SCristian Dumitrescu struct ring_params p; 46077a41301SCristian Dumitrescu char *name; 46177a41301SCristian Dumitrescu struct ring *ring; 46277a41301SCristian Dumitrescu 46377a41301SCristian Dumitrescu if (n_tokens != 6) { 46477a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 46577a41301SCristian Dumitrescu return; 46677a41301SCristian Dumitrescu } 46777a41301SCristian Dumitrescu 46877a41301SCristian Dumitrescu name = tokens[1]; 46977a41301SCristian Dumitrescu 47077a41301SCristian Dumitrescu if (strcmp(tokens[2], "size") != 0) { 47177a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size"); 47277a41301SCristian Dumitrescu return; 47377a41301SCristian Dumitrescu } 47477a41301SCristian Dumitrescu 47577a41301SCristian Dumitrescu if (parser_read_uint32(&p.size, tokens[3]) != 0) { 47677a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "size"); 47777a41301SCristian Dumitrescu return; 47877a41301SCristian Dumitrescu } 47977a41301SCristian Dumitrescu 48077a41301SCristian Dumitrescu if (strcmp(tokens[4], "numa") != 0) { 48177a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "numa"); 48277a41301SCristian Dumitrescu return; 48377a41301SCristian Dumitrescu } 48477a41301SCristian Dumitrescu 48577a41301SCristian Dumitrescu if (parser_read_uint32(&p.numa_node, tokens[5]) != 0) { 48677a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "numa_node"); 48777a41301SCristian Dumitrescu return; 48877a41301SCristian Dumitrescu } 48977a41301SCristian Dumitrescu 49077a41301SCristian Dumitrescu ring = ring_create(obj, name, &p); 49177a41301SCristian Dumitrescu if (!ring) { 49277a41301SCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]); 49377a41301SCristian Dumitrescu return; 49477a41301SCristian Dumitrescu } 49577a41301SCristian Dumitrescu } 49677a41301SCristian Dumitrescu 497e2b8dc52SVenkata Suresh Kumar P static const char cmd_tap_help[] = 498e2b8dc52SVenkata Suresh Kumar P "tap <tap_name>\n"; 499e2b8dc52SVenkata Suresh Kumar P 500e2b8dc52SVenkata Suresh Kumar P static void 501e2b8dc52SVenkata Suresh Kumar P cmd_tap(char **tokens, 502e2b8dc52SVenkata Suresh Kumar P uint32_t n_tokens, 503e2b8dc52SVenkata Suresh Kumar P char *out, 504e2b8dc52SVenkata Suresh Kumar P size_t out_size, 505e2b8dc52SVenkata Suresh Kumar P void *obj) 506e2b8dc52SVenkata Suresh Kumar P { 507e2b8dc52SVenkata Suresh Kumar P struct tap *tap; 508e2b8dc52SVenkata Suresh Kumar P char *name; 509e2b8dc52SVenkata Suresh Kumar P 510e2b8dc52SVenkata Suresh Kumar P if (n_tokens < 2) { 511e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 512e2b8dc52SVenkata Suresh Kumar P return; 513e2b8dc52SVenkata Suresh Kumar P } 514e2b8dc52SVenkata Suresh Kumar P name = tokens[1]; 515e2b8dc52SVenkata Suresh Kumar P 516e2b8dc52SVenkata Suresh Kumar P tap = tap_create(obj, name); 517e2b8dc52SVenkata Suresh Kumar P if (tap == NULL) { 518e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]); 519e2b8dc52SVenkata Suresh Kumar P return; 520e2b8dc52SVenkata Suresh Kumar P } 521e2b8dc52SVenkata Suresh Kumar P } 522e2b8dc52SVenkata Suresh Kumar P 5235074e1d5SCristian Dumitrescu static const char cmd_pipeline_create_help[] = 5245074e1d5SCristian Dumitrescu "pipeline <pipeline_name> create <numa_node>\n"; 5255074e1d5SCristian Dumitrescu 5265074e1d5SCristian Dumitrescu static void 5275074e1d5SCristian Dumitrescu cmd_pipeline_create(char **tokens, 5285074e1d5SCristian Dumitrescu uint32_t n_tokens, 5295074e1d5SCristian Dumitrescu char *out, 5305074e1d5SCristian Dumitrescu size_t out_size, 5315074e1d5SCristian Dumitrescu void *obj) 5325074e1d5SCristian Dumitrescu { 5335074e1d5SCristian Dumitrescu struct pipeline *p; 5345074e1d5SCristian Dumitrescu char *name; 5355074e1d5SCristian Dumitrescu uint32_t numa_node; 5365074e1d5SCristian Dumitrescu 5375074e1d5SCristian Dumitrescu if (n_tokens != 4) { 5385074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 5395074e1d5SCristian Dumitrescu return; 5405074e1d5SCristian Dumitrescu } 5415074e1d5SCristian Dumitrescu 5425074e1d5SCristian Dumitrescu name = tokens[1]; 5435074e1d5SCristian Dumitrescu 5445074e1d5SCristian Dumitrescu if (parser_read_uint32(&numa_node, tokens[3]) != 0) { 5455074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "numa_node"); 5465074e1d5SCristian Dumitrescu return; 5475074e1d5SCristian Dumitrescu } 5485074e1d5SCristian Dumitrescu 5495074e1d5SCristian Dumitrescu p = pipeline_create(obj, name, (int)numa_node); 5505074e1d5SCristian Dumitrescu if (!p) { 5515074e1d5SCristian Dumitrescu snprintf(out, out_size, "pipeline create error."); 5525074e1d5SCristian Dumitrescu return; 5535074e1d5SCristian Dumitrescu } 5545074e1d5SCristian Dumitrescu } 5555074e1d5SCristian Dumitrescu 5565074e1d5SCristian Dumitrescu static const char cmd_pipeline_port_in_help[] = 5575074e1d5SCristian Dumitrescu "pipeline <pipeline_name> port in <port_id>\n" 5585074e1d5SCristian Dumitrescu " link <link_name> rxq <queue_id> bsz <burst_size>\n" 55977a41301SCristian Dumitrescu " ring <ring_name> bsz <burst_size>\n" 560e2b8dc52SVenkata Suresh Kumar P " | source <mempool_name> <file_name>\n" 561e2b8dc52SVenkata Suresh Kumar P " | tap <tap_name> mempool <mempool_name> mtu <mtu> bsz <burst_size>\n"; 5625074e1d5SCristian Dumitrescu 5635074e1d5SCristian Dumitrescu static void 5645074e1d5SCristian Dumitrescu cmd_pipeline_port_in(char **tokens, 5655074e1d5SCristian Dumitrescu uint32_t n_tokens, 5665074e1d5SCristian Dumitrescu char *out, 5675074e1d5SCristian Dumitrescu size_t out_size, 5685074e1d5SCristian Dumitrescu void *obj) 5695074e1d5SCristian Dumitrescu { 5705074e1d5SCristian Dumitrescu struct pipeline *p; 5715074e1d5SCristian Dumitrescu int status; 5725074e1d5SCristian Dumitrescu uint32_t port_id = 0, t0; 5735074e1d5SCristian Dumitrescu 5745074e1d5SCristian Dumitrescu if (n_tokens < 6) { 5755074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 5765074e1d5SCristian Dumitrescu return; 5775074e1d5SCristian Dumitrescu } 5785074e1d5SCristian Dumitrescu 5795074e1d5SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 5805074e1d5SCristian Dumitrescu if (!p || p->ctl) { 5815074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]); 5825074e1d5SCristian Dumitrescu return; 5835074e1d5SCristian Dumitrescu } 5845074e1d5SCristian Dumitrescu 5855074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "port") != 0) { 5865074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port"); 5875074e1d5SCristian Dumitrescu return; 5885074e1d5SCristian Dumitrescu } 5895074e1d5SCristian Dumitrescu 5905074e1d5SCristian Dumitrescu if (strcmp(tokens[3], "in") != 0) { 5915074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in"); 5925074e1d5SCristian Dumitrescu return; 5935074e1d5SCristian Dumitrescu } 5945074e1d5SCristian Dumitrescu 5955074e1d5SCristian Dumitrescu if (parser_read_uint32(&port_id, tokens[4]) != 0) { 5965074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "port_id"); 5975074e1d5SCristian Dumitrescu return; 5985074e1d5SCristian Dumitrescu } 5995074e1d5SCristian Dumitrescu 6005074e1d5SCristian Dumitrescu t0 = 5; 6015074e1d5SCristian Dumitrescu 6025074e1d5SCristian Dumitrescu if (strcmp(tokens[t0], "link") == 0) { 6035074e1d5SCristian Dumitrescu struct rte_swx_port_ethdev_reader_params params; 6045074e1d5SCristian Dumitrescu struct link *link; 6055074e1d5SCristian Dumitrescu 6065074e1d5SCristian Dumitrescu if (n_tokens < t0 + 6) { 6075074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, 6085074e1d5SCristian Dumitrescu "pipeline port in link"); 6095074e1d5SCristian Dumitrescu return; 6105074e1d5SCristian Dumitrescu } 6115074e1d5SCristian Dumitrescu 6125074e1d5SCristian Dumitrescu link = link_find(obj, tokens[t0 + 1]); 6135074e1d5SCristian Dumitrescu if (!link) { 6145074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, 6155074e1d5SCristian Dumitrescu "link_name"); 6165074e1d5SCristian Dumitrescu return; 6175074e1d5SCristian Dumitrescu } 6185074e1d5SCristian Dumitrescu params.dev_name = link->dev_name; 6195074e1d5SCristian Dumitrescu 6205074e1d5SCristian Dumitrescu if (strcmp(tokens[t0 + 2], "rxq") != 0) { 6215074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq"); 6225074e1d5SCristian Dumitrescu return; 6235074e1d5SCristian Dumitrescu } 6245074e1d5SCristian Dumitrescu 6255074e1d5SCristian Dumitrescu if (parser_read_uint16(¶ms.queue_id, tokens[t0 + 3]) != 0) { 6265074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, 6275074e1d5SCristian Dumitrescu "queue_id"); 6285074e1d5SCristian Dumitrescu return; 6295074e1d5SCristian Dumitrescu } 6305074e1d5SCristian Dumitrescu 6315074e1d5SCristian Dumitrescu if (strcmp(tokens[t0 + 4], "bsz") != 0) { 6325074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz"); 6335074e1d5SCristian Dumitrescu return; 6345074e1d5SCristian Dumitrescu } 6355074e1d5SCristian Dumitrescu 6365074e1d5SCristian Dumitrescu if (parser_read_uint32(¶ms.burst_size, tokens[t0 + 5])) { 6375074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, 6385074e1d5SCristian Dumitrescu "burst_size"); 6395074e1d5SCristian Dumitrescu return; 6405074e1d5SCristian Dumitrescu } 6415074e1d5SCristian Dumitrescu 6425074e1d5SCristian Dumitrescu t0 += 6; 6435074e1d5SCristian Dumitrescu 6445074e1d5SCristian Dumitrescu status = rte_swx_pipeline_port_in_config(p->p, 6455074e1d5SCristian Dumitrescu port_id, 6465074e1d5SCristian Dumitrescu "ethdev", 6475074e1d5SCristian Dumitrescu ¶ms); 64877a41301SCristian Dumitrescu } else if (strcmp(tokens[t0], "ring") == 0) { 64977a41301SCristian Dumitrescu struct rte_swx_port_ring_reader_params params; 65077a41301SCristian Dumitrescu struct ring *ring; 65177a41301SCristian Dumitrescu 65277a41301SCristian Dumitrescu if (n_tokens < t0 + 4) { 65377a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, 65477a41301SCristian Dumitrescu "pipeline port in ring"); 65577a41301SCristian Dumitrescu return; 65677a41301SCristian Dumitrescu } 65777a41301SCristian Dumitrescu 65877a41301SCristian Dumitrescu ring = ring_find(obj, tokens[t0 + 1]); 65977a41301SCristian Dumitrescu if (!ring) { 66077a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, 66177a41301SCristian Dumitrescu "ring_name"); 66277a41301SCristian Dumitrescu return; 66377a41301SCristian Dumitrescu } 66477a41301SCristian Dumitrescu params.name = ring->name; 66577a41301SCristian Dumitrescu 66677a41301SCristian Dumitrescu if (strcmp(tokens[t0 + 2], "bsz") != 0) { 66777a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz"); 66877a41301SCristian Dumitrescu return; 66977a41301SCristian Dumitrescu } 67077a41301SCristian Dumitrescu 67177a41301SCristian Dumitrescu if (parser_read_uint32(¶ms.burst_size, tokens[t0 + 3])) { 67277a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, 67377a41301SCristian Dumitrescu "burst_size"); 67477a41301SCristian Dumitrescu return; 67577a41301SCristian Dumitrescu } 67677a41301SCristian Dumitrescu 67777a41301SCristian Dumitrescu t0 += 4; 67877a41301SCristian Dumitrescu 67977a41301SCristian Dumitrescu status = rte_swx_pipeline_port_in_config(p->p, 68077a41301SCristian Dumitrescu port_id, 68177a41301SCristian Dumitrescu "ring", 68277a41301SCristian Dumitrescu ¶ms); 6835074e1d5SCristian Dumitrescu } else if (strcmp(tokens[t0], "source") == 0) { 6845074e1d5SCristian Dumitrescu struct rte_swx_port_source_params params; 6855074e1d5SCristian Dumitrescu struct mempool *mp; 6865074e1d5SCristian Dumitrescu 6875074e1d5SCristian Dumitrescu if (n_tokens < t0 + 3) { 6885074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, 6895074e1d5SCristian Dumitrescu "pipeline port in source"); 6905074e1d5SCristian Dumitrescu return; 6915074e1d5SCristian Dumitrescu } 6925074e1d5SCristian Dumitrescu 6935074e1d5SCristian Dumitrescu mp = mempool_find(obj, tokens[t0 + 1]); 6945074e1d5SCristian Dumitrescu if (!mp) { 6955074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, 6965074e1d5SCristian Dumitrescu "mempool_name"); 6975074e1d5SCristian Dumitrescu return; 6985074e1d5SCristian Dumitrescu } 6995074e1d5SCristian Dumitrescu params.pool = mp->m; 7005074e1d5SCristian Dumitrescu 7015074e1d5SCristian Dumitrescu params.file_name = tokens[t0 + 2]; 7025074e1d5SCristian Dumitrescu 7035074e1d5SCristian Dumitrescu t0 += 3; 7045074e1d5SCristian Dumitrescu 7055074e1d5SCristian Dumitrescu status = rte_swx_pipeline_port_in_config(p->p, 7065074e1d5SCristian Dumitrescu port_id, 7075074e1d5SCristian Dumitrescu "source", 7085074e1d5SCristian Dumitrescu ¶ms); 709e2b8dc52SVenkata Suresh Kumar P } else if (strcmp(tokens[t0], "tap") == 0) { 710e2b8dc52SVenkata Suresh Kumar P struct rte_swx_port_fd_reader_params params; 711e2b8dc52SVenkata Suresh Kumar P struct tap *tap; 712e2b8dc52SVenkata Suresh Kumar P struct mempool *mp; 713e2b8dc52SVenkata Suresh Kumar P 714e2b8dc52SVenkata Suresh Kumar P if (n_tokens < t0 + 8) { 715e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_ARG_MISMATCH, 716e2b8dc52SVenkata Suresh Kumar P "pipeline port in tap"); 717e2b8dc52SVenkata Suresh Kumar P return; 718e2b8dc52SVenkata Suresh Kumar P } 719e2b8dc52SVenkata Suresh Kumar P 720e2b8dc52SVenkata Suresh Kumar P tap = tap_find(obj, tokens[t0 + 1]); 721e2b8dc52SVenkata Suresh Kumar P if (!tap) { 722e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_ARG_INVALID, 723e2b8dc52SVenkata Suresh Kumar P "tap_name"); 724e2b8dc52SVenkata Suresh Kumar P return; 725e2b8dc52SVenkata Suresh Kumar P } 726e2b8dc52SVenkata Suresh Kumar P params.fd = tap->fd; 727e2b8dc52SVenkata Suresh Kumar P 728e2b8dc52SVenkata Suresh Kumar P if (strcmp(tokens[t0 + 2], "mempool") != 0) { 729e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_ARG_NOT_FOUND, 730e2b8dc52SVenkata Suresh Kumar P "mempool"); 731e2b8dc52SVenkata Suresh Kumar P return; 732e2b8dc52SVenkata Suresh Kumar P } 733e2b8dc52SVenkata Suresh Kumar P 734e2b8dc52SVenkata Suresh Kumar P mp = mempool_find(obj, tokens[t0 + 3]); 735e2b8dc52SVenkata Suresh Kumar P if (!mp) { 736e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_ARG_INVALID, 737e2b8dc52SVenkata Suresh Kumar P "mempool_name"); 738e2b8dc52SVenkata Suresh Kumar P return; 739e2b8dc52SVenkata Suresh Kumar P } 740e2b8dc52SVenkata Suresh Kumar P params.mempool = mp->m; 741e2b8dc52SVenkata Suresh Kumar P 742e2b8dc52SVenkata Suresh Kumar P if (strcmp(tokens[t0 + 4], "mtu") != 0) { 743e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_ARG_NOT_FOUND, 744e2b8dc52SVenkata Suresh Kumar P "mtu"); 745e2b8dc52SVenkata Suresh Kumar P return; 746e2b8dc52SVenkata Suresh Kumar P } 747e2b8dc52SVenkata Suresh Kumar P 748e2b8dc52SVenkata Suresh Kumar P if (parser_read_uint32(¶ms.mtu, tokens[t0 + 5]) != 0) { 749e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_ARG_INVALID, "mtu"); 750e2b8dc52SVenkata Suresh Kumar P return; 751e2b8dc52SVenkata Suresh Kumar P } 752e2b8dc52SVenkata Suresh Kumar P 753e2b8dc52SVenkata Suresh Kumar P if (strcmp(tokens[t0 + 6], "bsz") != 0) { 754e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz"); 755e2b8dc52SVenkata Suresh Kumar P return; 756e2b8dc52SVenkata Suresh Kumar P } 757e2b8dc52SVenkata Suresh Kumar P 758e2b8dc52SVenkata Suresh Kumar P if (parser_read_uint32(¶ms.burst_size, tokens[t0 + 7])) { 759e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_ARG_INVALID, 760e2b8dc52SVenkata Suresh Kumar P "burst_size"); 761e2b8dc52SVenkata Suresh Kumar P return; 762e2b8dc52SVenkata Suresh Kumar P } 763e2b8dc52SVenkata Suresh Kumar P 764e2b8dc52SVenkata Suresh Kumar P t0 += 8; 765e2b8dc52SVenkata Suresh Kumar P 766e2b8dc52SVenkata Suresh Kumar P status = rte_swx_pipeline_port_in_config(p->p, 767e2b8dc52SVenkata Suresh Kumar P port_id, 768e2b8dc52SVenkata Suresh Kumar P "fd", 769e2b8dc52SVenkata Suresh Kumar P ¶ms); 770e2b8dc52SVenkata Suresh Kumar P 7715074e1d5SCristian Dumitrescu } else { 7725074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]); 7735074e1d5SCristian Dumitrescu return; 7745074e1d5SCristian Dumitrescu } 7755074e1d5SCristian Dumitrescu 7765074e1d5SCristian Dumitrescu if (status) { 7775074e1d5SCristian Dumitrescu snprintf(out, out_size, "port in error."); 7785074e1d5SCristian Dumitrescu return; 7795074e1d5SCristian Dumitrescu } 7805074e1d5SCristian Dumitrescu 7815074e1d5SCristian Dumitrescu if (n_tokens != t0) { 7825074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 7835074e1d5SCristian Dumitrescu return; 7845074e1d5SCristian Dumitrescu } 7855074e1d5SCristian Dumitrescu } 7865074e1d5SCristian Dumitrescu 7875074e1d5SCristian Dumitrescu static const char cmd_pipeline_port_out_help[] = 7885074e1d5SCristian Dumitrescu "pipeline <pipeline_name> port out <port_id>\n" 7895074e1d5SCristian Dumitrescu " link <link_name> txq <txq_id> bsz <burst_size>\n" 79077a41301SCristian Dumitrescu " ring <ring_name> bsz <burst_size>\n" 791e2b8dc52SVenkata Suresh Kumar P " | sink <file_name> | none\n" 792e2b8dc52SVenkata Suresh Kumar P " | tap <tap_name> bsz <burst_size>\n"; 7935074e1d5SCristian Dumitrescu 7945074e1d5SCristian Dumitrescu static void 7955074e1d5SCristian Dumitrescu cmd_pipeline_port_out(char **tokens, 7965074e1d5SCristian Dumitrescu uint32_t n_tokens, 7975074e1d5SCristian Dumitrescu char *out, 7985074e1d5SCristian Dumitrescu size_t out_size, 7995074e1d5SCristian Dumitrescu void *obj) 8005074e1d5SCristian Dumitrescu { 8015074e1d5SCristian Dumitrescu struct pipeline *p; 8025074e1d5SCristian Dumitrescu int status; 8035074e1d5SCristian Dumitrescu uint32_t port_id = 0, t0; 8045074e1d5SCristian Dumitrescu 8055074e1d5SCristian Dumitrescu if (n_tokens < 6) { 8065074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 8075074e1d5SCristian Dumitrescu return; 8085074e1d5SCristian Dumitrescu } 8095074e1d5SCristian Dumitrescu 8105074e1d5SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 8115074e1d5SCristian Dumitrescu if (!p || p->ctl) { 8125074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]); 8135074e1d5SCristian Dumitrescu return; 8145074e1d5SCristian Dumitrescu } 8155074e1d5SCristian Dumitrescu 8165074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "port") != 0) { 8175074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port"); 8185074e1d5SCristian Dumitrescu return; 8195074e1d5SCristian Dumitrescu } 8205074e1d5SCristian Dumitrescu 8215074e1d5SCristian Dumitrescu if (strcmp(tokens[3], "out") != 0) { 8225074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out"); 8235074e1d5SCristian Dumitrescu return; 8245074e1d5SCristian Dumitrescu } 8255074e1d5SCristian Dumitrescu 8265074e1d5SCristian Dumitrescu if (parser_read_uint32(&port_id, tokens[4]) != 0) { 8275074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "port_id"); 8285074e1d5SCristian Dumitrescu return; 8295074e1d5SCristian Dumitrescu } 8305074e1d5SCristian Dumitrescu 8315074e1d5SCristian Dumitrescu t0 = 5; 8325074e1d5SCristian Dumitrescu 8335074e1d5SCristian Dumitrescu if (strcmp(tokens[t0], "link") == 0) { 8345074e1d5SCristian Dumitrescu struct rte_swx_port_ethdev_writer_params params; 8355074e1d5SCristian Dumitrescu struct link *link; 8365074e1d5SCristian Dumitrescu 8375074e1d5SCristian Dumitrescu if (n_tokens < t0 + 6) { 8385074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, 8395074e1d5SCristian Dumitrescu "pipeline port out link"); 8405074e1d5SCristian Dumitrescu return; 8415074e1d5SCristian Dumitrescu } 8425074e1d5SCristian Dumitrescu 8435074e1d5SCristian Dumitrescu link = link_find(obj, tokens[t0 + 1]); 8445074e1d5SCristian Dumitrescu if (!link) { 8455074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, 8465074e1d5SCristian Dumitrescu "link_name"); 8475074e1d5SCristian Dumitrescu return; 8485074e1d5SCristian Dumitrescu } 8495074e1d5SCristian Dumitrescu params.dev_name = link->dev_name; 8505074e1d5SCristian Dumitrescu 8515074e1d5SCristian Dumitrescu if (strcmp(tokens[t0 + 2], "txq") != 0) { 8525074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq"); 8535074e1d5SCristian Dumitrescu return; 8545074e1d5SCristian Dumitrescu } 8555074e1d5SCristian Dumitrescu 8565074e1d5SCristian Dumitrescu if (parser_read_uint16(¶ms.queue_id, tokens[t0 + 3]) != 0) { 8575074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, 8585074e1d5SCristian Dumitrescu "queue_id"); 8595074e1d5SCristian Dumitrescu return; 8605074e1d5SCristian Dumitrescu } 8615074e1d5SCristian Dumitrescu 8625074e1d5SCristian Dumitrescu if (strcmp(tokens[t0 + 4], "bsz") != 0) { 8635074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz"); 8645074e1d5SCristian Dumitrescu return; 8655074e1d5SCristian Dumitrescu } 8665074e1d5SCristian Dumitrescu 8675074e1d5SCristian Dumitrescu if (parser_read_uint32(¶ms.burst_size, tokens[t0 + 5])) { 8685074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, 8695074e1d5SCristian Dumitrescu "burst_size"); 8705074e1d5SCristian Dumitrescu return; 8715074e1d5SCristian Dumitrescu } 8725074e1d5SCristian Dumitrescu 8735074e1d5SCristian Dumitrescu t0 += 6; 8745074e1d5SCristian Dumitrescu 8755074e1d5SCristian Dumitrescu status = rte_swx_pipeline_port_out_config(p->p, 8765074e1d5SCristian Dumitrescu port_id, 8775074e1d5SCristian Dumitrescu "ethdev", 8785074e1d5SCristian Dumitrescu ¶ms); 87977a41301SCristian Dumitrescu } else if (strcmp(tokens[t0], "ring") == 0) { 88077a41301SCristian Dumitrescu struct rte_swx_port_ring_writer_params params; 88177a41301SCristian Dumitrescu struct ring *ring; 88277a41301SCristian Dumitrescu 88377a41301SCristian Dumitrescu if (n_tokens < t0 + 4) { 88477a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, 88577a41301SCristian Dumitrescu "pipeline port out link"); 88677a41301SCristian Dumitrescu return; 88777a41301SCristian Dumitrescu } 88877a41301SCristian Dumitrescu 88977a41301SCristian Dumitrescu ring = ring_find(obj, tokens[t0 + 1]); 89077a41301SCristian Dumitrescu if (!ring) { 89177a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, 89277a41301SCristian Dumitrescu "ring_name"); 89377a41301SCristian Dumitrescu return; 89477a41301SCristian Dumitrescu } 89577a41301SCristian Dumitrescu params.name = ring->name; 89677a41301SCristian Dumitrescu 89777a41301SCristian Dumitrescu if (strcmp(tokens[t0 + 2], "bsz") != 0) { 89877a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz"); 89977a41301SCristian Dumitrescu return; 90077a41301SCristian Dumitrescu } 90177a41301SCristian Dumitrescu 90277a41301SCristian Dumitrescu if (parser_read_uint32(¶ms.burst_size, tokens[t0 + 3])) { 90377a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, 90477a41301SCristian Dumitrescu "burst_size"); 90577a41301SCristian Dumitrescu return; 90677a41301SCristian Dumitrescu } 90777a41301SCristian Dumitrescu 90877a41301SCristian Dumitrescu t0 += 4; 90977a41301SCristian Dumitrescu 91077a41301SCristian Dumitrescu status = rte_swx_pipeline_port_out_config(p->p, 91177a41301SCristian Dumitrescu port_id, 91277a41301SCristian Dumitrescu "ring", 91377a41301SCristian Dumitrescu ¶ms); 9145074e1d5SCristian Dumitrescu } else if (strcmp(tokens[t0], "sink") == 0) { 9155074e1d5SCristian Dumitrescu struct rte_swx_port_sink_params params; 9165074e1d5SCristian Dumitrescu 9175074e1d5SCristian Dumitrescu params.file_name = strcmp(tokens[t0 + 1], "none") ? 9185074e1d5SCristian Dumitrescu tokens[t0 + 1] : NULL; 9195074e1d5SCristian Dumitrescu 9205074e1d5SCristian Dumitrescu t0 += 2; 9215074e1d5SCristian Dumitrescu 9225074e1d5SCristian Dumitrescu status = rte_swx_pipeline_port_out_config(p->p, 9235074e1d5SCristian Dumitrescu port_id, 9245074e1d5SCristian Dumitrescu "sink", 9255074e1d5SCristian Dumitrescu ¶ms); 926e2b8dc52SVenkata Suresh Kumar P } else if (strcmp(tokens[t0], "tap") == 0) { 927e2b8dc52SVenkata Suresh Kumar P struct rte_swx_port_fd_writer_params params; 928e2b8dc52SVenkata Suresh Kumar P struct tap *tap; 929e2b8dc52SVenkata Suresh Kumar P 930e2b8dc52SVenkata Suresh Kumar P if (n_tokens < t0 + 4) { 931e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_ARG_MISMATCH, 932e2b8dc52SVenkata Suresh Kumar P "pipeline port out tap"); 933e2b8dc52SVenkata Suresh Kumar P return; 934e2b8dc52SVenkata Suresh Kumar P } 935e2b8dc52SVenkata Suresh Kumar P 936e2b8dc52SVenkata Suresh Kumar P tap = tap_find(obj, tokens[t0 + 1]); 937e2b8dc52SVenkata Suresh Kumar P if (!tap) { 938e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_ARG_INVALID, 939e2b8dc52SVenkata Suresh Kumar P "tap_name"); 940e2b8dc52SVenkata Suresh Kumar P return; 941e2b8dc52SVenkata Suresh Kumar P } 942e2b8dc52SVenkata Suresh Kumar P params.fd = tap->fd; 943e2b8dc52SVenkata Suresh Kumar P 944e2b8dc52SVenkata Suresh Kumar P if (strcmp(tokens[t0 + 2], "bsz") != 0) { 945e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz"); 946e2b8dc52SVenkata Suresh Kumar P return; 947e2b8dc52SVenkata Suresh Kumar P } 948e2b8dc52SVenkata Suresh Kumar P 949e2b8dc52SVenkata Suresh Kumar P if (parser_read_uint32(¶ms.burst_size, tokens[t0 + 3])) { 950e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, MSG_ARG_INVALID, 951e2b8dc52SVenkata Suresh Kumar P "burst_size"); 952e2b8dc52SVenkata Suresh Kumar P return; 953e2b8dc52SVenkata Suresh Kumar P } 954e2b8dc52SVenkata Suresh Kumar P 955e2b8dc52SVenkata Suresh Kumar P t0 += 4; 956e2b8dc52SVenkata Suresh Kumar P 957e2b8dc52SVenkata Suresh Kumar P status = rte_swx_pipeline_port_out_config(p->p, 958e2b8dc52SVenkata Suresh Kumar P port_id, 959e2b8dc52SVenkata Suresh Kumar P "fd", 960e2b8dc52SVenkata Suresh Kumar P ¶ms); 9615074e1d5SCristian Dumitrescu } else { 9625074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]); 9635074e1d5SCristian Dumitrescu return; 9645074e1d5SCristian Dumitrescu } 9655074e1d5SCristian Dumitrescu 9665074e1d5SCristian Dumitrescu if (status) { 9675074e1d5SCristian Dumitrescu snprintf(out, out_size, "port out error."); 9685074e1d5SCristian Dumitrescu return; 9695074e1d5SCristian Dumitrescu } 9705074e1d5SCristian Dumitrescu 9715074e1d5SCristian Dumitrescu if (n_tokens != t0) { 9725074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 9735074e1d5SCristian Dumitrescu return; 9745074e1d5SCristian Dumitrescu } 9755074e1d5SCristian Dumitrescu } 9765074e1d5SCristian Dumitrescu 9775074e1d5SCristian Dumitrescu static const char cmd_pipeline_build_help[] = 9785074e1d5SCristian Dumitrescu "pipeline <pipeline_name> build <spec_file>\n"; 9795074e1d5SCristian Dumitrescu 9805074e1d5SCristian Dumitrescu static void 9815074e1d5SCristian Dumitrescu cmd_pipeline_build(char **tokens, 9825074e1d5SCristian Dumitrescu uint32_t n_tokens, 9835074e1d5SCristian Dumitrescu char *out, 9845074e1d5SCristian Dumitrescu size_t out_size, 9855074e1d5SCristian Dumitrescu void *obj) 9865074e1d5SCristian Dumitrescu { 9875074e1d5SCristian Dumitrescu struct pipeline *p = NULL; 9885074e1d5SCristian Dumitrescu FILE *spec = NULL; 9895074e1d5SCristian Dumitrescu uint32_t err_line; 9905074e1d5SCristian Dumitrescu const char *err_msg; 9915074e1d5SCristian Dumitrescu int status; 9925074e1d5SCristian Dumitrescu 9935074e1d5SCristian Dumitrescu if (n_tokens != 4) { 9945074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 9955074e1d5SCristian Dumitrescu return; 9965074e1d5SCristian Dumitrescu } 9975074e1d5SCristian Dumitrescu 9985074e1d5SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 9995074e1d5SCristian Dumitrescu if (!p || p->ctl) { 10005074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]); 10015074e1d5SCristian Dumitrescu return; 10025074e1d5SCristian Dumitrescu } 10035074e1d5SCristian Dumitrescu 10045074e1d5SCristian Dumitrescu spec = fopen(tokens[3], "r"); 10055074e1d5SCristian Dumitrescu if (!spec) { 10065074e1d5SCristian Dumitrescu snprintf(out, out_size, "Cannot open file %s.\n", tokens[3]); 10075074e1d5SCristian Dumitrescu return; 10085074e1d5SCristian Dumitrescu } 10095074e1d5SCristian Dumitrescu 10105074e1d5SCristian Dumitrescu status = rte_swx_pipeline_build_from_spec(p->p, 10115074e1d5SCristian Dumitrescu spec, 10125074e1d5SCristian Dumitrescu &err_line, 10135074e1d5SCristian Dumitrescu &err_msg); 10145074e1d5SCristian Dumitrescu fclose(spec); 10155074e1d5SCristian Dumitrescu if (status) { 10165074e1d5SCristian Dumitrescu snprintf(out, out_size, "Error %d at line %u: %s\n.", 10175074e1d5SCristian Dumitrescu status, err_line, err_msg); 10185074e1d5SCristian Dumitrescu return; 10195074e1d5SCristian Dumitrescu } 10205074e1d5SCristian Dumitrescu 10215074e1d5SCristian Dumitrescu p->ctl = rte_swx_ctl_pipeline_create(p->p); 10225074e1d5SCristian Dumitrescu if (!p->ctl) { 10235074e1d5SCristian Dumitrescu snprintf(out, out_size, "Pipeline control create failed."); 10245074e1d5SCristian Dumitrescu rte_swx_pipeline_free(p->p); 10255074e1d5SCristian Dumitrescu return; 10265074e1d5SCristian Dumitrescu } 10275074e1d5SCristian Dumitrescu } 10285074e1d5SCristian Dumitrescu 1029275ebefeSCristian Dumitrescu static void 1030275ebefeSCristian Dumitrescu table_entry_free(struct rte_swx_table_entry *entry) 1031275ebefeSCristian Dumitrescu { 1032275ebefeSCristian Dumitrescu if (!entry) 1033275ebefeSCristian Dumitrescu return; 1034275ebefeSCristian Dumitrescu 1035275ebefeSCristian Dumitrescu free(entry->key); 1036275ebefeSCristian Dumitrescu free(entry->key_mask); 1037275ebefeSCristian Dumitrescu free(entry->action_data); 1038275ebefeSCristian Dumitrescu free(entry); 1039275ebefeSCristian Dumitrescu } 1040275ebefeSCristian Dumitrescu 104175129cebSChurchill Khangar #ifndef MAX_LINE_SIZE 104275129cebSChurchill Khangar #define MAX_LINE_SIZE 2048 104375129cebSChurchill Khangar #endif 104475129cebSChurchill Khangar 104575129cebSChurchill Khangar static int 104675129cebSChurchill Khangar pipeline_table_entries_add(struct rte_swx_ctl_pipeline *p, 104775129cebSChurchill Khangar const char *table_name, 104875129cebSChurchill Khangar FILE *file, 104975129cebSChurchill Khangar uint32_t *file_line_number) 105075129cebSChurchill Khangar { 105175129cebSChurchill Khangar char *line = NULL; 105275129cebSChurchill Khangar uint32_t line_id = 0; 105375129cebSChurchill Khangar int status = 0; 105475129cebSChurchill Khangar 105575129cebSChurchill Khangar /* Buffer allocation. */ 105675129cebSChurchill Khangar line = malloc(MAX_LINE_SIZE); 105775129cebSChurchill Khangar if (!line) 105875129cebSChurchill Khangar return -ENOMEM; 105975129cebSChurchill Khangar 106075129cebSChurchill Khangar /* File read. */ 106175129cebSChurchill Khangar for (line_id = 1; ; line_id++) { 106275129cebSChurchill Khangar struct rte_swx_table_entry *entry; 106375129cebSChurchill Khangar int is_blank_or_comment; 106475129cebSChurchill Khangar 106575129cebSChurchill Khangar if (fgets(line, MAX_LINE_SIZE, file) == NULL) 106675129cebSChurchill Khangar break; 106775129cebSChurchill Khangar 106875129cebSChurchill Khangar entry = rte_swx_ctl_pipeline_table_entry_read(p, 106975129cebSChurchill Khangar table_name, 107075129cebSChurchill Khangar line, 107175129cebSChurchill Khangar &is_blank_or_comment); 107275129cebSChurchill Khangar if (!entry) { 107375129cebSChurchill Khangar if (is_blank_or_comment) 107475129cebSChurchill Khangar continue; 107575129cebSChurchill Khangar 107675129cebSChurchill Khangar status = -EINVAL; 107775129cebSChurchill Khangar goto error; 107875129cebSChurchill Khangar } 107975129cebSChurchill Khangar 108075129cebSChurchill Khangar status = rte_swx_ctl_pipeline_table_entry_add(p, 108175129cebSChurchill Khangar table_name, 108275129cebSChurchill Khangar entry); 108375129cebSChurchill Khangar table_entry_free(entry); 108475129cebSChurchill Khangar if (status) 108575129cebSChurchill Khangar goto error; 108675129cebSChurchill Khangar } 108775129cebSChurchill Khangar 108875129cebSChurchill Khangar error: 108975129cebSChurchill Khangar free(line); 109075129cebSChurchill Khangar *file_line_number = line_id; 109175129cebSChurchill Khangar return status; 109275129cebSChurchill Khangar } 109375129cebSChurchill Khangar 109475129cebSChurchill Khangar static const char cmd_pipeline_table_add_help[] = 109575129cebSChurchill Khangar "pipeline <pipeline_name> table <table_name> add <file_name>\n"; 10965074e1d5SCristian Dumitrescu 10975074e1d5SCristian Dumitrescu static void 109875129cebSChurchill Khangar cmd_pipeline_table_add(char **tokens, 10995074e1d5SCristian Dumitrescu uint32_t n_tokens, 11005074e1d5SCristian Dumitrescu char *out, 11015074e1d5SCristian Dumitrescu size_t out_size, 11025074e1d5SCristian Dumitrescu void *obj) 11035074e1d5SCristian Dumitrescu { 11045074e1d5SCristian Dumitrescu struct pipeline *p; 110575129cebSChurchill Khangar char *pipeline_name, *table_name, *file_name; 110675129cebSChurchill Khangar FILE *file = NULL; 110775129cebSChurchill Khangar uint32_t file_line_number = 0; 11085074e1d5SCristian Dumitrescu int status; 11095074e1d5SCristian Dumitrescu 111075129cebSChurchill Khangar if (n_tokens != 6) { 11115074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 11125074e1d5SCristian Dumitrescu return; 11135074e1d5SCristian Dumitrescu } 11145074e1d5SCristian Dumitrescu 11155074e1d5SCristian Dumitrescu pipeline_name = tokens[1]; 11165074e1d5SCristian Dumitrescu p = pipeline_find(obj, pipeline_name); 11175074e1d5SCristian Dumitrescu if (!p || !p->ctl) { 11185074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 11195074e1d5SCristian Dumitrescu return; 11205074e1d5SCristian Dumitrescu } 11215074e1d5SCristian Dumitrescu 112275129cebSChurchill Khangar table_name = tokens[3]; 112375129cebSChurchill Khangar 112475129cebSChurchill Khangar file_name = tokens[5]; 112575129cebSChurchill Khangar file = fopen(file_name, "r"); 112675129cebSChurchill Khangar if (!file) { 112775129cebSChurchill Khangar snprintf(out, out_size, "Cannot open file %s.\n", file_name); 112875129cebSChurchill Khangar return; 112975129cebSChurchill Khangar } 113075129cebSChurchill Khangar 113175129cebSChurchill Khangar status = pipeline_table_entries_add(p->ctl, 113275129cebSChurchill Khangar table_name, 113375129cebSChurchill Khangar file, 113475129cebSChurchill Khangar &file_line_number); 113575129cebSChurchill Khangar if (status) 113675129cebSChurchill Khangar snprintf(out, out_size, "Invalid entry in file %s at line %u\n", 113775129cebSChurchill Khangar file_name, 113875129cebSChurchill Khangar file_line_number); 113975129cebSChurchill Khangar 114075129cebSChurchill Khangar fclose(file); 114175129cebSChurchill Khangar } 114275129cebSChurchill Khangar 114375129cebSChurchill Khangar static int 114475129cebSChurchill Khangar pipeline_table_entries_delete(struct rte_swx_ctl_pipeline *p, 114575129cebSChurchill Khangar const char *table_name, 114675129cebSChurchill Khangar FILE *file, 114775129cebSChurchill Khangar uint32_t *file_line_number) 114875129cebSChurchill Khangar { 114975129cebSChurchill Khangar char *line = NULL; 115075129cebSChurchill Khangar uint32_t line_id = 0; 115175129cebSChurchill Khangar int status = 0; 115275129cebSChurchill Khangar 115375129cebSChurchill Khangar /* Buffer allocation. */ 115475129cebSChurchill Khangar line = malloc(MAX_LINE_SIZE); 115575129cebSChurchill Khangar if (!line) 115675129cebSChurchill Khangar return -ENOMEM; 115775129cebSChurchill Khangar 115875129cebSChurchill Khangar /* File read. */ 115975129cebSChurchill Khangar for (line_id = 1; ; line_id++) { 116075129cebSChurchill Khangar struct rte_swx_table_entry *entry; 116175129cebSChurchill Khangar int is_blank_or_comment; 116275129cebSChurchill Khangar 116375129cebSChurchill Khangar if (fgets(line, MAX_LINE_SIZE, file) == NULL) 116475129cebSChurchill Khangar break; 116575129cebSChurchill Khangar 116675129cebSChurchill Khangar entry = rte_swx_ctl_pipeline_table_entry_read(p, 116775129cebSChurchill Khangar table_name, 116875129cebSChurchill Khangar line, 116975129cebSChurchill Khangar &is_blank_or_comment); 117075129cebSChurchill Khangar if (!entry) { 117175129cebSChurchill Khangar if (is_blank_or_comment) 117275129cebSChurchill Khangar continue; 117375129cebSChurchill Khangar 117475129cebSChurchill Khangar status = -EINVAL; 117575129cebSChurchill Khangar goto error; 117675129cebSChurchill Khangar } 117775129cebSChurchill Khangar 117875129cebSChurchill Khangar status = rte_swx_ctl_pipeline_table_entry_delete(p, 117975129cebSChurchill Khangar table_name, 118075129cebSChurchill Khangar entry); 118175129cebSChurchill Khangar table_entry_free(entry); 118275129cebSChurchill Khangar if (status) 118375129cebSChurchill Khangar goto error; 118475129cebSChurchill Khangar } 118575129cebSChurchill Khangar 118675129cebSChurchill Khangar error: 118775129cebSChurchill Khangar *file_line_number = line_id; 118875129cebSChurchill Khangar free(line); 118975129cebSChurchill Khangar return status; 119075129cebSChurchill Khangar } 119175129cebSChurchill Khangar 119275129cebSChurchill Khangar static const char cmd_pipeline_table_delete_help[] = 119375129cebSChurchill Khangar "pipeline <pipeline_name> table <table_name> delete <file_name>\n"; 119475129cebSChurchill Khangar 119575129cebSChurchill Khangar static void 119675129cebSChurchill Khangar cmd_pipeline_table_delete(char **tokens, 119775129cebSChurchill Khangar uint32_t n_tokens, 119875129cebSChurchill Khangar char *out, 119975129cebSChurchill Khangar size_t out_size, 120075129cebSChurchill Khangar void *obj) 120175129cebSChurchill Khangar { 120275129cebSChurchill Khangar struct pipeline *p; 120375129cebSChurchill Khangar char *pipeline_name, *table_name, *file_name; 120475129cebSChurchill Khangar FILE *file = NULL; 120575129cebSChurchill Khangar uint32_t file_line_number = 0; 120675129cebSChurchill Khangar int status; 120775129cebSChurchill Khangar 120875129cebSChurchill Khangar if (n_tokens != 6) { 120975129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 121075129cebSChurchill Khangar return; 121175129cebSChurchill Khangar } 121275129cebSChurchill Khangar 121375129cebSChurchill Khangar pipeline_name = tokens[1]; 121475129cebSChurchill Khangar p = pipeline_find(obj, pipeline_name); 121575129cebSChurchill Khangar if (!p || !p->ctl) { 121675129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 12175074e1d5SCristian Dumitrescu return; 12185074e1d5SCristian Dumitrescu } 12195074e1d5SCristian Dumitrescu 12205074e1d5SCristian Dumitrescu table_name = tokens[3]; 12215074e1d5SCristian Dumitrescu 122275129cebSChurchill Khangar file_name = tokens[5]; 122375129cebSChurchill Khangar file = fopen(file_name, "r"); 122475129cebSChurchill Khangar if (!file) { 122575129cebSChurchill Khangar snprintf(out, out_size, "Cannot open file %s.\n", file_name); 12265074e1d5SCristian Dumitrescu return; 12275074e1d5SCristian Dumitrescu } 12285074e1d5SCristian Dumitrescu 122975129cebSChurchill Khangar status = pipeline_table_entries_delete(p->ctl, 123075129cebSChurchill Khangar table_name, 123175129cebSChurchill Khangar file, 123275129cebSChurchill Khangar &file_line_number); 123375129cebSChurchill Khangar if (status) 123475129cebSChurchill Khangar snprintf(out, out_size, "Invalid entry in file %s at line %u\n", 123575129cebSChurchill Khangar file_name, 123675129cebSChurchill Khangar file_line_number); 12375074e1d5SCristian Dumitrescu 123875129cebSChurchill Khangar fclose(file); 12395074e1d5SCristian Dumitrescu } 12405074e1d5SCristian Dumitrescu 124175129cebSChurchill Khangar static int 124275129cebSChurchill Khangar pipeline_table_default_entry_add(struct rte_swx_ctl_pipeline *p, 124375129cebSChurchill Khangar const char *table_name, 124475129cebSChurchill Khangar FILE *file, 124575129cebSChurchill Khangar uint32_t *file_line_number) 124675129cebSChurchill Khangar { 124775129cebSChurchill Khangar char *line = NULL; 124875129cebSChurchill Khangar uint32_t line_id = 0; 124975129cebSChurchill Khangar int status = 0; 12505074e1d5SCristian Dumitrescu 12515074e1d5SCristian Dumitrescu /* Buffer allocation. */ 125275129cebSChurchill Khangar line = malloc(MAX_LINE_SIZE); 125375129cebSChurchill Khangar if (!line) 125475129cebSChurchill Khangar return -ENOMEM; 12555074e1d5SCristian Dumitrescu 125675129cebSChurchill Khangar /* File read. */ 12575074e1d5SCristian Dumitrescu for (line_id = 1; ; line_id++) { 12585074e1d5SCristian Dumitrescu struct rte_swx_table_entry *entry; 1259cff9a717SCristian Dumitrescu int is_blank_or_comment; 12605074e1d5SCristian Dumitrescu 126175129cebSChurchill Khangar if (fgets(line, MAX_LINE_SIZE, file) == NULL) 12625074e1d5SCristian Dumitrescu break; 12635074e1d5SCristian Dumitrescu 126475129cebSChurchill Khangar entry = rte_swx_ctl_pipeline_table_entry_read(p, 12655074e1d5SCristian Dumitrescu table_name, 1266cff9a717SCristian Dumitrescu line, 1267cff9a717SCristian Dumitrescu &is_blank_or_comment); 12685074e1d5SCristian Dumitrescu if (!entry) { 1269cff9a717SCristian Dumitrescu if (is_blank_or_comment) 1270cff9a717SCristian Dumitrescu continue; 1271cff9a717SCristian Dumitrescu 127275129cebSChurchill Khangar status = -EINVAL; 12735074e1d5SCristian Dumitrescu goto error; 12745074e1d5SCristian Dumitrescu } 12755074e1d5SCristian Dumitrescu 127675129cebSChurchill Khangar status = rte_swx_ctl_pipeline_table_default_entry_add(p, 12775074e1d5SCristian Dumitrescu table_name, 12785074e1d5SCristian Dumitrescu entry); 1279275ebefeSCristian Dumitrescu table_entry_free(entry); 128075129cebSChurchill Khangar if (status) 12815074e1d5SCristian Dumitrescu goto error; 12825074e1d5SCristian Dumitrescu } 128375129cebSChurchill Khangar 128475129cebSChurchill Khangar error: 128575129cebSChurchill Khangar *file_line_number = line_id; 128675129cebSChurchill Khangar free(line); 128775129cebSChurchill Khangar return status; 12885074e1d5SCristian Dumitrescu } 12895074e1d5SCristian Dumitrescu 129075129cebSChurchill Khangar static const char cmd_pipeline_table_default_help[] = 129175129cebSChurchill Khangar "pipeline <pipeline_name> table <table_name> default <file_name>\n"; 12925074e1d5SCristian Dumitrescu 129375129cebSChurchill Khangar static void 129475129cebSChurchill Khangar cmd_pipeline_table_default(char **tokens, 129575129cebSChurchill Khangar uint32_t n_tokens, 129675129cebSChurchill Khangar char *out, 129775129cebSChurchill Khangar size_t out_size, 129875129cebSChurchill Khangar void *obj) 129975129cebSChurchill Khangar { 130075129cebSChurchill Khangar struct pipeline *p; 130175129cebSChurchill Khangar char *pipeline_name, *table_name, *file_name; 130275129cebSChurchill Khangar FILE *file = NULL; 130375129cebSChurchill Khangar uint32_t file_line_number = 0; 130475129cebSChurchill Khangar int status; 13055074e1d5SCristian Dumitrescu 130675129cebSChurchill Khangar if (n_tokens != 6) { 130775129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 130875129cebSChurchill Khangar return; 130975129cebSChurchill Khangar } 13105074e1d5SCristian Dumitrescu 131175129cebSChurchill Khangar pipeline_name = tokens[1]; 131275129cebSChurchill Khangar p = pipeline_find(obj, pipeline_name); 131375129cebSChurchill Khangar if (!p || !p->ctl) { 131475129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 131575129cebSChurchill Khangar return; 131675129cebSChurchill Khangar } 131775129cebSChurchill Khangar 131875129cebSChurchill Khangar table_name = tokens[3]; 131975129cebSChurchill Khangar 132075129cebSChurchill Khangar file_name = tokens[5]; 132175129cebSChurchill Khangar file = fopen(file_name, "r"); 132275129cebSChurchill Khangar if (!file) { 132375129cebSChurchill Khangar snprintf(out, out_size, "Cannot open file %s.\n", file_name); 132475129cebSChurchill Khangar return; 132575129cebSChurchill Khangar } 132675129cebSChurchill Khangar 132775129cebSChurchill Khangar status = pipeline_table_default_entry_add(p->ctl, 13285074e1d5SCristian Dumitrescu table_name, 132975129cebSChurchill Khangar file, 133075129cebSChurchill Khangar &file_line_number); 133175129cebSChurchill Khangar if (status) 133275129cebSChurchill Khangar snprintf(out, out_size, "Invalid entry in file %s at line %u\n", 133375129cebSChurchill Khangar file_name, 133475129cebSChurchill Khangar file_line_number); 1335cff9a717SCristian Dumitrescu 133675129cebSChurchill Khangar fclose(file); 13375074e1d5SCristian Dumitrescu } 13385074e1d5SCristian Dumitrescu 133975129cebSChurchill Khangar static const char cmd_pipeline_table_show_help[] = 134075129cebSChurchill Khangar "pipeline <pipeline_name> table <table_name> show\n"; 134175129cebSChurchill Khangar 134275129cebSChurchill Khangar static void 134375129cebSChurchill Khangar cmd_pipeline_table_show(char **tokens, 134475129cebSChurchill Khangar uint32_t n_tokens, 134575129cebSChurchill Khangar char *out, 134675129cebSChurchill Khangar size_t out_size, 134775129cebSChurchill Khangar void *obj) 134875129cebSChurchill Khangar { 134975129cebSChurchill Khangar struct pipeline *p; 135075129cebSChurchill Khangar char *pipeline_name, *table_name; 135175129cebSChurchill Khangar int status; 135275129cebSChurchill Khangar 135375129cebSChurchill Khangar if (n_tokens != 5) { 135475129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 135575129cebSChurchill Khangar return; 13565074e1d5SCristian Dumitrescu } 13575074e1d5SCristian Dumitrescu 135875129cebSChurchill Khangar pipeline_name = tokens[1]; 135975129cebSChurchill Khangar p = pipeline_find(obj, pipeline_name); 136075129cebSChurchill Khangar if (!p || !p->ctl) { 136175129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 136275129cebSChurchill Khangar return; 13635074e1d5SCristian Dumitrescu } 13645074e1d5SCristian Dumitrescu 136575129cebSChurchill Khangar table_name = tokens[3]; 136675129cebSChurchill Khangar status = rte_swx_ctl_pipeline_table_fprintf(stdout, p->ctl, table_name); 136775129cebSChurchill Khangar if (status) 136875129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "table_name"); 13695074e1d5SCristian Dumitrescu } 137075129cebSChurchill Khangar 1371598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_group_add_help[] = 1372598fe0ddSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> group add\n"; 1373598fe0ddSCristian Dumitrescu 1374598fe0ddSCristian Dumitrescu static void 1375598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_add(char **tokens, 1376598fe0ddSCristian Dumitrescu uint32_t n_tokens, 1377598fe0ddSCristian Dumitrescu char *out, 1378598fe0ddSCristian Dumitrescu size_t out_size, 1379598fe0ddSCristian Dumitrescu void *obj) 1380598fe0ddSCristian Dumitrescu { 1381598fe0ddSCristian Dumitrescu struct pipeline *p; 1382598fe0ddSCristian Dumitrescu char *pipeline_name, *selector_name; 1383598fe0ddSCristian Dumitrescu uint32_t group_id; 1384598fe0ddSCristian Dumitrescu int status; 1385598fe0ddSCristian Dumitrescu 1386598fe0ddSCristian Dumitrescu if (n_tokens != 6) { 1387598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 1388598fe0ddSCristian Dumitrescu return; 1389598fe0ddSCristian Dumitrescu } 1390598fe0ddSCristian Dumitrescu 1391598fe0ddSCristian Dumitrescu pipeline_name = tokens[1]; 1392598fe0ddSCristian Dumitrescu p = pipeline_find(obj, pipeline_name); 1393598fe0ddSCristian Dumitrescu if (!p || !p->ctl) { 1394598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 1395598fe0ddSCristian Dumitrescu return; 1396598fe0ddSCristian Dumitrescu } 1397598fe0ddSCristian Dumitrescu 1398598fe0ddSCristian Dumitrescu if (strcmp(tokens[2], "selector") != 0) { 1399598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector"); 1400598fe0ddSCristian Dumitrescu return; 1401598fe0ddSCristian Dumitrescu } 1402598fe0ddSCristian Dumitrescu 1403598fe0ddSCristian Dumitrescu selector_name = tokens[3]; 1404598fe0ddSCristian Dumitrescu 1405598fe0ddSCristian Dumitrescu if (strcmp(tokens[4], "group") || 1406598fe0ddSCristian Dumitrescu strcmp(tokens[5], "add")) { 1407598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group add"); 1408598fe0ddSCristian Dumitrescu return; 1409598fe0ddSCristian Dumitrescu } 1410598fe0ddSCristian Dumitrescu 1411598fe0ddSCristian Dumitrescu status = rte_swx_ctl_pipeline_selector_group_add(p->ctl, 1412598fe0ddSCristian Dumitrescu selector_name, 1413598fe0ddSCristian Dumitrescu &group_id); 1414598fe0ddSCristian Dumitrescu if (status) 1415598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]); 1416598fe0ddSCristian Dumitrescu else 1417598fe0ddSCristian Dumitrescu snprintf(out, out_size, "Group ID: %u\n", group_id); 1418598fe0ddSCristian Dumitrescu } 1419598fe0ddSCristian Dumitrescu 1420598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_group_delete_help[] = 1421598fe0ddSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> group delete <group_id>\n"; 1422598fe0ddSCristian Dumitrescu 1423598fe0ddSCristian Dumitrescu static void 1424598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_delete(char **tokens, 1425598fe0ddSCristian Dumitrescu uint32_t n_tokens, 1426598fe0ddSCristian Dumitrescu char *out, 1427598fe0ddSCristian Dumitrescu size_t out_size, 1428598fe0ddSCristian Dumitrescu void *obj) 1429598fe0ddSCristian Dumitrescu { 1430598fe0ddSCristian Dumitrescu struct pipeline *p; 1431598fe0ddSCristian Dumitrescu char *pipeline_name, *selector_name; 1432598fe0ddSCristian Dumitrescu uint32_t group_id; 1433598fe0ddSCristian Dumitrescu int status; 1434598fe0ddSCristian Dumitrescu 1435598fe0ddSCristian Dumitrescu if (n_tokens != 7) { 1436598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 1437598fe0ddSCristian Dumitrescu return; 1438598fe0ddSCristian Dumitrescu } 1439598fe0ddSCristian Dumitrescu 1440598fe0ddSCristian Dumitrescu pipeline_name = tokens[1]; 1441598fe0ddSCristian Dumitrescu p = pipeline_find(obj, pipeline_name); 1442598fe0ddSCristian Dumitrescu if (!p || !p->ctl) { 1443598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 1444598fe0ddSCristian Dumitrescu return; 1445598fe0ddSCristian Dumitrescu } 1446598fe0ddSCristian Dumitrescu 1447598fe0ddSCristian Dumitrescu if (strcmp(tokens[2], "selector") != 0) { 1448598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector"); 1449598fe0ddSCristian Dumitrescu return; 1450598fe0ddSCristian Dumitrescu } 1451598fe0ddSCristian Dumitrescu 1452598fe0ddSCristian Dumitrescu selector_name = tokens[3]; 1453598fe0ddSCristian Dumitrescu 1454598fe0ddSCristian Dumitrescu if (strcmp(tokens[4], "group") || 1455598fe0ddSCristian Dumitrescu strcmp(tokens[5], "delete")) { 1456598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group delete"); 1457598fe0ddSCristian Dumitrescu return; 1458598fe0ddSCristian Dumitrescu } 1459598fe0ddSCristian Dumitrescu 1460598fe0ddSCristian Dumitrescu if (parser_read_uint32(&group_id, tokens[6]) != 0) { 1461598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "group_id"); 1462598fe0ddSCristian Dumitrescu return; 1463598fe0ddSCristian Dumitrescu } 1464598fe0ddSCristian Dumitrescu 1465598fe0ddSCristian Dumitrescu status = rte_swx_ctl_pipeline_selector_group_delete(p->ctl, 1466598fe0ddSCristian Dumitrescu selector_name, 1467598fe0ddSCristian Dumitrescu group_id); 1468598fe0ddSCristian Dumitrescu if (status) 1469598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]); 1470598fe0ddSCristian Dumitrescu } 1471598fe0ddSCristian Dumitrescu 1472598fe0ddSCristian Dumitrescu #define GROUP_MEMBER_INFO_TOKENS_MAX 6 1473598fe0ddSCristian Dumitrescu 1474598fe0ddSCristian Dumitrescu static int 1475598fe0ddSCristian Dumitrescu token_is_comment(const char *token) 1476598fe0ddSCristian Dumitrescu { 1477598fe0ddSCristian Dumitrescu if ((token[0] == '#') || 1478598fe0ddSCristian Dumitrescu (token[0] == ';') || 1479598fe0ddSCristian Dumitrescu ((token[0] == '/') && (token[1] == '/'))) 1480598fe0ddSCristian Dumitrescu return 1; /* TRUE. */ 1481598fe0ddSCristian Dumitrescu 1482598fe0ddSCristian Dumitrescu return 0; /* FALSE. */ 1483598fe0ddSCristian Dumitrescu } 1484598fe0ddSCristian Dumitrescu 1485598fe0ddSCristian Dumitrescu static int 1486598fe0ddSCristian Dumitrescu pipeline_selector_group_member_read(const char *string, 1487598fe0ddSCristian Dumitrescu uint32_t *group_id, 1488598fe0ddSCristian Dumitrescu uint32_t *member_id, 1489598fe0ddSCristian Dumitrescu uint32_t *weight, 1490598fe0ddSCristian Dumitrescu int *is_blank_or_comment) 1491598fe0ddSCristian Dumitrescu { 1492598fe0ddSCristian Dumitrescu char *token_array[GROUP_MEMBER_INFO_TOKENS_MAX], **tokens; 1493598fe0ddSCristian Dumitrescu char *s0 = NULL, *s; 149400b67591SAli Alnubani uint32_t n_tokens = 0, group_id_val = 0, member_id_val = 0, weight_val = 0; 1495598fe0ddSCristian Dumitrescu int blank_or_comment = 0; 1496598fe0ddSCristian Dumitrescu 1497598fe0ddSCristian Dumitrescu /* Check input arguments. */ 1498598fe0ddSCristian Dumitrescu if (!string || !string[0]) 1499598fe0ddSCristian Dumitrescu goto error; 1500598fe0ddSCristian Dumitrescu 1501598fe0ddSCristian Dumitrescu /* Memory allocation. */ 1502598fe0ddSCristian Dumitrescu s0 = strdup(string); 1503598fe0ddSCristian Dumitrescu if (!s0) 1504598fe0ddSCristian Dumitrescu goto error; 1505598fe0ddSCristian Dumitrescu 1506598fe0ddSCristian Dumitrescu /* Parse the string into tokens. */ 1507598fe0ddSCristian Dumitrescu for (s = s0; ; ) { 1508598fe0ddSCristian Dumitrescu char *token; 1509598fe0ddSCristian Dumitrescu 1510598fe0ddSCristian Dumitrescu token = strtok_r(s, " \f\n\r\t\v", &s); 1511598fe0ddSCristian Dumitrescu if (!token || token_is_comment(token)) 1512598fe0ddSCristian Dumitrescu break; 1513598fe0ddSCristian Dumitrescu 1514*cfcc7bf8SCristian Dumitrescu if (n_tokens >= GROUP_MEMBER_INFO_TOKENS_MAX) 1515598fe0ddSCristian Dumitrescu goto error; 1516598fe0ddSCristian Dumitrescu 1517598fe0ddSCristian Dumitrescu token_array[n_tokens] = token; 1518598fe0ddSCristian Dumitrescu n_tokens++; 1519598fe0ddSCristian Dumitrescu } 1520598fe0ddSCristian Dumitrescu 1521598fe0ddSCristian Dumitrescu if (!n_tokens) { 1522598fe0ddSCristian Dumitrescu blank_or_comment = 1; 1523598fe0ddSCristian Dumitrescu goto error; 1524598fe0ddSCristian Dumitrescu } 1525598fe0ddSCristian Dumitrescu 1526598fe0ddSCristian Dumitrescu tokens = token_array; 1527598fe0ddSCristian Dumitrescu 1528598fe0ddSCristian Dumitrescu if (n_tokens < 4 || 1529598fe0ddSCristian Dumitrescu strcmp(tokens[0], "group") || 1530598fe0ddSCristian Dumitrescu strcmp(tokens[2], "member")) 1531598fe0ddSCristian Dumitrescu goto error; 1532598fe0ddSCristian Dumitrescu 1533598fe0ddSCristian Dumitrescu /* 1534598fe0ddSCristian Dumitrescu * Group ID. 1535598fe0ddSCristian Dumitrescu */ 1536598fe0ddSCristian Dumitrescu if (parser_read_uint32(&group_id_val, tokens[1]) != 0) 1537598fe0ddSCristian Dumitrescu goto error; 1538598fe0ddSCristian Dumitrescu *group_id = group_id_val; 1539598fe0ddSCristian Dumitrescu 1540598fe0ddSCristian Dumitrescu /* 1541598fe0ddSCristian Dumitrescu * Member ID. 1542598fe0ddSCristian Dumitrescu */ 1543598fe0ddSCristian Dumitrescu if (parser_read_uint32(&member_id_val, tokens[3]) != 0) 1544598fe0ddSCristian Dumitrescu goto error; 1545598fe0ddSCristian Dumitrescu *member_id = member_id_val; 1546598fe0ddSCristian Dumitrescu 1547598fe0ddSCristian Dumitrescu tokens += 4; 1548598fe0ddSCristian Dumitrescu n_tokens -= 4; 1549598fe0ddSCristian Dumitrescu 1550598fe0ddSCristian Dumitrescu /* 1551598fe0ddSCristian Dumitrescu * Weight. 1552598fe0ddSCristian Dumitrescu */ 1553598fe0ddSCristian Dumitrescu if (n_tokens && !strcmp(tokens[0], "weight")) { 1554598fe0ddSCristian Dumitrescu if (n_tokens < 2) 1555598fe0ddSCristian Dumitrescu goto error; 1556598fe0ddSCristian Dumitrescu 1557598fe0ddSCristian Dumitrescu if (parser_read_uint32(&weight_val, tokens[1]) != 0) 1558598fe0ddSCristian Dumitrescu goto error; 1559598fe0ddSCristian Dumitrescu *weight = weight_val; 1560598fe0ddSCristian Dumitrescu 1561598fe0ddSCristian Dumitrescu tokens += 2; 1562598fe0ddSCristian Dumitrescu n_tokens -= 2; 1563598fe0ddSCristian Dumitrescu } 1564598fe0ddSCristian Dumitrescu 1565598fe0ddSCristian Dumitrescu if (n_tokens) 1566598fe0ddSCristian Dumitrescu goto error; 1567598fe0ddSCristian Dumitrescu 1568598fe0ddSCristian Dumitrescu free(s0); 1569598fe0ddSCristian Dumitrescu return 0; 1570598fe0ddSCristian Dumitrescu 1571598fe0ddSCristian Dumitrescu error: 1572598fe0ddSCristian Dumitrescu free(s0); 1573598fe0ddSCristian Dumitrescu if (is_blank_or_comment) 1574598fe0ddSCristian Dumitrescu *is_blank_or_comment = blank_or_comment; 1575598fe0ddSCristian Dumitrescu return -EINVAL; 1576598fe0ddSCristian Dumitrescu } 1577598fe0ddSCristian Dumitrescu 1578598fe0ddSCristian Dumitrescu static int 1579598fe0ddSCristian Dumitrescu pipeline_selector_group_members_add(struct rte_swx_ctl_pipeline *p, 1580598fe0ddSCristian Dumitrescu const char *selector_name, 1581598fe0ddSCristian Dumitrescu FILE *file, 1582598fe0ddSCristian Dumitrescu uint32_t *file_line_number) 1583598fe0ddSCristian Dumitrescu { 1584598fe0ddSCristian Dumitrescu char *line = NULL; 1585598fe0ddSCristian Dumitrescu uint32_t line_id = 0; 1586598fe0ddSCristian Dumitrescu int status = 0; 1587598fe0ddSCristian Dumitrescu 1588598fe0ddSCristian Dumitrescu /* Buffer allocation. */ 1589598fe0ddSCristian Dumitrescu line = malloc(MAX_LINE_SIZE); 1590598fe0ddSCristian Dumitrescu if (!line) 1591598fe0ddSCristian Dumitrescu return -ENOMEM; 1592598fe0ddSCristian Dumitrescu 1593598fe0ddSCristian Dumitrescu /* File read. */ 1594598fe0ddSCristian Dumitrescu for (line_id = 1; ; line_id++) { 1595598fe0ddSCristian Dumitrescu uint32_t group_id, member_id, weight; 1596598fe0ddSCristian Dumitrescu int is_blank_or_comment; 1597598fe0ddSCristian Dumitrescu 1598598fe0ddSCristian Dumitrescu if (fgets(line, MAX_LINE_SIZE, file) == NULL) 1599598fe0ddSCristian Dumitrescu break; 1600598fe0ddSCristian Dumitrescu 1601598fe0ddSCristian Dumitrescu status = pipeline_selector_group_member_read(line, 1602598fe0ddSCristian Dumitrescu &group_id, 1603598fe0ddSCristian Dumitrescu &member_id, 1604598fe0ddSCristian Dumitrescu &weight, 1605598fe0ddSCristian Dumitrescu &is_blank_or_comment); 1606598fe0ddSCristian Dumitrescu if (status) { 1607598fe0ddSCristian Dumitrescu if (is_blank_or_comment) 1608598fe0ddSCristian Dumitrescu continue; 1609598fe0ddSCristian Dumitrescu 1610598fe0ddSCristian Dumitrescu goto error; 1611598fe0ddSCristian Dumitrescu } 1612598fe0ddSCristian Dumitrescu 1613598fe0ddSCristian Dumitrescu status = rte_swx_ctl_pipeline_selector_group_member_add(p, 1614598fe0ddSCristian Dumitrescu selector_name, 1615598fe0ddSCristian Dumitrescu group_id, 1616598fe0ddSCristian Dumitrescu member_id, 1617598fe0ddSCristian Dumitrescu weight); 1618598fe0ddSCristian Dumitrescu if (status) 1619598fe0ddSCristian Dumitrescu goto error; 1620598fe0ddSCristian Dumitrescu } 1621598fe0ddSCristian Dumitrescu 1622598fe0ddSCristian Dumitrescu error: 1623598fe0ddSCristian Dumitrescu free(line); 1624598fe0ddSCristian Dumitrescu *file_line_number = line_id; 1625598fe0ddSCristian Dumitrescu return status; 1626598fe0ddSCristian Dumitrescu } 1627598fe0ddSCristian Dumitrescu 1628598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_group_member_add_help[] = 1629598fe0ddSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> group member add <file_name>"; 1630598fe0ddSCristian Dumitrescu 1631598fe0ddSCristian Dumitrescu static void 1632598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_add(char **tokens, 1633598fe0ddSCristian Dumitrescu uint32_t n_tokens, 1634598fe0ddSCristian Dumitrescu char *out, 1635598fe0ddSCristian Dumitrescu size_t out_size, 1636598fe0ddSCristian Dumitrescu void *obj) 1637598fe0ddSCristian Dumitrescu { 1638598fe0ddSCristian Dumitrescu struct pipeline *p; 1639598fe0ddSCristian Dumitrescu char *pipeline_name, *selector_name, *file_name; 1640598fe0ddSCristian Dumitrescu FILE *file = NULL; 1641598fe0ddSCristian Dumitrescu uint32_t file_line_number = 0; 1642598fe0ddSCristian Dumitrescu int status; 1643598fe0ddSCristian Dumitrescu 1644598fe0ddSCristian Dumitrescu if (n_tokens != 8) { 1645598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 1646598fe0ddSCristian Dumitrescu return; 1647598fe0ddSCristian Dumitrescu } 1648598fe0ddSCristian Dumitrescu 1649598fe0ddSCristian Dumitrescu pipeline_name = tokens[1]; 1650598fe0ddSCristian Dumitrescu p = pipeline_find(obj, pipeline_name); 1651598fe0ddSCristian Dumitrescu if (!p || !p->ctl) { 1652598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 1653598fe0ddSCristian Dumitrescu return; 1654598fe0ddSCristian Dumitrescu } 1655598fe0ddSCristian Dumitrescu 1656598fe0ddSCristian Dumitrescu if (strcmp(tokens[2], "selector") != 0) { 1657598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector"); 1658598fe0ddSCristian Dumitrescu return; 1659598fe0ddSCristian Dumitrescu } 1660598fe0ddSCristian Dumitrescu 1661598fe0ddSCristian Dumitrescu selector_name = tokens[3]; 1662598fe0ddSCristian Dumitrescu 1663598fe0ddSCristian Dumitrescu if (strcmp(tokens[4], "group") || 1664598fe0ddSCristian Dumitrescu strcmp(tokens[5], "member") || 1665598fe0ddSCristian Dumitrescu strcmp(tokens[6], "add")) { 1666598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group member add"); 1667598fe0ddSCristian Dumitrescu return; 1668598fe0ddSCristian Dumitrescu } 1669598fe0ddSCristian Dumitrescu 1670598fe0ddSCristian Dumitrescu file_name = tokens[7]; 1671598fe0ddSCristian Dumitrescu file = fopen(file_name, "r"); 1672598fe0ddSCristian Dumitrescu if (!file) { 1673598fe0ddSCristian Dumitrescu snprintf(out, out_size, "Cannot open file %s.\n", file_name); 1674598fe0ddSCristian Dumitrescu return; 1675598fe0ddSCristian Dumitrescu } 1676598fe0ddSCristian Dumitrescu 1677598fe0ddSCristian Dumitrescu status = pipeline_selector_group_members_add(p->ctl, 1678598fe0ddSCristian Dumitrescu selector_name, 1679598fe0ddSCristian Dumitrescu file, 1680598fe0ddSCristian Dumitrescu &file_line_number); 1681598fe0ddSCristian Dumitrescu if (status) 1682598fe0ddSCristian Dumitrescu snprintf(out, out_size, "Invalid entry in file %s at line %u\n", 1683598fe0ddSCristian Dumitrescu file_name, 1684598fe0ddSCristian Dumitrescu file_line_number); 1685598fe0ddSCristian Dumitrescu 1686598fe0ddSCristian Dumitrescu fclose(file); 1687598fe0ddSCristian Dumitrescu } 1688598fe0ddSCristian Dumitrescu 1689598fe0ddSCristian Dumitrescu static int 1690598fe0ddSCristian Dumitrescu pipeline_selector_group_members_delete(struct rte_swx_ctl_pipeline *p, 1691598fe0ddSCristian Dumitrescu const char *selector_name, 1692598fe0ddSCristian Dumitrescu FILE *file, 1693598fe0ddSCristian Dumitrescu uint32_t *file_line_number) 1694598fe0ddSCristian Dumitrescu { 1695598fe0ddSCristian Dumitrescu char *line = NULL; 1696598fe0ddSCristian Dumitrescu uint32_t line_id = 0; 1697598fe0ddSCristian Dumitrescu int status = 0; 1698598fe0ddSCristian Dumitrescu 1699598fe0ddSCristian Dumitrescu /* Buffer allocation. */ 1700598fe0ddSCristian Dumitrescu line = malloc(MAX_LINE_SIZE); 1701598fe0ddSCristian Dumitrescu if (!line) 1702598fe0ddSCristian Dumitrescu return -ENOMEM; 1703598fe0ddSCristian Dumitrescu 1704598fe0ddSCristian Dumitrescu /* File read. */ 1705598fe0ddSCristian Dumitrescu for (line_id = 1; ; line_id++) { 1706598fe0ddSCristian Dumitrescu uint32_t group_id, member_id, weight; 1707598fe0ddSCristian Dumitrescu int is_blank_or_comment; 1708598fe0ddSCristian Dumitrescu 1709598fe0ddSCristian Dumitrescu if (fgets(line, MAX_LINE_SIZE, file) == NULL) 1710598fe0ddSCristian Dumitrescu break; 1711598fe0ddSCristian Dumitrescu 1712598fe0ddSCristian Dumitrescu status = pipeline_selector_group_member_read(line, 1713598fe0ddSCristian Dumitrescu &group_id, 1714598fe0ddSCristian Dumitrescu &member_id, 1715598fe0ddSCristian Dumitrescu &weight, 1716598fe0ddSCristian Dumitrescu &is_blank_or_comment); 1717598fe0ddSCristian Dumitrescu if (status) { 1718598fe0ddSCristian Dumitrescu if (is_blank_or_comment) 1719598fe0ddSCristian Dumitrescu continue; 1720598fe0ddSCristian Dumitrescu 1721598fe0ddSCristian Dumitrescu goto error; 1722598fe0ddSCristian Dumitrescu } 1723598fe0ddSCristian Dumitrescu 1724598fe0ddSCristian Dumitrescu status = rte_swx_ctl_pipeline_selector_group_member_delete(p, 1725598fe0ddSCristian Dumitrescu selector_name, 1726598fe0ddSCristian Dumitrescu group_id, 1727598fe0ddSCristian Dumitrescu member_id); 1728598fe0ddSCristian Dumitrescu if (status) 1729598fe0ddSCristian Dumitrescu goto error; 1730598fe0ddSCristian Dumitrescu } 1731598fe0ddSCristian Dumitrescu 1732598fe0ddSCristian Dumitrescu error: 1733598fe0ddSCristian Dumitrescu free(line); 1734598fe0ddSCristian Dumitrescu *file_line_number = line_id; 1735598fe0ddSCristian Dumitrescu return status; 1736598fe0ddSCristian Dumitrescu } 1737598fe0ddSCristian Dumitrescu 1738598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_group_member_delete_help[] = 1739598fe0ddSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> group member delete <file_name>"; 1740598fe0ddSCristian Dumitrescu 1741598fe0ddSCristian Dumitrescu static void 1742598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_delete(char **tokens, 1743598fe0ddSCristian Dumitrescu uint32_t n_tokens, 1744598fe0ddSCristian Dumitrescu char *out, 1745598fe0ddSCristian Dumitrescu size_t out_size, 1746598fe0ddSCristian Dumitrescu void *obj) 1747598fe0ddSCristian Dumitrescu { 1748598fe0ddSCristian Dumitrescu struct pipeline *p; 1749598fe0ddSCristian Dumitrescu char *pipeline_name, *selector_name, *file_name; 1750598fe0ddSCristian Dumitrescu FILE *file = NULL; 1751598fe0ddSCristian Dumitrescu uint32_t file_line_number = 0; 1752598fe0ddSCristian Dumitrescu int status; 1753598fe0ddSCristian Dumitrescu 1754598fe0ddSCristian Dumitrescu if (n_tokens != 8) { 1755598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 1756598fe0ddSCristian Dumitrescu return; 1757598fe0ddSCristian Dumitrescu } 1758598fe0ddSCristian Dumitrescu 1759598fe0ddSCristian Dumitrescu pipeline_name = tokens[1]; 1760598fe0ddSCristian Dumitrescu p = pipeline_find(obj, pipeline_name); 1761598fe0ddSCristian Dumitrescu if (!p || !p->ctl) { 1762598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 1763598fe0ddSCristian Dumitrescu return; 1764598fe0ddSCristian Dumitrescu } 1765598fe0ddSCristian Dumitrescu 1766598fe0ddSCristian Dumitrescu if (strcmp(tokens[2], "selector") != 0) { 1767598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector"); 1768598fe0ddSCristian Dumitrescu return; 1769598fe0ddSCristian Dumitrescu } 1770598fe0ddSCristian Dumitrescu 1771598fe0ddSCristian Dumitrescu selector_name = tokens[3]; 1772598fe0ddSCristian Dumitrescu 1773598fe0ddSCristian Dumitrescu if (strcmp(tokens[4], "group") || 1774598fe0ddSCristian Dumitrescu strcmp(tokens[5], "member") || 1775598fe0ddSCristian Dumitrescu strcmp(tokens[6], "delete")) { 1776598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group member delete"); 1777598fe0ddSCristian Dumitrescu return; 1778598fe0ddSCristian Dumitrescu } 1779598fe0ddSCristian Dumitrescu 1780598fe0ddSCristian Dumitrescu file_name = tokens[7]; 1781598fe0ddSCristian Dumitrescu file = fopen(file_name, "r"); 1782598fe0ddSCristian Dumitrescu if (!file) { 1783598fe0ddSCristian Dumitrescu snprintf(out, out_size, "Cannot open file %s.\n", file_name); 1784598fe0ddSCristian Dumitrescu return; 1785598fe0ddSCristian Dumitrescu } 1786598fe0ddSCristian Dumitrescu 1787598fe0ddSCristian Dumitrescu status = pipeline_selector_group_members_delete(p->ctl, 1788598fe0ddSCristian Dumitrescu selector_name, 1789598fe0ddSCristian Dumitrescu file, 1790598fe0ddSCristian Dumitrescu &file_line_number); 1791598fe0ddSCristian Dumitrescu if (status) 1792598fe0ddSCristian Dumitrescu snprintf(out, out_size, "Invalid entry in file %s at line %u\n", 1793598fe0ddSCristian Dumitrescu file_name, 1794598fe0ddSCristian Dumitrescu file_line_number); 1795598fe0ddSCristian Dumitrescu 1796598fe0ddSCristian Dumitrescu fclose(file); 1797598fe0ddSCristian Dumitrescu } 1798598fe0ddSCristian Dumitrescu 1799598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_show_help[] = 1800598fe0ddSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> show\n"; 1801598fe0ddSCristian Dumitrescu 1802598fe0ddSCristian Dumitrescu static void 1803598fe0ddSCristian Dumitrescu cmd_pipeline_selector_show(char **tokens, 1804598fe0ddSCristian Dumitrescu uint32_t n_tokens, 1805598fe0ddSCristian Dumitrescu char *out, 1806598fe0ddSCristian Dumitrescu size_t out_size, 1807598fe0ddSCristian Dumitrescu void *obj) 1808598fe0ddSCristian Dumitrescu { 1809598fe0ddSCristian Dumitrescu struct pipeline *p; 1810598fe0ddSCristian Dumitrescu char *pipeline_name, *selector_name; 1811598fe0ddSCristian Dumitrescu int status; 1812598fe0ddSCristian Dumitrescu 1813598fe0ddSCristian Dumitrescu if (n_tokens != 5) { 1814598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 1815598fe0ddSCristian Dumitrescu return; 1816598fe0ddSCristian Dumitrescu } 1817598fe0ddSCristian Dumitrescu 1818598fe0ddSCristian Dumitrescu pipeline_name = tokens[1]; 1819598fe0ddSCristian Dumitrescu p = pipeline_find(obj, pipeline_name); 1820598fe0ddSCristian Dumitrescu if (!p || !p->ctl) { 1821598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 1822598fe0ddSCristian Dumitrescu return; 1823598fe0ddSCristian Dumitrescu } 1824598fe0ddSCristian Dumitrescu 1825598fe0ddSCristian Dumitrescu selector_name = tokens[3]; 1826598fe0ddSCristian Dumitrescu status = rte_swx_ctl_pipeline_selector_fprintf(stdout, 1827598fe0ddSCristian Dumitrescu p->ctl, selector_name); 1828598fe0ddSCristian Dumitrescu if (status) 1829598fe0ddSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "selector_name"); 1830598fe0ddSCristian Dumitrescu } 1831598fe0ddSCristian Dumitrescu 183275129cebSChurchill Khangar static const char cmd_pipeline_commit_help[] = 183375129cebSChurchill Khangar "pipeline <pipeline_name> commit\n"; 183475129cebSChurchill Khangar 183575129cebSChurchill Khangar static void 183675129cebSChurchill Khangar cmd_pipeline_commit(char **tokens, 183775129cebSChurchill Khangar uint32_t n_tokens, 183875129cebSChurchill Khangar char *out, 183975129cebSChurchill Khangar size_t out_size, 184075129cebSChurchill Khangar void *obj) 184175129cebSChurchill Khangar { 184275129cebSChurchill Khangar struct pipeline *p; 184375129cebSChurchill Khangar char *pipeline_name; 184475129cebSChurchill Khangar int status; 184575129cebSChurchill Khangar 184675129cebSChurchill Khangar if (n_tokens != 3) { 184775129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 184875129cebSChurchill Khangar return; 184975129cebSChurchill Khangar } 185075129cebSChurchill Khangar 185175129cebSChurchill Khangar pipeline_name = tokens[1]; 185275129cebSChurchill Khangar p = pipeline_find(obj, pipeline_name); 185375129cebSChurchill Khangar if (!p || !p->ctl) { 185475129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 185575129cebSChurchill Khangar return; 18565074e1d5SCristian Dumitrescu } 18575074e1d5SCristian Dumitrescu 18585074e1d5SCristian Dumitrescu status = rte_swx_ctl_pipeline_commit(p->ctl, 1); 185975129cebSChurchill Khangar if (status) 186075129cebSChurchill Khangar snprintf(out, out_size, "Commit failed. " 186175129cebSChurchill Khangar "Use \"commit\" to retry or \"abort\" to discard the pending work.\n"); 18625074e1d5SCristian Dumitrescu } 18635074e1d5SCristian Dumitrescu 186475129cebSChurchill Khangar static const char cmd_pipeline_abort_help[] = 186575129cebSChurchill Khangar "pipeline <pipeline_name> abort\n"; 18665074e1d5SCristian Dumitrescu 186775129cebSChurchill Khangar static void 186875129cebSChurchill Khangar cmd_pipeline_abort(char **tokens, 186975129cebSChurchill Khangar uint32_t n_tokens, 187075129cebSChurchill Khangar char *out, 187175129cebSChurchill Khangar size_t out_size, 187275129cebSChurchill Khangar void *obj) 187375129cebSChurchill Khangar { 187475129cebSChurchill Khangar struct pipeline *p; 187575129cebSChurchill Khangar char *pipeline_name; 18765074e1d5SCristian Dumitrescu 187775129cebSChurchill Khangar if (n_tokens != 3) { 187875129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 18795074e1d5SCristian Dumitrescu return; 188075129cebSChurchill Khangar } 18815074e1d5SCristian Dumitrescu 188275129cebSChurchill Khangar pipeline_name = tokens[1]; 188375129cebSChurchill Khangar p = pipeline_find(obj, pipeline_name); 188475129cebSChurchill Khangar if (!p || !p->ctl) { 188575129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 188675129cebSChurchill Khangar return; 188775129cebSChurchill Khangar } 188875129cebSChurchill Khangar 18895074e1d5SCristian Dumitrescu rte_swx_ctl_pipeline_abort(p->ctl); 18905074e1d5SCristian Dumitrescu } 18915074e1d5SCristian Dumitrescu 189264cfcebdSCristian Dumitrescu static const char cmd_pipeline_regrd_help[] = 189364cfcebdSCristian Dumitrescu "pipeline <pipeline_name> regrd <register_array_name> <index>\n"; 189464cfcebdSCristian Dumitrescu 189564cfcebdSCristian Dumitrescu static void 189664cfcebdSCristian Dumitrescu cmd_pipeline_regrd(char **tokens, 189764cfcebdSCristian Dumitrescu uint32_t n_tokens, 189864cfcebdSCristian Dumitrescu char *out, 189964cfcebdSCristian Dumitrescu size_t out_size, 190064cfcebdSCristian Dumitrescu void *obj) 190164cfcebdSCristian Dumitrescu { 190264cfcebdSCristian Dumitrescu struct pipeline *p; 190364cfcebdSCristian Dumitrescu const char *name; 190464cfcebdSCristian Dumitrescu uint64_t value; 190564cfcebdSCristian Dumitrescu uint32_t idx; 190664cfcebdSCristian Dumitrescu int status; 190764cfcebdSCristian Dumitrescu 190864cfcebdSCristian Dumitrescu if (n_tokens != 5) { 190964cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 191064cfcebdSCristian Dumitrescu return; 191164cfcebdSCristian Dumitrescu } 191264cfcebdSCristian Dumitrescu 191364cfcebdSCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 191464cfcebdSCristian Dumitrescu if (!p || !p->ctl) { 191564cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 191664cfcebdSCristian Dumitrescu return; 191764cfcebdSCristian Dumitrescu } 191864cfcebdSCristian Dumitrescu 191964cfcebdSCristian Dumitrescu if (strcmp(tokens[2], "regrd")) { 192064cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "regrd"); 192164cfcebdSCristian Dumitrescu return; 192264cfcebdSCristian Dumitrescu } 192364cfcebdSCristian Dumitrescu 192464cfcebdSCristian Dumitrescu name = tokens[3]; 192564cfcebdSCristian Dumitrescu 192664cfcebdSCristian Dumitrescu if (parser_read_uint32(&idx, tokens[4])) { 192764cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index"); 192864cfcebdSCristian Dumitrescu return; 192964cfcebdSCristian Dumitrescu } 193064cfcebdSCristian Dumitrescu 193164cfcebdSCristian Dumitrescu status = rte_swx_ctl_pipeline_regarray_read(p->p, name, idx, &value); 193264cfcebdSCristian Dumitrescu if (status) { 193364cfcebdSCristian Dumitrescu snprintf(out, out_size, "Command failed.\n"); 193464cfcebdSCristian Dumitrescu return; 193564cfcebdSCristian Dumitrescu } 193664cfcebdSCristian Dumitrescu 193764cfcebdSCristian Dumitrescu snprintf(out, out_size, "0x%" PRIx64 "\n", value); 193864cfcebdSCristian Dumitrescu } 193964cfcebdSCristian Dumitrescu 194064cfcebdSCristian Dumitrescu static const char cmd_pipeline_regwr_help[] = 194164cfcebdSCristian Dumitrescu "pipeline <pipeline_name> regwr <register_array_name> <index> <value>\n"; 194264cfcebdSCristian Dumitrescu 194364cfcebdSCristian Dumitrescu static void 194464cfcebdSCristian Dumitrescu cmd_pipeline_regwr(char **tokens, 194564cfcebdSCristian Dumitrescu uint32_t n_tokens, 194664cfcebdSCristian Dumitrescu char *out, 194764cfcebdSCristian Dumitrescu size_t out_size, 194864cfcebdSCristian Dumitrescu void *obj) 194964cfcebdSCristian Dumitrescu { 195064cfcebdSCristian Dumitrescu struct pipeline *p; 195164cfcebdSCristian Dumitrescu const char *name; 195264cfcebdSCristian Dumitrescu uint64_t value; 195364cfcebdSCristian Dumitrescu uint32_t idx; 195464cfcebdSCristian Dumitrescu int status; 195564cfcebdSCristian Dumitrescu 195664cfcebdSCristian Dumitrescu if (n_tokens != 6) { 195764cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 195864cfcebdSCristian Dumitrescu return; 195964cfcebdSCristian Dumitrescu } 196064cfcebdSCristian Dumitrescu 196164cfcebdSCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 196264cfcebdSCristian Dumitrescu if (!p || !p->ctl) { 196364cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 196464cfcebdSCristian Dumitrescu return; 196564cfcebdSCristian Dumitrescu } 196664cfcebdSCristian Dumitrescu 196764cfcebdSCristian Dumitrescu if (strcmp(tokens[2], "regwr")) { 196864cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "regwr"); 196964cfcebdSCristian Dumitrescu return; 197064cfcebdSCristian Dumitrescu } 197164cfcebdSCristian Dumitrescu 197264cfcebdSCristian Dumitrescu name = tokens[3]; 197364cfcebdSCristian Dumitrescu 197464cfcebdSCristian Dumitrescu if (parser_read_uint32(&idx, tokens[4])) { 197564cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index"); 197664cfcebdSCristian Dumitrescu return; 197764cfcebdSCristian Dumitrescu } 197864cfcebdSCristian Dumitrescu 197964cfcebdSCristian Dumitrescu if (parser_read_uint64(&value, tokens[5])) { 198064cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "value"); 198164cfcebdSCristian Dumitrescu return; 198264cfcebdSCristian Dumitrescu } 198364cfcebdSCristian Dumitrescu 198464cfcebdSCristian Dumitrescu status = rte_swx_ctl_pipeline_regarray_write(p->p, name, idx, value); 198564cfcebdSCristian Dumitrescu if (status) { 198664cfcebdSCristian Dumitrescu snprintf(out, out_size, "Command failed.\n"); 198764cfcebdSCristian Dumitrescu return; 198864cfcebdSCristian Dumitrescu } 198964cfcebdSCristian Dumitrescu } 199064cfcebdSCristian Dumitrescu 1991f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_profile_add_help[] = 1992f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter profile <profile_name> add " 1993f38913b7SCristian Dumitrescu "cir <cir> pir <pir> cbs <cbs> pbs <pbs>\n"; 1994f38913b7SCristian Dumitrescu 1995f38913b7SCristian Dumitrescu static void 1996f38913b7SCristian Dumitrescu cmd_pipeline_meter_profile_add(char **tokens, 1997f38913b7SCristian Dumitrescu uint32_t n_tokens, 1998f38913b7SCristian Dumitrescu char *out, 1999f38913b7SCristian Dumitrescu size_t out_size, 2000f38913b7SCristian Dumitrescu void *obj) 2001f38913b7SCristian Dumitrescu { 2002f38913b7SCristian Dumitrescu struct rte_meter_trtcm_params params; 2003f38913b7SCristian Dumitrescu struct pipeline *p; 2004f38913b7SCristian Dumitrescu const char *profile_name; 2005f38913b7SCristian Dumitrescu int status; 2006f38913b7SCristian Dumitrescu 2007f38913b7SCristian Dumitrescu if (n_tokens != 14) { 2008f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 2009f38913b7SCristian Dumitrescu return; 2010f38913b7SCristian Dumitrescu } 2011f38913b7SCristian Dumitrescu 2012f38913b7SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 2013f38913b7SCristian Dumitrescu if (!p || !p->ctl) { 2014f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 2015f38913b7SCristian Dumitrescu return; 2016f38913b7SCristian Dumitrescu } 2017f38913b7SCristian Dumitrescu 2018f38913b7SCristian Dumitrescu if (strcmp(tokens[2], "meter")) { 2019f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter"); 2020f38913b7SCristian Dumitrescu return; 2021f38913b7SCristian Dumitrescu } 2022f38913b7SCristian Dumitrescu 2023f38913b7SCristian Dumitrescu if (strcmp(tokens[3], "profile")) { 2024f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile"); 2025f38913b7SCristian Dumitrescu return; 2026f38913b7SCristian Dumitrescu } 2027f38913b7SCristian Dumitrescu 2028f38913b7SCristian Dumitrescu profile_name = tokens[4]; 2029f38913b7SCristian Dumitrescu 2030f38913b7SCristian Dumitrescu if (strcmp(tokens[5], "add")) { 2031f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add"); 2032f38913b7SCristian Dumitrescu return; 2033f38913b7SCristian Dumitrescu } 2034f38913b7SCristian Dumitrescu 2035f38913b7SCristian Dumitrescu if (strcmp(tokens[6], "cir")) { 2036f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir"); 2037f38913b7SCristian Dumitrescu return; 2038f38913b7SCristian Dumitrescu } 2039f38913b7SCristian Dumitrescu 2040f38913b7SCristian Dumitrescu if (parser_read_uint64(¶ms.cir, tokens[7])) { 2041f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "cir"); 2042f38913b7SCristian Dumitrescu return; 2043f38913b7SCristian Dumitrescu } 2044f38913b7SCristian Dumitrescu 2045f38913b7SCristian Dumitrescu if (strcmp(tokens[8], "pir")) { 2046f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir"); 2047f38913b7SCristian Dumitrescu return; 2048f38913b7SCristian Dumitrescu } 2049f38913b7SCristian Dumitrescu 2050f38913b7SCristian Dumitrescu if (parser_read_uint64(¶ms.pir, tokens[9])) { 2051f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pir"); 2052f38913b7SCristian Dumitrescu return; 2053f38913b7SCristian Dumitrescu } 2054f38913b7SCristian Dumitrescu 2055f38913b7SCristian Dumitrescu if (strcmp(tokens[10], "cbs")) { 2056f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs"); 2057f38913b7SCristian Dumitrescu return; 2058f38913b7SCristian Dumitrescu } 2059f38913b7SCristian Dumitrescu 2060f38913b7SCristian Dumitrescu if (parser_read_uint64(¶ms.cbs, tokens[11])) { 2061f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "cbs"); 2062f38913b7SCristian Dumitrescu return; 2063f38913b7SCristian Dumitrescu } 2064f38913b7SCristian Dumitrescu 2065f38913b7SCristian Dumitrescu if (strcmp(tokens[12], "pbs")) { 2066f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs"); 2067f38913b7SCristian Dumitrescu return; 2068f38913b7SCristian Dumitrescu } 2069f38913b7SCristian Dumitrescu 2070f38913b7SCristian Dumitrescu if (parser_read_uint64(¶ms.pbs, tokens[13])) { 2071f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pbs"); 2072f38913b7SCristian Dumitrescu return; 2073f38913b7SCristian Dumitrescu } 2074f38913b7SCristian Dumitrescu 2075f38913b7SCristian Dumitrescu status = rte_swx_ctl_meter_profile_add(p->p, profile_name, ¶ms); 2076f38913b7SCristian Dumitrescu if (status) { 2077f38913b7SCristian Dumitrescu snprintf(out, out_size, "Command failed.\n"); 2078f38913b7SCristian Dumitrescu return; 2079f38913b7SCristian Dumitrescu } 2080f38913b7SCristian Dumitrescu } 2081f38913b7SCristian Dumitrescu 2082f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_profile_delete_help[] = 2083f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter profile <profile_name> delete\n"; 2084f38913b7SCristian Dumitrescu 2085f38913b7SCristian Dumitrescu static void 2086f38913b7SCristian Dumitrescu cmd_pipeline_meter_profile_delete(char **tokens, 2087f38913b7SCristian Dumitrescu uint32_t n_tokens, 2088f38913b7SCristian Dumitrescu char *out, 2089f38913b7SCristian Dumitrescu size_t out_size, 2090f38913b7SCristian Dumitrescu void *obj) 2091f38913b7SCristian Dumitrescu { 2092f38913b7SCristian Dumitrescu struct pipeline *p; 2093f38913b7SCristian Dumitrescu const char *profile_name; 2094f38913b7SCristian Dumitrescu int status; 2095f38913b7SCristian Dumitrescu 2096f38913b7SCristian Dumitrescu if (n_tokens != 6) { 2097f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 2098f38913b7SCristian Dumitrescu return; 2099f38913b7SCristian Dumitrescu } 2100f38913b7SCristian Dumitrescu 2101f38913b7SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 2102f38913b7SCristian Dumitrescu if (!p || !p->ctl) { 2103f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 2104f38913b7SCristian Dumitrescu return; 2105f38913b7SCristian Dumitrescu } 2106f38913b7SCristian Dumitrescu 2107f38913b7SCristian Dumitrescu if (strcmp(tokens[2], "meter")) { 2108f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter"); 2109f38913b7SCristian Dumitrescu return; 2110f38913b7SCristian Dumitrescu } 2111f38913b7SCristian Dumitrescu 2112f38913b7SCristian Dumitrescu if (strcmp(tokens[3], "profile")) { 2113f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile"); 2114f38913b7SCristian Dumitrescu return; 2115f38913b7SCristian Dumitrescu } 2116f38913b7SCristian Dumitrescu 2117f38913b7SCristian Dumitrescu profile_name = tokens[4]; 2118f38913b7SCristian Dumitrescu 2119f38913b7SCristian Dumitrescu if (strcmp(tokens[5], "delete")) { 2120f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete"); 2121f38913b7SCristian Dumitrescu return; 2122f38913b7SCristian Dumitrescu } 2123f38913b7SCristian Dumitrescu 2124f38913b7SCristian Dumitrescu status = rte_swx_ctl_meter_profile_delete(p->p, profile_name); 2125f38913b7SCristian Dumitrescu if (status) { 2126f38913b7SCristian Dumitrescu snprintf(out, out_size, "Command failed.\n"); 2127f38913b7SCristian Dumitrescu return; 2128f38913b7SCristian Dumitrescu } 2129f38913b7SCristian Dumitrescu } 2130f38913b7SCristian Dumitrescu 2131f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_reset_help[] = 2132f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> " 2133f38913b7SCristian Dumitrescu "reset\n"; 2134f38913b7SCristian Dumitrescu 2135f38913b7SCristian Dumitrescu static void 2136f38913b7SCristian Dumitrescu cmd_pipeline_meter_reset(char **tokens, 2137f38913b7SCristian Dumitrescu uint32_t n_tokens, 2138f38913b7SCristian Dumitrescu char *out, 2139f38913b7SCristian Dumitrescu size_t out_size, 2140f38913b7SCristian Dumitrescu void *obj) 2141f38913b7SCristian Dumitrescu { 2142f38913b7SCristian Dumitrescu struct pipeline *p; 2143f38913b7SCristian Dumitrescu const char *name; 214400b67591SAli Alnubani uint32_t idx0 = 0, idx1 = 0; 2145f38913b7SCristian Dumitrescu 2146f38913b7SCristian Dumitrescu if (n_tokens != 9) { 2147f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 2148f38913b7SCristian Dumitrescu return; 2149f38913b7SCristian Dumitrescu } 2150f38913b7SCristian Dumitrescu 2151f38913b7SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 2152f38913b7SCristian Dumitrescu if (!p || !p->ctl) { 2153f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 2154f38913b7SCristian Dumitrescu return; 2155f38913b7SCristian Dumitrescu } 2156f38913b7SCristian Dumitrescu 2157f38913b7SCristian Dumitrescu if (strcmp(tokens[2], "meter")) { 2158f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter"); 2159f38913b7SCristian Dumitrescu return; 2160f38913b7SCristian Dumitrescu } 2161f38913b7SCristian Dumitrescu 2162f38913b7SCristian Dumitrescu name = tokens[3]; 2163f38913b7SCristian Dumitrescu 2164f38913b7SCristian Dumitrescu if (strcmp(tokens[4], "from")) { 2165f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from"); 2166f38913b7SCristian Dumitrescu return; 2167f38913b7SCristian Dumitrescu } 2168f38913b7SCristian Dumitrescu 2169f38913b7SCristian Dumitrescu if (parser_read_uint32(&idx0, tokens[5])) { 2170f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index0"); 2171f38913b7SCristian Dumitrescu return; 2172f38913b7SCristian Dumitrescu } 2173f38913b7SCristian Dumitrescu 2174f38913b7SCristian Dumitrescu if (strcmp(tokens[6], "to")) { 2175f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to"); 2176f38913b7SCristian Dumitrescu return; 2177f38913b7SCristian Dumitrescu } 2178f38913b7SCristian Dumitrescu 2179f38913b7SCristian Dumitrescu if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) { 2180f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index1"); 2181f38913b7SCristian Dumitrescu return; 2182f38913b7SCristian Dumitrescu } 2183f38913b7SCristian Dumitrescu 2184f38913b7SCristian Dumitrescu if (strcmp(tokens[8], "reset")) { 2185f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "reset"); 2186f38913b7SCristian Dumitrescu return; 2187f38913b7SCristian Dumitrescu } 2188f38913b7SCristian Dumitrescu 2189f38913b7SCristian Dumitrescu for ( ; idx0 <= idx1; idx0++) { 2190f38913b7SCristian Dumitrescu int status; 2191f38913b7SCristian Dumitrescu 2192f38913b7SCristian Dumitrescu status = rte_swx_ctl_meter_reset(p->p, name, idx0); 2193f38913b7SCristian Dumitrescu if (status) { 2194f38913b7SCristian Dumitrescu snprintf(out, out_size, "Command failed for index %u.\n", idx0); 2195f38913b7SCristian Dumitrescu return; 2196f38913b7SCristian Dumitrescu } 2197f38913b7SCristian Dumitrescu } 2198f38913b7SCristian Dumitrescu } 2199f38913b7SCristian Dumitrescu 2200f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_set_help[] = 2201f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> " 2202f38913b7SCristian Dumitrescu "set profile <profile_name>\n"; 2203f38913b7SCristian Dumitrescu 2204f38913b7SCristian Dumitrescu static void 2205f38913b7SCristian Dumitrescu cmd_pipeline_meter_set(char **tokens, 2206f38913b7SCristian Dumitrescu uint32_t n_tokens, 2207f38913b7SCristian Dumitrescu char *out, 2208f38913b7SCristian Dumitrescu size_t out_size, 2209f38913b7SCristian Dumitrescu void *obj) 2210f38913b7SCristian Dumitrescu { 2211f38913b7SCristian Dumitrescu struct pipeline *p; 2212f38913b7SCristian Dumitrescu const char *name, *profile_name; 221300b67591SAli Alnubani uint32_t idx0 = 0, idx1 = 0; 2214f38913b7SCristian Dumitrescu 2215f38913b7SCristian Dumitrescu if (n_tokens != 11) { 2216f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 2217f38913b7SCristian Dumitrescu return; 2218f38913b7SCristian Dumitrescu } 2219f38913b7SCristian Dumitrescu 2220f38913b7SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 2221f38913b7SCristian Dumitrescu if (!p || !p->ctl) { 2222f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 2223f38913b7SCristian Dumitrescu return; 2224f38913b7SCristian Dumitrescu } 2225f38913b7SCristian Dumitrescu 2226f38913b7SCristian Dumitrescu if (strcmp(tokens[2], "meter")) { 2227f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter"); 2228f38913b7SCristian Dumitrescu return; 2229f38913b7SCristian Dumitrescu } 2230f38913b7SCristian Dumitrescu 2231f38913b7SCristian Dumitrescu name = tokens[3]; 2232f38913b7SCristian Dumitrescu 2233f38913b7SCristian Dumitrescu if (strcmp(tokens[4], "from")) { 2234f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from"); 2235f38913b7SCristian Dumitrescu return; 2236f38913b7SCristian Dumitrescu } 2237f38913b7SCristian Dumitrescu 2238f38913b7SCristian Dumitrescu if (parser_read_uint32(&idx0, tokens[5])) { 2239f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index0"); 2240f38913b7SCristian Dumitrescu return; 2241f38913b7SCristian Dumitrescu } 2242f38913b7SCristian Dumitrescu 2243f38913b7SCristian Dumitrescu if (strcmp(tokens[6], "to")) { 2244f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to"); 2245f38913b7SCristian Dumitrescu return; 2246f38913b7SCristian Dumitrescu } 2247f38913b7SCristian Dumitrescu 2248f38913b7SCristian Dumitrescu if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) { 2249f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index1"); 2250f38913b7SCristian Dumitrescu return; 2251f38913b7SCristian Dumitrescu } 2252f38913b7SCristian Dumitrescu 2253f38913b7SCristian Dumitrescu if (strcmp(tokens[8], "set")) { 2254f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "set"); 2255f38913b7SCristian Dumitrescu return; 2256f38913b7SCristian Dumitrescu } 2257f38913b7SCristian Dumitrescu 2258f38913b7SCristian Dumitrescu if (strcmp(tokens[9], "profile")) { 2259f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile"); 2260f38913b7SCristian Dumitrescu return; 2261f38913b7SCristian Dumitrescu } 2262f38913b7SCristian Dumitrescu 2263f38913b7SCristian Dumitrescu profile_name = tokens[10]; 2264f38913b7SCristian Dumitrescu 2265f38913b7SCristian Dumitrescu for ( ; idx0 <= idx1; idx0++) { 2266f38913b7SCristian Dumitrescu int status; 2267f38913b7SCristian Dumitrescu 2268f38913b7SCristian Dumitrescu status = rte_swx_ctl_meter_set(p->p, name, idx0, profile_name); 2269f38913b7SCristian Dumitrescu if (status) { 2270f38913b7SCristian Dumitrescu snprintf(out, out_size, "Command failed for index %u.\n", idx0); 2271f38913b7SCristian Dumitrescu return; 2272f38913b7SCristian Dumitrescu } 2273f38913b7SCristian Dumitrescu } 2274f38913b7SCristian Dumitrescu } 2275f38913b7SCristian Dumitrescu 2276f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_stats_help[] = 2277f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> " 2278f38913b7SCristian Dumitrescu "stats\n"; 2279f38913b7SCristian Dumitrescu 2280f38913b7SCristian Dumitrescu static void 2281f38913b7SCristian Dumitrescu cmd_pipeline_meter_stats(char **tokens, 2282f38913b7SCristian Dumitrescu uint32_t n_tokens, 2283f38913b7SCristian Dumitrescu char *out, 2284f38913b7SCristian Dumitrescu size_t out_size, 2285f38913b7SCristian Dumitrescu void *obj) 2286f38913b7SCristian Dumitrescu { 2287f38913b7SCristian Dumitrescu struct rte_swx_ctl_meter_stats stats; 2288f38913b7SCristian Dumitrescu struct pipeline *p; 2289f38913b7SCristian Dumitrescu const char *name; 229000b67591SAli Alnubani uint32_t idx0 = 0, idx1 = 0; 2291f38913b7SCristian Dumitrescu 2292f38913b7SCristian Dumitrescu if (n_tokens != 9) { 2293f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 2294f38913b7SCristian Dumitrescu return; 2295f38913b7SCristian Dumitrescu } 2296f38913b7SCristian Dumitrescu 2297f38913b7SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 2298f38913b7SCristian Dumitrescu if (!p || !p->ctl) { 2299f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 2300f38913b7SCristian Dumitrescu return; 2301f38913b7SCristian Dumitrescu } 2302f38913b7SCristian Dumitrescu 2303f38913b7SCristian Dumitrescu if (strcmp(tokens[2], "meter")) { 2304f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter"); 2305f38913b7SCristian Dumitrescu return; 2306f38913b7SCristian Dumitrescu } 2307f38913b7SCristian Dumitrescu 2308f38913b7SCristian Dumitrescu name = tokens[3]; 2309f38913b7SCristian Dumitrescu 2310f38913b7SCristian Dumitrescu if (strcmp(tokens[4], "from")) { 2311f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from"); 2312f38913b7SCristian Dumitrescu return; 2313f38913b7SCristian Dumitrescu } 2314f38913b7SCristian Dumitrescu 2315f38913b7SCristian Dumitrescu if (parser_read_uint32(&idx0, tokens[5])) { 2316f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index0"); 2317f38913b7SCristian Dumitrescu return; 2318f38913b7SCristian Dumitrescu } 2319f38913b7SCristian Dumitrescu 2320f38913b7SCristian Dumitrescu if (strcmp(tokens[6], "to")) { 2321f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to"); 2322f38913b7SCristian Dumitrescu return; 2323f38913b7SCristian Dumitrescu } 2324f38913b7SCristian Dumitrescu 2325f38913b7SCristian Dumitrescu if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) { 2326f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index1"); 2327f38913b7SCristian Dumitrescu return; 2328f38913b7SCristian Dumitrescu } 2329f38913b7SCristian Dumitrescu 2330f38913b7SCristian Dumitrescu if (strcmp(tokens[8], "stats")) { 2331f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats"); 2332f38913b7SCristian Dumitrescu return; 2333f38913b7SCristian Dumitrescu } 2334f38913b7SCristian Dumitrescu 2335f38913b7SCristian Dumitrescu /* Table header. */ 2336f38913b7SCristian Dumitrescu snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n", 2337f38913b7SCristian Dumitrescu "-------", 2338f38913b7SCristian Dumitrescu "----------------", "----------------", "----------------", 2339f38913b7SCristian Dumitrescu "----------------", "----------------", "----------------"); 2340f38913b7SCristian Dumitrescu out_size -= strlen(out); 2341f38913b7SCristian Dumitrescu out += strlen(out); 2342f38913b7SCristian Dumitrescu 2343f38913b7SCristian Dumitrescu snprintf(out, out_size, "| %4s | %16s | %16s | %16s | %16s | %16s | %16s |\n", 2344f38913b7SCristian Dumitrescu "METER #", 2345f38913b7SCristian Dumitrescu "GREEN (packets)", "YELLOW (packets)", "RED (packets)", 2346f38913b7SCristian Dumitrescu "GREEN (bytes)", "YELLOW (bytes)", "RED (bytes)"); 2347f38913b7SCristian Dumitrescu out_size -= strlen(out); 2348f38913b7SCristian Dumitrescu out += strlen(out); 2349f38913b7SCristian Dumitrescu 2350f38913b7SCristian Dumitrescu snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n", 2351f38913b7SCristian Dumitrescu "-------", 2352f38913b7SCristian Dumitrescu "----------------", "----------------", "----------------", 2353f38913b7SCristian Dumitrescu "----------------", "----------------", "----------------"); 2354f38913b7SCristian Dumitrescu out_size -= strlen(out); 2355f38913b7SCristian Dumitrescu out += strlen(out); 2356f38913b7SCristian Dumitrescu 2357f38913b7SCristian Dumitrescu /* Table rows. */ 2358f38913b7SCristian Dumitrescu for ( ; idx0 <= idx1; idx0++) { 2359f38913b7SCristian Dumitrescu int status; 2360f38913b7SCristian Dumitrescu 2361f38913b7SCristian Dumitrescu status = rte_swx_ctl_meter_stats_read(p->p, name, idx0, &stats); 2362f38913b7SCristian Dumitrescu if (status) { 2363f38913b7SCristian Dumitrescu snprintf(out, out_size, "Pipeline meter stats error at index %u.\n", idx0); 2364f38913b7SCristian Dumitrescu out_size -= strlen(out); 2365f38913b7SCristian Dumitrescu out += strlen(out); 2366f38913b7SCristian Dumitrescu return; 2367f38913b7SCristian Dumitrescu } 2368f38913b7SCristian Dumitrescu 2369f38913b7SCristian Dumitrescu snprintf(out, out_size, "| %7d | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 2370f38913b7SCristian Dumitrescu " | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 " |\n", 2371f38913b7SCristian Dumitrescu idx0, 2372f38913b7SCristian Dumitrescu stats.n_pkts[RTE_COLOR_GREEN], 2373f38913b7SCristian Dumitrescu stats.n_pkts[RTE_COLOR_YELLOW], 2374f38913b7SCristian Dumitrescu stats.n_pkts[RTE_COLOR_RED], 2375f38913b7SCristian Dumitrescu stats.n_bytes[RTE_COLOR_GREEN], 2376f38913b7SCristian Dumitrescu stats.n_bytes[RTE_COLOR_YELLOW], 2377f38913b7SCristian Dumitrescu stats.n_bytes[RTE_COLOR_RED]); 2378f38913b7SCristian Dumitrescu out_size -= strlen(out); 2379f38913b7SCristian Dumitrescu out += strlen(out); 2380f38913b7SCristian Dumitrescu } 2381f38913b7SCristian Dumitrescu } 2382f38913b7SCristian Dumitrescu 23835074e1d5SCristian Dumitrescu static const char cmd_pipeline_stats_help[] = 23845074e1d5SCristian Dumitrescu "pipeline <pipeline_name> stats\n"; 23855074e1d5SCristian Dumitrescu 23865074e1d5SCristian Dumitrescu static void 23875074e1d5SCristian Dumitrescu cmd_pipeline_stats(char **tokens, 23885074e1d5SCristian Dumitrescu uint32_t n_tokens, 23895074e1d5SCristian Dumitrescu char *out, 23905074e1d5SCristian Dumitrescu size_t out_size, 23915074e1d5SCristian Dumitrescu void *obj) 23925074e1d5SCristian Dumitrescu { 23935074e1d5SCristian Dumitrescu struct rte_swx_ctl_pipeline_info info; 23945074e1d5SCristian Dumitrescu struct pipeline *p; 23955074e1d5SCristian Dumitrescu uint32_t i; 23965074e1d5SCristian Dumitrescu int status; 23975074e1d5SCristian Dumitrescu 23985074e1d5SCristian Dumitrescu if (n_tokens != 3) { 23995074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 24005074e1d5SCristian Dumitrescu return; 24015074e1d5SCristian Dumitrescu } 24025074e1d5SCristian Dumitrescu 24035074e1d5SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 24045074e1d5SCristian Dumitrescu if (!p || !p->ctl) { 24055074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 24065074e1d5SCristian Dumitrescu return; 24075074e1d5SCristian Dumitrescu } 24085074e1d5SCristian Dumitrescu 24095074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "stats")) { 24105074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats"); 24115074e1d5SCristian Dumitrescu return; 24125074e1d5SCristian Dumitrescu } 24135074e1d5SCristian Dumitrescu 24145074e1d5SCristian Dumitrescu status = rte_swx_ctl_pipeline_info_get(p->p, &info); 24155074e1d5SCristian Dumitrescu if (status) { 24165074e1d5SCristian Dumitrescu snprintf(out, out_size, "Pipeline info get error."); 24175074e1d5SCristian Dumitrescu return; 24185074e1d5SCristian Dumitrescu } 24195074e1d5SCristian Dumitrescu 24205074e1d5SCristian Dumitrescu snprintf(out, out_size, "Input ports:\n"); 24215074e1d5SCristian Dumitrescu out_size -= strlen(out); 24225074e1d5SCristian Dumitrescu out += strlen(out); 24235074e1d5SCristian Dumitrescu 24245074e1d5SCristian Dumitrescu for (i = 0; i < info.n_ports_in; i++) { 24255074e1d5SCristian Dumitrescu struct rte_swx_port_in_stats stats; 24265074e1d5SCristian Dumitrescu 24275074e1d5SCristian Dumitrescu rte_swx_ctl_pipeline_port_in_stats_read(p->p, i, &stats); 24285074e1d5SCristian Dumitrescu 24295074e1d5SCristian Dumitrescu snprintf(out, out_size, "\tPort %u:" 24305074e1d5SCristian Dumitrescu " packets %" PRIu64 24315074e1d5SCristian Dumitrescu " bytes %" PRIu64 24325074e1d5SCristian Dumitrescu " empty %" PRIu64 "\n", 24335074e1d5SCristian Dumitrescu i, stats.n_pkts, stats.n_bytes, stats.n_empty); 24345074e1d5SCristian Dumitrescu out_size -= strlen(out); 24355074e1d5SCristian Dumitrescu out += strlen(out); 24365074e1d5SCristian Dumitrescu } 24375074e1d5SCristian Dumitrescu 2438742b0a57SCristian Dumitrescu snprintf(out, out_size, "\nOutput ports:\n"); 24395074e1d5SCristian Dumitrescu out_size -= strlen(out); 24405074e1d5SCristian Dumitrescu out += strlen(out); 24415074e1d5SCristian Dumitrescu 24425074e1d5SCristian Dumitrescu for (i = 0; i < info.n_ports_out; i++) { 24435074e1d5SCristian Dumitrescu struct rte_swx_port_out_stats stats; 24445074e1d5SCristian Dumitrescu 24455074e1d5SCristian Dumitrescu rte_swx_ctl_pipeline_port_out_stats_read(p->p, i, &stats); 24465074e1d5SCristian Dumitrescu 24475074e1d5SCristian Dumitrescu snprintf(out, out_size, "\tPort %u:" 24485074e1d5SCristian Dumitrescu " packets %" PRIu64 24495074e1d5SCristian Dumitrescu " bytes %" PRIu64 "\n", 24505074e1d5SCristian Dumitrescu i, stats.n_pkts, stats.n_bytes); 24515074e1d5SCristian Dumitrescu out_size -= strlen(out); 24525074e1d5SCristian Dumitrescu out += strlen(out); 24535074e1d5SCristian Dumitrescu } 2454742b0a57SCristian Dumitrescu 2455742b0a57SCristian Dumitrescu snprintf(out, out_size, "\nTables:\n"); 2456742b0a57SCristian Dumitrescu out_size -= strlen(out); 2457742b0a57SCristian Dumitrescu out += strlen(out); 2458742b0a57SCristian Dumitrescu 2459742b0a57SCristian Dumitrescu for (i = 0; i < info.n_tables; i++) { 2460742b0a57SCristian Dumitrescu struct rte_swx_ctl_table_info table_info; 2461742b0a57SCristian Dumitrescu uint64_t n_pkts_action[info.n_actions]; 2462742b0a57SCristian Dumitrescu struct rte_swx_table_stats stats = { 2463742b0a57SCristian Dumitrescu .n_pkts_hit = 0, 2464742b0a57SCristian Dumitrescu .n_pkts_miss = 0, 2465742b0a57SCristian Dumitrescu .n_pkts_action = n_pkts_action, 2466742b0a57SCristian Dumitrescu }; 2467742b0a57SCristian Dumitrescu uint32_t j; 2468742b0a57SCristian Dumitrescu 2469742b0a57SCristian Dumitrescu status = rte_swx_ctl_table_info_get(p->p, i, &table_info); 2470742b0a57SCristian Dumitrescu if (status) { 2471742b0a57SCristian Dumitrescu snprintf(out, out_size, "Table info get error."); 2472742b0a57SCristian Dumitrescu return; 2473742b0a57SCristian Dumitrescu } 2474742b0a57SCristian Dumitrescu 2475742b0a57SCristian Dumitrescu status = rte_swx_ctl_pipeline_table_stats_read(p->p, table_info.name, &stats); 2476742b0a57SCristian Dumitrescu if (status) { 2477742b0a57SCristian Dumitrescu snprintf(out, out_size, "Table stats read error."); 2478742b0a57SCristian Dumitrescu return; 2479742b0a57SCristian Dumitrescu } 2480742b0a57SCristian Dumitrescu 2481742b0a57SCristian Dumitrescu snprintf(out, out_size, "\tTable %s:\n" 2482742b0a57SCristian Dumitrescu "\t\tHit (packets): %" PRIu64 "\n" 2483742b0a57SCristian Dumitrescu "\t\tMiss (packets): %" PRIu64 "\n", 2484742b0a57SCristian Dumitrescu table_info.name, 2485742b0a57SCristian Dumitrescu stats.n_pkts_hit, 2486742b0a57SCristian Dumitrescu stats.n_pkts_miss); 2487742b0a57SCristian Dumitrescu out_size -= strlen(out); 2488742b0a57SCristian Dumitrescu out += strlen(out); 2489742b0a57SCristian Dumitrescu 2490742b0a57SCristian Dumitrescu for (j = 0; j < info.n_actions; j++) { 2491742b0a57SCristian Dumitrescu struct rte_swx_ctl_action_info action_info; 2492742b0a57SCristian Dumitrescu 2493742b0a57SCristian Dumitrescu status = rte_swx_ctl_action_info_get(p->p, j, &action_info); 2494742b0a57SCristian Dumitrescu if (status) { 2495742b0a57SCristian Dumitrescu snprintf(out, out_size, "Action info get error."); 2496742b0a57SCristian Dumitrescu return; 2497742b0a57SCristian Dumitrescu } 2498742b0a57SCristian Dumitrescu 2499742b0a57SCristian Dumitrescu snprintf(out, out_size, "\t\tAction %s (packets): %" PRIu64 "\n", 2500742b0a57SCristian Dumitrescu action_info.name, 2501742b0a57SCristian Dumitrescu stats.n_pkts_action[j]); 2502742b0a57SCristian Dumitrescu out_size -= strlen(out); 2503742b0a57SCristian Dumitrescu out += strlen(out); 2504742b0a57SCristian Dumitrescu } 2505742b0a57SCristian Dumitrescu } 25065074e1d5SCristian Dumitrescu } 25075074e1d5SCristian Dumitrescu 25085074e1d5SCristian Dumitrescu static const char cmd_thread_pipeline_enable_help[] = 25095074e1d5SCristian Dumitrescu "thread <thread_id> pipeline <pipeline_name> enable\n"; 25105074e1d5SCristian Dumitrescu 25115074e1d5SCristian Dumitrescu static void 25125074e1d5SCristian Dumitrescu cmd_thread_pipeline_enable(char **tokens, 25135074e1d5SCristian Dumitrescu uint32_t n_tokens, 25145074e1d5SCristian Dumitrescu char *out, 25155074e1d5SCristian Dumitrescu size_t out_size, 25165074e1d5SCristian Dumitrescu void *obj) 25175074e1d5SCristian Dumitrescu { 25185074e1d5SCristian Dumitrescu char *pipeline_name; 25195074e1d5SCristian Dumitrescu struct pipeline *p; 25205074e1d5SCristian Dumitrescu uint32_t thread_id; 25215074e1d5SCristian Dumitrescu int status; 25225074e1d5SCristian Dumitrescu 25235074e1d5SCristian Dumitrescu if (n_tokens != 5) { 25245074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 25255074e1d5SCristian Dumitrescu return; 25265074e1d5SCristian Dumitrescu } 25275074e1d5SCristian Dumitrescu 25285074e1d5SCristian Dumitrescu if (parser_read_uint32(&thread_id, tokens[1]) != 0) { 25295074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "thread_id"); 25305074e1d5SCristian Dumitrescu return; 25315074e1d5SCristian Dumitrescu } 25325074e1d5SCristian Dumitrescu 25335074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "pipeline") != 0) { 25345074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline"); 25355074e1d5SCristian Dumitrescu return; 25365074e1d5SCristian Dumitrescu } 25375074e1d5SCristian Dumitrescu 25385074e1d5SCristian Dumitrescu pipeline_name = tokens[3]; 25395074e1d5SCristian Dumitrescu p = pipeline_find(obj, pipeline_name); 25405074e1d5SCristian Dumitrescu if (!p || !p->ctl) { 25415074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 25425074e1d5SCristian Dumitrescu return; 25435074e1d5SCristian Dumitrescu } 25445074e1d5SCristian Dumitrescu 25455074e1d5SCristian Dumitrescu if (strcmp(tokens[4], "enable") != 0) { 25465074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable"); 25475074e1d5SCristian Dumitrescu return; 25485074e1d5SCristian Dumitrescu } 25495074e1d5SCristian Dumitrescu 25505074e1d5SCristian Dumitrescu status = thread_pipeline_enable(thread_id, obj, pipeline_name); 25515074e1d5SCristian Dumitrescu if (status) { 25525074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable"); 25535074e1d5SCristian Dumitrescu return; 25545074e1d5SCristian Dumitrescu } 25555074e1d5SCristian Dumitrescu } 25565074e1d5SCristian Dumitrescu 25575074e1d5SCristian Dumitrescu static const char cmd_thread_pipeline_disable_help[] = 25585074e1d5SCristian Dumitrescu "thread <thread_id> pipeline <pipeline_name> disable\n"; 25595074e1d5SCristian Dumitrescu 25605074e1d5SCristian Dumitrescu static void 25615074e1d5SCristian Dumitrescu cmd_thread_pipeline_disable(char **tokens, 25625074e1d5SCristian Dumitrescu uint32_t n_tokens, 25635074e1d5SCristian Dumitrescu char *out, 25645074e1d5SCristian Dumitrescu size_t out_size, 25655074e1d5SCristian Dumitrescu void *obj) 25665074e1d5SCristian Dumitrescu { 25675074e1d5SCristian Dumitrescu struct pipeline *p; 25685074e1d5SCristian Dumitrescu char *pipeline_name; 25695074e1d5SCristian Dumitrescu uint32_t thread_id; 25705074e1d5SCristian Dumitrescu int status; 25715074e1d5SCristian Dumitrescu 25725074e1d5SCristian Dumitrescu if (n_tokens != 5) { 25735074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 25745074e1d5SCristian Dumitrescu return; 25755074e1d5SCristian Dumitrescu } 25765074e1d5SCristian Dumitrescu 25775074e1d5SCristian Dumitrescu if (parser_read_uint32(&thread_id, tokens[1]) != 0) { 25785074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "thread_id"); 25795074e1d5SCristian Dumitrescu return; 25805074e1d5SCristian Dumitrescu } 25815074e1d5SCristian Dumitrescu 25825074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "pipeline") != 0) { 25835074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline"); 25845074e1d5SCristian Dumitrescu return; 25855074e1d5SCristian Dumitrescu } 25865074e1d5SCristian Dumitrescu 25875074e1d5SCristian Dumitrescu pipeline_name = tokens[3]; 25885074e1d5SCristian Dumitrescu p = pipeline_find(obj, pipeline_name); 25895074e1d5SCristian Dumitrescu if (!p || !p->ctl) { 25905074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 25915074e1d5SCristian Dumitrescu return; 25925074e1d5SCristian Dumitrescu } 25935074e1d5SCristian Dumitrescu 25945074e1d5SCristian Dumitrescu if (strcmp(tokens[4], "disable") != 0) { 25955074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable"); 25965074e1d5SCristian Dumitrescu return; 25975074e1d5SCristian Dumitrescu } 25985074e1d5SCristian Dumitrescu 25995074e1d5SCristian Dumitrescu status = thread_pipeline_disable(thread_id, obj, pipeline_name); 26005074e1d5SCristian Dumitrescu if (status) { 26015074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, 26025074e1d5SCristian Dumitrescu "thread pipeline disable"); 26035074e1d5SCristian Dumitrescu return; 26045074e1d5SCristian Dumitrescu } 26055074e1d5SCristian Dumitrescu } 26065074e1d5SCristian Dumitrescu 26075074e1d5SCristian Dumitrescu static void 26085074e1d5SCristian Dumitrescu cmd_help(char **tokens, 26095074e1d5SCristian Dumitrescu uint32_t n_tokens, 26105074e1d5SCristian Dumitrescu char *out, 26115074e1d5SCristian Dumitrescu size_t out_size, 26125074e1d5SCristian Dumitrescu void *arg __rte_unused) 26135074e1d5SCristian Dumitrescu { 26145074e1d5SCristian Dumitrescu tokens++; 26155074e1d5SCristian Dumitrescu n_tokens--; 26165074e1d5SCristian Dumitrescu 26175074e1d5SCristian Dumitrescu if (n_tokens == 0) { 26185074e1d5SCristian Dumitrescu snprintf(out, out_size, 26197fef9ef1SYogesh Jangra "Type 'help <command>' for command details.\n\n" 26207fef9ef1SYogesh Jangra "List of commands:\n" 26217fef9ef1SYogesh Jangra "\tmempool\n" 26227fef9ef1SYogesh Jangra "\tlink\n" 2623e2b8dc52SVenkata Suresh Kumar P "\ttap\n" 26247fef9ef1SYogesh Jangra "\tpipeline create\n" 26257fef9ef1SYogesh Jangra "\tpipeline port in\n" 26267fef9ef1SYogesh Jangra "\tpipeline port out\n" 26277fef9ef1SYogesh Jangra "\tpipeline build\n" 262875129cebSChurchill Khangar "\tpipeline table add\n" 262975129cebSChurchill Khangar "\tpipeline table delete\n" 263075129cebSChurchill Khangar "\tpipeline table default\n" 263175129cebSChurchill Khangar "\tpipeline table show\n" 2632598fe0ddSCristian Dumitrescu "\tpipeline selector group add\n" 2633598fe0ddSCristian Dumitrescu "\tpipeline selector group delete\n" 2634598fe0ddSCristian Dumitrescu "\tpipeline selector group member add\n" 2635598fe0ddSCristian Dumitrescu "\tpipeline selector group member delete\n" 2636598fe0ddSCristian Dumitrescu "\tpipeline selector show\n" 263775129cebSChurchill Khangar "\tpipeline commit\n" 263875129cebSChurchill Khangar "\tpipeline abort\n" 263964cfcebdSCristian Dumitrescu "\tpipeline regrd\n" 264064cfcebdSCristian Dumitrescu "\tpipeline regwr\n" 2641f38913b7SCristian Dumitrescu "\tpipeline meter profile add\n" 2642f38913b7SCristian Dumitrescu "\tpipeline meter profile delete\n" 2643f38913b7SCristian Dumitrescu "\tpipeline meter reset\n" 2644f38913b7SCristian Dumitrescu "\tpipeline meter set\n" 2645f38913b7SCristian Dumitrescu "\tpipeline meter stats\n" 26467fef9ef1SYogesh Jangra "\tpipeline stats\n" 26477fef9ef1SYogesh Jangra "\tthread pipeline enable\n" 26487fef9ef1SYogesh Jangra "\tthread pipeline disable\n\n"); 26495074e1d5SCristian Dumitrescu return; 26505074e1d5SCristian Dumitrescu } 26515074e1d5SCristian Dumitrescu 26525074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "mempool") == 0) { 26535074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_mempool_help); 26545074e1d5SCristian Dumitrescu return; 26555074e1d5SCristian Dumitrescu } 26565074e1d5SCristian Dumitrescu 26575074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "link") == 0) { 26585074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_link_help); 26595074e1d5SCristian Dumitrescu return; 26605074e1d5SCristian Dumitrescu } 26615074e1d5SCristian Dumitrescu 266277a41301SCristian Dumitrescu if (strcmp(tokens[0], "ring") == 0) { 266377a41301SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_ring_help); 266477a41301SCristian Dumitrescu return; 266577a41301SCristian Dumitrescu } 266677a41301SCristian Dumitrescu 2667e2b8dc52SVenkata Suresh Kumar P if (strcmp(tokens[0], "tap") == 0) { 2668e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, "\n%s\n", cmd_tap_help); 2669e2b8dc52SVenkata Suresh Kumar P return; 2670e2b8dc52SVenkata Suresh Kumar P } 2671e2b8dc52SVenkata Suresh Kumar P 26725074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 26737fef9ef1SYogesh Jangra (n_tokens == 2) && (strcmp(tokens[1], "create") == 0)) { 26745074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_create_help); 26755074e1d5SCristian Dumitrescu return; 26765074e1d5SCristian Dumitrescu } 26775074e1d5SCristian Dumitrescu 26785074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 26797fef9ef1SYogesh Jangra (n_tokens == 3) && (strcmp(tokens[1], "port") == 0)) { 26807fef9ef1SYogesh Jangra if (strcmp(tokens[2], "in") == 0) { 26815074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 26825074e1d5SCristian Dumitrescu cmd_pipeline_port_in_help); 26835074e1d5SCristian Dumitrescu return; 26845074e1d5SCristian Dumitrescu } 26855074e1d5SCristian Dumitrescu 26867fef9ef1SYogesh Jangra if (strcmp(tokens[2], "out") == 0) { 26875074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 26885074e1d5SCristian Dumitrescu cmd_pipeline_port_out_help); 26895074e1d5SCristian Dumitrescu return; 26905074e1d5SCristian Dumitrescu } 26915074e1d5SCristian Dumitrescu } 26925074e1d5SCristian Dumitrescu 26935074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 26947fef9ef1SYogesh Jangra (n_tokens == 2) && (strcmp(tokens[1], "build") == 0)) { 26955074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_build_help); 26965074e1d5SCristian Dumitrescu return; 26975074e1d5SCristian Dumitrescu } 26985074e1d5SCristian Dumitrescu 26995074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 27007fef9ef1SYogesh Jangra (n_tokens == 3) && 27017fef9ef1SYogesh Jangra (strcmp(tokens[1], "table") == 0) && 270275129cebSChurchill Khangar (strcmp(tokens[2], "add") == 0)) { 27035074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 270475129cebSChurchill Khangar cmd_pipeline_table_add_help); 270575129cebSChurchill Khangar return; 270675129cebSChurchill Khangar } 270775129cebSChurchill Khangar 270875129cebSChurchill Khangar if ((strcmp(tokens[0], "pipeline") == 0) && 270975129cebSChurchill Khangar (n_tokens == 3) && 271075129cebSChurchill Khangar (strcmp(tokens[1], "table") == 0) && 271175129cebSChurchill Khangar (strcmp(tokens[2], "delete") == 0)) { 271275129cebSChurchill Khangar snprintf(out, out_size, "\n%s\n", 271375129cebSChurchill Khangar cmd_pipeline_table_delete_help); 271475129cebSChurchill Khangar return; 271575129cebSChurchill Khangar } 271675129cebSChurchill Khangar 271775129cebSChurchill Khangar if ((strcmp(tokens[0], "pipeline") == 0) && 271875129cebSChurchill Khangar (n_tokens == 3) && 271975129cebSChurchill Khangar (strcmp(tokens[1], "table") == 0) && 272075129cebSChurchill Khangar (strcmp(tokens[2], "default") == 0)) { 272175129cebSChurchill Khangar snprintf(out, out_size, "\n%s\n", 272275129cebSChurchill Khangar cmd_pipeline_table_default_help); 272375129cebSChurchill Khangar return; 272475129cebSChurchill Khangar } 272575129cebSChurchill Khangar 272675129cebSChurchill Khangar if ((strcmp(tokens[0], "pipeline") == 0) && 272775129cebSChurchill Khangar (n_tokens == 3) && 272875129cebSChurchill Khangar (strcmp(tokens[1], "table") == 0) && 272975129cebSChurchill Khangar (strcmp(tokens[2], "show") == 0)) { 273075129cebSChurchill Khangar snprintf(out, out_size, "\n%s\n", 273175129cebSChurchill Khangar cmd_pipeline_table_show_help); 273275129cebSChurchill Khangar return; 273375129cebSChurchill Khangar } 273475129cebSChurchill Khangar 273575129cebSChurchill Khangar if ((strcmp(tokens[0], "pipeline") == 0) && 2736598fe0ddSCristian Dumitrescu (n_tokens == 4) && 2737598fe0ddSCristian Dumitrescu (strcmp(tokens[1], "selector") == 0) && 2738598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "group") == 0) && 2739598fe0ddSCristian Dumitrescu (strcmp(tokens[3], "add") == 0)) { 2740598fe0ddSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 2741598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_add_help); 2742598fe0ddSCristian Dumitrescu return; 2743598fe0ddSCristian Dumitrescu } 2744598fe0ddSCristian Dumitrescu 2745598fe0ddSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 2746598fe0ddSCristian Dumitrescu (n_tokens == 4) && 2747598fe0ddSCristian Dumitrescu (strcmp(tokens[1], "selector") == 0) && 2748598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "group") == 0) && 2749598fe0ddSCristian Dumitrescu (strcmp(tokens[3], "delete") == 0)) { 2750598fe0ddSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 2751598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_delete_help); 2752598fe0ddSCristian Dumitrescu return; 2753598fe0ddSCristian Dumitrescu } 2754598fe0ddSCristian Dumitrescu 2755598fe0ddSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 2756598fe0ddSCristian Dumitrescu (n_tokens == 5) && 2757598fe0ddSCristian Dumitrescu (strcmp(tokens[1], "selector") == 0) && 2758598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "group") == 0) && 2759598fe0ddSCristian Dumitrescu (strcmp(tokens[3], "member") == 0) && 2760598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "add") == 0)) { 2761598fe0ddSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 2762598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_add_help); 2763598fe0ddSCristian Dumitrescu return; 2764598fe0ddSCristian Dumitrescu } 2765598fe0ddSCristian Dumitrescu 2766598fe0ddSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 2767598fe0ddSCristian Dumitrescu (n_tokens == 5) && 2768598fe0ddSCristian Dumitrescu (strcmp(tokens[1], "selector") == 0) && 2769598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "group") == 0) && 2770598fe0ddSCristian Dumitrescu (strcmp(tokens[3], "member") == 0) && 2771598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "delete") == 0)) { 2772598fe0ddSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 2773598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_delete_help); 2774598fe0ddSCristian Dumitrescu return; 2775598fe0ddSCristian Dumitrescu } 2776598fe0ddSCristian Dumitrescu 2777598fe0ddSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 2778598fe0ddSCristian Dumitrescu (n_tokens == 3) && 2779598fe0ddSCristian Dumitrescu (strcmp(tokens[1], "selector") == 0) && 2780598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "show") == 0)) { 2781598fe0ddSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 2782598fe0ddSCristian Dumitrescu cmd_pipeline_selector_show_help); 2783598fe0ddSCristian Dumitrescu return; 2784598fe0ddSCristian Dumitrescu } 2785598fe0ddSCristian Dumitrescu 2786598fe0ddSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 278775129cebSChurchill Khangar (n_tokens == 2) && 278875129cebSChurchill Khangar (strcmp(tokens[1], "commit") == 0)) { 278975129cebSChurchill Khangar snprintf(out, out_size, "\n%s\n", 279075129cebSChurchill Khangar cmd_pipeline_commit_help); 279175129cebSChurchill Khangar return; 279275129cebSChurchill Khangar } 279375129cebSChurchill Khangar 279475129cebSChurchill Khangar if ((strcmp(tokens[0], "pipeline") == 0) && 279575129cebSChurchill Khangar (n_tokens == 2) && 279675129cebSChurchill Khangar (strcmp(tokens[1], "abort") == 0)) { 279775129cebSChurchill Khangar snprintf(out, out_size, "\n%s\n", 279875129cebSChurchill Khangar cmd_pipeline_abort_help); 27995074e1d5SCristian Dumitrescu return; 28005074e1d5SCristian Dumitrescu } 28015074e1d5SCristian Dumitrescu 28025074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 280364cfcebdSCristian Dumitrescu (n_tokens == 2) && (strcmp(tokens[1], "regrd") == 0)) { 280464cfcebdSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_regrd_help); 280564cfcebdSCristian Dumitrescu return; 280664cfcebdSCristian Dumitrescu } 280764cfcebdSCristian Dumitrescu 280864cfcebdSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 280964cfcebdSCristian Dumitrescu (n_tokens == 2) && (strcmp(tokens[1], "regwr") == 0)) { 281064cfcebdSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_regwr_help); 281164cfcebdSCristian Dumitrescu return; 281264cfcebdSCristian Dumitrescu } 281364cfcebdSCristian Dumitrescu 2814f38913b7SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") && 2815f38913b7SCristian Dumitrescu (n_tokens == 4) && !strcmp(tokens[1], "meter") 2816f38913b7SCristian Dumitrescu && !strcmp(tokens[2], "profile") 2817f38913b7SCristian Dumitrescu && !strcmp(tokens[3], "add")) { 2818f38913b7SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_profile_add_help); 2819f38913b7SCristian Dumitrescu return; 2820f38913b7SCristian Dumitrescu } 2821f38913b7SCristian Dumitrescu 2822f38913b7SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") && 2823f38913b7SCristian Dumitrescu (n_tokens == 4) && !strcmp(tokens[1], "meter") 2824f38913b7SCristian Dumitrescu && !strcmp(tokens[2], "profile") 2825f38913b7SCristian Dumitrescu && !strcmp(tokens[3], "delete")) { 2826f38913b7SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_profile_delete_help); 2827f38913b7SCristian Dumitrescu return; 2828f38913b7SCristian Dumitrescu } 2829f38913b7SCristian Dumitrescu 2830f38913b7SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") && 2831f38913b7SCristian Dumitrescu (n_tokens == 3) && !strcmp(tokens[1], "meter") 2832f38913b7SCristian Dumitrescu && !strcmp(tokens[2], "reset")) { 2833f38913b7SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_reset_help); 2834f38913b7SCristian Dumitrescu return; 2835f38913b7SCristian Dumitrescu } 2836f38913b7SCristian Dumitrescu 2837f38913b7SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") && 2838f38913b7SCristian Dumitrescu (n_tokens == 3) && !strcmp(tokens[1], "meter") 2839f38913b7SCristian Dumitrescu && !strcmp(tokens[2], "set")) { 2840f38913b7SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_set_help); 2841f38913b7SCristian Dumitrescu return; 2842f38913b7SCristian Dumitrescu } 2843f38913b7SCristian Dumitrescu 2844f38913b7SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") && 2845f38913b7SCristian Dumitrescu (n_tokens == 3) && !strcmp(tokens[1], "meter") 2846f38913b7SCristian Dumitrescu && !strcmp(tokens[2], "stats")) { 2847f38913b7SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_stats_help); 2848f38913b7SCristian Dumitrescu return; 2849f38913b7SCristian Dumitrescu } 2850f38913b7SCristian Dumitrescu 285164cfcebdSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 28527fef9ef1SYogesh Jangra (n_tokens == 2) && (strcmp(tokens[1], "stats") == 0)) { 28535074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_stats_help); 28545074e1d5SCristian Dumitrescu return; 28555074e1d5SCristian Dumitrescu } 28565074e1d5SCristian Dumitrescu 28575074e1d5SCristian Dumitrescu if ((n_tokens == 3) && 28585074e1d5SCristian Dumitrescu (strcmp(tokens[0], "thread") == 0) && 28595074e1d5SCristian Dumitrescu (strcmp(tokens[1], "pipeline") == 0)) { 28605074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "enable") == 0) { 28615074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 28625074e1d5SCristian Dumitrescu cmd_thread_pipeline_enable_help); 28635074e1d5SCristian Dumitrescu return; 28645074e1d5SCristian Dumitrescu } 28655074e1d5SCristian Dumitrescu 28665074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "disable") == 0) { 28675074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 28685074e1d5SCristian Dumitrescu cmd_thread_pipeline_disable_help); 28695074e1d5SCristian Dumitrescu return; 28705074e1d5SCristian Dumitrescu } 28715074e1d5SCristian Dumitrescu } 28725074e1d5SCristian Dumitrescu 28735074e1d5SCristian Dumitrescu snprintf(out, out_size, "Invalid command\n"); 28745074e1d5SCristian Dumitrescu } 28755074e1d5SCristian Dumitrescu 28765074e1d5SCristian Dumitrescu void 28775074e1d5SCristian Dumitrescu cli_process(char *in, char *out, size_t out_size, void *obj) 28785074e1d5SCristian Dumitrescu { 28795074e1d5SCristian Dumitrescu char *tokens[CMD_MAX_TOKENS]; 28805074e1d5SCristian Dumitrescu uint32_t n_tokens = RTE_DIM(tokens); 28815074e1d5SCristian Dumitrescu int status; 28825074e1d5SCristian Dumitrescu 28835074e1d5SCristian Dumitrescu if (is_comment(in)) 28845074e1d5SCristian Dumitrescu return; 28855074e1d5SCristian Dumitrescu 28865074e1d5SCristian Dumitrescu status = parse_tokenize_string(in, tokens, &n_tokens); 28875074e1d5SCristian Dumitrescu if (status) { 28885074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_TOO_MANY, ""); 28895074e1d5SCristian Dumitrescu return; 28905074e1d5SCristian Dumitrescu } 28915074e1d5SCristian Dumitrescu 28925074e1d5SCristian Dumitrescu if (n_tokens == 0) 28935074e1d5SCristian Dumitrescu return; 28945074e1d5SCristian Dumitrescu 28955074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "help") == 0) { 28965074e1d5SCristian Dumitrescu cmd_help(tokens, n_tokens, out, out_size, obj); 28975074e1d5SCristian Dumitrescu return; 28985074e1d5SCristian Dumitrescu } 28995074e1d5SCristian Dumitrescu 29005074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "mempool") == 0) { 29015074e1d5SCristian Dumitrescu cmd_mempool(tokens, n_tokens, out, out_size, obj); 29025074e1d5SCristian Dumitrescu return; 29035074e1d5SCristian Dumitrescu } 29045074e1d5SCristian Dumitrescu 29055074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "link") == 0) { 2906821848f5SCristian Dumitrescu if ((n_tokens >= 2) && (strcmp(tokens[1], "show") == 0)) { 29075074e1d5SCristian Dumitrescu cmd_link_show(tokens, n_tokens, out, out_size, obj); 29085074e1d5SCristian Dumitrescu return; 29095074e1d5SCristian Dumitrescu } 29105074e1d5SCristian Dumitrescu 29115074e1d5SCristian Dumitrescu cmd_link(tokens, n_tokens, out, out_size, obj); 29125074e1d5SCristian Dumitrescu return; 29135074e1d5SCristian Dumitrescu } 29145074e1d5SCristian Dumitrescu 291577a41301SCristian Dumitrescu if (strcmp(tokens[0], "ring") == 0) { 291677a41301SCristian Dumitrescu cmd_ring(tokens, n_tokens, out, out_size, obj); 291777a41301SCristian Dumitrescu return; 291877a41301SCristian Dumitrescu } 291977a41301SCristian Dumitrescu 2920e2b8dc52SVenkata Suresh Kumar P if (strcmp(tokens[0], "tap") == 0) { 2921e2b8dc52SVenkata Suresh Kumar P cmd_tap(tokens, n_tokens, out, out_size, obj); 2922e2b8dc52SVenkata Suresh Kumar P return; 2923e2b8dc52SVenkata Suresh Kumar P } 2924e2b8dc52SVenkata Suresh Kumar P 29255074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "pipeline") == 0) { 29265074e1d5SCristian Dumitrescu if ((n_tokens >= 3) && 29275074e1d5SCristian Dumitrescu (strcmp(tokens[2], "create") == 0)) { 29285074e1d5SCristian Dumitrescu cmd_pipeline_create(tokens, n_tokens, out, out_size, 29295074e1d5SCristian Dumitrescu obj); 29305074e1d5SCristian Dumitrescu return; 29315074e1d5SCristian Dumitrescu } 29325074e1d5SCristian Dumitrescu 29335074e1d5SCristian Dumitrescu if ((n_tokens >= 4) && 29345074e1d5SCristian Dumitrescu (strcmp(tokens[2], "port") == 0) && 29355074e1d5SCristian Dumitrescu (strcmp(tokens[3], "in") == 0)) { 29365074e1d5SCristian Dumitrescu cmd_pipeline_port_in(tokens, n_tokens, out, out_size, 29375074e1d5SCristian Dumitrescu obj); 29385074e1d5SCristian Dumitrescu return; 29395074e1d5SCristian Dumitrescu } 29405074e1d5SCristian Dumitrescu 29415074e1d5SCristian Dumitrescu if ((n_tokens >= 4) && 29425074e1d5SCristian Dumitrescu (strcmp(tokens[2], "port") == 0) && 29435074e1d5SCristian Dumitrescu (strcmp(tokens[3], "out") == 0)) { 29445074e1d5SCristian Dumitrescu cmd_pipeline_port_out(tokens, n_tokens, out, out_size, 29455074e1d5SCristian Dumitrescu obj); 29465074e1d5SCristian Dumitrescu return; 29475074e1d5SCristian Dumitrescu } 29485074e1d5SCristian Dumitrescu 29495074e1d5SCristian Dumitrescu if ((n_tokens >= 3) && 29505074e1d5SCristian Dumitrescu (strcmp(tokens[2], "build") == 0)) { 29515074e1d5SCristian Dumitrescu cmd_pipeline_build(tokens, n_tokens, out, out_size, 29525074e1d5SCristian Dumitrescu obj); 29535074e1d5SCristian Dumitrescu return; 29545074e1d5SCristian Dumitrescu } 29555074e1d5SCristian Dumitrescu 295675129cebSChurchill Khangar if ((n_tokens >= 5) && 295775129cebSChurchill Khangar (strcmp(tokens[2], "table") == 0) && 295875129cebSChurchill Khangar (strcmp(tokens[4], "add") == 0)) { 295975129cebSChurchill Khangar cmd_pipeline_table_add(tokens, n_tokens, out, 296075129cebSChurchill Khangar out_size, obj); 296175129cebSChurchill Khangar return; 296275129cebSChurchill Khangar } 296375129cebSChurchill Khangar 296475129cebSChurchill Khangar if ((n_tokens >= 5) && 296575129cebSChurchill Khangar (strcmp(tokens[2], "table") == 0) && 296675129cebSChurchill Khangar (strcmp(tokens[4], "delete") == 0)) { 296775129cebSChurchill Khangar cmd_pipeline_table_delete(tokens, n_tokens, out, 296875129cebSChurchill Khangar out_size, obj); 296975129cebSChurchill Khangar return; 297075129cebSChurchill Khangar } 297175129cebSChurchill Khangar 297275129cebSChurchill Khangar if ((n_tokens >= 5) && 297375129cebSChurchill Khangar (strcmp(tokens[2], "table") == 0) && 297475129cebSChurchill Khangar (strcmp(tokens[4], "default") == 0)) { 297575129cebSChurchill Khangar cmd_pipeline_table_default(tokens, n_tokens, out, 297675129cebSChurchill Khangar out_size, obj); 297775129cebSChurchill Khangar return; 297875129cebSChurchill Khangar } 297975129cebSChurchill Khangar 298075129cebSChurchill Khangar if ((n_tokens >= 5) && 298175129cebSChurchill Khangar (strcmp(tokens[2], "table") == 0) && 298275129cebSChurchill Khangar (strcmp(tokens[4], "show") == 0)) { 298375129cebSChurchill Khangar cmd_pipeline_table_show(tokens, n_tokens, out, 298475129cebSChurchill Khangar out_size, obj); 298575129cebSChurchill Khangar return; 298675129cebSChurchill Khangar } 298775129cebSChurchill Khangar 2988598fe0ddSCristian Dumitrescu if ((n_tokens >= 6) && 2989598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "selector") == 0) && 2990598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "group") == 0) && 2991598fe0ddSCristian Dumitrescu (strcmp(tokens[5], "add") == 0)) { 2992598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_add(tokens, n_tokens, out, 2993598fe0ddSCristian Dumitrescu out_size, obj); 2994598fe0ddSCristian Dumitrescu return; 2995598fe0ddSCristian Dumitrescu } 2996598fe0ddSCristian Dumitrescu 2997598fe0ddSCristian Dumitrescu if ((n_tokens >= 6) && 2998598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "selector") == 0) && 2999598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "group") == 0) && 3000598fe0ddSCristian Dumitrescu (strcmp(tokens[5], "delete") == 0)) { 3001598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_delete(tokens, n_tokens, out, 3002598fe0ddSCristian Dumitrescu out_size, obj); 3003598fe0ddSCristian Dumitrescu return; 3004598fe0ddSCristian Dumitrescu } 3005598fe0ddSCristian Dumitrescu 3006598fe0ddSCristian Dumitrescu if ((n_tokens >= 7) && 3007598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "selector") == 0) && 3008598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "group") == 0) && 3009598fe0ddSCristian Dumitrescu (strcmp(tokens[5], "member") == 0) && 3010598fe0ddSCristian Dumitrescu (strcmp(tokens[6], "add") == 0)) { 3011598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_add(tokens, n_tokens, out, 3012598fe0ddSCristian Dumitrescu out_size, obj); 3013598fe0ddSCristian Dumitrescu return; 3014598fe0ddSCristian Dumitrescu } 3015598fe0ddSCristian Dumitrescu 3016598fe0ddSCristian Dumitrescu if ((n_tokens >= 7) && 3017598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "selector") == 0) && 3018598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "group") == 0) && 3019598fe0ddSCristian Dumitrescu (strcmp(tokens[5], "member") == 0) && 3020598fe0ddSCristian Dumitrescu (strcmp(tokens[6], "delete") == 0)) { 3021598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_delete(tokens, n_tokens, out, 3022598fe0ddSCristian Dumitrescu out_size, obj); 3023598fe0ddSCristian Dumitrescu return; 3024598fe0ddSCristian Dumitrescu } 3025598fe0ddSCristian Dumitrescu 3026598fe0ddSCristian Dumitrescu if ((n_tokens >= 5) && 3027598fe0ddSCristian Dumitrescu (strcmp(tokens[2], "selector") == 0) && 3028598fe0ddSCristian Dumitrescu (strcmp(tokens[4], "show") == 0)) { 3029598fe0ddSCristian Dumitrescu cmd_pipeline_selector_show(tokens, n_tokens, out, 3030598fe0ddSCristian Dumitrescu out_size, obj); 3031598fe0ddSCristian Dumitrescu return; 3032598fe0ddSCristian Dumitrescu } 3033598fe0ddSCristian Dumitrescu 30345074e1d5SCristian Dumitrescu if ((n_tokens >= 3) && 303575129cebSChurchill Khangar (strcmp(tokens[2], "commit") == 0)) { 303675129cebSChurchill Khangar cmd_pipeline_commit(tokens, n_tokens, out, 303775129cebSChurchill Khangar out_size, obj); 303875129cebSChurchill Khangar return; 303975129cebSChurchill Khangar } 304075129cebSChurchill Khangar 304175129cebSChurchill Khangar if ((n_tokens >= 3) && 304275129cebSChurchill Khangar (strcmp(tokens[2], "abort") == 0)) { 304375129cebSChurchill Khangar cmd_pipeline_abort(tokens, n_tokens, out, 30445074e1d5SCristian Dumitrescu out_size, obj); 30455074e1d5SCristian Dumitrescu return; 30465074e1d5SCristian Dumitrescu } 30475074e1d5SCristian Dumitrescu 30485074e1d5SCristian Dumitrescu if ((n_tokens >= 3) && 304964cfcebdSCristian Dumitrescu (strcmp(tokens[2], "regrd") == 0)) { 305064cfcebdSCristian Dumitrescu cmd_pipeline_regrd(tokens, n_tokens, out, out_size, obj); 305164cfcebdSCristian Dumitrescu return; 305264cfcebdSCristian Dumitrescu } 305364cfcebdSCristian Dumitrescu 305464cfcebdSCristian Dumitrescu if ((n_tokens >= 3) && 305564cfcebdSCristian Dumitrescu (strcmp(tokens[2], "regwr") == 0)) { 305664cfcebdSCristian Dumitrescu cmd_pipeline_regwr(tokens, n_tokens, out, out_size, obj); 305764cfcebdSCristian Dumitrescu return; 305864cfcebdSCristian Dumitrescu } 305964cfcebdSCristian Dumitrescu 3060f38913b7SCristian Dumitrescu if ((n_tokens >= 6) && 3061f38913b7SCristian Dumitrescu (strcmp(tokens[2], "meter") == 0) && 3062f38913b7SCristian Dumitrescu (strcmp(tokens[3], "profile") == 0) && 3063f38913b7SCristian Dumitrescu (strcmp(tokens[5], "add") == 0)) { 3064f38913b7SCristian Dumitrescu cmd_pipeline_meter_profile_add(tokens, n_tokens, out, out_size, obj); 3065f38913b7SCristian Dumitrescu return; 3066f38913b7SCristian Dumitrescu } 3067f38913b7SCristian Dumitrescu 3068f38913b7SCristian Dumitrescu if ((n_tokens >= 6) && 3069f38913b7SCristian Dumitrescu (strcmp(tokens[2], "meter") == 0) && 3070f38913b7SCristian Dumitrescu (strcmp(tokens[3], "profile") == 0) && 3071f38913b7SCristian Dumitrescu (strcmp(tokens[5], "delete") == 0)) { 3072f38913b7SCristian Dumitrescu cmd_pipeline_meter_profile_delete(tokens, n_tokens, out, out_size, obj); 3073f38913b7SCristian Dumitrescu return; 3074f38913b7SCristian Dumitrescu } 3075f38913b7SCristian Dumitrescu 3076f38913b7SCristian Dumitrescu if ((n_tokens >= 9) && 3077f38913b7SCristian Dumitrescu (strcmp(tokens[2], "meter") == 0) && 3078f38913b7SCristian Dumitrescu (strcmp(tokens[8], "reset") == 0)) { 3079f38913b7SCristian Dumitrescu cmd_pipeline_meter_reset(tokens, n_tokens, out, out_size, obj); 3080f38913b7SCristian Dumitrescu return; 3081f38913b7SCristian Dumitrescu } 3082f38913b7SCristian Dumitrescu 3083f38913b7SCristian Dumitrescu if ((n_tokens >= 9) && 3084f38913b7SCristian Dumitrescu (strcmp(tokens[2], "meter") == 0) && 3085f38913b7SCristian Dumitrescu (strcmp(tokens[8], "set") == 0)) { 3086f38913b7SCristian Dumitrescu cmd_pipeline_meter_set(tokens, n_tokens, out, out_size, obj); 3087f38913b7SCristian Dumitrescu return; 3088f38913b7SCristian Dumitrescu } 3089f38913b7SCristian Dumitrescu 3090f38913b7SCristian Dumitrescu if ((n_tokens >= 9) && 3091f38913b7SCristian Dumitrescu (strcmp(tokens[2], "meter") == 0) && 3092f38913b7SCristian Dumitrescu (strcmp(tokens[8], "stats") == 0)) { 3093f38913b7SCristian Dumitrescu cmd_pipeline_meter_stats(tokens, n_tokens, out, out_size, obj); 3094f38913b7SCristian Dumitrescu return; 3095f38913b7SCristian Dumitrescu } 3096f38913b7SCristian Dumitrescu 309764cfcebdSCristian Dumitrescu if ((n_tokens >= 3) && 30985074e1d5SCristian Dumitrescu (strcmp(tokens[2], "stats") == 0)) { 30995074e1d5SCristian Dumitrescu cmd_pipeline_stats(tokens, n_tokens, out, out_size, 31005074e1d5SCristian Dumitrescu obj); 31015074e1d5SCristian Dumitrescu return; 31025074e1d5SCristian Dumitrescu } 31035074e1d5SCristian Dumitrescu } 31045074e1d5SCristian Dumitrescu 31055074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "thread") == 0) { 31065074e1d5SCristian Dumitrescu if ((n_tokens >= 5) && 31075074e1d5SCristian Dumitrescu (strcmp(tokens[4], "enable") == 0)) { 31085074e1d5SCristian Dumitrescu cmd_thread_pipeline_enable(tokens, n_tokens, 31095074e1d5SCristian Dumitrescu out, out_size, obj); 31105074e1d5SCristian Dumitrescu return; 31115074e1d5SCristian Dumitrescu } 31125074e1d5SCristian Dumitrescu 31135074e1d5SCristian Dumitrescu if ((n_tokens >= 5) && 31145074e1d5SCristian Dumitrescu (strcmp(tokens[4], "disable") == 0)) { 31155074e1d5SCristian Dumitrescu cmd_thread_pipeline_disable(tokens, n_tokens, 31165074e1d5SCristian Dumitrescu out, out_size, obj); 31175074e1d5SCristian Dumitrescu return; 31185074e1d5SCristian Dumitrescu } 31195074e1d5SCristian Dumitrescu } 31205074e1d5SCristian Dumitrescu 31215074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]); 31225074e1d5SCristian Dumitrescu } 31235074e1d5SCristian Dumitrescu 31245074e1d5SCristian Dumitrescu int 31255074e1d5SCristian Dumitrescu cli_script_process(const char *file_name, 31265074e1d5SCristian Dumitrescu size_t msg_in_len_max, 31275074e1d5SCristian Dumitrescu size_t msg_out_len_max, 31285074e1d5SCristian Dumitrescu void *obj) 31295074e1d5SCristian Dumitrescu { 31305074e1d5SCristian Dumitrescu char *msg_in = NULL, *msg_out = NULL; 31315074e1d5SCristian Dumitrescu FILE *f = NULL; 31325074e1d5SCristian Dumitrescu 31335074e1d5SCristian Dumitrescu /* Check input arguments */ 31345074e1d5SCristian Dumitrescu if ((file_name == NULL) || 31355074e1d5SCristian Dumitrescu (strlen(file_name) == 0) || 31365074e1d5SCristian Dumitrescu (msg_in_len_max == 0) || 31375074e1d5SCristian Dumitrescu (msg_out_len_max == 0)) 31385074e1d5SCristian Dumitrescu return -EINVAL; 31395074e1d5SCristian Dumitrescu 31405074e1d5SCristian Dumitrescu msg_in = malloc(msg_in_len_max + 1); 31415074e1d5SCristian Dumitrescu msg_out = malloc(msg_out_len_max + 1); 31425074e1d5SCristian Dumitrescu if ((msg_in == NULL) || 31435074e1d5SCristian Dumitrescu (msg_out == NULL)) { 31445074e1d5SCristian Dumitrescu free(msg_out); 31455074e1d5SCristian Dumitrescu free(msg_in); 31465074e1d5SCristian Dumitrescu return -ENOMEM; 31475074e1d5SCristian Dumitrescu } 31485074e1d5SCristian Dumitrescu 31495074e1d5SCristian Dumitrescu /* Open input file */ 31505074e1d5SCristian Dumitrescu f = fopen(file_name, "r"); 31515074e1d5SCristian Dumitrescu if (f == NULL) { 31525074e1d5SCristian Dumitrescu free(msg_out); 31535074e1d5SCristian Dumitrescu free(msg_in); 31545074e1d5SCristian Dumitrescu return -EIO; 31555074e1d5SCristian Dumitrescu } 31565074e1d5SCristian Dumitrescu 31575074e1d5SCristian Dumitrescu /* Read file */ 31585074e1d5SCristian Dumitrescu for ( ; ; ) { 31595074e1d5SCristian Dumitrescu if (fgets(msg_in, msg_in_len_max + 1, f) == NULL) 31605074e1d5SCristian Dumitrescu break; 31615074e1d5SCristian Dumitrescu 31625074e1d5SCristian Dumitrescu printf("%s", msg_in); 31635074e1d5SCristian Dumitrescu msg_out[0] = 0; 31645074e1d5SCristian Dumitrescu 31655074e1d5SCristian Dumitrescu cli_process(msg_in, 31665074e1d5SCristian Dumitrescu msg_out, 31675074e1d5SCristian Dumitrescu msg_out_len_max, 31685074e1d5SCristian Dumitrescu obj); 31695074e1d5SCristian Dumitrescu 31705074e1d5SCristian Dumitrescu if (strlen(msg_out)) 31715074e1d5SCristian Dumitrescu printf("%s", msg_out); 31725074e1d5SCristian Dumitrescu } 31735074e1d5SCristian Dumitrescu 31745074e1d5SCristian Dumitrescu /* Close file */ 31755074e1d5SCristian Dumitrescu fclose(f); 31765074e1d5SCristian Dumitrescu free(msg_out); 31775074e1d5SCristian Dumitrescu free(msg_in); 31785074e1d5SCristian Dumitrescu return 0; 31795074e1d5SCristian Dumitrescu } 3180