examples/ip_pipeline: assign MAC address to routing ports
[dpdk.git] / examples / ip_pipeline / pipeline / pipeline_routing_be.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2015 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 __INCLUDE_PIPELINE_ROUTING_BE_H__
35 #define __INCLUDE_PIPELINE_ROUTING_BE_H__
36
37 #include <rte_ether.h>
38
39 #include "pipeline_common_be.h"
40
41 /*
42  * Pipeline argument parsing
43  */
44 #ifndef PIPELINE_ROUTING_N_ROUTES_DEFAULT
45 #define PIPELINE_ROUTING_N_ROUTES_DEFAULT                  4096
46 #endif
47
48 enum pipeline_routing_encap {
49         PIPELINE_ROUTING_ENCAP_ETHERNET = 0,
50         PIPELINE_ROUTING_ENCAP_ETHERNET_QINQ,
51         PIPELINE_ROUTING_ENCAP_ETHERNET_MPLS,
52 };
53
54 struct pipeline_routing_params {
55         /* routing */
56         uint32_t n_routes;
57
58         /* routing packet encapsulation */
59         enum pipeline_routing_encap encap;
60         uint32_t qinq_sched;
61         uint32_t mpls_color_mark;
62
63         /* arp */
64         uint32_t n_arp_entries;
65
66         /* packet buffer offsets */
67         uint32_t ip_hdr_offset;
68         uint32_t arp_key_offset;
69         uint32_t color_offset;
70
71         /* debug */
72         uint32_t dbg_ah_disable;
73 };
74
75 int
76 pipeline_routing_parse_args(struct pipeline_routing_params *p,
77         struct pipeline_params *params);
78
79 /*
80  * Route
81  */
82 enum pipeline_routing_route_key_type {
83         PIPELINE_ROUTING_ROUTE_IPV4,
84 };
85
86 struct pipeline_routing_route_key_ipv4 {
87         uint32_t ip;
88         uint32_t depth;
89 };
90
91 struct pipeline_routing_route_key {
92         enum pipeline_routing_route_key_type type;
93         union {
94                 struct pipeline_routing_route_key_ipv4 ipv4;
95         } key;
96 };
97
98 enum pipeline_routing_route_flags {
99         PIPELINE_ROUTING_ROUTE_LOCAL = 1 << 0, /* 0 = remote; 1 = local */
100         PIPELINE_ROUTING_ROUTE_ARP = 1 << 1, /* 0 = ARP OFF; 1 = ARP ON */
101         PIPELINE_ROUTING_ROUTE_QINQ = 1 << 2, /* 0 = QINQ OFF; 1 = QINQ ON */
102         PIPELINE_ROUTING_ROUTE_MPLS = 1 << 3, /* 0 = MPLS OFF; 1 = MPLS ON */
103 };
104
105 #define PIPELINE_ROUTING_MPLS_LABELS_MAX         4
106
107 struct pipeline_routing_route_data {
108         uint32_t flags;
109         uint32_t port_id; /* Output port ID */
110
111         union {
112                 /* Next hop IP (valid only when ARP is enabled) */
113                 uint32_t ip;
114
115                 /* Next hop MAC address (valid only when ARP disabled */
116                 struct ether_addr macaddr;
117         } ethernet;
118
119         union {
120                 struct {
121                         uint16_t svlan;
122                         uint16_t cvlan;
123                 } qinq;
124
125                 struct {
126                         uint32_t labels[PIPELINE_ROUTING_MPLS_LABELS_MAX];
127                         uint32_t n_labels;
128                 } mpls;
129         } l2;
130 };
131
132 /*
133  * ARP
134  */
135 enum pipeline_routing_arp_key_type {
136         PIPELINE_ROUTING_ARP_IPV4,
137 };
138
139 struct pipeline_routing_arp_key_ipv4 {
140         uint32_t port_id;
141         uint32_t ip;
142 };
143
144 struct pipeline_routing_arp_key {
145         enum pipeline_routing_arp_key_type type;
146         union {
147                 struct pipeline_routing_arp_key_ipv4 ipv4;
148         } key;
149 };
150
151 /*
152  * Messages
153  */
154 enum pipeline_routing_msg_req_type {
155         PIPELINE_ROUTING_MSG_REQ_ROUTE_ADD,
156         PIPELINE_ROUTING_MSG_REQ_ROUTE_DEL,
157         PIPELINE_ROUTING_MSG_REQ_ROUTE_ADD_DEFAULT,
158         PIPELINE_ROUTING_MSG_REQ_ROUTE_DEL_DEFAULT,
159         PIPELINE_ROUTING_MSG_REQ_ARP_ADD,
160         PIPELINE_ROUTING_MSG_REQ_ARP_DEL,
161         PIPELINE_ROUTING_MSG_REQ_ARP_ADD_DEFAULT,
162         PIPELINE_ROUTING_MSG_REQ_ARP_DEL_DEFAULT,
163         PIPELINE_ROUTING_MSG_REQ_SET_MACADDR,
164         PIPELINE_ROUTING_MSG_REQS
165 };
166
167 /*
168  * MSG ROUTE ADD
169  */
170 struct pipeline_routing_route_add_msg_req {
171         enum pipeline_msg_req_type type;
172         enum pipeline_routing_msg_req_type subtype;
173
174         /* key */
175         struct pipeline_routing_route_key key;
176
177         /* data */
178         struct pipeline_routing_route_data data;
179 };
180
181 struct pipeline_routing_route_add_msg_rsp {
182         int status;
183         int key_found;
184         void *entry_ptr;
185 };
186
187 /*
188  * MSG ROUTE DELETE
189  */
190 struct pipeline_routing_route_delete_msg_req {
191         enum pipeline_msg_req_type type;
192         enum pipeline_routing_msg_req_type subtype;
193
194         /* key */
195         struct pipeline_routing_route_key key;
196 };
197
198 struct pipeline_routing_route_delete_msg_rsp {
199         int status;
200         int key_found;
201 };
202
203 /*
204  * MSG ROUTE ADD DEFAULT
205  */
206 struct pipeline_routing_route_add_default_msg_req {
207         enum pipeline_msg_req_type type;
208         enum pipeline_routing_msg_req_type subtype;
209
210         /* data */
211         uint32_t port_id;
212 };
213
214 struct pipeline_routing_route_add_default_msg_rsp {
215         int status;
216         void *entry_ptr;
217 };
218
219 /*
220  * MSG ROUTE DELETE DEFAULT
221  */
222 struct pipeline_routing_route_delete_default_msg_req {
223         enum pipeline_msg_req_type type;
224         enum pipeline_routing_msg_req_type subtype;
225 };
226
227 struct pipeline_routing_route_delete_default_msg_rsp {
228         int status;
229 };
230
231 /*
232  * MSG ARP ADD
233  */
234 struct pipeline_routing_arp_add_msg_req {
235         enum pipeline_msg_req_type type;
236         enum pipeline_routing_msg_req_type subtype;
237
238         /* key */
239         struct pipeline_routing_arp_key key;
240
241         /* data */
242         struct ether_addr macaddr;
243 };
244
245 struct pipeline_routing_arp_add_msg_rsp {
246         int status;
247         int key_found;
248         void *entry_ptr;
249 };
250
251 /*
252  * MSG ARP DELETE
253  */
254 struct pipeline_routing_arp_delete_msg_req {
255         enum pipeline_msg_req_type type;
256         enum pipeline_routing_msg_req_type subtype;
257
258         /* key */
259         struct pipeline_routing_arp_key key;
260 };
261
262 struct pipeline_routing_arp_delete_msg_rsp {
263         int status;
264         int key_found;
265 };
266
267 /*
268  * MSG ARP ADD DEFAULT
269  */
270 struct pipeline_routing_arp_add_default_msg_req {
271         enum pipeline_msg_req_type type;
272         enum pipeline_routing_msg_req_type subtype;
273
274         /* data */
275         uint32_t port_id;
276 };
277
278 struct pipeline_routing_arp_add_default_msg_rsp {
279         int status;
280         void *entry_ptr;
281 };
282
283 /*
284  * MSG ARP DELETE DEFAULT
285  */
286 struct pipeline_routing_arp_delete_default_msg_req {
287         enum pipeline_msg_req_type type;
288         enum pipeline_routing_msg_req_type subtype;
289 };
290
291 struct pipeline_routing_arp_delete_default_msg_rsp {
292         int status;
293 };
294
295 /*
296  * MSG SET MACADDR
297  */
298 struct pipeline_routing_set_macaddr_msg_req {
299         enum pipeline_msg_req_type type;
300         enum pipeline_routing_msg_req_type subtype;
301
302         uint64_t macaddr[PIPELINE_MAX_PORT_OUT];
303 };
304
305 struct pipeline_routing_set_macaddr_msg_rsp {
306         int status;
307 };
308
309 extern struct pipeline_be_ops pipeline_routing_be_ops;
310
311 #endif