Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -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" |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 29 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame^] | 30 | #include <iostream> |
| 31 | #include <sstream> |
| 32 | #include <map> |
| 33 | #include <list> |
| 34 | #include <set> |
| 35 | #include "ns3/rocketfuel-topology-reader.h" |
| 36 | |
| 37 | #include <boost/lexical_cast.hpp> |
| 38 | #include <boost/foreach.hpp> |
| 39 | |
| 40 | using namespace ns3; |
| 41 | using namespace std; |
| 42 | using namespace boost; |
| 43 | |
| 44 | NS_LOG_COMPONENT_DEFINE ("BlackholeSprint"); |
| 45 | |
| 46 | void PrintTime () |
| 47 | { |
| 48 | cout << "Progress: " << Simulator::Now ().ToDouble (Time::S) << "s" << endl; |
| 49 | |
| 50 | Simulator::Schedule (Seconds (1.0), PrintTime); |
| 51 | } |
| 52 | |
| 53 | |
| 54 | class Experiment |
| 55 | { |
| 56 | public: |
| 57 | Experiment () |
| 58 | : m_reader ("/sprint") { } |
| 59 | |
| 60 | void |
| 61 | ConfigureTopology () |
| 62 | { |
| 63 | Names::Clear (); |
| 64 | |
| 65 | string weights ("./src/NDNabstraction/examples/sprint-pops.weights"); |
| 66 | string latencies ("./src/NDNabstraction/examples/sprint-pops.latencies"); |
| 67 | string positions ("./src/NDNabstraction/examples/sprint-pops.positions"); |
| 68 | |
| 69 | m_reader.SetFileName (positions); |
| 70 | m_reader.SetFileType (RocketfuelWeightsReader::POSITIONS); |
| 71 | m_reader.Read (); |
| 72 | |
| 73 | m_reader.SetFileName (weights); |
| 74 | m_reader.SetFileType (RocketfuelWeightsReader::WEIGHTS); |
| 75 | m_reader.Read (); |
| 76 | |
| 77 | m_reader.SetFileName (latencies); |
| 78 | m_reader.SetFileType (RocketfuelWeightsReader::LATENCIES); |
| 79 | m_reader.Read (); |
| 80 | |
| 81 | m_reader.Commit (); |
| 82 | NS_ASSERT_MSG (m_reader.LinksSize () != 0, "Problems reading the topology file. Failing."); |
| 83 | |
| 84 | NS_LOG_INFO("Nodes = " << m_reader.GetNodes ().GetN()); |
| 85 | NS_LOG_INFO("Links = " << m_reader.LinksSize ()); |
| 86 | |
| 87 | // ------------------------------------------------------------ |
| 88 | // -- Read topology data. |
| 89 | // -------------------------------------------- |
| 90 | |
| 91 | InternetStackHelper stack; |
| 92 | Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops"); |
| 93 | stack.SetRoutingHelper (ipv4RoutingHelper); |
| 94 | stack.Install (m_reader.GetNodes ()); |
| 95 | |
| 96 | m_reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0")); |
| 97 | |
| 98 | // Install CCNx stack |
| 99 | NS_LOG_INFO ("Installing CCNx stack"); |
| 100 | CcnxStackHelper ccnxHelper; |
| 101 | ccnxHelper.SetForwardingStrategy ("ns3::CcnxBestRouteStrategy"); |
| 102 | ccnxHelper.EnableLimits (true, Seconds(0.1)); |
| 103 | ccnxHelper.SetDefaultRoutes (false); |
| 104 | ccnxHelper.InstallAll (); |
| 105 | |
| 106 | m_rand = UniformVariable (0, m_reader.GetNodes ().GetN()); |
| 107 | m_linkRand = UniformVariable(0, m_reader.LinksSize()); |
| 108 | } |
| 109 | |
| 110 | void |
| 111 | ConfigureRouting () |
| 112 | { |
| 113 | CcnxStackHelper ccnxHelper; |
| 114 | // // Populate FIB based on IPv4 global routing controller |
| 115 | ccnxHelper.InstallFakeGlobalRoutes (); |
| 116 | ccnxHelper.InstallRoutesToAll (); |
| 117 | } |
| 118 | |
| 119 | public: |
| 120 | void |
| 121 | Run (const Time &finishTime) |
| 122 | { |
| 123 | cout << "Run Simulation.\n"; |
| 124 | Simulator::Stop (finishTime); |
| 125 | //Simulator::Schedule (Seconds (1.0), PrintTime); |
| 126 | Simulator::Run (); |
| 127 | Simulator::Destroy (); |
| 128 | cout << "Done.\n"; |
| 129 | } |
| 130 | |
| 131 | //We are creating 10 pairs of producer-hijacker and everybody else is a consumer |
| 132 | ApplicationContainer |
| 133 | AddApplications(uint32_t numOfPairs) |
| 134 | { |
| 135 | NS_LOG_INFO("Adding applications"); |
| 136 | ApplicationContainer apps; |
| 137 | |
| 138 | list<uint32_t > usedNodes; |
| 139 | list<uint32_t >::iterator listIterator; |
| 140 | list<uint32_t >::iterator listIterator2; |
| 141 | |
| 142 | uint32_t producerNodeId; |
| 143 | uint32_t hijackerNodeId; |
| 144 | |
| 145 | for(uint32_t pairCount = 0; pairCount < numOfPairs; pairCount++) |
| 146 | { |
| 147 | NS_LOG_INFO("pairCount = "<<pairCount); |
| 148 | while(true) |
| 149 | { |
| 150 | producerNodeId = m_rand.GetValue (); |
| 151 | hijackerNodeId = m_rand.GetValue (); |
| 152 | |
| 153 | bool unique = true; |
| 154 | for(listIterator=usedNodes.begin(); listIterator != usedNodes.end(); ++listIterator) |
| 155 | { |
| 156 | if((*listIterator == producerNodeId) || (*listIterator == hijackerNodeId)) |
| 157 | { |
| 158 | NS_LOG_INFO("NonUnique"); |
| 159 | unique = false; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | if(unique == true) |
| 164 | { |
| 165 | usedNodes.push_back(producerNodeId); |
| 166 | usedNodes.push_back(hijackerNodeId); |
| 167 | break; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | NS_LOG_INFO("Producer #" << producerNodeId); |
| 172 | Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (producerNodeId)); |
| 173 | CcnxAppHelper producerHelper ("ns3::CcnxProducer"); |
| 174 | producerHelper.SetPrefix ("/" + lexical_cast<string> (node1->GetId ())); |
| 175 | |
| 176 | apps.Add(producerHelper.Install (node1)); |
| 177 | |
| 178 | NS_LOG_INFO("Hijacker # "<<hijackerNodeId); |
| 179 | Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (hijackerNodeId)); |
| 180 | CcnxAppHelper hijackerHelper ("ns3::CcnxHijacker"); |
| 181 | hijackerHelper.SetPrefix ("/" + lexical_cast<string> (node1->GetId ())); |
| 182 | |
| 183 | apps.Add(hijackerHelper.Install (node1)); |
| 184 | |
| 185 | /*NS_LOG_INFO("Consumers"); |
| 186 | for(uint32_t j = 0; j<m_reader.GetNodes().GetN();j++) |
| 187 | { |
| 188 | //NS_LOG_INFO("j="<<j); |
| 189 | bool consumer = true; |
| 190 | for(listIterator=usedNodes.begin(); listIterator != usedNodes.end(); ++listIterator) |
| 191 | { |
| 192 | if(*listIterator == j) |
| 193 | { |
| 194 | consumer = false; |
| 195 | NS_LOG_INFO(j<<" CANNOT be CONSUMER"); |
| 196 | break; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | if(consumer == true) |
| 201 | { |
| 202 | Ptr<Node> node3 = Names::Find<Node> ("/sprint", lexical_cast<string> (j)); |
| 203 | |
| 204 | CcnxAppHelper consumerHelper ("ns3::CcnxConsumer"); |
| 205 | consumerHelper.SetPrefix ("/" + lexical_cast<string> (node1->GetId ())); |
| 206 | consumerHelper.SetAttribute ("MeanRate", StringValue ("1Kbps")); |
| 207 | consumerHelper.SetAttribute ("Size", StringValue ("2")); |
| 208 | |
| 209 | apps.Add(consumerHelper.Install (node3)); |
| 210 | } |
| 211 | }*/ |
| 212 | } |
| 213 | |
| 214 | NS_LOG_INFO("Consumers"); |
| 215 | for(listIterator=usedNodes.begin(); listIterator != usedNodes.end(); ++listIterator,++listIterator) |
| 216 | { |
| 217 | for(uint32_t j = 0; j<m_reader.GetNodes().GetN();j++) |
| 218 | { |
| 219 | //NS_LOG_INFO("j="<<j); |
| 220 | bool consumer = true; |
| 221 | for(listIterator2=usedNodes.begin(); listIterator2 != usedNodes.end(); ++listIterator2) |
| 222 | { |
| 223 | if(*listIterator2 == j) |
| 224 | { |
| 225 | consumer = false; |
| 226 | NS_LOG_INFO(j<<" CANNOT be a CONSUMER"); |
| 227 | break; |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | if(consumer == true) |
| 232 | { |
| 233 | Ptr<Node> node3 = Names::Find<Node> ("/sprint", lexical_cast<string> (j)); |
| 234 | Ptr<Node> node4 = Names::Find<Node> ("/sprint", lexical_cast<string> (*listIterator)); |
| 235 | |
| 236 | CcnxAppHelper consumerHelper ("ns3::CcnxConsumer"); |
| 237 | NS_LOG_INFO("Node = " << *listIterator); |
| 238 | consumerHelper.SetPrefix ("/" + lexical_cast<string> (node4->GetId ())); |
| 239 | consumerHelper.SetAttribute ("MeanRate", StringValue ("1Kbps")); |
| 240 | consumerHelper.SetAttribute ("Size", StringValue ("2")); |
| 241 | |
| 242 | apps.Add(consumerHelper.Install (node3)); |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | |
| 248 | return apps; |
| 249 | } |
| 250 | |
| 251 | UniformVariable m_rand; |
| 252 | UniformVariable m_linkRand; |
| 253 | |
| 254 | private: |
| 255 | RocketfuelWeightsReader m_reader; |
| 256 | }; |
| 257 | |
| 258 | int |
| 259 | main (int argc, char *argv[]) |
| 260 | { |
| 261 | cout << "Begin blackhole scenario\n"; |
| 262 | |
| 263 | Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("2Mbps")); |
| 264 | Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("100")); |
| 265 | |
| 266 | Time finishTime = Seconds (20.0); |
| 267 | |
| 268 | |
| 269 | CommandLine cmd; |
| 270 | cmd.AddValue ("finish", "Finish time", finishTime); |
| 271 | cmd.Parse (argc, argv); |
| 272 | |
| 273 | Experiment experiment; |
| 274 | |
| 275 | for (uint32_t i = 0; i < 80; i++) |
| 276 | { |
| 277 | Config::SetGlobal ("RngRun", IntegerValue (i)); |
| 278 | cout << "seed = " << SeedManager::GetSeed () << ", run = " << SeedManager::GetRun () << endl; |
| 279 | |
| 280 | Experiment experiment; |
| 281 | cout << "Run " << i << endl; |
| 282 | |
| 283 | string prefix = "run-" + lexical_cast<string> (i) + "-"; |
| 284 | |
| 285 | experiment.ConfigureTopology (); |
| 286 | ApplicationContainer apps = experiment.AddApplications (10); |
| 287 | experiment.ConfigureRouting (); |
| 288 | |
| 289 | /*ApplicationContainer apps = experiment.AddApplications (); |
| 290 | |
| 291 | for (uint32_t i = 0; i < apps.GetN () / 2; i++) |
| 292 | { |
| 293 | cout << "From " << apps.Get (i*2)->GetNode ()->GetId () |
| 294 | << " to " << apps.Get (i*2 + 1)->GetNode ()->GetId (); |
| 295 | cout << "\n"; |
| 296 | } |
| 297 | */ |
| 298 | |
| 299 | //tracing |
| 300 | CcnxTraceHelper traceHelper; |
| 301 | traceHelper.EnableRateL3All (prefix + "rate-trace.log"); |
| 302 | traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumer", prefix + "consumers-seqs.log"); |
| 303 | |
| 304 | experiment.Run (finishTime); |
| 305 | } |
| 306 | |
| 307 | cout << "Finish blackhole scenario\n"; |
| 308 | return 0; |
| 309 | } |