doc/manual/other.texi
author Tom Henderson <tomh@tomh.org>
Sun, 15 Jun 2008 21:38:13 -0700
changeset 3274 eaa3a345b05e
child 4755 04a9a7e9a624
permissions -rw-r--r--
Split out non-tutorial sections from tutorial; place into a doc/manual directory
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3274
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     1
@c ========================================================================
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     2
@c Other Network Topologies
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     3
@c ========================================================================
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     4
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
@node Other-network-topologies
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     6
@chapter Other Network Topologies
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     7
@cindex topology
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     8
@cindex Channel
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     9
@cindex NetDevice
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    10
@cindex topology!bus
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    11
@cindex topology!point-to-point
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    12
@cindex PointToPointChannel
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    13
@cindex PointToPointNetDevice
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    15
@emph{Network topology} is the study of the arrangement of of the elements
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    16
(in @command{ns-3} represented by the classes @code{Channel} and @code{Node})
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    17
of a network.  Two fundamental types of physical topologies are the 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
@emph{point-to-point} and @emph{bus} topologies.  We have already been exposed
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    19
to the @command{ns-3} channel specialization named @code{CsmaChannel}.  This is
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
a simulation of a bus network.  We also provide a simulation of a 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    21
point-to-point channel with associated net devices.  As described previously,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    22
the associated C++ classes specialize the @command{ns-3} base classes
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    23
@code{NetDevice} and @code{Channel} and are called @code{PointToPointNetDevice}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    24
and @code{PointToPointChannel} respectively.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    25
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    26
We will use combinations of these bus and point-to-point topology elements
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    27
to show how to create several commonly seen network topologies.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    28
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    29
@section A Point-to-Point Network
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    30
We're going to take what might be seen as a step backward and look at a simple
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    31
point-to-point network.  We will be building the simplest network you can 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    32
imagine.  A serial link (point to point) between two computers.  When you
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
see this point-to-point network, you can think of an RS-422 (or RS-232 for 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    34
you old-timers) cable.  This topology is shown below.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    35
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    36
@sp 1
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    37
@center @image{figures/pp,,,,png}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    38
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    39
@cindex CreateObject
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    40
@cindex InternetNode
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    41
We have provided a file for you in the @code{tutorial}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    42
directory called @code{tutorial-point-to-point.cc}.  You should now be
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    43
familiar enough with the system to pick out fairly easily what has been
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    44
changed.  Let's focus on the following lines:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    45
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    46
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    47
  Ptr<Node> n0 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    48
  Ptr<Node> n1 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    49
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    50
  Ptr<PointToPointChannel> link = PointToPointTopology::AddPointToPointLink (
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    51
    n0, n1, DataRate (38400), MilliSeconds (20));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    52
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    53
  PointToPointTopology::AddIpv4Addresses (link, n0, "10.1.1.1",
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    54
    n1, "10.1.1.2");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    55
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    56
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    57
You can see that we created two @code{InternetNode} objects in the usual way.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    58
Then, instead of creating a @code{CsmaChannel} we create a 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    59
@code{PointToPointChannel}.  This point-to-point channel, which we call
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    60
@code{link}, connects node zero (@code{n0}) and node one (@code{n1}) over a
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    61
simulated link that runs at 38400 bits per second and has a 20 millisecond
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    62
simulated speed-of-light delay.  This call also creates appropriate net devices
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    63
and attaches them to nodes zero and one.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    64
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    65
We then add IP addresses to the net devices we just created using the topology
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    66
helper @code{AddIpv4Addresses}.  Node zero gets the IP address 10.1.1.1 and
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    67
node one gets the IP address 10.1.1.2 assigned.  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    68
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    69
The alert tutorial user may wonder what the network number or prefix is of
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    70
those IP addresses.  The point-to-point topology assumes that you want a
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    71
@code{/30} subnet and assigns an appropriate net mask for you.  It then then
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    72
@emph{asserts} that the network numbers of the two net devices match.  So there
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    73
is an implicit network mask created down in the topology code that looks like,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    74
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    75
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    76
  Ipv4Mask netmask("255.255.255.252");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    77
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    78
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    79
The rest of the code you should recognize and understand.  We are just going
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    80
to echo one packet across the point-to-point link.  You should be now be able
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    81
to build and run this example and to locate and interpret the ASCII trace 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    82
file.  This is left as an exercise for you.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    83
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    84
The file @code{tutorial-point-to-point.cc} is reproduced here for your 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    85
convenience:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    86
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    87
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    88
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    89
/*
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    90
 * This program is free software; you can redistribute it and/or modify
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    91
 * it under the terms of the GNU General Public License version 2 as
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    92
 * published by the Free Software Foundation;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    93
 *
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    94
 * This program is distributed in the hope that it will be useful,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    95
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    96
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    97
 * GNU General Public License for more details.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    98
 *
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    99
 * You should have received a copy of the GNU General Public License
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   100
 * along with this program; if not, write to the Free Software
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   101
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   102
 */
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   103
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   104
#include "ns3/log.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   105
#include "ns3/ptr.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   106
#include "ns3/internet-stack.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   107
#include "ns3/point-to-point-channel.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   108
#include "ns3/mac48-address.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   109
#include "ns3/point-to-point-net-device.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   110
#include "ns3/point-to-point-topology.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   111
#include "ns3/udp-echo-client.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   112
#include "ns3/udp-echo-server.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   113
#include "ns3/simulator.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   114
#include "ns3/nstime.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   115
#include "ns3/ascii-trace.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   116
#include "ns3/pcap-trace.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   117
#include "ns3/global-route-manager.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   118
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   119
NS_LOG_COMPONENT_DEFINE ("PointToPointSimulation");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   120
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   121
using namespace ns3;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   122
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   123
// Network topology
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   124
//
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   125
//                       point to point
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   126
//                      +--------------+
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   127
//                      |              |
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   128
//                     n0             n1
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   129
//
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   130
int 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   131
main (int argc, char *argv[])
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   132
{
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   133
  LogComponentEnable ("PointToPointSimulation", LOG_LEVEL_INFO);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   134
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   135
  NS_LOG_INFO ("Point to Point Topology Simulation");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   136
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   137
  Ptr<Node> n0 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   138
  Ptr<Node> n1 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   139
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   140
  Ptr<PointToPointChannel> link = PointToPointTopology::AddPointToPointLink (
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   141
    n0, n1, DataRate (38400), MilliSeconds (20));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   142
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   143
  PointToPointTopology::AddIpv4Addresses (link, n0, "10.1.1.1", 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   144
    n1, "10.1.1.2");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   145
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   146
  uint16_t port = 7;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   147
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   148
  Ptr<UdpEchoClient> client = CreateObject<UdpEchoClient> (n0, "10.1.1.2", 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   149
    port, 1, Seconds(1.), 1024);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   150
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   151
  Ptr<UdpEchoServer> server = CreateObject<UdpEchoServer> (n1, port);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   152
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   153
  server->Start(Seconds(1.));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   154
  client->Start(Seconds(2.));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   155
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   156
  server->Stop (Seconds(10.));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   157
  client->Stop (Seconds(10.));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   158
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   159
  AsciiTrace asciitrace ("tutorial.tr");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   160
  asciitrace.TraceAllQueues ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   161
  asciitrace.TraceAllNetDeviceRx ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   162
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   163
  Simulator::Run ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   164
  Simulator::Destroy ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   165
}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   166
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   167
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   168
@section A Star Network
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   169
A point-to-point network is considered a special case of a star network.  As
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   170
you might expect, the process of constructing a star network is an extension
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   171
of the very simple process used for a point-to-point link.  We have provided
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   172
a file for you in the @code{tutorial} directory called @code{tutorial-star.cc}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   173
that implements a simple star network as seen below.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   174
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   175
@sp 1
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   176
@center @image{figures/star,,,,png}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   177
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   178
In order to create a star network, we need to be able to instantiate some
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   179
number (greater than one) of net devices on a node.  In the name of simplicity
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   180
of use, the @code{PointToPointTopology} topology helper does not allow one to
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   181
do this.  We provided a separate topology helper class, the 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   182
@code{PointToPointIpv4Topology} helper class that provides the slightly finer
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   183
granularity we need to accomplish a star network.  In order to use this new
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   184
helper we have to load the definitions by including the appropriate file.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   185
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   186
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   187
  #include "ns3/point-to-point-ipv4-topology.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   188
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   189
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   190
The star that we're going to create has a node in the center (@code{n0}) with
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   191
six nodes surrounding (@code{n1} - @code{n6}).  You should be able to easily
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   192
find and understand the code that creates these nodes.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   193
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   194
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   195
  Ptr<Node> n0 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   196
  Ptr<Node> n1 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   197
  Ptr<Node> n2 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   198
  Ptr<Node> n3 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   199
  Ptr<Node> n4 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   200
  Ptr<Node> n5 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   201
  Ptr<Node> n6 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   202
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   203
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   204
Next, we get into the differences between the @code{PointToPointTopology}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   205
helper and the @code{PointToPointIpv4Topology} helper.  The
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   206
@code{PointToPointIpv4Topology} helper looks and feels a little like the 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   207
@code{CsmaIpv4Topology} helper.  Just like you created a CSMA channel 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   208
previously, you need to create a point-to-point channel.  The following
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   209
code creates a @code{PointToPointChannel} and calls it @code{link01}.  You can
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   210
interpret this name as being the channel (or @emph{link}) from node zero to 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   211
node one.  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   212
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   213
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   214
  Ptr<PointToPointChannel> link01 =
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   215
    PointToPointIpv4Topology::CreateChannel (DataRate (38400),
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   216
    MilliSeconds (20));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   217
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   218
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   219
You need to provide a data rate for the channel which we set at 38400 bits 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   220
per second.  You must also provide a speed-of-light delay which we set at
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   221
20 milliseconds.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   222
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   223
Just as you added a net device to the nodes in the CSMA tutorial section, you
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   224
do the same here but with a point-to-point net device.  The following code
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   225
illustrates how we do that:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   226
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   227
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   228
  uint32_t nd01 = PointToPointIpv4Topology::AddNetDevice (n0,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   229
    link01);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   230
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   231
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   232
We call the @code{PointToPointIpv4Topology} helper and ask it to add a net
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   233
device to node zero (@code{n0}) and connect it to the appropriate 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   234
point-to-point link (@code{link01}) which you will recall is the serial link
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   235
from node zero to node one.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   236
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   237
If you look at the following code, you will see the same calls are repeated
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   238
to create the remaining five point-to-point channels and connect them
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   239
to net devices on node zero.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   240
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   241
The next new code is found after the ``spokes'' of the star have been created.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   242
It looks like the following:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   243
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   244
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   245
  uint32_t nd1 = PointToPointIpv4Topology::AddNetDevice (n1, link01);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   246
  uint32_t nd2 = PointToPointIpv4Topology::AddNetDevice (n2, link02);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   247
  uint32_t nd3 = PointToPointIpv4Topology::AddNetDevice (n3, link03);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   248
  uint32_t nd4 = PointToPointIpv4Topology::AddNetDevice (n4, link04);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   249
  uint32_t nd5 = PointToPointIpv4Topology::AddNetDevice (n5, link05);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   250
  uint32_t nd6 = PointToPointIpv4Topology::AddNetDevice (n6, link06);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   251
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   252
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   253
Here we are creating the net devices on the nodes surrounding the center node.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   254
In the first call, we are adding a net device on node one (@code{n1}) and
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   255
connecting that net device to the channel named @code{link01}.  Remember that
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   256
we created the channel @code{link01} as the channel connecting node zero and
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   257
node one.  We previously created a net device on node zero and attached that
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   258
device to @code{link01}.  Here we are connecting the other side of that link
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   259
to node one.  The return value from this call is the net device index of the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   260
created net device.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   261
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   262
The next section of code adds addresses to the net devices we just created.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   263
The first call adds the IP address 10.1.1.1 to the net device going from 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   264
node zero to node one.  Recall that we first created a node named @code{n0}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   265
and a channel called @code{link01}.  We added a net device to @code{n0} and
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   266
remembered the net device index as the @code{uint32_t nd01}.  This meant
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   267
the net device @emph{nd} on node @emph{0} that we connected to node @emph{1}. 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   268
We call @code{AddAddress} to add an IP address (10.1.1.1) to the net device
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   269
on node zero identified by the net device index @code{nd01}.  We provide a
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   270
net mask suitable for a point to point network.  This is typically a /30 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   271
address but we don't force that in this API.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   272
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   273
After setting up the address on node zero, we do the same for the node on
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   274
the other end of the ``spoke'' --- in this case node one, with its single
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   275
net device.  Note that the network number is the same on both sides of this
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   276
network.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   277
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   278
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   279
  PointToPointIpv4Topology::AddAddress (n0, nd01, "10.1.1.1",
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   280
    ``255.255.255.252'');
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   281
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   282
  PointToPointIpv4Topology::AddAddress (n1, nd1, "10.1.1.2",
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   283
    ``255.255.255.252'');
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   284
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   285
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   286
The following code repeats this pattern assining similar IP addresses to the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   287
remaining net devices.  Note that there are no @code{Mac48Address} address
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   288
assignments --- they are not required.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   289
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   290
The rest of the code you should recognize and understand.  We are just going
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   291
to echo one packet across the point-to-point link.  You should be now be able
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   292
to build and run this example and to locate and interpret the ASCII trace 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   293
file.  This is left as an exercise for you.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   294
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   295
The file @code{tutorial-star.cc} is reproduced here for your convenience:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   296
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   297
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   298
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   299
/*
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   300
 * This program is free software; you can redistribute it and/or modify
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   301
 * it under the terms of the GNU General Public License version 2 as
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   302
 * published by the Free Software Foundation;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   303
 *
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   304
 * This program is distributed in the hope that it will be useful,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   305
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   306
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   307
 * GNU General Public License for more details.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   308
 *
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   309
 * You should have received a copy of the GNU General Public License
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   310
 * along with this program; if not, write to the Free Software
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   311
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   312
 */
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   313
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   314
#include "ns3/log.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   315
#include "ns3/ptr.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   316
#include "ns3/internet-stack.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   317
#include "ns3/point-to-point-channel.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   318
#include "ns3/mac48-address.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   319
#include "ns3/point-to-point-net-device.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   320
#include "ns3/point-to-point-ipv4-topology.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   321
#include "ns3/udp-echo-client.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   322
#include "ns3/udp-echo-server.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   323
#include "ns3/simulator.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   324
#include "ns3/nstime.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   325
#include "ns3/ascii-trace.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   326
#include "ns3/pcap-trace.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   327
#include "ns3/global-route-manager.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   328
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   329
NS_LOG_COMPONENT_DEFINE ("StarSimulation");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   330
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   331
using namespace ns3;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   332
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   333
// Network topology
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   334
//
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   335
//                  n3    n2
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   336
//                   |   /
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   337
//                    | /
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   338
//              n4 --- n0 --- n1
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   339
//                    /  |
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   340
//                   /    |
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   341
//                  n5    n6
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   342
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   343
int 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   344
main (int argc, char *argv[])
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   345
{
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   346
  LogComponentEnable ("StarSimulation", LOG_LEVEL_INFO);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   347
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   348
  NS_LOG_INFO ("Star Topology Simulation");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   349
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   350
  Ptr<Node> n0 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   351
  Ptr<Node> n1 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   352
  Ptr<Node> n2 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   353
  Ptr<Node> n3 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   354
  Ptr<Node> n4 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   355
  Ptr<Node> n5 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   356
  Ptr<Node> n6 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   357
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   358
  Ptr<PointToPointChannel> link01 = 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   359
    PointToPointIpv4Topology::CreateChannel (DataRate (38400), 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   360
    MilliSeconds (20));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   361
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   362
  uint32_t nd01 = PointToPointIpv4Topology::AddNetDevice (n0,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   363
    link01);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   364
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   365
  Ptr<PointToPointChannel> link02 = 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   366
    PointToPointIpv4Topology::CreateChannel (DataRate (38400), 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   367
    MilliSeconds (20));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   368
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   369
  uint32_t nd02 = PointToPointIpv4Topology::AddNetDevice (n0,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   370
    link02);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   371
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   372
  Ptr<PointToPointChannel> link03 = 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   373
    PointToPointIpv4Topology::CreateChannel (DataRate (38400), 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   374
    MilliSeconds (20));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   375
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   376
  uint32_t nd03 = PointToPointIpv4Topology::AddNetDevice (n0,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   377
    link03);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   378
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   379
  Ptr<PointToPointChannel> link04 = 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   380
    PointToPointIpv4Topology::CreateChannel (DataRate (38400), 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   381
    MilliSeconds (20));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   382
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   383
  uint32_t nd04 = PointToPointIpv4Topology::AddNetDevice (n0, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   384
    link04);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   385
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   386
  Ptr<PointToPointChannel> link05 = 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   387
    PointToPointIpv4Topology::CreateChannel (DataRate (38400), 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   388
    MilliSeconds (20));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   389
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   390
  uint32_t nd05 = PointToPointIpv4Topology::AddNetDevice (n0,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   391
    link05);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   392
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   393
  Ptr<PointToPointChannel> link06 = 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   394
    PointToPointIpv4Topology::CreateChannel (DataRate (38400), 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   395
    MilliSeconds (20));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   396
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   397
  uint32_t nd06 = PointToPointIpv4Topology::AddNetDevice (n0, link06);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   398
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   399
  uint32_t nd1 = PointToPointIpv4Topology::AddNetDevice (n1, link01);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   400
  uint32_t nd2 = PointToPointIpv4Topology::AddNetDevice (n2, link02);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   401
  uint32_t nd3 = PointToPointIpv4Topology::AddNetDevice (n3, link03);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   402
  uint32_t nd4 = PointToPointIpv4Topology::AddNetDevice (n4, link04);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   403
  uint32_t nd5 = PointToPointIpv4Topology::AddNetDevice (n5, link05);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   404
  uint32_t nd6 = PointToPointIpv4Topology::AddNetDevice (n6, link06);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   405
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   406
  PointToPointIpv4Topology::AddAddress (n0, nd01, "10.1.1.1", 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   407
    "255.255.255.252");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   408
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   409
  PointToPointIpv4Topology::AddAddress (n1, nd1, "10.1.1.2", 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   410
    "255.255.255.252");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   411
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   412
  PointToPointIpv4Topology::AddAddress (n0, nd02, "10.1.2.1", 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   413
    "255.255.255.252");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   414
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   415
  PointToPointIpv4Topology::AddAddress (n2, nd2, "10.1.2.2", 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   416
    "255.255.255.252");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   417
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   418
  PointToPointIpv4Topology::AddAddress (n0, nd03, "10.1.3.1", 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   419
    "255.255.255.252");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   420
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   421
  PointToPointIpv4Topology::AddAddress (n3, nd3, "10.1.2.2", 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   422
    "255.255.255.252");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   423
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   424
  PointToPointIpv4Topology::AddAddress (n0, nd04, "10.1.4.1", 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   425
    "255.255.255.252");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   426
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   427
  PointToPointIpv4Topology::AddAddress (n4, nd4, "10.1.4.2", 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   428
    "255.255.255.252");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   429
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   430
  PointToPointIpv4Topology::AddAddress (n0, nd05, "10.1.5.1", 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   431
    "255.255.255.252");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   432
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   433
  PointToPointIpv4Topology::AddAddress (n5, nd5, "10.1.5.2", 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   434
    "255.255.255.252");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   435
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   436
  PointToPointIpv4Topology::AddAddress (n0, nd06, "10.1.6.1", 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   437
    "255.255.255.252");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   438
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   439
  PointToPointIpv4Topology::AddAddress (n6, nd6, "10.1.6.2", 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   440
    "255.255.255.252");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   441
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   442
  uint16_t port = 7;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   443
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   444
  Ptr<UdpEchoClient> client = CreateObject<UdpEchoClient> (n0, "10.1.1.2", 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   445
    port, 1, Seconds(1.), 1024);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   446
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   447
  Ptr<UdpEchoServer> server = CreateObject<UdpEchoServer> (n1, port);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   448
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   449
  server->Start(Seconds(1.));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   450
  client->Start(Seconds(2.));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   451
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   452
  server->Stop (Seconds(10.));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   453
  client->Stop (Seconds(10.));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   454
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   455
  AsciiTrace asciitrace ("tutorial.tr");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   456
  asciitrace.TraceAllQueues ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   457
  asciitrace.TraceAllNetDeviceRx ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   458
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   459
  Simulator::Run ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   460
  Simulator::Destroy ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   461
}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   462
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   463
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   464
@subsection Routing
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   465
If you are really excited about this simulator you may have already tried to
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   466
modify the scripts outside the tutorial.  I know that one of the first things
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   467
that would have occurred to me when I saw the star network would have been to
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   468
start trying to add applications to echo packets from nodes other than zero.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   469
If you tried, for example, to start the echo client on node one instead of
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   470
node zero, you would have found an empty trace file.  The reason for this
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   471
is that you have now created an internetwork.  This means you will need to 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   472
enable internetwork routing.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   473
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   474
We have provided a file for you in the @code{tutorial} directory called 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   475
@code{tutorial-star-routing.cc} to show you how this is done.  This extremely
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   476
tricky and difficult change is shown below:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   477
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   478
@verbatim 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   479
 GlobalRouteManager::PopulateRoutingTables ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   480
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   481
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   482
This one-line addition, located just before the simulation runs, tells the 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   483
@command{ns-3} @emph{global route manager} to walk the topology you created and 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   484
build internetwork routing tables for all of the nodes in the simulation.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   485
We changed the client application so that it runs on node four:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   486
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   487
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   488
  Ptr<UdpEchoClient> client = CreateObject<UdpEchoClient> (n4, "10.1.1.2", 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   489
    port, 1, Seconds(1.), 1024);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   490
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   491
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   492
Now if you build and run @code{tutorial-star-routing.cc} you can examine the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   493
@code{tutorial.tr} file and see that your UDP echo packets are now correctly
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   494
routed through the topology.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   495
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   496
@section A Dumbbell Network
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   497
One of the most interesting simple topologies (from a phenomenological point of
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   498
view) is commonly called a dumbbell network.  The name derives from a 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   499
superficial similarity in form to a piece of exercise equipment.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   500
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   501
The dumbbell model is typically composed of two bus or star network elements
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   502
connected via a point-to-point link.  The point-to-point link is usually 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   503
configured with a lower bandwidth than the bus elements to provide a 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   504
@emph{choke point}.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   505
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   506
The following is a representation of the topology.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   507
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   508
@sp 1
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   509
@center @image{figures/dumbbell,,,,png}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   510
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   511
We have provided a file that constructs this dumbbell network and creates 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   512
enough data flowing across the choke point that some packets will be dropped.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   513
The file is called @code{tutorial-linear-dumbbell.cc} and is located in the 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   514
@code{tutorial} directory.  We have already covered all of the code used to
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   515
create this network, so we will just quickly go over the main sections of the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   516
script.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   517
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   518
The first section creates a CSMA lan that will become the left side of the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   519
dumbbell network.  This code should be very familiar since we used the same
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   520
process to create our first example.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   521
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   522
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   523
//
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   524
// Create the lan on the left side of the dumbbell.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   525
//
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   526
  Ptr<Node> n0 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   527
  Ptr<Node> n1 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   528
  Ptr<Node> n2 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   529
  Ptr<Node> n3 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   530
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   531
  Ptr<CsmaChannel> lan1 = 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   532
    CsmaTopology::CreateCsmaChannel (DataRate (10000000), MilliSeconds (2));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   533
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   534
  uint32_t nd0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n0, lan1, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   535
    "08:00:2e:00:00:00");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   536
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   537
  uint32_t nd1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n1, lan1, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   538
    "08:00:2e:00:00:01");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   539
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   540
  uint32_t nd2 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, lan1, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   541
    "08:00:2e:00:00:02");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   542
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   543
  uint32_t nd3 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, lan1, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   544
    "08:00:2e:00:00:03");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   545
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   546
  CsmaIpv4Topology::AddIpv4Address (n0, nd0, "10.1.1.1", "255.255.255.0");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   547
  CsmaIpv4Topology::AddIpv4Address (n1, nd1, "10.1.1.2", "255.255.255.0");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   548
  CsmaIpv4Topology::AddIpv4Address (n2, nd2, "10.1.1.3", "255.255.255.0");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   549
  CsmaIpv4Topology::AddIpv4Address (n3, nd3, "10.1.1.4", "255.255.255.0");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   550
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   551
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   552
The code to generate the CSMA lan on the right side is similar; only the names
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   553
have been changed.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   554
 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   555
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   556
//
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   557
// Create the lan on the right side of the dumbbell.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   558
//
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   559
  Ptr<Node> n4 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   560
  Ptr<Node> n5 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   561
  Ptr<Node> n6 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   562
  Ptr<Node> n7 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   563
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   564
  Ptr<CsmaChannel> lan2 = 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   565
    CsmaTopology::CreateCsmaChannel (DataRate (10000000), MilliSeconds (2));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   566
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   567
  uint32_t nd4 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n4, lan2, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   568
    "08:00:2e:00:00:04");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   569
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   570
  uint32_t nd5 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n5, lan2, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   571
    "08:00:2e:00:00:05");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   572
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   573
  uint32_t nd6 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n6, lan2, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   574
    "08:00:2e:00:00:06");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   575
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   576
  uint32_t nd7 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n7, lan2, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   577
    "08:00:2e:00:00:07");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   578
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   579
  CsmaIpv4Topology::AddIpv4Address (n4, nd4, "10.1.2.1", "255.255.255.0");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   580
  CsmaIpv4Topology::AddIpv4Address (n5, nd5, "10.1.2.2", "255.255.255.0");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   581
  CsmaIpv4Topology::AddIpv4Address (n6, nd6, "10.1.2.3", "255.255.255.0");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   582
  CsmaIpv4Topology::AddIpv4Address (n7, nd7, "10.1.2.4", "255.255.255.0");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   583
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   584
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   585
Next, we create a point to point link to connect the two lans.  We connect
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   586
the point-to-point channel between nodes three (on the left lan) and four
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   587
(on the right lan).  You should recoginze this as substantially similar to
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   588
the link setup from the @code{point-to-point} example.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   589
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   590
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   591
//
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   592
// Create the point-to-point link to connect the two lans.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   593
//
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   594
  Ptr<PointToPointChannel> link = PointToPointTopology::AddPointToPointLink (
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   595
    n3, n4, DataRate (38400), MilliSeconds (20));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   596
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   597
  PointToPointTopology::AddIpv4Addresses (link, n3, "10.1.3.1", 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   598
    n4, "10.1.3.2");
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   599
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   600
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   601
Then we configure data flows.  We create four echo clients that send UDP 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   602
packets from the left side lan to servers created on the right side lan.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   603
Notice that we send 100 packets with an inter-packet gap of ten milliseconds
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   604
instead of the single packet we have previously used.  This data rate is
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   605
sufficient to saturate the point-to-point link and will cause packets to be
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   606
dropped when the queue on the link net devices overflows (the default maximum
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   607
queue depth is 100 packets).  Note that we stagger the start of the echo 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   608
clients to slowly bring up the data rates.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   609
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   610
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   611
//
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   612
// Create data flows across the link:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   613
//   n0 ==> n4 ==> n0
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   614
//   n1 ==> n5 ==> n1
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   615
//   n2 ==> n6 ==> n2
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   616
//   n3 ==> n7 ==> n3
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   617
//
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   618
  uint16_t port = 7;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   619
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   620
  Ptr<UdpEchoClient> client0 = CreateObject<UdpEchoClient> (n0, "10.1.2.1", 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   621
    port, 100, Seconds(.01), 1024);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   622
  Ptr<UdpEchoClient> client1 = CreateObject<UdpEchoClient> (n1, "10.1.2.2", 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   623
    port, 100, Seconds(.01), 1024);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   624
  Ptr<UdpEchoClient> client2 = CreateObject<UdpEchoClient> (n2, "10.1.2.3", 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   625
    port, 100, Seconds(.01), 1024);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   626
  Ptr<UdpEchoClient> client3 = CreateObject<UdpEchoClient> (n3, "10.1.2.4", 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   627
    port, 100, Seconds(.01), 1024);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   628
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   629
  Ptr<UdpEchoServer> server4 = CreateObject<UdpEchoServer> (n4, port);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   630
  Ptr<UdpEchoServer> server5 = CreateObject<UdpEchoServer> (n5, port);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   631
  Ptr<UdpEchoServer> server6 = CreateObject<UdpEchoServer> (n6, port);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   632
  Ptr<UdpEchoServer> server7 = CreateObject<UdpEchoServer> (n7, port);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   633
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   634
  server4->Start(Seconds(1.));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   635
  server5->Start(Seconds(1.));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   636
  server6->Start(Seconds(1.));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   637
  server7->Start(Seconds(1.));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   638
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   639
  client0->Start(Seconds(2.));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   640
  client1->Start(Seconds(2.1));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   641
  client2->Start(Seconds(2.2));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   642
  client3->Start(Seconds(2.3));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   643
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   644
  server4->Stop (Seconds(10.));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   645
  server5->Stop (Seconds(10.));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   646
  server6->Stop (Seconds(10.));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   647
  server7->Stop (Seconds(10.));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   648
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   649
  client0->Stop (Seconds(10.));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   650
  client1->Stop (Seconds(10.));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   651
  client2->Stop (Seconds(10.));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   652
  client3->Stop (Seconds(10.));
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   653
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   654
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   655
The remainder of the file should be quite familiar to you.  Go ahead and 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   656
run @code{tutorial-linear-dumbbell}.  Now take a look at the trace 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   657
(@code{tutorial.tr}) file.  You will now see trace lines that begin with 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   658
@code{d}.  Alternatively you can search for the string ``queue-drop'' which
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   659
is the expansion of the drop code ('d').
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   660
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   661
Interpretation of a dropped packet is straightforward.  We have expanded
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   662
the first @code{queue-drop} trace for you below.  See the section on ASCII 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   663
tracing for details.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   664
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   665
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   666
  00 d 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   667
  01 2.40938 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   668
  02 nodeid=3 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   669
  03 device=1 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   670
  04 queue-drop 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   671
  05 pkt-uid=124 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   672
  06 LLCSNAP(type 0x800) 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   673
  07   IPV4(
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   674
  08     tos 0x0 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   675
  09     ttl 63 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   676
  10     id 20 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   677
  11     offset 0 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   678
  12     flags [none] 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   679
  13     length: 1052) 10.1.1.3 > 10.1.2.3 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   680
  14     UDP(length: 1032) 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   681
  15       49153 > 7 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   682
  16       DATA (length 1024)
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   683
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   684
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   685
We leave it as an exercise to examine the trace files in more detail.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   686
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   687
@c ========================================================================
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   688
@c Nonlinear Thinking
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   689
@c ========================================================================
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   690
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   691
@node Nonlinear-Thinking
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   692
@chapter Nonlinear Thinking
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   693
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   694
One thing that all of our examples so far have in common is that they are
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   695
composed of a linear collection of calls into the @command{ns-3} system.  The
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   696
programmers among the readers may have wondered why there is not as much
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   697
as a for-loop in all of the examples.  The answer is that we wanted to 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   698
introduce you to @command{ns-3} scripting with a minimum of conceptual 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   699
overhead.  We're going to remedy that situation shortly.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   700
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   701
We have written a number of @command{ns-3} scripts in C++.  Although we have 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   702
been perfectly linear in our script implementations, just like any other C++ 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   703
program, an @command{ns-3} script can use any features of the language you
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   704
desire.  If you will look back at the @code{tutorial-linear-dumbbell.cc}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   705
example, you may notice that the code to create the left and right sides of
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   706
the dumbbell is operationally identical --- only the names change.  An obvious
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   707
improvement of this program would be to use subroutines to create the sides.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   708
Since we are working with C++, we should probably do this in an 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   709
object-oriented way.  Since object-oriented design is somewhat of a black art
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   710
to some people, we'll take some time here and outline a simple methodology 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   711
you can follow.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   712
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   713
@section Object Design 101 --- Class Ipv4BusNetwork
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   714
If you are a master of object oriented design, feel free to skip or skim this
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   715
section, in which we derive a simplistic but fully operational bus network 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   716
class.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   717
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   718
So you want to create a BusNetwork class.  Often the biggest hurdle in a 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   719
design is figuring out how to get started.  One of the simplest and most 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   720
straightforward ways to do an object decomposition of a problem is to simply 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   721
write down a description of the problem and take a look at the words 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   722
you used.  Let's take some time and do that, first at a very high level.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   723
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   724
@example
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   725
A bus network is an implementation of a particular network topology that
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   726
contains some number of nodes.  Each of these nodes is attached to a single 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   727
multi-drop channel.  The network itself has some attributes independent of
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   728
the topology such as a network mask, network number (prefix) and base IP
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   729
address.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   730
@end example
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   731
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   732
The first thing to do is to focus on the nouns and adjectives.  These will
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   733
give you a starting point for required classes and member variables.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   734
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   735
Immediately we can notice that at the highest level we are talking about the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   736
noun @emph{network}.  This probably won't surprise you.  We also have an 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   737
adjective that modifies the noun --- @emph{bus}.  This should lead us to our 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   738
first class defintion.  Usually class names are constructed in the same way
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   739
as an English language sentence would be spoken.  For example, one would speak
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   740
of a @emph{bus network} in conversation, so we would normally create a
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   741
@code{class BusNetwork} to represent it.  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   742
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   743
One thing to note is that we have used two words in our description quite 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   744
naturally: @emph{is} and @emph{has}.  When you see these words should should
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   745
immediately think of the object-oriented concepts of @emph{ISA} (inheritance)
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   746
and @emph{HASA} (containment) respectively.  We wrote that a bus network
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   747
@emph{is} an implementation of a particular network topology.  Perhaps you 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   748
will agree that there is a natural base class called @code{Network} that 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   749
@emph{has} the attributes discussed above.  The fact that a @code{BusNetwork}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   750
@emph{ISA} kind of @code{Network} suggests inheritance.  Let's capture that 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   751
thought right away remembering that we're focused on IP version four here:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   752
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   753
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   754
  class Ipv4Network
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   755
  {
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   756
  public:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   757
    Ipv4Address m_network;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   758
    Ipv4Mask m_mask;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   759
    Ipv4Address m_baseAddress;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   760
  };
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   761
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   762
  class Ipv4BusNetwork : public Ipv4Network
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   763
  {
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   764
  };
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   765
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   766
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   767
Let's take a look at the @emph{HASA} relationships of the bus network.  Clearly
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   768
it will @emph{have} a reference to the underlying channel that implements the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   769
actual communications medium.  We use smart pointers for those references, so 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   770
one member variable is obvious:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   771
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   772
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   773
  Ptr<CsmaChannel> m_channel;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   774
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   775
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   776
A bus network will also need to contain references to all of the nodes we
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   777
eventually want to create.  If you are working in C++ and see the words contain
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   778
or container, you should immediately think of the Standard Template Library
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   779
or STL.  A quick search of the available containers there will probably lead
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   780
you to consider the vector class.  A vector is a container that looks like an
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   781
array.  This is just what we need here.  Again, we want to use smart pointers
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   782
to reference our nodes, so the declaration of the vector would look like,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   783
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   784
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   785
  std::vector<Ptr<Node> > m_nodes;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   786
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   787
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   788
It will save you headaches in the future if you notice that the space between
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   789
the two right brackets is required to differentiate this situation from a
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   790
right-shift operator.  So we have a pretty good start already after just a
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   791
little work.  Now we need to turn our attention to actions.  Let's write 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   792
another little description of the things you consider doing to a Bus network.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   793
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   794
@example
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   795
We need to be able to create a bus network.  We need to be able to delete a
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   796
bus network.  We need to be able to get a handle to a node in order to add
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   797
applications.  We need to be able to set the network, mask and base address
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   798
somehow, specify how many nodes to create and provide the underlying channel
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   799
its required bandwidth and delay parameters.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   800
@end example
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   801
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   802
We now look at the @emph{verbs} in that sentence.  These will give a good 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   803
starting point for the methods of the classes.  For example, the verbs 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   804
@emph{create} and @emph{delete} should suggest @emph{constructor} and 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   805
@emph{destructor}.  The verb @emph{get} leads us to providing a method called
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   806
@code{GetNode}.  We have to provide a number of parameters so we can either
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   807
provide @emph{setters} or we can simply pass them in as parameters to our
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   808
constructors.  Since this is a simple example, we won't bother to implement
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   809
getters and setters (methods to get and set member variables to enhance data
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   810
hiding).  Let's use this guidance to finish up our class declarations:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   811
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   812
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   813
  class Ipv4Network
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   814
  {
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   815
  public:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   816
    Ipv4Network (Ipv4Address network, Ipv4Mask mask, Ipv4Address address);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   817
    virtual ~Ipv4Network ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   818
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   819
    Ipv4Address m_network;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   820
    Ipv4Mask m_mask;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   821
    Ipv4Address m_baseAddress;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   822
  };
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   823
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   824
  class Ipv4BusNetwork : public Ipv4Network
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   825
  {
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   826
  public:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   827
    Ipv4BusNetwork (
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   828
      Ipv4Address   network, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   829
      Ipv4Mask      mask, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   830
      Ipv4Address   startAddress, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   831
      DataRate      bps, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   832
      Time          delay, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   833
      uint32_t      n);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   834
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   835
    virtual ~Ipv4BusNetwork ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   836
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   837
    Ptr<Node> GetNode (uint32_t n);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   838
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   839
  private:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   840
    std::vector<Ptr<Node> > m_nodes;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   841
    Ptr<CsmaChannel> m_channel;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   842
  };
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   843
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   844
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   845
That's it.  We have actually already walked through almost all of the code
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   846
required to construct a bus network in our @code{tutorial-csma-echo.cc} 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   847
example, so let's just jump forward and take a look at an implementation
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   848
of this thing.  We provide an implementation for you in the files 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   849
@code{ipv4-bus-network.h} and @code{ipv4-bus-network.cc} located in the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   850
@code{tutorial} directory.  We also provide an example that uses the new
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   851
class in the file @code{tutorial-bus-network.cc}.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   852
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   853
The interesting method from our current perspective is the Ipv4BusNetwork
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   854
constructor, shown below:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   855
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   856
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   857
  Ipv4BusNetwork::Ipv4BusNetwork (
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   858
    Ipv4Address   network, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   859
    Ipv4Mask      mask, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   860
    Ipv4Address   baseAddress, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   861
    DataRate      bps, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   862
    Time          delay, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   863
    uint32_t      n)
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   864
  : 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   865
    Ipv4Network (network, mask, baseAddress)
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   866
  {
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   867
    Ipv4AddressGenerator::SeedNetwork (mask, network);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   868
    Ipv4AddressGenerator::SeedAddress (mask, baseAddress);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   869
  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   870
    m_channel = CsmaTopology::CreateCsmaChannel (bps, delay);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   871
  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   872
    for (uint32_t i = 0; i < n; ++i)
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   873
      {
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   874
        Ptr<Node> node = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   875
        uint32_t nd = CsmaIpv4Topology::AddIpv4CsmaNetDevice (node, m_channel, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   876
          Mac48Address::Allocate ());
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   877
        Ipv4Address address = Ipv4AddressGenerator::AllocateAddress (mask, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   878
          network);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   879
        CsmaIpv4Topology::AddIpv4Address (node, nd, address, mask);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   880
        m_nodes.push_back (node);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   881
      }
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   882
  }
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   883
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   884
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   885
Notice that we do the simple and straightforward thing and pass all of our
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   886
parameters to the constructor.  For those unfamiliar with C++, the line after
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   887
the colon and before the opening brace (shown below),
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   888
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   889
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   890
  : 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   891
    Ipv4Network (network, mask, baseAddress)
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   892
  {
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   893
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   894
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   895
Passes the appropriate parameters to the constructor of the base class
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   896
@code{Ipv4Network}.  There are two new calls that we haven't seen immediately
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   897
after this initialization.  They are:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   898
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   899
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   900
    Ipv4AddressGenerator::SeedNetwork (mask, network);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   901
    Ipv4AddressGenerator::SeedAddress (mask, baseAddress);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   902
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   903
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   904
We provide an IP address generator class to allow us to programatically 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   905
allocate IP addresses.  The first call to @code{SeedNetwork} gives the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   906
address generator a starting network number to use when generating addresses.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   907
The second call to @code{SeedAddress} gives the address generator a starting
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   908
IP address to use.  There is a starting network and starting address for each
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   909
of the 32 possible network masks.  Later in the for loop, you will see a
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   910
call to @code{AllocateAddress} in which the IP address for each node created
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   911
in the loop is actually generated.  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   912
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   913
The only unfamiliar call in the reset of the constructor will be:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   914
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   915
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   916
  m_nodes.push_back (node);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   917
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   918
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   919
This is the STL code to add the newly created node to the vector of nodes
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   920
attached to the bus.  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   921
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   922
For your convenience, we reproduce the entire bus network implementation below:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   923
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   924
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   925
  /* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   926
  /*
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   927
   * Copyright (c) 2007 University of Washington
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   928
   *
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   929
   * This program is free software; you can redistribute it and/or modify
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   930
   * it under the terms of the GNU General Public License version 2 as
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   931
   * published by the Free Software Foundation;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   932
   *
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   933
   * This program is distributed in the hope that it will be useful,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   934
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   935
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   936
   * GNU General Public License for more details.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   937
   *
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   938
   * You should have received a copy of the GNU General Public License
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   939
   * along with this program; if not, write to the Free Software
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   940
   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   941
   */
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   942
  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   943
  #include "ns3/mac48-address.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   944
  #include "ns3/csma-net-device.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   945
  #include "ns3/csma-topology.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   946
  #include "ns3/csma-ipv4-topology.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   947
  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   948
  #include "ipv4-bus-network.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   949
  #include "ipv4-address-generator.h"
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   950
  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   951
  namespace ns3 {
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   952
  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   953
  Ipv4Network::Ipv4Network (
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   954
    Ipv4Address   network, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   955
    Ipv4Mask      mask, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   956
    Ipv4Address   address)
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   957
  : 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   958
    m_network (network), m_mask (mask), m_baseAddress (address)
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   959
  {
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   960
  }
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   961
  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   962
  Ipv4Network::~Ipv4Network ()
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   963
  {
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   964
  }
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   965
  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   966
  Ipv4BusNetwork::Ipv4BusNetwork (
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   967
    Ipv4Address   network, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   968
    Ipv4Mask      mask, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   969
    Ipv4Address   baseAddress, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   970
    DataRate      bps, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   971
    Time          delay, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   972
    uint32_t      n)
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   973
  : 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   974
    Ipv4Network (network, mask, baseAddress)
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   975
  {
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   976
    Ipv4AddressGenerator::SeedNetwork (mask, network);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   977
    Ipv4AddressGenerator::SeedAddress (mask, baseAddress);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   978
  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   979
    m_channel = CsmaTopology::CreateCsmaChannel (bps, delay);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   980
  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   981
    for (uint32_t i = 0; i < n; ++i)
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   982
      {
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   983
        Ptr<Node> node = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   984
        uint32_t nd = CsmaIpv4Topology::AddIpv4CsmaNetDevice (node, m_channel, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   985
          Mac48Address::Allocate ());
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   986
        Ipv4Address address = Ipv4AddressGenerator::AllocateAddress (mask, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   987
          network);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   988
        CsmaIpv4Topology::AddIpv4Address (node, nd, address, mask);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   989
        m_nodes.push_back (node);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   990
      }
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   991
  }
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   992
  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   993
  Ipv4BusNetwork::~Ipv4BusNetwork ()
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   994
  {
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   995
  }
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   996
  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   997
    Ptr<Node>
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   998
  Ipv4BusNetwork::GetNode (uint32_t n)
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   999
  {
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1000
    return m_nodes[n];
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1001
  }
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1002
  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1003
  }; // namespace ns3
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1004
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1005
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1006
@section Using Ipv4BusNetwork
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1007
If all you ever want to do with a bus network can be captured in a topology
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1008
with four nodes on the bus, the preceeding section may seem like a colossal
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1009
waste of time.  This is probably not the case, though.  Now that we have a
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1010
relatively abstract bus class, we can create bus networks with 4, 40 or 4000
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1011
nodes with no additional effort.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1012
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1013
A use of the bus network class is shown in the file 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1014
@code{bus-netowrk.cc} located in the @code{tutorial} directory.  The
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1015
interesting code is,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1016
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1017
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1018
  Ipv4BusNetwork bus ("10.1.0.0", "255.255.0.0", "0.0.0.3",
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1019
    DataRate(10000000), MilliSeconds(20), 10);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1020
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1021
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1022
Here we create a bus network with the network number ``10.1.0.0'' and the 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1023
network mask ``255.255.0.0'' that completes the IP network definition.  You 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1024
can consider these together as ``10.1.0.0/16'' if you prefer.  The next 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1025
parameter tells the bus to start numbering IP addresses of contained nodes at
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1026
``10.1.0.3'' (remember the network number will be combined).  We provided a
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1027
data rate of 10 megabits per second and a latency of 20 milliseconds.  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1028
Finally, we ask the @code{Ipv4BusNetwork} object to create ten nodes in the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1029
network.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1030
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1031
If you are feeling brave, go ahead and change the number of nodes to be 100,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1032
1000, 10,000 or more to generate larger and larger networks.  Before you go 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1033
too far, remember that a trace file will be generated when you run your 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1034
resulting program and ee asked the trace facility to trace all net device 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1035
receive events.  This will include the reception of the broadcast ARP request 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1036
by all of the nodes in the simulation, so this can add up quickly.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1037
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1038
@c ========================================================================
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1039
@c Summary
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1040
@c ========================================================================
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1041
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1042
@node Summary
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1043
@chapter Summary
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1044
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1045
This concludes the first part of the tutorial.  We have focused on
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1046
using the @command{ns-3} system to construct various network topologies and to
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1047
simulate sendng data across the networks; and we've shown you how to use the 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1048
trace facility to get access to simulation results.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1049
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1050
We now encourage you to play with the system a little.  Experiment with what
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1051
we have provided.  Build a hierarchical network simulation.  Perhaps exercise
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1052
your object design skills and create a new @code{Ipv4DumbbellNetwork} class 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1053
to create dumbbell networks using the Ipv4BusNetwork class we just created.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1054
Hint:  An Ipv4DumbbellNetwork @emph{has} two @code{Ipv4BusNetwork} objects; 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1055
a left side and a right side.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1056
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1057
In the next part of the tutorial we are going to drop down a level and begin
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1058
examining the lower levels of the system in more detail.  We are going to
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1059
explain how to change the behavior of the system and eventually how to write
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1060
new models and applications.  This is a good time to make sure that you
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1061
thorougly understand what we've gone over so far.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1062
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1063
@c ========================================================================
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1064
@c Object Model
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1065
@c ========================================================================
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1066
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1067
@node Object-Model
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1068
@chapter Object Model
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1069
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1070
@cindex Object Model
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1071
There are two distinctly different meanings associated with the term Object
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1072
Model.  The first speaks to the implementation of an object system --- a system
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1073
view; and the second speaks to the application programming interface (classes
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1074
or objects) one uses to access some service or system --- an application view.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1075
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1076
As an example of the system view sense of the term, the C++ language has an
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1077
associated object model that describes how objects are laid out in memory,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1078
how virtual functions work, how inheritance is implemented, constructor and
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1079
destructor execution ordering, template instantiation, etc.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1080
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1081
@cindex API
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1082
@cindex DOM
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1083
@cindex Document Object Model
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1084
In the case of the application view, the Document Object Model is a good
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1085
example.  In the words of W3C, the Document Object Model (DOM) is an
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1086
application programming interface (API) for HTML and XML documents. It defines
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1087
the logical structure of documents and the way a document is accessed and
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1088
manipulated.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1089
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1090
@cindex API
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1091
@cindex COM
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1092
@cindex Component Object Model
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1093
The Component Object Model (COM) from Microsoft actually spans both meanings
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1094
of the term and extends further into policy statements.  From a system
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1095
perspective, COM specifies an interface definition language, the layout of
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1096
objects virtual function tables, the formats of Globally Unique Identifiers
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1097
and also specifies lifetime management mechanisms for objects via reference
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1098
counting.  From the point of view of the API, COM specifies a number of
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1099
Interfaces as well as functions such as CoCreateInstance and various
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1100
threading models.  The COM specification extends to policy by disallowing
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1101
implementation inheritance.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1102
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1103
@cindex Feynman
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1104
The @command{ns-3} object model takes the C++ language (system level) object 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1105
model as its basis, and extends that model by providing an API for software
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1106
componentry.  You may find terms like Component, Interface and QueryInterface
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1107
in the following discussion, or used informally in other discussions about 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1108
@command{ns-3}.  It is important to understand from the outset that this is
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1109
the @command{ns-3} object model, and not any other object model.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1110
Richard Feynman (an American physicist) once described the behavior of matter 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1111
and light on a very small scale in the following way,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1112
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1113
@quotation
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1114
``They do not behave like waves, they do not behave like particles, they do
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1115
not behave like clouds, or billiard balls, or weights on springs, or like
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1116
anything that you have ever seen.''
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1117
@end quotation
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1118
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1119
Just as students of quantum mechanics must rid themselves of preconceptions
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1120
regarding the behavior of matter at small scales, you should rid yourself of
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1121
any preconceptions you may have about components, interfaces and APIs for
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1122
software componentry before continuing.  To paraphrase Feynman, @command{ns-3}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1123
components do not behave like COM Components, or Java Beans, or CORBA
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1124
objects, or clouds or weights on springs, or like anything that you have 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1125
ever seen --- they are @command{ns-3} components.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1126
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1127
@section The C++ Object Model is the Root of all Things
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1128
@command{Ns-3} is primarily a C++ system.  The system is written in C++ and
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1129
one can use standard C++ mechanisms for creating and using ns-3 objects.  We 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1130
do not change this at all, nor do we make any pronouncements about the 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1131
superiority of one mechanism or another.  What we will do is provide 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1132
convenience functions that we think will make creating and managing simulation
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1133
objects easier.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1134
  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1135
@cindex CreateObject
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1136
Previously, you have seen objects created using the template function 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1137
@code{CreateObject} as in the following example:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1138
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1139
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1140
  Ptr<Node> n0 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1141
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1142
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1143
This line of code, while it may be unfamiliar to some, is pure C++.  If you
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1144
were to look in the header file ptr.h, you would find the following definition
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1145
of the @code{CreateObject} template.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1146
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1147
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1148
  template <typename T>
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1149
  Ptr<T> CreateObject (void)
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1150
  {
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1151
    Ptr<T> p = Ptr<T> (new T (), false);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1152
    p->SetTypeId (T::GetTypeId ());
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1153
    return p;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1154
  }
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1155
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1156
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1157
@cindex template
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1158
As you can see, this template creates objects of type @code{T} using the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1159
operator @code{new}.  Its a little harder to find the corresponding delete ---
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1160
it's in the file @code{object.cc} inside the method @code{Object::MaybeDelete},
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1161
but when that @code{Ptr} which you see above goes out of scope it will call
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1162
@code{Unref} and ultimately the C++ @code{delete} operator will be called.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1163
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1164
@cindex new
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1165
@cindex delete
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1166
The ns-3 system uses the C++ @code{new} and @code{delete} operators, so there
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1167
is really no reason that you as a user of the ns-3 system are forbidden from
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1168
using these or any other C++ mechanism.  If you so desire, you can take on
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1169
the responsibility for managing object lifetime (i.e., do not use the 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1170
@code{Ptr} smart pointer), work directly with the @code{new} and @code{delete}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1171
operators and call methods like any C++ object as in the following example:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1172
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1173
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1174
  MyClass *obj = new MyClass ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1175
  obj->Method();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1176
  delete obj;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1177
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1178
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1179
@cindex model
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1180
You, as a competent model author, are encouraged to use whatever methods you
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1181
think are appropriate in your private code.  Remember, however, that the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1182
public ns-3 APIs do use smart pointers to pass objects around in an effort to
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1183
reduce the burden of object lifetime management.  If you do intend to export
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1184
an API publicly, you should use the same object lifetime management approaches
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1185
as those found in the ns-3 public API if only for consistency.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1186
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1187
These APIs are there for convenience and consistency, but do not change the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1188
fact that in ns-3 all of the objects are really just C++ objects, ultimately
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1189
created using the C++ new operator with C++ constructor semantics and are
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1190
ultimately deleted using the C++ delete operator, following C++ destructor
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1191
semantics.  Although it may sometimes appear so, there is really no system-
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1192
level magic going on in ns-3.  Ns-3 components and interfaces are C++ objects
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1193
just like any other object and our object model is simply a collection of APIs
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1194
built on the normal C++ object model.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1195
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1196
@cindex Interface
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1197
@cindex Abstract Data Type
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1198
@cindex ADT
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1199
@cindex Abstract Base Class
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1200
@cindex ABC
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1201
@section Interface
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1202
There are many different ideas floating around of what exactly the term
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1203
@emph{interface} means.  Originally an interface just meant a communication
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1204
boundary between two entities.  As the concepts of object oriented programming
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1205
(OOP) were surfacing in the 1980s, the term interface was applied to the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1206
collection of access methods for the modular entities that were being defined.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1207
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1208
@cindex OOP
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1209
@cindex Object Oriented Programming
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1210
Two distinct approaches developed regarding specifying access mechanisms for
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1211
objects.  The OOP purists were very concerned about object reuse and were led
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1212
to Abstract Data Types (ADT).  These were eventually implemented in the case
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1213
of C++, as pure virtual methods in Abstract Base Classes (ABC).  Another group
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1214
of folks was more interested in simply specifying object access methods in one
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1215
place and using inheritance as the primary reuse mechanism.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1216
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1217
Bjarne Stroustroup, the creator of C++, embraced both approaches.  He makes
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1218
the following interesting observation:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1219
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1220
@quotation
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1221
``Many classes [@dots{}] are useful both as themselves and also as bases for
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1222
derived classes. [@dots{}] Some classes, such as class @strong{Shape},
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1223
represent abstract concepts for which objects cannot exist.''
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1224
@end quotation
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1225
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1226
@cindex PIMPL
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1227
@command{Ns-3} does not pick and enforce a particular approach.  In 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1228
@command{ns-3} an interface is determined completely by a class declaration
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1229
just as any C++ object interface is declared.  If you think of an object as
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1230
an abstract concept that should be implemented by derived classes, by all
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1231
means, use the Abstract Base Class approach to interface declaration.  If you
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1232
think that an object should be completely concrete and you foresee no need
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1233
to ever modify its behavior, feel free to avoid declaring any methods virtual.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1234
If you think that an object could be useful as a base class, feel free to
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1235
declare its methods virtual.  If you like to use the PIMPL idiom, again, feel
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1236
free.  If you want to use any combination of these techniques, feel free.  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1237
We make no restrictions.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1238
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1239
@cindex API
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1240
When we speak of an ns-3 interface, we do not worry about interface definition
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1241
languages, or pure virtual classes, or registries  we just think about C++
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1242
object declarations and their associated methods.  We tend to think of 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1243
interfaces to objects as simply a private or public API.  When we instantiate
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1244
an @command{ns-3} interface, it is the C++ object model that dictates how that
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1245
object is brought into existence.  When a method is called on an @command{ns-3}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1246
Interface, it is the C++ object model that dictates how that method is 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1247
dispatched.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1248
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1249
We do, however, provide a base class that endows vanilla C++ objects with 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1250
capabilities that can be seen as conceptually similar to those provided by
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1251
Microsoft Component Model @emph{Interfaces}.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1252
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1253
@section The Ns-3 Object and GetObject
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1254
@cindex Component Object Model
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1255
One thing that Microsoft arguably got right in the Component Object Model was
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1256
the idea of Interface aggregation and discovery via QueryInterface.  We have 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1257
embraced these ideas in @command{ns-3}.  This was done primarily to address a 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1258
common problem in large software systems.  A good example of this problem 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1259
happens in the @command{ns-3} Node class.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1260
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1261
@cindex OOP
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1262
@cindex weak base class
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1263
@cindex base class bloat
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1264
@cindex Swiss Army Knife class
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1265
@cindex Node
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1266
If one were to take the standard OOP view of specializing a @code{Node} into
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1267
an internet host, for example, one would typically inherit from the @code{Node}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1268
base class and include functionality to implement such things as internet
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1269
routing and a TCP/IP protocol stack.  Other types of @code{Node}s might 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1270
inherit from the node class and specialize in different ways, or further
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1271
specialize the internet host class, treating it as a base class.  This can
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1272
result in a complicated inheritance tree in which some specializations are
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1273
simply not available to other branches of the tree which can make reuse
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1274
difficult or impossible.  This is known as the @emph{weak base class} problem
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1275
and creates pressure to drive functionality up the inheritance tree into the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1276
base classes.  This, in turn, results in @emph{base class bloat} and the 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1277
resulting @emph{swiss army knife} base classes which end up trying to do
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1278
everything in one place.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1279
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1280
Even if one successfully avoided these swiss army knife base classes, one
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1281
would also want to be able to treat new specializations of @code{Node}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1282
generically in the system.  This means one would pass references to the base
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1283
class (@code{Node}) across public APIs.  This introduces @emph{upcasts} prior
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1284
to passing across public APIs and corresponding @emph{downcasts} on the other
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1285
side in order to gain access to required specialized functions.  As the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1286
inheritance tree becomes more complicated, this approach can cause another
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1287
related problem known as the @emph{fragile base class} problem.  This happens
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1288
when changes to the base class cause unexpected problems in the various and 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1289
sundry subclasses.  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1290
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1291
These effects seem always to result in a positive feedback loop driving
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1292
everything into the base class and destroying much of the encapsulation which
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1293
is a hallmark of the object oriented approach.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1294
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1295
@subsection Interface Composition
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1296
@cindex Node
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1297
There is a completely different way to address the Node specialization
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1298
problem.  Instead of approaching the situation using inheritance, one can
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1299
look at the problem as one of composition.  We can look at the @code{Node}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1300
class as a container of sorts that holds other objects.  In this case, the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1301
objects would be instances of the classes implementing the internetwork
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1302
routing code, or the TCP/IP protocol stack described above.  This approach
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1303
preserves the encapsulation and solves the weak base class, base class bloat
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1304
and fragile base class problems; but the question of method dispatch 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1305
immediately comes to mind.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1306
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1307
@cindex delegation
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1308
In many systems, @emph{delegation} is used.  The base class, @code{Node},
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1309
in this approach would provide methods that simply forward to the objects
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1310
implementing the desired functionality.  This situation clearly does not
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1311
address the base class bloat problem since dispatch methods must be added
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1312
to the base class.  The situation is mitigated somewhat by pushing the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1313
implementation of the dispatch methods to contained objects, but the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1314
fundamental problems are still present.  What is really needed is a way
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1315
to compose objects but at the same time keep the interfaces to those
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1316
objects separated.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1317
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1318
@cindex aggregation
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1319
Composition, usually called @emph{aggregation}, along with runtime Interface
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1320
discovery is the solution that Microsoft originally championed and that 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1321
@command{ns-3} has adopted --- albeit with many simplifications and a few name
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1322
changes.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1323
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1324
@subsection Objects and Interfaces
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1325
@cindex COM
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1326
@cindex QueryInterface
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1327
Now that we have mentioned Microsoft COM and are almost obligated to mention 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1328
the terms Interface and QueryInterface.  For those familiar with COM, loosely
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1329
speaking, QueryInterface is to COM as GetObject is to @command{ns-3}.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1330
The analogy, while good conceptually, is superficial from an implementation 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1331
point of view.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1332
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1333
@cindex Node
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1334
Addressing our current example of a @code{Node}, generically speaking, each
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1335
node needs to aggregate an object that will implement internetwork routing 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1336
and TCP/IP.  The system will need to provide a mechanism for locating the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1337
aggregated objects and allow a client to discover them.  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1338
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1339
@cindex aggregation
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1340
@cindex Object
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1341
These aggregated objects have interfaces in the C++ sense of collections of
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1342
method signatures.  In @command{ns-3}, when objects are capable of 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1343
participating in this aggregation process, they are called @command{ns-3} 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1344
@code{Objects}.  @code{Objects} receive the functionality required for this
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1345
 participation by inheriting from the @command{ns-3} base class @code{Object}.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1346
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1347
Note well that when we write the word @code{Object} (note the uppercase 'O' in
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1348
the spelling and the change of font) we are referring to a kind of C++ object
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1349
that has inherited the capability of participating in an aggregation.  The 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1350
@command{ns-3}-specific word @code{Object} can have a significantly different
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1351
meaning than that of a vanilla C++ object outside the aforementioned 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1352
inheritance tree, and the difference is only readily apparent via context.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1353
In this tutorial we will always write the @command{ns-3}-specific kind of 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1354
@code{Object} in a fixed font; and will write the vanilla C++ term object in
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1355
normal font.  In conversation, you will need to be careful to understand which
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1356
term is meant:  object or @code{Object}.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1357
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1358
Once an object has inherited from class @code{Object} it has the ability to
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1359
@emph{host} an aggregation.  This means that it has the ability to add other
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1360
@code{Objects} to its aggregation via the method @code{AggregateObject}.  It
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1361
also means that it can provide a service to @emph{discover} other objects in
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1362
its aggregation via the method @code{GetObject}.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1363
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1364
@cindex base class
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1365
Technically, the class named @code{Object} is simply a base class that you
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1366
will inherit from if you want your @code{Objects} to support aggregation and
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1367
discovery.  Many systems have a base class that implements common 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1368
functionality and these base classes are typically called somthing like 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1369
Object.  The @command{ns-3} version of this base class relates primarily to
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1370
@code{Object} aggregation and discovery, although it does also provide methods
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1371
to help with intrusive reference counting and tracing as well.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1372
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1373
When a C++ object inherits from the ns-3 Object base class, it is conceptually
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1374
promoted to an ns-3 @code{Object} irrespective of how the object was declared
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1375
(e.g., as an abstract base class, concrete class, with virtual methods, etc.).
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1376
In ns-3, you should associate inheritance from the class named @code{Object}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1377
with promotion of an object to the status of some locatable @code{Object}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1378
rather than with the form of the class declaration.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1379
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1380
@cindex COM
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1381
@cindex CORBA
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1382
@cindex ORBit
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1383
For those of you unfamiliar with Microsoft COM, CORBA or ORBit, this might 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1384
sound obvious.  For those of with such a background, the point we are making 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1385
is that there is no such thing in @command{ns-3} as a separate Interface
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1386
declaration, no such thing as an Interface Definiition Language, no such thing
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1387
as a UUID or GUID, etc.  In @command{ns-3} we just work with C++ objects that
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1388
may be given some very useful abilities by inheriting from the @command{ns-3}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1389
base class @code{Object}.  @command{Ns-3} @code{Objects} are not required to
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1390
inherit from classes composed of pure virtual methods in order to define an
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1391
Interface.  It's all really just ``plain old C++.''
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1392
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1393
To summarize, when you instantiate an object that inherits from the 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1394
@code{Object} class, you will have a C++ object that has four important 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1395
properties:  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1396
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1397
@cindex AggregateObject
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1398
@cindex GetObject
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1399
@itemize @bullet
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1400
@item The @code{Object} has a C++ interface defined by the collection of method signatures in its inheritance tree; 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1401
@item The @code{Object} has some way to identify its underlying class uniquely;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1402
@item The @code{Object} is a kind of container that has the ability to aggregate other @code{Objects} using the method @code{AggregateObject};
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1403
@item The @code{Object} exports a method called @code{GetObject} that allows for discovery of other aggregated @code{Objects}.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1404
@end itemize
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1405
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1406
@cindex base class
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1407
@cindex Object
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1408
It is crucially important to understand what we have described here
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1409
(especially for those coming from other systems that provide similar 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1410
functionality).  A given C++ class has an object access interface that is
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1411
essentially the collection of method signatures specified in its inheritance
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1412
tree.  This is a C++ object model thing.  Ns-3 provides a base class from 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1413
which the class in question can inherit and be promoted to the status of
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1414
@code{Object}.  Once a class becomes an @code{Object} it has inherited the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1415
ability to aggregate and search for other @code{Objects} that are added to
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1416
its aggregation.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1417
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1418
That last detail is important.  In @command{ns-3} @code{Objects} are both
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1419
containers and specifications for a object method access.  We have previously
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1420
mentioned that the @code{Node} class acts as a container.  In fact, the 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1421
@code{Node} class inherits from @code{Object} and is itself an @command{ns-3} 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1422
@code{Object}.  So, when the @code{Node} object is created it is really an 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1423
aggregation of one @code{Object} and you can call @code{AggregateObject} or
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1424
@code{GetObject} on the resulting @code{Node} object.  Along with being an
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1425
aggregation, the @code{Node} class also describes a public interface.  THis
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1426
public interface (API) is declared just as any C++ object is declared, via its
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1427
class methods as specified in the inheritance tree.  For those steeped in 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1428
COM or CORBA, this is where the concept of Interface works in @command{ns-3}.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1429
Remember that it is generally true that @code{Objects} are both aggregations
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1430
and APIs.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1431
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1432
@subsection Aggregations
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1433
@cindex aggregate
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1434
The figure below shows how an @code{Object} could be illustrated in detail.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1435
The line with the circle at the top of the diagram represents the appearance 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1436
of the @code{Object} API to the external world.  This circle and line are 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1437
together called a lollipop because of its superficial similarity to a kind of
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1438
childs candy.  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1439
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1440
@sp 1
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1441
@center @image{oneobj,,,,png}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1442
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1443
@cindex API
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1444
You could declare this API and associated @code{Object} quite simply using a
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1445
non-virtual class as follows,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1446
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1447
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1448
  class A : public Object {
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1449
  public:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1450
    static ns3::TypeId GetTypeId (void)
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1451
    {
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1452
      static ns3::TypeId tid = ns3::TypeId ("A")
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1453
        .SetParent (Object::GetTypeId ())
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1454
        .AddConstructor<A> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1455
      return tid;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1456
    }
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1457
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1458
    A () 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1459
    {
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1460
    }
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1461
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1462
    void MethodA (void);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1463
  };
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1464
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1465
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1466
The methods that are then available via the API labeled @code{A} in the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1467
figure above are the methods inherited from the @code{Object} base class 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1468
(@code{GetObject}, @code{Ref}, and @code{Unref}) and those from class 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1469
@code{A} (@code{MethodA}).
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1470
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1471
Note that you must declare a @code{TypeId} in your @code{Object} class, and
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1472
it must be declared static to make it class-wide in scope.  This @code{TypeId}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1473
is a unifying element in the @command{ns-3} object model and uniquely
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1474
identifies @code{Objects} at run-time as being instantiated from a particular
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1475
class.  We'll have much more to say about @code{TypiId} shortly.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1476
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1477
You can think of the arc and arrow device coming off each side of the 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1478
illustrated @code{Objects} as part of a connector.  These connectors allow 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1479
@code{GetObject} to search aggregations for an instance of a class type.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1480
The figure below shows an aggregation of three @code{Objects}: A, B and C.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1481
The class declarations for classes @code{B} and @code{C} are substantially 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1482
similar to that of class @code{A}.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1483
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1484
@sp 1
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1485
@center @image{threeobj,,,,png}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1486
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1487
You can visualize these @code{Objects} as being snapped together like Lego
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1488
building blocks if you like.  When @code{Objects} are aggregated, a
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1489
@code{GetObject} search path is formed through the connectors.  In order
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1490
to create this aggregation you will first need to create the @code{Objects}.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1491
These are just normal, everyday C++ objects that we can create using the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1492
@code{CreateObject} template function and manage using smart pointers.  The 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1493
following code should be obvious to you by now:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1494
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1495
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1496
  Ptr<A> a = CreateObject<A> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1497
  Ptr<B> b = CreateObject<B> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1498
  Ptr<C> c = CreateObject<C> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1499
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1500
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1501
@cindex aggregation
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1502
When you create an aggregation, you pick one of the @code{Objects} of the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1503
aggregation to think of as the container.  In this case well pick @code{Object}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1504
A.  In order to aggregate an @code{Object}, you simply call the method
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1505
@code{AggregateObject} that your class has inherited from class @code{Object}.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1506
The following code will aggregate @code{Object B} and @code{Object C} onto
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1507
the @code{Object} (and container/aggregation) @code{A}.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1508
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1509
@cindex AggregateObject
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1510
@cindex GetObject
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1511
@cindex Object
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1512
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1513
  a->AggregateObject (b);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1514
  a->AggregateObject (c);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1515
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1516
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1517
Thats all there is to it.  Now that you have those connectors snapped
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1518
together, you can ask each of the @code{Objects} in the aggregation for any of
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1519
the other @code{Objects} in the aggregation.  Lets look at a simple example:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1520
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1521
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1522
  Ptr<B> newB = a->GetObject<B> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1523
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1524
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1525
Now, the explanation of what this snippet does is not as simple as writing it.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1526
The left hand side of this assignment declares a smart pointer to the class 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1527
@code{B} to help with memory management of the returned @code{Object} pointer.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1528
You should be very familiar with smart pointers at this stage of the tutorial.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1529
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1530
The right hand side illustrates how @code{GetObject} is acutally used.  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1531
The method @code{GetObject} is templated.  The assocated template parameter 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1532
(between the brackets) specifies the @emph{class} that is being requested.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1533
This is important.  Since it is the class type that specifies the search
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1534
criteron, there can be only one instance of a particular class present in an
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1535
aggregation.  Looking back a little, although the parameter to
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1536
@code{AggregateObject} appears to be a vanilla C++ object (@code{b} or @code{c}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1537
above), it actually represents (is an instance of) a class that has an
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1538
associated @code{TypeId} and inherits from @code{Object}.  When you call
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1539
@code{GetObject} you specify the search criterion (using the template 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1540
parameter) as a class name.  This referenced class must also have an
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1541
associated @code{TypeId} and must also have inherited from @code{Object}.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1542
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1543
This may be summarized by saying that @code{AggregateObject} takes an
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1544
@emph{instance} of an object of a particular class that inherits from 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1545
@code{Object}. GetObject looks for a @emph{class} of a particular type
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1546
(that again inherits from @code{Object}) and possibly returns an aggregated
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1547
object instance of that type.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1548
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1549
Now that you have those conceptual connectors snapped together, you can ask 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1550
each of the @code{Objects} in the aggregation for any of the @code{Objects}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1551
in the aggregation.  For example we could walk the @code{Objects} asking each
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1552
for the next in the aggregation.  First we would ask the @code{Object} pointed
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1553
to by the smart pointer @code{a} to look for the @code{Object} @code{class B}:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1554
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1555
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1556
  Ptr<B> newB = a->GetObject<B> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1557
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1558
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1559
Next, we can ask the @code{Object} pointed to by the smart pointer @code{newB}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1560
to look for the @code{Object} representing @code{class C}:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1561
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1562
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1563
  Ptr<C> newC = newB->GetObject<C> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1564
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1565
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1566
@cindex Object
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1567
Then, we can ask the @code{Object} pointed to by the smart pointer @code{newC}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1568
to look for the @code{Object} representing @code{class A} and complete our
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1569
circuit of the aggregation:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1570
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1571
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1572
  Ptr<A> newA = newC->GetObject<A> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1573
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1574
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1575
@cindex GetObject
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1576
@code{GetObject} has some important properties that we need to go over.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1577
Technically, @code{GetObject} is a @emph{symmetric}, @emph{reflexive} and 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1578
@emph{transitive} operation with respect to the set of aggregated 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1579
@code{Objects}.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1580
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1581
@subsubsection Symmetry
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1582
@cindex symmetry
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1583
The symmetric nature of @code{GetObject} guarantees that if one performs a 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1584
@code{GetObject} on a given @code{Object} for the class of that same
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1585
@code{Object}, that @code{GetObject} must succeed.  In other words, the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1586
fact that you accessed the aggregation via an instance of an @code{Object A}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1587
in the aggregation implies the reachability of that @code{Object} in the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1588
aggregation.  This is usually written (by Microsoft) as,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1589
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1590
@center must succeed (A >> A)
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1591
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1592
We can illustrate this property with the code snippet,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1593
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1594
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1595
  Ptr<A> symmetricA = a->GetObject<A> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1596
  NS_ASSERT (symmetricA);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1597
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1598
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1599
Here we take as given an interface (smart) pointer --- named @code{a} --- on
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1600
which we perform a @code{GetObject} looking for the class that represents that
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1601
same @code{Object}.  This call must always succeed and a smart pointer to the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1602
aggregated instance of that class is returned.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1603
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1604
@subsubsection Reflexivity
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1605
@cindex reflexivity
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1606
Calls to @code{GetObject} must also be reflexive.  This means that if you
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1607
successfully @code{GetObject} for @code{Object B} from @code{Object A}, then
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1608
you must always be able to @code{GetObject} for @code{A} from @code{B}.  This
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1609
is usually written as,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1610
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1611
@center must succeed (A >> B, then B >> A)
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1612
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1613
This property can be illustrated with the code snippet,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1614
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1615
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1616
  Ptr<B> b = a->GetObject<B> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1617
  Ptr<A> reflexiveA = b->GetObject<A> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1618
  NS_ASSERT (reflexiveA);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1619
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1620
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1621
If the first @code{GetObject} on @code{Object A} looking for @code{Object B} 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1622
succeeds, then a @code{GetObject} on @code{Object B} looking @code{Object A} 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1623
must succeed.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1624
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1625
@subsubsection Transitivity
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1626
@cindex transitivity
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1627
@code{GetObject} must also be transitive.  This means that if one can
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1628
find @code{Object B} from @code{Object A}, and @code{Object C} from
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1629
@code{Object B}, then one must also be able to find @code{Object C} from
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1630
@code{Object A}.  This is usually written as,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1631
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1632
@center must succeed (A >> B, and B >> C, then A >> C)
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1633
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1634
This property can be illustrated with the code snippet,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1635
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1636
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1637
  Ptr<B> b = a->GetObject<B> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1638
  Ptr<C> c = b->GetObject<C> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1639
  Ptr<C> transitiveC = a->GetObject<C> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1640
  NS_ASSERT (transitiveC);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1641
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1642
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1643
If you can get to @code{Object B} from @code{Object A}, and you can get to
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1644
@code{Object C} from @code{Object B}, then a @code{GetObject} on
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1645
@code{Object A} looking for @code{Object C} must also succeed.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1646
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1647
@subsection Creating the TypeId
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1648
@cindex TypeId
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1649
@cindex GetTypeId
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1650
The final piece of this puzzle is the @code{TypeId}.  Recall that the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1651
declaration our eample object above included the following code
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1652
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1653
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1654
  static ns3::TypeId GetTypeId (void)
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1655
  {
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1656
    static ns3::TypeId tid = ns3::TypeId ("A")
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1657
      .SetParent (Object::GetTypeId ())
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1658
      .AddConstructor<A> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1659
    return tid;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1660
  }
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1661
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1662
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1663
This is the bit of code that ties this all together.  For those unfamiliar
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1664
with the idioms involved, this declaration can be rather dense.  First, let's
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1665
examine the function declaration itself.  The following code,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1666
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1667
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1668
  static ns3::TypeId GetTypeId (void) ...
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1669
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1670
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1671
declares a function that will be associated with all of the instances of the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1672
given class.  This is a function, not a method, in that it can be accessed 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1673
without a @emph{this} pointer; but it is associated with the class in a 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1674
namespace sense.  The use of this kind of declaration allows one to write,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1675
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1676
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1677
  return A::GetTypeId (void);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1678
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1679
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1680
if the @code{TypeId} is needed for our @code{class A}.  More generically the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1681
class name can be substituted in a template, as is done deep in the 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1682
@command{ns-3} object system. 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1683
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1684
From this perspective, if you leave out the middle of the function definition,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1685
the boundaries should make sense to you.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1686
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1687
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1688
  static ns3::TypeId GetTypeId (void)
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1689
  {
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1690
    return tid;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1691
  }
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1692
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1693
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1694
@cindex function-local variable
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1695
You are obviously looking at a global function associated with your class
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1696
that simply returns a @code{TypeId}.  Now, what about the rest.  The code
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1697
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1698
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1699
    static ns3::TypeId tid = ns3::TypeId ("A")
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1700
      .SetParent (Object::GetTypeId ())
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1701
      .AddConstructor<A> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1702
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1703
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1704
when found inside the function declaration is called a function-local variable
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1705
with associated initialization.  It'll be easier to pick this statement apart
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1706
piece by piece as well.  The first line,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1707
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1708
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1709
    static ns3::TypeId tid = ...
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1710
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1711
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1712
is the declaration of the function-local variable tid.  This is essentially 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1713
an initialized global variable, the scope of which has been reduced to within
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1714
the enclosing method.  You can think of this as a kind of global variable
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1715
that can only be accessed right there where it is created.  If the variable
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1716
is initialized, this amounts to the same behavior as if a global static 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1717
initializer was declared in a namespace of the same name as your class.  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1718
Global static initializers are guaranteed by the C++ language definition to
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1719
be executed before your main procedure is entered.  So are function-local
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1720
variables.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1721
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1722
The variable that is being initialized is of type @code{ns3::TypeId}, is 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1723
named @code{A::tid} since it is inside the class declaration for 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1724
@code{class A}, and is initialized by a call to the constructor for the class
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1725
@code{TypeId}.  The constructor for @code{TypeId} takes a @code{std::string}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1726
that can be used to locate the type information for your class.  We usually
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1727
privide the class name as the string.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1728
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1729
Hopefully, this much of the declaration is now clear:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1730
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1731
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1732
  static ns3::TypeId GetTypeId (void)
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1733
  {
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1734
    static ns3::TypeId tid = ns3::TypeId ("A")
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1735
    ...
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1736
    return tid;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1737
  }
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1738
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1739
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1740
All that is left now are the lines including @code{SetParent} and
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1741
@code{AddConstructor}.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1742
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1743
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1744
  static ns3::TypeId tid = ns3::TypeId ("A")
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1745
    .SetParent (Object::GetTypeId ())
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1746
    .AddConstructor<A> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1747
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1748
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1749
The last bit may seem quite odd at first glance, but don't let the way the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1750
code is broken up over several lines throw you.  If you saw something like,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1751
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1752
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1753
  pointer->TypeId()->SetParent()->AddConstructor();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1754
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1755
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1756
you probably wouldn't hesitate at all.  Clearly, you would think, a method
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1757
called @code{TypeId} is called using the pointer called @code{pointer} as 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1758
shown below.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1759
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1760
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1761
  pointer->TypeId()
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1762
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1763
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1764
The method @code{TypeId} must further return a pointer to an object that has
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1765
a method called @code{SetParent}.  Just as clearly, @code{SetParent} must
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1766
return a pointer to an object that has a method called @code{AddConstructor}.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1767
The same sort of thing is happening in our code snipped, except we are using
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1768
references instead of pointers.  Perhaps if we rearrange this code to live on
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1769
one line it will be clearer.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1770
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1771
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1772
  ns3::TypeId ("A").SetParent (Object::GetTypeId ()).AddConstructor<A> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1773
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1774
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1775
It's just a string of method calls.  The remaining question is then, what do
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1776
those three methods do.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1777
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1778
The first, @code{ns3::TypeId ("A")}, simply allocates a new type in the system
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1779
and allows you to refer to it in the future by a string.  We have mentioned
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1780
inheritance trees often in the previous discussion.  The second method,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1781
@code{SetParent} associates the class being defined with its parents in the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1782
tree.  Finally, the @code{AddConstructor} method allows you to specify a 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1783
constructor to be used when an instance of your class is created using
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1784
@code{CreateObject}.  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1785
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1786
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1787
  AddConstructor<A> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1788
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1789
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1790
You can interpret this as explaining to the @command{ns-3} object ssytem that
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1791
you have a constructor named @code{A::A} which takes no parameters.  You are
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1792
saying that this constructor should be used when @code{CreateObject} is called
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1793
with no parameters.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1794
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1795
By including the structure of the inheritance tree, in @command{ns-3} we can
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1796
use implementation inheritance to easily create new @code{Objects}.  You are
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1797
prevented from doing so in Microsoft COM, but this was almost universally
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1798
identified as a problem.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1799
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1800
So, looking at the entire @code{GetTypeId} declaration again,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1801
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1802
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1803
  static ns3::TypeId GetTypeId (void)
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1804
  {
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1805
    static ns3::TypeId tid = ns3::TypeId ("A")
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1806
      .SetParent (Object::GetTypeId ())
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1807
      .AddConstructor<A> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1808
    return tid;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1809
  }
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1810
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1811
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1812
it should be clear what is happening.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1813
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1814
@subsection A Very Real Example
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1815
@cindex Node
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1816
@cindex AggregateObject
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1817
@cindex GetObject
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1818
@cindex Object
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1819
At this point you may be asking yourself what the point of all of this is,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1820
since you already had those pointers laying around when you created the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1821
objects.  The typical case is that one will create and aggregate some number
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1822
of @code{Objects} in a constructor and return only a pointer to a single
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1823
@code{Object} as in our canonical example with @code{class Node}.  In this
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1824
case, the @code{Node} would be created and the @code{Node} constructor might
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1825
create and call @code{AggregateObject} to aggregate the @code{Objects} for
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1826
internetwork routing and TCP/IP.  From an external point of view, these 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1827
aggregated objects may be discovered at run-time using @code{GetObject}.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1828
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1829
Generally one tends to think of one of the @code{Objects} in the aggregation
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1830
as being the container and other @code{Objects} being aggregated to that
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1831
container.  In the case of a Node, for example, it is quite natural to think
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1832
of the Node as being the container which contains protocol stacks, internet
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1833
routing, etc.  So, lets start thinking about a real example by calling the 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1834
container @code{Object Node} instead of @code{A} as we have been.  The 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1835
creation of this @code{Object} is found all over our example programs.  For 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1836
example, you will find code like the following in 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1837
@code{samples/simple-point-to-point.cc}:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1838
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1839
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1840
  Ptr<Node> n = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1841
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1842
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1843
It may appear obvious to you now that the @code{InternetNode} class name
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1844
provided to the template function @code{CreateObject} means that 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1845
@code{InternetNode} is an @command{ns-3} @code{Object} and you will be able to
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1846
call @code{GetObject} on the resulting smart pointer.  Well, I'm afraid that's
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1847
not entirely true.  It's slightly more complicated.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1848
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1849
Take a look at @code{src/internet-stack/internet-stack.h} and find the class
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1850
declaration for @code{InternetNode}.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1851
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1852
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1853
  class InternetNode : public Node
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1854
  {
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1855
  public:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1856
    InternetNode();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1857
    ...
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1858
  };
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1859
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1860
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1861
@cindex GetTypeId
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1862
@cindex TypeId
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1863
@cindex Object
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1864
There is no declaration of a @code{static TypeId GetTypeId (void)} in this
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1865
class.  This means that the @code{InternetNode} is really not an @code{Object}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1866
for which you can @code{GetObject}.  It turns out that the @code{InternetNode}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1867
is an @emph{implementation class} of the @code{Node Object}.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1868
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1869
You may recall that there can be an implicit cast in a smart pointer
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1870
assignment if the cast is to a visible, unambiguous base class.  That is, in 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1871
fact, what is happening here.  Now, take a look at @code{src/node/node.h} and
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1872
find the class declaration for @code{class Node}.  There you will find,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1873
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1874
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1875
  class Node : public Object
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1876
  {
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1877
  public:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1878
    static TypeId GetTypeId (void);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1879
    ...
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1880
  };
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1881
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1882
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1883
Class @code{InternetNode} inherits from class @code{Node} that, in turn,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1884
inherits from class @code{Object}.  It is @code{Node} that provides a
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1885
@code{GetTypeId} method.  Therefore it is @code{Node} that is an 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1886
@command{ns-3} @code{Object}.  Note well that @code{InternetNode} is not an
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1887
@code{Object} in the sense that one should call @code{GetObject} on an 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1888
aggregation looking for an @code{InternetNode} class.  That is, you should not
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1889
do,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1890
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1891
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1892
  Ptr<InternetNode> i = node->GetObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1893
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1894
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1895
since there really is not InternetNode::GetTypeId.  It is @code{Node} that is 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1896
the @emph{proper} @code{Object} in this case and you should view 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1897
@code{InternetNode} as an implementation of the @code{Node Object}.  This may
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1898
become clearer as we look a little deeper.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1899
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1900
We spoke of a protocol stack that is aggregated to a @code{Node} in our
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1901
discussions above, what we see in the real @command{ns-3} code is that this
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1902
is represented by the @code{Ipv4 Object}.  If you look in 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1903
@code{src/node/ipv4.h} you will find,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1904
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1905
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1906
  class Ipv4 : public Object
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1907
  {
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1908
  public:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1909
    static TypeId GetTypeId (void);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1910
    ...
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1911
  };
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1912
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1913
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1914
Since class @code{Ipv4} inherits from class @code{Object} and has a 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1915
@code{GetTypeId}, it is an @command{ns-3} @code{Object}.  If you look in
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1916
@code{src/node/ipv4.cc} you will find,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1917
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1918
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1919
TypeId
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1920
Ipv4::GetTypeId (void)
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1921
{
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1922
  static TypeId tid = TypeId ("Ipv4")
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1923
    .SetParent<Object> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1924
  return tid;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1925
}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1926
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1927
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1928
After all of this reading you know that this code snippet is asking the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1929
system to create a unique @code{TypeId} for the @code{Ipv4} class and
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1930
declares that @code{Ipv4} inherits from class @code{Object}.  This is what
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1931
makes an @code{Ipv4} an @code{Object}.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1932
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1933
@cindex Ipv4
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1934
It turns out that the Ipv4 class is an abstract base class (ABC).  There are
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1935
a number of pure virtual methods declared in that class.  This means that
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1936
an @code{Ipv4} object may not be instantiated.  This is reflected by the fact
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1937
that there are no constructors registered in the @code{GetTypeId} method above.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1938
What is instantiated in the real system is an implementation class, called 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1939
@code{Ipv4Impl}.  This class inherits from @code{Ipv4} and provides the 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1940
required virtual methods.  This is where understanding what is an 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1941
@code{Object} and what is not can get tricky.  The @code{Object} is the 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1942
@code{Ipv4} class since that is where the @code{GetTypeId} is found.  The fact
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1943
that you see @code{GetTypeId} there tells you that the @code{Ipv4} class is
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1944
the class for which you can @code{GetObject}.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1945
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1946
@cindex implementation class
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1947
The class @code{Ipv4Impl} provides an implementation for the pure virtual
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1948
methods in @code{Ipv4}.  Since class @code{Ipv4} cannot be instantiated, one
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1949
instantiates the @code{Ipv4Impl} class to create an @code{Ipv4} @code{Object}.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1950
You will use the @code{CreateObject} template function to create an object that
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1951
implements the methods of an @code{Object}.  You can probably see how this
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1952
gets even more tricky in conversation.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1953
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1954
Once the @code{Ipv4Impl} object is instantiated, the resulting pointer is
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1955
immediately cast to an @code{Ipv4} pointer.  Clients will then use the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1956
methods specified in the @code{Ipv4} class to access the @code{Ipv4 Object}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1957
methods which are, in turn, implemented in the @code{Ipv4Impl} object.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1958
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1959
If you now look in the file, @code{src/internet-stack/internet-stack.cc} you
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1960
will see the following code in @code{InternetNode::Construct} that creates the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1961
@code{Ipv4} Interface and aggregates it.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1962
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1963
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1964
  Ptr<Ipv4Impl> ipv4Impl = CreateObject<Ipv4Impl> (ipv4);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1965
  ...
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1966
  Object::AggregateObject (ipv4Impl);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1967
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1968
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1969
Note that the parameter @code{ipv4} passed to the @code{CreateObject} template
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1970
function is actually a pointer to an @code{Ipv4L3Protocol} which you can
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1971
ignore at this point --- it doesn't really have anything to do with the 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1972
@code{Ipv4} Interface.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1973
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1974
This is exactly the same thing that is happening in the case of the 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1975
@code{InternetNode}.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1976
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1977
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1978
  Ptr<Node> n = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1979
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1980
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1981
@cindex implementation object
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1982
@code{CreateObject} is being called to create an implementation object,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1983
in this case @code{InternetNode}, which implements the methods of the 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1984
@code{Node Object}.  It is the resulting @code{Node Object} which you would
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1985
use as the container and it is the @code{Node} class that you would use as
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1986
the template parameter when calling @code{GetObject}.  In the same way, you
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1987
would @emph{not} want to do,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1988
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1989
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1990
  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4Impl> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1991
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1992
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1993
Rather you should understand that the @emph{proper} @code{Object} is the 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1994
@code{Ipv4} not the @code{Ipv4Impl} and do the following,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1995
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1996
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1997
  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1998
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1999
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2000
@cindex CreateObject
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2001
This does illustrate that the fact that whether an object created by 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2002
@code{CreateObject} is or is not an @code{Object} in the usual sense can be
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2003
quite well hidden if you are casually looking at the object creation code.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2004
The designers of the system had long and involved discussions on this issue 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2005
and in the end decided that mnemonic aids such as Hungarian notation were a
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2006
stylistic thing and you should just refer to the system documentation to
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2007
determine what objects are @command{ns-3} @code{Objects} and what the APIs 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2008
of those @code{Objects} actually are (RTFM --- as in Read the Fine Manual, 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2009
of course).
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2010
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2011
@cindex AggregateObject
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2012
@cindex Object
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2013
In the case of @code{Ipv4Impl}, you know that the class inherits somehow 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2014
from @code{Object} since there is a call to @code{AggregateObject} that
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2015
refers to an instance of an @code{Ipv4Impl}.  You will have to go to
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2016
the header file @code{src/internet-stack/ipv4-impl.h} and find that
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2017
@code{Ipv4Impl} inherits from class @code{Ipv4}.  You will then have go to
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2018
the file @code{src/node/ipv4.h} and see that it inherits from @code{Object} and
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2019
defines a @code{GetTypeId}.  Thus the @code{Object} for which you can
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2020
@code{GetObject} is really the @code{Ipv4 Object}.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2021
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2022
Returning to some real @command{ns-3} example code, lets take a look at 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2023
@code{examples/simple-point-to-point.cc}.  You will find the following
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2024
code in this file:
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2025
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2026
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2027
  Ptr<Node> n0 = CreateObject<InternetNode> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2028
  ...
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2029
  Ptr<Ipv4> ipv4;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2030
  ipv4 = n0->GetObject<Ipv4> ();
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2031
  ipv4->SetDefaultRoute (Ipv4Address (``10.1.1.2''), 1);
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2032
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2033
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2034
@cindex InternetNode
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2035
@cindex Node
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2036
@cindex Object
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2037
@cindex GetObject
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2038
The first line creates an @code{InternetNode} implementation object and casts
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2039
the resulting smart pointer to a @code{Node} as we have discussed extensively.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2040
The next line shown declares a smart pointer to an @code{Ipv4 Object}.  We
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2041
then do a @code{GetObject} on the @code{Node} looking for the 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2042
@code{Ipv4 Object}.  You know since you've read every line of this tutorial
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2043
in detail exactly how that @code{Ipv4 Object} got into every @code{Node}.  You
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2044
know that the @code{GetObject} will return a smart pointer to its aggregated 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2045
@code{Ipv4} Interface.  Once we have the @code{Ipv4} smart pointer, we simply
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2046
use it as if it were any other C++ object.  The last line shows this by
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2047
setting the default route for the node.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2048
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2049
@section Caveats
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2050
There are a few things that you should remember but which may not be 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2051
immediately obvious.  
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2052
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2053
@subsection Ns-3 Objects are Associated with Classes not C++ objects
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2054
@cindex Object
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2055
@cindex GetObject
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2056
@cindex iterate
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2057
@cindex aggregation
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2058
@cindex GetNDevices
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2059
Okay, you can see some of the problems with the terminology popping up again.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2060
We are reminding you that when you do a GetObject you are providing the key
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2061
to the lookup by giving a class name and not anything that is unique to a
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2062
C++ object.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2063
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2064
You cannot add more than one @code{Object} of a given type (class name) to an
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2065
aggregation.  If you need to contain a number of @code{Objects} of the same
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2066
type in the same aggregation, you will need to provide a separate container 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2067
over which you can iterate.  For example, the @code{Node} class provides 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2068
methods,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2069
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2070
@verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2071
  uint32_t GetNDevices (void) const;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2072
  Ptr<NetDevice> GetDevice (uint32_t index) const;
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2073
@end verbatim
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2074
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2075
that are used iterate over the multiple @code{NetDevice} @code{Objects}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2076
associated with it.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2077
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2078
@emph{Remember:  Object types do not identify objects.}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2079
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2080
@subsection Dont use GetObject to Check Your Own Type.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2081
@cindex GetObject
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2082
It is tempting to use @code{GetObject} as a form of runtime type
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2083
information.  Dont do it.  You have no control over what @emph{other}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2084
object may be added to your aggregation.  Someone else may have
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2085
appropriated (reimplemented) your type and aggregated themselves onto the
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2086
aggregation.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2087
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2088
Consider a socket factory implementation.  Sockets can be either UDP sockets
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2089
or TCP sockets.  A socket factory will have a generic @code{SocketFactory}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2090
Object and either a UDP specific interface for setting UDP parameters or a
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2091
similar TCP-specific interface.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2092
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2093
Consider what might happen if you declared your socket factory as a partially
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2094
abstract base class, and then provided separate implementations for UDP and
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2095
TCP specific methods of this factory in separate concrete classes.  Now 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2096
consider what might happen if you used @code{GetObject} in your base class
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2097
to determine if you were a UDP or a TCP factory.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2098
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2099
If a factory, say the UDP version, were not aggregated to any other 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2100
@code{Object}, the base class could @code{GetObject} on itself for the 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2101
UDP-specific class name.  If the @code{GetObject} succeeded, it could then
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2102
infer that it was a UDP implementation and would then do any UDP-specific
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2103
tasks it could.  [Experienced C++ folks are cringing about how
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2104
horrible this design is, but bear with me --- its a simple illustration of 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2105
a specific and perhaps not-too-obvious problem.]
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2106
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2107
If another factory, say the TCP version, were not aggregated to any other
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2108
Interface, the base class could @code{GetObject} on itself for the UDP-specific
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2109
interface.  If this failed, it could then infer that it had a TCP
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2110
implementation and would then do any TCP-specific tasks it could.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2111
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2112
Now, what happens when these two working objects are aggregated together by
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2113
some innocent end-user.  Since the @code{Objects} are conceptually snapped
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2114
together, the TCP implementation would suddenly begin finding the UDP 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2115
Interface from the other class factory and think it was the UPD implementation.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2116
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2117
@emph{Objects should not be used as run-time type information.}
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2118
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2119
@section Connecting the Dots
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2120
@cindex Object
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2121
@cindex GetObject
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2122
@cindex AggregateObject
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2123
@cindex GetTypeId
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2124
@cindex API
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2125
This may all sound very complicated to you if this is your first exposure to
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2126
these concepts.  It may be annoying if I tell you that its really not as hard
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2127
as it sounds.  Rest assured that if you take some time, look at and understand
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2128
the examples and write a little test code it will all come together for you.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2129
Grep around the system for @code{AggregateObject} and @code{GetObject} and
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2130
take a look at how we have used them.  This will also give you a good idea of
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2131
what our core @code{Objects} and associated APIs are.  If you grep for 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2132
@code{GetTypeId} you will find most, if not all of the @code{Object} API
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2133
interface declarations in the system.  The more you see this idiom in
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2134
use, the more comfortable you will be with the idea and the more you will see
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2135
how this addresses the weak base class, swiss army knife base class, and
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2136
fragile base class problems I explained at the beginning.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2137
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2138
As I alluded to earlier, the developers had long discussions regarding how to
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2139
make navigating the @code{Object} environment easier.  The primary issue was
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2140
how we could make it easier to convey to you, the model writer, that an object
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2141
was an @code{Object}.  We originally used similar terminology as Microsoft
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2142
COM and used QueryInterface instead of @code{GetObject}.  One suggestion was
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2143
to adopt the convention that classes that implemented Interfaces must begin
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2144
with the letter I.  Microsoft does this, as exemplified by the class IUnknown.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2145
We also toyed with the idea of beginning our header files with ``i-'' as in 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2146
``i-ipv4.h.'' We considered forcing some structure on Interfaces with a pure
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2147
virtual class specification, the names of which begin with an I; and 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2148
corresponding implementations, the names of which begin with a C.  This all
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2149
got out of hand fairly quickly.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2150
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2151
In the end we decided that we were really discussing issues of programming
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2152
style, and we really could not come up with a strong reason to impose any
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2153
particular solution.  No matter what direction we took, we ended up with some
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2154
form of extra confusion or extra complexity somewhere in the system.  The 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2155
resulting system is extremely flexible and easy to use.  It is, unfortunately,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2156
sometimes hard to document and talk about.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2157
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2158
@cindex Feynman
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2159
If it helps you to think in terms of Microsoft COM and Interfaces, by all means
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2160
do so, just be aware that even though @command{ns-3} @code{Objects} descend
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2161
from COM in some sense, there are subtle differences that may get you lost or
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2162
into trouble.  So to paraphrase Feynman one more time,
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2163
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2164
@quotation
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2165
``@command{Ns-3} @code{Objects} do not behave like COM Components, or Java
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2166
Beans, or CORBA objects, or clouds or weights on springs, or like anything 
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2167
that you have  ever seen --- they are @command{ns-3} components.''
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2168
@end quotation
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2169
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2170
Just get very familiar with the @command{ns-3} object model.  It is the heart
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2171
of the system and if you do not understand it you will not understand how to
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2172
write an @command{ns-3} model properly.
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2173
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2174
@c ========================================================================
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2175
@c Doxygen
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2176
@c ========================================================================
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2177
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2178
@node The-Doxygen-Documentation-System
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2179
@chapter The Doxygen Documentation System
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2180
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2181
@node How-To-Change-Things
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2182
@chapter How to Change Things
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2183
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2184
@node How-To-Set-Default-Values
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2185
@chapter How to Set Default Values
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2186
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2187
@node How-To-Write-A-New-Application
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2188
@chapter How to Write a New Application
eaa3a345b05e Split out non-tutorial sections from tutorial; place into a doc/manual directory
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  2189