21 #include "ns3/config.h"
22 #include "ns3/uinteger.h"
23 #include "ns3/socket-factory.h"
24 #include "ns3/ipv6-raw-socket-factory.h"
25 #include "ns3/udp-socket-factory.h"
26 #include "ns3/simulator.h"
27 #include "ns3/simple-net-device.h"
28 #include "ns3/socket.h"
29 #include "ns3/udp-socket.h"
33 #include "ns3/inet-socket-address.h"
34 #include "ns3/boolean.h"
36 #include "ns3/sixlowpan-net-device.h"
37 #include "ns3/internet-stack-helper.h"
38 #include "ns3/icmpv6-l4-protocol.h"
39 #include "ns3/error-channel.h"
43 #include <netinet/in.h>
67 virtual void DoRun (
void);
104 void HandleReadIcmpClient (
Ipv6Address icmpSource, uint8_t icmpTtl, uint8_t icmpType,
105 uint8_t icmpCode, uint32_t icmpInfo);
112 void SetFill (uint8_t *fill, uint32_t fillSize, uint32_t dataSize);
123 :
TestCase (
"Verify the 6LoWPAN protocol fragmentation and reassembly")
150 TypeId tid = TypeId::LookupByName (
"ns3::UdpSocketFactory");
165 while ((packet = socket->
RecvFrom (from)))
167 if (Inet6SocketAddress::IsMatchingType (from))
183 TypeId tid = TypeId::LookupByName (
"ns3::UdpSocketFactory");
199 while ((packet = socket->
RecvFrom (from)))
201 if (Inet6SocketAddress::IsMatchingType (from))
210 uint8_t icmpTtl, uint8_t icmpType,
211 uint8_t icmpCode, uint32_t icmpInfo)
223 m_data =
new uint8_t [dataSize];
227 if (fillSize >= dataSize)
229 memcpy (
m_data, fill, dataSize);
234 while (filled + fillSize < dataSize)
236 memcpy (&
m_data[filled], fill, fillSize);
240 memcpy (&
m_data[filled], fill, dataSize - filled);
254 p = Create<Packet> (
m_size);
267 Packet::EnablePrinting ();
270 Ptr<Node> serverNode = CreateObject<Node> ();
278 serverDev = CreateObject<SimpleNetDevice> ();
279 serverDev->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
280 serverDev->SetMtu (1500);
281 serverDev->SetReceiveErrorModel (serverDevErrorModel);
282 serverDevErrorModel->Disable ();
286 serverSix->SetAttribute (
"ForceEtherType",
BooleanValue (
true) );
288 serverSix->SetNetDevice (serverDev);
291 ipv6->AddInterface (serverDev);
292 uint32_t netdev_idx = ipv6->AddInterface (serverSix);
294 ipv6->AddAddress (netdev_idx, ipv6Addr);
295 ipv6->SetUp (netdev_idx);
301 Ptr<Node> clientNode = CreateObject<Node> ();
309 clientDev = CreateObject<SimpleNetDevice> ();
310 clientDev->SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
311 clientDev->SetMtu (150);
312 clientDev->SetReceiveErrorModel (clientDevErrorModel);
313 clientDevErrorModel->Disable ();
317 clientSix->SetAttribute (
"ForceEtherType",
BooleanValue (
true) );
319 clientSix->SetNetDevice (clientDev);
322 ipv6->AddInterface (clientDev);
323 uint32_t netdev_idx = ipv6->AddInterface (clientSix);
325 ipv6->AddAddress (netdev_idx, ipv6Addr);
326 ipv6->SetUp (netdev_idx);
332 serverDev->SetChannel (
channel);
333 clientDev->SetChannel (
channel);
337 uint32_t packetSizes[5] = {200, 300, 400, 500, 600};
340 uint8_t fillData[78];
341 for ( uint32_t
k = 48;
k <= 125;
k++ )
343 fillData[
k - 48] =
k;
347 for (
int i = 0; i < 5; i++)
358 uint8_t recvBuffer[65000];
363 "Packet size not correct: recvSize: " << recvSize <<
" packetSizes[" << i <<
"]: " << packetSizes[i] );
367 0,
"Packet content differs");
373 channel->SetJumpingMode (
true);
374 for (
int i = 0; i < 5; i++)
385 uint8_t recvBuffer[65000];
390 "Packet size not correct: recvSize: " << recvSize <<
" packetSizes[" << i <<
"]: " << packetSizes[i] );
394 0,
"Packet content differs");
396 channel->SetJumpingMode (
false);
401 channel->SetDuplicateMode (
true);
402 for (
int i = 1; i < 5; i++)
409 serverDevErrorModel->Reset ();
418 uint8_t recvBuffer[65000];
423 "Packet size not correct: recvSize: " << recvSize <<
" packetSizes[" << i <<
"]: " << packetSizes[i] );
427 0,
"Packet content differs");
429 channel->SetDuplicateMode (
false);
435 clientDevErrorModel->Disable ();
436 serverDevErrorModel->Enable ();
437 for (
int i = 1; i < 5; i++)
444 serverDevErrorModel->Reset ();
459 Simulator::Destroy ();
476 :
TestSuite (
"sixlowpan-fragmentation", UNIT)
6LoWPAN Fragmentation Test
uint8_t m_icmpType
ICMP type.
Ptr< Packet > m_sentPacketClient
Packet sent by client.
void StartClient(Ptr< Node > clientNode)
Start the client node.
void StartServer(Ptr< Node > serverNode)
Start the server node.
Ptr< Socket > m_socketServer
Socket on the server.
Ptr< Socket > m_socketClient
Socket on the client.
uint8_t m_icmpCode
ICMP code.
void SetFill(uint8_t *fill, uint32_t fillSize, uint32_t dataSize)
Set the packet optional content.
void HandleReadIcmpClient(Ipv6Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo)
Handles incoming ICMP packets in the client.
Ptr< Packet > m_receivedPacketServer
packet received by the server.
void HandleReadServer(Ptr< Socket > socket)
Handles incoming packets in the server.
SixlowpanFragmentationTest()
uint32_t m_dataSize
Size of the data (if any).
void HandleReadClient(Ptr< Socket > socket)
Handles incoming packets in the client.
Ptr< Packet > SendClient(void)
Send a packet to the server.
uint32_t m_size
Size of the packet if no data has been provided.
~SixlowpanFragmentationTest()
virtual void DoRun(void)
Implementation to actually run this TestCase.
Ptr< Packet > m_receivedPacketClient
Packet received by the client.
uint8_t * m_data
Data to be carried in the packet.
6LoWPAN Fragmentation TestSuite
SixlowpanFragmentationTestSuite()
a polymophic address class
AttributeValue implementation for Boolean.
AttributeValue implementation for Callback.
An implementation of the ICMPv6 protocol.
aggregate IP/TCP/UDP functionality to existing Nodes.
void SetIpv4StackInstall(bool enable)
Enable/disable IPv4 stack install.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
Describes an IPv6 address.
Access to the IPv6 forwarding table, interfaces, and configuration.
IPv6 address associated with an interface.
Describes an IPv6 prefix.
uint32_t GetId(void) const
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
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.
void RemoveAllByteTags(void)
Remove all byte tags stored in this packet.
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
void RemoveAllPacketTags(void)
Remove all packet tags.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
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.
virtual Ptr< Node > GetNode(void) const =0
Return the node this socket is associated with.
void SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
Notify application when new data is available to be read.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this 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.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
a unique identifier for an interface.
#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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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...
static SixlowpanFragmentationTestSuite g_sixlowpanFragmentationTestSuite
Static variable for test initialization.
static const uint32_t packetSize