Moving to python 3 for kubernetes scripts
[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 }__rte_cache_aligned;
72
73 /**
74  * A structure for Route table entires of IPv6
75  *
76  */
77 struct nd_route_table_entry {
78         uint32_t port;          /**< Port */
79         uint8_t nhipv6[16];     /**< next hop Ipv6 */
80         uint8_t depth;          /**< Depth */
81 }__rte_cache_aligned;
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 }__rte_cache_aligned;
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 /**
99  * Get the route next hop ip address and port number for IPv4
100  * @param dst_ip_addr
101  *  Destination IPv4 address
102  * @param dst_port
103  *  A pointer to destination port
104  * @param nhip
105  *  A pointer to next hop ip address
106  */
107
108 static inline int gw_get_route_nh_port_ipv4(uint32_t dst_ip_addr,
109                          uint32_t *dst_port, uint32_t *nhip, uint32_t nport)
110 {
111         int i = 0;
112         uint32_t j = nport;
113
114         while(likely(i < p_route_data[j]->route_ent_cnt)) {
115              if (likely((p_route_data[j]->route_table[i].nh_mask) ==
116                         (dst_ip_addr &
117                          p_route_data[j]->route_table[i].mask))) {
118
119                   *dst_port = p_route_data[j]->route_table[i].port;
120                   *nhip =  p_route_data[j]->route_table[i].nh;
121
122 #ifdef ARPICMP_DEBUG
123                   lib_arp_nh_found++;
124 #endif
125                   return 1;
126              }
127              i++;
128         }
129
130        *nhip = 0;
131        *dst_port = 0xff;
132        return 0;
133 }
134
135
136 extern void gw_get_nh_port_ipv4(uint32_t dst_ip_addr,
137                                         uint32_t *dst_port, uint32_t *nhip);
138
139 extern void gw_get_nh_port_ipv6(uint8_t *dst_ipv6_addr,
140                                         uint32_t *dst_port, uint8_t *nhipv6);
141
142 #endif