Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Ilya Moiseenko <iliamo@cs.ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | |
| 22 | #include "ns3/core-module.h" |
| 23 | #include "ns3/network-module.h" |
| 24 | #include "ns3/point-to-point-module.h" |
| 25 | #include "ns3/NDNabstraction-module.h" |
| 26 | #include "ns3/point-to-point-grid.h" |
| 27 | #include "ns3/ipv4-global-routing-helper.h" |
| 28 | #include "ns3/random-variable.h" |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 29 | #include "ns3/internet-module.h" |
| 30 | #include "ns3/applications-module.h" |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 31 | |
| 32 | #include <iostream> |
| 33 | #include <sstream> |
| 34 | #include <map> |
| 35 | #include <list> |
| 36 | #include <set> |
| 37 | #include "ns3/rocketfuel-topology-reader.h" |
| 38 | |
| 39 | #include <boost/lexical_cast.hpp> |
| 40 | #include <boost/foreach.hpp> |
| 41 | |
| 42 | using namespace ns3; |
| 43 | using namespace std; |
| 44 | using namespace boost; |
| 45 | |
| 46 | NS_LOG_COMPONENT_DEFINE ("Scenario"); |
| 47 | |
| 48 | void PrintTime () |
| 49 | { |
| 50 | cout << "Progress: " << Simulator::Now ().ToDouble (Time::S) << "s" << endl; |
| 51 | |
| 52 | Simulator::Schedule (Seconds (1.0), PrintTime); |
| 53 | } |
| 54 | |
| 55 | class Experiment |
| 56 | { |
| 57 | public: |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 58 | Experiment () |
| 59 | : m_rand (0,52) |
| 60 | , reader ("/sprint") |
| 61 | { } |
| 62 | |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 63 | void |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 64 | ConfigureCcnxTopology () |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 65 | { |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 66 | Names::Clear (); |
| 67 | |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 68 | string weights ("./src/NDNabstraction/examples/sprint-pops.weights"); |
| 69 | string latencies ("./src/NDNabstraction/examples/sprint-pops.latencies"); |
| 70 | string positions ("./src/NDNabstraction/examples/sprint-pops.positions"); |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 71 | |
| 72 | RocketfuelWeightsReader reader ("/sprint"); |
| 73 | |
| 74 | reader.SetFileName (positions); |
| 75 | reader.SetFileType (RocketfuelWeightsReader::POSITIONS); |
| 76 | reader.Read (); |
| 77 | |
| 78 | reader.SetFileName (weights); |
| 79 | reader.SetFileType (RocketfuelWeightsReader::WEIGHTS); |
| 80 | reader.Read (); |
| 81 | |
| 82 | reader.SetFileName (latencies); |
| 83 | reader.SetFileType (RocketfuelWeightsReader::LATENCIES); |
| 84 | reader.Read (); |
| 85 | |
| 86 | reader.Commit (); |
| 87 | NS_ASSERT_MSG (reader.LinksSize () != 0, "Problems reading the topology file. Failing."); |
| 88 | |
| 89 | NS_LOG_INFO("Nodes = " << reader.GetNodes ().GetN()); |
| 90 | NS_LOG_INFO("Links = " << reader.LinksSize ()); |
| 91 | |
| 92 | // ------------------------------------------------------------ |
| 93 | // -- Read topology data. |
| 94 | // -------------------------------------------- |
| 95 | |
| 96 | InternetStackHelper stack; |
| 97 | Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops"); |
| 98 | stack.SetRoutingHelper (ipv4RoutingHelper); |
| 99 | stack.Install (reader.GetNodes ()); |
| 100 | |
| 101 | reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0")); |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 102 | |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 103 | // Install CCNx stack |
| 104 | NS_LOG_INFO ("Installing CCNx stack"); |
| 105 | CcnxStackHelper ccnxHelper; |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 106 | ccnxHelper.SetForwardingStrategy ("ns3::CcnxBestRouteStrategy"); |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 107 | ccnxHelper.EnableLimits (true, Seconds(0.1)); |
| 108 | ccnxHelper.SetDefaultRoutes (false); |
| 109 | ccnxHelper.InstallAll (); |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 110 | } |
| 111 | |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 112 | void |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 113 | ConfigureRouting () |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 114 | { |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 115 | CcnxStackHelper ccnxHelper; |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 116 | // // Populate FIB based on IPv4 global routing controller |
| 117 | ccnxHelper.InstallFakeGlobalRoutes (); |
| 118 | ccnxHelper.InstallRoutesToAll (); |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 119 | } |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 120 | |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 121 | ApplicationContainer |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 122 | AddCcnxRandomApplications (uint16_t numStreams) |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 123 | { |
| 124 | map<uint32_t, set<uint32_t> > streams; |
| 125 | ApplicationContainer apps; |
| 126 | |
| 127 | uint16_t createdStreams = 0; |
| 128 | uint16_t guard = 0; |
| 129 | while (createdStreams < numStreams && guard < (numeric_limits<uint16_t>::max ()-1)) |
| 130 | { |
| 131 | guard ++; |
| 132 | |
| 133 | uint32_t node1_num = m_rand.GetValue (); |
| 134 | uint32_t node2_num = m_rand.GetValue (); |
| 135 | |
| 136 | if (node1_num == node2_num) |
| 137 | continue; |
| 138 | |
| 139 | if (streams[node1_num].count (node2_num) > 0) // don't create duplicate streams |
| 140 | continue; |
| 141 | |
| 142 | streams[node1_num].insert (node2_num); |
| 143 | |
| 144 | Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (node1_num)); |
| 145 | Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (node2_num)); |
| 146 | |
| 147 | CcnxAppHelper consumerHelper ("ns3::CcnxConsumer"); |
| 148 | consumerHelper.SetPrefix ("/" + lexical_cast<string> (node2->GetId ())); |
| 149 | consumerHelper.SetAttribute ("MeanRate", StringValue ("2Mbps")); |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 150 | consumerHelper.SetAttribute ("Size", StringValue ("1.983642578125")); //to make sure max seq # is 2000 |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 151 | |
| 152 | CcnxAppHelper producerHelper ("ns3::CcnxProducer"); |
| 153 | producerHelper.SetPrefix ("/" + lexical_cast<string> (node2->GetId ())); |
| 154 | |
| 155 | apps.Add |
| 156 | (consumerHelper.Install (node1)); |
| 157 | |
| 158 | apps.Add |
| 159 | (producerHelper.Install (node2)); |
| 160 | |
| 161 | createdStreams ++; |
| 162 | } |
| 163 | |
| 164 | return apps; |
| 165 | } |
| 166 | |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 167 | void |
| 168 | Run (const Time &finishTime) |
| 169 | { |
| 170 | cout << "Run Simulation.\n"; |
| 171 | Simulator::Stop (finishTime); |
| 172 | // Simulator::Schedule (Seconds (1.0), PrintTime); |
| 173 | Simulator::Run (); |
| 174 | Simulator::Destroy (); |
| 175 | cout << "Done.\n"; |
| 176 | } |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 177 | |
| 178 | UniformVariable m_rand; |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 179 | RocketfuelWeightsReader reader; |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 180 | }; |
| 181 | |
| 182 | |
| 183 | int |
| 184 | main (int argc, char *argv[]) |
| 185 | { |
| 186 | cout << "Begin congestion-pop scenario\n"; |
| 187 | |
| 188 | Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps")); |
| 189 | Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20")); |
| 190 | |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 191 | uint32_t maxRuns = 1; |
| 192 | uint32_t startRun = 0; |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 193 | CommandLine cmd; |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 194 | cmd.AddValue ("start", "Initial run number", startRun); |
| 195 | cmd.AddValue ("runs", "Number of runs", maxRuns); |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 196 | cmd.Parse (argc, argv); |
| 197 | |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 198 | for (uint32_t run = startRun; run < startRun + maxRuns; run++) |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 199 | { |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 200 | Config::SetGlobal ("RngRun", IntegerValue (run)); |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 201 | cout << "seed = " << SeedManager::GetSeed () << ", run = " << SeedManager::GetRun () << endl; |
| 202 | |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 203 | Experiment experiment; |
| 204 | cout << "Run " << run << endl; |
| 205 | |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 206 | experiment.ConfigureCcnxTopology (); |
| 207 | ApplicationContainer apps = experiment.AddCcnxRandomApplications (20); |
| 208 | experiment.ConfigureRouting (); |
| 209 | |
| 210 | string prefix = "run-" + lexical_cast<string> (run) + "-"; |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 211 | |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 212 | ofstream of_nodes ((prefix + "apps.log").c_str ()); |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 213 | for (uint32_t i = 0; i < apps.GetN () / 2; i++) |
| 214 | { |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 215 | of_nodes << "From " << apps.Get (i*2)->GetNode ()->GetId () |
| 216 | << " to " << apps.Get (i*2 + 1)->GetNode ()->GetId (); |
| 217 | of_nodes << "\n"; |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 218 | } |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 219 | of_nodes.close (); |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 220 | |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 221 | CcnxTraceHelper traceHelper; |
| 222 | traceHelper.EnableRateL3All (prefix + "rate-trace.log"); |
| 223 | traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumer", prefix + "consumers-seqs.log"); |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 224 | |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 225 | experiment.Run (Seconds (200.0)); |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 226 | } |
| 227 | |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 228 | // cout << "Finish congestion-pop scenario\n"; |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 229 | return 0; |
| 230 | } |