Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -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" |
| 29 | #include "ns3/internet-module.h" |
| 30 | #include "ns3/applications-module.h" |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 31 | #include "ns3/config-store.h" |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 32 | |
| 33 | #include <iostream> |
| 34 | #include <sstream> |
| 35 | #include <map> |
| 36 | #include <list> |
| 37 | #include <set> |
| 38 | #include "ns3/rocketfuel-topology-reader.h" |
| 39 | |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 40 | #include "../helper/tracers/ipv4-seqs-app-tracer.h" |
| 41 | |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 42 | #include <boost/lexical_cast.hpp> |
| 43 | #include <boost/foreach.hpp> |
| 44 | |
| 45 | using namespace ns3; |
| 46 | using namespace std; |
| 47 | using namespace boost; |
| 48 | |
| 49 | NS_LOG_COMPONENT_DEFINE ("Scenario"); |
| 50 | |
| 51 | void PrintTime () |
| 52 | { |
| 53 | cout << "Progress: " << Simulator::Now ().ToDouble (Time::S) << "s" << endl; |
| 54 | |
| 55 | Simulator::Schedule (Seconds (1.0), PrintTime); |
| 56 | } |
| 57 | |
| 58 | class Experiment |
| 59 | { |
| 60 | public: |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 61 | Experiment () |
| 62 | : m_rand (0,52) |
| 63 | , reader ("/sprint") |
| 64 | { } |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 65 | |
| 66 | void |
| 67 | ConfigureIpv4Topology () |
| 68 | { |
| 69 | Names::Clear (); |
| 70 | |
| 71 | string weights ("./src/NDNabstraction/examples/sprint-pops.weights"); |
| 72 | string latencies ("./src/NDNabstraction/examples/sprint-pops.latencies"); |
| 73 | string positions ("./src/NDNabstraction/examples/sprint-pops.positions"); |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 74 | |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 75 | reader.SetFileName (positions); |
| 76 | reader.SetFileType (RocketfuelWeightsReader::POSITIONS); |
| 77 | reader.Read (); |
| 78 | |
| 79 | reader.SetFileName (weights); |
| 80 | reader.SetFileType (RocketfuelWeightsReader::WEIGHTS); |
| 81 | reader.Read (); |
| 82 | |
| 83 | reader.SetFileName (latencies); |
| 84 | reader.SetFileType (RocketfuelWeightsReader::LATENCIES); |
| 85 | reader.Read (); |
| 86 | |
| 87 | reader.Commit (); |
| 88 | NS_ASSERT_MSG (reader.LinksSize () != 0, "Problems reading the topology file. Failing."); |
| 89 | |
| 90 | NS_LOG_INFO("Nodes = " << reader.GetNodes ().GetN()); |
| 91 | NS_LOG_INFO("Links = " << reader.LinksSize ()); |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 92 | |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 93 | InternetStackHelper stack; |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 94 | stack.Install (reader.GetNodes ()); |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 95 | reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0")); |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 96 | } |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 97 | |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 98 | void |
| 99 | ConfigureRouting () |
| 100 | { |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 101 | Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
| 102 | |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 103 | // m_rand = UniformVariable (0, reader.GetNodes ().GetN()); |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 104 | } |
| 105 | |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 106 | ApplicationContainer |
| 107 | AddTcpRandomApplications (uint16_t numStreams) |
| 108 | { |
| 109 | map<uint32_t, set<uint32_t> > streams; |
| 110 | ApplicationContainer apps; |
| 111 | |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 112 | const static uint32_t base_port = 10; |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 113 | uint16_t createdStreams = 0; |
| 114 | uint16_t guard = 0; |
| 115 | while (createdStreams < numStreams && guard < (numeric_limits<uint16_t>::max ()-1)) |
| 116 | { |
| 117 | guard ++; |
| 118 | |
| 119 | uint32_t node1_num = m_rand.GetValue (); |
| 120 | uint32_t node2_num = m_rand.GetValue (); |
| 121 | |
| 122 | if (node1_num == node2_num) |
| 123 | continue; |
| 124 | |
| 125 | if (streams[node1_num].count (node2_num) > 0) // don't create duplicate streams |
| 126 | continue; |
| 127 | |
| 128 | streams[node1_num].insert (node2_num); |
| 129 | |
| 130 | Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (node1_num)); |
| 131 | Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (node2_num)); |
| 132 | |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 133 | Ptr<Ipv4> ipv4 = node1->GetObject<Ipv4> (); |
| 134 | // ipv4->GetAddress (0, 0); |
| 135 | |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 136 | // to make sure we don't reuse the same port numbers for different flows, just make all port numbers unique |
| 137 | PacketSinkHelper consumerHelper ("ns3::TcpSocketFactory", |
| 138 | InetSocketAddress (Ipv4Address::GetAny (), base_port + createdStreams)); |
| 139 | |
| 140 | BulkSendHelper producerHelper ("ns3::TcpSocketFactory", |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 141 | InetSocketAddress (ipv4->GetAddress (1, 0).GetLocal (), base_port + createdStreams)); |
| 142 | // cout << "SendTo: " << ipv4->GetAddress (1, 0).GetLocal () << endl; |
| 143 | producerHelper.SetAttribute ("MaxBytes", UintegerValue (2081040)); // equal to 2001 ccnx packets |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 144 | |
| 145 | apps.Add |
| 146 | (consumerHelper.Install (node1)); |
| 147 | |
| 148 | apps.Add |
| 149 | (producerHelper.Install (node2)); |
| 150 | |
| 151 | createdStreams ++; |
| 152 | } |
| 153 | |
| 154 | return apps; |
| 155 | } |
| 156 | |
| 157 | void |
| 158 | Run (const Time &finishTime) |
| 159 | { |
| 160 | cout << "Run Simulation.\n"; |
| 161 | Simulator::Stop (finishTime); |
| 162 | // Simulator::Schedule (Seconds (1.0), PrintTime); |
| 163 | Simulator::Run (); |
| 164 | Simulator::Destroy (); |
| 165 | cout << "Done.\n"; |
| 166 | } |
| 167 | |
| 168 | UniformVariable m_rand; |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 169 | RocketfuelWeightsReader reader; |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 170 | }; |
| 171 | |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 172 | int |
| 173 | main (int argc, char *argv[]) |
| 174 | { |
| 175 | cout << "Begin congestion-pop scenario\n"; |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 176 | Packet::EnableChecking(); |
| 177 | Packet::EnablePrinting(); |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 178 | |
| 179 | Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps")); |
| 180 | Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20")); |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 181 | Config::SetDefault ("ns3::TcpSocket::SegmentSize", StringValue ("1040")); |
| 182 | |
| 183 | Config::SetDefault ("ns3::BulkSendApplication::SendSize", StringValue ("1040")); |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 184 | |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 185 | // Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("attributes.xml")); |
| 186 | // Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save")); |
| 187 | // Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml")); |
| 188 | |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 189 | uint32_t maxRuns = 1; |
| 190 | uint32_t startRun = 0; |
| 191 | CommandLine cmd; |
| 192 | cmd.AddValue ("start", "Initial run number", startRun); |
| 193 | cmd.AddValue ("runs", "Number of runs", maxRuns); |
| 194 | cmd.Parse (argc, argv); |
| 195 | |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 196 | // ConfigStore config; |
| 197 | // config.ConfigureDefaults (); |
| 198 | |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 199 | for (uint32_t run = startRun; run < startRun + maxRuns; run++) |
| 200 | { |
| 201 | Config::SetGlobal ("RngRun", IntegerValue (run)); |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 202 | cout << "seed = " << SeedManager::GetSeed () << ", run = " << SeedManager::GetRun () << endl; |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 203 | |
| 204 | Experiment experiment; |
| 205 | cout << "Run " << run << endl; |
| 206 | |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 207 | experiment.ConfigureIpv4Topology (); |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 208 | ApplicationContainer apps = experiment.AddTcpRandomApplications (20); |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 209 | experiment.ConfigureRouting (); |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 210 | |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 211 | string prefix = "run-tcp-" + lexical_cast<string> (run) + "-"; |
| 212 | |
| 213 | ofstream of_nodes ((prefix + "apps.log").c_str ()); |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 214 | for (uint32_t i = 0; i < apps.GetN () / 2; i++) |
| 215 | { |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 216 | of_nodes << "From " << apps.Get (i*2)->GetNode ()->GetId () |
| 217 | << " to " << apps.Get (i*2 + 1)->GetNode ()->GetId (); |
| 218 | of_nodes << "\n"; |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 219 | } |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 220 | |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 221 | CcnxTraceHelper traceHelper; |
| 222 | traceHelper.EnableIpv4SeqsAppAll (prefix + "consumers-seqs.log"); |
| 223 | |
| 224 | // config.ConfigureAttributes (); |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 225 | |
| 226 | experiment.Run (Seconds (200.0)); |
| 227 | } |
| 228 | |
| 229 | // cout << "Finish congestion-pop scenario\n"; |
| 230 | return 0; |
| 231 | } |