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 |
| 66 | 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] | 67 | { |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame^] | 68 | uint32_t node1_num = i->get<0> (); |
| 69 | uint32_t node2_num = i->get<1> (); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 70 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame^] | 71 | Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (node1_num)); |
| 72 | Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (node2_num)); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 73 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame^] | 74 | // node1 legitimate producer |
| 75 | // node2 "fake" producer |
| 76 | |
| 77 | string prefix = "/" + lexical_cast<string> (node1->GetId ()); |
| 78 | |
| 79 | CcnxAppHelper legitimateProducerHelper ("ns3::CcnxProducer"); |
| 80 | legitimateProducerHelper.SetPrefix (prefix); |
| 81 | apps.Add |
| 82 | (legitimateProducerHelper.Install (node1)); |
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 | CcnxAppHelper fakeProducerHelper ("ns3::CcnxHijacker"); |
| 85 | fakeProducerHelper.SetPrefix (prefix); |
| 86 | apps.Add |
| 87 | (fakeProducerHelper.Install (node2)); |
| 88 | |
| 89 | // one more trick. Need to install route to hijacker (aka "hijacker announces itself as a legitimate producer") |
| 90 | CcnxStackHelper::InstallRouteTo (prefix, node2); |
| 91 | |
| 92 | prefixes.push_back (prefix); // remember prefixes that consumers will be requesting |
| 93 | } |
| 94 | |
| 95 | // All consumers request exactly 10 packets, to convert number interests packets to requested size: |
| 96 | // size = 1040 * (max_number_of_packets-1) / 1024 / 1024 |
| 97 | double requestSize = 1040.0 * (10 - 1) / 1024.0 / 1024.0; |
| 98 | |
| 99 | // Create Consumers |
| 100 | NodeContainer nodes = reader->GetNodes (); |
| 101 | for (NodeContainer::Iterator node = nodes.Begin (); node != nodes.End (); node++) |
| 102 | { |
| 103 | uint32_t namedId = lexical_cast<uint32_t> (Names::FindName (*node)); |
| 104 | if (m_usedNodes.count (namedId) > 0) |
| 105 | continue; |
| 106 | |
| 107 | CcnxAppHelper consumerHelper ("ns3::CcnxConsumerCbr"); |
| 108 | BOOST_FOREACH (const string &prefix, prefixes) |
| 109 | { |
| 110 | consumerHelper.SetPrefix (prefix); |
| 111 | consumerHelper.SetAttribute ("MeanRate", StringValue ("8Kbps")); // this is about 1 interest a second |
| 112 | consumerHelper.SetAttribute ("Size", DoubleValue(requestSize)); |
| 113 | |
| 114 | apps.Add |
| 115 | (consumerHelper.Install (*node)); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 116 | } |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame^] | 117 | } |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 118 | return apps; |
| 119 | } |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | int |
| 123 | main (int argc, char *argv[]) |
| 124 | { |
| 125 | cout << "Begin blackhole scenario\n"; |
| 126 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame^] | 127 | Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("100Mbps")); |
| 128 | Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("2000")); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 129 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame^] | 130 | Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("attributes.xml")); |
| 131 | Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save")); |
| 132 | Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml")); |
| 133 | |
| 134 | uint32_t maxRuns = 1; |
| 135 | uint32_t startRun = 0; |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 136 | CommandLine cmd; |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame^] | 137 | cmd.AddValue ("start", "Initial run number", startRun); |
| 138 | cmd.AddValue ("runs", "Number of runs", maxRuns); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 139 | cmd.Parse (argc, argv); |
| 140 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame^] | 141 | // ConfigStore config; |
| 142 | // config.ConfigureDefaults (); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 143 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame^] | 144 | Experiment experiment; |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 145 | for (uint32_t i = 0; i < 80; i++) |
| 146 | { |
| 147 | Config::SetGlobal ("RngRun", IntegerValue (i)); |
| 148 | cout << "seed = " << SeedManager::GetSeed () << ", run = " << SeedManager::GetRun () << endl; |
| 149 | |
| 150 | Experiment experiment; |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame^] | 151 | experiment.GenerateRandomPairs (10); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 152 | cout << "Run " << i << endl; |
| 153 | |
| 154 | string prefix = "run-" + lexical_cast<string> (i) + "-"; |
| 155 | |
| 156 | experiment.ConfigureTopology (); |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame^] | 157 | experiment.InstallCcnxStack (); |
| 158 | ApplicationContainer apps = experiment.AddApplications (); |
| 159 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 160 | //tracing |
| 161 | CcnxTraceHelper traceHelper; |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame^] | 162 | // traceHelper.EnableRateL3All (prefix + "rate-trace.log"); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 163 | traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumer", prefix + "consumers-seqs.log"); |
| 164 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame^] | 165 | experiment.Run (Seconds(20.0)); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | cout << "Finish blackhole scenario\n"; |
| 169 | return 0; |
| 170 | } |