13998e2a0SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 24bbf8e30SJasvinder Singh * Copyright(c) 2010-2018 Intel Corporation 377a33467SCristian Dumitrescu */ 477a33467SCristian Dumitrescu 5fbc74e66SJasvinder Singh #include <stdio.h> 6fbc74e66SJasvinder Singh #include <string.h> 7fbc74e66SJasvinder Singh #include <fcntl.h> 8fbc74e66SJasvinder Singh #include <unistd.h> 9fbc74e66SJasvinder Singh #include <getopt.h> 1077a33467SCristian Dumitrescu 11a8bd581dSJasvinder Singh #include <rte_launch.h> 12fbc74e66SJasvinder Singh #include <rte_eal.h> 1377a33467SCristian Dumitrescu 144bbf8e30SJasvinder Singh #include "cli.h" 154bbf8e30SJasvinder Singh #include "conn.h" 169a408cc8SJasvinder Singh #include "kni.h" 17*bd9b67a1SFan Zhang #include "cryptodev.h" 18133c2c65SJasvinder Singh #include "link.h" 196bfe74f8SJasvinder Singh #include "mempool.h" 20d75c371eSJasvinder Singh #include "pipeline.h" 218245472cSJasvinder Singh #include "swq.h" 222f74ae28SJasvinder Singh #include "tap.h" 23c0b668e0SJasvinder Singh #include "thread.h" 2425961ff3SJasvinder Singh #include "tmgr.h" 254bbf8e30SJasvinder Singh 264bbf8e30SJasvinder Singh static const char usage[] = 274bbf8e30SJasvinder Singh "%s EAL_ARGS -- [-h HOST] [-p PORT] [-s SCRIPT]\n"; 284bbf8e30SJasvinder Singh 294bbf8e30SJasvinder Singh static const char welcome[] = 304bbf8e30SJasvinder Singh "\n" 314bbf8e30SJasvinder Singh "Welcome to IP Pipeline!\n" 324bbf8e30SJasvinder Singh "\n"; 334bbf8e30SJasvinder Singh 344bbf8e30SJasvinder Singh static const char prompt[] = "pipeline> "; 354bbf8e30SJasvinder Singh 364bbf8e30SJasvinder Singh static struct app_params { 374bbf8e30SJasvinder Singh struct conn_params conn; 384bbf8e30SJasvinder Singh char *script_name; 394bbf8e30SJasvinder Singh } app = { 404bbf8e30SJasvinder Singh .conn = { 414bbf8e30SJasvinder Singh .welcome = welcome, 424bbf8e30SJasvinder Singh .prompt = prompt, 434bbf8e30SJasvinder Singh .addr = "0.0.0.0", 444bbf8e30SJasvinder Singh .port = 8086, 454bbf8e30SJasvinder Singh .buf_size = 1024 * 1024, 464bbf8e30SJasvinder Singh .msg_in_len_max = 1024, 474bbf8e30SJasvinder Singh .msg_out_len_max = 1024 * 1024, 484bbf8e30SJasvinder Singh .msg_handle = cli_process, 494bbf8e30SJasvinder Singh }, 504bbf8e30SJasvinder Singh .script_name = NULL, 514bbf8e30SJasvinder Singh }; 524bbf8e30SJasvinder Singh 534bbf8e30SJasvinder Singh static int 544bbf8e30SJasvinder Singh parse_args(int argc, char **argv) 554bbf8e30SJasvinder Singh { 564bbf8e30SJasvinder Singh char *app_name = argv[0]; 574bbf8e30SJasvinder Singh struct option lgopts[] = { 584bbf8e30SJasvinder Singh { NULL, 0, 0, 0 } 594bbf8e30SJasvinder Singh }; 604bbf8e30SJasvinder Singh int opt, option_index; 614bbf8e30SJasvinder Singh int h_present, p_present, s_present, n_args, i; 624bbf8e30SJasvinder Singh 634bbf8e30SJasvinder Singh /* Skip EAL input args */ 644bbf8e30SJasvinder Singh n_args = argc; 654bbf8e30SJasvinder Singh for (i = 0; i < n_args; i++) 664bbf8e30SJasvinder Singh if (strcmp(argv[i], "--") == 0) { 674bbf8e30SJasvinder Singh argc -= i; 684bbf8e30SJasvinder Singh argv += i; 694bbf8e30SJasvinder Singh break; 704bbf8e30SJasvinder Singh } 714bbf8e30SJasvinder Singh 724bbf8e30SJasvinder Singh if (i == n_args) 734bbf8e30SJasvinder Singh return 0; 744bbf8e30SJasvinder Singh 754bbf8e30SJasvinder Singh /* Parse args */ 764bbf8e30SJasvinder Singh h_present = 0; 774bbf8e30SJasvinder Singh p_present = 0; 784bbf8e30SJasvinder Singh s_present = 0; 794bbf8e30SJasvinder Singh 804bbf8e30SJasvinder Singh while ((opt = getopt_long(argc, argv, "h:p:s:", lgopts, &option_index)) 814bbf8e30SJasvinder Singh != EOF) 824bbf8e30SJasvinder Singh switch (opt) { 834bbf8e30SJasvinder Singh case 'h': 844bbf8e30SJasvinder Singh if (h_present) { 854bbf8e30SJasvinder Singh printf("Error: Multiple -h arguments\n"); 864bbf8e30SJasvinder Singh return -1; 874bbf8e30SJasvinder Singh } 884bbf8e30SJasvinder Singh h_present = 1; 894bbf8e30SJasvinder Singh 904bbf8e30SJasvinder Singh if (!strlen(optarg)) { 914bbf8e30SJasvinder Singh printf("Error: Argument for -h not provided\n"); 924bbf8e30SJasvinder Singh return -1; 934bbf8e30SJasvinder Singh } 944bbf8e30SJasvinder Singh 954bbf8e30SJasvinder Singh app.conn.addr = strdup(optarg); 964bbf8e30SJasvinder Singh if (app.conn.addr == NULL) { 974bbf8e30SJasvinder Singh printf("Error: Not enough memory\n"); 984bbf8e30SJasvinder Singh return -1; 994bbf8e30SJasvinder Singh } 1004bbf8e30SJasvinder Singh break; 1014bbf8e30SJasvinder Singh 1024bbf8e30SJasvinder Singh case 'p': 1034bbf8e30SJasvinder Singh if (p_present) { 1044bbf8e30SJasvinder Singh printf("Error: Multiple -p arguments\n"); 1054bbf8e30SJasvinder Singh return -1; 1064bbf8e30SJasvinder Singh } 1074bbf8e30SJasvinder Singh p_present = 1; 1084bbf8e30SJasvinder Singh 1094bbf8e30SJasvinder Singh if (!strlen(optarg)) { 1104bbf8e30SJasvinder Singh printf("Error: Argument for -p not provided\n"); 1114bbf8e30SJasvinder Singh return -1; 1124bbf8e30SJasvinder Singh } 1134bbf8e30SJasvinder Singh 1144bbf8e30SJasvinder Singh app.conn.port = (uint16_t) atoi(optarg); 1154bbf8e30SJasvinder Singh break; 1164bbf8e30SJasvinder Singh 1174bbf8e30SJasvinder Singh case 's': 1184bbf8e30SJasvinder Singh if (s_present) { 1194bbf8e30SJasvinder Singh printf("Error: Multiple -s arguments\n"); 1204bbf8e30SJasvinder Singh return -1; 1214bbf8e30SJasvinder Singh } 1224bbf8e30SJasvinder Singh s_present = 1; 1234bbf8e30SJasvinder Singh 1244bbf8e30SJasvinder Singh if (!strlen(optarg)) { 1254bbf8e30SJasvinder Singh printf("Error: Argument for -s not provided\n"); 1264bbf8e30SJasvinder Singh return -1; 1274bbf8e30SJasvinder Singh } 1284bbf8e30SJasvinder Singh 1294bbf8e30SJasvinder Singh app.script_name = strdup(optarg); 1304bbf8e30SJasvinder Singh if (app.script_name == NULL) { 1314bbf8e30SJasvinder Singh printf("Error: Not enough memory\n"); 1324bbf8e30SJasvinder Singh return -1; 1334bbf8e30SJasvinder Singh } 1344bbf8e30SJasvinder Singh break; 1354bbf8e30SJasvinder Singh 1364bbf8e30SJasvinder Singh default: 1374bbf8e30SJasvinder Singh printf(usage, app_name); 1384bbf8e30SJasvinder Singh return -1; 1394bbf8e30SJasvinder Singh } 1404bbf8e30SJasvinder Singh 1414bbf8e30SJasvinder Singh optind = 1; /* reset getopt lib */ 1424bbf8e30SJasvinder Singh 1434bbf8e30SJasvinder Singh return 0; 1444bbf8e30SJasvinder Singh } 1454bbf8e30SJasvinder Singh 14677a33467SCristian Dumitrescu int 14798a16481SDavid Marchand main(int argc, char **argv) 14877a33467SCristian Dumitrescu { 1494bbf8e30SJasvinder Singh struct conn *conn; 150fbc74e66SJasvinder Singh int status; 15177a33467SCristian Dumitrescu 1524bbf8e30SJasvinder Singh /* Parse application arguments */ 1534bbf8e30SJasvinder Singh status = parse_args(argc, argv); 1544bbf8e30SJasvinder Singh if (status < 0) 1554bbf8e30SJasvinder Singh return status; 1564bbf8e30SJasvinder Singh 157fbc74e66SJasvinder Singh /* EAL */ 158fbc74e66SJasvinder Singh status = rte_eal_init(argc, argv); 159fbc74e66SJasvinder Singh if (status < 0) { 160fbc74e66SJasvinder Singh printf("Error: EAL initialization failed (%d)\n", status); 161fbc74e66SJasvinder Singh return status; 162fbc74e66SJasvinder Singh }; 16377a33467SCristian Dumitrescu 1644bbf8e30SJasvinder Singh /* Connectivity */ 1654bbf8e30SJasvinder Singh conn = conn_init(&app.conn); 1664bbf8e30SJasvinder Singh if (conn == NULL) { 1674bbf8e30SJasvinder Singh printf("Error: Connectivity initialization failed (%d)\n", 1684bbf8e30SJasvinder Singh status); 1694bbf8e30SJasvinder Singh return status; 1704bbf8e30SJasvinder Singh }; 1714bbf8e30SJasvinder Singh 1726bfe74f8SJasvinder Singh /* Mempool */ 1736bfe74f8SJasvinder Singh status = mempool_init(); 1746bfe74f8SJasvinder Singh if (status) { 1756bfe74f8SJasvinder Singh printf("Error: Mempool initialization failed (%d)\n", status); 1766bfe74f8SJasvinder Singh return status; 1776bfe74f8SJasvinder Singh } 1786bfe74f8SJasvinder Singh 179133c2c65SJasvinder Singh /* Link */ 180133c2c65SJasvinder Singh status = link_init(); 181133c2c65SJasvinder Singh if (status) { 182133c2c65SJasvinder Singh printf("Error: Link initialization failed (%d)\n", status); 183133c2c65SJasvinder Singh return status; 184133c2c65SJasvinder Singh } 185133c2c65SJasvinder Singh 1868245472cSJasvinder Singh /* SWQ */ 1878245472cSJasvinder Singh status = swq_init(); 1888245472cSJasvinder Singh if (status) { 1898245472cSJasvinder Singh printf("Error: SWQ initialization failed (%d)\n", status); 1908245472cSJasvinder Singh return status; 1918245472cSJasvinder Singh } 1928245472cSJasvinder Singh 19325961ff3SJasvinder Singh /* Traffic Manager */ 19425961ff3SJasvinder Singh status = tmgr_init(); 19525961ff3SJasvinder Singh if (status) { 19625961ff3SJasvinder Singh printf("Error: TMGR initialization failed (%d)\n", status); 19725961ff3SJasvinder Singh return status; 19825961ff3SJasvinder Singh } 19925961ff3SJasvinder Singh 2002f74ae28SJasvinder Singh /* TAP */ 2012f74ae28SJasvinder Singh status = tap_init(); 2022f74ae28SJasvinder Singh if (status) { 2032f74ae28SJasvinder Singh printf("Error: TAP initialization failed (%d)\n", status); 2042f74ae28SJasvinder Singh return status; 2052f74ae28SJasvinder Singh } 2062f74ae28SJasvinder Singh 2079a408cc8SJasvinder Singh /* KNI */ 2089a408cc8SJasvinder Singh status = kni_init(); 2099a408cc8SJasvinder Singh if (status) { 2109a408cc8SJasvinder Singh printf("Error: KNI initialization failed (%d)\n", status); 2119a408cc8SJasvinder Singh return status; 2129a408cc8SJasvinder Singh } 2139a408cc8SJasvinder Singh 214*bd9b67a1SFan Zhang /* Sym Crypto */ 215*bd9b67a1SFan Zhang status = cryptodev_init(); 216*bd9b67a1SFan Zhang if (status) { 217*bd9b67a1SFan Zhang printf("Error: Cryptodev initialization failed (%d)\n", 218*bd9b67a1SFan Zhang status); 219*bd9b67a1SFan Zhang return status; 220*bd9b67a1SFan Zhang } 221*bd9b67a1SFan Zhang 22271937434SJasvinder Singh /* Action */ 22371937434SJasvinder Singh status = port_in_action_profile_init(); 22471937434SJasvinder Singh if (status) { 22571937434SJasvinder Singh printf("Error: Input port action profile initialization failed (%d)\n", status); 22671937434SJasvinder Singh return status; 22771937434SJasvinder Singh } 22871937434SJasvinder Singh 22971937434SJasvinder Singh status = table_action_profile_init(); 23071937434SJasvinder Singh if (status) { 23171937434SJasvinder Singh printf("Error: Action profile initialization failed (%d)\n", 23271937434SJasvinder Singh status); 23371937434SJasvinder Singh return status; 23471937434SJasvinder Singh } 23571937434SJasvinder Singh 236d75c371eSJasvinder Singh /* Pipeline */ 237d75c371eSJasvinder Singh status = pipeline_init(); 238d75c371eSJasvinder Singh if (status) { 239d75c371eSJasvinder Singh printf("Error: Pipeline initialization failed (%d)\n", status); 240d75c371eSJasvinder Singh return status; 241d75c371eSJasvinder Singh } 242d75c371eSJasvinder Singh 243c0b668e0SJasvinder Singh /* Thread */ 244c0b668e0SJasvinder Singh status = thread_init(); 245c0b668e0SJasvinder Singh if (status) { 246c0b668e0SJasvinder Singh printf("Error: Thread initialization failed (%d)\n", status); 247c0b668e0SJasvinder Singh return status; 248c0b668e0SJasvinder Singh } 249c0b668e0SJasvinder Singh 250a8bd581dSJasvinder Singh rte_eal_mp_remote_launch( 251a8bd581dSJasvinder Singh thread_main, 252a8bd581dSJasvinder Singh NULL, 253a8bd581dSJasvinder Singh SKIP_MASTER); 254a8bd581dSJasvinder Singh 2554bbf8e30SJasvinder Singh /* Script */ 2564bbf8e30SJasvinder Singh if (app.script_name) 2574bbf8e30SJasvinder Singh cli_script_process(app.script_name, 2584bbf8e30SJasvinder Singh app.conn.msg_in_len_max, 2594bbf8e30SJasvinder Singh app.conn.msg_out_len_max); 2604bbf8e30SJasvinder Singh 2614bbf8e30SJasvinder Singh /* Dispatch loop */ 2624bbf8e30SJasvinder Singh for ( ; ; ) { 2634bbf8e30SJasvinder Singh conn_poll_for_conn(conn); 2644bbf8e30SJasvinder Singh 2654bbf8e30SJasvinder Singh conn_poll_for_msg(conn); 2669a408cc8SJasvinder Singh 2679a408cc8SJasvinder Singh kni_handle_request(); 2684bbf8e30SJasvinder Singh } 26977a33467SCristian Dumitrescu } 270