Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -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 | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 29 | #include "ns3/ccnx-l3-protocol.h" |
| 30 | #include "ns3/topology-reader.h" |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -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 ("LinkFailureSprint"); |
| 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 | |
| 56 | class Experiment |
| 57 | { |
| 58 | public: |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 59 | Experiment () |
| 60 | : m_reader ("/sprint") { } |
| 61 | |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 62 | void |
| 63 | ConfigureTopology () |
| 64 | { |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 65 | Names::Clear (); |
| 66 | |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 67 | string weights ("./src/NDNabstraction/examples/sprint-pops.weights"); |
| 68 | string latencies ("./src/NDNabstraction/examples/sprint-pops.latencies"); |
| 69 | string positions ("./src/NDNabstraction/examples/sprint-pops.positions"); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 70 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 71 | //RocketfuelWeightsReader reader ("/sprint"); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 72 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 73 | m_reader.SetFileName (positions); |
| 74 | m_reader.SetFileType (RocketfuelWeightsReader::POSITIONS); |
| 75 | m_reader.Read (); |
| 76 | |
| 77 | m_reader.SetFileName (weights); |
| 78 | m_reader.SetFileType (RocketfuelWeightsReader::WEIGHTS); |
| 79 | m_reader.Read (); |
| 80 | |
| 81 | m_reader.SetFileName (latencies); |
| 82 | m_reader.SetFileType (RocketfuelWeightsReader::LATENCIES); |
| 83 | m_reader.Read (); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 84 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 85 | m_reader.Commit (); |
| 86 | NS_ASSERT_MSG (m_reader.LinksSize () != 0, "Problems reading the topology file. Failing."); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 87 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 88 | NS_LOG_INFO("Nodes = " << m_reader.GetNodes ().GetN()); |
| 89 | NS_LOG_INFO("Links = " << m_reader.LinksSize ()); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 90 | |
| 91 | // ------------------------------------------------------------ |
| 92 | // -- Read topology data. |
| 93 | // -------------------------------------------- |
| 94 | |
| 95 | InternetStackHelper stack; |
| 96 | Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops"); |
| 97 | stack.SetRoutingHelper (ipv4RoutingHelper); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 98 | stack.Install (m_reader.GetNodes ()); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 99 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 100 | m_reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0")); |
| 101 | |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 102 | // Install CCNx stack |
| 103 | NS_LOG_INFO ("Installing CCNx stack"); |
| 104 | CcnxStackHelper ccnxHelper; |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 105 | ccnxHelper.SetForwardingStrategy ("ns3::CcnxBestRouteStrategy"); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 106 | ccnxHelper.EnableLimits (true, Seconds(0.1)); |
| 107 | ccnxHelper.SetDefaultRoutes (false); |
| 108 | ccnxHelper.InstallAll (); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 109 | |
| 110 | m_rand = UniformVariable (0, m_reader.GetNodes ().GetN()); |
| 111 | //m_linkRand = UniformVariable(0, m_reader.LinksSize()); |
| 112 | } |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 113 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 114 | void |
| 115 | ConfigureRouting () |
| 116 | { |
| 117 | CcnxStackHelper ccnxHelper; |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 118 | // // Populate FIB based on IPv4 global routing controller |
| 119 | ccnxHelper.InstallFakeGlobalRoutes (); |
| 120 | ccnxHelper.InstallRoutesToAll (); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | public: |
| 124 | void |
| 125 | Run (const Time &finishTime) |
| 126 | { |
| 127 | cout << "Run Simulation.\n"; |
| 128 | Simulator::Stop (finishTime); |
| 129 | Simulator::Schedule (Seconds (1.0), PrintTime); |
| 130 | Simulator::Run (); |
| 131 | Simulator::Destroy (); |
| 132 | cout << "Done.\n"; |
| 133 | } |
| 134 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 135 | void |
| 136 | FailLinks(double threshold) |
| 137 | { |
| 138 | NS_LOG_INFO("Failing links"); |
| 139 | m_linkRand = UniformVariable(0, 1.0); |
| 140 | double probability = 0.0; |
| 141 | |
| 142 | BOOST_FOREACH (const TopologyReader::Link &link, m_reader.GetLinks()) |
| 143 | { |
| 144 | probability = m_linkRand.GetValue(); |
| 145 | NS_LOG_INFO ("Probability = " << probability); |
| 146 | |
| 147 | if(probability <= threshold) |
| 148 | { |
| 149 | Ptr<Node> fromNode = link.GetFromNode (); |
| 150 | Ptr<Node> toNode = link.GetToNode (); |
| 151 | NS_LOG_INFO("From node id = " << fromNode->GetId()); |
| 152 | NS_LOG_INFO("To node id = " << toNode->GetId()); |
| 153 | |
| 154 | Ptr<CcnxL3Protocol> fromCcnx = fromNode->GetObject<CcnxL3Protocol> (); |
| 155 | Ptr<CcnxL3Protocol> toCcnx = toNode->GetObject<CcnxL3Protocol> (); |
| 156 | |
| 157 | Ptr<NetDevice> fromDevice = link.GetFromNetDevice (); |
| 158 | Ptr<NetDevice> toDevice = link.GetToNetDevice (); |
| 159 | |
| 160 | Ptr<CcnxFace> fromFace = fromCcnx->GetFaceByNetDevice (fromDevice); |
| 161 | Ptr<CcnxFace> toFace = toCcnx->GetFaceByNetDevice (toDevice); |
| 162 | |
| 163 | NS_LOG_INFO("From face id = " << fromFace->GetId()); |
| 164 | NS_LOG_INFO("To face id = " << toFace->GetId()); |
| 165 | fromFace->SetUp (false); |
| 166 | toFace->SetUp (false); |
| 167 | |
| 168 | NS_LOG_INFO(fromFace->IsUp()); |
| 169 | NS_LOG_INFO(toFace->IsUp()); |
| 170 | } |
| 171 | |
| 172 | } |
| 173 | /* |
| 174 | uint32_t nodeId = m_rand.GetValue (); |
| 175 | Ptr<Node> node = Names::Find<Node> ("/sprint", lexical_cast<string> (nodeId)); |
| 176 | |
| 177 | Ptr<CcnxL3Protocol> ccnx = node->GetObject<CcnxL3Protocol> (); |
| 178 | UniformVariable faceRandom = UniformVariable (0, ccnx->GetNFaces ()); |
| 179 | uint32_t faceId = faceRandom.GetValue(); |
| 180 | Ptr<CcnxFace> face = ccnx->GetFace (faceId); |
| 181 | face->SetUp(false); |
| 182 | */ |
| 183 | } |
| 184 | |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 185 | //We are creating "everybody-to-everybody" usage pattern |
| 186 | ApplicationContainer |
| 187 | AddApplications() |
| 188 | { |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 189 | NS_LOG_INFO("Adding applications"); |
| 190 | NS_LOG_INFO("GetN = " << m_reader.GetNodes().GetN()); |
| 191 | |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 192 | ApplicationContainer apps; |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 193 | for(uint32_t i = 0; i<m_reader.GetNodes().GetN(); i++) |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 194 | { |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 195 | NS_LOG_INFO("i="<<i); |
| 196 | Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (i)); |
| 197 | |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 198 | CcnxAppHelper producerHelper ("ns3::CcnxProducer"); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 199 | producerHelper.SetPrefix ("/" + lexical_cast<string> (node1->GetId ())); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 200 | |
| 201 | apps.Add(producerHelper.Install (node1)); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 202 | |
| 203 | for(uint32_t j = 0; j<m_reader.GetNodes().GetN();j++) |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 204 | { |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 205 | NS_LOG_INFO("j="<<j); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 206 | if(i==j) |
| 207 | continue; |
| 208 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 209 | Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (j)); |
| 210 | |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 211 | CcnxAppHelper consumerHelper ("ns3::CcnxConsumer"); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 212 | consumerHelper.SetPrefix ("/" + lexical_cast<string> (node1->GetId ())); |
| 213 | consumerHelper.SetAttribute ("MeanRate", StringValue ("1Kbps")); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 214 | consumerHelper.SetAttribute ("Size", StringValue ("2")); |
| 215 | |
| 216 | apps.Add(consumerHelper.Install (node2)); |
| 217 | } |
| 218 | } |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 219 | |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 220 | return apps; |
| 221 | } |
| 222 | |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 223 | UniformVariable m_rand; |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 224 | UniformVariable m_linkRand; |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 225 | RocketfuelWeightsReader m_reader; |
| 226 | }; |
| 227 | |
| 228 | int |
| 229 | main (int argc, char *argv[]) |
| 230 | { |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 231 | cout << "Begin link failure scenario\n"; |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 232 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 233 | Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("10Mbps")); |
| 234 | Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("100")); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 235 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 236 | Time finishTime1 = Seconds (5.0); |
| 237 | Time finishTime2 = Seconds (20.0); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 238 | |
| 239 | CommandLine cmd; |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 240 | cmd.AddValue ("finish", "Finish time", finishTime1); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 241 | cmd.Parse (argc, argv); |
| 242 | |
| 243 | Experiment experiment; |
| 244 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 245 | for (uint32_t i = 0; i < 80; i++) |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 246 | { |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 247 | Config::SetGlobal ("RngRun", IntegerValue (i)); |
| 248 | cout << "seed = " << SeedManager::GetSeed () << ", run = " << SeedManager::GetRun () << endl; |
| 249 | |
| 250 | Experiment experiment; |
| 251 | cout << "Run " << i << endl; |
| 252 | |
| 253 | string prefix = "run-" + lexical_cast<string> (i) + "-"; |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 254 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 255 | //before link failure |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 256 | experiment.ConfigureTopology (); |
| 257 | ApplicationContainer apps = experiment.AddApplications (); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 258 | experiment.ConfigureRouting (); |
| 259 | //tracing |
| 260 | //... |
| 261 | //experiment.Run (finishTime1); |
| 262 | |
| 263 | //after link failure |
| 264 | experiment.FailLinks(0.1); |
| 265 | |
| 266 | //tracing |
| 267 | CcnxTraceHelper traceHelper; |
| 268 | traceHelper.EnableRateL3All (prefix + "rate-trace.log"); |
| 269 | traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumer", prefix + "consumers-seqs.log"); |
| 270 | //... |
| 271 | experiment.Run (finishTime2); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 272 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 273 | /* |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 274 | for (uint32_t i = 0; i < apps.GetN () / 2; i++) |
| 275 | { |
| 276 | cout << "From " << apps.Get (i*2)->GetNode ()->GetId () |
| 277 | << " to " << apps.Get (i*2 + 1)->GetNode ()->GetId (); |
| 278 | cout << "\n"; |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 279 | }*/ |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 280 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 281 | //CcnxTraceHelper traceHelper; |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 282 | // traceHelper.EnableAggregateAppAll ("ns3::CcnxConsumer"); |
| 283 | // traceHelper.EnableAggregateAppAll ("ns3::CcnxProducer"); |
| 284 | // traceHelper.EnableAggregateL3All (); |
| 285 | // traceHelper.SetL3TraceFile ("trace-l3.log"); |
| 286 | // traceHelper.SetAppTraceFile ("trace-app.log"); |
| 287 | // traceHelper.EnableRateL3All ("rate-trace.log"); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 288 | //traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumer", "consumers-seqs.log"); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 289 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 290 | |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 291 | } |
| 292 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 293 | cout << "Finish link failure scenario\n"; |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 294 | return 0; |
| 295 | } |