From 9059dd7e3e18849e54c1a6f289f6c4eaa12e30c1 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Wed, 3 Oct 2007 12:41:17 -0700 Subject: [PATCH 01/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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 873a2c8dda5164faf07b515c2b54fa5a46122955 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 15 Nov 2007 10:23:54 +0100 Subject: [PATCH 14/23] 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 15/23] 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 16/23] 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 17/23] 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 18/23] 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 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 19/23] 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 20/23] 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 21/23] 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 22/23] 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 23/23] 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