author | Mitch Watrous <watrous@u.washington.edu> |
Wed, 02 Mar 2011 13:42:28 -0800 | |
changeset 6847 | 138f00c56381 |
parent 6845 | 7dc660ca04ff |
child 6848 | 1f453ad50ef3 |
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 |
* Author: George F. Riley<riley@ece.gatech.edu> |
|
17 |
*/ |
|
18 |
||
19 |
#include <iostream> |
|
20 |
||
21 |
#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
|
22 |
#include "ns3/network-module.h" |
5776 | 23 |
#include "ns3/helper-module.h" |
6847
138f00c56381
Move applications to a single module
Mitch Watrous <watrous@u.washington.edu>
parents:
6845
diff
changeset
|
24 |
#include "ns3/applications-module.h" |
6649
f5413d463948
Missing ipv4-global-routing-helper.h include
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5776
diff
changeset
|
25 |
#include "ns3/ipv4-global-routing-helper.h" |
5776 | 26 |
|
27 |
using namespace ns3; |
|
28 |
||
29 |
int main (int argc, char *argv[]) |
|
30 |
{ |
|
31 |
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (512)); |
|
32 |
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("500kb/s")); |
|
33 |
||
34 |
uint32_t nLeftLeaf = 5; |
|
35 |
uint32_t nRightLeaf = 5; |
|
36 |
uint32_t nLeaf = 0; // If non-zero, number of both left and right |
|
37 |
uint16_t port = 0; // If non zero, port to bind to for anim connection |
|
38 |
std::string animFile; // Name of file for animation output |
|
39 |
||
40 |
CommandLine cmd; |
|
41 |
cmd.AddValue ("nLeftLeaf", "Number of left side leaf nodes", nLeftLeaf); |
|
42 |
cmd.AddValue ("nRightLeaf","Number of right side leaf nodes", nRightLeaf); |
|
43 |
cmd.AddValue ("nLeaf", "Number of left and right side leaf nodes", nLeaf); |
|
44 |
cmd.AddValue ("port", "Port Number for Remote Animation", port); |
|
45 |
cmd.AddValue ("animFile", "File Name for Animation Output", animFile); |
|
46 |
||
47 |
cmd.Parse (argc,argv); |
|
48 |
if (nLeaf > 0) |
|
49 |
{ |
|
50 |
nLeftLeaf = nLeaf; |
|
51 |
nRightLeaf = nLeaf; |
|
52 |
} |
|
53 |
||
54 |
// Create the point-to-point link helpers |
|
55 |
PointToPointHelper pointToPointRouter; |
|
56 |
pointToPointRouter.SetDeviceAttribute ("DataRate", StringValue ("10Mbps")); |
|
57 |
pointToPointRouter.SetChannelAttribute ("Delay", StringValue ("1ms")); |
|
58 |
PointToPointHelper pointToPointLeaf; |
|
59 |
pointToPointLeaf.SetDeviceAttribute ("DataRate", StringValue ("10Mbps")); |
|
60 |
pointToPointLeaf.SetChannelAttribute ("Delay", StringValue ("1ms")); |
|
61 |
||
62 |
PointToPointDumbbellHelper d(nLeftLeaf, pointToPointLeaf, |
|
63 |
nRightLeaf, pointToPointLeaf, |
|
64 |
pointToPointRouter); |
|
65 |
||
66 |
// Install Stack |
|
67 |
InternetStackHelper stack; |
|
68 |
d.InstallStack (stack); |
|
69 |
||
70 |
// Assign IP Addresses |
|
71 |
d.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"), |
|
72 |
Ipv4AddressHelper ("10.2.1.0", "255.255.255.0"), |
|
73 |
Ipv4AddressHelper ("10.3.1.0", "255.255.255.0")); |
|
74 |
||
75 |
// Install on/off app on all right side nodes |
|
76 |
OnOffHelper clientHelper ("ns3::UdpSocketFactory", Address ()); |
|
77 |
clientHelper.SetAttribute |
|
78 |
("OnTime", RandomVariableValue (UniformVariable (0, 1))); |
|
79 |
clientHelper.SetAttribute |
|
80 |
("OffTime", RandomVariableValue (UniformVariable (0, 1))); |
|
81 |
ApplicationContainer clientApps; |
|
82 |
||
83 |
for (uint32_t i = 0; i < d.RightCount (); ++i) |
|
84 |
{ |
|
85 |
// Create an on/off app sending packets to the same leaf right side |
|
86 |
AddressValue remoteAddress (InetSocketAddress (d.GetLeftIpv4Address (i), 1000)); |
|
87 |
clientHelper.SetAttribute ("Remote", remoteAddress); |
|
88 |
clientApps.Add(clientHelper.Install (d.GetRight (i))); |
|
89 |
} |
|
90 |
||
91 |
clientApps.Start (Seconds (0.0)); |
|
92 |
clientApps.Stop (Seconds (10.0)); |
|
93 |
||
94 |
// Set the bounding box for animation |
|
95 |
d.BoundingBox (1, 1, 10, 10); |
|
96 |
||
97 |
// Create the animation object and configure for specified output |
|
98 |
AnimationInterface anim; |
|
99 |
if (port > 0) |
|
100 |
{ |
|
101 |
anim.SetServerPort (port); |
|
102 |
} |
|
103 |
else if (!animFile.empty ()) |
|
104 |
{ |
|
105 |
anim.SetOutputFile (animFile); |
|
106 |
} |
|
107 |
anim.StartAnimation (); |
|
108 |
||
109 |
// Set up the acutal simulation |
|
110 |
Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
|
111 |
||
112 |
std::cout << "Running the simulation" << std::endl; |
|
113 |
Simulator::Run (); |
|
114 |
std::cout << "Destroying the simulation" << std::endl; |
|
115 |
Simulator::Destroy (); |
|
116 |
std::cout << "Stopping the animation" << std::endl; |
|
117 |
anim.StopAnimation(); |
|
118 |
return 0; |
|
119 |
} |