cTopology and getDistanceToTarget

18 views
Skip to first unread message

imtit...@gmail.com

unread,
May 29, 2021, 8:16:21 PM5/29/21
to OMNeT++ Users

I am using the following code to get the number of hops from the current node to the target node. The problem is that the number of hops is very large (inf) whent I cast it to string. Also, it gives me the same number of hops to all nodes  :

cTopology topo;

      topo.extractByModulePath(cStringTokenizer("*.router*").asVector());

      cTopology::Node *thisNode = topo.getNodeFor(getParentModule());

      broadcastmsg=1;

   for (int i = 0; i < topo.getNumNodes(); i++) {

    if (topo.getNode(i) == thisNode) continue; // skip ourselves

      {cModule *targetModule =topo.getNode(i)->getModule();

      EV_INFO << "We are "<<topo.getNode(i)->getDistanceToTarget()<<"hops to to target.\n";

      }

    }

Help is much appreciated 

Alfonso Ariza Quintana

unread,
May 31, 2021, 3:45:41 AM5/31/21
to omn...@googlegroups.com
you need to call calculateUnweightedSingleShortestPathsTo() first to compute the route. This only works in wired network.

De: omn...@googlegroups.com <omn...@googlegroups.com> en nombre de imtit...@gmail.com <imtit...@gmail.com>
Enviado: domingo, 30 de mayo de 2021 2:16
Para: OMNeT++ Users <omn...@googlegroups.com>
Asunto: [Omnetpp-l] cTopology and getDistanceToTarget
 
--
You received this message because you are subscribed to the Google Groups "OMNeT++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/omnetpp/060650d9-2802-46e7-8c59-57059e6f0532n%40googlegroups.com.

imtit...@gmail.com

unread,
Jun 1, 2021, 5:20:43 PM6/1/21
to OMNeT++ Users
Thanks  Alfonso  for reply.
I did what you suggested. I called calculateUnweightedSingleShortestPathsTo() but still I get zeros by topo.getNode(i)->getDistanceToTarget():

      cTopology topo;
      topo.extractByModulePath(cStringTokenizer("*.router*").asVector());
      cTopology::Node *thisNode = topo.getNodeFor(getParentModule());
      broadcastmsg=1;
      cTopology::Node *node ;
    for (int i = 0; i < topo.getNumNodes(); i++) {
        node= topo.getNode(i);
    if (node == thisNode) { // skip ourselves
               continue;}
     targetNode->enable();
    topo.calculateUnweightedSingleShortestPathsTo(targetNode);
    EV_INFO << "There are "<<topo.getNode(i)->getDistanceToTarget()<<"hops.\n";
      }

imtit...@gmail.com

unread,
Jun 1, 2021, 5:29:50 PM6/1/21
to OMNeT++ Users
I have a wired network, and this piece of code is located in app[0] in the router .ini file is following:
**.router*.numApps = 1
**.router*.app[0].typename = "CoIDS"

Alfonso Ariza Quintana

unread,
Jun 2, 2021, 4:14:30 AM6/2/21
to omn...@googlegroups.com
This is that I suspect.
I suspect that you are extracting only a part of your network
topo.extractByModulePath(cStringTokenizer("*.router*").asVector());

If this is true, cTopology cannot find a route in the set of extracted nodes.



Enviado: martes, 1 de junio de 2021 23:20
Para: OMNeT++ Users <omn...@googlegroups.com>
Asunto: Re: [Omnetpp-l] cTopology and getDistanceToTarget
 
Reply all
Reply to author
Forward
0 new messages