Finding Energy, node position and speed in AODV - NS2 Tutorial # 11.1

AODV - Part 2

Finding the node position, energy and speed of the node while it is forwarding a packet.

By default, these codes are not there in AODV, so we are going to modify or append in AODV protocol..


Steps
Step 1:

Open aodv.h and aodv.cc, these two files will be modified

Step 2:

Declare variables in aodv.h file in protected mode


double xpos,ypos,zpos,energy_t;

int n_speed;

MobileNode *t_node;

FILE *fp;


Step 3:

initialize these values inside the constrctor of aodv.cc file


xpos=ypos=zpos=0.0;

n_speed=0;

energy_t=0.0;

fp=fopen("runtime.dat","w");

Step 4:

add the following statements to the forward() function of aodv.cc

fprintf(fp,"Position is X, Y, Z, Node Speed,Energy\n");

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

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

fprintf(fp,"%d %f %f %f",index,xpos,ypos,zpos);

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

n_speed=((MobileNode*)t_node)->speed();

energy_t=t_node->energy_model()->energy();

fprintf(fp,"%d %d %f\n",index,n_speed,energy_t);


After the above step,

Step5:

recompile ns2 using the command

$] make

Step 6:

run a TCL File and check for the runtime.dat file in the same folder.

$] ns AODV.tcl

You will get a file called as runtime.dat in the same folder.

use the file for plotting any characteristics.

Thanks for watching.

Please share and subscribe to my Video channel.

More lectrures to come.

Youtube.com/tspradeepkumar

https://www.nsnam.com



T S Pradeep Kumar