Obtaining Node Position and Energy Dynamically in NS2.34

To read this article in Scribd go <here>

For an alternative method to obtain a nodes position, go <here>

Happy to meet you in another interesting task in NS2!

This time we will “dynamically” calculate a nodes position and remaining energy.This post is based on the valuable tips mentioned <here>  by Elmurod Talipov.
Now to the task…
I will be modifying the sample script simple-wireless.tcl found at ~/ns-allinone-2.34/ns-2.34/tcl/ex and all my tasks in ns2 would be based on AODV protocol.

1. In simple-wireless.tcl, change the routing protocol to AODV, enable Energy model and set the initial energy value.

2. In the node configuration set the EnergyModel, Initial Energy value, power spent in receiving mode,transmit mode,idle mode and sleep mode.

3. Now we will move to the backend code(c++). Our edits would be performed only in aodv.cc and aodv.h.

4. In aodv.h,first include the following header file that contains the procedures/functions needed to access node postion,energy and several other functions.

#include <mobilenode.h>
You will find class AODV,  something like the one shown below.

5. In that, declare the following variables in “protected” scope.

With that, no more work to be done in aodv.h. What we have actually done here is to declare the variables that we will using in aodv.cc to record a nodes position and energy.

6. In aodv.cc, we will initialize the variables that we have just declared in aodv.h. This we do in the AODV “constructor“(invoked only once during node creation).

7. Next, we include the code to access the functions in mobilenode.h, that fetch the nodes current position and energy.

I have included that code AODV::forward() function, so that the nodes position and energy are printed each time it forwards a packet. Where and When you want them to be printed is your choice. Alternatively, you may have the code included in the function of your choice and have the output redirected to a file.

8. Thats all! All we have to do now is to run simple-wireless.tcl
$ns simple-wireless.tcl
and the output would be something like this:


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

This article is licensed under GNU GENERAL PUBLIC LICENSE

About these ads

58 comments on “Obtaining Node Position and Energy Dynamically in NS2.34

  1. Pingback: Finding Node Position,Velocity and Speed in NS2.34 « tutorMicman

  2. Hi manoj,
    Could you please help me on finding the waiting time of a wireless node.
    i am creating a new routing protocol for my final year B.Tech project and would request you to help me.

  3. Sir,
    I need a tcl script to find the residual energy of nodes after they transfer the packets in AODV i tried the above procedure i got error in the energymodel..can you plz help me to make out this…and one more issue is that I am using xgraph 12.1 and I need to rescale x axis value to have integers and no decimals since x axis is number of nodes..can you please help me to make out this..thanks in advance.

  4. hello sir,how to put different initial energy levels to different nodes……………pls give suggest me a solution……..

  5. sir,
    can you tell me how to do local repair in AODV using hand off approach??
    for this where i should edit plz suggest me sir

  6. Salam & Hello

    how we can redirect the out put on a file ??
    I need the value of received signal strength Pr and the position of node every x second on separately trace file
    please help,

  7. hi friends..
    pls help and save me

    i am abhi …now i am doing my b.tech project …i want code for DYNAMIC ROUTING WITH SECURITY CONSIDERATIONS…. Any one have code pls reply once..
    i want implemented in NS2 TOOL by using TCL language

  8. Hi, Manoj

    Could u give me some help on how to extract the current node’s own speed. Not just print on screen. Because I want to each node be able to know its speed, position in my Agent’s C++ code.

    Appreciated

    Dsheng

  9. hi friends,
    i am sambit, doing my m tech project on cooperative caching in manet. but i face some problems like
    how to make dynamic clustering among the nodes in manet
    how to spread data items inside manet
    how to call a c++ procedure from tcl script etc
    can any one help me in this regard.
    my mail id : sambitmshr2@gmail.com
    thanks

  10. hi Manoj
    i am facing some problems running this code.

    firstly in the node config part in the tcl file, the energyModel on line 94 and idlePower on line 98 are being considered as “invalid command names”.

    secondly when i comment them i am not getting the defined output (which mean at least the POSITION) in the simple.tr file.

    Kindly help asap

    Regards

  11. hi,
    I want a single node’s position. How i have to add the condition in the above program.Can u plz tell that condition.

    Jeru

  12. Hello;

    i tried to execute this exapmle without success.
    I did not get the informations in the terminal.
    shoul i do make et make install for ns-2 after modifying the aodv.cc and adodv.h?
    i get also en erro ‘invalid command name” when i add node-config -idlPower??
    Any help please ???????
    thanks in advance for your help.*
    siwar

  13. Hi BeroOo and everyone else
    can anyone of you please tell me how this code is running at their end?
    do we need to put some changes in it or what else

    Thanks and Regards

  14. Hello Manoj Sir,
    can I do the same changes in ns-2.31 version… can you please help me sir, what do I need to modify additionally…
    Thanks & Regards,
    Divya Ganesh

  15. I want to know what r the companies(like IBM, HCL….ect..) using NS2 for testing or developing or some other purpose….
    plzzz tell me……..

  16. We are doing our B.Tech main project on the topic:load balancing-An Approach Based on Clustering in Manet.We are planning to do this in NS2.We are completely new to this topic.And would like to know the details on the following:
    1.how to create nodes dynamically using cbrp
    2.selecting clusterheads

  17. hello.. monoj sir.. i successfully added above modification but i dont get printed value at my terminal window.. please do reply

  18. hi ,
    am not getting node ‘s position and energy……
    am just getting SORTING LISTS DONE…
    NS EXISTING…..
    please help me in sorting out this…

  19. hello
    will u please tell me how a node can go in sleep mode and come back to its real state, using AODV protocol in ns2.35

  20. can we assign different energy value for different nodes ?????????????????? in ns2
    then how?????????? plz……….help me

  21. on the last code ?? what does mean (index)
    it’s not declared ??? How can we declare it

    thank you so much

  22. Hi Everyone this is Jyoti from TechnoZonk.

    We can develop any kind of simulation based on NS2.

    NS2 Project Developers and NS2 Training In India. Having 14+ years experience in Networking, Linux and Network Simulator over 7+ years. First time Professional Ns2 Reserch projects development done by us and delivered more than 300 projects around India . Also trained more than 2000 students in ns2. Having strong knowledge to bring new domain and create strong professionals for the same.

    Contact us :9920118169
    for more info or email us on rungtajyoti@yahoo.co.in

  23. Sir,
    Could u please tell how to print the signal strength of a particular node in ns2. I have already printed the pr value by copying the print statement from propagation.cc to tworayground.cc. now plwase help me to print pr for a particular node sir…

  24. hello sir….can you tell me if we want to change power level on certain condition how we can do it.

  25. Hi,
    Thanks for your code.. tried the same.. i am getting segmentation fault.. I am very new to ns2.. Can you please tell me how to debug?

  26. hi manoj

    I’m mitra n i’m so happy to finad ur blog it’s so handy.
    thank u so much 4 ur awesome code, i’ve run itand it does work very well
    but i want to do the exact same thing in my tcl file
    i mean finding the current mobile node position in tcl code
    will u please help me out with it.
    i appreciate any help.

  27. how to compare particular node with current index value
    for example to compare 5 node with index value
    how to change code in aodv.cc file

  28. Hi,
    i want to print transmission energy and reception energy with node ID of whenever packet is sent and receive. I can print the transmission and receive energy whenever this operation is performed in wireless-phy.cc but unable to print the node ID. I’ll be grateful if anyone can guide how to print node ID in wireless-phy.cc.
    Regards,
    Najma

  29. i did all changes above mentioned. and when i execute make i am getting below error error: invalid use of incomplete type ‘class MobileNode’
    ypos=iNode->Y();
    please help me

  30. hi!
    I try to run simple-wireless.tcl follow your conduct but I see a error :
    invalid comman -energyModel
    so can you help me ?

  31. i implement this code to get the energy of node, make command was successful with out errors but when i compile tcl file it gives me segmentation fault. please can any one help me why this error and how to fix it???

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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