REST_API: rest api client implementation
[samplevnf.git] / VNFs / vCGNAPT / pipeline / pipeline_cgnapt_common.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_PIPELINE_CGNAPT_COMMON_H__
18 #define __INCLUDE_PIPELINE_CGNAPT_COMMON_H__
19
20 #include "pipeline_common_fe.h"
21
22 extern uint8_t CGNAPT_DEBUG;
23
24 struct pipeline_cgnapt_entry_key {
25         uint32_t ip;
26         uint16_t port;          /* L4 port */
27         uint16_t pid;           /* if port id */
28 };
29
30 /*
31  * CGNAPY Entry
32  */
33 enum cgnapt_entry_type {
34         CGNAPT_ENTRY_IPV4,
35         CGNAPT_ENTRY_IPV6
36 };
37
38 #ifdef PCP_ENABLE
39 /**
40  * An enum defining the CG-NAPT entry creation type
41  */
42
43 enum {
44         STATIC_CGNAPT_ENTRY,
45         DYNAMIC_CGNAPT_ENTRY,
46         PCP_CGNAPT_ENTRY,
47 };
48 #endif
49
50 struct app_pipeline_cgnapt_entry_params {
51         enum cgnapt_entry_type type;
52         union {
53                 uint32_t prv_ip;        /* private ip address */
54                 uint8_t prv_ipv6[16];
55                 uint16_t u16_prv_ipv6[8];
56                 uint32_t u32_prv_ipv6[4];
57         } u;
58         uint32_t prv_ip;
59         uint16_t prv_port;      /* private port */
60         uint32_t pub_ip;        /* public ip address */
61         uint16_t pub_port;      /* public port */
62         uint16_t prv_phy_port;  /* physical port on private side */
63         uint16_t pub_phy_port;  /* physical port on public side */
64         uint32_t ttl;           /* time to live */
65         long long int timeout;
66         #ifdef PCP_ENABLE
67         struct rte_timer *timer;
68         #endif
69 };
70
71 /*
72  *CGNAPT table
73  */
74
75 struct cgnapt_table_entry {
76         struct rte_pipeline_table_entry head;
77         struct app_pipeline_cgnapt_entry_params data;
78 } __rte_cache_aligned;
79
80 /**
81  * A structure defining the CG-NAPT multiple entry parameter.
82  */
83 struct app_pipeline_cgnapt_mentry_params {
84         enum cgnapt_entry_type type;
85         union {
86                 uint32_t prv_ip;        /* private ip address */
87                 uint8_t prv_ipv6[16];
88                 uint16_t u16_prv_ipv6[8];
89                 uint32_t u32_prv_ipv6[4];
90         } u;
91         uint32_t prv_ip;        /* private ip address */
92         uint16_t prv_port;      /* private port start */
93         uint32_t pub_ip;        /* public ip address */
94         uint16_t pub_port;      /* public port start */
95         uint16_t prv_phy_port;  /* physical port on private side */
96         uint16_t pub_phy_port;  /* physical port on public side */
97         uint32_t ttl;           /* time to live */
98         uint32_t num_ue;        /* number of UEs to add */
99         uint16_t prv_port_max;  /* max value for private port */
100         uint16_t pub_port_max;  /* max value for public port */
101 };
102
103 /**
104  * A structure defining the NAT64 Network Specific Prefix.
105  */
106 struct pipeline_cgnapt_nsp_t {
107         uint8_t prefix[16];
108         uint8_t depth;
109 };
110
111
112 /*
113  * Messages
114  */
115 enum pipeline_cgnapt_msg_req_type {
116         PIPELINE_CGNAPT_MSG_REQ_ENTRY_ADD,
117         PIPELINE_CGNAPT_MSG_REQ_ENTRY_DEL,
118         /* to be used for periodic synchronization */
119         PIPELINE_CGNAPT_MSG_REQ_ENTRY_SYNC,
120         /* to be used for debug purposes */
121         PIPELINE_CGNAPT_MSG_REQ_ENTRY_DBG,
122         /* Multiple (bulk) add */
123         PIPELINE_CGNAPT_MSG_REQ_ENTRY_ADDM,
124         PIPELINE_CGNAPT_MSG_REQ_VER,
125         PIPELINE_CGNAPT_MSG_REQ_NSP_ADD,
126         PIPELINE_CGNAPT_MSG_REQ_NSP_DEL,
127         #ifdef PCP_ENABLE
128         PIPELINE_CGNAPT_MSG_REQ_PCP,
129         #endif
130         PIPELINE_CGNAPT_MSG_REQS
131 };
132
133 /**
134  * A structure defining MSG ENTRY ADD request.
135  */
136 struct pipeline_cgnapt_entry_add_msg_req {
137         enum pipeline_msg_req_type type;
138         enum pipeline_cgnapt_msg_req_type subtype;
139
140         /* key */
141         struct pipeline_cgnapt_entry_key key;
142
143         /* data */
144         struct app_pipeline_cgnapt_entry_params data;
145 };
146
147 /**
148  * A structure defining MSG ENTRY ADD response.
149  */
150 struct pipeline_cgnapt_entry_add_msg_rsp {
151         int status;
152         int key_found;
153         void *entry_ptr;
154 };
155
156 /**
157  * A structure defining MSG ENTRY MADD request.
158  */
159 struct pipeline_cgnapt_entry_addm_msg_req {
160         enum pipeline_msg_req_type type;
161         enum pipeline_cgnapt_msg_req_type subtype;
162
163         /* data */
164         struct app_pipeline_cgnapt_mentry_params data;
165 };
166
167 struct pipeline_cgnapt_entry_addm_msg_rsp {
168         int status;
169         int key_found;
170         void *entry_ptr;
171 };
172
173 /**
174  * A structure defining MSG ENTRY DELETE request.
175  */
176 struct pipeline_cgnapt_entry_delete_msg_req {
177         enum pipeline_msg_req_type type;
178         enum pipeline_cgnapt_msg_req_type subtype;
179
180         /* key */
181         struct pipeline_cgnapt_entry_key key;
182 };
183
184 /**
185  * A structure defining MSG ENTRY DELETE response.
186  */
187 struct pipeline_cgnapt_entry_delete_msg_rsp {
188         int status;
189         int key_found;
190 };
191
192 /*
193  * MSG ENTRY SYNC
194  */
195 struct pipeline_cgnapt_entry_sync_msg_req {
196         enum pipeline_msg_req_type type;
197         enum pipeline_cgnapt_msg_req_type subtype;
198
199         /* data */
200         struct app_pipeline_cgnapt_entry_params data;
201 };
202
203 struct pipeline_cgnapt_entry_sync_msg_rsp {
204         int status;
205         void *entry_ptr;
206 };
207
208 /**
209  * A structure defining the debug command response message.
210  */
211 struct pipeline_cgnapt_entry_dbg_msg_rsp {
212         int status;
213         void *entry_ptr;
214 };
215
216 /**
217  * A structure defining the NSP add request.
218  */
219 struct pipeline_cgnapt_nsp_add_msg_req {
220         enum pipeline_msg_req_type type;
221         enum pipeline_cgnapt_msg_req_type subtype;
222
223         /* Network Specific Prefix and prefix length */
224         struct pipeline_cgnapt_nsp_t nsp;
225 };
226
227 /**
228  * A structure defining the NSP add response.
229  */
230 struct pipeline_cgnapt_nsp_add_msg_rsp {
231         int status;
232         int key_found;
233 };
234
235 /**
236  * A structure defining MSG NSP DEL request
237  */
238 struct pipeline_cgnapt_nsp_del_msg_req {
239         enum pipeline_msg_req_type type;
240         enum pipeline_cgnapt_msg_req_type subtype;
241
242         /* Network Specific Prefix and prefix length */
243         struct pipeline_cgnapt_nsp_t nsp;
244
245 };
246
247 /**
248  * A structure defining MSG NSP DEL response
249  */
250 struct pipeline_cgnapt_nsp_del_msg_rsp {
251         int status;
252         int key_found;
253 };
254
255 /**
256  * A structure defining the debug command request message.
257  */
258 struct pipeline_cgnapt_entry_dbg_msg_req {
259         enum pipeline_msg_req_type type;
260         enum pipeline_cgnapt_msg_req_type subtype;
261
262         /* data */
263         uint8_t data[5];
264 };
265
266 extern struct pipeline_be_ops pipeline_cgnapt_be_ops;
267 void print_num_ip_clients(void);
268 void all_cgnapt_stats(char *);
269 void all_cgnapt_clear_stats(char *);
270 void print_static_cgnapt_entries(void);
271 #endif