doc/tutorial/building-topologies.texi
author Craig Dowell <craigdo@ee.washington.edu>
Thu, 03 Jul 2008 17:37:32 -0700
changeset 3382 d5f8e5fae1c6
parent 3355 ea06eff669b3
child 3700 fa1c7b813873
permissions -rw-r--r--
fix bug 234 which changes required methods on helpers to constructor parameters. Update tutorial content to reflect. Change RemoteIpv4 attribute to RemoteAddress.
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 ========================================================================
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     7
@c PART:  Building Topologies
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     8
@c ========================================================================
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     9
@c The below chapters are under the major heading "Building Topologies"
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 ========================================================================
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    13
@c Building Topologies
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    14
@c ========================================================================
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    15
@node Building Topologies
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    16
@chapter Building Topologies
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
3344
1d2fe1f35250 a few section 8 nits
Tom Henderson <tomh@tomh.org>
parents: 3339
diff changeset
    19
* Building a Bus Network Topology::
1d2fe1f35250 a few section 8 nits
Tom Henderson <tomh@tomh.org>
parents: 3339
diff changeset
    20
* Building a Wireless Network Topology::
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    21
@end menu
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    22
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    23
@c ========================================================================
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    24
@c Building a Bus Network Topology
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
@c ========================================================================
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    26
@node Building a Bus Network Topology
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    27
@section Building a Bus Network Topology
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    29
@cindex topology
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
    30
@cindex bus network topology
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
    31
In this section we are going to expand our mastery of @command{ns-3} network 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
    32
devices and channels to cover an example of a bus network.  @command{Ns-3}
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
    33
provides a net device and channel we call CSMA (Carrier Sense Multiple Access).
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    34
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
    35
The @command{ns-3} CSMA device models a simple network in the spirit of 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
    36
Ethernet.  A real Ethernet uses CSMA/CD (Carrier Sense Multiple Access with 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
    37
Collision Detection) scheme with exponentially increasing backoff to contend 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
    38
for the shared transmission medium.  The @command{ns-3} CSMA device and 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
    39
channel models only a subset of this.
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    40
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    41
Just as we have seen point-to-point topology helper objects when constructing
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    42
point-to-point topologies, we will see equivalent CSMA topology helpers in
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    43
this section.  The appearance and operation of these helpers should look 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    44
quite familiar to you.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    46
We provide an example script in our @code{examples} directory.  This script
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    47
builds on the @code{first.cc} script and adds a CSMA network to the 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    48
point-to-point simulation we've already considered.  Go ahead and open 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    49
@code{examples/second.cc} in your favorite editor.  You will have already seen
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
    50
enough @command{ns-3} code to understand most of what is going on in this 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
    51
example, but we will go over the entire script and examine some of the output.
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    52
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    53
Just as in the @code{first.cc} example (and in all ns-3 examples) the file
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    54
begins with an emacs mode line and some GPL boilerplate.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    55
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    56
One thing that can be surprisingly useful is a small bit of ASCII art that
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    57
shows a cartoon of the network topology constructed in the example.  You will
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    58
find a similar ``drawing'' in most of our examples.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    59
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    60
In this case, you can see that we are going to extend our point-to-point
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    61
example (the link between the nodes n0 and n1 below) by hanging a bus network
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    62
off of the right side.  Notice that this is the default network topology 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    63
since you can actually vary the number of nodes created on the LAN.  If you
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    64
set nCsma to one, there will be a total of two nodes on the LAN (CSMA 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    65
channel) --- one required node and one ``extra'' node.  By default there are
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    66
thee ``extra'' nodes as seen below:
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    68
@verbatim
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    69
// Default Network Topology
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    70
//
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    71
//       10.1.1.0
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    72
// n0 -------------- n1   n2   n3   n4
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    73
//    point-to-point  |    |    |    |
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    74
//                    ================
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    75
//                      LAN 10.1.2.0
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    76
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    77
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    78
The actual code begins by loading module include files just as was done in the
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    79
@code{first.cc} example.  Then the ns-3 namespace is @code{used} and a logging
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    80
component is defined.  This is all just as it was in @code{first.cc}, so there
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    81
is nothing new yet.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    82
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    83
@verbatim
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    84
  #include "ns3/core-module.h"
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    85
  #include "ns3/simulator-module.h"
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    86
  #include "ns3/node-module.h"
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    87
  #include "ns3/helper-module.h"
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    88
  #include "ns3/global-routing-module.h"
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    89
  
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    90
  using namespace ns3;
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    91
  
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    92
  NS_LOG_COMPONENT_DEFINE ("SecondScriptExample");
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    93
@end verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    94
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    95
The main program begins by enabling the @code{UdpEchoClientApplication} and
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    96
@code{UdpEchoServerApplication} logging components at @code{INFO} level so
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    97
we can see some output when we run the example.  This should be entirely 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    98
familiar to you so far.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    99
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   100
@verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   101
  int
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   102
  main (int argc, char *argv[])
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   103
  {
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   104
    LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   105
    LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   106
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   107
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   108
Next, you will see some familiar code that will allow you to change the number
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   109
of devices on the CSMA network via command line argument.  We did something
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   110
similar when we allowed the number of packets sent to be changed in the section
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   111
on command line arguments.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   112
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   113
@verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   114
  uint32_t nCsma = 3;
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   115
  CommandLine cmd;
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   116
  cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma);
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   117
  cmd.Parse (argc,argv);
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   118
@end verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   119
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   120
The next step is to create two nodes that we will connect via the 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   121
point-to-point link.  The @code{NodeContainer} is used to do this just as was
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   122
done in @code{first.cc}.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   123
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   124
@verbatim
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   125
  NodeContainer p2pNodes;
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   126
  p2pNodes.Create (2);
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   127
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   128
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   129
Next, we delare another @code{NodeContainer} to hold the nodes that will be
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   130
part of the bus (CSMA) network.  First, we just instantiate the container
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   131
object itself.  
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   132
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   133
@verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   134
  NodeContainer csmaNodes;
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   135
  csmaNodes.Add (p2pNodes.Get (1));
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   136
  csmaNodes.Create (nCsma);
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   137
@end verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   138
3354
f11e4def3fc4 tweak, tweak the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3349
diff changeset
   139
The next line of code @code{Gets} the first node (as in having an index of one)
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   140
from the point-to-point node container and adds it to the container of nodes
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   141
that will get CSMA devices.  The node in question is going to end up with a 
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   142
point-to-point device @emph{and} a CSMA device.  We then create a number of 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   143
``extra'' nodes that compose the remainder of the CSMA network.
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   144
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   145
The next bit of code should be quite familiar by now.  We instantiate a
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   146
@code{PointToPointHelper} and set the associated default attributes so that
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   147
we create a five megabit per second transmitter on devices created using the
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   148
helper and a two millisecond delay on channels created by the helper.
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
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   151
  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: 3355
diff changeset
   152
  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: 3355
diff changeset
   153
  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   154
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   155
  NetDeviceContainer p2pDevices;
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   156
  p2pDevices = pointToPoint.Install (p2pNodes);
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   157
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   158
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   159
We then instantiate a @code{NetDeviceContainer} to keep track of the 
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   160
point-to-point net devices and we @code{Install} devices on the 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   161
point-to-point nodes.
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   162
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   163
We mentioned above that you were going to see a helper for CSMA devices and
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   164
channels, and the next lines introduce them.  The @code{CsmaHelper} works just
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   165
like a @code{PointToPointHelper}, but it creates and connects CSMA devices and
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   166
channels.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   167
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   168
@verbatim
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   169
  CsmaHelper csma;
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   170
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   171
  NetDeviceContainer csmaDevices;
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   172
  csmaDevices = csma.Install (csmaNodes);
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   173
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   174
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   175
Just as we created a @code{NetDeviceContainer} to hold the devices created by
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   176
the @code{PointToPointHelper} we create a @code{NetDeviceContainer} to hold 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   177
the devices created by our @code{CsmaHelper}.  We call the @code{Install} 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   178
method of the @code{CsmaHelper} to install the devices into the nodes of the
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   179
@code{csmaNodes NodeContainer}.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   180
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   181
We now have our nodes, devices and channels created, but we have no protocol
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   182
stacks present.  Just as in the @code{first.cc} script, we will use the
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   183
@code{InternetStackHelper} to install these stacks.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   184
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   185
@verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   186
  InternetStackHelper stack;
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   187
  stack.Install (p2pNodes.Get (0));
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   188
  stack.Install (csmaNodes);
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   189
@end verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   190
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   191
Recall that we took one of the nodes from the @code{p2pNodes} container and
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   192
added it to the @code{csmaNodes} container.  Thus we only need to install 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   193
the stacks on the remaining @code{p2pNodes} node, and all of the nodes in the
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   194
@code{csmaNodes} container to cover all of the nodes in the simulation.
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   195
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   196
Just as in the @code{first.cc} example script, we are going to use the 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   197
@code{Ipv4AddressHelper} to assign IP addresses to our device interfaces.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   198
First we use the network 10.1.1.0 to create the two addresses needed for our
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   199
two point-to-point devices.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   200
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   201
@verbatim
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   202
  Ipv4AddressHelper address;
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   203
  address.SetBase ("10.1.1.0", "255.255.255.0");
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   204
  Ipv4InterfaceContainer p2pInterfaces;
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   205
  p2pInterfaces = address.Assign (p2pDevices);
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   206
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   207
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   208
Recall that we save the created interfaces in a container to make it easy to
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   209
pull out addressing information later for use in setting up the applications.
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   210
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   211
We now need to assign IP addresses to our CSMA device interfaces.  The 
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   212
operation works just as it did for the point-to-point case, except we now
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   213
are performing the operation on a container that has a variable number of 
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   214
CSMA devices --- remember we made the number of CSMA devices changeable by 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   215
command line argument.  The CSMA devices will be associated with IP addresses 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   216
from network number 10.1.2.0 in this case, as seen below.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   217
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   218
@verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   219
  address.SetBase ("10.1.2.0", "255.255.255.0");
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   220
  Ipv4InterfaceContainer csmaInterfaces;
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   221
  csmaInterfaces = address.Assign (csmaDevices);
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   222
@end verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   223
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   224
Now we have a topology built, but we need applications.  This section is
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   225
going to be fundamentally similar to the applications section of 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   226
@code{first.cc} but we are going to instantiate the server on one of the 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   227
nodes that has a CSMA node and the client on the node having only a 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   228
point-to-point device.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   229
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: 3355
diff changeset
   230
First, we set up the echo server.  We create a @code{UdpEchoServerHelper} and
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: 3355
diff changeset
   231
provide a required attribute value to the constructor which is the server port
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: 3355
diff changeset
   232
number.  Recall that this port can be changed later using the 
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: 3355
diff changeset
   233
@code{SetAttribute} method if desired, but we require it to be provided to
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: 3355
diff changeset
   234
the constructor.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   235
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   236
@verbatim
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: 3355
diff changeset
   237
  UdpEchoServerHelper echoServer (9);
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: 3355
diff changeset
   238
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   239
  ApplicationContainer serverApps = echoServer.Install (csmaNodes.Get (nCsma));
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   240
  serverApps.Start (Seconds (1.0));
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   241
  serverApps.Stop (Seconds (10.0));
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   242
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   243
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   244
Recall that the @code{csmaNodes NodeContainer} contains one of the 
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   245
nodes created for the point-to-point network and @code{nCsma} ``extra'' nodes. 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   246
What we want to get at is the last of the ``extra'' nodes.  The zeroth entry of
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   247
the @code{csmaNodes} container will the the point-to-point node.  The easy
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   248
way to think of this, then, is if we create one ``extra'' CSMA node, then it
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   249
will be be at index one of the @code{csmaNodes} container.  By induction,
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   250
if we create @code{nCsma} ``extra'' nodes the last one will be at index 
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   251
@code{nCsma}.  You see this exhibited in the @code{Get} of the first line of 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   252
code.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   253
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   254
The client application is set up exactly as we did in the @code{first.cc}
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: 3355
diff changeset
   255
example script.  Again, we provide required attributes to the 
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: 3355
diff changeset
   256
@code{UdpEchoClientHelper} in the constructor (in this case the remote address
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: 3355
diff changeset
   257
and port).  We tell the client to send packets to the server we just installed
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: 3355
diff changeset
   258
on the last of the ``extra'' CSMA nodes.  We install the client on the 
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: 3355
diff changeset
   259
leftmost point-to-point node seen in the topology illustration.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   260
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   261
@verbatim
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: 3355
diff changeset
   262
  UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (nCsma), 9);
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: 3355
diff changeset
   263
  echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
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: 3355
diff changeset
   264
  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
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: 3355
diff changeset
   265
  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   266
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   267
  ApplicationContainer clientApps = echoClient.Install (p2pNodes.Get (0));
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   268
  clientApps.Start (Seconds (2.0));
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   269
  clientApps.Stop (Seconds (10.0));
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   270
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   271
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   272
Since we have actually built an internetwork here, we need some form of 
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   273
internetwork routing.  @command{Ns-3} provides what we call a global route 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   274
manager to set up the routing tables on nodes.  This route manager has a 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   275
global function that runs though the nodes created for the simulation and does
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   276
the hard work of setting up routing for you.  
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   277
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   278
Basically, what happens is that each node behaves as if it were an OSPF router
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   279
that communicates instantly and magically with all other routers behind the
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   280
scenes.  Each node generates link advertisements and communicates them 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   281
directly to a global route manager which uses this global information to 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   282
construct the routing tables for each node.  Setting up this form of routing
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   283
is a one-liner:
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   284
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   285
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   286
  GlobalRouteManager::PopulateRoutingTables ();
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   287
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   288
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   289
The remainder of the script should be very familiar to you.  We just enable
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   290
pcap tracing, run the simulation and exit the script.  Notice that enabling
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   291
pcap tracing using the CSMA helper is done in the same way as for the pcap
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   292
tracing with the point-to-point helper.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   293
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   294
@verbatim
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   295
    PointToPointHelper::EnablePcapAll ("second");
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   296
    CsmaHelper::EnablePcapAll ("second");
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   297
  
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   298
    Simulator::Run ();
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   299
    Simulator::Destroy ();
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   300
    return 0;
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   301
  }
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   302
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   303
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   304
In order to run this example, you have to copy the @code{second.cc} example
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   305
script into the scratch directory and use Waf to build just as you did with
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   306
the @code{first.cc} example.  If you are in the top-level directory of the
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   307
repository you would type,
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   308
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   309
@verbatim
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   310
  cp examples/second.cc scratch/
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   311
  ./waf
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   312
  ./waf --run scratch/second
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   313
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   314
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   315
Since we have set up the UDP echo applications to log just as we did in 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   316
@code{first.cc}, you will see similar output when you run the script.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   317
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   318
@verbatim
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   319
  ~/repos/ns-3-dev > ./waf --run scratch/second
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   320
  Entering directory `/home/craigdo/repos/ns-3-dev/build'
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   321
  Compilation finished successfully
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   322
  Sent 1024 bytes to 10.1.2.4
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   323
  Received 1024 bytes from 10.1.1.1
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   324
  Received 1024 bytes from 10.1.2.4
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   325
  ~/repos/ns-3-dev >
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   326
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   327
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   328
Recall that the first message, @code{Sent 1024 bytes to 10.1.2.4} is the 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   329
UDP echo client sending a packet to the server.  In this case, the server
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   330
is on a different network (10.1.2.0).  The second message, @code{Received 1024 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   331
bytes from 10.1.1.1}, is from the UDP echo server, generated when it receives
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   332
the echo packet.  The final message, @code{Received 1024 bytes from 10.1.2.4}
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   333
is from the echo client, indicating that it has received its echo back from
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   334
the server.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   335
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   336
If you now go and look in the top level directory, you will find a number of
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   337
trace files:
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   338
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   339
@verbatim
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   340
  ~/repos/ns-3-dev > ls *.pcap
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   341
  second-0-0.pcap  second-1-1.pcap  second-3-0.pcap
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   342
  second-1-0.pcap  second-2-0.pcap  second-4-0.pcap
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   343
  ~/repos/ns-3-dev >
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   344
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   345
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   346
Let's take a moment to look at the naming of these files.  They all have the 
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   347
same form, @code{<name>-<node>-<device>.pcap}.  For example, the first file
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   348
in the listing is @code{second-0-0.pcap} which is the pcap trace from node 
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   349
zero - device zero.  There are no other devices on node zero so this is the
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   350
only trace from that node.  
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   351
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   352
Now look at @code{second-1-0.pcap} and @code{second-1-1.pcap}.  The former is
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   353
the pcap trace for device zero on node one and the latter is the trace file 
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   354
for device one on node one.  If you refer back to the topology illustrration at
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   355
the start of the section, you will see that node one is the node that has
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   356
both a point-to-point device and a CSMA device, so we should expect two pcap
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   357
traces for that node.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   358
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   359
Now, let's follow the echo packet through the internetwork.  First, do a 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   360
tcpdump of the trace file for the leftmost point-to-point node --- node zero.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   361
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   362
@verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   363
  ~/repos/ns-3-dev > tcpdump -r second-0-0.pcap -nn -tt
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   364
  reading from file second-0-0.pcap, link-type PPP (PPP)
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   365
  2.000000 IP 10.1.1.1.49153 > 10.1.2.4.9: UDP, length 1024
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   366
  2.007382 IP 10.1.2.4.9 > 10.1.1.1.49153: UDP, length 1024
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   367
  ~/repos/ns-3-dev >
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   368
@end verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   369
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   370
The first line of the dump indicates that the link type is PPP (point-to-point)
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   371
which we expect.  You then see the echo packet leaving node zero via the 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   372
device associated with IP address 10.1.1.1 headed for IP address
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   373
10.1.2.4 (the rightmost CSMA node).  This packet will move over the 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   374
point-to-point link and be received by the point-to-point net device on node 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   375
one.  Let's take a look:
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   376
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   377
@verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   378
  ~/repos/ns-3-dev > tcpdump -r second-1-0.pcap -nn -tt
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   379
  reading from file second-1-0.pcap, link-type PPP (PPP)
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   380
  2.003686 IP 10.1.1.1.49153 > 10.1.2.4.9: UDP, length 1024
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   381
  2.003695 IP 10.1.2.4.9 > 10.1.1.1.49153: UDP, length 1024
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   382
  ~/repos/ns-3-dev >
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   383
@end verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   384
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   385
Here we see that the link type is also PPP as we would expect.  You see the
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   386
packet from IP address 10.1.1.1 headed toward 10.1.2.4 appear on this 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   387
interface.  Now, internally to this node, the packet will be forwarded to the
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   388
CSMA interface and we should see it pop out the other device headed for its
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   389
ultimate destination.  Let's then look at second-1-1.pcap and see if its there.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   390
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   391
@verbatim
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   392
  ~/repos/ns-3-dev > tcpdump -r second-1-1.pcap -nn -tt
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   393
  reading from file second-1-1.pcap, link-type EN10MB (Ethernet)
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   394
  2.003686 arp who-has 10.1.2.4 (ff:ff:ff:ff:ff:ff) tell 10.1.2.1
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   395
  2.003687 arp reply 10.1.2.4 is-at 00:00:00:00:00:06
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   396
  2.003687 IP 10.1.1.1.49153 > 10.1.2.4.9: UDP, length 1024
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   397
  2.003691 arp who-has 10.1.2.1 (ff:ff:ff:ff:ff:ff) tell 10.1.2.4
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   398
  2.003691 arp reply 10.1.2.1 is-at 00:00:00:00:00:03
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   399
  2.003695 IP 10.1.2.4.9 > 10.1.1.1.49153: UDP, length 1024
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   400
  ~/repos/ns-3-dev >
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   401
@end verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   402
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   403
As you can see, the link type is now ``Ethernet.''  Something new has appeared,
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   404
though.  The bus network needs @code{ARP}, the Address Resolution Protocol.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   405
The node knows it needs to send the packet to IP address 10.1.2.4, but it
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   406
doesn't know the MAC address of the corresponding node.  It broadcasts on the
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   407
CSMA network (ff:ff:ff:ff:ff:ff) asking for the device that has IP address
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   408
10.1.2.4.  In this case, the rightmost node replies saying it is at MAC address
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   409
00:00:00:00:00:06.  This exchange is seen in the following lines,
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   410
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   411
@verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   412
  2.003686 arp who-has 10.1.2.4 (ff:ff:ff:ff:ff:ff) tell 10.1.2.1
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   413
  2.003687 arp reply 10.1.2.4 is-at 00:00:00:00:00:06
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   414
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   415
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   416
Then node one, device one goes ahead and sends the echo packet to the UDP echo
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   417
server at IP address 10.1.2.4.  We can now look at the pcap trace for the 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   418
echo server,
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   419
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   420
@verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   421
  ~/repos/ns-3-dev > tcpdump -r second-4-0.pcap -nn -tt
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   422
  reading from file second-4-0.pcap, link-type EN10MB (Ethernet)
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   423
  2.003686 arp who-has 10.1.2.4 (ff:ff:ff:ff:ff:ff) tell 10.1.2.1
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   424
  2.003686 arp reply 10.1.2.4 is-at 00:00:00:00:00:06
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   425
  2.003690 IP 10.1.1.1.49153 > 10.1.2.4.9: UDP, length 1024
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   426
  2.003690 arp who-has 10.1.2.1 (ff:ff:ff:ff:ff:ff) tell 10.1.2.4
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   427
  2.003692 arp reply 10.1.2.1 is-at 00:00:00:00:00:03
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   428
  2.003692 IP 10.1.2.4.9 > 10.1.1.1.49153: UDP, length 1024
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   429
  ~/repos/ns-3-dev >
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   430
@end verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   431
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   432
Again, you see that the link type is ``Ethernet.''  The first two entries are
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   433
the ARP exchange we just explained.  The third packet is the echo packet 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   434
being delivered to its final destination.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   435
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   436
The echo server turns the packet around and needs to send it back to the echo
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   437
client on 10.1.1.1 but it knows that this address is on another network that 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   438
it reaches via IP address 10.1.2.1.  This is because we initialized global
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   439
routing and it has figured all of this out for us.  But, the echo server node
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   440
doesn't know the MAC address of the first CSMA node, so it has to ARP for it
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   441
just like the first CSMA node had to do.  We leave it as an exercise for you
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   442
to find the entries corresponding to the packet returning back on its way to
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   443
the client (we have already dumped the traces and you can find them in those
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   444
tcpdumps above.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   445
3337
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   446
Let's take a look at one of the CSMA nodes that wasn't involved in the packet 
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   447
exchange:
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   448
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   449
@verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   450
  ~/repos/ns-3-dev > tcpdump -r second-2-0.pcap -nn -tt
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   451
  reading from file second-2-0.pcap, link-type EN10MB (Ethernet)
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   452
  2.003686 arp who-has 10.1.2.4 (ff:ff:ff:ff:ff:ff) tell 10.1.2.1
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   453
  2.003691 arp who-has 10.1.2.1 (ff:ff:ff:ff:ff:ff) tell 10.1.2.4
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   454
  ~/repos/ns-3-dev >
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   455
@end verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   456
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   457
You can see that the CSMA channel is a broadcast medium and so all of the 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   458
devices see the ARP requests involved in the packet exchange.  The remaining
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   459
pcap trace will be identical to this one.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   460
3337
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   461
Finally, recall that we added the ability to control the number of CSMA devices
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   462
in the simulation by command line argument.  You can change this argument in
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   463
the same way as when we looked at changing the number of packets echoed in the
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   464
@code{first.cc} example.  Try setting the number of ``extra'' devices to four:
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   465
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   466
@verbatim
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   467
  ~/repos/ns-3-dev > ./waf --run "scratch/second --nCsma=4"
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   468
  Entering directory `/home/craigdo/repos/ns-3-dev/build'
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   469
  Compilation finished successfully
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   470
  Sent 1024 bytes to 10.1.2.5
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   471
  Received 1024 bytes from 10.1.1.1
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   472
  Received 1024 bytes from 10.1.2.5
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   473
  ~/repos/ns-3-dev >
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   474
@end verbatim
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   475
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   476
Notice that the echo server has now been relocated to the last of the CSMA
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   477
nodes, which is 10.1.2.5 instead of the default case, 10.1.2.4.  You can 
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   478
increase the number to your hearts content, but remember that you will get a
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   479
pcap trace file for every node in the simulation.  One thing you can do to
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   480
keep from getting all of those pcap traces with nothing but ARP exchanges in 
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   481
them is to be more specific about which nodes and devices you want to trace.
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   482
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   483
Let's take a look at @code{scratch/second.cc} and add that code enabling us
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   484
to be more specific.  The file we provided used the @code{EnablePcapAll} 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   485
methods of the helpers to enable pcap on all devices.  We now want to use the
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   486
more specific method, @code{EnablePcap}, which takes a node number and device
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   487
number as parameters.  Go ahead and replace the @code{EnablePcapAll} calls 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   488
with the calls below.
3337
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   489
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   490
@verbatim
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   491
  PointToPointHelper::EnablePcap ("second", p2pNodes.Get (0)->GetId (), 0);
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   492
  CsmaHelper::EnablePcap ("second", csmaNodes.Get (nCsma)->GetId (), 0);
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   493
@end verbatim
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   494
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   495
We know that we want to create a pcap file with the base name "second" and
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   496
we also know that the device of interest in both cases is going to be zero,
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   497
so those parameters are not really interesting.  In order to get the node
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   498
number, you have two choices:  first, nodes are numbered in a monotonically
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   499
increasing fashion starting from zero in the order in which you created them.
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   500
One way to get a node number is to figure this number out ``manually'' by
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   501
contemplating the order of node creation.  If you take a look at the network 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   502
topology illustration at the beginning of the file, we did this for you and
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   503
you can see that the last CSMA node is going to be node number 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   504
@code{nCsma + 1}.  This approach can become annoyingly difficult in larger 
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   505
simulations.  
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   506
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   507
An alternate way, which we use here, is to realize that the
3354
f11e4def3fc4 tweak, tweak the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3349
diff changeset
   508
@code{NodeContainers} contain pointers to @command{ns-3} @code{Node} Objects.
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   509
The @code{Node} Object has a method called @code{GetId} which will return that
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   510
node's ID, which is the node number we seek.  Let's go take a look at the 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   511
Doxygen for the @code{Node} and locate that method, which is further down in 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   512
the @command{ns-3} core code than we've seen so far; but sometimes you have to
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   513
search diligently for useful things.
3337
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   514
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   515
Go to the Doxygen documentation for your release (recall that you can find it
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   516
on the project web site).  You can get to the @code{Node} documentation by
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   517
looking through at the ``Classes'' tab and scrolling down the ``Class List'' 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   518
until you find @code{ns3::Node}.  Select @code{ns3::Node} and you will be taken
3337
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   519
to the documentation for the @code{Node} class.  If you now scroll down to the
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   520
@code{GetId} method and select it, you will be taken to the detailed 
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   521
documentation for the method.  Using the @code{GetId} method can make 
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   522
determining node numbers much easier in complex topologies.
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   523
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   524
Now that we have got some trace filtering in place, it is reasonable to start
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   525
increasing the number of CSMA devices in our simulation.  If you build the 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   526
new script and run the simulation setting @code{nCsma} to 100, you will see 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   527
the following output:
3337
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   528
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   529
@verbatim
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   530
  ~/repos/ns-3-dev > ./waf --run "scratch/second --nCsma=100"
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   531
  Entering directory `/home/craigdo/repos/ns-3-dev/build'
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   532
  Compilation finished successfully
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   533
  Sent 1024 bytes to 10.1.2.101
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   534
  Received 1024 bytes from 10.1.1.1
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   535
  Received 1024 bytes from 10.1.2.101
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   536
  ~/repos/ns-3-dev >
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   537
@end verbatim
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   538
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   539
Note that the echo server is now located at 10.1.2.101 which corresponds to
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   540
having 100 ``extra'' CSMA nodes with the echo server on the last one.  If you
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   541
list the pcap files in the top level directory,
3337
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   542
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   543
@verbatim
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   544
  ~/repos/ns-3-dev > ls *.pcap
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   545
  second-0-0.pcap  second-101-0.pcap
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   546
  ~/repos/ns-3-dev >
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   547
@end verbatim
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   548
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   549
you will see that we have, in fact, only created two trace files.  The trace
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   550
file @code{second-0-0.pcap} is the ``leftmost'' point-to-point device which is
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   551
the echo packet source.  The file @code{second-101-0.pcap} corresponds to the
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   552
rightmost CSMA device which is where the echo server resides.
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   553
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   554
@c ========================================================================
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   555
@c Building a Wireless Network Topology
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   556
@c ========================================================================
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   557
@node Building a Wireless Network Topology
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   558
@section Building a Wireless Network Topology
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   559
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   560
@cindex topology
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   561
@cindex wireless network topology
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   562
In this section we are going to further expand our knowledge of @command{ns-3}
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   563
network devices and channels to cover an example of a wireless network.  
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   564
@command{Ns-3} provides a set of 802.11 models that attempt to provide an 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   565
accurate MAC-level implementation of the 802.11 specification and a 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   566
``not-so-slow'' PHY-level model of the 802.11a specification.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   567
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   568
Just as we have seen both point-to-point and CSMA topology helper objects when
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   569
constructing point-to-point topologies, we will see equivalent @code{Wifi}
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   570
topology helpers in this section.  The appearance and operation of these 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   571
helpers should look quite familiar to you.
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   572
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   573
We provide an example script in our @code{examples} directory.  This script
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   574
builds on the @code{second.cc} script and adds a Wifi network.  Go ahead and
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   575
open @code{examples/third.cc} in your favorite editor.  You will have already
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   576
seen enough @command{ns-3} code to understand most of what is going on in 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   577
this example, but there are a few new things, so we will go over the entire 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   578
script and examine some of the output.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   579
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   580
Just as in the @code{second.cc} example (and in all @command{ns-3} examples)
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   581
the file begins with an emacs mode line and some GPL boilerplate.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   582
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   583
Take a look at the ASCII art (reproduced below) that shows the default network
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   584
topology constructed in the example.  You can see that we are going to 
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   585
further extend our example by hanging a wireless network off of the left side.
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   586
Notice that this is a default network topology since you can actually vary the
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   587
number of nodes created on the wired and wireless networks.  Just as in the 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   588
@code{second.cc} script case, if you change @code{nCsma}, it will give you a 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   589
number of ``extra'' CSMA nodes.  Similarly, you can set @code{nWifi} to 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   590
control how many @code{STA} (station) nodes are created in the simulation.
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   591
There will always be one @code{AP} (access point) node on the wireless 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   592
network.  By default there are thee ``extra'' CSMA nodes and three wireless 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   593
@code{STA} nodes.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   594
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   595
The code begins by loading module include files just as was done in the
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   596
@code{second.cc} example.  There are a couple of new includes corresponding
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   597
to the Wifi module and the mobility module which we will discuss below.
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   598
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   599
@verbatim
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   600
#include "ns3/core-module.h"
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   601
#include "ns3/simulator-module.h"
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   602
#include "ns3/node-module.h"
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   603
#include "ns3/helper-module.h"
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   604
#include "ns3/global-routing-module.h"
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   605
#include "ns3/wifi-module.h"
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   606
#include "ns3/mobility-module.h"
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   607
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   608
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   609
The network topology illustration follows:
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   610
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   611
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   612
  // Default Network Topology
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   613
  //
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   614
  //   Wifi 10.1.3.0
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   615
  //                 AP
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   616
  //  *    *    *    *
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   617
  //  |    |    |    |    10.1.1.0
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   618
  // n5   n6   n7   n0 -------------- n1   n2   n3   n4
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   619
  //                   point-to-point  |    |    |    |
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   620
  //                                   ================
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   621
  //                                     LAN 10.1.2.0
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   622
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   623
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   624
You can see that we are adding a new network device to the node on the left 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   625
side of the point-to-point link that becomes the access point for the wireless
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   626
network.  A number of wireless STA nodes are created to fill out the new 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   627
10.1.3.0 network as shown on the left side of the illustration.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   628
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   629
After the illustration, the @code{ns-3} namespace is @code{used} and a logging
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   630
component is defined.  This should all be quite familiar by now.
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   631
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   632
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   633
  using namespace ns3;
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   634
  
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   635
  NS_LOG_COMPONENT_DEFINE ("ThirdScriptExample");
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   636
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   637
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   638
As has become the norm in this tutorial, the main program begins by enabling
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   639
the @code{UdpEchoClientApplication} and @code{UdpEchoServerApplication} 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   640
logging components at @code{INFO} level so we can see some output when we run
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   641
the simulation.
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   642
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   643
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   644
  int
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   645
  main (int argc, char *argv[])
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   646
  {
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   647
    LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   648
    LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   649
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   650
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   651
Next, you will see more familiar code that will allow you to change the number
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   652
of devices on the CSMA and Wifi networks via command line argument.
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   653
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   654
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   655
  uint32_t nCsma = 3;
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   656
  uint32_t nWifi = 3;
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   657
  CommandLine cmd;
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   658
  cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma);
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   659
  cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi);
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   660
  cmd.Parse (argc,argv);
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   661
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   662
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   663
Just as in all of the previous examples, the next step is to create two nodes
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   664
that we will connect via the point-to-point link.  
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   665
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   666
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   667
  NodeContainer p2pNodes;
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   668
  p2pNodes.Create (2);
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   669
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   670
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   671
Next, we see an old friend.  We instantiate a @code{PointToPointHelper} and 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   672
set the associated default attributes so that we create a five megabit per 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   673
second transmitter on devices created using the helper and a two millisecond 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   674
delay on channels created by the helper.  We then @code{Intall} the devices
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   675
on the nodes and the channel between them.
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   676
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   677
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   678
  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: 3355
diff changeset
   679
  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: 3355
diff changeset
   680
  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   681
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   682
  NetDeviceContainer p2pDevices;
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   683
  p2pDevices = pointToPoint.Install (p2pNodes);
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   684
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   685
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   686
Next, we delare another @code{NodeContainer} to hold the nodes that will be
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   687
part of the bus (CSMA) network.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   688
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   689
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   690
  NodeContainer csmaNodes;
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   691
  csmaNodes.Add (p2pNodes.Get (1));
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   692
  csmaNodes.Create (nCsma);
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   693
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   694
3354
f11e4def3fc4 tweak, tweak the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3349
diff changeset
   695
The next line of code @code{Gets} the first node (as in having an index of one)
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   696
from the point-to-point node container and adds it to the container of nodes
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   697
that will get CSMA devices.  The node in question is going to end up with a 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   698
point-to-point device and a CSMA device.  We then create a number of ``extra''
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   699
nodes that compose the remainder of the CSMA network.
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   700
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   701
We then instantiate a @code{CsmaHelper} and a @code{NetDeviceContainer} to 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   702
keep track of the CSMA net devices.  Then we @code{Install} CSMA devices on 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   703
the selected nodes.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   704
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   705
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   706
  CsmaHelper csma;
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   707
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   708
  NetDeviceContainer csmaDevices;
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   709
  csmaDevices = csma.Install (csmaNodes);
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   710
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   711
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   712
Next, we are going to create the nodes that will be part of the Wifi network.
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   713
We are going to create a number of ``station'' nodes as specified by the 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   714
command line argument, and we are going to use the ``leftmost'' node of the 
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   715
point-to-point link as the node for the access point.
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   716
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   717
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   718
  NodeContainer wifiStaNodes;
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   719
  wifiStaNodes.Create (nWifi);
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   720
  NodeContainer wifiApNode = p2pNodes.Get (0);
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   721
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   722
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   723
The next bit of code is going to be quite different from the helper-based
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   724
topology generation we've seen so far, so we're going to take it line-by-line
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   725
for a while.  The next line of code you will see is:
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   726
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   727
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   728
  Ptr<WifiChannel> channel = CreateObject<WifiChannel> ();
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   729
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   730
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   731
Now, I'm not going to explain at this stage @emph{precisely} what this all
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   732
means, but hopefully with a very short digression I can give you enough 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   733
information so that this makes sense.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   734
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   735
C++ is an object oriented programming language.  @command{Ns-3} extends the
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   736
basic C++ object model to implement a number of nifty features.  We have seen
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   737
the @code{Attribute} system which is one of the major extensions we have 
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   738
implemented.  Another extension is to provide for relatively automatic memory 
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   739
management.  Like many systems, @command{ns-3} creates a base class called 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   740
@code{Object} that provides our extensions ``for free'' to other classes that
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   741
 inherit from our @code{class Object}.  
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   742
3344
1d2fe1f35250 a few section 8 nits
Tom Henderson <tomh@tomh.org>
parents: 3339
diff changeset
   743
In the code snippet above, the right hand side of the expression is a 
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   744
call to a templated C++ function called @code{CreateObject}.  The 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   745
@emph{template parameter} inside the angle brackets basically tells the 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   746
compiler what class it is we want to instantiate.  Our system returns a
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   747
@emph{smart pointer} to the object of the class that was created and assigns
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   748
it to the smart pointer named @code{channel} that is declared on the left 
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   749
hand side of the assignment.
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   750
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   751
The @command{ns-3} smart pointer is also template-based.  Here you see that 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   752
we declare a smart pointer to a @code{WifiChannel} which is the type of object
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   753
that was created in the @code{CreateObject} call.  The feature of immediate 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   754
interest here is that we are never going to have to delete the underlying C++
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   755
object.  It is handled automatically for us.  Nice, eh?
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   756
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   757
The idea to take away from this discussion is that this line of code creates
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   758
an @command{ns-3} @code{Object} that will automatically bring you the benefits
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   759
of the @command{ns-3} @code{Attribute} system we've seen previously.  The 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   760
resulting smart pointer works with the @code{Object} to perform memory 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   761
management automatically for you.  If you are interested in more details about
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   762
low level ns-3 code and exactly what it is doing, you are encouraged to 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   763
explore the ns-3 manual and our ``how-to'' documents.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   764
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   765
Now, back to the example.  The line of code above has created a wireless
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   766
@code{Wifi} channel.  This channel model requires that we create and attach 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   767
other models that describe various behaviors.  This provides an accomplished
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   768
user with even more opportunity to change the way the wireless network behaves
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   769
without changing the core code.
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   770
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   771
The first opportunity we have to change the behavior of the wireless network is
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   772
by providing a propagation delay model.  Again, I don't want to devolve this
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   773
tutorial into a manual on @code{Wifi}, but this model describes how the 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   774
electromagnetic signals are going to propagate.  We are going to create the 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   775
simplest model, the @code{ConstantSpeedPropagationDelayModel} that, by default,
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   776
has the signals propagating at a constant speed --- approximately that of the 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   777
speed of light in air.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   778
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   779
Recall that we created the @code{WifiChannel} and assigned it to a smart 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   780
pointer.  One of the features of a smart pointer is that you can use it
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   781
just as you would a ``normal'' C++ pointer.  The next line of code will
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   782
create a @code{ConstantSpeedPropagationDelayModel} using the 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   783
@code{CreateObject} template function and pass the resulting smart pointer
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   784
to the chanel model as an unnamed parameter of the 
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   785
@code{WifiChannel SetPropagationDelayModel} method.  In English, we create
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   786
a model for propagation speed of electromagnetic signals and tell the 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   787
wireless channel to use it.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   788
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   789
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   790
  channel->SetPropagationDelayModel (
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   791
    CreateObject<ConstantSpeedPropagationDelayModel> ());
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   792
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   793
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   794
The next lines of code use similar low-level @command{ns-3} methods to create
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   795
and set a ``propagation loss model'' for the channel.  
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   796
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   797
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   798
  Ptr<LogDistancePropagationLossModel> log =
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   799
    CreateObject<LogDistancePropagationLossModel> ();
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   800
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   801
  log->SetReferenceModel (CreateObject<FriisPropagationLossModel> ());
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   802
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   803
  channel->SetPropagationLossModel (log);
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   804
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   805
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   806
This snippet is used to tell the channel how it should calculate signal 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   807
attenuation of waves flowing in the channel.  The details of these calcuations
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   808
are beyond the scope of a tutorial.  You are encouraged to explore the Doxygen
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   809
documentation of classes @code{LogDistancePropagationLossModel} and
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   810
@code{FriisPropagationLossModel} if you are interested in the details.  As
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   811
usual, you will find the documentation in the ``Classes'' tab of the Doxygen 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   812
documentation.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   813
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   814
Now we will return to more familiar ground.  We next create a @code{WifiHelper}
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   815
object and set two default atributes that it will use when creating the actual
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   816
devices.
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   817
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   818
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   819
  WifiHelper wifi;
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   820
  wifi.SetPhy ("ns3::WifiPhy");
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   821
  wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   822
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   823
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   824
The @code{SetPhy} method tells the helper the type of physical layer class
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   825
we want it to instantiate when building @code{Wifi} devices.  In this case,  
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   826
the script is asking for physical layer models based on the YANS 802.11a 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   827
model.  Again, details are avialable in Doxygen.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   828
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   829
The @code{SetRemoteStationManager} method tells the helper the type of 
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   830
rate control algorithm to use.  Here, it is asking the helper to use the AARF
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   831
algorithm --- details are, of course, avialable in Doxygen.
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   832
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   833
Just as we can vary attributes describing the physical layer, we can do the
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   834
same for the MAC layer.
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   835
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   836
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   837
  Ssid ssid = Ssid ("ns-3-ssid");
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   838
  wifi.SetMac ("ns3::NqstaWifiMac",
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   839
    "Ssid", SsidValue (ssid),
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   840
    "ActiveProbing", BooleanValue (false));
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   841
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   842
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   843
This code first creates an 802.11 service set identifier (SSID) object that 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   844
will be used to set the value of the ``Ssid'' @code{Attribute} of the MAC
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   845
layer implementation.  The particular kind of MAC layer is specified by
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   846
@code{Attribute} as being of the "ns3::NqstaWifiMac" type.  This means that 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   847
the MAC will use a ``non-QoS station'' (nqsta) state machine.  Finally, the 
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   848
``ActiveProbing'' attribute is set to false.  This means that probe requests
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   849
will not be sent by MACs created by this helper.
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   850
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   851
Again, for the next lines of code we are back on familiar ground.  This code
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   852
will @code{Install} Wifi net devices on the nodes we have created as STA nodes
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   853
and will tie them to the @code{WifiChannel}.  Since we created the 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   854
@code{channel} manually rather than having the helper do it for us, we have to
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   855
pass it into the helper when we call the @code{Install} method.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   856
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   857
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   858
  NetDeviceContainer staDevices;
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   859
  staDevices = wifi.Install (wifiStaNodes, channel);
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   860
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   861
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   862
We have configured Wifi for all of our STA nodes, and now we need to 
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   863
configure the AP (access point) node.  We begin this process by changing
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   864
the default @code{Attributes} of the @code{WifiHelper} to reflect the 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   865
requirements of the AP.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   866
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   867
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   868
  wifi.SetMac ("ns3::NqapWifiMac", 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   869
    "Ssid", SsidValue (ssid),
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   870
    "BeaconGeneration", BooleanValue (true),
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   871
    "BeaconInterval", TimeValue (Seconds (2.5)));
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   872
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   873
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   874
In this case, the @code{WifiHelper} is going to create MAC layers of the 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   875
``ns3::NqapWifiMac'' (Non-Qos Access Point) type.  We set the 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   876
``BeaconGeneration'' attribute to true and also set an interval between 
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   877
beacons of 2.5 seconds.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   878
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   879
The next lines create the single AP and connect it to the channel in a
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   880
familiar way.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   881
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   882
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   883
  NetDeviceContainer apDevices;
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   884
  apDevices = wifi.Install (wifiApNode, channel);
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   885
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   886
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   887
Now, we are going to add mobility models.  We want the STA nodes to be mobile,
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   888
wandering around inside a bounding box, and we want to make the AP node 
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   889
stationary.  We use the @code{MobilityHelper} to make this easy for us.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   890
First, we instantiate a @code{MobilityHelper} obejct and set some attributes
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   891
controlling the ``position allocator'' functionality.
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   892
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   893
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   894
  MobilityHelper mobility;
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   895
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   896
  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   897
    "MinX", DoubleValue (0.0),
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   898
    "MinY", DoubleValue (0.0),
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   899
    "DeltaX", DoubleValue (5.0),
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   900
    "DeltaY", DoubleValue (10.0),
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   901
    "GridWidth", UintegerValue (3),
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   902
    "LayoutType", StringValue ("RowFirst"));
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   903
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   904
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   905
This code tells the mobility helper to use a two-dimensional grid to initially
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   906
place the STA nodes.  Feel free to explore the Doxygen for class 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   907
@code{ns3::GridPositionAllocator} to see exactly what is being done.
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   908
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   909
We have aranged our nodes on an initial grid, but now we need to tell them
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   910
how to move.  We choose the @code{RandomWalk2dMobilityModel} which has the 
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   911
nodes move in a random direction at a random speed around inside a bounding 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   912
box.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   913
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   914
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   915
  mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   916
    "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   917
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   918
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   919
We now tell the @code{MobilityHelper} to install the mobility models on the 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   920
STA nodes.
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   921
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   922
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   923
  mobility.Install (wifiStaNodes);
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   924
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   925
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
   926
We want the access point to remain in a fixed position during the simulation.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   927
We accomplish this by setting the mobility model for this node to be the 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   928
@code{ns3::StaticMobilityModel}:
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   929
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   930
@verbatim
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   931
  mobility.SetMobilityModel ("ns3::StaticMobilityModel");
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   932
  mobility.Install (wifiApNode);
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   933
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   934
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   935
We now have our nodes, devices and channels created, and mobility models 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   936
chosen for the Wifi nodes, but we have no protocol stacks present.  Just as 
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   937
we have done previously many times, we will use the @code{InternetStackHelper}
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   938
to install these stacks.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   939
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   940
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   941
  InternetStackHelper stack;
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   942
  stack.Install (csmaNodes);
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   943
  stack.Install (wifiApNode);
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   944
  stack.Install (wifiStaNodes);
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   945
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   946
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   947
Just as in the @code{second.cc} example script, we are going to use the 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   948
@code{Ipv4AddressHelper} to assign IP addresses to our device interfaces.
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   949
First we use the network 10.1.1.0 to create the two addresses needed for our
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   950
two point-to-point devices.  Then we use network 10.1.2.0 to assign addresses
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   951
the the CSMA network and then we assign addresses from network 10.1.3.0 to
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   952
both the STA devices and the AP on the wireless network.
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   953
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   954
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   955
  Ipv4AddressHelper address;
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   956
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   957
  address.SetBase ("10.1.1.0", "255.255.255.0");
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   958
  Ipv4InterfaceContainer p2pInterfaces;
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   959
  p2pInterfaces = address.Assign (p2pDevices);
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   960
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   961
  address.SetBase ("10.1.2.0", "255.255.255.0");
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   962
  Ipv4InterfaceContainer csmaInterfaces;
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   963
  csmaInterfaces = address.Assign (csmaDevices);
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   964
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   965
  address.SetBase ("10.1.3.0", "255.255.255.0");
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   966
  address.Assign (staDevices);
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   967
  address.Assign (apDevices);
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   968
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   969
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   970
We put the echo server on the ``rightmost'' node in the illustration at the
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   971
start of the file.  We have done this before.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   972
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   973
@verbatim
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: 3355
diff changeset
   974
  UdpEchoServerHelper echoServer (9);
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   975
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   976
  ApplicationContainer serverApps = echoServer.Install (csmaNodes.Get (nCsma));
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   977
  serverApps.Start (Seconds (1.0));
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   978
  serverApps.Stop (Seconds (10.0));
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   979
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   980
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   981
And we put the echo client on the last STA node we created, pointing it to
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   982
the server on the CSMA network.  We have also seen similar operations before.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   983
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   984
@verbatim
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: 3355
diff changeset
   985
  UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (nCsma), 9);
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: 3355
diff changeset
   986
  echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
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: 3355
diff changeset
   987
  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
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: 3355
diff changeset
   988
  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   989
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   990
  ApplicationContainer clientApps =
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   991
    echoClient.Install (wifiStaNodes.Get (nWifi - 1));
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   992
  clientApps.Start (Seconds (2.0));
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   993
  clientApps.Stop (Seconds (10.0));
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   994
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   995
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   996
Since we have built an internetwork here, we need enable internetwork routing
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
   997
just as we did in the @code{second.cc} example script.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   998
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
   999
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1000
  GlobalRouteManager::PopulateRoutingTables ();
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1001
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1002
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1003
One thing that can surprise some users is the fact that the simulation we just
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1004
created will never ``naturally'' stop.  This is because we asked the wireless
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1005
access point to generate beacons.  It will generate beacons forever, so we must
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1006
tell the simulator to stop even though it may have beacon generation events 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1007
scheduled.  The following line of code tells the simulator to stop so that 
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1008
we don't simulate beacons forever and enter what is essentially an endless
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1009
loop.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1010
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1011
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1012
  Simulator::Stop (Seconds (10.0));
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1013
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1014
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1015
We use the same trick as in the @code{second.cc} script to only generate 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1016
pcap traces from the nodes we find interesting.  Note that we use the same
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1017
``formula'' to get pcap tracing enabled on Wifi devices as we did on the
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1018
CSMA and point-to-point devices.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1019
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1020
@verbatim
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1021
  WifiHelper::EnablePcap ("third",
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1022
    wifiStaNodes.Get (nWifi - 1)->GetId (), 0);
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1023
  CsmaHelper::EnablePcap ("third",
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1024
    csmaNodes.Get (nCsma)->GetId (), 0);
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1025
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1026
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1027
Finally, we actually run the simulation, clean up and then exit the program.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1028
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1029
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1030
    Simulator::Run ();
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1031
    Simulator::Destroy ();
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1032
    return 0;
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1033
  }
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1034
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1035
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1036
In order to run this example, you have to copy the @code{third.cc} example
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1037
script into the scratch directory and use Waf to build just as you did with
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1038
the @code{second.cc} example.  If you are in the top-level directory of the
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1039
repository you would type,
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1040
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1041
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1042
  cp examples/third.cc scratch/
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1043
  ./waf
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1044
  ./waf --run scratch/third
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1045
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1046
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1047
Since we have set up the UDP echo applications just as we did in the 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1048
@code{second.cc} script, you will see similar output.
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1049
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1050
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1051
  ~/repos/ns-3-dev > ./waf --run scratch/third
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1052
  Entering directory `/home/craigdo/repos/ns-3-dev/build'
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1053
  Compilation finished successfully
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1054
  Sent 1024 bytes to 10.1.2.4
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1055
  Received 1024 bytes from 10.1.3.3
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1056
  Received 1024 bytes from 10.1.2.4
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1057
  ~/repos/ns-3-dev >
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1058
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1059
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1060
Recall that the first message, @code{Sent 1024 bytes to 10.1.2.4} is the 
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1061
UDP echo client sending a packet to the server.  In this case, the client
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1062
is on the wireless network (10.1.3.0).  The second message, 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1063
@code{Received 1024 bytes from 10.1.3.3}, is from the UDP echo server, 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1064
generated when it receives the echo packet.  The final message, 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1065
@code{Received 1024 bytes from 10.1.2.4} is from the echo client, indicating
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1066
that it has received its echo back from the server.
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1067
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1068
If you now go and look in the top level directory, you will find two trace 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1069
files:
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1070
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1071
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1072
  ~/repos/ns-3-dev > ls *.pcap
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1073
  third-4-0.pcap  third-7-0.pcap
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1074
  ~/repos/ns-3-dev >
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1075
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1076
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1077
The file ``third-4-0.pcap'' corresponds to the pcap trace for node four -
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1078
device zero.  This is the CSMA network node that acted as the echo server.
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1079
Take a look at the tcpdump for this device:
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1080
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1081
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1082
  ~/repos/ns-3-dev > tcpdump -r third-4-0.pcap -nn -tt
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1083
  reading from file third-4-0.pcap, link-type EN10MB (Ethernet)
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1084
  2.005855 arp who-has 10.1.2.4 (ff:ff:ff:ff:ff:ff) tell 10.1.2.1
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1085
  2.005855 arp reply 10.1.2.4 is-at 00:00:00:00:00:06
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1086
  2.005859 IP 10.1.3.3.49153 > 10.1.2.4.9: UDP, length 1024
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1087
  2.005859 arp who-has 10.1.2.1 (ff:ff:ff:ff:ff:ff) tell 10.1.2.4
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1088
  2.005861 arp reply 10.1.2.1 is-at 00:00:00:00:00:03
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1089
  2.005861 IP 10.1.2.4.9 > 10.1.3.3.49153: UDP, length 1024
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1090
  ~/repos/ns-3-dev >
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1091
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1092
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1093
This should be familiar and easily understood.  If you've forgotten, go back 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1094
and look at the discussion in @code{second.cc}.  This is the same sequence.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1095
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1096
Now, take a look at the other trace file, ``third-7-0.pcap.''  This is the
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1097
trace file for the wireless STA node that acts as the echo client.
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1098
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1099
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1100
  ~/repos/ns-3-dev > tcpdump -r third-7-0.pcap -nn -tt
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1101
  reading from file third-7-0.pcap, link-type IEEE802_11 (802.11)
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1102
  0.000146 Beacon (ns-3-ssid) ...
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1103
  H: 0
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1104
  0.000180 Assoc Request (ns-3-ssid) ...
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1105
  0.000336 Acknowledgment RA:00:00:00:00:00:07
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1106
  0.000454 Assoc Response AID(0) :: Succesful
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1107
  0.000514 Acknowledgment RA:00:00:00:00:00:0a
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1108
  0.000746 Assoc Request (ns-3-ssid) ...
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1109
  0.000902 Acknowledgment RA:00:00:00:00:00:09
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1110
  0.001020 Assoc Response AID(0) :: Succesful
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1111
  0.001036 Acknowledgment RA:00:00:00:00:00:0a
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1112
  0.001219 Assoc Request (ns-3-ssid) ...
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1113
  0.001279 Acknowledgment RA:00:00:00:00:00:08
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1114
  0.001478 Assoc Response AID(0) :: Succesful
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1115
  0.001538 Acknowledgment RA:00:00:00:00:00:0a
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1116
  2.000000 arp who-has 10.1.3.4 (ff:ff:ff:ff:ff:ff) tell 10.1.3.3
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1117
  2.000172 Acknowledgment RA:00:00:00:00:00:09
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1118
  2.000318 arp who-has 10.1.3.4 (ff:ff:ff:ff:ff:ff) tell 10.1.3.3
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1119
  2.000581 arp reply 10.1.3.4 is-at 00:00:00:00:00:0a
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1120
  2.000597 Acknowledgment RA:00:00:00:00:00:0a
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1121
  2.000693 IP 10.1.3.3.49153 > 10.1.2.4.9: UDP, length 1024
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1122
  2.002229 Acknowledgment RA:00:00:00:00:00:09
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1123
  2.009663 arp who-has 10.1.3.3 (ff:ff:ff:ff:ff:ff) tell 10.1.3.4
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1124
  2.009697 arp reply 10.1.3.3 is-at 00:00:00:00:00:09
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1125
  2.009869 Acknowledgment RA:00:00:00:00:00:09
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1126
  2.011487 IP 10.1.2.4.9 > 10.1.3.3.49153: UDP, length 1024
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1127
  2.011503 Acknowledgment RA:00:00:00:00:00:0a
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1128
  2.500112 Beacon[|802.11]
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1129
  5.000112 Beacon[|802.11]
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1130
  7.500112 Beacon[|802.11]
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1131
  ~/repos/ns-3-dev >
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1132
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1133
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1134
You can see that the link type is now 802.11 as you would expect.  We leave
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1135
it as an exercise to parse the dump and trace packets across the internetwork.
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1136
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1137
Now, we spent a lot of time setting up mobility models for the wireless network
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1138
and so it would be a shame to finish up without even showing that the STA
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1139
nodes are actually moving around.  Let's do this by hooking into the 
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1140
@code{MobilityModel} course change trace source.  This is usually considered
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1141
a fairly advanced topic, but let's just go for it.
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1142
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1143
As mentioned in the Tweaking Ns-3 section, the @command{ns-3} tracing system 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1144
is divided into trace sources and trace sinks, and we provide functions to 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1145
connect the two.  We will use the mobility model predefined course change 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1146
trace source to originate the trace events.  We will need to write a trace 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1147
sink to connect to that source that will display some pretty information for 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1148
us.  Despite its reputation as being difficult, it's really quite simple.
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1149
Just before the main program of the @code{scratch/third.cc} script, add the 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1150
following function:
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1151
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1152
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1153
  void
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1154
  CourseChange (std::string context, Ptr<const MobilityModel> model)
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1155
  {
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1156
    Vector position = model->GetPosition ();
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1157
    NS_LOG_UNCOND (context << 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1158
      " x = " << position.x << ", y = " << position.y);
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1159
  }
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1160
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1161
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
  1162
This code just pulls the position information from the mobility model and 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
  1163
unconditionally logs the x and y position of the node.  We are
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1164
going to arrange for this function to be called every time the wireless
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1165
node with the echo client changes its position.  We do this using the 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1166
@code{Config::Connect} function.  Add the following lines of code to the
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1167
script just before the @code{Simulator::Run} call.
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1168
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1169
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1170
  std::ostringstream oss;
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1171
  oss <<
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1172
    "/NodeList/" << wifiStaNodes.Get (nWifi - 1)->GetId () <<
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1173
    "/$ns3::MobilityModel/CourseChange";
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1174
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1175
  Config::Connect (oss.str (), MakeCallback (&CourseChange));
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1176
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1177
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1178
What we do here is to create a string containing the tracing namespace path
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
  1179
of the event to which we want to connect.  First, we have to figure out which 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
  1180
node it is we want using the @code{GetId} method as described earlier.  In the
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
  1181
case of the default number of CSMA and wireless nodes, this turns out to be 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
  1182
node seven and the tracing namespace path to the mobility model would look
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
  1183
like,
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1184
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1185
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1186
  /NodeList/7/$ns3::MobilityModel/CourseChange
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1187
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1188
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
  1189
Based on the discussion in the tracing section, you can easily infer that 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
  1190
this trace path references the seventh node in the NodeList.  It specifies
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
  1191
what is called an aggregated object of type @code{ns3::MobilityModel}.  The 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
  1192
dollar sign prefix implies that the MobilityModel is aggregated to node seven.
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
  1193
The last component of the path means that we are hooking into the 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
  1194
``CourseChange'' event of that model.  
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
  1195
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
  1196
We make a connection between the trace source in node seven with our trace 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
  1197
sink by calling @code{Config::Connect} and passing this namespace path.  Once 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
  1198
this is done, every course change event on node seven will be hooked into our 
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
  1199
trace sink, which will in turn print out the new position.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1200
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1201
If you now run the simulation, you will see the course changes displayed as 
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1202
they happen.
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1203
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1204
@verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1205
  ~/repos/ns-3-dev > ./waf --run scratch/third
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1206
  Entering directory `/home/craigdo/repos/ns-3-dev/build'
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1207
  Compilation finished successfully
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1208
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 10, y = 0
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1209
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 9.1304, y = 0.493761
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1210
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 8.70417, y = 1.39837
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1211
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 7.94799, y = 2.05274
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1212
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 8.82597, y = 1.57404
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1213
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 8.3003, y = 0.723347
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1214
  Sent 1024 bytes to 10.1.2.4
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1215
  Received 1024 bytes from 10.1.3.3
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1216
  Received 1024 bytes from 10.1.2.4
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1217
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 8.74083, y = 1.62109
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1218
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 9.00146, y = 0.655647
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1219
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 9.98731, y = 0.823279
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1220
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 9.50206, y = 1.69766
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1221
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 8.68108, y = 2.26862
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1222
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 9.25992, y = 1.45317
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1223
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 8.55655, y = 0.742346
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1224
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 8.21992, y = 1.68398
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1225
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 8.81273, y = 0.878638
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1226
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 7.83171, y = 1.07256
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1227
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 7.60027, y = 0.0997156
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1228
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 8.45367, y = 0.620978
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1229
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 7.68484, y = 1.26043
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1230
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 8.53659, y = 0.736479
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1231
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 9.51876, y = 0.548502
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1232
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 9.89778, y = 1.47389
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1233
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 8.98984, y = 1.893
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1234
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 9.91524, y = 1.51402
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1235
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 8.98761, y = 1.14054
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1236
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 8.16617, y = 0.570239
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1237
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 8.02954, y = 1.56086
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1238
  /NodeList/7/$ns3::MobilityModel/CourseChange x = 8.09551, y = 2.55868
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1239
  ~/repos/ns-3-dev >
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1240
@end verbatim
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1241
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1242
If you are feeling brave, there is a list of all trace sources in the 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1243
@command{ns-3} Doxygen which you can find in the ``NS-3 Modules'' section.  
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1244
Under the ``core'' section, you will find a link to ``The list of all trace 
3355
ea06eff669b3 some final tweaks to the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3354
diff changeset
  1245
sources.''  You may find it interesting to try and hook some of these 
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1246
traces yourself.  Additionally in the ``NS-3 Modules'' documentation, there is
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1247
a link to ``The list of all attributes.''  You can set the default value of 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1248
any of these atributes via the command line as we have previously discussed.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1249
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1250
We have just scratched the surface of @command{ns-3} in this tutorial, but we 
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1251
hope we have covered enough to get you started doing useful work.
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3337
diff changeset
  1252
3349
e6259dcffada more editing passes through tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3344
diff changeset
  1253
-- The @command{ns-3} development team.