Changing the mobility model over time

645 views
Skip to first unread message

Sergio Cabrero Barros

unread,
Jun 23, 2010, 6:07:00 AM6/23/10
to ns-3-users
Hello everybody,

I'm trying to build an ad-hoc scenario where nodes change their
mobility model (e.g. from constant position to random walk in the
second 30 of simulation). Due to the behavior of MobilityHelper, if I
assign a new model, it is not installed in the nodes, because two
objects of the same type (in this case MobilityModel) cannot be
aggregated to a node.

Does anyone knows how to do this? Is there a way to disaggregate an
object from another?

Thanks in advance!
Sergio

Gustavo Carneiro

unread,
Jun 23, 2010, 6:46:48 AM6/23/10
to ns-3-...@googlegroups.com
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.

Here's some of my Python-based code that you can use as reference:

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)

 

Thanks in advance!
Sergio

--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.




--
Gustavo J. A. M. Carneiro
INESC Porto, UTM, WiN, http://win.inescporto.pt/gjc
"The universe is always one step beyond logic." -- Frank Herbert

Sergio Cabrero Barros

unread,
Jun 23, 2010, 7:41:03 AM6/23/10
to ns-3-users
Muito Obrigado! I will give it a try

On Jun 23, 12:46 pm, Gustavo Carneiro <gjcarne...@gmail.com> wrote:
> On Wed, Jun 23, 2010 at 11:07, Sergio Cabrero Barros <
>
> > ns-3-users+...@googlegroups.com<ns-3-users%2Bunsu...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/ns-3-users?hl=en.
>
> --
> Gustavo J. A. M. Carneiro
> INESC Porto, UTM, WiN,http://win.inescporto.pt/gjc

Sergio Cabrero Barros

unread,
Jul 14, 2010, 5:10:20 AM7/14/10
to ns-3-users
Hi again,

I can't manage to build a Hierchical model. I am trying to build a
Hierarchical model with this code (I've also tried with other
models... parameters...):

------------

MobilityHelper mobility;

RandomWaypointMobilityModel childModel =
RandomWaypointMobilityModel();

mobility.SetMobilityModel ("ns3::HierarchicalMobilityModel",
"Child", PointerValue(&childModel)); // Default parameters (Speed,
changes...)

mobility.Install(_nodes.Get(0));

-----------

but I'm getting this:

---------

assert failed. file=../src/mobility/constant-velocity-helper.cc,
line=69, cond="m_lastUpdate <= now"
Command ['/opt/ns-3.7/ns-3.7/build/debug/scratch/SmallEmergency']
exited with code -11

----------

What am I doing wrong?

Thanks,
Sergio
Reply all
Reply to author
Forward
0 new messages