blob: dfbbf048a82a51814c9ff81cf90720d2aab7ab44 [file] [log] [blame]
Ilya Moiseenko46bdc7c2012-01-09 14:44:15 -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"
29
30#include <iostream>
31#include <sstream>
32#include <map>
33#include <list>
34#include <set>
35#include "ns3/rocketfuel-topology-reader.h"
36
37#include <boost/lexical_cast.hpp>
38#include <boost/foreach.hpp>
39
40using namespace ns3;
41using namespace std;
42using namespace boost;
43
44NS_LOG_COMPONENT_DEFINE ("LinkFailureSprint");
45
46void PrintTime ()
47{
48 cout << "Progress: " << Simulator::Now ().ToDouble (Time::S) << "s" << endl;
49
50 Simulator::Schedule (Seconds (1.0), PrintTime);
51}
52
53
54class Experiment
55{
56public:
57 void
58 ConfigureTopology ()
59 {
60 string weights ("./src/NDNabstraction/examples/sprint-pops.weights");
61 string latencies ("./src/NDNabstraction/examples/sprint-pops.latencies");
62 string positions ("./src/NDNabstraction/examples/sprint-pops.positions");
63 string strategy ("ns3::CcnxBestRouteStrategy");
64 // string strategy ("ns3::CcnxFloodingStrategy");
65
66 RocketfuelWeightsReader reader ("/sprint");
67 m_reader = reader;
68
69 reader.SetFileName (positions);
70 reader.SetFileType (RocketfuelWeightsReader::POSITIONS);
71 reader.Read ();
72
73 reader.SetFileName (weights);
74 reader.SetFileType (RocketfuelWeightsReader::WEIGHTS);
75 reader.Read ();
76
77 reader.SetFileName (latencies);
78 reader.SetFileType (RocketfuelWeightsReader::LATENCIES);
79 reader.Read ();
80
81 reader.Commit ();
82 NS_ASSERT_MSG (reader.LinksSize () != 0, "Problems reading the topology file. Failing.");
83
84 NS_LOG_INFO("Nodes = " << reader.GetNodes ().GetN());
85 NS_LOG_INFO("Links = " << reader.LinksSize ());
86
87 // ------------------------------------------------------------
88 // -- Read topology data.
89 // --------------------------------------------
90
91 InternetStackHelper stack;
92 Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops");
93 stack.SetRoutingHelper (ipv4RoutingHelper);
94 stack.Install (reader.GetNodes ());
95
96 reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
97
98 // Install CCNx stack
99 NS_LOG_INFO ("Installing CCNx stack");
100 CcnxStackHelper ccnxHelper;
101 ccnxHelper.SetForwardingStrategy (strategy);
102 ccnxHelper.EnableLimits (true, Seconds(0.1));
103 ccnxHelper.SetDefaultRoutes (false);
104 ccnxHelper.InstallAll ();
105
106 // // Populate FIB based on IPv4 global routing controller
107 ccnxHelper.InstallFakeGlobalRoutes ();
108 ccnxHelper.InstallRoutesToAll ();
109
110 m_rand = UniformVariable (0, reader.GetNodes ().GetN());
111 }
112
113public:
114 void
115 Run (const Time &finishTime)
116 {
117 cout << "Run Simulation.\n";
118 Simulator::Stop (finishTime);
119 Simulator::Schedule (Seconds (1.0), PrintTime);
120 Simulator::Run ();
121 Simulator::Destroy ();
122 cout << "Done.\n";
123 }
124
125 //We are creating "everybody-to-everybody" usage pattern
126 ApplicationContainer
127 AddApplications()
128 {
129 ApplicationContainer apps;
130 for(int i =0; i<reader.GetNodes().GetN(); i++;)
131 {
132 Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (node1_num));
133 CcnxAppHelper producerHelper ("ns3::CcnxProducer");
134 producerHelper.SetPrefix ("/" + lexical_cast<string> (i));
135
136 apps.Add(producerHelper.Install (node1));
137
138 for(int j = 0; j<reader.GetNodes().GetN();j++)
139 {
140 if(i==j)
141 continue;
142
143 Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (node2_num));
144
145 CcnxAppHelper consumerHelper ("ns3::CcnxConsumer");
146 consumerHelper.SetPrefix ("/" + lexical_cast<string> (i));
147 consumerHelper.SetAttribute ("MeanRate", StringValue ("2Mbps"));
148 consumerHelper.SetAttribute ("Size", StringValue ("2"));
149
150 apps.Add(consumerHelper.Install (node2));
151 }
152 }
153 return apps;
154 }
155
156 ApplicationContainer
157 AddRandomApplications (uint16_t numStreams)
158 {
159 map<uint32_t, set<uint32_t> > streams;
160 ApplicationContainer apps;
161
162 uint16_t createdStreams = 0;
163 uint16_t guard = 0;
164 while (createdStreams < numStreams && guard < (numeric_limits<uint16_t>::max ()-1))
165 {
166 guard ++;
167
168 uint32_t node1_num = m_rand.GetValue ();
169 uint32_t node2_num = m_rand.GetValue ();
170
171 if (node1_num == node2_num)
172 continue;
173
174 if (streams[node1_num].count (node2_num) > 0) // don't create duplicate streams
175 continue;
176
177 streams[node1_num].insert (node2_num);
178
179 Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (node1_num));
180 Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (node2_num));
181
182 CcnxAppHelper consumerHelper ("ns3::CcnxConsumer");
183 consumerHelper.SetPrefix ("/" + lexical_cast<string> (node2->GetId ()));
184 consumerHelper.SetAttribute ("MeanRate", StringValue ("2Mbps"));
185 consumerHelper.SetAttribute ("Size", StringValue ("2"));
186
187 CcnxAppHelper producerHelper ("ns3::CcnxProducer");
188 producerHelper.SetPrefix ("/" + lexical_cast<string> (node2->GetId ()));
189
190 apps.Add
191 (consumerHelper.Install (node1));
192
193 apps.Add
194 (producerHelper.Install (node2));
195
196 createdStreams ++;
197 }
198
199 return apps;
200 }
201
202
203 UniformVariable m_rand;
204
205private:
206 RocketfuelWeightsReader m_reader;
207};
208
209int
210main (int argc, char *argv[])
211{
212 cout << "Begin congestion-pop scenario\n";
213
214 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
215 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
216
217 Time finishTime = Seconds (20.0);
218
219 CommandLine cmd;
220 cmd.AddValue ("finish", "Finish time", finishTime);
221 cmd.Parse (argc, argv);
222
223 Experiment experiment;
224
225 for (uint32_t i = 0; i < 100; i++)
226 {
227
228 experiment.ConfigureTopology ();
229 ApplicationContainer apps = experiment.AddApplications ();
230
231 for (uint32_t i = 0; i < apps.GetN () / 2; i++)
232 {
233 cout << "From " << apps.Get (i*2)->GetNode ()->GetId ()
234 << " to " << apps.Get (i*2 + 1)->GetNode ()->GetId ();
235 cout << "\n";
236 }
237
238 CcnxTraceHelper traceHelper;
239 // traceHelper.EnableAggregateAppAll ("ns3::CcnxConsumer");
240 // traceHelper.EnableAggregateAppAll ("ns3::CcnxProducer");
241 // traceHelper.EnableAggregateL3All ();
242 // traceHelper.SetL3TraceFile ("trace-l3.log");
243 // traceHelper.SetAppTraceFile ("trace-app.log");
244 // traceHelper.EnableRateL3All ("rate-trace.log");
245 traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumer", "consumers-seqs.log");
246
247 experiment.Run (finishTime);
248 }
249
250 cout << "Finish congestion-pop scenario\n";
251 return 0;
252}