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