doc/tutorial/building-topologies.texi
author Craig Dowell <craigdo@ee.washington.edu>
Sun, 29 Jun 2008 10:44:24 -0700
changeset 3337 6b297a1f231b
parent 3336 1bb6f018fc42
child 3339 ff29f4ba75ed
permissions -rw-r--r--
finish off csma tutorial example words
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
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    19
* Building a Bus Network Topology
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    20
@end menu
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    21
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    22
@c ========================================================================
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    23
@c Building a Bus Network Topology
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    24
@c ========================================================================
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    25
@node Building a Bus Network Topology
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    26
@section Building a Bus Network Topology
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
@cindex topology
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    29
@cindex topology|star
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    30
In this section we are going to expand our mastery of ns-3 network devices and
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    31
channels to cover an example of a bus network.  Ns-3 provides a net device and 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    32
channel we call CSMA (Carrier Sense Multiple Access).
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    33
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    34
The ns-3 CSMA device models a simple network in the spirit of Ethernet.  A real
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    35
Ethernet uses CSMA/CD (Carrier Sense Multiple Access with Collision Detection)
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    36
scheme with exponentially increasing backoff to contend for the shared 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    37
transmission medium.  The ns-3 CSMA device and channel models only a
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    38
subset of this.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    39
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    40
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
    41
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
    42
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
    43
quite familiar to you.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    45
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
    46
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
    47
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
    48
@code{examples/second.cc} in your favorite editor.  You will have already seen
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    49
enough ns-3 code to understand most of what is going on in this example, but 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    50
we will go over the entire script and examine some of the output.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    51
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    52
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
    53
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
    54
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    55
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
    56
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
    57
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
    58
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    59
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
    60
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
    61
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
    62
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
    63
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
    64
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
    65
thee ``extra'' nodes as seen below:
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    66
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
@verbatim
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    68
// Default Network Topology
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    69
//
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    70
//       10.1.1.0
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    71
// n0 -------------- n1   n2   n3   n4
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    72
//    point-to-point  |    |    |    |
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    73
//                    ================
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    74
//                      LAN 10.1.2.0
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    75
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    76
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    77
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
    78
@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
    79
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
    80
is nothing new yet.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    81
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    82
@verbatim
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    83
  #include "ns3/core-module.h"
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    84
  #include "ns3/simulator-module.h"
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    85
  #include "ns3/node-module.h"
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    86
  #include "ns3/helper-module.h"
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    87
  #include "ns3/global-routing-module.h"
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    88
  
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    89
  using namespace ns3;
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    90
  
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    91
  NS_LOG_COMPONENT_DEFINE ("SecondScriptExample");
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    92
@end verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    93
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    94
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
    95
@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
    96
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
    97
familiar to you so far.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    98
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    99
@verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   100
  int
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   101
  main (int argc, char *argv[])
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   102
  {
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   103
    LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   104
    LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   105
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   106
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   107
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
   108
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
   109
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
   110
on command line arguments.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   111
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   112
@verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   113
  uint32_t nCsma = 3;
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   114
  CommandLine cmd;
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   115
  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
   116
  cmd.Parse (argc,argv);
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   117
@end verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   118
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   119
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
   120
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
   121
done in @code{first.cc}.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   122
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   123
@verbatim
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   124
  NodeContainer p2pNodes;
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   125
  p2pNodes.Create (2);
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   126
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   127
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   128
Next, we delare another @code{NodeContainer} to hold the nodes that will be
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   129
part of the bus (CSMA) network.  First we just instantiate the container
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   130
object itself.  
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   131
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   132
@verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   133
  NodeContainer csmaNodes;
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   134
  csmaNodes.Add (p2pNodes.Get (1));
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   135
  csmaNodes.Create (nCsma);
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   136
@end verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   137
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   138
The next line of code @code{Get}s the first node (as in having an index of one)
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   139
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
   140
that will get CSMA devices.  The node in question is going to end up with a 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   141
point-to-point device and a CSMA device.  We then create a number of ``extra''
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   142
nodes that compose the remainder of the CSMA network.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   143
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   144
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
   145
@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
   146
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
   147
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
   148
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   149
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   150
  PointToPointHelper pointToPoint;
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   151
  pointToPoint.SetDeviceParameter ("DataRate", StringValue ("5Mbps"));
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   152
  pointToPoint.SetChannelParameter ("Delay", StringValue ("2ms"));
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   153
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   154
  NetDeviceContainer p2pDevices;
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   155
  p2pDevices = pointToPoint.Install (p2pNodes);
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   156
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   157
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   158
We then instantiate a @code{NetDeviceContainer} to keep track of the 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   159
point-to-point net devices and we install devices on the ``point-to-point 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   160
nodes.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   161
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   162
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
   163
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
   164
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
   165
channels.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   166
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   167
@verbatim
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   168
  CsmaHelper csma;
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   169
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   170
  NetDeviceContainer csmaDevices;
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   171
  csmaDevices = csma.Install (csmaNodes);
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   172
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   173
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   174
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
   175
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
   176
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
   177
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
   178
@code{csmaNodes NodeContainer}.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   179
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   180
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
   181
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
   182
@code{InternetStackHelper} to install these stacks.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   183
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   184
@verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   185
  InternetStackHelper stack;
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   186
  stack.Install (p2pNodes.Get (0));
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   187
  stack.Install (csmaNodes);
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   188
@end verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   189
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   190
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
   191
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
   192
the stacks on the remaining @code{p2pNodes} node, and all of the nodes in the
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   193
@code{csmaNodes} container.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   194
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   195
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
   196
@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
   197
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
   198
two point-to-point devices.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   199
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   200
@verbatim
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   201
  Ipv4AddressHelper address;
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   202
  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
   203
  Ipv4InterfaceContainer p2pInterfaces;
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   204
  p2pInterfaces = address.Assign (p2pDevices);
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   205
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   206
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   207
Recall that we save the created interfaces in a container to make it easy to
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   208
pull out addressing information later.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   209
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   210
We then need to assign IP addresses to our CSMA device interfaces.  The 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   211
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
   212
are performing the operation on a container that has a variable number of 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   213
CSMA devices --- remember we made that number changeable by command line 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   214
argument.  So the CSMA devices will be associated with IP addresses from 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   215
network number 10.1.2.0 in this case.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   216
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   217
@verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   218
  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
   219
  Ipv4InterfaceContainer csmaInterfaces;
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   220
  csmaInterfaces = address.Assign (csmaDevices);
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   221
@end verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   222
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   223
Now, we have a topology built, but we need applications.  This section is
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   224
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
   225
@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
   226
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
   227
point-to-point device.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   228
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   229
You should completely understand the code for setting up the server since we
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   230
have seen this before.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   231
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   232
@verbatim
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   233
  ApplicationContainer serverApps = echoServer.Install (csmaNodes.Get (nCsma));
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   234
  serverApps.Start (Seconds (1.0));
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   235
  serverApps.Stop (Seconds (10.0));
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   236
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   237
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   238
Recall that the @code{csmaNodes NodeContainer} contains one of the 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   239
nodes created for the point-to-point network and @code{nCsma} extra nodes.  
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   240
What we want to get is the last of the ``extra'' nodes.  The zeroth entry of
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   241
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
   242
way to think of this, then, is if we create one ``extra'' CSMA node, then it
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   243
will be be at index one of the @code{csmaNodes} container and, by induction,
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   244
if we create @code{nCsma} ``extra'' nodes the last one will be at index 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   245
@code{nCsma}.  You see this exhibited in the first line of code.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   246
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   247
The client application is set up exactly as we did in the @code{first.cc}
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   248
example script.  We point the client to the server we set up on the last of
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   249
the ``extra'' CSMA nodes and install the client onto the point-to-point node
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   250
that is not associated with any CSMA device.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   251
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   252
@verbatim
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   253
  UdpEchoClientHelper echoClient;
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   254
  echoClient.SetRemote (csmaInterfaces.GetAddress (nCsma), 9);
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   255
  echoClient.SetAppAttribute ("MaxPackets", UintegerValue (1));
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   256
  echoClient.SetAppAttribute ("Interval", TimeValue (Seconds (1.)));
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   257
  echoClient.SetAppAttribute ("PacketSize", UintegerValue (1024));
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   258
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   259
  ApplicationContainer clientApps = echoClient.Install (p2pNodes.Get (0));
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   260
  clientApps.Start (Seconds (2.0));
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   261
  clientApps.Stop (Seconds (10.0));
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   262
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   263
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   264
Since we have actually built an internetwork here, we need some form of 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   265
internetwork routing.  Ns-3 provides what we call a global route manager to 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   266
set up the routing tables on nodes.  This route manager has a global function
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   267
 that runs though the nodes created for the simulation and does the hard work 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   268
of setting up routing for you.  
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   269
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   270
Basically, what happens is that each node behaves as if it were an OSPF router
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   271
that communicates instantly and magically with all other routers.  Each node
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   272
generates link advertisements and communicates them directly to a global route
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   273
 manager, which uses this global information to construct the routing tables 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   274
for each node.  Setting up this form of routing is a one-liner:
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   275
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   276
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   277
  GlobalRouteManager::PopulateRoutingTables ();
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   278
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   279
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   280
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
   281
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
   282
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
   283
tracing with the point-to-point helper.
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
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   286
    PointToPointHelper::EnablePcapAll ("second");
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   287
    CsmaHelper::EnablePcapAll ("second");
3332
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
    Simulator::Run ();
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   290
    Simulator::Destroy ();
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   291
    return 0;
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   292
  }
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   293
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   294
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   295
In order to run this example, you have to copy the @code{second.cc} example
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   296
script into the scratch directory and use waf to build just as you did with
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   297
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
   298
repository you would type,
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   299
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   300
@verbatim
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   301
  cp examples/second.cc scratch/
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   302
  ./waf
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   303
  ./waf --run scratch/second
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   304
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   305
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   306
Since we have set up the UDP echo applications just as we did in the 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   307
@code{first.cc} script, you will see similar output.
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
  ~/repos/ns-3-dev > ./waf --run scratch/second
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   311
  Entering directory `/home/craigdo/repos/ns-3-dev/build'
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   312
  Compilation finished successfully
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   313
  Sent 1024 bytes to 10.1.2.4
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   314
  Received 1024 bytes from 10.1.1.1
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   315
  Received 1024 bytes from 10.1.2.4
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   316
  ~/repos/ns-3-dev >
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   317
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   318
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   319
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
   320
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
   321
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
   322
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
   323
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
   324
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
   325
the server.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   326
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   327
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
   328
trace files:
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   329
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   330
@verbatim
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   331
  ~/repos/ns-3-dev > ls *.pcap
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   332
  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
   333
  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
   334
  ~/repos/ns-3-dev >
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   335
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   336
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   337
Let's take a moment to look at the naming of these files.  They all have the 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   338
same form --- @code{<name>-<node>-<device>.pcap}.  For example, the first file
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   339
in the listing is @code{second-0-0.pcap} which is the pcap trace from node 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   340
zero, device zero.  There are no other devices on node zero so this is the
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   341
only trace from that node.  
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   342
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   343
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
   344
the pcap trace for device zero on node one and the latter is the trace file 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   345
for device one on node one.  If you refer back to the topology cartoon at
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   346
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
   347
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
   348
traces for that node.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   349
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   350
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
   351
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
   352
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   353
@verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   354
  ~/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
   355
  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
   356
  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
   357
  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
   358
  ~/repos/ns-3-dev >
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   359
@end verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   360
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   361
The first line of the dump indicates that the link type is PPP (point-to-point)
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   362
which we should expect.  You then see the echo packet leaving node zero on 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   363
via the device associated with IP address 10.1.1.1 headed for IP address
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   364
10.1.2.4 (the rightmost CSMA node).
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   365
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   366
This packet will move over the point-to-point link and be received by the
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   367
point-to-point net device on node one.  Let's take a look:
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   368
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   369
@verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   370
  ~/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
   371
  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
   372
  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
   373
  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
   374
  ~/repos/ns-3-dev >
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   375
@end verbatim
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
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
   378
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
   379
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
   380
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
   381
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
   382
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   383
@verbatim
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   384
  ~/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
   385
  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
   386
  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
   387
  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
   388
  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
   389
  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
   390
  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
   391
  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
   392
  ~/repos/ns-3-dev >
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   393
@end verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   394
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   395
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
   396
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
   397
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
   398
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
   399
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
   400
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
   401
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
   402
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   403
@verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   404
  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
   405
  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
   406
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   407
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   408
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
   409
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
   410
echo server,
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   411
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   412
@verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   413
  ~/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
   414
  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
   415
  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
   416
  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
   417
  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
   418
  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
   419
  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
   420
  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
   421
  ~/repos/ns-3-dev >
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   422
@end verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   423
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   424
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
   425
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
   426
being delivered to its final destination.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   427
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   428
The echo server turns the packet around and needs to send it back to the echo
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   429
cleint on 10.1.1.1 but it knows that this address is on another network that 
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   430
it reaches via IP address 10.1.2.1.  This is because we initialized the global
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   431
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
   432
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
   433
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
   434
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
   435
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
   436
tcpdumps above.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   437
3337
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   438
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
   439
exchange:
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   440
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   441
@verbatim
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   442
  ~/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
   443
  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
   444
  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
   445
  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
   446
  ~/repos/ns-3-dev >
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   447
@end verbatim
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
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
   450
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
   451
pcap trace will be identical to this one.
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   452
3337
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   453
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
   454
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
   455
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
   456
@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
   457
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   458
@verbatim
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   459
  ~/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
   460
  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
   461
  Compilation finished successfully
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   462
  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
   463
  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
   464
  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
   465
  ~/repos/ns-3-dev >
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   466
@end verbatim
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   467
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   468
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
   469
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
   470
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
   471
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
   472
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
   473
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
   474
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   475
Let's take a look at @code{scratch/second.cc} and be more specific about which
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   476
nodes and devices we want to trace.  The file we provide uses the 
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   477
@code{EnablePcapAll} methods of the helpers to enable pcap on all devices.  
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   478
We want to use the more specific method, @code{EnablePcap}, which takes
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   479
a node number and device number as parameters.  Go ahead and replace the 
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   480
@code{EnablePcapAll} calls with the calls below.
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   481
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   482
@verbatim
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   483
  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
   484
  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
   485
@end verbatim
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   486
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   487
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
   488
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
   489
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
   490
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
   491
increasing fashion starting from zero in the order in which you created them.
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   492
One way to get a node number to pass to the helper is to figure this number
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   493
out ``manually.''  If you take a look at the network topology illustration at
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   494
the beginning of the file, you can see that the last CSMA node is going to be
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   495
node number code{nCsma + 1}.  This can become annoyingly difficult in larger
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   496
simulations.  An alternate way, which we use here, is to realize that the
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   497
@code{NodeContainer}s contain pointers to ns-3 @code{Node} Objects.  The
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   498
@code{Node} Object has a method called @code{GetId} which will return that
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   499
node's ID.  Let's go take a look at the Doxygen for the @code{Node} and locate
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   500
that method, which is further down in the code than we've seen so far.
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   501
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   502
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
   503
on the project web site).  You can get to the @code{Node} documentation by
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   504
looking through at the ``Classes'' tab in and scrolling down to 
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   505
@code{ns3::Node} in the list.  Select @code{ns3::Node} and you will be taken
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   506
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
   507
@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
   508
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
   509
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
   510
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   511
Now that we have got some trace filtering in place, it is reasonable to start
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   512
increasing the number of CSMA devices in our simulation.  If you run the 
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   513
simulation setting @code{nCsma} to 100, you will see the following:
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
@verbatim
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   516
  ~/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
   517
  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
   518
  Compilation finished successfully
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   519
  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
   520
  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
   521
  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
   522
  ~/repos/ns-3-dev >
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   523
@end verbatim
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   524
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   525
Note that the echo server is now located at 10.1.2.101 which corresponds to
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   526
100 ``extra'' CSMA nodes with the echo server on the last one.  If you list
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   527
the pcap files in the top level directory,
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 > ls *.pcap
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   531
  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
   532
  ~/repos/ns-3-dev >
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   533
@end verbatim
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   534
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   535
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
   536
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
   537
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
   538
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
   539
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   540
6b297a1f231b finish off csma tutorial example words
Craig Dowell <craigdo@ee.washington.edu>
parents: 3336
diff changeset
   541
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