OLD | NEW |
(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: George F. Riley<riley@ece.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 nLeftLeaf = 5; |
| 34 uint32_t nRightLeaf = 5; |
| 35 uint32_t nLeaf = 0; // If non-zero, number of both left and right |
| 36 uint16_t port = 0; // If non zero, port to bind to for anim connection |
| 37 std::string animFile; // Name of file for animation output |
| 38 |
| 39 CommandLine cmd; |
| 40 cmd.AddValue ("nLeftLeaf", "Number of left side leaf nodes", nLeftLeaf); |
| 41 cmd.AddValue ("nRightLeaf","Number of right side leaf nodes", nRightLeaf); |
| 42 cmd.AddValue ("nLeaf", "Number of left and right side leaf nodes", nLeaf); |
| 43 cmd.AddValue ("port", "Port Number for Remote Animation", port); |
| 44 cmd.AddValue ("animFile", "File Name for Animation Output", animFile); |
| 45 |
| 46 cmd.Parse (argc,argv); |
| 47 if (nLeaf > 0) |
| 48 { |
| 49 nLeftLeaf = nLeaf; |
| 50 nRightLeaf = nLeaf; |
| 51 } |
| 52 ·· |
| 53 // Create the point-to-point link helpers |
| 54 PointToPointHelper pointToPointRouter; |
| 55 pointToPointRouter.SetDeviceAttribute ("DataRate", StringValue ("10Mbps")); |
| 56 pointToPointRouter.SetChannelAttribute ("Delay", StringValue ("1ms")); |
| 57 PointToPointHelper pointToPointLeaf; |
| 58 pointToPointLeaf.SetDeviceAttribute ("DataRate", StringValue ("10Mbps")); |
| 59 pointToPointLeaf.SetChannelAttribute ("Delay", StringValue ("1ms")); |
| 60 |
| 61 PointToPointDumbbellHelper d(nLeftLeaf, pointToPointLeaf, |
| 62 nRightLeaf, pointToPointLeaf, |
| 63 pointToPointRouter); |
| 64 |
| 65 // Install Stack |
| 66 InternetStackHelper stack; |
| 67 d.InstallStack (stack); |
| 68 |
| 69 // Assign IP Addresses |
| 70 d.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"), |
| 71 Ipv4AddressHelper ("10.2.1.0", "255.255.255.0"), |
| 72 Ipv4AddressHelper ("10.3.1.0", "255.255.255.0")); |
| 73 ·· |
| 74 // Install on/off app on all right side nodes |
| 75 OnOffHelper clientHelper ("ns3::UdpSocketFactory", Address ()); |
| 76 clientHelper.SetAttribute· |
| 77 ("OnTime", RandomVariableValue (UniformVariable (0, 1))); |
| 78 clientHelper.SetAttribute· |
| 79 ("OffTime", RandomVariableValue (UniformVariable (0, 1))); |
| 80 ApplicationContainer clientApps; |
| 81 |
| 82 for (uint32_t i = 0; i < d.RightCount (); ++i) |
| 83 { |
| 84 // Create an on/off app sending packets to the same leaf right side |
| 85 AddressValue remoteAddress (InetSocketAddress (d.GetLeftIpv4Address (i), 1
000)); |
| 86 clientHelper.SetAttribute ("Remote", remoteAddress); |
| 87 clientApps.Add(clientHelper.Install (d.GetRight (i))); |
| 88 } |
| 89 |
| 90 clientApps.Start (Seconds (0.0)); |
| 91 clientApps.Stop (Seconds (10.0)); |
| 92 |
| 93 // Set the bounding box for animation |
| 94 d.BoundingBox (1, 1, 10, 10); |
| 95 |
| 96 // Create the animation object and configure for specified output |
| 97 AnimationInterface anim; |
| 98 if (port > 0) |
| 99 { |
| 100 anim.SetServerPort (port); |
| 101 } |
| 102 else if (!animFile.empty ()) |
| 103 { |
| 104 anim.SetOutputFile (animFile); |
| 105 } |
| 106 anim.StartAnimation (); |
| 107 ·· |
| 108 // Set up the acutal simulation |
| 109 Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
| 110 |
| 111 std::cout << "Running the simulation" << std::endl; |
| 112 Simulator::Run (); |
| 113 std::cout << "Destroying the simulation" << std::endl; |
| 114 Simulator::Destroy (); |
| 115 std::cout << "Stopping the animation" << std::endl; |
| 116 anim.StopAnimation(); |
| 117 return 0; |
| 118 } |
OLD | NEW |