Add hash_mac() and apply it when appropriate.
Signed-off-by: Andy Zhou <azhou@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
static inline uint32_t hash_int(uint32_t x, uint32_t basis);
static inline uint32_t hash_2words(uint32_t, uint32_t);
static inline uint32_t hash_uint64(uint64_t);
+static inline uint32_t hash_uint64_basis(uint64_t x, uint32_t basis);
uint32_t hash_3words(uint32_t, uint32_t, uint32_t);
static inline uint32_t hash_boolean(bool x, uint32_t basis);
return hash_2words((uint32_t)(x >> 32), (uint32_t)x);
}
+static inline uint32_t hash_uint64_basis(const uint64_t x,
+ const uint32_t basis)
+{
+ return hash_3words((uint32_t)(x >> 32), (uint32_t)x, basis);
+}
#ifdef __cplusplus
}
#endif
mac_table_hash(const struct mac_learning *ml, const uint8_t mac[ETH_ADDR_LEN],
uint16_t vlan)
{
- unsigned int mac1 = get_unaligned_u32(ALIGNED_CAST(uint32_t *, mac));
- unsigned int mac2 = get_unaligned_u16(ALIGNED_CAST(uint16_t *, mac + 4));
- return hash_3words(mac1, mac2 | (vlan << 16), ml->secret);
+ return hash_mac(mac, vlan, ml->secret);
}
static struct mac_entry *
#include "flow.h"
#include "openvswitch/types.h"
#include "random.h"
+#include "hash.h"
#include "util.h"
struct ofpbuf;
| ((uint64_t) ea[4] << 8)
| ea[5]);
}
+static inline uint64_t eth_addr_vlan_to_uint64(const uint8_t ea[ETH_ADDR_LEN],
+ uint16_t vlan)
+{
+ return (((uint64_t)vlan << 48) | eth_addr_to_uint64(ea));
+}
static inline void eth_addr_from_uint64(uint64_t x, uint8_t ea[ETH_ADDR_LEN])
{
ea[0] = x >> 40;
/* Set the top bit to indicate random Nicira address. */
ea[3] |= 0x80;
}
+static inline uint32_t hash_mac(const uint8_t ea[ETH_ADDR_LEN],
+ const uint16_t vlan, const uint32_t basis)
+{
+ return hash_uint64_basis(eth_addr_vlan_to_uint64(ea, vlan), basis);
+}
bool eth_addr_is_reserved(const uint8_t ea[ETH_ADDR_LEN]);
bool eth_addr_from_string(const char *, uint8_t ea[ETH_ADDR_LEN]);
static unsigned int
bond_hash_src(const uint8_t mac[ETH_ADDR_LEN], uint16_t vlan, uint32_t basis)
{
- return hash_3words(hash_bytes(mac, ETH_ADDR_LEN, 0), vlan, basis);
+ return hash_mac(mac, vlan, basis);
}
static unsigned int
const struct ofputil_bucket *bucket;
uint32_t basis;
- basis = hash_bytes(ctx->xin->flow.dl_dst, sizeof ctx->xin->flow.dl_dst, 0);
+ basis = hash_mac(ctx->xin->flow.dl_dst, 0, 0);
bucket = group_best_live_bucket(ctx, group, basis);
if (bucket) {
memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);