blob: d4884d5c1068ab1dd7204224cc7267a1bf42fb81 [file] [log] [blame]
Ilya Moiseenko2063c882012-01-11 19:59:32 -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 Moiseenko46bdc7c2012-01-09 14:44:15 -080029
Ilya Moiseenko2063c882012-01-11 19:59:32 -080030#include <sstream>
31#include <map>
32#include <list>
33#include <set>
34#include "ns3/rocketfuel-topology-reader.h"
35
36#include <boost/lexical_cast.hpp>
37#include <boost/foreach.hpp>
38
Ilya Moiseenko2c069b92012-01-13 18:39:28 -080039#include <boost/config.hpp>
40#include <iostream>
41#include <fstream>
42
43#include <boost/graph/graph_traits.hpp>
44#include <boost/graph/adjacency_list.hpp>
45#include <boost/graph/dijkstra_shortest_paths.hpp>
46
Ilya Moiseenko2063c882012-01-11 19:59:32 -080047using namespace ns3;
48using namespace std;
49using namespace boost;
50
51NS_LOG_COMPONENT_DEFINE ("BlackholeSprint");
52
53void PrintTime ()
54{
55 cout << "Progress: " << Simulator::Now ().ToDouble (Time::S) << "s" << endl;
56
57 Simulator::Schedule (Seconds (1.0), PrintTime);
58}
59
Alexander Afanasyevb7626842012-01-12 13:43:33 -080060#include "base-experiment.h"
Ilya Moiseenko2063c882012-01-11 19:59:32 -080061
Alexander Afanasyevb7626842012-01-12 13:43:33 -080062class Experiment : public BaseExperiment
Ilya Moiseenko2063c882012-01-11 19:59:32 -080063{
64public:
Ilya Moiseenko2c069b92012-01-13 18:39:28 -080065 enum nodes {N0,N1,N2,N3,N4,N5,N6,N7,N8,N9,N10,N11,N12,N13,N14,N15,N16,N17,N18,N19,N20,N21,N22,N23,N24,N25,N26,N27,N28,N29,N30,N31,N32,N33,N34,N35,N36,N37,N38,N39,N40,N41,N42,N43,N44,N45,N46,N47,N48,N49,N50,N51};
66
67 typedef std::pair<int, int> Edge;
68 const Edge edge_array[84];
69
70 Experiment ()
71 : edge_array((Edge[84]){
72 Edge(N0, N1),
73 Edge(N2, N3),
74 Edge(N1, N4),
75 Edge(N1, N5),
76 Edge(N1, N6),
77 Edge(N1, N7),
78 Edge(N1, N8),
79 Edge(N1, N9),
80 Edge(N1, N10),
81 Edge(N1, N11),
82 Edge(N12, N13),
83 Edge(N14, N15),
84 Edge(N14, N16),
85 Edge(N14, N17),
86 Edge(N15, N18),
87 Edge(N15, N19),
88 Edge(N20, N21),
89 Edge(N20, N22),
90 Edge(N23, N24),
91 Edge(N25, N26),
92 Edge(N27, N28),
93 Edge(N8, N20),
94 Edge(N8, N16),
95 Edge(N8, N28),
96 Edge(N8, N24),
97 Edge(N8, N26),
98 Edge(N21, N31),
99 Edge(N13, N32),
100 Edge(N13, N33),
101 Edge(N17, N35),
102 Edge(N17, N20),
103 Edge(N17, N18),
104 Edge(N17, N28),
105 Edge(N17, N24),
106 Edge(N17, N25),
107 Edge(N17, N26),
108 Edge(N17, N29),
109 Edge(N17, N36),
110 Edge(N11, N24),
111 Edge(N11, N38),
112 Edge(N11, N17),
113 Edge(N33, N39),
114 Edge(N33, N40),
115 Edge(N6, N7),
116 Edge(N6, N28),
117 Edge(N6, N25),
118 Edge(N6, N8),
119 Edge(N6, N17),
120 Edge(N6, N34),
121 Edge(N6, N11),
122 Edge(N39, N42),
123 Edge(N16, N24),
124 Edge(N16, N29),
125 Edge(N16, N17),
126 Edge(N31, N45),
127 Edge(N31, N46),
128 Edge(N31, N37),
129 Edge(N31, N47),
130 Edge(N32, N48),
131 Edge(N32, N44),
132 Edge(N32, N42),
133 Edge(N48, N49),
134 Edge(N7, N13),
135 Edge(N38, N43),
136 Edge(N9, N15),
137 Edge(N9, N20),
138 Edge(N9, N31),
139 Edge(N9, N30),
140 Edge(N9, N17),
141 Edge(N9, N19),
142 Edge(N5, N32),
143 Edge(N5, N8),
144 Edge(N5, N7),
145 Edge(N18, N23),
146 Edge(N40, N48),
147 Edge(N40, N49),
148 Edge(N24, N38),
149 Edge(N24, N31),
150 Edge(N24, N45),
151 Edge(N24, N50),
152 Edge(N3, N9),
153 Edge(N19, N41),
154 Edge(N19, N20),
155 Edge(N19, N51)
156 })
157 { }
158
159
160 int
161 ComputeShortestWeightsPath(uint32_t sourceNode, uint32_t destinationNode)
162 {
163 typedef adjacency_list < listS, vecS, undirectedS,
164 no_property, property < edge_weight_t, int > > graph_t;
165 typedef graph_traits < graph_t >::vertex_descriptor vertex_descriptor;
166 typedef graph_traits < graph_t >::edge_descriptor edge_descriptor;
167
168 //string name[] = {"0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51"};
169
170
171 int weights[] = { 312, 10786, 222, 2500, 4000, 2500, 3860, 11769, 352, 3500, 2622, 500, 14192, 8909, 11747, 44530, 19775, 345, 5337, 2184, 645, 11409, 8282, 3000, 7735, 5500, 20741, 7552, 1500, 2091, 14409, 4337, 4000, 5735, 1315, 2500, 3282, 2478, 5096, 3235, 4360, 2000, 3000, 2500, 6860, 5176, 5860, 3860, 802, 5500, 699, 1547, 3000, 5282, 500, 268, 3375, 2708, 1712, 2329, 3352, 3201, 30890, 1643, 5500, 2500, 4735, 124, 13909, 42030, 28338, 2360, 2000, 5735, 2340, 2529, 2860, 9909, 10409, 92, 59812, 26190, 39530, 14125 };
172
173 int num_arcs = sizeof(edge_array) / sizeof(Edge);
174
175 graph_t g(edge_array, edge_array + num_arcs, weights, m_numNodes);
176 property_map<graph_t, edge_weight_t>::type weightmap = get(edge_weight, g);
177
178 std::vector<vertex_descriptor> p(num_vertices(g));
179 std::vector<int> d(num_vertices(g));
180
181 vertex_descriptor s = vertex(static_cast<nodes>(sourceNode), g);
182
183 dijkstra_shortest_paths(g, s, predecessor_map(&p[0]).distance_map(&d[0]));
184
185 NS_LOG_INFO("Shortest distance (weights) from Node"<<sourceNode << " to Node"<<destinationNode<<" equals " << d[destinationNode]);
186
187 /*
188 //PRINTING
189 NS_LOG_INFO ("distances and parents:");
190 graph_traits < graph_t >::vertex_iterator vi, vend;
191
192 for (boost::tie(vi, vend) = vertices(g); vi != vend; ++vi)
193 {
194 NS_LOG_INFO("distance(" << name[*vi] << ") = " << d[*vi] << ", ");
195 NS_LOG_INFO("parent(" << name[*vi] << ") = " << name[p[*vi]] << std::endl);
196 }
197 */
198
199 return d[destinationNode];
200 }
201
202 double
203 ComputeShortestDelayPath(uint32_t sourceNode, uint32_t destinationNode)
204 {
205 typedef adjacency_list < listS, vecS, undirectedS,
206 no_property, property < edge_weight_t, double > > graph_t;
207 typedef graph_traits < graph_t >::vertex_descriptor vertex_descriptor;
208 typedef graph_traits < graph_t >::edge_descriptor edge_descriptor;
209
210 //string name[] = {"0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51"};
211
212 double weights[] = {0.312, 10.786, 0.222, 1.035, 1.414, 1.24, 0.814, 19.532, 0.352, 4.593, 2.622, 0.207, 12.098, 13.941, 7.791, 38.946, 19.775, 0.345, 5.337, 0.276, 0.645, 19.787, 8.352, 1.578, 10.459, 5.005, 20.741, 4.737, 1.424, 2.091, 14.409, 7.13, 6.214, 6.437, 1.315, 1.176, 3.282, 2.478, 5.751, 3.235, 4.718, 1.817, 2.035, 0.327, 0.97, 5.176, 0.612, 5.725, 0.802, 6.007, 0.699, 3.655, 0.135, 3.286, 0.268, 0.268, 3.375, 2.708, 1.712, 2.329, 1.595, 3.201, 31.13, 1.643, 5.513, 0.437, 2.648, 0.124, 14.774, 42.03, 28.338, 0.359, 0.316, 0.779, 2.34, 2.529, 7.706, 9.827, 10.045, 0.092, 59.812, 26.19, 42.057, 14.125};
213
214 int num_arcs = sizeof(edge_array) / sizeof(Edge);
215
216 graph_t g(edge_array, edge_array + num_arcs, weights, m_numNodes);
217 property_map<graph_t, edge_weight_t>::type weightmap = get(edge_weight, g);
218
219 std::vector<vertex_descriptor> p(num_vertices(g));
220 std::vector<double> d(num_vertices(g));
221
222 vertex_descriptor s = vertex(static_cast<nodes>(sourceNode), g);
223
224 dijkstra_shortest_paths(g, s, predecessor_map(&p[0]).distance_map(&d[0]));
225
226 NS_LOG_INFO("Shortest distance (delay) from Node"<<sourceNode << " to Node"<<destinationNode<<" equals " << d[destinationNode]);
227
228 /*
229 //PRINTING
230 NS_LOG_INFO ("distances and parents:");
231 graph_traits < graph_t >::vertex_iterator vi, vend;
232
233 for (boost::tie(vi, vend) = vertices(g); vi != vend; ++vi)
234 {
235 NS_LOG_INFO("distance(" << name[*vi] << ") = " << d[*vi] << ", ");
236 NS_LOG_INFO("parent(" << name[*vi] << ") = " << name[p[*vi]] << std::endl);
237 }
238 */
239
240 return d[destinationNode];
241 }
242
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800243 // hijacker is more than an application. just disable all faces
244 static void
245 InstallHijacker (std::string prefix, Ptr<Node> node)
246 {
247 Ptr<Ccnx> ccnx = node->GetObject<Ccnx> ();
248 for (uint32_t i = 0; i < ccnx->GetNFaces (); i++)
249 {
250 Ptr<CcnxFace> face = ccnx->GetFace (i);
251 face->SetUp (false);
252 }
253 CcnxStackHelper::InstallRouteTo (prefix, node);
254 }
255
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800256 //We are creating 10 pairs of producer-hijacker and everybody else is a consumer
257 ApplicationContainer
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800258 AddApplications ()
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800259 {
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800260 ApplicationContainer apps;
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800261
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800262 list<string> prefixes;
263
264 // Create Producers/Hijackers
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800265 uint32_t pair = 0;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800266 for (list<tuple<uint32_t,uint32_t> >::iterator i = m_pairs.begin (); i != m_pairs.end (); i++)
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800267 {
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800268 uint32_t node1_num = i->get<0> ();
269 uint32_t node2_num = i->get<1> ();
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800270
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800271 cout << "Good: " << node1_num << ", bad: " << node2_num << "\n";
272
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800273 Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (node1_num));
274 Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (node2_num));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800275
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800276 // node1 legitimate producer
277 // node2 "fake" producer
278
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800279 string prefix = "/bh/" + lexical_cast<string> (pair);
280 pair ++;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800281
282 CcnxAppHelper legitimateProducerHelper ("ns3::CcnxProducer");
283 legitimateProducerHelper.SetPrefix (prefix);
284 apps.Add
285 (legitimateProducerHelper.Install (node1));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800286
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800287 // one more trick. Need to install route to hijacker (aka "hijacker announces itself as a legitimate producer")
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800288 CcnxStackHelper::InstallRouteTo (prefix, node1);
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800289 Simulator::Schedule (Seconds(10.0), Experiment::InstallHijacker, prefix, node2);
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800290
291 prefixes.push_back (prefix); // remember prefixes that consumers will be requesting
292 }
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800293
294 // Create Consumers
295 NodeContainer nodes = reader->GetNodes ();
296 for (NodeContainer::Iterator node = nodes.Begin (); node != nodes.End (); node++)
297 {
298 uint32_t namedId = lexical_cast<uint32_t> (Names::FindName (*node));
299 if (m_usedNodes.count (namedId) > 0)
300 continue;
301
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800302 CcnxAppHelper consumerHelper ("ns3::CcnxConsumerBatches");
Alexander Afanasyev94cebd02012-01-16 12:22:34 -0800303 consumerHelper.SetAttribute ("LifeTime", StringValue("100s"));
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800304 consumerHelper.SetAttribute ("Batches", StringValue("0s 10 6s 1 20s 1"));
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800305 BOOST_FOREACH (const string &prefix, prefixes)
306 {
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -0800307 consumerHelper.SetPrefix (prefix + "/" + lexical_cast<string> (namedId)); // make sure we're requesting unique prefixes... this was a huge bug before
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800308
309 ApplicationContainer consumer = consumerHelper.Install (*node);
310 apps.Add (consumer);
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800311 }
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800312
313 // break;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800314 }
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800315 return apps;
316 }
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800317};
318
319int
320main (int argc, char *argv[])
321{
322 cout << "Begin blackhole scenario\n";
323
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800324 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("100Mbps"));
325 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("2000"));
Alexander Afanasyev94cebd02012-01-16 12:22:34 -0800326 Config::SetDefault ("ns3::RttEstimator::InitialEstimation", StringValue ("0.5s"));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800327
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800328 Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("attributes.xml"));
329 Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
330 Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
331
332 uint32_t maxRuns = 1;
333 uint32_t startRun = 0;
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800334 CommandLine cmd;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800335 cmd.AddValue ("start", "Initial run number", startRun);
336 cmd.AddValue ("runs", "Number of runs", maxRuns);
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800337 cmd.Parse (argc, argv);
338
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800339 // ConfigStore config;
340 // config.ConfigureDefaults ();
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800341
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800342 Experiment experiment;
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800343 for (uint32_t run = startRun; run < startRun + maxRuns; run++)
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800344 {
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800345 Config::SetGlobal ("RngRun", IntegerValue (run));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800346 cout << "seed = " << SeedManager::GetSeed () << ", run = " << SeedManager::GetRun () << endl;
347
348 Experiment experiment;
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800349 // experiment.GenerateRandomPairs (1);
350 experiment.SetPair (run);
Ilya Moiseenko2c069b92012-01-13 18:39:28 -0800351 experiment.ComputeShortestWeightsPath(1,12);
352 experiment.ComputeShortestDelayPath(1,12);
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800353 cout << "Run " << run << endl;
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800354
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800355 string prefix = "blackhole-" + lexical_cast<string> (run) + "-";
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800356
357 experiment.ConfigureTopology ();
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800358 experiment.InstallCcnxStack (false);
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800359 ApplicationContainer apps = experiment.AddApplications ();
360
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800361 //tracing
362 CcnxTraceHelper traceHelper;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800363 // traceHelper.EnableRateL3All (prefix + "rate-trace.log");
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800364 traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumerBatches", prefix + "consumers-seqs.log");
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800365
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800366 // enable path weights some time from now (ensure that all faces are created)
367 Simulator::Schedule (Seconds (4.5), &CcnxTraceHelper::EnablePathWeights, &traceHelper, prefix + "weights.log");
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800368 std::cout << "Total " << apps.GetN () << " applications\n";
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800369
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800370 experiment.Run (Seconds(40.0));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800371 }
372
373 cout << "Finish blackhole scenario\n";
374 return 0;
375}