13#include "ns3/arp-l3-protocol.h"
14#include "ns3/boolean.h"
15#include "ns3/icmpv4-l4-protocol.h"
16#include "ns3/icmpv6-l4-protocol.h"
17#include "ns3/inet-socket-address.h"
18#include "ns3/inet6-socket-address.h"
19#include "ns3/internet-stack-helper.h"
20#include "ns3/ipv4-l3-protocol.h"
21#include "ns3/ipv4-list-routing.h"
22#include "ns3/ipv4-queue-disc-item.h"
23#include "ns3/ipv4-static-routing.h"
24#include "ns3/ipv6-address-helper.h"
25#include "ns3/ipv6-l3-protocol.h"
26#include "ns3/ipv6-list-routing.h"
27#include "ns3/ipv6-static-routing.h"
30#include "ns3/simple-channel.h"
31#include "ns3/simple-net-device-helper.h"
32#include "ns3/simple-net-device.h"
33#include "ns3/simulator.h"
34#include "ns3/socket-factory.h"
35#include "ns3/socket.h"
36#include "ns3/tcp-l4-protocol.h"
38#include "ns3/traffic-control-helper.h"
39#include "ns3/udp-l4-protocol.h"
40#include "ns3/udp-socket-factory.h"
56 void DoRun()
override;
75 availableData = socket->GetRxAvailable();
79 "ReceivedPacket size is not equal to the Rx buffer size");
87 internet.Install(rxNode);
90 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
94 Ptr<Socket> txSocket = rxSocketFactory->CreateSocket();
100 "first socket should not receive it (it is bound specifically to the "
101 "second interface's address");
113 void DoRun()
override;
131 uint32_t availableData [[maybe_unused]] = socket->GetRxAvailable();
135 "ReceivedPacket size is not equal to the Rx buffer size");
143 internet.Install(rxNode);
146 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
150 Ptr<Socket> txSocket = rxSocketFactory->CreateSocket();
156 "first socket should not receive it (it is bound specifically to the "
157 "second interface's address");
207 void DoRun()
override;
229 :
TestCase(
"UDP socket implementation")
237 availableData = socket->GetRxAvailable();
241 "ReceivedPacket size is not equal to the Rx buffer size");
248 availableData = socket->GetRxAvailable();
252 "ReceivedPacket size is not equal to the Rx buffer size");
275 bool found =
m_sentPacket->GetPacket()->PeekPacketTag(priorityTag);
339 internet.Install(
nodes);
349 ipv4 = rxNode->GetObject<
Ipv4>();
350 netdev_idx = ipv4->AddInterface(net1.
Get(0));
352 ipv4->AddAddress(netdev_idx, ipv4Addr);
353 ipv4->SetUp(netdev_idx);
355 netdev_idx = ipv4->AddInterface(net2.
Get(0));
357 ipv4->AddAddress(netdev_idx, ipv4Addr);
358 ipv4->SetUp(netdev_idx);
361 ipv4 = txNode->GetObject<
Ipv4>();
362 netdev_idx = ipv4->AddInterface(net1.
Get(1));
364 ipv4->AddAddress(netdev_idx, ipv4Addr);
365 ipv4->SetUp(netdev_idx);
367 netdev_idx = ipv4->AddInterface(net2.
Get(1));
369 ipv4->AddAddress(netdev_idx, ipv4Addr);
370 ipv4->SetUp(netdev_idx);
375 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
381 Ptr<Socket> rxSocket2 = rxSocketFactory->CreateSocket();
388 Ptr<Socket> txSocket = txSocketFactory->CreateSocket();
389 txSocket->SetAllowBroadcast(
true);
398 "second interface should not receive it");
408 "first socket should not receive it (it is bound specifically to the "
409 "first interface's address");
412 "second socket should not receive it (it is bound specifically to the "
413 "second interface's address");
423 rxSocket2->Dispose();
424 rxSocket2 = rxSocketFactory->CreateSocket();
433 "first socket should not receive it (it is bound specifically to the "
434 "first interface's address");
442 txSocket->BindToNetDevice(net1.
Get(1));
446 "first socket should not receive it (it is bound specifically to the "
447 "first interface's address");
456 int err = txSocket->GetPeerName(peerAddress);
460 "socket error code should be ERROR_NOTCONN");
463 err = txSocket->Connect(peer);
466 err = txSocket->GetPeerName(peerAddress);
470 "address from socket GetPeerName() should equal the connected address");
482 txSocket->SetPriority(6);
494 txSocket->SetIpTos(0xb8);
533 void DoRun()
override;
563 :
TestCase(
"UDP6 socket implementation")
582 uint32_t availableData [[maybe_unused]] = socket->GetRxAvailable();
586 "ReceivedPacket size is not equal to the Rx buffer size");
592 uint32_t availableData [[maybe_unused]] = socket->GetRxAvailable();
596 "ReceivedPacket size is not equal to the Rx buffer size");
655 ipv6 = rxNode->GetObject<
Ipv6>();
656 device = net1.
Get(0);
657 ifIndex = ipv6->GetInterfaceForDevice(device);
659 ipv6->AddAddress(ifIndex, ipv6Addr);
660 ipv6->SetUp(ifIndex);
662 device = net2.
Get(0);
663 ifIndex = ipv6->GetInterfaceForDevice(device);
665 ipv6->AddAddress(ifIndex, ipv6Addr);
666 ipv6->SetUp(ifIndex);
668 ipv6 = txNode->GetObject<
Ipv6>();
669 device = net1.
Get(1);
670 ifIndex = ipv6->GetInterfaceForDevice(device);
672 ipv6->AddAddress(ifIndex, ipv6Addr);
673 ipv6->SetUp(ifIndex);
675 device = net2.
Get(1);
676 ifIndex = ipv6->GetInterfaceForDevice(device);
678 ipv6->AddAddress(ifIndex, ipv6Addr);
679 ipv6->SetUp(ifIndex);
683 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
689 Ptr<Socket> rxSocket2 = rxSocketFactory->CreateSocket();
696 Ptr<Socket> txSocket = txSocketFactory->CreateSocket();
697 txSocket->SetAllowBroadcast(
true);
713 rxSocket2->Dispose();
714 rxSocket2 = rxSocketFactory->CreateSocket();
720 txSocket->BindToNetDevice(net1.
Get(1));
724 "first socket should not receive it (it is bound specifically to the "
725 "second interface's address");
733 int err = txSocket->GetPeerName(peerAddress);
737 "socket error code should be ERROR_NOTCONN");
740 err = txSocket->Connect(peer);
743 err = txSocket->GetPeerName(peerAddress);
747 "address from socket GetPeerName() should equal the connected address");
UDP Socket over IPv6 Test.
Ptr< Packet > m_receivedPacket
Received packet (1).
void ReceivePacket(Ptr< Socket > socket, Ptr< Packet > packet, const Address &from)
Receive packets (1).
void SendDataTo(Ptr< Socket > socket, std::string to)
Send data.
void ReceivePkt2(Ptr< Socket > socket)
Receive packets (2).
void DoRun() override
Implementation to actually run this TestCase.
Ptr< Packet > m_receivedPacket2
Received packet (2).
void ReceivePkt(Ptr< Socket > socket)
Receive packets (1).
void ReceivePacket2(Ptr< Socket > socket, Ptr< Packet > packet, const Address &from)
Receive packets (2).
void DoSendDataTo(Ptr< Socket > socket, std::string to)
Send data.
UDP Socket Loopback over IPv6 Test.
void ReceivePkt(Ptr< Socket > socket)
Receive a packet.
Ptr< Packet > m_receivedPacket
Received packet.
void DoRun() override
Implementation to actually run this TestCase.
UDP Socket over IPv4 Test.
uint32_t GetTos()
Get the TOS of the received packet.
uint32_t GetPriority()
Get the priority of the received packet.
void SendData(Ptr< Socket > socket)
Send data.
void ReceivePkt2(Ptr< Socket > socket)
Receive packets (2).
void SendDataTo(Ptr< Socket > socket, std::string to)
Send data.
Ptr< Packet > m_receivedPacket
Received packet (1).
void DoRun() override
Implementation to actually run this TestCase.
void DoSendData(Ptr< Socket > socket)
Send data.
Ptr< Ipv4QueueDiscItem > m_sentPacket
Sent packet.
void ReceivePkt(Ptr< Socket > socket)
Receive packets (1).
void SentPkt(Ptr< const QueueDiscItem > item)
Adds a packet to the list of sent packets.
Ptr< Packet > m_receivedPacket2
Received packet (2).
void DoSendDataTo(Ptr< Socket > socket, std::string to)
Send data.
UDP Socket Loopback over IPv4 Test.
Ptr< Packet > m_receivedPacket
Received packet.
void ReceivePkt(Ptr< Socket > socket)
Receive a packet.
void DoRun() override
Implementation to actually run this TestCase.
a polymophic address class
An implementation of the ICMPv6 protocol.
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.
static Ipv4Address GetAny()
Access to the IPv4 forwarding table, interfaces, and configuration.
a class to store IPv4 address information on an interface
a class to represent an Ipv4 address mask
Helper class to auto-assign global IPv6 unicast addresses.
Describes an IPv6 address.
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
Access to the IPv6 forwarding table, interfaces, and configuration.
IPv6 address associated with an interface.
Keep track of a set of IPv6 interfaces.
Describes an IPv6 prefix.
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.
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
void RemoveAllByteTags()
Remove all byte tags stored in this packet.
Smart pointer class similar to boost::intrusive_ptr.
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.
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...
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static void ScheduleWithContext(uint32_t context, const Time &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
static void Run()
Run the simulation.
indicates whether the socket has a priority set.
uint8_t GetPriority() const
Get the tag's priority.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
static constexpr auto UNIT
Build a set of QueueDisc objects.
QueueDiscContainer Install(NetDeviceContainer c)
static TrafficControlHelper Default(std::size_t nTxQueues=1)
API to create UDP socket instances.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
#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.
#define NS_TEST_EXPECT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report if not.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Time Seconds(double value)
Construct a Time in the indicated unit.
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...
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
static UdpTestSuite g_udpTestSuite
Static variable for test initialization.