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

typedef std::vector<PIMNeighbor *> inet::PIMNeighborTable::PIMNeighborVector
protected

Member Enumeration Documentation

Enumerator
NeighborLivenessTimer 
80  {
82  };
Definition: PIMNeighborTable.h:81

Constructor & Destructor Documentation

inet::PIMNeighborTable::~PIMNeighborTable ( )
virtual
71 {
72  for (auto & elem : neighbors) {
73  for (auto & _it2 : elem.second) {
74  cancelEvent((_it2)->getLivenessTimer());
75  delete (_it2);
76  }
77  }
78 }
InterfaceToNeighborsMap neighbors
Definition: PIMNeighborTable.h:90

Member Function Documentation

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.

113 {
114  Enter_Method_Silent();
115 
116  PIMNeighborVector& neighborsOnInterface = neighbors[entry->getInterfaceId()];
117 
118  for (auto & elem : neighborsOnInterface)
119  if ((elem)->getAddress() == entry->getAddress())
120  return false;
121 
122 
123  EV_DETAIL << "Added new neighbor to table: " << entry->info() << "\n";
124  entry->nt = this;
125  neighborsOnInterface.push_back(entry);
126  take(entry->getLivenessTimer());
127  restartLivenessTimer(entry, holdTime);
128 
129  emit(NF_PIM_NEIGHBOR_ADDED, entry);
130 
131  return true;
132 }
virtual void restartLivenessTimer(PIMNeighbor *neighbor, double holdTime)
Restarts the Neighbor Liveness timer of the given neighbor.
Definition: PIMNeighborTable.cc:157
simsignal_t NF_PIM_NEIGHBOR_ADDED
Definition: NotifierConsts.cc:81
std::vector< PIMNeighbor * > PIMNeighborVector
Definition: PIMNeighborTable.h:85
InterfaceToNeighborsMap neighbors
Definition: PIMNeighborTable.h:90
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.

135 {
136  Enter_Method_Silent();
137 
138  auto it = neighbors.find(neighbor->getInterfaceId());
139  if (it != neighbors.end()) {
140  PIMNeighborVector& neighborsOnInterface = it->second;
141  auto it2 = find(neighborsOnInterface.begin(), neighborsOnInterface.end(), neighbor);
142  if (it2 != neighborsOnInterface.end()) {
143  neighborsOnInterface.erase(it2);
144 
145  emit(NF_PIM_NEIGHBOR_DELETED, neighbor);
146 
147  neighbor->nt = nullptr;
148  cancelEvent(neighbor->getLivenessTimer());
149  delete neighbor;
150 
151  return true;
152  }
153  }
154  return false;
155 }
std::vector< PIMNeighbor * > PIMNeighborVector
Definition: PIMNeighborTable.h:85
simsignal_t NF_PIM_NEIGHBOR_DELETED
Definition: NotifierConsts.cc:82
InterfaceToNeighborsMap neighbors
Definition: PIMNeighborTable.h:90
std::vector< T >::iterator find(std::vector< T > &v, const T &a)
Definition: stlutils.h:48
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.

Referenced by inet::PIMSM::addNewRouteG(), and inet::PIMSM::addNewRouteSG().

165 {
166  auto neighborsOnInterface = neighbors.find(interfaceId);
167  if (neighborsOnInterface != neighbors.end()) {
168  for (auto & elem : neighborsOnInterface->second)
169  if ((elem)->getAddress() == addr && (elem)->getInterfaceId() == interfaceId)
170  return elem;
171 
172  }
173  return nullptr;
174 }
InterfaceToNeighborsMap neighbors
Definition: PIMNeighborTable.h:90
PIMNeighbor * inet::PIMNeighborTable::getNeighbor ( int  interfaceId,
int  index 
)
virtual

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

Referenced by inet::PIMSM::addNewRouteG(), inet::PIMSM::addNewRouteSG(), and inet::PIMSM::updateDesignatedRouterAddress().

183 {
184  auto it = neighbors.find(interfaceId);
185  return it != neighbors.end() ? it->second.at(index) : nullptr;
186 }
InterfaceToNeighborsMap neighbors
Definition: PIMNeighborTable.h:90
int inet::PIMNeighborTable::getNumNeighbors ( int  interfaceId)
virtual

Returns the number of neighbors on the given interface.

Referenced by inet::PIMSM::addNewRouteG(), inet::PIMSM::addNewRouteSG(), inet::PIMSM::processPruneG(), inet::PIMSM::processPrunePendingTimer(), inet::PIMSM::processPruneSG(), and inet::PIMSM::updateDesignatedRouterAddress().

177 {
178  auto it = neighbors.find(interfaceId);
179  return it != neighbors.end() ? it->second.size() : 0;
180 }
InterfaceToNeighborsMap neighbors
Definition: PIMNeighborTable.h:90
void inet::PIMNeighborTable::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
90 {
91  // self message (timer)
92  if (msg->isSelfMessage()) {
93  if (msg->getKind() == NeighborLivenessTimer) {
95  }
96  else
97  ASSERT(false);
98  }
99  else
100  throw cRuntimeError("PIMNeighborTable received a message although it does not have gates.");
101 }
virtual void processLivenessTimer(cMessage *timer)
Definition: PIMNeighborTable.cc:103
Definition: PIMNeighborTable.h:81
void inet::PIMNeighborTable::initialize ( int  stage)
overrideprotectedvirtual
81 {
82  cSimpleModule::initialize(stage);
83 
84  if (stage == INITSTAGE_LOCAL) {
85  WATCH_MAP(neighbors);
86  }
87 }
Local initializations.
Definition: InitStages.h:35
InterfaceToNeighborsMap neighbors
Definition: PIMNeighborTable.h:90
virtual int inet::PIMNeighborTable::numInitStages ( ) const
inlineoverrideprotectedvirtual
132 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::PIMNeighborTable::processLivenessTimer ( cMessage *  timer)
protectedvirtual
104 {
105  EV << "PIMNeighborTable::processNLTimer\n";
106  PIMNeighbor *neighbor = check_and_cast<PIMNeighbor *>((cObject *)livenessTimer->getContextPointer());
107  IPv4Address neighborAddress = neighbor->getAddress();
108  deleteNeighbor(neighbor);
109  EV << "PIM::processNLTimer: Neighbor " << neighborAddress << "was removed from PIM neighbor table.\n";
110 }
virtual bool deleteNeighbor(PIMNeighbor *neighbor)
Deletes a neighbor from the table.
Definition: PIMNeighborTable.cc:134
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.

158 {
159  Enter_Method_Silent();
160  cancelEvent(neighbor->getLivenessTimer());
161  scheduleAt(simTime() + holdTime, neighbor->getLivenessTimer());
162 }

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const PIMNeighborVector v 
)
friend
47 {
48  for (unsigned int i = 0; i < v.size(); i++) {
49  PIMNeighbor *e = v[i];
50  os << "[" << i << "]: "
51  << "{ If = " << e->getInterfacePtr()->getName() << "; Addr = " << e->getAddress() << "; Ver = " << e->getVersion()
52  << "; GenID = " << e->getGenerationId() << "; Pr = " << e->getDRPriority() << "}; ";
53  }
54  return os;
55 };
const value< double, units::C > e(1.602176487e-19)

Member Data Documentation

InterfaceToNeighborsMap inet::PIMNeighborTable::neighbors
protected

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