Finding Node Position,Velocity and Speed in NS2.34

In this article I would explain the use of three predefined functions in to access a nodes position,velocity and speed dynamically. Let me choose the AODV protocol.

1. Include mobilenode.h header in aodv.h


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

double xpos;

double ypos;

double zval;

int node_speed;

MobileNode *iNode;

3. In initialize the declared variables.

xpos = 0.0;
ypos = 0.0;
val = 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 run
make clean; make all

command after any 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).

One thought to “Finding Node Position,Velocity and Speed in NS2.34”

Leave a Reply

Your email address will not be published. Required fields are marked *