blob: c77760d6c251dc127da0f2eda1560fecbc41e503 [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
26class BaseExperiment
27{
28public:
29 BaseExperiment ()
30 : m_rand (0,52)
31 , reader (0)
Ilya Moiseenko2c069b92012-01-13 18:39:28 -080032 , m_numNodes (52)
Alexander Afanasyevb7626842012-01-12 13:43:33 -080033 { }
34
35 ~BaseExperiment ()
36 {
37 if (reader != 0) delete reader;
38 }
39
40 void
41 ConfigureTopology ()
42 {
43 Names::Clear ();
44 cout << "Configure Topology\n";
45 if (reader != 0) delete reader;
46 reader = new RocketfuelWeightsReader ("/sprint");
47
48 string weights ("./src/NDNabstraction/examples/sprint-pops.weights");
49 string latencies ("./src/NDNabstraction/examples/sprint-pops.latencies");
50 string positions ("./src/NDNabstraction/examples/sprint-pops.positions");
51
52 reader->SetFileName (positions);
53 reader->SetFileType (RocketfuelWeightsReader::POSITIONS);
54 reader->Read ();
55
56 reader->SetFileName (weights);
57 reader->SetFileType (RocketfuelWeightsReader::WEIGHTS);
58 reader->Read ();
59
60 reader->SetFileName (latencies);
61 reader->SetFileType (RocketfuelWeightsReader::LATENCIES);
62 reader->Read ();
63
64 reader->Commit ();
65 }
66
Alexander Afanasyev4d66de52012-01-13 00:06:01 -080067 void InstallCcnxStack (bool installFIBs = true)
Alexander Afanasyevb7626842012-01-12 13:43:33 -080068 {
69 InternetStackHelper stack;
70 Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops");
71 stack.SetRoutingHelper (ipv4RoutingHelper);
72 stack.Install (reader->GetNodes ());
73
74 reader->AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
75
76 // Install CCNx stack
77 cout << "Installing CCNx stack\n";
78 CcnxStackHelper ccnxHelper;
79 ccnxHelper.SetForwardingStrategy ("ns3::CcnxBestRouteStrategy");
80 ccnxHelper.EnableLimits (true, Seconds(0.1));
81 ccnxHelper.SetDefaultRoutes (false);
82 ccnxHelper.InstallAll ();
83
Alexander Afanasyevb7626842012-01-12 13:43:33 -080084 ccnxHelper.InstallFakeGlobalRoutes ();
Alexander Afanasyev4d66de52012-01-13 00:06:01 -080085 if (installFIBs)
86 {
87 // // Populate FIB based on IPv4 global routing controller
88 ccnxHelper.InstallRoutesToAll ();
89 }
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -080090
91 reader->ApplyOspfMetric ();
Alexander Afanasyevb7626842012-01-12 13:43:33 -080092 }
93
94 void InstallIpStack ()
95 {
96 InternetStackHelper stack;
97 stack.Install (reader->GetNodes ());
98 reader->AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -080099 reader->ApplyOspfMetric ();
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800100
101 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
102 }
103
104 void
105 GenerateRandomPairs (uint16_t numStreams)
106 {
107 m_pairs.clear ();
108 // map<uint32_t, set<uint32_t> > streams;
109 m_usedNodes.clear ();
110
111 uint16_t createdStreams = 0;
112 uint16_t guard = 0;
113 while (createdStreams < numStreams && guard < (numeric_limits<uint16_t>::max ()-1))
114 {
115 guard ++;
116
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800117 uint32_t node1_num = m_rand.GetValue (); //43;//
118 uint32_t node2_num = m_rand.GetValue (); //38;//
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800119
120 if (node1_num == node2_num)
121 continue;
122
123 if (m_usedNodes.count (node1_num) > 0 ||
124 m_usedNodes.count (node2_num) > 0 )
125 {
126 continue; // don't reuse nodes
127 }
128
129 m_usedNodes.insert (node1_num);
130 m_usedNodes.insert (node2_num);
131
132 m_pairs.push_back (make_tuple (node1_num, node2_num));
133 createdStreams ++;
134 }
135 }
136
137 void
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800138 SetPair (uint32_t pairId)
139 {
140 m_pairs.clear ();
141 m_usedNodes.clear ();
142
143 uint32_t i = 0;
144 for (uint32_t node1_num = 0; node1_num < 52; node1_num++)
145 for (uint32_t node2_num = 0; node2_num < 52; node2_num++)
146 {
147 if (node1_num == node2_num) continue;
148
149 // std::cout << "i = " << i << ", pairId = " << pairId << "\n";
150 if (i++ != pairId) continue;
151
152 m_usedNodes.insert (node1_num);
153 m_usedNodes.insert (node2_num);
154
155 m_pairs.push_back (make_tuple (node1_num, node2_num));
156 return;
157 }
158 }
159
160 void
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800161 Run (const Time &finishTime)
162 {
163 cout << "Run Simulation.\n";
164 Simulator::Stop (finishTime);
165 // Simulator::Schedule (Seconds (1.0), PrintTime);
166 Simulator::Run ();
167 Simulator::Destroy ();
168 cout << "Done.\n";
169 }
170
171 UniformVariable m_rand;
172 RocketfuelWeightsReader *reader;
173
174 list<tuple<uint32_t,uint32_t> > m_pairs;
175 set<uint32_t> m_usedNodes;
Ilya Moiseenko2c069b92012-01-13 18:39:28 -0800176 const int m_numNodes;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800177};
178
179#endif