How to get current location of a node

2,543 views
Skip to first unread message

Gopal

unread,
Sep 10, 2012, 6:30:20 AM9/10/12
to omn...@googlegroups.com
Dear All

I am using regular/base Omnet  (no frameworks like INET).   I have two types of nodes ... fixed and mobile.  Would like fetch their x,y position.  In the NED files,  I may set their p tag either using matrix or ring or someother configuration.  Example:  @display("p=1000,1000,m,3,2000,2000");   However,  if I try to get the actual current location of the node using something like: 
xpos = atoi(dispString.getTagArg("p", 0))
ypos = atoi(dispString.getTagArg("p", 1)), 
then I get back xpos,ypos = (1000,1000) instead of something like (2000,4000).  

I know I could try to generate the actual position by inverting the initial @display formula ... eg.,  xpos = atoi(dispStr.getTagArg("p", 0)) + 2000*(id%3);  ... but this is not a generic mechanism and it assumes I know the exact layout method that was used.

Anyway to get the actual location of a node using some omnet API ?

regards
GA



Gopal

unread,
Sep 12, 2012, 5:10:24 AM9/12/12
to omn...@googlegroups.com
Any one have any idea on how to get current node position ?

Rudolf Hornig

unread,
Sep 12, 2012, 6:31:56 AM9/12/12
to omn...@googlegroups.com
Hi, unfortunately you cannot do this. 

If you need the position of the nodes you have to implement the module placement manually. (i.e. implement some kind of framework that is similar to the mobility module in INET).

There is (intentionally) no API to read back the positions of the icons. The reason:
- If you can read back the positions of the node, you can use them in your simulation (you want to do this too). 
- If you use these values then the result of your simulation will depend on the original layout (obviously).
- The icon layouting may be based on visual properties like how big is the icon size (in pixels)
- Now what will happen if you try to run your simulation in Cmdenv (i.e. from command line). layouting is not available in Cmdenv...

In short, you have to explicitly handle the location of the nodes and should not rely on the layouting algorithms in Tkenv. 
Rudolf

Gopal

unread,
Sep 13, 2012, 2:48:02 AM9/13/12
to omn...@googlegroups.com
Thank you Rudolf .... after much hunting I had begun to suspect that I would have to roll my own framework as well.  The plan was to have a bunch of mobile nodes moving around between fixed nodes (arranged in some pattern).   In order to check if the mobile node was within range of a fixed node,  I would need the "actual" x,y positions for all the nodes. 

regards
GA

Gayatri Prajapati

unread,
May 1, 2013, 12:39:02 AM5/1/13
to omn...@googlegroups.com
hello Gopal sir,
i ma Gayatri. i want to create a network of some fixed node and some mobile node. can you give me your code for that?
please...............

sifatm...@upesh.edu.pk

unread,
Jun 12, 2015, 2:34:13 AM6/12/15
to omn...@googlegroups.com
Dear Gopal! i also want to calculate position of each node but don't know how to calculate using base omnet so please if you found some solution then please share it with me.

Sara

unread,
Jun 17, 2015, 8:04:18 AM6/17/15
to omn...@googlegroups.com

Hello all,


PLZ I need help, I am looking for a two-dimensional coordinate system to locate a mobile node in MANET (to get its x y coordinates).


I would be thankful for any of your suggestions.

Alfonso Ariza Quintana

unread,
Jun 18, 2015, 3:44:09 AM6/18/15
to omn...@googlegroups.com

Position of the node

 

#include “ModuleAccess.h”

#include “IMobility.h”

 

        cModule host getContainingNode(this);

        IMobility  *mod = check_and_cast<IMobility *>(host->getSubmodule("mobility"));

        Coord pos = mod->getCurrentPosition();

       

 

If you want to have access to the position of all nodes

#include “ModuleAccess.h”

#include “IMobility.h”

#include <vector>

 

 

    cTopology topo("topo");

    topo.extractByProperty("node");

    std::vector< IMobility *> posVect;

 

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

    {

        cTopology::Node *destNode = topo.getNode(i);

        IMobility *mod;

        cModule *host = destNode->getModule();

        mod = check_and_cast<IMobility *>(host->getSubmodule("mobility"));

        posVect.push_back(mod);

    }

 

  // position of node i

        Coord pos = posVec[i]->->getCurrentPosition();

--
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.
Visit this group at http://groups.google.com/group/omnetpp.
For more options, visit https://groups.google.com/d/optout.

Sara Cherbal

unread,
Jun 22, 2015, 9:00:59 AM6/22/15
to omn...@googlegroups.com
Thank you so much for the help.

Syed Hasnain

unread,
Jul 9, 2015, 3:21:20 PM7/9/15
to omn...@googlegroups.com, aari...@hotmail.com
Can I get the current speed of a node in a similar way? If not, what's the procedure? 
Please help.

Alfonso Ariza Quintana

unread,
Jul 10, 2015, 3:47:50 AM7/10/15
to omn...@googlegroups.com

Yes, you can, there is other method getCurrentSpeed() that return the speed vector

 

Coord spVec = mob->getCurrentSpeed();

 

double speed = sqrt((spVec.x* spVec.x)+ (spVec.y* spVec.y)+ (spVec.z* spVec.z));

nwhite

unread,
Oct 8, 2015, 5:13:10 AM10/8/15
to OMNeT++ Users, aari...@hotmail.com
Hi everyone.. the good thing its working in cc file... however what if i want to include the location inside the MSG packet and tried to retrieve it at cc file specifically in handleLowerMsg function..thank you

mento...@gmail.com

unread,
Sep 3, 2016, 10:50:14 AM9/3/16
to OMNeT++ Users, aari...@hotmail.com
i am getting error in the following statement. getContainingNode was not declared in this scope
cModule host=getContainingNode(this);
I am using omnet version 5.
How should i resolve it?

DebuGitu

unread,
Jan 4, 2017, 10:34:54 PM1/4/17
to OMNeT++ Users, aari...@hotmail.com
I am trying to access the position of the node and I used this code but i am getting an error:
fatal error: ModuleAccess.h: No such file or directory
 #include "ModuleAccess.h"

mento...@gmail.com

unread,
Jan 6, 2017, 4:41:20 AM1/6/17
to OMNeT++ Users, aari...@hotmail.com
ModuleAccess.h is part of inet you must include inet namespace
#include <omnetpp.h>
using namespace omnetpp;

#include "inet/common/ModuleAccess.h"
#include "inet/mobility/contract/IMobility.h"
using namespace inet;

sifatm...@upesh.edu.pk

unread,
Feb 9, 2017, 11:56:46 AM2/9/17
to OMNeT++ Users, aari...@hotmail.com

Alfonso! it is a code for base omnet++ or for INET?

Alfonso Ariza Quintana

unread,
Feb 9, 2017, 12:10:13 PM2/9/17
to omn...@googlegroups.com

Inet 2.x

 

For inet 3.x, you can have access also, but the code change a bit,

This is an example that crate a vector with the address and mobility module of the nodes.

 

#include "inet/mobility/contract/IMobility.h

 

 

 

    cTopology topo("topo");

   topo.extractByProperty("networkNode");

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

    {

        cTopology::Node *destNode = topo.getNode(i);

        IMobility *mod;

        IInterfaceTable* itable = L3AddressResolver().findInterfaceTableOf(destNode->getModule());

        bool notfound = true;

        uint64_t add;

 

        for (int j = 0 ; j < itable->getNumInterfaces(); j++)

        {

            InterfaceEntry *e = itable->getInterface(j);

            if (e->getMacAddress().isUnspecified())

                continue;

            if (e->isLoopback())

                continue;

            if (!notfound)

                break;

            for(auto it = segmentMap.begin(); it != segmentMap.end();++it)

            {

                if (it->first == e->getMacAddress().getInt())

                {

                    notfound = false;

                    add = e->getMacAddress().getInt();

                    break;

                }

            }

        }

 

        if (notfound)

            continue;

 

        cModule *host = getContainingNode(destNode->getModule());

        mod = check_and_cast<IMobility *>(host->getSubmodule("mobility"));

        if (mod == nullptr)

            throw cRuntimeError("node or mobility module not found");

 

        vectorList[add] = mod;

    }

 

De: omn...@googlegroups.com [mailto:omn...@googlegroups.com] En nombre de sifatm...@upesh.edu.pk


Enviado el: jueves, 09 de febrero de 2017 17:57
Para: OMNeT++ Users <omn...@googlegroups.com>
CC: aari...@hotmail.com

adisi...@gmail.com

unread,
Apr 2, 2017, 3:37:03 PM4/2/17
to OMNeT++ Users, aari...@hotmail.com
Hello Alfonso Sir,

How can I get the position of a node, based on its IP address. I know the IP address of the node. How can I get this nodes position?

Regards,
Advithiya

adisi...@gmail.com

unread,
Apr 2, 2017, 4:59:01 PM4/2/17
to OMNeT++ Users, aari...@hotmail.com
I tried using this code. But when I ran it in the Debug mode, the execution directly jumps to the following line and I am unable to read the value of the variables. I have directly used this code in the Handle Message Function. Is there something I am missing? Kindly advice.

if (it->first == e_int->getMacAddress().getInt())

Regards,
Advithiya

adisi...@gmail.com

unread,
Apr 3, 2017, 6:25:17 AM4/3/17
to OMNeT++ Users, aari...@hotmail.com


Thank you sir. I did  the changes as you suggested. But now its showing an error saying  " ‘class inet::InterfaceEntry’ has no member named ‘first’" in the line

                                  if (((*it)->first) == (e->getMacAddress().getInt()))

      I added the header files for the "segmentMap" part.
                  
                     #include "inet/transportlayer/contract/udp/UDPControlInfo_m.h"
                     #include "inet/applications/udpapp/UDPBasicP2P.h"

    However I get the error saying "segmentMap" is not declared in this scope
   
            "for (auto it = segmentMap.begin(); it != segmentMap.end();++it)"

So I declared a vector "segmentMap" of type InterfaceEntry.

Kindly let me know what is wrong here.

Regards,
Advithiya.

Alfonso Ariza Quintana

unread,
Apr 3, 2017, 11:30:30 AM4/3/17
to omn...@googlegroups.com

If you have declared segmentMap of the type vector, it doesn’t have the field first.

 

I recommend to consult a c++ book, this is a c++ error.

Reply all
Reply to author
Forward
0 new messages