do not use DefaultValues in simulator

This commit is contained in:
Mathieu Lacage
2008-03-03 20:47:12 +01:00
parent 81b8f0f159
commit 59df24f63f
11 changed files with 86 additions and 240 deletions

View File

@@ -173,8 +173,6 @@ Experiment::Run (const WifiHelper &wifi)
int main (int argc, char *argv[])
{
Simulator::SetLinkedList ();
// disable fragmentation
Config::SetDefault ("WifiRemoteStationManager::FragmentationThreshold", String ("2200"));
Config::SetDefault ("WifiRemoteStationManager::RtsCtsThreshold", String ("2200"));

View File

@@ -103,8 +103,6 @@ AdvancePosition (Ptr<Node> node)
int main (int argc, char *argv[])
{
Simulator::SetLinkedList ();
Packet::EnableMetadata ();
// enable rts cts all the time.

View File

@@ -26,4 +26,13 @@ namespace ns3 {
Scheduler::~Scheduler ()
{}
}; // namespace ns3
TypeId
Scheduler::GetTypeId (void)
{
static TypeId tid = TypeId ("Scheduler")
.SetParent<Object> ()
;
return tid;
}
} // namespace ns3

View File

@@ -23,6 +23,7 @@
#include <stdint.h>
#include "event-id.h"
#include "ns3/object.h"
namespace ns3 {
@@ -47,8 +48,11 @@ namespace ns3 {
* scheduler included in ns3: see the files
* src/simulator/scheduler-list.h and src/simulator/scheduler-list.cc
*/
class Scheduler {
class Scheduler : public Object
{
public:
static TypeId GetTypeId (void);
struct EventKey {
uint64_t m_ts;
uint32_t m_uid;

View File

@@ -24,7 +24,6 @@
#include "ns3/ptr.h"
#include "ns3/assert.h"
#include "ns3/default-value.h"
#include <math.h>
@@ -50,9 +49,12 @@ std::cout << "SIMU TRACE " << x << std::endl;
namespace ns3 {
class SimulatorPrivate {
class SimulatorPrivate : public Object
{
public:
SimulatorPrivate (Scheduler *events);
static TypeId GetTypeId (void);
SimulatorPrivate ();
~SimulatorPrivate ();
void EnableLogTo (char const *filename);
@@ -72,6 +74,9 @@ public:
Time GetDelayLeft (const EventId &id) const;
Time GetMaximumSimulationTime (void) const;
void SetScheduler (Ptr<Scheduler> scheduler);
Ptr<Scheduler> GetScheduler (void) const;
private:
void ProcessOneEvent (void);
uint64_t NextTs (void) const;
@@ -80,7 +85,7 @@ private:
DestroyEvents m_destroyEvents;
uint64_t m_stopAt;
bool m_stop;
Scheduler *m_events;
Ptr<Scheduler> m_events;
uint32_t m_uid;
uint32_t m_currentUid;
uint64_t m_currentTs;
@@ -93,13 +98,26 @@ private:
};
TypeId
SimulatorPrivate::GetTypeId (void)
{
static TypeId tid = TypeId ("SimulatorPrivate")
.SetParent<Object> ()
.AddConstructor<SimulatorPrivate> ()
.AddAttribute ("Scheduler",
"XXX",
Ptr<Scheduler> (0),
// XXX: allow getting the scheduler too.
MakePtrAccessor (&SimulatorPrivate::SetScheduler),
MakePtrChecker<Scheduler> ())
;
return tid;
}
SimulatorPrivate::SimulatorPrivate (Scheduler *events)
SimulatorPrivate::SimulatorPrivate ()
{
m_stop = false;
m_stopAt = 0;
m_events = events;
// uids are allocated from 4.
// uid 0 is "invalid" events
// uid 1 is "now" events
@@ -128,10 +146,28 @@ SimulatorPrivate::~SimulatorPrivate ()
{
EventId next = m_events->RemoveNext ();
}
delete m_events;
m_events = (Scheduler *)0xdeadbeaf;
m_events = 0;
}
void
SimulatorPrivate::SetScheduler (Ptr<Scheduler> scheduler)
{
if (m_events != 0)
{
while (!m_events->IsEmpty ())
{
EventId next = m_events->RemoveNext ();
scheduler->Insert (next);
}
}
m_events = scheduler;
}
Ptr<Scheduler>
SimulatorPrivate::GetScheduler (void) const
{
return m_events;
}
void
SimulatorPrivate::EnableLogTo (char const *filename)
@@ -361,22 +397,9 @@ namespace ns3 {
SimulatorPrivate *Simulator::m_priv = 0;
void Simulator::SetLinkedList (void)
void Simulator::SetScheduler (Ptr<Scheduler> scheduler)
{
DefaultValue::Bind ("Scheduler", "List");
}
void Simulator::SetBinaryHeap (void)
{
DefaultValue::Bind ("Scheduler", "BinaryHeap");
}
void Simulator::SetStdMap (void)
{
DefaultValue::Bind ("Scheduler", "Map");
}
void
Simulator::SetExternal (const std::string &external)
{
DefaultValue::Bind ("Scheduler", external);
GetPriv ()->SetScheduler (scheduler);
}
void Simulator::EnableLogTo (char const *filename)
{
@@ -389,8 +412,9 @@ Simulator::GetPriv (void)
{
if (m_priv == 0)
{
Scheduler *events = SchedulerFactory::CreateDefault ();
m_priv = new SimulatorPrivate (events);
m_priv = new SimulatorPrivate ();
Ptr<Scheduler> scheduler = CreateObject<SchedulerMap> ();
m_priv->SetScheduler (scheduler);
}
TRACE_S ("priv " << m_priv);
return m_priv;
@@ -900,19 +924,19 @@ SimulatorTests::RunTests (void)
bool result = true;
Simulator::Destroy ();
Simulator::SetLinkedList ();
Simulator::SetScheduler (CreateObject<SchedulerList> ());
if (!RunOneTest ())
{
result = false;
}
Simulator::Destroy ();
Simulator::SetBinaryHeap ();
Simulator::SetScheduler (CreateObject<SchedulerHeap> ());
if (!RunOneTest ())
{
result = false;
}
Simulator::Destroy ();
Simulator::SetStdMap ();
Simulator::SetScheduler (CreateObject<SchedulerMap> ());
if (!RunOneTest ())
{
result = false;

View File

@@ -25,6 +25,7 @@
#include "event-id.h"
#include "event-impl.h"
#include "nstime.h"
#include "scheduler.h"
#include "ns3/type-traits.h"
namespace ns3 {
@@ -58,29 +59,9 @@ public:
*/
static void EnableParallelSimulation (void);
/**
* Force the use of an event scheduler based on a linked-list.
* This method must be invoked before any other method exported
* by the Simulator class.
* - insert: O(n)
* - remove: O(1)
* XXX
*/
static void SetLinkedList (void);
/**
* Force the use of an event scheduler based on a binary heap.
* This method must be invoked before any other method exported
* by the Simulator class.
* - insert: O(log(n))
* - remove: O(log(n))
*/
static void SetBinaryHeap (void);
/**
* Force the use of an event scheduler based on a std::map.
* This method must be invoked before any other method exported
* by the Simulator class.
* - insert: O(log(n))
* - remove: O(log(n))
*/
static void SetStdMap (void);
static void SetScheduler (Ptr<Scheduler> scheduler);
/**
* Force the use of a user-provided event scheduler.

View File

@@ -1,105 +0,0 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007 INRIA
*
* 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 <mathieu.lacage@sophia.inria.fr>
*/
#include "time-default-value.h"
namespace ns3 {
TimeDefaultValue::TimeDefaultValue (const std::string name,
const std::string help,
Time defaultValue)
: DefaultValueBase (name, help),
m_defaultValue (defaultValue),
m_value (defaultValue)
{
DefaultValueList::Add (this);
}
Time
TimeDefaultValue::GetValue (void) const
{
return m_value;
}
bool
TimeDefaultValue::DoParseValue (const std::string &value)
{
std::string::size_type n = value.find_first_not_of("0123456789.");
if (n == std::string::npos)
{
return false;
}
std::string trailer = value.substr(n, std::string::npos);
std::istringstream iss;
iss.str (value.substr(0, n));
if (trailer == std::string("s"))
{
double v;
iss >> v;
m_value = Seconds (v);
return !iss.bad () && !iss.fail ();
}
uint64_t integer;
iss >> integer;
if (iss.bad () || iss.fail ())
{
return false;
}
if (trailer == std::string("ms"))
{
m_value = MilliSeconds (integer);
return true;
}
if (trailer == std::string("us"))
{
m_value = MicroSeconds (integer);
return true;
}
if (trailer == std::string("ns"))
{
m_value = NanoSeconds (integer);
return true;
}
if (trailer == std::string("ps"))
{
m_value = PicoSeconds (integer);
return true;
}
if (trailer == std::string("fs"))
{
m_value = FemtoSeconds (integer);
return true;
}
return false;
}
std::string
TimeDefaultValue::DoGetType (void) const
{
return "(s|ms|us|ns|ps|fs)";
}
std::string
TimeDefaultValue::DoGetDefaultValue (void) const
{
std::ostringstream oss;
oss << m_value.GetSeconds () << "s";
return oss.str ();
}
} // namespace ns3

View File

@@ -1,69 +0,0 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007 INRIA
*
* 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 <mathieu.lacage@sophia.inria.fr>
*/
#ifndef TIME_DEFAULT_VALUE_H
#define TIME_DEFAULT_VALUE_H
#include "ns3/default-value.h"
#include "ns3/nstime.h"
namespace ns3 {
/**
* \ingroup config
* \brief a ns3::Time variable for ns3::Bind
*
* Every instance of this type is automatically
* registered in the variable pool which is used
* by ns3::Bind.
*/
class TimeDefaultValue : public DefaultValueBase
{
public:
/**
* \param name name of variable
* \param help help text which explains the purpose
* and the semantics of this variable
* \param defaultValue the default value to assign
* to this variable.
*
* Unless the user invokes ns3::Bind with the right arguments,
* the GetValue method will return the default value. Otherwise,
* it will return the user-specified value.
*/
TimeDefaultValue (const std::string name,
const std::string help,
Time defaultValue);
/**
* \returns the default value for this variable or a
* user-provided overriden variable.
*/
Time GetValue (void) const;
private:
virtual bool DoParseValue (const std::string &value);
virtual std::string DoGetType (void) const;
virtual std::string DoGetDefaultValue (void) const;
Time m_defaultValue;
Time m_value;
};
} // namespace ns3
#endif /* TIME_DEFAULT_VALUE_H */

View File

@@ -59,7 +59,6 @@ def build(bld):
'scheduler-map.cc',
'event-impl.cc',
'simulator.cc',
'time-default-value.cc',
'timer.cc',
'watchdog.cc',
]
@@ -72,9 +71,10 @@ def build(bld):
'event-impl.h',
'simulator.h',
'scheduler.h',
'scheduler-factory.h',
'scheduler-list.h',
'scheduler-map.h',
'scheduler-heap.h',
'simulation-singleton.h',
'time-default-value.h',
'timer.h',
'timer-impl.h',
'watchdog.h',

View File

@@ -20,6 +20,9 @@
*/
#include "ns3/simulator.h"
#include "ns3/scheduler-list.h"
#include "ns3/scheduler-map.h"
#include "ns3/scheduler-heap.h"
#include "ns3/system-wall-clock-ms.h"
#include <iostream>
#include <fstream>
@@ -159,15 +162,15 @@ int main (int argc, char *argv[])
{
if (strcmp ("--list", argv[0]) == 0)
{
Simulator::SetLinkedList ();
Simulator::SetScheduler (CreateObject<SchedulerList> ());
}
else if (strcmp ("--heap", argv[0]) == 0)
{
Simulator::SetBinaryHeap ();
Simulator::SetScheduler (CreateObject<SchedulerHeap> ());
}
else if (strcmp ("--map", argv[0]) == 0)
{
Simulator::SetStdMap ();
Simulator::SetScheduler (CreateObject<SchedulerMap> ());
}
else if (strcmp ("--debug", argv[0]) == 0)
{

View File

@@ -20,6 +20,9 @@
*/
#include "ns3/simulator.h"
#include "ns3/scheduler-list.h"
#include "ns3/scheduler-map.h"
#include "ns3/scheduler-heap.h"
#include "ns3/nstime.h"
#include "ns3/system-wall-clock-ms.h"
#include <vector>
@@ -315,15 +318,15 @@ int main (int argc, char *argv[])
{
if (is_map)
{
Simulator::SetStdMap ();
Simulator::SetScheduler (CreateObject<SchedulerMap> ());
}
else if (is_list)
{
Simulator::SetLinkedList ();
Simulator::SetScheduler (CreateObject<SchedulerList> ());
}
else if (is_heap)
{
Simulator::SetBinaryHeap ();
Simulator::SetScheduler (CreateObject<SchedulerHeap> ());
}
log.Run ();
Simulator::Destroy ();