aodv example with energy

1,708 views
Skip to first unread message

Emad Aldalu

unread,
Apr 9, 2014, 12:30:28 PM4/9/14
to ns-3-...@googlegroups.com
Hi all,
I need to update the aodv.cc example such that the node energy is considered. energy-model-example.cc looks so complex for me. A simpler example using energy model would be helpful for me. Can anyone help or suggest please?
I'm new to ns3.

Thanks,
Emad

Tommaso Pecorella

unread,
Apr 10, 2014, 2:13:15 AM4/10/14
to ns-3-...@googlegroups.com
Hi,

I fear you can't find an "easier" example. Feel free to ask about the things you didn't understand, but the example itself is pretty simple, so I'd suggest you to take your time and study the tutorial and manual.

Cheers,

T.

Jack Higgins

unread,
Apr 29, 2015, 8:13:28 AM4/29/15
to ns-3-...@googlegroups.com

Hi Mr Pecorella,

I am actually implementing the same example as described in the comment ( AODV with energy source on multiple nodes (25) ).

My way of implementing it is the following:

for(NodeContainer::Iterator j= fixedPosTop.Begin(); j!= fixedPosTop.End(); ++j){

            Ptr<BasicEnergySource> energySource = CreateObject<BasicEnergySource>();
            Ptr<WifiRadioEnergyModel> energyModel = CreateObject<WifiRadioEnergyModel>();

           energySource->SetInitialEnergy (300);
           energyModel->SetEnergySource (energySource);
           energySource->AppendDeviceEnergyModel (energyModel);
           energyModel->SetTxCurrentA(0.0174);

   // add energy source to node
           Ptr<Node> object = *j;
         object->AggregateObject (energySource);


              // adding tracing functions

           energySource->TraceConnectWithoutContext ("RemainingEnergy", MakeCallback (&RemainingEnergy));
   
           NS_ASSERT (energySource != NULL);
           energySource->TraceConnectWithoutContext ("TotalEnergyConsumption", MakeCallback (&TotalEnergy));

  }

-------------------------------------------------------------------------------

but for some reason I am getting results  like this:


1sec Current remaining energy = 249.222J
1sec Current remaining energy = 249.222J
1sec Current remaining energy = 249.222J
1sec Current remaining energy = 249.222J
2sec Current remaining energy = 248.403J
2sec Current remaining energy = 248.403J
2sec Current remaining energy = 248.403J
2sec Current remaining energy = 248.403J
2sec Current remaining energy = 248.403J
2sec Current remaining energy = 248.403J
2sec Current remaining energy = 248.403J
2sec Current remaining energy = 248.403J


all 25 nodes show the same energy in the same sec, which is not possible.  since not all the nodes are transmitting the same number of times.

Am I implementing the energy source incorrectly? if that is so, which is the best way to implement  energy sources for each node in the simulation?


Best regards,

Jack

Tommaso Pecorella

unread,
Apr 29, 2015, 1:35:13 PM4/29/15
to ns-3-...@googlegroups.com
No script, no answer.

Also, what's wrong with energy-model-example.cc ?

T.

Jack Higgins

unread,
Apr 29, 2015, 10:03:04 PM4/29/15
to ns-3-...@googlegroups.com


Hi, thanks for the reply. I attached the code I am using now.

There is nothing wrong with energy-model-example.cc, the only thing is that energy-model-example.cc only implements the energy source on 1 node.
Replicate the same behaviour for multiple nodes is simple enough, (or so I thought) ,  but I am basically obtaining the same energy on all nodes in the same second. (different node transmit different number of times therefore there should have different energy values at any given time)

Perhaps my way of connecting the trace sources is not correct or the way I am adding the energy source is wrong.  I am not a vergy good c++ programmer so maybe is just a silly mistake. Any help would be much appreciated.


Jack
wirelessExample2.cc

Tommaso Pecorella

unread,
Apr 30, 2015, 2:50:12 AM4/30/15
to ns-3-...@googlegroups.com
Hi,

I have absolutely no idea about what's wrong, but this works.
I'll leave to you to find the differences and why your code wasn't working.

Have fun,

T.
wirelessExample2.cc

Jack Higgins

unread,
May 1, 2015, 4:47:12 AM5/1/15
to ns-3-...@googlegroups.com

Thanks a lot!,

I was implementing such solution using EnergySourceContainer when I read your post. You also answered my future next questions regarding a tracing function with context , Thank you a lot.


Also, I noticed 2 unexpected behaviours in the simulation ,  First , The Energy Consumption icon does not appear next to the Nodes in the NetAnim program no matter what I do, Is there any trick to make it appear?
Second, the server seems to be receiving packages only from 1 client, 2000 packets are supposed to be sent from each client node, but the UdpRecvApp->GetReceived() function; only register a portion of one client (e.g.  1999 received , 1 packet lost).


Sorry for asking too many questions!,


Best Regards,

Jack

Tommaso Pecorella

unread,
May 1, 2015, 4:56:23 AM5/1/15
to ns-3-...@googlegroups.com
First question: no idea. Make sure to use the latest ns-3 and NetAnim. In case check directly with John.
Second question: no idea. It could be the routing, radio range, collisions, anything. It shouldn't have anything to do with the Energy tho. If you "strip" the energy from your simulation, you should have the same results [up to small differences due to random numbers]. If there's a huge difference... post the script.


Have fun,

T.

Jack Higgins

unread,
May 7, 2015, 12:09:51 AM5/7/15
to ns-3-...@googlegroups.com

Thanks , I will check that with John, and for the second problem try other solutions.


Khaled Soliman

unread,
Aug 5, 2015, 4:26:57 PM8/5/15
to ns-3-users
Hello All

I have tried the code but it's not working with more than the configured nodes (rows * columns). If I increased the rows or columns, the traffic couldn't reach the destination.
On the other hand, how can I link between the assigned energy level and the aodv routing protocol to drop the node which has empty battery.

Thanks for your support.

Jack Higgins

unread,
Aug 6, 2015, 2:50:04 AM8/6/15
to ns-3-users
Hello Khaled,

I made that example quite a while ago when I was learning  about AODV and energy model.  The file is a modification of WirelessExample.cc that comes with NS3. It is not by any means meant to be taken as a serious example. The code I implemented in that example is messy and hard to check (back then I was also learning NS3 coding standards).

The reason why the packets do not reach the destination is because as you modify the number of row and colums,  the spacing between the nodes changes as well. If the nodes are away more than 250 meters communication is not possible as the the max range of the node was set on 250 meters. The way that the spacing is set in the program is incorrect. Modify those lines of code and you should be able to get the example working with more nodes.

On your second question, I am not 100% sure but maybe you should read about malicious node setting I think that might lead you  to the right answer. As far as I know you can not just "kill the node" but you could make it drop the packets after the energy set in the node is depleted. ( This would simulate a node turning off after his energy is depleted).

Happy coding!.

Aya Hatem

unread,
Jan 16, 2019, 1:03:10 AM1/16/19
to ns-3-users
hello jack 
can you help me to modify in olsr protocol to take decision inside protocol based in remaining energy in ns 3
 
 

Jack Higgins

unread,
Jan 16, 2019, 10:31:01 AM1/16/19
to ns-3-users
Hi Aya,

As a general rule, you should make a new post when you have questions, not continue an old link like this.
Making a new post helps others to respond to your answer more quickly and also locate the answer more quickly.

As for your question, you should simply set the energy module in the scenario file and modify OLSR protocol to do something similar as in the example below.
In a protocol I created called ZEAL, I use the energy module to create a sleep and wakeup function in the protocol.  You can see the full code of my protocol
at www.bitbucket.com/acidcube/zeal. Or check my paper in IEEE xplore.

Regards, 

jack

void
ZealRoutingProtocol::SleepNode (Time sleepTime)
{
   Time scheduleTime = Simulator::Now() + sleepTime;
   //Time simulationTime = MilliSeconds(sinkMovTime*3*1000);
   Time simulationTime = MilliSeconds((sinkMovTime/2)*m_totalHalfCycles*1000);
   if(sleepTime > 0)
     {

       Ptr<Node> thisNode = m_ipv4->GetObject<Node>();
       Ptr<EnergySourceContainer> EnergySourceContainerOnNode = thisNode->GetObject<EnergySourceContainer> ();
       if(EnergySourceContainerOnNode != NULL)
         {

    	   //do not set the timer to wake up if the scheduled time is > simulationTime
    	   //(Avoids scheduling an event after the end of the simulation)
            if(scheduleTime < simulationTime)
              {
   	             m_sleepLimitTimer.SetFunction (&ZealRoutingProtocol::WakeUpNode,this);
   	             m_sleepLimitTimer.Schedule (sleepTime);
   	          }

    	    //Setting wifiRadio consumption to 0
            Ptr<BasicEnergySource> basicSourcePtr = DynamicCast<BasicEnergySource> (EnergySourceContainerOnNode->Get(0));
            Ptr<DeviceEnergyModel> basicRadioModelPtr = basicSourcePtr->FindDeviceEnergyModels ("ns3::WifiRadioEnergyModel").Get (0);
            basicRadioModelPtr->SetAttribute("RxCurrentA", DoubleValue (0.0));
            basicRadioModelPtr->SetAttribute("TxCurrentA", DoubleValue (0.0));
            basicRadioModelPtr->SetAttribute("IdleCurrentA", DoubleValue (0.0));
            basicRadioModelPtr->SetAttribute("CcaBusyCurrentA", DoubleValue (0.0));


            Ptr<NetDevice> dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (m_mainAddress));
            Ptr<WifiNetDevice> wifi = dev->GetObject<WifiNetDevice> ();
            Ptr<WifiPhy> phy = wifi->GetPhy();

            phy->SetSleepMode();

         }

     }
}

void
ZealRoutingProtocol::WakeUpNode ()
{
   //Wakes up the sleeping node

   Ptr<NetDevice> dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (m_mainAddress));
   Ptr<WifiNetDevice> wifi = dev->GetObject<WifiNetDevice> ();
   Ptr<WifiPhy> phy = wifi->GetPhy();
   phy->ResumeFromSleep();
   //Setting wifiRadio consumption to 0
   Ptr<Node> thisNode = m_ipv4->GetObject<Node>();
   Ptr<EnergySourceContainer> EnergySourceContrainerOnNode = thisNode->GetObject<EnergySourceContainer> ();
   Ptr<BasicEnergySource> basicSourcePtr = DynamicCast<BasicEnergySource> (EnergySourceContrainerOnNode->Get(0));

   double rmnEnergy = basicSourcePtr->GetRemainingEnergy ();
   //std::cout<<Simulator::Now().GetSeconds()<<" The node "<<m_mainAddress<<" WAKES UP | RMNENERGY "<<rmnEnergy<<"\n";

   Ptr<DeviceEnergyModel> basicRadioModelPtr = basicSourcePtr->FindDeviceEnergyModels ("ns3::WifiRadioEnergyModel").Get (0);
   basicRadioModelPtr->SetAttribute("RxCurrentA", DoubleValue (0.313));
   basicRadioModelPtr->SetAttribute("TxCurrentA", DoubleValue (0.38));
   basicRadioModelPtr->SetAttribute("IdleCurrentA", DoubleValue (0.273));
   basicRadioModelPtr->SetAttribute("CcaBusyCurrentA", DoubleValue (0.273));

   m_sleepNodeFlag = false;

   //if(m_localZone == 4)//(m_mainAddress == "10.1.1.63" )
	//  std::cout<<Simulator::Now().GetSeconds()<<" ++ WAKE UP "<<m_mainAddress<<"\n";

   if(!m_subSinkFlag)
     {
	    SendPacketFromQueue2();
	   // Time delay = MilliSeconds(0.5);
	   // Simulator::Schedule (delay, &ZealRoutingProtocol::SendPacketFromQueue2, this);
     }



}

Aya Hatem

unread,
Jan 17, 2019, 8:21:29 AM1/17/19
to ns-3-...@googlegroups.com
Thanks very much Jack

Regards 
Aya Hatem

--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.
To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at https://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.

Manoj Paul

unread,
Jan 27, 2020, 10:14:30 AM1/27/20
to ns-3-users
Hello Jack,
     I could not understand your code on ZEAL. I could not even run it properly in ns3.29, could you please let us know how energy can be controlled with this code or may be with other code block in AODV.


Thanks,
Manoj Paul

Jack Higgins

unread,
Jan 27, 2020, 8:15:54 PM1/27/20
to ns-3-users
Dear Paul,

This is an old post, try to make a new post when the thread is too old.

ZEAL was made for ns-3 3.25. Some things have changed since then.

Assuming that you correctly installed the ZEAL module and not just run the zeal example from the scratch folder (without installing the module),
The virtual function "printroutingtable" changed in the class Ipv4RoutingProtocol in the last ns-3 releases.
You need to update the correct number of parameters in this function in zeal-routing-protocol.cc and zeal-routing-protocol.h.

That is the only change I am aware of, other changes may exist.

To use AODV with energy, you need to set the energy module in your scenario file (the file where you set the topology, the interfaces and the type of routing protocol).
Refer to the energy module examples to see its usage. Alternatively, fix the zeal protocol and see the zeal example. This example is using the energy module.

Good luck"!

Regards,

Al

Manoj Paul

unread,
Feb 6, 2020, 10:34:33 PM2/6/20
to ns-3-users
Hello Jack,
     I have kept ns3 3.24 in my machine. And i also read the steps to add new module in ns3. Could you please let me know what is the correct way to install Zeal module since I am interested to know how energy module is working in AODV.


Have a nice day !!

Thanks,
Manoj Paul
Reply all
Reply to author
Forward
0 new messages