blob: ef20ab4710e375e61241a2ad75cd0c7876ffe218 [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
30 Simulator::Schedule (Seconds (1.0), PrintTime);
31}
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 Afanasyev4d66de52012-01-13 00:06:01 -080074 void InstallCcnxStack (bool installFIBs = true)
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 ();
92
Alexander Afanasyevb7626842012-01-12 13:43:33 -080093 ccnxHelper.InstallFakeGlobalRoutes ();
Alexander Afanasyev4d66de52012-01-13 00:06:01 -080094 if (installFIBs)
95 {
96 // // Populate FIB based on IPv4 global routing controller
97 ccnxHelper.InstallRoutesToAll ();
98 }
Alexander Afanasyevb7626842012-01-12 13:43:33 -080099 }
100
101 void InstallIpStack ()
102 {
103 InternetStackHelper stack;
104 stack.Install (reader->GetNodes ());
105 reader->AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800106 reader->ApplyOspfMetric ();
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800107
108 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
109 }
110
111 void
112 GenerateRandomPairs (uint16_t numStreams)
113 {
114 m_pairs.clear ();
115 // map<uint32_t, set<uint32_t> > streams;
116 m_usedNodes.clear ();
117
118 uint16_t createdStreams = 0;
119 uint16_t guard = 0;
120 while (createdStreams < numStreams && guard < (numeric_limits<uint16_t>::max ()-1))
121 {
122 guard ++;
123
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800124 uint32_t node1_num = m_rand.GetValue (); //43;//
125 uint32_t node2_num = m_rand.GetValue (); //38;//
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800126
127 if (node1_num == node2_num)
128 continue;
129
130 if (m_usedNodes.count (node1_num) > 0 ||
131 m_usedNodes.count (node2_num) > 0 )
132 {
133 continue; // don't reuse nodes
134 }
135
136 m_usedNodes.insert (node1_num);
137 m_usedNodes.insert (node2_num);
138
139 m_pairs.push_back (make_tuple (node1_num, node2_num));
140 createdStreams ++;
141 }
142 }
143
144 void
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800145 SetPair (uint32_t pairId)
146 {
147 m_pairs.clear ();
148 m_usedNodes.clear ();
149
150 uint32_t i = 0;
151 for (uint32_t node1_num = 0; node1_num < 52; node1_num++)
152 for (uint32_t node2_num = 0; node2_num < 52; node2_num++)
153 {
154 if (node1_num == node2_num) continue;
155
156 // std::cout << "i = " << i << ", pairId = " << pairId << "\n";
157 if (i++ != pairId) continue;
158
159 m_usedNodes.insert (node1_num);
160 m_usedNodes.insert (node2_num);
161
162 m_pairs.push_back (make_tuple (node1_num, node2_num));
163 return;
164 }
165 }
166
167 void
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800168 Run (const Time &finishTime)
169 {
170 cout << "Run Simulation.\n";
171 Simulator::Stop (finishTime);
Alexander Afanasyev6c678382012-01-22 16:15:41 -0800172 Simulator::Schedule (Seconds (1.0), PrintTime);
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800173 Simulator::Run ();
174 Simulator::Destroy ();
175 cout << "Done.\n";
176 }
177
178 UniformVariable m_rand;
179 RocketfuelWeightsReader *reader;
180
181 list<tuple<uint32_t,uint32_t> > m_pairs;
182 set<uint32_t> m_usedNodes;
Ilya Moiseenko2c069b92012-01-13 18:39:28 -0800183 const int m_numNodes;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800184};
185
186#endif