author | Mitch Watrous <watrous@u.washington.edu> |
Wed, 02 Mar 2011 13:42:28 -0800 | |
changeset 6847 | 138f00c56381 |
parent 6845 | 7dc660ca04ff |
permissions | -rw-r--r-- |
3795
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
2 |
/* |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
3 |
* This program is free software; you can redistribute it and/or modify |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
4 |
* it under the terms of the GNU General Public License version 2 as |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
5 |
* published by the Free Software Foundation; |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
6 |
* |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
7 |
* This program is distributed in the hope that it will be useful, |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
10 |
* GNU General Public License for more details. |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
11 |
* |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
12 |
* You should have received a copy of the GNU General Public License |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
13 |
* along with this program; if not, write to the Free Software |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
15 |
* |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
16 |
*/ |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
17 |
|
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
18 |
#include "ns3/core-module.h" |
6823
a27f86fb4e55
Merge node and common modules into new network module
Tom Henderson <tomh@tomh.org>
parents:
6821
diff
changeset
|
19 |
#include "ns3/network-module.h" |
3795
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
20 |
#include "ns3/helper-module.h" |
6847
138f00c56381
Move applications to a single module
Mitch Watrous <watrous@u.washington.edu>
parents:
6845
diff
changeset
|
21 |
#include "ns3/applications-module.h" |
4210
da9be6abb1b2
bug 486: patches for icc compilation.
Timo Bingmann <timo.bingmann@student.kit.edu>
parents:
3858
diff
changeset
|
22 |
#include "ns3/csma-module.h" |
6649
f5413d463948
Missing ipv4-global-routing-helper.h include
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6009
diff
changeset
|
23 |
#include "ns3/ipv4-global-routing-helper.h" |
3795
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
24 |
|
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
25 |
// Network topology (default) |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
26 |
// |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
27 |
// n2 + + n3 . |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
28 |
// | ... |\ /| ... | . |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
29 |
// ======= \ / ======= . |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
30 |
// CSMA \ / CSMA . |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
31 |
// \ / . |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
32 |
// n1 +--- n0 ---+ n4 . |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
33 |
// | ... | / \ | ... | . |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
34 |
// ======= / \ ======= . |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
35 |
// CSMA / \ CSMA . |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
36 |
// / \ . |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
37 |
// n6 + + n5 . |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
38 |
// | ... | | ... | . |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
39 |
// ======= ======= . |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
40 |
// CSMA CSMA . |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
41 |
// |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
42 |
|
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
43 |
using namespace ns3; |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
44 |
|
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
45 |
NS_LOG_COMPONENT_DEFINE ("CsmaStar"); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
46 |
|
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
47 |
int |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
48 |
main (int argc, char *argv[]) |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
49 |
{ |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
50 |
|
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
51 |
// |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
52 |
// Set up some default values for the simulation. |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
53 |
// |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
54 |
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (137)); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
55 |
|
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
56 |
// ??? try and stick 15kb/s into the data rate |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
57 |
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("14kb/s")); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
58 |
|
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
59 |
// |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
60 |
// Default number of nodes in the star. Overridable by command line argument. |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
61 |
// |
5776
aae948449722
Moved net-anim from contrib
Josh Pelkey <jpelkey@gatech.edu>
parents:
5369
diff
changeset
|
62 |
uint32_t nSpokes = 7; |
3795
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
63 |
|
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
64 |
CommandLine cmd; |
5776
aae948449722
Moved net-anim from contrib
Josh Pelkey <jpelkey@gatech.edu>
parents:
5369
diff
changeset
|
65 |
cmd.AddValue("nSpokes", "Number of spoke nodes to place in the star", nSpokes); |
3795
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
66 |
cmd.Parse (argc, argv); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
67 |
|
5776
aae948449722
Moved net-anim from contrib
Josh Pelkey <jpelkey@gatech.edu>
parents:
5369
diff
changeset
|
68 |
NS_LOG_INFO ("Build star topology."); |
3795
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
69 |
CsmaHelper csma; |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
70 |
csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps")); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
71 |
csma.SetChannelAttribute ("Delay", StringValue ("1ms")); |
5776
aae948449722
Moved net-anim from contrib
Josh Pelkey <jpelkey@gatech.edu>
parents:
5369
diff
changeset
|
72 |
CsmaStarHelper star (nSpokes, csma); |
3795
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
73 |
|
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
74 |
NodeContainer fillNodes; |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
75 |
|
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
76 |
// |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
77 |
// Just to be nasy, hang some more nodes off of the CSMA channel for each |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
78 |
// spoke, so that there are a total of 16 nodes on each channel. Stash |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
79 |
// all of these new devices into a container. |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
80 |
// |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
81 |
NetDeviceContainer fillDevices; |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
82 |
|
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
83 |
uint32_t nFill = 14; |
5776
aae948449722
Moved net-anim from contrib
Josh Pelkey <jpelkey@gatech.edu>
parents:
5369
diff
changeset
|
84 |
for (uint32_t i = 0; i < star.GetSpokeDevices ().GetN (); ++i) |
3795
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
85 |
{ |
5776
aae948449722
Moved net-anim from contrib
Josh Pelkey <jpelkey@gatech.edu>
parents:
5369
diff
changeset
|
86 |
Ptr<Channel> channel = star.GetSpokeDevices ().Get (i)->GetChannel (); |
3795
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
87 |
Ptr<CsmaChannel> csmaChannel = channel->GetObject<CsmaChannel> (); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
88 |
NodeContainer newNodes; |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
89 |
newNodes.Create (nFill); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
90 |
fillNodes.Add (newNodes); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
91 |
fillDevices.Add (csma.Install (newNodes, csmaChannel)); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
92 |
} |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
93 |
|
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
94 |
NS_LOG_INFO ("Install internet stack on all nodes."); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
95 |
InternetStackHelper internet; |
5776
aae948449722
Moved net-anim from contrib
Josh Pelkey <jpelkey@gatech.edu>
parents:
5369
diff
changeset
|
96 |
star.InstallStack (internet); |
aae948449722
Moved net-anim from contrib
Josh Pelkey <jpelkey@gatech.edu>
parents:
5369
diff
changeset
|
97 |
internet.Install (fillNodes); |
3795
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
98 |
|
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
99 |
NS_LOG_INFO ("Assign IP Addresses."); |
5776
aae948449722
Moved net-anim from contrib
Josh Pelkey <jpelkey@gatech.edu>
parents:
5369
diff
changeset
|
100 |
star.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.0.0", "255.255.255.0")); |
3795
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
101 |
|
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
102 |
// |
5776
aae948449722
Moved net-anim from contrib
Josh Pelkey <jpelkey@gatech.edu>
parents:
5369
diff
changeset
|
103 |
// We assigned addresses to the logical hub and the first "drop" of the |
aae948449722
Moved net-anim from contrib
Josh Pelkey <jpelkey@gatech.edu>
parents:
5369
diff
changeset
|
104 |
// CSMA network that acts as the spoke, but we also have a number of fill |
aae948449722
Moved net-anim from contrib
Josh Pelkey <jpelkey@gatech.edu>
parents:
5369
diff
changeset
|
105 |
// devices (nFill) also hanging off the CSMA network. We have got to |
aae948449722
Moved net-anim from contrib
Josh Pelkey <jpelkey@gatech.edu>
parents:
5369
diff
changeset
|
106 |
// assign addresses to them as well. We put all of the fill devices into |
aae948449722
Moved net-anim from contrib
Josh Pelkey <jpelkey@gatech.edu>
parents:
5369
diff
changeset
|
107 |
// a single device container, so the first nFill devices are associated |
aae948449722
Moved net-anim from contrib
Josh Pelkey <jpelkey@gatech.edu>
parents:
5369
diff
changeset
|
108 |
// with the channel connected to spokeDevices.Get (0), the second nFill |
aae948449722
Moved net-anim from contrib
Josh Pelkey <jpelkey@gatech.edu>
parents:
5369
diff
changeset
|
109 |
// devices afe associated with the channel connected to spokeDevices.Get (1) |
aae948449722
Moved net-anim from contrib
Josh Pelkey <jpelkey@gatech.edu>
parents:
5369
diff
changeset
|
110 |
// etc. |
3795
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
111 |
// |
5776
aae948449722
Moved net-anim from contrib
Josh Pelkey <jpelkey@gatech.edu>
parents:
5369
diff
changeset
|
112 |
Ipv4AddressHelper address; |
aae948449722
Moved net-anim from contrib
Josh Pelkey <jpelkey@gatech.edu>
parents:
5369
diff
changeset
|
113 |
for(uint32_t i = 0; i < star.SpokeCount (); ++i) |
3795
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
114 |
{ |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
115 |
std::ostringstream subnet; |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
116 |
subnet << "10.1." << i << ".0"; |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
117 |
NS_LOG_INFO ("Assign IP Addresses for CSMA subnet " << subnet.str ()); |
5776
aae948449722
Moved net-anim from contrib
Josh Pelkey <jpelkey@gatech.edu>
parents:
5369
diff
changeset
|
118 |
address.SetBase (subnet.str ().c_str (), "255.255.255.0", "0.0.0.3"); |
aae948449722
Moved net-anim from contrib
Josh Pelkey <jpelkey@gatech.edu>
parents:
5369
diff
changeset
|
119 |
|
3858 | 120 |
for (uint32_t j = 0; j < nFill; ++j) |
121 |
{ |
|
122 |
address.Assign (fillDevices.Get (i * nFill + j)); |
|
123 |
} |
|
3795
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
124 |
} |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
125 |
|
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
126 |
NS_LOG_INFO ("Create applications."); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
127 |
// |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
128 |
// Create a packet sink on the star "hub" to receive packets. |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
129 |
// |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
130 |
uint16_t port = 50000; |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
131 |
Address hubLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port)); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
132 |
PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", hubLocalAddress); |
5776
aae948449722
Moved net-anim from contrib
Josh Pelkey <jpelkey@gatech.edu>
parents:
5369
diff
changeset
|
133 |
ApplicationContainer hubApp = packetSinkHelper.Install (star.GetHub ()); |
3795
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
134 |
hubApp.Start (Seconds (1.0)); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
135 |
hubApp.Stop (Seconds (10.0)); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
136 |
|
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
137 |
// |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
138 |
// Create OnOff applications to send TCP to the hub, one on each spoke node. |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
139 |
// |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
140 |
OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ()); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
141 |
onOffHelper.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
142 |
onOffHelper.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
143 |
|
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
144 |
ApplicationContainer spokeApps; |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
145 |
|
5776
aae948449722
Moved net-anim from contrib
Josh Pelkey <jpelkey@gatech.edu>
parents:
5369
diff
changeset
|
146 |
for (uint32_t i = 0; i < star.SpokeCount (); ++i) |
3795
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
147 |
{ |
5776
aae948449722
Moved net-anim from contrib
Josh Pelkey <jpelkey@gatech.edu>
parents:
5369
diff
changeset
|
148 |
AddressValue remoteAddress (InetSocketAddress (star.GetHubIpv4Address (i), port)); |
3795
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
149 |
onOffHelper.SetAttribute ("Remote", remoteAddress); |
5859
41cff0992d09
Added documentation for animation interface
Josh Pelkey <jpelkey@gatech.edu>
parents:
5776
diff
changeset
|
150 |
spokeApps.Add (onOffHelper.Install (star.GetSpokeNode (i))); |
3795
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
151 |
} |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
152 |
|
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
153 |
spokeApps.Start (Seconds (1.0)); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
154 |
spokeApps.Stop (Seconds (10.0)); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
155 |
|
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
156 |
// |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
157 |
// Because we are evil, we also add OnOff applications to send TCP to the hub |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
158 |
// from the fill devices on each CSMA link. The first nFill nodes in the |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
159 |
// fillNodes container are on the CSMA network talking to the zeroth device |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
160 |
// on the hub node. The next nFill nodes are on the CSMA network talking to |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
161 |
// the first device on the hub node, etc. So the ith fillNode is associated |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
162 |
// with the hub address found on the (i / nFill)th device on the hub node. |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
163 |
// |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
164 |
ApplicationContainer fillApps; |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
165 |
|
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
166 |
for (uint32_t i = 0; i < fillNodes.GetN (); ++i) |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
167 |
{ |
5776
aae948449722
Moved net-anim from contrib
Josh Pelkey <jpelkey@gatech.edu>
parents:
5369
diff
changeset
|
168 |
AddressValue remoteAddress (InetSocketAddress (star.GetHubIpv4Address (i / nFill), port)); |
3795
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
169 |
onOffHelper.SetAttribute ("Remote", remoteAddress); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
170 |
fillApps.Add (onOffHelper.Install (fillNodes.Get (i))); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
171 |
} |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
172 |
|
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
173 |
fillApps.Start (Seconds (1.0)); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
174 |
fillApps.Stop (Seconds (10.0)); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
175 |
|
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
176 |
NS_LOG_INFO ("Enable static global routing."); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
177 |
// |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
178 |
// Turn on global static routing so we can actually be routed across the star. |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
179 |
// |
4616
a84f60b6cd12
bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4264
diff
changeset
|
180 |
Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
3795
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
181 |
|
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
182 |
NS_LOG_INFO ("Enable pcap tracing."); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
183 |
// |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
184 |
// Do pcap tracing on all devices on all nodes. |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
185 |
// |
6009
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
5859
diff
changeset
|
186 |
csma.EnablePcapAll ("csma-star", false); |
3795
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
187 |
|
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
188 |
NS_LOG_INFO ("Run Simulation."); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
189 |
Simulator::Run (); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
190 |
Simulator::Destroy (); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
191 |
NS_LOG_INFO ("Done."); |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
192 |
|
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
193 |
return 0; |
707acdf0f8b3
csma version of install star and example
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
194 |
} |