diff --git a/.hgignore b/.hgignore
index 96ea69ce7..c19d9d91a 100644
--- a/.hgignore
+++ b/.hgignore
@@ -1,11 +1,10 @@
-.*.orig$
-.*\.o$
-.*~$
-build-dir
-build
-.*\.sconsign
-doc/html.*
-doc/latex.*
-.lock-wscript
-.waf*
-waf
+\.rej$
+\.orig$
+\.o$
+~$
+^build-dir
+^build
+^doc/html
+^doc/latex
+^\.lock-wscript
+^\.waf
diff --git a/.hgtags b/.hgtags
index aac74dfcf..35f08ab9c 100644
--- a/.hgtags
+++ b/.hgtags
@@ -4,3 +4,5 @@
38099dd26e9467b8f49f8632f22789858149a6e7 release ns-3.0.3
5701e60bf01a8ac1308945e69001e0cc07948faf release ns-3.0.4
08046b6aef37932507696a2f2f427b42d693781e release ns-3.0.5
+267e2ebc28e4e4ae2f579e1cfc29902acade0c34 buffer-working-before-breaking
+606df29888e7573b825fc891a002f0757166b616 release ns-3.0.6
diff --git a/RELEASE_NOTES b/RELEASE_NOTES
index 85a5f2d6e..e429e5fec 100644
--- a/RELEASE_NOTES
+++ b/RELEASE_NOTES
@@ -3,6 +3,13 @@
This file contains ns-3 release notes (most recent releases first).
+Release 3.0.6 (2007/09/15)
+========================
+ - Static multicast IPv4 routing
+ - Logging overhaul (NS_LOG macros)
+ - Refactoring of tracing subsystem
+ - Tutorial document started
+
Release 3.0.5 (2007/08/15)
========================
diff --git a/SConstruct b/SConstruct
deleted file mode 100644
index 9c9a2567c..000000000
--- a/SConstruct
+++ /dev/null
@@ -1,521 +0,0 @@
-## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
-
-import os.path
-import build
-
-version_file = open ('VERSION', 'r')
-version = version_file.readline ()
-version_file.close ()
-version = version.strip ()
-
-ns3 = build.Ns3()
-ns3.build_dir = 'build-dir'
-ns3.version = version
-ns3.name = 'ns3'
-ns3.distname = 'ns'
-ns3.doxygen_config = os.path.join('doc', 'doxygen.conf')
-ns3.add_extra_dist(os.path.join('doc', 'main.txt'))
-ns3.add_extra_dist ('doc/architecture.pdf')
-ns3.add_extra_dist ('doc/contributing.txt')
-ns3.add_extra_dist ('doc/build.txt')
-ns3.add_extra_dist ('doc/codingstd.txt')
-ns3.add_extra_dist ('doc/mercurial.txt')
-ns3.add_extra_dist ('README')
-ns3.add_extra_dist ('RELEASE_NOTES')
-ns3.add_extra_dist ('AUTHORS')
-ns3.add_extra_dist ('VERSION')
-
-ns3.add_extra_dist('doc/build-waf.txt')
-ns3.add_extra_dist('ns3/_placeholder_')
-for wscript in [
- "src/core/wscript",
- "src/node/wscript",
- "src/devices/p2p/wscript",
- "src/common/wscript",
- "src/applications/wscript",
- "src/simulator/wscript",
- "src/internet-node/wscript",
- "src/wscript",
- "utils/wscript",
- "samples/wscript",
- "examples/wscript",
- "wscript",
- ]:
- ns3.add_extra_dist(wscript)
-ns3.add_extra_dist('waf')
-ns3.add_extra_dist('waf.bat')
-
-#
-# The Core module
-#
-core = build.Ns3Module('core', 'src/core')
-ns3.add(core)
-core.add_sources([
- 'callback-test.cc',
- 'debug.cc',
- 'assert.cc',
- 'ptr.cc',
- 'object.cc',
- 'test.cc',
- 'random-variable.cc',
- 'rng-stream.cc',
- 'uid-manager.cc',
- 'default-value.cc',
- 'command-line.cc',
- 'type-name.cc',
- 'component-manager.cc',
- ])
-env = Environment()
-if env['PLATFORM'] == 'posix' or env['PLATFORM'] == 'darwin' or env['PLATFORM'] == 'cygwin':
- core.add_external_dep('pthread')
- core.add_sources([
- 'unix-system-wall-clock-ms.cc',
- ])
-elif env['PLATFORM'] == 'win32':
- core.add_sources([
- 'win32-system-wall-clock-ms.cc',
- ])
-core.add_headers ([
- 'uid-manager.h',
- 'singleton.h',
-])
-core.add_inst_headers([
- 'system-wall-clock-ms.h',
- 'empty.h',
- 'callback.h',
- 'ptr.h',
- 'object.h',
- 'debug.h',
- 'assert.h',
- 'fatal-error.h',
- 'test.h',
- 'random-variable.h',
- 'rng-stream.h',
- 'default-value.h',
- 'command-line.h',
- 'type-name.h',
- 'component-manager.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 Simulator module
-#
-simu = build.Ns3Module('simulator', 'src/simulator')
-ns3.add(simu)
-simu.add_dep('core')
-simu.add_external_dep('m')
-simu.add_sources([
- 'high-precision.cc',
- 'time.cc',
- 'event-id.cc',
- 'scheduler.cc',
- 'scheduler-factory.cc',
- 'scheduler-list.cc',
- 'scheduler-heap.cc',
- 'scheduler-map.cc',
- 'event-impl.cc',
- 'simulator.cc',
- ])
-simu.add_headers([
- 'scheduler-heap.h',
- 'scheduler-map.h',
- 'scheduler-list.h'
- ])
-simu.add_inst_headers([
- 'high-precision.h',
- 'nstime.h',
- 'event-id.h',
- 'event-impl.h',
- 'simulator.h',
- 'scheduler.h',
- 'scheduler-factory.h',
- 'simulation-singleton.h',
- ])
-high_precision_as_double = ARGUMENTS.get('high-precision-as-double', 'n')
-if high_precision_as_double == 'y':
- simu.add_inst_header ('high-precision-double.h')
- simu.add_source ('high-precision-double.cc')
-else:
- simu.add_inst_headers ([
- 'high-precision-128.h',
- 'cairo-wideint-private.h'
- ])
- simu.add_sources ([
- 'high-precision-128.cc',
- 'cairo-wideint.c',
- ])
-
-def config_simulator (env, config):
- retval = []
- high_precision_as_double = ARGUMENTS.get('high-precision-as-double', 'n')
- if high_precision_as_double == 'y':
- retval.append ('#define USE_HIGH_PRECISION_DOUBLE 1')
- else:
- retval.append ('#undef USE_HIGH_PRECISION_DOUBLE')
- if config.CheckCHeader ('stdint.h') == 1:
- retval.append ('#define HAVE_STDINT_H 1')
- elif config.CheckCHeader ('inttypes.h') == 1:
- retval.append ('#define HAVE_INTTYPES_H 1')
- elif config.CheckCHeader ('sys/inttypes.h') == 1:
- retval.append ('#define HAVE_SYS_INT_TYPES_H 1')
- return retval
-simu.add_config (config_simulator)
-
-#
-# The Common module
-#
-common = build.Ns3Module('common', 'src/common')
-common.add_deps(['core', 'simulator'])
-ns3.add(common)
-common.add_sources([
- 'buffer.cc',
- 'chunk.cc',
- 'header.cc',
- 'trailer.cc',
- 'packet-printer.cc',
- 'packet-metadata.cc',
- 'packet.cc',
- 'tags.cc',
- 'pcap-writer.cc',
- 'variable-tracer-test.cc',
- 'trace-context.cc',
- 'trace-resolver.cc',
- 'callback-trace-source.cc',
- 'empty-trace-resolver.cc',
- 'composite-trace-resolver.cc',
- 'trace-root.cc',
- 'data-rate.cc',
- ])
-common.add_headers ([
- ])
-common.add_inst_headers([
- 'buffer.h',
- 'chunk.h',
- 'header.h',
- 'trailer.h',
- 'tags.h',
- 'packet.h',
- 'packet-printer.h',
- 'packet-metadata.h',
- 'uv-trace-source.h',
- 'sv-trace-source.h',
- 'fv-trace-source.h',
- 'pcap-writer.h',
- 'callback-trace-source.h',
- 'trace-context.h',
- 'trace-resolver.h',
- 'empty-trace-resolver.h',
- 'composite-trace-resolver.h',
- 'array-trace-resolver.h',
- 'trace-root.h',
- 'terminal-trace-resolver.h',
- 'data-rate.h',
- ])
-
-#
-# The Node module
-#
-node = build.Ns3Module ('node', 'src/node')
-ns3.add (node)
-node.add_deps (['core', 'common', 'simulator'])
-node.add_sources ([
- 'node.cc',
- 'ipv4-address.cc',
- 'net-device.cc',
- 'mac-address.cc',
- 'llc-snap-header.cc',
- 'ipv4-route.cc',
- 'queue.cc',
- 'drop-tail-queue.cc',
- 'channel.cc',
- 'node-list.cc',
- 'socket.cc',
- 'socket-factory.cc',
- 'udp.cc',
- 'ipv4.cc',
- 'application.cc',
- ])
-node.add_inst_headers ([
- 'node.h',
- 'ipv4-address.h',
- 'net-device.h',
- 'mac-address.h',
- 'ipv4-route.h',
- 'queue.h',
- 'drop-tail-queue.h',
- 'llc-snap-header.h',
- 'channel.h',
- 'node-list.h',
- 'socket.h',
- 'socket-factory.h',
- 'udp.h',
- 'ipv4.h',
- 'application.h',
- ])
-
-#
-# The Applications module
-#
-applications = build.Ns3Module ('applications', 'src/applications')
-ns3.add (applications)
-applications.add_deps (['node'])
-applications.add_sources ([
- 'onoff-application.cc',
-])
-applications.add_inst_headers ([
- 'onoff-application.h',
-])
-
-#
-# The Internet Node module
-#
-inode = build.Ns3Module ('internet-node', 'src/internet-node')
-ns3.add (inode)
-inode.add_deps (['node', 'routing'])
-inode.add_sources ([
- 'internet-node.cc',
- 'l3-demux.cc',
- 'l3-protocol.cc',
- 'ipv4-l4-demux.cc',
- 'ipv4-l4-protocol.cc',
- 'ipv4-header.cc',
- 'udp-header.cc',
- 'ipv4-checksum.cc',
- 'ipv4-interface.cc',
- 'ipv4-l3-protocol.cc',
- 'ipv4-end-point.cc',
- 'udp-l4-protocol.cc',
- 'arp-header.cc',
- 'arp-cache.cc',
- 'arp-ipv4-interface.cc',
- 'arp-l3-protocol.cc',
- 'ipv4-loopback-interface.cc',
- 'header-utils.cc',
- 'udp-socket.cc',
- 'ipv4-end-point-demux.cc',
- 'arp-private.cc',
- 'ipv4-impl.cc',
- 'ipv4-private.cc',
- 'ascii-trace.cc',
- 'pcap-trace.cc',
- 'udp-impl.cc',
-])
-inode.add_headers ([
- 'ipv4-checksum.h',
- 'arp-header.h',
- 'arp-cache.h',
- 'arp-l3-protocol.h',
- 'ipv4-loopback-interface.h',
- 'l3-demux.h',
- 'header-utils.h',
- 'arp-ipv4-interface.h',
- 'udp-socket.h',
- 'udp-l4-protocol.h',
- 'arp-private.h',
- 'ipv4-impl.h',
- 'ipv4-private.h',
- 'ipv4-l3-protocol.h',
- 'l3-protocol.h',
- 'ipv4-l4-protocol.h',
- 'ipv4-l4-demux.h',
- 'ipv4-end-point-demux.h',
- 'ipv4-end-point.h',
- 'ipv4-header.h',
- 'ipv4-interface.h',
- 'udp-header.h',
- 'sgi-hashmap.h',
- 'udp-impl.h',
-])
-inode.add_inst_headers ([
- 'internet-node.h',
- 'ascii-trace.h',
- 'pcap-trace.h',
- 'ipv4-header.h',
- 'udp-header.h',
-])
-
-#
-# The Point-to-point module
-#
-p2p = build.Ns3Module ('p2p', 'src/devices/p2p')
-ns3.add (p2p)
-p2p.add_deps (['node'])
-p2p.add_sources ([
- 'p2p-net-device.cc',
- 'p2p-channel.cc',
- 'p2p-topology.cc',
- ])
-p2p.add_inst_headers ([
- 'p2p-net-device.h',
- 'p2p-channel.h',
- 'p2p-topology.h',
- ])
-
-#
-# The Routing module
-#
-routing = build.Ns3Module('routing', 'src/routing')
-routing.add_deps(['core', 'node'])
-ns3.add(routing)
-routing.add_sources([
- 'routing-environment.cc',
- 'static-router.cc',
- 'static-route-manager.cc',
- 'static-route-manager-impl.cc',
- 'candidate-queue.cc',
- ])
-routing.add_headers ([
- 'candidate-queue.h',
- 'static-route-manager-impl.h',
- ])
-routing.add_inst_headers([
- 'routing-environment.h',
- 'static-router.h',
- 'static-route-manager.h',
- ])
-
-# utils
-run_tests = build.Ns3Module('run-tests', 'utils')
-ns3.add(run_tests)
-run_tests.set_executable()
-run_tests.add_deps(['core', 'simulator', 'common', 'routing'])
-run_tests.add_source('run-tests.cc')
-
-bench_object = build.Ns3Module('bench-object', 'utils')
-ns3.add(bench_object)
-bench_object.set_executable()
-bench_object.add_deps(['core'])
-bench_object.add_source('bench-object.cc')
-
-bench_packets = build.Ns3Module('bench-packets', 'utils')
-ns3.add(bench_packets)
-bench_packets.set_executable()
-bench_packets.add_deps (['core', 'common'])
-bench_packets.add_source('bench-packets.cc')
-
-bench_simu = build.Ns3Module('bench-simulator', 'utils')
-ns3.add(bench_simu)
-bench_simu.set_executable()
-bench_simu.add_dep('simulator')
-bench_simu.add_source('bench-simulator.cc')
-
-replay_simu = build.Ns3Module('replay-simulation', 'utils')
-ns3.add(replay_simu)
-replay_simu.set_executable()
-replay_simu.add_dep('simulator')
-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_packet_printer = build.Ns3Module('sample-packet-printer', 'samples')
-sample_packet_printer.set_executable()
-ns3.add(sample_packet_printer)
-sample_packet_printer.add_deps (['common', 'internet-node'])
-sample_packet_printer.add_source('main-packet-printer.cc')
-
-sample_callback = build.Ns3Module('sample-callback', 'samples')
-sample_callback.set_executable()
-ns3.add(sample_callback)
-sample_callback.add_dep('core')
-sample_callback.add_source('main-callback.cc')
-
-sample_ptr = build.Ns3Module('sample-ptr', 'samples')
-sample_ptr.set_executable()
-ns3.add(sample_ptr)
-sample_ptr.add_dep('core')
-sample_ptr.add_source('main-ptr.cc')
-
-sample_trace = build.Ns3Module('sample-trace', 'samples')
-#ns3.add(sample_trace)
-sample_trace.add_dep('common')
-sample_trace.set_executable()
-sample_trace.add_source('main-trace.cc')
-
-sample_query_interface = build.Ns3Module('sample-query-interface', 'samples')
-ns3.add(sample_query_interface)
-sample_query_interface.add_dep('common')
-sample_query_interface.set_executable()
-sample_query_interface.add_source('main-query-interface.cc')
-
-sample_simu = build.Ns3Module('sample-simulator', 'samples')
-ns3.add(sample_simu)
-sample_simu.set_executable()
-sample_simu.add_dep('simulator')
-sample_simu.add_source('main-simulator.cc')
-
-sample_packet = build.Ns3Module('sample-packet', 'samples')
-ns3.add(sample_packet)
-sample_packet.set_executable()
-sample_packet.add_dep('common')
-sample_packet.add_source('main-packet.cc')
-
-sample_test = build.Ns3Module('sample-test', 'samples')
-sample_test.set_executable()
-ns3.add(sample_test)
-sample_test.add_dep('core')
-sample_test.add_source('main-test.cc')
-
-sample_simple = build.Ns3Module('sample-simple', 'samples')
-sample_simple.set_executable()
-ns3.add(sample_simple)
-sample_simple.add_deps(['core', 'simulator', 'node', 'internet-node', 'routing'])
-sample_simple.add_source('main-simple.cc')
-
-sample_sp2p = build.Ns3Module('sample-simple-p2p', 'samples')
-sample_sp2p.set_executable()
-#n3.add(sample_sp2p)
-sample_sp2p.add_deps(['core', 'simulator', 'node', 'internet-node', 'p2p'])
-sample_sp2p.add_source('main-simple-p2p.cc')
-
-sample_default_value = build.Ns3Module('sample-default-value', 'samples')
-sample_default_value.set_executable()
-ns3.add(sample_default_value)
-sample_default_value.add_deps(['core', 'simulator', 'node', 'p2p'])
-sample_default_value.add_source('main-default-value.cc')
-
-sample_object = build.Ns3Module('sample-object', 'samples')
-sample_object.set_executable()
-ns3.add(sample_object)
-sample_object.add_deps(['core'])
-sample_object.add_source('main-object.cc')
-
-sample_component_manager = build.Ns3Module('sample-component-manager', 'samples')
-sample_component_manager.set_executable()
-ns3.add(sample_component_manager)
-sample_component_manager.add_deps(['core'])
-sample_component_manager.add_source('main-component-manager.cc')
-
-# examples
-example_simple_p2p = build.Ns3Module('simple-p2p', 'examples')
-example_simple_p2p.set_executable()
-ns3.add(example_simple_p2p)
-example_simple_p2p.add_deps(['core', 'simulator', 'node', 'p2p', 'internet-node', 'applications', 'routing'])
-example_simple_p2p.add_source('simple-p2p.cc')
-
-example_static_routing = build.Ns3Module('simple-static-routing', 'examples')
-example_static_routing.set_executable()
-ns3.add(example_static_routing)
-example_static_routing.add_deps(['core', 'simulator', 'node', 'p2p', 'internet-node', 'applications', 'routing'])
-example_static_routing.add_source('simple-static-routing.cc')
-
-ns3.generate_dependencies()
diff --git a/VERSION b/VERSION
index eca690e73..818bd47ab 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-3.0.5
+3.0.6
diff --git a/doc/doxygen.conf b/doc/doxygen.conf
index fc6fd25fa..ac0f72a0e 100644
--- a/doc/doxygen.conf
+++ b/doc/doxygen.conf
@@ -450,7 +450,7 @@ WARN_LOGFILE =
# directories like "/usr/src/myproject". Separate the files or directories
# with spaces.
-INPUT = src doc/main.txt
+INPUT = src doc/main.txt doc/trace-source-list.h doc/tracing.h
# If the value of the INPUT tag contains directories, you can use the
# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
@@ -514,7 +514,7 @@ EXAMPLE_RECURSIVE = NO
# directories that contain image that are included in the documentation (see
# the \image command).
-IMAGE_PATH =
+IMAGE_PATH = doc
# The INPUT_FILTER tag can be used to specify a program that doxygen should
# invoke to filter for each input file. Doxygen will invoke the filter program
diff --git a/doc/main.txt b/doc/main.txt
index 3fc144687..37e1ed92d 100644
--- a/doc/main.txt
+++ b/doc/main.txt
@@ -23,6 +23,7 @@
* - \ref config
* - a base class for objects which need to support reference counting
* and QueryInterface: ns3::Object and ns3::InterfaceId
+ * - a set of low-level trace facilities integrated in the ns3::Object system: \ref tracing
* - a ns3::ComponentManager which can be used to manage the creation
* of any object which derives from ns3::Object through an ns3::ClassId
* - a smart-pointer class ns3::Ptr designed to work together with ns3::Object
@@ -33,11 +34,10 @@
* ns3::Scheduler and ns3::SchedulerFactory
* - a simulator class used to create, schedule and cancel events: ns3::Simulator
*
- * The "common" module contains:
+ * The "core" module contains:
* - a packet class to create and manipulate simulation packets: ns3::Packet, ns3::Header,
* and ns3::Trailer. This packet class also supports per-packet ns3::Tag which are
* globs of data which can be attached to any packet.
- * - a set of low-level trace facilities: \ref lowleveltracing
*
* The "node" module contains:
* - a ns3::Node base class which should be subclassed by any new type of
diff --git a/doc/namespace-2.dia b/doc/namespace-2.dia
new file mode 100644
index 000000000..5cd5ed59e
--- /dev/null
+++ b/doc/namespace-2.dia
@@ -0,0 +1,1658 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ #A4#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #/devices/[0-n]#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #NodeList#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #Node#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #/queue#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #/nodes/[0-n]#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #/udp#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #/rx#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #/netdevice#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #/ipv4#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #/interfaces/[0-n]#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #/rx#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #/queue#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #/rx#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #/enqueue#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #/dequeue#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #/drop#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #InternetNode#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #PointToPointNetDevice#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #Queue#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #Ipv4L3Protocol#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #Ipv4Interface#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #CsmaNetDevice#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #/enqueue#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #/dequeue#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #/drop#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #Queue#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/doc/namespace-2.png b/doc/namespace-2.png
new file mode 100644
index 000000000..7ea379c82
Binary files /dev/null and b/doc/namespace-2.png differ
diff --git a/doc/trace-source-list.h b/doc/trace-source-list.h
new file mode 100644
index 000000000..c23d06ece
--- /dev/null
+++ b/doc/trace-source-list.h
@@ -0,0 +1,204 @@
+///
+/// \ingroup TraceSourceList
+/// \brief send ipv4 packet to outgoing interface
+/// \param arg1 the trace context associated to the connected trace source.
+/// \param arg2 packet sent.
+/// \param arg3 index of output ipv4 interface.
+///
+///
+/// The path to this trace source is: /nodes/[0-n]/ipv4/tx.
+///
+/// The following classes can be extracted from \p arg1 with
+/// ns3::TraceContext::GetElement:
+/// - ns3::NodeListIndex
+/// - ns3::Ipv4L3ProtocolTraceContextElement
+void TraceSinkCallback0 (const TraceContext & arg1, const Packet & arg2, uint32_t arg3);
+
+///
+/// \ingroup TraceSourceList
+/// \brief receive ipv4 packet from incoming interface
+/// \param arg1 the trace context associated to the connected trace source.
+/// \param arg2 packet received.
+/// \param arg3 index of input ipv4 interface.
+///
+///
+/// The path to this trace source is: /nodes/[0-n]/ipv4/rx.
+///
+/// The following classes can be extracted from \p arg1 with
+/// ns3::TraceContext::GetElement:
+/// - ns3::NodeListIndex
+/// - ns3::Ipv4L3ProtocolTraceContextElement
+void TraceSinkCallback1 (const TraceContext & arg1, const Packet & arg2, uint32_t arg3);
+
+///
+/// \ingroup TraceSourceList
+/// \brief drop ipv4 packet
+/// \param arg1 the trace context associated to the connected trace source.
+/// \param arg2 packet dropped.
+///
+///
+/// The path to this trace source is: /nodes/[0-n]/ipv4/drop.
+///
+/// The following classes can be extracted from \p arg1 with
+/// ns3::TraceContext::GetElement:
+/// - ns3::NodeListIndex
+/// - ns3::Ipv4L3ProtocolTraceContextElement
+void TraceSinkCallback2 (const TraceContext & arg1, const Packet & arg2);
+
+///
+/// \ingroup TraceSourceList
+/// \brief store packet in queue
+/// \param arg1 the trace context associated to the connected trace source.
+/// \param arg2 packet queued.
+///
+///
+/// The path to this trace source is: /nodes/[0-n]/devices/[0-n]/queue/enqueue.
+///
+/// The following classes can be extracted from \p arg1 with
+/// ns3::TraceContext::GetElement:
+/// - ns3::NodeListIndex
+/// - ns3::NodeNetDeviceIndex
+/// - ns3::QueueTraceType
+void TraceSinkCallback3 (const TraceContext & arg1, const Packet & arg2);
+
+///
+/// \ingroup TraceSourceList
+/// \brief remove packet from queue
+/// \param arg1 the trace context associated to the connected trace source.
+/// \param arg2 packet dequeued.
+///
+///
+/// The path to this trace source is: /nodes/[0-n]/devices/[0-n]/queue/dequeue.
+///
+/// The following classes can be extracted from \p arg1 with
+/// ns3::TraceContext::GetElement:
+/// - ns3::NodeListIndex
+/// - ns3::NodeNetDeviceIndex
+/// - ns3::QueueTraceType
+void TraceSinkCallback4 (const TraceContext & arg1, const Packet & arg2);
+
+///
+/// \ingroup TraceSourceList
+/// \brief drop packet from queue
+/// \param arg1 the trace context associated to the connected trace source.
+/// \param arg2 packet dropped.
+///
+///
+/// The path to this trace source is: /nodes/[0-n]/devices/[0-n]/queue/drop.
+///
+/// The following classes can be extracted from \p arg1 with
+/// ns3::TraceContext::GetElement:
+/// - ns3::NodeListIndex
+/// - ns3::NodeNetDeviceIndex
+/// - ns3::QueueTraceType
+void TraceSinkCallback5 (const TraceContext & arg1, const Packet & arg2);
+
+///
+/// \ingroup TraceSourceList
+/// \brief receive MAC packet
+/// \param arg1 the trace context associated to the connected trace source.
+/// \param arg2 packet received.
+///
+///
+/// The path to this trace source is: /nodes/[0-n]/devices/[0-n]/rx.
+///
+/// The following classes can be extracted from \p arg1 with
+/// ns3::TraceContext::GetElement:
+/// - ns3::NodeListIndex
+/// - ns3::NodeNetDeviceIndex
+/// - ns3::PointToPointTraceType
+void TraceSinkCallback6 (const TraceContext & arg1, const Packet & arg2);
+
+///
+/// \ingroup TraceSourceList
+/// \brief receive MAC packet
+/// \param arg1 the trace context associated to the connected trace source.
+/// \param arg2 packet received.
+///
+///
+/// The path to this trace source is: /nodes/[0-n]/devices/[0-n]/rx.
+///
+/// The following classes can be extracted from \p arg1 with
+/// ns3::TraceContext::GetElement:
+/// - ns3::NodeListIndex
+/// - ns3::NodeNetDeviceIndex
+/// - ns3::CsmaTraceType
+void TraceSinkCallback7 (const TraceContext & arg1, const Packet & arg2);
+
+///
+/// \ingroup TraceSourceList
+/// \brief drop MAC packet
+/// \param arg1 the trace context associated to the connected trace source.
+/// \param arg2 packet dropped.
+///
+///
+/// The path to this trace source is: /nodes/[0-n]/devices/[0-n]/drop.
+///
+/// The following classes can be extracted from \p arg1 with
+/// ns3::TraceContext::GetElement:
+/// - ns3::NodeListIndex
+/// - ns3::NodeNetDeviceIndex
+/// - ns3::CsmaTraceType
+void TraceSinkCallback8 (const TraceContext & arg1, const Packet & arg2);
+
+///
+/// \ingroup TraceSourceList
+/// \brief The value of the speed vector changed
+/// \param arg1 the trace context associated to the connected trace source.
+/// \param arg2 the mobility model whose course changed.
+///
+///
+/// The path to this trace source is: /nodes/[0-n]/$MobilityModelNotifier/course-change.
+///
+/// The following classes can be extracted from \p arg1 with
+/// ns3::TraceContext::GetElement:
+/// - ns3::NodeListIndex
+void TraceSinkCallback9 (const TraceContext & arg1, Ptr arg2);
+
+///
+/// \ingroup TraceSourceList
+/// \brief send ipv4 packet to outgoing interface
+/// \param arg1 the trace context associated to the connected trace source.
+/// \param arg2 packet sent.
+/// \param arg3 index of output ipv4 interface.
+///
+///
+/// The path to this trace source is: /nodes/[0-n]/$Ipv4L3Protocol/tx.
+///
+/// The following classes can be extracted from \p arg1 with
+/// ns3::TraceContext::GetElement:
+/// - ns3::NodeListIndex
+/// - ns3::Ipv4L3ProtocolTraceContextElement
+void TraceSinkCallback10 (const TraceContext & arg1, const Packet & arg2, uint32_t arg3);
+
+///
+/// \ingroup TraceSourceList
+/// \brief receive ipv4 packet from incoming interface
+/// \param arg1 the trace context associated to the connected trace source.
+/// \param arg2 packet received.
+/// \param arg3 index of input ipv4 interface.
+///
+///
+/// The path to this trace source is: /nodes/[0-n]/$Ipv4L3Protocol/rx.
+///
+/// The following classes can be extracted from \p arg1 with
+/// ns3::TraceContext::GetElement:
+/// - ns3::NodeListIndex
+/// - ns3::Ipv4L3ProtocolTraceContextElement
+void TraceSinkCallback11 (const TraceContext & arg1, const Packet & arg2, uint32_t arg3);
+
+///
+/// \ingroup TraceSourceList
+/// \brief drop ipv4 packet
+/// \param arg1 the trace context associated to the connected trace source.
+/// \param arg2 packet dropped.
+///
+///
+/// The path to this trace source is: /nodes/[0-n]/$Ipv4L3Protocol/drop.
+///
+/// The following classes can be extracted from \p arg1 with
+/// ns3::TraceContext::GetElement:
+/// - ns3::NodeListIndex
+/// - ns3::Ipv4L3ProtocolTraceContextElement
+void TraceSinkCallback12 (const TraceContext & arg1, const Packet & arg2);
+
diff --git a/doc/tracing.h b/doc/tracing.h
new file mode 100644
index 000000000..45e7d9db5
--- /dev/null
+++ b/doc/tracing.h
@@ -0,0 +1,576 @@
+/**
+ * \defgroup TraceSourceList List of trace sources
+ */
+
+/**
+ * \defgroup tracing Tracing
+ *
+ * The flexibility of the ns-3 tracing system comes at the cost of quite
+ * a bit of complexity so, before trying to use the low-level aspects
+ * of the tracing API, it is important to focus on some basic definitions:
+ *
+ * - A trace source is an object instance which can report trace events
+ * to a set of listening trace sinks.
+ *
+ * - A trace sink is a user-provided callback (a function) which can
+ * be connected to a set of trace sources to receive the events generated
+ * by each trace source.
+ *
+ * - A trace resolver is an object which allows users to establish
+ * connections between a set of trace sources and a set of trace sinks.
+ *
+ * \section TraceSource Generating Trace Events
+ *
+ * So, what does it look like in practice ? First, let's look at trace
+ * sources. We have two types of trace sources: numeric, and, normal
+ * trace sources. Numeric trace sources behave as normal c++ integers
+ * or c++ floating point numbers except that they report as trace events
+ * each change of their value. For example:
+ * \code
+ * class MyModel
+ * {
+ * public:
+ * void DoSomething (void)
+ * {
+ * // use the "int" trace source just
+ * // like any other "int" variable.
+ * m_cwnd *= 2;
+ * m_cwnd += 4;
+ * if (m_cwnd > 100)
+ * {
+ * // do something.
+ * }
+ * }
+ * private:
+ * // declare an instance of a "int" trace source
+ * SVTraceSource m_cwnd;
+ * };
+ * \endcode
+ * Normal trace sources, on the other hand, allow you to trace the
+ * call of arbitrary functions and methods, as shown below. They are
+ * typically used to track "rx", "tx", or "drop" events but could
+ * also be used to track route change events, or position change
+ * events:
+ * \code
+ * class MyModel
+ * {
+ * public:
+ * void DoSomething (Packet packet)
+ * {
+ * // report this event on packet
+ * m_doSomething (packet);
+ * // do something
+ * }
+ * private:
+ * // report every "something" function call.
+ * CallbackTraceSource m_doSomething;
+ * };
+ * \endcode
+ * Every type of trace source derives from the ns3::TraceSource base class.
+ * As of today, the set of concrete subclasses is relatively short:
+ * ns3::CallbackTraceSource, ns3::SvTraceSource, ns3::UvTraceSource, and,
+ * ns3::FvTraceSource.
+ *
+ * \section TraceSink Receiving Trace Events
+ *
+ * To receive these trace events, a user should specify a set of trace sinks.
+ * For example, to receive the "int" and the "something" events shown in the
+ * examples above, a user would declare the following functions:
+ * \code
+ * // oldValue and newValue contain the previous and new values of
+ * // the connected SVTraceSource trace source.
+ * void
+ * CwndTraceSink (const TraceContext &context, int64_t oldValue, int64_t newValue)
+ * {
+ * // for example, print the new value:
+ * std::cout << "cwnd=" << newValue << std::endl;
+ * }
+ * void
+ * DoSomethingTraceSink (const TraceContext &context, Packet packet)
+ * {
+ * // for example, print the arguments
+ * std::cout << "packet " << packet << std::endl;
+ * }
+ * \endcode
+ * Each of these sink function takes, as a first argument, a reference to a
+ * const TraceContext object. This context object contains information which
+ * describes the instance of the connected trace source: that information is
+ * setup during the connection process and does not change afterwards
+ * The type and the number of the other arguments to each trace sink depends
+ * on the type of the connected trace source: it conveys per-event information
+ * from the trace source to the trace sink. For example, UVTraceSource and
+ * SVTraceSource trace sources require two extra arguments. The former requires
+ * two unsigned 64 bit integers while the latter requires two signed 64 bit
+ * integers. More generally, users can consult the \ref TraceSourceList
+ * to figure out the arguments which a trace sink is required to receive
+ * for each trace source: a signature of the user trace sink must match
+ * _exactly_ the signature documented in the \ref TraceSourceList.
+ *
+ *
+ * \section TraceSourceSimpleExport A simple way to connect Trace Sources with Trace Sinks
+ *
+ * The crux of the complexity of the ns-3 tracing system comes from its
+ * flexible system used to connect trace sources to trace sinks but what is really
+ * nice about it is that it is not necessary to use it to setup simple traces.
+ *
+ * The simplest way to export a set of trace sources to a user, for example,
+ * during the early prototyping phases of a system, is to add a set of public methods
+ * to give to your users access to the trace source object instances you use to generate
+ * trace events:
+ * \code
+ * class MyModel
+ * {
+ * public:
+ * void DoSomething (Packet packet)
+ * {
+ * // report this event on packet
+ * m_doSomething (packet);
+ * // do something
+ * }
+ * CallbackTraceSource *PeekSomethingTraceSource (void) const
+ * {
+ * return &m_doSomething
+ * }
+ * private:
+ * // report every "something" function call.
+ * CallbackTraceSource m_doSomething;
+ * };
+ * \endcode
+ * If your users hold a pointer to an instance of MyModel, and if they want to connect
+ * a MySomethingSink, they can simply do the following which invokes the
+ * TraceSource::AddCallback method and creates a Callback object from the user's
+ * sink with the MakeCallback function.
+ * \code
+ * void
+ * MySomethingSink (const TraceContext &context, Packet packet)
+ * {
+ * // do whatever you want.
+ * }
+ * MyModel *model = ...;
+ * CallbackTraceSource *source = model->PeekSomethingTraceSource ();
+ * source->AddCallback (MakeCallback (&MySomethingSink));
+ * \endcode
+ *
+ * The full power of the tracing system comes however from its ns3::NodeList::Connect
+ * method which is described in the following sections.
+ *
+ * \section TraceConnection Connecting Trace Sources to Trace Sinks
+ *
+ * If a trace source is integrated in the ns-3 trace connection facility, a user
+ * should call the ns3::NodeList::Connect method to establish a connection between
+ * a trace sink and a set of matching trace sources. The second argument to that
+ * method is a callback to the user's trace sink.
+ * That callback is easy to construct: call ns3::MakeCallback and you are done. The
+ * first argument is a string whose format is similar to a unix path and which is
+ * used to uniquely identify the set of trace sources you want to connect to.
+ * The set of acceptable path strings is also documented in the \ref TraceSourceList.
+ *
+ * So, what does this look like from the perspective of a user ? If we wanted to
+ * connect to a trace source defined somewhere deep into the a set of NetDevice objects
+ * located in some nodes of the system, we could write the following:
+ * \code
+ * void
+ * DoSomethingTraceSink (const TraceContext &context, Packet packet)
+ * {
+ * // for example, print the arguments
+ * std::cout << "packet: " << packet << std::endl;
+ * }
+ * // connect the above sink to a matching trace source
+ * NodeList::Connect ("/nodes/* /devices/* /rx", MakeCallback &DoSomethingTraceSink);
+ * \endcode
+ *
+ * The connection path string "/nodes/* /devices/* /rx" matches the "rx" trace source
+ * located in every netdevice located in every node. The syntax of that path string
+ * is loosely based on regular expressions so, a user could conceivably connect
+ * to the trace sources present in only one node identified by node index:
+ * "/nodex/3/devices/* /rx".
+ *
+ * The matching algorithm used here is very useful since it allows you to connect
+ * at once a large set of trace sources to a single sink but it introduces another
+ * problem: it becomes impossible when you receive an event in your trace sink to
+ * know from _which_ trace source the event is coming from. In our example, the
+ * trace source might be coming from the NetDevice number 2 of Node 10 or Netdevice
+ * number 0 of Node 5. In both cases, you might need to know which of these NetDevice
+ * is generating this event, if only to generate some ascii trace dump. Another
+ * similar use-case is that you might have connected the same trace sink to
+ * multiple types of events which have the same signature: it is quite common
+ * to receive all tx, rx, and drop events in the same trace sink and that would be
+ * quite trivial to achieve with a string such as: "/nodes/* /devices/* /*"
+ *
+ * The source of a trace event can be retrieved from a trace sink using
+ * different means: the simplest
+ * way to get this information is to use the builtin printing facility of
+ * the TraceContext object:
+ * \code
+ * void
+ * DoSomethingTraceSink (const TraceContext &context, Packet packet)
+ * {
+ * // for example, print the arguments
+ * std::cout << "context=\"" << context << "\" packet: " << packet << std::endl;
+ * }
+ * \endcode
+ * The above code is going to generate output which looks like the following:
+ * \code
+ * context="nodeid=2 device=0 dev-rx" packet: IPV4(tos 0x0 ttl 64 id 0 offset ...
+ * context="nodeid=1 device=0 dev-rx" packet: IPV4(tos 0x0 ttl 64 id 0 offset ...
+ * ...
+ * \endcode
+ *
+ * Another more advanced way to get information out of a TraceContext is to call its
+ * ns3::TraceContext::GetElement method. This method takes as its first and only
+ * argument an instance of the object we want to read and the list of available
+ * object instances we can read from a TraceContext is documented, once again,
+ * in the \ref TraceSourceList. For example, we could write the following to
+ * generate adhoc trace output:
+ * \code
+ * void DeviceRxSink (const TraceContext &context, const Packet &packet)
+ * {
+ * NodeListIndex nodeIndex;
+ * NodeNetDeviceIndex deviceIndex;
+ * context.GetElement (nodeIndex);
+ * context.GetElement (deviceIndex);
+ * std::cout << "node-index=" << nodeIndex.Get ();
+ * std::cout << ", device-index=" << deviceIndex.Get ();
+ * std::cout << ", packet: " << packet;
+ * std::cout << std::endl;
+ * }
+ * \endcode
+ *
+ * \section ExportingTraceSources Exporting new Trace Sources
+ *
+ * Using existing trace sources to connect them to a set of adhoc trace sinks
+ * is not really complicated but, setting up new trace sources which can hook
+ * in this automatic connection system is a bit more complicated.
+ *
+ * So far, we know that a model author can generate trace events really easily:
+ * \code
+ * class MyModel
+ * {
+ * public:
+ * void DoSomething (Packet packet)
+ * {
+ * // report this event on packet with value
+ * m_doSomething (packet);
+ * // do something
+ * }
+ * private:
+ * // report every "something" function call.
+ * CallbackTraceSource m_doSomething;
+ * };
+ * \endcode
+ *
+ * To make these new trace sources available to the rest of the connection system,
+ * the first step is to make sure that your model object derives from the ns3::Object
+ * base class either directly (as shown below) or indirectly through another base class:
+ * \code
+ * class MyModel : public Object {...};
+ * // or:
+ * class SomeOtherObject : public Object {...};
+ * class MyModel : public SomeOtherObject {...};
+ * \endcode
+ *
+ * This is pretty trivial and lays the ground for the second step: overriding the
+ * ns3::Object::GetTraceResolver method:
+ * \code
+ * class MyModel : public MyParent
+ * {
+ * public:
+ * // declare overriden method
+ * virtual Ptr GetTraceResolver (void) const;
+ * private:
+ * // the new trace source to export.
+ * CallbackTraceSource m_rxSource;
+ * };
+ * \endcode
+ *
+ * To implement this method, you could attempt to implement a new subclass of
+ * the ns3::TraceResolver base class and return an instance from this method but
+ * this would be very hard. Instead, you should use the helper class
+ * ns3::CompositeTraceResolver to register your trace sources and chain up to
+ * your parent:
+ * \code
+ * Ptr
+ * MyModel::GetTraceResolver (void) const
+ * {
+ * // create an empty trace resolver
+ * Ptr resolver = Create ();
+ * // register m_rxSource
+ * resolver->AddSource ("rx", // the name of the trace source in the path string
+ * TraceDoc ("some help text to explain the purpose of this trace source",
+ * "Packet", // the type of the first argument to the trace source
+ * "the purpose of the first argument",
+ * "type-of-second-argument", "purpose-of-second-argument"),
+ * m_rxSource // the trace source itself is registered
+ * );
+ * // make sure we include the trace sources implemented in the parent.
+ * resolver->SetParentResolver (MyParent::GetTraceResolver ());
+ * return resolver;
+ * }
+ * \endcode
+ *
+ * Once you have written that code, you must make sure that this new method GetTraceResolver
+ * is going to be called at some point by the tracing system. If your model is located somewhere
+ * deep in MAC or PHY layer, that is, it is part of a NetDevice implementation, all you
+ * have to do is to make sure that your model is registered as a "composite" of your NetDevice
+ * subclass:
+ * \code
+ * class MyNetDevice : public NetDevice
+ * {
+ * public:
+ * Ptr GetTraceResolver (void) const;
+ * private:
+ * Ptr m_model;
+ * };
+ *
+ * Ptr
+ * MyNetDevice::GetTraceResolver (void) const
+ * {
+ * Ptr resolver = ...;
+ * // register other trace source
+ * ...
+ * // register now your model as a "composite"
+ * resolver->AddComposite ("my-model", m_model);
+ * // chain up to parent.
+ * resolver->SetParentResolver (NetDevice::GetTraceResolver ());
+ * return resolver;
+ * }
+ * \endcode
+ *
+ * The code above will make your "rx" trace source appear under the
+ * /nodes/xx/devices/xx/my-model/rx namespace path.
+ *
+ * If you have implemented a new layer 3 or 4 protocol object, the process to
+ * export your trace sources is quite similar. You need to subclass from
+ * ns3::Object, override the ns3::Object::GetTraceResolver method, make
+ * sure you chain up to your parent's GetTraceResolver method, and, finally,
+ * make sure that someone calls your new GetTraceResolver method. How to accomplish
+ * the latter should be documented in the node's API documentation which describes
+ * how to implement a new layer 3 or 4 protocol object.
+ *
+ * \section AdvancedTraceContext Creating new Trace Context Elements
+ *
+ * The last important feature which model developers need to understand
+ * is how to provide extra context information to trace sinks. For example,
+ * if your model exports both rx and tx trace sources which share the same
+ * signature, it is quite natural for a user to connect to a single trace sink
+ * to both of them with a trace path string such as "/nodes/* /devices/* /(rx|tx)".
+ * In this case, it becomes necessary to be able, from the trace sink function,
+ * to tell which event triggered the call to the trace sink: a rx or a tx event.
+ *
+ * That example is detailed below with a TX, a RX, and a DROP source:
+ * \code
+ * class MyModel
+ * {
+ * private:
+ * CallbackTraceSource m_rxSource;
+ * CallbackTraceSource m_txSource;
+ * CallbackTraceSource m_dropSource;
+ * };
+ * \endcode
+ * When a single sink is connected to all 3 sources here, one might want
+ * to write code like the following:
+ * \code
+ * void DeviceRxSink (const TraceContext &context, const Packet &packet)
+ * {
+ * switch (type) {
+ * case RX:
+ * std::cout << "rx" << std::endl;
+ * break;
+ * case TX:
+ * std::cout << "tx" << std::endl;
+ * break;
+ * case DROP:
+ * std::cout << "drop" << std::endl;
+ * break;
+ * }
+ * \endcode
+ *
+ * \subsection AdvancedTraceContextSimpleSolution The simple solution
+ *
+ * The simplest way to do achieve the result shown above is to include
+ * in the trace source an extra explicit argument which describes the source event:
+ * - define a small enum with 3 values
+ * - change the signature of m_rxSource, m_txSource, and m_dropSource to include
+ * the enum
+ * - pass the enum value in each event
+ *
+ * The resulting code is shown below:
+ * \code
+ * class MyModel
+ * {
+ * public:
+ * // define the trace type enum.
+ * enum TraceType {
+ * RX,
+ * TX,
+ * DROP
+ * };
+ * private:
+ * // generate events
+ * void NotifyRxPacket (Packet p) {
+ * m_rxSource (p, MyModel::RX);
+ * }
+ * void NotifyTxPacket (Packet p) {
+ * m_rxSource (p, MyModel::TX);
+ * }
+ * void NotifyDropPacket (Packet p) {
+ * m_rxSource (p, MyModel::DROP);
+ * }
+ * CallbackTraceSource m_rxSource;
+ * CallbackTraceSource m_txSource;
+ * CallbackTraceSource m_dropSource;
+ * };
+ * \endcode
+ * These 3 new sources can be connected easily to a new trace sink:
+ * \code
+ * void ASimpleTraceSink (const TraceContext &context, const Packet &packet, enum MyModel::TraceType type)
+ * {
+ * // here, read the "type" argument
+ * }
+ * \endcode
+ *
+ * This solution works but it makes it impossible to connect a single trace sink to a set
+ * of trace sources which represent "rx" events in different NetDevice objects since
+ * each of them will define a different enum type with different values: since the
+ * trace sink signature must match exactly the trace source signature, it is impossible
+ * to connect at the same time to all "rx" events of different NetDevice.
+ *
+ * \subsection AdvancedTraceContextFancySolution The more complex and generic solution
+ *
+ * There is, hopefully, a way to get the best of both worlds, that is, to allow a
+ * user to connect to a lot of trace source events of the same kind but coming from different
+ * implementations and to allow the user to differentiate between these different
+ * implementations.
+ *
+ * Rather than define an adhoc enum type with a list of trace sources, you can also
+ * define a new ns3::TraceContextElement for your source sources. For example, if you
+ * define a new MyModelTraceType class which contains the type of trace, your users can
+ * then write trace sink code which looks like this:
+ * \code
+ * void AFancyTraceSink (const TraceContext &context, const Packet &packet)
+ * {
+ * MyModelTraceType type;
+ * if (context.GetElement (type))
+ * {
+ * switch (type.Get ())
+ * {
+ * case MyModelTraceType::RX:
+ * std::cout << "rx" << std::endl;
+ * break;
+ * case MyModelTraceType::TX:
+ * std::cout << "tx" << std::endl;
+ * break;
+ * case MyModelTraceType::DROP:
+ * std::cout << "drop" << std::endl;
+ * break;
+ * }
+ * }
+ * }
+ * \endcode
+ *
+ * Of course, since the type of trace is stored in the TraceContext, your users can
+ * also take the shortcut which uses the printing functionality of the TraceContext:
+ * \code
+ * void ALessFancyTraceSink (const TraceContext &context, const Packet &packet)
+ * {
+ * std::cout << "context=\"" << context << "\" packet: " << packet << std::endl;
+ * }
+ * \endcode
+ * which will generate something like the following when the trace source comes
+ * from MyModel:
+ * \code
+ * context="my-model-rx" packet: ...
+ * \endcode
+ *
+ * The first step to achieve this is to define and implement a new
+ * subclass of the ns3::TraceContextElement base class. The exact list of
+ * public methods which must be implemented is described in the API
+ * documentation of the ns3::TraceContextElement class.
+ * \code
+ * class MyModelTraceType : public TraceContextElement
+ * {
+ * public:
+ * enum Type {
+ * RX,
+ * TX,
+ * DROP
+ * };
+ * // called from MyModel::GetTraceResolver
+ * MyModelTraceType (enum Type type);
+ * // called from trace sink
+ * enum Type Get (void) const;
+ * // needed by the tracing subsystem
+ * static uint16_t GetUid (void);
+ * // needed by the tracing subsystem to
+ * // print the content of a TraceContext
+ * void Print (std::ostream &os) const;
+ * // needed by the tracing subsystem to
+ * // generate the doxygen documentation.
+ * std::string GetTypeName (void) const;
+ * private:
+ * enum Type m_type;
+ * };
+ * \endcode
+ * The implementation does not require much thinking:
+ * \code
+ * MyModelTraceType::MyModelTraceType (enum Type type)
+ * : m_type (type)
+ * {}
+ * enum Type
+ * MyModelTraceType::Get (void) const
+ * {
+ * return m_type;
+ * }
+ * uint16_t
+ * MyModelTraceType::GetUid (void)
+ * {
+ * // use protected TraceContextElement::AllocateUid method
+ * // the input string is used to uniquely identify this new subclass
+ * static uint16_t uid = AllocateUid ("ns3::MyModelTraceType");
+ * return uid;
+ * }
+ * void
+ * MyModelTraceType::Print (std::ostream &os) const
+ * (
+ * // this method is invoked by the print function of a TraceContext
+ * // if it contains an instance of this TraceContextElement.
+ * switch (m_type) {
+ * case RX: os << "rx"; break;
+ * // ...
+ * }
+ * )
+ * std::string
+ * MyModelTraceType::GetTypeName (void) const
+ * {
+ * // This method should return a fully-qualified c++ typename
+ * // This method is used only for documentation purposes to
+ * // generate the content of the Trace Source List.
+ * return "ns3::MyModelTraceType";
+ * }
+ * \endcode
+ *
+ * Once this subclass is implemented, the work is almost completed: you
+ * just need to pass an instance of that class as the last argument of
+ * the ns3::CompositeTraceResolver::AddSource method as shown below:
+ * \code
+ * Ptr
+ * MyModel::GetTraceResolver (void) const
+ * {
+ * // create an empty trace resolver
+ * Ptr resolver = Create ();
+ * // register m_rxSource
+ * resolver->AddSource ("rx", // the name of the trace source in the path string
+ * TraceDoc ("some help text to explain the purpose of this trace source",
+ * "Packet", // the type of the first argument to the trace source
+ * "the purpose of the first argument",
+ * "type-of-second-argument", "purpose-of-second-argument"),
+ * m_rxSource, // the trace source itself is registered
+ * // the TraceContextElement associated to this trace source.
+ * MyModelTraceType (MyModelTraceType::RX)
+ * );
+ * // make sure we include the trace sources implemented in the parent.
+ * resolver->SetParentResolver (MyParent::GetTraceResolver ());
+ * return resolver;
+ * }
+ * \endcode
+ */
diff --git a/examples/csma-broadcast.cc b/examples/csma-broadcast.cc
new file mode 100644
index 000000000..06775e26d
--- /dev/null
+++ b/examples/csma-broadcast.cc
@@ -0,0 +1,204 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+//
+// Example of the sending of a datagram to a broadcast address
+//
+// Network topology
+// ==============
+// | |
+// n0 n1 n2
+// | |
+// ==========
+//
+// n0 originates UDP broadcast to 255.255.255.255/discard port, which
+// is replicated and received on both n1 and n2
+
+#include
+#include
+#include
+#include
+
+#include "ns3/command-line.h"
+#include "ns3/default-value.h"
+#include "ns3/ptr.h"
+#include "ns3/random-variable.h"
+#include "ns3/log.h"
+
+#include "ns3/simulator.h"
+#include "ns3/nstime.h"
+#include "ns3/data-rate.h"
+
+#include "ns3/ascii-trace.h"
+#include "ns3/pcap-trace.h"
+#include "ns3/internet-node.h"
+#include "ns3/csma-channel.h"
+#include "ns3/csma-net-device.h"
+#include "ns3/csma-topology.h"
+#include "ns3/csma-ipv4-topology.h"
+#include "ns3/mac48-address.h"
+#include "ns3/ipv4-address.h"
+#include "ns3/inet-socket-address.h"
+#include "ns3/ipv4.h"
+#include "ns3/socket.h"
+#include "ns3/ipv4-route.h"
+#include "ns3/onoff-application.h"
+#include "ns3/packet-sink.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("CsmaBroadcastExample");
+
+int
+main (int argc, char *argv[])
+{
+ // Users may find it convenient to turn on explicit debugging
+ // for selected modules; the below lines suggest how to do this
+#if 0
+ LogComponentEnable ("CsmaBroadcastExample", LOG_LEVEL_INFO);
+
+ LogComponentEnable("Object", LOG_LEVEL_ALL);
+ LogComponentEnable("Queue", LOG_LEVEL_ALL);
+ LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL);
+ LogComponentEnable("Channel", LOG_LEVEL_ALL);
+ LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL);
+ LogComponentEnable("NetDevice", LOG_LEVEL_ALL);
+ LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable("PacketSocket", LOG_LEVEL_ALL);
+ LogComponentEnable("Socket", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpSocket", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL);
+ LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL);
+ LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL);
+ // Enable the below logging command to see the packets being received
+ LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
+#endif
+
+ // Set up some default values for the simulation. Use the Bind()
+ // technique to tell the system what subclass of Queue to use,
+ // and what the queue limit is
+
+ // The below Bind command tells the queue factory which class to
+ // instantiate, when the queue factory is invoked in the topology code
+ DefaultValue::Bind ("Queue", "DropTailQueue");
+
+ // Allow the user to override any of the defaults and the above
+ // Bind()s at run-time, via command-line arguments
+ CommandLine::Parse (argc, argv);
+
+ // Here, we will explicitly create four nodes. In more sophisticated
+ // topologies, we could configure a node factory.
+ NS_LOG_INFO ("Create nodes.");
+ Ptr n0 = Create ();
+ Ptr n1 = Create ();
+ Ptr n2 = Create ();
+
+ // We create the channels first without any IP addressing information
+ NS_LOG_INFO ("Create channels.");
+ Ptr channel0 =
+ CsmaTopology::CreateCsmaChannel(
+ DataRate(5000000), MilliSeconds(2));
+
+ // We create the channels first without any IP addressing information
+ Ptr channel1 =
+ CsmaTopology::CreateCsmaChannel(
+ DataRate(5000000), MilliSeconds(2));
+
+ NS_LOG_INFO ("Build Topology.");
+ uint32_t n0ifIndex0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n0, channel0,
+ Mac48Address("10:54:23:54:0:50"));
+ uint32_t n0ifIndex1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n0, channel1,
+ Mac48Address("10:54:23:54:0:51"));
+ uint32_t n1ifIndex = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n1, channel0,
+ Mac48Address("10:54:23:54:23:51"));
+ uint32_t n2ifIndex = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, channel1,
+ Mac48Address("10:54:23:54:23:52"));
+
+ // Later, we add IP addresses.
+ NS_LOG_INFO ("Assign IP Addresses.");
+ CsmaIpv4Topology::AddIpv4Address (
+ n0, n0ifIndex0, Ipv4Address("10.1.0.1"), Ipv4Mask("255.255.0.0"));
+
+ CsmaIpv4Topology::AddIpv4Address (
+ n1, n1ifIndex, Ipv4Address("10.1.0.2"), Ipv4Mask("255.255.0.0"));
+
+ CsmaIpv4Topology::AddIpv4Address (
+ n0, n0ifIndex1, Ipv4Address("192.168.1.1"), Ipv4Mask("255.255.255.0"));
+
+ CsmaIpv4Topology::AddIpv4Address (
+ n2, n2ifIndex, Ipv4Address("192.168.1.2"), Ipv4Mask("255.255.255.0"));
+
+ // RFC 863 discard port ("9") indicates packet should be thrown away
+ // by the system. We allow this silent discard to be overridden
+ // by the PacketSink application.
+ uint16_t port = 9;
+
+ // Create the OnOff application to send UDP datagrams of size
+ // 512 bytes (default) at a rate of 500 Kb/s (default) from n0
+ NS_LOG_INFO ("Create Applications.");
+ Ptr ooff = Create (
+ n0,
+ InetSocketAddress ("255.255.255.255", port),
+ "Udp",
+ ConstantVariable(1),
+ ConstantVariable(0));
+ // Start the application
+ ooff->Start(Seconds(1.0));
+ ooff->Stop (Seconds(10.0));
+
+ // Create an optional packet sink to receive these packets
+ Ptr sink = Create (
+ n1,
+ InetSocketAddress (Ipv4Address::GetAny (), port),
+ "Udp");
+ // Start the sink
+ sink->Start (Seconds (1.0));
+ sink->Stop (Seconds (10.0));
+
+ // Create an optional packet sink to receive these packets
+ sink = Create (
+ n2,
+ InetSocketAddress (Ipv4Address::GetAny (), port),
+ "Udp");
+ // Start the sink
+ sink->Start (Seconds (1.0));
+ sink->Stop (Seconds (10.0));
+
+ NS_LOG_INFO ("Configure Tracing.");
+ // Configure tracing of all enqueue, dequeue, and NetDevice receive events
+ // Trace output will be sent to the csma-broadcast.tr file
+ AsciiTrace asciitrace ("csma-broadcast.tr");
+ asciitrace.TraceAllNetDeviceRx ();
+ asciitrace.TraceAllQueues ();
+
+ // Also configure some tcpdump traces; each interface will be traced
+ // The output files will be named
+ // simple-point-to-point.pcap--
+ // and can be read by the "tcpdump -r" command (use "-tt" option to
+ // display timestamps correctly)
+ PcapTrace pcaptrace ("csma-broadcast.pcap");
+ pcaptrace.TraceAllIp ();
+
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+}
diff --git a/examples/csma-multicast.cc b/examples/csma-multicast.cc
new file mode 100644
index 000000000..942485f50
--- /dev/null
+++ b/examples/csma-multicast.cc
@@ -0,0 +1,333 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+// Network topology
+//
+// Lan1
+// ===========
+// | | |
+// n0 n1 n2 n3 n4
+// | | |
+// ===========
+// Lan0
+//
+// - Multicast source is at node n0;
+// - Multicast forwarded by node n2 onto LAN1;
+// - Nodes n0, n1, n2, n3, and n4 receive the multicast frame.
+// - Node n4 listens for the data (actual listener not yet implementted)
+
+#include "ns3/command-line.h"
+#include "ns3/default-value.h"
+#include "ns3/ptr.h"
+#include "ns3/random-variable.h"
+#include "ns3/log.h"
+#include "ns3/simulator.h"
+#include "ns3/nstime.h"
+#include "ns3/data-rate.h"
+#include "ns3/ascii-trace.h"
+#include "ns3/pcap-trace.h"
+#include "ns3/internet-node.h"
+#include "ns3/csma-channel.h"
+#include "ns3/csma-net-device.h"
+#include "ns3/csma-topology.h"
+#include "ns3/csma-ipv4-topology.h"
+#include "ns3/mac48-address.h"
+#include "ns3/ipv4-address.h"
+#include "ns3/inet-socket-address.h"
+#include "ns3/ipv4.h"
+#include "ns3/socket.h"
+#include "ns3/ipv4-route.h"
+#include "ns3/onoff-application.h"
+#include "ns3/packet-sink.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("CsmaMulticastExample");
+
+int
+main (int argc, char *argv[])
+{
+//
+// Users may find it convenient to turn on explicit debugging
+// for selected modules; the below lines suggest how to do this
+//
+#if 0
+ LogComponentEnable ("CsmaMulticastExample", LOG_LEVEL_INFO);
+
+ LogComponentEnable("Object", LOG_LEVEL_ALL);
+ LogComponentEnable("Queue", LOG_LEVEL_ALL);
+ LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL);
+ LogComponentEnable("Channel", LOG_LEVEL_ALL);
+ LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL);
+ LogComponentEnable("NetDevice", LOG_LEVEL_ALL);
+ LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable("PacketSocket", LOG_LEVEL_ALL);
+ LogComponentEnable("Socket", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpSocket", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL);
+ LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL);
+ LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL);
+ LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
+ LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
+#endif
+//
+// Set up default values for the simulation. Use the DefaultValue::Bind()
+// technique to tell the system what subclass of Queue to use. The Bind
+// command command tells the queue factory which class to instantiate when the
+// queue factory is invoked in the topology code
+//
+ DefaultValue::Bind ("Queue", "DropTailQueue");
+//
+// Allow the user to override any of the defaults and the above Bind() at
+// run-time, via command-line arguments
+//
+ CommandLine::Parse (argc, argv);
+//
+// Explicitly create the nodes required by the topology (shown above).
+//
+ NS_LOG_INFO ("Create nodes.");
+ Ptr n0 = Create ();
+ Ptr n1 = Create ();
+ Ptr n2 = Create ();
+ Ptr n3 = Create ();
+ Ptr n4 = Create ();
+
+ NS_LOG_INFO ("Create channels.");
+//
+// Explicitly create the channels required by the topology (shown above).
+//
+ Ptr lan0 =
+ CsmaTopology::CreateCsmaChannel(DataRate(5000000), MilliSeconds(2));
+
+ Ptr lan1 =
+ CsmaTopology::CreateCsmaChannel(DataRate(5000000), MilliSeconds(2));
+
+ NS_LOG_INFO ("Build Topology.");
+//
+// Now fill out the topology by creating the net devices required to connect
+// the nodes to the channels and hooking them up. AddIpv4CsmaNetDevice will
+// create a net device, add a MAC address (in memory of the pink flamingo) and
+// connect the net device to a nodes and also to a channel. the
+// AddIpv4CsmaNetDevice method returns a net device index for the net device
+// created on the node. Interpret nd0 as the net device we created for node
+// zero. Interpret nd2Lan0 as the net device we created for node two to
+// connect to Lan0.
+//
+ uint32_t nd0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n0, lan0,
+ Mac48Address("08:00:2e:00:00:00"));
+ uint32_t nd1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n1, lan0,
+ Mac48Address("08:00:2e:00:00:01"));
+ uint32_t nd2Lan0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, lan0,
+ Mac48Address("08:00:2e:00:00:02"));
+
+ uint32_t nd2Lan1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, lan1,
+ Mac48Address("08:00:2e:00:00:03"));
+ uint32_t nd3 __attribute__ ((unused)) =
+ CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, lan1,
+ Mac48Address("08:00:2e:00:00:04"));
+ uint32_t nd4 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n4, lan1,
+ Mac48Address("08:00:2e:00:00:05"));
+
+ NS_LOG_INFO ("nd0 = " << nd0);
+ NS_LOG_INFO ("nd1 = " << nd1);
+ NS_LOG_INFO ("nd2Lan0 = " << nd2Lan0);
+ NS_LOG_INFO ("nd2Lan1 = " << nd2Lan1);
+ NS_LOG_INFO ("nd3 = " << nd3);
+ NS_LOG_INFO ("nd4 = " << nd3);
+//
+// We've got the "hardware" in place. Now we need to add IP addresses.
+//
+ NS_LOG_INFO ("Assign IP Addresses.");
+ CsmaIpv4Topology::AddIpv4Address (n0, nd0, Ipv4Address ("10.1.1.1"),
+ Ipv4Mask ("255.255.255.0"));
+
+ CsmaIpv4Topology::AddIpv4Address (n1, nd1, Ipv4Address ("10.1.1.2"),
+ Ipv4Mask ("255.255.255.0"));
+
+//
+// We'll need these addresses later
+//
+ Ipv4Address n2Lan0Addr ("10.1.1.3");
+ Ipv4Address n2Lan1Addr ("10.1.2.1");
+
+ CsmaIpv4Topology::AddIpv4Address (n2, nd2Lan0, n2Lan0Addr,
+ Ipv4Mask ("255.255.255.0"));
+//
+// Assign IP addresses to the net devices and associated interfaces on Lan1
+//
+ CsmaIpv4Topology::AddIpv4Address (n2, nd2Lan1, n2Lan1Addr,
+ Ipv4Mask ("255.255.255.0"));
+
+ CsmaIpv4Topology::AddIpv4Address (n3, nd1, Ipv4Address ("10.1.2.2"),
+ Ipv4Mask ("255.255.255.0"));
+
+ CsmaIpv4Topology::AddIpv4Address (n4, nd4, Ipv4Address ("10.1.2.3"),
+ Ipv4Mask ("255.255.255.0"));
+
+ NS_LOG_INFO ("Configure multicasting.");
+//
+// Now we can configure multicasting. As described above, the multicast
+// source is at node zero, which we assigned the IP address of 10.1.1.1
+// earlier. We need to define a multicast group to send packets to. This
+// can be any multicast address from 224.0.0.0 through 239.255.255.255
+// (avoiding the reserved routing protocol addresses). We just pick a
+// convenient number (225.0.0.0) and or in some bits to let us verify that
+// correct Ethernet multicast addresses are constructed down in the system.
+//
+ Ipv4Address multicastSource ("10.1.1.1");
+ Ipv4Address multicastGroup ("225.1.2.4");
+//
+// We are going to manually configure multicast routing. This means telling
+// node two that it should expect multicast data coming from IP address
+// 10.1.1.1 originally. It should expect these data coming in over its IP
+// interface connected to Lan0. When node two receives these packets, they
+// should be forwarded out the interface that connects it to Lan1.
+//
+// We're going to need the interface indices on node two corresponding to
+// these interfaces, which we call ifIndexLan0 and ifIndexLan1. The most
+// general way to get these interfaces is to look them up by IP address.
+// Looking back to the topology creation calls above, we saved the addresses
+// assigned to the interface connecting node two to Lan0 and Lan1. Now is
+// a fine time to find the interface indices on node two.
+//
+ Ptr ipv4;
+ ipv4 = n2->QueryInterface (Ipv4::iid);
+
+ uint32_t ifIndexLan0 = ipv4->FindInterfaceForAddr (n2Lan0Addr);
+ uint32_t ifIndexLan1 = ipv4->FindInterfaceForAddr (n2Lan1Addr);
+//
+// Now, we need to do is to call the AddMulticastRoute () method on node
+// two's Ipv4 interface and tell it that whenever it receives a packet on
+// the interface from Lan0, with the packet from the multicast source,
+// destined for the multicast group, it should forward these packets down
+// the interface connecting it to Lan1. (Note: the vector of output
+// interfaces is in case there are multiple net devices on a node -- not
+// true in this case).
+//
+ std::vector outputInterfaces (1);
+ outputInterfaces[0] = ifIndexLan1;
+
+ ipv4->AddMulticastRoute (multicastSource, multicastGroup, ifIndexLan0,
+ outputInterfaces);
+//
+// We need to specify how the source node handles multicasting. There are a
+// number of ways we can deal with this, we just need to pick one. The first
+// method is to add an explicit route out of the source node, just as we did
+// for the forwarding node. Use this method when you want to send packets out
+// multiple interfaces or send packets out different interfaces based on the
+// differing multicast groups. Since the source is local, there will be no
+// input interface over which packets are received, so use
+// Ipv4RoutingProtocol::IF_INDEX_ANY as a wildcard.
+//
+// A second way is to specify a multicast route using wildcards. If you
+// want to send multicasts out differing sets of interfaces based on the
+// multicast group, you can use AddMulticastRoute () but specify the origin
+// as a wildcard. If you want all multicasts to go out a single set of
+// interfaces, you can make both the origin and group a wildcard.
+//
+// If you have a simple system, where the source has a single interface, this
+// can be done via the SetDefaultMulticastRoute () method on the Ipv4
+// interface. This tells the system to send all multicasts out a single
+// specified network interface index.
+//
+// A last way is to specify a (or use an existing) default unicast route. The
+// multicast routing code uses the unicast default route as a multicast "route
+// of last resort." this method for is also on Ipv4 and is called
+// SetDefaultRoute ().
+//
+// Since this is a simple multicast example, we use the
+// SetDefaultMulticastRoute () approach. We are going to first need the
+// Ipv4 interface for node 0 which is the multicast source. We use this
+// interface to find the output interface index, and tell node zero to send
+// its multicast traffic out that interface.
+//
+ ipv4 = n0->QueryInterface (Ipv4::iid);
+ uint32_t ifIndexSrc = ipv4->FindInterfaceForAddr (multicastSource);
+ ipv4->SetDefaultMulticastRoute (ifIndexSrc);
+//
+// As described above, node four will be the only node listening for the
+// multicast data. To enable forwarding bits up the protocol stack, we need
+// to tell the stack to join the multicast group.
+//
+ ipv4 = n4->QueryInterface (Ipv4::iid);
+ ipv4->JoinMulticastGroup (multicastSource, multicastGroup);
+//
+// Create an OnOff application to send UDP datagrams from node zero to the
+// multicast group (node four will be listening).
+//
+ NS_LOG_INFO ("Create Applications.");
+
+ uint16_t port = 9; // Discard port (RFC 863)
+
+ // Configure a multicast packet generator that generates a packet
+ // every few seconds
+ Ptr ooff = Create (
+ n0,
+ InetSocketAddress (multicastGroup, port),
+ "Udp",
+ ConstantVariable(1),
+ ConstantVariable(0),
+ DataRate ("255b/s"),
+ 128);
+//
+// Tell the application when to start and stop.
+//
+ ooff->Start(Seconds(1.));
+ ooff->Stop (Seconds(10.));
+
+ // Create an optional packet sink to receive these packets
+ // If you enable logging on this (above) it will print a log statement
+ // for every packet received
+ Ptr sink = Create (
+ n4,
+ InetSocketAddress (Ipv4Address::GetAny (), port),
+ "Udp");
+ // Start the sink
+ sink->Start (Seconds (1.0));
+ sink->Stop (Seconds (10.0));
+
+//
+// Configure tracing of all enqueue, dequeue, and NetDevice receive events.
+// Trace output will be sent to the file "csma-multicast.tr"
+//
+ NS_LOG_INFO ("Configure Tracing.");
+ AsciiTrace asciitrace ("csma-multicast.tr");
+ asciitrace.TraceAllNetDeviceRx ();
+ asciitrace.TraceAllQueues ();
+//
+// Also configure some tcpdump traces; each interface will be traced.
+// The output files will be named:
+// csma-multicast.pcap--
+// and can be read by the "tcpdump -r" command (use "-tt" option to
+// display timestamps correctly)
+//
+ PcapTrace pcaptrace ("csma-multicast.pcap");
+ pcaptrace.TraceAllIp ();
+//
+// Now, do the actual simulation.
+//
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+}
diff --git a/examples/csma-one-subnet.cc b/examples/csma-one-subnet.cc
index dc1bd58c0..76918cbb7 100644
--- a/examples/csma-one-subnet.cc
+++ b/examples/csma-one-subnet.cc
@@ -14,35 +14,25 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-// Port of ns-2/tcl/ex/simple.tcl to ns-3
-//
// Network topology
//
// n0 n1 n2 n3
// | | | |
-// =====================
+// =================
+// LAN
//
-// - CBR/UDP flows from n0 to n1, and from n3 to n0
-// - UDP packet size of 210 bytes, with per-packet interval 0.00375 sec.
-// (i.e., DataRate of 448,000 bps)
+// - CBR/UDP flows from n0 to n1 and from n3 to n0
// - DropTail queues
// - Tracing of queues and packet receptions to file "csma-one-subnet.tr"
-#include
-#include
-#include
-#include
-
#include "ns3/command-line.h"
#include "ns3/default-value.h"
#include "ns3/ptr.h"
#include "ns3/random-variable.h"
-#include "ns3/debug.h"
-
+#include "ns3/log.h"
#include "ns3/simulator.h"
#include "ns3/nstime.h"
#include "ns3/data-rate.h"
-
#include "ns3/ascii-trace.h"
#include "ns3/pcap-trace.h"
#include "ns3/internet-node.h"
@@ -50,7 +40,7 @@
#include "ns3/csma-net-device.h"
#include "ns3/csma-topology.h"
#include "ns3/csma-ipv4-topology.h"
-#include "ns3/eui48-address.h"
+#include "ns3/mac48-address.h"
#include "ns3/ipv4-address.h"
#include "ns3/inet-socket-address.h"
#include "ns3/ipv4.h"
@@ -58,109 +48,168 @@
#include "ns3/ipv4-route.h"
#include "ns3/onoff-application.h"
-
using namespace ns3;
+NS_LOG_COMPONENT_DEFINE ("CsmaOneSubnetExample");
-int main (int argc, char *argv[])
+int
+main (int argc, char *argv[])
{
-
- // Users may find it convenient to turn on explicit debugging
- // for selected modules; the below lines suggest how to do this
+//
+// Users may find it convenient to turn on explicit debugging
+// for selected modules; the below lines suggest how to do this
+//
#if 0
- DebugComponentEnable("CsmaNetDevice");
- DebugComponentEnable("Ipv4L3Protocol");
- DebugComponentEnable("NetDevice");
- DebugComponentEnable("Channel");
- DebugComponentEnable("CsmaChannel");
- DebugComponentEnable("PacketSocket");
+ LogComponentEnable ("CsmaOneSubnetExample", LOG_LEVEL_INFO);
+
+ LogComponentEnable("Object", LOG_LEVEL_ALL);
+ LogComponentEnable("Queue", LOG_LEVEL_ALL);
+ LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL);
+ LogComponentEnable("Channel", LOG_LEVEL_ALL);
+ LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL);
+ LogComponentEnable("NetDevice", LOG_LEVEL_ALL);
+ LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable("PacketSocket", LOG_LEVEL_ALL);
+ LogComponentEnable("Socket", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpSocket", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL);
+ LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL);
+ LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL);
+ LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
#endif
-
- // Set up some default values for the simulation. Use the Bind()
- // technique to tell the system what subclass of Queue to use,
- // and what the queue limit is
-
- // The below Bind command tells the queue factory which class to
- // instantiate, when the queue factory is invoked in the topology code
+//
+// Set up default values for the simulation. Use the DefaultValue::Bind()
+// technique to tell the system what subclass of Queue to use. The Bind
+// command command tells the queue factory which class to instantiate when the
+// queue factory is invoked in the topology code
+//
DefaultValue::Bind ("Queue", "DropTailQueue");
-
- // Allow the user to override any of the defaults and the above
- // Bind()s at run-time, via command-line arguments
+//
+// Allow the user to override any of the defaults and the above Bind() at
+// run-time, via command-line arguments
+//
CommandLine::Parse (argc, argv);
-
- // Here, we will explicitly create four nodes. In more sophisticated
- // topologies, we could configure a node factory.
+//
+// Explicitly create the nodes required by the topology (shown above).
+//
+ NS_LOG_INFO ("Create nodes.");
Ptr n0 = Create ();
Ptr n1 = Create ();
Ptr n2 = Create ();
Ptr n3 = Create ();
- // We create the channels first without any IP addressing information
- Ptr channel0 =
- CsmaTopology::CreateCsmaChannel(
- DataRate(5000000), MilliSeconds(2));
+ NS_LOG_INFO ("Create channels.");
+//
+// Explicitly create the channels required by the topology (shown above).
+//
+ Ptr lan = CsmaTopology::CreateCsmaChannel(
+ DataRate(5000000), MilliSeconds(2));
- uint32_t n0ifIndex = CsmaIpv4Topology::AddIpv4CsmaNode (n0, channel0,
- Eui48Address("10:54:23:54:23:50"));
- uint32_t n1ifIndex = CsmaIpv4Topology::AddIpv4CsmaNode (n1, channel0,
- Eui48Address("10:54:23:54:23:51"));
- uint32_t n2ifIndex = CsmaIpv4Topology::AddIpv4CsmaNode (n2, channel0,
- Eui48Address("10:54:23:54:23:52"));
- uint32_t n3ifIndex = CsmaIpv4Topology::AddIpv4CsmaNode (n3, channel0,
- Eui48Address("10:54:23:54:23:53"));
+ NS_LOG_INFO ("Build Topology.");
+//
+// Now fill out the topology by creating the net devices required to connect
+// the nodes to the channels and hooking them up. AddIpv4CsmaNetDevice will
+// create a net device, add a MAC address (in memory of the pink flamingo) and
+// connect the net device to a nodes and also to a channel. the
+// AddIpv4CsmaNetDevice method returns a net device index for the net device
+// created on the node. Interpret nd0 as the net device we created for node
+// zero.
+//
+ uint32_t nd0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n0, lan,
+ Mac48Address("08:00:2e:00:00:00"));
- // Later, we add IP addresses.
- CsmaIpv4Topology::AddIpv4Address (
- n0, n0ifIndex, Ipv4Address("10.1.1.1"), Ipv4Mask("255.255.255.0"));
+ uint32_t nd1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n1, lan,
+ Mac48Address("08:00:2e:00:00:01"));
- CsmaIpv4Topology::AddIpv4Address (
- n1, n1ifIndex, Ipv4Address("10.1.1.2"), Ipv4Mask("255.255.255.0"));
+ uint32_t nd2 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, lan,
+ Mac48Address("08:00:2e:00:00:02"));
- CsmaIpv4Topology::AddIpv4Address (
- n2, n2ifIndex, Ipv4Address("10.1.1.3"), Ipv4Mask("255.255.255.0"));
+ uint32_t nd3 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, lan,
+ Mac48Address("08:00:2e:00:00:03"));
+//
+// We've got the "hardware" in place. Now we need to add IP addresses.
+//
+ NS_LOG_INFO ("Assign IP Addresses.");
+//
+// XXX BUGBUG
+// Need a better way to get the interface index. The point-to-point topology
+// as implemented can't return the index since it creates interfaces on both
+// sides (i.e., it does AddIpv4Addresses, not AddIpv4Address). We need a
+// method on Ipv4 to find the interface index corresponding to a given ipv4
+// address.
+//
+// Assign IP addresses to the net devices and associated interfaces
+// on the lan. The AddIpv4Address method returns an Ipv4 interface index
+// which we do not need here.
+//
+ CsmaIpv4Topology::AddIpv4Address (n0, nd0, Ipv4Address("10.1.1.1"),
+ Ipv4Mask("255.255.255.0"));
+
+ CsmaIpv4Topology::AddIpv4Address (n1, nd1, Ipv4Address("10.1.1.2"),
+ Ipv4Mask("255.255.255.0"));
+
+ CsmaIpv4Topology::AddIpv4Address (n2, nd2, Ipv4Address("10.1.1.3"),
+ Ipv4Mask("255.255.255.0"));
- CsmaIpv4Topology::AddIpv4Address (
- n3, n3ifIndex, Ipv4Address("10.1.1.4"), Ipv4Mask("255.255.255.0"));
-
- // Create the OnOff application to send UDP datagrams of size
- // 210 bytes at a rate of 448 Kb/s
- // from n0 to n1
+ CsmaIpv4Topology::AddIpv4Address (n3, nd3, Ipv4Address("10.1.1.4"),
+ Ipv4Mask("255.255.255.0"));
+//
+// Create an OnOff application to send UDP datagrams from node zero to node 1.
+//
+ NS_LOG_INFO ("Create Applications.");
+ uint16_t port = 9; // Discard port (RFC 863)
Ptr ooff = Create (
n0,
- InetSocketAddress ("10.1.1.2", 80),
+ InetSocketAddress ("10.1.1.2", port),
"Udp",
ConstantVariable(1),
ConstantVariable(0));
- // Start the application
+//
+// Tell the application when to start and stop.
+//
ooff->Start(Seconds(1.0));
ooff->Stop (Seconds(10.0));
-
- // Create a similar flow from n3 to n0, starting at time 1.1 seconds
+//
+// Create a similar flow from n3 to n0, starting at time 1.1 seconds
+//
ooff = Create (
n3,
- InetSocketAddress ("10.1.1.1", 80),
+ InetSocketAddress ("10.1.1.1", port),
"Udp",
ConstantVariable(1),
ConstantVariable(0));
- // Start the application
+
ooff->Start(Seconds(1.1));
ooff->Stop (Seconds(10.0));
-
- // Configure tracing of all enqueue, dequeue, and NetDevice receive events
- // Trace output will be sent to the csma-one-subnet.tr file
+//
+// Configure tracing of all enqueue, dequeue, and NetDevice receive events.
+// Trace output will be sent to the file "csma-one-subnet.tr"
+//
+ NS_LOG_INFO ("Configure Tracing.");
AsciiTrace asciitrace ("csma-one-subnet.tr");
asciitrace.TraceAllNetDeviceRx ();
asciitrace.TraceAllQueues ();
-
- // Also configure some tcpdump traces; each interface will be traced
- // The output files will be named
- // simple-point-to-point.pcap--
- // and can be read by the "tcpdump -r" command (use "-tt" option to
- // display timestamps correctly)
+//
+// Also configure some tcpdump traces; each interface will be traced.
+// The output files will be named:
+// csma-one-subnet.pcap--
+// and can be read by the "tcpdump -r" command (use "-tt" option to
+// display timestamps correctly)
+//
PcapTrace pcaptrace ("csma-one-subnet.pcap");
pcaptrace.TraceAllIp ();
-
+//
+// Now, do the actual simulation.
+//
+ NS_LOG_INFO ("Run Simulation.");
Simulator::Run ();
-
Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
}
diff --git a/examples/csma-packet-socket.cc b/examples/csma-packet-socket.cc
index 9db207fbe..fde9a8f0b 100644
--- a/examples/csma-packet-socket.cc
+++ b/examples/csma-packet-socket.cc
@@ -37,7 +37,7 @@
#include "ns3/default-value.h"
#include "ns3/ptr.h"
#include "ns3/random-variable.h"
-#include "ns3/debug.h"
+#include "ns3/log.h"
#include "ns3/simulator.h"
#include "ns3/nstime.h"
@@ -48,7 +48,7 @@
#include "ns3/internet-node.h"
#include "ns3/csma-channel.h"
#include "ns3/csma-net-device.h"
-#include "ns3/eui48-address.h"
+#include "ns3/mac48-address.h"
#include "ns3/packet-socket-address.h"
#include "ns3/socket.h"
#include "ns3/onoff-application.h"
@@ -56,6 +56,8 @@
using namespace ns3;
+NS_LOG_COMPONENT_DEFINE ("CsmaPacketSocketExample");
+
static Ptr
CreateCsmaDevice (Ptr node, Ptr channel)
{
@@ -66,28 +68,56 @@ CreateCsmaDevice (Ptr node, Ptr channel)
return device;
}
-
-int main (int argc, char *argv[])
+int
+main (int argc, char *argv[])
{
+#if 0
+ LogComponentEnable ("CsmaPacketSocketExample", LOG_LEVEL_INFO);
+
+ LogComponentEnable("Object", LOG_LEVEL_ALL);
+ LogComponentEnable("Queue", LOG_LEVEL_ALL);
+ LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL);
+ LogComponentEnable("Channel", LOG_LEVEL_ALL);
+ LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL);
+ LogComponentEnable("NetDevice", LOG_LEVEL_ALL);
+ LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable("PacketSocket", LOG_LEVEL_ALL);
+ LogComponentEnable("Socket", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpSocket", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL);
+ LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL);
+ LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL);
+ LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
+#endif
+
CommandLine::Parse (argc, argv);
// Here, we will explicitly create four nodes. In more sophisticated
// topologies, we could configure a node factory.
+ NS_LOG_INFO ("Create nodes.");
Ptr n0 = Create ();
Ptr n1 = Create ();
Ptr n2 = Create ();
Ptr n3 = Create ();
// create the shared medium used by all csma devices.
+ NS_LOG_INFO ("Create channels.");
Ptr channel = Create (DataRate(5000000), MilliSeconds(2));
// use a helper function to connect our nodes to the shared channel.
+ NS_LOG_INFO ("Build Topology.");
Ptr n0If = CreateCsmaDevice (n0, channel);
Ptr n1If = CreateCsmaDevice (n1, channel);
Ptr n2If = CreateCsmaDevice (n2, channel);
Ptr n3If = CreateCsmaDevice (n3, channel);
-
// create the address which identifies n1 from n0
PacketSocketAddress n0ToN1;
n0ToN1.SetSingleDevice (n0If->GetIfIndex ()); // set outgoing interface for outgoing packets
@@ -103,6 +133,7 @@ int main (int argc, char *argv[])
// Create the OnOff application to send raw datagrams of size
// 210 bytes at a rate of 448 Kb/s
// from n0 to n1
+ NS_LOG_INFO ("Create Applications.");
Ptr ooff = Create (
n0,
n0ToN1,
@@ -126,11 +157,13 @@ int main (int argc, char *argv[])
// Configure tracing of all enqueue, dequeue, and NetDevice receive events
// Trace output will be sent to the csma-packet-socket.tr file
+ NS_LOG_INFO ("Configure Tracing.");
AsciiTrace asciitrace ("csma-packet-socket.tr");
asciitrace.TraceAllNetDeviceRx ();
asciitrace.TraceAllQueues ();
+ NS_LOG_INFO ("Run Simulation.");
Simulator::Run ();
-
Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
}
diff --git a/examples/mixed-global-routing.cc b/examples/mixed-global-routing.cc
index b3017e029..e5eb8dd97 100644
--- a/examples/mixed-global-routing.cc
+++ b/examples/mixed-global-routing.cc
@@ -36,7 +36,7 @@
#include
#include
-#include "ns3/debug.h"
+#include "ns3/log.h"
#include "ns3/command-line.h"
#include "ns3/default-value.h"
@@ -56,7 +56,7 @@
#include "ns3/csma-net-device.h"
#include "ns3/csma-topology.h"
#include "ns3/csma-ipv4-topology.h"
-#include "ns3/eui48-address.h"
+#include "ns3/mac48-address.h"
#include "ns3/ipv4-address.h"
#include "ns3/ipv4.h"
#include "ns3/socket.h"
@@ -68,22 +68,39 @@
using namespace ns3;
-int main (int argc, char *argv[])
+NS_LOG_COMPONENT_DEFINE ("MixedGlobalRoutingExample");
+
+int
+main (int argc, char *argv[])
{
// Users may find it convenient to turn on explicit debugging
// for selected modules; the below lines suggest how to do this
#if 0
- DebugComponentEnable ("Object");
- DebugComponentEnable ("Queue");
- DebugComponentEnable ("DropTailQueue");
- DebugComponentEnable ("Channel");
- DebugComponentEnable ("PointToPointChannel");
- DebugComponentEnable ("PointToPointNetDevice");
- DebugComponentEnable ("GlobalRouter");
- DebugComponentEnable ("GlobalRouteManager");
-#endif
+ LogComponentEnable ("MixedGlobalRoutingExample", LOG_LEVEL_INFO);
+ LogComponentEnable("Object", LOG_LEVEL_ALL);
+ LogComponentEnable("Queue", LOG_LEVEL_ALL);
+ LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL);
+ LogComponentEnable("Channel", LOG_LEVEL_ALL);
+ LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL);
+ LogComponentEnable("NetDevice", LOG_LEVEL_ALL);
+ LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable("PacketSocket", LOG_LEVEL_ALL);
+ LogComponentEnable("Socket", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpSocket", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL);
+ LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL);
+ LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL);
+ LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
+#endif
// Set up some default values for the simulation. Use the Bind ()
// technique to tell the system what subclass of Queue to use,
// and what the queue limit is
@@ -102,6 +119,7 @@ int main (int argc, char *argv[])
// Bind ()s at run-time, via command-line arguments
CommandLine::Parse (argc, argv);
+ NS_LOG_INFO ("Create nodes.");
Ptr n0 = Create ();
Ptr n1 = Create ();
Ptr n2 = Create ();
@@ -111,6 +129,7 @@ int main (int argc, char *argv[])
Ptr n6 = Create ();
// We create the channels first without any IP addressing information
+ NS_LOG_INFO ("Create channels.");
Ptr channel0 =
PointToPointTopology::AddPointToPointLink (
n0, n2, DataRate (5000000), MilliSeconds (2));
@@ -128,16 +147,18 @@ int main (int argc, char *argv[])
CsmaTopology::CreateCsmaChannel(
DataRate(5000000), MilliSeconds(2));
- uint32_t n2ifIndex = CsmaIpv4Topology::AddIpv4CsmaNode (n2, channelc0,
- Eui48Address("10:54:23:54:23:50"));
- uint32_t n3ifIndex = CsmaIpv4Topology::AddIpv4CsmaNode (n3, channelc0,
- Eui48Address("10:54:23:54:23:51"));
- uint32_t n4ifIndex = CsmaIpv4Topology::AddIpv4CsmaNode (n4, channelc0,
- Eui48Address("10:54:23:54:23:52"));
- uint32_t n5ifIndex = CsmaIpv4Topology::AddIpv4CsmaNode (n5, channelc0,
- Eui48Address("10:54:23:54:23:53"));
+ NS_LOG_INFO ("Build Topology.");
+ uint32_t n2ifIndex = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, channelc0,
+ Mac48Address("10:54:23:54:23:50"));
+ uint32_t n3ifIndex = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, channelc0,
+ Mac48Address("10:54:23:54:23:51"));
+ uint32_t n4ifIndex = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n4, channelc0,
+ Mac48Address("10:54:23:54:23:52"));
+ uint32_t n5ifIndex = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n5, channelc0,
+ Mac48Address("10:54:23:54:23:53"));
// Later, we add IP addresses.
+ NS_LOG_INFO ("Assign IP Addresses.");
PointToPointTopology::AddIpv4Addresses (
channel0, n0, Ipv4Address ("10.1.1.1"),
n2, Ipv4Address ("10.1.1.2"));
@@ -168,9 +189,11 @@ int main (int argc, char *argv[])
// Create the OnOff application to send UDP datagrams of size
// 210 bytes at a rate of 448 Kb/s
+ NS_LOG_INFO ("Create Applications.");
+ uint16_t port = 9; // Discard port (RFC 863)
Ptr ooff = Create (
n0,
- InetSocketAddress ("10.1.3.2", 80),
+ InetSocketAddress ("10.1.3.2", port),
"Udp",
ConstantVariable (1),
ConstantVariable (0),
@@ -182,6 +205,7 @@ int main (int argc, char *argv[])
// Configure tracing of all enqueue, dequeue, and NetDevice receive events
// Trace output will be sent to the simple-global-routing.tr file
+ NS_LOG_INFO ("Configure Tracing.");
AsciiTrace asciitrace ("mixed-global-routing.tr");
asciitrace.TraceAllQueues ();
asciitrace.TraceAllNetDeviceRx ();
@@ -193,7 +217,8 @@ int main (int argc, char *argv[])
PcapTrace pcaptrace ("mixed-global-routing.pcap");
pcaptrace.TraceAllIp ();
+ NS_LOG_INFO ("Run Simulation.");
Simulator::Run ();
-
Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
}
diff --git a/examples/simple-global-routing.cc b/examples/simple-global-routing.cc
index 75879be23..362ca7af3 100644
--- a/examples/simple-global-routing.cc
+++ b/examples/simple-global-routing.cc
@@ -42,7 +42,7 @@
#include
#include
-#include "ns3/debug.h"
+#include "ns3/log.h"
#include "ns3/command-line.h"
#include "ns3/default-value.h"
@@ -65,29 +65,46 @@
#include "ns3/ipv4-route.h"
#include "ns3/point-to-point-topology.h"
#include "ns3/onoff-application.h"
+#include "ns3/packet-sink.h"
#include "ns3/global-route-manager.h"
using namespace ns3;
-int main (int argc, char *argv[])
-{
+NS_LOG_COMPONENT_DEFINE ("SimpleGlobalRoutingExample");
+int
+main (int argc, char *argv[])
+{
// Users may find it convenient to turn on explicit debugging
// for selected modules; the below lines suggest how to do this
#if 0
- DebugComponentEnable ("Object");
- DebugComponentEnable ("Queue");
- DebugComponentEnable ("DropTailQueue");
- DebugComponentEnable ("Channel");
- DebugComponentEnable ("PointToPointChannel");
- DebugComponentEnable ("PointToPointNetDevice");
- DebugComponentEnable ("GlobalRouter");
- DebugComponentEnable ("GlobalRouteMaager");
-#endif
+ LogComponentEnable ("SimpleGlobalRoutingExample", LOG_LEVEL_INFO);
- // Set up some default values for the simulation. Use the DefaultValue::Bind ()
- // technique to tell the system what subclass of Queue to use,
- // and what the queue limit is
+ LogComponentEnable("Object", LOG_LEVEL_ALL);
+ LogComponentEnable("Queue", LOG_LEVEL_ALL);
+ LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL);
+ LogComponentEnable("Channel", LOG_LEVEL_ALL);
+ LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL);
+ LogComponentEnable("NetDevice", LOG_LEVEL_ALL);
+ LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable("PacketSocket", LOG_LEVEL_ALL);
+ LogComponentEnable("Socket", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpSocket", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL);
+ LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL);
+ LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL);
+ LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
+#endif
+ // Set up some default values for the simulation. Use the
+ // DefaultValue::Bind () technique to tell the system what subclass of
+ // Queue to use, and what the queue limit is
// The below Bind command tells the queue factory which class to
// instantiate, when the queue factory is invoked in the topology code
@@ -104,12 +121,14 @@ int main (int argc, char *argv[])
// Here, we will explicitly create four nodes. In more sophisticated
// topologies, we could configure a node factory.
+ NS_LOG_INFO ("Create nodes.");
Ptr n0 = Create ();
Ptr n1 = Create ();
Ptr n2 = Create ();
Ptr n3 = Create ();
// We create the channels first without any IP addressing information
+ NS_LOG_INFO ("Create channels.");
Ptr channel0 =
PointToPointTopology::AddPointToPointLink (
n0, n2, DataRate (5000000), MilliSeconds (2));
@@ -123,6 +142,7 @@ int main (int argc, char *argv[])
n2, n3, DataRate (1500000), MilliSeconds (10));
// Later, we add IP addresses.
+ NS_LOG_INFO ("Assign IP Addresses.");
PointToPointTopology::AddIpv4Addresses (
channel0, n0, Ipv4Address ("10.1.1.1"),
n2, Ipv4Address ("10.1.1.2"));
@@ -141,9 +161,11 @@ int main (int argc, char *argv[])
// Create the OnOff application to send UDP datagrams of size
// 210 bytes at a rate of 448 Kb/s
+ NS_LOG_INFO ("Create Applications.");
+ uint16_t port = 9; // Discard port (RFC 863)
Ptr ooff = Create (
n0,
- InetSocketAddress ("10.1.3.2", 80),
+ InetSocketAddress ("10.1.3.2", port),
"Udp",
ConstantVariable (1),
ConstantVariable (0));
@@ -151,10 +173,20 @@ int main (int argc, char *argv[])
ooff->Start (Seconds (1.0));
ooff->Stop (Seconds (10.0));
+ // Create a packet sink to receive these packets
+ // The last argument "true" disables output from the Receive callback
+ Ptr sink = Create (
+ n3,
+ InetSocketAddress (Ipv4Address::GetAny (), port),
+ "Udp");
+ // Start the sink
+ sink->Start (Seconds (1.0));
+ sink->Stop (Seconds (10.0));
+
// Create a similar flow from n3 to n1, starting at time 1.1 seconds
ooff = Create (
n3,
- InetSocketAddress ("10.1.2.1", 80),
+ InetSocketAddress ("10.1.2.1", port),
"Udp",
ConstantVariable (1),
ConstantVariable (0));
@@ -162,8 +194,18 @@ int main (int argc, char *argv[])
ooff->Start (Seconds (1.1));
ooff->Stop (Seconds (10.0));
+ // Create a packet sink to receive these packets
+ sink = Create (
+ n1,
+ InetSocketAddress (Ipv4Address::GetAny (), port),
+ "Udp");
+ // Start the sink
+ sink->Start (Seconds (1.1));
+ sink->Stop (Seconds (10.0));
+
// Configure tracing of all enqueue, dequeue, and NetDevice receive events
// Trace output will be sent to the simple-global-routing.tr file
+ NS_LOG_INFO ("Configure Tracing.");
AsciiTrace asciitrace ("simple-global-routing.tr");
asciitrace.TraceAllQueues ();
asciitrace.TraceAllNetDeviceRx ();
@@ -175,9 +217,10 @@ int main (int argc, char *argv[])
PcapTrace pcaptrace ("simple-global-routing.pcap");
pcaptrace.TraceAllIp ();
+ NS_LOG_INFO ("Run Simulation.");
Simulator::Run ();
-
Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
return 0;
}
diff --git a/examples/simple-point-to-point.cc b/examples/simple-point-to-point.cc
index 4e7657cdb..5bbde9bca 100644
--- a/examples/simple-point-to-point.cc
+++ b/examples/simple-point-to-point.cc
@@ -38,11 +38,7 @@
// - Tracing of queues and packet receptions to file
// "simple-point-to-point.tr"
-#include
-#include
-#include
-#include
-
+#include "ns3/log.h"
#include "ns3/command-line.h"
#include "ns3/default-value.h"
#include "ns3/ptr.h"
@@ -64,22 +60,41 @@
#include "ns3/ipv4-route.h"
#include "ns3/point-to-point-topology.h"
#include "ns3/onoff-application.h"
+#include "ns3/packet-sink.h"
using namespace ns3;
-int main (int argc, char *argv[])
-{
+NS_LOG_COMPONENT_DEFINE ("SimplePointToPointExample");
+int
+main (int argc, char *argv[])
+{
// Users may find it convenient to turn on explicit debugging
// for selected modules; the below lines suggest how to do this
- // remember to add #include "ns3/debug.h" before enabling these
#if 0
- DebugComponentEnable("Object");
- DebugComponentEnable("Queue");
- DebugComponentEnable("DropTailQueue");
- DebugComponentEnable("Channel");
- DebugComponentEnable("PointToPointChannel");
- DebugComponentEnable("PointToPointNetDevice");
+ LogComponentEnable ("SimplePointToPointExample", LOG_LEVEL_INFO);
+
+ LogComponentEnable("Object", LOG_LEVEL_ALL);
+ LogComponentEnable("Queue", LOG_LEVEL_ALL);
+ LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL);
+ LogComponentEnable("Channel", LOG_LEVEL_ALL);
+ LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL);
+ LogComponentEnable("NetDevice", LOG_LEVEL_ALL);
+ LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable("PacketSocket", LOG_LEVEL_ALL);
+ LogComponentEnable("Socket", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpSocket", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL);
+ LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL);
+ LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL);
+ LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
#endif
// Set up some default values for the simulation. Use the Bind()
@@ -101,12 +116,14 @@ int main (int argc, char *argv[])
// Here, we will explicitly create four nodes. In more sophisticated
// topologies, we could configure a node factory.
+ NS_LOG_INFO ("Create nodes.");
Ptr n0 = Create ();
Ptr n1 = Create ();
Ptr n2 = Create ();
Ptr n3 = Create ();
// We create the channels first without any IP addressing information
+ NS_LOG_INFO ("Create channels.");
Ptr channel0 =
PointToPointTopology::AddPointToPointLink (
n0, n2, DataRate(5000000), MilliSeconds(2));
@@ -120,6 +137,7 @@ int main (int argc, char *argv[])
n2, n3, DataRate(1500000), MilliSeconds(10));
// Later, we add IP addresses.
+ NS_LOG_INFO ("Assign IP Addresses.");
PointToPointTopology::AddIpv4Addresses (
channel0, n0, Ipv4Address("10.1.1.1"),
n2, Ipv4Address("10.1.1.2"));
@@ -136,16 +154,18 @@ int main (int argc, char *argv[])
// NetDevice creation, IP Address assignment, and routing) are
// separated because there may be a need to postpone IP Address
// assignment (emulation) or modify to use dynamic routing
+ NS_LOG_INFO ("Add Static Routes.");
PointToPointTopology::AddIpv4Routes(n0, n2, channel0);
PointToPointTopology::AddIpv4Routes(n1, n2, channel1);
PointToPointTopology::AddIpv4Routes(n2, n3, channel2);
-
// Create the OnOff application to send UDP datagrams of size
// 210 bytes at a rate of 448 Kb/s
+ NS_LOG_INFO ("Create Applications.");
+ uint16_t port = 9; // Discard port (RFC 863)
Ptr ooff = Create (
n0,
- InetSocketAddress ("10.1.3.2", 80),
+ InetSocketAddress ("10.1.3.2", port),
"Udp",
ConstantVariable(1),
ConstantVariable(0));
@@ -153,10 +173,19 @@ int main (int argc, char *argv[])
ooff->Start(Seconds(1.0));
ooff->Stop (Seconds(10.0));
+ // Create an optional packet sink to receive these packets
+ Ptr sink = Create (
+ n3,
+ InetSocketAddress (Ipv4Address::GetAny (), port),
+ "Udp");
+ // Start the sink
+ sink->Start (Seconds (1.0));
+ sink->Stop (Seconds (10.0));
+
// Create a similar flow from n3 to n1, starting at time 1.1 seconds
ooff = Create (
n3,
- InetSocketAddress ("10.1.2.1", 80),
+ InetSocketAddress ("10.1.2.1", port),
"Udp",
ConstantVariable(1),
ConstantVariable(0));
@@ -164,8 +193,18 @@ int main (int argc, char *argv[])
ooff->Start(Seconds(1.1));
ooff->Stop (Seconds(10.0));
+ // Create a packet sink to receive these packets
+ sink = Create (
+ n1,
+ InetSocketAddress (Ipv4Address::GetAny (), port),
+ "Udp");
+ // Start the sink
+ sink->Start (Seconds (1.1));
+ sink->Stop (Seconds (10.0));
+
// Here, finish off packet routing configuration
// This will likely set by some global StaticRouting object in the future
+ NS_LOG_INFO ("Set Default Routes.");
Ptr ipv4;
ipv4 = n0->QueryInterface (Ipv4::iid);
ipv4->SetDefaultRoute (Ipv4Address ("10.1.1.2"), 1);
@@ -174,6 +213,7 @@ int main (int argc, char *argv[])
// Configure tracing of all enqueue, dequeue, and NetDevice receive events
// Trace output will be sent to the simple-point-to-point.tr file
+ NS_LOG_INFO ("Configure Tracing.");
AsciiTrace asciitrace ("simple-point-to-point.tr");
asciitrace.TraceAllQueues ();
asciitrace.TraceAllNetDeviceRx ();
@@ -186,7 +226,8 @@ int main (int argc, char *argv[])
PcapTrace pcaptrace ("simple-point-to-point.pcap");
pcaptrace.TraceAllIp ();
- Simulator::Run ();
-
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
}
diff --git a/examples/udp-echo.cc b/examples/udp-echo.cc
new file mode 100644
index 000000000..8eebef638
--- /dev/null
+++ b/examples/udp-echo.cc
@@ -0,0 +1,213 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+// Network topology
+//
+// n0 n1 n2 n3
+// | | | |
+// =================
+// LAN
+//
+// - UDP flows from n0 to n1 and back
+// - DropTail queues
+// - Tracing of queues and packet receptions to file "udp-echo.tr"
+
+#include "ns3/command-line.h"
+#include "ns3/default-value.h"
+#include "ns3/ptr.h"
+#include "ns3/log.h"
+#include "ns3/simulator.h"
+#include "ns3/nstime.h"
+#include "ns3/data-rate.h"
+#include "ns3/ascii-trace.h"
+#include "ns3/pcap-trace.h"
+#include "ns3/internet-node.h"
+#include "ns3/csma-channel.h"
+#include "ns3/csma-net-device.h"
+#include "ns3/csma-topology.h"
+#include "ns3/csma-ipv4-topology.h"
+#include "ns3/mac48-address.h"
+#include "ns3/ipv4-address.h"
+#include "ns3/inet-socket-address.h"
+#include "ns3/ipv4.h"
+#include "ns3/socket.h"
+#include "ns3/ipv4-route.h"
+#include "ns3/udp-echo-client.h"
+#include "ns3/udp-echo-server.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("UdpEchoExample");
+
+int
+main (int argc, char *argv[])
+{
+//
+// Users may find it convenient to turn on explicit debugging
+// for selected modules; the below lines suggest how to do this
+//
+#if 0
+ LogComponentEnable ("UdpEchoExample", LOG_LEVEL_INFO);
+
+ LogComponentEnable("Object", LOG_LEVEL_ALL);
+ LogComponentEnable("Queue", LOG_LEVEL_ALL);
+ LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL);
+ LogComponentEnable("Channel", LOG_LEVEL_ALL);
+ LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL);
+ LogComponentEnable("NetDevice", LOG_LEVEL_ALL);
+ LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable("PacketSocket", LOG_LEVEL_ALL);
+ LogComponentEnable("Socket", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpSocket", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL);
+ LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL);
+ LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL);
+ LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
+#endif
+//
+// Set up default values for the simulation. Use the DefaultValue::Bind()
+// technique to tell the system what subclass of Queue to use. The Bind
+// command command tells the queue factory which class to instantiate when the
+// queue factory is invoked in the topology code
+//
+ DefaultValue::Bind ("Queue", "DropTailQueue");
+//
+// Allow the user to override any of the defaults and the above Bind() at
+// run-time, via command-line arguments
+//
+ CommandLine::Parse (argc, argv);
+//
+// Explicitly create the nodes required by the topology (shown above).
+//
+ NS_LOG_INFO ("Create nodes.");
+ Ptr n0 = Create ();
+ Ptr n1 = Create ();
+ Ptr n2 = Create ();
+ Ptr n3 = Create ();
+
+ NS_LOG_INFO ("Create channels.");
+//
+// Explicitly create the channels required by the topology (shown above).
+//
+ Ptr lan = CsmaTopology::CreateCsmaChannel(
+ DataRate(5000000), MilliSeconds(2));
+
+ NS_LOG_INFO ("Build Topology.");
+//
+// Now fill out the topology by creating the net devices required to connect
+// the nodes to the channels and hooking them up. AddIpv4CsmaNetDevice will
+// create a net device, add a MAC address (in memory of the pink flamingo) and
+// connect the net device to a nodes and also to a channel. the
+// AddIpv4CsmaNetDevice method returns a net device index for the net device
+// created on the node. Interpret nd0 as the net device we created for node
+// zero.
+//
+ uint32_t nd0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n0, lan,
+ Mac48Address("08:00:2e:00:00:00"));
+
+ uint32_t nd1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n1, lan,
+ Mac48Address("08:00:2e:00:00:01"));
+
+ uint32_t nd2 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, lan,
+ Mac48Address("08:00:2e:00:00:02"));
+
+ uint32_t nd3 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, lan,
+ Mac48Address("08:00:2e:00:00:03"));
+//
+// We've got the "hardware" in place. Now we need to add IP addresses.
+//
+ NS_LOG_INFO ("Assign IP Addresses.");
+//
+// XXX BUGBUG
+// Need a better way to get the interface index. The point-to-point topology
+// as implemented can't return the index since it creates interfaces on both
+// sides (i.e., it does AddIpv4Addresses, not AddIpv4Address). We need a
+// method on Ipv4 to find the interface index corresponding to a given ipv4
+// address.
+//
+// Assign IP addresses to the net devices and associated interfaces
+// on the lan. The AddIpv4Address method returns an Ipv4 interface index
+// which we do not need here.
+//
+ CsmaIpv4Topology::AddIpv4Address (n0, nd0, Ipv4Address("10.1.1.1"),
+ Ipv4Mask("255.255.255.0"));
+
+ CsmaIpv4Topology::AddIpv4Address (n1, nd1, Ipv4Address("10.1.1.2"),
+ Ipv4Mask("255.255.255.0"));
+
+ CsmaIpv4Topology::AddIpv4Address (n2, nd2, Ipv4Address("10.1.1.3"),
+ Ipv4Mask("255.255.255.0"));
+
+ CsmaIpv4Topology::AddIpv4Address (n3, nd3, Ipv4Address("10.1.1.4"),
+ Ipv4Mask("255.255.255.0"));
+
+ NS_LOG_INFO ("Create Applications.");
+//
+// Create a UdpEchoServer application on node one.
+//
+ uint16_t port = 9; // well-known echo port number
+
+ Ptr server = Create (n1, port);
+//
+// Create a UdpEchoClient application to send UDP datagrams from node zero to
+// node one.
+//
+ uint32_t packetSize = 1024;
+ uint32_t maxPacketCount = 1;
+ Time interPacketInterval = Seconds (1.);
+
+ Ptr client = Create (n0, "10.1.1.2", port,
+ maxPacketCount, interPacketInterval, packetSize);
+//
+// Tell the applications when to start and stop.
+//
+ server->Start(Seconds(1.));
+ client->Start(Seconds(2.));
+
+ server->Stop (Seconds(10.));
+ client->Stop (Seconds(10.));
+//
+// Configure tracing of all enqueue, dequeue, and NetDevice receive events.
+// Trace output will be sent to the file "udp-echo.tr"
+//
+ NS_LOG_INFO ("Configure Tracing.");
+ AsciiTrace asciitrace ("udp-echo.tr");
+ asciitrace.TraceAllNetDeviceRx ();
+ asciitrace.TraceAllQueues ();
+//
+// Also configure some tcpdump traces; each interface will be traced.
+// The output files will be named:
+// udp-echo.pcap--
+// and can be read by the "tcpdump -r" command (use "-tt" option to
+// display timestamps correctly)
+//
+ PcapTrace pcaptrace ("udp-echo.pcap");
+ pcaptrace.TraceAllIp ();
+//
+// Now, do the actual simulation.
+//
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+}
diff --git a/examples/waf b/examples/waf
new file mode 100755
index 000000000..191b7dbb2
--- /dev/null
+++ b/examples/waf
@@ -0,0 +1 @@
+exec "`dirname "$0"`"/../waf "$@"
diff --git a/examples/wscript b/examples/wscript
index e5e771555..a1f16e29b 100644
--- a/examples/wscript
+++ b/examples/wscript
@@ -14,10 +14,22 @@ def build(bld):
['csma', 'internet-node'])
obj.source = 'csma-one-subnet.cc'
+ obj = bld.create_ns3_program('udp-echo',
+ ['csma', 'internet-node'])
+ obj.source = 'udp-echo.cc'
+
+ obj = bld.create_ns3_program('csma-broadcast',
+ ['csma', 'internet-node'])
+ obj.source = 'csma-broadcast.cc'
+
obj = bld.create_ns3_program('csma-packet-socket',
['csma', 'internet-node'])
obj.source = 'csma-packet-socket.cc'
+ obj = bld.create_ns3_program('csma-multicast',
+ ['csma', 'internet-node'])
+ obj.source = 'csma-multicast.cc'
+
obj = bld.create_ns3_program( 'mixed-global-routing',
['point-to-point', 'internet-node', 'global-routing' , 'csma-cd'])
obj.source = 'mixed-global-routing.cc'
diff --git a/samples/main-channel.cc b/samples/main-channel.cc
index 250a354c8..99ceb04ec 100644
--- a/samples/main-channel.cc
+++ b/samples/main-channel.cc
@@ -18,7 +18,7 @@
*/
#include
-#include "ns3/debug.h"
+#include "ns3/log.h"
#include "ns3/assert.h"
#include "ns3/packet.h"
#include "ns3/drop-tail.h"
@@ -27,6 +27,8 @@
using namespace ns3;
+NS_LOG_COMPONENT_DEFINE ("ChannelSample");
+
// ===========================================================================
// Cook up a simplistic Internet Node
// ===========================================================================
@@ -48,19 +50,19 @@ protected:
FakeInternetNode::FakeInternetNode ()
{
- NS_DEBUG_UNCOND("FakeInternetNode::FakeInternetNode ()");
+ NS_LOG_FUNCTION;
}
FakeInternetNode::~FakeInternetNode ()
{
- NS_DEBUG_UNCOND("FakeInternetNode::~FakeInternetNode ()");
+ NS_LOG_FUNCTION;
}
void
FakeInternetNode::Doit (void)
{
- NS_DEBUG_UNCOND("FakeInternetNode::Doit ()");
- NS_DEBUG_UNCOND("FakeInternetNode::Doit (): **** Send outbound packet");
+ NS_LOG_FUNCTION;
+ NS_LOG_INFO ("**** Send outbound packet");
Packet p;
m_dtqOutbound.Enqueue(p);
@@ -70,9 +72,9 @@ FakeInternetNode::Doit (void)
bool
FakeInternetNode::UpperDoSendUp (Packet &p)
{
- NS_DEBUG_UNCOND("FakeInternetNode::UpperDoSendUp (" << &p << ")");
-
- NS_DEBUG_UNCOND("FakeInternetNode::UpperDoSendUp (): **** Receive inbound packet");
+ NS_LOG_FUNCTION;
+ NS_LOG_PARAM ("(" << &p << ")");
+ NS_LOG_INFO ("**** Receive inbound packet");
m_dtqInbound.Enqueue(p);
return m_dtqInbound.Dequeue(p);
}
@@ -80,7 +82,8 @@ FakeInternetNode::UpperDoSendUp (Packet &p)
bool
FakeInternetNode::UpperDoPull (Packet &p)
{
- NS_DEBUG_UNCOND("FakeInternetNode::DoPull (" << &p << ")");
+ NS_LOG_FUNCTION;
+ NS_LOG_PARAM ("(" << &p << ")");
return m_dtqOutbound.Dequeue(p);
}
@@ -107,29 +110,29 @@ protected:
FakePhysicalLayer::FakePhysicalLayer ()
{
- NS_DEBUG_UNCOND("FakePhysicalLayer::FakePhysicalLayer ()");
+ NS_LOG_FUNCTION;
}
FakePhysicalLayer::~FakePhysicalLayer ()
{
- NS_DEBUG_UNCOND("FakePhysicalLayer::~FakePhysicalLayer ()");
+ NS_LOG_FUNCTION;
}
bool
FakePhysicalLayer::LowerDoNotify (LayerConnectorUpper *upper)
{
- NS_DEBUG_UNCOND("FakePhysicalLayer::LowerDoNotify ()");
+ NS_LOG_FUNCTION;
Packet p;
- NS_DEBUG_UNCOND("FakePhysicalLayer::LowerDoNotify (): Starting pull");
+ NS_LOG_LOGIC ("Starting pull");
NS_ASSERT(m_upperPartner);
m_upperPartner->UpperPull(p);
m_dtqOutbound.Enqueue(p);
- NS_DEBUG_UNCOND("FakePhysicalLayer::LowerDoNotify (): Got bits, Notify lower");
+ NS_LOG_LOGIC ("Got bits, Notify lower");
NS_ASSERT(m_lowerPartner);
return m_lowerPartner->LowerNotify(this);
@@ -138,7 +141,8 @@ FakePhysicalLayer::LowerDoNotify (LayerConnectorUpper *upper)
bool
FakePhysicalLayer::UpperDoSendUp (Packet &p)
{
- NS_DEBUG_UNCOND("FakePhysicalLayer::UpperDoSendUp (" << &p << ")");
+ NS_LOG_FUNCTION;
+ NS_LOG_PARAM ("(" << &p << ")");
NS_ASSERT(m_upperPartner);
return m_upperPartner->UpperSendUp(p);
@@ -147,7 +151,8 @@ FakePhysicalLayer::UpperDoSendUp (Packet &p)
bool
FakePhysicalLayer::UpperDoPull (Packet &p)
{
- NS_DEBUG_UNCOND("FakePhysicalLayer::DoPull (" << &p << ")");
+ NS_LOG_FUNCTION;
+ NS_LOG_PARAM ("(" << &p << ")");
return m_dtqOutbound.Dequeue(p);
}
@@ -164,24 +169,17 @@ public:
FakeChannel::FakeChannel ()
{
- NS_DEBUG_UNCOND("FakeChannel::FakeChannel ()");
+ NS_LOG_FUNCTION;
}
FakeChannel::~FakeChannel ()
{
- NS_DEBUG_UNCOND("FakeChannel::~FakeChannel ()");
+ NS_LOG_FUNCTION;
}
int main (int argc, char *argv[])
{
- NS_DEBUG_UNCOND("Channel Hackorama");
-
-#if 0
- DebugComponentEnable("Queue");
- DebugComponentEnable("DropTailQueue");
- DebugComponentEnable("LayerConnector");
- DebugComponentEnable("Channel");
-#endif
+ NS_LOG_INFO ("Channel Hackorama");
FakeInternetNode node1, node2, node3, node4;
FakePhysicalLayer phys1, phys2, phys3, phys4;
diff --git a/samples/main-default-value.cc b/samples/main-default-value.cc
index f125a7181..dcaa8a83a 100644
--- a/samples/main-default-value.cc
+++ b/samples/main-default-value.cc
@@ -3,7 +3,7 @@
#include
#include "ns3/default-value.h"
#include "ns3/command-line.h"
-#include "ns3/debug.h"
+#include "ns3/log.h"
using namespace ns3;
@@ -76,9 +76,9 @@ int main (int argc, char* argv[])
DefaultValue::Bind("testInt1", "57");
TestClass* testclass = new TestClass ();
- NS_DEBUG_UNCOND("TestBool1 default value (" << testclass->m_testBool1 << ")");
- NS_DEBUG_UNCOND("TestInt1 default value (" << testclass->m_testInt1 << ")");
- NS_DEBUG_UNCOND("TestInt2 default value (" << testclass->m_testInt2 << ")");
+ NS_LOG_UNCOND("TestBool1 default value (" << testclass->m_testBool1 << ")");
+ NS_LOG_UNCOND("TestInt1 default value (" << testclass->m_testInt1 << ")");
+ NS_LOG_UNCOND("TestInt2 default value (" << testclass->m_testInt2 << ")");
delete testclass;
return 0;
diff --git a/samples/main-query-interface.cc b/samples/main-query-interface.cc
index 20da36ff3..db23a5000 100644
--- a/samples/main-query-interface.cc
+++ b/samples/main-query-interface.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "ns3/debug.h"
+#include "ns3/log.h"
#include "ns3/object.h"
#include "ns3/component-manager.h"
@@ -79,10 +79,11 @@ private:
void
AnInterface::methodA (void)
{
+ NS_LOG_FUNCTION;
// pre-dispatch asserts
- NS_DEBUG_UNCOND("AnInterface pre-condition::methodA");
+ NS_LOG_LOGIC ("pre-condition");
domethodA ();
- NS_DEBUG_UNCOND("AnInterface post-condition::methodA\n");
+ NS_LOG_LOGIC ("post-condition");
// post-dispatch asserts
}
@@ -114,12 +115,13 @@ private:
void
AnImplementation::methodImpl (void)
{
- NS_DEBUG_UNCOND("AnImplementation::methodImpl\n");
+ NS_LOG_FUNCTION;
}
AnImplementation::AnImplementation (void)
{
+ NS_LOG_FUNCTION;
// enable our interface
SetInterfaceId (AnImplementation::iid);
}
@@ -127,7 +129,7 @@ AnImplementation::AnImplementation (void)
void
AnImplementation::domethodA ()
{
- NS_DEBUG_UNCOND("AnImplementation::domethodA");
+ NS_LOG_FUNCTION;
}
//
@@ -201,7 +203,7 @@ ANewImplementation::ANewImplementation (void)
void
ANewImplementation::methodImpl (void)
{
- NS_DEBUG_UNCOND("ANewImplementation::methodImpl\n");
+ NS_LOG_FUNCTION;
}
const InterfaceId ANewImplementation::iid =
@@ -238,7 +240,7 @@ AnExtendedImplementation::AnExtendedImplementation (void)
void
AnExtendedImplementation::methodExtendedImpl (void)
{
- NS_DEBUG_UNCOND("AnExtendedImplementation::methodExtendedImpl\n");
+ NS_LOG_FUNCTION;
}
const InterfaceId AnExtendedImplementation::iid =
diff --git a/samples/main-random-topology.cc b/samples/main-random-topology.cc
index 3fb52a0d9..3021ed3fb 100644
--- a/samples/main-random-topology.cc
+++ b/samples/main-random-topology.cc
@@ -15,7 +15,7 @@
using namespace ns3;
static void
-CourseChange (Ptr position)
+CourseChange (const TraceContext &context, Ptr position)
{
Position pos = position->Get ();
std::cout << Simulator::Now () << ", pos=" << position << ", x=" << pos.x << ", y=" << pos.y
@@ -39,7 +39,7 @@ int main (int argc, char *argv[])
for (uint32_t i = 0; i < 10000; i++)
{
Ptr notifier = Create ();
- notifier->RegisterListener (MakeCallback (&CourseChange));
+ notifier->TraceConnect ("/course-change", MakeCallback (&CourseChange));
objects.push_back (notifier);
}
diff --git a/samples/main-tw.cc b/samples/main-tw.cc
index c4e1ff1f4..4fcb8b94b 100644
--- a/samples/main-tw.cc
+++ b/samples/main-tw.cc
@@ -18,14 +18,14 @@
*/
#include
-#include "ns3/debug.h"
+#include "ns3/log.h"
#include "ns3/trace-writer.h"
using namespace ns3;
int main (int argc, char *argv[])
{
- NS_DEBUG_UNCOND("TraceWriter Test")
+ NS_LOG_UNCOND("TraceWriter Test")
TraceWriter writer1;
writer1.Open("trace-writer-test.txt");
diff --git a/samples/waf b/samples/waf
new file mode 100755
index 000000000..191b7dbb2
--- /dev/null
+++ b/samples/waf
@@ -0,0 +1 @@
+exec "`dirname "$0"`"/../waf "$@"
diff --git a/samples/wscript b/samples/wscript
index 998ab464f..a8ffc2d38 100644
--- a/samples/wscript
+++ b/samples/wscript
@@ -26,7 +26,7 @@ def build(bld):
obj.source = 'main-test.cc'
obj = bld.create_ns3_program('main-simple',
- ['node', 'internet-node', 'applications'])
+ ['node', 'internet-node', 'onoff'])
obj.source = 'main-simple.cc'
obj = bld.create_ns3_program('main-default-value',
diff --git a/src/applications/onoff-application.cc b/src/applications/onoff/onoff-application.cc
similarity index 86%
rename from src/applications/onoff-application.cc
rename to src/applications/onoff/onoff-application.cc
index 32bcd7564..29f3d9d04 100644
--- a/src/applications/onoff-application.cc
+++ b/src/applications/onoff/onoff-application.cc
@@ -22,6 +22,7 @@
// George F. Riley, Georgia Tech, Spring 2007
// Adapted from ApplicationOnOff in GTNetS.
+#include "ns3/log.h"
#include "ns3/address.h"
#include "ns3/node.h"
#include "ns3/nstime.h"
@@ -34,6 +35,8 @@
#include "ns3/packet.h"
#include "onoff-application.h"
+NS_LOG_COMPONENT_DEFINE ("OnOffApplication");
+
using namespace std;
namespace ns3 {
@@ -70,8 +73,8 @@ OnOffApplication::OnOffApplication(Ptr n,
: Application(n),
m_cbrRate (rate)
{
- Construct (n, remote, iid,
- ontime, offtime, size);
+ NS_LOG_FUNCTION;
+ Construct (n, remote, iid, ontime, offtime, size);
}
void
@@ -82,6 +85,8 @@ OnOffApplication::Construct (Ptr n,
const RandomVariable& offTime,
uint32_t size)
{
+ NS_LOG_FUNCTION;
+
m_socket = 0;
m_peer = remote;
m_connected = false;
@@ -95,30 +100,40 @@ OnOffApplication::Construct (Ptr n,
m_iid = iid;
}
-
OnOffApplication::~OnOffApplication()
-{}
+{
+ NS_LOG_FUNCTION;
+}
void
OnOffApplication::SetMaxBytes(uint32_t maxBytes)
{
+ NS_LOG_FUNCTION;
+ NS_LOG_PARAM ("(" << maxBytes << ")");
m_maxBytes = maxBytes;
}
void
OnOffApplication::SetDefaultRate (const DataRate &rate)
{
+ NS_LOG_FUNCTION;
+ NS_LOG_PARAM ("(" << &rate << ")");
g_defaultRate.SetValue (rate);
}
+
void
OnOffApplication::SetDefaultSize (uint32_t size)
{
+ NS_LOG_FUNCTION;
+ NS_LOG_PARAM ("(" << size << ")");
g_defaultSize.SetValue (size);
}
void
OnOffApplication::DoDispose (void)
{
+ NS_LOG_FUNCTION;
+
m_socket = 0;
delete m_onTime;
delete m_offTime;
@@ -130,10 +145,11 @@ OnOffApplication::DoDispose (void)
Application::DoDispose ();
}
-
// Application Methods
-void OnOffApplication::StartApplication() // Called at time specified by Start
+void OnOffApplication::StartApplication() // Called at time specified by Start
{
+ NS_LOG_FUNCTION;
+
// Create the socket if not already
if (!m_socket)
{
@@ -151,8 +167,10 @@ void OnOffApplication::StartApplication() // Called at time specified by Star
ScheduleStartEvent();
}
-void OnOffApplication::StopApplication() // Called at time specified by Stop
+void OnOffApplication::StopApplication() // Called at time specified by Stop
{
+ NS_LOG_FUNCTION;
+
if (m_sendEvent.IsRunning ())
{ // Cancel the pending send packet event
// Calculate residual bits since last packet sent
@@ -166,23 +184,32 @@ void OnOffApplication::StopApplication() // Called at time specified by Stop
// Event handlers
void OnOffApplication::StartSending()
{
+ NS_LOG_FUNCTION;
+
ScheduleNextTx(); // Schedule the send packet event
}
void OnOffApplication::StopSending()
{
+ NS_LOG_FUNCTION;
+
Simulator::Cancel(m_sendEvent);
}
// Private helpers
void OnOffApplication::ScheduleNextTx()
{
+ NS_LOG_FUNCTION;
+
if (m_totBytes < m_maxBytes)
{
uint32_t bits = m_pktSize * 8 - m_residualBits;
+ NS_LOG_LOGIC ("bits = " << bits);
Time nextTime(Seconds (bits /
static_cast(m_cbrRate.GetBitRate()))); // Time till next packet
- m_sendEvent = Simulator::Schedule(nextTime, &OnOffApplication::SendPacket, this);
+ NS_LOG_LOGIC ("nextTime = " << nextTime);
+ m_sendEvent = Simulator::Schedule(nextTime,
+ &OnOffApplication::SendPacket, this);
}
else
{ // All done, cancel any pending events
@@ -192,12 +219,17 @@ void OnOffApplication::ScheduleNextTx()
void OnOffApplication::ScheduleStartEvent()
{ // Schedules the event to start sending data (switch to the "On" state)
+ NS_LOG_FUNCTION;
+
Time offInterval = Seconds(m_offTime->GetValue());
+ NS_LOG_LOGIC ("start at " << offInterval);
m_startStopEvent = Simulator::Schedule(offInterval, &OnOffApplication::StartSending, this);
}
void OnOffApplication::ScheduleStopEvent()
{ // Schedules the event to stop sending data (switch to "Off" state)
+ NS_LOG_FUNCTION;
+
Time onInterval = Seconds(m_onTime->GetValue());
Simulator::Schedule(onInterval, &OnOffApplication::StopSending, this);
}
@@ -205,6 +237,8 @@ void OnOffApplication::ScheduleStopEvent()
void OnOffApplication::SendPacket()
{
+ NS_LOG_FUNCTION;
+
NS_ASSERT (m_sendEvent.IsExpired ());
m_socket->Send(Packet (m_pktSize));
m_totBytes += m_pktSize;
@@ -215,12 +249,15 @@ void OnOffApplication::SendPacket()
void OnOffApplication::ConnectionSucceeded(Ptr)
{
+ NS_LOG_FUNCTION;
+
m_connected = true;
ScheduleStartEvent();
}
void OnOffApplication::ConnectionFailed(Ptr)
{
+ NS_LOG_FUNCTION;
cout << "OnOffApplication, Connection Failed" << endl;
}
diff --git a/src/applications/onoff-application.h b/src/applications/onoff/onoff-application.h
similarity index 100%
rename from src/applications/onoff-application.h
rename to src/applications/onoff/onoff-application.h
diff --git a/src/applications/onoff/waf b/src/applications/onoff/waf
new file mode 100755
index 000000000..4283ec141
--- /dev/null
+++ b/src/applications/onoff/waf
@@ -0,0 +1 @@
+exec "`dirname "$0"`"/../../../waf "$@"
diff --git a/src/applications/wscript b/src/applications/onoff/wscript
similarity index 76%
rename from src/applications/wscript
rename to src/applications/onoff/wscript
index 02aa11f7f..c1bfe4c52 100644
--- a/src/applications/wscript
+++ b/src/applications/onoff/wscript
@@ -1,12 +1,12 @@
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
def build(bld):
- obj = bld.create_ns3_module('applications', ['node'])
- obj.source = [
+ module = bld.create_ns3_module('onoff', ['core'])
+ module.source = [
'onoff-application.cc',
]
-
headers = bld.create_obj('ns3header')
headers.source = [
'onoff-application.h',
]
+
diff --git a/src/applications/packet-sink/packet-sink.cc b/src/applications/packet-sink/packet-sink.cc
new file mode 100644
index 000000000..503e0cbff
--- /dev/null
+++ b/src/applications/packet-sink/packet-sink.cc
@@ -0,0 +1,109 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright 2007 University of Washington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Tom Henderson (tomhend@u.washington.edu)
+ */
+#include "ns3/address.h"
+#include "ns3/log.h"
+#include "ns3/inet-socket-address.h"
+#include "ns3/node.h"
+#include "ns3/socket.h"
+#include "ns3/simulator.h"
+#include "ns3/socket-factory.h"
+#include "ns3/packet.h"
+#include "packet-sink.h"
+
+using namespace std;
+
+namespace ns3 {
+
+NS_LOG_COMPONENT_DEFINE ("PacketSinkApplication");
+
+// Constructors
+
+PacketSink::PacketSink (Ptr n,
+ const Address &local,
+ std::string iid)
+ : Application(n)
+{
+ Construct (n, local, iid);
+}
+
+void
+PacketSink::Construct (Ptr n,
+ const Address &local,
+ std::string iid)
+{
+ m_socket = 0;
+ m_local = local;
+ m_iid = iid;
+}
+
+PacketSink::~PacketSink()
+{}
+
+void
+PacketSink::DoDispose (void)
+{
+ m_socket = 0;
+
+ // chain up
+ Application::DoDispose ();
+}
+
+
+// Application Methods
+void PacketSink::StartApplication() // Called at time specified by Start
+{
+ // Create the socket if not already
+ if (!m_socket)
+ {
+ InterfaceId iid = InterfaceId::LookupByName (m_iid);
+ Ptr socketFactory =
+ GetNode ()->QueryInterface (iid);
+ m_socket = socketFactory->CreateSocket ();
+ m_socket->Bind (m_local);
+ }
+ m_socket->SetRecvCallback((Callback, const Packet &,
+ const Address &>) MakeCallback(&PacketSink::Receive, this));
+}
+
+void PacketSink::StopApplication() // Called at time specified by Stop
+{
+ if (!m_socket)
+ {
+ m_socket->SetRecvCallback((Callback, const Packet &,
+ const Address &>) NULL);
+
+ }
+}
+
+// This LOG output inspired by the application on Joseph Kopena's wiki
+void PacketSink::Receive(Ptr socket, const Packet &packet,
+ const Address &from)
+{
+ if (InetSocketAddress::IsMatchingType (from))
+ {
+ InetSocketAddress address = InetSocketAddress::ConvertFrom (from);
+ NS_LOG_INFO ("Received " << packet.GetSize() << " bytes from " <<
+ address.GetIpv4() << " [" << address << "]---'" <<
+ packet.PeekData() << "'");
+ // TODO: Add a tracing source here
+ }
+}
+
+} // Namespace ns3
diff --git a/src/applications/packet-sink/packet-sink.h b/src/applications/packet-sink/packet-sink.h
new file mode 100644
index 000000000..8af7b3ab5
--- /dev/null
+++ b/src/applications/packet-sink/packet-sink.h
@@ -0,0 +1,87 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright 2007 University of Washington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Tom Henderson (tomhend@u.washington.edu)
+ */
+
+#ifndef __packet_sink_h__
+#define __packet_sink_h__
+
+#include "ns3/application.h"
+#include "ns3/event-id.h"
+#include "ns3/ptr.h"
+
+namespace ns3 {
+
+class Address;
+class Socket;
+class Packet;
+
+/**
+ * \brief Receive and consume traffic generated to an IP address and port
+ *
+ * This application was written to complement OnOffApplication, but it
+ * is more general so a PacketSink name was selected. Functionally it is
+ * important to use in multicast situations, so that reception of the layer-2
+ * multicast frames of interest are enabled, but it is also useful for
+ * unicast as an example of how you can write something simple to receive
+ * packets at the application layer. Also, if an IP stack generates
+ * ICMP Port Unreachable errors, receiving applications will be needed.
+ *
+ * The constructor specifies the Address (IP address and port) and the
+ * transport protocol to use. A virtual Receive () method is installed
+ * as a callback on the receiving socket. By default, when logging is
+ * enabled, it prints out the size of packets and their address, but
+ * we intend to also add a tracing source to Receive() at a later date.
+ */
+class PacketSink : public Application
+{
+public:
+ /**
+ * \param n node associated to this application
+ * \param local local address to bind to
+ * \param iid string to identify transport protocol of interest
+ */
+ PacketSink (Ptr n,
+ const Address &local,
+ std::string iid);
+
+ virtual ~PacketSink ();
+
+protected:
+ virtual void DoDispose (void);
+private:
+ // inherited from Application base class.
+ virtual void StartApplication (void); // Called at time specified by Start
+ virtual void StopApplication (void); // Called at time specified by Stop
+
+ void Construct (Ptr n,
+ const Address &local,
+ std::string iid);
+
+ virtual void Receive (Ptr socket, const Packet& packet, const Address& from);
+
+ Ptr m_socket; // Associated socket
+ Address m_local; // Local address to bind to
+ std::string m_iid; // Protocol name (e.g., "Udp")
+
+};
+
+} // namespace ns3
+
+#endif
+
diff --git a/src/applications/packet-sink/waf b/src/applications/packet-sink/waf
new file mode 100755
index 000000000..4283ec141
--- /dev/null
+++ b/src/applications/packet-sink/waf
@@ -0,0 +1 @@
+exec "`dirname "$0"`"/../../../waf "$@"
diff --git a/src/applications/packet-sink/wscript b/src/applications/packet-sink/wscript
new file mode 100644
index 000000000..332b6e4a1
--- /dev/null
+++ b/src/applications/packet-sink/wscript
@@ -0,0 +1,12 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+ module = bld.create_ns3_module('packet-sink', ['node'])
+ module.source = [
+ 'packet-sink.cc',
+ ]
+ headers = bld.create_obj('ns3header')
+ headers.source = [
+ 'packet-sink.h',
+ ]
+
diff --git a/src/applications/udp-echo/udp-echo-client.cc b/src/applications/udp-echo/udp-echo-client.cc
new file mode 100644
index 000000000..a5489ef2c
--- /dev/null
+++ b/src/applications/udp-echo/udp-echo-client.cc
@@ -0,0 +1,168 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright 2007 University of Washington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#include "ns3/log.h"
+#include "ns3/ipv4-address.h"
+#include "ns3/nstime.h"
+#include "ns3/inet-socket-address.h"
+#include "ns3/socket.h"
+#include "ns3/simulator.h"
+#include "ns3/socket-factory.h"
+#include "ns3/packet.h"
+#include "udp-echo-client.h"
+
+namespace ns3 {
+
+NS_LOG_COMPONENT_DEFINE ("UdpEchoClientApplication");
+
+UdpEchoClient::UdpEchoClient (
+ Ptr n,
+ Ipv4Address serverAddress,
+ uint16_t serverPort,
+ uint32_t count,
+ Time interval,
+ uint32_t size)
+:
+ Application(n)
+{
+ NS_LOG_FUNCTION;
+ NS_LOG_PARAM ("(" << n << ", " << serverAddress <<
+ ", " << serverPort << ", " << count << ", " << interval <<
+ ", " << size << ")");
+
+ Construct (n, serverAddress, serverPort, count, interval, size);
+}
+
+UdpEchoClient::~UdpEchoClient()
+{
+ NS_LOG_FUNCTION;
+}
+
+void
+UdpEchoClient::Construct (
+ Ptr n,
+ Ipv4Address serverAddress,
+ uint16_t serverPort,
+ uint32_t count,
+ Time interval,
+ uint32_t size)
+{
+ NS_LOG_FUNCTION;
+ NS_LOG_PARAM ("(" << n << ", " << serverAddress <<
+ ", " << serverPort << ", " << count << ", " << interval <<
+ ", " << size << ")");
+
+ m_node = n;
+ m_serverAddress = serverAddress;
+ m_serverPort = serverPort;
+ m_count = count;
+ m_interval = interval;
+ m_size = size;
+
+ m_sent = 0;
+ m_socket = 0;
+ m_peer = InetSocketAddress (serverAddress, serverPort);
+ m_sendEvent = EventId ();
+}
+
+void
+UdpEchoClient::DoDispose (void)
+{
+ NS_LOG_FUNCTION;
+ Application::DoDispose ();
+}
+
+void
+UdpEchoClient::StartApplication (void)
+{
+ NS_LOG_FUNCTION;
+
+ if (!m_socket)
+ {
+ InterfaceId iid = InterfaceId::LookupByName ("Udp");
+ Ptr socketFactory =
+ GetNode ()->QueryInterface (iid);
+ m_socket = socketFactory->CreateSocket ();
+ m_socket->Bind ();
+ m_socket->Connect (m_peer);
+ }
+
+ m_socket->SetRecvCallback((Callback, const Packet &,
+ const Address &>) MakeCallback(&UdpEchoClient::Receive, this));
+
+ ScheduleTransmit (Seconds(0.));
+}
+
+void
+UdpEchoClient::StopApplication ()
+{
+ NS_LOG_FUNCTION;
+
+ if (!m_socket)
+ {
+ m_socket->SetRecvCallback((Callback, const Packet &,
+ const Address &>) NULL);
+ }
+
+ Simulator::Cancel(m_sendEvent);
+}
+
+void
+UdpEchoClient::ScheduleTransmit (Time dt)
+{
+ NS_LOG_FUNCTION;
+ m_sendEvent = Simulator::Schedule(dt, &UdpEchoClient::Send, this);
+}
+
+void
+UdpEchoClient::Send (void)
+{
+ NS_LOG_FUNCTION;
+
+ NS_ASSERT (m_sendEvent.IsExpired ());
+
+ Packet p (m_size);
+ m_socket->Send (p);
+ ++m_sent;
+
+ NS_LOG_INFO ("Sent " << m_size << " bytes to " << m_serverAddress);
+
+ if (m_sent < m_count)
+ {
+ ScheduleTransmit (m_interval);
+ }
+}
+
+void
+UdpEchoClient::Receive(
+ Ptr socket,
+ const Packet &packet,
+ const Address &from)
+{
+ NS_LOG_FUNCTION;
+ NS_LOG_PARAM ("(" << socket << ", " << packet << ", " << from << ")");
+
+ if (InetSocketAddress::IsMatchingType (from))
+ {
+ InetSocketAddress address = InetSocketAddress::ConvertFrom (from);
+ NS_LOG_INFO ("Received " << packet.GetSize() << " bytes from " <<
+ address.GetIpv4());
+ }
+}
+
+
+} // Namespace ns3
diff --git a/src/applications/udp-echo/udp-echo-client.h b/src/applications/udp-echo/udp-echo-client.h
new file mode 100644
index 000000000..91914287d
--- /dev/null
+++ b/src/applications/udp-echo/udp-echo-client.h
@@ -0,0 +1,72 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright 2007 University of Washington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef __UDP_ECHO_CLIENT_H__
+#define __UDP_ECHO_CLIENT_H__
+
+#include "ns3/application.h"
+#include "ns3/event-id.h"
+#include "ns3/ptr.h"
+
+namespace ns3 {
+
+class Address;
+class Socket;
+class Packet;
+
+class UdpEchoClient : public Application
+{
+public:
+ UdpEchoClient (Ptr n, Ipv4Address serverAddr, uint16_t serverPort,
+ uint32_t count, Time interval, uint32_t size);
+
+ virtual ~UdpEchoClient ();
+
+protected:
+ virtual void DoDispose (void);
+
+private:
+ void Construct (Ptr n, Ipv4Address serverAddr, uint16_t serverPort,
+ uint32_t count, Time interval, uint32_t size);
+
+ virtual void StartApplication (void);
+ virtual void StopApplication (void);
+
+ void ScheduleTransmit (Time dt);
+ void Send (void);
+
+ void Receive(Ptr socket, const Packet &packet, const Address &from);
+
+ Ptr m_node;
+ Ipv4Address m_serverAddress;
+ uint16_t m_serverPort;
+ uint32_t m_count;
+ Time m_interval;
+ uint32_t m_size;
+
+ uint32_t m_sent;
+ Ptr m_socket;
+ Address m_peer;
+ EventId m_sendEvent;
+
+};
+
+} // namespace ns3
+
+#endif // __UDP_ECHO_CLIENT_H__
+
diff --git a/src/applications/udp-echo/udp-echo-server.cc b/src/applications/udp-echo/udp-echo-server.cc
new file mode 100644
index 000000000..11654ed8d
--- /dev/null
+++ b/src/applications/udp-echo/udp-echo-server.cc
@@ -0,0 +1,123 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright 2007 University of Washington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "ns3/log.h"
+#include "ns3/ipv4-address.h"
+#include "ns3/nstime.h"
+#include "ns3/inet-socket-address.h"
+#include "ns3/socket.h"
+#include "ns3/simulator.h"
+#include "ns3/socket-factory.h"
+#include "ns3/packet.h"
+
+#include "udp-echo-server.h"
+
+namespace ns3 {
+
+NS_LOG_COMPONENT_DEFINE ("UdpEchoServerApplication");
+
+UdpEchoServer::UdpEchoServer (
+ Ptr n,
+ uint16_t port)
+:
+ Application(n)
+{
+ NS_LOG_FUNCTION;
+ NS_LOG_PARAM ("(" << n << ", " << port << ")");
+
+ Construct (n, port);
+}
+
+UdpEchoServer::~UdpEchoServer()
+{
+ NS_LOG_FUNCTION;
+}
+
+void
+UdpEchoServer::Construct (
+ Ptr n,
+ uint16_t port)
+{
+ NS_LOG_FUNCTION;
+ NS_LOG_PARAM ("(" << n << ", " << port << ")");
+
+ m_node = n;
+ m_port = port;
+
+ m_socket = 0;
+ m_local = InetSocketAddress (Ipv4Address::GetAny (), port);
+}
+
+void
+UdpEchoServer::DoDispose (void)
+{
+ NS_LOG_FUNCTION;
+ Application::DoDispose ();
+}
+
+void
+UdpEchoServer::StartApplication (void)
+{
+ NS_LOG_FUNCTION;
+
+ if (!m_socket)
+ {
+ InterfaceId iid = InterfaceId::LookupByName ("Udp");
+ Ptr socketFactory =
+ GetNode ()->QueryInterface (iid);
+ m_socket = socketFactory->CreateSocket ();
+ m_socket->Bind (m_local);
+ }
+
+ m_socket->SetRecvCallback((Callback, const Packet &,
+ const Address &>) MakeCallback(&UdpEchoServer::Receive, this));
+}
+
+void
+UdpEchoServer::StopApplication ()
+{
+ NS_LOG_FUNCTION;
+
+ if (!m_socket)
+ {
+ m_socket->SetRecvCallback((Callback, const Packet &,
+ const Address &>) NULL);
+ }
+}
+
+void
+UdpEchoServer::Receive(
+ Ptr socket,
+ const Packet &packet,
+ const Address &from)
+{
+ NS_LOG_FUNCTION;
+ NS_LOG_PARAM ("(" << socket << ", " << packet << ", " << from << ")");
+
+ if (InetSocketAddress::IsMatchingType (from))
+ {
+ InetSocketAddress address = InetSocketAddress::ConvertFrom (from);
+ NS_LOG_INFO ("Received " << packet.GetSize() << " bytes from " <<
+ address.GetIpv4());
+
+ NS_LOG_LOGIC ("Echoing packet");
+ socket->SendTo (from, packet);
+ }
+}
+
+} // Namespace ns3
diff --git a/src/applications/udp-echo/udp-echo-server.h b/src/applications/udp-echo/udp-echo-server.h
new file mode 100644
index 000000000..597fef8fe
--- /dev/null
+++ b/src/applications/udp-echo/udp-echo-server.h
@@ -0,0 +1,59 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright 2007 University of Washington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef __UDP_ECHO_SERVER_H__
+#define __UDP_ECHO_SERVER_H__
+
+#include "ns3/application.h"
+#include "ns3/event-id.h"
+#include "ns3/ptr.h"
+
+namespace ns3 {
+
+class Address;
+class Socket;
+class Packet;
+
+class UdpEchoServer : public Application
+{
+public:
+ UdpEchoServer (Ptr n, uint16_t clientPort);
+ virtual ~UdpEchoServer ();
+
+protected:
+ virtual void DoDispose (void);
+
+private:
+ void Construct (Ptr n, uint16_t clientPort);
+
+ virtual void StartApplication (void);
+ virtual void StopApplication (void);
+
+ void Receive(Ptr socket, const Packet &packet, const Address &from);
+
+ Ptr m_node;
+ uint16_t m_port;
+
+ Ptr m_socket;
+ Address m_local;
+};
+
+} // namespace ns3
+
+#endif // __UDP_ECHO_SERVER_H__
+
diff --git a/src/applications/udp-echo/waf b/src/applications/udp-echo/waf
new file mode 100755
index 000000000..4283ec141
--- /dev/null
+++ b/src/applications/udp-echo/waf
@@ -0,0 +1 @@
+exec "`dirname "$0"`"/../../../waf "$@"
diff --git a/src/applications/udp-echo/wscript b/src/applications/udp-echo/wscript
new file mode 100644
index 000000000..f6416980a
--- /dev/null
+++ b/src/applications/udp-echo/wscript
@@ -0,0 +1,14 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+ module = bld.create_ns3_module('udp-echo', ['internet-node'])
+ module.source = [
+ 'udp-echo-client.cc',
+ 'udp-echo-server.cc',
+ ]
+ headers = bld.create_obj('ns3header')
+ headers.source = [
+ 'udp-echo-client.h',
+ 'udp-echo-server.h',
+ ]
+
diff --git a/src/common/array-trace-resolver.h b/src/common/array-trace-resolver.h
deleted file mode 100644
index e4507d4af..000000000
--- a/src/common/array-trace-resolver.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2007 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 ARRAY_TRACE_RESOLVER_H
-#define ARRAY_TRACE_RESOLVER_H
-
-#include
-#include
-#include "ns3/callback.h"
-#include "trace-resolver.h"
-
-namespace ns3 {
-
-/**
- * \brief a helper class to offer trace resolution for an array of objects.
- * \ingroup lowleveltracing
- */
-template
-class ArrayTraceResolver : public TraceResolver
-{
-public:
- /**
- * \param context trace context associated to this trace resolver
- * \param getSize callback which returns dynamically the size of underlying array
- * \param get callback which returns any element in the underlying array
- *
- * Construct a trace resolver which can match any input integer
- * against an element in an array. The array is accessed using a
- * pair of callbacks. It is the responsability of the user to
- * provide two such callbacks whose job is to adapt the array
- * API to the resolver needs. Each element of the array is expected
- * to provide a method named CreateTraceResolver which takes as
- * only argument a reference to a const TraceContext and returns
- * a pointer to a TraceResolver. i.e. the signature is:
- * TraceResolver * (*) (TraceContext const &)
- */
- ArrayTraceResolver (TraceContext const &context,
- Callback getSize,
- Callback get);
-private:
- virtual TraceResolverList DoLookup (std::string id) const;
- Callback m_getSize;
- Callback m_get;
-};
-}//namespace ns3
-
-namespace ns3 {
-
-template
-ArrayTraceResolver::ArrayTraceResolver (TraceContext const &context,
- Callback getSize,
- Callback get)
- : TraceResolver (context),
- m_getSize (getSize),
- m_get (get)
-{}
-template
-TraceResolver::TraceResolverList
-ArrayTraceResolver::DoLookup (std::string id) const
-{
- TraceResolverList list;
- if (id == "*")
- {
- for (uint32_t i = 0; i < m_getSize (); i++)
- {
- TraceContext context = GetContext ();
- INDEX index = i;
- context.Add (index);
- list.push_back (m_get (i)->CreateTraceResolver (context));
- }
- }
- return list;
-}
-
-
-}//namespace ns3
-
-#endif /* ARRAY_TRACE_RESOLVER_H */
diff --git a/src/common/buffer.cc b/src/common/buffer.cc
index 196bb4889..6154df7d3 100644
--- a/src/common/buffer.cc
+++ b/src/common/buffer.cc
@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2005,2006 INRIA
- * All rights reserved.
+ * Copyright (c) 2005,2006,2007 INRIA
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -20,385 +19,534 @@
*/
#include "buffer.h"
#include "ns3/assert.h"
-
+#include "ns3/log.h"
#include
-//#define TRACE(x) std::cout << x << std::endl;
-#define TRACE(x)
+
+NS_LOG_COMPONENT_DEFINE ("Buffer");
+
+#define LOG_INTERNAL_STATE(y) \
+NS_LOG_LOGIC (y << "start="<
{
+public:
+ ~BufferDataList ();
+};
+
+static struct BufferData *BufferAllocate (uint32_t reqSize);
+
+static void BufferDeallocate (struct BufferData *data);
+
+
+} // namespace ns3
+
+namespace ns3 {
+
+#ifdef BUFFER_HEURISTICS
+static uint32_t g_recommendedStart = 0;
+static uint64_t g_nAddNoRealloc = 0;
+static uint64_t g_nAddRealloc = 0;
+static BufferDataList g_freeList;
+static uint32_t g_maxSize = 0;
+static uint64_t g_nAllocs = 0;
+static uint64_t g_nCreates = 0;
+#endif /* BUFFER_HEURISTICS */
+
+BufferDataList::~BufferDataList ()
+{
+#ifdef PRINT_STATS
+#ifdef BUFFER_HEURISTICS
+ double efficiency;
+ efficiency = g_nAllocs;
+ efficiency /= g_nCreates;
+ std::cout <<"buffer free list efficiency="<= m_data->m_dirtyStart &&
+ m_end <= m_data->m_dirtyEnd;
+ bool internalSizeOk = m_end - (m_zeroAreaEnd - m_zeroAreaStart) <= m_data->m_size &&
+ m_start <= m_data->m_size &&
+ m_zeroAreaStart <= m_data->m_size;
-namespace ns3 {
+ NS_ASSERT (offsetsOk);
+ NS_ASSERT (dirtyOk);
+ NS_ASSERT (internalSizeOk);
+ return m_data->m_count > 0 && offsetsOk && dirtyOk &&
+ internalSizeOk;
+}
+
+void
+Buffer::Initialize (uint32_t zeroSize)
+{
+ m_data = Buffer::Create (0);
+#ifdef BUFFER_HEURISTICS
+ m_start = std::min (m_data->m_size, g_recommendedStart);
+ m_maxZeroAreaStart = m_start;
+#else
+ m_start = 0;
+#endif /* BUFFER_HEURISTICS */
+ m_zeroAreaStart = m_start;
+ m_zeroAreaEnd = m_zeroAreaStart + zeroSize;
+ m_end = m_zeroAreaEnd;
+ m_data->m_dirtyStart = m_start;
+ m_data->m_dirtyEnd = m_end;
+ NS_ASSERT (CheckInternalState ());
+}
+
+Buffer::Buffer (Buffer const&o)
+ : m_data (o.m_data),
+#ifdef BUFFER_HEURISTICS
+ m_maxZeroAreaStart (o.m_zeroAreaStart),
+#endif
+ m_zeroAreaStart (o.m_zeroAreaStart),
+ m_zeroAreaEnd (o.m_zeroAreaEnd),
+ m_start (o.m_start),
+ m_end (o.m_end)
+{
+ m_data->m_count++;
+ NS_ASSERT (CheckInternalState ());
+}
+
+Buffer &
+Buffer::operator = (Buffer const&o)
+{
+ NS_ASSERT (CheckInternalState ());
+ if (m_data != o.m_data)
+ {
+ // not assignment to self.
+ m_data->m_count--;
+ if (m_data->m_count == 0)
+ {
+ Recycle (m_data);
+ }
+ m_data = o.m_data;
+ m_data->m_count++;
+ }
+ HEURISTICS (
+ g_recommendedStart = std::max (g_recommendedStart, m_maxZeroAreaStart);
+ m_maxZeroAreaStart = o.m_maxZeroAreaStart;
+ );
+ m_zeroAreaStart = o.m_zeroAreaStart;
+ m_zeroAreaEnd = o.m_zeroAreaEnd;
+ m_start = o.m_start;
+ m_end = o.m_end;
+ NS_ASSERT (CheckInternalState ());
+ return *this;
+}
+
+Buffer::~Buffer ()
+{
+ HEURISTICS (g_recommendedStart = std::max (g_recommendedStart, m_maxZeroAreaStart));
+ m_data->m_count--;
+ if (m_data->m_count == 0)
+ {
+ Recycle (m_data);
+ }
+}
+
+uint32_t
+Buffer::GetSize (void) const
+{
+ NS_ASSERT (CheckInternalState ());
+ return m_end - m_start;
+}
+
+Buffer::Iterator
+Buffer::Begin (void) const
+{
+ NS_ASSERT (CheckInternalState ());
+ return Buffer::Iterator (this);
+}
+Buffer::Iterator
+Buffer::End (void) const
+{
+ NS_ASSERT (CheckInternalState ());
+ return Buffer::Iterator (this, false);
+}
+
+uint32_t
+Buffer::GetInternalSize (void) const
+{
+ return m_zeroAreaStart - m_start + m_end - m_zeroAreaEnd;
+}
+uint32_t
+Buffer::GetInternalEnd (void) const
+{
+ return m_end - (m_zeroAreaEnd - m_zeroAreaStart);
+}
void
Buffer::AddAtStart (uint32_t start)
{
- NS_ASSERT (m_start <= m_data->m_initialStart);
+ NS_ASSERT (CheckInternalState ());
bool isDirty = m_data->m_count > 1 && m_start > m_data->m_dirtyStart;
- if (m_start >= start && !isDirty)
+ if (m_start >= start && !isDirty)
{
- /* enough space in the buffer and not dirty. */
+ /* enough space in the buffer and not dirty.
+ * To add: |..|
+ * Before: |*****---------***|
+ * After: |***..---------***|
+ */
+ NS_ASSERT (m_data->m_count == 1 || m_start == m_data->m_dirtyStart);
m_start -= start;
- m_size += start;
+ HEURISTICS (g_nAddNoRealloc++);
}
- else if (m_size + start <= m_data->m_size && !isDirty)
+#if 0
+ // the following is an optimization
+ else if (m_start >= start)
{
- /* enough space but need to move data around to fit new data */
- memmove (m_data->m_data + start, GetStart (), m_size);
- NS_ASSERT (start > m_start);
- m_data->m_initialStart += start - m_start;
- m_start = 0;
- m_size += start;
- }
- else if (m_start < start)
- {
- /* not enough space in buffer */
- uint32_t newSize = m_size + start;
- struct Buffer::BufferData *newData = Buffer::Allocate (newSize, 0);
- memcpy (newData->m_data + start, GetStart (), m_size);
- newData->m_initialStart = m_data->m_initialStart + start;
+ struct BufferData *newData = Buffer::Create (m_data->m_size);
+ memcpy (newData->m_data + m_start, m_data->m_data + m_start, GetInternalSize ());
m_data->m_count--;
- if (m_data->m_count == 0)
+ if (m_data->m_count == 0)
{
- Buffer::Deallocate (m_data);
+ Buffer::Recycle (m_data);
}
m_data = newData;
- m_start = 0;
- m_size = newSize;
- }
- else
+
+ m_start -= start;
+ HEURISTICS (g_nAddRealloc++);
+ }
+ else
{
- /* enough space in the buffer but it is dirty ! */
- 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;
+ NS_ASSERT (m_start < start);
+#else
+ else
+ {
+#endif
+ uint32_t newSize = GetInternalSize () + start;
+ struct BufferData *newData = Buffer::Create (newSize);
+ memcpy (newData->m_data + start, m_data->m_data + m_start, GetInternalSize ());
m_data->m_count--;
- if (m_data->m_count == 0)
+ if (m_data->m_count == 0)
{
- Recycle (m_data);
+ Buffer::Recycle (m_data);
}
m_data = newData;
- m_start -= start;
- m_size += start;
- }
+
+ int32_t delta = start - m_start;
+ m_start = 0;
+ m_zeroAreaStart += delta;
+ m_zeroAreaEnd += delta;
+ m_end += delta;
+
+ HEURISTICS (g_nAddRealloc++);
+ }
+ HEURISTICS (m_maxZeroAreaStart = std::max (m_maxZeroAreaStart, m_zeroAreaStart));
// update dirty area
m_data->m_dirtyStart = m_start;
- m_data->m_dirtySize = m_size;
- // update m_maxTotalAddStart
- uint32_t addedAtStart;
- if (m_data->m_initialStart > m_start)
- {
- addedAtStart = m_data->m_initialStart - m_start;
- }
- else
- {
- addedAtStart = 0;
- }
- if (addedAtStart > m_maxTotalAddStart)
- {
- m_maxTotalAddStart = addedAtStart;
- }
- TRACE ("start add="<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)
+ NS_ASSERT (CheckInternalState ());
+ bool isDirty = m_data->m_count > 1 && m_end < m_data->m_dirtyEnd;
+ if (GetInternalEnd () + end <= m_data->m_size && !isDirty)
{
- /* enough space in buffer and not dirty */
- m_size += end;
+ /* enough space in buffer and not dirty
+ * Add: |...|
+ * Before: |**----*****|
+ * After: |**----...**|
+ */
+ NS_ASSERT (m_data->m_count == 1 || m_end == m_data->m_dirtyEnd);
+ m_end += end;
+
+ HEURISTICS (g_nAddNoRealloc++);
}
- else if (m_size + end <= m_data->m_size && !isDirty)
+#if 0
+ // this is an optimization
+ else if (GetInternalEnd () + end > m_data->m_size)
{
- /* 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);
- NS_ASSERT (newStart < m_start);
- m_data->m_initialStart -= m_start - newStart;
- m_start = newStart;
- m_size += end;
- }
- else if (m_start + m_size + end > m_data->m_size)
- {
- /* not enough space in buffer */
- uint32_t newSize = m_size + end;
- struct Buffer::BufferData *newData = Buffer::Allocate (newSize, 0);
- memcpy (newData->m_data, GetStart (), m_size);
- newData->m_initialStart = m_data->m_initialStart - m_start;
+ struct BufferData *newData = Buffer::Create (newSize);
+ memcpy (newData->m_data + m_start, m_data->m_data + m_start, GetInternalSize ());
m_data->m_count--;
if (m_data->m_count == 0)
{
- Buffer::Deallocate (m_data);
+ Buffer::Recycle (m_data);
}
m_data = newData;
- m_size = newSize;
+
+ m_end += end;
+ HEURISTICS (g_nAddRealloc++);
+ }
+#endif
+ else
+ {
+ uint32_t newSize = GetInternalSize () + end;
+ struct BufferData *newData = Buffer::Create (newSize);
+ memcpy (newData->m_data, m_data->m_data + m_start, GetInternalSize ());
+ m_data->m_count--;
+ if (m_data->m_count == 0)
+ {
+ Buffer::Recycle (m_data);
+ }
+ m_data = newData;
+
+
+ m_zeroAreaStart -= m_start;
+ m_zeroAreaEnd -= m_start;
+ m_end -= m_start;
m_start = 0;
+
+ m_end += end;
+
+ HEURISTICS (g_nAddRealloc++);
}
- else
- {
- /* enough space in the buffer but it is dirty ! */
- 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;
- m_data->m_count--;
- if (m_data->m_count == 0)
- {
- Recycle (m_data);
- }
- m_data = newData;
- m_size += end;
- }
+ HEURISTICS (m_maxZeroAreaStart = std::max (m_maxZeroAreaStart, m_zeroAreaStart));
// update dirty area
m_data->m_dirtyStart = m_start;
- m_data->m_dirtySize = m_size;
- // update m_maxTotalAddEnd
- uint32_t endLoc = m_start + m_size;
- uint32_t addedAtEnd;
- if (m_data->m_initialStart < endLoc)
- {
- addedAtEnd = endLoc - m_data->m_initialStart;
- }
- else
- {
- addedAtEnd = 0;
- }
- if (addedAtEnd > m_maxTotalAddEnd)
- {
- m_maxTotalAddEnd = addedAtEnd;
- }
- TRACE ("end add="<= start);
+ uint32_t zeroSize = m_zeroAreaEnd - m_zeroAreaStart;
+ m_start = newStart - zeroSize;
+ m_end -= zeroSize;
+ m_zeroAreaStart = m_start;
+ m_zeroAreaEnd = m_start;
+ }
else
{
- 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;
- if (start <= zeroStart)
- {
- /* only remove start of buffer */
- m_start += start;
- m_size -= start;
- }
- else if (start <= zeroEnd)
- {
- /* remove start of buffer _and_ start of zero area */
- m_start += zeroStart;
- uint32_t zeroDelta = start - zeroStart;
- m_zeroAreaSize -= zeroDelta;
- NS_ASSERT (zeroDelta <= start);
- m_size -= zeroStart;
- }
- else if (start <= dataEnd)
- {
- /* remove start of buffer, complete zero area, and part
- * of end of buffer */
- m_start += start - m_zeroAreaSize;
- m_size -= start - m_zeroAreaSize;
- m_zeroAreaSize = 0;
- }
- else
- {
- /* remove all buffer */
- m_start += m_size;
- m_size = 0;
- m_zeroAreaSize = 0;
- }
+ /* remove all buffer */
+ m_end -= m_zeroAreaEnd - m_zeroAreaStart;
+ m_start = m_end;
+ m_zeroAreaEnd = m_end;
+ m_zeroAreaStart = m_end;
}
- TRACE ("start remove="< m_zeroAreaEnd)
{
- if (m_size <= end)
- {
- m_size = 0;
- }
- else
- {
- m_size -= end;
- }
- }
- else
- {
- 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;
- NS_ASSERT (zeroStart <= m_size);
- NS_ASSERT (zeroEnd <= m_size + m_zeroAreaSize);
- if (dataEnd <= end)
- {
- /* remove all buffer */
- m_zeroAreaSize = 0;
- m_start += m_size;
- m_size = 0;
- }
- else if (dataEnd - zeroStart <= end)
- {
- /* remove end of buffer, zero area, part of start of buffer */
- NS_ASSERT (end >= m_zeroAreaSize);
- m_size -= end - m_zeroAreaSize;
- m_zeroAreaSize = 0;
- }
- else if (dataEnd - zeroEnd <= end)
- {
- /* remove end of buffer, part of zero area */
- uint32_t zeroDelta = end - (dataEnd - zeroEnd);
- m_zeroAreaSize -= zeroDelta;
- m_size -= end - zeroDelta;
- }
- else
- {
- /* remove part of end of buffer */
- m_size -= end;
- }
+ /* remove part of end of buffer */
+ m_end = newEnd;
}
- TRACE ("end remove="<m_initialStart - m_start;
- uint32_t zeroEnd = zeroStart + m_zeroAreaSize;
- if (m_zeroAreaSize != 0 &&
+ NS_ASSERT (CheckInternalState ());
+ uint32_t zeroStart = m_zeroAreaStart - m_start;
+ uint32_t zeroEnd = zeroStart + m_zeroAreaEnd;
+ if (m_zeroAreaEnd != 0 &&
start + length > zeroStart &&
start <= zeroEnd)
{
@@ -407,51 +555,433 @@ Buffer::CreateFragment (uint32_t start, uint32_t length) const
Buffer tmp = *this;
tmp.RemoveAtStart (start);
tmp.RemoveAtEnd (GetSize () - (start + length));
+ NS_ASSERT (CheckInternalState ());
return tmp;
}
Buffer
Buffer::CreateFullCopy (void) const
{
- if (m_zeroAreaSize != 0)
+ NS_ASSERT (CheckInternalState ());
+ if (m_zeroAreaEnd != 0)
{
- 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);
- uint32_t dataStart = m_data->m_initialStart - m_start;
+ tmp.AddAtStart (m_zeroAreaEnd - m_zeroAreaStart);
+ tmp.Begin ().WriteU8 (0, m_zeroAreaEnd - m_zeroAreaStart);
+ uint32_t dataStart = m_zeroAreaStart - m_start;
tmp.AddAtStart (dataStart);
tmp.Begin ().Write (m_data->m_data+m_start, dataStart);
- uint32_t dataEnd = m_size - (m_data->m_initialStart - m_start);
+ uint32_t dataEnd = m_end - m_zeroAreaEnd;
tmp.AddAtEnd (dataEnd);
Buffer::Iterator i = tmp.End ();
i.Prev (dataEnd);
- i.Write (m_data->m_data+m_data->m_initialStart,dataEnd);
+ i.Write (m_data->m_data+m_zeroAreaStart,dataEnd);
return tmp;
}
+ NS_ASSERT (CheckInternalState ());
return *this;
}
void
Buffer::TransformIntoRealBuffer (void) const
{
+ NS_ASSERT (CheckInternalState ());
Buffer tmp = CreateFullCopy ();
*const_cast (this) = tmp;
+ NS_ASSERT (CheckInternalState ());
}
uint8_t const*
Buffer::PeekData (void) const
{
+ NS_ASSERT (CheckInternalState ());
TransformIntoRealBuffer ();
+ NS_ASSERT (CheckInternalState ());
return m_data->m_data + m_start;
}
+/******************************************************
+ * The buffer iterator below.
+ ******************************************************/
+Buffer::Iterator::Iterator ()
+ : m_zeroStart (0),
+ m_zeroEnd (0),
+ m_dataStart (0),
+ m_dataEnd (0),
+ m_current (0),
+ m_data (0)
+{}
+Buffer::Iterator::Iterator (Buffer const*buffer)
+{
+ Construct (buffer);
+ m_current = m_dataStart;
+}
+Buffer::Iterator::Iterator (Buffer const*buffer, bool dummy)
+{
+ Construct (buffer);
+ m_current = m_dataEnd;
+}
-}; // namespace ns3
+void
+Buffer::Iterator::Construct (const Buffer *buffer)
+{
+ m_zeroStart = buffer->m_zeroAreaStart;
+ m_zeroEnd = buffer->m_zeroAreaEnd;
+ m_dataStart = buffer->m_start;
+ m_dataEnd = buffer->m_end;
+ m_data = buffer->m_data->m_data;
+}
+
+void
+Buffer::Iterator::Next (void)
+{
+ NS_ASSERT (m_current + 1 <= m_dataEnd);
+ m_current++;
+}
+void
+Buffer::Iterator::Prev (void)
+{
+ NS_ASSERT (m_current >= 1);
+ m_current--;
+}
+void
+Buffer::Iterator::Next (uint32_t delta)
+{
+ NS_ASSERT (m_current + delta <= m_dataEnd);
+ m_current += delta;
+}
+void
+Buffer::Iterator::Prev (uint32_t delta)
+{
+ NS_ASSERT (m_current >= delta);
+ m_current -= delta;
+}
+uint32_t
+Buffer::Iterator::GetDistanceFrom (Iterator const &o) const
+{
+ NS_ASSERT (m_data == o.m_data);
+ int32_t diff = m_current - o.m_current;
+ if (diff < 0)
+ {
+ return -diff;
+ }
+ else
+ {
+ return diff;
+ }
+}
+
+bool
+Buffer::Iterator::IsEnd (void) const
+{
+ return m_current == m_dataEnd;
+}
+bool
+Buffer::Iterator::IsStart (void) const
+{
+ return m_current == m_dataStart;
+}
+
+bool
+Buffer::Iterator::CheckNoZero (uint32_t start, uint32_t end) const
+{
+ bool ok = true;
+ for (uint32_t i = start; i < end; i++)
+ {
+ if (!Check (i))
+ {
+ ok = false;
+ }
+ }
+ return ok;
+}
+bool
+Buffer::Iterator::Check (uint32_t i) const
+{
+ return i >= m_dataStart &&
+ !(i >= m_zeroStart && i < m_zeroEnd) &&
+ i <= m_dataEnd;
+}
+
+
+void
+Buffer::Iterator::Write (Iterator start, Iterator end)
+{
+ NS_ASSERT (start.m_data == end.m_data);
+ NS_ASSERT (start.m_current <= end.m_current);
+ NS_ASSERT (start.m_zeroStart == end.m_zeroStart);
+ NS_ASSERT (start.m_zeroEnd == end.m_zeroEnd);
+ NS_ASSERT (m_data != start.m_data);
+ uint32_t size = end.m_current - start.m_current;
+ Iterator cur = start;
+ for (uint32_t i = 0; i < size; i++)
+ {
+ uint8_t data = cur.ReadU8 ();
+ WriteU8 (data);
+ }
+}
+
+void
+Buffer::Iterator::WriteU16 (uint16_t data)
+{
+ WriteU8 (data & 0xff);
+ data >>= 8;
+ WriteU8 (data & 0xff);
+}
+void
+Buffer::Iterator::WriteU32 (uint32_t data)
+{
+ WriteU8 (data & 0xff);
+ data >>= 8;
+ WriteU8 (data & 0xff);
+ data >>= 8;
+ WriteU8 (data & 0xff);
+ data >>= 8;
+ WriteU8 (data & 0xff);
+}
+void
+Buffer::Iterator::WriteU64 (uint64_t data)
+{
+ WriteU8 (data & 0xff);
+ data >>= 8;
+ WriteU8 (data & 0xff);
+ data >>= 8;
+ WriteU8 (data & 0xff);
+ data >>= 8;
+ WriteU8 (data & 0xff);
+ data >>= 8;
+ WriteU8 (data & 0xff);
+ data >>= 8;
+ WriteU8 (data & 0xff);
+ data >>= 8;
+ WriteU8 (data & 0xff);
+ data >>= 8;
+ WriteU8 (data & 0xff);
+}
+void
+Buffer::Iterator::WriteHtonU16 (uint16_t data)
+{
+ WriteU8 ((data >> 8) & 0xff);
+ WriteU8 ((data >> 0) & 0xff);
+}
+void
+Buffer::Iterator::WriteHtonU32 (uint32_t data)
+{
+ WriteU8 ((data >> 24) & 0xff);
+ WriteU8 ((data >> 16) & 0xff);
+ WriteU8 ((data >> 8) & 0xff);
+ WriteU8 ((data >> 0) & 0xff);
+}
+void
+Buffer::Iterator::WriteHtonU64 (uint64_t data)
+{
+ WriteU8 ((data >> 56) & 0xff);
+ WriteU8 ((data >> 48) & 0xff);
+ WriteU8 ((data >> 40) & 0xff);
+ WriteU8 ((data >> 32) & 0xff);
+ WriteU8 ((data >> 24) & 0xff);
+ WriteU8 ((data >> 16) & 0xff);
+ WriteU8 ((data >> 8) & 0xff);
+ WriteU8 ((data >> 0) & 0xff);
+}
+void
+Buffer::Iterator::Write (uint8_t const*buffer, uint32_t size)
+{
+ for (uint32_t i = 0; i < size; i++)
+ {
+ WriteU8 (buffer[i]);
+ }
+}
+
+uint16_t
+Buffer::Iterator::ReadU16 (void)
+{
+ uint8_t byte0 = ReadU8 ();
+ uint8_t byte1 = ReadU8 ();
+ uint16_t data = byte1;
+ data <<= 8;
+ data |= byte0;
+
+ return data;
+}
+uint32_t
+Buffer::Iterator::ReadU32 (void)
+{
+ uint8_t byte0 = ReadU8 ();
+ uint8_t byte1 = ReadU8 ();
+ uint8_t byte2 = ReadU8 ();
+ uint8_t byte3 = ReadU8 ();
+ uint32_t data = byte3;
+ data <<= 8;
+ data |= byte2;
+ data <<= 8;
+ data |= byte1;
+ data <<= 8;
+ data |= byte0;
+ return data;
+}
+uint64_t
+Buffer::Iterator::ReadU64 (void)
+{
+ uint8_t byte0 = ReadU8 ();
+ uint8_t byte1 = ReadU8 ();
+ uint8_t byte2 = ReadU8 ();
+ uint8_t byte3 = ReadU8 ();
+ uint8_t byte4 = ReadU8 ();
+ uint8_t byte5 = ReadU8 ();
+ uint8_t byte6 = ReadU8 ();
+ uint8_t byte7 = ReadU8 ();
+ uint32_t data = byte7;
+ data <<= 8;
+ data |= byte6;
+ data <<= 8;
+ data |= byte5;
+ data <<= 8;
+ data |= byte4;
+ data <<= 8;
+ data |= byte3;
+ data <<= 8;
+ data |= byte2;
+ data <<= 8;
+ data |= byte1;
+ data <<= 8;
+ data |= byte0;
+
+ return data;
+}
+uint16_t
+Buffer::Iterator::ReadNtohU16 (void)
+{
+ uint16_t retval = 0;
+ retval |= ReadU8 ();
+ retval <<= 8;
+ retval |= ReadU8 ();
+ return retval;
+}
+uint32_t
+Buffer::Iterator::ReadNtohU32 (void)
+{
+ uint32_t retval = 0;
+ retval |= ReadU8 ();
+ retval <<= 8;
+ retval |= ReadU8 ();
+ retval <<= 8;
+ retval |= ReadU8 ();
+ retval <<= 8;
+ retval |= ReadU8 ();
+ return retval;
+}
+uint64_t
+Buffer::Iterator::ReadNtohU64 (void)
+{
+ uint64_t retval = 0;
+ retval |= ReadU8 ();
+ retval <<= 8;
+ retval |= ReadU8 ();
+ retval <<= 8;
+ retval |= ReadU8 ();
+ retval <<= 8;
+ retval |= ReadU8 ();
+ retval <<= 8;
+ retval |= ReadU8 ();
+ retval <<= 8;
+ retval |= ReadU8 ();
+ retval <<= 8;
+ retval |= ReadU8 ();
+ retval <<= 8;
+ retval |= ReadU8 ();
+ return retval;
+}
+void
+Buffer::Iterator::Read (uint8_t *buffer, uint32_t size)
+{
+ for (uint32_t i = 0; i < size; i++)
+ {
+ buffer[i] = ReadU8 ();
+ }
+}
+
+#ifndef BUFFER_USE_INLINE
+
+void
+Buffer::Iterator::WriteU8 (uint8_t data)
+{
+ if (m_current < m_dataStart)
+ {
+ // XXX trying to write outside of data area
+ NS_ASSERT (false);
+ }
+ else if (m_current < m_zeroStart)
+ {
+ m_data[m_current] = data;
+ m_current++;
+ }
+ else if (m_current < m_zeroEnd)
+ {
+ // XXX trying to write in zero area
+ NS_ASSERT (false);
+ }
+ else if (m_current < m_dataEnd)
+ {
+ m_data[m_current - (m_zeroEnd-m_zeroStart)] = data;
+ m_current++;
+ }
+ else
+ {
+ // XXX trying to write outside of data area
+ NS_ASSERT (false);
+ }
+}
+
+void
+Buffer::Iterator::WriteU8 (uint8_t data, uint32_t len)
+{
+ for (uint32_t i = 0; i < len; i++)
+ {
+ WriteU8 (data);
+ }
+}
+
+uint8_t
+Buffer::Iterator::ReadU8 (void)
+{
+ if (m_current < m_dataStart)
+ {
+ // XXX trying to read from outside of data area
+ NS_ASSERT (false);
+ }
+ else if (m_current < m_zeroStart)
+ {
+ uint8_t data = m_data[m_current];
+ m_current++;
+ return data;
+ }
+ else if (m_current < m_zeroEnd)
+ {
+ m_current++;
+ return 0;
+ }
+ else if (m_current < m_dataEnd)
+ {
+ uint8_t data = m_data[m_current - (m_zeroEnd-m_zeroStart)];
+ m_current++;
+ return data;
+ }
+ else
+ {
+ // XXX trying to read from outside of data area
+ NS_ASSERT (false);
+ }
+ // to quiet compiler.
+ return 0;
+}
+
+#endif /* BUFFER_USE_INLINE */
+
+} // namespace ns3
#ifdef RUN_SELF_TESTS
@@ -460,6 +990,7 @@ Buffer::PeekData (void) const
#include "ns3/random-variable.h"
#include
+
namespace ns3 {
class BufferTest: public Test {
@@ -687,6 +1218,13 @@ BufferTest::RunTests (void)
i.Prev (100);
i.WriteU8 (1, 100);
+#if 0
+ buffer = Buffer (10);
+ ENSURE_WRITTEN_BYTES (buffer, 10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
+ buffer.Begin ().WriteU8 (1);
+ ENSURE_WRITTEN_BYTES (buffer, 10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
+#endif
+
// Bug #54
{
const uint32_t actualSize = 72602;
@@ -718,7 +1256,7 @@ BufferTest::RunTests (void)
static BufferTest gBufferTest;
-}; // namespace ns3
+} // namespace ns3
#endif /* RUN_SELF_TESTS */
diff --git a/src/common/buffer.h b/src/common/buffer.h
index 229a040fd..a6a8f51db 100644
--- a/src/common/buffer.h
+++ b/src/common/buffer.h
@@ -1,7 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2005,2006 INRIA
- * All rights reserved.
+ * Copyright (c) 2005,2006,2007 INRIA
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -24,6 +23,16 @@
#include
#include
+#define BUFFER_HEURISTICS 1
+#define BUFFER_USE_INLINE 1
+
+
+#ifdef BUFFER_USE_INLINE
+#define BUFFER_INLINE inline
+#else
+#define BUFFER_INLINE
+#endif
+
namespace ns3 {
/**
@@ -36,6 +45,51 @@ namespace ns3 {
* by creating new Buffers of the maximum size ever used.
* The correct maximum size is learned at runtime during use by
* recording the maximum size of each packet.
+ *
+ * \internal
+ * The implementation of the Buffer class uses a COW (Copy On Write)
+ * technique to ensure that the underlying data buffer which holds
+ * the data bytes is shared among a lot of Buffer instances despite
+ * data being added or removed from them.
+ *
+ * When multiple Buffer instances hold a reference to the same
+ * underlying BufferData object, they must be able to detect when
+ * the operation they want to perform should trigger a copy of the
+ * BufferData. If the BufferData::m_count field is one, it means that
+ * there exist only one instance of Buffer which references the
+ * BufferData instance so, it is safe to modify it. It is also
+ * safe to modify the content of a BufferData if the modification
+ * falls outside of the "dirty area" defined by the BufferData.
+ * In every other case, the BufferData must be copied before
+ * being modified.
+ *
+ * To understand the way the Buffer::Add and Buffer::Remove methods
+ * work, you first need to understand the "virtual offsets" used to
+ * keep track of the content of buffers. Each Buffer instance
+ * contains real data bytes in its BufferData instance but it also
+ * contains "virtual zero data" which typically is used to represent
+ * application-level payload. No memory is allocated to store the
+ * zero bytes of application-level payload unless the user fragments
+ * a Buffer: this application-level payload is kept track of with
+ * a pair of integers which describe where in the buffer content
+ * the "virtual zero area" starts and ends.
+ *
+ * ***: unused bytes
+ * xxx: bytes "added" at the front of the zero area
+ * ...: bytes "added" at the back of the zero area
+ * 000: virtual zero bytes
+ *
+ * Real byte buffer: |********xxxxxxxxxxxx.........*****|
+ * |--------^ m_start
+ * |-------------------^ m_zeroAreaStart
+ * |-----------------------------^ m_end - (m_zeroAreaEnd - m_zeroAreaStart)
+ * virtual byte buffer: |xxxxxxxxxxxx0000000000000.........|
+ * |--------^ m_start
+ * |--------------------^ m_zeroAreaStart
+ * |---------------------------------^ m_zeroAreaEnd
+ * |------------------------------------------^ m_end
+ *
+ * A simple state invariant is that m_start <= m_zeroStart <= m_zeroEnd <= m_end
*/
class Buffer {
public:
@@ -44,23 +98,23 @@ public:
*/
class Iterator {
public:
- inline Iterator ();
+ Iterator ();
/**
* go forward by one byte
*/
- inline void Next (void);
+ void Next (void);
/**
* go backward by one byte
*/
- inline void Prev (void);
+ void Prev (void);
/**
* \param delta number of bytes to go forward
*/
- inline void Next (uint32_t delta);
+ void Next (uint32_t delta);
/**
* \param delta number of bytes to go backward
*/
- inline void Prev (uint32_t delta);
+ void Prev (uint32_t delta);
/**
* \param o the second iterator
* \return number of bytes included between the two iterators
@@ -69,18 +123,18 @@ public:
* to the same underlying buffer. Debug builds ensure
* this with an assert.
*/
- inline int32_t GetDistanceFrom (Iterator const &o) const;
+ uint32_t GetDistanceFrom (Iterator const &o) const;
/**
* \return true if this iterator points to the end of the byte array.
* false otherwise.
*/
- inline bool IsEnd (void) const;
+ bool IsEnd (void) const;
/**
* \return true if this iterator points to the start of the byte array.
* false otherwise.
*/
- inline bool IsStart (void) const;
+ bool IsStart (void) const;
/**
* \param data data to write in buffer
@@ -88,7 +142,7 @@ public:
* Write the data in buffer and avance the iterator position
* by one byte.
*/
- inline void WriteU8 (uint8_t data);
+ BUFFER_INLINE void WriteU8 (uint8_t data);
/**
* \param data data to write in buffer
* \param len number of times data must be written in buffer
@@ -96,7 +150,7 @@ public:
* Write the data in buffer len times and avance the iterator position
* by len byte.
*/
- inline void WriteU8 (uint8_t data, uint32_t len);
+ BUFFER_INLINE void WriteU8 (uint8_t data, uint32_t len);
/**
* \param data data to write in buffer
*
@@ -106,7 +160,7 @@ public:
* return exactly what we wrote with writeU16 if the program
* is run on the same machine.
*/
- inline void WriteU16 (uint16_t data);
+ void WriteU16 (uint16_t data);
/**
* \param data data to write in buffer
*
@@ -116,7 +170,7 @@ public:
* return exactly what we wrote with writeU32 if the program
* is run on the same machine.
*/
- inline void WriteU32 (uint32_t data);
+ void WriteU32 (uint32_t data);
/**
* \param data data to write in buffer
*
@@ -126,7 +180,7 @@ public:
* return exactly what we wrote with writeU64 if the program
* is run on the same machine.
*/
- inline void WriteU64 (uint64_t data);
+ void WriteU64 (uint64_t data);
/**
* \param data data to write in buffer
*
@@ -134,7 +188,7 @@ public:
* by two bytes. The data is written in network order and the
* input data is expected to be in host order.
*/
- inline void WriteHtonU16 (uint16_t data);
+ void WriteHtonU16 (uint16_t data);
/**
* \param data data to write in buffer
*
@@ -142,7 +196,7 @@ public:
* by four bytes. The data is written in network order and the
* input data is expected to be in host order.
*/
- inline void WriteHtonU32 (uint32_t data);
+ void WriteHtonU32 (uint32_t data);
/**
* \param data data to write in buffer
*
@@ -150,7 +204,7 @@ public:
* by eight bytes. The data is written in network order and the
* input data is expected to be in host order.
*/
- inline void WriteHtonU64 (uint64_t data);
+ void WriteHtonU64 (uint64_t data);
/**
* \param buffer a byte buffer to copy in the internal buffer.
* \param size number of bytes to copy.
@@ -158,7 +212,7 @@ public:
* Write the data in buffer and avance the iterator position
* by size bytes.
*/
- inline void Write (uint8_t const*buffer, uint32_t size);
+ void Write (uint8_t const*buffer, uint32_t size);
/**
* \param start the start of the data to copy
* \param end the end of the data to copy
@@ -170,7 +224,7 @@ public:
* we do to avoid overlapping copies. This is enforced
* in debug builds by asserts.
*/
- inline void Write (Iterator start, Iterator end);
+ void Write (Iterator start, Iterator end);
/**
* \return the byte read in the buffer.
@@ -178,7 +232,7 @@ public:
* Read data and advance the Iterator by the number of bytes
* read.
*/
- inline uint8_t ReadU8 (void);
+ BUFFER_INLINE uint8_t ReadU8 (void);
/**
* \return the two bytes read in the buffer.
*
@@ -186,7 +240,7 @@ public:
* read.
* The data is read in the format written by writeU16.
*/
- inline uint16_t ReadU16 (void);
+ uint16_t ReadU16 (void);
/**
* \return the four bytes read in the buffer.
*
@@ -194,7 +248,7 @@ public:
* read.
* The data is read in the format written by writeU32.
*/
- inline uint32_t ReadU32 (void);
+ uint32_t ReadU32 (void);
/**
* \return the eight bytes read in the buffer.
*
@@ -202,7 +256,7 @@ public:
* read.
* The data is read in the format written by writeU64.
*/
- inline uint64_t ReadU64 (void);
+ uint64_t ReadU64 (void);
/**
* \return the two bytes read in the buffer.
*
@@ -210,7 +264,7 @@ public:
* read.
* The data is read in network format and return in host format.
*/
- inline uint16_t ReadNtohU16 (void);
+ uint16_t ReadNtohU16 (void);
/**
* \return the four bytes read in the buffer.
*
@@ -218,7 +272,7 @@ public:
* read.
* The data is read in network format and return in host format.
*/
- inline uint32_t ReadNtohU32 (void);
+ uint32_t ReadNtohU32 (void);
/**
* \return the eight bytes read in the buffer.
*
@@ -226,7 +280,7 @@ public:
* read.
* The data is read in network format and return in host format.
*/
- inline uint64_t ReadNtohU64 (void);
+ uint64_t ReadNtohU64 (void);
/**
* \param buffer buffer to copy data into
* \param size number of bytes to copy
@@ -235,22 +289,45 @@ public:
* input buffer and avance the Iterator by the number of
* bytes read.
*/
- inline void Read (uint8_t *buffer, uint16_t size);
+ void Read (uint8_t *buffer, uint32_t size);
private:
friend class Buffer;
- inline Iterator (Buffer const*buffer, uint32_t m_current);
- inline uint32_t GetIndex (uint32_t n);
+ Iterator (Buffer const*buffer);
+ Iterator (Buffer const*buffer, bool);
+ void Construct (const Buffer *buffer);
+ bool CheckNoZero (uint32_t start, uint32_t end) const;
+ bool Check (uint32_t i) const;
+
+ /* offset in virtual bytes from the start of the data buffer to the
+ * start of the "virtual zero area".
+ */
uint32_t m_zeroStart;
+ /* offset in virtual bytes from the start of the data buffer to the
+ * end of the "virtual zero area".
+ */
uint32_t m_zeroEnd;
+ /* offset in virtual bytes from the start of the data buffer to the
+ * start of the data which can be read by this iterator
+ */
+ uint32_t m_dataStart;
+ /* offset in virtual bytes from the start of the data buffer to the
+ * end of the data which can be read by this iterator
+ */
uint32_t m_dataEnd;
+ /* offset in virtual bytes from the start of the data buffer to the
+ * current position represented by this iterator.
+ */
uint32_t m_current;
+ /* a pointer to the underlying byte buffer. All offsets are relative
+ * to this pointer.
+ */
uint8_t *m_data;
};
/**
* \return the number of bytes stored in this buffer.
*/
- inline uint32_t GetSize (void) const;
+ uint32_t GetSize (void) const;
/**
* \return a pointer to the start of the internal
@@ -313,401 +390,135 @@ public:
* \return an Iterator which points to the
* start of this Buffer.
*/
- inline Buffer::Iterator Begin (void) const;
+ Buffer::Iterator Begin (void) const;
/**
* \return an Iterator which points to the
* end of this Buffer.
*/
- inline Buffer::Iterator End (void) const;
+ Buffer::Iterator End (void) const;
Buffer CreateFullCopy (void) const;
- inline Buffer (Buffer const &o);
- inline Buffer &operator = (Buffer const &o);
- inline Buffer ();
- inline Buffer (uint32_t dataSize);
- inline ~Buffer ();
+ Buffer (Buffer const &o);
+ Buffer &operator = (Buffer const &o);
+ Buffer ();
+ Buffer (uint32_t dataSize);
+ ~Buffer ();
private:
- struct BufferData {
- uint32_t m_count;
- uint32_t m_size;
- uint32_t m_initialStart;
- uint32_t m_dirtyStart;
- uint32_t m_dirtySize;
- uint8_t m_data[1];
- };
- class BufferDataList : public std::vector
- {
- public:
- ~BufferDataList ();
- };
- inline uint8_t *GetStart (void) const;
void TransformIntoRealBuffer (void) const;
- static void Recycle (struct Buffer::BufferData *data);
- static struct Buffer::BufferData *Create (void);
- static struct Buffer::BufferData *Allocate (uint32_t size, uint32_t start);
- static void Deallocate (struct Buffer::BufferData *data);
-
- static BufferDataList m_freeList;
- static uint32_t m_maxTotalAddStart;
- static uint32_t m_maxTotalAddEnd;
+ bool CheckInternalState (void) const;
+ void Initialize (uint32_t zeroSize);
+ uint32_t GetInternalSize (void) const;
+ uint32_t GetInternalEnd (void) const;
+ static void Recycle (struct BufferData *data);
+ static struct BufferData *Create (uint32_t size);
+ /* This structure is described in the buffer.cc file.
+ */
struct BufferData *m_data;
- uint32_t m_zeroAreaSize;
+#ifdef BUFFER_HEURISTICS
+ /* keep track of the maximum value of m_zeroAreaStart across
+ * the lifetime of a Buffer instance. This variable is used
+ * purely as a source of information for the heuristics which
+ * decide on the position of the zero area in new buffers.
+ * It is read from the Buffer destructor to update the global
+ * heuristic data and these global heuristic data are used from
+ * the Buffer constructor to choose an initial value for
+ * m_zeroAreaStart.
+ * It is possible to disable all these heuristics by undefining the
+ * BUFFER_HEURISTICS macro at the top of buffer.h
+ */
+ uint32_t m_maxZeroAreaStart;
+#endif /* BUFFER_HEURISTICS */
+ /* offset to the start of the virtual zero area from the start
+ * of m_data->m_data
+ */
+ uint32_t m_zeroAreaStart;
+ /* offset to the end of the virtual zero area from the start
+ * of m_data->m_data
+ */
+ uint32_t m_zeroAreaEnd;
+ /* offset to the start of the data referenced by this Buffer
+ * instance from the start of m_data->m_data
+ */
uint32_t m_start;
- uint32_t m_size;
+ /* offset to the end of the data referenced by this Buffer
+ * instance from the start of m_data->m_data
+ */
+ uint32_t m_end;
};
-}; // namespace ns3
+} // namespace ns3
-
-/**************************************************
- Start of implementation of methods which
- need to be inline for performance reasons.
- *************************************************/
+#ifdef BUFFER_USE_INLINE
#include "ns3/assert.h"
namespace ns3 {
-Buffer::Buffer ()
- : m_data (Buffer::Create ()),
- m_zeroAreaSize (0),
- m_start (m_maxTotalAddStart),
- m_size (0)
+void
+Buffer::Iterator::WriteU8 (uint8_t data)
{
- if (m_start > m_data->m_size)
+ NS_ASSERT (Check (m_current));
+
+ if (m_current < m_zeroStart)
{
- m_start = 0;
+ m_data[m_current] = data;
+ m_current++;
}
- NS_ASSERT (m_start <= m_data->m_size);
-}
-
-Buffer::Buffer (uint32_t dataSize)
- : m_data (Buffer::Create ()),
- m_zeroAreaSize (dataSize),
- m_start (m_maxTotalAddStart),
- m_size (0)
-{
- if (m_start > m_data->m_size)
+ else
{
- m_start = 0;
+ m_data[m_current - (m_zeroEnd-m_zeroStart)] = data;
+ m_current++;
}
- NS_ASSERT (m_start <= m_data->m_size);
-}
-
-
-Buffer::Buffer (Buffer const&o)
- : m_data (o.m_data),
- m_zeroAreaSize (o.m_zeroAreaSize),
- m_start (o.m_start),
- m_size (o.m_size)
-{
- m_data->m_count++;
- NS_ASSERT (m_start <= m_data->m_size);
-}
-
-Buffer &
-Buffer::operator = (Buffer const&o)
-{
- if (m_data != o.m_data)
- {
- // not assignment to self.
- m_data->m_count--;
- if (m_data->m_count == 0)
- {
- Recycle (m_data);
- }
- m_data = o.m_data;
- m_data->m_count++;
- }
- m_zeroAreaSize = o.m_zeroAreaSize;
- m_start = o.m_start;
- m_size = o.m_size;
- NS_ASSERT (m_start <= m_data->m_size);
- return *this;
-}
-
-Buffer::~Buffer ()
-{
- m_data->m_count--;
- if (m_data->m_count == 0)
- {
- Recycle (m_data);
- }
-}
-
-
-uint8_t *
-Buffer::GetStart (void) const
-{
- return m_data->m_data + m_start;
-}
-
-uint32_t
-Buffer::GetSize (void) const
-{
- return m_size + m_zeroAreaSize;
-}
-
-Buffer::Iterator
-Buffer::Begin (void) const
-{
- return Buffer::Iterator (this, 0);
-}
-Buffer::Iterator
-Buffer::End (void) const
-{
- return Buffer::Iterator (this, GetSize ());
-}
-
-
-Buffer::Iterator::Iterator ()
- : m_zeroStart (0),
- m_zeroEnd (0),
- m_dataEnd (0),
- m_current (0),
- m_data (0)
-{}
-Buffer::Iterator::Iterator (Buffer const*buffer, uint32_t current)
- : m_zeroStart (buffer->m_data->m_initialStart-buffer->m_start),
- m_zeroEnd (m_zeroStart+buffer->m_zeroAreaSize),
- m_dataEnd (buffer->GetSize ()),
- m_current (current),
- m_data (buffer->m_data->m_data+buffer->m_start)
-{}
-
-void
-Buffer::Iterator::Next (void)
-{
- NS_ASSERT (m_current + 1 <= m_dataEnd);
- m_current++;
-}
-void
-Buffer::Iterator::Prev (void)
-{
- NS_ASSERT (m_current >= 1);
- m_current--;
-}
-void
-Buffer::Iterator::Next (uint32_t delta)
-{
- NS_ASSERT (m_current + delta <= m_dataEnd);
- m_current += delta;
-}
-void
-Buffer::Iterator::Prev (uint32_t delta)
-{
- NS_ASSERT (m_current >= delta);
- m_current -= delta;
-}
-int32_t
-Buffer::Iterator::GetDistanceFrom (Iterator const &o) const
-{
- NS_ASSERT (m_data == o.m_data);
- int32_t start = m_current;
- int32_t end = o.m_current;
- return end - start;
-}
-
-bool
-Buffer::Iterator::IsEnd (void) const
-{
- return m_current == m_dataEnd;
-}
-bool
-Buffer::Iterator::IsStart (void) const
-{
- return m_current == 0;
-}
-
-uint32_t
-Buffer::Iterator::GetIndex (uint32_t n)
-{
- NS_ASSERT (
- (m_current + n <= m_dataEnd) &&
- ((m_current + n <= m_zeroStart) ||
- (m_current >= m_zeroEnd) ||
- m_zeroStart == m_zeroEnd)
- );
- uint32_t index;
- if (m_current < m_zeroStart)
- {
- index = m_current;
- }
- else
- {
- index = m_current - (m_zeroEnd-m_zeroStart);
- }
- return index;
-}
-
-
-void
-Buffer::Iterator::Write (Iterator start, Iterator end)
-{
- NS_ASSERT (start.m_data == end.m_data);
- NS_ASSERT (start.m_current <= end.m_current);
- NS_ASSERT (start.m_zeroStart == end.m_zeroStart);
- NS_ASSERT (start.m_zeroEnd == end.m_zeroEnd);
- 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);
- memcpy (dest, src, size);
- m_current += size;
}
void
Buffer::Iterator::WriteU8 (uint8_t data, uint32_t len)
{
- uint8_t *current = m_data + GetIndex (len);
- memset (current, data, len);
- m_current += len;
-}
-void
-Buffer::Iterator::WriteU8 (uint8_t data)
-{
- m_data[GetIndex (1)] = data;
- m_current++;
-}
-void
-Buffer::Iterator::WriteU16 (uint16_t data)
-{
- uint16_t *buffer = (uint16_t *)(m_data + GetIndex (2));
- *buffer = data;
- m_current += 2;
-}
-void
-Buffer::Iterator::WriteU32 (uint32_t data)
-{
- uint32_t *buffer = (uint32_t *)(m_data + GetIndex (4));
- *buffer = data;
- m_current += 4;
-}
-void
-Buffer::Iterator::WriteU64 (uint64_t data)
-{
- uint64_t *buffer = (uint64_t *)(m_data + GetIndex (8));
- *buffer = data;
- m_current += 8;
-}
-void
-Buffer::Iterator::WriteHtonU16 (uint16_t data)
-{
- uint8_t *current = m_data + GetIndex (2);
- *(current+0) = (data >> 8) & 0xff;
- *(current+1) = (data >> 0) & 0xff;
- m_current += 2;
-}
-void
-Buffer::Iterator::WriteHtonU32 (uint32_t data)
-{
- uint8_t *current = m_data + GetIndex (4);
- *(current+0) = (data >> 24) & 0xff;
- *(current+1) = (data >> 16) & 0xff;
- *(current+2) = (data >> 8) & 0xff;
- *(current+3) = (data >> 0) & 0xff;
- m_current += 4;
-}
-void
-Buffer::Iterator::WriteHtonU64 (uint64_t data)
-{
- uint8_t *current = m_data + GetIndex (8);
- *(current+0) = (data >> 56) & 0xff;
- *(current+1) = (data >> 48) & 0xff;
- *(current+2) = (data >> 40) & 0xff;
- *(current+3) = (data >> 32) & 0xff;
- *(current+4) = (data >> 24) & 0xff;
- *(current+5) = (data >> 16) & 0xff;
- *(current+6) = (data >> 8) & 0xff;
- *(current+7) = (data >> 0) & 0xff;
- m_current += 8;
-}
-void
-Buffer::Iterator::Write (uint8_t const*buffer, uint32_t size)
-{
- uint8_t *current = m_data + GetIndex (size);
- memcpy (current, buffer, size);
- m_current += size;
+ NS_ASSERT (CheckNoZero (m_current, m_current + len));
+ if (m_current <= m_zeroStart)
+ {
+ memset (&(m_data[m_current]), data, len);
+ m_current += len;
+ }
+ else
+ {
+ uint8_t *buffer = &m_data[m_current - (m_zeroEnd-m_zeroStart)];
+ memset (buffer, data, len);
+ m_current += len;
+ }
}
uint8_t
Buffer::Iterator::ReadU8 (void)
{
- uint8_t data = m_data[GetIndex(1)];
- m_current++;
- return data;
-}
-uint16_t
-Buffer::Iterator::ReadU16 (void)
-{
- uint16_t *buffer = reinterpret_cast(m_data + GetIndex (2));
- m_current += 2;
- return *buffer;
-}
-uint32_t
-Buffer::Iterator::ReadU32 (void)
-{
- uint32_t *buffer = reinterpret_cast(m_data + GetIndex (4));
- m_current += 4;
- return *buffer;
-}
-uint64_t
-Buffer::Iterator::ReadU64 (void)
-{
- uint64_t *buffer = reinterpret_cast(m_data + GetIndex (8));
- m_current += 8;
- return *buffer;
-}
-uint16_t
-Buffer::Iterator::ReadNtohU16 (void)
-{
- uint8_t *current = m_data + GetIndex (2);
- uint16_t retval = 0;
- retval |= static_cast