12#include "ns3/arp-l3-protocol.h"
13#include "ns3/boolean.h"
14#include "ns3/core-module.h"
15#include "ns3/error-model.h"
16#include "ns3/icmpv4-l4-protocol.h"
17#include "ns3/inet-socket-address.h"
18#include "ns3/internet-stack-helper.h"
19#include "ns3/ipv4-address-helper.h"
20#include "ns3/ipv4-global-routing-helper.h"
21#include "ns3/ipv4-l3-protocol.h"
22#include "ns3/ipv4-list-routing.h"
23#include "ns3/ipv4-raw-socket-factory.h"
24#include "ns3/ipv4-static-routing.h"
27#include "ns3/simple-channel.h"
28#include "ns3/simple-net-device-helper.h"
29#include "ns3/simple-net-device.h"
30#include "ns3/simulator.h"
31#include "ns3/socket-factory.h"
32#include "ns3/socket.h"
35#include "ns3/win32-internet.h"
37#include <netinet/in.h>
38#include <sys/socket.h>
73 void DoRun()
override;
101 :
TestCase(
"IPv4 raw fragmentation, fragment‑loss test")
110 if (p->PeekHeader(h))
130 socket->SendTo(p, 0, realTo);
131 NS_LOG_DEBUG(
"Sender sent " << p->GetSize() <<
" bytes to 10.0.1.1");
146 net.
Get(1)->SetMtu(1000);
149 internet.Install(
nodes);
155 ipv4 = rxNode->GetObject<
Ipv4>();
156 netdev_idx = ipv4->AddInterface(net.
Get(0));
158 ipv4->AddAddress(netdev_idx, ipv4Addr);
159 ipv4->SetUp(netdev_idx);
161 ipv4 = txNode->GetObject<
Ipv4>();
162 netdev_idx = ipv4->AddInterface(net.
Get(1));
164 ipv4->AddAddress(netdev_idx, ipv4Addr);
165 ipv4->SetUp(netdev_idx);
167 net.
Get(0)->TraceConnectWithoutContext(
172 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
177 Ptr<Socket> txSocket = txSocketFactory->CreateSocket();
180 std::vector<uint32_t> payloadSizes = {500, 1000, 5000, 10000, 20000, 40000, 60000};
182 for (
auto sentPayloadSize : payloadSizes)
197 "Reassembled payload size must match the payload size sent");
201 std::vector<uint32_t> fragmentablePayloadSizes = {5000, 10000, 20000, 40000, 60000};
203 for (
auto sentPayloadSize : fragmentablePayloadSizes)
208 errModel->SetList({1});
262 void DoRun()
override;
292 :
TestCase(
"IPv4 Raw socket implementation")
312 availableData = socket->GetRxAvailable();
318 "Received packet size is not equal to Rx buffer size");
325 availableData = socket->GetRxAvailable();
331 "Received packet size is not equal to Rx buffer size");
359 socket->SetAttribute(
"IpHeaderInclude",
BooleanValue(
true));
367 p->AddHeader(ipHeader);
370 socket->SetAttribute(
"IpHeaderInclude",
BooleanValue(
false));
408 internet.Install(
nodes);
415 ipv4 = rxNode->GetObject<
Ipv4>();
416 netdev_idx = ipv4->AddInterface(net1.
Get(0));
418 ipv4->AddAddress(netdev_idx, ipv4Addr);
419 ipv4->SetUp(netdev_idx);
421 netdev_idx = ipv4->AddInterface(net2.
Get(0));
423 ipv4->AddAddress(netdev_idx, ipv4Addr);
424 ipv4->SetUp(netdev_idx);
427 ipv4 = txNode->GetObject<
Ipv4>();
428 netdev_idx = ipv4->AddInterface(net1.
Get(1));
430 ipv4->AddAddress(netdev_idx, ipv4Addr);
431 ipv4->SetUp(netdev_idx);
433 netdev_idx = ipv4->AddInterface(net2.
Get(1));
435 ipv4->AddAddress(netdev_idx, ipv4Addr);
436 ipv4->SetUp(netdev_idx);
440 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
446 Ptr<Socket> rxSocket2 = rxSocketFactory->CreateSocket();
453 Ptr<Socket> txSocket = txSocketFactory->CreateSocket();
462 "second interface should not receive it");
472 "second interface should not receive it");
480 SendData (txSocket,
"255.255.255.255");
495 "second socket should not receive it (it is bound specifically to the "
496 "second interface's address");
507 rxSocket2->Dispose ();
508 rxSocket2 = rxSocketFactory->CreateSocket ();
512 SendData (txSocket,
"255.255.255.255");
523 int err = txSocket->GetPeerName(peerAddress);
527 "socket error code should be ERROR_NOTCONN");
530 err = txSocket->Connect(peer);
533 err = txSocket->GetPeerName(peerAddress);
538 "address from socket GetPeerName() should equal the connected address");
IPv4 Raw Socket Fragmentation Test Configuration : Two sockets.
uint32_t m_droppedFragments
Number of dropped fragments.
void DoRun() override
Implementation to actually run this TestCase.
void RxCallback(Ptr< Socket > s)
Receive callback.
uint32_t m_rxCount
Received packet count.
uint32_t m_rxPayloadSize
Received packet size.
Ipv4RawFragmentationTest()
void SendPacket(Ptr< Socket > s, uint32_t sz)
Send data to the receiver.
void PhyRxDropCallback(Ptr< const Packet > p)
Packet dropped callback at Phy Rx.
void SendData_IpHdr(Ptr< Socket > socket, std::string to)
Send data.
void ReceivePkt(Ptr< Socket > socket)
Receive data.
Ptr< Packet > m_receivedPacket
Received packet (1).
void DoRun() override
Implementation to actually run this TestCase.
Ptr< Packet > m_receivedPacket2
Received packet (2).
void SendData(Ptr< Socket > socket, std::string to)
Send data.
void DoSendData(Ptr< Socket > socket, std::string to)
Send data.
void DoSendData_IpHdr(Ptr< Socket > socket, std::string to)
Send data.
void ReceivePacket2(Ptr< Socket > socket, Ptr< Packet > packet, const Address &from)
Receive data.
void ReceivePkt2(Ptr< Socket > socket)
Receive data.
void ReceivePacket(Ptr< Socket > socket, Ptr< Packet > packet, const Address &from)
Receive data.
IPv4 RAW Socket TestSuite.
a polymophic address class
AttributeValue implementation for Boolean.
void SetPort(uint16_t port)
aggregate IP/TCP/UDP functionality to existing Nodes.
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
API to create RAW socket instances.
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.
AttributeValue implementation for Pointer.
Smart pointer class similar to boost::intrusive_ptr.
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 EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
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.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
TestCase(const TestCase &)=delete
@ UNIT
This test suite implements a Unit Test.
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
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_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.
static Ipv4RawTestSuite g_ipv4rawTestSuite
Static variable for test initialization.
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...