14#include "ns3/arp-l3-protocol.h"
15#include "ns3/boolean.h"
16#include "ns3/config.h"
17#include "ns3/error-channel.h"
18#include "ns3/icmpv4-l4-protocol.h"
19#include "ns3/icmpv6-l4-protocol.h"
20#include "ns3/inet-socket-address.h"
21#include "ns3/inet6-socket-address.h"
22#include "ns3/internet-stack-helper.h"
23#include "ns3/ipv4-l3-protocol.h"
24#include "ns3/ipv4-list-routing.h"
25#include "ns3/ipv4-raw-socket-factory.h"
26#include "ns3/ipv4-static-routing.h"
27#include "ns3/ipv6-l3-protocol.h"
28#include "ns3/ipv6-list-routing.h"
29#include "ns3/ipv6-raw-socket-factory.h"
30#include "ns3/ipv6-static-routing.h"
33#include "ns3/simple-net-device.h"
34#include "ns3/simulator.h"
35#include "ns3/socket-factory.h"
36#include "ns3/socket.h"
38#include "ns3/traffic-control-layer.h"
39#include "ns3/udp-l4-protocol.h"
40#include "ns3/udp-socket-factory.h"
41#include "ns3/udp-socket.h"
42#include "ns3/uinteger.h"
45#include "ns3/win32-internet.h"
47#include <netinet/in.h>
98 void Print(std::ostream& os)
const override
100 os <<
"token=" <<
token;
142 void DoRun()
override;
221 :
TestCase(
"Verify the IPv6 layer 3 protocol fragmentation and reassembly")
261 while ((packet = socket->RecvFrom(from)))
291 while ((packet = socket->RecvFrom(from)))
317 m_data =
new uint8_t[dataSize];
321 if (fillSize >= dataSize)
323 memcpy(
m_data, fill, dataSize);
328 while (filled + fillSize < dataSize)
330 memcpy(&
m_data[filled], fill, fillSize);
334 memcpy(&
m_data[filled], fill, dataSize - filled);
353 p->AddPacketTag(tag);
365 ipv6->GetMtu(interface),
366 "Received packet size > MTU: packetSizes: " << packet->GetSize());
374 ipv6->GetMtu(interface),
375 "Transmitted packet size > MTU: packetSizes: " << packet->GetSize());
384 internet.SetIpv4StackInstall(
false);
388 internet.Install(serverNode);
394 serverDev->SetMtu(1500);
395 serverDev->SetReceiveErrorModel(serverDevErrorModel);
396 serverDevErrorModel->Disable();
397 serverNode->AddDevice(serverDev);
399 uint32_t netdev_idx = ipv6->AddInterface(serverDev);
402 ipv6->AddAddress(netdev_idx, ipv6Addr);
403 ipv6->SetUp(netdev_idx);
404 ipv6->TraceConnectWithoutContext(
412 internet.Install(clientNode);
418 clientDev->SetMtu(1500);
419 clientDev->SetReceiveErrorModel(clientDevErrorModel);
420 clientDevErrorModel->Disable();
421 clientNode->AddDevice(clientDev);
423 uint32_t netdev_idx = ipv6->AddInterface(clientDev);
426 ipv6->AddAddress(netdev_idx, ipv6Addr);
427 ipv6->SetUp(netdev_idx);
428 ipv6->TraceConnectWithoutContext(
436 serverDev->SetChannel(channel);
437 clientDev->SetChannel(channel);
438 channel->SetJumpingTime(
Seconds(0.5));
441 uint32_t packetSizes[5] = {1500, 2000, 5000, 10000, 65000};
444 uint8_t fillData[78];
445 for (
uint32_t k = 48; k <= 125; k++)
447 fillData[k - 48] = k;
451 for (
int i = 0; i < 5; i++)
464 uint8_t recvBuffer[65000];
470 "Packet size not correct: recvSize: "
471 << recvSize <<
" packetSizes[" << i <<
"]: " << packetSizes[i]);
476 "Packet content differs");
482 channel->SetJumpingMode(
true);
483 for (
int i = 0; i < 5; i++)
496 uint8_t recvBuffer[65000];
502 "Packet size not correct: recvSize: "
503 << recvSize <<
" packetSizes[" << i <<
"]: " << packetSizes[i]);
508 "Packet content differs");
510 channel->SetJumpingMode(
false);
519 clientDevErrorModel->Disable();
520 serverDevErrorModel->Enable();
521 for (
int i = 1; i < 5; i++)
528 serverDevErrorModel->Reset();
545 "Client did not receive ICMPv6::TIME_EXCEEDED " <<
int(
m_icmpType)
551 clientDevErrorModel->Disable();
552 serverDevErrorModel->Disable();
553 for (
int i = 0; i < 5; i++)
582 "ByteTag name not correct");
Tag used in IPv6 Fragmentation Test.
void Serialize(TagBuffer buffer) const override
static TypeId GetTypeId()
Get the type ID.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
uint64_t GetToken() const
Get the token.
uint64_t token
Token carried by the tag.
void Print(std::ostream &os) const override
void Deserialize(TagBuffer buffer) override
uint32_t GetSerializedSize() const override
void SetToken(uint64_t token)
Set the token.
void HandleReadServer(Ptr< Socket > socket)
Handle incoming packets.
Ptr< Socket > m_socketClient
Client socket.
uint32_t m_dataSize
Data size.
void SetFill(uint8_t *fill, uint32_t fillSize, uint32_t dataSize)
Set the packet fill.
uint8_t m_icmpCode
ICMP code.
void HandleReadIcmpClient(Ipv6Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo)
Handle incoming ICMP packets.
Ptr< Socket > m_socketServer
Server socket.
void DoRun() override
Implementation to actually run this TestCase.
void StartServer(Ptr< Node > ServerNode)
Start the server.
~Ipv6FragmentationTest() override
Ptr< Packet > m_receivedPacketServer
Packet received by server.
Ptr< Packet > m_sentPacketClient
Packet sent by client.
void HandleReadClient(Ptr< Socket > socket)
Handle incoming packets.
Ptr< Packet > SendClient()
Send a packet.
void HandleServerRx(Ptr< const Packet > packet, Ptr< Ipv6 > ipv6, uint32_t interface)
Handle Server's incoming packets.
void HandleClientTx(Ptr< const Packet > packet, Ptr< Ipv6 > ipv6, uint32_t interface)
Handle Client's transmitting packets.
uint8_t m_icmpType
ICMP type.
uint32_t m_size
packet size.
Ptr< Packet > m_receivedPacketClient
Packet received by client.
void StartClient(Ptr< Node > ClientNode)
Start the client.
IPv6 Fragmentation TestSuite.
Ipv6FragmentationTestSuite()
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.
static bool IsMatchingType(const Address &addr)
If the address match.
aggregate IP/TCP/UDP functionality to existing Nodes.
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.
Describes an IPv6 prefix.
static Mac48Address ConvertFrom(const Address &address)
static Mac48Address Allocate()
Allocate a new Mac48Address.
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.
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 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.
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.
static constexpr auto UNIT
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.
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_LT_OR_EQ(actual, limit, msg)
Test that an actual value is less than or equal to a limit and report 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.
static Ipv6FragmentationTestSuite g_ipv6fragmentationTestSuite
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.