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"
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"
49#include "ns3/traffic-control-helper.h"
50#include "ns3/udp-l4-protocol.h"
51#include "ns3/udp-socket-factory.h"
68 void DoRun()
override;
91 "ReceivedPacket size is not equal to the Rx buffer size");
102 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
106 Ptr<Socket> txSocket = rxSocketFactory->CreateSocket();
109 Simulator::Destroy();
112 "first socket should not receive it (it is bound specifically to the "
113 "second interface's address");
126 void DoRun()
override;
148 "ReceivedPacket size is not equal to the Rx buffer size");
159 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
163 Ptr<Socket> txSocket = rxSocketFactory->CreateSocket();
166 Simulator::Destroy();
169 "first socket should not receive it (it is bound specifically to the "
170 "second interface's address");
221 void DoRun()
override;
243 :
TestCase(
"UDP socket implementation")
255 "ReceivedPacket size is not equal to the Rx buffer size");
266 "ReceivedPacket size is not equal to the Rx buffer size");
276 Create<Ipv4QueueDiscItem>(ipv4Item->GetPacket()->Copy(), addr, 0, ipv4Item->GetHeader());
306 Simulator::ScheduleWithContext(socket->
GetNode()->
GetId(),
324 Simulator::ScheduleWithContext(socket->
GetNode()->
GetId(),
364 netdev_idx = ipv4->AddInterface(net1.
Get(0));
366 ipv4->AddAddress(netdev_idx, ipv4Addr);
367 ipv4->SetUp(netdev_idx);
369 netdev_idx = ipv4->AddInterface(net2.
Get(0));
371 ipv4->AddAddress(netdev_idx, ipv4Addr);
372 ipv4->SetUp(netdev_idx);
376 netdev_idx = ipv4->AddInterface(net1.
Get(1));
378 ipv4->AddAddress(netdev_idx, ipv4Addr);
379 ipv4->SetUp(netdev_idx);
381 netdev_idx = ipv4->AddInterface(net2.
Get(1));
383 ipv4->AddAddress(netdev_idx, ipv4Addr);
384 ipv4->SetUp(netdev_idx);
389 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
395 Ptr<Socket> rxSocket2 = rxSocketFactory->CreateSocket();
402 Ptr<Socket> txSocket = txSocketFactory->CreateSocket();
403 txSocket->SetAllowBroadcast(
true);
412 "second interface should not receive it");
422 "first socket should not receive it (it is bound specifically to the "
423 "first interface's address");
426 "second socket should not receive it (it is bound specifically to the "
427 "second interface's address");
438 rxSocket2 = rxSocketFactory->CreateSocket();
447 "first socket should not receive it (it is bound specifically to the "
448 "first interface's address");
456 txSocket->BindToNetDevice(net1.
Get(1));
460 "first socket should not receive it (it is bound specifically to the "
461 "first interface's address");
470 int err = txSocket->GetPeerName(peerAddress);
473 Socket::ERROR_NOTCONN,
474 "socket error code should be ERROR_NOTCONN");
477 err = txSocket->Connect(peer);
480 err = txSocket->GetPeerName(peerAddress);
484 "address from socket GetPeerName() should equal the connected address");
496 txSocket->SetIpTos(0x28);
497 txSocket->SetPriority(6);
522 Simulator::Destroy();
550 void DoRun()
override;
580 :
TestCase(
"UDP6 socket implementation")
603 "ReceivedPacket size is not equal to the Rx buffer size");
613 "ReceivedPacket size is not equal to the Rx buffer size");
628 Simulator::ScheduleWithContext(socket->
GetNode()->
GetId(),
673 device = net1.
Get(0);
674 ifIndex = ipv6->GetInterfaceForDevice(device);
676 ipv6->AddAddress(ifIndex, ipv6Addr);
677 ipv6->SetUp(ifIndex);
679 device = net2.
Get(0);
680 ifIndex = ipv6->GetInterfaceForDevice(device);
682 ipv6->AddAddress(ifIndex, ipv6Addr);
683 ipv6->SetUp(ifIndex);
686 device = net1.
Get(1);
687 ifIndex = ipv6->GetInterfaceForDevice(device);
689 ipv6->AddAddress(ifIndex, ipv6Addr);
690 ipv6->SetUp(ifIndex);
692 device = net2.
Get(1);
693 ifIndex = ipv6->GetInterfaceForDevice(device);
695 ipv6->AddAddress(ifIndex, ipv6Addr);
696 ipv6->SetUp(ifIndex);
700 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
706 Ptr<Socket> rxSocket2 = rxSocketFactory->CreateSocket();
713 Ptr<Socket> txSocket = txSocketFactory->CreateSocket();
714 txSocket->SetAllowBroadcast(
true);
731 rxSocket2 = rxSocketFactory->CreateSocket();
737 txSocket->BindToNetDevice(net1.
Get(1));
741 "first socket should not receive it (it is bound specifically to the "
742 "second interface's address");
750 int err = txSocket->GetPeerName(peerAddress);
753 Socket::ERROR_NOTCONN,
754 "socket error code should be ERROR_NOTCONN");
757 err = txSocket->Connect(peer);
760 err = txSocket->GetPeerName(peerAddress);
764 "address from socket GetPeerName() should equal the connected address");
766 Simulator::Destroy();
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
AttributeValue implementation for Boolean.
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.
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
const Ipv4Header & GetHeader() const
Helper class to auto-assign global IPv6 unicast addresses.
Describes an IPv6 address.
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.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
void Dispose()
Dispose of this Object.
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.
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
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
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.
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.
uint8_t GetPriority() const
Get the tag's priority.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
@ UNIT
This test suite implements a Unit Test.
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.
#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...
static UdpTestSuite g_udpTestSuite
Static variable for test initialization.