IPv6NeighbourCache.cc

Go to the documentation of this file.
00001 
00020 #include "IPv6NeighbourCache.h"
00021 
00022 
00023 std::ostream& operator<<(std::ostream& os, const IPv6NeighbourCache::Key& e)
00024 {
00025     return os << "if=" << e.interfaceID << " " << e.address; //FIXME try printing interface name
00026 }
00027 
00028 std::ostream& operator<<(std::ostream& os, const IPv6NeighbourCache::Neighbour& e)
00029 {
00030     os << e.macAddress;
00031     if (e.isRouter) os << " ROUTER";
00032     if (e.isDefaultRouter) os << " defaultRtr";
00033     os << " " << IPv6NeighbourCache::stateName(e.reachabilityState);
00034     os << " reachabilityExp:"  << e.reachabilityExpires;
00035     if (e.numProbesSent) os << " probesSent:" << e.numProbesSent;
00036     if (e.isRouter) os << " rtrExp:" << e.routerExpiryTime;
00037     return os;
00038 }
00039 
00040 IPv6NeighbourCache::IPv6NeighbourCache()
00041 {
00042     WATCH_MAP(neighbourMap);
00043 }
00044 
00045 IPv6NeighbourCache::Neighbour *IPv6NeighbourCache::lookup(const IPv6Address& addr, int interfaceID)
00046 {
00047     Key key(addr, interfaceID);
00048     NeighbourMap::iterator i = neighbourMap.find(key);
00049     return i==neighbourMap.end() ? NULL : &(i->second);
00050 }
00051 
00052 const IPv6NeighbourCache::Key *IPv6NeighbourCache::lookupKeyAddr(Key& key)
00053 {
00054     NeighbourMap::iterator i = neighbourMap.find(key);
00055     return &(i->first);
00056 }
00057 
00058 IPv6NeighbourCache::Neighbour *IPv6NeighbourCache::addNeighbour(const IPv6Address& addr, int interfaceID)
00059 {
00060     Key key(addr, interfaceID);
00061     ASSERT(neighbourMap.find(key)==neighbourMap.end()); // entry must not exist yet
00062     Neighbour& nbor = neighbourMap[key];
00063 
00064     nbor.nceKey = lookupKeyAddr(key);//a ptr that links to the key.-WEI for convenience.
00065     nbor.isRouter = false;
00066     nbor.isDefaultRouter = false;
00067     nbor.reachabilityState = INCOMPLETE;
00068     nbor.reachabilityExpires = 0;
00069     nbor.numProbesSent = 0;
00070     nbor.nudTimeoutEvent = NULL;
00071     nbor.numOfARNSSent = 0;
00072     nbor.routerExpiryTime = 0;
00073     return &nbor;
00074 }
00075 
00076 IPv6NeighbourCache::Neighbour *IPv6NeighbourCache::addNeighbour(const IPv6Address& addr, int interfaceID, MACAddress macAddress)
00077 {
00078     Key key(addr, interfaceID);
00079     ASSERT(neighbourMap.find(key)==neighbourMap.end()); // entry must not exist yet
00080     Neighbour& nbor = neighbourMap[key];
00081 
00082     nbor.nceKey = lookupKeyAddr(key);//a ptr that links to the key.-WEI for convenience.
00083     nbor.macAddress = macAddress;
00084     nbor.isRouter = false;
00085     nbor.isDefaultRouter = false;
00086     nbor.reachabilityState = STALE;
00087     nbor.reachabilityExpires = 0;
00088     nbor.numProbesSent = 0;
00089     nbor.nudTimeoutEvent = NULL;
00090     nbor.routerExpiryTime = 0;
00091     return &nbor;
00092 }
00093 
00095 IPv6NeighbourCache::Neighbour *IPv6NeighbourCache::addRouter(const IPv6Address& addr, int interfaceID, simtime_t expiryTime)
00096 {
00097     Key key(addr, interfaceID);
00098     ASSERT(neighbourMap.find(key)==neighbourMap.end()); // entry must not exist yet
00099     Neighbour& nbor = neighbourMap[key];
00100 
00101     nbor.nceKey = lookupKeyAddr(key);//a ptr that links to the key.-WEI for convenience.
00102     nbor.isRouter = true;
00103     nbor.isDefaultRouter = true;//FIXME: a router may advertise itself it self as a router but not as a default one.-WEI
00104     nbor.reachabilityState = INCOMPLETE;
00105     nbor.reachabilityExpires = 0;
00106     nbor.numProbesSent = 0;
00107     nbor.nudTimeoutEvent = NULL;
00108     nbor.routerExpiryTime = expiryTime;
00109     return &nbor;
00110 }
00111 
00113 IPv6NeighbourCache::Neighbour *IPv6NeighbourCache::addRouter(const IPv6Address& addr, int interfaceID, MACAddress macAddress, simtime_t expiryTime)
00114 {
00115     Key key(addr, interfaceID);
00116     ASSERT(neighbourMap.find(key)==neighbourMap.end()); // entry must not exist yet
00117     Neighbour& nbor = neighbourMap[key];
00118 
00119     nbor.nceKey = lookupKeyAddr(key);//a ptr that links to the key.-WEI for convenience.
00120     nbor.macAddress = macAddress;
00121     nbor.isRouter = true;
00122     nbor.isDefaultRouter = true;
00123     nbor.reachabilityState = STALE;
00124     nbor.reachabilityExpires = 0;
00125     nbor.numProbesSent = 0;
00126     nbor.nudTimeoutEvent = NULL;
00127 
00128     nbor.routerExpiryTime = expiryTime;
00129     return &nbor;
00130 }
00131 
00132 void IPv6NeighbourCache::remove(const IPv6Address& addr, int interfaceID)
00133 {
00134     Key key(addr, interfaceID);
00135     NeighbourMap::iterator it = neighbourMap.find(key);
00136     ASSERT(it!=neighbourMap.end()); // entry must exist
00137     delete it->second.nudTimeoutEvent;
00138     neighbourMap.erase(it);
00139 }
00140 
00141 void IPv6NeighbourCache::remove(NeighbourMap::iterator it)
00142 {
00143     delete it->second.nudTimeoutEvent;
00144     neighbourMap.erase(it);
00145 }
00146 
00147 const char *IPv6NeighbourCache::stateName(ReachabilityState state)
00148 {
00149     switch (state)
00150     {
00151         case INCOMPLETE: return "INCOMPLETE";
00152         case REACHABLE:  return "REACHABLE";
00153         case STALE:      return "STALE";
00154         case DELAY:      return "DELAY";
00155         case PROBE:      return "PROBE";
00156         default:         return "???";
00157     }
00158 }
00159