blob: 3901d7014f80808cd27b657464f57ec17b2eb1c6 [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
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800243 //We are creating 10 pairs of producer-hijacker and everybody else is a consumer
244 ApplicationContainer
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800245 AddApplications ()
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800246 {
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800247 ApplicationContainer apps;
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800248
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800249 list<string> prefixes;
250
251 // Create Producers/Hijackers
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800252 uint32_t pair = 0;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800253 for (list<tuple<uint32_t,uint32_t> >::iterator i = m_pairs.begin (); i != m_pairs.end (); i++)
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800254 {
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800255 uint32_t node1_num = i->get<0> ();
256 uint32_t node2_num = i->get<1> ();
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800257
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800258 cout << "Good: " << node1_num << ", bad: " << node2_num << "\n";
259
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800260 Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (node1_num));
261 Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (node2_num));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800262
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800263 // node1 legitimate producer
264 // node2 "fake" producer
265
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800266 string prefix = "/bh/" + lexical_cast<string> (pair);
267 pair ++;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800268
269 CcnxAppHelper legitimateProducerHelper ("ns3::CcnxProducer");
270 legitimateProducerHelper.SetPrefix (prefix);
271 apps.Add
272 (legitimateProducerHelper.Install (node1));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800273
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800274 CcnxAppHelper fakeProducerHelper ("ns3::CcnxHijacker");
275 fakeProducerHelper.SetPrefix (prefix);
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800276 ApplicationContainer hijacker = fakeProducerHelper.Install (node2);
277 apps.Add (hijacker);
278 hijacker.Start (Seconds(1.0));
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800279
280 // one more trick. Need to install route to hijacker (aka "hijacker announces itself as a legitimate producer")
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800281 CcnxStackHelper::InstallRouteTo (prefix, node1);
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800282 Simulator::Schedule (Seconds(1.0), CcnxStackHelper::InstallRouteTo, prefix, node2);
283 // CcnxStackHelper::InstallRouteTo (prefix, node2);
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800284
285 prefixes.push_back (prefix); // remember prefixes that consumers will be requesting
286 }
287
288 // All consumers request exactly 10 packets, to convert number interests packets to requested size:
289 // size = 1040 * (max_number_of_packets-1) / 1024 / 1024
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800290 // double requestSize = 1040.0 * (10 - 1) / 1024.0 / 1024.0;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800291
292 // Create Consumers
293 NodeContainer nodes = reader->GetNodes ();
294 for (NodeContainer::Iterator node = nodes.Begin (); node != nodes.End (); node++)
295 {
296 uint32_t namedId = lexical_cast<uint32_t> (Names::FindName (*node));
297 if (m_usedNodes.count (namedId) > 0)
298 continue;
299
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800300 CcnxAppHelper consumerHelper ("ns3::CcnxConsumerBatches");
Alexander Afanasyev94cebd02012-01-16 12:22:34 -0800301 consumerHelper.SetAttribute ("LifeTime", StringValue("100s"));
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -0800302 consumerHelper.SetAttribute ("Batches", StringValue("0s 10 0.5s 1 2s 1"));
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800303 BOOST_FOREACH (const string &prefix, prefixes)
304 {
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -0800305 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 -0800306
307 ApplicationContainer consumer = consumerHelper.Install (*node);
308 apps.Add (consumer);
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800309 }
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800310
311 // break;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800312 }
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800313 return apps;
314 }
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800315};
316
317int
318main (int argc, char *argv[])
319{
320 cout << "Begin blackhole scenario\n";
321
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800322 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("100Mbps"));
323 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("2000"));
Alexander Afanasyev94cebd02012-01-16 12:22:34 -0800324 Config::SetDefault ("ns3::RttEstimator::InitialEstimation", StringValue ("0.5s"));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800325
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800326 Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("attributes.xml"));
327 Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
328 Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
329
330 uint32_t maxRuns = 1;
331 uint32_t startRun = 0;
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800332 CommandLine cmd;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800333 cmd.AddValue ("start", "Initial run number", startRun);
334 cmd.AddValue ("runs", "Number of runs", maxRuns);
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800335 cmd.Parse (argc, argv);
336
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800337 // ConfigStore config;
338 // config.ConfigureDefaults ();
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800339
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800340 Experiment experiment;
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800341 for (uint32_t run = startRun; run < startRun + maxRuns; run++)
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800342 {
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800343 Config::SetGlobal ("RngRun", IntegerValue (run));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800344 cout << "seed = " << SeedManager::GetSeed () << ", run = " << SeedManager::GetRun () << endl;
345
346 Experiment experiment;
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800347 experiment.GenerateRandomPairs (1);
Ilya Moiseenko2c069b92012-01-13 18:39:28 -0800348 experiment.ComputeShortestWeightsPath(1,12);
349 experiment.ComputeShortestDelayPath(1,12);
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800350 cout << "Run " << run << endl;
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800351
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800352 string prefix = "blackhole-" + lexical_cast<string> (run) + "-";
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800353
354 experiment.ConfigureTopology ();
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800355 experiment.InstallCcnxStack (false);
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800356 ApplicationContainer apps = experiment.AddApplications ();
357
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800358 //tracing
359 CcnxTraceHelper traceHelper;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800360 // traceHelper.EnableRateL3All (prefix + "rate-trace.log");
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800361 traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumerBatches", prefix + "consumers-seqs.log");
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800362
363 traceHelper.EnablePathWeights (prefix + "weights.log");
364 std::cout << "Total " << apps.GetN () << " applications\n";
365 for (ApplicationContainer::Iterator i = apps.Begin (); i != apps.End (); i++)
366 {
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -0800367 Simulator::Schedule (Seconds (0.45), &CcnxTraceHelper::WeightsConnect, &traceHelper, (*i)->GetNode (), *i);
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800368 }
369
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}