doc/tutorial/source/tweaking.rst
author Tom Henderson <tomh@tomh.org>
Sat, 16 Jan 2016 08:14:40 -0800
changeset 11683 9142266fbb25
parent 11248 88468adb47b5
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: 9104
diff changeset
     2
.. highlight:: cpp
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     3
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     4
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
Tweaking
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     6
--------
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     7
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
     8
.. _UsingLogging:
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
     9
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    10
Using the Logging Module
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    11
************************
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    12
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    13
We have already taken a brief look at the |ns3| logging module while
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
going over the ``first.cc`` script.  We will now take a closer look and 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    15
see what kind of use-cases the logging subsystem was designed to cover.
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
Logging Overview
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
++++++++++++++++
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    19
Many large systems support some kind of message logging facility, and 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
|ns3| is not an exception.  In some cases, only error messages are 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    21
logged to the "operator console" (which is typically ``stderr`` in Unix-
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    22
based systems).  In other systems, warning messages may be output as well as 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    23
more detailed informational messages.  In some cases, logging facilities are 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    24
used to output debug messages which can quickly turn the output into a blur.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    25
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    26
|ns3| takes the view that all of these verbosity levels are useful 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    27
and we provide a selectable, multi-level approach to message logging.  Logging
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    28
can be disabled completely, enabled on a component-by-component basis, or
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    29
enabled globally; and it provides selectable verbosity levels.  The 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    30
|ns3| log module provides a straightforward, relatively easy to use
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    31
way to get useful information out of your simulation.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    32
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
You should understand that we do provide a general purpose mechanism --- 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    34
tracing --- to get data out of your models which should be preferred for 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    35
simulation output (see the tutorial section Using the Tracing System for
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    36
more details on our tracing system).  Logging should be preferred for 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    37
debugging information, warnings, error messages, or any time you want to 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    38
easily get a quick message out of your scripts or models.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    39
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    40
There are currently seven levels of log messages of increasing verbosity
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    41
defined in the system.  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    42
9104
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
    43
* LOG_ERROR --- Log error messages (associated macro: NS_LOG_ERROR);
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
    44
* LOG_WARN --- Log warning messages (associated macro: NS_LOG_WARN);
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
    45
* LOG_DEBUG --- Log relatively rare, ad-hoc debugging messages
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
    46
  (associated macro: NS_LOG_DEBUG);
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
    47
* LOG_INFO --- Log informational messages about program progress
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
    48
  (associated macro: NS_LOG_INFO);
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
    49
* LOG_FUNCTION --- Log a message describing each function called
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
    50
  (two associated macros: NS_LOG_FUNCTION, used for member functions,
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
    51
  and NS_LOG_FUNCTION_NOARGS, used for static functions);
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
    52
* LOG_LOGIC -- Log messages describing logical flow within a function
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
    53
  (associated macro: NS_LOG_LOGIC);
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
    54
* LOG_ALL --- Log everything mentioned above (no associated macro).
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    55
9104
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
    56
For each LOG_TYPE there is also LOG_LEVEL_TYPE that, if used, enables
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
    57
logging of all the levels above it in addition to it's level.  (As a
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
    58
consequence of this, LOG_ERROR and LOG_LEVEL_ERROR and also LOG_ALL
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
    59
and LOG_LEVEL_ALL are functionally equivalent.)  For example,
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
    60
enabling LOG_INFO will only enable messages provided by NS_LOG_INFO macro,
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
    61
while enabling LOG_LEVEL_INFO will also enable messages provided by
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
    62
NS_LOG_DEBUG, NS_LOG_WARN and NS_LOG_ERROR macros.  
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
    63
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
    64
We also provide an unconditional logging macro that is always displayed,
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    65
irrespective of logging levels or component selection.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    66
9104
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
    67
* NS_LOG_UNCOND -- Log the associated message unconditionally (no associated
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
    68
  log level).
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    69
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    70
Each level can be requested singly or cumulatively; and logging can be set 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    71
up using a shell environment variable (NS_LOG) or by logging system function 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    72
call.  As was seen earlier in the tutorial, the logging system has Doxygen 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    73
documentation and now would be a good time to peruse the Logging Module 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    74
documentation if you have not done so.
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
Now that you have read the documentation in great detail, let's use some of
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    77
that knowledge to get some interesting information out of the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    78
``scratch/myfirst.cc`` example script you have already built.
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
Enabling Logging
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    81
++++++++++++++++
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    82
Let's use the NS_LOG environment variable to turn on some more logging, but
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    83
first, just to get our bearings, go ahead and run the last script just as you 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    84
did previously,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    85
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
    86
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    87
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
    88
  $ ./waf --run scratch/myfirst
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    89
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    90
You should see the now familiar output of the first |ns3| example
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    91
program
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    92
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
    93
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    94
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
    95
  $ Waf: Entering directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    96
  Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    97
  'build' finished successfully (0.413s)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    98
  Sent 1024 bytes to 10.1.1.2
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    99
  Received 1024 bytes from 10.1.1.1
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   100
  Received 1024 bytes from 10.1.1.2
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   101
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   102
It turns out that the "Sent" and "Received" messages you see above are
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   103
actually logging messages from the ``UdpEchoClientApplication`` and 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   104
``UdpEchoServerApplication``.  We can ask the client application, for 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   105
example, to print more information by setting its logging level via the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   106
NS_LOG environment variable.  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   107
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   108
I am going to assume from here on that you are using an sh-like shell that uses 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   109
the"VARIABLE=value" syntax.  If you are using a csh-like shell, then you 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   110
will have to convert my examples to the "setenv VARIABLE value" syntax 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   111
required by those shells.
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
Right now, the UDP echo client application is responding to the following line
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   114
of code in ``scratch/myfirst.cc``,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   115
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
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   118
  LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   119
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   120
This line of code enables the ``LOG_LEVEL_INFO`` level of logging.  When 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   121
we pass a logging level flag, we are actually enabling the given level and
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   122
all lower levels.  In this case, we have enabled ``NS_LOG_INFO``,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   123
``NS_LOG_DEBUG``, ``NS_LOG_WARN`` and ``NS_LOG_ERROR``.  We can
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   124
increase the logging level and get more information without changing the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   125
script and recompiling by setting the NS_LOG environment variable like this:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   126
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   127
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   128
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   129
  $ export NS_LOG=UdpEchoClientApplication=level_all
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   130
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   131
This sets the shell environment variable ``NS_LOG`` to the string,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   132
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   133
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   134
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   135
  UdpEchoClientApplication=level_all
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   136
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   137
The left hand side of the assignment is the name of the logging component we
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   138
want to set, and the right hand side is the flag we want to use.  In this case,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   139
we are going to turn on all of the debugging levels for the application.  If
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   140
you run the script with NS_LOG set this way, the |ns3| logging 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   141
system will pick up the change and you should see the following output:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   142
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   143
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   144
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   145
  Waf: Entering directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   146
  Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   147
  'build' finished successfully (0.404s)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   148
  UdpEchoClientApplication:UdpEchoClient()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   149
  UdpEchoClientApplication:SetDataSize(1024)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   150
  UdpEchoClientApplication:StartApplication()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   151
  UdpEchoClientApplication:ScheduleTransmit()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   152
  UdpEchoClientApplication:Send()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   153
  Sent 1024 bytes to 10.1.1.2
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   154
  Received 1024 bytes from 10.1.1.1
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   155
  UdpEchoClientApplication:HandleRead(0x6241e0, 0x624a20)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   156
  Received 1024 bytes from 10.1.1.2
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   157
  UdpEchoClientApplication:StopApplication()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   158
  UdpEchoClientApplication:DoDispose()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   159
  UdpEchoClientApplication:~UdpEchoClient()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   160
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   161
The additional debug information provided by the application is from
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   162
the NS_LOG_FUNCTION level.  This shows every time a function in the application
9104
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
   163
is called during script execution.  Generally, use of (at least)
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
   164
NS_LOG_FUNCTION(this) in member functions is preferred. Use
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
   165
NS_LOG_FUNCTION_NOARGS() only in static functions.  Note, however, that there
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
   166
are no requirements in the |ns3| system that models must support any particular
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
   167
logging  functionality.  The decision regarding how much information is logged
5de0d2c78514 Improve logging part in tutorial, and make clear distinction between logging level and logging macro.
Vedran Miletić <rivanvx@gmail.com>
parents: 7140
diff changeset
   168
is left to the individual model developer.  In the case of the echo
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   169
applications, a good deal of log output is available.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   170
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   171
You can now see a log of the function calls that were made to the application.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   172
If you look closely you will notice a single colon between the string 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   173
``UdpEchoClientApplication`` and the method name where you might have 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   174
expected a C++ scope operator (``::``).  This is intentional.  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   175
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   176
The name is not actually a class name, it is a logging component name.  When 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   177
there is a one-to-one correspondence between a source file and a class, this 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   178
will generally be the class name but you should understand that it is not 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   179
actually a class name, and there is a single colon there instead of a double
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   180
colon to remind you in a relatively subtle way to conceptually separate the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   181
logging component name from the class name.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   182
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   183
It turns out that in some cases, it can be hard to determine which method
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   184
actually generates a log message.  If you look in the text above, you may
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   185
wonder where the string "``Received 1024 bytes from 10.1.1.2``" comes
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   186
from.  You can resolve this by OR'ing the ``prefix_func`` level into the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   187
``NS_LOG`` environment variable.  Try doing the following,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   188
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   189
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   190
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   191
  $ export 'NS_LOG=UdpEchoClientApplication=level_all|prefix_func'
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   192
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   193
Note that the quotes are required since the vertical bar we use to indicate an
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   194
OR operation is also a Unix pipe connector.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   195
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   196
Now, if you run the script you will see that the logging system makes sure 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   197
that every message from the given log component is prefixed with the component
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   198
name.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   199
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   200
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   201
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   202
  Waf: Entering directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   203
  Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   204
  'build' finished successfully (0.417s)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   205
  UdpEchoClientApplication:UdpEchoClient()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   206
  UdpEchoClientApplication:SetDataSize(1024)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   207
  UdpEchoClientApplication:StartApplication()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   208
  UdpEchoClientApplication:ScheduleTransmit()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   209
  UdpEchoClientApplication:Send()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   210
  UdpEchoClientApplication:Send(): Sent 1024 bytes to 10.1.1.2
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   211
  Received 1024 bytes from 10.1.1.1
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   212
  UdpEchoClientApplication:HandleRead(0x6241e0, 0x624a20)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   213
  UdpEchoClientApplication:HandleRead(): Received 1024 bytes from 10.1.1.2
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   214
  UdpEchoClientApplication:StopApplication()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   215
  UdpEchoClientApplication:DoDispose()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   216
  UdpEchoClientApplication:~UdpEchoClient()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   217
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   218
You can now see all of the messages coming from the UDP echo client application
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   219
are identified as such.  The message "Received 1024 bytes from 10.1.1.2" is
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   220
now clearly identified as coming from the echo client application.  The 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   221
remaining message must be coming from the UDP echo server application.  We 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   222
can enable that component by entering a colon separated list of components in
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   223
the NS_LOG environment variable.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   224
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   225
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   226
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   227
  $ export 'NS_LOG=UdpEchoClientApplication=level_all|prefix_func:
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   228
                 UdpEchoServerApplication=level_all|prefix_func'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   229
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   230
Warning:  You will need to remove the newline after the ``:`` in the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   231
example text above which is only there for document formatting purposes.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   232
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   233
Now, if you run the script you will see all of the log messages from both the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   234
echo client and server applications.  You may see that this can be very useful
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   235
in debugging problems.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   236
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   237
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   238
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   239
  Waf: Entering directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   240
  Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   241
  'build' finished successfully (0.406s)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   242
  UdpEchoServerApplication:UdpEchoServer()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   243
  UdpEchoClientApplication:UdpEchoClient()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   244
  UdpEchoClientApplication:SetDataSize(1024)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   245
  UdpEchoServerApplication:StartApplication()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   246
  UdpEchoClientApplication:StartApplication()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   247
  UdpEchoClientApplication:ScheduleTransmit()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   248
  UdpEchoClientApplication:Send()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   249
  UdpEchoClientApplication:Send(): Sent 1024 bytes to 10.1.1.2
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   250
  UdpEchoServerApplication:HandleRead(): Received 1024 bytes from 10.1.1.1
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   251
  UdpEchoServerApplication:HandleRead(): Echoing packet
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   252
  UdpEchoClientApplication:HandleRead(0x624920, 0x625160)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   253
  UdpEchoClientApplication:HandleRead(): Received 1024 bytes from 10.1.1.2
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   254
  UdpEchoServerApplication:StopApplication()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   255
  UdpEchoClientApplication:StopApplication()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   256
  UdpEchoClientApplication:DoDispose()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   257
  UdpEchoServerApplication:DoDispose()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   258
  UdpEchoClientApplication:~UdpEchoClient()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   259
  UdpEchoServerApplication:~UdpEchoServer()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   260
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   261
It is also sometimes useful to be able to see the simulation time at which a
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   262
log message is generated.  You can do this by ORing in the prefix_time bit.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   263
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   264
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   265
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   266
  $ export 'NS_LOG=UdpEchoClientApplication=level_all|prefix_func|prefix_time:
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   267
                 UdpEchoServerApplication=level_all|prefix_func|prefix_time'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   268
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   269
Again, you will have to remove the newline above.  If you run the script now,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   270
you should see the following output:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   271
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   272
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   273
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   274
  Waf: Entering directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   275
  Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   276
  'build' finished successfully (0.418s)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   277
  0s UdpEchoServerApplication:UdpEchoServer()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   278
  0s UdpEchoClientApplication:UdpEchoClient()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   279
  0s UdpEchoClientApplication:SetDataSize(1024)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   280
  1s UdpEchoServerApplication:StartApplication()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   281
  2s UdpEchoClientApplication:StartApplication()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   282
  2s UdpEchoClientApplication:ScheduleTransmit()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   283
  2s UdpEchoClientApplication:Send()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   284
  2s UdpEchoClientApplication:Send(): Sent 1024 bytes to 10.1.1.2
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   285
  2.00369s UdpEchoServerApplication:HandleRead(): Received 1024 bytes from 10.1.1.1
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   286
  2.00369s UdpEchoServerApplication:HandleRead(): Echoing packet
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   287
  2.00737s UdpEchoClientApplication:HandleRead(0x624290, 0x624ad0)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   288
  2.00737s UdpEchoClientApplication:HandleRead(): Received 1024 bytes from 10.1.1.2
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   289
  10s UdpEchoServerApplication:StopApplication()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   290
  10s UdpEchoClientApplication:StopApplication()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   291
  UdpEchoClientApplication:DoDispose()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   292
  UdpEchoServerApplication:DoDispose()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   293
  UdpEchoClientApplication:~UdpEchoClient()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   294
  UdpEchoServerApplication:~UdpEchoServer()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   295
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   296
You can see that the constructor for the UdpEchoServer was called at a 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   297
simulation time of 0 seconds.  This is actually happening before the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   298
simulation starts, but the time is displayed as zero seconds.  The same is true
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   299
for the UdpEchoClient constructor message.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   300
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   301
Recall that the ``scratch/first.cc`` script started the echo server 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   302
application at one second into the simulation.  You can now see that the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   303
``StartApplication`` method of the server is, in fact, called at one second.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   304
You can also see that the echo client application is started at a simulation 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   305
time of two seconds as we requested in the script.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   306
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   307
You can now follow the progress of the simulation from the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   308
``ScheduleTransmit`` call in the client that calls ``Send`` to the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   309
``HandleRead`` callback in the echo server application.  Note that the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   310
elapsed time for the packet to be sent across the point-to-point link is 3.69
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   311
milliseconds.  You see the echo server logging a message telling you that it
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   312
has echoed the packet and then, after another channel delay, you see the echo
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   313
client receive the echoed packet in its ``HandleRead`` method.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   314
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   315
There is a lot that is happening under the covers in this simulation that you
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   316
are not seeing as well.  You can very easily follow the entire process by
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   317
turning on all of the logging components in the system.  Try setting the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   318
``NS_LOG`` variable to the following,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   319
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   320
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   321
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   322
  $ export 'NS_LOG=*=level_all|prefix_func|prefix_time'
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   323
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   324
The asterisk above is the logging component wildcard.  This will turn on all 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   325
of the logging in all of the components used in the simulation.  I won't 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   326
reproduce the output here (as of this writing it produces 1265 lines of output
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   327
for the single packet echo) but you can redirect this information into a file 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   328
and look through it with your favorite editor if you like,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   329
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   330
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   331
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   332
  $ ./waf --run scratch/myfirst > log.out 2>&1
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   333
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   334
I personally use this extremely verbose version of logging when I am presented 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   335
with a problem and I have no idea where things are going wrong.  I can follow the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   336
progress of the code quite easily without having to set breakpoints and step 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   337
through code in a debugger.  I can just edit up the output in my favorite editor
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   338
and search around for things I expect, and see things happening that I don't 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   339
expect.  When I have a general idea about what is going wrong, I transition into
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   340
a debugger for a fine-grained examination of the problem.  This kind of output 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   341
can be especially useful when your script does something completely unexpected.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   342
If you are stepping using a debugger you may miss an unexpected excursion 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   343
completely.  Logging the excursion makes it quickly visible.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   344
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   345
Adding Logging to your Code
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   346
+++++++++++++++++++++++++++
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   347
You can add new logging to your simulations by making calls to the log 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   348
component via several macros.  Let's do so in the ``myfirst.cc`` script we
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   349
have in the ``scratch`` directory.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   350
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   351
Recall that we have defined a logging component in that script:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   352
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   353
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   354
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   355
  NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   356
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   357
You now know that you can enable all of the logging for this component by
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   358
setting the ``NS_LOG`` environment variable to the various levels.  Let's
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   359
go ahead and add some logging to the script.  The macro used to add an 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   360
informational level log message is ``NS_LOG_INFO``.  Go ahead and add one 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   361
(just before we start creating the nodes) that tells you that the script is 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   362
"Creating Topology."  This is done as in this code snippet,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   363
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   364
Open ``scratch/myfirst.cc`` in your favorite editor and add the line,
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
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   367
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   368
  NS_LOG_INFO ("Creating Topology");
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   369
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   370
right before the lines,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   371
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   372
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   373
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   374
  NodeContainer nodes;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   375
  nodes.Create (2);
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
Now build the script using waf and clear the ``NS_LOG`` variable to turn 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   378
off the torrent of logging we previously enabled:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   379
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   380
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   381
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   382
  $ ./waf
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   383
  $ export NS_LOG=
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   384
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   385
Now, if you run the script, 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   386
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   387
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   388
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   389
  $ ./waf --run scratch/myfirst
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   390
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   391
you will ``not`` see your new message since its associated logging 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   392
component (``FirstScriptExample``) has not been enabled.  In order to see your
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   393
message you will have to enable the ``FirstScriptExample`` logging component
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   394
with a level greater than or equal to ``NS_LOG_INFO``.  If you just want to 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   395
see this particular level of logging, you can enable it by,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   396
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   397
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   398
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   399
  $ export NS_LOG=FirstScriptExample=info
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   400
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   401
If you now run the script you will see your new "Creating Topology" log
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   402
message,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   403
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   404
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   405
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   406
  Waf: Entering directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   407
  Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   408
  'build' finished successfully (0.404s)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   409
  Creating Topology
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   410
  Sent 1024 bytes to 10.1.1.2
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   411
  Received 1024 bytes from 10.1.1.1
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   412
  Received 1024 bytes from 10.1.1.2
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   413
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   414
Using Command Line Arguments
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   415
****************************
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   416
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   417
.. _Attribute:
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   418
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   419
Overriding Default Attributes
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   420
+++++++++++++++++++++++++++++
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   421
Another way you can change how |ns3| scripts behave without editing
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   422
and building is via *command line arguments.*  We provide a mechanism to 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   423
parse command line arguments and automatically set local and global variables
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   424
based on those arguments.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   425
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   426
The first step in using the command line argument system is to declare the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   427
command line parser.  This is done quite simply (in your main program) as
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   428
in the following code,
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
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   431
7140
d203296efb63 Fix an example dependency problem and fix some paths in the documentation
Mitch Watrous <watrous@u.washington.edu>
parents: 6754
diff changeset
   432
  int
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   433
  main (int argc, char *argv[])
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
    ...  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   436
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   437
    CommandLine cmd;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   438
    cmd.Parse (argc, argv);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   439
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   440
    ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   441
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   442
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   443
This simple two line snippet is actually very useful by itself.  It opens the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   444
door to the |ns3| global variable and ``Attribute`` systems.  Go 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   445
ahead and add that two lines of code to the ``scratch/myfirst.cc`` script at
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   446
the start of ``main``.  Go ahead and build the script and run it, but ask 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   447
the script for help in the following way,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   448
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   449
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   450
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   451
  $ ./waf --run "scratch/myfirst --PrintHelp"
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   452
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   453
This will ask Waf to run the ``scratch/myfirst`` script and pass the command
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   454
line argument ``--PrintHelp`` to the script.  The quotes are required to 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   455
sort out which program gets which argument.  The command line parser will
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   456
now see the ``--PrintHelp`` argument and respond with,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   457
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   458
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   459
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   460
  Waf: Entering directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   461
  Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   462
  'build' finished successfully (0.413s)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   463
  TcpL4Protocol:TcpStateMachine()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   464
  CommandLine:HandleArgument(): Handle arg name=PrintHelp value=
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   465
  --PrintHelp: Print this help message.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   466
  --PrintGroups: Print the list of groups.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   467
  --PrintTypeIds: Print all TypeIds.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   468
  --PrintGroup=[group]: Print all TypeIds of group.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   469
  --PrintAttributes=[typeid]: Print all attributes of typeid.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   470
  --PrintGlobals: Print the list of globals.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   471
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   472
Let's focus on the ``--PrintAttributes`` option.  We have already hinted
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   473
at the |ns3| ``Attribute`` system while walking through the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   474
``first.cc`` script.  We looked at the following lines of code,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   475
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   476
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   477
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   478
    PointToPointHelper pointToPoint;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   479
    pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   480
    pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   481
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   482
and mentioned that ``DataRate`` was actually an ``Attribute`` of the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   483
``PointToPointNetDevice``.  Let's use the command line argument parser
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   484
to take a look at the ``Attributes`` of the PointToPointNetDevice.  The help
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   485
listing says that we should provide a ``TypeId``.  This corresponds to the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   486
class name of the class to which the ``Attributes`` belong.  In this case it
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   487
will be ``ns3::PointToPointNetDevice``.  Let's go ahead and type in,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   488
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   489
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   490
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   491
  $ ./waf --run "scratch/myfirst --PrintAttributes=ns3::PointToPointNetDevice"
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   492
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   493
The system will print out all of the ``Attributes`` of this kind of net device.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   494
Among the ``Attributes`` you will see listed is,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   495
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   496
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   497
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   498
  --ns3::PointToPointNetDevice::DataRate=[32768bps]:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   499
    The default data rate for point to point links
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   500
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   501
This is the default value that will be used when a ``PointToPointNetDevice``
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   502
is created in the system.  We overrode this default with the ``Attribute``
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   503
setting in the ``PointToPointHelper`` above.  Let's use the default values 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   504
for the point-to-point devices and channels by deleting the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   505
``SetDeviceAttribute`` call and the ``SetChannelAttribute`` call from 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   506
the ``myfirst.cc`` we have in the scratch directory.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   507
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   508
Your script should now just declare the ``PointToPointHelper`` and not do 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   509
any ``set`` operations as in the following example,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   510
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   511
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   512
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   513
  ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   514
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   515
  NodeContainer nodes;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   516
  nodes.Create (2);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   517
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   518
  PointToPointHelper pointToPoint;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   519
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   520
  NetDeviceContainer devices;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   521
  devices = pointToPoint.Install (nodes);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   522
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   523
  ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   524
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   525
Go ahead and build the new script with Waf (``./waf``) and let's go back 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   526
and enable some logging from the UDP echo server application and turn on the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   527
time prefix.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   528
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   529
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   530
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   531
  $ export 'NS_LOG=UdpEchoServerApplication=level_all|prefix_time'
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   532
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   533
If you run the script, you should now see the following output,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   534
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   535
.. sourcecode:: bash
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
  Waf: Entering directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   538
  Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   539
  'build' finished successfully (0.405s)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   540
  0s UdpEchoServerApplication:UdpEchoServer()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   541
  1s UdpEchoServerApplication:StartApplication()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   542
  Sent 1024 bytes to 10.1.1.2
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   543
  2.25732s Received 1024 bytes from 10.1.1.1
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   544
  2.25732s Echoing packet
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   545
  Received 1024 bytes from 10.1.1.2
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   546
  10s UdpEchoServerApplication:StopApplication()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   547
  UdpEchoServerApplication:DoDispose()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   548
  UdpEchoServerApplication:~UdpEchoServer()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   549
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   550
Recall that the last time we looked at the simulation time at which the packet
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   551
was received by the echo server, it was at 2.00369 seconds.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   552
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   553
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   554
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   555
  2.00369s UdpEchoServerApplication:HandleRead(): Received 1024 bytes from 10.1.1.1
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   556
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   557
Now it is receiving the packet at 2.25732 seconds.  This is because we just dropped
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   558
the data rate of the ``PointToPointNetDevice`` down to its default of 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   559
32768 bits per second from five megabits per second.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   560
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   561
If we were to provide a new ``DataRate`` using the command line, we could 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   562
speed our simulation up again.  We do this in the following way, according to
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   563
the formula implied by the help item:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   564
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   565
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   566
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   567
  $ ./waf --run "scratch/myfirst --ns3::PointToPointNetDevice::DataRate=5Mbps"
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   568
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   569
This will set the default value of the ``DataRate`` ``Attribute`` back to 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   570
five megabits per second.  Are you surprised by the result?  It turns out that
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   571
in order to get the original behavior of the script back, we will have to set 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   572
the speed-of-light delay of the channel as well.  We can ask the command line 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   573
system to print out the ``Attributes`` of the channel just like we did for
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   574
the net device:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   575
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   576
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   577
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   578
  $ ./waf --run "scratch/myfirst --PrintAttributes=ns3::PointToPointChannel"
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   579
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   580
We discover the ``Delay`` ``Attribute`` of the channel is set in the following
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   581
way:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   582
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   583
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   584
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   585
  --ns3::PointToPointChannel::Delay=[0ns]:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   586
    Transmission delay through the channel
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   587
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   588
We can then set both of these default values through the command line system,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   589
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   590
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   591
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   592
  $ ./waf --run "scratch/myfirst
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   593
    --ns3::PointToPointNetDevice::DataRate=5Mbps
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   594
    --ns3::PointToPointChannel::Delay=2ms"
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   595
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   596
in which case we recover the timing we had when we explicitly set the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   597
``DataRate`` and ``Delay`` in the script:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   598
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   599
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   600
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   601
  Waf: Entering directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   602
  Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   603
  'build' finished successfully (0.417s)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   604
  0s UdpEchoServerApplication:UdpEchoServer()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   605
  1s UdpEchoServerApplication:StartApplication()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   606
  Sent 1024 bytes to 10.1.1.2
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   607
  2.00369s Received 1024 bytes from 10.1.1.1
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   608
  2.00369s Echoing packet
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   609
  Received 1024 bytes from 10.1.1.2
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   610
  10s UdpEchoServerApplication:StopApplication()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   611
  UdpEchoServerApplication:DoDispose()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   612
  UdpEchoServerApplication:~UdpEchoServer()
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
Note that the packet is again received by the server at 2.00369 seconds.  We 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   615
could actually set any of the ``Attributes`` used in the script in this way.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   616
In particular we could set the ``UdpEchoClient Attribute MaxPackets`` 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   617
to some other value than one.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   618
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   619
How would you go about that?  Give it a try.  Remember you have to comment 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   620
out the place we override the default ``Attribute`` and explicitly set 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   621
``MaxPackets`` in the script.  Then you have to rebuild the script.  You 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   622
will also have to find the syntax for actually setting the new default attribute
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   623
value using the command line help facility.  Once you have this figured out 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   624
you should be able to control the number of packets echoed from the command 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   625
line.  Since we're nice folks, we'll tell you that your command line should 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   626
end up looking something like,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   627
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   628
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   629
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   630
  $ ./waf --run "scratch/myfirst 
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   631
    --ns3::PointToPointNetDevice::DataRate=5Mbps 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   632
    --ns3::PointToPointChannel::Delay=2ms 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   633
    --ns3::UdpEchoClient::MaxPackets=2"
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   634
11248
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   635
A natural question to arise at this point is how to learn about the existence
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   636
of all of these attributes.  Again, the command line help facility has
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   637
a feature for this.  If we ask for command line help we should see:
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   638
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   639
.. sourcecode:: bash
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   640
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   641
  $ ./waf --run "scratch/myfirst --PrintHelp"
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   642
  myfirst [Program Arguments] [General Arguments]
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   643
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   644
  General Arguments:
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   645
    --PrintGlobals:              Print the list of globals.
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   646
    --PrintGroups:               Print the list of groups.
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   647
    --PrintGroup=[group]:        Print all TypeIds of group.
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   648
    --PrintTypeIds:              Print all TypeIds.
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   649
    --PrintAttributes=[typeid]:  Print all attributes of typeid.
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   650
    --PrintHelp:                 Print this help message.
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   651
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   652
If you select the "PrintGroups" argument, you should see a list of all
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   653
registered TypeId groups.  The group names are aligned with the module names
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   654
in the source directory (although with a leading capital letter).  Printing 
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   655
out all of the information at once would be too much, so a further filter 
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   656
is available to print information on a per-group basis.   So, focusing
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   657
again on the point-to-point module:
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   658
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   659
.. sourcecode:: bash
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   660
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   661
  ./waf --run "scratch/myfirst --PrintGroup=PointToPoint"
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   662
  TypeIds in group PointToPoint:
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   663
    ns3::PointToPointChannel
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   664
    ns3::PointToPointNetDevice
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   665
    ns3::PointToPointRemoteChannel
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   666
    ns3::PppHeader
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   667
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   668
and from here, one can find the possible TypeId names to search for
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   669
attributes, such as in the ``--PrintAttributes=ns3::PointToPointChannel``
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   670
example shown above.
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   671
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   672
Another way to find out about attributes is through the ns-3 Doxygen; there
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   673
is a page that lists out all of the registered attributes in the simulator.
88468adb47b5 additional coverage of group name usage in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 11088
diff changeset
   674
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   675
Hooking Your Own Values
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   676
+++++++++++++++++++++++
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   677
You can also add your own hooks to the command line system.  This is done
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   678
quite simply by using the ``AddValue`` method to the command line parser.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   679
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   680
Let's use this facility to specify the number of packets to echo in a 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   681
completely different way.  Let's add a local variable called ``nPackets``
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   682
to the ``main`` function.  We'll initialize it to one to match our previous 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   683
default behavior.  To allow the command line parser to change this value, we
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   684
need to hook the value into the parser.  We do this by adding a call to 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   685
``AddValue``.  Go ahead and change the ``scratch/myfirst.cc`` script to
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   686
start with the following code,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   687
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   688
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   689
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   690
  int
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   691
  main (int argc, char *argv[])
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   692
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   693
    uint32_t nPackets = 1;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   694
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   695
    CommandLine cmd;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   696
    cmd.AddValue("nPackets", "Number of packets to echo", nPackets);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   697
    cmd.Parse (argc, argv);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   698
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   699
    ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   700
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   701
Scroll down to the point in the script where we set the ``MaxPackets``
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   702
``Attribute`` and change it so that it is set to the variable ``nPackets``
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   703
instead of the constant ``1`` as is shown below.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   704
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   705
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   706
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   707
  echoClient.SetAttribute ("MaxPackets", UintegerValue (nPackets));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   708
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   709
Now if you run the script and provide the ``--PrintHelp`` argument, you 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   710
should see your new ``User Argument`` listed in the help display.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   711
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   712
Try,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   713
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   714
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   715
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   716
  $ ./waf --run "scratch/myfirst --PrintHelp"
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   717
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   718
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   719
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   720
  Waf: Entering directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   721
  Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   722
  'build' finished successfully (0.403s)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   723
  --PrintHelp: Print this help message.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   724
  --PrintGroups: Print the list of groups.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   725
  --PrintTypeIds: Print all TypeIds.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   726
  --PrintGroup=[group]: Print all TypeIds of group.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   727
  --PrintAttributes=[typeid]: Print all attributes of typeid.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   728
  --PrintGlobals: Print the list of globals.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   729
  User Arguments:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   730
      --nPackets: Number of packets to echo
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   731
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   732
If you want to specify the number of packets to echo, you can now do so by
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   733
setting the ``--nPackets`` argument in the command line,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   734
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   735
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   736
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   737
  $ ./waf --run "scratch/myfirst --nPackets=2"
6754
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
You should now see
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   740
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   741
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   742
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   743
  Waf: Entering directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   744
  Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   745
  'build' finished successfully (0.404s)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   746
  0s UdpEchoServerApplication:UdpEchoServer()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   747
  1s UdpEchoServerApplication:StartApplication()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   748
  Sent 1024 bytes to 10.1.1.2
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   749
  2.25732s Received 1024 bytes from 10.1.1.1
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   750
  2.25732s Echoing packet
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   751
  Received 1024 bytes from 10.1.1.2
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   752
  Sent 1024 bytes to 10.1.1.2
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   753
  3.25732s Received 1024 bytes from 10.1.1.1
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   754
  3.25732s Echoing packet
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   755
  Received 1024 bytes from 10.1.1.2
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   756
  10s UdpEchoServerApplication:StopApplication()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   757
  UdpEchoServerApplication:DoDispose()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   758
  UdpEchoServerApplication:~UdpEchoServer()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   759
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   760
You have now echoed two packets.  Pretty easy, isn't it?
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   761
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   762
You can see that if you are an |ns3| user, you can use the command 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   763
line argument system to control global values and ``Attributes``.  If you are
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   764
a model author, you can add new ``Attributes`` to your ``Objects`` and 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   765
they will automatically be available for setting by your users through the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   766
command line system.  If you are a script author, you can add new variables to 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   767
your scripts and hook them into the command line system quite painlessly.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   768
11088
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   769
.. _UsingTracingSystem:
50e89dc6d8b1 [Sphinx] Update the Tracing chapter in the Tutorial.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   770
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   771
Using the Tracing System
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   772
************************
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   773
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   774
The whole point of simulation is to generate output for further study, and 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   775
the |ns3| tracing system is a primary mechanism for this.  Since 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   776
|ns3| is a C++ program, standard facilities for generating output 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   777
from C++ programs could be used:  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   778
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   779
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   780
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   781
  #include <iostream>
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   782
  ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   783
  int main ()
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   784
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   785
    ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   786
    std::cout << "The value of x is " << x << std::endl;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   787
    ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   788
  } 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   789
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   790
You could even use the logging module to add a little structure to your 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   791
solution.  There are many well-known problems generated by such approaches
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   792
and so we have provided a generic event tracing subsystem to address the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   793
issues we thought were important.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   794
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   795
The basic goals of the |ns3| tracing system are:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   796
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   797
* For basic tasks, the tracing system should allow the user to generate 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   798
  standard tracing for popular tracing sources, and to customize which objects
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   799
  generate the tracing;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   800
* Intermediate users must be able to extend the tracing system to modify
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   801
  the output format generated, or to insert new tracing sources, without 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   802
  modifying the core of the simulator;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   803
* Advanced users can modify the simulator core to add new tracing sources
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   804
  and sinks.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   805
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   806
The |ns3| tracing system is built on the concepts of independent 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   807
tracing sources and tracing sinks, and a uniform mechanism for connecting
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   808
sources to sinks.  Trace sources are entities that can signal events that
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   809
happen in a simulation and provide access to interesting underlying data. 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   810
For example, a trace source could indicate when a packet is received by a net
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   811
device and provide access to the packet contents for interested trace sinks.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   812
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   813
Trace sources are not useful by themselves, they must be "connected" to
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   814
other pieces of code that actually do something useful with the information 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   815
provided by the sink.  Trace sinks are consumers of the events and data
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   816
provided by the trace sources.  For example, one could create a trace sink 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   817
that would (when connected to the trace source of the previous example) print 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   818
out interesting parts of the received packet.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   819
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   820
The rationale for this explicit division is to allow users to attach new
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   821
types of sinks to existing tracing sources, without requiring editing and 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   822
recompilation of the core of the simulator.  Thus, in the example above, 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   823
a user could define a new tracing sink in her script and attach it to an 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   824
existing tracing source defined in the simulation core by editing only the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   825
user script.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   826
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   827
In this tutorial, we will walk through some pre-defined sources and sinks and
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   828
show how they may be customized with little user effort.  See the ns-3 manual
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   829
or how-to sections for information on advanced tracing configuration including
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   830
extending the tracing namespace and creating new tracing sources.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   831
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   832
ASCII Tracing
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   833
+++++++++++++
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   834
|ns3| provides helper functionality that wraps the low-level tracing
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   835
system to help you with the details involved in configuring some easily 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   836
understood packet traces.  If you enable this functionality, you will see
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   837
output in a ASCII files --- thus the name.  For those familiar with 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   838
|ns2| output, this type of trace is analogous to the ``out.tr``
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   839
generated by many scripts.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   840
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   841
Let's just jump right in and add some ASCII tracing output to our 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   842
``scratch/myfirst.cc`` script.  Right before the call to 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   843
``Simulator::Run ()``, add the following lines of code:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   844
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   845
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   846
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   847
  AsciiTraceHelper ascii;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   848
  pointToPoint.EnableAsciiAll (ascii.CreateFileStream ("myfirst.tr"));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   849
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   850
Like in many other |ns3| idioms, this code uses a  helper object to 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   851
help create ASCII traces.  The second line contains two nested method calls.  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   852
The "inside" method, ``CreateFileStream()`` uses an unnamed object idiom
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   853
to create a file stream object on the stack (without an object  name) and pass
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   854
it down to the called method.  We'll go into this more in the future, but all
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   855
you have to know at this point is that you are creating an object representing
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   856
a file named "myfirst.tr" and passing it into ``ns-3``.  You are telling 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   857
``ns-3`` to deal with the lifetime issues of the created object and also to 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   858
deal with problems caused by a little-known (intentional) limitation of C++ 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   859
ofstream objects relating to copy constructors.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   860
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   861
The outside call, to ``EnableAsciiAll()``, tells the helper that you 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   862
want to enable ASCII tracing on all point-to-point devices in your simulation; 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   863
and you want the (provided) trace sinks to write out information about packet 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   864
movement in ASCII format.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   865
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   866
For those familiar with |ns2|, the traced events are equivalent to 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   867
the popular trace points that log "+", "-", "d", and "r" events.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   868
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   869
You can now build the script and run it from the command line:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   870
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   871
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   872
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   873
  $ ./waf --run scratch/myfirst
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   874
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   875
Just as you have seen many times before, you will see some messages from Waf and then
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   876
"'build' finished successfully" with some number of messages from 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   877
the running program.  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   878
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   879
When it ran, the program will have created a file named ``myfirst.tr``.  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   880
Because of the way that Waf works, the file is not created in the local 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   881
directory, it is created at the top-level directory of the repository by 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   882
default.  If you want to control where the traces are saved you can use the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   883
``--cwd`` option of Waf to specify this.  We have not done so, thus we 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   884
need to change into the top level directory of our repo and take a look at 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   885
the ASCII trace file ``myfirst.tr`` in your favorite editor.
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
Parsing Ascii Traces
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   888
~~~~~~~~~~~~~~~~~~~~
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   889
There's a lot of information there in a pretty dense form, but the first thing
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   890
to notice is that there are a number of distinct lines in this file.  It may
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   891
be difficult to see this clearly unless you widen your window considerably.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   892
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   893
Each line in the file corresponds to a *trace event*.  In this case
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   894
we are tracing events on the *transmit queue* present in every 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   895
point-to-point net device in the simulation.  The transmit queue is a queue 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   896
through which every packet destined for a point-to-point channel must pass.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   897
Note that each line in the trace file begins with a lone character (has a 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   898
space after it).  This character will have the following meaning:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   899
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   900
* ``+``: An enqueue operation occurred on the device queue;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   901
* ``-``: A dequeue operation occurred on the device queue;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   902
* ``d``: A packet was dropped, typically because the queue was full;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   903
* ``r``: A packet was received by the net device.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   904
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   905
Let's take a more detailed view of the first line in the trace file.  I'll 
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   906
break it down into sections (indented for clarity) with a reference
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   907
number on the left side:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   908
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   909
.. sourcecode:: text
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   910
  :linenos:
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   911
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   912
  + 
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   913
  2 
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   914
  /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue 
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   915
  ns3::PppHeader (
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   916
    Point-to-Point Protocol: IP (0x0021)) 
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   917
    ns3::Ipv4Header (
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   918
      tos 0x0 ttl 64 id 0 protocol 17 offset 0 flags [none] 
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   919
      length: 1052 10.1.1.1 > 10.1.1.2)
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   920
      ns3::UdpHeader (
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   921
        length: 1032 49153 > 9) 
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   922
        Payload (size=1024)
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   923
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   924
The first section of this expanded trace event (reference number 0) is the 
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   925
operation.  We have a ``+`` character, so this corresponds to an
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   926
*enqueue* operation on the transmit queue.  The second section (reference 1)
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   927
is the simulation time expressed in seconds.  You may recall that we asked the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   928
``UdpEchoClientApplication`` to start sending packets at two seconds.  Here
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   929
we see confirmation that this is, indeed, happening.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   930
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   931
The next section of the example trace (reference 2) tell us which trace source
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   932
originated this event (expressed in the tracing namespace).  You can think
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   933
of the tracing namespace somewhat like you would a filesystem namespace.  The 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   934
root of the namespace is the ``NodeList``.  This corresponds to a container
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   935
managed in the |ns3| core code that contains all of the nodes that are
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   936
created in a script.  Just as a filesystem may have directories under the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   937
root, we may have node numbers in the ``NodeList``.  The string 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   938
``/NodeList/0`` therefore refers to the zeroth node in the ``NodeList``
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   939
which we typically think of as "node 0".  In each node there is a list of 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   940
devices that have been installed.  This list appears next in the namespace.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   941
You can see that this trace event comes from ``DeviceList/0`` which is the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   942
zeroth device installed in the node. 
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
The next string, ``$ns3::PointToPointNetDevice`` tells you what kind of 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   945
device is in the zeroth position of the device list for node zero.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   946
Recall that the operation ``+`` found at reference 00 meant that an enqueue 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   947
operation happened on the transmit queue of the device.  This is reflected in 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   948
the final segments of the "trace path" which are ``TxQueue/Enqueue``.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   949
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   950
The remaining sections in the trace should be fairly intuitive.  References 3-4
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   951
indicate that the packet is encapsulated in the point-to-point protocol.  
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   952
References 5-7 show that the packet has an IP version four header and has
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   953
originated from IP address 10.1.1.1 and is destined for 10.1.1.2.  References
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   954
8-9 show that this packet has a UDP header and, finally, reference 10 shows
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   955
that the payload is the expected 1024 bytes.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   956
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   957
The next line in the trace file shows the same packet being dequeued from the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   958
transmit queue on the same node. 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   959
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   960
The Third line in the trace file shows the packet being received by the net
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   961
device on the node with the echo server. I have reproduced that event below.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   962
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   963
.. sourcecode:: text
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   964
  :linenos:
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   965
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   966
  r 
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   967
  2.25732 
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   968
  /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/MacRx 
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   969
    ns3::Ipv4Header (
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   970
      tos 0x0 ttl 64 id 0 protocol 17 offset 0 flags [none]
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   971
      length: 1052 10.1.1.1 > 10.1.1.2)
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   972
      ns3::UdpHeader (
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   973
        length: 1032 49153 > 9) 
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
   974
        Payload (size=1024)
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   975
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   976
Notice that the trace operation is now ``r`` and the simulation time has
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   977
increased to 2.25732 seconds.  If you have been following the tutorial steps
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   978
closely this means that you have left the ``DataRate`` of the net devices
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   979
and the channel ``Delay`` set to their default values.  This time should 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   980
be familiar as you have seen it before in a previous section.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   981
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   982
The trace source namespace entry (reference 02) has changed to reflect that
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   983
this event is coming from node 1 (``/NodeList/1``) and the packet reception
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   984
trace source (``/MacRx``).  It should be quite easy for you to follow the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   985
progress of the packet through the topology by looking at the rest of the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   986
traces in the file.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   987
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   988
PCAP Tracing
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   989
++++++++++++
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   990
The |ns3| device helpers can also be used to create trace files in the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   991
``.pcap`` format.  The acronym pcap (usually written in lower case) stands
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   992
for packet capture, and is actually an API that includes the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   993
definition of a ``.pcap`` file format.  The most popular program that can
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   994
read and display this format is Wireshark (formerly called Ethereal).
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   995
However, there are many traffic trace analyzers that use this packet format.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   996
We encourage users to exploit the many tools available for analyzing pcap
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   997
traces.  In this tutorial, we concentrate on viewing pcap traces with tcpdump.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   998
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   999
The code used to enable pcap tracing is a one-liner.  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1000
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1001
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1002
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1003
  pointToPoint.EnablePcapAll ("myfirst");
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1004
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1005
Go ahead and insert this line of code after the ASCII tracing code we just 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1006
added to ``scratch/myfirst.cc``.  Notice that we only passed the string
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1007
"myfirst," and not "myfirst.pcap" or something similar.  This is because the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1008
parameter is a prefix, not a complete file name.  The helper will actually 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1009
create a trace file for every point-to-point device in the simulation.  The 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1010
file names will be built using the prefix, the node number, the device number
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1011
and a ".pcap" suffix.
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
In our example script, we will eventually see files named "myfirst-0-0.pcap" 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1014
and "myfirst-1-0.pcap" which are the pcap traces for node 0-device 0 and 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1015
node 1-device 0, respectively.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1016
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1017
Once you have added the line of code to enable pcap tracing, you can run the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1018
script in the usual way:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1019
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
  1020
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1021
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
  1022
  $ ./waf --run scratch/myfirst
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1023
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1024
If you look at the top level directory of your distribution, you should now
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1025
see three log files:  ``myfirst.tr`` is the ASCII trace file we have 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1026
previously examined.  ``myfirst-0-0.pcap`` and ``myfirst-1-0.pcap``
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1027
are the new pcap files we just generated.  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1028
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1029
Reading output with tcpdump
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1030
~~~~~~~~~~~~~~~~~~~~~~~~~~~
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1031
The easiest thing to do at this point will be to use ``tcpdump`` to look
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1032
at the ``pcap`` files.  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1033
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
  1034
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1035
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9104
diff changeset
  1036
  $ tcpdump -nn -tt -r myfirst-0-0.pcap
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1037
  reading from file myfirst-0-0.pcap, link-type PPP (PPP)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1038
  2.000000 IP 10.1.1.1.49153 > 10.1.1.2.9: UDP, length 1024
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1039
  2.514648 IP 10.1.1.2.9 > 10.1.1.1.49153: UDP, length 1024
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1040
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1041
  tcpdump -nn -tt -r myfirst-1-0.pcap
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1042
  reading from file myfirst-1-0.pcap, link-type PPP (PPP)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1043
  2.257324 IP 10.1.1.1.49153 > 10.1.1.2.9: UDP, length 1024
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1044
  2.257324 IP 10.1.1.2.9 > 10.1.1.1.49153: UDP, length 1024
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
You can see in the dump of ``myfirst-0-0.pcap`` (the client device) that the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1047
echo packet is sent at 2 seconds into the simulation.  If you look at the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1048
second dump (``myfirst-1-0.pcap``) you can see that packet being received
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1049
at 2.257324 seconds.  You see the packet being echoed back at 2.257324 seconds
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1050
in the second dump, and finally, you see the packet being received back at 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1051
the client in the first dump at 2.514648 seconds.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1052
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1053
Reading output with Wireshark
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1054
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1055
If you are unfamiliar with Wireshark, there is a web site available from which
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1056
you can download programs and documentation:  http://www.wireshark.org/.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1057
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1058
Wireshark is a graphical user interface which can be used for displaying these
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1059
trace files.  If you have Wireshark available, you can open each of the trace
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1060
files and display the contents as if you had captured the packets using a
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1061
*packet sniffer*.