SetVelocity returns segmentation fault

239 views
Skip to first unread message

Rukna

unread,
Feb 2, 2015, 1:12:52 PM2/2/15
to ns-3-...@googlegroups.com
I am trying to change the velocity of Wi-Fi nodes in adhoc mode. 
By following code, I am trying to change the velocity:
================================
Ptr<ConstantVelocityMobilityModel> model = container.Get(0)->GetObject<ConstantVelocityMobilityModel>();
  model->SetVelocity(Vector(10,0,0));
================================

However, it gives me segmentation fault. Then, I run the debugger and I got following errors:
=======================================
Starting program: /home/delta/ns3/bake/source/ns-3.17/build/scratch/lab 
whe[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0xb7f6c358 in ns3::operator<= (lhs=..., rhs=...) at ./ns3/nstime.h:503
503  return lhs.m_data <= rhs.m_data;
(gdb) where
#0  0xb7f6c358 in ns3::operator<= (lhs=..., rhs=...) at ./ns3/nstime.h:503
#1  0xb5fc82aa in ns3::ConstantVelocityHelper::Update (this=0x1c)
    at ../src/mobility/model/constant-velocity-helper.cc:73
#2  0xb5fc8862 in ns3::ConstantVelocityMobilityModel::SetVelocity (this=0x0, speed=...)
    at ../src/mobility/model/constant-velocity-mobility-model.cc:46
#3  0x0805aae1 in main (argc=1, argv=0xbfffef24) at ../scratch/lab.cc:259
=======================================

I donot understand the reason behind error. Can anyone help me?

Tommaso Pecorella

unread,
Feb 2, 2015, 3:01:44 PM2/2/15
to ns-3-...@googlegroups.com
Learn to use the debugger, it will be useful in the future.
Also, I'd strongly suggest to check your simulation script.

The node (assuming it's a node) in container, position 0, doesn't have a ConstantVelocityMobilityModel associated.

T.

Rukna

unread,
Feb 2, 2015, 3:13:06 PM2/2/15
to ns-3-...@googlegroups.com
Thank you for your reply. But I have already set the position model:
==================
  MobilityHelper mobility;
  Ptr<ListPositionAllocator> positionAlloc = CreateObject <ListPositionAllocator>();
  positionAlloc ->Add(Vector(200, 0, 0)); // node0
  mobility.SetPositionAllocator(positionAlloc);
  mobility.SetMobilityModel("ns3::ConstantVelocityMobilityModel");
  mobility.Install(container);
  Ptr<ConstantVelocityMobilityModel> model = container.Get(0)->GetObject<ConstantVelocityMobilityModel>();
  model->SetVelocity(Vector(10,0,0));
==================
Can you suggest anything from error message? Also, can you suggest me about learning debugging?

Tommaso Pecorella

unread,
Feb 2, 2015, 3:58:58 PM2/2/15
to ns-3-...@googlegroups.com
Hi,

about debugging, there are a lot of tutorials in Internet. However I'd suggest to use a graphical debugger. usually the IDEs like Eclipse and NetBeans have an integrated graphical interface.

About the error, it's very strange.
This line:
#2  0xb5fc8862 in ns3::ConstantVelocityMobilityModel::SetVelocity (this=0x0, speed=...)
    at ../src/mobility/model/constant-velocity-mobility-model.cc:46
tells you that you tried to call a member function (SetVelocity) on a null pointer. As a consequence, the previous call failed. Which, indeed, is rather strange.
Try to activate the logging functions, in particular the ones of MobilityHelper, to make sure that the MobilityModel has been installed and aggregated to the node.
Other than that... only the [extremely] stupid question: are you sure that there is a node in the container ?

Hope this helps,

T.

Rukna

unread,
Feb 2, 2015, 4:13:09 PM2/2/15
to ns-3-...@googlegroups.com
Thanks again. According to your suggestion, I am trying to run ns3 in eclipse. 

However, I have declared node container:
NodeContainer container;

This is really strange. Anyway, I am glad to get your reply.

K' Dash

unread,
Feb 2, 2015, 4:19:32 PM2/2/15
to ns-3-...@googlegroups.com
you just declared but not created any node. :)

do this 

container.Create ();

K' Dash

unread,
Feb 2, 2015, 4:38:28 PM2/2/15
to ns-3-...@googlegroups.com
I have 2 questions to Tom. just for learning purpose. 

1. how you came to know that the error in this (#2  0xb5fc8862 in ns3::ConstantVelocityMobilityModel::SetVelocity (this=0x0, speed=...)) line?

2. The error you pointed on that particular line then why debugger goes up?

Tommaso Pecorella

unread,
Feb 3, 2015, 2:30:38 AM2/3/15
to ns-3-...@googlegroups.com
Easy... 

Depending on your O.S. protection level, it may (or may not) check if your program is trying to access a memory area not allocated to the program itself.
Note that in some cases this is ok, e.g., when you're using a shared memory model.
Anyway, a null pointer is a almost 100% a problem, as no program should access the memory start. Using a pointer to 0x0 may be forbidden by the O.S. (and the error is raised immediately), or it may not. In the latter case your program will start doing random stuff (it's accessing random points in the memory) 'til it definitely crashes.
Summarizing: the rule of thumb for every crash is: find the null pointer. If you find it, you have your bug.

Cheers,

T.

K' Dash

unread,
Feb 3, 2015, 4:51:30 AM2/3/15
to ns-3-...@googlegroups.com
I know its not a debugging group. but still I need to learn debugging tricks.

see my error. and guide me to fix it...

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff4d3f69e in ns3::GUID_address::GUID_address (this=0x7fffffffcab0) at ./ns3/GUID_address.h:29
29 class GUID_address //: public Address
Missing separate debuginfos, use: debuginfo-install atlas-3.8.4-10.fc19.x86_64 glibc-2.17-21.fc19.x86_64 gsl-1.15-8.fc19.x86_64 libgcc-4.8.3-7.fc19.x86_64 libstdc++-4.8.3-7.fc19.x86_64
(gdb) bt
#0  0x00007ffff4d3f69e in ns3::GUID_address::GUID_address (this=0x7fffffffcab0) at ./ns3/GUID_address.h:29
#1  0x00007ffff4d5f9c1 in ns3::GUID::GetGUIDaddress (this=0x0) at ../src/medeha/model/GUID.cc:103====> here the Null pointer
#2  0x00007ffff4d32219 in ns3::MeDeHaDtnRouting::SendHello (this=0x672b60) at ../src/medeha/model/medeha-dtn-routing.cc:746
#3  0x00007ffff4d33066 in ns3::MeDeHaDtnRouting::HelloTimerExpire (this=0x672b60) at ../src/medeha/model/medeha-dtn-routing.cc:982
#4  0x00007ffff4d44ef1 in ns3::EventImpl* ns3::MakeEvent<void (ns3::MeDeHaDtnRouting::*)(), ns3::MeDeHaDtnRouting*>(void (ns3::MeDeHaDtnRouting::*)(), ns3::MeDeHaDtnRouting*)::EventMemberImpl0::Notify() (this=0x620f60) at ./ns3/make-event.h:94
#5  0x00007ffff0817225 in ns3::EventImpl::Invoke (this=0x620f60) at ../src/core/model/event-impl.cc:45
#6  0x00007ffff081bf97 in ns3::DefaultSimulatorImpl::ProcessOneEvent (this=0x67c7e0) at ../src/core/model/default-simulator-impl.cc:141
#7  0x00007ffff081c33b in ns3::DefaultSimulatorImpl::Run (this=0x67c7e0) at ../src/core/model/default-simulator-impl.cc:194
#8  0x00007ffff0818030 in ns3::Simulator::Run () at ../src/core/model/simulator.cc:161
#9  0x000000000040e9fb in main (argc=1, argv=0x7fffffffded8) at ../scratch/adhoc2nodes.cc:175


if I go to previous file function which is SendHello() at line 746 there 

void
MeDeHaDtnRouting::SendHello ()
{
    NS_LOG_FUNCTION (this);
	Ptr<Packet> packet = Create<Packet> ();

	uint16_t addressCounter = 0;

	Ipv4Address address[1];
	Ptr<GUID> GUIDnode = m_node->GetObject< GUID > ();
	GUID_address guidaddr= GUIDnode->GetGUIDaddress();=========> This line making the error. 
	//std::cout<<"guid address"<<guidaddr<<"\n";
	Ipv4Address loopback ("127.0.0.1");
	for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++)
	{
		Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal ();
		if (addr != loopback &&
				addr != m_mainAddress)
		{
			//ipv4AddressAlternate = addr;
			address[addressCounter] = addr;
			addressCounter++;
		}
	}


















--
You received this message because you are subscribed to a topic in the Google Groups "ns-3-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ns-3-users/BwaalhvArJo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+...@googlegroups.com.
To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.



--
Regards,
ADNAN RASHID


Konstantinos

unread,
Feb 3, 2015, 5:29:04 AM2/3/15
to ns-3-...@googlegroups.com
Hi Adnan,

please open a new thread, this was related to "GetVelocity" errors.
Try to do add a check before you get the GUIDAddress that the GUIDnode object is initialized properly.
Have you aggregated the GUID class with the Node class? If not, then the GetObject should not work.

Ptr<GUID> GUIDnode = m_node->GetObject< GUID > ();
GUID_address guidaddr
= GUIDnode->GetGUIDaddress();

To unsubscribe from this group and all its topics, send an email to ns-3-users+unsubscribe@googlegroups.com.

To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.



--
Regards,
ADNAN RASHID


Mohammad Afrashteh

unread,
Sep 14, 2017, 4:57:50 AM9/14/17
to ns-3-users
Hi Runka,

About me, it was for before Install NodeContainer I've used SetVelocity. So first I used mobilityHelperVehicle.Install(nodeContainerVehicle) then SetVelocity that solved problem.

I hope this helps you.

Ankur Sarker

unread,
Sep 15, 2017, 5:21:58 PM9/15/17
to ns-3-...@googlegroups.com
Thanks for your reply. It works for me :)

--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to a topic in the Google Groups "ns-3-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ns-3-users/BwaalhvArJo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+unsubscribe@googlegroups.com.
To post to this group, send email to ns-3-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages