Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -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" |
| 29 | #include "ns3/internet-module.h" |
| 30 | #include "ns3/applications-module.h" |
| 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: |
| 58 | void |
| 59 | ConfigureCcnxTopology () |
| 60 | { |
| 61 | Names::Clear (); |
| 62 | |
| 63 | string weights ("./src/NDNabstraction/examples/sprint-pops.weights"); |
| 64 | string latencies ("./src/NDNabstraction/examples/sprint-pops.latencies"); |
| 65 | string positions ("./src/NDNabstraction/examples/sprint-pops.positions"); |
| 66 | string strategy ("ns3::CcnxBestRouteStrategy"); |
| 67 | // string strategy ("ns3::CcnxFloodingStrategy"); |
| 68 | |
| 69 | RocketfuelWeightsReader reader ("/sprint"); |
| 70 | |
| 71 | reader.SetFileName (positions); |
| 72 | reader.SetFileType (RocketfuelWeightsReader::POSITIONS); |
| 73 | reader.Read (); |
| 74 | |
| 75 | reader.SetFileName (weights); |
| 76 | reader.SetFileType (RocketfuelWeightsReader::WEIGHTS); |
| 77 | reader.Read (); |
| 78 | |
| 79 | reader.SetFileName (latencies); |
| 80 | reader.SetFileType (RocketfuelWeightsReader::LATENCIES); |
| 81 | reader.Read (); |
| 82 | |
| 83 | reader.Commit (); |
| 84 | NS_ASSERT_MSG (reader.LinksSize () != 0, "Problems reading the topology file. Failing."); |
| 85 | |
| 86 | NS_LOG_INFO("Nodes = " << reader.GetNodes ().GetN()); |
| 87 | NS_LOG_INFO("Links = " << reader.LinksSize ()); |
| 88 | |
| 89 | // ------------------------------------------------------------ |
| 90 | // -- Read topology data. |
| 91 | // -------------------------------------------- |
| 92 | |
| 93 | InternetStackHelper stack; |
| 94 | Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops"); |
| 95 | stack.SetRoutingHelper (ipv4RoutingHelper); |
| 96 | stack.Install (reader.GetNodes ()); |
| 97 | |
| 98 | reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0")); |
| 99 | |
| 100 | // Install CCNx stack |
| 101 | NS_LOG_INFO ("Installing CCNx stack"); |
| 102 | CcnxStackHelper ccnxHelper; |
| 103 | ccnxHelper.SetForwardingStrategy (strategy); |
| 104 | ccnxHelper.EnableLimits (true, Seconds(0.1)); |
| 105 | ccnxHelper.SetDefaultRoutes (false); |
| 106 | ccnxHelper.InstallAll (); |
| 107 | |
| 108 | // // Populate FIB based on IPv4 global routing controller |
| 109 | ccnxHelper.InstallFakeGlobalRoutes (); |
| 110 | ccnxHelper.InstallRoutesToAll (); |
| 111 | |
| 112 | m_rand = UniformVariable (0, reader.GetNodes ().GetN()); |
| 113 | } |
| 114 | |
| 115 | void |
| 116 | ConfigureIpv4Topology () |
| 117 | { |
| 118 | Names::Clear (); |
| 119 | |
| 120 | string weights ("./src/NDNabstraction/examples/sprint-pops.weights"); |
| 121 | string latencies ("./src/NDNabstraction/examples/sprint-pops.latencies"); |
| 122 | string positions ("./src/NDNabstraction/examples/sprint-pops.positions"); |
| 123 | string strategy ("ns3::CcnxBestRouteStrategy"); |
| 124 | // string strategy ("ns3::CcnxFloodingStrategy"); |
| 125 | |
| 126 | RocketfuelWeightsReader reader ("/sprint"); |
| 127 | |
| 128 | reader.SetFileName (positions); |
| 129 | reader.SetFileType (RocketfuelWeightsReader::POSITIONS); |
| 130 | reader.Read (); |
| 131 | |
| 132 | reader.SetFileName (weights); |
| 133 | reader.SetFileType (RocketfuelWeightsReader::WEIGHTS); |
| 134 | reader.Read (); |
| 135 | |
| 136 | reader.SetFileName (latencies); |
| 137 | reader.SetFileType (RocketfuelWeightsReader::LATENCIES); |
| 138 | reader.Read (); |
| 139 | |
| 140 | reader.Commit (); |
| 141 | NS_ASSERT_MSG (reader.LinksSize () != 0, "Problems reading the topology file. Failing."); |
| 142 | |
| 143 | NS_LOG_INFO("Nodes = " << reader.GetNodes ().GetN()); |
| 144 | NS_LOG_INFO("Links = " << reader.LinksSize ()); |
| 145 | |
| 146 | // ------------------------------------------------------------ |
| 147 | // -- Read topology data. |
| 148 | // -------------------------------------------- |
| 149 | |
| 150 | InternetStackHelper stack; |
| 151 | Ipv4GlobalRoutingHelper ipv4RoutingHelper; |
| 152 | stack.SetRoutingHelper (ipv4RoutingHelper); |
| 153 | stack.Install (reader.GetNodes ()); |
| 154 | |
| 155 | reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0")); |
| 156 | |
| 157 | // Install CCNx stack |
| 158 | NS_LOG_INFO ("Installing CCNx stack"); |
| 159 | CcnxStackHelper ccnxHelper; |
| 160 | ccnxHelper.InstallFakeGlobalRoutesImpl (); |
| 161 | Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
| 162 | |
| 163 | m_rand = UniformVariable (0, reader.GetNodes ().GetN()); |
| 164 | } |
| 165 | |
| 166 | |
| 167 | ApplicationContainer |
| 168 | AddCcnxRandomApplications (uint16_t numStreams) |
| 169 | { |
| 170 | map<uint32_t, set<uint32_t> > streams; |
| 171 | ApplicationContainer apps; |
| 172 | |
| 173 | uint16_t createdStreams = 0; |
| 174 | uint16_t guard = 0; |
| 175 | while (createdStreams < numStreams && guard < (numeric_limits<uint16_t>::max ()-1)) |
| 176 | { |
| 177 | guard ++; |
| 178 | |
| 179 | uint32_t node1_num = m_rand.GetValue (); |
| 180 | uint32_t node2_num = m_rand.GetValue (); |
| 181 | |
| 182 | if (node1_num == node2_num) |
| 183 | continue; |
| 184 | |
| 185 | if (streams[node1_num].count (node2_num) > 0) // don't create duplicate streams |
| 186 | continue; |
| 187 | |
| 188 | streams[node1_num].insert (node2_num); |
| 189 | |
| 190 | Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (node1_num)); |
| 191 | Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (node2_num)); |
| 192 | |
| 193 | CcnxAppHelper consumerHelper ("ns3::CcnxConsumer"); |
| 194 | consumerHelper.SetPrefix ("/" + lexical_cast<string> (node2->GetId ())); |
| 195 | consumerHelper.SetAttribute ("MeanRate", StringValue ("2Mbps")); |
| 196 | consumerHelper.SetAttribute ("Size", StringValue ("1.983642578125")); //to make sure max seq # is 2000 |
| 197 | |
| 198 | CcnxAppHelper producerHelper ("ns3::CcnxProducer"); |
| 199 | producerHelper.SetPrefix ("/" + lexical_cast<string> (node2->GetId ())); |
| 200 | |
| 201 | apps.Add |
| 202 | (consumerHelper.Install (node1)); |
| 203 | |
| 204 | apps.Add |
| 205 | (producerHelper.Install (node2)); |
| 206 | |
| 207 | createdStreams ++; |
| 208 | } |
| 209 | |
| 210 | return apps; |
| 211 | } |
| 212 | |
| 213 | ApplicationContainer |
| 214 | AddTcpRandomApplications (uint16_t numStreams) |
| 215 | { |
| 216 | map<uint32_t, set<uint32_t> > streams; |
| 217 | ApplicationContainer apps; |
| 218 | |
| 219 | const static uint32_t base_port = 1000; |
| 220 | uint16_t createdStreams = 0; |
| 221 | uint16_t guard = 0; |
| 222 | while (createdStreams < numStreams && guard < (numeric_limits<uint16_t>::max ()-1)) |
| 223 | { |
| 224 | guard ++; |
| 225 | |
| 226 | uint32_t node1_num = m_rand.GetValue (); |
| 227 | uint32_t node2_num = m_rand.GetValue (); |
| 228 | |
| 229 | if (node1_num == node2_num) |
| 230 | continue; |
| 231 | |
| 232 | if (streams[node1_num].count (node2_num) > 0) // don't create duplicate streams |
| 233 | continue; |
| 234 | |
| 235 | streams[node1_num].insert (node2_num); |
| 236 | |
| 237 | Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (node1_num)); |
| 238 | Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (node2_num)); |
| 239 | |
| 240 | // to make sure we don't reuse the same port numbers for different flows, just make all port numbers unique |
| 241 | PacketSinkHelper consumerHelper ("ns3::TcpSocketFactory", |
| 242 | InetSocketAddress (Ipv4Address::GetAny (), base_port + createdStreams)); |
| 243 | |
| 244 | BulkSendHelper producerHelper ("ns3::TcpSocketFactory", |
| 245 | InetSocketAddress (Ipv4Address(node1->GetId ()), base_port + createdStreams)); |
| 246 | producerHelper.SetAttribute ("MaxBytes", UintegerValue (2080000)); // equal to 2000 ccnx packets |
| 247 | |
| 248 | apps.Add |
| 249 | (consumerHelper.Install (node1)); |
| 250 | |
| 251 | apps.Add |
| 252 | (producerHelper.Install (node2)); |
| 253 | |
| 254 | createdStreams ++; |
| 255 | } |
| 256 | |
| 257 | return apps; |
| 258 | } |
| 259 | |
| 260 | void |
| 261 | Run (const Time &finishTime) |
| 262 | { |
| 263 | cout << "Run Simulation.\n"; |
| 264 | Simulator::Stop (finishTime); |
| 265 | // Simulator::Schedule (Seconds (1.0), PrintTime); |
| 266 | Simulator::Run (); |
| 267 | Simulator::Destroy (); |
| 268 | cout << "Done.\n"; |
| 269 | } |
| 270 | |
| 271 | UniformVariable m_rand; |
| 272 | }; |
| 273 | |
| 274 | |
| 275 | int |
| 276 | main (int argc, char *argv[]) |
| 277 | { |
| 278 | cout << "Begin congestion-pop scenario\n"; |
| 279 | |
| 280 | Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps")); |
| 281 | Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20")); |
| 282 | |
| 283 | uint32_t maxRuns = 1; |
| 284 | uint32_t startRun = 0; |
| 285 | CommandLine cmd; |
| 286 | cmd.AddValue ("start", "Initial run number", startRun); |
| 287 | cmd.AddValue ("runs", "Number of runs", maxRuns); |
| 288 | cmd.Parse (argc, argv); |
| 289 | |
| 290 | for (uint32_t run = startRun; run < startRun + maxRuns; run++) |
| 291 | { |
| 292 | Config::SetGlobal ("RngRun", IntegerValue (run)); |
| 293 | |
| 294 | Experiment experiment; |
| 295 | cout << "Run " << run << endl; |
| 296 | |
| 297 | experiment.ConfigureTopology (); |
| 298 | // ApplicationContainer apps = experiment.AddCcnxRandomApplications (20); |
| 299 | ApplicationContainer apps = experiment.AddTcpRandomApplications (20); |
| 300 | |
| 301 | for (uint32_t i = 0; i < apps.GetN () / 2; i++) |
| 302 | { |
| 303 | cout << "From " << apps.Get (i*2)->GetNode ()->GetId () |
| 304 | << " to " << apps.Get (i*2 + 1)->GetNode ()->GetId (); |
| 305 | cout << "\n"; |
| 306 | } |
| 307 | |
| 308 | // CcnxTraceHelper traceHelper; |
| 309 | // traceHelper.EnableAggregateAppAll ("ns3::CcnxConsumer"); |
| 310 | // traceHelper.EnableAggregateAppAll ("ns3::CcnxProducer"); |
| 311 | // traceHelper.SetAppTraceFile (prefix + "trace-app.log"); |
| 312 | |
| 313 | // string prefix = "run-" + lexical_cast<string> (run) + "-"; |
| 314 | |
| 315 | // traceHelper.EnableAggregateL3All (); |
| 316 | // traceHelper.SetL3TraceFile ("trace-l3.log"); |
| 317 | // traceHelper.EnableRateL3All (prefix + "rate-trace.log"); |
| 318 | // traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumer", prefix + "consumers-seqs.log"); |
| 319 | |
| 320 | experiment.Run (Seconds (200.0)); |
| 321 | } |
| 322 | |
| 323 | // cout << "Finish congestion-pop scenario\n"; |
| 324 | return 0; |
| 325 | } |