2 * @file IxEthDBLearning.c
5 * IXP400 SW Release version 2.0
7 * -- Copyright Notice --
10 * Copyright 2001-2005, Intel Corporation.
11 * All rights reserved.
14 * SPDX-License-Identifier: BSD-3-Clause
16 * -- End of Copyright Notice --
19 #include "IxEthDB_p.h"
22 * @brief hashes the mac address in a mac descriptor with a XOR function
24 * @param entry pointer to a mac descriptor to be hashed
26 * This function only extracts the mac address and employs ixEthDBKeyXORHash()
27 * to do the actual hashing.
28 * Used only to add a whole entry to a hash table, as opposed to searching which
29 * takes only a key and uses the key hashing directly.
31 * @see ixEthDBKeyXORHash()
33 * @return the hash value
37 UINT32 ixEthDBEntryXORHash(void *entry)
39 MacDescriptor *descriptor = (MacDescriptor *) entry;
41 return ixEthDBKeyXORHash(descriptor->macAddress);
45 * @brief hashes a mac address
47 * @param key pointer to a 6 byte structure (typically an IxEthDBMacAddr pointer)
50 * Given a 6 bytes MAC address, the hash used is:
52 * hash(MAC[0:5]) = MAC[0:1] ^ MAC[2:3] ^ MAC[4:5]
54 * Used by the hash table to search and remove entries based
55 * solely on their keys (mac addresses).
57 * @return the hash value
61 UINT32 ixEthDBKeyXORHash(void *key)
64 UINT8 *value = (UINT8 *) key;
66 hashValue = (value[5] << 8) | value[4];
67 hashValue ^= (value[3] << 8) | value[2];
68 hashValue ^= (value[1] << 8) | value[0];
74 * @brief mac descriptor match function
76 * @param reference mac address (typically an IxEthDBMacAddr pointer) structure
77 * @param entry pointer to a mac descriptor whose key (mac address) is to be
78 * matched against the reference key
80 * Used by the hash table to retrieve entries. Hashing entries can produce
81 * collisions, i.e. descriptors with different mac addresses and the same
82 * hash value, where this function is used to differentiate entries.
84 * @retval true if the entry matches the reference key (equal addresses)
85 * @retval false if the entry does not match the reference key
89 BOOL ixEthDBAddressMatch(void *reference, void *entry)
91 return (ixEthDBAddressCompare(reference, ((MacDescriptor *) entry)->macAddress) == 0);
95 * @brief compares two mac addresses
97 * @param mac1 first mac address to compare
98 * @param mac2 second mac address to compare
100 * This comparison works in a similar way to strcmp, producing similar results.
101 * Used to insert values keyed on mac addresses into binary search trees.
103 * @retval -1 if mac1 < mac2
104 * @retval 0 if ma1 == mac2
105 * @retval 1 if mac1 > mac2
107 UINT32 ixEthDBAddressCompare(UINT8 *mac1, UINT8 *mac2)
111 for (local_index = 0 ; local_index < IX_IEEE803_MAC_ADDRESS_SIZE ; local_index++)
113 if (mac1[local_index] > mac2[local_index])
117 else if (mac1[local_index] < mac2[local_index])