📄 aliastable.cc
字号:
#include <click/config.h>#include <click/confparse.hh>#include <click/error.hh>#include <click/glue.hh>#include <click/straccum.hh>#include <click/timestamp.hh>#include <click/string.hh>#include <clicknet/ether.h>#include "aliastable.hh"CLICK_DECLS#define FNV1_32_INIT ((uint32_t)0x811c9dc5)#define FNV_32_PRIME ((uint32_t)0x01000193)#define MASK_16 (((uint32_t)1<<16)-1)#define MASK_8 (((uint32_t)1<<8)-1)AliasTable::AliasTable() : Element(0,0){ uint8_t data[6]; memset(data, 0xFF, sizeof(uint8_t)*6); _bcast = EtherAddress(data);}AliasTable::~AliasTable(){}const EtherAddress &AliasTable::get_random_neighbor(const EtherAddress& myea) { for (AliasTableType::const_iterator i=_alias_table.begin(); i!=_alias_table.end(); i++) { if (i.key()!= myea) { return i.key(); } } return _bcast;}void *AliasTable::cast(const char *n){ if (strcmp(n, "AliasTable") == 0) return (AliasTable *) this; else return 0;}uint8_tAliasTable::lookup(const EtherAddress& addr) { uint8_t nbid; StringAccum sa; sa << addr << ' '; nbid = _alias_table.find(addr); if (nbid) return nbid; nbid = gen_alias(addr); _alias_table.insert(addr, nbid); _alias_table_rev.insert(nbid, addr); return nbid;}unsigned char*AliasTable::lookup_addr(uint8_t nbid) { EtherAddress addr = _alias_table_rev.find(nbid); return addr.data();}uint8_t AliasTable::gen_alias(EtherAddress addr){ return hashint(addr);}uint8_t hashint(const EtherAddress& addr) { const unsigned char *d = addr.data(); uint32_t hval = FNV1_32_INIT; int i = 0; while(i < 6) { hval *= FNV_32_PRIME; hval ^= (uint32_t)(*d++); i++; } hval = (hval>>8) ^ (hval&MASK_8); return (uint8_t)hval;}#include <click/bighashmap.cc>#include <click/vector.cc>#if EXPLICIT_TEMPLATE_INSTANCEStemplate class HashMap<EtherAddress, uint8_t>;#endifCLICK_ENDDECLSEXPORT_ELEMENT(AliasTable)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -