nsc: make sure nsc has a configured interface
authorFlorian Westphal <fw@strlen.de>
Mon Sep 22 22:18:53 2008 +0200 (16 months ago)
changeset 3710ad0c222a18be
parent 3709 34d3f0952500
child 3711 fed597b0583e
nsc: make sure nsc has a configured interface

the receive method hands packets to the nsc core via
nsc's if_receive_packet() method.

NSC (rightfully) assumes that if it gets a packet, there must
be a network interface. However, at this time the interface
initialization in ns-3-nsc is done when the first socket is created.

The result is a segmentation fault inside nsc when ns-3 receives
a packet on an nsc-enabled node before a socked has been created
on that node.

For the time being, use NS_ASSERT to make sure the nsc interface exits.
This also gets rid of the NS_LOG use inside the Softinterrupt timer
method and replaces
NS_LOG_FUNCTION_NOARGS with NS_LOG_FUNCTION (this), as suggested by
Mathieu Lacage.
src/internet-stack/nsc-tcp-l4-protocol.cc
     1.1 --- a/src/internet-stack/nsc-tcp-l4-protocol.cc	Mon Sep 22 10:36:24 2008 -0700
     1.2 +++ b/src/internet-stack/nsc-tcp-l4-protocol.cc	Mon Sep 22 22:18:53 2008 +0200
     1.3 @@ -86,13 +86,12 @@
     1.4      m_softTimer (Timer::CANCEL_ON_DESTROY)
     1.5  {
     1.6    m_dlopenHandle = NULL;
     1.7 -  NS_LOG_FUNCTION_NOARGS ();
     1.8    NS_LOG_LOGIC("Made a NscTcpL4Protocol "<<this);
     1.9  }
    1.10  
    1.11  NscTcpL4Protocol::~NscTcpL4Protocol ()
    1.12  {
    1.13 -  NS_LOG_FUNCTION_NOARGS ();
    1.14 +  NS_LOG_FUNCTION (this);
    1.15    dlclose(m_dlopenHandle);
    1.16  }
    1.17  
    1.18 @@ -151,7 +150,7 @@
    1.19  void
    1.20  NscTcpL4Protocol::DoDispose (void)
    1.21  {
    1.22 -  NS_LOG_FUNCTION_NOARGS ();
    1.23 +  NS_LOG_FUNCTION (this);
    1.24    if (m_endPoints != 0)
    1.25      {
    1.26        delete m_endPoints;
    1.27 @@ -164,7 +163,7 @@
    1.28  Ptr<Socket>
    1.29  NscTcpL4Protocol::CreateSocket (void)
    1.30  {
    1.31 -  NS_LOG_FUNCTION_NOARGS ();
    1.32 +  NS_LOG_FUNCTION (this);
    1.33    if (!m_nscInterfacesSetUp)
    1.34    {
    1.35      Ptr<Ipv4> ip = m_node->GetObject<Ipv4> ();
    1.36 @@ -229,7 +228,7 @@
    1.37  Ipv4EndPoint *
    1.38  NscTcpL4Protocol::Allocate (void)
    1.39  {
    1.40 -  NS_LOG_FUNCTION_NOARGS ();
    1.41 +  NS_LOG_FUNCTION (this);
    1.42    return m_endPoints->Allocate ();
    1.43  }
    1.44  
    1.45 @@ -298,6 +297,7 @@
    1.46  
    1.47    const uint8_t *data = const_cast<uint8_t *>(packet->PeekData());
    1.48  
    1.49 +  NS_ASSERT_MSG (m_nscInterfacesSetUp, "got packet, but no listening sockets (and no interface)");
    1.50    // deliver complete packet to the NSC network stack
    1.51    m_nscStack->if_receive_packet(0, data, packetSize);
    1.52    wakeup ();
    1.53 @@ -305,7 +305,6 @@
    1.54  
    1.55  void NscTcpL4Protocol::SoftInterrupt (void)
    1.56  {
    1.57 -  NS_LOG_FUNCTION_NOARGS ();
    1.58    m_nscStack->timer_interrupt ();
    1.59    m_nscStack->increment_ticks ();
    1.60    m_softTimer.Schedule ();