diff -r 175c382cfab0 src/core/model/test.cc --- a/src/core/model/test.cc Sun Jun 26 13:40:27 2011 +0100 +++ b/src/core/model/test.cc Mon Jun 27 14:48:14 2011 +0200 @@ -21,6 +21,8 @@ #include "abort.h" #include +#include "ns3/simulator.h" + // Set to true to enable a segmentation fault upon a test case macro test // failing (for debugging purposes) bool gBreakOnFailure = false; @@ -395,11 +397,22 @@ void TestCase::DoSetup (void) { + /* + * Ensure a clean execution environment + */ + Simulator::Destroy(); } void TestCase::DoTeardown (void) { + /* + * Most tests will destroy their simulators when successful, + * but on failure, they tend to leave the simulator alive. + * This can be a problem for subsequent test runs, so we + * must destroy the simulator on TestCase teardown just in case. + */ + Simulator::Destroy(); } TestSuite::TestSuite (std::string name, TestType type) diff -r 175c382cfab0 src/core/model/test.h --- a/src/core/model/test.h Sun Jun 26 13:40:27 2011 +0100 +++ b/src/core/model/test.h Mon Jun 27 14:48:14 2011 +0200 @@ -753,7 +753,7 @@ actualStream << actual; \ std::ostringstream limitStream; \ limitStream << limit; \ - ReporTesttFailure (std::string (# actual) + " (actual) > " + std::string (# limit) + " (limit)", \ + ReportTestFailure (std::string (# actual) + " (actual) > " + std::string (# limit) + " (limit)", \ actualStream.str (), limitStream.str (), msgStream.str (), file, line); \ } \ } while (false) diff -r 175c382cfab0 src/energy/test/basic-energy-model-test.cc --- a/src/energy/test/basic-energy-model-test.cc Sun Jun 26 13:40:27 2011 +0100 +++ b/src/energy/test/basic-energy-model-test.cc Mon Jun 27 14:48:14 2011 +0200 @@ -217,6 +217,8 @@ private: void DoRun (void); + void DoSetup (void); + void DoTeardown (void); /** * Callback invoked when energy is drained from source. @@ -238,11 +240,13 @@ double m_simTimeS; // maximum simulation time, in seconds double m_timeStepS; // simulation time step size, in seconds double m_updateIntervalS; // update interval of each device model + std::string m_phyMode; }; BasicEnergyDepletionTest::BasicEnergyDepletionTest () : TestCase ("Basic energy model energy depletion test case") + , m_phyMode ("DsssRate1Mbps") { m_numOfNodes = 10; m_callbackCount = 0; @@ -256,6 +260,34 @@ } void +BasicEnergyDepletionTest::DoSetup (void) +{ + TestCase::DoSetup (); + + // disable fragmentation for frames below 2200 bytes + Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", + StringValue ("2200")); + // turn off RTS/CTS for frames below 2200 bytes + Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", + StringValue ("2200")); + // Fix non-unicast data rate to be the same as that of unicast + Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", + StringValue (m_phyMode)); +} + +void +BasicEnergyDepletionTest::DoTeardown (void) +{ + // Restore defaults + std::string invalidWifiMode ("Invalid-WifiMode"); + Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2346")); + Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2346")); + Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue (invalidWifiMode)); + + TestCase::DoTeardown (); +} + +void BasicEnergyDepletionTest::DoRun (void) { /* @@ -287,18 +319,6 @@ NodeContainer c; c.Create (m_numOfNodes); - std::string phyMode ("DsssRate1Mbps"); - - // disable fragmentation for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", - StringValue ("2200")); - // turn off RTS/CTS for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", - StringValue ("2200")); - // Fix non-unicast data rate to be the same as that of unicast - Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", - StringValue (phyMode)); - // install YansWifiPhy WifiHelper wifi; wifi.SetStandard (WIFI_PHY_STANDARD_80211b); @@ -319,8 +339,8 @@ // Add a non-QoS upper MAC, and disable rate control NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", - "DataMode", StringValue (phyMode), - "ControlMode", StringValue (phyMode)); + "DataMode", StringValue (m_phyMode), + "ControlMode", StringValue (m_phyMode)); // Set it to ad-hoc mode wifiMac.SetType ("ns3::AdhocWifiMac"); NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c); diff -r 175c382cfab0 src/energy/test/rv-battery-model-test.cc --- a/src/energy/test/rv-battery-model-test.cc Sun Jun 26 13:40:27 2011 +0100 +++ b/src/energy/test/rv-battery-model-test.cc Mon Jun 27 14:48:14 2011 +0200 @@ -57,13 +57,21 @@ void CreateLoadProfiles (void); /** - * \returns False if no error occurs. - * * Runs test. */ void DoRun (void); /** + * Sets up test configuration + */ + void DoSetup (void); + + /** + * Restores environment after test runs + */ + void DoTeardown (void); + + /** * \param load Load value, in Amperes (A). * \param expLifetime Expected lifetime. * \return False if no error occurs. @@ -99,14 +107,19 @@ std::vector m_loadProfiles; double m_alpha; double m_beta; + std::string m_phyMode; }; BatteryLifetimeTest::BatteryLifetimeTest () : TestCase ("RV battery model battery lifetime test case.") + , m_phyMode ("DsssRate1Mbps") { // Itsy battery m_alpha = 35220; m_beta = 0.637; + + // create load profiles for variable load test + CreateLoadProfiles (); } BatteryLifetimeTest::~BatteryLifetimeTest () @@ -638,10 +651,42 @@ } void +BatteryLifetimeTest::DoSetup (void) +{ + TestCase::DoSetup (); + + // disable fragmentation for frames below 2200 bytes + Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", + StringValue ("2200")); + // turn off RTS/CTS for frames below 2200 bytes + Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", + StringValue ("2200")); + // Fix non-unicast data rate to be the same as that of unicast + Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", + StringValue (m_phyMode)); +} + +void +BatteryLifetimeTest::DoTeardown (void) +{ + // Restore defaults + std::string invalidWifiMode ("Invalid-WifiMode"); + Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2346")); + Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2346")); + Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue (invalidWifiMode)); + + TestCase::DoTeardown (); +} + +void BatteryLifetimeTest::DoRun (void) { NS_LOG_DEBUG ("Constant load run."); + // set constant load test parameters + m_alpha = 35220; + m_beta = 0.637; + // 640mA NS_TEST_ASSERT_MSG_EQ (ConstantLoadTest (0.640, Seconds (2844.0)), false, "Problems with constant load test (640mA)."); // 320mA @@ -653,9 +698,6 @@ // 32mA NS_TEST_ASSERT_MSG_EQ (ConstantLoadTest (0.032, Seconds (65580.0)), false, "Problems with constant load test (32)."); - // create load profiles for variable load test - CreateLoadProfiles (); - // variable load with Itsy battery NS_LOG_DEBUG ("\n\nItsy"); m_alpha = 35220; @@ -696,18 +738,6 @@ NodeContainer c; c.Create (1); - std::string phyMode ("DsssRate1Mbps"); - - // disable fragmentation for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", - StringValue ("2200")); - // turn off RTS/CTS for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", - StringValue ("2200")); - // Fix non-unicast data rate to be the same as that of unicast - Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", - StringValue (phyMode)); - // install YansWifiPhy WifiHelper wifi; wifi.SetStandard (WIFI_PHY_STANDARD_80211b); @@ -728,8 +758,8 @@ // Add a non-QoS upper MAC, and disable rate control NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", - "DataMode", StringValue (phyMode), - "ControlMode", StringValue (phyMode)); + "DataMode", StringValue (m_phyMode), + "ControlMode", StringValue (m_phyMode)); // Set it to ad-hoc mode wifiMac.SetType ("ns3::AdhocWifiMac"); NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c); @@ -759,7 +789,7 @@ NS_LOG_DEBUG ("Expected lifetime = " << expLifetime.GetSeconds () << "s"); NS_LOG_DEBUG ("Actual lifetime = " << actualLifetime.GetSeconds () << "s"); - + NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL (actualLifetime, expLifetime, "Incorrect lifetime!"); /* NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL (actualLifetime.GetSeconds () / 60, @@ -783,18 +813,6 @@ NodeContainer c; c.Create (1); - std::string phyMode ("DsssRate1Mbps"); - - // disable fragmentation for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", - StringValue ("2200")); - // turn off RTS/CTS for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", - StringValue ("2200")); - // Fix non-unicast data rate to be the same as that of unicast - Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", - StringValue (phyMode)); - // install YansWifiPhy WifiHelper wifi; wifi.SetStandard (WIFI_PHY_STANDARD_80211b); @@ -815,8 +833,8 @@ // Add a non-QoS upper MAC, and disable rate control NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", - "DataMode", StringValue (phyMode), - "ControlMode", StringValue (phyMode)); + "DataMode", StringValue (m_phyMode), + "ControlMode", StringValue (m_phyMode)); // Set it to ad-hoc mode wifiMac.SetType ("ns3::AdhocWifiMac"); NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c); diff -r 175c382cfab0 src/mobility/test/ns2-mobility-helper-test-suite.cc --- a/src/mobility/test/ns2-mobility-helper-test-suite.cc Sun Jun 26 13:40:27 2011 +0100 +++ b/src/mobility/test/ns2-mobility-helper-test-suite.cc Mon Jun 27 14:48:14 2011 +0200 @@ -204,6 +204,7 @@ void DoSetup () { + Simulator::Destroy(); CreateNodes (); } diff -r 175c382cfab0 src/network/model/packet-metadata.cc --- a/src/network/model/packet-metadata.cc Sun Jun 26 13:40:27 2011 +0100 +++ b/src/network/model/packet-metadata.cc Mon Jun 27 14:48:14 2011 +0200 @@ -67,6 +67,26 @@ m_enableChecking = true; } +void +PacketMetadata::Disable (void) +{ + NS_ASSERT_MSG (!m_metadataSkipped, + "Error: attempting to enable the packet metadata " + "subsystem too late in the simulation, which is not allowed.\n" + "A common cause for this problem is to enable ASCII tracing " + "after sending any packets. One way to fix this problem is " + "to call ns3::PacketMetadata::Enable () near the beginning of" + " the program, before any packets are sent."); + m_enable = false; +} + +void +PacketMetadata::DisableChecking (void) +{ + Disable (); + m_enableChecking = false; +} + void PacketMetadata::ReserveCopy (uint32_t size) { diff -r 175c382cfab0 src/network/model/packet-metadata.h --- a/src/network/model/packet-metadata.h Sun Jun 26 13:40:27 2011 +0100 +++ b/src/network/model/packet-metadata.h Mon Jun 27 14:48:14 2011 +0200 @@ -127,6 +127,9 @@ static void Enable (void); static void EnableChecking (void); + static void Disable (void); + static void DisableChecking (void); + inline PacketMetadata (uint64_t uid, uint32_t size); inline PacketMetadata (PacketMetadata const &o); inline PacketMetadata &operator = (PacketMetadata const& o); diff -r 175c382cfab0 src/network/model/packet.cc --- a/src/network/model/packet.cc Sun Jun 26 13:40:27 2011 +0100 +++ b/src/network/model/packet.cc Mon Jun 27 14:48:14 2011 +0200 @@ -560,6 +560,20 @@ PacketMetadata::EnableChecking (); } +void +Packet::DisablePrinting (void) +{ + NS_LOG_FUNCTION_NOARGS (); + PacketMetadata::Disable (); +} + +void +Packet::DisableChecking (void) +{ + NS_LOG_FUNCTION_NOARGS (); + PacketMetadata::DisableChecking (); +} + uint32_t Packet::GetSerializedSize (void) const { uint32_t size = 0; diff -r 175c382cfab0 src/network/model/packet.h --- a/src/network/model/packet.h Sun Jun 26 13:40:27 2011 +0100 +++ b/src/network/model/packet.h Mon Jun 27 14:48:14 2011 +0200 @@ -429,6 +429,14 @@ * errors will be detected and will abort the program. */ static void EnableChecking (void); + /** + * \sa EnablePrinting + */ + static void DisablePrinting (void); + /** + * \sa EnableChecking + */ + static void DisableChecking (void); /** * For packet serializtion, the total size is checked diff -r 175c382cfab0 src/olsr/test/bug780-test.cc --- a/src/olsr/test/bug780-test.cc Sun Jun 26 13:40:27 2011 +0100 +++ b/src/olsr/test/bug780-test.cc Mon Jun 27 14:48:14 2011 +0200 @@ -75,6 +75,28 @@ } void +Bug780Test::DoSetup () +{ + TestCase::DoSetup (); + + //sending one packets per sec + // Fix non-unicast data rate to be the same as that of unicast + Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", + StringValue ("400")); +} + +void +Bug780Test::DoTeardown () +{ + //sending one packets per sec + // Fix non-unicast data rate to be the same as that of unicast + Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", + StringValue ("2346")); + + TestCase::DoTeardown (); +} + +void Bug780Test::DoRun () { SeedManager::SetSeed (123); @@ -97,11 +119,6 @@ double SimTime = 200.0; std::string phyMode ("DsssRate1Mbps"); - //sending one packets per sec - // Fix non-unicast data rate to be the same as that of unicast - Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", - StringValue ("400")); - NodeContainer adhocNodes; adhocNodes.Create (nWifis); diff -r 175c382cfab0 src/olsr/test/bug780-test.h --- a/src/olsr/test/bug780-test.h Sun Jun 26 13:40:27 2011 +0100 +++ b/src/olsr/test/bug780-test.h Mon Jun 27 14:48:14 2011 +0200 @@ -42,6 +42,8 @@ void CheckResults (); /// Go void DoRun (); + void DoSetup (); + void DoTeardown (); }; } diff -r 175c382cfab0 src/propagation/test/propagation-loss-model-test-suite.cc --- a/src/propagation/test/propagation-loss-model-test-suite.cc Sun Jun 26 13:40:27 2011 +0100 +++ b/src/propagation/test/propagation-loss-model-test-suite.cc Mon Jun 27 14:48:14 2011 +0200 @@ -42,6 +42,8 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + virtual void DoTeardown (void); typedef struct { Vector m_position; @@ -63,14 +65,33 @@ } void -FriisPropagationLossModelTestCase::DoRun (void) +FriisPropagationLossModelTestCase::DoSetup (void) { + TestCase::DoSetup (); + // The ns-3 testing manual gives more background on the values selected // for this test. First, set a few defaults. // wavelength at 2.4 GHz is 0.125m Config::SetDefault ("ns3::FriisPropagationLossModel::Lambda", DoubleValue (0.125)); Config::SetDefault ("ns3::FriisPropagationLossModel::SystemLoss", DoubleValue (1.0)); +} + +void +FriisPropagationLossModelTestCase::DoTeardown (void) +{ + // Restore defaults + Config::SetDefault ("ns3::FriisPropagationLossModel::Lambda", DoubleValue (0.0582524)); + Config::SetDefault ("ns3::FriisPropagationLossModel::SystemLoss", DoubleValue (1.0)); + + TestCase::DoTeardown (); +} + +void +FriisPropagationLossModelTestCase::DoRun (void) +{ + // The ns-3 testing manual gives more background on the values selected + // for this test. // Select a reference transmit power // Pt = 10^(17.0206/10)/10^3 = .05035702 W @@ -139,6 +160,8 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + virtual void DoTeardown (void); typedef struct { @@ -162,15 +185,32 @@ } void -TwoRayGroundPropagationLossModelTestCase::DoRun (void) +TwoRayGroundPropagationLossModelTestCase::DoSetup (void) { + TestCase::DoSetup (); + // wavelength at 2.4 GHz is 0.125m Config::SetDefault ("ns3::TwoRayGroundPropagationLossModel::Lambda", DoubleValue (0.125)); Config::SetDefault ("ns3::TwoRayGroundPropagationLossModel::SystemLoss", DoubleValue (1.0)); // set antenna height to 1.5m above z coordinate Config::SetDefault ("ns3::TwoRayGroundPropagationLossModel::HeightAboveZ", DoubleValue (1.5)); +} +void +TwoRayGroundPropagationLossModelTestCase::DoTeardown (void) +{ + TestCase::DoTeardown (); + + // Restore defaults + Config::SetDefault ("ns3::TwoRayGroundPropagationLossModel::Lambda", DoubleValue (0.0582524)); + Config::SetDefault ("ns3::TwoRayGroundPropagationLossModel::SystemLoss", DoubleValue (1.0)); + Config::SetDefault ("ns3::TwoRayGroundPropagationLossModel::HeightAboveZ", DoubleValue (0.0)); +} + +void +TwoRayGroundPropagationLossModelTestCase::DoRun (void) +{ // Select a reference transmit power of 17.0206 dBm // Pt = 10^(17.0206/10)/10^3 = .05035702 W double txPowerW = 0.05035702; @@ -267,6 +307,8 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + virtual void DoTeardown (void); typedef struct { Vector m_position; @@ -288,12 +330,28 @@ } void -LogDistancePropagationLossModelTestCase::DoRun (void) +LogDistancePropagationLossModelTestCase::DoSetup (void) { + TestCase::DoSetup (); + // reference loss at 2.4 GHz is 40.045997 Config::SetDefault ("ns3::LogDistancePropagationLossModel::ReferenceLoss", DoubleValue (40.045997)); Config::SetDefault ("ns3::LogDistancePropagationLossModel::Exponent", DoubleValue (3)); +} +void +LogDistancePropagationLossModelTestCase::DoTeardown (void) +{ + // Restore defaults + Config::SetDefault ("ns3::LogDistancePropagationLossModel::ReferenceLoss", DoubleValue (46.6777)); + Config::SetDefault ("ns3::LogDistancePropagationLossModel::Exponent", DoubleValue (3)); + + TestCase::DoTeardown (); +} + +void +LogDistancePropagationLossModelTestCase::DoRun (void) +{ // Select a reference transmit power // Pt = 10^(17.0206/10)/10^3 = .05035702 W double txPowerW = 0.05035702; @@ -402,6 +460,8 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + virtual void DoTeardown (void); }; RangePropagationLossModelTestCase::RangePropagationLossModelTestCase () @@ -414,9 +474,26 @@ } void +RangePropagationLossModelTestCase::DoSetup (void) +{ + TestCase::DoSetup (); + + // Set testcase parameters + Config::SetDefault ("ns3::RangePropagationLossModel::MaxRange", DoubleValue (127.2)); +} + +void +RangePropagationLossModelTestCase::DoTeardown (void) +{ + // Restore defaults + Config::SetDefault ("ns3::RangePropagationLossModel::MaxRange", DoubleValue (250.0)); + + TestCase::DoTeardown (); +} + +void RangePropagationLossModelTestCase::DoRun (void) { - Config::SetDefault ("ns3::RangePropagationLossModel::MaxRange", DoubleValue (127.2)); Ptr a = CreateObject (); a->SetPosition (Vector (0,0,0)); Ptr b = CreateObject (); diff -r 175c382cfab0 src/test/csma-system-test-suite.cc --- a/src/test/csma-system-test-suite.cc Sun Jun 26 13:40:27 2011 +0100 +++ b/src/test/csma-system-test-suite.cc Mon Jun 27 14:48:14 2011 +0200 @@ -165,6 +165,9 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + virtual void DoTeardown (void); + void SinkRxNode1 (Ptr p, const Address &ad); void SinkRxNode2 (Ptr p, const Address &ad); void DropEvent (Ptr p); @@ -201,6 +204,28 @@ m_drops++; } + +void +CsmaBroadcastTestCase::DoSetup () +{ + TestCase::DoSetup(); + + // + // Set up default values for the simulation. + // + // Select DIX/Ethernet II-style encapsulation (no LLC/Snap header) + Config::SetDefault ("ns3::CsmaNetDevice::EncapsulationMode", StringValue ("Dix")); +} + +void +CsmaBroadcastTestCase::DoTeardown () +{ + // Restore defaults + // NOTE: don't, Dix is the default + + TestCase::DoTeardown (); +} + // // Example of the sending of a datagram to a broadcast address // @@ -333,12 +358,6 @@ void CsmaMulticastTestCase::DoRun (void) { - // - // Set up default values for the simulation. - // - // Select DIX/Ethernet II-style encapsulation (no LLC/Snap header) - Config::SetDefault ("ns3::CsmaNetDevice::EncapsulationMode", StringValue ("Dix")); - NodeContainer c; c.Create (5); // We will later want two subcontainers of these nodes, for the two LANs diff -r 175c382cfab0 src/test/global-routing-test-suite.cc --- a/src/test/global-routing-test-suite.cc Sun Jun 26 13:40:27 2011 +0100 +++ b/src/test/global-routing-test-suite.cc Mon Jun 27 14:48:14 2011 +0200 @@ -55,7 +55,11 @@ private: void SinkRx (std::string path, Ptr p, const Address &address); void HandleRead (Ptr); + virtual void DoRun (void); + virtual void DoSetup (void); + virtual void DoTeardown (void); + int m_count; std::vector m_firstInterface; std::vector m_secondInterface; @@ -118,6 +122,25 @@ } } +void +DynamicGlobalRoutingTestCase::DoSetup () +{ + TestCase::DoSetup(); + + // The below value configures the default behavior of global routing. + // By default, it is disabled. To respond to interface events, set to true + Config::SetDefault ("ns3::Ipv4GlobalRouting::RespondToInterfaceEvents", BooleanValue (true)); +} + +void +DynamicGlobalRoutingTestCase::DoTeardown () +{ + // By default, it is disabled. Restore it. + Config::SetDefault ("ns3::Ipv4GlobalRouting::RespondToInterfaceEvents", BooleanValue (false)); + + TestCase::DoTeardown(); +} + // Test derived from examples/routing/dynamic-global-routing.cc // // Network topology @@ -140,10 +163,6 @@ void DynamicGlobalRoutingTestCase::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 - Config::SetDefault ("ns3::Ipv4GlobalRouting::RespondToInterfaceEvents", BooleanValue (true)); - NodeContainer c; c.Create (7); NodeContainer n0n2 = NodeContainer (c.Get (0), c.Get (2)); diff -r 175c382cfab0 src/test/ns3tcp/ns3tcp-cwnd-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-cwnd-test-suite.cc Sun Jun 26 13:40:27 2011 +0100 +++ b/src/test/ns3tcp/ns3tcp-cwnd-test-suite.cc Mon Jun 27 14:48:14 2011 +0200 @@ -384,6 +384,9 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + virtual void DoTeardown (void); + bool m_writeResults; class CwndEvent { @@ -419,11 +422,26 @@ } void +Ns3TcpCwndTestCase2::DoSetup (void) +{ + TestCase::DoSetup (); + + // Set up some default values for the simulation. + Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (4)); +} + +void +Ns3TcpCwndTestCase2::DoTeardown (void) +{ + // Restore defaults + Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (100)); + + TestCase::DoTeardown (); +} + +void Ns3TcpCwndTestCase2::DoRun (void) { - // Set up some default values for the simulation. - Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (4)); - NodeContainer n0n1; n0n1.Create (2); diff -r 175c382cfab0 src/test/ns3tcp/ns3tcp-loss-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-loss-test-suite.cc Sun Jun 26 13:40:27 2011 +0100 +++ b/src/test/ns3tcp/ns3tcp-loss-test-suite.cc Mon Jun 27 14:48:14 2011 +0200 @@ -115,6 +115,11 @@ void Ns3TcpLossTestCase::DoSetup (void) { + Simulator::Destroy(); + + // Enable packet metadata + Packet::EnablePrinting (); + // // We expect there to be a file called ns3tcp-state-response-vectors.pcap in // response-vectors/ of this directory @@ -133,12 +138,56 @@ m_pcapFile.Open (m_pcapFilename, std::ios::in|std::ios::binary); NS_ABORT_MSG_UNLESS (m_pcapFile.GetDataLinkType () == PCAP_LINK_TYPE, "Wrong response vectors in directory"); } + + // Config + std::ostringstream tcpModel; + tcpModel << "ns3::Tcp" << m_tcpModel; + Config::SetDefault ("ns3::TcpL4Protocol::SocketType", StringValue (tcpModel.str ())); + Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); + Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (1)); + + // Logging + if (m_writeLogging) + { + LogComponentEnableAll (LOG_PREFIX_FUNC); + LogComponentEnable ("TcpLossResponse", LOG_LEVEL_ALL); + LogComponentEnable ("ErrorModel", LOG_LEVEL_DEBUG); + LogComponentEnable ("TcpLossResponse", LOG_LEVEL_ALL); + LogComponentEnable ("TcpNewReno", LOG_LEVEL_INFO); + LogComponentEnable ("TcpReno", LOG_LEVEL_INFO); + LogComponentEnable ("TcpTahoe", LOG_LEVEL_INFO); + LogComponentEnable ("TcpSocketBase", LOG_LEVEL_INFO); + } + } void Ns3TcpLossTestCase::DoTeardown (void) { + // Restore Config + std::string tcpModel ("ns3::TcpNewReno"); + Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (536)); + Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (2)); + + // Restore Logging + if (m_writeLogging) + { + LogComponentDisableAll (LOG_PREFIX_FUNC); + LogComponentDisable ("TcpLossResponse", LOG_LEVEL_ALL); + LogComponentDisable ("ErrorModel", LOG_LEVEL_DEBUG); + LogComponentDisable ("TcpLossResponse", LOG_LEVEL_ALL); + LogComponentDisable ("TcpNewReno", LOG_LEVEL_INFO); + LogComponentDisable ("TcpReno", LOG_LEVEL_INFO); + LogComponentDisable ("TcpTahoe", LOG_LEVEL_INFO); + LogComponentDisable ("TcpSocketBase", LOG_LEVEL_INFO); + } + m_pcapFile.Close (); + + // Enable packet metadata + Packet::DisablePrinting (); + + Simulator::Destroy(); } void @@ -182,22 +231,29 @@ // file and see if it still does the right thing. // uint8_t expected[PCAP_SNAPLEN]; - uint32_t tsSec, tsUsec, inclLen, origLen, readLen; + uint32_t tsSec=0, tsUsec=0, inclLen=0, origLen=0, readLen=0; m_pcapFile.Read (expected, sizeof(expected), tsSec, tsUsec, inclLen, origLen, readLen); - uint8_t *actual = new uint8_t[readLen]; - p->CopyData (actual, readLen); + if (readLen != 0 && origLen != 0) + { + uint8_t *actual = new uint8_t[readLen]; + p->CopyData (actual, readLen); - uint32_t result = memcmp (actual, expected, readLen); + uint32_t result = memcmp (actual, expected, readLen); - delete [] actual; + delete [] actual; - // - // Avoid streams of errors -- only report the first. - // - if (GetErrorStatus () == false) + // + // Avoid streams of errors -- only report the first. + // + if (GetErrorStatus () == false) + { + NS_TEST_EXPECT_MSG_EQ (result, 0, "Expected data comparison error"); + } + } + else if (GetErrorStatus () == false) { - NS_TEST_EXPECT_MSG_EQ (result, 0, "Expected data comparison error"); + NS_TEST_EXPECT_MSG_GT (readLen, 0, "Unexpected packet error"); } } } @@ -282,25 +338,6 @@ // Example corresponding to simulations in the paper "Simulation-based // Comparisons of Tahoe, Reno, and SACK TCP - std::ostringstream tcpModel; - tcpModel << "ns3::Tcp" << m_tcpModel; - Config::SetDefault ("ns3::TcpL4Protocol::SocketType", - StringValue (tcpModel.str ())); - Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); - Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (1)); - - if (m_writeLogging) - { - LogComponentEnableAll (LOG_PREFIX_FUNC); - LogComponentEnable ("TcpLossResponse", LOG_LEVEL_ALL); - LogComponentEnable ("ErrorModel", LOG_LEVEL_DEBUG); - LogComponentEnable ("TcpLossResponse", LOG_LEVEL_ALL); - LogComponentEnable ("TcpNewReno", LOG_LEVEL_INFO); - LogComponentEnable ("TcpReno", LOG_LEVEL_INFO); - LogComponentEnable ("TcpTahoe", LOG_LEVEL_INFO); - LogComponentEnable ("TcpSocketBase", LOG_LEVEL_INFO); - } - //////////////////////////////////////////////////////// // Topology construction // @@ -359,13 +396,6 @@ ipInterfs.GetAddress (1), servPort); - Config::Connect ("/NodeList/0/$ns3::Ipv4L3Protocol/Tx", - MakeCallback (&Ns3TcpLossTestCase::Ipv4L3Tx, this)); - - Config::ConnectWithoutContext - ("/NodeList/0/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow", - MakeCallback (&Ns3TcpLossTestCase::CwndTracer, this)); - //////////////////////////////////////////////////////// // Set up loss model at node k1 // @@ -403,6 +433,13 @@ pem->SetList (sampleList); dev1.Get (1)->SetAttribute ("ReceiveErrorModel", PointerValue (pem)); + Config::Connect ("/NodeList/0/$ns3::Ipv4L3Protocol/Tx", + MakeCallback (&Ns3TcpLossTestCase::Ipv4L3Tx, this)); + + Config::ConnectWithoutContext + ("/NodeList/0/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow", + MakeCallback (&Ns3TcpLossTestCase::CwndTracer, this)); + // One can toggle the comment for the following line on or off to see the // effects of finite send buffer modelling. One can also change the size of // that buffer. @@ -442,7 +479,6 @@ Ns3TcpLossTestSuite::Ns3TcpLossTestSuite () : TestSuite ("ns3-tcp-loss", SYSTEM) { - Packet::EnablePrinting (); // Enable packet metadata for all test cases AddTestCase (new Ns3TcpLossTestCase ("Tahoe", 0)); AddTestCase (new Ns3TcpLossTestCase ("Tahoe", 1)); AddTestCase (new Ns3TcpLossTestCase ("Tahoe", 2)); diff -r 175c382cfab0 src/test/ns3tcp/ns3tcp-socket-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-socket-test-suite.cc Sun Jun 26 13:40:27 2011 +0100 +++ b/src/test/ns3tcp/ns3tcp-socket-test-suite.cc Mon Jun 27 14:48:14 2011 +0200 @@ -158,6 +158,9 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + virtual void DoTeardown (void); + bool m_writeResults; void SinkRx (std::string path, Ptr p, const Address &address); @@ -179,6 +182,22 @@ } void +Ns3TcpSocketTestCase2::DoSetup (void) +{ + TestCase::DoSetup (); + Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); +} + +void +Ns3TcpSocketTestCase2::DoTeardown (void) +{ + // Restore defaults + Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (536)); + + TestCase::DoTeardown (); +} + +void Ns3TcpSocketTestCase2::DoRun (void) { uint16_t sinkPort = 50000; @@ -189,8 +208,6 @@ Time writerStopTimeObj = Seconds (writerStopTime); Time simStopTimeObj= Seconds (simStopTime); - Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); - NodeContainer nodes; nodes.Create (2); Ptr n0 = nodes.Get (0); diff -r 175c382cfab0 src/test/ns3tcp/ns3tcp-state-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-state-test-suite.cc Sun Jun 26 13:40:27 2011 +0100 +++ b/src/test/ns3tcp/ns3tcp-state-test-suite.cc Mon Jun 27 14:48:14 2011 +0200 @@ -110,6 +110,11 @@ void Ns3TcpStateTestCase::DoSetup (void) { + Simulator::Destroy(); + + // Enable packet metadata + Packet::EnablePrinting (); + // // We expect there to be a file called ns3tcp-state-response-vectors.pcap in // response-vectors/ of this directory @@ -128,12 +133,56 @@ m_pcapFile.Open (m_pcapFilename, std::ios::in|std::ios::binary); NS_ABORT_MSG_UNLESS (m_pcapFile.GetDataLinkType () == PCAP_LINK_TYPE, "Wrong response vectors in directory"); } + + // Config + std::string tcpModel ("ns3::TcpNewReno"); + Config::SetDefault ("ns3::TcpL4Protocol::SocketType", StringValue (tcpModel)); + Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); + Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (1)); + Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (20)); + + // Logging + if (m_writeLogging) + { + LogComponentEnableAll (LOG_PREFIX_FUNC); + LogComponentEnable ("TcpTestCases", LOG_LEVEL_ALL); + LogComponentEnable ("ErrorModel", LOG_LEVEL_DEBUG); + LogComponentEnable ("TcpTestCases", LOG_LEVEL_ALL); + LogComponentEnable ("TcpNewReno", LOG_LEVEL_INFO); + LogComponentEnable ("TcpReno", LOG_LEVEL_INFO); + LogComponentEnable ("TcpTahoe", LOG_LEVEL_INFO); + LogComponentEnable ("TcpSocketBase", LOG_LEVEL_INFO); + } } void Ns3TcpStateTestCase::DoTeardown (void) { + // Restore Logging + if (m_writeLogging) + { + LogComponentDisableAll (LOG_PREFIX_FUNC); + LogComponentDisable ("TcpTestCases", LOG_LEVEL_ALL); + LogComponentDisable ("ErrorModel", LOG_LEVEL_DEBUG); + LogComponentDisable ("TcpTestCases", LOG_LEVEL_ALL); + LogComponentDisable ("TcpNewReno", LOG_LEVEL_INFO); + LogComponentDisable ("TcpReno", LOG_LEVEL_INFO); + LogComponentDisable ("TcpTahoe", LOG_LEVEL_INFO); + LogComponentDisable ("TcpSocketBase", LOG_LEVEL_INFO); + } + + // Restore config to usual defaults + Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (536)); + Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (2)); + Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (100)); + // No need to restore ns3::TcpL4Protocol::SocketType, ns3::TcpNewReno is already the default + m_pcapFile.Close (); + + // Enable packet metadata + Packet::DisablePrinting (); + + Simulator::Destroy(); } void @@ -177,22 +226,29 @@ // file and see if it still does the right thing. // uint8_t expected[PCAP_SNAPLEN]; - uint32_t tsSec, tsUsec, inclLen, origLen, readLen; + uint32_t tsSec=0, tsUsec=0, inclLen=0, origLen=0, readLen=0; m_pcapFile.Read (expected, sizeof(expected), tsSec, tsUsec, inclLen, origLen, readLen); + + if (readLen != 0 && origLen != 0) + { + uint8_t *actual = new uint8_t[readLen]; + p->CopyData (actual, readLen); - uint8_t *actual = new uint8_t[readLen]; - p->CopyData (actual, readLen); + uint32_t result = memcmp (actual, expected, readLen); - uint32_t result = memcmp (actual, expected, readLen); + delete [] actual; - delete [] actual; - - // - // Avoid streams of errors -- only report the first. - // - if (GetErrorStatus () == false) + // + // Avoid streams of errors -- only report the first. + // + if (GetErrorStatus () == false) + { + NS_TEST_EXPECT_MSG_EQ (result, 0, "Expected data comparison error"); + } + } + else if (GetErrorStatus () == false) { - NS_TEST_EXPECT_MSG_EQ (result, 0, "Expected data comparison error"); + NS_TEST_EXPECT_MSG_GT (readLen, 0, "Unexpected packet error"); } } } @@ -266,29 +322,10 @@ // 10Mb/s, 0.1ms 10Mb/s, 0.1ms // n0-----------------n1-----------------n2 - std::string tcpModel ("ns3::TcpNewReno"); - - Config::SetDefault ("ns3::TcpL4Protocol::SocketType", StringValue (tcpModel)); - Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); - Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (1)); - Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (20)); - - if (m_writeLogging) - { - LogComponentEnableAll (LOG_PREFIX_FUNC); - LogComponentEnable ("TcpTestCases", LOG_LEVEL_ALL); - LogComponentEnable ("ErrorModel", LOG_LEVEL_DEBUG); - LogComponentEnable ("TcpTestCases", LOG_LEVEL_ALL); - LogComponentEnable ("TcpNewReno", LOG_LEVEL_INFO); - LogComponentEnable ("TcpReno", LOG_LEVEL_INFO); - LogComponentEnable ("TcpTahoe", LOG_LEVEL_INFO); - LogComponentEnable ("TcpSocketBase", LOG_LEVEL_INFO); - } - //////////////////////////////////////////////////////// // Topology construction // - + // Create three nodes NodeContainer n0n1; n0n1.Create (2); @@ -338,9 +375,6 @@ Simulator::ScheduleNow (&Ns3TcpStateTestCase::StartFlow, this, localSocket, ipInterfs.GetAddress (1), servPort); - Config::Connect ("/NodeList/0/$ns3::Ipv4L3Protocol/Tx", - MakeCallback (&Ns3TcpStateTestCase::Ipv4L3Tx, this)); - //////////////////////////////////////////////////////// // Set up different test cases: Lost model at node n1, different file size // @@ -411,6 +445,9 @@ errN1->SetList (dropListN1); dev1.Get (0)->SetAttribute ("ReceiveErrorModel", PointerValue (errN1)); + Config::Connect ("/NodeList/0/$ns3::Ipv4L3Protocol/Tx", + MakeCallback (&Ns3TcpStateTestCase::Ipv4L3Tx, this)); + std::ostringstream oss; oss << "tcp-state" << m_testCase << "-test-case"; if (m_writeResults) @@ -434,8 +471,6 @@ Simulator::Stop (Seconds (1000)); Simulator::Run (); Simulator::Destroy (); - - } class Ns3TcpStateTestSuite : public TestSuite @@ -447,7 +482,6 @@ Ns3TcpStateTestSuite::Ns3TcpStateTestSuite () : TestSuite ("ns3-tcp-state", SYSTEM) { - Packet::EnablePrinting (); // Enable packet metadata for all test cases AddTestCase (new Ns3TcpStateTestCase (0)); AddTestCase (new Ns3TcpStateTestCase (1)); AddTestCase (new Ns3TcpStateTestCase (2)); diff -r 175c382cfab0 src/test/ns3wifi/wifi-interference-test-suite.cc --- a/src/test/ns3wifi/wifi-interference-test-suite.cc Sun Jun 26 13:40:27 2011 +0100 +++ b/src/test/ns3wifi/wifi-interference-test-suite.cc Mon Jun 27 14:48:14 2011 +0200 @@ -57,6 +57,9 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + virtual void DoTeardown (void); + void ReceivePacket (Ptr socket); static void GenerateTraffic (Ptr socket, uint32_t pktSize, uint32_t pktCount, Time pktInterval); void PrintEndSync (std::string context, uint32_t dataRate, double snr, double per); @@ -65,11 +68,14 @@ double m_PER; double m_SNR; uint32_t m_DataRate; + + std::string m_phyMode; }; // Add some help text to this case to describe what it is intended to test WifiInterferenceTestCase::WifiInterferenceTestCase () : TestCase ("Test interference calculation when interfering frame exactly overlaps intended frame") + , m_phyMode ("DsssRate1Mbps") { } @@ -77,6 +83,31 @@ { } +void +WifiInterferenceTestCase::DoSetup () +{ + TestCase::DoSetup (); + + // disable fragmentation for frames below 2200 bytes + Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200")); + // turn off RTS/CTS for frames below 2200 bytes + Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200")); + // Fix non-unicast data rate to be the same as that of unicast + Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue (m_phyMode)); +} + +void +WifiInterferenceTestCase::DoTeardown () +{ + // Restore default configuration + std::string invalidWifiMode ("Invalid-WifiMode"); + Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2346")); + Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2346")); + Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue (invalidWifiMode)); + + TestCase::DoTeardown (); +} + void WifiInterferenceTestCase::ReceivePacket (Ptr socket) { @@ -131,14 +162,6 @@ // Convert to time object Time interPacketInterval = Seconds (interval); - // disable fragmentation for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200")); - // turn off RTS/CTS for frames below 2200 bytes - Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200")); - // Fix non-unicast data rate to be the same as that of unicast - Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", - StringValue (phyMode)); - NodeContainer c; c.Create (3); @@ -232,8 +255,6 @@ void WifiInterferenceTestCase::DoRun (void) { - - std::string phyMode ("DsssRate1Mbps"); double Prss = -90; // -dBm double Irss = -90; // -dBm double delta = 0; // microseconds @@ -246,17 +267,17 @@ // Compute the packet error rate (PER) when delta=0 microseconds. This // means that the interferer arrives at exactly the same time as the // intended packet - PER = WifiSimpleInterference (phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); + PER = WifiSimpleInterference (m_phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); // Now rerun this test case and compute the PER when the delta time between // arrival of the intended frame and interferer is 1 microsecond. delta = 1; - PER1 = WifiSimpleInterference (phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); + PER1 = WifiSimpleInterference (m_phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); // Now rerun this test case and compute the PER when the delta time between // arrival of the intended frame and interferer is 2 microseconds. delta = 2; - PER2 = WifiSimpleInterference (phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); + PER2 = WifiSimpleInterference (m_phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); double PERDiff1 = PER - PER1;