A Discrete-Event Network Simulator
API
udp-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007 Georgia Tech Research Corporation
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Raj Bhattacharjea <raj.b@gatech.edu>
19  */
25 #include "ns3/test.h"
26 #include "ns3/socket-factory.h"
27 #include "ns3/udp-socket-factory.h"
28 #include "ns3/simulator.h"
29 #include "ns3/simple-channel.h"
30 #include "ns3/simple-net-device.h"
31 #include "ns3/simple-net-device-helper.h"
32 #include "ns3/socket.h"
33 #include "ns3/traffic-control-helper.h"
34 
35 #include "ns3/boolean.h"
36 #include "ns3/log.h"
37 #include "ns3/node.h"
38 #include "ns3/inet-socket-address.h"
39 #include "ns3/inet6-socket-address.h"
40 #include "ns3/internet-stack-helper.h"
41 
42 #include "ns3/arp-l3-protocol.h"
43 #include "ns3/ipv4-l3-protocol.h"
44 #include "ns3/ipv4-queue-disc-item.h"
45 #include "ns3/ipv6-l3-protocol.h"
46 #include "ns3/icmpv4-l4-protocol.h"
47 #include "ns3/icmpv6-l4-protocol.h"
48 #include "ns3/udp-l4-protocol.h"
49 #include "ns3/tcp-l4-protocol.h"
50 #include "ns3/ipv4-list-routing.h"
51 #include "ns3/ipv4-static-routing.h"
52 #include "ns3/ipv6-list-routing.h"
53 #include "ns3/ipv6-static-routing.h"
54 #include "ns3/ipv6-address-helper.h"
55 
56 #include <string>
57 #include <limits>
58 
59 using namespace ns3;
60 
61 
69 {
70 public:
72  virtual void DoRun (void);
73 
78  void ReceivePkt (Ptr<Socket> socket);
80 };
81 
83  : TestCase ("UDP loopback test")
84 {
85 }
86 
88 {
89  uint32_t availableData;
90  availableData = socket->GetRxAvailable ();
92  NS_ASSERT (availableData == m_receivedPacket->GetSize ());
93 }
94 
95 void
97 {
98  Ptr<Node> rxNode = CreateObject<Node> ();
99  InternetStackHelper internet;
100  internet.Install (rxNode);
101 
102  Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory> ();
103  Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket ();
104  rxSocket->Bind (InetSocketAddress (Ipv4Address::GetAny (), 80));
105  rxSocket->SetRecvCallback (MakeCallback (&UdpSocketLoopbackTest::ReceivePkt, this));
106 
107  Ptr<Socket> txSocket = rxSocketFactory->CreateSocket ();
108  txSocket->SendTo (Create<Packet> (246), 0, InetSocketAddress ("127.0.0.1", 80));
109  Simulator::Run ();
110  Simulator::Destroy ();
111  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 246, "first socket should not receive it (it is bound specifically to the second interface's address");
112 }
113 
121 {
122 public:
124  virtual void DoRun (void);
125 
130  void ReceivePkt (Ptr<Socket> socket);
132 };
133 
135  : TestCase ("UDP6 loopback test")
136 {
137 }
138 
140 {
141  uint32_t availableData;
142  availableData = socket->GetRxAvailable ();
144  NS_ASSERT (availableData == m_receivedPacket->GetSize ());
145  //cast availableData to void, to suppress 'availableData' set but not used
146  //compiler warning
147  (void) availableData;
148 }
149 
150 void
152 {
153  Ptr<Node> rxNode = CreateObject<Node> ();
154  InternetStackHelper internet;
155  internet.Install (rxNode);
156 
157  Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory> ();
158  Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket ();
159  rxSocket->Bind (Inet6SocketAddress (Ipv6Address::GetAny (), 80));
160  rxSocket->SetRecvCallback (MakeCallback (&Udp6SocketLoopbackTest::ReceivePkt, this));
161 
162  Ptr<Socket> txSocket = rxSocketFactory->CreateSocket ();
163  txSocket->SendTo (Create<Packet> (246), 0, Inet6SocketAddress ("::1", 80));
164  Simulator::Run ();
165  Simulator::Destroy ();
166  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 246, "first socket should not receive it (it is bound specifically to the second interface's address");
167 }
168 
176 {
180 
185  uint32_t GetTos (void);
186 
191  uint32_t GetPriority (void);
192 
198  void DoSendDataTo (Ptr<Socket> socket, std::string to);
204  void SendDataTo (Ptr<Socket> socket, std::string to);
209  void DoSendData (Ptr<Socket> socket);
214  void SendData (Ptr<Socket> socket);
215 
216 public:
217  virtual void DoRun (void);
219 
224  void ReceivePkt (Ptr<Socket> socket);
229  void ReceivePkt2 (Ptr<Socket> socket);
230 
235  void SentPkt (Ptr<const QueueDiscItem> item);
236 };
237 
239  : TestCase ("UDP socket implementation")
240 {
241 }
242 
244 {
245  uint32_t availableData;
246  availableData = socket->GetRxAvailable ();
248  NS_ASSERT (availableData == m_receivedPacket->GetSize ());
249 }
250 
252 {
253  uint32_t availableData;
254  availableData = socket->GetRxAvailable ();
256  NS_ASSERT (availableData == m_receivedPacket2->GetSize ());
257 }
258 
260 {
261  Ptr<const Ipv4QueueDiscItem> ipv4Item = DynamicCast<const Ipv4QueueDiscItem> (item);
262  NS_TEST_EXPECT_MSG_NE (ipv4Item, 0, "no IPv4 packet");
263  Address addr;
264  m_sentPacket = Create<Ipv4QueueDiscItem> (ipv4Item->GetPacket ()->Copy (), addr, 0, ipv4Item->GetHeader ());
265 }
266 
268 {
269  return static_cast<uint32_t> (m_sentPacket->GetHeader ().GetTos ());
270 }
271 
273 {
274  SocketPriorityTag priorityTag;
275  bool found = m_sentPacket->GetPacket ()->PeekPacketTag (priorityTag);
276  NS_TEST_EXPECT_MSG_EQ (found, true, "the packet should carry a SocketPriorityTag");
277  return static_cast<uint32_t> (priorityTag.GetPriority ());
278 }
279 
280 void
282 {
283  Address realTo = InetSocketAddress (Ipv4Address (to.c_str ()), 1234);
284  NS_TEST_EXPECT_MSG_EQ (socket->SendTo (Create<Packet> (123), 0, realTo),
285  123, "100");
286 }
287 
288 void
290 {
291  m_receivedPacket = Create<Packet> ();
292  m_receivedPacket2 = Create<Packet> ();
293  Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (0),
294  &UdpSocketImplTest::DoSendDataTo, this, socket, to);
295  Simulator::Run ();
296 }
297 
298 void
300 {
301  NS_TEST_EXPECT_MSG_EQ (socket->Send (Create<Packet> (123), 0), 123, "100");
302 }
303 
304 void
306 {
307  Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (0),
308  &UdpSocketImplTest::DoSendData, this, socket);
309  Simulator::Run ();
310 }
311 
312 void
314 {
315  // Create topology
316 
317  // Receiver Node
318  Ptr<Node> rxNode = CreateObject<Node> ();
319  // Sender Node
320  Ptr<Node> txNode = CreateObject<Node> ();
321 
322  NodeContainer nodes (rxNode, txNode);
323 
324  SimpleNetDeviceHelper helperChannel1;
325  helperChannel1.SetNetDevicePointToPointMode (true);
326  NetDeviceContainer net1 = helperChannel1.Install (nodes);
327 
328  SimpleNetDeviceHelper helperChannel2;
329  helperChannel2.SetNetDevicePointToPointMode (true);
330  NetDeviceContainer net2 = helperChannel2.Install (nodes);
331 
332  InternetStackHelper internet;
333  internet.Install (nodes);
334 
335  TrafficControlHelper tch = TrafficControlHelper::Default ();
336  QueueDiscContainer qdiscs = tch.Install (net1.Get (1));
337 
338  Ptr<Ipv4> ipv4;
339  uint32_t netdev_idx;
340  Ipv4InterfaceAddress ipv4Addr;
341 
342  // Receiver Node
343  ipv4 = rxNode->GetObject<Ipv4> ();
344  netdev_idx = ipv4->AddInterface (net1.Get (0));
345  ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.0.1"), Ipv4Mask ("/24"));
346  ipv4->AddAddress (netdev_idx, ipv4Addr);
347  ipv4->SetUp (netdev_idx);
348 
349  netdev_idx = ipv4->AddInterface (net2.Get (0));
350  ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.1.1"), Ipv4Mask ("/24"));
351  ipv4->AddAddress (netdev_idx, ipv4Addr);
352  ipv4->SetUp (netdev_idx);
353 
354  // Sender Node
355  ipv4 = txNode->GetObject<Ipv4> ();
356  netdev_idx = ipv4->AddInterface (net1.Get (1));
357  ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.0.2"), Ipv4Mask ("/24"));
358  ipv4->AddAddress (netdev_idx, ipv4Addr);
359  ipv4->SetUp (netdev_idx);
360 
361  netdev_idx = ipv4->AddInterface (net2.Get (1));
362  ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.1.2"), Ipv4Mask ("/24"));
363  ipv4->AddAddress (netdev_idx, ipv4Addr);
364  ipv4->SetUp (netdev_idx);
365 
366  // Create the UDP sockets
367  Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory> ();
368 
369  Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket ();
370  NS_TEST_EXPECT_MSG_EQ (rxSocket->Bind (InetSocketAddress (Ipv4Address ("10.0.0.1"), 1234)), 0, "trivial");
371  rxSocket->SetRecvCallback (MakeCallback (&UdpSocketImplTest::ReceivePkt, this));
372 
373  Ptr<Socket> rxSocket2 = rxSocketFactory->CreateSocket ();
374  NS_TEST_EXPECT_MSG_EQ (rxSocket2->Bind (InetSocketAddress (Ipv4Address ("10.0.1.1"), 1234)), 0, "trivial");
376 
377  Ptr<SocketFactory> txSocketFactory = txNode->GetObject<UdpSocketFactory> ();
378  Ptr<Socket> txSocket = txSocketFactory->CreateSocket ();
379  txSocket->SetAllowBroadcast (true);
380 
381  // ------ Now the tests ------------
382 
383  // Unicast test
384  SendDataTo (txSocket, "10.0.0.1");
385  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 123, "trivial");
386  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 0, "second interface should not receive it");
387 
390 
391  // Simple broadcast test
392 
393  SendDataTo (txSocket, "255.255.255.255");
394  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 0, "first socket should not receive it (it is bound specifically to the first interface's address");
395  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 0, "second socket should not receive it (it is bound specifically to the second interface's address");
396 
399 
400  // Broadcast test with multiple receiving sockets
401 
402  // When receiving broadcast packets, all sockets sockets bound to
403  // the address/port should receive a copy of the same packet -- if
404  // the socket address matches.
405  rxSocket2->Dispose ();
406  rxSocket2 = rxSocketFactory->CreateSocket ();
408  NS_TEST_EXPECT_MSG_EQ (rxSocket2->Bind (InetSocketAddress (Ipv4Address ("0.0.0.0"), 1234)), 0, "trivial");
409 
410  SendDataTo (txSocket, "255.255.255.255");
411  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 0, "first socket should not receive it (it is bound specifically to the first interface's address");
412  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 123, "trivial");
413 
414  m_receivedPacket = 0;
415  m_receivedPacket2 = 0;
416 
417  // Simple Link-local multicast test
418 
419  txSocket->BindToNetDevice (net1.Get (1));
420  SendDataTo (txSocket, "224.0.0.9");
421  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 0, "first socket should not receive it (it is bound specifically to the first interface's address");
422  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 123, "recv2: 224.0.0.9");
423 
426 
427  // Simple getpeername tests
428 
429  Address peerAddress;
430  int err = txSocket->GetPeerName (peerAddress);
431  NS_TEST_EXPECT_MSG_EQ (err, -1, "socket GetPeerName() should fail when socket is not connected");
432  NS_TEST_EXPECT_MSG_EQ (txSocket->GetErrno (), Socket::ERROR_NOTCONN, "socket error code should be ERROR_NOTCONN");
433 
434  InetSocketAddress peer ("10.0.0.1", 1234);
435  err = txSocket->Connect (peer);
436  NS_TEST_EXPECT_MSG_EQ (err, 0, "socket Connect() should succeed");
437 
438  err = txSocket->GetPeerName (peerAddress);
439  NS_TEST_EXPECT_MSG_EQ (err, 0, "socket GetPeerName() should succeed when socket is connected");
440  NS_TEST_EXPECT_MSG_EQ (peerAddress, peer, "address from socket GetPeerName() should equal the connected address");
441 
444 
445  // TOS and priority tests
446 
447  // Intercept the packets dequeued by the queue disc on the sender node
448  qdiscs.Get (0)->TraceConnectWithoutContext ("Dequeue", MakeCallback (&UdpSocketImplTest::SentPkt, this));
449 
450  // The socket is not connected.
451  txSocket->SetIpTos (0x28); // AF11
452  txSocket->SetPriority (6); // Interactive
453  // Send a packet to a specified destination:
454  // - for not connected sockets, the tos specified in the destination address (0) is used
455  // - since the tos is zero, the priority set for the socket is used
456  SendDataTo (txSocket, "10.0.0.1");
457  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 123, "trivial");
458 
459  NS_TEST_EXPECT_MSG_EQ (GetTos (), 0, "the TOS should be set to 0");
460  NS_TEST_EXPECT_MSG_EQ (GetPriority (), 6, "Interactive (6)");
461 
463 
464  InetSocketAddress dest ("10.0.0.1", 1234);
465  dest.SetTos (0xb8); // EF
466  // the connect operation sets the tos (and priority) for the socket
467  NS_TEST_EXPECT_MSG_EQ (txSocket->Connect (dest), 0, "the connect operation failed");
468 
469  SendData (txSocket);
470  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 123, "trivial");
471 
472  NS_TEST_EXPECT_MSG_EQ (GetTos (), 0xb8, "the TOS should be set to 0xb8");
473  NS_TEST_EXPECT_MSG_EQ (GetPriority (), 4, "Interactive bulk (4)");
474 
476 
477  Simulator::Destroy ();
478 
479 }
480 
488 {
491 
497  void DoSendDataTo (Ptr<Socket> socket, std::string to);
503  void SendDataTo (Ptr<Socket> socket, std::string to);
504 
505 public:
506  virtual void DoRun (void);
508 
515  void ReceivePacket (Ptr<Socket> socket, Ptr<Packet> packet, const Address &from);
522  void ReceivePacket2 (Ptr<Socket> socket, Ptr<Packet> packet, const Address &from);
527  void ReceivePkt (Ptr<Socket> socket);
532  void ReceivePkt2 (Ptr<Socket> socket);
533 };
534 
536  : TestCase ("UDP6 socket implementation")
537 {
538 }
539 
541 {
542  m_receivedPacket = packet;
543 }
544 
546 {
547  m_receivedPacket2 = packet;
548 }
549 
551 {
552  uint32_t availableData;
553  availableData = socket->GetRxAvailable ();
555  NS_ASSERT (availableData == m_receivedPacket->GetSize ());
556  //cast availableData to void, to suppress 'availableData' set but not used
557  //compiler warning
558  (void) availableData;
559 }
560 
562 {
563  uint32_t availableData;
564  availableData = socket->GetRxAvailable ();
566  NS_ASSERT (availableData == m_receivedPacket2->GetSize ());
567  //cast availableData to void, to suppress 'availableData' set but not used
568  //compiler warning
569  (void) availableData;
570 }
571 
572 void
574 {
575  Address realTo = Inet6SocketAddress (Ipv6Address (to.c_str ()), 1234);
576  NS_TEST_EXPECT_MSG_EQ (socket->SendTo (Create<Packet> (123), 0, realTo),
577  123, "200");
578 }
579 
580 void
582 {
583  m_receivedPacket = Create<Packet> ();
584  m_receivedPacket2 = Create<Packet> ();
585  Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (0),
586  &Udp6SocketImplTest::DoSendDataTo, this, socket, to);
587  Simulator::Run ();
588 }
589 
590 void
592 {
593  // Create topology
594 
595  // Receiver Node
596  Ptr<Node> rxNode = CreateObject<Node> ();
597  // Sender Node
598  Ptr<Node> txNode = CreateObject<Node> ();
599 
600  NodeContainer nodes (rxNode, txNode);
601 
602  SimpleNetDeviceHelper helperChannel1;
603  helperChannel1.SetNetDevicePointToPointMode (true);
604  NetDeviceContainer net1 = helperChannel1.Install (nodes);
605 
606  SimpleNetDeviceHelper helperChannel2;
607  helperChannel2.SetNetDevicePointToPointMode (true);
608  NetDeviceContainer net2 = helperChannel2.Install (nodes);
609 
610  InternetStackHelper internetv6;
611  internetv6.Install (nodes);
612 
613  txNode->GetObject<Icmpv6L4Protocol> ()->SetAttribute ("DAD", BooleanValue (false));
614  rxNode->GetObject<Icmpv6L4Protocol> ()->SetAttribute ("DAD", BooleanValue (false));
615 
616  Ipv6AddressHelper ipv6helper;
617  Ipv6InterfaceContainer iic1 = ipv6helper.AssignWithoutAddress (net1);
618  Ipv6InterfaceContainer iic2 = ipv6helper.AssignWithoutAddress (net2);
619 
620  Ptr<NetDevice> device;
621  Ptr<Ipv6> ipv6;
622  int32_t ifIndex;
623  Ipv6InterfaceAddress ipv6Addr;
624 
625  ipv6 = rxNode->GetObject<Ipv6> ();
626  device = net1.Get (0);
627  ifIndex = ipv6->GetInterfaceForDevice (device);
628  ipv6Addr = Ipv6InterfaceAddress (Ipv6Address ("2001:0100::1"), Ipv6Prefix (64));
629  ipv6->AddAddress (ifIndex, ipv6Addr);
630  ipv6->SetUp (ifIndex);
631 
632  device = net2.Get (0);
633  ifIndex = ipv6->GetInterfaceForDevice (device);
634  ipv6Addr = Ipv6InterfaceAddress (Ipv6Address ("2001:0100:1::1"), Ipv6Prefix (64));
635  ipv6->AddAddress (ifIndex, ipv6Addr);
636  ipv6->SetUp (ifIndex);
637 
638  ipv6 = txNode->GetObject<Ipv6> ();
639  device = net1.Get (1);
640  ifIndex = ipv6->GetInterfaceForDevice (device);
641  ipv6Addr = Ipv6InterfaceAddress (Ipv6Address ("2001:0100::2"), Ipv6Prefix (64));
642  ipv6->AddAddress (ifIndex, ipv6Addr);
643  ipv6->SetUp (ifIndex);
644 
645  device = net2.Get (1);
646  ifIndex = ipv6->GetInterfaceForDevice (device);
647  ipv6Addr = Ipv6InterfaceAddress (Ipv6Address ("2001:0100:1::2"), Ipv6Prefix (64));
648  ipv6->AddAddress (ifIndex, ipv6Addr);
649  ipv6->SetUp (ifIndex);
650 
651  // Create the UDP sockets
652  Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory> ();
653  Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket ();
654  NS_TEST_EXPECT_MSG_EQ (rxSocket->Bind (Inet6SocketAddress (Ipv6Address ("2001:0100::1"), 1234)), 0, "trivial");
655  rxSocket->SetRecvCallback (MakeCallback (&Udp6SocketImplTest::ReceivePkt, this));
656 
657  Ptr<Socket> rxSocket2 = rxSocketFactory->CreateSocket ();
659  NS_TEST_EXPECT_MSG_EQ (rxSocket2->Bind (Inet6SocketAddress (Ipv6Address ("2001:0100:1::1"), 1234)), 0, "trivial");
660 
661  Ptr<SocketFactory> txSocketFactory = txNode->GetObject<UdpSocketFactory> ();
662  Ptr<Socket> txSocket = txSocketFactory->CreateSocket ();
663  txSocket->SetAllowBroadcast (true);
664  // ------ Now the tests ------------
665 
666  // Unicast test
667  SendDataTo (txSocket, "2001:0100::1");
668  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 123, "trivial");
669  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 0, "second interface should receive it");
670 
673 
674  // Simple Link-local multicast test
675 
676  // When receiving broadcast packets, all sockets sockets bound to
677  // the address/port should receive a copy of the same packet -- if
678  // the socket address matches.
679  rxSocket2->Dispose ();
680  rxSocket2 = rxSocketFactory->CreateSocket ();
682  NS_TEST_EXPECT_MSG_EQ (rxSocket2->Bind (Inet6SocketAddress (Ipv6Address ("::"), 1234)), 0, "trivial");
683 
684  txSocket->BindToNetDevice (net1.Get (1));
685  SendDataTo (txSocket, "ff02::1");
686  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 0, "first socket should not receive it (it is bound specifically to the second interface's address");
687  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 123, "recv2: ff02::1");
688 
691 
692  // Simple getpeername tests
693  Address peerAddress;
694  int err = txSocket->GetPeerName (peerAddress);
695  NS_TEST_EXPECT_MSG_EQ (err, -1, "socket GetPeerName() should fail when socket is not connected");
696  NS_TEST_EXPECT_MSG_EQ (txSocket->GetErrno (), Socket::ERROR_NOTCONN, "socket error code should be ERROR_NOTCONN");
697 
698  Inet6SocketAddress peer ("2001:0100::1", 1234);
699  err = txSocket->Connect (peer);
700  NS_TEST_EXPECT_MSG_EQ (err, 0, "socket Connect() should succeed");
701 
702  err = txSocket->GetPeerName (peerAddress);
703  NS_TEST_EXPECT_MSG_EQ (err, 0, "socket GetPeerName() should succeed when socket is connected");
704  NS_TEST_EXPECT_MSG_EQ (peerAddress, peer, "address from socket GetPeerName() should equal the connected address");
705 
706  Simulator::Destroy ();
707 
708 }
709 
710 
717 class UdpTestSuite : public TestSuite
718 {
719 public:
721  {
722  AddTestCase (new UdpSocketImplTest, TestCase::QUICK);
723  AddTestCase (new UdpSocketLoopbackTest, TestCase::QUICK);
724  AddTestCase (new Udp6SocketImplTest, TestCase::QUICK);
725  AddTestCase (new Udp6SocketLoopbackTest, TestCase::QUICK);
726  }
727 };
728 
730 
uint32_t GetTos(void)
Get the TOS of the received packet.
Definition: udp-test.cc:267
void Dispose(void)
Dispose of this Object.
Definition: object.cc:214
void ReceivePkt(Ptr< Socket > socket)
Receive a packet.
Definition: udp-test.cc:139
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
an Inet address class
AttributeValue implementation for Boolean.
Definition: boolean.h:36
QueueDiscContainer Install(NetDeviceContainer c)
uint32_t GetId(void) const
Definition: node.cc:107
Keep track of a set of IPv6 interfaces.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: udp-test.cc:151
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:81
virtual bool SetAllowBroadcast(bool allowBroadcast)=0
Configure whether broadcast datagram transmissions are allowed.
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:263
A suite of tests to run.
Definition: test.h:1343
UDP Socket over IPv4 Test.
Definition: udp-test.cc:175
uint8_t GetPriority(void) const
Get the tag&#39;s priority.
Definition: socket.cc:848
uint8_t GetTos(void) const
Definition: ipv4-header.cc:194
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
IPv6 address associated with an interface.
aggregate IP/TCP/UDP functionality to existing Nodes.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition: test.h:283
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: udp-test.cc:313
virtual Ptr< Socket > CreateSocket(void)=0
encapsulates test code
Definition: test.h:1153
Ptr< Packet > GetPacket(void) const
Definition: queue-item.cc:42
Ptr< Packet > m_receivedPacket2
Received packet (2).
Definition: udp-test.cc:178
a polymophic address class
Definition: address.h:90
Holds a vector of ns3::QueueDisc pointers.
void SendData(Ptr< Socket > socket)
Send data.
Definition: udp-test.cc:305
void ReceivePkt(Ptr< Socket > socket)
Receive a packet.
Definition: udp-test.cc:87
void ReceivePacket2(Ptr< Socket > socket, Ptr< Packet > packet, const Address &from)
Receive packets (2).
Definition: udp-test.cc:545
nodes
Definition: first.py:32
void DoSendDataTo(Ptr< Socket > socket, std::string to)
Send data.
Definition: udp-test.cc:573
#define max(a, b)
Definition: 80211b.c:43
Ptr< Packet > m_receivedPacket
Received packet.
Definition: udp-test.cc:79
Ptr< Packet > m_receivedPacket
Received packet.
Definition: udp-test.cc:131
UDP Socket over IPv6 Test.
Definition: udp-test.cc:487
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
const Ipv4Header & GetHeader(void) const
virtual void SetUp(uint32_t interface)=0
holds a vector of ns3::NetDevice pointers
indicates whether the socket has a priority set.
Definition: socket.h:1307
An Inet6 address class.
An implementation of the ICMPv6 protocol.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1610
Build a set of QueueDisc objects.
void SetRecvCallback(Callback< void, Ptr< Socket > >)
Notify application when new data is available to be read.
Definition: socket.cc:128
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
Definition: socket.cc:71
void ReceivePkt2(Ptr< Socket > socket)
Receive packets (2).
Definition: udp-test.cc:561
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:76
void ReceivePkt2(Ptr< Socket > socket)
Receive packets (2).
Definition: udp-test.cc:251
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:464
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:295
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
UDP Socket Loopback over IPv6 Test.
Definition: udp-test.cc:120
keep track of a set of node pointers.
void DoSendData(Ptr< Socket > socket)
Send data.
Definition: udp-test.cc:299
void SendDataTo(Ptr< Socket > socket, std::string to)
Send data.
Definition: udp-test.cc:289
Ptr< QueueDisc > Get(std::size_t i) const
Get the Ptr<QueueDisc> stored in this container at a given index.
virtual Ptr< Packet > Recv(uint32_t maxSize, uint32_t flags)=0
Read data from the socket.
void SetNetDevicePointToPointMode(bool pointToPointMode)
SimpleNetDevice is Broadcast capable and ARP needing.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
#define NS_TEST_EXPECT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report if not.
Definition: test.h:737
void ReceivePkt(Ptr< Socket > socket)
Receive packets (1).
Definition: udp-test.cc:550
void DoSendDataTo(Ptr< Socket > socket, std::string to)
Send data.
Definition: udp-test.cc:281
Helper class to auto-assign global IPv6 unicast addresses.
Ptr< Packet > m_receivedPacket2
Received packet (2).
Definition: udp-test.cc:490
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
Describes an IPv6 address.
Definition: ipv6-address.h:49
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
static UdpTestSuite g_udpTestSuite
Static variable for test initialization.
Definition: udp-test.cc:729
a class to store IPv4 address information on an interface
virtual Ptr< Node > GetNode(void) const =0
Return the node this socket is associated with.
void ReceivePkt(Ptr< Socket > socket)
Receive packets (1).
Definition: udp-test.cc:243
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1070
void RemoveAllByteTags(void)
Remove all byte tags stored in this packet.
Definition: packet.cc:371
Ptr< Packet > m_receivedPacket
Received packet (1).
Definition: udp-test.cc:489
Ptr< Packet > m_receivedPacket
Received packet (1).
Definition: udp-test.cc:177
Describes an IPv6 prefix.
Definition: ipv6-address.h:459
UDP Socket Loopback over IPv4 Test.
Definition: udp-test.cc:68
virtual bool AddAddress(uint32_t interface, Ipv4InterfaceAddress address)=0
virtual bool AddAddress(uint32_t interface, Ipv6InterfaceAddress address)=0
Add an address on the specified IPv6 interface.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
Send data to a specified peer.
void ReceivePacket(Ptr< Socket > socket, Ptr< Packet > packet, const Address &from)
Receive packets (1).
Definition: udp-test.cc:540
uint32_t GetPriority(void)
Get the priority of the received packet.
Definition: udp-test.cc:272
API to create UDP socket instances.
build a set of SimpleNetDevice objects
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Definition: packet.cc:885
This test suite implements a Unit Test.
Definition: test.h:1353
void SendDataTo(Ptr< Socket > socket, std::string to)
Send data.
Definition: udp-test.cc:581
void SentPkt(Ptr< const QueueDiscItem > item)
Adds a packet to the list of sent packets.
Definition: udp-test.cc:259
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
Ptr< Ipv4QueueDiscItem > m_sentPacket
Sent packet.
Definition: udp-test.cc:179
UDP TestSuite.
Definition: udp-test.cc:717
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: udp-test.cc:591
virtual int32_t GetInterfaceForDevice(Ptr< const NetDevice > device) const =0
Get the interface index of the specified NetDevice.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: udp-test.cc:96
virtual void SetUp(uint32_t interface)=0
Set the interface into the "up" state.
virtual uint32_t GetRxAvailable(void) const =0
Return number of bytes which can be returned from one or multiple calls to Recv.