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

Base class for STP and RSTP. More...

#include <STPBase.h>

Inheritance diagram for inet::STPBase:
inet::ILifecycle inet::RSTP inet::STP

Public Member Functions

 STPBase ()
 
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
virtual void receiveSignal (cComponent *source, simsignal_t signalID, cObject *obj, cObject *details) override
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Protected Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void start ()
 
virtual void stop ()
 
virtual void colorLink (unsigned int i, bool forwarding) const
 Adds effects to be represented by Tkenv. More...
 
virtual void refreshDisplay () const override
 Adds effects to be represented by Tkenv. More...
 
virtual int getRootIndex () const
 Obtains the root gate index. More...
 
Ieee8021dInterfaceDatagetPortInterfaceData (unsigned int portNum)
 Gets Ieee8021dInterfaceData for port number. More...
 
const Ieee8021dInterfaceDatagetPortInterfaceData (unsigned int portNum) const
 
InterfaceEntrygetPortInterfaceEntry (unsigned int portNum)
 Gets InterfaceEntry for port number. More...
 
virtual InterfaceEntrychooseInterface ()
 

Protected Attributes

bool visualize = false
 
bool isOperational = false
 
unsigned int numPorts = 0
 
unsigned int bridgePriority = 0
 
MACAddress bridgeAddress
 
simtime_t maxAge
 
simtime_t helloTime
 
simtime_t forwardDelay
 
cModule * switchModule = nullptr
 
IMACAddressTablemacTable = nullptr
 
IInterfaceTableifTable = nullptr
 
InterfaceEntryie = nullptr
 

Detailed Description

Base class for STP and RSTP.

Constructor & Destructor Documentation

inet::STPBase::STPBase ( )
31 {
32 }

Member Function Documentation

InterfaceEntry * inet::STPBase::chooseInterface ( )
protectedvirtual

Referenced by start().

171 {
172  // TODO: Currently, we assume that the first non-loopback interface is an Ethernet interface
173  // since STP and RSTP work on EtherSwitches.
174  // NOTE that, we doesn't check if the returning interface is an Ethernet interface!
175  IInterfaceTable *ift = check_and_cast<IInterfaceTable *>(getModuleByPath(par("interfaceTablePath")));
176 
177  for (int i = 0; i < ift->getNumInterfaces(); i++) {
178  InterfaceEntry *current = ift->getInterface(i);
179  if (!current->isLoopback())
180  return current;
181  }
182 
183  return nullptr;
184 }
void inet::STPBase::colorLink ( unsigned int  i,
bool  forwarding 
) const
protectedvirtual

Adds effects to be represented by Tkenv.

Colors the link black if forwarding parameter is true and the port to which the link is connected to is also forwarding, otherwise colors the link gray.

Referenced by refreshDisplay().

83 {
84  if (visualize) {
85  cGate *inGate = switchModule->gate("ethg$i", i);
86  cGate *outGate = switchModule->gate("ethg$o", i);
87  cGate *outGateNext = outGate ? outGate->getNextGate() : nullptr;
88  cGate *outGatePrev = outGate ? outGate->getPreviousGate() : nullptr;
89  cGate *inGatePrev = inGate ? inGate->getPreviousGate() : nullptr;
90  cGate *inGatePrev2 = inGatePrev ? inGatePrev->getPreviousGate() : nullptr;
91 
92  if (outGate && inGate && inGatePrev && outGateNext && outGatePrev && inGatePrev2) {
93  if (forwarding) {
94  outGatePrev->getDisplayString().setTagArg("ls", 0, ENABLED_LINK_COLOR);
95  inGate->getDisplayString().setTagArg("ls", 0, ENABLED_LINK_COLOR);
96  }
97  else {
98  outGatePrev->getDisplayString().setTagArg("ls", 0, DISABLED_LINK_COLOR);
99  inGate->getDisplayString().setTagArg("ls", 0, DISABLED_LINK_COLOR);
100  }
101 
102  if ((!inGatePrev2->getDisplayString().containsTag("ls") || strcmp(inGatePrev2->getDisplayString().getTagArg("ls", 0), ENABLED_LINK_COLOR) == 0) && forwarding) {
103  outGate->getDisplayString().setTagArg("ls", 0, ENABLED_LINK_COLOR);
104  inGatePrev->getDisplayString().setTagArg("ls", 0, ENABLED_LINK_COLOR);
105  }
106  else {
107  outGate->getDisplayString().setTagArg("ls", 0, DISABLED_LINK_COLOR);
108  inGatePrev->getDisplayString().setTagArg("ls", 0, DISABLED_LINK_COLOR);
109  }
110  }
111  }
112 }
bool visualize
Definition: STPBase.h:35
cModule * switchModule
Definition: STPBase.h:46
Ieee8021dInterfaceData * inet::STPBase::getPortInterfaceData ( unsigned int  portNum)
protected

Gets Ieee8021dInterfaceData for port number.

Returns
The port's Ieee8021dInterfaceData, or nullptr if it doesn't exist.

Referenced by inet::STP::checkRootEligibility(), inet::RSTP::checkTC(), inet::STP::checkTimers(), inet::RSTP::compareInterfacedata(), inet::RSTP::contestInterfacedata(), inet::RSTP::flushOtherPorts(), inet::STP::generateBPDU(), inet::STP::generateTCN(), inet::RSTP::getBestAlternate(), getRootIndex(), inet::RSTP::handleBackup(), inet::STP::handleBPDU(), inet::RSTP::handleHelloTime(), inet::STP::handleTick(), inet::RSTP::handleUpgrade(), inet::RSTP::initInterfacedata(), inet::STP::initInterfacedata(), inet::RSTP::initPorts(), inet::STP::isSuperiorBPDU(), inet::operator<<(), inet::RSTP::printState(), inet::RSTP::processBetterSource(), inet::RSTP::processBPDU(), inet::RSTP::processSameSource(), inet::RSTP::receiveSignal(), refreshDisplay(), inet::RSTP::scheduleNextUpgrade(), inet::STP::selectDesignatedPorts(), inet::STP::selectRootPort(), inet::RSTP::sendBPDU(), inet::RSTP::sendBPDUs(), inet::RSTP::sendTCNtoRoot(), inet::STP::setAllDesignated(), inet::STP::setSuperiorBPDU(), and inet::RSTP::updateInterfacedata().

141 {
142  Ieee8021dInterfaceData *portData = getPortInterfaceEntry(portNum)->ieee8021dData();
143  if (!portData)
144  throw cRuntimeError("Ieee8021dInterfaceData not found!");
145 
146  return portData;
147 }
Ieee8021dInterfaceData * ieee8021dData() const
Definition: InterfaceEntry.h:227
InterfaceEntry * getPortInterfaceEntry(unsigned int portNum)
Gets InterfaceEntry for port number.
Definition: STPBase.cc:149
const Ieee8021dInterfaceData* inet::STPBase::getPortInterfaceData ( unsigned int  portNum) const
inlineprotected

Referenced by getPortInterfaceData().

86 { return const_cast<STPBase *>(this)->getPortInterfaceData(portNum); }
Ieee8021dInterfaceData * getPortInterfaceData(unsigned int portNum)
Gets Ieee8021dInterfaceData for port number.
Definition: STPBase.cc:140
STPBase()
Definition: STPBase.cc:30
InterfaceEntry * inet::STPBase::getPortInterfaceEntry ( unsigned int  portNum)
protected

Gets InterfaceEntry for port number.

Returns
The port's InterfaceEntry, or nullptr if it doesn't exist.

Referenced by getPortInterfaceData(), inet::RSTP::handleUpgrade(), inet::RSTP::receiveSignal(), and inet::RSTP::scheduleNextUpgrade().

150 {
151  cGate *gate = switchModule->gate("ethg$o", portNum);
152  if (!gate)
153  throw cRuntimeError("gate is nullptr");
154  InterfaceEntry *gateIfEntry = ifTable->getInterfaceByNodeOutputGateId(gate->getId());
155  if (!gateIfEntry)
156  throw cRuntimeError("gate's Interface is nullptr");
157 
158  return gateIfEntry;
159 }
virtual InterfaceEntry * getInterfaceByNodeOutputGateId(int id) const =0
Returns an interface given by its getNodeOutputGateId().
cModule * switchModule
Definition: STPBase.h:46
IInterfaceTable * ifTable
Definition: STPBase.h:48
int inet::STPBase::getRootIndex ( ) const
protectedvirtual

Obtains the root gate index.

Returns
The root gate index or -1 if there is no root gate.

Referenced by inet::RSTP::contestInterfacedata(), inet::RSTP::printState(), inet::RSTP::processBetterSource(), refreshDisplay(), inet::RSTP::sendBPDU(), and inet::RSTP::sendTCNtoRoot().

162 {
163  for (unsigned int i = 0; i < numPorts; i++)
165  return i;
166 
167  return -1;
168 }
Ieee8021dInterfaceData * getPortInterfaceData(unsigned int portNum)
Gets Ieee8021dInterfaceData for port number.
Definition: STPBase.cc:140
Definition: Ieee8021dInterfaceData.h:37
unsigned int numPorts
Definition: STPBase.h:37
bool inet::STPBase::handleOperationStage ( LifecycleOperation operation,
int  stage,
IDoneCallback doneCallback 
)
overridevirtual

Perform one stage of a lifecycle operation.

Processing may be done entirely within this method, or may be a longer process that involves nonzero simulation time or several events, and is triggered by this method call.

Return value: true = "done"; false = "not yet done, will invoke doneCallback when done"

Implements inet::ILifecycle.

187 {
188  Enter_Method_Silent();
189 
190  if (dynamic_cast<NodeStartOperation *>(operation)) {
192  start();
193  }
194  else if (dynamic_cast<NodeShutdownOperation *>(operation)) {
196  stop();
197  }
198  else if (dynamic_cast<NodeCrashOperation *>(operation)) {
200  stop();
201  }
202  else
203  throw cRuntimeError("Unsupported operation '%s'", operation->getClassName());
204 
205  return true;
206 }
Definition: NodeOperations.h:49
Stage
Definition: NodeOperations.h:71
Stage
Definition: NodeOperations.h:126
virtual void start()
Definition: STPBase.cc:65
Stage
Definition: NodeOperations.h:46
virtual void stop()
Definition: STPBase.cc:76
Definition: NodeOperations.h:127
Definition: NodeOperations.h:77
void inet::STPBase::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented in inet::STP, and inet::RSTP.

Referenced by inet::RSTP::initialize(), and inet::STP::initialize().

35 {
36  if (stage == INITSTAGE_LOCAL) {
37  visualize = par("visualize");
38  bridgePriority = par("bridgePriority");
39 
40  maxAge = par("maxAge");
41  helloTime = par("helloTime");
42  forwardDelay = par("forwardDelay");
43 
44  macTable = check_and_cast<IMACAddressTable *>(getModuleByPath(par("macTablePath")));
45  ifTable = check_and_cast<IInterfaceTable *>(getModuleByPath(par("interfaceTablePath")));
47  if (!switchModule)
48  throw cRuntimeError("Containing @networkNode module not found");
49  numPorts = switchModule->gate("ethg$o", 0)->getVectorSize();
50  }
51 
52  if (stage == INITSTAGE_LINK_LAYER_2) { // "auto" MAC addresses assignment takes place in stage 0
53  cModule *m = findContainingNode(this);
54  if (m)
55  m->subscribe(NF_INTERFACE_STATE_CHANGED, this);
56 
57  NodeStatus *nodeStatus = dynamic_cast<NodeStatus *>(switchModule->getSubmodule("status"));
58  isOperational = (!nodeStatus) || nodeStatus->getState() == NodeStatus::UP;
59 
60  if (isOperational)
61  start();
62  }
63 }
unsigned int bridgePriority
Definition: STPBase.h:39
simtime_t maxAge
Definition: STPBase.h:42
simtime_t forwardDelay
Definition: STPBase.h:44
IMACAddressTable * macTable
Definition: STPBase.h:47
virtual void start()
Definition: STPBase.cc:65
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:56
Local initializations.
Definition: InitStages.h:35
bool visualize
Definition: STPBase.h:35
simsignal_t NF_INTERFACE_STATE_CHANGED
Definition: NotifierConsts.cc:50
cModule * switchModule
Definition: STPBase.h:46
bool isOperational
Definition: STPBase.h:36
IInterfaceTable * ifTable
Definition: STPBase.h:48
Additional link-layer initializations that depend on the previous stage.
Definition: InitStages.h:64
simtime_t helloTime
Definition: STPBase.h:43
unsigned int numPorts
Definition: STPBase.h:37
value< double, units::m > m
Definition: Units.h:1047
Definition: NodeStatus.h:40
virtual int inet::STPBase::numInitStages ( ) const
inlineoverrideprotectedvirtual

Reimplemented in inet::STP, and inet::RSTP.

57 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
virtual void inet::STPBase::receiveSignal ( cComponent *  source,
simsignal_t  signalID,
cObject *  obj,
cObject *  details 
)
inlineoverridevirtual

Reimplemented in inet::RSTP.

54 {}
void inet::STPBase::refreshDisplay ( ) const
overrideprotectedvirtual

Adds effects to be represented by Tkenv.

Inactive links are colored grey. Shows port role, state. Marks root switch.

115 {
116  if (visualize) {
117  for (unsigned int i = 0; i < numPorts; i++) {
118  const Ieee8021dInterfaceData *port = getPortInterfaceData(i);
119 
120  // color link
121  colorLink(i, isOperational && (port->getState() == Ieee8021dInterfaceData::FORWARDING));
122 
123  // label ethernet interface with port status and role
124  cModule *nicModule = switchModule->getSubmodule("eth", i);
125  if (nicModule != nullptr) {
126  char buf[32];
127  sprintf(buf, "%s\n%s", port->getRoleName(), port->getStateName());
128  nicModule->getDisplayString().setTagArg("t", 0, buf);
129  }
130  }
131 
132  // mark root switch
133  if (isOperational && (const_cast<STPBase*>(this)->getRootIndex() == -1))
134  switchModule->getDisplayString().setTagArg("i", 1, ROOT_SWITCH_COLOR);
135  else
136  switchModule->getDisplayString().setTagArg("i", 1, "");
137  }
138 }
Ieee8021dInterfaceData * getPortInterfaceData(unsigned int portNum)
Gets Ieee8021dInterfaceData for port number.
Definition: STPBase.cc:140
virtual int getRootIndex() const
Obtains the root gate index.
Definition: STPBase.cc:161
virtual void colorLink(unsigned int i, bool forwarding) const
Adds effects to be represented by Tkenv.
Definition: STPBase.cc:82
bool visualize
Definition: STPBase.h:35
cModule * switchModule
Definition: STPBase.h:46
bool isOperational
Definition: STPBase.h:36
Definition: Ieee8021dInterfaceData.h:39
unsigned int numPorts
Definition: STPBase.h:37
void inet::STPBase::start ( )
protectedvirtual

Reimplemented in inet::STP, and inet::RSTP.

Referenced by handleOperationStage(), initialize(), inet::RSTP::start(), and inet::STP::start().

66 {
67  isOperational = true;
68  ie = chooseInterface();
69 
70  if (ie)
71  bridgeAddress = ie->getMacAddress(); // get the bridge's MAC address
72  else
73  throw cRuntimeError("No non-loopback interface found!");
74 }
InterfaceEntry * ie
Definition: STPBase.h:49
virtual InterfaceEntry * chooseInterface()
Definition: STPBase.cc:170
MACAddress bridgeAddress
Definition: STPBase.h:40
const MACAddress & getMacAddress() const
Definition: InterfaceEntry.h:197
bool isOperational
Definition: STPBase.h:36
void inet::STPBase::stop ( )
protectedvirtual

Reimplemented in inet::STP, and inet::RSTP.

Referenced by handleOperationStage(), inet::RSTP::stop(), and inet::STP::stop().

77 {
78  isOperational = false;
79  ie = nullptr;
80 }
InterfaceEntry * ie
Definition: STPBase.h:49
bool isOperational
Definition: STPBase.h:36

Member Data Documentation

simtime_t inet::STPBase::helloTime
protected
InterfaceEntry* inet::STPBase::ie = nullptr
protected

Referenced by start(), and stop().

IInterfaceTable* inet::STPBase::ifTable = nullptr
protected
bool inet::STPBase::isOperational = false
protected
cModule* inet::STPBase::switchModule = nullptr
protected
bool inet::STPBase::visualize = false
protected

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