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> 155074e1d5SCristian Dumitrescu #include <rte_swx_pipeline.h> 165074e1d5SCristian Dumitrescu #include <rte_swx_ctl.h> 175074e1d5SCristian Dumitrescu 185074e1d5SCristian Dumitrescu #include "cli.h" 195074e1d5SCristian Dumitrescu 205074e1d5SCristian Dumitrescu #include "obj.h" 215074e1d5SCristian Dumitrescu #include "thread.h" 225074e1d5SCristian Dumitrescu 235074e1d5SCristian Dumitrescu #ifndef CMD_MAX_TOKENS 245074e1d5SCristian Dumitrescu #define CMD_MAX_TOKENS 256 255074e1d5SCristian Dumitrescu #endif 265074e1d5SCristian Dumitrescu 275074e1d5SCristian Dumitrescu #define MSG_OUT_OF_MEMORY "Not enough memory.\n" 285074e1d5SCristian Dumitrescu #define MSG_CMD_UNKNOWN "Unknown command \"%s\".\n" 295074e1d5SCristian Dumitrescu #define MSG_CMD_UNIMPLEM "Command \"%s\" not implemented.\n" 305074e1d5SCristian Dumitrescu #define MSG_ARG_NOT_ENOUGH "Not enough arguments for command \"%s\".\n" 315074e1d5SCristian Dumitrescu #define MSG_ARG_TOO_MANY "Too many arguments for command \"%s\".\n" 325074e1d5SCristian Dumitrescu #define MSG_ARG_MISMATCH "Wrong number of arguments for command \"%s\".\n" 335074e1d5SCristian Dumitrescu #define MSG_ARG_NOT_FOUND "Argument \"%s\" not found.\n" 345074e1d5SCristian Dumitrescu #define MSG_ARG_INVALID "Invalid value for argument \"%s\".\n" 355074e1d5SCristian Dumitrescu #define MSG_FILE_ERR "Error in file \"%s\" at line %u.\n" 365074e1d5SCristian Dumitrescu #define MSG_FILE_NOT_ENOUGH "Not enough rules in file \"%s\".\n" 375074e1d5SCristian Dumitrescu #define MSG_CMD_FAIL "Command \"%s\" failed.\n" 385074e1d5SCristian Dumitrescu 395074e1d5SCristian Dumitrescu #define skip_white_spaces(pos) \ 405074e1d5SCristian Dumitrescu ({ \ 415074e1d5SCristian Dumitrescu __typeof__(pos) _p = (pos); \ 425074e1d5SCristian Dumitrescu for ( ; isspace(*_p); _p++) \ 435074e1d5SCristian Dumitrescu ; \ 445074e1d5SCristian Dumitrescu _p; \ 455074e1d5SCristian Dumitrescu }) 465074e1d5SCristian Dumitrescu 475074e1d5SCristian Dumitrescu static int 485074e1d5SCristian Dumitrescu parser_read_uint64(uint64_t *value, const char *p) 495074e1d5SCristian Dumitrescu { 505074e1d5SCristian Dumitrescu char *next; 515074e1d5SCristian Dumitrescu uint64_t val; 525074e1d5SCristian Dumitrescu 535074e1d5SCristian Dumitrescu p = skip_white_spaces(p); 545074e1d5SCristian Dumitrescu if (!isdigit(*p)) 555074e1d5SCristian Dumitrescu return -EINVAL; 565074e1d5SCristian Dumitrescu 575074e1d5SCristian Dumitrescu val = strtoul(p, &next, 10); 585074e1d5SCristian Dumitrescu if (p == next) 595074e1d5SCristian Dumitrescu return -EINVAL; 605074e1d5SCristian Dumitrescu 615074e1d5SCristian Dumitrescu p = next; 625074e1d5SCristian Dumitrescu switch (*p) { 635074e1d5SCristian Dumitrescu case 'T': 645074e1d5SCristian Dumitrescu val *= 1024ULL; 655074e1d5SCristian Dumitrescu /* fall through */ 665074e1d5SCristian Dumitrescu case 'G': 675074e1d5SCristian Dumitrescu val *= 1024ULL; 685074e1d5SCristian Dumitrescu /* fall through */ 695074e1d5SCristian Dumitrescu case 'M': 705074e1d5SCristian Dumitrescu val *= 1024ULL; 715074e1d5SCristian Dumitrescu /* fall through */ 725074e1d5SCristian Dumitrescu case 'k': 735074e1d5SCristian Dumitrescu case 'K': 745074e1d5SCristian Dumitrescu val *= 1024ULL; 755074e1d5SCristian Dumitrescu p++; 765074e1d5SCristian Dumitrescu break; 775074e1d5SCristian Dumitrescu } 785074e1d5SCristian Dumitrescu 795074e1d5SCristian Dumitrescu p = skip_white_spaces(p); 805074e1d5SCristian Dumitrescu if (*p != '\0') 815074e1d5SCristian Dumitrescu return -EINVAL; 825074e1d5SCristian Dumitrescu 835074e1d5SCristian Dumitrescu *value = val; 845074e1d5SCristian Dumitrescu return 0; 855074e1d5SCristian Dumitrescu } 865074e1d5SCristian Dumitrescu 875074e1d5SCristian Dumitrescu static int 885074e1d5SCristian Dumitrescu parser_read_uint32(uint32_t *value, const char *p) 895074e1d5SCristian Dumitrescu { 905074e1d5SCristian Dumitrescu uint64_t val = 0; 915074e1d5SCristian Dumitrescu int ret = parser_read_uint64(&val, p); 925074e1d5SCristian Dumitrescu 935074e1d5SCristian Dumitrescu if (ret < 0) 945074e1d5SCristian Dumitrescu return ret; 955074e1d5SCristian Dumitrescu 965074e1d5SCristian Dumitrescu if (val > UINT32_MAX) 975074e1d5SCristian Dumitrescu return -ERANGE; 985074e1d5SCristian Dumitrescu 995074e1d5SCristian Dumitrescu *value = val; 1005074e1d5SCristian Dumitrescu return 0; 1015074e1d5SCristian Dumitrescu } 1025074e1d5SCristian Dumitrescu 1035074e1d5SCristian Dumitrescu static int 1045074e1d5SCristian Dumitrescu parser_read_uint16(uint16_t *value, const char *p) 1055074e1d5SCristian Dumitrescu { 1065074e1d5SCristian Dumitrescu uint64_t val = 0; 1075074e1d5SCristian Dumitrescu int ret = parser_read_uint64(&val, p); 1085074e1d5SCristian Dumitrescu 1095074e1d5SCristian Dumitrescu if (ret < 0) 1105074e1d5SCristian Dumitrescu return ret; 1115074e1d5SCristian Dumitrescu 1125074e1d5SCristian Dumitrescu if (val > UINT16_MAX) 1135074e1d5SCristian Dumitrescu return -ERANGE; 1145074e1d5SCristian Dumitrescu 1155074e1d5SCristian Dumitrescu *value = val; 1165074e1d5SCristian Dumitrescu return 0; 1175074e1d5SCristian Dumitrescu } 1185074e1d5SCristian Dumitrescu 1195074e1d5SCristian Dumitrescu #define PARSE_DELIMITER " \f\n\r\t\v" 1205074e1d5SCristian Dumitrescu 1215074e1d5SCristian Dumitrescu static int 1225074e1d5SCristian Dumitrescu parse_tokenize_string(char *string, char *tokens[], uint32_t *n_tokens) 1235074e1d5SCristian Dumitrescu { 1245074e1d5SCristian Dumitrescu uint32_t i; 1255074e1d5SCristian Dumitrescu 1265074e1d5SCristian Dumitrescu if ((string == NULL) || 1275074e1d5SCristian Dumitrescu (tokens == NULL) || 1285074e1d5SCristian Dumitrescu (*n_tokens < 1)) 1295074e1d5SCristian Dumitrescu return -EINVAL; 1305074e1d5SCristian Dumitrescu 1315074e1d5SCristian Dumitrescu for (i = 0; i < *n_tokens; i++) { 1325074e1d5SCristian Dumitrescu tokens[i] = strtok_r(string, PARSE_DELIMITER, &string); 1335074e1d5SCristian Dumitrescu if (tokens[i] == NULL) 1345074e1d5SCristian Dumitrescu break; 1355074e1d5SCristian Dumitrescu } 1365074e1d5SCristian Dumitrescu 1375074e1d5SCristian Dumitrescu if ((i == *n_tokens) && strtok_r(string, PARSE_DELIMITER, &string)) 1385074e1d5SCristian Dumitrescu return -E2BIG; 1395074e1d5SCristian Dumitrescu 1405074e1d5SCristian Dumitrescu *n_tokens = i; 1415074e1d5SCristian Dumitrescu return 0; 1425074e1d5SCristian Dumitrescu } 1435074e1d5SCristian Dumitrescu 1445074e1d5SCristian Dumitrescu static int 1455074e1d5SCristian Dumitrescu is_comment(char *in) 1465074e1d5SCristian Dumitrescu { 1475074e1d5SCristian Dumitrescu if ((strlen(in) && index("!#%;", in[0])) || 1485074e1d5SCristian Dumitrescu (strncmp(in, "//", 2) == 0) || 1495074e1d5SCristian Dumitrescu (strncmp(in, "--", 2) == 0)) 1505074e1d5SCristian Dumitrescu return 1; 1515074e1d5SCristian Dumitrescu 1525074e1d5SCristian Dumitrescu return 0; 1535074e1d5SCristian Dumitrescu } 1545074e1d5SCristian Dumitrescu 1555074e1d5SCristian Dumitrescu static const char cmd_mempool_help[] = 1565074e1d5SCristian Dumitrescu "mempool <mempool_name>\n" 1575074e1d5SCristian Dumitrescu " buffer <buffer_size>\n" 1585074e1d5SCristian Dumitrescu " pool <pool_size>\n" 1595074e1d5SCristian Dumitrescu " cache <cache_size>\n" 1605074e1d5SCristian Dumitrescu " cpu <cpu_id>\n"; 1615074e1d5SCristian Dumitrescu 1625074e1d5SCristian Dumitrescu static void 1635074e1d5SCristian Dumitrescu cmd_mempool(char **tokens, 1645074e1d5SCristian Dumitrescu uint32_t n_tokens, 1655074e1d5SCristian Dumitrescu char *out, 1665074e1d5SCristian Dumitrescu size_t out_size, 1675074e1d5SCristian Dumitrescu void *obj) 1685074e1d5SCristian Dumitrescu { 1695074e1d5SCristian Dumitrescu struct mempool_params p; 1705074e1d5SCristian Dumitrescu char *name; 1715074e1d5SCristian Dumitrescu struct mempool *mempool; 1725074e1d5SCristian Dumitrescu 1735074e1d5SCristian Dumitrescu if (n_tokens != 10) { 1745074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 1755074e1d5SCristian Dumitrescu return; 1765074e1d5SCristian Dumitrescu } 1775074e1d5SCristian Dumitrescu 1785074e1d5SCristian Dumitrescu name = tokens[1]; 1795074e1d5SCristian Dumitrescu 1805074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "buffer") != 0) { 1815074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buffer"); 1825074e1d5SCristian Dumitrescu return; 1835074e1d5SCristian Dumitrescu } 1845074e1d5SCristian Dumitrescu 1855074e1d5SCristian Dumitrescu if (parser_read_uint32(&p.buffer_size, tokens[3]) != 0) { 1865074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "buffer_size"); 1875074e1d5SCristian Dumitrescu return; 1885074e1d5SCristian Dumitrescu } 1895074e1d5SCristian Dumitrescu 1905074e1d5SCristian Dumitrescu if (strcmp(tokens[4], "pool") != 0) { 1915074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pool"); 1925074e1d5SCristian Dumitrescu return; 1935074e1d5SCristian Dumitrescu } 1945074e1d5SCristian Dumitrescu 1955074e1d5SCristian Dumitrescu if (parser_read_uint32(&p.pool_size, tokens[5]) != 0) { 1965074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pool_size"); 1975074e1d5SCristian Dumitrescu return; 1985074e1d5SCristian Dumitrescu } 1995074e1d5SCristian Dumitrescu 2005074e1d5SCristian Dumitrescu if (strcmp(tokens[6], "cache") != 0) { 2015074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cache"); 2025074e1d5SCristian Dumitrescu return; 2035074e1d5SCristian Dumitrescu } 2045074e1d5SCristian Dumitrescu 2055074e1d5SCristian Dumitrescu if (parser_read_uint32(&p.cache_size, tokens[7]) != 0) { 2065074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "cache_size"); 2075074e1d5SCristian Dumitrescu return; 2085074e1d5SCristian Dumitrescu } 2095074e1d5SCristian Dumitrescu 2105074e1d5SCristian Dumitrescu if (strcmp(tokens[8], "cpu") != 0) { 2115074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu"); 2125074e1d5SCristian Dumitrescu return; 2135074e1d5SCristian Dumitrescu } 2145074e1d5SCristian Dumitrescu 2155074e1d5SCristian Dumitrescu if (parser_read_uint32(&p.cpu_id, tokens[9]) != 0) { 2165074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id"); 2175074e1d5SCristian Dumitrescu return; 2185074e1d5SCristian Dumitrescu } 2195074e1d5SCristian Dumitrescu 2205074e1d5SCristian Dumitrescu mempool = mempool_create(obj, name, &p); 2215074e1d5SCristian Dumitrescu if (mempool == NULL) { 2225074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]); 2235074e1d5SCristian Dumitrescu return; 2245074e1d5SCristian Dumitrescu } 2255074e1d5SCristian Dumitrescu } 2265074e1d5SCristian Dumitrescu 2275074e1d5SCristian Dumitrescu static const char cmd_link_help[] = 2285074e1d5SCristian Dumitrescu "link <link_name>\n" 2295074e1d5SCristian Dumitrescu " dev <device_name> | port <port_id>\n" 2305074e1d5SCristian Dumitrescu " rxq <n_queues> <queue_size> <mempool_name>\n" 2315074e1d5SCristian Dumitrescu " txq <n_queues> <queue_size>\n" 2325074e1d5SCristian Dumitrescu " promiscuous on | off\n" 2335074e1d5SCristian Dumitrescu " [rss <qid_0> ... <qid_n>]\n"; 2345074e1d5SCristian Dumitrescu 2355074e1d5SCristian Dumitrescu static void 2365074e1d5SCristian Dumitrescu cmd_link(char **tokens, 2375074e1d5SCristian Dumitrescu uint32_t n_tokens, 2385074e1d5SCristian Dumitrescu char *out, 2395074e1d5SCristian Dumitrescu size_t out_size, 2405074e1d5SCristian Dumitrescu void *obj) 2415074e1d5SCristian Dumitrescu { 2425074e1d5SCristian Dumitrescu struct link_params p; 2435074e1d5SCristian Dumitrescu struct link_params_rss rss; 2445074e1d5SCristian Dumitrescu struct link *link; 2455074e1d5SCristian Dumitrescu char *name; 2465074e1d5SCristian Dumitrescu 2475074e1d5SCristian Dumitrescu memset(&p, 0, sizeof(p)); 2485074e1d5SCristian Dumitrescu 2495074e1d5SCristian Dumitrescu if ((n_tokens < 13) || (n_tokens > 14 + LINK_RXQ_RSS_MAX)) { 2505074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 2515074e1d5SCristian Dumitrescu return; 2525074e1d5SCristian Dumitrescu } 2535074e1d5SCristian Dumitrescu name = tokens[1]; 2545074e1d5SCristian Dumitrescu 2555074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "dev") == 0) 2565074e1d5SCristian Dumitrescu p.dev_name = tokens[3]; 2575074e1d5SCristian Dumitrescu else if (strcmp(tokens[2], "port") == 0) { 2585074e1d5SCristian Dumitrescu p.dev_name = NULL; 2595074e1d5SCristian Dumitrescu 2605074e1d5SCristian Dumitrescu if (parser_read_uint16(&p.port_id, tokens[3]) != 0) { 2615074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "port_id"); 2625074e1d5SCristian Dumitrescu return; 2635074e1d5SCristian Dumitrescu } 2645074e1d5SCristian Dumitrescu } else { 2655074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dev or port"); 2665074e1d5SCristian Dumitrescu return; 2675074e1d5SCristian Dumitrescu } 2685074e1d5SCristian Dumitrescu 2695074e1d5SCristian Dumitrescu if (strcmp(tokens[4], "rxq") != 0) { 2705074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq"); 2715074e1d5SCristian Dumitrescu return; 2725074e1d5SCristian Dumitrescu } 2735074e1d5SCristian Dumitrescu 2745074e1d5SCristian Dumitrescu if (parser_read_uint32(&p.rx.n_queues, tokens[5]) != 0) { 2755074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "n_queues"); 2765074e1d5SCristian Dumitrescu return; 2775074e1d5SCristian Dumitrescu } 2785074e1d5SCristian Dumitrescu if (parser_read_uint32(&p.rx.queue_size, tokens[6]) != 0) { 2795074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "queue_size"); 2805074e1d5SCristian Dumitrescu return; 2815074e1d5SCristian Dumitrescu } 2825074e1d5SCristian Dumitrescu 2835074e1d5SCristian Dumitrescu p.rx.mempool_name = tokens[7]; 2845074e1d5SCristian Dumitrescu 2855074e1d5SCristian Dumitrescu if (strcmp(tokens[8], "txq") != 0) { 2865074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq"); 2875074e1d5SCristian Dumitrescu return; 2885074e1d5SCristian Dumitrescu } 2895074e1d5SCristian Dumitrescu 2905074e1d5SCristian Dumitrescu if (parser_read_uint32(&p.tx.n_queues, tokens[9]) != 0) { 2915074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "n_queues"); 2925074e1d5SCristian Dumitrescu return; 2935074e1d5SCristian Dumitrescu } 2945074e1d5SCristian Dumitrescu 2955074e1d5SCristian Dumitrescu if (parser_read_uint32(&p.tx.queue_size, tokens[10]) != 0) { 2965074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "queue_size"); 2975074e1d5SCristian Dumitrescu return; 2985074e1d5SCristian Dumitrescu } 2995074e1d5SCristian Dumitrescu 3005074e1d5SCristian Dumitrescu if (strcmp(tokens[11], "promiscuous") != 0) { 3015074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "promiscuous"); 3025074e1d5SCristian Dumitrescu return; 3035074e1d5SCristian Dumitrescu } 3045074e1d5SCristian Dumitrescu 3055074e1d5SCristian Dumitrescu if (strcmp(tokens[12], "on") == 0) 3065074e1d5SCristian Dumitrescu p.promiscuous = 1; 3075074e1d5SCristian Dumitrescu else if (strcmp(tokens[12], "off") == 0) 3085074e1d5SCristian Dumitrescu p.promiscuous = 0; 3095074e1d5SCristian Dumitrescu else { 3105074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "on or off"); 3115074e1d5SCristian Dumitrescu return; 3125074e1d5SCristian Dumitrescu } 3135074e1d5SCristian Dumitrescu 3145074e1d5SCristian Dumitrescu /* RSS */ 3155074e1d5SCristian Dumitrescu p.rx.rss = NULL; 3165074e1d5SCristian Dumitrescu if (n_tokens > 13) { 3175074e1d5SCristian Dumitrescu uint32_t queue_id, i; 3185074e1d5SCristian Dumitrescu 3195074e1d5SCristian Dumitrescu if (strcmp(tokens[13], "rss") != 0) { 3205074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rss"); 3215074e1d5SCristian Dumitrescu return; 3225074e1d5SCristian Dumitrescu } 3235074e1d5SCristian Dumitrescu 3245074e1d5SCristian Dumitrescu p.rx.rss = &rss; 3255074e1d5SCristian Dumitrescu 3265074e1d5SCristian Dumitrescu rss.n_queues = 0; 3275074e1d5SCristian Dumitrescu for (i = 14; i < n_tokens; i++) { 3285074e1d5SCristian Dumitrescu if (parser_read_uint32(&queue_id, tokens[i]) != 0) { 3295074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, 3305074e1d5SCristian Dumitrescu "queue_id"); 3315074e1d5SCristian Dumitrescu return; 3325074e1d5SCristian Dumitrescu } 3335074e1d5SCristian Dumitrescu 3345074e1d5SCristian Dumitrescu rss.queue_id[rss.n_queues] = queue_id; 3355074e1d5SCristian Dumitrescu rss.n_queues++; 3365074e1d5SCristian Dumitrescu } 3375074e1d5SCristian Dumitrescu } 3385074e1d5SCristian Dumitrescu 3395074e1d5SCristian Dumitrescu link = link_create(obj, name, &p); 3405074e1d5SCristian Dumitrescu if (link == NULL) { 3415074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]); 3425074e1d5SCristian Dumitrescu return; 3435074e1d5SCristian Dumitrescu } 3445074e1d5SCristian Dumitrescu } 3455074e1d5SCristian Dumitrescu 3465074e1d5SCristian Dumitrescu /* Print the link stats and info */ 3475074e1d5SCristian Dumitrescu static void 3485074e1d5SCristian Dumitrescu print_link_info(struct link *link, char *out, size_t out_size) 3495074e1d5SCristian Dumitrescu { 3505074e1d5SCristian Dumitrescu struct rte_eth_stats stats; 3515074e1d5SCristian Dumitrescu struct rte_ether_addr mac_addr; 3525074e1d5SCristian Dumitrescu struct rte_eth_link eth_link; 3535074e1d5SCristian Dumitrescu uint16_t mtu; 3545074e1d5SCristian Dumitrescu int ret; 3555074e1d5SCristian Dumitrescu 3565074e1d5SCristian Dumitrescu memset(&stats, 0, sizeof(stats)); 3575074e1d5SCristian Dumitrescu rte_eth_stats_get(link->port_id, &stats); 3585074e1d5SCristian Dumitrescu 3595074e1d5SCristian Dumitrescu ret = rte_eth_macaddr_get(link->port_id, &mac_addr); 3605074e1d5SCristian Dumitrescu if (ret != 0) { 3615074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s: MAC address get failed: %s", 3625074e1d5SCristian Dumitrescu link->name, rte_strerror(-ret)); 3635074e1d5SCristian Dumitrescu return; 3645074e1d5SCristian Dumitrescu } 3655074e1d5SCristian Dumitrescu 3665074e1d5SCristian Dumitrescu ret = rte_eth_link_get(link->port_id, ð_link); 3675074e1d5SCristian Dumitrescu if (ret < 0) { 3685074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s: link get failed: %s", 3695074e1d5SCristian Dumitrescu link->name, rte_strerror(-ret)); 3705074e1d5SCristian Dumitrescu return; 3715074e1d5SCristian Dumitrescu } 3725074e1d5SCristian Dumitrescu 3735074e1d5SCristian Dumitrescu rte_eth_dev_get_mtu(link->port_id, &mtu); 3745074e1d5SCristian Dumitrescu 3755074e1d5SCristian Dumitrescu snprintf(out, out_size, 3765074e1d5SCristian Dumitrescu "\n" 3775074e1d5SCristian Dumitrescu "%s: flags=<%s> mtu %u\n" 3785074e1d5SCristian Dumitrescu "\tether %02X:%02X:%02X:%02X:%02X:%02X rxqueues %u txqueues %u\n" 3795074e1d5SCristian Dumitrescu "\tport# %u speed %s\n" 3805074e1d5SCristian Dumitrescu "\tRX packets %" PRIu64" bytes %" PRIu64"\n" 3815074e1d5SCristian Dumitrescu "\tRX errors %" PRIu64" missed %" PRIu64" no-mbuf %" PRIu64"\n" 3825074e1d5SCristian Dumitrescu "\tTX packets %" PRIu64" bytes %" PRIu64"\n" 3835074e1d5SCristian Dumitrescu "\tTX errors %" PRIu64"\n", 3845074e1d5SCristian Dumitrescu link->name, 3855074e1d5SCristian Dumitrescu eth_link.link_status == 0 ? "DOWN" : "UP", 3865074e1d5SCristian Dumitrescu mtu, 3875074e1d5SCristian Dumitrescu mac_addr.addr_bytes[0], mac_addr.addr_bytes[1], 3885074e1d5SCristian Dumitrescu mac_addr.addr_bytes[2], mac_addr.addr_bytes[3], 3895074e1d5SCristian Dumitrescu mac_addr.addr_bytes[4], mac_addr.addr_bytes[5], 3905074e1d5SCristian Dumitrescu link->n_rxq, 3915074e1d5SCristian Dumitrescu link->n_txq, 3925074e1d5SCristian Dumitrescu link->port_id, 3935074e1d5SCristian Dumitrescu rte_eth_link_speed_to_str(eth_link.link_speed), 3945074e1d5SCristian Dumitrescu stats.ipackets, 3955074e1d5SCristian Dumitrescu stats.ibytes, 3965074e1d5SCristian Dumitrescu stats.ierrors, 3975074e1d5SCristian Dumitrescu stats.imissed, 3985074e1d5SCristian Dumitrescu stats.rx_nombuf, 3995074e1d5SCristian Dumitrescu stats.opackets, 4005074e1d5SCristian Dumitrescu stats.obytes, 4015074e1d5SCristian Dumitrescu stats.oerrors); 4025074e1d5SCristian Dumitrescu } 4035074e1d5SCristian Dumitrescu 4045074e1d5SCristian Dumitrescu /* 4055074e1d5SCristian Dumitrescu * link show [<link_name>] 4065074e1d5SCristian Dumitrescu */ 4075074e1d5SCristian Dumitrescu static void 4085074e1d5SCristian Dumitrescu cmd_link_show(char **tokens, 4095074e1d5SCristian Dumitrescu uint32_t n_tokens, 4105074e1d5SCristian Dumitrescu char *out, 4115074e1d5SCristian Dumitrescu size_t out_size, 4125074e1d5SCristian Dumitrescu void *obj) 4135074e1d5SCristian Dumitrescu { 4145074e1d5SCristian Dumitrescu struct link *link; 4155074e1d5SCristian Dumitrescu char *link_name; 4165074e1d5SCristian Dumitrescu 4175074e1d5SCristian Dumitrescu if (n_tokens != 2 && n_tokens != 3) { 4185074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 4195074e1d5SCristian Dumitrescu return; 4205074e1d5SCristian Dumitrescu } 4215074e1d5SCristian Dumitrescu 4225074e1d5SCristian Dumitrescu if (n_tokens == 2) { 4235074e1d5SCristian Dumitrescu link = link_next(obj, NULL); 4245074e1d5SCristian Dumitrescu 4255074e1d5SCristian Dumitrescu while (link != NULL) { 4265074e1d5SCristian Dumitrescu out_size = out_size - strlen(out); 4275074e1d5SCristian Dumitrescu out = &out[strlen(out)]; 4285074e1d5SCristian Dumitrescu 4295074e1d5SCristian Dumitrescu print_link_info(link, out, out_size); 4305074e1d5SCristian Dumitrescu link = link_next(obj, link); 4315074e1d5SCristian Dumitrescu } 4325074e1d5SCristian Dumitrescu } else { 4335074e1d5SCristian Dumitrescu out_size = out_size - strlen(out); 4345074e1d5SCristian Dumitrescu out = &out[strlen(out)]; 4355074e1d5SCristian Dumitrescu 4365074e1d5SCristian Dumitrescu link_name = tokens[2]; 4375074e1d5SCristian Dumitrescu link = link_find(obj, link_name); 4385074e1d5SCristian Dumitrescu 4395074e1d5SCristian Dumitrescu if (link == NULL) { 4405074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, 4415074e1d5SCristian Dumitrescu "Link does not exist"); 4425074e1d5SCristian Dumitrescu return; 4435074e1d5SCristian Dumitrescu } 4445074e1d5SCristian Dumitrescu print_link_info(link, out, out_size); 4455074e1d5SCristian Dumitrescu } 4465074e1d5SCristian Dumitrescu } 4475074e1d5SCristian Dumitrescu 44877a41301SCristian Dumitrescu static const char cmd_ring_help[] = 44977a41301SCristian Dumitrescu "ring <ring_name> size <size> numa <numa_node>\n"; 45077a41301SCristian Dumitrescu 45177a41301SCristian Dumitrescu static void 45277a41301SCristian Dumitrescu cmd_ring(char **tokens, 45377a41301SCristian Dumitrescu uint32_t n_tokens, 45477a41301SCristian Dumitrescu char *out, 45577a41301SCristian Dumitrescu size_t out_size, 45677a41301SCristian Dumitrescu void *obj) 45777a41301SCristian Dumitrescu { 45877a41301SCristian Dumitrescu struct ring_params p; 45977a41301SCristian Dumitrescu char *name; 46077a41301SCristian Dumitrescu struct ring *ring; 46177a41301SCristian Dumitrescu 46277a41301SCristian Dumitrescu if (n_tokens != 6) { 46377a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 46477a41301SCristian Dumitrescu return; 46577a41301SCristian Dumitrescu } 46677a41301SCristian Dumitrescu 46777a41301SCristian Dumitrescu name = tokens[1]; 46877a41301SCristian Dumitrescu 46977a41301SCristian Dumitrescu if (strcmp(tokens[2], "size") != 0) { 47077a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size"); 47177a41301SCristian Dumitrescu return; 47277a41301SCristian Dumitrescu } 47377a41301SCristian Dumitrescu 47477a41301SCristian Dumitrescu if (parser_read_uint32(&p.size, tokens[3]) != 0) { 47577a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "size"); 47677a41301SCristian Dumitrescu return; 47777a41301SCristian Dumitrescu } 47877a41301SCristian Dumitrescu 47977a41301SCristian Dumitrescu if (strcmp(tokens[4], "numa") != 0) { 48077a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "numa"); 48177a41301SCristian Dumitrescu return; 48277a41301SCristian Dumitrescu } 48377a41301SCristian Dumitrescu 48477a41301SCristian Dumitrescu if (parser_read_uint32(&p.numa_node, tokens[5]) != 0) { 48577a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "numa_node"); 48677a41301SCristian Dumitrescu return; 48777a41301SCristian Dumitrescu } 48877a41301SCristian Dumitrescu 48977a41301SCristian Dumitrescu ring = ring_create(obj, name, &p); 49077a41301SCristian Dumitrescu if (!ring) { 49177a41301SCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]); 49277a41301SCristian Dumitrescu return; 49377a41301SCristian Dumitrescu } 49477a41301SCristian Dumitrescu } 49577a41301SCristian Dumitrescu 4965074e1d5SCristian Dumitrescu static const char cmd_pipeline_create_help[] = 4975074e1d5SCristian Dumitrescu "pipeline <pipeline_name> create <numa_node>\n"; 4985074e1d5SCristian Dumitrescu 4995074e1d5SCristian Dumitrescu static void 5005074e1d5SCristian Dumitrescu cmd_pipeline_create(char **tokens, 5015074e1d5SCristian Dumitrescu uint32_t n_tokens, 5025074e1d5SCristian Dumitrescu char *out, 5035074e1d5SCristian Dumitrescu size_t out_size, 5045074e1d5SCristian Dumitrescu void *obj) 5055074e1d5SCristian Dumitrescu { 5065074e1d5SCristian Dumitrescu struct pipeline *p; 5075074e1d5SCristian Dumitrescu char *name; 5085074e1d5SCristian Dumitrescu uint32_t numa_node; 5095074e1d5SCristian Dumitrescu 5105074e1d5SCristian Dumitrescu if (n_tokens != 4) { 5115074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 5125074e1d5SCristian Dumitrescu return; 5135074e1d5SCristian Dumitrescu } 5145074e1d5SCristian Dumitrescu 5155074e1d5SCristian Dumitrescu name = tokens[1]; 5165074e1d5SCristian Dumitrescu 5175074e1d5SCristian Dumitrescu if (parser_read_uint32(&numa_node, tokens[3]) != 0) { 5185074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "numa_node"); 5195074e1d5SCristian Dumitrescu return; 5205074e1d5SCristian Dumitrescu } 5215074e1d5SCristian Dumitrescu 5225074e1d5SCristian Dumitrescu p = pipeline_create(obj, name, (int)numa_node); 5235074e1d5SCristian Dumitrescu if (!p) { 5245074e1d5SCristian Dumitrescu snprintf(out, out_size, "pipeline create error."); 5255074e1d5SCristian Dumitrescu return; 5265074e1d5SCristian Dumitrescu } 5275074e1d5SCristian Dumitrescu } 5285074e1d5SCristian Dumitrescu 5295074e1d5SCristian Dumitrescu static const char cmd_pipeline_port_in_help[] = 5305074e1d5SCristian Dumitrescu "pipeline <pipeline_name> port in <port_id>\n" 5315074e1d5SCristian Dumitrescu " link <link_name> rxq <queue_id> bsz <burst_size>\n" 53277a41301SCristian Dumitrescu " ring <ring_name> bsz <burst_size>\n" 5337fef9ef1SYogesh Jangra " | source <mempool_name> <file_name>\n"; 5345074e1d5SCristian Dumitrescu 5355074e1d5SCristian Dumitrescu static void 5365074e1d5SCristian Dumitrescu cmd_pipeline_port_in(char **tokens, 5375074e1d5SCristian Dumitrescu uint32_t n_tokens, 5385074e1d5SCristian Dumitrescu char *out, 5395074e1d5SCristian Dumitrescu size_t out_size, 5405074e1d5SCristian Dumitrescu void *obj) 5415074e1d5SCristian Dumitrescu { 5425074e1d5SCristian Dumitrescu struct pipeline *p; 5435074e1d5SCristian Dumitrescu int status; 5445074e1d5SCristian Dumitrescu uint32_t port_id = 0, t0; 5455074e1d5SCristian Dumitrescu 5465074e1d5SCristian Dumitrescu if (n_tokens < 6) { 5475074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 5485074e1d5SCristian Dumitrescu return; 5495074e1d5SCristian Dumitrescu } 5505074e1d5SCristian Dumitrescu 5515074e1d5SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 5525074e1d5SCristian Dumitrescu if (!p || p->ctl) { 5535074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]); 5545074e1d5SCristian Dumitrescu return; 5555074e1d5SCristian Dumitrescu } 5565074e1d5SCristian Dumitrescu 5575074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "port") != 0) { 5585074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port"); 5595074e1d5SCristian Dumitrescu return; 5605074e1d5SCristian Dumitrescu } 5615074e1d5SCristian Dumitrescu 5625074e1d5SCristian Dumitrescu if (strcmp(tokens[3], "in") != 0) { 5635074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in"); 5645074e1d5SCristian Dumitrescu return; 5655074e1d5SCristian Dumitrescu } 5665074e1d5SCristian Dumitrescu 5675074e1d5SCristian Dumitrescu if (parser_read_uint32(&port_id, tokens[4]) != 0) { 5685074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "port_id"); 5695074e1d5SCristian Dumitrescu return; 5705074e1d5SCristian Dumitrescu } 5715074e1d5SCristian Dumitrescu 5725074e1d5SCristian Dumitrescu t0 = 5; 5735074e1d5SCristian Dumitrescu 5745074e1d5SCristian Dumitrescu if (strcmp(tokens[t0], "link") == 0) { 5755074e1d5SCristian Dumitrescu struct rte_swx_port_ethdev_reader_params params; 5765074e1d5SCristian Dumitrescu struct link *link; 5775074e1d5SCristian Dumitrescu 5785074e1d5SCristian Dumitrescu if (n_tokens < t0 + 6) { 5795074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, 5805074e1d5SCristian Dumitrescu "pipeline port in link"); 5815074e1d5SCristian Dumitrescu return; 5825074e1d5SCristian Dumitrescu } 5835074e1d5SCristian Dumitrescu 5845074e1d5SCristian Dumitrescu link = link_find(obj, tokens[t0 + 1]); 5855074e1d5SCristian Dumitrescu if (!link) { 5865074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, 5875074e1d5SCristian Dumitrescu "link_name"); 5885074e1d5SCristian Dumitrescu return; 5895074e1d5SCristian Dumitrescu } 5905074e1d5SCristian Dumitrescu params.dev_name = link->dev_name; 5915074e1d5SCristian Dumitrescu 5925074e1d5SCristian Dumitrescu if (strcmp(tokens[t0 + 2], "rxq") != 0) { 5935074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq"); 5945074e1d5SCristian Dumitrescu return; 5955074e1d5SCristian Dumitrescu } 5965074e1d5SCristian Dumitrescu 5975074e1d5SCristian Dumitrescu if (parser_read_uint16(¶ms.queue_id, tokens[t0 + 3]) != 0) { 5985074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, 5995074e1d5SCristian Dumitrescu "queue_id"); 6005074e1d5SCristian Dumitrescu return; 6015074e1d5SCristian Dumitrescu } 6025074e1d5SCristian Dumitrescu 6035074e1d5SCristian Dumitrescu if (strcmp(tokens[t0 + 4], "bsz") != 0) { 6045074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz"); 6055074e1d5SCristian Dumitrescu return; 6065074e1d5SCristian Dumitrescu } 6075074e1d5SCristian Dumitrescu 6085074e1d5SCristian Dumitrescu if (parser_read_uint32(¶ms.burst_size, tokens[t0 + 5])) { 6095074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, 6105074e1d5SCristian Dumitrescu "burst_size"); 6115074e1d5SCristian Dumitrescu return; 6125074e1d5SCristian Dumitrescu } 6135074e1d5SCristian Dumitrescu 6145074e1d5SCristian Dumitrescu t0 += 6; 6155074e1d5SCristian Dumitrescu 6165074e1d5SCristian Dumitrescu status = rte_swx_pipeline_port_in_config(p->p, 6175074e1d5SCristian Dumitrescu port_id, 6185074e1d5SCristian Dumitrescu "ethdev", 6195074e1d5SCristian Dumitrescu ¶ms); 62077a41301SCristian Dumitrescu } else if (strcmp(tokens[t0], "ring") == 0) { 62177a41301SCristian Dumitrescu struct rte_swx_port_ring_reader_params params; 62277a41301SCristian Dumitrescu struct ring *ring; 62377a41301SCristian Dumitrescu 62477a41301SCristian Dumitrescu if (n_tokens < t0 + 4) { 62577a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, 62677a41301SCristian Dumitrescu "pipeline port in ring"); 62777a41301SCristian Dumitrescu return; 62877a41301SCristian Dumitrescu } 62977a41301SCristian Dumitrescu 63077a41301SCristian Dumitrescu ring = ring_find(obj, tokens[t0 + 1]); 63177a41301SCristian Dumitrescu if (!ring) { 63277a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, 63377a41301SCristian Dumitrescu "ring_name"); 63477a41301SCristian Dumitrescu return; 63577a41301SCristian Dumitrescu } 63677a41301SCristian Dumitrescu params.name = ring->name; 63777a41301SCristian Dumitrescu 63877a41301SCristian Dumitrescu if (strcmp(tokens[t0 + 2], "bsz") != 0) { 63977a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz"); 64077a41301SCristian Dumitrescu return; 64177a41301SCristian Dumitrescu } 64277a41301SCristian Dumitrescu 64377a41301SCristian Dumitrescu if (parser_read_uint32(¶ms.burst_size, tokens[t0 + 3])) { 64477a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, 64577a41301SCristian Dumitrescu "burst_size"); 64677a41301SCristian Dumitrescu return; 64777a41301SCristian Dumitrescu } 64877a41301SCristian Dumitrescu 64977a41301SCristian Dumitrescu t0 += 4; 65077a41301SCristian Dumitrescu 65177a41301SCristian Dumitrescu status = rte_swx_pipeline_port_in_config(p->p, 65277a41301SCristian Dumitrescu port_id, 65377a41301SCristian Dumitrescu "ring", 65477a41301SCristian Dumitrescu ¶ms); 6555074e1d5SCristian Dumitrescu } else if (strcmp(tokens[t0], "source") == 0) { 6565074e1d5SCristian Dumitrescu struct rte_swx_port_source_params params; 6575074e1d5SCristian Dumitrescu struct mempool *mp; 6585074e1d5SCristian Dumitrescu 6595074e1d5SCristian Dumitrescu if (n_tokens < t0 + 3) { 6605074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, 6615074e1d5SCristian Dumitrescu "pipeline port in source"); 6625074e1d5SCristian Dumitrescu return; 6635074e1d5SCristian Dumitrescu } 6645074e1d5SCristian Dumitrescu 6655074e1d5SCristian Dumitrescu mp = mempool_find(obj, tokens[t0 + 1]); 6665074e1d5SCristian Dumitrescu if (!mp) { 6675074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, 6685074e1d5SCristian Dumitrescu "mempool_name"); 6695074e1d5SCristian Dumitrescu return; 6705074e1d5SCristian Dumitrescu } 6715074e1d5SCristian Dumitrescu params.pool = mp->m; 6725074e1d5SCristian Dumitrescu 6735074e1d5SCristian Dumitrescu params.file_name = tokens[t0 + 2]; 6745074e1d5SCristian Dumitrescu 6755074e1d5SCristian Dumitrescu t0 += 3; 6765074e1d5SCristian Dumitrescu 6775074e1d5SCristian Dumitrescu status = rte_swx_pipeline_port_in_config(p->p, 6785074e1d5SCristian Dumitrescu port_id, 6795074e1d5SCristian Dumitrescu "source", 6805074e1d5SCristian Dumitrescu ¶ms); 6815074e1d5SCristian Dumitrescu } else { 6825074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]); 6835074e1d5SCristian Dumitrescu return; 6845074e1d5SCristian Dumitrescu } 6855074e1d5SCristian Dumitrescu 6865074e1d5SCristian Dumitrescu if (status) { 6875074e1d5SCristian Dumitrescu snprintf(out, out_size, "port in error."); 6885074e1d5SCristian Dumitrescu return; 6895074e1d5SCristian Dumitrescu } 6905074e1d5SCristian Dumitrescu 6915074e1d5SCristian Dumitrescu if (n_tokens != t0) { 6925074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 6935074e1d5SCristian Dumitrescu return; 6945074e1d5SCristian Dumitrescu } 6955074e1d5SCristian Dumitrescu } 6965074e1d5SCristian Dumitrescu 6975074e1d5SCristian Dumitrescu static const char cmd_pipeline_port_out_help[] = 6985074e1d5SCristian Dumitrescu "pipeline <pipeline_name> port out <port_id>\n" 6995074e1d5SCristian Dumitrescu " link <link_name> txq <txq_id> bsz <burst_size>\n" 70077a41301SCristian Dumitrescu " ring <ring_name> bsz <burst_size>\n" 7015074e1d5SCristian Dumitrescu " | sink <file_name> | none\n"; 7025074e1d5SCristian Dumitrescu 7035074e1d5SCristian Dumitrescu static void 7045074e1d5SCristian Dumitrescu cmd_pipeline_port_out(char **tokens, 7055074e1d5SCristian Dumitrescu uint32_t n_tokens, 7065074e1d5SCristian Dumitrescu char *out, 7075074e1d5SCristian Dumitrescu size_t out_size, 7085074e1d5SCristian Dumitrescu void *obj) 7095074e1d5SCristian Dumitrescu { 7105074e1d5SCristian Dumitrescu struct pipeline *p; 7115074e1d5SCristian Dumitrescu int status; 7125074e1d5SCristian Dumitrescu uint32_t port_id = 0, t0; 7135074e1d5SCristian Dumitrescu 7145074e1d5SCristian Dumitrescu if (n_tokens < 6) { 7155074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 7165074e1d5SCristian Dumitrescu return; 7175074e1d5SCristian Dumitrescu } 7185074e1d5SCristian Dumitrescu 7195074e1d5SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 7205074e1d5SCristian Dumitrescu if (!p || p->ctl) { 7215074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]); 7225074e1d5SCristian Dumitrescu return; 7235074e1d5SCristian Dumitrescu } 7245074e1d5SCristian Dumitrescu 7255074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "port") != 0) { 7265074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port"); 7275074e1d5SCristian Dumitrescu return; 7285074e1d5SCristian Dumitrescu } 7295074e1d5SCristian Dumitrescu 7305074e1d5SCristian Dumitrescu if (strcmp(tokens[3], "out") != 0) { 7315074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out"); 7325074e1d5SCristian Dumitrescu return; 7335074e1d5SCristian Dumitrescu } 7345074e1d5SCristian Dumitrescu 7355074e1d5SCristian Dumitrescu if (parser_read_uint32(&port_id, tokens[4]) != 0) { 7365074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "port_id"); 7375074e1d5SCristian Dumitrescu return; 7385074e1d5SCristian Dumitrescu } 7395074e1d5SCristian Dumitrescu 7405074e1d5SCristian Dumitrescu t0 = 5; 7415074e1d5SCristian Dumitrescu 7425074e1d5SCristian Dumitrescu if (strcmp(tokens[t0], "link") == 0) { 7435074e1d5SCristian Dumitrescu struct rte_swx_port_ethdev_writer_params params; 7445074e1d5SCristian Dumitrescu struct link *link; 7455074e1d5SCristian Dumitrescu 7465074e1d5SCristian Dumitrescu if (n_tokens < t0 + 6) { 7475074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, 7485074e1d5SCristian Dumitrescu "pipeline port out link"); 7495074e1d5SCristian Dumitrescu return; 7505074e1d5SCristian Dumitrescu } 7515074e1d5SCristian Dumitrescu 7525074e1d5SCristian Dumitrescu link = link_find(obj, tokens[t0 + 1]); 7535074e1d5SCristian Dumitrescu if (!link) { 7545074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, 7555074e1d5SCristian Dumitrescu "link_name"); 7565074e1d5SCristian Dumitrescu return; 7575074e1d5SCristian Dumitrescu } 7585074e1d5SCristian Dumitrescu params.dev_name = link->dev_name; 7595074e1d5SCristian Dumitrescu 7605074e1d5SCristian Dumitrescu if (strcmp(tokens[t0 + 2], "txq") != 0) { 7615074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq"); 7625074e1d5SCristian Dumitrescu return; 7635074e1d5SCristian Dumitrescu } 7645074e1d5SCristian Dumitrescu 7655074e1d5SCristian Dumitrescu if (parser_read_uint16(¶ms.queue_id, tokens[t0 + 3]) != 0) { 7665074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, 7675074e1d5SCristian Dumitrescu "queue_id"); 7685074e1d5SCristian Dumitrescu return; 7695074e1d5SCristian Dumitrescu } 7705074e1d5SCristian Dumitrescu 7715074e1d5SCristian Dumitrescu if (strcmp(tokens[t0 + 4], "bsz") != 0) { 7725074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz"); 7735074e1d5SCristian Dumitrescu return; 7745074e1d5SCristian Dumitrescu } 7755074e1d5SCristian Dumitrescu 7765074e1d5SCristian Dumitrescu if (parser_read_uint32(¶ms.burst_size, tokens[t0 + 5])) { 7775074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, 7785074e1d5SCristian Dumitrescu "burst_size"); 7795074e1d5SCristian Dumitrescu return; 7805074e1d5SCristian Dumitrescu } 7815074e1d5SCristian Dumitrescu 7825074e1d5SCristian Dumitrescu t0 += 6; 7835074e1d5SCristian Dumitrescu 7845074e1d5SCristian Dumitrescu status = rte_swx_pipeline_port_out_config(p->p, 7855074e1d5SCristian Dumitrescu port_id, 7865074e1d5SCristian Dumitrescu "ethdev", 7875074e1d5SCristian Dumitrescu ¶ms); 78877a41301SCristian Dumitrescu } else if (strcmp(tokens[t0], "ring") == 0) { 78977a41301SCristian Dumitrescu struct rte_swx_port_ring_writer_params params; 79077a41301SCristian Dumitrescu struct ring *ring; 79177a41301SCristian Dumitrescu 79277a41301SCristian Dumitrescu if (n_tokens < t0 + 4) { 79377a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, 79477a41301SCristian Dumitrescu "pipeline port out link"); 79577a41301SCristian Dumitrescu return; 79677a41301SCristian Dumitrescu } 79777a41301SCristian Dumitrescu 79877a41301SCristian Dumitrescu ring = ring_find(obj, tokens[t0 + 1]); 79977a41301SCristian Dumitrescu if (!ring) { 80077a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, 80177a41301SCristian Dumitrescu "ring_name"); 80277a41301SCristian Dumitrescu return; 80377a41301SCristian Dumitrescu } 80477a41301SCristian Dumitrescu params.name = ring->name; 80577a41301SCristian Dumitrescu 80677a41301SCristian Dumitrescu if (strcmp(tokens[t0 + 2], "bsz") != 0) { 80777a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz"); 80877a41301SCristian Dumitrescu return; 80977a41301SCristian Dumitrescu } 81077a41301SCristian Dumitrescu 81177a41301SCristian Dumitrescu if (parser_read_uint32(¶ms.burst_size, tokens[t0 + 3])) { 81277a41301SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, 81377a41301SCristian Dumitrescu "burst_size"); 81477a41301SCristian Dumitrescu return; 81577a41301SCristian Dumitrescu } 81677a41301SCristian Dumitrescu 81777a41301SCristian Dumitrescu t0 += 4; 81877a41301SCristian Dumitrescu 81977a41301SCristian Dumitrescu status = rte_swx_pipeline_port_out_config(p->p, 82077a41301SCristian Dumitrescu port_id, 82177a41301SCristian Dumitrescu "ring", 82277a41301SCristian Dumitrescu ¶ms); 8235074e1d5SCristian Dumitrescu } else if (strcmp(tokens[t0], "sink") == 0) { 8245074e1d5SCristian Dumitrescu struct rte_swx_port_sink_params params; 8255074e1d5SCristian Dumitrescu 8265074e1d5SCristian Dumitrescu params.file_name = strcmp(tokens[t0 + 1], "none") ? 8275074e1d5SCristian Dumitrescu tokens[t0 + 1] : NULL; 8285074e1d5SCristian Dumitrescu 8295074e1d5SCristian Dumitrescu t0 += 2; 8305074e1d5SCristian Dumitrescu 8315074e1d5SCristian Dumitrescu status = rte_swx_pipeline_port_out_config(p->p, 8325074e1d5SCristian Dumitrescu port_id, 8335074e1d5SCristian Dumitrescu "sink", 8345074e1d5SCristian Dumitrescu ¶ms); 8355074e1d5SCristian Dumitrescu } else { 8365074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]); 8375074e1d5SCristian Dumitrescu return; 8385074e1d5SCristian Dumitrescu } 8395074e1d5SCristian Dumitrescu 8405074e1d5SCristian Dumitrescu if (status) { 8415074e1d5SCristian Dumitrescu snprintf(out, out_size, "port out error."); 8425074e1d5SCristian Dumitrescu return; 8435074e1d5SCristian Dumitrescu } 8445074e1d5SCristian Dumitrescu 8455074e1d5SCristian Dumitrescu if (n_tokens != t0) { 8465074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 8475074e1d5SCristian Dumitrescu return; 8485074e1d5SCristian Dumitrescu } 8495074e1d5SCristian Dumitrescu } 8505074e1d5SCristian Dumitrescu 8515074e1d5SCristian Dumitrescu static const char cmd_pipeline_build_help[] = 8525074e1d5SCristian Dumitrescu "pipeline <pipeline_name> build <spec_file>\n"; 8535074e1d5SCristian Dumitrescu 8545074e1d5SCristian Dumitrescu static void 8555074e1d5SCristian Dumitrescu cmd_pipeline_build(char **tokens, 8565074e1d5SCristian Dumitrescu uint32_t n_tokens, 8575074e1d5SCristian Dumitrescu char *out, 8585074e1d5SCristian Dumitrescu size_t out_size, 8595074e1d5SCristian Dumitrescu void *obj) 8605074e1d5SCristian Dumitrescu { 8615074e1d5SCristian Dumitrescu struct pipeline *p = NULL; 8625074e1d5SCristian Dumitrescu FILE *spec = NULL; 8635074e1d5SCristian Dumitrescu uint32_t err_line; 8645074e1d5SCristian Dumitrescu const char *err_msg; 8655074e1d5SCristian Dumitrescu int status; 8665074e1d5SCristian Dumitrescu 8675074e1d5SCristian Dumitrescu if (n_tokens != 4) { 8685074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 8695074e1d5SCristian Dumitrescu return; 8705074e1d5SCristian Dumitrescu } 8715074e1d5SCristian Dumitrescu 8725074e1d5SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 8735074e1d5SCristian Dumitrescu if (!p || p->ctl) { 8745074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]); 8755074e1d5SCristian Dumitrescu return; 8765074e1d5SCristian Dumitrescu } 8775074e1d5SCristian Dumitrescu 8785074e1d5SCristian Dumitrescu spec = fopen(tokens[3], "r"); 8795074e1d5SCristian Dumitrescu if (!spec) { 8805074e1d5SCristian Dumitrescu snprintf(out, out_size, "Cannot open file %s.\n", tokens[3]); 8815074e1d5SCristian Dumitrescu return; 8825074e1d5SCristian Dumitrescu } 8835074e1d5SCristian Dumitrescu 8845074e1d5SCristian Dumitrescu status = rte_swx_pipeline_build_from_spec(p->p, 8855074e1d5SCristian Dumitrescu spec, 8865074e1d5SCristian Dumitrescu &err_line, 8875074e1d5SCristian Dumitrescu &err_msg); 8885074e1d5SCristian Dumitrescu fclose(spec); 8895074e1d5SCristian Dumitrescu if (status) { 8905074e1d5SCristian Dumitrescu snprintf(out, out_size, "Error %d at line %u: %s\n.", 8915074e1d5SCristian Dumitrescu status, err_line, err_msg); 8925074e1d5SCristian Dumitrescu return; 8935074e1d5SCristian Dumitrescu } 8945074e1d5SCristian Dumitrescu 8955074e1d5SCristian Dumitrescu p->ctl = rte_swx_ctl_pipeline_create(p->p); 8965074e1d5SCristian Dumitrescu if (!p->ctl) { 8975074e1d5SCristian Dumitrescu snprintf(out, out_size, "Pipeline control create failed."); 8985074e1d5SCristian Dumitrescu rte_swx_pipeline_free(p->p); 8995074e1d5SCristian Dumitrescu return; 9005074e1d5SCristian Dumitrescu } 9015074e1d5SCristian Dumitrescu } 9025074e1d5SCristian Dumitrescu 903275ebefeSCristian Dumitrescu static void 904275ebefeSCristian Dumitrescu table_entry_free(struct rte_swx_table_entry *entry) 905275ebefeSCristian Dumitrescu { 906275ebefeSCristian Dumitrescu if (!entry) 907275ebefeSCristian Dumitrescu return; 908275ebefeSCristian Dumitrescu 909275ebefeSCristian Dumitrescu free(entry->key); 910275ebefeSCristian Dumitrescu free(entry->key_mask); 911275ebefeSCristian Dumitrescu free(entry->action_data); 912275ebefeSCristian Dumitrescu free(entry); 913275ebefeSCristian Dumitrescu } 914275ebefeSCristian Dumitrescu 9155074e1d5SCristian Dumitrescu static const char cmd_pipeline_table_update_help[] = 9165074e1d5SCristian Dumitrescu "pipeline <pipeline_name> table <table_name> update <file_name_add> " 9175074e1d5SCristian Dumitrescu "<file_name_delete> <file_name_default>"; 9185074e1d5SCristian Dumitrescu 9195074e1d5SCristian Dumitrescu static void 9205074e1d5SCristian Dumitrescu cmd_pipeline_table_update(char **tokens, 9215074e1d5SCristian Dumitrescu uint32_t n_tokens, 9225074e1d5SCristian Dumitrescu char *out, 9235074e1d5SCristian Dumitrescu size_t out_size, 9245074e1d5SCristian Dumitrescu void *obj) 9255074e1d5SCristian Dumitrescu { 9265074e1d5SCristian Dumitrescu struct pipeline *p; 9275074e1d5SCristian Dumitrescu char *pipeline_name, *table_name, *line = NULL; 9285074e1d5SCristian Dumitrescu char *file_name_add, *file_name_delete, *file_name_default; 9295074e1d5SCristian Dumitrescu FILE *file_add = NULL, *file_delete = NULL, *file_default = NULL; 9305074e1d5SCristian Dumitrescu uint32_t line_id; 9315074e1d5SCristian Dumitrescu int status; 9325074e1d5SCristian Dumitrescu 9335074e1d5SCristian Dumitrescu if (n_tokens != 8) { 9345074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 9355074e1d5SCristian Dumitrescu return; 9365074e1d5SCristian Dumitrescu } 9375074e1d5SCristian Dumitrescu 9385074e1d5SCristian Dumitrescu pipeline_name = tokens[1]; 9395074e1d5SCristian Dumitrescu p = pipeline_find(obj, pipeline_name); 9405074e1d5SCristian Dumitrescu if (!p || !p->ctl) { 9415074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 9425074e1d5SCristian Dumitrescu return; 9435074e1d5SCristian Dumitrescu } 9445074e1d5SCristian Dumitrescu 9455074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "table") != 0) { 9465074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table"); 9475074e1d5SCristian Dumitrescu return; 9485074e1d5SCristian Dumitrescu } 9495074e1d5SCristian Dumitrescu 9505074e1d5SCristian Dumitrescu table_name = tokens[3]; 9515074e1d5SCristian Dumitrescu 9525074e1d5SCristian Dumitrescu if (strcmp(tokens[4], "update") != 0) { 9535074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "update"); 9545074e1d5SCristian Dumitrescu return; 9555074e1d5SCristian Dumitrescu } 9565074e1d5SCristian Dumitrescu 9575074e1d5SCristian Dumitrescu file_name_add = tokens[5]; 9585074e1d5SCristian Dumitrescu file_name_delete = tokens[6]; 9595074e1d5SCristian Dumitrescu file_name_default = tokens[7]; 9605074e1d5SCristian Dumitrescu 9615074e1d5SCristian Dumitrescu /* File open. */ 9625074e1d5SCristian Dumitrescu if (strcmp(file_name_add, "none")) { 9635074e1d5SCristian Dumitrescu file_add = fopen(file_name_add, "r"); 9645074e1d5SCristian Dumitrescu if (!file_add) { 9655074e1d5SCristian Dumitrescu snprintf(out, out_size, "Cannot open file %s", 9665074e1d5SCristian Dumitrescu file_name_add); 9675074e1d5SCristian Dumitrescu goto error; 9685074e1d5SCristian Dumitrescu } 9695074e1d5SCristian Dumitrescu } 9705074e1d5SCristian Dumitrescu 9715074e1d5SCristian Dumitrescu if (strcmp(file_name_delete, "none")) { 97264eaee23SCristian Dumitrescu file_delete = fopen(file_name_delete, "r"); 97364eaee23SCristian Dumitrescu if (!file_delete) { 9745074e1d5SCristian Dumitrescu snprintf(out, out_size, "Cannot open file %s", 9755074e1d5SCristian Dumitrescu file_name_delete); 9765074e1d5SCristian Dumitrescu goto error; 9775074e1d5SCristian Dumitrescu } 9785074e1d5SCristian Dumitrescu } 9795074e1d5SCristian Dumitrescu 9805074e1d5SCristian Dumitrescu if (strcmp(file_name_default, "none")) { 98164eaee23SCristian Dumitrescu file_default = fopen(file_name_default, "r"); 98264eaee23SCristian Dumitrescu if (!file_default) { 9835074e1d5SCristian Dumitrescu snprintf(out, out_size, "Cannot open file %s", 9845074e1d5SCristian Dumitrescu file_name_default); 9855074e1d5SCristian Dumitrescu goto error; 9865074e1d5SCristian Dumitrescu } 9875074e1d5SCristian Dumitrescu } 9885074e1d5SCristian Dumitrescu 9895074e1d5SCristian Dumitrescu if (!file_add && !file_delete && !file_default) { 9905074e1d5SCristian Dumitrescu snprintf(out, out_size, "Nothing to be done."); 9915074e1d5SCristian Dumitrescu return; 9925074e1d5SCristian Dumitrescu } 9935074e1d5SCristian Dumitrescu 9945074e1d5SCristian Dumitrescu /* Buffer allocation. */ 9955074e1d5SCristian Dumitrescu line = malloc(2048); 9965074e1d5SCristian Dumitrescu if (!line) { 9975074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_OUT_OF_MEMORY); 9985074e1d5SCristian Dumitrescu goto error; 9995074e1d5SCristian Dumitrescu } 10005074e1d5SCristian Dumitrescu 10015074e1d5SCristian Dumitrescu /* Add. */ 100203665a48SCristian Dumitrescu if (file_add) 10035074e1d5SCristian Dumitrescu for (line_id = 1; ; line_id++) { 10045074e1d5SCristian Dumitrescu struct rte_swx_table_entry *entry; 1005*cff9a717SCristian Dumitrescu int is_blank_or_comment; 10065074e1d5SCristian Dumitrescu 10075074e1d5SCristian Dumitrescu if (fgets(line, 2048, file_add) == NULL) 10085074e1d5SCristian Dumitrescu break; 10095074e1d5SCristian Dumitrescu 10105074e1d5SCristian Dumitrescu entry = rte_swx_ctl_pipeline_table_entry_read(p->ctl, 10115074e1d5SCristian Dumitrescu table_name, 1012*cff9a717SCristian Dumitrescu line, 1013*cff9a717SCristian Dumitrescu &is_blank_or_comment); 10145074e1d5SCristian Dumitrescu if (!entry) { 1015*cff9a717SCristian Dumitrescu if (is_blank_or_comment) 1016*cff9a717SCristian Dumitrescu continue; 1017*cff9a717SCristian Dumitrescu 10185074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_FILE_ERR, 10195074e1d5SCristian Dumitrescu file_name_add, line_id); 10205074e1d5SCristian Dumitrescu goto error; 10215074e1d5SCristian Dumitrescu } 10225074e1d5SCristian Dumitrescu 10235074e1d5SCristian Dumitrescu status = rte_swx_ctl_pipeline_table_entry_add(p->ctl, 10245074e1d5SCristian Dumitrescu table_name, 10255074e1d5SCristian Dumitrescu entry); 1026275ebefeSCristian Dumitrescu table_entry_free(entry); 10275074e1d5SCristian Dumitrescu if (status) { 10285074e1d5SCristian Dumitrescu snprintf(out, out_size, 10295074e1d5SCristian Dumitrescu "Invalid entry in file %s at line %u", 10305074e1d5SCristian Dumitrescu file_name_add, line_id); 10315074e1d5SCristian Dumitrescu goto error; 10325074e1d5SCristian Dumitrescu } 10335074e1d5SCristian Dumitrescu } 10345074e1d5SCristian Dumitrescu 10355074e1d5SCristian Dumitrescu 10365074e1d5SCristian Dumitrescu /* Delete. */ 103703665a48SCristian Dumitrescu if (file_delete) 10385074e1d5SCristian Dumitrescu for (line_id = 1; ; line_id++) { 10395074e1d5SCristian Dumitrescu struct rte_swx_table_entry *entry; 1040*cff9a717SCristian Dumitrescu int is_blank_or_comment; 10415074e1d5SCristian Dumitrescu 10425074e1d5SCristian Dumitrescu if (fgets(line, 2048, file_delete) == NULL) 10435074e1d5SCristian Dumitrescu break; 10445074e1d5SCristian Dumitrescu 10455074e1d5SCristian Dumitrescu entry = rte_swx_ctl_pipeline_table_entry_read(p->ctl, 10465074e1d5SCristian Dumitrescu table_name, 1047*cff9a717SCristian Dumitrescu line, 1048*cff9a717SCristian Dumitrescu &is_blank_or_comment); 10495074e1d5SCristian Dumitrescu if (!entry) { 1050*cff9a717SCristian Dumitrescu if (is_blank_or_comment) 1051*cff9a717SCristian Dumitrescu continue; 1052*cff9a717SCristian Dumitrescu 10535074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_FILE_ERR, 10545074e1d5SCristian Dumitrescu file_name_delete, line_id); 10555074e1d5SCristian Dumitrescu goto error; 10565074e1d5SCristian Dumitrescu } 10575074e1d5SCristian Dumitrescu 10585074e1d5SCristian Dumitrescu status = rte_swx_ctl_pipeline_table_entry_delete(p->ctl, 10595074e1d5SCristian Dumitrescu table_name, 10605074e1d5SCristian Dumitrescu entry); 1061275ebefeSCristian Dumitrescu table_entry_free(entry); 10625074e1d5SCristian Dumitrescu if (status) { 10635074e1d5SCristian Dumitrescu snprintf(out, out_size, 10645074e1d5SCristian Dumitrescu "Invalid entry in file %s at line %u", 10655074e1d5SCristian Dumitrescu file_name_delete, line_id); 10665074e1d5SCristian Dumitrescu goto error; 10675074e1d5SCristian Dumitrescu } 10685074e1d5SCristian Dumitrescu } 10695074e1d5SCristian Dumitrescu 10705074e1d5SCristian Dumitrescu /* Default. */ 107103665a48SCristian Dumitrescu if (file_default) 10725074e1d5SCristian Dumitrescu for (line_id = 1; ; line_id++) { 10735074e1d5SCristian Dumitrescu struct rte_swx_table_entry *entry; 1074*cff9a717SCristian Dumitrescu int is_blank_or_comment; 10755074e1d5SCristian Dumitrescu 10765074e1d5SCristian Dumitrescu if (fgets(line, 2048, file_default) == NULL) 10775074e1d5SCristian Dumitrescu break; 10785074e1d5SCristian Dumitrescu 10795074e1d5SCristian Dumitrescu entry = rte_swx_ctl_pipeline_table_entry_read(p->ctl, 10805074e1d5SCristian Dumitrescu table_name, 1081*cff9a717SCristian Dumitrescu line, 1082*cff9a717SCristian Dumitrescu &is_blank_or_comment); 10835074e1d5SCristian Dumitrescu if (!entry) { 1084*cff9a717SCristian Dumitrescu if (is_blank_or_comment) 1085*cff9a717SCristian Dumitrescu continue; 1086*cff9a717SCristian Dumitrescu 10875074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_FILE_ERR, 10885074e1d5SCristian Dumitrescu file_name_default, line_id); 10895074e1d5SCristian Dumitrescu goto error; 10905074e1d5SCristian Dumitrescu } 10915074e1d5SCristian Dumitrescu 10925074e1d5SCristian Dumitrescu status = rte_swx_ctl_pipeline_table_default_entry_add(p->ctl, 10935074e1d5SCristian Dumitrescu table_name, 10945074e1d5SCristian Dumitrescu entry); 1095275ebefeSCristian Dumitrescu table_entry_free(entry); 10965074e1d5SCristian Dumitrescu if (status) { 10975074e1d5SCristian Dumitrescu snprintf(out, out_size, 10985074e1d5SCristian Dumitrescu "Invalid entry in file %s at line %u", 10995074e1d5SCristian Dumitrescu file_name_default, line_id); 11005074e1d5SCristian Dumitrescu goto error; 11015074e1d5SCristian Dumitrescu } 11025074e1d5SCristian Dumitrescu } 11035074e1d5SCristian Dumitrescu 11045074e1d5SCristian Dumitrescu status = rte_swx_ctl_pipeline_commit(p->ctl, 1); 11055074e1d5SCristian Dumitrescu if (status) { 11065074e1d5SCristian Dumitrescu snprintf(out, out_size, "Commit failed."); 11075074e1d5SCristian Dumitrescu goto error; 11085074e1d5SCristian Dumitrescu } 11095074e1d5SCristian Dumitrescu 11105074e1d5SCristian Dumitrescu 11115074e1d5SCristian Dumitrescu rte_swx_ctl_pipeline_table_fprintf(stdout, p->ctl, table_name); 11125074e1d5SCristian Dumitrescu 111303665a48SCristian Dumitrescu free(line); 111403665a48SCristian Dumitrescu if (file_add) 111503665a48SCristian Dumitrescu fclose(file_add); 111603665a48SCristian Dumitrescu if (file_delete) 111703665a48SCristian Dumitrescu fclose(file_delete); 111803665a48SCristian Dumitrescu if (file_default) 111903665a48SCristian Dumitrescu fclose(file_default); 11205074e1d5SCristian Dumitrescu return; 11215074e1d5SCristian Dumitrescu 11225074e1d5SCristian Dumitrescu error: 11235074e1d5SCristian Dumitrescu rte_swx_ctl_pipeline_abort(p->ctl); 11245074e1d5SCristian Dumitrescu free(line); 11255074e1d5SCristian Dumitrescu if (file_add) 11265074e1d5SCristian Dumitrescu fclose(file_add); 11275074e1d5SCristian Dumitrescu if (file_delete) 11285074e1d5SCristian Dumitrescu fclose(file_delete); 11295074e1d5SCristian Dumitrescu if (file_default) 11305074e1d5SCristian Dumitrescu fclose(file_default); 11315074e1d5SCristian Dumitrescu } 11325074e1d5SCristian Dumitrescu 11335074e1d5SCristian Dumitrescu static const char cmd_pipeline_stats_help[] = 11345074e1d5SCristian Dumitrescu "pipeline <pipeline_name> stats\n"; 11355074e1d5SCristian Dumitrescu 11365074e1d5SCristian Dumitrescu static void 11375074e1d5SCristian Dumitrescu cmd_pipeline_stats(char **tokens, 11385074e1d5SCristian Dumitrescu uint32_t n_tokens, 11395074e1d5SCristian Dumitrescu char *out, 11405074e1d5SCristian Dumitrescu size_t out_size, 11415074e1d5SCristian Dumitrescu void *obj) 11425074e1d5SCristian Dumitrescu { 11435074e1d5SCristian Dumitrescu struct rte_swx_ctl_pipeline_info info; 11445074e1d5SCristian Dumitrescu struct pipeline *p; 11455074e1d5SCristian Dumitrescu uint32_t i; 11465074e1d5SCristian Dumitrescu int status; 11475074e1d5SCristian Dumitrescu 11485074e1d5SCristian Dumitrescu if (n_tokens != 3) { 11495074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 11505074e1d5SCristian Dumitrescu return; 11515074e1d5SCristian Dumitrescu } 11525074e1d5SCristian Dumitrescu 11535074e1d5SCristian Dumitrescu p = pipeline_find(obj, tokens[1]); 11545074e1d5SCristian Dumitrescu if (!p || !p->ctl) { 11555074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 11565074e1d5SCristian Dumitrescu return; 11575074e1d5SCristian Dumitrescu } 11585074e1d5SCristian Dumitrescu 11595074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "stats")) { 11605074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats"); 11615074e1d5SCristian Dumitrescu return; 11625074e1d5SCristian Dumitrescu } 11635074e1d5SCristian Dumitrescu 11645074e1d5SCristian Dumitrescu status = rte_swx_ctl_pipeline_info_get(p->p, &info); 11655074e1d5SCristian Dumitrescu if (status) { 11665074e1d5SCristian Dumitrescu snprintf(out, out_size, "Pipeline info get error."); 11675074e1d5SCristian Dumitrescu return; 11685074e1d5SCristian Dumitrescu } 11695074e1d5SCristian Dumitrescu 11705074e1d5SCristian Dumitrescu snprintf(out, out_size, "Input ports:\n"); 11715074e1d5SCristian Dumitrescu out_size -= strlen(out); 11725074e1d5SCristian Dumitrescu out += strlen(out); 11735074e1d5SCristian Dumitrescu 11745074e1d5SCristian Dumitrescu for (i = 0; i < info.n_ports_in; i++) { 11755074e1d5SCristian Dumitrescu struct rte_swx_port_in_stats stats; 11765074e1d5SCristian Dumitrescu 11775074e1d5SCristian Dumitrescu rte_swx_ctl_pipeline_port_in_stats_read(p->p, i, &stats); 11785074e1d5SCristian Dumitrescu 11795074e1d5SCristian Dumitrescu snprintf(out, out_size, "\tPort %u:" 11805074e1d5SCristian Dumitrescu " packets %" PRIu64 11815074e1d5SCristian Dumitrescu " bytes %" PRIu64 11825074e1d5SCristian Dumitrescu " empty %" PRIu64 "\n", 11835074e1d5SCristian Dumitrescu i, stats.n_pkts, stats.n_bytes, stats.n_empty); 11845074e1d5SCristian Dumitrescu out_size -= strlen(out); 11855074e1d5SCristian Dumitrescu out += strlen(out); 11865074e1d5SCristian Dumitrescu } 11875074e1d5SCristian Dumitrescu 11885074e1d5SCristian Dumitrescu snprintf(out, out_size, "Output ports:\n"); 11895074e1d5SCristian Dumitrescu out_size -= strlen(out); 11905074e1d5SCristian Dumitrescu out += strlen(out); 11915074e1d5SCristian Dumitrescu 11925074e1d5SCristian Dumitrescu for (i = 0; i < info.n_ports_out; i++) { 11935074e1d5SCristian Dumitrescu struct rte_swx_port_out_stats stats; 11945074e1d5SCristian Dumitrescu 11955074e1d5SCristian Dumitrescu rte_swx_ctl_pipeline_port_out_stats_read(p->p, i, &stats); 11965074e1d5SCristian Dumitrescu 11975074e1d5SCristian Dumitrescu snprintf(out, out_size, "\tPort %u:" 11985074e1d5SCristian Dumitrescu " packets %" PRIu64 11995074e1d5SCristian Dumitrescu " bytes %" PRIu64 "\n", 12005074e1d5SCristian Dumitrescu i, stats.n_pkts, stats.n_bytes); 12015074e1d5SCristian Dumitrescu out_size -= strlen(out); 12025074e1d5SCristian Dumitrescu out += strlen(out); 12035074e1d5SCristian Dumitrescu } 12045074e1d5SCristian Dumitrescu } 12055074e1d5SCristian Dumitrescu 12065074e1d5SCristian Dumitrescu static const char cmd_thread_pipeline_enable_help[] = 12075074e1d5SCristian Dumitrescu "thread <thread_id> pipeline <pipeline_name> enable\n"; 12085074e1d5SCristian Dumitrescu 12095074e1d5SCristian Dumitrescu static void 12105074e1d5SCristian Dumitrescu cmd_thread_pipeline_enable(char **tokens, 12115074e1d5SCristian Dumitrescu uint32_t n_tokens, 12125074e1d5SCristian Dumitrescu char *out, 12135074e1d5SCristian Dumitrescu size_t out_size, 12145074e1d5SCristian Dumitrescu void *obj) 12155074e1d5SCristian Dumitrescu { 12165074e1d5SCristian Dumitrescu char *pipeline_name; 12175074e1d5SCristian Dumitrescu struct pipeline *p; 12185074e1d5SCristian Dumitrescu uint32_t thread_id; 12195074e1d5SCristian Dumitrescu int status; 12205074e1d5SCristian Dumitrescu 12215074e1d5SCristian Dumitrescu if (n_tokens != 5) { 12225074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 12235074e1d5SCristian Dumitrescu return; 12245074e1d5SCristian Dumitrescu } 12255074e1d5SCristian Dumitrescu 12265074e1d5SCristian Dumitrescu if (parser_read_uint32(&thread_id, tokens[1]) != 0) { 12275074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "thread_id"); 12285074e1d5SCristian Dumitrescu return; 12295074e1d5SCristian Dumitrescu } 12305074e1d5SCristian Dumitrescu 12315074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "pipeline") != 0) { 12325074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline"); 12335074e1d5SCristian Dumitrescu return; 12345074e1d5SCristian Dumitrescu } 12355074e1d5SCristian Dumitrescu 12365074e1d5SCristian Dumitrescu pipeline_name = tokens[3]; 12375074e1d5SCristian Dumitrescu p = pipeline_find(obj, pipeline_name); 12385074e1d5SCristian Dumitrescu if (!p || !p->ctl) { 12395074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 12405074e1d5SCristian Dumitrescu return; 12415074e1d5SCristian Dumitrescu } 12425074e1d5SCristian Dumitrescu 12435074e1d5SCristian Dumitrescu if (strcmp(tokens[4], "enable") != 0) { 12445074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable"); 12455074e1d5SCristian Dumitrescu return; 12465074e1d5SCristian Dumitrescu } 12475074e1d5SCristian Dumitrescu 12485074e1d5SCristian Dumitrescu status = thread_pipeline_enable(thread_id, obj, pipeline_name); 12495074e1d5SCristian Dumitrescu if (status) { 12505074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable"); 12515074e1d5SCristian Dumitrescu return; 12525074e1d5SCristian Dumitrescu } 12535074e1d5SCristian Dumitrescu } 12545074e1d5SCristian Dumitrescu 12555074e1d5SCristian Dumitrescu static const char cmd_thread_pipeline_disable_help[] = 12565074e1d5SCristian Dumitrescu "thread <thread_id> pipeline <pipeline_name> disable\n"; 12575074e1d5SCristian Dumitrescu 12585074e1d5SCristian Dumitrescu static void 12595074e1d5SCristian Dumitrescu cmd_thread_pipeline_disable(char **tokens, 12605074e1d5SCristian Dumitrescu uint32_t n_tokens, 12615074e1d5SCristian Dumitrescu char *out, 12625074e1d5SCristian Dumitrescu size_t out_size, 12635074e1d5SCristian Dumitrescu void *obj) 12645074e1d5SCristian Dumitrescu { 12655074e1d5SCristian Dumitrescu struct pipeline *p; 12665074e1d5SCristian Dumitrescu char *pipeline_name; 12675074e1d5SCristian Dumitrescu uint32_t thread_id; 12685074e1d5SCristian Dumitrescu int status; 12695074e1d5SCristian Dumitrescu 12705074e1d5SCristian Dumitrescu if (n_tokens != 5) { 12715074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); 12725074e1d5SCristian Dumitrescu return; 12735074e1d5SCristian Dumitrescu } 12745074e1d5SCristian Dumitrescu 12755074e1d5SCristian Dumitrescu if (parser_read_uint32(&thread_id, tokens[1]) != 0) { 12765074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "thread_id"); 12775074e1d5SCristian Dumitrescu return; 12785074e1d5SCristian Dumitrescu } 12795074e1d5SCristian Dumitrescu 12805074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "pipeline") != 0) { 12815074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline"); 12825074e1d5SCristian Dumitrescu return; 12835074e1d5SCristian Dumitrescu } 12845074e1d5SCristian Dumitrescu 12855074e1d5SCristian Dumitrescu pipeline_name = tokens[3]; 12865074e1d5SCristian Dumitrescu p = pipeline_find(obj, pipeline_name); 12875074e1d5SCristian Dumitrescu if (!p || !p->ctl) { 12885074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name"); 12895074e1d5SCristian Dumitrescu return; 12905074e1d5SCristian Dumitrescu } 12915074e1d5SCristian Dumitrescu 12925074e1d5SCristian Dumitrescu if (strcmp(tokens[4], "disable") != 0) { 12935074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable"); 12945074e1d5SCristian Dumitrescu return; 12955074e1d5SCristian Dumitrescu } 12965074e1d5SCristian Dumitrescu 12975074e1d5SCristian Dumitrescu status = thread_pipeline_disable(thread_id, obj, pipeline_name); 12985074e1d5SCristian Dumitrescu if (status) { 12995074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_CMD_FAIL, 13005074e1d5SCristian Dumitrescu "thread pipeline disable"); 13015074e1d5SCristian Dumitrescu return; 13025074e1d5SCristian Dumitrescu } 13035074e1d5SCristian Dumitrescu } 13045074e1d5SCristian Dumitrescu 13055074e1d5SCristian Dumitrescu static void 13065074e1d5SCristian Dumitrescu cmd_help(char **tokens, 13075074e1d5SCristian Dumitrescu uint32_t n_tokens, 13085074e1d5SCristian Dumitrescu char *out, 13095074e1d5SCristian Dumitrescu size_t out_size, 13105074e1d5SCristian Dumitrescu void *arg __rte_unused) 13115074e1d5SCristian Dumitrescu { 13125074e1d5SCristian Dumitrescu tokens++; 13135074e1d5SCristian Dumitrescu n_tokens--; 13145074e1d5SCristian Dumitrescu 13155074e1d5SCristian Dumitrescu if (n_tokens == 0) { 13165074e1d5SCristian Dumitrescu snprintf(out, out_size, 13177fef9ef1SYogesh Jangra "Type 'help <command>' for command details.\n\n" 13187fef9ef1SYogesh Jangra "List of commands:\n" 13197fef9ef1SYogesh Jangra "\tmempool\n" 13207fef9ef1SYogesh Jangra "\tlink\n" 13217fef9ef1SYogesh Jangra "\tpipeline create\n" 13227fef9ef1SYogesh Jangra "\tpipeline port in\n" 13237fef9ef1SYogesh Jangra "\tpipeline port out\n" 13247fef9ef1SYogesh Jangra "\tpipeline build\n" 13257fef9ef1SYogesh Jangra "\tpipeline table update\n" 13267fef9ef1SYogesh Jangra "\tpipeline stats\n" 13277fef9ef1SYogesh Jangra "\tthread pipeline enable\n" 13287fef9ef1SYogesh Jangra "\tthread pipeline disable\n\n"); 13295074e1d5SCristian Dumitrescu return; 13305074e1d5SCristian Dumitrescu } 13315074e1d5SCristian Dumitrescu 13325074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "mempool") == 0) { 13335074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_mempool_help); 13345074e1d5SCristian Dumitrescu return; 13355074e1d5SCristian Dumitrescu } 13365074e1d5SCristian Dumitrescu 13375074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "link") == 0) { 13385074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_link_help); 13395074e1d5SCristian Dumitrescu return; 13405074e1d5SCristian Dumitrescu } 13415074e1d5SCristian Dumitrescu 134277a41301SCristian Dumitrescu if (strcmp(tokens[0], "ring") == 0) { 134377a41301SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_ring_help); 134477a41301SCristian Dumitrescu return; 134577a41301SCristian Dumitrescu } 134677a41301SCristian Dumitrescu 13475074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 13487fef9ef1SYogesh Jangra (n_tokens == 2) && (strcmp(tokens[1], "create") == 0)) { 13495074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_create_help); 13505074e1d5SCristian Dumitrescu return; 13515074e1d5SCristian Dumitrescu } 13525074e1d5SCristian Dumitrescu 13535074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 13547fef9ef1SYogesh Jangra (n_tokens == 3) && (strcmp(tokens[1], "port") == 0)) { 13557fef9ef1SYogesh Jangra if (strcmp(tokens[2], "in") == 0) { 13565074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 13575074e1d5SCristian Dumitrescu cmd_pipeline_port_in_help); 13585074e1d5SCristian Dumitrescu return; 13595074e1d5SCristian Dumitrescu } 13605074e1d5SCristian Dumitrescu 13617fef9ef1SYogesh Jangra if (strcmp(tokens[2], "out") == 0) { 13625074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 13635074e1d5SCristian Dumitrescu cmd_pipeline_port_out_help); 13645074e1d5SCristian Dumitrescu return; 13655074e1d5SCristian Dumitrescu } 13665074e1d5SCristian Dumitrescu } 13675074e1d5SCristian Dumitrescu 13685074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 13697fef9ef1SYogesh Jangra (n_tokens == 2) && (strcmp(tokens[1], "build") == 0)) { 13705074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_build_help); 13715074e1d5SCristian Dumitrescu return; 13725074e1d5SCristian Dumitrescu } 13735074e1d5SCristian Dumitrescu 13745074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 13757fef9ef1SYogesh Jangra (n_tokens == 3) && 13767fef9ef1SYogesh Jangra (strcmp(tokens[1], "table") == 0) && 13777fef9ef1SYogesh Jangra (strcmp(tokens[2], "update") == 0)) { 13785074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 13795074e1d5SCristian Dumitrescu cmd_pipeline_table_update_help); 13805074e1d5SCristian Dumitrescu return; 13815074e1d5SCristian Dumitrescu } 13825074e1d5SCristian Dumitrescu 13835074e1d5SCristian Dumitrescu if ((strcmp(tokens[0], "pipeline") == 0) && 13847fef9ef1SYogesh Jangra (n_tokens == 2) && (strcmp(tokens[1], "stats") == 0)) { 13855074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", cmd_pipeline_stats_help); 13865074e1d5SCristian Dumitrescu return; 13875074e1d5SCristian Dumitrescu } 13885074e1d5SCristian Dumitrescu 13895074e1d5SCristian Dumitrescu if ((n_tokens == 3) && 13905074e1d5SCristian Dumitrescu (strcmp(tokens[0], "thread") == 0) && 13915074e1d5SCristian Dumitrescu (strcmp(tokens[1], "pipeline") == 0)) { 13925074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "enable") == 0) { 13935074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 13945074e1d5SCristian Dumitrescu cmd_thread_pipeline_enable_help); 13955074e1d5SCristian Dumitrescu return; 13965074e1d5SCristian Dumitrescu } 13975074e1d5SCristian Dumitrescu 13985074e1d5SCristian Dumitrescu if (strcmp(tokens[2], "disable") == 0) { 13995074e1d5SCristian Dumitrescu snprintf(out, out_size, "\n%s\n", 14005074e1d5SCristian Dumitrescu cmd_thread_pipeline_disable_help); 14015074e1d5SCristian Dumitrescu return; 14025074e1d5SCristian Dumitrescu } 14035074e1d5SCristian Dumitrescu } 14045074e1d5SCristian Dumitrescu 14055074e1d5SCristian Dumitrescu snprintf(out, out_size, "Invalid command\n"); 14065074e1d5SCristian Dumitrescu } 14075074e1d5SCristian Dumitrescu 14085074e1d5SCristian Dumitrescu void 14095074e1d5SCristian Dumitrescu cli_process(char *in, char *out, size_t out_size, void *obj) 14105074e1d5SCristian Dumitrescu { 14115074e1d5SCristian Dumitrescu char *tokens[CMD_MAX_TOKENS]; 14125074e1d5SCristian Dumitrescu uint32_t n_tokens = RTE_DIM(tokens); 14135074e1d5SCristian Dumitrescu int status; 14145074e1d5SCristian Dumitrescu 14155074e1d5SCristian Dumitrescu if (is_comment(in)) 14165074e1d5SCristian Dumitrescu return; 14175074e1d5SCristian Dumitrescu 14185074e1d5SCristian Dumitrescu status = parse_tokenize_string(in, tokens, &n_tokens); 14195074e1d5SCristian Dumitrescu if (status) { 14205074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_ARG_TOO_MANY, ""); 14215074e1d5SCristian Dumitrescu return; 14225074e1d5SCristian Dumitrescu } 14235074e1d5SCristian Dumitrescu 14245074e1d5SCristian Dumitrescu if (n_tokens == 0) 14255074e1d5SCristian Dumitrescu return; 14265074e1d5SCristian Dumitrescu 14275074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "help") == 0) { 14285074e1d5SCristian Dumitrescu cmd_help(tokens, n_tokens, out, out_size, obj); 14295074e1d5SCristian Dumitrescu return; 14305074e1d5SCristian Dumitrescu } 14315074e1d5SCristian Dumitrescu 14325074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "mempool") == 0) { 14335074e1d5SCristian Dumitrescu cmd_mempool(tokens, n_tokens, out, out_size, obj); 14345074e1d5SCristian Dumitrescu return; 14355074e1d5SCristian Dumitrescu } 14365074e1d5SCristian Dumitrescu 14375074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "link") == 0) { 1438821848f5SCristian Dumitrescu if ((n_tokens >= 2) && (strcmp(tokens[1], "show") == 0)) { 14395074e1d5SCristian Dumitrescu cmd_link_show(tokens, n_tokens, out, out_size, obj); 14405074e1d5SCristian Dumitrescu return; 14415074e1d5SCristian Dumitrescu } 14425074e1d5SCristian Dumitrescu 14435074e1d5SCristian Dumitrescu cmd_link(tokens, n_tokens, out, out_size, obj); 14445074e1d5SCristian Dumitrescu return; 14455074e1d5SCristian Dumitrescu } 14465074e1d5SCristian Dumitrescu 144777a41301SCristian Dumitrescu if (strcmp(tokens[0], "ring") == 0) { 144877a41301SCristian Dumitrescu cmd_ring(tokens, n_tokens, out, out_size, obj); 144977a41301SCristian Dumitrescu return; 145077a41301SCristian Dumitrescu } 145177a41301SCristian Dumitrescu 14525074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "pipeline") == 0) { 14535074e1d5SCristian Dumitrescu if ((n_tokens >= 3) && 14545074e1d5SCristian Dumitrescu (strcmp(tokens[2], "create") == 0)) { 14555074e1d5SCristian Dumitrescu cmd_pipeline_create(tokens, n_tokens, out, out_size, 14565074e1d5SCristian Dumitrescu obj); 14575074e1d5SCristian Dumitrescu return; 14585074e1d5SCristian Dumitrescu } 14595074e1d5SCristian Dumitrescu 14605074e1d5SCristian Dumitrescu if ((n_tokens >= 4) && 14615074e1d5SCristian Dumitrescu (strcmp(tokens[2], "port") == 0) && 14625074e1d5SCristian Dumitrescu (strcmp(tokens[3], "in") == 0)) { 14635074e1d5SCristian Dumitrescu cmd_pipeline_port_in(tokens, n_tokens, out, out_size, 14645074e1d5SCristian Dumitrescu obj); 14655074e1d5SCristian Dumitrescu return; 14665074e1d5SCristian Dumitrescu } 14675074e1d5SCristian Dumitrescu 14685074e1d5SCristian Dumitrescu if ((n_tokens >= 4) && 14695074e1d5SCristian Dumitrescu (strcmp(tokens[2], "port") == 0) && 14705074e1d5SCristian Dumitrescu (strcmp(tokens[3], "out") == 0)) { 14715074e1d5SCristian Dumitrescu cmd_pipeline_port_out(tokens, n_tokens, out, out_size, 14725074e1d5SCristian Dumitrescu obj); 14735074e1d5SCristian Dumitrescu return; 14745074e1d5SCristian Dumitrescu } 14755074e1d5SCristian Dumitrescu 14765074e1d5SCristian Dumitrescu if ((n_tokens >= 3) && 14775074e1d5SCristian Dumitrescu (strcmp(tokens[2], "build") == 0)) { 14785074e1d5SCristian Dumitrescu cmd_pipeline_build(tokens, n_tokens, out, out_size, 14795074e1d5SCristian Dumitrescu obj); 14805074e1d5SCristian Dumitrescu return; 14815074e1d5SCristian Dumitrescu } 14825074e1d5SCristian Dumitrescu 14835074e1d5SCristian Dumitrescu if ((n_tokens >= 3) && 14845074e1d5SCristian Dumitrescu (strcmp(tokens[2], "table") == 0)) { 14855074e1d5SCristian Dumitrescu cmd_pipeline_table_update(tokens, n_tokens, out, 14865074e1d5SCristian Dumitrescu out_size, obj); 14875074e1d5SCristian Dumitrescu return; 14885074e1d5SCristian Dumitrescu } 14895074e1d5SCristian Dumitrescu 14905074e1d5SCristian Dumitrescu if ((n_tokens >= 3) && 14915074e1d5SCristian Dumitrescu (strcmp(tokens[2], "stats") == 0)) { 14925074e1d5SCristian Dumitrescu cmd_pipeline_stats(tokens, n_tokens, out, out_size, 14935074e1d5SCristian Dumitrescu obj); 14945074e1d5SCristian Dumitrescu return; 14955074e1d5SCristian Dumitrescu } 14965074e1d5SCristian Dumitrescu } 14975074e1d5SCristian Dumitrescu 14985074e1d5SCristian Dumitrescu if (strcmp(tokens[0], "thread") == 0) { 14995074e1d5SCristian Dumitrescu if ((n_tokens >= 5) && 15005074e1d5SCristian Dumitrescu (strcmp(tokens[4], "enable") == 0)) { 15015074e1d5SCristian Dumitrescu cmd_thread_pipeline_enable(tokens, n_tokens, 15025074e1d5SCristian Dumitrescu out, out_size, obj); 15035074e1d5SCristian Dumitrescu return; 15045074e1d5SCristian Dumitrescu } 15055074e1d5SCristian Dumitrescu 15065074e1d5SCristian Dumitrescu if ((n_tokens >= 5) && 15075074e1d5SCristian Dumitrescu (strcmp(tokens[4], "disable") == 0)) { 15085074e1d5SCristian Dumitrescu cmd_thread_pipeline_disable(tokens, n_tokens, 15095074e1d5SCristian Dumitrescu out, out_size, obj); 15105074e1d5SCristian Dumitrescu return; 15115074e1d5SCristian Dumitrescu } 15125074e1d5SCristian Dumitrescu } 15135074e1d5SCristian Dumitrescu 15145074e1d5SCristian Dumitrescu snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]); 15155074e1d5SCristian Dumitrescu } 15165074e1d5SCristian Dumitrescu 15175074e1d5SCristian Dumitrescu int 15185074e1d5SCristian Dumitrescu cli_script_process(const char *file_name, 15195074e1d5SCristian Dumitrescu size_t msg_in_len_max, 15205074e1d5SCristian Dumitrescu size_t msg_out_len_max, 15215074e1d5SCristian Dumitrescu void *obj) 15225074e1d5SCristian Dumitrescu { 15235074e1d5SCristian Dumitrescu char *msg_in = NULL, *msg_out = NULL; 15245074e1d5SCristian Dumitrescu FILE *f = NULL; 15255074e1d5SCristian Dumitrescu 15265074e1d5SCristian Dumitrescu /* Check input arguments */ 15275074e1d5SCristian Dumitrescu if ((file_name == NULL) || 15285074e1d5SCristian Dumitrescu (strlen(file_name) == 0) || 15295074e1d5SCristian Dumitrescu (msg_in_len_max == 0) || 15305074e1d5SCristian Dumitrescu (msg_out_len_max == 0)) 15315074e1d5SCristian Dumitrescu return -EINVAL; 15325074e1d5SCristian Dumitrescu 15335074e1d5SCristian Dumitrescu msg_in = malloc(msg_in_len_max + 1); 15345074e1d5SCristian Dumitrescu msg_out = malloc(msg_out_len_max + 1); 15355074e1d5SCristian Dumitrescu if ((msg_in == NULL) || 15365074e1d5SCristian Dumitrescu (msg_out == NULL)) { 15375074e1d5SCristian Dumitrescu free(msg_out); 15385074e1d5SCristian Dumitrescu free(msg_in); 15395074e1d5SCristian Dumitrescu return -ENOMEM; 15405074e1d5SCristian Dumitrescu } 15415074e1d5SCristian Dumitrescu 15425074e1d5SCristian Dumitrescu /* Open input file */ 15435074e1d5SCristian Dumitrescu f = fopen(file_name, "r"); 15445074e1d5SCristian Dumitrescu if (f == NULL) { 15455074e1d5SCristian Dumitrescu free(msg_out); 15465074e1d5SCristian Dumitrescu free(msg_in); 15475074e1d5SCristian Dumitrescu return -EIO; 15485074e1d5SCristian Dumitrescu } 15495074e1d5SCristian Dumitrescu 15505074e1d5SCristian Dumitrescu /* Read file */ 15515074e1d5SCristian Dumitrescu for ( ; ; ) { 15525074e1d5SCristian Dumitrescu if (fgets(msg_in, msg_in_len_max + 1, f) == NULL) 15535074e1d5SCristian Dumitrescu break; 15545074e1d5SCristian Dumitrescu 15555074e1d5SCristian Dumitrescu printf("%s", msg_in); 15565074e1d5SCristian Dumitrescu msg_out[0] = 0; 15575074e1d5SCristian Dumitrescu 15585074e1d5SCristian Dumitrescu cli_process(msg_in, 15595074e1d5SCristian Dumitrescu msg_out, 15605074e1d5SCristian Dumitrescu msg_out_len_max, 15615074e1d5SCristian Dumitrescu obj); 15625074e1d5SCristian Dumitrescu 15635074e1d5SCristian Dumitrescu if (strlen(msg_out)) 15645074e1d5SCristian Dumitrescu printf("%s", msg_out); 15655074e1d5SCristian Dumitrescu } 15665074e1d5SCristian Dumitrescu 15675074e1d5SCristian Dumitrescu /* Close file */ 15685074e1d5SCristian Dumitrescu fclose(f); 15695074e1d5SCristian Dumitrescu free(msg_out); 15705074e1d5SCristian Dumitrescu free(msg_in); 15715074e1d5SCristian Dumitrescu return 0; 15725074e1d5SCristian Dumitrescu } 1573