blob: 4b3c05265489386bbac4ff9bb3bd9a165ff28fdb [file] [log] [blame]
Alexander Afanasyevb7626842012-01-12 13:43:33 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2011,2012 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: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 */
20
21#ifndef BASE_EXPERIMENT_H
22#define BASE_EXPERIMENT_H
23
24#include "ns3/rocketfuel-topology-reader.h"
25
Alexander Afanasyev6c678382012-01-22 16:15:41 -080026void PrintTime ()
27{
28 cout << "Progress: " << Simulator::Now ().ToDouble (Time::S) << "s" << endl;
29
Alexander Afanasyevf410daf2012-01-22 17:18:41 -080030 Simulator::Schedule (Seconds (5.0), PrintTime);
Alexander Afanasyev6c678382012-01-22 16:15:41 -080031}
32
Alexander Afanasyevb7626842012-01-12 13:43:33 -080033class BaseExperiment
34{
35public:
36 BaseExperiment ()
37 : m_rand (0,52)
38 , reader (0)
Ilya Moiseenko2c069b92012-01-13 18:39:28 -080039 , m_numNodes (52)
Alexander Afanasyevb7626842012-01-12 13:43:33 -080040 { }
41
42 ~BaseExperiment ()
43 {
44 if (reader != 0) delete reader;
45 }
46
47 void
48 ConfigureTopology ()
49 {
50 Names::Clear ();
51 cout << "Configure Topology\n";
52 if (reader != 0) delete reader;
53 reader = new RocketfuelWeightsReader ("/sprint");
54
55 string weights ("./src/NDNabstraction/examples/sprint-pops.weights");
56 string latencies ("./src/NDNabstraction/examples/sprint-pops.latencies");
57 string positions ("./src/NDNabstraction/examples/sprint-pops.positions");
58
59 reader->SetFileName (positions);
60 reader->SetFileType (RocketfuelWeightsReader::POSITIONS);
61 reader->Read ();
62
63 reader->SetFileName (weights);
64 reader->SetFileType (RocketfuelWeightsReader::WEIGHTS);
65 reader->Read ();
66
67 reader->SetFileName (latencies);
68 reader->SetFileType (RocketfuelWeightsReader::LATENCIES);
69 reader->Read ();
70
71 reader->Commit ();
72 }
73
Alexander Afanasyev812f7ab2012-01-24 11:08:04 -080074 void InstallCcnxStackImpl ()
Alexander Afanasyevb7626842012-01-12 13:43:33 -080075 {
76 InternetStackHelper stack;
77 Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops");
78 stack.SetRoutingHelper (ipv4RoutingHelper);
79 stack.Install (reader->GetNodes ());
80
81 reader->AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
82
83 // Install CCNx stack
84 cout << "Installing CCNx stack\n";
85 CcnxStackHelper ccnxHelper;
86 ccnxHelper.SetForwardingStrategy ("ns3::CcnxBestRouteStrategy");
87 ccnxHelper.EnableLimits (true, Seconds(0.1));
88 ccnxHelper.SetDefaultRoutes (false);
89 ccnxHelper.InstallAll ();
90
Alexander Afanasyevef056552012-01-20 16:19:12 -080091 reader->ApplyOspfMetric ();
Alexander Afanasyev812f7ab2012-01-24 11:08:04 -080092 }
93
94 void InstallCcnxStack (bool installFIBs = true)
95 {
96 InstallCcnxStackImpl ();
Alexander Afanasyevef056552012-01-20 16:19:12 -080097
Alexander Afanasyev812f7ab2012-01-24 11:08:04 -080098 CcnxStackHelper ccnxHelper;
Alexander Afanasyevb7626842012-01-12 13:43:33 -080099 ccnxHelper.InstallFakeGlobalRoutes ();
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800100 if (installFIBs)
101 {
102 // // Populate FIB based on IPv4 global routing controller
103 ccnxHelper.InstallRoutesToAll ();
104 }
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800105 }
106
107 void InstallIpStack ()
108 {
109 InternetStackHelper stack;
110 stack.Install (reader->GetNodes ());
111 reader->AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800112 reader->ApplyOspfMetric ();
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800113
114 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
115 }
116
117 void
118 GenerateRandomPairs (uint16_t numStreams)
119 {
120 m_pairs.clear ();
121 // map<uint32_t, set<uint32_t> > streams;
122 m_usedNodes.clear ();
123
124 uint16_t createdStreams = 0;
125 uint16_t guard = 0;
126 while (createdStreams < numStreams && guard < (numeric_limits<uint16_t>::max ()-1))
127 {
128 guard ++;
129
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800130 uint32_t node1_num = m_rand.GetValue (); //43;//
131 uint32_t node2_num = m_rand.GetValue (); //38;//
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800132
133 if (node1_num == node2_num)
134 continue;
135
136 if (m_usedNodes.count (node1_num) > 0 ||
137 m_usedNodes.count (node2_num) > 0 )
138 {
139 continue; // don't reuse nodes
140 }
141
142 m_usedNodes.insert (node1_num);
143 m_usedNodes.insert (node2_num);
144
145 m_pairs.push_back (make_tuple (node1_num, node2_num));
146 createdStreams ++;
147 }
148 }
149
150 void
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800151 SetPair (uint32_t pairId)
152 {
153 m_pairs.clear ();
154 m_usedNodes.clear ();
155
156 uint32_t i = 0;
157 for (uint32_t node1_num = 0; node1_num < 52; node1_num++)
158 for (uint32_t node2_num = 0; node2_num < 52; node2_num++)
159 {
160 if (node1_num == node2_num) continue;
161
162 // std::cout << "i = " << i << ", pairId = " << pairId << "\n";
163 if (i++ != pairId) continue;
164
165 m_usedNodes.insert (node1_num);
166 m_usedNodes.insert (node2_num);
167
168 m_pairs.push_back (make_tuple (node1_num, node2_num));
169 return;
170 }
171 }
172
173 void
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800174 Run (const Time &finishTime)
175 {
176 cout << "Run Simulation.\n";
177 Simulator::Stop (finishTime);
Alexander Afanasyev1e9348f2012-01-22 17:15:54 -0800178 Simulator::Schedule (Seconds (5.0), PrintTime);
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800179 Simulator::Run ();
180 Simulator::Destroy ();
181 cout << "Done.\n";
182 }
183
184 UniformVariable m_rand;
185 RocketfuelWeightsReader *reader;
186
187 list<tuple<uint32_t,uint32_t> > m_pairs;
188 set<uint32_t> m_usedNodes;
Ilya Moiseenko2c069b92012-01-13 18:39:28 -0800189 const int m_numNodes;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800190};
191
192#endif