From 287bda5b7e154c09b35b5d54b0312974b00574de Mon Sep 17 00:00:00 2001 From: Tommaso Pecorella Date: Sat, 6 Sep 2014 07:09:08 +0200 Subject: [PATCH] Move some tests from src/test to appropriate places --- .../test/ipv4-global-routing-test-suite.cc} | 300 +++++++++++------- .../test/ipv4-static-routing-test-suite.cc} | 123 ++++--- src/internet/wscript | 2 + .../test/mobility-test-suite.cc | 0 src/mobility/wscript | 1 + src/test/perf/perf-io.cc | 1 - src/test/perf/wscript | 2 +- src/test/wscript | 3 - 8 files changed, 255 insertions(+), 177 deletions(-) rename src/{test/global-routing-test-suite.cc => internet/test/ipv4-global-routing-test-suite.cc} (51%) rename src/{test/static-routing-test-suite.cc => internet/test/ipv4-static-routing-test-suite.cc} (54%) rename src/{ => mobility}/test/mobility-test-suite.cc (100%) diff --git a/src/test/global-routing-test-suite.cc b/src/internet/test/ipv4-global-routing-test-suite.cc similarity index 51% rename from src/test/global-routing-test-suite.cc rename to src/internet/test/ipv4-global-routing-test-suite.cc index 047e0d9e6..a85a7345a 100644 --- a/src/test/global-routing-test-suite.cc +++ b/src/internet/test/ipv4-global-routing-test-suite.cc @@ -17,9 +17,6 @@ #include #include "ns3/boolean.h" #include "ns3/config.h" -#include "ns3/csma-helper.h" -#include "ns3/flow-monitor.h" -#include "ns3/flow-monitor-helper.h" #include "ns3/inet-socket-address.h" #include "ns3/internet-stack-helper.h" #include "ns3/ipv4-address-helper.h" @@ -27,53 +24,69 @@ #include "ns3/ipv4-static-routing-helper.h" #include "ns3/node.h" #include "ns3/node-container.h" -#include "ns3/on-off-helper.h" #include "ns3/packet.h" -#include "ns3/packet-sink-helper.h" -#include "ns3/packet-sink.h" -#include "ns3/packet-socket-helper.h" -#include "ns3/packet-socket-address.h" -#include "ns3/csma-net-device.h" -#include "ns3/point-to-point-helper.h" +#include "ns3/simple-net-device-helper.h" #include "ns3/pointer.h" -#include "ns3/simple-channel.h" #include "ns3/simulator.h" #include "ns3/string.h" #include "ns3/test.h" #include "ns3/uinteger.h" #include "ns3/ipv4-packet-info-tag.h" +#include "ns3/simple-net-device.h" +#include "ns3/simple-channel.h" +#include "ns3/socket-factory.h" +#include "ns3/udp-socket-factory.h" using namespace ns3; -class DynamicGlobalRoutingTestCase : public TestCase +class Ipv4DynamicGlobalRoutingTestCase : public TestCase { public: - DynamicGlobalRoutingTestCase (); - virtual ~DynamicGlobalRoutingTestCase (); + Ipv4DynamicGlobalRoutingTestCase (); + virtual ~Ipv4DynamicGlobalRoutingTestCase (); private: + void SendData (uint8_t index); + void ShutDownSock (uint8_t index); void SinkRx (std::string path, Ptr p, const Address &address); void HandleRead (Ptr); virtual void DoRun (void); + int m_count; + std::vector, bool> > m_sendSocks; + DataRate m_dataRate; + uint16_t m_packetSize; std::vector m_firstInterface; std::vector m_secondInterface; }; // Add some help text to this case to describe what it is intended to test -DynamicGlobalRoutingTestCase::DynamicGlobalRoutingTestCase () +Ipv4DynamicGlobalRoutingTestCase::Ipv4DynamicGlobalRoutingTestCase () : TestCase ("Dynamic global routing example"), m_count (0) { m_firstInterface.resize (16); m_secondInterface.resize (16); + m_dataRate = DataRate ("2kbps"); + m_packetSize = 50; } -DynamicGlobalRoutingTestCase::~DynamicGlobalRoutingTestCase () +Ipv4DynamicGlobalRoutingTestCase::~Ipv4DynamicGlobalRoutingTestCase () { + std::vector, bool> >::iterator iter; + + for (iter = m_sendSocks.begin (); iter != m_sendSocks.end (); iter++) + { + if (iter->second) + { + iter->second = false; + iter->first->Close (); + iter->first = 0; + } + } } void -DynamicGlobalRoutingTestCase::SinkRx (std::string path, Ptr p, const Address& address) +Ipv4DynamicGlobalRoutingTestCase::SinkRx (std::string path, Ptr p, const Address& address) { Ipv4PacketInfoTag tag; bool found; @@ -88,7 +101,7 @@ DynamicGlobalRoutingTestCase::SinkRx (std::string path, Ptr p, con } void -DynamicGlobalRoutingTestCase::HandleRead (Ptr socket) +Ipv4DynamicGlobalRoutingTestCase::HandleRead (Ptr socket) { Ptr packet; Address from; @@ -117,6 +130,28 @@ DynamicGlobalRoutingTestCase::HandleRead (Ptr socket) } } +void +Ipv4DynamicGlobalRoutingTestCase::SendData (uint8_t index) +{ + if (m_sendSocks[index].second == false) + { + return; + } + Ptr packet = Create (m_packetSize); + m_sendSocks[index].first->Send (packet); + + Time tNext (Seconds (m_packetSize * 8 / static_cast (m_dataRate.GetBitRate ()))); + Simulator::Schedule (tNext, &Ipv4DynamicGlobalRoutingTestCase::SendData, this, index); +} + +void +Ipv4DynamicGlobalRoutingTestCase::ShutDownSock (uint8_t index) +{ + m_sendSocks[index].second = false; + m_sendSocks[index].first->Close (); + m_sendSocks[index].first = 0; +} + // Test derived from examples/routing/dynamic-global-routing.cc // // Network topology @@ -137,7 +172,7 @@ DynamicGlobalRoutingTestCase::HandleRead (Ptr socket) // facing n1 receives packets at times (2-4), (6-8), (12-13) // void -DynamicGlobalRoutingTestCase::DoRun (void) +Ipv4DynamicGlobalRoutingTestCase::DoRun (void) { // The below value configures the default behavior of global routing. // By default, it is disabled. To respond to interface events, set to true @@ -155,23 +190,16 @@ DynamicGlobalRoutingTestCase::DoRun (void) internet.Install (c); // We create the channels first without any IP addressing information - PointToPointHelper p2p; - p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); - p2p.SetChannelAttribute ("Delay", StringValue ("2ms")); - NetDeviceContainer d0d2 = p2p.Install (n0n2); - NetDeviceContainer d1d6 = p2p.Install (n1n6); + SimpleNetDeviceHelper devHelper; - NetDeviceContainer d1d2 = p2p.Install (n1n2); + devHelper.SetNetDevicePointToPointMode (true); + NetDeviceContainer d0d2 = devHelper.Install (n0n2); + devHelper.SetNetDevicePointToPointMode (false); - p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps")); - p2p.SetChannelAttribute ("Delay", StringValue ("10ms")); - NetDeviceContainer d5d6 = p2p.Install (n5n6); - - // We create the channels first without any IP addressing information - CsmaHelper csma; - csma.SetChannelAttribute ("DataRate", StringValue ("5Mbps")); - csma.SetChannelAttribute ("Delay", StringValue ("2ms")); - NetDeviceContainer d2345 = csma.Install (n2345); + NetDeviceContainer d1d6 = devHelper.Install (n1n6); + NetDeviceContainer d1d2 = devHelper.Install (n1n2); + NetDeviceContainer d5d6 = devHelper.Install (n5n6); + NetDeviceContainer d2345 = devHelper.Install (n2345); // Later, we add IP addresses. Ipv4AddressHelper ipv4; @@ -194,40 +222,38 @@ DynamicGlobalRoutingTestCase::DoRun (void) // tables in the nodes. Ipv4GlobalRoutingHelper::PopulateRoutingTables (); - // Create the OnOff application to send UDP datagrams of size - // 210 bytes at a rate of 448 Kb/s + // Create the applications to send UDP datagrams of size + // 50 bytes at a rate of 2 Kb/s + TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); uint16_t port = 9; // Discard port (RFC 863) - OnOffHelper onoff ("ns3::UdpSocketFactory", - InetSocketAddress (i5i6.GetAddress (1), port)); - onoff.SetConstantRate (DataRate ("2kbps")); - onoff.SetAttribute ("PacketSize", UintegerValue (50)); - ApplicationContainer apps = onoff.Install (c.Get (1)); - apps.Start (Seconds (1.0)); - apps.Stop (Seconds (10.0)); + std::pair, bool> sendSockA; + sendSockA.first = Socket::CreateSocket (c.Get (1), tid); + sendSockA.first->Bind (); + sendSockA.first->Connect (InetSocketAddress (i5i6.GetAddress (1), port)); + sendSockA.second = true; + m_sendSocks.push_back (sendSockA); + Simulator::Schedule (Seconds (1.0), &Ipv4DynamicGlobalRoutingTestCase::SendData, this, 0); + Simulator::Schedule (Seconds (10.0), &Ipv4DynamicGlobalRoutingTestCase::ShutDownSock, this, 0); - // Create a second OnOff application to send UDP datagrams of size - // 210 bytes at a rate of 448 Kb/s - OnOffHelper onoff2 ("ns3::UdpSocketFactory", - InetSocketAddress (i1i6.GetAddress (1), port)); - onoff2.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]")); - onoff2.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]")); - onoff2.SetAttribute ("DataRate", StringValue ("2kbps")); - onoff2.SetAttribute ("PacketSize", UintegerValue (50)); + std::pair, bool> sendSockB; + sendSockB.first = Socket::CreateSocket (c.Get (1), tid); + sendSockB.first->Bind (); + sendSockB.first->Connect (InetSocketAddress (i1i6.GetAddress (1), port)); + sendSockB.second = true; + m_sendSocks.push_back (sendSockB); + Simulator::Schedule (Seconds (11.0), &Ipv4DynamicGlobalRoutingTestCase::SendData, this, 1); + Simulator::Schedule (Seconds (16.0), &Ipv4DynamicGlobalRoutingTestCase::ShutDownSock, this, 1); - ApplicationContainer apps2 = onoff2.Install (c.Get (1)); - apps2.Start (Seconds (11.0)); - apps2.Stop (Seconds (16.0)); // Create an optional packet sink to receive these packets - TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); Ptr sink2 = Socket::CreateSocket (c.Get (6), tid); sink2->Bind (Address (InetSocketAddress (Ipv4Address::GetAny (), port))); sink2->Listen (); sink2->ShutdownSend (); sink2->SetRecvPktInfo (true); - sink2->SetRecvCallback (MakeCallback (&DynamicGlobalRoutingTestCase::HandleRead, this)); + sink2->SetRecvCallback (MakeCallback (&Ipv4DynamicGlobalRoutingTestCase::HandleRead, this)); Ptr n1 = c.Get (1); Ptr ipv41 = n1->GetObject (); @@ -237,72 +263,107 @@ DynamicGlobalRoutingTestCase::DoRun (void) // Trace receptions Config::Connect ("/NodeList/6/ApplicationList/*/$ns3::PacketSink/Rx", - MakeCallback (&DynamicGlobalRoutingTestCase::SinkRx, this)); + MakeCallback (&Ipv4DynamicGlobalRoutingTestCase::SinkRx, this)); - Simulator::Schedule (Seconds (2),&Ipv4::SetDown,ipv41, ipv4ifIndex1); - Simulator::Schedule (Seconds (4),&Ipv4::SetUp,ipv41, ipv4ifIndex1); + Simulator::Schedule (Seconds (2), &Ipv4::SetDown,ipv41, ipv4ifIndex1); + Simulator::Schedule (Seconds (4), &Ipv4::SetUp,ipv41, ipv4ifIndex1); Ptr n6 = c.Get (6); Ptr ipv46 = n6->GetObject (); // The first ifIndex is 0 for loopback, then the first p2p is numbered 1, // then the next p2p is numbered 2 uint32_t ipv4ifIndex6 = 2; - Simulator::Schedule (Seconds (6),&Ipv4::SetDown,ipv46, ipv4ifIndex6); - Simulator::Schedule (Seconds (8),&Ipv4::SetUp,ipv46, ipv4ifIndex6); + Simulator::Schedule (Seconds (6), &Ipv4::SetDown,ipv46, ipv4ifIndex6); + Simulator::Schedule (Seconds (8), &Ipv4::SetUp,ipv46, ipv4ifIndex6); - Simulator::Schedule (Seconds (12),&Ipv4::SetDown,ipv41, ipv4ifIndex1); - Simulator::Schedule (Seconds (14),&Ipv4::SetUp,ipv41, ipv4ifIndex1); + Simulator::Schedule (Seconds (12), &Ipv4::SetDown,ipv41, ipv4ifIndex1); + Simulator::Schedule (Seconds (14), &Ipv4::SetUp,ipv41, ipv4ifIndex1); Simulator::Run (); - NS_TEST_ASSERT_MSG_EQ (m_count, 68, "Dynamic global routing did not deliver all packets"); + NS_TEST_ASSERT_MSG_EQ (m_count, 70, "Dynamic global routing did not deliver all packets"); // Test that for node n6, the interface facing n5 receives packets at // times (1-2), (4-6), (8-10), (11-12), (14-16) and the interface // facing n1 receives packets at times (2-4), (6-8), (12-13) - NS_TEST_ASSERT_MSG_EQ (m_firstInterface[1], 4, "Dynamic global routing did not deliver all packets"); - NS_TEST_ASSERT_MSG_EQ (m_secondInterface[2], 5, "Dynamic global routing did not deliver all packets"); - NS_TEST_ASSERT_MSG_EQ (m_secondInterface[3], 5, "Dynamic global routing did not deliver all packets"); - NS_TEST_ASSERT_MSG_EQ (m_firstInterface[4], 5, "Dynamic global routing did not deliver all packets"); - NS_TEST_ASSERT_MSG_EQ (m_firstInterface[5], 5, "Dynamic global routing did not deliver all packets"); - NS_TEST_ASSERT_MSG_EQ (m_secondInterface[6], 5, "Dynamic global routing did not deliver all packets"); - NS_TEST_ASSERT_MSG_EQ (m_secondInterface[7], 5, "Dynamic global routing did not deliver all packets"); - NS_TEST_ASSERT_MSG_EQ (m_firstInterface[8], 5, "Dynamic global routing did not deliver all packets"); - NS_TEST_ASSERT_MSG_EQ (m_firstInterface[9], 5, "Dynamic global routing did not deliver all packets"); - NS_TEST_ASSERT_MSG_EQ (m_firstInterface[10], 0, "Dynamic global routing did not deliver all packets"); - NS_TEST_ASSERT_MSG_EQ (m_firstInterface[11], 4, "Dynamic global routing did not deliver all packets"); - NS_TEST_ASSERT_MSG_EQ (m_secondInterface[12], 5, "Dynamic global routing did not deliver all packets"); - NS_TEST_ASSERT_MSG_EQ (m_secondInterface[13], 5, "Dynamic global routing did not deliver all packets"); - NS_TEST_ASSERT_MSG_EQ (m_firstInterface[14], 5, "Dynamic global routing did not deliver all packets"); - NS_TEST_ASSERT_MSG_EQ (m_firstInterface[15], 5, "Dynamic global routing did not deliver all packets"); + NS_TEST_ASSERT_MSG_EQ (m_firstInterface[1], 5, "Dynamic global routing did not deliver all packets " << int(m_firstInterface[1])); + NS_TEST_ASSERT_MSG_EQ (m_secondInterface[2], 5, "Dynamic global routing did not deliver all packets " << int(m_secondInterface[2])); + NS_TEST_ASSERT_MSG_EQ (m_secondInterface[3], 5, "Dynamic global routing did not deliver all packets " << int(m_secondInterface[3])); + NS_TEST_ASSERT_MSG_EQ (m_firstInterface[4], 5, "Dynamic global routing did not deliver all packets " << int(m_firstInterface[4])); + NS_TEST_ASSERT_MSG_EQ (m_firstInterface[5], 5, "Dynamic global routing did not deliver all packets " << int(m_firstInterface[5])); + NS_TEST_ASSERT_MSG_EQ (m_secondInterface[6], 5, "Dynamic global routing did not deliver all packets " << int(m_secondInterface[6])); + NS_TEST_ASSERT_MSG_EQ (m_secondInterface[7], 5, "Dynamic global routing did not deliver all packets " << int(m_secondInterface[7])); + NS_TEST_ASSERT_MSG_EQ (m_firstInterface[8], 5, "Dynamic global routing did not deliver all packets " << int(m_firstInterface[8])); + NS_TEST_ASSERT_MSG_EQ (m_firstInterface[9], 5, "Dynamic global routing did not deliver all packets " << int(m_firstInterface[9])); + NS_TEST_ASSERT_MSG_EQ (m_firstInterface[10], 0, "Dynamic global routing did not deliver all packets " << int(m_firstInterface[10])); + NS_TEST_ASSERT_MSG_EQ (m_firstInterface[11], 5, "Dynamic global routing did not deliver all packets " << int(m_firstInterface[11])); + NS_TEST_ASSERT_MSG_EQ (m_secondInterface[12], 5, "Dynamic global routing did not deliver all packets " << int(m_secondInterface[12])); + NS_TEST_ASSERT_MSG_EQ (m_secondInterface[13], 5, "Dynamic global routing did not deliver all packets " << int(m_secondInterface[13])); + NS_TEST_ASSERT_MSG_EQ (m_firstInterface[14], 5, "Dynamic global routing did not deliver all packets " << int(m_firstInterface[14])); + NS_TEST_ASSERT_MSG_EQ (m_firstInterface[15], 5, "Dynamic global routing did not deliver all packets " << int(m_firstInterface[15])); Simulator::Destroy (); } -class GlobalRoutingSlash32TestCase : public TestCase +class Ipv4GlobalRoutingSlash32TestCase : public TestCase { public: - GlobalRoutingSlash32TestCase (); - virtual ~GlobalRoutingSlash32TestCase (); + Ipv4GlobalRoutingSlash32TestCase (); + virtual ~Ipv4GlobalRoutingSlash32TestCase (); + + Ptr m_receivedPacket; + void ReceivePkt (Ptr socket); + void DoSendData (Ptr socket, std::string to); + void SendData (Ptr socket, std::string to); private: virtual void DoRun (void); }; // Add some help text to this case to describe what it is intended to test -GlobalRoutingSlash32TestCase::GlobalRoutingSlash32TestCase () +Ipv4GlobalRoutingSlash32TestCase::Ipv4GlobalRoutingSlash32TestCase () : TestCase ("Slash 32 global routing example") { } -GlobalRoutingSlash32TestCase::~GlobalRoutingSlash32TestCase () +Ipv4GlobalRoutingSlash32TestCase::~Ipv4GlobalRoutingSlash32TestCase () { } +void +Ipv4GlobalRoutingSlash32TestCase::ReceivePkt (Ptr socket) +{ + uint32_t availableData; + availableData = socket->GetRxAvailable (); + m_receivedPacket = socket->Recv (std::numeric_limits::max (), 0); + NS_ASSERT (availableData == m_receivedPacket->GetSize ()); + //cast availableData to void, to suppress 'availableData' set but not used + //compiler warning + (void) availableData; +} + +void +Ipv4GlobalRoutingSlash32TestCase::DoSendData (Ptr socket, std::string to) +{ + Address realTo = InetSocketAddress (Ipv4Address (to.c_str ()), 1234); + NS_TEST_EXPECT_MSG_EQ (socket->SendTo (Create (123), 0, realTo), + 123, "100"); +} + +void +Ipv4GlobalRoutingSlash32TestCase::SendData (Ptr socket, std::string to) +{ + m_receivedPacket = Create (); + Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (60), + &Ipv4GlobalRoutingSlash32TestCase::DoSendData, this, socket, to); + Simulator::Stop (Seconds (66)); + Simulator::Run (); +} + // Test program for this 3-router scenario, using global routing // // (a.a.a.a/32)A<--x.x.x.0/30-->B<--y.y.y.0/30-->C(c.c.c.c/32) // void -GlobalRoutingSlash32TestCase::DoRun (void) +Ipv4GlobalRoutingSlash32TestCase::DoRun (void) { Ptr nA = CreateObject (); Ptr nB = CreateObject (); @@ -313,23 +374,20 @@ GlobalRoutingSlash32TestCase::DoRun (void) InternetStackHelper internet; internet.Install (c); - // Point-to-point links + // simple links NodeContainer nAnB = NodeContainer (nA, nB); NodeContainer nBnC = NodeContainer (nB, nC); - // We create the channels first without any IP addressing information - PointToPointHelper p2p; - p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); - p2p.SetChannelAttribute ("Delay", StringValue ("2ms")); - NetDeviceContainer dAdB = p2p.Install (nAnB); + SimpleNetDeviceHelper devHelper; - NetDeviceContainer dBdC = p2p.Install (nBnC);; - - Ptr deviceA = CreateObject (); + Ptr deviceA = CreateObject (); deviceA->SetAddress (Mac48Address::Allocate ()); nA->AddDevice (deviceA); - Ptr deviceC = CreateObject (); + NetDeviceContainer dAdB = devHelper.Install (nAnB); + NetDeviceContainer dBdC = devHelper.Install (nBnC); + + Ptr deviceC = CreateObject (); deviceC->SetAddress (Mac48Address::Allocate ()); nC->AddDevice (deviceC); @@ -342,17 +400,18 @@ GlobalRoutingSlash32TestCase::DoRun (void) Ipv4InterfaceContainer iBiC = ipv4.Assign (dBdC); Ptr ipv4A = nA->GetObject (); + Ptr ipv4B = nB->GetObject (); Ptr ipv4C = nC->GetObject (); int32_t ifIndexA = ipv4A->AddInterface (deviceA); int32_t ifIndexC = ipv4C->AddInterface (deviceC); - Ipv4InterfaceAddress ifInAddrA = Ipv4InterfaceAddress (Ipv4Address ("172.16.1.1"), Ipv4Mask ("255.255.255.255")); + Ipv4InterfaceAddress ifInAddrA = Ipv4InterfaceAddress (Ipv4Address ("172.16.1.1"), Ipv4Mask ("/32")); ipv4A->AddAddress (ifIndexA, ifInAddrA); ipv4A->SetMetric (ifIndexA, 1); ipv4A->SetUp (ifIndexA); - Ipv4InterfaceAddress ifInAddrC = Ipv4InterfaceAddress (Ipv4Address ("192.168.1.1"), Ipv4Mask ("255.255.255.255")); + Ipv4InterfaceAddress ifInAddrC = Ipv4InterfaceAddress (Ipv4Address ("192.168.1.1"), Ipv4Mask ("/32")); ipv4C->AddAddress (ifIndexC, ifInAddrC); ipv4C->SetMetric (ifIndexC, 1); ipv4C->SetUp (ifIndexC); @@ -361,43 +420,38 @@ GlobalRoutingSlash32TestCase::DoRun (void) // tables in the nodes. Ipv4GlobalRoutingHelper::PopulateRoutingTables (); - // Create the OnOff application to send UDP datagrams of size - // 210 bytes at a rate of 448 Kb/s - uint16_t port = 9; // Discard port (RFC 863) - OnOffHelper onoff ("ns3::UdpSocketFactory", - Address (InetSocketAddress (ifInAddrC.GetLocal (), port))); - onoff.SetConstantRate (DataRate (6000)); - ApplicationContainer apps = onoff.Install (nA); - apps.Start (Seconds (1.0)); - apps.Stop (Seconds (10.0)); + // Create the UDP sockets + Ptr rxSocketFactory = nC->GetObject (); + Ptr rxSocket = rxSocketFactory->CreateSocket (); + NS_TEST_EXPECT_MSG_EQ (rxSocket->Bind (InetSocketAddress (Ipv4Address ("192.168.1.1"), 1234)), 0, "trivial"); + rxSocket->SetRecvCallback (MakeCallback (&Ipv4GlobalRoutingSlash32TestCase::ReceivePkt, this)); - // Create a packet sink to receive these packets - PacketSinkHelper sink ("ns3::UdpSocketFactory", - Address (InetSocketAddress (Ipv4Address::GetAny (), port))); - apps = sink.Install (nC); - apps.Start (Seconds (1.0)); - apps.Stop (Seconds (10.0)); + Ptr txSocketFactory = nA->GetObject (); + Ptr txSocket = txSocketFactory->CreateSocket (); + txSocket->SetAllowBroadcast (true); + + // ------ Now the tests ------------ + + // Unicast test + SendData (txSocket, "192.168.1.1"); + NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 123, "Static routing with /32 did not deliver all packets."); - Simulator::Run (); - // Check that we received 13 * 512 = 6656 bytes - Ptr sinkPtr = DynamicCast (apps.Get (0)); - NS_TEST_ASSERT_MSG_EQ (sinkPtr->GetTotalRx (), 6656, "Static routing with /32 did not deliver all packets"); Simulator::Destroy (); } -class GlobalRoutingTestSuite : public TestSuite +class Ipv4GlobalRoutingTestSuite : public TestSuite { public: - GlobalRoutingTestSuite (); + Ipv4GlobalRoutingTestSuite (); }; -GlobalRoutingTestSuite::GlobalRoutingTestSuite () - : TestSuite ("global-routing", UNIT) +Ipv4GlobalRoutingTestSuite::Ipv4GlobalRoutingTestSuite () + : TestSuite ("ipv4-global-routing", UNIT) { - AddTestCase (new DynamicGlobalRoutingTestCase, TestCase::QUICK); - AddTestCase (new GlobalRoutingSlash32TestCase, TestCase::QUICK); + AddTestCase (new Ipv4DynamicGlobalRoutingTestCase, TestCase::QUICK); + AddTestCase (new Ipv4GlobalRoutingSlash32TestCase, TestCase::QUICK); } // Do not forget to allocate an instance of this TestSuite -static GlobalRoutingTestSuite globalRoutingTestSuite; +static Ipv4GlobalRoutingTestSuite globalRoutingTestSuite; diff --git a/src/test/static-routing-test-suite.cc b/src/internet/test/ipv4-static-routing-test-suite.cc similarity index 54% rename from src/test/static-routing-test-suite.cc rename to src/internet/test/ipv4-static-routing-test-suite.cc index e91752ebd..f94f9bad7 100644 --- a/src/test/static-routing-test-suite.cc +++ b/src/internet/test/ipv4-static-routing-test-suite.cc @@ -18,55 +18,87 @@ #include "ns3/boolean.h" #include "ns3/config.h" -#include "ns3/csma-helper.h" -#include "ns3/csma-net-device.h" #include "ns3/inet-socket-address.h" #include "ns3/internet-stack-helper.h" #include "ns3/ipv4-address-helper.h" #include "ns3/ipv4-static-routing-helper.h" #include "ns3/node.h" #include "ns3/node-container.h" -#include "ns3/on-off-helper.h" #include "ns3/packet.h" -#include "ns3/packet-sink-helper.h" -#include "ns3/packet-sink.h" -#include "ns3/packet-socket-helper.h" -#include "ns3/packet-socket-address.h" -#include "ns3/point-to-point-helper.h" #include "ns3/pointer.h" #include "ns3/simulator.h" #include "ns3/string.h" #include "ns3/test.h" #include "ns3/uinteger.h" +#include "ns3/simple-net-device.h" +#include "ns3/simple-channel.h" +#include "ns3/simple-net-device-helper.h" +#include "ns3/socket-factory.h" +#include "ns3/udp-socket-factory.h" using namespace ns3; -class StaticRoutingSlash32TestCase : public TestCase +class Ipv4StaticRoutingSlash32TestCase : public TestCase { public: - StaticRoutingSlash32TestCase (); - virtual ~StaticRoutingSlash32TestCase (); + Ipv4StaticRoutingSlash32TestCase (); + virtual ~Ipv4StaticRoutingSlash32TestCase (); + + Ptr m_receivedPacket; + void ReceivePkt (Ptr socket); + void DoSendData (Ptr socket, std::string to); + void SendData (Ptr socket, std::string to); private: virtual void DoRun (void); }; // Add some help text to this case to describe what it is intended to test -StaticRoutingSlash32TestCase::StaticRoutingSlash32TestCase () +Ipv4StaticRoutingSlash32TestCase::Ipv4StaticRoutingSlash32TestCase () : TestCase ("Slash 32 static routing example") { } -StaticRoutingSlash32TestCase::~StaticRoutingSlash32TestCase () +Ipv4StaticRoutingSlash32TestCase::~Ipv4StaticRoutingSlash32TestCase () { } +void +Ipv4StaticRoutingSlash32TestCase::ReceivePkt (Ptr socket) +{ + uint32_t availableData; + availableData = socket->GetRxAvailable (); + m_receivedPacket = socket->Recv (std::numeric_limits::max (), 0); + NS_ASSERT (availableData == m_receivedPacket->GetSize ()); + //cast availableData to void, to suppress 'availableData' set but not used + //compiler warning + (void) availableData; +} + +void +Ipv4StaticRoutingSlash32TestCase::DoSendData (Ptr socket, std::string to) +{ + Address realTo = InetSocketAddress (Ipv4Address (to.c_str ()), 1234); + NS_TEST_EXPECT_MSG_EQ (socket->SendTo (Create (123), 0, realTo), + 123, "100"); +} + +void +Ipv4StaticRoutingSlash32TestCase::SendData (Ptr socket, std::string to) +{ + m_receivedPacket = Create (); + Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (60), + &Ipv4StaticRoutingSlash32TestCase::DoSendData, this, socket, to); + Simulator::Stop (Seconds (66)); + Simulator::Run (); +} + // Test program for this 3-router scenario, using static routing // // (a.a.a.a/32)A<--x.x.x.0/30-->B<--y.y.y.0/30-->C(c.c.c.c/32) // void -StaticRoutingSlash32TestCase::DoRun (void) +Ipv4StaticRoutingSlash32TestCase::DoRun (void) { Ptr nA = CreateObject (); Ptr nB = CreateObject (); @@ -77,23 +109,20 @@ StaticRoutingSlash32TestCase::DoRun (void) InternetStackHelper internet; internet.Install (c); - // Point-to-point links + // simple links NodeContainer nAnB = NodeContainer (nA, nB); NodeContainer nBnC = NodeContainer (nB, nC); - // We create the channels first without any IP addressing information - PointToPointHelper p2p; - p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); - p2p.SetChannelAttribute ("Delay", StringValue ("2ms")); - NetDeviceContainer dAdB = p2p.Install (nAnB); + SimpleNetDeviceHelper devHelper; - NetDeviceContainer dBdC = p2p.Install (nBnC);; - - Ptr deviceA = CreateObject (); + Ptr deviceA = CreateObject (); deviceA->SetAddress (Mac48Address::Allocate ()); nA->AddDevice (deviceA); - Ptr deviceC = CreateObject (); + NetDeviceContainer dAdB = devHelper.Install (nAnB); + NetDeviceContainer dBdC = devHelper.Install (nBnC); + + Ptr deviceC = CreateObject (); deviceC->SetAddress (Mac48Address::Allocate ()); nC->AddDevice (deviceC); @@ -130,41 +159,37 @@ StaticRoutingSlash32TestCase::DoRun (void) Ptr staticRoutingB = ipv4RoutingHelper.GetStaticRouting (ipv4B); // The ifIndex we want on node B is 2; 0 corresponds to loopback, and 1 to the first point to point link staticRoutingB->AddHostRouteTo (Ipv4Address ("192.168.1.1"), Ipv4Address ("10.1.1.6"), 2); - // Create the OnOff application to send UDP datagrams of size - // 210 bytes at a rate of 448 Kb/s - uint16_t port = 9; // Discard port (RFC 863) - OnOffHelper onoff ("ns3::UdpSocketFactory", - Address (InetSocketAddress (ifInAddrC.GetLocal (), port))); - onoff.SetConstantRate (DataRate (6000)); - ApplicationContainer apps = onoff.Install (nA); - apps.Start (Seconds (1.0)); - apps.Stop (Seconds (10.0)); - // Create a packet sink to receive these packets - PacketSinkHelper sink ("ns3::UdpSocketFactory", - Address (InetSocketAddress (Ipv4Address::GetAny (), port))); - apps = sink.Install (nC); - apps.Start (Seconds (1.0)); - apps.Stop (Seconds (10.0)); + // Create the UDP sockets + Ptr rxSocketFactory = nC->GetObject (); + Ptr rxSocket = rxSocketFactory->CreateSocket (); + NS_TEST_EXPECT_MSG_EQ (rxSocket->Bind (InetSocketAddress (Ipv4Address ("192.168.1.1"), 1234)), 0, "trivial"); + rxSocket->SetRecvCallback (MakeCallback (&Ipv4StaticRoutingSlash32TestCase::ReceivePkt, this)); + + Ptr txSocketFactory = nA->GetObject (); + Ptr txSocket = txSocketFactory->CreateSocket (); + txSocket->SetAllowBroadcast (true); + + // ------ Now the tests ------------ + + // Unicast test + SendData (txSocket, "192.168.1.1"); + NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 123, "Static routing with /32 did not deliver all packets."); - Simulator::Run (); - // Check that we received 13 * 512 = 6656 bytes - Ptr sinkPtr = DynamicCast (apps.Get (0)); - NS_TEST_ASSERT_MSG_EQ (sinkPtr->GetTotalRx (), 6656, "Static routing with /32 did not deliver all packets"); Simulator::Destroy (); } -class StaticRoutingTestSuite : public TestSuite +class Ipv4StaticRoutingTestSuite : public TestSuite { public: - StaticRoutingTestSuite (); + Ipv4StaticRoutingTestSuite (); }; -StaticRoutingTestSuite::StaticRoutingTestSuite () - : TestSuite ("static-routing", UNIT) +Ipv4StaticRoutingTestSuite::Ipv4StaticRoutingTestSuite () + : TestSuite ("ipv4-static-routing", UNIT) { - AddTestCase (new StaticRoutingSlash32TestCase, TestCase::QUICK); + AddTestCase (new Ipv4StaticRoutingSlash32TestCase, TestCase::QUICK); } // Do not forget to allocate an instance of this TestSuite -static StaticRoutingTestSuite staticRoutingTestSuite; +static Ipv4StaticRoutingTestSuite ipv4StaticRoutingTestSuite; diff --git a/src/internet/wscript b/src/internet/wscript index 1a249501b..82352d736 100644 --- a/src/internet/wscript +++ b/src/internet/wscript @@ -222,6 +222,8 @@ def build(bld): 'test/ipv4-forwarding-test.cc', 'test/error-channel.cc', 'test/ipv4-test.cc', + 'test/ipv4-static-routing-test-suite.cc', + 'test/ipv4-global-routing-test-suite.cc', 'test/ipv6-extension-header-test-suite.cc', 'test/ipv6-list-routing-test-suite.cc', 'test/ipv6-packet-info-tag-test-suite.cc', diff --git a/src/test/mobility-test-suite.cc b/src/mobility/test/mobility-test-suite.cc similarity index 100% rename from src/test/mobility-test-suite.cc rename to src/mobility/test/mobility-test-suite.cc diff --git a/src/mobility/wscript b/src/mobility/wscript index 1fd153173..4575e2902 100644 --- a/src/mobility/wscript +++ b/src/mobility/wscript @@ -25,6 +25,7 @@ def build(bld): mobility_test = bld.create_ns3_module_test_library('mobility') mobility_test.source = [ + 'test/mobility-test-suite.cc', 'test/mobility-trace-test-suite.cc', 'test/ns2-mobility-helper-test-suite.cc', 'test/steady-state-random-waypoint-mobility-model-test.cc', diff --git a/src/test/perf/perf-io.cc b/src/test/perf/perf-io.cc index b7fa464e4..d15ddc23b 100644 --- a/src/test/perf/perf-io.cc +++ b/src/test/perf/perf-io.cc @@ -24,7 +24,6 @@ #include #include "ns3/core-module.h" -#include "ns3/network-module.h" #include "ns3/abort.h" using namespace ns3; diff --git a/src/test/perf/wscript b/src/test/perf/wscript index 8d0963453..cd3443a8a 100644 --- a/src/test/perf/wscript +++ b/src/test/perf/wscript @@ -4,7 +4,7 @@ def configure(conf): pass def build(bld): - obj = bld.create_ns3_program('perf-io', ['network']) + obj = bld.create_ns3_program('perf-io') obj.source = 'perf-io.cc' diff --git a/src/test/wscript b/src/test/wscript index 72b3fbfed..a44c71ed8 100644 --- a/src/test/wscript +++ b/src/test/wscript @@ -22,9 +22,6 @@ def build(bld): test_test = bld.create_ns3_module_test_library('test') test_test.source = [ 'csma-system-test-suite.cc', - 'global-routing-test-suite.cc', - 'static-routing-test-suite.cc', - 'mobility-test-suite.cc', 'ns3wifi/wifi-interference-test-suite.cc', 'ns3wifi/wifi-msdu-aggregator-test-suite.cc', 'ns3tcp/ns3tcp-cwnd-test-suite.cc',