Historic archive of defunct list bloat-devel@lists.bufferbloat.net
 help / color / mirror / Atom feed
* A tiny almost sorta kinda nearly minimal perfect hash for a mac classifier?
@ 2011-11-13 20:43 Dave Taht
  2011-11-14  2:22 ` Sean Conner
  2011-11-15 21:14 ` Sean Conner
  0 siblings, 2 replies; 11+ messages in thread
From: Dave Taht @ 2011-11-13 20:43 UTC (permalink / raw)
  To: bloat-devel

There's this class of non-algorithms where stupid and brute force
nearly works. Then there are the be-all end-all algorithms which scale
beautifully O(1) over n - so long as n is large enough to wipe out the
overhead of the be-all-end-all algorithm, and taking locks, allocating
memory at bad times, etc, is ok.

I keep running into problems where brute force and a simple table
lookup is almost enough.

Here's one. I'd like to classify network streams so that they end up
in a unique queue[x], based on their nexthop mac address in the ip
header.

One of a small number (say, x < 2048) of queues, that needs to be
absolutely unique per mac. It's ok if 99% of the queues
are idle at any given point. It's OK if the initial classification
collides with another mac so long as eventually it doesn't.

Algo needs to be fast and lock free, relying only on a very few atomic
increment and/or swaps, only in rare cases...

On most networks today, you are usually talking to a VERY few
machines. The number of machines that appear and disappear is rather
small and stable over very long periods of time (proof: go type arp -a
on your home network)

Yet mac addresses are 48 bits wide.

Even in the case of an access point, you are never going to see more
than 2048 of them, and most APs stop at around 127 stations, and most
wireless networks have many fewer endpoints than that...

So great, I figure a mere 2 bin table lookup and random replacement
will work fine, I stuck my first attempt up at
http://www.teklibre.com/~d/mactoclass.c

and I hate it. Didn't get so far as writing garbage collection.
(double buffer it) Does anything elegant exist? Anything worthy in the
kernel?

-- 
Dave Täht
SKYPE: davetaht
US Tel: 1-239-829-5608
FR Tel: 0638645374
http://www.bufferbloat.net

^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: A tiny almost sorta kinda nearly minimal perfect hash for a mac classifier?
@ 2011-11-14  8:20 Sean Conner
  0 siblings, 0 replies; 11+ messages in thread
From: Sean Conner @ 2011-11-14  8:20 UTC (permalink / raw)
  To: bloat-devel

It was thus said that the Great Dave Taht once stated:
> On Mon, Nov 14, 2011 at 3:41 AM, Fred Baker <fred@cisco.com> wrote:
> >
> > On Nov 14, 2011, at 10:22 AM, Sean Conner wrote:
> >
> >> �Why not just use the lower N bits as the hash function?
> >
> > or
> >
> > unsigned macHash (unsigned long long �macAddressClone) {
> > � � return 0xFFF & (macAddressClone ^ (macAddressClone >> 12));
> > }
> >
> > That allows you to keep different OUIs separated somewhat.
> 
> I should probably not have used 'arp' as an example, but suggested tcpdump.
> 
> Multicast and broadcast on 802.11 are 'special'. They are always
> transmitted at the lowest rate possible (and eat up correspondingly
> far more airtime), and in the case of power save mode, can be deferred
> up to 200 ms, to wait for stations to be awake enough to 'hear' them.
> So anything with the multicast mac bit set should end up dumped in a
> special queue to manage that better.
> 
> Virtual interfaces on a given radio twiddle on the local mac bit and
> then do arbitrary transforms elsewhere on the mac

  The format for a MAC address is:

+--------+--------+--------+--------+--------+--------+
|      lg|        |        |        |        |        |
+--------+--------+--------+--------+--------+--------+
\______||____OUI___________/
       ||
       |+-- group/individual bit (1 = multicast/broadcast)
       +--- global/local assigned address (1 = local)

Given that, I would then write the hash code as:

typdef union macaddr
{
  uint8_t  bit8[6];
  uint16_t bit16[3];
} macaddr__t;

typedef enum macqueue
{
  MACQ_NORMAL,
  MACQ_SPECIAL
} macqueue__t;

macqueue__t mac_hash(unsigned int *phash,macaddr__t addr)
{
  *phash = addr.bit16[2] & 0x0FFF;
  if (addr.bit8[0] & 0x01)
    return MACQ_SPECIAL;
  else
    return MACQ_NORMAL;
  /*------------
  ; if I was very concerned with speed, I would do:
  ;     return addr.bit8[0] & 0x01;
  ; but I opted for clarity here, not speed
  ;---------------*/
}

The broadcast MAC address is FF:FF:FF:FF:FF:FF while a multicast MAC address
is based off the IP multicast address, but the global bit is set, for
example: 01:00:5E:7F:00:01.  This way, if you want to set
broadcasts/multicasts on their own special queue, you can (heck, you can
even have a separate hash table for them given this).  I don't see how
locally defined addresses will mess this up, unless I see actual, real world
evidence.  

  -spc (Measure twice, cut once and all that ... )


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-11-15 22:20 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-13 20:43 A tiny almost sorta kinda nearly minimal perfect hash for a mac classifier? Dave Taht
2011-11-14  2:22 ` Sean Conner
2011-11-14  2:41   ` Fred Baker
2011-11-14  7:44     ` Dave Taht
2011-11-14  8:13       ` Sean Conner
2011-11-14  8:21   ` Dave Taht
2011-11-15 21:14 ` Sean Conner
2011-11-15 21:44   ` Jonathan Morton
2011-11-15 22:19     ` Dave Taht
2011-11-15 22:20       ` Dave Taht
2011-11-14  8:20 Sean Conner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox