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