hashref.h

Reference Documentation

product_line_custom
Napatech SmartNIC
category
Reference Information

Go to the documentation of this file.

1/* 2 * %NT_SOFTWARE_LICENSE% 3 */ 4 5/** 6 * @file 7 * 8 * This header file contains the interface to the hash reference library. 9 * 10 */ 11#ifndef __HASHREF_H__ 12#define __HASHREF_H__ 13 14#include "nt.h" 15 16/** 17 * Available hash modes 18 */ 19enum NtHashRefHashMode_e { 20 NT_HASHREF_HASHMODE_UNDEFINED = 0, 21 NT_HASHREF_HASHMODE_LAST_MPLS_LABEL, //!< Hash Key Type 2: Last MPLS Label 22 NT_HASHREF_HASHMODE_ALL_MPLS_LABELS, //!< Hash Key Type 3: All MPLS Labels 23 NT_HASHREF_HASHMODE_2_TUPLE, //!< Hash Key Type 4: 2-Tuple 24 NT_HASHREF_HASHMODE_2_TUPLE_SORTED, //!< Hash Key Type 5: 2-Tuple Sorted 25 NT_HASHREF_HASHMODE_LAST_VLAN_ID, //!< Hash Key Type 6: Last VLAN ID 26 NT_HASHREF_HASHMODE_ALL_VLAN_IDS, //!< Hash Key Type 7: All VLAN IDs 27 NT_HASHREF_HASHMODE_5_TUPLE, //!< Hash Key Type 8: 5-Tuple 28 NT_HASHREF_HASHMODE_5_TUPLE_SORTED, //!< Hash Key Type 9: 5-Tuple Sorted 29 NT_HASHREF_HASHMODE_3_TUPLE_GRE_V0, //!< Hash Key Type 10: 3-Tuple GREv0 30 NT_HASHREF_HASHMODE_3_TUPLE_GRE_V0_SORTED, //!< Hash Key Type 11: 3-Tuple GREv0 Sorted 31 NT_HASHREF_HASHMODE_5_TUPLE_SCTP, //!< Hash Key Type 12: 5-Tuple SCTP 32 NT_HASHREF_HASHMODE_5_TUPLE_SCTP_SORTED, //!< Hash Key Type 13: 5-Tuple SCTP Sorted 33 NT_HASHREF_HASHMODE_INNER_2_TUPLE, //!< Hash Key Type 14 for PCIe Gen2 Adapters: Inner 2-Tuple 34 NT_HASHREF_HASHMODE_3_TUPLE_GTP_V0, //!< Hash Key Type 14 for PCIe Gen1 Adapters: 3-Tuple GTPv0 35 NT_HASHREF_HASHMODE_INNER_2_TUPLE_SORTED, //!< Hash Key Type 15 for PCIe Gen2 Adapters: Inner 2-Tuple Sorted 36 NT_HASHREF_HASHMODE_3_TUPLE_GTP_V0_SORTED, //!< Hash Key Type 15 for PCIe Gen1 Adapters: 3-Tuple GTPv0 Sorted 37 NT_HASHREF_HASHMODE_INNER_5_TUPLE, //!< Hash Key Type 16 for PCIe Gen2 Adapters: Inner 5-Tuple 38 NT_HASHREF_HASHMODE_3_TUPLE_GTP_V1V2, //!< Hash Key Type 16 for PCIe Gen1 Adapters: 3-Tuple GTPv1/GTPv2 39 NT_HASHREF_HASHMODE_INNER_5_TUPLE_SORTED, //!< Hash Key Type 17 for PCIe Gen2 Adapters: Inner 5-Tuple Sorted 40 NT_HASHREF_HASHMODE_3_TUPLE_GTP_V1V2_SORTED, //!< Hash Key Type 17 for PCIe Gen1 Adapters: 3-Tuple GTPv1/GTPv2 Sorted 41 NT_HASHREF_HASHMODE_IP_FRAGMENT_TUPLE, //!< Hash Key Type 30 for PCIe Gen2 Adapters: IP Fragment Tuple 42 NT_HASHREF_HASHMODE_LAST 43}; 44 45/** 46 * Hash reference configuration 47 */ 48typedef struct NtHashRefConfig_v0_s { 49 enum NtAdapterType_e adapterType; //!< The adapter type 50 union Ntfpgaid_u fpgaid; //!< The FPGA ID of the adapter to emulate in the hash value calculation 51 enum NtHashRefHashMode_e hashmode;//!< The hash mode to use, see @ref ::NtHashRefHashMode_e for available hash modes 52 uint32_t hashmask[10]; //!< Hash mask - default in NTPL is 0xFFFFFFFF for all hash words. 53 uint32_t streams; //!< Number of streams to distribute to 54 uint32_t seed; //!< Hash seed as defined in ntservice.ini. Default is 0xFFFFFFFF 55} NtHashRefConfig_v0_t; 56 57/** 58 * Hash reference configuration versions 59 */ 60enum NtHashRefConfig_e { 61 NT_HASHREF_CONFIG_UNDEFINED = 0, 62 NT_HASHREF_CONFIG_V0, //!< Use hash reference configuration @ref ::NtHashRefConfig_v0_t 63 NT_HASHREF_CONFIG_LAST 64}; 65 66/** 67 * Hash reference configuration 68 */ 69typedef struct NtHashRefConfig_s { 70 enum NtHashRefConfig_e config; //!< Configuration version to use 71 union NtHashRefConfig_u { 72 NtHashRefConfig_v0_t config_v0; //!< Hash reference configuration version 0 73 } u; 74} NtHashRefConfig_t; 75 76 77enum NtHashRefInputType_e { 78 NT_HASHREF_INPUT_TYPE_UNDEFINED = 0, 79 NT_HASHREF_INPUT_TYPE_LAST_MPLS_LABEL, 80 NT_HASHREF_INPUT_TYPE_ALL_MPLS_LABELS, 81 NT_HASHREF_INPUT_TYPE_TUPLE_2_IP_V4, 82 NT_HASHREF_INPUT_TYPE_TUPLE_2_IP_V6, 83 NT_HASHREF_INPUT_TYPE_LAST_VLAN_ID, 84 NT_HASHREF_INPUT_TYPE_ALL_VLAN_IDS, 85 NT_HASHREF_INPUT_TYPE_TUPLE_5_IP_V4, 86 NT_HASHREF_INPUT_TYPE_TUPLE_5_IP_V6, 87 NT_HASHREF_INPUT_TYPE_TUPLE_3_GRE_V0_IP_V4, 88 NT_HASHREF_INPUT_TYPE_TUPLE_3_GRE_V0_IP_V6, 89 NT_HASHREF_INPUT_TYPE_TUPLE_5_SCTP_IP_V4, 90 NT_HASHREF_INPUT_TYPE_TUPLE_5_SCTP_IP_V6, 91 NT_HASHREF_INPUT_TYPE_IP_FRAGMENT_TUPLE_IP_V4, 92 NT_HASHREF_INPUT_TYPE_IP_FRAGMENT_TUPLE_IP_V6, 93 NT_HASHREF_INPUT_TYPE_TUPLE_3_GTP_V0_IP_V4, 94 NT_HASHREF_INPUT_TYPE_TUPLE_3_GTP_V0_IP_V6, 95 NT_HASHREF_INPUT_TYPE_TUPLE_3_GTP_V1_V2_IP_V4, 96 NT_HASHREF_INPUT_TYPE_TUPLE_3_GTP_V1_V2_IP_V6, 97 NT_HASHREF_INPUT_TYPE_LAST 98}; 99 100/** 101 * Hash calculation input 102 */ 103typedef struct { 104 /** 105 * hashref input union 106 */ 107 enum NtHashRefInputType_e inputType; /* Denotes the used structure */ 108 union NtHashRefInput_u { 109 struct NtLastMplsLabel_s { 110 uint32_t label; //!< 20-bit MPLS label 111 } lastMplsLabel; 112 struct NtAllMplsLabels_s { 113 uint32_t label[7]; //!< 20-bit MPLS label 114 } allMplsLabels; 115 struct NtTuple2IPv4_s { 116 uint32_t srcIP; //!< 32-bit IPv4 address in network order 117 uint32_t dstIP; //!< 32-bit IPv4 address in network order 118 } tuple2IPv4; 119 struct NtTuple2IPv6_s { 120 uint8_t srcIP[16]; //!< 128-bit IPv6 address in network order 121 uint8_t dstIP[16]; //!< 128-bit IPv6 address in network order 122 } tuple2IPv6; 123 struct NtLastVlanId_s { 124 uint16_t vlanId; //!< 12-bit VLAN Id in network order 125 } lastVlanId; 126 struct NtAllVlanIds_s { 127 uint16_t vlanId[3]; //!< 12-bit VLAN Id in network order 128 } allVlanIds; 129 struct NtTuple5IPv4_s { 130 uint32_t srcIP; //!< 32-bit IPv4 address in network order 131 uint32_t dstIP; //!< 32-bit IPv4 address in network order 132 uint16_t srcPort; //!< 16-bit port number in network order 133 uint16_t dstPort; //!< 16-bit port number in network order 134 uint8_t protocol; //!< 8-bit IP protocol number 135 } tuple5IPv4; 136 struct NtTuple5IPv6_s { 137 uint8_t srcIP[16]; //!< 128-bit IPv6 address in network order 138 uint8_t dstIP[16]; //!< 128-bit IPv6 address in network order 139 uint16_t srcPort; //!< 16-bit port number in network order 140 uint16_t dstPort; //!< 16-bit port number in network order 141 uint8_t protocol; //!< 8-bit IP protocol number 142 } tuple5IPv6; 143 struct NtTuple3GREv0IPv4_s { 144 uint32_t srcIP; //!< 32-bit IPv4 address in network order 145 uint32_t dstIP; //!< 32-bit IPv4 address in network order 146 uint32_t key; //!< 32-bit GRE key in network order 147 } tuple3GREv0IPv4; 148 struct NtTuple3GREv0IPv6_s { 149 uint8_t srcIP[16]; //!< 128-bit IPv6 address in network order 150 uint8_t dstIP[16]; //!< 128-bit IPv6 address in network order 151 uint32_t key; //!< 32-bit GRE key in network order 152 } tuple3GREv0IPv6; 153 struct NtTuple5SCTPIPv4_s { 154 uint32_t srcIP; //!< 32-bit IPv4 address in network order 155 uint32_t dstIP; //!< 32-bit IPv4 address in network order 156 uint16_t srcPort; //!< 16-bit port number in network order 157 uint16_t dstPort; //!< 16-bit port number in network order 158 uint32_t verificationTag;//!< 32-bit verification tag in network order 159 } tuple5SCTPIPv4; 160 struct NtTuple5SCTPIPv6_s{ 161 uint8_t srcIP[16]; //!< 128-bit IPv6 address in network order 162 uint8_t dstIP[16]; //!< 128-bit IPv6 address in network order 163 uint16_t srcPort; //!< 16-bit port number in network order 164 uint16_t dstPort; //!< 16-bit port number in network order 165 uint32_t verificationTag;//!< 32-bit verification tag in network order 166 } tuple5SCTPIPv6; 167 struct NtIpFragmentTupleIPv4_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 ipId; //!< 16-bit IP identifier in network order 171 uint8_t ipProt; //!< 8-bit IP protocol number 172 } ipFragmentTupleIPv4; 173 struct NtIpFragmentTupleIPv6_s { 174 uint8_t srcIP[16]; //!< 128-bit IPv6 address in network order 175 uint8_t dstIP[16]; //!< 128-bit IPv6 address in network order 176 uint32_t id; //!< 32-bit fragment identifier 177 } ipFragmentTupleIPv6; 178 struct NtTuple3GTPv0IPv4_s { 179 uint32_t srcIP; //!< 32-bit IPv4 address in network order 180 uint32_t dstIP; //!< 32-bit IPv4 address in network order 181 uint16_t flowLabel; //!< 16-bit flow label in network order 182 } tuple3GTPv0IPv4; 183 struct NtTuple3GTPv0IPv6_s { 184 uint8_t srcIP[16]; //!< 128-bit IPv6 address in network order 185 uint8_t dstIP[16]; //!< 128-bit IPv6 address in network order 186 uint16_t flowLabel; //!< 16-bit flow label in network order 187 } tuple3GTPv0IPv6; 188 struct NtTuple3GTPv1v2IPv4_s { 189 uint32_t srcIP; //!< 32-bit IPv4 address in network order 190 uint32_t dstIP; //!< 32-bit IPv4 address in network order 191 uint32_t teid; //!< 32-bit tunnel identifier in network order 192 } tuple3GTPv1v2IPv4; 193 struct NtTuple3GTPv1v2IPv6_s { 194 uint8_t srcIP[16]; //!< 128-bit IPv6 address in network order 195 uint8_t dstIP[16]; //!< 128-bit IPv6 address in network order 196 uint32_t teid; //!< 32-bit tunnel identifier in network order 197 } tuple3GTPv1v2IPv6; 198 } u; 199} NtHashRefInput_t; 200 201typedef struct NtHashRefResult_s { 202 uint32_t hashvalue; //!< 24-bit calculated hash value 203 uint32_t stream; //!< Destination stream - set if the streams value 204 //!< is non-zero in the hash reference configuration 205} NtHashRefResult_t; 206 207/** 208 * Hash reference handle 209 */ 210typedef struct NtHashRef_s* NtHashRef_t; 211 212/** 213 * @brief Allocate and configure a hash reference handle 214 * 215 * @param[out] handle Allocated hash reference handle 216 * @param[in] config Hash reference configuration 217 * 218 * @retval 0 Success 219 * @retval !=0 Error 220 */ 221int NT_HashRefOpen(NtHashRef_t *handle, const NtHashRefConfig_t *config); 222 223/** 224 * @brief Calculate hash value 225 * 226 * This function calculates the hash value based on the configuration 227 * associated with the handle and the input given 228 * 229 * @param[in] handle Hash reference handle 230 * @param[in] input Input for hash calculation. Must match the selected input type 231 * @param[out] result The result of the hash calculation 232 * 233 * @retval 0 Success 234 * @retval !=0 Error 235 */ 236int NT_HashRefCalc(const NtHashRef_t handle, const NtHashRefInput_t *input, 237 NtHashRefResult_t *result); 238 239/** 240 * @brief Close the hash reference handle and free associated resources 241 * 242 * @retval 0 Success 243 * @retval !=0 Error 244 */ 245int NT_HashRefClose(NtHashRef_t handle); 246 247#endif // __HASHREF_H__