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

Utility class for testing the STP protocol. More...

#include <STPTester.h>

Inheritance diagram for inet::STPTester:

Public Types

enum  Color { WHITE, GRAY, BLACK }
 

Public Member Functions

 STPTester ()
 
 ~STPTester ()
 
virtual void initialize () override
 
virtual void handleMessage (cMessage *msg) override
 

Protected Member Functions

void dfsVisit (Topology::Node *node)
 
bool isForwarding (Topology::Node *node, unsigned int portNum)
 
void depthFirstSearch ()
 
bool isLoopFreeGraph ()
 
bool isConnectedGraph ()
 
bool isTreeGraph ()
 
int getNumOfNodes ()
 
int getNumOfVisitedNodes ()
 

Protected Attributes

bool loop = false
 
int numOfVisitedNodes = 0
 
int numOfNodes = 0
 
std::map< Topology::Node *, int > color
 
std::map< Topology::Node *, Topology::Node * > parent
 
Topology graph
 
simtime_t checkTime
 
cMessage * checkTimer = nullptr
 

Detailed Description

Utility class for testing the STP protocol.

First, it extracts the network topology (network nodes marked with the NED property), regarding the enabled (state=FORWARDING) links only. Then it analyzes the resulting graph for connectedness and loop free-ness, using a modified depth-first search with cycle detection. The results can be obtained with getter methods.

Member Enumeration Documentation

Enumerator
WHITE 
GRAY 
BLACK 
41  {
42  WHITE, GRAY, BLACK
43  };
Definition: STPTester.h:42
Definition: STPTester.h:42
Definition: STPTester.h:42

Constructor & Destructor Documentation

inet::STPTester::STPTester ( )
29 {
30 }
inet::STPTester::~STPTester ( )
33 {
34  cancelAndDelete(checkTimer);
35 }
cMessage * checkTimer
Definition: STPTester.h:54

Member Function Documentation

void inet::STPTester::depthFirstSearch ( )
protected

Referenced by handleMessage().

66 {
67  loop = false;
69  graph.extractByProperty("networkNode");
71 
72  for (int i = 0; i < graph.getNumNodes(); i++) {
73  color[graph.getNode(i)] = WHITE;
74  parent[graph.getNode(i)] = nullptr;
75  }
76 
77  /* Use this for testing loop-freeness in all connected components.
78  * Note that in this case the algorithm is unable to decide
79  * whether a graph is connected.
80  *
81  * for (int i = 0; i < graph.getNumNodes(); i++)
82  * if (color[graph.getNode(i)] == WHITE)
83  * dfsVisit(graph.getNode(i));
84  */
85 
86  // We only call dfsVisit() for a root node to test whether a graph is connected or not
87  if (numOfNodes > 0)
89 }
void extractByProperty(const char *propertyName, const char *value=nullptr)
Extracts model topology by a module property.
Definition: Topology.cc:159
std::map< Topology::Node *, Topology::Node * > parent
Definition: STPTester.h:50
Definition: STPTester.h:42
std::map< Topology::Node *, int > color
Definition: STPTester.h:49
Node * getNode(int i)
Returns pointer to the ith node in the graph.
Definition: Topology.cc:356
int getNumNodes() const
Returns the number of nodes in the graph.
Definition: Topology.h:522
int numOfVisitedNodes
Definition: STPTester.h:47
void dfsVisit(Topology::Node *node)
Definition: STPTester.cc:91
Topology graph
Definition: STPTester.h:51
bool loop
Definition: STPTester.h:46
int numOfNodes
Definition: STPTester.h:48
void inet::STPTester::dfsVisit ( Topology::Node node)
protected

Referenced by depthFirstSearch().

92 {
93  color[node] = GRAY;
94 
95  for (int i = 0; i < node->getNumOutLinks(); i++) {
96  Topology::LinkOut *linkOut = node->getLinkOut(i);
97  Topology::Node *neighbor = linkOut->getRemoteNode();
98 
99  // If we found a port which is in state discarding,
100  // then we do not expand this link
101 
102  if (!isForwarding(node, i))
103  continue;
104 
105  // If we found a port that points to a remote port which is in state
106  // discarding, then we also do not expand this link
107 
108  int remotePort = linkOut->getRemoteGate()->getIndex();
109  if (!isForwarding(neighbor, remotePort))
110  continue;
111 
112  if (color[neighbor] == WHITE) {
113  parent[neighbor] = node;
114  dfsVisit(neighbor);
115  }
116 
117  if (color[neighbor] == GRAY && parent[node] != neighbor)
118  loop = true;
119  }
120  color[node] = BLACK;
122 }
bool isForwarding(Topology::Node *node, unsigned int portNum)
Definition: STPTester.cc:149
std::map< Topology::Node *, Topology::Node * > parent
Definition: STPTester.h:50
Definition: STPTester.h:42
std::map< Topology::Node *, int > color
Definition: STPTester.h:49
Definition: STPTester.h:42
int numOfVisitedNodes
Definition: STPTester.h:47
void dfsVisit(Topology::Node *node)
Definition: STPTester.cc:91
bool loop
Definition: STPTester.h:46
Definition: STPTester.h:42
int inet::STPTester::getNumOfNodes ( )
protected
140 {
141  return numOfNodes;
142 }
int numOfNodes
Definition: STPTester.h:48
int inet::STPTester::getNumOfVisitedNodes ( )
protected
145 {
146  return numOfVisitedNodes;
147 }
int numOfVisitedNodes
Definition: STPTester.h:47
void inet::STPTester::handleMessage ( cMessage *  msg)
overridevirtual
45 {
46  if (msg->isSelfMessage()) {
48  if (isLoopFreeGraph())
49  EV_DEBUG << "The netwotrk is loop-free" << endl;
50  else
51  EV_DEBUG << "The netwotrk is not loop-free" << endl;
52  if (isConnectedGraph())
53  EV_DEBUG << "All nodes are connected with each other" << endl;
54  else
55  EV_DEBUG << "Not all nodes are connected with each other" << endl;
56  if (isTreeGraph())
57  EV_DEBUG << "The network topology is a tree topology" << endl;
58  scheduleAt(simTime() + checkTime, msg);
59  }
60  else {
61  throw cRuntimeError("This module only handle selfmessages");
62  }
63 }
simtime_t checkTime
Definition: STPTester.h:53
bool isLoopFreeGraph()
Definition: STPTester.cc:124
void depthFirstSearch()
Definition: STPTester.cc:65
bool isConnectedGraph()
Definition: STPTester.cc:129
bool isTreeGraph()
Definition: STPTester.cc:134
void inet::STPTester::initialize ( )
overridevirtual
38 {
39  checkTimer = new cMessage("checktime");
40  checkTime = par("checkTime");
41  scheduleAt(simTime() + checkTime, checkTimer);
42 }
simtime_t checkTime
Definition: STPTester.h:53
cMessage * checkTimer
Definition: STPTester.h:54
bool inet::STPTester::isConnectedGraph ( )
protected

Referenced by handleMessage().

130 {
131  return numOfNodes == numOfVisitedNodes;
132 }
int numOfVisitedNodes
Definition: STPTester.h:47
int numOfNodes
Definition: STPTester.h:48
bool inet::STPTester::isForwarding ( Topology::Node node,
unsigned int  portNum 
)
protected

Referenced by dfsVisit().

150 {
151  cModule *tmpIfTable = node->getModule()->getSubmodule("interfaceTable");
152  IInterfaceTable *ifTable = dynamic_cast<IInterfaceTable *>(tmpIfTable);
153 
154  // EtherHost has no InterfaceTable
155  if (ifTable == nullptr)
156  return true;
157 
158  cGate *gate = node->getModule()->gate("ethg$o", portNum);
159  InterfaceEntry *gateIfEntry = ifTable->getInterfaceByNodeOutputGateId(gate->getId());
160  Ieee8021dInterfaceData *portData = gateIfEntry->ieee8021dData();
161 
162  // If portData does not exist, then it implies that
163  // the node is not a switch
164  if (portData == nullptr)
165  return true;
166 
167  return portData->isForwarding();
168 }
bool inet::STPTester::isLoopFreeGraph ( )
protected

Referenced by handleMessage().

125 {
126  return !loop;
127 }
bool loop
Definition: STPTester.h:46
bool inet::STPTester::isTreeGraph ( )
protected

Referenced by handleMessage().

135 {
136  return !loop && (numOfNodes == numOfVisitedNodes);
137 }
int numOfVisitedNodes
Definition: STPTester.h:47
bool loop
Definition: STPTester.h:46
int numOfNodes
Definition: STPTester.h:48

Member Data Documentation

simtime_t inet::STPTester::checkTime
protected

Referenced by handleMessage(), and initialize().

cMessage* inet::STPTester::checkTimer = nullptr
protected

Referenced by initialize(), and ~STPTester().

std::map<Topology::Node *, int> inet::STPTester::color
protected

Referenced by depthFirstSearch(), and dfsVisit().

Topology inet::STPTester::graph
protected

Referenced by depthFirstSearch().

bool inet::STPTester::loop = false
protected
int inet::STPTester::numOfNodes = 0
protected
int inet::STPTester::numOfVisitedNodes = 0
protected
std::map<Topology::Node *, Topology::Node *> inet::STPTester::parent
protected

Referenced by depthFirstSearch(), and dfsVisit().


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