Finding Node Position,Velocity and Speed in NS2.34

My post on calculating node position and energy would have benefitted you in your work in ns2.In this article I would explain the use of three predefined functions in to access a nodes position,velocity and speed dynamically.As usual my work is on AODV protocol.

1. Add mobilenode.h header in aodv.h


2. In protected scope declare the variables you would be using to store the node parameters.

<see step5 in this post>

double xpos;

double ypos;

double zval;

int node_speed;

MobileNode  *iNode;

3. In initialize the declared variables.

xpos = 0.0;

ypos = 0.0;

zval = 0.0;

node_speed = 0;

MobileNode  *iNode;

4. Finally access the required functions from mobilenode.h. I am accesing those functions from AODV::forward() function
/***This code retrieves node position*****/

iNode = (MobileNode*) (Node::get_node_by_address(index));

((MobileNode *) iNode)->getLoc(&xpos,&ypos,&zpos);

printf(“Position of %d,  X=%f,  Y=%f,  Z=%f   \n “, index,  xpos, ypos, zpos);

/***This code retrieves the nodes velocity*****/

iNode = (MobileNode*) (Node::get_node_by_address(index));

((MobileNode *) iNode)->getVelo(&xpos, &ypos, &zpos);

printf(“Velocity of %d,  X=%f, Y=%f, Z=%f   \n”, index, xpos,  ypos, zpos);

/***This code retrieves the nodes speed*****/

iNode = (MobileNode*) (Node::get_node_by_address(index));

node_speed = ((MobileNode *) iNode)->speed();

printf(“Velocity of %d, Speed=%d  \n”,  index, node_speed);

Remember to make clean; make all after any such changes to or aodv.h

After all these steps are done, execute simple-wireless.tcl found at ~/ns-allinone-2.34/ns-2.34/tcl/ex with the protocol mentioned in it changed from DSDV to AODV. The result would be displayed on the terminal whenever AODV::forward() is invoked(in this case).

If you find any discrepancies in this post, please feel free to drop me a mail at By doing so, You would be saving the valuable time of many researchers.


10 comments on “Finding Node Position,Velocity and Speed in NS2.34

  1. Hi,
    Iam making these changes in and aodv.h to find nodes position and speed but nothing is appearing on the screen, Iam using make clean and make all.
    Could you please guide me regarding this problem.
    Thanks in advance

  2. Thanks for your great efforts.

    Could you please tell us how we can add these information to Hello packet?.


  3. hi
    I have done all d changes given by u including make clean n make all but i cant see d speed on d screen.
    Kindly help

  4. Hello,

    i tried to execute this exaple in order to get the position node but without success.
    i did not get the results in the terminal…

    thanks in advance for your help.

  5. can u help me regarding to my project :fast detection of replica node attack in mobile sensor network using sequential probability ratio test


  6. after making the above changes in the files i am getting this error

    /aodv/aodv.h:291: error: expected unqualified-id before ‘/’ token
    make: *** [aodv/aodv_logs.o] Error 1
    pleas help

  7. I am doing my M .E project in coopreative caching in MANET . Could you please help me in implementing this.

  8. your code is very useful for me to get the node energy and speed dynamically.
    but it prints the energy and speed of the node through which the packet have been transferred.
    For my project,i need to get the energy and speed of all nodE( i.e number of node that we have specified )dynamically.
    plz help can i get the energy and speed of all the node dynamically.


  9. Hello! It is nice to share us! However when I put all codes in aodv.h and accordingly and make clean and make all an error which says ‘get_node_by_adress’ is not a member of ‘Node’.What shall I do? By the way I am using ns-2.35.
    Thank You

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s