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> 
   68   virtual void DoRun (
void);
 
  105   void HandleReadIcmpClient (
Ipv6Address icmpSource, uint8_t icmpTtl, uint8_t icmpType,
 
  106                              uint8_t icmpCode, uint32_t icmpInfo);
 
  113   void SetFill (uint8_t *fill, uint32_t fillSize, uint32_t dataSize);
 
  124   : 
TestCase (
"Verify the 6LoWPAN protocol fragmentation and reassembly")
 
  151       TypeId tid = TypeId::LookupByName (
"ns3::UdpSocketFactory");
 
  166   while ((packet = socket->
RecvFrom (from)))
 
  168       if (Inet6SocketAddress::IsMatchingType (from))
 
  184       TypeId tid = TypeId::LookupByName (
"ns3::UdpSocketFactory");
 
  200   while ((packet = socket->
RecvFrom (from)))
 
  202       if (Inet6SocketAddress::IsMatchingType (from))
 
  211                                                   uint8_t icmpTtl, uint8_t icmpType,
 
  212                                                   uint8_t icmpCode, uint32_t icmpInfo)
 
  224       m_data = 
new uint8_t [dataSize];
 
  228   if (fillSize >= dataSize)
 
  230       memcpy (
m_data, fill, dataSize);
 
  235   while (filled + fillSize < dataSize)
 
  237       memcpy (&
m_data[filled], fill, fillSize);
 
  241   memcpy (&
m_data[filled], fill, dataSize - filled);
 
  255       p = Create<Packet> (
m_size);
 
  268   Packet::EnablePrinting ();
 
  271   Ptr<Node> serverNode = CreateObject<Node> ();
 
  279     serverDev = CreateObject<SimpleNetDevice> ();
 
  280     serverDev->
SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
 
  283     serverDevErrorModel->
Disable ();
 
  296     ipv6->
SetUp (netdev_idx);
 
  302   Ptr<Node> clientNode = CreateObject<Node> ();
 
  310     clientDev = CreateObject<SimpleNetDevice> ();
 
  311     clientDev->
SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
 
  314     clientDevErrorModel->
Disable ();
 
  327     ipv6->
SetUp (netdev_idx);
 
  338   uint32_t packetSizes[5] = {200, 300, 400, 500, 600};
 
  341   uint8_t fillData[78];
 
  342   for ( uint32_t k = 48; k <= 125; k++ )
 
  344       fillData[k - 48] = k;
 
  348   for ( 
int i = 0; i < 5; i++)
 
  352       SetFill (fillData, 78, packetSize);
 
  359       uint8_t recvBuffer[65000];
 
  364                              "Packet size not correct: recvSize: " << recvSize << 
" packetSizes[" << i << 
"]: " << packetSizes[i] );
 
  368                              0, 
"Packet content differs");
 
  375   for ( 
int i = 0; i < 5; i++)
 
  379       SetFill (fillData, 78, packetSize);
 
  386       uint8_t recvBuffer[65000];
 
  391                              "Packet size not correct: recvSize: " << recvSize << 
" packetSizes[" << i << 
"]: " << packetSizes[i] );
 
  395                              0, 
"Packet content differs");
 
  403   for ( 
int i = 1; i < 5; i++)
 
  407       SetFill (fillData, 78, packetSize);
 
  410       serverDevErrorModel->
Reset ();
 
  419       uint8_t recvBuffer[65000];
 
  424                              "Packet size not correct: recvSize: " << recvSize << 
" packetSizes[" << i << 
"]: " << packetSizes[i] );
 
  428                              0, 
"Packet content differs");
 
  436   clientDevErrorModel->
Disable ();
 
  437   serverDevErrorModel->
Enable ();
 
  438   for ( 
int i = 1; i < 5; i++)
 
  442       SetFill (fillData, 78, packetSize);
 
  445       serverDevErrorModel->
Reset ();
 
  460   Simulator::Destroy ();
 
  478   : 
TestSuite (
"sixlowpan-fragmentation", UNIT)
 
AttributeValue implementation for Boolean. 
 
Ptr< T > GetObject(void) const 
Get a pointer to the requested aggregated Object. 
 
Access to the IPv6 forwarding table, interfaces, and configuration. 
 
SixlowpanFragmentationTestSuite()
 
uint8_t m_icmpType
ICMP type. 
 
IPv6 address associated with an interface. 
 
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). 
 
Ptr< Packet > m_sentPacketClient
Packet sent by client. 
 
Ptr< Socket > m_socketClient
Socket on the client. 
 
void SetNetDevice(Ptr< NetDevice > device)
Setup SixLowPan to be a proxy for the specified NetDevice. 
 
void StartServer(Ptr< Node > serverNode)
Start the server node. 
 
Ptr< Packet > m_receivedPacketServer
packet received by the server. 
 
a polymophic address class 
 
AttributeValue implementation for Callback. 
 
void RemoveAllPacketTags(void)
Remove all packet tags. 
 
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite. 
 
uint32_t m_size
Size of the packet if no data has been provided. 
 
virtual bool SetMtu(const uint16_t mtu)
 
void SetIpv4StackInstall(bool enable)
Enable/disable IPv4 stack install. 
 
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. 
 
6LoWPAN Fragmentation TestSuite 
 
void Disable(void)
Disable the error model. 
 
static SixlowpanFragmentationTestSuite g_sixlowpanFragmentationTestSuite
Static variable for test initialization. 
 
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 
performs a COW copy of the packet. 
 
Ptr< Packet > m_receivedPacketClient
Packet received by the client. 
 
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. 
 
void SetDuplicateMode(bool mode)
Set if the odd packets are duplicated (even ones are not duplicated ever) 
 
void StartClient(Ptr< Node > clientNode)
Start the client node. 
 
Ptr< Socket > m_socketServer
Socket on the server. 
 
void Install(std::string nodeName) const 
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
 
void Reset(void)
Reset any state associated with the error model. 
 
void SetReceiveErrorModel(Ptr< ErrorModel > em)
Attach a receive ErrorModel to the SimpleNetDevice. 
 
void HandleReadServer(Ptr< Socket > socket)
Handles incoming packets in the server. 
 
uint8_t m_icmpCode
ICMP code. 
 
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
Add a NetDevice interface. 
 
6LoWPAN Fragmentation Test 
 
void HandleReadClient(Ptr< Socket > socket)
Handles incoming packets in the client. 
 
Describes an IPv6 address. 
 
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node. 
 
uint32_t GetId(void) const 
 
virtual Ptr< Node > GetNode(void) const =0
Return the node this socket is associated with. 
 
Ptr< Packet > SendClient(void)
Send a packet to the server. 
 
virtual void SetAddress(Address address)
Set the address of this interface. 
 
Time Seconds(double value)
Construct a Time in the indicated unit. 
 
void RemoveAllByteTags(void)
Remove all byte tags stored in this packet. 
 
uint8_t * m_data
Data to be carried in the packet. 
 
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. 
 
static const uint32_t packetSize
 
~SixlowpanFragmentationTest()
 
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)
Handles incoming ICMP packets in the client. 
 
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host. 
 
uint32_t m_dataSize
Size of the data (if any). 
 
void SetChannel(Ptr< SimpleChannel > channel)
Attach a channel to this net device. 
 
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful. 
 
a unique identifier for an interface. 
 
void Enable(void)
Enable the error model. 
 
void SetFill(uint8_t *fill, uint32_t fillSize, uint32_t dataSize)
Set the packet optional content. 
 
virtual void SetUp(uint32_t interface)=0
Set the interface into the "up" state. 
 
virtual void DoRun(void)
Implementation to actually run this TestCase.