diff --git a/doc/tutorial/source/building-topologies.rst b/doc/tutorial/source/building-topologies.rst
index 87a423eaa..aea9e9c98 100644
--- a/doc/tutorial/source/building-topologies.rst
+++ b/doc/tutorial/source/building-topologies.rst
@@ -1,6 +1,8 @@
.. include:: replace.txt
.. highlight:: cpp
+.. _BuildingTopologies:
+
Building Topologies
-------------------
diff --git a/doc/tutorial/source/data-collection.rst b/doc/tutorial/source/data-collection.rst
index 793115db9..1f646de07 100644
--- a/doc/tutorial/source/data-collection.rst
+++ b/doc/tutorial/source/data-collection.rst
@@ -178,6 +178,8 @@ by hooking the data collection components to |ns3| trace sources, and
marshaling the data into a formatted ``gnuplot`` and into a formatted
text file. In the next sections, we'll review each of these.
+.. _GnuPlotHelper:
+
GnuplotHelper
*************
diff --git a/doc/tutorial/source/tracing.rst b/doc/tutorial/source/tracing.rst
index b21a57170..627648474 100644
--- a/doc/tutorial/source/tracing.rst
+++ b/doc/tutorial/source/tracing.rst
@@ -3,15 +3,24 @@
.. role:: raw-role(raw)
:format: html latex
+.. Mimic doxygen formatting for parameter names
+
+.. raw:: html
+
+
+
+.. role:: param
+
+
Tracing
-------
Background
**********
-As mentioned in the Using the Tracing System section, the whole point
+As mentioned in :ref:`UsingTracingSystem`, the whole point
of running an |ns3| simulation is to generate output for study. You
-have two basic strategies to work with in |ns3|: using generic
+have two basic strategies to obtain output from |ns3|: using generic
pre-defined bulk output mechanisms and parsing their content to
extract interesting information; or somehow developing an output
mechanism that conveys exactly (and perhaps only) the information
@@ -19,13 +28,17 @@ wanted.
Using pre-defined bulk output mechanisms has the advantage of not
requiring any changes to |ns3|, but it may require writing scripts to
-parse and filter for data of interest. Often, pcap or NS_LOG output
-messages are gathered during simulation runs and separately run
-through scripts that use grep, sed or awk to parse the messages and
-reduce and transform the data to a manageable form. Programs must be
-written to do the transformation, so this does not come for free. Of
-course, if the information of interest does not exist in any of the
-pre-defined output mechanisms, this approach fails.
+parse and filter for data of interest. Often, PCAP or ``NS_LOG``
+output messages are gathered during simulation runs and separately run
+through scripts that use ``grep``, ``sed`` or ``awk`` to parse the
+messages and reduce and transform the data to a manageable form.
+Programs must be written to do the transformation, so this does not
+come for free. ``NS_LOG`` output is not considered part of the |ns3|
+API, and can change without warning between releases. In addition,
+``NS_LOG`` output is only available in debug builds, so relying on it
+imposes a performance penalty. Of course, if the information of
+interest does not exist in any of the pre-defined output mechanisms,
+this approach fails.
If you need to add some tidbit of information to the pre-defined bulk
mechanisms, this can certainly be done; and if you use one of the
@@ -38,12 +51,13 @@ have to manage by only tracing the events of interest to you (for
large simulations, dumping everything to disk for post-processing can
create I/O bottlenecks). Second, if you use this method, you can
control the format of the output directly so you avoid the
-postprocessing step with sed or awk script. If you desire, your
-output can be formatted directly into a form acceptable by gnuplot,
-for example. You can add hooks in the core which can then be accessed
-by other users, but which will produce no information unless
-explicitly asked to do so. For these reasons, we believe that the
-|ns3| tracing system is the best way to get information out of a
+postprocessing step with ``sed``, ``awk``, ``perl`` or ``python``
+scripts. If you desire, your output can be formatted directly into a
+form acceptable by gnuplot, for example (see also
+:ref:`GnuplotHelper`). You can add hooks in the core which can then
+be accessed by other users, but which will produce no information
+unless explicitly asked to do so. For these reasons, we believe that
+the |ns3| tracing system is the best way to get information out of a
simulation and is also therefore one of the most important mechanisms
to understand in |ns3|.
@@ -51,7 +65,7 @@ Blunt Instruments
+++++++++++++++++
There are many ways to get information out of a program. The most
-straightforward way is to just directly print the information to the
+straightforward way is to just print the information directly to the
standard output, as in::
#include
@@ -74,15 +88,15 @@ though.
As the number of print statements increases in your programs, the task
of dealing with the large number of outputs will become more and more
complicated. Eventually, you may feel the need to control what
-information is being printed in some way; perhaps by turning on and
+information is being printed in some way, perhaps by turning on and
off certain categories of prints, or increasing or decreasing the
amount of information you want. If you continue down this path you
-may discover that you have re-implemented the ``NS_LOG`` mechanism.
-In order to avoid that, one of the first things you might consider is
-using ``NS_LOG`` itself.
+may discover that you have re-implemented the ``NS_LOG`` mechanism
+(see :ref:`UsingLogging`). In order to avoid that, one of the first
+things you might consider is using ``NS_LOG`` itself.
We mentioned above that one way to get information out of |ns3| is to
-parse existing NS_LOG output for interesting information. If you
+parse existing ``NS_LOG`` output for interesting information. If you
discover that some tidbit of information you need is not present in
existing log output, you could edit the core of |ns3| and simply add
your interesting information to the output stream. Now, this is
@@ -93,8 +107,8 @@ other people as a patch to the existing core.
Let's pick a random example. If you wanted to add more logging to the
|ns3| TCP socket (``tcp-socket-base.cc``) you could just add a new
message down in the implementation. Notice that in
-TcpSocketBase::ReceivedAck() there is no log message for the no ACK
-case. You could simply add one, changing the code from::
+``TcpSocketBase::ReceivedAck()`` there is no log message for the no ACK
+case. You could simply add one, changing the code. Here is the original::
/** Process the newly received ACK */
void
@@ -108,7 +122,8 @@ case. You could simply add one, changing the code from::
}
...
-to add a new ``NS_LOG_LOGIC`` in the appropriate statement::
+To log the no ACK case, you can add a new ``NS_LOG_LOGIC`` in the
+``if`` statement body::
/** Process the newly received ACK */
void
@@ -124,12 +139,13 @@ to add a new ``NS_LOG_LOGIC`` in the appropriate statement::
...
This may seem fairly simple and satisfying at first glance, but
-something to consider is that you will be writing code to add the
-``NS_LOG`` statement and you will also have to write code (as in grep,
-sed or awk scripts) to parse the log output in order to isolate your
-information. This is because even though you have some control over
-what is output by the logging system, you only have control down to
-the log component level.
+something to consider is that you will be writing code to add
+``NS_LOG`` statements and you will also have to write code (as in
+``grep``, ``sed`` or ``awk`` scripts) to parse the log output in order
+to isolate your information. This is because even though you have
+some control over what is output by the logging system, you only have
+control down to the log component level, which is typically an entire
+source code file.
If you are adding code to an existing module, you will also have to
live with the output that every other developer has found interesting.
@@ -140,32 +156,36 @@ files to disk and process them down to a few lines whenever you want
to do anything.
Since there are no guarantees in |ns3| about the stability of
-``NS_LOG`` output, you may also discover that pieces of log output on
-which you depend disappear or change between releases. If you depend
+``NS_LOG`` output, you may also discover that pieces of log output
+which you depend on disappear or change between releases. If you depend
on the structure of the output, you may find other messages being
added or deleted which may affect your parsing code.
-For these reasons, we consider prints to ``std::cout`` and NS_LOG
+Finally, ``NS_LOG`` output is only available in debug builds, you
+can't get log output from optimized builds, which run about twice as
+fast. Relying on ``NS_LOG`` imposes a performance penalty.
+
+For these reasons, we consider prints to ``std::cout`` and ``NS_LOG``
messages to be quick and dirty ways to get more information out of
-|ns3|.
+|ns3|, but not suitable for serious work.
It is desirable to have a stable facility using stable APIs that allow
one to reach into the core system and only get the information
required. It is desirable to be able to do this without having to
change and recompile the core system. Even better would be a system
-that notified the user when an item of interest changed or an
+that notified user code when an item of interest changed or an
interesting event happened so the user doesn't have to actively poke
around in the system looking for things.
The |ns3| tracing system is designed to work along those lines and is
-well-integrated with the Attribute and Config subsystems allowing for
-relatively simple use scenarios.
+well-integrated with the :ref:`Attribute ` and :ref:`Config
+` subsystems allowing for relatively simple use scenarios.
Overview
********
-The ns-3 tracing system is built on the concepts of independent
-tracing sources and tracing sinks; along with a uniform mechanism for
+The |ns3| tracing system is built on the concepts of independent
+tracing sources and tracing sinks, along with a uniform mechanism for
connecting sources to sinks.
Trace sources are entities that can signal events that happen in a
@@ -174,15 +194,18 @@ example, a trace source could indicate when a packet is received by a
net device and provide access to the packet contents for interested
trace sinks. A trace source might also indicate when an interesting
state change happens in a model. For example, the congestion window
-of a TCP model is a prime candidate for a trace source.
+of a TCP model is a prime candidate for a trace source. Every time
+the congestion window changes connected trace sinks are notified with
+the old and new value.
Trace sources are not useful by themselves; they must be connected to
other pieces of code that actually do something useful with the
information provided by the source. The entities that consume trace
information are called trace sinks. Trace sources are generators of
-events and trace sinks are consumers. This explicit division allows
+data and trace sinks are consumers. This explicit division allows
for large numbers of trace sources to be scattered around the system
-in places which model authors believe might be useful.
+in places which model authors believe might be useful. Inserting
+trace sources introduces a very small execution overhead.
There can be zero or more consumers of trace events generated by a
trace source. One can think of a trace source as a kind of
@@ -192,16 +215,17 @@ other code doing something entirely different from the same
information.
Unless a user connects a trace sink to one of these sources, nothing
-is output. By using the tracing system, both you and other people at
-the same trace source are getting exactly what they want and only what
-they want out of the system. Neither of you are impacting any other
-user by changing what information is output by the system. If you
-happen to add a trace source, your work as a good open-source citizen
-may allow other users to provide new utilities that are perhaps very
-useful overall, without making any changes to the |ns3| core.
+is output. By using the tracing system, both you and other people
+hooked to the same trace source are getting exactly what they want and
+only what they want out of the system. Neither of you are impacting
+any other user by changing what information is output by the system.
+If you happen to add a trace source, your work as a good open-source
+citizen may allow other users to provide new utilities that are
+perhaps very useful overall, without making any changes to the |ns3|
+core.
-A Simple Low-Level Example
-++++++++++++++++++++++++++
+Simple Example
+++++++++++++++
Let's take a few minutes and walk through a simple tracing example.
We are going to need a little background on Callbacks to understand
@@ -216,24 +240,24 @@ to call a function (or method in C++) without any specific
inter-module dependency. This ultimately means you need some kind of
indirection -- you treat the address of the called function as a
variable. This variable is called a pointer-to-function variable.
-The relationship between function and pointer-to-function pointer is
+The relationship between function and pointer-to-function is
really no different that that of object and pointer-to-object.
In C the canonical example of a pointer-to-function is a
-pointer-to-function-returning-integer (PFI). For a PFI taking one int
+pointer-to-function-returning-integer (PFI). For a PFI taking one ``int``
parameter, this could be declared like,
::
int (*pfi)(int arg) = 0;
-What you get from this is a variable named simply "pfi" that is
-initialized to the value 0. If you want to initialize this pointer to
-something meaningful, you have to have a function with a matching
-signature. In this case, you could provide a function that looks
-like,
-
-::
+(But read the `C++-FAQ Section 33
+`_ before
+writing code like this!) What you get from this is a variable named
+simply ``pfi`` that is initialized to the value 0. If you want to
+initialize this pointer to something meaningful, you have to have a
+function with a matching signature. In this case, you could provide a
+function that looks like::
int MyFunction (int arg) {}
@@ -243,54 +267,49 @@ your function::
pfi = MyFunction;
You can then call MyFunction indirectly using the more suggestive form
-of the call,
-
-::
+of the call::
int result = (*pfi) (1234);
This is suggestive since it looks like you are dereferencing the
function pointer just like you would dereference any pointer.
Typically, however, people take advantage of the fact that the
-compiler knows what is going on and will just use a shorter form,
-
-::
+compiler knows what is going on and will just use a shorter form::
int result = pfi (1234);
-This looks like you are calling a function named "pfi," but the
+This looks like you are calling a function named ``pfi``, but the
compiler is smart enough to know to call through the variable ``pfi``
indirectly to the function ``MyFunction``.
-Conceptually, this is almost exactly how the tracing system will work.
-Basically, a trace source *is* a callback. When a trace sink
-expresses interest in receiving trace events, it adds a Callback to a
+Conceptually, this is almost exactly how the tracing system works.
+Basically, a trace sink *is* a callback. When a trace sink expresses
+interest in receiving trace events, it adds itself as a Callback to a
list of Callbacks internally held by the trace source. When an
-interesting event happens, the trace source invokes its ``operator()``
-providing zero or more parameters. The ``operator()`` eventually
-wanders down into the system and does something remarkably like the
-indirect call you just saw. It provides zero or more parameters (the
-call to "pfi" above passed one parameter to the target function
-``MyFunction``).
+interesting event happens, the trace source invokes its
+``operator(...)`` providing zero or more arguments. The
+``operator(...)`` eventually wanders down into the system and does
+something remarkably like the indirect call you just saw, providing
+zero or more parameters, just as the call to ``pfi`` above passed one
+parameter to the target function ``MyFunction``.
The important difference that the tracing system adds is that for each
trace source there is an internal list of Callbacks. Instead of just
-making one indirect call, a trace source may invoke multiple. When a
-trace sink expresses interest in notifications from a trace source, it
-basically just arranges to add its own function to the callback list.
+making one indirect call, a trace source may invoke multiple
+Callbacks. When a trace sink expresses interest in notifications from
+a trace source, it basically just arranges to add its own function to
+the callback list.
If you are interested in more details about how this is actually
arranged in |ns3|, feel free to peruse the Callback section of the
-manual.
+|ns3| Manual.
-Example Code
-~~~~~~~~~~~~
+Walkthrough: ``fourth.cc``
+~~~~~~~~~~~~~~~~~~~~~~~~~~
We have provided some code to implement what is really the simplest
example of tracing that can be assembled. You can find this code in
-the tutorial directory as ``fourth.cc``. Let's walk through it.
-
-::
+the tutorial directory as ``fourth.cc``. Let's walk through it::
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
@@ -321,21 +340,16 @@ Most of this code should be quite familiar to you. As mentioned
above, the trace system makes heavy use of the Object and Attribute
systems, so you will need to include them. The first two includes
above bring in the declarations for those systems explicitly. You
-could use the core module header, but this illustrates how simple this
-all really is.
+could use the core module header to get everything at once, but we do
+the includes explicitly here to illustrate how simple this all really
+is.
The file, ``traced-value.h`` brings in the required declarations for
tracing of data that obeys value semantics. In general, value
semantics just means that you can pass the object itself around,
-rather than passing the address of the object. In order to use value
-semantics at all you have to have an object with an associated copy
-constructor and assignment operator available. We extend the
-requirements to talk about the set of operators that are pre-defined
-for plain-old-data (POD) types. Operator=, operator++, operator---,
-operator+, operator==, etc.
-
-What this all really means is that you will be able to trace changes
-to a C++ object made using those operators.
+rather than passing the address of the object. What this all really
+means is that you will be able to trace all changes made to a
+TracedValue in a really simple way.
Since the tracing system is integrated with Attributes, and Attributes
work with Objects, there must be an |ns3| ``Object`` for the trace
@@ -354,7 +368,8 @@ simple Object we can work with.
.AddConstructor ()
.AddTraceSource ("MyInteger",
"An integer value to trace.",
- MakeTraceSourceAccessor (&MyObject::m_myInt))
+ MakeTraceSourceAccessor (&MyObject::m_myInt),
+ "ns3::Traced::Value::Int32Callback")
;
return tid;
}
@@ -368,27 +383,45 @@ the ``.AddTraceSource`` and the ``TracedValue`` declaration of
``m_myInt``.
The ``.AddTraceSource`` provides the "hooks" used for connecting the
-trace source to the outside world through the config system. The
-``TracedValue`` declaration provides the infrastructure that overloads
-the operators mentioned above and drives the callback process.
+trace source to the outside world through the Config system. The
+first argument is a name for this trace source, which makes it
+visible in the Config system. The second argument is a help string.
+Now look at the third argument, in fact focus on the *argument* of
+the third argument: ``&MyObject::m_myInt``. This is the TracedValue
+which is being added to the class; it is always a class data member.
+(The final argument is the name of a ``typedef`` for the TracedValue
+type, as a string. This is used to generate documentation for the
+correct Callback function signature, which is useful especially
+for more general types of Callbacks.)
+
+The ``TracedValue<>`` declaration provides the infrastructure that
+drives the callback process. Any time the underlying value is changed
+the TracedValue mechanism will provide both the old and the new value
+of that variable, in this case an ``int32_t`` value. The trace
+sink function for this TracedValue will need the signature
::
+ void (* TracedValueCallback)(const int32_t oldValue, const int32_t newValue);
+
+All trace sinks hooking this trace source must have this signature.
+We'll discuss below how you can determine the required callback
+signature in other cases.
+
+Sure enough, continuing through ``fourth.cc`` we see::
+
void
IntTrace (int32_t oldValue, int32_t newValue)
{
std::cout << "Traced " << oldValue << " to " << newValue << std::endl;
}
-This is the definition of the trace sink. It corresponds directly to
-a callback function. Once it is connected, this function will be
-called whenever one of the overloaded operators of the ``TracedValue``
-is executed.
+This is the definition of a matching trace sink. It corresponds
+directly to the callback function signature. Once it is connected,
+this function will be called whenever the ``TracedValue`` changes.
We have now seen the trace source and the trace sink. What remains is
-code to connect the source to the sink.
-
-::
+code to connect the source to the sink, which happens in ``main``::
int
main (int argc, char *argv[])
@@ -399,41 +432,41 @@ code to connect the source to the sink.
myObject->m_myInt = 1234;
}
-Here we first create the Object in which the trace source lives.
+Here we first create the MyObject instance in which the trace source
+lives.
The next step, the ``TraceConnectWithoutContext``, forms the
-connection between the trace source and the trace sink. Notice the
-``MakeCallback`` template function. This function does the magic
-required to create the underlying |ns3| Callback object and associate
-it with the function ``IntTrace``. TraceConnect makes the association
-between your provided function and the overloaded ``operator()`` in
-the traced variable referred to by the "MyInteger" Attribute. After
-this association is made, the trace source will "fire" your provided
-callback function.
+connection between the trace source and the trace sink. The first
+argument is just the trace source name "MyInteger" we saw above.
+Notice the ``MakeCallback`` template function. This function does the
+magic required to create the underlying |ns3| Callback object and
+associate it with the function ``IntTrace``. ``TraceConnect`` makes
+the association between your provided function and overloaded
+``operator()`` in the traced variable referred to by the "MyInteger"
+Attribute. After this association is made, the trace source will
+"fire" your provided callback function.
The code to make all of this happen is, of course, non-trivial, but
the essence is that you are arranging for something that looks just
like the ``pfi()`` example above to be called by the trace source.
The declaration of the ``TracedValue m_myInt;`` in the Object
-itself performs the magic needed to provide the overloaded operators
-(++, ---, etc.) that will use the ``operator()`` to actually invoke
-the Callback with the desired parameters. The ``.AddTraceSource``
+itself performs the magic needed to provide the overloaded assignment
+operators that will use the ``operator()`` to actually invoke the
+Callback with the desired parameters. The ``.AddTraceSource``
performs the magic to connect the Callback to the Config system, and
``TraceConnectWithoutContext`` performs the magic to connect your
function to the trace source, which is specified by Attribute name.
Let's ignore the bit about context for now.
-Finally, the line,
-
-::
+Finally, the line assigning a value to ``m_myInt``::
myObject->m_myInt = 1234;
should be interpreted as an invocation of ``operator=`` on the member
variable ``m_myInt`` with the integer ``1234`` passed as a parameter.
-It turns out that this operator is defined (by ``TracedValue``) to
+Since ``m_myInt`` is a ``TracedValue``, this operator is defined to
execute a callback that returns void and takes two integer values as
parameters --- an old value and a new value for the integer in
question. That is exactly the function signature for the callback
@@ -444,7 +477,7 @@ list of callbacks. A trace sink is a function used as the target of a
callback. The Attribute and object type information systems are used
to provide a way to connect trace sources to trace sinks. The act of
"hitting" a trace source is executing an operator on the trace source
-which fires callbacks. This results in the trace sink callbacks
+which fires callbacks. This results in the trace sink callbacks who
registering interest in the source being called with the parameters
provided by the source.
@@ -466,21 +499,21 @@ source fired and automatically provided the before and after values to
the trace sink. The function ``IntTrace`` then printed this to the
standard output.
-Using the Config Subsystem to Connect to Trace Sources
-++++++++++++++++++++++++++++++++++++++++++++++++++++++
+.. _Config:
+
+Connect with Config
++++++++++++++++++++
The ``TraceConnectWithoutContext`` call shown above in the simple
example is actually very rarely used in the system. More typically,
-the ``Config`` subsystem is used to allow selecting a trace source in
-the system using what is called a *config path*. We saw an example of
+the ``Config`` subsystem is used to select a trace source in the
+system using what is called a *Config path*. We saw an example of
this in the previous section where we hooked the "CourseChange" event
when we were experimenting with ``third.cc``.
Recall that we defined a trace sink to print course change information
from the mobility models of our simulation. It should now be a lot
-more clear to you what this function is doing.
-
-::
+more clear to you what this function is doing::
void
CourseChange (std::string context, Ptr model)
@@ -491,21 +524,21 @@ more clear to you what this function is doing.
}
When we connected the "CourseChange" trace source to the above trace
-sink, we used what is called a "Config Path" to specify the source
-when we arranged a connection between the pre-defined trace source and
-the new trace sink::
+sink, we used a Config path to specify the source when we arranged a
+connection between the pre-defined trace source and the new trace
+sink::
std::ostringstream oss;
- oss <<
- "/NodeList/" << wifiStaNodes.Get (nWifi - 1)->GetId () <<
- "/$ns3::MobilityModel/CourseChange";
+ oss << "/NodeList/"
+ << wifiStaNodes.Get (nWifi - 1)->GetId ()
+ << "/$ns3::MobilityModel/CourseChange";
Config::Connect (oss.str (), MakeCallback (&CourseChange));
Let's try and make some sense of what is sometimes considered
relatively mysterious code. For the purposes of discussion, assume
-that the node number returned by the ``GetId()`` is "7". In this
-case, the path above turns out to be,
+that the Node number returned by the ``GetId()`` is "7". In this
+case, the path above turns out to be
::
@@ -515,30 +548,28 @@ The last segment of a config path must be an ``Attribute`` of an
``Object``. In fact, if you had a pointer to the ``Object`` that has
the "CourseChange" ``Attribute`` handy, you could write this just like
we did in the previous example. You know by now that we typically
-store pointers to our nodes in a NodeContainer. In the ``third.cc``
+store pointers to our ``Nodes`` in a NodeContainer. In the ``third.cc``
example, the Nodes of interest are stored in the ``wifiStaNodes``
NodeContainer. In fact, while putting the path together, we used this
-container to get a Ptr which we used to call GetId() on. We
-could have used this Ptr directly to call a connect method
+container to get a ``Ptr`` which we used to call ``GetId()``. We
+could have used this ``Ptr`` to call a Connect method
directly::
Ptr theObject = wifiStaNodes.Get (nWifi - 1);
theObject->TraceConnectWithoutContext ("CourseChange", MakeCallback (&CourseChange));
-In the ``third.cc`` example, we actually want an additional "context"
+In the ``third.cc`` example, we actually wanted an additional "context"
to be delivered along with the Callback parameters (which will be
explained below) so we could actually use the following equivalent
-code,
-
-::
+code::
Ptr theObject = wifiStaNodes.Get (nWifi - 1);
theObject->TraceConnect ("CourseChange", MakeCallback (&CourseChange));
It turns out that the internal code for
-``Config::ConnectWithoutContext`` and ``Config::Connect`` actually do
-find a Ptr and call the appropriate TraceConnect method at the
-lowest level.
+``Config::ConnectWithoutContext`` and ``Config::Connect`` actually
+find a ``Ptr`` and call the appropriate ``TraceConnect``
+method at the lowest level.
The ``Config`` functions take a path that represents a chain of
``Object`` pointers. Each segment of a path corresponds to an Object
@@ -555,26 +586,29 @@ The leading "/" character in the path refers to a so-called namespace.
One of the predefined namespaces in the config system is "NodeList"
which is a list of all of the nodes in the simulation. Items in the
list are referred to by indices into the list, so "/NodeList/7" refers
-to the eighth node in the list of nodes created during the simulation.
-This reference is actually a ``Ptr`` and so is a subclass of an
-``ns3::Object``.
+to the eighth Node in the list of nodes created during the simulation
+(recall indices start at `0'). This reference is actually a
+``Ptr`` and so is a subclass of an ``ns3::Object``.
-As described in the Object Model section of the |ns3| manual, we
-support Object Aggregation. This allows us to form an association
-between different Objects without any programming. Each Object in an
-Aggregation can be reached from the other Objects.
+As described in the Object Model section of the |ns3| Manual, we make
+widespread use of object aggregation. This allows us to form an
+association between different Objects without building a complicated
+inheritance tree or predeciding what objects will be part of a
+Node. Each Object in an Aggregation can be reached from the other
+Objects.
-The next path segment being walked begins with the "$" character.
-This indicates to the config system that a ``GetObject`` call should
-be made looking for the type that follows. It turns out that the
-MobilityHelper used in ``third.cc`` arranges to Aggregate, or
-associate, a mobility model to each of the wireless Nodes. When you
-add the "$" you are asking for another Object that has presumably been
-previously aggregated. You can think of this as switching pointers
-from the original Ptr as specified by "/NodeList/7" to its
-associated mobility model --- which is of type "$ns3::MobilityModel".
-If you are familiar with ``GetObject``, we have asked the system to do
-the following::
+In our example the next path segment being walked begins with the "$"
+character. This indicates to the config system that the segment is
+the name of an object type, so a ``GetObject`` call should be made
+looking for that type. It turns out that the ``MobilityHelper`` used
+in ``third.cc`` arranges to Aggregate, or associate, a mobility model
+to each of the wireless ``Nodes``. When you add the "$" you are
+asking for another Object that has presumably been previously
+aggregated. You can think of this as switching pointers from the
+original Ptr as specified by "/NodeList/7" to its associated
+mobility model --- which is of type ``ns3::MobilityModel``. If you
+are familiar with ``GetObject``, we have asked the system to do the
+following::
Ptr mobilityModel = node->GetObject ()
@@ -582,13 +616,14 @@ We are now at the last Object in the path, so we turn our attention to
the Attributes of that Object. The ``MobilityModel`` class defines an
Attribute called "CourseChange". You can see this by looking at the
source code in ``src/mobility/model/mobility-model.cc`` and searching
-for "CourseChange" in your favorite editor. You should find,
+for "CourseChange" in your favorite editor. You should find
::
.AddTraceSource ("CourseChange",
"The value of the position and/or velocity vector changed",
- MakeTraceSourceAccessor (&MobilityModel::m_courseChangeTrace))
+ MakeTraceSourceAccessor (&MobilityModel::m_courseChangeTrace),
+ "ns3::MobilityModel::CourseChangeCallback")
which should look very familiar at this point.
@@ -601,7 +636,10 @@ variable in ``mobility-model.h`` you will find
The type declaration ``TracedCallback`` identifies
``m_courseChangeTrace`` as a special list of Callbacks that can be
-hooked using the Config functions described above.
+hooked using the Config functions described above. The ``typedef``
+for the callback function signature is also defined in the header file::
+
+ typedef void (* CourseChangeCallback)(Ptr * model);
The ``MobilityModel`` class is designed to be a base class providing a
common interface for all of the specific subclasses. If you search
@@ -626,7 +664,7 @@ installed, there will be a ``NotifyCourseChange()`` call which calls
up into the ``MobilityModel`` base class. As seen above, this invokes
``operator()`` on ``m_courseChangeTrace``, which in turn, calls any
registered trace sinks. In the example, the only code registering an
-interest was the code that provided the config path. Therefore, the
+interest was the code that provided the Config path. Therefore, the
``CourseChange`` function that was hooked from Node number seven will
be the only Callback called.
@@ -641,54 +679,56 @@ through which the config code located the trace source. In the case
we have been looking at there can be any number of trace sources in
the system corresponding to any number of nodes with mobility models.
There needs to be some way to identify which trace source is actually
-the one that fired the Callback. An easy way is to request a trace
-context when you ``Config::Connect``.
+the one that fired the Callback. The easy way is to connect with
+``Config::Connect``, instead of ``Config::ConnectWithoutContext``.
-How to Find and Connect Trace Sources, and Discover Callback Signatures
-+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Finding Sources
++++++++++++++++
The first question that inevitably comes up for new users of the
-Tracing system is, "okay, I know that there must be trace sources in
+Tracing system is, *"Okay, I know that there must be trace sources in
the simulation core, but how do I find out what trace sources are
-available to me"?
+available to me?"*
-The second question is, "okay, I found a trace source, how do I figure
-out the config path to use when I connect to it"?
+The second question is, *"Okay, I found a trace source, how do I figure
+out the Config path to use when I connect to it?"*
-The third question is, "okay, I found a trace source, how do I figure
-out what the return type and formal arguments of my callback function
-need to be"?
+The third question is, *"Okay, I found a trace source and the Config
+path, how do I figure out what the return type and formal arguments of
+my callback function need to be?"*
-The fourth question is, "okay, I typed that all in and got this
-incredibly bizarre error message, what in the world does it mean"?
+The fourth question is, *"Okay, I typed that all in and got this
+incredibly bizarre error message, what in the world does it mean?"*
-What Trace Sources are Available?
-+++++++++++++++++++++++++++++++++
+We'll address each of these in turn.
-The answer to this question is found in the |ns3| Doxygen. If you go
-to the project web site, `ns-3 project `_, you
-will find a link to "Documentation" in the navigation bar. If you
-select this link, you will be taken to our documentation page. There
-is a link to "Latest Release" that will take you to the documentation
-for the latest stable release of |ns3|. If you select the "API
-Documentation" link, you will be taken to the |ns3| API documentation
-page.
+Available Sources
++++++++++++++++++
-Expand the "Modules" book in the NS-3 documentation tree by clicking
-the "+" box. Now, expand the "C++ Constructs Used by All Modules"
-book in the tree by clicking its "+" box. You should now see four
-extremely useful links:
+*Okay, I know that there must be trace sources in the simulation core,
+but how do I find out what trace sources are available to me?*
+The answer to the first question is found in the |ns3| API
+documentation. If you go to the project web site, `ns-3 project
+`_, you will find a link to "Documentation" in
+the navigation bar. If you select this link, you will be taken to our
+documentation page. There is a link to "Latest Release" that will take
+you to the documentation for the latest stable release of |ns3|. If
+you select the "API Documentation" link, you will be taken to the
+|ns3| API documentation page.
-* The list of all trace sources
-* The list of all attributes
-* The list of all global values
-* Debugging
+In the sidebar you should see a hierachy that begins
-The list of interest to us here is "the list of all trace sources".
-Go ahead and select that link. You will see, perhaps not too
-surprisingly, a list of all of the trace sources available in the
-|ns3| core.
+* ns-3
+
+ * ns-3 Documentation
+ * All TraceSources
+ * All Attributes
+ * All GlobalValues
+
+The list of interest to us here is "All TraceSources". Go ahead and
+select that link. You will see, perhaps not too surprisingly, a list
+of all of the trace sources available in |ns3|.
As an example, scroll down to ``ns3::MobilityModel``. You will find
an entry for
@@ -700,70 +740,49 @@ an entry for
You should recognize this as the trace source we used in the
``third.cc`` example. Perusing this list will be helpful.
-What String do I use to Connect?
-++++++++++++++++++++++++++++++++
+Config Paths
+++++++++++++
-The easiest way to do this is to grep around in the |ns3| codebase for
-someone who has already figured it out, You should always try to copy
-someone else's working code before you start to write your own. Try
-something like:
+*Okay, I found a trace source, how do I figure out the Config path to
+use when I connect to it?*
-.. sourcecode:: bash
+If you know which object you are interested in, the "Detailed
+Description" section for the class will list all available trace
+sources. For example, starting from the list of "All TraceSources,"
+click on the ``ns3::MobilityModel`` link, which will take you to the
+documentation for the ``MobilityModel`` class. Almost at the top of
+the page is a one line brief description of the class, ending in a
+link "More...". Click on this link to skip the API summary and go to
+the "Detailed Description" of the class. At the end of the
+description will be (up to) three lists:
- $ find . -name '*.cc' | xargs grep CourseChange | grep Connect
+* **Config Paths**: a list of typical Config paths for this class.
+* **Attributes**: a list of all attributes supplied by this class.
+* **TraceSources**: a list of all TraceSources available from this class.
-and you may find your answer along with working code. For example, in
-this case, ``./ns-3-dev/examples/wireless/mixed-wireless.cc`` has
-something just waiting for you to use::
+First we'll discuss the Config paths.
- Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange",
- MakeCallback (&CourseChangeCallback));
-
-If you cannot find any examples in the distribution, you can find this
-out from the |ns3| Doxygen. It will probably be simplest just to walk
-through the "CourseChanged" example.
-
-Let's assume that you have just found the "CourseChanged" trace source
-in "The list of all trace sources" and you want to figure out how to
+Let's assume that you have just found the "CourseChange" trace source
+in the "All TraceSources" list and you want to figure out how to
connect to it. You know that you are using (again, from the
-``third.cc`` example) an ``ns3::RandomWalk2dMobilityModel``. So open
-the "Class List" book in the NS-3 documentation tree by clicking its
-"+" box. You will now see a list of all of the classes in |ns3|.
-Scroll down until you see the entry for
-``ns3::RandomWalk2dMobilityModel`` and follow that link. You should
-now be looking at the "ns3::RandomWalk2dMobilityModel Class
-Reference".
+``third.cc`` example) an ``ns3::RandomWalk2dMobilityModel``. So
+either click on the class name in the "All TraceSources" list, or find
+``ns3::RandomWalk2dMobilityModel`` in the "Class List". Either way
+you should now be looking at the "ns3::RandomWalk2dMobilityModel Class
+Reference" page.
-If you now scroll down to the "Member Function Documentation" section,
-you will see documentation for the ``GetTypeId`` function. You
-constructed one of these in the simple tracing example above::
+If you now scroll down to the "Detailed Description" section, after
+the summary list of class methods and attributes (or just click on the
+"More..." link at the end of the class brief description at the top of
+the page) you will see the overall documentation for the class.
+Continuing to scroll down, find the "Config Paths" list:
- static TypeId GetTypeId (void)
- {
- static TypeId tid = TypeId ("MyObject")
- .SetParent (Object::GetTypeId ())
- .AddConstructor ()
- .AddTraceSource ("MyInteger",
- "An integer value to trace.",
- MakeTraceSourceAccessor (&MyObject::m_myInt))
- ;
- return tid;
- }
+ **Config Paths**
-As mentioned above, this is the bit of code that connected the Config
-and Attribute systems to the underlying trace source. This is also
-the place where you should start looking for information about the way
-to connect.
+ ``ns3::RandomWalk2dMobilityModel`` is accessible through the
+ following paths with ``Config::Set`` and ``Config::Connect``:
-You are looking at the same information for the
-RandomWalk2dMobilityModel; and the information you want is now right
-there in front of you in the Doxygen:
-
-.. sourcecode:: bash
-
- This object is accessible through the following paths with Config::Set and Config::Connect:
-
- /NodeList/[i]/$ns3::MobilityModel/$ns3::RandomWalk2dMobilityModel
+ * "/NodeList/[i]/$ns3::MobilityModel/$ns3::RandomWalk2dMobilityModel"
The documentation tells you how to get to the
``RandomWalk2dMobilityModel`` Object. Compare the string above with
@@ -775,74 +794,118 @@ The difference is due to the fact that two ``GetObject`` calls are
implied in the string found in the documentation. The first, for
``$ns3::MobilityModel`` will query the aggregation for the base class.
The second implied ``GetObject`` call, for
-``$ns3::RandomWalk2dMobilityModel``, is used to "cast" the base class
-to the concrete implementation class. The documentation shows both of
-these operations for you. It turns out that the actual Attribute you
-are going to be looking for is found in the base class as we have
-seen.
+``$ns3::RandomWalk2dMobilityModel``, is used to cast the base class to
+the concrete implementation class. The documentation shows both of
+these operations for you. It turns out that the actual trace source
+you are looking for is found in the base class.
-Look further down in the ``GetTypeId`` doxygen. You will find,
+Look further down in the "Detailed Description" section for the list
+of trace sources. You will find
-.. sourcecode:: bash
+ No TraceSources are defined for this type.
+
+ **TraceSources defined in parent class ``ns3::MobilityModel``**
- No TraceSources defined for this type.
- TraceSources defined in parent class ns3::MobilityModel:
+ * **CourseChange**: The value of the position and/or velocity vector
+ changed.
- CourseChange: The value of the position and/or velocity vector changed
- Reimplemented from ns3::MobilityModel
+ Callback signature: ``ns3::MobilityModel::CourseChangeCallback``
This is exactly what you need to know. The trace source of interest
is found in ``ns3::MobilityModel`` (which you knew anyway). The
-interesting thing this bit of Doxygen tells you is that you don't need
-that extra cast in the config path above to get to the concrete class,
-since the trace source is actually in the base class. Therefore the
-additional ``GetObject`` is not required and you simply use the path::
+interesting thing this bit of API Documentation tells you is that you
+don't need that extra cast in the config path above to get to the
+concrete class, since the trace source is actually in the base class.
+Therefore the additional ``GetObject`` is not required and you simply
+use the path::
- /NodeList/[i]/$ns3::MobilityModel
+ "/NodeList/[i]/$ns3::MobilityModel"
which perfectly matches the example path::
- /NodeList/7/$ns3::MobilityModel
+ "/NodeList/7/$ns3::MobilityModel"
-What Return Value and Formal Arguments?
-+++++++++++++++++++++++++++++++++++++++
-
-The easiest way to do this is to grep around in the |ns3| codebase for
-someone who has already figured it out, You should always try to copy
-someone else's working code. Try something like:
+As an aside, another way to find the Config path is to ``grep`` around in
+the |ns3| codebase for someone who has already figured it out. You
+should always try to copy someone else's working code before you start
+to write your own. Try something like:
.. sourcecode:: bash
$ find . -name '*.cc' | xargs grep CourseChange | grep Connect
and you may find your answer along with working code. For example, in
-this case, ``./ns-3-dev/examples/wireless/mixed-wireless.cc`` has
-something just waiting for you to use. You will find
-
-::
+this case, ``src/mobility/examples/main-random-topology.cc`` has
+something just waiting for you to use::
Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange",
- MakeCallback (&CourseChangeCallback));
+ MakeCallback (&CourseChange));
-as a result of your grep. The ``MakeCallback`` should indicate to you
-that there is a callback function there which you can use. Sure
-enough, there is::
+We'll return to this example in a moment.
+
+Callback Signatures
++++++++++++++++++++
+
+*Okay, I found a trace source and the Config path, how do I figure out
+what the return type and formal arguments of my callback function need
+to be?*
+
+The easiest way is to examine the callback signature ``typedef``,
+which is given in the "Callback signature" of the trace source in the
+"Detailed Description" for the class, as shown above.
+
+Repeating the "CourseChange" trace source entry from
+``ns3::RandomWalk2dMobilityModel`` we have:
+
+ * **CourseChange**: The value of the position and/or velocity vector
+ changed.
+
+ Callback signature: ``ns3::MobilityModel::CourseChangeCallback``
+
+The callback signature is given as a link to the relevant ``typedef``,
+where we find
+
+ ``typedef void (* CourseChangeCallback)(const std::string context, Ptr * model);``
+
+ **TracedCallback** signature for course change notifications.
+
+ If the callback is connected using ``ConnectWithoutContext`` omit the
+ ``context`` argument from the signature.
+
+ **Parameters**:
+
+ | [in] :param:`context` The context string supplied by the Trace source.
+ | [in] :param:`model` The MobilityModel which is changing course.
+
+As above, to see this in use ``grep`` around in the |ns3| codebase for
+an example. The example above, from
+``src/mobility/examples/main-random-topology.cc``, connects the
+"CourseChange" trace source to the ``CourseChange`` function in the
+same file::
static void
- CourseChangeCallback (std::string path, Ptr model)
+ CourseChange (std::string context, Ptr model)
{
...
}
-Take My Word for It
-~~~~~~~~~~~~~~~~~~~
+Notice that this function:
-If there are no examples to work from, this can be, well, challenging
-to actually figure out from the source code.
+* Takes a "context" string argument, which we'll describe in a minute.
+ (If the callback is connected using the ``ConnectWithoutContext``
+ function the ``context`` argument will be omitted.)
+* Has the ``MobilityModel`` supplied as the last argument (or only
+ argument if ``ConnectWithoutContext`` is used).
+* Returns ``void``.
+
+If, by chance, the callback signature hasn't been documented, and
+there are no examples to work from, determining the right callback
+function signature can be, well, challenging to actually figure out
+from the source code.
Before embarking on a walkthrough of the code, I'll be kind and just
tell you a simple way to figure this out: The return value of your
-callback will always be void. The formal parameter list for a
+callback will always be ``void``. The formal parameter list for a
``TracedCallback`` can be found from the template parameter list in
the declaration. Recall that for our current example, this is in
``mobility-model.h``, where we have previously found::
@@ -853,44 +916,40 @@ There is a one-to-one correspondence between the template parameter
list in the declaration and the formal arguments of the callback
function. Here, there is one template parameter, which is a
``Ptr``. This tells you that you need a function
-that returns void and takes a a ``Ptr``. For
-example,
-
-::
+that returns void and takes a ``Ptr``. For
+example::
void
- CourseChangeCallback (Ptr model)
+ CourseChange (Ptr model)
{
...
}
That's all you need if you want to ``Config::ConnectWithoutContext``.
If you want a context, you need to ``Config::Connect`` and use a
-Callback function that takes a string context, then the required
-argument.
-
-::
+Callback function that takes a string context, then the template
+arguments::
void
- CourseChangeCallback (std::string path, Ptr model)
+ CourseChange (const std::string context, Ptr model)
{
...
}
-If you want to ensure that your ``CourseChangeCallback`` is only
+If you want to ensure that your ``CourseChangeCallback`` function is only
visible in your local file, you can add the keyword ``static`` and
come up with::
static void
- CourseChangeCallback (std::string path, Ptr model)
+ CourseChange (const std::string path, Ptr model)
{
...
}
which is exactly what we used in the ``third.cc`` example.
-The Hard Way
-~~~~~~~~~~~~
+Implementation
+~~~~~~~~~~~~~~
This section is entirely optional. It is going to be a bumpy ride,
especially for those unfamiliar with the details of templates.
@@ -898,7 +957,7 @@ However, if you get through this, you will have a very good handle on
a lot of the |ns3| low level idioms.
So, again, let's figure out what signature of callback function is
-required for the "CourseChange" Attribute. This is going to be
+required for the "CourseChange" trace source. This is going to be
painful, but you only need to do this once. After you get through
this, you will be able to just look at a ``TracedCallback`` and
understand it.
@@ -912,20 +971,20 @@ previously found::
This declaration is for a template. The template parameter is inside
the angle-brackets, so we are really interested in finding out what
that ``TracedCallback<>`` is. If you have absolutely no idea where
-this might be found, grep is your friend.
+this might be found, ``grep`` is your friend.
We are probably going to be interested in some kind of declaration in
the |ns3| source, so first change into the ``src`` directory. Then,
we know this declaration is going to have to be in some kind of header
-file, so just grep for it using:
+file, so just ``grep`` for it using:
.. sourcecode:: bash
$ find . -name '*.h' | xargs grep TracedCallback
-You'll see 124 lines fly by (I piped this through wc to see how bad it
-was). Although that may seem like it, that's not really a lot. Just
-pipe the output through more and start scanning through it. On the
+You'll see 303 lines fly by (I piped this through ``wc`` to see how bad it
+was). Although that may seem like a lot, that's not really a lot. Just
+pipe the output through ``more`` and start scanning through it. On the
first page, you will see some very suspiciously template-looking
stuff.
@@ -964,8 +1023,6 @@ what is happening.
You will see a comment at the top of the file that should be
comforting:
-.. sourcecode:: text
-
An ns3::TracedCallback has almost exactly the same API as a normal
ns3::Callback but instead of forwarding calls to a single function
(as an ns3::Callback normally does), it forwards calls to a chain of
@@ -974,7 +1031,7 @@ comforting:
This should sound very familiar and let you know you are on the right
track.
-Just after this comment, you will find,
+Just after this comment, you will find
::
@@ -1032,31 +1089,22 @@ about. The code creates a Callback of the right type and assigns your
function to it. This is the equivalent of the ``pfi = MyFunction`` we
discussed at the start of this section. The code then adds the
Callback to the list of Callbacks for this source. The only thing
-left is to look at the definition of Callback. Using the same grep
+left is to look at the definition of Callback. Using the same ``grep``
trick as we used to find ``TracedCallback``, you will be able to find
that the file ``./core/callback.h`` is the one we need to look at.
If you look down through the file, you will see a lot of probably
almost incomprehensible template code. You will eventually come to
-some Doxygen for the Callback template class, though. Fortunately,
+some API Documentation for the Callback template class, though. Fortunately,
there is some English:
-.. sourcecode:: text
+ **Callback** template class.
- This class template implements the Functor Design Pattern.
- It is used to declare the type of a Callback:
- - the first non-optional template argument represents
- the return type of the callback.
- - the second optional template argument represents
- the type of the first argument to the callback.
- - the third optional template argument represents
- the type of the second argument to the callback.
- - the fourth optional template argument represents
- the type of the third argument to the callback.
- - the fifth optional template argument represents
- the type of the fourth argument to the callback.
- - the sixth optional template argument represents
- the type of the fifth argument to the callback.
+ This class template implements the Functor Design Pattern. It is used to declare the type of a **Callback**:
+
+ * the first non-optional template argument represents the return type of the callback.
+ * the reminaining (optional) template arguments represent the type of the subsequent arguments to the callback.
+ * up to nine arguments are supported.
We are trying to figure out what the
@@ -1065,9 +1113,10 @@ We are trying to figure out what the
Callback > cb;
declaration means. Now we are in a position to understand that the
-first (non-optional) parameter, ``void``, represents the return type
-of the Callback. The second (non-optional) parameter, ``Ptr`` represents the first argument to the callback.
+first (non-optional) template argument, ``void``, represents the
+return type of the Callback. The second (optional) template argument,
+``Ptr`` represents the type of the first argument
+to the callback.
The Callback in question is your function to receive the trace events.
From this you can infer that you need a function that returns ``void``
@@ -1087,7 +1136,7 @@ Callback function that takes a string context. This is because the
``Connect`` function will provide the context for you. You'll need::
void
- CourseChangeCallback (std::string path, Ptr model)
+ CourseChangeCallback (std::string context, Ptr model)
{
...
}
@@ -1111,71 +1160,72 @@ Callbacks, feel free to take a look at the |ns3| manual. They are one
of the most frequently used constructs in the low-level parts of
|ns3|. It is, in my opinion, a quite elegant thing.
-What About TracedValue?
-+++++++++++++++++++++++
+TracedValues
+++++++++++++
Earlier in this section, we presented a simple piece of code that used
a ``TracedValue`` to demonstrate the basics of the tracing
-code. We just glossed over the way to find the return type and formal
-arguments for the ``TracedValue``. Rather than go through the whole
-exercise, we will just point you at the correct file,
-``src/core/model/traced-value.h`` and to the important piece of code::
+code. We just glossed over the what a TracedValue really is and how
+to find the return type and formal arguments for the callback.
- template
- class TracedValue
- {
- public:
- ...
- void Set (const T &v) {
- if (m_v != v)
- {
- m_cb (m_v, v);
- m_v = v;
- }
- }
- ...
- private:
- T m_v;
- TracedCallback m_cb;
- };
+As we mentioned, the file, ``traced-value.h`` brings in the required
+declarations for tracing of data that obeys value semantics. In
+general, value semantics just means that you can pass the object
+itself around, rather than passing the address of the object. We
+extend that requirement to include the full set of assignment-style
+operators that are pre-defined for plain-old-data (POD) types:
-Here you see that the ``TracedValue`` is templated, of course. In the
-simple example case at the start of the section, the typename is
-int32_t. This means that the member variable being traced (``m_v`` in
-the private section of the class) will be an ``int32_t m_v``. The
-``Set`` method will take a ``const int32_t &v`` as a parameter. You
-should now be able to understand that the ``Set`` code will fire the
-``m_cb`` callback with two parameters: the first being the current
-value of the ``TracedValue``; and the second being the new value being
-set.
+ +---------------------+---------------------+
+ | ``operator=`` (assignment) |
+ +---------------------+---------------------+
+ | ``operator*=`` | ``operator/=`` |
+ +---------------------+---------------------+
+ | ``operator+=`` | ``operator-=`` |
+ +---------------------+---------------------+
+ | ``operator++`` (both prefix and postfix) |
+ +---------------------+---------------------+
+ | ``operator--`` (both prefix and postfix) |
+ +---------------------+---------------------+
+ | ``operator<<=`` | ``operator>>=`` |
+ +---------------------+---------------------+
+ | ``operator&=`` | ``operator|=`` |
+ +---------------------+---------------------+
+ | ``operator%=`` | ``operator^=`` |
+ +---------------------+---------------------+
-The callback, ``m_cb`` is declared as a ``TracedCallback`` which
-will correspond to a ``TracedCallback`` when the
-class is instantiated.
+What this all really means is that you will be able to trace all
+changes made using those operators to a C++ object which has value
+semantics.
-Recall that the callback target of a TracedCallback always returns
-``void``. Further recall that there is a one-to-one correspondence
-between the template parameter list in the declaration and the formal
-arguments of the callback function. Therefore the callback will need
-to have a function signature that looks like::
+The ``TracedValue<>`` declaration we saw above provides the
+infrastructure that overloads the operators mentioned above and drives
+the callback process. On use of any of the operators above with a
+``TracedValue`` it will provide both the old and the new value of that
+variable, in this case an ``int32_t`` value. By inspection of the
+``TracedValue`` declaration, we know the trace sink function will have
+arguments ``(const int32_t oldValue, const int32_t newValue)``. The
+return type for a ``TracedValue`` callback function is always
+``void``, so the expected callback signature will be::
- void
- MyCallback (int32_t oldValue, int32_t newValue)
- {
- ...
- }
+ void (* TracedValueCallback)(const int32_t oldValue, const int32_t newValue);
-It probably won't surprise you that this is exactly what we provided
-in that simple example we covered so long ago::
+The ``.AddTraceSource`` in the ``GetTypeId`` method provides the
+"hooks" used for connecting the trace source to the outside world
+through the Config system. We already discussed the first three
+agruments to ``AddTraceSource``: the Attribute name for the Config
+system, a help string, and the address of the TracedValue class data
+member.
- void
- IntTrace (int32_t oldValue, int32_t newValue)
- {
- std::cout << "Traced " << oldValue << " to " << newValue << std::endl;
- }
+The final string argument, "ns3::Traced::Value::Int32" in the example,
+is the name of a ``typedef`` for the callback function signature. We
+require these signatures to be defined, and give the fully qualified
+type name to ``AddTraceSource``, so the API documentation can link a
+trace source to the function signature. For TracedValue the signature
+is straightforward; for TracedCallbacks we've already seen the API
+docs really help.
-A Real Example
-**************
+Real Example
+************
Let's do an example taken from one of the best-known books on TCP
around. "TCP/IP Illustrated, Volume 1: The Protocols," by W. Richard
@@ -1186,26 +1236,25 @@ and send sequence number while data is being transmitted." Let's just
recreate the cwnd part of that plot in |ns3| using the tracing system
and ``gnuplot``.
-Are There Trace Sources Available?
-++++++++++++++++++++++++++++++++++
+Available Sources
++++++++++++++++++
The first thing to think about is how we want to get the data out.
-What is it that we need to trace? The first thing to do is to consult
-"The list of all trace sources" to see what we have to work with.
-Recall that this is found in the |ns3| Doxygen in the "C++ Constructs
-Used by All Modules" Module section. If you scroll through the list,
+What is it that we need to trace? So let's consult "All Trace
+Sources" list to see what we have to work with. Recall that this is
+found in the |ns3| API Documentation. If you scroll through the list,
you will eventually find:
-.. sourcecode:: bash
+ **ns3::TcpNewReno**
- ns3::TcpNewReno
- CongestionWindow: The TCP connection's congestion window
+ * **CongestionWindow**: The TCP connection's congestion window
+ * **SlowStartThreshold**: TCP slow start threshold (bytes)
It turns out that the |ns3| TCP implementation lives (mostly) in the
file ``src/internet/model/tcp-socket-base.cc`` while congestion
control variants are in files such as
-``src/internet/model/tcp-newreno.cc``. If you don't know this a
-priori, you can use the recursive grep trick:
+``src/internet/model/tcp-newreno.cc``. If you don't know this *a
+priori*, you can use the recursive ``grep`` trick:
.. sourcecode:: bash
@@ -1214,54 +1263,36 @@ priori, you can use the recursive grep trick:
You will find page after page of instances of tcp pointing you to that
file.
-If you open ``src/internet/model/tcp-newreno.cc`` in your favorite
-editor, you will see right up at the top of the file, the following
-declarations::
+Bringing up the class documentation for ``TcpNewReno`` and skipping to
+the list of TraceSources you will find
- TypeId
- TcpNewReno::GetTypeId ()
- {
- static TypeId tid = TypeId("ns3::TcpNewReno")
- .SetParent ()
- .AddConstructor ()
- .AddTraceSource ("CongestionWindow",
- "The TCP connection's congestion window",
- MakeTraceSourceAccessor (&TcpNewReno::m_cWnd))
- ;
- return tid;
- }
+ **TraceSources**
-This should tell you to look for the declaration of ``m_cWnd`` in the
-header file ``src/internet/model/tcp-newreno.h``. If you open this
-file in your favorite editor, you will find::
+ * **CongestionWindow**: The TCP connnection's congestion window
- TracedValue m_cWnd; //Congestion window
+ Callback signature: **ns3::Traced::Value::Uint322Callback**
+
+Clicking on the callback ``typedef`` link we see the signature
+you now know to expect::
+
+ typedef void(* ns3::Traced::Value::Int32Callback)(const int32_t oldValue, const int32_t newValue)
You should now understand this code completely. If we have a pointer
to the ``TcpNewReno``, we can ``TraceConnect`` to the
"CongestionWindow" trace source if we provide an appropriate callback
target. This is the same kind of trace source that we saw in the
simple example at the start of this section, except that we are
-talking about ``uint32_t`` instead of ``int32_t``.
+talking about ``uint32_t`` instead of ``int32_t``. And we know
+that we have to provide a callback function with that signature.
-We now know that we need to provide a callback that returns void and
-takes two ``uint32_t`` parameters, the first being the old value and
-the second being the new value::
-
- void
- CwndTrace (uint32_t oldValue, uint32_t newValue)
- {
- ...
- }
-
-What Script to Use?
-+++++++++++++++++++
+Finding Examples
+++++++++++++++++
It's always best to try and find working code laying around that you
can modify, rather than starting from scratch. So the first order of
business now is to find some code that already hooks the
"CongestionWindow" trace source and see if we can modify it. As
-usual, grep is your friend:
+usual, ``grep`` is your friend:
.. sourcecode:: bash
@@ -1295,33 +1326,33 @@ of in ``DoRun``. Rather than walk through this, step, by step, we
have provided the file that results from porting this test back to a
native |ns3| script -- ``examples/tutorial/fifth.cc``.
-A Common Problem and Solution
-+++++++++++++++++++++++++++++
+Dynamic Trace Sources
++++++++++++++++++++++
-The ``fifth.cc`` example demonstrates an extremely important rule that you
-must understand before using any kind of ``Attribute``: you must ensure
-that the target of a ``Config`` command exists before trying to use it.
-This is no different than saying an object must be instantiated before
-trying to call it. Although this may seem obvious when stated this
-way, it does trip up many people trying to use the system for the
-first time.
+The ``fifth.cc`` example demonstrates an extremely important rule that
+you must understand before using any kind of trace source: you must
+ensure that the target of a ``Config::Connect`` command exists before
+trying to use it. This is no different than saying an object must be
+instantiated before trying to call it. Although this may seem obvious
+when stated this way, it does trip up many people trying to use the
+system for the first time.
-Let's return to basics for a moment. There are three basic time
-periods that exist in any |ns3| script. The first time period is
-sometimes called "Configuration Time" or "Setup Time," and is in force
+Let's return to basics for a moment. There are three basic execution
+phases that exist in any |ns3| script. The first phase is
+sometimes called "Configuration Time" or "Setup Time," and exists
during the period when the ``main`` function of your script is
-running, but before ``Simulator::Run`` is called. The second time
-period is sometimes called "Simulation Time" and is in force during
+running, but before ``Simulator::Run`` is called. The second phase
+is sometimes called "Simulation Time" and exists during
the time period when ``Simulator::Run`` is actively executing its
events. After it completes executing the simulation,
``Simulator::Run`` will return control back to the ``main`` function.
-When this happens, the script enters what can be called "Teardown
-Time," which is when the structures and objects created during setup
+When this happens, the script enters what can be called the "Teardown
+Phase," which is when the structures and objects created during setup
are taken apart and released.
Perhaps the most common mistake made in trying to use the tracing
-system is assuming that entities constructed dynamically during
-simulation time are available during configuration time. In
+system is assuming that entities constructed dynamically *during
+simulation time* are available during configuration time. In
particular, an |ns3| ``Socket`` is a dynamic object often created by
``Applications`` to communicate between ``Nodes``. An |ns3|
``Application`` always has a "Start Time" and a "Stop Time" associated
@@ -1329,18 +1360,24 @@ with it. In the vast majority of cases, an ``Application`` will not
attempt to create a dynamic object until its ``StartApplication``
method is called at some "Start Time". This is to ensure that the
simulation is completely configured before the app tries to do
-anything (what would happen if it tried to connect to a node that
-didn't exist yet during configuration time). The answer to this issue
-is to 1) create a simulator event that is run after the dynamic object
-is created and hook the trace when that event is executed; or 2)
-create the dynamic object at configuration time, hook it then, and
-give the object to the system to use during simulation time. We took
-the second approach in the ``fifth.cc`` example. This decision
-required us to create the ``MyApp`` ``Application``, the entire
-purpose of which is to take a ``Socket`` as a parameter.
+anything (what would happen if it tried to connect to a Node that
+didn't exist yet during configuration time?). As a result, during the
+configuration phase you can't connect a trace source to a trace sink
+if one of them is created dynamically during the simulation.
-A fifth.cc Walkthrough
-++++++++++++++++++++++
+The two solutions to this connundrum are
+
+#. Create a simulator event that is run after the dynamic object is
+ created and hook the trace when that event is executed; or
+#. Create the dynamic object at configuration time, hook it then, and
+ give the object to the system to use during simulation time.
+
+We took the second approach in the ``fifth.cc`` example. This
+decision required us to create the ``MyApp`` ``Application``, the
+entire purpose of which is to take a ``Socket`` as a parameter.
+
+Walkthrough: ``fifth.cc``
++++++++++++++++++++++++++
Now, let's take a look at the example program we constructed by
dissecting the congestion window test. Open
@@ -1457,8 +1494,8 @@ override the ``StartApplication`` and ``StopApplication`` methods.
These methods are automatically called when ``MyApp`` is required to
start and stop sending data during the simulation.
-How Applications are Started and Stopped (optional)
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Starting/Stopping Applications
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It is worthwhile to spend a bit of time explaining how events actually
get started in the system. This is another fairly deep explanation,
@@ -1501,7 +1538,7 @@ the simulator at the appropriate time. In the case of ``MyApp`` you
will find that ``MyApp::StartApplication`` does the initial ``Bind``,
and ``Connect`` on the socket, and then starts data flowing by calling
``MyApp::SendPacket``. ``MyApp::StopApplication`` stops generating
-packets by cancelling any pending send events and closing the socket.
+packets by cancelling any pending send events then closes the socket.
One of the nice things about |ns3| is that you can completely ignore
the implementation details of how your ``Application`` is
@@ -1517,7 +1554,7 @@ probably end.
The key to picking up the trail again is to know that there is a
global list of all of the nodes in the system. Whenever you create a
-node in a simulation, a pointer to that node is added to the global
+node in a simulation, a pointer to that Node is added to the global
``NodeList``.
Take a look at ``src/network/model/node-list.cc`` and search for
@@ -1530,21 +1567,21 @@ relatively common idom in |ns3|. So, take a look at
Simulator::ScheduleWithContext (index, TimeStep (0), &Node::Initialize, node);
-This tells you that whenever a ``Node`` is created in a simulation, as
+This tells you that whenever a Node is created in a simulation, as
a side-effect, a call to that node's ``Initialize`` method is
scheduled for you that happens at time zero. Don't read too much into
-that name, yet. It doesn't mean that the node is going to start doing
+that name, yet. It doesn't mean that the Node is going to start doing
anything, it can be interpreted as an informational call into the
-``Node`` telling it that the simulation has started, not a call for
-action telling the ``Node`` to start doing something.
+Node telling it that the simulation has started, not a call for
+action telling the Node to start doing something.
So, ``NodeList::Add`` indirectly schedules a call to
-``Node::Initialize`` at time zero to advise a new node that the
+``Node::Initialize`` at time zero to advise a new Node that the
simulation has started. If you look in ``src/network/model/node.h``
you will, however, not find a method called ``Node::Initialize``. It
turns out that the ``Initialize`` method is inherited from class
``Object``. All objects in the system can be notified when the
-simulation starts, and objects of class ``Node`` are just one kind of
+simulation starts, and objects of class Node are just one kind of
those objects.
Take a look at ``src/core/model/object.cc`` next and search for
@@ -1552,9 +1589,10 @@ Take a look at ``src/core/model/object.cc`` next and search for
might have expected since |ns3| ``Objects`` support aggregation. The
code in ``Object::Initialize`` then loops through all of the objects
that have been aggregated together and calls their ``DoInitialize``
-method. This is another idiom that is very common in |ns3|. There is
-a public API method, that stays constant across implementations, that
-calls a private implementation method that is inherited and
+method. This is another idiom that is very common in |ns3|, sometimes
+called the "template design pattern.": a public non-virtual API
+method, which stays constant across implementations, and that calls a
+private virtual implementation method that is inherited and
implemented by subclasses. The names are typically something like
``MethodName`` for the public API and ``DoMethodName`` for the private
API.
@@ -1562,8 +1600,8 @@ API.
This tells us that we should look for a ``Node::DoInitialize`` method
in ``src/network/model/node.cc`` for the method that will continue our
trail. If you locate the code, you will find a method that loops
-through all of the devices in the node and then all of the
-applications in the node calling ``device->Initialize`` and
+through all of the devices in the Node and then all of the
+applications in the Node calling ``device->Initialize`` and
``application->Initialize`` respectively.
You may already know that classes ``Device`` and ``Application`` both
@@ -1587,15 +1625,15 @@ all straight, when you implement an |ns3| ``Application``, your new
application inherits from class ``Application``. You override the
``StartApplication`` and ``StopApplication`` methods and provide
mechanisms for starting and stopping the flow of data out of your new
-``Application``. When a ``Node`` is created in the simulation, it is
-added to a global ``NodeList``. The act of adding a node to this
+``Application``. When a Node is created in the simulation, it is
+added to a global ``NodeList``. The act of adding a Node to this
``NodeList`` causes a simulator event to be scheduled for time zero
which calls the ``Node::Initialize`` method of the newly added
-``Node`` to be called when the simulation starts. Since a ``Node``
+Node to be called when the simulation starts. Since a Node
inherits from ``Object``, this calls the ``Object::Initialize`` method
-on the ``Node`` which, in turn, calls the ``DoInitialize`` methods on
-all of the ``Objects`` aggregated to the ``Node`` (think mobility
-models). Since the ``Node`` ``Object`` has overridden
+on the Node which, in turn, calls the ``DoInitialize`` methods on
+all of the ``Objects`` aggregated to the Node (think mobility
+models). Since the Node ``Object`` has overridden
``DoInitialize``, that method is called when the simulation starts.
The ``Node::DoInitialize`` method calls the ``Initialize`` methods of
all of the ``Applications`` on the node. Since ``Applications`` are
@@ -1765,8 +1803,8 @@ that it uses to transport the data. If you set the data rate of an
``Application`` to the same data rate as your underlying ``Channel``
you will eventually get a buffer overflow.
-The Trace Sinks
-~~~~~~~~~~~~~~~
+Trace Sinks
+~~~~~~~~~~~
The whole point of this exercise is to get trace callbacks from TCP
indicating the congestion window has been updated. The next piece of
@@ -1808,11 +1846,11 @@ see that this trace source refers to
member variable, you will find that it is declared as a
``TracedCallback >``. This should tell you that the
callback target should be a function that returns void and takes a
-single parameter which is a ``Ptr`` -- just what we have
-above.
+single parameter which is a ``Ptr`` (assuming we use
+``ConnectWithoutContext``) -- just what we have above.
-The Main Program
-~~~~~~~~~~~~~~~~
+Main Program
+~~~~~~~~~~~~
The following code should be very familiar to you by now::
@@ -1869,7 +1907,7 @@ The above code should be familiar. It installs internet stacks on our
two nodes and creates interfaces and assigns IP addresses for the
point-to-point devices.
-Since we are using TCP, we need something on the destination node to
+Since we are using TCP, we need something on the destination Node to
receive TCP connections and data. The ``PacketSink`` ``Application``
is commonly used in |ns3| for that purpose.
@@ -1914,13 +1952,13 @@ trace source.
MakeCallback (&CwndChange));
The first statement calls the static member function
-``Socket::CreateSocket`` and provides a ``Node`` and an explicit
+``Socket::CreateSocket`` and provides a Node and an explicit
``TypeId`` for the object factory used to create the socket. This is
a slightly lower level call than the ``PacketSinkHelper`` call above,
and uses an explicit C++ type instead of one referred to by a string.
Otherwise, it is conceptually the same thing.
-Once the ``TcpSocket`` is created and attached to the ``Node``, we can
+Once the ``TcpSocket`` is created and attached to the Node, we can
use ``TraceConnectWithoutContext`` to connect the CongestionWindow
trace source to our trace sink.
@@ -1943,12 +1981,12 @@ The first line creates an ``Object`` of type ``MyApp`` -- our
at each send event, how many send events to generate and the rate at
which to produce data from those events.
-Next, we manually add the ``MyApp Application`` to the source node and
+Next, we manually add the ``MyApp Application`` to the source Node and
explicitly call the ``Start`` and ``Stop`` methods on the
``Application`` to tell it when to start and stop doing its thing.
We need to actually do the connect from the receiver point-to-point
-``NetDevice`` to our callback now.
+``NetDevice`` drop event to our ``RxDrop`` callback now.
::
@@ -1981,12 +2019,12 @@ we enter the teardown phase. In this case, ``Simulator::Destroy``
takes care of the gory details and we just return a success code after
it completes.
-Running fifth.cc
-++++++++++++++++
+Running ``fifth.cc``
+++++++++++++++++++++
Since we have provided the file ``fifth.cc`` for you, if you have
-built your distribution (in debug mode since it uses NS_LOG -- recall
-that optimized builds optimize out NS_LOGs) it will be waiting for you
+built your distribution (in debug mode since it uses ``NS_LOG`` -- recall
+that optimized builds optimize out ``NS_LOG``) it will be waiting for you
to run.
.. sourcecode:: bash
@@ -2045,7 +2083,7 @@ Using Mid-Level Helpers
In the previous section, we showed how to hook a trace source and get
hopefully interesting information out of a simulation. Perhaps you
will recall that we called logging to the standard output using
-``std::cout`` a "Blunt Instrument" much earlier in this chapter. We
+``std::cout`` a "blunt instrument" much earlier in this chapter. We
also wrote about how it was a problem having to parse the log output
in order to isolate interesting information. It may have occurred to
you that we just spent a lot of time implementing an example that
@@ -2062,14 +2100,14 @@ provided in |ns3| to do just that and complete the picture.
We provide a script that writes the cwnd change and drop events
developed in the example ``fifth.cc`` to disk in separate files. The
cwnd changes are stored as a tab-separated ASCII file and the drop
-events are stored in a pcap file. The changes to make this happen are
+events are stored in a PCAP file. The changes to make this happen are
quite small.
-A sixth.cc Walkthrough
-~~~~~~~~~~~~~~~~~~~~~~
+Walkthrough: ``sixth.cc``
+~~~~~~~~~~~~~~~~~~~~~~~~~
Let's take a look at the changes required to go from ``fifth.cc`` to
-``sixth.cc``. Open ``examples/tutorial/fifth.cc`` in your favorite
+``sixth.cc``. Open ``examples/tutorial/sixth.cc`` in your favorite
editor. You can see the first change by searching for CwndChange.
You will find that we have changed the signatures for the trace sinks
and have added a single line to each sink that writes the traced
@@ -2096,12 +2134,12 @@ This is an object that holds (keeps safely alive) a C++ output stream.
It turns out that this is a very simple object, but one that manages
lifetime issues for the stream and solves a problem that even
experienced C++ users run into. It turns out that the copy
-constructor for ostream is marked private. This means that ostreams
-do not obey value semantics and cannot be used in any mechanism that
-requires the stream to be copied. This includes the |ns3| callback
-system, which as you may recall, requires objects that obey value
-semantics. Further notice that we have added the following line in
-the ``CwndChange`` trace sink implementation::
+constructor for ``std::ostream`` is marked private. This means that
+``std::ostreams`` do not obey value semantics and cannot be used in
+any mechanism that requires the stream to be copied. This includes
+the |ns3| callback system, which as you may recall, requires objects
+that obey value semantics. Further notice that we have added the
+following line in the ``CwndChange`` trace sink implementation::
*stream->GetStream () << Simulator::Now ().GetSeconds () << "\t" << oldCwnd << "\t" << newCwnd << std::endl;
@@ -2115,9 +2153,9 @@ carrying around a ``std::ofstream`` for you, and you can use it here
like any other output stream.
A similar situation happens in ``RxDrop`` except that the object being
-passed around (a ``Ptr``) represents a pcap file.
+passed around (a ``Ptr``) represents a PCAP file.
There is a one-liner in the trace sink to write a timestamp and the
-contents of the packet being dropped to the pcap file::
+contents of the packet being dropped to the PCAP file::
file->Write(Simulator::Now(), p);
@@ -2144,15 +2182,15 @@ rich set of functions to make using text (ASCII) files easy. We are
just going to illustrate the use of the file stream creation function
here.
-The ``CreateFileStream{}`` function is basically going to instantiate
-a std::ofstream object and create a new file (or truncate an existing
-file). This ofstream is packaged up in an |ns3| object for lifetime
+The ``CreateFileStream`` function is basically going to instantiate
+a ``std::ofstream`` object and create a new file (or truncate an existing
+file). This ``std::ofstream`` is packaged up in an |ns3| object for lifetime
management and copy constructor issue resolution.
We then take this |ns3| object representing the file and pass it to
``MakeBoundCallback()``. This function creates a callback just like
``MakeCallback()``, but it "binds" a new value to the callback. This
-value is added to the callback before it is called.
+value is added as the first argument to the callback before it is called.
Essentially, ``MakeBoundCallback(&CwndChange, stream)`` causes the
trace source to add the additional "stream" parameter to the front of
@@ -2162,7 +2200,7 @@ shown above, which includes the "extra" parameter
``Ptr stream``.
In the second section of code in the snippet above, we instantiate a
-``PcapHelper`` to do the same thing for our pcap trace file that we
+``PcapHelper`` to do the same thing for our PCAP trace file that we
did with the ``AsciiTraceHelper``. The line of code,
::
@@ -2170,23 +2208,24 @@ did with the ``AsciiTraceHelper``. The line of code,
Ptr file = pcapHelper.CreateFile ("sixth.pcap",
"w", PcapHelper::DLT_PPP);
-creates a pcap file named "sixth.pcap" with file mode "w". This means
-that the new file is to truncated if an existing file with that name
-is found. The final parameter is the "data link type" of the new pcap
-file. These are the same as the pcap library data link types defined
-in ``bpf.h`` if you are familar with pcap. In this case, ``DLT_PPP``
-indicates that the pcap file is going to contain packets prefixed with
-point to point headers. This is true since the packets are coming
-from our point-to-point device driver. Other common data link types
-are DLT_EN10MB (10 MB Ethernet) appropriate for csma devices and
-DLT_IEEE802_11 (IEEE 802.11) appropriate for wifi devices. These are
-defined in ``src/network/helper/trace-helper.h`` if you are interested
-in seeing the list. The entries in the list match those in ``bpf.h``
-but we duplicate them to avoid a pcap source dependence.
+creates a PCAP file named "sixth.pcap" with file mode "w". This means
+that the new file is truncated (contents deleted) if an existing file
+with that name is found. The final parameter is the "data link type"
+of the new PCAP file. These are the same as the PCAP library data
+link types defined in ``bpf.h`` if you are familar with PCAP. In this
+case, ``DLT_PPP`` indicates that the PCAP file is going to contain
+packets prefixed with point to point headers. This is true since the
+packets are coming from our point-to-point device driver. Other
+common data link types are DLT_EN10MB (10 MB Ethernet) appropriate for
+csma devices and DLT_IEEE802_11 (IEEE 802.11) appropriate for wifi
+devices. These are defined in ``src/network/helper/trace-helper.h``
+if you are interested in seeing the list. The entries in the list
+match those in ``bpf.h`` but we duplicate them to avoid a PCAP source
+dependence.
-A |ns3| object representing the pcap file is returned from
+A |ns3| object representing the PCAP file is returned from
``CreateFile`` and used in a bound callback exactly as it was in the
-ascii case.
+ASCII case.
An important detour: It is important to notice that even though both
of these objects are declared in very similar ways,
@@ -2197,13 +2236,13 @@ of these objects are declared in very similar ways,
Ptr stream ...
The underlying objects are entirely different. For example, the
-Ptr is a smart pointer to an |ns3| Object that is a
-fairly heaviweight thing that supports ``Attributes`` and is
-integrated into the config system. The Ptr, on
-the other hand, is a smart pointer to a reference counted object that
-is a very lightweight thing. Remember to always look at the object
-you are referencing before making any assumptions about the "powers"
-that object may have.
+``Ptr`` is a smart pointer to an |ns3| Object that is
+a fairly heavyweight thing that supports Attributes and is integrated
+into the Config system. The ``Ptr``, on the
+other hand, is a smart pointer to a reference counted object that is a
+very lightweight thing. Remember to look at the object you are
+referencing before making any assumptions about the "powers" that
+object may have.
For example, take a look at ``src/network/utils/pcap-file-wrapper.h``
in the distribution and notice,
@@ -2224,11 +2263,11 @@ inheritance. Then look at
that this object is not an |ns3| Object at all, it is "merely" a C++
object that happens to support intrusive reference counting.
-The point here is that just because you read Ptr it does
-not necessarily mean that "something" is an |ns3| Object on which you
-can hang |ns3| ``Attributes``, for example.
+The point here is that just because you read ``Ptr`` it does
+not necessarily mean that ``something`` is an |ns3| Object on which you
+can hang |ns3| Attributes, for example.
-Now, back to the example. If you now build and run this example,
+Now, back to the example. If you build and run this example,
.. sourcecode:: bash
@@ -2260,7 +2299,7 @@ window and a new congestion window suitable for directly importing
into your plot program. There are no extraneous prints in the file,
no parsing or editing is required.
-Since "sixth.pcap" is a pcap file, you can fiew it with ``tcpdump``.
+Since "sixth.pcap" is a PCAP file, you can fiew it with ``tcpdump``.
.. sourcecode:: bash
@@ -2271,7 +2310,7 @@ Since "sixth.pcap" is a pcap file, you can fiew it with ``tcpdump``.
7.426220 IP 10.1.1.1.49153 > 10.1.1.2.8080: Flags [.], seq 785704:786240, ack 1, win 32768, options [TS val 7423 ecr 7421,eol], length 536
9.630693 IP 10.1.1.1.49153 > 10.1.1.2.8080: Flags [.], seq 882688:883224, ack 1, win 32768, options [TS val 9620 ecr 9618,eol], length 536
-You have a pcap file with the packets that were dropped in the
+You have a PCAP file with the packets that were dropped in the
simulation. There are no other packets present in the file and there
is nothing else present to make life difficult.
@@ -2310,12 +2349,12 @@ and we did this in only 18 lines of code::
Ptr file = pcapHelper.CreateFile ("sixth.pcap", "w", PcapHelper::DLT_PPP);
devices.Get (1)->TraceConnectWithoutContext("PhyRxDrop", MakeBoundCallback (&RxDrop, file));
-Using Trace Helpers
-*******************
+Trace Helpers
+*************
The |ns3| trace helpers provide a rich environment for configuring and
selecting different trace events and writing them to files. In
-previous sections, primarily "Building Topologies," we have seen
+previous sections, primarily :ref:`BuildingTopologies`, we have seen
several varieties of the trace helper methods designed for use inside
other (device) helpers.
@@ -2333,29 +2372,29 @@ for all of the trace-related methods found in the system. We will now
take a little time and take a look at the "big picture".
There are currently two primary use cases of the tracing helpers in
-|ns3|: Device helpers and protocol helpers. Device helpers look at
+|ns3|: device helpers and protocol helpers. Device helpers look at
the problem of specifying which traces should be enabled through a
-node, device pair. For example, you may want to specify that pcap
+(node, device) pair. For example, you may want to specify that PCAP
tracing should be enabled on a particular device on a specific node.
This follows from the |ns3| device conceptual model, and also the
conceptual models of the various device helpers. Following naturally
-from this, the files created follow a -- naming
+from this, the files created follow a ``--`` naming
convention.
Protocol helpers look at the problem of specifying which traces should
be enabled through a protocol and interface pair. This follows from
the |ns3| protocol stack conceptual model, and also the conceptual
models of internet stack helpers. Naturally, the trace files should
-follow a -- naming convention.
+follow a ``--`` naming convention.
The trace helpers therefore fall naturally into a two-dimensional
taxonomy. There are subtleties that prevent all four classes from
behaving identically, but we do strive to make them all work as
-similarly as possible; and whenever p
-ossible there are analogs for all methods in all classes.
+similarly as possible; and whenever possible there are analogs for all
+methods in all classes.
+-----------------+---------+---------+
- | | pcap | ascii |
+ | | PCAP | ASCII |
+=================+=========+=========+
| Device Helper | |check| | |check| |
+-----------------+---------+---------+
@@ -2364,25 +2403,28 @@ ossible there are analogs for all methods in all classes.
We use an approach called a ``mixin`` to add tracing functionality to
our helper classes. A ``mixin`` is a class that provides
-functionality to that is inherited by a subclass. Inheriting from a
+functionality when it is inherited by a subclass. Inheriting from a
mixin is not considered a form of specialization but is really a way
to collect functionality.
Let's take a quick look at all four of these cases and their
respective ``mixins``.
-Pcap Tracing Device Helpers
-+++++++++++++++++++++++++++
+Device Helpers
+++++++++++++++
-The goal of these helpers is to make it easy to add a consistent pcap
+PCAP
+~~~~
+
+The goal of these helpers is to make it easy to add a consistent PCAP
trace facility to an |ns3| device. We want all of the various flavors
-of pcap tracing to work the same across all devices, so the methods of
+of PCAP tracing to work the same across all devices, so the methods of
these helpers are inherited by device helpers. Take a look at
``src/network/helper/trace-helper.h`` if you want to follow the
discussion while looking at real code.
The class ``PcapHelperForDevice`` is a ``mixin`` provides the high
-level functionality for using pcap tracing in an |ns3| device. Every
+level functionality for using PCAP tracing in an |ns3| device. Every
device must implement a single virtual method inherited from this
class.
@@ -2394,22 +2436,22 @@ The signature of this method reflects the device-centric view of the
situation at this level. All of the public methods inherited from
class ``PcapUserHelperForDevice`` reduce to calling this single
device-dependent implementation method. For example, the lowest level
-pcap method,
+PCAP method,
::
void EnablePcap (std::string prefix, Ptr nd, bool promiscuous = false, bool explicitFilename = false);
will call the device implementation of ``EnablePcapInternal``
-directly. All other public pcap tracing methods build on this
+directly. All other public PCAP tracing methods build on this
implementation to provide additional user-level functionality. What
this means to the user is that all device helpers in the system will
-have all of the pcap trace methods available; and these methods will
+have all of the PCAP trace methods available; and these methods will
all work in the same way across devices if the device implements
``EnablePcapInternal`` correctly.
-Pcap Tracing Device Helper Methods
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Methods
+#######
::
@@ -2421,7 +2463,7 @@ Pcap Tracing Device Helper Methods
void EnablePcapAll (std::string prefix, bool promiscuous = false);
In each of the methods shown above, there is a default parameter
-called ``promiscuous`` that defaults to false. This parameter
+called ``promiscuous`` that defaults to ``false``. This parameter
indicates that the trace should not be gathered in promiscuous mode.
If you do want your traces to include all traffic seen by the device
(and if the device supports a promiscuous mode) simply add a true
@@ -2439,14 +2481,14 @@ by ``nd``.
The first two methods also include a default parameter called
``explicitFilename`` that will be discussed below.
-You are encouraged to peruse the Doxygen for class
+You are encouraged to peruse the API Documentation for class
``PcapHelperForDevice`` to find the details of these methods; but to
summarize ...
-You can enable pcap tracing on a particular node/net-device pair by
+* You can enable PCAP tracing on a particular node/net-device pair by
providing a ``Ptr`` to an ``EnablePcap`` method. The
``Ptr`` is implicit since the net device must belong to exactly
-one ``Node``. For example,
+ one Node. For example,
::
@@ -2454,11 +2496,11 @@ one ``Node``. For example,
...
helper.EnablePcap ("prefix", nd);
-You can enable pcap tracing on a particular node/net-device pair by
+* You can enable PCAP tracing on a particular node/net-device pair by
providing a ``std::string`` representing an object name service string
to an ``EnablePcap`` method. The ``Ptr`` is looked up from
the name string. Again, the ```` is implicit since the named
-net device must belong to exactly one ``Node``. For example,
+ net device must belong to exactly one Node. For example,
::
@@ -2467,12 +2509,12 @@ net device must belong to exactly one ``Node``. For example,
...
helper.EnablePcap ("prefix", "server/ath0");
-You can enable pcap tracing on a collection of node/net-device pairs
+* You can enable PCAP tracing on a collection of node/net-device pairs
by providing a ``NetDeviceContainer``. For each ``NetDevice`` in the
container the type is checked. For each device of the proper type
(the same type as is managed by the device helper), tracing is
enabled. Again, the ```` is implicit since the found net device
-must belong to exactly one ``Node``. For example,
+ must belong to exactly one Node. For example,
::
@@ -2480,10 +2522,10 @@ must belong to exactly one ``Node``. For example,
...
helper.EnablePcap ("prefix", d);
-You can enable pcap tracing on a collection of node/net-device pairs
-by providing a ``NodeContainer``. For each ``Node`` in the
+* You can enable PCAP tracing on a collection of node/net-device pairs
+ by providing a ``NodeContainer``. For each Node in the
``NodeContainer`` its attached ``NetDevices`` are iterated. For each
-``NetDevice`` attached to each node in the container, the type of that
+ ``NetDevice`` attached to each Node in the container, the type of that
device is checked. For each device of the proper type (the same type
as is managed by the device helper), tracing is enabled.
@@ -2493,43 +2535,43 @@ as is managed by the device helper), tracing is enabled.
...
helper.EnablePcap ("prefix", n);
-You can enable pcap tracing on the basis of node ID and device ID as
-well as with explicit ``Ptr``. Each ``Node`` in the system has an
-integer node ID and each device connected to a node has an integer
+* You can enable PCAP tracing on the basis of Node ID and device ID as
+ well as with explicit ``Ptr``. Each Node in the system has an
+ integer Node ID and each device connected to a Node has an integer
device ID.
::
helper.EnablePcap ("prefix", 21, 1);
-Finally, you can enable pcap tracing for all devices in the system,
+* Finally, you can enable PCAP tracing for all devices in the system,
with the same type as that managed by the device helper.
::
helper.EnablePcapAll ("prefix");
-Pcap Tracing Device Helper Filename Selection
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Filenames
+#########
Implicit in the method descriptions above is the construction of a
-complete filename by the implementation method. By convention, pcap
-traces in the |ns3| system are of the form "--.pcap"
+complete filename by the implementation method. By convention, PCAP
+traces in the |ns3| system are of the form ``--.pcap``
-As previously mentioned, every node in the system will have a
-system-assigned node id; and every device will have an interface index
+As previously mentioned, every Node in the system will have a
+system-assigned Node id; and every device will have an interface index
(also called a device id) relative to its node. By default, then, a
-pcap trace file created as a result of enabling tracing on the first
-device of node 21 using the prefix "prefix" would be
-"prefix-21-1.pcap".
+PCAP trace file created as a result of enabling tracing on the first
+device of Node 21 using the prefix "prefix" would be
+``prefix-21-1.pcap``.
You can always use the |ns3| object name service to make this more
clear. For example, if you use the object name service to assign the
-name "server" to node 21, the resulting pcap trace file name will
-automatically become, "prefix-server-1.pcap" and if you also assign
-the name "eth0" to the device, your pcap file name will automatically
-pick this up and be called "prefix-server-eth0.pcap".
+name "server" to Node 21, the resulting PCAP trace file name will
+automatically become, ``prefix-server-1.pcap`` and if you also assign
+the name "eth0" to the device, your PCAP file name will automatically
+pick this up and be called ``prefix-server-eth0.pcap``.
Finally, two of the methods shown above,
@@ -2541,12 +2583,12 @@ Finally, two of the methods shown above,
have a default parameter called ``explicitFilename``. When set to
true, this parameter disables the automatic filename completion
mechanism and allows you to create an explicit filename. This option
-is only available in the methods which enable pcap tracing on a single
+is only available in the methods which enable PCAP tracing on a single
device.
For example, in order to arrange for a device helper to create a
-single promiscuous pcap capture file of a specific name
-("my-pcap-file.pcap") on a given device, one could::
+single promiscuous PCAP capture file of a specific name
+``my-pcap-file.pcap`` on a given device, one could::
Ptr nd;
...
@@ -2556,18 +2598,18 @@ The first ``true`` parameter enables promiscuous mode traces and the
second tells the helper to interpret the ``prefix`` parameter as a
complete filename.
-Ascii Tracing Device Helpers
-++++++++++++++++++++++++++++
+ASCII
+~~~~~
-The behavior of the ascii trace helper ``mixin`` is substantially
-similar to the pcap version. Take a look at
+The behavior of the ASCII trace helper ``mixin`` is substantially
+similar to the PCAP version. Take a look at
``src/network/helper/trace-helper.h`` if you want to follow the
discussion while looking at real code.
The class ``AsciiTraceHelperForDevice`` adds the high level
-functionality for using ascii tracing to a device helper class. As in
-the pcap case, every device must implement a single virtual method
-inherited from the ascii trace ``mixin``.
+functionality for using ASCII tracing to a device helper class. As in
+the PCAP case, every device must implement a single virtual method
+inherited from the ASCII trace ``mixin``.
::
@@ -2580,7 +2622,7 @@ inherited from the ascii trace ``mixin``.
The signature of this method reflects the device-centric view of the
situation at this level; and also the fact that the helper may be
writing to a shared output stream. All of the public
-ascii-trace-related methods inherited from class
+ASCII-trace-related methods inherited from class
``AsciiTraceHelperForDevice`` reduce to calling this single device-
dependent implementation method. For example, the lowest level ascii
trace methods,
@@ -2593,15 +2635,15 @@ trace methods,
will call the device implementation of ``EnableAsciiInternal``
directly, providing either a valid prefix or stream. All other public
-ascii tracing methods will build on these low-level functions to
+ASCII tracing methods will build on these low-level functions to
provide additional user-level functionality. What this means to the
user is that all device helpers in the system will have all of the
-ascii trace methods available; and these methods will all work in the
+ASCII trace methods available; and these methods will all work in the
same way across devices if the devices implement
``EnablAsciiInternal`` correctly.
-Ascii Tracing Device Helper Methods
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Methods
+#######
::
@@ -2623,24 +2665,23 @@ Ascii Tracing Device Helper Methods
void EnableAscii (std::string prefix, uint32_t nodeid, uint32_t deviceid, bool explicitFilename);
void EnableAscii (Ptr stream, uint32_t nodeid, uint32_t deviceid);
-You are encouraged to peruse the Doxygen for class
+You are encouraged to peruse the API Documentation for class
``AsciiTraceHelperForDevice`` to find the details of these methods;
but to summarize ...
-There are twice as many methods available for ascii tracing as there
-were for pcap tracing. This is because, in addition to the pcap-style
-model where traces from each unique node/device pair are written to a
-unique file, we support a model in which trace information for many
-node/device pairs is written to a common file. This means that the
--- file name generation mechanism is replaced by
-a mechanism to refer to a common file; and the number of API methods
-is doubled to allow all combinations.
+* There are twice as many methods available for ASCII tracing as
+ there were for PCAP tracing. This is because, in addition to the
+ PCAP-style model where traces from each unique node/device pair are
+ written to a unique file, we support a model in which trace
+ information for many node/device pairs is written to a common file.
+ This means that the -- file name generation
+ mechanism is replaced by a mechanism to refer to a common file; and
+ the number of API methods is doubled to allow all combinations.
-Just as in pcap tracing, you can enable ascii tracing on a particular
-node/net-device pair by providing a ``Ptr`` to an
-``EnableAscii`` method. The ``Ptr`` is implicit since the net
-device must belong to exactl
-y one ``Node``. For example,
+* Just as in PCAP tracing, you can enable ASCII tracing on a
+ particular (node, net-device) pair by providing a ``Ptr``
+ to an ``EnableAscii`` method. The ``Ptr`` is implicit since
+ the net device must belong to exactly one Node. For example,
::
@@ -2648,20 +2689,20 @@ y one ``Node``. For example,
...
helper.EnableAscii ("prefix", nd);
-The first four methods also include a default parameter called
-``explicitFilename`` that operate similar to equivalent parameters in
-the pcap case.
+* The first four methods also include a default parameter called
+ ``explicitFilename`` that operate similar to equivalent parameters
+ in the PCAP case.
-In this case, no trace contexts are written to the ascii trace file
-since they would be redundant. The system will pick the file name to
-be created using the same rules as described in the pcap section,
-except that the file will have the suffix ".tr" instead of ".pcap".
+ In this case, no trace contexts are written to the ASCII trace file
+ since they would be redundant. The system will pick the file name
+ to be created using the same rules as described in the PCAP section,
+ except that the file will have the suffix ``.tr`` instead of
+ ``.pcap``.
-If you want to enable ascii tracing on more than one net device and
-have all traces sent to a single file, you can do that as well by
-using an object to refe
-r to a single file. We have already seen this in the "cwnd" example
-above::
+* If you want to enable ASCII tracing on more than one net device
+ and have all traces sent to a single file, you can do that as well
+ by using an object to refer to a single file. We have already seen
+ this in the "cwnd" example above::
Ptr nd1;
Ptr nd2;
@@ -2672,16 +2713,17 @@ above::
helper.EnableAscii (stream, nd2);
-In this case, trace contexts are written to the ascii trace file since
-they are required to disambiguate traces from the two devices. Note
-that since the user is completely specifying the file name, the string
-should include the ",tr" for consistency.
+ In this case, trace contexts *are* written to the ASCII trace file
+ since they are required to disambiguate traces from the two devices.
+ Note that since the user is completely specifying the file name, the
+ string should include the ``,tr`` suffix for consistency.
-You can enable ascii tracing on a particular node/net-device pair by
-providing a ``std::string`` representing an object name service string
-to an ``EnablePcap`` method. The ``Ptr`` is looked up from
-the name string. Again, the ```` is implicit since the named
-net device must belong to exactly one ``Node``. For example,
+* You can enable ASCII tracing on a particular (node, net-device)
+ pair by providing a ``std::string`` representing an object name
+ service string to an ``EnablePcap`` method. The ``Ptr``
+ is looked up from the name string. Again, the ```` is
+ implicit since the named net device must belong to exactly one Node.
+ For example,
::
@@ -2693,10 +2735,11 @@ net device must belong to exactly one ``Node``. For example,
helper.EnableAscii ("prefix", "client/eth0");
helper.EnableAscii ("prefix", "server/eth0");
-This would result in two files named "prefix-client-eth0.tr" and
-"prefix-server-eth0.tr" with traces for each device in the respective
-trace file. Since all of the EnableAscii functions are overloaded to
-take a stream wrapper, you can use that form as well::
+ This would result in two files named ``prefix-client-eth0.tr`` and
+ ``prefix-server-eth0.tr`` with traces for each device in the
+ respective trace file. Since all of the ``EnableAscii`` functions
+ are overloaded to take a stream wrapper, you can use that form as
+ well::
Names::Add ("client" ...);
Names::Add ("client/eth0" ...);
@@ -2708,16 +2751,17 @@ take a stream wrapper, you can use that form as well::
helper.EnableAscii (stream, "client/eth0");
helper.EnableAscii (stream, "server/eth0");
-This would result in a single trace file called "trace-file-name.tr"
-that contains all of the trace events for both devices. The events
-would be disambiguated by trace context strings.
+ This would result in a single trace file called
+ ``trace-file-name.tr`` that contains all of the trace events for
+ both devices. The events would be disambiguated by trace context
+ strings.
-You can enable ascii tracing on a collection of node/net-device pairs
-by providing a ``NetDeviceContainer``. For each ``NetDevice`` in the
-container the type is checked. For each device of the proper type
-(the same type as is managed by the device helper), tracing is
-enabled. Again, the ```` is implicit since the found net device
-must belong to exactly one ``Node``. For example,
+* You can enable ASCII tracing on a collection of (node, net-device)
+ pairs by providing a ``NetDeviceContainer``. For each ``NetDevice``
+ in the container the type is checked. For each device of the proper
+ type (the same type as is managed by the device helper), tracing is
+ enabled. Again, the ```` is implicit since the found net
+ device must belong to exactly one Node. For example,
::
@@ -2725,8 +2769,10 @@ must belong to exactly one ``Node``. For example,
...
helper.EnableAscii ("prefix", d);
-This would result in a number of ascii trace files being created, each
-of which follows the --.tr convention.
+ This would result in a number of ASCII trace files being created,
+ each of which follows the ``--.tr``
+ convention.
+
Combining all of the traces into a single file is accomplished
similarly to the examples above::
@@ -2736,12 +2782,12 @@ similarly to the examples above::
...
helper.EnableAscii (stream, d);
-You can enable ascii tracing on a collection of node/net-device pairs
-by providing a ``NodeContainer``. For each ``Node`` in the
-``NodeContainer`` its attached ``NetDevices`` are iterated. For each
-``NetDevice`` attached to each node in the container, the type of that
-device is checked. For each device of the proper type (the same type
-as is managed by the device helper), tracing is enabled.
+* You can enable ASCII tracing on a collection of (node, net-device)
+ pairs by providing a ``NodeContainer``. For each Node in the
+ ``NodeContainer`` its attached ``NetDevices`` are iterated. For
+ each ``NetDevice`` attached to each Node in the container, the type
+ of that device is checked. For each device of the proper type (the
+ same type as is managed by the device helper), tracing is enabled.
::
@@ -2749,14 +2795,14 @@ as is managed by the device helper), tracing is enabled.
...
helper.EnableAscii ("prefix", n);
-This would result in a number of ascii trace files being created, each
-of which follows the --.tr convention.
-Combining all of the traces into a single file is accomplished
-similarly to the examples above.
+ This would result in a number of ASCII trace files being created,
+ each of which follows the ``--.tr``
+ convention. Combining all of the traces into a single file is
+ accomplished similarly to the examples above.
-You can enable pcap tracing on the basis of node ID and device ID as
-well as with explicit ``Ptr``. Each ``Node`` in the system has an
-integer node ID and each device connected to a node has an integer
+* You can enable PCAP tracing on the basis of Node ID and device ID
+ as well as with explicit ``Ptr``. Each Node in the system has an
+ integer Node ID and each device connected to a Node has an integer
device ID.
::
@@ -2766,40 +2812,40 @@ device ID.
Of course, the traces can be combined into a single file as shown
above.
-Finally, you can enable pcap tracing for all devices in the system,
-with the same type as that managed by the device helper.
+* Finally, you can enable PCAP tracing for all devices in the
+ system, with the same type as that managed by the device helper.
::
helper.EnableAsciiAll ("prefix");
-This would result in a number of ascii trace files being created, one
-for every device in the system of the type managed by the helper. All
-of these files will follow the --.tr
-convention. Combining all of the traces into a single file is
-accomplished similarly to the examples above.
+ This would result in a number of ASCII trace files being created,
+ one for every device in the system of the type managed by the
+ helper. All of these files will follow the ``--.tr`` convention. Combining all of the traces into a
+ single file is accomplished similarly to the examples above.
-Ascii Tracing Device Helper Filename Selection
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Filenames
+#########
Implicit in the prefix-style method descriptions above is the
construction of the complete filenames by the implementation method.
-By convention, ascii traces in the |ns3| system are of the form
-"--.tr"
+By convention, ASCII traces in the |ns3| system are of the form
+``--.tr``
-As previously mentioned, every node in the system will have a
-system-assigned node id; and every device will have an interface index
+As previously mentioned, every Node in the system will have a
+system-assigned Node id; and every device will have an interface index
(also called a device id) relative to its node. By default, then, an
-ascii trace file created as a result of enabling tracing on the first
-device of node 21, using the prefix "prefix", would be
-"prefix-21-1.tr".
+ASCII trace file created as a result of enabling tracing on the first
+device of Node 21, using the prefix "prefix", would be
+``prefix-21-1.tr``.
You can always use the |ns3| object name service to make this more
clear. For example, if you use the object name service to assign the
-name "server" to node 21, the resulting ascii trace file name will
-automatically become, "prefix-server-1.tr" and if you also assign the
-name "eth0" to the device, your ascii trace file name will
-automatically pick this up and be called "prefix-server-eth0.tr".
+name "server" to Node 21, the resulting ASCII trace file name will
+automatically become, ``prefix-server-1.tr`` and if you also assign the
+name "eth0" to the device, your ASCII trace file name will
+automatically pick this up and be called ``prefix-server-eth0.tr``.
Several of the methods have a default parameter called
``explicitFilename``. When set to true, this parameter disables the
@@ -2807,12 +2853,15 @@ automatic filename completion mechanism and allows you to create an
explicit filename. This option is only available in the methods which
take a prefix and enable tracing on a single device.
-Pcap Tracing Protocol Helpers
-+++++++++++++++++++++++++++++
+Protocol Helpers
+++++++++++++++++
+
+PCAP
+~~~~
The goal of these ``mixins`` is to make it easy to add a consistent
-pcap trace facility to protocols. We want all of the various flavors
-of pcap tracing to work the same across all protocols, so the methods
+PCAP trace facility to protocols. We want all of the various flavors
+of PCAP tracing to work the same across all protocols, so the methods
of these helpers are inherited by stack helpers. Take a look at
``src/network/helper/trace-helper.h`` if you want to follow the
discussion while looking at real code.
@@ -2824,7 +2873,7 @@ instead of a ``Ptr`` and call ``EnablePcapIpv6`` instead of
``EnablePcapIpv4``.
The class ``PcapHelperForIpv4`` provides the high level functionality
-for using pcap tracing in the ``Ipv4`` protocol. Each protocol helper
+for using PCAP tracing in the ``Ipv4`` protocol. Each protocol helper
enabling these methods must implement a single virtual method
inherited from this class. There will be a separate implementation
for ``Ipv6``, for example, but the only difference will be in the
@@ -2843,7 +2892,7 @@ The signature of this method reflects the protocol and
interface-centric view of the situation at this level. All of the
public methods inherited from class ``PcapHelperForIpv4`` reduce to
calling this single device-dependent implementation method. For
-example, the lowest level pcap method,
+example, the lowest level PCAP method,
::
@@ -2851,19 +2900,19 @@ example, the lowest level pcap method,
will call the device implementation of ``EnablePcapIpv4Internal``
-directly. All other public pcap tracing methods build on this
+directly. All other public PCAP tracing methods build on this
implementation to provide additional user-level functionality. What
this means to the user is that all protocol helpers in the system will
-have all of the pcap trace methods available; and these methods will
+have all of the PCAP trace methods available; and these methods will
all work in the same way across protocols if the helper implements
``EnablePcapIpv4Internal`` correctly.
-Pcap Tracing Protocol Helper Methods
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Methods
+#######
These methods are designed to be in one-to-one correspondence with the
-``Node``- and ``NetDevice``- centric versions of the device versions.
-Instead of ``Node`` and ``NetDevice`` pair constraints, we use
+Node- and ``NetDevice``- centric versions of the device versions.
+Instead of Node and ``NetDevice`` pair constraints, we use
protocol and interface constraints.
Note that just like in the device version, there are six methods::
@@ -2875,11 +2924,11 @@ Note that just like in the device version, there are six methods::
void EnablePcapIpv4 (std::string prefix, uint32_t nodeid, uint32_t interface, bool explicitFilename);
void EnablePcapIpv4All (std::string prefix);
-You are encouraged to peruse the Doxygen for class
+You are encouraged to peruse the API Documentation for class
``PcapHelperForIpv4`` to find the details of these methods; but to
summarize ...
-You can enable pcap tracing on a particular protocol/interface pair by
+* You can enable PCAP tracing on a particular protocol/interface pair by
providing a ``Ptr`` and ``interface`` to an ``EnablePcap``
method. For example,
@@ -2889,7 +2938,7 @@ method. For example,
...
helper.EnablePcapIpv4 ("prefix", ipv4, 0);
-You can enable pcap tracing on a particular node/net-device pair by
+* You can enable PCAP tracing on a particular node/net-device pair by
providing a ``std::string`` representing an object name service string
to an ``EnablePcap`` method. The ``Ptr`` is looked up from the
name string. For example,
@@ -2900,7 +2949,7 @@ name string. For example,
...
helper.EnablePcapIpv4 ("prefix", "serverIpv4", 1);
-You can enable pcap tracing on a collection of protocol/interface
+* You can enable PCAP tracing on a collection of protocol/interface
pairs by providing an ``Ipv4InterfaceContainer``. For each ``Ipv4`` /
interface pair in the container the protocol type is checked. For
each protocol of the proper type (the same type as is managed by the
@@ -2919,8 +2968,8 @@ For example,
...
helper.EnablePcapIpv4 ("prefix", interfaces);
-You can enable pcap tracing on a collection of protocol/interface
-pairs by providing a ``NodeContainer``. For each ``Node`` in the
+* You can enable PCAP tracing on a collection of protocol/interface
+ pairs by providing a ``NodeContainer``. For each Node in the
``NodeContainer`` the appropriate protocol is found. For each
protocol, its interfaces are enumerated and tracing is enabled on the
resulting pairs. For example,
@@ -2931,7 +2980,7 @@ resulting pairs. For example,
...
helper.EnablePcapIpv4 ("prefix", n);
-You can enable pcap tracing on the basis of node ID and interface as
+* You can enable PCAP tracing on the basis of Node ID and interface as
well. In this case, the node-id is translated to a ``Ptr`` and
the appropriate protocol is looked up in the node. The resulting
protocol and interface are used to specify the resulting trace source.
@@ -2940,56 +2989,57 @@ protocol and interface are used to specify the resulting trace source.
helper.EnablePcapIpv4 ("prefix", 21, 1);
-Finally, you can enable pcap tracing for all interfaces in the system, with
-associated protocol being the same type as that managed by the device helper.
+* Finally, you can enable PCAP tracing for all interfaces in the
+ system, with associated protocol being the same type as that managed
+ by the device helper.
::
helper.EnablePcapIpv4All ("prefix");
-Pcap Tracing Protocol Helper Filename Selection
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Filenames
+#########
Implicit in all of the method descriptions above is the construction
of the complete filenames by the implementation method. By
-convention, pcap traces taken for devices in the |ns3| system are of
+convention, PCAP traces taken for devices in the |ns3| system are of
the form "--.pcap". In the case of
protocol traces, there is a one-to-one correspondence between
protocols and ``Nodes``. This is because protocol ``Objects`` are
aggregated to ``Node Objects``. Since there is no global protocol id
-in the system, we use the corresponding node id in file naming.
+in the system, we use the corresponding Node id in file naming.
Therefore there is a possibility for file name collisions in
automatically chosen trace file names. For this reason, the file name
convention is changed for protocol traces.
-As previously mentioned, every node in the system will have a
-system-assigned node id. Since there is a one-to-one correspondence
-between protocol instances and node instances we use the node id.
+As previously mentioned, every Node in the system will have a
+system-assigned Node id. Since there is a one-to-one correspondence
+between protocol instances and Node instances we use the Node id.
Each interface has an interface id relative to its protocol. We use
the convention "-n-i.pcap" for trace
file naming in protocol helpers.
-Therefore, by default, a pcap trace file created as a result of
-enabling tracing on interface 1 of the Ipv4 protocol of node 21 using
+Therefore, by default, a PCAP trace file created as a result of
+enabling tracing on interface 1 of the Ipv4 protocol of Node 21 using
the prefix "prefix" would be "prefix-n21-i1.pcap".
You can always use the |ns3| object name service to make this more
clear. For example, if you use the object name service to assign the
-name "serverIpv4" to the Ptr on node 21, the resulting pcap
+name "serverIpv4" to the Ptr on Node 21, the resulting PCAP
trace file name will automatically become,
"prefix-nserverIpv4-i1.pcap".
Several of the methods have a default parameter called
``explicitFilename``. When set to true, this parameter disables the
automatic filename completion mechanism and allows you to create an
-explicit filename. This option is only availa
-ble in the methods which take a prefix and enable tracing on a single device.
+explicit filename. This option is only available in the methods which
+take a prefix and enable tracing on a single device.
-Ascii Tracing Protocol Helpers
-++++++++++++++++++++++++++++++
+ASCII
+~~~~~
-The behavior of the ascii trace helpers is substantially similar to
-the pcap case. Take a look at ``src/network/helper/trace-helper.h``
+The behavior of the ASCII trace helpers is substantially similar to
+the PCAP case. Take a look at ``src/network/helper/trace-helper.h``
if you want to follow the discussion while looking at real code.
In this section we will be illustrating the methods as applied to the
@@ -2999,7 +3049,7 @@ instead of a ``Ptr`` and call ``EnableAsciiIpv6`` instead of
``EnableAsciiIpv4``.
The class ``AsciiTraceHelperForIpv4`` adds the high level
-functionality for using ascii tracing to a protocol helper. Each
+functionality for using ASCII tracing to a protocol helper. Each
protocol that enables these methods must implement a single virtual
method inherited from this class.
@@ -3017,7 +3067,7 @@ fact that the helper may be writing to a shared output stream. All of
the public methods inherited from class
``PcapAndAsciiTraceHelperForIpv4`` reduce to calling this single
device- dependent implementation method. For example, the lowest
-level ascii trace methods,
+level ASCII trace methods,
::
@@ -3027,15 +3077,15 @@ level ascii trace methods,
will call the device implementation of ``EnableAsciiIpv4Internal``
directly, providing either the prefix or the stream. All other public
-ascii tracing methods will build on these low-level functions to
+ASCII tracing methods will build on these low-level functions to
provide additional user-level functionality. What this means to the
user is that all device helpers in the system will have all of the
-ascii trace methods available; and these methods will all work in the
+ASCII trace methods available; and these methods will all work in the
same way across protocols if the protocols implement
``EnablAsciiIpv4Internal`` correctly.
-Ascii Tracing Protocol Helper Methods
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Methods
+#######
::
@@ -3057,11 +3107,12 @@ Ascii Tracing Protocol Helper Methods
void EnableAsciiIpv4 (std::string prefix, uint32_t nodeid, uint32_t deviceid, bool explicitFilename);
void EnableAsciiIpv4 (Ptr stream, uint32_t nodeid, uint32_t interface);
-You are encouraged to peruse the Doxygen for class ``PcapAndAsciiHelperForIpv4``
-to find the details of these methods; but to summarize ...
+You are encouraged to peruse the API Documentation for class
+``PcapAndAsciiHelperForIpv4`` to find the details of these methods;
+but to summarize ...
-There are twice as many methods available for ascii tracing as there
-were for pcap tracing. This is because, in addition to the pcap-style
+* There are twice as many methods available for ASCII tracing as there
+ were for PCAP tracing. This is because, in addition to the PCAP-style
model where traces from each unique protocol/interface pair are
written to a unique file, we support a model in which trace
information for many protocol/interface pairs is written to a common
@@ -3070,11 +3121,9 @@ generation mechanism is replaced by a mechanism to refer to a common
file; and the number of API methods is doubled to allow all
combinations.
-Just as in pcap tracing, you can enable ascii tracing on a particular
+* Just as in PCAP tracing, you can enable ASCII tracing on a particular
protocol/interface pair by providing a ``Ptr`` and an
-``interface`` to an ``Enab
-leAscii`` method.
-For example,
+ ``interface`` to an ``EnableAscii`` method. For example,
::
@@ -3082,12 +3131,12 @@ For example,
...
helper.EnableAsciiIpv4 ("prefix", ipv4, 1);
-In this case, no trace contexts are written to the ascii trace file
+ In this case, no trace contexts are written to the ASCII trace file
since they would be redundant. The system will pick the file name to
-be created using the same rules as described in the pcap section,
+ be created using the same rules as described in the PCAP section,
except that the file will have the suffix ".tr" instead of ".pcap".
-If you want to enable ascii tracing on more than one interface and
+* If you want to enable ASCII tracing on more than one interface and
have all traces sent to a single file, you can do that as well by
using an object to refer to a single file. We have already something
similar to this in the "cwnd" example above::
@@ -3100,12 +3149,12 @@ similar to this in the "cwnd" example above::
helper.EnableAsciiIpv4 (stream, protocol1, 1);
helper.EnableAsciiIpv4 (stream, protocol2, 1);
-In this case, trace contexts are written to the ascii trace file since
+ In this case, trace contexts are written to the ASCII trace file since
they are required to disambiguate traces from the two interfaces.
Note that since the user is completely specifying the file name, the
string should include the ",tr" for consistency.
-You can enable ascii tracing on a particular protocol by providing a
+* You can enable ASCII tracing on a particular protocol by providing a
``std::string`` representing an object name service string to an
``EnablePcap`` method. The ``Ptr`` is looked up from the name
string. The ```` in the resulting filenames is implicit since
@@ -3137,7 +3186,7 @@ This would result in a single trace file called "trace-file-name.tr"
that contains all of the trace events for both interfaces. The events
would be disambiguated by trace context strings.
-You can enable ascii tracing on a collection of protocol/interface
+* You can enable ASCII tracing on a collection of protocol/interface
pairs by providing an ``Ipv4InterfaceContainer``. For each protocol
of the proper type (the same type as is managed by the device helper),
tracing is enabled for the corresponding interface. Again, the
@@ -3157,7 +3206,7 @@ between each protocol and its node. For example,
...
helper.EnableAsciiIpv4 ("prefix", interfaces);
-This would result in a number of ascii trace files being created, each
+ This would result in a number of ASCII trace files being created, each
of which follows the -n-i.tr convention.
Combining all of the traces into a single file is accomplished
similarly to the examples above::
@@ -3174,8 +3223,8 @@ similarly to the examples above::
...
helper.EnableAsciiIpv4 (stream, interfaces);
-You can enable ascii tracing on a collection of protocol/interface
-pairs by providing a ``NodeContainer``. For each ``Node`` in the
+* You can enable ASCII tracing on a collection of protocol/interface
+ pairs by providing a ``NodeContainer``. For each Node in the
``NodeContainer`` the appropriate protocol is found. For each
protocol, its interfaces are enumerated and tracing is enabled on the
resulting pairs. For example,
@@ -3186,12 +3235,12 @@ resulting pairs. For example,
...
helper.EnableAsciiIpv4 ("prefix", n);
-This would result in a number of ascii trace files being created, each of which
-follows the --.tr convention. Combining
-all of the traces into a single file is accomplished similarly to the
-examples above.
+ This would result in a number of ASCII trace files being created,
+ each of which follows the --.tr
+ convention. Combining all of the traces into a single file is
+ accomplished similarly to the examples above.
-You can enable pcap tracing on the basis of node ID and device ID as
+* You can enable PCAP tracing on the basis of Node ID and device ID as
well. In this case, the node-id is translated to a ``Ptr`` and
the appropriate protocol is looked up in the node. The resulting
protocol and interface are used to specify the resulting trace source.
@@ -3203,7 +3252,7 @@ protocol and interface are used to specify the resulting trace source.
Of course, the traces can be combined into a single file as shown
above.
-Finally, you can enable ascii tracing for all interfaces in the
+* Finally, you can enable ASCII tracing for all interfaces in the
system, with associated protocol being the same type as that managed
by the device helper.
@@ -3211,42 +3260,42 @@ by the device helper.
helper.EnableAsciiIpv4All ("prefix");
-This would result in a number of ascii trace files being created, one
+ This would result in a number of ASCII trace files being created, one
for every interface in the system related to a protocol of the type
managed by the helper. All of these files will follow the
-n-i--.tr"
-As previously mentioned, every node in the system will have a
-system-assigned node id. Since there is a one-to-one correspondence
+As previously mentioned, every Node in the system will have a
+system-assigned Node id. Since there is a one-to-one correspondence
between protocols and nodes we use to node-id to identify the protocol
identity. Every interface on a given protocol will have an interface
index (also called simply an interface) relative to its protocol. By
-default, then, an ascii trace file created as a result of enabling
-tracing on the first device of node 21, using the prefix "prefix",
+default, then, an ASCII trace file created as a result of enabling
+tracing on the first device of Node 21, using the prefix "prefix",
would be "prefix-n21-i1.tr". Use the prefix to disambiguate multiple
protocols per node.
You can always use the |ns3| object name service to make this more
clear. For example, if you use the object name service to assign the
-name "serverIpv4" to the protocol on node 21, and also specify
-interface one, the resulting ascii trace file name will automatically
+name "serverIpv4" to the protocol on Node 21, and also specify
+interface one, the resulting ASCII trace file name will automatically
become, "prefix-nserverIpv4-1.tr".
Several of the methods have a default parameter called
``explicitFilename``. When set to true, this parameter disables the
automatic filename completion mechanism and allows you to create an
-explicit filename. This option is only available in the me
-thods which take a prefix and enable tracing on a single device.
+explicit filename. This option is only available in the methods which
+take a prefix and enable tracing on a single device.
Summary
*******
@@ -3266,7 +3315,7 @@ be immediately accessible to users at higher levels.
This is a very comprehensive system, and we realize that it is a lot
to digest, especially for new users or those not intimately familiar
with C++ and its idioms. We do consider the tracing system a very
-important part of |ns3| and so reco
-mmend becoming as familiar as possible with it. It is
-probably the case that understanding the rest of the |ns3| system will
-be quite simple once you have mastered the tracing system
+important part of |ns3| and so recommend becoming as familiar as
+possible with it. It is probably the case that understanding the rest
+of the |ns3| system will be quite simple once you have mastered the
+tracing system
diff --git a/doc/tutorial/source/tweaking.rst b/doc/tutorial/source/tweaking.rst
index fd98b68b7..f7bd9727f 100644
--- a/doc/tutorial/source/tweaking.rst
+++ b/doc/tutorial/source/tweaking.rst
@@ -5,6 +5,8 @@
Tweaking
--------
+.. _UsingLogging:
+
Using the Logging Module
************************
@@ -412,6 +414,8 @@ message,
Using Command Line Arguments
****************************
+.. _Attribute:
+
Overriding Default Attributes
+++++++++++++++++++++++++++++
Another way you can change how |ns3| scripts behave without editing
@@ -722,6 +726,8 @@ they will automatically be available for setting by your users through the
command line system. If you are a script author, you can add new variables to
your scripts and hook them into the command line system quite painlessly.
+.. _UsingTracingSystem:
+
Using the Tracing System
************************