795b1aeb6ae9d4ea5aeebe79b7386cc90d8f71a0
[deb_dpdk.git] / test / test-pipeline / main.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <stdint.h>
37 #include <inttypes.h>
38 #include <sys/types.h>
39 #include <string.h>
40 #include <sys/queue.h>
41 #include <stdarg.h>
42 #include <errno.h>
43 #include <getopt.h>
44 #include <unistd.h>
45
46 #include <rte_common.h>
47 #include <rte_byteorder.h>
48 #include <rte_log.h>
49 #include <rte_memory.h>
50 #include <rte_memcpy.h>
51 #include <rte_memzone.h>
52 #include <rte_eal.h>
53 #include <rte_per_lcore.h>
54 #include <rte_launch.h>
55 #include <rte_atomic.h>
56 #include <rte_cycles.h>
57 #include <rte_prefetch.h>
58 #include <rte_lcore.h>
59 #include <rte_branch_prediction.h>
60 #include <rte_interrupts.h>
61 #include <rte_pci.h>
62 #include <rte_random.h>
63 #include <rte_debug.h>
64 #include <rte_ether.h>
65 #include <rte_ethdev.h>
66 #include <rte_mempool.h>
67 #include <rte_mbuf.h>
68 #include <rte_ip.h>
69 #include <rte_tcp.h>
70 #include <rte_lpm.h>
71 #include <rte_lpm6.h>
72
73 #include "main.h"
74
75 int
76 main(int argc, char **argv)
77 {
78         uint32_t lcore;
79         int ret;
80
81         /* Init EAL */
82         ret = rte_eal_init(argc, argv);
83         if (ret < 0)
84                 return -1;
85         argc -= ret;
86         argv += ret;
87
88         /* Parse application arguments (after the EAL ones) */
89         ret = app_parse_args(argc, argv);
90         if (ret < 0) {
91                 app_print_usage();
92                 return -1;
93         }
94
95         /* Init */
96         app_init();
97
98         /* Launch per-lcore init on every lcore */
99         rte_eal_mp_remote_launch(app_lcore_main_loop, NULL, CALL_MASTER);
100         RTE_LCORE_FOREACH_SLAVE(lcore) {
101                 if (rte_eal_wait_lcore(lcore) < 0)
102                         return -1;
103         }
104
105         return 0;
106 }
107
108 int
109 app_lcore_main_loop(__attribute__((unused)) void *arg)
110 {
111         unsigned lcore;
112
113         lcore = rte_lcore_id();
114
115         if (lcore == app.core_rx) {
116                 switch (app.pipeline_type) {
117                 case e_APP_PIPELINE_ACL:
118                         app_main_loop_rx();
119                         return 0;
120
121                 default:
122                         app_main_loop_rx_metadata();
123                         return 0;
124                 }
125         }
126
127         if (lcore == app.core_worker) {
128                 switch (app.pipeline_type) {
129                 case e_APP_PIPELINE_STUB:
130                         app_main_loop_worker_pipeline_stub();
131                         return 0;
132
133                 case e_APP_PIPELINE_HASH_KEY8_EXT:
134                 case e_APP_PIPELINE_HASH_KEY8_LRU:
135                 case e_APP_PIPELINE_HASH_KEY16_EXT:
136                 case e_APP_PIPELINE_HASH_KEY16_LRU:
137                 case e_APP_PIPELINE_HASH_KEY32_EXT:
138                 case e_APP_PIPELINE_HASH_KEY32_LRU:
139                 case e_APP_PIPELINE_HASH_SPEC_KEY8_EXT:
140                 case e_APP_PIPELINE_HASH_SPEC_KEY8_LRU:
141                 case e_APP_PIPELINE_HASH_SPEC_KEY16_EXT:
142                 case e_APP_PIPELINE_HASH_SPEC_KEY16_LRU:
143                 case e_APP_PIPELINE_HASH_SPEC_KEY32_EXT:
144                 case e_APP_PIPELINE_HASH_SPEC_KEY32_LRU:
145                 /* cases for cuckoo hash table types */
146                 case e_APP_PIPELINE_HASH_CUCKOO_KEY8:
147                 case e_APP_PIPELINE_HASH_CUCKOO_KEY16:
148                 case e_APP_PIPELINE_HASH_CUCKOO_KEY32:
149                 case e_APP_PIPELINE_HASH_CUCKOO_KEY48:
150                 case e_APP_PIPELINE_HASH_CUCKOO_KEY64:
151                 case e_APP_PIPELINE_HASH_CUCKOO_KEY80:
152                 case e_APP_PIPELINE_HASH_CUCKOO_KEY96:
153                 case e_APP_PIPELINE_HASH_CUCKOO_KEY112:
154                 case e_APP_PIPELINE_HASH_CUCKOO_KEY128:
155                         app_main_loop_worker_pipeline_hash();
156                         return 0;
157
158                 case e_APP_PIPELINE_ACL:
159 #ifndef RTE_LIBRTE_ACL
160                         rte_exit(EXIT_FAILURE, "ACL not present in build\n");
161 #else
162                         app_main_loop_worker_pipeline_acl();
163                         return 0;
164 #endif
165
166                 case e_APP_PIPELINE_LPM:
167                         app_main_loop_worker_pipeline_lpm();
168                         return 0;
169
170                 case e_APP_PIPELINE_LPM_IPV6:
171                         app_main_loop_worker_pipeline_lpm_ipv6();
172                         return 0;
173
174                 case e_APP_PIPELINE_NONE:
175                 default:
176                         app_main_loop_worker();
177                         return 0;
178                 }
179         }
180
181         if (lcore == app.core_tx) {
182                 app_main_loop_tx();
183                 return 0;
184         }
185
186         return 0;
187 }