blob: 873a9564ae1c46e39e5c86f258086ef78d7b1043 [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)
32 { }
33
34 ~BaseExperiment ()
35 {
36 if (reader != 0) delete reader;
37 }
38
39 void
40 ConfigureTopology ()
41 {
42 Names::Clear ();
43 cout << "Configure Topology\n";
44 if (reader != 0) delete reader;
45 reader = new RocketfuelWeightsReader ("/sprint");
46
47 string weights ("./src/NDNabstraction/examples/sprint-pops.weights");
48 string latencies ("./src/NDNabstraction/examples/sprint-pops.latencies");
49 string positions ("./src/NDNabstraction/examples/sprint-pops.positions");
50
51 reader->SetFileName (positions);
52 reader->SetFileType (RocketfuelWeightsReader::POSITIONS);
53 reader->Read ();
54
55 reader->SetFileName (weights);
56 reader->SetFileType (RocketfuelWeightsReader::WEIGHTS);
57 reader->Read ();
58
59 reader->SetFileName (latencies);
60 reader->SetFileType (RocketfuelWeightsReader::LATENCIES);
61 reader->Read ();
62
63 reader->Commit ();
64 }
65
Alexander Afanasyev4d66de52012-01-13 00:06:01 -080066 void InstallCcnxStack (bool installFIBs = true)
Alexander Afanasyevb7626842012-01-12 13:43:33 -080067 {
68 InternetStackHelper stack;
69 Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops");
70 stack.SetRoutingHelper (ipv4RoutingHelper);
71 stack.Install (reader->GetNodes ());
72
73 reader->AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
74
75 // Install CCNx stack
76 cout << "Installing CCNx stack\n";
77 CcnxStackHelper ccnxHelper;
78 ccnxHelper.SetForwardingStrategy ("ns3::CcnxBestRouteStrategy");
79 ccnxHelper.EnableLimits (true, Seconds(0.1));
80 ccnxHelper.SetDefaultRoutes (false);
81 ccnxHelper.InstallAll ();
82
Alexander Afanasyevb7626842012-01-12 13:43:33 -080083 ccnxHelper.InstallFakeGlobalRoutes ();
Alexander Afanasyev4d66de52012-01-13 00:06:01 -080084 if (installFIBs)
85 {
86 // // Populate FIB based on IPv4 global routing controller
87 ccnxHelper.InstallRoutesToAll ();
88 }
Alexander Afanasyevb7626842012-01-12 13:43:33 -080089 }
90
91 void InstallIpStack ()
92 {
93 InternetStackHelper stack;
94 stack.Install (reader->GetNodes ());
95 reader->AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
96
97 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
98 }
99
100 void
101 GenerateRandomPairs (uint16_t numStreams)
102 {
103 m_pairs.clear ();
104 // map<uint32_t, set<uint32_t> > streams;
105 m_usedNodes.clear ();
106
107 uint16_t createdStreams = 0;
108 uint16_t guard = 0;
109 while (createdStreams < numStreams && guard < (numeric_limits<uint16_t>::max ()-1))
110 {
111 guard ++;
112
113 uint32_t node1_num = m_rand.GetValue ();
114 uint32_t node2_num = m_rand.GetValue ();
115
116 if (node1_num == node2_num)
117 continue;
118
119 if (m_usedNodes.count (node1_num) > 0 ||
120 m_usedNodes.count (node2_num) > 0 )
121 {
122 continue; // don't reuse nodes
123 }
124
125 m_usedNodes.insert (node1_num);
126 m_usedNodes.insert (node2_num);
127
128 m_pairs.push_back (make_tuple (node1_num, node2_num));
129 createdStreams ++;
130 }
131 }
132
133 void
134 Run (const Time &finishTime)
135 {
136 cout << "Run Simulation.\n";
137 Simulator::Stop (finishTime);
138 // Simulator::Schedule (Seconds (1.0), PrintTime);
139 Simulator::Run ();
140 Simulator::Destroy ();
141 cout << "Done.\n";
142 }
143
144 UniformVariable m_rand;
145 RocketfuelWeightsReader *reader;
146
147 list<tuple<uint32_t,uint32_t> > m_pairs;
148 set<uint32_t> m_usedNodes;
149};
150
151#endif