hashref.h Source File

Reference Documentation

Platform
Napatech SmartNIC
Content Type
Reference Information
Capture Software Version
Link™ Capture Software 12.15
Napatech Software Suite: include/ntutil/hashref.h Source File
hashref.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2025 Napatech A/S. All Rights Reserved.
4  *
5  * 1. Copying, modification, and distribution of this file, or executable
6  * versions of this file, is governed by the terms of the Napatech Software
7  * license agreement under which this file was made available. If you do not
8  * agree to the terms of the license do not install, copy, access or
9  * otherwise use this file.
10  *
11  * 2. Under the Napatech Software license agreement you are granted a
12  * limited, non-exclusive, non-assignable, copyright license to copy, modify
13  * and distribute this file in conjunction with Napatech SmartNIC's and
14  * similar hardware manufactured or supplied by Napatech A/S.
15  *
16  * 3. The full Napatech Software License Agreement is included in this
17  * distribution, please see "NA-0009 Software License Agreement.pdf"
18  *
19  * 4. Redistributions of source code must retain this copyright notice,
20  * list of conditions and the following disclaimer.
21  *
22  * THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTIES, EXPRESS OR
23  * IMPLIED, AND NAPATECH DISCLAIMS ALL IMPLIED WARRANTIES INCLUDING ANY
24  * IMPLIED WARRANTY OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, OR OF
25  * FITNESS FOR A PARTICULAR PURPOSE. TO THE EXTENT NOT PROHIBITED BY
26  * APPLICABLE LAW, IN NO EVENT SHALL NAPATECH BE LIABLE FOR PERSONAL INJURY,
27  * OR ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES WHATSOEVER,
28  * INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, CORRUPTION OR
29  * LOSS OF DATA, FAILURE TO TRANSMIT OR RECEIVE ANY DATA OR INFORMATION,
30  * BUSINESS INTERRUPTION OR ANY OTHER COMMERCIAL DAMAGES OR LOSSES, ARISING
31  * OUT OF OR RELATED TO YOUR USE OR INABILITY TO USE NAPATECH SOFTWARE OR
32  * SERVICES OR ANY THIRD PARTY SOFTWARE OR APPLICATIONS IN CONJUNCTION WITH
33  * THE NAPATECH SOFTWARE OR SERVICES, HOWEVER CAUSED, REGARDLESS OF THE THEORY
34  * OF LIABILITY (CONTRACT, TORT OR OTHERWISE) AND EVEN IF NAPATECH HAS BEEN
35  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME JURISDICTIONS DO NOT ALLOW
36  * THE EXCLUSION OR LIMITATION OF LIABILITY FOR PERSONAL INJURY, OR OF
37  * INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS LIMITATION MAY NOT APPLY TO YOU.
38  *
39  *
40 
41  */
42 
43 /**
44  * @file
45  *
46  * This header file contains the interface to the hash reference library.
47  *
48  */
49 #ifndef __HASHREF_H__
50 #define __HASHREF_H__
51 
52 #include "nt.h"
53 
54 /**
55  * Available hash modes
56  */
59  NT_HASHREF_HASHMODE_LAST_MPLS_LABEL, //!< Hash Key Type 2: Last MPLS Label
60  NT_HASHREF_HASHMODE_ALL_MPLS_LABELS, //!< Hash Key Type 3: All MPLS Labels
61  NT_HASHREF_HASHMODE_2_TUPLE, //!< Hash Key Type 4: 2-Tuple
62  NT_HASHREF_HASHMODE_2_TUPLE_SORTED, //!< Hash Key Type 5: 2-Tuple Sorted
63  NT_HASHREF_HASHMODE_LAST_VLAN_ID, //!< Hash Key Type 6: Last VLAN ID
64  NT_HASHREF_HASHMODE_ALL_VLAN_IDS, //!< Hash Key Type 7: All VLAN IDs
65  NT_HASHREF_HASHMODE_5_TUPLE, //!< Hash Key Type 8: 5-Tuple
66  NT_HASHREF_HASHMODE_5_TUPLE_SORTED, //!< Hash Key Type 9: 5-Tuple Sorted
67  NT_HASHREF_HASHMODE_3_TUPLE_GRE_V0, //!< Hash Key Type 10: 3-Tuple GREv0
68  NT_HASHREF_HASHMODE_3_TUPLE_GRE_V0_SORTED, //!< Hash Key Type 11: 3-Tuple GREv0 Sorted
69  NT_HASHREF_HASHMODE_5_TUPLE_SCTP, //!< Hash Key Type 12: 5-Tuple SCTP
70  NT_HASHREF_HASHMODE_5_TUPLE_SCTP_SORTED, //!< Hash Key Type 13: 5-Tuple SCTP Sorted
71  NT_HASHREF_HASHMODE_INNER_2_TUPLE, //!< Hash Key Type 14 for PCIe Gen2 Adapters: Inner 2-Tuple
72  NT_HASHREF_HASHMODE_3_TUPLE_GTP_V0, //!< Hash Key Type 14 for PCIe Gen1 Adapters: 3-Tuple GTPv0
73  NT_HASHREF_HASHMODE_INNER_2_TUPLE_SORTED, //!< Hash Key Type 15 for PCIe Gen2 Adapters: Inner 2-Tuple Sorted
74  NT_HASHREF_HASHMODE_3_TUPLE_GTP_V0_SORTED, //!< Hash Key Type 15 for PCIe Gen1 Adapters: 3-Tuple GTPv0 Sorted
75  NT_HASHREF_HASHMODE_INNER_5_TUPLE, //!< Hash Key Type 16 for PCIe Gen2 Adapters: Inner 5-Tuple
76  NT_HASHREF_HASHMODE_3_TUPLE_GTP_V1V2, //!< Hash Key Type 16 for PCIe Gen1 Adapters: 3-Tuple GTPv1/GTPv2
77  NT_HASHREF_HASHMODE_INNER_5_TUPLE_SORTED, //!< Hash Key Type 17 for PCIe Gen2 Adapters: Inner 5-Tuple Sorted
78  NT_HASHREF_HASHMODE_3_TUPLE_GTP_V1V2_SORTED, //!< Hash Key Type 17 for PCIe Gen1 Adapters: 3-Tuple GTPv1/GTPv2 Sorted
79  NT_HASHREF_HASHMODE_IP_FRAGMENT_TUPLE, //!< Hash Key Type 30 for PCIe Gen2 Adapters: IP Fragment Tuple
81 };
82 
83 /**
84  * Hash reference configuration
85  */
86 typedef struct NtHashRefConfig_v0_s {
87  enum NtAdapterType_e adapterType; //!< The adapter type
88  union Ntfpgaid_u fpgaid; //!< The FPGA ID of the adapter to emulate in the hash value calculation
89  enum NtHashRefHashMode_e hashmode;//!< The hash mode to use, see @ref ::NtHashRefHashMode_e for available hash modes
90  uint32_t hashmask[10]; //!< Hash mask - default in NTPL is 0xFFFFFFFF for all hash words.
91  uint32_t streams; //!< Number of streams to distribute to
92  uint32_t seed; //!< Hash seed as defined in ntservice.ini. Default is 0xFFFFFFFF
94 
95 /**
96  * Hash reference configuration versions
97  */
100  NT_HASHREF_CONFIG_V0, //!< Use hash reference configuration @ref ::NtHashRefConfig_v0_t
102 };
103 
104 /**
105  * Hash reference configuration
106  */
107 typedef struct NtHashRefConfig_s {
108  enum NtHashRefConfig_e config; //!< Configuration version to use
110  NtHashRefConfig_v0_t config_v0; //!< Hash reference configuration version 0
111  } u;
113 
114 
136 };
137 
138 /**
139  * Hash calculation input
140  */
141 typedef struct {
142  /**
143  * hashref input union
144  */
145  enum NtHashRefInputType_e inputType; /* Denotes the used structure */
148  uint32_t label; //!< 20-bit MPLS label
149  } lastMplsLabel;
151  uint32_t label[7]; //!< 20-bit MPLS label
152  } allMplsLabels;
153  struct NtTuple2IPv4_s {
154  uint32_t srcIP; //!< 32-bit IPv4 address in network order
155  uint32_t dstIP; //!< 32-bit IPv4 address in network order
156  } tuple2IPv4;
157  struct NtTuple2IPv6_s {
158  uint8_t srcIP[16]; //!< 128-bit IPv6 address in network order
159  uint8_t dstIP[16]; //!< 128-bit IPv6 address in network order
160  } tuple2IPv6;
161  struct NtLastVlanId_s {
162  uint16_t vlanId; //!< 12-bit VLAN Id in network order
163  } lastVlanId;
164  struct NtAllVlanIds_s {
165  uint16_t vlanId[3]; //!< 12-bit VLAN Id in network order
166  } allVlanIds;
167  struct NtTuple5IPv4_s {
168  uint32_t srcIP; //!< 32-bit IPv4 address in network order
169  uint32_t dstIP; //!< 32-bit IPv4 address in network order
170  uint16_t srcPort; //!< 16-bit port number in network order
171  uint16_t dstPort; //!< 16-bit port number in network order
172  uint8_t protocol; //!< 8-bit IP protocol number
173  } tuple5IPv4;
174  struct NtTuple5IPv6_s {
175  uint8_t srcIP[16]; //!< 128-bit IPv6 address in network order
176  uint8_t dstIP[16]; //!< 128-bit IPv6 address in network order
177  uint16_t srcPort; //!< 16-bit port number in network order
178  uint16_t dstPort; //!< 16-bit port number in network order
179  uint8_t protocol; //!< 8-bit IP protocol number
180  } tuple5IPv6;
182  uint32_t srcIP; //!< 32-bit IPv4 address in network order
183  uint32_t dstIP; //!< 32-bit IPv4 address in network order
184  uint32_t key; //!< 32-bit GRE key in network order
185  } tuple3GREv0IPv4;
187  uint8_t srcIP[16]; //!< 128-bit IPv6 address in network order
188  uint8_t dstIP[16]; //!< 128-bit IPv6 address in network order
189  uint32_t key; //!< 32-bit GRE key in network order
190  } tuple3GREv0IPv6;
192  uint32_t srcIP; //!< 32-bit IPv4 address in network order
193  uint32_t dstIP; //!< 32-bit IPv4 address in network order
194  uint16_t srcPort; //!< 16-bit port number in network order
195  uint16_t dstPort; //!< 16-bit port number in network order
196  uint32_t verificationTag;//!< 32-bit verification tag in network order
197  } tuple5SCTPIPv4;
199  uint8_t srcIP[16]; //!< 128-bit IPv6 address in network order
200  uint8_t dstIP[16]; //!< 128-bit IPv6 address in network order
201  uint16_t srcPort; //!< 16-bit port number in network order
202  uint16_t dstPort; //!< 16-bit port number in network order
203  uint32_t verificationTag;//!< 32-bit verification tag in network order
204  } tuple5SCTPIPv6;
206  uint32_t srcIP; //!< 32-bit IPv4 address in network order
207  uint32_t dstIP; //!< 32-bit IPv4 address in network order
208  uint16_t ipId; //!< 16-bit IP identifier in network order
209  uint8_t ipProt; //!< 8-bit IP protocol number
210  } ipFragmentTupleIPv4;
212  uint8_t srcIP[16]; //!< 128-bit IPv6 address in network order
213  uint8_t dstIP[16]; //!< 128-bit IPv6 address in network order
214  uint32_t id; //!< 32-bit fragment identifier
215  } ipFragmentTupleIPv6;
217  uint32_t srcIP; //!< 32-bit IPv4 address in network order
218  uint32_t dstIP; //!< 32-bit IPv4 address in network order
219  uint16_t flowLabel; //!< 16-bit flow label in network order
220  } tuple3GTPv0IPv4;
222  uint8_t srcIP[16]; //!< 128-bit IPv6 address in network order
223  uint8_t dstIP[16]; //!< 128-bit IPv6 address in network order
224  uint16_t flowLabel; //!< 16-bit flow label in network order
225  } tuple3GTPv0IPv6;
227  uint32_t srcIP; //!< 32-bit IPv4 address in network order
228  uint32_t dstIP; //!< 32-bit IPv4 address in network order
229  uint32_t teid; //!< 32-bit tunnel identifier in network order
230  } tuple3GTPv1v2IPv4;
232  uint8_t srcIP[16]; //!< 128-bit IPv6 address in network order
233  uint8_t dstIP[16]; //!< 128-bit IPv6 address in network order
234  uint32_t teid; //!< 32-bit tunnel identifier in network order
235  } tuple3GTPv1v2IPv6;
236  } u;
238 
239 typedef struct NtHashRefResult_s {
240  uint32_t hashvalue; //!< 24-bit calculated hash value
241  uint32_t stream; //!< Destination stream - set if the streams value
242  //!< is non-zero in the hash reference configuration
244 
245 /**
246  * Hash reference handle
247  */
248 typedef struct NtHashRef_s *NtHashRef_t;
249 typedef const struct NtHashRef_s *const_NtHashRef_t;
250 
251 /**
252  * @brief Allocate and configure a hash reference handle
253  *
254  * @param[out] handle Allocated hash reference handle
255  * @param[in] config Hash reference configuration
256  *
257  * @retval 0 Success
258  * @retval !=0 Error
259  */
260 int NT_HashRefOpen(NtHashRef_t *handle, const NtHashRefConfig_t *config);
261 
262 /**
263  * @brief Calculate hash value
264  *
265  * This function calculates the hash value based on the configuration
266  * associated with the handle and the input given
267  *
268  * @param[in] handle Hash reference handle
269  * @param[in] input Input for hash calculation. Must match the selected input type
270  * @param[out] result The result of the hash calculation
271  *
272  * @retval 0 Success
273  * @retval !=0 Error
274  */
275 int NT_HashRefCalc(NtHashRef_t handle, const NtHashRefInput_t *input,
276  NtHashRefResult_t *result);
277 
278 /**
279  * @brief Calculate 32-bit hash value
280  *
281  * This function calculates the hash value based on the configuration
282  * associated with the handle and the input given
283  *
284  * @param[in] handle Hash reference handle
285  * @param[in] input Input for hash calculation. Must match the selected input type
286  * @param[out] result The result of the 32-bit hash calculation
287  *
288  * @retval 0 Success
289  * @retval !=0 Error
290  */
291 int NT_HashRefCalcV2(NtHashRef_t handle, const NtHashRefInput_t *input,
292  NtHashRefResult_t *result);
293 
294 /**
295  * @brief Close the hash reference handle and free associated resources
296  *
297  * @retval 0 Success
298  * @retval !=0 Error
299  */
300 int NT_HashRefClose(NtHashRef_t handle);
301 
302 #endif // __HASHREF_H__