doc/tutorial/source/conceptual-overview.rst
author Tom Henderson <tomh@tomh.org>
Sat, 16 Jan 2016 08:14:40 -0800
changeset 11683 9142266fbb25
parent 11681 d0b2d73051f7
permissions -rw-r--r--
add figures to main documentation build
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     1
.. include:: replace.txt
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9195
diff changeset
     2
.. highlight:: cpp
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     3
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     4
Conceptual Overview
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
-------------------
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     6
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     7
The first thing we need to do before actually starting to look at or write
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     8
|ns3| code is to explain a few core concepts and abstractions in the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     9
system.  Much of this may appear transparently obvious to some, but we
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    10
recommend taking the time to read through this section just to ensure you
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    11
are starting on a firm foundation.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    12
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    13
Key Abstractions
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
****************
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    15
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    16
In this section, we'll review some terms that are commonly used in
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    17
networking, but have a specific meaning in |ns3|.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    19
Node
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
++++
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    21
In Internet jargon, a computing device that connects to a network is called
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    22
a *host* or sometimes an *end system*.  Because |ns3| is a 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    23
*network* simulator, not specifically an *Internet* simulator, we 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    24
intentionally do not use the term host since it is closely associated with
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    25
the Internet and its protocols.  Instead, we use a more generic term also
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    26
used by other simulators that originates in Graph Theory --- the *node*.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    27
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    28
In |ns3| the basic computing device abstraction is called the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    29
node.  This abstraction is represented in C++ by the class ``Node``.  The 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    30
``Node`` class provides methods for managing the representations of 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    31
computing devices in simulations.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    32
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
You should think of a ``Node`` as a computer to which you will add 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    34
functionality.  One adds things like applications, protocol stacks and
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    35
peripheral cards with their associated drivers to enable the computer to do
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    36
useful work.  We use the same basic model in |ns3|.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    37
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    38
Application
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    39
+++++++++++
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    40
Typically, computer software is divided into two broad classes.  *System
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    41
Software* organizes various computer resources such as memory, processor
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    42
cycles, disk, network, etc., according to some computing model.  System
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    43
software usually does not use those resources to complete tasks that directly
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    44
benefit a user.  A user would typically run an *application* that acquires
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    45
and uses the resources controlled by the system software to accomplish some
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    46
goal.  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    47
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    48
Often, the line of separation between system and application software is made
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    49
at the privilege level change that happens in operating system traps.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    50
In |ns3| there is no real concept of operating system and especially
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    51
no concept of privilege levels or system calls.  We do, however, have the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    52
idea of an application.  Just as software applications run on computers to
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    53
perform tasks in the "real world," |ns3| applications run on
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    54
|ns3| ``Nodes`` to drive simulations in the simulated world.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    55
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    56
In |ns3| the basic abstraction for a user program that generates some
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    57
activity to be simulated is the application.  This abstraction is represented 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    58
in C++ by the class ``Application``.  The ``Application`` class provides 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    59
methods for managing the representations of our version of user-level 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    60
applications in simulations.  Developers are expected to specialize the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    61
``Application`` class in the object-oriented programming sense to create new
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    62
applications.  In this tutorial, we will use specializations of class 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    63
``Application`` called ``UdpEchoClientApplication`` and 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    64
``UdpEchoServerApplication``.  As you might expect, these applications 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    65
compose a client/server application set used to generate and echo simulated 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    66
network packets 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    67
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    68
Channel
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    69
+++++++
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    70
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    71
In the real world, one can connect a computer to a network.  Often the media
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    72
over which data flows in these networks are called *channels*.  When
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    73
you connect your Ethernet cable to the plug in the wall, you are connecting 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    74
your computer to an Ethernet communication channel.  In the simulated world
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    75
of |ns3|, one connects a ``Node`` to an object representing a
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    76
communication channel.  Here the basic communication subnetwork abstraction 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    77
is called the channel and is represented in C++ by the class ``Channel``.  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    78
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    79
The ``Channel`` class provides methods for managing communication 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    80
subnetwork objects and connecting nodes to them.  ``Channels`` may also be
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    81
specialized by developers in the object oriented programming sense.  A 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    82
``Channel`` specialization may model something as simple as a wire.  The 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    83
specialized  ``Channel`` can also model things as complicated as a large 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    84
Ethernet switch, or three-dimensional space full of obstructions in the case 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    85
of wireless networks.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    86
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    87
We will use specialized versions of the ``Channel`` called
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    88
``CsmaChannel``, ``PointToPointChannel`` and ``WifiChannel`` in this
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    89
tutorial.  The ``CsmaChannel``, for example, models a version of a 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    90
communication subnetwork that implements a *carrier sense multiple 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    91
access* communication medium.  This gives us Ethernet-like functionality.  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    92
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    93
Net Device
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    94
++++++++++
11221
243001f59f66 fix tutorial typos (found by Renan)
Tom Henderson <tomh@tomh.org>
parents: 10950
diff changeset
    95
It used to be the case that if you wanted to connect a computer to a network,
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    96
you had to buy a specific kind of network cable and a hardware device called
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    97
(in PC terminology) a *peripheral card* that needed to be installed in
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    98
your computer.  If the peripheral card implemented some networking function,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    99
they were called Network Interface Cards, or *NICs*.  Today most 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   100
computers come with the network interface hardware built in and users don't 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   101
see these building blocks.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   102
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   103
A NIC will not work without a software driver to control the hardware.  In 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   104
Unix (or Linux), a piece of peripheral hardware is classified as a 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   105
*device*.  Devices are controlled using *device drivers*, and network
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   106
devices (NICs) are controlled using *network device drivers*
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   107
collectively known as *net devices*.  In Unix and Linux you refer
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   108
to these net devices by names such as *eth0*.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   109
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   110
In |ns3| the *net device* abstraction covers both the software 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   111
driver and the simulated hardware.  A net device is "installed" in a 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   112
``Node`` in order to enable the ``Node`` to communicate with other 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   113
``Nodes`` in the simulation via ``Channels``.  Just as in a real
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   114
computer, a ``Node`` may be connected to more than one ``Channel`` via
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   115
multiple ``NetDevices``.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   116
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   117
The net device abstraction is represented in C++ by the class ``NetDevice``.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   118
The ``NetDevice`` class provides methods for managing connections to 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   119
``Node`` and ``Channel`` objects; and may be specialized by developers
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   120
in the object-oriented programming sense.  We will use the several specialized
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   121
versions of the ``NetDevice`` called ``CsmaNetDevice``,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   122
``PointToPointNetDevice``, and ``WifiNetDevice`` in this tutorial.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   123
Just as an Ethernet NIC is designed to work with an Ethernet network, the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   124
``CsmaNetDevice`` is designed to work with a ``CsmaChannel``; the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   125
``PointToPointNetDevice`` is designed to work with a 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   126
``PointToPointChannel`` and a ``WifiNetNevice`` is designed to work with
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   127
a ``WifiChannel``.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   128
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   129
Topology Helpers
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   130
++++++++++++++++
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   131
In a real network, you will find host computers with added (or built-in)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   132
NICs.  In |ns3| we would say that you will find ``Nodes`` with 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   133
attached ``NetDevices``.  In a large simulated network you will need to 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   134
arrange many connections between ``Nodes``, ``NetDevices`` and 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   135
``Channels``.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   136
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   137
Since connecting ``NetDevices`` to ``Nodes``, ``NetDevices``
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   138
to ``Channels``, assigning IP addresses,  etc., are such common tasks
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   139
in |ns3|, we provide what we call *topology helpers* to make 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   140
this as easy as possible.  For example, it may take many distinct 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   141
|ns3| core operations to create a NetDevice, add a MAC address, 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   142
install that net device on a ``Node``, configure the node's protocol stack,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   143
and then connect the ``NetDevice`` to a ``Channel``.  Even more
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   144
operations would be required to connect multiple devices onto multipoint 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   145
channels and then to connect individual networks together into internetworks.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   146
We provide topology helper objects that combine those many distinct operations
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   147
into an easy to use model for your convenience.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   148
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   149
A First ns-3 Script
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   150
*******************
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   151
If you downloaded the system as was suggested above, you will have a release
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   152
of |ns3| in a directory called ``repos`` under your home 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   153
directory.  Change into that release directory, and you should find a 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   154
directory structure something like the following:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   155
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9195
diff changeset
   156
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   157
7275
83f76a2f8449 documentation fixes
Andrey Mazo <mazo@iitp.ru>
parents: 7147
diff changeset
   158
  AUTHORS       examples       scratch        utils      waf.bat*
83f76a2f8449 documentation fixes
Andrey Mazo <mazo@iitp.ru>
parents: 7147
diff changeset
   159
  bindings      LICENSE        src            utils.py   waf-tools
83f76a2f8449 documentation fixes
Andrey Mazo <mazo@iitp.ru>
parents: 7147
diff changeset
   160
  build         ns3            test.py*       utils.pyc  wscript
83f76a2f8449 documentation fixes
Andrey Mazo <mazo@iitp.ru>
parents: 7147
diff changeset
   161
  CHANGES.html  README         testpy-output  VERSION    wutils.py
83f76a2f8449 documentation fixes
Andrey Mazo <mazo@iitp.ru>
parents: 7147
diff changeset
   162
  doc           RELEASE_NOTES  testpy.supp    waf*       wutils.pyc
83f76a2f8449 documentation fixes
Andrey Mazo <mazo@iitp.ru>
parents: 7147
diff changeset
   163
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   164
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   165
Change into the ``examples/tutorial`` directory.  You should see a file named 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   166
``first.cc`` located there.  This is a script that will create a simple
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   167
point-to-point link between two nodes and echo a single packet between the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   168
nodes.  Let's take a look at that script line by line, so go ahead and open
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   169
``first.cc`` in your favorite editor.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   170
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   171
Boilerplate
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   172
+++++++++++
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   173
The first line in the file is an emacs mode line.  This tells emacs about the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   174
formatting conventions (coding style) we use in our source code.  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   175
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   176
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   177
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   178
  /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   179
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   180
This is always a somewhat controversial subject, so we might as well get it
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   181
out of the way immediately.  The |ns3| project, like most large 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   182
projects, has adopted a coding style to which all contributed code must 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   183
adhere.  If you want to contribute your code to the project, you will 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   184
eventually have to conform to the |ns3| coding standard as described 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   185
in the file ``doc/codingstd.txt`` or shown on the project web page
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   186
`here
7867
87c579ca5690 fix broken tutorial link
Bruno Haick <bghaick@hotmail.com>
parents: 7479
diff changeset
   187
<http://www.nsnam.org/developers/contributing-code/coding-style/>`_.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   188
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   189
We recommend that you, well, just get used to the look and feel of |ns3|
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   190
code and adopt this standard whenever you are working with our code.  All of 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   191
the development team and contributors have done so with various amounts of 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   192
grumbling.  The emacs mode line above makes it easier to get the formatting 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   193
correct if you use the emacs editor.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   194
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   195
The |ns3| simulator is licensed using the GNU General Public 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   196
License.  You will see the appropriate GNU legalese at the head of every file 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   197
in the |ns3| distribution.  Often you will see a copyright notice for
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   198
one of the institutions involved in the |ns3| project above the GPL
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   199
text and an author listed below.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   200
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   201
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   202
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   203
  /*
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   204
   * This program is free software; you can redistribute it and/or modify
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   205
   * it under the terms of the GNU General Public License version 2 as
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   206
   * published by the Free Software Foundation;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   207
   *
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   208
   * This program is distributed in the hope that it will be useful,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   209
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   210
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   211
   * GNU General Public License for more details.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   212
   *
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   213
   * You should have received a copy of the GNU General Public License
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   214
   * along with this program; if not, write to the Free Software
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   215
   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   216
   */
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   217
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   218
Module Includes
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   219
+++++++++++++++
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   220
The code proper starts with a number of include statements.  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   221
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   222
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   223
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   224
  #include "ns3/core-module.h"
7137
dbefbad7bee3 Fix module names in documentation
Mitch Watrous <watrous@u.washington.edu>
parents: 7025
diff changeset
   225
  #include "ns3/network-module.h"
dbefbad7bee3 Fix module names in documentation
Mitch Watrous <watrous@u.washington.edu>
parents: 7025
diff changeset
   226
  #include "ns3/internet-module.h"
dbefbad7bee3 Fix module names in documentation
Mitch Watrous <watrous@u.washington.edu>
parents: 7025
diff changeset
   227
  #include "ns3/point-to-point-module.h"
dbefbad7bee3 Fix module names in documentation
Mitch Watrous <watrous@u.washington.edu>
parents: 7025
diff changeset
   228
  #include "ns3/applications-module.h"
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   229
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   230
To help our high-level script users deal with the large number of include 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   231
files present in the system, we group includes according to relatively large 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   232
modules.  We provide a single include file that will recursively load all of 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   233
the include files used in each module.  Rather than having to look up exactly
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   234
what header you need, and possibly have to get a number of dependencies right,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   235
we give you the ability to load a group of files at a large granularity.  This
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   236
is not the most efficient approach but it certainly makes writing scripts much
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   237
easier.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   238
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   239
Each of the |ns3| include files is placed in a directory called 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   240
``ns3`` (under the build directory) during the build process to help avoid
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   241
include file name collisions.  The ``ns3/core-module.h`` file corresponds 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   242
to the ns-3 module you will find in the directory ``src/core`` in your 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   243
downloaded release distribution.  If you list this directory you will find a
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   244
large number of header files.  When you do a build, Waf will place public 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   245
header files in an ``ns3`` directory under the appropriate 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   246
``build/debug`` or ``build/optimized`` directory depending on your 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   247
configuration.  Waf will also automatically generate a module include file to
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   248
load all of the public header files.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   249
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   250
Since you are, of course, following this tutorial religiously, you will 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   251
already have done a
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   252
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9195
diff changeset
   253
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   254
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9195
diff changeset
   255
  $ ./waf -d debug --enable-examples --enable-tests configure
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   256
6998
1c2b8cfb71d2 Make tests not be built by default
Mitch Watrous <watrous@u.washington.edu>
parents: 6754
diff changeset
   257
in order to configure the project to perform debug builds that include 
7024
4392d52b3536 Make examples not be built by default
Mitch Watrous <watrous@u.washington.edu>
parents: 6998
diff changeset
   258
examples and tests.  You will also have done a
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   259
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9195
diff changeset
   260
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   261
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9195
diff changeset
   262
  $ ./waf
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   263
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   264
to build the project.  So now if you look in the directory 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   265
``../../build/debug/ns3`` you will find the four module include files shown 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   266
above.  You can take a look at the contents of these files and find that they
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   267
do include all of the public include files in their respective modules.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   268
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   269
Ns3 Namespace
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   270
+++++++++++++
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   271
The next line in the ``first.cc`` script is a namespace declaration.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   272
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   273
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   274
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   275
  using namespace ns3;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   276
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   277
The |ns3| project is implemented in a C++ namespace called 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   278
``ns3``.  This groups all |ns3|-related declarations in a scope
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   279
outside the global namespace, which we hope will help with integration with 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   280
other code.  The C++ ``using`` statement introduces the |ns3|
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   281
namespace into the current (global) declarative region.  This is a fancy way
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   282
of saying that after this declaration, you will not have to type ``ns3::``
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   283
scope resolution operator before all of the |ns3| code in order to use
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   284
it.  If you are unfamiliar with namespaces, please consult almost any C++ 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   285
tutorial and compare the ``ns3`` namespace and usage here with instances of
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   286
the ``std`` namespace and the ``using namespace std;`` statements you 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   287
will often find in discussions of ``cout`` and streams.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   288
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   289
Logging
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   290
+++++++
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   291
The next line of the script is the following,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   292
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   293
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   294
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   295
  NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   296
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   297
We will use this statement as a convenient place to talk about our Doxygen
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   298
documentation system.  If you look at the project web site, 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   299
`ns-3 project
7479
0ff4a85b9e04 Fix references to old website in Tutorial
Mitch Watrous <watrous@u.washington.edu>
parents: 7275
diff changeset
   300
<http://www.nsnam.org>`_, you will find a link to "Documentation" in the navigation bar.  If you select this link, you will be
0ff4a85b9e04 Fix references to old website in Tutorial
Mitch Watrous <watrous@u.washington.edu>
parents: 7275
diff changeset
   301
taken to our documentation page. There 
0ff4a85b9e04 Fix references to old website in Tutorial
Mitch Watrous <watrous@u.washington.edu>
parents: 7275
diff changeset
   302
is a link to "Latest Release" that will take you to the documentation
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   303
for the latest stable release of |ns3|.
7479
0ff4a85b9e04 Fix references to old website in Tutorial
Mitch Watrous <watrous@u.washington.edu>
parents: 7275
diff changeset
   304
If you select the "API Documentation" link, you will be
0ff4a85b9e04 Fix references to old website in Tutorial
Mitch Watrous <watrous@u.washington.edu>
parents: 7275
diff changeset
   305
taken to the |ns3| API documentation page.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   306
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   307
Along the left side, you will find a graphical representation of the structure
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   308
of the documentation.  A good place to start is the ``NS-3 Modules``
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   309
"book" in the |ns3| navigation tree.  If you expand ``Modules`` 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   310
you will see a list of |ns3| module documentation.  The concept of 
11681
d0b2d73051f7 update some stale tutorial info
Tom Henderson <tomh@tomh.org>
parents: 11221
diff changeset
   311
module here ties directly into the module include files discussed above.  The |ns3| logging subsystem is discussed in the :ref:`UsingLogging` section, so
d0b2d73051f7 update some stale tutorial info
Tom Henderson <tomh@tomh.org>
parents: 11221
diff changeset
   312
we'll get to it later in this tutorial, but you can find out about the above
d0b2d73051f7 update some stale tutorial info
Tom Henderson <tomh@tomh.org>
parents: 11221
diff changeset
   313
statement by looking at the ``Core`` module, then expanding the 
d0b2d73051f7 update some stale tutorial info
Tom Henderson <tomh@tomh.org>
parents: 11221
diff changeset
   314
``Debugging tools`` book, and then selecting the ``Logging`` page.  Click
d0b2d73051f7 update some stale tutorial info
Tom Henderson <tomh@tomh.org>
parents: 11221
diff changeset
   315
on ``Logging``.
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   316
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   317
You should now be looking at the Doxygen documentation for the Logging module.
11681
d0b2d73051f7 update some stale tutorial info
Tom Henderson <tomh@tomh.org>
parents: 11221
diff changeset
   318
In the list of ``Macros``'s at the top of the page you will see the entry
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   319
for ``NS_LOG_COMPONENT_DEFINE``.  Before jumping in, it would probably be 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   320
good to look for the "Detailed Description" of the logging module to get a 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   321
feel for the overall operation.  You can either scroll down or select the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   322
"More..." link under the collaboration diagram to do this.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   323
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   324
Once you have a general idea of what is going on, go ahead and take a look at
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   325
the specific ``NS_LOG_COMPONENT_DEFINE`` documentation.  I won't duplicate
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   326
the documentation here, but to summarize, this line declares a logging 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   327
component called ``FirstScriptExample`` that allows you to enable and 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   328
disable console message logging by reference to the name.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   329
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   330
Main Function
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   331
+++++++++++++
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   332
The next lines of the script you will find are,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   333
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   334
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   335
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   336
  int
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   337
  main (int argc, char *argv[])
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   338
  {
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   339
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   340
This is just the declaration of the main function of your program (script).
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   341
Just as in any C++ program, you need to define a main function that will be 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   342
the first function run.  There is nothing at all special here.  Your 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   343
|ns3| script is just a C++ program.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   344
10171
0b3ce943b7c8 bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   345
The next line sets the time resolution to one nanosecond, which happens
0b3ce943b7c8 bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   346
to be the default value:
0b3ce943b7c8 bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   347
0b3ce943b7c8 bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   348
::
0b3ce943b7c8 bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   349
0b3ce943b7c8 bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   350
    Time::SetResolution (Time::NS);
0b3ce943b7c8 bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   351
0b3ce943b7c8 bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   352
The resolution is the smallest time value that can be represented (as well as
0b3ce943b7c8 bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   353
the smallest representable difference between two time values).
0b3ce943b7c8 bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   354
You can change the resolution exactly once.  The mechanism enabling this
0b3ce943b7c8 bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   355
flexibility is somewhat memory hungry, so once the resolution has been
0b3ce943b7c8 bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   356
set explicitly we release the memory, preventing further updates.   (If
0b3ce943b7c8 bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   357
you don't set the resolution explicitly, it will default to one nanosecond,
0b3ce943b7c8 bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   358
and the memory will be released when the simulation starts.)
0b3ce943b7c8 bug 954: Changing the simulation time resolution does not work well with attributes
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9957
diff changeset
   359
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   360
The next two lines of the script are used to enable two logging components that
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   361
are built into the Echo Client and Echo Server applications:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   362
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   363
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   364
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   365
    LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   366
    LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   367
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   368
If you have read over the Logging component documentation you will have seen
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   369
that there are a number of levels of logging verbosity/detail that you can 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   370
enable on each component.  These two lines of code enable debug logging at the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   371
INFO level for echo clients and servers.  This will result in the application
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   372
printing out messages as packets are sent and received during the simulation.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   373
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   374
Now we will get directly to the business of creating a topology and running 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   375
a simulation.  We use the topology helper objects to make this job as
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   376
easy as possible.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   377
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   378
Topology Helpers
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   379
++++++++++++++++
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   380
NodeContainer
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   381
~~~~~~~~~~~~~
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   382
The next two lines of code in our script will actually create the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   383
|ns3| ``Node`` objects that will represent the computers in the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   384
simulation.  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   385
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   386
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   387
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   388
    NodeContainer nodes;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   389
    nodes.Create (2);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   390
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   391
Let's find the documentation for the ``NodeContainer`` class before we
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   392
continue.  Another way to get into the documentation for a given class is via 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   393
the ``Classes`` tab in the Doxygen pages.  If you still have the Doxygen 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   394
handy, just scroll up to the top of the page and select the ``Classes`` 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   395
tab.  You should see a new set of tabs appear, one of which is 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   396
``Class List``.  Under that tab you will see a list of all of the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   397
|ns3| classes.  Scroll down, looking for ``ns3::NodeContainer``.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   398
When you find the class, go ahead and select it to go to the documentation for
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   399
the class.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   400
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   401
You may recall that one of our key abstractions is the ``Node``.  This
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   402
represents a computer to which we are going to add things like protocol stacks,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   403
applications and peripheral cards.  The ``NodeContainer`` topology helper
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   404
provides a convenient way to create, manage and access any ``Node`` objects
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   405
that we create in order to run a simulation.  The first line above just 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   406
declares a NodeContainer which we call ``nodes``.  The second line calls the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   407
``Create`` method on the ``nodes`` object and asks the container to 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   408
create two nodes.  As described in the Doxygen, the container calls down into
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   409
the |ns3| system proper to create two ``Node`` objects and stores
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   410
pointers to those objects internally.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   411
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   412
The nodes as they stand in the script do nothing.  The next step in 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   413
constructing a topology is to connect our nodes together into a network.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   414
The simplest form of network we support is a single point-to-point link 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   415
between two nodes.  We'll construct one of those links here.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   416
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   417
PointToPointHelper
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   418
~~~~~~~~~~~~~~~~~~
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   419
We are constructing a point to point link, and, in a pattern which will become
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   420
quite familiar to you, we use a topology helper object to do the low-level
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   421
work required to put the link together.  Recall that two of our key 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   422
abstractions are the ``NetDevice`` and the ``Channel``.  In the real
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   423
world, these terms correspond roughly to peripheral cards and network cables.  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   424
Typically these two things are intimately tied together and one cannot expect
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   425
to interchange, for example, Ethernet devices and wireless channels.  Our 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   426
Topology Helpers follow this intimate coupling and therefore you will use a
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   427
single ``PointToPointHelper`` to configure and connect |ns3|
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   428
``PointToPointNetDevice`` and ``PointToPointChannel`` objects in this 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   429
script.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   430
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   431
The next three lines in the script are,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   432
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   433
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   434
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   435
    PointToPointHelper pointToPoint;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   436
    pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   437
    pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   438
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   439
The first line,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   440
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   441
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   442
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   443
    PointToPointHelper pointToPoint;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   444
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   445
instantiates a ``PointToPointHelper`` object on the stack.  From a 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   446
high-level perspective the next line,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   447
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   448
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   449
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   450
    pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   451
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   452
tells the ``PointToPointHelper`` object to use the value "5Mbps"
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   453
(five megabits per second) as the "DataRate" when it creates a 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   454
``PointToPointNetDevice`` object.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   455
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   456
From a more detailed perspective, the string "DataRate" corresponds
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   457
to what we call an ``Attribute`` of the ``PointToPointNetDevice``.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   458
If you look at the Doxygen for class ``ns3::PointToPointNetDevice`` and 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   459
find the documentation for the ``GetTypeId`` method, you will find a list
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   460
of  ``Attributes`` defined for the device.  Among these is the "DataRate"
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   461
``Attribute``.  Most user-visible |ns3| objects have similar lists of 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   462
``Attributes``.  We use this mechanism to easily configure simulations without
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   463
recompiling as you will see in a following section.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   464
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   465
Similar to the "DataRate" on the ``PointToPointNetDevice`` you will find a
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   466
"Delay" ``Attribute`` associated with the ``PointToPointChannel``.  The 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   467
final line,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   468
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   469
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   470
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   471
    pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   472
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   473
tells the ``PointToPointHelper`` to use the value "2ms" (two milliseconds)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   474
as the value of the transmission delay of every point to point channel it 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   475
subsequently creates.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   476
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   477
NetDeviceContainer
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   478
~~~~~~~~~~~~~~~~~~
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   479
At this point in the script, we have a ``NodeContainer`` that contains
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   480
two nodes.  We have a ``PointToPointHelper`` that is primed and ready to 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   481
make ``PointToPointNetDevices`` and wire ``PointToPointChannel`` objects
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   482
between them.  Just as we used the ``NodeContainer`` topology helper object
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   483
to create the ``Nodes`` for our simulation, we will ask the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   484
``PointToPointHelper`` to do the work involved in creating, configuring and
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   485
installing our devices for us.  We will need to have a list of all of the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   486
NetDevice objects that are created, so we use a NetDeviceContainer to hold 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   487
them just as we used a NodeContainer to hold the nodes we created.  The 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   488
following two lines of code,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   489
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   490
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   491
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   492
    NetDeviceContainer devices;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   493
    devices = pointToPoint.Install (nodes);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   494
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   495
will finish configuring the devices and channel.  The first line declares the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   496
device container mentioned above and the second does the heavy lifting.  The 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   497
``Install`` method of the ``PointToPointHelper`` takes a 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   498
``NodeContainer`` as a parameter.  Internally, a ``NetDeviceContainer`` 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   499
is created.  For each node in the ``NodeContainer`` (there must be exactly 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   500
two for a point-to-point link) a ``PointToPointNetDevice`` is created and 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   501
saved in the device container.  A ``PointToPointChannel`` is created and 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   502
the two ``PointToPointNetDevices`` are attached.  When objects are created
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   503
by the ``PointToPointHelper``, the ``Attributes`` previously set in the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   504
helper are used to initialize the corresponding ``Attributes`` in the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   505
created objects.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   506
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   507
After executing the ``pointToPoint.Install (nodes)`` call we will have
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   508
two nodes, each with an installed point-to-point net device and a single
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   509
point-to-point channel between them.  Both devices will be configured to 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   510
transmit data at five megabits per second over the channel which has a two 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   511
millisecond transmission delay.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   512
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   513
InternetStackHelper
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   514
~~~~~~~~~~~~~~~~~~~
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   515
We now have nodes and devices configured, but we don't have any protocol stacks
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   516
installed on our nodes.  The next two lines of code will take care of that.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   517
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   518
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   519
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   520
    InternetStackHelper stack;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   521
    stack.Install (nodes);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   522
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   523
The ``InternetStackHelper`` is a topology helper that is to internet stacks
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   524
what the ``PointToPointHelper`` is to point-to-point net devices.  The
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   525
``Install`` method takes a ``NodeContainer`` as a parameter.  When it is
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   526
executed, it will install an Internet Stack (TCP, UDP, IP, etc.) on each of
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   527
the nodes in the node container.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   528
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   529
Ipv4AddressHelper
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   530
~~~~~~~~~~~~~~~~~
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   531
Next we need to associate the devices on our nodes with IP addresses.  We 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   532
provide a topology helper to manage the allocation of IP addresses.  The only
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   533
user-visible API is to set the base IP address and network mask to use when
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   534
performing the actual address allocation (which is done at a lower level 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   535
inside the helper).
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   536
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   537
The next two lines of code in our example script, ``first.cc``,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   538
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   539
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   540
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   541
    Ipv4AddressHelper address;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   542
    address.SetBase ("10.1.1.0", "255.255.255.0");
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   543
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   544
declare an address helper object and tell it that it should begin allocating IP
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   545
addresses from the network 10.1.1.0 using the mask 255.255.255.0 to define 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   546
the allocatable bits.  By default the addresses allocated will start at one
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   547
and increase monotonically, so the first address allocated from this base will
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   548
be 10.1.1.1, followed by 10.1.1.2, etc.  The low level |ns3| system
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   549
actually remembers all of the IP addresses allocated and will generate a
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   550
fatal error if you accidentally cause the same address to be generated twice 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   551
(which is a very hard to debug error, by the way).
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   552
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   553
The next line of code,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   554
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   555
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   556
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   557
    Ipv4InterfaceContainer interfaces = address.Assign (devices);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   558
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   559
performs the actual address assignment.  In |ns3| we make the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   560
association between an IP address and a device using an ``Ipv4Interface``
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   561
object.  Just as we sometimes need a list of net devices created by a helper 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   562
for future reference we sometimes need a list of ``Ipv4Interface`` objects.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   563
The ``Ipv4InterfaceContainer`` provides this functionality.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   564
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   565
Now we have a point-to-point network built, with stacks installed and IP 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   566
addresses assigned.  What we need at this point are applications to generate
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   567
traffic.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   568
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   569
Applications
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   570
++++++++++++
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   571
Another one of the core abstractions of the ns-3 system is the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   572
``Application``.  In this script we use two specializations of the core
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   573
|ns3| class ``Application`` called ``UdpEchoServerApplication``
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   574
and ``UdpEchoClientApplication``.  Just as we have in our previous 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   575
explanations,  we use helper objects to help configure and manage the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   576
underlying objects.  Here, we use ``UdpEchoServerHelper`` and
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   577
``UdpEchoClientHelper`` objects to make our lives easier.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   578
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   579
UdpEchoServerHelper
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   580
~~~~~~~~~~~~~~~~~~~
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   581
The following lines of code in our example script, ``first.cc``, are used
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   582
to set up a UDP echo server application on one of the nodes we have previously
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   583
created.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   584
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   585
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   586
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   587
    UdpEchoServerHelper echoServer (9);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   588
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   589
    ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   590
    serverApps.Start (Seconds (1.0));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   591
    serverApps.Stop (Seconds (10.0));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   592
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   593
The first line of code in the above snippet declares the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   594
``UdpEchoServerHelper``.  As usual, this isn't the application itself, it
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   595
is an object used to help us create the actual applications.  One of our 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   596
conventions is to place *required* ``Attributes`` in the helper constructor.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   597
In this case, the helper can't do anything useful unless it is provided with
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   598
a port number that the client also knows about.  Rather than just picking one 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   599
and hoping it all works out, we require the port number as a parameter to the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   600
constructor.  The constructor, in turn, simply does a ``SetAttribute``
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   601
with the passed value.  If you want, you can set the "Port" ``Attribute``
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   602
to another value later using ``SetAttribute``.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   603
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   604
Similar to many other helper objects, the ``UdpEchoServerHelper`` object 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   605
has an ``Install`` method.  It is the execution of this method that actually
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   606
causes the underlying echo server application to be instantiated and attached
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   607
to a node.  Interestingly, the ``Install`` method takes a
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   608
``NodeContainter`` as a parameter just as the other ``Install`` methods
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   609
we have seen.  This is actually what is passed to the method even though it 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   610
doesn't look so in this case.  There is a C++ *implicit conversion* at
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   611
work here that takes the result of ``nodes.Get (1)`` (which returns a smart
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   612
pointer to a node object --- ``Ptr<Node>``) and uses that in a constructor
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   613
for an unnamed ``NodeContainer`` that is then passed to ``Install``.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   614
If you are ever at a loss to find a particular method signature in C++ code
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   615
that compiles and runs just fine, look for these kinds of implicit conversions.  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   616
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   617
We now see that ``echoServer.Install`` is going to install a
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   618
``UdpEchoServerApplication`` on the node found at index number one of the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   619
``NodeContainer`` we used to manage our nodes.  ``Install`` will return
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   620
a container that holds pointers to all of the applications (one in this case 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   621
since we passed a ``NodeContainer`` containing one node) created by the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   622
helper.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   623
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   624
Applications require a time to "start" generating traffic and may take an
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   625
optional time to "stop".  We provide both.  These times are set using  the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   626
``ApplicationContainer`` methods ``Start`` and ``Stop``.  These 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   627
methods take ``Time`` parameters.  In this case, we use an *explicit*
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   628
C++ conversion sequence to take the C++ double 1.0 and convert it to an 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   629
|ns3| ``Time`` object using a ``Seconds`` cast.  Be aware that
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   630
the conversion rules may be controlled by the model author, and C++ has its
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   631
own rules, so you can't always just assume that parameters will be happily 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   632
converted for you.  The two lines,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   633
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   634
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   635
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   636
    serverApps.Start (Seconds (1.0));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   637
    serverApps.Stop (Seconds (10.0));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   638
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   639
will cause the echo server application to ``Start`` (enable itself) at one
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   640
second into the simulation and to ``Stop`` (disable itself) at ten seconds
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   641
into the simulation.  By virtue of the fact that we have declared a simulation
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   642
event (the application stop event) to be executed at ten seconds, the simulation
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   643
will last *at least* ten seconds.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   644
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   645
UdpEchoClientHelper
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   646
~~~~~~~~~~~~~~~~~~~
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   647
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   648
The echo client application is set up in a method substantially similar to
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   649
that for the server.  There is an underlying ``UdpEchoClientApplication``
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   650
that is managed by an ``UdpEchoClientHelper``.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   651
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   652
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   653
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   654
    UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   655
    echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
9112
ede7a74e7411 bug 1514: make TimeValue usage consistent in the tutorial
Tom Henderson <tomh@tomh.org>
parents: 7867
diff changeset
   656
    echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   657
    echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   658
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   659
    ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   660
    clientApps.Start (Seconds (2.0));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   661
    clientApps.Stop (Seconds (10.0));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   662
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   663
For the echo client, however, we need to set five different ``Attributes``.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   664
The first two ``Attributes`` are set during construction of the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   665
``UdpEchoClientHelper``.  We pass parameters that are used (internally to
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   666
the helper) to set the "RemoteAddress" and "RemotePort" ``Attributes``
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   667
in accordance with our convention to make required ``Attributes`` parameters
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   668
in the helper constructors.  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   669
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   670
Recall that we used an ``Ipv4InterfaceContainer`` to keep track of the IP 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   671
addresses we assigned to our devices.  The zeroth interface in the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   672
``interfaces`` container is going to correspond to the IP address of the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   673
zeroth node in the ``nodes`` container.  The first interface in the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   674
``interfaces`` container corresponds to the IP address of the first node 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   675
in the ``nodes`` container.  So, in the first line of code (from above), we
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   676
are creating the helper and telling it so set the remote address of the client
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   677
to be  the IP address assigned to the node on which the server resides.  We 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   678
also tell it to arrange to send packets to port nine.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   679
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   680
The "MaxPackets" ``Attribute`` tells the client the maximum number of 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   681
packets we allow it to send during the simulation.  The "Interval" 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   682
``Attribute`` tells the client how long to wait between packets, and the
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   683
"PacketSize" ``Attribute`` tells the client how large its packet payloads
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   684
should be.  With this particular combination of ``Attributes``, we are 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   685
telling the client to send one 1024-byte packet.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   686
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   687
Just as in the case of the echo server, we tell the echo client to ``Start``
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   688
and ``Stop``, but here we start the client one second after the server is
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   689
enabled (at two seconds into the simulation).
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   690
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   691
Simulator
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   692
+++++++++
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   693
What we need to do at this point is to actually run the simulation.  This is 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   694
done using the global function ``Simulator::Run``.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   695
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   696
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   697
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   698
    Simulator::Run ();
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   699
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   700
When we previously called the methods,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   701
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   702
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   703
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   704
    serverApps.Start (Seconds (1.0));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   705
    serverApps.Stop (Seconds (10.0));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   706
    ...
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   707
    clientApps.Start (Seconds (2.0));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   708
    clientApps.Stop (Seconds (10.0));
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   709
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   710
we actually scheduled events in the simulator at 1.0 seconds, 2.0 seconds and
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   711
two events at 10.0 seconds.  When ``Simulator::Run`` is called, the system 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   712
will begin looking through the list of scheduled events and executing them.  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   713
First it will run the event at 1.0 seconds, which will enable the echo server 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   714
application (this event may, in turn, schedule many other events).  Then it 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   715
will run the event scheduled for t=2.0 seconds which will start the echo client
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   716
application.  Again, this event may schedule many more events.  The start event
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   717
implementation in the echo client application will begin the data transfer phase
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   718
of the simulation by sending a packet to the server.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   719
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   720
The act of sending the packet to the server will trigger a chain of events
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   721
that will be automatically scheduled behind the scenes and which will perform 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   722
the mechanics of the packet echo according to the various timing parameters 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   723
that we have set in the script.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   724
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   725
Eventually, since we only send one packet (recall the ``MaxPackets`` 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   726
``Attribute`` was set to one), the chain of events triggered by 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   727
that single client echo request will taper off and the simulation will go 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   728
idle.  Once this happens, the remaining events will be the ``Stop`` events
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   729
for the server and the client.  When these events are executed, there are
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   730
no further events to process and ``Simulator::Run`` returns.  The simulation
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   731
is then complete.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   732
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   733
All that remains is to clean up.  This is done by calling the global function 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   734
``Simulator::Destroy``.  As the helper functions (or low level 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   735
|ns3| code) executed, they arranged it so that hooks were inserted in
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   736
the simulator to destroy all of the objects that were created.  You did not 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   737
have to keep track of any of these objects yourself --- all you had to do 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   738
was to call ``Simulator::Destroy`` and exit.  The |ns3| system
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   739
took care of the hard part for you.  The remaining lines of our first 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   740
|ns3| script, ``first.cc``, do just that:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   741
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   742
::
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   743
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   744
    Simulator::Destroy ();
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   745
    return 0;
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   746
  }
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   747
10950
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   748
When the simulator will stop?
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   749
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   750
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   751
|ns3| is a Discrete Event (DE) simulator. In such a simulator, each event is
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   752
associated with its execution time, and the simulation proceeds by executing
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   753
events in the temporal order of simulation time.  Events may cause future
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   754
events to be scheduled (for example, a timer may reschedule itself to
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   755
expire at the next interval).
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   756
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   757
The initial events are usually triggered by each object, e.g., IPv6 will 
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   758
schedule Router Advertisements, Neighbor Solicitations, etc., 
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   759
an Application schedule the first packet sending event, etc.
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   760
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   761
When an event is processed, it may generate zero, one or more events.
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   762
As a simulation executes, events are consumed, but more events may (or may
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   763
not) be generated.
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   764
The simulation will stop automatically when no further events are in the 
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   765
event queue, or when a special Stop event is found. The Stop event is 
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   766
created through the 
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   767
``Simulator::Stop (stopTime);`` function.
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   768
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   769
There is a typical case where ``Simulator::Stop`` is absolutely necessary 
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   770
to stop the simulation: when there is a self-sustaining event.
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   771
Self-sustaining (or recurring) events are events that always reschedule 
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   772
themselves. As a consequence, they always keep the event queue non-empty.
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   773
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   774
There are many protocols and modules containing recurring events, e.g.:
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   775
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   776
* FlowMonitor - periodic check for lost packets
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   777
* RIPng - periodic broadcast of routing tables update
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   778
* etc.
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   779
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   780
In these cases, ``Simulator::Stop`` is necessary to gracefully stop the 
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   781
simulation.  In addition, when |ns3| is in emulation mode, the 
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   782
``RealtimeSimulator`` is used to keep the simulation clock aligned with 
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   783
the machine clock, and ``Simulator::Stop`` is necessary to stop the 
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   784
process.  
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   785
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   786
Many of the simulation programs in the tutorial do not explicitly call
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   787
``Simulator::Stop``, since the event queue will automatically run out
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   788
of events.  However, these programs will also accept a call to 
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   789
``Simulator::Stop``.  For example, the following additional statement
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   790
in the first example program will schedule an explicit stop at 11 seconds: 
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   791
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   792
::
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   793
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   794
  +  Simulator::Stop (Seconds (11.0));
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   795
     Simulator::Run ();
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   796
     Simulator::Destroy ();
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   797
     return 0;
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   798
   }
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   799
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   800
The above wil not actually change the behavior of this program, since
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   801
this particular simulation naturally ends after 10 seconds.  But if you 
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   802
were to change the stop time in the above statement from 11 seconds to 1 
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   803
second, you would notice that the simulation stops before any output is 
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   804
printed to the screen (since the output occurs around time 2 seconds of 
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   805
simulation time).
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   806
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   807
It is important to call ``Simulator::Stop`` *before* calling 
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   808
``Simulator::Run``; otherwise, ``Simulator::Run`` may never return control
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   809
to the main program to execute the stop!
9a28fac0260b update tutorial to describe Simulator::Stop
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10171
diff changeset
   810
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   811
Building Your Script
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   812
++++++++++++++++++++
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   813
We have made it trivial to build your simple scripts.  All you have to do is 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   814
to drop your script into the scratch directory and it will automatically be 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   815
built if you run Waf.  Let's try it.  Copy ``examples/tutorial/first.cc`` into 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   816
the ``scratch`` directory after changing back into the top level directory.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   817
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9195
diff changeset
   818
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   819
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9195
diff changeset
   820
  $ cd ../..
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9195
diff changeset
   821
  $ cp examples/tutorial/first.cc scratch/myfirst.cc
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   822
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   823
Now build your first example script using waf:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   824
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9195
diff changeset
   825
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   826
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9195
diff changeset
   827
  $ ./waf
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   828
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   829
You should see messages reporting that your ``myfirst`` example was built
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   830
successfully.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   831
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9195
diff changeset
   832
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   833
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   834
  Waf: Entering directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   835
  [614/708] cxx: scratch/myfirst.cc -> build/debug/scratch/myfirst_3.o
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   836
  [706/708] cxx_link: build/debug/scratch/myfirst_3.o -> build/debug/scratch/myfirst
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   837
  Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   838
  'build' finished successfully (2.357s)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   839
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   840
You can now run the example (note that if you build your program in the scratch
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   841
directory you must run it out of the scratch directory):
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   842
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9195
diff changeset
   843
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   844
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9195
diff changeset
   845
  $ ./waf --run scratch/myfirst
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   846
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   847
You should see some output:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   848
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9195
diff changeset
   849
.. sourcecode:: bash
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   850
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   851
  Waf: Entering directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   852
  Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone/ns-3-dev/build'
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   853
  'build' finished successfully (0.418s)
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   854
  Sent 1024 bytes to 10.1.1.2
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   855
  Received 1024 bytes from 10.1.1.1
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   856
  Received 1024 bytes from 10.1.1.2
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   857
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   858
Here you see that the build system checks to make sure that the file has been
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   859
build and then runs it.  You see the logging component on the echo client 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   860
indicate that it has sent one 1024 byte packet to the Echo Server on 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   861
10.1.1.2.  You also see the logging component on the echo server say that
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   862
it has received the 1024 bytes from 10.1.1.1.  The echo server silently 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   863
echoes the packet and you see the echo client log that it has received its 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   864
packet back from the server.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   865
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   866
Ns-3 Source Code
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   867
****************
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   868
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   869
Now that you have used some of the |ns3| helpers you may want to 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   870
have a look at some of the source code that implements that functionality.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   871
The most recent code can be browsed on our web server at the following link:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   872
http://code.nsnam.org/ns-3-dev.  There, you will see the Mercurial
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   873
summary page for our |ns3| development tree.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   874
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   875
At the top of the page, you will see a number of links,
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   876
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9195
diff changeset
   877
.. sourcecode:: text
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   878
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   879
  summary | shortlog | changelog | graph | tags | files 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   880
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   881
Go ahead and select the ``files`` link.  This is what the top-level of
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   882
most of our *repositories* will look:
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   883
9957
1a4d84a85bad Manual and Tutorial syntax coloring
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9195
diff changeset
   884
.. sourcecode:: text
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   885
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   886
  drwxr-xr-x                               [up]     
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   887
  drwxr-xr-x                               bindings python  files
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   888
  drwxr-xr-x                               doc              files
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   889
  drwxr-xr-x                               examples         files
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   890
  drwxr-xr-x                               ns3              files
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   891
  drwxr-xr-x                               scratch          files
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   892
  drwxr-xr-x                               src              files
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   893
  drwxr-xr-x                               utils            files
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   894
  -rw-r--r-- 2009-07-01 12:47 +0200 560    .hgignore        file | revisions | annotate
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   895
  -rw-r--r-- 2009-07-01 12:47 +0200 1886   .hgtags          file | revisions | annotate
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   896
  -rw-r--r-- 2009-07-01 12:47 +0200 1276   AUTHORS          file | revisions | annotate
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   897
  -rw-r--r-- 2009-07-01 12:47 +0200 30961  CHANGES.html     file | revisions | annotate
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   898
  -rw-r--r-- 2009-07-01 12:47 +0200 17987  LICENSE          file | revisions | annotate
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   899
  -rw-r--r-- 2009-07-01 12:47 +0200 3742   README           file | revisions | annotate
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   900
  -rw-r--r-- 2009-07-01 12:47 +0200 16171  RELEASE_NOTES    file | revisions | annotate
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   901
  -rw-r--r-- 2009-07-01 12:47 +0200 6      VERSION          file | revisions | annotate
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   902
  -rwxr-xr-x 2009-07-01 12:47 +0200 88110  waf              file | revisions | annotate
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   903
  -rwxr-xr-x 2009-07-01 12:47 +0200 28     waf.bat          file | revisions | annotate
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   904
  -rw-r--r-- 2009-07-01 12:47 +0200 35395  wscript          file | revisions | annotate
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   905
  -rw-r--r-- 2009-07-01 12:47 +0200 7673   wutils.py        file | revisions | annotate
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   906
  
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   907
Our example scripts are in the ``examples`` directory.  If you click on ``examples``
7275
83f76a2f8449 documentation fixes
Andrey Mazo <mazo@iitp.ru>
parents: 7147
diff changeset
   908
you will see a list of subdirectories.  One of the files in ``tutorial`` subdirectory is ``first.cc``.  If
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   909
you click on ``first.cc`` you will find the code you just walked through.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   910
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   911
The source code is mainly in the ``src`` directory.  You can view source
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   912
code either by clicking on the directory name or by clicking on the ``files``
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   913
link to the right of the directory name.  If you click on the ``src``
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   914
directory, you will be taken to the listing of the ``src`` subdirectories.  If you 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   915
then click on ``core`` subdirectory, you will find a list of files.  The first file
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   916
you will find (as of this writing) is ``abort.h``.  If you click on the 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   917
``abort.h`` link, you will be sent to the source file for ``abort.h`` which 
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   918
contains useful macros for exiting scripts if abnormal conditions are detected.
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   919
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   920
The source code for the helpers we have used in this chapter can be found in the 
7147
71adbc0422a5 Fix more paths in the documentation
Mitch Watrous <watrous@u.washington.edu>
parents: 7137
diff changeset
   921
``src/applications/helper`` directory.  Feel free to poke around in the directory tree to
6754
7ff69b244b5b Move tutorial to Sphinx
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   922
get a feel for what is there and the style of |ns3| programs.