12#include "ns3/arp-l3-protocol.h"
13#include "ns3/boolean.h"
14#include "ns3/config.h"
15#include "ns3/error-channel.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-l3-protocol.h"
20#include "ns3/ipv4-list-routing.h"
21#include "ns3/ipv4-raw-socket-factory.h"
22#include "ns3/ipv4-static-routing.h"
25#include "ns3/simple-net-device-helper.h"
26#include "ns3/simple-net-device.h"
27#include "ns3/simulator.h"
28#include "ns3/socket-factory.h"
29#include "ns3/socket.h"
31#include "ns3/udp-l4-protocol.h"
32#include "ns3/udp-socket-factory.h"
33#include "ns3/udp-socket.h"
34#include "ns3/uinteger.h"
37#include "ns3/win32-internet.h"
39#include <netinet/in.h>
90 void Print(std::ostream& os)
const override
92 os <<
"token=" <<
token;
134 void DoRun()
override;
197 :
TestCase(
std::string(
"Verify the IPv4 layer 3 protocol fragmentation and reassembly: ") +
198 (broadcast ?
"broadcast" :
"unicast"))
231 udpSocket->MulticastJoinGroup(0,
Ipv4Address(
"10.0.0.1"));
243 while ((packet = socket->RecvFrom(from)))
274 while ((packet = socket->RecvFrom(from)))
299 m_data =
new uint8_t[dataSize];
303 if (fillSize >= dataSize)
305 memcpy(
m_data, fill, dataSize);
310 while (filled + fillSize < dataSize)
312 memcpy(&
m_data[filled], fill, fillSize);
316 memcpy(&
m_data[filled], fill, dataSize - filled);
335 p->AddPacketTag(tag);
371 channel->SetJumpingTime(
Seconds(0.5));
378 internet.Install(
nodes);
385 ipv4 = serverNode->GetObject<
Ipv4>();
386 netdev_idx = ipv4->AddInterface(net.
Get(0));
388 ipv4->AddAddress(netdev_idx, ipv4Addr);
389 ipv4->SetUp(netdev_idx);
392 serverDevErrorModel->Disable();
393 serverDev->SetMtu(1500);
394 serverDev->SetReceiveErrorModel(serverDevErrorModel);
398 ipv4 = clientNode->GetObject<
Ipv4>();
399 netdev_idx = ipv4->AddInterface(net.
Get(1));
401 ipv4->AddAddress(netdev_idx, ipv4Addr);
402 ipv4->SetUp(netdev_idx);
405 clientDevErrorModel->Disable();
406 clientDev->SetMtu(1500);
407 clientDev->SetReceiveErrorModel(clientDevErrorModel);
411 uint32_t packetSizes[5] = {1000, 2000, 5000, 10000, 65000};
414 uint8_t fillData[78];
415 for (
uint32_t k = 48; k <= 125; k++)
417 fillData[k - 48] = k;
421 for (
int i = 0; i < 5; i++)
434 uint8_t recvBuffer[65000];
443 "Packet content differs");
449 channel->SetJumpingMode(
true);
450 for (
int i = 0; i < 5; i++)
463 uint8_t recvBuffer[65000];
472 "Packet content differs");
474 channel->SetJumpingMode(
false);
483 clientDevErrorModel->Disable();
484 serverDevErrorModel->Enable();
485 for (
int i = 1; i < 5; i++)
492 serverDevErrorModel->Reset();
507 "Client did not receive ICMP::TIME_EXCEEDED");
512 clientDevErrorModel->Disable();
513 serverDevErrorModel->Disable();
514 for (
int i = 0; i < 5; i++)
543 "ByteTag name not correct");
Tag used in IPv4 Fragmentation Test.
static TypeId GetTypeId()
Get the type ID.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
uint32_t GetSerializedSize() const override
void SetToken(uint64_t token)
Set the token.
void Deserialize(TagBuffer buffer) override
uint64_t token
Token carried by the tag.
void Serialize(TagBuffer buffer) const override
uint64_t GetToken() const
Get the token.
void Print(std::ostream &os) const override
Ptr< Packet > m_receivedPacketClient
Packet received by client.
Ptr< Packet > m_receivedPacketServer
Packet received by server.
Ptr< Packet > m_sentPacketClient
Packet sent by client.
uint8_t m_icmpType
ICMP type.
uint32_t m_size
packet size.
Ptr< Packet > SendClient()
Send a packet.
Ptr< Socket > m_socketServer
Server socket.
void StartClient(Ptr< Node > ClientNode)
Start the client.
Ptr< Socket > m_socketClient
Client socket.
void StartServer(Ptr< Node > ServerNode)
Start the server.
void HandleReadIcmpClient(Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo)
Handle incoming ICMP packets.
~Ipv4FragmentationTest() override
uint32_t m_dataSize
Data size.
void HandleReadClient(Ptr< Socket > socket)
Handle incoming packets.
Ipv4FragmentationTest(bool broadcast)
Constructor.
void DoRun() override
Implementation to actually run this TestCase.
void HandleReadServer(Ptr< Socket > socket)
Handle incoming packets.
void SetFill(uint8_t *fill, uint32_t fillSize, uint32_t dataSize)
Set the packet fill.
bool m_broadcast
broadcast packets
IPv4 Fragmentation TestSuite.
Ipv4FragmentationTestSuite()
a polymophic address class
Identifies a byte tag and a set of bytes within a packet to which the tag applies.
uint32_t GetEnd() const
The index is an offset from the start of the packet.
void GetTag(Tag &tag) const
Read the requested tag and store it in the user-provided tag instance.
uint32_t GetStart() const
The index is an offset from the start of the packet.
Iterator over the set of byte tags in a packet.
void SetIpv4(Ipv4Address address)
static bool IsMatchingType(const Address &address)
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
aggregate IP/TCP/UDP functionality to existing Nodes.
Ipv4 addresses are stored in host order in this class.
static Ipv4Address GetBroadcast()
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
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.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
ByteTagIterator GetByteTagIterator() const
Returns an iterator over the set of byte tags included in this packet.
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 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.
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
virtual bool SetAllowBroadcast(bool allowBroadcast)=0
Configure whether broadcast datagram transmissions are allowed.
virtual int GetPeerName(Address &address) const =0
Get the peer address of a connected socket.
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
void SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
Notify application when new data is available to be read.
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...
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.
void WriteU64(uint64_t v)
tag a set of bytes in a packet
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
a unique identifier for an interface.
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Callback< ObjectBase * > GetConstructor() const
Get the constructor callback.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
std::string GetName() const
Get the name.
A sockets interface to UDP.
Hold an unsigned integer type.
void SetDefault(std::string name, const AttributeValue &value)
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_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.
static Ipv4FragmentationTestSuite g_ipv4fragmentationTestSuite
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...
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
static const uint32_t packetSize
Packet size generated at the AP.