Support packets in flight
[samplevnf.git] / VNFs / DPPD-PROX / tx_pkt.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 _TX_PKT_H_
18 #define _TX_PKT_H_
19
20 #include <inttypes.h>
21 #include <string.h>
22 #include <rte_mbuf.h>
23 #include "ip6_addr.h"
24
25 struct task_base;
26
27 struct prox_headroom {
28         uint64_t command;
29         uint64_t data64;
30         uint32_t ip;
31         uint32_t prefix;
32         uint32_t gateway_ip;
33         uint16_t vlan;
34         struct ipv6_addr ipv6_addr;
35 } __attribute__((packed));
36
37 void flush_queues_hw(struct task_base *tbase);
38 void flush_queues_sw(struct task_base *tbase);
39
40 void flush_queues_no_drop_hw(struct task_base *tbase);
41 void flush_queues_no_drop_sw(struct task_base *tbase);
42
43 /* The following four transmit functions always send packets to the
44    single output unless the packet should be dropped. These functions
45    are used if (1) the task is only sending to one destination and
46    (2), packets can potentially be dropped (as specified by the out
47    parameter, which is either NO_PORT_AVAIL or 0). */
48 int tx_pkt_no_drop_hw1(struct task_base *tbase, struct rte_mbuf **mbufs, const uint16_t n_pkts, uint8_t *out);
49 int tx_pkt_no_drop_sw1(struct task_base *tbase, struct rte_mbuf **mbufs, const uint16_t n_pkts, uint8_t *out);
50 int tx_pkt_hw1(struct task_base *tbase, struct rte_mbuf **mbufs, const uint16_t n_pkts, uint8_t *out);
51 int tx_pkt_sw1(struct task_base *tbase, struct rte_mbuf **mbufs, const uint16_t n_pkts, uint8_t *out);
52
53 /* The following four transmit functions are used if (1) the task is
54    only sending to one destination and (2), packets are never dropped
55    by the task (the out parameter is ignored). */
56 int tx_pkt_no_drop_never_discard_hw1_lat_opt(struct task_base *tbase, struct rte_mbuf **mbufs, const uint16_t n_pkts, uint8_t *out);
57 int tx_pkt_no_drop_never_discard_hw1_thrpt_opt(struct task_base *tbase, struct rte_mbuf **mbufs, const uint16_t n_pkts, uint8_t *out);
58 int tx_pkt_no_drop_never_discard_hw1_no_pointer(struct task_base *tbase, struct rte_mbuf **mbufs, const uint16_t n_pkts, uint8_t *out);
59 int tx_pkt_no_drop_never_discard_sw1(struct task_base *tbase, struct rte_mbuf **mbufs, const uint16_t n_pkts, uint8_t *out);
60 int tx_pkt_never_discard_hw1_lat_opt(struct task_base *tbase, struct rte_mbuf **mbufs, const uint16_t n_pkts, uint8_t *out);
61 int tx_pkt_never_discard_hw1_thrpt_opt(struct task_base *tbase, struct rte_mbuf **mbufs, const uint16_t n_pkts, uint8_t *out);
62 int tx_pkt_never_discard_sw1(struct task_base *tbase, struct rte_mbuf **mbufs, const uint16_t n_pkts, uint8_t *out);
63
64 /* The two "self" transmit functions are used if the task is
65    transmitting to another task running on the same core and the
66    destination task ID is one higher than the current task. The never_discard
67    version of the function ignores the out parameter and should
68    therefor only be used if the task never discards packets.*/
69 int tx_pkt_self(struct task_base *tbase, struct rte_mbuf **mbufs, const uint16_t n_pkts, uint8_t *out);
70 int tx_pkt_never_discard_self(struct task_base *tbase, struct rte_mbuf **mbufs, const uint16_t n_pkts, uint8_t *out);
71
72 /* The following four tarnsmit functions are the most general. They
73    are used if (1) packets can be dropped and (2) there are multiple
74    outputs in the task. */
75 int tx_pkt_no_drop_hw(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkts, uint8_t *out);
76 int tx_pkt_no_drop_sw(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkts, uint8_t *out);
77 int tx_pkt_hw(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkts, uint8_t *out);
78 int tx_pkt_sw(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkts, uint8_t *out);
79 int tx_ctrlplane_hw(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkts, uint8_t *out);
80 int tx_ctrlplane_sw(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkts, uint8_t *out);
81
82 int tx_pkt_trace(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkts, uint8_t *out);
83 int tx_pkt_dump(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkts, uint8_t *out);
84 int tx_pkt_distr(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkts, uint8_t *out);
85 int tx_pkt_bw(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkts, uint8_t *out);
86
87 uint16_t tx_try_sw1(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkts);
88 uint16_t tx_try_hw1(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkts);
89 uint16_t tx_try_self(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkts);
90
91 /* When there are no output ports, this function is configured as the
92    tx function. This tx function can be used to make each task a
93    sink. */
94 int tx_pkt_drop_all(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkts, uint8_t *out);
95 int tx_pkt_l3(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkts, uint8_t *out);
96 int tx_pkt_ndp(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkts, uint8_t *out);
97
98 static inline uint8_t get_command(struct rte_mbuf *mbuf)
99 {
100         struct prox_headroom *prox_headroom = (struct prox_headroom *)(rte_pktmbuf_mtod(mbuf, uint8_t*) - sizeof(struct prox_headroom));
101         return prox_headroom->command & 0xFF;
102 }
103 static inline uint8_t get_task(struct rte_mbuf *mbuf)
104 {
105         struct prox_headroom *prox_headroom = (struct prox_headroom *)(rte_pktmbuf_mtod(mbuf, uint8_t*) - sizeof(struct prox_headroom));
106         return (prox_headroom->command >> 8) & 0xFF;
107 }
108 static inline uint8_t get_core(struct rte_mbuf *mbuf)
109 {
110         struct prox_headroom *prox_headroom = (struct prox_headroom *)(rte_pktmbuf_mtod(mbuf, uint8_t*) - sizeof(struct prox_headroom));
111         return (prox_headroom->command >> 16) & 0xFF;
112 }
113 static inline uint32_t get_ip(struct rte_mbuf *mbuf)
114 {
115         struct prox_headroom *prox_headroom = (struct prox_headroom *)(rte_pktmbuf_mtod(mbuf, uint8_t*) - sizeof(struct prox_headroom));
116         return (prox_headroom->command >> 32) & 0xFFFFFFFF;
117 }
118
119 static inline void ctrl_ring_set_command_core_task_ip(struct rte_mbuf *mbuf, uint64_t udata64)
120 {
121         struct prox_headroom *prox_headroom = (struct prox_headroom *)(rte_pktmbuf_mtod(mbuf, uint8_t*) - sizeof(struct prox_headroom));
122         prox_headroom->command = udata64;
123 }
124
125 static inline void ctrl_ring_set_command(struct rte_mbuf *mbuf, uint8_t command)
126 {
127         struct prox_headroom *prox_headroom = (struct prox_headroom *)(rte_pktmbuf_mtod(mbuf, uint8_t*) - sizeof(struct prox_headroom));
128         prox_headroom->command = command;
129 }
130
131 static inline void ctrl_ring_set_ip(struct rte_mbuf *mbuf, uint32_t udata32)
132 {
133         struct prox_headroom *prox_headroom = (struct prox_headroom *)(rte_pktmbuf_mtod(mbuf, uint8_t*) - sizeof(struct prox_headroom));
134         prox_headroom->ip = udata32;
135 }
136
137 static inline uint32_t ctrl_ring_get_ip(struct rte_mbuf *mbuf)
138 {
139         struct prox_headroom *prox_headroom = (struct prox_headroom *)(rte_pktmbuf_mtod(mbuf, uint8_t*) - sizeof(struct prox_headroom));
140         return prox_headroom->ip;
141 }
142
143 static inline void ctrl_ring_set_gateway_ip(struct rte_mbuf *mbuf, uint32_t udata32)
144 {
145         struct prox_headroom *prox_headroom = (struct prox_headroom *)(rte_pktmbuf_mtod(mbuf, uint8_t*) - sizeof(struct prox_headroom));
146         prox_headroom->gateway_ip = udata32;
147 }
148
149 static inline uint32_t ctrl_ring_get_gateway_ip(struct rte_mbuf *mbuf)
150 {
151         struct prox_headroom *prox_headroom = (struct prox_headroom *)(rte_pktmbuf_mtod(mbuf, uint8_t*) - sizeof(struct prox_headroom));
152         return prox_headroom->gateway_ip;
153 }
154
155 static inline void ctrl_ring_set_prefix(struct rte_mbuf *mbuf, uint32_t udata32)
156 {
157         struct prox_headroom *prox_headroom = (struct prox_headroom *)(rte_pktmbuf_mtod(mbuf, uint8_t*) - sizeof(struct prox_headroom));
158         prox_headroom->prefix = udata32;
159 }
160
161 static inline uint32_t ctrl_ring_get_prefix(struct rte_mbuf *mbuf)
162 {
163         struct prox_headroom *prox_headroom = (struct prox_headroom *)(rte_pktmbuf_mtod(mbuf, uint8_t*) - sizeof(struct prox_headroom));
164         return prox_headroom->prefix;
165 }
166
167 static inline void ctrl_ring_set_data(struct rte_mbuf *mbuf, uint64_t data)
168 {
169         struct prox_headroom *prox_headroom = (struct prox_headroom *)(rte_pktmbuf_mtod(mbuf, uint8_t*) - sizeof(struct prox_headroom));
170         prox_headroom->data64 = data;
171 }
172
173 static inline uint64_t ctrl_ring_get_data(struct rte_mbuf *mbuf)
174 {
175         struct prox_headroom *prox_headroom = (struct prox_headroom *)(rte_pktmbuf_mtod(mbuf, uint8_t*) - sizeof(struct prox_headroom));
176         return prox_headroom->data64;
177 }
178
179 static inline void ctrl_ring_set_ipv6_addr(struct rte_mbuf *mbuf, struct ipv6_addr *ip)
180 {
181         struct prox_headroom *prox_headroom = (struct prox_headroom *)(rte_pktmbuf_mtod(mbuf, uint8_t*) - sizeof(struct prox_headroom));
182         memcpy(&prox_headroom->ipv6_addr, ip, sizeof(struct ipv6_addr));
183 }
184
185 static inline struct ipv6_addr *ctrl_ring_get_ipv6_addr(struct rte_mbuf *mbuf)
186 {
187         struct prox_headroom *prox_headroom = (struct prox_headroom *)(rte_pktmbuf_mtod(mbuf, uint8_t*) - sizeof(struct prox_headroom));
188         return &prox_headroom->ipv6_addr;
189 }
190
191 static inline void ctrl_ring_set_vlan(struct rte_mbuf *mbuf, uint32_t udata16)
192 {
193         struct prox_headroom *prox_headroom = (struct prox_headroom *)(rte_pktmbuf_mtod(mbuf, uint8_t*) - sizeof(struct prox_headroom));
194         prox_headroom->vlan = udata16;
195 }
196
197 static inline uint16_t ctrl_ring_get_vlan(struct rte_mbuf *mbuf)
198 {
199         struct prox_headroom *prox_headroom = (struct prox_headroom *)(rte_pktmbuf_mtod(mbuf, uint8_t*) - sizeof(struct prox_headroom));
200         return prox_headroom->vlan;
201 }
202
203 int tx_ring_cti(struct task_base *tbase, struct rte_ring *ring, uint8_t command, struct rte_mbuf *mbuf, uint8_t core_id, uint8_t task_id, uint32_t ip, uint16_t vlan);
204 void tx_ring_cti6(struct task_base *tbase, struct rte_ring *ring, uint8_t command, struct rte_mbuf *mbuf, uint8_t core_id, uint8_t task_id, struct ipv6_addr *ip, uint16_t vlan);
205 void tx_ring_ip(struct task_base *tbase, struct rte_ring *ring, uint8_t command, struct rte_mbuf *mbuf, uint32_t ip);
206 void tx_ring_ip6(struct task_base *tbase, struct rte_ring *ring, uint8_t command,  struct rte_mbuf *mbuf, struct ipv6_addr *ip);
207 void tx_ring_ip6_data(struct task_base *tbase, struct rte_ring *ring, uint8_t command,  struct rte_mbuf *mbuf, struct ipv6_addr *ip, uint64_t data);
208 void tx_ring(struct task_base *tbase, struct rte_ring *ring, uint16_t command, struct rte_mbuf *mbuf);
209 void tx_ring_route(struct task_base *tbase, struct rte_ring *ring, int add, struct rte_mbuf *mbuf, uint32_t ip, uint32_t gateway_ip, uint32_t prefix);
210 static void store_packet(struct task_base *tbase, struct rte_mbuf *mbufs);
211
212 #endif /* _TX_PKT_H_ */