blob: 4992a9da23ade14e08831311566f354c5ef0d6c4 [file] [log] [blame]
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -08001/* -*- 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 Afanasyev6c678382012-01-22 16:15:41 -080029#include "ns3/ccnx.h"
Ilya Moiseenko2063c882012-01-11 19:59:32 -080030#include "ns3/topology-reader.h"
Alexander Afanasyev6c678382012-01-22 16:15:41 -080031#include "../model/ccnx-net-device-face.h"
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -080032
33#include <iostream>
34#include <sstream>
35#include <map>
36#include <list>
37#include <set>
38#include "ns3/rocketfuel-topology-reader.h"
39
40#include <boost/lexical_cast.hpp>
41#include <boost/foreach.hpp>
42
43using namespace ns3;
44using namespace std;
45using namespace boost;
46
47NS_LOG_COMPONENT_DEFINE ("LinkFailureSprint");
48
Alexander Afanasyev17acc112012-01-20 15:04:24 -080049#include "base-experiment.h"
50
51class Experiment : public BaseExperiment
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -080052{
53public:
Alexander Afanasyev6c678382012-01-22 16:15:41 -080054 typedef tuple<string, string> failure_t;
55 typedef list<failure_t> failures_t;
56
57 Experiment (const string &file)
58 {
59 ifstream failures (("./src/NDNabstraction/examples/failures/failures-"+file).c_str ());
60 for(std::string line; std::getline(failures, line); )
61 {
62 if (line == "")
63 {
64 m_failures.push_back (failures_t ());
65 continue;
66 }
67
68 failures_t failures;
69 istringstream run (line);
70 while (!run.eof () && !run.bad ())
71 {
72 int32_t link1 = -1;
73 int32_t link2 = -1;
74 run >> link1;
75 run.get ();
76 run >> link2;
77 run.get ();
78 if (link1 < 0 || link2 < 0) continue;
79
80 // cout << link1 << " <-> " << link2 << " ";
81 failures.push_back (failure_t (lexical_cast<string> (link1), lexical_cast<string> (link2)));
82 }
83 m_failures.push_back (failures);
84 }
85 }
86
Alexander Afanasyev17acc112012-01-20 15:04:24 -080087 // hijacker is more than an application. just disable all faces
Alexander Afanasyev6c678382012-01-22 16:15:41 -080088 void
Alexander Afanasyev17acc112012-01-20 15:04:24 -080089 FailLinks (uint32_t failId)
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -080090 {
Alexander Afanasyev6c678382012-01-22 16:15:41 -080091 failures_t failures = m_failures [failId];
92 BOOST_FOREACH (failure_t failure, failures)
93 {
94 Ptr<Node> node1 = Names::Find<Node> ("/sprint", failure.get<0> ());
95 Ptr<Node> node2 = Names::Find<Node> ("/sprint", failure.get<1> ());
96 // cout << failure.get<0> () << " <-> " << failure.get<1> () << " ";
97 // cout << node1 << ", " << node2 << "\n";
98
99 Ptr<Ccnx> ccnx1 = node1->GetObject<Ccnx> ();
100 Ptr<Ccnx> ccnx2 = node2->GetObject<Ccnx> ();
101 for (uint32_t faceId = 0; faceId < ccnx1->GetNFaces (); faceId++)
102 {
103 Ptr<CcnxFace> face = ccnx1->GetFace (faceId);
104 Ptr<CcnxNetDeviceFace> ndFace = face->GetObject<CcnxNetDeviceFace> ();
105 if (ndFace == 0) continue;
106
107 Ptr<PointToPointNetDevice> nd1 = ndFace->GetNetDevice ()->GetObject<PointToPointNetDevice> ();
108 if (nd1 == 0) continue;
109
110 Ptr<Channel> channel = nd1->GetChannel ();
111 if (channel == 0) continue;
112
113 Ptr<PointToPointChannel> ppChannel = DynamicCast<PointToPointChannel> (channel);
114
115 Ptr<NetDevice> nd2 = ppChannel->GetDevice (0);
116 if (nd2->GetNode () == node1)
117 nd2 = ppChannel->GetDevice (1);
118
119 if (Names::FindName (nd2->GetNode ()) == failure.get<1> ())
120 {
121 cout << "Failing " << failure.get<0> () << " <-> " << failure.get<1> () << " link\n";
122
123 Ptr<CcnxFace> face1 = ccnx1->GetFaceByNetDevice (nd1);
124 Ptr<CcnxFace> face2 = ccnx2->GetFaceByNetDevice (nd2);
125
126 face1->SetUp (false);
127 face2->SetUp (false);
128
129 break;
130 }
131 }
132 }
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800133 }
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800134
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800135 // void
136 // FailLinks(double threshold)
137 // {
138 // NS_LOG_INFO("Failing links");
139 // m_linkRand = UniformVariable(0, 1.0);
140 // double probability = 0.0;
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800141
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800142 // BOOST_FOREACH (const TopologyReader::Link &link, m_reader.GetLinks())
143 // {
144 // probability = m_linkRand.GetValue();
145 // NS_LOG_INFO ("Probability = " << probability);
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800146
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800147 // 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());
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800153
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800154 // Ptr<CcnxL3Protocol> fromCcnx = fromNode->GetObject<CcnxL3Protocol> ();
155 // Ptr<CcnxL3Protocol> toCcnx = toNode->GetObject<CcnxL3Protocol> ();
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800156
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800157 // Ptr<NetDevice> fromDevice = link.GetFromNetDevice ();
158 // Ptr<NetDevice> toDevice = link.GetToNetDevice ();
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800159
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800160 // Ptr<CcnxFace> fromFace = fromCcnx->GetFaceByNetDevice (fromDevice);
161 // Ptr<CcnxFace> toFace = toCcnx->GetFaceByNetDevice (toDevice);
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800162
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800163 // 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);
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800167
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800168 // NS_LOG_INFO(fromFace->IsUp());
169 // NS_LOG_INFO(toFace->IsUp());
170 // }
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800171
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800172 // }
173 // /*
174 // uint32_t nodeId = m_rand.GetValue ();
175 // Ptr<Node> node = Names::Find<Node> ("/sprint", lexical_cast<string> (nodeId));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800176
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800177 // 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 // }
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800184
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800185 //We are creating "everybody-to-everybody" usage pattern
186 ApplicationContainer
187 AddApplications()
188 {
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800189 NS_LOG_INFO ("Adding applications");
Alexander Afanasyev6c678382012-01-22 16:15:41 -0800190 NS_LOG_INFO ("GetN = " << reader->GetNodes().GetN());
191
192 double delay = 0;
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800193
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800194 ApplicationContainer apps;
Alexander Afanasyev6c678382012-01-22 16:15:41 -0800195 for (uint32_t i = 0; i<reader->GetNodes().GetN(); i++)
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800196 {
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800197 NS_LOG_INFO("i="<<i);
198 Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (i));
199
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800200 CcnxAppHelper producerHelper ("ns3::CcnxProducer");
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800201 producerHelper.SetPrefix ("/" + lexical_cast<string> (node1->GetId ()));
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800202
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800203 apps.Add (producerHelper.Install (node1));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800204
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800205 CcnxAppHelper consumerHelper ("ns3::CcnxConsumerBatches");
206 consumerHelper.SetAttribute ("LifeTime", StringValue("100s"));
Alexander Afanasyev6c678382012-01-22 16:15:41 -0800207 consumerHelper.SetAttribute ("Batches", StringValue("0s 1 1s 1 2s 1 3s 1 6s 1 20s 1"));
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800208
Alexander Afanasyev6c678382012-01-22 16:15:41 -0800209 for(uint32_t j = 0; j<reader->GetNodes().GetN();j++)
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800210 {
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800211 NS_LOG_INFO("j="<<j);
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800212 if(i==j)
213 continue;
214
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800215 Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (j));
216
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800217 consumerHelper.SetPrefix ("/" + lexical_cast<string> (node1->GetId ()) + "/" + lexical_cast<string> (node2->GetId ()));
Alexander Afanasyev6c678382012-01-22 16:15:41 -0800218 ApplicationContainer consumer = consumerHelper.Install (node2);
219 consumer.Start (Seconds (delay));
220 apps.Add (consumer);
221
222 delay += 0.0001;
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800223 }
224 }
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800225
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800226 return apps;
227 }
Alexander Afanasyev6c678382012-01-22 16:15:41 -0800228
229private:
230 vector<failures_t> m_failures;
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800231};
232
233int
234main (int argc, char *argv[])
235{
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800236 cout << "Begin link failure scenario\n";
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800237
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800238 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("100Mbps"));
239 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("2000"));
240 Config::SetDefault ("ns3::RttEstimator::InitialEstimation", StringValue ("0.5s"));
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800241
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800242 Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("attributes.xml"));
243 Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
244 Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
245
246 uint32_t maxRuns = 1;
247 uint32_t startRun = 0;
248 std::string failures = "";
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800249 CommandLine cmd;
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800250 cmd.AddValue ("start", "Initial run number", startRun);
251 cmd.AddValue ("runs", "Number of runs", maxRuns);
252 cmd.AddValue ("failures", "File with failures", failures);
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800253 cmd.Parse (argc, argv);
254
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800255 if (failures == "")
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800256 {
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800257 std::cerr << "--failures=<file> parameter has to be specified" << std::endl;
258 return 1;
259 }
260
261 // ConfigStore config;
262 // config.ConfigureDefaults ();
263
Alexander Afanasyev6c678382012-01-22 16:15:41 -0800264 Experiment experiment (failures);
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800265 for (uint32_t run = startRun; run < startRun + maxRuns; run++)
266 {
267 Config::SetGlobal ("RngRun", IntegerValue (run));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800268 cout << "seed = " << SeedManager::GetSeed () << ", run = " << SeedManager::GetRun () << endl;
269
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800270 cout << "Run " << run << endl;
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800271 string prefix = "link-failure-" + lexical_cast<string> (run) + "-";
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800272
273 experiment.ConfigureTopology ();
Alexander Afanasyev6c678382012-01-22 16:15:41 -0800274 experiment.InstallCcnxStack (true);
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800275 ApplicationContainer apps = experiment.AddApplications ();
Alexander Afanasyev6c678382012-01-22 16:15:41 -0800276 cout << "Total number of applications: " << apps.GetN () << "\n";
277
278 Simulator::Schedule (Seconds (10.0), &Experiment::FailLinks, &experiment, run);
279
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800280 //tracing
281 CcnxTraceHelper traceHelper;
Alexander Afanasyev6c678382012-01-22 16:15:41 -0800282 Simulator::Schedule (Seconds (4.5), &CcnxTraceHelper::EnableSeqsAppAll, &traceHelper,
283 "ns3::CcnxConsumerBatches", prefix + "consumers-seqs.log");
284 Simulator::Schedule (Seconds (4.5), &CcnxTraceHelper::EnablePathWeights, &traceHelper,
285 prefix + "weights.log");
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800286
Alexander Afanasyev6c678382012-01-22 16:15:41 -0800287 experiment.Run (Seconds(30.0));
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800288 }
289
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800290 cout << "Finish link failure scenario\n";
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800291 return 0;
292}