INET Framework for OMNeT++/OMNEST
inet::visualizer::RoutingTableVisualizerBase Class Referenceabstract

#include <RoutingTableVisualizerBase.h>

Inheritance diagram for inet::visualizer::RoutingTableVisualizerBase:
inet::visualizer::VisualizerBase inet::visualizer::RoutingTableCanvasVisualizer inet::visualizer::RoutingTableOsgVisualizer

Classes

class  DirectiveResolver
 
class  RouteVisualization
 

Public Member Functions

virtual ~RoutingTableVisualizerBase ()
 
virtual void receiveSignal (cComponent *source, simsignal_t signal, cObject *obj, cObject *details) override
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual void handleParameterChange (const char *name) override
 
virtual void subscribe ()
 
virtual void unsubscribe ()
 
virtual const RouteVisualizationcreateRouteVisualization (IPv4Route *route, cModule *node, cModule *nextHop) const =0
 
virtual const RouteVisualizationgetRouteVisualization (IPv4Route *route, int nodeModuleId, int nextHopModuleId)
 
virtual void addRouteVisualization (const RouteVisualization *routeVisualization)
 
virtual void removeRouteVisualization (const RouteVisualization *routeVisualization)
 
virtual std::vector< IPv4AddressgetDestinations ()
 
virtual void addRouteVisualizations (IIPv4RoutingTable *routingTable)
 
virtual void removeRouteVisualizations (IIPv4RoutingTable *routingTable)
 
virtual void removeAllRouteVisualizations ()
 
virtual void updateRouteVisualizations (IIPv4RoutingTable *routingTable)
 
virtual void updateAllRouteVisualizations ()
 
virtual std::string getRouteVisualizationText (const IPv4Route *route) const
 
virtual void refreshRouteVisualization (const RouteVisualization *routeVisualization) const =0
 
- Protected Member Functions inherited from inet::visualizer::VisualizerBase
virtual int numInitStages () const override
 
virtual Coord getPosition (const cModule *networkNode) const
 
virtual Coord getContactPosition (const cModule *networkNode, const Coord &fromPosition, const char *contactMode, double contactSpacing) const
 
virtual InterfaceEntrygetInterfaceEntry (cModule *networkNode, cModule *module) const
 

Protected Attributes

LineManagerlineManager = nullptr
 
std::map< std::tuple< const IPv4Route *, int, int >, const RouteVisualization * > routeVisualizations
 
Parameters
bool displayRoutingTables = false
 
bool displayRoutesIndividually = false
 
bool displayLabels = false
 
NetworkNodeFilter destinationFilter
 
NetworkNodeFilter nodeFilter
 
cFigure::Color lineColor
 
cFigure::LineStyle lineStyle
 
double lineShift = NaN
 
const char * lineShiftMode = nullptr
 
double lineWidth = NaN
 
double lineContactSpacing = NaN
 
const char * lineContactMode = nullptr
 
StringFormat labelFormat
 
cFigure::Font labelFont
 
cFigure::Color labelColor
 
- Protected Attributes inherited from inet::visualizer::VisualizerBase
cModule * visualizerTargetModule = nullptr
 
const char * tags = nullptr
 

Constructor & Destructor Documentation

inet::visualizer::RoutingTableVisualizerBase::~RoutingTableVisualizerBase ( )
virtual
63 {
65  unsubscribe();
66 }
bool displayRoutingTables
Definition: RoutingTableVisualizerBase.h:60
virtual void unsubscribe()
Definition: RoutingTableVisualizerBase.cc:116

Member Function Documentation

void inet::visualizer::RoutingTableVisualizerBase::addRouteVisualization ( const RouteVisualization routeVisualization)
protectedvirtual

Reimplemented in inet::visualizer::RoutingTableCanvasVisualizer.

Referenced by inet::visualizer::RoutingTableCanvasVisualizer::addRouteVisualization(), and addRouteVisualizations().

151 {
152  auto key = std::make_tuple(routeVisualization->route, routeVisualization->sourceModuleId, routeVisualization->destinationModuleId);
153  routeVisualizations[key] = routeVisualization;
154 }
std::map< std::tuple< const IPv4Route *, int, int >, const RouteVisualization * > routeVisualizations
Definition: RoutingTableVisualizerBase.h:79
void inet::visualizer::RoutingTableVisualizerBase::addRouteVisualizations ( IIPv4RoutingTable routingTable)
protectedvirtual

Referenced by updateAllRouteVisualizations(), and updateRouteVisualizations().

184 {
185  L3AddressResolver addressResolver;
186  auto node = getContainingNode(check_and_cast<cModule *>(routingTable));
187  for (auto destination : getDestinations()) {
188  if (!routingTable->isLocalAddress(destination)) {
189  auto route = routingTable->findBestMatchingRoute(destination);
190  if (route != nullptr) {
191  auto gateway = route->getGateway();
192  auto nextHop = addressResolver.findHostWithAddress(gateway.isUnspecified() ? destination : gateway);
193  if (nextHop != nullptr) {
194  auto routeVisualization = getRouteVisualization(displayRoutesIndividually ? route : nullptr, node->getId(), nextHop->getId());
195  if (routeVisualization == nullptr)
197  else {
198  routeVisualization->numRoutes++;
199  refreshRouteVisualization(routeVisualization);
200  }
201  }
202  }
203  }
204  }
205 }
virtual void addRouteVisualization(const RouteVisualization *routeVisualization)
Definition: RoutingTableVisualizerBase.cc:150
virtual std::vector< IPv4Address > getDestinations()
Definition: RoutingTableVisualizerBase.cc:162
virtual void refreshRouteVisualization(const RouteVisualization *routeVisualization) const =0
virtual const RouteVisualization * getRouteVisualization(IPv4Route *route, int nodeModuleId, int nextHopModuleId)
Definition: RoutingTableVisualizerBase.cc:143
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:65
virtual const RouteVisualization * createRouteVisualization(IPv4Route *route, cModule *node, cModule *nextHop) const =0
bool displayRoutesIndividually
Definition: RoutingTableVisualizerBase.h:61
virtual const RouteVisualization* inet::visualizer::RoutingTableVisualizerBase::createRouteVisualization ( IPv4Route route,
cModule *  node,
cModule *  nextHop 
) const
protectedpure virtual
std::vector< IPv4Address > inet::visualizer::RoutingTableVisualizerBase::getDestinations ( )
protectedvirtual

Referenced by addRouteVisualizations().

163 {
164  L3AddressResolver addressResolver;
165  std::vector<IPv4Address> destinations;
166  for (cModule::SubmoduleIterator it(getSystemModule()); !it.end(); it++) {
167  auto networkNode = *it;
168  if (isNetworkNode(networkNode) && destinationFilter.matches(networkNode)) {
169  auto interfaceTable = addressResolver.findInterfaceTableOf(networkNode);
170  for (int i = 0; i < interfaceTable->getNumInterfaces(); i++) {
171  auto interface = interfaceTable->getInterface(i);
172  if (interface->ipv4Data() != nullptr) {
173  auto address = interface->ipv4Data()->getIPAddress();
174  if (!address.isUnspecified())
175  destinations.push_back(address);
176  }
177  }
178  }
179  }
180  return destinations;
181 }
bool matches(const cModule *module) const
Definition: NetworkNodeFilter.cc:29
bool isNetworkNode(const cModule *mod)
Returns true if the given module is a network node, i.e.
Definition: ModuleAccess.cc:28
NetworkNodeFilter destinationFilter
Definition: RoutingTableVisualizerBase.h:63
const RoutingTableVisualizerBase::RouteVisualization * inet::visualizer::RoutingTableVisualizerBase::getRouteVisualization ( IPv4Route route,
int  nodeModuleId,
int  nextHopModuleId 
)
protectedvirtual

Referenced by addRouteVisualizations().

144 {
145  auto key = std::make_tuple(route, nodeModuleId, nextHopModuleId);
146  auto it = routeVisualizations.find(key);
147  return it == routeVisualizations.end() ? nullptr : it->second;
148 }
std::map< std::tuple< const IPv4Route *, int, int >, const RouteVisualization * > routeVisualizations
Definition: RoutingTableVisualizerBase.h:79
std::string inet::visualizer::RoutingTableVisualizerBase::getRouteVisualizationText ( const IPv4Route route) const
protectedvirtual

Referenced by inet::visualizer::RoutingTableCanvasVisualizer::refreshRouteVisualization().

252 {
253  DirectiveResolver directiveResolver(route);
254  return labelFormat.formatString(&directiveResolver);
255 }
StringFormat labelFormat
Definition: RoutingTableVisualizerBase.h:72
const char * formatString(IDirectiveResolver *resolver) const
Definition: StringFormat.cc:29
void inet::visualizer::RoutingTableVisualizerBase::handleParameterChange ( const char *  name)
overrideprotectedvirtual
95 {
96  if (name != nullptr) {
97  if (!strcmp(name, "destinationFilter"))
98  destinationFilter.setPattern(par("destinationFilter"));
99  else if (!strcmp(name, "nodeFilter"))
100  nodeFilter.setPattern(par("nodeFilter"));
101  else if (!strcmp(name, "labelFormat"))
102  labelFormat.parseFormat(par("labelFormat"));
104  }
105 }
StringFormat labelFormat
Definition: RoutingTableVisualizerBase.h:72
void setPattern(const char *pattern)
Definition: NetworkNodeFilter.cc:24
NetworkNodeFilter nodeFilter
Definition: RoutingTableVisualizerBase.h:64
void parseFormat(const char *format)
Definition: StringFormat.cc:24
NetworkNodeFilter destinationFilter
Definition: RoutingTableVisualizerBase.h:63
virtual void updateAllRouteVisualizations()
Definition: RoutingTableVisualizerBase.cc:237
void inet::visualizer::RoutingTableVisualizerBase::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::visualizer::VisualizerBase.

Reimplemented in inet::visualizer::RoutingTableOsgVisualizer, and inet::visualizer::RoutingTableCanvasVisualizer.

Referenced by inet::visualizer::RoutingTableCanvasVisualizer::initialize().

69 {
71  if (!hasGUI()) return;
72  if (stage == INITSTAGE_LOCAL) {
73  displayRoutingTables = par("displayRoutingTables");
74  displayRoutesIndividually = par("displayRoutesIndividually");
75  displayLabels = par("displayLabels");
76  destinationFilter.setPattern(par("destinationFilter"));
77  nodeFilter.setPattern(par("nodeFilter"));
78  lineColor = cFigure::Color(par("lineColor"));
79  lineStyle = cFigure::parseLineStyle(par("lineStyle"));
80  lineWidth = par("lineWidth");
81  lineShift = par("lineShift");
82  lineShiftMode = par("lineShiftMode");
83  lineContactSpacing = par("lineContactSpacing");
84  lineContactMode = par("lineContactMode");
86  labelFormat.parseFormat(par("labelFormat"));
87  labelFont = cFigure::parseFont(par("labelFont"));
88  labelColor = cFigure::Color(par("labelColor"));
90  subscribe();
91  }
92 }
cFigure::LineStyle lineStyle
Definition: RoutingTableVisualizerBase.h:66
StringFormat labelFormat
Definition: RoutingTableVisualizerBase.h:72
cFigure::Font labelFont
Definition: RoutingTableVisualizerBase.h:73
void setPattern(const char *pattern)
Definition: NetworkNodeFilter.cc:24
bool displayRoutingTables
Definition: RoutingTableVisualizerBase.h:60
static LineManager * getLineManager(const cCanvas *canvas)
Definition: LineManager.cc:27
NetworkNodeFilter nodeFilter
Definition: RoutingTableVisualizerBase.h:64
const char * lineContactMode
Definition: RoutingTableVisualizerBase.h:71
virtual void subscribe()
Definition: RoutingTableVisualizerBase.cc:107
double lineShift
Definition: RoutingTableVisualizerBase.h:67
virtual void initialize(int stage) override
Definition: VisualizerBase.cc:29
Local initializations.
Definition: InitStages.h:35
LineManager * lineManager
Definition: RoutingTableVisualizerBase.h:77
Color
Definition: DiffservUtil.h:30
void parseFormat(const char *format)
Definition: StringFormat.cc:24
cFigure::Color lineColor
Definition: RoutingTableVisualizerBase.h:65
cModule * visualizerTargetModule
Definition: VisualizerBase.h:31
bool displayRoutesIndividually
Definition: RoutingTableVisualizerBase.h:61
bool displayLabels
Definition: RoutingTableVisualizerBase.h:62
cFigure::Color labelColor
Definition: RoutingTableVisualizerBase.h:74
NetworkNodeFilter destinationFilter
Definition: RoutingTableVisualizerBase.h:63
double lineWidth
Definition: RoutingTableVisualizerBase.h:69
const char * lineShiftMode
Definition: RoutingTableVisualizerBase.h:68
double lineContactSpacing
Definition: RoutingTableVisualizerBase.h:70
void inet::visualizer::RoutingTableVisualizerBase::receiveSignal ( cComponent *  source,
simsignal_t  signal,
cObject *  obj,
cObject *  details 
)
overridevirtual
129 {
130  Enter_Method_Silent();
131  if (signal == NF_ROUTE_ADDED || signal == NF_ROUTE_DELETED || signal == NF_ROUTE_CHANGED) {
132  auto routingTable = check_and_cast<IIPv4RoutingTable *>(source);
133  auto networkNode = getContainingNode(check_and_cast<cModule *>(source));
134  if (nodeFilter.matches(networkNode))
135  updateRouteVisualizations(routingTable);
136  }
137  else if (signal == NF_INTERFACE_IPv4CONFIG_CHANGED)
139  else
140  throw cRuntimeError("Unknown signal");
141 }
simsignal_t NF_ROUTE_DELETED
Definition: NotifierConsts.cc:58
bool matches(const cModule *module) const
Definition: NetworkNodeFilter.cc:29
NetworkNodeFilter nodeFilter
Definition: RoutingTableVisualizerBase.h:64
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:65
simsignal_t NF_INTERFACE_IPv4CONFIG_CHANGED
Definition: NotifierConsts.cc:53
simsignal_t NF_ROUTE_CHANGED
Definition: NotifierConsts.cc:59
simsignal_t NF_ROUTE_ADDED
Definition: NotifierConsts.cc:57
virtual void updateRouteVisualizations(IIPv4RoutingTable *routingTable)
Definition: RoutingTableVisualizerBase.cc:231
virtual void updateAllRouteVisualizations()
Definition: RoutingTableVisualizerBase.cc:237
virtual void inet::visualizer::RoutingTableVisualizerBase::refreshRouteVisualization ( const RouteVisualization routeVisualization) const
protectedpure virtual
void inet::visualizer::RoutingTableVisualizerBase::removeAllRouteVisualizations ( )
protectedvirtual

Referenced by updateAllRouteVisualizations().

221 {
222  std::vector<const RouteVisualization *> removedRouteVisualizations;
223  for (auto it : routeVisualizations)
224  removedRouteVisualizations.push_back(it.second);
225  for (auto it : removedRouteVisualizations) {
227  delete it;
228  }
229 }
std::map< std::tuple< const IPv4Route *, int, int >, const RouteVisualization * > routeVisualizations
Definition: RoutingTableVisualizerBase.h:79
virtual void removeRouteVisualization(const RouteVisualization *routeVisualization)
Definition: RoutingTableVisualizerBase.cc:156
void inet::visualizer::RoutingTableVisualizerBase::removeRouteVisualization ( const RouteVisualization routeVisualization)
protectedvirtual

Reimplemented in inet::visualizer::RoutingTableCanvasVisualizer.

Referenced by removeAllRouteVisualizations(), inet::visualizer::RoutingTableCanvasVisualizer::removeRouteVisualization(), and removeRouteVisualizations().

157 {
158  auto key = std::make_tuple(routeVisualization->route, routeVisualization->sourceModuleId, routeVisualization->destinationModuleId);
159  routeVisualizations.erase(routeVisualizations.find(key));
160 }
std::map< std::tuple< const IPv4Route *, int, int >, const RouteVisualization * > routeVisualizations
Definition: RoutingTableVisualizerBase.h:79
void inet::visualizer::RoutingTableVisualizerBase::removeRouteVisualizations ( IIPv4RoutingTable routingTable)
protectedvirtual

Referenced by updateRouteVisualizations().

208 {
209  auto networkNode = getContainingNode(check_and_cast<cModule *>(routingTable));
210  std::vector<const RouteVisualization *> removedRouteVisualizations;
211  for (auto it : routeVisualizations)
212  if (std::get<1>(it.first) == networkNode->getId() && it.second)
213  removedRouteVisualizations.push_back(it.second);
214  for (auto it : removedRouteVisualizations) {
216  delete it;
217  }
218 }
std::map< std::tuple< const IPv4Route *, int, int >, const RouteVisualization * > routeVisualizations
Definition: RoutingTableVisualizerBase.h:79
virtual void removeRouteVisualization(const RouteVisualization *routeVisualization)
Definition: RoutingTableVisualizerBase.cc:156
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:65
void inet::visualizer::RoutingTableVisualizerBase::subscribe ( )
protectedvirtual

Referenced by initialize().

108 {
109  auto subscriptionModule = getModuleFromPar<cModule>(par("subscriptionModule"), this);
110  subscriptionModule->subscribe(NF_ROUTE_ADDED, this);
111  subscriptionModule->subscribe(NF_ROUTE_DELETED, this);
112  subscriptionModule->subscribe(NF_ROUTE_CHANGED, this);
113  subscriptionModule->subscribe(NF_INTERFACE_IPv4CONFIG_CHANGED, this);
114 }
simsignal_t NF_ROUTE_DELETED
Definition: NotifierConsts.cc:58
simsignal_t NF_INTERFACE_IPv4CONFIG_CHANGED
Definition: NotifierConsts.cc:53
simsignal_t NF_ROUTE_CHANGED
Definition: NotifierConsts.cc:59
simsignal_t NF_ROUTE_ADDED
Definition: NotifierConsts.cc:57
void inet::visualizer::RoutingTableVisualizerBase::unsubscribe ( )
protectedvirtual

Referenced by ~RoutingTableVisualizerBase().

117 {
118  // NOTE: lookup the module again because it may have been deleted first
119  auto subscriptionModule = getModuleFromPar<cModule>(par("subscriptionModule"), this, false);
120  if (subscriptionModule != nullptr) {
121  subscriptionModule->unsubscribe(NF_ROUTE_ADDED, this);
122  subscriptionModule->unsubscribe(NF_ROUTE_DELETED, this);
123  subscriptionModule->unsubscribe(NF_ROUTE_CHANGED, this);
124  subscriptionModule->unsubscribe(NF_INTERFACE_IPv4CONFIG_CHANGED, this);
125  }
126 }
simsignal_t NF_ROUTE_DELETED
Definition: NotifierConsts.cc:58
simsignal_t NF_INTERFACE_IPv4CONFIG_CHANGED
Definition: NotifierConsts.cc:53
simsignal_t NF_ROUTE_CHANGED
Definition: NotifierConsts.cc:59
simsignal_t NF_ROUTE_ADDED
Definition: NotifierConsts.cc:57
void inet::visualizer::RoutingTableVisualizerBase::updateAllRouteVisualizations ( )
protectedvirtual

Referenced by handleParameterChange(), and receiveSignal().

238 {
240  for (cModule::SubmoduleIterator it(getSystemModule()); !it.end(); it++) {
241  auto networkNode = *it;
242  if (isNetworkNode(networkNode) && nodeFilter.matches(networkNode)) {
243  L3AddressResolver addressResolver;
244  auto routingTable = addressResolver.findIPv4RoutingTableOf(networkNode);
245  if (routingTable != nullptr)
246  addRouteVisualizations(routingTable);
247  }
248  }
249 }
bool matches(const cModule *module) const
Definition: NetworkNodeFilter.cc:29
NetworkNodeFilter nodeFilter
Definition: RoutingTableVisualizerBase.h:64
virtual void addRouteVisualizations(IIPv4RoutingTable *routingTable)
Definition: RoutingTableVisualizerBase.cc:183
bool isNetworkNode(const cModule *mod)
Returns true if the given module is a network node, i.e.
Definition: ModuleAccess.cc:28
virtual void removeAllRouteVisualizations()
Definition: RoutingTableVisualizerBase.cc:220
void inet::visualizer::RoutingTableVisualizerBase::updateRouteVisualizations ( IIPv4RoutingTable routingTable)
protectedvirtual

Referenced by receiveSignal().

232 {
233  removeRouteVisualizations(routingTable);
234  addRouteVisualizations(routingTable);
235 }
virtual void addRouteVisualizations(IIPv4RoutingTable *routingTable)
Definition: RoutingTableVisualizerBase.cc:183
virtual void removeRouteVisualizations(IIPv4RoutingTable *routingTable)
Definition: RoutingTableVisualizerBase.cc:207

Member Data Documentation

NetworkNodeFilter inet::visualizer::RoutingTableVisualizerBase::destinationFilter
protected
bool inet::visualizer::RoutingTableVisualizerBase::displayLabels = false
protected
bool inet::visualizer::RoutingTableVisualizerBase::displayRoutesIndividually = false
protected
bool inet::visualizer::RoutingTableVisualizerBase::displayRoutingTables = false
protected
cFigure::Color inet::visualizer::RoutingTableVisualizerBase::labelColor
protected
cFigure::Font inet::visualizer::RoutingTableVisualizerBase::labelFont
protected
StringFormat inet::visualizer::RoutingTableVisualizerBase::labelFormat
protected
cFigure::Color inet::visualizer::RoutingTableVisualizerBase::lineColor
protected
const char* inet::visualizer::RoutingTableVisualizerBase::lineContactMode = nullptr
protected
double inet::visualizer::RoutingTableVisualizerBase::lineContactSpacing = NaN
protected
double inet::visualizer::RoutingTableVisualizerBase::lineShift = NaN
protected
const char* inet::visualizer::RoutingTableVisualizerBase::lineShiftMode = nullptr
protected
cFigure::LineStyle inet::visualizer::RoutingTableVisualizerBase::lineStyle
protected
double inet::visualizer::RoutingTableVisualizerBase::lineWidth = NaN
protected
NetworkNodeFilter inet::visualizer::RoutingTableVisualizerBase::nodeFilter
protected
std::map<std::tuple<const IPv4Route *, int, int>, const RouteVisualization *> inet::visualizer::RoutingTableVisualizerBase::routeVisualizations
protected

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