20 #define NS3_LOG_ENABLE 1
23 #include "ns3/config.h"
24 #include "ns3/uinteger.h"
25 #include "ns3/socket-factory.h"
26 #include "ns3/ipv6-raw-socket-factory.h"
27 #include "ns3/udp-socket-factory.h"
28 #include "ns3/simulator.h"
30 #include "ns3/simple-net-device.h"
31 #include "ns3/drop-tail-queue.h"
32 #include "ns3/socket.h"
33 #include "ns3/udp-socket.h"
37 #include "ns3/inet-socket-address.h"
38 #include "ns3/boolean.h"
40 #include "ns3/ipv6-static-routing.h"
41 #include "ns3/ipv6-list-routing.h"
42 #include "ns3/inet6-socket-address.h"
43 #include "ns3/sixlowpan-net-device.h"
45 #include "ns3/udp-l4-protocol.h"
47 #include "ns3/ipv6-l3-protocol.h"
48 #include "ns3/icmpv6-l4-protocol.h"
52 #include <netinet/in.h>
68 ipv6Routing->AddRoutingProtocol (ipv6staticRouting, 0);
101 virtual void DoRun (
void);
112 void HandleReadIcmpClient (
Ipv6Address icmpSource, uint8_t icmpTtl, uint8_t icmpType,
113 uint8_t icmpCode,uint32_t icmpInfo);
115 void SetFill (uint8_t *fill, uint32_t fillSize, uint32_t dataSize);
122 :
TestCase (
"Verify the 6LoWPAN protocol fragmentation and reassembly")
146 TypeId tid = TypeId::LookupByName (
"ns3::UdpSocketFactory");
161 while ((packet = socket->
RecvFrom (from)))
163 if (Inet6SocketAddress::IsMatchingType (from))
179 TypeId tid = TypeId::LookupByName (
"ns3::UdpSocketFactory");
195 while ((packet = socket->
RecvFrom (from)))
197 if (Inet6SocketAddress::IsMatchingType (from))
206 uint8_t icmpTtl, uint8_t icmpType,
207 uint8_t icmpCode, uint32_t icmpInfo)
219 m_data =
new uint8_t [dataSize];
223 if (fillSize >= dataSize)
225 memcpy (
m_data, fill, dataSize);
230 while (filled + fillSize < dataSize)
232 memcpy (&
m_data[filled], fill, fillSize);
236 memcpy (&
m_data[filled], fill, dataSize - filled);
250 p = Create<Packet> (
m_size);
263 Ptr<Node> serverNode = CreateObject<Node> ();
268 serverDev = CreateObject<SimpleNetDevice> ();
269 serverDev->
SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
272 serverDevErrorModel->
Disable ();
285 ipv6->
SetUp (netdev_idx);
293 Ptr<Node> clientNode = CreateObject<Node> ();
298 clientDev = CreateObject<SimpleNetDevice> ();
299 clientDev->
SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
302 clientDevErrorModel->
Disable ();
315 ipv6->
SetUp (netdev_idx);
329 uint32_t packetSizes[5] = {200, 300, 400, 500, 600};
332 uint8_t fillData[78];
333 for ( uint32_t k = 48; k <= 125; k++ )
335 fillData[k - 48] = k;
339 for (
int i = 0; i < 5; i++)
341 uint32_t packetSize = packetSizes[i];
343 SetFill (fillData, 78, packetSize);
350 uint8_t recvBuffer[65000];
355 "Packet size not correct: recvSize: " << recvSize <<
" packetSizes[" << i <<
"]: " << packetSizes[i] );
359 0,
"Packet content differs");
366 for (
int i = 0; i < 5; i++)
368 uint32_t packetSize = packetSizes[i];
370 SetFill (fillData, 78, packetSize);
377 uint8_t recvBuffer[65000];
382 "Packet size not correct: recvSize: " << recvSize <<
" packetSizes[" << i <<
"]: " << packetSizes[i] );
386 0,
"Packet content differs");
394 for (
int i = 1; i < 5; i++)
396 uint32_t packetSize = packetSizes[i];
398 SetFill (fillData, 78, packetSize);
401 serverDevErrorModel->
Reset ();
410 uint8_t recvBuffer[65000];
415 "Packet size not correct: recvSize: " << recvSize <<
" packetSizes[" << i <<
"]: " << packetSizes[i] );
419 0,
"Packet content differs");
427 clientDevErrorModel->
Disable ();
428 serverDevErrorModel->
Enable ();
429 for (
int i = 1; i < 5; i++)
431 uint32_t packetSize = packetSizes[i];
433 SetFill (fillData, 78, packetSize);
436 serverDevErrorModel->
Reset ();
453 Simulator::Destroy ();
Access to the IPv6 forwarding table, interfaces, and configuration.
SixlowpanFragmentationTestSuite()
IPv6 address associated with an interface.
uint32_t GetSize(void) const
Ptr< Packet > m_sentPacketClient
Ptr< Socket > m_socketClient
void SetNetDevice(Ptr< NetDevice > device)
Setup SixLowPan to be a proxy for the specified NetDevice.
A sockets interface to UDP.
Ptr< Packet > m_receivedPacketServer
a polymophic address class
AttributeValue form of a Callback.
void SetJumpingMode(bool mode)
Set if the odd packets are delayed (even ones are not delayed ever)
void RemoveAllPacketTags(void)
Remove all packet tags.
virtual bool SetMtu(const uint16_t mtu)
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
void StartClient(Ptr< Node > ClientNode)
An implementation of the ICMPv6 protocol.
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 Disable(void)
Disable the error model.
void AggregateObject(Ptr< Object > other)
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
Ptr< Packet > Copy(void) const
Ptr< Packet > m_receivedPacketClient
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
Ptr< Socket > m_socketServer
void SetReceiveErrorModel(Ptr< ErrorModel > em)
Attach a receive ErrorModel to the SimpleNetDevice.
void HandleReadServer(Ptr< Socket > socket)
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
Add a NetDevice interface.
void StartServer(Ptr< Node > ServerNode)
virtual void RegisterExtensions()
Register the IPv6 Extensions.
void HandleReadClient(Ptr< Socket > socket)
Describes an IPv6 address.
void SetRoutingProtocol(Ptr< Ipv6RoutingProtocol > routingProtocol)
Set routing protocol for this stack.
SixlowpanFragmentationTestSuite g_sixlowpanFragmentationTestSuite
uint32_t AddDevice(Ptr< NetDevice > device)
uint32_t GetId(void) const
virtual Ptr< Node > GetNode(void) const =0
Return the node this socket is associated with.
Ptr< Packet > SendClient(void)
virtual void SetAddress(Address address)
Set the address of this interface.
void RemoveAllByteTags(void)
Remove all byte tags stored in this packet.
virtual void RegisterOptions()
Register the IPv6 Options.
Describes an IPv6 prefix.
SixlowpanFragmentationTest()
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
Copy the packet contents to a byte buffer.
~SixlowpanFragmentationTest()
void SetDuplicateMode(bool mode)
Set if the odd packets are duplicated (even ones are not duplicated ever)
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.
void HandleReadIcmpClient(Ipv6Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo)
This test suite implements a Unit Test.
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
static void AddInternetStack(Ptr< Node > node)
void SetChannel(Ptr< SimpleChannel > channel)
Attach a channel to this net device.
void SetAttribute(std::string name, const AttributeValue &value)
Ptr< T > GetObject(void) const
a unique identifier for an interface.
void Enable(void)
Enable the error model.
void SetFill(uint8_t *fill, uint32_t fillSize, uint32_t dataSize)
virtual void SetUp(uint32_t interface)=0
Set the interface into the "up" state.
virtual void DoRun(void)
Implementation to actually run this TestCase.