Search code examples
omnet++

Access other modules to obtain information in them in OMNeT++


In the AODV network, I set the application layer app of a certain node to udpEchoApp, and I hope to make some modifications in the cc file so that the routing table information of the node can be obtained in the application layer app. How should I do it, I have tried to use the following method cModule *parent=getParentModule(); cModule * sub=parent->getSubModule(routingTableRecorder);

But I still don't know how to use it, and the second sentence of code error is displayed. Hope someone can help me


Solution

  • From the application one can use findModuleByPath() to get the routing table of own node, for example that way:

    #include "inet/networklayer/ipv4/Ipv4RoutingTable.h"
    
    cModule *mod = findModuleByPath("^.ipv4.routingTable"); // ^ means parent module
    if (mod) {
        IIpv4RoutingTable *rt = dynamic_cast<IIpv4RoutingTable*>(mod);
          if (rt) {
             // now a routing table can be printed
             for (int i = 0; i < rt->getNumRoutes(); i++) {
                 Ipv4Route *e = rt->getRoute(i);
                 EV << e << endl;
             }
         }
    }