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/drop-tail-queue.h"
33 #include "ns3/socket.h"
34 #include "ns3/traffic-control-helper.h"
35 
36 #include "ns3/boolean.h"
37 #include "ns3/log.h"
38 #include "ns3/node.h"
39 #include "ns3/inet-socket-address.h"
40 #include "ns3/inet6-socket-address.h"
41 #include "ns3/internet-stack-helper.h"
42 
43 #include "ns3/arp-l3-protocol.h"
44 #include "ns3/ipv4-l3-protocol.h"
45 #include "ns3/ipv4-queue-disc-item.h"
46 #include "ns3/ipv6-l3-protocol.h"
47 #include "ns3/icmpv4-l4-protocol.h"
48 #include "ns3/icmpv6-l4-protocol.h"
49 #include "ns3/udp-l4-protocol.h"
50 #include "ns3/tcp-l4-protocol.h"
51 #include "ns3/ipv4-list-routing.h"
52 #include "ns3/ipv4-static-routing.h"
53 #include "ns3/ipv6-list-routing.h"
54 #include "ns3/ipv6-static-routing.h"
55 #include "ns3/ipv6-address-helper.h"
56 
57 #include <string>
58 #include <limits>
59 
60 using namespace ns3;
61 
62 
64 {
65 public:
67  virtual void DoRun (void);
68 
69  void ReceivePkt (Ptr<Socket> socket);
71 };
72 
74  : TestCase ("UDP loopback test")
75 {
76 }
77 
79 {
80  uint32_t availableData;
81  availableData = socket->GetRxAvailable ();
83  NS_ASSERT (availableData == m_receivedPacket->GetSize ());
84 }
85 
86 void
88 {
89  Ptr<Node> rxNode = CreateObject<Node> ();
90  InternetStackHelper internet;
91  internet.Install (rxNode);
92 
93  Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory> ();
94  Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket ();
95  rxSocket->Bind (InetSocketAddress (Ipv4Address::GetAny (), 80));
96  rxSocket->SetRecvCallback (MakeCallback (&UdpSocketLoopbackTest::ReceivePkt, this));
97 
98  Ptr<Socket> txSocket = rxSocketFactory->CreateSocket ();
99  txSocket->SendTo (Create<Packet> (246), 0, InetSocketAddress ("127.0.0.1", 80));
100  Simulator::Run ();
101  Simulator::Destroy ();
102  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");
103 }
104 
106 {
107 public:
109  virtual void DoRun (void);
110 
111  void ReceivePkt (Ptr<Socket> socket);
113 };
114 
116  : TestCase ("UDP6 loopback test")
117 {
118 }
119 
121 {
122  uint32_t availableData;
123  availableData = socket->GetRxAvailable ();
125  NS_ASSERT (availableData == m_receivedPacket->GetSize ());
126  //cast availableData to void, to suppress 'availableData' set but not used
127  //compiler warning
128  (void) availableData;
129 }
130 
131 void
133 {
134  Ptr<Node> rxNode = CreateObject<Node> ();
135  InternetStackHelper internet;
136  internet.Install (rxNode);
137 
138  Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory> ();
139  Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket ();
140  rxSocket->Bind (Inet6SocketAddress (Ipv6Address::GetAny (), 80));
141  rxSocket->SetRecvCallback (MakeCallback (&Udp6SocketLoopbackTest::ReceivePkt, this));
142 
143  Ptr<Socket> txSocket = rxSocketFactory->CreateSocket ();
144  txSocket->SendTo (Create<Packet> (246), 0, Inet6SocketAddress ("::1", 80));
145  Simulator::Run ();
146  Simulator::Destroy ();
147  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");
148 }
149 
151 {
155  uint32_t GetTos (void);
156  uint32_t GetPriority (void);
157  void DoSendDataTo (Ptr<Socket> socket, std::string to);
158  void SendDataTo (Ptr<Socket> socket, std::string to);
159  void DoSendData (Ptr<Socket> socket);
160  void SendData (Ptr<Socket> socket);
161 
162 public:
163  virtual void DoRun (void);
165 
166  void ReceivePkt (Ptr<Socket> socket);
167  void ReceivePkt2 (Ptr<Socket> socket);
168  void SentPkt (Ptr<const QueueItem> item);
169 };
170 
172  : TestCase ("UDP socket implementation")
173 {
174 }
175 
177 {
178  uint32_t availableData;
179  availableData = socket->GetRxAvailable ();
181  NS_ASSERT (availableData == m_receivedPacket->GetSize ());
182 }
183 
185 {
186  uint32_t availableData;
187  availableData = socket->GetRxAvailable ();
189  NS_ASSERT (availableData == m_receivedPacket2->GetSize ());
190 }
191 
193 {
194  Ptr<const Ipv4QueueDiscItem> ipv4Item = DynamicCast<const Ipv4QueueDiscItem> (item);
195  NS_TEST_EXPECT_MSG_NE (ipv4Item, 0, "no IPv4 packet");
196  Address addr;
197  m_sentPacket = Create<Ipv4QueueDiscItem> (ipv4Item->GetPacket ()->Copy (), addr, 0, ipv4Item->GetHeader ());
198 }
199 
201 {
202  return static_cast<uint32_t> (m_sentPacket->GetHeader ().GetTos ());
203 }
204 
206 {
207  SocketPriorityTag priorityTag;
208  bool found = m_sentPacket->GetPacket ()->PeekPacketTag (priorityTag);
209  NS_TEST_EXPECT_MSG_EQ (found, true, "the packet should carry a SocketPriorityTag");
210  return static_cast<uint32_t> (priorityTag.GetPriority ());
211 }
212 
213 void
215 {
216  Address realTo = InetSocketAddress (Ipv4Address (to.c_str ()), 1234);
217  NS_TEST_EXPECT_MSG_EQ (socket->SendTo (Create<Packet> (123), 0, realTo),
218  123, "100");
219 }
220 
221 void
223 {
224  m_receivedPacket = Create<Packet> ();
225  m_receivedPacket2 = Create<Packet> ();
226  Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (0),
227  &UdpSocketImplTest::DoSendDataTo, this, socket, to);
228  Simulator::Run ();
229 }
230 
231 void
233 {
234  NS_TEST_EXPECT_MSG_EQ (socket->Send (Create<Packet> (123), 0), 123, "100");
235 }
236 
237 void
239 {
240  Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (0),
241  &UdpSocketImplTest::DoSendData, this, socket);
242  Simulator::Run ();
243 }
244 
245 void
247 {
248  // Create topology
249 
250  // Receiver Node
251  Ptr<Node> rxNode = CreateObject<Node> ();
252  // Sender Node
253  Ptr<Node> txNode = CreateObject<Node> ();
254 
255  NodeContainer nodes (rxNode, txNode);
256 
257  SimpleNetDeviceHelper helperChannel1;
258  helperChannel1.SetNetDevicePointToPointMode (true);
259  NetDeviceContainer net1 = helperChannel1.Install (nodes);
260 
261  SimpleNetDeviceHelper helperChannel2;
262  helperChannel2.SetNetDevicePointToPointMode (true);
263  NetDeviceContainer net2 = helperChannel2.Install (nodes);
264 
265  InternetStackHelper internet;
266  internet.Install (nodes);
267 
268  TrafficControlHelper tch = TrafficControlHelper::Default ();
269  QueueDiscContainer qdiscs = tch.Install (net1.Get (1));
270 
271  Ptr<Ipv4> ipv4;
272  uint32_t netdev_idx;
273  Ipv4InterfaceAddress ipv4Addr;
274 
275  // Receiver Node
276  ipv4 = rxNode->GetObject<Ipv4> ();
277  netdev_idx = ipv4->AddInterface (net1.Get (0));
278  ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.0.1"), Ipv4Mask (0xffff0000U));
279  ipv4->AddAddress (netdev_idx, ipv4Addr);
280  ipv4->SetUp (netdev_idx);
281 
282  netdev_idx = ipv4->AddInterface (net2.Get (0));
283  ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.1.1"), Ipv4Mask (0xffff0000U));
284  ipv4->AddAddress (netdev_idx, ipv4Addr);
285  ipv4->SetUp (netdev_idx);
286 
287  // Sender Node
288  ipv4 = txNode->GetObject<Ipv4> ();
289  netdev_idx = ipv4->AddInterface (net1.Get (1));
290  ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.0.2"), Ipv4Mask (0xffff0000U));
291  ipv4->AddAddress (netdev_idx, ipv4Addr);
292  ipv4->SetUp (netdev_idx);
293 
294  netdev_idx = ipv4->AddInterface (net2.Get (1));
295  ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.1.2"), Ipv4Mask (0xffff0000U));
296  ipv4->AddAddress (netdev_idx, ipv4Addr);
297  ipv4->SetUp (netdev_idx);
298 
299  // Create the UDP sockets
300  Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory> ();
301  Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket ();
302  NS_TEST_EXPECT_MSG_EQ (rxSocket->Bind (InetSocketAddress (Ipv4Address ("10.0.0.1"), 1234)), 0, "trivial");
303  rxSocket->SetRecvCallback (MakeCallback (&UdpSocketImplTest::ReceivePkt, this));
304 
305  Ptr<Socket> rxSocket2 = rxSocketFactory->CreateSocket ();
307  NS_TEST_EXPECT_MSG_EQ (rxSocket2->Bind (InetSocketAddress (Ipv4Address ("10.0.1.1"), 1234)), 0, "trivial");
308 
309  Ptr<SocketFactory> txSocketFactory = txNode->GetObject<UdpSocketFactory> ();
310  Ptr<Socket> txSocket = txSocketFactory->CreateSocket ();
311  txSocket->SetAllowBroadcast (true);
312 
313  // ------ Now the tests ------------
314 
315  // Unicast test
316  SendDataTo (txSocket, "10.0.0.1");
317  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 123, "trivial");
318  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 0, "second interface should receive it");
319 
322 
323  // Simple broadcast test
324 
325  SendDataTo (txSocket, "255.255.255.255");
326  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 123, "trivial");
327  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");
328 
331 
332  // Broadcast test with multiple receiving sockets
333 
334  // When receiving broadcast packets, all sockets sockets bound to
335  // the address/port should receive a copy of the same packet -- if
336  // the socket address matches.
337  rxSocket2->Dispose ();
338  rxSocket2 = rxSocketFactory->CreateSocket ();
340  NS_TEST_EXPECT_MSG_EQ (rxSocket2->Bind (InetSocketAddress (Ipv4Address ("0.0.0.0"), 1234)), 0, "trivial");
341 
342  SendDataTo (txSocket, "255.255.255.255");
343  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 123, "trivial");
344  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 123, "trivial");
345 
346  m_receivedPacket = 0;
347  m_receivedPacket2 = 0;
348 
349  // Simple Link-local multicast test
350 
351  txSocket->BindToNetDevice (net1.Get (1));
352  SendDataTo (txSocket, "224.0.0.9");
353  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");
354  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 123, "recv2: 224.0.0.9");
355 
356  m_receivedPacket->RemoveAllByteTags ();
358 
359  // Simple getpeername tests
360 
361  Address peerAddress;
362  int err = txSocket->GetPeerName (peerAddress);
363  NS_TEST_EXPECT_MSG_EQ (err, -1, "socket GetPeerName() should fail when socket is not connected");
364  NS_TEST_EXPECT_MSG_EQ (txSocket->GetErrno (), Socket::ERROR_NOTCONN, "socket error code should be ERROR_NOTCONN");
365 
366  InetSocketAddress peer ("10.0.0.1", 1234);
367  err = txSocket->Connect (peer);
368  NS_TEST_EXPECT_MSG_EQ (err, 0, "socket Connect() should succeed");
369 
370  err = txSocket->GetPeerName (peerAddress);
371  NS_TEST_EXPECT_MSG_EQ (err, 0, "socket GetPeerName() should succeed when socket is connected");
372  NS_TEST_EXPECT_MSG_EQ (peerAddress, peer, "address from socket GetPeerName() should equal the connected address");
373 
374  m_receivedPacket->RemoveAllByteTags ();
376 
377  // TOS and priority tests
378 
379  // Intercept the packets dequeued by the queue disc on the sender node
380  qdiscs.Get (0)->TraceConnectWithoutContext ("Dequeue", MakeCallback (&UdpSocketImplTest::SentPkt, this));
381 
382  // The socket is not connected.
383  txSocket->SetIpTos (0x28); // AF11
384  txSocket->SetPriority (6); // Interactive
385  // Send a packet to a specified destination:
386  // - for not connected sockets, the tos specified in the destination address (0) is used
387  // - since the tos is zero, the priority set for the socket is used
388  SendDataTo (txSocket, "10.0.0.1");
389  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 123, "trivial");
390 
391  NS_TEST_EXPECT_MSG_EQ (GetTos (), 0, "the TOS should be set to 0");
392  NS_TEST_EXPECT_MSG_EQ (GetPriority (), 6, "Interactive (6)");
393 
394  m_receivedPacket->RemoveAllByteTags ();
395 
396  InetSocketAddress dest ("10.0.0.1", 1234);
397  dest.SetTos (0xb8); // EF
398  // the connect operation sets the tos (and priority) for the socket
399  NS_TEST_EXPECT_MSG_EQ (txSocket->Connect (dest), 0, "the connect operation failed");
400 
401  SendData (txSocket);
402  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 123, "trivial");
403 
404  NS_TEST_EXPECT_MSG_EQ (GetTos (), 0xb8, "the TOS should be set to 0xb8");
405  NS_TEST_EXPECT_MSG_EQ (GetPriority (), 4, "Interactive bulk (4)");
406 
407  m_receivedPacket->RemoveAllByteTags ();
408 
409  Simulator::Destroy ();
410 
411 }
412 
414 {
417  void DoSendData (Ptr<Socket> socket, std::string to);
418  void SendData (Ptr<Socket> socket, std::string to);
419 
420 public:
421  virtual void DoRun (void);
423 
424  void ReceivePacket (Ptr<Socket> socket, Ptr<Packet> packet, const Address &from);
425  void ReceivePacket2 (Ptr<Socket> socket, Ptr<Packet> packet, const Address &from);
426  void ReceivePkt (Ptr<Socket> socket);
427  void ReceivePkt2 (Ptr<Socket> socket);
428 };
429 
431  : TestCase ("UDP6 socket implementation")
432 {
433 }
434 
436 {
437  m_receivedPacket = packet;
438 }
439 
441 {
442  m_receivedPacket2 = packet;
443 }
444 
446 {
447  uint32_t availableData;
448  availableData = socket->GetRxAvailable ();
450  NS_ASSERT (availableData == m_receivedPacket->GetSize ());
451  //cast availableData to void, to suppress 'availableData' set but not used
452  //compiler warning
453  (void) availableData;
454 }
455 
457 {
458  uint32_t availableData;
459  availableData = socket->GetRxAvailable ();
461  NS_ASSERT (availableData == m_receivedPacket2->GetSize ());
462  //cast availableData to void, to suppress 'availableData' set but not used
463  //compiler warning
464  (void) availableData;
465 }
466 
467 void
469 {
470  Address realTo = Inet6SocketAddress (Ipv6Address (to.c_str ()), 1234);
471  NS_TEST_EXPECT_MSG_EQ (socket->SendTo (Create<Packet> (123), 0, realTo),
472  123, "200");
473 }
474 
475 void
477 {
478  m_receivedPacket = Create<Packet> ();
479  m_receivedPacket2 = Create<Packet> ();
480  Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (0),
481  &Udp6SocketImplTest::DoSendData, this, socket, to);
482  Simulator::Run ();
483 }
484 
485 void
487 {
488  // Create topology
489 
490  // Receiver Node
491  Ptr<Node> rxNode = CreateObject<Node> ();
492  // Sender Node
493  Ptr<Node> txNode = CreateObject<Node> ();
494 
495  NodeContainer nodes (rxNode, txNode);
496 
497  SimpleNetDeviceHelper helperChannel1;
498  helperChannel1.SetNetDevicePointToPointMode (true);
499  NetDeviceContainer net1 = helperChannel1.Install (nodes);
500 
501  SimpleNetDeviceHelper helperChannel2;
502  helperChannel2.SetNetDevicePointToPointMode (true);
503  NetDeviceContainer net2 = helperChannel2.Install (nodes);
504 
505  InternetStackHelper internetv6;
506  internetv6.Install (nodes);
507 
508  txNode->GetObject<Icmpv6L4Protocol> ()->SetAttribute ("DAD", BooleanValue (false));
509  rxNode->GetObject<Icmpv6L4Protocol> ()->SetAttribute ("DAD", BooleanValue (false));
510 
511  Ipv6AddressHelper ipv6helper;
512  Ipv6InterfaceContainer iic1 = ipv6helper.AssignWithoutAddress (net1);
513  Ipv6InterfaceContainer iic2 = ipv6helper.AssignWithoutAddress (net2);
514 
515  Ptr<NetDevice> device;
516  Ptr<Ipv6> ipv6;
517  int32_t ifIndex;
518  Ipv6InterfaceAddress ipv6Addr;
519 
520  ipv6 = rxNode->GetObject<Ipv6> ();
521  device = net1.Get (0);
522  ifIndex = ipv6->GetInterfaceForDevice (device);
523  ipv6Addr = Ipv6InterfaceAddress (Ipv6Address ("2001:0100::1"), Ipv6Prefix (64));
524  ipv6->AddAddress (ifIndex, ipv6Addr);
525  ipv6->SetUp (ifIndex);
526 
527  device = net2.Get (0);
528  ifIndex = ipv6->GetInterfaceForDevice (device);
529  ipv6Addr = Ipv6InterfaceAddress (Ipv6Address ("2001:0100:1::1"), Ipv6Prefix (64));
530  ipv6->AddAddress (ifIndex, ipv6Addr);
531  ipv6->SetUp (ifIndex);
532 
533  ipv6 = txNode->GetObject<Ipv6> ();
534  device = net1.Get (1);
535  ifIndex = ipv6->GetInterfaceForDevice (device);
536  ipv6Addr = Ipv6InterfaceAddress (Ipv6Address ("2001:0100::2"), Ipv6Prefix (64));
537  ipv6->AddAddress (ifIndex, ipv6Addr);
538  ipv6->SetUp (ifIndex);
539 
540  device = net2.Get (1);
541  ifIndex = ipv6->GetInterfaceForDevice (device);
542  ipv6Addr = Ipv6InterfaceAddress (Ipv6Address ("2001:0100:1::2"), Ipv6Prefix (64));
543  ipv6->AddAddress (ifIndex, ipv6Addr);
544  ipv6->SetUp (ifIndex);
545 
546  // Create the UDP sockets
547  Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory> ();
548  Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket ();
549  NS_TEST_EXPECT_MSG_EQ (rxSocket->Bind (Inet6SocketAddress (Ipv6Address ("2001:0100::1"), 1234)), 0, "trivial");
550  rxSocket->SetRecvCallback (MakeCallback (&Udp6SocketImplTest::ReceivePkt, this));
551 
552  Ptr<Socket> rxSocket2 = rxSocketFactory->CreateSocket ();
554  NS_TEST_EXPECT_MSG_EQ (rxSocket2->Bind (Inet6SocketAddress (Ipv6Address ("2001:0100:1::1"), 1234)), 0, "trivial");
555 
556  Ptr<SocketFactory> txSocketFactory = txNode->GetObject<UdpSocketFactory> ();
557  Ptr<Socket> txSocket = txSocketFactory->CreateSocket ();
558  txSocket->SetAllowBroadcast (true);
559  // ------ Now the tests ------------
560 
561  // Unicast test
562  SendData (txSocket, "2001:0100::1");
563  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 123, "trivial");
564  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 0, "second interface should receive it");
565 
568 
569  // Simple Link-local multicast test
570 
571  // When receiving broadcast packets, all sockets sockets bound to
572  // the address/port should receive a copy of the same packet -- if
573  // the socket address matches.
574  rxSocket2->Dispose ();
575  rxSocket2 = rxSocketFactory->CreateSocket ();
577  NS_TEST_EXPECT_MSG_EQ (rxSocket2->Bind (Inet6SocketAddress (Ipv6Address ("::"), 1234)), 0, "trivial");
578 
579  txSocket->BindToNetDevice (net1.Get (1));
580  SendData (txSocket, "ff02::1");
581  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");
582  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 123, "recv2: ff02::1");
583 
586 
587  // Simple getpeername tests
588  Address peerAddress;
589  int err = txSocket->GetPeerName (peerAddress);
590  NS_TEST_EXPECT_MSG_EQ (err, -1, "socket GetPeerName() should fail when socket is not connected");
591  NS_TEST_EXPECT_MSG_EQ (txSocket->GetErrno (), Socket::ERROR_NOTCONN, "socket error code should be ERROR_NOTCONN");
592 
593  Inet6SocketAddress peer ("2001:0100::1", 1234);
594  err = txSocket->Connect (peer);
595  NS_TEST_EXPECT_MSG_EQ (err, 0, "socket Connect() should succeed");
596 
597  err = txSocket->GetPeerName (peerAddress);
598  NS_TEST_EXPECT_MSG_EQ (err, 0, "socket GetPeerName() should succeed when socket is connected");
599  NS_TEST_EXPECT_MSG_EQ (peerAddress, peer, "address from socket GetPeerName() should equal the connected address");
600 
601  Simulator::Destroy ();
602 
603 }
604 
605 
606 //-----------------------------------------------------------------------------
607 class UdpTestSuite : public TestSuite
608 {
609 public:
611  {
612  AddTestCase (new UdpSocketImplTest, TestCase::QUICK);
613  AddTestCase (new UdpSocketLoopbackTest, TestCase::QUICK);
614  AddTestCase (new Udp6SocketImplTest, TestCase::QUICK);
615  AddTestCase (new Udp6SocketLoopbackTest, TestCase::QUICK);
616  }
uint32_t GetTos(void)
Definition: udp-test.cc:200
void Dispose(void)
Dispose of this Object.
Definition: object.cc:214
void ReceivePkt(Ptr< Socket > socket)
Definition: udp-test.cc:120
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
an Inet address class
AttributeValue implementation for Boolean.
Definition: boolean.h:34
QueueDiscContainer Install(NetDeviceContainer c)
Keep track of a set of IPv6 interfaces.
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:132
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:462
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.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:257
A suite of tests to run.
Definition: test.h:1333
#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:278
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: udp-test.cc:246
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:792
virtual Ptr< Socket > CreateSocket(void)=0
encapsulates test code
Definition: test.h:1147
This test suite implements a Unit Test.
Definition: test.h:1343
Ptr< Packet > m_receivedPacket2
Definition: udp-test.cc:153
void SentPkt(Ptr< const QueueItem > item)
Definition: udp-test.cc:192
a polymophic address class
Definition: address.h:90
Holds a vector of ns3::QueueDisc pointers.
void SendData(Ptr< Socket > socket)
Definition: udp-test.cc:238
tuple nodes
Definition: first.py:25
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Definition: packet.cc:846
Ptr< QueueDisc > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
void ReceivePkt(Ptr< Socket > socket)
Definition: udp-test.cc:78
void ReceivePacket2(Ptr< Socket > socket, Ptr< Packet > packet, const Address &from)
Definition: udp-test.cc:440
#define max(a, b)
Definition: 80211b.c:45
Ptr< Packet > m_receivedPacket
Definition: udp-test.cc:70
Ptr< Packet > m_receivedPacket
Definition: udp-test.cc:112
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:298
virtual void SetUp(uint32_t interface)=0
const Ipv4Header & GetHeader(void) const
holds a vector of ns3::NetDevice pointers
indicates whether the socket has a priority set.
Definition: socket.h:1304
An Inet6 address class.
An implementation of the ICMPv6 protocol.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
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)
Definition: udp-test.cc:456
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:76
void ReceivePkt2(Ptr< Socket > socket)
Definition: udp-test.cc:184
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:122
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:299
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.
keep track of a set of node pointers.
void DoSendData(Ptr< Socket > socket)
Definition: udp-test.cc:232
void SendDataTo(Ptr< Socket > socket, std::string to)
Definition: udp-test.cc:222
void DoSendData(Ptr< Socket > socket, std::string to)
Definition: udp-test.cc:468
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.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
#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:732
uint8_t GetPriority(void) const
Get the tag's priority.
Definition: socket.cc:854
void ReceivePkt(Ptr< Socket > socket)
Definition: udp-test.cc:445
void DoSendDataTo(Ptr< Socket > socket, std::string to)
Definition: udp-test.cc:214
Helper class to auto-assign global IPv6 unicast addresses.
UdpTestSuite g_udpTestSuite
Ptr< Packet > m_receivedPacket2
Definition: udp-test.cc:416
void SendData(Ptr< Socket > socket, std::string to)
Definition: udp-test.cc:476
Describes an IPv6 address.
Definition: ipv6-address.h:48
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
uint32_t GetId(void) const
Definition: node.cc:107
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)
Definition: udp-test.cc:176
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
void RemoveAllByteTags(void)
Remove all byte tags stored in this packet.
Definition: packet.cc:349
Ptr< Packet > m_receivedPacket
Definition: udp-test.cc:415
Ptr< Packet > m_receivedPacket
Definition: udp-test.cc:152
Describes an IPv6 prefix.
Definition: ipv6-address.h:394
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)
Definition: udp-test.cc:435
uint32_t GetPriority(void)
Definition: udp-test.cc:205
uint8_t GetTos(void) const
Definition: ipv4-header.cc:194
API to create UDP socket instances.
build a set of SimpleNetDevice objects
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
Ptr< Ipv4QueueDiscItem > m_sentPacket
Definition: udp-test.cc:154
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: udp-test.cc:486
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:87
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.
Ptr< Packet > GetPacket(void) const
Definition: net-device.cc:45