diff -r eaf06b48cb5c src/aodv/test/aodv-regression.cc --- a/src/aodv/test/aodv-regression.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/aodv/test/aodv-regression.cc Thu Aug 04 10:23:48 2011 +0200 @@ -67,6 +67,14 @@ // Ping loopback test case AddTestCase (new LoopbackTestCase ()); } + + virtual void DoSetup (void) + { + TestSuite::DoSetup(); + + // Set a reproducible random seed + SeedManager::SetSeed(12345); + } } g_aodvRegressionTestSuite; @@ -92,7 +100,6 @@ void ChainRegressionTest::DoRun () { - SeedManager::SetSeed (12345); Config::SetDefault ("ns3::ArpCache::AliveTimeout", TimeValue (m_arpAliveTimeout)); CreateNodes (); diff -r eaf06b48cb5c src/aodv/test/bug-772.cc --- a/src/aodv/test/bug-772.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/aodv/test/bug-772.cc Thu Aug 04 10:23:48 2011 +0200 @@ -74,6 +74,7 @@ Bug772ChainTest::DoRun () { SeedManager::SetSeed (12345); + Config::SetDefault ("ns3::ArpCache::AliveTimeout", TimeValue (Seconds (1))); CreateNodes (); CreateDevices (); diff -r eaf06b48cb5c src/core/model/config.cc --- a/src/core/model/config.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/core/model/config.cc Thu Aug 04 10:23:48 2011 +0200 @@ -603,6 +603,11 @@ { return GlobalValue::BindFailSafe (name, value); } +void Reset () +{ + AttributeList::GetGlobal ()->Reset (); + GlobalValue::ResetAll (); +} void ConnectWithoutContext (std::string path, const CallbackBase &cb) { Singleton::Get ()->ConnectWithoutContext (path, cb); diff -r eaf06b48cb5c src/core/model/config.h --- a/src/core/model/config.h Sun Jul 17 08:01:33 2011 -0400 +++ b/src/core/model/config.h Thu Aug 04 10:23:48 2011 +0200 @@ -110,6 +110,11 @@ * This function undoes the work of Config::ConnectWithContext. */ void Disconnect (std::string path, const CallbackBase &cb); +/** + * This method resets the effect of all SetDefault, SetDefaultFailSafe, + * SetGlobal, and SetGlobalFailSafe calls. + */ +void Reset (); /** * \brief hold a set of objects which match a specific search string. diff -r eaf06b48cb5c src/core/model/global-value.cc --- a/src/core/model/global-value.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/core/model/global-value.cc Thu Aug 04 10:23:48 2011 +0200 @@ -49,6 +49,7 @@ void GlobalValue::InitializeFromEnv (void) { + m_value = m_initialValue->Copy (); #ifdef HAVE_GETENV char *envVar = getenv ("NS_GLOBAL_VALUE"); if (envVar == 0) @@ -88,9 +89,22 @@ return m_help; } void +GlobalValue::ResetValue (void) +{ + InitializeFromEnv (); +} +void +GlobalValue::ResetAll (void) +{ + for (Iterator i = Begin (); i != End (); i++) + { + (*i)->ResetValue (); + } +} +void GlobalValue::GetValue (AttributeValue &value) const { - bool ok = m_checker->Copy (*m_initialValue, value); + bool ok = m_checker->Copy (*m_value, value); if (ok) { return; @@ -100,7 +114,7 @@ { NS_FATAL_ERROR ("GlobalValue name="<Set (m_initialValue->SerializeToString (m_checker)); + str->Set (m_value->SerializeToString (m_checker)); } Ptr GlobalValue::GetChecker (void) const @@ -113,7 +127,7 @@ { if (m_checker->Check (value)) { - m_initialValue = value.Copy (); + m_value = value.Copy (); return true; } // attempt to convert to string. @@ -134,7 +148,7 @@ { return false; } - m_checker->Copy (*v, *PeekPointer (m_initialValue)); + m_checker->Copy (*v, *PeekPointer (m_value)); return true; } diff -r eaf06b48cb5c src/core/model/global-value.h --- a/src/core/model/global-value.h Sun Jul 17 08:01:33 2011 -0400 +++ b/src/core/model/global-value.h Thu Aug 04 10:23:48 2011 +0200 @@ -84,6 +84,10 @@ * \param value the new value to set in this GlobalValue. */ bool SetValue (const AttributeValue &value); + /** + * Reset the global value to its default/initial value. + */ + void ResetValue (); /** * \param name the name of the global value @@ -136,6 +140,11 @@ * */ static void GetValueByName (std::string name, AttributeValue &value); + + /** + * Resets all GlobalValue s to their defaults. + */ + static void ResetAll (); private: @@ -145,6 +154,7 @@ void InitializeFromEnv (void); std::string m_name; std::string m_help; + Ptr m_value; Ptr m_initialValue; Ptr m_checker; }; diff -r eaf06b48cb5c src/core/model/random-variable.cc --- a/src/core/model/random-variable.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/core/model/random-variable.cc Thu Aug 04 10:23:48 2011 +0200 @@ -64,6 +64,11 @@ void SeedManager::SetSeed (uint32_t seed) { Config::SetGlobal ("RngSeed", IntegerValue (seed)); + + // A call to SeedManager::SetSeed is an explicit request for a reproducible + // state. RngStream does not re-initialize itself after setting the global + // value above, unless we explicitly call SetPackageSeed. + RngStream::SetPackageSeed(seed); } void SeedManager::SetRun (uint32_t run) diff -r eaf06b48cb5c src/core/model/rng-stream.cc --- a/src/core/model/rng-stream.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/core/model/rng-stream.cc Thu Aug 04 10:23:48 2011 +0200 @@ -305,7 +305,12 @@ RngStream::EnsureGlobalInitialized (void) { static bool initialized = false; - static uint32_t run = 0; + uint32_t run = 0; + + IntegerValue value; + g_rngRun.GetValue (value); + run = value.Get (); + if (!initialized) { initialized = true; @@ -313,10 +318,9 @@ IntegerValue value; g_rngSeed.GetValue (value); seed = value.Get (); - g_rngRun.GetValue (value); - run = value.Get (); SetPackageSeed (seed); } + return run; } diff -r eaf06b48cb5c src/core/model/test.cc --- a/src/core/model/test.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/core/model/test.cc Thu Aug 04 10:23:48 2011 +0200 @@ -21,6 +21,9 @@ #include "abort.h" #include +#include "ns3/simulator.h" +#include "ns3/config.h" + // Set to true to enable a segmentation fault upon a test case macro test // failing (for debugging purposes) bool gBreakOnFailure = false; @@ -395,11 +398,29 @@ 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(); + + /** + * Some tests will change default configuration settings. In + * those cases, a full configuration reset is the only way to get + * back to a reproducible state. + */ + Config::Reset (); } TestSuite::TestSuite (std::string name, TestType type) @@ -659,6 +680,22 @@ void TestSuite::DoSetup (void) { + /* + * Ensure repeatable state, reset all configuration settings to their defaults + */ + Config::Reset (); + + /* + * Preserve global RNG state (RngStream contains process-wide side effects) + */ + m_rngRunBackup = SeedManager::GetRun(); + m_rngSeedBackup = SeedManager::GetSeed(); + + /* + * Reset RNG state (in case the testing framework changed it somehow between runs) + */ + SeedManager::SetRun(m_rngRunBackup); + SeedManager::SetSeed(m_rngSeedBackup); } void @@ -697,6 +734,11 @@ void TestSuite::DoTeardown (void) { + /* + * Restore global RNG state + */ + SeedManager::SetRun(m_rngRunBackup); + SeedManager::SetSeed(m_rngSeedBackup); } class TestRunnerImpl diff -r eaf06b48cb5c src/core/model/test.h --- a/src/core/model/test.h Sun Jul 17 08:01:33 2011 -0400 +++ b/src/core/model/test.h Thu Aug 04 10:23:48 2011 +0200 @@ -29,6 +29,7 @@ #include #include "ns3/system-wall-clock-ms.h" +#include "ns3/random-variable.h" extern bool gBreakOnFailure; @@ -753,7 +754,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) @@ -1276,6 +1277,15 @@ bool m_error; TestType m_type; + // Backup of process-wide RNG state + // FIXME: This *should* be done per-testcase, but current test cases + // depend have cases where they depend on RNG state resulting from + // previous runs within a TestSuite (like routing-aodv-regression), + // so in order not to break them, we do not reset RNG state between + // test cases, only between tests suites. + uint32_t m_rngSeedBackup; + uint32_t m_rngRunBackup; + typedef std::vector TestCaseVector_t; TestCaseVector_t m_tests; }; diff -r eaf06b48cb5c src/core/test/names-test-suite.cc --- a/src/core/test/names-test-suite.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/core/test/names-test-suite.cc Thu Aug 04 10:23:48 2011 +0200 @@ -87,6 +87,7 @@ BasicAddTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -153,6 +154,7 @@ StringContextAddTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -216,6 +218,7 @@ FullyQualifiedAddTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -282,6 +285,7 @@ RelativeAddTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -347,6 +351,7 @@ BasicRenameTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -407,6 +412,7 @@ StringContextRenameTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -467,6 +473,7 @@ FullyQualifiedRenameTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -527,6 +534,7 @@ RelativeRenameTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -587,6 +595,7 @@ FindPathTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -641,6 +650,7 @@ BasicFindTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -703,6 +713,7 @@ StringContextFindTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -765,6 +776,7 @@ FullyQualifiedFindTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -827,6 +839,7 @@ RelativeFindTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void @@ -887,6 +900,7 @@ AlternateFindTestCase::DoTeardown (void) { Names::Clear (); + TestCase::DoTeardown (); } void diff -r eaf06b48cb5c src/core/test/time-test-suite.cc --- a/src/core/test/time-test-suite.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/core/test/time-test-suite.cc Thu Aug 04 10:23:48 2011 +0200 @@ -76,6 +76,7 @@ TimeSimpleTestCase::DoTeardown (void) { Time::SetResolution (m_originalResolution); + TestCase::DoTeardown (); } static class TimeTestSuite : public TestSuite diff -r eaf06b48cb5c src/core/test/timer-test-suite.cc --- a/src/core/test/timer-test-suite.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/core/test/timer-test-suite.cc Thu Aug 04 10:23:48 2011 +0200 @@ -215,6 +215,7 @@ { Simulator::Run (); Simulator::Destroy (); + TestCase::DoTeardown (); } static class TimerTestSuite : public TestSuite diff -r eaf06b48cb5c src/energy/test/basic-energy-model-test.cc --- a/src/energy/test/basic-energy-model-test.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/energy/test/basic-energy-model-test.cc Thu Aug 04 10:23:48 2011 +0200 @@ -217,6 +217,7 @@ private: void DoRun (void); + void DoSetup (void); /** * Callback invoked when energy is drained from source. @@ -238,11 +239,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 +259,22 @@ } 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::DoRun (void) { /* @@ -287,18 +306,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 +326,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 eaf06b48cb5c src/energy/test/rv-battery-model-test.cc --- a/src/energy/test/rv-battery-model-test.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/energy/test/rv-battery-model-test.cc Thu Aug 04 10:23:48 2011 +0200 @@ -57,13 +57,16 @@ void CreateLoadProfiles (void); /** - * \returns False if no error occurs. - * * Runs test. */ void DoRun (void); /** + * Sets up test configuration + */ + void DoSetup (void); + + /** * \param load Load value, in Amperes (A). * \param expLifetime Expected lifetime. * \return False if no error occurs. @@ -99,14 +102,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 +646,30 @@ } 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::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 +681,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 +721,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 +741,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 +772,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 +796,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 +816,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 eaf06b48cb5c src/internet/test/ipv4-address-generator-test-suite.cc --- a/src/internet/test/ipv4-address-generator-test-suite.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/internet/test/ipv4-address-generator-test-suite.cc Thu Aug 04 10:23:48 2011 +0200 @@ -38,6 +38,7 @@ NetworkNumberAllocatorTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); + TestCase::DoTeardown (); } void NetworkNumberAllocatorTestCase::DoRun (void) @@ -117,7 +118,7 @@ AddressAllocatorTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); - Simulator::Destroy (); + TestCase::DoTeardown (); } @@ -138,7 +139,7 @@ NetworkAndAddressTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); - Simulator::Destroy (); + TestCase::DoTeardown (); } void @@ -202,6 +203,7 @@ ExampleAddressGeneratorTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); + TestCase::DoTeardown (); } void @@ -254,7 +256,7 @@ AddressCollisionTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); - Simulator::Destroy (); + TestCase::DoTeardown (); } void AddressCollisionTestCase::DoRun (void) diff -r eaf06b48cb5c src/internet/test/ipv4-address-helper-test-suite.cc --- a/src/internet/test/ipv4-address-helper-test-suite.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/internet/test/ipv4-address-helper-test-suite.cc Thu Aug 04 10:23:48 2011 +0200 @@ -41,7 +41,7 @@ NetworkAllocatorHelperTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); - Simulator::Destroy (); + TestCase::DoTeardown (); } void NetworkAllocatorHelperTestCase::DoRun (void) @@ -87,7 +87,7 @@ AddressAllocatorHelperTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); - Simulator::Destroy (); + TestCase::DoTeardown (); } void @@ -176,7 +176,7 @@ ResetAllocatorHelperTestCase::DoTeardown (void) { Ipv4AddressGenerator::Reset (); - Simulator::Destroy (); + TestCase::DoTeardown (); } static class Ipv4AddressHelperTestSuite : public TestSuite diff -r eaf06b48cb5c src/internet/test/tcp-test.cc --- a/src/internet/test/tcp-test.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/internet/test/tcp-test.cc Thu Aug 04 10:23:48 2011 +0200 @@ -160,7 +160,7 @@ delete [] m_sourceTxPayload; delete [] m_sourceRxPayload; delete [] m_serverRxPayload; - Simulator::Destroy (); + TestCase::DoTeardown (); } void diff -r eaf06b48cb5c src/mobility/test/ns2-mobility-helper-test-suite.cc --- a/src/mobility/test/ns2-mobility-helper-test-suite.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/mobility/test/ns2-mobility-helper-test-suite.cc Thu Aug 04 10:23:48 2011 +0200 @@ -204,6 +204,7 @@ void DoSetup () { + Simulator::Destroy(); CreateNodes (); } @@ -211,7 +212,7 @@ { Names::Clear (); std::remove (m_traceFile.c_str ()); - Simulator::Destroy (); + TestCase::DoTeardown (); } /// Go diff -r eaf06b48cb5c src/mobility/test/steady-state-random-waypoint-mobility-model-test.cc --- a/src/mobility/test/steady-state-random-waypoint-mobility-model-test.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/mobility/test/steady-state-random-waypoint-mobility-model-test.cc Thu Aug 04 10:23:48 2011 +0200 @@ -47,6 +47,7 @@ SteadyStateRandomWaypointTest::DoTeardown (void) { mobilityStack.clear(); + TestCase::DoTeardown(); } void diff -r eaf06b48cb5c src/mobility/test/waypoint-mobility-model-test.cc --- a/src/mobility/test/waypoint-mobility-model-test.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/mobility/test/waypoint-mobility-model-test.cc Thu Aug 04 10:23:48 2011 +0200 @@ -57,6 +57,7 @@ { mobilityStack.clear(); waypoints.clear(); + TestCase::DoTeardown(); } void diff -r eaf06b48cb5c src/network/model/packet-metadata.cc --- a/src/network/model/packet-metadata.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/network/model/packet-metadata.cc Thu Aug 04 10:23:48 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 eaf06b48cb5c src/network/model/packet-metadata.h --- a/src/network/model/packet-metadata.h Sun Jul 17 08:01:33 2011 -0400 +++ b/src/network/model/packet-metadata.h Thu Aug 04 10:23:48 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 eaf06b48cb5c src/network/model/packet.cc --- a/src/network/model/packet.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/network/model/packet.cc Thu Aug 04 10:23:48 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 eaf06b48cb5c src/network/model/packet.h --- a/src/network/model/packet.h Sun Jul 17 08:01:33 2011 -0400 +++ b/src/network/model/packet.h Thu Aug 04 10:23:48 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 eaf06b48cb5c src/network/test/pcap-file-test-suite.cc --- a/src/network/test/pcap-file-test-suite.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/network/test/pcap-file-test-suite.cc Thu Aug 04 10:23:48 2011 +0200 @@ -114,6 +114,7 @@ WriteModeCreateTestCase::DoTeardown (void) { remove (m_testFilename.c_str ()); + TestCase::DoTeardown (); } void @@ -226,6 +227,7 @@ ReadModeCreateTestCase::DoTeardown (void) { remove (m_testFilename.c_str ()); + TestCase::DoTeardown (); } void @@ -332,6 +334,7 @@ AppendModeCreateTestCase::DoTeardown (void) { remove (m_testFilename.c_str ()); + TestCase::DoTeardown (); } void @@ -438,6 +441,7 @@ FileHeaderTestCase::DoTeardown (void) { remove (m_testFilename.c_str ()); + TestCase::DoTeardown (); } void @@ -675,6 +679,7 @@ RecordHeaderTestCase::DoTeardown (void) { remove (m_testFilename.c_str ()); + TestCase::DoTeardown (); } void @@ -972,6 +977,7 @@ void ReadFileTestCase::DoTeardown (void) { + TestCase::DoTeardown (); } const uint32_t N_KNOWN_PACKETS = 6; diff -r eaf06b48cb5c src/network/utils/mac48-address.cc --- a/src/network/utils/mac48-address.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/network/utils/mac48-address.cc Thu Aug 04 10:23:48 2011 +0200 @@ -20,10 +20,17 @@ #include "mac48-address.h" #include "ns3/address.h" #include "ns3/assert.h" +#include "ns3/uinteger.h" +#include "ns3/global-value.h" #include #include #include +static ns3::GlobalValue g_Mac48Origin ("Mac48Origin", + "The initial value the Mac48Address::Allocate helper will use.", + ns3::UintegerValue (0), + ns3::MakeUintegerChecker ()); + namespace ns3 { ATTRIBUTE_HELPER_CPP (Mac48Address); @@ -118,7 +125,10 @@ Mac48Address Mac48Address::Allocate (void) { - static uint64_t id = 0; + UintegerValue value; + g_Mac48Origin.GetValue (value); + uint64_t id = value.Get(); + id++; Mac48Address address; address.m_address[0] = (id >> 40) & 0xff; @@ -127,6 +137,10 @@ address.m_address[3] = (id >> 16) & 0xff; address.m_address[4] = (id >> 8) & 0xff; address.m_address[5] = (id >> 0) & 0xff; + + value.Set(id); + g_Mac48Origin.SetValue (value); + return address; } uint8_t diff -r eaf06b48cb5c src/olsr/test/bug780-test.cc --- a/src/olsr/test/bug780-test.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/olsr/test/bug780-test.cc Thu Aug 04 10:23:48 2011 +0200 @@ -75,6 +75,17 @@ } 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::DoRun () { SeedManager::SetSeed (123); @@ -97,11 +108,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 eaf06b48cb5c src/olsr/test/bug780-test.h --- a/src/olsr/test/bug780-test.h Sun Jul 17 08:01:33 2011 -0400 +++ b/src/olsr/test/bug780-test.h Thu Aug 04 10:23:48 2011 +0200 @@ -43,6 +43,7 @@ void CheckResults (); /// Go void DoRun (); + void DoSetup (); }; } diff -r eaf06b48cb5c src/propagation/test/propagation-loss-model-test-suite.cc --- a/src/propagation/test/propagation-loss-model-test-suite.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/propagation/test/propagation-loss-model-test-suite.cc Thu Aug 04 10:23:48 2011 +0200 @@ -42,6 +42,7 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); typedef struct { Vector m_position; @@ -63,14 +64,23 @@ } 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::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 +149,7 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); typedef struct { @@ -162,15 +173,21 @@ } 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::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 +284,7 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); typedef struct { Vector m_position; @@ -288,12 +306,18 @@ } 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::DoRun (void) +{ // Select a reference transmit power // Pt = 10^(17.0206/10)/10^3 = .05035702 W double txPowerW = 0.05035702; @@ -402,6 +426,7 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); }; RangePropagationLossModelTestCase::RangePropagationLossModelTestCase () @@ -414,9 +439,17 @@ } void +RangePropagationLossModelTestCase::DoSetup (void) +{ + TestCase::DoSetup (); + + // Set testcase parameters + Config::SetDefault ("ns3::RangePropagationLossModel::MaxRange", DoubleValue (127.2)); +} + +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 eaf06b48cb5c src/test/csma-system-test-suite.cc --- a/src/test/csma-system-test-suite.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/test/csma-system-test-suite.cc Thu Aug 04 10:23:48 2011 +0200 @@ -165,6 +165,8 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + void SinkRxNode1 (Ptr p, const Address &ad); void SinkRxNode2 (Ptr p, const Address &ad); void DropEvent (Ptr p); @@ -201,6 +203,19 @@ 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")); +} + // // Example of the sending of a datagram to a broadcast address // @@ -333,12 +348,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 eaf06b48cb5c src/test/error-model-test-suite.cc --- a/src/test/error-model-test-suite.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/test/error-model-test-suite.cc Thu Aug 04 10:23:48 2011 +0200 @@ -81,6 +81,9 @@ // Set some arbitrary deterministic values SeedManager::SetSeed (7); SeedManager::SetRun (5); + + m_count = 0; + m_drops = 0; Ptr a = CreateObject (); Ptr b = CreateObject (); diff -r eaf06b48cb5c src/test/global-routing-test-suite.cc --- a/src/test/global-routing-test-suite.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/test/global-routing-test-suite.cc Thu Aug 04 10:23:48 2011 +0200 @@ -55,7 +55,10 @@ private: void SinkRx (std::string path, Ptr p, const Address &address); void HandleRead (Ptr); + virtual void DoRun (void); + virtual void DoSetup (void); + int m_count; std::vector m_firstInterface; std::vector m_secondInterface; @@ -118,6 +121,16 @@ } } +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)); +} + // Test derived from examples/routing/dynamic-global-routing.cc // // Network topology @@ -140,10 +153,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 eaf06b48cb5c src/test/ns3tcp/ns3tcp-cwnd-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-cwnd-test-suite.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/test/ns3tcp/ns3tcp-cwnd-test-suite.cc Thu Aug 04 10:23:48 2011 +0200 @@ -384,6 +384,8 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + bool m_writeResults; class CwndEvent { @@ -419,11 +421,17 @@ } void +Ns3TcpCwndTestCase2::DoSetup (void) +{ + TestCase::DoSetup (); + + // Set up some default values for the simulation. + Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (4)); +} + +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 eaf06b48cb5c src/test/ns3tcp/ns3tcp-interop-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-interop-test-suite.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/test/ns3tcp/ns3tcp-interop-test-suite.cc Thu Aug 04 10:23:48 2011 +0200 @@ -128,6 +128,7 @@ Ns3TcpInteroperabilityTestCase::DoTeardown (void) { m_pcapFile.Close (); + TestCase::DoTeardown (); } void diff -r eaf06b48cb5c src/test/ns3tcp/ns3tcp-loss-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-loss-test-suite.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/test/ns3tcp/ns3tcp-loss-test-suite.cc Thu Aug 04 10:23:48 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,51 @@ 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 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 (); + + TestCase::DoTeardown (); } void @@ -182,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); - 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 +333,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 +391,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 +428,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 +474,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 eaf06b48cb5c src/test/ns3tcp/ns3tcp-socket-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-socket-test-suite.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/test/ns3tcp/ns3tcp-socket-test-suite.cc Thu Aug 04 10:23:48 2011 +0200 @@ -158,6 +158,8 @@ private: virtual void DoRun (void); + virtual void DoSetup (void); + bool m_writeResults; void SinkRx (std::string path, Ptr p, const Address &address); @@ -179,6 +181,13 @@ } void +Ns3TcpSocketTestCase2::DoSetup (void) +{ + TestCase::DoSetup (); + Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); +} + +void Ns3TcpSocketTestCase2::DoRun (void) { uint16_t sinkPort = 50000; @@ -189,8 +198,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 eaf06b48cb5c src/test/ns3tcp/ns3tcp-state-test-suite.cc --- a/src/test/ns3tcp/ns3tcp-state-test-suite.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/test/ns3tcp/ns3tcp-state-test-suite.cc Thu Aug 04 10:23:48 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,50 @@ 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); + } + m_pcapFile.Close (); + + // Enable packet metadata + Packet::DisablePrinting (); + + TestCase::DoTeardown (); } void @@ -177,22 +220,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 +316,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 +369,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 +439,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 +465,6 @@ Simulator::Stop (Seconds (1000)); Simulator::Run (); Simulator::Destroy (); - - } class Ns3TcpStateTestSuite : public TestSuite @@ -447,7 +476,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 eaf06b48cb5c src/test/ns3wifi/wifi-interference-test-suite.cc --- a/src/test/ns3wifi/wifi-interference-test-suite.cc Sun Jul 17 08:01:33 2011 -0400 +++ b/src/test/ns3wifi/wifi-interference-test-suite.cc Thu Aug 04 10:23:48 2011 +0200 @@ -57,6 +57,8 @@ private: virtual void DoRun (void); + virtual void DoSetup (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 +67,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 +82,19 @@ { } +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::ReceivePacket (Ptr socket) { @@ -131,14 +149,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 +242,6 @@ void WifiInterferenceTestCase::DoRun (void) { - - std::string phyMode ("DsssRate1Mbps"); double Prss = -90; // -dBm double Irss = -90; // -dBm double delta = 0; // microseconds @@ -246,17 +254,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;