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 | |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 56 | #include "base-experiment.h" |
| 57 | |
| 58 | class Experiment : public BaseExperiment |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 59 | { |
| 60 | public: |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 61 | // hijacker is more than an application. just disable all faces |
| 62 | static void |
| 63 | FailLinks (uint32_t failId) |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 64 | { |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 65 | // Ptr<Ccnx> ccnx = node->GetObject<Ccnx> (); |
| 66 | // for (uint32_t i = 0; i < ccnx->GetNFaces (); i++) |
| 67 | // { |
| 68 | // Ptr<CcnxFace> face = ccnx->GetFace (i); |
| 69 | // face->SetUp (false); |
| 70 | // } |
| 71 | // CcnxStackHelper::InstallRouteTo (prefix, node); |
| 72 | } |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 73 | |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 74 | // void |
| 75 | // FailLinks(double threshold) |
| 76 | // { |
| 77 | // NS_LOG_INFO("Failing links"); |
| 78 | // m_linkRand = UniformVariable(0, 1.0); |
| 79 | // double probability = 0.0; |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 80 | |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 81 | // BOOST_FOREACH (const TopologyReader::Link &link, m_reader.GetLinks()) |
| 82 | // { |
| 83 | // probability = m_linkRand.GetValue(); |
| 84 | // NS_LOG_INFO ("Probability = " << probability); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 85 | |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 86 | // if(probability <= threshold) |
| 87 | // { |
| 88 | // Ptr<Node> fromNode = link.GetFromNode (); |
| 89 | // Ptr<Node> toNode = link.GetToNode (); |
| 90 | // NS_LOG_INFO("From node id = " << fromNode->GetId()); |
| 91 | // NS_LOG_INFO("To node id = " << toNode->GetId()); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 92 | |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 93 | // Ptr<CcnxL3Protocol> fromCcnx = fromNode->GetObject<CcnxL3Protocol> (); |
| 94 | // Ptr<CcnxL3Protocol> toCcnx = toNode->GetObject<CcnxL3Protocol> (); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 95 | |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 96 | // Ptr<NetDevice> fromDevice = link.GetFromNetDevice (); |
| 97 | // Ptr<NetDevice> toDevice = link.GetToNetDevice (); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 98 | |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 99 | // Ptr<CcnxFace> fromFace = fromCcnx->GetFaceByNetDevice (fromDevice); |
| 100 | // Ptr<CcnxFace> toFace = toCcnx->GetFaceByNetDevice (toDevice); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 101 | |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 102 | // NS_LOG_INFO("From face id = " << fromFace->GetId()); |
| 103 | // NS_LOG_INFO("To face id = " << toFace->GetId()); |
| 104 | // fromFace->SetUp (false); |
| 105 | // toFace->SetUp (false); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 106 | |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 107 | // NS_LOG_INFO(fromFace->IsUp()); |
| 108 | // NS_LOG_INFO(toFace->IsUp()); |
| 109 | // } |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 110 | |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 111 | // } |
| 112 | // /* |
| 113 | // uint32_t nodeId = m_rand.GetValue (); |
| 114 | // Ptr<Node> node = Names::Find<Node> ("/sprint", lexical_cast<string> (nodeId)); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 115 | |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 116 | // Ptr<CcnxL3Protocol> ccnx = node->GetObject<CcnxL3Protocol> (); |
| 117 | // UniformVariable faceRandom = UniformVariable (0, ccnx->GetNFaces ()); |
| 118 | // uint32_t faceId = faceRandom.GetValue(); |
| 119 | // Ptr<CcnxFace> face = ccnx->GetFace (faceId); |
| 120 | // face->SetUp(false); |
| 121 | // */ |
| 122 | // } |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 123 | |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 124 | //We are creating "everybody-to-everybody" usage pattern |
| 125 | ApplicationContainer |
| 126 | AddApplications() |
| 127 | { |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 128 | NS_LOG_INFO ("Adding applications"); |
| 129 | NS_LOG_INFO ("GetN = " << m_reader.GetNodes().GetN()); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 130 | |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 131 | ApplicationContainer apps; |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 132 | for (uint32_t i = 0; i<m_reader.GetNodes().GetN(); i++) |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 133 | { |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 134 | NS_LOG_INFO("i="<<i); |
| 135 | Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (i)); |
| 136 | |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 137 | CcnxAppHelper producerHelper ("ns3::CcnxProducer"); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 138 | producerHelper.SetPrefix ("/" + lexical_cast<string> (node1->GetId ())); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 139 | |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 140 | apps.Add (producerHelper.Install (node1)); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 141 | |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 142 | CcnxAppHelper consumerHelper ("ns3::CcnxConsumerBatches"); |
| 143 | consumerHelper.SetAttribute ("LifeTime", StringValue("100s")); |
| 144 | consumerHelper.SetAttribute ("Batches", StringValue("0s 10 6s 1 20s 1")); |
| 145 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 146 | for(uint32_t j = 0; j<m_reader.GetNodes().GetN();j++) |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 147 | { |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 148 | NS_LOG_INFO("j="<<j); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 149 | if(i==j) |
| 150 | continue; |
| 151 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 152 | Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (j)); |
| 153 | |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 154 | consumerHelper.SetPrefix ("/" + lexical_cast<string> (node1->GetId ()) + "/" + lexical_cast<string> (node2->GetId ())); |
| 155 | apps.Add (consumerHelper.Install (node2)); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 156 | } |
| 157 | } |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 158 | |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 159 | return apps; |
| 160 | } |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 161 | }; |
| 162 | |
| 163 | int |
| 164 | main (int argc, char *argv[]) |
| 165 | { |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 166 | cout << "Begin link failure scenario\n"; |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 167 | |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 168 | Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("100Mbps")); |
| 169 | Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("2000")); |
| 170 | Config::SetDefault ("ns3::RttEstimator::InitialEstimation", StringValue ("0.5s")); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 171 | |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 172 | Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("attributes.xml")); |
| 173 | Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save")); |
| 174 | Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml")); |
| 175 | |
| 176 | uint32_t maxRuns = 1; |
| 177 | uint32_t startRun = 0; |
| 178 | std::string failures = ""; |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 179 | CommandLine cmd; |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 180 | cmd.AddValue ("start", "Initial run number", startRun); |
| 181 | cmd.AddValue ("runs", "Number of runs", maxRuns); |
| 182 | cmd.AddValue ("failures", "File with failures", failures); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 183 | cmd.Parse (argc, argv); |
| 184 | |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 185 | if (failures == "") |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 186 | { |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 187 | std::cerr << "--failures=<file> parameter has to be specified" << std::endl; |
| 188 | return 1; |
| 189 | } |
| 190 | |
| 191 | // ConfigStore config; |
| 192 | // config.ConfigureDefaults (); |
| 193 | |
| 194 | Experiment experiment; |
| 195 | for (uint32_t run = startRun; run < startRun + maxRuns; run++) |
| 196 | { |
| 197 | Config::SetGlobal ("RngRun", IntegerValue (run)); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 198 | cout << "seed = " << SeedManager::GetSeed () << ", run = " << SeedManager::GetRun () << endl; |
| 199 | |
| 200 | Experiment experiment; |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 201 | // experiment.GenerateRandomPairs (1); |
| 202 | experiment.FailLinks (run); |
| 203 | cout << "Run " << run << endl; |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 204 | |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 205 | string prefix = "link-failure-" + lexical_cast<string> (run) + "-"; |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 206 | |
| 207 | experiment.ConfigureTopology (); |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 208 | experiment.InstallCcnxStack (false); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 209 | ApplicationContainer apps = experiment.AddApplications (); |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 210 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 211 | //tracing |
| 212 | CcnxTraceHelper traceHelper; |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 213 | // traceHelper.EnableRateL3All (prefix + "rate-trace.log"); |
| 214 | traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumerBatches", prefix + "consumers-seqs.log"); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 215 | |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 216 | // enable path weights some time from now (ensure that all faces are created) |
| 217 | Simulator::Schedule (Seconds (4.5), &CcnxTraceHelper::EnablePathWeights, &traceHelper, prefix + "weights.log"); |
| 218 | std::cout << "Total " << apps.GetN () << " applications\n"; |
| 219 | |
| 220 | experiment.Run (Seconds(40.0)); |
| 221 | } |
| 222 | |
| 223 | |
| 224 | |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 225 | |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 226 | // Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("10Mbps")); |
| 227 | // Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("100")); |
| 228 | |
| 229 | // Time finishTime1 = Seconds (5.0); |
| 230 | // Time finishTime2 = Seconds (20.0); |
| 231 | |
| 232 | // CommandLine cmd; |
| 233 | // cmd.AddValue ("finish", "Finish time", finishTime1); |
| 234 | // cmd.Parse (argc, argv); |
| 235 | |
| 236 | // Experiment experiment; |
| 237 | |
| 238 | // for (uint32_t i = 0; i < 80; i++) |
| 239 | // { |
| 240 | // Config::SetGlobal ("RngRun", IntegerValue (i)); |
| 241 | // cout << "seed = " << SeedManager::GetSeed () << ", run = " << SeedManager::GetRun () << endl; |
| 242 | |
| 243 | // Experiment experiment; |
| 244 | // cout << "Run " << i << endl; |
| 245 | |
| 246 | // string prefix = "run-" + lexical_cast<string> (i) + "-"; |
| 247 | |
| 248 | // //before link failure |
| 249 | // experiment.ConfigureTopology (); |
| 250 | // ApplicationContainer apps = experiment.AddApplications (); |
| 251 | // experiment.ConfigureRouting (); |
| 252 | // //tracing |
| 253 | // //... |
| 254 | // //experiment.Run (finishTime1); |
| 255 | |
| 256 | // //after link failure |
| 257 | // experiment.FailLinks(0.1); |
| 258 | |
| 259 | // //tracing |
| 260 | // CcnxTraceHelper traceHelper; |
| 261 | // traceHelper.EnableRateL3All (prefix + "rate-trace.log"); |
| 262 | // traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumer", prefix + "consumers-seqs.log"); |
| 263 | // //... |
| 264 | // experiment.Run (finishTime2); |
| 265 | |
| 266 | // /* |
| 267 | // for (uint32_t i = 0; i < apps.GetN () / 2; i++) |
| 268 | // { |
| 269 | // cout << "From " << apps.Get (i*2)->GetNode ()->GetId () |
| 270 | // << " to " << apps.Get (i*2 + 1)->GetNode ()->GetId (); |
| 271 | // cout << "\n"; |
| 272 | // }*/ |
| 273 | |
| 274 | // //CcnxTraceHelper traceHelper; |
| 275 | // // traceHelper.EnableAggregateAppAll ("ns3::CcnxConsumer"); |
| 276 | // // traceHelper.EnableAggregateAppAll ("ns3::CcnxProducer"); |
| 277 | // // traceHelper.EnableAggregateL3All (); |
| 278 | // // traceHelper.SetL3TraceFile ("trace-l3.log"); |
| 279 | // // traceHelper.SetAppTraceFile ("trace-app.log"); |
| 280 | // // traceHelper.EnableRateL3All ("rate-trace.log"); |
| 281 | // //traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumer", "consumers-seqs.log"); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 282 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 283 | |
Alexander Afanasyev | 17acc11 | 2012-01-20 15:04:24 -0800 | [diff] [blame^] | 284 | // } |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 285 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 286 | cout << "Finish link failure scenario\n"; |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 287 | return 0; |
| 288 | } |