6a14aae066551d8c740210d118e1b9aa09cf9708
[samplevnf.git] / VNFs / DPPD-PROX / task_init.h
1 /*
2 // Copyright (c) 2010-2020 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 _TASK_INIT_H_
18 #define _TASK_INIT_H_
19
20 #include <sys/queue.h>
21
22 #include <rte_common.h>
23 #include <rte_sched.h>
24 #include <rte_ether.h>
25 #include "prox_compat.h"
26 #include "task_base.h"
27 #include "prox_globals.h"
28 #include "ip6_addr.h"
29 #include "flow_iter.h"
30 #include "parse_utils.h"
31 #include "prox_compat.h"
32
33 struct rte_mbuf;
34 struct lcore_cfg;
35
36 #if MAX_RINGS_PER_TASK < PROX_MAX_PORTS
37 #error MAX_RINGS_PER_TASK < PROX_MAX_PORTS
38 #endif
39
40 #define TASK_ARG_DROP           0x01
41 #define TASK_ARG_RX_RING        0x02
42 #define TASK_ARG_RTE_TABLE      0x08
43 #define TASK_ARG_LOCAL_LPM      0x10
44 #define TASK_ARG_QINQ_ACL       0x20
45 #define TASK_ARG_CTRL_RINGS_P   0x40
46 #define TASK_ARG_DST_MAC_SET    0x80
47 #define TASK_ARG_SRC_MAC_SET    0x100
48 #define TASK_ARG_DO_NOT_SET_SRC_MAC 0x200
49 #define TASK_ARG_DO_NOT_SET_DST_MAC 0x400
50 #define TASK_ARG_HW_SRC_MAC     0x800
51 #define TASK_ARG_L3             0x1000
52 #define TASK_ARG_NDP            0x2000
53 #define TASK_ARG_SEND_NA_AT_STARTUP             0x4000
54
55 #define PROX_MODE_LEN   32
56
57 enum protocols {IPV4, ARP, IPV6};
58
59 struct qos_cfg {
60         struct rte_sched_port_params port_params;
61         struct rte_sched_subport_params subport_params[1];
62         struct rte_sched_pipe_params pipe_params[1];
63 };
64
65 enum task_mode {NOT_SET, MASTER, QINQ_DECAP4, QINQ_DECAP6,
66                 QINQ_ENCAP4, QINQ_ENCAP6, GRE_DECAP, GRE_ENCAP,CGNAT, ESP_ENC, ESP_DEC, QOS, POLICE
67 };
68
69 struct task_args;
70
71 struct task_init {
72         enum task_mode mode;
73         char mode_str[PROX_MODE_LEN];
74         char sub_mode_str[PROX_MODE_LEN];
75         void (*early_init)(struct task_args *targ);
76         void (*init)(struct task_base *tbase, struct task_args *targ);
77         int (*handle)(struct task_base *tbase, struct rte_mbuf **mbufs, const uint16_t n_pkts);
78         void (*start)(struct task_base *tbase);
79         void (*stop)(struct task_base *tbase);
80         void (*start_first)(struct task_base *tbase);
81         void (*stop_last)(struct task_base *tbase);
82         int (*thread_x)(struct lcore_cfg* lconf);
83         struct flow_iter flow_iter;
84         size_t size;
85         uint16_t     flag_req_data; /* flags from prox_shared.h */
86         uint64_t     flag_features;
87         LIST_ENTRY(task_init) entries;
88 };
89
90 static int task_init_flag_set(struct task_init *task_init, uint64_t flag)
91 {
92         return !!(task_init->flag_features & flag);
93 }
94
95 enum police_action {
96         ACT_GREEN = RTE_COLOR_GREEN,
97         ACT_YELLOW = RTE_COLOR_YELLOW,
98         ACT_RED = RTE_COLOR_RED,
99         ACT_DROP = 3,
100         ACT_INVALID = 4
101 };
102
103 struct range {
104         uint32_t min;
105         uint32_t value;
106         uint32_t max;
107         uint32_t offset;
108         uint8_t range_len;
109 };
110
111 /* Configuration for task that is only used during startup. */
112 struct task_args {
113         struct task_base       *tbase;
114         struct task_init*       task_init;
115         struct rte_mempool     *pool;
116         char                   pool_name[MAX_NAME_SIZE];
117         struct lcore_cfg       *lconf;
118         uint32_t               nb_mbuf;
119         uint32_t               mbuf_size;
120         uint32_t               nb_cache_mbuf;
121         uint8_t                nb_slave_threads;
122         uint8_t                nb_worker_threads;
123         uint8_t                worker_thread_id;
124         uint8_t                task;
125         uint32_t               id;
126         struct core_task_set   core_task_set[MAX_PROTOCOLS];
127         struct task_args       *prev_tasks[MAX_RINGS_PER_TASK];
128         uint32_t               n_prev_tasks;
129         uint32_t               ring_size; /* default is RX_RING_SIZE */
130         struct qos_cfg         qos_conf;
131         uint32_t               flags;
132         uint32_t               runtime_flags;
133         uint8_t                nb_txports;
134         uint8_t                nb_txrings;
135         uint8_t                nb_rxrings;
136         uint8_t                tot_rxrings;
137         uint8_t                nb_rxports;
138         uint32_t               byte_offset;
139         uint32_t               ipv6_router;
140         uint32_t               gateway_ipv4;
141         uint32_t               local_ipv4;
142         uint32_t               remote_ipv4;
143         uint32_t               local_prefix;
144         uint32_t               reachable_timeout;
145         uint32_t               arp_ndp_retransmit_timeout;
146         struct ipv6_addr       local_ipv6;    /* For IPv6 Tunnel, it's the local tunnel endpoint address */
147         struct ipv6_addr       global_ipv6;
148         struct ipv6_addr       gateway_ipv6;
149         struct ipv6_addr       router_prefix;
150         struct rte_ring        *rx_rings[MAX_RINGS_PER_TASK];
151         struct rte_ring        *tx_rings[MAX_RINGS_PER_TASK];
152         struct rte_ring        *ctrl_plane_ring;
153         uint32_t               tot_n_txrings_inited;
154         prox_rte_ether_addr      edaddr;
155         prox_rte_ether_addr      esaddr;
156         struct port_queue      tx_port_queue[PROX_MAX_PORTS];
157         struct port_queue      rx_port_queue[PROX_MAX_PORTS];
158         /* Used to set up actual task at initialization time. */
159         enum task_mode         mode;
160         /* Destination output position in hw or sw when using mac learned dest port. */
161         uint8_t                mapping[PROX_MAX_PORTS];
162         struct rte_table_hash  *cpe_table;
163         struct rte_table_hash  *qinq_gre_table;
164         struct rte_hash        *cpe_gre_hash;
165         struct rte_hash        *qinq_gre_hash;
166         struct cpe_data        *cpe_data;
167         struct cpe_gre_data    *cpe_gre_data;
168         struct qinq_gre_data   *qinq_gre_data;
169         uint8_t                tx_opt_ring;
170         struct task_args       *tx_opt_ring_task;
171         uint32_t               qinq_tag;
172
173 #ifdef ENABLE_EXTRA_USER_STATISTICS
174         uint32_t               n_users; // Number of users in user table.
175 #endif
176         uint32_t               n_flows; // Number of flows used in policing
177         uint32_t               cir;
178         uint32_t               cbs;
179         uint32_t               ebs;
180         uint32_t               pir;
181         uint32_t               pbs;
182         uint32_t               overhead;
183         enum police_action     police_act[3][3];
184         uint32_t               marking[4];
185         uint32_t               n_max_rules;
186         uint32_t               random_delay_us;
187         uint32_t               delay_us;
188         uint32_t               cpe_table_timeout_ms;
189         uint32_t               etype;
190 #ifdef GRE_TP
191         uint32_t tb_rate;                /**< Pipe token bucket rate (measured in bytes per second) */
192         uint32_t tb_size;                /**< Pipe token bucket size (measured in credits) */
193 #endif
194         uint8_t                tunnel_hop_limit;  /* IPv6 Tunnel - Hop limit */
195         uint16_t               lookup_port_mask;  /* Ipv6 Tunnel - Mask applied to UDP/TCP port before lookup */
196         uint32_t               ctrl_freq;
197         uint8_t                lb_friend_core;
198         uint8_t                lb_friend_task;
199         /* gen related*/
200         uint64_t               rate_bps;
201         uint32_t               n_rand_str;
202         uint32_t               n_ranges;
203         uint32_t               rand_offset[64];
204         char                   rand_str[64][64];
205         struct range           range[64];
206         char                   pcap_file[256];
207         uint32_t               accur_pos;
208         uint32_t               sig_pos;
209         uint32_t               sig;
210         uint32_t               lat_pos;
211         uint32_t               packet_id_pos;
212         uint32_t               latency_buffer_size;
213         uint32_t               bucket_size;
214         uint32_t               lat_enabled;
215         uint32_t               pkt_size;
216         uint8_t                pkt_inline[MAX_PKT_SIZE];
217         uint32_t               probability_no_drop;
218         uint32_t               probability_duplicate;
219         uint32_t               probability_delay;
220         char                   nat_table[256];
221         uint32_t               use_src;
222         char                   route_table[256];
223         char                   rules[256];
224         char                   dscp[256];
225         char                   tun_bindings[256];
226         char                   cpe_table_name[256];
227         char                   user_table[256];
228         uint32_t               n_concur_conn;
229         char                   streams[256];
230         uint32_t               min_bulk_size;
231         uint32_t               max_bulk_size;
232         uint32_t               max_setup_rate;
233         uint32_t               n_pkts;
234         uint32_t               loop;
235         uint32_t               flow_table_size;
236         char                   dpi_engine_path[256];
237         char                   dpi_engine_args[16][256];
238         uint32_t               n_dpi_engine_args;
239         uint32_t               generator_id;
240         uint32_t               accuracy_limit_nsec;
241         /* cgnat related */
242         uint32_t                     public_ip_count;
243         struct public_ip_config_info *public_ip_config_info;
244         struct public_entry          *public_entries;
245         struct private_flow_entry    *private_flow_entries;
246         struct rte_hash              *public_ip_port_hash;
247         struct rte_hash              *private_ip_port_hash;
248         struct rte_hash              *private_ip_hash;
249         struct private_ip_info       *private_ip_info;
250         struct rte_ring                 **ctrl_rx_rings;
251         struct rte_ring                 **ctrl_tx_rings;
252         int                             n_ctrl_rings;
253         uint                            irq_debug;
254         struct task_base *tmaster;
255         char sub_mode_str[PROX_MODE_LEN];
256         uint32_t               igmp_address;
257         uint32_t                imix_nb_pkts;
258         uint32_t                imix_pkt_sizes[MAX_IMIX_PKTS];
259         uint32_t        multiplier;
260         uint32_t        mirror_size;
261 };
262
263 /* Return the first port that is reachable through the task. If the
264    task itself does not send directly to a port, the function will
265    search reachable tasks through each outgoing ring */
266 struct task_args *find_reachable_task_sending_to_port(struct task_args *from);
267 struct prox_port_cfg *find_reachable_port(struct task_args *from);
268
269 struct task_base *init_task_struct(struct task_args *targ);
270 struct task_init *to_task_init(const char *mode_str, const char *sub_mode_str);
271 void tasks_list(void);
272 int task_is_master(struct task_args *targ);
273
274 void reg_task(struct task_init* t);
275
276 #endif /* _TASK_INIT_H_ */