--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/contrib/event-garbage-collector.cc Fri Dec 07 08:43:55 2007 +0100
@@ -0,0 +1,153 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2007 INESC Porto
+ *
+ * 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: Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
+ */
+#include "event-garbage-collector.h"
+
+#define CLEANUP_CHUNK_MIN_SIZE 8
+#define CLEANUP_CHUNK_MAX_SIZE 128
+
+
+namespace ns3 {
+
+
+EventGarbageCollector::EventGarbageCollector () :
+ m_nextCleanupSize (CLEANUP_CHUNK_MIN_SIZE)
+{}
+
+void
+EventGarbageCollector::Track (EventId event)
+{
+ m_events.insert (event);
+ if (m_events.size () >= m_nextCleanupSize)
+ Cleanup ();
+}
+
+void
+EventGarbageCollector::Grow ()
+{
+ m_nextCleanupSize += (m_nextCleanupSize < CLEANUP_CHUNK_MAX_SIZE?
+ m_nextCleanupSize : CLEANUP_CHUNK_MAX_SIZE);
+}
+
+void
+EventGarbageCollector::Shrink ()
+{
+ while (m_nextCleanupSize > m_events.size ())
+ m_nextCleanupSize >>= 1;
+ Grow ();
+}
+
+// Called when a new event was added and the cleanup limit was exceeded in consequence.
+void
+EventGarbageCollector::Cleanup ()
+{
+ for (EventList::iterator iter = m_events.begin (); iter != m_events.end ();)
+ {
+ if ((*iter).IsExpired ())
+ {
+ m_events.erase (iter++);
+ }
+ else
+ break; // EventIds are sorted by timestamp => further events are not expired for sure
+ }
+
+ // If after cleanup we are still over the limit, increase the limit.
+ if (m_events.size () >= m_nextCleanupSize)
+ Grow ();
+ else
+ Shrink ();
+}
+
+
+EventGarbageCollector::~EventGarbageCollector ()
+{
+ for (EventList::iterator event = m_events.begin ();
+ event != m_events.end (); event++)
+ {
+ Simulator::Cancel (*event);
+ }
+}
+
+}; // namespace ns3
+
+
+
+#ifdef RUN_SELF_TESTS
+
+#include "ns3/test.h"
+
+namespace ns3 {
+
+class EventGarbageCollectorTests : public Test
+{
+ int m_counter;
+ EventGarbageCollector *m_events;
+
+ void EventGarbageCollectorCallback ();
+
+public:
+
+ EventGarbageCollectorTests ();
+ virtual ~EventGarbageCollectorTests ();
+ virtual bool RunTests (void);
+};
+
+EventGarbageCollectorTests::EventGarbageCollectorTests ()
+ : Test ("EventGarbageCollector"), m_counter (0), m_events (0)
+{}
+
+EventGarbageCollectorTests::~EventGarbageCollectorTests ()
+{}
+
+void
+EventGarbageCollectorTests::EventGarbageCollectorCallback ()
+{
+ m_counter++;
+ if (m_counter == 50)
+ {
+ // this should cause the remaining (50) events to be cancelled
+ delete m_events;
+ m_events = 0;
+ }
+}
+
+bool EventGarbageCollectorTests::RunTests (void)
+{
+ bool result = true;
+
+ m_events = new EventGarbageCollector ();
+
+ for (int n = 0; n < 100; n++)
+ {
+ m_events->Track (Simulator::Schedule
+ (Simulator::Now (),
+ &EventGarbageCollectorTests::EventGarbageCollectorCallback,
+ this));
+ }
+ Simulator::Run ();
+ NS_TEST_ASSERT_EQUAL (m_events, 0);
+ NS_TEST_ASSERT_EQUAL (m_counter, 50);
+ return result;
+}
+
+static EventGarbageCollectorTests g_eventCollectorTests;
+
+};
+
+#endif /* RUN_SELF_TESTS */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/contrib/event-garbage-collector.h Fri Dec 07 08:43:55 2007 +0100
@@ -0,0 +1,71 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2007 INESC Porto
+ *
+ * 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: Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
+ */
+#ifndef EVENT_GARBAGE_COLLECTOR_H
+#define EVENT_GARBAGE_COLLECTOR_H
+
+#include <set>
+#include "ns3/event-id.h"
+#include "ns3/simulator.h"
+
+namespace ns3 {
+
+/**
+ * \brief An object that tracks scheduled events and automatically
+ * cancels them when it is destroyed. It is useful in situations
+ * where multiple instances of the same type of event can
+ * simultaneously be scheduled, and when the events should be limited
+ * to the lifetime of a container object.
+ */
+class EventGarbageCollector
+{
+public:
+
+ EventGarbageCollector ();
+
+ /**
+ * \brief Tracks a new event
+ */
+ void Track (EventId event);
+
+ ~EventGarbageCollector ();
+
+private:
+
+ struct EventIdLessThanTs
+ {
+ bool operator () (const EventId &a, const EventId &b) const
+ {
+ return (a.GetTs () < b.GetTs ());
+ }
+ };
+
+ typedef std::multiset<EventId, EventIdLessThanTs> EventList;
+
+ EventList::size_type m_nextCleanupSize;
+ EventList m_events;
+
+ void Cleanup ();
+ void Grow ();
+ void Shrink ();
+};
+
+}; // namespace ns3
+
+#endif /* EVENT_GARBAGE_COLLECTOR_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/contrib/gnuplot.cc Fri Dec 07 08:43:55 2007 +0100
@@ -0,0 +1,112 @@
+/* -*- 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 "gnuplot.h"
+#include <ostream>
+
+namespace ns3 {
+
+GnuplotDataset::GnuplotDataset (std::string title)
+ : m_title (title),
+ m_style (LINES)
+{}
+void
+GnuplotDataset::SetStyle (enum Style style)
+{
+ m_style = style;
+}
+void
+GnuplotDataset::Add (double x, double y)
+{
+ m_dataset.push_back (std::make_pair (x,y));
+}
+
+Gnuplot::Gnuplot (std::string pngFilename)
+ : m_pngFilename (pngFilename)
+{}
+
+Gnuplot::~Gnuplot ()
+{
+ for (Datasets::const_iterator i = m_datasets.begin (); i != m_datasets.end (); i++)
+ {
+ delete *i;
+ }
+ m_datasets.clear ();
+}
+
+void
+Gnuplot::AddDataset (const GnuplotDataset &dataset)
+{
+ m_datasets.push_back (new GnuplotDataset (dataset));
+}
+
+void
+Gnuplot::GenerateOutput (std::ostream &os)
+{
+ os << "set terminal png" << std::endl;
+ os << "set output '" << m_pngFilename << "'" << std::endl;
+ os << "plot ";
+ for (Datasets::const_iterator i = m_datasets.begin (); i != m_datasets.end ();)
+ {
+ os << "'-' title '" << (*i)->m_title << "'";
+ switch ((*i)->m_style) {
+ case GnuplotDataset::LINES:
+ os << " with lines";
+ break;
+ case GnuplotDataset::POINTS:
+ os << " with points";
+ break;
+ case GnuplotDataset::LINES_POINTS:
+ os << " with linespoints";
+ break;
+ case GnuplotDataset::DOTS:
+ os << " with dots";
+ break;
+ case GnuplotDataset::IMPULSES:
+ os << " with impulses";
+ break;
+ case GnuplotDataset::STEPS:
+ os << " with steps";
+ break;
+ case GnuplotDataset::FSTEPS:
+ os << " with fsteps";
+ break;
+ case GnuplotDataset::HISTEPS:
+ os << " with histeps";
+ break;
+ }
+ i++;
+ if (i != m_datasets.end ())
+ {
+ os << ", ";
+ }
+ }
+ os << std::endl;
+ for (Datasets::const_iterator i = m_datasets.begin (); i != m_datasets.end (); i++)
+ {
+ for (GnuplotDataset::Dataset::const_iterator j = (*i)->m_dataset.begin ();
+ j != (*i)->m_dataset.end (); j++)
+ {
+ os << j->first << " " << j->second << std::endl;
+ }
+ os << "e" << std::endl;
+ }
+}
+
+} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/contrib/gnuplot.h Fri Dec 07 08:43:55 2007 +0100
@@ -0,0 +1,71 @@
+/* -*- 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 GNUPLOT_H
+#define GNUPLOT_H
+
+#include <string>
+#include <vector>
+#include <utility>
+
+namespace ns3 {
+
+class GnuplotDataset
+{
+public:
+ enum Style {
+ LINES,
+ POINTS,
+ LINES_POINTS,
+ DOTS,
+ IMPULSES,
+ STEPS,
+ FSTEPS,
+ HISTEPS,
+ };
+
+ GnuplotDataset (std::string title);
+ void SetStyle (enum Style style);
+ void Add (double x, double y);
+private:
+ friend class Gnuplot;
+ typedef std::vector<std::pair<double,double> > Dataset;
+ Dataset m_dataset;
+ std::string m_title;
+ enum Style m_style;
+};
+
+class Gnuplot
+{
+public:
+ Gnuplot (std::string pngFilename);
+ ~Gnuplot ();
+
+ void AddDataset (const GnuplotDataset &dataset);
+
+ void GenerateOutput (std::ostream &os);
+private:
+ typedef std::vector<GnuplotDataset *> Datasets;
+ Datasets m_datasets;
+ std::string m_pngFilename;
+};
+
+} // namespace ns3
+
+#endif /* GNUPLOT_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/contrib/wscript Fri Dec 07 08:43:55 2007 +0100
@@ -0,0 +1,14 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+ module = bld.create_ns3_module('contrib', ['simulator'])
+ module.source = [
+ 'event-garbage-collector.cc',
+ 'gnuplot.cc',
+ ]
+
+ headers = bld.create_obj('ns3header')
+ headers.source = [
+ 'event-garbage-collector.h',
+ 'gnuplot.h',
+ ]
--- a/src/core/random-variable.h Fri Dec 07 08:41:52 2007 +0100
+++ b/src/core/random-variable.h Fri Dec 07 08:43:55 2007 +0100
@@ -193,20 +193,24 @@
/**
* \brief The uniform distribution RNG for NS-3.
* \ingroup randomvariable
+ *
* This class supports the creation of objects that return random numbers
* from a fixed uniform distribution. It also supports the generation of
* single random numbers from various uniform distributions.
+ *
+ * The low end of the range is always included and the high end
+ * of the range is always excluded.
* \code
* UniformVariable x(0,10);
- * x.GetValue(); //will always return numbers [0,10]
- * UniformVariable::GetSingleValue(100,1000); //returns a value [100,1000]
+ * x.GetValue(); //will always return numbers [0,10)
+ * UniformVariable::GetSingleValue(100,1000); //returns a value [100,1000)
* \endcode
*/
class UniformVariable : public RandomVariable {
public:
/**
* Creates a uniform random number generator in the
- * range [0.0 .. 1.0)
+ * range [0.0 .. 1.0).
*/
UniformVariable();
@@ -334,9 +338,19 @@
/**
* \brief Exponentially Distributed random var
* \ingroup randomvariable
+ *
* This class supports the creation of objects that return random numbers
* from a fixed exponential distribution. It also supports the generation of
* single random numbers from various exponential distributions.
+ *
+ * The probability density function of an exponential variable
+ * is defined over the interval [0, +inf) as:
+ * \f$ \alpha e^{-\alpha x} \f$
+ * where \f$ \alpha = \frac{1}{mean} \f$
+ *
+ * The bounded version is defined over the internal [0,+inf) as:
+ * \f$ \left\{ \begin{array}{cl} \alpha e^{-\alpha x} & x < bound \\ bound & x > bound \end{array}\right. \f$
+ *
* \code
* ExponentialVariable x(3.14);
* x.GetValue(); //will always return with mean 3.14
@@ -394,9 +408,18 @@
/**
* \brief ParetoVariable distributed random var
* \ingroup randomvariable
+ *
* This class supports the creation of objects that return random numbers
* from a fixed pareto distribution. It also supports the generation of
* single random numbers from various pareto distributions.
+ *
+ * The probability density function is defined over the range [\f$x_m\f$,+inf) as:
+ * \f$ k \frac{x_m^k}{x^{k+1}}\f$ where \f$x_m > 0\f$ is called the location
+ * parameter and \f$ k > 0\f$ is called the pareto index or shape.
+ *
+ * The parameter \f$ x_m \f$ can be infered from the mean and the parameter \f$ k \f$
+ * with the equation \f$ x_m = mean \frac{k-1}{k}, k > 1\f$.
+ *
* \code
* ParetoVariable x(3.14);
* x.GetValue(); //will always return with mean 3.14
@@ -468,9 +491,16 @@
/**
* \brief WeibullVariable distributed random var
* \ingroup randomvariable
+ *
* This class supports the creation of objects that return random numbers
* from a fixed weibull distribution. It also supports the generation of
* single random numbers from various weibull distributions.
+ *
+ * The probability density function is defined over the interval [0, +inf]
+ * as: \f$ \frac{k}{\lambda}\left(\frac{x}{\lambda}\right)^{k-1}e^{-\left(\frac{x}{\lambda}\right)^k} \f$
+ * where \f$ k > 0\f$ is the shape parameter and \f$ \lambda > 0\f$ is the scale parameter. The
+ * specified mean is related to the scale and shape parameters by the following relation:
+ * \f$ mean = \lambda\Gamma\left(1+\frac{1}{k}\right) \f$ where \f$ \Gamma \f$ is the Gamma function.
*/
class WeibullVariable : public RandomVariable {
public:
@@ -533,11 +563,16 @@
/**
* \brief Class NormalVariable defines a random variable with a
* normal (Gaussian) distribution.
+ * \ingroup randomvariable
*
* This class supports the creation of objects that return random numbers
* from a fixed normal distribution. It also supports the generation of
* single random numbers from various normal distributions.
- * \ingroup randomvariable
+ *
+ * The density probability function is defined over the interval (-inf,+inf)
+ * as: \f$ \frac{1}{\sigma\sqrt{2\pi}} e^{-\frac{(x-\mu)^2}{s\sigma^2}}\f$
+ * where \f$ mean = \mu \f$ and \f$ variance = \sigma^2 \f$
+ *
*/
class NormalVariable : public RandomVariable { // Normally Distributed random var
@@ -588,7 +623,7 @@
*
* Defines a random variable that has a specified, empirical
* distribution. The distribution is specified by a
- * series of calls the the CDF member function, specifying a
+ * series of calls to the CDF member function, specifying a
* value and the probability that the function value is less than
* the specified value. When values are requested,
* a uniform random variable is used to select a probabililty,
@@ -693,6 +728,7 @@
/**
* \brief Log-normal Distributed random var
* \ingroup randomvariable
+ *
* LogNormalVariable defines a random variable with log-normal
* distribution. If one takes the natural logarithm of random
* variable following the log-normal distribution, the obtained values
@@ -700,23 +736,22 @@
* This class supports the creation of objects that return random numbers
* from a fixed lognormal distribution. It also supports the generation of
* single random numbers from various lognormal distributions.
+ *
+ * The probability density function is defined over the interval [0,+inf) as:
+ * \f$ \frac{1}{x\sigma\sqrt{2\pi}} e^{-\frac{(ln(x) - \mu)^2}{2\sigma^2}}\f$
+ * where \f$ mean = e^{\mu+\frac{\sigma^2}{2}} \f$ and
+ * \f$ variance = (e^{\sigma^2}-1)e^{2\mu+\sigma^2}\f$
+ *
+ * The \f$ \mu \f$ and \f$ \sigma \f$ parameters can be calculated from the mean
+ * and standard deviation with the following equations:
+ * \f$ \mu = ln(mean) - \frac{1}{2}ln\left(1+\frac{stddev}{mean^2}\right)\f$, and,
+ * \f$ \sigma = \sqrt{ln\left(1+\frac{stddev}{mean^2}\right)}\f$
*/
class LogNormalVariable : public RandomVariable {
public:
/**
- * \param mu Mean value of the underlying normal distribution.
- * \param sigma Standard deviation of the underlying normal distribution.
- *
- * Notice: the parameters mu and sigma are _not_ the mean and standard
- * deviation of the log-normal distribution. To obtain the
- * parameters mu and sigma for a given mean and standard deviation
- * of the log-normal distribution the following convertion can be
- * used:
- * \code
- * double tmp = log (1 + pow (stddev/mean, 2));
- * double sigma = sqrt (tmp);
- * double mu = log (mean) - 0.5*tmp;
- * \endcode
+ * \param mu mu parameter of the lognormal distribution
+ * \param sigma sigma parameter of the lognormal distribution
*/
LogNormalVariable (double mu, double sigma);
@@ -727,8 +762,8 @@
virtual RandomVariable* Copy() const;
public:
/**
- * \param mu Mean value of the underlying normal distribution.
- * \param sigma Standard deviation of the underlying normal distribution.
+ * \param mu mu parameter of the underlying normal distribution
+ * \param sigma sigma parameter of the underlying normal distribution
* \return A random number from the distribution specified by mu and sigma
*/
static double GetSingleValue(double mu, double sigma);
--- a/src/devices/point-to-point/point-to-point-net-device.cc Fri Dec 07 08:41:52 2007 +0100
+++ b/src/devices/point-to-point/point-to-point-net-device.cc Fri Dec 07 08:43:55 2007 +0100
@@ -253,7 +253,7 @@
PointToPointTraceType (PointToPointTraceType::RX));
resolver->AddSource ("drop",
TraceDoc ("drop MAC packet",
- "const Packet &", "packet dropped"),
+ "Ptr<const Packet>", "packet dropped"),
m_dropTrace,
PointToPointTraceType (PointToPointTraceType::DROP));
resolver->SetParentResolver (NetDevice::GetTraceResolver ());
--- a/src/mobility/mobility-model-notifier.cc Fri Dec 07 08:41:52 2007 +0100
+++ b/src/mobility/mobility-model-notifier.cc Fri Dec 07 08:43:55 2007 +0100
@@ -45,7 +45,7 @@
Ptr<CompositeTraceResolver> resolver =
Create<CompositeTraceResolver> ();
resolver->AddSource ("course-change",
- TraceDoc ("The value of the speed vector changed",
+ TraceDoc ("The value of the position and/or velocity vector changed",
"Ptr<const MobilityModel>",
"the mobility model whose course changed"),
m_trace);
--- a/src/routing/olsr/event-garbage-collector.cc Fri Dec 07 08:41:52 2007 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,153 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2007 INESC Porto
- *
- * 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: Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
- */
-#include "event-garbage-collector.h"
-
-#define CLEANUP_CHUNK_MIN_SIZE 8
-#define CLEANUP_CHUNK_MAX_SIZE 128
-
-
-namespace ns3 {
-
-
-EventGarbageCollector::EventGarbageCollector () :
- m_nextCleanupSize (CLEANUP_CHUNK_MIN_SIZE)
-{}
-
-void
-EventGarbageCollector::Track (EventId event)
-{
- m_events.insert (event);
- if (m_events.size () >= m_nextCleanupSize)
- Cleanup ();
-}
-
-void
-EventGarbageCollector::Grow ()
-{
- m_nextCleanupSize += (m_nextCleanupSize < CLEANUP_CHUNK_MAX_SIZE?
- m_nextCleanupSize : CLEANUP_CHUNK_MAX_SIZE);
-}
-
-void
-EventGarbageCollector::Shrink ()
-{
- while (m_nextCleanupSize > m_events.size ())
- m_nextCleanupSize >>= 1;
- Grow ();
-}
-
-// Called when a new event was added and the cleanup limit was exceeded in consequence.
-void
-EventGarbageCollector::Cleanup ()
-{
- for (EventList::iterator iter = m_events.begin (); iter != m_events.end ();)
- {
- if ((*iter).IsExpired ())
- {
- m_events.erase (iter++);
- }
- else
- break; // EventIds are sorted by timestamp => further events are not expired for sure
- }
-
- // If after cleanup we are still over the limit, increase the limit.
- if (m_events.size () >= m_nextCleanupSize)
- Grow ();
- else
- Shrink ();
-}
-
-
-EventGarbageCollector::~EventGarbageCollector ()
-{
- for (EventList::iterator event = m_events.begin ();
- event != m_events.end (); event++)
- {
- Simulator::Cancel (*event);
- }
-}
-
-}; // namespace ns3
-
-
-
-#ifdef RUN_SELF_TESTS
-
-#include "ns3/test.h"
-
-namespace ns3 {
-
-class EventGarbageCollectorTests : public Test
-{
- int m_counter;
- EventGarbageCollector *m_events;
-
- void EventGarbageCollectorCallback ();
-
-public:
-
- EventGarbageCollectorTests ();
- virtual ~EventGarbageCollectorTests ();
- virtual bool RunTests (void);
-};
-
-EventGarbageCollectorTests::EventGarbageCollectorTests ()
- : Test ("EventGarbageCollector"), m_counter (0), m_events (0)
-{}
-
-EventGarbageCollectorTests::~EventGarbageCollectorTests ()
-{}
-
-void
-EventGarbageCollectorTests::EventGarbageCollectorCallback ()
-{
- m_counter++;
- if (m_counter == 50)
- {
- // this should cause the remaining (50) events to be cancelled
- delete m_events;
- m_events = 0;
- }
-}
-
-bool EventGarbageCollectorTests::RunTests (void)
-{
- bool result = true;
-
- m_events = new EventGarbageCollector ();
-
- for (int n = 0; n < 100; n++)
- {
- m_events->Track (Simulator::Schedule
- (Simulator::Now (),
- &EventGarbageCollectorTests::EventGarbageCollectorCallback,
- this));
- }
- Simulator::Run ();
- NS_TEST_ASSERT_EQUAL (m_events, 0);
- NS_TEST_ASSERT_EQUAL (m_counter, 50);
- return result;
-}
-
-static EventGarbageCollectorTests g_eventCollectorTests;
-
-};
-
-#endif /* RUN_SELF_TESTS */
--- a/src/routing/olsr/event-garbage-collector.h Fri Dec 07 08:41:52 2007 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,71 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2007 INESC Porto
- *
- * 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: Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
- */
-#ifndef EVENT_GARBAGE_COLLECTOR_H
-#define EVENT_GARBAGE_COLLECTOR_H
-
-#include <set>
-#include "ns3/event-id.h"
-#include "ns3/simulator.h"
-
-namespace ns3 {
-
-/**
- * \brief An object that tracks scheduled events and automatically
- * cancels them when it is destroyed. It is useful in situations
- * where multiple instances of the same type of event can
- * simultaneously be scheduled, and when the events should be limited
- * to the lifetime of a container object.
- */
-class EventGarbageCollector
-{
-public:
-
- EventGarbageCollector ();
-
- /**
- * \brief Tracks a new event
- */
- void Track (EventId event);
-
- ~EventGarbageCollector ();
-
-private:
-
- struct EventIdLessThanTs
- {
- bool operator () (const EventId &a, const EventId &b) const
- {
- return (a.GetTs () < b.GetTs ());
- }
- };
-
- typedef std::multiset<EventId, EventIdLessThanTs> EventList;
-
- EventList::size_type m_nextCleanupSize;
- EventList m_events;
-
- void Cleanup ();
- void Grow ();
- void Shrink ();
-};
-
-}; // namespace ns3
-
-#endif /* EVENT_GARBAGE_COLLECTOR_H */
--- a/src/routing/olsr/olsr-agent-impl.h Fri Dec 07 08:41:52 2007 +0100
+++ b/src/routing/olsr/olsr-agent-impl.h Fri Dec 07 08:43:55 2007 +0100
@@ -37,7 +37,7 @@
#include "ns3/packet.h"
#include "ns3/node.h"
#include "ns3/socket.h"
-#include "event-garbage-collector.h"
+#include "ns3/event-garbage-collector.h"
#include "ns3/timer.h"
#include "ns3/callback-trace-source.h"
--- a/src/routing/olsr/olsr-header.cc Fri Dec 07 08:41:52 2007 +0100
+++ b/src/routing/olsr/olsr-header.cc Fri Dec 07 08:43:55 2007 +0100
@@ -21,6 +21,7 @@
#include "ns3/assert.h"
#include "olsr-header.h"
+#include "ns3/log.h"
#define IPV4_ADDRESS_SIZE 4
#define OLSR_MSG_HEADER_SIZE 12
@@ -29,6 +30,10 @@
namespace ns3 {
namespace olsr {
+
+NS_LOG_COMPONENT_DEFINE("OlsrHeader");
+
+
/// Scaling factor used in RFC 3626.
#define OLSR_C 0.0625
@@ -161,6 +166,7 @@
size += m_message.mid.GetSerializedSize ();
break;
case HELLO_MESSAGE:
+ NS_LOG_DEBUG ("Hello Message Size: " << size << " + " << m_message.hello.GetSerializedSize ());
size += m_message.hello.GetSerializedSize ();
break;
case TC_MESSAGE:
@@ -187,7 +193,7 @@
Buffer::Iterator i = start;
i.WriteU8 (m_messageType);
i.WriteU8 (m_vTime);
- i.WriteHtonU16 (GetSerializedSize () - OLSR_MSG_HEADER_SIZE);
+ i.WriteHtonU16 (GetSerializedSize ());
i.WriteHtonU32 (m_originatorAddress.GetHostOrder ());
i.WriteU8 (m_timeToLive);
i.WriteU8 (m_hopCount);
@@ -230,16 +236,16 @@
switch (m_messageType)
{
case MID_MESSAGE:
- size += m_message.mid.Deserialize (i, m_messageSize);
+ size += m_message.mid.Deserialize (i, m_messageSize - OLSR_MSG_HEADER_SIZE);
break;
case HELLO_MESSAGE:
- size += m_message.hello.Deserialize (i, m_messageSize);
+ size += m_message.hello.Deserialize (i, m_messageSize - OLSR_MSG_HEADER_SIZE);
break;
case TC_MESSAGE:
- size += m_message.tc.Deserialize (i, m_messageSize);
+ size += m_message.tc.Deserialize (i, m_messageSize - OLSR_MSG_HEADER_SIZE);
break;
case HNA_MESSAGE:
- size += m_message.hna.Deserialize (i, m_messageSize);
+ size += m_message.hna.Deserialize (i, m_messageSize - OLSR_MSG_HEADER_SIZE);
break;
default:
NS_ASSERT (false);
--- a/src/routing/olsr/wscript Fri Dec 07 08:41:52 2007 +0100
+++ b/src/routing/olsr/wscript Fri Dec 07 08:43:55 2007 +0100
@@ -1,7 +1,7 @@
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
def build(bld):
- module = bld.create_ns3_module('olsr', ['internet-node'])
+ module = bld.create_ns3_module('olsr', ['internet-node', 'contrib'])
module.includes = '.'
module.source = [
'olsr-header.cc',
@@ -10,7 +10,6 @@
'olsr-agent.cc',
'olsr-agent-impl.cc',
'olsr.cc',
- 'event-garbage-collector.cc',
]
headers = bld.create_obj('ns3header')
--- a/src/wscript Fri Dec 07 08:41:52 2007 +0100
+++ b/src/wscript Fri Dec 07 08:43:55 2007 +0100
@@ -14,6 +14,7 @@
'core',
'common',
'simulator',
+ 'contrib',
'node',
'internet-node',
'devices/point-to-point',
@@ -82,12 +83,15 @@
Object.genobj.__init__(self, 'other')
self.inst_var = 'INCLUDEDIR'
self.inst_dir = 'ns3'
+ self.sub_dir = None # if not None, header files will be published as ns3/sub_dir/file.h
self.env = env
if not self.env:
self.env = Params.g_build.m_allenvs['default']
def apply(self):
ns3_dir_node = Params.g_build.m_srcnode.find_dir("ns3")
+ if self.sub_dir is not None:
+ ns3_dir_node = ns3_dir_node.find_dir(self.sub_dir)
for filename in self.to_list(self.source):
src_node = self.path.find_source(filename)
if src_node is None:
@@ -99,10 +103,14 @@
task.set_outputs([dst_node])
def install(self):
+ if self.sub_dir is None:
+ inst_dir = self.inst_dir
+ else:
+ inst_dir = os.path.join(self.inst_dir, self.sub_dir)
for i in self.m_tasks:
current = Params.g_build.m_curdirnode
lst = map(lambda a: a.relpath_gen(current), i.m_outputs)
- Common.install_files(self.inst_var, self.inst_dir, lst)
+ Common.install_files(self.inst_var, inst_dir, lst)
def _ns3_headers_inst(task):
assert len(task.m_inputs) == len(task.m_outputs)