examples: no more bare metal environment
[dpdk.git] / examples / ip_pipeline / main.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 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 #ifndef _MAIN_H_
35 #define _MAIN_H_
36
37 #include <stdint.h>
38
39 #include <rte_mempool.h>
40 #include <rte_mbuf.h>
41 #include <rte_ring.h>
42 #include <rte_ethdev.h>
43
44 #ifdef RTE_LIBRTE_ACL
45 #include <rte_table_acl.h>
46 #endif
47
48 struct app_flow_key {
49         union {
50                 struct {
51                         uint8_t ttl; /* needs to be set to 0 */
52                         uint8_t proto;
53                         uint16_t header_checksum; /* needs to be set to 0 */
54                         uint32_t ip_src;
55                 };
56                 uint64_t slab0;
57         };
58
59         union {
60                 struct {
61                         uint32_t ip_dst;
62                         uint16_t port_src;
63                         uint16_t port_dst;
64                 };
65                 uint64_t slab1;
66         };
67 } __attribute__((__packed__));
68
69 struct app_arp_key {
70         uint32_t nh_ip;
71         uint32_t nh_iface;
72 } __attribute__((__packed__));
73
74 struct app_pkt_metadata {
75         uint32_t signature;
76         uint8_t reserved1[28];
77
78         struct app_flow_key flow_key;
79
80         struct app_arp_key arp_key;
81         struct ether_addr nh_arp;
82
83         uint8_t reserved3[2];
84 } __attribute__((__packed__));
85
86 #ifndef APP_MBUF_ARRAY_SIZE
87 #define APP_MBUF_ARRAY_SIZE            256
88 #endif
89
90 struct app_mbuf_array {
91         struct rte_mbuf *array[APP_MBUF_ARRAY_SIZE];
92         uint32_t n_mbufs;
93 };
94
95 #ifndef APP_MAX_PORTS
96 #define APP_MAX_PORTS                  4
97 #endif
98
99 #ifndef APP_MAX_SWQ_PER_CORE
100 #define APP_MAX_SWQ_PER_CORE           8
101 #endif
102
103 #define APP_SWQ_INVALID                ((uint32_t)(-1))
104
105 #define APP_SWQ_IN_REQ                 (APP_MAX_SWQ_PER_CORE - 1)
106
107 #define APP_SWQ_OUT_RESP               (APP_MAX_SWQ_PER_CORE - 1)
108
109 enum app_core_type {
110         APP_CORE_NONE = 0, /* Unused */
111         APP_CORE_MASTER,   /* Management */
112         APP_CORE_RX,       /* Reception */
113         APP_CORE_TX,       /* Transmission */
114         APP_CORE_PT,       /* Pass-through */
115         APP_CORE_FC,       /* Flow Classification */
116         APP_CORE_FW,       /* Firewall */
117         APP_CORE_RT,       /* Routing */
118         APP_CORE_TM,       /* Traffic Management */
119         APP_CORE_IPV4_FRAG,/* IPv4 Fragmentation */
120         APP_CORE_IPV4_RAS, /* IPv4 Reassembly */
121 };
122
123 struct app_core_params {
124         uint32_t core_id;
125         enum app_core_type core_type;
126
127         /* SWQ map */
128         uint32_t swq_in[APP_MAX_SWQ_PER_CORE];
129         uint32_t swq_out[APP_MAX_SWQ_PER_CORE];
130 } __rte_cache_aligned;
131
132 struct app_params {
133         /* CPU cores */
134         struct app_core_params cores[RTE_MAX_LCORE];
135         uint32_t n_cores;
136
137         /* Ports*/
138         uint32_t ports[APP_MAX_PORTS];
139         uint32_t n_ports;
140         uint32_t rsz_hwq_rx;
141         uint32_t rsz_hwq_tx;
142         uint32_t bsz_hwq_rd;
143         uint32_t bsz_hwq_wr;
144         struct rte_eth_conf port_conf;
145         struct rte_eth_rxconf rx_conf;
146         struct rte_eth_txconf tx_conf;
147
148         /* SW Queues (SWQs) */
149         struct rte_ring **rings;
150         uint32_t rsz_swq;
151         uint32_t bsz_swq_rd;
152         uint32_t bsz_swq_wr;
153
154         /* Buffer pool */
155         struct rte_mempool *pool;
156         struct rte_mempool *indirect_pool;
157         uint32_t pool_buffer_size;
158         uint32_t pool_size;
159         uint32_t pool_cache_size;
160
161         /* Message buffer pool */
162         struct rte_mempool *msg_pool;
163         uint32_t msg_pool_buffer_size;
164         uint32_t msg_pool_size;
165         uint32_t msg_pool_cache_size;
166
167         /* Rule tables */
168         uint32_t max_arp_rules;
169         uint32_t max_routing_rules;
170         uint32_t max_firewall_rules;
171         uint32_t max_flow_rules;
172
173         /* Processing */
174         uint32_t ether_hdr_pop_push;
175 } __rte_cache_aligned;
176
177 extern struct app_params app;
178
179 const char *app_core_type_id_to_string(enum app_core_type id);
180 int app_core_type_string_to_id(const char *string, enum app_core_type *id);
181 void app_cores_config_print(void);
182
183 void app_check_core_params(void);
184 struct app_core_params *app_get_core_params(uint32_t core_id);
185 uint32_t app_get_first_core_id(enum app_core_type core_type);
186 struct rte_ring *app_get_ring_req(uint32_t core_id);
187 struct rte_ring *app_get_ring_resp(uint32_t core_id);
188
189 int app_parse_args(int argc, char **argv);
190 void app_print_usage(char *prgname);
191 void app_init(void);
192 void app_ping(void);
193 int app_lcore_main_loop(void *arg);
194
195 /* Hash functions */
196 uint64_t test_hash(void *key, uint32_t key_size, uint64_t seed);
197 uint32_t rte_jhash2_16(uint32_t *k, uint32_t initval);
198 #if defined(__x86_64__)
199 uint32_t rte_aeshash_16(uint64_t *k, uint64_t seed);
200 uint32_t rte_crchash_16(uint64_t *k, uint64_t seed);
201 #endif
202
203 /* I/O with no pipeline */
204 void app_main_loop_rx(void);
205 void app_main_loop_tx(void);
206 void app_main_loop_passthrough(void);
207
208 /* Pipeline */
209 void app_main_loop_pipeline_rx(void);
210 void app_main_loop_pipeline_rx_frag(void);
211 void app_main_loop_pipeline_tx(void);
212 void app_main_loop_pipeline_tx_ras(void);
213 void app_main_loop_pipeline_flow_classification(void);
214 void app_main_loop_pipeline_firewall(void);
215 void app_main_loop_pipeline_routing(void);
216 void app_main_loop_pipeline_passthrough(void);
217 void app_main_loop_pipeline_ipv4_frag(void);
218 void app_main_loop_pipeline_ipv4_ras(void);
219
220 /* Command Line Interface (CLI) */
221 void app_main_loop_cmdline(void);
222
223 /* Messages */
224 enum app_msg_req_type {
225         APP_MSG_REQ_PING,
226         APP_MSG_REQ_FC_ADD,
227         APP_MSG_REQ_FC_DEL,
228         APP_MSG_REQ_FC_ADD_ALL,
229         APP_MSG_REQ_FW_ADD,
230         APP_MSG_REQ_FW_DEL,
231         APP_MSG_REQ_RT_ADD,
232         APP_MSG_REQ_RT_DEL,
233         APP_MSG_REQ_ARP_ADD,
234         APP_MSG_REQ_ARP_DEL,
235         APP_MSG_REQ_RX_PORT_ENABLE,
236         APP_MSG_REQ_RX_PORT_DISABLE,
237 };
238
239 struct app_msg_req {
240         enum app_msg_req_type type;
241         union {
242                 struct {
243                         uint32_t ip;
244                         uint8_t depth;
245                         uint8_t port;
246                         uint32_t nh_ip;
247                 } routing_add;
248                 struct {
249                         uint32_t ip;
250                         uint8_t depth;
251                 } routing_del;
252                 struct {
253                         uint8_t out_iface;
254                         uint32_t nh_ip;
255                         struct ether_addr nh_arp;
256                 } arp_add;
257                 struct {
258                         uint8_t out_iface;
259                         uint32_t nh_ip;
260                 } arp_del;
261                 struct {
262                         union {
263                                 uint8_t key_raw[16];
264                                 struct app_flow_key key;
265                         };
266                         uint8_t port;
267                 } flow_classif_add;
268                 struct {
269                         union {
270                                 uint8_t key_raw[16];
271                                 struct app_flow_key key;
272                         };
273                 } flow_classif_del;
274 #ifdef RTE_LIBRTE_ACL
275                 struct {
276                         struct rte_table_acl_rule_add_params add_params;
277                         uint8_t port;
278                 } firewall_add;
279                 struct {
280                         struct rte_table_acl_rule_delete_params delete_params;
281                 } firewall_del;
282 #endif
283                 struct {
284                         uint8_t port;
285                 } rx_up;
286                 struct {
287                         uint8_t port;
288                 } rx_down;
289         };
290 };
291
292 struct app_msg_resp {
293         int result;
294 };
295
296 #define APP_FLUSH 0xFF
297
298 #endif /* _MAIN_H_ */