From 9059dd7e3e18849e54c1a6f289f6c4eaa12e30c1 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Wed, 3 Oct 2007 12:41:17 -0700 Subject: [PATCH 01/67] log changes --- src/core/log.cc | 33 +++++++++++++++- src/core/log.h | 102 ++++++++++++++++++++++++++++++++---------------- 2 files changed, 100 insertions(+), 35 deletions(-) diff --git a/src/core/log.cc b/src/core/log.cc index 6f5bd6acf..97d82cc4c 100644 --- a/src/core/log.cc +++ b/src/core/log.cc @@ -207,7 +207,7 @@ LogComponentEnableEnvVar (void) } LogComponent::LogComponent (char const * name) - : m_levels (0) + : m_levels (0), m_name (name) { ComponentList *components = GetComponentList (); for (ComponentListI i = components->begin (); @@ -244,6 +244,13 @@ LogComponent::Disable (enum LogLevel level) m_levels &= ~level; } +char const * +LogComponent::Name (void) const +{ + return m_name; +} + + void LogComponentEnable (char const *name, enum LogLevel level) { @@ -260,6 +267,18 @@ LogComponentEnable (char const *name, enum LogLevel level) } } +void +LogComponentEnableAll (enum LogLevel level) +{ + ComponentList *components = GetComponentList (); + for (ComponentListI i = components->begin (); + i != components->end (); + i++) + { + i->second->Enable (level); + } +} + void LogComponentDisable (char const *name, enum LogLevel level) { @@ -276,6 +295,18 @@ LogComponentDisable (char const *name, enum LogLevel level) } } +void +LogComponentDisableAll (enum LogLevel level) +{ + ComponentList *components = GetComponentList (); + for (ComponentListI i = components->begin (); + i != components->end (); + i++) + { + i->second->Disable (level); + } +} + void LogComponentPrintList (void) { diff --git a/src/core/log.h b/src/core/log.h index 267419bf5..d54b8fcdf 100644 --- a/src/core/log.h +++ b/src/core/log.h @@ -92,20 +92,25 @@ { \ if (g_log.IsEnabled (level)) \ { \ - std::clog << __PRETTY_FUNCTION__ << " ==> " << \ - msg << std::endl; \ + if (g_log.IsEnabled (ns3::LOG_PREFIX_ALL)) \ + { \ + std::clog << g_log.Name () << ":" << \ + __FUNCTION__ << "(): "; \ + } \ + std::clog << msg << std::endl; \ } \ } \ while (false) -#define NS_LOG_F(level) \ - do \ - { \ - if (g_log.IsEnabled (level)) \ - { \ - std::clog << __PRETTY_FUNCTION__ << std::endl;\ - } \ - } \ +#define NS_LOG_F(level) \ + do \ + { \ + if (g_log.IsEnabled (level)) \ + { \ + std::clog << g_log.Name () << ":" << __FUNCTION__ << \ + "(): " << std::endl; \ + } \ + } \ while (false) #define NS_LOG_ERROR(msg) \ @@ -129,9 +134,6 @@ #define NS_LOG_LOGIC(msg) \ NS_LOG(ns3::LOG_LOGIC, msg) -#define NS_LOG_ALL(msg) \ - NS_LOG(ns3::LOG_ALL, msg) - #define NS_LOG_UNCOND(msg) \ do \ { \ @@ -150,7 +152,6 @@ #define NS_LOG_FUNCTION #define NS_LOG_PARAM(msg) #define NS_LOG_LOGIC(msg) -#define NS_LOG_ALL(msg) #define NS_LOG_UNCOND(msg) #endif @@ -160,59 +161,88 @@ namespace ns3 { #ifdef NS3_LOG_ENABLE enum LogLevel { - LOG_ERROR = 0x0001, // serious error messages only - LOG_LEVEL_ERROR = 0x0001, + LOG_NONE = 0x00000000, // no logging - LOG_WARN = 0x0002, // warning messages - LOG_LEVEL_WARN = 0x0003, + LOG_ERROR = 0x00000001, // serious error messages only + LOG_LEVEL_ERROR = 0x00000001, - LOG_DEBUG = 0x0004, // rare ad-hoc debug messages - LOG_LEVEL_DEBUG = 0x0007, + LOG_WARN = 0x00000002, // warning messages + LOG_LEVEL_WARN = 0x00000003, - LOG_INFO = 0x0008, // informational messages (e.g., banners) - LOG_LEVEL_INFO = 0x000f, + LOG_DEBUG = 0x00000004, // rare ad-hoc debug messages + LOG_LEVEL_DEBUG = 0x00000007, - LOG_FUNCTION = 0x0010, // function tracing - LOG_LEVEL_FUNCTION = 0x001f, + LOG_INFO = 0x00000008, // informational messages (e.g., banners) + LOG_LEVEL_INFO = 0x0000000f, - LOG_PARAM = 0x0020, // parameters to functions - LOG_LEVEL_PARAM = 0x003f, + LOG_FUNCTION = 0x00000010, // function tracing + LOG_LEVEL_FUNCTION = 0x0000001f, - LOG_LOGIC = 0x0040, // control flow tracing within functions - LOG_LEVEL_LOGIC = 0x007f, + LOG_PARAM = 0x00000020, // parameters to functions + LOG_LEVEL_PARAM = 0x0000003f, - LOG_ALL = 0x4000, // print everything - LOG_LEVEL_ALL = 0x7fff + LOG_LOGIC = 0x00000040, // control flow tracing within functions + LOG_LEVEL_LOGIC = 0x0000007f, + + LOG_ALL = 0x7fffffff, // print everything + LOG_LEVEL_ALL = LOG_ALL, + + LOG_PREFIX_ALL = 0x80000000 }; #endif +#ifdef NS3_LOG_ENABLE /** * \param name a log component name + * \param level a logging level + * \param decorate whether or not to add function names to all logs * \ingroup logging * * Enable the logging output associated with that log component. * The logging output can be later disabled with a call * to ns3::LogComponentDisable. */ -#ifdef NS3_LOG_ENABLE -void LogComponentEnable (char const *name, enum LogLevel level); + void LogComponentEnable (char const *name, enum LogLevel level); +/** + * \param level a logging level + * \param decorate whether or not to add function names to all logs + * \ingroup logging + * + * Enable the logging output for all registered log components. + */ + void LogComponentEnableAll (enum LogLevel level); #else #define LogComponentEnable(a,b) +#define LogComponentEnableAll(a) #endif +#ifdef NS3_LOG_ENABLE /** * \param name a log component name + * \param level a logging level * \ingroup logging * * Disable the logging output associated with that log component. * The logging output can be later re-enabled with a call * to ns3::LogComponentEnable. */ -#ifdef NS3_LOG_ENABLE void LogComponentDisable (char const *name, enum LogLevel level); + +/** + * \param name a log component name + * \param level a logging level + * \ingroup logging + * + * Disable the logging output associated with that log component. + * The logging output can be later re-enabled with a call + * to ns3::LogComponentEnable. + */ +void LogComponentDisableAll (enum LogLevel level); + #else #define LogComponentDisable(a,b) +#define LogComponentDisableAll(a) #endif /** @@ -240,8 +270,12 @@ public: bool IsNoneEnabled (void) const; void Enable (enum LogLevel level); void Disable (enum LogLevel level); + bool Decorate (void) const; + char const *Name (void) const; private: - int32_t m_levels; + int32_t m_levels; + char const *m_name; + bool m_decorate; }; #endif From 3af33c8b75590547bf5b1a231f2d72a1921b8ed9 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Wed, 3 Oct 2007 13:34:06 -0700 Subject: [PATCH 02/67] enable log prefix --- tutorial/hello-simulator.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tutorial/hello-simulator.cc b/tutorial/hello-simulator.cc index 735d98130..885597be2 100644 --- a/tutorial/hello-simulator.cc +++ b/tutorial/hello-simulator.cc @@ -23,7 +23,8 @@ using namespace ns3; int main (int argc, char *argv[]) { - LogComponentEnable ("HelloSimulator", LOG_LEVEL_INFO); + LogComponentEnable ("HelloSimulator", + LogLevel (LOG_LEVEL_INFO | LOG_PREFIX_ALL)); NS_LOG_INFO ("Hello Simulator"); } From 5f61c348c2d6b49d2f46bced3b36b467351ef61c Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Fri, 5 Oct 2007 16:00:04 -0700 Subject: [PATCH 03/67] prototype address and network allocation --- tutorial/ipv4-address-extended.cc | 177 ++++++++++++++++++++++++++++++ tutorial/ipv4-address-extended.h | 39 +++++++ tutorial/testipv4.cc | 57 ++++++++++ tutorial/wscript | 4 + 4 files changed, 277 insertions(+) create mode 100644 tutorial/ipv4-address-extended.cc create mode 100644 tutorial/ipv4-address-extended.h create mode 100644 tutorial/testipv4.cc diff --git a/tutorial/ipv4-address-extended.cc b/tutorial/ipv4-address-extended.cc new file mode 100644 index 000000000..0fd18994d --- /dev/null +++ b/tutorial/ipv4-address-extended.cc @@ -0,0 +1,177 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 University of Washington + * + * 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 + */ + +#include "ns3/assert.h" +#include "ns3/log.h" +#include "ns3/simulation-singleton.h" +#include "ipv4-address-extended.h" + +NS_LOG_COMPONENT_DEFINE("Ipv4AddressEx"); + +namespace ns3 { + +class Ipv4NetworkManager +{ +public: + Ipv4NetworkManager (); + virtual ~Ipv4NetworkManager (); + + Ipv4Address Allocate (const Ipv4Mask mask); + +private: + static const uint32_t N_BITS = 32; + class State + { + public: + uint32_t mask; + uint32_t network; + }; + State m_state[N_BITS]; +}; + +Ipv4NetworkManager::Ipv4NetworkManager () +{ + NS_LOG_FUNCTION; + + uint32_t mask = 0; + + for (uint32_t i = 0; i < N_BITS; ++i) + { + m_state[i].mask = mask; + mask >>= 1; + mask |= 0x80000000; + m_state[i].network = 0; + NS_LOG_LOGIC ("m_state[" << i << "]"); + NS_LOG_LOGIC ("mask = " << std::hex << m_state[i].mask); + NS_LOG_LOGIC ("network = " << std::hex << m_state[i].network); + } +} + +Ipv4NetworkManager::~Ipv4NetworkManager () +{ + NS_LOG_FUNCTION; +} + +Ipv4Address +Ipv4NetworkManager::Allocate (const Ipv4Mask mask) +{ + NS_LOG_FUNCTION; + + uint32_t bits = mask.GetHostOrder (); + + for (uint32_t i = 0; i < N_BITS; ++i) + { + if (bits & 1) + { + uint32_t nBits = N_BITS - i; + NS_ASSERT(nBits >= 0 && nBits < N_BITS); + ++m_state[nBits].network; + return Ipv4Address (m_state[nBits].network << i); + } + bits >>= 1; + } + NS_ASSERT_MSG(false, "Impossible"); + return Ipv4Address (bits); +} + +class Ipv4AddressManager +{ +public: + Ipv4AddressManager (); + virtual ~Ipv4AddressManager (); + + Ipv4Address Allocate (const Ipv4Mask mask, const Ipv4Address network); + +private: + static const uint32_t N_BITS = 32; + class State + { + public: + uint32_t mask; + uint32_t address; + }; + State m_state[N_BITS]; +}; + +Ipv4AddressManager::Ipv4AddressManager () +{ + NS_LOG_FUNCTION; + + uint32_t mask = 0; + + for (uint32_t i = 0; i < N_BITS; ++i) + { + m_state[i].mask = mask; + mask >>= 1; + mask |= 0x80000000; + m_state[i].address = 0; + NS_LOG_LOGIC ("m_state[" << i << "]"); + NS_LOG_LOGIC ("mask = " << std::hex << m_state[i].mask); + NS_LOG_LOGIC ("address = " << std::hex << m_state[i].address); + } +} + +Ipv4AddressManager::~Ipv4AddressManager () +{ + NS_LOG_FUNCTION; +} + +Ipv4Address +Ipv4AddressManager::Allocate (const Ipv4Mask mask, const Ipv4Address network) +{ + NS_LOG_FUNCTION; + + uint32_t bits = mask.GetHostOrder (); + uint32_t net = network.GetHostOrder (); + + for (uint32_t i = 0; i < N_BITS; ++i) + { + if (bits & 1) + { + uint32_t nBits = N_BITS - i; + NS_ASSERT(nBits >= 0 && nBits < N_BITS); + ++m_state[nBits].address; + NS_ASSERT_MSG((m_state[nBits].mask & m_state[nBits].address) == 0, + "Ipv4AddressManager::Allocate(): Overflow"); + return Ipv4Address (net | m_state[nBits].address); + } + bits >>= 1; + } + NS_ASSERT_MSG(false, "Impossible"); + return Ipv4Address (bits); +} + +Ipv4Address +Ipv4AddressEx::AllocateAddress (const Ipv4Mask mask, const Ipv4Address network) +{ + NS_LOG_FUNCTION; + + return SimulationSingleton::Get ()-> + Allocate (mask, network); +} + +Ipv4Address +Ipv4AddressEx::AllocateNetwork (const Ipv4Mask mask) +{ + NS_LOG_FUNCTION; + + return SimulationSingleton::Get ()-> + Allocate (mask); +} + +}; // namespace ns3 diff --git a/tutorial/ipv4-address-extended.h b/tutorial/ipv4-address-extended.h new file mode 100644 index 000000000..fb1626204 --- /dev/null +++ b/tutorial/ipv4-address-extended.h @@ -0,0 +1,39 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 University of Washington + * + * 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 + */ + +#ifndef IPV4_ADDRESS_EXTENDED_H +#define IPV4_ADDRESS_EXTENDED_H + +#include +#include + +#include "ns3/ipv4-address.h" + +namespace ns3 { + +class Ipv4AddressEx : public Ipv4Address { +public: + static Ipv4Address AllocateAddress (const Ipv4Mask mask, + const Ipv4Address network); + + static Ipv4Address AllocateNetwork (const Ipv4Mask mask); +}; + +}; // namespace ns3 + +#endif /* IPV4_ADDRESS_EXTENDED_H */ diff --git a/tutorial/testipv4.cc b/tutorial/testipv4.cc new file mode 100644 index 000000000..706d046ed --- /dev/null +++ b/tutorial/testipv4.cc @@ -0,0 +1,57 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * 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 + */ + +#include "ns3/log.h" +#include "ipv4-address-extended.h" + +NS_LOG_COMPONENT_DEFINE ("TestIpv4"); + +using namespace ns3; + +int +main (int argc, char *argv[]) +{ + LogComponentEnable ("TestIpv4", LOG_LEVEL_ALL); + + NS_LOG_INFO ("Test Ipv4"); + + Ipv4Mask mask1 ("255.0.0.0"); + + for (uint32_t i = 0; i < 10; ++i) + { + Ipv4Address network = Ipv4AddressEx::AllocateNetwork (mask1); + Ipv4Address address = Ipv4AddressEx::AllocateAddress (mask1, network); + NS_LOG_INFO ("address = " << address); + } + + Ipv4Mask mask2 ("255.255.0.0"); + + for (uint32_t i = 0; i < 10; ++i) + { + Ipv4Address network = Ipv4AddressEx::AllocateNetwork (mask2); + Ipv4Address address = Ipv4AddressEx::AllocateAddress (mask2, network); + NS_LOG_INFO ("address = " << address); + } + + Ipv4Mask mask3 ("255.255.255.0"); + + for (uint32_t i = 0; i < 10; ++i) + { + Ipv4Address network = Ipv4AddressEx::AllocateNetwork (mask3); + Ipv4Address address = Ipv4AddressEx::AllocateAddress (mask3, network); + NS_LOG_INFO ("address = " << address); + } +} diff --git a/tutorial/wscript b/tutorial/wscript index b7d90bdf5..4a22ee109 100644 --- a/tutorial/wscript +++ b/tutorial/wscript @@ -20,3 +20,7 @@ def build(bld): obj = bld.create_ns3_program('tutorial-naive-dumbbell', ['core']) obj.source = 'tutorial-naive-dumbbell.cc' + + obj = bld.create_ns3_program('testipv4', + ['core']) + obj.source = ['testipv4.cc', 'ipv4-address-extended.cc'] From a84a41bc75e798261a1216fadf4752d06a4bb2f7 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Fri, 5 Oct 2007 18:17:18 -0700 Subject: [PATCH 04/67] add seed calls --- tutorial/ipv4-address-extended.cc | 70 ++++++++++++++++++++++++++++++- tutorial/ipv4-address-extended.h | 6 +++ tutorial/testipv4.cc | 1 + 3 files changed, 75 insertions(+), 2 deletions(-) diff --git a/tutorial/ipv4-address-extended.cc b/tutorial/ipv4-address-extended.cc index 0fd18994d..b25d5b6e6 100644 --- a/tutorial/ipv4-address-extended.cc +++ b/tutorial/ipv4-address-extended.cc @@ -32,6 +32,7 @@ public: virtual ~Ipv4NetworkManager (); Ipv4Address Allocate (const Ipv4Mask mask); + void Seed (const Ipv4Mask mask, const Ipv4Address network); private: static const uint32_t N_BITS = 32; @@ -67,6 +68,29 @@ Ipv4NetworkManager::~Ipv4NetworkManager () NS_LOG_FUNCTION; } +void +Ipv4NetworkManager::Seed (const Ipv4Mask mask, const Ipv4Address network) +{ + NS_LOG_FUNCTION; + + uint32_t maskBits = mask.GetHostOrder (); + uint32_t networkBits = network.GetHostOrder (); + + for (uint32_t i = 0; i < N_BITS; ++i) + { + if (maskBits & 1) + { + uint32_t nMaskBits = N_BITS - i; + NS_ASSERT(nMaskBits >= 0 && nMaskBits < N_BITS); + m_state[nMaskBits].network = networkBits >> (N_BITS - i); + return; + } + maskBits >>= 1; + } + NS_ASSERT_MSG(false, "Impossible"); + return; +} + Ipv4Address Ipv4NetworkManager::Allocate (const Ipv4Mask mask) { @@ -80,8 +104,9 @@ Ipv4NetworkManager::Allocate (const Ipv4Mask mask) { uint32_t nBits = N_BITS - i; NS_ASSERT(nBits >= 0 && nBits < N_BITS); + Ipv4Address addr (m_state[nBits].network << i); ++m_state[nBits].network; - return Ipv4Address (m_state[nBits].network << i); + return addr; } bits >>= 1; } @@ -96,6 +121,7 @@ public: virtual ~Ipv4AddressManager (); Ipv4Address Allocate (const Ipv4Mask mask, const Ipv4Address network); + void Seed (const Ipv4Mask mask, const Ipv4Address address); private: static const uint32_t N_BITS = 32; @@ -131,6 +157,29 @@ Ipv4AddressManager::~Ipv4AddressManager () NS_LOG_FUNCTION; } +void +Ipv4AddressManager::Seed (const Ipv4Mask mask, const Ipv4Address address) +{ + NS_LOG_FUNCTION; + + uint32_t maskBits = mask.GetHostOrder (); + uint32_t addressBits = address.GetHostOrder (); + + for (uint32_t i = 0; i < N_BITS; ++i) + { + if (maskBits & 1) + { + uint32_t nMaskBits = N_BITS - i; + NS_ASSERT(nMaskBits >= 0 && nMaskBits < N_BITS); + m_state[nMaskBits].address = addressBits; + return; + } + maskBits >>= 1; + } + NS_ASSERT_MSG(false, "Impossible"); + return; +} + Ipv4Address Ipv4AddressManager::Allocate (const Ipv4Mask mask, const Ipv4Address network) { @@ -145,10 +194,11 @@ Ipv4AddressManager::Allocate (const Ipv4Mask mask, const Ipv4Address network) { uint32_t nBits = N_BITS - i; NS_ASSERT(nBits >= 0 && nBits < N_BITS); + Ipv4Address addr (net | m_state[nBits].address); ++m_state[nBits].address; NS_ASSERT_MSG((m_state[nBits].mask & m_state[nBits].address) == 0, "Ipv4AddressManager::Allocate(): Overflow"); - return Ipv4Address (net | m_state[nBits].address); + return addr; } bits >>= 1; } @@ -156,6 +206,14 @@ Ipv4AddressManager::Allocate (const Ipv4Mask mask, const Ipv4Address network) return Ipv4Address (bits); } +void +Ipv4AddressEx::SeedAddress (const Ipv4Mask mask, const Ipv4Address address) +{ + NS_LOG_FUNCTION; + + SimulationSingleton::Get ()->Seed (mask, address); +} + Ipv4Address Ipv4AddressEx::AllocateAddress (const Ipv4Mask mask, const Ipv4Address network) { @@ -165,6 +223,14 @@ Ipv4AddressEx::AllocateAddress (const Ipv4Mask mask, const Ipv4Address network) Allocate (mask, network); } +void +Ipv4AddressEx::SeedNetwork (const Ipv4Mask mask, const Ipv4Address address) +{ + NS_LOG_FUNCTION; + + SimulationSingleton::Get ()->Seed (mask, address); +} + Ipv4Address Ipv4AddressEx::AllocateNetwork (const Ipv4Mask mask) { diff --git a/tutorial/ipv4-address-extended.h b/tutorial/ipv4-address-extended.h index fb1626204..0bdfc24e9 100644 --- a/tutorial/ipv4-address-extended.h +++ b/tutorial/ipv4-address-extended.h @@ -28,9 +28,15 @@ namespace ns3 { class Ipv4AddressEx : public Ipv4Address { public: + static void SeedAddress (const Ipv4Mask mask, + const Ipv4Address address); + static Ipv4Address AllocateAddress (const Ipv4Mask mask, const Ipv4Address network); + static void SeedNetwork (const Ipv4Mask mask, + const Ipv4Address address); + static Ipv4Address AllocateNetwork (const Ipv4Mask mask); }; diff --git a/tutorial/testipv4.cc b/tutorial/testipv4.cc index 706d046ed..588580319 100644 --- a/tutorial/testipv4.cc +++ b/tutorial/testipv4.cc @@ -38,6 +38,7 @@ main (int argc, char *argv[]) } Ipv4Mask mask2 ("255.255.0.0"); + Ipv4AddressEx::SeedNetwork (mask2, "192.168.0.0"); for (uint32_t i = 0; i < 10; ++i) { From 11ac94d4498f327275b87f76bf720d4e8531f9b4 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Fri, 5 Oct 2007 18:52:22 -0700 Subject: [PATCH 05/67] exercise --- tutorial/testipv4.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tutorial/testipv4.cc b/tutorial/testipv4.cc index 588580319..7cee873a1 100644 --- a/tutorial/testipv4.cc +++ b/tutorial/testipv4.cc @@ -39,11 +39,12 @@ main (int argc, char *argv[]) Ipv4Mask mask2 ("255.255.0.0"); Ipv4AddressEx::SeedNetwork (mask2, "192.168.0.0"); + Ipv4AddressEx::SeedAddress (mask2, "0.0.0.3"); + Ipv4Address network1 = Ipv4AddressEx::AllocateNetwork (mask2); for (uint32_t i = 0; i < 10; ++i) { - Ipv4Address network = Ipv4AddressEx::AllocateNetwork (mask2); - Ipv4Address address = Ipv4AddressEx::AllocateAddress (mask2, network); + Ipv4Address address = Ipv4AddressEx::AllocateAddress (mask2, network1); NS_LOG_INFO ("address = " << address); } From 3e4acb6921ff4e579284518a1e7fb4daeecdb113 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Mon, 8 Oct 2007 14:50:00 -0700 Subject: [PATCH 06/67] more descriptive name --- ...-extended.cc => ipv4-address-generator.cc} | 78 +++++++++++-------- ...ss-extended.h => ipv4-address-generator.h} | 8 +- tutorial/testipv4.cc | 21 ++--- tutorial/wscript | 2 +- 4 files changed, 62 insertions(+), 47 deletions(-) rename tutorial/{ipv4-address-extended.cc => ipv4-address-generator.cc} (73%) rename tutorial/{ipv4-address-extended.h => ipv4-address-generator.h} (89%) diff --git a/tutorial/ipv4-address-extended.cc b/tutorial/ipv4-address-generator.cc similarity index 73% rename from tutorial/ipv4-address-extended.cc rename to tutorial/ipv4-address-generator.cc index b25d5b6e6..dc28b4ddc 100644 --- a/tutorial/ipv4-address-extended.cc +++ b/tutorial/ipv4-address-generator.cc @@ -19,17 +19,17 @@ #include "ns3/assert.h" #include "ns3/log.h" #include "ns3/simulation-singleton.h" -#include "ipv4-address-extended.h" +#include "ipv4-address-generator.h" -NS_LOG_COMPONENT_DEFINE("Ipv4AddressEx"); +NS_LOG_COMPONENT_DEFINE("Ipv4AddressGenerator"); namespace ns3 { -class Ipv4NetworkManager +class Ipv4NetworkGeneratorImpl { public: - Ipv4NetworkManager (); - virtual ~Ipv4NetworkManager (); + Ipv4NetworkGeneratorImpl (); + virtual ~Ipv4NetworkGeneratorImpl (); Ipv4Address Allocate (const Ipv4Mask mask); void Seed (const Ipv4Mask mask, const Ipv4Address network); @@ -45,7 +45,7 @@ private: State m_state[N_BITS]; }; -Ipv4NetworkManager::Ipv4NetworkManager () +Ipv4NetworkGeneratorImpl::Ipv4NetworkGeneratorImpl () { NS_LOG_FUNCTION; @@ -63,13 +63,15 @@ Ipv4NetworkManager::Ipv4NetworkManager () } } -Ipv4NetworkManager::~Ipv4NetworkManager () +Ipv4NetworkGeneratorImpl::~Ipv4NetworkGeneratorImpl () { NS_LOG_FUNCTION; } -void -Ipv4NetworkManager::Seed (const Ipv4Mask mask, const Ipv4Address network) + void +Ipv4NetworkGeneratorImpl::Seed ( + const Ipv4Mask mask, + const Ipv4Address network) { NS_LOG_FUNCTION; @@ -91,8 +93,8 @@ Ipv4NetworkManager::Seed (const Ipv4Mask mask, const Ipv4Address network) return; } -Ipv4Address -Ipv4NetworkManager::Allocate (const Ipv4Mask mask) + Ipv4Address +Ipv4NetworkGeneratorImpl::Allocate (const Ipv4Mask mask) { NS_LOG_FUNCTION; @@ -114,11 +116,11 @@ Ipv4NetworkManager::Allocate (const Ipv4Mask mask) return Ipv4Address (bits); } -class Ipv4AddressManager +class Ipv4AddressGeneratorImpl { public: - Ipv4AddressManager (); - virtual ~Ipv4AddressManager (); + Ipv4AddressGeneratorImpl (); + virtual ~Ipv4AddressGeneratorImpl (); Ipv4Address Allocate (const Ipv4Mask mask, const Ipv4Address network); void Seed (const Ipv4Mask mask, const Ipv4Address address); @@ -134,7 +136,7 @@ private: State m_state[N_BITS]; }; -Ipv4AddressManager::Ipv4AddressManager () +Ipv4AddressGeneratorImpl::Ipv4AddressGeneratorImpl () { NS_LOG_FUNCTION; @@ -152,13 +154,15 @@ Ipv4AddressManager::Ipv4AddressManager () } } -Ipv4AddressManager::~Ipv4AddressManager () +Ipv4AddressGeneratorImpl::~Ipv4AddressGeneratorImpl () { NS_LOG_FUNCTION; } -void -Ipv4AddressManager::Seed (const Ipv4Mask mask, const Ipv4Address address) + void +Ipv4AddressGeneratorImpl::Seed ( + const Ipv4Mask mask, + const Ipv4Address address) { NS_LOG_FUNCTION; @@ -180,8 +184,10 @@ Ipv4AddressManager::Seed (const Ipv4Mask mask, const Ipv4Address address) return; } -Ipv4Address -Ipv4AddressManager::Allocate (const Ipv4Mask mask, const Ipv4Address network) + Ipv4Address +Ipv4AddressGeneratorImpl::Allocate ( + const Ipv4Mask mask, + const Ipv4Address network) { NS_LOG_FUNCTION; @@ -197,7 +203,7 @@ Ipv4AddressManager::Allocate (const Ipv4Mask mask, const Ipv4Address network) Ipv4Address addr (net | m_state[nBits].address); ++m_state[nBits].address; NS_ASSERT_MSG((m_state[nBits].mask & m_state[nBits].address) == 0, - "Ipv4AddressManager::Allocate(): Overflow"); + "Ipv4AddressGeneratorImpl::Allocate(): Overflow"); return addr; } bits >>= 1; @@ -206,37 +212,43 @@ Ipv4AddressManager::Allocate (const Ipv4Mask mask, const Ipv4Address network) return Ipv4Address (bits); } -void -Ipv4AddressEx::SeedAddress (const Ipv4Mask mask, const Ipv4Address address) + void +Ipv4AddressGenerator::SeedAddress ( + const Ipv4Mask mask, + const Ipv4Address address) { NS_LOG_FUNCTION; - SimulationSingleton::Get ()->Seed (mask, address); + SimulationSingleton::Get ()->Seed (mask, address); } -Ipv4Address -Ipv4AddressEx::AllocateAddress (const Ipv4Mask mask, const Ipv4Address network) + Ipv4Address +Ipv4AddressGenerator::AllocateAddress ( + const Ipv4Mask mask, + const Ipv4Address network) { NS_LOG_FUNCTION; - return SimulationSingleton::Get ()-> + return SimulationSingleton::Get ()-> Allocate (mask, network); } -void -Ipv4AddressEx::SeedNetwork (const Ipv4Mask mask, const Ipv4Address address) + void +Ipv4AddressGenerator::SeedNetwork ( + const Ipv4Mask mask, + const Ipv4Address address) { NS_LOG_FUNCTION; - SimulationSingleton::Get ()->Seed (mask, address); + SimulationSingleton::Get ()->Seed (mask, address); } -Ipv4Address -Ipv4AddressEx::AllocateNetwork (const Ipv4Mask mask) + Ipv4Address +Ipv4AddressGenerator::AllocateNetwork (const Ipv4Mask mask) { NS_LOG_FUNCTION; - return SimulationSingleton::Get ()-> + return SimulationSingleton::Get ()-> Allocate (mask); } diff --git a/tutorial/ipv4-address-extended.h b/tutorial/ipv4-address-generator.h similarity index 89% rename from tutorial/ipv4-address-extended.h rename to tutorial/ipv4-address-generator.h index 0bdfc24e9..2962940d3 100644 --- a/tutorial/ipv4-address-extended.h +++ b/tutorial/ipv4-address-generator.h @@ -16,8 +16,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef IPV4_ADDRESS_EXTENDED_H -#define IPV4_ADDRESS_EXTENDED_H +#ifndef IPV4_ADDRESS_GENERATOR_H +#define IPV4_ADDRESS_GENERATOR_H #include #include @@ -26,7 +26,7 @@ namespace ns3 { -class Ipv4AddressEx : public Ipv4Address { +class Ipv4AddressGenerator { public: static void SeedAddress (const Ipv4Mask mask, const Ipv4Address address); @@ -42,4 +42,4 @@ public: }; // namespace ns3 -#endif /* IPV4_ADDRESS_EXTENDED_H */ +#endif /* IPV4_ADDRESS_GENERATOR_H */ diff --git a/tutorial/testipv4.cc b/tutorial/testipv4.cc index 7cee873a1..dcad2e387 100644 --- a/tutorial/testipv4.cc +++ b/tutorial/testipv4.cc @@ -15,7 +15,7 @@ */ #include "ns3/log.h" -#include "ipv4-address-extended.h" +#include "ipv4-address-generator.h" NS_LOG_COMPONENT_DEFINE ("TestIpv4"); @@ -32,19 +32,21 @@ main (int argc, char *argv[]) for (uint32_t i = 0; i < 10; ++i) { - Ipv4Address network = Ipv4AddressEx::AllocateNetwork (mask1); - Ipv4Address address = Ipv4AddressEx::AllocateAddress (mask1, network); + Ipv4Address network = Ipv4AddressGenerator::AllocateNetwork (mask1); + Ipv4Address address = Ipv4AddressGenerator::AllocateAddress (mask1, + network); NS_LOG_INFO ("address = " << address); } Ipv4Mask mask2 ("255.255.0.0"); - Ipv4AddressEx::SeedNetwork (mask2, "192.168.0.0"); - Ipv4AddressEx::SeedAddress (mask2, "0.0.0.3"); + Ipv4AddressGenerator::SeedNetwork (mask2, "192.168.0.0"); + Ipv4AddressGenerator::SeedAddress (mask2, "0.0.0.3"); - Ipv4Address network1 = Ipv4AddressEx::AllocateNetwork (mask2); + Ipv4Address network1 = Ipv4AddressGenerator::AllocateNetwork (mask2); for (uint32_t i = 0; i < 10; ++i) { - Ipv4Address address = Ipv4AddressEx::AllocateAddress (mask2, network1); + Ipv4Address address = Ipv4AddressGenerator::AllocateAddress (mask2, + network1); NS_LOG_INFO ("address = " << address); } @@ -52,8 +54,9 @@ main (int argc, char *argv[]) for (uint32_t i = 0; i < 10; ++i) { - Ipv4Address network = Ipv4AddressEx::AllocateNetwork (mask3); - Ipv4Address address = Ipv4AddressEx::AllocateAddress (mask3, network); + Ipv4Address network = Ipv4AddressGenerator::AllocateNetwork (mask3); + Ipv4Address address = Ipv4AddressGenerator::AllocateAddress (mask3, + network); NS_LOG_INFO ("address = " << address); } } diff --git a/tutorial/wscript b/tutorial/wscript index 4a22ee109..17a9597d1 100644 --- a/tutorial/wscript +++ b/tutorial/wscript @@ -23,4 +23,4 @@ def build(bld): obj = bld.create_ns3_program('testipv4', ['core']) - obj.source = ['testipv4.cc', 'ipv4-address-extended.cc'] + obj.source = ['testipv4.cc', 'ipv4-address-generator.cc'] From 8ac82843aff7c27a32383f0d7bd5e6a311bb75f5 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Mon, 8 Oct 2007 18:51:48 -0700 Subject: [PATCH 07/67] tutorial file names --- .../{tutorial-naive-dumbbell.cc => tutorial-linear-dumbbell.cc} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tutorial/{tutorial-naive-dumbbell.cc => tutorial-linear-dumbbell.cc} (100%) diff --git a/tutorial/tutorial-naive-dumbbell.cc b/tutorial/tutorial-linear-dumbbell.cc similarity index 100% rename from tutorial/tutorial-naive-dumbbell.cc rename to tutorial/tutorial-linear-dumbbell.cc From 9f2902e9d217a092d0f78d7a6a061a52af8ca2e9 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Mon, 8 Oct 2007 20:51:21 -0700 Subject: [PATCH 08/67] support for star network, example in tutorial --- .../point-to-point-ipv4-topology.cc | 73 ++++++++ .../point-to-point-ipv4-topology.h | 49 +++++ src/devices/point-to-point/wscript | 2 + tutorial/tutorial-point-to-point.cc | 78 ++++++++ tutorial/tutorial-star.cc | 176 ++++++++++++++++++ tutorial/wscript | 12 +- 6 files changed, 388 insertions(+), 2 deletions(-) create mode 100644 src/devices/point-to-point/point-to-point-ipv4-topology.cc create mode 100644 src/devices/point-to-point/point-to-point-ipv4-topology.h create mode 100644 tutorial/tutorial-point-to-point.cc create mode 100644 tutorial/tutorial-star.cc diff --git a/src/devices/point-to-point/point-to-point-ipv4-topology.cc b/src/devices/point-to-point/point-to-point-ipv4-topology.cc new file mode 100644 index 000000000..bc4a21967 --- /dev/null +++ b/src/devices/point-to-point/point-to-point-ipv4-topology.cc @@ -0,0 +1,73 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * 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 + */ + +#include "ns3/assert.h" +#include "ns3/log.h" +#include "ns3/nstime.h" +#include "ns3/internet-node.h" +#include "ns3/ipv4-address.h" +#include "ns3/ipv4.h" +#include "ns3/queue.h" + +#include "point-to-point-channel.h" +#include "point-to-point-net-device.h" +#include "point-to-point-ipv4-topology.h" + +namespace ns3 { + + Ptr +PointToPointIpv4Topology::CreateChannel ( + const DataRate& bps, + const Time& delay) +{ + return Create (bps, delay); +} + + uint32_t +PointToPointIpv4Topology::AddNetDevice ( + Ptr node, + Ptr channel) +{ + NS_ASSERT (channel->GetNDevices () <= 1); + + Ptr nd = Create (node); + + Ptr q = Queue::CreateDefault (); + nd->AddQueue(q); + nd->Attach (channel); + + return nd->GetIfIndex (); +} + + uint32_t +PointToPointIpv4Topology::AddAddress ( + Ptr node, + uint32_t netDeviceNumber, + Ipv4Address address, + Ipv4Mask mask) +{ + Ptr nd = node->GetDevice(netDeviceNumber); + Ptr ipv4 = node->QueryInterface (Ipv4::iid); + uint32_t ifIndex = ipv4->AddInterface (nd); + + ipv4->SetAddress (ifIndex, address); + ipv4->SetNetworkMask (ifIndex, mask); + ipv4->SetUp (ifIndex); + + return ifIndex; +} + +} // namespace ns3 diff --git a/src/devices/point-to-point/point-to-point-ipv4-topology.h b/src/devices/point-to-point/point-to-point-ipv4-topology.h new file mode 100644 index 000000000..c2a9a4391 --- /dev/null +++ b/src/devices/point-to-point/point-to-point-ipv4-topology.h @@ -0,0 +1,49 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * 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 + */ + +#ifndef POINT_TO_POINT_IPV4_TOPOLOGY_H +#define POINT_TO_POINT_IPV4_TOPOLOGY_H + +#include "ns3/ptr.h" + +namespace ns3 { + +class PointToPointChannel; +class Node; +class Ipv4Address; +class Ipv4Mask; +class DataRate; + +class PointToPointIpv4Topology { +public: + static Ptr CreateChannel ( + const DataRate& dataRate, const Time& delay); + + static uint32_t AddNetDevice( + Ptr node, + Ptr channel); + + static uint32_t AddAddress( + Ptr node, + uint32_t ndIndex, + Ipv4Address address, + Ipv4Mask mask); +}; + +} // namespace ns3 + +#endif // POINT_TO_POINT_IPV4_TOPOLOGY_H + diff --git a/src/devices/point-to-point/wscript b/src/devices/point-to-point/wscript index c788a7880..7ec56847c 100644 --- a/src/devices/point-to-point/wscript +++ b/src/devices/point-to-point/wscript @@ -7,11 +7,13 @@ def build(bld): 'point-to-point-net-device.cc', 'point-to-point-channel.cc', 'point-to-point-topology.cc', + 'point-to-point-ipv4-topology.cc', ] headers = bld.create_obj('ns3header') headers.source = [ 'point-to-point-net-device.h', 'point-to-point-channel.h', 'point-to-point-topology.h', + 'point-to-point-ipv4-topology.h', ] diff --git a/tutorial/tutorial-point-to-point.cc b/tutorial/tutorial-point-to-point.cc new file mode 100644 index 000000000..30e1b02d7 --- /dev/null +++ b/tutorial/tutorial-point-to-point.cc @@ -0,0 +1,78 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * 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 + */ + +#include "ns3/log.h" +#include "ns3/ptr.h" +#include "ns3/internet-node.h" +#include "ns3/point-to-point-channel.h" +#include "ns3/mac48-address.h" +#include "ns3/point-to-point-net-device.h" +#include "ns3/point-to-point-topology.h" +#include "ns3/udp-echo-client.h" +#include "ns3/udp-echo-server.h" +#include "ns3/simulator.h" +#include "ns3/nstime.h" +#include "ns3/ascii-trace.h" +#include "ns3/pcap-trace.h" +#include "ns3/global-route-manager.h" + +NS_LOG_COMPONENT_DEFINE ("PointToPointSimulation"); + +using namespace ns3; + +// Network topology +// +// point to point +// +--------------+ +// | | +// n0 n1 +// +int +main (int argc, char *argv[]) +{ + LogComponentEnable ("PointToPointSimulation", LOG_LEVEL_INFO); + + NS_LOG_INFO ("Point to Point Topology Simulation"); + + Ptr n0 = Create (); + Ptr n1 = Create (); + + Ptr link = PointToPointTopology::AddPointToPointLink ( + n0, n1, DataRate (38400), MilliSeconds (20)); + + PointToPointTopology::AddIpv4Addresses (link, n0, "10.1.1.1", + n1, "10.1.1.2"); + + uint16_t port = 7; + + Ptr client = Create (n0, "10.1.1.2", port, + 1, Seconds(1.), 1024); + + Ptr server = Create (n1, port); + + server->Start(Seconds(1.)); + client->Start(Seconds(2.)); + + server->Stop (Seconds(10.)); + client->Stop (Seconds(10.)); + + AsciiTrace asciitrace ("tutorial.tr"); + asciitrace.TraceAllQueues (); + asciitrace.TraceAllNetDeviceRx (); + + Simulator::Run (); + Simulator::Destroy (); +} diff --git a/tutorial/tutorial-star.cc b/tutorial/tutorial-star.cc new file mode 100644 index 000000000..c7251893f --- /dev/null +++ b/tutorial/tutorial-star.cc @@ -0,0 +1,176 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * 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 + */ + +#include "ns3/log.h" +#include "ns3/ptr.h" +#include "ns3/internet-node.h" +#include "ns3/point-to-point-channel.h" +#include "ns3/mac48-address.h" +#include "ns3/point-to-point-net-device.h" +#include "ns3/point-to-point-ipv4-topology.h" +#include "ns3/udp-echo-client.h" +#include "ns3/udp-echo-server.h" +#include "ns3/simulator.h" +#include "ns3/nstime.h" +#include "ns3/ascii-trace.h" +#include "ns3/pcap-trace.h" +#include "ns3/global-route-manager.h" + +NS_LOG_COMPONENT_DEFINE ("PointToPointSimulation"); + +using namespace ns3; + +// Network topology +// +// n3 n2 +// | / +// | / +// n4 --- n0 --- n1 +// / | +// / | +// n5 n6 + +int +main (int argc, char *argv[]) +{ + LogComponentEnable ("PointToPointSimulation", LOG_LEVEL_INFO); + + NS_LOG_INFO ("Point to Point Topology Simulation"); + + Ptr n0 = Create (); + Ptr n1 = Create (); + Ptr n2 = Create (); + Ptr n3 = Create (); + Ptr n4 = Create (); + Ptr n5 = Create (); + Ptr n6 = Create (); + + Ptr link01 = + PointToPointIpv4Topology::CreateChannel (DataRate (38400), + MilliSeconds (20)); + + uint32_t nd01 = PointToPointIpv4Topology::AddNetDevice (n0, + link01); + + Ptr link02 = + PointToPointIpv4Topology::CreateChannel (DataRate (38400), + MilliSeconds (20)); + + uint32_t nd02 = PointToPointIpv4Topology::AddNetDevice (n0, + link02); + + Ptr link03 = + PointToPointIpv4Topology::CreateChannel (DataRate (38400), + MilliSeconds (20)); + + uint32_t nd03 = PointToPointIpv4Topology::AddNetDevice (n0, + link03); + + Ptr link04 = + PointToPointIpv4Topology::CreateChannel (DataRate (38400), + MilliSeconds (20)); + + uint32_t nd04 = PointToPointIpv4Topology::AddNetDevice (n0, + link04); + + Ptr link05 = + PointToPointIpv4Topology::CreateChannel (DataRate (38400), + MilliSeconds (20)); + + uint32_t nd05 = PointToPointIpv4Topology::AddNetDevice (n0, + link05); + + Ptr link06 = + PointToPointIpv4Topology::CreateChannel (DataRate (38400), + MilliSeconds (20)); + + uint32_t nd06 = PointToPointIpv4Topology::AddNetDevice (n0, + link06); + + uint32_t nd1 = PointToPointIpv4Topology::AddNetDevice (n1, + link01); + + uint32_t nd2 = PointToPointIpv4Topology::AddNetDevice (n2, + link02); + + uint32_t nd3 = PointToPointIpv4Topology::AddNetDevice (n3, + link03); + + uint32_t nd4 = PointToPointIpv4Topology::AddNetDevice (n4, + link04); + + uint32_t nd5 = PointToPointIpv4Topology::AddNetDevice (n5, + link05); + + uint32_t nd6 = PointToPointIpv4Topology::AddNetDevice (n6, + link06); + + PointToPointIpv4Topology::AddAddress (n0, nd01, "10.1.1.1", + "255.255.255.252"); + + PointToPointIpv4Topology::AddAddress (n1, nd1, "10.1.1.2", + "255.255.255.252"); + + PointToPointIpv4Topology::AddAddress (n0, nd02, "10.1.2.1", + "255.255.255.252"); + + PointToPointIpv4Topology::AddAddress (n2, nd2, "10.1.2.2", + "255.255.255.252"); + + PointToPointIpv4Topology::AddAddress (n0, nd03, "10.1.3.1", + "255.255.255.252"); + + PointToPointIpv4Topology::AddAddress (n3, nd3, "10.1.2.2", + "255.255.255.252"); + + PointToPointIpv4Topology::AddAddress (n0, nd04, "10.1.4.1", + "255.255.255.252"); + + PointToPointIpv4Topology::AddAddress (n4, nd4, "10.1.4.2", + "255.255.255.252"); + + PointToPointIpv4Topology::AddAddress (n0, nd05, "10.1.5.1", + "255.255.255.252"); + + PointToPointIpv4Topology::AddAddress (n5, nd5, "10.1.5.2", + "255.255.255.252"); + + PointToPointIpv4Topology::AddAddress (n0, nd06, "10.1.6.1", + "255.255.255.252"); + + PointToPointIpv4Topology::AddAddress (n6, nd6, "10.1.6.2", + "255.255.255.252"); + + uint16_t port = 7; + + Ptr client = Create (n0, "10.1.1.2", port, + 1, Seconds(1.), 1024); + + Ptr server = Create (n1, port); + + server->Start(Seconds(1.)); + client->Start(Seconds(2.)); + + server->Stop (Seconds(10.)); + client->Stop (Seconds(10.)); + + AsciiTrace asciitrace ("tutorial.tr"); + asciitrace.TraceAllQueues (); + asciitrace.TraceAllNetDeviceRx (); + + Simulator::Run (); + Simulator::Destroy (); +} diff --git a/tutorial/wscript b/tutorial/wscript index 17a9597d1..0284fc689 100644 --- a/tutorial/wscript +++ b/tutorial/wscript @@ -17,9 +17,17 @@ def build(bld): ['core']) obj.source = 'tutorial-csma-echo-pcap-trace.cc' - obj = bld.create_ns3_program('tutorial-naive-dumbbell', + obj = bld.create_ns3_program('tutorial-point-to-point', ['core']) - obj.source = 'tutorial-naive-dumbbell.cc' + obj.source = 'tutorial-point-to-point.cc' + + obj = bld.create_ns3_program('tutorial-star', + ['core']) + obj.source = 'tutorial-star.cc' + + obj = bld.create_ns3_program('tutorial-linear-dumbbell', + ['core']) + obj.source = 'tutorial-linear-dumbbell.cc' obj = bld.create_ns3_program('testipv4', ['core']) From 79aa1535f365ce35eb2f86cce9455f8aa6807919 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Mon, 8 Oct 2007 22:00:04 -0700 Subject: [PATCH 09/67] topologies --- tutorial/tutorial-star-routing.cc | 166 ++++++++++++++++++++++++++++++ tutorial/tutorial-star.cc | 26 ++--- tutorial/wscript | 4 + 3 files changed, 177 insertions(+), 19 deletions(-) create mode 100644 tutorial/tutorial-star-routing.cc diff --git a/tutorial/tutorial-star-routing.cc b/tutorial/tutorial-star-routing.cc new file mode 100644 index 000000000..765ac7728 --- /dev/null +++ b/tutorial/tutorial-star-routing.cc @@ -0,0 +1,166 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * 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 + */ + +#include "ns3/log.h" +#include "ns3/ptr.h" +#include "ns3/internet-node.h" +#include "ns3/point-to-point-channel.h" +#include "ns3/mac48-address.h" +#include "ns3/point-to-point-net-device.h" +#include "ns3/point-to-point-ipv4-topology.h" +#include "ns3/udp-echo-client.h" +#include "ns3/udp-echo-server.h" +#include "ns3/simulator.h" +#include "ns3/nstime.h" +#include "ns3/ascii-trace.h" +#include "ns3/pcap-trace.h" +#include "ns3/global-route-manager.h" + +NS_LOG_COMPONENT_DEFINE ("PointToPointSimulation"); + +using namespace ns3; + +// Network topology +// +// n3 n2 +// | / +// | / +// n4 --- n0 --- n1 +// / | +// / | +// n5 n6 + +int +main (int argc, char *argv[]) +{ + LogComponentEnable ("PointToPointSimulation", LOG_LEVEL_INFO); + + NS_LOG_INFO ("Point to Point Topology Simulation"); + + Ptr n0 = Create (); + Ptr n1 = Create (); + Ptr n2 = Create (); + Ptr n3 = Create (); + Ptr n4 = Create (); + Ptr n5 = Create (); + Ptr n6 = Create (); + + Ptr link01 = + PointToPointIpv4Topology::CreateChannel (DataRate (38400), + MilliSeconds (20)); + + uint32_t nd01 = PointToPointIpv4Topology::AddNetDevice (n0, + link01); + + Ptr link02 = + PointToPointIpv4Topology::CreateChannel (DataRate (38400), + MilliSeconds (20)); + + uint32_t nd02 = PointToPointIpv4Topology::AddNetDevice (n0, + link02); + + Ptr link03 = + PointToPointIpv4Topology::CreateChannel (DataRate (38400), + MilliSeconds (20)); + + uint32_t nd03 = PointToPointIpv4Topology::AddNetDevice (n0, + link03); + + Ptr link04 = + PointToPointIpv4Topology::CreateChannel (DataRate (38400), + MilliSeconds (20)); + + uint32_t nd04 = PointToPointIpv4Topology::AddNetDevice (n0, + link04); + + Ptr link05 = + PointToPointIpv4Topology::CreateChannel (DataRate (38400), + MilliSeconds (20)); + + uint32_t nd05 = PointToPointIpv4Topology::AddNetDevice (n0, + link05); + + Ptr link06 = + PointToPointIpv4Topology::CreateChannel (DataRate (38400), + MilliSeconds (20)); + + uint32_t nd06 = PointToPointIpv4Topology::AddNetDevice (n0, link06); + + uint32_t nd1 = PointToPointIpv4Topology::AddNetDevice (n1, link01); + uint32_t nd2 = PointToPointIpv4Topology::AddNetDevice (n2, link02); + uint32_t nd3 = PointToPointIpv4Topology::AddNetDevice (n3, link03); + uint32_t nd4 = PointToPointIpv4Topology::AddNetDevice (n4, link04); + uint32_t nd5 = PointToPointIpv4Topology::AddNetDevice (n5, link05); + uint32_t nd6 = PointToPointIpv4Topology::AddNetDevice (n6, link06); + + PointToPointIpv4Topology::AddAddress (n0, nd01, "10.1.1.1", + "255.255.255.252"); + + PointToPointIpv4Topology::AddAddress (n1, nd1, "10.1.1.2", + "255.255.255.252"); + + PointToPointIpv4Topology::AddAddress (n0, nd02, "10.1.2.1", + "255.255.255.252"); + + PointToPointIpv4Topology::AddAddress (n2, nd2, "10.1.2.2", + "255.255.255.252"); + + PointToPointIpv4Topology::AddAddress (n0, nd03, "10.1.3.1", + "255.255.255.252"); + + PointToPointIpv4Topology::AddAddress (n3, nd3, "10.1.2.2", + "255.255.255.252"); + + PointToPointIpv4Topology::AddAddress (n0, nd04, "10.1.4.1", + "255.255.255.252"); + + PointToPointIpv4Topology::AddAddress (n4, nd4, "10.1.4.2", + "255.255.255.252"); + + PointToPointIpv4Topology::AddAddress (n0, nd05, "10.1.5.1", + "255.255.255.252"); + + PointToPointIpv4Topology::AddAddress (n5, nd5, "10.1.5.2", + "255.255.255.252"); + + PointToPointIpv4Topology::AddAddress (n0, nd06, "10.1.6.1", + "255.255.255.252"); + + PointToPointIpv4Topology::AddAddress (n6, nd6, "10.1.6.2", + "255.255.255.252"); + + uint16_t port = 7; + + Ptr client = Create (n4, "10.1.1.2", port, + 1, Seconds(1.), 1024); + + Ptr server = Create (n1, port); + + server->Start(Seconds(1.)); + client->Start(Seconds(2.)); + + server->Stop (Seconds(10.)); + client->Stop (Seconds(10.)); + + AsciiTrace asciitrace ("tutorial.tr"); + asciitrace.TraceAllQueues (); + asciitrace.TraceAllNetDeviceRx (); + + GlobalRouteManager::PopulateRoutingTables (); + + Simulator::Run (); + Simulator::Destroy (); +} diff --git a/tutorial/tutorial-star.cc b/tutorial/tutorial-star.cc index c7251893f..dafc5a82a 100644 --- a/tutorial/tutorial-star.cc +++ b/tutorial/tutorial-star.cc @@ -97,26 +97,14 @@ main (int argc, char *argv[]) PointToPointIpv4Topology::CreateChannel (DataRate (38400), MilliSeconds (20)); - uint32_t nd06 = PointToPointIpv4Topology::AddNetDevice (n0, - link06); + uint32_t nd06 = PointToPointIpv4Topology::AddNetDevice (n0, link06); - uint32_t nd1 = PointToPointIpv4Topology::AddNetDevice (n1, - link01); - - uint32_t nd2 = PointToPointIpv4Topology::AddNetDevice (n2, - link02); - - uint32_t nd3 = PointToPointIpv4Topology::AddNetDevice (n3, - link03); - - uint32_t nd4 = PointToPointIpv4Topology::AddNetDevice (n4, - link04); - - uint32_t nd5 = PointToPointIpv4Topology::AddNetDevice (n5, - link05); - - uint32_t nd6 = PointToPointIpv4Topology::AddNetDevice (n6, - link06); + uint32_t nd1 = PointToPointIpv4Topology::AddNetDevice (n1, link01); + uint32_t nd2 = PointToPointIpv4Topology::AddNetDevice (n2, link02); + uint32_t nd3 = PointToPointIpv4Topology::AddNetDevice (n3, link03); + uint32_t nd4 = PointToPointIpv4Topology::AddNetDevice (n4, link04); + uint32_t nd5 = PointToPointIpv4Topology::AddNetDevice (n5, link05); + uint32_t nd6 = PointToPointIpv4Topology::AddNetDevice (n6, link06); PointToPointIpv4Topology::AddAddress (n0, nd01, "10.1.1.1", "255.255.255.252"); diff --git a/tutorial/wscript b/tutorial/wscript index 0284fc689..7e51208e3 100644 --- a/tutorial/wscript +++ b/tutorial/wscript @@ -25,6 +25,10 @@ def build(bld): ['core']) obj.source = 'tutorial-star.cc' + obj = bld.create_ns3_program('tutorial-star-routing', + ['core']) + obj.source = 'tutorial-star-routing.cc' + obj = bld.create_ns3_program('tutorial-linear-dumbbell', ['core']) obj.source = 'tutorial-linear-dumbbell.cc' From 6b5b86f34372778723a76721af0c42feeb67e887 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Tue, 9 Oct 2007 18:02:32 -0700 Subject: [PATCH 10/67] tutorial topologies --- tutorial/tutorial-linear-dumbbell.cc | 62 +++++++++++++++++++++------- tutorial/tutorial-star-routing.cc | 6 +-- tutorial/tutorial-star.cc | 6 +-- 3 files changed, 54 insertions(+), 20 deletions(-) diff --git a/tutorial/tutorial-linear-dumbbell.cc b/tutorial/tutorial-linear-dumbbell.cc index e203ef9f3..c39abd963 100644 --- a/tutorial/tutorial-linear-dumbbell.cc +++ b/tutorial/tutorial-linear-dumbbell.cc @@ -51,10 +51,11 @@ int main (int argc, char *argv[]) { LogComponentEnable ("DumbbellSimulation", LOG_LEVEL_INFO); -// LogComponentEnableAll (LOG_LEVEL_ALL, LOG_DECORATE_ALL); NS_LOG_INFO ("Dumbbell Topology Simulation"); - +// +// Create the lan on the left side of the dumbbell. +// Ptr n0 = Create (); Ptr n1 = Create (); Ptr n2 = Create (); @@ -79,7 +80,9 @@ main (int argc, char *argv[]) CsmaIpv4Topology::AddIpv4Address (n1, nd1, "10.1.1.2", "255.255.255.0"); CsmaIpv4Topology::AddIpv4Address (n2, nd2, "10.1.1.3", "255.255.255.0"); CsmaIpv4Topology::AddIpv4Address (n3, nd3, "10.1.1.4", "255.255.255.0"); - +// +// Create the lan on the right side of the dumbbell. +// Ptr n4 = Create (); Ptr n5 = Create (); Ptr n6 = Create (); @@ -104,31 +107,62 @@ main (int argc, char *argv[]) CsmaIpv4Topology::AddIpv4Address (n5, nd5, "10.1.2.2", "255.255.255.0"); CsmaIpv4Topology::AddIpv4Address (n6, nd6, "10.1.2.3", "255.255.255.0"); CsmaIpv4Topology::AddIpv4Address (n7, nd7, "10.1.2.4", "255.255.255.0"); - +// +// Create the point-to-point link to connect the two lans. +// Ptr link = PointToPointTopology::AddPointToPointLink ( n3, n4, DataRate (38400), MilliSeconds (20)); PointToPointTopology::AddIpv4Addresses (link, n3, "10.1.3.1", n4, "10.1.3.2"); - +// +// Create data flows across the link: +// n0 ==> n4 ==> n0 +// n1 ==> n5 ==> n1 +// n2 ==> n6 ==> n2 +// n3 ==> n7 ==> n3 +// uint16_t port = 7; - Ptr client = Create (n0, "10.1.2.4", port, - 1, Seconds(1.), 1024); + Ptr client0 = Create (n0, "10.1.2.1", port, + 100, Seconds(.01), 1024); + Ptr client1 = Create (n1, "10.1.2.2", port, + 100, Seconds(.01), 1024); + Ptr client2 = Create (n2, "10.1.2.3", port, + 100, Seconds(.01), 1024); + Ptr client3 = Create (n3, "10.1.2.4", port, + 100, Seconds(.01), 1024); - Ptr server = Create (n7, port); + Ptr server4 = Create (n4, port); + Ptr server5 = Create (n5, port); + Ptr server6 = Create (n6, port); + Ptr server7 = Create (n7, port); - server->Start(Seconds(1.)); - client->Start(Seconds(2.)); + server4->Start(Seconds(1.)); + server5->Start(Seconds(1.)); + server6->Start(Seconds(1.)); + server7->Start(Seconds(1.)); - server->Stop (Seconds(10.)); - client->Stop (Seconds(10.)); + client0->Start(Seconds(2.)); + client1->Start(Seconds(2.1)); + client2->Start(Seconds(2.2)); + client3->Start(Seconds(2.3)); - AsciiTrace asciitrace ("tutorial-4.tr"); + server4->Stop (Seconds(10.)); + server5->Stop (Seconds(10.)); + server6->Stop (Seconds(10.)); + server7->Stop (Seconds(10.)); + + client0->Stop (Seconds(10.)); + client1->Stop (Seconds(10.)); + client2->Stop (Seconds(10.)); + client3->Stop (Seconds(10.)); + + AsciiTrace asciitrace ("tutorial.tr"); asciitrace.TraceAllQueues (); asciitrace.TraceAllNetDeviceRx (); - PcapTrace pcaptrace ("tutorial-4.pcap"); + PcapTrace pcaptrace ("tutorial.pcap"); pcaptrace.TraceAllIp (); GlobalRouteManager::PopulateRoutingTables (); diff --git a/tutorial/tutorial-star-routing.cc b/tutorial/tutorial-star-routing.cc index 765ac7728..a0db26180 100644 --- a/tutorial/tutorial-star-routing.cc +++ b/tutorial/tutorial-star-routing.cc @@ -29,7 +29,7 @@ #include "ns3/pcap-trace.h" #include "ns3/global-route-manager.h" -NS_LOG_COMPONENT_DEFINE ("PointToPointSimulation"); +NS_LOG_COMPONENT_DEFINE ("StarRoutingSimulation"); using namespace ns3; @@ -46,9 +46,9 @@ using namespace ns3; int main (int argc, char *argv[]) { - LogComponentEnable ("PointToPointSimulation", LOG_LEVEL_INFO); + LogComponentEnable ("StarRoutingSimulation", LOG_LEVEL_INFO); - NS_LOG_INFO ("Point to Point Topology Simulation"); + NS_LOG_INFO ("Star Topology with Routing Simulation"); Ptr n0 = Create (); Ptr n1 = Create (); diff --git a/tutorial/tutorial-star.cc b/tutorial/tutorial-star.cc index dafc5a82a..38ff6100e 100644 --- a/tutorial/tutorial-star.cc +++ b/tutorial/tutorial-star.cc @@ -29,7 +29,7 @@ #include "ns3/pcap-trace.h" #include "ns3/global-route-manager.h" -NS_LOG_COMPONENT_DEFINE ("PointToPointSimulation"); +NS_LOG_COMPONENT_DEFINE ("StarSimulation"); using namespace ns3; @@ -46,9 +46,9 @@ using namespace ns3; int main (int argc, char *argv[]) { - LogComponentEnable ("PointToPointSimulation", LOG_LEVEL_INFO); + LogComponentEnable ("StarSimulation", LOG_LEVEL_INFO); - NS_LOG_INFO ("Point to Point Topology Simulation"); + NS_LOG_INFO ("Star Topology Simulation"); Ptr n0 = Create (); Ptr n1 = Create (); From 2425ad39ef99157cc05df51bba4504747d7c0eeb Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Tue, 9 Oct 2007 21:54:03 -0700 Subject: [PATCH 11/67] bus network --- tutorial/bus-network.cc | 65 ++++++++++++++++++++++++++++++++ tutorial/bus-network.h | 53 ++++++++++++++++++++++++++ tutorial/tutorial-bus-network.cc | 63 +++++++++++++++++++++++++++++++ tutorial/wscript | 6 +++ 4 files changed, 187 insertions(+) create mode 100644 tutorial/bus-network.cc create mode 100644 tutorial/bus-network.h create mode 100644 tutorial/tutorial-bus-network.cc diff --git a/tutorial/bus-network.cc b/tutorial/bus-network.cc new file mode 100644 index 000000000..7f6051340 --- /dev/null +++ b/tutorial/bus-network.cc @@ -0,0 +1,65 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 University of Washington + * + * 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 + */ + +#include "ns3/mac48-address.h" +#include "ns3/csma-net-device.h" +#include "ns3/csma-topology.h" +#include "ns3/csma-ipv4-topology.h" + +#include "bus-network.h" +#include "ipv4-address-generator.h" + +namespace ns3 { + +BusNetwork::BusNetwork ( + Ipv4Mask mask, + Ipv4Address network, + Ipv4Address startAddress, + DataRate bps, + Time delay, + uint32_t n) +{ + Ipv4AddressGenerator::SeedNetwork (mask, network); + Ipv4AddressGenerator::SeedAddress (mask, startAddress); + + m_channel = CsmaTopology::CreateCsmaChannel (bps, delay); + + for (uint32_t i = 0; i < n; ++i) + { + Ptr node = Create (); + uint32_t nd = CsmaIpv4Topology::AddIpv4CsmaNetDevice (node, m_channel, + Mac48Address::Allocate ()); + Ipv4Address address = Ipv4AddressGenerator::AllocateAddress (mask, + network); + CsmaIpv4Topology::AddIpv4Address (node, nd, address, mask); + m_nodes.push_back (node); + } +} + +BusNetwork::~BusNetwork () +{ + m_nodes.erase (m_nodes.begin (), m_nodes.end ()); +} + + Ptr +BusNetwork::GetNode (uint32_t n) +{ + return m_nodes[n]; +} + +}; // namespace ns3 diff --git a/tutorial/bus-network.h b/tutorial/bus-network.h new file mode 100644 index 000000000..b69b6a6d5 --- /dev/null +++ b/tutorial/bus-network.h @@ -0,0 +1,53 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 University of Washington + * + * 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 + */ + +#ifndef BUS_NETWORK_H +#define BUS_NETWORK_H + +#include +#include "ns3/ptr.h" +#include "ns3/node.h" +#include "ns3/ipv4-address.h" +#include "ns3/data-rate.h" +#include "ns3/csma-channel.h" + +namespace ns3 { + +class BusNetwork +{ +public: + BusNetwork ( + Ipv4Mask mask, + Ipv4Address network, + Ipv4Address startAddress, + DataRate bps, + Time delay, + uint32_t n); + + virtual ~BusNetwork (); + + Ptr GetNode (uint32_t n); + +private: + std::vector > m_nodes; + Ptr m_channel; +}; + +}; // namespace ns3 + +#endif /* BUS_NETWORK_H */ diff --git a/tutorial/tutorial-bus-network.cc b/tutorial/tutorial-bus-network.cc new file mode 100644 index 000000000..0bb3ef9d3 --- /dev/null +++ b/tutorial/tutorial-bus-network.cc @@ -0,0 +1,63 @@ + +/* + * 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 + */ + +#include "ns3/log.h" +#include "ns3/ipv4-address.h" +#include "ns3/udp-echo-client.h" +#include "ns3/udp-echo-server.h" +#include "ns3/simulator.h" +#include "ns3/nstime.h" +#include "ns3/ascii-trace.h" + +#include "bus-network.h" + +NS_LOG_COMPONENT_DEFINE ("BusNetworkSimulation"); + +using namespace ns3; + +int +main (int argc, char *argv[]) +{ + LogComponentEnable ("BusNetworkSimulation", LOG_LEVEL_ALL); + LogComponentEnable ("BusNetwork", LOG_LEVEL_ALL); + + NS_LOG_INFO ("Bus Network Simulation"); + + BusNetwork busNetwork (Ipv4Mask ("255.255.0.0"), Ipv4Address ("10.1.0.0"), + Ipv4Address ("0.0.0.0"), DataRate(10000000), MilliSeconds(20), 10); + + uint32_t port = 7; + + Ptr n0 = busNetwork.GetNode (0); + Ptr client = Create (n0, "10.1.0.1", port, + 1, Seconds(1.), 1024); + + Ptr n1 = busNetwork.GetNode (1); + Ptr server = Create (n1, port); + + server->Start(Seconds(1.)); + client->Start(Seconds(2.)); + + server->Stop (Seconds(10.)); + client->Stop (Seconds(10.)); + + AsciiTrace asciitrace ("tutorial.tr"); + asciitrace.TraceAllQueues (); + asciitrace.TraceAllNetDeviceRx (); + + Simulator::Run (); + Simulator::Destroy (); +} diff --git a/tutorial/wscript b/tutorial/wscript index 7e51208e3..b51f21c46 100644 --- a/tutorial/wscript +++ b/tutorial/wscript @@ -36,3 +36,9 @@ def build(bld): obj = bld.create_ns3_program('testipv4', ['core']) obj.source = ['testipv4.cc', 'ipv4-address-generator.cc'] + + obj = bld.create_ns3_program('tutorial-bus-network', + ['core']) + obj.source = ['tutorial-bus-network.cc', + 'bus-network.cc', + 'ipv4-address-generator.cc'] From a2388cc4b49235c5ec842bcb2f013409b632d0fe Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Wed, 10 Oct 2007 11:55:07 -0700 Subject: [PATCH 12/67] improve obj design example --- .../{bus-network.cc => ipv4-bus-network.cc} | 32 +++++++++++++------ .../{bus-network.h => ipv4-bus-network.h} | 27 +++++++++++----- tutorial/tutorial-bus-network.cc | 11 +++---- tutorial/wscript | 2 +- 4 files changed, 48 insertions(+), 24 deletions(-) rename tutorial/{bus-network.cc => ipv4-bus-network.cc} (76%) rename tutorial/{bus-network.h => ipv4-bus-network.h} (74%) diff --git a/tutorial/bus-network.cc b/tutorial/ipv4-bus-network.cc similarity index 76% rename from tutorial/bus-network.cc rename to tutorial/ipv4-bus-network.cc index 7f6051340..898816c1b 100644 --- a/tutorial/bus-network.cc +++ b/tutorial/ipv4-bus-network.cc @@ -21,21 +21,36 @@ #include "ns3/csma-topology.h" #include "ns3/csma-ipv4-topology.h" -#include "bus-network.h" +#include "ipv4-bus-network.h" #include "ipv4-address-generator.h" namespace ns3 { -BusNetwork::BusNetwork ( - Ipv4Mask mask, +Ipv4Network::Ipv4Network ( Ipv4Address network, - Ipv4Address startAddress, + Ipv4Mask mask, + Ipv4Address address) +: + m_network (network), m_mask (mask), m_baseAddress (address) +{ +} + +Ipv4Network::~Ipv4Network () +{ +} + +Ipv4BusNetwork::Ipv4BusNetwork ( + Ipv4Address network, + Ipv4Mask mask, + Ipv4Address baseAddress, DataRate bps, Time delay, - uint32_t n) + uint32_t n) +: + Ipv4Network (network, mask, baseAddress) { Ipv4AddressGenerator::SeedNetwork (mask, network); - Ipv4AddressGenerator::SeedAddress (mask, startAddress); + Ipv4AddressGenerator::SeedAddress (mask, baseAddress); m_channel = CsmaTopology::CreateCsmaChannel (bps, delay); @@ -51,13 +66,12 @@ BusNetwork::BusNetwork ( } } -BusNetwork::~BusNetwork () +Ipv4BusNetwork::~Ipv4BusNetwork () { - m_nodes.erase (m_nodes.begin (), m_nodes.end ()); } Ptr -BusNetwork::GetNode (uint32_t n) +Ipv4BusNetwork::GetNode (uint32_t n) { return m_nodes[n]; } diff --git a/tutorial/bus-network.h b/tutorial/ipv4-bus-network.h similarity index 74% rename from tutorial/bus-network.h rename to tutorial/ipv4-bus-network.h index b69b6a6d5..de90f7bf7 100644 --- a/tutorial/bus-network.h +++ b/tutorial/ipv4-bus-network.h @@ -16,8 +16,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef BUS_NETWORK_H -#define BUS_NETWORK_H +#ifndef IPV4_BUS_NETWORK_H +#define IPV4_BUS_NETWORK_H #include #include "ns3/ptr.h" @@ -28,18 +28,29 @@ namespace ns3 { -class BusNetwork +class Ipv4Network { public: - BusNetwork ( - Ipv4Mask mask, + Ipv4Network (Ipv4Address network, Ipv4Mask mask, Ipv4Address address); + virtual ~Ipv4Network (); + + Ipv4Address m_network; + Ipv4Mask m_mask; + Ipv4Address m_baseAddress; +}; + +class Ipv4BusNetwork : public Ipv4Network +{ +public: + Ipv4BusNetwork ( Ipv4Address network, - Ipv4Address startAddress, + Ipv4Mask mask, + Ipv4Address baseAddress, DataRate bps, Time delay, uint32_t n); - virtual ~BusNetwork (); + virtual ~Ipv4BusNetwork (); Ptr GetNode (uint32_t n); @@ -50,4 +61,4 @@ private: }; // namespace ns3 -#endif /* BUS_NETWORK_H */ +#endif /* IPV4_BUS_NETWORK_H */ diff --git a/tutorial/tutorial-bus-network.cc b/tutorial/tutorial-bus-network.cc index 0bb3ef9d3..3b5907892 100644 --- a/tutorial/tutorial-bus-network.cc +++ b/tutorial/tutorial-bus-network.cc @@ -22,7 +22,7 @@ #include "ns3/nstime.h" #include "ns3/ascii-trace.h" -#include "bus-network.h" +#include "ipv4-bus-network.h" NS_LOG_COMPONENT_DEFINE ("BusNetworkSimulation"); @@ -32,20 +32,19 @@ int main (int argc, char *argv[]) { LogComponentEnable ("BusNetworkSimulation", LOG_LEVEL_ALL); - LogComponentEnable ("BusNetwork", LOG_LEVEL_ALL); NS_LOG_INFO ("Bus Network Simulation"); - BusNetwork busNetwork (Ipv4Mask ("255.255.0.0"), Ipv4Address ("10.1.0.0"), - Ipv4Address ("0.0.0.0"), DataRate(10000000), MilliSeconds(20), 10); + Ipv4BusNetwork bus ("10.1.0.0", "255.255.0.0", "0.0.0.0", + DataRate(10000000), MilliSeconds(20), 10); uint32_t port = 7; - Ptr n0 = busNetwork.GetNode (0); + Ptr n0 = bus.GetNode (0); Ptr client = Create (n0, "10.1.0.1", port, 1, Seconds(1.), 1024); - Ptr n1 = busNetwork.GetNode (1); + Ptr n1 = bus.GetNode (1); Ptr server = Create (n1, port); server->Start(Seconds(1.)); diff --git a/tutorial/wscript b/tutorial/wscript index b51f21c46..6b8ba9d31 100644 --- a/tutorial/wscript +++ b/tutorial/wscript @@ -40,5 +40,5 @@ def build(bld): obj = bld.create_ns3_program('tutorial-bus-network', ['core']) obj.source = ['tutorial-bus-network.cc', - 'bus-network.cc', + 'ipv4-bus-network.cc', 'ipv4-address-generator.cc'] From 6ad1a5b57fb15a9108f5a7a00257d2db0904eab1 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Wed, 10 Oct 2007 12:25:52 -0700 Subject: [PATCH 13/67] don't use any for starting address --- tutorial/tutorial-bus-network.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorial/tutorial-bus-network.cc b/tutorial/tutorial-bus-network.cc index 3b5907892..7013eadbe 100644 --- a/tutorial/tutorial-bus-network.cc +++ b/tutorial/tutorial-bus-network.cc @@ -35,7 +35,7 @@ main (int argc, char *argv[]) NS_LOG_INFO ("Bus Network Simulation"); - Ipv4BusNetwork bus ("10.1.0.0", "255.255.0.0", "0.0.0.0", + Ipv4BusNetwork bus ("10.1.0.0", "255.255.0.0", "0.0.0.3", DataRate(10000000), MilliSeconds(20), 10); uint32_t port = 7; From d17845d767006880c56f1f0ea73f1eef948bd768 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Tue, 30 Oct 2007 15:55:50 +0000 Subject: [PATCH 14/67] Remove empty OlsrTest unit test class. --- src/routing/olsr/olsr-agent-impl.cc | 37 ----------------------------- src/routing/olsr/olsr-agent-impl.h | 2 -- 2 files changed, 39 deletions(-) diff --git a/src/routing/olsr/olsr-agent-impl.cc b/src/routing/olsr/olsr-agent-impl.cc index b2acdad7d..48c30d029 100644 --- a/src/routing/olsr/olsr-agent-impl.cc +++ b/src/routing/olsr/olsr-agent-impl.cc @@ -2112,40 +2112,3 @@ AgentImpl::IfaceAssocTupleTimerExpire (IfaceAssocTuple tuple) }} // namespace olsr, ns3 - -#ifdef RUN_SELF_TESTS - - -#include "ns3/test.h" - -namespace ns3 { - -class OlsrTest : public ns3::Test { -private: -public: - OlsrTest (); - virtual bool RunTests (void); - - -}; - -OlsrTest::OlsrTest () - : ns3::Test ("Olsr") -{} - - -bool -OlsrTest::RunTests (void) -{ - bool result = true; - - - return result; -} - -static OlsrTest gOlsrTest; - -} - - -#endif /* RUN_SELF_TESTS */ diff --git a/src/routing/olsr/olsr-agent-impl.h b/src/routing/olsr/olsr-agent-impl.h index 1b561c821..5c21264af 100644 --- a/src/routing/olsr/olsr-agent-impl.h +++ b/src/routing/olsr/olsr-agent-impl.h @@ -48,8 +48,6 @@ namespace olsr { class AgentImpl : public Agent { - friend class OlsrTest; - public: AgentImpl (Ptr node); From 5a0fa236cbf4077e38b46b245e19dddedc579c94 Mon Sep 17 00:00:00 2001 From: Raj Bhattacharjea Date: Tue, 30 Oct 2007 13:27:33 -0400 Subject: [PATCH 15/67] Fixed randomvariable bugs and modified unit tests so that there is no non-deterministic failure on the tests --- src/core/random-variable.cc | 143 ++++++++++++++++++++++++++++++++++-- src/core/random-variable.h | 8 +- utils/run-tests.cc | 2 + 3 files changed, 142 insertions(+), 11 deletions(-) diff --git a/src/core/random-variable.cc b/src/core/random-variable.cc index fa44440d0..c44d9ead2 100644 --- a/src/core/random-variable.cc +++ b/src/core/random-variable.cc @@ -42,7 +42,6 @@ namespace ns3{ //----------------------------------------------------------------------------- // RandomVariable methods -uint32_t RandomVariable::runNumber = 0; bool RandomVariable::initialized = false; // True if RngStream seed set bool RandomVariable::useDevRandom = false; // True if use /dev/random bool RandomVariable::globalSeedSet = false; // True if GlobalSeed called @@ -50,6 +49,7 @@ int RandomVariable::devRandom = -1; uint32_t RandomVariable::globalSeed[6]; unsigned long RandomVariable::heuristic_sequence; RngStream* RandomVariable::m_static_generator = 0; +uint32_t RandomVariable::runNumber = 0; //the static object random_variable_initializer initializes the static members //of RandomVariable @@ -58,9 +58,9 @@ static class RandomVariableInitializer public: RandomVariableInitializer() { - RandomVariable::Initialize(); // sets the static package seed - RandomVariable::m_static_generator = new RngStream(); - RandomVariable::m_static_generator->InitializeStream(); +// RandomVariable::Initialize(); // sets the static package seed +// RandomVariable::m_static_generator = new RngStream(); +// RandomVariable::m_static_generator->InitializeStream(); } ~RandomVariableInitializer() { @@ -69,10 +69,11 @@ static class RandomVariableInitializer } random_variable_initializer; RandomVariable::RandomVariable() + : m_generator(NULL) { - m_generator = new RngStream(); - m_generator->InitializeStream(); - m_generator->ResetNthSubstream(RandomVariable::runNumber); +// m_generator = new RngStream(); +// m_generator->InitializeStream(); +// m_generator->ResetNthSubstream(RandomVariable::runNumber); } RandomVariable::RandomVariable(const RandomVariable& r) @@ -97,6 +98,12 @@ void RandomVariable::UseDevRandom(bool udr) void RandomVariable::GetSeed(uint32_t seed[6]) { + if(!m_generator) + { + m_generator = new RngStream(); + m_generator->InitializeStream(); + m_generator->ResetNthSubstream(RandomVariable::runNumber); + } m_generator->GetState(seed); } @@ -202,6 +209,16 @@ UniformVariable::UniformVariable(const UniformVariable& c) double UniformVariable::GetValue() { + if(!RandomVariable::initialized) + { + RandomVariable::Initialize(); + } + if(!m_generator) + { + m_generator = new RngStream(); + m_generator->InitializeStream(); + m_generator->ResetNthSubstream(RandomVariable::runNumber); + } return m_min + m_generator->RandU01() * (m_max - m_min); } @@ -212,6 +229,12 @@ RandomVariable* UniformVariable::Copy() const double UniformVariable::GetSingleValue(double s, double l) { + if(!RandomVariable::m_static_generator) + { + RandomVariable::Initialize(); // sets the static package seed + RandomVariable::m_static_generator = new RngStream(); + RandomVariable::m_static_generator->InitializeStream(); + } return s + m_static_generator->RandU01() * (l - s);; } @@ -305,6 +328,16 @@ ExponentialVariable::ExponentialVariable(const ExponentialVariable& c) double ExponentialVariable::GetValue() { + if(!RandomVariable::initialized) + { + RandomVariable::Initialize(); + } + if(!m_generator) + { + m_generator = new RngStream(); + m_generator->InitializeStream(); + m_generator->ResetNthSubstream(RandomVariable::runNumber); + } double r = -m_mean*log(m_generator->RandU01()); if (m_bound != 0 && r > m_bound) return m_bound; return r; @@ -316,6 +349,12 @@ RandomVariable* ExponentialVariable::Copy() const } double ExponentialVariable::GetSingleValue(double m, double b/*=0*/) { + if(!RandomVariable::m_static_generator) + { + RandomVariable::Initialize(); // sets the static package seed + RandomVariable::m_static_generator = new RngStream(); + RandomVariable::m_static_generator->InitializeStream(); + } double r = -m*log(m_static_generator->RandU01()); if (b != 0 && r > b) return b; return r; @@ -341,6 +380,16 @@ ParetoVariable::ParetoVariable(const ParetoVariable& c) double ParetoVariable::GetValue() { + if(!RandomVariable::initialized) + { + RandomVariable::Initialize(); + } + if(!m_generator) + { + m_generator = new RngStream(); + m_generator->InitializeStream(); + m_generator->ResetNthSubstream(RandomVariable::runNumber); + } double scale = m_mean * ( m_shape - 1.0) / m_shape; double r = (scale * ( 1.0 / pow(m_generator->RandU01(), 1.0 / m_shape))); if (m_bound != 0 && r > m_bound) return m_bound; @@ -354,6 +403,12 @@ RandomVariable* ParetoVariable::Copy() const double ParetoVariable::GetSingleValue(double m, double s, double b/*=0*/) { + if(!RandomVariable::m_static_generator) + { + RandomVariable::Initialize(); // sets the static package seed + RandomVariable::m_static_generator = new RngStream(); + RandomVariable::m_static_generator->InitializeStream(); + } double scale = m * ( s - 1.0) / s; double r = (scale * ( 1.0 / pow(m_static_generator->RandU01(), 1.0 / s))); if (b != 0 && r > b) return b; @@ -375,6 +430,16 @@ WeibullVariable::WeibullVariable(const WeibullVariable& c) double WeibullVariable::GetValue() { + if(!RandomVariable::initialized) + { + RandomVariable::Initialize(); + } + if(!m_generator) + { + m_generator = new RngStream(); + m_generator->InitializeStream(); + m_generator->ResetNthSubstream(RandomVariable::runNumber); + } double exponent = 1.0 / m_alpha; double r = m_mean * pow( -log(m_generator->RandU01()), exponent); if (m_bound != 0 && r > m_bound) return m_bound; @@ -388,6 +453,12 @@ RandomVariable* WeibullVariable::Copy() const double WeibullVariable::GetSingleValue(double m, double s, double b/*=0*/) { + if(!RandomVariable::m_static_generator) + { + RandomVariable::Initialize(); // sets the static package seed + RandomVariable::m_static_generator = new RngStream(); + RandomVariable::m_static_generator->InitializeStream(); + } double exponent = 1.0 / s; double r = m * pow( -log(m_static_generator->RandU01()), exponent); if (b != 0 && r > b) return b; @@ -412,6 +483,16 @@ NormalVariable::NormalVariable(const NormalVariable& c) double NormalVariable::GetValue() { + if(!RandomVariable::initialized) + { + RandomVariable::Initialize(); + } + if(!m_generator) + { + m_generator = new RngStream(); + m_generator->InitializeStream(); + m_generator->ResetNthSubstream(RandomVariable::runNumber); + } if (m_nextValid) { // use previously generated m_nextValid = false; @@ -445,6 +526,12 @@ RandomVariable* NormalVariable::Copy() const double NormalVariable::GetSingleValue(double m, double v, double b) { + if(!RandomVariable::m_static_generator) + { + RandomVariable::Initialize(); // sets the static package seed + RandomVariable::m_static_generator = new RngStream(); + RandomVariable::m_static_generator->InitializeStream(); + } if (m_static_nextValid) { // use previously generated m_static_nextValid = false; @@ -495,6 +582,16 @@ EmpiricalVariable::~EmpiricalVariable() { } double EmpiricalVariable::GetValue() { // Return a value from the empirical distribution // This code based (loosely) on code by Bruce Mah (Thanks Bruce!) + if(!RandomVariable::initialized) + { + RandomVariable::Initialize(); + } + if(!m_generator) + { + m_generator = new RngStream(); + m_generator->InitializeStream(); + m_generator->ResetNthSubstream(RandomVariable::runNumber); + } if (emp.size() == 0) return 0.0; // HuH? No empirical data if (!validated) Validate(); // Insure in non-decreasing double r = m_generator->RandU01(); @@ -642,6 +739,16 @@ LogNormalVariable::LogNormalVariable (double mu, double sigma) double LogNormalVariable::GetValue () { + if(!RandomVariable::initialized) + { + RandomVariable::Initialize(); + } + if(!m_generator) + { + m_generator = new RngStream(); + m_generator->InitializeStream(); + m_generator->ResetNthSubstream(RandomVariable::runNumber); + } double u, v, r2, normal, z; do @@ -665,6 +772,12 @@ LogNormalVariable::GetValue () double LogNormalVariable::GetSingleValue (double mu, double sigma) { + if(!RandomVariable::m_static_generator) + { + RandomVariable::Initialize(); // sets the static package seed + RandomVariable::m_static_generator = new RngStream(); + RandomVariable::m_static_generator->InitializeStream(); + } double u, v, r2, normal, z; do { @@ -698,6 +811,16 @@ TriangularVariable::TriangularVariable(const TriangularVariable& c) double TriangularVariable::GetValue() { + if(!RandomVariable::initialized) + { + RandomVariable::Initialize(); + } + if(!m_generator) + { + m_generator = new RngStream(); + m_generator->InitializeStream(); + m_generator->ResetNthSubstream(RandomVariable::runNumber); + } double u = m_generator->RandU01(); if(u <= (m_mode - m_min) / (m_max - m_min) ) return m_min + sqrt(u * (m_max - m_min) * (m_mode - m_min) ); @@ -712,6 +835,12 @@ RandomVariable* TriangularVariable::Copy() const double TriangularVariable::GetSingleValue(double s, double l, double mean) { + if(!RandomVariable::m_static_generator) + { + RandomVariable::Initialize(); // sets the static package seed + RandomVariable::m_static_generator = new RngStream(); + RandomVariable::m_static_generator->InitializeStream(); + } double mode = 3.0*mean-s-l; double u = m_static_generator->RandU01(); if(u <= (mode - s) / (l - s) ) diff --git a/src/core/random-variable.h b/src/core/random-variable.h index ce4cebd4d..ccc5caa34 100644 --- a/src/core/random-variable.h +++ b/src/core/random-variable.h @@ -71,7 +71,7 @@ public: * \brief Returns a random double from the underlying distribution * \return A floating point random value */ - virtual double GetValue() = 0; + virtual double GetValue() = 0; /** * \brief Returns a random integer integer from the underlying distribution @@ -173,19 +173,19 @@ public: */ static void SetRunNumber(uint32_t n); private: - static void Initialize(); // Initialize the RNG system static void GetRandomSeeds(uint32_t seeds[6]); private: - static bool initialized; // True if package seed is set static bool useDevRandom; // True if using /dev/random desired static bool globalSeedSet; // True if global seed has been specified static int devRandom; // File handle for /dev/random static uint32_t globalSeed[6]; // The global seed to use - static uint32_t runNumber; friend class RandomVariableInitializer; protected: static unsigned long heuristic_sequence; static RngStream* m_static_generator; + static uint32_t runNumber; + static void Initialize(); // Initialize the RNG system + static bool initialized; // True if package seed is set RngStream* m_generator; //underlying generator being wrapped }; diff --git a/utils/run-tests.cc b/utils/run-tests.cc index f99f560c3..ce3b38c00 100644 --- a/utils/run-tests.cc +++ b/utils/run-tests.cc @@ -21,11 +21,13 @@ #include "ns3/test.h" #include "ns3/packet-metadata.h" +#include "ns3/random-variable.h" int main (int argc, char *argv[]) { #ifdef RUN_SELF_TESTS + ns3::RandomVariable::UseGlobalSeed(1,2,3,4,5,6); ns3::PacketMetadata::Enable (); ns3::TestManager::EnableVerbose (); bool success = ns3::TestManager::RunTests (); From 534b6552911ae5345bd4f5ae845bea48c8897214 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 31 Oct 2007 11:28:40 +0100 Subject: [PATCH 16/67] fix typo --- doc/tracing.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/tracing.h b/doc/tracing.h index 45e7d9db5..e7993a842 100644 --- a/doc/tracing.h +++ b/doc/tracing.h @@ -531,14 +531,14 @@ * } * void * MyModelTraceType::Print (std::ostream &os) const - * ( + * { * // this method is invoked by the print function of a TraceContext * // if it contains an instance of this TraceContextElement. * switch (m_type) { * case RX: os << "rx"; break; * // ... * } - * ) + * } * std::string * MyModelTraceType::GetTypeName (void) const * { From 936c25c98b30e12f2699fa6f6e6c886fa926de00 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 31 Oct 2007 11:35:06 +0100 Subject: [PATCH 17/67] add missing type specifier in sample code --- doc/tracing.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/tracing.h b/doc/tracing.h index e7993a842..9a058ad72 100644 --- a/doc/tracing.h +++ b/doc/tracing.h @@ -516,7 +516,7 @@ * MyModelTraceType::MyModelTraceType (enum Type type) * : m_type (type) * {} - * enum Type + * enum MyModelTraceType::Type * MyModelTraceType::Get (void) const * { * return m_type; From 7af70745f30c979243c5038d79aac8f4bd6aa20e Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 31 Oct 2007 11:39:26 +0100 Subject: [PATCH 18/67] add missing default constructor --- doc/tracing.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/tracing.h b/doc/tracing.h index 9a058ad72..27657bd02 100644 --- a/doc/tracing.h +++ b/doc/tracing.h @@ -497,6 +497,8 @@ * }; * // called from MyModel::GetTraceResolver * MyModelTraceType (enum Type type); + * // needed for by the tracing subsystem. + * MyModelTraceType (); * // called from trace sink * enum Type Get (void) const; * // needed by the tracing subsystem @@ -513,6 +515,10 @@ * \endcode * The implementation does not require much thinking: * \code + * MyModelTraceType::MyModelTraceType () + * : m_type (RX) + * {// an arbitrary default value. + * } * MyModelTraceType::MyModelTraceType (enum Type type) * : m_type (type) * {} From b471e74ef8befe5230a8cf577d1f6e6f487d41f4 Mon Sep 17 00:00:00 2001 From: Raj Bhattacharjea Date: Thu, 1 Nov 2007 14:59:00 -0400 Subject: [PATCH 19/67] Fixed randomvariable memory bug that caused a segfault --- src/core/random-variable.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/random-variable.cc b/src/core/random-variable.cc index c44d9ead2..2190b90e1 100644 --- a/src/core/random-variable.cc +++ b/src/core/random-variable.cc @@ -77,8 +77,12 @@ RandomVariable::RandomVariable() } RandomVariable::RandomVariable(const RandomVariable& r) + :m_generator(0) { - m_generator = new RngStream(*r.m_generator); + if(r.m_generator) + { + m_generator = new RngStream(*r.m_generator); + } } RandomVariable::~RandomVariable() From 0d70b12c75c871049f09c20b3d5540886606deec Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Fri, 2 Nov 2007 08:28:45 -0700 Subject: [PATCH 20/67] update doxygen.conf to 1.5.4 --- doc/doxygen.conf | 213 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 150 insertions(+), 63 deletions(-) diff --git a/doc/doxygen.conf b/doc/doxygen.conf index f6025d2bc..135a890b1 100644 --- a/doc/doxygen.conf +++ b/doc/doxygen.conf @@ -1,4 +1,4 @@ -# Doxyfile 1.4.4 +# Doxyfile 1.5.4 # This file describes the settings to be used by the documentation system # doxygen (www.doxygen.org) for a project @@ -14,10 +14,18 @@ # Project related configuration options #--------------------------------------------------------------------------- +# This tag specifies the encoding used for all characters in the config file that +# follow. The default is UTF-8 which is also the encoding used for all text before +# the first occurrence of this tag. Doxygen uses libiconv (or the iconv built into +# libc) for the transcoding. See http://www.gnu.org/software/libiconv for the list of +# possible encodings. + +DOXYFILE_ENCODING = UTF-8 + # The PROJECT_NAME tag is a single word (or a sequence of words surrounded # by quotes) that should identify the project. -PROJECT_NAME = "NS-3" +PROJECT_NAME = "NS-3 " # The PROJECT_NUMBER tag can be used to enter a project or revision number. # This could be handy for archiving the generated documentation or @@ -45,24 +53,14 @@ CREATE_SUBDIRS = NO # documentation generated by doxygen is written. Doxygen will use this # information to generate all constant output in the proper language. # The default language is English, other supported languages are: -# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, -# Dutch, Finnish, French, German, Greek, Hungarian, Italian, Japanese, -# Japanese-en (Japanese with English messages), Korean, Korean-en, Norwegian, -# Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, -# Swedish, and Ukrainian. +# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, +# Croatian, Czech, Danish, Dutch, Finnish, French, German, Greek, Hungarian, +# Italian, Japanese, Japanese-en (Japanese with English messages), Korean, +# Korean-en, Lithuanian, Norwegian, Polish, Portuguese, Romanian, Russian, +# Serbian, Slovak, Slovene, Spanish, Swedish, and Ukrainian. OUTPUT_LANGUAGE = English -# This tag can be used to specify the encoding used in the generated output. -# The encoding is not always determined by the language that is chosen, -# but also whether or not the output is meant for Windows or non-Windows users. -# In case there is a difference, setting the USE_WINDOWS_ENCODING tag to YES -# forces the Windows encoding (this is the default for the Windows binary), -# whereas setting the tag to NO uses a Unix-style encoding (the default for -# all platforms other than Windows). - -USE_WINDOWS_ENCODING = NO - # If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will # include brief member descriptions after the members that are listed in # the file and class documentation (similar to JavaDoc). @@ -135,11 +133,19 @@ SHORT_NAMES = NO # If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen # will interpret the first line (until the first dot) of a JavaDoc-style # comment as the brief description. If set to NO, the JavaDoc -# comments will behave just like the Qt-style comments (thus requiring an -# explicit @brief command for a brief description. +# comments will behave just like regular Qt-style comments +# (thus requiring an explicit @brief command for a brief description.) JAVADOC_AUTOBRIEF = NO +# If the QT_AUTOBRIEF tag is set to YES then Doxygen will +# interpret the first line (until the first dot) of a Qt-style +# comment as the brief description. If set to NO, the comments +# will behave just like regular Qt-style comments (thus requiring +# an explicit \brief command for a brief description.) + +QT_AUTOBRIEF = NO + # The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen # treat a multi-line C++ special comment block (i.e. a block of //! or /// # comments) as a brief description. This used to be the default behaviour. @@ -161,13 +167,6 @@ DETAILS_AT_TOP = NO INHERIT_DOCS = YES -# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC -# tag is set to YES, then doxygen will reuse the documentation of the first -# member in the group (if any) for the other members of the group. By default -# all members of a group must be documented explicitly. - -DISTRIBUTE_GROUP_DOC = NO - # If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce # a new page for each member. If set to NO, the documentation of a member will # be part of the file/class/namespace that contains it. @@ -195,13 +194,40 @@ ALIASES = OPTIMIZE_OUTPUT_FOR_C = NO -# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java sources -# only. Doxygen will then generate output that is more tailored for Java. +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java +# sources only. Doxygen will then generate output that is more tailored for Java. # For instance, namespaces will be presented as packages, qualified scopes # will look different, etc. OPTIMIZE_OUTPUT_JAVA = NO +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want to +# include (a tag file for) the STL sources as input, then you should +# set this tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. +# func(std::string) {}). This also make the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. + +BUILTIN_STL_SUPPORT = NO + +# If you use Microsoft's C++/CLI language, you should set this option to YES to +# enable parsing support. + +CPP_CLI_SUPPORT = NO + +# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only. +# Doxygen will parse them like normal C++ but will assume all classes use public +# instead of private inheritance when no explicit protection keyword is present. + +SIP_SUPPORT = NO + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. + +DISTRIBUTE_GROUP_DOC = NO + # Set the SUBGROUPING tag to YES (the default) to allow class member groups of # the same type (for instance a group of public functions) to be put as a # subgroup of that type (e.g. under the Public Functions section). Set it to @@ -210,6 +236,16 @@ OPTIMIZE_OUTPUT_JAVA = NO SUBGROUPING = YES +# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct (or union) is +# documented as struct with the name of the typedef. So +# typedef struct TypeS {} TypeT, will appear in the documentation as a struct +# with name TypeT. When disabled the typedef will appear as a member of a file, +# namespace, or class. And the struct will be named TypeS. This can typically +# be useful for C code where the coding convention is that all structs are +# typedef'ed and only the typedef is referenced never the struct's name. + +TYPEDEF_HIDES_STRUCT = NO + #--------------------------------------------------------------------------- # Build related configuration options #--------------------------------------------------------------------------- @@ -244,6 +280,13 @@ EXTRACT_LOCAL_CLASSES = NO EXTRACT_LOCAL_METHODS = NO +# If this flag is set to YES, the members of anonymous namespaces will be extracted +# and appear in the documentation as a namespace called 'anonymous_namespace{file}', +# where file will be replaced with the base name of the file that contains the anonymous +# namespace. By default anonymous namespace are hidden. + +EXTRACT_ANON_NSPACES = NO + # If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all # undocumented members of documented classes, files or namespaces. # If set to NO (the default) these members will be included in the @@ -376,7 +419,7 @@ SHOW_USED_FILES = YES # If the sources in your project are distributed over multiple directories # then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy -# in the documentation. The default is YES. +# in the documentation. The default is NO. SHOW_DIRECTORIES = NO @@ -385,7 +428,7 @@ SHOW_DIRECTORIES = NO # version control system). Doxygen will invoke the program by executing (via # popen()) the command , where is the value of # the FILE_VERSION_FILTER tag, and is the name of an input file -# provided by doxygen. Whatever the progam writes to standard output +# provided by doxygen. Whatever the program writes to standard output # is used as the file version. See the manual for examples. FILE_VERSION_FILTER = @@ -433,7 +476,7 @@ WARN_NO_PARAMDOC = NO # $version, which will be replaced by the version of the file (if it could # be obtained via FILE_VERSION_FILTER) -WARN_FORMAT = "$file:$line: $text" +WARN_FORMAT = "$file:$line: $text " # The WARN_LOGFILE tag can be used to specify a file to which warning # and error messages should be written. If left blank the output is written @@ -450,16 +493,27 @@ WARN_LOGFILE = # directories like "/usr/src/myproject". Separate the files or directories # with spaces. -INPUT = src doc/main.txt doc/trace-source-list.h doc/tracing.h +INPUT = src \ + doc/main.txt \ + doc/trace-source-list.h \ + doc/tracing.h + +# This tag can be used to specify the character encoding of the source files that +# doxygen parses. Internally doxygen uses the UTF-8 encoding, which is also the default +# input encoding. Doxygen uses libiconv (or the iconv built into libc) for the transcoding. +# See http://www.gnu.org/software/libiconv for the list of possible encodings. + +INPUT_ENCODING = UTF-8 # If the value of the INPUT tag contains directories, you can use the # FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp # and *.h) to filter out the source-files in the directories. If left # blank the following patterns are tested: # *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx -# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm +# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90 -FILE_PATTERNS = *.h *.tcc +FILE_PATTERNS = *.h \ + *.tcc # The RECURSIVE tag can be used to turn specify whether or not subdirectories # should be searched for input files as well. Possible values are YES and NO. @@ -471,13 +525,12 @@ RECURSIVE = YES # excluded from the INPUT source files. This way you can easily exclude a # subdirectory from a directory tree whose root is specified with the INPUT tag. -EXCLUDE = \ - src/routing/olsr/olsr-state.h \ - src/routing/olsr/repositories.h \ - src/routing/olsr/routing-table.h \ - src/simulator/high-precision.h \ - src/simulator/high-precision-128.h \ - src/simulator/high-precision-double.h +EXCLUDE = src/routing/olsr/olsr-state.h \ + src/routing/olsr/repositories.h \ + src/routing/olsr/routing-table.h \ + src/simulator/high-precision.h \ + src/simulator/high-precision-128.h \ + src/simulator/high-precision-double.h # The EXCLUDE_SYMLINKS tag can be used select whether or not files or # directories that are symbolic links (a Unix filesystem feature) are excluded @@ -493,6 +546,13 @@ EXCLUDE_SYMLINKS = NO EXCLUDE_PATTERNS = +# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names +# (namespaces, classes, functions, etc.) that should be excluded from the output. +# The symbol name can be a fully qualified name, a word, or if the wildcard * is used, +# a substring. Examples: ANamespace, AClass, AClass::ANamespace, ANamespace::*Test + +EXCLUDE_SYMBOLS = + # The EXAMPLE_PATH tag can be used to specify one or more files or # directories that contain example code fragments that are included (see # the \include command). @@ -551,7 +611,9 @@ FILTER_SOURCE_FILES = NO # If the SOURCE_BROWSER tag is set to YES then a list of source files will # be generated. Documented entities will be cross-referenced with these sources. # Note: To get rid of all source code in the generated output, make sure also -# VERBATIM_HEADERS is set to NO. +# VERBATIM_HEADERS is set to NO. If you have enabled CALL_GRAPH or CALLER_GRAPH +# then you must also enable this option. If you don't then doxygen will produce +# a warning and turn it on anyway SOURCE_BROWSER = NO @@ -578,6 +640,13 @@ REFERENCED_BY_RELATION = YES REFERENCES_RELATION = YES +# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) +# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from +# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will +# link to the source code. Otherwise they will link to the documentstion. + +REFERENCES_LINK_SOURCE = YES + # If the USE_HTAGS tag is set to YES then the references to source code # will point to the HTML generated by the htags(1) tool instead of doxygen # built-in source browser. The htags tool is part of GNU's global source @@ -670,6 +739,14 @@ HTML_ALIGN_MEMBERS = YES GENERATE_HTMLHELP = NO +# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +# documentation will contain sections that can be hidden and shown after the +# page has loaded. For this to work a browser that supports +# JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox +# Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari). + +HTML_DYNAMIC_SECTIONS = NO + # If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can # be used to specify the file name of the resulting .chm file. You # can add a path in front of the file if the result should not be @@ -972,7 +1049,7 @@ MACRO_EXPANSION = NO # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES # then the macro expansion is limited to the macros specified with the -# PREDEFINED and EXPAND_AS_PREDEFINED tags. +# PREDEFINED and EXPAND_AS_DEFINED tags. EXPAND_ONLY_PREDEF = NO @@ -1002,7 +1079,9 @@ INCLUDE_FILE_PATTERNS = # undefined via #undef or recursively expanded use the := operator # instead of the = operator. -PREDEFINED = RUN_SELF_TESTS NS3_ASSERT_ENABLE NS3_LOG_ENABLE +PREDEFINED = RUN_SELF_TESTS \ + NS3_ASSERT_ENABLE \ + NS3_LOG_ENABLE # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then # this tag can be used to specify a list of macro names that should be expanded. @@ -1075,6 +1154,14 @@ PERL_PATH = /usr/bin/perl CLASS_DIAGRAMS = YES +# You can define message sequence charts within doxygen comments using the \msc +# command. Doxygen will then run the mscgen tool (see http://www.mcternan.me.uk/mscgen/) to +# produce the chart and insert it in the documentation. The MSCGEN_PATH tag allows you to +# specify the directory where the mscgen tool resides. If left empty the tool is assumed to +# be found in the default search path. + +MSCGEN_PATH = + # If set to YES, the inheritance and collaboration graphs will hide # inheritance and usage relations if the target is undocumented # or is not a class. @@ -1132,7 +1219,7 @@ INCLUDE_GRAPH = YES INCLUDED_BY_GRAPH = YES -# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will +# If the CALL_GRAPH, SOURCE_BROWSER and HAVE_DOT tags are set to YES then doxygen will # generate a call dependency graph for every global function or class method. # Note that enabling this option will significantly increase the time of a run. # So in most cases it will be better to enable call graphs for selected @@ -1140,6 +1227,14 @@ INCLUDED_BY_GRAPH = YES CALL_GRAPH = NO +# If the CALLER_GRAPH, SOURCE_BROWSER and HAVE_DOT tags are set to YES then doxygen will +# generate a caller dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable caller graphs for selected +# functions only using the \callergraph command. + +CALLER_GRAPH = NO + # If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen # will graphical hierarchy of all classes instead of a textual one. @@ -1169,31 +1264,23 @@ DOT_PATH = DOTFILE_DIRS = -# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width -# (in pixels) of the graphs generated by dot. If a graph becomes larger than -# this value, doxygen will try to truncate the graph, so that it fits within -# the specified constraint. Beware that most browsers cannot cope with very -# large images. +# The MAX_DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of +# nodes that will be shown in the graph. If the number of nodes in a graph +# becomes larger than this value, doxygen will truncate the graph, which is +# visualized by representing a node as a red box. Note that doxygen if the number +# of direct children of the root node in a graph is already larger than +# MAX_DOT_GRAPH_NOTES then the graph will not be shown at all. Also note +# that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. -MAX_DOT_GRAPH_WIDTH = 1024 - -# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height -# (in pixels) of the graphs generated by dot. If a graph becomes larger than -# this value, doxygen will try to truncate the graph, so that it fits within -# the specified constraint. Beware that most browsers cannot cope with very -# large images. - -MAX_DOT_GRAPH_HEIGHT = 1024 +DOT_GRAPH_MAX_NODES = 50 # The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the # graphs generated by dot. A depth value of 3 means that only nodes reachable # from the root by following a path via at most 3 edges will be shown. Nodes # that lay further from the root node will be omitted. Note that setting this # option to 1 or 2 may greatly reduce the computation time needed for large -# code bases. Also note that a graph may be further truncated if the graph's -# image dimensions are not sufficient to fit the graph (see MAX_DOT_GRAPH_WIDTH -# and MAX_DOT_GRAPH_HEIGHT). If 0 is used for the depth value (the default), -# the graph is not depth-constrained. +# code bases. Also note that the size of a graph can be further restricted by +# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. MAX_DOT_GRAPH_DEPTH = 0 From bc759b5bb3d80a5da465e4b80fa759b60829de30 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Fri, 2 Nov 2007 08:41:50 -0700 Subject: [PATCH 21/67] Minor change to doxygen due to debug-to-log cutover --- doc/main.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/main.txt b/doc/main.txt index 1027eb97f..6da3b9e08 100644 --- a/doc/main.txt +++ b/doc/main.txt @@ -18,7 +18,7 @@ * - a Functor class: ns3::Callback * - an os-independent interface to get access to the elapsed wall clock time: ns3::SystemWallClockMs * - a class to register regression tests with the test manager: ns3::Test and ns3::TestManager - * - debugging facilities: \ref debugging, \ref assert, \ref error + * - debugging facilities: \ref logging, \ref assert, \ref error * - \ref randomvariable * - \ref config * - a base class for objects which need to support reference counting From c3cbbcacd7067256371aa0f4a29b4bbe749e1c3d Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Wed, 14 Nov 2007 20:40:05 -0800 Subject: [PATCH 22/67] Add src/common/error-model implementation and example script, and add to NetDevices --- examples/simple-error-model.cc | 240 ++++++++++++++ examples/wscript | 4 + src/common/error-model.cc | 300 ++++++++++++++++++ src/common/error-model.h | 236 ++++++++++++++ src/common/wscript | 2 + src/devices/csma/csma-net-device.cc | 65 ++-- src/devices/csma/csma-net-device.h | 17 + .../point-to-point-net-device.cc | 60 +++- .../point-to-point-net-device.h | 34 ++ 9 files changed, 930 insertions(+), 28 deletions(-) create mode 100644 examples/simple-error-model.cc create mode 100644 src/common/error-model.cc create mode 100644 src/common/error-model.h diff --git a/examples/simple-error-model.cc b/examples/simple-error-model.cc new file mode 100644 index 000000000..04b627e62 --- /dev/null +++ b/examples/simple-error-model.cc @@ -0,0 +1,240 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * 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 + * + * ns-2 simple.tcl script (ported from ns-2) + * Originally authored by Steve McCanne, 12/19/1996 + */ + +// Port of ns-2/tcl/ex/simple.tcl to ns-3 +// +// Network topology +// +// n0 +// \ 5 Mb/s, 2ms +// \ 1.5Mb/s, 10ms +// n2 -------------------------n3 +// / +// / 5 Mb/s, 2ms +// n1 +// +// - all links are point-to-point links with indicated one-way BW/delay +// - CBR/UDP flows from n0 to n3, and from n3 to n1 +// - FTP/TCP flow from n0 to n3, starting at time 1.2 to time 1.35 sec. +// - UDP packet size of 210 bytes, with per-packet interval 0.00375 sec. +// (i.e., DataRate of 448,000 bps) +// - DropTail queues +// - Tracing of queues and packet receptions to file +// "simple-error-model.tr" + +#include "ns3/log.h" +#include "ns3/assert.h" +#include "ns3/command-line.h" +#include "ns3/default-value.h" +#include "ns3/ptr.h" + +#include "ns3/simulator.h" +#include "ns3/nstime.h" +#include "ns3/data-rate.h" + +#include "ns3/ascii-trace.h" +#include "ns3/pcap-trace.h" +#include "ns3/internet-node.h" +#include "ns3/default-value.h" +#include "ns3/component-manager.h" +#include "ns3/random-variable.h" +#include "ns3/point-to-point-channel.h" +#include "ns3/point-to-point-net-device.h" +#include "ns3/ipv4-address.h" +#include "ns3/inet-socket-address.h" +#include "ns3/ipv4.h" +#include "ns3/socket.h" +#include "ns3/ipv4-route.h" +#include "ns3/point-to-point-topology.h" +#include "ns3/onoff-application.h" +#include "ns3/packet-sink.h" +#include "ns3/error-model.h" + +using namespace ns3; + +NS_LOG_COMPONENT_DEFINE ("SimpleErrorModelExample"); + +int +main (int argc, char *argv[]) +{ + // Users may find it convenient to turn on explicit debugging + // for selected modules; the below lines suggest how to do this +#if 0 + LogComponentEnable ("SimplePointToPointExample", LOG_LEVEL_INFO); +#endif + + // Set up some default values for the simulation. Use the Bind() + // technique to tell the system what subclass of ErrorModel to use + DefaultValue::Bind ("ErrorModel", "RateErrorModel"); + // Set a few parameters + DefaultValue::Bind ("RateErrorModelErrorRate", "0.01"); + DefaultValue::Bind ("RateErrorModelErrorUnit", "EU_PKT"); + + DefaultValue::Bind ("OnOffApplicationPacketSize", "210"); + DefaultValue::Bind ("OnOffApplicationDataRate", "448kb/s"); + + + // Allow the user to override any of the defaults and the above + // Bind()s at run-time, via command-line arguments + CommandLine::Parse (argc, argv); + + // Here, we will explicitly create four nodes. In more sophisticated + // topologies, we could configure a node factory. + NS_LOG_INFO ("Create nodes."); + Ptr n0 = Create (); + Ptr n1 = Create (); + Ptr n2 = Create (); + Ptr n3 = Create (); + + // We create the channels first without any IP addressing information + NS_LOG_INFO ("Create channels."); + Ptr channel0 = + PointToPointTopology::AddPointToPointLink ( + n0, n2, DataRate(5000000), MilliSeconds(2)); + + Ptr channel1 = + PointToPointTopology::AddPointToPointLink ( + n1, n2, DataRate(5000000), MilliSeconds(2)); + + Ptr channel2 = + PointToPointTopology::AddPointToPointLink ( + n2, n3, DataRate(1500000), MilliSeconds(10)); + + // Later, we add IP addresses. + NS_LOG_INFO ("Assign IP Addresses."); + PointToPointTopology::AddIpv4Addresses ( + channel0, n0, Ipv4Address("10.1.1.1"), + n2, Ipv4Address("10.1.1.2")); + + PointToPointTopology::AddIpv4Addresses ( + channel1, n1, Ipv4Address("10.1.2.1"), + n2, Ipv4Address("10.1.2.2")); + + PointToPointTopology::AddIpv4Addresses ( + channel2, n2, Ipv4Address("10.1.3.1"), + n3, Ipv4Address("10.1.3.2")); + + // Finally, we add static routes. These three steps (Channel and + // NetDevice creation, IP Address assignment, and routing) are + // separated because there may be a need to postpone IP Address + // assignment (emulation) or modify to use dynamic routing + NS_LOG_INFO ("Add Static Routes."); + PointToPointTopology::AddIpv4Routes(n0, n2, channel0); + PointToPointTopology::AddIpv4Routes(n1, n2, channel1); + PointToPointTopology::AddIpv4Routes(n2, n3, channel2); + + // Create the OnOff application to send UDP datagrams of size + // 210 bytes at a rate of 448 Kb/s + NS_LOG_INFO ("Create Applications."); + uint16_t port = 9; // Discard port (RFC 863) + Ptr ooff = Create ( + n0, + InetSocketAddress ("10.1.3.2", port), + "Udp", + ConstantVariable(1), + ConstantVariable(0)); + // Start the application + ooff->Start(Seconds(1.0)); + ooff->Stop (Seconds(10.0)); + + // Create an optional packet sink to receive these packets + Ptr sink = Create ( + n3, + InetSocketAddress (Ipv4Address::GetAny (), port), + "Udp"); + // Start the sink + sink->Start (Seconds (1.0)); + sink->Stop (Seconds (10.0)); + + // Create a similar flow from n3 to n1, starting at time 1.1 seconds + ooff = Create ( + n3, + InetSocketAddress ("10.1.2.1", port), + "Udp", + ConstantVariable(1), + ConstantVariable(0)); + // Start the application + ooff->Start(Seconds(1.1)); + ooff->Stop (Seconds(10.0)); + + // Create a packet sink to receive these packets + sink = Create ( + n1, + InetSocketAddress (Ipv4Address::GetAny (), port), + "Udp"); + // Start the sink + sink->Start (Seconds (1.1)); + sink->Stop (Seconds (10.0)); + + // Here, finish off packet routing configuration + // This will likely set by some global StaticRouting object in the future + NS_LOG_INFO ("Set Default Routes."); + Ptr ipv4; + ipv4 = n0->QueryInterface (Ipv4::iid); + ipv4->SetDefaultRoute (Ipv4Address ("10.1.1.2"), 1); + ipv4 = n3->QueryInterface (Ipv4::iid); + ipv4->SetDefaultRoute (Ipv4Address ("10.1.3.1"), 1); + + // + // Error model + // + // We want to add an error model to node 3's NetDevice + // We can obtain a handle to the NetDevice via the channel and node + // pointers + Ptr nd3 = PointToPointTopology::GetNetDevice + (n3, channel2); + // Create an ErrorModel based on the implementation (constructor) + // specified by the default classId + Ptr em = ErrorModel::CreateDefault (); + NS_ASSERT (em != 0); + // Now, query interface on the resulting em pointer to see if a + // RateErrorModel interface exists. If so, set the packet error rate + Ptr bem = em->QueryInterface + (RateErrorModel::iid); + if (bem) + { + bem->SetRandomVariable (UniformVariable ()); + bem->SetRate (0.001); + } + nd3->AddReceiveErrorModel (em); + + // Now, let's use the ListErrorModel and explicitly force a loss + // of the packets with pkt-uids = 11 and 17 on node 2, device 0 + Ptr nd2 = PointToPointTopology::GetNetDevice + (n2, channel0); + std::list sampleList; + sampleList.push_back (11); + sampleList.push_back (17); + // This time, we'll explicitly create the error model we want + Ptr pem = Create (); + pem->SetList (sampleList); + nd2->AddReceiveErrorModel (pem); + + // Configure tracing of all enqueue, dequeue, and NetDevice receive events + // Trace output will be sent to the simple-error-model.tr file + NS_LOG_INFO ("Configure Tracing."); + AsciiTrace asciitrace ("simple-error-model.tr"); + asciitrace.TraceAllQueues (); + asciitrace.TraceAllNetDeviceRx (); + + NS_LOG_INFO ("Run Simulation."); + Simulator::Run (); + Simulator::Destroy (); + NS_LOG_INFO ("Done."); +} diff --git a/examples/wscript b/examples/wscript index f597225fb..e458fa057 100644 --- a/examples/wscript +++ b/examples/wscript @@ -14,6 +14,10 @@ def build(bld): ['point-to-point', 'internet-node']) obj.source = 'simple-point-to-point.cc' + obj = bld.create_ns3_program('simple-error-model', + ['point-to-point', 'internet-node']) + obj.source = 'simple-error-model.cc' + obj = bld.create_ns3_program('csma-one-subnet', ['csma', 'internet-node']) obj.source = 'csma-one-subnet.cc' diff --git a/src/common/error-model.cc b/src/common/error-model.cc new file mode 100644 index 000000000..938cced29 --- /dev/null +++ b/src/common/error-model.cc @@ -0,0 +1,300 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 University of Washington + * + * 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: Tom Henderson + * This code has been ported from ns-2 (queue/errmodel.{cc,h} + */ + +#include + +#include "error-model.h" + +#include "ns3/packet.h" +#include "ns3/assert.h" +#include "ns3/log.h" +#include "ns3/random-variable.h" +#include "ns3/default-value.h" + +NS_LOG_COMPONENT_DEFINE ("ErrorModel"); + +namespace ns3 { + +static ClassIdDefaultValue g_classIdErrorModelDefaultValue ("ErrorModel", + "Error Model", ErrorModel::iid, "RateErrorModel"); + +const InterfaceId ErrorModel::iid = + MakeInterfaceId ("ErrorModel", Object::iid); + +ErrorModel::ErrorModel () : + m_enable (true) +{ + NS_LOG_FUNCTION; + SetInterfaceId (ErrorModel::iid); +} + +ErrorModel::~ErrorModel () +{ + NS_LOG_FUNCTION; +} + +Ptr +ErrorModel::CreateDefault (void) +{ + NS_LOG_FUNCTION; + ClassId classId = g_classIdErrorModelDefaultValue.GetValue (); + Ptr em = ComponentManager::Create (classId, + ErrorModel::iid); + return em; +} + +bool +ErrorModel::IsCorrupt (Packet& p) +{ + NS_LOG_FUNCTION; + bool result; + // Insert any pre-conditions here + result = DoCorrupt (p); + // Insert any post-conditions here + return result; +} + +void +ErrorModel::Reset (void) +{ + NS_LOG_FUNCTION; + DoReset (); +} + +void +ErrorModel::Enable (void) +{ + NS_LOG_FUNCTION; + m_enable = true; +} + +void +ErrorModel::Disable (void) +{ + NS_LOG_FUNCTION; + m_enable = false; +} + +bool +ErrorModel::IsEnabled (void) const +{ + NS_LOG_FUNCTION; + return m_enable; +} + +// +// RateErrorModel +// + +const InterfaceId RateErrorModel::iid = + MakeInterfaceId ("RateErrorModel", ErrorModel::iid); + +const ClassId RateErrorModel::cid = + MakeClassId ("RateErrorModel", ErrorModel::iid, + RateErrorModel::iid); + +// Defaults for rate/size +static NumericDefaultValue g_defaultRateErrorModelErrorRate + ("RateErrorModelErrorRate", "The error rate for the error model", 0.0); + +static EnumDefaultValue + g_defaultRateErrorModelErrorUnit ("RateErrorModelErrorUnit", + "The error unit for this error model", + EU_BYTE, "EU_BYTE", + EU_PKT, "EU_PKT", + EU_BIT, "EU_BIT", + 0, (void*)0); + +RateErrorModel::RateErrorModel () : + m_unit (g_defaultRateErrorModelErrorUnit.GetValue() ), + m_rate (g_defaultRateErrorModelErrorRate.GetValue() ) +{ + NS_LOG_FUNCTION; + // Assume a uniform random variable if user does not specify + m_ranvar = new UniformVariable (); + SetInterfaceId (RateErrorModel::iid); +} + +RateErrorModel::~RateErrorModel () +{ + NS_LOG_FUNCTION; + delete m_ranvar; +} + +enum ErrorUnit +RateErrorModel::GetUnit (void) const +{ + NS_LOG_FUNCTION; + return m_unit; +} + +void +RateErrorModel::SetUnit (enum ErrorUnit error_unit) +{ + NS_LOG_FUNCTION; + m_unit = error_unit; +} + +double +RateErrorModel::GetRate (void) const +{ + NS_LOG_FUNCTION; + return m_rate; +} + +void +RateErrorModel::SetRate (double rate) +{ + NS_LOG_FUNCTION; + m_rate = rate; +} + +void +RateErrorModel::SetRandomVariable (const RandomVariable &ranvar) +{ + NS_LOG_FUNCTION; + delete m_ranvar; + m_ranvar = ranvar.Copy (); +} + +bool +RateErrorModel::DoCorrupt (Packet& p) +{ + NS_LOG_FUNCTION; + if (!m_enable) + { + return false; + } + switch (m_unit) + { + case EU_PKT: + return DoCorruptPkt (p); + case EU_BYTE: + return DoCorruptByte (p); + case EU_BIT: + return DoCorruptBit (p); + default: + NS_ASSERT_MSG (false, "m_unit not supported yet"); + break; + } + return false; +} + +bool +RateErrorModel::DoCorruptPkt (Packet& p) +{ + NS_LOG_FUNCTION; + return (m_ranvar->GetValue () < m_rate); +} + +bool +RateErrorModel::DoCorruptByte (Packet& p) +{ + NS_LOG_FUNCTION; + // compute pkt error rate, assume uniformly distributed byte error + double per = 1 - pow (1.0 - m_rate, p.GetSize ()); + return (m_ranvar->GetValue () < per); +} + +bool +RateErrorModel::DoCorruptBit(Packet& p) +{ + NS_LOG_FUNCTION; + // compute pkt error rate, assume uniformly distributed bit error + double per = 1 - pow (1.0 - m_rate, (8 * p.GetSize ()) ); + return (m_ranvar->GetValue () < per); +} + +void +RateErrorModel::DoReset (void) +{ + NS_LOG_FUNCTION; + /* re-initialize any state; no-op for now */ +} + +// +// ListErrorModel +// + +const InterfaceId ListErrorModel::iid = + MakeInterfaceId ("ListErrorModel", ErrorModel::iid); + +const ClassId ListErrorModel::cid = + MakeClassId ("ListErrorModel", ErrorModel::iid, + ListErrorModel::iid); + +ListErrorModel::ListErrorModel () +{ + NS_LOG_FUNCTION; + SetInterfaceId (ListErrorModel::iid); +} + +ListErrorModel::~ListErrorModel () +{ + NS_LOG_FUNCTION; +} + +std::list +ListErrorModel::GetList (void) const +{ + NS_LOG_FUNCTION; + return m_packetList; +} + +void +ListErrorModel::SetList (const std::list &packetlist) +{ + NS_LOG_FUNCTION; + m_packetList = packetlist; +} + +// When performance becomes a concern, the list provided could be +// converted to a dynamically-sized array of uint32_t to avoid +// list iteration below. +bool +ListErrorModel::DoCorrupt (Packet& p) +{ + NS_LOG_FUNCTION; + if (!m_enable) + { + return false; + } + uint32_t uid = p.GetUid (); + for (PacketListCI i = m_packetList.begin (); + i != m_packetList.end (); i++) + { + if (uid == *i) + { + return true; + } + } + return false; +} + +void +ListErrorModel::DoReset (void) +{ + NS_LOG_FUNCTION; + m_packetList.clear(); +} + + +} //namespace ns3 diff --git a/src/common/error-model.h b/src/common/error-model.h new file mode 100644 index 000000000..e386d2f94 --- /dev/null +++ b/src/common/error-model.h @@ -0,0 +1,236 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 University of Washington + * + * 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: Tom Henderson + * This code has been ported from ns-2 (queue/errmodel.{cc,h} + */ +#ifndef ERROR_MODEL_H +#define ERROR_MODEL_H + +#include +#include "ns3/object.h" +#include "ns3/component-manager.h" + +namespace ns3 { + +class Packet; +class RandomVariable; + +/** + * \brief General error model that can be used to corrupt packets + * + * This object is used to flag packets as being lost/errored or not. + * It is part of the Object framework and can be aggregated to + * other ns3 objects and handled by the Ptr class. + * + * The main method is IsCorrupt(Packet& p) which returns true if + * the packet is to be corrupted according to the underlying model. + * Depending on the error model, the packet itself may have its packet + * data buffer errored or not, or side information may be returned to + * the client in the form of a packet tag. + * The object can have state (resettable by Reset()). + * The object can also be enabled and disabled via two public member functions. + * + * Typical code (simplified) to use an ErrorModel may look something like + * this: + * \code + * Ptr rem = Create (); + * rem->SetRandomVariable (UniformVariable ()); + * rem->SetRate (0.001); + * ... + * Packet p; + * if (rem->IsCorrupt (p)) + * { + * dropTrace(p); + * } else { + * Forward (p); + * } + * \endcode + * + * Two practical error models, a ListErrorModel and a RateErrorModel, + * are currently implemented. + */ +class ErrorModel : public Object +{ +public: + static const InterfaceId iid; + /** + * A factory method to generate a preconfigured default ErrorModel for use + * \return an ErrorModel smart pointer that is the default ErrorModel + * type defined + */ + static Ptr CreateDefault (void); + + ErrorModel (); + virtual ~ErrorModel (); + + /** + * \returns true if the Packet is to be considered as errored/corrupted + * \param pkt Packet to apply error model to + */ + bool IsCorrupt (Packet& pkt); + /** + * Reset any state associated with the error model + */ + void Reset (void); + /** + * Enable the error model + */ + void Enable (void); + /** + * Disable the error model + */ + void Disable (void); + /** + * \return true if error model is enabled; false otherwise + */ + bool IsEnabled (void) const; + +protected: + bool m_enable; + +private: + /* + * These methods must be implemented by subclasses + */ + virtual bool DoCorrupt (Packet&) = 0; + virtual void DoReset (void) = 0; + +}; + +enum ErrorUnit + { + EU_BIT, + EU_BYTE, + EU_PKT + }; + +/** + * \brief Determine which packets are errored corresponding to an underlying + * distribution, rate, and unit. + * + * This object is used to flag packets as being lost/errored or not. + * The two parameters that govern the behavior are the rate (or + * equivalently, the mean duration/spacing between errors), and the + * unit (which may be per-bit, per-byte, and per-packet). + * Users can optionally provide a RandomVariable object; the default + * is to use a Uniform(0,1) distribution. + + * Reset() on this model will do nothing + * + * IsCorrupt() will not modify the packet data buffer + */ +class RateErrorModel : public ErrorModel +{ +public: + static const InterfaceId iid; + static const ClassId cid; + + RateErrorModel (); + virtual ~RateErrorModel (); + + /** + * \returns the ErrorUnit being used by the underlying model + */ + enum ErrorUnit GetUnit (void) const; + /** + * \param error_unit the ErrorUnit to be used by the underlying model + */ + void SetUnit (enum ErrorUnit error_unit); + + /** + * \returns the error rate being applied by the model + */ + double GetRate (void) const; + /** + * \param rate the error rate to be used by the model + */ + void SetRate (double rate); + + /** + * \param ranvar A random variable distribution to generate random variates + */ + void SetRandomVariable (const RandomVariable &ranvar); + +private: + virtual bool DoCorrupt (Packet& p); + virtual bool DoCorruptPkt (Packet& p); + virtual bool DoCorruptByte (Packet& p); + virtual bool DoCorruptBit (Packet& p); + virtual void DoReset (void); + + enum ErrorUnit m_unit; + double m_rate; + + RandomVariable* m_ranvar; +}; + +/** + * \brief Provide a list of Packet uids to corrupt + * + * This object is used to flag packets as being lost/errored or not. + * A note on performance: the list is assumed to be unordered, and + * in general, Packet uids received may be unordered. Therefore, + * each call to IsCorrupt() will result in a walk of the list with + * the present underlying implementation. + * + * Note also that if one wants to target multiple packets from looking + * at an (unerrored) trace file, the act of erroring a given packet may + * cause subsequent packet uids to change. For instance, suppose one wants + * to error packets 11 and 17 on a given device. It may be that erroring + * packet 11 will cause the subsequent uid stream to change and 17 may no + * longer correspond to the second packet that one wants to lose. Therefore, + * be advised that it might take some trial and error to select the + * right uids when multiple are provided. + * + * Reset() on this model will clear the list + * + * IsCorrupt() will not modify the packet data buffer + */ +class ListErrorModel : public ErrorModel +{ +public: + static const InterfaceId iid; + static const ClassId cid; + ListErrorModel (); + virtual ~ListErrorModel (); + + /** + * \return a copy of the underlying list + */ + std::list GetList (void) const; + /** + * \param packetlist The list of packet uids to error. + * + * This method overwrites any previously provided list. + */ + void SetList (const std::list &packetlist); + +private: + virtual bool DoCorrupt (Packet& p); + virtual void DoReset (void); + + typedef std::list PacketList; + typedef std::list::const_iterator PacketListCI; + + PacketList m_packetList; + +}; + + +} //namespace ns3 +#endif diff --git a/src/common/wscript b/src/common/wscript index 2472ecd1e..30589542a 100644 --- a/src/common/wscript +++ b/src/common/wscript @@ -13,6 +13,7 @@ def build(bld): 'tag-registry.cc', 'pcap-writer.cc', 'data-rate.cc', + 'error-model.cc', ] headers = bld.create_obj('ns3header') @@ -29,4 +30,5 @@ def build(bld): 'packet-metadata.h', 'pcap-writer.h', 'data-rate.h', + 'error-model.h', ] diff --git a/src/devices/csma/csma-net-device.cc b/src/devices/csma/csma-net-device.cc index e4fd05a1b..903bb6cb6 100644 --- a/src/devices/csma/csma-net-device.cc +++ b/src/devices/csma/csma-net-device.cc @@ -28,6 +28,7 @@ #include "ns3/ethernet-header.h" #include "ns3/ethernet-trailer.h" #include "ns3/llc-snap-header.h" +#include "ns3/error-model.h" NS_LOG_COMPONENT_DEFINE ("CsmaNetDevice"); @@ -82,7 +83,8 @@ CsmaTraceType::Get (void) const CsmaNetDevice::CsmaNetDevice (Ptr node) : NetDevice (node, Mac48Address::Allocate ()), - m_bps (DataRate (0xffffffff)) + m_bps (DataRate (0xffffffff)), + m_receiveErrorModel (0) { NS_LOG_FUNCTION; NS_LOG_PARAM ("(" << node << ")"); @@ -93,7 +95,8 @@ CsmaNetDevice::CsmaNetDevice (Ptr node) CsmaNetDevice::CsmaNetDevice (Ptr node, Mac48Address addr, CsmaEncapsulationMode encapMode) : NetDevice(node, addr), - m_bps (DataRate (0xffffffff)) + m_bps (DataRate (0xffffffff)), + m_receiveErrorModel (0) { NS_LOG_FUNCTION; NS_LOG_PARAM ("(" << node << ")"); @@ -531,6 +534,15 @@ CsmaNetDevice::AddQueue (Ptr q) m_queue = q; } +void CsmaNetDevice::AddReceiveErrorModel (Ptr em) +{ + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << em << ")"); + + m_receiveErrorModel = em; + AddInterface (em); +} + void CsmaNetDevice::Receive (const Packet& packet) { @@ -593,31 +605,41 @@ CsmaNetDevice::Receive (const Packet& packet) return; } - m_rxTrace (p); + if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (p) ) + { + NS_LOG_LOGIC ("Dropping pkt due to error model "); + m_dropTrace (packet); + // Do not forward up; let this packet go + } + else + { + m_rxTrace (p); // // protocol must be initialized to avoid a compiler warning in the RAW // case that breaks the optimized build. // - uint16_t protocol = 0; + uint16_t protocol = 0; - switch (m_encapMode) - { - case ETHERNET_V1: - case IP_ARP: - protocol = header.GetLengthType(); - break; - case LLC: { - LlcSnapHeader llc; - p.RemoveHeader (llc); - protocol = llc.GetType (); - } break; - case RAW: - NS_ASSERT (false); - break; + switch (m_encapMode) + { + case ETHERNET_V1: + case IP_ARP: + protocol = header.GetLengthType(); + break; + case LLC: + { + LlcSnapHeader llc; + p.RemoveHeader (llc); + protocol = llc.GetType (); + } + break; + case RAW: + NS_ASSERT (false); + break; + } + ForwardUp (p, protocol, header.GetSource ()); + return; } - - ForwardUp (p, protocol, header.GetSource ()); - return; } Address @@ -687,4 +709,5 @@ CsmaNetDevice::DoGetChannel(void) const return m_channel; } + } // namespace ns3 diff --git a/src/devices/csma/csma-net-device.h b/src/devices/csma/csma-net-device.h index bbe5259ed..1ce38d098 100644 --- a/src/devices/csma/csma-net-device.h +++ b/src/devices/csma/csma-net-device.h @@ -40,6 +40,7 @@ namespace ns3 { class Queue; class CsmaChannel; +class ErrorModel; /** * \brief hold in a TraceContext the type of trace source from a CsmaNetDevice @@ -192,6 +193,16 @@ enum CsmaEncapsulationMode { * ownership. */ void AddQueue (Ptr queue); + /** + * Attach a receive ErrorModel to the CsmaNetDevice. + * + * The CsmaNetDevice may optionally include an ErrorModel in + * the packet receive chain. + * + * @see ErrorModel + * @param em a pointer to the ErrorModel + */ + void AddReceiveErrorModel(Ptr em); /** * Receive a packet from a connected CsmaChannel. * @@ -453,6 +464,12 @@ private: * @see class DropTailQueue */ Ptr m_queue; + + /** + * Error model for receive packet events + */ + Ptr m_receiveErrorModel; + /** * NOT TESTED * The trace source for the packet reception events that the device can 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 ce3a253eb..66525b7a1 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 @@ -26,6 +26,7 @@ #include "ns3/composite-trace-resolver.h" #include "ns3/mac48-address.h" #include "ns3/llc-snap-header.h" +#include "ns3/error-model.h" #include "point-to-point-net-device.h" #include "point-to-point-channel.h" @@ -38,14 +39,28 @@ DataRateDefaultValue PointToPointNetDevice::g_defaultRate( "The default data rate for point to point links", DataRate ("10Mb/s")); -PointToPointTraceType::PointToPointTraceType () +PointToPointTraceType::PointToPointTraceType (enum Type type) + : m_type (type) { NS_LOG_FUNCTION; } +PointToPointTraceType::PointToPointTraceType () + : m_type (RX) +{ + NS_LOG_FUNCTION; +} + void PointToPointTraceType::Print (std::ostream &os) const { - os << "dev-rx"; + switch (m_type) { + case RX: + os << "dev-rx"; + break; + case DROP: + os << "dev-drop"; + break; + } } uint16_t @@ -63,6 +78,12 @@ PointToPointTraceType::GetTypeName (void) const return "ns3::PointToPointTraceType"; } +enum PointToPointTraceType::Type +PointToPointTraceType::Get (void) const +{ + NS_LOG_FUNCTION; + return m_type; +} PointToPointNetDevice::PointToPointNetDevice (Ptr node, const DataRate& rate) @@ -73,7 +94,9 @@ PointToPointNetDevice::PointToPointNetDevice (Ptr node, m_tInterframeGap (Seconds(0)), m_channel (0), m_queue (0), - m_rxTrace () + m_rxTrace (), + m_dropTrace (), + m_receiveErrorModel (0) { NS_LOG_FUNCTION; NS_LOG_PARAM ("(" << node << ")"); @@ -94,6 +117,7 @@ PointToPointNetDevice::~PointToPointNetDevice() { NS_LOG_FUNCTION; m_queue = 0; + m_receiveErrorModel = 0; } void @@ -221,7 +245,12 @@ PointToPointNetDevice::GetTraceResolver (void) const TraceDoc ("receive MAC packet", "const Packet &", "packet received"), m_rxTrace, - PointToPointTraceType ()); + PointToPointTraceType (PointToPointTraceType::RX)); + resolver->AddSource ("drop", + TraceDoc ("drop MAC packet", + "const Packet &", "packet dropped"), + m_dropTrace, + PointToPointTraceType (PointToPointTraceType::DROP)); resolver->SetParentResolver (NetDevice::GetTraceResolver ()); return resolver; } @@ -262,6 +291,15 @@ void PointToPointNetDevice::AddQueue (Ptr q) m_queue = q; } +void PointToPointNetDevice::AddReceiveErrorModel (Ptr em) +{ + NS_LOG_FUNCTION; + NS_LOG_PARAM ("(" << em << ")"); + + m_receiveErrorModel = em; + AddInterface (em); +} + void PointToPointNetDevice::Receive (Packet& p) { NS_LOG_FUNCTION; @@ -269,9 +307,17 @@ void PointToPointNetDevice::Receive (Packet& p) uint16_t protocol = 0; Packet packet = p; - m_rxTrace (packet); - ProcessHeader(packet, protocol); - ForwardUp (packet, protocol, GetBroadcast ()); + if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (p) ) + { + m_dropTrace (packet); + // Do not forward up; let this packet go + } + else + { + m_rxTrace (packet); + ProcessHeader(packet, protocol); + ForwardUp (packet, protocol, GetBroadcast ()); + } } Ptr PointToPointNetDevice::GetQueue(void) const diff --git a/src/devices/point-to-point/point-to-point-net-device.h b/src/devices/point-to-point/point-to-point-net-device.h index b85a2a66b..e597773ad 100644 --- a/src/devices/point-to-point/point-to-point-net-device.h +++ b/src/devices/point-to-point/point-to-point-net-device.h @@ -37,6 +37,7 @@ namespace ns3 { class Queue; class PointToPointChannel; +class ErrorModel; /** * \brief hold in a TraceContext the type of trace source from a PointToPointNetDevice @@ -44,10 +45,21 @@ class PointToPointChannel; class PointToPointTraceType : public TraceContextElement { public: + enum Type { + RX, + DROP + }; + PointToPointTraceType (enum Type type); PointToPointTraceType (); void Print (std::ostream &os) const; static uint16_t GetUid (void); std::string GetTypeName (void) const; + /** + * \returns the type of the trace source which generated an event. + */ + enum Type Get (void) const; +private: + enum Type m_type; }; /** @@ -133,6 +145,16 @@ public: * ownership. */ void AddQueue (Ptr queue); + /** + * Attach a receive ErrorModel to the PointToPointNetDevice. + * + * The PointToPointNetDevice may optionally include an ErrorModel in + * the packet receive chain. + * + * @see ErrorModel + * @param em a pointer to the ErrorModel + */ + void AddReceiveErrorModel(Ptr em); /** * Receive a packet from a connected PointToPointChannel. * @@ -288,11 +310,23 @@ private: * @see class TraceResolver */ CallbackTraceSource m_rxTrace; + /** + * The trace source for the packet drop events that the device can + * fire. + * + * @see class CallBackTraceSource + * @see class TraceResolver + */ + CallbackTraceSource m_dropTrace; /** * Default data rate. Used for all newly created p2p net devices */ static DataRateDefaultValue g_defaultRate; + /** + * Error model for receive packet events + */ + Ptr m_receiveErrorModel; }; }; // namespace ns3 From f7e49cfb04c6f0c9a98051d5991c7e2758aca826 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Wed, 14 Nov 2007 20:50:53 -0800 Subject: [PATCH 23/67] GetNetDevice method in PointToPointTopology class --- .../point-to-point/point-to-point-topology.cc | 24 +++++++++++++++++++ .../point-to-point/point-to-point-topology.h | 11 +++++++++ 2 files changed, 35 insertions(+) diff --git a/src/devices/point-to-point/point-to-point-topology.cc b/src/devices/point-to-point/point-to-point-topology.cc index 7e0fd4efd..e6b10a82f 100644 --- a/src/devices/point-to-point/point-to-point-topology.cc +++ b/src/devices/point-to-point/point-to-point-topology.cc @@ -62,6 +62,30 @@ PointToPointTopology::AddPointToPointLink( return channel; } +Ptr +PointToPointTopology::GetNetDevice (Ptr n, Ptr chan) +{ + Ptr found = 0; + + // The PointToPoint channel is used to find the relevant NetDevice + NS_ASSERT (chan->GetNDevices () == 2); + Ptr nd1 = chan->GetDevice (0); + Ptr nd2 = chan->GetDevice (1); + if ( nd1->GetNode ()->GetId () == n->GetId () ) + { + found = nd1; + } + else if ( nd2->GetNode ()->GetId () == n->GetId () ) + { + found = nd2; + } + else + { + NS_ASSERT (found); + } + return found; +} + void PointToPointTopology::AddIpv4Addresses( Ptr chan, diff --git a/src/devices/point-to-point/point-to-point-topology.h b/src/devices/point-to-point/point-to-point-topology.h index 35a452269..29b0419a0 100644 --- a/src/devices/point-to-point/point-to-point-topology.h +++ b/src/devices/point-to-point/point-to-point-topology.h @@ -55,6 +55,17 @@ public: static Ptr AddPointToPointLink( Ptr n1, Ptr n2, const DataRate& dataRate, const Time& delay); + /** + * \param n Node + * \param chan PointToPointChannel connected to node n + * \return Pointer to the corresponding PointToPointNetDevice + * + * Utility function to retrieve a PointToPointNetDevice pointer + * corresponding to the input parameters + */ + static Ptr GetNetDevice( + Ptr n, Ptr chan); + /** * \param chan PointToPointChannel to use * \param n1 Node From 1b919575f2128dc76976fd6ccc99322344eec985 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Thu, 8 Nov 2007 22:31:54 -0800 Subject: [PATCH 24/67] fix bug 100 DefaultValue::Bind for floats --- src/core/default-value.cc | 2 +- src/core/default-value.h | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/core/default-value.cc b/src/core/default-value.cc index 2acb6e97d..cd3ed23a0 100644 --- a/src/core/default-value.cc +++ b/src/core/default-value.cc @@ -381,7 +381,7 @@ DefaultValueTest::RunTests (void) DefaultValue::Bind ("test-c", "257"); NumericDefaultValue x ("test-x", "help-x", 10.0); NumericDefaultValue y ("test-y", "help-y", 10.0); - + DefaultValue::Bind ("test-y", "-3"); EnumDefaultValue e ("test-e", "help-e", MY_ENUM_C, "C", diff --git a/src/core/default-value.h b/src/core/default-value.h index 8d252ab45..f9caac9e4 100644 --- a/src/core/default-value.h +++ b/src/core/default-value.h @@ -219,6 +219,7 @@ private: virtual bool DoParseValue (const std::string &value); virtual std::string DoGetType (void) const; virtual std::string DoGetDefaultValue (void) const; + T RealMin (void) const; T m_defaultValue; T m_minValue; T m_maxValue; @@ -377,7 +378,7 @@ NumericDefaultValue::NumericDefaultValue (std::string name, T defaultValue) : DefaultValueBase (name, help), m_defaultValue (defaultValue), - m_minValue (std::numeric_limits::min ()), + m_minValue (RealMin ()), m_maxValue (std::numeric_limits::max ()), m_value (defaultValue) { @@ -469,6 +470,21 @@ NumericDefaultValue::DoGetDefaultValue (void) const return oss.str (); } +template +T +NumericDefaultValue::RealMin (void) const +{ + if (std::numeric_limits::is_integer) + { + return std::numeric_limits::min (); + } + else + { + return -std::numeric_limits::max (); + } +} + + /************************************************************** **************************************************************/ From 25d1f542d717748b1e723f8aa766962fcb2f5906 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Wed, 14 Nov 2007 21:05:31 -0800 Subject: [PATCH 25/67] implement StringDefaultValue; bug93 patch from Mathieu --- src/core/default-value.cc | 80 +++++++++++++++++++++++++++++++++++++++ src/core/default-value.h | 36 ++++++++++++++++++ 2 files changed, 116 insertions(+) diff --git a/src/core/default-value.cc b/src/core/default-value.cc index cd3ed23a0..24814bf46 100644 --- a/src/core/default-value.cc +++ b/src/core/default-value.cc @@ -317,6 +317,86 @@ CommandDefaultValue::DoGetDefaultValue (void) const } +StringDefaultValue::StringDefaultValue (const std::string &name, + const std::string &help, + const std::string defaultValue) + : DefaultValueBase (name, help), + m_defaultValue (defaultValue), + m_value (defaultValue), + m_minSize (0), + m_maxSize (-1) +{ + DefaultValueList::Add (this); +} +StringDefaultValue::StringDefaultValue (const std::string &name, + const std::string &help, + const std::string defaultValue, + int maxSize) + : DefaultValueBase (name, help), + m_defaultValue (defaultValue), + m_value (defaultValue), + m_minSize (0), + m_maxSize (maxSize) +{ + DefaultValueList::Add (this); +} +StringDefaultValue::StringDefaultValue (const std::string &name, + const std::string &help, + const std::string defaultValue, + int minSize, + int maxSize) + : DefaultValueBase (name, help), + m_defaultValue (defaultValue), + m_value (defaultValue), + m_minSize (minSize), + m_maxSize (maxSize) +{ + DefaultValueList::Add (this); +} + + +std::string +StringDefaultValue::GetValue (void) const +{ + return m_value; +} + +bool +StringDefaultValue::DoParseValue (const std::string &value) +{ + if ((int)value.size () < m_minSize) + { + return false; + } + if (m_maxSize != -1 && (int)value.size () > m_maxSize) + { + return false; + } + m_value = value; + return true; +} +std::string +StringDefaultValue::DoGetType (void) const +{ + if (m_maxSize == -1) + { + return "string:0"; + } + else + { + std::ostringstream oss; + oss << "string:0:" << m_maxSize; + return oss.str (); + } +} +std::string +StringDefaultValue::DoGetDefaultValue (void) const +{ + return m_defaultValue; +} + + + }//namespace ns3 #ifdef RUN_SELF_TESTS diff --git a/src/core/default-value.h b/src/core/default-value.h index f9caac9e4..686b3ad94 100644 --- a/src/core/default-value.h +++ b/src/core/default-value.h @@ -340,6 +340,42 @@ public: T m_value; }; +/** + * \brief A string variable for ns3::Bind + * \ingroup config + * + * Every instance of this type is automatically + * registered in the variable pool which is used + * by ns3::Bind. + */ +class StringDefaultValue : public DefaultValueBase +{ +public: + StringDefaultValue (const std::string &name, + const std::string &help, + const std::string defaultValue); + StringDefaultValue (const std::string &name, + const std::string &help, + const std::string defaultValue, + int maxSize); + StringDefaultValue (const std::string &name, + const std::string &help, + const std::string defaultValue, + int minSize, + int maxSize); + + std::string GetValue (void) const; +private: + virtual bool DoParseValue (const std::string &value); + virtual std::string DoGetType (void) const; + virtual std::string DoGetDefaultValue (void) const; + + std::string m_defaultValue; + std::string m_value; + int m_minSize; + int m_maxSize; +}; + /** * \brief Class used to call a certain function during the configuration of the * simulation From baeee68d27e64a8c85c96547db55996c68f82ec9 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Mon, 5 Nov 2007 21:08:02 -0800 Subject: [PATCH 26/67] move ipv4 static to member functions --- src/node/ipv4.cc | 48 ++----------------- src/node/ipv4.h | 20 ++++---- .../global-route-manager-impl.cc | 2 +- 3 files changed, 14 insertions(+), 56 deletions(-) diff --git a/src/node/ipv4.cc b/src/node/ipv4.cc index f8a852149..b0e5f9349 100644 --- a/src/node/ipv4.cc +++ b/src/node/ipv4.cc @@ -36,13 +36,11 @@ Ipv4::~Ipv4 () {} uint32_t -Ipv4::GetIfIndexByAddress (Ptr node, Ipv4Address a, Ipv4Mask amask) +Ipv4::GetIfIndexByAddress (Ipv4Address addr, Ipv4Mask mask) { - Ptr ipv4 = node->QueryInterface (Ipv4::iid); - NS_ASSERT_MSG (ipv4, "Ipv4::GetIfIndexByAddress: No Ipv4 interface"); - for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i++) + for (uint32_t i = 0; i < GetNInterfaces (); i++) { - if (ipv4->GetAddress (i).CombineMask(amask) == a.CombineMask(amask) ) + if (GetAddress (i).CombineMask(mask) == addr.CombineMask(mask) ) { return i; } @@ -52,44 +50,4 @@ Ipv4::GetIfIndexByAddress (Ptr node, Ipv4Address a, Ipv4Mask amask) return 0; } -// -// XXX BUGBUG I don't think this is really the right approach here. The call -// to GetRoute () filters down into Ipv4L3Protocol where it translates into -// a call into the Ipv4 static routing package. This bypasses any other -// routing packages. At a minimum, the name is misleading. -// -bool -Ipv4::GetRouteToDestination ( - Ptr node, - Ipv4Route& route, - Ipv4Address a, - Ipv4Mask amask) -{ - Ipv4Route tempRoute; - Ptr ipv4 = node->QueryInterface (Ipv4::iid); - NS_ASSERT_MSG (ipv4, "Ipv4::GetRouteToDestination: No Ipv4 interface"); - for (uint32_t i = 0; i < ipv4->GetNRoutes (); i++) - { - tempRoute = ipv4->GetRoute (i); - // Host route found - if ( tempRoute.IsNetwork () == false && tempRoute.GetDest () == a ) - { - route = tempRoute; - return true; - } - else if ( tempRoute.IsNetwork () && - tempRoute.GetDestNetwork () == a.CombineMask(amask) ) - { - route = tempRoute; - return true; - } - else if ( tempRoute.IsDefault () ) - { - route = tempRoute; - return true; - } - } - return false; -} - } // namespace ns3 diff --git a/src/node/ipv4.h b/src/node/ipv4.h index 00f14f7ba..0cd1d129e 100644 --- a/src/node/ipv4.h +++ b/src/node/ipv4.h @@ -449,16 +449,16 @@ public: */ virtual void SetDown (uint32_t i) = 0; -/** - * Convenience functions (Doxygen still needed) - * - * Return the ifIndex corresponding to the Ipv4Address provided. - */ - static uint32_t GetIfIndexByAddress (Ptr node, Ipv4Address a, - Ipv4Mask amask = Ipv4Mask("255.255.255.255")); - - static bool GetRouteToDestination (Ptr node, Ipv4Route& route, - Ipv4Address a, Ipv4Mask amask = Ipv4Mask("255.255.255.255")); + /** + * \brief Convenience function to return the ifIndex corresponding + * to the Ipv4Address provided + * + * \param addr Ipv4Address + * \param mask corresponding Ipv4Mask + * \returns ifIndex corresponding to a/amask + */ + virtual uint32_t GetIfIndexByAddress (Ipv4Address addr, + Ipv4Mask mask = Ipv4Mask("255.255.255.255")); }; } // namespace ns3 diff --git a/src/routing/global-routing/global-route-manager-impl.cc b/src/routing/global-routing/global-route-manager-impl.cc index ed61f7f5c..b666fcb8c 100644 --- a/src/routing/global-routing/global-route-manager-impl.cc +++ b/src/routing/global-routing/global-route-manager-impl.cc @@ -1172,7 +1172,7 @@ GlobalRouteManagerImpl::FindOutgoingInterfaceId (Ipv4Address a, Ipv4Mask amask) // we're looking for. If we find one, return the corresponding interface // index. // - return (Ipv4::GetIfIndexByAddress (node, a, amask) ); + return (ipv4->GetIfIndexByAddress (a, amask) ); } } // From 48a98d8b1f31bf420df73b636b2646daf063daf3 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Tue, 6 Nov 2007 15:45:05 -0800 Subject: [PATCH 27/67] update bench-packets.cc program --- utils/bench-packets.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/utils/bench-packets.cc b/utils/bench-packets.cc index e16c17b02..b35a2379c 100644 --- a/utils/bench-packets.cc +++ b/utils/bench-packets.cc @@ -211,13 +211,19 @@ int main (int argc, char *argv[]) argc--; argv++; } + if (n == 0) + { + std::cerr << "Error-- number of packets must be specified " << + "by command-line argument --n=(number of packets)" << std::endl; + exit (1); + } + std::cout << "Running bench-packets with n=" << n << std::endl; - + Packet::EnableMetadata (); runBench (&benchPtrA, n, "a"); runBench (&benchPtrB, n, "b"); runBench (&benchPtrC, n, "c"); - Packet::EnableMetadata (); //runBench (&benchPrint, n, "print"); PacketMetadata::SetOptOne (false); runBench (&benchPtrA, n, "meta-a"); From 00bf89e1d202661804566ce8de5dcf799b8e2257 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 8 Nov 2007 10:24:33 +0100 Subject: [PATCH 28/67] a vector class --- src/mobility/vector.cc | 48 ++++++++++++++++++++++++++++++++ src/mobility/vector.h | 63 ++++++++++++++++++++++++++++++++++++++++++ src/mobility/wscript | 2 ++ 3 files changed, 113 insertions(+) create mode 100644 src/mobility/vector.cc create mode 100644 src/mobility/vector.h diff --git a/src/mobility/vector.cc b/src/mobility/vector.cc new file mode 100644 index 000000000..79917c16e --- /dev/null +++ b/src/mobility/vector.cc @@ -0,0 +1,48 @@ +/* -*- 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 "vector.h" +#include + +namespace ns3 { + + +Vector::Vector (double _x, double _y, double _z) + : x (_x), + y (_y), + z (_z) +{} + +Vector::Vector () + : x (0.0), + y (0.0), + z (0.0) +{} + +double +CalculateDistance (const Vector &a, const Vector &b) +{ + double dx = b.x - a.x; + double dy = b.y - a.y; + double dz = b.z - a.z; + double distance = std::sqrt (dx * dx + dy * dy + dz * dz); + return distance; +} + +} // namespace ns3 diff --git a/src/mobility/vector.h b/src/mobility/vector.h new file mode 100644 index 000000000..6bc277f27 --- /dev/null +++ b/src/mobility/vector.h @@ -0,0 +1,63 @@ +/* -*- 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 VECTOR_H +#define VECTOR_H + +namespace ns3 { + +/** + * \brief a 3d cartesian position vector + * + * Unit is meters. + */ +class Vector +{ +public: + /** + * \param _x x coordinate of vector vector + * \param _y y coordinate of vector vector + * \param _z z coordinate of vector vector + * + * Create vector vector (_x, _y, _z) + */ + Vector (double _x, double _y, double _z); + /** + * Create vector vector (0.0, 0.0, 0.0) + */ + Vector (); + /** + * x coordinate of vector vector + */ + double x; + /** + * y coordinate of vector vector + */ + double y; + /** + * z coordinate of vector vector + */ + double z; +}; + +double CalculateDistance (const Vector &a, const Vector &b); + +} // namespace ns3 + +#endif /* VECTOR_H */ diff --git a/src/mobility/wscript b/src/mobility/wscript index f630a4b71..2833ce1e0 100644 --- a/src/mobility/wscript +++ b/src/mobility/wscript @@ -3,6 +3,7 @@ def build(bld): mobility = bld.create_ns3_module('mobility', ['core', 'simulator']) mobility.source = [ + 'vector.cc', 'grid-topology.cc', 'hierarchical-mobility-model.cc', 'mobility-model.cc', @@ -24,6 +25,7 @@ def build(bld): headers = bld.create_obj('ns3header') headers.source = [ + 'vector.h', 'grid-topology.h', 'hierarchical-mobility-model.h', 'mobility-model.h', From 6e660e4c27e108376839d82488576c52eff777e2 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 8 Nov 2007 11:24:41 +0100 Subject: [PATCH 29/67] rename MobilityModel::Get/Set to GetPosition/SetPosition --- samples/main-grid-topology.cc | 2 +- samples/main-random-topology.cc | 2 +- samples/main-random-walk.cc | 2 +- src/mobility/grid-topology.cc | 4 ++-- src/mobility/hierarchical-mobility-model.cc | 14 +++++++------- src/mobility/hierarchical-mobility-model.h | 4 ++-- src/mobility/mobility-model.cc | 12 ++++++------ src/mobility/mobility-model.h | 8 ++++---- src/mobility/ns2-mobility-file-topology.cc | 4 ++-- src/mobility/random-direction-2d-mobility-model.cc | 4 ++-- src/mobility/random-direction-2d-mobility-model.h | 4 ++-- src/mobility/random-topology.cc | 2 +- src/mobility/random-walk-2d-mobility-model.cc | 4 ++-- src/mobility/random-walk-2d-mobility-model.h | 4 ++-- src/mobility/random-waypoint-mobility-model.cc | 4 ++-- src/mobility/random-waypoint-mobility-model.h | 4 ++-- src/mobility/static-mobility-model.cc | 4 ++-- src/mobility/static-mobility-model.h | 4 ++-- src/mobility/static-speed-mobility-model.cc | 4 ++-- src/mobility/static-speed-mobility-model.h | 4 ++-- utils/mobility-visualizer-model.cc | 2 +- 21 files changed, 48 insertions(+), 48 deletions(-) diff --git a/samples/main-grid-topology.cc b/samples/main-grid-topology.cc index e2fb1c3e6..ef0f15d37 100644 --- a/samples/main-grid-topology.cc +++ b/samples/main-grid-topology.cc @@ -41,7 +41,7 @@ int main (int argc, char *argv[]) Ptr object = *j; Ptr position = object->QueryInterface (MobilityModel::iid); NS_ASSERT (position != 0); - Position pos = position->Get (); + Position pos = position->GetPosition (); std::cout << "x=" << pos.x << ", y=" << pos.y << ", z=" << pos.z << std::endl; } diff --git a/samples/main-random-topology.cc b/samples/main-random-topology.cc index 3021ed3fb..608397d53 100644 --- a/samples/main-random-topology.cc +++ b/samples/main-random-topology.cc @@ -17,7 +17,7 @@ using namespace ns3; static void CourseChange (const TraceContext &context, Ptr position) { - Position pos = position->Get (); + Position pos = position->GetPosition (); std::cout << Simulator::Now () << ", pos=" << position << ", x=" << pos.x << ", y=" << pos.y << ", z=" << pos.z << std::endl; } diff --git a/samples/main-random-walk.cc b/samples/main-random-walk.cc index cccd64936..45be9b904 100644 --- a/samples/main-random-walk.cc +++ b/samples/main-random-walk.cc @@ -18,7 +18,7 @@ using namespace ns3; static void CourseChange (ns3::TraceContext const&, Ptr mobility) { - Position pos = mobility->Get (); + Position pos = mobility->GetPosition (); Speed vel = mobility->GetSpeed (); std::cout << Simulator::Now () << ", model=" << mobility << ", POS: x=" << pos.x << ", y=" << pos.y << ", z=" << pos.z << "; VEL:" << vel.dx << ", y=" << vel.dy diff --git a/src/mobility/grid-topology.cc b/src/mobility/grid-topology.cc index 625cb49ae..f738a3be2 100644 --- a/src/mobility/grid-topology.cc +++ b/src/mobility/grid-topology.cc @@ -46,7 +46,7 @@ GridTopology::LayoutOneRowFirst (Ptr object, uint32_t i) Ptr mobility = ComponentManager::Create (m_positionClassId, MobilityModel::iid); object->AddInterface (mobility); - mobility->Set (Position (x, y, 0.0)); + mobility->SetPosition (Position (x, y, 0.0)); } void @@ -58,7 +58,7 @@ GridTopology::LayoutOneColumnFirst (Ptr object, uint32_t i) Ptr mobility = ComponentManager::Create (m_positionClassId, MobilityModel::iid); object->AddInterface (mobility); - mobility->Set (Position (x, y, 0.0)); + mobility->SetPosition (Position (x, y, 0.0)); } diff --git a/src/mobility/hierarchical-mobility-model.cc b/src/mobility/hierarchical-mobility-model.cc index 00f4643c2..d144597ec 100644 --- a/src/mobility/hierarchical-mobility-model.cc +++ b/src/mobility/hierarchical-mobility-model.cc @@ -57,24 +57,24 @@ HierarchicalMobilityModel::GetParent (void) const } Position -HierarchicalMobilityModel::DoGet (void) const +HierarchicalMobilityModel::DoGetPosition (void) const { - Position parentPosition = m_parent->Get (); - Position childPosition = m_child->Get (); + Position parentPosition = m_parent->GetPosition (); + Position childPosition = m_child->GetPosition (); return Position (parentPosition.x + childPosition.x, parentPosition.y + childPosition.y, parentPosition.z + childPosition.z); } void -HierarchicalMobilityModel::DoSet (const Position &position) +HierarchicalMobilityModel::DoSetPosition (const Position &position) { - // This implementation of DoSet is really an arbitraty choice. + // This implementation of DoSetPosition is really an arbitraty choice. // anything else would have been ok. - Position parentPosition = m_parent->Get (); + Position parentPosition = m_parent->GetPosition (); Position childPosition (position.x - parentPosition.x, position.y - parentPosition.y, position.z - parentPosition.z); - m_child->Set (childPosition); + m_child->SetPosition (childPosition); } Speed HierarchicalMobilityModel::DoGetSpeed (void) const diff --git a/src/mobility/hierarchical-mobility-model.h b/src/mobility/hierarchical-mobility-model.h index 44623244d..d15c173c0 100644 --- a/src/mobility/hierarchical-mobility-model.h +++ b/src/mobility/hierarchical-mobility-model.h @@ -58,8 +58,8 @@ public: Ptr GetParent (void) const; private: - virtual Position DoGet (void) const; - virtual void DoSet (const Position &position); + virtual Position DoGetPosition (void) const; + virtual void DoSetPosition (const Position &position); virtual Speed DoGetSpeed (void) const; void ParentChanged (const TraceContext &context, Ptr model); diff --git a/src/mobility/mobility-model.cc b/src/mobility/mobility-model.cc index 50965d800..ffc4fdc70 100644 --- a/src/mobility/mobility-model.cc +++ b/src/mobility/mobility-model.cc @@ -34,9 +34,9 @@ MobilityModel::~MobilityModel () {} Position -MobilityModel::Get (void) const +MobilityModel::GetPosition (void) const { - return DoGet (); + return DoGetPosition (); } Speed MobilityModel::GetSpeed (void) const @@ -45,16 +45,16 @@ MobilityModel::GetSpeed (void) const } void -MobilityModel::Set (const Position &position) +MobilityModel::SetPosition (const Position &position) { - DoSet (position); + DoSetPosition (position); } double MobilityModel::GetDistanceFrom (Ptr other) const { - Position oPosition = other->DoGet (); - Position position = DoGet (); + Position oPosition = other->DoGetPosition (); + Position position = DoGetPosition (); return CalculateDistance (position, oPosition); } diff --git a/src/mobility/mobility-model.h b/src/mobility/mobility-model.h index 07fd171ea..774f293b6 100644 --- a/src/mobility/mobility-model.h +++ b/src/mobility/mobility-model.h @@ -43,11 +43,11 @@ public: /** * \returns the current position */ - Position Get (void) const; + Position GetPosition (void) const; /** * \param position the position to set. */ - void Set (const Position &position); + void SetPosition (const Position &position); /** * \returns the current position. */ @@ -70,14 +70,14 @@ private: * Concrete subclasses of this base class must * implement this method. */ - virtual Position DoGet (void) const = 0; + virtual Position DoGetPosition (void) const = 0; /** * \param position the position to set. * * Concrete subclasses of this base class must * implement this method. */ - virtual void DoSet (const Position &position) = 0; + virtual void DoSetPosition (const Position &position) = 0; /** * \returns the current speed. * diff --git a/src/mobility/ns2-mobility-file-topology.cc b/src/mobility/ns2-mobility-file-topology.cc index 2b2a32f92..73add3c2c 100644 --- a/src/mobility/ns2-mobility-file-topology.cc +++ b/src/mobility/ns2-mobility-file-topology.cc @@ -97,7 +97,7 @@ Ns2MobilityFileTopology::LayoutObjectStore (const ObjectStore &store) const { double value = ReadDouble (line.substr (endNodeId + 9, std::string::npos)); std::string coordinate = line.substr (endNodeId + 6, 1); - Position position = model->Get (); + Position position = model->GetPosition (); if (coordinate == "X") { position.x = value; @@ -117,7 +117,7 @@ Ns2MobilityFileTopology::LayoutObjectStore (const ObjectStore &store) const { continue; } - model->Set (position); + model->SetPosition (position); } else { diff --git a/src/mobility/random-direction-2d-mobility-model.cc b/src/mobility/random-direction-2d-mobility-model.cc index 9df80874c..508478d18 100644 --- a/src/mobility/random-direction-2d-mobility-model.cc +++ b/src/mobility/random-direction-2d-mobility-model.cc @@ -188,12 +188,12 @@ RandomDirection2dMobilityModel::ResetDirectionAndSpeed (void) SetDirectionAndSpeed (direction); } Position -RandomDirection2dMobilityModel::DoGet (void) const +RandomDirection2dMobilityModel::DoGetPosition (void) const { return m_helper.GetCurrentPosition (m_parameters->m_bounds); } void -RandomDirection2dMobilityModel::DoSet (const Position &position) +RandomDirection2dMobilityModel::DoSetPosition (const Position &position) { m_helper.InitializePosition (position); Simulator::Remove (m_event); diff --git a/src/mobility/random-direction-2d-mobility-model.h b/src/mobility/random-direction-2d-mobility-model.h index 6dce660a1..7c5520a35 100644 --- a/src/mobility/random-direction-2d-mobility-model.h +++ b/src/mobility/random-direction-2d-mobility-model.h @@ -106,8 +106,8 @@ class RandomDirection2dMobilityModel : public MobilityModel void SetDirectionAndSpeed (double direction); void InitializeDirectionAndSpeed (void); virtual void DoDispose (void); - virtual Position DoGet (void) const; - virtual void DoSet (const Position &position); + virtual Position DoGetPosition (void) const; + virtual void DoSetPosition (const Position &position); virtual Speed DoGetSpeed (void) const; static const double PI; diff --git a/src/mobility/random-topology.cc b/src/mobility/random-topology.cc index f04ce2b56..2e044cce9 100644 --- a/src/mobility/random-topology.cc +++ b/src/mobility/random-topology.cc @@ -71,7 +71,7 @@ RandomTopology::LayoutOne (Ptr object) MobilityModel::iid); object->AddInterface (mobility); Position position = m_positionModel->Get (); - mobility->Set (position); + mobility->SetPosition (position); } diff --git a/src/mobility/random-walk-2d-mobility-model.cc b/src/mobility/random-walk-2d-mobility-model.cc index 07aa948d0..0c2304c62 100644 --- a/src/mobility/random-walk-2d-mobility-model.cc +++ b/src/mobility/random-walk-2d-mobility-model.cc @@ -210,12 +210,12 @@ RandomWalk2dMobilityModel::DoDispose (void) MobilityModel::DoDispose (); } Position -RandomWalk2dMobilityModel::DoGet (void) const +RandomWalk2dMobilityModel::DoGetPosition (void) const { return m_helper.GetCurrentPosition (m_parameters->m_bounds); } void -RandomWalk2dMobilityModel::DoSet (const Position &position) +RandomWalk2dMobilityModel::DoSetPosition (const Position &position) { NS_ASSERT (m_parameters->m_bounds.IsInside (position)); m_helper.InitializePosition (position); diff --git a/src/mobility/random-walk-2d-mobility-model.h b/src/mobility/random-walk-2d-mobility-model.h index 2e921216b..aeaa6625c 100644 --- a/src/mobility/random-walk-2d-mobility-model.h +++ b/src/mobility/random-walk-2d-mobility-model.h @@ -132,8 +132,8 @@ class RandomWalk2dMobilityModel : public MobilityModel void Rebound (Time timeLeft); void DoWalk (Time timeLeft); virtual void DoDispose (void); - virtual Position DoGet (void) const; - virtual void DoSet (const Position &position); + virtual Position DoGetPosition (void) const; + virtual void DoSetPosition (const Position &position); virtual Speed DoGetSpeed (void) const; StaticSpeedHelper m_helper; diff --git a/src/mobility/random-waypoint-mobility-model.cc b/src/mobility/random-waypoint-mobility-model.cc index 0078a35c2..420903123 100644 --- a/src/mobility/random-waypoint-mobility-model.cc +++ b/src/mobility/random-waypoint-mobility-model.cc @@ -142,12 +142,12 @@ RandomWaypointMobilityModel::Start (void) } Position -RandomWaypointMobilityModel::DoGet (void) const +RandomWaypointMobilityModel::DoGetPosition (void) const { return m_helper.GetCurrentPosition (); } void -RandomWaypointMobilityModel::DoSet (const Position &position) +RandomWaypointMobilityModel::DoSetPosition (const Position &position) { m_helper.InitializePosition (position); Simulator::Remove (m_event); diff --git a/src/mobility/random-waypoint-mobility-model.h b/src/mobility/random-waypoint-mobility-model.h index 72aef43b3..a45061a25 100644 --- a/src/mobility/random-waypoint-mobility-model.h +++ b/src/mobility/random-waypoint-mobility-model.h @@ -98,8 +98,8 @@ public: private: void Start (void); void BeginWalk (void); - virtual Position DoGet (void) const; - virtual void DoSet (const Position &position); + virtual Position DoGetPosition (void) const; + virtual void DoSetPosition (const Position &position); virtual Speed DoGetSpeed (void) const; StaticSpeedHelper m_helper; diff --git a/src/mobility/static-mobility-model.cc b/src/mobility/static-mobility-model.cc index 5142b8178..7297640c8 100644 --- a/src/mobility/static-mobility-model.cc +++ b/src/mobility/static-mobility-model.cc @@ -37,12 +37,12 @@ StaticMobilityModel::~StaticMobilityModel () {} Position -StaticMobilityModel::DoGet (void) const +StaticMobilityModel::DoGetPosition (void) const { return m_position; } void -StaticMobilityModel::DoSet (const Position &position) +StaticMobilityModel::DoSetPosition (const Position &position) { m_position = position; NotifyCourseChange (); diff --git a/src/mobility/static-mobility-model.h b/src/mobility/static-mobility-model.h index a1215c08a..6caba0367 100644 --- a/src/mobility/static-mobility-model.h +++ b/src/mobility/static-mobility-model.h @@ -48,8 +48,8 @@ public: virtual ~StaticMobilityModel (); private: - virtual Position DoGet (void) const; - virtual void DoSet (const Position &position); + virtual Position DoGetPosition (void) const; + virtual void DoSetPosition (const Position &position); virtual Speed DoGetSpeed (void) const; Position m_position; diff --git a/src/mobility/static-speed-mobility-model.cc b/src/mobility/static-speed-mobility-model.cc index 3f0dd3229..c2c18ea2a 100644 --- a/src/mobility/static-speed-mobility-model.cc +++ b/src/mobility/static-speed-mobility-model.cc @@ -57,12 +57,12 @@ StaticSpeedMobilityModel::SetSpeed (const Speed speed) Position -StaticSpeedMobilityModel::DoGet (void) const +StaticSpeedMobilityModel::DoGetPosition (void) const { return m_helper.GetCurrentPosition (); } void -StaticSpeedMobilityModel::DoSet (const Position &position) +StaticSpeedMobilityModel::DoSetPosition (const Position &position) { m_helper.InitializePosition (position); NotifyCourseChange (); diff --git a/src/mobility/static-speed-mobility-model.h b/src/mobility/static-speed-mobility-model.h index 85d4793d7..d997d16f7 100644 --- a/src/mobility/static-speed-mobility-model.h +++ b/src/mobility/static-speed-mobility-model.h @@ -67,8 +67,8 @@ public: */ void SetSpeed (const Speed speed); private: - virtual Position DoGet (void) const; - virtual void DoSet (const Position &position); + virtual Position DoGetPosition (void) const; + virtual void DoSetPosition (const Position &position); virtual Speed DoGetSpeed (void) const; void Update (void) const; StaticSpeedHelper m_helper; diff --git a/utils/mobility-visualizer-model.cc b/utils/mobility-visualizer-model.cc index 21cb007e4..94f46538c 100644 --- a/utils/mobility-visualizer-model.cc +++ b/utils/mobility-visualizer-model.cc @@ -48,7 +48,7 @@ Sample () { Ptr node = *nodeIter; Ptr mobility = node->QueryInterface (MobilityModel::iid); - Position pos = mobility->Get (); + Position pos = mobility->GetPosition (); Speed vel = mobility->GetSpeed (); NodeUpdate update; From eb666a62ac57c2d1d5f7720ba12fb4324e1e1256 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 8 Nov 2007 12:33:30 +0100 Subject: [PATCH 30/67] replace Position and Speed by Vector --- samples/main-grid-topology.cc | 2 +- samples/main-random-topology.cc | 2 +- samples/main-random-walk.cc | 8 +-- src/mobility/grid-topology.cc | 4 +- src/mobility/hierarchical-mobility-model.cc | 26 ++++---- src/mobility/hierarchical-mobility-model.h | 6 +- src/mobility/mobility-model.cc | 10 +-- src/mobility/mobility-model.h | 15 +++-- src/mobility/ns2-mobility-file-topology.cc | 4 +- src/mobility/position.cc | 48 -------------- src/mobility/position.h | 63 ------------------- .../random-direction-2d-mobility-model.cc | 18 +++--- .../random-direction-2d-mobility-model.h | 6 +- src/mobility/random-position.cc | 8 +-- src/mobility/random-position.h | 8 +-- src/mobility/random-topology.cc | 2 +- src/mobility/random-walk-2d-mobility-model.cc | 32 +++++----- src/mobility/random-walk-2d-mobility-model.h | 6 +- .../random-waypoint-mobility-model.cc | 12 ++-- src/mobility/random-waypoint-mobility-model.h | 6 +- src/mobility/rectangle.cc | 37 ++++++----- src/mobility/rectangle.h | 9 ++- src/mobility/speed.cc | 36 ----------- src/mobility/speed.h | 61 ------------------ src/mobility/static-mobility-model.cc | 10 +-- src/mobility/static-mobility-model.h | 10 +-- src/mobility/static-speed-helper.cc | 32 +++++----- src/mobility/static-speed-helper.h | 25 ++++---- src/mobility/static-speed-mobility-model.cc | 14 ++--- src/mobility/static-speed-mobility-model.h | 15 +++-- src/mobility/wscript | 4 -- utils/mobility-visualizer-model.cc | 8 +-- 32 files changed, 165 insertions(+), 382 deletions(-) delete mode 100644 src/mobility/position.cc delete mode 100644 src/mobility/position.h delete mode 100644 src/mobility/speed.cc delete mode 100644 src/mobility/speed.h diff --git a/samples/main-grid-topology.cc b/samples/main-grid-topology.cc index ef0f15d37..7d9f5bbe5 100644 --- a/samples/main-grid-topology.cc +++ b/samples/main-grid-topology.cc @@ -41,7 +41,7 @@ int main (int argc, char *argv[]) Ptr object = *j; Ptr position = object->QueryInterface (MobilityModel::iid); NS_ASSERT (position != 0); - Position pos = position->GetPosition (); + Vector pos = position->GetPosition (); std::cout << "x=" << pos.x << ", y=" << pos.y << ", z=" << pos.z << std::endl; } diff --git a/samples/main-random-topology.cc b/samples/main-random-topology.cc index 608397d53..fe896278d 100644 --- a/samples/main-random-topology.cc +++ b/samples/main-random-topology.cc @@ -17,7 +17,7 @@ using namespace ns3; static void CourseChange (const TraceContext &context, Ptr position) { - Position pos = position->GetPosition (); + Vector pos = position->GetPosition (); std::cout << Simulator::Now () << ", pos=" << position << ", x=" << pos.x << ", y=" << pos.y << ", z=" << pos.z << std::endl; } diff --git a/samples/main-random-walk.cc b/samples/main-random-walk.cc index 45be9b904..2fa095d4e 100644 --- a/samples/main-random-walk.cc +++ b/samples/main-random-walk.cc @@ -18,11 +18,11 @@ using namespace ns3; static void CourseChange (ns3::TraceContext const&, Ptr mobility) { - Position pos = mobility->GetPosition (); - Speed vel = mobility->GetSpeed (); + Vector pos = mobility->GetPosition (); + Vector vel = mobility->GetSpeed (); std::cout << Simulator::Now () << ", model=" << mobility << ", POS: x=" << pos.x << ", y=" << pos.y - << ", z=" << pos.z << "; VEL:" << vel.dx << ", y=" << vel.dy - << ", z=" << vel.dz << std::endl; + << ", z=" << pos.z << "; VEL:" << vel.x << ", y=" << vel.y + << ", z=" << vel.z << std::endl; } int main (int argc, char *argv[]) diff --git a/src/mobility/grid-topology.cc b/src/mobility/grid-topology.cc index f738a3be2..1e33a70cd 100644 --- a/src/mobility/grid-topology.cc +++ b/src/mobility/grid-topology.cc @@ -46,7 +46,7 @@ GridTopology::LayoutOneRowFirst (Ptr object, uint32_t i) Ptr mobility = ComponentManager::Create (m_positionClassId, MobilityModel::iid); object->AddInterface (mobility); - mobility->SetPosition (Position (x, y, 0.0)); + mobility->SetPosition (Vector (x, y, 0.0)); } void @@ -58,7 +58,7 @@ GridTopology::LayoutOneColumnFirst (Ptr object, uint32_t i) Ptr mobility = ComponentManager::Create (m_positionClassId, MobilityModel::iid); object->AddInterface (mobility); - mobility->SetPosition (Position (x, y, 0.0)); + mobility->SetPosition (Vector (x, y, 0.0)); } diff --git a/src/mobility/hierarchical-mobility-model.cc b/src/mobility/hierarchical-mobility-model.cc index d144597ec..a01ba4821 100644 --- a/src/mobility/hierarchical-mobility-model.cc +++ b/src/mobility/hierarchical-mobility-model.cc @@ -56,34 +56,34 @@ HierarchicalMobilityModel::GetParent (void) const return m_parent; } -Position +Vector HierarchicalMobilityModel::DoGetPosition (void) const { - Position parentPosition = m_parent->GetPosition (); - Position childPosition = m_child->GetPosition (); - return Position (parentPosition.x + childPosition.x, + Vector parentPosition = m_parent->GetPosition (); + Vector childPosition = m_child->GetPosition (); + return Vector (parentPosition.x + childPosition.x, parentPosition.y + childPosition.y, parentPosition.z + childPosition.z); } void -HierarchicalMobilityModel::DoSetPosition (const Position &position) +HierarchicalMobilityModel::DoSetPosition (const Vector &position) { // This implementation of DoSetPosition is really an arbitraty choice. // anything else would have been ok. - Position parentPosition = m_parent->GetPosition (); - Position childPosition (position.x - parentPosition.x, + Vector parentPosition = m_parent->GetPosition (); + Vector childPosition (position.x - parentPosition.x, position.y - parentPosition.y, position.z - parentPosition.z); m_child->SetPosition (childPosition); } -Speed +Vector HierarchicalMobilityModel::DoGetSpeed (void) const { - Speed parentSpeed = m_parent->GetSpeed (); - Speed childSpeed = m_child->GetSpeed (); - Speed speed (parentSpeed.dx + childSpeed.dx, - parentSpeed.dy + childSpeed.dy, - parentSpeed.dz + childSpeed.dz); + Vector parentSpeed = m_parent->GetSpeed (); + Vector childSpeed = m_child->GetSpeed (); + Vector speed (parentSpeed.x + childSpeed.x, + parentSpeed.y + childSpeed.y, + parentSpeed.z + childSpeed.z); return speed; } diff --git a/src/mobility/hierarchical-mobility-model.h b/src/mobility/hierarchical-mobility-model.h index d15c173c0..c454e043c 100644 --- a/src/mobility/hierarchical-mobility-model.h +++ b/src/mobility/hierarchical-mobility-model.h @@ -58,9 +58,9 @@ public: Ptr GetParent (void) const; private: - virtual Position DoGetPosition (void) const; - virtual void DoSetPosition (const Position &position); - virtual Speed DoGetSpeed (void) const; + virtual Vector DoGetPosition (void) const; + virtual void DoSetPosition (const Vector &position); + virtual Vector DoGetSpeed (void) const; void ParentChanged (const TraceContext &context, Ptr model); void ChildChanged (const TraceContext &context, Ptr model); diff --git a/src/mobility/mobility-model.cc b/src/mobility/mobility-model.cc index ffc4fdc70..0e4ef568f 100644 --- a/src/mobility/mobility-model.cc +++ b/src/mobility/mobility-model.cc @@ -33,19 +33,19 @@ MobilityModel::MobilityModel () MobilityModel::~MobilityModel () {} -Position +Vector MobilityModel::GetPosition (void) const { return DoGetPosition (); } -Speed +Vector MobilityModel::GetSpeed (void) const { return DoGetSpeed (); } void -MobilityModel::SetPosition (const Position &position) +MobilityModel::SetPosition (const Vector &position) { DoSetPosition (position); } @@ -53,8 +53,8 @@ MobilityModel::SetPosition (const Position &position) double MobilityModel::GetDistanceFrom (Ptr other) const { - Position oPosition = other->DoGetPosition (); - Position position = DoGetPosition (); + Vector oPosition = other->DoGetPosition (); + Vector position = DoGetPosition (); return CalculateDistance (position, oPosition); } diff --git a/src/mobility/mobility-model.h b/src/mobility/mobility-model.h index 774f293b6..6702e10c5 100644 --- a/src/mobility/mobility-model.h +++ b/src/mobility/mobility-model.h @@ -21,8 +21,7 @@ #define MOBILITY_MODEL_H #include "ns3/object.h" -#include "position.h" -#include "speed.h" +#include "vector.h" namespace ns3 { @@ -43,15 +42,15 @@ public: /** * \returns the current position */ - Position GetPosition (void) const; + Vector GetPosition (void) const; /** * \param position the position to set. */ - void SetPosition (const Position &position); + void SetPosition (const Vector &position); /** * \returns the current position. */ - Speed GetSpeed (void) const; + Vector GetSpeed (void) const; /** * \param position a reference to another mobility model * \returns the distance between the two objects. Unit is meters. @@ -70,21 +69,21 @@ private: * Concrete subclasses of this base class must * implement this method. */ - virtual Position DoGetPosition (void) const = 0; + virtual Vector DoGetPosition (void) const = 0; /** * \param position the position to set. * * Concrete subclasses of this base class must * implement this method. */ - virtual void DoSetPosition (const Position &position) = 0; + virtual void DoSetPosition (const Vector &position) = 0; /** * \returns the current speed. * * Concrete subclasses of this base class must * implement this method. */ - virtual Speed DoGetSpeed (void) const = 0; + virtual Vector DoGetSpeed (void) const = 0; }; }; // namespace ns3 diff --git a/src/mobility/ns2-mobility-file-topology.cc b/src/mobility/ns2-mobility-file-topology.cc index 73add3c2c..44a31d8a3 100644 --- a/src/mobility/ns2-mobility-file-topology.cc +++ b/src/mobility/ns2-mobility-file-topology.cc @@ -97,7 +97,7 @@ Ns2MobilityFileTopology::LayoutObjectStore (const ObjectStore &store) const { double value = ReadDouble (line.substr (endNodeId + 9, std::string::npos)); std::string coordinate = line.substr (endNodeId + 6, 1); - Position position = model->GetPosition (); + Vector position = model->GetPosition (); if (coordinate == "X") { position.x = value; @@ -129,7 +129,7 @@ Ns2MobilityFileTopology::LayoutObjectStore (const ObjectStore &store) const double zSpeed = ReadDouble (line.substr (ySpeedEnd + 1, std::string::npos)); NS_LOG_DEBUG ("at=" << at << "xSpeed=" << xSpeed << ", ySpeed=" << ySpeed << ", zSpeed=" << zSpeed); Simulator::Schedule (Seconds (at), &StaticSpeedMobilityModel::SetSpeed, model, - Speed (xSpeed, ySpeed, zSpeed)); + Vector (xSpeed, ySpeed, zSpeed)); } } file.close(); diff --git a/src/mobility/position.cc b/src/mobility/position.cc deleted file mode 100644 index 2418cb61e..000000000 --- a/src/mobility/position.cc +++ /dev/null @@ -1,48 +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 - */ -#include "position.h" -#include - -namespace ns3 { - - -Position::Position (double _x, double _y, double _z) - : x (_x), - y (_y), - z (_z) -{} - -Position::Position () - : x (0.0), - y (0.0), - z (0.0) -{} - -double -CalculateDistance (const Position &a, const Position &b) -{ - double dx = b.x - a.x; - double dy = b.y - a.y; - double dz = b.z - a.z; - double distance = std::sqrt (dx * dx + dy * dy + dz * dz); - return distance; -} - -} // namespace ns3 diff --git a/src/mobility/position.h b/src/mobility/position.h deleted file mode 100644 index 08ab9a134..000000000 --- a/src/mobility/position.h +++ /dev/null @@ -1,63 +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 - */ -#ifndef POSITION_H -#define POSITION_H - -namespace ns3 { - -/** - * \brief a 3d cartesian position vector - * - * Unit is meters. - */ -class Position -{ -public: - /** - * \param _x x coordinate of position vector - * \param _y y coordinate of position vector - * \param _z z coordinate of position vector - * - * Create position vector (_x, _y, _z) - */ - Position (double _x, double _y, double _z); - /** - * Create position vector (0.0, 0.0, 0.0) - */ - Position (); - /** - * x coordinate of position vector - */ - double x; - /** - * y coordinate of position vector - */ - double y; - /** - * z coordinate of position vector - */ - double z; -}; - -double CalculateDistance (const Position &a, const Position &b); - -} // namespace ns3 - -#endif /* POSITION_H */ diff --git a/src/mobility/random-direction-2d-mobility-model.cc b/src/mobility/random-direction-2d-mobility-model.cc index 508478d18..8163aee53 100644 --- a/src/mobility/random-direction-2d-mobility-model.cc +++ b/src/mobility/random-direction-2d-mobility-model.cc @@ -153,12 +153,12 @@ RandomDirection2dMobilityModel::SetDirectionAndSpeed (double direction) { NS_LOG_FUNCTION; double speed = m_parameters->m_speedVariable->GetValue (); - const Speed vector (std::cos (direction) * speed, - std::sin (direction) * speed, - 0.0); - Position position = m_helper.GetCurrentPosition (m_parameters->m_bounds); + const Vector vector (std::cos (direction) * speed, + std::sin (direction) * speed, + 0.0); + Vector position = m_helper.GetCurrentPosition (m_parameters->m_bounds); m_helper.Reset (vector); - Position next = m_parameters->m_bounds.CalculateIntersection (position, vector); + Vector next = m_parameters->m_bounds.CalculateIntersection (position, vector); Time delay = Seconds (CalculateDistance (position, next) / speed); m_event = Simulator::Schedule (delay, &RandomDirection2dMobilityModel::BeginPause, this); @@ -169,7 +169,7 @@ RandomDirection2dMobilityModel::ResetDirectionAndSpeed (void) { double direction = UniformVariable::GetSingleValue (0, PI); - Position position = m_helper.GetCurrentPosition (m_parameters->m_bounds); + Vector position = m_helper.GetCurrentPosition (m_parameters->m_bounds); switch (m_parameters->m_bounds.GetClosestSide (position)) { case Rectangle::RIGHT: @@ -187,19 +187,19 @@ RandomDirection2dMobilityModel::ResetDirectionAndSpeed (void) } SetDirectionAndSpeed (direction); } -Position +Vector RandomDirection2dMobilityModel::DoGetPosition (void) const { return m_helper.GetCurrentPosition (m_parameters->m_bounds); } void -RandomDirection2dMobilityModel::DoSetPosition (const Position &position) +RandomDirection2dMobilityModel::DoSetPosition (const Vector &position) { m_helper.InitializePosition (position); Simulator::Remove (m_event); m_event = Simulator::ScheduleNow (&RandomDirection2dMobilityModel::Start, this); } -Speed +Vector RandomDirection2dMobilityModel::DoGetSpeed (void) const { return m_helper.GetSpeed (); diff --git a/src/mobility/random-direction-2d-mobility-model.h b/src/mobility/random-direction-2d-mobility-model.h index 7c5520a35..8ebc21100 100644 --- a/src/mobility/random-direction-2d-mobility-model.h +++ b/src/mobility/random-direction-2d-mobility-model.h @@ -106,9 +106,9 @@ class RandomDirection2dMobilityModel : public MobilityModel void SetDirectionAndSpeed (double direction); void InitializeDirectionAndSpeed (void); virtual void DoDispose (void); - virtual Position DoGetPosition (void) const; - virtual void DoSetPosition (const Position &position); - virtual Speed DoGetSpeed (void) const; + virtual Vector DoGetPosition (void) const; + virtual void DoSetPosition (const Vector &position); + virtual Vector DoGetSpeed (void) const; static const double PI; Ptr m_parameters; diff --git a/src/mobility/random-position.cc b/src/mobility/random-position.cc index 4e2a79f69..2dab23144 100644 --- a/src/mobility/random-position.cc +++ b/src/mobility/random-position.cc @@ -91,12 +91,12 @@ RandomRectanglePosition::~RandomRectanglePosition () m_x = 0; m_y = 0; } -Position +Vector RandomRectanglePosition::Get (void) const { double x = m_x->GetValue (); double y = m_y->GetValue (); - return Position (x, y, 0.0); + return Vector (x, y, 0.0); } RandomDiscPosition::RandomDiscPosition () @@ -120,7 +120,7 @@ RandomDiscPosition::~RandomDiscPosition () m_theta = 0; m_rho = 0; } -Position +Vector RandomDiscPosition::Get (void) const { double theta = m_theta->GetValue (); @@ -128,7 +128,7 @@ RandomDiscPosition::Get (void) const double x = m_x + std::cos (theta) * rho; double y = m_y + std::sin (theta) * rho; NS_LOG_DEBUG ("Disc position x=" << x << ", y=" << y); - return Position (x, y, 0.0); + return Vector (x, y, 0.0); } diff --git a/src/mobility/random-position.h b/src/mobility/random-position.h index 04a5b6890..aa4b5a14b 100644 --- a/src/mobility/random-position.h +++ b/src/mobility/random-position.h @@ -22,7 +22,7 @@ #include "ns3/object.h" #include "ns3/component-manager.h" -#include "position.h" +#include "vector.h" namespace ns3 { @@ -42,7 +42,7 @@ public: /** * \returns the next randomly-choosen position. */ - virtual Position Get (void) const = 0; + virtual Vector Get (void) const = 0; }; /** @@ -67,7 +67,7 @@ public: RandomRectanglePosition (const RandomVariable &x, const RandomVariable &y); virtual ~RandomRectanglePosition (); - virtual Position Get (void) const; + virtual Vector Get (void) const; private: RandomVariable *m_x; RandomVariable *m_y; @@ -102,7 +102,7 @@ public: const RandomVariable &rho, double x, double y); virtual ~RandomDiscPosition (); - virtual Position Get (void) const; + virtual Vector Get (void) const; private: RandomVariable *m_theta; RandomVariable *m_rho; diff --git a/src/mobility/random-topology.cc b/src/mobility/random-topology.cc index 2e044cce9..64469053b 100644 --- a/src/mobility/random-topology.cc +++ b/src/mobility/random-topology.cc @@ -70,7 +70,7 @@ RandomTopology::LayoutOne (Ptr object) Ptr mobility = ComponentManager::Create (m_mobilityModel, MobilityModel::iid); object->AddInterface (mobility); - Position position = m_positionModel->Get (); + Vector position = m_positionModel->Get (); mobility->SetPosition (position); } diff --git a/src/mobility/random-walk-2d-mobility-model.cc b/src/mobility/random-walk-2d-mobility-model.cc index 0c2304c62..6f1e93aee 100644 --- a/src/mobility/random-walk-2d-mobility-model.cc +++ b/src/mobility/random-walk-2d-mobility-model.cc @@ -143,9 +143,9 @@ RandomWalk2dMobilityModel::Start (void) { double speed = m_parameters->m_speed->GetValue (); double direction = m_parameters->m_direction->GetValue (); - Speed vector (std::cos (direction) * speed, - std::sin (direction) * speed, - 0.0); + Vector vector (std::cos (direction) * speed, + std::sin (direction) * speed, + 0.0); m_helper.Reset (vector); Time delayLeft; @@ -163,11 +163,11 @@ RandomWalk2dMobilityModel::Start (void) void RandomWalk2dMobilityModel::DoWalk (Time delayLeft) { - Position position = m_helper.GetCurrentPosition (); - Speed speed = m_helper.GetSpeed (); - Position nextPosition = position; - nextPosition.x += speed.dx * delayLeft.GetSeconds (); - nextPosition.y += speed.dy * delayLeft.GetSeconds (); + Vector position = m_helper.GetCurrentPosition (); + Vector speed = m_helper.GetSpeed (); + Vector nextPosition = position; + nextPosition.x += speed.x * delayLeft.GetSeconds (); + nextPosition.y += speed.y * delayLeft.GetSeconds (); if (m_parameters->m_bounds.IsInside (nextPosition)) { m_event = Simulator::Schedule (delayLeft, &RandomWalk2dMobilityModel::Start, this); @@ -175,7 +175,7 @@ RandomWalk2dMobilityModel::DoWalk (Time delayLeft) else { nextPosition = m_parameters->m_bounds.CalculateIntersection (position, speed); - Time delay = Seconds ((nextPosition.x - position.x) / speed.dx); + Time delay = Seconds ((nextPosition.x - position.x) / speed.x); m_event = Simulator::Schedule (delay, &RandomWalk2dMobilityModel::Rebound, this, delayLeft - delay); } @@ -185,17 +185,17 @@ RandomWalk2dMobilityModel::DoWalk (Time delayLeft) void RandomWalk2dMobilityModel::Rebound (Time delayLeft) { - Position position = m_helper.GetCurrentPosition (m_parameters->m_bounds); - Speed speed = m_helper.GetSpeed (); + Vector position = m_helper.GetCurrentPosition (m_parameters->m_bounds); + Vector speed = m_helper.GetSpeed (); switch (m_parameters->m_bounds.GetClosestSide (position)) { case Rectangle::RIGHT: case Rectangle::LEFT: - speed.dx = - speed.dx; + speed.x = - speed.x; break; case Rectangle::TOP: case Rectangle::BOTTOM: - speed.dy = - speed.dy; + speed.y = - speed.y; break; } m_helper.Reset (speed); @@ -209,20 +209,20 @@ RandomWalk2dMobilityModel::DoDispose (void) // chain up MobilityModel::DoDispose (); } -Position +Vector RandomWalk2dMobilityModel::DoGetPosition (void) const { return m_helper.GetCurrentPosition (m_parameters->m_bounds); } void -RandomWalk2dMobilityModel::DoSetPosition (const Position &position) +RandomWalk2dMobilityModel::DoSetPosition (const Vector &position) { NS_ASSERT (m_parameters->m_bounds.IsInside (position)); m_helper.InitializePosition (position); Simulator::Remove (m_event); m_event = Simulator::ScheduleNow (&RandomWalk2dMobilityModel::Start, this); } -Speed +Vector RandomWalk2dMobilityModel::DoGetSpeed (void) const { return m_helper.GetSpeed (); diff --git a/src/mobility/random-walk-2d-mobility-model.h b/src/mobility/random-walk-2d-mobility-model.h index aeaa6625c..f018d8b13 100644 --- a/src/mobility/random-walk-2d-mobility-model.h +++ b/src/mobility/random-walk-2d-mobility-model.h @@ -132,9 +132,9 @@ class RandomWalk2dMobilityModel : public MobilityModel void Rebound (Time timeLeft); void DoWalk (Time timeLeft); virtual void DoDispose (void); - virtual Position DoGetPosition (void) const; - virtual void DoSetPosition (const Position &position); - virtual Speed DoGetSpeed (void) const; + virtual Vector DoGetPosition (void) const; + virtual void DoSetPosition (const Vector &position); + virtual Vector DoGetSpeed (void) const; StaticSpeedHelper m_helper; EventId m_event; diff --git a/src/mobility/random-waypoint-mobility-model.cc b/src/mobility/random-waypoint-mobility-model.cc index 420903123..1807f5227 100644 --- a/src/mobility/random-waypoint-mobility-model.cc +++ b/src/mobility/random-waypoint-mobility-model.cc @@ -117,15 +117,15 @@ RandomWaypointMobilityModel::RandomWaypointMobilityModel (Ptrm_position->Get (); + Vector m_current = m_helper.GetCurrentPosition (); + Vector destination = m_parameters->m_position->Get (); double speed = m_parameters->m_speed->GetValue (); double dx = (destination.x - m_current.x); double dy = (destination.y - m_current.y); double dz = (destination.z - m_current.z); double k = speed / std::sqrt (dx*dx + dy*dy + dz*dz); - m_helper.Reset (Speed (k*dx, k*dy, k*dz)); + m_helper.Reset (Vector (k*dx, k*dy, k*dz)); Time travelDelay = Seconds (CalculateDistance (destination, m_current) / speed); m_event = Simulator::Schedule (travelDelay, &RandomWaypointMobilityModel::Start, this); @@ -141,19 +141,19 @@ RandomWaypointMobilityModel::Start (void) m_event = Simulator::Schedule (pause, &RandomWaypointMobilityModel::BeginWalk, this); } -Position +Vector RandomWaypointMobilityModel::DoGetPosition (void) const { return m_helper.GetCurrentPosition (); } void -RandomWaypointMobilityModel::DoSetPosition (const Position &position) +RandomWaypointMobilityModel::DoSetPosition (const Vector &position) { m_helper.InitializePosition (position); Simulator::Remove (m_event); Simulator::ScheduleNow (&RandomWaypointMobilityModel::Start, this); } -Speed +Vector RandomWaypointMobilityModel::DoGetSpeed (void) const { return m_helper.GetSpeed (); diff --git a/src/mobility/random-waypoint-mobility-model.h b/src/mobility/random-waypoint-mobility-model.h index a45061a25..922d0310b 100644 --- a/src/mobility/random-waypoint-mobility-model.h +++ b/src/mobility/random-waypoint-mobility-model.h @@ -98,9 +98,9 @@ public: private: void Start (void); void BeginWalk (void); - virtual Position DoGetPosition (void) const; - virtual void DoSetPosition (const Position &position); - virtual Speed DoGetSpeed (void) const; + virtual Vector DoGetPosition (void) const; + virtual void DoSetPosition (const Vector &position); + virtual Vector DoGetSpeed (void) const; StaticSpeedHelper m_helper; Ptr m_parameters; diff --git a/src/mobility/rectangle.cc b/src/mobility/rectangle.cc index 2f10a7d43..e39f8ae74 100644 --- a/src/mobility/rectangle.cc +++ b/src/mobility/rectangle.cc @@ -18,8 +18,7 @@ * Author: Mathieu Lacage */ #include "rectangle.h" -#include "position.h" -#include "speed.h" +#include "vector.h" #include "ns3/assert.h" #include #include @@ -42,7 +41,7 @@ Rectangle::Rectangle () {} bool -Rectangle::IsInside (const Position &position) const +Rectangle::IsInside (const Vector &position) const { return position.x <= this->xMax && position.x >= this->xMin && @@ -50,7 +49,7 @@ Rectangle::IsInside (const Position &position) const } Rectangle::Side -Rectangle::GetClosestSide (const Position &position) const +Rectangle::GetClosestSide (const Vector &position) const { double xMinDist = std::abs (position.x - this->xMin); double xMaxDist = std::abs (this->xMax - position.x); @@ -82,38 +81,38 @@ Rectangle::GetClosestSide (const Position &position) const } } -Position -Rectangle::CalculateIntersection (const Position ¤t, const Speed &speed) const +Vector +Rectangle::CalculateIntersection (const Vector ¤t, const Vector &speed) const { - double xMaxY = current.y + (this->xMax - current.x) / speed.dx * speed.dy; - double xMinY = current.y + (this->xMin - current.x) / speed.dx * speed.dy; - double yMaxX = current.x + (this->yMax - current.y) / speed.dy * speed.dx; - double yMinX = current.x + (this->yMin - current.y) / speed.dy * speed.dx; + double xMaxY = current.y + (this->xMax - current.x) / speed.x * speed.y; + double xMinY = current.y + (this->xMin - current.x) / speed.x * speed.y; + double yMaxX = current.x + (this->yMax - current.y) / speed.y * speed.x; + double yMinX = current.x + (this->yMin - current.y) / speed.y * speed.x; bool xMaxYOk = (xMaxY <= this->yMax && xMaxY >= this->yMin); bool xMinYOk = (xMinY <= this->yMax && xMinY >= this->yMin); bool yMaxXOk = (yMaxX <= this->xMax && yMaxX >= this->xMin); bool yMinXOk = (yMinX <= this->xMax && yMinX >= this->xMin); - if (xMaxYOk && speed.dx >= 0) + if (xMaxYOk && speed.x >= 0) { - return Position (this->xMax, xMaxY, 0.0); + return Vector (this->xMax, xMaxY, 0.0); } - else if (xMinYOk && speed.dx <= 0) + else if (xMinYOk && speed.x <= 0) { - return Position (this->xMin, xMinY, 0.0); + return Vector (this->xMin, xMinY, 0.0); } - else if (yMaxXOk && speed.dy >= 0) + else if (yMaxXOk && speed.y >= 0) { - return Position (yMaxX, this->yMax, 0.0); + return Vector (yMaxX, this->yMax, 0.0); } - else if (yMinXOk && speed.dy <= 0) + else if (yMinXOk && speed.y <= 0) { - return Position (yMinX, this->yMin, 0.0); + return Vector (yMinX, this->yMin, 0.0); } else { NS_ASSERT (false); // quiet compiler - return Position (0.0, 0.0, 0.0); + return Vector (0.0, 0.0, 0.0); } } diff --git a/src/mobility/rectangle.h b/src/mobility/rectangle.h index df519b545..d61620960 100644 --- a/src/mobility/rectangle.h +++ b/src/mobility/rectangle.h @@ -22,8 +22,7 @@ namespace ns3 { -class Position; -class Speed; +class Vector; /** * \brief a 2d rectangle @@ -51,9 +50,9 @@ public: * Create a zero-sized rectangle located at coordinates (0.0,0.0) */ Rectangle (); - bool IsInside (const Position &position) const; - Side GetClosestSide (const Position &position) const; - Position CalculateIntersection (const Position ¤t, const Speed &speed) const; + bool IsInside (const Vector &position) const; + Side GetClosestSide (const Vector &position) const; + Vector CalculateIntersection (const Vector ¤t, const Vector &speed) const; double xMin; double xMax; diff --git a/src/mobility/speed.cc b/src/mobility/speed.cc deleted file mode 100644 index c6abd0c1d..000000000 --- a/src/mobility/speed.cc +++ /dev/null @@ -1,36 +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 - */ -#include "speed.h" - -namespace ns3 { - -Speed::Speed (double _dx, double _dy, double _dz) - : dx (_dx), - dy (_dy), - dz (_dz) -{} - -Speed::Speed () - : dx (0.0), - dy (0.0), - dz (0.0) -{} - -} // namespace ns3 diff --git a/src/mobility/speed.h b/src/mobility/speed.h deleted file mode 100644 index d64b1e63b..000000000 --- a/src/mobility/speed.h +++ /dev/null @@ -1,61 +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 - */ -#ifndef SPEED_H -#define SPEED_H - -namespace ns3 { - -/** - * \brief keep track of 3d cartesian speed vectors - * - * Unit is meters/s. - */ -class Speed -{ -public: - /** - * \param _dx x coordinate of speed vector - * \param _dy y coordinate of speed vector - * \param _dz z coordinate of speed vector - * - * Create speed vector (_dx, _dy, _dz) - */ - Speed (double _dx, double _dy, double _dz); - /** - * Create speed vector (0.0, 0.0, 0.0) - */ - Speed (); - /** - * x coordinate of speed vector - */ - double dx; - /** - * y coordinate of speed vector - */ - double dy; - /** - * z coordinate of speed vector - */ - double dz; -}; - -} // namespace ns3 - -#endif /* SPEED_H */ diff --git a/src/mobility/static-mobility-model.cc b/src/mobility/static-mobility-model.cc index 7297640c8..4729e2c3f 100644 --- a/src/mobility/static-mobility-model.cc +++ b/src/mobility/static-mobility-model.cc @@ -28,7 +28,7 @@ StaticMobilityModel::StaticMobilityModel () { SetInterfaceId (StaticMobilityModel::iid); } -StaticMobilityModel::StaticMobilityModel (const Position &position) +StaticMobilityModel::StaticMobilityModel (const Vector &position) : m_position (position) { SetInterfaceId (StaticMobilityModel::iid); @@ -36,21 +36,21 @@ StaticMobilityModel::StaticMobilityModel (const Position &position) StaticMobilityModel::~StaticMobilityModel () {} -Position +Vector StaticMobilityModel::DoGetPosition (void) const { return m_position; } void -StaticMobilityModel::DoSetPosition (const Position &position) +StaticMobilityModel::DoSetPosition (const Vector &position) { m_position = position; NotifyCourseChange (); } -Speed +Vector StaticMobilityModel::DoGetSpeed (void) const { - return Speed (); + return Vector (0.0, 0.0, 0.0); } }; // namespace ns3 diff --git a/src/mobility/static-mobility-model.h b/src/mobility/static-mobility-model.h index 6caba0367..3143097ba 100644 --- a/src/mobility/static-mobility-model.h +++ b/src/mobility/static-mobility-model.h @@ -44,15 +44,15 @@ public: * Create a position located at coordinates (x,y,z). * Unit is meters */ - StaticMobilityModel (const Position &position); + StaticMobilityModel (const Vector &position); virtual ~StaticMobilityModel (); private: - virtual Position DoGetPosition (void) const; - virtual void DoSetPosition (const Position &position); - virtual Speed DoGetSpeed (void) const; + virtual Vector DoGetPosition (void) const; + virtual void DoSetPosition (const Vector &position); + virtual Vector DoGetSpeed (void) const; - Position m_position; + Vector m_position; }; }; // namespace ns3 diff --git a/src/mobility/static-speed-helper.cc b/src/mobility/static-speed-helper.cc index b2d806ab8..9f91b87e2 100644 --- a/src/mobility/static-speed-helper.cc +++ b/src/mobility/static-speed-helper.cc @@ -25,40 +25,40 @@ namespace ns3 { StaticSpeedHelper::StaticSpeedHelper () {} -StaticSpeedHelper::StaticSpeedHelper (const Position &position) +StaticSpeedHelper::StaticSpeedHelper (const Vector &position) : m_position (position) {} -StaticSpeedHelper::StaticSpeedHelper (const Position &position, - const Speed &speed) +StaticSpeedHelper::StaticSpeedHelper (const Vector &position, + const Vector &speed) : m_position (position), m_speed (speed), m_paused (true) {} void -StaticSpeedHelper::InitializePosition (const Position &position) +StaticSpeedHelper::InitializePosition (const Vector &position) { m_position = position; - m_speed.dx = 0.0; - m_speed.dy = 0.0; - m_speed.dz = 0.0; + m_speed.x = 0.0; + m_speed.y = 0.0; + m_speed.z = 0.0; m_lastUpdate = Simulator::Now (); m_paused = true; } -Position +Vector StaticSpeedHelper::GetCurrentPosition (void) const { Update (); return m_position; } -Speed +Vector StaticSpeedHelper::GetSpeed (void) const { - return m_paused? Speed (0, 0, 0) : m_speed; + return m_paused? Vector (0.0, 0.0, 0.0) : m_speed; } void -StaticSpeedHelper::SetSpeed (const Speed &speed) +StaticSpeedHelper::SetSpeed (const Vector &speed) { Update (); m_speed = speed; @@ -76,13 +76,13 @@ StaticSpeedHelper::Update (void) const Time deltaTime = now - m_lastUpdate; m_lastUpdate = now; double deltaS = deltaTime.GetSeconds (); - m_position.x += m_speed.dx * deltaS; - m_position.y += m_speed.dy * deltaS; - m_position.z += m_speed.dz * deltaS; + m_position.x += m_speed.x * deltaS; + m_position.y += m_speed.y * deltaS; + m_position.z += m_speed.z * deltaS; } void -StaticSpeedHelper::Reset (const Speed &speed) +StaticSpeedHelper::Reset (const Vector &speed) { Update (); m_speed = speed; @@ -98,7 +98,7 @@ StaticSpeedHelper::UpdateFull (const Rectangle &bounds) const m_position.y = std::max (bounds.yMin, m_position.y); } -Position +Vector StaticSpeedHelper::GetCurrentPosition (const Rectangle &bounds) const { UpdateFull (bounds); diff --git a/src/mobility/static-speed-helper.h b/src/mobility/static-speed-helper.h index 343898f22..b641ed626 100644 --- a/src/mobility/static-speed-helper.h +++ b/src/mobility/static-speed-helper.h @@ -21,8 +21,7 @@ #define STATIC_SPEED_HELPER_H #include "ns3/nstime.h" -#include "position.h" -#include "speed.h" +#include "vector.h" namespace ns3 { @@ -32,16 +31,16 @@ class StaticSpeedHelper { public: StaticSpeedHelper (); - StaticSpeedHelper (const Position &position); - StaticSpeedHelper (const Position &position, - const Speed &speed); - void InitializePosition (const Position &position); + StaticSpeedHelper (const Vector &position); + StaticSpeedHelper (const Vector &position, + const Vector &speed); + void InitializePosition (const Vector &position); - void Reset (const Speed &speed); - Position GetCurrentPosition (const Rectangle &bounds) const; - Position GetCurrentPosition (void) const; - Speed GetSpeed (void) const; - void SetSpeed (const Speed &speed); + void Reset (const Vector &speed); + Vector GetCurrentPosition (const Rectangle &bounds) const; + Vector GetCurrentPosition (void) const; + Vector GetSpeed (void) const; + void SetSpeed (const Vector &speed); void Pause (void); void Unpause (void); @@ -49,8 +48,8 @@ class StaticSpeedHelper void Update (void) const; void UpdateFull (const Rectangle &rectangle) const; mutable Time m_lastUpdate; - mutable Position m_position; - Speed m_speed; + mutable Vector m_position; + Vector m_speed; bool m_paused; }; diff --git a/src/mobility/static-speed-mobility-model.cc b/src/mobility/static-speed-mobility-model.cc index c2c18ea2a..57e7e1e84 100644 --- a/src/mobility/static-speed-mobility-model.cc +++ b/src/mobility/static-speed-mobility-model.cc @@ -33,13 +33,13 @@ StaticSpeedMobilityModel::StaticSpeedMobilityModel () { SetInterfaceId (StaticSpeedMobilityModel::iid); } -StaticSpeedMobilityModel::StaticSpeedMobilityModel (const Position &position) +StaticSpeedMobilityModel::StaticSpeedMobilityModel (const Vector &position) : m_helper (position) { SetInterfaceId (StaticSpeedMobilityModel::iid); } -StaticSpeedMobilityModel::StaticSpeedMobilityModel (const Position &position, - const Speed &speed) +StaticSpeedMobilityModel::StaticSpeedMobilityModel (const Vector &position, + const Vector &speed) : m_helper (position, speed) { SetInterfaceId (StaticSpeedMobilityModel::iid); @@ -49,25 +49,25 @@ StaticSpeedMobilityModel::~StaticSpeedMobilityModel () {} void -StaticSpeedMobilityModel::SetSpeed (const Speed speed) +StaticSpeedMobilityModel::SetSpeed (const Vector &speed) { m_helper.SetSpeed (speed); NotifyCourseChange (); } -Position +Vector StaticSpeedMobilityModel::DoGetPosition (void) const { return m_helper.GetCurrentPosition (); } void -StaticSpeedMobilityModel::DoSetPosition (const Position &position) +StaticSpeedMobilityModel::DoSetPosition (const Vector &position) { m_helper.InitializePosition (position); NotifyCourseChange (); } -Speed +Vector StaticSpeedMobilityModel::DoGetSpeed (void) const { return m_helper.GetSpeed (); diff --git a/src/mobility/static-speed-mobility-model.h b/src/mobility/static-speed-mobility-model.h index d997d16f7..f6f1dbddb 100644 --- a/src/mobility/static-speed-mobility-model.h +++ b/src/mobility/static-speed-mobility-model.h @@ -25,7 +25,6 @@ #include "ns3/nstime.h" #include "ns3/component-manager.h" #include "static-speed-helper.h" -#include "speed.h" namespace ns3 { @@ -48,15 +47,15 @@ public: * Create a position located at coordinates (x,y,z) with * speed (0,0,0). */ - StaticSpeedMobilityModel (const Position &position); + StaticSpeedMobilityModel (const Vector &position); /** * * Create a position located at coordinates (x,y,z) with * speed (dx,dy,dz). * Unit is meters and meters/s */ - StaticSpeedMobilityModel (const Position &position, - const Speed &speed); + StaticSpeedMobilityModel (const Vector &position, + const Vector &speed); virtual ~StaticSpeedMobilityModel (); /** @@ -65,11 +64,11 @@ public: * Set the current speed now to (dx,dy,dz) * Unit is meters/s */ - void SetSpeed (const Speed speed); + void SetSpeed (const Vector &speed); private: - virtual Position DoGetPosition (void) const; - virtual void DoSetPosition (const Position &position); - virtual Speed DoGetSpeed (void) const; + virtual Vector DoGetPosition (void) const; + virtual void DoSetPosition (const Vector &position); + virtual Vector DoGetSpeed (void) const; void Update (void) const; StaticSpeedHelper m_helper; }; diff --git a/src/mobility/wscript b/src/mobility/wscript index 2833ce1e0..8b5256a77 100644 --- a/src/mobility/wscript +++ b/src/mobility/wscript @@ -8,12 +8,10 @@ def build(bld): 'hierarchical-mobility-model.cc', 'mobility-model.cc', 'mobility-model-notifier.cc', - 'position.cc', 'random-position.cc', 'random-topology.cc', 'rectangle.cc', 'rectangle-default-value.cc', - 'speed.cc', 'static-mobility-model.cc', 'static-speed-helper.cc', 'static-speed-mobility-model.cc', @@ -30,12 +28,10 @@ def build(bld): 'hierarchical-mobility-model.h', 'mobility-model.h', 'mobility-model-notifier.h', - 'position.h', 'random-position.h', 'random-topology.h', 'rectangle.h', 'rectangle-default-value.h', - 'speed.h', 'static-mobility-model.h', 'static-speed-helper.h', 'static-speed-mobility-model.h', diff --git a/utils/mobility-visualizer-model.cc b/utils/mobility-visualizer-model.cc index 94f46538c..b3c7773d3 100644 --- a/utils/mobility-visualizer-model.cc +++ b/utils/mobility-visualizer-model.cc @@ -48,15 +48,15 @@ Sample () { Ptr node = *nodeIter; Ptr mobility = node->QueryInterface (MobilityModel::iid); - Position pos = mobility->GetPosition (); - Speed vel = mobility->GetSpeed (); + Vector pos = mobility->GetPosition (); + Vector vel = mobility->GetSpeed (); NodeUpdate update; update.node = PeekPointer (node); update.x = pos.x; update.y = pos.y; - update.vx = vel.dx; - update.vy = vel.dy; + update.vx = vel.x; + update.vy = vel.y; data->updateList.push_back (update); } data->time = Simulator::Now ().GetSeconds (); From 99fca41f027082b79e33a7a4236d04a80c6420d4 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 8 Nov 2007 12:36:15 +0100 Subject: [PATCH 31/67] GetSpeed -> GetVelocity --- samples/main-random-walk.cc | 2 +- src/mobility/hierarchical-mobility-model.cc | 6 +++--- src/mobility/hierarchical-mobility-model.h | 2 +- src/mobility/mobility-model.cc | 4 ++-- src/mobility/mobility-model.h | 4 ++-- src/mobility/random-direction-2d-mobility-model.cc | 4 ++-- src/mobility/random-direction-2d-mobility-model.h | 2 +- src/mobility/random-walk-2d-mobility-model.cc | 8 ++++---- src/mobility/random-walk-2d-mobility-model.h | 2 +- src/mobility/random-waypoint-mobility-model.cc | 4 ++-- src/mobility/random-waypoint-mobility-model.h | 2 +- src/mobility/static-mobility-model.cc | 2 +- src/mobility/static-mobility-model.h | 2 +- src/mobility/static-speed-helper.cc | 2 +- src/mobility/static-speed-helper.h | 2 +- src/mobility/static-speed-mobility-model.cc | 4 ++-- src/mobility/static-speed-mobility-model.h | 2 +- utils/mobility-visualizer-model.cc | 2 +- 18 files changed, 28 insertions(+), 28 deletions(-) diff --git a/samples/main-random-walk.cc b/samples/main-random-walk.cc index 2fa095d4e..c4a0db34f 100644 --- a/samples/main-random-walk.cc +++ b/samples/main-random-walk.cc @@ -19,7 +19,7 @@ static void CourseChange (ns3::TraceContext const&, Ptr mobility) { Vector pos = mobility->GetPosition (); - Vector vel = mobility->GetSpeed (); + Vector vel = mobility->GetVelocity (); std::cout << Simulator::Now () << ", model=" << mobility << ", POS: x=" << pos.x << ", y=" << pos.y << ", z=" << pos.z << "; VEL:" << vel.x << ", y=" << vel.y << ", z=" << vel.z << std::endl; diff --git a/src/mobility/hierarchical-mobility-model.cc b/src/mobility/hierarchical-mobility-model.cc index a01ba4821..3f72ba1e7 100644 --- a/src/mobility/hierarchical-mobility-model.cc +++ b/src/mobility/hierarchical-mobility-model.cc @@ -77,10 +77,10 @@ HierarchicalMobilityModel::DoSetPosition (const Vector &position) m_child->SetPosition (childPosition); } Vector -HierarchicalMobilityModel::DoGetSpeed (void) const +HierarchicalMobilityModel::DoGetVelocity (void) const { - Vector parentSpeed = m_parent->GetSpeed (); - Vector childSpeed = m_child->GetSpeed (); + Vector parentSpeed = m_parent->GetVelocity (); + Vector childSpeed = m_child->GetVelocity (); Vector speed (parentSpeed.x + childSpeed.x, parentSpeed.y + childSpeed.y, parentSpeed.z + childSpeed.z); diff --git a/src/mobility/hierarchical-mobility-model.h b/src/mobility/hierarchical-mobility-model.h index c454e043c..f864289f5 100644 --- a/src/mobility/hierarchical-mobility-model.h +++ b/src/mobility/hierarchical-mobility-model.h @@ -60,7 +60,7 @@ public: private: virtual Vector DoGetPosition (void) const; virtual void DoSetPosition (const Vector &position); - virtual Vector DoGetSpeed (void) const; + virtual Vector DoGetVelocity (void) const; void ParentChanged (const TraceContext &context, Ptr model); void ChildChanged (const TraceContext &context, Ptr model); diff --git a/src/mobility/mobility-model.cc b/src/mobility/mobility-model.cc index 0e4ef568f..c08d51619 100644 --- a/src/mobility/mobility-model.cc +++ b/src/mobility/mobility-model.cc @@ -39,9 +39,9 @@ MobilityModel::GetPosition (void) const return DoGetPosition (); } Vector -MobilityModel::GetSpeed (void) const +MobilityModel::GetVelocity (void) const { - return DoGetSpeed (); + return DoGetVelocity (); } void diff --git a/src/mobility/mobility-model.h b/src/mobility/mobility-model.h index 6702e10c5..e9722c111 100644 --- a/src/mobility/mobility-model.h +++ b/src/mobility/mobility-model.h @@ -50,7 +50,7 @@ public: /** * \returns the current position. */ - Vector GetSpeed (void) const; + Vector GetVelocity (void) const; /** * \param position a reference to another mobility model * \returns the distance between the two objects. Unit is meters. @@ -83,7 +83,7 @@ private: * Concrete subclasses of this base class must * implement this method. */ - virtual Vector DoGetSpeed (void) const = 0; + virtual Vector DoGetVelocity (void) const = 0; }; }; // namespace ns3 diff --git a/src/mobility/random-direction-2d-mobility-model.cc b/src/mobility/random-direction-2d-mobility-model.cc index 8163aee53..cb91c7144 100644 --- a/src/mobility/random-direction-2d-mobility-model.cc +++ b/src/mobility/random-direction-2d-mobility-model.cc @@ -200,9 +200,9 @@ RandomDirection2dMobilityModel::DoSetPosition (const Vector &position) m_event = Simulator::ScheduleNow (&RandomDirection2dMobilityModel::Start, this); } Vector -RandomDirection2dMobilityModel::DoGetSpeed (void) const +RandomDirection2dMobilityModel::DoGetVelocity (void) const { - return m_helper.GetSpeed (); + return m_helper.GetVelocity (); } diff --git a/src/mobility/random-direction-2d-mobility-model.h b/src/mobility/random-direction-2d-mobility-model.h index 8ebc21100..24f0fd94e 100644 --- a/src/mobility/random-direction-2d-mobility-model.h +++ b/src/mobility/random-direction-2d-mobility-model.h @@ -108,7 +108,7 @@ class RandomDirection2dMobilityModel : public MobilityModel virtual void DoDispose (void); virtual Vector DoGetPosition (void) const; virtual void DoSetPosition (const Vector &position); - virtual Vector DoGetSpeed (void) const; + virtual Vector DoGetVelocity (void) const; static const double PI; Ptr m_parameters; diff --git a/src/mobility/random-walk-2d-mobility-model.cc b/src/mobility/random-walk-2d-mobility-model.cc index 6f1e93aee..bf24e9003 100644 --- a/src/mobility/random-walk-2d-mobility-model.cc +++ b/src/mobility/random-walk-2d-mobility-model.cc @@ -164,7 +164,7 @@ void RandomWalk2dMobilityModel::DoWalk (Time delayLeft) { Vector position = m_helper.GetCurrentPosition (); - Vector speed = m_helper.GetSpeed (); + Vector speed = m_helper.GetVelocity (); Vector nextPosition = position; nextPosition.x += speed.x * delayLeft.GetSeconds (); nextPosition.y += speed.y * delayLeft.GetSeconds (); @@ -186,7 +186,7 @@ void RandomWalk2dMobilityModel::Rebound (Time delayLeft) { Vector position = m_helper.GetCurrentPosition (m_parameters->m_bounds); - Vector speed = m_helper.GetSpeed (); + Vector speed = m_helper.GetVelocity (); switch (m_parameters->m_bounds.GetClosestSide (position)) { case Rectangle::RIGHT: @@ -223,9 +223,9 @@ RandomWalk2dMobilityModel::DoSetPosition (const Vector &position) m_event = Simulator::ScheduleNow (&RandomWalk2dMobilityModel::Start, this); } Vector -RandomWalk2dMobilityModel::DoGetSpeed (void) const +RandomWalk2dMobilityModel::DoGetVelocity (void) const { - return m_helper.GetSpeed (); + return m_helper.GetVelocity (); } diff --git a/src/mobility/random-walk-2d-mobility-model.h b/src/mobility/random-walk-2d-mobility-model.h index f018d8b13..46b871753 100644 --- a/src/mobility/random-walk-2d-mobility-model.h +++ b/src/mobility/random-walk-2d-mobility-model.h @@ -134,7 +134,7 @@ class RandomWalk2dMobilityModel : public MobilityModel virtual void DoDispose (void); virtual Vector DoGetPosition (void) const; virtual void DoSetPosition (const Vector &position); - virtual Vector DoGetSpeed (void) const; + virtual Vector DoGetVelocity (void) const; StaticSpeedHelper m_helper; EventId m_event; diff --git a/src/mobility/random-waypoint-mobility-model.cc b/src/mobility/random-waypoint-mobility-model.cc index 1807f5227..01478cc6a 100644 --- a/src/mobility/random-waypoint-mobility-model.cc +++ b/src/mobility/random-waypoint-mobility-model.cc @@ -154,9 +154,9 @@ RandomWaypointMobilityModel::DoSetPosition (const Vector &position) Simulator::ScheduleNow (&RandomWaypointMobilityModel::Start, this); } Vector -RandomWaypointMobilityModel::DoGetSpeed (void) const +RandomWaypointMobilityModel::DoGetVelocity (void) const { - return m_helper.GetSpeed (); + return m_helper.GetVelocity (); } diff --git a/src/mobility/random-waypoint-mobility-model.h b/src/mobility/random-waypoint-mobility-model.h index 922d0310b..3a86f349a 100644 --- a/src/mobility/random-waypoint-mobility-model.h +++ b/src/mobility/random-waypoint-mobility-model.h @@ -100,7 +100,7 @@ private: void BeginWalk (void); virtual Vector DoGetPosition (void) const; virtual void DoSetPosition (const Vector &position); - virtual Vector DoGetSpeed (void) const; + virtual Vector DoGetVelocity (void) const; StaticSpeedHelper m_helper; Ptr m_parameters; diff --git a/src/mobility/static-mobility-model.cc b/src/mobility/static-mobility-model.cc index 4729e2c3f..6e39678df 100644 --- a/src/mobility/static-mobility-model.cc +++ b/src/mobility/static-mobility-model.cc @@ -48,7 +48,7 @@ StaticMobilityModel::DoSetPosition (const Vector &position) NotifyCourseChange (); } Vector -StaticMobilityModel::DoGetSpeed (void) const +StaticMobilityModel::DoGetVelocity (void) const { return Vector (0.0, 0.0, 0.0); } diff --git a/src/mobility/static-mobility-model.h b/src/mobility/static-mobility-model.h index 3143097ba..995cad598 100644 --- a/src/mobility/static-mobility-model.h +++ b/src/mobility/static-mobility-model.h @@ -50,7 +50,7 @@ public: private: virtual Vector DoGetPosition (void) const; virtual void DoSetPosition (const Vector &position); - virtual Vector DoGetSpeed (void) const; + virtual Vector DoGetVelocity (void) const; Vector m_position; }; diff --git a/src/mobility/static-speed-helper.cc b/src/mobility/static-speed-helper.cc index 9f91b87e2..d781494f6 100644 --- a/src/mobility/static-speed-helper.cc +++ b/src/mobility/static-speed-helper.cc @@ -53,7 +53,7 @@ StaticSpeedHelper::GetCurrentPosition (void) const } Vector -StaticSpeedHelper::GetSpeed (void) const +StaticSpeedHelper::GetVelocity (void) const { return m_paused? Vector (0.0, 0.0, 0.0) : m_speed; } diff --git a/src/mobility/static-speed-helper.h b/src/mobility/static-speed-helper.h index b641ed626..d743460f4 100644 --- a/src/mobility/static-speed-helper.h +++ b/src/mobility/static-speed-helper.h @@ -39,7 +39,7 @@ class StaticSpeedHelper void Reset (const Vector &speed); Vector GetCurrentPosition (const Rectangle &bounds) const; Vector GetCurrentPosition (void) const; - Vector GetSpeed (void) const; + Vector GetVelocity (void) const; void SetSpeed (const Vector &speed); void Pause (void); void Unpause (void); diff --git a/src/mobility/static-speed-mobility-model.cc b/src/mobility/static-speed-mobility-model.cc index 57e7e1e84..779aeae9a 100644 --- a/src/mobility/static-speed-mobility-model.cc +++ b/src/mobility/static-speed-mobility-model.cc @@ -68,9 +68,9 @@ StaticSpeedMobilityModel::DoSetPosition (const Vector &position) NotifyCourseChange (); } Vector -StaticSpeedMobilityModel::DoGetSpeed (void) const +StaticSpeedMobilityModel::DoGetVelocity (void) const { - return m_helper.GetSpeed (); + return m_helper.GetVelocity (); } }; // namespace ns3 diff --git a/src/mobility/static-speed-mobility-model.h b/src/mobility/static-speed-mobility-model.h index f6f1dbddb..81198d735 100644 --- a/src/mobility/static-speed-mobility-model.h +++ b/src/mobility/static-speed-mobility-model.h @@ -68,7 +68,7 @@ public: private: virtual Vector DoGetPosition (void) const; virtual void DoSetPosition (const Vector &position); - virtual Vector DoGetSpeed (void) const; + virtual Vector DoGetVelocity (void) const; void Update (void) const; StaticSpeedHelper m_helper; }; diff --git a/utils/mobility-visualizer-model.cc b/utils/mobility-visualizer-model.cc index b3c7773d3..8b48c6b69 100644 --- a/utils/mobility-visualizer-model.cc +++ b/utils/mobility-visualizer-model.cc @@ -49,7 +49,7 @@ Sample () Ptr node = *nodeIter; Ptr mobility = node->QueryInterface (MobilityModel::iid); Vector pos = mobility->GetPosition (); - Vector vel = mobility->GetSpeed (); + Vector vel = mobility->GetVelocity (); NodeUpdate update; update.node = PeekPointer (node); From c905f0658dc0ffbcb659069fb670d079abdded62 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 8 Nov 2007 12:39:21 +0100 Subject: [PATCH 32/67] dox typo --- src/mobility/mobility-model.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mobility/mobility-model.h b/src/mobility/mobility-model.h index e9722c111..e55b27988 100644 --- a/src/mobility/mobility-model.h +++ b/src/mobility/mobility-model.h @@ -48,7 +48,7 @@ public: */ void SetPosition (const Vector &position); /** - * \returns the current position. + * \returns the current velocity. */ Vector GetVelocity (void) const; /** @@ -78,7 +78,7 @@ private: */ virtual void DoSetPosition (const Vector &position) = 0; /** - * \returns the current speed. + * \returns the current velocity. * * Concrete subclasses of this base class must * implement this method. From c114ad9aa746d97d311a5e12a7c6bb26d9d61c4a Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Thu, 8 Nov 2007 23:08:00 -0800 Subject: [PATCH 33/67] minor fix for bug95; also const operators for DataRate --- src/common/data-rate.cc | 30 +++++++++++++++++++ src/common/data-rate.h | 6 ++++ src/devices/csma/csma-net-device.cc | 5 +++- .../point-to-point-net-device.cc | 5 +++- 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/common/data-rate.cc b/src/common/data-rate.cc index 832fa98cb..a472d10c2 100644 --- a/src/common/data-rate.cc +++ b/src/common/data-rate.cc @@ -150,31 +150,61 @@ bool DataRate::operator < (const DataRate& rhs) return m_bps (const DataRate& rhs) { return m_bps>rhs.m_bps; } +bool DataRate::operator > (const DataRate& rhs) const +{ + return m_bps>rhs.m_bps; +} + bool DataRate::operator >= (const DataRate& rhs) { return m_bps>=rhs.m_bps; } +bool DataRate::operator >= (const DataRate& rhs) const +{ + return m_bps>=rhs.m_bps; +} + bool DataRate::operator == (const DataRate& rhs) { return m_bps==rhs.m_bps; } +bool DataRate::operator == (const DataRate& rhs) const +{ + return m_bps==rhs.m_bps; +} + bool DataRate::operator != (const DataRate& rhs) { return m_bps!=rhs.m_bps; } +bool DataRate::operator != (const DataRate& rhs) const +{ + return m_bps!=rhs.m_bps; +} + double DataRate::CalculateTxTime(uint32_t bytes) const { return static_cast(bytes)*8/m_bps; diff --git a/src/common/data-rate.h b/src/common/data-rate.h index 1e5db50f9..1c1fb18d2 100644 --- a/src/common/data-rate.h +++ b/src/common/data-rate.h @@ -73,11 +73,17 @@ class DataRate DataRate (const std::string s); bool operator < (const DataRate& rhs); + bool operator < (const DataRate& rhs) const; bool operator <= (const DataRate& rhs); + bool operator <= (const DataRate& rhs) const; bool operator > (const DataRate& rhs); + bool operator > (const DataRate& rhs) const; bool operator >= (const DataRate& rhs); + bool operator >= (const DataRate& rhs) const; bool operator == (const DataRate& rhs); + bool operator == (const DataRate& rhs) const; bool operator != (const DataRate& rhs); + bool operator != (const DataRate& rhs) const; /** * \brief Calculate transmission time diff --git a/src/devices/csma/csma-net-device.cc b/src/devices/csma/csma-net-device.cc index 903bb6cb6..b636bd097 100644 --- a/src/devices/csma/csma-net-device.cc +++ b/src/devices/csma/csma-net-device.cc @@ -198,7 +198,10 @@ void CsmaNetDevice::SetDataRate (DataRate bps) { NS_LOG_FUNCTION; - m_bps = bps; + if (!m_channel || bps <= m_channel->GetDataRate ()) + { + m_bps = bps; + } } void 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 66525b7a1..8d3478751 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 @@ -151,7 +151,10 @@ void PointToPointNetDevice::DoDispose() void PointToPointNetDevice::SetDataRate(const DataRate& bps) { NS_LOG_FUNCTION; - m_bps = bps; + if (!m_channel || bps <= m_channel->GetDataRate ()) + { + m_bps = bps; + } } void PointToPointNetDevice::SetInterframeGap(const Time& t) From 79f4bb679e4b70f958ce185a2e8a7b21e3ae77fe Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Wed, 14 Nov 2007 21:17:43 -0800 Subject: [PATCH 34/67] get rid of non-const operators in DataRate --- src/common/data-rate.cc | 30 ------------------------------ src/common/data-rate.h | 6 ------ 2 files changed, 36 deletions(-) diff --git a/src/common/data-rate.cc b/src/common/data-rate.cc index a472d10c2..5e8358804 100644 --- a/src/common/data-rate.cc +++ b/src/common/data-rate.cc @@ -145,61 +145,31 @@ uint64_t DataRate::Parse(const std::string s) return v; } -bool DataRate::operator < (const DataRate& rhs) -{ - return m_bps (const DataRate& rhs) -{ - return m_bps>rhs.m_bps; -} - bool DataRate::operator > (const DataRate& rhs) const { return m_bps>rhs.m_bps; } -bool DataRate::operator >= (const DataRate& rhs) -{ - return m_bps>=rhs.m_bps; -} - bool DataRate::operator >= (const DataRate& rhs) const { return m_bps>=rhs.m_bps; } -bool DataRate::operator == (const DataRate& rhs) -{ - return m_bps==rhs.m_bps; -} - bool DataRate::operator == (const DataRate& rhs) const { return m_bps==rhs.m_bps; } -bool DataRate::operator != (const DataRate& rhs) -{ - return m_bps!=rhs.m_bps; -} - bool DataRate::operator != (const DataRate& rhs) const { return m_bps!=rhs.m_bps; diff --git a/src/common/data-rate.h b/src/common/data-rate.h index 1c1fb18d2..3607f4916 100644 --- a/src/common/data-rate.h +++ b/src/common/data-rate.h @@ -72,17 +72,11 @@ class DataRate */ DataRate (const std::string s); - bool operator < (const DataRate& rhs); bool operator < (const DataRate& rhs) const; - bool operator <= (const DataRate& rhs); bool operator <= (const DataRate& rhs) const; - bool operator > (const DataRate& rhs); bool operator > (const DataRate& rhs) const; - bool operator >= (const DataRate& rhs); bool operator >= (const DataRate& rhs) const; - bool operator == (const DataRate& rhs); bool operator == (const DataRate& rhs) const; - bool operator != (const DataRate& rhs); bool operator != (const DataRate& rhs) const; /** From a53e880346dfa26ef60f7ae0b8492d2335e50586 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Wed, 14 Nov 2007 21:29:27 -0800 Subject: [PATCH 35/67] Change default scheduler to Map from List (bug 90) --- src/simulator/scheduler-list.cc | 2 +- src/simulator/scheduler-map.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/simulator/scheduler-list.cc b/src/simulator/scheduler-list.cc index 8fa57f473..191eb49b0 100644 --- a/src/simulator/scheduler-list.cc +++ b/src/simulator/scheduler-list.cc @@ -32,7 +32,7 @@ static class SchedulerListFactory : public SchedulerFactory public: SchedulerListFactory () { - SchedulerFactory::AddDefault (this, "List"); + SchedulerFactory::Add (this, "List"); } private: virtual Scheduler *DoCreate (void) const diff --git a/src/simulator/scheduler-map.cc b/src/simulator/scheduler-map.cc index 5e20ff8d6..078167ec4 100644 --- a/src/simulator/scheduler-map.cc +++ b/src/simulator/scheduler-map.cc @@ -43,7 +43,7 @@ static class SchedulerMapFactory : public SchedulerFactory public: SchedulerMapFactory () { - SchedulerFactory::Add (this, "Map"); + SchedulerFactory::AddDefault (this, "Map"); } private: virtual Scheduler *DoCreate (void) const From 2e68155c6da9a0640c38a4f31bbf5f08871e2513 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Wed, 14 Nov 2007 21:59:14 -0800 Subject: [PATCH 36/67] nicer logging of parameters (bug 79 patch from Gustavo) --- samples/main-channel.cc | 8 +- src/applications/onoff/onoff-application.cc | 6 +- src/applications/udp-echo/udp-echo-client.cc | 12 +- src/applications/udp-echo/udp-echo-server.cc | 6 +- src/common/packet-metadata.cc | 4 +- src/core/log.cc | 5 + src/core/log.h | 108 +++++++++++++++++- src/devices/csma/csma-channel.cc | 22 ++-- src/devices/csma/csma-net-device.cc | 14 +-- .../point-to-point/point-to-point-channel.cc | 10 +- .../point-to-point-net-device.cc | 10 +- src/internet-node/arp-ipv4-interface.cc | 2 +- src/internet-node/ipv4-end-point-demux.cc | 20 ++-- src/internet-node/ipv4-interface.cc | 8 +- src/internet-node/ipv4-l3-protocol.cc | 85 ++++++-------- src/internet-node/ipv4-loopback-interface.cc | 2 +- src/internet-node/ipv4-static-routing.cc | 5 +- src/internet-node/udp-l4-protocol.cc | 17 ++- src/internet-node/udp-socket.cc | 14 +-- src/node/channel.cc | 4 +- src/node/drop-tail-queue.cc | 8 +- src/node/queue.cc | 8 +- src/routing/global-routing/candidate-queue.cc | 2 +- .../global-route-manager-impl.cc | 2 +- .../global-routing/global-router-interface.cc | 6 +- 25 files changed, 240 insertions(+), 148 deletions(-) diff --git a/samples/main-channel.cc b/samples/main-channel.cc index 99ceb04ec..025f1c3a8 100644 --- a/samples/main-channel.cc +++ b/samples/main-channel.cc @@ -73,7 +73,7 @@ FakeInternetNode::Doit (void) FakeInternetNode::UpperDoSendUp (Packet &p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); NS_LOG_INFO ("**** Receive inbound packet"); m_dtqInbound.Enqueue(p); return m_dtqInbound.Dequeue(p); @@ -83,7 +83,7 @@ FakeInternetNode::UpperDoSendUp (Packet &p) FakeInternetNode::UpperDoPull (Packet &p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); return m_dtqOutbound.Dequeue(p); } @@ -142,7 +142,7 @@ FakePhysicalLayer::LowerDoNotify (LayerConnectorUpper *upper) FakePhysicalLayer::UpperDoSendUp (Packet &p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); NS_ASSERT(m_upperPartner); return m_upperPartner->UpperSendUp(p); @@ -152,7 +152,7 @@ FakePhysicalLayer::UpperDoSendUp (Packet &p) FakePhysicalLayer::UpperDoPull (Packet &p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); return m_dtqOutbound.Dequeue(p); } diff --git a/src/applications/onoff/onoff-application.cc b/src/applications/onoff/onoff-application.cc index 29f3d9d04..8fa315fc9 100644 --- a/src/applications/onoff/onoff-application.cc +++ b/src/applications/onoff/onoff-application.cc @@ -109,7 +109,7 @@ void OnOffApplication::SetMaxBytes(uint32_t maxBytes) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << maxBytes << ")"); + NS_LOG_PARAMS (this << maxBytes); m_maxBytes = maxBytes; } @@ -117,7 +117,7 @@ void OnOffApplication::SetDefaultRate (const DataRate &rate) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &rate << ")"); + NS_LOG_PARAMS (&rate); g_defaultRate.SetValue (rate); } @@ -125,7 +125,7 @@ void OnOffApplication::SetDefaultSize (uint32_t size) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << size << ")"); + NS_LOG_PARAMS (size); g_defaultSize.SetValue (size); } diff --git a/src/applications/udp-echo/udp-echo-client.cc b/src/applications/udp-echo/udp-echo-client.cc index a5489ef2c..35a52e7b4 100644 --- a/src/applications/udp-echo/udp-echo-client.cc +++ b/src/applications/udp-echo/udp-echo-client.cc @@ -40,9 +40,8 @@ UdpEchoClient::UdpEchoClient ( Application(n) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << n << ", " << serverAddress << - ", " << serverPort << ", " << count << ", " << interval << - ", " << size << ")"); + NS_LOG_PARAMS (this << n << serverAddress << serverPort << count + << interval << size); Construct (n, serverAddress, serverPort, count, interval, size); } @@ -62,9 +61,8 @@ UdpEchoClient::Construct ( uint32_t size) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << n << ", " << serverAddress << - ", " << serverPort << ", " << count << ", " << interval << - ", " << size << ")"); + NS_LOG_PARAMS (this << n << serverAddress << serverPort + << count << interval << size); m_node = n; m_serverAddress = serverAddress; @@ -154,7 +152,7 @@ UdpEchoClient::Receive( const Address &from) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << socket << ", " << packet << ", " << from << ")"); + NS_LOG_PARAMS (this << socket << packet << from); if (InetSocketAddress::IsMatchingType (from)) { diff --git a/src/applications/udp-echo/udp-echo-server.cc b/src/applications/udp-echo/udp-echo-server.cc index 2538013cf..5d2d5b361 100644 --- a/src/applications/udp-echo/udp-echo-server.cc +++ b/src/applications/udp-echo/udp-echo-server.cc @@ -38,7 +38,7 @@ UdpEchoServer::UdpEchoServer ( Application(n) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << n << ", " << port << ")"); + NS_LOG_PARAMS (this << n << port); Construct (n, port); } @@ -54,7 +54,7 @@ UdpEchoServer::Construct ( uint16_t port) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << n << ", " << port << ")"); + NS_LOG_PARAMS (this << n << port); m_node = n; m_port = port; @@ -106,7 +106,7 @@ UdpEchoServer::Receive( const Address &from) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << socket << ", " << packet << ", " << from << ")"); + NS_LOG_PARAMS (this << socket << packet << from); if (InetSocketAddress::IsMatchingType (from)) { diff --git a/src/common/packet-metadata.cc b/src/common/packet-metadata.cc index ebb5850ba..0f6541f75 100644 --- a/src/common/packet-metadata.cc +++ b/src/common/packet-metadata.cc @@ -703,7 +703,7 @@ PacketMetadata::DoAddHeader (uint32_t uid, uint32_t size) m_metadataSkipped = true; return; } - NS_LOG_PARAM ("(uid=" << uid << ", size=" << size << ")"); + NS_LOG_PARAMS ("(uid=" << uid << ", size=" << size << ")"); struct PacketMetadata::SmallItem item; item.next = m_head; @@ -723,7 +723,7 @@ PacketMetadata::DoRemoveHeader (uint32_t uid, uint32_t size) m_metadataSkipped = true; return; } - NS_LOG_PARAM ("(uid=" << uid << ", size=" << size << ")"); + NS_LOG_PARAMS ("(uid=" << uid << ", size=" << size << ")"); struct PacketMetadata::SmallItem item; struct PacketMetadata::ExtraItem extraItem; uint32_t read = ReadItems (m_head, &item, &extraItem); diff --git a/src/core/log.cc b/src/core/log.cc index de43712cf..0edf8eabd 100644 --- a/src/core/log.cc +++ b/src/core/log.cc @@ -341,6 +341,11 @@ LogComponentPrintList (void) } } + +ParameterLogger g_parameterLogger; +EndParameterListStruct EndParameterList; + + } // namespace ns3 #endif // NS3_LOG_ENABLE diff --git a/src/core/log.h b/src/core/log.h index d4cf9542e..7d12c3009 100644 --- a/src/core/log.h +++ b/src/core/log.h @@ -75,6 +75,7 @@ #endif + /** * \ingroup logging * \param msg message to output @@ -88,6 +89,84 @@ #ifdef NS3_LOG_ENABLE + +namespace ns3 { + +struct EndParameterListStruct {}; +extern EndParameterListStruct EndParameterList; + +struct ParameterName +{ + const char *name; + ParameterName (const char *name_) : name (name_) {} +}; + +class ParameterLogger : public std::ostream +{ + int m_itemNumber; + const char *m_parameterName; +public: + ParameterLogger () + : m_itemNumber (0) + {} + + template + ParameterLogger& operator<< (T param) + { + switch (m_itemNumber) + { + case 0: // first item is actually the function name + if (m_parameterName) + { + std::clog << m_parameterName << "=" << param; + m_parameterName = 0; + } + else + { + std::clog << param; + } + break; + case 1: + if (m_parameterName) + { + std::clog << ", " << m_parameterName << "=" << param; + m_parameterName = 0; + } + else + { + std::clog << ", " << param; + } + break; + default: // parameter following a previous parameter + std::clog << ", " << param; + break; + } + m_itemNumber++; + return *this; + } + + ParameterLogger& + operator << (ParameterName paramName) + { + m_parameterName = paramName.name; + return *this; + } + + ParameterLogger& + operator << (EndParameterListStruct dummy) + { + std::clog << ")" << std::endl; + m_itemNumber = 0; + return *this; + } +}; + +extern ParameterLogger g_parameterLogger; + +} + + + /** * \param level the log level * \param msg the message to log @@ -142,8 +221,33 @@ #define NS_LOG_FUNCTION \ NS_LOG_F(ns3::LOG_FUNCTION) -#define NS_LOG_PARAM(msg) \ - NS_LOG(ns3::LOG_PARAM, msg) + + +#define NS_LOG_PARAMS(parameters) \ + do \ + { \ + if (g_log.IsEnabled (ns3::LOG_PARAM)) \ + { \ + g_parameterLogger << __PRETTY_FUNCTION__ \ + << parameters \ + << EndParameterList; \ + } \ + } \ + while (false) + + +#define NS_LOG_PARAMS_BEGIN() \ + if (g_log.IsEnabled (ns3::LOG_PARAM)) \ + { \ + g_parameterLogger << __PRETTY_FUNCTION__; + +#define NS_LOG_PARAM(param) \ + g_parameterLogger << ParameterName (#param) << param; + +#define NS_LOG_PARAMS_END() \ + g_parameterLogger << EndParameterList; \ + } + #define NS_LOG_LOGIC(msg) \ NS_LOG(ns3::LOG_LOGIC, msg) diff --git a/src/devices/csma/csma-channel.cc b/src/devices/csma/csma-channel.cc index 598884104..63ca27ea7 100644 --- a/src/devices/csma/csma-channel.cc +++ b/src/devices/csma/csma-channel.cc @@ -68,8 +68,7 @@ CsmaChannel::CsmaChannel( m_delay (delay) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << Channel::GetName() << ", " << bps.GetBitRate() << - ", " << delay << ")"); + NS_LOG_PARAMS (this << Channel::GetName() << bps.GetBitRate() << delay); Init(); } @@ -83,8 +82,7 @@ CsmaChannel::CsmaChannel( m_delay (delay) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << name << ", " << bps.GetBitRate() << ", " << delay << - ")"); + NS_LOG_PARAMS (this << name << bps.GetBitRate() << delay); Init(); } @@ -97,7 +95,7 @@ int32_t CsmaChannel::Attach(Ptr device) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << device << ")"); + NS_LOG_PARAMS (this << device); NS_ASSERT(device != 0); CsmaDeviceRec rec(device); @@ -110,7 +108,7 @@ bool CsmaChannel::Reattach(Ptr device) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << device << ")"); + NS_LOG_PARAMS (this << device); NS_ASSERT(device != 0); std::vector::iterator it; @@ -136,7 +134,7 @@ bool CsmaChannel::Reattach(uint32_t deviceId) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << deviceId << ")"); + NS_LOG_PARAMS (this << deviceId); if (deviceId < m_deviceList.size()) { @@ -158,7 +156,7 @@ bool CsmaChannel::Detach(uint32_t deviceId) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << deviceId << ")"); + NS_LOG_PARAMS (this << deviceId); if (deviceId < m_deviceList.size()) { @@ -189,7 +187,7 @@ bool CsmaChannel::Detach(Ptr device) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << device << ")"); + NS_LOG_PARAMS (this << device); NS_ASSERT(device != 0); std::vector::iterator it; @@ -208,7 +206,7 @@ bool CsmaChannel::TransmitStart(Packet& p, uint32_t srcId) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ", " << srcId << ")"); + NS_LOG_PARAMS (this << &p << srcId); NS_LOG_INFO ("UID is " << p.GetUid () << ")"); if (m_state != IDLE) @@ -240,7 +238,7 @@ bool CsmaChannel::TransmitEnd() { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &m_currentPkt << ", " << m_currentSrc << ")"); + NS_LOG_PARAMS (this << &m_currentPkt << m_currentSrc); NS_LOG_INFO ("UID is " << m_currentPkt.GetUid () << ")"); NS_ASSERT(m_state == TRANSMITTING); @@ -266,7 +264,7 @@ void CsmaChannel::PropagationCompleteEvent() { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &m_currentPkt << ")"); + NS_LOG_PARAMS (this << &m_currentPkt); NS_LOG_INFO ("UID is " << m_currentPkt.GetUid () << ")"); NS_ASSERT(m_state == PROPAGATING); diff --git a/src/devices/csma/csma-net-device.cc b/src/devices/csma/csma-net-device.cc index b636bd097..fef638271 100644 --- a/src/devices/csma/csma-net-device.cc +++ b/src/devices/csma/csma-net-device.cc @@ -87,7 +87,7 @@ CsmaNetDevice::CsmaNetDevice (Ptr node) m_receiveErrorModel (0) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << node << ")"); + NS_LOG_PARAMS (this << node); m_encapMode = IP_ARP; Init(true, true); } @@ -99,7 +99,7 @@ CsmaNetDevice::CsmaNetDevice (Ptr node, Mac48Address addr, m_receiveErrorModel (0) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << node << ")"); + NS_LOG_PARAMS (this << node); m_encapMode = encapMode; Init(true, true); @@ -112,7 +112,7 @@ CsmaNetDevice::CsmaNetDevice (Ptr node, Mac48Address addr, m_bps (DataRate (0xffffffff)) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << node << ")"); + NS_LOG_PARAMS (this << node); m_encapMode = encapMode; Init(sendEnable, receiveEnable); @@ -145,7 +145,7 @@ CsmaNetDevice& CsmaNetDevice::operator= (const CsmaNetDevice nd) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &nd << ")"); + NS_LOG_PARAMS (this << &nd); return *this; } */ @@ -513,7 +513,7 @@ bool CsmaNetDevice::Attach (Ptr ch) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &ch << ")"); + NS_LOG_PARAMS (this << &ch); m_channel = ch; @@ -532,7 +532,7 @@ void CsmaNetDevice::AddQueue (Ptr q) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << q << ")"); + NS_LOG_PARAMS (this << q); m_queue = q; } @@ -649,7 +649,7 @@ Address CsmaNetDevice::MakeMulticastAddress(Ipv4Address multicastGroup) const { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << multicastGroup << ")"); + NS_LOG_PARAMS (this << multicastGroup); // // First, get the generic multicast address. // diff --git a/src/devices/point-to-point/point-to-point-channel.cc b/src/devices/point-to-point/point-to-point-channel.cc index d224a8df8..3760848fb 100644 --- a/src/devices/point-to-point/point-to-point-channel.cc +++ b/src/devices/point-to-point/point-to-point-channel.cc @@ -52,8 +52,7 @@ PointToPointChannel::PointToPointChannel( m_nDevices(0) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << Channel::GetName() << ", " << bps.GetBitRate() << - ", " << delay << ")"); + NS_LOG_PARAMS (this << Channel::GetName() << bps.GetBitRate() << delay); } PointToPointChannel::PointToPointChannel( @@ -67,15 +66,14 @@ PointToPointChannel::PointToPointChannel( m_nDevices(0) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << name << ", " << bps.GetBitRate() << ", " << - delay << ")"); + NS_LOG_PARAMS (this << name << bps.GetBitRate() << delay); } void PointToPointChannel::Attach(Ptr device) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << device << ")"); + NS_LOG_PARAMS (this << device); NS_ASSERT(m_nDevices < N_DEVICES && "Only two devices permitted"); NS_ASSERT(device != 0); @@ -99,7 +97,7 @@ PointToPointChannel::TransmitStart(Packet& p, const Time& txTime) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ", " << src << ")"); + NS_LOG_PARAMS (this << &p << src); NS_LOG_LOGIC ("UID is " << p.GetUid () << ")"); NS_ASSERT(m_link[0].m_state != INITIALIZING); 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 8d3478751..e28b2350c 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 @@ -99,7 +99,7 @@ PointToPointNetDevice::PointToPointNetDevice (Ptr node, m_receiveErrorModel (0) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << node << ")"); + NS_LOG_PARAMS (this << node); // // XXX BUGBUG // @@ -201,7 +201,7 @@ bool PointToPointNetDevice::SendTo (const Packet& packet, const Address& dest, PointToPointNetDevice::TransmitStart (Packet &p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); NS_LOG_LOGIC ("UID is " << p.GetUid () << ")"); // // This function is called to start the process of transmitting a packet. @@ -262,7 +262,7 @@ bool PointToPointNetDevice::Attach (Ptr ch) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &ch << ")"); + NS_LOG_PARAMS (this << &ch); m_channel = ch; @@ -289,7 +289,7 @@ PointToPointNetDevice::Attach (Ptr ch) void PointToPointNetDevice::AddQueue (Ptr q) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << q << ")"); + NS_LOG_PARAMS (this << q); m_queue = q; } @@ -306,7 +306,7 @@ void PointToPointNetDevice::AddReceiveErrorModel (Ptr em) void PointToPointNetDevice::Receive (Packet& p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); uint16_t protocol = 0; Packet packet = p; diff --git a/src/internet-node/arp-ipv4-interface.cc b/src/internet-node/arp-ipv4-interface.cc index 8d80c5711..3dc95f5a4 100644 --- a/src/internet-node/arp-ipv4-interface.cc +++ b/src/internet-node/arp-ipv4-interface.cc @@ -64,7 +64,7 @@ void ArpIpv4Interface::SendTo (Packet p, Ipv4Address dest) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ", " << dest << ")"); + NS_LOG_PARAMS (this << &p << dest); NS_ASSERT (GetDevice () != 0); if (GetDevice ()->NeedsArp ()) diff --git a/src/internet-node/ipv4-end-point-demux.cc b/src/internet-node/ipv4-end-point-demux.cc index 8ad8c6a3f..ddf64cc51 100644 --- a/src/internet-node/ipv4-end-point-demux.cc +++ b/src/internet-node/ipv4-end-point-demux.cc @@ -93,7 +93,7 @@ Ipv4EndPoint * Ipv4EndPointDemux::Allocate (Ipv4Address address) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << this << ", " << address << ")"); + NS_LOG_PARAMS (this << address); uint16_t port = AllocateEphemeralPort (); if (port == 0) { @@ -117,7 +117,7 @@ Ipv4EndPoint * Ipv4EndPointDemux::Allocate (Ipv4Address address, uint16_t port) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << this << ", " << address << ", " << port << ")"); + NS_LOG_PARAMS (this << address << port); if (LookupLocal (address, port)) { NS_LOG_WARN ("Duplicate address/port; failing."); @@ -134,10 +134,7 @@ Ipv4EndPointDemux::Allocate (Ipv4Address localAddress, uint16_t localPort, Ipv4Address peerAddress, uint16_t peerPort) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(localAddress=" << localAddress - << ", localPort=" << localPort - << ", peerAddress=" << peerAddress - << ", peerPort=" << peerPort << ")"); + NS_LOG_PARAMS (this << localAddress << localPort << peerAddress << peerPort); for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) { if ((*i)->GetLocalPort () == localPort && @@ -189,8 +186,15 @@ Ipv4EndPointDemux::Lookup (Ipv4Address daddr, uint16_t dport, Ipv4EndPoint *generic = 0; EndPoints retval; - NS_LOG_PARAM ("(daddr=" << daddr << ", dport=" << dport - << ", saddr=" << saddr << ", sport=" << sport << ")"); + //NS_LOG_PARAMS (this << daddr << dport << saddr << sport); + NS_LOG_PARAMS_BEGIN (); + NS_LOG_PARAM (this); + NS_LOG_PARAM (daddr); + NS_LOG_PARAM (dport); + NS_LOG_PARAM (saddr); + NS_LOG_PARAM (sport); + NS_LOG_PARAM (incomingInterface); + NS_LOG_PARAMS_END (); for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) { diff --git a/src/internet-node/ipv4-interface.cc b/src/internet-node/ipv4-interface.cc index bcc346394..81e6bca65 100644 --- a/src/internet-node/ipv4-interface.cc +++ b/src/internet-node/ipv4-interface.cc @@ -41,7 +41,7 @@ Ipv4Interface::Ipv4Interface (Ptr nd) m_metric(1) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &nd << ")"); + NS_LOG_PARAMS (this << &nd); } Ipv4Interface::~Ipv4Interface () @@ -68,7 +68,7 @@ void Ipv4Interface::SetAddress (Ipv4Address a) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << a << ")"); + NS_LOG_PARAMS (this << a); m_address = a; } @@ -76,7 +76,7 @@ void Ipv4Interface::SetNetworkMask (Ipv4Mask mask) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << mask << ")"); + NS_LOG_PARAMS (this << mask); m_netmask = mask; } @@ -101,7 +101,7 @@ void Ipv4Interface::SetMetric (uint16_t metric) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << metric << ")"); + NS_LOG_PARAMS ("(" << metric << ")"); m_metric = metric; } diff --git a/src/internet-node/ipv4-l3-protocol.cc b/src/internet-node/ipv4-l3-protocol.cc index 908a7bb99..367a03895 100644 --- a/src/internet-node/ipv4-l3-protocol.cc +++ b/src/internet-node/ipv4-l3-protocol.cc @@ -233,7 +233,7 @@ Ipv4L3Protocol::AddHostRouteTo (Ipv4Address dest, uint32_t interface) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << dest << ", " << nextHop << ", " << interface << ")"); + NS_LOG_PARAMS (this << dest << nextHop << interface); m_staticRouting->AddHostRouteTo (dest, nextHop, interface); } @@ -242,7 +242,7 @@ Ipv4L3Protocol::AddHostRouteTo (Ipv4Address dest, uint32_t interface) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << dest << ", " << interface << ")"); + NS_LOG_PARAMS (this << dest << interface); m_staticRouting->AddHostRouteTo (dest, interface); } @@ -253,8 +253,7 @@ Ipv4L3Protocol::AddNetworkRouteTo (Ipv4Address network, uint32_t interface) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << network << ", " << networkMask << ", " << nextHop << - ", " << interface << ")"); + NS_LOG_PARAMS (this << network << networkMask << nextHop << interface); m_staticRouting->AddNetworkRouteTo (network, networkMask, nextHop, interface); } @@ -264,8 +263,7 @@ Ipv4L3Protocol::AddNetworkRouteTo (Ipv4Address network, uint32_t interface) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << network << ", " << networkMask << ", " << interface << - ")"); + NS_LOG_PARAMS (this << network << networkMask << interface); m_staticRouting->AddNetworkRouteTo (network, networkMask, interface); } @@ -274,7 +272,7 @@ Ipv4L3Protocol::SetDefaultRoute (Ipv4Address nextHop, uint32_t interface) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << nextHop << ", " << interface << ")"); + NS_LOG_PARAMS (this << nextHop << interface); m_staticRouting->SetDefaultRoute (nextHop, interface); } @@ -285,7 +283,7 @@ Ipv4L3Protocol::Lookup ( Ipv4RoutingProtocol::RouteReplyCallback routeReply) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &ipHeader << ", " << &packet << &routeReply << ")"); + NS_LOG_PARAMS (this << &ipHeader << &packet << &routeReply); Lookup (Ipv4RoutingProtocol::IF_INDEX_ANY, ipHeader, packet, routeReply); } @@ -298,8 +296,7 @@ Ipv4L3Protocol::Lookup ( Ipv4RoutingProtocol::RouteReplyCallback routeReply) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << ifIndex << ", " << &ipHeader << ", " << &packet << - &routeReply << ")"); + NS_LOG_PARAMS (this << ifIndex << &ipHeader << &packet << &routeReply); for (Ipv4RoutingProtocolList::const_iterator rprotoIter = m_routingProtocols.begin (); @@ -348,7 +345,7 @@ Ipv4L3Protocol::AddRoutingProtocol (Ptr routingProtocol, int priority) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &routingProtocol << ", " << priority << ")"); + NS_LOG_PARAMS (this << &routingProtocol << priority); m_routingProtocols.push_back (std::pair > (-priority, routingProtocol)); m_routingProtocols.sort (); @@ -372,7 +369,7 @@ void Ipv4L3Protocol::RemoveRoute (uint32_t index) { NS_LOG_FUNCTION; - NS_LOG_PARAM("(" << index << ")"); + NS_LOG_PARAMS (this << index); m_staticRouting->RemoveRoute (index); } @@ -383,8 +380,7 @@ Ipv4L3Protocol::AddMulticastRoute (Ipv4Address origin, std::vector outputInterfaces) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << origin << ", " << group << ", " << inputInterface << - ", " << &outputInterfaces << ")"); + NS_LOG_PARAMS (this << origin << group << inputInterface << &outputInterfaces); m_staticRouting->AddMulticastRoute (origin, group, inputInterface, outputInterfaces); @@ -394,7 +390,7 @@ void Ipv4L3Protocol::SetDefaultMulticastRoute (uint32_t outputInterface) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << outputInterface << ")"); + NS_LOG_PARAMS (this << outputInterface); m_staticRouting->SetDefaultMulticastRoute (outputInterface); } @@ -410,7 +406,7 @@ Ipv4MulticastRoute * Ipv4L3Protocol::GetMulticastRoute (uint32_t index) const { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << index << ")"); + NS_LOG_PARAMS (this << index); return m_staticRouting->GetMulticastRoute (index); } @@ -420,8 +416,7 @@ Ipv4L3Protocol::RemoveMulticastRoute (Ipv4Address origin, uint32_t inputInterface) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << origin << ", " << group << ", " << inputInterface << - ")"); + NS_LOG_PARAMS (this << origin << group << inputInterface); m_staticRouting->RemoveMulticastRoute (origin, group, inputInterface); } @@ -429,7 +424,7 @@ void Ipv4L3Protocol::RemoveMulticastRoute (uint32_t index) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << index << ")"); + NS_LOG_PARAMS (this << index); m_staticRouting->RemoveMulticastRoute (index); } @@ -437,7 +432,7 @@ uint32_t Ipv4L3Protocol::AddInterface (Ptr device) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &device << ")"); + NS_LOG_PARAMS (this << &device); Ptr interface = Create (m_node, device); return AddIpv4Interface (interface); } @@ -446,7 +441,7 @@ uint32_t Ipv4L3Protocol::AddIpv4Interface (Ptrinterface) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << interface << ")"); + NS_LOG_PARAMS (this << interface); uint32_t index = m_nInterfaces; m_interfaces.push_back (interface); m_nInterfaces++; @@ -457,7 +452,7 @@ Ptr Ipv4L3Protocol::GetInterface (uint32_t index) const { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << index << ")"); + NS_LOG_PARAMS (this << index); uint32_t tmp = 0; for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++) { @@ -481,7 +476,7 @@ uint32_t Ipv4L3Protocol::FindInterfaceForAddr (Ipv4Address addr) const { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << addr << ")"); + NS_LOG_PARAMS (this << addr); uint32_t ifIndex = 0; for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); @@ -503,7 +498,7 @@ uint32_t Ipv4L3Protocol::FindInterfaceForAddr (Ipv4Address addr, Ipv4Mask mask) const { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << addr << ", " << mask << ")"); + NS_LOG_PARAMS (this << addr << mask); uint32_t ifIndex = 0; for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); @@ -525,7 +520,7 @@ Ptr Ipv4L3Protocol::FindInterfaceForDevice (Ptr device) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &device << ")"); + NS_LOG_PARAMS (this << &device); for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++) { if ((*i)->GetDevice () == device) @@ -540,8 +535,7 @@ void Ipv4L3Protocol::Receive( Ptr device, const Packet& p, uint16_t protocol, const Address &from) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &device << ", " << &p << ", " << protocol << ", " << - from << ")"); + NS_LOG_PARAMS (this << &device << &p << protocol << from); NS_LOG_LOGIC ("Packet from " << from); @@ -585,8 +579,7 @@ Ipv4L3Protocol::Send (Packet const &packet, uint8_t protocol) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &packet << ", " << source << ", " << ", " << - destination << ", " << protocol << ")"); + NS_LOG_PARAMS (this << &packet << source << destination << protocol); Ipv4Header ipHeader; @@ -637,8 +630,7 @@ Ipv4L3Protocol::SendRealOut (bool found, Ipv4Header const &ipHeader) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << found << ", " << &route << ", " << &packet << - &ipHeader << ")"); + NS_LOG_PARAMS (this << found << &route << &packet << &ipHeader); if (!found) { @@ -673,8 +665,7 @@ Ipv4L3Protocol::Forwarding ( Ptr device) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << ifIndex << ", " << &packet << ", " << &ipHeader << - ", " << device << ")"); + NS_LOG_PARAMS (ifIndex << &packet << &ipHeader<< device); for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++) @@ -751,7 +742,7 @@ Ipv4L3Protocol::ForwardUp (Packet p, Ipv4Header const&ip, Ptr incomingInterface) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ", " << &ip << ")"); + NS_LOG_PARAMS (this << &p << &ip); Ptr demux = m_node->QueryInterface (Ipv4L4Demux::iid); Ptr protocol = demux->GetProtocol (ip.GetProtocol ()); @@ -762,7 +753,7 @@ void Ipv4L3Protocol::JoinMulticastGroup (Ipv4Address origin, Ipv4Address group) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << origin << ", " << group << ")"); + NS_LOG_PARAMS (this << origin << group); m_multicastGroups.push_back( std::pair (origin, group)); } @@ -771,7 +762,7 @@ void Ipv4L3Protocol::LeaveMulticastGroup (Ipv4Address origin, Ipv4Address group) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << origin << ", " << group << ")"); + NS_LOG_PARAMS (this << origin << group); for (Ipv4MulticastGroupList::iterator i = m_multicastGroups.begin (); i != m_multicastGroups.end (); @@ -789,7 +780,7 @@ void Ipv4L3Protocol::SetAddress (uint32_t i, Ipv4Address address) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << i << ", " << address << ")"); + NS_LOG_PARAMS (this << i << address); Ptr interface = GetInterface (i); interface->SetAddress (address); } @@ -798,7 +789,7 @@ void Ipv4L3Protocol::SetNetworkMask (uint32_t i, Ipv4Mask mask) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << i << ", " << mask << ")"); + NS_LOG_PARAMS (this << i << mask); Ptr interface = GetInterface (i); interface->SetNetworkMask (mask); } @@ -807,7 +798,7 @@ Ipv4Mask Ipv4L3Protocol::GetNetworkMask (uint32_t i) const { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << i << ")"); + NS_LOG_PARAMS (this << i); Ptr interface = GetInterface (i); return interface->GetNetworkMask (); } @@ -816,7 +807,7 @@ Ipv4Address Ipv4L3Protocol::GetAddress (uint32_t i) const { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << i << ")"); + NS_LOG_PARAMS (this << i); Ptr interface = GetInterface (i); return interface->GetAddress (); } @@ -825,7 +816,7 @@ void Ipv4L3Protocol::SetMetric (uint32_t i, uint16_t metric) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << i << ", " << metric << ")"); + NS_LOG_PARAMS ("(" << i << ", " << metric << ")"); Ptr interface = GetInterface (i); interface->SetMetric (metric); } @@ -834,7 +825,7 @@ uint16_t Ipv4L3Protocol::GetMetric (uint32_t i) const { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << i << ")"); + NS_LOG_PARAMS ("(" << i << ")"); Ptr interface = GetInterface (i); return interface->GetMetric (); } @@ -844,7 +835,7 @@ Ipv4L3Protocol::GetIfIndexForDestination ( Ipv4Address destination, uint32_t& ifIndex) const { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << destination << ", " << &ifIndex << ")"); + NS_LOG_PARAMS (this << destination << &ifIndex); // // The first thing we do in trying to determine a source address is to // consult the routing protocols. These will also check for a default route @@ -911,7 +902,7 @@ uint16_t Ipv4L3Protocol::GetMtu (uint32_t i) const { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << i << ")"); + NS_LOG_PARAMS (this << i); Ptr interface = GetInterface (i); return interface->GetMtu (); } @@ -920,7 +911,7 @@ bool Ipv4L3Protocol::IsUp (uint32_t i) const { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << i << ")"); + NS_LOG_PARAMS (this << i); Ptr interface = GetInterface (i); return interface->IsUp (); } @@ -929,7 +920,7 @@ void Ipv4L3Protocol::SetUp (uint32_t i) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << i << ")"); + NS_LOG_PARAMS (this << i); Ptr interface = GetInterface (i); interface->SetUp (); @@ -948,7 +939,7 @@ void Ipv4L3Protocol::SetDown (uint32_t ifaceIndex) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << ifaceIndex << ")"); + NS_LOG_PARAMS (this << ifaceIndex); Ptr interface = GetInterface (ifaceIndex); interface->SetDown (); diff --git a/src/internet-node/ipv4-loopback-interface.cc b/src/internet-node/ipv4-loopback-interface.cc index eb59a662d..30f18ad9e 100644 --- a/src/internet-node/ipv4-loopback-interface.cc +++ b/src/internet-node/ipv4-loopback-interface.cc @@ -47,7 +47,7 @@ void Ipv4LoopbackInterface::SendTo (Packet packet, Ipv4Address dest) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &packet << ", " << dest << ")"); + NS_LOG_PARAMS (this << &packet << dest); Ptr ipv4 = m_node->QueryInterface (Ipv4L3Protocol::iid); diff --git a/src/internet-node/ipv4-static-routing.cc b/src/internet-node/ipv4-static-routing.cc index 6b7d8671d..8636631d8 100644 --- a/src/internet-node/ipv4-static-routing.cc +++ b/src/internet-node/ipv4-static-routing.cc @@ -522,8 +522,7 @@ Ipv4StaticRouting::RequestRoute ( RouteReplyCallback routeReply) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << ifIndex << &ipHeader << ", " << &packet << ", " << - &routeReply << ")"); + NS_LOG_PARAMS (this << ifIndex << &ipHeader << &packet << &routeReply); NS_LOG_LOGIC ("source = " << ipHeader.GetSource ()); @@ -576,7 +575,7 @@ bool Ipv4StaticRouting::RequestIfIndex (Ipv4Address destination, uint32_t& ifIndex) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << destination << ", " << &ifIndex << ")"); + NS_LOG_PARAMS (this << destination << &ifIndex); // // First, see if this is a multicast packet we have a route for. If we // have a route, then send the packet down each of the specified interfaces. diff --git a/src/internet-node/udp-l4-protocol.cc b/src/internet-node/udp-l4-protocol.cc index cbf8cbf52..cd7246536 100644 --- a/src/internet-node/udp-l4-protocol.cc +++ b/src/internet-node/udp-l4-protocol.cc @@ -83,7 +83,7 @@ Ipv4EndPoint * UdpL4Protocol::Allocate (Ipv4Address address) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << address << ")"); + NS_LOG_PARAMS (this << address); return m_endPoints->Allocate (address); } @@ -91,7 +91,7 @@ Ipv4EndPoint * UdpL4Protocol::Allocate (uint16_t port) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << port << ")"); + NS_LOG_PARAMS (this << port); return m_endPoints->Allocate (port); } @@ -99,7 +99,7 @@ Ipv4EndPoint * UdpL4Protocol::Allocate (Ipv4Address address, uint16_t port) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << address << ", " << port << ")"); + NS_LOG_PARAMS (this << address << port); return m_endPoints->Allocate (address, port); } Ipv4EndPoint * @@ -107,8 +107,7 @@ UdpL4Protocol::Allocate (Ipv4Address localAddress, uint16_t localPort, Ipv4Address peerAddress, uint16_t peerPort) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << localAddress << ", " << localPort << ", " << - peerAddress << ", " << peerPort << ")"); + NS_LOG_PARAMS (this << localAddress << localPort << peerAddress << peerPort); return m_endPoints->Allocate (localAddress, localPort, peerAddress, peerPort); } @@ -117,7 +116,7 @@ void UdpL4Protocol::DeAllocate (Ipv4EndPoint *endPoint) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << endPoint << ")"); + NS_LOG_PARAMS (this << endPoint); m_endPoints->DeAllocate (endPoint); } @@ -128,8 +127,7 @@ UdpL4Protocol::Receive(Packet& packet, Ptr interface) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &packet << ", " << source << ", " << destination << - ")"); + NS_LOG_PARAMS (this << &packet << source << destination); UdpHeader udpHeader; packet.RemoveHeader (udpHeader); @@ -149,8 +147,7 @@ UdpL4Protocol::Send (Packet packet, uint16_t sport, uint16_t dport) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &packet << ", " << saddr << ", " << daddr << ", " << - sport << ", " << dport << ")"); + NS_LOG_PARAMS (this << &packet << saddr << daddr << sport << dport); UdpHeader udpHeader; udpHeader.SetDestination (dport); diff --git a/src/internet-node/udp-socket.cc b/src/internet-node/udp-socket.cc index d6c968d80..ff695cbfd 100644 --- a/src/internet-node/udp-socket.cc +++ b/src/internet-node/udp-socket.cc @@ -117,7 +117,7 @@ int UdpSocket::Bind (const Address &address) { NS_LOG_FUNCTION; - NS_LOG_PARAM("(" << address << ")"); + NS_LOG_PARAMS (this << address); if (!InetSocketAddress::IsMatchingType (address)) { @@ -175,7 +175,7 @@ int UdpSocket::Connect(const Address & address) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << address << ")"); + NS_LOG_PARAMS (this << address); Ipv4Route routeToDest; InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); m_defaultAddress = transport.GetIpv4 (); @@ -190,7 +190,7 @@ int UdpSocket::Send (const Packet &p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); if (!m_connected) { @@ -226,7 +226,7 @@ int UdpSocket::DoSendTo (const Packet &p, const Address &address) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ", " << address << ")"); + NS_LOG_PARAMS (this << &p << address); if (!m_connected) { @@ -248,7 +248,7 @@ int UdpSocket::DoSendTo (const Packet &p, Ipv4Address dest, uint16_t port) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ", " << dest << ", " << port << ")"); + NS_LOG_PARAMS (this << &p << dest << port); Ipv4Route routeToDest; @@ -308,7 +308,7 @@ int UdpSocket::SendTo(const Address &address, const Packet &p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << address << ", " << &p << ")"); + NS_LOG_PARAMS (this << address << &p); InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); Ipv4Address ipv4 = transport.GetIpv4 (); uint16_t port = transport.GetPort (); @@ -319,7 +319,7 @@ void UdpSocket::ForwardUp (const Packet &packet, Ipv4Address ipv4, uint16_t port) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &packet << ", " << ipv4 << ", " << port << ")"); + NS_LOG_PARAMS (this << &packet << ipv4 << port); if (m_shutdownRecv) { diff --git a/src/node/channel.cc b/src/node/channel.cc index b571e6123..740b8edec 100644 --- a/src/node/channel.cc +++ b/src/node/channel.cc @@ -37,7 +37,7 @@ Channel::Channel (std::string name) : m_name(name) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << name << ")"); + NS_LOG_PARAMS (this << name); SetInterfaceId (Channel::iid); } @@ -50,7 +50,7 @@ Channel::~Channel () Channel::SetName(std::string name) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << name << ")"); + NS_LOG_PARAMS (this << name); m_name = name; } diff --git a/src/node/drop-tail-queue.cc b/src/node/drop-tail-queue.cc index 8b5ceea79..a4fb979bb 100644 --- a/src/node/drop-tail-queue.cc +++ b/src/node/drop-tail-queue.cc @@ -45,7 +45,7 @@ void DropTailQueue::SetMaxPackets (uint32_t npackets) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << npackets << ")"); + NS_LOG_PARAMS (this << npackets); m_maxPackets = npackets; } @@ -61,7 +61,7 @@ bool DropTailQueue::DoEnqueue (const Packet& p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); if (m_packets.size () >= m_maxPackets) { @@ -78,7 +78,7 @@ bool DropTailQueue::DoDequeue (Packet& p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); if (m_packets.empty()) { @@ -98,7 +98,7 @@ bool DropTailQueue::DoPeek (Packet& p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); if (m_packets.empty()) { diff --git a/src/node/queue.cc b/src/node/queue.cc index 4a622c2b0..ab7f8f894 100644 --- a/src/node/queue.cc +++ b/src/node/queue.cc @@ -139,7 +139,7 @@ bool Queue::Enqueue (const Packet& p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); NS_LOG_LOGIC ("m_traceEnqueue (p)"); m_traceEnqueue (p); @@ -157,7 +157,7 @@ bool Queue::Dequeue (Packet &p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); bool retval = DoDequeue (p); @@ -189,7 +189,7 @@ bool Queue::Peek (Packet &p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); return DoPeek (p); } @@ -264,7 +264,7 @@ void Queue::Drop (const Packet& p) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << &p << ")"); + NS_LOG_PARAMS (this << &p); m_nTotalDroppedPackets++; m_nTotalDroppedBytes += p.GetSize (); diff --git a/src/routing/global-routing/candidate-queue.cc b/src/routing/global-routing/candidate-queue.cc index e6d3b552e..403c2e9b7 100644 --- a/src/routing/global-routing/candidate-queue.cc +++ b/src/routing/global-routing/candidate-queue.cc @@ -52,7 +52,7 @@ CandidateQueue::Clear (void) CandidateQueue::Push (SPFVertex *vNew) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << vNew << ")"); + NS_LOG_PARAMS (this << vNew); CandidateList_t::iterator i = m_candidates.begin (); diff --git a/src/routing/global-routing/global-route-manager-impl.cc b/src/routing/global-routing/global-route-manager-impl.cc index b666fcb8c..57a17f828 100644 --- a/src/routing/global-routing/global-route-manager-impl.cc +++ b/src/routing/global-routing/global-route-manager-impl.cc @@ -975,7 +975,7 @@ GlobalRouteManagerImpl::DebugSPFCalculate (Ipv4Address root) GlobalRouteManagerImpl::SPFCalculate (Ipv4Address root) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << root << ")"); + NS_LOG_PARAMS (this << root); SPFVertex *v; // diff --git a/src/routing/global-routing/global-router-interface.cc b/src/routing/global-routing/global-router-interface.cc index ee49733c1..9ade5d010 100644 --- a/src/routing/global-routing/global-router-interface.cc +++ b/src/routing/global-routing/global-router-interface.cc @@ -58,8 +58,7 @@ GlobalRoutingLinkRecord::GlobalRoutingLinkRecord ( m_metric (metric) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << linkType << ", " << linkId << ", " << linkData << - ", " << metric << ")"); + NS_LOG_PARAMS (this << linkType << linkId << linkData << metric); } GlobalRoutingLinkRecord::~GlobalRoutingLinkRecord () @@ -157,8 +156,7 @@ GlobalRoutingLSA::GlobalRoutingLSA ( m_status(status) { NS_LOG_FUNCTION; - NS_LOG_PARAM ("(" << status << ", " << linkStateId << ", " << - advertisingRtr << ")"); + NS_LOG_PARAMS (this << status << linkStateId << advertisingRtr); } GlobalRoutingLSA::GlobalRoutingLSA (GlobalRoutingLSA& lsa) From c1544ba7c4791594243c2155d019418a95b09adb Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 15 Nov 2007 10:15:16 +0100 Subject: [PATCH 37/67] check for Time bounds --- src/simulator/time.cc | 74 ++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 32 deletions(-) diff --git a/src/simulator/time.cc b/src/simulator/time.cc index a58a54925..e4a41dd9a 100644 --- a/src/simulator/time.cc +++ b/src/simulator/time.cc @@ -354,62 +354,62 @@ TimeTests::~TimeTests () bool TimeTests::RunTests (void) { - bool ok = true; + bool result = true; Time t0, t1; - CheckOld(&ok); + CheckOld(&result); t0 = MilliSeconds ((uint64_t)10.0); t1 = MilliSeconds ((uint64_t)11.0); - CheckOperations(t0, t1, &ok); + CheckOperations(t0, t1, &result); // t0 = Seconds ((uint64_t)10.0); // t1 = Seconds ((uint64_t)11.0); - // CheckOperations(t0, t1, &ok); + // CheckOperations(t0, t1, &result); - CheckConversions((uint64_t)5, &ok); - CheckConversions((uint64_t)0, &ok); - CheckConversions((uint64_t)783, &ok); - CheckConversions((uint64_t)1132, &ok); - // CheckConversions((uint64_t)3341039, &ok); + CheckConversions((uint64_t)5, &result); + CheckConversions((uint64_t)0, &result); + CheckConversions((uint64_t)783, &result); + CheckConversions((uint64_t)1132, &result); + // CheckConversions((uint64_t)3341039, &result); // Now vary the precision and check the conversions if (TimeStepPrecision::Get () != TimeStepPrecision::NS) { - ok = false; + result = false; } - CheckPrecision(TimeStepPrecision::US, 7, &ok); + CheckPrecision(TimeStepPrecision::US, 7, &result); - CheckConversions((uint64_t)7, &ok); - CheckConversions((uint64_t)546, &ok); - CheckConversions((uint64_t)6231, &ok); - // CheckConversions((uint64_t)1234639, &ok); + CheckConversions((uint64_t)7, &result); + CheckConversions((uint64_t)546, &result); + CheckConversions((uint64_t)6231, &result); + // CheckConversions((uint64_t)1234639, &result); - CheckPrecision(TimeStepPrecision::MS, 3, &ok); + CheckPrecision(TimeStepPrecision::MS, 3, &result); - CheckConversions((uint64_t)3, &ok); - CheckConversions((uint64_t)134, &ok); - CheckConversions((uint64_t)2341, &ok); - // CheckConversions((uint64_t)8956239, &ok); + CheckConversions((uint64_t)3, &result); + CheckConversions((uint64_t)134, &result); + CheckConversions((uint64_t)2341, &result); + // CheckConversions((uint64_t)8956239, &result); - CheckPrecision(TimeStepPrecision::PS, 21, &ok); + CheckPrecision(TimeStepPrecision::PS, 21, &result); - CheckConversions((uint64_t)4, &ok); - CheckConversions((uint64_t)342, &ok); - CheckConversions((uint64_t)1327, &ok); - // CheckConversions((uint64_t)5439627, &ok); + CheckConversions((uint64_t)4, &result); + CheckConversions((uint64_t)342, &result); + CheckConversions((uint64_t)1327, &result); + // CheckConversions((uint64_t)5439627, &result); - CheckPrecision(TimeStepPrecision::NS, 12, &ok); - CheckConversions((uint64_t)12, &ok); + CheckPrecision(TimeStepPrecision::NS, 12, &result); + CheckConversions((uint64_t)12, &result); - CheckPrecision(TimeStepPrecision::S, 7, &ok); - CheckConversions((uint64_t)7, &ok); + CheckPrecision(TimeStepPrecision::S, 7, &result); + CheckConversions((uint64_t)7, &result); - CheckPrecision(TimeStepPrecision::FS, 5, &ok); - CheckConversions((uint64_t)5, &ok); + CheckPrecision(TimeStepPrecision::FS, 5, &result); + CheckConversions((uint64_t)5, &result); TimeStepPrecision::Set (TimeStepPrecision::NS); @@ -420,7 +420,17 @@ bool TimeTests::RunTests (void) DefaultValue::Bind ("TimeStepPrecision", "PS"); DefaultValue::Bind ("TimeStepPrecision", "FS"); - return ok; + + Time tooBig = TimeStep (0x8000000000000000LL); + NS_TEST_ASSERT (tooBig.IsNegative ()); + tooBig = TimeStep (0xffffffffffffffffLL); + NS_TEST_ASSERT (tooBig.IsNegative ()); + tooBig = TimeStep (0x7fffffffffffffffLL); + NS_TEST_ASSERT (tooBig.IsPositive ()); + tooBig += TimeStep (1); + NS_TEST_ASSERT (tooBig.IsNegative ()); + + return result; } void TimeTests::CheckOld (bool *ok) From 838bef63b3d572aafbbbcb0431a161445e6c25f3 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 15 Nov 2007 10:22:35 +0100 Subject: [PATCH 38/67] merge with Position -> Vector rename --- samples/main-adhoc-wifi.cc | 18 ++++++++-------- samples/main-ap-wifi.cc | 24 +++++++++++----------- samples/main-propagation-loss.cc | 4 ++-- src/devices/wifi/propagation-loss-model.cc | 4 ++-- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/samples/main-adhoc-wifi.cc b/samples/main-adhoc-wifi.cc index fc153f6e0..b97822213 100644 --- a/samples/main-adhoc-wifi.cc +++ b/samples/main-adhoc-wifi.cc @@ -46,13 +46,13 @@ static GnuplotDataset *g_output = 0; static Ptr CreateAdhocNode (Ptr channel, - Position position, const char *address) + Vector position, const char *address) { Ptr node = Create (); Ptr device = Create (node); device->ConnectTo (channel); Ptr mobility = Create (); - mobility->Set (position); + mobility->SetPosition (position); node->AddInterface (mobility); Ptr ipv4 = node->QueryInterface (Ipv4::iid); @@ -64,23 +64,23 @@ CreateAdhocNode (Ptr channel, } static void -SetPosition (Ptr node, Position position) +SetPosition (Ptr node, Vector position) { Ptr mobility = node->QueryInterface (MobilityModel::iid); - mobility->Set (position); + mobility->SetPosition (position); } -static Position +static Vector GetPosition (Ptr node) { Ptr mobility = node->QueryInterface (MobilityModel::iid); - return mobility->Get (); + return mobility->GetPosition (); } static void AdvancePosition (Ptr node) { - Position pos = GetPosition (node); + Vector pos = GetPosition (node); double mbs = ((g_bytesTotal * 8.0) / 1000000); g_bytesTotal = 0; g_output->Add (pos.x, mbs); @@ -119,10 +119,10 @@ RunOneExperiment (void) Ptr channel = Create (); Ptr a = CreateAdhocNode (channel, - Position (5.0,0.0,0.0), + Vector (5.0,0.0,0.0), "192.168.0.1"); Ptr b = CreateAdhocNode (channel, - Position (0.0, 0.0, 0.0), + Vector (0.0, 0.0, 0.0), "192.168.0.2"); Ptr app = Create (a, InetSocketAddress ("192.168.0.2", 10), diff --git a/samples/main-ap-wifi.cc b/samples/main-ap-wifi.cc index 26266b94f..85e8877ce 100644 --- a/samples/main-ap-wifi.cc +++ b/samples/main-ap-wifi.cc @@ -69,7 +69,7 @@ WifiPhyStateTrace (const TraceContext &context, Time start, Time duration, enum static Ptr CreateApNode (Ptr channel, - Position position, + Vector position, const char *ipAddress, Ssid ssid, Time at) @@ -80,7 +80,7 @@ CreateApNode (Ptr channel, Simulator::Schedule (at, &NqapWifiNetDevice::StartBeaconing, device); device->ConnectTo (channel); Ptr mobility = Create (); - mobility->Set (position); + mobility->SetPosition (position); node->AddInterface (mobility); Ptr ipv4 = node->QueryInterface (Ipv4::iid); @@ -93,7 +93,7 @@ CreateApNode (Ptr channel, static Ptr CreateStaNode (Ptr channel, - Position position, + Vector position, const char *ipAddress, Ssid ssid) { @@ -103,7 +103,7 @@ CreateStaNode (Ptr channel, ssid); device->ConnectTo (channel); Ptr mobility = Create (); - mobility->Set (position); + mobility->SetPosition (position); node->AddInterface (mobility); Ptr ipv4 = node->QueryInterface (Ipv4::iid); @@ -115,23 +115,23 @@ CreateStaNode (Ptr channel, } static void -SetPosition (Ptr node, Position position) +SetPosition (Ptr node, Vector position) { Ptr mobility = node->QueryInterface (MobilityModel::iid); - mobility->Set (position); + mobility->SetPosition (position); } -static Position +static Vector GetPosition (Ptr node) { Ptr mobility = node->QueryInterface (MobilityModel::iid); - return mobility->Get (); + return mobility->GetPosition (); } static void AdvancePosition (Ptr node) { - Position pos = GetPosition (node); + Vector pos = GetPosition (node); pos.x += 5.0; if (pos.x >= 210.0) { return; @@ -164,19 +164,19 @@ int main (int argc, char *argv[]) Ssid ssid = Ssid ("mathieu"); Ptr a = CreateApNode (channel, - Position (5.0,0.0,0.0), + Vector (5.0,0.0,0.0), "192.168.0.1", ssid, Seconds (0.1)); Simulator::Schedule (Seconds (1.0), &AdvancePosition, a); Ptr b = CreateStaNode (channel, - Position (0.0, 0.0, 0.0), + Vector (0.0, 0.0, 0.0), "192.168.0.2", ssid); Ptr c = CreateStaNode (channel, - Position (0.0, 0.0, 0.0), + Vector (0.0, 0.0, 0.0), "192.168.0.3", ssid); diff --git a/samples/main-propagation-loss.cc b/samples/main-propagation-loss.cc index 7a6de7e58..2df93d2f1 100644 --- a/samples/main-propagation-loss.cc +++ b/samples/main-propagation-loss.cc @@ -30,10 +30,10 @@ PrintOne (double minTxpower, double maxTxpower, double stepTxpower, double min, Ptr b = Create (); Ptr model = PropagationLossModel::CreateDefault (); - a->Set (Position (0.0, 0.0, 0.0)); + a->SetPosition (Vector (0.0, 0.0, 0.0)); for (double x = min; x < max; x+= step) { - b->Set (Position (x, 0.0, 0.0)); + b->SetPosition (Vector (x, 0.0, 0.0)); std::cout << x << " "; for (double txpower = minTxpower; txpower < maxTxpower; txpower += stepTxpower) { diff --git a/src/devices/wifi/propagation-loss-model.cc b/src/devices/wifi/propagation-loss-model.cc index ba97e060f..98490c738 100644 --- a/src/devices/wifi/propagation-loss-model.cc +++ b/src/devices/wifi/propagation-loss-model.cc @@ -288,8 +288,8 @@ LogDistancePropagationLossModel::GetRxPower (double txPowerDbm, * * rx = rx0(tx) - 10 * n * log (d/d0) */ - static Ptr zero = Create (Position (0.0, 0.0, 0.0)); - static Ptr reference = Create (Position (m_referenceDistance, 0.0, 0.0)); + static Ptr zero = Create (Vector (0.0, 0.0, 0.0)); + static Ptr reference = Create (Vector (m_referenceDistance, 0.0, 0.0)); double rx0 = m_reference->GetRxPower (txPowerDbm, zero, reference); double pathLossDb = 10 * m_exponent * log10 (distance / m_referenceDistance); double rxPowerDbm = rx0 - pathLossDb; From 873a2c8dda5164faf07b515c2b54fa5a46122955 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 15 Nov 2007 10:23:54 +0100 Subject: [PATCH 39/67] add a valueref macro --- doc/doxygen.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/doxygen.conf b/doc/doxygen.conf index 135a890b1..8fe4fd648 100644 --- a/doc/doxygen.conf +++ b/doc/doxygen.conf @@ -185,7 +185,7 @@ TAB_SIZE = 4 # will result in a user-defined paragraph with heading "Side Effects:". # You can put \n's in the value part of an alias to insert newlines. -ALIASES = +ALIASES = valueref{1}="\ref DefaultValue\1 \"\1\"" # Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C # sources only. Doxygen will then generate output that is more tailored for C. From 34345b47d0b1c2a1380c561ca4b370abf57119e7 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 15 Nov 2007 10:24:51 +0100 Subject: [PATCH 40/67] print default value list in trace source list doxygen output. --- utils/print-trace-sources.cc | 37 +++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/utils/print-trace-sources.cc b/utils/print-trace-sources.cc index dcfe559a1..ed9411535 100644 --- a/utils/print-trace-sources.cc +++ b/utils/print-trace-sources.cc @@ -6,6 +6,7 @@ #include "ns3/csma-net-device.h" #include "ns3/queue.h" #include "ns3/mobility-model-notifier.h" +#include "ns3/default-value.h" using namespace ns3; @@ -35,7 +36,7 @@ PrintSimpleText (const TraceResolver::SourceCollection *sources, std::ostream &o os << std::endl; } } -void +static void PrintDoxygenText (const TraceResolver::SourceCollection *sources, std::ostream &os) { uint32_t z = 0; @@ -81,6 +82,37 @@ PrintDoxygenText (const TraceResolver::SourceCollection *sources, std::ostream & } } +static void +PrintOneDefaultValue (DefaultValueBase *value, std::ostream &os) +{ + os << "///
  • \\anchor DefaultValue" << value->GetName () + << " " << value->GetName () << std::endl; + os << "///
      " << std::endl; + os << "///
    • Type: " << value->GetType () << "" << std::endl; + os << "///
    • Default value: " << value->GetDefaultValue () << "" << std::endl; + os << "///
    • Description: " << value->GetHelp () << "" << std::endl; + os << "///
    " << std::endl; + os << "///
  • " << std::endl; +} + +static void +PrintDefaultValuesDoxygen (std::ostream &os) +{ + os << "/// \\page ListOfDefaultValues The list of default values" << std::endl; + os << "/// \\defgroup ListOfDefaultValuesGroup The list of default values" << std::endl; + os << "///
      " << std::endl; + for (DefaultValueList::Iterator i = DefaultValueList::Begin (); + i != DefaultValueList::End (); i++) + { + if ((*i)->GetName () == "help") + { + continue; + } + PrintOneDefaultValue (*i, os); + } + os << "///
    " << std::endl; +} + int main (int argc, char *argv[]) { @@ -96,5 +128,8 @@ int main (int argc, char *argv[]) NodeList::GetTraceResolver ()->CollectSources ("", TraceContext (), &collection); PrintDoxygenText (&collection, std::cout); + + PrintDefaultValuesDoxygen (std::cout); + return 0; } From ed31e39491be3e5f1a3b738eb24d2a738ab417d6 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 15 Nov 2007 10:25:35 +0100 Subject: [PATCH 41/67] use the \valueref macro --- .../random-direction-2d-mobility-model.h | 8 ++++++-- src/mobility/random-position.h | 12 ++++++++---- src/mobility/random-topology.h | 5 +++-- src/mobility/random-walk-2d-mobility-model.h | 19 ++++++++++++++----- src/mobility/random-waypoint-mobility-model.h | 6 ++++-- 5 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/mobility/random-direction-2d-mobility-model.h b/src/mobility/random-direction-2d-mobility-model.h index 24f0fd94e..1d0773e50 100644 --- a/src/mobility/random-direction-2d-mobility-model.h +++ b/src/mobility/random-direction-2d-mobility-model.h @@ -41,7 +41,9 @@ class RandomDirection2dMobilityModelParameters : public Object { public: /** - * Create a default parameter object from Bind default values. + * Create from \valueref{RandomDirection2dSpeed}, + * \valueref{RandomDirection2dPause}, and, + * \valueref{RandomDirection2dArea}. */ RandomDirection2dMobilityModelParameters (); /** @@ -91,7 +93,9 @@ class RandomDirection2dMobilityModel : public MobilityModel static const ClassId cid; /** - * Create a RandomDirection model from the default Bind values. + * Create from \valueref{RandomDirection2dSpeed}, + * \valueref{RandomDirection2dPause}, and, + * \valueref{RandomDirection2dArea}. */ RandomDirection2dMobilityModel (); /** diff --git a/src/mobility/random-position.h b/src/mobility/random-position.h index aa4b5a14b..27559844d 100644 --- a/src/mobility/random-position.h +++ b/src/mobility/random-position.h @@ -54,8 +54,9 @@ class RandomRectanglePosition : public RandomPosition public: static const ClassId cid; /** - * Create a random position model based on the - * Bind default values. + * Create a random position model with construction + * values from \valueref{RandomRectanglePositionX}, and + * \valueref{RandomRectanglePositionY} */ RandomRectanglePosition (); /** @@ -82,8 +83,11 @@ class RandomDiscPosition : public RandomPosition public: static const ClassId cid; /** - * Create a random position model based on the - * Bind default values. + * Create a random position model with construction + * values from \valueref{RandomDiscPositionTheta}, + * \valueref{RandomDiscPositionRho}, + * \valueref{RandomDiscPositionX}, and, + * \valueref{RandomDiscPositionY}. */ RandomDiscPosition (); /** diff --git a/src/mobility/random-topology.h b/src/mobility/random-topology.h index a955839e0..4a6d1817c 100644 --- a/src/mobility/random-topology.h +++ b/src/mobility/random-topology.h @@ -41,8 +41,9 @@ class RandomTopology { public: /** - * Create a default random topology based - * on Bind configuration. + * Create a default random topology with construction + * values from \valueref{RandomTopologyPositionType}, and, + * \valueref{RandomTopologyMobilityType}. */ RandomTopology (); /** diff --git a/src/mobility/random-walk-2d-mobility-model.h b/src/mobility/random-walk-2d-mobility-model.h index 46b871753..72def7ade 100644 --- a/src/mobility/random-walk-2d-mobility-model.h +++ b/src/mobility/random-walk-2d-mobility-model.h @@ -44,7 +44,10 @@ class RandomWalk2dMobilityModelParameters : public Object public: /** * Instantiate a set of RandomWalk parameters initialized - * with the Bind default values. + * with construction values from \valueref{RandomWalk2dMode}, + * \valueref{RandomWalk2dDistance}, \valueref{RandomWalk2dTime}, + * \valueref{RandomWalk2dSpeed}, \valueref{RandomWalk2dDirection}, + * and, \valueref{RandomWalk2dBounds}. */ RandomWalk2dMobilityModelParameters (); virtual ~RandomWalk2dMobilityModelParameters (); @@ -104,9 +107,9 @@ class RandomWalk2dMobilityModelParameters : public Object * either a fixed distance has been walked or until a fixed amount * of time. * - * The parameters of the model can be specified either with the ns3::Bind - * function and the variables "RandomWalk2dSpeed", "RandomWalk2dMode", - * "RandomWalk2dDistance", "RandomWalk2dTime", and, "RandomWalk2dBounds" or + * The parameters of the model can be specified either with the DefaultValue::Bind + * function and the variables \valueref{RandomWalk2dSpeed}, \valueref{RandomWalk2dMode}, + * \valueref{RandomWalk2dDistance}, \valueref{RandomWalk2dTime}, and, \valueref{RandomWalk2dBounds} or * with an instance of the RandomWalk2dMobilityModelParameters class which * must be fed to the RandomWalk2dMobilityModel constructors. */ @@ -115,7 +118,13 @@ class RandomWalk2dMobilityModel : public MobilityModel public: static const ClassId cid; /** - * Create a new position object located at position (0,0,0) + * Instantiate a set of RandomWalk parameters initialized + * with construction values from \valueref{RandomWalk2dMode}, + * \valueref{RandomWalk2dDistance}, \valueref{RandomWalk2dTime}, + * \valueref{RandomWalk2dSpeed}, \valueref{RandomWalk2dDirection}, + * and, \valueref{RandomWalk2dBounds}. + * + * The default position is (0,0,0) */ RandomWalk2dMobilityModel (); /** diff --git a/src/mobility/random-waypoint-mobility-model.h b/src/mobility/random-waypoint-mobility-model.h index 3a86f349a..273d38a02 100644 --- a/src/mobility/random-waypoint-mobility-model.h +++ b/src/mobility/random-waypoint-mobility-model.h @@ -38,7 +38,8 @@ class RandomWaypointMobilityModelParameters : public Object { public: /** - * Defaults parameters based on the Bind values. + * Default parameters from \valueref{RandomWaypointPause}, + * and, \valueref{RandomWaypointPosition}. */ RandomWaypointMobilityModelParameters (); /** @@ -88,7 +89,8 @@ public: static const ClassId cid; /** - * Create a waypoint mobility model from the Bind default values. + * Default parameters from \valueref{RandomWaypointPause}, + * and, \valueref{RandomWaypointPosition}. */ RandomWaypointMobilityModel (); /** From aad088e588619d5e1c3cbc06754cfcbcbf9eca96 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 15 Nov 2007 10:35:55 +0100 Subject: [PATCH 42/67] print-trace-sources.cc -> print-introspected-doxygen.cc --- doc/doxygen.conf | 2 +- ...int-trace-sources.cc => print-introspected-doxygen.cc} | 0 utils/wscript | 4 ++-- wscript | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) rename utils/{print-trace-sources.cc => print-introspected-doxygen.cc} (100%) diff --git a/doc/doxygen.conf b/doc/doxygen.conf index 8fe4fd648..476854249 100644 --- a/doc/doxygen.conf +++ b/doc/doxygen.conf @@ -495,7 +495,7 @@ WARN_LOGFILE = INPUT = src \ doc/main.txt \ - doc/trace-source-list.h \ + doc/introspected-doxygen.h \ doc/tracing.h # This tag can be used to specify the character encoding of the source files that diff --git a/utils/print-trace-sources.cc b/utils/print-introspected-doxygen.cc similarity index 100% rename from utils/print-trace-sources.cc rename to utils/print-introspected-doxygen.cc diff --git a/utils/wscript b/utils/wscript index 390508478..8b8092334 100644 --- a/utils/wscript +++ b/utils/wscript @@ -28,9 +28,9 @@ def build(bld): obj = bld.create_ns3_program('replay-simulation', ['simulator']) obj.source = 'replay-simulation.cc' - obj = bld.create_ns3_program('print-trace-sources', + obj = bld.create_ns3_program('print-introspected-doxygen', ['internet-node', 'csma-cd', 'point-to-point']) - obj.source = 'print-trace-sources.cc' + obj.source = 'print-introspected-doxygen.cc' if env['ENABLE_MOBILITY_VISUALIZER']: obj = bld.create_ns3_program('mobility-visualizer', diff --git a/wscript b/wscript index 5bf302938..2cc749a8b 100644 --- a/wscript +++ b/wscript @@ -214,8 +214,8 @@ def _run_waf_check(): ## generate the trace sources list docs env = Params.g_build.env_of_name('default') proc_env = _get_proc_env() - prog = _find_program('print-trace-sources', env).m_linktask.m_outputs[0].abspath(env) - out = open('doc/trace-source-list.h', 'w') + prog = _find_program('print-introspected-doxygen', env).m_linktask.m_outputs[0].abspath(env) + out = open('doc/introspected-doxygen.h', 'w') if subprocess.Popen([prog], stdout=out, env=proc_env).wait(): raise SystemExit(1) out.close() @@ -353,8 +353,8 @@ def run_shell(): def doxygen(): - if not os.path.exists('doc/trace-source-list.h'): - Params.warning("doc/trace-source-list.h does not exist; run waf check to generate it.") + if not os.path.exists('doc/introspected-doxygen.h'): + Params.warning("doc/introspected-doxygen.h does not exist; run waf check to generate it.") ## run doxygen doxygen_config = os.path.join('doc', 'doxygen.conf') From 391adea51648aa9ec6ae63066c1fcab709a8a1af Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 15 Nov 2007 10:37:38 +0100 Subject: [PATCH 43/67] update ignore list --- .hgignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.hgignore b/.hgignore index 90e70c089..7d79571a0 100644 --- a/.hgignore +++ b/.hgignore @@ -8,4 +8,4 @@ ^doc/latex ^\.lock-wscript ^\.waf -^doc/trace-source-list\.h$ +^doc/introspected-doxygen\.h$ From 587d573a0437c6a99204a1438eab1aed2bd47419 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Thu, 15 Nov 2007 10:16:26 +0000 Subject: [PATCH 44/67] Add some missing NS_LOG_PARAM* definitions in optimized build --- src/core/log.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/log.h b/src/core/log.h index 7d12c3009..72c429bda 100644 --- a/src/core/log.h +++ b/src/core/log.h @@ -268,7 +268,10 @@ extern ParameterLogger g_parameterLogger; #define NS_LOG_DEBUG(msg) #define NS_LOG_INFO(msg) #define NS_LOG_FUNCTION -#define NS_LOG_PARAM(msg) +#define NS_LOG_PARAMS(parameters) +#define NS_LOG_PARAMS_BEGIN() +#define NS_LOG_PARAM(param) +#define NS_LOG_PARAMS_END() #define NS_LOG_LOGIC(msg) #define NS_LOG_UNCOND(msg) From 01d2d77a76afa04c023af959ec4fe2abce55171c Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 15 Nov 2007 13:03:09 +0100 Subject: [PATCH 45/67] backoff is finished when the end of backoff is _equal_ to now. --- src/devices/wifi/dcf-manager.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devices/wifi/dcf-manager.cc b/src/devices/wifi/dcf-manager.cc index 9ffbb75db..7b93da140 100644 --- a/src/devices/wifi/dcf-manager.cc +++ b/src/devices/wifi/dcf-manager.cc @@ -220,7 +220,7 @@ DcfManager::DoGrantAccess (void) { DcfState *state = *i; if (state->NeedsAccess () && - GetBackoffEndFor (state) < Simulator::Now ()) + GetBackoffEndFor (state) <= Simulator::Now ()) { /** * This is the first dcf we find with an expired backoff and which From 6aa4ae880af0a5febf9b1e4188d4e58888e8f959 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 15 Nov 2007 13:24:09 +0100 Subject: [PATCH 46/67] add a new test-case --- src/devices/wifi/dcf-manager-test.cc | 86 ++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 25 deletions(-) diff --git a/src/devices/wifi/dcf-manager-test.cc b/src/devices/wifi/dcf-manager-test.cc index e275d91c8..fcd5fd8de 100644 --- a/src/devices/wifi/dcf-manager-test.cc +++ b/src/devices/wifi/dcf-manager-test.cc @@ -42,8 +42,8 @@ private: void AddDcfState (uint32_t cwMin, uint32_t cwMax, uint32_t aifsn); void EndTest (void); void ExpectAccessGranted (uint64_t time, uint32_t from); - void ExpectInternalCollision (uint64_t time, uint32_t from); - void ExpectCollision (uint64_t time, uint32_t from); + void ExpectInternalCollision (uint64_t time, uint32_t from, uint32_t nSlots); + void ExpectCollision (uint64_t time, uint32_t from, uint32_t nSlots); void AddRxOkEvt (uint64_t at, uint64_t duration); void AddRxErrorEvt (uint64_t at, uint64_t duration); void AddTxEvt (uint64_t at, uint64_t duration); @@ -51,15 +51,21 @@ private: void AddNavStart (uint64_t at, uint64_t duration); void AddAccessRequest (uint64_t time, uint32_t from); + struct ExpectedCollision { + uint64_t at; + uint32_t from; + uint32_t nSlots; + }; typedef std::vector DcfStates; - typedef std::list > ExpectedEvent; + typedef std::list > ExpectedAccess; + typedef std::list ExpectedCollisions; DcfManager *m_dcfManager; MacParameters *m_parameters; DcfStates m_dcfStates; - ExpectedEvent m_expectedAccessGranted; - ExpectedEvent m_expectedInternalCollision; - ExpectedEvent m_expectedCollision; + ExpectedAccess m_expectedAccessGranted; + ExpectedCollisions m_expectedInternalCollision; + ExpectedCollisions m_expectedCollision; bool m_result; }; @@ -81,15 +87,11 @@ DcfStateTest::NotifyAccessGranted (void) void DcfStateTest::NotifyInternalCollision (void) { - UpdateFailedCw (); - StartBackoffNow (0); m_test->NotifyInternalCollision (m_i); } void DcfStateTest::NotifyCollision (void) { - UpdateFailedCw (); - StartBackoffNow (0); m_test->NotifyCollision (m_i); } @@ -106,8 +108,8 @@ DcfManagerTest::NotifyAccessGranted (uint32_t i) NS_TEST_ASSERT (!m_expectedAccessGranted.empty ()); std::pair expected = m_expectedAccessGranted.front (); m_expectedAccessGranted.pop_front (); - NS_TEST_ASSERT_EQUAL (MicroSeconds (expected.first), Simulator::Now ()); - NS_TEST_ASSERT_EQUAL (expected.second, i); + NS_TEST_ASSERT_EQUAL (Simulator::Now (), MicroSeconds (expected.first)); + NS_TEST_ASSERT_EQUAL (i, expected.second); if (!result) { m_result = result; @@ -118,10 +120,19 @@ DcfManagerTest::NotifyInternalCollision (uint32_t i) { bool result = true; NS_TEST_ASSERT (!m_expectedInternalCollision.empty ()); - std::pair expected = m_expectedInternalCollision.front (); + struct ExpectedCollision expected = m_expectedInternalCollision.front (); m_expectedInternalCollision.pop_front (); - NS_TEST_ASSERT_EQUAL (MicroSeconds (expected.first), Simulator::Now ()); - NS_TEST_ASSERT_EQUAL (expected.second, i); + NS_TEST_ASSERT_EQUAL (Simulator::Now (), MicroSeconds (expected.at)); + NS_TEST_ASSERT_EQUAL (i, expected.from); + uint32_t k = 0; + for (DcfStates::const_iterator j = m_dcfStates.begin (); j != m_dcfStates.end (); j++, k++) + { + if (i == k) + { + DcfState *state = *j; + state->StartBackoffNow (expected.nSlots); + } + } if (!result) { m_result = result; @@ -132,10 +143,12 @@ DcfManagerTest::NotifyCollision (uint32_t i) { bool result = true; NS_TEST_ASSERT (!m_expectedCollision.empty ()); - std::pair expected = m_expectedCollision.front (); + struct ExpectedCollision expected = m_expectedCollision.front (); m_expectedCollision.pop_front (); - NS_TEST_ASSERT_EQUAL (MicroSeconds (expected.first), Simulator::Now ()); - NS_TEST_ASSERT_EQUAL (expected.second, i); + NS_TEST_ASSERT_EQUAL (Simulator::Now (), MicroSeconds (expected.at)); + NS_TEST_ASSERT_EQUAL (i, expected.from); + DcfState *state = m_dcfStates[i]; + state->StartBackoffNow (expected.nSlots); if (!result) { m_result = result; @@ -149,14 +162,22 @@ DcfManagerTest::ExpectAccessGranted (uint64_t time, uint32_t from) m_expectedAccessGranted.push_back (std::make_pair (time, from)); } void -DcfManagerTest::ExpectInternalCollision (uint64_t time, uint32_t from) +DcfManagerTest::ExpectInternalCollision (uint64_t time, uint32_t nSlots, uint32_t from) { - m_expectedInternalCollision.push_back (std::make_pair (time, from)); + struct ExpectedCollision col; + col.at = time; + col.from = from; + col.nSlots = nSlots; + m_expectedInternalCollision.push_back (col); } void -DcfManagerTest::ExpectCollision (uint64_t time, uint32_t from) +DcfManagerTest::ExpectCollision (uint64_t time, uint32_t nSlots, uint32_t from) { - m_expectedCollision.push_back (std::make_pair (time, from)); + struct ExpectedCollision col; + col.at = time; + col.from = from; + col.nSlots = nSlots; + m_expectedCollision.push_back (col); } void @@ -258,11 +279,26 @@ DcfManagerTest::RunTests (void) StartTest (1 /* slot time */, 3 /* sifs */, 10 /* ack tx dur */); AddDcfState (8 /* cwmin */, 64 /* cwmax */, 1 /* aifsn */); AddAccessRequest (1 /* at */ , 0 /* from */); - ExpectAccessGranted (4 /* at */, 0 /* from */); - AddAccessRequest (10 /* at */ , 0 /* from */); - ExpectAccessGranted (10 /* at */, 0 /* from */); + ExpectAccessGranted (4, 0); + AddAccessRequest (10, 0); + ExpectAccessGranted (10, 0); EndTest (); + // + // 20 60 66 70 74 78 80 100 104 108 + // | rx | sifs | aifsn | bslot0 | bslot1 | | rx | blot2 | bslot3 | + // + // + StartTest (4, 6 , 10); + AddDcfState (8, 64, 1); + AddRxOkEvt (20, 40); + AddRxOkEvt (80, 20); + AddAccessRequest (30, 0); + ExpectCollision (30, 4, 0); // backoff: 4 slots + ExpectAccessGranted (108, 0); + EndTest (); + + return m_result; } From b15597dbe7b5af085db33566e117f6230c24a384 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 15 Nov 2007 13:37:38 +0100 Subject: [PATCH 47/67] forgot sifs + aifsn for test --- src/devices/wifi/dcf-manager-test.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/devices/wifi/dcf-manager-test.cc b/src/devices/wifi/dcf-manager-test.cc index fcd5fd8de..47d7a50b8 100644 --- a/src/devices/wifi/dcf-manager-test.cc +++ b/src/devices/wifi/dcf-manager-test.cc @@ -285,8 +285,8 @@ DcfManagerTest::RunTests (void) EndTest (); // - // 20 60 66 70 74 78 80 100 104 108 - // | rx | sifs | aifsn | bslot0 | bslot1 | | rx | blot2 | bslot3 | + // 20 60 66 70 74 78 80 100 106 110 114 118 + // | rx | sifs | aifsn | bslot0 | bslot1 | | rx | sifs | aifsn | bslot2 | bslot3 | // // StartTest (4, 6 , 10); @@ -295,7 +295,7 @@ DcfManagerTest::RunTests (void) AddRxOkEvt (80, 20); AddAccessRequest (30, 0); ExpectCollision (30, 4, 0); // backoff: 4 slots - ExpectAccessGranted (108, 0); + ExpectAccessGranted (118, 0); EndTest (); From b52be989ed82ce1c3c4e90be6f0748460f0c18a0 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 15 Nov 2007 13:37:51 +0100 Subject: [PATCH 48/67] start a backoff only if no backoff is started --- src/devices/wifi/dcf-manager.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/devices/wifi/dcf-manager.cc b/src/devices/wifi/dcf-manager.cc index 7b93da140..65b1c78be 100644 --- a/src/devices/wifi/dcf-manager.cc +++ b/src/devices/wifi/dcf-manager.cc @@ -65,6 +65,7 @@ void DcfState::StartBackoffNow (uint32_t nSlots) { NS_ASSERT (m_backoffSlots == 0); + MY_DEBUG ("start backoff="<GetBackoffSlots () == 0 && IsBusy ()) { MY_DEBUG ("medium is busy: collision"); From 03941802131dad47707d2affc384f3003abb180f Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 15 Nov 2007 13:44:58 +0100 Subject: [PATCH 49/67] a new test-case with some comments --- src/devices/wifi/dcf-manager-test.cc | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/devices/wifi/dcf-manager-test.cc b/src/devices/wifi/dcf-manager-test.cc index 47d7a50b8..0f44a2137 100644 --- a/src/devices/wifi/dcf-manager-test.cc +++ b/src/devices/wifi/dcf-manager-test.cc @@ -284,11 +284,15 @@ DcfManagerTest::RunTests (void) ExpectAccessGranted (10, 0); EndTest (); + // The test below mainly intends to test the case where the medium + // becomes busy in the middle of a backoff slot: the backoff counter + // must not be decremented for this backoff slot. This is the case + // below for the backoff slot starting at time 78us. // // 20 60 66 70 74 78 80 100 106 110 114 118 // | rx | sifs | aifsn | bslot0 | bslot1 | | rx | sifs | aifsn | bslot2 | bslot3 | - // - // + // | + // 30 request access. backoff slots: 4 StartTest (4, 6 , 10); AddDcfState (8, 64, 1); AddRxOkEvt (20, 40); @@ -298,6 +302,25 @@ DcfManagerTest::RunTests (void) ExpectAccessGranted (118, 0); EndTest (); + // The test below is subject to some discussion because I am + // not sure I understand the intent of the spec here. + // i.e., what happens if you make a request to get access + // to the medium during the difs idle time after a busy period ? + // do you need to start a backoff ? Or do you need to wait until + // the end of difs and access the medium ? + // Here, we wait until the end of difs and access the medium. + // + // 20 60 66 70 + // | rx | sifs | aifsn | + // | + // 62 request access. + // + StartTest (4, 6 , 10); + AddDcfState (8, 64, 1); + AddRxOkEvt (20, 40); + AddAccessRequest (62, 0); + ExpectAccessGranted (70, 0); + EndTest (); return m_result; } From 18e5bf9c075982b504ab40b647e90ea29c638524 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 15 Nov 2007 14:21:48 +0100 Subject: [PATCH 50/67] keep track of the last time a backoff was updated. --- src/devices/wifi/dcf-manager.cc | 8 +++++--- src/devices/wifi/dcf-manager.h | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/devices/wifi/dcf-manager.cc b/src/devices/wifi/dcf-manager.cc index 65b1c78be..17455f40a 100644 --- a/src/devices/wifi/dcf-manager.cc +++ b/src/devices/wifi/dcf-manager.cc @@ -55,10 +55,11 @@ DcfState::UpdateFailedCw (void) m_cw = cw; } void -DcfState::UpdateBackoffSlotsNow (uint32_t nSlots) +DcfState::UpdateBackoffSlotsNow (uint32_t nSlots, Time backoffUpdateBound) { uint32_t n = std::min (nSlots, m_backoffSlots); m_backoffSlots -= n; + m_backoffStart = backoffUpdateBound; } void @@ -319,7 +320,7 @@ DcfManager::UpdateBackoff (void) if (backoffStart <= Simulator::Now ()) { Scalar nSlots = (Simulator::Now () - backoffStart) / m_slotTime; - uint32_t nIntSlots = lrint (nSlots.GetDouble ()); + uint32_t nIntSlots = lrint (nSlots.GetDouble ()); /** * For each DcfState, calculate how many backoff slots elapsed since * the last time its backoff counter was updated. If the number of @@ -329,7 +330,8 @@ DcfManager::UpdateBackoff (void) if (nIntSlots > state->GetAifsn ()) { MY_DEBUG ("dcf " << k << " dec backoff slots=" << nIntSlots); - state->UpdateBackoffSlotsNow (nIntSlots); + Time backoffUpdateBound = backoffStart + Scalar (nIntSlots) * m_slotTime; + state->UpdateBackoffSlotsNow (nIntSlots, backoffUpdateBound); } } } diff --git a/src/devices/wifi/dcf-manager.h b/src/devices/wifi/dcf-manager.h index 1c70519eb..39e9089ea 100644 --- a/src/devices/wifi/dcf-manager.h +++ b/src/devices/wifi/dcf-manager.h @@ -29,7 +29,7 @@ private: uint32_t GetBackoffSlots (void) const; Time GetBackoffStart (void) const; - void UpdateBackoffSlotsNow (uint32_t nSlots); + void UpdateBackoffSlotsNow (uint32_t nSlots, Time backoffUpdateBound); virtual bool NeedsAccess (void) const = 0; virtual void NotifyAccessGranted (void) = 0; From 80ba6513757a65a1691c1086ecf82707073b70bf Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 15 Nov 2007 14:22:54 +0100 Subject: [PATCH 51/67] add a small comment --- src/devices/wifi/dcf-manager.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/devices/wifi/dcf-manager.h b/src/devices/wifi/dcf-manager.h index 39e9089ea..4db1c2acd 100644 --- a/src/devices/wifi/dcf-manager.h +++ b/src/devices/wifi/dcf-manager.h @@ -38,6 +38,9 @@ private: uint32_t m_aifsn; uint32_t m_backoffSlots; + // the backoffStart variable is used to keep track of the + // time at which a backoff was started or the time at which + // the backoff counter was last updated. Time m_backoffStart; uint32_t m_cwMin; uint32_t m_cwMax; From 842205687399d90b2874837df3eb3465f14a9739 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 15 Nov 2007 14:23:01 +0100 Subject: [PATCH 52/67] more working tests. --- src/devices/wifi/dcf-manager-test.cc | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/devices/wifi/dcf-manager-test.cc b/src/devices/wifi/dcf-manager-test.cc index 0f44a2137..344609b8f 100644 --- a/src/devices/wifi/dcf-manager-test.cc +++ b/src/devices/wifi/dcf-manager-test.cc @@ -302,6 +302,20 @@ DcfManagerTest::RunTests (void) ExpectAccessGranted (118, 0); EndTest (); + // Test the case where the backoff slots is zero. + // + // 20 60 66 70 + // | rx | sifs | aifsn | + // | + // 30 request access. backoff slots: 0 + StartTest (4, 6 , 10); + AddDcfState (8, 64, 1); + AddRxOkEvt (20, 40); + AddAccessRequest (30, 0); + ExpectCollision (30, 0, 0); // backoff: 0 slots + ExpectAccessGranted (70, 0); + EndTest (); + // The test below is subject to some discussion because I am // not sure I understand the intent of the spec here. // i.e., what happens if you make a request to get access @@ -322,6 +336,24 @@ DcfManagerTest::RunTests (void) ExpectAccessGranted (70, 0); EndTest (); + + // Test an EIFS + // + // 20 60 66 76 80 84 88 92 96 + // | rx | sifs | acktxttime | aifsn | bslot0 | bslot1 | bslot2 | bslot3 | + // | | <---------eifs----------->| + // 30 request access. backoff slots: 4 + StartTest (4, 6, 10); + AddDcfState (8, 64, 1); + AddRxErrorEvt (20, 40); + AddAccessRequest (30, 0); + ExpectCollision (30, 4, 0); // backoff: 4 slots + ExpectAccessGranted (96, 0); + EndTest (); + + + + return m_result; } From c6cfbd4e8c6b58aa2f988f15be052dce267ed3d7 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 15 Nov 2007 14:26:40 +0100 Subject: [PATCH 53/67] test interupted eifs --- src/devices/wifi/dcf-manager-test.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/devices/wifi/dcf-manager-test.cc b/src/devices/wifi/dcf-manager-test.cc index 344609b8f..812ae5a47 100644 --- a/src/devices/wifi/dcf-manager-test.cc +++ b/src/devices/wifi/dcf-manager-test.cc @@ -351,6 +351,21 @@ DcfManagerTest::RunTests (void) ExpectAccessGranted (96, 0); EndTest (); + // Test an EIFS which is interupted by a successfull transmission. + // + // 20 60 66 69 75 81 85 89 93 97 101 + // | rx | sifs | | rx | sifs | aifsn | bslot0 | bslot1 | bslot2 | bslot3 | + // | | <--eifs-->| + // 30 request access. backoff slots: 4 + StartTest (4, 6, 10); + AddDcfState (8, 64, 1); + AddRxErrorEvt (20, 40); + AddAccessRequest (30, 0); + ExpectCollision (30, 4, 0); // backoff: 4 slots + AddRxOkEvt (69, 6); + ExpectAccessGranted (101, 0); + EndTest (); + From 20f47863bf86bbc1bf5d4679b326f1a1e614e96e Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 15 Nov 2007 14:29:06 +0100 Subject: [PATCH 54/67] ignore cwmin/cwmax parameters since we set the backoff slots for every collision. --- src/devices/wifi/dcf-manager-test.cc | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/devices/wifi/dcf-manager-test.cc b/src/devices/wifi/dcf-manager-test.cc index 812ae5a47..c1eaae91a 100644 --- a/src/devices/wifi/dcf-manager-test.cc +++ b/src/devices/wifi/dcf-manager-test.cc @@ -39,7 +39,7 @@ public: private: void StartTest (uint64_t slotTime, uint64_t sifs, uint64_t ackTxDuration); - void AddDcfState (uint32_t cwMin, uint32_t cwMax, uint32_t aifsn); + void AddDcfState (uint32_t aifsn); void EndTest (void); void ExpectAccessGranted (uint64_t time, uint32_t from); void ExpectInternalCollision (uint64_t time, uint32_t from, uint32_t nSlots); @@ -190,10 +190,9 @@ DcfManagerTest::StartTest (uint64_t slotTime, uint64_t sifs, uint64_t ackTxDurat } void -DcfManagerTest::AddDcfState (uint32_t cwMin, uint32_t cwMax, uint32_t aifsn) +DcfManagerTest::AddDcfState (uint32_t aifsn) { DcfStateTest *state = new DcfStateTest (this, m_dcfStates.size ()); - state->SetCwBounds (cwMin, cwMax); state->SetAifsn (aifsn); m_dcfStates.push_back (state); m_dcfManager->Add (state); @@ -277,7 +276,7 @@ DcfManagerTest::RunTests (void) m_result = true; StartTest (1 /* slot time */, 3 /* sifs */, 10 /* ack tx dur */); - AddDcfState (8 /* cwmin */, 64 /* cwmax */, 1 /* aifsn */); + AddDcfState (1); AddAccessRequest (1 /* at */ , 0 /* from */); ExpectAccessGranted (4, 0); AddAccessRequest (10, 0); @@ -294,7 +293,7 @@ DcfManagerTest::RunTests (void) // | // 30 request access. backoff slots: 4 StartTest (4, 6 , 10); - AddDcfState (8, 64, 1); + AddDcfState (1); AddRxOkEvt (20, 40); AddRxOkEvt (80, 20); AddAccessRequest (30, 0); @@ -309,7 +308,7 @@ DcfManagerTest::RunTests (void) // | // 30 request access. backoff slots: 0 StartTest (4, 6 , 10); - AddDcfState (8, 64, 1); + AddDcfState (1); AddRxOkEvt (20, 40); AddAccessRequest (30, 0); ExpectCollision (30, 0, 0); // backoff: 0 slots @@ -330,7 +329,7 @@ DcfManagerTest::RunTests (void) // 62 request access. // StartTest (4, 6 , 10); - AddDcfState (8, 64, 1); + AddDcfState (1); AddRxOkEvt (20, 40); AddAccessRequest (62, 0); ExpectAccessGranted (70, 0); @@ -344,7 +343,7 @@ DcfManagerTest::RunTests (void) // | | <---------eifs----------->| // 30 request access. backoff slots: 4 StartTest (4, 6, 10); - AddDcfState (8, 64, 1); + AddDcfState (1); AddRxErrorEvt (20, 40); AddAccessRequest (30, 0); ExpectCollision (30, 4, 0); // backoff: 4 slots @@ -358,7 +357,7 @@ DcfManagerTest::RunTests (void) // | | <--eifs-->| // 30 request access. backoff slots: 4 StartTest (4, 6, 10); - AddDcfState (8, 64, 1); + AddDcfState (1); AddRxErrorEvt (20, 40); AddAccessRequest (30, 0); ExpectCollision (30, 4, 0); // backoff: 4 slots @@ -366,9 +365,6 @@ DcfManagerTest::RunTests (void) ExpectAccessGranted (101, 0); EndTest (); - - - return m_result; } From cfd44fc50c7cea18631147da4fb2c013e9b0e3a9 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 15 Nov 2007 14:42:16 +0100 Subject: [PATCH 55/67] even if an access timer is running, we need to start a backoff if needed --- src/devices/wifi/dcf-manager.cc | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/devices/wifi/dcf-manager.cc b/src/devices/wifi/dcf-manager.cc index 17455f40a..90b443bd7 100644 --- a/src/devices/wifi/dcf-manager.cc +++ b/src/devices/wifi/dcf-manager.cc @@ -185,19 +185,10 @@ void DcfManager::RequestAccess (DcfState *state) { UpdateBackoff (); - if (m_accessTimeout.IsRunning ()) - { - /* we don't need to do anything because we have an access - * timer which will expire soon. - */ - MY_DEBUG ("access timer running. will be notified"); - return; - } /** - * Since no access timeout is running, and if we have no - * backoff running for this DcfState, start a new backoff - * if needed. - */ + * If there is a collision, generate a backoff + * by notifying the collision to the user. + */ if (state->GetBackoffSlots () == 0 && IsBusy ()) { @@ -207,7 +198,6 @@ DcfManager::RequestAccess (DcfState *state) */ state->NotifyCollision (); } - DoGrantAccess (); DoRestartAccessTimeoutIfNeeded (); } From 5ecad32251ab80d821fea15cda447b61e3d9bed1 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 15 Nov 2007 14:50:27 +0100 Subject: [PATCH 56/67] if the backoff end is now, the backoff is expired. --- src/devices/wifi/dcf-manager.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devices/wifi/dcf-manager.cc b/src/devices/wifi/dcf-manager.cc index 90b443bd7..3c32d1099 100644 --- a/src/devices/wifi/dcf-manager.cc +++ b/src/devices/wifi/dcf-manager.cc @@ -226,7 +226,7 @@ DcfManager::DoGrantAccess (void) { DcfState *state = *j; if (state->NeedsAccess () && - GetBackoffEndFor (state) < Simulator::Now ()) + GetBackoffEndFor (state) <= Simulator::Now ()) { MY_DEBUG ("dcf " << k << " needs access. backoff expired. internal collision."); /** From 225df7593f80d0a12d2f26cdbcb4a2e98ea2823d Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 15 Nov 2007 16:23:26 +0100 Subject: [PATCH 57/67] backoff end time is never in the past. --- src/devices/wifi/dcf-manager.cc | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/devices/wifi/dcf-manager.cc b/src/devices/wifi/dcf-manager.cc index 3c32d1099..ebd7f4e24 100644 --- a/src/devices/wifi/dcf-manager.cc +++ b/src/devices/wifi/dcf-manager.cc @@ -341,29 +341,30 @@ DcfManager::DoRestartAccessTimeoutIfNeeded (void) DcfState *state = *i; if (state->NeedsAccess ()) { - accessTimeoutNeeded = true; - expectedBackoffEnd = std::min (expectedBackoffEnd, GetBackoffEndFor (state)); + Time tmp = GetBackoffEndFor (state); + if (tmp > Simulator::Now ()) + { + accessTimeoutNeeded = true; + expectedBackoffEnd = std::min (expectedBackoffEnd, tmp); + } } } if (accessTimeoutNeeded) { MY_DEBUG ("expected backoff end="< Simulator::Now ()) + Time expectedBackoffDelay = expectedBackoffEnd - Simulator::Now (); + if (m_accessTimeout.IsRunning () && + Simulator::GetDelayLeft (m_accessTimeout) > expectedBackoffDelay) { - Time expectedBackoffDelay = expectedBackoffEnd - Simulator::Now (); - if (m_accessTimeout.IsRunning () && - Simulator::GetDelayLeft (m_accessTimeout) > expectedBackoffDelay) - { - m_accessTimeout.Cancel (); - } - if (m_accessTimeout.IsExpired ()) - { - m_accessTimeout = Simulator::Schedule (expectedBackoffDelay, - &DcfManager::AccessTimeout, this); - } + m_accessTimeout.Cancel (); + } + if (m_accessTimeout.IsExpired ()) + { + m_accessTimeout = Simulator::Schedule (expectedBackoffDelay, + &DcfManager::AccessTimeout, this); } } -} + } void DcfManager::NotifyRxStartNow (Time duration) From ac99f9e46c94ae3fbbb363998fae76ee89a50e87 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 15 Nov 2007 16:34:41 +0100 Subject: [PATCH 58/67] we need to accumulate a record of all changes before applying them in one go. --- src/devices/wifi/dcf-manager.cc | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/devices/wifi/dcf-manager.cc b/src/devices/wifi/dcf-manager.cc index ebd7f4e24..9126c1585 100644 --- a/src/devices/wifi/dcf-manager.cc +++ b/src/devices/wifi/dcf-manager.cc @@ -219,14 +219,14 @@ DcfManager::DoGrantAccess (void) * needs access to the medium. i.e., it has data to send. */ MY_DEBUG ("dcf " << k << " needs access. backoff expired. access granted."); - state->NotifyAccessGranted (); i++; // go to the next item in the list. k++; + std::vector internalCollisionStates; for (States::const_iterator j = i; j != m_states.end (); j++, k++) { - DcfState *state = *j; - if (state->NeedsAccess () && - GetBackoffEndFor (state) <= Simulator::Now ()) + DcfState *otherState = *j; + if (otherState->NeedsAccess () && + GetBackoffEndFor (otherState) <= Simulator::Now ()) { MY_DEBUG ("dcf " << k << " needs access. backoff expired. internal collision."); /** @@ -234,9 +234,23 @@ DcfManager::DoGrantAccess (void) * has expired and which needed access to the medium * must be notified that we did get an internal collision. */ - state->NotifyInternalCollision (); + internalCollisionStates.push_back (otherState); } } + + /** + * Now, we notify all of these changes in one go. It is necessary to + * perform first the calculations of which states are colliding and then + * only apply the changes because applying the changes through notification + * could change the global state of the manager, and, thus, could change + * the result of the calculations. + */ + state->NotifyAccessGranted (); + for (std::vector::const_iterator k = internalCollisionStates.begin (); + k != internalCollisionStates.end (); k++) + { + (*k)->NotifyInternalCollision (); + } break; } i++; From f992fe0b8d0a03dd39a0d279700df39e8673423a Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 15 Nov 2007 16:34:53 +0100 Subject: [PATCH 59/67] test internal collisions. --- src/devices/wifi/dcf-manager-test.cc | 191 +++++++++++++++------------ 1 file changed, 103 insertions(+), 88 deletions(-) diff --git a/src/devices/wifi/dcf-manager-test.cc b/src/devices/wifi/dcf-manager-test.cc index c1eaae91a..7f3b32e06 100644 --- a/src/devices/wifi/dcf-manager-test.cc +++ b/src/devices/wifi/dcf-manager-test.cc @@ -6,6 +6,7 @@ #include "dcf-manager.h" #include "mac-parameters.h" + namespace ns3 { class DcfManagerTest; @@ -14,12 +15,25 @@ class DcfStateTest : public DcfState { public: DcfStateTest (DcfManagerTest *test, uint32_t i); + void QueueTx (uint64_t txTime, uint64_t expectedGrantTime); private: + friend class DcfManagerTest; virtual bool NeedsAccess (void) const; virtual void NotifyAccessGranted (void); virtual void NotifyInternalCollision (void); virtual void NotifyCollision (void); + typedef std::pair ExpectedGrant; + typedef std::list ExpectedGrants; + struct ExpectedCollision { + uint64_t at; + uint32_t nSlots; + }; + typedef std::list ExpectedCollisions; + + ExpectedCollisions m_expectedInternalCollision; + ExpectedCollisions m_expectedCollision; + ExpectedGrants m_expectedGrants; DcfManagerTest *m_test; uint32_t m_i; }; @@ -41,31 +55,21 @@ private: void StartTest (uint64_t slotTime, uint64_t sifs, uint64_t ackTxDuration); void AddDcfState (uint32_t aifsn); void EndTest (void); - void ExpectAccessGranted (uint64_t time, uint32_t from); void ExpectInternalCollision (uint64_t time, uint32_t from, uint32_t nSlots); void ExpectCollision (uint64_t time, uint32_t from, uint32_t nSlots); void AddRxOkEvt (uint64_t at, uint64_t duration); void AddRxErrorEvt (uint64_t at, uint64_t duration); - void AddTxEvt (uint64_t at, uint64_t duration); void AddNavReset (uint64_t at, uint64_t duration); void AddNavStart (uint64_t at, uint64_t duration); - void AddAccessRequest (uint64_t time, uint32_t from); + void AddAccessRequest (uint64_t at, uint64_t txTime, + uint64_t expectedGrantTime, uint32_t from); + void DoAccessRequest (uint64_t txTime, uint64_t expectedGrantTime, DcfStateTest *state); - struct ExpectedCollision { - uint64_t at; - uint32_t from; - uint32_t nSlots; - }; typedef std::vector DcfStates; - typedef std::list > ExpectedAccess; - typedef std::list ExpectedCollisions; DcfManager *m_dcfManager; MacParameters *m_parameters; DcfStates m_dcfStates; - ExpectedAccess m_expectedAccessGranted; - ExpectedCollisions m_expectedInternalCollision; - ExpectedCollisions m_expectedCollision; bool m_result; }; @@ -74,10 +78,15 @@ private: DcfStateTest::DcfStateTest (DcfManagerTest *test, uint32_t i) : m_test (test), m_i(i) {} +void +DcfStateTest::QueueTx (uint64_t txTime, uint64_t expectedGrantTime) +{ + m_expectedGrants.push_back (std::make_pair (txTime, expectedGrantTime)); +} bool DcfStateTest::NeedsAccess (void) const { - return true; + return !m_expectedGrants.empty (); } void DcfStateTest::NotifyAccessGranted (void) @@ -104,12 +113,13 @@ DcfManagerTest::DcfManagerTest () void DcfManagerTest::NotifyAccessGranted (uint32_t i) { + DcfStateTest *state = m_dcfStates[i]; bool result = true; - NS_TEST_ASSERT (!m_expectedAccessGranted.empty ()); - std::pair expected = m_expectedAccessGranted.front (); - m_expectedAccessGranted.pop_front (); - NS_TEST_ASSERT_EQUAL (Simulator::Now (), MicroSeconds (expected.first)); - NS_TEST_ASSERT_EQUAL (i, expected.second); + NS_TEST_ASSERT (!state->m_expectedGrants.empty ()); + std::pair expected = state->m_expectedGrants.front (); + state->m_expectedGrants.pop_front (); + NS_TEST_ASSERT_EQUAL (Simulator::Now (), MicroSeconds (expected.second)); + m_dcfManager->NotifyTxStartNow (MicroSeconds (expected.first)); if (!result) { m_result = result; @@ -118,21 +128,13 @@ DcfManagerTest::NotifyAccessGranted (uint32_t i) void DcfManagerTest::NotifyInternalCollision (uint32_t i) { + DcfStateTest *state = m_dcfStates[i]; bool result = true; - NS_TEST_ASSERT (!m_expectedInternalCollision.empty ()); - struct ExpectedCollision expected = m_expectedInternalCollision.front (); - m_expectedInternalCollision.pop_front (); + NS_TEST_ASSERT (!state->m_expectedInternalCollision.empty ()); + struct DcfStateTest::ExpectedCollision expected = state->m_expectedInternalCollision.front (); + state->m_expectedInternalCollision.pop_front (); NS_TEST_ASSERT_EQUAL (Simulator::Now (), MicroSeconds (expected.at)); - NS_TEST_ASSERT_EQUAL (i, expected.from); - uint32_t k = 0; - for (DcfStates::const_iterator j = m_dcfStates.begin (); j != m_dcfStates.end (); j++, k++) - { - if (i == k) - { - DcfState *state = *j; - state->StartBackoffNow (expected.nSlots); - } - } + state->StartBackoffNow (expected.nSlots); if (!result) { m_result = result; @@ -141,13 +143,12 @@ DcfManagerTest::NotifyInternalCollision (uint32_t i) void DcfManagerTest::NotifyCollision (uint32_t i) { + DcfStateTest *state = m_dcfStates[i]; bool result = true; - NS_TEST_ASSERT (!m_expectedCollision.empty ()); - struct ExpectedCollision expected = m_expectedCollision.front (); - m_expectedCollision.pop_front (); + NS_TEST_ASSERT (!state->m_expectedCollision.empty ()); + struct DcfStateTest::ExpectedCollision expected = state->m_expectedCollision.front (); + state->m_expectedCollision.pop_front (); NS_TEST_ASSERT_EQUAL (Simulator::Now (), MicroSeconds (expected.at)); - NS_TEST_ASSERT_EQUAL (i, expected.from); - DcfState *state = m_dcfStates[i]; state->StartBackoffNow (expected.nSlots); if (!result) { @@ -156,28 +157,23 @@ DcfManagerTest::NotifyCollision (uint32_t i) } -void -DcfManagerTest::ExpectAccessGranted (uint64_t time, uint32_t from) -{ - m_expectedAccessGranted.push_back (std::make_pair (time, from)); -} void DcfManagerTest::ExpectInternalCollision (uint64_t time, uint32_t nSlots, uint32_t from) { - struct ExpectedCollision col; + DcfStateTest *state = m_dcfStates[from]; + struct DcfStateTest::ExpectedCollision col; col.at = time; - col.from = from; col.nSlots = nSlots; - m_expectedInternalCollision.push_back (col); + state->m_expectedInternalCollision.push_back (col); } void DcfManagerTest::ExpectCollision (uint64_t time, uint32_t nSlots, uint32_t from) { - struct ExpectedCollision col; + DcfStateTest *state = m_dcfStates[from]; + struct DcfStateTest::ExpectedCollision col; col.at = time; - col.from = from; col.nSlots = nSlots; - m_expectedCollision.push_back (col); + state->m_expectedCollision.push_back (col); } void @@ -203,13 +199,14 @@ DcfManagerTest::EndTest (void) { bool result = true; Simulator::Run (); - NS_TEST_ASSERT (m_expectedAccessGranted.empty ()); - NS_TEST_ASSERT (m_expectedInternalCollision.empty ()); - NS_TEST_ASSERT (m_expectedCollision.empty ()); Simulator::Destroy (); for (DcfStates::const_iterator i = m_dcfStates.begin (); i != m_dcfStates.end (); i++) { - delete *i; + DcfStateTest *state = *i; + NS_TEST_ASSERT (state->m_expectedGrants.empty ()); + NS_TEST_ASSERT (state->m_expectedInternalCollision.empty ()); + NS_TEST_ASSERT (state->m_expectedCollision.empty ()); + delete state; } m_dcfStates.clear (); delete m_dcfManager; @@ -238,13 +235,7 @@ DcfManagerTest::AddRxErrorEvt (uint64_t at, uint64_t duration) Simulator::Schedule (MicroSeconds (at+duration) - Now (), &DcfManager::NotifyRxEndErrorNow, m_dcfManager); } -void -DcfManagerTest::AddTxEvt (uint64_t at, uint64_t duration) -{ - Simulator::Schedule (MicroSeconds (at) - Now (), - &DcfManager::NotifyTxStartNow, m_dcfManager, - MicroSeconds (duration)); -} + void DcfManagerTest::AddNavReset (uint64_t at, uint64_t duration) { @@ -260,11 +251,19 @@ DcfManagerTest::AddNavStart (uint64_t at, uint64_t duration) MicroSeconds (duration)); } void -DcfManagerTest::AddAccessRequest (uint64_t time, uint32_t from) +DcfManagerTest::AddAccessRequest (uint64_t at, uint64_t txTime, + uint64_t expectedGrantTime, uint32_t from) { - Simulator::Schedule (MicroSeconds (time) - Now (), - &DcfManager::RequestAccess, - m_dcfManager, m_dcfStates[from]); + Simulator::Schedule (MicroSeconds (at) - Now (), + &DcfManagerTest::DoAccessRequest, this, + txTime, expectedGrantTime, m_dcfStates[from]); +} + +void +DcfManagerTest::DoAccessRequest (uint64_t txTime, uint64_t expectedGrantTime, DcfStateTest *state) +{ + state->QueueTx (txTime, expectedGrantTime); + m_dcfManager->RequestAccess (state); } @@ -275,12 +274,13 @@ DcfManagerTest::RunTests (void) { m_result = true; - StartTest (1 /* slot time */, 3 /* sifs */, 10 /* ack tx dur */); + // 0 3 4 5 8 9 10 12 + // | sifs | aifsn | tx | sifs | aifsn | | tx | + // + StartTest (1, 3, 10); AddDcfState (1); - AddAccessRequest (1 /* at */ , 0 /* from */); - ExpectAccessGranted (4, 0); - AddAccessRequest (10, 0); - ExpectAccessGranted (10, 0); + AddAccessRequest (1, 1, 4, 0); + AddAccessRequest (10, 2, 10, 0); EndTest (); // The test below mainly intends to test the case where the medium @@ -288,31 +288,29 @@ DcfManagerTest::RunTests (void) // must not be decremented for this backoff slot. This is the case // below for the backoff slot starting at time 78us. // - // 20 60 66 70 74 78 80 100 106 110 114 118 - // | rx | sifs | aifsn | bslot0 | bslot1 | | rx | sifs | aifsn | bslot2 | bslot3 | + // 20 60 66 70 74 78 80 100 106 110 114 118 120 + // | rx | sifs | aifsn | bslot0 | bslot1 | | rx | sifs | aifsn | bslot2 | bslot3 | tx | // | // 30 request access. backoff slots: 4 StartTest (4, 6 , 10); AddDcfState (1); AddRxOkEvt (20, 40); AddRxOkEvt (80, 20); - AddAccessRequest (30, 0); + AddAccessRequest (30, 2, 118, 0); ExpectCollision (30, 4, 0); // backoff: 4 slots - ExpectAccessGranted (118, 0); EndTest (); // Test the case where the backoff slots is zero. // - // 20 60 66 70 - // | rx | sifs | aifsn | + // 20 60 66 70 72 + // | rx | sifs | aifsn | tx | // | // 30 request access. backoff slots: 0 StartTest (4, 6 , 10); AddDcfState (1); AddRxOkEvt (20, 40); - AddAccessRequest (30, 0); + AddAccessRequest (30, 2, 70, 0); ExpectCollision (30, 0, 0); // backoff: 0 slots - ExpectAccessGranted (70, 0); EndTest (); // The test below is subject to some discussion because I am @@ -323,46 +321,63 @@ DcfManagerTest::RunTests (void) // the end of difs and access the medium ? // Here, we wait until the end of difs and access the medium. // - // 20 60 66 70 - // | rx | sifs | aifsn | + // 20 60 66 70 72 + // | rx | sifs | aifsn | tx | // | // 62 request access. // StartTest (4, 6 , 10); AddDcfState (1); AddRxOkEvt (20, 40); - AddAccessRequest (62, 0); - ExpectAccessGranted (70, 0); + AddAccessRequest (62, 2, 70, 0); EndTest (); // Test an EIFS // - // 20 60 66 76 80 84 88 92 96 - // | rx | sifs | acktxttime | aifsn | bslot0 | bslot1 | bslot2 | bslot3 | + // 20 60 66 76 80 84 88 92 96 98 + // | rx | sifs | acktxttime | aifsn | bslot0 | bslot1 | bslot2 | bslot3 | tx | // | | <---------eifs----------->| // 30 request access. backoff slots: 4 StartTest (4, 6, 10); AddDcfState (1); AddRxErrorEvt (20, 40); - AddAccessRequest (30, 0); + AddAccessRequest (30, 2, 96, 0); ExpectCollision (30, 4, 0); // backoff: 4 slots - ExpectAccessGranted (96, 0); EndTest (); // Test an EIFS which is interupted by a successfull transmission. // - // 20 60 66 69 75 81 85 89 93 97 101 - // | rx | sifs | | rx | sifs | aifsn | bslot0 | bslot1 | bslot2 | bslot3 | + // 20 60 66 69 75 81 85 89 93 97 101 103 + // | rx | sifs | | rx | sifs | aifsn | bslot0 | bslot1 | bslot2 | bslot3 | tx | // | | <--eifs-->| // 30 request access. backoff slots: 4 StartTest (4, 6, 10); AddDcfState (1); AddRxErrorEvt (20, 40); - AddAccessRequest (30, 0); + AddAccessRequest (30, 2, 101, 0); ExpectCollision (30, 4, 0); // backoff: 4 slots AddRxOkEvt (69, 6); - ExpectAccessGranted (101, 0); + EndTest (); + + + // Test two DCFs which suffer an internal collision. the first DCF has a higher + // priority than the second DCF. + // + // 20 60 66 70 74 78 88 + // DCF0 | rx | sifs | aifsn | bslot0 | bslot1 | tx | + // DCF1 | rx | sifs | aifsn | aifsn | aifsn | | sifs | aifsn | aifsn | aifsn | bslot | tx | + // 94 98 102 106 110 112 + StartTest (4, 6, 10); + AddDcfState (1); // high priority DCF + AddDcfState (3); // low priority DCF + AddRxOkEvt (20, 40); + AddAccessRequest (30, 10, 78, 0); + ExpectCollision (30, 2, 0); // backoff: 2 slot + + AddAccessRequest (40, 2, 110, 1); + ExpectCollision (40, 0, 1); // backoff: 0 slot + ExpectInternalCollision (78, 1, 1); // backoff: 1 slot EndTest (); return m_result; From fc099a35ab7c8dd054d79661611f82787ba6cd00 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Thu, 15 Nov 2007 15:42:07 +0000 Subject: [PATCH 60/67] Add DropTailQueue unit tests. --- src/node/drop-tail-queue.cc | 65 +++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/node/drop-tail-queue.cc b/src/node/drop-tail-queue.cc index a4fb979bb..7b88231ab 100644 --- a/src/node/drop-tail-queue.cc +++ b/src/node/drop-tail-queue.cc @@ -111,4 +111,69 @@ DropTailQueue::DoPeek (Packet& p) return true; } +} // namespace ns3 + + +#ifdef RUN_SELF_TESTS + +#include "ns3/test.h" + +namespace ns3 { + +class DropTailQueueTest: public Test { +public: + virtual bool RunTests (void); + DropTailQueueTest (); +}; + + +DropTailQueueTest::DropTailQueueTest () + : Test ("DropTailQueue") {} + + +bool +DropTailQueueTest::RunTests (void) +{ + bool result = true; + + DropTailQueue queue; + queue.SetMaxPackets (3); + + Packet p1, p2, p3, p4; + + NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 0); + queue.Enqueue (p1); + NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 1); + queue.Enqueue (p2); + NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 2); + queue.Enqueue (p3); + NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 3); + queue.Enqueue (p4); // will be dropped + NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 3); + + Packet p; + + NS_TEST_ASSERT (queue.Dequeue (p)); + NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 2); + NS_TEST_ASSERT_EQUAL (p.GetUid (), p1.GetUid ()); + + NS_TEST_ASSERT (queue.Dequeue (p)); + NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 1); + NS_TEST_ASSERT_EQUAL (p.GetUid (), p2.GetUid ()); + + NS_TEST_ASSERT (queue.Dequeue (p)); + NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 0); + NS_TEST_ASSERT_EQUAL (p.GetUid (), p3.GetUid ()); + + NS_TEST_ASSERT (!queue.Dequeue (p)); + + return result; +} + + +static DropTailQueueTest gDropTailQueueTest; + }; // namespace ns3 + +#endif /* RUN_SELF_TESTS */ + From 11a58a55c367a68b969eff96aa76e57b4883799c Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Thu, 15 Nov 2007 16:08:28 +0000 Subject: [PATCH 61/67] Add a few NS_LOG_LOGIC calls in PacketSocket::SendTo () --- src/node/packet-socket.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/node/packet-socket.cc b/src/node/packet-socket.cc index 448b84334..000d95966 100644 --- a/src/node/packet-socket.cc +++ b/src/node/packet-socket.cc @@ -222,22 +222,26 @@ PacketSocket::SendTo(const Address &address, const Packet &p) PacketSocketAddress ad; if (m_state == STATE_CLOSED) { + NS_LOG_LOGIC ("ERROR_BADF"); m_errno = ERROR_BADF; return -1; } if (m_state == STATE_OPEN) { // XXX should return another error here. + NS_LOG_LOGIC ("ERROR_INVAL"); m_errno = ERROR_INVAL; return -1; } if (m_shutdownSend) { + NS_LOG_LOGIC ("ERROR_SHUTDOWN"); m_errno = ERROR_SHUTDOWN; return -1; } if (!PacketSocketAddress::IsMatchingType (address)) { + NS_LOG_LOGIC ("ERROR_AFNOSUPPORT"); m_errno = ERROR_AFNOSUPPORT; return -1; } @@ -250,6 +254,7 @@ PacketSocket::SendTo(const Address &address, const Packet &p) Ptr device = m_node->GetDevice (ad.GetSingleDevice ()); if (!device->Send (p, dest, ad.GetProtocol ())) { + NS_LOG_LOGIC ("error: NetDevice::Send error"); error = true; } } @@ -260,6 +265,7 @@ PacketSocket::SendTo(const Address &address, const Packet &p) Ptr device = m_node->GetDevice (i); if (!device->Send (p, dest, ad.GetProtocol ())) { + NS_LOG_LOGIC ("error: NetDevice::Send error"); error = true; } } @@ -271,6 +277,7 @@ PacketSocket::SendTo(const Address &address, const Packet &p) if (error) { + NS_LOG_LOGIC ("ERROR_INVAL 2"); m_errno = ERROR_INVAL; return -1; } From 71c53d9f3dac4d01c443f00aa6d1f3f88c9c2a8d Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Thu, 15 Nov 2007 18:56:34 -0800 Subject: [PATCH 62/67] move in topo --- src/devices/point-to-point/wscript | 2 -- .../point-to-point-ipv4-topology.cc | 4 +-- .../point-to-point-ipv4-topology.h | 0 tutorial/tutorial-star-routing.cc | 3 +- tutorial/tutorial-star.cc | 3 +- tutorial/wscript | 36 ++++++++----------- 6 files changed, 20 insertions(+), 28 deletions(-) rename {src/devices/point-to-point => tutorial}/point-to-point-ipv4-topology.cc (95%) rename {src/devices/point-to-point => tutorial}/point-to-point-ipv4-topology.h (100%) diff --git a/src/devices/point-to-point/wscript b/src/devices/point-to-point/wscript index 7ec56847c..c788a7880 100644 --- a/src/devices/point-to-point/wscript +++ b/src/devices/point-to-point/wscript @@ -7,13 +7,11 @@ def build(bld): 'point-to-point-net-device.cc', 'point-to-point-channel.cc', 'point-to-point-topology.cc', - 'point-to-point-ipv4-topology.cc', ] headers = bld.create_obj('ns3header') headers.source = [ 'point-to-point-net-device.h', 'point-to-point-channel.h', 'point-to-point-topology.h', - 'point-to-point-ipv4-topology.h', ] diff --git a/src/devices/point-to-point/point-to-point-ipv4-topology.cc b/tutorial/point-to-point-ipv4-topology.cc similarity index 95% rename from src/devices/point-to-point/point-to-point-ipv4-topology.cc rename to tutorial/point-to-point-ipv4-topology.cc index bc4a21967..d508f84d5 100644 --- a/src/devices/point-to-point/point-to-point-ipv4-topology.cc +++ b/tutorial/point-to-point-ipv4-topology.cc @@ -22,8 +22,8 @@ #include "ns3/ipv4.h" #include "ns3/queue.h" -#include "point-to-point-channel.h" -#include "point-to-point-net-device.h" +#include "ns3/point-to-point-channel.h" +#include "ns3/point-to-point-net-device.h" #include "point-to-point-ipv4-topology.h" namespace ns3 { diff --git a/src/devices/point-to-point/point-to-point-ipv4-topology.h b/tutorial/point-to-point-ipv4-topology.h similarity index 100% rename from src/devices/point-to-point/point-to-point-ipv4-topology.h rename to tutorial/point-to-point-ipv4-topology.h diff --git a/tutorial/tutorial-star-routing.cc b/tutorial/tutorial-star-routing.cc index a0db26180..765b3ee4c 100644 --- a/tutorial/tutorial-star-routing.cc +++ b/tutorial/tutorial-star-routing.cc @@ -20,7 +20,6 @@ #include "ns3/point-to-point-channel.h" #include "ns3/mac48-address.h" #include "ns3/point-to-point-net-device.h" -#include "ns3/point-to-point-ipv4-topology.h" #include "ns3/udp-echo-client.h" #include "ns3/udp-echo-server.h" #include "ns3/simulator.h" @@ -29,6 +28,8 @@ #include "ns3/pcap-trace.h" #include "ns3/global-route-manager.h" +#include "point-to-point-ipv4-topology.h" + NS_LOG_COMPONENT_DEFINE ("StarRoutingSimulation"); using namespace ns3; diff --git a/tutorial/tutorial-star.cc b/tutorial/tutorial-star.cc index 38ff6100e..fbcccf5a9 100644 --- a/tutorial/tutorial-star.cc +++ b/tutorial/tutorial-star.cc @@ -20,7 +20,6 @@ #include "ns3/point-to-point-channel.h" #include "ns3/mac48-address.h" #include "ns3/point-to-point-net-device.h" -#include "ns3/point-to-point-ipv4-topology.h" #include "ns3/udp-echo-client.h" #include "ns3/udp-echo-server.h" #include "ns3/simulator.h" @@ -29,6 +28,8 @@ #include "ns3/pcap-trace.h" #include "ns3/global-route-manager.h" +#include "point-to-point-ipv4-topology.h" + NS_LOG_COMPONENT_DEFINE ("StarSimulation"); using namespace ns3; diff --git a/tutorial/wscript b/tutorial/wscript index 6b8ba9d31..388c9f21b 100644 --- a/tutorial/wscript +++ b/tutorial/wscript @@ -1,44 +1,36 @@ ## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- def build(bld): - obj = bld.create_ns3_program('hello-simulator', - ['core']) + obj = bld.create_ns3_program('hello-simulator', ['core']) obj.source = 'hello-simulator.cc' - obj = bld.create_ns3_program('tutorial-csma-echo', - ['core']) + obj = bld.create_ns3_program('tutorial-csma-echo', ['core']) obj.source = 'tutorial-csma-echo.cc' - obj = bld.create_ns3_program('tutorial-csma-echo-ascii-trace', - ['core']) + obj = bld.create_ns3_program('tutorial-csma-echo-ascii-trace', ['core']) obj.source = 'tutorial-csma-echo-ascii-trace.cc' - obj = bld.create_ns3_program('tutorial-csma-echo-pcap-trace', - ['core']) + obj = bld.create_ns3_program('tutorial-csma-echo-pcap-trace', ['core']) obj.source = 'tutorial-csma-echo-pcap-trace.cc' - obj = bld.create_ns3_program('tutorial-point-to-point', - ['core']) + obj = bld.create_ns3_program('tutorial-point-to-point', ['core']) obj.source = 'tutorial-point-to-point.cc' - obj = bld.create_ns3_program('tutorial-star', - ['core']) - obj.source = 'tutorial-star.cc' + obj = bld.create_ns3_program('tutorial-star', ['core']) + obj.source = ['tutorial-star.cc', + 'point-to-point-ipv4-topology.cc'] - obj = bld.create_ns3_program('tutorial-star-routing', - ['core']) - obj.source = 'tutorial-star-routing.cc' + obj = bld.create_ns3_program('tutorial-star-routing', ['core']) + obj.source = ['tutorial-star-routing.cc', + 'point-to-point-ipv4-topology.cc'] - obj = bld.create_ns3_program('tutorial-linear-dumbbell', - ['core']) + obj = bld.create_ns3_program('tutorial-linear-dumbbell', ['core']) obj.source = 'tutorial-linear-dumbbell.cc' - obj = bld.create_ns3_program('testipv4', - ['core']) + obj = bld.create_ns3_program('testipv4', ['core']) obj.source = ['testipv4.cc', 'ipv4-address-generator.cc'] - obj = bld.create_ns3_program('tutorial-bus-network', - ['core']) + obj = bld.create_ns3_program('tutorial-bus-network', ['core']) obj.source = ['tutorial-bus-network.cc', 'ipv4-bus-network.cc', 'ipv4-address-generator.cc'] From d1865a2c1ece066bf346ca55bfa719abc4bbbf1c Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Thu, 15 Nov 2007 19:21:06 -0800 Subject: [PATCH 63/67] release files --- RELEASE_NOTES | 5 +++++ VERSION | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 4aff62726..3c6a78ebb 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -3,6 +3,11 @@ This file contains ns-3 release notes (most recent releases first). +Release 3.0.8 (2007/11/15) +======================== + - A simple error model + - Source files for ns-3 tutorial + Release 3.0.7 (2007/10/15) ======================== - OLSR routing protocol diff --git a/VERSION b/VERSION index 2451c27ca..67786e246 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.0.7 +3.0.8 From 577373aed98b463f1c46dea13ad721f08d86e958 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Thu, 15 Nov 2007 19:52:53 -0800 Subject: [PATCH 64/67] Added tag release ns-3.0.8 for changeset 560a5091e0e6 --- .hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgtags b/.hgtags index 45520a625..b4fa52149 100644 --- a/.hgtags +++ b/.hgtags @@ -7,3 +7,4 @@ 267e2ebc28e4e4ae2f579e1cfc29902acade0c34 buffer-working-before-breaking 606df29888e7573b825fc891a002f0757166b616 release ns-3.0.6 36472385a1cc7c44d34fb7a5951b930010f4e8d2 release ns-3.0.7 +560a5091e0e6ded47d269e2f2dee780f13950a63 release ns-3.0.8 From 125796fec74222ba47abd077757902401b2be105 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 16 Nov 2007 08:54:16 +0100 Subject: [PATCH 65/67] simple NAV test --- src/devices/wifi/dcf-manager-test.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/devices/wifi/dcf-manager-test.cc b/src/devices/wifi/dcf-manager-test.cc index 7f3b32e06..c2286afa7 100644 --- a/src/devices/wifi/dcf-manager-test.cc +++ b/src/devices/wifi/dcf-manager-test.cc @@ -380,6 +380,21 @@ DcfManagerTest::RunTests (void) ExpectInternalCollision (78, 1, 1); // backoff: 1 slot EndTest (); + + // test simple NAV count + // + // + StartTest (4, 6, 10); + AddDcfState (1); + AddRxOkEvt (20, 40); + AddNavStart (60, 11); + AddRxOkEvt (66, 5); + AddNavStart (71, 0); + AddAccessRequest (30, 10, 89, 0); + ExpectCollision (30, 2, 0); // backoff: 2 slot + EndTest (); + + return m_result; } From 50cd61e7c3271a6b1b78c53aab5332a7b6b163bf Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 16 Nov 2007 08:56:03 +0100 Subject: [PATCH 66/67] more comment on the test --- src/devices/wifi/dcf-manager-test.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/devices/wifi/dcf-manager-test.cc b/src/devices/wifi/dcf-manager-test.cc index c2286afa7..9b5f478e9 100644 --- a/src/devices/wifi/dcf-manager-test.cc +++ b/src/devices/wifi/dcf-manager-test.cc @@ -381,16 +381,18 @@ DcfManagerTest::RunTests (void) EndTest (); - // test simple NAV count // + // test simple NAV count. This scenario modelizes a simple DATA+ACK handshake + // where the data rate used for the ACK is higher than expected by the DATA source + // so, the data exchange completes before the end of nav. // StartTest (4, 6, 10); AddDcfState (1); AddRxOkEvt (20, 40); - AddNavStart (60, 11); + AddNavStart (60, 15); AddRxOkEvt (66, 5); AddNavStart (71, 0); - AddAccessRequest (30, 10, 89, 0); + AddAccessRequest (30, 10, 93, 0); ExpectCollision (30, 2, 0); // backoff: 2 slot EndTest (); From bdc6fcf5dd57619f1b21ce9de91950caf51cb3ea Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 16 Nov 2007 08:58:55 +0100 Subject: [PATCH 67/67] another more complex NAV test --- src/devices/wifi/dcf-manager-test.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/devices/wifi/dcf-manager-test.cc b/src/devices/wifi/dcf-manager-test.cc index 9b5f478e9..3517c9531 100644 --- a/src/devices/wifi/dcf-manager-test.cc +++ b/src/devices/wifi/dcf-manager-test.cc @@ -395,6 +395,22 @@ DcfManagerTest::RunTests (void) AddAccessRequest (30, 10, 93, 0); ExpectCollision (30, 2, 0); // backoff: 2 slot EndTest (); + + + // + // test more complex NAV handling by a CF-poll. This scenario modelizes a + // simple DATA+ACK handshake interrupted by a CF-poll which resets the + // NAV counter. + // + StartTest (4, 6, 10); + AddDcfState (1); + AddRxOkEvt (20, 40); + AddNavStart (60, 15); + AddRxOkEvt (66, 5); + AddNavReset (71, 2); + AddAccessRequest (30, 10, 91, 0); + ExpectCollision (30, 2, 0); // backoff: 2 slot + EndTest (); return m_result;