| 82 | self.use_l4_port = use_l4_port |
| 83 | |
| 84 | def toeplitz_hash(self, data: bytes) -> int: |
| 85 | # see rte_softrss_* in lib/hash/rte_thash.h |
| 86 | hash_value = ctypes.c_uint32(0) |
| 87 | |
| 88 | for i, byte in enumerate(data): |
| 89 | for j in range(8): |
| 90 | bit = (byte >> (7 - j)) & 0x01 |
| 91 | |
| 92 | if bit == 1: |
| 93 | keyword = ctypes.c_uint32(0) |
| 94 | keyword.value |= self.key[i] << 24 |
| 95 | keyword.value |= self.key[i + 1] << 16 |
| 96 | keyword.value |= self.key[i + 2] << 8 |
| 97 | keyword.value |= self.key[i + 3] |
| 98 | |
| 99 | if j > 0: |
| 100 | keyword.value <<= j |
| 101 | keyword.value |= self.key[i + 4] >> (8 - j) |
| 102 | |
| 103 | hash_value.value ^= keyword.value |
| 104 | |
| 105 | return hash_value.value |
| 106 | |
| 107 | def get_queue_index(self, packet: Packet) -> int: |
| 108 | bytes_to_hash = packet.hash_data(self.use_l4_port) |