No. Once an interface is added to an object you cannot remove the interface or change it.
I've had the same problem, and this is how I've solved it. I use HierarchicalMobilityModel as the main model of each node. The Parent model can be NULL if you want, meaning that the position reported by the Child model is taken as absolute position. The Child mobility model is the model that you really want to use. To change from one mobility model to another you modify the Child attribute of the HierarchicalMobilityModel, as many times as you want.
class Bus(RBridge):
def __init__(self, random_mobility=False):
super(Bus, self).__init__()
static_mobility = ns3.StaticMobilityModel()
mobility = ns3.HierarchicalMobilityModel(Child=ns3.PointerValue(static_mobility))
self.AggregateObject(mobility)
def set_static_position(self):
"""Change the mobility model to static, making the bus appear stopped"""
mobility = self.GetObject(ns3.MobilityModel.GetTypeId())
pos = mobility.GetPosition()
static_mobility = ns3.StaticMobilityModel()
mobility.SetAttribute("Child", ns3.PointerValue(static_mobility))
mobility.SetPosition(pos)
def set_constant_speed(self, vx, vy):
"""Change the mobility model to constant speed"""
mobility = self.GetObject(ns3.MobilityModel.GetTypeId())
pos = mobility.GetPosition()
constant_speed_mobility = ns3.StaticSpeedMobilityModel()
mobility.SetAttribute("Child", ns3.PointerValue(constant_speed_mobility))
mobility.SetPosition(pos)
v = ns3.Vector()
v.x = vx
v.y = vy
v.z = 0
constant_speed_mobility.SetVelocity(v)
def set_constant_acceleration(self, ax, ay, vx=None, vy=None):
"""Change the mobility model to constant acceleration.
If vx or vy is None, current velocity is preserved."""
mobility = self.GetObject(ns3.MobilityModel.GetTypeId())
pos = mobility.GetPosition()
if vx is None or vy is None:
v = mobility.GetVelocity()
else:
v = ns3.Vector(vx, vy, 0)
accel_mobility = ns3.ConstantAccelerationMobilityModel()
mobility.SetAttribute("Child", ns3.PointerValue(accel_mobility))
mobility.SetPosition(pos)
a = ns3.Vector(ax, ay, 0)
accel_mobility.SetVelocityAndAcceleration(v, a)