25 #include "ns3/config.h"
26 #include "ns3/uinteger.h"
27 #include "ns3/socket-factory.h"
28 #include "ns3/ipv4-raw-socket-factory.h"
29 #include "ns3/udp-socket-factory.h"
30 #include "ns3/simulator.h"
32 #include "ns3/simple-net-device.h"
33 #include "ns3/simple-net-device-helper.h"
34 #include "ns3/drop-tail-queue.h"
35 #include "ns3/socket.h"
36 #include "ns3/udp-socket.h"
40 #include "ns3/inet-socket-address.h"
41 #include "ns3/boolean.h"
43 #include "ns3/arp-l3-protocol.h"
44 #include "ns3/ipv4-l3-protocol.h"
45 #include "ns3/icmpv4-l4-protocol.h"
46 #include "ns3/ipv4-list-routing.h"
47 #include "ns3/ipv4-static-routing.h"
48 #include "ns3/udp-l4-protocol.h"
49 #include "ns3/internet-stack-helper.h"
53 #include <netinet/in.h>
74 virtual void Print (std::ostream &os)
const { os <<
"token=" << token; }
75 void setToken (uint64_t token) { this->token = token; }
94 virtual void DoRun (
void);
105 void HandleReadIcmpClient (
Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType,
106 uint8_t icmpCode,uint32_t icmpInfo);
108 void SetFill (uint8_t *fill, uint32_t fillSize, uint32_t dataSize);
115 :
TestCase (
"Verify the IPv4 layer 3 protocol fragmentation and reassembly")
139 TypeId tid = TypeId::LookupByName (
"ns3::UdpSocketFactory");
159 while ((packet = socket->
RecvFrom (from)))
161 if (InetSocketAddress::IsMatchingType (from))
174 TypeId tid = TypeId::LookupByName (
"ns3::UdpSocketFactory");
190 while ((packet = socket->
RecvFrom (from)))
192 if (InetSocketAddress::IsMatchingType (from))
201 uint8_t icmpTtl, uint8_t icmpType,
202 uint8_t icmpCode, uint32_t icmpInfo)
213 m_data =
new uint8_t [dataSize];
217 if (fillSize >= dataSize)
219 memcpy (
m_data, fill, dataSize);
224 while (filled + fillSize < dataSize)
226 memcpy (&
m_data[filled], fill, fillSize);
230 memcpy(&
m_data[filled], fill, dataSize - filled);
244 p = Create<Packet> (
m_size);
266 Ptr<Node> serverNode = CreateObject<Node> ();
268 Ptr<Node> clientNode = CreateObject<Node> ();
291 ipv4->
SetUp (netdev_idx);
294 serverDevErrorModel->
Disable ();
295 serverDev->SetMtu(1500);
296 serverDev->SetReceiveErrorModel (serverDevErrorModel);
304 ipv4->
SetUp (netdev_idx);
307 clientDevErrorModel->
Disable ();
308 clientDev->SetMtu(1500);
309 clientDev->SetReceiveErrorModel (clientDevErrorModel);
313 uint32_t packetSizes[5] = {1000, 2000, 5000, 10000, 65000};
316 uint8_t fillData[78];
317 for ( uint32_t k=48; k<=125; k++ )
323 for(
int i= 0; i<5; i++)
327 SetFill (fillData, 78, packetSize);
334 uint8_t recvBuffer[65000];
342 0,
"Packet content differs");
349 for(
int i= 0; i<5; i++)
353 SetFill (fillData, 78, packetSize);
360 uint8_t recvBuffer[65000];
368 0,
"Packet content differs");
379 clientDevErrorModel->
Disable();
380 serverDevErrorModel->
Enable();
381 for(
int i= 1; i<5; i++)
385 SetFill (fillData, 78, packetSize);
388 serverDevErrorModel->
Reset();
404 clientDevErrorModel->
Disable ();
405 serverDevErrorModel->
Disable ();
406 for (
int i= 0; i<5; i++)
410 SetFill (fillData, 78, packetSize);
426 uint32_t tagStart = 0;
428 while (iter.HasNext ())
453 Simulator::Destroy ();
virtual uint32_t GetSerializedSize() const
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
void StartClient(Ptr< Node > ClientNode)
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
void WriteU64(uint64_t v)
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
a class to represent an Ipv4 address mask
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Ptr< Packet > m_sentPacketClient
aggregate IP/TCP/UDP functionality to existing Nodes.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
static TypeId GetTypeId()
This test suite implements a Unit Test.
Ptr< Socket > m_socketServer
A sockets interface to UDP.
void setToken(uint64_t token)
a polymophic address class
Callback< ObjectBase * > GetConstructor(void) const
AttributeValue implementation for Callback.
Ptr< Socket > m_socketClient
Ptr< Packet > SendClient(void)
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Identifies a byte tag and a set of bytes within a packet to which the tag applies.
virtual int MulticastJoinGroup(uint32_t interface, const Address &groupAddress)=0
Corresponds to socket option MCAST_JOIN_GROUP.
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
virtual void Deserialize(TagBuffer buffer)
virtual void SetUp(uint32_t interface)=0
Hold an unsigned integer type.
holds a vector of ns3::NetDevice pointers
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
ByteTagIterator GetByteTagIterator(void) const
Retiurns an iterator over the set of byte tags included in this packet.
void SetRecvCallback(Callback< void, Ptr< Socket > >)
Notify application when new data is available to be read.
uint32_t GetEnd(void) const
The index is an offset from the start of the packet.
void Disable(void)
Disable the error model.
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
void SetJumpingMode(bool mode)
Set if the odd packets are delayed (even ones are not delayed ever)
Access to the Ipv4 forwarding table, interfaces, and configuration.
virtual void Serialize(TagBuffer buffer) const
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
tag a set of bytes in a packet
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
void SetNetDevicePointToPointMode(bool pointToPointMode)
SimpleNetDevice is Broadcast capable and ARP needing.
Iterator over the set of byte tags in a packet.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
#define NS_TEST_EXPECT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report if not.
std::string GetName(void) const
virtual void Print(std::ostream &os) const
TypeId GetTypeId(void) const
void HandleReadIcmpClient(Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo)
virtual TypeId GetInstanceTypeId() const
Get the most derived TypeId for this Object.
void GetTag(Tag &tag) const
Read the requested tag and store it in the user-provided tag instance.
void StartServer(Ptr< Node > ServerNode)
Ipv4 addresses are stored in host order in this class.
Ipv4FragmentationTestSuite g_ipv4fragmentationTestSuite
uint32_t GetStart(void) const
The index is an offset from the start of the packet.
uint32_t GetId(void) const
a class to store IPv4 address information on an interface
virtual Ptr< Node > GetNode(void) const =0
Return the node this socket is associated with.
Time Seconds(double value)
Construct a Time in the indicated unit.
void SetDefault(std::string name, const AttributeValue &value)
Ptr< Packet > m_receivedPacketServer
virtual bool AddAddress(uint32_t interface, Ipv4InterfaceAddress address)=0
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Ptr< Packet > m_receivedPacketClient
virtual void DoRun(void)
Implementation to actually run this TestCase.
void SetJumpingTime(Time delay)
Set the delay for the odd packets (even ones are not delayed)
static const uint32_t packetSize
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)=0
Read a single packet from the socket and retrieve the sender address.
build a set of SimpleNetDevice objects
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
Ipv4FragmentationTestSuite()
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
void Enable(void)
Enable the error model.
void SetFill(uint8_t *fill, uint32_t fillSize, uint32_t dataSize)
void HandleReadClient(Ptr< Socket > socket)
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.
void HandleReadServer(Ptr< Socket > socket)