23 #define NS3_LOG_ENABLE 1
26 #include "ns3/config.h"
27 #include "ns3/uinteger.h"
28 #include "ns3/socket-factory.h"
29 #include "ns3/ipv4-raw-socket-factory.h"
30 #include "ns3/ipv6-raw-socket-factory.h"
31 #include "ns3/udp-socket-factory.h"
32 #include "ns3/simulator.h"
33 #include "error-channel.h"
34 #include "error-net-device.h"
35 #include "ns3/drop-tail-queue.h"
36 #include "ns3/socket.h"
37 #include "ns3/udp-socket.h"
41 #include "ns3/inet-socket-address.h"
42 #include "ns3/boolean.h"
44 #include "ns3/ipv6-static-routing.h"
45 #include "ns3/ipv6-list-routing.h"
46 #include "ns3/inet6-socket-address.h"
48 #include "ns3/arp-l3-protocol.h"
49 #include "ns3/ipv4-l3-protocol.h"
50 #include "ns3/icmpv4-l4-protocol.h"
51 #include "ns3/ipv4-list-routing.h"
52 #include "ns3/ipv4-static-routing.h"
53 #include "ns3/udp-l4-protocol.h"
55 #include "ns3/ipv6-l3-protocol.h"
56 #include "ns3/icmpv6-l4-protocol.h"
60 #include <netinet/in.h>
76 ipv6Routing->AddRoutingProtocol (ipv6staticRouting, 0);
109 virtual void DoRun (
void);
120 void HandleReadIcmpClient (
Ipv6Address icmpSource, uint8_t icmpTtl, uint8_t icmpType,
121 uint8_t icmpCode,uint32_t icmpInfo);
123 void SetFill (uint8_t *fill, uint32_t fillSize, uint32_t dataSize);
129 Ipv6FragmentationTest::Ipv6FragmentationTest ()
130 :
TestCase (
"Verify the IPv6 layer 3 protocol fragmentation and reassembly")
137 Ipv6FragmentationTest::~Ipv6FragmentationTest ()
149 Ipv6FragmentationTest::StartServer (
Ptr<Node> ServerNode)
152 if (m_socketServer == 0)
154 TypeId tid = TypeId::LookupByName (
"ns3::UdpSocketFactory");
155 m_socketServer = Socket::CreateSocket (ServerNode, tid);
157 m_socketServer->
Bind (local);
158 Ptr<UdpSocket> udpSocket = DynamicCast<UdpSocket> (m_socketServer);
165 Ipv6FragmentationTest::HandleReadServer (
Ptr<Socket> socket)
169 while ((packet = socket->
RecvFrom (from)))
171 if (Inet6SocketAddress::IsMatchingType (from))
176 m_receivedPacketServer = packet->
Copy ();
182 Ipv6FragmentationTest::StartClient (
Ptr<Node> ClientNode)
185 if (m_socketClient == 0)
187 TypeId tid = TypeId::LookupByName (
"ns3::UdpSocketFactory");
188 m_socketClient = Socket::CreateSocket (ClientNode, tid);
192 m_socketClient->
SetAttribute (
"IcmpCallback6", cbValue);
199 Ipv6FragmentationTest::HandleReadClient (
Ptr<Socket> socket)
203 while ((packet = socket->
RecvFrom (from)))
205 if (Inet6SocketAddress::IsMatchingType (from))
207 m_receivedPacketClient = packet->
Copy ();
213 Ipv6FragmentationTest::HandleReadIcmpClient (
Ipv6Address icmpSource,
214 uint8_t icmpTtl, uint8_t icmpType,
215 uint8_t icmpCode, uint32_t icmpInfo)
217 m_icmpType = icmpType;
218 m_icmpCode = icmpCode;
222 Ipv6FragmentationTest::SetFill (uint8_t *fill, uint32_t fillSize, uint32_t dataSize)
224 if (dataSize != m_dataSize)
227 m_data =
new uint8_t [dataSize];
228 m_dataSize = dataSize;
231 if (fillSize >= dataSize)
233 memcpy (m_data, fill, dataSize);
238 while (filled + fillSize < dataSize)
240 memcpy (&m_data[filled], fill, fillSize);
244 memcpy (&m_data[filled], fill, dataSize - filled);
249 Ptr<Packet> Ipv6FragmentationTest::SendClient (
void)
254 p = Create<Packet> (m_data, m_dataSize);
258 p = Create<Packet> (m_size);
260 m_socketClient->
Send (p);
276 Ptr<Node> serverNode = CreateObject<Node> ();
277 AddInternetStack (serverNode);
281 serverDev = CreateObject<ErrorNetDevice> ();
282 serverDev->
SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
285 serverDevErrorModel->
Disable ();
291 ipv6->
SetUp (netdev_idx);
293 StartServer (serverNode);
296 Ptr<Node> clientNode = CreateObject<Node> ();
297 AddInternetStack (clientNode);
301 clientDev = CreateObject<ErrorNetDevice> ();
302 clientDev->
SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
305 clientDevErrorModel->
Disable ();
311 ipv6->
SetUp (netdev_idx);
313 StartClient (clientNode);
317 serverDev->SetChannel (channel);
318 clientDev->SetChannel (channel);
323 uint32_t packetSizes[5] = {1000, 2000, 5000, 10000, 65000};
326 uint8_t fillData[78];
327 for ( uint32_t k = 48; k <= 125; k++ )
329 fillData[k - 48] = k;
333 for (
int i = 0; i < 5; i++)
335 uint32_t packetSize = packetSizes[i];
337 SetFill (fillData, 78, packetSize);
339 m_receivedPacketServer = Create<Packet> ();
341 &Ipv6FragmentationTest::SendClient,
this);
344 uint8_t recvBuffer[65000];
346 uint16_t recvSize = m_receivedPacketServer->
GetSize ();
348 NS_TEST_EXPECT_MSG_EQ (recvSize, packetSizes[i],
349 "Packet size not correct: recvSize: " << recvSize <<
" packetSizes[" << i <<
"]: " << packetSizes[i] );
351 m_receivedPacketServer->
CopyData (recvBuffer, 65000);
352 NS_TEST_EXPECT_MSG_EQ (memcmp (m_data, recvBuffer, m_receivedPacketServer->
GetSize ()),
353 0,
"Packet content differs");
360 for (
int i = 0; i < 5; i++)
362 uint32_t packetSize = packetSizes[i];
364 SetFill (fillData, 78, packetSize);
366 m_receivedPacketServer = Create<Packet> ();
368 &Ipv6FragmentationTest::SendClient,
this);
371 uint8_t recvBuffer[65000];
373 uint16_t recvSize = m_receivedPacketServer->
GetSize ();
375 NS_TEST_EXPECT_MSG_EQ (recvSize, packetSizes[i],
376 "Packet size not correct: recvSize: " << recvSize <<
" packetSizes[" << i <<
"]: " << packetSizes[i] );
378 m_receivedPacketServer->
CopyData (recvBuffer, 65000);
379 NS_TEST_EXPECT_MSG_EQ (memcmp (m_data, recvBuffer, m_receivedPacketServer->
GetSize ()),
380 0,
"Packet content differs");
391 clientDevErrorModel->
Disable ();
392 serverDevErrorModel->
Enable ();
393 for (
int i = 1; i < 5; i++)
395 uint32_t packetSize = packetSizes[i];
397 SetFill (fillData, 78, packetSize);
400 serverDevErrorModel->Reset ();
402 m_receivedPacketServer = Create<Packet> ();
406 &Ipv6FragmentationTest::SendClient,
this);
409 uint16_t recvSize = m_receivedPacketServer->
GetSize ();
411 NS_TEST_EXPECT_MSG_EQ ((recvSize == 0),
true,
"Server got a packet, something wrong");
412 NS_TEST_EXPECT_MSG_EQ ((m_icmpType == Icmpv6Header::ICMPV6_ERROR_TIME_EXCEEDED)
413 && (m_icmpCode == Icmpv6Header::ICMPV6_FRAGTIME),
414 true,
"Client did not receive ICMPv6::TIME_EXCEEDED " <<
int(m_icmpType) <<
int(m_icmpCode) );
418 Simulator::Destroy ();
428 } g_ipv6fragmentationTestSuite;
Access to the IPv6 forwarding table, interfaces, and configuration.
IPv6 address associated with an interface.
uint32_t GetSize(void) const
virtual bool SetMtu(const uint16_t mtu)
TestSuite(std::string name, Type type=UNIT)
Constuct a new test suite.
A sockets interface to UDP.
a polymophic address class
void RemoveAllPacketTags(void)
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void SetRecvCallback(Callback< void, Ptr< Socket > >)
Notify application when new data is available to be read.
void AggregateObject(Ptr< Object > other)
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)
Ptr< Packet > Copy(void) const
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
void SetReceiveErrorModel(Ptr< ErrorModel > em)
virtual void SetAddress(Address address)
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
Add a NetDevice interface.
virtual void DoRun(void)
Implementation to actually run this test case.
virtual void RegisterExtensions()
Register the IPv6 Extensions.
Describes an IPv6 address.
void SetRoutingProtocol(Ptr< Ipv6RoutingProtocol > routingProtocol)
Set routing protocol for this stack.
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
uint32_t AddDevice(Ptr< NetDevice > device)
uint32_t GetId(void) const
virtual Ptr< Node > GetNode(void) const =0
void RemoveAllByteTags(void)
virtual void RegisterOptions()
Register the IPv6 Options.
Describes an IPv6 prefix. It is just a bitmask like Ipv4Mask.
virtual bool AddAddress(uint32_t interface, Ipv6InterfaceAddress address)=0
Add an address on the specified IPv6 interface.
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
void SetJumpingTime(Time delay)
Set the delay for the odd packets (even ones are not delayed)
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.
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
void SetAttribute(std::string name, const AttributeValue &value)
Ptr< T > GetObject(void) const
a unique identifier for an interface.
virtual void SetUp(uint32_t interface)=0
Set the interface into the "up" state.