c++ns-3

How to set up the position allocator when using Ramdomwaypoint model in NS-3


I tried to alter the example code(third.cc) by replacing the mobility model name(RandomWalk2dMobilityModel) with RandomWaypointMobilityModel. After running the code, it turned out to be an output like

assert failed. cond="m_position", msg="No position allocator added before using this model"

So basically this is the most relevant code with the error msg

MobilityHelper mobility;

mobility.SetPositionAllocator ("ns3::GridPositionAllocator",

"MinX", DoubleValue (0.0),

"MinY", DoubleValue (0.0),

"DeltaX", DoubleValue (5.0),

"DeltaY", DoubleValue (10.0),

"GridWidth", UintegerValue (3),

"LayoutType", StringValue ("RowFirst"));

// mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel", // "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));

mobility.SetMobilityModel ("ns3::RandomWaypointMobilityModel");
mobility.Install (wifiStaNodes);

mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");

mobility.Install (wifiApNode);

What I am confused about is before setting mobility model, there has already set up the position allocator it worked for randomwalk2d, however, obviously it does not work for randomwaypoint model. So how to deal with it? I'll appreciate if there is someone who can help me to figure it out.

Many thanks.


Solution

  • There should be actually TWO position allocators when you are using RandomWayPointModel.