Implementing a simple MANET routing example

1,818 views
Skip to first unread message

Gokul

unread,
Aug 3, 2010, 6:22:14 PM8/3/10
to ns-3-users
Hello all

I am trying to implement a MANET routing example with 10 nodes, using
randomwaypoint mobility model and OLSR/AODV routing. The code works
fine when I use the constantvelocity mobility model. I have installed
the OnOff app on a few nodes and their corresponding destination nodes
have packetsink apps installed on them. I am getting a segmentation
fault when the randomwaypoint model is used. Could anyone please help?
The following is the code:

#include <fstream>
#include <string>
#include "ns3/core-module.h"
#include "ns3/common-module.h"
#include "ns3/node-module.h"
#include "ns3/helper-module.h"
#include "ns3/mobility-module.h"
#include "ns3/contrib-module.h"
#include "ns3/wifi-module.h"

using namespace ns3;

int
main (int argc,char *argv[])
{
uint32_t number_of_nodes = 10;
double stop_time = 500;

Config::SetDefault ("ns3::OnOffApplication::PacketSize", StringValue
("512"));
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue
("1000kb/s"));

NodeContainer nodes;
nodes.Create(number_of_nodes);

//Creating wifi devices

WifiHelper wifi;
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
YansWifiChannelHelper wifichan = YansWifiChannelHelper::Default();
wifiPhy.SetChannel(wifichan.Create());

NqosWifiMacHelper mac = NqosWifiMacHelper::Default ();
mac.SetType ("ns3::AdhocWifiMac");

wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode", StringValue ("wifia-54mbs"));

NetDeviceContainer devices = wifi.Install(wifiPhy,mac,nodes);

OlsrHelper olsr;
//AodvHelper aodv;
//
// Add the IPv4 protocol stack to the nodes in our container
//
InternetStackHelper internet;
internet.SetRoutingHelper (olsr);
//internet.SetRoutingHelper (aodv);
internet.Install (nodes);

Ipv4AddressHelper ipaddrss;
ipaddrss.SetBase("192.168.0.0", "255.255.255.0");
ipaddrss.Assign(devices);

MobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc =
CreateObject<ListPositionAllocator> ();
double x = 0.0;
double y = 0.0;

for (uint32_t i = 0; i< number_of_nodes; i++)
{
positionAlloc->Add(Vector (x,y,0.0));
x +=5.0;
y +=3.0;

mobility.SetPositionAllocator(positionAlloc);
}

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

//ConstantVelocityMobilityModel const_vel;
//const_vel.SetVelocity(Vector(100.0,100.0,0.0));
//mobility.SetMobilityModel("ns3::ConstantVelocityMobilityModel")
//const_vel=ns3.ConstantVelocityMobilityModel()
//const_vel.SetVelocity(ns3.Vector(100.0,100.0,0.0))

mobility.SetMobilityModel("ns3::RandomWaypointMobilityModel",
"Speed", RandomVariableValue(UniformVariable(0.1,1)), "Pause",
RandomVariableValue(ConstantVariable(0.2)));

mobility.Install(nodes);

uint32_t port = 5000;

OnOffHelper cbrgenhelper("ns3::UdpSocketFactory", Address());

cbrgenhelper.SetAttribute("OnTime", RandomVariableValue
(ConstantVariable (42)));
cbrgenhelper.SetAttribute("OffTime", RandomVariableValue
(ConstantVariable (0)));

ApplicationContainer cbrgen;
AddressValue remoteaddr;

for (uint32_t j = 0; j < 4; j++)
{
AddressValue remoteaddr
(InetSocketAddress(ipaddrss.Assign(devices).GetAddress(j+1),port));
cbrgenhelper.SetAttribute ("Remote", remoteaddr);
cbrgen.Add(cbrgenhelper.Install(nodes.Get(j)));
}

cbrgen.Start(Seconds(0.0));
cbrgen.Stop(Seconds(stop_time - 10.0));


for (uint32_t k = 0; k < 4; k++)
{
PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress
(ipaddrss.Assign(devices).GetAddress (k+1), port));
cbrgen.Add (sink.Install (nodes.Get (k+1)));
}

cbrgen.Start (Seconds (1.0));
cbrgen.Stop (Seconds (stop_time - 10.0));

Simulator::Stop (Seconds (90.0));

wifiPhy.EnablePcap("test", devices.Get(0), true);

Simulator::Run();
Simulator::Destroy();
}

Tom Henderson

unread,
Aug 4, 2010, 12:48:13 AM8/4/10
to ns-3-...@googlegroups.com
On 8/3/10 3:22 PM, Gokul wrote:
> Hello all
>
> I am trying to implement a MANET routing example with 10 nodes, using
> randomwaypoint mobility model and OLSR/AODV routing. The code works
> fine when I use the constantvelocity mobility model. I have installed
> the OnOff app on a few nodes and their corresponding destination nodes
> have packetsink apps installed on them. I am getting a segmentation
> fault when the randomwaypoint model is used. Could anyone please help?

To see where it is failing, try

./waf --command-template="gdb %s" --run <program-name>

In this case, it reported to me:
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff756d9f4 in ns3::RandomWaypointMobilityModel::BeginWalk (this=
0x6bf420) at ../src/mobility/random-waypoint-mobility-model.cc:62
62 Vector destination = m_position->GetNext ();

The code looked basically OK to me but then I noticed this comment in
the Doxygen for this class:

* The implementation of this model is not 2d-specific. i.e. if you provide
* a 3d random waypoint position model to this mobility model, the model
* will still work. There is no 3d position allocator for now but it should
* be trivial to add one.

And I noticed that you may be trying to use a 3-D position allocator?
Anyway, it seems that the problem may be that m_position is not
initialized properly.

Tom

Gokul Bhat

unread,
Aug 4, 2010, 10:29:09 AM8/4/10
to ns-3-...@googlegroups.com
Thanks. I don't need the 3D position allocator but I figured if I just insert a 0 in the z-coordinate argument, I will be fine. About the initialization, do you think there is something wrong in the way I am setting the mobility model?





--
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.




--
Gokul S Bhat
Ph.D Student, Electrical Engineering department, University of Florida, Gainesville

Gokul Bhat

unread,
Aug 8, 2010, 1:13:24 PM8/8/10
to ns-3-...@googlegroups.com
Hello

As I mentioned in my previous e mail as how I am trying to implement a simple MANET wifi routing scenario with 10 nodes. I am using OLSR routing for this purpose and the mobility model I am using is the randomwaypointmobility model. I encounter a segmentation fault and gdb says that it occurs here:

Vector destination = m_position->GetNext ();

On printing "m_position->GetNext(), gdb says that : Couldn't find method ns3::Ptr<ns3::PositionAllocator>::GetNext
I am confused as this is not the case. Please help.

P.S. I am pasting the code for your reference:

#include <fstream>
#include <string>
#include "ns3/core-module.h"
#include "ns3/common-module.h"
#include "ns3/node-module.h"
#include "ns3/helper-module.h"
#include "ns3/mobility-module.h"
#include "ns3/contrib-module.h"
#include "ns3/wifi-module.h"

using namespace ns3;

int
main (int argc,char *argv[])
{
    LogComponentEnable("OnOfftApplication", LOG_LEVEL_FUNCTION);

    LogComponentEnable("PacketSinkApplication", LOG_LEVEL_FUNCTION);

    LogComponentEnable("WifiPhy", LOG_LEVEL_ALL);
      Ptr<RandomRectanglePositionAllocator> positionAlloc = CreateObject<RandomRectanglePositionAllocator> ();
    //Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();

    /*double x = 0;
    double y = 0;*/
   
    positionAlloc->SetX (RandomVariable(ConstantVariable(100)));
    positionAlloc->SetY (RandomVariable(ConstantVariable(100)));
/*    for (uint32_t i = 0; i< number_of_nodes; ++i)
    {
        positionAlloc->Add(Vector (x,y,0.0));
        x = x + 0.5;
        y = y + 0.4;
       
    }*/

    mobility.SetPositionAllocator(positionAlloc);   
    //mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");

    //ConstantVelocityMobilityModel const_vel;
    //const_vel.SetVelocity(Vector(100.0,100.0,0.0));
    //mobility.SetMobilityModel("ns3::ConstantVelocityMobilityModel")
    //const_vel=ns3.ConstantVelocityMobilityModel()
    //const_vel.SetVelocity(ns3.Vector(100.0,100.0,0.0))   

    mobility.SetMobilityModel("ns3::RandomWaypointMobilityModel", "Speed", RandomVariableValue(UniformVariable(0.1,1)), "Pause", RandomVariableValue(ConstantVariable(0.2)));

    //mobility.SetMobilityModel("ns3::SteadyStateRandomWaypointMobilityModel", "MinSpeed", DoubleValue(0.1), "MaxSpeed", DoubleValue(20), "MinPause", DoubleValue(0.1), "MaxPause", DoubleValue(0.5),"MinX", DoubleValue(0), "MaxX", DoubleValue(1000), "MinY", DoubleValue(0), "MaxY", DoubleValue(1000.0));


    mobility.Install(nodes);

    uint32_t port = 5000;

    OnOffHelper cbrgenhelper("ns3::UdpSocketFactory", Address());
   
    cbrgenhelper.SetAttribute("OnTime", RandomVariableValue (ConstantVariable (42)));
    cbrgenhelper.SetAttribute("OffTime", RandomVariableValue (ConstantVariable (0)));

    ApplicationContainer cbrgen;
    AddressValue remoteaddr;
   
    for (uint32_t j = 0; j < 4; j++)
    {
        AddressValue remoteaddr (InetSocketAddress(ipaddrss.Assign(devices).GetAddress(j+1),port));
        cbrgenhelper.SetAttribute ("Remote", remoteaddr);
        cbrgen.Add(cbrgenhelper.Install(nodes.Get(j)));
    }
   
    cbrgen.Start(Seconds(0.0));
    cbrgen.Stop(Seconds(stop_time - 10.0));


    for (uint32_t k = 0; k < 4; k++)
    {
        PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (ipaddrss.Assign(devices).GetAddress (k+1), port));
        cbrgen.Add (sink.Install (nodes.Get (k+1)));
    }

    cbrgen.Start (Seconds (1.0));
    cbrgen.Stop (Seconds (stop_time - 10.0));

    Simulator::Stop (Seconds (500.0));

    wifiPhy.EnablePcap("test_less", devices.Get(0), true);

    Simulator::Run();
    Simulator::Destroy();

Gokul Bhat

unread,
Aug 11, 2010, 10:25:51 AM8/11/10
to ns-3-...@googlegroups.com
Could anyone please help or give any suggestions as I am completely
baffled by this segmentation fault?

Gustavo Carneiro

unread,
Aug 11, 2010, 11:19:23 AM8/11/10
to ns-3-...@googlegroups.com
On Wed, Aug 11, 2010 at 15:25, Gokul Bhat <gkoo...@gmail.com> wrote:
Could anyone please help or give any suggestions as I am completely
baffled by this segmentation fault?

On Sun, Aug 8, 2010 at 1:13 PM, Gokul Bhat <gkoo...@gmail.com> wrote:
> Hello
>
> As I mentioned in my previous e mail as how I am trying to implement a
> simple MANET wifi routing scenario with 10 nodes. I am using OLSR routing
> for this purpose and the mobility model I am using is the
> randomwaypointmobility model. I encounter a segmentation fault and gdb says
> that it occurs here:
> Vector destination = m_position->GetNext ();
>
> On printing "m_position->GetNext(), gdb says that : Couldn't find method
> ns3::Ptr<ns3::PositionAllocator>::GetNext

Ptr is a smart pointer, but GDB does not know it, it thinks it is a structure.  Try m_position.m_ptr->GetNext().




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

Gokul Bhat

unread,
Aug 12, 2010, 11:02:18 AM8/12/10
to ns-3-...@googlegroups.com
Thank you for that help. On printing m_position.m_ptr->GetNext():
Cannot access memory at 0x0
I am now trying to figure out the reason for this error. If anyone
could point me where to look at specifically or where should I begin
from, I would be grateful.

Thanks in advance.

Chris Facchini

unread,
Aug 25, 2010, 5:25:26 AM8/25/10
to ns-3-users
Hi,

On Aug 12, 5:02 pm, Gokul Bhat <gkool...@gmail.com> wrote:
> Thank you for that help. On printing m_position.m_ptr->GetNext():
> Cannot access memory at 0x0
> I am now trying to figure out the reason for this error. If anyone
> could point me where to look at specifically or where should I begin
> from, I would be grateful.

So, as Tom suggested, the simulation breaks at Vector destination =
m_position->GetNext ();
Indeed, as you have already seen, m_position points to NULL, that is,
m_position does not point to any PositionAllocator object.

Browsing the code you'll see that the only point when m_position is
initialized is inside SetAttribute ().
Such method provides a default value (PointerValue ()), which is, in
fact, NULL.

Now, what I tried was to also specify the "PositionAllocator"
attribute in the main simulation script:
mobility.SetMobilityModel ("ns3::RandomWaypointMobilityModel",
"Speed", RandomVariableValue (UniformVariable (0.1, 1)),
"Pause", RandomVariableValue (ConstantVariable (0.2)),
"PositionAllocator", DynamicCast<PositionAllocator>
(positionAlloc));

(I have used the dynamic_cast to turn the ListPositionallocator
pointer into a PositionAllocator pointer.)

And now, the bad news.
ns-3 complains about the fact that there is no matching function to
call SetMobilityModel. For reference, here is the error:
error: no matching function for call to
‘ns3::MobilityHelper::SetMobilityModel(const char [33], const char
[6], ns3::RandomVariableValue, const char [6],
ns3::RandomVariableValue, const char [18],
ns3::Ptr<ns3::PositionAllocator>)

To me there is anything wrong with that function, but facts show
otherwise.

Does anyone have a... pointer? :)

Thanks,
Chris

Gokul Bhat

unread,
Aug 25, 2010, 1:45:47 PM8/25/10
to ns-3-...@googlegroups.com
If that is the case, then what is the use of mobility.SetPositionAllocator(positionAlloc) ? Isnt this used to initialize the m_position?

--
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.

Gokul Bhat

unread,
Aug 26, 2010, 1:04:21 PM8/26/10
to ns-3-...@googlegroups.com
If instead of DynamicCast, I use "PointerValue(pointerAlloc) for initializing m_position, then that error is taken care of.

There are two different types of error I come across now.

In ns-3.8:

assert failed. file=../src/simulator/default-simulator-impl.cc, line=192, cond="tAbsolute.IsPositive ()"


Program received signal SIGSEGV, Segmentation fault.
0x015bfe16 in ns3::DefaultSimulatorImpl::Schedule (this=0x9188a50, time=@0xbfc95cbc, event=0x91c7948) at ../src/simulator/default-simulator-impl.cc:192
192      NS_ASSERT (tAbsolute.IsPositive ());


In ns-3.9:

mac=00:00:00:00:00:07] received size=56, from=00:00:00:00:00:0a
[mac=00:00:00:00:00:09] AdhocWifiMac:Enqueue(56, ff:ff:ff:ff:ff:ff)

aborted. cond="hiPart.hi != 0", msg="High precision 128 bits multiplication error: multiplication overflow.", file=../src/simulator/high-precision-cairo.cc, line=78
terminate called without an active exception

Program received signal SIGABRT, Aborted.
0x0012d422 in __kernel_vsyscall ()
Reply all
Reply to author
Forward
0 new messages