diff --git a/src/core/model/log.cc b/src/core/model/log.cc index e9e7d9f2a..14ffbd883 100644 --- a/src/core/model/log.cc +++ b/src/core/model/log.cc @@ -19,8 +19,6 @@ */ #include "log.h" -#ifdef NS3_LOG_ENABLE - #include #include #include @@ -381,35 +379,3 @@ ParameterLogger::ParameterLogger (std::ostream &os) {} } // namespace ns3 - -#else // NS3_LOG_ENABLE - -namespace ns3 { - -void -LogComponentEnable (char const *name, enum LogLevel level) -{ - -} - -void -LogComponentEnableAll (enum LogLevel level) -{ - -} - -void -LogComponentDisable (char const *name, enum LogLevel level) -{ - -} - -void -LogComponentDisableAll (enum LogLevel level) -{ - -} - -} // namespace ns3 - -#endif diff --git a/src/core/model/log.h b/src/core/model/log.h index b1ec1dadc..f544e86ab 100644 --- a/src/core/model/log.h +++ b/src/core/model/log.h @@ -323,8 +323,22 @@ void LogComponentDisableAll (enum LogLevel level); } \ while (false) -namespace ns3 { +#else /* LOG_ENABLE */ +#define NS_LOG_COMPONENT_DEFINE(component) +#define NS_LOG(level, msg) +#define NS_LOG_ERROR(msg) +#define NS_LOG_WARN(msg) +#define NS_LOG_DEBUG(msg) +#define NS_LOG_INFO(msg) +#define NS_LOG_FUNCTION_NOARGS() +#define NS_LOG_FUNCTION(msg) +#define NS_LOG_LOGIC(msg) +#define NS_LOG_UNCOND(msg) + +#endif /* LOG_ENABLE */ + +namespace ns3 { /** * \ingroup logging @@ -385,27 +399,5 @@ public: } // namespace ns3 -#else /* LOG_ENABLE */ - -#define NS_LOG_COMPONENT_DEFINE(component) -#define NS_LOG(level, msg) -#define NS_LOG_ERROR(msg) -#define NS_LOG_WARN(msg) -#define NS_LOG_DEBUG(msg) -#define NS_LOG_INFO(msg) -#define NS_LOG_FUNCTION_NOARGS() -#define NS_LOG_FUNCTION(msg) -#define NS_LOG_LOGIC(msg) -#define NS_LOG_UNCOND(msg) - -#define LogComponentPrintList -#define LogRegisterTimePrinter(printer) - -#define LogSetTimePrinter(printer) -#define LogGetTimePrinter -#define LogSetNodePrinter(printer) -#define LogGetNodePrinter - -#endif /* LOG_ENABLE */ #endif // __LOG_H__ diff --git a/src/core/model/simulator.cc b/src/core/model/simulator.cc index a001148a2..e517efaa0 100644 --- a/src/core/model/simulator.cc +++ b/src/core/model/simulator.cc @@ -51,14 +51,6 @@ GlobalValue g_schedTypeImpl = GlobalValue ("SchedulerType", TypeIdValue (MapScheduler::GetTypeId ()), MakeTypeIdChecker ()); - -#ifdef NS3_LOG_ENABLE - -// -// Note: Calls that take TimePrinter as a parameter are defined as nothing -// in the logging module if NS3_LOG_ENABLE is not defined. -// - static void TimePrinter (std::ostream &os) { @@ -78,8 +70,6 @@ NodePrinter (std::ostream &os) } } -#endif /* NS3_LOG_ENABLE */ - static SimulatorImpl **PeekImpl (void) { static SimulatorImpl *impl = 0; diff --git a/src/core/test/command-line-test-suite.cc b/src/core/test/command-line-test-suite.cc index e31092949..03c247e66 100644 --- a/src/core/test/command-line-test-suite.cc +++ b/src/core/test/command-line-test-suite.cc @@ -217,7 +217,7 @@ public: }; CommandLineTestSuite::CommandLineTestSuite () - : TestSuite ("command-line", BVT) + : TestSuite ("command-line", UNIT) { AddTestCase (new CommandLineBooleanTestCase); AddTestCase (new CommandLineIntTestCase); diff --git a/src/core/test/config-test-suite.cc b/src/core/test/config-test-suite.cc index 18d11949c..56a65293f 100644 --- a/src/core/test/config-test-suite.cc +++ b/src/core/test/config-test-suite.cc @@ -605,7 +605,7 @@ public: }; ConfigTestSuite::ConfigTestSuite () - : TestSuite ("config", BVT) + : TestSuite ("config", UNIT) { AddTestCase (new RootNamespaceConfigTestCase); AddTestCase (new UnderRootNamespaceConfigTestCase); diff --git a/src/core/test/global-value-test-suite.cc b/src/core/test/global-value-test-suite.cc index 407541134..0aaa31311 100644 --- a/src/core/test/global-value-test-suite.cc +++ b/src/core/test/global-value-test-suite.cc @@ -83,7 +83,7 @@ public: }; GlobalValueTestSuite::GlobalValueTestSuite () - : TestSuite ("global-value", BVT) + : TestSuite ("global-value", UNIT) { AddTestCase (new GlobalValueTestCase); } diff --git a/src/core/test/object-test-suite.cc b/src/core/test/object-test-suite.cc index 2c899976e..826cba2c8 100644 --- a/src/core/test/object-test-suite.cc +++ b/src/core/test/object-test-suite.cc @@ -417,7 +417,7 @@ public: }; ObjectTestSuite::ObjectTestSuite () - : TestSuite ("object", BVT) + : TestSuite ("object", UNIT) { AddTestCase (new CreateObjectTestCase); AddTestCase (new AggregateObjectTestCase); diff --git a/src/core/test/random-variable-test-suite.cc b/src/core/test/random-variable-test-suite.cc index d2ad40496..b1479e641 100644 --- a/src/core/test/random-variable-test-suite.cc +++ b/src/core/test/random-variable-test-suite.cc @@ -136,7 +136,7 @@ public: }; BasicRandomNumberTestSuite::BasicRandomNumberTestSuite () - : TestSuite ("basic-random-number", BVT) + : TestSuite ("basic-random-number", UNIT) { AddTestCase (new BasicRandomNumberTestCase); AddTestCase (new RandomNumberSerializationTestCase); diff --git a/src/mobility/helper/ns2-mobility-helper.cc b/src/mobility/helper/ns2-mobility-helper.cc index 4a0e73438..9153bbaf9 100644 --- a/src/mobility/helper/ns2-mobility-helper.cc +++ b/src/mobility/helper/ns2-mobility-helper.cc @@ -41,16 +41,11 @@ #include #include #include -#include #include "ns3/log.h" #include "ns3/simulator.h" #include "ns3/node-list.h" #include "ns3/node.h" #include "ns3/constant-velocity-mobility-model.h" -#include "ns3/test.h" -#include "ns3/node-container.h" -#include "ns3/names.h" -#include "ns3/config.h" #include "ns2-mobility-helper.h" NS_LOG_COMPONENT_DEFINE ("Ns2MobilityHelper"); @@ -663,367 +658,4 @@ Ns2MobilityHelper::Install (void) const Install (NodeList::Begin (), NodeList::End ()); } -// ----------------------------------------------------------------------------- -// Testing -// ----------------------------------------------------------------------------- -bool operator== (Vector const & a, Vector const & b) -{ - return (a.x == b.x && a.y == b.y && a.z == b.z); -} -/** - * Every test case is supposed to: - * 1. Generate short mobility trace file - * 2. Read it back using Ns2MobilityHelper - * 3. Check initial node positions and speeds. - * 4. Run simulation listening for all CourseChange events and compare actual mobility with the reference - */ -class Ns2MobilityHelperTest : public TestCase -{ -public: - /// Single record in mobility reference - struct ReferencePoint - { - std::string node; ///< node ID as string, e.g. "1" - Time time; ///< timestamp - Vector pos; ///< reference position - Vector vel; ///< reference velocity - - ReferencePoint (std::string const & id, Time t, Vector const & p, Vector const & v) - : node (id), - time (t), - pos (p), - vel (v) - { - } - /// Sort by timestamp - bool operator< (ReferencePoint const & o) const - { - return (time < o.time); - } - }; - /** - * Create new test case. To make it useful SetTrace () and AddReferencePoint () must be called - * - * \param name Short description - * \param nodes Number of nodes used in the test trace, 1 by default - */ - Ns2MobilityHelperTest (std::string const & name, Time timeLimit, uint32_t nodes = 1) - : TestCase (name), - m_timeLimit (timeLimit), - m_nodeCount (nodes), - m_nextRefPoint (0) - { - } - /// Empty - virtual ~Ns2MobilityHelperTest () - { - } - /// Set NS-2 trace to read as single large string (don't forget to add \n and quote ") - void SetTrace (std::string const & trace) - { - m_trace = trace; - } - /// Add next reference point - void AddReferencePoint (ReferencePoint const & r) - { - m_reference.push_back (r); - } - /// Sugar - void AddReferencePoint (const char * id, double sec, Vector const & p, Vector const & v) - { - AddReferencePoint (ReferencePoint (id, Seconds (sec), p, v)); - } - -private: - /// Test time limit - Time m_timeLimit; - /// Number of nodes used in the test - uint32_t m_nodeCount; - /// Trace as string - std::string m_trace; - /// Reference mobility - std::vector m_reference; - /// Next reference point to be checked - size_t m_nextRefPoint; - /// TMP trace file name - std::string m_traceFile; - -private: - /// Dump NS-2 trace to tmp file - bool WriteTrace () - { - m_traceFile = GetTempDir () + "Ns2MobilityHelperTest.tcl"; - std::ofstream of (m_traceFile.c_str ()); - NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL (of.is_open (), true, "Need to write tmp. file"); - of << m_trace; - of.close (); - return false; // no errors - } - /// Create and name nodes - void CreateNodes () - { - NodeContainer nodes; - nodes.Create (m_nodeCount); - for (uint32_t i = 0; i < m_nodeCount; ++i) - { - std::ostringstream os; - os << i; - Names::Add (os.str (), nodes.Get (i)); - } - } - /// Check that all initial positions are correct - bool CheckInitialPositions () - { - std::stable_sort (m_reference.begin (), m_reference.end ()); - while (m_nextRefPoint < m_reference.size () && m_reference[m_nextRefPoint].time == Seconds (0)) - { - ReferencePoint const & rp = m_reference[m_nextRefPoint]; - Ptr node = Names::Find (rp.node); - NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL (node, 0, "Can't find node with id " << rp.node); - Ptr mob = node->GetObject (); - NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL (mob, 0, "Can't find mobility for node " << rp.node); - - NS_TEST_EXPECT_MSG_EQ (rp.pos, mob->GetPosition (), "Initial position mismatch for node " << rp.node); - NS_TEST_EXPECT_MSG_EQ (rp.vel, mob->GetVelocity (), "Initial velocity mismatch for node " << rp.node); - - m_nextRefPoint++; - } - return GetErrorStatus (); - } - /// Listen for course change events - void CourseChange (std::string context, Ptr mobility) - { - Time time = Simulator::Now (); - Ptr node = mobility->GetObject (); - NS_ASSERT (node); - std::string id = Names::FindName (node); - NS_ASSERT (!id.empty ()); - Vector pos = mobility->GetPosition (); - Vector vel = mobility->GetVelocity (); - - NS_TEST_EXPECT_MSG_LT (m_nextRefPoint, m_reference.size (), "Not enough reference points"); - if (m_nextRefPoint >= m_reference.size ()) - { - return; - } - - ReferencePoint const & ref = m_reference [m_nextRefPoint++]; - NS_TEST_EXPECT_MSG_EQ (time, ref.time, "Time mismatch"); - NS_TEST_EXPECT_MSG_EQ (id, ref.node, "Node ID mismatch at time " << time.GetSeconds () << " s"); - NS_TEST_EXPECT_MSG_EQ (pos, ref.pos, "Position mismatch at time " << time.GetSeconds () << " s for node " << id); - NS_TEST_EXPECT_MSG_EQ (vel, ref.vel, "Velocity mismatch at time " << time.GetSeconds () << " s for node " << id); - } - /// Go - void DoRun () - { - NS_TEST_ASSERT_MSG_EQ (m_trace.empty (), false, "Need trace"); - NS_TEST_ASSERT_MSG_EQ (m_reference.empty (), false, "Need reference"); - - if (WriteTrace ()) - { - return; - } - CreateNodes (); - Ns2MobilityHelper mobility (m_traceFile); - mobility.Install (); - if (CheckInitialPositions ()) - { - return; - } - Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange", - MakeCallback (&Ns2MobilityHelperTest::CourseChange, this)); - Simulator::Stop (m_timeLimit); - Simulator::Run (); - Names::Clear (); - std::remove (m_traceFile.c_str ()); - Simulator::Destroy (); - } -}; - -/// The test suite -class Ns2MobilityHelperTestSuite : public TestSuite -{ -public: - Ns2MobilityHelperTestSuite () : TestSuite ("mobility-ns2-trace-helper", UNIT) - { - // to be used as temporary variable for test cases. - // Note that test suite takes care of deleting all test cases. - Ns2MobilityHelperTest * t (0); - - // Initial position - t = new Ns2MobilityHelperTest ("initial position", Seconds (1)); - t->SetTrace ("$node_(0) set X_ 1.0\n" - "$node_(0) set Y_ 2.0\n" - "$node_(0) set Z_ 3.0\n" - ); - t->AddReferencePoint ("0", 0, Vector (1, 2, 3), Vector (0, 0, 0)); - AddTestCase (t); - - // Check parsing comments, empty lines and no EOF at the end of file - t = new Ns2MobilityHelperTest ("comments", Seconds (1)); - t->SetTrace ("# comment\n" - "\n\n" // empty lines - "$node_(0) set X_ 1.0 # comment \n" - "$node_(0) set Y_ 2.0 ### \n" - "$node_(0) set Z_ 3.0 # $node_(0) set Z_ 3.0\n" - "#$node_(0) set Z_ 100 #" - ); - t->AddReferencePoint ("0", 0, Vector (1, 2, 3), Vector (0, 0, 0)); - AddTestCase (t); - - // Simple setdest. Arguments are interpreted as x, y, speed by default - t = new Ns2MobilityHelperTest ("simple setdest", Seconds (10)); - t->SetTrace ("$ns_ at 1.0 \"$node_(0) setdest 25 0 5\""); - // id t position velocity - t->AddReferencePoint ("0", 0, Vector (0, 0, 0), Vector (0, 0, 0)); - t->AddReferencePoint ("0", 1, Vector (0, 0, 0), Vector (5, 0, 0)); - t->AddReferencePoint ("0", 6, Vector (25, 0, 0), Vector (0, 0, 0)); - AddTestCase (t); - - // Several set and setdest. Arguments are interpreted as x, y, speed by default - t = new Ns2MobilityHelperTest ("square setdest", Seconds (6)); - t->SetTrace ("$node_(0) set X_ 0.0\n" - "$node_(0) set Y_ 0.0\n" - "$ns_ at 1.0 \"$node_(0) setdest 5 0 5\"\n" - "$ns_ at 2.0 \"$node_(0) setdest 5 5 5\"\n" - "$ns_ at 3.0 \"$node_(0) setdest 0 5 5\"\n" - "$ns_ at 4.0 \"$node_(0) setdest 0 0 5\"\n" - ); - // id t position velocity - t->AddReferencePoint ("0", 0, Vector (0, 0, 0), Vector (0, 0, 0)); - t->AddReferencePoint ("0", 1, Vector (0, 0, 0), Vector (5, 0, 0)); - t->AddReferencePoint ("0", 2, Vector (5, 0, 0), Vector (0, 0, 0)); - t->AddReferencePoint ("0", 2, Vector (5, 0, 0), Vector (0, 5, 0)); - t->AddReferencePoint ("0", 3, Vector (5, 5, 0), Vector (0, 0, 0)); - t->AddReferencePoint ("0", 3, Vector (5, 5, 0), Vector (-5, 0, 0)); - t->AddReferencePoint ("0", 4, Vector (0, 5, 0), Vector (0, 0, 0)); - t->AddReferencePoint ("0", 4, Vector (0, 5, 0), Vector (0, -5, 0)); - t->AddReferencePoint ("0", 5, Vector (0, 0, 0), Vector (0, 0, 0)); - AddTestCase (t); - - // Scheduled set position - t = new Ns2MobilityHelperTest ("scheduled set position", Seconds (2)); - t->SetTrace ("$ns_ at 1.0 \"$node_(0) set X_ 10\"\n" - "$ns_ at 1.0 \"$node_(0) set Z_ 10\"\n" - "$ns_ at 1.0 \"$node_(0) set Y_ 10\""); - // id t position velocity - t->AddReferencePoint ("0", 1, Vector (10, 0, 0), Vector (0, 0, 0)); - t->AddReferencePoint ("0", 1, Vector (10, 0, 10), Vector (0, 0, 0)); - t->AddReferencePoint ("0", 1, Vector (10, 10, 10), Vector (0, 0, 0)); - AddTestCase (t); - - // Malformed lines - t = new Ns2MobilityHelperTest ("malformed lines", Seconds (2)); - t->SetTrace ("$node() set X_ 1 # node id is not present\n" - "$node # incoplete line\"\n" - "$node this line is not correct\n" - "$node_(0) set X_ 1 # line OK \n" - "$node_(0) set Y_ 2 # line OK \n" - "$node_(0) set Z_ 3 # line OK \n" - "$ns_ at \"$node_(0) setdest 4 4 4\" # time not present\n" - "$ns_ at 1 \"$node_(0) setdest 2 2 1 \" # line OK \n"); - // id t position velocity - t->AddReferencePoint ("0", 0, Vector (1, 2, 3), Vector (0, 0, 0)); - t->AddReferencePoint ("0", 1, Vector (1, 2, 3), Vector (1, 0, 0)); - t->AddReferencePoint ("0", 2, Vector (2, 2, 3), Vector (0, 0, 0)); - AddTestCase (t); - - // Non possible values - t = new Ns2MobilityHelperTest ("non possible values", Seconds (2)); - t->SetTrace ("$node_(0) set X_ 1 # line OK \n" - "$node_(0) set Y_ 2 # line OK \n" - "$node_(0) set Z_ 3 # line OK \n" - "$node_(-22) set Y_ 3 # node id not correct\n" - "$node_(3.3) set Y_ 1111 # node id not correct\n" - "$ns_ at sss \"$node_(0) setdest 5 5 5\" # time is not a number\n" - "$ns_ at 1 \"$node_(0) setdest 2 2 1\" # line OK \n" - "$ns_ at 1 \"$node_(0) setdest 2 2 -1\" # negative speed is not correct\n" - "$ns_ at 1 \"$node_(0) setdest 2 2 sdfs\" # speed is not a number\n" - "$ns_ at 1 \"$node_(0) setdest 2 2 s232dfs\" # speed is not a number\n" - "$ns_ at 1 \"$node_(0) setdest 233 2.. s232dfs\" # more than one non numbers\n" - "$ns_ at -12 \"$node_(0) setdest 11 22 33\" # time should not be negative\n"); - // id t position velocity - t->AddReferencePoint ("0", 0, Vector (1, 2, 3), Vector (0, 0, 0)); - t->AddReferencePoint ("0", 1, Vector (1, 2, 3), Vector (1, 0, 0)); - t->AddReferencePoint ("0", 2, Vector (2, 2, 3), Vector (0, 0, 0)); - AddTestCase (t); - - // More than one node - t = new Ns2MobilityHelperTest ("few nodes, combinations of set and setdest", Seconds (10), 3); - t->SetTrace ("$node_(0) set X_ 1.0\n" - "$node_(0) set Y_ 2.0\n" - "$node_(0) set Z_ 3.0\n" - "$ns_ at 1.0 \"$node_(1) setdest 25 0 5\"\n" - "$node_(2) set X_ 0.0\n" - "$node_(2) set Y_ 0.0\n" - "$ns_ at 1.0 \"$node_(2) setdest 5 0 5\"\n" - "$ns_ at 2.0 \"$node_(2) setdest 5 5 5\"\n" - "$ns_ at 3.0 \"$node_(2) setdest 0 5 5\"\n" - "$ns_ at 4.0 \"$node_(2) setdest 0 0 5\"\n"); - // id t position velocity - t->AddReferencePoint ("0", 0, Vector (1, 2, 3), Vector (0, 0, 0)); - t->AddReferencePoint ("1", 0, Vector (0, 0, 0), Vector (0, 0, 0)); - t->AddReferencePoint ("1", 1, Vector (0, 0, 0), Vector (5, 0, 0)); - t->AddReferencePoint ("1", 6, Vector (25, 0, 0), Vector (0, 0, 0)); - t->AddReferencePoint ("2", 0, Vector (0, 0, 0), Vector (0, 0, 0)); - t->AddReferencePoint ("2", 1, Vector (0, 0, 0), Vector (5, 0, 0)); - t->AddReferencePoint ("2", 2, Vector (5, 0, 0), Vector (0, 0, 0)); - t->AddReferencePoint ("2", 2, Vector (5, 0, 0), Vector (0, 5, 0)); - t->AddReferencePoint ("2", 3, Vector (5, 5, 0), Vector (0, 0, 0)); - t->AddReferencePoint ("2", 3, Vector (5, 5, 0), Vector (-5, 0, 0)); - t->AddReferencePoint ("2", 4, Vector (0, 5, 0), Vector (0, 0, 0)); - t->AddReferencePoint ("2", 4, Vector (0, 5, 0), Vector (0, -5, 0)); - t->AddReferencePoint ("2", 5, Vector (0, 0, 0), Vector (0, 0, 0)); - AddTestCase (t); - - // Test for Speed == 0, that acts as stop the node. - t = new Ns2MobilityHelperTest ("setdest with speed cero", Seconds (10)); - t->SetTrace ("$ns_ at 1.0 \"$node_(0) setdest 25 0 5\"\n" - "$ns_ at 7.0 \"$node_(0) setdest 11 22 0\"\n"); - // id t position velocity - t->AddReferencePoint ("0", 0, Vector (0, 0, 0), Vector (0, 0, 0)); - t->AddReferencePoint ("0", 1, Vector (0, 0, 0), Vector (5, 0, 0)); - t->AddReferencePoint ("0", 6, Vector (25, 0, 0), Vector (0, 0, 0)); - t->AddReferencePoint ("0", 7, Vector (25, 0, 0), Vector (0, 0, 0)); - AddTestCase (t); - - - // Test negative positions - t = new Ns2MobilityHelperTest ("test negative positions", Seconds (10)); - t->SetTrace ("$node_(0) set X_ -1.0\n" - "$node_(0) set Y_ 0\n" - "$ns_ at 1.0 \"$node_(0) setdest 0 0 1\"\n" - "$ns_ at 2.0 \"$node_(0) setdest 0 -1 1\"\n"); - // id t position velocity - t->AddReferencePoint ("0", 0, Vector (-1, 0, 0), Vector (0, 0, 0)); - t->AddReferencePoint ("0", 1, Vector (-1, 0, 0), Vector (1, 0, 0)); - t->AddReferencePoint ("0", 2, Vector (0, 0, 0), Vector (0, 0, 0)); - t->AddReferencePoint ("0", 2, Vector (0, 0, 0), Vector (0, -1, 0)); - t->AddReferencePoint ("0", 3, Vector (0, -1, 0), Vector (0, 0, 0)); - AddTestCase (t); - - // Sqare setdest with values in the form 1.0e+2 - t = new Ns2MobilityHelperTest ("Foalt numbers in 1.0e+2 format", Seconds (6)); - t->SetTrace ("$node_(0) set X_ 0.0\n" - "$node_(0) set Y_ 0.0\n" - "$ns_ at 1.0 \"$node_(0) setdest 1.0e+2 0 1.0e+2\"\n" - "$ns_ at 2.0 \"$node_(0) setdest 1.0e+2 1.0e+2 1.0e+2\"\n" - "$ns_ at 3.0 \"$node_(0) setdest 0 1.0e+2 1.0e+2\"\n" - "$ns_ at 4.0 \"$node_(0) setdest 0 0 1.0e+2\"\n"); - // id t position velocity - t->AddReferencePoint ("0", 0, Vector (0, 0, 0), Vector (0, 0, 0)); - t->AddReferencePoint ("0", 1, Vector (0, 0, 0), Vector (100, 0, 0)); - t->AddReferencePoint ("0", 2, Vector (100, 0, 0), Vector (0, 0, 0)); - t->AddReferencePoint ("0", 2, Vector (100, 0, 0), Vector (0, 100, 0)); - t->AddReferencePoint ("0", 3, Vector (100, 100, 0), Vector (0, 0, 0)); - t->AddReferencePoint ("0", 3, Vector (100, 100, 0), Vector (-100, 0, 0)); - t->AddReferencePoint ("0", 4, Vector (0, 100, 0), Vector (0, 0, 0)); - t->AddReferencePoint ("0", 4, Vector (0, 100, 0), Vector (0, -100, 0)); - t->AddReferencePoint ("0", 5, Vector (0, 0, 0), Vector (0, 0, 0)); - AddTestCase (t); - - } -} g_ns2TransmobilityHelperTestSuite; - - } // namespace ns3 diff --git a/src/mobility/test/ns2-mobility-helper-test-suite.cc b/src/mobility/test/ns2-mobility-helper-test-suite.cc new file mode 100644 index 000000000..113303462 --- /dev/null +++ b/src/mobility/test/ns2-mobility-helper-test-suite.cc @@ -0,0 +1,417 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 INRIA + * 2009,2010 Contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Mathieu Lacage + * Contributors: Thomas Waldecker + * Martín Giachino + * + * Brief description: Implementation of a ns2 movement trace file reader. + * + * This implementation is based on the ns2 movement documentation of ns2 + * as described in http://www.isi.edu/nsnam/ns/doc/node174.html + * + * Valid trace files use the following ns2 statements: + * + * $node set X_ x1 + * $node set Y_ y1 + * $node set Z_ z1 + * $ns at $time $node setdest x2 y2 speed + * $ns at $time $node set X_ x1 + * $ns at $time $node set Y_ Y1 + * $ns at $time $node set Z_ Z1 + * + */ + +#include +#include "ns3/log.h" +#include "ns3/simulator.h" +#include "ns3/node-list.h" +#include "ns3/node.h" +#include "ns3/constant-velocity-mobility-model.h" +#include "ns3/test.h" +#include "ns3/node-container.h" +#include "ns3/names.h" +#include "ns3/config.h" +#include "ns3/ns2-mobility-helper.h" + +namespace ns3 { + +// ----------------------------------------------------------------------------- +// Testing +// ----------------------------------------------------------------------------- +bool operator== (Vector const & a, Vector const & b) +{ + return (a.x == b.x && a.y == b.y && a.z == b.z); +} +/** + * Every test case is supposed to: + * 1. Generate short mobility trace file + * 2. Read it back using Ns2MobilityHelper + * 3. Check initial node positions and speeds. + * 4. Run simulation listening for all CourseChange events and compare actual mobility with the reference + */ +class Ns2MobilityHelperTest : public TestCase +{ +public: + /// Single record in mobility reference + struct ReferencePoint + { + std::string node; ///< node ID as string, e.g. "1" + Time time; ///< timestamp + Vector pos; ///< reference position + Vector vel; ///< reference velocity + + ReferencePoint (std::string const & id, Time t, Vector const & p, Vector const & v) + : node (id), + time (t), + pos (p), + vel (v) + { + } + /// Sort by timestamp + bool operator< (ReferencePoint const & o) const + { + return (time < o.time); + } + }; + /** + * Create new test case. To make it useful SetTrace () and AddReferencePoint () must be called + * + * \param name Short description + * \param nodes Number of nodes used in the test trace, 1 by default + */ + Ns2MobilityHelperTest (std::string const & name, Time timeLimit, uint32_t nodes = 1) + : TestCase (name), + m_timeLimit (timeLimit), + m_nodeCount (nodes), + m_nextRefPoint (0) + { + } + /// Empty + virtual ~Ns2MobilityHelperTest () + { + } + /// Set NS-2 trace to read as single large string (don't forget to add \n and quote ") + void SetTrace (std::string const & trace) + { + m_trace = trace; + } + /// Add next reference point + void AddReferencePoint (ReferencePoint const & r) + { + m_reference.push_back (r); + } + /// Sugar + void AddReferencePoint (const char * id, double sec, Vector const & p, Vector const & v) + { + AddReferencePoint (ReferencePoint (id, Seconds (sec), p, v)); + } + +private: + /// Test time limit + Time m_timeLimit; + /// Number of nodes used in the test + uint32_t m_nodeCount; + /// Trace as string + std::string m_trace; + /// Reference mobility + std::vector m_reference; + /// Next reference point to be checked + size_t m_nextRefPoint; + /// TMP trace file name + std::string m_traceFile; + +private: + /// Dump NS-2 trace to tmp file + bool WriteTrace () + { + m_traceFile = GetTempDir () + "Ns2MobilityHelperTest.tcl"; + std::ofstream of (m_traceFile.c_str ()); + NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL (of.is_open (), true, "Need to write tmp. file"); + of << m_trace; + of.close (); + return false; // no errors + } + /// Create and name nodes + void CreateNodes () + { + NodeContainer nodes; + nodes.Create (m_nodeCount); + for (uint32_t i = 0; i < m_nodeCount; ++i) + { + std::ostringstream os; + os << i; + Names::Add (os.str (), nodes.Get (i)); + } + } + /// Check that all initial positions are correct + bool CheckInitialPositions () + { + std::stable_sort (m_reference.begin (), m_reference.end ()); + while (m_nextRefPoint < m_reference.size () && m_reference[m_nextRefPoint].time == Seconds (0)) + { + ReferencePoint const & rp = m_reference[m_nextRefPoint]; + Ptr node = Names::Find (rp.node); + NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL (node, 0, "Can't find node with id " << rp.node); + Ptr mob = node->GetObject (); + NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL (mob, 0, "Can't find mobility for node " << rp.node); + + NS_TEST_EXPECT_MSG_EQ (rp.pos, mob->GetPosition (), "Initial position mismatch for node " << rp.node); + NS_TEST_EXPECT_MSG_EQ (rp.vel, mob->GetVelocity (), "Initial velocity mismatch for node " << rp.node); + + m_nextRefPoint++; + } + return GetErrorStatus (); + } + /// Listen for course change events + void CourseChange (std::string context, Ptr mobility) + { + Time time = Simulator::Now (); + Ptr node = mobility->GetObject (); + NS_ASSERT (node); + std::string id = Names::FindName (node); + NS_ASSERT (!id.empty ()); + Vector pos = mobility->GetPosition (); + Vector vel = mobility->GetVelocity (); + + NS_TEST_EXPECT_MSG_LT (m_nextRefPoint, m_reference.size (), "Not enough reference points"); + if (m_nextRefPoint >= m_reference.size ()) + { + return; + } + + ReferencePoint const & ref = m_reference [m_nextRefPoint++]; + NS_TEST_EXPECT_MSG_EQ (time, ref.time, "Time mismatch"); + NS_TEST_EXPECT_MSG_EQ (id, ref.node, "Node ID mismatch at time " << time.GetSeconds () << " s"); + NS_TEST_EXPECT_MSG_EQ (pos, ref.pos, "Position mismatch at time " << time.GetSeconds () << " s for node " << id); + NS_TEST_EXPECT_MSG_EQ (vel, ref.vel, "Velocity mismatch at time " << time.GetSeconds () << " s for node " << id); + } + /// Go + void DoRun () + { + NS_TEST_ASSERT_MSG_EQ (m_trace.empty (), false, "Need trace"); + NS_TEST_ASSERT_MSG_EQ (m_reference.empty (), false, "Need reference"); + + if (WriteTrace ()) + { + return; + } + CreateNodes (); + Ns2MobilityHelper mobility (m_traceFile); + mobility.Install (); + if (CheckInitialPositions ()) + { + return; + } + Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange", + MakeCallback (&Ns2MobilityHelperTest::CourseChange, this)); + Simulator::Stop (m_timeLimit); + Simulator::Run (); + Names::Clear (); + std::remove (m_traceFile.c_str ()); + Simulator::Destroy (); + } +}; + +/// The test suite +class Ns2MobilityHelperTestSuite : public TestSuite +{ +public: + Ns2MobilityHelperTestSuite () : TestSuite ("mobility-ns2-trace-helper", UNIT) + { + // to be used as temporary variable for test cases. + // Note that test suite takes care of deleting all test cases. + Ns2MobilityHelperTest * t (0); + + // Initial position + t = new Ns2MobilityHelperTest ("initial position", Seconds (1)); + t->SetTrace ("$node_(0) set X_ 1.0\n" + "$node_(0) set Y_ 2.0\n" + "$node_(0) set Z_ 3.0\n" + ); + t->AddReferencePoint ("0", 0, Vector (1, 2, 3), Vector (0, 0, 0)); + AddTestCase (t); + + // Check parsing comments, empty lines and no EOF at the end of file + t = new Ns2MobilityHelperTest ("comments", Seconds (1)); + t->SetTrace ("# comment\n" + "\n\n" // empty lines + "$node_(0) set X_ 1.0 # comment \n" + "$node_(0) set Y_ 2.0 ### \n" + "$node_(0) set Z_ 3.0 # $node_(0) set Z_ 3.0\n" + "#$node_(0) set Z_ 100 #" + ); + t->AddReferencePoint ("0", 0, Vector (1, 2, 3), Vector (0, 0, 0)); + AddTestCase (t); + + // Simple setdest. Arguments are interpreted as x, y, speed by default + t = new Ns2MobilityHelperTest ("simple setdest", Seconds (10)); + t->SetTrace ("$ns_ at 1.0 \"$node_(0) setdest 25 0 5\""); + // id t position velocity + t->AddReferencePoint ("0", 0, Vector (0, 0, 0), Vector (0, 0, 0)); + t->AddReferencePoint ("0", 1, Vector (0, 0, 0), Vector (5, 0, 0)); + t->AddReferencePoint ("0", 6, Vector (25, 0, 0), Vector (0, 0, 0)); + AddTestCase (t); + + // Several set and setdest. Arguments are interpreted as x, y, speed by default + t = new Ns2MobilityHelperTest ("square setdest", Seconds (6)); + t->SetTrace ("$node_(0) set X_ 0.0\n" + "$node_(0) set Y_ 0.0\n" + "$ns_ at 1.0 \"$node_(0) setdest 5 0 5\"\n" + "$ns_ at 2.0 \"$node_(0) setdest 5 5 5\"\n" + "$ns_ at 3.0 \"$node_(0) setdest 0 5 5\"\n" + "$ns_ at 4.0 \"$node_(0) setdest 0 0 5\"\n" + ); + // id t position velocity + t->AddReferencePoint ("0", 0, Vector (0, 0, 0), Vector (0, 0, 0)); + t->AddReferencePoint ("0", 1, Vector (0, 0, 0), Vector (5, 0, 0)); + t->AddReferencePoint ("0", 2, Vector (5, 0, 0), Vector (0, 0, 0)); + t->AddReferencePoint ("0", 2, Vector (5, 0, 0), Vector (0, 5, 0)); + t->AddReferencePoint ("0", 3, Vector (5, 5, 0), Vector (0, 0, 0)); + t->AddReferencePoint ("0", 3, Vector (5, 5, 0), Vector (-5, 0, 0)); + t->AddReferencePoint ("0", 4, Vector (0, 5, 0), Vector (0, 0, 0)); + t->AddReferencePoint ("0", 4, Vector (0, 5, 0), Vector (0, -5, 0)); + t->AddReferencePoint ("0", 5, Vector (0, 0, 0), Vector (0, 0, 0)); + AddTestCase (t); + + // Scheduled set position + t = new Ns2MobilityHelperTest ("scheduled set position", Seconds (2)); + t->SetTrace ("$ns_ at 1.0 \"$node_(0) set X_ 10\"\n" + "$ns_ at 1.0 \"$node_(0) set Z_ 10\"\n" + "$ns_ at 1.0 \"$node_(0) set Y_ 10\""); + // id t position velocity + t->AddReferencePoint ("0", 1, Vector (10, 0, 0), Vector (0, 0, 0)); + t->AddReferencePoint ("0", 1, Vector (10, 0, 10), Vector (0, 0, 0)); + t->AddReferencePoint ("0", 1, Vector (10, 10, 10), Vector (0, 0, 0)); + AddTestCase (t); + + // Malformed lines + t = new Ns2MobilityHelperTest ("malformed lines", Seconds (2)); + t->SetTrace ("$node() set X_ 1 # node id is not present\n" + "$node # incoplete line\"\n" + "$node this line is not correct\n" + "$node_(0) set X_ 1 # line OK \n" + "$node_(0) set Y_ 2 # line OK \n" + "$node_(0) set Z_ 3 # line OK \n" + "$ns_ at \"$node_(0) setdest 4 4 4\" # time not present\n" + "$ns_ at 1 \"$node_(0) setdest 2 2 1 \" # line OK \n"); + // id t position velocity + t->AddReferencePoint ("0", 0, Vector (1, 2, 3), Vector (0, 0, 0)); + t->AddReferencePoint ("0", 1, Vector (1, 2, 3), Vector (1, 0, 0)); + t->AddReferencePoint ("0", 2, Vector (2, 2, 3), Vector (0, 0, 0)); + AddTestCase (t); + + // Non possible values + t = new Ns2MobilityHelperTest ("non possible values", Seconds (2)); + t->SetTrace ("$node_(0) set X_ 1 # line OK \n" + "$node_(0) set Y_ 2 # line OK \n" + "$node_(0) set Z_ 3 # line OK \n" + "$node_(-22) set Y_ 3 # node id not correct\n" + "$node_(3.3) set Y_ 1111 # node id not correct\n" + "$ns_ at sss \"$node_(0) setdest 5 5 5\" # time is not a number\n" + "$ns_ at 1 \"$node_(0) setdest 2 2 1\" # line OK \n" + "$ns_ at 1 \"$node_(0) setdest 2 2 -1\" # negative speed is not correct\n" + "$ns_ at 1 \"$node_(0) setdest 2 2 sdfs\" # speed is not a number\n" + "$ns_ at 1 \"$node_(0) setdest 2 2 s232dfs\" # speed is not a number\n" + "$ns_ at 1 \"$node_(0) setdest 233 2.. s232dfs\" # more than one non numbers\n" + "$ns_ at -12 \"$node_(0) setdest 11 22 33\" # time should not be negative\n"); + // id t position velocity + t->AddReferencePoint ("0", 0, Vector (1, 2, 3), Vector (0, 0, 0)); + t->AddReferencePoint ("0", 1, Vector (1, 2, 3), Vector (1, 0, 0)); + t->AddReferencePoint ("0", 2, Vector (2, 2, 3), Vector (0, 0, 0)); + AddTestCase (t); + + // More than one node + t = new Ns2MobilityHelperTest ("few nodes, combinations of set and setdest", Seconds (10), 3); + t->SetTrace ("$node_(0) set X_ 1.0\n" + "$node_(0) set Y_ 2.0\n" + "$node_(0) set Z_ 3.0\n" + "$ns_ at 1.0 \"$node_(1) setdest 25 0 5\"\n" + "$node_(2) set X_ 0.0\n" + "$node_(2) set Y_ 0.0\n" + "$ns_ at 1.0 \"$node_(2) setdest 5 0 5\"\n" + "$ns_ at 2.0 \"$node_(2) setdest 5 5 5\"\n" + "$ns_ at 3.0 \"$node_(2) setdest 0 5 5\"\n" + "$ns_ at 4.0 \"$node_(2) setdest 0 0 5\"\n"); + // id t position velocity + t->AddReferencePoint ("0", 0, Vector (1, 2, 3), Vector (0, 0, 0)); + t->AddReferencePoint ("1", 0, Vector (0, 0, 0), Vector (0, 0, 0)); + t->AddReferencePoint ("1", 1, Vector (0, 0, 0), Vector (5, 0, 0)); + t->AddReferencePoint ("1", 6, Vector (25, 0, 0), Vector (0, 0, 0)); + t->AddReferencePoint ("2", 0, Vector (0, 0, 0), Vector (0, 0, 0)); + t->AddReferencePoint ("2", 1, Vector (0, 0, 0), Vector (5, 0, 0)); + t->AddReferencePoint ("2", 2, Vector (5, 0, 0), Vector (0, 0, 0)); + t->AddReferencePoint ("2", 2, Vector (5, 0, 0), Vector (0, 5, 0)); + t->AddReferencePoint ("2", 3, Vector (5, 5, 0), Vector (0, 0, 0)); + t->AddReferencePoint ("2", 3, Vector (5, 5, 0), Vector (-5, 0, 0)); + t->AddReferencePoint ("2", 4, Vector (0, 5, 0), Vector (0, 0, 0)); + t->AddReferencePoint ("2", 4, Vector (0, 5, 0), Vector (0, -5, 0)); + t->AddReferencePoint ("2", 5, Vector (0, 0, 0), Vector (0, 0, 0)); + AddTestCase (t); + + // Test for Speed == 0, that acts as stop the node. + t = new Ns2MobilityHelperTest ("setdest with speed cero", Seconds (10)); + t->SetTrace ("$ns_ at 1.0 \"$node_(0) setdest 25 0 5\"\n" + "$ns_ at 7.0 \"$node_(0) setdest 11 22 0\"\n"); + // id t position velocity + t->AddReferencePoint ("0", 0, Vector (0, 0, 0), Vector (0, 0, 0)); + t->AddReferencePoint ("0", 1, Vector (0, 0, 0), Vector (5, 0, 0)); + t->AddReferencePoint ("0", 6, Vector (25, 0, 0), Vector (0, 0, 0)); + t->AddReferencePoint ("0", 7, Vector (25, 0, 0), Vector (0, 0, 0)); + AddTestCase (t); + + + // Test negative positions + t = new Ns2MobilityHelperTest ("test negative positions", Seconds (10)); + t->SetTrace ("$node_(0) set X_ -1.0\n" + "$node_(0) set Y_ 0\n" + "$ns_ at 1.0 \"$node_(0) setdest 0 0 1\"\n" + "$ns_ at 2.0 \"$node_(0) setdest 0 -1 1\"\n"); + // id t position velocity + t->AddReferencePoint ("0", 0, Vector (-1, 0, 0), Vector (0, 0, 0)); + t->AddReferencePoint ("0", 1, Vector (-1, 0, 0), Vector (1, 0, 0)); + t->AddReferencePoint ("0", 2, Vector (0, 0, 0), Vector (0, 0, 0)); + t->AddReferencePoint ("0", 2, Vector (0, 0, 0), Vector (0, -1, 0)); + t->AddReferencePoint ("0", 3, Vector (0, -1, 0), Vector (0, 0, 0)); + AddTestCase (t); + + // Sqare setdest with values in the form 1.0e+2 + t = new Ns2MobilityHelperTest ("Foalt numbers in 1.0e+2 format", Seconds (6)); + t->SetTrace ("$node_(0) set X_ 0.0\n" + "$node_(0) set Y_ 0.0\n" + "$ns_ at 1.0 \"$node_(0) setdest 1.0e+2 0 1.0e+2\"\n" + "$ns_ at 2.0 \"$node_(0) setdest 1.0e+2 1.0e+2 1.0e+2\"\n" + "$ns_ at 3.0 \"$node_(0) setdest 0 1.0e+2 1.0e+2\"\n" + "$ns_ at 4.0 \"$node_(0) setdest 0 0 1.0e+2\"\n"); + // id t position velocity + t->AddReferencePoint ("0", 0, Vector (0, 0, 0), Vector (0, 0, 0)); + t->AddReferencePoint ("0", 1, Vector (0, 0, 0), Vector (100, 0, 0)); + t->AddReferencePoint ("0", 2, Vector (100, 0, 0), Vector (0, 0, 0)); + t->AddReferencePoint ("0", 2, Vector (100, 0, 0), Vector (0, 100, 0)); + t->AddReferencePoint ("0", 3, Vector (100, 100, 0), Vector (0, 0, 0)); + t->AddReferencePoint ("0", 3, Vector (100, 100, 0), Vector (-100, 0, 0)); + t->AddReferencePoint ("0", 4, Vector (0, 100, 0), Vector (0, 0, 0)); + t->AddReferencePoint ("0", 4, Vector (0, 100, 0), Vector (0, -100, 0)); + t->AddReferencePoint ("0", 5, Vector (0, 0, 0), Vector (0, 0, 0)); + AddTestCase (t); + + } +} g_ns2TransmobilityHelperTestSuite; + + +} // namespace ns3 diff --git a/src/mobility/wscript b/src/mobility/wscript index ad76150b7..b065ae20c 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/ns2-mobility-helper-test-suite.cc', 'test/steady-state-random-waypoint-mobility-model-test.cc', 'test/waypoint-mobility-model-test.cc', ] diff --git a/src/network/model/net-device.h b/src/network/model/net-device.h index ea25c5ea6..c267ef0af 100644 --- a/src/network/model/net-device.h +++ b/src/network/model/net-device.h @@ -167,8 +167,7 @@ public: * encapsulated in an abstract Address to avoid dependencies on the exact * MAC address format. * - * A default implementation of GetMulticast is provided, but this - * method simply NS_ASSERTS. In the case of net devices that do not support + * In the case of net devices that do not support * multicast, clients are expected to test NetDevice::IsMulticast and avoid * attempting to map multicast packets. Subclasses of NetDevice that do * support multicasting are expected to override this method and provide an diff --git a/src/spectrum/model/spectrum-model.cc b/src/spectrum/model/spectrum-model.cc index 08f09f1cc..268cf3ec7 100644 --- a/src/spectrum/model/spectrum-model.cc +++ b/src/spectrum/model/spectrum-model.cc @@ -19,8 +19,9 @@ * Author: Nicola Baldo */ +#include +#include #include -#include #include #include diff --git a/src/test/csma-system-test-suite.cc b/src/test/csma-system-test-suite.cc index a66d257f0..43d4ef647 100644 --- a/src/test/csma-system-test-suite.cc +++ b/src/test/csma-system-test-suite.cc @@ -1094,7 +1094,7 @@ public: }; CsmaSystemTestSuite::CsmaSystemTestSuite () - : TestSuite ("csma-system", BVT) + : TestSuite ("csma-system", UNIT) { AddTestCase (new CsmaBridgeTestCase); AddTestCase (new CsmaBroadcastTestCase); diff --git a/src/test/error-model-test-suite.cc b/src/test/error-model-test-suite.cc index 47071979c..adeae95b9 100644 --- a/src/test/error-model-test-suite.cc +++ b/src/test/error-model-test-suite.cc @@ -122,7 +122,7 @@ public: }; ErrorModelTestSuite::ErrorModelTestSuite () - : TestSuite ("error-model", BVT) + : TestSuite ("error-model", UNIT) { AddTestCase (new ErrorModelSimple); } diff --git a/src/test/global-routing-test-suite.cc b/src/test/global-routing-test-suite.cc index 326760bec..5a78fa7ed 100644 --- a/src/test/global-routing-test-suite.cc +++ b/src/test/global-routing-test-suite.cc @@ -398,7 +398,7 @@ public: }; GlobalRoutingTestSuite::GlobalRoutingTestSuite () - : TestSuite ("global-routing", BVT) + : TestSuite ("global-routing", UNIT) { AddTestCase (new DynamicGlobalRoutingTestCase); AddTestCase (new GlobalRoutingSlash32TestCase); diff --git a/src/test/mobility-test-suite.cc b/src/test/mobility-test-suite.cc index abf771b73..cccf8a0b2 100644 --- a/src/test/mobility-test-suite.cc +++ b/src/test/mobility-test-suite.cc @@ -361,7 +361,7 @@ public: }; MobilityTestSuite::MobilityTestSuite () - : TestSuite ("mobility", BVT) + : TestSuite ("mobility", UNIT) { AddTestCase (new WaypointLazyNotifyFalse); AddTestCase (new WaypointLazyNotifyTrue); diff --git a/src/test/sample-test-suite.cc b/src/test/sample-test-suite.cc index 3a667540a..c10f2bf3f 100644 --- a/src/test/sample-test-suite.cc +++ b/src/test/sample-test-suite.cc @@ -54,7 +54,7 @@ public: }; SampleTestSuite::SampleTestSuite () - : TestSuite ("sample", BVT) + : TestSuite ("sample", UNIT) { AddTestCase (new SampleTestCase1); } diff --git a/src/test/static-routing-test-suite.cc b/src/test/static-routing-test-suite.cc index b9f3c006e..7c4e05297 100644 --- a/src/test/static-routing-test-suite.cc +++ b/src/test/static-routing-test-suite.cc @@ -164,7 +164,7 @@ public: }; StaticRoutingTestSuite::StaticRoutingTestSuite () - : TestSuite ("static-routing", BVT) + : TestSuite ("static-routing", UNIT) { AddTestCase (new StaticRoutingSlash32TestCase); } diff --git a/src/wifi/helper/yans-wifi-helper.cc b/src/wifi/helper/yans-wifi-helper.cc index 8ac0d45fc..5dce690d5 100644 --- a/src/wifi/helper/yans-wifi-helper.cc +++ b/src/wifi/helper/yans-wifi-helper.cc @@ -278,16 +278,31 @@ PcapSniffTxEvent ( header.SetFrameFlags (frameFlags); header.SetRate (rate); + uint16_t channelFlags = 0; + switch (rate) + { + case 2: // 1Mbps + case 4: // 2Mbps + case 10: // 5Mbps + case 22: // 11Mbps + channelFlags |= RadiotapHeader::CHANNEL_FLAG_CCK; + break; + + default: + channelFlags |= RadiotapHeader::CHANNEL_FLAG_OFDM; + break; + } + if (channelFreqMhz < 2500) { - header.SetChannelFrequencyAndFlags (channelFreqMhz, - RadiotapHeader::CHANNEL_FLAG_SPECTRUM_2GHZ | RadiotapHeader::CHANNEL_FLAG_CCK); + channelFlags |= RadiotapHeader::CHANNEL_FLAG_SPECTRUM_2GHZ; } else { - header.SetChannelFrequencyAndFlags (channelFreqMhz, - RadiotapHeader::CHANNEL_FLAG_SPECTRUM_5GHZ | RadiotapHeader::CHANNEL_FLAG_OFDM); + channelFlags |= RadiotapHeader::CHANNEL_FLAG_SPECTRUM_5GHZ; } + + header.SetChannelFrequencyAndFlags (channelFreqMhz, channelFlags); p->AddHeader (header); file->Write (Simulator::Now (), p); @@ -339,16 +354,31 @@ PcapSniffRxEvent ( header.SetFrameFlags (frameFlags); header.SetRate (rate); + uint16_t channelFlags = 0; + switch (rate) + { + case 2: // 1Mbps + case 4: // 2Mbps + case 10: // 5Mbps + case 22: // 11Mbps + channelFlags |= RadiotapHeader::CHANNEL_FLAG_CCK; + break; + + default: + channelFlags |= RadiotapHeader::CHANNEL_FLAG_OFDM; + break; + } + if (channelFreqMhz < 2500) { - header.SetChannelFrequencyAndFlags (channelFreqMhz, - RadiotapHeader::CHANNEL_FLAG_SPECTRUM_2GHZ | RadiotapHeader::CHANNEL_FLAG_CCK); + channelFlags |= RadiotapHeader::CHANNEL_FLAG_SPECTRUM_2GHZ; } else { - header.SetChannelFrequencyAndFlags (channelFreqMhz, - RadiotapHeader::CHANNEL_FLAG_SPECTRUM_5GHZ | RadiotapHeader::CHANNEL_FLAG_OFDM); + channelFlags |= RadiotapHeader::CHANNEL_FLAG_SPECTRUM_5GHZ; } + + header.SetChannelFrequencyAndFlags (channelFreqMhz, channelFlags); header.SetAntennaSignalPower (signalDbm); header.SetAntennaNoisePower (noiseDbm); diff --git a/src/wifi/model/dca-txop.cc b/src/wifi/model/dca-txop.cc index ffc78e9e0..4bc442ece 100644 --- a/src/wifi/model/dca-txop.cc +++ b/src/wifi/model/dca-txop.cc @@ -24,6 +24,7 @@ #include "ns3/simulator.h" #include "ns3/node.h" #include "ns3/uinteger.h" +#include "ns3/pointer.h" #include "dca-txop.h" #include "dcf-manager.h" @@ -102,6 +103,10 @@ DcaTxop::GetTypeId (void) static TypeId tid = TypeId ("ns3::DcaTxop") .SetParent (ns3::Dcf::GetTypeId ()) .AddConstructor () + .AddAttribute ("Queue", "The WifiMacQueue object", + PointerValue (), + MakePointerAccessor (&DcaTxop::GetQueue), + MakePointerChecker ()) ; return tid; } @@ -171,18 +176,13 @@ DcaTxop::SetTxFailedCallback (TxFailed callback) m_txFailedCallback = callback; } -void -DcaTxop::SetMaxQueueSize (uint32_t size) +Ptr +DcaTxop::GetQueue () const { - NS_LOG_FUNCTION (this << size); - m_queue->SetMaxSize (size); -} -void -DcaTxop::SetMaxQueueDelay (Time delay) -{ - NS_LOG_FUNCTION (this << delay); - m_queue->SetMaxDelay (delay); + NS_LOG_FUNCTION (this); + return m_queue; } + void DcaTxop::SetMinCw (uint32_t minCw) { diff --git a/src/wifi/model/dca-txop.h b/src/wifi/model/dca-txop.h index c4d8d5463..97739c596 100644 --- a/src/wifi/model/dca-txop.h +++ b/src/wifi/model/dca-txop.h @@ -89,8 +89,7 @@ public: */ void SetTxFailedCallback (TxFailed callback); - void SetMaxQueueSize (uint32_t size); - void SetMaxQueueDelay (Time delay); + Ptr GetQueue () const; virtual void SetMinCw (uint32_t minCw); virtual void SetMaxCw (uint32_t maxCw); virtual void SetAifsn (uint32_t aifsn); diff --git a/src/wifi/model/edca-txop-n.cc b/src/wifi/model/edca-txop-n.cc index 2a6e38d22..d57d67a34 100644 --- a/src/wifi/model/edca-txop-n.cc +++ b/src/wifi/model/edca-txop-n.cc @@ -21,6 +21,7 @@ */ #include "ns3/log.h" #include "ns3/assert.h" +#include "ns3/pointer.h" #include "edca-txop-n.h" #include "mac-low.h" @@ -138,6 +139,10 @@ EdcaTxopN::GetTypeId (void) UintegerValue(0), MakeUintegerAccessor (&EdcaTxopN::SetBlockAckInactivityTimeout), MakeUintegerChecker ()) + .AddAttribute ("Queue", "The WifiMacQueue object", + PointerValue (), + MakePointerAccessor (&EdcaTxopN::GetQueue), + MakePointerChecker ()) ; return tid; } @@ -230,18 +235,11 @@ EdcaTxopN::GetTypeOfStation (void) const return m_typeOfStation; } -void -EdcaTxopN::SetMaxQueueSize (uint32_t size) +Ptr +EdcaTxopN::GetQueue () const { - NS_LOG_FUNCTION (this << size); - m_queue->SetMaxSize (size); -} - -void -EdcaTxopN::SetMaxQueueDelay (Time delay) -{ - NS_LOG_FUNCTION (this << delay); - m_queue->SetMaxDelay (delay); + NS_LOG_FUNCTION (this); + return m_queue; } void diff --git a/src/wifi/model/edca-txop-n.h b/src/wifi/model/edca-txop-n.h index b0a92d62b..c269a4b54 100644 --- a/src/wifi/model/edca-txop-n.h +++ b/src/wifi/model/edca-txop-n.h @@ -93,8 +93,7 @@ public: void SetTypeOfStation (enum TypeOfStation type); enum TypeOfStation GetTypeOfStation (void) const; - void SetMaxQueueSize (uint32_t size); - void SetMaxQueueDelay (Time delay); + Ptr GetQueue () const; virtual void SetMinCw (uint32_t minCw); virtual void SetMaxCw (uint32_t maxCw); virtual void SetAifsn (uint32_t aifsn); diff --git a/src/wifi/model/regular-wifi-mac.cc b/src/wifi/model/regular-wifi-mac.cc index 0e73406f5..e059fe31c 100644 --- a/src/wifi/model/regular-wifi-mac.cc +++ b/src/wifi/model/regular-wifi-mac.cc @@ -423,7 +423,18 @@ RegularWifiMac::Receive (Ptr packet, const WifiMacHeader *hdr) Mac48Address to = hdr->GetAddr1 (); Mac48Address from = hdr->GetAddr2 (); - if (hdr->IsMgt () && hdr->IsAction () && to == GetAddress ()) + // We don't know how to deal with any frame that is not addressed to + // us (and odds are there is nothing sensible we could do anyway), + // so we ignore such frames. + // + // The derived class may also do some such filtering, but it doesn't + // hurt to have it here too as a backstop. + if (to != GetAddress ()) + { + return; + } + + if (hdr->IsMgt () && hdr->IsAction ()) { // There is currently only any reason for Management Action // frames to be flying about if we are a QoS STA. diff --git a/src/wscript b/src/wscript index afc207997..52bef2d17 100644 --- a/src/wscript +++ b/src/wscript @@ -95,12 +95,16 @@ def configure(conf): conf.env['NS3_MODULES'] = ['ns3-' + module.split('/')[-1] for module in all_modules] -def create_ns3_module(bld, name, dependencies=()): +def create_ns3_module(bld, name, dependencies=(), test=False): # Create a separate library for this module. if bld.env['ENABLE_STATIC_NS3']: module = bld.new_task_gen('cxx', 'cstaticlib') else: module = bld.new_task_gen('cxx', 'cshlib') + if not test: + pcfile = bld.new_task_gen('ns3pcfile') + pcfile.module = module + module.is_ns3_module = True module.name = 'ns3-' + name # Add the proper path to the module's name. @@ -136,7 +140,7 @@ def create_ns3_module_test_library(bld, name): # Create an ns3 module for the test library that depends only on # the module being tested. library_name = name + "-test" - library = bld.create_ns3_module(library_name, [name]) + library = bld.create_ns3_module(library_name, [name], test = True) # Modify attributes for the test library that are different from a # normal module. @@ -276,6 +280,100 @@ def build(bld): modheader = bld.new_task_gen('ns3moduleheader') modheader.module = module.split('/')[-1] +class ns3pcfile_task(Task.Task): + after = 'cc cxx' + def __str__(self): + "string to display to the user" + tgt_str = ' '.join([a.nice_path(self.env) for a in self.outputs]) + return 'pcfile: %s\n' % (tgt_str) + def runnable_status(self): + return super(ns3pcfile_task, self).runnable_status() + def _self_libs(self, env, name, libdir): + if env['ENABLE_STATIC_NS3']: + path_st = 'STATICLIBPATH_ST' + lib_st = 'STATICLIB_ST' + lib_marker = 'STATICLIB_MARKER' + else: + path_st = 'LIBPATH_ST' + lib_st = 'LIB_ST' + lib_marker = 'SHLIB_MARKER' + return [env[path_st] % libdir, + env[lib_marker], + env[lib_st] % name] + def _lib(self, env, dep): + libpath = env['LIBPATH_%s' % dep] + linkflags = env['LINKFLAGS_%s' % dep] + libs = env['LIB_%s' % dep] + retval = [] + for path in libpath: + retval.append(env['LIBPATH_ST'] % path) + retval = retval + linkflags + for lib in libs: + retval.append(env['LIB_ST'] % lib) + return retval + def _listify(self, v): + if isinstance(v, list): + return v + else: + return [v] + def _cflags(self, dep): + flags = self.env['CFLAGS_%s' % dep] + return self._listify(flags) + def _cxxflags(self, dep): + return self._listify(self.env['CXXFLAGS_%s' % dep]) + def _defines(self, dep): + defines = self.env['CCDEFINES_%s' % dep] + self.env['CXXDEFINES_%s' % dep] + return [self.env['CCDEFINES_ST'] % define for define in self.env['CCDEFINES_%s' % dep]] + \ + [self.env['CXXDEFINES_ST'] % define for define in self.env['CXXDEFINES_%s' % dep]] + def _includes(self, dep): + includes = self.env['CPPPATH_%s' % dep] + return [self.env['CPPPATH_ST'] % include for include in includes] + + def _generate_pcfile(self, name, use, uselib_local, prefix, outfilename): + outfile = open(outfilename, 'w') + includedir = os.path.join(prefix, 'include') + libdir = os.path.join(prefix, 'lib') + libs = self._self_libs(self.env, name, '%{libdir}') + for dep in use: + libs = libs + self._lib(self.env, dep) + for dep in uselib_local: + libs = libs + [self.env['LIB_ST'] % dep] + cflags = [self.env['CPPPATH_ST'] % '${includedir}'] + for dep in use: + cflags = cflags + self._cflags(dep) + self._cxxflags(dep) + \ + self._defines(dep) + self._includes(dep) + print >> outfile, """ +prefix=%s +libdir=%s +includedir=%s + +Name: lib%s +Description: ns-3 module %s +Version: devel +Libs: %s +Cflags: %s +""" % (prefix, libdir, includedir, + name, name, ' '.join(libs), ' '.join(cflags)) + outfile.close() + + def run(self): + output_filename = self.outputs[0].bldpath(self.env) + self._generate_pcfile(self.module.name, self.module.uselib, + self.module.uselib_local, + self.env['PREFIX'], output_filename) + +class ns3pcfile_taskgen(TaskGen.task_gen): + def __init__(self, *args, **kwargs): + super(ns3pcfile_taskgen, self).__init__(*args, **kwargs) + def apply(self): + output_filename = os.path.join('pkgconfig', 'lib%s.pc' % self.module.name) + output_node = self.bld.path.find_or_declare(output_filename) + task = self.create_task('ns3pcfile', env=self.env) + self.bld.install_files(os.path.join('${PREFIX}', 'lib', 'pkgconfig'), + output_filename) + task.set_outputs([output_node]) + task.module = self.module + class ns3header_taskgen(TaskGen.task_gen): """A set of NS-3 header files""" @@ -359,7 +457,6 @@ class ns3header_task(Task.Task): if ex.errno != 2: raise return 0 - class gen_ns3_module_header_task(Task.Task): diff --git a/utils/check-style.py b/utils/check-style.py index 2544e3091..c42884bf0 100755 --- a/utils/check-style.py +++ b/utils/check-style.py @@ -87,7 +87,6 @@ sp_after_semi_for=Add sp_arith=Add sp_assign=Add sp_compare=Add -sp_cmt_cpp_start=Add sp_func_class_paren=Add sp_after_type=Add sp_type_func=Add