conntrack: timer reset in reply traffic causes performance impact
[samplevnf.git] / common / VIL / pipeline_loadb / pipeline_loadb_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_LOADB_BE_H__
18 #define __INCLUDE_PIPELINE_LOADB_BE_H__
19
20 #include <rte_ip.h>
21 #include "pipeline_common_be.h"
22 #include <app.h>
23
24 #define MBUF_HDR_ROOM 256
25 #define ETH_HDR_SIZE  14
26 #define IP_HDR_SRC_ADR_OFST 12
27 #define IP_HDR_DST_ADR_OFST 16
28 #define IP_HDR_PROTOCOL_OFST 9
29 #define IP_HDR_SIZE  20
30 #define IPV6_HDR_SRC_ADR_OFST 8
31 #define IPV6_HDR_DST_ADR_OFST 24
32 #define IPV6_HDR_PROTOCOL_OFST 6
33 #define IPV6_HDR_SIZE  40
34 #define IP_PROTOCOL_TCP 6
35 #define IP_PROTOCOL_UDP 17
36 #define PIPELINE_LOADB_KEY_MAX_SIZE  64
37
38 #define LOADB_ING_DIR 0
39 #define LOADB_EGR_DIR 1
40
41 #define LOADB_DBG_CMD_OFST 8
42 #define LOADB_DBG_CMD_STATS_SHOW 0
43 #define LOADB_DBG_CMD_STATS_CLEAR 1
44 #define LOADB_DBG_CMD_DBG_LEVEL 2
45 #define LOADB_DBG_CMD_DBG_SHOW 3
46 #define LOADB_DBG_CMD_IF_STATS 4
47 #define LOADB_DBG_CMD_OFST1 10
48
49 #define PIPELINE_LOADB_KEY_PORT_IN_AH(f_ah, f_pkt_work, f_pkt4_work)    \
50 static int                                                              \
51 f_ah(                                                                   \
52         __rte_unused struct rte_pipeline *rte_p,                        \
53         struct rte_mbuf **pkts,                                         \
54         uint32_t n_pkts,                                                \
55         void *arg)                                                      \
56 {                                                                       \
57         uint32_t i, j;                                                  \
58                                                                         \
59         for (j = 0; j < n_pkts; j++)                                    \
60                 rte_prefetch0(pkts[j]);                                 \
61         pkt_burst_cnt = 0;                                              \
62         for (i = 0; i < (n_pkts & (~0x3LLU)); i += 4)                   \
63                 f_pkt4_work(&pkts[i], i, arg);                          \
64                                                                         \
65         for ( ; i < n_pkts; i++)                                        \
66                 f_pkt_work(pkts[i], i, arg);                            \
67                                                                         \
68                                                                         \
69         return 0;                                                       \
70 }
71
72 extern uint8_t LOADB_DEBUG;
73 extern uint8_t in_port_egress_prv[PIPELINE_MAX_PORT_IN];
74 extern uint8_t prv_que_port_index[PIPELINE_MAX_PORT_IN];
75 extern uint8_t in_port_dir_a[PIPELINE_MAX_PORT_IN];
76
77 extern uint8_t get_in_port_dir(uint8_t);
78 extern uint8_t is_port_index_privte(uint16_t);
79 extern uint8_t is_phy_port_privte(uint16_t);
80 extern uint32_t get_prv_to_pub_port(uint32_t *ip_addr, uint8_t type);
81 extern uint32_t get_pub_to_prv_port(uint32_t *ip_addr, uint8_t type);
82 extern uint8_t prv_to_pub_map[PIPELINE_MAX_PORT_IN];
83 //extern struct app_params *myApp;
84 //extern struct pipeline_arpicmp *p_arp;
85
86 /*
87  * LOADB Entry
88  */
89
90 struct pipeline_loadb_in_port_h_arg {
91         struct pipeline_loadb *p;
92         uint8_t in_port_id;
93 };
94
95 /*
96  * Messages
97  */
98 enum pipeline_loadb_msg_req_type {
99         /* to be used for debug purposes */
100         PIPELINE_LOADB_MSG_REQ_ENTRY_DBG,
101         PIPELINE_LOADB_MSG_REQS
102 };
103
104 /*
105  * MSG ENTRY DBG
106  */
107 struct pipeline_loadb_entry_dbg_msg_req {
108         enum pipeline_msg_req_type type;
109         enum pipeline_loadb_msg_req_type subtype;
110
111         /* data */
112         uint8_t data[5];
113 };
114
115 struct pipeline_loadb_entry_dbg_msg_rsp {
116         int status;
117         void *entry_ptr;
118 };
119
120 extern struct pipeline_be_ops pipeline_loadb_be_ops;
121 struct ipv4_hdr_port {
122         struct ipv4_hdr ipv4;
123         uint16_t src_port;
124         uint16_t dst_port;
125
126 } __attribute__((__packed__));
127 struct ipv6_hdr_port {
128         struct ipv6_hdr ipv6;
129         uint16_t src_port;
130         uint16_t dst_port;
131
132 } __attribute__((__packed__));
133
134 struct lb_pkt {
135         struct ether_hdr eth;
136         union{
137                 struct ipv4_hdr_port ipv4_port;
138                 struct ipv6_hdr_port ipv6_port;
139         };
140 } __attribute__((__packed__));
141
142 uint8_t calculate_lb_thread_prv(struct rte_mbuf *pkt, void *arg);
143 uint8_t calculate_lb_thread_pub(struct rte_mbuf *pkt, void *arg);
144 int check_loadb_thread(
145         struct app_params *app,
146         struct pipeline_params *params,
147         int32_t n_vnf_threads);
148
149 #endif