[Error]I build my code successfully but get segmentation fault(SIGSEGV) after that.

238 views
Skip to first unread message

Kohei MORIYAMA

unread,
Dec 14, 2012, 2:03:11 AM12/14/12
to ns-3-...@googlegroups.com
Hi all.

I've built my code successfully but the simulations stopped with segmentation fault(SIGSEGV). 
That fault came up after I changed the interference range from "all other nodes" to "within 2 hops away" (see the Flow Image below).

When the range is "all node", my code always succeed in simulation.
I think it is because more nodes try to send packets when the range is "within 2 hops away" than when the range is "all node".
But I don't know which code to fix...

---Flow Image---
      n7 ●
        ↓
      n8 ●
        ↓
      n9 ●
                 ↓     
 ●→●→●→●←●←●←●
 n1  n2 n3 ↑    n4  n5  n6
        ●n10
        ↑
        ●n11
        ↑
               ●n12

Source      : n1~n12        
Destination: the cross point node(n0)
Baud rate   : 54Mbps
Packet Size:1000 byte [OnOffApplication]
DataRate     :0.1~5 Mbps [OnOffApplication]
MaxQueue   :400
-----------------

Even if the range is "within 2 hops away", simulations work fine when DataRate[OnOffApplication] is from 0.1 to 1 Mbps.
When I increase DataRate[OnOffApplication] from 1.1666667 to 5 Mbps, simulations stop with segmentation fault(SIGSEGV).

Here are stacks when the error comes up.

void
SwMacCsma::ChannelAccessGranted ()
{
  NS_LOG_FUNCTION ("");
  if (m_pktQueue.size () == 0) { return; }
  
  m_backoffStart = Seconds (0);
  m_backoffRemain = Seconds (0);
  m_state = WAIT_TX;
  
  m_pktData = m_pktQueue.front();
  m_pktQueue.pop_front ();
  
  if (m_pktData == 0)
    NS_ASSERT ("Queue has null packet");
  
  SwMacHeader header;
  m_pktData->PeekHeader (header);//m_pktData is Ptr<Packet> and indicates the data packet a node is going to send.

 ↓
[packet.cc]
uint32_t
Packet::PeekHeader (Header &header) const
{
  uint32_t deserialized = header.Deserialize (m_buffer.Begin ());
 ↓
[buffer]
Buffer::Iterator 
Buffer::Begin (void) const
{
  NS_ASSERT (CheckInternalState ());
  return Buffer::Iterator (this); →"this" cannot access to memory at address 0x0 here.
 ↓
Buffer::Iterator::Iterator (Buffer const*buffer)
{
  Construct (buffer); →buffer cannnot access memory at address 0x4.  
  m_current = m_dataStart;
}
 ↓
void
Buffer::Iterator::Construct (const Buffer *buffer)
{
  m_zeroStart = buffer->m_zeroAreaStart; →buffer cannnot access memory at address 0x4.
  m_zeroEnd = buffer->m_zeroAreaEnd;
  m_dataStart = buffer->m_start;
  m_dataEnd = buffer->m_end;
  m_data = buffer->m_data->m_data;
}
------

I've try to solve this problem but all that I tried can't solve it... Please help.
What I've tried to solve this problem are...
 
1. Increasing Stack Size  
    ulimit -s unlimited

2. Implementing Cleanup() method [If a packet stays longer than m_maxDelay in the queue, it is dropped.]
    
    .AddAttribute ("MaxDelay", "If a packet stays longer than this delay in the queue, it is dropped.",
                   TimeValue (Seconds (10.0)),
                   MakeTimeAccessor (&SwMacCsma::m_maxDelay),
                   MakeTimeChecker ())
    .
    .
    .         
void
SwMacCsma::Cleanup (void)
{
  NS_LOG_FUNCTION_NOARGS ();
  if (m_pktQueue.size () == 0)
    {
      return;
    }
  Time now = Simulator::Now ();
  std::list<Ptr<Packet> >::iterator it = m_pktQueue.begin();
while( it != m_pktQueue.end() )  
       {
SwMacHeader header;
Ptr<Packet> packet = *it;
packet->PeekHeader (header);
Time tstamp = header.GetTstamp(); //tstamp is the time a packet is enqueued.
if ( tstamp + m_maxDelay > now)
                {
                  m_pktQueue.remove(*it);
                  ++it;
                   }
                 else
                 {
  ++it; 
                  }
}
}

I'm new to ns3 and C++ programming, so any advice and suggestion to work on this problem are welcome.
Thanks.

---Additional Info.----
In fact, I removed Cleanup() method, because SIGIOT occurs when I use this method at the beginning of Enqueue (Ptr<Packet> packet, Mac48Address dest).

---SIGIOT Error---
Waf: Leaving directory `/home/kmoriyama/tarballs/ns-allinone-3.15/ns-3.15/build'
'build' finished successfully (6.765s)

assert failed. cond="m_current >= m_dataStart && m_current <= m_dataEnd", msg="You have attempted to read beyond the bounds of the available buffer space. This usually indicates that a Header::Deserialize or Trailer::Deserialize method is trying to read data which was not written by a Header::Serialize or Trailer::Serialize method. In short: check the code of your Serialize and Deserialize methods.", file=./ns3/buffer.h, line=823

terminate called without an active exception
Command ['/home/kmoriyama/tarballs/ns-allinone-3.15/ns-3.15/build/scratch/csmaca-cross-stat', '--rate=0.833333333Mbps'] terminated with signal SIGIOT. Run it under a debugger to get more information (./waf --run <program> --command-template="gdb --args %s <args>").
---

After I removed this method, no SIGIOT occurs after building successfully.

But, Header::Deserialize this message mentions is the same class where SIGSEGV occurs. Is this a clue?  
This error says Check the code of your Serialize and Deserialize methods, but I don't know what my Serialize and Deserialize methods and where they are...

Here is Enqueue method I use.
bool
SwMacCsma::Enqueue (Ptr<Packet> packet, Mac48Address dest)
{
  NS_LOG_FUNCTION ("dest" << dest << "#queue" << m_pktQueue.size () << 
                  "state" << m_state << "pktSize" << packet->GetSize ());
  Cleanup ();
  if (m_pktQueue.size () >= m_queueLimit)
    {
      return false;
    }
  m_traceEnqueue (m_device->GetNode ()->GetId (), m_device->GetIfIndex ());
  
  packet->AddHeader (SwMacHeader (m_address, dest, SW_PKT_TYPE_DATA, Simulator::Now ()));
  m_pktQueue.push_back (packet);
  
  if (m_state == IDLE)
    { 
      CcaForDifs ();
    }
  
  return false;
}


---
Kohei Moriyama
Undergraduate Student
University of Tsukuba, Japan

Kohei MORIYAMA

unread,
Dec 17, 2012, 3:00:09 AM12/17/12
to ns-3-...@googlegroups.com
When is it possible the address of a Ptr<Packet> become 0x0(null)?

By debugging, I made sure a Ptr<Packet> has an address certainly when it is enqueued.

---Enqueue Function----

bool
SwMacCsma::Enqueue (Ptr<Packet> packet, Mac48Address dest)
{
  if (m_pktQueue.size () >= m_queueLimit) //m_pktQueue is std::list<Ptr<Packet> >
    {
      return false;
    }
 
  packet->AddHeader (SwMacHeader (m_address, dest, SW_PKT_TYPE_DATA));
  m_pktQueue.push_back (packet);
   
  return false;
}


But when a Ptr<Packet> that is returned by "m_pktQueue.front()" is 0x0, segmentation fault(SIGSEGV) occurs.

m_pktData = m_pktQueue.front(); //m_pktData is Ptr<Packet> and indicates the data packet a node is going to send.
  m_pktQueue.pop_front ();
  
  SwMacHeader header;
  m_pktData->PeekHeader (header); //SIGSEGV occurs.

It means a Ptr<Packet> that had its address become 0x0(null), but I don't know why... Please help...





Reply all
Reply to author
Forward
0 new messages