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 | |
| 39 | using namespace ns3; |
| 40 | using namespace std; |
| 41 | using namespace boost; |
| 42 | |
| 43 | NS_LOG_COMPONENT_DEFINE ("BlackholeSprint"); |
| 44 | |
| 45 | void PrintTime () |
| 46 | { |
| 47 | cout << "Progress: " << Simulator::Now ().ToDouble (Time::S) << "s" << endl; |
| 48 | |
| 49 | Simulator::Schedule (Seconds (1.0), PrintTime); |
| 50 | } |
| 51 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 52 | #include "base-experiment.h" |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 53 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 54 | class Experiment : public BaseExperiment |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 55 | { |
| 56 | public: |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 57 | //We are creating 10 pairs of producer-hijacker and everybody else is a consumer |
| 58 | ApplicationContainer |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 59 | AddApplications () |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 60 | { |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 61 | ApplicationContainer apps; |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 62 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 63 | list<string> prefixes; |
| 64 | |
| 65 | // Create Producers/Hijackers |
Alexander Afanasyev | 4d66de5 | 2012-01-13 00:06:01 -0800 | [diff] [blame^] | 66 | uint32_t pair = 0; |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 67 | 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] | 68 | { |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 69 | uint32_t node1_num = i->get<0> (); |
| 70 | uint32_t node2_num = i->get<1> (); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 71 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 72 | 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 Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 74 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 75 | // node1 legitimate producer |
| 76 | // node2 "fake" producer |
| 77 | |
Alexander Afanasyev | 4d66de5 | 2012-01-13 00:06:01 -0800 | [diff] [blame^] | 78 | string prefix = "/bh/" + lexical_cast<string> (pair); |
| 79 | pair ++; |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 80 | |
| 81 | CcnxAppHelper legitimateProducerHelper ("ns3::CcnxProducer"); |
| 82 | legitimateProducerHelper.SetPrefix (prefix); |
| 83 | apps.Add |
| 84 | (legitimateProducerHelper.Install (node1)); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 85 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 86 | 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 Afanasyev | 4d66de5 | 2012-01-13 00:06:01 -0800 | [diff] [blame^] | 92 | CcnxStackHelper::InstallRouteTo (prefix, node1); |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 93 | 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 Afanasyev | 4d66de5 | 2012-01-13 00:06:01 -0800 | [diff] [blame^] | 114 | consumerHelper.SetAttribute ("MeanRate", StringValue ("1000Kbps")); // this is about 1 interest a second |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 115 | consumerHelper.SetAttribute ("Size", DoubleValue(requestSize)); |
| 116 | |
| 117 | apps.Add |
| 118 | (consumerHelper.Install (*node)); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 119 | } |
Alexander Afanasyev | 4d66de5 | 2012-01-13 00:06:01 -0800 | [diff] [blame^] | 120 | |
| 121 | // break; |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 122 | } |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 123 | return apps; |
| 124 | } |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | int |
| 128 | main (int argc, char *argv[]) |
| 129 | { |
| 130 | cout << "Begin blackhole scenario\n"; |
| 131 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 132 | Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("100Mbps")); |
| 133 | Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("2000")); |
Alexander Afanasyev | 4d66de5 | 2012-01-13 00:06:01 -0800 | [diff] [blame^] | 134 | Config::SetDefault ("ns3::RttEstimator::InitialEstimation", StringValue ("1s")); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 135 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 136 | 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 Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 142 | CommandLine cmd; |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 143 | cmd.AddValue ("start", "Initial run number", startRun); |
| 144 | cmd.AddValue ("runs", "Number of runs", maxRuns); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 145 | cmd.Parse (argc, argv); |
| 146 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 147 | // ConfigStore config; |
| 148 | // config.ConfigureDefaults (); |
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 | Experiment experiment; |
Alexander Afanasyev | 4d66de5 | 2012-01-13 00:06:01 -0800 | [diff] [blame^] | 151 | for (uint32_t i = startRun; i < maxRuns; i++) |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 152 | { |
| 153 | Config::SetGlobal ("RngRun", IntegerValue (i)); |
| 154 | cout << "seed = " << SeedManager::GetSeed () << ", run = " << SeedManager::GetRun () << endl; |
| 155 | |
| 156 | Experiment experiment; |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 157 | experiment.GenerateRandomPairs (10); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 158 | cout << "Run " << i << endl; |
| 159 | |
Alexander Afanasyev | 4d66de5 | 2012-01-13 00:06:01 -0800 | [diff] [blame^] | 160 | string prefix = "blackhole-" + lexical_cast<string> (i) + "-"; |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 161 | |
| 162 | experiment.ConfigureTopology (); |
Alexander Afanasyev | 4d66de5 | 2012-01-13 00:06:01 -0800 | [diff] [blame^] | 163 | experiment.InstallCcnxStack (false); |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 164 | ApplicationContainer apps = experiment.AddApplications (); |
| 165 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 166 | //tracing |
| 167 | CcnxTraceHelper traceHelper; |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 168 | // traceHelper.EnableRateL3All (prefix + "rate-trace.log"); |
Alexander Afanasyev | 4d66de5 | 2012-01-13 00:06:01 -0800 | [diff] [blame^] | 169 | traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumerCbr", prefix + "consumers-seqs.log"); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 170 | |
Alexander Afanasyev | 4d66de5 | 2012-01-13 00:06:01 -0800 | [diff] [blame^] | 171 | experiment.Run (Seconds(40.0)); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | cout << "Finish blackhole scenario\n"; |
| 175 | return 0; |
| 176 | } |