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
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);
}
}