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" 31 #include "ns3/simple-net-device.h" 32 #include "ns3/simple-net-device-helper.h" 33 #include "ns3/socket.h" 34 #include "ns3/udp-socket.h" 38 #include "ns3/inet-socket-address.h" 39 #include "ns3/boolean.h" 41 #include "ns3/arp-l3-protocol.h" 42 #include "ns3/ipv4-l3-protocol.h" 43 #include "ns3/icmpv4-l4-protocol.h" 44 #include "ns3/ipv4-list-routing.h" 45 #include "ns3/ipv4-static-routing.h" 46 #include "ns3/udp-l4-protocol.h" 47 #include "ns3/internet-stack-helper.h" 48 #include "ns3/error-channel.h" 52 #include <netinet/in.h> 80 virtual void Print (std::ostream &os)
const { os <<
"token=" << token; }
85 void SetToken (uint64_t token) { this->token = token; }
115 virtual void DoRun (
void);
152 void HandleReadIcmpClient (
Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType,
153 uint8_t icmpCode, uint32_t icmpInfo);
161 void SetFill (uint8_t *fill, uint32_t fillSize, uint32_t dataSize);
172 :
TestCase (
std::string (
"Verify the IPv4 layer 3 protocol fragmentation and reassembly: ") +
173 (broadcast?
"broadcast":
"unicast"))
200 TypeId tid = TypeId::LookupByName (
"ns3::UdpSocketFactory");
220 while ((packet = socket->
RecvFrom (from)))
222 if (InetSocketAddress::IsMatchingType (from))
235 TypeId tid = TypeId::LookupByName (
"ns3::UdpSocketFactory");
252 while ((packet = socket->
RecvFrom (from)))
254 if (InetSocketAddress::IsMatchingType (from))
263 uint8_t icmpTtl, uint8_t icmpType,
264 uint8_t icmpCode, uint32_t icmpInfo)
275 m_data =
new uint8_t [dataSize];
279 if (fillSize >= dataSize)
281 memcpy (
m_data, fill, dataSize);
286 while (filled + fillSize < dataSize)
288 memcpy (&
m_data[filled], fill, fillSize);
292 memcpy(&
m_data[filled], fill, dataSize - filled);
306 p = Create<Packet> (
m_size);
318 saddress.
SetIpv4 (Ipv4Address::GetBroadcast ());
339 Ptr<Node> serverNode = CreateObject<Node> ();
341 Ptr<Node> clientNode = CreateObject<Node> ();
364 ipv4->
SetUp (netdev_idx);
367 serverDevErrorModel->
Disable ();
368 serverDev->SetMtu(1500);
369 serverDev->SetReceiveErrorModel (serverDevErrorModel);
377 ipv4->
SetUp (netdev_idx);
380 clientDevErrorModel->
Disable ();
381 clientDev->SetMtu(1500);
382 clientDev->SetReceiveErrorModel (clientDevErrorModel);
386 uint32_t packetSizes[5] = {1000, 2000, 5000, 10000, 65000};
389 uint8_t fillData[78];
390 for ( uint32_t k=48; k<=125; k++ )
396 for(
int i= 0; i<5; i++)
407 uint8_t recvBuffer[65000];
415 0,
"Packet content differs");
422 for(
int i= 0; i<5; i++)
433 uint8_t recvBuffer[65000];
441 0,
"Packet content differs");
443 channel->SetJumpingMode(
false);
452 clientDevErrorModel->
Disable();
453 serverDevErrorModel->
Enable();
454 for(
int i= 1; i<5; i++)
461 serverDevErrorModel->
Reset();
477 clientDevErrorModel->
Disable ();
478 serverDevErrorModel->
Disable ();
479 for (
int i= 0; i<5; i++)
499 uint32_t tagStart = 0;
501 while (iter.HasNext ())
526 Simulator::Destroy ();
Callback< ObjectBase * > GetConstructor(void) const
Get the constructor callback.
TypeId GetTypeId(void) const
std::string GetName(void) const
Get the name.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
uint64_t GetToken()
Get the token.
void StartClient(Ptr< Node > ClientNode)
Start the client.
uint32_t GetId(void) const
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
void WriteU64(uint64_t v)
virtual bool SetAllowBroadcast(bool allowBroadcast)=0
Configure whether broadcast datagram transmissions are allowed.
a class to represent an Ipv4 address mask
static const uint32_t packetSize
Ptr< Packet > m_sentPacketClient
Packet sent by client.
aggregate IP/TCP/UDP functionality to existing Nodes.
uint32_t GetStart(void) const
The index is an offset from the start of the packet.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
static TypeId GetTypeId()
Get the type ID.
Ptr< Socket > m_socketServer
Server socket.
IPv4 Fragmentation TestSuite.
uint8_t m_icmpType
ICMP type.
A sockets interface to UDP.
a polymophic address class
AttributeValue implementation for Callback.
Ptr< Socket > m_socketClient
Client socket.
Ptr< Packet > SendClient(void)
Send a packet.
Tag used in IPv4 Fragmentation Test.
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, TestDuration duration=QUICK)
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
void SetRecvCallback(Callback< void, Ptr< Socket > >)
Notify application when new data is available to be read.
static Ipv4FragmentationTestSuite g_ipv4fragmentationTestSuite
Static variable for test initialization.
void Disable(void)
Disable the error model.
bool m_broadcast
broadcast packets
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
Access to the IPv4 forwarding table, interfaces, and configuration.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
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.
virtual void Print(std::ostream &os) const
void SetNetDevicePointToPointMode(bool pointToPointMode)
SimpleNetDevice is Broadcast capable and ARP needing.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Iterator over the set of byte tags in a packet.
void Reset(void)
Reset any state associated with the error model.
#define NS_TEST_EXPECT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report if not.
void SetIpv4(Ipv4Address address)
virtual TypeId GetInstanceTypeId() const
Get the most derived TypeId for this Object.
void HandleReadIcmpClient(Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo)
Handle incoming ICMP packets.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
uint32_t GetEnd(void) const
The index is an offset from the start of the packet.
uint32_t m_dataSize
Data size.
void StartServer(Ptr< Node > ServerNode)
Start the server.
virtual void Serialize(TagBuffer buffer) const
Ipv4 addresses are stored in host order in this class.
a class to store IPv4 address information on an interface
void AddPacketTag(const Tag &tag) const
Add a packet tag.
virtual Ptr< Node > GetNode(void) const =0
Return the node this socket is associated with.
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
uint32_t m_size
packet size.
Time Seconds(double value)
Construct a Time in the indicated unit.
void SetDefault(std::string name, const AttributeValue &value)
void SetToken(uint64_t token)
Set the token.
Ptr< Packet > m_receivedPacketServer
Packet received by server.
uint64_t token
Token carried by the tag.
virtual bool AddAddress(uint32_t interface, Ipv4InterfaceAddress address)=0
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
Send data to a specified peer.
Ptr< Packet > m_receivedPacketClient
Packet received by client.
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual int GetPeerName(Address &address) const =0
Get the peer address of a connected socket.
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.
Ipv4FragmentationTest(bool broadcast)
build a set of SimpleNetDevice objects
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
void GetTag(Tag &tag) const
Read the requested tag and store it in the user-provided tag instance.
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
Ipv4FragmentationTestSuite()
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.
void Enable(void)
Enable the error model.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
void SetFill(uint8_t *fill, uint32_t fillSize, uint32_t dataSize)
Set the packet fill.
ByteTagIterator GetByteTagIterator(void) const
Returns an iterator over the set of byte tags included in this packet.
void HandleReadClient(Ptr< Socket > socket)
Handle incoming packets.
void HandleReadServer(Ptr< Socket > socket)
Handle incoming packets.
virtual uint32_t GetSerializedSize() const