NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
simple_fwd_pkt.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 
26 #ifndef SIMPLE_FWD_PKT_H_
27 #define SIMPLE_FWD_PKT_H_
28 
29 #include <stdint.h>
30 #include <stdbool.h>
31 
32 #include <doca_flow_net.h>
33 
34 #define IPV4 (4) /* IPv4 address length in bytes */
35 #define IPV6 (6) /* IPv6 address length in bytes */
36 
43  uint8_t *l2; /* Pointer to Layer 2 format */
44  uint8_t *l3; /* Pointer to Layer 3 format */
45  uint8_t *l4; /* Pointer to Layer 4 format */
46 
47  uint8_t l3_type; /* Layer 2 protocol type */
48  uint8_t l4_type; /* Layer 3 protocol type */
49 
50  /* if tunnel it is the internal, if no tunnel then outer*/
51  uint8_t *l7;
52 };
53 
60  bool l2; /* Flag representing whether or not layer 2 is found */
61  enum doca_flow_tun_type type; /* Tunneling type (GRE, GTP or VXLAN) */
62 
63  /* Packet's tunneling parsing result represented as either GTP, GRE or VXLAN tunneling */
64  union {
65  struct {
66  doca_be32_t vni; /* VXLAN VNI */
67  };
68  struct {
69  doca_be32_t gre_key; /* GRE key value */
70  doca_be16_t proto; /* GRE protocol type */
71  };
72  struct {
73  uint8_t gtp_msg_type; /* GTP message type */
74  uint8_t gtp_flags; /* GTP flags */
75  doca_be32_t teid; /* GTP tied */
76  };
77  };
78 };
79 
86  void *orig_data; /* Pointer ro the packet raw data; before being formatted */
87  uint16_t orig_port_id; /* Port identifier from which the packet was received */
88  uint16_t pipe_queue; /* The pipe queue of the received packet, this should be the same as the RX queue index */
89  uint32_t rss_hash; /* RSS hash value */
90 
91  struct simple_fwd_pkt_format outer; /* Outer packet parsing result */
92  enum doca_flow_tun_type tun_type; /* Tunneling type (GRE, GTP or VXLAN) */
93  struct simple_fwd_pkt_tun_format tun; /* Tunneling parsing result*/
94  struct simple_fwd_pkt_format inner; /* Inner packet parsing result */
95  int len; /* Length, in bytes, of the packet */
96 };
97 
98 /*
99  * Packet's key, for entry search.
100  * computed from packet's parsing result, based on the 5-tuple and the tunneling type.
101  */
103  doca_be32_t ipv4_1; /* First Ipv4 address */
104  doca_be32_t ipv4_2; /* Second Ipv4 address */
105  doca_be16_t port_1; /* First port address */
106  doca_be16_t port_2; /* Second port address */
107  union {
108  doca_be32_t vni; /* VNI value */
109  doca_be32_t teid; /* GTPU TEID value */
110  doca_be32_t gre_key; /* GRE key value */
111  };
112  uint8_t protocol; /* Protocol type */
113  uint8_t tun_type; /* Supported tunneling type (GRE, GTP or VXLAN) */
114  uint16_t port_id; /* Port identifier on which the packet was received */
115  uint8_t pad[4]; /* Padding bytes in the packet */
116  uint32_t rss_hash; /* RSS hash value */
117 };
118 
119 /*
120  * Parses the packet and extract the relevant headers, outer/inner in addition to the tunnels.
121  *
122  * @data [in]: packet raw data
123  * @len [in]: the length of the packet's raw data in bytes
124  * @pinfo [out]: extracted packet's info
125  * @return: 0 on success and negative value otherwise
126  */
127 int simple_fwd_parse_packet(uint8_t *data, int len, struct simple_fwd_pkt_info *pinfo);
128 
129 /*
130  * Extracts the outer destination MAC address from the packet's info
131  *
132  * @pinfo [in]: the packet's info
133  * @return: outer destination MAC address
134  */
136 
137 /*
138  * Extracts the outer source MAC address from the packet's info
139  *
140  * @pinfo [in]: the packet's info
141  * @return: outer source MAC address
142  */
144 
145 /*
146  * Extracts the outer destination IPv4 address from the packet's info
147  *
148  * @pinfo [in]: the packet's info
149  * @return: outer destination IPv4 address
150  *
151  * @NOTE: the returned value is converted to big endian
152  */
154 
155 /*
156  * Extracts the outer source IPv4 address from the packet's info
157  *
158  * @pinfo [in]: the packet's info
159  * @return: outer source IPv4 address
160  *
161  * @NOTE: the returned value is converted to big endian
162  */
164 
165 /*
166  * Extracts the inner source IPv4 address from the packet's info
167  *
168  * @pinfo [in]: the packet's info
169  * @return: inner source IPv4 address
170  *
171  * @NOTE: the returned value is converted to big endian
172  */
174 
175 /*
176  * Extracts the inner destination IPv4 address from the packet's info
177  *
178  * @pinfo [in]: the packet's info
179  * @return: inner destination IPv4 address
180  *
181  * @NOTE: the returned value is converted to big endian
182  */
184 
185 /*
186  * Extracts the inner source port address from the packet's info
187  *
188  * @pinfo [in]: the packet's info
189  * @return: inner source port
190  *
191  * @NOTE: the returned value is converted to big endian
192  */
194 
195 /*
196  * Extracts the inner destination port address from the packet's info
197  *
198  * @pinfo [in]: the packet's info
199  * @return: inner destination port
200  *
201  * @NOTE: the returned value is converted to big endian
202  */
204 
205 /*
206  * Extracts the outer source port address from the packet's info
207  *
208  * @pinfo [in]: the packet's info
209  * @return: outer source port
210  *
211  * @NOTE: the returned value is converted to big endian
212  */
214 
215 /*
216  * Extracts the outer destination port address from the packet's info
217  *
218  * @pinfo [in]: the packet's info
219  * @return: outer destination port
220  *
221  * @NOTE: the returned value is converted to big endian
222  */
224 
225 /*
226  * Decap the packet's header if the tunneling is VXLAN
227  *
228  * @pinfo [in]: the packet's info
229  */
230 void simple_fwd_pinfo_decap(struct simple_fwd_pkt_info *pinfo);
231 
232 #endif /* SIMPLE_FWD_PKT_H_ */
uint64_t len
doca_flow_tun_type
doca flow tunnel type
uint32_t doca_be32_t
Definition: doca_types.h:121
uint16_t doca_be16_t
Declare DOCA endianity types.
Definition: doca_types.h:120
doca_be16_t simple_fwd_pinfo_inner_dst_port(struct simple_fwd_pkt_info *pinfo)
doca_be16_t simple_fwd_pinfo_outer_dst_port(struct simple_fwd_pkt_info *pinfo)
void simple_fwd_pinfo_decap(struct simple_fwd_pkt_info *pinfo)
doca_be32_t simple_fwd_pinfo_outer_ipv4_src(struct simple_fwd_pkt_info *pinfo)
doca_be16_t simple_fwd_pinfo_inner_src_port(struct simple_fwd_pkt_info *pinfo)
doca_be16_t simple_fwd_pinfo_outer_src_port(struct simple_fwd_pkt_info *pinfo)
doca_be32_t simple_fwd_pinfo_inner_ipv4_src(struct simple_fwd_pkt_info *pinfo)
doca_be32_t simple_fwd_pinfo_inner_ipv4_dst(struct simple_fwd_pkt_info *pinfo)
int simple_fwd_parse_packet(uint8_t *data, int len, struct simple_fwd_pkt_info *pinfo)
uint8_t * simple_fwd_pinfo_outer_mac_src(struct simple_fwd_pkt_info *pinfo)
doca_be32_t simple_fwd_pinfo_outer_ipv4_dst(struct simple_fwd_pkt_info *pinfo)
uint8_t * simple_fwd_pinfo_outer_mac_dst(struct simple_fwd_pkt_info *pinfo)
doca_be32_t gre_key
doca_be16_t port_2
doca_be32_t ipv4_2
doca_be16_t port_1
doca_be32_t ipv4_1
struct simple_fwd_pkt_format outer
enum doca_flow_tun_type tun_type
struct simple_fwd_pkt_format inner
struct simple_fwd_pkt_tun_format tun
enum doca_flow_tun_type type