blob: 421f1344478485eb0c73ef98dee9704afd0665eb [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
56class Experiment
57{
58public:
Ilya Moiseenko2063c882012-01-11 19:59:32 -080059 Experiment ()
60 : m_reader ("/sprint") { }
61
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -080062 void
63 ConfigureTopology ()
64 {
Ilya Moiseenko2063c882012-01-11 19:59:32 -080065 Names::Clear ();
66
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -080067 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 Moiseenko46bdc7c2012-01-09 14:44:15 -080070
Ilya Moiseenko2063c882012-01-11 19:59:32 -080071 //RocketfuelWeightsReader reader ("/sprint");
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -080072
Ilya Moiseenko2063c882012-01-11 19:59:32 -080073 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 Moiseenko46bdc7c2012-01-09 14:44:15 -080084
Ilya Moiseenko2063c882012-01-11 19:59:32 -080085 m_reader.Commit ();
86 NS_ASSERT_MSG (m_reader.LinksSize () != 0, "Problems reading the topology file. Failing.");
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -080087
Ilya Moiseenko2063c882012-01-11 19:59:32 -080088 NS_LOG_INFO("Nodes = " << m_reader.GetNodes ().GetN());
89 NS_LOG_INFO("Links = " << m_reader.LinksSize ());
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -080090
91 // ------------------------------------------------------------
92 // -- Read topology data.
93 // --------------------------------------------
94
95 InternetStackHelper stack;
96 Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops");
97 stack.SetRoutingHelper (ipv4RoutingHelper);
Ilya Moiseenko2063c882012-01-11 19:59:32 -080098 stack.Install (m_reader.GetNodes ());
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -080099
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800100 m_reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
101
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800102 // Install CCNx stack
103 NS_LOG_INFO ("Installing CCNx stack");
104 CcnxStackHelper ccnxHelper;
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800105 ccnxHelper.SetForwardingStrategy ("ns3::CcnxBestRouteStrategy");
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800106 ccnxHelper.EnableLimits (true, Seconds(0.1));
107 ccnxHelper.SetDefaultRoutes (false);
108 ccnxHelper.InstallAll ();
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800109
110 m_rand = UniformVariable (0, m_reader.GetNodes ().GetN());
111 //m_linkRand = UniformVariable(0, m_reader.LinksSize());
112 }
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800113
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800114 void
115 ConfigureRouting ()
116 {
117 CcnxStackHelper ccnxHelper;
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800118 // // Populate FIB based on IPv4 global routing controller
119 ccnxHelper.InstallFakeGlobalRoutes ();
120 ccnxHelper.InstallRoutesToAll ();
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800121 }
122
123public:
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 Moiseenko2063c882012-01-11 19:59:32 -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;
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 Moiseenko46bdc7c2012-01-09 14:44:15 -0800185 //We are creating "everybody-to-everybody" usage pattern
186 ApplicationContainer
187 AddApplications()
188 {
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800189 NS_LOG_INFO("Adding applications");
190 NS_LOG_INFO("GetN = " << m_reader.GetNodes().GetN());
191
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800192 ApplicationContainer apps;
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800193 for(uint32_t i = 0; i<m_reader.GetNodes().GetN(); i++)
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800194 {
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800195 NS_LOG_INFO("i="<<i);
196 Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (i));
197
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800198 CcnxAppHelper producerHelper ("ns3::CcnxProducer");
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800199 producerHelper.SetPrefix ("/" + lexical_cast<string> (node1->GetId ()));
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800200
201 apps.Add(producerHelper.Install (node1));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800202
203 for(uint32_t j = 0; j<m_reader.GetNodes().GetN();j++)
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800204 {
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800205 NS_LOG_INFO("j="<<j);
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800206 if(i==j)
207 continue;
208
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800209 Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (j));
210
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800211 CcnxAppHelper consumerHelper ("ns3::CcnxConsumer");
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800212 consumerHelper.SetPrefix ("/" + lexical_cast<string> (node1->GetId ()));
213 consumerHelper.SetAttribute ("MeanRate", StringValue ("1Kbps"));
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800214 consumerHelper.SetAttribute ("Size", StringValue ("2"));
215
216 apps.Add(consumerHelper.Install (node2));
217 }
218 }
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800219
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800220 return apps;
221 }
222
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800223 UniformVariable m_rand;
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800224 UniformVariable m_linkRand;
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800225 RocketfuelWeightsReader m_reader;
226};
227
228int
229main (int argc, char *argv[])
230{
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800231 cout << "Begin link failure scenario\n";
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800232
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800233 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("10Mbps"));
234 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("100"));
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800235
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800236 Time finishTime1 = Seconds (5.0);
237 Time finishTime2 = Seconds (20.0);
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800238
239 CommandLine cmd;
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800240 cmd.AddValue ("finish", "Finish time", finishTime1);
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800241 cmd.Parse (argc, argv);
242
243 Experiment experiment;
244
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800245 for (uint32_t i = 0; i < 80; i++)
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800246 {
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800247 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 Moiseenko46bdc7c2012-01-09 14:44:15 -0800254
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800255 //before link failure
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800256 experiment.ConfigureTopology ();
257 ApplicationContainer apps = experiment.AddApplications ();
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800258 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 Moiseenko46bdc7c2012-01-09 14:44:15 -0800272
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800273/*
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800274 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 Moiseenko2063c882012-01-11 19:59:32 -0800279 }*/
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800280
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800281 //CcnxTraceHelper traceHelper;
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800282 // 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 Moiseenko2063c882012-01-11 19:59:32 -0800288 //traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumer", "consumers-seqs.log");
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800289
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800290
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800291 }
292
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800293 cout << "Finish link failure scenario\n";
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -0800294 return 0;
295}