Battery Consumption in AODV

1,351 views
Skip to first unread message

B ABHISHEK

unread,
May 15, 2014, 4:13:55 AM5/15/14
to ns-3-...@googlegroups.com
Dear Friend ,

I want your help regarding Energy in Ad-hoc network .
In AODV how can i get rest energy in any node ...?

Konstantinos

unread,
May 15, 2014, 5:10:28 AM5/15/14
to ns-3-...@googlegroups.com
Hi, 

I can't clearly understand your question. It may have two meanings.

1) have a MANET scenario which runs AODV and get the energy of node at your screen for each node. 
Energy model does not relate to the Routing. So, whatever routing protocol you use, the way to get the energy in a node is the same as explained in the example for energy.

2) have a MANET scenario which runs AODV and you want the energy of the node within AODV so that you can do some route-optimization
In this case, the solution is same! 

See the example for energy in /src/energy/examples/
There you have something like this

66  Ptr<Node> node = CreateObject<Node> ();
67 
68  Ptr<SimpleDeviceEnergyModel> sem = CreateObject<SimpleDeviceEnergyModel> ();
69  Ptr<EnergySourceContainer> esCont = CreateObject<EnergySourceContainer> ();
70  Ptr<LiIonEnergySource> es = CreateObject<LiIonEnergySource> ();
71  esCont->Add (es);
72  es->SetNode (node);
73  sem->SetEnergySource (es);
74  es->AppendDeviceEnergyModel (sem);
75  sem->SetNode (node);
76  node->AggregateObject (esCont);

which creates a energy modes and sets it on the node. After this point you can get the energy model from the node. Therefore, within AODV you need the pointer to the node, and use GetObject() to get the EnergySourceContainer that gives the energy source. 

Emad Aldalu

unread,
Jun 8, 2014, 6:18:01 PM6/8/14
to ns-3-...@googlegroups.com
Hi Konstantinos,

Can you please elaborate on how to get the node remaining energy to be used as a new field in AODV header?

please check this code:
 /* energy source */
   BasicEnergySourceHelper basicSourceHelper;
   // configure energy source
   basicSourceHelper.Set ("BasicEnergySourceInitialEnergyJ", DoubleValue (0.9));
   // install source
   EnergySourceContainer sources = basicSourceHelper.Install (nodes);
   /* device energy model */
   WifiRadioEnergyModelHelper radioEnergyHelper;
   // configure radio energy model
   radioEnergyHelper.Set ("TxCurrentA", DoubleValue (0.0174));
   radioEnergyHelper.Set ("RxCurrentA", DoubleValue (0.0174));
   // install device model
   DeviceEnergyModelContainer deviceModels = radioEnergyHelper.Install (devices, sources);

Ptr<BasicEnergySource> basicSourcePtr0 = DynamicCast<BasicEnergySource> (sources.Get (0));
std::cout << "At " << Simulator::Now ().GetSeconds () << " Cell voltage: " << basicSourcePtr0->GetSupplyVoltage () << " V Remaining Capacity: " <<
 basicSourcePtr0->GetRemainingEnergy ()  << std::endl;

This code attaches the energy model to the nodes. Last line prints the node available energy. This code is in the main function. how can I use it in AODV? which file or files to edit in AODV?

Thanks,
Emad

Konstantinos

unread,
Jun 8, 2014, 6:31:01 PM6/8/14
to ns-3-...@googlegroups.com
What you are going to need in AODV is only the last part, i.e. the part that you say it prints node's available energy. 
Of course you need to have configured the Energy model on that node, meaning all the lines above in the main function are also needed in the scenario, but not in the AODV modifications.

Then when you construct the AODV header you will need to retrieve the energy similar to the way it is done by the two last lines you provided..

The files that need to be changed is those defining the AODV packet/header structure in order to add the extra field, the routing/neighbor-tables in order to keep track of the energy levels and the AODV-routing-protocol to actually add the energy level in the AODV header send it, read it and use it in the selection process.

Emad Aldalu

unread,
Jun 8, 2014, 7:03:52 PM6/8/14
to ns-3-...@googlegroups.com
Thank you Konstantinos for the quick response.
I'm new to ns-3 so please be patient :)
I still didn't get the point.
The nodes and the energy model are defined in the main function where the simulation scenario is defined. to use AODV as a routing protocol, the code below is used:

AodvHelper aodv;
  InternetStackHelper stack;
  stack.SetRoutingHelper (aodv); // has effect on the next Install ()
  stack.Install (nodes);

The AODV header is constructed automatically i.e. it is referred to aodv only in the above code.
as the remaining energy is changing, the value should be read every time a route discovery take place. so  basicSourcePtr0->GetRemainingEnergy () should be called from inside aodv-routing-protocol.
Is the node referenced in aodv-routing-protocol so that this value is taken from the node.

attached is the test.

Thanks
Emad
myaodv.cc

Emad Aldalu

unread,
Jun 9, 2014, 8:35:49 PM6/9/14
to ns-3-...@googlegroups.com
Hi Konstantinos
This is a quote from your reply above" 

"Therefore, within AODV you need the pointer to the node, and use GetObject() to get the EnergySourceContainer that gives the energy source"

can you please explain how to get the pointer to the node?

Thanks,
Emad

On Sunday, June 8, 2014 3:31:01 PM UTC-7, Konstantinos wrote:

Konstantinos

unread,
Jun 10, 2014, 5:08:24 AM6/10/14
to ns-3-...@googlegroups.com
In a similar way (GetObject) you can get the pointer to the node from the pointer to the IPv4.

See the very first lines of aodv-routing-protocol.cc

28 #define NS_LOG_APPEND_CONTEXT \
29  if (m_ipv4) { std::clog << "[node " << m_ipv4->GetObject<Node> ()->GetId () << "] "; }

Emad Aldalu

unread,
Jun 14, 2014, 11:47:37 AM6/14/14
to ns-3-...@googlegroups.com
Thank you Konstantinos for the continuous help.
I added the following code to aodv-routing-protocol.cc to get the pointer to the node:
Ptr<Node> node = m_ipv4->GetObject<Node>();
std::cout << node->GetId()<<std::endl;

it worked fine. And as there are 4 nodes in the scenario, it prints numbers from 0 to 3.
Now to get the energy source which was installed on the node, I tried the following code:

Ptr<BasicEnergySource>  source  =  node->GetObject<BasicEnergySource>();
std::cout << source->GetRemainingEnergy() <<std::endl; 

but this work doesnt work. it give this error:
Command ['/home/emad/Bake/source/my-ns-3.17/build/scratch/myaodv'] terminated with signal SIGSEGV. Run it under a debugger to get more information (./waf --run <program> --command-template="gdb --args %s <args>").

can you please help?

Thanks,
Emad

Konstantinos

unread,
Jun 14, 2014, 2:54:30 PM6/14/14
to ns-3-...@googlegroups.com
Have you installed an Energy model on the node?
i.e. what I have already posted in https://groups.google.com/d/msg/ns-3-users/S-Z9m3wLf60/MHVE178xoVQJ

Emad Aldalu

unread,
Jun 14, 2014, 3:12:23 PM6/14/14
to ns-3-...@googlegroups.com
Hi Konstantinos,
Yes. The energy model was installed on the nodes in myaodv.cc but not same as you posted.
The code below installs the energy model on the nodes. While I'm able to retrieve the remaining energy in the main test, I don't know how to retrieve the node remaining energy from inside aodv-routing-protocol.cc.
attached is myaodv.cc file.

Thanks,
Emad

 /////////  energy
  /* energy source */
   BasicEnergySourceHelper basicSourceHelper;
   // configure energy source
   basicSourceHelper.Set ("BasicEnergySourceInitialEnergyJ", DoubleValue (0.9));
   // install source
   EnergySourceContainer sources = basicSourceHelper.Install (nodes);
   /* device energy model */
   WifiRadioEnergyModelHelper radioEnergyHelper;
   // configure radio energy model
   radioEnergyHelper.Set ("TxCurrentA", DoubleValue (0.0174));
   radioEnergyHelper.Set ("RxCurrentA", DoubleValue (0.0174));
   // install device model
   DeviceEnergyModelContainer deviceModels = radioEnergyHelper.Install (devices, sources);
  ///////////////////////////////////////////////////////

  InstallInternetStack ();
  InstallApplications ();

  /** connect trace sources **/
    /***************************************************************************/
    // all sources are connected to node 1
    // energy source
    Ptr<BasicEnergySource> basicSourcePtr0 = DynamicCast<BasicEnergySource> (sources.Get (0));
    Ptr<BasicEnergySource> basicSourcePtr1 = DynamicCast<BasicEnergySource> (sources.Get (1));
    Ptr<BasicEnergySource> basicSourcePtr2 = DynamicCast<BasicEnergySource> (sources.Get (2));
    Ptr<BasicEnergySource> basicSourcePtr3 = DynamicCast<BasicEnergySource> (sources.Get (3));
    //basicSourcePtr->TraceConnectWithoutContext ("RemainingEnergy", MakeCallback (&RemainingEnergy));
    // device energy model
    Ptr<DeviceEnergyModel> basicRadioModelPtr =
      basicSourcePtr0->FindDeviceEnergyModels ("ns3::WifiRadioEnergyModel").Get (0);
    NS_ASSERT (basicRadioModelPtr != NULL);
    //basicRadioModelPtr->TraceConnectWithoutContext ("TotalEnergyConsumption", MakeCallback (&TotalEnergy));
    /*******************************

std::cout << "At " << Simulator::Now ().GetSeconds () << " Cell voltage: " << basicSourcePtr0->GetSupplyVoltage () << " V Remaining Capacity: " <<
   basicSourcePtr0->GetRemainingEnergy ()  << " Ah" << std::endl;
myaodv.cc

Konstantinos

unread,
Jun 14, 2014, 3:24:37 PM6/14/14
to ns-3-...@googlegroups.com
You should follow the same approach you use in the main to retrieve the energy also in the AODV
ie.
Ptr<BasicEnergySource> basicSourcePtr = DynamicCast<BasicEnergySource> (node);

Emad Aldalu

unread,
Jun 14, 2014, 3:52:26 PM6/14/14
to ns-3-...@googlegroups.com
Thank you Konstantinos.
I added the code as you described to aodv-routing-protocol.cc:

Ptr<Node> node = m_ipv4->GetObject<Node>();
std::cout << node->GetId()<<std::endl;

Ptr<BasicEnergySource> basicSourcePtr = DynamicCast<BasicEnergySource> (node);

std::cout << "Remaining Capacity: " << basicSourcePtr->GetRemainingEnergy () << std::endl;

Once the execution reaches the last line which should print the remaining energy, the program exits with the following error:
Command ['/home/emad/Bake/source/my-ns-3.17/build/scratch/myaodv'] terminated with signal SIGSEGV. Run it under a debugger to get more information (./waf --run <program> --command-template="gdb --args %s <args>").

Thanks,
Emad

Konstantinos

unread,
Jun 14, 2014, 4:54:22 PM6/14/14
to ns-3-...@googlegroups.com
Use the debugger to find what is the problem. Check if the pointer is instantiated correctly.

PS: something I noticed now, why are you using such an old version of NS-3? 3.17 is quite old and with ns-3.20 coming in a few days I would recommend to use the latest code in order to be able to provide you better support.

Emad Aldalu

unread,
Jun 14, 2014, 5:36:12 PM6/14/14
to ns-3-...@googlegroups.com
Hi Konstantinos,
The energy source pointer seems null.

Name : basicSourcePtr
Details:{m_ptr = 0x0}
Default:{...}
Decimal:{...}
Hex:{...}
Binary:{...}
Octal:{...}
Name : m_ptr
Details:0x0
Default:0x0
Decimal:0
Hex:0x0
Binary:0
Octal:0

Note that the Node pointer has value:
Name : node
Details:{m_ptr = 0x6b9660}
Default:{...}
Decimal:{...}
Hex:{...}
Binary:{...}
Octal:{...}

Is the way that we are following to return the energy source valid?
in the main, sources.Get( ) is passed to the function:
Ptr<BasicEnergySource> basicSourcePtr0 = DynamicCast<BasicEnergySource> (sources.Get (0));

Regarding the version, I installed ns-3 about five months ago. I guess it was the latest version.


Thanks,
Emad

Konstantinos

unread,
Jun 14, 2014, 6:33:51 PM6/14/14
to ns-3-...@googlegroups.com


On Saturday, June 14, 2014 10:36:12 PM UTC+1, Emad Aldalu wrote:
Hi Konstantinos,
sources.Get() returns a pointer to an energy source, while I thought it was returning a pointer to a node.
and since you do not have the energy sources, that's what you need to retrieve first. 
 
Try something like this

Ptr<EnergySourceContainer> EnergySourceContrainerOnNode = node->GetObject<EnergySourceContainer> ();
Ptr<BasicEnergySource> basicSourcePtr = DynamicCast<BasicEnergySource> (EnergySourceContrainerOnNode->Get(0));

The issue why you can not get the energy source directly from the node is that the object that is aggregated is the container not the single source as shown in the

...
54  if (EnergySourceContrainerOnNode == NULL)
55  {
56  ObjectFactory fac;
57  fac.SetTypeId ("ns3::EnergySourceContainer");
58  EnergySourceContrainerOnNode = fac.Create<EnergySourceContainer> ();
59  EnergySourceContrainerOnNode->Add (src);
60  (*i)->AggregateObject (EnergySourceContrainerOnNode);
61  }


Regarding the version, I installed ns-3 about five months ago. I guess it was the latest version.

 
FYI 3.17 released 1+yr ago and 5mths ago there was at least 3.19. I recommend using the latest version since there are a lot of changes which affect both WiFi and Energy models you want to use.

Emad Aldalu

unread,
Jun 14, 2014, 7:22:01 PM6/14/14
to ns-3-...@googlegroups.com
Thank you very much Konstantinos. You are helpful. 
That worked.
I'm also installing ns-3.19.

Emad
<div style="line-height:1;font-family:monospace,fixed;color:rgb(0,0,0);min-height:13px;white-space:pre-wrap;word-wrap:br
...

Emad Aldalu

unread,
Oct 10, 2014, 5:16:30 PM10/10/14
to ns-3-...@googlegroups.com
Hi Konstantinos,
I have added a new field (minEnergy) to aodv routing table. The field registers the minimum energy of the nodes along a path from the source to destination. Below is a sample output:
Node: 0 Time: 70s 
AODV Routing table
Destination Gateway Interface Flag Expire Hops MinEnergy
10.0.0.2 10.0.0.2 10.0.0.1 UP 2.58           1 1
10.0.0.3 10.0.0.2 10.0.0.1 UP 2.06           2 1
10.255.255.255 10.255.255.255 10.0.0.1 UP 9223371966.85 1 1
127.0.0.1 127.0.0.1 127.0.0.1 UP 9223371966.85 1 1

Node with ID=0 can reach node 10.0.0.3 with number of hops equal to 2 and the minimum energy of the nodes along the path is 1 J.
My goal is to chose the path based on the minimum energy. But AODV constructs only single path from the source to destination. Isn't it?
I noticed that in aodv-routing-protocol.cc, the protocol is either update an existing route or create a new route if none is exist.
How can minEnergy be used in the selection process?

Thanks,
Emad

Emad Aldalu

unread,
Oct 11, 2014, 2:31:57 PM10/11/14
to ns-3-...@googlegroups.com
Can anyone please help here?

maaly algharaibeh

unread,
Nov 22, 2014, 4:02:21 PM11/22/14
to ns-3-...@googlegroups.com


Dear Friend ,
i am new in ns2 my project is to increase the life time of network of the aodv protocol where i will add the initial energy  and energy consumption in the code and how to choose rout based on the energy on the path
thanks 
 

Thomas

unread,
May 26, 2021, 1:01:47 AM5/26/21
to ns-3-users
Hi Emad,
Please post the source code for aodv.cc which you have modified in this thread  and aodv routing table  with the sample output format given. It will be helpful for my research.
Thank you.

Hemant Saini

unread,
May 27, 2021, 9:37:40 AM5/27/21
to ns-3-users
hi emad pl share the aodv modified code that you succed 
Message has been deleted

Eric

unread,
Sep 14, 2021, 8:51:41 PM9/14/21
to ns-3-users
I want to record the residual energy of the node in the routing table.
So, I added an energy model to the main script(aodv.cc) and made it output remaining energy when receiving RREQ from aodv-routing-protocol.cc
and An entry called Remaining Energy was also added to the routing table.
I want to record Remaining Energy in the routing table, how to do it?

I'll upload my code here "//JJJ//" is the part I edited.
2021년 5월 27일 목요일 오후 10시 37분 40초 UTC+9에 Hemant Saini님이 작성:
aodv-routing-protocol.cc
aodv-routing-protocol.h
aodv.cc
aodv-rtable.h
aodv-rtable.cc

Ioannis Machaliotis

unread,
Jul 3, 2023, 12:24:55 PM7/3/23
to ns-3-users
Hello, 

I am studying the Energy Models in ns3 and for now I am focused on calculating the energy consumption of wifi nodes during my simulation. For that, I have to set the Initial Energy before I call my Energy Model.
Taking a look at this thread, I see that Eric's project has some similarities, and I thought I could learn from that.

So, my question falls at the aodv.cc file, line 141. How did you pick 10.0 for "BasicEnergySourceInitialEnergyJ"? 

Thank you :) 
Message has been deleted

igs...@gmail.com

unread,
Jul 3, 2023, 1:13:23 PM7/3/23
to ns-3-users
Hello Ioannis Machaliotis,

Generally, initial battery energy of the node is set with respect to the application and the expected node capability.
For example, if you use a wireless node which is assumed to uses continuous  power source, then setting any higher value for initial energy  will not have any implication - because, in such case, you only try to measure the total consumed energy at the end of the simulation.
But, if you are using the same wireless node, for example, on a drone, then you can not assume a very high value for initial energy.
Similarly, if you are using a wireless node as a tiny sensor node, then its initial battery energy is based on the allowed maximum size of the node, expected life of the node/network, as well as the financial budget of that project.

On the other hand, in a simulation, you are interested to show the effect of link failure due to exhausting batteries, with in a short duration  of simulations, then you may intentionally set very low initial energy to make that node 'dead' as early as possible.

So, simply, it depends on your application.

Charles Pandian.
Reply all
Reply to author
Forward
0 new messages