From 84bdfa4ac58ca6b017d5ea20f8c43cba3f458eac Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 6 Feb 2007 20:40:38 +0100 Subject: [PATCH 01/25] add debugging support --- SConstruct | 16 ++++++ src/core/debug.cc | 133 ++++++++++++++++++++++++++++++++++++++++++++++ src/core/debug.h | 64 ++++++++++++++++++++++ 3 files changed, 213 insertions(+) create mode 100644 src/core/debug.cc create mode 100644 src/core/debug.h diff --git a/SConstruct b/SConstruct index af7467119..65bc9736e 100644 --- a/SConstruct +++ b/SConstruct @@ -18,6 +18,7 @@ ns3.add(core) core.add_sources([ 'reference-list-test.cc', 'callback-test.cc', + 'debug.cc', 'ptr.cc', 'test.cc' ]) @@ -39,9 +40,24 @@ core.add_inst_headers([ 'reference-list.h', 'callback.h', 'ptr.h', + 'debug.h', 'test.h' ]) +def config_core (env, config): + retval = [] + # XXX This check is primitive but it should be + # good enough for now. + if config.CheckCHeader ('stdlib.h') == 1: + retval.append ('#define HAVE_STDLIB_H 1') + retval.append ('#define HAVE_GETENV 1') + else: + retval.append ('#undef HAVE_STDLIB_H') + retval.append ('#undef HAVE_GETENV') + return retval +core.add_config (config_core) + + # # The Simu module diff --git a/src/core/debug.cc b/src/core/debug.cc new file mode 100644 index 000000000..11892bc4b --- /dev/null +++ b/src/core/debug.cc @@ -0,0 +1,133 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2006 INRIA + * All rights reserved. + * + * 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 +#include +#include +#include +#include "debug.h" +#include "ns3/core-config.h" + +#ifdef HAVE_STDLIB_H +#include +#endif + +namespace ns3 { + +typedef std::list > ComponentList; +typedef std::list >::iterator ComponentListI; + +static ComponentList g_components; + +DebugComponent::DebugComponent (std::string name) + : m_isEnabled (false) +{ + for (ComponentListI i = g_components.begin (); + i != g_components.end (); + i++) + { + assert (i->first.compare (name) != 0); + } + g_components.push_back (std::make_pair (name, this)); +} +bool +DebugComponent::IsEnabled (void) +{ + return m_isEnabled; +} +void +DebugComponent::Enable (void) +{ + m_isEnabled = true; +} +void +DebugComponent::Disable (void) +{ + m_isEnabled = false; +} + +void +DebugComponentEnable (char const *name) +{ + for (ComponentListI i = g_components.begin (); + i != g_components.end (); + i++) + { + if (i->first.compare (name) == 0) + { + i->second->Enable (); + break; + } + } +} +void +DebugComponentDisable (char const *name) +{ + for (ComponentListI i = g_components.begin (); + i != g_components.end (); + i++) + { + if (i->first.compare (name) == 0) + { + i->second->Disable (); + break; + } + } +} + +void +DebugComponentEnableEnvVar (void) +{ +#ifdef HAVE_GETENV + char *envVar = getenv("NS3_DEBUG"); + if (envVar == 0) + { + return; + } + std::string env = envVar; + std::string::size_type cur = 0; + std::string::size_type next = 0; + while (true) + { + next = env.find_first_of (";", cur); + if (next == std::string::npos) + { + std::string tmp = env.substr (cur, next); + DebugComponentEnable (tmp.c_str ()); + } + cur = next; + } +#endif +} + +void +DebugComponentPrintList (void) +{ + for (ComponentListI i = g_components.begin (); + i != g_components.end (); + i++) + { + std::cout << i->first << "=" << (i->second->IsEnabled ()?"enabled":"disabled") << std::endl; + } +} + + + +}; // namespace ns3 diff --git a/src/core/debug.h b/src/core/debug.h new file mode 100644 index 000000000..e1b241824 --- /dev/null +++ b/src/core/debug.h @@ -0,0 +1,64 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2006 INRIA + * All rights reserved. + * + * 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 DEBUG_H +#define DEBUG_H + +#include +#include + +namespace ns3 { + +void DebugComponentEnable (char const *name); +void DebugComponentDisable (char const *name); +void DebugComponentEnableEnvVar (void); +void DebugComponentPrintList (void); + +class DebugComponent { +public: + DebugComponent (std::string name); + bool IsEnabled (void); + void Enable (void); + void Disable (void); +private: + bool m_isEnabled; +}; + +}; // namespace ns3 + + +#ifdef NS3_DEBUG_ENABLE + +#define DEBUG_COMPONENT_DEFINE(name) \ + static DebugComponent g_debug = DebugComponent (name); + +#define DEBUG(x) \ + if (g_debug.IsEnabled ()) \ + { \ + std::cout << x << std::endl; \ + } +#else /* NS3_DEBUG_ENABLE */ + +#define DEBUG_COMPONENT_DEFINE(name) +#define DEBUG(x) + +#endif /* NS3_DEBUG_ENABLE */ + +#endif /* DEBUG_H */ From 8cfa657d892f1c5a1b7b2f8437c45d0a6bfb1f0e Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 6 Feb 2007 21:42:31 +0100 Subject: [PATCH 02/25] remove EnableEnvVar function --- src/core/debug.cc | 70 +++++++++++++++++++++++++++++++---------------- src/core/debug.h | 1 - 2 files changed, 46 insertions(+), 25 deletions(-) diff --git a/src/core/debug.cc b/src/core/debug.cc index 11892bc4b..f2764eb89 100644 --- a/src/core/debug.cc +++ b/src/core/debug.cc @@ -35,6 +35,48 @@ typedef std::list > ComponentList; typedef std::list >::iterator ComponentListI; static ComponentList g_components; +static bool g_firstDebug = true; + +void +DebugComponentEnableEnvVar (void) +{ +#ifdef HAVE_GETENV + char *envVar = getenv("NS3_DEBUG"); + if (envVar == 0) + { + return; + } + std::string env = envVar; + std::string::size_type cur = 0; + std::string::size_type next = 0; + while (true) + { + next = env.find_first_of (";", cur); + if (next == std::string::npos) + { + std::string tmp = env.substr (cur, next); + bool found = false; + for (ComponentListI i = g_components.begin (); + i != g_components.end (); + i++) + { + if (i->first.compare (tmp) == 0) + { + found = true; + i->second->Enable (); + break; + } + } + if (!found) + { + std::cout << "No debug component named=\"" << tmp << "\"" << std::endl; + } + } + cur = next; + } +#endif +} + DebugComponent::DebugComponent (std::string name) : m_isEnabled (false) @@ -55,6 +97,10 @@ DebugComponent::IsEnabled (void) void DebugComponent::Enable (void) { + if (g_firstDebug) { + DebugComponentEnableEnvVar (); + g_firstDebug = false; + } m_isEnabled = true; } void @@ -92,30 +138,6 @@ DebugComponentDisable (char const *name) } } -void -DebugComponentEnableEnvVar (void) -{ -#ifdef HAVE_GETENV - char *envVar = getenv("NS3_DEBUG"); - if (envVar == 0) - { - return; - } - std::string env = envVar; - std::string::size_type cur = 0; - std::string::size_type next = 0; - while (true) - { - next = env.find_first_of (";", cur); - if (next == std::string::npos) - { - std::string tmp = env.substr (cur, next); - DebugComponentEnable (tmp.c_str ()); - } - cur = next; - } -#endif -} void DebugComponentPrintList (void) diff --git a/src/core/debug.h b/src/core/debug.h index e1b241824..7dbddda5e 100644 --- a/src/core/debug.h +++ b/src/core/debug.h @@ -28,7 +28,6 @@ namespace ns3 { void DebugComponentEnable (char const *name); void DebugComponentDisable (char const *name); -void DebugComponentEnableEnvVar (void); void DebugComponentPrintList (void); class DebugComponent { From 95778d9453bda7dede108af9ca086ec68105f11f Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 7 Feb 2007 08:29:01 +0100 Subject: [PATCH 03/25] define NS3_DEBBUG_ENABLE when needed --- build.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/build.py b/build.py index 02868a0b0..6c048a89a 100644 --- a/build.py +++ b/build.py @@ -458,8 +458,9 @@ class Ns3: dbg_env = env.Copy() - env.Append(CFLAGS = debug_flags, - CXXFLAGS = debug_flags, ) + dbg_env.Append(CFLAGS = debug_flags, + CXXFLAGS = debug_flags, + CPPDEFINES = ['NS3_DEBUG_ENABLE']) # debug static support variant.static = True variant.env = dbg_env @@ -469,8 +470,9 @@ class Ns3: dbg_env.Alias('dbg-static', builder) dbg_env = env.Copy() - env.Append(CFLAGS=debug_flags, - CXXFLAGS=debug_flags, ) + dbg_env.Append(CFLAGS=debug_flags, + CXXFLAGS=debug_flags, + CPPDEFINES = ['NS3_DEBUG_ENABLE']) # debug shared support variant.static = False variant.env = dbg_env From 7abd85418369f1a55726bbfdaa8195790e7b853f Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 7 Feb 2007 08:49:54 +0100 Subject: [PATCH 04/25] test and debug the debug support --- SConstruct | 7 ++++ samples/main-debug-other.cc | 13 ++++++++ samples/main-debug.cc | 18 ++++++++++ src/core/debug.cc | 66 ++++++++++++++++++++++++------------- src/core/debug.h | 10 +++--- 5 files changed, 86 insertions(+), 28 deletions(-) create mode 100644 samples/main-debug-other.cc create mode 100644 samples/main-debug.cc diff --git a/SConstruct b/SConstruct index 65bc9736e..db6f8c9b5 100644 --- a/SConstruct +++ b/SConstruct @@ -183,6 +183,13 @@ replay_simu.add_source('replay-simulation.cc') # samples +sample_debug = build.Ns3Module('sample-debug', 'samples') +sample_debug.set_executable() +ns3.add(sample_debug) +sample_debug.add_dep('core') +sample_debug.add_source('main-debug.cc') +sample_debug.add_source('main-debug-other.cc') + sample_callback = build.Ns3Module('sample-callback', 'samples') sample_callback.set_executable() ns3.add(sample_callback) diff --git a/samples/main-debug-other.cc b/samples/main-debug-other.cc new file mode 100644 index 000000000..2ce182f8c --- /dev/null +++ b/samples/main-debug-other.cc @@ -0,0 +1,13 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +#include "ns3/debug.h" + +NS3_DEBUG_COMPONENT_DEFINE ("MyComponentB"); + +namespace foo { + +void OneFunction (void) +{ + NS3_DEBUG ("OneFunction debug"); +} + +}; // namespace foo diff --git a/samples/main-debug.cc b/samples/main-debug.cc new file mode 100644 index 000000000..332e693f2 --- /dev/null +++ b/samples/main-debug.cc @@ -0,0 +1,18 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +#include "ns3/debug.h" + +NS3_DEBUG_COMPONENT_DEFINE ("MyComponentA"); + +// declare other function +namespace foo { +void OneFunction (void); +} + +int main (int argc, int argv) +{ + NS3_DEBUG ("nargc="<first.compare (tmp) == 0) { - if (i->first.compare (tmp) == 0) - { - found = true; - i->second->Enable (); - break; - } + found = true; + i->second->Enable (); + break; } - if (!found) - { - std::cout << "No debug component named=\"" << tmp << "\"" << std::endl; - } - } - cur = next; + } + if (!found) + { + std::cout << "No debug component named=\"" << tmp << "\"" << std::endl; + } + if (next == std::string::npos) + { + break; + } + cur = next + 1; + if (cur >= env.size ()) + { + break; + } } #endif } @@ -92,15 +110,15 @@ DebugComponent::DebugComponent (std::string name) bool DebugComponent::IsEnabled (void) { + if (g_firstDebug) { + DebugComponentEnableEnvVar (); + g_firstDebug = false; + } return m_isEnabled; } void DebugComponent::Enable (void) { - if (g_firstDebug) { - DebugComponentEnableEnvVar (); - g_firstDebug = false; - } m_isEnabled = true; } void @@ -153,3 +171,5 @@ DebugComponentPrintList (void) }; // namespace ns3 + + diff --git a/src/core/debug.h b/src/core/debug.h index 7dbddda5e..c64f88e45 100644 --- a/src/core/debug.h +++ b/src/core/debug.h @@ -45,18 +45,18 @@ private: #ifdef NS3_DEBUG_ENABLE -#define DEBUG_COMPONENT_DEFINE(name) \ - static DebugComponent g_debug = DebugComponent (name); +#define NS3_DEBUG_COMPONENT_DEFINE(name) \ + static ns3::DebugComponent g_debug = ns3::DebugComponent (name); -#define DEBUG(x) \ +#define NS3_DEBUG(x) \ if (g_debug.IsEnabled ()) \ { \ std::cout << x << std::endl; \ } #else /* NS3_DEBUG_ENABLE */ -#define DEBUG_COMPONENT_DEFINE(name) -#define DEBUG(x) +#define NS3_DEBUG_COMPONENT_DEFINE(name) +#define NS3_DEBUG(x) #endif /* NS3_DEBUG_ENABLE */ From bd19595461a80ad40b678b573d1322f77fcdec47 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 13 Feb 2007 09:45:32 +0100 Subject: [PATCH 05/25] add NS3_ASSERT and NS3_ASSERT_MSG --- samples/main-debug.cc | 7 +++++++ src/core/debug.cc | 6 ++++++ src/core/debug.h | 21 +++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/samples/main-debug.cc b/samples/main-debug.cc index 332e693f2..d10f5169d 100644 --- a/samples/main-debug.cc +++ b/samples/main-debug.cc @@ -15,4 +15,11 @@ int main (int argc, int argv) foo::OneFunction (); NS3_DEBUG ("other debug output"); + + int a = 0; + + NS3_ASSERT (a == 0); + NS3_ASSERT_MSG (a == 0, "my msg"); + NS3_ASSERT (a != 0) + NS3_ASSERT_MSG (a != 0, "my 2 msg"); } diff --git a/src/core/debug.cc b/src/core/debug.cc index addfa6b1c..a0da17a5e 100644 --- a/src/core/debug.cc +++ b/src/core/debug.cc @@ -168,6 +168,12 @@ DebugComponentPrintList (void) } } +void +AssertBreakpoint (void) +{ + int *a = 0; + a = 0; +} }; // namespace ns3 diff --git a/src/core/debug.h b/src/core/debug.h index c64f88e45..458d1f243 100644 --- a/src/core/debug.h +++ b/src/core/debug.h @@ -40,6 +40,8 @@ private: bool m_isEnabled; }; +void AssertBreakpoint (void); + }; // namespace ns3 @@ -53,10 +55,29 @@ private: { \ std::cout << x << std::endl; \ } + +#define NS3_ASSERT(condition) \ + if (!(condition)) \ + { \ + std::cout << "assert failed. file=" << __FILE__ << \ + ", line=" << __LINE__ << ", cond=\""#condition << \ + "\"" << std::endl; \ + ns3::AssertBreakpoint (); \ + } + +#define NS3_ASSERT_MSG(condition, message) \ + if (!(condition)) \ + { \ + std::cout << message << std::endl; \ + ns3::AssertBreakpoint (); \ + } + #else /* NS3_DEBUG_ENABLE */ #define NS3_DEBUG_COMPONENT_DEFINE(name) #define NS3_DEBUG(x) +#define NS3_ASSERT(cond) +#define NS3_ASSERT_MSG(cond) #endif /* NS3_DEBUG_ENABLE */ From f5fee4c7af0eb6d5f1934ca6d44fc5c44723ee91 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 13 Feb 2007 09:52:42 +0100 Subject: [PATCH 06/25] really trigger segfault when needed --- src/core/debug.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/debug.cc b/src/core/debug.cc index a0da17a5e..178f01735 100644 --- a/src/core/debug.cc +++ b/src/core/debug.cc @@ -172,7 +172,7 @@ void AssertBreakpoint (void) { int *a = 0; - a = 0; + *a = 0; } From cb102a5d0b52311a7f63c223247d89047b4c1fbe Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 13 Feb 2007 10:22:49 +0100 Subject: [PATCH 07/25] improve assert brekapoint function --- src/core/debug.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/core/debug.cc b/src/core/debug.cc index 178f01735..162e23578 100644 --- a/src/core/debug.cc +++ b/src/core/debug.cc @@ -172,7 +172,15 @@ void AssertBreakpoint (void) { int *a = 0; - *a = 0; + /** + * we test here to allow a debugger to change the value of + * the variable 'a' to allow the debugger to avoid the + * subsequent segfault. + */ + if (a == 0) + { + *a = 0; + } } From 310f67b83550e0a76fe50f28480af73ee015fe97 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 13 Feb 2007 10:23:10 +0100 Subject: [PATCH 08/25] avoid warning in optimized builds --- samples/main-debug.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/main-debug.cc b/samples/main-debug.cc index d10f5169d..dda796bd9 100644 --- a/samples/main-debug.cc +++ b/samples/main-debug.cc @@ -16,7 +16,8 @@ int main (int argc, int argv) NS3_DEBUG ("other debug output"); - int a = 0; + int a; + a = 0; NS3_ASSERT (a == 0); NS3_ASSERT_MSG (a == 0, "my msg"); From b2c8866cbff478c352f194bb162036d3d8fc0feb Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 13 Feb 2007 10:23:31 +0100 Subject: [PATCH 09/25] make sure tha NS3_DEBUG_ENABLE is defined by doxygen preprocessor --- doc/doxygen.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/doxygen.conf b/doc/doxygen.conf index 61806a900..07fbd04c4 100644 --- a/doc/doxygen.conf +++ b/doc/doxygen.conf @@ -996,7 +996,7 @@ INCLUDE_FILE_PATTERNS = # undefined via #undef or recursively expanded use the := operator # instead of the = operator. -PREDEFINED = RUN_SELF_TESTS +PREDEFINED = RUN_SELF_TESTS NS3_DEBUG_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. From 42ea8aabe07ff2d54f96f6ce09c555baae5285f7 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 13 Feb 2007 10:23:47 +0100 Subject: [PATCH 10/25] add API doc --- src/core/debug.h | 98 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 3 deletions(-) diff --git a/src/core/debug.h b/src/core/debug.h index 458d1f243..d1aecbb18 100644 --- a/src/core/debug.h +++ b/src/core/debug.h @@ -24,10 +24,53 @@ #include #include +/** + * \defgroup debugging + * \brief Debugging functions and macros + * + * The ns3 debugging support provides a few simple macros + * for debugging and sending out messages to the user. There + * two classes of functionality: + * - ASSERT functionality: macros which are used to verify + * at runtime that a certain condition is true. If it is + * not true, the program halts. These checks are built + * into the program only in debugging builds. They are + * removed in optimized builds. + * + * - DEBUG functionality: macros which allow developers to + * send information out on screen only in debugging builds. + * All debug messages are disabled by default. To enable + * selected debug messages, use the ns3::DebugComponentEnable + * function. Alternatively, you can use the NS3_DEBUG + * environment variable to define a ';'-separated list of + * messages to enable. For example, NS3_DEBUG=a;b;c;DAFD;GH + * would enable the components 'a', 'b', 'c', 'DAFD', and, 'GH'. + */ + namespace ns3 { +/** + * \param name a debug component name + * \ingroup debugging + * + * Enable the debugging output associated with that debug component. + * The debugging output can be later disabled with a call + * to ns3::DebugComponentDisable. + */ void DebugComponentEnable (char const *name); +/** + * \param name a debug component name + * \ingroup debugging + * + * Disable the debugging output associated with that debug component. + * The debugging output can be later re-enabled with a call + * to ns3::DebugComponentEnable. + */ void DebugComponentDisable (char const *name); +/** + * \ingroup debugging + * Print the list of debugging messages available. + */ void DebugComponentPrintList (void); class DebugComponent { @@ -40,6 +83,15 @@ private: bool m_isEnabled; }; +/** + * \ingroup debugging + * + * When an NS3_ASSERT cannot verify its condition, + * this function is called. This is where you should + * be able to put a breakpoint with a debugger if + * you want to catch assertions before the program + * halts. + */ void AssertBreakpoint (void); }; // namespace ns3 @@ -47,15 +99,46 @@ void AssertBreakpoint (void); #ifdef NS3_DEBUG_ENABLE +/** + * \ingroup debugging + * \param name a string + * + * Define a Debug component with a specific name. This macro + * should be used at the top of every file in which you want + * to use the NS3_DEBUG macro. This macro defines a new + * "debug component" which can be later selectively enabled + * or disabled with the ns3::DebugComponentEnable and + * ns3::DebugComponentDisable functions or with the NS3_DEBUG + * environment variable. + */ #define NS3_DEBUG_COMPONENT_DEFINE(name) \ static ns3::DebugComponent g_debug = ns3::DebugComponent (name); -#define NS3_DEBUG(x) \ +/** + * \ingroup debugging + * \param msg message to output + * + * Generate debugging output in the "debug component" of the + * current file. i.e., every call to NS3_DEBUG from within + * a file implicitely generates out within the component + * defined with the NS3_DEBUG_COMPONENT_DEFINE macro in the + * same file. + */ +#define NS3_DEBUG(msg) \ if (g_debug.IsEnabled ()) \ { \ - std::cout << x << std::endl; \ + std::cout << msg << std::endl; \ } +/** + * \ingroup debugging + * \param condition condition to verifiy. + * + * At runtime, in debugging builds, if this condition is not + * true, the program prints the source file, line number and + * unverified condition and halts in the ns3::AssertBreakpoint + * function. + */ #define NS3_ASSERT(condition) \ if (!(condition)) \ { \ @@ -65,6 +148,15 @@ void AssertBreakpoint (void); ns3::AssertBreakpoint (); \ } +/** + * \ingroup debugging + * \param condition condition to verifiy. + * \param message message to output + * + * At runtime, in debugging builds, if this condition is not + * true, the program prints the message to output and + * halts in the ns3::AssertBreakpoint function. + */ #define NS3_ASSERT_MSG(condition, message) \ if (!(condition)) \ { \ @@ -77,7 +169,7 @@ void AssertBreakpoint (void); #define NS3_DEBUG_COMPONENT_DEFINE(name) #define NS3_DEBUG(x) #define NS3_ASSERT(cond) -#define NS3_ASSERT_MSG(cond) +#define NS3_ASSERT_MSG(cond,msg) #endif /* NS3_DEBUG_ENABLE */ From 06788bac2715c6517d90330c92fe62d031edeeaf Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 13 Feb 2007 18:20:24 +0100 Subject: [PATCH 11/25] regex: s/NS3_/NS_/ --- samples/main-debug-other.cc | 4 ++-- samples/main-debug.cc | 14 +++++++------- src/core/debug.h | 30 +++++++++++++++--------------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/samples/main-debug-other.cc b/samples/main-debug-other.cc index 2ce182f8c..da7587506 100644 --- a/samples/main-debug-other.cc +++ b/samples/main-debug-other.cc @@ -1,13 +1,13 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ #include "ns3/debug.h" -NS3_DEBUG_COMPONENT_DEFINE ("MyComponentB"); +NS_DEBUG_COMPONENT_DEFINE ("MyComponentB"); namespace foo { void OneFunction (void) { - NS3_DEBUG ("OneFunction debug"); + NS_DEBUG ("OneFunction debug"); } }; // namespace foo diff --git a/samples/main-debug.cc b/samples/main-debug.cc index dda796bd9..303775582 100644 --- a/samples/main-debug.cc +++ b/samples/main-debug.cc @@ -1,7 +1,7 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ #include "ns3/debug.h" -NS3_DEBUG_COMPONENT_DEFINE ("MyComponentA"); +NS_DEBUG_COMPONENT_DEFINE ("MyComponentA"); // declare other function namespace foo { @@ -10,17 +10,17 @@ void OneFunction (void); int main (int argc, int argv) { - NS3_DEBUG ("nargc="< + */ + +#include "assert.h" + +namespace ns3 { + +void +AssertBreakpoint (void) +{ + int *a = 0; + /** + * we test here to allow a debugger to change the value of + * the variable 'a' to allow the debugger to avoid the + * subsequent segfault. + */ + if (a == 0) + { + *a = 0; + } +} + +}//namespace ns3 diff --git a/src/core/assert.h b/src/core/assert.h new file mode 100644 index 000000000..bf3fed648 --- /dev/null +++ b/src/core/assert.h @@ -0,0 +1,95 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2006 INRIA + * All rights reserved. + * + * 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 ASSERT_H +#define ASSERT_H + +/** + * \defgroup assert + * \brief assert functions and macros + * + * The assert macros are used to verify + * at runtime that a certain condition is true. If it is + * not true, the program halts. These checks are built + * into the program only in debugging builds. They are + * removed in optimized builds. + */ + +namespace ns3 { + +/** + * \ingroup debugging + * + * When an NS_ASSERT cannot verify its condition, + * this function is called. This is where you should + * be able to put a breakpoint with a debugger if + * you want to catch assertions before the program + * halts. + */ +void AssertBreakpoint (void); + +}//namespace ns3 + +#ifdef NS3_ASSERT_ENABLE + +#include + +/** + * \ingroup assert + * \param condition condition to verifiy. + * + * At runtime, in debugging builds, if this condition is not + * true, the program prints the source file, line number and + * unverified condition and halts in the ns3::AssertBreakpoint + * function. + */ +#define NS_ASSERT(condition) \ + if (!(condition)) \ + { \ + std::cout << "assert failed. file=" << __FILE__ << \ + ", line=" << __LINE__ << ", cond=\""#condition << \ + "\"" << std::endl; \ + ns3::AssertBreakpoint (); \ + } + +/** + * \ingroup assert + * \param condition condition to verifiy. + * \param message message to output + * + * At runtime, in debugging builds, if this condition is not + * true, the program prints the message to output and + * halts in the ns3::AssertBreakpoint function. + */ +#define NS_ASSERT_MSG(condition, message) \ + if (!(condition)) \ + { \ + std::cout << message << std::endl; \ + ns3::AssertBreakpoint (); \ + } + +#else /* NS3_ASSERT_ENABLE */ + +#define NS_ASSERT(cond) +#define NS_ASSERT_MSG(cond,msg) + +#endif /* NS3_ASSERT_ENABLE */ + +#endif /* ASSERT_H */ diff --git a/src/core/debug.cc b/src/core/debug.cc index 162e23578..a250be103 100644 --- a/src/core/debug.cc +++ b/src/core/debug.cc @@ -96,7 +96,7 @@ DebugComponentEnableEnvVar (void) } -DebugComponent::DebugComponent (std::string name) +DebugComponent::DebugComponent (char const * name) : m_isEnabled (false) { for (ComponentListI i = g_components.begin (); @@ -168,22 +168,6 @@ DebugComponentPrintList (void) } } -void -AssertBreakpoint (void) -{ - int *a = 0; - /** - * we test here to allow a debugger to change the value of - * the variable 'a' to allow the debugger to avoid the - * subsequent segfault. - */ - if (a == 0) - { - *a = 0; - } -} - - }; // namespace ns3 diff --git a/src/core/debug.h b/src/core/debug.h index 51705241b..31253d4a8 100644 --- a/src/core/debug.h +++ b/src/core/debug.h @@ -21,22 +21,10 @@ #ifndef DEBUG_H #define DEBUG_H -#include -#include - /** * \defgroup debugging * \brief Debugging functions and macros * - * The ns3 debugging support provides a few simple macros - * for debugging and sending out messages to the user. There - * two classes of functionality: - * - ASSERT functionality: macros which are used to verify - * at runtime that a certain condition is true. If it is - * not true, the program halts. These checks are built - * into the program only in debugging builds. They are - * removed in optimized builds. - * * - DEBUG functionality: macros which allow developers to * send information out on screen only in debugging builds. * All debug messages are disabled by default. To enable @@ -75,7 +63,7 @@ void DebugComponentPrintList (void); class DebugComponent { public: - DebugComponent (std::string name); + DebugComponent (char const *name); bool IsEnabled (void); void Enable (void); void Disable (void); @@ -83,22 +71,15 @@ private: bool m_isEnabled; }; -/** - * \ingroup debugging - * - * When an NS_ASSERT cannot verify its condition, - * this function is called. This is where you should - * be able to put a breakpoint with a debugger if - * you want to catch assertions before the program - * halts. - */ -void AssertBreakpoint (void); - }; // namespace ns3 #ifdef NS3_DEBUG_ENABLE +#include +#include + + /** * \ingroup debugging * \param name a string @@ -130,46 +111,10 @@ void AssertBreakpoint (void); std::cout << msg << std::endl; \ } -/** - * \ingroup debugging - * \param condition condition to verifiy. - * - * At runtime, in debugging builds, if this condition is not - * true, the program prints the source file, line number and - * unverified condition and halts in the ns3::AssertBreakpoint - * function. - */ -#define NS_ASSERT(condition) \ - if (!(condition)) \ - { \ - std::cout << "assert failed. file=" << __FILE__ << \ - ", line=" << __LINE__ << ", cond=\""#condition << \ - "\"" << std::endl; \ - ns3::AssertBreakpoint (); \ - } - -/** - * \ingroup debugging - * \param condition condition to verifiy. - * \param message message to output - * - * At runtime, in debugging builds, if this condition is not - * true, the program prints the message to output and - * halts in the ns3::AssertBreakpoint function. - */ -#define NS_ASSERT_MSG(condition, message) \ - if (!(condition)) \ - { \ - std::cout << message << std::endl; \ - ns3::AssertBreakpoint (); \ - } - #else /* NS3_DEBUG_ENABLE */ #define NS_DEBUG_COMPONENT_DEFINE(name) #define NS_DEBUG(x) -#define NS_ASSERT(cond) -#define NS_ASSERT_MSG(cond,msg) #endif /* NS3_DEBUG_ENABLE */ From 8cf0f1f4b4be479f8267f43bc8ac855effc62c82 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 16 Feb 2007 09:23:13 +0100 Subject: [PATCH 13/25] make sure that NS3_ASSER_ENABLE is defined in debug builds --- build.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build.py b/build.py index 6c048a89a..89e130083 100644 --- a/build.py +++ b/build.py @@ -460,7 +460,8 @@ class Ns3: dbg_env = env.Copy() dbg_env.Append(CFLAGS = debug_flags, CXXFLAGS = debug_flags, - CPPDEFINES = ['NS3_DEBUG_ENABLE']) + CPPDEFINES = ['NS3_DEBUG_ENABLE', + 'NS3_ASSERT_ENABLE']) # debug static support variant.static = True variant.env = dbg_env @@ -472,7 +473,8 @@ class Ns3: dbg_env = env.Copy() dbg_env.Append(CFLAGS=debug_flags, CXXFLAGS=debug_flags, - CPPDEFINES = ['NS3_DEBUG_ENABLE']) + CPPDEFINES = ['NS3_DEBUG_ENABLE', + 'NS3_ASSERT_ENABLE']) # debug shared support variant.static = False variant.env = dbg_env From 07b9fc12aad06af56627e5db4ea36e0ce57023dd Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 16 Feb 2007 09:23:22 +0100 Subject: [PATCH 14/25] add fatal-error.h header --- SConstruct | 1 + src/core/fatal-error.h | 43 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/core/fatal-error.h diff --git a/SConstruct b/SConstruct index dea42ab6f..ef87afdd1 100644 --- a/SConstruct +++ b/SConstruct @@ -43,6 +43,7 @@ core.add_inst_headers([ 'ptr.h', 'debug.h', 'assert.h', + 'fatal-error.h', 'test.h' ]) diff --git a/src/core/fatal-error.h b/src/core/fatal-error.h new file mode 100644 index 000000000..f2bba0f84 --- /dev/null +++ b/src/core/fatal-error.h @@ -0,0 +1,43 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2006 INRIA + * All rights reserved. + * + * 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 FATAL_ERROR_H +#define FATAL_ERROR_H + +#include "assert.h" + +/** + * \defgroup error + * \brief fatal error handling + * + * \param msg message to output when this macro is hit. + * + * When this macro is hit at runtime, the user-specified + * error message is output and the program is halted by calling + * the ns3::AssertBreakpoint function. This macro is enabled + * unconditionally in all builds, including debug and optimized + * builds. + */ +#define NS_FATAL_ERROR(msg) \ + std::cout << msg << std::endl; \ + ns3::AssertBreakpoint (); + + +#endif /* FATAL_ERROR_H */ From ded5b872b9d17b4fbec4ffd144012c61171a902f Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 16 Feb 2007 09:26:56 +0100 Subject: [PATCH 15/25] add NS_DEBUG_UNCOND --- src/core/debug.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/core/debug.h b/src/core/debug.h index 31253d4a8..c7025a8b3 100644 --- a/src/core/debug.h +++ b/src/core/debug.h @@ -111,10 +111,21 @@ private: std::cout << msg << std::endl; \ } +/** + * \ingroup debugging + * \param msg message to output + * + * Generate debugging output unconditionally in all + * debug builds. + */ +#define NS_DEBUG_UNCOND (msg) \ + std::cout << msg << std::endl; + #else /* NS3_DEBUG_ENABLE */ #define NS_DEBUG_COMPONENT_DEFINE(name) #define NS_DEBUG(x) +#define NS_DEBUG_UNCOND(msg) #endif /* NS3_DEBUG_ENABLE */ From f2533a764589e506ead31f8199e007230a549a80 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 16 Feb 2007 09:34:28 +0100 Subject: [PATCH 16/25] convert NS3_TRACE to NS_DEBUG --- src/common/trace-writer.cc | 18 +++++++++--------- src/node/drop-tail.cc | 20 ++++++++++---------- src/node/queue.cc | 36 ++++++++++++++++++------------------ 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/common/trace-writer.cc b/src/common/trace-writer.cc index 84d94ba6e..397ad0ade 100644 --- a/src/common/trace-writer.cc +++ b/src/common/trace-writer.cc @@ -33,7 +33,7 @@ namespace { void TraceWriter::Init (const char *filename) { - NS3_TRACE(twDebug, "TraceWriter()::Init(" << filename << ")") + NS_DEBUG("TraceWriter()::Init(" << filename << ")") std::streambuf *sb = m_filestr.rdbuf(); rdbuf(sb); @@ -47,7 +47,7 @@ TraceWriter::Init (const char *filename) TraceWriter::TraceWriter () : m_filestr() { - NS3_TRACE(twDebug, "TraceWriter()::TraceWriter()") + NS_DEBUG("TraceWriter()::TraceWriter()") Init (0); } @@ -55,7 +55,7 @@ TraceWriter::TraceWriter () : TraceWriter::TraceWriter (std::string const &filename) : m_filestr() { - NS3_TRACE(twDebug, "TraceWriter()::TraceWriter (\"" << filename << "\")") + NS_DEBUG("TraceWriter()::TraceWriter (\"" << filename << "\")") Init (filename.c_str()); } @@ -63,7 +63,7 @@ TraceWriter::TraceWriter (std::string const &filename) : TraceWriter::TraceWriter (char const *filename) : m_filestr() { - NS3_TRACE(twDebug, "TraceWriter()::TraceWriter (\"" << filename << "\")") + NS_DEBUG("TraceWriter()::TraceWriter (\"" << filename << "\")") Init (filename); } @@ -71,13 +71,13 @@ TraceWriter::TraceWriter (char const *filename) : TraceWriter::~TraceWriter () { - NS3_TRACE(twDebug, "TraceWriter()::~TraceWriter()") + NS_DEBUG("TraceWriter()::~TraceWriter()") } void TraceWriter::Open (std::string const &filename) { - NS3_TRACE(twDebug, "TraceWriter()::Open (\"" << filename << "\")") + NS_DEBUG("TraceWriter()::Open (\"" << filename << "\")") Init(filename.c_str()); } @@ -85,7 +85,7 @@ TraceWriter::Open (std::string const &filename) void TraceWriter::Open (char const *filename) { - NS3_TRACE(twDebug, "TraceWriter()::Open (\"" << filename << "\")") + NS_DEBUG("TraceWriter()::Open (\"" << filename << "\")") Init(filename); } @@ -93,7 +93,7 @@ TraceWriter::Open (char const *filename) void TraceWriter::Close () { - NS3_TRACE(twDebug, "TraceWriter()::Close ()") + NS_DEBUG("TraceWriter()::Close ()") m_filestr.close (); } @@ -101,7 +101,7 @@ TraceWriter::Close () void TraceWriter::Write (std::string const &str) { - NS3_TRACE(twDebug, "TraceWriter()::Write (\"" << str << "\")") + NS_DEBUG("TraceWriter()::Write (\"" << str << "\")") m_filestr << str; } diff --git a/src/node/drop-tail.cc b/src/node/drop-tail.cc index 3b87ea5b6..9f6ecd653 100644 --- a/src/node/drop-tail.cc +++ b/src/node/drop-tail.cc @@ -30,7 +30,7 @@ DropTailQueue::DropTailQueue () : m_packets (), m_maxPackets(DTQ_NPACKETS_MAX_DEFAULT) { - NS3_TRACE(dtqDebug, + NS_DEBUG( "DropTailQueue::DropTailQueue ()") } @@ -38,7 +38,7 @@ DropTailQueue::DropTailQueue (TraceContainer &traceContainer) : m_packets(), m_maxPackets(DTQ_NPACKETS_MAX_DEFAULT) { - NS3_TRACE(dtqDebug, + NS_DEBUG( "DropTailQueue::DropTailQueue (" << &traceContainer << ")") RegisterTraces(traceContainer); @@ -46,14 +46,14 @@ DropTailQueue::DropTailQueue (TraceContainer &traceContainer) : DropTailQueue::~DropTailQueue () { - NS3_TRACE(dtqDebug, + NS_DEBUG( "DropTailQueue::~DropTailQueue ()") } void DropTailQueue::SetMaxPackets (uint32_t npackets) { - NS3_TRACE(dtqDebug, + NS_DEBUG( "DropTailQueue::SetMaxPackets (" << npackets << ")") m_maxPackets = npackets; @@ -62,7 +62,7 @@ DropTailQueue::SetMaxPackets (uint32_t npackets) uint32_t DropTailQueue::GetMaxPackets (void) { - NS3_TRACE(dtqDebug, + NS_DEBUG( "DropTailQueue::GetMaxPackets () <= " << m_maxPackets) return m_maxPackets; @@ -71,12 +71,12 @@ DropTailQueue::GetMaxPackets (void) bool DropTailQueue::DoEnque (const Packet& p) { - NS3_TRACE(dtqDebug, + NS_DEBUG( "DropTailQueue::DoEnque (" << &p << ")") if (m_nPackets >= m_maxPackets) { - NS3_TRACE(dtqDebug, + NS_DEBUG( "DropTailQueue::DoEnque (): Queue full -- droppping pkt") Drop (p); return false; @@ -89,12 +89,12 @@ DropTailQueue::DoEnque (const Packet& p) bool DropTailQueue::DoDeque (Packet& p) { - NS3_TRACE(dtqDebug, + NS_DEBUG( "DropTailQueue::DoDeque (" << &p << ")") if (m_packets.empty()) { - NS3_TRACE(dtqDebug, + NS_DEBUG( "DropTailQueue::DoDeque (): Queue empty") return false; } @@ -102,7 +102,7 @@ DropTailQueue::DoDeque (Packet& p) p = m_packets.front (); m_packets.pop (); - NS3_TRACE(dtqDebug, + NS_DEBUG( "DropTailQueue::DoDeque (): Popped " << &p << " <= true") return true; diff --git a/src/node/queue.cc b/src/node/queue.cc index ec0631ddd..00cbcd0b8 100644 --- a/src/node/queue.cc +++ b/src/node/queue.cc @@ -34,20 +34,20 @@ Queue::Queue() : m_nTotalDroppedBytes(0), m_nTotalDroppedPackets(0) { - NS3_TRACE(qDebug, "Queue::Queue ()") + NS_DEBUG("Queue::Queue ()") } Queue::~Queue() { - NS3_TRACE(qDebug, "Queue::~Queue ()") + NS_DEBUG("Queue::~Queue ()") } bool Queue::Enque (const Packet& p) { - NS3_TRACE(qDebug, "Queue::Enque (" << &p << ")") + NS_DEBUG("Queue::Enque (" << &p << ")") - NS3_TRACE(qDebug, "Queue::Enque (): m_traceEnque (p)") + NS_DEBUG("Queue::Enque (): m_traceEnque (p)") m_traceEnque ("+ ", p); bool retval = DoEnque (p); @@ -62,7 +62,7 @@ Queue::Enque (const Packet& p) bool Queue::Deque (Packet &p) { - NS3_TRACE(qDebug, "Queue::Deque (" << &p << ")") + NS_DEBUG("Queue::Deque (" << &p << ")") bool retval = DoDeque (p); @@ -74,7 +74,7 @@ Queue::Deque (Packet &p) assert(m_nBytes >= 0); assert(m_nPackets >= 0); - NS3_TRACE(qDebug, "Queue::Deque (): m_traceDeque (p)") + NS_DEBUG("Queue::Deque (): m_traceDeque (p)") m_traceDeque ("+ ", static_cast(p)); } @@ -84,7 +84,7 @@ Queue::Deque (Packet &p) void Queue::DequeAll (void) { - NS3_TRACE(qDebug, "Queue::DequeAll ()") + NS_DEBUG("Queue::DequeAll ()") assert (!"Don't know what to do with dequeued packets!"); } @@ -92,7 +92,7 @@ Queue::DequeAll (void) uint32_t Queue::GetNPackets (void) { - NS3_TRACE(qDebug, "Queue::GetNPackets () <= " << m_nPackets) + NS_DEBUG("Queue::GetNPackets () <= " << m_nPackets) return m_nPackets; } @@ -100,7 +100,7 @@ Queue::GetNPackets (void) uint32_t Queue::GetNBytes (void) { - NS3_TRACE(qDebug, "Queue::GetNBytes () <= " << m_nBytes) + NS_DEBUG("Queue::GetNBytes () <= " << m_nBytes) return m_nBytes; } @@ -109,14 +109,14 @@ Queue::GetNBytes (void) bool Queue::IsEmpty (void) { - NS3_TRACE(qDebug, "Queue::IsEmpty () <= " << (m_nPackets == 0)) + NS_DEBUG("Queue::IsEmpty () <= " << (m_nPackets == 0)) return m_nPackets == 0; } void Queue::RegisterTraces (TraceContainer &container) { - NS3_TRACE(qDebug, "Queue::RegisterTraces (" << &container << ")") + NS_DEBUG("Queue::RegisterTraces (" << &container << ")") container.RegisterCallback ("Queue::Enque", &m_traceEnque); container.RegisterCallback ("Queue::Deque", &m_traceDeque); @@ -126,7 +126,7 @@ Queue::RegisterTraces (TraceContainer &container) uint32_t Queue::GetTotalReceivedBytes (void) { - NS3_TRACE(qDebug, + NS_DEBUG( "Queue::GetTotalReceivedBytes () <= " << m_nTotalReceivedBytes) return m_nTotalReceivedBytes; @@ -135,7 +135,7 @@ Queue::GetTotalReceivedBytes (void) uint32_t Queue::GetTotalReceivedPackets (void) { - NS3_TRACE(qDebug, + NS_DEBUG( "Queue::GetTotalReceivedPackets () <= " << m_nTotalReceivedPackets) return m_nTotalReceivedPackets; @@ -144,7 +144,7 @@ Queue::GetTotalReceivedPackets (void) uint32_t Queue:: GetTotalDroppedBytes (void) { - NS3_TRACE(qDebug, + NS_DEBUG( "Queue::GetTotalDroppedBytes () <= " << m_nTotalDroppedBytes ) return m_nTotalDroppedBytes; @@ -153,7 +153,7 @@ Queue:: GetTotalDroppedBytes (void) uint32_t Queue::GetTotalDroppedPackets (void) { - NS3_TRACE(qDebug, + NS_DEBUG( "Queue::GetTotalDroppedPackets () <= " << m_nTotalDroppedPackets) return m_nTotalDroppedPackets; @@ -162,7 +162,7 @@ Queue::GetTotalDroppedPackets (void) void Queue::ResetStatistics (void) { - NS3_TRACE(qDebug, "Queue::ResetStatistics ()") + NS_DEBUG("Queue::ResetStatistics ()") m_nTotalReceivedBytes = 0; m_nTotalReceivedPackets = 0; @@ -173,12 +173,12 @@ Queue::ResetStatistics (void) void Queue::Drop (const Packet& p) { - NS3_TRACE(qDebug, "Queue::Drop (" << &p << ")") + NS_DEBUG("Queue::Drop (" << &p << ")") m_nTotalDroppedPackets++; m_nTotalDroppedBytes += p.GetSize (); - NS3_TRACE(qDebug, "Queue::Drop (): m_traceDrop (p)") + NS_DEBUG("Queue::Drop (): m_traceDrop (p)") m_traceEnque ("d ", p); } From 9e99f617ec47a7ff5d3f8426175e07a82e260f98 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 16 Feb 2007 09:35:01 +0100 Subject: [PATCH 17/25] convert NS3_TRACEALL to NS_DEBUG_UNCOND --- samples/main-tw.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/main-tw.cc b/samples/main-tw.cc index 47d655782..c4e1ff1f4 100644 --- a/samples/main-tw.cc +++ b/samples/main-tw.cc @@ -25,7 +25,7 @@ using namespace ns3; int main (int argc, char *argv[]) { - NS3_TRACEALL("TraceWriter Test") + NS_DEBUG_UNCOND("TraceWriter Test") TraceWriter writer1; writer1.Open("trace-writer-test.txt"); From 2fafcce00c8d180990c4e89eab74c8078324e6ad Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 16 Feb 2007 09:37:35 +0100 Subject: [PATCH 18/25] call NS_DEBUG_COMPONENT_DEFINE when needed --- src/common/trace-writer.cc | 8 +++----- src/node/drop-tail.cc | 6 ++---- src/node/queue.cc | 6 ++---- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/common/trace-writer.cc b/src/common/trace-writer.cc index 397ad0ade..b7e11add5 100644 --- a/src/common/trace-writer.cc +++ b/src/common/trace-writer.cc @@ -24,13 +24,11 @@ #include "ns3/debug.h" #include "trace-writer.h" +NS_DEBUG_COMPONENT_DEFINE ("TraceWriter"); + namespace ns3 { -namespace { - int twDebug = 0; -} - - void +void TraceWriter::Init (const char *filename) { NS_DEBUG("TraceWriter()::Init(" << filename << ")") diff --git a/src/node/drop-tail.cc b/src/node/drop-tail.cc index 9f6ecd653..f4a597faf 100644 --- a/src/node/drop-tail.cc +++ b/src/node/drop-tail.cc @@ -20,11 +20,9 @@ #include "ns3/debug.h" #include "drop-tail.h" -namespace ns3 { +NS_DEBUG_COMPONENT_DEFINE ("DropTailQueue"); -namespace { - int dtqDebug = 0; -} +namespace ns3 { DropTailQueue::DropTailQueue () : m_packets (), diff --git a/src/node/queue.cc b/src/node/queue.cc index 00cbcd0b8..546a173bc 100644 --- a/src/node/queue.cc +++ b/src/node/queue.cc @@ -20,11 +20,9 @@ #include "ns3/debug.h" #include "queue.h" -namespace ns3 { +NS_DEBUG_COMPONENT_DEFINE ("Queue"); -namespace { - int qDebug = 0; -} +namespace ns3 { Queue::Queue() : m_nBytes(0), From 7f5d4a1a79d96fcdda066ff491fe64142cb19151 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 16 Feb 2007 09:40:19 +0100 Subject: [PATCH 19/25] remove extra debug.cc from build --- SConstruct | 1 - 1 file changed, 1 deletion(-) diff --git a/SConstruct b/SConstruct index 0c1d94cdd..83d17ce55 100644 --- a/SConstruct +++ b/SConstruct @@ -21,7 +21,6 @@ core.add_sources([ 'debug.cc', 'assert.cc', 'ptr.cc', - 'debug.cc', 'test.cc' ]) env = Environment() From 342ada342acc58338634353c4f94c33041f9f86e Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 16 Feb 2007 09:42:53 +0100 Subject: [PATCH 20/25] preprecessor typo --- src/core/debug.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/debug.h b/src/core/debug.h index c7025a8b3..34b85e6e4 100644 --- a/src/core/debug.h +++ b/src/core/debug.h @@ -118,7 +118,7 @@ private: * Generate debugging output unconditionally in all * debug builds. */ -#define NS_DEBUG_UNCOND (msg) \ +#define NS_DEBUG_UNCOND(msg) \ std::cout << msg << std::endl; #else /* NS3_DEBUG_ENABLE */ From d9318db068264090f18a1e7fdadec231a3129ab2 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 16 Feb 2007 09:56:21 +0100 Subject: [PATCH 21/25] convert use of to "ns3/assert.h" --- samples/main-callback.cc | 8 +++--- samples/main-ptr.cc | 2 +- src/common/buffer.cc | 38 +++++++++++++------------- src/common/buffer.h | 28 +++++++++---------- src/common/data-writer.cc | 6 ++-- src/common/header.cc | 2 +- src/common/packet.cc | 8 +++--- src/common/tags.cc | 8 +++--- src/common/tags.h | 14 +++++----- src/common/trace-container.cc | 12 ++++---- src/common/trace-container.h | 22 +++++++-------- src/common/trailer.cc | 2 +- src/core/debug.cc | 4 +-- src/core/ptr.h | 4 +-- src/core/reference-list.h | 2 +- src/core/unix-system-file.cc | 7 +++-- src/node/arp-cache.cc | 18 ++++++------ src/node/arp-header.cc | 6 ++-- src/node/arp.cc | 2 +- src/node/ipv4-header.cc | 8 +++--- src/node/ipv4-route.cc | 6 ++-- src/node/ipv4.cc | 12 ++++---- src/node/llc-snap-header.cc | 2 +- src/node/mac-address.cc | 6 ++-- src/node/net-device.cc | 4 +-- src/node/queue.cc | 6 ++-- src/node/udp-socket.cc | 2 +- src/node/udp.cc | 4 +-- src/simulator/high-precision-double.cc | 2 +- src/simulator/high-precision.cc | 2 +- src/simulator/nstime.h | 2 +- src/simulator/scheduler-heap.cc | 8 +++--- src/simulator/scheduler-list.cc | 6 ++-- src/simulator/scheduler-map.cc | 8 +++--- src/simulator/scheduler.cc | 10 +++---- src/simulator/simulator.cc | 14 +++++----- utils/replay-simulation.cc | 4 +-- 37 files changed, 150 insertions(+), 149 deletions(-) diff --git a/samples/main-callback.cc b/samples/main-callback.cc index 202f47151..f56e3f6a2 100644 --- a/samples/main-callback.cc +++ b/samples/main-callback.cc @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ #include "ns3/callback.h" -#include +#include "ns3/assert.h" #include using namespace ns3; @@ -30,7 +30,7 @@ int main (int argc, char *argv[]) // build callback instance which points to cbOne function one = MakeCallback (&CbOne); // this is not a null callback - assert (!one.IsNull ()); + NS_ASSERT (!one.IsNull ()); // invoke cbOne function through callback instance double retOne; retOne = one (10.0, 20.0); @@ -42,7 +42,7 @@ int main (int argc, char *argv[]) // build callback instance which points to MyCb::cbTwo two = MakeCallback (&MyCb::CbTwo, &cb); // this is not a null callback - assert (!two.IsNull ()); + NS_ASSERT (!two.IsNull ()); // invoke MyCb::cbTwo through callback instance int retTwo; retTwo = two (10.0); @@ -52,7 +52,7 @@ int main (int argc, char *argv[]) // invoking a null function pointer: // it will crash. //int retTwoNull = two (20.0); - assert (two.IsNull ()); + NS_ASSERT (two.IsNull ()); return 0; } diff --git a/samples/main-ptr.cc b/samples/main-ptr.cc index 3fea325ba..aa350f040 100644 --- a/samples/main-ptr.cc +++ b/samples/main-ptr.cc @@ -51,7 +51,7 @@ int main (int argc, char *argv[]) Ptr a = new A (); a->Method (); Ptr prev = StoreA (a); - assert (prev == 0); + NS_ASSERT (prev == 0); } { diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 2305e150d..5bb97440d 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -19,7 +19,7 @@ * Author: Mathieu Lacage */ #include "buffer.h" -#include +#include "ns3/assert.h" #include //#define TRACE(x) std::cout << x << std::endl; @@ -38,7 +38,7 @@ Buffer::Allocate (uint32_t reqSize, uint32_t reqStart) { reqSize = 1; } - assert (reqSize >= 1); + NS_ASSERT (reqSize >= 1); uint32_t size = reqSize - 1 + sizeof (struct Buffer::BufferData); uint8_t *b = new uint8_t [size]; struct BufferData *data = reinterpret_cast(b); @@ -60,7 +60,7 @@ Buffer::Deallocate (struct Buffer::BufferData *data) void Buffer::Recycle (struct Buffer::BufferData *data) { - assert (data->m_count == 0); + NS_ASSERT (data->m_count == 0); /* get rid of it if it is too small for later reuse. */ if (data->m_size < (Buffer::m_maxTotalAddStart + Buffer::m_maxTotalAddEnd)) { @@ -98,7 +98,7 @@ Buffer::Create (void) } struct Buffer::BufferData *data = Buffer::Allocate (m_maxTotalAddStart+m_maxTotalAddEnd, m_maxTotalAddStart); - assert (data->m_count == 1); + NS_ASSERT (data->m_count == 1); return data; } #else @@ -119,7 +119,7 @@ Buffer::Create (void) }; // namespace ns3 -#include +#include "ns3/assert.h" namespace ns3 { @@ -127,7 +127,7 @@ namespace ns3 { void Buffer::AddAtStart (uint32_t start) { - assert (m_start <= m_data->m_initialStart); + NS_ASSERT (m_start <= m_data->m_initialStart); bool isDirty = m_data->m_count > 1 && m_start > m_data->m_dirtyStart; if (m_start >= start && !isDirty) { @@ -139,7 +139,7 @@ Buffer::AddAtStart (uint32_t start) { /* enough space but need to move data around to fit new data */ memmove (m_data->m_data + start, GetStart (), m_size); - assert (start > m_start); + NS_ASSERT (start > m_start); m_data->m_initialStart += start; m_start = 0; m_size += start; @@ -163,7 +163,7 @@ Buffer::AddAtStart (uint32_t start) else { /* enough space in the buffer but it is dirty ! */ - assert (isDirty); + NS_ASSERT (isDirty); struct Buffer::BufferData *newData = Buffer::Create (); memcpy (newData->m_data + m_start, GetStart (), m_size); newData->m_initialStart = m_data->m_initialStart; @@ -200,7 +200,7 @@ Buffer::AddAtStart (uint32_t start) void Buffer::AddAtEnd (uint32_t end) { - assert (m_start <= m_data->m_initialStart); + NS_ASSERT (m_start <= m_data->m_initialStart); bool isDirty = m_data->m_count > 1 && m_start + m_size < m_data->m_dirtyStart + m_data->m_dirtySize; if (m_start + m_size + end <= m_data->m_size && !isDirty) @@ -213,7 +213,7 @@ Buffer::AddAtEnd (uint32_t end) /* enough space but need to move data around to fit the extra data */ uint32_t newStart = m_data->m_size - (m_size + end); memmove (m_data->m_data + newStart, GetStart (), m_size); - assert (newStart < m_start); + NS_ASSERT (newStart < m_start); m_data->m_initialStart -= m_start - newStart; m_start = newStart; m_size += end; @@ -237,7 +237,7 @@ Buffer::AddAtEnd (uint32_t end) else { /* enough space in the buffer but it is dirty ! */ - assert (isDirty); + NS_ASSERT (isDirty); struct Buffer::BufferData *newData = Buffer::Create (); memcpy (newData->m_data + m_start, GetStart (), m_size); newData->m_initialStart = m_data->m_initialStart; @@ -290,7 +290,7 @@ Buffer::RemoveAtStart (uint32_t start) } else { - assert (m_data->m_initialStart >= m_start); + NS_ASSERT (m_data->m_initialStart >= m_start); uint32_t zeroStart = m_data->m_initialStart - m_start; uint32_t zeroEnd = zeroStart + m_zeroAreaSize; uint32_t dataEnd = m_size + m_zeroAreaSize; @@ -306,7 +306,7 @@ Buffer::RemoveAtStart (uint32_t start) m_start += zeroStart; uint32_t zeroDelta = start - zeroStart; m_zeroAreaSize -= zeroDelta; - assert (zeroDelta <= start); + NS_ASSERT (zeroDelta <= start); m_size -= zeroStart; } else if (start <= dataEnd) @@ -346,12 +346,12 @@ Buffer::RemoveAtEnd (uint32_t end) } else { - assert (m_data->m_initialStart >= m_start); + NS_ASSERT (m_data->m_initialStart >= m_start); uint32_t zeroStart = m_data->m_initialStart - m_start; uint32_t zeroEnd = zeroStart + m_zeroAreaSize; uint32_t dataEnd = m_size + m_zeroAreaSize; - assert (zeroStart <= m_size); - assert (zeroEnd <= m_size + m_zeroAreaSize); + NS_ASSERT (zeroStart <= m_size); + NS_ASSERT (zeroEnd <= m_size + m_zeroAreaSize); if (dataEnd <= end) { /* remove all buffer */ @@ -362,7 +362,7 @@ Buffer::RemoveAtEnd (uint32_t end) else if (dataEnd - zeroStart <= end) { /* remove end of buffer, zero area, part of start of buffer */ - assert (end >= m_zeroAreaSize); + NS_ASSERT (end >= m_zeroAreaSize); m_size -= end - m_zeroAreaSize; m_zeroAreaSize = 0; } @@ -406,8 +406,8 @@ Buffer::TransformIntoRealBuffer (void) const { if (m_zeroAreaSize != 0) { - assert (m_data->m_initialStart >= m_start); - assert (m_size >= (m_data->m_initialStart - m_start)); + NS_ASSERT (m_data->m_initialStart >= m_start); + NS_ASSERT (m_size >= (m_data->m_initialStart - m_start)); Buffer tmp; tmp.AddAtStart (m_zeroAreaSize); tmp.Begin ().WriteU8 (0, m_zeroAreaSize); diff --git a/src/common/buffer.h b/src/common/buffer.h index f67b65fcd..500e11f7c 100644 --- a/src/common/buffer.h +++ b/src/common/buffer.h @@ -361,7 +361,7 @@ private: need to be inline for performance reasons. *************************************************/ -#include +#include "ns3/assert.h" namespace ns3 { @@ -375,7 +375,7 @@ Buffer::Buffer () { m_start = 0; } - assert (m_start <= m_data->m_size); + NS_ASSERT (m_start <= m_data->m_size); } Buffer::Buffer (uint32_t dataSize) @@ -388,7 +388,7 @@ Buffer::Buffer (uint32_t dataSize) { m_start = 0; } - assert (m_start <= m_data->m_size); + NS_ASSERT (m_start <= m_data->m_size); } @@ -399,7 +399,7 @@ Buffer::Buffer (Buffer const&o) m_size (o.m_size) { m_data->m_count++; - assert (m_start <= m_data->m_size); + NS_ASSERT (m_start <= m_data->m_size); } Buffer & @@ -419,7 +419,7 @@ Buffer::operator = (Buffer const&o) m_zeroAreaSize = o.m_zeroAreaSize; m_start = o.m_start; m_size = o.m_size; - assert (m_start <= m_data->m_size); + NS_ASSERT (m_start <= m_data->m_size); return *this; } @@ -475,31 +475,31 @@ Buffer::Iterator::Iterator (Buffer const*buffer, uint32_t current) void Buffer::Iterator::Next (void) { - assert (m_current + 1 <= m_dataEnd); + NS_ASSERT (m_current + 1 <= m_dataEnd); m_current++; } void Buffer::Iterator::Prev (void) { - assert (m_current >= 1); + NS_ASSERT (m_current >= 1); m_current--; } void Buffer::Iterator::Next (uint32_t delta) { - assert (m_current + delta <= m_dataEnd); + NS_ASSERT (m_current + delta <= m_dataEnd); m_current += delta; } void Buffer::Iterator::Prev (uint32_t delta) { - assert (m_current >= delta); + NS_ASSERT (m_current >= delta); m_current -= delta; } int32_t Buffer::Iterator::GetDistanceFrom (Iterator const &o) const { - assert (m_data == o.m_data); + NS_ASSERT (m_data == o.m_data); int32_t start = m_current; int32_t end = o.m_current; return end - start; @@ -519,7 +519,7 @@ Buffer::Iterator::IsStart (void) const uint32_t Buffer::Iterator::GetIndex (uint32_t n) { - assert ( + NS_ASSERT ( (m_current + n <= m_dataEnd) && ((m_current + n <= m_zeroStart) || (m_current >= m_zeroEnd)) @@ -540,9 +540,9 @@ Buffer::Iterator::GetIndex (uint32_t n) void Buffer::Iterator::Write (Iterator start, Iterator end) { - assert (start.m_data == end.m_data); - assert (start.m_current <= end.m_current); - assert (m_data != start.m_data); + NS_ASSERT (start.m_data == end.m_data); + NS_ASSERT (start.m_current <= end.m_current); + NS_ASSERT (m_data != start.m_data); uint32_t size = end.m_current - start.m_current; uint8_t *src = start.m_data + start.GetIndex (size); uint8_t *dest = m_data + GetIndex (size); diff --git a/src/common/data-writer.cc b/src/common/data-writer.cc index 53fc2d3cd..40b0cad68 100644 --- a/src/common/data-writer.cc +++ b/src/common/data-writer.cc @@ -25,7 +25,7 @@ #include #include #include -#include +#include "ns3/assert.h" #include #include @@ -71,7 +71,7 @@ void DataWriterPrivate::Open (char const *filename) { m_fd = ::Open (filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); - assert (m_fd != -1); + NS_ASSERT (m_fd != -1); } #ifndef min @@ -92,7 +92,7 @@ DataWriterPrivate::Write (uint8_t *buffer, uint32_t size) { ssize_t written = 0; written = ::Write (m_fd, m_data, BUFFER_SIZE); - assert (written == BUFFER_SIZE); + NS_ASSERT (written == BUFFER_SIZE); m_current = 0; } } diff --git a/src/common/header.cc b/src/common/header.cc index 49e2683b0..2a3a31d94 100644 --- a/src/common/header.cc +++ b/src/common/header.cc @@ -20,7 +20,7 @@ */ #include "header.h" -#include +#include "ns3/assert.h" namespace ns3 { diff --git a/src/common/packet.cc b/src/common/packet.cc index f6df542a2..6067e9640 100644 --- a/src/common/packet.cc +++ b/src/common/packet.cc @@ -19,7 +19,7 @@ * Author: Mathieu Lacage */ #include "packet.h" -#include +#include "ns3/assert.h" namespace ns3 { @@ -81,7 +81,7 @@ Packet::Peek (Header &header) void Packet::Remove (Header const &header) { - assert (header.IsDeserialized ()); + NS_ASSERT (header.IsDeserialized ()); m_buffer.RemoveAtStart (header.GetSize ()); } void @@ -102,7 +102,7 @@ Packet::Peek (Trailer &trailer) void Packet::Remove (Trailer const &trailer) { - assert (trailer.IsDeserialized ()); + NS_ASSERT (trailer.IsDeserialized ()); m_buffer.RemoveAtEnd (trailer.GetSize ()); } @@ -123,7 +123,7 @@ Packet::AddAtEnd (Packet packet) void Packet::AddAtEnd (Packet packet, uint32_t start, uint32_t size) { - assert (packet.GetSize () <= start + size); + NS_ASSERT (packet.GetSize () <= start + size); Buffer src = packet.m_buffer; m_buffer.AddAtEnd (src.GetSize ()); Buffer::Iterator destStart = m_buffer.End (); diff --git a/src/common/tags.cc b/src/common/tags.cc index c732a0f91..594e7a249 100644 --- a/src/common/tags.cc +++ b/src/common/tags.cc @@ -30,7 +30,7 @@ TagRegistry::TagsData TagRegistry::m_registry; void TagRegistry::Record (std::string uuid, PrettyPrinter prettyPrinter) { - assert (!m_sorted); + NS_ASSERT (!m_sorted); m_registry.push_back (make_pair (uuid, prettyPrinter)); } uint32_t @@ -41,7 +41,7 @@ TagRegistry::LookupUid (std::string uuid) std::sort (m_registry.begin (), m_registry.end ()); m_sorted = true; } - assert (m_sorted); + NS_ASSERT (m_sorted); uint32_t uid = 1; for (TagsDataCI i = m_registry.begin (); i != m_registry.end (); i++) { @@ -52,14 +52,14 @@ TagRegistry::LookupUid (std::string uuid) uid++; } // someone asked for a uid for an unregistered uuid. - assert (!"You tried to use unregistered tag: make sure you create an instance of type TagRegistration."); + NS_ASSERT (!"You tried to use unregistered tag: make sure you create an instance of type TagRegistration."); // quiet compiler return 0; } void TagRegistry::PrettyPrint (uint32_t uid, uint8_t buf[Tags::SIZE], std::ostream &os) { - assert (m_registry.size () > uid); + NS_ASSERT (m_registry.size () > uid); PrettyPrinter prettyPrinter = m_registry[uid].second; if (prettyPrinter != 0) { diff --git a/src/common/tags.h b/src/common/tags.h index 18b68d378..fd0bfacbf 100644 --- a/src/common/tags.h +++ b/src/common/tags.h @@ -109,7 +109,7 @@ private: /************************************************************** An implementation of the templates defined above *************************************************************/ -#include +#include "ns3/assert.h" #include namespace ns3 { @@ -179,7 +179,7 @@ std::string *TypeUid::GetUuid (void) template TagRegistration::TagRegistration (std::string uuid, void (*prettyPrinter) (T const*, std::ostream &)) { - assert (sizeof (T) <= Tags::SIZE); + NS_ASSERT (sizeof (T) <= Tags::SIZE); m_prettyPrinter = prettyPrinter; TagRegistry::Record (uuid, &TagRegistration::PrettyPrinterCb); TypeUid::Record (uuid); @@ -188,7 +188,7 @@ template void TagRegistration::PrettyPrinterCb (uint8_t *buf, std::ostream &os) { - assert (sizeof (T) <= Tags::SIZE); + NS_ASSERT (sizeof (T) <= Tags::SIZE); T *tag = reinterpret_cast (buf); (*m_prettyPrinter) (tag, os); } @@ -203,12 +203,12 @@ template void Tags::Add (T const&tag) { - assert (sizeof (T) <= Tags::SIZE); + NS_ASSERT (sizeof (T) <= Tags::SIZE); uint8_t const*buf = reinterpret_cast (&tag); // ensure this id was not yet added for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next) { - assert (cur->m_id != TypeUid::GetUid ()); + NS_ASSERT (cur->m_id != TypeUid::GetUid ()); } struct TagData *newStart = AllocData (); newStart->m_count = 1; @@ -223,7 +223,7 @@ template bool Tags::Remove (T &tag) { - assert (sizeof (T) <= Tags::SIZE); + NS_ASSERT (sizeof (T) <= Tags::SIZE); return Remove (TypeUid::GetUid ()); } @@ -231,7 +231,7 @@ template bool Tags::Peek (T &tag) const { - assert (sizeof (T) <= Tags::SIZE); + NS_ASSERT (sizeof (T) <= Tags::SIZE); uint8_t *buf = reinterpret_cast (&tag); for (struct TagData *cur = m_next; cur != 0; cur = cur->m_next) { diff --git a/src/common/trace-container.cc b/src/common/trace-container.cc index 13070a207..5dcd9d3ce 100644 --- a/src/common/trace-container.cc +++ b/src/common/trace-container.cc @@ -22,7 +22,7 @@ #include "trace-container.h" #include "stream-tracer.h" #include -#include +#include "ns3/assert.h" namespace ns3 { @@ -46,7 +46,7 @@ TraceContainer::SetUiVariableCallback (char const *name, Callback callback) @@ -59,12 +59,12 @@ TraceContainer::SetSiVariableCallback (char const *name, Callback callback) { - assert (false); + NS_ASSERT (false); } void TraceContainer::SetStream (char const *name, std::ostream *os) @@ -77,7 +77,7 @@ TraceContainer::SetStream (char const *name, std::ostream *os) return; } } - assert (false); + NS_ASSERT (false); } void @@ -111,7 +111,7 @@ TraceContainer::RegisterSiVariable (char const *name, SiVariableTracerBase *var) void TraceContainer::RegisterFVariable (char const *name, FVariableTracerBase *var) { - assert (false); + NS_ASSERT (false); } void diff --git a/src/common/trace-container.h b/src/common/trace-container.h index bc32e5257..a8f8ba5b9 100644 --- a/src/common/trace-container.h +++ b/src/common/trace-container.h @@ -196,7 +196,7 @@ private: }; // namespace ns3 -#include +#include "ns3/assert.h" namespace ns3 { @@ -215,11 +215,11 @@ TraceContainer::SetCallback (char const *name, Callback callback) } else { - assert (!"non-matching callback"); + NS_ASSERT (!"non-matching callback"); } } } - assert (false); + NS_ASSERT (false); } template void @@ -236,11 +236,11 @@ TraceContainer::SetCallback (char const *name, Callback callback) } else { - assert (!"non-matching callback"); + NS_ASSERT (!"non-matching callback"); } } } - assert (false); + NS_ASSERT (false); } template void @@ -257,11 +257,11 @@ TraceContainer::SetCallback (char const *name, Callback callback) } else { - assert (!"non-matching callback"); + NS_ASSERT (!"non-matching callback"); } } } - assert (false); + NS_ASSERT (false); } template void @@ -278,11 +278,11 @@ TraceContainer::SetCallback (char const *name, Callback callba } else { - assert (!"non-matching callback"); + NS_ASSERT (!"non-matching callback"); } } } - assert (false); + NS_ASSERT (false); } template void @@ -299,11 +299,11 @@ TraceContainer::SetCallback (char const *name, Callback cal } else { - assert (!"non-matching callback"); + NS_ASSERT (!"non-matching callback"); } } } - assert (false); + NS_ASSERT (false); } diff --git a/src/common/trailer.cc b/src/common/trailer.cc index c80a8426f..a00918819 100644 --- a/src/common/trailer.cc +++ b/src/common/trailer.cc @@ -20,7 +20,7 @@ */ #include "trailer.h" -#include +#include "ns3/assert.h" namespace ns3 { diff --git a/src/core/debug.cc b/src/core/debug.cc index a250be103..9d098af49 100644 --- a/src/core/debug.cc +++ b/src/core/debug.cc @@ -18,11 +18,11 @@ * * Author: Mathieu Lacage */ -#include #include #include #include #include "debug.h" +#include "assert.h" #include "ns3/core-config.h" #ifdef HAVE_STDLIB_H @@ -103,7 +103,7 @@ DebugComponent::DebugComponent (char const * name) i != g_components.end (); i++) { - assert (i->first.compare (name) != 0); + NS_ASSERT (i->first.compare (name) != 0); } g_components.push_back (std::make_pair (name, this)); } diff --git a/src/core/ptr.h b/src/core/ptr.h index 06ea24c76..8fe1db397 100644 --- a/src/core/ptr.h +++ b/src/core/ptr.h @@ -23,7 +23,7 @@ #define PTR_H #include -#include +#include "assert.h" namespace ns3 { @@ -246,7 +246,7 @@ template T * Ptr::Remove (void) { - assert ((*m_count) == 1); + NS_ASSERT ((*m_count) == 1); T *retval = m_ptr; m_ptr = 0; return retval; diff --git a/src/core/reference-list.h b/src/core/reference-list.h index 6174d4a23..08a4452bb 100644 --- a/src/core/reference-list.h +++ b/src/core/reference-list.h @@ -101,7 +101,7 @@ private: void RemoveFromList (void) { if (m_prev == this) { - //assert (m_next == this); + //NS_ASSERT (m_next == this); delete m_objPtr; m_objPtr = OBJ_PTR (); } diff --git a/src/core/unix-system-file.cc b/src/core/unix-system-file.cc index 909f6d89f..6fa7916a7 100644 --- a/src/core/unix-system-file.cc +++ b/src/core/unix-system-file.cc @@ -25,10 +25,11 @@ #include #include #include -#include #include #include +#include "assert.h" + #define noTRACE_SYS_FILE 1 #ifdef TRACE_SYS_FILE @@ -71,7 +72,7 @@ void SystemFilePrivate::Open (char const *filename) { m_fd = ::open (filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); - assert (m_fd != -1); + NS_ASSERT (m_fd != -1); } #ifndef min @@ -92,7 +93,7 @@ SystemFilePrivate::Write (uint8_t const*buffer, uint32_t size) { ssize_t written = 0; written = ::write (m_fd, m_data, BUFFER_SIZE); - assert (written == BUFFER_SIZE); + NS_ASSERT (written == BUFFER_SIZE); m_current = 0; } } diff --git a/src/node/arp-cache.cc b/src/node/arp-cache.cc index 07ea73545..f60561500 100644 --- a/src/node/arp-cache.cc +++ b/src/node/arp-cache.cc @@ -18,7 +18,7 @@ * * Author: Mathieu Lacage */ -#include +#include "ns3/assert.h" #include "ns3/packet.h" #include "ns3/simulator.h" @@ -153,14 +153,14 @@ void ArpCache::Entry::MarkDead (void) { m_state = DEAD; - //assert (m_waiting != 0); + //NS_ASSERT (m_waiting != 0); UpdateSeen (); } Packet ArpCache::Entry::MarkAlive (MacAddress macAddress) { - assert (m_state == WAIT_REPLY); - //assert (m_waiting != 0); + NS_ASSERT (m_state == WAIT_REPLY); + //NS_ASSERT (m_waiting != 0); m_macAddress = macAddress; m_state = ALIVE; UpdateSeen (); @@ -172,7 +172,7 @@ ArpCache::Entry::MarkAlive (MacAddress macAddress) Packet ArpCache::Entry::UpdateWaitReply (Packet waiting) { - assert (m_state == WAIT_REPLY); + NS_ASSERT (m_state == WAIT_REPLY); /* We are already waiting for an answer so * we dump the previously waiting packet and * replace it with this one. @@ -184,8 +184,8 @@ ArpCache::Entry::UpdateWaitReply (Packet waiting) void ArpCache::Entry::MarkWaitReply (Packet waiting) { - assert (m_state == ALIVE || m_state == DEAD); - //assert (m_waiting == 0); + NS_ASSERT (m_state == ALIVE || m_state == DEAD); + //NS_ASSERT (m_waiting == 0); m_state = WAIT_REPLY; m_waiting = waiting; UpdateSeen (); @@ -194,7 +194,7 @@ ArpCache::Entry::MarkWaitReply (Packet waiting) MacAddress ArpCache::Entry::GetMacAddress (void) { - assert (m_state == ALIVE); + NS_ASSERT (m_state == ALIVE); return m_macAddress; } bool @@ -212,7 +212,7 @@ ArpCache::Entry::IsExpired (void) timeout = m_arp->GetAliveTimeout (); break; default: - assert (false); + NS_ASSERT (false); timeout = Seconds (0); /* NOTREACHED */ break; diff --git a/src/node/arp-header.cc b/src/node/arp-header.cc index a29462333..b86f50a2b 100644 --- a/src/node/arp-header.cc +++ b/src/node/arp-header.cc @@ -19,7 +19,7 @@ * Author: Mathieu Lacage */ -#include +#include "ns3/assert.h" #include "arp-header.h" #include "header-utils.h" @@ -96,7 +96,7 @@ ArpHeader::PrintTo (std::ostream &os) const } else { - assert (IsReply ()); + NS_ASSERT (IsReply ()); os << " source mac: " << m_macSource << " source ipv4: " << m_ipv4Source << " dest mac: " << m_macDest @@ -114,7 +114,7 @@ void ArpHeader::SerializeTo (Buffer::Iterator start) const { Buffer::Iterator i = start; - assert (m_macSource.GetLength () == m_macDest.GetLength ()); + NS_ASSERT (m_macSource.GetLength () == m_macDest.GetLength ()); /* ethernet */ i.WriteHtonU16 (0x0001); diff --git a/src/node/arp.cc b/src/node/arp.cc index 8ca5fc670..911083c72 100644 --- a/src/node/arp.cc +++ b/src/node/arp.cc @@ -61,7 +61,7 @@ Arp::FindCache (NetDevice *device) } Ipv4Interface *interface = m_node->GetIpv4 ()->FindInterfaceForDevice (device); ArpCache * cache = new ArpCache (device, interface); - assert (device->IsBroadcast ()); + NS_ASSERT (device->IsBroadcast ()); device->SetLinkChangeCallback (MakeCallback (&ArpCache::Flush, cache)); m_cacheList.push_back (cache); return cache; diff --git a/src/node/ipv4-header.cc b/src/node/ipv4-header.cc index d2e13abcb..63cf985ba 100644 --- a/src/node/ipv4-header.cc +++ b/src/node/ipv4-header.cc @@ -19,7 +19,7 @@ * Author: Mathieu Lacage */ -#include +#include "ns3/assert.h" #include "ns3/header.h" #include "ipv4-header.h" @@ -137,13 +137,13 @@ Ipv4Header::IsDontFragment (void) const void Ipv4Header::SetFragmentOffset (uint16_t offset) { - assert (!(offset & (~0x3fff))); + NS_ASSERT (!(offset & (~0x3fff))); m_fragmentOffset = offset; } uint16_t Ipv4Header::GetFragmentOffset (void) const { - assert (!(m_fragmentOffset & (~0x3fff))); + NS_ASSERT (!(m_fragmentOffset & (~0x3fff))); return m_fragmentOffset; } @@ -272,7 +272,7 @@ Ipv4Header::DeserializeFrom (Buffer::Iterator start) uint8_t verIhl = i.ReadU8 (); uint8_t ihl = verIhl & 0x0f; uint16_t headerSize = ihl * 4; - assert ((verIhl >> 4) == 4); + NS_ASSERT ((verIhl >> 4) == 4); m_tos = i.ReadU8 (); uint16_t size = i.ReadNtohU16 (); m_payloadSize = size - headerSize; diff --git a/src/node/ipv4-route.cc b/src/node/ipv4-route.cc index 35afc4a88..bcc556894 100644 --- a/src/node/ipv4-route.cc +++ b/src/node/ipv4-route.cc @@ -20,7 +20,7 @@ */ #include "ipv4-route.h" -#include +#include "ns3/assert.h" namespace ns3 { @@ -180,7 +180,7 @@ std::ostream& operator<< (std::ostream& os, Ipv4Route const& route) { if (route.IsDefault ()) { - assert (route.IsGateway ()); + NS_ASSERT (route.IsGateway ()); os << "default out=" << route.GetInterface () << ", next hop=" << route.GetGateway (); } else if (route.IsHost ()) @@ -215,7 +215,7 @@ std::ostream& operator<< (std::ostream& os, Ipv4Route const& route) } else { - assert (false); + NS_ASSERT (false); } return os; } diff --git a/src/node/ipv4.cc b/src/node/ipv4.cc index 9fb146d32..0f6902042 100644 --- a/src/node/ipv4.cc +++ b/src/node/ipv4.cc @@ -129,7 +129,7 @@ Ipv4::Lookup (Ipv4Address dest) i != m_hostRoutes.end (); i++) { - assert ((*i)->IsHost ()); + NS_ASSERT ((*i)->IsHost ()); if ((*i)->GetDest ().IsEqual (dest)) { return (*i); @@ -139,7 +139,7 @@ Ipv4::Lookup (Ipv4Address dest) j != m_networkRoutes.end (); j++) { - assert ((*j)->IsNetwork ()); + NS_ASSERT ((*j)->IsNetwork ()); Ipv4Mask mask = (*j)->GetDestNetworkMask (); Ipv4Address entry = (*j)->GetDestNetwork (); if (mask.IsMatch (dest, entry)) @@ -149,7 +149,7 @@ Ipv4::Lookup (Ipv4Address dest) } if (m_defaultRoute != 0) { - assert (m_defaultRoute->IsDefault ()); + NS_ASSERT (m_defaultRoute->IsDefault ()); return m_defaultRoute; } return 0; @@ -204,7 +204,7 @@ Ipv4::GetRoute (uint32_t index) } tmp++; } - assert (false); + NS_ASSERT (false); // quiet compiler. return 0; } @@ -250,7 +250,7 @@ Ipv4::RemoveRoute (uint32_t index) } tmp++; } - assert (false); + NS_ASSERT (false); } @@ -365,7 +365,7 @@ Ipv4::SendRealOut (Packet const &p, Ipv4Header const &ip, Ipv4Route const &route Packet packet = p; packet.Add (ip); Ipv4Interface *outInterface = GetInterface (route.GetInterface ()); - assert (packet.GetSize () <= outInterface->GetMtu ()); + NS_ASSERT (packet.GetSize () <= outInterface->GetMtu ()); // XXX log trace here. if (route.IsGateway ()) { diff --git a/src/node/llc-snap-header.cc b/src/node/llc-snap-header.cc index 989dab079..77a43c72c 100644 --- a/src/node/llc-snap-header.cc +++ b/src/node/llc-snap-header.cc @@ -19,7 +19,7 @@ * Author: Mathieu Lacage */ -#include +#include "ns3/assert.h" #include "llc-snap-header.h" diff --git a/src/node/mac-address.cc b/src/node/mac-address.cc index c8ebff2bf..be455a8a3 100644 --- a/src/node/mac-address.cc +++ b/src/node/mac-address.cc @@ -21,7 +21,7 @@ #include #include -#include +#include "ns3/assert.h" #include "mac-address.h" #define ASCII_a (0x41) @@ -56,7 +56,7 @@ MacAddress::MacAddress () : m_len(0) MacAddress::MacAddress (uint8_t const *address, uint8_t len) { - assert(len <= MacAddress::MAX_LEN); + NS_ASSERT (len <= MacAddress::MAX_LEN); for (int i=0; i < len; i++) { m_address[i] = address[i]; @@ -164,7 +164,7 @@ bool operator < (MacAddress const&a, MacAddress const&b) uint8_t b_p[MacAddress::MAX_LEN]; a.Peek (a_p); b.Peek (b_p); - assert(a.GetLength() == b.GetLength()); + NS_ASSERT (a.GetLength() == b.GetLength()); for (uint8_t i = 0; i < a.GetLength(); i++) { if (a_p[i] < b_p[i]) diff --git a/src/node/net-device.cc b/src/node/net-device.cc index f351b1065..da2b8cadb 100644 --- a/src/node/net-device.cc +++ b/src/node/net-device.cc @@ -20,7 +20,7 @@ */ #include -#include +#include "ns3/assert.h" #include "net-device.h" #include "l3-demux.h" @@ -93,7 +93,7 @@ NetDevice::IsBroadcast (void) const MacAddress const & NetDevice::GetBroadcast (void) const { - assert (m_isBroadcast); + NS_ASSERT (m_isBroadcast); return m_broadcast; } diff --git a/src/node/queue.cc b/src/node/queue.cc index 546a173bc..7b2000cb3 100644 --- a/src/node/queue.cc +++ b/src/node/queue.cc @@ -69,8 +69,8 @@ Queue::Deque (Packet &p) m_nBytes -= p.GetSize (); m_nPackets--; - assert(m_nBytes >= 0); - assert(m_nPackets >= 0); + NS_ASSERT (m_nBytes >= 0); + NS_ASSERT (m_nPackets >= 0); NS_DEBUG("Queue::Deque (): m_traceDeque (p)") m_traceDeque ("+ ", static_cast(p)); @@ -84,7 +84,7 @@ Queue::DequeAll (void) { NS_DEBUG("Queue::DequeAll ()") - assert (!"Don't know what to do with dequeued packets!"); + NS_ASSERT (!"Don't know what to do with dequeued packets!"); } uint32_t diff --git a/src/node/udp-socket.cc b/src/node/udp-socket.cc index 2ac0b4681..478cbcfae 100644 --- a/src/node/udp-socket.cc +++ b/src/node/udp-socket.cc @@ -30,7 +30,7 @@ UdpSocket::UdpSocket (Node *node) : m_endPoint (0), m_node (node) { - assert (GetUdp () != 0); + NS_ASSERT (GetUdp () != 0); } UdpSocket::~UdpSocket () { diff --git a/src/node/udp.cc b/src/node/udp.cc index db8434a1f..a9d5e1692 100644 --- a/src/node/udp.cc +++ b/src/node/udp.cc @@ -19,7 +19,7 @@ * Author: Mathieu Lacage */ -#include +#include "ns3/assert.h" #include "ns3/packet.h" #include "udp.h" #include "udp-header.h" @@ -95,7 +95,7 @@ Udp::Receive(Packet& packet, } UdpSocket *socket = endPoint->GetSocket (); socket->ForwardUp (packet, source, udpHeader.GetSource ()); - assert (socket != 0); + NS_ASSERT (socket != 0); } void diff --git a/src/simulator/high-precision-double.cc b/src/simulator/high-precision-double.cc index 86e2d62cd..c4639c1eb 100644 --- a/src/simulator/high-precision-double.cc +++ b/src/simulator/high-precision-double.cc @@ -21,7 +21,7 @@ #include "high-precision-double.h" #include -#include +#include "ns3/assert.h" namespace ns3 { diff --git a/src/simulator/high-precision.cc b/src/simulator/high-precision.cc index 27ecf2a10..0313be6b2 100644 --- a/src/simulator/high-precision.cc +++ b/src/simulator/high-precision.cc @@ -21,7 +21,7 @@ #include "high-precision.h" #include -#include +#include "ns3/assert.h" namespace ns3 { diff --git a/src/simulator/nstime.h b/src/simulator/nstime.h index c0b2d87d7..32d0ba9b5 100644 --- a/src/simulator/nstime.h +++ b/src/simulator/nstime.h @@ -22,7 +22,7 @@ #define TIME_H #include -#include +#include "ns3/assert.h" #include #include "high-precision.h" diff --git a/src/simulator/scheduler-heap.cc b/src/simulator/scheduler-heap.cc index ca9e73fbb..807c6b263 100644 --- a/src/simulator/scheduler-heap.cc +++ b/src/simulator/scheduler-heap.cc @@ -34,7 +34,7 @@ #include "scheduler-heap.h" #include "event-impl.h" -#include +#include "ns3/assert.h" #define noTRACE_HEAP 1 @@ -112,7 +112,7 @@ SchedulerHeap::IsBottom (uint32_t id) const void SchedulerHeap::Exch (uint32_t a, uint32_t b) { - assert (b < m_heap.size () && a < m_heap.size ()); + NS_ASSERT (b < m_heap.size () && a < m_heap.size ()); TRACE ("Exch " << a << ", " << b); std::pair tmp (m_heap[a]); m_heap[a] = m_heap[b]; @@ -191,7 +191,7 @@ SchedulerHeap::TopDown (uint32_t start) { return; } - assert (!IsBottom (index)); + NS_ASSERT (!IsBottom (index)); uint32_t left = LeftChild (index); if (IsBottom (left)) { @@ -248,7 +248,7 @@ SchedulerHeap::RealRemove (EventId id, Scheduler::EventKey *key) return retval; } } - assert (false); + NS_ASSERT (false); // quiet compiler return 0; } diff --git a/src/simulator/scheduler-list.cc b/src/simulator/scheduler-list.cc index 16ce7a01e..7f1f43f03 100644 --- a/src/simulator/scheduler-list.cc +++ b/src/simulator/scheduler-list.cc @@ -22,7 +22,7 @@ #include "scheduler-list.h" #include "event-impl.h" #include -#include +#include "ns3/assert.h" namespace ns3 { @@ -93,14 +93,14 @@ SchedulerList::RealRemove (EventId id, Scheduler::EventKey *key) if (i->second.m_uid == id.GetUid ()) { EventImpl *retval = i->first; - assert (id.GetEventImpl () == retval); + NS_ASSERT (id.GetEventImpl () == retval); key->m_ns = id.GetNs (); key->m_uid = id.GetUid (); m_events.erase (i); return retval; } } - assert (false); + NS_ASSERT (false); return 0; } diff --git a/src/simulator/scheduler-map.cc b/src/simulator/scheduler-map.cc index aaccaf865..5e07c9779 100644 --- a/src/simulator/scheduler-map.cc +++ b/src/simulator/scheduler-map.cc @@ -22,7 +22,7 @@ #include "scheduler-map.h" #include "event-impl.h" -#include +#include "ns3/assert.h" #define noTRACE_MAP 1 @@ -76,7 +76,7 @@ SchedulerMap::RealInsert (EventImpl *event, Scheduler::EventKey key) { std::pair result; result = m_list.insert (std::make_pair (key, event)); - assert (result.second); + NS_ASSERT (result.second); return EventId (event, key.m_ns, key.m_uid); } @@ -90,14 +90,14 @@ EventImpl * SchedulerMap::RealPeekNext (void) const { EventMapCI i = m_list.begin (); - assert (i != m_list.end ()); + NS_ASSERT (i != m_list.end ()); return (*i).second; } Scheduler::EventKey SchedulerMap::RealPeekNextKey (void) const { EventMapCI i = m_list.begin (); - assert (i != m_list.end ()); + NS_ASSERT (i != m_list.end ()); return (*i).first; } void diff --git a/src/simulator/scheduler.cc b/src/simulator/scheduler.cc index 6feab0750..df450d466 100644 --- a/src/simulator/scheduler.cc +++ b/src/simulator/scheduler.cc @@ -20,7 +20,7 @@ */ #include "scheduler.h" -#include +#include "ns3/assert.h" namespace ns3 { @@ -40,25 +40,25 @@ Scheduler::IsEmpty (void) const EventImpl * Scheduler::PeekNext (void) const { - assert (!RealIsEmpty ()); + NS_ASSERT (!RealIsEmpty ()); return RealPeekNext (); } Scheduler::EventKey Scheduler::PeekNextKey (void) const { - assert (!RealIsEmpty ()); + NS_ASSERT (!RealIsEmpty ()); return RealPeekNextKey (); } void Scheduler::RemoveNext (void) { - assert (!RealIsEmpty ()); + NS_ASSERT (!RealIsEmpty ()); return RealRemoveNext (); } EventImpl * Scheduler::Remove (EventId id, EventKey *key) { - assert (!RealIsEmpty ()); + NS_ASSERT (!RealIsEmpty ()); return RealRemove (id, key); } diff --git a/src/simulator/simulator.cc b/src/simulator/simulator.cc index 152d7d896..d9d7b1c16 100644 --- a/src/simulator/simulator.cc +++ b/src/simulator/simulator.cc @@ -24,7 +24,7 @@ #include "event-impl.h" #include -#include +#include "ns3/assert.h" #include #include #include @@ -147,7 +147,7 @@ SimulatorPrivate::IsFinished (void) const uint64_t SimulatorPrivate::NextNs (void) const { - assert (!m_events->IsEmpty ()); + NS_ASSERT (!m_events->IsEmpty ()); Scheduler::EventKey nextKey = m_events->PeekNextKey (); return nextKey.m_ns; } @@ -179,14 +179,14 @@ SimulatorPrivate::Stop (void) void SimulatorPrivate::StopAt (Time const &at) { - assert (at.IsPositive ()); + NS_ASSERT (at.IsPositive ()); m_stopAt = at.GetNanoSeconds (); } EventId SimulatorPrivate::Schedule (Time const &time, EventImpl *event) { - assert (time.IsPositive ()); - assert (time >= NanoSeconds (m_currentNs)); + NS_ASSERT (time.IsPositive ()); + NS_ASSERT (time >= NanoSeconds (m_currentNs)); uint64_t ns = (uint64_t) time.GetNanoSeconds (); Scheduler::EventKey key = {ns, m_uid}; if (m_logEnable) @@ -296,7 +296,7 @@ void Simulator::SetStdMap (void) void Simulator::SetExternal (SchedulerFactory const*factory) { - assert (factory != 0); + NS_ASSERT (factory != 0); m_schedFactory = factory; m_listType = EXTERNAL; } @@ -326,7 +326,7 @@ Simulator::GetPriv (void) events = m_schedFactory->Create (); default: // not reached events = 0; - assert (false); + NS_ASSERT (false); break; } m_priv = new SimulatorPrivate (events); diff --git a/utils/replay-simulation.cc b/utils/replay-simulation.cc index 7641be419..9741cf84e 100644 --- a/utils/replay-simulation.cc +++ b/utils/replay-simulation.cc @@ -206,7 +206,7 @@ LogReader::ExecuteLogCommands (uint32_t uid) //std::cout << "exec insert remove" << std::endl; EventId id = Simulator::Schedule (NanoSeconds (cmd.insertRemove.m_evNs) - Now (), &LogReader::ExecuteLogCommands, this, m_uid); - assert (id.GetUid () == m_uid); + NS_ASSERT (id.GetUid () == m_uid); if (cmd.insertRemove.m_evLoc + 1 > m_removeEvents.size ()) { uint32_t missing = cmd.insertRemove.m_evLoc + 1 - m_removeEvents.size (); @@ -218,7 +218,7 @@ LogReader::ExecuteLogCommands (uint32_t uid) m_uid++; } break; default: - assert (false); + NS_ASSERT (false); break; } cmd = *m_command; From 873bbd4ba1c029115d5474bd85f1ebe055cd58a4 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 16 Feb 2007 10:04:02 +0100 Subject: [PATCH 22/25] convert old TRACE code to use new NS_DEBUG macro --- src/node/arp-cache.cc | 11 ----------- src/node/arp.cc | 25 +++++++++++++------------ src/node/ipv4-header.cc | 17 +++-------------- src/node/ipv4.cc | 19 ++++++++++--------- src/node/llc-snap-header.cc | 12 ------------ 5 files changed, 26 insertions(+), 58 deletions(-) diff --git a/src/node/arp-cache.cc b/src/node/arp-cache.cc index f60561500..d1d477b5c 100644 --- a/src/node/arp-cache.cc +++ b/src/node/arp-cache.cc @@ -26,17 +26,6 @@ #include "arp-cache.h" #include "arp-header.h" -#ifdef TRACE_ARP -#include -#include "simulator.h" -# define TRACE(x) \ -std::cout << "ARP TRACE " << Simulator::Now () << " " \ - << x << std::endl; -#else /* TRACE_ARP */ -# define TRACE(format,...) -#endif /* TRACE_ARP */ - - namespace ns3 { ArpCache::ArpCache (NetDevice *device, Ipv4Interface *interface) diff --git a/src/node/arp.cc b/src/node/arp.cc index 911083c72..4a8a3cb56 100644 --- a/src/node/arp.cc +++ b/src/node/arp.cc @@ -19,6 +19,7 @@ * Author: Mathieu Lacage */ #include "ns3/packet.h" +#include "ns3/debug.h" #include "arp.h" #include "arp-header.h" #include "arp-cache.h" @@ -27,7 +28,7 @@ #include "node.h" #include "ipv4.h" -#define TRACE(x) +NS_DEBUG_COMPONENT_DEFINE ("Arp"); namespace ns3 { @@ -77,7 +78,7 @@ Arp::Receive(Packet& packet, NetDevice *device) if (arp.IsRequest () && arp.GetDestinationIpv4Address () == cache->GetInterface ()->GetAddress ()) { - TRACE ("got request from " << arp.GetSourceIpv4Address () << " -- send reply"); + NS_DEBUG ("got request from " << arp.GetSourceIpv4Address () << " -- send reply"); SendArpReply (cache, arp.GetSourceIpv4Address (), arp.GetSourceHardwareAddress ()); } @@ -91,7 +92,7 @@ Arp::Receive(Packet& packet, NetDevice *device) { if (entry->IsWaitReply ()) { - TRACE ("got reply from " << arp.GetSourceIpv4Address () + NS_DEBUG ("got reply from " << arp.GetSourceIpv4Address () << " for waiting entry -- flush"); MacAddress from_mac = arp.GetSourceHardwareAddress (); Packet waiting = entry->MarkAlive (from_mac); @@ -101,14 +102,14 @@ Arp::Receive(Packet& packet, NetDevice *device) { // ignore this reply which might well be an attempt // at poisening my arp cache. - TRACE ("got reply from " << arp.GetSourceIpv4Address () << + NS_DEBUG ("got reply from " << arp.GetSourceIpv4Address () << " for non-waiting entry -- drop"); // XXX report packet as dropped. } } else { - TRACE ("got reply for unknown entry -- drop"); + NS_DEBUG ("got reply for unknown entry -- drop"); // XXX report packet as dropped. } } @@ -126,19 +127,19 @@ Arp::Lookup (Packet &packet, Ipv4Address destination, { if (entry->IsDead ()) { - TRACE ("dead entry for " << destination << " expired -- send arp request"); + NS_DEBUG ("dead entry for " << destination << " expired -- send arp request"); entry->MarkWaitReply (packet); SendArpRequest (cache, destination); } else if (entry->IsAlive ()) { - TRACE ("alive entry for " << destination << " expired -- send arp request"); + NS_DEBUG ("alive entry for " << destination << " expired -- send arp request"); entry->MarkWaitReply (packet); SendArpRequest (cache, destination); } else if (entry->IsWaitReply ()) { - TRACE ("wait reply for " << destination << " expired -- drop"); + NS_DEBUG ("wait reply for " << destination << " expired -- drop"); entry->MarkDead (); // XXX report packet as 'dropped' } @@ -147,18 +148,18 @@ Arp::Lookup (Packet &packet, Ipv4Address destination, { if (entry->IsDead ()) { - TRACE ("dead entry for " << destination << " valid -- drop"); + NS_DEBUG ("dead entry for " << destination << " valid -- drop"); // XXX report packet as 'dropped' } else if (entry->IsAlive ()) { - TRACE ("alive entry for " << destination << " valid -- send"); + NS_DEBUG ("alive entry for " << destination << " valid -- send"); *hardwareDestination = entry->GetMacAddress (); return true; } else if (entry->IsWaitReply ()) { - TRACE ("wait reply for " << destination << " valid -- drop previous"); + NS_DEBUG ("wait reply for " << destination << " valid -- drop previous"); Packet old = entry->UpdateWaitReply (packet); // XXX report 'old' packet as 'dropped' } @@ -168,7 +169,7 @@ Arp::Lookup (Packet &packet, Ipv4Address destination, else { // This is our first attempt to transmit data to this destination. - TRACE ("no entry for " << destination << " -- send arp request"); + NS_DEBUG ("no entry for " << destination << " -- send arp request"); entry = cache->Add (destination); entry->MarkWaitReply (packet); SendArpRequest (cache, destination); diff --git a/src/node/ipv4-header.cc b/src/node/ipv4-header.cc index 63cf985ba..205e0e479 100644 --- a/src/node/ipv4-header.cc +++ b/src/node/ipv4-header.cc @@ -20,19 +20,11 @@ */ #include "ns3/assert.h" +#include "ns3/debug.h" #include "ns3/header.h" #include "ipv4-header.h" -#define TRACE_CHUNK_IPV4 1 - -#ifdef TRACE_CHUNK_IPV4 -#include -#include "ns3/simulator.h" -# define TRACE(x) \ -std::cout << "CHUNK IPV4 TRACE " << Simulator::Now () << " " << x << std::endl; -#else /* TRACE_CHUNK_IPV4 */ -# define TRACE(format,...) -#endif /* TRACE_CHUNK_IPV4 */ +NS_DEBUG_COMPONENT_DEFINE ("Ipv4Header"); namespace ns3 { @@ -225,7 +217,6 @@ Ipv4Header::SerializeTo (Buffer::Iterator start) const { Buffer::Iterator i = start; - //TRACE ("init ipv4 current="<GetCurrent ()); uint8_t verIhl = (4 << 4) | (5); i.WriteU8 (verIhl); i.WriteU8 (m_tos); @@ -255,10 +246,9 @@ Ipv4Header::SerializeTo (Buffer::Iterator start) const #if 0 // XXX we need to add Buffer::Iterator::PeekData method uint8_t *data = start.PeekData (); - //TRACE ("fini ipv4 current="<GetCurrent ()); uint16_t checksum = UtilsChecksumCalculate (0, data, GetSize ()); checksum = UtilsChecksumComplete (checksum); - //TRACE ("checksum=" <GetAddress ().IsEqual (ipHeader.GetDestination ())) { - TRACE ("for me 1"); + NS_DEBUG ("for me 1"); return false; } } @@ -399,7 +400,7 @@ Ipv4::Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice &device) { if (ipHeader.GetDestination ().IsEqual (interface->GetBroadcast ())) { - TRACE ("for me 2"); + NS_DEBUG ("for me 2"); return false; } break; @@ -408,29 +409,29 @@ Ipv4::Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice &device) if (ipHeader.GetDestination ().IsEqual (Ipv4Address::GetBroadcast ())) { - TRACE ("for me 3"); + NS_DEBUG ("for me 3"); return false; } if (ipHeader.GetDestination ().IsEqual (Ipv4Address::GetAny ())) { - TRACE ("for me 4"); + NS_DEBUG ("for me 4"); return false; } if (ipHeader.GetTtl () == 1) { // Should send ttl expired here // XXX - TRACE ("not for me -- ttl expired. drop."); + NS_DEBUG ("not for me -- ttl expired. drop."); return true; } ipHeader.SetTtl (ipHeader.GetTtl () - 1); Ipv4Route *route = Lookup (ipHeader.GetDestination ()); if (route == 0) { - TRACE ("not for me -- forwarding but no route to host. drop."); + NS_DEBUG ("not for me -- forwarding but no route to host. drop."); return true; } - TRACE ("not for me -- forwarding."); + NS_DEBUG ("not for me -- forwarding."); SendRealOut (packet, ipHeader, *route); return true; } diff --git a/src/node/llc-snap-header.cc b/src/node/llc-snap-header.cc index 77a43c72c..81998f594 100644 --- a/src/node/llc-snap-header.cc +++ b/src/node/llc-snap-header.cc @@ -23,18 +23,6 @@ #include "llc-snap-header.h" -#define noTRACE_LLC_SNAP_HEADER 1 - -#ifdef TRACE_LLC_SNAP_HEADER -#include -#include "ns3/simulator.h" -# define TRACE(x) \ -std::cout << "LLCSNAP HEAD TRACE " << Simulator::Now () << " " << x << std::endl; -#else /* TRACE_LLC_SNAP_HEADER */ -# define TRACE(format,...) -#endif /* TRACE_LLC_SNAP_HEADER */ - - namespace ns3 { LlcSnapHeader::LlcSnapHeader () From e4166af2948d109e4cc0292e7b7216171ff800ba Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sat, 17 Feb 2007 09:28:02 +0100 Subject: [PATCH 23/25] remove Ipv4L3Protocol class. --- SConstruct | 4 +-- src/node/arp-ipv4-interface.cc | 3 +- src/node/internet-node.cc | 12 +++----- src/node/internet-node.h | 1 - src/node/ipv4-l3-protocol.cc | 56 ---------------------------------- src/node/ipv4-l3-protocol.h | 47 ---------------------------- src/node/ipv4.cc | 5 ++- src/node/ipv4.h | 10 ++++-- 8 files changed, 18 insertions(+), 120 deletions(-) delete mode 100644 src/node/ipv4-l3-protocol.cc delete mode 100644 src/node/ipv4-l3-protocol.h diff --git a/SConstruct b/SConstruct index 83d17ce55..3c4a42dba 100644 --- a/SConstruct +++ b/SConstruct @@ -169,7 +169,6 @@ node.add_sources ([ 'drop-tail.cc', 'l3-demux.cc', 'l3-protocol.cc', - 'ipv4-l3-protocol.cc', 'ipv4-l4-demux.cc', 'ipv4-l4-protocol.cc', 'udp-ipv4-l4-protocol.cc', @@ -206,14 +205,12 @@ node.add_headers ([ 'udp.h', 'ipv4-l4-protocol.h', 'udp-ipv4-l4-protocol.h', - 'ipv4-l3-protocol.h', 'arp-l3-protocol.h', 'arp-header.h', 'arp-cache-cache.h', 'arp.h', 'ipv4-loopback-interface.h', 'l3-demux.h', - 'l3-protocol.h', 'ipv4-l4-demux.h', 'net-device-list.h', 'llc-snap-header.h', @@ -233,6 +230,7 @@ node.add_inst_headers ([ 'ipv4-interface.h', 'mac-address.h', 'ipv4.h', + 'l3-protocol.h', 'ipv4-route.h', ]) diff --git a/src/node/arp-ipv4-interface.cc b/src/node/arp-ipv4-interface.cc index 391903e7a..3287d7dd6 100644 --- a/src/node/arp-ipv4-interface.cc +++ b/src/node/arp-ipv4-interface.cc @@ -26,6 +26,7 @@ #include "arp.h" #include "node.h" #include "net-device.h" +#include "ipv4.h" namespace ns3 { @@ -44,7 +45,7 @@ ArpIpv4Interface::SendTo (Packet p, Ipv4Address dest) bool found = arp->Lookup (p, dest, GetDevice (), &hardwareDestination); if (found) { - GetDevice ()->Send (p, hardwareDestination, 0x0800 /* XXX */); + GetDevice ()->Send (p, hardwareDestination, Ipv4::PROT_NUMBER); } } diff --git a/src/node/internet-node.cc b/src/node/internet-node.cc index 4909f1035..43c1ffab1 100644 --- a/src/node/internet-node.cc +++ b/src/node/internet-node.cc @@ -23,7 +23,6 @@ #include "net-device-list.h" #include "l3-demux.h" -#include "ipv4-l3-protocol.h" #include "ipv4-l4-demux.h" #include "internet-node.h" #include "udp.h" @@ -42,9 +41,8 @@ InternetNode::InternetNode() m_l3Demux = new L3Demux(this); m_ipv4L4Demux = new Ipv4L4Demux(this); m_udp = new Udp (this); - m_ipv4 = new Ipv4 (this); m_arp = new Arp (this); - m_l3Demux->Insert (Ipv4L3Protocol (this)); + m_l3Demux->Insert (Ipv4 (this)); m_l3Demux->Insert (ArpL3Protocol (this)); m_ipv4L4Demux->Insert (UdpIpv4L4Protocol (this)); SetupLoopback (); @@ -56,7 +54,6 @@ InternetNode::InternetNode (InternetNode const &o) m_l3Demux = o.m_l3Demux->Copy (this); m_ipv4L4Demux = o.m_ipv4L4Demux->Copy (this); m_udp = o.m_udp->Copy (this); - m_ipv4 = o.m_ipv4->Copy (this); m_arp = o.m_arp->Copy (this); SetupLoopback (); } @@ -67,7 +64,6 @@ InternetNode::~InternetNode () delete m_l3Demux; delete m_ipv4L4Demux; delete m_udp; - delete m_ipv4; delete m_arp; } @@ -77,8 +73,8 @@ InternetNode::SetupLoopback (void) Ipv4LoopbackInterface * interface = new Ipv4LoopbackInterface (this); interface->SetAddress (Ipv4Address::GetLoopback ()); interface->SetNetworkMask (Ipv4Mask::GetLoopback ()); - uint32_t index = m_ipv4->AddInterface (interface); - m_ipv4->AddHostRouteTo (Ipv4Address::GetLoopback (), index); + uint32_t index = GetIpv4 ()->AddInterface (interface); + GetIpv4 ()->AddHostRouteTo (Ipv4Address::GetLoopback (), index); interface->SetUp (); } @@ -112,7 +108,7 @@ InternetNode::GetIpv4L4Demux() const Ipv4 * InternetNode::GetIpv4 (void) const { - return m_ipv4; + return static_cast (m_l3Demux->Lookup (Ipv4::PROT_NUMBER)); } Udp * InternetNode::GetUdp (void) const diff --git a/src/node/internet-node.h b/src/node/internet-node.h index a8fe8f696..b6e2d29cb 100644 --- a/src/node/internet-node.h +++ b/src/node/internet-node.h @@ -52,7 +52,6 @@ private: NetDeviceList* m_netDevices; L3Demux* m_l3Demux; Ipv4L4Demux* m_ipv4L4Demux; - Ipv4 * m_ipv4; Udp * m_udp; Arp * m_arp; }; diff --git a/src/node/ipv4-l3-protocol.cc b/src/node/ipv4-l3-protocol.cc deleted file mode 100644 index 9cd5f5e2c..000000000 --- a/src/node/ipv4-l3-protocol.cc +++ /dev/null @@ -1,56 +0,0 @@ -// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- -// -// Copyright (c) 2006 Georgia Tech Research Corporation -// All rights reserved. -// -// 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: George F. Riley -// - -// NS3 - Layer 3 Protocol base class -// George F. Riley, Georgia Tech, Spring 2007 - -#include "ipv4-l3-protocol.h" -#include "ipv4.h" -#include "node.h" - -namespace ns3 { - -Ipv4L3Protocol::Ipv4L3Protocol (Node *node) - : L3Protocol (0x0800, 4), - m_node (node) -{} -Ipv4L3Protocol::~Ipv4L3Protocol () -{} - -Ipv4L3Protocol * -Ipv4L3Protocol::Copy (Node *node) const -{ - Ipv4L3Protocol *copy = new Ipv4L3Protocol (node); - return copy; -} -void -Ipv4L3Protocol::Receive(Packet& p, NetDevice &device) -{ - Ipv4 *ipv4 = m_node->GetIpv4 (); - if (ipv4 != 0) - { - ipv4->Receive (p, device); - } -} - - - -}//namespace ns3 diff --git a/src/node/ipv4-l3-protocol.h b/src/node/ipv4-l3-protocol.h deleted file mode 100644 index 90388446f..000000000 --- a/src/node/ipv4-l3-protocol.h +++ /dev/null @@ -1,47 +0,0 @@ -// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- -// -// Copyright (c) 2006 Georgia Tech Research Corporation -// All rights reserved. -// -// 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: George F. Riley -// - -// NS3 - Layer 3 Protocol base class -// George F. Riley, Georgia Tech, Spring 2007 - -#ifndef IPV4_L3_PROTOCOL_H -#define IPV4_L3_PROTOCOL_H - -#include "l3-protocol.h" - -namespace ns3 { - -class Ipv4L3Protocol : public L3Protocol -{ -public: - Ipv4L3Protocol (Node *node); - virtual ~Ipv4L3Protocol (); - - virtual Ipv4L3Protocol *Copy (Node *node) const; - virtual void Receive (Packet& p, NetDevice &device); -private: - Node *m_node; -}; - -}//namespace ns3 - - -#endif /* IPV4_L3_PROTOCOL_H */ diff --git a/src/node/ipv4.cc b/src/node/ipv4.cc index 83947b3db..d996467f7 100644 --- a/src/node/ipv4.cc +++ b/src/node/ipv4.cc @@ -36,8 +36,11 @@ NS_DEBUG_COMPONENT_DEFINE ("Ipv4"); namespace ns3 { +const uint16_t Ipv4::PROT_NUMBER = 0x0800; + Ipv4::Ipv4(Node *node) - : m_nInterfaces (0), + : L3Protocol (PROT_NUMBER, 4), + m_nInterfaces (0), m_defaultTtl (64), m_identification (0), m_defaultRoute (0), diff --git a/src/node/ipv4.h b/src/node/ipv4.h index ff7f86523..59fced43c 100644 --- a/src/node/ipv4.h +++ b/src/node/ipv4.h @@ -25,6 +25,7 @@ #include #include #include "ipv4-address.h" +#include "l3-protocol.h" namespace ns3 { @@ -40,8 +41,11 @@ class Node; /** * ::Send is always defined in subclasses. */ -class Ipv4 { +class Ipv4 : public L3Protocol +{ public: + static const uint16_t PROT_NUMBER; + Ipv4(Node *node); virtual ~Ipv4 (); @@ -88,7 +92,7 @@ public: Ipv4Interface *FindInterfaceForDevice (NetDevice const*device); - Ipv4* Copy(Node *node) const; + virtual Ipv4* Copy(Node *node) const; /** * Lower layer calls this method after calling L3Demux::Lookup * The ARP subclass needs to know from which NetDevice this @@ -96,7 +100,7 @@ public: * - implement a per-NetDevice ARP cache * - send back arp replies on the right device */ - void Receive(Packet& p, NetDevice &device); + virtual void Receive(Packet& p, NetDevice &device); void Send (Packet const &packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol); From d7a398bc118683e7ac9967ebe1bdcc62ab94ec1c Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sat, 17 Feb 2007 09:35:50 +0100 Subject: [PATCH 24/25] remove ArpL3Protocol object --- SConstruct | 2 -- src/node/arp-l3-protocol.cc | 53 ------------------------------------- src/node/arp-l3-protocol.h | 49 ---------------------------------- src/node/arp.cc | 17 +++++++----- src/node/arp.h | 9 ++++--- src/node/internet-node.cc | 8 ++---- 6 files changed, 18 insertions(+), 120 deletions(-) delete mode 100644 src/node/arp-l3-protocol.cc delete mode 100644 src/node/arp-l3-protocol.h diff --git a/SConstruct b/SConstruct index 3c4a42dba..b486badf4 100644 --- a/SConstruct +++ b/SConstruct @@ -187,7 +187,6 @@ node.add_sources ([ 'udp-socket.cc', 'udp.cc', 'arp-header.cc', - 'arp-l3-protocol.cc', 'arp-cache.cc', 'arp-ipv4-interface.cc', 'arp.cc', @@ -205,7 +204,6 @@ node.add_headers ([ 'udp.h', 'ipv4-l4-protocol.h', 'udp-ipv4-l4-protocol.h', - 'arp-l3-protocol.h', 'arp-header.h', 'arp-cache-cache.h', 'arp.h', diff --git a/src/node/arp-l3-protocol.cc b/src/node/arp-l3-protocol.cc deleted file mode 100644 index e32df81e3..000000000 --- a/src/node/arp-l3-protocol.cc +++ /dev/null @@ -1,53 +0,0 @@ -// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- -// -// Copyright (c) 2006 Georgia Tech Research Corporation -// All rights reserved. -// -// 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: George F. Riley -// - -// NS3 - Layer 3 Protocol base class -// George F. Riley, Georgia Tech, Spring 2007 - -#include "arp-l3-protocol.h" -#include "arp.h" -#include "node.h" - -namespace ns3 { - -ArpL3Protocol::ArpL3Protocol (Node *node) - : L3Protocol (0x0806, 0/* XXX: correct version number ? */ ), - m_node (node) -{} -ArpL3Protocol::~ArpL3Protocol () -{} - -ArpL3Protocol * -ArpL3Protocol::Copy (Node *node) const -{ - return new ArpL3Protocol (node); -} -void -ArpL3Protocol::Receive(Packet& p, NetDevice &device) -{ - Arp * arp = m_node->GetArp (); - if (arp != 0) - { - arp->Receive (p, &device); - } -} - -}//namespace ns3 diff --git a/src/node/arp-l3-protocol.h b/src/node/arp-l3-protocol.h deleted file mode 100644 index 7b76563bf..000000000 --- a/src/node/arp-l3-protocol.h +++ /dev/null @@ -1,49 +0,0 @@ -// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- -// -// Copyright (c) 2006 Georgia Tech Research Corporation -// All rights reserved. -// -// 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: George F. Riley -// - -// NS3 - Layer 3 Protocol base class -// George F. Riley, Georgia Tech, Spring 2007 -#ifndef ARP_L3_PROTOCOL_H -#define ARP_L3_PROTOCOL_H - -#include "l3-protocol.h" - -namespace ns3 { - -class Node; -class NetDevice; -class Packet; - -class ArpL3Protocol : public L3Protocol -{ - public: - ArpL3Protocol (Node *node); - virtual ~ArpL3Protocol (); - - virtual ArpL3Protocol *Copy (Node *node) const; - virtual void Receive(Packet& p, NetDevice &device); -private: - Node *m_node; -}; - -}//namespace ns3 - -#endif /* ARP_L3_PROTOCOL_H */ diff --git a/src/node/arp.cc b/src/node/arp.cc index 4a8a3cb56..acf7035ae 100644 --- a/src/node/arp.cc +++ b/src/node/arp.cc @@ -32,8 +32,11 @@ NS_DEBUG_COMPONENT_DEFINE ("Arp"); namespace ns3 { +const uint16_t Arp::PROT_NUMBER = 0x0806; + Arp::Arp (Node *node) - : m_node (node) + : L3Protocol (PROT_NUMBER, 0/* XXX: correct version number ? */ ), + m_node (node) {} Arp::~Arp () @@ -45,7 +48,7 @@ Arp::~Arp () } Arp * -Arp::Copy (Node *node) +Arp::Copy (Node *node) const { return new Arp (node); } @@ -69,9 +72,9 @@ Arp::FindCache (NetDevice *device) } void -Arp::Receive(Packet& packet, NetDevice *device) +Arp::Receive(Packet& packet, NetDevice &device) { - ArpCache *cache = FindCache (device); + ArpCache *cache = FindCache (&device); ArpHeader arp; packet.Peek (arp); packet.Remove (arp); @@ -84,7 +87,7 @@ Arp::Receive(Packet& packet, NetDevice *device) } else if (arp.IsReply () && arp.GetDestinationIpv4Address ().IsEqual (cache->GetInterface ()->GetAddress ()) && - arp.GetDestinationHardwareAddress ().IsEqual (device->GetAddress ())) + arp.GetDestinationHardwareAddress ().IsEqual (device.GetAddress ())) { Ipv4Address from = arp.GetSourceIpv4Address (); ArpCache::Entry *entry = cache->Lookup (from); @@ -187,7 +190,7 @@ Arp::SendArpRequest (ArpCache const *cache, Ipv4Address to) to); Packet packet; packet.Add (arp); - cache->GetDevice ()->Send (packet, cache->GetDevice ()->GetBroadcast (), 0x0806); + cache->GetDevice ()->Send (packet, cache->GetDevice ()->GetBroadcast (), PROT_NUMBER); } void @@ -199,7 +202,7 @@ Arp::SendArpReply (ArpCache const *cache, Ipv4Address toIp, MacAddress toMac) toMac, toIp); Packet packet; packet.Add (arp); - cache->GetDevice ()->Send (packet, toMac, 0x0806); + cache->GetDevice ()->Send (packet, toMac, PROT_NUMBER); } }//namespace ns3 diff --git a/src/node/arp.h b/src/node/arp.h index a325da23e..4ea17dad6 100644 --- a/src/node/arp.h +++ b/src/node/arp.h @@ -24,6 +24,7 @@ #include #include "ipv4-address.h" #include "mac-address.h" +#include "l3-protocol.h" namespace ns3 { @@ -32,14 +33,16 @@ class NetDevice; class Node; class Packet; -class Arp +class Arp : public L3Protocol { public: + static const uint16_t PROT_NUMBER; + Arp (Node *node); ~Arp (); - Arp *Copy (Node *node); + virtual Arp *Copy (Node *node) const; - void Receive(Packet& p, NetDevice *device); + virtual void Receive(Packet& p, NetDevice &device); bool Lookup (Packet &p, Ipv4Address destination, NetDevice *device, MacAddress *hardwareDestination); diff --git a/src/node/internet-node.cc b/src/node/internet-node.cc index 43c1ffab1..c15ae68b8 100644 --- a/src/node/internet-node.cc +++ b/src/node/internet-node.cc @@ -29,7 +29,6 @@ #include "ipv4.h" #include "arp.h" #include "udp-ipv4-l4-protocol.h" -#include "arp-l3-protocol.h" #include "ipv4-loopback-interface.h" namespace ns3 { @@ -41,9 +40,8 @@ InternetNode::InternetNode() m_l3Demux = new L3Demux(this); m_ipv4L4Demux = new Ipv4L4Demux(this); m_udp = new Udp (this); - m_arp = new Arp (this); m_l3Demux->Insert (Ipv4 (this)); - m_l3Demux->Insert (ArpL3Protocol (this)); + m_l3Demux->Insert (Arp (this)); m_ipv4L4Demux->Insert (UdpIpv4L4Protocol (this)); SetupLoopback (); } @@ -54,7 +52,6 @@ InternetNode::InternetNode (InternetNode const &o) m_l3Demux = o.m_l3Demux->Copy (this); m_ipv4L4Demux = o.m_ipv4L4Demux->Copy (this); m_udp = o.m_udp->Copy (this); - m_arp = o.m_arp->Copy (this); SetupLoopback (); } @@ -64,7 +61,6 @@ InternetNode::~InternetNode () delete m_l3Demux; delete m_ipv4L4Demux; delete m_udp; - delete m_arp; } void @@ -119,7 +115,7 @@ InternetNode::GetUdp (void) const Arp * InternetNode::GetArp (void) const { - return m_arp; + return static_cast (m_l3Demux->Lookup (Arp::PROT_NUMBER)); } From c2e3d19e066102d73b8ede99e93db4c7f1bba59f Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Sat, 17 Feb 2007 09:42:30 +0100 Subject: [PATCH 25/25] remove UdpIpv4L4Protocol class --- SConstruct | 2 -- src/node/internet-node.cc | 8 ++--- src/node/internet-node.h | 2 -- src/node/udp-ipv4-l4-protocol.cc | 58 -------------------------------- src/node/udp-ipv4-l4-protocol.h | 58 -------------------------------- src/node/udp.cc | 9 ++--- src/node/udp.h | 14 ++++---- 7 files changed, 15 insertions(+), 136 deletions(-) delete mode 100644 src/node/udp-ipv4-l4-protocol.cc delete mode 100644 src/node/udp-ipv4-l4-protocol.h diff --git a/SConstruct b/SConstruct index b486badf4..486185c27 100644 --- a/SConstruct +++ b/SConstruct @@ -171,7 +171,6 @@ node.add_sources ([ 'l3-protocol.cc', 'ipv4-l4-demux.cc', 'ipv4-l4-protocol.cc', - 'udp-ipv4-l4-protocol.cc', 'ipv4-address.cc', 'internet-node.cc', 'net-device.cc', @@ -203,7 +202,6 @@ node.add_headers ([ 'ipv4-checksum.h', 'udp.h', 'ipv4-l4-protocol.h', - 'udp-ipv4-l4-protocol.h', 'arp-header.h', 'arp-cache-cache.h', 'arp.h', diff --git a/src/node/internet-node.cc b/src/node/internet-node.cc index c15ae68b8..42e17243a 100644 --- a/src/node/internet-node.cc +++ b/src/node/internet-node.cc @@ -28,7 +28,6 @@ #include "udp.h" #include "ipv4.h" #include "arp.h" -#include "udp-ipv4-l4-protocol.h" #include "ipv4-loopback-interface.h" namespace ns3 { @@ -39,10 +38,9 @@ InternetNode::InternetNode() m_netDevices = new NetDeviceList(); m_l3Demux = new L3Demux(this); m_ipv4L4Demux = new Ipv4L4Demux(this); - m_udp = new Udp (this); m_l3Demux->Insert (Ipv4 (this)); m_l3Demux->Insert (Arp (this)); - m_ipv4L4Demux->Insert (UdpIpv4L4Protocol (this)); + m_ipv4L4Demux->Insert (Udp (this)); SetupLoopback (); } @@ -51,7 +49,6 @@ InternetNode::InternetNode (InternetNode const &o) m_netDevices = new NetDeviceList (); m_l3Demux = o.m_l3Demux->Copy (this); m_ipv4L4Demux = o.m_ipv4L4Demux->Copy (this); - m_udp = o.m_udp->Copy (this); SetupLoopback (); } @@ -60,7 +57,6 @@ InternetNode::~InternetNode () delete m_netDevices; delete m_l3Demux; delete m_ipv4L4Demux; - delete m_udp; } void @@ -109,7 +105,7 @@ InternetNode::GetIpv4 (void) const Udp * InternetNode::GetUdp (void) const { - return m_udp; + return static_cast (m_ipv4L4Demux->Lookup (Udp::PROT_NUMBER)); } Arp * diff --git a/src/node/internet-node.h b/src/node/internet-node.h index b6e2d29cb..1b9e6378a 100644 --- a/src/node/internet-node.h +++ b/src/node/internet-node.h @@ -52,8 +52,6 @@ private: NetDeviceList* m_netDevices; L3Demux* m_l3Demux; Ipv4L4Demux* m_ipv4L4Demux; - Udp * m_udp; - Arp * m_arp; }; }//namespace ns3 diff --git a/src/node/udp-ipv4-l4-protocol.cc b/src/node/udp-ipv4-l4-protocol.cc deleted file mode 100644 index d8e04a6dd..000000000 --- a/src/node/udp-ipv4-l4-protocol.cc +++ /dev/null @@ -1,58 +0,0 @@ -// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- -// -// Copyright (c) 2006 Georgia Tech Research Corporation -// All rights reserved. -// -// 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: George F. Riley -// - -// NS3 - Layer 4 Protocol base class -// George F. Riley, Georgia Tech, Spring 2007 - -#include "udp-ipv4-l4-protocol.h" -#include "node.h" -#include "udp.h" - -namespace ns3 { - -/* see http://www.iana.org/assignments/protocol-numbers */ -const uint8_t UdpIpv4L4Protocol::UDP_PROTOCOL = 17; - - -UdpIpv4L4Protocol::UdpIpv4L4Protocol(Node *node) - : Ipv4L4Protocol (UDP_PROTOCOL, 2), - m_node (node) -{} -UdpIpv4L4Protocol::~UdpIpv4L4Protocol () -{} - -UdpIpv4L4Protocol* -UdpIpv4L4Protocol::Copy(Node *node) const -{ - return new UdpIpv4L4Protocol (node); -} -void -UdpIpv4L4Protocol::Receive(Packet& p, - Ipv4Address const &source, - Ipv4Address const &destination) -{ - if (m_node->GetUdp () != 0) - { - m_node->GetUdp ()->Receive (p, source, destination); - } -} - -}//namespace ns3 diff --git a/src/node/udp-ipv4-l4-protocol.h b/src/node/udp-ipv4-l4-protocol.h deleted file mode 100644 index 124d6fe8b..000000000 --- a/src/node/udp-ipv4-l4-protocol.h +++ /dev/null @@ -1,58 +0,0 @@ -// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- -// -// Copyright (c) 2006 Georgia Tech Research Corporation -// All rights reserved. -// -// 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: George F. Riley -// - -// NS3 - Layer 4 Protocol base class -// George F. Riley, Georgia Tech, Spring 2007 - -#ifndef UDP_IPV4_L4_PROTOCOL_H -#define UDP_IPV4_L4_PROTOCOL_H - -#include -#include "ipv4-l4-protocol.h" - -namespace ns3 { - -class Node; -class Packet; -class Ipv4Address; - -class UdpIpv4L4Protocol : public Ipv4L4Protocol { -public: - UdpIpv4L4Protocol(Node *node); - virtual ~UdpIpv4L4Protocol (); - - virtual UdpIpv4L4Protocol* Copy(Node *node) const; - /** - * Called from lower-level layers to send the packet up - * in the stack. - */ - virtual void Receive(Packet& p, - Ipv4Address const &source, - Ipv4Address const &destination); - - private: - Node *m_node; - static const uint8_t UDP_PROTOCOL; -}; - -} // Namespace ns3 - -#endif /* UDP_IPV4_L4_PROTOCOL */ diff --git a/src/node/udp.cc b/src/node/udp.cc index a9d5e1692..f1f0fef29 100644 --- a/src/node/udp.cc +++ b/src/node/udp.cc @@ -33,10 +33,11 @@ namespace ns3 { /* see http://www.iana.org/assignments/protocol-numbers */ -const uint8_t Udp::UDP_PROTOCOL = 17; +const uint8_t Udp::PROT_NUMBER = 17; Udp::Udp (Node *node) - : m_node (node), + : Ipv4L4Protocol (PROT_NUMBER, 2), + m_node (node), m_endPoints (new Ipv4EndPointDemux ()) {} @@ -109,14 +110,14 @@ Udp::Send (Packet packet, udpHeader.SetPayloadSize (packet.GetSize ()); udpHeader.InitializeChecksum (saddr, daddr, - UDP_PROTOCOL); + PROT_NUMBER); packet.Add (udpHeader); Ipv4 *ipv4 = m_node->GetIpv4 (); if (ipv4 != 0) { - ipv4->Send (packet, saddr, daddr, UDP_PROTOCOL); + ipv4->Send (packet, saddr, daddr, PROT_NUMBER); } } diff --git a/src/node/udp.h b/src/node/udp.h index f11877528..da88a1433 100644 --- a/src/node/udp.h +++ b/src/node/udp.h @@ -28,13 +28,16 @@ #include "ipv4-address.h" #include "ipv4-end-point-demux.h" #include "udp-end-point.h" +#include "ipv4-l4-protocol.h" namespace ns3 { class Node; -class Udp { +class Udp : public Ipv4L4Protocol { public: + static const uint8_t PROT_NUMBER; + Udp (Node *node); virtual ~Udp (); @@ -50,12 +53,11 @@ public: Ipv4Address saddr, Ipv4Address daddr, uint16_t sport, uint16_t dport); // inherited from Ipv4L4Protocol - Udp* Copy(Node *node) const; - void Receive(Packet& p, - Ipv4Address const &source, - Ipv4Address const &destination); + virtual Udp* Copy(Node *node) const; + virtual void Receive(Packet& p, + Ipv4Address const &source, + Ipv4Address const &destination); private: - static const uint8_t UDP_PROTOCOL; Node *m_node; Ipv4EndPointDemux *m_endPoints; };