blob: cf29d64fa21df9e43fc702427b26d09ea47e3487 [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:
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -080065 // hijacker is more than an application. just disable all faces
66 static void
67 InstallHijacker (std::string prefix, Ptr<Node> node)
68 {
69 Ptr<Ccnx> ccnx = node->GetObject<Ccnx> ();
70 for (uint32_t i = 0; i < ccnx->GetNFaces (); i++)
71 {
72 Ptr<CcnxFace> face = ccnx->GetFace (i);
73 face->SetUp (false);
74 }
75 CcnxStackHelper::InstallRouteTo (prefix, node);
76 }
77
Ilya Moiseenko2063c882012-01-11 19:59:32 -080078 //We are creating 10 pairs of producer-hijacker and everybody else is a consumer
79 ApplicationContainer
Alexander Afanasyevb7626842012-01-12 13:43:33 -080080 AddApplications ()
Ilya Moiseenko2063c882012-01-11 19:59:32 -080081 {
Ilya Moiseenko2063c882012-01-11 19:59:32 -080082 ApplicationContainer apps;
Ilya Moiseenko2063c882012-01-11 19:59:32 -080083
Alexander Afanasyevb7626842012-01-12 13:43:33 -080084 list<string> prefixes;
85
86 // Create Producers/Hijackers
Alexander Afanasyev4d66de52012-01-13 00:06:01 -080087 uint32_t pair = 0;
Alexander Afanasyevb7626842012-01-12 13:43:33 -080088 for (list<tuple<uint32_t,uint32_t> >::iterator i = m_pairs.begin (); i != m_pairs.end (); i++)
Ilya Moiseenko2063c882012-01-11 19:59:32 -080089 {
Alexander Afanasyevb7626842012-01-12 13:43:33 -080090 uint32_t node1_num = i->get<0> ();
91 uint32_t node2_num = i->get<1> ();
Ilya Moiseenko2063c882012-01-11 19:59:32 -080092
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080093 cout << "Good: " << node1_num << ", bad: " << node2_num << "\n";
94
Alexander Afanasyevb7626842012-01-12 13:43:33 -080095 Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (node1_num));
96 Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (node2_num));
Ilya Moiseenko2063c882012-01-11 19:59:32 -080097
Alexander Afanasyevb7626842012-01-12 13:43:33 -080098 // node1 legitimate producer
99 // node2 "fake" producer
100
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800101 string prefix = "/bh/" + lexical_cast<string> (pair);
102 pair ++;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800103
104 CcnxAppHelper legitimateProducerHelper ("ns3::CcnxProducer");
105 legitimateProducerHelper.SetPrefix (prefix);
106 apps.Add
107 (legitimateProducerHelper.Install (node1));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800108
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800109 // one more trick. Need to install route to hijacker (aka "hijacker announces itself as a legitimate producer")
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800110 CcnxStackHelper::InstallRouteTo (prefix, node1);
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800111 Simulator::Schedule (Seconds(10.0), Experiment::InstallHijacker, prefix, node2);
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800112
113 prefixes.push_back (prefix); // remember prefixes that consumers will be requesting
114 }
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800115
116 // Create Consumers
117 NodeContainer nodes = reader->GetNodes ();
118 for (NodeContainer::Iterator node = nodes.Begin (); node != nodes.End (); node++)
119 {
120 uint32_t namedId = lexical_cast<uint32_t> (Names::FindName (*node));
121 if (m_usedNodes.count (namedId) > 0)
122 continue;
123
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800124 CcnxAppHelper consumerHelper ("ns3::CcnxConsumerBatches");
Alexander Afanasyev94cebd02012-01-16 12:22:34 -0800125 consumerHelper.SetAttribute ("LifeTime", StringValue("100s"));
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800126 consumerHelper.SetAttribute ("Batches", StringValue("0s 10 6s 1 20s 1"));
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800127 BOOST_FOREACH (const string &prefix, prefixes)
128 {
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -0800129 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 -0800130
131 ApplicationContainer consumer = consumerHelper.Install (*node);
132 apps.Add (consumer);
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800133 }
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800134
135 // break;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800136 }
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800137 return apps;
138 }
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800139};
140
141int
142main (int argc, char *argv[])
143{
144 cout << "Begin blackhole scenario\n";
145
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800146 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("100Mbps"));
147 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("2000"));
Alexander Afanasyev94cebd02012-01-16 12:22:34 -0800148 Config::SetDefault ("ns3::RttEstimator::InitialEstimation", StringValue ("0.5s"));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800149
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800150 Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("attributes.xml"));
151 Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
152 Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
153
154 uint32_t maxRuns = 1;
155 uint32_t startRun = 0;
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800156 CommandLine cmd;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800157 cmd.AddValue ("start", "Initial run number", startRun);
158 cmd.AddValue ("runs", "Number of runs", maxRuns);
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800159 cmd.Parse (argc, argv);
160
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800161 // ConfigStore config;
162 // config.ConfigureDefaults ();
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800163
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800164 Experiment experiment;
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800165 for (uint32_t run = startRun; run < startRun + maxRuns; run++)
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800166 {
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800167 Config::SetGlobal ("RngRun", IntegerValue (run));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800168 cout << "seed = " << SeedManager::GetSeed () << ", run = " << SeedManager::GetRun () << endl;
169
170 Experiment experiment;
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800171 // experiment.GenerateRandomPairs (1);
172 experiment.SetPair (run);
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800173 cout << "Run " << run << endl;
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800174
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800175 string prefix = "blackhole-" + lexical_cast<string> (run) + "-";
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800176
177 experiment.ConfigureTopology ();
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800178 experiment.InstallCcnxStack (false);
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800179 ApplicationContainer apps = experiment.AddApplications ();
180
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800181 //tracing
182 CcnxTraceHelper traceHelper;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800183 // traceHelper.EnableRateL3All (prefix + "rate-trace.log");
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800184 traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumerBatches", prefix + "consumers-seqs.log");
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800185
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800186 // enable path weights some time from now (ensure that all faces are created)
187 Simulator::Schedule (Seconds (4.5), &CcnxTraceHelper::EnablePathWeights, &traceHelper, prefix + "weights.log");
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800188 std::cout << "Total " << apps.GetN () << " applications\n";
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800189
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800190 experiment.Run (Seconds(40.0));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800191 }
192
193 cout << "Finish blackhole scenario\n";
194 return 0;
195}