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/drop-tail-queue.h"
32 #include "ns3/socket.h"
36 #include "ns3/inet-socket-address.h"
37 #include "ns3/inet6-socket-address.h"
39 #include "ns3/arp-l3-protocol.h"
40 #include "ns3/ipv4-l3-protocol.h"
41 #include "ns3/ipv6-l3-protocol.h"
42 #include "ns3/icmpv4-l4-protocol.h"
43 #include "ns3/icmpv6-l4-protocol.h"
44 #include "ns3/udp-l4-protocol.h"
45 #include "ns3/tcp-l4-protocol.h"
46 #include "ns3/ipv4-list-routing.h"
47 #include "ns3/ipv4-static-routing.h"
48 #include "ns3/ipv6-list-routing.h"
49 #include "ns3/ipv6-static-routing.h"
68 ipv4Routing->AddRoutingProtocol (ipv4staticRouting, 0);
90 ipv6Routing->AddRoutingProtocol (ipv6staticRouting, 0);
111 virtual void DoRun (
void);
124 uint32_t availableData;
133 Ptr<Node> rxNode = CreateObject<Node> ();
144 Simulator::Destroy ();
152 virtual void DoRun (
void);
165 uint32_t availableData;
171 (void) availableData;
177 Ptr<Node> rxNode = CreateObject<Node> ();
188 Simulator::Destroy ();
200 virtual void DoRun (
void);
210 :
TestCase (
"UDP socket implementation")
226 uint32_t availableData;
234 uint32_t availableData;
253 Simulator::ScheduleWithContext (socket->
GetNode ()->
GetId (), Seconds (0),
264 Ptr<Node> rxNode = CreateObject<Node> ();
268 rxDev1 = CreateObject<SimpleNetDevice> ();
269 rxDev1->
SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
275 ipv4->
SetUp (netdev_idx);
279 rxDev2 = CreateObject<SimpleNetDevice> ();
280 rxDev2->
SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
286 ipv4->
SetUp (netdev_idx);
290 Ptr<Node> txNode = CreateObject<Node> ();
294 txDev1 = CreateObject<SimpleNetDevice> ();
295 txDev1->
SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
301 ipv4->
SetUp (netdev_idx);
305 txDev2 = CreateObject<SimpleNetDevice> ();
306 txDev2->
SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
312 ipv4->
SetUp (netdev_idx);
351 SendData (txSocket,
"255.255.255.255");
368 SendData (txSocket,
"255.255.255.255");
377 txSocket->BindToNetDevice (txDev1);
379 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");
382 m_receivedPacket->RemoveAllByteTags ();
385 Simulator::Destroy ();
397 virtual void DoRun (
void);
407 :
TestCase (
"UDP6 socket implementation")
423 uint32_t availableData;
429 (void) availableData;
434 uint32_t availableData;
440 (void) availableData;
456 Simulator::ScheduleWithContext (socket->
GetNode ()->
GetId (), Seconds (0),
467 Ptr<Node> rxNode = CreateObject<Node> ();
471 rxDev1 = CreateObject<SimpleNetDevice> ();
472 rxDev1->
SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
478 ipv6->
SetUp (netdev_idx);
481 rxDev2 = CreateObject<SimpleNetDevice> ();
482 rxDev2->
SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
488 ipv6->
SetUp (netdev_idx);
492 Ptr<Node> txNode = CreateObject<Node> ();
496 txDev1 = CreateObject<SimpleNetDevice> ();
497 txDev1->
SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
503 ipv6->
SetUp (netdev_idx);
507 txDev2 = CreateObject<SimpleNetDevice> ();
508 txDev2->
SetAddress (Mac48Address::ConvertFrom (Mac48Address::Allocate ()));
514 ipv6->
SetUp (netdev_idx);
543 SendData (txSocket,
"2001:0100::1");
560 txSocket->BindToNetDevice (txDev1);
568 Simulator::Destroy ();
void ReceivePkt(Ptr< Socket > socket)
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
static void AddInternetStack6(Ptr< Node > node)
virtual void DoRun(void)
Implementation to actually run this TestCase.
Access to the IPv6 forwarding table, interfaces, and configuration.
virtual bool SetAllowBroadcast(bool allowBroadcast)=0
Configure whether broadcast datagram transmissions are allowed.
a class to represent an Ipv4 address mask
#define NS_ASSERT(condition)
IPv6 address associated with an interface.
virtual void DoRun(void)
Implementation to actually run this TestCase.
uint32_t GetSize(void) const
virtual Ptr< Socket > CreateSocket(void)=0
static void AddInternetStack(Ptr< Node > node)
Ptr< Packet > m_receivedPacket2
a polymophic address class
void DoSendData(Ptr< Socket > socket, std::string to)
void SendData(Ptr< Socket > socket, std::string to)
void ReceivePkt(Ptr< Socket > socket)
void ReceivePacket2(Ptr< Socket > socket, Ptr< Packet > packet, const Address &from)
Ptr< Packet > m_receivedPacket
Ptr< Packet > m_receivedPacket
virtual void SetUp(uint32_t interface)=0
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
void ReceivePacket(Ptr< Socket > socket, Ptr< Packet > packet, const Address &from)
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.
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 AggregateObject(Ptr< Object > other)
void ReceivePkt2(Ptr< Socket > socket)
Access to the Ipv4 forwarding table, interfaces, and configuration.
void ReceivePkt2(Ptr< Socket > socket)
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
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 AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
void ReceivePacket2(Ptr< Socket > socket, Ptr< Packet > packet, const Address &from)
void ReceivePkt(Ptr< Socket > socket)
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
Add a NetDevice interface.
UdpTestSuite g_udpTestSuite
Ptr< Packet > m_receivedPacket2
void SendData(Ptr< Socket > socket, std::string to)
virtual void RegisterExtensions()
Register the IPv6 Extensions.
Describes an IPv6 address.
Ipv4 addresses are stored in host order in this class.
void SetRoutingProtocol(Ptr< Ipv6RoutingProtocol > routingProtocol)
Set routing protocol for this stack.
uint32_t AddDevice(Ptr< NetDevice > device)
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)
virtual void SetAddress(Address address)
Set the address of this interface.
void RemoveAllByteTags(void)
Remove all byte tags stored in this packet.
Ptr< Packet > m_receivedPacket
Ptr< Packet > m_receivedPacket
virtual void RegisterOptions()
Register the IPv6 Options.
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)
API to create UDP socket instances.
This test suite implements a Unit Test.
void SetChannel(Ptr< SimpleChannel > channel)
Attach a channel to this net device.
Ptr< T > GetObject(void) const
virtual void DoRun(void)
Implementation to actually run this TestCase.
void Dispose(void)
Run the DoDispose methods of this object and all the objects aggregated to it.
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.
void SetRoutingProtocol(Ptr< Ipv4RoutingProtocol > routingProtocol)
Register a new routing protocol to be used by this Ipv4 stack.