blob: c912ecbfe9081e2d9285b1e462e2077f6c2ff7d7 [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
Alexander Afanasyevb7626842012-01-12 13:43:33 -080053#include "base-experiment.h"
Ilya Moiseenko2063c882012-01-11 19:59:32 -080054
Alexander Afanasyevb7626842012-01-12 13:43:33 -080055class Experiment : public BaseExperiment
Ilya Moiseenko2063c882012-01-11 19:59:32 -080056{
57public:
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -080058 // hijacker is more than an application. just disable all faces
59 static void
60 InstallHijacker (std::string prefix, Ptr<Node> node)
61 {
62 Ptr<Ccnx> ccnx = node->GetObject<Ccnx> ();
63 for (uint32_t i = 0; i < ccnx->GetNFaces (); i++)
64 {
65 Ptr<CcnxFace> face = ccnx->GetFace (i);
66 face->SetUp (false);
67 }
68 CcnxStackHelper::InstallRouteTo (prefix, node);
69 }
70
Ilya Moiseenko2063c882012-01-11 19:59:32 -080071 //We are creating 10 pairs of producer-hijacker and everybody else is a consumer
72 ApplicationContainer
Alexander Afanasyevb7626842012-01-12 13:43:33 -080073 AddApplications ()
Ilya Moiseenko2063c882012-01-11 19:59:32 -080074 {
Ilya Moiseenko2063c882012-01-11 19:59:32 -080075 ApplicationContainer apps;
Ilya Moiseenko2063c882012-01-11 19:59:32 -080076
Alexander Afanasyevb7626842012-01-12 13:43:33 -080077 list<string> prefixes;
78
79 // Create Producers/Hijackers
Alexander Afanasyev4d66de52012-01-13 00:06:01 -080080 uint32_t pair = 0;
Alexander Afanasyevb7626842012-01-12 13:43:33 -080081 for (list<tuple<uint32_t,uint32_t> >::iterator i = m_pairs.begin (); i != m_pairs.end (); i++)
Ilya Moiseenko2063c882012-01-11 19:59:32 -080082 {
Alexander Afanasyevb7626842012-01-12 13:43:33 -080083 uint32_t node1_num = i->get<0> ();
84 uint32_t node2_num = i->get<1> ();
Ilya Moiseenko2063c882012-01-11 19:59:32 -080085
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080086 cout << "Good: " << node1_num << ", bad: " << node2_num << "\n";
87
Alexander Afanasyevb7626842012-01-12 13:43:33 -080088 Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (node1_num));
89 Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (node2_num));
Ilya Moiseenko2063c882012-01-11 19:59:32 -080090
Alexander Afanasyevb7626842012-01-12 13:43:33 -080091 // node1 legitimate producer
92 // node2 "fake" producer
93
Alexander Afanasyev4d66de52012-01-13 00:06:01 -080094 string prefix = "/bh/" + lexical_cast<string> (pair);
95 pair ++;
Alexander Afanasyevb7626842012-01-12 13:43:33 -080096
97 CcnxAppHelper legitimateProducerHelper ("ns3::CcnxProducer");
98 legitimateProducerHelper.SetPrefix (prefix);
99 apps.Add
100 (legitimateProducerHelper.Install (node1));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800101
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800102 // one more trick. Need to install route to hijacker (aka "hijacker announces itself as a legitimate producer")
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800103 CcnxStackHelper::InstallRouteTo (prefix, node1);
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800104 Simulator::Schedule (Seconds(10.0), Experiment::InstallHijacker, prefix, node2);
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800105
106 prefixes.push_back (prefix); // remember prefixes that consumers will be requesting
107 }
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800108
109 // Create Consumers
110 NodeContainer nodes = reader->GetNodes ();
111 for (NodeContainer::Iterator node = nodes.Begin (); node != nodes.End (); node++)
112 {
113 uint32_t namedId = lexical_cast<uint32_t> (Names::FindName (*node));
114 if (m_usedNodes.count (namedId) > 0)
115 continue;
116
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800117 CcnxAppHelper consumerHelper ("ns3::CcnxConsumerBatches");
Alexander Afanasyev94cebd02012-01-16 12:22:34 -0800118 consumerHelper.SetAttribute ("LifeTime", StringValue("100s"));
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800119 consumerHelper.SetAttribute ("Batches", StringValue("0s 10 6s 1 20s 1"));
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800120 BOOST_FOREACH (const string &prefix, prefixes)
121 {
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -0800122 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 -0800123
124 ApplicationContainer consumer = consumerHelper.Install (*node);
125 apps.Add (consumer);
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800126 }
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800127
128 // break;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800129 }
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800130 return apps;
131 }
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800132};
133
134int
135main (int argc, char *argv[])
136{
137 cout << "Begin blackhole scenario\n";
138
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800139 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("100Mbps"));
140 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("2000"));
Alexander Afanasyev94cebd02012-01-16 12:22:34 -0800141 Config::SetDefault ("ns3::RttEstimator::InitialEstimation", StringValue ("0.5s"));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800142
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800143 Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("attributes.xml"));
144 Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
145 Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
146
147 uint32_t maxRuns = 1;
148 uint32_t startRun = 0;
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800149 CommandLine cmd;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800150 cmd.AddValue ("start", "Initial run number", startRun);
151 cmd.AddValue ("runs", "Number of runs", maxRuns);
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800152 cmd.Parse (argc, argv);
153
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800154 // ConfigStore config;
155 // config.ConfigureDefaults ();
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800156
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800157 Experiment experiment;
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800158 for (uint32_t run = startRun; run < startRun + maxRuns; run++)
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800159 {
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800160 Config::SetGlobal ("RngRun", IntegerValue (run));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800161 cout << "seed = " << SeedManager::GetSeed () << ", run = " << SeedManager::GetRun () << endl;
162
163 Experiment experiment;
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800164 // experiment.GenerateRandomPairs (1);
165 experiment.SetPair (run);
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800166 cout << "Run " << run << endl;
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800167
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800168 string prefix = "blackhole-" + lexical_cast<string> (run) + "-";
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800169
170 experiment.ConfigureTopology ();
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800171 experiment.InstallCcnxStack (false);
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800172 ApplicationContainer apps = experiment.AddApplications ();
173
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800174 //tracing
175 CcnxTraceHelper traceHelper;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800176 // traceHelper.EnableRateL3All (prefix + "rate-trace.log");
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800177 traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumerBatches", prefix + "consumers-seqs.log");
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800178
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800179 // enable path weights some time from now (ensure that all faces are created)
180 Simulator::Schedule (Seconds (4.5), &CcnxTraceHelper::EnablePathWeights, &traceHelper, prefix + "weights.log");
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800181 std::cout << "Total " << apps.GetN () << " applications\n";
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800182
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800183 experiment.Run (Seconds(40.0));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800184 }
185
186 cout << "Finish blackhole scenario\n";
187 return 0;
188}