author | Tom Henderson <tomh@tomh.org> |
Sat, 16 Jan 2010 14:05:19 -0800 | |
changeset 5914 | 72726df9dcaa |
parent 5859 | 41cff0992d09 |
child 6649 | f5413d463948 |
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" |
|
19 |
#include "ns3/simulator-module.h" |
|
20 |
#include "ns3/node-module.h" |
|
21 |
#include "ns3/helper-module.h" |
|
22 |
||
23 |
// Network topology (default) |
|
24 |
// |
|
25 |
// n2 n3 n4 . |
|
26 |
// \ | / . |
|
27 |
// \|/ . |
|
28 |
// n1--- n0---n5 . |
|
29 |
// /|\ . |
|
30 |
// / | \ . |
|
31 |
// n8 n7 n6 . |
|
32 |
// |
|
33 |
||
34 |
||
35 |
using namespace ns3; |
|
36 |
||
37 |
NS_LOG_COMPONENT_DEFINE ("StarAnimation"); |
|
38 |
||
39 |
int |
|
40 |
main (int argc, char *argv[]) |
|
41 |
{ |
|
42 |
||
43 |
// |
|
44 |
// Set up some default values for the simulation. |
|
45 |
// |
|
46 |
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (137)); |
|
47 |
||
48 |
// ??? try and stick 15kb/s into the data rate |
|
49 |
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("14kb/s")); |
|
50 |
||
51 |
// |
|
52 |
// Default number of nodes in the star. Overridable by command line argument. |
|
53 |
// |
|
54 |
uint32_t nSpokes = 8; |
|
55 |
uint32_t animPort = 0; |
|
56 |
std::string animFile; |
|
57 |
||
58 |
CommandLine cmd; |
|
59 |
cmd.AddValue("nSpokes", "Number of spoke nodes to place in the star", nSpokes); |
|
60 |
cmd.AddValue ("animPort", "Port Number for Remote Animation", animPort); |
|
61 |
cmd.AddValue ("animFile", "File Name for Animation Output", animFile); |
|
62 |
||
63 |
cmd.Parse (argc, argv); |
|
64 |
||
65 |
NS_LOG_INFO ("Build star topology."); |
|
66 |
PointToPointHelper pointToPoint; |
|
67 |
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); |
|
68 |
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); |
|
69 |
PointToPointStarHelper star (nSpokes, pointToPoint); |
|
70 |
||
71 |
NS_LOG_INFO ("Install internet stack on all nodes."); |
|
72 |
InternetStackHelper internet; |
|
73 |
star.InstallStack (internet); |
|
74 |
||
75 |
NS_LOG_INFO ("Assign IP Addresses."); |
|
76 |
star.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0")); |
|
77 |
||
78 |
NS_LOG_INFO ("Create applications."); |
|
79 |
// |
|
80 |
// Create a packet sink on the star "hub" to receive packets. |
|
81 |
// |
|
82 |
uint16_t port = 50000; |
|
83 |
Address hubLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port)); |
|
84 |
PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", hubLocalAddress); |
|
85 |
ApplicationContainer hubApp = packetSinkHelper.Install (star.GetHub ()); |
|
86 |
hubApp.Start (Seconds (1.0)); |
|
87 |
hubApp.Stop (Seconds (10.0)); |
|
88 |
||
89 |
// |
|
90 |
// Create OnOff applications to send TCP to the hub, one on each spoke node. |
|
91 |
// |
|
92 |
OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ()); |
|
93 |
onOffHelper.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); |
|
94 |
onOffHelper.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); |
|
95 |
||
96 |
ApplicationContainer spokeApps; |
|
97 |
||
98 |
for (uint32_t i = 0; i < star.SpokeCount (); ++i) |
|
99 |
{ |
|
100 |
AddressValue remoteAddress (InetSocketAddress (star.GetHubIpv4Address (i), port)); |
|
101 |
onOffHelper.SetAttribute ("Remote", remoteAddress); |
|
5859
41cff0992d09
Added documentation for animation interface
Josh Pelkey <jpelkey@gatech.edu>
parents:
5776
diff
changeset
|
102 |
spokeApps.Add (onOffHelper.Install (star.GetSpokeNode (i))); |
5776 | 103 |
} |
104 |
spokeApps.Start (Seconds (1.0)); |
|
105 |
spokeApps.Stop (Seconds (10.0)); |
|
106 |
||
107 |
NS_LOG_INFO ("Enable static global routing."); |
|
108 |
// |
|
109 |
// Turn on global static routing so we can actually be routed across the star. |
|
110 |
// |
|
111 |
Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
|
112 |
||
113 |
// Set the bounding box for animation |
|
114 |
star.BoundingBox (1, 1, 10, 10); |
|
115 |
||
116 |
// Create the animation object and configure for specified output |
|
117 |
AnimationInterface anim; |
|
118 |
if (animPort > 0) |
|
119 |
{ |
|
120 |
anim.SetServerPort (animPort); |
|
121 |
} |
|
122 |
else if (!animFile.empty ()) |
|
123 |
{ |
|
124 |
anim.SetOutputFile (animFile); |
|
125 |
} |
|
126 |
anim.StartAnimation (); |
|
127 |
||
128 |
NS_LOG_INFO ("Run Simulation."); |
|
129 |
Simulator::Run (); |
|
130 |
Simulator::Destroy (); |
|
131 |
NS_LOG_INFO ("Done."); |
|
132 |
||
133 |
return 0; |
|
134 |
} |