#include <IPv6NeighbourCache.h>
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this program; if not, see <http://www.gnu.org/licenses/>. IPv6 Neighbour Cache (RFC 2461 Neighbor Discovery for IPv6). Used internally by the IPv6NeighbourDiscovery simple module.
This is just a plain container class -- the IPv6NeighbourDiscovery module is free to manipulate the contents of the Neighbour entries as it pleases.
NOTE: we don't keep a separate Default Router List, the Neighbour Cache serves that purpose too. Removing an entry from the Default Router List in our case is done by setting the isDefaultRouter flag of the entry to false.
Public Types | |
enum | ReachabilityState { INCOMPLETE, REACHABLE, STALE, DELAY, PROBE } |
typedef std::vector< cMessage * > | MsgPtrVector |
typedef std::map< Key, Neighbour > | NeighbourMap |
typedef NeighbourMap::iterator | iterator |
Public Member Functions | |
IPv6NeighbourCache () | |
virtual | ~IPv6NeighbourCache () |
virtual Neighbour * | lookup (const IPv6Address &addr, int interfaceID) |
virtual const Key * | lookupKeyAddr (Key &key) |
iterator | begin () |
iterator | end () |
virtual Neighbour * | addNeighbour (const IPv6Address &addr, int interfaceID) |
virtual Neighbour * | addNeighbour (const IPv6Address &addr, int interfaceID, MACAddress macAddress) |
virtual Neighbour * | addRouter (const IPv6Address &addr, int interfaceID, simtime_t expiryTime) |
virtual Neighbour * | addRouter (const IPv6Address &addr, int interfaceID, MACAddress macAddress, simtime_t expiryTime) |
virtual void | remove (const IPv6Address &addr, int interfaceID) |
virtual void | remove (NeighbourMap::iterator it) |
Static Public Member Functions | |
static const char * | stateName (ReachabilityState state) |
Protected Attributes | |
NeighbourMap | neighbourMap |
Classes | |
struct | Key |
struct | Neighbour |
typedef std::vector<cMessage*> IPv6NeighbourCache::MsgPtrVector |
typedef std::map<Key,Neighbour> IPv6NeighbourCache::NeighbourMap |
The std::map underlying the Neighbour Cache data structure
typedef NeighbourMap::iterator IPv6NeighbourCache::iterator |
IPv6NeighbourCache::IPv6NeighbourCache | ( | ) |
IPv6NeighbourCache::Neighbour * IPv6NeighbourCache::lookup | ( | const IPv6Address & | addr, | |
int | interfaceID | |||
) | [virtual] |
Returns a neighbour entry, or NULL.
Referenced by IPv6NeighbourDiscovery::processIPv6Datagram(), IPv6NeighbourDiscovery::processNAPacket(), IPv6NeighbourDiscovery::processNSWithSpecifiedSrcAddr(), IPv6NeighbourDiscovery::processRAForRouterUpdates(), IPv6NeighbourDiscovery::reachabilityConfirmed(), and IPv6NeighbourDiscovery::resolveNeighbour().
00046 { 00047 Key key(addr, interfaceID); 00048 NeighbourMap::iterator i = neighbourMap.find(key); 00049 return i==neighbourMap.end() ? NULL : &(i->second); 00050 }
const IPv6NeighbourCache::Key * IPv6NeighbourCache::lookupKeyAddr | ( | Key & | key | ) | [virtual] |
Experimental code.
Referenced by addNeighbour(), and addRouter().
00053 { 00054 NeighbourMap::iterator i = neighbourMap.find(key); 00055 return &(i->first); 00056 }
iterator IPv6NeighbourCache::begin | ( | ) | [inline] |
For iteration on the internal std::map
Referenced by IPv6NeighbourDiscovery::selectDefaultRouter().
00124 {return neighbourMap.begin();}
iterator IPv6NeighbourCache::end | ( | ) | [inline] |
For iteration on the internal std::map
Referenced by IPv6NeighbourDiscovery::selectDefaultRouter().
00127 {return neighbourMap.end();}
IPv6NeighbourCache::Neighbour * IPv6NeighbourCache::addNeighbour | ( | const IPv6Address & | addr, | |
int | interfaceID | |||
) | [virtual] |
Creates and initializes a neighbour entry with isRouter=false, state=INCOMPLETE.
Referenced by IPv6NeighbourDiscovery::processIPv6Datagram(), IPv6NeighbourDiscovery::processNSWithSpecifiedSrcAddr(), and IPv6NeighbourDiscovery::processRAForRouterUpdates().
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 }
IPv6NeighbourCache::Neighbour * IPv6NeighbourCache::addNeighbour | ( | const IPv6Address & | addr, | |
int | interfaceID, | |||
MACAddress | macAddress | |||
) | [virtual] |
Creates and initializes a neighbour entry with isRouter=false, MAC address and state=STALE.
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 }
IPv6NeighbourCache::Neighbour * IPv6NeighbourCache::addRouter | ( | const IPv6Address & | addr, | |
int | interfaceID, | |||
simtime_t | expiryTime | |||
) | [virtual] |
Creates and initializes a router entry (isRouter=isDefaultRouter=true), state=INCOMPLETE.
Referenced by IPv6NeighbourDiscovery::processRAForRouterUpdates().
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 }
IPv6NeighbourCache::Neighbour * IPv6NeighbourCache::addRouter | ( | const IPv6Address & | addr, | |
int | interfaceID, | |||
MACAddress | macAddress, | |||
simtime_t | expiryTime | |||
) | [virtual] |
Creates and initializes a router entry (isRouter=isDefaultRouter=true), MAC address and state=STALE.
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 }
void IPv6NeighbourCache::remove | ( | const IPv6Address & | addr, | |
int | interfaceID | |||
) | [virtual] |
Deletes the given neighbour from the cache.
Referenced by IPv6NeighbourDiscovery::dropQueuedPacketsAwaitingAR(), IPv6NeighbourDiscovery::processNUDTimeout(), IPv6NeighbourDiscovery::selectDefaultRouter(), and IPv6NeighbourDiscovery::timeoutDefaultRouter().
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 }
void IPv6NeighbourCache::remove | ( | NeighbourMap::iterator | it | ) | [virtual] |
Deletes the given neighbour from the cache.
00142 { 00143 delete it->second.nudTimeoutEvent; 00144 neighbourMap.erase(it); 00145 }
const char * IPv6NeighbourCache::stateName | ( | ReachabilityState | state | ) | [static] |
Returns the name of the given state as string
Referenced by operator<<().
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 }
NeighbourMap IPv6NeighbourCache::neighbourMap [protected] |
Referenced by addNeighbour(), addRouter(), IPv6NeighbourCache(), lookup(), lookupKeyAddr(), and remove().