author | John Abraham <john.abraham@gatech.edu> |
Wed, 17 Aug 2011 12:52:06 -0400 | |
changeset 7443 | 32635b529440 |
parent 7256 | b04ba6772f8c |
child 7476 | 2761997c72b2 |
permissions | -rw-r--r-- |
5776 | 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 |
||
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" |
6864 | 20 |
#include "ns3/netanim-module.h" |
6848
1f453ad50ef3
Converts csma, emu, tap-bridge, point-to-point, wifi and wimax modules into modular format
Lalith Suresh <suresh.lalith@gmail.com>
parents:
6847
diff
changeset
|
21 |
#include "ns3/internet-module.h" |
1f453ad50ef3
Converts csma, emu, tap-bridge, point-to-point, wifi and wimax modules into modular format
Lalith Suresh <suresh.lalith@gmail.com>
parents:
6847
diff
changeset
|
22 |
#include "ns3/point-to-point-module.h" |
6847
138f00c56381
Move applications to a single module
Mitch Watrous <watrous@u.washington.edu>
parents:
6845
diff
changeset
|
23 |
#include "ns3/applications-module.h" |
7089
ebe626d82692
Bug 1105 Move topology helpers into separate per-device modules
John Abraham<john.abraham@gatech.edu>
parents:
7081
diff
changeset
|
24 |
#include "ns3/point-to-point-layout-module.h" |
5776 | 25 |
|
26 |
// Network topology (default) |
|
27 |
// |
|
28 |
// n2 n3 n4 . |
|
29 |
// \ | / . |
|
30 |
// \|/ . |
|
31 |
// n1--- n0---n5 . |
|
32 |
// /|\ . |
|
33 |
// / | \ . |
|
34 |
// n8 n7 n6 . |
|
35 |
// |
|
36 |
||
37 |
||
38 |
using namespace ns3; |
|
39 |
||
40 |
NS_LOG_COMPONENT_DEFINE ("StarAnimation"); |
|
41 |
||
42 |
int |
|
43 |
main (int argc, char *argv[]) |
|
44 |
{ |
|
45 |
||
46 |
// |
|
47 |
// Set up some default values for the simulation. |
|
48 |
// |
|
49 |
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (137)); |
|
50 |
||
51 |
// ??? try and stick 15kb/s into the data rate |
|
52 |
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("14kb/s")); |
|
53 |
||
54 |
// |
|
55 |
// Default number of nodes in the star. Overridable by command line argument. |
|
56 |
// |
|
57 |
uint32_t nSpokes = 8; |
|
58 |
uint32_t animPort = 0; |
|
59 |
std::string animFile; |
|
60 |
||
61 |
CommandLine cmd; |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7181
diff
changeset
|
62 |
cmd.AddValue ("nSpokes", "Number of spoke nodes to place in the star", nSpokes); |
5776 | 63 |
cmd.AddValue ("animPort", "Port Number for Remote Animation", animPort); |
64 |
cmd.AddValue ("animFile", "File Name for Animation Output", animFile); |
|
65 |
||
66 |
cmd.Parse (argc, argv); |
|
67 |
||
68 |
NS_LOG_INFO ("Build star topology."); |
|
69 |
PointToPointHelper pointToPoint; |
|
70 |
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); |
|
71 |
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); |
|
72 |
PointToPointStarHelper star (nSpokes, pointToPoint); |
|
73 |
||
74 |
NS_LOG_INFO ("Install internet stack on all nodes."); |
|
75 |
InternetStackHelper internet; |
|
76 |
star.InstallStack (internet); |
|
77 |
||
78 |
NS_LOG_INFO ("Assign IP Addresses."); |
|
79 |
star.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0")); |
|
80 |
||
81 |
NS_LOG_INFO ("Create applications."); |
|
82 |
// |
|
7181
7ff8011cf487
net-anim coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
7089
diff
changeset
|
83 |
// Create a packet sink on the star "hub" to receive packets. |
5776 | 84 |
// |
85 |
uint16_t port = 50000; |
|
86 |
Address hubLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port)); |
|
87 |
PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", hubLocalAddress); |
|
88 |
ApplicationContainer hubApp = packetSinkHelper.Install (star.GetHub ()); |
|
89 |
hubApp.Start (Seconds (1.0)); |
|
90 |
hubApp.Stop (Seconds (10.0)); |
|
91 |
||
92 |
// |
|
93 |
// Create OnOff applications to send TCP to the hub, one on each spoke node. |
|
94 |
// |
|
95 |
OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ()); |
|
96 |
onOffHelper.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); |
|
97 |
onOffHelper.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); |
|
98 |
||
99 |
ApplicationContainer spokeApps; |
|
100 |
||
101 |
for (uint32_t i = 0; i < star.SpokeCount (); ++i) |
|
102 |
{ |
|
103 |
AddressValue remoteAddress (InetSocketAddress (star.GetHubIpv4Address (i), port)); |
|
104 |
onOffHelper.SetAttribute ("Remote", remoteAddress); |
|
5859
41cff0992d09
Added documentation for animation interface
Josh Pelkey <jpelkey@gatech.edu>
parents:
5776
diff
changeset
|
105 |
spokeApps.Add (onOffHelper.Install (star.GetSpokeNode (i))); |
7181
7ff8011cf487
net-anim coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
7089
diff
changeset
|
106 |
} |
5776 | 107 |
spokeApps.Start (Seconds (1.0)); |
108 |
spokeApps.Stop (Seconds (10.0)); |
|
109 |
||
110 |
NS_LOG_INFO ("Enable static global routing."); |
|
111 |
// |
|
112 |
// Turn on global static routing so we can actually be routed across the star. |
|
113 |
// |
|
114 |
Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
|
115 |
||
116 |
// Set the bounding box for animation |
|
7081
9e2c7d8d842f
Bug 1106: Remove CanvasLocation dependencies
John Abraham <john.abraham@gatech.edu>
parents:
6864
diff
changeset
|
117 |
star.BoundingBox (1, 1, 100, 100); |
7181
7ff8011cf487
net-anim coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
7089
diff
changeset
|
118 |
|
5776 | 119 |
// Create the animation object and configure for specified output |
120 |
AnimationInterface anim; |
|
121 |
if (animPort > 0) |
|
122 |
{ |
|
123 |
anim.SetServerPort (animPort); |
|
124 |
} |
|
125 |
else if (!animFile.empty ()) |
|
126 |
{ |
|
127 |
anim.SetOutputFile (animFile); |
|
128 |
} |
|
7443
32635b529440
NetAnim minor comments
John Abraham <john.abraham@gatech.edu>
parents:
7256
diff
changeset
|
129 |
// Uncomment the below statement to generate Animation trace in XML |
32635b529440
NetAnim minor comments
John Abraham <john.abraham@gatech.edu>
parents:
7256
diff
changeset
|
130 |
// anim.SetXMLOutput (); |
5776 | 131 |
anim.StartAnimation (); |
132 |
||
133 |
NS_LOG_INFO ("Run Simulation."); |
|
134 |
Simulator::Run (); |
|
135 |
Simulator::Destroy (); |
|
136 |
NS_LOG_INFO ("Done."); |
|
137 |
||
138 |
return 0; |
|
139 |
} |