blob: c00c127f392b16b2e814dc08ac7c1b08620486bc [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 Afanasyevb7626842012-01-12 13:43:33 -080090 }
91
92 void InstallIpStack ()
93 {
94 InternetStackHelper stack;
95 stack.Install (reader->GetNodes ());
96 reader->AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
97
98 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
99 }
100
101 void
102 GenerateRandomPairs (uint16_t numStreams)
103 {
104 m_pairs.clear ();
105 // map<uint32_t, set<uint32_t> > streams;
106 m_usedNodes.clear ();
107
108 uint16_t createdStreams = 0;
109 uint16_t guard = 0;
110 while (createdStreams < numStreams && guard < (numeric_limits<uint16_t>::max ()-1))
111 {
112 guard ++;
113
114 uint32_t node1_num = m_rand.GetValue ();
115 uint32_t node2_num = m_rand.GetValue ();
116
117 if (node1_num == node2_num)
118 continue;
119
120 if (m_usedNodes.count (node1_num) > 0 ||
121 m_usedNodes.count (node2_num) > 0 )
122 {
123 continue; // don't reuse nodes
124 }
125
126 m_usedNodes.insert (node1_num);
127 m_usedNodes.insert (node2_num);
128
129 m_pairs.push_back (make_tuple (node1_num, node2_num));
130 createdStreams ++;
131 }
132 }
133
134 void
135 Run (const Time &finishTime)
136 {
137 cout << "Run Simulation.\n";
138 Simulator::Stop (finishTime);
139 // Simulator::Schedule (Seconds (1.0), PrintTime);
140 Simulator::Run ();
141 Simulator::Destroy ();
142 cout << "Done.\n";
143 }
144
145 UniformVariable m_rand;
146 RocketfuelWeightsReader *reader;
147
148 list<tuple<uint32_t,uint32_t> > m_pairs;
149 set<uint32_t> m_usedNodes;
Ilya Moiseenko2c069b92012-01-13 18:39:28 -0800150 const int m_numNodes;
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800151};
152
153#endif