Sunday 2 November 2014

In AODV ns2 where can i find node's 

Position, Energy, Speed and Transmission range  ? 

>  In mobilenode.h ( ns-2.35/common ), you can find node's position ( X & Y ) and speed.

   >  In node.h ( ns-2.35/common ), you can find the energy of a node ( energy_model() -> energy() ).

   >  In god.h ( ns-2.35/mobile ), you can find Macro variable RANGE (Transmission Range).

I am back. Finally, I could make little time to write this post. I believe such information is available in elsewhere. But, I also believe explaining simple method of obtaining node position and current remaining energy would help a lot of people. I strongly suggest scanning the code of WFRP before reading the post further.

Alright, lets get on the work. First you have to include mobilenode.h (located in NSROOT/ns-2.xx/common/ ) into wfrp.h file. Add following line after #include <cmu-trace.h>
1#include <mobilenode.h>
We have to make little more modifications to wfrp.h, thus change the lines from 119 to 122 (wfrp.h) as below
1// Node Location
2double      posx;       // position x;
3double      posy;       // position y;
4 
5// Remaining Energy
6double      iEnergy;
At line 153 (wfrp.h) add following code
1// Energy Management
2void        update_energy();
3 
4// This node;
5MobileNode  *iNode;
Now we are going to update actual node position and energy. Add following code to line 147 of wfrp.cc :
1//initialize energy
2iEnergy = 0;
3 
4// Get pointer to the node
5iNode = (MobileNode *) (Node::get_node_by_address(index));

In above code get_node_by_address(nsaddr_t id) is located in $NSROOT/ns-2.xx/common/node.h, which obtains pointer to the node according to given address. The class Node contains various information about node, including energy model, location, speed, neighbors, etc.

Update the wfrp.cc code from the line 530 as below
1void
2WFRP::update_position() {
3 
4iNode->update_position();
5 
6posx = iNode->X();
7posy = iNode->Y();
8 
9#ifdef DEBUG
10printf("U (%.6f): UPDATE POSITION, for Node %d, X: %.4f  and Y : %.4f n", CURRENT_TIME, index, posx, posy);
11#endif
12 
13}
14 
15void
16WFRP:: update_energy() {
17iEnergy = iNode->energy_model()->energy();
18 
19#ifdef DEBUG
20printf("U (%.6f): UPDATE ENERGY, for Node %d, Energy %.4f n", CURRENT_TIME, index, iEnergy);
21#endif
22 
23}      

First routine (update_position) updates the position at request time and puts X and Y position to posx, posy respectively. Note, iNode->update_position() routine is in $NSROOT/ns-2.xx/common/mobilenode.cc. You may also obtain node’s current speed, radio range, and Z position.
Second routine (update_energy) gets nodes current remaining energy and puts it to iEnergy. For information refer to $NSROOT/ns-2.xx/mobile/energy-model.cc.
After completing modification just re-make. For location based routing protocols this might very useful. Leave comments here if you have any problems with the code.
Note : energyModel must be set in TCL file, in order to obtain node’s energy or energy model related information.

No comments:

Post a Comment