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> |
1 | // Node Location |
2 | double posx; // position x; |
3 | double posy; // position y; |
4 |
5 | // Remaining Energy |
6 | double iEnergy; |
1 | // Energy Management |
2 | void update_energy(); |
3 |
4 | // This node; |
5 | MobileNode *iNode; |
1 | //initialize energy |
2 | iEnergy = 0; |
3 |
4 | // Get pointer to the node |
5 | iNode = (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
1 | void |
2 | WFRP::update_position() { |
3 |
4 | iNode->update_position(); |
5 |
6 | posx = iNode->X(); |
7 | posy = iNode->Y(); |
8 |
9 | #ifdef DEBUG |
10 | printf ( "U (%.6f): UPDATE POSITION, for Node %d, X: %.4f and Y : %.4f n" , CURRENT_TIME, index, posx, posy); |
11 | #endif |
12 |
13 | } |
14 |
15 | void |
16 | WFRP:: update_energy() { |
17 | iEnergy = iNode->energy_model()->energy(); |
18 |
19 | #ifdef DEBUG |
20 | printf ( "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