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 ())); |
| 129 | consumerHelper.SetAttribute ("Size", StringValue ("100.0")); |
| 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 | |
| 148 | // uint32_t streamId = 0; |
| 149 | // const static uint32_t base_port = 10; |
| 150 | // for (list<tuple<uint32_t,uint32_t> >::iterator i = m_pairs.begin (); i != m_pairs.end (); i++) |
| 151 | // { |
| 152 | // uint32_t node1_num = i->get<0> (); |
| 153 | // uint32_t node2_num = i->get<1> (); |
| 154 | |
| 155 | // Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (node2_num)); |
| 156 | // Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (node1_num)); |
| 157 | |
| 158 | // Ptr<Ipv4> ipv4 = node1->GetObject<Ipv4> (); |
| 159 | // // ipv4->GetAddress (0, 0); |
| 160 | |
| 161 | // // to make sure we don't reuse the same port numbers for different flows, just make all port numbers unique |
| 162 | // PacketSinkHelper consumerHelper ("ns3::TcpSocketFactory", |
| 163 | // InetSocketAddress (Ipv4Address::GetAny (), base_port + streamId)); |
| 164 | |
| 165 | // BulkSendHelper producerHelper ("ns3::TcpSocketFactory", |
| 166 | // InetSocketAddress (ipv4->GetAddress (1, 0).GetLocal (), base_port + streamId)); |
| 167 | // // cout << "SendTo: " << ipv4->GetAddress (1, 0).GetLocal () << endl; |
| 168 | // producerHelper.SetAttribute ("MaxBytes", UintegerValue (2081040)); // equal to 2001 ccnx packets |
| 169 | |
| 170 | // apps.Add |
| 171 | // (consumerHelper.Install (node1)); |
| 172 | |
| 173 | // apps.Add |
| 174 | // (producerHelper.Install (node2)); |
| 175 | |
| 176 | // streamId++; |
| 177 | // } |
| 178 | |
| 179 | return apps; |
| 180 | } |
| 181 | |
| 182 | void |
| 183 | Run (const Time &finishTime) |
| 184 | { |
| 185 | cout << "Run Simulation.\n"; |
| 186 | Simulator::Stop (finishTime); |
| 187 | Simulator::Schedule (Seconds (5.0), PrintTime); |
| 188 | Simulator::Run (); |
| 189 | Simulator::Destroy (); |
| 190 | cout << "Done.\n"; |
| 191 | } |
| 192 | }; |
| 193 | |
| 194 | |
| 195 | int |
| 196 | main (int argc, char *argv[]) |
| 197 | { |
| 198 | cout << "Begin congestion-pop scenario\n"; |
| 199 | |
| 200 | Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps")); |
| 201 | // Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("60")); |
| 202 | Config::SetDefault ("ns3::TcpSocket::SegmentSize", StringValue ("1040")); |
| 203 | |
| 204 | Config::SetDefault ("ns3::BulkSendApplication::SendSize", StringValue ("1040")); |
| 205 | |
| 206 | Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("attributes.xml")); |
| 207 | Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save")); |
| 208 | Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml")); |
| 209 | |
| 210 | CommandLine cmd; |
| 211 | cmd.Parse (argc, argv); |
| 212 | |
| 213 | // ConfigStore config; |
| 214 | // config.ConfigureDefaults (); |
| 215 | |
| 216 | Experiment experiment; |
| 217 | string prefix = "congestion-zoom-"; |
| 218 | |
| 219 | cout << "NDN experiment\n"; |
| 220 | // NDN |
| 221 | { |
| 222 | experiment.ConfigureTopology (); |
| 223 | experiment.InstallCcnxStack (); |
| 224 | ApplicationContainer apps = experiment.AddCcnxApplications (); |
| 225 | |
| 226 | // for (uint32_t i = 0; i < apps.GetN () / 2; i++) |
| 227 | // { |
| 228 | // apps.Get (i*2)->SetStartTime (Seconds (1+i)); |
| 229 | // apps.Get (i*2 + 1)->SetStartTime (Seconds (1+i)); |
| 230 | // } |
| 231 | |
| 232 | CcnxTraceHelper traceHelper; |
| 233 | traceHelper.EnableRateL3All (prefix + "rate-trace.log"); |
| 234 | // traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumerCbr", prefix + "consumers-seqs.log"); |
| 235 | traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumerWindow", prefix + "consumers-seqs.log"); |
| 236 | traceHelper.EnableWindowsAll (prefix + "windows.log"); |
| 237 | |
| 238 | // config.ConfigureAttributes (); |
| 239 | experiment.Run (Seconds (50.0)); |
| 240 | // experiment.reader->SavePositions ("pos.log"); |
| 241 | } |
| 242 | |
| 243 | // cout << "TCP experiment\n"; |
| 244 | // // TCP |
| 245 | // { |
| 246 | // experiment.ConfigureTopology (); |
| 247 | // experiment.InstallIpStack (); |
| 248 | // ApplicationContainer apps = experiment.AddTcpApplications (); |
| 249 | |
| 250 | // CcnxTraceHelper traceHelper; |
| 251 | // traceHelper.EnableIpv4SeqsAppAll (prefix + "tcp-consumers-seqs.log"); |
| 252 | // traceHelper.EnableWindowsTcpAll (prefix + "tcp-windows.log"); |
| 253 | |
| 254 | // for (uint32_t i = 0; i < apps.GetN () / 2; i++) |
| 255 | // { |
| 256 | // apps.Get (i*2)->SetStartTime (Seconds (1+i)); |
| 257 | |
| 258 | // apps.Get (i*2 + 1)->SetStartTime (Seconds (1+i)); |
| 259 | |
| 260 | // // cout << "Node: " << apps.Get (i*2 + 1)->GetNode ()->GetId () << "\n"; |
| 261 | // // care only about BulkSender |
| 262 | // Simulator::Schedule (Seconds (1+i+0.01), |
| 263 | // &CcnxTraceHelper::TcpConnect, &traceHelper, apps.Get (i*2)->GetNode ()); |
| 264 | |
| 265 | // Simulator::Schedule (Seconds (1+i+0.01), |
| 266 | // &CcnxTraceHelper::TcpConnect, &traceHelper, apps.Get (i*2 + 1)->GetNode ()); |
| 267 | // } |
| 268 | |
| 269 | // experiment.Run (Seconds (50.0)); |
| 270 | // } |
| 271 | |
| 272 | return 0; |
| 273 | } |