1

I am trying to get a bug out of my ns-3 (networking simulation software) program.

I run it under gdb:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff4850195 in ns3::MpTcpBulkSendApplication::StartApplication (this=0x706850) at ../src/applications/model/mp-tcp-bulk-send-application.cc:170
170       m_socket->Bind();
(gdb) bt
#0  0x00007ffff4850195 in ns3::MpTcpBulkSendApplication::StartApplication (this=0x706850) at ../src/applications/model/mp-tcp-bulk-send-application.cc:170
#1  0x00007ffff09f9b45 in ns3::EventImpl* ns3::MakeEvent<void (ns3::Application::*)(), ns3::Application*>(void (ns3::Application::*)(), ns3::Application*)::EventMemberImpl0::Notify() (this=0x62f440) at ./ns3/make-event.h:94
#2  0x00007ffff02e90ef in ns3::EventImpl::Invoke (this=0x62f440) at ../src/core/model/event-impl.cc:45
#3  0x00007ffff02ee3a9 in ns3::DefaultSimulatorImpl::ProcessOneEvent (this=0x6d2d00) at ../src/core/model/default-simulator-impl.cc:141
#4  0x00007ffff02ee7ac in ns3::DefaultSimulatorImpl::Run (this=0x6d2d00) at ../src/core/model/default-simulator-impl.cc:194
#5  0x00007ffff02e9ff5 in ns3::Simulator::Run () at ../src/core/model/simulator.cc:161
#6  0x0000000000410640 in main (argc=1, argv=0x7fffffffdc58) at ../scratch/doordi3.cc:188

I can't understand what is happening, what gives the error. Any help would be welcome.

Thanks.

This function is the place from where error is coming:

// Application Methods
void MpTcpBulkSendApplication::StartApplication (void) // Called at time specified by Start
{
  NS_LOG_FUNCTION (this);
  //NS_LOG_UNCOND(Simulator::Now().GetSeconds() << " StartApplication -> Node-FlowId: {" << GetNode()->GetId() <<"-" << m_flowId<< "} MaxBytes: " << m_maxBytes << " F-Type: " << m_flowType << " S-Time: " << m_simTime);
  // Create the socket if not already
  if (!m_socket)
     { cout<<"Going to Bind"<<endl;
      //m_socket = CreateObject<MpTcpSocketBase>(GetNode()); //m_socket = Socket::CreateSocket (GetNode (), m_tid);
      m_socket = DynamicCast<MpTcpSocketBase>(Socket::CreateSocket (GetNode (), m_tid));
      m_socket->Bind();
      //m_socket->SetMaxSubFlowNumber(m_subflows);
      m_socket->SetFlowType(m_flowType);
      m_socket->SetOutputFileName(m_outputFileName);
      int result = m_socket->Connect(m_peer);
      if (result == 0)
        {
          m_socket->SetFlowId(m_flowId);
          m_socket->SetDupAckThresh(m_dupack);
          m_socket->SetConnectCallback(MakeCallback(&MpTcpBulkSendApplication::ConnectionSucceeded, this),MakeCallback(&MpTcpBulkSendApplication::ConnectionFailed, this));
          m_socket->SetDataSentCallback(MakeCallback(&MpTcpBulkSendApplication::DataSend, this));
          m_socket->SetCloseCallbacks (MakeCallback (&MpTcpBulkSendApplication::HandlePeerClose, this),MakeCallback (&MpTcpBulkSendApplication::HandlePeerError, this));
          //m_socket->SetSendCallback(MakeCallback(&MpTcpBulkSendApplication::DataSend, this));
        }
      else
        {
          NS_LOG_UNCOND("Connection is failed");
        }
    }
  if (m_connected)
    { 
      SendData ();
    }
}
ferrer
  • 135
  • 3
  • 10
  • GDB gave you the code line of the segmentation fault. We cannot give you more without any more clues. If you want more details, you can try using Valgrind. – Aracthor Jan 23 '16 at 13:09
  • Could you provide the entire code that you have written? – user2277550 Jan 23 '16 at 13:11
  • @user2277550 it needs mptcp code with ns3 to work. So, I didn't post that. Would it be helpful ? – ferrer Jan 23 '16 at 13:17
  • Probably not. However your debugger is fairly clear about where the segfault is being created. Just check out the ways in which socket binding can give you a segfault and see if the issue is one of them. – user2277550 Jan 23 '16 at 13:22
  • Do you still have that gdb session where the program got the error? In gdb, type `print m_socket`. Is it 0 or some unreasonably large or small number? – Mark Plotnick Jan 23 '16 at 13:23
  • @MarkPlotnick Thanks for the guidance Mark. I did that and I get: $1 = {m_ptr = 0x0} . So, its zero. – ferrer Jan 23 '16 at 13:38
  • Also, could anybody explain what Config::SetDefault("ns3::TcpL4Protocol::SocketType", TypeIdValue(MpTcpSocketBase::GetTypeId())); this line does in ns3 ? – ferrer Jan 23 '16 at 13:39
  • Can you tell us what version of ns-3 you're running, for example ns-3.24 or ns-3-dev or someone's customized branch? – Mark Plotnick Jan 23 '16 at 13:51
  • @MarkPlotnick I am running this implementation: https://github.com/mkheirkhah/mptcp (ns-3 with MPTCP model). The same code is being used by the ns-3 team to develop the official version for Multipath TCP. Thanks. – ferrer Jan 23 '16 at 13:55

1 Answers1

5

In the comments you indicated that printing out the value of the pointer produces a 0. So that's pretty much your answer. The code is attempting to dereference a null pointer.

You obtained this pointer from some library function whose purpose, based on the context, is to create a socket. If you were to check the documentation of your library function, you will find an explanation that a null pointer gets returned if the socket cannot be created for some reason.

So, you have two follow-up courses of action:

1) Investigate why the socket could not be created.

2) Take this as a lesson learned: whenever you are calling a library function, you must check its documentation. If the library function indicates that it could possibly fail in its mission, and return a value, or some indication of some sorts that the operation has failed, your code must check for it, and take the appropriate action. You cannot assume that the library function will always succeed. Otherwise your code will fail in some mysterious fashion, and you will be forced to go to some web site and ask strangers to help you. And you don't obviously want to do that. You want to be able to figure out your bugs all by yourself.

Sam Varshavchik
  • 114,536
  • 5
  • 94
  • 148