Alexander Afanasyev | ed78b63 | 2012-01-25 19:26:43 -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" |
| 31 | #include "ns3/config-store.h" |
| 32 | |
| 33 | #include <boost/lexical_cast.hpp> |
| 34 | #include <boost/foreach.hpp> |
| 35 | |
| 36 | using namespace ns3; |
| 37 | using namespace std; |
| 38 | using namespace boost; |
| 39 | |
| 40 | NS_LOG_COMPONENT_DEFINE ("Scenario"); |
| 41 | |
| 42 | // void PrintTime () |
| 43 | // { |
| 44 | // cout << "Progress: " << Simulator::Now ().ToDouble (Time::S) << "s" << endl; |
| 45 | |
| 46 | // Simulator::Schedule (Seconds (1.0), PrintTime); |
| 47 | // } |
| 48 | |
| 49 | #include "base-experiment.h" |
| 50 | |
| 51 | class Experiment |
| 52 | { |
| 53 | public: |
| 54 | AnnotatedTopologyReader *reader; |
| 55 | string prefix; |
| 56 | |
| 57 | Experiment () |
| 58 | : reader (0) |
| 59 | , prefix ("simple/") |
| 60 | { } |
| 61 | |
| 62 | void |
| 63 | ConfigureTopology () |
| 64 | { |
| 65 | Names::Clear (); |
| 66 | cout << "Configure Topology\n"; |
| 67 | if (reader != 0) delete reader; |
| 68 | reader = new AnnotatedTopologyReader (prefix); |
| 69 | |
| 70 | string input ("./src/NDNabstraction/examples/congestion-zoom.txt"); |
| 71 | |
| 72 | reader->SetFileName (input); |
| 73 | reader->Read (); |
| 74 | } |
| 75 | |
| 76 | void InstallCcnxStackImpl () |
| 77 | { |
| 78 | InternetStackHelper stack; |
| 79 | Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops"); |
| 80 | stack.SetRoutingHelper (ipv4RoutingHelper); |
| 81 | stack.Install (reader->GetNodes ()); |
| 82 | |
| 83 | reader->AssignIpv4Addresses (Ipv4Address ("10.0.0.0")); |
| 84 | |
| 85 | // Install CCNx stack |
| 86 | cout << "Installing CCNx stack\n"; |
| 87 | CcnxStackHelper ccnxHelper; |
| 88 | ccnxHelper.SetForwardingStrategy ("ns3::CcnxBestRouteStrategy"); |
| 89 | ccnxHelper.EnableLimits (true, Seconds(0.1)); |
| 90 | ccnxHelper.SetDefaultRoutes (false); |
| 91 | ccnxHelper.InstallAll (); |
| 92 | |
| 93 | reader->ApplyOspfMetric (); |
| 94 | } |
| 95 | |
| 96 | void InstallCcnxStack (bool installFIBs = true) |
| 97 | { |
| 98 | InstallCcnxStackImpl (); |
| 99 | |
| 100 | CcnxStackHelper ccnxHelper; |
| 101 | ccnxHelper.InstallFakeGlobalRoutes (); |
| 102 | if (installFIBs) |
| 103 | { |
| 104 | // // Populate FIB based on IPv4 global routing controller |
| 105 | ccnxHelper.InstallRoutesToAll (); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | void InstallIpStack () |
| 110 | { |
| 111 | InternetStackHelper stack; |
| 112 | stack.Install (reader->GetNodes ()); |
| 113 | reader->AssignIpv4Addresses (Ipv4Address ("10.0.0.0")); |
| 114 | reader->ApplyOspfMetric (); |
| 115 | |
| 116 | Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
| 117 | } |
| 118 | |
| 119 | ApplicationContainer |
| 120 | AddCcnxApplications () |
| 121 | { |
| 122 | ApplicationContainer apps; |
| 123 | |
| 124 | Ptr<Node> client = Names::Find<Node> (prefix, lexical_cast<string> ("client")); |
| 125 | Ptr<Node> server = Names::Find<Node> (prefix, lexical_cast<string> ("server")); |
| 126 | |
| 127 | CcnxAppHelper consumerHelper ("ns3::CcnxConsumerWindow"); |
| 128 | consumerHelper.SetPrefix ("/" + lexical_cast<string> (server->GetId ())); |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame^] | 129 | consumerHelper.SetAttribute ("Size", StringValue ("2.0")); |
Alexander Afanasyev | ed78b63 | 2012-01-25 19:26:43 -0800 | [diff] [blame] | 130 | |
| 131 | CcnxAppHelper producerHelper ("ns3::CcnxProducer"); |
| 132 | producerHelper.SetPrefix ("/" + lexical_cast<string> (server->GetId ())); |
| 133 | |
| 134 | apps.Add |
| 135 | (consumerHelper.Install (client)); |
| 136 | |
| 137 | apps.Add |
| 138 | (producerHelper.Install (server)); |
| 139 | |
| 140 | return apps; |
| 141 | } |
| 142 | |
| 143 | ApplicationContainer |
| 144 | AddTcpApplications () |
| 145 | { |
| 146 | ApplicationContainer apps; |
| 147 | |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame^] | 148 | Ptr<Node> client = Names::Find<Node> (prefix, lexical_cast<string> ("client")); |
| 149 | Ptr<Node> server = Names::Find<Node> (prefix, lexical_cast<string> ("server")); |
| 150 | |
| 151 | Ptr<Ipv4> ipv4 = client->GetObject<Ipv4> (); |
| 152 | |
| 153 | // to make sure we don't reuse the same port numbers for different flows, just make all port numbers unique |
| 154 | PacketSinkHelper consumerHelper ("ns3::TcpSocketFactory", |
| 155 | InetSocketAddress (Ipv4Address::GetAny (), 1024)); |
| 156 | |
| 157 | BulkSendHelper producerHelper ("ns3::TcpSocketFactory", |
| 158 | InetSocketAddress (ipv4->GetAddress (1, 0).GetLocal (), 1024)); |
| 159 | // cout << "SendTo: " << ipv4->GetAddress (1, 0).GetLocal () << endl; |
| 160 | producerHelper.SetAttribute ("MaxBytes", UintegerValue (2081040)); // equal to 2001 ccnx packets |
| 161 | |
| 162 | apps.Add |
| 163 | (consumerHelper.Install (client)); |
| 164 | |
| 165 | apps.Add |
| 166 | (producerHelper.Install (server)); |
| 167 | |
Alexander Afanasyev | ed78b63 | 2012-01-25 19:26:43 -0800 | [diff] [blame] | 168 | // uint32_t streamId = 0; |
| 169 | // const static uint32_t base_port = 10; |
| 170 | // for (list<tuple<uint32_t,uint32_t> >::iterator i = m_pairs.begin (); i != m_pairs.end (); i++) |
| 171 | // { |
| 172 | // uint32_t node1_num = i->get<0> (); |
| 173 | // uint32_t node2_num = i->get<1> (); |
| 174 | |
| 175 | // Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (node2_num)); |
| 176 | // Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (node1_num)); |
| 177 | |
| 178 | // Ptr<Ipv4> ipv4 = node1->GetObject<Ipv4> (); |
| 179 | // // ipv4->GetAddress (0, 0); |
| 180 | |
| 181 | // // to make sure we don't reuse the same port numbers for different flows, just make all port numbers unique |
| 182 | // PacketSinkHelper consumerHelper ("ns3::TcpSocketFactory", |
| 183 | // InetSocketAddress (Ipv4Address::GetAny (), base_port + streamId)); |
| 184 | |
| 185 | // BulkSendHelper producerHelper ("ns3::TcpSocketFactory", |
| 186 | // InetSocketAddress (ipv4->GetAddress (1, 0).GetLocal (), base_port + streamId)); |
| 187 | // // cout << "SendTo: " << ipv4->GetAddress (1, 0).GetLocal () << endl; |
| 188 | // producerHelper.SetAttribute ("MaxBytes", UintegerValue (2081040)); // equal to 2001 ccnx packets |
| 189 | |
| 190 | // apps.Add |
| 191 | // (consumerHelper.Install (node1)); |
| 192 | |
| 193 | // apps.Add |
| 194 | // (producerHelper.Install (node2)); |
| 195 | |
| 196 | // streamId++; |
| 197 | // } |
| 198 | |
| 199 | return apps; |
| 200 | } |
| 201 | |
| 202 | void |
| 203 | Run (const Time &finishTime) |
| 204 | { |
| 205 | cout << "Run Simulation.\n"; |
| 206 | Simulator::Stop (finishTime); |
| 207 | Simulator::Schedule (Seconds (5.0), PrintTime); |
| 208 | Simulator::Run (); |
| 209 | Simulator::Destroy (); |
| 210 | cout << "Done.\n"; |
| 211 | } |
| 212 | }; |
| 213 | |
| 214 | |
| 215 | int |
| 216 | main (int argc, char *argv[]) |
| 217 | { |
| 218 | cout << "Begin congestion-pop scenario\n"; |
| 219 | |
| 220 | Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps")); |
| 221 | // Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("60")); |
| 222 | Config::SetDefault ("ns3::TcpSocket::SegmentSize", StringValue ("1040")); |
| 223 | |
| 224 | Config::SetDefault ("ns3::BulkSendApplication::SendSize", StringValue ("1040")); |
| 225 | |
| 226 | Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("attributes.xml")); |
| 227 | Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save")); |
| 228 | Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml")); |
| 229 | |
| 230 | CommandLine cmd; |
| 231 | cmd.Parse (argc, argv); |
| 232 | |
| 233 | // ConfigStore config; |
| 234 | // config.ConfigureDefaults (); |
| 235 | |
| 236 | Experiment experiment; |
| 237 | string prefix = "congestion-zoom-"; |
| 238 | |
| 239 | cout << "NDN experiment\n"; |
| 240 | // NDN |
| 241 | { |
| 242 | experiment.ConfigureTopology (); |
| 243 | experiment.InstallCcnxStack (); |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame^] | 244 | experiment.AddCcnxApplications (); |
Alexander Afanasyev | ed78b63 | 2012-01-25 19:26:43 -0800 | [diff] [blame] | 245 | |
| 246 | // for (uint32_t i = 0; i < apps.GetN () / 2; i++) |
| 247 | // { |
| 248 | // apps.Get (i*2)->SetStartTime (Seconds (1+i)); |
| 249 | // apps.Get (i*2 + 1)->SetStartTime (Seconds (1+i)); |
| 250 | // } |
| 251 | |
| 252 | CcnxTraceHelper traceHelper; |
| 253 | traceHelper.EnableRateL3All (prefix + "rate-trace.log"); |
| 254 | // traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumerCbr", prefix + "consumers-seqs.log"); |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame^] | 255 | // traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumerWindow", prefix + "consumers-seqs.log"); |
| 256 | // traceHelper.EnableWindowsAll (prefix + "windows.log"); |
Alexander Afanasyev | ed78b63 | 2012-01-25 19:26:43 -0800 | [diff] [blame] | 257 | |
| 258 | // config.ConfigureAttributes (); |
| 259 | experiment.Run (Seconds (50.0)); |
| 260 | // experiment.reader->SavePositions ("pos.log"); |
| 261 | } |
| 262 | |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame^] | 263 | cout << "TCP experiment\n"; |
| 264 | // TCP |
| 265 | { |
| 266 | experiment.ConfigureTopology (); |
| 267 | experiment.InstallIpStack (); |
| 268 | experiment.AddTcpApplications (); |
Alexander Afanasyev | ed78b63 | 2012-01-25 19:26:43 -0800 | [diff] [blame] | 269 | |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame^] | 270 | CcnxTraceHelper traceHelper; |
| 271 | traceHelper.EnableIpv4RateL3All (prefix + "ipv4-rate-trace.log"); |
| 272 | // traceHelper.EnableIpv4SeqsAppAll (prefix + "tcp-consumers-seqs.log"); |
| 273 | // traceHelper.EnableWindowsTcpAll (prefix + "tcp-windows.log"); |
Alexander Afanasyev | ed78b63 | 2012-01-25 19:26:43 -0800 | [diff] [blame] | 274 | |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame^] | 275 | // for (uint32_t i = 0; i < apps.GetN () / 2; i++) |
| 276 | // { |
| 277 | // apps.Get (i*2)->SetStartTime (Seconds (1+i)); |
Alexander Afanasyev | ed78b63 | 2012-01-25 19:26:43 -0800 | [diff] [blame] | 278 | |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame^] | 279 | // apps.Get (i*2 + 1)->SetStartTime (Seconds (1+i)); |
Alexander Afanasyev | ed78b63 | 2012-01-25 19:26:43 -0800 | [diff] [blame] | 280 | |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame^] | 281 | // // cout << "Node: " << apps.Get (i*2 + 1)->GetNode ()->GetId () << "\n"; |
| 282 | // // care only about BulkSender |
| 283 | // Simulator::Schedule (Seconds (1+i+0.01), |
| 284 | // &CcnxTraceHelper::TcpConnect, &traceHelper, apps.Get (i*2)->GetNode ()); |
Alexander Afanasyev | ed78b63 | 2012-01-25 19:26:43 -0800 | [diff] [blame] | 285 | |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame^] | 286 | // Simulator::Schedule (Seconds (1+i+0.01), |
| 287 | // &CcnxTraceHelper::TcpConnect, &traceHelper, apps.Get (i*2 + 1)->GetNode ()); |
| 288 | // } |
Alexander Afanasyev | ed78b63 | 2012-01-25 19:26:43 -0800 | [diff] [blame] | 289 | |
Alexander Afanasyev | 7e71c75 | 2012-01-25 21:40:39 -0800 | [diff] [blame^] | 290 | experiment.Run (Seconds (50.0)); |
| 291 | } |
Alexander Afanasyev | ed78b63 | 2012-01-25 19:26:43 -0800 | [diff] [blame] | 292 | |
| 293 | return 0; |
| 294 | } |