Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(433)

Side by Side Diff: examples/animation/test-grid-animation.cc

Issue 117051: Ns-3 Net-anim Interface (Closed)
Patch Set: MinGW ifdefs Created 14 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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"
25
26 using namespace ns3;
27
28 int main (int argc, char *argv[])
29 {
30 Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (512));
31 Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("500kb/s") );
32
33 uint32_t xSize = 5;
34 uint32_t ySize = 5;
35 uint16_t port = 0;
36 std::string animFile;
37
38 CommandLine cmd;
39 cmd.AddValue ("xSize", "Number of rows of nodes", xSize);
40 cmd.AddValue ("ySize", "Number of columns of nodes", ySize);
41 cmd.AddValue ("port", "Port Number for Remote Animation", port);
42 cmd.AddValue ("animFile", "File Name for Animation Output", animFile);
43
44 cmd.Parse (argc,argv);
45 if (xSize < 1)
46 NS_FATAL_ERROR ("Need more nodes for grid.");
47 if (ySize < 1)
48 NS_FATAL_ERROR ("Need more nodes for grid.");
49 if (xSize < 2 && ySize < 2)
faker.moatamri 2009/11/09 14:22:13 you can gather those 3 ifs into one with a multipl
Josh Pelkey 2009/11/13 16:59:45 Done.
50 NS_FATAL_ERROR ("Need more nodes for grid.");
51 ··
52 PointToPointHelper pointToPoint;
53 pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
54 pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
55
56 // Create Grid
57 PointToPointGridHelper grid (xSize, ySize, pointToPoint);
58
59 // Install stack on Grid
60 InternetStackHelper stack;
61 grid.InstallStack (stack);
62
63 // Assign Addresses to Grid
64 grid.AssignIpv4Addresses (Ipv4AddressHelper("10.1.1.0", "255.255.255.0"),
65 Ipv4AddressHelper("10.2.1.0", "255.255.255.0"));
66
67
68 OnOffHelper clientHelper ("ns3::UdpSocketFactory", Address ());
69 clientHelper.SetAttribute·
70 ("OnTime", RandomVariableValue (ConstantVariable (1)));
71 clientHelper.SetAttribute·
72 ("OffTime", RandomVariableValue (ConstantVariable (0)));
73 ApplicationContainer clientApps;
74
75 // Create an on/off app sending packets
76 AddressValue remoteAddress(InetSocketAddress(grid.GetIpv4Address (xSize-1,ySiz e-1), 1000));
77 clientHelper.SetAttribute("Remote", remoteAddress);
78 clientApps.Add(clientHelper.Install(grid.GetNode (0,0)));
79
80 clientApps.Start (Seconds (0.0));
81 clientApps.Stop (Seconds (1.5));
82
83 // Set the bounding box for animation
84 grid.BoundingBox(1, 1, 10, 10);
85
86 // Create the animation object and configure for specified output
87 AnimationInterface anim;
88 if (port > 0)
89 {
90 anim.SetServerPort(port);
91 }
92 else if (!animFile.empty())
93 {
94 anim.SetOutputFile(animFile);
95 }
96 anim.StartAnimation();
97 ··
98 // Set up the actual simulation
99 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
100
101 std::cout << "Running the simulation" << std::endl;
102 Simulator::Run ();
103 std::cout << "Destroying the simulation" << std::endl;
104 Simulator::Destroy ();
105 std::cout << "Stopping the animation" << std::endl;
106 anim.StopAnimation();
107 return 0;
108 }
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b