blob: 51a5fa0c9f6038b40a003e234009054595f7f5e1 [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
48void PrintTime ()
49{
50 cout << "Progress: " << Simulator::Now ().ToDouble (Time::S) << "s" << endl;
51
52 Simulator::Schedule (Seconds (1.0), PrintTime);
53}
54
55class Experiment
56{
57public:
Alexander Afanasyevc4f88282012-01-03 11:27:20 -080058 Experiment ()
59 : m_rand (0,52)
60 , reader ("/sprint")
61 { }
62
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -080063 void
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -080064 ConfigureCcnxTopology ()
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -080065 {
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -080066 Names::Clear ();
67
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -080068 string weights ("./src/NDNabstraction/examples/sprint-pops.weights");
69 string latencies ("./src/NDNabstraction/examples/sprint-pops.latencies");
70 string positions ("./src/NDNabstraction/examples/sprint-pops.positions");
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -080071
72 RocketfuelWeightsReader reader ("/sprint");
73
74 reader.SetFileName (positions);
75 reader.SetFileType (RocketfuelWeightsReader::POSITIONS);
76 reader.Read ();
77
78 reader.SetFileName (weights);
79 reader.SetFileType (RocketfuelWeightsReader::WEIGHTS);
80 reader.Read ();
81
82 reader.SetFileName (latencies);
83 reader.SetFileType (RocketfuelWeightsReader::LATENCIES);
84 reader.Read ();
85
86 reader.Commit ();
87 NS_ASSERT_MSG (reader.LinksSize () != 0, "Problems reading the topology file. Failing.");
88
89 NS_LOG_INFO("Nodes = " << reader.GetNodes ().GetN());
90 NS_LOG_INFO("Links = " << reader.LinksSize ());
91
92 // ------------------------------------------------------------
93 // -- Read topology data.
94 // --------------------------------------------
95
96 InternetStackHelper stack;
97 Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops");
98 stack.SetRoutingHelper (ipv4RoutingHelper);
99 stack.Install (reader.GetNodes ());
100
101 reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800102
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800103 // Install CCNx stack
104 NS_LOG_INFO ("Installing CCNx stack");
105 CcnxStackHelper ccnxHelper;
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800106 ccnxHelper.SetForwardingStrategy ("ns3::CcnxBestRouteStrategy");
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800107 ccnxHelper.EnableLimits (true, Seconds(0.1));
108 ccnxHelper.SetDefaultRoutes (false);
109 ccnxHelper.InstallAll ();
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800110 }
111
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800112 void
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800113 ConfigureRouting ()
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800114 {
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800115 CcnxStackHelper ccnxHelper;
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800116 // // Populate FIB based on IPv4 global routing controller
117 ccnxHelper.InstallFakeGlobalRoutes ();
118 ccnxHelper.InstallRoutesToAll ();
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800119 }
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800120
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800121 ApplicationContainer
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800122 AddCcnxRandomApplications (uint16_t numStreams)
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800123 {
124 map<uint32_t, set<uint32_t> > streams;
125 ApplicationContainer apps;
126
127 uint16_t createdStreams = 0;
128 uint16_t guard = 0;
129 while (createdStreams < numStreams && guard < (numeric_limits<uint16_t>::max ()-1))
130 {
131 guard ++;
132
133 uint32_t node1_num = m_rand.GetValue ();
134 uint32_t node2_num = m_rand.GetValue ();
135
136 if (node1_num == node2_num)
137 continue;
138
139 if (streams[node1_num].count (node2_num) > 0) // don't create duplicate streams
140 continue;
141
142 streams[node1_num].insert (node2_num);
143
144 Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (node1_num));
145 Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (node2_num));
146
147 CcnxAppHelper consumerHelper ("ns3::CcnxConsumer");
148 consumerHelper.SetPrefix ("/" + lexical_cast<string> (node2->GetId ()));
149 consumerHelper.SetAttribute ("MeanRate", StringValue ("2Mbps"));
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800150 consumerHelper.SetAttribute ("Size", StringValue ("1.983642578125")); //to make sure max seq # is 2000
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800151
152 CcnxAppHelper producerHelper ("ns3::CcnxProducer");
153 producerHelper.SetPrefix ("/" + lexical_cast<string> (node2->GetId ()));
154
155 apps.Add
156 (consumerHelper.Install (node1));
157
158 apps.Add
159 (producerHelper.Install (node2));
160
161 createdStreams ++;
162 }
163
164 return apps;
165 }
166
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800167 void
168 Run (const Time &finishTime)
169 {
170 cout << "Run Simulation.\n";
171 Simulator::Stop (finishTime);
172 // Simulator::Schedule (Seconds (1.0), PrintTime);
173 Simulator::Run ();
174 Simulator::Destroy ();
175 cout << "Done.\n";
176 }
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800177
178 UniformVariable m_rand;
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800179 RocketfuelWeightsReader reader;
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800180};
181
182
183int
184main (int argc, char *argv[])
185{
186 cout << "Begin congestion-pop scenario\n";
187
188 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
189 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
190
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800191 uint32_t maxRuns = 1;
192 uint32_t startRun = 0;
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800193 CommandLine cmd;
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800194 cmd.AddValue ("start", "Initial run number", startRun);
195 cmd.AddValue ("runs", "Number of runs", maxRuns);
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800196 cmd.Parse (argc, argv);
197
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800198 for (uint32_t run = startRun; run < startRun + maxRuns; run++)
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800199 {
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800200 Config::SetGlobal ("RngRun", IntegerValue (run));
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800201 cout << "seed = " << SeedManager::GetSeed () << ", run = " << SeedManager::GetRun () << endl;
202
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800203 Experiment experiment;
204 cout << "Run " << run << endl;
205
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800206 experiment.ConfigureCcnxTopology ();
207 ApplicationContainer apps = experiment.AddCcnxRandomApplications (20);
208 experiment.ConfigureRouting ();
209
210 string prefix = "run-" + lexical_cast<string> (run) + "-";
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800211
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800212 ofstream of_nodes ((prefix + "apps.log").c_str ());
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800213 for (uint32_t i = 0; i < apps.GetN () / 2; i++)
214 {
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800215 of_nodes << "From " << apps.Get (i*2)->GetNode ()->GetId ()
216 << " to " << apps.Get (i*2 + 1)->GetNode ()->GetId ();
217 of_nodes << "\n";
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800218 }
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800219 of_nodes.close ();
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800220
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800221 CcnxTraceHelper traceHelper;
222 traceHelper.EnableRateL3All (prefix + "rate-trace.log");
223 traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumer", prefix + "consumers-seqs.log");
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800224
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800225 experiment.Run (Seconds (200.0));
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800226 }
227
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800228 // cout << "Finish congestion-pop scenario\n";
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800229 return 0;
230}