blob: 7a9e4bf51242174cd70e3869d25d086694023658 [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
66 void InstallCcnxStack ()
67 {
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
83 // // Populate FIB based on IPv4 global routing controller
84 ccnxHelper.InstallFakeGlobalRoutes ();
85 ccnxHelper.InstallRoutesToAll ();
86 }
87
88 void InstallIpStack ()
89 {
90 InternetStackHelper stack;
91 stack.Install (reader->GetNodes ());
92 reader->AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
93
94 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
95 }
96
97 void
98 GenerateRandomPairs (uint16_t numStreams)
99 {
100 m_pairs.clear ();
101 // map<uint32_t, set<uint32_t> > streams;
102 m_usedNodes.clear ();
103
104 uint16_t createdStreams = 0;
105 uint16_t guard = 0;
106 while (createdStreams < numStreams && guard < (numeric_limits<uint16_t>::max ()-1))
107 {
108 guard ++;
109
110 uint32_t node1_num = m_rand.GetValue ();
111 uint32_t node2_num = m_rand.GetValue ();
112
113 if (node1_num == node2_num)
114 continue;
115
116 if (m_usedNodes.count (node1_num) > 0 ||
117 m_usedNodes.count (node2_num) > 0 )
118 {
119 continue; // don't reuse nodes
120 }
121
122 m_usedNodes.insert (node1_num);
123 m_usedNodes.insert (node2_num);
124
125 m_pairs.push_back (make_tuple (node1_num, node2_num));
126 createdStreams ++;
127 }
128 }
129
130 void
131 Run (const Time &finishTime)
132 {
133 cout << "Run Simulation.\n";
134 Simulator::Stop (finishTime);
135 // Simulator::Schedule (Seconds (1.0), PrintTime);
136 Simulator::Run ();
137 Simulator::Destroy ();
138 cout << "Done.\n";
139 }
140
141 UniformVariable m_rand;
142 RocketfuelWeightsReader *reader;
143
144 list<tuple<uint32_t,uint32_t> > m_pairs;
145 set<uint32_t> m_usedNodes;
146};
147
148#endif