author | Gustavo J. A. M. Carneiro <gjc@inescporto.pt> |
Wed, 27 Oct 2010 12:05:40 +0100 | |
changeset 6649 | f5413d463948 |
parent 5776 | aae948449722 |
child 6821 | 203367ae7433 |
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: Josh Pelkey <jpelkey@gatech.edu> |
|
17 |
*/ |
|
18 |
||
19 |
#include <iostream> |
|
20 |
||
21 |
#include "ns3/core-module.h" |
|
22 |
#include "ns3/simulator-module.h" |
|
23 |
#include "ns3/node-module.h" |
|
24 |
#include "ns3/helper-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 xSize = 5; |
|
35 |
uint32_t ySize = 5; |
|
36 |
uint16_t port = 0; |
|
37 |
std::string animFile; |
|
38 |
||
39 |
CommandLine cmd; |
|
40 |
cmd.AddValue ("xSize", "Number of rows of nodes", xSize); |
|
41 |
cmd.AddValue ("ySize", "Number of columns of nodes", ySize); |
|
42 |
cmd.AddValue ("port", "Port Number for Remote Animation", port); |
|
43 |
cmd.AddValue ("animFile", "File Name for Animation Output", animFile); |
|
44 |
||
45 |
cmd.Parse (argc,argv); |
|
46 |
if (xSize < 1 || ySize < 1 || (xSize < 2 && ySize < 2)) |
|
47 |
{ |
|
48 |
NS_FATAL_ERROR ("Need more nodes for grid."); |
|
49 |
} |
|
50 |
||
51 |
PointToPointHelper pointToPoint; |
|
52 |
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); |
|
53 |
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); |
|
54 |
||
55 |
// Create Grid |
|
56 |
PointToPointGridHelper grid (xSize, ySize, pointToPoint); |
|
57 |
||
58 |
// Install stack on Grid |
|
59 |
InternetStackHelper stack; |
|
60 |
grid.InstallStack (stack); |
|
61 |
||
62 |
// Assign Addresses to Grid |
|
63 |
grid.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"), |
|
64 |
Ipv4AddressHelper ("10.2.1.0", "255.255.255.0")); |
|
65 |
||
66 |
||
67 |
OnOffHelper clientHelper ("ns3::UdpSocketFactory", Address ()); |
|
68 |
clientHelper.SetAttribute |
|
69 |
("OnTime", RandomVariableValue (ConstantVariable (1))); |
|
70 |
clientHelper.SetAttribute |
|
71 |
("OffTime", RandomVariableValue (ConstantVariable (0))); |
|
72 |
ApplicationContainer clientApps; |
|
73 |
||
74 |
// Create an on/off app sending packets |
|
75 |
AddressValue remoteAddress (InetSocketAddress (grid.GetIpv4Address (xSize-1,ySize-1), 1000)); |
|
76 |
clientHelper.SetAttribute ("Remote", remoteAddress); |
|
77 |
clientApps.Add (clientHelper.Install (grid.GetNode (0,0))); |
|
78 |
||
79 |
clientApps.Start (Seconds (0.0)); |
|
80 |
clientApps.Stop (Seconds (1.5)); |
|
81 |
||
82 |
// Set the bounding box for animation |
|
83 |
grid.BoundingBox (1, 1, 10, 10); |
|
84 |
||
85 |
// Create the animation object and configure for specified output |
|
86 |
AnimationInterface anim; |
|
87 |
if (port > 0) |
|
88 |
{ |
|
89 |
anim.SetServerPort (port); |
|
90 |
} |
|
91 |
else if (!animFile.empty ()) |
|
92 |
{ |
|
93 |
anim.SetOutputFile (animFile); |
|
94 |
} |
|
95 |
anim.StartAnimation (); |
|
96 |
||
97 |
// Set up the actual simulation |
|
98 |
Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
|
99 |
||
100 |
std::cout << "Running the simulation" << std::endl; |
|
101 |
Simulator::Run (); |
|
102 |
std::cout << "Destroying the simulation" << std::endl; |
|
103 |
Simulator::Destroy (); |
|
104 |
std::cout << "Stopping the animation" << std::endl; |
|
105 |
anim.StopAnimation(); |
|
106 |
return 0; |
|
107 |
} |