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

Class holding informatation about neighboring PIM routers. More...

#include <PimNeighborTable.h>

Inheritance diagram for inet::PimNeighborTable:

Public Types

enum  TimerKind { NeighborLivenessTimer = 1 }
 

Public Member Functions

virtual ~PimNeighborTable ()
 
virtual bool addNeighbor (PimNeighbor *neighbor, double holdTime)
 Adds the a neighbor to the table. More...
 
virtual bool deleteNeighbor (PimNeighbor *neighbor)
 Deletes a neighbor from the table. More...
 
virtual void restartLivenessTimer (PimNeighbor *neighbor, double holdTime)
 Restarts the Neighbor Liveness timer of the given neighbor. More...
 
virtual PimNeighborfindNeighbor (int interfaceId, Ipv4Address addr)
 Returns the neighbor that is identified by the given (interfaceId,addr), or nullptr if no such neighbor. More...
 
virtual int getNumNeighbors (int interfaceId)
 Returns the number of neighbors on the given interface. More...
 
virtual PimNeighborgetNeighbor (int interfaceId, int index)
 Returns the neighbor on the given interface at the specified position. More...
 

Protected Types

typedef std::vector< PimNeighbor * > PimNeighborVector
 
typedef std::map< int, PimNeighborVectorInterfaceToNeighborsMap
 

Protected Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void handleMessage (cMessage *) override
 
virtual void processLivenessTimer (cMessage *timer)
 

Protected Attributes

InterfaceToNeighborsMap neighbors
 

Friends

std::ostream & operator<< (std::ostream &os, const PimNeighborVector &v)
 

Detailed Description

Class holding informatation about neighboring PIM routers.

Routers are identified by the link to which they are connected and their address.

Expired entries are automatically deleted.

Member Typedef Documentation

◆ InterfaceToNeighborsMap

◆ PimNeighborVector

typedef std::vector<PimNeighbor *> inet::PimNeighborTable::PimNeighborVector
protected

Member Enumeration Documentation

◆ TimerKind

Enumerator
NeighborLivenessTimer 
69  {
71  };

Constructor & Destructor Documentation

◆ ~PimNeighborTable()

inet::PimNeighborTable::~PimNeighborTable ( )
virtual
59 {
60  for (auto& elem : neighbors) {
61  for (auto& _it2 : elem.second) {
62  cancelEvent((_it2)->getLivenessTimer());
63  delete _it2;
64  }
65  }
66 }

Member Function Documentation

◆ addNeighbor()

bool inet::PimNeighborTable::addNeighbor ( PimNeighbor neighbor,
double  holdTime 
)
virtual

Adds the a neighbor to the table.

The operation might fail if there is a neighbor with the same (ie,address) in the table. Success is indicated by the returned value.

101 {
102  Enter_Method("addNeighbor");
103 
104  PimNeighborVector& neighborsOnInterface = neighbors[entry->getInterfaceId()];
105 
106  for (auto& elem : neighborsOnInterface)
107  if ((elem)->getAddress() == entry->getAddress())
108  return false;
109 
110  EV_DETAIL << "Added new neighbor to table: " << entry->str() << "\n";
111  entry->nt = this;
112  neighborsOnInterface.push_back(entry);
113  take(entry->getLivenessTimer());
114  restartLivenessTimer(entry, holdTime);
115 
116  emit(pimNeighborAddedSignal, entry);
117 
118  return true;
119 }

◆ deleteNeighbor()

bool inet::PimNeighborTable::deleteNeighbor ( PimNeighbor neighbor)
virtual

Deletes a neighbor from the table.

If the neighbor was not found in the table then it is untouched, otherwise deleted. Returns true if the neighbor object was deleted.

122 {
123  Enter_Method("deleteNeighbor");
124 
125  auto it = neighbors.find(neighbor->getInterfaceId());
126  if (it != neighbors.end()) {
127  PimNeighborVector& neighborsOnInterface = it->second;
128  auto it2 = find(neighborsOnInterface, neighbor);
129  if (it2 != neighborsOnInterface.end()) {
130  neighborsOnInterface.erase(it2);
131 
132  emit(pimNeighborDeletedSignal, neighbor);
133 
134  neighbor->nt = nullptr;
135  cancelEvent(neighbor->getLivenessTimer());
136  delete neighbor;
137 
138  return true;
139  }
140  }
141  return false;
142 }

Referenced by processLivenessTimer().

◆ findNeighbor()

PimNeighbor * inet::PimNeighborTable::findNeighbor ( int  interfaceId,
Ipv4Address  addr 
)
virtual

Returns the neighbor that is identified by the given (interfaceId,addr), or nullptr if no such neighbor.

151 {
152  auto neighborsOnInterface = neighbors.find(interfaceId);
153  if (neighborsOnInterface != neighbors.end()) {
154  for (auto& elem : neighborsOnInterface->second)
155  if ((elem)->getAddress() == addr && (elem)->getInterfaceId() == interfaceId)
156  return elem;
157 
158  }
159  return nullptr;
160 }

◆ getNeighbor()

PimNeighbor * inet::PimNeighborTable::getNeighbor ( int  interfaceId,
int  index 
)
virtual

Returns the neighbor on the given interface at the specified position.

169 {
170  auto it = neighbors.find(interfaceId);
171  return it != neighbors.end() ? it->second.at(index) : nullptr;
172 }

◆ getNumNeighbors()

int inet::PimNeighborTable::getNumNeighbors ( int  interfaceId)
virtual

Returns the number of neighbors on the given interface.

163 {
164  auto it = neighbors.find(interfaceId);
165  return it != neighbors.end() ? it->second.size() : 0;
166 }

◆ handleMessage()

void inet::PimNeighborTable::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
78 {
79  // self message (timer)
80  if (msg->isSelfMessage()) {
81  if (msg->getKind() == NeighborLivenessTimer) {
83  }
84  else
85  ASSERT(false);
86  }
87  else
88  throw cRuntimeError("PimNeighborTable received a message although it does not have gates.");
89 }

◆ initialize()

void inet::PimNeighborTable::initialize ( int  stage)
overrideprotectedvirtual
69 {
70  cSimpleModule::initialize(stage);
71 
72  if (stage == INITSTAGE_LOCAL) {
73  WATCH_MAP(neighbors);
74  }
75 }

◆ numInitStages()

virtual int inet::PimNeighborTable::numInitStages ( ) const
inlineoverrideprotectedvirtual
121 { return NUM_INIT_STAGES; }

◆ processLivenessTimer()

void inet::PimNeighborTable::processLivenessTimer ( cMessage *  timer)
protectedvirtual
92 {
93  EV << "PimNeighborTable::processNLTimer\n";
94  PimNeighbor *neighbor = check_and_cast<PimNeighbor *>((cObject *)livenessTimer->getContextPointer());
95  Ipv4Address neighborAddress = neighbor->getAddress();
96  deleteNeighbor(neighbor);
97  EV << "PIM::processNLTimer: Neighbor " << neighborAddress << "was removed from PIM neighbor table.\n";
98 }

Referenced by handleMessage().

◆ restartLivenessTimer()

void inet::PimNeighborTable::restartLivenessTimer ( PimNeighbor neighbor,
double  holdTime 
)
virtual

Restarts the Neighbor Liveness timer of the given neighbor.

When the timer expires, the neigbor is automatically deleted.

145 {
146  Enter_Method("restartLivenessTimer");
147  rescheduleAfter(holdTime, neighbor->getLivenessTimer());
148 }

Referenced by addNeighbor().

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const PimNeighborVector v 
)
friend
35 {
36  for (unsigned int i = 0; i < v.size(); i++) {
37  PimNeighbor *e = v[i];
38  os << "[" << i << "]: "
39  << "{ If: " << e->getInterfacePtr()->getInterfaceName() << " Addr: " << e->getAddress() << " Ver: " << e->getVersion()
40  << " GenID: " << e->getGenerationId() << " DrPriority: " << e->getDRPriority() << " livenessTimer: " << e->getLivenessTimer()->getArrivalTime() << " }; ";
41  }
42  return os;
43 };

Member Data Documentation

◆ neighbors


The documentation for this class was generated from the following files:
inet::pimNeighborDeletedSignal
simsignal_t pimNeighborDeletedSignal
Definition: Simsignals.cc:61
inet::units::constants::e
const value< double, units::C > e(1.602176487e-19)
inet::PimNeighborTable::restartLivenessTimer
virtual void restartLivenessTimer(PimNeighbor *neighbor, double holdTime)
Restarts the Neighbor Liveness timer of the given neighbor.
Definition: PimNeighborTable.cc:144
inet::find
std::vector< T >::iterator find(std::vector< T > &v, const Tk &a)
Definition: stlutils.h:44
inet::PimNeighborTable::NeighborLivenessTimer
@ NeighborLivenessTimer
Definition: PimNeighborTable.h:70
inet::PimNeighborTable::neighbors
InterfaceToNeighborsMap neighbors
Definition: PimNeighborTable.h:79
inet::pimNeighborAddedSignal
simsignal_t pimNeighborAddedSignal
Definition: Simsignals.cc:60
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::PimNeighborTable::processLivenessTimer
virtual void processLivenessTimer(cMessage *timer)
Definition: PimNeighborTable.cc:91
NUM_INIT_STAGES
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
inet::PimNeighborTable::PimNeighborVector
std::vector< PimNeighbor * > PimNeighborVector
Definition: PimNeighborTable.h:74
inet::PimNeighborTable::deleteNeighbor
virtual bool deleteNeighbor(PimNeighbor *neighbor)
Deletes a neighbor from the table.
Definition: PimNeighborTable.cc:121
Enter_Method
#define Enter_Method(...)
Definition: SelfDoc.h:71