xref: /dpdk/app/test-pipeline/main.c (revision f8dbaebbf1c9efcbb2e2354b341ed62175466a57)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation
3  */
4 
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <stdint.h>
8 #include <inttypes.h>
9 #include <sys/types.h>
10 #include <string.h>
11 #include <sys/queue.h>
12 #include <stdarg.h>
13 #include <errno.h>
14 #include <getopt.h>
15 #include <unistd.h>
16 
17 #include <rte_common.h>
18 #include <rte_byteorder.h>
19 #include <rte_log.h>
20 #include <rte_memory.h>
21 #include <rte_memcpy.h>
22 #include <rte_eal.h>
23 #include <rte_per_lcore.h>
24 #include <rte_launch.h>
25 #include <rte_cycles.h>
26 #include <rte_prefetch.h>
27 #include <rte_lcore.h>
28 #include <rte_branch_prediction.h>
29 #include <rte_interrupts.h>
30 #include <rte_pci.h>
31 #include <rte_random.h>
32 #include <rte_debug.h>
33 #include <rte_ether.h>
34 #include <rte_ethdev.h>
35 #include <rte_mempool.h>
36 #include <rte_mbuf.h>
37 #include <rte_ip.h>
38 #include <rte_tcp.h>
39 #include <rte_lpm.h>
40 #include <rte_lpm6.h>
41 
42 #include "main.h"
43 
44 int
45 main(int argc, char **argv)
46 {
47 	uint32_t lcore;
48 	int ret;
49 
50 	/* Init EAL */
51 	ret = rte_eal_init(argc, argv);
52 	if (ret < 0)
53 		return -1;
54 	argc -= ret;
55 	argv += ret;
56 
57 	/* Parse application arguments (after the EAL ones) */
58 	ret = app_parse_args(argc, argv);
59 	if (ret < 0) {
60 		app_print_usage();
61 		return -1;
62 	}
63 
64 	/* Init */
65 	app_init();
66 
67 	/* Launch per-lcore init on every lcore */
68 	rte_eal_mp_remote_launch(app_lcore_main_loop, NULL, CALL_MAIN);
69 	RTE_LCORE_FOREACH_WORKER(lcore) {
70 		if (rte_eal_wait_lcore(lcore) < 0)
71 			return -1;
72 	}
73 
74 	return 0;
75 }
76 
77 int
78 app_lcore_main_loop(__rte_unused void *arg)
79 {
80 	unsigned lcore;
81 
82 	lcore = rte_lcore_id();
83 
84 	if (lcore == app.core_rx) {
85 		switch (app.pipeline_type) {
86 		case e_APP_PIPELINE_ACL:
87 			app_main_loop_rx();
88 			return 0;
89 
90 		default:
91 			app_main_loop_rx_metadata();
92 			return 0;
93 		}
94 	}
95 
96 	if (lcore == app.core_worker) {
97 		switch (app.pipeline_type) {
98 		case e_APP_PIPELINE_STUB:
99 			app_main_loop_worker_pipeline_stub();
100 			return 0;
101 
102 		case e_APP_PIPELINE_HASH_KEY8_EXT:
103 		case e_APP_PIPELINE_HASH_KEY8_LRU:
104 		case e_APP_PIPELINE_HASH_KEY16_EXT:
105 		case e_APP_PIPELINE_HASH_KEY16_LRU:
106 		case e_APP_PIPELINE_HASH_KEY32_EXT:
107 		case e_APP_PIPELINE_HASH_KEY32_LRU:
108 		case e_APP_PIPELINE_HASH_SPEC_KEY8_EXT:
109 		case e_APP_PIPELINE_HASH_SPEC_KEY8_LRU:
110 		case e_APP_PIPELINE_HASH_SPEC_KEY16_EXT:
111 		case e_APP_PIPELINE_HASH_SPEC_KEY16_LRU:
112 		case e_APP_PIPELINE_HASH_SPEC_KEY32_EXT:
113 		case e_APP_PIPELINE_HASH_SPEC_KEY32_LRU:
114 		/* cases for cuckoo hash table types */
115 		case e_APP_PIPELINE_HASH_CUCKOO_KEY8:
116 		case e_APP_PIPELINE_HASH_CUCKOO_KEY16:
117 		case e_APP_PIPELINE_HASH_CUCKOO_KEY32:
118 		case e_APP_PIPELINE_HASH_CUCKOO_KEY48:
119 		case e_APP_PIPELINE_HASH_CUCKOO_KEY64:
120 		case e_APP_PIPELINE_HASH_CUCKOO_KEY80:
121 		case e_APP_PIPELINE_HASH_CUCKOO_KEY96:
122 		case e_APP_PIPELINE_HASH_CUCKOO_KEY112:
123 		case e_APP_PIPELINE_HASH_CUCKOO_KEY128:
124 			app_main_loop_worker_pipeline_hash();
125 			return 0;
126 
127 		case e_APP_PIPELINE_ACL:
128 #ifndef RTE_LIB_ACL
129 			rte_exit(EXIT_FAILURE, "ACL not present in build\n");
130 #else
131 			app_main_loop_worker_pipeline_acl();
132 			return 0;
133 #endif
134 
135 		case e_APP_PIPELINE_LPM:
136 			app_main_loop_worker_pipeline_lpm();
137 			return 0;
138 
139 		case e_APP_PIPELINE_LPM_IPV6:
140 			app_main_loop_worker_pipeline_lpm_ipv6();
141 			return 0;
142 
143 		case e_APP_PIPELINE_NONE:
144 		default:
145 			app_main_loop_worker();
146 			return 0;
147 		}
148 	}
149 
150 	if (lcore == app.core_tx) {
151 		app_main_loop_tx();
152 		return 0;
153 	}
154 
155 	return 0;
156 }
157