INET Framework for OMNeT++/OMNEST
inet::IPv6NeighbourCache Class Reference

IPv6 Neighbour Cache (RFC 2461 Neighbor Discovery for IPv6). More...

#include <IPv6NeighbourCache.h>

Classes

class  DefaultRouterList
 
struct  Key
 Key into neighbour cache. More...
 
struct  Neighbour
 Stores a neighbour (or router) entry. More...
 

Public Types

enum  ReachabilityState {
  INCOMPLETE, REACHABLE, STALE, DELAY,
  PROBE
}
 Neighbour's reachability state. More...
 
typedef std::vector< cMessage * > MsgPtrVector
 
typedef std::map< Key, NeighbourNeighbourMap
 The std::map underlying the Neighbour Cache data structure. More...
 

Public Member Functions

 IPv6NeighbourCache (cSimpleModule &neighbourDiscovery)
 
virtual ~IPv6NeighbourCache ()
 
virtual Neighbourlookup (const IPv6Address &addr, int interfaceID)
 Returns a neighbour entry, or nullptr. More...
 
virtual const KeylookupKeyAddr (Key &key)
 Experimental code. More...
 
DefaultRouterListgetDefaultRouterList ()
 
NeighbourMap::iterator begin ()
 For iteration on the internal std::map. More...
 
NeighbourMap::iterator end ()
 For iteration on the internal std::map. More...
 
virtual NeighbouraddNeighbour (const IPv6Address &addr, int interfaceID)
 Creates and initializes a neighbour entry with isRouter=false, state=INCOMPLETE. More...
 
virtual NeighbouraddNeighbour (const IPv6Address &addr, int interfaceID, MACAddress macAddress)
 Creates and initializes a neighbour entry with isRouter=false, MAC address and state=STALE. More...
 
virtual NeighbouraddRouter (const IPv6Address &addr, int interfaceID, MACAddress macAddress, simtime_t expiryTime, bool isHomeAgent=false)
 Creates and initializes a router entry (isRouter=isDefaultRouter=true), MAC address and state=STALE. More...
 
virtual void remove (const IPv6Address &addr, int interfaceID)
 Deletes the given neighbour from the cache. More...
 
virtual void invalidateEntriesForInterfaceID (int interfaceID)
 Set status of all neighbours on given interface to state PROBE. More...
 
virtual void invalidateAllEntries ()
 Set status of all neighbours to state PROBE. More...
 
virtual void remove (NeighbourMap::iterator it)
 Deletes the given neighbour from the cache. More...
 

Static Public Member Functions

static const char * stateName (ReachabilityState state)
 Returns the name of the given state as string. More...
 

Protected Attributes

cSimpleModule & neighbourDiscovery
 
NeighbourMap neighbourMap
 
DefaultRouterList defaultRouterList
 

Detailed Description

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: IPv6NeighbourCache also stores the Default Router List. A router becomes a default router by calling getDefaultRouterList().add(router) and stops to be a default router after getDefaultRouterList().remove(router) has been called. References to default routers are stored in a circular list to ease round-robin selection.

Member Typedef Documentation

typedef std::vector<cMessage *> inet::IPv6NeighbourCache::MsgPtrVector

The std::map underlying the Neighbour Cache data structure.

Member Enumeration Documentation

Neighbour's reachability state.

Enumerator
INCOMPLETE 
REACHABLE 
STALE 
DELAY 
PROBE 
Definition: IPv6NeighbourCache.h:53
Definition: IPv6NeighbourCache.h:53
Definition: IPv6NeighbourCache.h:53
Definition: IPv6NeighbourCache.h:53
Definition: IPv6NeighbourCache.h:53

Constructor & Destructor Documentation

inet::IPv6NeighbourCache::IPv6NeighbourCache ( cSimpleModule &  neighbourDiscovery)
81 {
82  WATCH_MAP(neighbourMap);
83 }
NeighbourMap neighbourMap
Definition: IPv6NeighbourCache.h:162
cSimpleModule & neighbourDiscovery
Definition: IPv6NeighbourCache.h:161
virtual inet::IPv6NeighbourCache::~IPv6NeighbourCache ( )
inlinevirtual
167 {}

Member Function Documentation

IPv6NeighbourCache::Neighbour * inet::IPv6NeighbourCache::addNeighbour ( const IPv6Address addr,
int  interfaceID 
)
virtual

Creates and initializes a neighbour entry with isRouter=false, state=INCOMPLETE.

Referenced by inet::IPv6NeighbourDiscovery::processIPv6Datagram(), inet::IPv6NeighbourDiscovery::processNSWithSpecifiedSrcAddr(), and inet::IPv6NeighbourDiscovery::processRAForRouterUpdates().

99 {
100  Key key(addr, interfaceID);
101  ASSERT(neighbourMap.find(key) == neighbourMap.end()); // entry must not exist yet
102  Neighbour& nbor = neighbourMap[key];
103 
104  nbor.nceKey = lookupKeyAddr(key);
105  nbor.isRouter = false;
106  nbor.isHomeAgent = false;
107  nbor.reachabilityState = INCOMPLETE;
108  return &nbor;
109 }
NeighbourMap neighbourMap
Definition: IPv6NeighbourCache.h:162
virtual const Key * lookupKeyAddr(Key &key)
Experimental code.
Definition: IPv6NeighbourCache.cc:92
Definition: IPv6NeighbourCache.h:53
void * Key
Definition: Macho.h:325
IPv6NeighbourCache::Neighbour * inet::IPv6NeighbourCache::addNeighbour ( const IPv6Address addr,
int  interfaceID,
MACAddress  macAddress 
)
virtual

Creates and initializes a neighbour entry with isRouter=false, MAC address and state=STALE.

112 {
113  Key key(addr, interfaceID);
114  ASSERT(neighbourMap.find(key) == neighbourMap.end()); // entry must not exist yet
115  Neighbour& nbor = neighbourMap[key];
116 
117  nbor.nceKey = lookupKeyAddr(key);
118  nbor.macAddress = macAddress;
119  nbor.isRouter = false;
120  nbor.isHomeAgent = false;
121  nbor.reachabilityState = STALE;
122  return &nbor;
123 }
NeighbourMap neighbourMap
Definition: IPv6NeighbourCache.h:162
virtual const Key * lookupKeyAddr(Key &key)
Experimental code.
Definition: IPv6NeighbourCache.cc:92
Definition: IPv6NeighbourCache.h:53
void * Key
Definition: Macho.h:325
IPv6NeighbourCache::Neighbour * inet::IPv6NeighbourCache::addRouter ( const IPv6Address addr,
int  interfaceID,
MACAddress  macAddress,
simtime_t  expiryTime,
bool  isHomeAgent = false 
)
virtual

Creates and initializes a router entry (isRouter=isDefaultRouter=true), MAC address and state=STALE.

Update by CB: Added an optional parameter which is false by default. Specifies whether a router is also a home agent.

Referenced by inet::IPv6NeighbourDiscovery::processRAForRouterUpdates().

132 {
133  Key key(addr, interfaceID);
134  ASSERT(neighbourMap.find(key) == neighbourMap.end()); // entry must not exist yet
135  Neighbour& nbor = neighbourMap[key];
136 
137  nbor.nceKey = lookupKeyAddr(key);
138  nbor.macAddress = macAddress;
139  nbor.isRouter = true;
140  nbor.isHomeAgent = isHomeAgent;
141  nbor.reachabilityState = STALE;
142  nbor.routerExpiryTime = expiryTime;
143 
144  defaultRouterList.add(nbor);
145 
146  return &nbor;
147 }
void add(Neighbour &router)
Definition: IPv6NeighbourCache.cc:23
NeighbourMap neighbourMap
Definition: IPv6NeighbourCache.h:162
DefaultRouterList defaultRouterList
Definition: IPv6NeighbourCache.h:163
virtual const Key * lookupKeyAddr(Key &key)
Experimental code.
Definition: IPv6NeighbourCache.cc:92
Definition: IPv6NeighbourCache.h:53
void * Key
Definition: Macho.h:325
NeighbourMap::iterator inet::IPv6NeighbourCache::begin ( )
inline

For iteration on the internal std::map.

Referenced by inet::IPv6NeighbourDiscovery::routersUnreachabilityDetection().

178 { return neighbourMap.begin(); }
NeighbourMap neighbourMap
Definition: IPv6NeighbourCache.h:162
NeighbourMap::iterator inet::IPv6NeighbourCache::end ( )
inline

For iteration on the internal std::map.

Referenced by inet::IPv6NeighbourDiscovery::routersUnreachabilityDetection().

181 { return neighbourMap.end(); }
NeighbourMap neighbourMap
Definition: IPv6NeighbourCache.h:162
DefaultRouterList& inet::IPv6NeighbourCache::getDefaultRouterList ( )
inline
void inet::IPv6NeighbourCache::invalidateAllEntries ( )
virtual

Set status of all neighbours to state PROBE.

Referenced by inet::IPv6NeighbourDiscovery::invalidateNeigbourCache().

180 {
181  while (!neighbourMap.empty()) {
182  auto it = neighbourMap.begin();
183  remove(it);
184  }
186 
187  /*
188  int size = neighbourMap.size();
189  EV << "size: " << size << endl;
190  for (auto it = neighbourMap.begin(); it != neighbourMap.end(); it++)
191  {
192  it->second.reachabilityState = PROBE; // we make sure this neighbour is not used anymore in the future, unless reachability can be confirmed
193  }
194  */
195 }
NeighbourMap neighbourMap
Definition: IPv6NeighbourCache.h:162
DefaultRouterList defaultRouterList
Definition: IPv6NeighbourCache.h:163
void clear()
Definition: IPv6NeighbourCache.h:151
void inet::IPv6NeighbourCache::invalidateEntriesForInterfaceID ( int  interfaceID)
virtual

Set status of all neighbours on given interface to state PROBE.

168 {
169  for (auto & elem : neighbourMap) {
170  if (elem.first.interfaceID == interfaceID) {
171  elem.second.reachabilityState = PROBE; // we make sure this neighbour is not used anymore in the future, unless reachability can be confirmed
172  neighbourDiscovery.cancelAndDelete(elem.second.nudTimeoutEvent); // 20.9.07 - CB
173  elem.second.nudTimeoutEvent = nullptr;
174  }
175  }
176 }
Definition: IPv6NeighbourCache.h:53
NeighbourMap neighbourMap
Definition: IPv6NeighbourCache.h:162
cSimpleModule & neighbourDiscovery
Definition: IPv6NeighbourCache.h:161
IPv6NeighbourCache::Neighbour * inet::IPv6NeighbourCache::lookup ( const IPv6Address addr,
int  interfaceID 
)
virtual

Returns a neighbour entry, or nullptr.

Referenced by inet::IPv6NeighbourDiscovery::processIPv6Datagram(), inet::IPv6NeighbourDiscovery::processNAPacket(), inet::IPv6NeighbourDiscovery::processNSWithSpecifiedSrcAddr(), inet::IPv6NeighbourDiscovery::processRAForRouterUpdates(), inet::IPv6NeighbourDiscovery::reachabilityConfirmed(), and inet::IPv6NeighbourDiscovery::resolveNeighbour().

86 {
87  Key key(addr, interfaceID);
88  auto i = neighbourMap.find(key);
89  return i == neighbourMap.end() ? nullptr : &(i->second);
90 }
NeighbourMap neighbourMap
Definition: IPv6NeighbourCache.h:162
void * Key
Definition: Macho.h:325
const IPv6NeighbourCache::Key * inet::IPv6NeighbourCache::lookupKeyAddr ( Key key)
virtual

Experimental code.

Referenced by addNeighbour(), and addRouter().

93 {
94  auto i = neighbourMap.find(key);
95  return &(i->first);
96 }
NeighbourMap neighbourMap
Definition: IPv6NeighbourCache.h:162
void inet::IPv6NeighbourCache::remove ( const IPv6Address addr,
int  interfaceID 
)
virtual

Deletes the given neighbour from the cache.

Referenced by inet::IPv6NeighbourDiscovery::dropQueuedPacketsAwaitingAR(), inet::IPv6NeighbourDiscovery::processNUDTimeout(), inet::IPv6NeighbourDiscovery::selectDefaultRouter(), and inet::IPv6NeighbourDiscovery::timeoutDefaultRouter().

150 {
151  Key key(addr, interfaceID);
152  auto it = neighbourMap.find(key);
153  ASSERT(it != neighbourMap.end()); // entry must exist
154  remove(it);
155 }
NeighbourMap neighbourMap
Definition: IPv6NeighbourCache.h:162
void * Key
Definition: Macho.h:325
void inet::IPv6NeighbourCache::remove ( NeighbourMap::iterator  it)
virtual

Deletes the given neighbour from the cache.

158 {
159  neighbourDiscovery.cancelAndDelete(it->second.nudTimeoutEvent); // 20.9.07 - CB
160  it->second.nudTimeoutEvent = nullptr;
161  if (it->second.isDefaultRouter())
162  defaultRouterList.remove(it->second);
163  neighbourMap.erase(it);
164 }
NeighbourMap neighbourMap
Definition: IPv6NeighbourCache.h:162
DefaultRouterList defaultRouterList
Definition: IPv6NeighbourCache.h:163
void remove(Neighbour &router)
Definition: IPv6NeighbourCache.cc:41
cSimpleModule & neighbourDiscovery
Definition: IPv6NeighbourCache.h:161
const char * inet::IPv6NeighbourCache::stateName ( ReachabilityState  state)
static

Returns the name of the given state as string.

Referenced by inet::operator<<().

198 {
199  switch (state) {
200  case INCOMPLETE:
201  return "INCOMPLETE";
202 
203  case REACHABLE:
204  return "REACHABLE";
205 
206  case STALE:
207  return "STALE";
208 
209  case DELAY:
210  return "DELAY";
211 
212  case PROBE:
213  return "PROBE";
214 
215  default:
216  return "???";
217  }
218 }
Definition: IPv6NeighbourCache.h:53
Definition: IPv6NeighbourCache.h:53
Definition: IPv6NeighbourCache.h:53
Definition: IPv6NeighbourCache.h:53
Definition: IPv6NeighbourCache.h:53

Member Data Documentation

DefaultRouterList inet::IPv6NeighbourCache::defaultRouterList
protected
cSimpleModule& inet::IPv6NeighbourCache::neighbourDiscovery
protected

The documentation for this class was generated from the following files: