High memory usage by WifiPhy's ResumeFromOff() and SetOffMode()

36 views
Skip to first unread message

Ricardo

unread,
Dec 16, 2019, 10:22:26 PM12/16/19
to ns-3-users
Hi,

I'm writing the code for a routing protocol, and I'm having one issue when running simulations. The code worked just fine until I added a functionality to turn nodes on and off. It causes a memory leak (or something like that), the use of memory grows a lot during the simulations (the simulations have up to 10,000 nodes).

The code that I use to turn nodes on and off is:

void
RoutingProtocol::Enable ()
{
  NS_LOG_FUNCTION
(this);
  NS_LOG_DEBUG
("Turning on WifiNetDevice...");

 
Ptr<Node> node = m_ipv4->GetObject<Node> ();
 
Ptr<NetDevice> device = node->GetDevice (0);
 
Ptr<WifiNetDevice> wifi_device = DynamicCast<WifiNetDevice> (device);
 
Ptr<WifiPhy> wifi_phy = wifi_device->GetPhy ();

  wifi_phy
->ResumeFromOff ();

  wifi_phy
= 0;
  wifi_device
= 0;
  device
= 0;
  node
= 0;

  NS_LOG_DEBUG
("WifiNetDevice successfully turned on.");
}

void
RoutingProtocol::Disable ()
{
  NS_LOG_FUNCTION
(this);
  NS_LOG_DEBUG
("Turning off WifiNetDevice...");

 
Ptr<Node> node = m_ipv4->GetObject<Node> ();
 
Ptr<NetDevice> device = node->GetDevice (0);
 
Ptr<WifiNetDevice> wifi_device = DynamicCast<WifiNetDevice> (device);
 
Ptr<WifiPhy> wifi_phy = wifi_device->GetPhy ();

  wifi_phy
->SetOffMode ();

  wifi_phy
= 0;
  wifi_device
= 0;
  device
= 0;
  node
= 0;

  NS_LOG_DEBUG
("WifiNetDevice successfully turned off.");
}


RoutingProtocol is the class that inherits the Ipv4RoutingProtocol class.

Before the addition of these two functions (RoutingProtocol::Enable and  RoutingProtocol::Disable) there were no problems (memory usage remained very stable). Furthermore, even with these functions, but with the calls to ResumeFromOff() and SetOffMode() commented out, the memory leak/high memory usage does not occur. 

Something inside ResumeFromOff() and SetOffMode() causes this issue. I read the code of these two functions but I don't understand why or what causes the memory leak/high memory usage.

Does anyone know what may fix this issue I'm having?

Thanks! :)

PS. Currently, I'm using NS-3 version 3.29.

Ricardo

unread,
Dec 16, 2019, 10:49:07 PM12/16/19
to ns-3-users
Additional information:

In the script that configures the simulation, after I create the nodes, create the devices, install the internet stack into the devices, configure the mobility model, and install the routing protocol into the nodes, I schedule the calls to RoutingProtocol::Enable() and RoutingProtocol::Disable() for each node using:

Ptr<Node> node;
Ptr<my_routing_protocol::RoutingProtocol> routing_protocol;
uint32_t node_initial_time
, node_end_time;

for (uint32_t node_id = 0u; node_id < m_nodes_container.GetN (); ++node_id)
{
  node
= m_nodes_container.Get (node_id);
  routing_protocol
= node->GetObject<my_routing_protocol::RoutingProtocol> ();

 
// Assignment of the initial and ending time.
  node_initial_time
= ...;
  node_end_time
= ...;

 
Simulator::Schedule (Seconds (node_initial_time),
                       
&my_routing_protocol::RoutingProtocol::Enable,
                       routing_protocol
);
 
Simulator::Schedule (Seconds (node_end_time),
                       
&my_routing_protocol::RoutingProtocol::Disable,
                       routing_protocol
);
}


After that, I run the simulation.

Simulator::Stop (Seconds (m_simulation_duration));
Simulator::Run ();
Simulator::Destroy ();


Thanks in advance :)
Reply all
Reply to author
Forward
0 new messages