a problem in udp-client.cc

164 views
Skip to first unread message

buptw...@gmail.com

unread,
Jun 3, 2014, 3:54:35 AM6/3/14
to ns-3-...@googlegroups.com
Hi all,
  I wrote an example of NS-3 which includes 1 master node and 15 slave nodes, and it uses applications of udp-client on slave nodes and udp-server on master node respectively. I think my example should work because it works in NS-3.17.
  But, after I updated my NS-3.17 to NS-3.19, something happens. When a packet is generated and sent through a socket, an error may happen, in fact, only 5 of the slave nodes can send packets successfully. And it must be because the sentence "m_socket->Send (p)"(udp-client.cc:172) returns a value of -1, because it outputs "Error while sending 127 bytes to 1.0.0.1"(udp-client.cc:183).
  So, my question is, why the Send function of class Socket returns -1? Do some codes of socket change when version changes from 3.17 to 3.19? And how can I solve this problem?

Tommaso Pecorella

unread,
Jun 3, 2014, 4:10:33 AM6/3/14
to ns-3-...@googlegroups.com
Hi,

sockets have changed in the sense that it is now forbidden to open the same socket twice (before closing the old one). By "same socket" we mean:
- UDP: same source address / port
- TCP: same 4-tuple src/dst-addr/port.

Check that you didn't install your applications in the wrong way.

Other changes... not that I am aware of.

Hope this helps,

T.

buptw...@gmail.com

unread,
Jun 3, 2014, 5:04:47 AM6/3/14
to ns-3-...@googlegroups.com
Hi,
  I checked the application install codes, but I can't clearly catch where goes wrong. Could you please have a look?

    uint16_t port = 9;
    ApplicationContainer clientApps;
    ApplicationContainer serverApps;
    for (uint32_t u = 0; u < slaveNodes.GetN (); u++)
    {
        ++port;
        UdpClientHelper client (masterIpIfaces.GetAddress (0), port);
        client.SetAttribute ("Interval", TimeValue (Seconds(1)));
        client.SetAttribute ("PacketSize", UintegerValue(127));
        client.SetAttribute ("MaxPackets", UintegerValue(1000));
        clientApps.Add (client.Install (slaveNodes.Get(u)));

        UdpServerHelper server (port);
        serverApps.Add (server.Install (masterNodes.Get(0)));
      }
    clientApps.Start (Seconds(2.01));
    serverApps.Start (Seconds(2.01));

  I'm so sorry for trouble you, thank you so much for your help.

在 2014年6月3日星期二UTC+8下午4时10分33秒,Tommaso Pecorella写道:

Tommaso Pecorella

unread,
Jun 3, 2014, 5:32:21 AM6/3/14
to ns-3-...@googlegroups.com
Hi,

everything seems fine. Mind sending the complete script ?

T.

buptw...@gmail.com

unread,
Jun 3, 2014, 5:48:18 AM6/3/14
to ns-3-...@googlegroups.com
Hi,
  OK, but the script is related to new module named PLC, which is built by my teammates and I. And it goes well in NS-3.17. The error should be Send function of class Socket returns -1 as I described above.

在 2014年6月3日星期二UTC+8下午5时32分21秒,Tommaso Pecorella写道:
plc-simple.cc

Tommaso Pecorella

unread,
Jun 3, 2014, 3:45:17 PM6/3/14
to ns-3-...@googlegroups.com
Hi,

indeed, I can't debug it. Can you please check what's happening in this function ?
void
UdpClient::StartApplication (void)
{
  NS_LOG_FUNCTION
(this);
 
if (m_socket == 0)
   
{
     
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
      m_socket
= Socket::CreateSocket (GetNode (), tid);
     
if (Ipv4Address::IsMatchingType(m_peerAddress) == true)
       
{
          m_socket
->Bind ();
          m_socket
->Connect (InetSocketAddress (Ipv4Address::ConvertFrom(m_peerAddress), m_peerPort));
       
}
     
else if (Ipv6Address::IsMatchingType(m_peerAddress) == true)
       
{
          m_socket
->Bind6 ();
          m_socket
->Connect (Inet6SocketAddress (Ipv6Address::ConvertFrom(m_peerAddress), m_peerPort));
       
}
   
}

  m_socket
->SetRecvCallback (MakeNullCallback<void, Ptr<Socket> > ());
  m_sendEvent
= Simulator::Schedule (Seconds (0.0), &UdpClient::Send, this);
}


In particular Bind and Connect could return -1 (if they fails). Mind checking if they fail ?

Thanks,

T.

buptw...@gmail.com

unread,
Jun 4, 2014, 9:34:00 AM6/4/14
to ns-3-...@googlegroups.com
Hi,
  I did some research on the codes today, and I found that, "m_socket->Send(p)" returns -1 because in udp-socket-impl.cc, line 596, route==0 and NS_LOG_LOGIC outputs "No route to destination", function UdpSocketImpl::DoSendTo (...) returns -1. So, I think the reason may be routing or icmp, but I can't be sure about it.
  I can't spend too much time on it, so I may switch to NS-3.17 to have a try.
  And thank you very much for your help, if you come up with some solution in some day, please tell me. Thanks again.

在 2014年6月4日星期三UTC+8上午3时45分17秒,Tommaso Pecorella写道:

Tommaso Pecorella

unread,
Jun 4, 2014, 2:37:35 PM6/4/14
to ns-3-...@googlegroups.com
Found it. And it was easy too. The side-effect is that we just proved to be both blind as moles.

You've put all the interfaces and nodes on the very same network (1.0.0.0/8). The obvious consequence is that the "master" node (the one with more than one interface) has no clue on where to send a packet. It will always try to use the first interface, and (of course) it will fail miserably.
Why it (sometimes) sends something it's a mystery. Why 3.17 did work is a bigger mystery.

Solution: use a 1.0.0.0/24 for the various "links" and change network part for each of "link".

Cheers,

T.

buptw...@gmail.com

unread,
Jun 6, 2014, 2:51:44 AM6/6/14
to ns-3-...@googlegroups.com
Great! I'll try it again later and I hope this works.
Thank you so much!

在 2014年6月5日星期四UTC+8上午2时37分35秒,Tommaso Pecorella写道:
Reply all
Reply to author
Forward
0 new messages