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