author | Craig Dowell <craigdo@ee.washington.edu> |
Thu, 03 Jul 2008 15:44:54 -0700 | |
changeset 3381 | 3cdd9d60f7c7 |
parent 3257 | ba198dad54a2 |
child 3630 | 0aa446f659d9 |
permissions | -rw-r--r-- |
1428
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
2 |
/* |
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
3 |
* This program is free software; you can redistribute it and/or modify |
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
4 |
* it under the terms of the GNU General Public License version 2 as |
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
5 |
* published by the Free Software Foundation; |
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
6 |
* |
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
7 |
* This program is distributed in the hope that it will be useful, |
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
10 |
* GNU General Public License for more details. |
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
11 |
* |
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
12 |
* You should have received a copy of the GNU General Public License |
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
13 |
* along with this program; if not, write to the Free Software |
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
15 |
*/ |
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
16 |
|
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
17 |
// Network topology |
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
18 |
// |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1432
diff
changeset
|
19 |
// Lan1 |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1432
diff
changeset
|
20 |
// =========== |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1432
diff
changeset
|
21 |
// | | | |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1432
diff
changeset
|
22 |
// n0 n1 n2 n3 n4 |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1432
diff
changeset
|
23 |
// | | | |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1432
diff
changeset
|
24 |
// =========== |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1432
diff
changeset
|
25 |
// Lan0 |
1428
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
26 |
// |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1432
diff
changeset
|
27 |
// - Multicast source is at node n0; |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1432
diff
changeset
|
28 |
// - Multicast forwarded by node n2 onto LAN1; |
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1432
diff
changeset
|
29 |
// - Nodes n0, n1, n2, n3, and n4 receive the multicast frame. |
2798
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
30 |
// - Node n4 listens for the data |
1428
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
31 |
|
2800
b3e87b8fa9d2
move csma-multicast to new tracing helpers
Tom Henderson <tomh@tomh.org>
parents:
2798
diff
changeset
|
32 |
#include <iostream> |
b3e87b8fa9d2
move csma-multicast to new tracing helpers
Tom Henderson <tomh@tomh.org>
parents:
2798
diff
changeset
|
33 |
#include <fstream> |
b3e87b8fa9d2
move csma-multicast to new tracing helpers
Tom Henderson <tomh@tomh.org>
parents:
2798
diff
changeset
|
34 |
|
2798
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
35 |
#include "ns3/core-module.h" |
2890
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2889
diff
changeset
|
36 |
#include "ns3/simulator-module.h" |
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2889
diff
changeset
|
37 |
#include "ns3/node-module.h" |
2798
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
38 |
#include "ns3/helper-module.h" |
1428
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
39 |
|
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
40 |
using namespace ns3; |
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
41 |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
42 |
NS_LOG_COMPONENT_DEFINE ("CsmaMulticastExample"); |
1429
31cb0668defd
debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents:
1428
diff
changeset
|
43 |
|
1428
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
44 |
int |
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
45 |
main (int argc, char *argv[]) |
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
46 |
{ |
2798
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
47 |
// |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
48 |
// Users may find it convenient to turn on explicit debugging |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
49 |
// for selected modules; the below lines suggest how to do this |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
50 |
// |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
51 |
// LogComponentEnable ("CsmaMulticastExample", LOG_LEVEL_INFO); |
1433
a6fb891b59fd
cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents:
1432
diff
changeset
|
52 |
|
2798
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
53 |
// |
2860
9105a5cf6535
use global seed in examples, new regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
2838
diff
changeset
|
54 |
// Make the random number generators generate reproducible results. |
9105a5cf6535
use global seed in examples, new regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
2838
diff
changeset
|
55 |
// |
9105a5cf6535
use global seed in examples, new regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
2838
diff
changeset
|
56 |
RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8); |
9105a5cf6535
use global seed in examples, new regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
2838
diff
changeset
|
57 |
|
9105a5cf6535
use global seed in examples, new regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
2838
diff
changeset
|
58 |
// |
2798
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
59 |
// Set up default values for the simulation. |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
60 |
// |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
61 |
// Select Ethernet II-style encapsulation (no LLC/Snap header) |
2965
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2890
diff
changeset
|
62 |
Config::SetDefault ("ns3::CsmaNetDevice::EncapsulationMode", StringValue ("IpArp")); |
2533
80cdc3eec057
do not use Queue::CreateDefault
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2502
diff
changeset
|
63 |
|
2798
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
64 |
// Allow the user to override any of the defaults at |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
65 |
// run-time, via command-line arguments |
2575
1aae382e65e2
rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2533
diff
changeset
|
66 |
CommandLine cmd; |
1aae382e65e2
rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2533
diff
changeset
|
67 |
cmd.Parse (argc, argv); |
1432
3aef7d7a71c2
more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents:
1430
diff
changeset
|
68 |
|
2798
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
69 |
NS_LOG_INFO ("Create nodes."); |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
70 |
NodeContainer c; |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
71 |
c.Create (5); |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
72 |
// We will later want two subcontainers of these nodes, for the two LANs |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
73 |
NodeContainer c0 = NodeContainer (c.Get (0), c.Get (1), c.Get (2)); |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
74 |
NodeContainer c1 = NodeContainer (c.Get (2), c.Get (3), c.Get (4)); |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
75 |
|
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
76 |
NS_LOG_INFO ("Build Topology."); |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
77 |
CsmaHelper csma; |
3381
3cdd9d60f7c7
bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents:
3257
diff
changeset
|
78 |
csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000))); |
3cdd9d60f7c7
bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents:
3257
diff
changeset
|
79 |
csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2))); |
2798
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
80 |
|
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
81 |
// We will use these NetDevice containers later, for IP addressing |
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2860
diff
changeset
|
82 |
NetDeviceContainer nd0 = csma.Install (c0); // First LAN |
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2860
diff
changeset
|
83 |
NetDeviceContainer nd1 = csma.Install (c1); // Second LAN |
1440
c77745b2731c
add ipv4 methods, remove source multicast route requirement, fix udp socket source address prob
Craig Dowell <craigdo@ee.washington.edu>
parents:
1437
diff
changeset
|
84 |
|
2798
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
85 |
NS_LOG_INFO ("Add IP Stack."); |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
86 |
InternetStackHelper internet; |
2902
9c2cfada5e72
make duplicate aggregations fail; avoid duplicate aggregations
Craig Dowell <craigdo@ee.washington.edu>
parents:
2890
diff
changeset
|
87 |
internet.Install (c); |
1429
31cb0668defd
debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents:
1428
diff
changeset
|
88 |
|
2798
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
89 |
NS_LOG_INFO ("Assign IP Addresses."); |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
90 |
Ipv4AddressHelper ipv4Addr; |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
91 |
ipv4Addr.SetBase ("10.1.1.0", "255.255.255.0"); |
2888
872dc8466352
Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2887
diff
changeset
|
92 |
ipv4Addr.Assign (nd0); |
2798
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
93 |
ipv4Addr.SetBase ("10.1.2.0", "255.255.255.0"); |
2888
872dc8466352
Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2887
diff
changeset
|
94 |
ipv4Addr.Assign (nd1); |
1436
9f9fe7919c89
Silliness for optimized version
Craig Dowell <craigdo@ee.washington.edu>
parents:
1435
diff
changeset
|
95 |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
96 |
NS_LOG_INFO ("Configure multicasting."); |
2798
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
97 |
// |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
98 |
// Now we can configure multicasting. As described above, the multicast |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
99 |
// source is at node zero, which we assigned the IP address of 10.1.1.1 |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
100 |
// earlier. We need to define a multicast group to send packets to. This |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
101 |
// can be any multicast address from 224.0.0.0 through 239.255.255.255 |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
102 |
// (avoiding the reserved routing protocol addresses). |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
103 |
// |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
104 |
|
1428
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
105 |
Ipv4Address multicastSource ("10.1.1.1"); |
1442
bb5cf98c0c64
real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents:
1440
diff
changeset
|
106 |
Ipv4Address multicastGroup ("225.1.2.4"); |
1428
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
107 |
|
2798
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
108 |
// Now, we will set up multicast routing. We need to do three things: |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
109 |
// 1) Configure a (static) multicast route on node n2 |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
110 |
// 2) Set up a default multicast route on the sender n0 |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
111 |
// 3) Have node n4 join the multicast group |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
112 |
// We have a helper that can help us with static multicast |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
113 |
StaticMulticastRouteHelper multicast; |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
114 |
|
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
115 |
// 1) Configure a (static) multicast route on node n2 (multicastRouter) |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
116 |
Ptr<Node> multicastRouter = c.Get (2); // The node in question |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
117 |
Ptr<NetDevice> inputIf = nd0.Get (2); // The input NetDevice |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
118 |
NetDeviceContainer outputDevices; // A container of output NetDevices |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
119 |
outputDevices.Add (nd1.Get (0)); // (we only need one NetDevice here) |
1428
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
120 |
|
2798
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
121 |
multicast.AddMulticastRoute (multicastRouter, multicastSource, |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
122 |
multicastGroup, inputIf, outputDevices); |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
123 |
|
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
124 |
// 2) Set up a default multicast route on the sender n0 |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
125 |
Ptr<Node> sender = c.Get (0); |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
126 |
Ptr<NetDevice> senderIf = nd0.Get(0); |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
127 |
multicast.SetDefaultMulticastRoute (sender, senderIf); |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
128 |
|
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
129 |
// 3) Have node n4 join the multicast group |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
130 |
Ptr<Node> receiver = c.Get (4); |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
131 |
multicast.JoinMulticastGroup (receiver, multicastSource, multicastGroup); |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
132 |
|
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
133 |
// |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
134 |
// Create an OnOff application to send UDP datagrams from node zero to the |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
135 |
// multicast group (node four will be listening). |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
136 |
// |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
137 |
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:
1509
diff
changeset
|
138 |
|
2798
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
139 |
uint16_t multicastPort = 9; // Discard port (RFC 863) |
1514
addb79f47ba5
change port number used by example scripts to 'discard' or 'echo' instead of '80'
Tom Henderson <tomh@tomh.org>
parents:
1509
diff
changeset
|
140 |
|
1515
e87ff7b66737
Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents:
1514
diff
changeset
|
141 |
// Configure a multicast packet generator that generates a packet |
e87ff7b66737
Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents:
1514
diff
changeset
|
142 |
// every few seconds |
3125
d2d8a36cfd23
s/ns3::Udp/ns3::UdpSocketFactory
Tom Henderson <tomh@tomh.org>
parents:
2997
diff
changeset
|
143 |
OnOffHelper onoff ("ns3::UdpSocketFactory", |
2890
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2889
diff
changeset
|
144 |
Address (InetSocketAddress (multicastGroup, multicastPort))); |
2965
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2890
diff
changeset
|
145 |
onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); |
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2890
diff
changeset
|
146 |
onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); |
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2890
diff
changeset
|
147 |
onoff.SetAttribute ("DataRate", DataRateValue (DataRate ("255b/s"))); |
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2890
diff
changeset
|
148 |
onoff.SetAttribute ("PacketSize", UintegerValue (128)); |
2798
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
149 |
|
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2860
diff
changeset
|
150 |
ApplicationContainer srcC = onoff.Install (c0.Get (0)); |
2798
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
151 |
|
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
152 |
// |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
153 |
// Tell the application when to start and stop. |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
154 |
// |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
155 |
srcC.Start(Seconds(1.)); |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
156 |
srcC.Stop (Seconds(10.)); |
1515
e87ff7b66737
Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents:
1514
diff
changeset
|
157 |
|
e87ff7b66737
Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents:
1514
diff
changeset
|
158 |
// Create an optional packet sink to receive these packets |
3125
d2d8a36cfd23
s/ns3::Udp/ns3::UdpSocketFactory
Tom Henderson <tomh@tomh.org>
parents:
2997
diff
changeset
|
159 |
PacketSinkHelper sink ("ns3::UdpSocketFactory", |
2965
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2890
diff
changeset
|
160 |
InetSocketAddress (Ipv4Address::GetAny(), multicastPort)); |
2890
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2889
diff
changeset
|
161 |
|
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2860
diff
changeset
|
162 |
ApplicationContainer sinkC = sink.Install (c1.Get (2)); // Node n4 |
1515
e87ff7b66737
Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents:
1514
diff
changeset
|
163 |
// Start the sink |
2798
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
164 |
sinkC.Start (Seconds (1.0)); |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
165 |
sinkC.Stop (Seconds (10.0)); |
1515
e87ff7b66737
Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents:
1514
diff
changeset
|
166 |
|
2798
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
167 |
// |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
168 |
// Configure tracing of all enqueue, dequeue, and NetDevice receive events. |
2800
b3e87b8fa9d2
move csma-multicast to new tracing helpers
Tom Henderson <tomh@tomh.org>
parents:
2798
diff
changeset
|
169 |
NS_LOG_INFO ("Configure Tracing."); |
b3e87b8fa9d2
move csma-multicast to new tracing helpers
Tom Henderson <tomh@tomh.org>
parents:
2798
diff
changeset
|
170 |
// |
b3e87b8fa9d2
move csma-multicast to new tracing helpers
Tom Henderson <tomh@tomh.org>
parents:
2798
diff
changeset
|
171 |
// Ascii trace output will be sent to the file "csma-multicast.tr" |
2798
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
172 |
// |
2800
b3e87b8fa9d2
move csma-multicast to new tracing helpers
Tom Henderson <tomh@tomh.org>
parents:
2798
diff
changeset
|
173 |
std::ofstream ascii; |
b3e87b8fa9d2
move csma-multicast to new tracing helpers
Tom Henderson <tomh@tomh.org>
parents:
2798
diff
changeset
|
174 |
ascii.open ("csma-multicast.tr"); |
2996
a83b94e277d4
EnablePcap()->EnablePcapAll(); EnableAscii()->EnableAsciiAll()
Tom Henderson <tomh@tomh.org>
parents:
2902
diff
changeset
|
175 |
CsmaHelper::EnableAsciiAll (ascii); |
2800
b3e87b8fa9d2
move csma-multicast to new tracing helpers
Tom Henderson <tomh@tomh.org>
parents:
2798
diff
changeset
|
176 |
|
2798
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
177 |
// Also configure some tcpdump traces; each interface will be traced. |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
178 |
// The output files will be named: |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
179 |
// csma-multicast.pcap-<nodeId>-<interfaceId> |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
180 |
// and can be read by the "tcpdump -r" command (use "-tt" option to |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
181 |
// display timestamps correctly) |
2996
a83b94e277d4
EnablePcap()->EnablePcapAll(); EnableAscii()->EnableAsciiAll()
Tom Henderson <tomh@tomh.org>
parents:
2902
diff
changeset
|
182 |
CsmaHelper::EnablePcapAll ("csma-multicast"); |
2798
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
183 |
// |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
184 |
// Now, do the actual simulation. |
143e2e1c5167
csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents:
2602
diff
changeset
|
185 |
// |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
186 |
NS_LOG_INFO ("Run Simulation."); |
1428
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
187 |
Simulator::Run (); |
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
188 |
Simulator::Destroy (); |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1501
diff
changeset
|
189 |
NS_LOG_INFO ("Done."); |
1428
a8f3d01d4a2c
untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
190 |
} |