26 #include "ns3/socket-factory.h"
27 #include "ns3/udp-socket-factory.h"
28 #include "ns3/simulator.h"
29 #include "ns3/simple-channel.h"
30 #include "ns3/simple-net-device.h"
31 #include "ns3/simple-net-device-helper.h"
32 #include "ns3/drop-tail-queue.h"
33 #include "ns3/socket.h"
34 #include "ns3/traffic-control-helper.h"
36 #include "ns3/boolean.h"
39 #include "ns3/inet-socket-address.h"
40 #include "ns3/inet6-socket-address.h"
41 #include "ns3/internet-stack-helper.h"
43 #include "ns3/arp-l3-protocol.h"
44 #include "ns3/ipv4-l3-protocol.h"
45 #include "ns3/ipv4-queue-disc-item.h"
46 #include "ns3/ipv6-l3-protocol.h"
47 #include "ns3/icmpv4-l4-protocol.h"
48 #include "ns3/icmpv6-l4-protocol.h"
49 #include "ns3/udp-l4-protocol.h"
50 #include "ns3/tcp-l4-protocol.h"
51 #include "ns3/ipv4-list-routing.h"
52 #include "ns3/ipv4-static-routing.h"
53 #include "ns3/ipv6-list-routing.h"
54 #include "ns3/ipv6-static-routing.h"
55 #include "ns3/ipv6-address-helper.h"
67 virtual void DoRun (
void);
80 uint32_t availableData;
101 Simulator::Destroy ();
109 virtual void DoRun (
void);
122 uint32_t availableData;
128 (void) availableData;
134 Ptr<Node> rxNode = CreateObject<Node> ();
146 Simulator::Destroy ();
163 virtual void DoRun (
void);
172 :
TestCase (
"UDP socket implementation")
178 uint32_t availableData;
186 uint32_t availableData;
210 return static_cast<uint32_t
> (priorityTag.
GetPriority ());
251 Ptr<Node> rxNode = CreateObject<Node> ();
253 Ptr<Node> txNode = CreateObject<Node> ();
280 ipv4->
SetUp (netdev_idx);
285 ipv4->
SetUp (netdev_idx);
292 ipv4->
SetUp (netdev_idx);
297 ipv4->
SetUp (netdev_idx);
351 txSocket->BindToNetDevice (net1.
Get (1));
353 NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 0,
"first socket should not receive it (it is bound specifically to the second interface's address");
356 m_receivedPacket->RemoveAllByteTags ();
362 int err = txSocket->GetPeerName (peerAddress);
364 NS_TEST_EXPECT_MSG_EQ (txSocket->GetErrno (), Socket::ERROR_NOTCONN,
"socket error code should be ERROR_NOTCONN");
367 err = txSocket->Connect (peer);
370 err = txSocket->GetPeerName (peerAddress);
372 NS_TEST_EXPECT_MSG_EQ (peerAddress, peer,
"address from socket GetPeerName() should equal the connected address");
374 m_receivedPacket->RemoveAllByteTags ();
383 txSocket->SetIpTos (0x28);
384 txSocket->SetPriority (6);
394 m_receivedPacket->RemoveAllByteTags ();
407 m_receivedPacket->RemoveAllByteTags ();
409 Simulator::Destroy ();
421 virtual void DoRun (
void);
431 :
TestCase (
"UDP6 socket implementation")
447 uint32_t availableData;
453 (void) availableData;
458 uint32_t availableData;
464 (void) availableData;
491 Ptr<Node> rxNode = CreateObject<Node> ();
493 Ptr<Node> txNode = CreateObject<Node> ();
521 device = net1.
Get (0);
525 ipv6->
SetUp (ifIndex);
527 device = net2.
Get (0);
531 ipv6->
SetUp (ifIndex);
534 device = net1.
Get (1);
538 ipv6->
SetUp (ifIndex);
540 device = net2.
Get (1);
544 ipv6->
SetUp (ifIndex);
562 SendData (txSocket,
"2001:0100::1");
579 txSocket->BindToNetDevice (net1.
Get (1));
589 int err = txSocket->GetPeerName (peerAddress);
591 NS_TEST_EXPECT_MSG_EQ (txSocket->GetErrno (), Socket::ERROR_NOTCONN,
"socket error code should be ERROR_NOTCONN");
594 err = txSocket->Connect (peer);
597 err = txSocket->GetPeerName (peerAddress);
599 NS_TEST_EXPECT_MSG_EQ (peerAddress, peer,
"address from socket GetPeerName() should equal the connected address");
601 Simulator::Destroy ();
void Dispose(void)
Dispose of this Object.
void ReceivePkt(Ptr< Socket > socket)
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
AttributeValue implementation for Boolean.
QueueDiscContainer Install(NetDeviceContainer c)
Keep track of a set of IPv6 interfaces.
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
virtual void DoRun(void)
Implementation to actually run this TestCase.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Access to the IPv6 forwarding table, interfaces, and configuration.
virtual bool SetAllowBroadcast(bool allowBroadcast)=0
Configure whether broadcast datagram transmissions are allowed.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
a class to represent an Ipv4 address mask
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
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.
virtual void DoRun(void)
Implementation to actually run this TestCase.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
virtual Ptr< Socket > CreateSocket(void)=0
This test suite implements a Unit Test.
Ptr< Packet > m_receivedPacket2
void SentPkt(Ptr< const QueueItem > item)
a polymophic address class
Holds a vector of ns3::QueueDisc pointers.
void SendData(Ptr< Socket > socket)
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Ptr< QueueDisc > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
void ReceivePkt(Ptr< Socket > socket)
void ReceivePacket2(Ptr< Socket > socket, Ptr< Packet > packet, const Address &from)
Ptr< Packet > m_receivedPacket
Ptr< Packet > m_receivedPacket
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
virtual void SetUp(uint32_t interface)=0
const Ipv4Header & GetHeader(void) const
holds a vector of ns3::NetDevice pointers
indicates whether the socket has a priority set.
An implementation of the ICMPv6 protocol.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Build a set of QueueDisc objects.
void SetRecvCallback(Callback< void, Ptr< Socket > >)
Notify application when new data is available to be read.
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
void ReceivePkt2(Ptr< Socket > socket)
Access to the IPv4 forwarding table, interfaces, and configuration.
void ReceivePkt2(Ptr< Socket > socket)
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
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.
keep track of a set of node pointers.
void DoSendData(Ptr< Socket > socket)
void SendDataTo(Ptr< Socket > socket, std::string to)
void DoSendData(Ptr< Socket > socket, std::string to)
virtual Ptr< Packet > Recv(uint32_t maxSize, uint32_t flags)=0
Read data from the socket.
void SetNetDevicePointToPointMode(bool pointToPointMode)
SimpleNetDevice is Broadcast capable and ARP needing.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
#define NS_TEST_EXPECT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report if not.
uint8_t GetPriority(void) const
Get the tag's priority.
void ReceivePkt(Ptr< Socket > socket)
void DoSendDataTo(Ptr< Socket > socket, std::string to)
Helper class to auto-assign global IPv6 unicast addresses.
UdpTestSuite g_udpTestSuite
Ptr< Packet > m_receivedPacket2
void SendData(Ptr< Socket > socket, std::string to)
Describes an IPv6 address.
Ipv4 addresses are stored in host order in this class.
uint32_t GetId(void) const
a class to store IPv4 address information on an interface
virtual Ptr< Node > GetNode(void) const =0
Return the node this socket is associated with.
void ReceivePkt(Ptr< Socket > socket)
Time Seconds(double value)
Construct a Time in the indicated unit.
void RemoveAllByteTags(void)
Remove all byte tags stored in this packet.
Ptr< Packet > m_receivedPacket
Ptr< Packet > m_receivedPacket
Describes an IPv6 prefix.
virtual bool AddAddress(uint32_t interface, Ipv4InterfaceAddress address)=0
virtual bool AddAddress(uint32_t interface, Ipv6InterfaceAddress address)=0
Add an address on the specified IPv6 interface.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
Send data to a specified peer.
void ReceivePacket(Ptr< Socket > socket, Ptr< Packet > packet, const Address &from)
uint32_t GetPriority(void)
API to create UDP socket instances.
build a set of SimpleNetDevice objects
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
Ptr< Ipv4QueueDiscItem > m_sentPacket
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual int32_t GetInterfaceForDevice(Ptr< const NetDevice > device) const =0
Get the interface index of the specified NetDevice.
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual void SetUp(uint32_t interface)=0
Set the interface into the "up" state.
virtual uint32_t GetRxAvailable(void) const =0
Return number of bytes which can be returned from one or multiple calls to Recv.
Ptr< Packet > GetPacket(void) const