blob: 9b8fcfc79e8b2411d5ab743beb6098f33f47697a [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 Afanasyevb7626842012-01-12 13:43:33 -0800258 Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (node1_num));
259 Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (node2_num));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800260
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800261 // node1 legitimate producer
262 // node2 "fake" producer
263
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800264 string prefix = "/bh/" + lexical_cast<string> (pair);
265 pair ++;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800266
267 CcnxAppHelper legitimateProducerHelper ("ns3::CcnxProducer");
268 legitimateProducerHelper.SetPrefix (prefix);
269 apps.Add
270 (legitimateProducerHelper.Install (node1));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800271
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800272 CcnxAppHelper fakeProducerHelper ("ns3::CcnxHijacker");
273 fakeProducerHelper.SetPrefix (prefix);
274 apps.Add
275 (fakeProducerHelper.Install (node2));
276
277 // one more trick. Need to install route to hijacker (aka "hijacker announces itself as a legitimate producer")
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800278 CcnxStackHelper::InstallRouteTo (prefix, node1);
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800279 CcnxStackHelper::InstallRouteTo (prefix, node2);
280
281 prefixes.push_back (prefix); // remember prefixes that consumers will be requesting
282 }
283
284 // All consumers request exactly 10 packets, to convert number interests packets to requested size:
285 // size = 1040 * (max_number_of_packets-1) / 1024 / 1024
286 double requestSize = 1040.0 * (10 - 1) / 1024.0 / 1024.0;
287
288 // Create Consumers
289 NodeContainer nodes = reader->GetNodes ();
290 for (NodeContainer::Iterator node = nodes.Begin (); node != nodes.End (); node++)
291 {
292 uint32_t namedId = lexical_cast<uint32_t> (Names::FindName (*node));
293 if (m_usedNodes.count (namedId) > 0)
294 continue;
295
296 CcnxAppHelper consumerHelper ("ns3::CcnxConsumerCbr");
297 BOOST_FOREACH (const string &prefix, prefixes)
298 {
299 consumerHelper.SetPrefix (prefix);
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800300 consumerHelper.SetAttribute ("MeanRate", StringValue ("1000Kbps")); // this is about 1 interest a second
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800301 consumerHelper.SetAttribute ("Size", DoubleValue(requestSize));
302
303 apps.Add
304 (consumerHelper.Install (*node));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800305 }
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800306
307 // break;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800308 }
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800309 return apps;
310 }
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800311};
312
313int
314main (int argc, char *argv[])
315{
316 cout << "Begin blackhole scenario\n";
317
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800318 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("100Mbps"));
319 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("2000"));
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800320 Config::SetDefault ("ns3::RttEstimator::InitialEstimation", StringValue ("1s"));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800321
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800322 Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("attributes.xml"));
323 Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
324 Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
325
326 uint32_t maxRuns = 1;
327 uint32_t startRun = 0;
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800328 CommandLine cmd;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800329 cmd.AddValue ("start", "Initial run number", startRun);
330 cmd.AddValue ("runs", "Number of runs", maxRuns);
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800331 cmd.Parse (argc, argv);
332
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800333 // ConfigStore config;
334 // config.ConfigureDefaults ();
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800335
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800336 Experiment experiment;
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800337 for (uint32_t i = startRun; i < maxRuns; i++)
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800338 {
339 Config::SetGlobal ("RngRun", IntegerValue (i));
340 cout << "seed = " << SeedManager::GetSeed () << ", run = " << SeedManager::GetRun () << endl;
341
342 Experiment experiment;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800343 experiment.GenerateRandomPairs (10);
Ilya Moiseenko2c069b92012-01-13 18:39:28 -0800344 experiment.ComputeShortestWeightsPath(1,12);
345 experiment.ComputeShortestDelayPath(1,12);
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800346 cout << "Run " << i << endl;
347
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800348 string prefix = "blackhole-" + lexical_cast<string> (i) + "-";
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800349
350 experiment.ConfigureTopology ();
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800351 experiment.InstallCcnxStack (false);
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800352 ApplicationContainer apps = experiment.AddApplications ();
353
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800354 //tracing
355 CcnxTraceHelper traceHelper;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800356 // traceHelper.EnableRateL3All (prefix + "rate-trace.log");
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800357 traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumerCbr", prefix + "consumers-seqs.log");
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800358
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800359 experiment.Run (Seconds(40.0));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800360 }
361
362 cout << "Finish blackhole scenario\n";
363 return 0;
364}