blob: 0c658605f7100fb4076b99d51e05cdc70831ba11 [file] [log] [blame]
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -08001/* -*- 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"
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -080029#include "ns3/internet-module.h"
30#include "ns3/applications-module.h"
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -080031
32#include <iostream>
33#include <sstream>
34#include <map>
35#include <list>
36#include <set>
37#include "ns3/rocketfuel-topology-reader.h"
38
39#include <boost/lexical_cast.hpp>
40#include <boost/foreach.hpp>
41
42using namespace ns3;
43using namespace std;
44using namespace boost;
45
46NS_LOG_COMPONENT_DEFINE ("Scenario");
47
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -080048// void PrintTime ()
49// {
50// cout << "Progress: " << Simulator::Now ().ToDouble (Time::S) << "s" << endl;
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -080051
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -080052// Simulator::Schedule (Seconds (1.0), PrintTime);
53// }
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -080054
55class Experiment
56{
57public:
Alexander Afanasyevc4f88282012-01-03 11:27:20 -080058 Experiment ()
59 : m_rand (0,52)
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -080060 , reader (0)
Alexander Afanasyevc4f88282012-01-03 11:27:20 -080061 { }
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -080062
63 ~Experiment ()
64 {
65 if (reader != 0) delete reader;
66 }
67
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -080068 void
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -080069 ConfigureTopology ()
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -080070 {
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -080071 Names::Clear ();
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -080072 cout << "Configure Topology\n";
73 if (reader != 0) delete reader;
74 reader = new RocketfuelWeightsReader ("/sprint");
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -080075
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -080076 string weights ("./src/NDNabstraction/examples/sprint-pops.weights");
77 string latencies ("./src/NDNabstraction/examples/sprint-pops.latencies");
78 string positions ("./src/NDNabstraction/examples/sprint-pops.positions");
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -080079
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -080080 reader->SetFileName (positions);
81 reader->SetFileType (RocketfuelWeightsReader::POSITIONS);
82 reader->Read ();
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -080083
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -080084 reader->SetFileName (weights);
85 reader->SetFileType (RocketfuelWeightsReader::WEIGHTS);
86 reader->Read ();
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -080087
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -080088 reader->SetFileName (latencies);
89 reader->SetFileType (RocketfuelWeightsReader::LATENCIES);
90 reader->Read ();
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -080091
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -080092 reader->Commit ();
93 }
94
95 void InstallCcnxStack ()
96 {
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -080097 InternetStackHelper stack;
98 Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops");
99 stack.SetRoutingHelper (ipv4RoutingHelper);
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800100 stack.Install (reader->GetNodes ());
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800101
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800102 reader->AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800103
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800104 // Install CCNx stack
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800105 cout << "Installing CCNx stack\n";
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800106 CcnxStackHelper ccnxHelper;
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800107 ccnxHelper.SetForwardingStrategy ("ns3::CcnxBestRouteStrategy");
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800108 ccnxHelper.EnableLimits (true, Seconds(0.1));
109 ccnxHelper.SetDefaultRoutes (false);
110 ccnxHelper.InstallAll ();
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800111
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800112 // // Populate FIB based on IPv4 global routing controller
113 ccnxHelper.InstallFakeGlobalRoutes ();
114 ccnxHelper.InstallRoutesToAll ();
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800115 }
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800116
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800117 void InstallIpStack ()
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800118 {
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800119 InternetStackHelper stack;
120 stack.Install (reader->GetNodes ());
121 reader->AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
122
123 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
124 }
125
126 void
127 GenerateRandomPairs (uint16_t numStreams)
128 {
129 m_pairs.clear ();
130 // map<uint32_t, set<uint32_t> > streams;
131 set<uint32_t> usedNodes;
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800132
133 uint16_t createdStreams = 0;
134 uint16_t guard = 0;
135 while (createdStreams < numStreams && guard < (numeric_limits<uint16_t>::max ()-1))
136 {
137 guard ++;
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800138
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800139 uint32_t node1_num = m_rand.GetValue ();
140 uint32_t node2_num = m_rand.GetValue ();
141
142 if (node1_num == node2_num)
143 continue;
144
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800145 if (usedNodes.count (node1_num) > 0 ||
146 usedNodes.count (node2_num) > 0 )
147 {
148 continue; // don't reuse nodes
149 }
150
151 usedNodes.insert (node1_num);
152 usedNodes.insert (node2_num);
153
154 m_pairs.push_back (make_tuple (node1_num, node2_num));
155 createdStreams ++;
156 }
157 }
158
159 ApplicationContainer
160 AddCcnxApplications ()
161 {
162 ApplicationContainer apps;
163
164 for (list<tuple<uint32_t,uint32_t> >::iterator i = m_pairs.begin (); i != m_pairs.end (); i++)
165 {
166 uint32_t node1_num = i->get<0> ();
167 uint32_t node2_num = i->get<1> ();
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800168
169 Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (node1_num));
170 Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (node2_num));
171
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800172 CcnxAppHelper consumerHelper ("ns3::CcnxConsumerWindow");
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800173 consumerHelper.SetPrefix ("/" + lexical_cast<string> (node2->GetId ()));
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800174 // consumerHelper.SetAttribute ("MeanRate", StringValue ("2Mbps"));
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800175 consumerHelper.SetAttribute ("Size", StringValue ("1.983642578125")); //to make sure max seq # is 2000
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800176
177 CcnxAppHelper producerHelper ("ns3::CcnxProducer");
178 producerHelper.SetPrefix ("/" + lexical_cast<string> (node2->GetId ()));
179
180 apps.Add
181 (consumerHelper.Install (node1));
182
183 apps.Add
184 (producerHelper.Install (node2));
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800185 }
186
187 return apps;
188 }
189
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800190 ApplicationContainer
191 AddTcpApplications ()
192 {
193 ApplicationContainer apps;
194
195 uint32_t streamId = 0;
196 const static uint32_t base_port = 10;
197 for (list<tuple<uint32_t,uint32_t> >::iterator i = m_pairs.begin (); i != m_pairs.end (); i++)
198 {
199 uint32_t node1_num = i->get<0> ();
200 uint32_t node2_num = i->get<1> ();
201
202 Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (node2_num));
203 Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (node1_num));
204
205 Ptr<Ipv4> ipv4 = node1->GetObject<Ipv4> ();
206 // ipv4->GetAddress (0, 0);
207
208 // to make sure we don't reuse the same port numbers for different flows, just make all port numbers unique
209 PacketSinkHelper consumerHelper ("ns3::TcpSocketFactory",
210 InetSocketAddress (Ipv4Address::GetAny (), base_port + streamId));
211
212 BulkSendHelper producerHelper ("ns3::TcpSocketFactory",
213 InetSocketAddress (ipv4->GetAddress (1, 0).GetLocal (), base_port + streamId));
214 // cout << "SendTo: " << ipv4->GetAddress (1, 0).GetLocal () << endl;
215 producerHelper.SetAttribute ("MaxBytes", UintegerValue (2081040)); // equal to 2001 ccnx packets
216
217 apps.Add
218 (consumerHelper.Install (node1));
219
220 apps.Add
221 (producerHelper.Install (node2));
222
223 streamId++;
224 }
225
226 return apps;
227 }
228
229
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800230 void
231 Run (const Time &finishTime)
232 {
233 cout << "Run Simulation.\n";
234 Simulator::Stop (finishTime);
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800235 // Simulator::Schedule (Seconds (1.0), PrintTime);
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800236 Simulator::Run ();
237 Simulator::Destroy ();
238 cout << "Done.\n";
239 }
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800240
241 UniformVariable m_rand;
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800242 RocketfuelWeightsReader *reader;
243
244 list<tuple<uint32_t,uint32_t> > m_pairs;
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800245};
246
247
248int
249main (int argc, char *argv[])
250{
251 cout << "Begin congestion-pop scenario\n";
252
253 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800254 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("60"));
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800255 Config::SetDefault ("ns3::TcpSocket::SegmentSize", StringValue ("1040"));
256
257 Config::SetDefault ("ns3::BulkSendApplication::SendSize", StringValue ("1040"));
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800258
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800259 uint32_t maxRuns = 1;
260 uint32_t startRun = 0;
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800261 CommandLine cmd;
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800262 cmd.AddValue ("start", "Initial run number", startRun);
263 cmd.AddValue ("runs", "Number of runs", maxRuns);
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800264 cmd.Parse (argc, argv);
265
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800266 for (uint32_t run = startRun; run < startRun + maxRuns; run++)
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800267 {
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800268 Config::SetGlobal ("RngRun", IntegerValue (run));
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800269 cout << "seed = " << SeedManager::GetSeed () << ", run = " << SeedManager::GetRun () << endl;
270
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800271 Experiment experiment;
272 cout << "Run " << run << endl;
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800273 string prefix = "run-" + lexical_cast<string> (run) + "-";
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800274
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800275 experiment.GenerateRandomPairs (20);
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800276 ofstream of_nodes ((prefix + "apps.log").c_str ());
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800277 for (list<tuple<uint32_t,uint32_t> >::iterator i = experiment.m_pairs.begin (); i != experiment.m_pairs.end (); i++)
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800278 {
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800279 of_nodes << "From " << i->get<0> ()
280 << " to " << i->get<1> ();
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800281 of_nodes << "\n";
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800282 }
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800283 of_nodes.close ();
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800284
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800285 cout << "NDN experiment\n";
286 // NDN
287 {
288 experiment.ConfigureTopology ();
289 experiment.InstallCcnxStack ();
290 ApplicationContainer apps = experiment.AddCcnxApplications ();
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800291
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800292 for (uint32_t i = 0; i < apps.GetN () / 2; i++)
293 {
294 apps.Get (i*2)->SetStartTime (Seconds (i));
295 apps.Get (i*2 + 1)->SetStartTime (Seconds (i));
296 }
297
298 CcnxTraceHelper traceHelper;
299 // traceHelper.EnableRateL3All (prefix + "rate-trace.log");
300 // traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumerCbr", prefix + "consumers-seqs.log");
301 traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumerWindow", prefix + "consumers-seqs.log");
302
303 experiment.Run (Seconds (200.0));
304 }
305
306 cout << "TCP experiment\n";
307 // TCP
308 {
309 experiment.ConfigureTopology ();
310 experiment.InstallIpStack ();
311 ApplicationContainer apps = experiment.AddTcpApplications ();
312
313 for (uint32_t i = 0; i < apps.GetN () / 2; i++)
314 {
315 apps.Get (i*2)->SetStartTime (Seconds (i));
316 apps.Get (i*2 + 1)->SetStartTime (Seconds (i));
317 }
318
319 CcnxTraceHelper traceHelper;
320 traceHelper.EnableIpv4SeqsAppAll (prefix + "tcp-consumers-seqs.log");
321
322 experiment.Run (Seconds (200.0));
323 }
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800324 }
325
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800326 // cout << "Finish congestion-pop scenario\n";
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800327 return 0;
328}