gateway: Created common code for routing in gateway
[samplevnf.git] / common / VIL / gateway / gateway.h
1 /*
2 // Copyright (c) 2017 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 #ifndef __INCLUDE_GATEWAY_H__
18 #define __INCLUDE_GATEWAY_H__
19
20 /**
21  * @file
22  * gateway.h
23  *
24  * Provide APIs for Packet fowarding in gateway configuration.
25  *
26  */
27
28 #include <rte_common.h>
29 #include <rte_malloc.h>
30 #include <rte_ether.h>
31 #include <rte_ethdev.h>
32 #include <rte_ip.h>
33 #include <rte_udp.h>
34 #include <rte_mbuf.h>
35 #include <rte_byteorder.h>
36
37 #include "pipeline.h"
38 #include "app.h"
39 #include "vnf_common.h"
40 #include "vnf_define.h"
41
42 /**
43 * A structure for Route table entries of IPv4
44 */
45 #define MAX_ROUTE_ENTRY_SIZE    32
46 #define MAX_ND_ROUTE_ENTRY_SIZE 32
47
48 extern struct route_data *p_route_data[];
49 extern struct nd_route_data *p_nd_route_data[];
50
51 extern uint32_t vnf_gateway;
52
53 /**
54  * A structure for Route table entires of IPv4
55  *
56  */
57 struct route_table_entry {
58         uint32_t nh;    /**< next hop */
59         uint32_t mask;  /**< mask */
60         uint32_t port;  /**< Physical port */
61         uint32_t nh_mask;
62 } __rte_cache_aligned;
63
64 /**
65  * Routing table for IPv4
66  *
67  */
68 struct route_data {
69         struct route_table_entry route_table[MAX_ROUTE_ENTRY_SIZE];
70         uint8_t route_ent_cnt;
71 };
72
73 /**
74  * A structure for Route table entires of IPv6
75  *
76  */
77 struct nd_route_table_entry {
78         uint8_t nhipv6[16];     /**< next hop Ipv6 */
79         uint8_t depth;          /**< Depth */
80         uint32_t port;          /**< Port */
81 };
82
83 /**
84  * Routing table for IPv6
85  *
86  */
87 struct nd_route_data {
88         struct nd_route_table_entry nd_route_table[MAX_ND_ROUTE_ENTRY_SIZE];
89         uint8_t nd_route_ent_cnt;
90 };
91
92 extern void gw_init(uint32_t num_ports);
93
94 extern uint32_t gw_get_num_ports(void);
95
96 extern uint32_t is_gateway(void);
97
98 extern void gw_get_nh_port_ipv4(uint32_t dst_ip_addr,
99                                         uint32_t *dst_port, uint32_t *nhip);
100
101 extern void gw_get_nh_port_ipv6(uint8_t *dst_ipv6_addr,
102                                         uint32_t *dst_port, uint8_t *nhipv6);
103
104 #endif