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);
117 UdpSocketLoopbackTest::UdpSocketLoopbackTest ()
122 void UdpSocketLoopbackTest::ReceivePkt (
Ptr<Socket> socket)
124 uint32_t availableData;
126 m_receivedPacket = socket->
Recv (std::numeric_limits<uint32_t>::max (), 0);
133 Ptr<Node> rxNode = CreateObject<Node> ();
134 AddInternetStack (rxNode);
139 rxSocket->SetRecvCallback (
MakeCallback (&UdpSocketLoopbackTest::ReceivePkt,
this));
144 Simulator::Destroy ();
145 NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->
GetSize (), 246,
"first socket should not receive it (it is bound specifically to the second interface's address");
152 virtual void DoRun (
void);
158 Udp6SocketLoopbackTest::Udp6SocketLoopbackTest ()
163 void Udp6SocketLoopbackTest::ReceivePkt (
Ptr<Socket> socket)
165 uint32_t availableData;
167 m_receivedPacket = socket->
Recv (std::numeric_limits<uint32_t>::max (), 0);
171 (void) availableData;
177 Ptr<Node> rxNode = CreateObject<Node> ();
178 AddInternetStack6 (rxNode);
183 rxSocket->SetRecvCallback (
MakeCallback (&Udp6SocketLoopbackTest::ReceivePkt,
this));
188 Simulator::Destroy ();
189 NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->
GetSize (), 246,
"first socket should not receive it (it is bound specifically to the second interface's address");
196 void DoSendData (
Ptr<Socket> socket, std::string to);
197 void SendData (
Ptr<Socket> socket, std::string to);
200 virtual void DoRun (
void);
209 UdpSocketImplTest::UdpSocketImplTest ()
210 :
TestCase (
"UDP socket implementation")
216 m_receivedPacket = packet;
221 m_receivedPacket2 = packet;
224 void UdpSocketImplTest::ReceivePkt (
Ptr<Socket> socket)
226 uint32_t availableData;
228 m_receivedPacket = socket->
Recv (std::numeric_limits<uint32_t>::max (), 0);
232 void UdpSocketImplTest::ReceivePkt2 (
Ptr<Socket> socket)
234 uint32_t availableData;
236 m_receivedPacket2 = socket->
Recv (std::numeric_limits<uint32_t>::max (), 0);
241 UdpSocketImplTest::DoSendData (
Ptr<Socket> socket, std::string to)
244 NS_TEST_EXPECT_MSG_EQ (socket->
SendTo (Create<Packet> (123), 0, realTo),
249 UdpSocketImplTest::SendData (
Ptr<Socket> socket, std::string to)
251 m_receivedPacket = Create<Packet> ();
252 m_receivedPacket2 = Create<Packet> ();
254 &UdpSocketImplTest::DoSendData,
this, socket, to);
264 Ptr<Node> rxNode = CreateObject<Node> ();
265 AddInternetStack (rxNode);
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> ();
291 AddInternetStack (txNode);
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);
317 rxDev1->SetChannel (channel1);
318 txDev1->SetChannel (channel1);
321 rxDev2->SetChannel (channel2);
322 txDev2->SetChannel (channel2);
329 rxSocket->SetRecvCallback (
MakeCallback (&UdpSocketImplTest::ReceivePkt,
this));
342 SendData (txSocket,
"10.0.0.1");
343 NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->
GetSize (), 123,
"trivial");
344 NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 0,
"second interface should receive it");
347 m_receivedPacket2->RemoveAllByteTags ();
351 SendData (txSocket,
"255.255.255.255");
352 NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->
GetSize (), 123,
"trivial");
353 NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 0,
"second socket should not receive it (it is bound specifically to the second interface's address");
356 m_receivedPacket2->RemoveAllByteTags ();
368 SendData (txSocket,
"255.255.255.255");
369 NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->
GetSize (), 123,
"trivial");
370 NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 123,
"trivial");
372 m_receivedPacket = 0;
373 m_receivedPacket2 = 0;
377 txSocket->BindToNetDevice (txDev1);
378 SendData (txSocket,
"224.0.0.9");
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");
380 NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 123,
"recv2: 224.0.0.9");
382 m_receivedPacket->RemoveAllByteTags ();
383 m_receivedPacket2->RemoveAllByteTags ();
385 Simulator::Destroy ();
393 void DoSendData (
Ptr<Socket> socket, std::string to);
394 void SendData (
Ptr<Socket> socket, std::string to);
397 virtual void DoRun (
void);
406 Udp6SocketImplTest::Udp6SocketImplTest ()
407 :
TestCase (
"UDP6 socket implementation")
413 m_receivedPacket = packet;
418 m_receivedPacket2 = packet;
421 void Udp6SocketImplTest::ReceivePkt (
Ptr<Socket> socket)
423 uint32_t availableData;
425 m_receivedPacket = socket->
Recv (std::numeric_limits<uint32_t>::max (), 0);
429 (void) availableData;
432 void Udp6SocketImplTest::ReceivePkt2 (
Ptr<Socket> socket)
434 uint32_t availableData;
436 m_receivedPacket2 = socket->
Recv (std::numeric_limits<uint32_t>::max (), 0);
437 NS_ASSERT (availableData == m_receivedPacket2->GetSize ());
440 (void) availableData;
444 Udp6SocketImplTest::DoSendData (
Ptr<Socket> socket, std::string to)
447 NS_TEST_EXPECT_MSG_EQ (socket->
SendTo (Create<Packet> (123), 0, realTo),
452 Udp6SocketImplTest::SendData (
Ptr<Socket> socket, std::string to)
454 m_receivedPacket = Create<Packet> ();
455 m_receivedPacket2 = Create<Packet> ();
457 &Udp6SocketImplTest::DoSendData,
this, socket, to);
467 Ptr<Node> rxNode = CreateObject<Node> ();
468 AddInternetStack6 (rxNode);
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> ();
493 AddInternetStack6 (txNode);
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);
519 rxDev1->SetChannel (channel1);
520 txDev1->SetChannel (channel1);
523 rxDev2->SetChannel (channel2);
524 txDev2->SetChannel (channel2);
531 rxSocket->SetRecvCallback (
MakeCallback (&Udp6SocketImplTest::ReceivePkt,
this));
543 SendData (txSocket,
"2001:0100::1");
544 NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->
GetSize (), 123,
"trivial");
545 NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 0,
"second interface should receive it");
548 m_receivedPacket2->RemoveAllByteTags ();
560 txSocket->BindToNetDevice (txDev1);
561 SendData (txSocket,
"ff02::1");
562 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");
563 NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 123,
"recv2: ff02::1");
566 m_receivedPacket2->RemoveAllByteTags ();
568 Simulator::Destroy ();
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
virtual void DoRun(void)
Implementation to actually run this test case.
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 test case.
uint32_t GetSize(void) const
virtual Ptr< Socket > CreateSocket(void)=0
TestSuite(std::string name, Type type=UNIT)
Constuct a new test suite.
a polymophic address class
virtual void SetUp(uint32_t interface)=0
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)
void AggregateObject(Ptr< Object > other)
Access to the Ipv4 forwarding table, interfaces, and configuration.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
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 test case to this test suite.
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
Add a NetDevice interface.
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.
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
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
virtual void SetAddress(Address address)
void RemoveAllByteTags(void)
virtual void RegisterOptions()
Register the IPv6 Options.
Describes an IPv6 prefix. It is just a bitmask like Ipv4Mask.
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.
API to create UDP socket instances.
Ptr< T > GetObject(void) const
virtual void DoRun(void)
Implementation to actually run this test case.
virtual void DoRun(void)
Implementation to actually run this test case.
virtual void SetUp(uint32_t interface)=0
Set the interface into the "up" state.
virtual uint32_t GetRxAvailable(void) const =0
void SetRoutingProtocol(Ptr< Ipv4RoutingProtocol > routingProtocol)
Register a new routing protocol to be used by this Ipv4 stack.