blob: d826ce6b26bbd2e14a93182ce4425cb48dcbaf07 [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
39using namespace ns3;
40using namespace std;
41using namespace boost;
42
43NS_LOG_COMPONENT_DEFINE ("BlackholeSprint");
44
45void PrintTime ()
46{
47 cout << "Progress: " << Simulator::Now ().ToDouble (Time::S) << "s" << endl;
48
49 Simulator::Schedule (Seconds (1.0), PrintTime);
50}
51
Alexander Afanasyevb7626842012-01-12 13:43:33 -080052#include "base-experiment.h"
Ilya Moiseenko2063c882012-01-11 19:59:32 -080053
Alexander Afanasyevb7626842012-01-12 13:43:33 -080054class Experiment : public BaseExperiment
Ilya Moiseenko2063c882012-01-11 19:59:32 -080055{
56public:
Ilya Moiseenko2063c882012-01-11 19:59:32 -080057 //We are creating 10 pairs of producer-hijacker and everybody else is a consumer
58 ApplicationContainer
Alexander Afanasyevb7626842012-01-12 13:43:33 -080059 AddApplications ()
Ilya Moiseenko2063c882012-01-11 19:59:32 -080060 {
Ilya Moiseenko2063c882012-01-11 19:59:32 -080061 ApplicationContainer apps;
Ilya Moiseenko2063c882012-01-11 19:59:32 -080062
Alexander Afanasyevb7626842012-01-12 13:43:33 -080063 list<string> prefixes;
64
65 // Create Producers/Hijackers
Alexander Afanasyev4d66de52012-01-13 00:06:01 -080066 uint32_t pair = 0;
Alexander Afanasyevb7626842012-01-12 13:43:33 -080067 for (list<tuple<uint32_t,uint32_t> >::iterator i = m_pairs.begin (); i != m_pairs.end (); i++)
Ilya Moiseenko2063c882012-01-11 19:59:32 -080068 {
Alexander Afanasyevb7626842012-01-12 13:43:33 -080069 uint32_t node1_num = i->get<0> ();
70 uint32_t node2_num = i->get<1> ();
Ilya Moiseenko2063c882012-01-11 19:59:32 -080071
Alexander Afanasyevb7626842012-01-12 13:43:33 -080072 Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (node1_num));
73 Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (node2_num));
Ilya Moiseenko2063c882012-01-11 19:59:32 -080074
Alexander Afanasyevb7626842012-01-12 13:43:33 -080075 // node1 legitimate producer
76 // node2 "fake" producer
77
Alexander Afanasyev4d66de52012-01-13 00:06:01 -080078 string prefix = "/bh/" + lexical_cast<string> (pair);
79 pair ++;
Alexander Afanasyevb7626842012-01-12 13:43:33 -080080
81 CcnxAppHelper legitimateProducerHelper ("ns3::CcnxProducer");
82 legitimateProducerHelper.SetPrefix (prefix);
83 apps.Add
84 (legitimateProducerHelper.Install (node1));
Ilya Moiseenko2063c882012-01-11 19:59:32 -080085
Alexander Afanasyevb7626842012-01-12 13:43:33 -080086 CcnxAppHelper fakeProducerHelper ("ns3::CcnxHijacker");
87 fakeProducerHelper.SetPrefix (prefix);
88 apps.Add
89 (fakeProducerHelper.Install (node2));
90
91 // one more trick. Need to install route to hijacker (aka "hijacker announces itself as a legitimate producer")
Alexander Afanasyev4d66de52012-01-13 00:06:01 -080092 CcnxStackHelper::InstallRouteTo (prefix, node1);
Alexander Afanasyevb7626842012-01-12 13:43:33 -080093 CcnxStackHelper::InstallRouteTo (prefix, node2);
94
95 prefixes.push_back (prefix); // remember prefixes that consumers will be requesting
96 }
97
98 // All consumers request exactly 10 packets, to convert number interests packets to requested size:
99 // size = 1040 * (max_number_of_packets-1) / 1024 / 1024
100 double requestSize = 1040.0 * (10 - 1) / 1024.0 / 1024.0;
101
102 // Create Consumers
103 NodeContainer nodes = reader->GetNodes ();
104 for (NodeContainer::Iterator node = nodes.Begin (); node != nodes.End (); node++)
105 {
106 uint32_t namedId = lexical_cast<uint32_t> (Names::FindName (*node));
107 if (m_usedNodes.count (namedId) > 0)
108 continue;
109
110 CcnxAppHelper consumerHelper ("ns3::CcnxConsumerCbr");
111 BOOST_FOREACH (const string &prefix, prefixes)
112 {
113 consumerHelper.SetPrefix (prefix);
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800114 consumerHelper.SetAttribute ("MeanRate", StringValue ("1000Kbps")); // this is about 1 interest a second
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800115 consumerHelper.SetAttribute ("Size", DoubleValue(requestSize));
116
117 apps.Add
118 (consumerHelper.Install (*node));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800119 }
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800120
121 // break;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800122 }
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800123 return apps;
124 }
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800125};
126
127int
128main (int argc, char *argv[])
129{
130 cout << "Begin blackhole scenario\n";
131
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800132 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("100Mbps"));
133 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("2000"));
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800134 Config::SetDefault ("ns3::RttEstimator::InitialEstimation", StringValue ("1s"));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800135
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800136 Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("attributes.xml"));
137 Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
138 Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
139
140 uint32_t maxRuns = 1;
141 uint32_t startRun = 0;
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800142 CommandLine cmd;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800143 cmd.AddValue ("start", "Initial run number", startRun);
144 cmd.AddValue ("runs", "Number of runs", maxRuns);
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800145 cmd.Parse (argc, argv);
146
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800147 // ConfigStore config;
148 // config.ConfigureDefaults ();
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800149
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800150 Experiment experiment;
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800151 for (uint32_t i = startRun; i < maxRuns; i++)
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800152 {
153 Config::SetGlobal ("RngRun", IntegerValue (i));
154 cout << "seed = " << SeedManager::GetSeed () << ", run = " << SeedManager::GetRun () << endl;
155
156 Experiment experiment;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800157 experiment.GenerateRandomPairs (10);
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800158 cout << "Run " << i << endl;
159
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800160 string prefix = "blackhole-" + lexical_cast<string> (i) + "-";
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800161
162 experiment.ConfigureTopology ();
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800163 experiment.InstallCcnxStack (false);
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800164 ApplicationContainer apps = experiment.AddApplications ();
165
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800166 //tracing
167 CcnxTraceHelper traceHelper;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800168 // traceHelper.EnableRateL3All (prefix + "rate-trace.log");
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800169 traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumerCbr", prefix + "consumers-seqs.log");
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800170
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800171 experiment.Run (Seconds(40.0));
Ilya Moiseenko2063c882012-01-11 19:59:32 -0800172 }
173
174 cout << "Finish blackhole scenario\n";
175 return 0;
176}