blob: 85e7b3dae65801a1e2ede036c812c625e4e5ca77 [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"
Ilya Moiseenko2063c882012-01-11 19:59:32 -080029#include "ns3/ccnx-l3-protocol.h"
30#include "ns3/topology-reader.h"
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -080031
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
42using namespace ns3;
43using namespace std;
44using namespace boost;
45
46NS_LOG_COMPONENT_DEFINE ("LinkFailureSprint");
47
48void PrintTime ()
49{
50 cout << "Progress: " << Simulator::Now ().ToDouble (Time::S) << "s" << endl;
51
52 Simulator::Schedule (Seconds (1.0), PrintTime);
53}
54
55
Alexander Afanasyev17acc112012-01-20 15:04:24 -080056#include "base-experiment.h"
57
58class Experiment : public BaseExperiment
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -080059{
60public:
Alexander Afanasyev17acc112012-01-20 15:04:24 -080061 // hijacker is more than an application. just disable all faces
62 static void
63 FailLinks (uint32_t failId)
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -080064 {
Alexander Afanasyev17acc112012-01-20 15:04:24 -080065 // 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 Moiseenko46bdc7c2012-01-09 14:44:15 -080073
Alexander Afanasyev17acc112012-01-20 15:04:24 -080074 // 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 Moiseenko46bdc7c2012-01-09 14:44:15 -080080
Alexander Afanasyev17acc112012-01-20 15:04:24 -080081 // BOOST_FOREACH (const TopologyReader::Link &link, m_reader.GetLinks())
82 // {
83 // probability = m_linkRand.GetValue();
84 // NS_LOG_INFO ("Probability = " << probability);
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -080085
Alexander Afanasyev17acc112012-01-20 15:04:24 -080086 // 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 Moiseenko2063c882012-01-11 19:59:32 -080092
Alexander Afanasyev17acc112012-01-20 15:04:24 -080093 // Ptr<CcnxL3Protocol> fromCcnx = fromNode->GetObject<CcnxL3Protocol> ();
94 // Ptr<CcnxL3Protocol> toCcnx = toNode->GetObject<CcnxL3Protocol> ();
Ilya Moiseenko2063c882012-01-11 19:59:32 -080095
Alexander Afanasyev17acc112012-01-20 15:04:24 -080096 // Ptr<NetDevice> fromDevice = link.GetFromNetDevice ();
97 // Ptr<NetDevice> toDevice = link.GetToNetDevice ();
Ilya Moiseenko2063c882012-01-11 19:59:32 -080098
Alexander Afanasyev17acc112012-01-20 15:04:24 -080099 // Ptr<CcnxFace> fromFace = fromCcnx->GetFaceByNetDevice (fromDevice);
100 // Ptr<CcnxFace> toFace = toCcnx->GetFaceByNetDevice (toDevice);
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800101
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800102 // 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 Moiseenko2063c882012-01-11 19:59:32 -0800106
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800107 // NS_LOG_INFO(fromFace->IsUp());
108 // NS_LOG_INFO(toFace->IsUp());
109 // }
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800110
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800111 // }
112 // /*
113 // uint32_t nodeId = m_rand.GetValue ();
114 // Ptr<Node> node = Names::Find<Node> ("/sprint", lexical_cast<string> (nodeId));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800115
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800116 // 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 Moiseenko2063c882012-01-11 19:59:32 -0800123
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800124 //We are creating "everybody-to-everybody" usage pattern
125 ApplicationContainer
126 AddApplications()
127 {
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800128 NS_LOG_INFO ("Adding applications");
129 NS_LOG_INFO ("GetN = " << m_reader.GetNodes().GetN());
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800130
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800131 ApplicationContainer apps;
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800132 for (uint32_t i = 0; i<m_reader.GetNodes().GetN(); i++)
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800133 {
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800134 NS_LOG_INFO("i="<<i);
135 Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (i));
136
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800137 CcnxAppHelper producerHelper ("ns3::CcnxProducer");
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800138 producerHelper.SetPrefix ("/" + lexical_cast<string> (node1->GetId ()));
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800139
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800140 apps.Add (producerHelper.Install (node1));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800141
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800142 CcnxAppHelper consumerHelper ("ns3::CcnxConsumerBatches");
143 consumerHelper.SetAttribute ("LifeTime", StringValue("100s"));
144 consumerHelper.SetAttribute ("Batches", StringValue("0s 10 6s 1 20s 1"));
145
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800146 for(uint32_t j = 0; j<m_reader.GetNodes().GetN();j++)
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800147 {
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800148 NS_LOG_INFO("j="<<j);
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800149 if(i==j)
150 continue;
151
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800152 Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (j));
153
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800154 consumerHelper.SetPrefix ("/" + lexical_cast<string> (node1->GetId ()) + "/" + lexical_cast<string> (node2->GetId ()));
155 apps.Add (consumerHelper.Install (node2));
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800156 }
157 }
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800158
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800159 return apps;
160 }
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800161};
162
163int
164main (int argc, char *argv[])
165{
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800166 cout << "Begin link failure scenario\n";
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800167
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800168 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 Moiseenko46bdc7c2012-01-09 14:44:15 -0800171
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800172 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 Moiseenko46bdc7c2012-01-09 14:44:15 -0800179 CommandLine cmd;
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800180 cmd.AddValue ("start", "Initial run number", startRun);
181 cmd.AddValue ("runs", "Number of runs", maxRuns);
182 cmd.AddValue ("failures", "File with failures", failures);
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800183 cmd.Parse (argc, argv);
184
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800185 if (failures == "")
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800186 {
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800187 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 Moiseenko2063c882012-01-11 19:59:32 -0800198 cout << "seed = " << SeedManager::GetSeed () << ", run = " << SeedManager::GetRun () << endl;
199
200 Experiment experiment;
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800201 // experiment.GenerateRandomPairs (1);
202 experiment.FailLinks (run);
203 cout << "Run " << run << endl;
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800204
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800205 string prefix = "link-failure-" + lexical_cast<string> (run) + "-";
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800206
207 experiment.ConfigureTopology ();
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800208 experiment.InstallCcnxStack (false);
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800209 ApplicationContainer apps = experiment.AddApplications ();
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800210
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800211 //tracing
212 CcnxTraceHelper traceHelper;
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800213 // traceHelper.EnableRateL3All (prefix + "rate-trace.log");
214 traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumerBatches", prefix + "consumers-seqs.log");
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800215
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800216 // 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 Moiseenko46bdc7c2012-01-09 14:44:15 -0800225
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800226// 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 Moiseenko46bdc7c2012-01-09 14:44:15 -0800282
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800283
Alexander Afanasyev17acc112012-01-20 15:04:24 -0800284// }
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800285
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800286 cout << "Finish link failure scenario\n";
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800287 return 0;
288}