Skip to content

WIP: Add Node::RemoveDevice()

Tom Henderson requested to merge tomhenderson/ns-3-dev:remove-net-device into master

Presently, ns-3 can dynamically add but not remove NetDevice objects from Node objects. This patch proposes extensions to class Node to allow for dynamic NetDevice removal. The motivating use case is to more cleanly handle the removal of virtual devices (e.g. bridge devices, tunneling devices) but should also work for any NetDevice.

In real systems, a device removal (such as a virtual device) will not affect the naming of other devices. We would like to keep stable device identifiers (stable across the removal of a device). The present implementation and API makes this difficult by storing and naming devices as indices of a vector; if there are three NetDevices on a node, numbered 0, 1, 2, and the user removes 0, then 1 will shift to 0 and 2 to 1-- we want to avoid that.

The main API change from a user perspective is to avoid iterating on a Node's NetDevices as follows:

for (uint32_t i = 0; i < node->GetNDevices(); i++)
  {
    Ptr<NetDevice> nd = node->GetDevice (i);
    // do something with nd
  }

instead, the new API is to export a const reference to a std::map that can be iterated:

const std::map<uint32_t, Ptr<NetDevice> >& devices = m_node->GetDeviceMap ();
for (auto it = devices.begin (); it != devices.end (); it++)
  {
    Ptr<NetDevice> nd = it->second;
    // do something with nd
  }

The method Ptr Node::GetDevice (uint32_t index) is retained (to fetch directly by ifIndex).

I also added methods to register callbacks to listen for device removal events.

I chose to avoid keeping an underlying vector container and shrinking it upon removal, because that would shift the mapping of ifIndex to NetDevice; in practice, ifIndex numbers are generally stable.

One change I did not make was to the PointerValue attribute Node::DeviceList, to rename it to DeviceMap. This would break existing code in subtle ways because Config paths would start to silently fail. The underlying attribute value type of DeviceList was changed to ObjectMapValue from ObjectVectorValue, however.

Edited by Tom Henderson

Merge request reports