Merge "VNF_Catalogue Codebase"
[samplevnf.git] / VNFs / vFW / pipeline / pipeline_vfw_be.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_VFW_BE_H__
18 #define __INCLUDE_PIPELINE_VFW_BE_H__
19
20 /**
21  * @file
22  * Pipeline VFW BE.
23  *
24  * Pipeline VFW Back End (BE).
25  * Responsible for packet processing.
26  *
27  */
28 #include <stdint.h>
29 #include <rte_ether.h>
30
31 #include "pipeline_common_be.h"
32 #include "rte_cnxn_tracking.h"
33 #include "rte_ct_tcp.h"
34 #include "lib_acl.h"
35
36 /*#define VFW_DEBUG 0*/
37 uint8_t vfw_debug;
38 extern uint8_t VFW_DEBUG;
39 extern uint8_t firewall_flag;
40 extern uint8_t cnxn_tracking_is_active;
41 #define KEY_SIZE 10              /*IPV4 src_ip + dst_ip + src_port + dst_port */
42 #define IP_32BIT_SIZE 4
43 #define MAX_VFW_INSTANCES 24       /* max number fw threads, actual usually less */
44 #define IPv4_HDR_VERSION 4
45 #define IPv6_HDR_VERSION 6
46 #define IP_VERSION_CHECK 4
47 extern int rte_VFW_hi_counter_block_in_use;
48
49 enum pipeline_vfw_key_type {
50        PIPELINE_VFW_IPV4_5TUPLE,
51        PIPELINE_VFW_IPV6_5TUPLE
52 };
53  /**
54  * A structure defining the VFW counter block.
55  * One counter block per VFW Thread
56  */
57 struct rte_VFW_counter_block {
58        char name[PIPELINE_NAME_SIZE];
59
60        /* as long as a counter doesn't cross cache line, writes are atomic */
61        uint64_t pkts_received;
62        uint64_t bytes_processed; /**< includes all L3 and higher headers. */
63        uint64_t num_batch_pkts_sum;
64        uint32_t num_pkts_measurements;
65        uint32_t unused_counter;
66
67        uint64_t entry_timestamp;
68        uint64_t exit_timestamp;
69        uint64_t internal_time_sum;
70        uint64_t external_time_sum;
71        uint32_t time_measurements;
72        uint32_t count_latencies;
73        /**< Sum latencies */
74        uint64_t sum_latencies;
75        uint64_t pkts_drop_without_rule;
76        uint64_t pkts_acl_forwarded;
77
78        /**< Total packets drop for ttl value by firewall.*/
79        uint64_t pkts_drop_ttl;
80        /**< Total packets drop for bad size by firewall. */
81        uint64_t pkts_drop_bad_size;
82        /**< Total packets drop for fragmented by firewall. */
83        uint64_t pkts_drop_fragmented;
84        /**< Total packets drop for without arp entry by firewall.*/
85        uint64_t pkts_drop_without_arp_entry;
86        /**< Total packets drop for ipv6 not tcp/udp by firewall. */
87        uint64_t pkts_drop_unsupported_type;
88        /**< A pointer to connection tracker counters.*/
89        struct rte_CT_counter_block *ct_counters;
90        /* average latency = sum_latencies / count_latencies */
91        uint64_t pkts_fw_forwarded;
92        uint64_t arpicmpPktCount;
93 } __rte_cache_aligned;
94
95 /** The counter table for VFW pipeline per thread data.*/
96 extern struct rte_VFW_counter_block
97 rte_vfw_counter_table[MAX_VFW_INSTANCES] __rte_cache_aligned;
98
99 /**
100  * A structure defining the IPv4 5-Tuple for VFW rules.
101  */
102 struct pipeline_vfw_key_ipv4_5tuple {
103        uint32_t src_ip;
104        uint32_t src_ip_mask;
105        uint32_t dst_ip;
106        uint32_t dst_ip_mask;
107        uint16_t src_port_from;
108        uint16_t src_port_to;
109        uint16_t dst_port_from;
110        uint16_t dst_port_to;
111        uint8_t proto;
112        uint8_t proto_mask;
113 };
114
115 /**
116  * A structure defining the IPv6 5-Tuple for VFW rules.
117  */
118 struct pipeline_vfw_key_ipv6_5tuple {
119        uint8_t src_ip[16];
120        uint32_t src_ip_mask;
121        uint8_t dst_ip[16];
122        uint32_t dst_ip_mask;
123        uint16_t src_port_from;
124        uint16_t src_port_to;
125        uint16_t dst_port_from;
126        uint16_t dst_port_to;
127        uint8_t proto;
128        uint8_t proto_mask;
129 };
130
131 /* Messages from CLI for processing by packet processing */
132
133 enum pipeline_tcpfw_msg_req_type {
134
135        PIPELINE_TCPFW_MSG_REQ_ENTRY_STATUS,
136        PIPELINE_TCPFW_MSG_REQ_DBG,
137        PIPELINE_TCPFW_MSG_REQ_SYNPROXY_FLAGS,
138        PIPELINE_TCPFW_MSG_REQS
139 };
140 /**
141  * A structure defining the key to store VFW rule.
142  * For both IPv4 and IPv6.
143  */
144 struct pipeline_vfw_key {
145        enum pipeline_vfw_key_type type;
146        union {
147               struct pipeline_vfw_key_ipv4_5tuple ipv4_5tuple;
148               struct pipeline_vfw_key_ipv6_5tuple ipv6_5tuple;
149        } key;
150 };
151
152
153
154 extern struct pipeline_action_key *action_array_a;
155 extern struct pipeline_action_key *action_array_b;
156 extern struct pipeline_action_key *action_array_active;
157 extern struct pipeline_action_key *action_array_standby;
158 extern uint32_t action_array_size;
159
160 extern struct action_counter_block
161 action_counter_table[MAX_VFW_INSTANCES][action_array_max]
162 __rte_cache_aligned;
163
164 /**
165  * A structure defining the add VFW rule command response message.
166  */
167 struct pipeline_vfw_add_msg_rsp {
168        int status;
169        int key_found;
170        void *entry_ptr;
171 };
172
173 struct app_pipeline_vfw_entry_params {
174        uint32_t s_addr;
175        uint16_t s_port;
176        uint32_t d_addr;
177        uint16_t d_port;
178
179 };
180
181 struct pipeline_vfw_entry_key {
182        uint32_t ip1[IP_32BIT_SIZE];
183        uint32_t ip2[IP_32BIT_SIZE];
184        uint16_t port1;
185        uint16_t port2;
186 };
187
188 /* Messages from CLI for processing by packet processing */
189
190 enum pipeline_vfw_msg_req_type {
191        PIPELINE_VFW_MSG_REQ_SYNPROXY_FLAGS,
192        PIPELINE_VFW_MSG_REQS
193 };
194
195 /*
196  * A structure defining the synproxy ON/OFF command request message.
197  */
198 struct pipeline_vfw_synproxy_flag_msg_req {
199        enum pipeline_msg_req_type type;
200        enum pipeline_vfw_msg_req_type subtype;
201
202        /* data */
203        uint8_t synproxy_flag;
204 };
205
206 /**
207  * A structure defining the synproxy ON/OFF command response message.
208  */
209 struct pipeline_vfw_synproxy_flag_msg_rsp {
210        int status;
211        void *entry_ptr;
212 };
213 extern struct pipeline_be_ops pipeline_vfw_be_ops;
214
215 extern int rte_ct_initialize_default_timeouts(struct rte_ct_cnxn_tracker
216                                          *new_cnxn_tracker);
217
218 #endif