A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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/drop-tail-queue.h"
32 #include "ns3/socket.h"
33 
34 #include "ns3/log.h"
35 #include "ns3/node.h"
36 #include "ns3/inet-socket-address.h"
37 #include "ns3/inet6-socket-address.h"
38 
39 #include "ns3/arp-l3-protocol.h"
40 #include "ns3/ipv4-l3-protocol.h"
41 #include "ns3/ipv6-l3-protocol.h"
42 #include "ns3/icmpv4-l4-protocol.h"
43 #include "ns3/icmpv6-l4-protocol.h"
44 #include "ns3/udp-l4-protocol.h"
45 #include "ns3/tcp-l4-protocol.h"
46 #include "ns3/ipv4-list-routing.h"
47 #include "ns3/ipv4-static-routing.h"
48 #include "ns3/ipv6-list-routing.h"
49 #include "ns3/ipv6-static-routing.h"
50 
51 #include <string>
52 #include <limits>
53 
54 using namespace ns3;
55 
56 static void
58 {
59  //ARP
60  Ptr<ArpL3Protocol> arp = CreateObject<ArpL3Protocol> ();
61  node->AggregateObject (arp);
62  //IPV4
63  Ptr<Ipv4L3Protocol> ipv4 = CreateObject<Ipv4L3Protocol> ();
64  //Routing for Ipv4
65  Ptr<Ipv4ListRouting> ipv4Routing = CreateObject<Ipv4ListRouting> ();
66  ipv4->SetRoutingProtocol (ipv4Routing);
67  Ptr<Ipv4StaticRouting> ipv4staticRouting = CreateObject<Ipv4StaticRouting> ();
68  ipv4Routing->AddRoutingProtocol (ipv4staticRouting, 0);
69  node->AggregateObject (ipv4);
70  //ICMP
71  Ptr<Icmpv4L4Protocol> icmp = CreateObject<Icmpv4L4Protocol> ();
72  node->AggregateObject (icmp);
73  //UDP
74  Ptr<UdpL4Protocol> udp = CreateObject<UdpL4Protocol> ();
75  node->AggregateObject (udp);
76  //TCP
77  Ptr<TcpL4Protocol> tcp = CreateObject<TcpL4Protocol> ();
78  node->AggregateObject (tcp);
79 }
80 
81 static void
83 {
84  //IPV6
85  Ptr<Ipv6L3Protocol> ipv6 = CreateObject<Ipv6L3Protocol> ();
86  //Routing for Ipv6
87  Ptr<Ipv6ListRouting> ipv6Routing = CreateObject<Ipv6ListRouting> ();
88  ipv6->SetRoutingProtocol (ipv6Routing);
89  Ptr<Ipv6StaticRouting> ipv6staticRouting = CreateObject<Ipv6StaticRouting> ();
90  ipv6Routing->AddRoutingProtocol (ipv6staticRouting, 0);
91  node->AggregateObject (ipv6);
92  //ICMP
93  Ptr<Icmpv6L4Protocol> icmp = CreateObject<Icmpv6L4Protocol> ();
94  node->AggregateObject (icmp);
95  //Ipv6 Extensions
96  ipv6->RegisterExtensions ();
97  ipv6->RegisterOptions ();
98  //UDP
99  Ptr<UdpL4Protocol> udp = CreateObject<UdpL4Protocol> ();
100  node->AggregateObject (udp);
101  //TCP
102  Ptr<TcpL4Protocol> tcp = CreateObject<TcpL4Protocol> ();
103  node->AggregateObject (tcp);
104 }
105 
106 
108 {
109 public:
111  virtual void DoRun (void);
112 
113  void ReceivePkt (Ptr<Socket> socket);
115 };
116 
118  : TestCase ("UDP loopback test")
119 {
120 }
121 
123 {
124  uint32_t availableData;
125  availableData = socket->GetRxAvailable ();
126  m_receivedPacket = socket->Recv (std::numeric_limits<uint32_t>::max (), 0);
127  NS_ASSERT (availableData == m_receivedPacket->GetSize ());
128 }
129 
130 void
132 {
133  Ptr<Node> rxNode = CreateObject<Node> ();
134  AddInternetStack (rxNode);
135 
136  Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory> ();
137  Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket ();
138  rxSocket->Bind (InetSocketAddress (Ipv4Address::GetAny (), 80));
139  rxSocket->SetRecvCallback (MakeCallback (&UdpSocketLoopbackTest::ReceivePkt, this));
140 
141  Ptr<Socket> txSocket = rxSocketFactory->CreateSocket ();
142  txSocket->SendTo (Create<Packet> (246), 0, InetSocketAddress ("127.0.0.1", 80));
143  Simulator::Run ();
144  Simulator::Destroy ();
145  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");
146 }
147 
149 {
150 public:
152  virtual void DoRun (void);
153 
154  void ReceivePkt (Ptr<Socket> socket);
156 };
157 
159  : TestCase ("UDP6 loopback test")
160 {
161 }
162 
164 {
165  uint32_t availableData;
166  availableData = socket->GetRxAvailable ();
167  m_receivedPacket = socket->Recv (std::numeric_limits<uint32_t>::max (), 0);
168  NS_ASSERT (availableData == m_receivedPacket->GetSize ());
169  //cast availableData to void, to suppress 'availableData' set but not used
170  //compiler warning
171  (void) availableData;
172 }
173 
174 void
176 {
177  Ptr<Node> rxNode = CreateObject<Node> ();
178  AddInternetStack6 (rxNode);
179 
180  Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory> ();
181  Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket ();
182  rxSocket->Bind (Inet6SocketAddress (Ipv6Address::GetAny (), 80));
183  rxSocket->SetRecvCallback (MakeCallback (&Udp6SocketLoopbackTest::ReceivePkt, this));
184 
185  Ptr<Socket> txSocket = rxSocketFactory->CreateSocket ();
186  txSocket->SendTo (Create<Packet> (246), 0, Inet6SocketAddress ("::1", 80));
187  Simulator::Run ();
188  Simulator::Destroy ();
189  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");
190 }
191 
193 {
196  void DoSendData (Ptr<Socket> socket, std::string to);
197  void SendData (Ptr<Socket> socket, std::string to);
198 
199 public:
200  virtual void DoRun (void);
202 
203  void ReceivePacket (Ptr<Socket> socket, Ptr<Packet> packet, const Address &from);
204  void ReceivePacket2 (Ptr<Socket> socket, Ptr<Packet> packet, const Address &from);
205  void ReceivePkt (Ptr<Socket> socket);
206  void ReceivePkt2 (Ptr<Socket> socket);
207 };
208 
210  : TestCase ("UDP socket implementation")
211 {
212 }
213 
215 {
216  m_receivedPacket = packet;
217 }
218 
220 {
221  m_receivedPacket2 = packet;
222 }
223 
225 {
226  uint32_t availableData;
227  availableData = socket->GetRxAvailable ();
228  m_receivedPacket = socket->Recv (std::numeric_limits<uint32_t>::max (), 0);
229  NS_ASSERT (availableData == m_receivedPacket->GetSize ());
230 }
231 
233 {
234  uint32_t availableData;
235  availableData = socket->GetRxAvailable ();
236  m_receivedPacket2 = socket->Recv (std::numeric_limits<uint32_t>::max (), 0);
237  NS_ASSERT (availableData == m_receivedPacket2->GetSize ());
238 }
239 
240 void
242 {
243  Address realTo = InetSocketAddress (Ipv4Address (to.c_str ()), 1234);
244  NS_TEST_EXPECT_MSG_EQ (socket->SendTo (Create<Packet> (123), 0, realTo),
245  123, "100");
246 }
247 
248 void
249 UdpSocketImplTest::SendData (Ptr<Socket> socket, std::string to)
250 {
251  m_receivedPacket = Create<Packet> ();
252  m_receivedPacket2 = Create<Packet> ();
253  Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (0),
254  &UdpSocketImplTest::DoSendData, this, socket, to);
255  Simulator::Run ();
256 }
257 
258 void
260 {
261  // Create topology
262 
263  // Receiver Node
264  Ptr<Node> rxNode = CreateObject<Node> ();
265  AddInternetStack (rxNode);
266  Ptr<SimpleNetDevice> rxDev1, rxDev2;
267  { // first interface
268  rxDev1 = CreateObject<SimpleNetDevice> ();
269  rxDev1->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
270  rxNode->AddDevice (rxDev1);
271  Ptr<Ipv4> ipv4 = rxNode->GetObject<Ipv4> ();
272  uint32_t netdev_idx = ipv4->AddInterface (rxDev1);
273  Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.0.1"), Ipv4Mask (0xffff0000U));
274  ipv4->AddAddress (netdev_idx, ipv4Addr);
275  ipv4->SetUp (netdev_idx);
276  }
277 
278  { // second interface
279  rxDev2 = CreateObject<SimpleNetDevice> ();
280  rxDev2->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
281  rxNode->AddDevice (rxDev2);
282  Ptr<Ipv4> ipv4 = rxNode->GetObject<Ipv4> ();
283  uint32_t netdev_idx = ipv4->AddInterface (rxDev2);
284  Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.1.1"), Ipv4Mask (0xffff0000U));
285  ipv4->AddAddress (netdev_idx, ipv4Addr);
286  ipv4->SetUp (netdev_idx);
287  }
288 
289  // Sender Node
290  Ptr<Node> txNode = CreateObject<Node> ();
291  AddInternetStack (txNode);
292  Ptr<SimpleNetDevice> txDev1;
293  {
294  txDev1 = CreateObject<SimpleNetDevice> ();
295  txDev1->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
296  txNode->AddDevice (txDev1);
297  Ptr<Ipv4> ipv4 = txNode->GetObject<Ipv4> ();
298  uint32_t netdev_idx = ipv4->AddInterface (txDev1);
299  Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.0.2"), Ipv4Mask (0xffff0000U));
300  ipv4->AddAddress (netdev_idx, ipv4Addr);
301  ipv4->SetUp (netdev_idx);
302  }
303  Ptr<SimpleNetDevice> txDev2;
304  {
305  txDev2 = CreateObject<SimpleNetDevice> ();
306  txDev2->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
307  txNode->AddDevice (txDev2);
308  Ptr<Ipv4> ipv4 = txNode->GetObject<Ipv4> ();
309  uint32_t netdev_idx = ipv4->AddInterface (txDev2);
310  Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.1.2"), Ipv4Mask (0xffff0000U));
311  ipv4->AddAddress (netdev_idx, ipv4Addr);
312  ipv4->SetUp (netdev_idx);
313  }
314 
315  // link the two nodes
316  Ptr<SimpleChannel> channel1 = CreateObject<SimpleChannel> ();
317  rxDev1->SetChannel (channel1);
318  txDev1->SetChannel (channel1);
319 
320  Ptr<SimpleChannel> channel2 = CreateObject<SimpleChannel> ();
321  rxDev2->SetChannel (channel2);
322  txDev2->SetChannel (channel2);
323 
324 
325  // Create the UDP sockets
326  Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory> ();
327  Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket ();
328  NS_TEST_EXPECT_MSG_EQ (rxSocket->Bind (InetSocketAddress (Ipv4Address ("10.0.0.1"), 1234)), 0, "trivial");
329  rxSocket->SetRecvCallback (MakeCallback (&UdpSocketImplTest::ReceivePkt, this));
330 
331  Ptr<Socket> rxSocket2 = rxSocketFactory->CreateSocket ();
333  NS_TEST_EXPECT_MSG_EQ (rxSocket2->Bind (InetSocketAddress (Ipv4Address ("10.0.1.1"), 1234)), 0, "trivial");
334 
335  Ptr<SocketFactory> txSocketFactory = txNode->GetObject<UdpSocketFactory> ();
336  Ptr<Socket> txSocket = txSocketFactory->CreateSocket ();
337  txSocket->SetAllowBroadcast (true);
338 
339  // ------ Now the tests ------------
340 
341  // Unicast test
342  SendData (txSocket, "10.0.0.1");
343  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 123, "trivial");
344  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 0, "second interface should receive it");
345 
348 
349  // Simple broadcast test
350 
351  SendData (txSocket, "255.255.255.255");
352  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 123, "trivial");
353  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");
354 
357 
358  // Broadcast test with multiple receiving sockets
359 
360  // When receiving broadcast packets, all sockets sockets bound to
361  // the address/port should receive a copy of the same packet -- if
362  // the socket address matches.
363  rxSocket2->Dispose ();
364  rxSocket2 = rxSocketFactory->CreateSocket ();
366  NS_TEST_EXPECT_MSG_EQ (rxSocket2->Bind (InetSocketAddress (Ipv4Address ("0.0.0.0"), 1234)), 0, "trivial");
367 
368  SendData (txSocket, "255.255.255.255");
369  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 123, "trivial");
370  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 123, "trivial");
371 
372  m_receivedPacket = 0;
373  m_receivedPacket2 = 0;
374 
375  // Simple Link-local multicast test
376 
377  txSocket->BindToNetDevice (txDev1);
378  SendData (txSocket, "224.0.0.9");
379  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");
380  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 123, "recv2: 224.0.0.9");
381 
382  m_receivedPacket->RemoveAllByteTags ();
384 
385  Simulator::Destroy ();
386 
387 }
388 
390 {
393  void DoSendData (Ptr<Socket> socket, std::string to);
394  void SendData (Ptr<Socket> socket, std::string to);
395 
396 public:
397  virtual void DoRun (void);
399 
400  void ReceivePacket (Ptr<Socket> socket, Ptr<Packet> packet, const Address &from);
401  void ReceivePacket2 (Ptr<Socket> socket, Ptr<Packet> packet, const Address &from);
402  void ReceivePkt (Ptr<Socket> socket);
403  void ReceivePkt2 (Ptr<Socket> socket);
404 };
405 
407  : TestCase ("UDP6 socket implementation")
408 {
409 }
410 
412 {
413  m_receivedPacket = packet;
414 }
415 
417 {
418  m_receivedPacket2 = packet;
419 }
420 
422 {
423  uint32_t availableData;
424  availableData = socket->GetRxAvailable ();
425  m_receivedPacket = socket->Recv (std::numeric_limits<uint32_t>::max (), 0);
426  NS_ASSERT (availableData == m_receivedPacket->GetSize ());
427  //cast availableData to void, to suppress 'availableData' set but not used
428  //compiler warning
429  (void) availableData;
430 }
431 
433 {
434  uint32_t availableData;
435  availableData = socket->GetRxAvailable ();
436  m_receivedPacket2 = socket->Recv (std::numeric_limits<uint32_t>::max (), 0);
437  NS_ASSERT (availableData == m_receivedPacket2->GetSize ());
438  //cast availableData to void, to suppress 'availableData' set but not used
439  //compiler warning
440  (void) availableData;
441 }
442 
443 void
445 {
446  Address realTo = Inet6SocketAddress (Ipv6Address (to.c_str ()), 1234);
447  NS_TEST_EXPECT_MSG_EQ (socket->SendTo (Create<Packet> (123), 0, realTo),
448  123, "200");
449 }
450 
451 void
453 {
454  m_receivedPacket = Create<Packet> ();
455  m_receivedPacket2 = Create<Packet> ();
456  Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (0),
457  &Udp6SocketImplTest::DoSendData, this, socket, to);
458  Simulator::Run ();
459 }
460 
461 void
463 {
464  // Create topology
465 
466  // Receiver Node
467  Ptr<Node> rxNode = CreateObject<Node> ();
468  AddInternetStack6 (rxNode);
469  Ptr<SimpleNetDevice> rxDev1, rxDev2;
470  { // first interface
471  rxDev1 = CreateObject<SimpleNetDevice> ();
472  rxDev1->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
473  rxNode->AddDevice (rxDev1);
474  Ptr<Ipv6> ipv6 = rxNode->GetObject<Ipv6> ();
475  uint32_t netdev_idx = ipv6->AddInterface (rxDev1);
476  Ipv6InterfaceAddress ipv6Addr = Ipv6InterfaceAddress (Ipv6Address ("2001:0100::1"), Ipv6Prefix (64));
477  ipv6->AddAddress (netdev_idx, ipv6Addr);
478  ipv6->SetUp (netdev_idx);
479  }
480  { // second interface
481  rxDev2 = CreateObject<SimpleNetDevice> ();
482  rxDev2->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
483  rxNode->AddDevice (rxDev2);
484  Ptr<Ipv6> ipv6 = rxNode->GetObject<Ipv6> ();
485  uint32_t netdev_idx = ipv6->AddInterface (rxDev2);
486  Ipv6InterfaceAddress ipv6Addr = Ipv6InterfaceAddress (Ipv6Address ("2001:0100:1::1"), Ipv6Prefix (64));
487  ipv6->AddAddress (netdev_idx, ipv6Addr);
488  ipv6->SetUp (netdev_idx);
489  }
490 
491  // Sender Node
492  Ptr<Node> txNode = CreateObject<Node> ();
493  AddInternetStack6 (txNode);
494  Ptr<SimpleNetDevice> txDev1;
495  {
496  txDev1 = CreateObject<SimpleNetDevice> ();
497  txDev1->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
498  txNode->AddDevice (txDev1);
499  Ptr<Ipv6> ipv6 = txNode->GetObject<Ipv6> ();
500  uint32_t netdev_idx = ipv6->AddInterface (txDev1);
501  Ipv6InterfaceAddress ipv6Addr = Ipv6InterfaceAddress (Ipv6Address ("2001:0100::2"), Ipv6Prefix (64));
502  ipv6->AddAddress (netdev_idx, ipv6Addr);
503  ipv6->SetUp (netdev_idx);
504  }
505  Ptr<SimpleNetDevice> txDev2;
506  {
507  txDev2 = CreateObject<SimpleNetDevice> ();
508  txDev2->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
509  txNode->AddDevice (txDev2);
510  Ptr<Ipv6> ipv6 = txNode->GetObject<Ipv6> ();
511  uint32_t netdev_idx = ipv6->AddInterface (txDev2);
512  Ipv6InterfaceAddress ipv6Addr = Ipv6InterfaceAddress (Ipv6Address ("2001:0100:1::2"), Ipv6Prefix (64));
513  ipv6->AddAddress (netdev_idx, ipv6Addr);
514  ipv6->SetUp (netdev_idx);
515  }
516 
517  // link the two nodes
518  Ptr<SimpleChannel> channel1 = CreateObject<SimpleChannel> ();
519  rxDev1->SetChannel (channel1);
520  txDev1->SetChannel (channel1);
521 
522  Ptr<SimpleChannel> channel2 = CreateObject<SimpleChannel> ();
523  rxDev2->SetChannel (channel2);
524  txDev2->SetChannel (channel2);
525 
526 
527  // Create the UDP sockets
528  Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory> ();
529  Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket ();
530  NS_TEST_EXPECT_MSG_EQ (rxSocket->Bind (Inet6SocketAddress (Ipv6Address ("2001:0100::1"), 1234)), 0, "trivial");
531  rxSocket->SetRecvCallback (MakeCallback (&Udp6SocketImplTest::ReceivePkt, this));
532 
533  Ptr<Socket> rxSocket2 = rxSocketFactory->CreateSocket ();
535  NS_TEST_EXPECT_MSG_EQ (rxSocket2->Bind (Inet6SocketAddress (Ipv6Address ("2001:0100:1::1"), 1234)), 0, "trivial");
536 
537  Ptr<SocketFactory> txSocketFactory = txNode->GetObject<UdpSocketFactory> ();
538  Ptr<Socket> txSocket = txSocketFactory->CreateSocket ();
539  txSocket->SetAllowBroadcast (true);
540  // ------ Now the tests ------------
541 
542  // Unicast test
543  SendData (txSocket, "2001:0100::1");
544  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 123, "trivial");
545  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 0, "second interface should receive it");
546 
549 
550  // Simple Link-local multicast test
551 
552  // When receiving broadcast packets, all sockets sockets bound to
553  // the address/port should receive a copy of the same packet -- if
554  // the socket address matches.
555  rxSocket2->Dispose ();
556  rxSocket2 = rxSocketFactory->CreateSocket ();
558  NS_TEST_EXPECT_MSG_EQ (rxSocket2->Bind (Inet6SocketAddress (Ipv6Address ("::"), 1234)), 0, "trivial");
559 
560  txSocket->BindToNetDevice (txDev1);
561  SendData (txSocket, "ff02::1");
562  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");
563  NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 123, "recv2: ff02::1");
564 
567 
568  Simulator::Destroy ();
569 
570 }
571 
572 
573 //-----------------------------------------------------------------------------
574 class UdpTestSuite : public TestSuite
575 {
576 public:
578  {
579  AddTestCase (new UdpSocketImplTest, TestCase::QUICK);
580  AddTestCase (new UdpSocketLoopbackTest, TestCase::QUICK);
581  AddTestCase (new Udp6SocketImplTest, TestCase::QUICK);
582  AddTestCase (new Udp6SocketLoopbackTest, TestCase::QUICK);
583  }
void ReceivePkt(Ptr< Socket > socket)
Definition: udp-test.cc:163
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
static void AddInternetStack6(Ptr< Node > node)
Definition: udp-test.cc:82
an Inet address class
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: udp-test.cc:175
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:80
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:222
A suite of tests to run.
Definition: test.h:1105
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
IPv6 address associated with an interface.
#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:265
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: udp-test.cc:259
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:744
virtual Ptr< Socket > CreateSocket(void)=0
static void AddInternetStack(Ptr< Node > node)
Definition: udp-test.cc:57
encapsulates test code
Definition: test.h:929
Ptr< Packet > m_receivedPacket2
Definition: udp-test.cc:195
a polymophic address class
Definition: address.h:86
void DoSendData(Ptr< Socket > socket, std::string to)
Definition: udp-test.cc:241
void SendData(Ptr< Socket > socket, std::string to)
Definition: udp-test.cc:249
void ReceivePkt(Ptr< Socket > socket)
Definition: udp-test.cc:122
void ReceivePacket2(Ptr< Socket > socket, Ptr< Packet > packet, const Address &from)
Definition: udp-test.cc:416
Ptr< Packet > m_receivedPacket
Definition: udp-test.cc:114
Ptr< Packet > m_receivedPacket
Definition: udp-test.cc:155
virtual void SetUp(uint32_t interface)=0
An Inet6 address class.
void ReceivePacket(Ptr< Socket > socket, Ptr< Packet > packet, const Address &from)
Definition: udp-test.cc:214
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1242
void SetRecvCallback(Callback< void, Ptr< Socket > >)
Notify application when new data is available to be read.
Definition: socket.cc:127
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:70
void AggregateObject(Ptr< Object > other)
Definition: object.cc:242
void ReceivePkt2(Ptr< Socket > socket)
Definition: udp-test.cc:432
Access to the Ipv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:76
void ReceivePkt2(Ptr< Socket > socket)
Definition: udp-test.cc:232
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
void DoSendData(Ptr< Socket > socket, std::string to)
Definition: udp-test.cc:444
virtual Ptr< Packet > Recv(uint32_t maxSize, uint32_t flags)=0
Read data from the socket.
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition: test.cc:184
void ReceivePacket2(Ptr< Socket > socket, Ptr< Packet > packet, const Address &from)
Definition: udp-test.cc:219
void ReceivePkt(Ptr< Socket > socket)
Definition: udp-test.cc:421
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
Add a NetDevice interface.
UdpTestSuite g_udpTestSuite
Ptr< Packet > m_receivedPacket2
Definition: udp-test.cc:392
void SendData(Ptr< Socket > socket, std::string to)
Definition: udp-test.cc:452
virtual void RegisterExtensions()
Register the IPv6 Extensions.
Describes an IPv6 address.
Definition: ipv6-address.h:46
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
void SetRoutingProtocol(Ptr< Ipv6RoutingProtocol > routingProtocol)
Set routing protocol for this stack.
uint32_t AddDevice(Ptr< NetDevice > device)
Definition: node.cc:120
uint32_t GetId(void) const
Definition: node.cc:106
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:224
virtual void SetAddress(Address address)
Set the address of this interface.
void RemoveAllByteTags(void)
Remove all byte tags stored in this packet.
Definition: packet.cc:361
Ptr< Packet > m_receivedPacket
Definition: udp-test.cc:391
Ptr< Packet > m_receivedPacket
Definition: udp-test.cc:194
virtual void RegisterOptions()
Register the IPv6 Options.
Describes an IPv6 prefix.
Definition: ipv6-address.h:387
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:411
API to create UDP socket instances.
This test suite implements a Unit Test.
Definition: test.h:1115
void SetChannel(Ptr< SimpleChannel > channel)
Attach a channel to this net device.
Ptr< T > GetObject(void) const
Definition: object.h:362
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: udp-test.cc:462
void Dispose(void)
Run the DoDispose methods of this object and all the objects aggregated to it.
Definition: object.cc:204
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: udp-test.cc:131
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.
void SetRoutingProtocol(Ptr< Ipv4RoutingProtocol > routingProtocol)
Register a new routing protocol to be used by this Ipv4 stack.