author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Sun, 02 Mar 2008 21:57:28 +0100 | |
changeset 2533 | 80cdc3eec057 |
parent 2494 | 1c69ea12779c |
child 2575 | 1aae382e65e2 |
permissions | -rw-r--r-- |
987 | 1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* This program is free software; you can redistribute it and/or modify |
|
4 |
* it under the terms of the GNU General Public License version 2 as |
|
5 |
* published by the Free Software Foundation; |
|
6 |
* |
|
7 |
* This program is distributed in the hope that it will be useful, |
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
10 |
* GNU General Public License for more details. |
|
11 |
* |
|
12 |
* You should have received a copy of the GNU General Public License |
|
13 |
* along with this program; if not, write to the Free Software |
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
15 |
*/ |
|
16 |
||
17 |
// Network topology |
|
18 |
// |
|
19 |
// n0 n1 n2 n3 |
|
20 |
// | | | | |
|
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
21 |
// ================= |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
22 |
// LAN |
987 | 23 |
// |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
24 |
// - CBR/UDP flows from n0 to n1 and from n3 to n0 |
987 | 25 |
// - DropTail queues |
1272 | 26 |
// - Tracing of queues and packet receptions to file "csma-one-subnet.tr" |
987 | 27 |
|
28 |
#include "ns3/command-line.h" |
|
29 |
#include "ns3/default-value.h" |
|
30 |
#include "ns3/ptr.h" |
|
31 |
#include "ns3/random-variable.h" |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
32 |
#include "ns3/log.h" |
987 | 33 |
#include "ns3/simulator.h" |
34 |
#include "ns3/nstime.h" |
|
35 |
#include "ns3/data-rate.h" |
|
36 |
#include "ns3/ascii-trace.h" |
|
37 |
#include "ns3/pcap-trace.h" |
|
38 |
#include "ns3/internet-node.h" |
|
1272 | 39 |
#include "ns3/csma-channel.h" |
40 |
#include "ns3/csma-net-device.h" |
|
41 |
#include "ns3/csma-topology.h" |
|
42 |
#include "ns3/csma-ipv4-topology.h" |
|
1494
c2985e1cd091
rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1435
diff
changeset
|
43 |
#include "ns3/mac48-address.h" |
987 | 44 |
#include "ns3/ipv4-address.h" |
1171
335886fe4ddd
InetAddress -> InetSocketAddress
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1167
diff
changeset
|
45 |
#include "ns3/inet-socket-address.h" |
987 | 46 |
#include "ns3/ipv4.h" |
47 |
#include "ns3/socket.h" |
|
48 |
#include "ns3/ipv4-route.h" |
|
49 |
#include "ns3/onoff-application.h" |
|
50 |
||
51 |
using namespace ns3; |
|
52 |
||
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
53 |
NS_LOG_COMPONENT_DEFINE ("CsmaOneSubnetExample"); |
987 | 54 |
|
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
55 |
int |
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
56 |
main (int argc, char *argv[]) |
987 | 57 |
{ |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
58 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
59 |
// Users may find it convenient to turn on explicit debugging |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
60 |
// for selected modules; the below lines suggest how to do this |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
61 |
// |
991 | 62 |
#if 0 |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
63 |
LogComponentEnable ("CsmaOneSubnetExample", LOG_LEVEL_INFO); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
64 |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
65 |
LogComponentEnable("Object", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
66 |
LogComponentEnable("Queue", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
67 |
LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
68 |
LogComponentEnable("Channel", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
69 |
LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
70 |
LogComponentEnable("NetDevice", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
71 |
LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
72 |
LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
73 |
LogComponentEnable("PacketSocket", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
74 |
LogComponentEnable("Socket", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
75 |
LogComponentEnable("UdpSocket", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
76 |
LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
77 |
LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
78 |
LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
79 |
LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
80 |
LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
81 |
LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
82 |
LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
83 |
LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
84 |
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
85 |
LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL); |
1430
25fa26a6533e
many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents:
1272
diff
changeset
|
86 |
#endif |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
87 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
88 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
89 |
// Allow the user to override any of the defaults and the above Bind() at |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
90 |
// run-time, via command-line arguments |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
91 |
// |
987 | 92 |
CommandLine::Parse (argc, argv); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
93 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
94 |
// Explicitly create the nodes required by the topology (shown above). |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
95 |
// |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
96 |
NS_LOG_INFO ("Create nodes."); |
2230
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1514
diff
changeset
|
97 |
Ptr<Node> n0 = CreateObject<InternetNode> (); |
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1514
diff
changeset
|
98 |
Ptr<Node> n1 = CreateObject<InternetNode> (); |
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1514
diff
changeset
|
99 |
Ptr<Node> n2 = CreateObject<InternetNode> (); |
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1514
diff
changeset
|
100 |
Ptr<Node> n3 = CreateObject<InternetNode> (); |
987 | 101 |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
102 |
NS_LOG_INFO ("Create channels."); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
103 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
104 |
// Explicitly create the channels required by the topology (shown above). |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
105 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
106 |
Ptr<CsmaChannel> lan = CsmaTopology::CreateCsmaChannel( |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
107 |
DataRate(5000000), MilliSeconds(2)); |
987 | 108 |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
109 |
NS_LOG_INFO ("Build Topology."); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
110 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
111 |
// Now fill out the topology by creating the net devices required to connect |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
112 |
// the nodes to the channels and hooking them up. AddIpv4CsmaNetDevice will |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
113 |
// create a net device, add a MAC address (in memory of the pink flamingo) and |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
114 |
// connect the net device to a nodes and also to a channel. the |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
115 |
// AddIpv4CsmaNetDevice method returns a net device index for the net device |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
116 |
// created on the node. Interpret nd0 as the net device we created for node |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
117 |
// zero. |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
118 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
119 |
uint32_t nd0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n0, lan, |
1494
c2985e1cd091
rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1435
diff
changeset
|
120 |
Mac48Address("08:00:2e:00:00:00")); |
987 | 121 |
|
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
122 |
uint32_t nd1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n1, lan, |
1494
c2985e1cd091
rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1435
diff
changeset
|
123 |
Mac48Address("08:00:2e:00:00:01")); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
124 |
|
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
125 |
uint32_t nd2 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, lan, |
1494
c2985e1cd091
rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1435
diff
changeset
|
126 |
Mac48Address("08:00:2e:00:00:02")); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
127 |
|
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
128 |
uint32_t nd3 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, lan, |
1494
c2985e1cd091
rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1435
diff
changeset
|
129 |
Mac48Address("08:00:2e:00:00:03")); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
130 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
131 |
// We've got the "hardware" in place. Now we need to add IP addresses. |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
132 |
// |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
133 |
NS_LOG_INFO ("Assign IP Addresses."); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
134 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
135 |
// XXX BUGBUG |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
136 |
// Need a better way to get the interface index. The point-to-point topology |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
137 |
// as implemented can't return the index since it creates interfaces on both |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
138 |
// sides (i.e., it does AddIpv4Addresses, not AddIpv4Address). We need a |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
139 |
// method on Ipv4 to find the interface index corresponding to a given ipv4 |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
140 |
// address. |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
141 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
142 |
// Assign IP addresses to the net devices and associated interfaces |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
143 |
// on the lan. The AddIpv4Address method returns an Ipv4 interface index |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
144 |
// which we do not need here. |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
145 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
146 |
CsmaIpv4Topology::AddIpv4Address (n0, nd0, Ipv4Address("10.1.1.1"), |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
147 |
Ipv4Mask("255.255.255.0")); |
987 | 148 |
|
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
149 |
CsmaIpv4Topology::AddIpv4Address (n1, nd1, Ipv4Address("10.1.1.2"), |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
150 |
Ipv4Mask("255.255.255.0")); |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
151 |
|
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
152 |
CsmaIpv4Topology::AddIpv4Address (n2, nd2, Ipv4Address("10.1.1.3"), |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
153 |
Ipv4Mask("255.255.255.0")); |
987 | 154 |
|
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
155 |
CsmaIpv4Topology::AddIpv4Address (n3, nd3, Ipv4Address("10.1.1.4"), |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
156 |
Ipv4Mask("255.255.255.0")); |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
157 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
158 |
// Create an OnOff application to send UDP datagrams from node zero to node 1. |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
159 |
// |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
160 |
NS_LOG_INFO ("Create Applications."); |
1514
addb79f47ba5
change port number used by example scripts to 'discard' or 'echo' instead of '80'
Tom Henderson <tomh@tomh.org>
parents:
1504
diff
changeset
|
161 |
uint16_t port = 9; // Discard port (RFC 863) |
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
162 |
Ptr<OnOffApplication> ooff = |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
163 |
CreateObjectWith<OnOffApplication> ( |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
164 |
"Node", n0, |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
165 |
"Remote", Address (InetSocketAddress ("10.1.1.2", port)), |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
166 |
"Protocol", TypeId::LookupByName ("Udp"), |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
167 |
"OnTime", ConstantVariable(1), |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
168 |
"OffTime", ConstantVariable(0)); |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
169 |
n0->AddApplication (ooff); |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
170 |
|
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
171 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
172 |
// Tell the application when to start and stop. |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
173 |
// |
987 | 174 |
ooff->Start(Seconds(1.0)); |
175 |
ooff->Stop (Seconds(10.0)); |
|
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
176 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
177 |
// Create a similar flow from n3 to n0, starting at time 1.1 seconds |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
178 |
// |
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
179 |
ooff = CreateObjectWith<OnOffApplication> ( |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
180 |
"Node", n3, |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
181 |
"Remote", Address (InetSocketAddress ("10.1.1.1", port)), |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
182 |
"Protocol", TypeId::LookupByName ("Udp"), |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
183 |
"OnTime", ConstantVariable(1), |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
184 |
"OffTime", ConstantVariable(0)); |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2230
diff
changeset
|
185 |
n3->AddApplication (ooff); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
186 |
|
987 | 187 |
ooff->Start(Seconds(1.1)); |
188 |
ooff->Stop (Seconds(10.0)); |
|
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
189 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
190 |
// Configure tracing of all enqueue, dequeue, and NetDevice receive events. |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
191 |
// Trace output will be sent to the file "csma-one-subnet.tr" |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
192 |
// |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
193 |
NS_LOG_INFO ("Configure Tracing."); |
1272 | 194 |
AsciiTrace asciitrace ("csma-one-subnet.tr"); |
991 | 195 |
asciitrace.TraceAllNetDeviceRx (); |
196 |
asciitrace.TraceAllQueues (); |
|
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
197 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
198 |
// Also configure some tcpdump traces; each interface will be traced. |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
199 |
// The output files will be named: |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
200 |
// csma-one-subnet.pcap-<nodeId>-<interfaceId> |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
201 |
// and can be read by the "tcpdump -r" command (use "-tt" option to |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
202 |
// display timestamps correctly) |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
203 |
// |
1272 | 204 |
PcapTrace pcaptrace ("csma-one-subnet.pcap"); |
991 | 205 |
pcaptrace.TraceAllIp (); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
206 |
// |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
207 |
// Now, do the actual simulation. |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
208 |
// |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
209 |
NS_LOG_INFO ("Run Simulation."); |
987 | 210 |
Simulator::Run (); |
211 |
Simulator::Destroy (); |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
212 |
NS_LOG_INFO ("Done."); |
987 | 213 |
} |