|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
27 #include "ns3/config.h"
28 #include "ns3/uinteger.h"
29 #include "ns3/socket-factory.h"
30 #include "ns3/ipv4-raw-socket-factory.h"
31 #include "ns3/ipv6-raw-socket-factory.h"
32 #include "ns3/udp-socket-factory.h"
33 #include "ns3/simulator.h"
34 #include "ns3/simple-net-device.h"
35 #include "ns3/socket.h"
36 #include "ns3/udp-socket.h"
40 #include "ns3/inet-socket-address.h"
41 #include "ns3/boolean.h"
43 #include "ns3/ipv6-static-routing.h"
44 #include "ns3/ipv6-list-routing.h"
45 #include "ns3/inet6-socket-address.h"
47 #include "ns3/arp-l3-protocol.h"
48 #include "ns3/ipv4-l3-protocol.h"
49 #include "ns3/icmpv4-l4-protocol.h"
50 #include "ns3/ipv4-list-routing.h"
51 #include "ns3/ipv4-static-routing.h"
52 #include "ns3/udp-l4-protocol.h"
54 #include "ns3/ipv6-l3-protocol.h"
55 #include "ns3/icmpv6-l4-protocol.h"
56 #include "ns3/traffic-control-layer.h"
57 #include "ns3/internet-stack-helper.h"
58 #include "ns3/error-channel.h"
62 #include <netinet/in.h>
90 virtual void Print (std::ostream &os)
const { os <<
"token=" << token; }
95 void SetToken (uint64_t token) { this->token = token; }
126 virtual void DoRun (
void);
163 void HandleReadIcmpClient (
Ipv6Address icmpSource, uint8_t icmpTtl, uint8_t icmpType,
164 uint8_t icmpCode, uint32_t icmpInfo);
172 void SetFill (uint8_t *fill, uint32_t fillSize, uint32_t dataSize);
183 :
TestCase (
"Verify the IPv6 layer 3 protocol fragmentation and reassembly")
210 TypeId tid = TypeId::LookupByName (
"ns3::UdpSocketFactory");
225 while ((packet = socket->
RecvFrom (from)))
227 if (Inet6SocketAddress::IsMatchingType (from))
240 TypeId tid = TypeId::LookupByName (
"ns3::UdpSocketFactory");
256 while ((packet = socket->
RecvFrom (from)))
258 if (Inet6SocketAddress::IsMatchingType (from))
267 uint8_t icmpTtl, uint8_t icmpType,
268 uint8_t icmpCode, uint32_t icmpInfo)
280 m_data =
new uint8_t [dataSize];
284 if (fillSize >= dataSize)
286 memcpy (
m_data, fill, dataSize);
291 while (filled + fillSize < dataSize)
293 memcpy (&
m_data[filled], fill, fillSize);
297 memcpy (&
m_data[filled], fill, dataSize - filled);
311 p = Create<Packet> (
m_size);
332 Ptr<Node> serverNode = CreateObject<Node> ();
337 serverDev = CreateObject<SimpleNetDevice> ();
338 serverDev->
SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
341 serverDevErrorModel->
Disable ();
347 ipv6->
SetUp (netdev_idx);
352 Ptr<Node> clientNode = CreateObject<Node> ();
357 clientDev = CreateObject<SimpleNetDevice> ();
358 clientDev->
SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
361 clientDevErrorModel->
Disable ();
367 ipv6->
SetUp (netdev_idx);
379 uint32_t packetSizes[5] = {2000, 2500, 5000, 10000, 65000};
382 uint8_t fillData[78];
383 for ( uint32_t
k = 48;
k <= 125;
k++ )
385 fillData[
k - 48] =
k;
389 for (
int i = 0; i < 5; i++)
400 uint8_t recvBuffer[65000];
405 "Packet size not correct: recvSize: " << recvSize <<
" packetSizes[" << i <<
"]: " << packetSizes[i] );
409 0,
"Packet content differs");
415 channel->SetJumpingMode (
true);
416 for (
int i = 0; i < 5; i++)
427 uint8_t recvBuffer[65000];
432 "Packet size not correct: recvSize: " << recvSize <<
" packetSizes[" << i <<
"]: " << packetSizes[i] );
436 0,
"Packet content differs");
438 channel->SetJumpingMode (
false);
447 clientDevErrorModel->
Disable ();
448 serverDevErrorModel->
Enable ();
449 for (
int i = 1; i < 5; i++)
456 serverDevErrorModel->
Reset ();
469 && (
m_icmpCode == Icmpv6Header::ICMPV6_FRAGTIME),
475 clientDevErrorModel->
Disable ();
476 serverDevErrorModel->
Disable ();
477 for (
int i= 0; i<5; i++)
497 uint32_t tagStart = 0;
523 Simulator::Destroy ();
a unique identifier for an interface.
IPv6 address associated with an interface.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
uint32_t m_size
packet size.
void StartClient(Ptr< Node > ClientNode)
Start the client.
TypeId GetTypeId(void) const
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
void StartServer(Ptr< Node > ServerNode)
Start the server.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
uint32_t GetId(void) const
void GetTag(Tag &tag) const
Read the requested tag and store it in the user-provided tag instance.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
Add a NetDevice interface.
virtual Ptr< Node > GetNode(void) const =0
Return the node this socket is associated with.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
virtual void Print(std::ostream &os) const
Ptr< Packet > m_sentPacketClient
Packet sent by client.
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
void Enable(void)
Enable the error model.
Tag used in IPv6 Fragmentation Test.
void Reset(void)
Reset any state associated with the error model.
void SetFill(uint8_t *fill, uint32_t fillSize, uint32_t dataSize)
Set the packet fill.
Describes an IPv6 address.
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.
virtual bool SetMtu(const uint16_t mtu)
uint8_t m_icmpCode
ICMP code.
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
ByteTagIterator GetByteTagIterator(void) const
Returns an iterator over the set of byte tags included in this packet.
Identifies a byte tag and a set of bytes within a packet to which the tag applies.
virtual bool AddAddress(uint32_t interface, Ipv6InterfaceAddress address, bool addOnLinkRoute=true)=0
Add an address on the specified IPv6 interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
virtual void SetAddress(Address address)
Set the address of this interface.
Ptr< Socket > m_socketClient
Client socket.
uint64_t token
Token carried by the tag.
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
#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 SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
Notify application when new data is available to be read.
Callback< ObjectBase * > GetConstructor(void) const
Get the constructor callback.
tag a set of bytes in a packet
a polymophic address class
uint32_t GetStart(void) const
The index is an offset from the start of the packet.
void Disable(void)
Disable the error model.
IPv6 Fragmentation TestSuite.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
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 HandleReadServer(Ptr< Socket > socket)
Handle incoming packets.
uint8_t m_icmpType
ICMP type.
AttributeValue implementation for Callback.
virtual void SetUp(uint32_t interface)=0
Set the interface into the "up" state.
uint32_t GetEnd(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.
virtual void Deserialize(TagBuffer buffer)
virtual void DoRun(void)
Implementation to actually run this TestCase.
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
uint32_t m_dataSize
Data size.
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...
Ptr< Packet > m_receivedPacketServer
Packet received by server.
A sockets interface to UDP.
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Ptr< Socket > m_socketServer
Server socket.
virtual TypeId GetInstanceTypeId() const
Get the most derived TypeId for this Object.
Ptr< Packet > m_receivedPacketClient
Packet received by client.
std::string GetName(void) const
Get the name.
static const uint32_t packetSize
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
@ UNIT
This test suite implements a Unit Test.
Time Seconds(double value)
Construct a Time in the indicated unit.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
void HandleReadClient(Ptr< Socket > socket)
Handle incoming packets.
uint64_t GetToken()
Get the token.
Ipv6FragmentationTestSuite()
Access to the IPv6 forwarding table, interfaces, and configuration.
static TypeId GetTypeId()
Get the type ID.
void SetIpv4StackInstall(bool enable)
Enable/disable IPv4 stack install.
void SetToken(uint64_t token)
Set the token.
static Ipv6FragmentationTestSuite g_ipv6fragmentationTestSuite
Static variable for test initialization.
Iterator over the set of byte tags in a packet.
void HandleReadIcmpClient(Ipv6Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo)
Handle incoming ICMP packets.
Describes an IPv6 prefix.
aggregate IP/TCP/UDP functionality to existing Nodes.
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.
Ptr< Packet > SendClient(void)
Send a packet.
void SetReceiveErrorModel(Ptr< ErrorModel > em)
Attach a receive ErrorModel to the SimpleNetDevice.
void WriteU64(uint64_t v)
virtual void Serialize(TagBuffer buffer) const
virtual uint32_t GetSerializedSize() const