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< Packet * > 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

◆ MsgPtrVector

◆ NeighbourMap

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

Member Enumeration Documentation

◆ ReachabilityState

Neighbour's reachability state.

Enumerator
INCOMPLETE 
REACHABLE 
STALE 
DELAY 
PROBE 

Constructor & Destructor Documentation

◆ Ipv6NeighbourCache()

inet::Ipv6NeighbourCache::Ipv6NeighbourCache ( cSimpleModule &  neighbourDiscovery)
72 {
73  WATCH_MAP(neighbourMap);
74 }

◆ ~Ipv6NeighbourCache()

virtual inet::Ipv6NeighbourCache::~Ipv6NeighbourCache ( )
inlinevirtual
151 {}

Member Function Documentation

◆ addNeighbour() [1/2]

Ipv6NeighbourCache::Neighbour * inet::Ipv6NeighbourCache::addNeighbour ( const Ipv6Address addr,
int  interfaceID 
)
virtual

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

90 {
91  Key key(addr, interfaceID);
92  ASSERT(!containsKey(neighbourMap, key)); // entry must not exist yet
93  Neighbour& nbor = neighbourMap[key];
94 
95  nbor.nceKey = lookupKeyAddr(key);
96  nbor.isRouter = false;
97  nbor.isHomeAgent = false;
98  nbor.reachabilityState = INCOMPLETE;
99  return &nbor;
100 }

Referenced by inet::Ipv6NeighbourDiscovery::processIpv6Datagram(), inet::Ipv6NeighbourDiscovery::processNsWithSpecifiedSrcAddr(), and inet::Ipv6NeighbourDiscovery::processRaForRouterUpdates().

◆ addNeighbour() [2/2]

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.

103 {
104  Key key(addr, interfaceID);
105  ASSERT(!containsKey(neighbourMap, key)); // entry must not exist yet
106  Neighbour& nbor = neighbourMap[key];
107 
108  nbor.nceKey = lookupKeyAddr(key);
109  nbor.macAddress = macAddress;
110  nbor.isRouter = false;
111  nbor.isHomeAgent = false;
112  nbor.reachabilityState = STALE;
113  return &nbor;
114 }

◆ addRouter()

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.

123 {
124  Key key(addr, interfaceID);
125  ASSERT(!containsKey(neighbourMap, key)); // entry must not exist yet
126  Neighbour& nbor = neighbourMap[key];
127 
128  nbor.nceKey = lookupKeyAddr(key);
129  nbor.macAddress = macAddress;
130  nbor.isRouter = true;
131  nbor.isHomeAgent = isHomeAgent;
132  nbor.reachabilityState = STALE;
133  nbor.routerExpiryTime = expiryTime;
134 
135  defaultRouterList.add(nbor);
136 
137  return &nbor;
138 }

Referenced by inet::Ipv6NeighbourDiscovery::processRaForRouterUpdates().

◆ begin()

NeighbourMap::iterator inet::Ipv6NeighbourCache::begin ( )
inline

For iteration on the internal std::map.

162 { return neighbourMap.begin(); }

◆ end()

NeighbourMap::iterator inet::Ipv6NeighbourCache::end ( )
inline

For iteration on the internal std::map.

165 { return neighbourMap.end(); }

◆ getDefaultRouterList()

◆ invalidateAllEntries()

void inet::Ipv6NeighbourCache::invalidateAllEntries ( )
virtual

Set status of all neighbours to state PROBE.

171 {
172  while (!neighbourMap.empty()) {
173  auto it = neighbourMap.begin();
174  remove(it);
175  }
177 
178  /*
179  int size = neighbourMap.size();
180  EV << "size: " << size << endl;
181  for (auto it = neighbourMap.begin(); it != neighbourMap.end(); it++)
182  {
183  it->second.reachabilityState = PROBE; // we make sure this neighbour is not used anymore in the future, unless reachability can be confirmed
184  }
185  */
186 }

◆ invalidateEntriesForInterfaceID()

void inet::Ipv6NeighbourCache::invalidateEntriesForInterfaceID ( int  interfaceID)
virtual

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

159 {
160  for (auto& elem : neighbourMap) {
161  if (elem.first.interfaceID == interfaceID) {
162  elem.second.reachabilityState = PROBE; // we make sure this neighbour is not used anymore in the future, unless reachability can be confirmed
163  neighbourDiscovery.cancelAndDelete(elem.second.nudTimeoutEvent); // 20.9.07 - CB
164  elem.second.nudTimeoutEvent = nullptr;
165  }
166  }
167 }

◆ lookup()

Ipv6NeighbourCache::Neighbour * inet::Ipv6NeighbourCache::lookup ( const Ipv6Address addr,
int  interfaceID 
)
virtual

◆ lookupKeyAddr()

const Ipv6NeighbourCache::Key * inet::Ipv6NeighbourCache::lookupKeyAddr ( Key key)
virtual

Experimental code.

84 {
85  auto i = neighbourMap.find(key);
86  return &(i->first);
87 }

Referenced by addNeighbour(), and addRouter().

◆ remove() [1/2]

void inet::Ipv6NeighbourCache::remove ( const Ipv6Address addr,
int  interfaceID 
)
virtual

Deletes the given neighbour from the cache.

141 {
142  Key key(addr, interfaceID);
143  auto it = neighbourMap.find(key);
144  ASSERT(it != neighbourMap.end()); // entry must exist
145  remove(it);
146 }

Referenced by inet::Ipv6NeighbourDiscovery::dropQueuedPacketsAwaitingAr(), invalidateAllEntries(), inet::Ipv6NeighbourDiscovery::processNudTimeout(), inet::Ipv6NeighbourDiscovery::selectDefaultRouter(), and inet::Ipv6NeighbourDiscovery::timeoutDefaultRouter().

◆ remove() [2/2]

void inet::Ipv6NeighbourCache::remove ( NeighbourMap::iterator  it)
virtual

Deletes the given neighbour from the cache.

149 {
150  neighbourDiscovery.cancelAndDelete(it->second.nudTimeoutEvent); // 20.9.07 - CB
151  it->second.nudTimeoutEvent = nullptr;
152  if (it->second.isDefaultRouter())
153  defaultRouterList.remove(it->second);
154  neighbourMap.erase(it);
155 }

◆ stateName()

const char * inet::Ipv6NeighbourCache::stateName ( ReachabilityState  state)
static

Returns the name of the given state as string.

189 {
190  switch (state) {
191  case INCOMPLETE:
192  return "INCOMPLETE";
193 
194  case REACHABLE:
195  return "REACHABLE";
196 
197  case STALE:
198  return "STALE";
199 
200  case DELAY:
201  return "DELAY";
202 
203  case PROBE:
204  return "PROBE";
205 
206  default:
207  return "???";
208  }
209 }

Referenced by inet::operator<<().

Member Data Documentation

◆ defaultRouterList

DefaultRouterList inet::Ipv6NeighbourCache::defaultRouterList
protected

◆ neighbourDiscovery

cSimpleModule& inet::Ipv6NeighbourCache::neighbourDiscovery
protected

◆ neighbourMap


The documentation for this class was generated from the following files:
inet::Ipv6NeighbourCache::DefaultRouterList::add
void add(Neighbour &router)
Definition: Ipv6NeighbourCache.cc:14
inet::Ipv6NeighbourCache::defaultRouterList
DefaultRouterList defaultRouterList
Definition: Ipv6NeighbourCache.h:147
inet::Ipv6NeighbourCache::INCOMPLETE
@ INCOMPLETE
Definition: Ipv6NeighbourCache.h:41
inet::Ipv6NeighbourCache::PROBE
@ PROBE
Definition: Ipv6NeighbourCache.h:41
inet::Ipv6NeighbourCache::remove
virtual void remove(const Ipv6Address &addr, int interfaceID)
Deletes the given neighbour from the cache.
Definition: Ipv6NeighbourCache.cc:140
inet::Ipv6NeighbourCache::DefaultRouterList::clear
void clear()
Definition: Ipv6NeighbourCache.h:135
inet::Ipv6NeighbourCache::STALE
@ STALE
Definition: Ipv6NeighbourCache.h:41
inet::Ipv6NeighbourCache::REACHABLE
@ REACHABLE
Definition: Ipv6NeighbourCache.h:41
inet::Ipv6NeighbourCache::lookupKeyAddr
virtual const Key * lookupKeyAddr(Key &key)
Experimental code.
Definition: Ipv6NeighbourCache.cc:83
inet::Ipv6NeighbourCache::DELAY
@ DELAY
Definition: Ipv6NeighbourCache.h:41
inet::Ipv6NeighbourCache::DefaultRouterList::remove
void remove(Neighbour &router)
Definition: Ipv6NeighbourCache.cc:32
inet::Ipv6NeighbourCache::neighbourMap
NeighbourMap neighbourMap
Definition: Ipv6NeighbourCache.h:146
inet::Macho::Key
void * Key
Definition: Macho.h:327
inet::Ipv6NeighbourCache::neighbourDiscovery
cSimpleModule & neighbourDiscovery
Definition: Ipv6NeighbourCache.h:145
inet::containsKey
bool containsKey(const std::map< K, V, _C > &m, const Tk &a)
Definition: stlutils.h:80