Reputation: 1
New to ns3, thanks! I added energyModel to my ns3 nodes, and they work well. But I found that when the remaining energy is 0 the node is still work (send and receive packet), I set the EnergyDepletionCallback but I don't how to shutdown the node or NetDevice in my callback.
Here is my energy model:
Ptr<BasicEnergySource> energySource = CreateObject<BasicEnergySource>();
Ptr<WifiRadioEnergyModel> energyModel = CreateObject<WifiRadioEnergyModel>();
energySource->SetInitialEnergy (1);
energyModel->SetEnergySource (energySource);
energySource->AppendDeviceEnergyModel (energyModel);
WifiRadioEnergyModel::WifiRadioEnergyDepletionCallback callback =
MakeCallback (&FqAodvExample::EnergyDepletionCallback, this);
energyModel->SetEnergyDepletionCallback (callback);
// aggregate energy source to node
nodes.Get (i)->AggregateObject (energySource);
Upvotes: 0
Views: 303
Reputation: 1
ok, I find the answer. In ns-3, there are no concepts of shutdown a node or device. But we can set the interface down to cut off the communication.
Here is my code of EnergyDepletionCallback to set interface down:
std::pair<Ptr<Ipv4>, uint32_t> returnValue = interfaces.Get (i);
Ptr<Ipv4> ipv4 = returnValue.first;
uint32_t index = returnValue.second;
Ptr<Ipv4Interface> iface = ipv4->GetObject<Ipv4L3Protocol> ()->GetInterface (index);
NS_LOG_UNCOND (Simulator::Now().GetSeconds() << "s Set " << iface->GetAddress(0).GetLocal() << " down.");
ipv4->SetDown (index);
Upvotes: 0