Bug 1386 - MobilityHelper use with RandomWaypointMobilityModel needs documentation
MobilityHelper use with RandomWaypointMobilityModel needs documentation
Status: RESOLVED DUPLICATE of bug 1314
Product: ns-3
Classification: Unclassified
Component: mobility models
pre-release
All All
: P3 normal
Assigned To: Pavel Boyko
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-03-02 19:43 EST by Tom Henderson
Modified: 2012-03-24 10:39 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Henderson 2012-03-02 19:43:37 EST
If one adds below the commented out statement to src/wimax/examples/wimax-ipv4.cc

  MobilityHelper mobility;
  //mobility.SetMobilityModel ("ns3::RandomWaypointMobilityModel");

the program will terminate with a segmentation fault.

The problem is that RandomWaypointMobilityModel (unlike others) requires that a PositionAllocator be provided to it.  The others just use the position allocator built into in the MobilityHelper to set initial position, then they don't need it anymore.  RandomWaypointMobilityModel, however, needs a position allocator. 

This can be remedied by passing in the position allocator, as in:

  Ptr<PositionAllocator> posAlloc = ...
  mobility.SetMobilityModel ("ns3::RandomWaypointMobilityModel", "PositionAllocator", PointerValue (posAlloc));

I think the easiest fix is as follows:

1) add a more helpful assert message here

--- a/src/mobility/model/random-waypoint-mobility-model.cc	Tue Feb 14 18:44:16 2012 +0000
+++ b/src/mobility/model/random-waypoint-mobility-model.cc	Fri Mar 02 16:37:05 2012 -0800
@@ -59,6 +59,7 @@
 {
   m_helper.Update ();
   Vector m_current = m_helper.GetCurrentPosition ();
+  NS_ASSERT_MSG (m_position, "No position allocator added before using this model");
   Vector destination = m_position->GetNext ();
   double speed = m_speed.GetValue ();
   double dx = (destination.x - m_current.x);

2) start some mobility model documentation and give some usage guidance for this model (ahem, there is no .rst file yet for mobility)

A small wrinkle here is which PositionAllocator to use for initial position when both the MobilityHelper and RandomWaypointMobilityModel each have an allocator? Probably the RandomWaypointMobilityModel one should be used, but this requires the MobilityHelper to do a downcast during Install() to check for this.
Comment 1 Tommaso Pecorella 2012-03-03 06:58:29 EST
+1 for the assert as a temporary fix.

About the PositionAllocator use, that's probably a design problem that have to be fixed on paper before implementing it.

About the documentaion, I'd like to talk about it in the next dev meeting. It's a point we have to fix once and for all, and it's not just affecting the mobility models.

Cheers,

T.
Comment 2 Mathieu Lacage 2012-03-24 10:39:03 EDT

*** This bug has been marked as a duplicate of bug 1314 ***