A Discrete-Event Network Simulator
API
udp-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 Georgia Tech Research Corporation
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Raj Bhattacharjea <raj.b@gatech.edu>
18 */
24#include "ns3/arp-l3-protocol.h"
25#include "ns3/boolean.h"
26#include "ns3/icmpv4-l4-protocol.h"
27#include "ns3/icmpv6-l4-protocol.h"
28#include "ns3/inet-socket-address.h"
29#include "ns3/inet6-socket-address.h"
30#include "ns3/internet-stack-helper.h"
31#include "ns3/ipv4-l3-protocol.h"
32#include "ns3/ipv4-list-routing.h"
33#include "ns3/ipv4-queue-disc-item.h"
34#include "ns3/ipv4-static-routing.h"
35#include "ns3/ipv6-address-helper.h"
36#include "ns3/ipv6-l3-protocol.h"
37#include "ns3/ipv6-list-routing.h"
38#include "ns3/ipv6-static-routing.h"
39#include "ns3/log.h"
40#include "ns3/node.h"
41#include "ns3/simple-channel.h"
42#include "ns3/simple-net-device-helper.h"
43#include "ns3/simple-net-device.h"
44#include "ns3/simulator.h"
45#include "ns3/socket-factory.h"
46#include "ns3/socket.h"
47#include "ns3/tcp-l4-protocol.h"
48#include "ns3/test.h"
49#include "ns3/traffic-control-helper.h"
50#include "ns3/udp-l4-protocol.h"
51#include "ns3/udp-socket-factory.h"
52
53#include <limits>
54#include <string>
55
56using namespace ns3;
57
65{
66 public:
68 void DoRun() override;
69
74 void ReceivePkt(Ptr<Socket> socket);
76};
77
79 : TestCase("UDP loopback test")
80{
81}
82
83void
85{
86 uint32_t availableData;
87 availableData = socket->GetRxAvailable();
89 NS_TEST_ASSERT_MSG_EQ(availableData,
91 "ReceivedPacket size is not equal to the Rx buffer size");
92}
93
94void
96{
97 Ptr<Node> rxNode = CreateObject<Node>();
98 InternetStackHelper internet;
99 internet.Install(rxNode);
100
101 Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory>();
102 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
103 rxSocket->Bind(InetSocketAddress(Ipv4Address::GetAny(), 80));
104 rxSocket->SetRecvCallback(MakeCallback(&UdpSocketLoopbackTest::ReceivePkt, this));
105
106 Ptr<Socket> txSocket = rxSocketFactory->CreateSocket();
107 txSocket->SendTo(Create<Packet>(246), 0, InetSocketAddress("127.0.0.1", 80));
108 Simulator::Run();
109 Simulator::Destroy();
111 246,
112 "first socket should not receive it (it is bound specifically to the "
113 "second interface's address");
114}
115
123{
124 public:
126 void DoRun() override;
127
132 void ReceivePkt(Ptr<Socket> socket);
134};
135
137 : TestCase("UDP6 loopback test")
138{
139}
140
141void
143{
144 uint32_t availableData [[maybe_unused]] = socket->GetRxAvailable();
146 NS_TEST_ASSERT_MSG_EQ(availableData,
148 "ReceivedPacket size is not equal to the Rx buffer size");
149}
150
151void
153{
154 Ptr<Node> rxNode = CreateObject<Node>();
155 InternetStackHelper internet;
156 internet.Install(rxNode);
157
158 Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory>();
159 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
160 rxSocket->Bind(Inet6SocketAddress(Ipv6Address::GetAny(), 80));
161 rxSocket->SetRecvCallback(MakeCallback(&Udp6SocketLoopbackTest::ReceivePkt, this));
162
163 Ptr<Socket> txSocket = rxSocketFactory->CreateSocket();
164 txSocket->SendTo(Create<Packet>(246), 0, Inet6SocketAddress("::1", 80));
165 Simulator::Run();
166 Simulator::Destroy();
168 246,
169 "first socket should not receive it (it is bound specifically to the "
170 "second interface's address");
171}
172
180{
184
190
196
202 void DoSendDataTo(Ptr<Socket> socket, std::string to);
208 void SendDataTo(Ptr<Socket> socket, std::string to);
213 void DoSendData(Ptr<Socket> socket);
218 void SendData(Ptr<Socket> socket);
219
220 public:
221 void DoRun() override;
223
228 void ReceivePkt(Ptr<Socket> socket);
233 void ReceivePkt2(Ptr<Socket> socket);
234
240};
241
243 : TestCase("UDP socket implementation")
244{
245}
246
247void
249{
250 uint32_t availableData;
251 availableData = socket->GetRxAvailable();
253 NS_TEST_ASSERT_MSG_EQ(availableData,
255 "ReceivedPacket size is not equal to the Rx buffer size");
256}
257
258void
260{
261 uint32_t availableData;
262 availableData = socket->GetRxAvailable();
264 NS_TEST_ASSERT_MSG_EQ(availableData,
266 "ReceivedPacket size is not equal to the Rx buffer size");
267}
268
269void
271{
272 Ptr<const Ipv4QueueDiscItem> ipv4Item = DynamicCast<const Ipv4QueueDiscItem>(item);
273 NS_TEST_EXPECT_MSG_NE(ipv4Item, nullptr, "no IPv4 packet");
274 Address addr;
276 Create<Ipv4QueueDiscItem>(ipv4Item->GetPacket()->Copy(), addr, 0, ipv4Item->GetHeader());
277}
278
281{
282 return static_cast<uint32_t>(m_sentPacket->GetHeader().GetTos());
283}
284
287{
288 SocketPriorityTag priorityTag;
289 bool found = m_sentPacket->GetPacket()->PeekPacketTag(priorityTag);
290 NS_TEST_EXPECT_MSG_EQ(found, true, "the packet should carry a SocketPriorityTag");
291 return static_cast<uint32_t>(priorityTag.GetPriority());
292}
293
294void
296{
297 Address realTo = InetSocketAddress(Ipv4Address(to.c_str()), 1234);
298 NS_TEST_EXPECT_MSG_EQ(socket->SendTo(Create<Packet>(123), 0, realTo), 123, "100");
299}
300
301void
303{
304 m_receivedPacket = Create<Packet>();
305 m_receivedPacket2 = Create<Packet>();
306 Simulator::ScheduleWithContext(socket->GetNode()->GetId(),
307 Seconds(0),
309 this,
310 socket,
311 to);
312 Simulator::Run();
313}
314
315void
317{
318 NS_TEST_EXPECT_MSG_EQ(socket->Send(Create<Packet>(123), 0), 123, "100");
319}
320
321void
323{
324 Simulator::ScheduleWithContext(socket->GetNode()->GetId(),
325 Seconds(0),
327 this,
328 socket);
329 Simulator::Run();
330}
331
332void
334{
335 // Create topology
336
337 // Receiver Node
338 Ptr<Node> rxNode = CreateObject<Node>();
339 // Sender Node
340 Ptr<Node> txNode = CreateObject<Node>();
341
342 NodeContainer nodes(rxNode, txNode);
343
344 SimpleNetDeviceHelper helperChannel1;
345 helperChannel1.SetNetDevicePointToPointMode(true);
346 NetDeviceContainer net1 = helperChannel1.Install(nodes);
347
348 SimpleNetDeviceHelper helperChannel2;
349 helperChannel2.SetNetDevicePointToPointMode(true);
350 NetDeviceContainer net2 = helperChannel2.Install(nodes);
351
352 InternetStackHelper internet;
353 internet.Install(nodes);
354
355 TrafficControlHelper tch = TrafficControlHelper::Default();
356 QueueDiscContainer qdiscs = tch.Install(net1.Get(1));
357
358 Ptr<Ipv4> ipv4;
359 uint32_t netdev_idx;
360 Ipv4InterfaceAddress ipv4Addr;
361
362 // Receiver Node
363 ipv4 = rxNode->GetObject<Ipv4>();
364 netdev_idx = ipv4->AddInterface(net1.Get(0));
365 ipv4Addr = Ipv4InterfaceAddress(Ipv4Address("10.0.0.1"), Ipv4Mask("/24"));
366 ipv4->AddAddress(netdev_idx, ipv4Addr);
367 ipv4->SetUp(netdev_idx);
368
369 netdev_idx = ipv4->AddInterface(net2.Get(0));
370 ipv4Addr = Ipv4InterfaceAddress(Ipv4Address("10.0.1.1"), Ipv4Mask("/24"));
371 ipv4->AddAddress(netdev_idx, ipv4Addr);
372 ipv4->SetUp(netdev_idx);
373
374 // Sender Node
375 ipv4 = txNode->GetObject<Ipv4>();
376 netdev_idx = ipv4->AddInterface(net1.Get(1));
377 ipv4Addr = Ipv4InterfaceAddress(Ipv4Address("10.0.0.2"), Ipv4Mask("/24"));
378 ipv4->AddAddress(netdev_idx, ipv4Addr);
379 ipv4->SetUp(netdev_idx);
380
381 netdev_idx = ipv4->AddInterface(net2.Get(1));
382 ipv4Addr = Ipv4InterfaceAddress(Ipv4Address("10.0.1.2"), Ipv4Mask("/24"));
383 ipv4->AddAddress(netdev_idx, ipv4Addr);
384 ipv4->SetUp(netdev_idx);
385
386 // Create the UDP sockets
387 Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory>();
388
389 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
390 NS_TEST_EXPECT_MSG_EQ(rxSocket->Bind(InetSocketAddress(Ipv4Address("10.0.0.1"), 1234)),
391 0,
392 "trivial");
393 rxSocket->SetRecvCallback(MakeCallback(&UdpSocketImplTest::ReceivePkt, this));
394
395 Ptr<Socket> rxSocket2 = rxSocketFactory->CreateSocket();
396 NS_TEST_EXPECT_MSG_EQ(rxSocket2->Bind(InetSocketAddress(Ipv4Address("10.0.1.1"), 1234)),
397 0,
398 "trivial");
400
401 Ptr<SocketFactory> txSocketFactory = txNode->GetObject<UdpSocketFactory>();
402 Ptr<Socket> txSocket = txSocketFactory->CreateSocket();
403 txSocket->SetAllowBroadcast(true);
404
405 // ------ Now the tests ------------
406
407 // Unicast test
408 SendDataTo(txSocket, "10.0.0.1");
411 0,
412 "second interface should not receive it");
413
416
417 // Simple broadcast test
418
419 SendDataTo(txSocket, "255.255.255.255");
421 0,
422 "first socket should not receive it (it is bound specifically to the "
423 "first interface's address");
425 0,
426 "second socket should not receive it (it is bound specifically to the "
427 "second interface's address");
428
431
432 // Broadcast test with multiple receiving sockets
433
434 // When receiving broadcast packets, all sockets sockets bound to
435 // the address/port should receive a copy of the same packet -- if
436 // the socket address matches.
437 rxSocket2->Dispose();
438 rxSocket2 = rxSocketFactory->CreateSocket();
440 NS_TEST_EXPECT_MSG_EQ(rxSocket2->Bind(InetSocketAddress(Ipv4Address("0.0.0.0"), 1234)),
441 0,
442 "trivial");
443
444 SendDataTo(txSocket, "255.255.255.255");
446 0,
447 "first socket should not receive it (it is bound specifically to the "
448 "first interface's address");
450
451 m_receivedPacket = nullptr;
452 m_receivedPacket2 = nullptr;
453
454 // Simple Link-local multicast test
455
456 txSocket->BindToNetDevice(net1.Get(1));
457 SendDataTo(txSocket, "224.0.0.9");
459 0,
460 "first socket should not receive it (it is bound specifically to the "
461 "first interface's address");
462 NS_TEST_EXPECT_MSG_EQ(m_receivedPacket2->GetSize(), 123, "recv2: 224.0.0.9");
463
466
467 // Simple getpeername tests
468
469 Address peerAddress;
470 int err = txSocket->GetPeerName(peerAddress);
471 NS_TEST_EXPECT_MSG_EQ(err, -1, "socket GetPeerName() should fail when socket is not connected");
472 NS_TEST_EXPECT_MSG_EQ(txSocket->GetErrno(),
473 Socket::ERROR_NOTCONN,
474 "socket error code should be ERROR_NOTCONN");
475
476 InetSocketAddress peer("10.0.0.1", 1234);
477 err = txSocket->Connect(peer);
478 NS_TEST_EXPECT_MSG_EQ(err, 0, "socket Connect() should succeed");
479
480 err = txSocket->GetPeerName(peerAddress);
481 NS_TEST_EXPECT_MSG_EQ(err, 0, "socket GetPeerName() should succeed when socket is connected");
482 NS_TEST_EXPECT_MSG_EQ(peerAddress,
483 peer,
484 "address from socket GetPeerName() should equal the connected address");
485
488
489 // TOS and priority tests
490
491 // Intercept the packets dequeued by the queue disc on the sender node
492 qdiscs.Get(0)->TraceConnectWithoutContext("Dequeue",
494
495 // The socket is not connected.
496 txSocket->SetIpTos(0x28); // AF11
497 txSocket->SetPriority(6); // Interactive
498 // Send a packet to a specified destination:
499 // - for not connected sockets, the tos specified in the destination address (0) is used
500 // - since the tos is zero, the priority set for the socket is used
501 SendDataTo(txSocket, "10.0.0.1");
503
504 NS_TEST_EXPECT_MSG_EQ(GetTos(), 0, "the TOS should be set to 0");
505 NS_TEST_EXPECT_MSG_EQ(GetPriority(), 6, "Interactive (6)");
506
508
509 InetSocketAddress dest("10.0.0.1", 1234);
510 dest.SetTos(0xb8); // EF
511 // the connect operation sets the tos (and priority) for the socket
512 NS_TEST_EXPECT_MSG_EQ(txSocket->Connect(dest), 0, "the connect operation failed");
513
514 SendData(txSocket);
516
517 NS_TEST_EXPECT_MSG_EQ(GetTos(), 0xb8, "the TOS should be set to 0xb8");
518 NS_TEST_EXPECT_MSG_EQ(GetPriority(), 4, "Interactive bulk (4)");
519
521
522 Simulator::Destroy();
523}
524
532{
535
541 void DoSendDataTo(Ptr<Socket> socket, std::string to);
547 void SendDataTo(Ptr<Socket> socket, std::string to);
548
549 public:
550 void DoRun() override;
552
559 void ReceivePacket(Ptr<Socket> socket, Ptr<Packet> packet, const Address& from);
566 void ReceivePacket2(Ptr<Socket> socket, Ptr<Packet> packet, const Address& from);
571 void ReceivePkt(Ptr<Socket> socket);
576 void ReceivePkt2(Ptr<Socket> socket);
577};
578
580 : TestCase("UDP6 socket implementation")
581{
582}
583
584void
586{
587 m_receivedPacket = packet;
588}
589
590void
592{
593 m_receivedPacket2 = packet;
594}
595
596void
598{
599 uint32_t availableData [[maybe_unused]] = socket->GetRxAvailable();
601 NS_TEST_ASSERT_MSG_EQ(availableData,
603 "ReceivedPacket size is not equal to the Rx buffer size");
604}
605
606void
608{
609 uint32_t availableData [[maybe_unused]] = socket->GetRxAvailable();
611 NS_TEST_ASSERT_MSG_EQ(availableData,
613 "ReceivedPacket size is not equal to the Rx buffer size");
614}
615
616void
618{
619 Address realTo = Inet6SocketAddress(Ipv6Address(to.c_str()), 1234);
620 NS_TEST_EXPECT_MSG_EQ(socket->SendTo(Create<Packet>(123), 0, realTo), 123, "200");
621}
622
623void
625{
626 m_receivedPacket = Create<Packet>();
627 m_receivedPacket2 = Create<Packet>();
628 Simulator::ScheduleWithContext(socket->GetNode()->GetId(),
629 Seconds(0),
631 this,
632 socket,
633 to);
634 Simulator::Run();
635}
636
637void
639{
640 // Create topology
641
642 // Receiver Node
643 Ptr<Node> rxNode = CreateObject<Node>();
644 // Sender Node
645 Ptr<Node> txNode = CreateObject<Node>();
646
647 NodeContainer nodes(rxNode, txNode);
648
649 SimpleNetDeviceHelper helperChannel1;
650 helperChannel1.SetNetDevicePointToPointMode(true);
651 NetDeviceContainer net1 = helperChannel1.Install(nodes);
652
653 SimpleNetDeviceHelper helperChannel2;
654 helperChannel2.SetNetDevicePointToPointMode(true);
655 NetDeviceContainer net2 = helperChannel2.Install(nodes);
656
657 InternetStackHelper internetv6;
658 internetv6.Install(nodes);
659
660 txNode->GetObject<Icmpv6L4Protocol>()->SetAttribute("DAD", BooleanValue(false));
661 rxNode->GetObject<Icmpv6L4Protocol>()->SetAttribute("DAD", BooleanValue(false));
662
663 Ipv6AddressHelper ipv6helper;
664 Ipv6InterfaceContainer iic1 = ipv6helper.AssignWithoutAddress(net1);
665 Ipv6InterfaceContainer iic2 = ipv6helper.AssignWithoutAddress(net2);
666
667 Ptr<NetDevice> device;
668 Ptr<Ipv6> ipv6;
669 int32_t ifIndex;
670 Ipv6InterfaceAddress ipv6Addr;
671
672 ipv6 = rxNode->GetObject<Ipv6>();
673 device = net1.Get(0);
674 ifIndex = ipv6->GetInterfaceForDevice(device);
675 ipv6Addr = Ipv6InterfaceAddress(Ipv6Address("2001:0100::1"), Ipv6Prefix(64));
676 ipv6->AddAddress(ifIndex, ipv6Addr);
677 ipv6->SetUp(ifIndex);
678
679 device = net2.Get(0);
680 ifIndex = ipv6->GetInterfaceForDevice(device);
681 ipv6Addr = Ipv6InterfaceAddress(Ipv6Address("2001:0100:1::1"), Ipv6Prefix(64));
682 ipv6->AddAddress(ifIndex, ipv6Addr);
683 ipv6->SetUp(ifIndex);
684
685 ipv6 = txNode->GetObject<Ipv6>();
686 device = net1.Get(1);
687 ifIndex = ipv6->GetInterfaceForDevice(device);
688 ipv6Addr = Ipv6InterfaceAddress(Ipv6Address("2001:0100::2"), Ipv6Prefix(64));
689 ipv6->AddAddress(ifIndex, ipv6Addr);
690 ipv6->SetUp(ifIndex);
691
692 device = net2.Get(1);
693 ifIndex = ipv6->GetInterfaceForDevice(device);
694 ipv6Addr = Ipv6InterfaceAddress(Ipv6Address("2001:0100:1::2"), Ipv6Prefix(64));
695 ipv6->AddAddress(ifIndex, ipv6Addr);
696 ipv6->SetUp(ifIndex);
697
698 // Create the UDP sockets
699 Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory>();
700 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
701 NS_TEST_EXPECT_MSG_EQ(rxSocket->Bind(Inet6SocketAddress(Ipv6Address("2001:0100::1"), 1234)),
702 0,
703 "trivial");
704 rxSocket->SetRecvCallback(MakeCallback(&Udp6SocketImplTest::ReceivePkt, this));
705
706 Ptr<Socket> rxSocket2 = rxSocketFactory->CreateSocket();
708 NS_TEST_EXPECT_MSG_EQ(rxSocket2->Bind(Inet6SocketAddress(Ipv6Address("2001:0100:1::1"), 1234)),
709 0,
710 "trivial");
711
712 Ptr<SocketFactory> txSocketFactory = txNode->GetObject<UdpSocketFactory>();
713 Ptr<Socket> txSocket = txSocketFactory->CreateSocket();
714 txSocket->SetAllowBroadcast(true);
715 // ------ Now the tests ------------
716
717 // Unicast test
718 SendDataTo(txSocket, "2001:0100::1");
720 NS_TEST_EXPECT_MSG_EQ(m_receivedPacket2->GetSize(), 0, "second interface should receive it");
721
724
725 // Simple Link-local multicast test
726
727 // When receiving broadcast packets, all sockets sockets bound to
728 // the address/port should receive a copy of the same packet -- if
729 // the socket address matches.
730 rxSocket2->Dispose();
731 rxSocket2 = rxSocketFactory->CreateSocket();
734 0,
735 "trivial");
736
737 txSocket->BindToNetDevice(net1.Get(1));
738 SendDataTo(txSocket, "ff02::1");
740 0,
741 "first socket should not receive it (it is bound specifically to the "
742 "second interface's address");
743 NS_TEST_EXPECT_MSG_EQ(m_receivedPacket2->GetSize(), 123, "recv2: ff02::1");
744
747
748 // Simple getpeername tests
749 Address peerAddress;
750 int err = txSocket->GetPeerName(peerAddress);
751 NS_TEST_EXPECT_MSG_EQ(err, -1, "socket GetPeerName() should fail when socket is not connected");
752 NS_TEST_EXPECT_MSG_EQ(txSocket->GetErrno(),
753 Socket::ERROR_NOTCONN,
754 "socket error code should be ERROR_NOTCONN");
755
756 Inet6SocketAddress peer("2001:0100::1", 1234);
757 err = txSocket->Connect(peer);
758 NS_TEST_EXPECT_MSG_EQ(err, 0, "socket Connect() should succeed");
759
760 err = txSocket->GetPeerName(peerAddress);
761 NS_TEST_EXPECT_MSG_EQ(err, 0, "socket GetPeerName() should succeed when socket is connected");
762 NS_TEST_EXPECT_MSG_EQ(peerAddress,
763 peer,
764 "address from socket GetPeerName() should equal the connected address");
765
766 Simulator::Destroy();
767}
768
776{
777 public:
779 : TestSuite("udp", UNIT)
780 {
781 AddTestCase(new UdpSocketImplTest, TestCase::QUICK);
782 AddTestCase(new UdpSocketLoopbackTest, TestCase::QUICK);
783 AddTestCase(new Udp6SocketImplTest, TestCase::QUICK);
784 AddTestCase(new Udp6SocketLoopbackTest, TestCase::QUICK);
785 }
786};
787
#define max(a, b)
Definition: 80211b.c:43
UDP Socket over IPv6 Test.
Definition: udp-test.cc:532
Ptr< Packet > m_receivedPacket
Received packet (1).
Definition: udp-test.cc:533
void ReceivePacket(Ptr< Socket > socket, Ptr< Packet > packet, const Address &from)
Receive packets (1).
Definition: udp-test.cc:585
void SendDataTo(Ptr< Socket > socket, std::string to)
Send data.
Definition: udp-test.cc:624
void ReceivePkt2(Ptr< Socket > socket)
Receive packets (2).
Definition: udp-test.cc:607
void DoRun() override
Implementation to actually run this TestCase.
Definition: udp-test.cc:638
Ptr< Packet > m_receivedPacket2
Received packet (2).
Definition: udp-test.cc:534
void ReceivePkt(Ptr< Socket > socket)
Receive packets (1).
Definition: udp-test.cc:597
void ReceivePacket2(Ptr< Socket > socket, Ptr< Packet > packet, const Address &from)
Receive packets (2).
Definition: udp-test.cc:591
void DoSendDataTo(Ptr< Socket > socket, std::string to)
Send data.
Definition: udp-test.cc:617
UDP Socket Loopback over IPv6 Test.
Definition: udp-test.cc:123
void ReceivePkt(Ptr< Socket > socket)
Receive a packet.
Definition: udp-test.cc:142
Ptr< Packet > m_receivedPacket
Received packet.
Definition: udp-test.cc:133
void DoRun() override
Implementation to actually run this TestCase.
Definition: udp-test.cc:152
UDP Socket over IPv4 Test.
Definition: udp-test.cc:180
uint32_t GetTos()
Get the TOS of the received packet.
Definition: udp-test.cc:280
uint32_t GetPriority()
Get the priority of the received packet.
Definition: udp-test.cc:286
void SendData(Ptr< Socket > socket)
Send data.
Definition: udp-test.cc:322
void ReceivePkt2(Ptr< Socket > socket)
Receive packets (2).
Definition: udp-test.cc:259
void SendDataTo(Ptr< Socket > socket, std::string to)
Send data.
Definition: udp-test.cc:302
Ptr< Packet > m_receivedPacket
Received packet (1).
Definition: udp-test.cc:181
void DoRun() override
Implementation to actually run this TestCase.
Definition: udp-test.cc:333
void DoSendData(Ptr< Socket > socket)
Send data.
Definition: udp-test.cc:316
Ptr< Ipv4QueueDiscItem > m_sentPacket
Sent packet.
Definition: udp-test.cc:183
void ReceivePkt(Ptr< Socket > socket)
Receive packets (1).
Definition: udp-test.cc:248
void SentPkt(Ptr< const QueueDiscItem > item)
Adds a packet to the list of sent packets.
Definition: udp-test.cc:270
Ptr< Packet > m_receivedPacket2
Received packet (2).
Definition: udp-test.cc:182
void DoSendDataTo(Ptr< Socket > socket, std::string to)
Send data.
Definition: udp-test.cc:295
UDP Socket Loopback over IPv4 Test.
Definition: udp-test.cc:65
Ptr< Packet > m_receivedPacket
Received packet.
Definition: udp-test.cc:75
void ReceivePkt(Ptr< Socket > socket)
Receive a packet.
Definition: udp-test.cc:84
void DoRun() override
Implementation to actually run this TestCase.
Definition: udp-test.cc:95
UDP TestSuite.
Definition: udp-test.cc:776
a polymophic address class
Definition: address.h:92
AttributeValue implementation for Boolean.
Definition: boolean.h:37
An implementation of the ICMPv6 protocol.
An Inet6 address class.
an Inet address class
aggregate IP/TCP/UDP functionality to existing Nodes.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:43
uint8_t GetTos() const
Definition: ipv4-header.cc:196
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:79
a class to store IPv4 address information on an interface
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:258
const Ipv4Header & GetHeader() const
Helper class to auto-assign global IPv6 unicast addresses.
Describes an IPv6 address.
Definition: ipv6-address.h:50
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:82
IPv6 address associated with an interface.
Keep track of a set of IPv6 interfaces.
Describes an IPv6 prefix.
Definition: ipv6-address.h:456
holds a vector of ns3::NetDevice pointers
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
keep track of a set of node pointers.
uint32_t GetId() const
Definition: node.cc:117
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:369
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
void Dispose()
Dispose of this Object.
Definition: object.cc:219
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:863
void RemoveAllByteTags()
Remove all byte tags stored in this packet.
Definition: packet.cc:393
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Definition: packet.cc:1002
Holds a vector of ns3::QueueDisc pointers.
Ptr< QueueDisc > Get(std::size_t i) const
Get the Ptr<QueueDisc> stored in this container at a given index.
Ptr< Packet > GetPacket() const
Definition: queue-item.cc:43
build a set of SimpleNetDevice objects
void SetNetDevicePointToPointMode(bool pointToPointMode)
SimpleNetDevice is Broadcast capable and ARP needing.
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
virtual uint32_t GetRxAvailable() const =0
Return number of bytes which can be returned from one or multiple calls to Recv.
void SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
Notify application when new data is available to be read.
Definition: socket.cc:126
virtual Ptr< Packet > Recv(uint32_t maxSize, uint32_t flags)=0
Read data from the socket.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
virtual Ptr< Node > GetNode() const =0
Return the node this socket is associated with.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
Send data to a specified peer.
indicates whether the socket has a priority set.
Definition: socket.h:1316
uint8_t GetPriority() const
Get the tag's priority.
Definition: socket.cc:858
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
A suite of tests to run.
Definition: test.h:1256
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1265
Build a set of QueueDisc objects.
QueueDiscContainer Install(NetDeviceContainer c)
API to create UDP socket instances.
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition: test.h:144
#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:666
#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:251
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
NodeContainer nodes
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:691
static UdpTestSuite g_udpTestSuite
Static variable for test initialization.
Definition: udp-test.cc:788