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

Base class of PIMSM and PIMDM modules. More...

#include <PIMBase.h>

Inheritance diagram for inet::PIMBase:
inet::OperationalBase inet::ILifecycle inet::PIMDM inet::PIMSM

Classes

struct  AssertMetric
 
struct  Interface
 
struct  RouteEntry
 
struct  SourceAndGroup
 

Public Member Functions

 PIMBase (PIMInterface::PIMMode mode)
 
virtual ~PIMBase ()
 
- Public Member Functions inherited from inet::OperationalBase
 OperationalBase ()
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Protected Types

enum  PIMTimerKind {
  HelloTimer = 1, TriggeredHelloDelay, AssertTimer, PruneTimer,
  PrunePendingTimer, GraftRetryTimer, UpstreamOverrideTimer, PruneLimitTimer,
  SourceActiveTimer, StateRefreshTimer, KeepAliveTimer, RegisterStopTimer,
  ExpiryTimer, JoinTimer
}
 

Protected Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
void sendHelloPackets ()
 
void sendHelloPacket (PIMInterface *pimInterface)
 
void processHelloTimer (cMessage *timer)
 
void processHelloPacket (PIMHello *pkt)
 
virtual bool isInitializeStage (int stage) override
 
virtual bool isNodeStartStage (int stage) override
 
virtual bool isNodeShutdownStage (int stage) override
 
virtual bool handleNodeStart (IDoneCallback *doneCallback) override
 
virtual bool handleNodeShutdown (IDoneCallback *doneCallback) override
 
virtual void handleNodeCrash () override
 
- Protected Member Functions inherited from inet::OperationalBase
virtual void handleMessage (cMessage *msg) override
 
virtual void handleMessageWhenDown (cMessage *msg)
 
virtual void handleMessageWhenUp (cMessage *msg)=0
 
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
virtual void setOperational (bool isOperational)
 

Protected Attributes

IIPv4RoutingTablert = nullptr
 
IInterfaceTableift = nullptr
 
PIMInterfaceTablepimIft = nullptr
 
PIMNeighborTablepimNbt = nullptr
 
bool isUp = false
 
bool isEnabled = false
 
const char * hostname = nullptr
 
double helloPeriod = 0
 
double holdTime = 0
 
int designatedRouterPriority = 0
 
PIMInterface::PIMMode mode = (PIMInterface::PIMMode)0
 
uint32_t generationID = 0
 
cMessage * helloTimer = nullptr
 
- Protected Attributes inherited from inet::OperationalBase
bool isOperational
 
simtime_t lastChange
 

Static Protected Attributes

static const IPv4Address ALL_PIM_ROUTERS_MCAST
 
static simsignal_t sentHelloPkSignal = registerSignal("sentHelloPk")
 
static simsignal_t rcvdHelloPkSignal = registerSignal("rcvdHelloPk")
 

Detailed Description

Base class of PIMSM and PIMDM modules.

Member Enumeration Documentation

Enumerator
HelloTimer 
TriggeredHelloDelay 
AssertTimer 
PruneTimer 
PrunePendingTimer 
GraftRetryTimer 
UpstreamOverrideTimer 
PruneLimitTimer 
SourceActiveTimer 
StateRefreshTimer 
KeepAliveTimer 
RegisterStopTimer 
ExpiryTimer 
JoinTimer 
131  {
132  // global timers
133  HelloTimer = 1,
135 
136  // timers for each interface and each source-group pair (S,G,I)
137  AssertTimer,
138  PruneTimer,
140 
141  // timers for each source-group pair (S,G)
147 
148  //PIM-SM specific timers
151  ExpiryTimer,
152  JoinTimer,
153  };
Definition: PIMBase.h:137
Definition: PIMBase.h:133
Definition: PIMBase.h:151
Definition: PIMBase.h:145
Definition: PIMBase.h:134
Definition: PIMBase.h:138
Definition: PIMBase.h:143
Definition: PIMBase.h:144
Definition: PIMBase.h:150
Definition: PIMBase.h:139
Definition: PIMBase.h:149
Definition: PIMBase.h:152
Definition: PIMBase.h:146
Definition: PIMBase.h:142

Constructor & Destructor Documentation

inet::PIMBase::PIMBase ( PIMInterface::PIMMode  mode)
inline
181 : mode(mode) {}
PIMInterface::PIMMode mode
Definition: PIMBase.h:172
inet::PIMBase::~PIMBase ( )
virtual
68 {
69  cancelAndDelete(helloTimer);
70 }
cMessage * helloTimer
Definition: PIMBase.h:174

Member Function Documentation

void inet::PIMBase::handleNodeCrash ( )
overrideprotectedvirtual

Reimplemented from inet::OperationalBase.

Reimplemented in inet::PIMDM, and inet::PIMSM.

Referenced by inet::PIMSM::handleNodeCrash(), and inet::PIMDM::handleNodeCrash().

129 {
130  // TODO unregister IP_PROT_PIM
131  cancelAndDelete(helloTimer);
132  helloTimer = nullptr;
133 }
cMessage * helloTimer
Definition: PIMBase.h:174
bool inet::PIMBase::handleNodeShutdown ( IDoneCallback doneCallback)
overrideprotectedvirtual

Reimplemented from inet::OperationalBase.

Reimplemented in inet::PIMDM, and inet::PIMSM.

Referenced by inet::PIMSM::handleNodeShutdown(), and inet::PIMDM::handleNodeShutdown().

121 {
122  // TODO unregister IP_PROT_PIM
123  cancelAndDelete(helloTimer);
124  helloTimer = nullptr;
125  return true;
126 }
cMessage * helloTimer
Definition: PIMBase.h:174
bool inet::PIMBase::handleNodeStart ( IDoneCallback doneCallback)
overrideprotectedvirtual

Reimplemented from inet::OperationalBase.

Reimplemented in inet::PIMDM, and inet::PIMSM.

Referenced by inet::PIMSM::handleNodeStart(), and inet::PIMDM::handleNodeStart().

95 {
96  generationID = intrand(UINT32_MAX);
97 
98  IPSocket ipSocket(gate("ipOut"));
99  ipSocket.registerProtocol(IP_PROT_PIM);
100 
101  // to receive PIM messages, join to ALL_PIM_ROUTERS multicast group
102  isEnabled = false;
103  for (int i = 0; i < pimIft->getNumInterfaces(); i++) {
104  PIMInterface *pimInterface = pimIft->getInterface(i);
105  if (pimInterface->getMode() == mode) {
107  isEnabled = true;
108  }
109  }
110 
111  if (isEnabled) {
112  EV_INFO << "PIM is enabled on device " << hostname << endl;
113  helloTimer = new cMessage("PIM HelloTimer", HelloTimer);
114  scheduleAt(simTime() + par("triggeredHelloDelay").doubleValue(), helloTimer);
115  }
116 
117  return true;
118 }
bool isEnabled
Definition: PIMBase.h:164
IPv4InterfaceData * ipv4Data() const
Definition: InterfaceEntry.h:221
cMessage * helloTimer
Definition: PIMBase.h:174
virtual PIMInterface * getInterface(int k)
Definition: PIMInterfaceTable.h:80
Definition: PIMBase.h:133
virtual void joinMulticastGroup(const IPv4Address &multicastAddress)
Definition: IPv4InterfaceData.cc:205
uint32_t generationID
Definition: PIMBase.h:173
PIMInterfaceTable * pimIft
Definition: PIMBase.h:160
InterfaceEntry * getInterfacePtr() const
Definition: PIMInterfaceTable.h:56
Definition: IPProtocolId_m.h:90
#define UINT32_MAX
Definition: lexer.cc:84
virtual int getNumInterfaces()
Definition: PIMInterfaceTable.h:79
PIMInterface::PIMMode mode
Definition: PIMBase.h:172
const char * hostname
Definition: PIMBase.h:165
static const IPv4Address ALL_PIM_ROUTERS_MCAST
Definition: PIMBase.h:155
void inet::PIMBase::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::OperationalBase.

Reimplemented in inet::PIMDM, and inet::PIMSM.

Referenced by inet::PIMSM::initialize(), and inet::PIMDM::initialize().

73 {
75 
76  if (stage == INITSTAGE_LOCAL) {
77  ift = getModuleFromPar<IInterfaceTable>(par("interfaceTableModule"), this);
78  rt = getModuleFromPar<IIPv4RoutingTable>(par("routingTableModule"), this);
79  pimIft = getModuleFromPar<PIMInterfaceTable>(par("pimInterfaceTableModule"), this);
80  pimNbt = getModuleFromPar<PIMNeighborTable>(par("pimNeighborTableModule"), this);
81 
82  cModule *host = findContainingNode(this);
83  if (!host)
84  throw cRuntimeError("PIMBase: containing node not found.");
85 
86  hostname = host->getName();
87 
88  helloPeriod = par("helloPeriod");
89  holdTime = par("holdTime");
90  designatedRouterPriority = mode == PIMInterface::SparseMode ? par("designatedRouterPriority") : -1;
91  }
92 }
PIMNeighborTable * pimNbt
Definition: PIMBase.h:161
int designatedRouterPriority
Definition: PIMBase.h:170
PIMInterfaceTable * pimIft
Definition: PIMBase.h:160
IInterfaceTable * ift
Definition: PIMBase.h:159
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:56
Local initializations.
Definition: InitStages.h:35
double holdTime
Definition: PIMBase.h:169
virtual void initialize(int stage) override
Definition: OperationalBase.cc:32
IIPv4RoutingTable * rt
Definition: PIMBase.h:158
Definition: PIMInterfaceTable.h:37
PIMInterface::PIMMode mode
Definition: PIMBase.h:172
const char * hostname
Definition: PIMBase.h:165
double helloPeriod
Definition: PIMBase.h:168
virtual bool inet::PIMBase::isInitializeStage ( int  stage)
inlineoverrideprotectedvirtual

Implements inet::OperationalBase.

193 { return stage == INITSTAGE_ROUTING_PROTOCOLS; }
Initialization of routing protocols.
Definition: InitStages.h:101
virtual bool inet::PIMBase::isNodeShutdownStage ( int  stage)
inlineoverrideprotectedvirtual

Implements inet::OperationalBase.

195 { return stage == INITSTAGE_ROUTING_PROTOCOLS; }
Initialization of routing protocols.
Definition: InitStages.h:101
virtual bool inet::PIMBase::isNodeStartStage ( int  stage)
inlineoverrideprotectedvirtual

Implements inet::OperationalBase.

194 { return stage == INITSTAGE_ROUTING_PROTOCOLS; }
Initialization of routing protocols.
Definition: InitStages.h:101
virtual int inet::PIMBase::numInitStages ( ) const
inlineoverrideprotectedvirtual

Reimplemented from inet::OperationalBase.

Reimplemented in inet::PIMDM, and inet::PIMSM.

185 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::PIMBase::processHelloPacket ( PIMHello pkt)
protected

Referenced by inet::PIMSM::handleMessageWhenUp().

191 {
192  IPv4ControlInfo *ctrl = check_and_cast<IPv4ControlInfo *>(packet->getControlInfo());
193  int interfaceId = ctrl->getInterfaceId();
194  IPv4Address address = ctrl->getSrcAddr();
195  int version = packet->getVersion();
196 
197  emit(rcvdHelloPkSignal, packet);
198 
199  // process options
200  double holdTime = 3.5 * 30;
201  long drPriority = -1L;
202  unsigned int generationId = 0;
203  for (unsigned int i = 0; i < packet->getOptionsArraySize(); i++) {
204  HelloOption *option = packet->getOptions(i);
205  if (dynamic_cast<HoldtimeOption *>(option))
206  holdTime = (double)static_cast<HoldtimeOption *>(option)->getHoldTime();
207  else if (dynamic_cast<DRPriorityOption *>(option))
208  drPriority = static_cast<DRPriorityOption *>(option)->getPriority();
209  else if (dynamic_cast<GenerationIDOption *>(option))
210  generationId = static_cast<GenerationIDOption *>(option)->getGenerationID();
211  }
212 
213  InterfaceEntry *ie = ift->getInterfaceById(interfaceId);
214 
215  EV_INFO << "Received PIM Hello from neighbor: interface=" << ie->getName() << " address=" << address << "\n";
216 
217  PIMNeighbor *neighbor = pimNbt->findNeighbor(interfaceId, address);
218  if (neighbor)
219  pimNbt->restartLivenessTimer(neighbor, holdTime);
220  else {
221  neighbor = new PIMNeighbor(ie, address, version);
222  pimNbt->addNeighbor(neighbor, holdTime);
223 
224  // TODO If a Hello message is received from a new neighbor, the
225  // receiving router SHOULD send its own Hello message after a random
226  // delay between 0 and Triggered_Hello_Delay.
227  }
228 
229  neighbor->setGenerationId(generationId);
230  neighbor->setDRPriority(drPriority);
231 
232  delete packet;
233 }
virtual InterfaceEntry * getInterfaceById(int id) const =0
Returns an interface by its Id.
PIMNeighborTable * pimNbt
Definition: PIMBase.h:161
virtual void restartLivenessTimer(PIMNeighbor *neighbor, double holdTime)
Restarts the Neighbor Liveness timer of the given neighbor.
Definition: PIMNeighborTable.cc:157
unsigned int version
Definition: TCP_NSC.cc:76
static simsignal_t rcvdHelloPkSignal
Definition: PIMBase.h:178
IInterfaceTable * ift
Definition: PIMBase.h:159
double holdTime
Definition: PIMBase.h:169
virtual PIMNeighbor * findNeighbor(int interfaceId, IPv4Address addr)
Returns the neighbor that is identified by the given (interfaceId,addr), or nullptr if no such neighb...
Definition: PIMNeighborTable.cc:164
virtual bool addNeighbor(PIMNeighbor *neighbor, double holdTime)
Adds the a neighbor to the table.
Definition: PIMNeighborTable.cc:112
void inet::PIMBase::processHelloTimer ( cMessage *  timer)
protected

Referenced by inet::PIMSM::handleMessageWhenUp().

136 {
137  ASSERT(timer == helloTimer);
138  EV_DETAIL << "Hello Timer expired.\n";
140  scheduleAt(simTime() + helloPeriod, helloTimer);
141 }
cMessage * helloTimer
Definition: PIMBase.h:174
void sendHelloPackets()
Definition: PIMBase.cc:143
double helloPeriod
Definition: PIMBase.h:168
void inet::PIMBase::sendHelloPacket ( PIMInterface pimInterface)
protected
153 {
154  EV_INFO << "Sending Hello packet on interface '" << pimInterface->getInterfacePtr()->getName() << "'\n";
155 
156  PIMHello *msg = new PIMHello("PIMHello");
157 
158  int byteLength = PIM_HEADER_LENGTH + 6 + 8; // HoldTime + GenerationID option
159 
160  msg->setOptionsArraySize(designatedRouterPriority < 0 ? 2 : 3);
161  HoldtimeOption *holdtimeOption = new HoldtimeOption();
162  holdtimeOption->setHoldTime(holdTime < 0 ? (uint16_t)0xffff : (uint16_t)holdTime);
163  msg->setOptions(0, holdtimeOption);
164 
165  GenerationIDOption *genIdOption = new GenerationIDOption();
166  genIdOption->setGenerationID(generationID);
167  msg->setOptions(1, genIdOption);
168 
169  if (designatedRouterPriority >= 0) {
170  DRPriorityOption *drPriorityOption = new DRPriorityOption();
171  drPriorityOption->setPriority(designatedRouterPriority);
172  msg->setOptions(2, drPriorityOption);
173  byteLength += 8;
174  }
175 
176  IPv4ControlInfo *ctrl = new IPv4ControlInfo();
177  ctrl->setDestAddr(ALL_PIM_ROUTERS_MCAST);
178  ctrl->setProtocol(IP_PROT_PIM);
179  ctrl->setTimeToLive(1);
180  ctrl->setInterfaceId(pimInterface->getInterfaceId());
181  msg->setControlInfo(ctrl);
182 
183  msg->setByteLength(byteLength);
184 
185  emit(sentHelloPkSignal, msg);
186 
187  send(msg, "ipOut");
188 }
int designatedRouterPriority
Definition: PIMBase.h:170
uint32_t generationID
Definition: PIMBase.h:173
static simsignal_t sentHelloPkSignal
Definition: PIMBase.h:177
Definition: IPProtocolId_m.h:90
double holdTime
Definition: PIMBase.h:169
static const IPv4Address ALL_PIM_ROUTERS_MCAST
Definition: PIMBase.h:155
#define PIM_HEADER_LENGTH
Definition: PIMPacket_m.h:33
void inet::PIMBase::sendHelloPackets ( )
protected
144 {
145  for (int i = 0; i < pimIft->getNumInterfaces(); i++) {
146  PIMInterface *pimInterface = pimIft->getInterface(i);
147  if (pimInterface->getMode() == mode)
148  sendHelloPacket(pimInterface);
149  }
150 }
virtual PIMInterface * getInterface(int k)
Definition: PIMInterfaceTable.h:80
PIMInterfaceTable * pimIft
Definition: PIMBase.h:160
void sendHelloPacket(PIMInterface *pimInterface)
Definition: PIMBase.cc:152
virtual int getNumInterfaces()
Definition: PIMInterfaceTable.h:79
PIMInterface::PIMMode mode
Definition: PIMBase.h:172

Member Data Documentation

const IPv4Address inet::PIMBase::ALL_PIM_ROUTERS_MCAST
staticprotected
int inet::PIMBase::designatedRouterPriority = 0
protected
uint32_t inet::PIMBase::generationID = 0
protected
double inet::PIMBase::helloPeriod = 0
protected
cMessage* inet::PIMBase::helloTimer = nullptr
protected
double inet::PIMBase::holdTime = 0
protected
const char* inet::PIMBase::hostname = nullptr
protected
bool inet::PIMBase::isEnabled = false
protected
bool inet::PIMBase::isUp = false
protected
PIMInterface::PIMMode inet::PIMBase::mode = (PIMInterface::PIMMode)0
protected
simsignal_t inet::PIMBase::rcvdHelloPkSignal = registerSignal("rcvdHelloPk")
staticprotected
simsignal_t inet::PIMBase::sentHelloPkSignal = registerSignal("sentHelloPk")
staticprotected

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