Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 1 | /* -*- 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 Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 29 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 30 | #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 Moiseenko | 2c069b9 | 2012-01-13 18:39:28 -0800 | [diff] [blame] | 39 | #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 Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 47 | using namespace ns3; |
| 48 | using namespace std; |
| 49 | using namespace boost; |
| 50 | |
| 51 | NS_LOG_COMPONENT_DEFINE ("BlackholeSprint"); |
| 52 | |
| 53 | void PrintTime () |
| 54 | { |
| 55 | cout << "Progress: " << Simulator::Now ().ToDouble (Time::S) << "s" << endl; |
| 56 | |
| 57 | Simulator::Schedule (Seconds (1.0), PrintTime); |
| 58 | } |
| 59 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 60 | #include "base-experiment.h" |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 61 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 62 | class Experiment : public BaseExperiment |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 63 | { |
| 64 | public: |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 65 | // 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 Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 78 | //We are creating 10 pairs of producer-hijacker and everybody else is a consumer |
| 79 | ApplicationContainer |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 80 | AddApplications () |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 81 | { |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 82 | ApplicationContainer apps; |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 83 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 84 | list<string> prefixes; |
| 85 | |
| 86 | // Create Producers/Hijackers |
Alexander Afanasyev | 4d66de5 | 2012-01-13 00:06:01 -0800 | [diff] [blame] | 87 | uint32_t pair = 0; |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 88 | for (list<tuple<uint32_t,uint32_t> >::iterator i = m_pairs.begin (); i != m_pairs.end (); i++) |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 89 | { |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 90 | uint32_t node1_num = i->get<0> (); |
| 91 | uint32_t node2_num = i->get<1> (); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 92 | |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 93 | cout << "Good: " << node1_num << ", bad: " << node2_num << "\n"; |
| 94 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 95 | 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 Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 97 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 98 | // node1 legitimate producer |
| 99 | // node2 "fake" producer |
| 100 | |
Alexander Afanasyev | 4d66de5 | 2012-01-13 00:06:01 -0800 | [diff] [blame] | 101 | string prefix = "/bh/" + lexical_cast<string> (pair); |
| 102 | pair ++; |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 103 | |
| 104 | CcnxAppHelper legitimateProducerHelper ("ns3::CcnxProducer"); |
| 105 | legitimateProducerHelper.SetPrefix (prefix); |
| 106 | apps.Add |
| 107 | (legitimateProducerHelper.Install (node1)); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 108 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 109 | // one more trick. Need to install route to hijacker (aka "hijacker announces itself as a legitimate producer") |
Alexander Afanasyev | 4d66de5 | 2012-01-13 00:06:01 -0800 | [diff] [blame] | 110 | CcnxStackHelper::InstallRouteTo (prefix, node1); |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 111 | Simulator::Schedule (Seconds(10.0), Experiment::InstallHijacker, prefix, node2); |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 112 | |
| 113 | prefixes.push_back (prefix); // remember prefixes that consumers will be requesting |
| 114 | } |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 115 | |
| 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 Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 124 | CcnxAppHelper consumerHelper ("ns3::CcnxConsumerBatches"); |
Alexander Afanasyev | 94cebd0 | 2012-01-16 12:22:34 -0800 | [diff] [blame] | 125 | consumerHelper.SetAttribute ("LifeTime", StringValue("100s")); |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 126 | consumerHelper.SetAttribute ("Batches", StringValue("0s 10 6s 1 20s 1")); |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 127 | BOOST_FOREACH (const string &prefix, prefixes) |
| 128 | { |
Alexander Afanasyev | 6bff0df | 2012-01-19 17:51:52 -0800 | [diff] [blame] | 129 | consumerHelper.SetPrefix (prefix + "/" + lexical_cast<string> (namedId)); // make sure we're requesting unique prefixes... this was a huge bug before |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 130 | |
| 131 | ApplicationContainer consumer = consumerHelper.Install (*node); |
| 132 | apps.Add (consumer); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 133 | } |
Alexander Afanasyev | 4d66de5 | 2012-01-13 00:06:01 -0800 | [diff] [blame] | 134 | |
| 135 | // break; |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 136 | } |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 137 | return apps; |
| 138 | } |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | int |
| 142 | main (int argc, char *argv[]) |
| 143 | { |
| 144 | cout << "Begin blackhole scenario\n"; |
| 145 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 146 | Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("100Mbps")); |
| 147 | Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("2000")); |
Alexander Afanasyev | 94cebd0 | 2012-01-16 12:22:34 -0800 | [diff] [blame] | 148 | Config::SetDefault ("ns3::RttEstimator::InitialEstimation", StringValue ("0.5s")); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 149 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 150 | 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 Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 156 | CommandLine cmd; |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 157 | cmd.AddValue ("start", "Initial run number", startRun); |
| 158 | cmd.AddValue ("runs", "Number of runs", maxRuns); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 159 | cmd.Parse (argc, argv); |
| 160 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 161 | // ConfigStore config; |
| 162 | // config.ConfigureDefaults (); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 163 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 164 | Experiment experiment; |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 165 | for (uint32_t run = startRun; run < startRun + maxRuns; run++) |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 166 | { |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 167 | Config::SetGlobal ("RngRun", IntegerValue (run)); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 168 | cout << "seed = " << SeedManager::GetSeed () << ", run = " << SeedManager::GetRun () << endl; |
| 169 | |
| 170 | Experiment experiment; |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 171 | // experiment.GenerateRandomPairs (1); |
| 172 | experiment.SetPair (run); |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 173 | cout << "Run " << run << endl; |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 174 | |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 175 | string prefix = "blackhole-" + lexical_cast<string> (run) + "-"; |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 176 | |
| 177 | experiment.ConfigureTopology (); |
Alexander Afanasyev | 4d66de5 | 2012-01-13 00:06:01 -0800 | [diff] [blame] | 178 | experiment.InstallCcnxStack (false); |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 179 | ApplicationContainer apps = experiment.AddApplications (); |
| 180 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 181 | //tracing |
| 182 | CcnxTraceHelper traceHelper; |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 183 | // traceHelper.EnableRateL3All (prefix + "rate-trace.log"); |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 184 | traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumerBatches", prefix + "consumers-seqs.log"); |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 185 | |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 186 | // 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 Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 188 | std::cout << "Total " << apps.GetN () << " applications\n"; |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 189 | |
Alexander Afanasyev | 4d66de5 | 2012-01-13 00:06:01 -0800 | [diff] [blame] | 190 | experiment.Run (Seconds(40.0)); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | cout << "Finish blackhole scenario\n"; |
| 194 | return 0; |
| 195 | } |