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 1041*75129cebSChurchill Khangar #ifndef MAX_LINE_SIZE 1042*75129cebSChurchill Khangar #define MAX_LINE_SIZE 2048 1043*75129cebSChurchill Khangar #endif 1044*75129cebSChurchill Khangar 1045*75129cebSChurchill Khangar static int 1046*75129cebSChurchill Khangar pipeline_table_entries_add(struct rte_swx_ctl_pipeline *p, 1047*75129cebSChurchill Khangar const char *table_name, 1048*75129cebSChurchill Khangar FILE *file, 1049*75129cebSChurchill Khangar uint32_t *file_line_number) 1050*75129cebSChurchill Khangar { 1051*75129cebSChurchill Khangar char *line = NULL; 1052*75129cebSChurchill Khangar uint32_t line_id = 0; 1053*75129cebSChurchill Khangar int status = 0; 1054*75129cebSChurchill Khangar 1055*75129cebSChurchill Khangar /* Buffer allocation. */ 1056*75129cebSChurchill Khangar line = malloc(MAX_LINE_SIZE); 1057*75129cebSChurchill Khangar if (!line) 1058*75129cebSChurchill Khangar return -ENOMEM; 1059*75129cebSChurchill Khangar 1060*75129cebSChurchill Khangar /* File read. */ 1061*75129cebSChurchill Khangar for (line_id = 1; ; line_id++) { 1062*75129cebSChurchill Khangar struct rte_swx_table_entry *entry; 1063*75129cebSChurchill Khangar int is_blank_or_comment; 1064*75129cebSChurchill Khangar 1065*75129cebSChurchill Khangar if (fgets(line, MAX_LINE_SIZE, file) == NULL) 1066*75129cebSChurchill Khangar break; 1067*75129cebSChurchill Khangar 1068*75129cebSChurchill Khangar entry = rte_swx_ctl_pipeline_table_entry_read(p, 1069*75129cebSChurchill Khangar table_name, 1070*75129cebSChurchill Khangar line, 1071*75129cebSChurchill Khangar &is_blank_or_comment); 1072*75129cebSChurchill Khangar if (!entry) { 1073*75129cebSChurchill Khangar if (is_blank_or_comment) 1074*75129cebSChurchill Khangar continue; 1075*75129cebSChurchill Khangar 1076*75129cebSChurchill Khangar status = -EINVAL; 1077*75129cebSChurchill Khangar goto error; 1078*75129cebSChurchill Khangar } 1079*75129cebSChurchill Khangar 1080*75129cebSChurchill Khangar status = rte_swx_ctl_pipeline_table_entry_add(p, 1081*75129cebSChurchill Khangar table_name, 1082*75129cebSChurchill Khangar entry); 1083*75129cebSChurchill Khangar table_entry_free(entry); 1084*75129cebSChurchill Khangar if (status) 1085*75129cebSChurchill Khangar goto error; 1086*75129cebSChurchill Khangar } 1087*75129cebSChurchill Khangar 1088*75129cebSChurchill Khangar error: 1089*75129cebSChurchill Khangar free(line); 1090*75129cebSChurchill Khangar *file_line_number = line_id; 1091*75129cebSChurchill Khangar return status; 1092*75129cebSChurchill Khangar } 1093*75129cebSChurchill Khangar 1094*75129cebSChurchill Khangar static const char cmd_pipeline_table_add_help[] = 1095*75129cebSChurchill Khangar "pipeline <pipeline_name> table <table_name> add <file_name>\n"; 10965074e1d5SCristian Dumitrescu 10975074e1d5SCristian Dumitrescu static void 1098*75129cebSChurchill 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; 1105*75129cebSChurchill Khangar char *pipeline_name, *table_name, *file_name; 1106*75129cebSChurchill Khangar FILE *file = NULL; 1107*75129cebSChurchill Khangar uint32_t file_line_number = 0; 11085074e1d5SCristian Dumitrescu int status; 11095074e1d5SCristian Dumitrescu 1110*75129cebSChurchill 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 1122*75129cebSChurchill Khangar table_name = tokens[3]; 1123*75129cebSChurchill Khangar 1124*75129cebSChurchill Khangar file_name = tokens[5]; 1125*75129cebSChurchill Khangar file = fopen(file_name, "r"); 1126*75129cebSChurchill Khangar if (!file) { 1127*75129cebSChurchill Khangar snprintf(out, out_size, "Cannot open file %s.\n", file_name); 1128*75129cebSChurchill Khangar return; 1129*75129cebSChurchill Khangar } 1130*75129cebSChurchill Khangar 1131*75129cebSChurchill Khangar status = pipeline_table_entries_add(p->ctl, 1132*75129cebSChurchill Khangar table_name, 1133*75129cebSChurchill Khangar file, 1134*75129cebSChurchill Khangar &file_line_number); 1135*75129cebSChurchill Khangar if (status) 1136*75129cebSChurchill Khangar snprintf(out, out_size, "Invalid entry in file %s at line %u\n", 1137*75129cebSChurchill Khangar file_name, 1138*75129cebSChurchill Khangar file_line_number); 1139*75129cebSChurchill Khangar 1140*75129cebSChurchill Khangar fclose(file); 1141*75129cebSChurchill Khangar } 1142*75129cebSChurchill Khangar 1143*75129cebSChurchill Khangar static int 1144*75129cebSChurchill Khangar pipeline_table_entries_delete(struct rte_swx_ctl_pipeline *p, 1145*75129cebSChurchill Khangar const char *table_name, 1146*75129cebSChurchill Khangar FILE *file, 1147*75129cebSChurchill Khangar uint32_t *file_line_number) 1148*75129cebSChurchill Khangar { 1149*75129cebSChurchill Khangar char *line = NULL; 1150*75129cebSChurchill Khangar uint32_t line_id = 0; 1151*75129cebSChurchill Khangar int status = 0; 1152*75129cebSChurchill Khangar 1153*75129cebSChurchill Khangar /* Buffer allocation. */ 1154*75129cebSChurchill Khangar line = malloc(MAX_LINE_SIZE); 1155*75129cebSChurchill Khangar if (!line) 1156*75129cebSChurchill Khangar return -ENOMEM; 1157*75129cebSChurchill Khangar 1158*75129cebSChurchill Khangar /* File read. */ 1159*75129cebSChurchill Khangar for (line_id = 1; ; line_id++) { 1160*75129cebSChurchill Khangar struct rte_swx_table_entry *entry; 1161*75129cebSChurchill Khangar int is_blank_or_comment; 1162*75129cebSChurchill Khangar 1163*75129cebSChurchill Khangar if (fgets(line, MAX_LINE_SIZE, file) == NULL) 1164*75129cebSChurchill Khangar break; 1165*75129cebSChurchill Khangar 1166*75129cebSChurchill Khangar entry = rte_swx_ctl_pipeline_table_entry_read(p, 1167*75129cebSChurchill Khangar table_name, 1168*75129cebSChurchill Khangar line, 1169*75129cebSChurchill Khangar &is_blank_or_comment); 1170*75129cebSChurchill Khangar if (!entry) { 1171*75129cebSChurchill Khangar if (is_blank_or_comment) 1172*75129cebSChurchill Khangar continue; 1173*75129cebSChurchill Khangar 1174*75129cebSChurchill Khangar status = -EINVAL; 1175*75129cebSChurchill Khangar goto error; 1176*75129cebSChurchill Khangar } 1177*75129cebSChurchill Khangar 1178*75129cebSChurchill Khangar status = rte_swx_ctl_pipeline_table_entry_delete(p, 1179*75129cebSChurchill Khangar table_name, 1180*75129cebSChurchill Khangar entry); 1181*75129cebSChurchill Khangar table_entry_free(entry); 1182*75129cebSChurchill Khangar if (status) 1183*75129cebSChurchill Khangar goto error; 1184*75129cebSChurchill Khangar } 1185*75129cebSChurchill Khangar 1186*75129cebSChurchill Khangar error: 1187*75129cebSChurchill Khangar *file_line_number = line_id; 1188*75129cebSChurchill Khangar free(line); 1189*75129cebSChurchill Khangar return status; 1190*75129cebSChurchill Khangar } 1191*75129cebSChurchill Khangar 1192*75129cebSChurchill Khangar static const char cmd_pipeline_table_delete_help[] = 1193*75129cebSChurchill Khangar "pipeline <pipeline_name> table <table_name> delete <file_name>\n"; 1194*75129cebSChurchill Khangar 1195*75129cebSChurchill Khangar static void 1196*75129cebSChurchill Khangar cmd_pipeline_table_delete(char **tokens, 1197*75129cebSChurchill Khangar uint32_t n_tokens, 1198*75129cebSChurchill Khangar char *out, 1199*75129cebSChurchill Khangar size_t out_size, 1200*75129cebSChurchill Khangar void *obj) 1201*75129cebSChurchill Khangar { 1202*75129cebSChurchill Khangar struct pipeline *p; 1203*75129cebSChurchill Khangar char *pipeline_name, *table_name, *file_name; 1204*75129cebSChurchill Khangar FILE *file = NULL; 1205*75129cebSChurchill Khangar uint32_t file_line_number = 0; 1206*75129cebSChurchill Khangar int status; 1207*75129cebSChurchill Khangar 1208*75129cebSChurchill Khangar if (n_tokens != 6) { 1209*75129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 1210*75129cebSChurchill Khangar return; 1211*75129cebSChurchill Khangar } 1212*75129cebSChurchill Khangar 1213*75129cebSChurchill Khangar pipeline_name = tokens[1]; 1214*75129cebSChurchill Khangar p = pipeline_find(obj, pipeline_name); 1215*75129cebSChurchill Khangar if (!p || !p->ctl) { 1216*75129cebSChurchill 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 1222*75129cebSChurchill Khangar file_name = tokens[5]; 1223*75129cebSChurchill Khangar file = fopen(file_name, "r"); 1224*75129cebSChurchill Khangar if (!file) { 1225*75129cebSChurchill Khangar snprintf(out, out_size, "Cannot open file %s.\n", file_name); 12265074e1d5SCristian Dumitrescu return; 12275074e1d5SCristian Dumitrescu } 12285074e1d5SCristian Dumitrescu 1229*75129cebSChurchill Khangar status = pipeline_table_entries_delete(p->ctl, 1230*75129cebSChurchill Khangar table_name, 1231*75129cebSChurchill Khangar file, 1232*75129cebSChurchill Khangar &file_line_number); 1233*75129cebSChurchill Khangar if (status) 1234*75129cebSChurchill Khangar snprintf(out, out_size, "Invalid entry in file %s at line %u\n", 1235*75129cebSChurchill Khangar file_name, 1236*75129cebSChurchill Khangar file_line_number); 12375074e1d5SCristian Dumitrescu 1238*75129cebSChurchill Khangar fclose(file); 12395074e1d5SCristian Dumitrescu } 12405074e1d5SCristian Dumitrescu 1241*75129cebSChurchill Khangar static int 1242*75129cebSChurchill Khangar pipeline_table_default_entry_add(struct rte_swx_ctl_pipeline *p, 1243*75129cebSChurchill Khangar const char *table_name, 1244*75129cebSChurchill Khangar FILE *file, 1245*75129cebSChurchill Khangar uint32_t *file_line_number) 1246*75129cebSChurchill Khangar { 1247*75129cebSChurchill Khangar char *line = NULL; 1248*75129cebSChurchill Khangar uint32_t line_id = 0; 1249*75129cebSChurchill Khangar int status = 0; 12505074e1d5SCristian Dumitrescu 12515074e1d5SCristian Dumitrescu /* Buffer allocation. */ 1252*75129cebSChurchill Khangar line = malloc(MAX_LINE_SIZE); 1253*75129cebSChurchill Khangar if (!line) 1254*75129cebSChurchill Khangar return -ENOMEM; 12555074e1d5SCristian Dumitrescu 1256*75129cebSChurchill 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 1261*75129cebSChurchill Khangar if (fgets(line, MAX_LINE_SIZE, file) == NULL) 12625074e1d5SCristian Dumitrescu break; 12635074e1d5SCristian Dumitrescu 1264*75129cebSChurchill 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 1272*75129cebSChurchill Khangar status = -EINVAL; 12735074e1d5SCristian Dumitrescu goto error; 12745074e1d5SCristian Dumitrescu } 12755074e1d5SCristian Dumitrescu 1276*75129cebSChurchill Khangar status = rte_swx_ctl_pipeline_table_default_entry_add(p, 12775074e1d5SCristian Dumitrescu table_name, 12785074e1d5SCristian Dumitrescu entry); 1279275ebefeSCristian Dumitrescu table_entry_free(entry); 1280*75129cebSChurchill Khangar if (status) 12815074e1d5SCristian Dumitrescu goto error; 12825074e1d5SCristian Dumitrescu } 1283*75129cebSChurchill Khangar 1284*75129cebSChurchill Khangar error: 1285*75129cebSChurchill Khangar *file_line_number = line_id; 1286*75129cebSChurchill Khangar free(line); 1287*75129cebSChurchill Khangar return status; 12885074e1d5SCristian Dumitrescu } 12895074e1d5SCristian Dumitrescu 1290*75129cebSChurchill Khangar static const char cmd_pipeline_table_default_help[] = 1291*75129cebSChurchill Khangar "pipeline <pipeline_name> table <table_name> default <file_name>\n"; 12925074e1d5SCristian Dumitrescu 1293*75129cebSChurchill Khangar static void 1294*75129cebSChurchill Khangar cmd_pipeline_table_default(char **tokens, 1295*75129cebSChurchill Khangar uint32_t n_tokens, 1296*75129cebSChurchill Khangar char *out, 1297*75129cebSChurchill Khangar size_t out_size, 1298*75129cebSChurchill Khangar void *obj) 1299*75129cebSChurchill Khangar { 1300*75129cebSChurchill Khangar struct pipeline *p; 1301*75129cebSChurchill Khangar char *pipeline_name, *table_name, *file_name; 1302*75129cebSChurchill Khangar FILE *file = NULL; 1303*75129cebSChurchill Khangar uint32_t file_line_number = 0; 1304*75129cebSChurchill Khangar int status; 13055074e1d5SCristian Dumitrescu 1306*75129cebSChurchill Khangar if (n_tokens != 6) { 1307*75129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 1308*75129cebSChurchill Khangar return; 1309*75129cebSChurchill Khangar } 13105074e1d5SCristian Dumitrescu 1311*75129cebSChurchill Khangar pipeline_name = tokens[1]; 1312*75129cebSChurchill Khangar p = pipeline_find(obj, pipeline_name); 1313*75129cebSChurchill Khangar if (!p || !p->ctl) { 1314*75129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 1315*75129cebSChurchill Khangar return; 1316*75129cebSChurchill Khangar } 1317*75129cebSChurchill Khangar 1318*75129cebSChurchill Khangar table_name = tokens[3]; 1319*75129cebSChurchill Khangar 1320*75129cebSChurchill Khangar file_name = tokens[5]; 1321*75129cebSChurchill Khangar file = fopen(file_name, "r"); 1322*75129cebSChurchill Khangar if (!file) { 1323*75129cebSChurchill Khangar snprintf(out, out_size, "Cannot open file %s.\n", file_name); 1324*75129cebSChurchill Khangar return; 1325*75129cebSChurchill Khangar } 1326*75129cebSChurchill Khangar 1327*75129cebSChurchill Khangar status = pipeline_table_default_entry_add(p->ctl, 13285074e1d5SCristian Dumitrescu table_name, 1329*75129cebSChurchill Khangar file, 1330*75129cebSChurchill Khangar &file_line_number); 1331*75129cebSChurchill Khangar if (status) 1332*75129cebSChurchill Khangar snprintf(out, out_size, "Invalid entry in file %s at line %u\n", 1333*75129cebSChurchill Khangar file_name, 1334*75129cebSChurchill Khangar file_line_number); 1335cff9a717SCristian Dumitrescu 1336*75129cebSChurchill Khangar fclose(file); 13375074e1d5SCristian Dumitrescu } 13385074e1d5SCristian Dumitrescu 1339*75129cebSChurchill Khangar static const char cmd_pipeline_table_show_help[] = 1340*75129cebSChurchill Khangar "pipeline <pipeline_name> table <table_name> show\n"; 1341*75129cebSChurchill Khangar 1342*75129cebSChurchill Khangar static void 1343*75129cebSChurchill Khangar cmd_pipeline_table_show(char **tokens, 1344*75129cebSChurchill Khangar uint32_t n_tokens, 1345*75129cebSChurchill Khangar char *out, 1346*75129cebSChurchill Khangar size_t out_size, 1347*75129cebSChurchill Khangar void *obj) 1348*75129cebSChurchill Khangar { 1349*75129cebSChurchill Khangar struct pipeline *p; 1350*75129cebSChurchill Khangar char *pipeline_name, *table_name; 1351*75129cebSChurchill Khangar int status; 1352*75129cebSChurchill Khangar 1353*75129cebSChurchill Khangar if (n_tokens != 5) { 1354*75129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 1355*75129cebSChurchill Khangar return; 13565074e1d5SCristian Dumitrescu } 13575074e1d5SCristian Dumitrescu 1358*75129cebSChurchill Khangar pipeline_name = tokens[1]; 1359*75129cebSChurchill Khangar p = pipeline_find(obj, pipeline_name); 1360*75129cebSChurchill Khangar if (!p || !p->ctl) { 1361*75129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 1362*75129cebSChurchill Khangar return; 13635074e1d5SCristian Dumitrescu } 13645074e1d5SCristian Dumitrescu 1365*75129cebSChurchill Khangar table_name = tokens[3]; 1366*75129cebSChurchill Khangar status = rte_swx_ctl_pipeline_table_fprintf(stdout, p->ctl, table_name); 1367*75129cebSChurchill Khangar if (status) 1368*75129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "table_name"); 13695074e1d5SCristian Dumitrescu } 1370*75129cebSChurchill Khangar 1371*75129cebSChurchill Khangar static const char cmd_pipeline_commit_help[] = 1372*75129cebSChurchill Khangar "pipeline <pipeline_name> commit\n"; 1373*75129cebSChurchill Khangar 1374*75129cebSChurchill Khangar static void 1375*75129cebSChurchill Khangar cmd_pipeline_commit(char **tokens, 1376*75129cebSChurchill Khangar uint32_t n_tokens, 1377*75129cebSChurchill Khangar char *out, 1378*75129cebSChurchill Khangar size_t out_size, 1379*75129cebSChurchill Khangar void *obj) 1380*75129cebSChurchill Khangar { 1381*75129cebSChurchill Khangar struct pipeline *p; 1382*75129cebSChurchill Khangar char *pipeline_name; 1383*75129cebSChurchill Khangar int status; 1384*75129cebSChurchill Khangar 1385*75129cebSChurchill Khangar if (n_tokens != 3) { 1386*75129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 1387*75129cebSChurchill Khangar return; 1388*75129cebSChurchill Khangar } 1389*75129cebSChurchill Khangar 1390*75129cebSChurchill Khangar pipeline_name = tokens[1]; 1391*75129cebSChurchill Khangar p = pipeline_find(obj, pipeline_name); 1392*75129cebSChurchill Khangar if (!p || !p->ctl) { 1393*75129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 1394*75129cebSChurchill Khangar return; 13955074e1d5SCristian Dumitrescu } 13965074e1d5SCristian Dumitrescu 13975074e1d5SCristian Dumitrescu status = rte_swx_ctl_pipeline_commit(p->ctl, 1); 1398*75129cebSChurchill Khangar if (status) 1399*75129cebSChurchill Khangar snprintf(out, out_size, "Commit failed. " 1400*75129cebSChurchill Khangar "Use \"commit\" to retry or \"abort\" to discard the pending work.\n"); 14015074e1d5SCristian Dumitrescu } 14025074e1d5SCristian Dumitrescu 1403*75129cebSChurchill Khangar static const char cmd_pipeline_abort_help[] = 1404*75129cebSChurchill Khangar "pipeline <pipeline_name> abort\n"; 14055074e1d5SCristian Dumitrescu 1406*75129cebSChurchill Khangar static void 1407*75129cebSChurchill Khangar cmd_pipeline_abort(char **tokens, 1408*75129cebSChurchill Khangar uint32_t n_tokens, 1409*75129cebSChurchill Khangar char *out, 1410*75129cebSChurchill Khangar size_t out_size, 1411*75129cebSChurchill Khangar void *obj) 1412*75129cebSChurchill Khangar { 1413*75129cebSChurchill Khangar struct pipeline *p; 1414*75129cebSChurchill Khangar char *pipeline_name; 14155074e1d5SCristian Dumitrescu 1416*75129cebSChurchill Khangar if (n_tokens != 3) { 1417*75129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 14185074e1d5SCristian Dumitrescu return; 1419*75129cebSChurchill Khangar } 14205074e1d5SCristian Dumitrescu 1421*75129cebSChurchill Khangar pipeline_name = tokens[1]; 1422*75129cebSChurchill Khangar p = pipeline_find(obj, pipeline_name); 1423*75129cebSChurchill Khangar if (!p || !p->ctl) { 1424*75129cebSChurchill Khangar snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 1425*75129cebSChurchill Khangar return; 1426*75129cebSChurchill Khangar } 1427*75129cebSChurchill Khangar 14285074e1d5SCristian Dumitrescu rte_swx_ctl_pipeline_abort(p->ctl); 14295074e1d5SCristian Dumitrescu } 14305074e1d5SCristian Dumitrescu 143164cfcebdSCristian Dumitrescu static const char cmd_pipeline_regrd_help[] = 143264cfcebdSCristian Dumitrescu "pipeline <pipeline_name> regrd <register_array_name> <index>\n"; 143364cfcebdSCristian Dumitrescu 143464cfcebdSCristian Dumitrescu static void 143564cfcebdSCristian Dumitrescu cmd_pipeline_regrd(char **tokens, 143664cfcebdSCristian Dumitrescu uint32_t n_tokens, 143764cfcebdSCristian Dumitrescu char *out, 143864cfcebdSCristian Dumitrescu size_t out_size, 143964cfcebdSCristian Dumitrescu void *obj) 144064cfcebdSCristian Dumitrescu { 144164cfcebdSCristian Dumitrescu struct pipeline *p; 144264cfcebdSCristian Dumitrescu const char *name; 144364cfcebdSCristian Dumitrescu uint64_t value; 144464cfcebdSCristian Dumitrescu uint32_t idx; 144564cfcebdSCristian Dumitrescu int status; 144664cfcebdSCristian Dumitrescu 144764cfcebdSCristian Dumitrescu if (n_tokens != 5) { 144864cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 144964cfcebdSCristian Dumitrescu return; 145064cfcebdSCristian Dumitrescu } 145164cfcebdSCristian Dumitrescu 145264cfcebdSCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 145364cfcebdSCristian Dumitrescu if (!p || !p->ctl) { 145464cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 145564cfcebdSCristian Dumitrescu return; 145664cfcebdSCristian Dumitrescu } 145764cfcebdSCristian Dumitrescu 145864cfcebdSCristian Dumitrescu if (strcmp(tokens[2], "regrd")) { 145964cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "regrd"); 146064cfcebdSCristian Dumitrescu return; 146164cfcebdSCristian Dumitrescu } 146264cfcebdSCristian Dumitrescu 146364cfcebdSCristian Dumitrescu name = tokens[3]; 146464cfcebdSCristian Dumitrescu 146564cfcebdSCristian Dumitrescu if (parser_read_uint32(&idx, tokens[4])) { 146664cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index"); 146764cfcebdSCristian Dumitrescu return; 146864cfcebdSCristian Dumitrescu } 146964cfcebdSCristian Dumitrescu 147064cfcebdSCristian Dumitrescu status = rte_swx_ctl_pipeline_regarray_read(p->p, name, idx, &value); 147164cfcebdSCristian Dumitrescu if (status) { 147264cfcebdSCristian Dumitrescu snprintf(out, out_size, "Command failed.\n"); 147364cfcebdSCristian Dumitrescu return; 147464cfcebdSCristian Dumitrescu } 147564cfcebdSCristian Dumitrescu 147664cfcebdSCristian Dumitrescu snprintf(out, out_size, "0x%" PRIx64 "\n", value); 147764cfcebdSCristian Dumitrescu } 147864cfcebdSCristian Dumitrescu 147964cfcebdSCristian Dumitrescu static const char cmd_pipeline_regwr_help[] = 148064cfcebdSCristian Dumitrescu "pipeline <pipeline_name> regwr <register_array_name> <index> <value>\n"; 148164cfcebdSCristian Dumitrescu 148264cfcebdSCristian Dumitrescu static void 148364cfcebdSCristian Dumitrescu cmd_pipeline_regwr(char **tokens, 148464cfcebdSCristian Dumitrescu uint32_t n_tokens, 148564cfcebdSCristian Dumitrescu char *out, 148664cfcebdSCristian Dumitrescu size_t out_size, 148764cfcebdSCristian Dumitrescu void *obj) 148864cfcebdSCristian Dumitrescu { 148964cfcebdSCristian Dumitrescu struct pipeline *p; 149064cfcebdSCristian Dumitrescu const char *name; 149164cfcebdSCristian Dumitrescu uint64_t value; 149264cfcebdSCristian Dumitrescu uint32_t idx; 149364cfcebdSCristian Dumitrescu int status; 149464cfcebdSCristian Dumitrescu 149564cfcebdSCristian Dumitrescu if (n_tokens != 6) { 149664cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 149764cfcebdSCristian Dumitrescu return; 149864cfcebdSCristian Dumitrescu } 149964cfcebdSCristian Dumitrescu 150064cfcebdSCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 150164cfcebdSCristian Dumitrescu if (!p || !p->ctl) { 150264cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 150364cfcebdSCristian Dumitrescu return; 150464cfcebdSCristian Dumitrescu } 150564cfcebdSCristian Dumitrescu 150664cfcebdSCristian Dumitrescu if (strcmp(tokens[2], "regwr")) { 150764cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "regwr"); 150864cfcebdSCristian Dumitrescu return; 150964cfcebdSCristian Dumitrescu } 151064cfcebdSCristian Dumitrescu 151164cfcebdSCristian Dumitrescu name = tokens[3]; 151264cfcebdSCristian Dumitrescu 151364cfcebdSCristian Dumitrescu if (parser_read_uint32(&idx, tokens[4])) { 151464cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index"); 151564cfcebdSCristian Dumitrescu return; 151664cfcebdSCristian Dumitrescu } 151764cfcebdSCristian Dumitrescu 151864cfcebdSCristian Dumitrescu if (parser_read_uint64(&value, tokens[5])) { 151964cfcebdSCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "value"); 152064cfcebdSCristian Dumitrescu return; 152164cfcebdSCristian Dumitrescu } 152264cfcebdSCristian Dumitrescu 152364cfcebdSCristian Dumitrescu status = rte_swx_ctl_pipeline_regarray_write(p->p, name, idx, value); 152464cfcebdSCristian Dumitrescu if (status) { 152564cfcebdSCristian Dumitrescu snprintf(out, out_size, "Command failed.\n"); 152664cfcebdSCristian Dumitrescu return; 152764cfcebdSCristian Dumitrescu } 152864cfcebdSCristian Dumitrescu } 152964cfcebdSCristian Dumitrescu 1530f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_profile_add_help[] = 1531f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter profile <profile_name> add " 1532f38913b7SCristian Dumitrescu "cir <cir> pir <pir> cbs <cbs> pbs <pbs>\n"; 1533f38913b7SCristian Dumitrescu 1534f38913b7SCristian Dumitrescu static void 1535f38913b7SCristian Dumitrescu cmd_pipeline_meter_profile_add(char **tokens, 1536f38913b7SCristian Dumitrescu uint32_t n_tokens, 1537f38913b7SCristian Dumitrescu char *out, 1538f38913b7SCristian Dumitrescu size_t out_size, 1539f38913b7SCristian Dumitrescu void *obj) 1540f38913b7SCristian Dumitrescu { 1541f38913b7SCristian Dumitrescu struct rte_meter_trtcm_params params; 1542f38913b7SCristian Dumitrescu struct pipeline *p; 1543f38913b7SCristian Dumitrescu const char *profile_name; 1544f38913b7SCristian Dumitrescu int status; 1545f38913b7SCristian Dumitrescu 1546f38913b7SCristian Dumitrescu if (n_tokens != 14) { 1547f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 1548f38913b7SCristian Dumitrescu return; 1549f38913b7SCristian Dumitrescu } 1550f38913b7SCristian Dumitrescu 1551f38913b7SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 1552f38913b7SCristian Dumitrescu if (!p || !p->ctl) { 1553f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 1554f38913b7SCristian Dumitrescu return; 1555f38913b7SCristian Dumitrescu } 1556f38913b7SCristian Dumitrescu 1557f38913b7SCristian Dumitrescu if (strcmp(tokens[2], "meter")) { 1558f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter"); 1559f38913b7SCristian Dumitrescu return; 1560f38913b7SCristian Dumitrescu } 1561f38913b7SCristian Dumitrescu 1562f38913b7SCristian Dumitrescu if (strcmp(tokens[3], "profile")) { 1563f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile"); 1564f38913b7SCristian Dumitrescu return; 1565f38913b7SCristian Dumitrescu } 1566f38913b7SCristian Dumitrescu 1567f38913b7SCristian Dumitrescu profile_name = tokens[4]; 1568f38913b7SCristian Dumitrescu 1569f38913b7SCristian Dumitrescu if (strcmp(tokens[5], "add")) { 1570f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add"); 1571f38913b7SCristian Dumitrescu return; 1572f38913b7SCristian Dumitrescu } 1573f38913b7SCristian Dumitrescu 1574f38913b7SCristian Dumitrescu if (strcmp(tokens[6], "cir")) { 1575f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir"); 1576f38913b7SCristian Dumitrescu return; 1577f38913b7SCristian Dumitrescu } 1578f38913b7SCristian Dumitrescu 1579f38913b7SCristian Dumitrescu if (parser_read_uint64(¶ms.cir, tokens[7])) { 1580f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "cir"); 1581f38913b7SCristian Dumitrescu return; 1582f38913b7SCristian Dumitrescu } 1583f38913b7SCristian Dumitrescu 1584f38913b7SCristian Dumitrescu if (strcmp(tokens[8], "pir")) { 1585f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir"); 1586f38913b7SCristian Dumitrescu return; 1587f38913b7SCristian Dumitrescu } 1588f38913b7SCristian Dumitrescu 1589f38913b7SCristian Dumitrescu if (parser_read_uint64(¶ms.pir, tokens[9])) { 1590f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pir"); 1591f38913b7SCristian Dumitrescu return; 1592f38913b7SCristian Dumitrescu } 1593f38913b7SCristian Dumitrescu 1594f38913b7SCristian Dumitrescu if (strcmp(tokens[10], "cbs")) { 1595f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs"); 1596f38913b7SCristian Dumitrescu return; 1597f38913b7SCristian Dumitrescu } 1598f38913b7SCristian Dumitrescu 1599f38913b7SCristian Dumitrescu if (parser_read_uint64(¶ms.cbs, tokens[11])) { 1600f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "cbs"); 1601f38913b7SCristian Dumitrescu return; 1602f38913b7SCristian Dumitrescu } 1603f38913b7SCristian Dumitrescu 1604f38913b7SCristian Dumitrescu if (strcmp(tokens[12], "pbs")) { 1605f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs"); 1606f38913b7SCristian Dumitrescu return; 1607f38913b7SCristian Dumitrescu } 1608f38913b7SCristian Dumitrescu 1609f38913b7SCristian Dumitrescu if (parser_read_uint64(¶ms.pbs, tokens[13])) { 1610f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pbs"); 1611f38913b7SCristian Dumitrescu return; 1612f38913b7SCristian Dumitrescu } 1613f38913b7SCristian Dumitrescu 1614f38913b7SCristian Dumitrescu status = rte_swx_ctl_meter_profile_add(p->p, profile_name, ¶ms); 1615f38913b7SCristian Dumitrescu if (status) { 1616f38913b7SCristian Dumitrescu snprintf(out, out_size, "Command failed.\n"); 1617f38913b7SCristian Dumitrescu return; 1618f38913b7SCristian Dumitrescu } 1619f38913b7SCristian Dumitrescu } 1620f38913b7SCristian Dumitrescu 1621f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_profile_delete_help[] = 1622f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter profile <profile_name> delete\n"; 1623f38913b7SCristian Dumitrescu 1624f38913b7SCristian Dumitrescu static void 1625f38913b7SCristian Dumitrescu cmd_pipeline_meter_profile_delete(char **tokens, 1626f38913b7SCristian Dumitrescu uint32_t n_tokens, 1627f38913b7SCristian Dumitrescu char *out, 1628f38913b7SCristian Dumitrescu size_t out_size, 1629f38913b7SCristian Dumitrescu void *obj) 1630f38913b7SCristian Dumitrescu { 1631f38913b7SCristian Dumitrescu struct pipeline *p; 1632f38913b7SCristian Dumitrescu const char *profile_name; 1633f38913b7SCristian Dumitrescu int status; 1634f38913b7SCristian Dumitrescu 1635f38913b7SCristian Dumitrescu if (n_tokens != 6) { 1636f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 1637f38913b7SCristian Dumitrescu return; 1638f38913b7SCristian Dumitrescu } 1639f38913b7SCristian Dumitrescu 1640f38913b7SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 1641f38913b7SCristian Dumitrescu if (!p || !p->ctl) { 1642f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 1643f38913b7SCristian Dumitrescu return; 1644f38913b7SCristian Dumitrescu } 1645f38913b7SCristian Dumitrescu 1646f38913b7SCristian Dumitrescu if (strcmp(tokens[2], "meter")) { 1647f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter"); 1648f38913b7SCristian Dumitrescu return; 1649f38913b7SCristian Dumitrescu } 1650f38913b7SCristian Dumitrescu 1651f38913b7SCristian Dumitrescu if (strcmp(tokens[3], "profile")) { 1652f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile"); 1653f38913b7SCristian Dumitrescu return; 1654f38913b7SCristian Dumitrescu } 1655f38913b7SCristian Dumitrescu 1656f38913b7SCristian Dumitrescu profile_name = tokens[4]; 1657f38913b7SCristian Dumitrescu 1658f38913b7SCristian Dumitrescu if (strcmp(tokens[5], "delete")) { 1659f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete"); 1660f38913b7SCristian Dumitrescu return; 1661f38913b7SCristian Dumitrescu } 1662f38913b7SCristian Dumitrescu 1663f38913b7SCristian Dumitrescu status = rte_swx_ctl_meter_profile_delete(p->p, profile_name); 1664f38913b7SCristian Dumitrescu if (status) { 1665f38913b7SCristian Dumitrescu snprintf(out, out_size, "Command failed.\n"); 1666f38913b7SCristian Dumitrescu return; 1667f38913b7SCristian Dumitrescu } 1668f38913b7SCristian Dumitrescu } 1669f38913b7SCristian Dumitrescu 1670f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_reset_help[] = 1671f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> " 1672f38913b7SCristian Dumitrescu "reset\n"; 1673f38913b7SCristian Dumitrescu 1674f38913b7SCristian Dumitrescu static void 1675f38913b7SCristian Dumitrescu cmd_pipeline_meter_reset(char **tokens, 1676f38913b7SCristian Dumitrescu uint32_t n_tokens, 1677f38913b7SCristian Dumitrescu char *out, 1678f38913b7SCristian Dumitrescu size_t out_size, 1679f38913b7SCristian Dumitrescu void *obj) 1680f38913b7SCristian Dumitrescu { 1681f38913b7SCristian Dumitrescu struct pipeline *p; 1682f38913b7SCristian Dumitrescu const char *name; 1683f38913b7SCristian Dumitrescu uint32_t idx0, idx1; 1684f38913b7SCristian Dumitrescu 1685f38913b7SCristian Dumitrescu if (n_tokens != 9) { 1686f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 1687f38913b7SCristian Dumitrescu return; 1688f38913b7SCristian Dumitrescu } 1689f38913b7SCristian Dumitrescu 1690f38913b7SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 1691f38913b7SCristian Dumitrescu if (!p || !p->ctl) { 1692f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 1693f38913b7SCristian Dumitrescu return; 1694f38913b7SCristian Dumitrescu } 1695f38913b7SCristian Dumitrescu 1696f38913b7SCristian Dumitrescu if (strcmp(tokens[2], "meter")) { 1697f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter"); 1698f38913b7SCristian Dumitrescu return; 1699f38913b7SCristian Dumitrescu } 1700f38913b7SCristian Dumitrescu 1701f38913b7SCristian Dumitrescu name = tokens[3]; 1702f38913b7SCristian Dumitrescu 1703f38913b7SCristian Dumitrescu if (strcmp(tokens[4], "from")) { 1704f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from"); 1705f38913b7SCristian Dumitrescu return; 1706f38913b7SCristian Dumitrescu } 1707f38913b7SCristian Dumitrescu 1708f38913b7SCristian Dumitrescu if (parser_read_uint32(&idx0, tokens[5])) { 1709f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index0"); 1710f38913b7SCristian Dumitrescu return; 1711f38913b7SCristian Dumitrescu } 1712f38913b7SCristian Dumitrescu 1713f38913b7SCristian Dumitrescu if (strcmp(tokens[6], "to")) { 1714f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to"); 1715f38913b7SCristian Dumitrescu return; 1716f38913b7SCristian Dumitrescu } 1717f38913b7SCristian Dumitrescu 1718f38913b7SCristian Dumitrescu if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) { 1719f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index1"); 1720f38913b7SCristian Dumitrescu return; 1721f38913b7SCristian Dumitrescu } 1722f38913b7SCristian Dumitrescu 1723f38913b7SCristian Dumitrescu if (strcmp(tokens[8], "reset")) { 1724f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "reset"); 1725f38913b7SCristian Dumitrescu return; 1726f38913b7SCristian Dumitrescu } 1727f38913b7SCristian Dumitrescu 1728f38913b7SCristian Dumitrescu for ( ; idx0 <= idx1; idx0++) { 1729f38913b7SCristian Dumitrescu int status; 1730f38913b7SCristian Dumitrescu 1731f38913b7SCristian Dumitrescu status = rte_swx_ctl_meter_reset(p->p, name, idx0); 1732f38913b7SCristian Dumitrescu if (status) { 1733f38913b7SCristian Dumitrescu snprintf(out, out_size, "Command failed for index %u.\n", idx0); 1734f38913b7SCristian Dumitrescu return; 1735f38913b7SCristian Dumitrescu } 1736f38913b7SCristian Dumitrescu } 1737f38913b7SCristian Dumitrescu } 1738f38913b7SCristian Dumitrescu 1739f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_set_help[] = 1740f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> " 1741f38913b7SCristian Dumitrescu "set profile <profile_name>\n"; 1742f38913b7SCristian Dumitrescu 1743f38913b7SCristian Dumitrescu static void 1744f38913b7SCristian Dumitrescu cmd_pipeline_meter_set(char **tokens, 1745f38913b7SCristian Dumitrescu uint32_t n_tokens, 1746f38913b7SCristian Dumitrescu char *out, 1747f38913b7SCristian Dumitrescu size_t out_size, 1748f38913b7SCristian Dumitrescu void *obj) 1749f38913b7SCristian Dumitrescu { 1750f38913b7SCristian Dumitrescu struct pipeline *p; 1751f38913b7SCristian Dumitrescu const char *name, *profile_name; 1752f38913b7SCristian Dumitrescu uint32_t idx0, idx1; 1753f38913b7SCristian Dumitrescu 1754f38913b7SCristian Dumitrescu if (n_tokens != 11) { 1755f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 1756f38913b7SCristian Dumitrescu return; 1757f38913b7SCristian Dumitrescu } 1758f38913b7SCristian Dumitrescu 1759f38913b7SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 1760f38913b7SCristian Dumitrescu if (!p || !p->ctl) { 1761f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 1762f38913b7SCristian Dumitrescu return; 1763f38913b7SCristian Dumitrescu } 1764f38913b7SCristian Dumitrescu 1765f38913b7SCristian Dumitrescu if (strcmp(tokens[2], "meter")) { 1766f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter"); 1767f38913b7SCristian Dumitrescu return; 1768f38913b7SCristian Dumitrescu } 1769f38913b7SCristian Dumitrescu 1770f38913b7SCristian Dumitrescu name = tokens[3]; 1771f38913b7SCristian Dumitrescu 1772f38913b7SCristian Dumitrescu if (strcmp(tokens[4], "from")) { 1773f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from"); 1774f38913b7SCristian Dumitrescu return; 1775f38913b7SCristian Dumitrescu } 1776f38913b7SCristian Dumitrescu 1777f38913b7SCristian Dumitrescu if (parser_read_uint32(&idx0, tokens[5])) { 1778f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index0"); 1779f38913b7SCristian Dumitrescu return; 1780f38913b7SCristian Dumitrescu } 1781f38913b7SCristian Dumitrescu 1782f38913b7SCristian Dumitrescu if (strcmp(tokens[6], "to")) { 1783f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to"); 1784f38913b7SCristian Dumitrescu return; 1785f38913b7SCristian Dumitrescu } 1786f38913b7SCristian Dumitrescu 1787f38913b7SCristian Dumitrescu if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) { 1788f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index1"); 1789f38913b7SCristian Dumitrescu return; 1790f38913b7SCristian Dumitrescu } 1791f38913b7SCristian Dumitrescu 1792f38913b7SCristian Dumitrescu if (strcmp(tokens[8], "set")) { 1793f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "set"); 1794f38913b7SCristian Dumitrescu return; 1795f38913b7SCristian Dumitrescu } 1796f38913b7SCristian Dumitrescu 1797f38913b7SCristian Dumitrescu if (strcmp(tokens[9], "profile")) { 1798f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile"); 1799f38913b7SCristian Dumitrescu return; 1800f38913b7SCristian Dumitrescu } 1801f38913b7SCristian Dumitrescu 1802f38913b7SCristian Dumitrescu profile_name = tokens[10]; 1803f38913b7SCristian Dumitrescu 1804f38913b7SCristian Dumitrescu for ( ; idx0 <= idx1; idx0++) { 1805f38913b7SCristian Dumitrescu int status; 1806f38913b7SCristian Dumitrescu 1807f38913b7SCristian Dumitrescu status = rte_swx_ctl_meter_set(p->p, name, idx0, profile_name); 1808f38913b7SCristian Dumitrescu if (status) { 1809f38913b7SCristian Dumitrescu snprintf(out, out_size, "Command failed for index %u.\n", idx0); 1810f38913b7SCristian Dumitrescu return; 1811f38913b7SCristian Dumitrescu } 1812f38913b7SCristian Dumitrescu } 1813f38913b7SCristian Dumitrescu } 1814f38913b7SCristian Dumitrescu 1815f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_stats_help[] = 1816f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> " 1817f38913b7SCristian Dumitrescu "stats\n"; 1818f38913b7SCristian Dumitrescu 1819f38913b7SCristian Dumitrescu static void 1820f38913b7SCristian Dumitrescu cmd_pipeline_meter_stats(char **tokens, 1821f38913b7SCristian Dumitrescu uint32_t n_tokens, 1822f38913b7SCristian Dumitrescu char *out, 1823f38913b7SCristian Dumitrescu size_t out_size, 1824f38913b7SCristian Dumitrescu void *obj) 1825f38913b7SCristian Dumitrescu { 1826f38913b7SCristian Dumitrescu struct rte_swx_ctl_meter_stats stats; 1827f38913b7SCristian Dumitrescu struct pipeline *p; 1828f38913b7SCristian Dumitrescu const char *name; 1829f38913b7SCristian Dumitrescu uint32_t idx0, idx1; 1830f38913b7SCristian Dumitrescu 1831f38913b7SCristian Dumitrescu if (n_tokens != 9) { 1832f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 1833f38913b7SCristian Dumitrescu return; 1834f38913b7SCristian Dumitrescu } 1835f38913b7SCristian Dumitrescu 1836f38913b7SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 1837f38913b7SCristian Dumitrescu if (!p || !p->ctl) { 1838f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 1839f38913b7SCristian Dumitrescu return; 1840f38913b7SCristian Dumitrescu } 1841f38913b7SCristian Dumitrescu 1842f38913b7SCristian Dumitrescu if (strcmp(tokens[2], "meter")) { 1843f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter"); 1844f38913b7SCristian Dumitrescu return; 1845f38913b7SCristian Dumitrescu } 1846f38913b7SCristian Dumitrescu 1847f38913b7SCristian Dumitrescu name = tokens[3]; 1848f38913b7SCristian Dumitrescu 1849f38913b7SCristian Dumitrescu if (strcmp(tokens[4], "from")) { 1850f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from"); 1851f38913b7SCristian Dumitrescu return; 1852f38913b7SCristian Dumitrescu } 1853f38913b7SCristian Dumitrescu 1854f38913b7SCristian Dumitrescu if (parser_read_uint32(&idx0, tokens[5])) { 1855f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index0"); 1856f38913b7SCristian Dumitrescu return; 1857f38913b7SCristian Dumitrescu } 1858f38913b7SCristian Dumitrescu 1859f38913b7SCristian Dumitrescu if (strcmp(tokens[6], "to")) { 1860f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to"); 1861f38913b7SCristian Dumitrescu return; 1862f38913b7SCristian Dumitrescu } 1863f38913b7SCristian Dumitrescu 1864f38913b7SCristian Dumitrescu if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) { 1865f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "index1"); 1866f38913b7SCristian Dumitrescu return; 1867f38913b7SCristian Dumitrescu } 1868f38913b7SCristian Dumitrescu 1869f38913b7SCristian Dumitrescu if (strcmp(tokens[8], "stats")) { 1870f38913b7SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats"); 1871f38913b7SCristian Dumitrescu return; 1872f38913b7SCristian Dumitrescu } 1873f38913b7SCristian Dumitrescu 1874f38913b7SCristian Dumitrescu /* Table header. */ 1875f38913b7SCristian Dumitrescu snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n", 1876f38913b7SCristian Dumitrescu "-------", 1877f38913b7SCristian Dumitrescu "----------------", "----------------", "----------------", 1878f38913b7SCristian Dumitrescu "----------------", "----------------", "----------------"); 1879f38913b7SCristian Dumitrescu out_size -= strlen(out); 1880f38913b7SCristian Dumitrescu out += strlen(out); 1881f38913b7SCristian Dumitrescu 1882f38913b7SCristian Dumitrescu snprintf(out, out_size, "| %4s | %16s | %16s | %16s | %16s | %16s | %16s |\n", 1883f38913b7SCristian Dumitrescu "METER #", 1884f38913b7SCristian Dumitrescu "GREEN (packets)", "YELLOW (packets)", "RED (packets)", 1885f38913b7SCristian Dumitrescu "GREEN (bytes)", "YELLOW (bytes)", "RED (bytes)"); 1886f38913b7SCristian Dumitrescu out_size -= strlen(out); 1887f38913b7SCristian Dumitrescu out += strlen(out); 1888f38913b7SCristian Dumitrescu 1889f38913b7SCristian Dumitrescu snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n", 1890f38913b7SCristian Dumitrescu "-------", 1891f38913b7SCristian Dumitrescu "----------------", "----------------", "----------------", 1892f38913b7SCristian Dumitrescu "----------------", "----------------", "----------------"); 1893f38913b7SCristian Dumitrescu out_size -= strlen(out); 1894f38913b7SCristian Dumitrescu out += strlen(out); 1895f38913b7SCristian Dumitrescu 1896f38913b7SCristian Dumitrescu /* Table rows. */ 1897f38913b7SCristian Dumitrescu for ( ; idx0 <= idx1; idx0++) { 1898f38913b7SCristian Dumitrescu int status; 1899f38913b7SCristian Dumitrescu 1900f38913b7SCristian Dumitrescu status = rte_swx_ctl_meter_stats_read(p->p, name, idx0, &stats); 1901f38913b7SCristian Dumitrescu if (status) { 1902f38913b7SCristian Dumitrescu snprintf(out, out_size, "Pipeline meter stats error at index %u.\n", idx0); 1903f38913b7SCristian Dumitrescu out_size -= strlen(out); 1904f38913b7SCristian Dumitrescu out += strlen(out); 1905f38913b7SCristian Dumitrescu return; 1906f38913b7SCristian Dumitrescu } 1907f38913b7SCristian Dumitrescu 1908f38913b7SCristian Dumitrescu snprintf(out, out_size, "| %7d | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 1909f38913b7SCristian Dumitrescu " | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 " |\n", 1910f38913b7SCristian Dumitrescu idx0, 1911f38913b7SCristian Dumitrescu stats.n_pkts[RTE_COLOR_GREEN], 1912f38913b7SCristian Dumitrescu stats.n_pkts[RTE_COLOR_YELLOW], 1913f38913b7SCristian Dumitrescu stats.n_pkts[RTE_COLOR_RED], 1914f38913b7SCristian Dumitrescu stats.n_bytes[RTE_COLOR_GREEN], 1915f38913b7SCristian Dumitrescu stats.n_bytes[RTE_COLOR_YELLOW], 1916f38913b7SCristian Dumitrescu stats.n_bytes[RTE_COLOR_RED]); 1917f38913b7SCristian Dumitrescu out_size -= strlen(out); 1918f38913b7SCristian Dumitrescu out += strlen(out); 1919f38913b7SCristian Dumitrescu } 1920f38913b7SCristian Dumitrescu } 1921f38913b7SCristian Dumitrescu 19225074e1d5SCristian Dumitrescu static const char cmd_pipeline_stats_help[] = 19235074e1d5SCristian Dumitrescu "pipeline <pipeline_name> stats\n"; 19245074e1d5SCristian Dumitrescu 19255074e1d5SCristian Dumitrescu static void 19265074e1d5SCristian Dumitrescu cmd_pipeline_stats(char **tokens, 19275074e1d5SCristian Dumitrescu uint32_t n_tokens, 19285074e1d5SCristian Dumitrescu char *out, 19295074e1d5SCristian Dumitrescu size_t out_size, 19305074e1d5SCristian Dumitrescu void *obj) 19315074e1d5SCristian Dumitrescu { 19325074e1d5SCristian Dumitrescu struct rte_swx_ctl_pipeline_info info; 19335074e1d5SCristian Dumitrescu struct pipeline *p; 19345074e1d5SCristian Dumitrescu uint32_t i; 19355074e1d5SCristian Dumitrescu int status; 19365074e1d5SCristian Dumitrescu 19375074e1d5SCristian Dumitrescu if (n_tokens != 3) { 19385074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 19395074e1d5SCristian Dumitrescu return; 19405074e1d5SCristian Dumitrescu } 19415074e1d5SCristian Dumitrescu 19425074e1d5SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 19435074e1d5SCristian Dumitrescu if (!p || !p->ctl) { 19445074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 19455074e1d5SCristian Dumitrescu return; 19465074e1d5SCristian Dumitrescu } 19475074e1d5SCristian Dumitrescu 19485074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "stats")) { 19495074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats"); 19505074e1d5SCristian Dumitrescu return; 19515074e1d5SCristian Dumitrescu } 19525074e1d5SCristian Dumitrescu 19535074e1d5SCristian Dumitrescu status = rte_swx_ctl_pipeline_info_get(p->p, &info); 19545074e1d5SCristian Dumitrescu if (status) { 19555074e1d5SCristian Dumitrescu snprintf(out, out_size, "Pipeline info get error."); 19565074e1d5SCristian Dumitrescu return; 19575074e1d5SCristian Dumitrescu } 19585074e1d5SCristian Dumitrescu 19595074e1d5SCristian Dumitrescu snprintf(out, out_size, "Input ports:\n"); 19605074e1d5SCristian Dumitrescu out_size -= strlen(out); 19615074e1d5SCristian Dumitrescu out += strlen(out); 19625074e1d5SCristian Dumitrescu 19635074e1d5SCristian Dumitrescu for (i = 0; i < info.n_ports_in; i++) { 19645074e1d5SCristian Dumitrescu struct rte_swx_port_in_stats stats; 19655074e1d5SCristian Dumitrescu 19665074e1d5SCristian Dumitrescu rte_swx_ctl_pipeline_port_in_stats_read(p->p, i, &stats); 19675074e1d5SCristian Dumitrescu 19685074e1d5SCristian Dumitrescu snprintf(out, out_size, "\tPort %u:" 19695074e1d5SCristian Dumitrescu " packets %" PRIu64 19705074e1d5SCristian Dumitrescu " bytes %" PRIu64 19715074e1d5SCristian Dumitrescu " empty %" PRIu64 "\n", 19725074e1d5SCristian Dumitrescu i, stats.n_pkts, stats.n_bytes, stats.n_empty); 19735074e1d5SCristian Dumitrescu out_size -= strlen(out); 19745074e1d5SCristian Dumitrescu out += strlen(out); 19755074e1d5SCristian Dumitrescu } 19765074e1d5SCristian Dumitrescu 1977742b0a57SCristian Dumitrescu snprintf(out, out_size, "\nOutput ports:\n"); 19785074e1d5SCristian Dumitrescu out_size -= strlen(out); 19795074e1d5SCristian Dumitrescu out += strlen(out); 19805074e1d5SCristian Dumitrescu 19815074e1d5SCristian Dumitrescu for (i = 0; i < info.n_ports_out; i++) { 19825074e1d5SCristian Dumitrescu struct rte_swx_port_out_stats stats; 19835074e1d5SCristian Dumitrescu 19845074e1d5SCristian Dumitrescu rte_swx_ctl_pipeline_port_out_stats_read(p->p, i, &stats); 19855074e1d5SCristian Dumitrescu 19865074e1d5SCristian Dumitrescu snprintf(out, out_size, "\tPort %u:" 19875074e1d5SCristian Dumitrescu " packets %" PRIu64 19885074e1d5SCristian Dumitrescu " bytes %" PRIu64 "\n", 19895074e1d5SCristian Dumitrescu i, stats.n_pkts, stats.n_bytes); 19905074e1d5SCristian Dumitrescu out_size -= strlen(out); 19915074e1d5SCristian Dumitrescu out += strlen(out); 19925074e1d5SCristian Dumitrescu } 1993742b0a57SCristian Dumitrescu 1994742b0a57SCristian Dumitrescu snprintf(out, out_size, "\nTables:\n"); 1995742b0a57SCristian Dumitrescu out_size -= strlen(out); 1996742b0a57SCristian Dumitrescu out += strlen(out); 1997742b0a57SCristian Dumitrescu 1998742b0a57SCristian Dumitrescu for (i = 0; i < info.n_tables; i++) { 1999742b0a57SCristian Dumitrescu struct rte_swx_ctl_table_info table_info; 2000742b0a57SCristian Dumitrescu uint64_t n_pkts_action[info.n_actions]; 2001742b0a57SCristian Dumitrescu struct rte_swx_table_stats stats = { 2002742b0a57SCristian Dumitrescu .n_pkts_hit = 0, 2003742b0a57SCristian Dumitrescu .n_pkts_miss = 0, 2004742b0a57SCristian Dumitrescu .n_pkts_action = n_pkts_action, 2005742b0a57SCristian Dumitrescu }; 2006742b0a57SCristian Dumitrescu uint32_t j; 2007742b0a57SCristian Dumitrescu 2008742b0a57SCristian Dumitrescu status = rte_swx_ctl_table_info_get(p->p, i, &table_info); 2009742b0a57SCristian Dumitrescu if (status) { 2010742b0a57SCristian Dumitrescu snprintf(out, out_size, "Table info get error."); 2011742b0a57SCristian Dumitrescu return; 2012742b0a57SCristian Dumitrescu } 2013742b0a57SCristian Dumitrescu 2014742b0a57SCristian Dumitrescu status = rte_swx_ctl_pipeline_table_stats_read(p->p, table_info.name, &stats); 2015742b0a57SCristian Dumitrescu if (status) { 2016742b0a57SCristian Dumitrescu snprintf(out, out_size, "Table stats read error."); 2017742b0a57SCristian Dumitrescu return; 2018742b0a57SCristian Dumitrescu } 2019742b0a57SCristian Dumitrescu 2020742b0a57SCristian Dumitrescu snprintf(out, out_size, "\tTable %s:\n" 2021742b0a57SCristian Dumitrescu "\t\tHit (packets): %" PRIu64 "\n" 2022742b0a57SCristian Dumitrescu "\t\tMiss (packets): %" PRIu64 "\n", 2023742b0a57SCristian Dumitrescu table_info.name, 2024742b0a57SCristian Dumitrescu stats.n_pkts_hit, 2025742b0a57SCristian Dumitrescu stats.n_pkts_miss); 2026742b0a57SCristian Dumitrescu out_size -= strlen(out); 2027742b0a57SCristian Dumitrescu out += strlen(out); 2028742b0a57SCristian Dumitrescu 2029742b0a57SCristian Dumitrescu for (j = 0; j < info.n_actions; j++) { 2030742b0a57SCristian Dumitrescu struct rte_swx_ctl_action_info action_info; 2031742b0a57SCristian Dumitrescu 2032742b0a57SCristian Dumitrescu status = rte_swx_ctl_action_info_get(p->p, j, &action_info); 2033742b0a57SCristian Dumitrescu if (status) { 2034742b0a57SCristian Dumitrescu snprintf(out, out_size, "Action info get error."); 2035742b0a57SCristian Dumitrescu return; 2036742b0a57SCristian Dumitrescu } 2037742b0a57SCristian Dumitrescu 2038742b0a57SCristian Dumitrescu snprintf(out, out_size, "\t\tAction %s (packets): %" PRIu64 "\n", 2039742b0a57SCristian Dumitrescu action_info.name, 2040742b0a57SCristian Dumitrescu stats.n_pkts_action[j]); 2041742b0a57SCristian Dumitrescu out_size -= strlen(out); 2042742b0a57SCristian Dumitrescu out += strlen(out); 2043742b0a57SCristian Dumitrescu } 2044742b0a57SCristian Dumitrescu } 20455074e1d5SCristian Dumitrescu } 20465074e1d5SCristian Dumitrescu 20475074e1d5SCristian Dumitrescu static const char cmd_thread_pipeline_enable_help[] = 20485074e1d5SCristian Dumitrescu "thread <thread_id> pipeline <pipeline_name> enable\n"; 20495074e1d5SCristian Dumitrescu 20505074e1d5SCristian Dumitrescu static void 20515074e1d5SCristian Dumitrescu cmd_thread_pipeline_enable(char **tokens, 20525074e1d5SCristian Dumitrescu uint32_t n_tokens, 20535074e1d5SCristian Dumitrescu char *out, 20545074e1d5SCristian Dumitrescu size_t out_size, 20555074e1d5SCristian Dumitrescu void *obj) 20565074e1d5SCristian Dumitrescu { 20575074e1d5SCristian Dumitrescu char *pipeline_name; 20585074e1d5SCristian Dumitrescu struct pipeline *p; 20595074e1d5SCristian Dumitrescu uint32_t thread_id; 20605074e1d5SCristian Dumitrescu int status; 20615074e1d5SCristian Dumitrescu 20625074e1d5SCristian Dumitrescu if (n_tokens != 5) { 20635074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 20645074e1d5SCristian Dumitrescu return; 20655074e1d5SCristian Dumitrescu } 20665074e1d5SCristian Dumitrescu 20675074e1d5SCristian Dumitrescu if (parser_read_uint32(&thread_id, tokens[1]) != 0) { 20685074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "thread_id"); 20695074e1d5SCristian Dumitrescu return; 20705074e1d5SCristian Dumitrescu } 20715074e1d5SCristian Dumitrescu 20725074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "pipeline") != 0) { 20735074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline"); 20745074e1d5SCristian Dumitrescu return; 20755074e1d5SCristian Dumitrescu } 20765074e1d5SCristian Dumitrescu 20775074e1d5SCristian Dumitrescu pipeline_name = tokens[3]; 20785074e1d5SCristian Dumitrescu p = pipeline_find(obj, pipeline_name); 20795074e1d5SCristian Dumitrescu if (!p || !p->ctl) { 20805074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 20815074e1d5SCristian Dumitrescu return; 20825074e1d5SCristian Dumitrescu } 20835074e1d5SCristian Dumitrescu 20845074e1d5SCristian Dumitrescu if (strcmp(tokens[4], "enable") != 0) { 20855074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable"); 20865074e1d5SCristian Dumitrescu return; 20875074e1d5SCristian Dumitrescu } 20885074e1d5SCristian Dumitrescu 20895074e1d5SCristian Dumitrescu status = thread_pipeline_enable(thread_id, obj, pipeline_name); 20905074e1d5SCristian Dumitrescu if (status) { 20915074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable"); 20925074e1d5SCristian Dumitrescu return; 20935074e1d5SCristian Dumitrescu } 20945074e1d5SCristian Dumitrescu } 20955074e1d5SCristian Dumitrescu 20965074e1d5SCristian Dumitrescu static const char cmd_thread_pipeline_disable_help[] = 20975074e1d5SCristian Dumitrescu "thread <thread_id> pipeline <pipeline_name> disable\n"; 20985074e1d5SCristian Dumitrescu 20995074e1d5SCristian Dumitrescu static void 21005074e1d5SCristian Dumitrescu cmd_thread_pipeline_disable(char **tokens, 21015074e1d5SCristian Dumitrescu uint32_t n_tokens, 21025074e1d5SCristian Dumitrescu char *out, 21035074e1d5SCristian Dumitrescu size_t out_size, 21045074e1d5SCristian Dumitrescu void *obj) 21055074e1d5SCristian Dumitrescu { 21065074e1d5SCristian Dumitrescu struct pipeline *p; 21075074e1d5SCristian Dumitrescu char *pipeline_name; 21085074e1d5SCristian Dumitrescu uint32_t thread_id; 21095074e1d5SCristian Dumitrescu int status; 21105074e1d5SCristian Dumitrescu 21115074e1d5SCristian Dumitrescu if (n_tokens != 5) { 21125074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 21135074e1d5SCristian Dumitrescu return; 21145074e1d5SCristian Dumitrescu } 21155074e1d5SCristian Dumitrescu 21165074e1d5SCristian Dumitrescu if (parser_read_uint32(&thread_id, tokens[1]) != 0) { 21175074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "thread_id"); 21185074e1d5SCristian Dumitrescu return; 21195074e1d5SCristian Dumitrescu } 21205074e1d5SCristian Dumitrescu 21215074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "pipeline") != 0) { 21225074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline"); 21235074e1d5SCristian Dumitrescu return; 21245074e1d5SCristian Dumitrescu } 21255074e1d5SCristian Dumitrescu 21265074e1d5SCristian Dumitrescu pipeline_name = tokens[3]; 21275074e1d5SCristian Dumitrescu p = pipeline_find(obj, pipeline_name); 21285074e1d5SCristian Dumitrescu if (!p || !p->ctl) { 21295074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 21305074e1d5SCristian Dumitrescu return; 21315074e1d5SCristian Dumitrescu } 21325074e1d5SCristian Dumitrescu 21335074e1d5SCristian Dumitrescu if (strcmp(tokens[4], "disable") != 0) { 21345074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable"); 21355074e1d5SCristian Dumitrescu return; 21365074e1d5SCristian Dumitrescu } 21375074e1d5SCristian Dumitrescu 21385074e1d5SCristian Dumitrescu status = thread_pipeline_disable(thread_id, obj, pipeline_name); 21395074e1d5SCristian Dumitrescu if (status) { 21405074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, 21415074e1d5SCristian Dumitrescu "thread pipeline disable"); 21425074e1d5SCristian Dumitrescu return; 21435074e1d5SCristian Dumitrescu } 21445074e1d5SCristian Dumitrescu } 21455074e1d5SCristian Dumitrescu 21465074e1d5SCristian Dumitrescu static void 21475074e1d5SCristian Dumitrescu cmd_help(char **tokens, 21485074e1d5SCristian Dumitrescu uint32_t n_tokens, 21495074e1d5SCristian Dumitrescu char *out, 21505074e1d5SCristian Dumitrescu size_t out_size, 21515074e1d5SCristian Dumitrescu void *arg __rte_unused) 21525074e1d5SCristian Dumitrescu { 21535074e1d5SCristian Dumitrescu tokens++; 21545074e1d5SCristian Dumitrescu n_tokens--; 21555074e1d5SCristian Dumitrescu 21565074e1d5SCristian Dumitrescu if (n_tokens == 0) { 21575074e1d5SCristian Dumitrescu snprintf(out, out_size, 21587fef9ef1SYogesh Jangra "Type 'help <command>' for command details.\n\n" 21597fef9ef1SYogesh Jangra "List of commands:\n" 21607fef9ef1SYogesh Jangra "\tmempool\n" 21617fef9ef1SYogesh Jangra "\tlink\n" 2162e2b8dc52SVenkata Suresh Kumar P "\ttap\n" 21637fef9ef1SYogesh Jangra "\tpipeline create\n" 21647fef9ef1SYogesh Jangra "\tpipeline port in\n" 21657fef9ef1SYogesh Jangra "\tpipeline port out\n" 21667fef9ef1SYogesh Jangra "\tpipeline build\n" 2167*75129cebSChurchill Khangar "\tpipeline table add\n" 2168*75129cebSChurchill Khangar "\tpipeline table delete\n" 2169*75129cebSChurchill Khangar "\tpipeline table default\n" 2170*75129cebSChurchill Khangar "\tpipeline table show\n" 2171*75129cebSChurchill Khangar "\tpipeline commit\n" 2172*75129cebSChurchill Khangar "\tpipeline abort\n" 217364cfcebdSCristian Dumitrescu "\tpipeline regrd\n" 217464cfcebdSCristian Dumitrescu "\tpipeline regwr\n" 2175f38913b7SCristian Dumitrescu "\tpipeline meter profile add\n" 2176f38913b7SCristian Dumitrescu "\tpipeline meter profile delete\n" 2177f38913b7SCristian Dumitrescu "\tpipeline meter reset\n" 2178f38913b7SCristian Dumitrescu "\tpipeline meter set\n" 2179f38913b7SCristian Dumitrescu "\tpipeline meter stats\n" 21807fef9ef1SYogesh Jangra "\tpipeline stats\n" 21817fef9ef1SYogesh Jangra "\tthread pipeline enable\n" 21827fef9ef1SYogesh Jangra "\tthread pipeline disable\n\n"); 21835074e1d5SCristian Dumitrescu return; 21845074e1d5SCristian Dumitrescu } 21855074e1d5SCristian Dumitrescu 21865074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "mempool") == 0) { 21875074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_mempool_help); 21885074e1d5SCristian Dumitrescu return; 21895074e1d5SCristian Dumitrescu } 21905074e1d5SCristian Dumitrescu 21915074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "link") == 0) { 21925074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_link_help); 21935074e1d5SCristian Dumitrescu return; 21945074e1d5SCristian Dumitrescu } 21955074e1d5SCristian Dumitrescu 219677a41301SCristian Dumitrescu if (strcmp(tokens[0], "ring") == 0) { 219777a41301SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_ring_help); 219877a41301SCristian Dumitrescu return; 219977a41301SCristian Dumitrescu } 220077a41301SCristian Dumitrescu 2201e2b8dc52SVenkata Suresh Kumar P if (strcmp(tokens[0], "tap") == 0) { 2202e2b8dc52SVenkata Suresh Kumar P snprintf(out, out_size, "\n%s\n", cmd_tap_help); 2203e2b8dc52SVenkata Suresh Kumar P return; 2204e2b8dc52SVenkata Suresh Kumar P } 2205e2b8dc52SVenkata Suresh Kumar P 22065074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 22077fef9ef1SYogesh Jangra (n_tokens == 2) && (strcmp(tokens[1], "create") == 0)) { 22085074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_create_help); 22095074e1d5SCristian Dumitrescu return; 22105074e1d5SCristian Dumitrescu } 22115074e1d5SCristian Dumitrescu 22125074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 22137fef9ef1SYogesh Jangra (n_tokens == 3) && (strcmp(tokens[1], "port") == 0)) { 22147fef9ef1SYogesh Jangra if (strcmp(tokens[2], "in") == 0) { 22155074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 22165074e1d5SCristian Dumitrescu cmd_pipeline_port_in_help); 22175074e1d5SCristian Dumitrescu return; 22185074e1d5SCristian Dumitrescu } 22195074e1d5SCristian Dumitrescu 22207fef9ef1SYogesh Jangra if (strcmp(tokens[2], "out") == 0) { 22215074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 22225074e1d5SCristian Dumitrescu cmd_pipeline_port_out_help); 22235074e1d5SCristian Dumitrescu return; 22245074e1d5SCristian Dumitrescu } 22255074e1d5SCristian Dumitrescu } 22265074e1d5SCristian Dumitrescu 22275074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 22287fef9ef1SYogesh Jangra (n_tokens == 2) && (strcmp(tokens[1], "build") == 0)) { 22295074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_build_help); 22305074e1d5SCristian Dumitrescu return; 22315074e1d5SCristian Dumitrescu } 22325074e1d5SCristian Dumitrescu 22335074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 22347fef9ef1SYogesh Jangra (n_tokens == 3) && 22357fef9ef1SYogesh Jangra (strcmp(tokens[1], "table") == 0) && 2236*75129cebSChurchill Khangar (strcmp(tokens[2], "add") == 0)) { 22375074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 2238*75129cebSChurchill Khangar cmd_pipeline_table_add_help); 2239*75129cebSChurchill Khangar return; 2240*75129cebSChurchill Khangar } 2241*75129cebSChurchill Khangar 2242*75129cebSChurchill Khangar if ((strcmp(tokens[0], "pipeline") == 0) && 2243*75129cebSChurchill Khangar (n_tokens == 3) && 2244*75129cebSChurchill Khangar (strcmp(tokens[1], "table") == 0) && 2245*75129cebSChurchill Khangar (strcmp(tokens[2], "delete") == 0)) { 2246*75129cebSChurchill Khangar snprintf(out, out_size, "\n%s\n", 2247*75129cebSChurchill Khangar cmd_pipeline_table_delete_help); 2248*75129cebSChurchill Khangar return; 2249*75129cebSChurchill Khangar } 2250*75129cebSChurchill Khangar 2251*75129cebSChurchill Khangar if ((strcmp(tokens[0], "pipeline") == 0) && 2252*75129cebSChurchill Khangar (n_tokens == 3) && 2253*75129cebSChurchill Khangar (strcmp(tokens[1], "table") == 0) && 2254*75129cebSChurchill Khangar (strcmp(tokens[2], "default") == 0)) { 2255*75129cebSChurchill Khangar snprintf(out, out_size, "\n%s\n", 2256*75129cebSChurchill Khangar cmd_pipeline_table_default_help); 2257*75129cebSChurchill Khangar return; 2258*75129cebSChurchill Khangar } 2259*75129cebSChurchill Khangar 2260*75129cebSChurchill Khangar if ((strcmp(tokens[0], "pipeline") == 0) && 2261*75129cebSChurchill Khangar (n_tokens == 3) && 2262*75129cebSChurchill Khangar (strcmp(tokens[1], "table") == 0) && 2263*75129cebSChurchill Khangar (strcmp(tokens[2], "show") == 0)) { 2264*75129cebSChurchill Khangar snprintf(out, out_size, "\n%s\n", 2265*75129cebSChurchill Khangar cmd_pipeline_table_show_help); 2266*75129cebSChurchill Khangar return; 2267*75129cebSChurchill Khangar } 2268*75129cebSChurchill Khangar 2269*75129cebSChurchill Khangar if ((strcmp(tokens[0], "pipeline") == 0) && 2270*75129cebSChurchill Khangar (n_tokens == 2) && 2271*75129cebSChurchill Khangar (strcmp(tokens[1], "commit") == 0)) { 2272*75129cebSChurchill Khangar snprintf(out, out_size, "\n%s\n", 2273*75129cebSChurchill Khangar cmd_pipeline_commit_help); 2274*75129cebSChurchill Khangar return; 2275*75129cebSChurchill Khangar } 2276*75129cebSChurchill Khangar 2277*75129cebSChurchill Khangar if ((strcmp(tokens[0], "pipeline") == 0) && 2278*75129cebSChurchill Khangar (n_tokens == 2) && 2279*75129cebSChurchill Khangar (strcmp(tokens[1], "abort") == 0)) { 2280*75129cebSChurchill Khangar snprintf(out, out_size, "\n%s\n", 2281*75129cebSChurchill Khangar cmd_pipeline_abort_help); 22825074e1d5SCristian Dumitrescu return; 22835074e1d5SCristian Dumitrescu } 22845074e1d5SCristian Dumitrescu 22855074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 228664cfcebdSCristian Dumitrescu (n_tokens == 2) && (strcmp(tokens[1], "regrd") == 0)) { 228764cfcebdSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_regrd_help); 228864cfcebdSCristian Dumitrescu return; 228964cfcebdSCristian Dumitrescu } 229064cfcebdSCristian Dumitrescu 229164cfcebdSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 229264cfcebdSCristian Dumitrescu (n_tokens == 2) && (strcmp(tokens[1], "regwr") == 0)) { 229364cfcebdSCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_regwr_help); 229464cfcebdSCristian Dumitrescu return; 229564cfcebdSCristian Dumitrescu } 229664cfcebdSCristian Dumitrescu 2297f38913b7SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") && 2298f38913b7SCristian Dumitrescu (n_tokens == 4) && !strcmp(tokens[1], "meter") 2299f38913b7SCristian Dumitrescu && !strcmp(tokens[2], "profile") 2300f38913b7SCristian Dumitrescu && !strcmp(tokens[3], "add")) { 2301f38913b7SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_profile_add_help); 2302f38913b7SCristian Dumitrescu return; 2303f38913b7SCristian Dumitrescu } 2304f38913b7SCristian Dumitrescu 2305f38913b7SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") && 2306f38913b7SCristian Dumitrescu (n_tokens == 4) && !strcmp(tokens[1], "meter") 2307f38913b7SCristian Dumitrescu && !strcmp(tokens[2], "profile") 2308f38913b7SCristian Dumitrescu && !strcmp(tokens[3], "delete")) { 2309f38913b7SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_profile_delete_help); 2310f38913b7SCristian Dumitrescu return; 2311f38913b7SCristian Dumitrescu } 2312f38913b7SCristian Dumitrescu 2313f38913b7SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") && 2314f38913b7SCristian Dumitrescu (n_tokens == 3) && !strcmp(tokens[1], "meter") 2315f38913b7SCristian Dumitrescu && !strcmp(tokens[2], "reset")) { 2316f38913b7SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_reset_help); 2317f38913b7SCristian Dumitrescu return; 2318f38913b7SCristian Dumitrescu } 2319f38913b7SCristian Dumitrescu 2320f38913b7SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") && 2321f38913b7SCristian Dumitrescu (n_tokens == 3) && !strcmp(tokens[1], "meter") 2322f38913b7SCristian Dumitrescu && !strcmp(tokens[2], "set")) { 2323f38913b7SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_set_help); 2324f38913b7SCristian Dumitrescu return; 2325f38913b7SCristian Dumitrescu } 2326f38913b7SCristian Dumitrescu 2327f38913b7SCristian Dumitrescu if (!strcmp(tokens[0], "pipeline") && 2328f38913b7SCristian Dumitrescu (n_tokens == 3) && !strcmp(tokens[1], "meter") 2329f38913b7SCristian Dumitrescu && !strcmp(tokens[2], "stats")) { 2330f38913b7SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_stats_help); 2331f38913b7SCristian Dumitrescu return; 2332f38913b7SCristian Dumitrescu } 2333f38913b7SCristian Dumitrescu 233464cfcebdSCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 23357fef9ef1SYogesh Jangra (n_tokens == 2) && (strcmp(tokens[1], "stats") == 0)) { 23365074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_stats_help); 23375074e1d5SCristian Dumitrescu return; 23385074e1d5SCristian Dumitrescu } 23395074e1d5SCristian Dumitrescu 23405074e1d5SCristian Dumitrescu if ((n_tokens == 3) && 23415074e1d5SCristian Dumitrescu (strcmp(tokens[0], "thread") == 0) && 23425074e1d5SCristian Dumitrescu (strcmp(tokens[1], "pipeline") == 0)) { 23435074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "enable") == 0) { 23445074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 23455074e1d5SCristian Dumitrescu cmd_thread_pipeline_enable_help); 23465074e1d5SCristian Dumitrescu return; 23475074e1d5SCristian Dumitrescu } 23485074e1d5SCristian Dumitrescu 23495074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "disable") == 0) { 23505074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 23515074e1d5SCristian Dumitrescu cmd_thread_pipeline_disable_help); 23525074e1d5SCristian Dumitrescu return; 23535074e1d5SCristian Dumitrescu } 23545074e1d5SCristian Dumitrescu } 23555074e1d5SCristian Dumitrescu 23565074e1d5SCristian Dumitrescu snprintf(out, out_size, "Invalid command\n"); 23575074e1d5SCristian Dumitrescu } 23585074e1d5SCristian Dumitrescu 23595074e1d5SCristian Dumitrescu void 23605074e1d5SCristian Dumitrescu cli_process(char *in, char *out, size_t out_size, void *obj) 23615074e1d5SCristian Dumitrescu { 23625074e1d5SCristian Dumitrescu char *tokens[CMD_MAX_TOKENS]; 23635074e1d5SCristian Dumitrescu uint32_t n_tokens = RTE_DIM(tokens); 23645074e1d5SCristian Dumitrescu int status; 23655074e1d5SCristian Dumitrescu 23665074e1d5SCristian Dumitrescu if (is_comment(in)) 23675074e1d5SCristian Dumitrescu return; 23685074e1d5SCristian Dumitrescu 23695074e1d5SCristian Dumitrescu status = parse_tokenize_string(in, tokens, &n_tokens); 23705074e1d5SCristian Dumitrescu if (status) { 23715074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_TOO_MANY, ""); 23725074e1d5SCristian Dumitrescu return; 23735074e1d5SCristian Dumitrescu } 23745074e1d5SCristian Dumitrescu 23755074e1d5SCristian Dumitrescu if (n_tokens == 0) 23765074e1d5SCristian Dumitrescu return; 23775074e1d5SCristian Dumitrescu 23785074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "help") == 0) { 23795074e1d5SCristian Dumitrescu cmd_help(tokens, n_tokens, out, out_size, obj); 23805074e1d5SCristian Dumitrescu return; 23815074e1d5SCristian Dumitrescu } 23825074e1d5SCristian Dumitrescu 23835074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "mempool") == 0) { 23845074e1d5SCristian Dumitrescu cmd_mempool(tokens, n_tokens, out, out_size, obj); 23855074e1d5SCristian Dumitrescu return; 23865074e1d5SCristian Dumitrescu } 23875074e1d5SCristian Dumitrescu 23885074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "link") == 0) { 2389821848f5SCristian Dumitrescu if ((n_tokens >= 2) && (strcmp(tokens[1], "show") == 0)) { 23905074e1d5SCristian Dumitrescu cmd_link_show(tokens, n_tokens, out, out_size, obj); 23915074e1d5SCristian Dumitrescu return; 23925074e1d5SCristian Dumitrescu } 23935074e1d5SCristian Dumitrescu 23945074e1d5SCristian Dumitrescu cmd_link(tokens, n_tokens, out, out_size, obj); 23955074e1d5SCristian Dumitrescu return; 23965074e1d5SCristian Dumitrescu } 23975074e1d5SCristian Dumitrescu 239877a41301SCristian Dumitrescu if (strcmp(tokens[0], "ring") == 0) { 239977a41301SCristian Dumitrescu cmd_ring(tokens, n_tokens, out, out_size, obj); 240077a41301SCristian Dumitrescu return; 240177a41301SCristian Dumitrescu } 240277a41301SCristian Dumitrescu 2403e2b8dc52SVenkata Suresh Kumar P if (strcmp(tokens[0], "tap") == 0) { 2404e2b8dc52SVenkata Suresh Kumar P cmd_tap(tokens, n_tokens, out, out_size, obj); 2405e2b8dc52SVenkata Suresh Kumar P return; 2406e2b8dc52SVenkata Suresh Kumar P } 2407e2b8dc52SVenkata Suresh Kumar P 24085074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "pipeline") == 0) { 24095074e1d5SCristian Dumitrescu if ((n_tokens >= 3) && 24105074e1d5SCristian Dumitrescu (strcmp(tokens[2], "create") == 0)) { 24115074e1d5SCristian Dumitrescu cmd_pipeline_create(tokens, n_tokens, out, out_size, 24125074e1d5SCristian Dumitrescu obj); 24135074e1d5SCristian Dumitrescu return; 24145074e1d5SCristian Dumitrescu } 24155074e1d5SCristian Dumitrescu 24165074e1d5SCristian Dumitrescu if ((n_tokens >= 4) && 24175074e1d5SCristian Dumitrescu (strcmp(tokens[2], "port") == 0) && 24185074e1d5SCristian Dumitrescu (strcmp(tokens[3], "in") == 0)) { 24195074e1d5SCristian Dumitrescu cmd_pipeline_port_in(tokens, n_tokens, out, out_size, 24205074e1d5SCristian Dumitrescu obj); 24215074e1d5SCristian Dumitrescu return; 24225074e1d5SCristian Dumitrescu } 24235074e1d5SCristian Dumitrescu 24245074e1d5SCristian Dumitrescu if ((n_tokens >= 4) && 24255074e1d5SCristian Dumitrescu (strcmp(tokens[2], "port") == 0) && 24265074e1d5SCristian Dumitrescu (strcmp(tokens[3], "out") == 0)) { 24275074e1d5SCristian Dumitrescu cmd_pipeline_port_out(tokens, n_tokens, out, out_size, 24285074e1d5SCristian Dumitrescu obj); 24295074e1d5SCristian Dumitrescu return; 24305074e1d5SCristian Dumitrescu } 24315074e1d5SCristian Dumitrescu 24325074e1d5SCristian Dumitrescu if ((n_tokens >= 3) && 24335074e1d5SCristian Dumitrescu (strcmp(tokens[2], "build") == 0)) { 24345074e1d5SCristian Dumitrescu cmd_pipeline_build(tokens, n_tokens, out, out_size, 24355074e1d5SCristian Dumitrescu obj); 24365074e1d5SCristian Dumitrescu return; 24375074e1d5SCristian Dumitrescu } 24385074e1d5SCristian Dumitrescu 2439*75129cebSChurchill Khangar if ((n_tokens >= 5) && 2440*75129cebSChurchill Khangar (strcmp(tokens[2], "table") == 0) && 2441*75129cebSChurchill Khangar (strcmp(tokens[4], "add") == 0)) { 2442*75129cebSChurchill Khangar cmd_pipeline_table_add(tokens, n_tokens, out, 2443*75129cebSChurchill Khangar out_size, obj); 2444*75129cebSChurchill Khangar return; 2445*75129cebSChurchill Khangar } 2446*75129cebSChurchill Khangar 2447*75129cebSChurchill Khangar if ((n_tokens >= 5) && 2448*75129cebSChurchill Khangar (strcmp(tokens[2], "table") == 0) && 2449*75129cebSChurchill Khangar (strcmp(tokens[4], "delete") == 0)) { 2450*75129cebSChurchill Khangar cmd_pipeline_table_delete(tokens, n_tokens, out, 2451*75129cebSChurchill Khangar out_size, obj); 2452*75129cebSChurchill Khangar return; 2453*75129cebSChurchill Khangar } 2454*75129cebSChurchill Khangar 2455*75129cebSChurchill Khangar if ((n_tokens >= 5) && 2456*75129cebSChurchill Khangar (strcmp(tokens[2], "table") == 0) && 2457*75129cebSChurchill Khangar (strcmp(tokens[4], "default") == 0)) { 2458*75129cebSChurchill Khangar cmd_pipeline_table_default(tokens, n_tokens, out, 2459*75129cebSChurchill Khangar out_size, obj); 2460*75129cebSChurchill Khangar return; 2461*75129cebSChurchill Khangar } 2462*75129cebSChurchill Khangar 2463*75129cebSChurchill Khangar if ((n_tokens >= 5) && 2464*75129cebSChurchill Khangar (strcmp(tokens[2], "table") == 0) && 2465*75129cebSChurchill Khangar (strcmp(tokens[4], "show") == 0)) { 2466*75129cebSChurchill Khangar cmd_pipeline_table_show(tokens, n_tokens, out, 2467*75129cebSChurchill Khangar out_size, obj); 2468*75129cebSChurchill Khangar return; 2469*75129cebSChurchill Khangar } 2470*75129cebSChurchill Khangar 24715074e1d5SCristian Dumitrescu if ((n_tokens >= 3) && 2472*75129cebSChurchill Khangar (strcmp(tokens[2], "commit") == 0)) { 2473*75129cebSChurchill Khangar cmd_pipeline_commit(tokens, n_tokens, out, 2474*75129cebSChurchill Khangar out_size, obj); 2475*75129cebSChurchill Khangar return; 2476*75129cebSChurchill Khangar } 2477*75129cebSChurchill Khangar 2478*75129cebSChurchill Khangar if ((n_tokens >= 3) && 2479*75129cebSChurchill Khangar (strcmp(tokens[2], "abort") == 0)) { 2480*75129cebSChurchill Khangar cmd_pipeline_abort(tokens, n_tokens, out, 24815074e1d5SCristian Dumitrescu out_size, obj); 24825074e1d5SCristian Dumitrescu return; 24835074e1d5SCristian Dumitrescu } 24845074e1d5SCristian Dumitrescu 24855074e1d5SCristian Dumitrescu if ((n_tokens >= 3) && 248664cfcebdSCristian Dumitrescu (strcmp(tokens[2], "regrd") == 0)) { 248764cfcebdSCristian Dumitrescu cmd_pipeline_regrd(tokens, n_tokens, out, out_size, obj); 248864cfcebdSCristian Dumitrescu return; 248964cfcebdSCristian Dumitrescu } 249064cfcebdSCristian Dumitrescu 249164cfcebdSCristian Dumitrescu if ((n_tokens >= 3) && 249264cfcebdSCristian Dumitrescu (strcmp(tokens[2], "regwr") == 0)) { 249364cfcebdSCristian Dumitrescu cmd_pipeline_regwr(tokens, n_tokens, out, out_size, obj); 249464cfcebdSCristian Dumitrescu return; 249564cfcebdSCristian Dumitrescu } 249664cfcebdSCristian Dumitrescu 2497f38913b7SCristian Dumitrescu if ((n_tokens >= 6) && 2498f38913b7SCristian Dumitrescu (strcmp(tokens[2], "meter") == 0) && 2499f38913b7SCristian Dumitrescu (strcmp(tokens[3], "profile") == 0) && 2500f38913b7SCristian Dumitrescu (strcmp(tokens[5], "add") == 0)) { 2501f38913b7SCristian Dumitrescu cmd_pipeline_meter_profile_add(tokens, n_tokens, out, out_size, obj); 2502f38913b7SCristian Dumitrescu return; 2503f38913b7SCristian Dumitrescu } 2504f38913b7SCristian Dumitrescu 2505f38913b7SCristian Dumitrescu if ((n_tokens >= 6) && 2506f38913b7SCristian Dumitrescu (strcmp(tokens[2], "meter") == 0) && 2507f38913b7SCristian Dumitrescu (strcmp(tokens[3], "profile") == 0) && 2508f38913b7SCristian Dumitrescu (strcmp(tokens[5], "delete") == 0)) { 2509f38913b7SCristian Dumitrescu cmd_pipeline_meter_profile_delete(tokens, n_tokens, out, out_size, obj); 2510f38913b7SCristian Dumitrescu return; 2511f38913b7SCristian Dumitrescu } 2512f38913b7SCristian Dumitrescu 2513f38913b7SCristian Dumitrescu if ((n_tokens >= 9) && 2514f38913b7SCristian Dumitrescu (strcmp(tokens[2], "meter") == 0) && 2515f38913b7SCristian Dumitrescu (strcmp(tokens[8], "reset") == 0)) { 2516f38913b7SCristian Dumitrescu cmd_pipeline_meter_reset(tokens, n_tokens, out, out_size, obj); 2517f38913b7SCristian Dumitrescu return; 2518f38913b7SCristian Dumitrescu } 2519f38913b7SCristian Dumitrescu 2520f38913b7SCristian Dumitrescu if ((n_tokens >= 9) && 2521f38913b7SCristian Dumitrescu (strcmp(tokens[2], "meter") == 0) && 2522f38913b7SCristian Dumitrescu (strcmp(tokens[8], "set") == 0)) { 2523f38913b7SCristian Dumitrescu cmd_pipeline_meter_set(tokens, n_tokens, out, out_size, obj); 2524f38913b7SCristian Dumitrescu return; 2525f38913b7SCristian Dumitrescu } 2526f38913b7SCristian Dumitrescu 2527f38913b7SCristian Dumitrescu if ((n_tokens >= 9) && 2528f38913b7SCristian Dumitrescu (strcmp(tokens[2], "meter") == 0) && 2529f38913b7SCristian Dumitrescu (strcmp(tokens[8], "stats") == 0)) { 2530f38913b7SCristian Dumitrescu cmd_pipeline_meter_stats(tokens, n_tokens, out, out_size, obj); 2531f38913b7SCristian Dumitrescu return; 2532f38913b7SCristian Dumitrescu } 2533f38913b7SCristian Dumitrescu 253464cfcebdSCristian Dumitrescu if ((n_tokens >= 3) && 25355074e1d5SCristian Dumitrescu (strcmp(tokens[2], "stats") == 0)) { 25365074e1d5SCristian Dumitrescu cmd_pipeline_stats(tokens, n_tokens, out, out_size, 25375074e1d5SCristian Dumitrescu obj); 25385074e1d5SCristian Dumitrescu return; 25395074e1d5SCristian Dumitrescu } 25405074e1d5SCristian Dumitrescu } 25415074e1d5SCristian Dumitrescu 25425074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "thread") == 0) { 25435074e1d5SCristian Dumitrescu if ((n_tokens >= 5) && 25445074e1d5SCristian Dumitrescu (strcmp(tokens[4], "enable") == 0)) { 25455074e1d5SCristian Dumitrescu cmd_thread_pipeline_enable(tokens, n_tokens, 25465074e1d5SCristian Dumitrescu out, out_size, obj); 25475074e1d5SCristian Dumitrescu return; 25485074e1d5SCristian Dumitrescu } 25495074e1d5SCristian Dumitrescu 25505074e1d5SCristian Dumitrescu if ((n_tokens >= 5) && 25515074e1d5SCristian Dumitrescu (strcmp(tokens[4], "disable") == 0)) { 25525074e1d5SCristian Dumitrescu cmd_thread_pipeline_disable(tokens, n_tokens, 25535074e1d5SCristian Dumitrescu out, out_size, obj); 25545074e1d5SCristian Dumitrescu return; 25555074e1d5SCristian Dumitrescu } 25565074e1d5SCristian Dumitrescu } 25575074e1d5SCristian Dumitrescu 25585074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]); 25595074e1d5SCristian Dumitrescu } 25605074e1d5SCristian Dumitrescu 25615074e1d5SCristian Dumitrescu int 25625074e1d5SCristian Dumitrescu cli_script_process(const char *file_name, 25635074e1d5SCristian Dumitrescu size_t msg_in_len_max, 25645074e1d5SCristian Dumitrescu size_t msg_out_len_max, 25655074e1d5SCristian Dumitrescu void *obj) 25665074e1d5SCristian Dumitrescu { 25675074e1d5SCristian Dumitrescu char *msg_in = NULL, *msg_out = NULL; 25685074e1d5SCristian Dumitrescu FILE *f = NULL; 25695074e1d5SCristian Dumitrescu 25705074e1d5SCristian Dumitrescu /* Check input arguments */ 25715074e1d5SCristian Dumitrescu if ((file_name == NULL) || 25725074e1d5SCristian Dumitrescu (strlen(file_name) == 0) || 25735074e1d5SCristian Dumitrescu (msg_in_len_max == 0) || 25745074e1d5SCristian Dumitrescu (msg_out_len_max == 0)) 25755074e1d5SCristian Dumitrescu return -EINVAL; 25765074e1d5SCristian Dumitrescu 25775074e1d5SCristian Dumitrescu msg_in = malloc(msg_in_len_max + 1); 25785074e1d5SCristian Dumitrescu msg_out = malloc(msg_out_len_max + 1); 25795074e1d5SCristian Dumitrescu if ((msg_in == NULL) || 25805074e1d5SCristian Dumitrescu (msg_out == NULL)) { 25815074e1d5SCristian Dumitrescu free(msg_out); 25825074e1d5SCristian Dumitrescu free(msg_in); 25835074e1d5SCristian Dumitrescu return -ENOMEM; 25845074e1d5SCristian Dumitrescu } 25855074e1d5SCristian Dumitrescu 25865074e1d5SCristian Dumitrescu /* Open input file */ 25875074e1d5SCristian Dumitrescu f = fopen(file_name, "r"); 25885074e1d5SCristian Dumitrescu if (f == NULL) { 25895074e1d5SCristian Dumitrescu free(msg_out); 25905074e1d5SCristian Dumitrescu free(msg_in); 25915074e1d5SCristian Dumitrescu return -EIO; 25925074e1d5SCristian Dumitrescu } 25935074e1d5SCristian Dumitrescu 25945074e1d5SCristian Dumitrescu /* Read file */ 25955074e1d5SCristian Dumitrescu for ( ; ; ) { 25965074e1d5SCristian Dumitrescu if (fgets(msg_in, msg_in_len_max + 1, f) == NULL) 25975074e1d5SCristian Dumitrescu break; 25985074e1d5SCristian Dumitrescu 25995074e1d5SCristian Dumitrescu printf("%s", msg_in); 26005074e1d5SCristian Dumitrescu msg_out[0] = 0; 26015074e1d5SCristian Dumitrescu 26025074e1d5SCristian Dumitrescu cli_process(msg_in, 26035074e1d5SCristian Dumitrescu msg_out, 26045074e1d5SCristian Dumitrescu msg_out_len_max, 26055074e1d5SCristian Dumitrescu obj); 26065074e1d5SCristian Dumitrescu 26075074e1d5SCristian Dumitrescu if (strlen(msg_out)) 26085074e1d5SCristian Dumitrescu printf("%s", msg_out); 26095074e1d5SCristian Dumitrescu } 26105074e1d5SCristian Dumitrescu 26115074e1d5SCristian Dumitrescu /* Close file */ 26125074e1d5SCristian Dumitrescu fclose(f); 26135074e1d5SCristian Dumitrescu free(msg_out); 26145074e1d5SCristian Dumitrescu free(msg_in); 26155074e1d5SCristian Dumitrescu return 0; 26165074e1d5SCristian Dumitrescu } 2617