doc/tutorial/tweaking.texi
author Craig Dowell <craigdo@ee.washington.edu>
Tue, 24 Mar 2009 12:45:30 -0700
changeset 4293 11a2cda6a096
parent 4207 11043ba9a122
child 4294 ebb973fdb763
permissions -rw-r--r--
clean up tutorial up through tweaking section
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
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
    92
to get our bearings, go ahead and run the script just as you did previously,
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    93
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    94
@verbatim
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
    95
  ./waf --run scratch/myfirst
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
    96
@end verbtim
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
    97
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
    98
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
    99
program
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   100
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   101
@verbatim
3354
f11e4def3fc4 tweak, tweak the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3351
diff changeset
   102
  Entering directory `/home/craigdo/repos/ns-3-dev/build'
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   103
  Compilation finished successfully
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   104
  Sent 1024 bytes to 10.1.1.2
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   105
  Received 1024 bytes from 10.1.1.1
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   106
  Received 1024 bytes from 10.1.1.2
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   107
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   108
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   109
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
   110
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
   111
@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
   112
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
   113
NS_LOG environment variable.  
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   114
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   115
I am going to assume from here on that are using an sh-like shell that uses 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   116
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
   117
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
   118
required by those shells.
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   119
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   120
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
   121
of code in @code{scratch/myfirst.cc},
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   122
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   123
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   124
  LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   125
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   126
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   127
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
   128
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
   129
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
   130
@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
   131
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
   132
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
   133
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   134
@verbatim
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   135
  export NS_LOG=UdpEchoClientApplication=level_all
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   136
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   137
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   138
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
   139
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   140
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   141
  UdpEchoClientApplication=level_all
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   142
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   143
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   144
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
   145
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
   146
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
   147
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
   148
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
   149
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   150
@verbatim
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   151
  Entering directory `/home/craigdo/repos/ns-3-allinone-dev/ns-3-dev/build'
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   152
  Build finished successfully (00:00:00)
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   153
  UdpEchoClientApplication:UdpEchoClient()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   154
  UdpEchoClientApplication:StartApplication()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   155
  UdpEchoClientApplication:ScheduleTransmit()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   156
  UdpEchoClientApplication:Send()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   157
  Sent 1024 bytes to 10.1.1.2
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   158
  Received 1024 bytes from 10.1.1.1
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   159
  UdpEchoClientApplication:HandleRead(0x638180, 0x6389b0)
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   160
  Received 1024 bytes from 10.1.1.2
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   161
  UdpEchoClientApplication:StopApplication()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   162
  UdpEchoClientApplication:DoDispose()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   163
  UdpEchoClientApplication:~UdpEchoClient()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   164
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   165
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   166
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
   167
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
   168
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
   169
@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
   170
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
   171
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
   172
applications, a good deal of log output is available.
3348
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   173
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   174
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
   175
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
   176
@code{UdpEchoClientApplication} and the method name where you might have 
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   177
expected a C++ scope operator (@code{::}).  This is intentional.  
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   178
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   179
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
   180
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
   181
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
   182
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
   183
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
   184
logging component name from the class name.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   185
3771
21f40ccb03b3 tutorial typos fixed (bug 379)
Tom Henderson <tomh@tomh.org>
parents: 3382
diff changeset
   186
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
   187
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
   188
wonder where the string ``@code{Received 1024 bytes from 10.1.1.2}'' comes
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   189
from.  You can resolve this by ORing the @code{prefix_func} level into the
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   190
@code{NS_LOG} environment variable.  Try doing the following,
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   191
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   192
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   193
  export 'NS_LOG=UdpEchoClientApplication=level_all|prefix_func'
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   194
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   195
3348
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   196
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
   197
OR operation is also a Unix pipe connector.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   198
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   199
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
   200
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
   201
name.
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
@verbatim
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   204
  Entering directory `/home/craigdo/repos/ns-3-allinone-dev/ns-3-dev/build'
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   205
  Build finished successfully (00:00:00)
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   206
  UdpEchoClientApplication:UdpEchoClient()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   207
  UdpEchoClientApplication:StartApplication()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   208
  UdpEchoClientApplication:ScheduleTransmit()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   209
  UdpEchoClientApplication:Send()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   210
  UdpEchoClientApplication:Send(): Sent 1024 bytes to 10.1.1.2
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   211
  Received 1024 bytes from 10.1.1.1
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   212
  UdpEchoClientApplication:HandleRead(0x638180, 0x6389b0)
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   213
  UdpEchoClientApplication:HandleRead(): Received 1024 bytes from 10.1.1.2
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   214
  UdpEchoClientApplication:StopApplication()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   215
  UdpEchoClientApplication:DoDispose()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   216
  UdpEchoClientApplication:~UdpEchoClient()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   217
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   218
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   219
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
   220
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
   221
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
   222
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
   223
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
   224
the NS_LOG environment variable.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   225
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   226
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   227
  export 'NS_LOG=UdpEchoClientApplication=level_all|prefix_func:
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   228
                 UdpEchoServerApplication=level_all|prefix_func'
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   229
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   230
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   231
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
   232
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
   233
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   234
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
   235
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
   236
in debugging problems.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   237
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   238
@verbatim
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   239
  Entering directory `/home/craigdo/repos/ns-3-allinone-dev/ns-3-dev/build'
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   240
  Build finished successfully (00:00:00)
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   241
  UdpEchoServerApplication:UdpEchoServer()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   242
  UdpEchoClientApplication:UdpEchoClient()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   243
  UdpEchoServerApplication:StartApplication()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   244
  UdpEchoClientApplication:StartApplication()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   245
  UdpEchoClientApplication:ScheduleTransmit()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   246
  UdpEchoClientApplication:Send()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   247
  UdpEchoClientApplication:Send(): Sent 1024 bytes to 10.1.1.2
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   248
  UdpEchoServerApplication:HandleRead(): Received 1024 bytes from 10.1.1.1
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   249
  UdpEchoServerApplication:HandleRead(): Echoing packet
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   250
  UdpEchoClientApplication:HandleRead(0x638320, 0x638b50)
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   251
  UdpEchoClientApplication:HandleRead(): Received 1024 bytes from 10.1.1.2
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   252
  UdpEchoServerApplication:StopApplication()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   253
  UdpEchoClientApplication:StopApplication()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   254
  UdpEchoClientApplication:DoDispose()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   255
  UdpEchoServerApplication:DoDispose()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   256
  UdpEchoClientApplication:~UdpEchoClient()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   257
  UdpEchoServerApplication:~UdpEchoServer()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   258
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   259
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   260
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
   261
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
   262
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   263
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   264
  export 'NS_LOG=UdpEchoClientApplication=level_all|prefix_func|prefix_time:
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   265
                 UdpEchoServerApplication=level_all|prefix_func|prefix_time'
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
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   268
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
   269
you should see the following output:
3332
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
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   272
  Entering directory `/home/craigdo/repos/ns-3-allinone-dev/ns-3-dev/build'
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   273
  Build finished successfully (00:00:00)
4207
11043ba9a122 tutorial fixes from Ruben Merz
Tom Henderson <tomh@tomh.org>
parents: 4032
diff changeset
   274
  0s UdpEchoServerApplication:UdpEchoServer()
11043ba9a122 tutorial fixes from Ruben Merz
Tom Henderson <tomh@tomh.org>
parents: 4032
diff changeset
   275
  0s UdpEchoClientApplication:UdpEchoClient()
11043ba9a122 tutorial fixes from Ruben Merz
Tom Henderson <tomh@tomh.org>
parents: 4032
diff changeset
   276
  1s UdpEchoServerApplication:StartApplication()
11043ba9a122 tutorial fixes from Ruben Merz
Tom Henderson <tomh@tomh.org>
parents: 4032
diff changeset
   277
  2s UdpEchoClientApplication:StartApplication()
11043ba9a122 tutorial fixes from Ruben Merz
Tom Henderson <tomh@tomh.org>
parents: 4032
diff changeset
   278
  2s UdpEchoClientApplication:ScheduleTransmit()
11043ba9a122 tutorial fixes from Ruben Merz
Tom Henderson <tomh@tomh.org>
parents: 4032
diff changeset
   279
  2s UdpEchoClientApplication:Send()
11043ba9a122 tutorial fixes from Ruben Merz
Tom Henderson <tomh@tomh.org>
parents: 4032
diff changeset
   280
  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
   281
  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
   282
  2.00369s UdpEchoServerApplication:HandleRead(): Echoing packet
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   283
  2.00737s UdpEchoClientApplication:HandleRead(0x638490, 0x638cc0)
4207
11043ba9a122 tutorial fixes from Ruben Merz
Tom Henderson <tomh@tomh.org>
parents: 4032
diff changeset
   284
  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
   285
  10s UdpEchoServerApplication:StopApplication()
11043ba9a122 tutorial fixes from Ruben Merz
Tom Henderson <tomh@tomh.org>
parents: 4032
diff changeset
   286
  10s UdpEchoClientApplication:StopApplication()
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   287
  UdpEchoClientApplication:DoDispose()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   288
  UdpEchoServerApplication:DoDispose()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   289
  UdpEchoClientApplication:~UdpEchoClient()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   290
  UdpEchoServerApplication:~UdpEchoServer()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   291
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   292
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   293
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
   294
simulation time of 0 seconds.  This is actually happening before the 
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   295
simulation starts.  The same for the UdpEchoClient constructor.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   296
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   297
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
   298
application at one second into the simulation.  You can now see that the 
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   299
@code{StartApplication} method of the server is, in fact, called at one second
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   300
(or one billion nanoseconds).  You can also see that the echo client 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   301
application is started at a simulation time of two seconds as we requested in
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   302
the script.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   303
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   304
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
   305
@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
   306
@code{HandleRead} callback in the echo server application.  Note that the 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   307
elapsed time as the packet is sent across the point-to-point link is 3.6864
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   308
milliseconds.  You see the echo server logging a message telling you that it
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   309
has echoed the packet and then, after a delay, you see the echo client receive
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   310
the echoed packet in its @code{HandleRead} method.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   311
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   312
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
   313
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
   314
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
   315
@code{NS_LOG} variable to the following,
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   316
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   317
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   318
  export 'NS_LOG=*=level_all|prefix_func|prefix_time'
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   319
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   320
3348
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   321
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
   322
of the logging in all of the components used in the simulation.  I won't 
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   323
reproduce the output here (as of this writing it produces 974 lines of output
3348
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   324
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
   325
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
   326
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   327
@verbatim
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   328
  ./waf --run scratch/myfirst > log.out 2>&1
3332
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
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   331
I personally use this volume of logging quite a bit when I am presented with 
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   332
a problem and I have no idea where things are going wrong.  I can follow the 
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   333
progress of the code quite easily without having to set breakpoints and step 
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   334
through code in a debugger.  When I have a general idea about what is going 
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   335
wrong, I transition into a debugger for fine-grained examination of the 
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   336
problem.  This kind of output can be especially useful when your script does 
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   337
something completely unexpected.  If you are stepping using a debugger you
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   338
may miss an unexpected excursion completely.  Logging the excursion makes it
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   339
quickly visible.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   340
3342
8762b90e6f7e formatting nits on the Tweaking chapter
Tom Henderson <tomh@tomh.org>
parents: 3340
diff changeset
   341
@node Adding Logging to your Code
8762b90e6f7e formatting nits on the Tweaking chapter
Tom Henderson <tomh@tomh.org>
parents: 3340
diff changeset
   342
@subsection Adding Logging to your Code
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   343
@cindex NS_LOG
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   344
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
   345
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
   346
have in the @code{scratch} directory.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   347
3348
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   348
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
   349
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   350
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   351
  NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   352
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   353
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   354
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
   355
setting the @code{NS_LOG} environment variable to the various levels.  Let's
3348
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   356
go ahead add some logging to the script.  The macro used to add an 
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   357
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
   358
(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
   359
``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
   360
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   361
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
   362
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   363
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   364
  NS_LOG_INFO ("Creating Topology");
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   365
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   366
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   367
right before the lines,
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   368
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   369
@verbatim
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   370
  NodeContainer nodes;
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   371
  nodes.Create (2);
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   372
@end verbatim
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
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
   375
off the torrent of logging we previously enabled:
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   376
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   377
@verbatim
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   378
  ./waf
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   379
  export NS_LOG=
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   380
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   381
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   382
Now, if you run the script, 
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   383
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   384
@verbatim
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   385
  ./waf --run scratch/myfirst
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   386
@end verbatim
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   387
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   388
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
   389
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
   390
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
   391
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
   392
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
   393
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   394
@verbatim
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   395
  export NS_LOG=FirstScriptExample=info
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   396
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   397
3348
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   398
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
   399
message,
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   400
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   401
@verbatim
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   402
  Entering directory `/home/craigdo/repos/ns-3-allinone-dev/ns-3-dev/build'
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   403
  Build finished successfully (00:00:00)
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   404
  Creating Topology
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   405
  Sent 1024 bytes to 10.1.1.2
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   406
  Received 1024 bytes from 10.1.1.1
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   407
  Received 1024 bytes from 10.1.1.2
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   408
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   409
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   410
@c ========================================================================
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   411
@c Using Command Line Arguments
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   412
@c ========================================================================
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   413
@node Using Command Line Arguments
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   414
@section Using Command Line Arguments
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   415
3342
8762b90e6f7e formatting nits on the Tweaking chapter
Tom Henderson <tomh@tomh.org>
parents: 3340
diff changeset
   416
@subsection Overriding Default Attributes
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   417
@cindex command line arguments
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3348
diff changeset
   418
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
   419
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
   420
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
   421
based on those arguments.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   422
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   423
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
   424
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
   425
in the following code,
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   426
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   427
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   428
    int
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   429
  main (int argc, char *argv[])
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   430
  {
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   431
    ...  
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   432
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   433
    CommandLine cmd;
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   434
    cmd.Parse (argc, argv);
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   435
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   436
    ...
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   437
  }
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   438
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   439
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   440
This simple two line snippet is actually very useful by itself.  It opens the
3348
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   441
door to the @command{ns-3} global variable and attribute systems.  Go ahead 
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   442
and add that two lines of code to the @code{scratch/first.cc} script at the 
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   443
start of @code{main}.  Go ahead and build the script and run it, but ask the script 
3348
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   444
for help in the following way,
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   445
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   446
@verbatim
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   447
  ./waf --run "scratch/myfirst --PrintHelp"
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   448
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   449
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   450
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
   451
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
   452
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
   453
now see the @code{--PrintHelp} argument and respond with,
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   454
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   455
@verbatim
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   456
  Entering directory `/home/craigdo/repos/ns-3-allinone-dev/ns-3-dev/build'
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   457
  Build finished successfully (00:00:00)
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   458
  --PrintHelp: Print this help message.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   459
  --PrintGroups: Print the list of groups.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   460
  --PrintTypeIds: Print all TypeIds.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   461
  --PrintGroup=[group]: Print all TypeIds of group.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   462
  --PrintAttributes=[typeid]: Print all attributes of typeid.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   463
  --PrintGlobals: Print the list of globals.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   464
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   465
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   466
Let's focus on the @code{--PrintAttributes} option.  We have already hinted
3348
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   467
at the @command{ns-3} attribute system while walking through the 
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   468
@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
   469
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   470
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   471
    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
   472
    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
   473
    pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   474
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   475
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   476
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
   477
@code{PointToPointNetDevice}.  Let's use the command line argument parser
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   478
to take a look at the attributes of the PointToPointNetDevice.  The help
3348
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   479
listing says that we should provide a @code{TypeId}.  This corresponds to the
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   480
class name of the class to which the attributes belong.  In this case it will
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   481
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
   482
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   483
@verbatim
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   484
  ./waf --run "scratch/myfirst --PrintAttributes=ns3::PointToPointNetDevice"
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   485
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   486
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   487
The system will print out all of the attributes of this kind of net device.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   488
Among the attributes you will see listed is,
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   489
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   490
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   491
  --ns3::PointToPointNetDevice::DataRate=[32768bps]:
3348
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   492
    The default data rate for point to point links
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   493
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   494
3348
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   495
This is the default value that will be used when a @code{PointToPointNetDevice}
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
   496
is created in the system.  We overrode this default with the attribute
3348
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   497
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
   498
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
   499
@code{SetDeviceAttribute} call and the @code{SetChannelAttribute} call from 
3348
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   500
the @code{first.cc} we have in the scratch directory.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   501
3348
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   502
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
   503
any @code{set} operations as in the following example,
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
  ...
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   507
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   508
  NodeContainer nodes;
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   509
  nodes.Create (2);
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   510
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   511
  PointToPointHelper pointToPoint;
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   512
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   513
  NetDeviceContainer devices;
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   514
  devices = pointToPoint.Install (nodes);
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   515
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   516
  ...
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   517
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   518
3348
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   519
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
   520
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
   521
time prefix.
3332
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
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   524
  export 'NS_LOG=UdpEchoServerApplication=level_all|prefix_time'
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   525
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   526
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   527
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
   528
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   529
@verbatim
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   530
  Build finished successfully (00:00:00)
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   531
  0s UdpEchoServerApplication:UdpEchoServer()
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   532
  1s UdpEchoServerApplication:StartApplication()
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   533
  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
   534
  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
   535
  2.25732s Echoing packet
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   536
  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
   537
  10s UdpEchoServerApplication:StopApplication()
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   538
  UdpEchoServerApplication:DoDispose()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   539
  UdpEchoServerApplication:~UdpEchoServer()
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
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
   543
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
   544
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   545
@verbatim
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   546
  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
   547
@end verbatim
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   548
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   549
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
   550
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
   551
32768 bits per second from five megabits per second.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   552
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   553
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
   554
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
   555
the formula implied by the help item:
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   556
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   557
@verbatim
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   558
  ./waf --run "scratch/myfirst --ns3::PointToPointNetDevice::DataRate=5Mbps"
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   559
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   560
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   561
This will set the default value of the @code{DataRate} attribute back to 
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   562
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
   563
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
   564
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
   565
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
   566
the net device:
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   567
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   568
@verbatim
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   569
  ./waf --run "scratch/myfirst --PrintAttributes=ns3::PointToPointChannel"
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   570
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   571
3348
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   572
We discover the @code{Delay} attribute of the channel is set in the following
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   573
way:
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   574
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   575
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   576
  --ns3::PointToPointChannel::Delay=[0ns]:
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   577
    Transmission delay through the channel
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   578
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   579
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   580
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
   581
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   582
@verbatim
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   583
  ./waf --run "scratch/myfirst
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   584
    --ns3::PointToPointNetDevice::DataRate=5Mbps
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   585
    --ns3::PointToPointChannel::Delay=2ms"
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   586
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   587
3348
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   588
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
   589
@code{DataRate} and @code{Delay} in the script:
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   590
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   591
@verbatim
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   592
  Entering directory `/home/craigdo/repos/ns-3-allinone-dev/ns-3-dev/build'
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   593
  Build finished successfully (00:00:00)
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   594
  0s UdpEchoServerApplication:UdpEchoServer()
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   595
  1s UdpEchoServerApplication:StartApplication()
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   596
  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
   597
  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
   598
  2.00369s Echoing packet
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   599
  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
   600
  10s UdpEchoServerApplication:StopApplication()
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   601
  UdpEchoServerApplication:DoDispose()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   602
  UdpEchoServerApplication:~UdpEchoServer()
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
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   605
Note that the packet is again received by the server at 2.00369 seconds.  We 
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   606
could actually set any of the attributes used in the script in this way.  In
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   607
particular we could set the @code{UdpEchoClient} attribute @code{MaxPackets} 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   608
to some other value than one.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   609
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   610
How would you go about that?  Give it a try.  Remember you have to comment 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   611
out the place we override the default attribute in the script.  Then you 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   612
have to rebuild the script using the default.  You will also have to find the
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   613
syntax for actually setting the new default atribute value using the command
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   614
line help facility.  Once you have this figured out you should be able to
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   615
control the number of packets echoed from the command line.  Since we're nice
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   616
folks, we'll tell you that your command line should end up looking something
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   617
like,
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   618
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   619
@verbatim
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   620
  ./waf --run "scratch/myfirst 
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   621
    --ns3::PointToPointNetDevice::DataRate=5Mbps 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   622
    --ns3::PointToPointChannel::Delay=2ms 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   623
    --ns3::UdpEchoClient::MaxPackets=2"
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   624
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   625
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   626
@subsection Hooking Your Own Values
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   627
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
   628
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
   629
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   630
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
   631
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
   632
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
   633
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
   634
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
   635
@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
   636
start with the following code,
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   637
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   638
@verbatim
3771
21f40ccb03b3 tutorial typos fixed (bug 379)
Tom Henderson <tomh@tomh.org>
parents: 3382
diff changeset
   639
  int
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   640
  main (int argc, char *argv[])
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   641
  {
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   642
    uint32_t nPackets = 1;
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
    CommandLine cmd;
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   645
    cmd.AddValue("nPackets", "Number of packets to echo", nPackets);
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   646
    cmd.Parse (argc, argv);
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
    ...
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   649
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   650
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   651
Scroll down to the point in the script where we set the @code{MaxPackets}
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   652
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
   653
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
   654
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   655
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   656
  echoClient.SetAppAttribute ("MaxPackets", UintegerValue (nPackets));
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   657
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   658
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   659
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
   660
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
   661
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   662
Try,
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   663
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   664
@verbatim
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   665
  ./waf --run "scratch/myfirst --PrintHelp"
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   666
@end verbatim
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   667
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   668
@verbatim
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   669
  Entering directory `/home/craigdo/repos/ns-3-allinone-dev/ns-3-dev/build'
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   670
  Build finished successfully (00:00:00)
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   671
  --PrintHelp: Print this help message.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   672
  --PrintGroups: Print the list of groups.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   673
  --PrintTypeIds: Print all TypeIds.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   674
  --PrintGroup=[group]: Print all TypeIds of group.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   675
  --PrintAttributes=[typeid]: Print all attributes of typeid.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   676
  --PrintGlobals: Print the list of globals.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   677
  User Arguments:
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   678
      --nPackets: Number of packets to echo
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   679
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   680
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   681
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
   682
setting the @code{--nPackets} argument in the command line,
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   683
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   684
@verbatim
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   685
  ./waf --run "scratch/myfirst --nPackets=2"
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   686
@end verbatim
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   687
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   688
You should now see
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   689
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   690
@verbatim
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   691
  Entering directory `/home/craigdo/repos/ns-3-allinone-dev/ns-3-dev/build'
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   692
  Build finished successfully (00:00:00)
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   693
  0s UdpEchoServerApplication:UdpEchoServer()
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   694
  1s UdpEchoServerApplication:StartApplication()
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   695
  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
   696
  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
   697
  2.25732s Echoing packet
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   698
  Received 1024 bytes from 10.1.1.2
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   699
  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
   700
  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
   701
  3.25732s Echoing packet
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   702
  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
   703
  10s UdpEchoServerApplication:StopApplication()
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   704
  UdpEchoServerApplication:DoDispose()
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   705
  UdpEchoServerApplication:~UdpEchoServer()
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   706
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   707
3348
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   708
You have now echoed two packets.
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   709
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   710
You can see that if you are an @command{ns-3} user, you can use the command 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   711
line argument system to control global values and attributes.  If you are a 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   712
model author, you can add new attributes to your Objects and they will 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   713
automatically be available for setting by your users through the command line
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   714
system.  If you are a script author, you can add new variables to your scripts
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   715
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
   716
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   717
@c ========================================================================
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   718
@c Using the Tracing System
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   719
@c ========================================================================
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   720
@node Using the Tracing System
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   721
@section Using the Tracing System
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   722
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   723
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
   724
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
   725
@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
   726
from C++ programs could be used:  
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   727
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   728
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   729
  #include <iostream>
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   730
  ...
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   731
  int main ()
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   732
  {
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   733
    ...
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   734
    std::cout << "The value of x is " << x << std::endl;
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   735
    ...
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
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   738
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   739
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
   740
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
   741
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
   742
issues we thought were important.
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   743
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   744
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
   745
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   746
@itemize @bullet
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   747
@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
   748
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
   749
generate the tracing;
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   750
@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
   751
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
   752
modifying the core of the simulator;
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   753
@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
   754
and sinks.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   755
@end itemize 
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
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
   758
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
   759
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
   760
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
   761
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
   762
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
   763
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   764
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
   765
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
   766
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
   767
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
   768
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
   769
out interesting parts of the received packet.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   770
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   771
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
   772
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
   773
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
   774
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
   775
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
   776
user script.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   777
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   778
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
   779
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
   780
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
   781
extending the tracing namespace and creating new tracing sources.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   782
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   783
@cindex tracing
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   784
@cindex ASCII tracing
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   785
@subsection ASCII Tracing
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   786
@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
   787
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
   788
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
   789
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
   790
@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
   791
generated by many scripts.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   792
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   793
@cindex tracing packets
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   794
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
   795
@code{scratch/myfirst.cc} script.  
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   796
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   797
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
   798
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
   799
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   800
@verbatim
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   801
  #include <fstream>
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   802
@end verbatim
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   803
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   804
Then, right before the before the call to @code{Simulator::Run ()}, add the
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   805
following lines of code.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   806
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   807
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   808
  std::ofstream ascii;
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   809
  ascii.open ("myfirst.tr");
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   810
  PointToPointHelper::EnableAsciiAll (ascii);
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   811
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   812
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   813
The first two lines are just vanilla C++ code to open a stream that will be
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   814
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
   815
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
   816
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
   817
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
   818
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
   819
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
   820
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
   821
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   822
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
   823
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   824
@verbatim
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   825
  ./waf --run scratch/myfirst
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   826
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   827
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   828
@cindex myfirst.tr
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   829
Just as you have seen many times before, you will see some messages from Waf and then
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   830
the ``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
   831
the running program.  
3348
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   832
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   833
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
   834
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
   835
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
   836
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
   837
@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
   838
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
   839
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
   840
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   841
@subsubsection Parsing Ascii Traces
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   842
@cindex parsing ascii traces
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   843
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
   844
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
   845
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
   846
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   847
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
   848
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
   849
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
   850
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
   851
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
   852
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
   853
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   854
@cindex ascii trace enqueue operation
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   855
@cindex ascii trace dequeue operation
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   856
@cindex ascii trace drop operation
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   857
@cindex ascii trace receive operation
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   858
@itemize @bullet
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   859
@item @code{+}: An enqueue operation occurred on the device queue;
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   860
@item @code{-}: A dequeue operation occurred on the device queue;
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   861
@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
   862
@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
   863
@end itemize
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   864
3348
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   865
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
   866
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
   867
number on the left side:
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   868
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   869
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   870
  00 + 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   871
  01 2 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   872
  02 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   873
  03 ns3::PppHeader (
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   874
  04   Point-to-Point Protocol: IP (0x0021)) 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   875
  05   ns3::Ipv4Header (
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   876
  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
   877
  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
   878
  08     ns3::UdpHeader (
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   879
  09       length: 1032 49153 > 9) 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   880
  10       Payload (size=1024)
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   881
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   882
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   883
@cindex trace event
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   884
@cindex simulation time
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   885
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
   886
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
   887
@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
   888
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
   889
@code{UdpEchoClientApplication} to start sending packets at two seconds.  Here
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   890
we see confirmation that this is, indeed, happening.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   891
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   892
@cindex node number
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   893
@cindex net device number
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   894
@cindex smart pointer
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   895
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
   896
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
   897
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
   898
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
   899
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
   900
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
   901
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
   902
@code{/NodeList/0} therefore refers to the zeroth node in the @code{NodeList}
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   903
which we typically think of as ``node 0.''  In each node there is a list of 
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   904
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
   905
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
   906
zeroth device installed in the node. 
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   907
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   908
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
   909
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
   910
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
   911
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
   912
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
   913
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   914
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
   915
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
   916
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
   917
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
   918
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
   919
that the payload is the expected 1024 bytes.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   920
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   921
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
   922
transmit queue on the same node. 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   923
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   924
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
   925
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
   926
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   927
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   928
  00 r 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   929
  01 2.25732 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   930
  02 /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/Rx 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   931
  03 ns3::PppHeader (
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   932
  04   Point-to-Point Protocol: IP (0x0021)) 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   933
  05   ns3::Ipv4Header (
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   934
  06     tos 0x0 ttl 64 id 0 offset 0 flags [none] 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   935
  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
   936
  08     ns3::UdpHeader (
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   937
  09       length: 1032 49153 > 9) 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   938
  10       Payload (size=1024)
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   939
@end verbatim
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
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
   942
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
   943
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
   944
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
   945
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
   946
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   947
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
   948
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
   949
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
   950
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
   951
traces in the file.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   952
3348
fe47da29d783 cleaning up tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3343
diff changeset
   953
@subsection PCAP Tracing
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   954
@cindex pcap
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   955
@cindex Wireshark
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   956
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
   957
@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
   958
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
   959
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
   960
read and display this format is Wireshark (formerly called Ethereal).
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   961
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
   962
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
   963
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
   964
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   965
@cindex pcap tracing
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   966
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
   967
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   968
@verbatim
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   969
  PointToPointHelper::EnablePcapAll ("myfirst");
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   970
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   971
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   972
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
   973
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
   974
``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
   975
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
   976
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
   977
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
   978
 and a ``.pcap'' suffix.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   979
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   980
In our example script, we will eventually see files named ``myfirst-0-0.pcap'' 
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   981
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
   982
node 1-device 0, respectively.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   983
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   984
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
   985
script in the usual way:
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   986
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   987
@verbatim
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
   988
  ./waf --run scratch/myfirst
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   989
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   990
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   991
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
   992
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
   993
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
   994
are the new pcap files we just generated.  
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   995
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   996
@subsubsection Reading output with tcpdump
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   997
@cindex tcpdump
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   998
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
   999
at the @code{pcap} files.  
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1000
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1001
@verbatim
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
  1002
  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
  1003
  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
  1004
  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
  1005
  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
  1006
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
  1007
  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
  1008
  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
  1009
  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
  1010
  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
  1011
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1012
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
  1013
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
  1014
echo packet is sent at 2 seconds into the simulation.  If you look at the
4293
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
  1015
second dump (@code{first-1-0.pcap}) you can see that packet being received
11a2cda6a096 clean up tutorial up through tweaking section
Craig Dowell <craigdo@ee.washington.edu>
parents: 4207
diff changeset
  1016
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
  1017
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
  1018
the client in the first dump at 2.514648 seconds.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1019
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1020
@subsubsection Reading output with Wireshark
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1021
@cindex Wireshark
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1022
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
  1023
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
  1024
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1025
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
  1026
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
  1027
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
  1028
@emph{packet sniffer}.