doc/tutorial/source/tracing.rst
author Tom Henderson <tomh@tomh.org>
Sat, 16 Jan 2016 08:14:40 -0800
changeset 11683 9142266fbb25
parent 11598 b4d1339b4913
permissions -rw-r--r--
add figures to main documentation build
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     1
.. include:: replace.txt
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
     2
.. highlight:: cpp
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
     3
.. role:: raw-role(raw)
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
     4
   :format: html latex
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
     6
.. Mimic doxygen formatting for parameter names
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
     7
   
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
     8
.. raw:: html
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
     9
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    10
    <style>.param {font-weight:bold; color:#602020;}</style>
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    11
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    12
.. role:: param
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    13
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    14
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    15
Tracing
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    16
-------
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    17
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
Background
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    19
**********
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    21
As mentioned in :ref:`UsingTracingSystem`, the whole point
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    22
of running an |ns3| simulation is to generate output for study.  You
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    23
have two basic strategies to obtain output from |ns3|: using generic
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    24
pre-defined bulk output mechanisms and parsing their content to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    25
extract interesting information; or somehow developing an output
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    26
mechanism that conveys exactly (and perhaps only) the information
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    27
wanted.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    28
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    29
Using pre-defined bulk output mechanisms has the advantage of not
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    30
requiring any changes to |ns3|, but it may require writing scripts to
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    31
parse and filter for data of interest.  Often, PCAP or ``NS_LOG``
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    32
output messages are gathered during simulation runs and separately run
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    33
through scripts that use ``grep``, ``sed`` or ``awk`` to parse the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    34
messages and reduce and transform the data to a manageable form.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    35
Programs must be written to do the transformation, so this does not
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    36
come for free.  ``NS_LOG`` output is not considered part of the |ns3|
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    37
API, and can change without warning between releases.  In addition,
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    38
``NS_LOG`` output is only available in debug builds, so relying on it
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    39
imposes a performance penalty.  Of course, if the information of
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    40
interest does not exist in any of the pre-defined output mechanisms,
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    41
this approach fails.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    42
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    43
If you need to add some tidbit of information to the pre-defined bulk
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    44
mechanisms, this can certainly be done; and if you use one of the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    45
|ns3| mechanisms, you may get your code added as a contribution.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    46
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    47
|ns3| provides another mechanism, called Tracing, that avoids some of
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    48
the problems inherent in the bulk output mechanisms.  It has several
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    49
important advantages.  First, you can reduce the amount of data you
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    50
have to manage by only tracing the events of interest to you (for
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    51
large simulations, dumping everything to disk for post-processing can
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    52
create I/O bottlenecks).  Second, if you use this method, you can
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    53
control the format of the output directly so you avoid the
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    54
postprocessing step with ``sed``, ``awk``, ``perl`` or ``python``
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    55
scripts.  If you desire, your output can be formatted directly into a
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    56
form acceptable by gnuplot, for example (see also
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    57
:ref:`GnuplotHelper`).  You can add hooks in the core which can then
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    58
be accessed by other users, but which will produce no information
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    59
unless explicitly asked to do so.  For these reasons, we believe that
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    60
the |ns3| tracing system is the best way to get information out of a
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    61
simulation and is also therefore one of the most important mechanisms
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    62
to understand in |ns3|.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    63
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    64
Blunt Instruments
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    65
+++++++++++++++++
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    66
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    67
There are many ways to get information out of a program.  The most
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    68
straightforward way is to just print the information directly to the
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    69
standard output, as in::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    70
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    71
  #include <iostream>
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    72
  ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    73
  void
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    74
  SomeFunction (void)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    75
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    76
    uint32_t x = SOME_INTERESTING_VALUE;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    77
    ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    78
    std::cout << "The value of x is " << x << std::endl;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    79
    ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    80
  } 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    81
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    82
Nobody is going to prevent you from going deep into the core of |ns3|
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    83
and adding print statements.  This is insanely easy to do and, after
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    84
all, you have complete control of your own |ns3| branch.  This will
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    85
probably not turn out to be very satisfactory in the long term,
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    86
though.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    87
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    88
As the number of print statements increases in your programs, the task
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    89
of dealing with the large number of outputs will become more and more
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    90
complicated.  Eventually, you may feel the need to control what
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    91
information is being printed in some way, perhaps by turning on and
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    92
off certain categories of prints, or increasing or decreasing the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    93
amount of information you want.  If you continue down this path you
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    94
may discover that you have re-implemented the ``NS_LOG`` mechanism
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    95
(see :ref:`UsingLogging`).  In order to avoid that, one of the first
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    96
things you might consider is using ``NS_LOG`` itself.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    97
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
    98
We mentioned above that one way to get information out of |ns3| is to
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
    99
parse existing ``NS_LOG`` output for interesting information.  If you
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   100
discover that some tidbit of information you need is not present in
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   101
existing log output, you could edit the core of |ns3| and simply add
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   102
your interesting information to the output stream.  Now, this is
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   103
certainly better than adding your own print statements since it
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   104
follows |ns3| coding conventions and could potentially be useful to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   105
other people as a patch to the existing core.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   106
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   107
Let's pick a random example.  If you wanted to add more logging to the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   108
|ns3| TCP socket (``tcp-socket-base.cc``) you could just add a new
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   109
message down in the implementation.  Notice that in
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   110
``TcpSocketBase::ReceivedAck()`` there is no log message for the no ACK
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   111
case.  You could simply add one, changing the code.  Here is the original::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   112
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   113
  /** Process the newly received ACK */
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   114
  void
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   115
  TcpSocketBase::ReceivedAck (Ptr<Packet> packet, const TcpHeader& tcpHeader)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   116
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   117
    NS_LOG_FUNCTION (this << tcpHeader);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   118
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   119
    // Received ACK. Compare the ACK number against highest unacked seqno
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   120
    if (0 == (tcpHeader.GetFlags () & TcpHeader::ACK))
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   121
      { // Ignore if no ACK flag
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   122
      }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   123
    ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   124
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   125
To log the no ACK case, you can add a new ``NS_LOG_LOGIC`` in the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   126
``if`` statement body::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   127
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   128
  /** Process the newly received ACK */
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   129
  void
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   130
  TcpSocketBase::ReceivedAck (Ptr<Packet> packet, const TcpHeader& tcpHeader)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   131
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   132
    NS_LOG_FUNCTION (this << tcpHeader);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   133
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   134
    // Received ACK. Compare the ACK number against highest unacked seqno
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   135
    if (0 == (tcpHeader.GetFlags () & TcpHeader::ACK))
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   136
      { // Ignore if no ACK flag
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   137
        NS_LOG_LOGIC ("TcpSocketBase " << this << " no ACK flag");
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   138
      }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   139
    ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   140
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   141
This may seem fairly simple and satisfying at first glance, but
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   142
something to consider is that you will be writing code to add
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   143
``NS_LOG`` statements and you will also have to write code (as in
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   144
``grep``, ``sed`` or ``awk`` scripts) to parse the log output in order
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   145
to isolate your information.  This is because even though you have
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   146
some control over what is output by the logging system, you only have
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   147
control down to the log component level, which is typically an entire
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   148
source code file.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   149
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   150
If you are adding code to an existing module, you will also have to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   151
live with the output that every other developer has found interesting.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   152
You may find that in order to get the small amount of information you
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   153
need, you may have to wade through huge amounts of extraneous messages
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   154
that are of no interest to you.  You may be forced to save huge log
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   155
files to disk and process them down to a few lines whenever you want
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   156
to do anything.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   157
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   158
Since there are no guarantees in |ns3| about the stability of
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   159
``NS_LOG`` output, you may also discover that pieces of log output 
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   160
which you depend on disappear or change between releases.  If you depend
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   161
on the structure of the output, you may find other messages being
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   162
added or deleted which may affect your parsing code.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   163
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   164
Finally, ``NS_LOG`` output is only available in debug builds, you
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   165
can't get log output from optimized builds, which run about twice as
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   166
fast.  Relying on ``NS_LOG`` imposes a performance penalty.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   167
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   168
For these reasons, we consider prints to ``std::cout`` and ``NS_LOG``
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   169
messages to be quick and dirty ways to get more information out of
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   170
|ns3|, but not suitable for serious work.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   171
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   172
It is desirable to have a stable facility using stable APIs that allow
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   173
one to reach into the core system and only get the information
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   174
required.  It is desirable to be able to do this without having to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   175
change and recompile the core system.  Even better would be a system
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   176
that notified user code when an item of interest changed or an
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   177
interesting event happened so the user doesn't have to actively poke
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   178
around in the system looking for things.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   179
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   180
The |ns3| tracing system is designed to work along those lines and is
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   181
well-integrated with the :ref:`Attribute <Attribute>` and :ref:`Config
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   182
<Config>` subsystems allowing for relatively simple use scenarios.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   183
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   184
Overview
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   185
********
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   186
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   187
The |ns3| tracing system is built on the concepts of independent
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   188
tracing sources and tracing sinks, along with a uniform mechanism for
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   189
connecting sources to sinks.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   190
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   191
Trace sources are entities that can signal events that happen in a
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   192
simulation and provide access to interesting underlying data.  For
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   193
example, a trace source could indicate when a packet is received by a
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   194
net device and provide access to the packet contents for interested
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   195
trace sinks.  A trace source might also indicate when an interesting
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   196
state change happens in a model.  For example, the congestion window
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   197
of a TCP model is a prime candidate for a trace source.  Every time
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   198
the congestion window changes connected trace sinks are notified with
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   199
the old and new value.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   200
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   201
Trace sources are not useful by themselves; they must be connected to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   202
other pieces of code that actually do something useful with the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   203
information provided by the source.  The entities that consume trace
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   204
information are called trace sinks.  Trace sources are generators of
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   205
data and trace sinks are consumers.  This explicit division allows
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   206
for large numbers of trace sources to be scattered around the system
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   207
in places which model authors believe might be useful.  Inserting
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   208
trace sources introduces a very small execution overhead.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   209
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   210
There can be zero or more consumers of trace events generated by a
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   211
trace source.  One can think of a trace source as a kind of
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   212
point-to-multipoint information link.  Your code looking for trace
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   213
events from a particular piece of core code could happily coexist with
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   214
other code doing something entirely different from the same
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   215
information.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   216
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   217
Unless a user connects a trace sink to one of these sources, nothing
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   218
is output.  By using the tracing system, both you and other people
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   219
hooked to the same trace source are getting exactly what they want and
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   220
only what they want out of the system.  Neither of you are impacting
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   221
any other user by changing what information is output by the system.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   222
If you happen to add a trace source, your work as a good open-source
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   223
citizen may allow other users to provide new utilities that are
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   224
perhaps very useful overall, without making any changes to the |ns3|
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   225
core.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   226
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   227
Simple Example
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   228
++++++++++++++
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   229
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   230
Let's take a few minutes and walk through a simple tracing example.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   231
We are going to need a little background on Callbacks to understand
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   232
what is happening in the example, so we have to take a small detour
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   233
right away.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   234
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   235
Callbacks
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   236
~~~~~~~~~
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   237
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   238
The goal of the Callback system in |ns3| is to allow one piece of code
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   239
to call a function (or method in C++) without any specific
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   240
inter-module dependency.  This ultimately means you need some kind of
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   241
indirection -- you treat the address of the called function as a
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   242
variable.  This variable is called a pointer-to-function variable.
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   243
The relationship between function and pointer-to-function is
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   244
really no different that that of object and pointer-to-object.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   245
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   246
In C the canonical example of a pointer-to-function is a
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   247
pointer-to-function-returning-integer (PFI).  For a PFI taking one ``int``
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   248
parameter, this could be declared like,
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   249
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   250
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   251
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   252
  int (*pfi)(int arg) = 0;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   253
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   254
(But read the `C++-FAQ Section 33
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   255
<http://www.parashift.com/c++-faq/pointers-to-members.html>`_ before
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   256
writing code like this!)  What you get from this is a variable named
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   257
simply ``pfi`` that is initialized to the value 0.  If you want to
11598
b4d1339b4913 Refactor TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11244
diff changeset
   258
initialize this pointer to something meaningful, you need to have a
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   259
function with a matching signature.  In this case, you could provide a
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   260
function that looks like::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   261
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   262
  int MyFunction (int arg) {}
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   263
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   264
If you have this target, you can initialize the variable to point to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   265
your function::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   266
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   267
  pfi = MyFunction;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   268
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   269
You can then call MyFunction indirectly using the more suggestive form
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   270
of the call::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   271
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   272
  int result = (*pfi) (1234);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   273
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   274
This is suggestive since it looks like you are dereferencing the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   275
function pointer just like you would dereference any pointer.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   276
Typically, however, people take advantage of the fact that the
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   277
compiler knows what is going on and will just use a shorter form::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   278
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   279
  int result = pfi (1234);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   280
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   281
This looks like you are calling a function named ``pfi``, but the
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   282
compiler is smart enough to know to call through the variable ``pfi``
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   283
indirectly to the function ``MyFunction``.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   284
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   285
Conceptually, this is almost exactly how the tracing system works.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   286
Basically, a trace sink *is* a callback.  When a trace sink expresses
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   287
interest in receiving trace events, it adds itself as a Callback to a
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   288
list of Callbacks internally held by the trace source.  When an
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   289
interesting event happens, the trace source invokes its
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   290
``operator(...)`` providing zero or more arguments.  The
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   291
``operator(...)`` eventually wanders down into the system and does
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   292
something remarkably like the indirect call you just saw, providing
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   293
zero or more parameters, just as the call to ``pfi`` above passed one
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   294
parameter to the target function ``MyFunction``.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   295
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   296
The important difference that the tracing system adds is that for each
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   297
trace source there is an internal list of Callbacks.  Instead of just
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   298
making one indirect call, a trace source may invoke multiple
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   299
Callbacks.  When a trace sink expresses interest in notifications from
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   300
a trace source, it basically just arranges to add its own function to
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   301
the callback list.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   302
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   303
If you are interested in more details about how this is actually
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   304
arranged in |ns3|, feel free to peruse the Callback section of the
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   305
|ns3| Manual.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   306
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   307
Walkthrough: ``fourth.cc``
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   308
~~~~~~~~~~~~~~~~~~~~~~~~~~
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   309
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   310
We have provided some code to implement what is really the simplest
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   311
example of tracing that can be assembled.  You can find this code in
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   312
the tutorial directory as ``fourth.cc``.  Let's walk through it::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   313
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   314
  /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   315
  /*
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   316
   * This program is free software; you can redistribute it and/or modify
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   317
   * it under the terms of the GNU General Public License version 2 as
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   318
   * published by the Free Software Foundation;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   319
   *
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   320
   * This program is distributed in the hope that it will be useful,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   321
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   322
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   323
   * GNU General Public License for more details.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   324
   *
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   325
   * You should have received a copy of the GNU General Public License
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   326
   * along with this program; if not, write to the Free Software
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   327
   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   328
   */
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   329
  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   330
  #include "ns3/object.h"
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   331
  #include "ns3/uinteger.h"
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   332
  #include "ns3/traced-value.h"
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   333
  #include "ns3/trace-source-accessor.h"
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   334
  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   335
  #include <iostream>
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   336
  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   337
  using namespace ns3;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   338
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   339
Most of this code should be quite familiar to you.  As mentioned
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   340
above, the trace system makes heavy use of the Object and Attribute
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   341
systems, so you will need to include them.  The first two includes
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   342
above bring in the declarations for those systems explicitly.  You
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   343
could use the core module header to get everything at once, but we do
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   344
the includes explicitly here to illustrate how simple this all really
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   345
is.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   346
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   347
The file, ``traced-value.h`` brings in the required declarations for
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   348
tracing of data that obeys value semantics.  In general, value
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   349
semantics just means that you can pass the object itself around,
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   350
rather than passing the address of the object.  What this all really
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   351
means is that you will be able to trace all changes made to a
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   352
TracedValue in a really simple way.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   353
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   354
Since the tracing system is integrated with Attributes, and Attributes
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   355
work with Objects, there must be an |ns3| ``Object`` for the trace
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   356
source to live in.  The next code snippet declares and defines a
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   357
simple Object we can work with.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   358
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   359
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   360
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   361
  class MyObject : public Object
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   362
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   363
  public:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   364
    static TypeId GetTypeId (void)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   365
    {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   366
      static TypeId tid = TypeId ("MyObject")
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   367
        .SetParent (Object::GetTypeId ())
11244
2a117115b91f update tutorial documentation for SetGroupName
Tom Henderson <tomh@tomh.org>
parents: 11089
diff changeset
   368
        .SetGroupName ("MyGroup")
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   369
        .AddConstructor<MyObject> ()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   370
        .AddTraceSource ("MyInteger",
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   371
                         "An integer value to trace.",
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   372
                         MakeTraceSourceAccessor (&MyObject::m_myInt),
11598
b4d1339b4913 Refactor TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11244
diff changeset
   373
                         "ns3::TracedValueCallback::Int32")
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   374
        ;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   375
      return tid;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   376
    }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   377
    
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   378
    MyObject () {}
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   379
    TracedValue<int32_t> m_myInt;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   380
  };
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   381
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   382
The two important lines of code, above, with respect to tracing are
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   383
the ``.AddTraceSource`` and the ``TracedValue`` declaration of
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   384
``m_myInt``.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   385
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   386
The ``.AddTraceSource`` provides the "hooks" used for connecting the
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   387
trace source to the outside world through the Config system.  The
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   388
first argument is a name for this trace source, which makes it
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   389
visible in the Config system. The second argument is a help string.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   390
Now look at the third argument, in fact focus on the *argument* of
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   391
the third argument: ``&MyObject::m_myInt``. This is the TracedValue
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   392
which is being added to the class; it is always a class data member.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   393
(The final argument is the name of a ``typedef`` for the TracedValue
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   394
type, as a string.  This is used to generate documentation for the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   395
correct Callback function signature, which is useful especially
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   396
for more general types of Callbacks.)
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   397
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   398
The ``TracedValue<>`` declaration provides the infrastructure that
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   399
drives the callback process.  Any time the underlying value is changed
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   400
the TracedValue mechanism will provide both the old and the new value
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   401
of that variable, in this case an ``int32_t`` value.  The trace
11598
b4d1339b4913 Refactor TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11244
diff changeset
   402
sink function ``traceSink`` for this TracedValue will need the signature
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   403
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   404
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   405
11598
b4d1339b4913 Refactor TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11244
diff changeset
   406
  void (* traceSink)(int32_t oldValue, int32_t newValue);
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   407
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   408
All trace sinks hooking this trace source must have this signature.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   409
We'll discuss below how you can determine the required callback
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   410
signature in other cases.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   411
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   412
Sure enough, continuing through ``fourth.cc`` we see::
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   413
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   414
  void
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   415
  IntTrace (int32_t oldValue, int32_t newValue)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   416
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   417
    std::cout << "Traced " << oldValue << " to " << newValue << std::endl;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   418
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   419
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   420
This is the definition of a matching trace sink.  It corresponds
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   421
directly to the callback function signature.  Once it is connected,
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   422
this function will be called whenever the ``TracedValue`` changes.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   423
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   424
We have now seen the trace source and the trace sink.  What remains is
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   425
code to connect the source to the sink, which happens in ``main``::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   426
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   427
  int
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   428
  main (int argc, char *argv[])
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   429
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   430
    Ptr<MyObject> myObject = CreateObject<MyObject> ();
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   431
    myObject->TraceConnectWithoutContext ("MyInteger", MakeCallback(&IntTrace));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   432
  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   433
    myObject->m_myInt = 1234;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   434
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   435
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   436
Here we first create the MyObject instance in which the trace source
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   437
lives.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   438
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   439
The next step, the ``TraceConnectWithoutContext``, forms the
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   440
connection between the trace source and the trace sink.  The first
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   441
argument is just the trace source name "MyInteger" we saw above.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   442
Notice the ``MakeCallback`` template function.  This function does the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   443
magic required to create the underlying |ns3| Callback object and
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   444
associate it with the function ``IntTrace``.  ``TraceConnect`` makes
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   445
the association between your provided function and overloaded
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   446
``operator()`` in the traced variable referred to by the "MyInteger"
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   447
Attribute.  After this association is made, the trace source will
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   448
"fire" your provided callback function.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   449
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   450
The code to make all of this happen is, of course, non-trivial, but
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   451
the essence is that you are arranging for something that looks just
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   452
like the ``pfi()`` example above to be called by the trace source.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   453
The declaration of the ``TracedValue<int32_t> m_myInt;`` in the Object
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   454
itself performs the magic needed to provide the overloaded assignment
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   455
operators that will use the ``operator()`` to actually invoke the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   456
Callback with the desired parameters.  The ``.AddTraceSource``
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   457
performs the magic to connect the Callback to the Config system, and
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   458
``TraceConnectWithoutContext`` performs the magic to connect your
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   459
function to the trace source, which is specified by Attribute name.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   460
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   461
Let's ignore the bit about context for now.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   462
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   463
Finally, the line assigning a value to ``m_myInt``::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   464
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   465
   myObject->m_myInt = 1234;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   466
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   467
should be interpreted as an invocation of ``operator=`` on the member
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   468
variable ``m_myInt`` with the integer ``1234`` passed as a parameter.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   469
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   470
Since ``m_myInt`` is a ``TracedValue``, this operator is defined to
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   471
execute a callback that returns void and takes two integer values as
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   472
parameters --- an old value and a new value for the integer in
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   473
question.  That is exactly the function signature for the callback
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   474
function we provided --- ``IntTrace``.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   475
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   476
To summarize, a trace source is, in essence, a variable that holds a
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   477
list of callbacks.  A trace sink is a function used as the target of a
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   478
callback.  The Attribute and object type information systems are used
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   479
to provide a way to connect trace sources to trace sinks.  The act of
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   480
"hitting" a trace source is executing an operator on the trace source
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   481
which fires callbacks.  This results in the trace sink callbacks who
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   482
registering interest in the source being called with the parameters
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   483
provided by the source.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   484
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   485
If you now build and run this example,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   486
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
   487
.. sourcecode:: bash
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
   488
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
   489
  $ ./waf --run fourth
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   490
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   491
you will see the output from the ``IntTrace`` function execute as soon
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   492
as the trace source is hit:
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   493
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
   494
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   495
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   496
  Traced 0 to 1234
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   497
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   498
When we executed the code, ``myObject->m_myInt = 1234;``, the trace
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   499
source fired and automatically provided the before and after values to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   500
the trace sink.  The function ``IntTrace`` then printed this to the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   501
standard output.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   502
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   503
.. _Config:
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   504
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   505
Connect with Config
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   506
+++++++++++++++++++
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   507
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   508
The ``TraceConnectWithoutContext`` call shown above in the simple
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   509
example is actually very rarely used in the system.  More typically,
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   510
the ``Config`` subsystem is used to select a trace source in the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   511
system using what is called a *Config path*.  We saw an example of
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   512
this in the previous section where we hooked the "CourseChange" event
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   513
when we were experimenting with ``third.cc``.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   514
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   515
Recall that we defined a trace sink to print course change information
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   516
from the mobility models of our simulation.  It should now be a lot
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   517
more clear to you what this function is doing::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   518
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   519
  void
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   520
  CourseChange (std::string context, Ptr<const MobilityModel> model)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   521
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   522
    Vector position = model->GetPosition ();
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   523
    NS_LOG_UNCOND (context << 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   524
      " x = " << position.x << ", y = " << position.y);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   525
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   526
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   527
When we connected the "CourseChange" trace source to the above trace
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   528
sink, we used a Config path to specify the source when we arranged a
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   529
connection between the pre-defined trace source and the new trace
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   530
sink::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   531
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   532
  std::ostringstream oss;
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   533
  oss << "/NodeList/"
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   534
      << wifiStaNodes.Get (nWifi - 1)->GetId ()
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   535
      << "/$ns3::MobilityModel/CourseChange";
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   536
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   537
  Config::Connect (oss.str (), MakeCallback (&CourseChange));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   538
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   539
Let's try and make some sense of what is sometimes considered
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   540
relatively mysterious code.  For the purposes of discussion, assume
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   541
that the Node number returned by the ``GetId()`` is "7".  In this
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   542
case, the path above turns out to be
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   543
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   544
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   545
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   546
  "/NodeList/7/$ns3::MobilityModel/CourseChange"
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   547
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   548
The last segment of a config path must be an ``Attribute`` of an
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   549
``Object``.  In fact, if you had a pointer to the ``Object`` that has
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   550
the "CourseChange" ``Attribute`` handy, you could write this just like
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   551
we did in the previous example.  You know by now that we typically
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   552
store pointers to our ``Nodes`` in a NodeContainer.  In the ``third.cc``
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   553
example, the Nodes of interest are stored in the ``wifiStaNodes``
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   554
NodeContainer.  In fact, while putting the path together, we used this
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   555
container to get a ``Ptr<Node>`` which we used to call ``GetId()``.  We
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   556
could have used this ``Ptr<Node>`` to call a Connect method
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   557
directly::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   558
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   559
  Ptr<Object> theObject = wifiStaNodes.Get (nWifi - 1);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   560
  theObject->TraceConnectWithoutContext ("CourseChange", MakeCallback (&CourseChange));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   561
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   562
In the ``third.cc`` example, we actually wanted an additional "context"
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   563
to be delivered along with the Callback parameters (which will be
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   564
explained below) so we could actually use the following equivalent
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   565
code::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   566
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   567
  Ptr<Object> theObject = wifiStaNodes.Get (nWifi - 1);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   568
  theObject->TraceConnect ("CourseChange", MakeCallback (&CourseChange));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   569
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   570
It turns out that the internal code for
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   571
``Config::ConnectWithoutContext`` and ``Config::Connect`` actually
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   572
find a ``Ptr<Object>`` and call the appropriate ``TraceConnect``
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   573
method at the lowest level.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   574
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   575
The ``Config`` functions take a path that represents a chain of
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   576
``Object`` pointers.  Each segment of a path corresponds to an Object
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   577
Attribute.  The last segment is the Attribute of interest, and prior
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   578
segments must be typed to contain or find Objects.  The ``Config``
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   579
code parses and "walks" this path until it gets to the final segment
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   580
of the path.  It then interprets the last segment as an ``Attribute``
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   581
on the last Object it found while walking the path.  The ``Config``
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   582
functions then call the appropriate ``TraceConnect`` or
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   583
``TraceConnectWithoutContext`` method on the final Object.  Let's see
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   584
what happens in a bit more detail when the above path is walked.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   585
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   586
The leading "/" character in the path refers to a so-called namespace.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   587
One of the predefined namespaces in the config system is "NodeList"
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   588
which is a list of all of the nodes in the simulation.  Items in the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   589
list are referred to by indices into the list, so "/NodeList/7" refers
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   590
to the eighth Node in the list of nodes created during the simulation
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   591
(recall indices start at `0').  This reference is actually a
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   592
``Ptr<Node>`` and so is a subclass of an ``ns3::Object``.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   593
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   594
As described in the Object Model section of the |ns3| Manual, we make
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   595
widespread use of object aggregation.  This allows us to form an
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   596
association between different Objects without building a complicated
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   597
inheritance tree or predeciding what objects will be part of a
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   598
Node.  Each Object in an Aggregation can be reached from the other
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   599
Objects.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   600
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   601
In our example the next path segment being walked begins with the "$"
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   602
character.  This indicates to the config system that the segment is
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   603
the name of an object type, so a ``GetObject`` call should be made
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   604
looking for that type.  It turns out that the ``MobilityHelper`` used
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   605
in ``third.cc`` arranges to Aggregate, or associate, a mobility model
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   606
to each of the wireless ``Nodes``.  When you add the "$" you are
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   607
asking for another Object that has presumably been previously
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   608
aggregated.  You can think of this as switching pointers from the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   609
original Ptr<Node> as specified by "/NodeList/7" to its associated
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   610
mobility model --- which is of type ``ns3::MobilityModel``.  If you
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   611
are familiar with ``GetObject``, we have asked the system to do the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   612
following::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   613
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   614
  Ptr<MobilityModel> mobilityModel = node->GetObject<MobilityModel> ()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   615
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   616
We are now at the last Object in the path, so we turn our attention to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   617
the Attributes of that Object.  The ``MobilityModel`` class defines an
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   618
Attribute called "CourseChange".  You can see this by looking at the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   619
source code in ``src/mobility/model/mobility-model.cc`` and searching
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   620
for "CourseChange" in your favorite editor.  You should find
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   621
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   622
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   623
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   624
  .AddTraceSource ("CourseChange",
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   625
                   "The value of the position and/or velocity vector changed",
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   626
                   MakeTraceSourceAccessor (&MobilityModel::m_courseChangeTrace),
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   627
                   "ns3::MobilityModel::CourseChangeCallback")
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   628
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   629
which should look very familiar at this point.  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   630
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   631
If you look for the corresponding declaration of the underlying traced
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   632
variable in ``mobility-model.h`` you will find
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   633
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   634
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   635
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   636
  TracedCallback<Ptr<const MobilityModel> > m_courseChangeTrace;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   637
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   638
The type declaration ``TracedCallback`` identifies
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   639
``m_courseChangeTrace`` as a special list of Callbacks that can be
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   640
hooked using the Config functions described above.  The ``typedef``
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   641
for the callback function signature is also defined in the header file::
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   642
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   643
  typedef void (* CourseChangeCallback)(Ptr<const MobilityModel> * model);
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   644
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   645
The ``MobilityModel`` class is designed to be a base class providing a
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   646
common interface for all of the specific subclasses.  If you search
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   647
down to the end of the file, you will see a method defined called
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   648
``NotifyCourseChange()``::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   649
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   650
  void
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   651
  MobilityModel::NotifyCourseChange (void) const
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   652
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   653
    m_courseChangeTrace(this);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   654
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   655
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   656
Derived classes will call into this method whenever they do a course
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   657
change to support tracing.  This method invokes ``operator()`` on the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   658
underlying ``m_courseChangeTrace``, which will, in turn, invoke all of
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   659
the registered Callbacks, calling all of the trace sinks that have
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   660
registered interest in the trace source by calling a Config function.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   661
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   662
So, in the ``third.cc`` example we looked at, whenever a course change
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   663
is made in one of the ``RandomWalk2dMobilityModel`` instances
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   664
installed, there will be a ``NotifyCourseChange()`` call which calls
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   665
up into the ``MobilityModel`` base class.  As seen above, this invokes
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   666
``operator()`` on ``m_courseChangeTrace``, which in turn, calls any
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   667
registered trace sinks.  In the example, the only code registering an
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   668
interest was the code that provided the Config path.  Therefore, the
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   669
``CourseChange`` function that was hooked from Node number seven will
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   670
be the only Callback called.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   671
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   672
The final piece of the puzzle is the "context".  Recall that we saw an
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   673
output looking something like the following from ``third.cc``::
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   674
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   675
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 7.27897, y =
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   676
  2.22677
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   677
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   678
The first part of the output is the context.  It is simply the path
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   679
through which the config code located the trace source.  In the case
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   680
we have been looking at there can be any number of trace sources in
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   681
the system corresponding to any number of nodes with mobility models.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   682
There needs to be some way to identify which trace source is actually
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   683
the one that fired the Callback.  The easy way is to connect with
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   684
``Config::Connect``, instead of ``Config::ConnectWithoutContext``.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   685
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   686
Finding Sources
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   687
+++++++++++++++
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   688
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   689
The first question that inevitably comes up for new users of the
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   690
Tracing system is, *"Okay, I know that there must be trace sources in
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   691
the simulation core, but how do I find out what trace sources are
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   692
available to me?"*
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   693
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   694
The second question is, *"Okay, I found a trace source, how do I figure
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   695
out the Config path to use when I connect to it?"*
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   696
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   697
The third question is, *"Okay, I found a trace source and the Config
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   698
path, how do I figure out what the return type and formal arguments of
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   699
my callback function need to be?"*
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   700
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   701
The fourth question is, *"Okay, I typed that all in and got this
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   702
incredibly bizarre error message, what in the world does it mean?"*
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   703
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   704
We'll address each of these in turn.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   705
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   706
Available Sources
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   707
+++++++++++++++++
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   708
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   709
*Okay, I know that there must be trace sources in the simulation core,
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   710
but how do I find out what trace sources are available to me?*
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   711
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   712
The answer to the first question is found in the |ns3| API
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   713
documentation.  If you go to the project web site, `ns-3 project
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   714
<http://www.nsnam.org>`_, you will find a link to "Documentation" in
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   715
the navigation bar.  If you select this link, you will be taken to our
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   716
documentation page. There is a link to "Latest Release" that will take
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   717
you to the documentation for the latest stable release of |ns3|.  If
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   718
you select the "API Documentation" link, you will be taken to the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   719
|ns3| API documentation page.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   720
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   721
In the sidebar you should see a hierachy that begins
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   722
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   723
*  ns-3
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   724
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   725
  *  ns-3 Documentation
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   726
  *  All TraceSources
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   727
  *  All Attributes
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   728
  *  All GlobalValues
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   729
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   730
The list of interest to us here is "All TraceSources".  Go ahead and
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   731
select that link.  You will see, perhaps not too surprisingly, a list
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   732
of all of the trace sources available in |ns3|.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   733
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   734
As an example, scroll down to ``ns3::MobilityModel``.  You will find
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   735
an entry for
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   736
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   737
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   738
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   739
  CourseChange: The value of the position and/or velocity vector changed 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   740
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   741
You should recognize this as the trace source we used in the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   742
``third.cc`` example.  Perusing this list will be helpful.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   743
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   744
Config Paths
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   745
++++++++++++
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   746
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   747
*Okay, I found a trace source, how do I figure out the Config path to
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   748
use when I connect to it?*
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   749
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   750
If you know which object you are interested in, the "Detailed
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   751
Description" section for the class will list all available trace
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   752
sources.  For example, starting from the list of "All TraceSources,"
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   753
click on the ``ns3::MobilityModel`` link, which will take you to the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   754
documentation for the ``MobilityModel`` class.  Almost at the top of
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   755
the page is a one line brief description of the class, ending in a
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   756
link "More...".  Click on this link to skip the API summary and go to
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   757
the "Detailed Description" of the class.  At the end of the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   758
description will be (up to) three lists:
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   759
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   760
* **Config Paths**: a list of typical Config paths for this class.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   761
* **Attributes**: a list of all attributes supplied by this class.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   762
* **TraceSources**: a list of all TraceSources available from this class.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   763
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   764
First we'll discuss the Config paths.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   765
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   766
Let's assume that you have just found the "CourseChange" trace source
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   767
in the "All TraceSources" list and you want to figure out how to
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   768
connect to it.  You know that you are using (again, from the
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   769
``third.cc`` example) an ``ns3::RandomWalk2dMobilityModel``.  So
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   770
either click on the class name in the "All TraceSources" list, or find
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   771
``ns3::RandomWalk2dMobilityModel`` in the "Class List".  Either way 
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   772
you should now be looking at the "ns3::RandomWalk2dMobilityModel Class
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   773
Reference" page.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   774
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   775
If you now scroll down to the "Detailed Description" section, after
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   776
the summary list of class methods and attributes (or just click on the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   777
"More..." link at the end of the class brief description at the top of
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   778
the page) you will see the overall documentation for the class.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   779
Continuing to scroll down, find the "Config Paths" list:
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   780
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   781
  **Config Paths**
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   782
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   783
  ``ns3::RandomWalk2dMobilityModel`` is accessible through the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   784
  following paths with ``Config::Set`` and ``Config::Connect``:
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   785
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   786
  * "/NodeList/[i]/$ns3::MobilityModel/$ns3::RandomWalk2dMobilityModel"
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   787
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   788
The documentation tells you how to get to the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   789
``RandomWalk2dMobilityModel`` Object.  Compare the string above with
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   790
the string we actually used in the example code::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   791
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   792
  "/NodeList/7/$ns3::MobilityModel"
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   793
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   794
The difference is due to the fact that two ``GetObject`` calls are
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   795
implied in the string found in the documentation.  The first, for
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   796
``$ns3::MobilityModel`` will query the aggregation for the base class.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   797
The second implied ``GetObject`` call, for
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   798
``$ns3::RandomWalk2dMobilityModel``, is used to cast the base class to
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   799
the concrete implementation class.  The documentation shows both of
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   800
these operations for you.  It turns out that the actual trace source
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   801
you are looking for is found in the base class.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   802
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   803
Look further down in the "Detailed Description" section for the list
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   804
of trace sources.  You will find
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   805
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   806
  No TraceSources are defined for this type.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   807
  
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   808
  **TraceSources defined in parent class ``ns3::MobilityModel``**
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   809
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   810
  * **CourseChange**: The value of the position and/or velocity vector
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   811
    changed.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   812
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   813
    Callback signature: ``ns3::MobilityModel::CourseChangeCallback``
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   814
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   815
This is exactly what you need to know.  The trace source of interest
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   816
is found in ``ns3::MobilityModel`` (which you knew anyway).  The
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   817
interesting thing this bit of API Documentation tells you is that you
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   818
don't need that extra cast in the config path above to get to the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   819
concrete class, since the trace source is actually in the base class.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   820
Therefore the additional ``GetObject`` is not required and you simply
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   821
use the path::
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   822
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   823
  "/NodeList/[i]/$ns3::MobilityModel"
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   824
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   825
which perfectly matches the example path::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   826
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   827
  "/NodeList/7/$ns3::MobilityModel"
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   828
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   829
As an aside, another way to find the Config path is to ``grep`` around in
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   830
the |ns3| codebase for someone who has already figured it out.  You
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   831
should always try to copy someone else's working code before you start
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   832
to write your own.  Try something like:
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   833
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
   834
.. sourcecode:: bash
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
   835
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
   836
  $ find . -name '*.cc' | xargs grep CourseChange | grep Connect
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   837
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   838
and you may find your answer along with working code.  For example, in
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   839
this case, ``src/mobility/examples/main-random-topology.cc`` has
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   840
something just waiting for you to use::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   841
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   842
  Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange", 
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   843
    MakeCallback (&CourseChange));
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   844
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   845
We'll return to this example in a moment.    
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   846
      
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   847
Callback Signatures
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   848
+++++++++++++++++++
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   849
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   850
*Okay, I found a trace source and the Config path, how do I figure out
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   851
what the return type and formal arguments of my callback function need
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   852
to be?*
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   853
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   854
The easiest way is to examine the callback signature ``typedef``,
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   855
which is given in the "Callback signature" of the trace source in the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   856
"Detailed Description" for the class, as shown above.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   857
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   858
Repeating the "CourseChange" trace source entry from
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   859
``ns3::RandomWalk2dMobilityModel`` we have:
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   860
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   861
  * **CourseChange**: The value of the position and/or velocity vector
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   862
    changed.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   863
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   864
    Callback signature: ``ns3::MobilityModel::CourseChangeCallback``
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   865
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   866
The callback signature is given as a link to the relevant ``typedef``,
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   867
where we find
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   868
11598
b4d1339b4913 Refactor TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11244
diff changeset
   869
  ``typedef void (* CourseChangeCallback)(std::string context, Ptr<const MobilityModel> * model);``
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   870
					  
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   871
  **TracedCallback** signature for course change notifications.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   872
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   873
  If the callback is connected using ``ConnectWithoutContext`` omit the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   874
  ``context`` argument from the signature.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   875
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   876
  **Parameters**:
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   877
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   878
      |  [in] :param:`context` The context string supplied by the Trace source.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   879
      |  [in] :param:`model` The MobilityModel which is changing course.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   880
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   881
As above, to see this in use ``grep`` around in the |ns3| codebase for
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   882
an example.  The example above, from
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   883
``src/mobility/examples/main-random-topology.cc``, connects the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   884
"CourseChange" trace source to the ``CourseChange`` function in the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   885
same file::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   886
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   887
  static void
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   888
  CourseChange (std::string context, Ptr<const MobilityModel> model)
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   889
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   890
    ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   891
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   892
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   893
Notice that this function:
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   894
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   895
* Takes a "context" string argument, which we'll describe in a minute.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   896
  (If the callback is connected using the ``ConnectWithoutContext``
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   897
  function the ``context`` argument will be omitted.)
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   898
* Has the ``MobilityModel`` supplied as the last argument (or only
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   899
  argument if ``ConnectWithoutContext`` is used).
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   900
* Returns ``void``.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   901
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   902
If, by chance, the callback signature hasn't been documented, and
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   903
there are no examples to work from, determining the right callback
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   904
function signature can be, well, challenging to actually figure out
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   905
from the source code.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   906
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   907
Before embarking on a walkthrough of the code, I'll be kind and just
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   908
tell you a simple way to figure this out: The return value of your
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   909
callback will always be ``void``.  The formal parameter list for a
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   910
``TracedCallback`` can be found from the template parameter list in
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   911
the declaration.  Recall that for our current example, this is in
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   912
``mobility-model.h``, where we have previously found::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   913
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   914
  TracedCallback<Ptr<const MobilityModel> > m_courseChangeTrace;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   915
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   916
There is a one-to-one correspondence between the template parameter
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   917
list in the declaration and the formal arguments of the callback
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   918
function.  Here, there is one template parameter, which is a
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   919
``Ptr<const MobilityModel>``.  This tells you that you need a function
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   920
that returns void and takes a ``Ptr<const MobilityModel>``.  For
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   921
example::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   922
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   923
  void
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   924
  CourseChange (Ptr<const MobilityModel> model)
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   925
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   926
    ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   927
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   928
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   929
That's all you need if you want to ``Config::ConnectWithoutContext``.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   930
If you want a context, you need to ``Config::Connect`` and use a
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   931
Callback function that takes a string context, then the template
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   932
arguments::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   933
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   934
  void
11598
b4d1339b4913 Refactor TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11244
diff changeset
   935
  CourseChange (std::string context, Ptr<const MobilityModel> model)
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   936
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   937
    ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   938
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   939
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   940
If you want to ensure that your ``CourseChangeCallback`` function is only
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   941
visible in your local file, you can add the keyword ``static`` and
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   942
come up with::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   943
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   944
  static void
11598
b4d1339b4913 Refactor TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11244
diff changeset
   945
  CourseChange (std::string path, Ptr<const MobilityModel> model)
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   946
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   947
    ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   948
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   949
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   950
which is exactly what we used in the ``third.cc`` example.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   951
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   952
Implementation
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   953
~~~~~~~~~~~~~~
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   954
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   955
This section is entirely optional.  It is going to be a bumpy ride,
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   956
especially for those unfamiliar with the details of templates.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   957
However, if you get through this, you will have a very good handle on
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   958
a lot of the |ns3| low level idioms.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   959
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   960
So, again, let's figure out what signature of callback function is
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   961
required for the "CourseChange" trace source.  This is going to be
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   962
painful, but you only need to do this once.  After you get through
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   963
this, you will be able to just look at a ``TracedCallback`` and
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   964
understand it.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   965
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   966
The first thing we need to look at is the declaration of the trace
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   967
source.  Recall that this is in ``mobility-model.h``, where we have
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   968
previously found::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   969
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   970
  TracedCallback<Ptr<const MobilityModel> > m_courseChangeTrace;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   971
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   972
This declaration is for a template.  The template parameter is inside
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   973
the angle-brackets, so we are really interested in finding out what
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   974
that ``TracedCallback<>`` is.  If you have absolutely no idea where
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   975
this might be found, ``grep`` is your friend.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   977
We are probably going to be interested in some kind of declaration in
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   978
the |ns3| source, so first change into the ``src`` directory.  Then,
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   979
we know this declaration is going to have to be in some kind of header
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   980
file, so just ``grep`` for it using:
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   981
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
   982
.. sourcecode:: bash
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
   983
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
   984
  $ find . -name '*.h' | xargs grep TracedCallback
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   985
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   986
You'll see 303 lines fly by (I piped this through ``wc`` to see how bad it
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   987
was).  Although that may seem like a lot, that's not really a lot.  Just
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
   988
pipe the output through ``more`` and start scanning through it.  On the
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   989
first page, you will see some very suspiciously template-looking
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
   990
stuff.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   991
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   992
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   993
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   994
  TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::TracedCallback ()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   995
  TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::ConnectWithoutContext (c ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   996
  TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::Connect (const CallbackB ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   997
  TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::DisconnectWithoutContext ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   998
  TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::Disconnect (const Callba ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   999
  TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::operator() (void) const ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1000
  TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::operator() (T1 a1) const ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1001
  TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::operator() (T1 a1, T2 a2 ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1002
  TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::operator() (T1 a1, T2 a2 ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1003
  TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::operator() (T1 a1, T2 a2 ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1004
  TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::operator() (T1 a1, T2 a2 ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1005
  TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::operator() (T1 a1, T2 a2 ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1006
  TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::operator() (T1 a1, T2 a2 ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1007
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1008
It turns out that all of this comes from the header file
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1009
``traced-callback.h`` which sounds very promising.  You can then take
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1010
a look at ``mobility-model.h`` and see that there is a line which
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1011
confirms this hunch::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1012
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1013
  #include "ns3/traced-callback.h"
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1014
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1015
Of course, you could have gone at this from the other direction and
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1016
started by looking at the includes in ``mobility-model.h`` and
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1017
noticing the include of ``traced-callback.h`` and inferring that this
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1018
must be the file you want.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1019
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1020
In either case, the next step is to take a look at
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1021
``src/core/model/traced-callback.h`` in your favorite editor to see
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1022
what is happening.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1023
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1024
You will see a comment at the top of the file that should be
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1025
comforting:
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1026
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1027
  An ns3::TracedCallback has almost exactly the same API as a normal
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1028
  ns3::Callback but instead of forwarding calls to a single function
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1029
  (as an ns3::Callback normally does), it forwards calls to a chain of
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1030
  ns3::Callback.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1031
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1032
This should sound very familiar and let you know you are on the right
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1033
track.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1034
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1035
Just after this comment, you will find
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1036
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1037
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1038
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1039
  template<typename T1 = empty, typename T2 = empty, 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1040
           typename T3 = empty, typename T4 = empty,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1041
           typename T5 = empty, typename T6 = empty,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1042
           typename T7 = empty, typename T8 = empty>
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1043
  class TracedCallback 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1044
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1045
    ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1046
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1047
This tells you that TracedCallback is a templated class.  It has eight
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1048
possible type parameters with default values.  Go back and compare
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1049
this with the declaration you are trying to understand::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1050
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1051
  TracedCallback<Ptr<const MobilityModel> > m_courseChangeTrace;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1052
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1053
The ``typename T1`` in the templated class declaration corresponds to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1054
the ``Ptr<const MobilityModel>`` in the declaration above.  All of the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1055
other type parameters are left as defaults.  Looking at the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1056
constructor really doesn't tell you much.  The one place where you
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1057
have seen a connection made between your Callback function and the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1058
tracing system is in the ``Connect`` and ``ConnectWithoutContext``
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1059
functions.  If you scroll down, you will see a
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1060
``ConnectWithoutContext`` method here::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1061
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1062
  template<typename T1, typename T2, 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1063
           typename T3, typename T4,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1064
           typename T5, typename T6,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1065
           typename T7, typename T8>
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1066
  void 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1067
  TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::ConnectWithoutContext ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1068
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1069
    Callback<void,T1,T2,T3,T4,T5,T6,T7,T8> cb;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1070
    cb.Assign (callback);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1071
    m_callbackList.push_back (cb);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1072
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1073
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1074
You are now in the belly of the beast.  When the template is
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1075
instantiated for the declaration above, the compiler will replace
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1076
``T1`` with ``Ptr<const MobilityModel>``.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1077
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1078
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1079
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1080
  void 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1081
  TracedCallback<Ptr<const MobilityModel>::ConnectWithoutContext ... cb
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1082
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1083
    Callback<void, Ptr<const MobilityModel> > cb;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1084
    cb.Assign (callback);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1085
    m_callbackList.push_back (cb);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1086
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1087
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1088
You can now see the implementation of everything we've been talking
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1089
about.  The code creates a Callback of the right type and assigns your
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1090
function to it.  This is the equivalent of the ``pfi = MyFunction`` we
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1091
discussed at the start of this section.  The code then adds the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1092
Callback to the list of Callbacks for this source.  The only thing
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1093
left is to look at the definition of Callback.  Using the same ``grep``
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1094
trick as we used to find ``TracedCallback``, you will be able to find
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1095
that the file ``./core/callback.h`` is the one we need to look at.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1096
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1097
If you look down through the file, you will see a lot of probably
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1098
almost incomprehensible template code.  You will eventually come to
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1099
some API Documentation for the Callback template class, though.  Fortunately,
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1100
there is some English:
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1101
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1102
  **Callback** template class.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1103
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1104
  This class template implements the Functor Design Pattern. It is used to declare the type of a **Callback**:
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1105
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1106
  * the first non-optional template argument represents the return type of the callback.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1107
  * the reminaining (optional) template arguments represent the type of the subsequent arguments to the callback.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1108
  * up to nine arguments are supported.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1109
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1110
We are trying to figure out what the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1111
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1112
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1113
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1114
    Callback<void, Ptr<const MobilityModel> > cb;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1115
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1116
declaration means.  Now we are in a position to understand that the
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1117
first (non-optional) template argument, ``void``, represents the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1118
return type of the Callback.  The second (optional) template argument,
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1119
``Ptr<const MobilityModel>`` represents the type of the first argument
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1120
to the callback.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1121
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1122
The Callback in question is your function to receive the trace events.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1123
From this you can infer that you need a function that returns ``void``
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1124
and takes a ``Ptr<const MobilityModel>``.  For example,
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1125
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1126
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1127
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1128
  void
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1129
  CourseChangeCallback (Ptr<const MobilityModel> model)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1130
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1131
    ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1132
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1133
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1134
That's all you need if you want to ``Config::ConnectWithoutContext``.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1135
If you want a context, you need to ``Config::Connect`` and use a
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1136
Callback function that takes a string context.  This is because the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1137
``Connect`` function will provide the context for you.  You'll need::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1138
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1139
  void
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1140
  CourseChangeCallback (std::string context, Ptr<const MobilityModel> model)
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1141
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1142
    ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1143
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1144
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1145
If you want to ensure that your ``CourseChangeCallback`` is only
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1146
visible in your local file, you can add the keyword ``static`` and
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1147
come up with::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1148
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1149
  static void
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1150
  CourseChangeCallback (std::string path, Ptr<const MobilityModel> model)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1151
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1152
    ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1153
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1154
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1155
which is exactly what we used in the ``third.cc`` example.  Perhaps
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1156
you should now go back and reread the previous section (Take My Word
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1157
for It).
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1158
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1159
If you are interested in more details regarding the implementation of
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1160
Callbacks, feel free to take a look at the |ns3| manual.  They are one
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1161
of the most frequently used constructs in the low-level parts of
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1162
|ns3|.  It is, in my opinion, a quite elegant thing.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1163
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1164
TracedValues
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1165
++++++++++++
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1166
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1167
Earlier in this section, we presented a simple piece of code that used
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1168
a ``TracedValue<int32_t>`` to demonstrate the basics of the tracing
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1169
code.  We just glossed over the what a TracedValue really is and how
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1170
to find the return type and formal arguments for the callback.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1171
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1172
As we mentioned, the file, ``traced-value.h`` brings in the required
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1173
declarations for tracing of data that obeys value semantics.  In
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1174
general, value semantics just means that you can pass the object
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1175
itself around, rather than passing the address of the object.  We
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1176
extend that requirement to include the full set of assignment-style
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1177
operators that are pre-defined for plain-old-data (POD) types:
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1178
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1179
  +---------------------+---------------------+
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1180
  | ``operator=`` (assignment)                |
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1181
  +---------------------+---------------------+
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1182
  | ``operator*=``      | ``operator/=``      |
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1183
  +---------------------+---------------------+
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1184
  | ``operator+=``      | ``operator-=``      |
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1185
  +---------------------+---------------------+
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1186
  | ``operator++`` (both prefix and postfix)  |
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1187
  +---------------------+---------------------+
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1188
  | ``operator--`` (both prefix and postfix)  |
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1189
  +---------------------+---------------------+
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1190
  | ``operator<<=``     | ``operator>>=``     |
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1191
  +---------------------+---------------------+
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1192
  | ``operator&=``      | ``operator|=``      |
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1193
  +---------------------+---------------------+
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1194
  | ``operator%=``      | ``operator^=``      |
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1195
  +---------------------+---------------------+
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1196
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1197
What this all really means is that you will be able to trace all
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1198
changes made using those operators to a C++ object which has value
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1199
semantics.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1200
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1201
The ``TracedValue<>`` declaration we saw above provides the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1202
infrastructure that overloads the operators mentioned above and drives
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1203
the callback process.  On use of any of the operators above with a
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1204
``TracedValue`` it will provide both the old and the new value of that
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1205
variable, in this case an ``int32_t`` value.  By inspection of the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1206
``TracedValue`` declaration, we know the trace sink function will have
11598
b4d1339b4913 Refactor TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11244
diff changeset
  1207
arguments ``(int32_t oldValue, int32_t newValue)``.  The
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1208
return type for a ``TracedValue`` callback function is always
11598
b4d1339b4913 Refactor TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11244
diff changeset
  1209
``void``, so the expected callback signature for the sink function
b4d1339b4913 Refactor TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11244
diff changeset
  1210
``traceSink`` will be::
b4d1339b4913 Refactor TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11244
diff changeset
  1211
b4d1339b4913 Refactor TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11244
diff changeset
  1212
  void (* traceSink)(int32_t oldValue, int32_t newValue);
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1213
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1214
The ``.AddTraceSource`` in the ``GetTypeId`` method provides the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1215
"hooks" used for connecting the trace source to the outside world
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1216
through the Config system.  We already discussed the first three
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1217
agruments to ``AddTraceSource``: the Attribute name for the Config
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1218
system, a help string, and the address of the TracedValue class data
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1219
member.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1220
11598
b4d1339b4913 Refactor TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11244
diff changeset
  1221
The final string argument, "ns3::TracedValueCallback::Int32" in the example,
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1222
is the name of a ``typedef`` for the callback function signature.  We
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1223
require these signatures to be defined, and give the fully qualified
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1224
type name to ``AddTraceSource``, so the API documentation can link a
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1225
trace source to the function signature.  For TracedValue the signature
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1226
is straightforward; for TracedCallbacks we've already seen the API
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1227
docs really help.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1228
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1229
Real Example
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1230
************
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1231
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1232
Let's do an example taken from one of the best-known books on TCP
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1233
around.  "TCP/IP Illustrated, Volume 1: The Protocols," by W. Richard
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1234
Stevens is a classic.  I just flipped the book open and ran across a
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1235
nice plot of both the congestion window and sequence numbers versus
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1236
time on page 366.  Stevens calls this, "Figure 21.10. Value of cwnd
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1237
and send sequence number while data is being transmitted."  Let's just
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1238
recreate the cwnd part of that plot in |ns3| using the tracing system
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1239
and ``gnuplot``.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1240
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1241
Available Sources
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1242
+++++++++++++++++
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1243
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1244
The first thing to think about is how we want to get the data out.
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1245
What is it that we need to trace?  So let's consult "All Trace
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1246
Sources" list to see what we have to work with.  Recall that this is
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1247
found in the |ns3| API Documentation.  If you scroll through the list,
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1248
you will eventually find:
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1249
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1250
  **ns3::TcpNewReno**
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1251
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1252
  * **CongestionWindow**: The TCP connection's congestion window
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1253
  * **SlowStartThreshold**: TCP slow start threshold (bytes)
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1254
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1255
It turns out that the |ns3| TCP implementation lives (mostly) in the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1256
file ``src/internet/model/tcp-socket-base.cc`` while congestion
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1257
control variants are in files such as
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1258
``src/internet/model/tcp-newreno.cc``.  If you don't know this *a
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1259
priori*, you can use the recursive ``grep`` trick:
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1260
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
  1261
.. sourcecode:: bash
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
  1262
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
  1263
  $ find . -name '*.cc' | xargs grep -i tcp
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1264
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1265
You will find page after page of instances of tcp pointing you to that
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1266
file.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1267
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1268
Bringing up the class documentation for ``TcpNewReno`` and skipping to
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1269
the list of TraceSources you will find
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1270
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1271
  **TraceSources**
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1272
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1273
  * **CongestionWindow**: The TCP connnection's congestion window
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1274
11598
b4d1339b4913 Refactor TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11244
diff changeset
  1275
    Callback signature:  **ns3::TracedValueCallback::Uint32**
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1276
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1277
Clicking on the callback ``typedef`` link we see the signature
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1278
you now know to expect::
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1279
11598
b4d1339b4913 Refactor TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11244
diff changeset
  1280
    typedef void(* ns3::TracedValueCallback::Int32)(int32_t oldValue, int32_t newValue)
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1281
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1282
You should now understand this code completely.  If we have a pointer
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1283
to the ``TcpNewReno``, we can ``TraceConnect`` to the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1284
"CongestionWindow" trace source if we provide an appropriate callback
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1285
target.  This is the same kind of trace source that we saw in the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1286
simple example at the start of this section, except that we are
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1287
talking about ``uint32_t`` instead of ``int32_t``.  And we know
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1288
that we have to provide a callback function with that signature.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1289
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1290
Finding Examples
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1291
++++++++++++++++
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1292
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1293
It's always best to try and find working code laying around that you
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1294
can modify, rather than starting from scratch.  So the first order of
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1295
business now is to find some code that already hooks the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1296
"CongestionWindow" trace source and see if we can modify it.  As
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1297
usual, ``grep`` is your friend:
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1298
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
  1299
.. sourcecode:: bash
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
  1300
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
  1301
  $ find . -name '*.cc' | xargs grep CongestionWindow
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1302
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1303
This will point out a couple of promising candidates: 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1304
``examples/tcp/tcp-large-transfer.cc`` and 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1305
``src/test/ns3tcp/ns3tcp-cwnd-test-suite.cc``.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1306
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1307
We haven't visited any of the test code yet, so let's take a look
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1308
there.  You will typically find that test code is fairly minimal, so
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1309
this is probably a very good bet.  Open
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1310
``src/test/ns3tcp/ns3tcp-cwnd-test-suite.cc`` in your favorite editor
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1311
and search for "CongestionWindow".  You will find,
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1312
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1313
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1314
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1315
  ns3TcpSocket->TraceConnectWithoutContext ("CongestionWindow", 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1316
    MakeCallback (&Ns3TcpCwndTestCase1::CwndChange, this));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1317
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1318
This should look very familiar to you.  We mentioned above that if we
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1319
had a pointer to the ``TcpNewReno``, we could ``TraceConnect`` to the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1320
"CongestionWindow" trace source.  That's exactly what we have here; so
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1321
it turns out that this line of code does exactly what we want.  Let's
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1322
go ahead and extract the code we need from this function
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1323
(``Ns3TcpCwndTestCase1::DoRun (void)``).  If you look at this
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1324
function, you will find that it looks just like an |ns3| script.  It
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1325
turns out that is exactly what it is.  It is a script run by the test
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1326
framework, so we can just pull it out and wrap it in ``main`` instead
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1327
of in ``DoRun``.  Rather than walk through this, step, by step, we
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1328
have provided the file that results from porting this test back to a
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1329
native |ns3| script -- ``examples/tutorial/fifth.cc``.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1330
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1331
Dynamic Trace Sources
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1332
+++++++++++++++++++++
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1333
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1334
The ``fifth.cc`` example demonstrates an extremely important rule that
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1335
you must understand before using any kind of trace source: you must
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1336
ensure that the target of a ``Config::Connect`` command exists before
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1337
trying to use it.  This is no different than saying an object must be
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1338
instantiated before trying to call it.  Although this may seem obvious
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1339
when stated this way, it does trip up many people trying to use the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1340
system for the first time.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1341
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1342
Let's return to basics for a moment.  There are three basic execution
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1343
phases that exist in any |ns3| script.  The first phase is
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1344
sometimes called "Configuration Time" or "Setup Time," and exists
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1345
during the period when the ``main`` function of your script is
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1346
running, but before ``Simulator::Run`` is called.  The second phase
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1347
is sometimes called "Simulation Time" and exists during
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1348
the time period when ``Simulator::Run`` is actively executing its
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1349
events.  After it completes executing the simulation,
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1350
``Simulator::Run`` will return control back to the ``main`` function.
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1351
When this happens, the script enters what can be called the "Teardown
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1352
Phase," which is when the structures and objects created during setup
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1353
are taken apart and released.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1354
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1355
Perhaps the most common mistake made in trying to use the tracing
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1356
system is assuming that entities constructed dynamically *during
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1357
simulation time* are available during configuration time.  In
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1358
particular, an |ns3| ``Socket`` is a dynamic object often created by
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1359
``Applications`` to communicate between ``Nodes``.  An |ns3|
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1360
``Application`` always has a "Start Time" and a "Stop Time" associated
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1361
with it.  In the vast majority of cases, an ``Application`` will not
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1362
attempt to create a dynamic object until its ``StartApplication``
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1363
method is called at some "Start Time".  This is to ensure that the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1364
simulation is completely configured before the app tries to do
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1365
anything (what would happen if it tried to connect to a Node that
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1366
didn't exist yet during configuration time?).  As a result, during the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1367
configuration phase you can't connect a trace source to a trace sink
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1368
if one of them is created dynamically during the simulation.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1369
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1370
The two solutions to this connundrum are
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1371
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1372
#. Create a simulator event that is run after the dynamic object is
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1373
   created and hook the trace when that event is executed; or
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1374
#. Create the dynamic object at configuration time, hook it then, and
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1375
   give the object to the system to use during simulation time.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1376
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1377
We took the second approach in the ``fifth.cc`` example.  This
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1378
decision required us to create the ``MyApp`` ``Application``, the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1379
entire purpose of which is to take a ``Socket`` as a parameter.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1380
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1381
Walkthrough: ``fifth.cc``
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1382
+++++++++++++++++++++++++
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1383
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1384
Now, let's take a look at the example program we constructed by
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1385
dissecting the congestion window test.  Open
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1386
``examples/tutorial/fifth.cc`` in your favorite editor.  You should
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1387
see some familiar looking code::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1388
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1389
  /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1390
  /*
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1391
   * This program is free software; you can redistribute it and/or modify
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1392
   * it under the terms of the GNU General Public License version 2 as
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1393
   * published by the Free Software Foundation;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1394
   *
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1395
   * This program is distributed in the hope that it will be useful,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1396
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1397
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1398
   * GNU General Public License for more details.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1399
   *
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1400
   * You should have received a copy of the GNU General Public License
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1401
   * along with this program; if not, write to the Free Software
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1402
   * Foundation, Include., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1403
   */
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1404
  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1405
  #include <fstream>
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1406
  #include "ns3/core-module.h"
7137
dbefbad7bee3 Fix module names in documentation
Mitch Watrous <watrous@u.washington.edu>
parents: 6754
diff changeset
  1407
  #include "ns3/network-module.h"
dbefbad7bee3 Fix module names in documentation
Mitch Watrous <watrous@u.washington.edu>
parents: 6754
diff changeset
  1408
  #include "ns3/internet-module.h"
dbefbad7bee3 Fix module names in documentation
Mitch Watrous <watrous@u.washington.edu>
parents: 6754
diff changeset
  1409
  #include "ns3/point-to-point-module.h"
dbefbad7bee3 Fix module names in documentation
Mitch Watrous <watrous@u.washington.edu>
parents: 6754
diff changeset
  1410
  #include "ns3/applications-module.h"
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1411
  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1412
  using namespace ns3;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1413
  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1414
  NS_LOG_COMPONENT_DEFINE ("FifthScriptExample");
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1415
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1416
This has all been covered, so we won't rehash it.  The next lines of
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1417
source are the network illustration and a comment addressing the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1418
problem described above with ``Socket``.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1419
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1420
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1421
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1422
  // ===========================================================================
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1423
  //
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1424
  //         node 0                 node 1
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1425
  //   +----------------+    +----------------+
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1426
  //   |    ns-3 TCP    |    |    ns-3 TCP    |
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1427
  //   +----------------+    +----------------+
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1428
  //   |    10.1.1.1    |    |    10.1.1.2    |
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1429
  //   +----------------+    +----------------+
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1430
  //   | point-to-point |    | point-to-point |
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1431
  //   +----------------+    +----------------+
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1432
  //           |                     |
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1433
  //           +---------------------+
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1434
  //                5 Mbps, 2 ms
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1435
  //
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1436
  //
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1437
  // We want to look at changes in the ns-3 TCP congestion window.  We need
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1438
  // to crank up a flow and hook the CongestionWindow attribute on the socket
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1439
  // of the sender.  Normally one would use an on-off application to generate a
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1440
  // flow, but this has a couple of problems.  First, the socket of the on-off
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1441
  // application is not created until Application Start time, so we wouldn't be
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1442
  // able to hook the socket (now) at configuration time.  Second, even if we
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1443
  // could arrange a call after start time, the socket is not public so we
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1444
  // couldn't get at it.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1445
  //
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1446
  // So, we can cook up a simple version of the on-off application that does what
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1447
  // we want.  On the plus side we don't need all of the complexity of the on-off
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1448
  // application.  On the minus side, we don't have a helper, so we have to get
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1449
  // a little more involved in the details, but this is trivial.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1450
  //
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1451
  // So first, we create a socket and do the trace connect on it; then we pass
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1452
  // this socket into the constructor of our simple application which we then
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1453
  // install in the source node.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1454
  // ===========================================================================
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1455
  //
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1456
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1457
This should also be self-explanatory.  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1458
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1459
The next part is the declaration of the ``MyApp`` ``Application`` that
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1460
we put together to allow the ``Socket`` to be created at configuration
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1461
time.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1462
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1463
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1464
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1465
  class MyApp : public Application
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1466
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1467
  public:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1468
  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1469
    MyApp ();
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1470
    virtual ~MyApp();
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1471
  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1472
    void Setup (Ptr<Socket> socket, Address address, uint32_t packetSize, 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1473
      uint32_t nPackets, DataRate dataRate);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1474
  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1475
  private:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1476
    virtual void StartApplication (void);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1477
    virtual void StopApplication (void);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1478
  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1479
    void ScheduleTx (void);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1480
    void SendPacket (void);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1481
  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1482
    Ptr<Socket>     m_socket;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1483
    Address         m_peer;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1484
    uint32_t        m_packetSize;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1485
    uint32_t        m_nPackets;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1486
    DataRate        m_dataRate;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1487
    EventId         m_sendEvent;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1488
    bool            m_running;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1489
    uint32_t        m_packetsSent;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1490
  };
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1491
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1492
You can see that this class inherits from the |ns3| ``Application``
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1493
class.  Take a look at ``src/network/model/application.h`` if you are
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1494
interested in what is inherited.  The ``MyApp`` class is obligated to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1495
override the ``StartApplication`` and ``StopApplication`` methods.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1496
These methods are automatically called when ``MyApp`` is required to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1497
start and stop sending data during the simulation.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1498
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1499
Starting/Stopping Applications
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1500
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1501
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1502
It is worthwhile to spend a bit of time explaining how events actually
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1503
get started in the system.  This is another fairly deep explanation,
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1504
and can be ignored if you aren't planning on venturing down into the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1505
guts of the system.  It is useful, however, in that the discussion
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1506
touches on how some very important parts of |ns3| work and exposes
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1507
some important idioms.  If you are planning on implementing new
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1508
models, you probably want to understand this section.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1509
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1510
The most common way to start pumping events is to start an
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1511
``Application``.  This is done as the result of the following
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1512
(hopefully) familar lines of an |ns3| script::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1513
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1514
  ApplicationContainer apps = ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1515
  apps.Start (Seconds (1.0));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1516
  apps.Stop (Seconds (10.0));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1517
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1518
The application container code (see
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1519
``src/network/helper/application-container.h`` if you are interested)
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1520
loops through its contained applications and calls,
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1521
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1522
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1523
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1524
  app->SetStartTime (startTime);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1525
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1526
as a result of the ``apps.Start`` call and
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1527
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1528
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1529
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1530
  app->SetStopTime (stopTime);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1531
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1532
as a result of the ``apps.Stop`` call.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1533
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1534
The ultimate result of these calls is that we want to have the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1535
simulator automatically make calls into our ``Applications`` to tell
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1536
them when to start and stop.  In the case of ``MyApp``, it inherits
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1537
from class ``Application`` and overrides ``StartApplication``, and
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1538
``StopApplication``.  These are the functions that will be called by
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1539
the simulator at the appropriate time.  In the case of ``MyApp`` you
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1540
will find that ``MyApp::StartApplication`` does the initial ``Bind``,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1541
and ``Connect`` on the socket, and then starts data flowing by calling
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1542
``MyApp::SendPacket``.  ``MyApp::StopApplication`` stops generating
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1543
packets by cancelling any pending send events then closes the socket.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1544
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1545
One of the nice things about |ns3| is that you can completely ignore
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1546
the implementation details of how your ``Application`` is
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1547
"automagically" called by the simulator at the correct time.  But
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1548
since we have already ventured deep into |ns3| already, let's go for
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1549
it.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1550
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1551
If you look at ``src/network/model/application.cc`` you will find that
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1552
the ``SetStartTime`` method of an ``Application`` just sets the member
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1553
variable ``m_startTime`` and the ``SetStopTime`` method just sets
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1554
``m_stopTime``.  From there, without some hints, the trail will
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1555
probably end.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1556
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1557
The key to picking up the trail again is to know that there is a
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1558
global list of all of the nodes in the system.  Whenever you create a
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1559
node in a simulation, a pointer to that Node is added to the global
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1560
``NodeList``.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1561
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1562
Take a look at ``src/network/model/node-list.cc`` and search for
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1563
``NodeList::Add``.  The public static implementation calls into a
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1564
private implementation called ``NodeListPriv::Add``.  This is a
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1565
relatively common idom in |ns3|.  So, take a look at
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1566
``NodeListPriv::Add``.  There you will find,
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1567
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1568
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1569
9706
f5e3b185f047 Update tutorial with Start/DoStart to Initialize/DoInitialize change
Vedran Miletić <rivanvx@gmail.com>
parents: 9163
diff changeset
  1570
  Simulator::ScheduleWithContext (index, TimeStep (0), &Node::Initialize, node);
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1571
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1572
This tells you that whenever a Node is created in a simulation, as
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1573
a side-effect, a call to that node's ``Initialize`` method is
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1574
scheduled for you that happens at time zero.  Don't read too much into
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1575
that name, yet.  It doesn't mean that the Node is going to start doing
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1576
anything, it can be interpreted as an informational call into the
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1577
Node telling it that the simulation has started, not a call for
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1578
action telling the Node to start doing something.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1579
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1580
So, ``NodeList::Add`` indirectly schedules a call to
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1581
``Node::Initialize`` at time zero to advise a new Node that the
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1582
simulation has started.  If you look in ``src/network/model/node.h``
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1583
you will, however, not find a method called ``Node::Initialize``.  It
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1584
turns out that the ``Initialize`` method is inherited from class
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1585
``Object``.  All objects in the system can be notified when the
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1586
simulation starts, and objects of class Node are just one kind of
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1587
those objects.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1588
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1589
Take a look at ``src/core/model/object.cc`` next and search for
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1590
``Object::Initialize``.  This code is not as straightforward as you
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1591
might have expected since |ns3| ``Objects`` support aggregation.  The
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1592
code in ``Object::Initialize`` then loops through all of the objects
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1593
that have been aggregated together and calls their ``DoInitialize``
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1594
method.  This is another idiom that is very common in |ns3|, sometimes
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1595
called the "template design pattern.": a public non-virtual API
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1596
method, which stays constant across implementations, and that calls a
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1597
private virtual implementation method that is inherited and
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1598
implemented by subclasses.  The names are typically something like
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1599
``MethodName`` for the public API and ``DoMethodName`` for the private
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1600
API.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1601
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1602
This tells us that we should look for a ``Node::DoInitialize`` method
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1603
in ``src/network/model/node.cc`` for the method that will continue our
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1604
trail.  If you locate the code, you will find a method that loops
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1605
through all of the devices in the Node and then all of the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1606
applications in the Node calling ``device->Initialize`` and
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1607
``application->Initialize`` respectively.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1608
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1609
You may already know that classes ``Device`` and ``Application`` both
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1610
inherit from class ``Object`` and so the next step will be to look at
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1611
what happens when ``Application::DoInitialize`` is called.  Take a
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1612
look at ``src/network/model/application.cc`` and you will find::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1613
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1614
  void
9706
f5e3b185f047 Update tutorial with Start/DoStart to Initialize/DoInitialize change
Vedran Miletić <rivanvx@gmail.com>
parents: 9163
diff changeset
  1615
  Application::DoInitialize (void)
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1616
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1617
    m_startEvent = Simulator::Schedule (m_startTime, &Application::StartApplication, this);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1618
    if (m_stopTime != TimeStep (0))
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1619
      {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1620
        m_stopEvent = Simulator::Schedule (m_stopTime, &Application::StopApplication, this);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1621
      }
9706
f5e3b185f047 Update tutorial with Start/DoStart to Initialize/DoInitialize change
Vedran Miletić <rivanvx@gmail.com>
parents: 9163
diff changeset
  1622
    Object::DoInitialize ();
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1623
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1624
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1625
Here, we finally come to the end of the trail.  If you have kept it
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1626
all straight, when you implement an |ns3| ``Application``, your new
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1627
application inherits from class ``Application``.  You override the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1628
``StartApplication`` and ``StopApplication`` methods and provide
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1629
mechanisms for starting and stopping the flow of data out of your new
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1630
``Application``.  When a Node is created in the simulation, it is
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1631
added to a global ``NodeList``.  The act of adding a Node to this
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1632
``NodeList`` causes a simulator event to be scheduled for time zero
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1633
which calls the ``Node::Initialize`` method of the newly added
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1634
Node to be called when the simulation starts.  Since a Node
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1635
inherits from ``Object``, this calls the ``Object::Initialize`` method
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1636
on the Node which, in turn, calls the ``DoInitialize`` methods on
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1637
all of the ``Objects`` aggregated to the Node (think mobility
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1638
models).  Since the Node ``Object`` has overridden
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1639
``DoInitialize``, that method is called when the simulation starts.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1640
The ``Node::DoInitialize`` method calls the ``Initialize`` methods of
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1641
all of the ``Applications`` on the node.  Since ``Applications`` are
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1642
also ``Objects``, this causes ``Application::DoInitialize`` to be
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1643
called.  When ``Application::DoInitialize`` is called, it schedules
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1644
events for the ``StartApplication`` and ``StopApplication`` calls on
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1645
the ``Application``.  These calls are designed to start and stop the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1646
flow of data from the ``Application``
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1647
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1648
This has been another fairly long journey, but it only has to be made
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1649
once, and you now understand another very deep piece of |ns3|.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1650
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1651
The MyApp Application
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1652
~~~~~~~~~~~~~~~~~~~~~
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1653
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1654
The ``MyApp`` ``Application`` needs a constructor and a destructor, of
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1655
course::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1656
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1657
  MyApp::MyApp ()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1658
    : m_socket (0),
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1659
      m_peer (),
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1660
      m_packetSize (0),
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1661
      m_nPackets (0),
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1662
      m_dataRate (0),
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1663
      m_sendEvent (),
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1664
      m_running (false),
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1665
      m_packetsSent (0)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1666
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1667
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1668
  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1669
  MyApp::~MyApp()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1670
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1671
    m_socket = 0;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1672
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1673
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1674
The existence of the next bit of code is the whole reason why we wrote
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1675
this ``Application`` in the first place.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1676
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1677
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1678
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1679
  void
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1680
  MyApp::Setup (Ptr<Socket> socket, Address address, uint32_t packetSize, 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1681
                       uint32_t nPackets, DataRate dataRate)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1682
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1683
    m_socket = socket;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1684
    m_peer = address;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1685
    m_packetSize = packetSize;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1686
    m_nPackets = nPackets;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1687
    m_dataRate = dataRate;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1688
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1689
  
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1690
This code should be pretty self-explanatory.  We are just initializing
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1691
member variables.  The important one from the perspective of tracing
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1692
is the ``Ptr<Socket> socket`` which we needed to provide to the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1693
application during configuration time.  Recall that we are going to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1694
create the ``Socket`` as a ``TcpSocket`` (which is implemented by
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1695
``TcpNewReno``) and hook its "CongestionWindow" trace source before
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1696
passing it to the ``Setup`` method.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1697
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1698
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1699
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1700
  void
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1701
  MyApp::StartApplication (void)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1702
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1703
    m_running = true;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1704
    m_packetsSent = 0;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1705
    m_socket->Bind ();
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1706
    m_socket->Connect (m_peer);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1707
    SendPacket ();
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1708
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1709
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1710
The above code is the overridden implementation
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1711
``Application::StartApplication`` that will be automatically called by
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1712
the simulator to start our ``Application`` running at the appropriate
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1713
time.  You can see that it does a ``Socket`` ``Bind`` operation.  If
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1714
you are familiar with Berkeley Sockets this shouldn't be a surprise.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1715
It performs the required work on the local side of the connection just
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1716
as you might expect.  The following ``Connect`` will do what is
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1717
required to establish a connection with the TCP at ``Address`` m_peer.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1718
It should now be clear why we need to defer a lot of this to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1719
simulation time, since the ``Connect`` is going to need a fully
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1720
functioning network to complete.  After the ``Connect``, the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1721
``Application`` then starts creating simulation events by calling
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1722
``SendPacket``.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1723
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1724
The next bit of code explains to the ``Application`` how to stop
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1725
creating simulation events.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1726
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1727
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1728
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1729
  void
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1730
  MyApp::StopApplication (void)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1731
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1732
    m_running = false;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1733
  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1734
    if (m_sendEvent.IsRunning ())
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1735
      {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1736
        Simulator::Cancel (m_sendEvent);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1737
      }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1738
  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1739
    if (m_socket)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1740
      {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1741
        m_socket->Close ();
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1742
      }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1743
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1744
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1745
Every time a simulation event is scheduled, an ``Event`` is created.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1746
If the ``Event`` is pending execution or executing, its method
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1747
``IsRunning`` will return ``true``.  In this code, if ``IsRunning()``
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1748
returns true, we ``Cancel`` the event which removes it from the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1749
simulator event queue.  By doing this, we break the chain of events
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1750
that the ``Application`` is using to keep sending its ``Packets`` and
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1751
the ``Application`` goes quiet.  After we quiet the ``Application`` we
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1752
``Close`` the socket which tears down the TCP connection.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1753
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1754
The socket is actually deleted in the destructor when the ``m_socket =
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1755
0`` is executed.  This removes the last reference to the underlying
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1756
Ptr<Socket> which causes the destructor of that Object to be called.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1757
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1758
Recall that ``StartApplication`` called ``SendPacket`` to start the
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1759
chain of events that describes the ``Application`` behavior.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1760
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1761
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1762
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1763
  void
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1764
  MyApp::SendPacket (void)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1765
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1766
    Ptr<Packet> packet = Create<Packet> (m_packetSize);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1767
    m_socket->Send (packet);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1768
  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1769
    if (++m_packetsSent < m_nPackets)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1770
      {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1771
        ScheduleTx ();
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1772
      }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1773
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1774
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1775
Here, you see that ``SendPacket`` does just that.  It creates a
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1776
``Packet`` and then does a ``Send`` which, if you know Berkeley
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1777
Sockets, is probably just what you expected to see.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1778
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1779
It is the responsibility of the ``Application`` to keep scheduling the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1780
chain of events, so the next lines call ``ScheduleTx`` to schedule
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1781
another transmit event (a ``SendPacket``) until the ``Application``
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1782
decides it has sent enough.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1783
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1784
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1785
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1786
  void
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1787
  MyApp::ScheduleTx (void)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1788
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1789
    if (m_running)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1790
      {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1791
        Time tNext (Seconds (m_packetSize * 8 / static_cast<double> (m_dataRate.GetBitRate ())));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1792
        m_sendEvent = Simulator::Schedule (tNext, &MyApp::SendPacket, this);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1793
      }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1794
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1795
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1796
Here, you see that ``ScheduleTx`` does exactly that.  If the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1797
``Application`` is running (if ``StopApplication`` has not been
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1798
called) it will schedule a new event, which calls ``SendPacket``
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1799
again.  The alert reader will spot something that also trips up new
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1800
users.  The data rate of an ``Application`` is just that.  It has
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1801
nothing to do with the data rate of an underlying ``Channel``.  This
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1802
is the rate at which the ``Application`` produces bits.  It does not
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1803
take into account any overhead for the various protocols or channels
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1804
that it uses to transport the data.  If you set the data rate of an
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1805
``Application`` to the same data rate as your underlying ``Channel``
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1806
you will eventually get a buffer overflow.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1807
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1808
Trace Sinks
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1809
~~~~~~~~~~~
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1810
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1811
The whole point of this exercise is to get trace callbacks from TCP
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1812
indicating the congestion window has been updated.  The next piece of
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1813
code implements the corresponding trace sink::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1814
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1815
  static void
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1816
  CwndChange (uint32_t oldCwnd, uint32_t newCwnd)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1817
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1818
    NS_LOG_UNCOND (Simulator::Now ().GetSeconds () << "\t" << newCwnd);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1819
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1820
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1821
This should be very familiar to you now, so we won't dwell on the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1822
details.  This function just logs the current simulation time and the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1823
new value of the congestion window every time it is changed.  You can
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1824
probably imagine that you could load the resulting output into a
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1825
graphics program (gnuplot or Excel) and immediately see a nice graph
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1826
of the congestion window behavior over time.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1827
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1828
We added a new trace sink to show where packets are dropped.  We are
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1829
going to add an error model to this code also, so we wanted to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1830
demonstrate this working.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1831
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1832
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1833
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1834
  static void
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1835
  RxDrop (Ptr<const Packet> p)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1836
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1837
    NS_LOG_UNCOND ("RxDrop at " << Simulator::Now ().GetSeconds ());
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1838
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1839
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1840
This trace sink will be connected to the "PhyRxDrop" trace source of
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1841
the point-to-point NetDevice.  This trace source fires when a packet
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1842
is dropped by the physical layer of a ``NetDevice``.  If you take a
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1843
small detour to the source
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1844
(``src/point-to-point/model/point-to-point-net-device.cc``) you will
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1845
see that this trace source refers to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1846
``PointToPointNetDevice::m_phyRxDropTrace``.  If you then look in
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1847
``src/point-to-point/model/point-to-point-net-device.h`` for this
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1848
member variable, you will find that it is declared as a
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1849
``TracedCallback<Ptr<const Packet> >``.  This should tell you that the
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1850
callback target should be a function that returns void and takes a
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1851
single parameter which is a ``Ptr<const Packet>`` (assuming we use
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1852
``ConnectWithoutContext``) -- just what we have above.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1853
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1854
Main Program
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1855
~~~~~~~~~~~~
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1856
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1857
The following code should be very familiar to you by now::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1858
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1859
  int
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1860
  main (int argc, char *argv[])
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1861
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1862
    NodeContainer nodes;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1863
    nodes.Create (2);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1864
  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1865
    PointToPointHelper pointToPoint;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1866
    pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1867
    pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1868
  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1869
    NetDeviceContainer devices;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1870
    devices = pointToPoint.Install (nodes);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1871
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1872
This creates two nodes with a point-to-point channel between them,
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1873
just as shown in the illustration at the start of the file.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1874
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1875
The next few lines of code show something new.  If we trace a
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1876
connection that behaves perfectly, we will end up with a monotonically
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1877
increasing congestion window.  To see any interesting behavior, we
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1878
really want to introduce link errors which will drop packets, cause
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1879
duplicate ACKs and trigger the more interesting behaviors of the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1880
congestion window.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1881
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1882
|ns3| provides ``ErrorModel`` objects which can be attached to
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1883
``Channels``.  We are using the ``RateErrorModel`` which allows us to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1884
introduce errors
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1885
into a ``Channel`` at a given *rate*. 
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1886
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1887
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1888
8986
3391f6a7fb3b Replace src/network usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8906
diff changeset
  1889
  Ptr<RateErrorModel> em = CreateObject<RateErrorModel> ();
3391f6a7fb3b Replace src/network usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8906
diff changeset
  1890
  em->SetAttribute ("ErrorRate", DoubleValue (0.00001));
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1891
  devices.Get (1)->SetAttribute ("ReceiveErrorModel", PointerValue (em));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1892
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1893
The above code instantiates a ``RateErrorModel`` Object, and we set
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1894
the "ErrorRate" ``Attribute`` to the desired value.  We then set the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1895
resulting instantiated ``RateErrorModel`` as the error model used by
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1896
the point-to-point ``NetDevice``.  This will give us some
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1897
retransmissions and make our plot a little more interesting.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1898
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1899
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1900
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1901
  InternetStackHelper stack;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1902
  stack.Install (nodes);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1903
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1904
  Ipv4AddressHelper address;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1905
  address.SetBase ("10.1.1.0", "255.255.255.252");
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1906
  Ipv4InterfaceContainer interfaces = address.Assign (devices);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1907
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1908
The above code should be familiar.  It installs internet stacks on our
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1909
two nodes and creates interfaces and assigns IP addresses for the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1910
point-to-point devices.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1911
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1912
Since we are using TCP, we need something on the destination Node to
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1913
receive TCP connections and data.  The ``PacketSink`` ``Application``
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1914
is commonly used in |ns3| for that purpose.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1915
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1916
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1917
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1918
  uint16_t sinkPort = 8080;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1919
  Address sinkAddress (InetSocketAddress(interfaces.GetAddress (1), sinkPort));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1920
  PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1921
    InetSocketAddress (Ipv4Address::GetAny (), sinkPort));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1922
  ApplicationContainer sinkApps = packetSinkHelper.Install (nodes.Get (1));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1923
  sinkApps.Start (Seconds (0.));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1924
  sinkApps.Stop (Seconds (20.));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1925
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1926
This should all be familiar, with the exception of,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1927
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1928
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1929
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1930
  PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1931
    InetSocketAddress (Ipv4Address::GetAny (), sinkPort));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1932
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1933
This code instantiates a ``PacketSinkHelper`` and tells it to create
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1934
sockets using the class ``ns3::TcpSocketFactory``.  This class
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1935
implements a design pattern called "object factory" which is a
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1936
commonly used mechanism for specifying a class used to create objects
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1937
in an abstract way.  Here, instead of having to create the objects
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1938
themselves, you provide the ``PacketSinkHelper`` a string that
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1939
specifies a ``TypeId`` string used to create an object which can then
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1940
be used, in turn, to create instances of the Objects created by the
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1941
factory.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1942
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1943
The remaining parameter tells the ``Application`` which address and
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1944
port it should ``Bind`` to.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1945
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1946
The next two lines of code will create the socket and connect the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1947
trace source.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1948
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1949
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1950
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1951
  Ptr<Socket> ns3TcpSocket = Socket::CreateSocket (nodes.Get (0), 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1952
    TcpSocketFactory::GetTypeId ());
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1953
  ns3TcpSocket->TraceConnectWithoutContext ("CongestionWindow", 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1954
    MakeCallback (&CwndChange));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1955
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1956
The first statement calls the static member function
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1957
``Socket::CreateSocket`` and provides a Node and an explicit
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1958
``TypeId`` for the object factory used to create the socket.  This is
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1959
a slightly lower level call than the ``PacketSinkHelper`` call above,
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1960
and uses an explicit C++ type instead of one referred to by a string.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1961
Otherwise, it is conceptually the same thing.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1962
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1963
Once the ``TcpSocket`` is created and attached to the Node, we can
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1964
use ``TraceConnectWithoutContext`` to connect the CongestionWindow
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1965
trace source to our trace sink.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1966
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1967
Recall that we coded an ``Application`` so we could take that
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1968
``Socket`` we just made (during configuration time) and use it in
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1969
simulation time.  We now have to instantiate that ``Application``.  We
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1970
didn't go to any trouble to create a helper to manage the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1971
``Application`` so we are going to have to create and install it
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1972
"manually".  This is actually quite easy::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1973
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1974
  Ptr<MyApp> app = CreateObject<MyApp> ();
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1975
  app->Setup (ns3TcpSocket, sinkAddress, 1040, 1000, DataRate ("1Mbps"));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1976
  nodes.Get (0)->AddApplication (app);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1977
  app->Start (Seconds (1.));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1978
  app->Stop (Seconds (20.));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1979
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1980
The first line creates an ``Object`` of type ``MyApp`` -- our
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1981
``Application``.  The second line tells the ``Application`` what
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1982
``Socket`` to use, what address to connect to, how much data to send
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1983
at each send event, how many send events to generate and the rate at
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1984
which to produce data from those events.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1985
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1986
Next, we manually add the ``MyApp Application`` to the source Node and
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1987
explicitly call the ``Start`` and ``Stop`` methods on the
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1988
``Application`` to tell it when to start and stop doing its thing.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1989
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1990
We need to actually do the connect from the receiver point-to-point
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  1991
``NetDevice`` drop event to our ``RxDrop`` callback now.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1992
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1993
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1994
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1995
  devices.Get (1)->TraceConnectWithoutContext("PhyRxDrop", MakeCallback (&RxDrop));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1996
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1997
It should now be obvious that we are getting a reference to the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1998
receiving ``Node NetDevice`` from its container and connecting the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  1999
trace source defined by the attribute "PhyRxDrop" on that device to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2000
the trace sink ``RxDrop``.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2001
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2002
Finally, we tell the simulator to override any ``Applications`` and
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2003
just stop processing events at 20 seconds into the simulation.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2004
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2005
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2006
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2007
    Simulator::Stop (Seconds(20));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2008
    Simulator::Run ();
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2009
    Simulator::Destroy ();
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2010
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2011
    return 0;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2012
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2013
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2014
Recall that as soon as ``Simulator::Run`` is called, configuration
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2015
time ends, and simulation time begins.  All of the work we
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2016
orchestrated by creating the ``Application`` and teaching it how to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2017
connect and send data actually happens during this function call.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2018
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2019
As soon as ``Simulator::Run`` returns, the simulation is complete and
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2020
we enter the teardown phase.  In this case, ``Simulator::Destroy``
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2021
takes care of the gory details and we just return a success code after
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2022
it completes.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2023
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2024
Running ``fifth.cc``
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2025
++++++++++++++++++++
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2026
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2027
Since we have provided the file ``fifth.cc`` for you, if you have
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2028
built your distribution (in debug mode since it uses ``NS_LOG`` -- recall
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2029
that optimized builds optimize out ``NS_LOG``) it will be waiting for you
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2030
to run.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2031
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
  2032
.. sourcecode:: bash
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
  2033
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
  2034
  $ ./waf --run fifth
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
  2035
  Waf: Entering directory `/home/craigdo/repos/ns-3-allinone-dev/ns-3-dev/build'
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2036
  Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone-dev/ns-3-dev/build'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2037
  'build' finished successfully (0.684s)
11051
fce08b2064ae update tutorial fifth.cc program output
Tom Henderson <tomh@tomh.org>
parents: 10976
diff changeset
  2038
  1       536
fce08b2064ae update tutorial fifth.cc program output
Tom Henderson <tomh@tomh.org>
parents: 10976
diff changeset
  2039
  1.0093  1072
fce08b2064ae update tutorial fifth.cc program output
Tom Henderson <tomh@tomh.org>
parents: 10976
diff changeset
  2040
  1.01528 1608
fce08b2064ae update tutorial fifth.cc program output
Tom Henderson <tomh@tomh.org>
parents: 10976
diff changeset
  2041
  1.02167 2144
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2042
  ...
11051
fce08b2064ae update tutorial fifth.cc program output
Tom Henderson <tomh@tomh.org>
parents: 10976
diff changeset
  2043
  1.11319 8040
fce08b2064ae update tutorial fifth.cc program output
Tom Henderson <tomh@tomh.org>
parents: 10976
diff changeset
  2044
  1.12151 8576
fce08b2064ae update tutorial fifth.cc program output
Tom Henderson <tomh@tomh.org>
parents: 10976
diff changeset
  2045
  1.12983 9112
fce08b2064ae update tutorial fifth.cc program output
Tom Henderson <tomh@tomh.org>
parents: 10976
diff changeset
  2046
  RxDrop at 1.13696
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2047
  ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2048
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2049
You can probably see immediately a downside of using prints of any
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2050
kind in your traces.  We get those extraneous waf messages printed all
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2051
over our interesting information along with those RxDrop messages.  We
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2052
will remedy that soon, but I'm sure you can't wait to see the results
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2053
of all of this work.  Let's redirect that output to a file called
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2054
``cwnd.dat``:
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2055
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
  2056
.. sourcecode:: bash
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
  2057
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
  2058
  $ ./waf --run fifth > cwnd.dat 2>&1
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2059
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2060
Now edit up "cwnd.dat" in your favorite editor and remove the waf
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2061
build status and drop lines, leaving only the traced data (you could
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2062
also comment out the ``TraceConnectWithoutContext("PhyRxDrop",
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2063
MakeCallback (&RxDrop));`` in the script to get rid of the drop prints
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2064
just as easily.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2065
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2066
You can now run gnuplot (if you have it installed) and tell it to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2067
generate some pretty pictures:
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2068
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
  2069
.. sourcecode:: bash
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
  2070
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
  2071
  $ gnuplot
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2072
  gnuplot> set terminal png size 640,480
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2073
  gnuplot> set output "cwnd.png"
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2074
  gnuplot> plot "cwnd.dat" using 1:2 title 'Congestion Window' with linespoints
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2075
  gnuplot> exit
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2076
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2077
You should now have a graph of the congestion window versus time
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2078
sitting in the file "cwnd.png" that looks like:
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2079
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2080
.. figure:: figures/cwnd.png
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2081
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2082
Using Mid-Level Helpers
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2083
+++++++++++++++++++++++
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2084
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2085
In the previous section, we showed how to hook a trace source and get
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2086
hopefully interesting information out of a simulation.  Perhaps you
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2087
will recall that we called logging to the standard output using
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2088
``std::cout`` a "blunt instrument" much earlier in this chapter.  We
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2089
also wrote about how it was a problem having to parse the log output
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2090
in order to isolate interesting information.  It may have occurred to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2091
you that we just spent a lot of time implementing an example that
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2092
exhibits all of the problems we purport to fix with the |ns3| tracing
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2093
system!  You would be correct.  But, bear with us.  We're not done
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2094
yet.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2095
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2096
One of the most important things we want to do is to is to have the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2097
ability to easily control the amount of output coming out of the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2098
simulation; and we also want to save those data to a file so we can
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2099
refer back to it later.  We can use the mid-level trace helpers
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2100
provided in |ns3| to do just that and complete the picture.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2101
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2102
We provide a script that writes the cwnd change and drop events
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2103
developed in the example ``fifth.cc`` to disk in separate files.  The
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2104
cwnd changes are stored as a tab-separated ASCII file and the drop
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2105
events are stored in a PCAP file.  The changes to make this happen are
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2106
quite small.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2107
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2108
Walkthrough: ``sixth.cc``
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2109
~~~~~~~~~~~~~~~~~~~~~~~~~
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2110
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2111
Let's take a look at the changes required to go from ``fifth.cc`` to
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2112
``sixth.cc``.  Open ``examples/tutorial/sixth.cc`` in your favorite
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2113
editor.  You can see the first change by searching for CwndChange.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2114
You will find that we have changed the signatures for the trace sinks
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2115
and have added a single line to each sink that writes the traced
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2116
information to a stream representing a file.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2117
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2118
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2119
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2120
  static void
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2121
  CwndChange (Ptr<OutputStreamWrapper> stream, uint32_t oldCwnd, uint32_t newCwnd)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2122
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2123
    NS_LOG_UNCOND (Simulator::Now ().GetSeconds () << "\t" << newCwnd);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2124
    *stream->GetStream () << Simulator::Now ().GetSeconds () << "\t" << oldCwnd << "\t" << newCwnd << std::endl;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2125
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2126
  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2127
  static void
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2128
  RxDrop (Ptr<PcapFileWrapper> file, Ptr<const Packet> p)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2129
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2130
    NS_LOG_UNCOND ("RxDrop at " << Simulator::Now ().GetSeconds ());
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2131
    file->Write(Simulator::Now(), p);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2132
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2133
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2134
We have added a "stream" parameter to the ``CwndChange`` trace sink.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2135
This is an object that holds (keeps safely alive) a C++ output stream.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2136
It turns out that this is a very simple object, but one that manages
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2137
lifetime issues for the stream and solves a problem that even
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2138
experienced C++ users run into.  It turns out that the copy
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2139
constructor for ``std::ostream`` is marked private.  This means that
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2140
``std::ostreams`` do not obey value semantics and cannot be used in
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2141
any mechanism that requires the stream to be copied.  This includes
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2142
the |ns3| callback system, which as you may recall, requires objects
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2143
that obey value semantics.  Further notice that we have added the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2144
following line in the ``CwndChange`` trace sink implementation::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2145
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2146
  *stream->GetStream () << Simulator::Now ().GetSeconds () << "\t" << oldCwnd << "\t" << newCwnd << std::endl;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2147
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2148
This would be very familiar code if you replaced ``*stream->GetStream
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2149
()`` with ``std::cout``, as in::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2150
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2151
  std::cout << Simulator::Now ().GetSeconds () << "\t" << oldCwnd << "\t" << newCwnd << std::endl;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2152
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2153
This illustrates that the ``Ptr<OutputStreamWrapper>`` is really just
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2154
carrying around a ``std::ofstream`` for you, and you can use it here
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2155
like any other output stream.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2156
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2157
A similar situation happens in ``RxDrop`` except that the object being
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2158
passed around (a ``Ptr<PcapFileWrapper>``) represents a PCAP file.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2159
There is a one-liner in the trace sink to write a timestamp and the
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2160
contents of the packet being dropped to the PCAP file::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2161
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2162
  file->Write(Simulator::Now(), p);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2163
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2164
Of course, if we have objects representing the two files, we need to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2165
create them somewhere and also cause them to be passed to the trace
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2166
sinks.  If you look in the ``main`` function, you will find new code
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2167
to do just that::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2168
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2169
  AsciiTraceHelper asciiTraceHelper;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2170
  Ptr<OutputStreamWrapper> stream = asciiTraceHelper.CreateFileStream ("sixth.cwnd");
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2171
  ns3TcpSocket->TraceConnectWithoutContext ("CongestionWindow", MakeBoundCallback (&CwndChange, stream));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2172
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2173
  ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2174
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2175
  PcapHelper pcapHelper;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2176
  Ptr<PcapFileWrapper> file = pcapHelper.CreateFile ("sixth.pcap", std::ios::out, PcapHelper::DLT_PPP);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2177
  devices.Get (1)->TraceConnectWithoutContext("PhyRxDrop", MakeBoundCallback (&RxDrop, file));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2178
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2179
In the first section of the code snippet above, we are creating the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2180
ASCII trace file, creating an object responsible for managing it and
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2181
using a variant of the callback creation function to arrange for the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2182
object to be passed to the sink.  Our ASCII trace helpers provide a
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2183
rich set of functions to make using text (ASCII) files easy.  We are
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2184
just going to illustrate the use of the file stream creation function
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2185
here.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2186
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2187
The ``CreateFileStream`` function is basically going to instantiate
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2188
a ``std::ofstream`` object and create a new file (or truncate an existing
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2189
file).  This ``std::ofstream`` is packaged up in an |ns3| object for lifetime
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2190
management and copy constructor issue resolution.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2191
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2192
We then take this |ns3| object representing the file and pass it to
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2193
``MakeBoundCallback()``.  This function creates a callback just like
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2194
``MakeCallback()``, but it "binds" a new value to the callback.  This
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2195
value is added as the first argument to the callback before it is called.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2196
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2197
Essentially, ``MakeBoundCallback(&CwndChange, stream)`` causes the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2198
trace source to add the additional "stream" parameter to the front of
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2199
the formal parameter list before invoking the callback.  This changes
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2200
the required signature of the ``CwndChange`` sink to match the one
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2201
shown above, which includes the "extra" parameter
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2202
``Ptr<OutputStreamWrapper> stream``.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2203
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2204
In the second section of code in the snippet above, we instantiate a
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2205
``PcapHelper`` to do the same thing for our PCAP trace file that we
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2206
did with the ``AsciiTraceHelper``. The line of code,
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2207
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2208
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2209
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2210
  Ptr<PcapFileWrapper> file = pcapHelper.CreateFile ("sixth.pcap",
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2211
  "w", PcapHelper::DLT_PPP);
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2212
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2213
creates a PCAP file named "sixth.pcap" with file mode "w".  This means
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2214
that the new file is truncated (contents deleted) if an existing file
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2215
with that name is found.  The final parameter is the "data link type"
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2216
of the new PCAP file.  These are the same as the PCAP library data
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2217
link types defined in ``bpf.h`` if you are familar with PCAP.  In this
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2218
case, ``DLT_PPP`` indicates that the PCAP file is going to contain
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2219
packets prefixed with point to point headers.  This is true since the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2220
packets are coming from our point-to-point device driver.  Other
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2221
common data link types are DLT_EN10MB (10 MB Ethernet) appropriate for
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2222
csma devices and DLT_IEEE802_11 (IEEE 802.11) appropriate for wifi
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2223
devices.  These are defined in ``src/network/helper/trace-helper.h``
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2224
if you are interested in seeing the list.  The entries in the list
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2225
match those in ``bpf.h`` but we duplicate them to avoid a PCAP source
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2226
dependence.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2227
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2228
A |ns3| object representing the PCAP file is returned from
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2229
``CreateFile`` and used in a bound callback exactly as it was in the
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2230
ASCII case.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2231
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2232
An important detour: It is important to notice that even though both
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2233
of these objects are declared in very similar ways,
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2234
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2235
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2236
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2237
  Ptr<PcapFileWrapper> file ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2238
  Ptr<OutputStreamWrapper> stream ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2239
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2240
The underlying objects are entirely different.  For example, the
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2241
``Ptr<PcapFileWrapper>`` is a smart pointer to an |ns3| Object that is
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2242
a fairly heavyweight thing that supports Attributes and is integrated
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2243
into the Config system.  The ``Ptr<OutputStreamWrapper>``, on the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2244
other hand, is a smart pointer to a reference counted object that is a
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2245
very lightweight thing.  Remember to look at the object you are
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2246
referencing before making any assumptions about the "powers" that
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2247
object may have.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2248
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2249
For example, take a look at ``src/network/utils/pcap-file-wrapper.h``
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2250
in the distribution and notice,
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2251
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2252
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2253
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2254
  class PcapFileWrapper : public Object
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2255
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2256
that class ``PcapFileWrapper`` is an |ns3| Object by virtue of its
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2257
inheritance.  Then look at
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2258
``src/network/model/output-stream-wrapper.h`` and notice,
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2259
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2260
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2261
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2262
  class OutputStreamWrapper : public
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2263
  SimpleRefCount<OutputStreamWrapper>
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2264
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2265
that this object is not an |ns3| Object at all, it is "merely" a C++
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2266
object that happens to support intrusive reference counting.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2267
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2268
The point here is that just because you read ``Ptr<something>`` it does
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2269
not necessarily mean that ``something`` is an |ns3| Object on which you
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2270
can hang |ns3| Attributes, for example.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2271
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2272
Now, back to the example.  If you build and run this example,
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2273
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
  2274
.. sourcecode:: bash
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
  2275
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
  2276
  $ ./waf --run sixth
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2277
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2278
you will see the same messages appear as when you ran "fifth", but two
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2279
new files will appear in the top-level directory of your |ns3|
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2280
distribution.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2281
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
  2282
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2283
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2284
  sixth.cwnd  sixth.pcap
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2285
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2286
Since "sixth.cwnd" is an ASCII text file, you can view it with ``cat``
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2287
or your favorite file viewer.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2288
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
  2289
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2290
11052
37eb915e9932 update tutorial sixth.cc program output
Tom Henderson <tomh@tomh.org>
parents: 11051
diff changeset
  2291
  1       0       536
37eb915e9932 update tutorial sixth.cc program output
Tom Henderson <tomh@tomh.org>
parents: 11051
diff changeset
  2292
  1.0093  536     1072
37eb915e9932 update tutorial sixth.cc program output
Tom Henderson <tomh@tomh.org>
parents: 11051
diff changeset
  2293
  1.01528 1072    1608
37eb915e9932 update tutorial sixth.cc program output
Tom Henderson <tomh@tomh.org>
parents: 11051
diff changeset
  2294
  1.02167 1608    2144
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2295
  ...
11052
37eb915e9932 update tutorial sixth.cc program output
Tom Henderson <tomh@tomh.org>
parents: 11051
diff changeset
  2296
  9.69256 5149	  5204
37eb915e9932 update tutorial sixth.cc program output
Tom Henderson <tomh@tomh.org>
parents: 11051
diff changeset
  2297
  9.89311 5204	  5259
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2298
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2299
You have a tab separated file with a timestamp, an old congestion
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2300
window and a new congestion window suitable for directly importing
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2301
into your plot program.  There are no extraneous prints in the file,
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2302
no parsing or editing is required.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2303
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2304
Since "sixth.pcap" is a PCAP file, you can fiew it with ``tcpdump``.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2305
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9706
diff changeset
  2306
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2307
11052
37eb915e9932 update tutorial sixth.cc program output
Tom Henderson <tomh@tomh.org>
parents: 11051
diff changeset
  2308
  reading from file sixth.pcap, link-type PPP (PPP)
37eb915e9932 update tutorial sixth.cc program output
Tom Henderson <tomh@tomh.org>
parents: 11051
diff changeset
  2309
  1.136956 IP 10.1.1.1.49153 > 10.1.1.2.8080: Flags [.], seq 17177:17681, ack 1, win 32768, options [TS val 1133 ecr 1127,eol], length 504
37eb915e9932 update tutorial sixth.cc program output
Tom Henderson <tomh@tomh.org>
parents: 11051
diff changeset
  2310
  1.403196 IP 10.1.1.1.49153 > 10.1.1.2.8080: Flags [.], seq 33280:33784, ack 1, win 32768, options [TS val 1399 ecr 1394,eol], length 504
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2311
  ...
11052
37eb915e9932 update tutorial sixth.cc program output
Tom Henderson <tomh@tomh.org>
parents: 11051
diff changeset
  2312
  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
37eb915e9932 update tutorial sixth.cc program output
Tom Henderson <tomh@tomh.org>
parents: 11051
diff changeset
  2313
  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
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2314
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2315
You have a PCAP file with the packets that were dropped in the
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2316
simulation.  There are no other packets present in the file and there
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2317
is nothing else present to make life difficult.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2318
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2319
It's been a long journey, but we are now at a point where we can
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2320
appreciate the |ns3| tracing system.  We have pulled important events
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2321
out of the middle of a TCP implementation and a device driver.  We
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2322
stored those events directly in files usable with commonly known
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2323
tools.  We did this without modifying any of the core code involved,
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2324
and we did this in only 18 lines of code::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2325
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2326
  static void
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2327
  CwndChange (Ptr<OutputStreamWrapper> stream, uint32_t oldCwnd, uint32_t newCwnd)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2328
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2329
    NS_LOG_UNCOND (Simulator::Now ().GetSeconds () << "\t" << newCwnd);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2330
    *stream->GetStream () << Simulator::Now ().GetSeconds () << "\t" << oldCwnd << "\t" << newCwnd << std::endl;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2331
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2332
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2333
  ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2334
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2335
  AsciiTraceHelper asciiTraceHelper;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2336
  Ptr<OutputStreamWrapper> stream = asciiTraceHelper.CreateFileStream ("sixth.cwnd");
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2337
  ns3TcpSocket->TraceConnectWithoutContext ("CongestionWindow", MakeBoundCallback (&CwndChange, stream));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2338
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2339
  ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2340
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2341
  static void
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2342
  RxDrop (Ptr<PcapFileWrapper> file, Ptr<const Packet> p)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2343
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2344
    NS_LOG_UNCOND ("RxDrop at " << Simulator::Now ().GetSeconds ());
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2345
    file->Write(Simulator::Now(), p);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2346
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2347
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2348
  ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2349
  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2350
  PcapHelper pcapHelper;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2351
  Ptr<PcapFileWrapper> file = pcapHelper.CreateFile ("sixth.pcap", "w", PcapHelper::DLT_PPP);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2352
  devices.Get (1)->TraceConnectWithoutContext("PhyRxDrop", MakeBoundCallback (&RxDrop, file));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2353
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2354
Trace Helpers
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2355
*************
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2356
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2357
The |ns3| trace helpers provide a rich environment for configuring and
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2358
selecting different trace events and writing them to files.  In
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2359
previous sections, primarily :ref:`BuildingTopologies`, we have seen
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2360
several varieties of the trace helper methods designed for use inside
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2361
other (device) helpers.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2362
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2363
Perhaps you will recall seeing some of these variations: 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2364
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2365
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2366
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2367
  pointToPoint.EnablePcapAll ("second");
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2368
  pointToPoint.EnablePcap ("second", p2pNodes.Get (0)->GetId (), 0);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2369
  csma.EnablePcap ("third", csmaDevices.Get (0), true);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2370
  pointToPoint.EnableAsciiAll (ascii.CreateFileStream ("myfirst.tr"));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2371
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2372
What may not be obvious, though, is that there is a consistent model
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2373
for all of the trace-related methods found in the system.  We will now
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2374
take a little time and take a look at the "big picture".
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2375
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2376
There are currently two primary use cases of the tracing helpers in
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2377
|ns3|:  device helpers and protocol helpers.  Device helpers look at
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2378
the problem of specifying which traces should be enabled through a
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2379
(node, device) pair.  For example, you may want to specify that PCAP
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2380
tracing should be enabled on a particular device on a specific node.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2381
This follows from the |ns3| device conceptual model, and also the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2382
conceptual models of the various device helpers.  Following naturally
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2383
from this, the files created follow a ``<prefix>-<node>-<device>`` naming
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2384
convention.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2385
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2386
Protocol helpers look at the problem of specifying which traces should
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2387
be enabled through a protocol and interface pair.  This follows from
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2388
the |ns3| protocol stack conceptual model, and also the conceptual
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2389
models of internet stack helpers.  Naturally, the trace files should
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2390
follow a ``<prefix>-<protocol>-<interface>`` naming convention.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2391
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2392
The trace helpers therefore fall naturally into a two-dimensional
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2393
taxonomy.  There are subtleties that prevent all four classes from
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2394
behaving identically, but we do strive to make them all work as
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2395
similarly as possible; and whenever possible there are analogs for all
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2396
methods in all classes.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2397
10110
19cd300c6fc6 Fix check marks in Tutorial
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
  2398
  +-----------------+---------+---------+
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2399
  |                 |  PCAP   |  ASCII  |
10110
19cd300c6fc6 Fix check marks in Tutorial
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
  2400
  +=================+=========+=========+
19cd300c6fc6 Fix check marks in Tutorial
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
  2401
  | Device Helper   | |check| | |check| |
19cd300c6fc6 Fix check marks in Tutorial
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
  2402
  +-----------------+---------+---------+
19cd300c6fc6 Fix check marks in Tutorial
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
  2403
  | Protocol Helper | |check| | |check| |
19cd300c6fc6 Fix check marks in Tutorial
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
  2404
  +-----------------+---------+---------+
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2405
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2406
We use an approach called a ``mixin`` to add tracing functionality to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2407
our helper classes.  A ``mixin`` is a class that provides
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2408
functionality when it is inherited by a subclass.  Inheriting from a
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2409
mixin is not considered a form of specialization but is really a way
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2410
to collect functionality.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2411
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2412
Let's take a quick look at all four of these cases and their
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2413
respective ``mixins``.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2414
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2415
Device Helpers
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2416
++++++++++++++
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2417
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2418
PCAP
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2419
~~~~
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2420
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2421
The goal of these helpers is to make it easy to add a consistent PCAP
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2422
trace facility to an |ns3| device.  We want all of the various flavors
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2423
of PCAP tracing to work the same across all devices, so the methods of
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2424
these helpers are inherited by device helpers.  Take a look at
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2425
``src/network/helper/trace-helper.h`` if you want to follow the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2426
discussion while looking at real code.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2427
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2428
The class ``PcapHelperForDevice`` is a ``mixin`` provides the high
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2429
level functionality for using PCAP tracing in an |ns3| device.  Every
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2430
device must implement a single virtual method inherited from this
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2431
class.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2432
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2433
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2434
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2435
  virtual void EnablePcapInternal (std::string prefix, Ptr<NetDevice> nd, bool promiscuous, bool explicitFilename) = 0;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2436
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2437
The signature of this method reflects the device-centric view of the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2438
situation at this level.  All of the public methods inherited from
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2439
class ``PcapUserHelperForDevice`` reduce to calling this single
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2440
device-dependent implementation method.  For example, the lowest level
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2441
PCAP method,
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2442
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2443
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2444
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2445
  void EnablePcap (std::string prefix, Ptr<NetDevice> nd, bool promiscuous = false, bool explicitFilename = false);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2446
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2447
will call the device implementation of ``EnablePcapInternal``
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2448
directly.  All other public PCAP tracing methods build on this
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2449
implementation to provide additional user-level functionality.  What
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2450
this means to the user is that all device helpers in the system will
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2451
have all of the PCAP trace methods available; and these methods will
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2452
all work in the same way across devices if the device implements
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2453
``EnablePcapInternal`` correctly.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2454
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2455
Methods
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2456
#######
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2457
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2458
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2459
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2460
  void EnablePcap (std::string prefix, Ptr<NetDevice> nd, bool promiscuous = false, bool explicitFilename = false);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2461
  void EnablePcap (std::string prefix, std::string ndName, bool promiscuous = false, bool explicitFilename = false);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2462
  void EnablePcap (std::string prefix, NetDeviceContainer d, bool promiscuous = false);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2463
  void EnablePcap (std::string prefix, NodeContainer n, bool promiscuous = false);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2464
  void EnablePcap (std::string prefix, uint32_t nodeid, uint32_t deviceid, bool promiscuous = false);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2465
  void EnablePcapAll (std::string prefix, bool promiscuous = false);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2466
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2467
In each of the methods shown above, there is a default parameter
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2468
called ``promiscuous`` that defaults to ``false``.  This parameter
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2469
indicates that the trace should not be gathered in promiscuous mode.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2470
If you do want your traces to include all traffic seen by the device
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2471
(and if the device supports a promiscuous mode) simply add a true
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2472
parameter to any of the calls above.  For example,
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2473
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2474
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2475
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2476
  Ptr<NetDevice> nd;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2477
  ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2478
  helper.EnablePcap ("prefix", nd, true);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2479
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2480
will enable promiscuous mode captures on the ``NetDevice`` specified
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2481
by ``nd``.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2482
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2483
The first two methods also include a default parameter called
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2484
``explicitFilename`` that will be discussed below.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2485
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2486
You are encouraged to peruse the API Documentation for class
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2487
``PcapHelperForDevice`` to find the details of these methods; but to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2488
summarize ...
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2489
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2490
* You can enable PCAP tracing on a particular node/net-device pair by
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2491
  providing a ``Ptr<NetDevice>`` to an ``EnablePcap`` method.  The
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2492
  ``Ptr<Node>`` is implicit since the net device must belong to exactly
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2493
  one Node.  For example,
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2494
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2495
  ::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2496
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2497
    Ptr<NetDevice> nd;
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2498
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2499
    helper.EnablePcap ("prefix", nd);
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2500
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2501
* You can enable PCAP tracing on a particular node/net-device pair by
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2502
  providing a ``std::string`` representing an object name service string
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2503
  to an ``EnablePcap`` method.  The ``Ptr<NetDevice>`` is looked up from
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2504
  the name string.  Again, the ``<Node>`` is implicit since the named
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2505
  net device must belong to exactly one Node.  For example,
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2506
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2507
  ::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2508
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2509
    Names::Add ("server" ...);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2510
    Names::Add ("server/eth0" ...);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2511
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2512
    helper.EnablePcap ("prefix", "server/ath0");
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2513
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2514
* You can enable PCAP tracing on a collection of node/net-device pairs
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2515
  by providing a ``NetDeviceContainer``.  For each ``NetDevice`` in the
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2516
  container the type is checked.  For each device of the proper type
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2517
  (the same type as is managed by the device helper), tracing is
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2518
  enabled.  Again, the ``<Node>`` is implicit since the found net device
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2519
  must belong to exactly one Node.  For example,
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2520
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2521
  ::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2522
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2523
    NetDeviceContainer d = ...;
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2524
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2525
    helper.EnablePcap ("prefix", d);
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2526
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2527
* You can enable PCAP tracing on a collection of node/net-device pairs
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2528
  by providing a ``NodeContainer``.  For each Node in the
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2529
  ``NodeContainer`` its attached ``NetDevices`` are iterated.  For each
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2530
  ``NetDevice`` attached to each Node in the container, the type of that
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2531
  device is checked.  For each device of the proper type (the same type
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2532
  as is managed by the device helper), tracing is enabled.
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2533
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2534
  ::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2535
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2536
    NodeContainer n;
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2537
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2538
    helper.EnablePcap ("prefix", n);
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2539
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2540
* You can enable PCAP tracing on the basis of Node ID and device ID as
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2541
  well as with explicit ``Ptr``.  Each Node in the system has an
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2542
  integer Node ID and each device connected to a Node has an integer
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2543
  device ID.
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2544
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2545
  ::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2546
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2547
    helper.EnablePcap ("prefix", 21, 1);
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2548
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2549
* Finally, you can enable PCAP tracing for all devices in the system,
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2550
  with the same type as that managed by the device helper.
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2551
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2552
  ::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2553
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2554
    helper.EnablePcapAll ("prefix");
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2555
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2556
Filenames
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2557
#########
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2558
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2559
Implicit in the method descriptions above is the construction of a
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2560
complete filename by the implementation method.  By convention, PCAP
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2561
traces in the |ns3| system are of the form ``<prefix>-<node id>-<device
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2562
id>.pcap``
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2563
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2564
As previously mentioned, every Node in the system will have a
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2565
system-assigned Node id; and every device will have an interface index
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2566
(also called a device id) relative to its node.  By default, then, a
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2567
PCAP trace file created as a result of enabling tracing on the first
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2568
device of Node 21 using the prefix "prefix" would be
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2569
``prefix-21-1.pcap``.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2570
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2571
You can always use the |ns3| object name service to make this more
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2572
clear.  For example, if you use the object name service to assign the
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2573
name "server" to Node 21, the resulting PCAP trace file name will
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2574
automatically become, ``prefix-server-1.pcap`` and if you also assign
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2575
the name "eth0" to the device, your PCAP file name will automatically
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2576
pick this up and be called ``prefix-server-eth0.pcap``.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2577
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2578
Finally, two of the methods shown above,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2579
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2580
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2581
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2582
  void EnablePcap (std::string prefix, Ptr<NetDevice> nd, bool promiscuous = false, bool explicitFilename = false);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2583
  void EnablePcap (std::string prefix, std::string ndName, bool promiscuous = false, bool explicitFilename = false);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2584
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2585
have a default parameter called ``explicitFilename``.  When set to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2586
true, this parameter disables the automatic filename completion
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2587
mechanism and allows you to create an explicit filename.  This option
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2588
is only available in the methods which enable PCAP tracing on a single
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2589
device.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2590
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2591
For example, in order to arrange for a device helper to create a
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2592
single promiscuous PCAP capture file of a specific name
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2593
``my-pcap-file.pcap`` on a given device, one could::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2594
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2595
  Ptr<NetDevice> nd;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2596
  ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2597
  helper.EnablePcap ("my-pcap-file.pcap", nd, true, true);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2598
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2599
The first ``true`` parameter enables promiscuous mode traces and the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2600
second tells the helper to interpret the ``prefix`` parameter as a
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2601
complete filename.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2602
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2603
ASCII
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2604
~~~~~
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2605
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2606
The behavior of the ASCII trace helper ``mixin`` is substantially
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2607
similar to the PCAP version.  Take a look at
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2608
``src/network/helper/trace-helper.h`` if you want to follow the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2609
discussion while looking at real code.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2610
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2611
The class ``AsciiTraceHelperForDevice`` adds the high level
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2612
functionality for using ASCII tracing to a device helper class.  As in
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2613
the PCAP case, every device must implement a single virtual method
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2614
inherited from the ASCII trace ``mixin``.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2615
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2616
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2617
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2618
  virtual void EnableAsciiInternal (Ptr<OutputStreamWrapper> stream, 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2619
                                    std::string prefix, 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2620
                                    Ptr<NetDevice> nd,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2621
                                    bool explicitFilename) = 0;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2622
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2623
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2624
The signature of this method reflects the device-centric view of the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2625
situation at this level; and also the fact that the helper may be
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2626
writing to a shared output stream.  All of the public
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2627
ASCII-trace-related methods inherited from class
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2628
``AsciiTraceHelperForDevice`` reduce to calling this single device-
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2629
dependent implementation method.  For example, the lowest level ascii
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2630
trace methods,
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2631
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2632
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2633
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2634
  void EnableAscii (std::string prefix, Ptr<NetDevice> nd, bool explicitFilename = false);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2635
  void EnableAscii (Ptr<OutputStreamWrapper> stream, Ptr<NetDevice> nd);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2636
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2637
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2638
will call the device implementation of ``EnableAsciiInternal``
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2639
directly, providing either a valid prefix or stream.  All other public
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2640
ASCII tracing methods will build on these low-level functions to
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2641
provide additional user-level functionality.  What this means to the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2642
user is that all device helpers in the system will have all of the
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2643
ASCII trace methods available; and these methods will all work in the
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2644
same way across devices if the devices implement
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2645
``EnablAsciiInternal`` correctly.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2646
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2647
Methods
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2648
#######
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2649
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2650
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2651
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2652
  void EnableAscii (std::string prefix, Ptr<NetDevice> nd, bool explicitFilename = false);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2653
  void EnableAscii (Ptr<OutputStreamWrapper> stream, Ptr<NetDevice> nd);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2654
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2655
  void EnableAscii (std::string prefix, std::string ndName, bool explicitFilename = false);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2656
  void EnableAscii (Ptr<OutputStreamWrapper> stream, std::string ndName);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2657
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2658
  void EnableAscii (std::string prefix, NetDeviceContainer d);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2659
  void EnableAscii (Ptr<OutputStreamWrapper> stream, NetDeviceContainer d);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2660
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2661
  void EnableAscii (std::string prefix, NodeContainer n);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2662
  void EnableAscii (Ptr<OutputStreamWrapper> stream, NodeContainer n);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2663
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2664
  void EnableAsciiAll (std::string prefix);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2665
  void EnableAsciiAll (Ptr<OutputStreamWrapper> stream);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2666
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2667
  void EnableAscii (std::string prefix, uint32_t nodeid, uint32_t deviceid, bool explicitFilename);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2668
  void EnableAscii (Ptr<OutputStreamWrapper> stream, uint32_t nodeid, uint32_t deviceid);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2669
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2670
You are encouraged to peruse the API Documentation for class
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2671
``AsciiTraceHelperForDevice`` to find the details of these methods;
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2672
but to summarize ...
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2673
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2674
* There are twice as many methods available for ASCII tracing as
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2675
  there were for PCAP tracing.  This is because, in addition to the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2676
  PCAP-style model where traces from each unique node/device pair are
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2677
  written to a unique file, we support a model in which trace
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2678
  information for many node/device pairs is written to a common file.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2679
  This means that the <prefix>-<node>-<device> file name generation
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2680
  mechanism is replaced by a mechanism to refer to a common file; and
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2681
  the number of API methods is doubled to allow all combinations.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2682
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2683
* Just as in PCAP tracing, you can enable ASCII tracing on a
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2684
  particular (node, net-device) pair by providing a ``Ptr<NetDevice>``
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2685
  to an ``EnableAscii`` method.  The ``Ptr<Node>`` is implicit since
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2686
  the net device must belong to exactly one Node.  For example,
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2687
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2688
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2689
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2690
  Ptr<NetDevice> nd;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2691
  ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2692
  helper.EnableAscii ("prefix", nd);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2693
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2694
* The first four methods also include a default parameter called
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2695
  ``explicitFilename`` that operate similar to equivalent parameters
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2696
  in the PCAP case.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2697
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2698
  In this case, no trace contexts are written to the ASCII trace file
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2699
  since they would be redundant.  The system will pick the file name
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2700
  to be created using the same rules as described in the PCAP section,
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2701
  except that the file will have the suffix ``.tr`` instead of
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2702
  ``.pcap``.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2703
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2704
* If you want to enable ASCII tracing on more than one net device
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2705
  and have all traces sent to a single file, you can do that as well
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2706
  by using an object to refer to a single file.  We have already seen
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2707
  this in the "cwnd" example above::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2708
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2709
    Ptr<NetDevice> nd1;
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2710
    Ptr<NetDevice> nd2;
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2711
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2712
    Ptr<OutputStreamWrapper> stream = asciiTraceHelper.CreateFileStream ("trace-file-name.tr");
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2713
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2714
    helper.EnableAscii (stream, nd1);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2715
    helper.EnableAscii (stream, nd2);
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2716
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2717
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2718
  In this case, trace contexts *are* written to the ASCII trace file
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2719
  since they are required to disambiguate traces from the two devices.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2720
  Note that since the user is completely specifying the file name, the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2721
  string should include the ``,tr`` suffix for consistency.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2722
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2723
* You can enable ASCII tracing on a particular (node, net-device)
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2724
  pair by providing a ``std::string`` representing an object name
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2725
  service string to an ``EnablePcap`` method.  The ``Ptr<NetDevice>``
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2726
  is looked up from the name string.  Again, the ``<Node>`` is
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2727
  implicit since the named net device must belong to exactly one Node.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2728
  For example,
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2729
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2730
  ::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2731
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2732
    Names::Add ("client" ...);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2733
    Names::Add ("client/eth0" ...);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2734
    Names::Add ("server" ...);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2735
    Names::Add ("server/eth0" ...);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2736
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2737
    helper.EnableAscii ("prefix", "client/eth0");
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2738
    helper.EnableAscii ("prefix", "server/eth0");
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2739
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2740
    This would result in two files named ``prefix-client-eth0.tr`` and
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2741
    ``prefix-server-eth0.tr`` with traces for each device in the
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2742
    respective trace file.  Since all of the ``EnableAscii`` functions
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2743
    are overloaded to take a stream wrapper, you can use that form as
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2744
    well::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2745
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2746
    Names::Add ("client" ...);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2747
    Names::Add ("client/eth0" ...);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2748
    Names::Add ("server" ...);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2749
    Names::Add ("server/eth0" ...);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2750
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2751
    Ptr<OutputStreamWrapper> stream = asciiTraceHelper.CreateFileStream ("trace-file-name.tr");
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2752
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2753
    helper.EnableAscii (stream, "client/eth0");
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2754
    helper.EnableAscii (stream, "server/eth0");
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2755
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2756
  This would result in a single trace file called
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2757
  ``trace-file-name.tr`` that contains all of the trace events for
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2758
  both devices.  The events would be disambiguated by trace context
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2759
  strings.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2760
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2761
* You can enable ASCII tracing on a collection of (node, net-device)
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2762
  pairs by providing a ``NetDeviceContainer``.  For each ``NetDevice``
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2763
  in the container the type is checked.  For each device of the proper
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2764
  type (the same type as is managed by the device helper), tracing is
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2765
  enabled.  Again, the ``<Node>`` is implicit since the found net
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2766
  device must belong to exactly one Node.  For example,
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2767
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2768
  ::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2769
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2770
    NetDeviceContainer d = ...;
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2771
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2772
    helper.EnableAscii ("prefix", d);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2773
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2774
    This would result in a number of ASCII trace files being created,
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2775
    each of which follows the ``<prefix>-<node id>-<device id>.tr``
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2776
    convention.
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2777
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2778
  Combining all of the traces into a single file is accomplished
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2779
  similarly to the examples above::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2780
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2781
    NetDeviceContainer d = ...;
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2782
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2783
    Ptr<OutputStreamWrapper> stream = asciiTraceHelper.CreateFileStream ("trace-file-name.tr");
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2784
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2785
    helper.EnableAscii (stream, d);
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2786
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2787
* You can enable ASCII tracing on a collection of (node, net-device)
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2788
  pairs by providing a ``NodeContainer``.  For each Node in the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2789
  ``NodeContainer`` its attached ``NetDevices`` are iterated.  For
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2790
  each ``NetDevice`` attached to each Node in the container, the type
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2791
  of that device is checked.  For each device of the proper type (the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2792
  same type as is managed by the device helper), tracing is enabled.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2793
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2794
  ::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2795
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2796
    NodeContainer n;
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2797
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2798
    helper.EnableAscii ("prefix", n);
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2799
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2800
  This would result in a number of ASCII trace files being created,
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2801
  each of which follows the ``<prefix>-<node id>-<device id>.tr``
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2802
  convention.  Combining all of the traces into a single file is
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2803
  accomplished similarly to the examples above.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2804
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2805
* You can enable PCAP tracing on the basis of Node ID and device ID
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2806
  as well as with explicit ``Ptr``.  Each Node in the system has an
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2807
  integer Node ID and each device connected to a Node has an integer
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2808
  device ID.
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2809
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2810
  ::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2811
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2812
    helper.EnableAscii ("prefix", 21, 1);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2813
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2814
  Of course, the traces can be combined into a single file as shown
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2815
  above.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2816
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2817
* Finally, you can enable PCAP tracing for all devices in the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2818
  system, with the same type as that managed by the device helper.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2819
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2820
  ::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2821
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2822
    helper.EnableAsciiAll ("prefix");
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2823
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2824
  This would result in a number of ASCII trace files being created,
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2825
  one for every device in the system of the type managed by the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2826
  helper.  All of these files will follow the ``<prefix>-<node
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2827
  id>-<device id>.tr`` convention.  Combining all of the traces into a
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2828
  single file is accomplished similarly to the examples above.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2829
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2830
Filenames
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2831
#########
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2832
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2833
Implicit in the prefix-style method descriptions above is the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2834
construction of the complete filenames by the implementation method.
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2835
By convention, ASCII traces in the |ns3| system are of the form
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2836
``<prefix>-<node id>-<device id>.tr``
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2837
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2838
As previously mentioned, every Node in the system will have a
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2839
system-assigned Node id; and every device will have an interface index
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2840
(also called a device id) relative to its node.  By default, then, an
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2841
ASCII trace file created as a result of enabling tracing on the first
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2842
device of Node 21, using the prefix "prefix", would be
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2843
``prefix-21-1.tr``.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2844
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2845
You can always use the |ns3| object name service to make this more
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2846
clear.  For example, if you use the object name service to assign the
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2847
name "server" to Node 21, the resulting ASCII trace file name will
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2848
automatically become, ``prefix-server-1.tr`` and if you also assign the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2849
name "eth0" to the device, your ASCII trace file name will
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2850
automatically pick this up and be called ``prefix-server-eth0.tr``.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2851
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2852
Several of the methods have a default parameter called
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2853
``explicitFilename``.  When set to true, this parameter disables the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2854
automatic filename completion mechanism and allows you to create an
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2855
explicit filename.  This option is only available in the methods which
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2856
take a prefix and enable tracing on a single device.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2857
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2858
Protocol Helpers
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2859
++++++++++++++++
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2860
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2861
PCAP
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2862
~~~~
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2863
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2864
The goal of these ``mixins`` is to make it easy to add a consistent
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2865
PCAP trace facility to protocols.  We want all of the various flavors
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2866
of PCAP tracing to work the same across all protocols, so the methods
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2867
of these helpers are inherited by stack helpers.  Take a look at
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2868
``src/network/helper/trace-helper.h`` if you want to follow the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2869
discussion while looking at real code.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2870
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2871
In this section we will be illustrating the methods as applied to the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2872
protocol ``Ipv4``.  To specify traces in similar protocols, just
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2873
substitute the appropriate type.  For example, use a ``Ptr<Ipv6>``
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2874
instead of a ``Ptr<Ipv4>`` and call ``EnablePcapIpv6`` instead of
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2875
``EnablePcapIpv4``.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2876
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2877
The class ``PcapHelperForIpv4`` provides the high level functionality
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2878
for using PCAP tracing in the ``Ipv4`` protocol.  Each protocol helper
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2879
enabling these methods must implement a single virtual method
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2880
inherited from this class.  There will be a separate implementation
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2881
for ``Ipv6``, for example, but the only difference will be in the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2882
method names and signatures.  Different method names are required to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2883
disambiguate class ``Ipv4`` from ``Ipv6`` which are both derived from
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2884
class ``Object``, and methods that share the same signature.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2885
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2886
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2887
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2888
  virtual void EnablePcapIpv4Internal (std::string prefix, 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2889
                                       Ptr<Ipv4> ipv4, 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2890
                                       uint32_t interface,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2891
                                       bool explicitFilename) = 0;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2892
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2893
The signature of this method reflects the protocol and
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2894
interface-centric view of the situation at this level.  All of the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2895
public methods inherited from class ``PcapHelperForIpv4`` reduce to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2896
calling this single device-dependent implementation method.  For
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2897
example, the lowest level PCAP method,
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2898
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2899
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2900
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2901
  void EnablePcapIpv4 (std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface, bool explicitFilename = false);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2902
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2903
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2904
will call the device implementation of ``EnablePcapIpv4Internal``
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2905
directly.  All other public PCAP tracing methods build on this
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2906
implementation to provide additional user-level functionality.  What
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2907
this means to the user is that all protocol helpers in the system will
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2908
have all of the PCAP trace methods available; and these methods will
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2909
all work in the same way across protocols if the helper implements
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2910
``EnablePcapIpv4Internal`` correctly.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2911
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2912
Methods
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2913
#######
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2914
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2915
These methods are designed to be in one-to-one correspondence with the
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2916
Node- and ``NetDevice``- centric versions of the device versions.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2917
Instead of Node and ``NetDevice`` pair constraints, we use
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2918
protocol and interface constraints.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2919
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2920
Note that just like in the device version, there are six methods::
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2921
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2922
  void EnablePcapIpv4 (std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface, bool explicitFilename = false);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2923
  void EnablePcapIpv4 (std::string prefix, std::string ipv4Name, uint32_t interface, bool explicitFilename = false);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2924
  void EnablePcapIpv4 (std::string prefix, Ipv4InterfaceContainer c);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2925
  void EnablePcapIpv4 (std::string prefix, NodeContainer n);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2926
  void EnablePcapIpv4 (std::string prefix, uint32_t nodeid, uint32_t interface, bool explicitFilename);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2927
  void EnablePcapIpv4All (std::string prefix);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2928
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2929
You are encouraged to peruse the API Documentation for class
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2930
``PcapHelperForIpv4`` to find the details of these methods; but to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2931
summarize ...
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  2932
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2933
* You can enable PCAP tracing on a particular protocol/interface pair by
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2934
  providing a ``Ptr<Ipv4>`` and ``interface`` to an ``EnablePcap``
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2935
  method.  For example,
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2936
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2937
  ::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2938
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2939
    Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2940
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2941
    helper.EnablePcapIpv4 ("prefix", ipv4, 0);
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2942
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2943
* You can enable PCAP tracing on a particular node/net-device pair by
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2944
  providing a ``std::string`` representing an object name service string
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2945
  to an ``EnablePcap`` method.  The ``Ptr<Ipv4>`` is looked up from the
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2946
  name string.  For example,
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2947
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2948
  ::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2949
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2950
    Names::Add ("serverIPv4" ...);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2951
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2952
    helper.EnablePcapIpv4 ("prefix", "serverIpv4", 1);
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2953
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2954
* You can enable PCAP tracing on a collection of protocol/interface
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2955
  pairs by providing an ``Ipv4InterfaceContainer``.  For each ``Ipv4`` /
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2956
  interface pair in the container the protocol type is checked.  For
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2957
  each protocol of the proper type (the same type as is managed by the
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2958
  device helper), tracing is enabled for the corresponding interface.
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2959
  For example,
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2960
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2961
  ::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2962
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2963
    NodeContainer nodes;
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2964
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2965
    NetDeviceContainer devices = deviceHelper.Install (nodes);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2966
    ... 
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2967
    Ipv4AddressHelper ipv4;
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2968
    ipv4.SetBase ("10.1.1.0", "255.255.255.0");
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2969
    Ipv4InterfaceContainer interfaces = ipv4.Assign (devices);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2970
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2971
    helper.EnablePcapIpv4 ("prefix", interfaces);
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2972
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2973
* You can enable PCAP tracing on a collection of protocol/interface
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2974
  pairs by providing a ``NodeContainer``.  For each Node in the
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2975
  ``NodeContainer`` the appropriate protocol is found.  For each
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2976
  protocol, its interfaces are enumerated and tracing is enabled on the
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2977
  resulting pairs.  For example,
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2978
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2979
  ::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2980
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2981
    NodeContainer n;
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2982
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2983
    helper.EnablePcapIpv4 ("prefix", n);
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2984
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2985
* You can enable PCAP tracing on the basis of Node ID and interface as
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2986
  well.  In this case, the node-id is translated to a ``Ptr<Node>`` and
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2987
  the appropriate protocol is looked up in the node.  The resulting
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2988
  protocol and interface are used to specify the resulting trace source.
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2989
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2990
  ::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2991
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2992
    helper.EnablePcapIpv4 ("prefix", 21, 1);
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2993
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2994
* Finally, you can enable PCAP tracing for all interfaces in the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2995
  system, with associated protocol being the same type as that managed
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  2996
  by the device helper.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2997
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2998
  ::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  2999
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3000
    helper.EnablePcapIpv4All ("prefix");
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3001
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3002
Filenames
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3003
#########
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3004
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3005
Implicit in all of the method descriptions above is the construction
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3006
of the complete filenames by the implementation method.  By
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3007
convention, PCAP traces taken for devices in the |ns3| system are of
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3008
the form "<prefix>-<node id>-<device id>.pcap".  In the case of
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3009
protocol traces, there is a one-to-one correspondence between
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3010
protocols and ``Nodes``.  This is because protocol ``Objects`` are
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3011
aggregated to ``Node Objects``.  Since there is no global protocol id
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3012
in the system, we use the corresponding Node id in file naming.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3013
Therefore there is a possibility for file name collisions in
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3014
automatically chosen trace file names.  For this reason, the file name
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3015
convention is changed for protocol traces.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3016
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3017
As previously mentioned, every Node in the system will have a
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3018
system-assigned Node id.  Since there is a one-to-one correspondence
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3019
between protocol instances and Node instances we use the Node id.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3020
Each interface has an interface id relative to its protocol.  We use
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3021
the convention "<prefix>-n<node id>-i<interface id>.pcap" for trace
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3022
file naming in protocol helpers.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3023
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3024
Therefore, by default, a PCAP trace file created as a result of
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3025
enabling tracing on interface 1 of the Ipv4 protocol of Node 21 using
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3026
the prefix "prefix" would be "prefix-n21-i1.pcap".
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3027
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3028
You can always use the |ns3| object name service to make this more
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3029
clear.  For example, if you use the object name service to assign the
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3030
name "serverIpv4" to the Ptr<Ipv4> on Node 21, the resulting PCAP
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3031
trace file name will automatically become,
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3032
"prefix-nserverIpv4-i1.pcap".
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3033
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3034
Several of the methods have a default parameter called
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3035
``explicitFilename``.  When set to true, this parameter disables the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3036
automatic filename completion mechanism and allows you to create an
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3037
explicit filename.  This option is only available in the methods which
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3038
take a prefix and enable tracing on a single device.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3039
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3040
ASCII
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3041
~~~~~
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3042
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3043
The behavior of the ASCII trace helpers is substantially similar to
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3044
the PCAP case.  Take a look at ``src/network/helper/trace-helper.h``
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3045
if you want to follow the discussion while looking at real code.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3046
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3047
In this section we will be illustrating the methods as applied to the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3048
protocol ``Ipv4``.  To specify traces in similar protocols, just
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3049
substitute the appropriate type.  For example, use a ``Ptr<Ipv6>``
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3050
instead of a ``Ptr<Ipv4>`` and call ``EnableAsciiIpv6`` instead of
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3051
``EnableAsciiIpv4``.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3052
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3053
The class ``AsciiTraceHelperForIpv4`` adds the high level
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3054
functionality for using ASCII tracing to a protocol helper.  Each
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3055
protocol that enables these methods must implement a single virtual
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3056
method inherited from this class.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3057
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3058
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3059
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3060
  virtual void EnableAsciiIpv4Internal (Ptr<OutputStreamWrapper> stream, 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3061
                                        std::string prefix, 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3062
                                        Ptr<Ipv4> ipv4, 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3063
                                        uint32_t interface,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3064
                                        bool explicitFilename) = 0;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3065
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3066
The signature of this method reflects the protocol- and
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3067
interface-centric view of the situation at this level; and also the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3068
fact that the helper may be writing to a shared output stream.  All of
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3069
the public methods inherited from class
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3070
``PcapAndAsciiTraceHelperForIpv4`` reduce to calling this single
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3071
device- dependent implementation method.  For example, the lowest
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3072
level ASCII trace methods,
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3073
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3074
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3075
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3076
  void EnableAsciiIpv4 (std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface, bool explicitFilename = false);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3077
  void EnableAsciiIpv4 (Ptr<OutputStreamWrapper> stream, Ptr<Ipv4> ipv4, uint32_t interface);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3078
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3079
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3080
will call the device implementation of ``EnableAsciiIpv4Internal``
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3081
directly, providing either the prefix or the stream.  All other public
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3082
ASCII tracing methods will build on these low-level functions to
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3083
provide additional user-level functionality.  What this means to the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3084
user is that all device helpers in the system will have all of the
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3085
ASCII trace methods available; and these methods will all work in the
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3086
same way across protocols if the protocols implement
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3087
``EnablAsciiIpv4Internal`` correctly.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3088
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3089
Methods
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3090
#######
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3091
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3092
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3093
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3094
  void EnableAsciiIpv4 (std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface, bool explicitFilename = false);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3095
  void EnableAsciiIpv4 (Ptr<OutputStreamWrapper> stream, Ptr<Ipv4> ipv4, uint32_t interface);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3096
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3097
  void EnableAsciiIpv4 (std::string prefix, std::string ipv4Name, uint32_t interface, bool explicitFilename = false);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3098
  void EnableAsciiIpv4 (Ptr<OutputStreamWrapper> stream, std::string ipv4Name, uint32_t interface);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3099
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3100
  void EnableAsciiIpv4 (std::string prefix, Ipv4InterfaceContainer c);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3101
  void EnableAsciiIpv4 (Ptr<OutputStreamWrapper> stream, Ipv4InterfaceContainer c);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3102
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3103
  void EnableAsciiIpv4 (std::string prefix, NodeContainer n);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3104
  void EnableAsciiIpv4 (Ptr<OutputStreamWrapper> stream, NodeContainer n);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3105
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3106
  void EnableAsciiIpv4All (std::string prefix);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3107
  void EnableAsciiIpv4All (Ptr<OutputStreamWrapper> stream);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3108
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3109
  void EnableAsciiIpv4 (std::string prefix, uint32_t nodeid, uint32_t deviceid, bool explicitFilename);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3110
  void EnableAsciiIpv4 (Ptr<OutputStreamWrapper> stream, uint32_t nodeid, uint32_t interface);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3111
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3112
You are encouraged to peruse the API Documentation for class
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3113
``PcapAndAsciiHelperForIpv4`` to find the details of these methods;
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3114
but to summarize ...
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3115
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3116
* There are twice as many methods available for ASCII tracing as there
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3117
  were for PCAP tracing.  This is because, in addition to the PCAP-style
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3118
  model where traces from each unique protocol/interface pair are
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3119
  written to a unique file, we support a model in which trace
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3120
  information for many protocol/interface pairs is written to a common
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3121
  file.  This means that the <prefix>-n<node id>-<interface> file name
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3122
  generation mechanism is replaced by a mechanism to refer to a common
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3123
  file; and the number of API methods is doubled to allow all
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3124
  combinations.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3125
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3126
* Just as in PCAP tracing, you can enable ASCII tracing on a particular
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3127
  protocol/interface pair by providing a ``Ptr<Ipv4>`` and an
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3128
  ``interface`` to an ``EnableAscii`` method.  For example,
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3129
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3130
  ::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3131
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3132
    Ptr<Ipv4> ipv4;
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3133
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3134
    helper.EnableAsciiIpv4 ("prefix", ipv4, 1);
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3135
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3136
  In this case, no trace contexts are written to the ASCII trace file
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3137
  since they would be redundant.  The system will pick the file name to
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3138
  be created using the same rules as described in the PCAP section,
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3139
  except that the file will have the suffix ".tr" instead of ".pcap".
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3140
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3141
* If you want to enable ASCII tracing on more than one interface and
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3142
  have all traces sent to a single file, you can do that as well by
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3143
  using an object to refer to a single file.  We have already something
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3144
  similar to this in the "cwnd" example above::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3145
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3146
    Ptr<Ipv4> protocol1 = node1->GetObject<Ipv4> ();
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3147
    Ptr<Ipv4> protocol2 = node2->GetObject<Ipv4> ();
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3148
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3149
    Ptr<OutputStreamWrapper> stream = asciiTraceHelper.CreateFileStream ("trace-file-name.tr");
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3150
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3151
    helper.EnableAsciiIpv4 (stream, protocol1, 1);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3152
    helper.EnableAsciiIpv4 (stream, protocol2, 1);
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3153
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3154
  In this case, trace contexts are written to the ASCII trace file since
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3155
  they are required to disambiguate traces from the two interfaces.
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3156
  Note that since the user is completely specifying the file name, the
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3157
  string should include the ",tr" for consistency.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3158
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3159
* You can enable ASCII tracing on a particular protocol by providing a
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3160
  ``std::string`` representing an object name service string to an
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3161
  ``EnablePcap`` method.  The ``Ptr<Ipv4>`` is looked up from the name
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3162
  string.  The ``<Node>`` in the resulting filenames is implicit since
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3163
  there is a one-to-one correspondence between protocol instances and
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3164
  nodes, For example,
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3165
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3166
  ::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3167
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3168
    Names::Add ("node1Ipv4" ...);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3169
    Names::Add ("node2Ipv4" ...);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3170
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3171
    helper.EnableAsciiIpv4 ("prefix", "node1Ipv4", 1);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3172
    helper.EnableAsciiIpv4 ("prefix", "node2Ipv4", 1);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3173
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3174
  This would result in two files named "prefix-nnode1Ipv4-i1.tr" and
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3175
  "prefix-nnode2Ipv4-i1.tr" with traces for each interface in the
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3176
  respective trace file.  Since all of the EnableAscii functions are
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3177
  overloaded to take a stream wrapper, you can use that form as well::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3178
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3179
    Names::Add ("node1Ipv4" ...);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3180
    Names::Add ("node2Ipv4" ...);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3181
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3182
    Ptr<OutputStreamWrapper> stream = asciiTraceHelper.CreateFileStream ("trace-file-name.tr");
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3183
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3184
    helper.EnableAsciiIpv4 (stream, "node1Ipv4", 1);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3185
    helper.EnableAsciiIpv4 (stream, "node2Ipv4", 1);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3186
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3187
  This would result in a single trace file called "trace-file-name.tr"
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3188
  that contains all of the trace events for both interfaces.  The events
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3189
  would be disambiguated by trace context strings.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3190
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3191
* You can enable ASCII tracing on a collection of protocol/interface
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3192
  pairs by providing an ``Ipv4InterfaceContainer``.  For each protocol
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3193
  of the proper type (the same type as is managed by the device helper),
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3194
  tracing is enabled for the corresponding interface.  Again, the
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3195
  ``<Node>`` is implicit since there is a one-to-one correspondence
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3196
  between each protocol and its node.  For example,
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3197
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3198
  ::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3199
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3200
    NodeContainer nodes;
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3201
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3202
    NetDeviceContainer devices = deviceHelper.Install (nodes);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3203
    ... 
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3204
    Ipv4AddressHelper ipv4;
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3205
    ipv4.SetBase ("10.1.1.0", "255.255.255.0");
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3206
    Ipv4InterfaceContainer interfaces = ipv4.Assign (devices);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3207
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3208
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3209
    helper.EnableAsciiIpv4 ("prefix", interfaces);
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3210
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3211
  This would result in a number of ASCII trace files being created, each
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3212
  of which follows the <prefix>-n<node id>-i<interface>.tr convention.
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3213
  Combining all of the traces into a single file is accomplished
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3214
  similarly to the examples above::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3215
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3216
    NodeContainer nodes;
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3217
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3218
    NetDeviceContainer devices = deviceHelper.Install (nodes);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3219
    ... 
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3220
    Ipv4AddressHelper ipv4;
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3221
    ipv4.SetBase ("10.1.1.0", "255.255.255.0");
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3222
    Ipv4InterfaceContainer interfaces = ipv4.Assign (devices);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3223
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3224
    Ptr<OutputStreamWrapper> stream = asciiTraceHelper.CreateFileStream ("trace-file-name.tr");
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3225
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3226
    helper.EnableAsciiIpv4 (stream, interfaces);
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3227
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3228
* You can enable ASCII tracing on a collection of protocol/interface
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3229
  pairs by providing a ``NodeContainer``.  For each Node in the
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3230
  ``NodeContainer`` the appropriate protocol is found.  For each
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3231
  protocol, its interfaces are enumerated and tracing is enabled on the
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3232
  resulting pairs.  For example,
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3233
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3234
  ::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3235
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3236
    NodeContainer n;
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3237
    ...
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3238
    helper.EnableAsciiIpv4 ("prefix", n);
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3239
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3240
  This would result in a number of ASCII trace files being created,
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3241
  each of which follows the <prefix>-<node id>-<device id>.tr
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3242
  convention.  Combining all of the traces into a single file is
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3243
  accomplished similarly to the examples above.
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3244
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3245
* You can enable PCAP tracing on the basis of Node ID and device ID as
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3246
  well.  In this case, the node-id is translated to a ``Ptr<Node>`` and
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3247
  the appropriate protocol is looked up in the node.  The resulting
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3248
  protocol and interface are used to specify the resulting trace source.
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3249
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3250
  ::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3251
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3252
    helper.EnableAsciiIpv4 ("prefix", 21, 1);
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3253
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3254
  Of course, the traces can be combined into a single file as shown
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3255
  above.
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3256
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3257
* Finally, you can enable ASCII tracing for all interfaces in the
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3258
  system, with associated protocol being the same type as that managed
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3259
  by the device helper.
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3260
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3261
  ::
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3262
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3263
    helper.EnableAsciiIpv4All ("prefix");
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3264
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3265
  This would result in a number of ASCII trace files being created, one
11089
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3266
  for every interface in the system related to a protocol of the type
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3267
  managed by the helper.  All of these files will follow the
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3268
  <prefix>-n<node id>-i<interface.tr convention.  Combining all of the
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3269
  traces into a single file is accomplished similarly to the examples
3cdc5e3127c1 New TracedCallback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11088
diff changeset
  3270
  above.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3271
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3272
Filenames
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3273
#########
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3274
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3275
Implicit in the prefix-style method descriptions above is the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3276
construction of the complete filenames by the implementation method.
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3277
By convention, ASCII traces in the |ns3| system are of the form
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3278
"<prefix>-<node id>-<device id>.tr"
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3279
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3280
As previously mentioned, every Node in the system will have a
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3281
system-assigned Node id.  Since there is a one-to-one correspondence
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3282
between protocols and nodes we use to node-id to identify the protocol
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3283
identity.  Every interface on a given protocol will have an interface
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3284
index (also called simply an interface) relative to its protocol.  By
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3285
default, then, an ASCII trace file created as a result of enabling
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3286
tracing on the first device of Node 21, using the prefix "prefix",
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3287
would be "prefix-n21-i1.tr".  Use the prefix to disambiguate multiple
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3288
protocols per node.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3289
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3290
You can always use the |ns3| object name service to make this more
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3291
clear.  For example, if you use the object name service to assign the
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3292
name "serverIpv4" to the protocol on Node 21, and also specify
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3293
interface one, the resulting ASCII trace file name will automatically
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3294
become, "prefix-nserverIpv4-1.tr".
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3295
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3296
Several of the methods have a default parameter called
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3297
``explicitFilename``.  When set to true, this parameter disables the
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3298
automatic filename completion mechanism and allows you to create an
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3299
explicit filename.  This option is only available in the methods which
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3300
take a prefix and enable tracing on a single device.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3301
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3302
Summary
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3303
*******
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  3304
10976
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3305
|ns3| includes an extremely rich environment allowing users at several
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3306
levels to customize the kinds of information that can be extracted
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3307
from simulations.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3308
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3309
There are high-level helper functions that allow users to simply
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3310
control the collection of pre-defined outputs to a fine granularity.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3311
There are mid-level helper functions to allow more sophisticated users
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3312
to customize how information is extracted and saved; and there are
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3313
low-level core functions to allow expert users to alter the system to
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3314
present new and previously unexported information in a way that will
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3315
be immediately accessible to users at higher levels.
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3316
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3317
This is a very comprehensive system, and we realize that it is a lot
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3318
to digest, especially for new users or those not intimately familiar
d6951023f908 Reflow tutorial page
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10182
diff changeset
  3319
with C++ and its idioms.  We do consider the tracing system a very
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3320
important part of |ns3| and so recommend becoming as familiar as
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3321
possible with it.  It is probably the case that understanding the rest
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3322
of the |ns3| system will be quite simple once you have mastered the
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11052
diff changeset
  3323
tracing system