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