source: SVN/cambria/redboot/packages/devs/eth/intel/npe/ethDB/current/src/IxEthDBLearning.c @ 1

Last change on this file since 1 was 1, checked in by Tim Harvey, 2 years ago

restored latest version of files from server backup

Signed-off-by: Tim Harvey <tharvey@…>

File size: 4.5 KB
Line 
1/**
2 * @file IxEthDBLearning.c
3 *
4 * @par
5 * IXP400 SW Release version 2.3
6 *
7 * -- Copyright Notice --
8 *
9 * @par
10 * Copyright (c) 2001-2005, Intel Corporation.
11 * All rights reserved.
12 *
13 * @par
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 *    notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 *    notice, this list of conditions and the following disclaimer in the
21 *    documentation and/or other materials provided with the distribution.
22 * 3. Neither the name of the Intel Corporation nor the names of its contributors
23 *    may be used to endorse or promote products derived from this software
24 *    without specific prior written permission.
25 *
26 *
27 * @par
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 *
40 *
41 * @par
42 * -- End of Copyright Notice --
43 */
44
45#include "IxEthDB_p.h"
46
47/**
48 * @brief hashes the mac address in a mac descriptor with a XOR function
49 *
50 * @param entry pointer to a mac descriptor to be hashed
51 *
52 * This function only extracts the mac address and employs ixEthDBKeyXORHash()
53 * to do the actual hashing.
54 * Used only to add a whole entry to a hash table, as opposed to searching which
55 * takes only a key and uses the key hashing directly.
56 *
57 * @see ixEthDBKeyXORHash()
58 *
59 * @return the hash value
60 *
61 * @internal
62 */
63UINT32 ixEthDBEntryXORHash(void *entry)
64{
65    MacDescriptor *descriptor = (MacDescriptor *) entry;
66
67    return ixEthDBKeyXORHash(descriptor->macAddress);
68}
69
70/**
71 * @brief hashes a mac address
72 *
73 * @param key pointer to a 6 byte structure (typically an IxEthDBMacAddr pointer)
74 * to be hashed
75 *
76 * Given a 6 bytes MAC address, the hash used is:
77 *
78 * hash(MAC[0:5]) = MAC[0:1] ^ MAC[2:3] ^ MAC[4:5]
79 *
80 * Used by the hash table to search and remove entries based
81 * solely on their keys (mac addresses).
82 *
83 * @return the hash value
84 *
85 * @internal
86 */
87UINT32 ixEthDBKeyXORHash(void *key)
88{
89    UINT32 hashValue;
90    UINT8 *value = (UINT8 *) key;
91   
92    hashValue  = (value[5] << 8) | value[4];
93    hashValue ^= (value[3] << 8) | value[2];
94    hashValue ^= (value[1] << 8) | value[0];
95
96    return hashValue;
97}
98
99/**
100 * @brief mac descriptor match function
101 *
102 * @param reference mac address (typically an IxEthDBMacAddr pointer) structure
103 * @param entry pointer to a mac descriptor whose key (mac address) is to be
104 * matched against the reference key
105 *
106 * Used by the hash table to retrieve entries. Hashing entries can produce
107 * collisions, i.e. descriptors with different mac addresses and the same
108 * hash value, where this function is used to differentiate entries.
109 *
110 * @retval TRUE if the entry matches the reference key (equal addresses)
111 * @retval FALSE if the entry does not match the reference key
112 *
113 * @internal
114 */
115BOOL ixEthDBAddressMatch(void *reference, void *entry)
116{
117    return (ixEthDBAddressCompare(reference, ((MacDescriptor *) entry)->macAddress) == 0);
118}
119
120/**
121 * @brief compares two mac addresses
122 *
123 * @param mac1 first mac address to compare
124 * @param mac2 second mac address to compare
125 *
126 * This comparison works in a similar way to strcmp, producing similar results.
127 * Used to insert values keyed on mac addresses into binary search trees.
128 *
129 * @retval -1 if mac1 < mac2
130 * @retval 0 if ma1 == mac2
131 * @retval 1 if mac1 > mac2
132 */
133INT32 ixEthDBAddressCompare(UINT8 *mac1, UINT8 *mac2)
134{
135    UINT32 local_index;
136
137    for (local_index = 0 ; local_index < IX_IEEE803_MAC_ADDRESS_SIZE ; local_index++)
138    {
139        if (mac1[local_index] > mac2[local_index])
140        {
141            return 1;
142        }
143        else if (mac1[local_index] < mac2[local_index])
144        {
145            return -1;
146        }
147    }
148
149    return 0;
150}
151
Note: See TracBrowser for help on using the repository browser.