From dd825831c7dee7a292fc37db6af1bdca0795e4b3 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 21 Nov 2007 13:36:47 +0100 Subject: [PATCH 1/7] bug 109: improve the doxygen documentation for RandomVariable --- src/core/random-variable.h | 75 ++++++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 20 deletions(-) diff --git a/src/core/random-variable.h b/src/core/random-variable.h index ccc5caa34..8dbbb27bb 100644 --- a/src/core/random-variable.h +++ b/src/core/random-variable.h @@ -193,20 +193,24 @@ protected: /** * \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 @@ private: /** * \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 @@ private: /** * \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 @@ private: /** * \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 @@ private: /** * \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 @@ private: * * 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 @@ private: /** * \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 @@ private: * 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 @@ public: 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); From 8ce92e1bc2acecbe25fc6168a85f8cd481f40ca4 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Tue, 27 Nov 2007 10:36:27 +0000 Subject: [PATCH 2/7] Fix bad Message Size value in OLSR headers (which prevented wireshark from decoding most OLSR packets). --- src/routing/olsr/olsr-header.cc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/routing/olsr/olsr-header.cc b/src/routing/olsr/olsr-header.cc index d5d84e3a4..aacc3e440 100644 --- a/src/routing/olsr/olsr-header.cc +++ b/src/routing/olsr/olsr-header.cc @@ -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 @@ MessageHeader::GetSerializedSize (void) const 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 @@ MessageHeader::Serialize (Buffer::Iterator start) const 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 @@ MessageHeader::Deserialize (Buffer::Iterator start) 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); From 7813d6fdd7b9b9b32875e361f3a709597002daf8 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 29 Nov 2007 00:59:00 +0100 Subject: [PATCH 3/7] fix typo due to Packet & -> Ptr change --- src/devices/point-to-point/point-to-point-net-device.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devices/point-to-point/point-to-point-net-device.cc b/src/devices/point-to-point/point-to-point-net-device.cc index c0ec4fab5..8048f8943 100644 --- a/src/devices/point-to-point/point-to-point-net-device.cc +++ b/src/devices/point-to-point/point-to-point-net-device.cc @@ -253,7 +253,7 @@ PointToPointNetDevice::GetTraceResolver (void) const PointToPointTraceType (PointToPointTraceType::RX)); resolver->AddSource ("drop", TraceDoc ("drop MAC packet", - "const Packet &", "packet dropped"), + "Ptr", "packet dropped"), m_dropTrace, PointToPointTraceType (PointToPointTraceType::DROP)); resolver->SetParentResolver (NetDevice::GetTraceResolver ()); From fb2ebab79322b6c85a1d078ca2de5ab829231212 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 29 Nov 2007 01:03:41 +0100 Subject: [PATCH 4/7] speed vector -> velocity vector --- src/mobility/mobility-model-notifier.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mobility/mobility-model-notifier.cc b/src/mobility/mobility-model-notifier.cc index 4b87dd066..a32d629d1 100644 --- a/src/mobility/mobility-model-notifier.cc +++ b/src/mobility/mobility-model-notifier.cc @@ -45,7 +45,7 @@ MobilityModelNotifier::GetTraceResolver (void) const Ptr resolver = Create (); resolver->AddSource ("course-change", - TraceDoc ("The value of the speed vector changed", + TraceDoc ("The value of the position and/or velocity vector changed", "Ptr", "the mobility model whose course changed"), m_trace); From bab56b0d88fa67ad962617868123e0c70a1c9f83 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Wed, 5 Dec 2007 11:51:10 +0000 Subject: [PATCH 5/7] Add support for publishing ns3 headers in a subdir of ns3/ (we probably won't be needing this, but since it was implemented it might as well be commited, in case we ever need it) --- src/wscript | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/wscript b/src/wscript index 0224c0bb8..f0df494d6 100644 --- a/src/wscript +++ b/src/wscript @@ -81,12 +81,15 @@ class Ns3Header(Object.genobj): 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: @@ -98,10 +101,14 @@ class Ns3Header(Object.genobj): 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) From 8debe6ef1d080e0041dd05d7ebce71c769350b67 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Thu, 6 Dec 2007 11:05:17 +0000 Subject: [PATCH 6/7] Create a new contrib module; move event-garbage-collector.{h,cc} to the contrib module. --- .../olsr => contrib}/event-garbage-collector.cc | 0 .../olsr => contrib}/event-garbage-collector.h | 0 src/contrib/wscript | 12 ++++++++++++ src/routing/olsr/olsr-agent-impl.h | 2 +- src/routing/olsr/wscript | 3 +-- src/wscript | 1 + 6 files changed, 15 insertions(+), 3 deletions(-) rename src/{routing/olsr => contrib}/event-garbage-collector.cc (100%) rename src/{routing/olsr => contrib}/event-garbage-collector.h (100%) create mode 100644 src/contrib/wscript diff --git a/src/routing/olsr/event-garbage-collector.cc b/src/contrib/event-garbage-collector.cc similarity index 100% rename from src/routing/olsr/event-garbage-collector.cc rename to src/contrib/event-garbage-collector.cc diff --git a/src/routing/olsr/event-garbage-collector.h b/src/contrib/event-garbage-collector.h similarity index 100% rename from src/routing/olsr/event-garbage-collector.h rename to src/contrib/event-garbage-collector.h diff --git a/src/contrib/wscript b/src/contrib/wscript new file mode 100644 index 000000000..18e72ac89 --- /dev/null +++ b/src/contrib/wscript @@ -0,0 +1,12 @@ +## -*- 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', + ] + + headers = bld.create_obj('ns3header') + headers.source = [ + 'event-garbage-collector.h', + ] diff --git a/src/routing/olsr/olsr-agent-impl.h b/src/routing/olsr/olsr-agent-impl.h index 22722c852..ab22927f2 100644 --- a/src/routing/olsr/olsr-agent-impl.h +++ b/src/routing/olsr/olsr-agent-impl.h @@ -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" diff --git a/src/routing/olsr/wscript b/src/routing/olsr/wscript index f6d866dcc..ba2f76687 100644 --- a/src/routing/olsr/wscript +++ b/src/routing/olsr/wscript @@ -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 @@ def build(bld): 'olsr-agent.cc', 'olsr-agent-impl.cc', 'olsr.cc', - 'event-garbage-collector.cc', ] headers = bld.create_obj('ns3header') diff --git a/src/wscript b/src/wscript index f0df494d6..efa55d5cd 100644 --- a/src/wscript +++ b/src/wscript @@ -14,6 +14,7 @@ all_modules = ( 'core', 'common', 'simulator', + 'contrib', 'node', 'internet-node', 'devices/point-to-point', From 32611749b25d88c42587d23993ad880403899b6a Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 6 Dec 2007 13:30:26 +0100 Subject: [PATCH 7/7] Gnuplot output class for contrib module --- src/contrib/gnuplot.cc | 112 +++++++++++++++++++++++++++++++++++++++++ src/contrib/gnuplot.h | 71 ++++++++++++++++++++++++++ src/contrib/wscript | 2 + 3 files changed, 185 insertions(+) create mode 100644 src/contrib/gnuplot.cc create mode 100644 src/contrib/gnuplot.h diff --git a/src/contrib/gnuplot.cc b/src/contrib/gnuplot.cc new file mode 100644 index 000000000..22818bf89 --- /dev/null +++ b/src/contrib/gnuplot.cc @@ -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 + */ +#include "gnuplot.h" +#include + +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 diff --git a/src/contrib/gnuplot.h b/src/contrib/gnuplot.h new file mode 100644 index 000000000..f9f26cf3f --- /dev/null +++ b/src/contrib/gnuplot.h @@ -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 + */ +#ifndef GNUPLOT_H +#define GNUPLOT_H + +#include +#include +#include + +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 > 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 Datasets; + Datasets m_datasets; + std::string m_pngFilename; +}; + +} // namespace ns3 + +#endif /* GNUPLOT_H */ diff --git a/src/contrib/wscript b/src/contrib/wscript index 18e72ac89..2e89aac37 100644 --- a/src/contrib/wscript +++ b/src/contrib/wscript @@ -4,9 +4,11 @@ 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', ]