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 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 53 | #include "base-experiment.h" |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 54 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 55 | class Experiment : public BaseExperiment |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 56 | { |
| 57 | public: |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 58 | // 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 Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 71 | //We are creating 10 pairs of producer-hijacker and everybody else is a consumer |
| 72 | ApplicationContainer |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 73 | AddApplications () |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 74 | { |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 75 | ApplicationContainer apps; |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 76 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 77 | list<string> prefixes; |
| 78 | |
| 79 | // Create Producers/Hijackers |
Alexander Afanasyev | 4d66de5 | 2012-01-13 00:06:01 -0800 | [diff] [blame] | 80 | uint32_t pair = 0; |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 81 | 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] | 82 | { |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 83 | uint32_t node1_num = i->get<0> (); |
| 84 | uint32_t node2_num = i->get<1> (); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 85 | |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 86 | cout << "Good: " << node1_num << ", bad: " << node2_num << "\n"; |
| 87 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 88 | 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 Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 90 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 91 | // node1 legitimate producer |
| 92 | // node2 "fake" producer |
| 93 | |
Alexander Afanasyev | 4d66de5 | 2012-01-13 00:06:01 -0800 | [diff] [blame] | 94 | string prefix = "/bh/" + lexical_cast<string> (pair); |
| 95 | pair ++; |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 96 | |
| 97 | CcnxAppHelper legitimateProducerHelper ("ns3::CcnxProducer"); |
| 98 | legitimateProducerHelper.SetPrefix (prefix); |
| 99 | apps.Add |
| 100 | (legitimateProducerHelper.Install (node1)); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 101 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 102 | // 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] | 103 | CcnxStackHelper::InstallRouteTo (prefix, node1); |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 104 | Simulator::Schedule (Seconds(10.0), Experiment::InstallHijacker, prefix, node2); |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 105 | |
| 106 | prefixes.push_back (prefix); // remember prefixes that consumers will be requesting |
| 107 | } |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 108 | |
| 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 Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 117 | CcnxAppHelper consumerHelper ("ns3::CcnxConsumerBatches"); |
Alexander Afanasyev | 94cebd0 | 2012-01-16 12:22:34 -0800 | [diff] [blame] | 118 | consumerHelper.SetAttribute ("LifeTime", StringValue("100s")); |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 119 | consumerHelper.SetAttribute ("Batches", StringValue("0s 10 6s 1 20s 1")); |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 120 | BOOST_FOREACH (const string &prefix, prefixes) |
| 121 | { |
Alexander Afanasyev | 6bff0df | 2012-01-19 17:51:52 -0800 | [diff] [blame] | 122 | 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] | 123 | |
| 124 | ApplicationContainer consumer = consumerHelper.Install (*node); |
| 125 | apps.Add (consumer); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 126 | } |
Alexander Afanasyev | 4d66de5 | 2012-01-13 00:06:01 -0800 | [diff] [blame] | 127 | |
| 128 | // break; |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 129 | } |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 130 | return apps; |
| 131 | } |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | int |
| 135 | main (int argc, char *argv[]) |
| 136 | { |
| 137 | cout << "Begin blackhole scenario\n"; |
| 138 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 139 | Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("100Mbps")); |
| 140 | Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("2000")); |
Alexander Afanasyev | 94cebd0 | 2012-01-16 12:22:34 -0800 | [diff] [blame] | 141 | Config::SetDefault ("ns3::RttEstimator::InitialEstimation", StringValue ("0.5s")); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 142 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 143 | 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 Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 149 | CommandLine cmd; |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 150 | cmd.AddValue ("start", "Initial run number", startRun); |
| 151 | cmd.AddValue ("runs", "Number of runs", maxRuns); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 152 | cmd.Parse (argc, argv); |
| 153 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 154 | // ConfigStore config; |
| 155 | // config.ConfigureDefaults (); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 156 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 157 | Experiment experiment; |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 158 | for (uint32_t run = startRun; run < startRun + maxRuns; run++) |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 159 | { |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 160 | Config::SetGlobal ("RngRun", IntegerValue (run)); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 161 | cout << "seed = " << SeedManager::GetSeed () << ", run = " << SeedManager::GetRun () << endl; |
| 162 | |
| 163 | Experiment experiment; |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 164 | // experiment.GenerateRandomPairs (1); |
| 165 | experiment.SetPair (run); |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 166 | cout << "Run " << run << endl; |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 167 | |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 168 | string prefix = "blackhole-" + lexical_cast<string> (run) + "-"; |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 169 | |
| 170 | experiment.ConfigureTopology (); |
Alexander Afanasyev | 4d66de5 | 2012-01-13 00:06:01 -0800 | [diff] [blame] | 171 | experiment.InstallCcnxStack (false); |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 172 | ApplicationContainer apps = experiment.AddApplications (); |
| 173 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 174 | //tracing |
| 175 | CcnxTraceHelper traceHelper; |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 176 | // traceHelper.EnableRateL3All (prefix + "rate-trace.log"); |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 177 | traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumerBatches", prefix + "consumers-seqs.log"); |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 178 | |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 179 | // 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 Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 181 | std::cout << "Total " << apps.GetN () << " applications\n"; |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 182 | |
Alexander Afanasyev | 4d66de5 | 2012-01-13 00:06:01 -0800 | [diff] [blame] | 183 | experiment.Run (Seconds(40.0)); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | cout << "Finish blackhole scenario\n"; |
| 187 | return 0; |
| 188 | } |