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

Records routing table changes into a file. More...

#include <RoutingTableRecorder.h>

Inheritance diagram for inet::RoutingTableRecorder:

Public Member Functions

 RoutingTableRecorder ()
 
virtual ~RoutingTableRecorder ()
 
virtual void receiveSignal (cComponent *source, simsignal_t signalID, cObject *obj, cObject *details) override
 

Protected Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void handleMessage (cMessage *) override
 
virtual void hookListeners ()
 
virtual void ensureRoutingLogFileOpen ()
 
virtual void receiveChangeNotification (cComponent *source, simsignal_t signalID, cObject *details)
 
virtual void recordInterfaceChange (cModule *host, const InterfaceEntry *ie, simsignal_t signalID)
 
virtual void recordRouteChange (cModule *host, const IRoute *route, simsignal_t signalID)
 

Private Attributes

FILE * routingLogFile
 

Detailed Description

Records routing table changes into a file.

See also
IPv4RoutingTable, IPv4Route

Constructor & Destructor Documentation

inet::RoutingTableRecorder::RoutingTableRecorder ( )
211 {
212  routingLogFile = nullptr;
213 }
FILE * routingLogFile
Definition: RoutingTableRecorder.h:92
inet::RoutingTableRecorder::~RoutingTableRecorder ( )
virtual
216 {
217 }

Member Function Documentation

void inet::RoutingTableRecorder::ensureRoutingLogFileOpen ( )
protectedvirtual
250 {
251  if (routingLogFile == nullptr) {
252  // hack to ensure that results/ folder is created
253  getSimulation()->getSystemModule()->recordScalar("hackForCreateResultsFolder", 0);
254 
255  std::string fname = getEnvir()->getConfig()->getAsFilename(CFGID_ROUTINGLOG_FILE);
256  routingLogFile = fopen(fname.c_str(), "w");
257  if (!routingLogFile)
258  throw cRuntimeError("Cannot open file %s", fname.c_str());
259  }
260 }
FILE * routingLogFile
Definition: RoutingTableRecorder.h:92
void inet::RoutingTableRecorder::handleMessage ( cMessage *  )
overrideprotectedvirtual
230 {
231  throw cRuntimeError(this, "This module doesn't process messages");
232 }
void inet::RoutingTableRecorder::hookListeners ( )
protectedvirtual
235 {
236  cModule *systemModule = getSimulation()->getSystemModule();
237  systemModule->subscribe(NF_INTERFACE_CREATED, this);
238  systemModule->subscribe(NF_INTERFACE_DELETED, this);
239  systemModule->subscribe(NF_INTERFACE_CONFIG_CHANGED, this);
240  systemModule->subscribe(NF_INTERFACE_IPv4CONFIG_CHANGED, this);
241  //systemModule->subscribe(NF_INTERFACE_IPv6CONFIG_CHANGED, this);
242  //systemModule->subscribe(NF_INTERFACE_STATE_CHANGED, this);
243 
244  systemModule->subscribe(NF_ROUTE_ADDED, this);
245  systemModule->subscribe(NF_ROUTE_DELETED, this);
246  systemModule->subscribe(NF_ROUTE_CHANGED, this);
247 }
simsignal_t NF_ROUTE_DELETED
Definition: NotifierConsts.cc:58
simsignal_t NF_INTERFACE_CONFIG_CHANGED
Definition: NotifierConsts.cc:51
simsignal_t NF_INTERFACE_CREATED
Definition: NotifierConsts.cc:48
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
simsignal_t NF_INTERFACE_DELETED
Definition: NotifierConsts.cc:49
void inet::RoutingTableRecorder::initialize ( int  stage)
overrideprotectedvirtual
220 {
221  cSimpleModule::initialize(stage);
222 
223  if (stage == INITSTAGE_NETWORK_LAYER) {
224  if (par("enabled").boolValue())
225  hookListeners();
226  }
227 }
virtual void hookListeners()
Definition: RoutingTableRecorder.cc:234
Initialization of network-layer protocols, stage 1.
Definition: InitStages.h:72
virtual int inet::RoutingTableRecorder::numInitStages ( ) const
inlineoverrideprotectedvirtual
101 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::RoutingTableRecorder::receiveChangeNotification ( cComponent *  source,
simsignal_t  signalID,
cObject *  details 
)
protectedvirtual
263 {
264  cModule *m = dynamic_cast<cModule *>(nsource);
265  if (!m)
266  m = nsource->getParentModule();
267  cModule *host = getContainingNode(m);
268  if (signalID == NF_ROUTE_ADDED || signalID == NF_ROUTE_DELETED || signalID == NF_ROUTE_CHANGED)
269  recordRouteChange(host, check_and_cast<const IRoute *>(obj), signalID);
270  else if (signalID == NF_INTERFACE_CREATED || signalID == NF_INTERFACE_DELETED)
271  recordInterfaceChange(host, check_and_cast<const InterfaceEntry *>(obj), signalID);
272  else if (signalID == NF_INTERFACE_CONFIG_CHANGED || signalID == NF_INTERFACE_IPv4CONFIG_CHANGED)
273  recordInterfaceChange(host, check_and_cast<const InterfaceEntryChangeDetails *>(obj)->getInterfaceEntry(), signalID);
274 }
simsignal_t NF_ROUTE_DELETED
Definition: NotifierConsts.cc:58
virtual void recordRouteChange(cModule *host, const IRoute *route, simsignal_t signalID)
Definition: RoutingTableRecorder.cc:306
simsignal_t NF_INTERFACE_CONFIG_CHANGED
Definition: NotifierConsts.cc:51
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:65
simsignal_t NF_INTERFACE_CREATED
Definition: NotifierConsts.cc:48
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
simsignal_t NF_INTERFACE_DELETED
Definition: NotifierConsts.cc:49
virtual void recordInterfaceChange(cModule *host, const InterfaceEntry *ie, simsignal_t signalID)
Definition: RoutingTableRecorder.cc:276
value< double, units::m > m
Definition: Units.h:1047
virtual void inet::RoutingTableRecorder::receiveSignal ( cComponent *  source,
simsignal_t  signalID,
cObject *  obj,
cObject *  details 
)
inlineoverridevirtual
98 { receiveChangeNotification(source, signalID, obj); }
virtual void receiveChangeNotification(cComponent *source, simsignal_t signalID, cObject *details)
Definition: RoutingTableRecorder.cc:262
void inet::RoutingTableRecorder::recordInterfaceChange ( cModule *  host,
const InterfaceEntry ie,
simsignal_t  signalID 
)
protectedvirtual
277 {
278  // Note: ie->getInterfaceTable() may be nullptr (entry already removed from its table)
279 
280  const char *tag;
281 
282  if (signalID == NF_INTERFACE_CREATED)
283  tag = "+I";
284  else if (signalID == NF_INTERFACE_DELETED)
285  tag = "-I";
286  else if (signalID == NF_INTERFACE_CONFIG_CHANGED)
287  tag = "*I";
288  else if (signalID == NF_INTERFACE_IPv4CONFIG_CHANGED)
289  tag = "*I";
290  else
291  throw cRuntimeError("Unexpected signal: %s", getSignalName(signalID));
292 
293  // action, eventNo, simtime, moduleId, ifname, address
295  fprintf(routingLogFile, "%s %" PRId64 " %s %d %s %s\n",
296  tag,
297  getSimulation()->getEventNumber(),
298  SIMTIME_STR(simTime()),
299  host->getId(),
300  ie->getName(),
301  (ie->ipv4Data() != nullptr ? ie->ipv4Data()->getIPAddress().str().c_str() : IPv4Address().str().c_str())
302  );
303  fflush(routingLogFile);
304 }
FILE * routingLogFile
Definition: RoutingTableRecorder.h:92
simsignal_t NF_INTERFACE_CONFIG_CHANGED
Definition: NotifierConsts.cc:51
simsignal_t NF_INTERFACE_CREATED
Definition: NotifierConsts.cc:48
simsignal_t NF_INTERFACE_IPv4CONFIG_CHANGED
Definition: NotifierConsts.cc:53
virtual void ensureRoutingLogFileOpen()
Definition: RoutingTableRecorder.cc:249
simsignal_t NF_INTERFACE_DELETED
Definition: NotifierConsts.cc:49
void inet::RoutingTableRecorder::recordRouteChange ( cModule *  host,
const IRoute route,
simsignal_t  signalID 
)
protectedvirtual
307 {
308  IRoutingTable *rt = route->getRoutingTableAsGeneric(); // may be nullptr! (route already removed from its routing table)
309 
310  const char *tag;
311  if (signalID == NF_ROUTE_ADDED)
312  tag = "+R";
313  else if (signalID == NF_ROUTE_CHANGED)
314  tag = "*R";
315  else if (signalID == NF_ROUTE_DELETED)
316  tag = "-R";
317  else
318  throw cRuntimeError("Unexpected signal: %s", getSignalName(signalID));
319 
320  // action, eventNo, simtime, moduleId, routerID, dest, dest netmask, nexthop
322  fprintf(routingLogFile, "%s %" PRId64 " %s %d %s %s %d %s\n",
323  tag,
324  getSimulation()->getEventNumber(),
325  SIMTIME_STR(simTime()),
326  host->getId(),
327  (rt ? rt->getRouterIdAsGeneric().str().c_str() : "*"),
328  route->getDestinationAsGeneric().str().c_str(),
329  route->getPrefixLength(),
330  route->getNextHopAsGeneric().str().c_str()
331  );
332  fflush(routingLogFile);
333 }
simsignal_t NF_ROUTE_DELETED
Definition: NotifierConsts.cc:58
FILE * routingLogFile
Definition: RoutingTableRecorder.h:92
simsignal_t NF_ROUTE_CHANGED
Definition: NotifierConsts.cc:59
simsignal_t NF_ROUTE_ADDED
Definition: NotifierConsts.cc:57
virtual void ensureRoutingLogFileOpen()
Definition: RoutingTableRecorder.cc:249

Member Data Documentation

FILE* inet::RoutingTableRecorder::routingLogFile
private

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