Initial commit of vpp code.
[vpp.git] / vnet / vnet / vcgn / dslite_defs.h
1 /* 
2  *------------------------------------------------------------------
3  * dslite_defs.h - DSLITE structure definiitions
4  *
5  * Copyright (c) 2011-2012 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19
20 #ifndef __DSLITE_DEFS_H__
21 #define __DSLITE_DEFS_H__
22
23 #ifdef TOBE_PORTED
24 #include "spp_platform_common.h"
25 #include "cgse_defs.h"
26 #endif
27 #include "cnat_cli.h"
28 #include "cnat_config.h"
29 #include "cnat_ports.h"
30 #include "cnat_bulk_port_defs.h"
31
32 extern u32 ds_lite_config_debug_level;
33
34 #define SWAP_IPV6_ADDR(ipv6_hdr, dslite_entry_ptr) \
35     ipv6_hdr->dst_addr[0] = ipv6_hdr->src_addr[0]; \
36     ipv6_hdr->dst_addr[1] = ipv6_hdr->src_addr[1]; \
37     ipv6_hdr->dst_addr[2] = ipv6_hdr->src_addr[2]; \
38     ipv6_hdr->dst_addr[3] = ipv6_hdr->src_addr[3]; \
39     ipv6_hdr->src_addr[0] = spp_host_to_net_byte_order_32(dslite_entry_ptr->AFTR_v6_address[0]); \
40     ipv6_hdr->src_addr[1] = spp_host_to_net_byte_order_32(dslite_entry_ptr->AFTR_v6_address[1]); \
41     ipv6_hdr->src_addr[2] = spp_host_to_net_byte_order_32(dslite_entry_ptr->AFTR_v6_address[2]); \
42     ipv6_hdr->src_addr[3] = spp_host_to_net_byte_order_32(dslite_entry_ptr->AFTR_v6_address[3]); 
43
44 #define DSLITE_SET_TX_PKT_TYPE(type)            {               \
45     ctx->ru.tx.packet_type = type;                            \
46 }
47
48 #define DSLITE_INC_STATS_V4(PTR, COUNTER, IPV4_SRC_ADDR) {            \
49     PTR->COUNTER++; \
50
51
52 #define DSLITE_INC_STATS_V6(PTR, COUNTER, IPV6_DEST_ADDR) {           \
53     PTR->COUNTER++;                                                 \
54 }
55
56
57 #define DSLITE_INVALID_UIDX 0xffff /*invalid svi app uidb index */
58 #define DSLITE_INVALID_VRFID 0xffffffff /*invalid vrf id */
59
60 #define DSLITE_VRF_MASK 0x3fff
61 #define DSLITE_MAX_VRFMAP_ENTRIES  (DSLITE_VRF_MASK + 1)
62
63 #define DSLITE_VRFMAP_ENTRY_INVALID 0xffff
64
65 #define DSLITE_V6_PREFIX_MASK_MIN       16 
66 #define DSLITE_V6_PREFIX_MASK_MAX       96 
67 #define DSLITE_V6_PREFIX_MASK_MULTIPLE  8
68
69 #define DSLITE_TUNNEL_MTU_MIN 1280
70 #define DSLITE_TUNNEL_MTU_MAX 9216 
71
72 #define DSLITE_TUNNEL_TTL_MIN 0
73 #define DSLITE_TUNNEL_TTL_MAX 255
74
75 #define DSLITE_TUNNEL_TOS_MIN 0
76 #define DSLITE_TUNNEL_TOS_MAX 255 
77
78 #define DSLITE_V4_MASK_MAX       32
79
80 //#define XLAT_MAX_FRAG_ID_COUNTERS (256)
81 #define DSLITE_AFTR_IPV4_ADDR 0xC0000001
82
83 #define DSLITE_MAX_TAP_RG_ENTRIES 2
84 #define DSLITE_MAX_DSLITE_ENTRIES (256)
85 #define DSLITE_MAX_DSLITE_ID      (DSLITE_MAX_DSLITE_ENTRIES-1)
86 /* Define the below value as 64 if first 64 entries are for NAT44 */
87 #define DSLITE_INDEX_OFFSET        1 
88
89 #define DSLITE_INVALID_DSLITE_ID  (0)
90
91 #define DSLITE_TABLE_ENTRY_DELETED 0
92 #define DSLITE_TABLE_ENTRY_ACTIVE  1
93 #define DSLITE_TABLE_ENTRY_DORMANT 2
94 #define DSLITE_TABLE_ENTRY_INVALID_UIDB 3
95
96 typedef struct  {
97     u16 tcp_initial_setup_timeout;
98     u16 tcp_active_timeout;
99     u16 udp_init_session_timeout;
100     u16 udp_act_session_timeout;
101     u16 icmp_session_timeout;
102     u16 temp;
103 } dslite_timeout_info_t;
104
105
106 typedef struct {
107
108     u16 state;     /* To use nat44 enums ?? TBD */
109     u16 dslite_id;   /* DSLITE_ID value for this table entry - for easy access */
110
111     u16 i_vrf;     /* V6 uidb index */
112     u16 o_vrf;     /* V4 uidb index */
113
114     u16 cnat_main_db_max_ports_per_user; /* port limit */
115     u16 tcp_mss;   /*tcp max segment size for this inside vrf */
116
117     u32 delete_time;
118
119     cnat_portmap_v2_t *portmap_list;
120
121     u32 nfv9_logging_index;
122     u32 syslog_logging_index; 
123     u32 AFTR_v6_address[4];
124
125 #define DSLITE_IPV4_TOS_OVERRIDE_FLAG 0x00000001
126 #define DSLITE_IPV6_TOS_OVERRIDE_FLAG 0x00000002
127 #define DSLITE_IPV4_TTL_OVERRIDE_FLAG 0x00000004
128 #define DSLITE_IPV6_TTL_OVERRIDE_FLAG 0x00000008
129 #define DSLITE_IPV6_FRAG_REASSEMB_ENG 0x00000010
130 #define DSLITE_FTP_ALG_ENABLE         0x00000020 
131 #define DSLITE_RTSP_ALG_ENABLE        0x00000040
132 #define DSLITE_NETFLOW_ENABLE 0x00000080
133 #define DSLITE_SYSLOG_ENABLE  0x00000100
134
135     u16  feature_flags;
136     u16  tunnel_mtu;
137
138     u8  ipv4_ttl_value;
139     u8  ipv6_ttl_value;
140     u8  ipv4_tos_value;
141     u8  ipv6_tos_value;
142
143     u32 v4_if_num;  /* V4 SVI ifnum */
144     u32 v6_if_num;  /* V6 SVI ifnum */
145     u32 i_vrf_id;  //inside vrf id
146     u32 o_vrf_id;  //outside vrf id
147  
148     dslite_timeout_info_t timeout_info;
149     u16 cnat_static_port_range;
150     u16 dyn_start_port; 
151
152     u32 AFTR_v4_addr;    
153     bulk_alloc_size_t bulk_size;  /* should be equivalent to u16 - 2 bytes */
154     u32 pcp_server_addr;
155     u16 pcp_server_port;
156     u8 mapping_refresh_both_direction;
157     u8 pad;
158     u16 rtsp_port;
159 #define DSLITE_BIDIR_REFRESH   1
160     u8 dslite_enable;  /* DS-Lite enable check flag */
161     u8 syslog_logging_policy;  /* DS-Lite Session Logging check flag */
162     u8 nf_logging_policy;
163
164     u8 temp1;
165     u16 temp2;
166     u32 temp3;
167     u32 rseed_ip;
168 } dslite_table_entry_t;
169
170 typedef struct {
171     u64 v4_to_v6_invalid_uidb_drop_count;
172     u64 v6_to_v4_invalid_uidb_drop_count;
173     u64 v4_to_v6_frag_invalid_uidb_drop_count;
174 } dslite_global_counters_t;
175
176 typedef struct {
177     u32 tap_enable; 
178     u32 ipv4_addr;
179     u32 ipv6_addr[4];
180 } dslite_tap_rg_t;
181
182 extern dslite_table_entry_t  *dslite_table_db_ptr;
183
184
185 #define DSLITE_ADD_UIDB_INDEX_DSLITE_ID_MAPPING(uidb_index, dslite_id) \
186     *(cgse_uidb_index_cgse_id_mapping_ptr + uidb_index) = dslite_id;
187
188 extern u8 my_instance_number;
189
190 extern void dslite_clear_counters(u16 dslite_id);
191 extern void dslite_clear_per_RG_counters();
192 extern dslite_global_counters_t dslite_global_counters;
193 extern u32 dslite_config_debug_level;
194 extern u32 dslite_data_path_debug_level;
195 extern u32 dslite_defrag_debug_level;
196 extern u32 dslite_debug_level;
197
198 typedef struct {
199     u64 v6_to_v4_tcp_input_count;
200     u64 v6_to_v4_tcp_nat_error;
201     u64 v6_to_v4_tcp_output_count;
202 } dslite_v6_to_v4_tcp_counter_t;
203
204 typedef struct {
205     u64 v4_to_v6_tcp_input_count;
206     u64 v4_to_v6_tcp_no_entry;
207     u64 v4_to_v6_tcp_output_count;
208 } dslite_v4_to_v6_tcp_counter_t;
209
210 typedef struct {
211     u64 v6_to_v4_udp_input_count;
212     u64 v6_to_v4_udp_nat_error;
213     u64 v6_to_v4_udp_output_count;
214 } dslite_v6_to_v4_udp_counter_t;
215
216 typedef struct {
217     u64 v4_to_v6_udp_input_count;
218     u64 v4_to_v6_udp_no_entry;
219     u64 v4_to_v6_udp_output_count;
220 } dslite_v4_to_v6_udp_counter_t;
221
222 typedef struct {
223     u64 v6_to_v4_icmp_qry_input_count;
224     u64 v6_to_v4_icmp_qry_nat_error;
225     u64 v6_to_v4_icmp_qry_output_count;
226 } dslite_v6_to_v4_icmp_qry_counter_t;
227
228 typedef struct {
229     u64 v4_to_v6_icmp_qry_input_count;
230     u64 v4_to_v6_icmp_qry_no_nat_entry;
231     u64 v4_to_v6_icmp_qry_output_count;
232 } dslite_v4_to_v6_icmp_qry_counter_t;
233
234 typedef struct {
235     u64 v6_to_v4_icmp_error_input_count;
236     u64 v6_to_v4_icmp_error_nat_error;
237     u64 v6_to_v4_icmp_error_output_count;
238 } dslite_v6_to_v4_icmp_error_counter_t;
239
240 typedef struct {
241     u64 v4_to_v6_icmp_error_input_count;
242     u64 v4_to_v6_icmp_error_no_nat_entry;
243     u64 v4_to_v6_icmp_error_output_count;
244 } dslite_v4_to_v6_icmp_error_counter_t;
245
246 typedef struct {
247     u64 v6_icmp_error_input_count;
248     u64 v6_AFTR_echo_reply_count;
249     u64 v6_to_v4_icmp_error_unsupported_type_drop_count;
250     u64 v6_to_v4_icmp_error_no_db_entry_count;
251     u64 v6_to_v4_icmp_err_throttled_count;
252     u64 v6_to_v4_icmp_error_xlated_count;
253 } dslite_v6_icmp_error_counter_t;
254
255 typedef struct {
256     u64 v4_to_v6_ttl_gen_count;
257     u64 v4_to_v6_icmp_throttle_count;
258     u64 v4_to_v6_ptb_gen_count;
259     u64 v4_to_v6_aftr_v4_echo_reply_count;
260     u64 v6_to_v4_ttl_gen_count;
261     u64 v6_to_v4_icmp_throttle_count;
262     u64 v6_to_v4_admin_prohib_icmp_count;
263     u64 v6_to_v4_aftr_v4_echo_reply_count;
264     u64 v6_icmp_gen_count;
265 } dslite_icmp_gen_counter_t;
266
267 typedef struct {
268     u64 dslite_input_tunnel_pkt;
269     u64 dslite_encap_count;
270     u64 dslite_decap_count;
271     u64 dslite_sec_check_failed;
272     u64 dslite_unsupp_packet;
273 } dslite_common_counter_t;
274
275 typedef struct {
276
277     dslite_v6_to_v4_tcp_counter_t  v64_tcp_counters;
278     dslite_v4_to_v6_tcp_counter_t  v46_tcp_counters;
279     dslite_v6_to_v4_udp_counter_t  v64_udp_counters;
280     dslite_v4_to_v6_udp_counter_t  v46_udp_counters;
281     dslite_v6_to_v4_icmp_qry_counter_t v64_icmp_counters;
282     dslite_v4_to_v6_icmp_qry_counter_t v46_icmp_counters;
283     dslite_v6_to_v4_icmp_error_counter_t  v64_icmp_error_counters;
284     dslite_v4_to_v6_icmp_error_counter_t v46_icmp_error_counters;
285     dslite_v6_icmp_error_counter_t  dslite_v6_icmp_err_counters;
286     dslite_icmp_gen_counter_t       dslite_icmp_gen_counters;
287     dslite_common_counter_t         dslite_common_counters;
288 } dslite_counters_t;
289
290 typedef struct {
291     u32 active_translations;
292     u32 translation_create_rate;
293     u32 translation_delete_rate;
294     u32 in2out_forwarding_rate;
295     u32 out2in_forwarding_rate;
296     u32 in2out_drops_port_limit_exceeded;
297     u32 in2out_drops_system_limit_reached;
298     u32 in2out_drops_resource_depletion;
299     u32 no_translation_entry_drops;
300     u32 pool_address_totally_free;
301     u32 num_subscribers;
302     u32 dummy;
303     u64 drops_sessiondb_limit_exceeded;
304 } dslite_common_stats_t;
305
306 typedef struct {
307     u16 msg_id;
308     u8 rc;
309     u8 pad[5];
310     dslite_counters_t  counters;
311 } dslite_show_statistics_summary_resp;
312
313
314 #define CMD_GENERATE_PTB 0x1
315 #define CMD_GENERATE_TTL 0x2
316
317 /*
318  * This structure is to provide abstraction for data exchanged from one
319  * VPP node to its disposition or further in the dslite node graph.
320  */
321 typedef struct {
322     u32 icmp_gen_type; // ctx->feature_data[0]
323     u32 reserved1;     // ctx->feature_data[1]
324     u32 reserved2;     // ctx->feature_data[2]
325     u32 reserved3;     // ctx->feature_data[3]
326 } dslite_feature_data_t;
327
328 extern dslite_counters_t    dslite_all_counters[DSLITE_MAX_DSLITE_ENTRIES];
329 //extern dslite_inst_gen_counter_t       dslite_inst_gen_counters[DSLITE_MAX_DSLITE_ENTRIES];
330
331
332   extern void dslite_show_config(void);
333 #define STAT_PORT_RANGE_FROM_INST_PTR(inst) ((inst)->cnat_static_port_range)
334
335 #endif /* __DSLITE_DEFS_H__ */
336