doc/tutorial/conceptual-overview.texi
author Craig Dowell <craigdo@ee.washington.edu>
Sun, 29 Jun 2008 23:14:16 -0700
changeset 3350 11e3699b754e
parent 3348 fe47da29d783
child 3351 9042f35c445e
permissions -rw-r--r--
minor tweaks for menus on tutorial
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 ========================================================================
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
     7
@c Conceptual Overview
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     8
@c ========================================================================
3340
0b45016b6097 Table of content fixes
Tom Henderson <tomh@tomh.org>
parents: 3332
diff changeset
     9
@node Conceptual Overview
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    10
@chapter Conceptual Overview
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    11
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    12
@menu
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    13
* Key Abstractions::
3350
11e3699b754e minor tweaks for menus on tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3348
diff changeset
    14
* A First ns-3 Script::
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    15
@end menu
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    16
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    17
The first thing we need to do before actually starting to look at or write
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
    18
@command{ns-3} code is to explain a few core concepts and abstractions in the
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    19
system.  Much of this may appear transparently obvious to some, but we
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
    20
recommend taking the time to read through this section just to ensure you
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    21
are starting on a firm foundation.
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
@node Key Abstractions
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    24
@section Key Abstractions
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
In this section, we'll review some terms that are commonly used in
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
    27
networking, but have a specific meaning in @command{ns-3}.
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
@subsection Node
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    30
@cindex Node
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    31
In Internet jargon, a computing device that connects to a network is called
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
    32
a @emph{host} or sometimes an @emph{end system}.  Because @command{ns-3} is a 
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
@emph{network} simulator, not specifically an @emph{Internet} simulator, we 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
intentionally do not use the term host since it is closely associated with
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
the Internet and its protocols.  Instead, we use a more generic term also
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    36
used by other simulators that originates in Graph Theory --- the @emph{node}.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    37
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    38
@cindex class Node
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
    39
In @command{ns-3} the basic computing device abstraction is called the 
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
node.  This abstraction is represented in C++ by the class @code{Node}.  The 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
@code{Node} class provides methods for managing the representations of 
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
    42
computing devices in simulations.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    43
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
You should think of a @code{Node} as a computer to which you will add 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
functionality.  One adds things like applications, protocol stacks and
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    46
peripheral cards with their associated drivers to enable the computer to do
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
    47
useful work.  We use the same basic model in @command{ns-3}.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    48
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    49
@subsection Application
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    50
@cindex Application
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
Typically, computer software is divided into two broad classes.  @emph{System
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    52
Software} organizes various computer resources such as memory, processor
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
cycles, disk, network, etc., according to some computing model.  System
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
software usually does not use those resources to complete tasks that directly
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    55
benefit a user.  A user would typically run an @emph{application} that acquires
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    56
and uses the resources controlled by the system software to accomplish some
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    57
goal.  
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    58
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    59
@cindex system call
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    60
Often, the line of separation between system and application software is made
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
at the privilege level change that happens in operating system traps.
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
    62
In @command{ns-3} there is no real concept of operating system and especially
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    63
no concept of privilege levels or system calls.  We do, however, have the
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    64
idea of an application.  Just as software applications run on computers to
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
    65
perform tasks in the ``real world,'' @command{ns-3} applications run on
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
    66
@command{ns-3} @code{Node}s to drive simulations in the simulated world.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
    68
@cindex class Application
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
    69
In @command{ns-3} the basic abstraction for a user program that generates some
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    70
activity to be simulated is the application.  This abstraction is represented 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    71
in C++ by the class @code{Application}.  The @code{Application} class provides 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    72
methods for managing the representations of our version of user-level 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    73
applications in simulations.  Developers are expected to specialize the
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
    74
@code{Application} class in the object-oriented programming sense to create new
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    75
applications.  In this tutorial, we will use specializations of class 
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
    76
@code{Application} called @code{UdpEchoClientApplication} and 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
    77
@code{UdpEchoServerApplication}.  As you might expect, these applications 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
    78
compose a client/server application set used to generate and echo simulated 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
    79
network packets 
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    80
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    81
@subsection Channel
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    82
@cindex Channel
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    83
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    84
In the real world, one can connect a computer to a network.  Often the media
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    85
over which data flows in these netowrks are called @emph{channels}.  When
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    86
you connect your Ethernet cable to the plug in the wall, you are connecting 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    87
your computer to an Ethernet communication channel.  In the simulated world
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
    88
of @command{ns-3} one connects a @code{Node} to an object representing a
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    89
communication channel.  Here the basic communication subnetwork abstraction 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    90
is called the channel and is represented in C++ by the class @code{Channel}.  
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    91
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    92
The @code{Channel} class provides methods for managing communication 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    93
subnetwork objects and connecting nodes to them.  They may also be specialized
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    94
by developers in the object oriented programming sense.  A @code{Channel}
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    95
specialization may model something as simple as a wire.  The specialized 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    96
@code{Channel} can also model things as complicated as a large Ethernet
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    97
switch, or three-dimensional space in the case of wireless networks.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    98
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    99
We will use specialized versions of the @code{Channel} called
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   100
@code{CsmaChannel}, @code{PointToPointChannel} and @code{WifiChannel} in this
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   101
tutorial.  The @code{CsmaChannel}, for example, models a version of a 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   102
communication subnetwork that implements a @emph{carrier sense multiple 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   103
access} communication medium.  This gives us Ethernet-like functionality.  
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   104
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   105
@subsection Net Device
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   106
@cindex NetDevice
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   107
@cindex Ethernet
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   108
It used to be the case that if you wanted to connect a computers to a network,
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   109
you had to buy a specific kind of network cable and a hardware device called
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   110
(in PC terminology) a @emph{peripheral card} that needed to be installed in
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   111
your computer.  These cards were called Network Interface Cards, or 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   112
@emph{NIC}s.  Today most computers come with the network controller hardware
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   113
built in and users don't see these building blocks.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   114
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   115
A NIC will not work without a software driver to control the hardware.  In 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   116
Unix (or Linux), a piece of peripheral hardware is classified as a 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   117
@emph{device}.  Devices are controlled using @emph{device drivers}, and network
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   118
devices (NICs) are controlled using @emph{network device drivers}
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   119
collectively known as @emph{net devices}.  In Unix and Linux you refer
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   120
to these net devices by names such as @emph{eth0}.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   121
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   122
In @command{ns-3} the @emph{net device} abstraction covers both the software 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   123
driver and the simulated hardware.  A net device is ``installed'' in a 
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   124
@code{Node} in order to enable the @code{Node} to communicate with other 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   125
@code{Node}s in the simulation via @code{Channel}s.  Just as in a real
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   126
computer, a @code{Node} may be connected to more than one @code{Channel} via
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   127
multiple @code{NetDevice}s.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   128
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   129
The net device abstraction is represented in C++ by the class @code{NetDevice}.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   130
The @code{NetDevice} class provides methods for managing connections to 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   131
@code{Node} and @code{Channel} objects; and may be specialized by developers
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   132
in the object-oriented programming sense.  We will use the several specialized
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   133
versions of the @code{NetDevice} called @code{CsmaNetDevice},
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   134
@code{PointToPointNetDevice}, and @code{WifiNetDevice} in this tutorial.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   135
Just as an Ethernet NIC is designed to work with an Ethernet network, the
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   136
@code{CsmaNetDevice} is designed to work with a @code{CsmaChannel}; the
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   137
@code{PointToPointNetDevice} is designed to work with a 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   138
@code{PointToPointChannel} and a @code{WifiNetNevice} is designed to work with
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   139
a @code{WifiChannel}.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   140
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   141
@subsection Topology Helpers
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   142
@cindex helper
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   143
@cindex topology
3339
ff29f4ba75ed finish up with a wifi example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3332
diff changeset
   144
@cindex topology helper
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   145
In a real network, you will find host computers with added (or built-in)
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   146
NICs.  In @command{ns-3} we would say that you will find @code{Nodes} with 
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   147
attached @code{NetDevices}.  In a large simulated network you will need to 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   148
arrange many connections between @code{Node}s, @code{NetDevice}s and 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   149
@code{Channel}s.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   150
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   151
Since connecting @code{NetDevice}s to @code{Node}s, @code{NetDevice}s
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   152
to @code{Channel}s, assigning IP addresses,  etc., are such common tasks
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   153
in @command{ns-3}, we provide what we call @emph{topology helpers} to make 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   154
this as easy as possible.  For example, will take several distinct 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   155
@command{ns-3} core operations to create a NetDevice, add a MAC address, 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   156
connect the net device to a @code{Node}, configure the protocol stack, and 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   157
then connect the @code{NetDevice} to a @code{Channel}.  More operations would
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   158
be required to connect multiple devices onto multipoint channels and then to 
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   159
connect networks together into internetworks.  We use topology helper objects
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   160
to combine those many distinct operations into an easy to use model.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   161
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   162
@c ========================================================================
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   163
@c A First ns-3 script
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   164
@c ========================================================================
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   165
@node A First ns-3 Script
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   166
@section A First ns-3 script
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   167
@cindex first script
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   168
If you downloaded the system as was suggested above, you will have a release
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   169
of @command{ns-3} in a directory called @code{repos} under your home 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   170
directory.  Change into that release directory, and you should find a 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   171
directory structure something like the following:
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   172
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   173
@verbatim
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   174
  AUTHORS  examples/  README         samples/  utils/   waf.bat*
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   175
  build/   LICENSE    regression/    scratch/  VERSION  wscript
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   176
  doc/     ns3/       RELEASE_NOTES  src/      waf*
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   177
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   178
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   179
@cindex first.cc
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   180
Change into the examples directory.  You should see a file named 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   181
@code{first.cc} located there.  This is a script that will create a simple
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   182
point-to-point link between two nodes and echo a single packet between the
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   183
nodes.  Let's take a look at that script line by line.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   184
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   185
@subsection Boilerplate
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   186
The first line in the file is an emacs mode line.  This tells emacs about the
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   187
formatting conventions (coding style) we use in our source code.  
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   188
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   189
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   190
  /* -*- Mode:C++; c-file-style:''gnu''; indent-tabs-mode:nil; -*- */
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   191
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   192
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   193
This is always a somewhat controversial subject, so we might as well get it
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   194
out of the way immediately.  The @code{ns-3} project, like most large 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   195
projects, has adopted a coding style to which all contributed code must 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   196
adhere.  If you want to contribute your code to the project, you will 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   197
eventually have to conform to the @command{ns-3} coding standard as described 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   198
in the file @code{doc/codingstd.txt}.  We recommend that you, well, just get 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   199
used to the look and feel of @code{ns-3} code and adopt this standard whenever
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   200
you are working with our code.  All of the development team have done so.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   201
The emacs mode line above makes it easier to get the formatting correct if you
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   202
use the emacs editor.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   203
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   204
The @command{ns-3} simulator is licentsed using the GNU General Public 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   205
License.  You will see the appropriate GNU legalese at the head of every file 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   206
in the @command{ns-3} distribution.  Often you will see a copyright notice for
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   207
one of the institutions involved in the @code{ns-3} project and an author
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   208
listed.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   209
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   210
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   211
  /*
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   212
   * This program is free software; you can redistribute it and/or modify
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   213
   * it under the terms of the GNU General Public License version 2 as
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   214
   * published by the Free Software Foundation;
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   215
   *
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   216
   * This program is distributed in the hope that it will be useful,
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   217
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   218
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   219
   * GNU General Public License for more details.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   220
   *
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   221
   * You should have received a copy of the GNU General Public License
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   222
   * along with this program; if not, write to the Free Software
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   223
   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   224
   */
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   225
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   226
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   227
@subsection Module Includes
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   228
The code proper starts with a number of include statements.  To help our high
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   229
level users deal with the large number of include files present in the system,
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   230
we group includes according to relatively large modules.  We provide a single
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   231
include file that, in turn, includes all of the include files used in each
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   232
module.  Rather than having to look up exactly what header you need, and
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   233
possibly have to get dependencies right, we give you the ability to load a 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   234
group of files at a large granularity.  This is not the most efficient approach
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   235
but it certainly makes writing scripts much easier.  Each of the 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   236
@command{ns-3} files is placed in a directory called @code{ns3} (under the 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   237
build directory) to help avoid include file name collisions.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   238
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   239
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   240
  #include "ns3/core-module.h"
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   241
  #include "ns3/simulator-module.h"
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   242
  #include "ns3/node-module.h"
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   243
  #include "ns3/helper-module.h"
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   244
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   245
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   246
The @code{ns3/core-module.h} file corresponds to the ns-3 module you will find
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   247
in the directory @code{src/core} in your downloaded release distribution.  If 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   248
you list this directory you will find a large number of header files.  When
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   249
you do a build, Waf will place public header files in an @code{ns3} directory
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   250
under the appropriate @code{build/debug} or @code{build/optimized} directory
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   251
depending on your configuration.  Waf will also automatically generate a module
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   252
include file to load all of the public header files.  Since you are following
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   253
this tutorial religiously, you will already have done a
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   254
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   255
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   256
  ./waf -d debug configure
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   257
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   258
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   259
to configure the project to perform debug builds.  You will also have done a
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
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   262
  ./waf
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   263
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   264
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   265
to build the project.  So now if you look in the directory 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   266
@code{build/debug/ns-3} you will find the four module include files shown 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   267
above.  You can take a look at the contents to find that these files will
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   268
include all of the public includes in the respective modules.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   269
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   270
@subsection Ns3 Namespace
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   271
The next line in the @code{first.cc} script is a namespace declaration.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   272
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   273
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   274
  using namespace ns3;
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   275
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   276
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   277
The @command{ns-3} project is implemented in a C++ namespace called 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   278
@code{ns3}.  This groups all @command{ns-3}-related declarations in a scope
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   279
outside the global namespace, which we hope will help with integration with 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   280
other code.  The C++ @code{using} statement introduces the @code{ns-3}
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   281
namespace into the current (global) declarative region.  This is a fancy way
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   282
of saying that after this declaration, you will not have to type @code{ns3::}
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   283
scope resolution operator before all of the @code{ns-3} code in order to use
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   284
it.  If you are unfamiliar with namespaces, please consult almost any C++ 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   285
tutorial and compare the @code{ns3} namespace and usage here with instances of
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   286
the @code{std} namespace and the @code{using namespace std;} statements you 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   287
will often find in discussions of @code{cout} and streams.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   288
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   289
@subsection Logging
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   290
The next line of the script is the following,
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   291
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   292
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   293
  NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   294
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   295
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   296
We will use this statement as a convenient place to talk about our Doxygen
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   297
documentation system.  If you look at the project web site, 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   298
@uref{http://www.nsnam.org,,ns-3 project}, you will find a link to ``Other
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   299
Documentation'' in the navigation bar.  If you select this link, you will be
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   300
taken to our documentation page.  You will find links to our development
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   301
@code{ns-3-dev} documentation as well as that for our latest release.  If you
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   302
select the @code{HTML} link you will be taken to the Doxygen documentation for
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   303
that version.  
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   304
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   305
Along the left side, you will find a graphical representation of the structure
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   306
of the documentation.  A good place to start is the @code{NS-3 Modules} 
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   307
``book.''  If you expand @code{Modules} you will see a list of @command{ns-3}
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   308
module documentation.  The concept of module here ties directly into the 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   309
module include files discussed above.  It turns out that the @command{ns-3}
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   310
logging subsystem is part of the @code{core} module, so go ahead and expand 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   311
that documentation node.  Now, open the @code{Debugging} book and then select 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   312
the @code{Logging} page.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   313
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   314
You should now be looking at the Doxygen documentation for the Logging module.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   315
In the list of @code{#define}s you will see @code{NS_LOG_COMPONENT_DEFINE}.  
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   316
It would probably be good to look for the ``Detailed Description'' of the 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   317
logging module now to get a feel for the overall operation and then look at
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   318
the specific @code{NS_LOG_COMPONENT_DEFINE} documentation.  I won't duplicate
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   319
the documentation here, but to summarize, this line declares a logging 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   320
component called @code{FirstScriptExample} that allows you to enable and 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   321
disable console message logging by reference to the name.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   322
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   323
@subsection Main Function
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   324
The next lines of the script you will find are:
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   325
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   326
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   327
    int
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   328
  main (int argc, char *argv[])
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
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   331
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   332
This is just the declaration of the main function of your program.  Just as in
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   333
any C++ program, you need to define a main function that will be the first 
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   334
function run.  There is nothing at all special here.  Your @command{ns-3}
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   335
script is just a C++ program.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   336
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   337
The next two lines of the script are used to enable two logging components that
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   338
are built into the Echo Client and Echo Server applications:
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   339
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   340
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   341
    LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   342
    LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   343
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   344
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   345
If you have read over the Logging component documentation you will see that
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   346
there are a number of levels of detail that you can enable on each component.  
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   347
These two lines of code enable debug logging at the INFO level for echo 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   348
clients and servers.  This will result in the application printing out 
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   349
messages as packets are sent and received.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   350
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   351
Now we will get directly to the business of creating a topology and running 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   352
a simulation.  We will use the topology helper objects to make this job as
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   353
easy as possible.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   354
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   355
@subsection Topology Helpers
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   356
@subsubsection NodeContainer
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   357
The next two lines of code in our script will actually create the 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   358
@command{ns-3} @code{Node} objects that will represent the computers in the 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   359
simulation.  
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   360
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   361
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   362
    NodeContainer nodes;
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   363
    nodes.Create (2);
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   364
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   365
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   366
Let's find the documentation for the @code{NodeContainer} class before we
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   367
continue.  Another way to get into the documentation for a given class is via 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   368
the @code{Classes} tab in the Doxygen pages.  If you still have the Doxygen 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   369
handy, just scroll up to the top of the page and select the @code{Classes} 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   370
tab.  You should see a new set of tabs appear, one of which is 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   371
@code{Class List}.  Under that tab you will see a list of all of the 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   372
@command{ns-3} classes.  Scroll down, looking for @code{ns3::NodeContainer}.
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   373
When you find the class, go ahead and select it to go to the documentation for
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   374
the class.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   375
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   376
You may recall that one of our key abstractions is the @code{Node}.  This
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   377
represents a computer to which we are going to add things like protocol stacks,
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   378
applications and peripheral cards.  The @code{NodeContainer} topology helper
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   379
provides a convenient way to create, manage and access any @code{Node} objects
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   380
that we create in order to run a simulation.  The first line above just 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   381
declares a NodeContainer which we call @code{nodes}.  The second line calls the
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   382
@code{Create} method on the @code{nodes} object that asks the container to 
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   383
create two nodes.  As described in the Doxygen, the container calls down into
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   384
the @command{ns-3} system proper to create two @code{Node} objects and stores
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   385
pointers to those objects internally.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   386
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   387
The nodes as they stand in the script do nothing.  The next step in 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   388
constructing a topology is to connect our nodes together into a network.
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   389
The simplest form of network we support is a single point-to-point link 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   390
between two nodes.  We'll construct one of those links here.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   391
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   392
@subsubsection PointToPointHelper
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   393
We are constructing a point to point link, and, in a pattern which will become
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   394
quite familiar to you, we use a topology helper object to do the low-level
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   395
work required to put the link together.  Recall that two of our key 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   396
abstractions are the @code{NetDevice} and the @code{Channel}.  In the real
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   397
world, these terms correspond roughly to peripheral cards and network cables.  
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   398
Typically these two things are intimately tied together and one cannot expect
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   399
to interchange, for example, Ethernet devices and wireless channels.  Our 
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   400
Topology Helpers follow this intimate coupling and therefore you will use a
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   401
single @code{PointToPointHelper} to configure and connect @command{ns-3}
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   402
@code{PointToPointNetDevice} and @code{PointToPointChannel} objects in this 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   403
script.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   404
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   405
The next three lines in the script are,
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   406
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   407
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   408
    PointToPointHelper pointToPoint;
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   409
    pointToPoint.SetDeviceParameter ("DataRate", StringValue ("5Mbps"));
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   410
    pointToPoint.SetChannelParameter ("Delay", StringValue ("2ms"));
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   411
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   412
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   413
The first line 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   414
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   415
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   416
    PointToPointHelper pointToPoint;
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   417
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   418
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   419
creates a @code{PointToPointHelper} object on the stack.  From a high-level 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   420
perspective the next line,
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   421
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   422
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   423
    pointToPoint.SetDeviceParameter ("DataRate", StringValue ("5Mbps"));
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   424
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   425
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   426
tells the @code{PointToPointHelper} object to use the value ``5mbps''
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   427
(five megabits per second) as the ``DataRate'' when it creates a 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   428
@code{PointToPointNetDevice} object.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   429
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   430
From a more detailed perspective, the string ``DataRate'' corresponds
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   431
to what we call an @code{Attribute} of the @code{PointToPointNetDevice}.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   432
If you look at the Doxygen for class @code{ns3::PointToPointNetDevice} and 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   433
find the documentation for the @code{GetTypeId} method, you will find a list
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   434
of  @code{Attributes} defined for the device.  Among these is the ``DataRate''
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   435
attribute.  Most user-visible @command{ns-3} objects have similar lists of 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   436
attributes.  We use this mechanism to easily configure simulations without
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   437
recompiling as you will see in a following section.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   438
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   439
Similar to the ``DataRate'' on the @code{PointToPointNetDevice} we find a
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   440
``Delay'' attribute associated with the @code{PointToPointChannel}.  The 
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   441
final line,
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   442
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   443
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   444
    pointToPoint.SetChannelParameter ("Delay", StringValue ("2ms"));
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   445
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   446
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   447
tells the @code{PointToPointHelper} to use the value ``2ms'' (two milliseconds)
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   448
as the value of the transmission delay of every point to point channel it 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   449
creates.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   450
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   451
@subsubsection NetDeviceContainer
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   452
At this point in the script, we have a @code{NodeContainer} that contains
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   453
two nodes.  We have a @code{PointToPointHelper} that is primed and ready to 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   454
make @code{PointToPointNetDevices} and wire @code{PoiintToPointChannel} objects
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   455
between them.  Just as we used the @code{NodeContainer} topology helper object
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   456
to create the @code{Node}s for our simulation, we will ask the 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   457
@code{PointToPointHelper} to do the work involved in creating, configuring and
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   458
installing our devices for us.  We will need to have a list of all of the 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   459
NetDevice objects that are created, so we use a NetDeviceContainer to hold 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   460
them just as we used a NodeContainer to hold the nodes we created.  The 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   461
following two lines of code,
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   462
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   463
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   464
    NetDeviceContainer devices;
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   465
    devices = pointToPoint.Install (nodes);
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   466
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   467
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   468
will finish configuring the devices and channel.  The first line declares the 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   469
device container mentioned above and the second does the heavy lifting.  The 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   470
@code{Install} method of the @code{PointToPointHelper} takes a 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   471
@code{NodeContainer} as a parameter.  Internally, a @code{NetDeviceContainer} 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   472
is created.  For each node in the @code{NodeContainer} (there must be exactly 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   473
two for a point-to-point link) a @code{PointToPointNetDevice} is created and 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   474
saved in the device container.  A @code{PointToPointChannel} is created and 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   475
the two @code{PointToPointNetDevices} are attached.  When objects are created
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   476
by the @code{PointToPointHelper}, the attributes previously set in the helper
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   477
are used to initialize the corresponding attributes in the created objects.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   478
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   479
After executing the the @code{pointToPoint.Install (nodes)} call we will have
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   480
two nodes, each with an installed point-to-point net device and a 
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   481
point-to-point channel between them.  Both devices will be configured to 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   482
transmit data at five megabits per second over the channel which has a two 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   483
millisecond transmission delay.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   484
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   485
@subsubsection InternetStackHelper
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   486
We now have nodes and devices configured, but we don't have any protocol stacks
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   487
installed on our nodes.  The next two lines of code will take care of that.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   488
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   489
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   490
    InternetStackHelper stack;
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   491
    stack.Install (nodes);
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   492
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   493
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   494
The @code{InternetStackHelper} is a topology helper that is to internet stacks
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   495
what the @code{PointToPointHelper} is to point-to-point net devices.  The
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   496
@code{Install} method takes a @code{NodeContainer} as a parameter.  When it is
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   497
executed, it will install an Internet Stack (TCP, UDP, IP, etc.) on each of
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   498
the nodes in the node container.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   499
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   500
@subsubsection Ipv4AddressHelper
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   501
Next we need to associate the devices on our nodes with IP addresses.  We 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   502
provide a topology helper to manage the allocation of IP addresses.  The only
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   503
user-visible API is to set the base IP address and network mask to use when
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   504
performing the actual address allocation (which is done at a lower level 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   505
inside the helper).
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   506
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   507
The next two lines of code in our example script, @code{first.cc},
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   508
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   509
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   510
    Ipv4AddressHelper address;
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   511
    address.SetBase ("10.1.1.0", "255.255.255.0");
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   512
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   513
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   514
declare an address helper object and tell it that it should begin allocating IP
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   515
addresses from the network 10.1.1.0 using the mask 255.255.255.0 to define 
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   516
the allocatable bits.  By default the addresses allocated will start at one
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   517
and increase monotonically, so the first address allocated from this base will
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   518
be 10.1.1.1, followed by 10.1.1.2, etc.  The low level @command{ns-3} system
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   519
actually remembers all of the IP addresses allocated and will generate a
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   520
fatal error if you accidentally cause the same address to be generated twice 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   521
(which is a very hard to find error, by the way).
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   522
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   523
The next line of code,
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   524
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   525
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   526
    Ipv4InterfaceContainer interfaces = address.Assign (devices);
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   527
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   528
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   529
performs the actual address assignment.  In @command{ns-3} we make the
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   530
association between an IP address and a device using an @code{Ipv4Interface}
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   531
object.  Just as we sometimes need a list of net devices created by a helper 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   532
for future reference we sometimes need a list of @code{Ipv4Interface} objects.
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   533
The @code{Ipv4InterfaceContainer} provides this functionality.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   534
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   535
Now we have a point-to-point network built, with stacks installed and IP 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   536
addresses assigned.  What we need at this point are applications to generate
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   537
traffic.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   538
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   539
@subsection Applications
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   540
Another one of the core abstractions of the ns-3 system is the 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   541
@code{Application}.  In this script we use two specializations of the core
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   542
@command{ns-3} class @code{Application} called @code{UdpEchoServerApplication}
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   543
and @code{UdpEchoClientApplication}.  Just as we have in our previous 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   544
explanations,  we use helper objects to help configure and manage the 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   545
underlying objects.  Here, we use @code{UdpEchoServerHelper} and
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   546
@code{UdpEchoClientHelper} objects to make our lives easier.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   547
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   548
@subsubsection UdpEchoServerHelper
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   549
The following lines of code in our example script, @code{first.cc}, are used
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   550
to set up a UDP echo server application on one of the nodes we have previously
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   551
created and connected using a point-to-point link.  
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   552
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   553
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   554
    UdpEchoServerHelper echoServer;
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   555
    echoServer.SetPort (9);
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   556
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   557
    ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   558
    serverApps.Start (Seconds (1.0));
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   559
    serverApps.Stop (Seconds (10.0));
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   560
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   561
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   562
The first line of code in the above snippet declares the 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   563
@code{UdpEchoServerHelper}.  As usual, this isn't the application itself, it
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   564
is an object used to help us create the actual applications.  The second line
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   565
that has the @code{SetPort} call, is used to tell the helper to assign the
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   566
value nine to the ``Port'' attribute when creating 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   567
@code{UdpEchoServerApplication} objects.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   568
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   569
Similar to many other helper objects, the @code{UdpEchoServerHelper} object 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   570
has an @code{Install} method.  It is the execution of this method that actually
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   571
causes the underlying echo server application to be instantiated and attached
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   572
to a node.  Interestingly, the @code{Install} method takes a
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   573
@code{NodeContainter} as a parameter just as the other @code{Install} methods
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   574
we have seen.  This is actually what is passed to the method even though it 
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   575
doesn't look so in this case.  There is a C++ @emph{implicit conversion} at
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   576
work here.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   577
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   578
We now see that @code{echoServer.Install} is going to install a
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   579
@code{UdpEchoServerApplication} on the node found at index number one of the
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   580
@code{NodeContainer} we used to manage our nodes.  @code{Install} will return
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   581
a container that has all of the applications (one in this case since we passed
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   582
a @code{NodeContainer} containing one node) made by the helper.  
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   583
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   584
Applications require a time to ``start'' generating traffic and a time to
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   585
``stop.''  These times are set using @code{ApplicationContainer} methods
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   586
@code{Start} and @code{Stop}.  These methods take @code{Time} parameters.  
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   587
In this case, we use an explicit conversion sequence to take the C++ double
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   588
1.0 and convert it to an @command{ns-3} @code{Time} object using a 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   589
@code{Seconds ()} cast.  The two lines,
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   590
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   591
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   592
    serverApps.Start (Seconds (1.0));
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   593
    serverApps.Stop (Seconds (10.0));
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   594
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   595
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   596
will cause the echo server application to @code{Start} (enable itself) at one
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   597
second into the simulation and to @code{Stop} (disable itself) at ten seconds
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   598
into the simulation.  By virtue of the fact that we have implicilty declared
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   599
a simulation event at ten seconds, the simulation will last at least ten 
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   600
seconds.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   601
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   602
@subsubsection UdpEchoClientHelper
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   603
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   604
The echo client application is set up in a substantially method similar to the
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   605
server.  There is an underlying @code{UdpEchoClientApplication} that is 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   606
managed by an @code{UdpEchoClientHelper}.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   607
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   608
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   609
    UdpEchoClientHelper echoClient;
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   610
    echoClient.SetRemote (interfaces.GetAddress (1), 9);
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   611
    echoClient.SetAppAttribute ("MaxPackets", UintegerValue (1));
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   612
    echoClient.SetAppAttribute ("Interval", TimeValue (Seconds (1.)));
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   613
    echoClient.SetAppAttribute ("PacketSize", UintegerValue (1024));
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   614
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   615
    ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   616
    clientApps.Start (Seconds (2.0));
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   617
    clientApps.Stop (Seconds (10.0));
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   618
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   619
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   620
For the echo client, however, we need to set four different attributes.  The 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   621
first attribute is set using the @code{SetRemote} method.  Recall that
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   622
we used an @code{Ipv4InterfaceContainer} to keep track of the IP addresses we
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   623
assigned to our devices.  As a result of the allocation, the zeroth interface
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   624
in the @code{interfaces} container cooresponds to the IP address of the 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   625
zeroth node in the @code{nodes} container.  The first interface in the 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   626
@code{interfaces} container cooresponds to the IP address of the first node in
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   627
the @code{nodes} container.  So, in the following line of code (reproduced 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   628
from above), we are setting the remote address of the client to be the IP 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   629
address assigned to the node on which the server resides, and we tell it to 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   630
send packets to port nine.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   631
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   632
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   633
    echoClient.SetRemote (interfaces.GetAddress (1), 9);
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   634
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   635
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   636
The ``MaxPackets'' attribute tells the client the maximum number of packets 
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   637
it can send.  The ``Interval'' attribute tells the client how long to wait 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   638
between packets, and the ``PacketSize'' attribute tells the client how large 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   639
its packets should be.  With this combination of attributes, we are telling 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   640
the client to send one 1024-byte packet.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   641
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   642
Just as in the case of the echo server, we tell the echo client to @code{Start}
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   643
and @code{Stop}, but here we start the client one second after the server is
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   644
enabled (at two seconds into the simulation).
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   645
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   646
@subsection Simulator
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   647
What we need to do at this point is to actually run the simulation.  This is 
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   648
done using the global function @code{Simulator::Run}.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   649
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   650
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   651
    Simulator::Run ();
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   652
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   653
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   654
When we previously called the methods,
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   655
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   656
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   657
    serverApps.Start (Seconds (1.0));
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   658
    serverApps.Stop (Seconds (10.0));
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   659
    ...
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   660
    clientApps.Start (Seconds (2.0));
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   661
    clientApps.Stop (Seconds (10.0));
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   662
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   663
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   664
we actually scheduled events in the simulator at 1.0 seconds, 2.0 seconds and
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   665
10.0 seconds.  When @code{Simulator::Run} is called, the ssytem will begin 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   666
looking through the list of scheduled events and executing them.  First it 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   667
will run the event at 1.0 seconds, which will enable the echo server 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   668
application.  Then it will run the event scheduled for t=2.0 seconds which 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   669
will start the echo client application.  The start event implementation in 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   670
the echo client will begin the data transfer phase of the simulation by 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   671
sending a packet to the server.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   672
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   673
The act of sending the packet to the server will trigger a chain of events
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   674
which will be automatically scheduled and which will perform the mechanics of
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   675
the packet echo according to the various timing parameters that we have set 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   676
in the script.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   677
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   678
Eventually, since we only send one packet, the chain of events triggered by 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   679
that single client echo request will taper off and the simulation will go 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   680
idle.  Once this happens, the remaining events will be the @code{Stop} events
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   681
for the server and the client.  When these events are executed, there are
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   682
no further events to process and @code{Simulator::Run} returns.  The simulation
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   683
is complete.
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   684
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   685
All that remains is to clean up.  This is done by calling the global function 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   686
@code{Simulator::Destroy}.  As the helper functions (or low level 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   687
@command{ns-3} code) executed, they arranged it so that hooks were inserted in
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   688
the simulator to destroy all of the objects that were created.  You did not 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   689
have to keep track of any of these objects yourself --- all you had to do 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   690
was to call @code{Simulator::Destroy} and exit.  The @command{ns-3} system
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   691
took care of the hard part for you.  The remaining lines of our first 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   692
@command{ns-3} script, @code{first.cc}, do just that:
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   693
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   694
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   695
    Simulator::Destroy ();
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   696
    return 0;
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   697
  }
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   698
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   699
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   700
@subsection Building Your Script
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   701
We have made it trivial to build your simple scripts.  All you have to do is 
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   702
to drop your script into the scratch directory and it will automatically be 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   703
built if you run Waf.  Let's try it.  Copy @code{examples/first.cc} into 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   704
the @code{scratch} directory.
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   705
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   706
@verbatim
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   707
  ~/repos/ns-3-tutorial > cp examples/first.cc scratch/
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   708
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   709
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   710
and then build it using waf,
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   711
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   712
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   713
  ~/repos/ns-3-tutorial > ./waf
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   714
  Entering directory `/home/craigdo/repos/ns-3-tutorial/build'
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   715
  [432/477] cxx: scratch/first.cc -> build/debug/scratch/first_2.o
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   716
  [475/477] cxx_link: build/debug/scratch/first_2.o ...
3332
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   717
  Compilation finished successfully
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   718
~/repos/ns-3-tutorial >
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   719
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   720
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   721
You can now run the example (note that if you build your program in the scratch
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   722
directory you must run it out of the scratch direcory):
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   723
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   724
@verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   725
  ~/repos/ns-3-tutorial > ./waf --run scratch/first
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   726
  Entering directory `/home/craigdo/repos/ns-3-tutorial/build'
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   727
  Compilation finished successfully
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   728
  Sent 1024 bytes to 10.1.1.2
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   729
  Received 1024 bytes from 10.1.1.1
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   730
  Received 1024 bytes from 10.1.1.2
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   731
  ~/repos/ns-3-tutorial >
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   732
@end verbatim
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   733
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   734
Here you see that the build system checks to make sure that the file has been
da67e8efa347 swap in new tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   735
build and then runs it.  You see the logging component on the echo client 
3345
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   736
indicate that it has sent one 1024 byte packet to the Echo Server on 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   737
10.1.1.2.  You also see the logging component on the echo server say that
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   738
it has received the 1024 bytes from 10.1.1.1.  The echo server silently 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   739
echoes the packet and you see the echo client log that it has received its 
b0af63b9f9a6 editing pass through the tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 3339
diff changeset
   740
packet back from the server.