[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

suggestion on hash function in sfq.cc



Hi,

The hash function SFQ::hash() as used in sfq.cc is a very
dangerous way to do hashing. We can't just "add" two addresses
and then do some shift etc. operations (infinte combinations
giving same k):

int ALQD::hash(Packet* pkt)
{
  hdr_ip* iph = (hdr_ip*)pkt->access(off_ip_);
  
  int i = (int)iph->src();
  int j = (int)iph->dst();
  int k = i + j;
  return (k + (k >> 8) + ~(k >> 4)) % ((2<<19)-1); // modulo a large
prime
}

My suggestion:
Why don't take simply the flow id from the packet header?

{
  hdr_ip* iph = (hdr_ip*)pkt->access(off_ip_);
  return(iph->flowid());
}


This suggestion holds for drr.cc too.

Roman