xref: /dpdk/app/test-pipeline/main.c (revision ffad67843613de9cd649f69d793f95eeb81f8c43)
1474572d2SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
2474572d2SBruce Richardson  * Copyright(c) 2010-2016 Intel Corporation
3474572d2SBruce Richardson  */
4474572d2SBruce Richardson 
5474572d2SBruce Richardson #include <stdio.h>
6474572d2SBruce Richardson #include <stdlib.h>
7474572d2SBruce Richardson #include <stdint.h>
8474572d2SBruce Richardson #include <inttypes.h>
9474572d2SBruce Richardson #include <sys/types.h>
10474572d2SBruce Richardson #include <string.h>
11474572d2SBruce Richardson #include <sys/queue.h>
12474572d2SBruce Richardson #include <stdarg.h>
13f6897b23SFeifei Wang #include <signal.h>
14474572d2SBruce Richardson #include <errno.h>
15474572d2SBruce Richardson #include <getopt.h>
16474572d2SBruce Richardson #include <unistd.h>
17474572d2SBruce Richardson 
18474572d2SBruce Richardson #include <rte_common.h>
19474572d2SBruce Richardson #include <rte_byteorder.h>
20474572d2SBruce Richardson #include <rte_log.h>
21474572d2SBruce Richardson #include <rte_memory.h>
22474572d2SBruce Richardson #include <rte_memcpy.h>
23474572d2SBruce Richardson #include <rte_eal.h>
24474572d2SBruce Richardson #include <rte_per_lcore.h>
25474572d2SBruce Richardson #include <rte_launch.h>
26474572d2SBruce Richardson #include <rte_cycles.h>
27474572d2SBruce Richardson #include <rte_prefetch.h>
28474572d2SBruce Richardson #include <rte_lcore.h>
29474572d2SBruce Richardson #include <rte_branch_prediction.h>
30474572d2SBruce Richardson #include <rte_interrupts.h>
31474572d2SBruce Richardson #include <rte_pci.h>
32474572d2SBruce Richardson #include <rte_random.h>
33474572d2SBruce Richardson #include <rte_debug.h>
34474572d2SBruce Richardson #include <rte_ether.h>
35474572d2SBruce Richardson #include <rte_ethdev.h>
36474572d2SBruce Richardson #include <rte_mempool.h>
37474572d2SBruce Richardson #include <rte_mbuf.h>
38474572d2SBruce Richardson #include <rte_ip.h>
39474572d2SBruce Richardson #include <rte_tcp.h>
40474572d2SBruce Richardson #include <rte_lpm.h>
41474572d2SBruce Richardson #include <rte_lpm6.h>
42474572d2SBruce Richardson 
43474572d2SBruce Richardson #include "main.h"
44474572d2SBruce Richardson 
45f6897b23SFeifei Wang bool force_quit;
46f6897b23SFeifei Wang 
47f6897b23SFeifei Wang static void
signal_handler(int signum)48f6897b23SFeifei Wang signal_handler(int signum)
49f6897b23SFeifei Wang {
50f6897b23SFeifei Wang 	if (signum == SIGINT || signum == SIGTERM)
51f6897b23SFeifei Wang 		force_quit = true;
52f6897b23SFeifei Wang }
53f6897b23SFeifei Wang 
54474572d2SBruce Richardson int
main(int argc,char ** argv)55474572d2SBruce Richardson main(int argc, char **argv)
56474572d2SBruce Richardson {
57474572d2SBruce Richardson 	uint32_t lcore;
58*ffad6784SFeifei Wang 	uint32_t i;
59474572d2SBruce Richardson 	int ret;
60474572d2SBruce Richardson 
61474572d2SBruce Richardson 	/* Init EAL */
62474572d2SBruce Richardson 	ret = rte_eal_init(argc, argv);
63474572d2SBruce Richardson 	if (ret < 0)
64474572d2SBruce Richardson 		return -1;
65474572d2SBruce Richardson 	argc -= ret;
66474572d2SBruce Richardson 	argv += ret;
67474572d2SBruce Richardson 
68f6897b23SFeifei Wang 	force_quit = false;
69f6897b23SFeifei Wang 	signal(SIGINT, signal_handler);
70f6897b23SFeifei Wang 	signal(SIGTERM, signal_handler);
71f6897b23SFeifei Wang 
72474572d2SBruce Richardson 	/* Parse application arguments (after the EAL ones) */
73474572d2SBruce Richardson 	ret = app_parse_args(argc, argv);
74474572d2SBruce Richardson 	if (ret < 0) {
75474572d2SBruce Richardson 		app_print_usage();
76474572d2SBruce Richardson 		return -1;
77474572d2SBruce Richardson 	}
78474572d2SBruce Richardson 
79474572d2SBruce Richardson 	/* Init */
80474572d2SBruce Richardson 	app_init();
81474572d2SBruce Richardson 
82474572d2SBruce Richardson 	/* Launch per-lcore init on every lcore */
83cb056611SStephen Hemminger 	rte_eal_mp_remote_launch(app_lcore_main_loop, NULL, CALL_MAIN);
84cb056611SStephen Hemminger 	RTE_LCORE_FOREACH_WORKER(lcore) {
85474572d2SBruce Richardson 		if (rte_eal_wait_lcore(lcore) < 0)
86474572d2SBruce Richardson 			return -1;
87474572d2SBruce Richardson 	}
88474572d2SBruce Richardson 
89*ffad6784SFeifei Wang 	/* Close ports */
90*ffad6784SFeifei Wang 	for (i = 0; i < app.n_ports; i++) {
91*ffad6784SFeifei Wang 		uint16_t port;
92*ffad6784SFeifei Wang 		int ret;
93*ffad6784SFeifei Wang 
94*ffad6784SFeifei Wang 		port = app.ports[i];
95*ffad6784SFeifei Wang 		printf("Closing port %d...", port);
96*ffad6784SFeifei Wang 		ret = rte_eth_dev_stop(port);
97*ffad6784SFeifei Wang 		if (ret != 0)
98*ffad6784SFeifei Wang 			printf("rte_eth_dev_stop: err=%d, port=%u\n",
99*ffad6784SFeifei Wang 					 ret, port);
100*ffad6784SFeifei Wang 		rte_eth_dev_close(port);
101*ffad6784SFeifei Wang 		printf("Done\n");
102*ffad6784SFeifei Wang 	}
103*ffad6784SFeifei Wang 
104*ffad6784SFeifei Wang 	/* Clean up the EAL */
105*ffad6784SFeifei Wang 	rte_eal_cleanup();
106*ffad6784SFeifei Wang 
107474572d2SBruce Richardson 	return 0;
108474572d2SBruce Richardson }
109474572d2SBruce Richardson 
110474572d2SBruce Richardson int
app_lcore_main_loop(__rte_unused void * arg)111f2fc83b4SThomas Monjalon app_lcore_main_loop(__rte_unused void *arg)
112474572d2SBruce Richardson {
113474572d2SBruce Richardson 	unsigned lcore;
114474572d2SBruce Richardson 
115474572d2SBruce Richardson 	lcore = rte_lcore_id();
116474572d2SBruce Richardson 
117474572d2SBruce Richardson 	if (lcore == app.core_rx) {
118474572d2SBruce Richardson 		switch (app.pipeline_type) {
119474572d2SBruce Richardson 		case e_APP_PIPELINE_ACL:
120474572d2SBruce Richardson 			app_main_loop_rx();
121474572d2SBruce Richardson 			return 0;
122474572d2SBruce Richardson 
123474572d2SBruce Richardson 		default:
124474572d2SBruce Richardson 			app_main_loop_rx_metadata();
125474572d2SBruce Richardson 			return 0;
126474572d2SBruce Richardson 		}
127474572d2SBruce Richardson 	}
128474572d2SBruce Richardson 
129474572d2SBruce Richardson 	if (lcore == app.core_worker) {
130474572d2SBruce Richardson 		switch (app.pipeline_type) {
131474572d2SBruce Richardson 		case e_APP_PIPELINE_STUB:
132474572d2SBruce Richardson 			app_main_loop_worker_pipeline_stub();
133474572d2SBruce Richardson 			return 0;
134474572d2SBruce Richardson 
135474572d2SBruce Richardson 		case e_APP_PIPELINE_HASH_KEY8_EXT:
136474572d2SBruce Richardson 		case e_APP_PIPELINE_HASH_KEY8_LRU:
137474572d2SBruce Richardson 		case e_APP_PIPELINE_HASH_KEY16_EXT:
138474572d2SBruce Richardson 		case e_APP_PIPELINE_HASH_KEY16_LRU:
139474572d2SBruce Richardson 		case e_APP_PIPELINE_HASH_KEY32_EXT:
140474572d2SBruce Richardson 		case e_APP_PIPELINE_HASH_KEY32_LRU:
141474572d2SBruce Richardson 		case e_APP_PIPELINE_HASH_SPEC_KEY8_EXT:
142474572d2SBruce Richardson 		case e_APP_PIPELINE_HASH_SPEC_KEY8_LRU:
143474572d2SBruce Richardson 		case e_APP_PIPELINE_HASH_SPEC_KEY16_EXT:
144474572d2SBruce Richardson 		case e_APP_PIPELINE_HASH_SPEC_KEY16_LRU:
145474572d2SBruce Richardson 		case e_APP_PIPELINE_HASH_SPEC_KEY32_EXT:
146474572d2SBruce Richardson 		case e_APP_PIPELINE_HASH_SPEC_KEY32_LRU:
147474572d2SBruce Richardson 		/* cases for cuckoo hash table types */
148474572d2SBruce Richardson 		case e_APP_PIPELINE_HASH_CUCKOO_KEY8:
149474572d2SBruce Richardson 		case e_APP_PIPELINE_HASH_CUCKOO_KEY16:
150474572d2SBruce Richardson 		case e_APP_PIPELINE_HASH_CUCKOO_KEY32:
151474572d2SBruce Richardson 		case e_APP_PIPELINE_HASH_CUCKOO_KEY48:
152474572d2SBruce Richardson 		case e_APP_PIPELINE_HASH_CUCKOO_KEY64:
153474572d2SBruce Richardson 		case e_APP_PIPELINE_HASH_CUCKOO_KEY80:
154474572d2SBruce Richardson 		case e_APP_PIPELINE_HASH_CUCKOO_KEY96:
155474572d2SBruce Richardson 		case e_APP_PIPELINE_HASH_CUCKOO_KEY112:
156474572d2SBruce Richardson 		case e_APP_PIPELINE_HASH_CUCKOO_KEY128:
157474572d2SBruce Richardson 			app_main_loop_worker_pipeline_hash();
158474572d2SBruce Richardson 			return 0;
159474572d2SBruce Richardson 
160474572d2SBruce Richardson 		case e_APP_PIPELINE_ACL:
161a8d0d473SBruce Richardson #ifndef RTE_LIB_ACL
162474572d2SBruce Richardson 			rte_exit(EXIT_FAILURE, "ACL not present in build\n");
163474572d2SBruce Richardson #else
164474572d2SBruce Richardson 			app_main_loop_worker_pipeline_acl();
165474572d2SBruce Richardson 			return 0;
166474572d2SBruce Richardson #endif
167474572d2SBruce Richardson 
168474572d2SBruce Richardson 		case e_APP_PIPELINE_LPM:
169474572d2SBruce Richardson 			app_main_loop_worker_pipeline_lpm();
170474572d2SBruce Richardson 			return 0;
171474572d2SBruce Richardson 
172474572d2SBruce Richardson 		case e_APP_PIPELINE_LPM_IPV6:
173474572d2SBruce Richardson 			app_main_loop_worker_pipeline_lpm_ipv6();
174474572d2SBruce Richardson 			return 0;
175474572d2SBruce Richardson 
176474572d2SBruce Richardson 		case e_APP_PIPELINE_NONE:
177474572d2SBruce Richardson 		default:
178474572d2SBruce Richardson 			app_main_loop_worker();
179474572d2SBruce Richardson 			return 0;
180474572d2SBruce Richardson 		}
181474572d2SBruce Richardson 	}
182474572d2SBruce Richardson 
183474572d2SBruce Richardson 	if (lcore == app.core_tx) {
184474572d2SBruce Richardson 		app_main_loop_tx();
185474572d2SBruce Richardson 		return 0;
186474572d2SBruce Richardson 	}
187474572d2SBruce Richardson 
188474572d2SBruce Richardson 	return 0;
189474572d2SBruce Richardson }
190