blob: c1ac4436ea3eb3bf07515dd88dac04a8d260691e [file] [log] [blame]
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011 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: Ilya Moiseenko <iliamo@cs.ucla.edu>
19 */
20
21
22#include "ns3/core-module.h"
23#include "ns3/network-module.h"
24#include "ns3/point-to-point-module.h"
25#include "ns3/NDNabstraction-module.h"
26#include "ns3/point-to-point-grid.h"
27#include "ns3/ipv4-global-routing-helper.h"
28#include "ns3/random-variable.h"
29#include "ns3/internet-module.h"
30#include "ns3/applications-module.h"
Alexander Afanasyevc4f88282012-01-03 11:27:20 -080031#include "ns3/config-store.h"
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -080032
33#include <iostream>
34#include <sstream>
35#include <map>
36#include <list>
37#include <set>
38#include "ns3/rocketfuel-topology-reader.h"
39
Alexander Afanasyevc4f88282012-01-03 11:27:20 -080040#include "../helper/tracers/ipv4-seqs-app-tracer.h"
41
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -080042#include <boost/lexical_cast.hpp>
43#include <boost/foreach.hpp>
44
45using namespace ns3;
46using namespace std;
47using namespace boost;
48
49NS_LOG_COMPONENT_DEFINE ("Scenario");
50
51void PrintTime ()
52{
53 cout << "Progress: " << Simulator::Now ().ToDouble (Time::S) << "s" << endl;
54
55 Simulator::Schedule (Seconds (1.0), PrintTime);
56}
57
58class Experiment
59{
60public:
Alexander Afanasyevc4f88282012-01-03 11:27:20 -080061 Experiment ()
62 : m_rand (0,52)
63 , reader ("/sprint")
64 { }
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -080065
66 void
67 ConfigureIpv4Topology ()
68 {
69 Names::Clear ();
70
71 string weights ("./src/NDNabstraction/examples/sprint-pops.weights");
72 string latencies ("./src/NDNabstraction/examples/sprint-pops.latencies");
73 string positions ("./src/NDNabstraction/examples/sprint-pops.positions");
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -080074
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -080075 reader.SetFileName (positions);
76 reader.SetFileType (RocketfuelWeightsReader::POSITIONS);
77 reader.Read ();
78
79 reader.SetFileName (weights);
80 reader.SetFileType (RocketfuelWeightsReader::WEIGHTS);
81 reader.Read ();
82
83 reader.SetFileName (latencies);
84 reader.SetFileType (RocketfuelWeightsReader::LATENCIES);
85 reader.Read ();
86
87 reader.Commit ();
88 NS_ASSERT_MSG (reader.LinksSize () != 0, "Problems reading the topology file. Failing.");
89
90 NS_LOG_INFO("Nodes = " << reader.GetNodes ().GetN());
91 NS_LOG_INFO("Links = " << reader.LinksSize ());
Alexander Afanasyevc4f88282012-01-03 11:27:20 -080092
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -080093 InternetStackHelper stack;
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -080094 stack.Install (reader.GetNodes ());
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -080095 reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
Alexander Afanasyevc4f88282012-01-03 11:27:20 -080096 }
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -080097
Alexander Afanasyevc4f88282012-01-03 11:27:20 -080098 void
99 ConfigureRouting ()
100 {
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800101 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
102
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800103 // m_rand = UniformVariable (0, reader.GetNodes ().GetN());
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800104 }
105
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800106 ApplicationContainer
107 AddTcpRandomApplications (uint16_t numStreams)
108 {
109 map<uint32_t, set<uint32_t> > streams;
110 ApplicationContainer apps;
111
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800112 const static uint32_t base_port = 10;
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800113 uint16_t createdStreams = 0;
114 uint16_t guard = 0;
115 while (createdStreams < numStreams && guard < (numeric_limits<uint16_t>::max ()-1))
116 {
117 guard ++;
118
119 uint32_t node1_num = m_rand.GetValue ();
120 uint32_t node2_num = m_rand.GetValue ();
121
122 if (node1_num == node2_num)
123 continue;
124
125 if (streams[node1_num].count (node2_num) > 0) // don't create duplicate streams
126 continue;
127
128 streams[node1_num].insert (node2_num);
129
130 Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (node1_num));
131 Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (node2_num));
132
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800133 Ptr<Ipv4> ipv4 = node1->GetObject<Ipv4> ();
134 // ipv4->GetAddress (0, 0);
135
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800136 // to make sure we don't reuse the same port numbers for different flows, just make all port numbers unique
137 PacketSinkHelper consumerHelper ("ns3::TcpSocketFactory",
138 InetSocketAddress (Ipv4Address::GetAny (), base_port + createdStreams));
139
140 BulkSendHelper producerHelper ("ns3::TcpSocketFactory",
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800141 InetSocketAddress (ipv4->GetAddress (1, 0).GetLocal (), base_port + createdStreams));
142 // cout << "SendTo: " << ipv4->GetAddress (1, 0).GetLocal () << endl;
143 producerHelper.SetAttribute ("MaxBytes", UintegerValue (2081040)); // equal to 2001 ccnx packets
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800144
145 apps.Add
146 (consumerHelper.Install (node1));
147
148 apps.Add
149 (producerHelper.Install (node2));
150
151 createdStreams ++;
152 }
153
154 return apps;
155 }
156
157 void
158 Run (const Time &finishTime)
159 {
160 cout << "Run Simulation.\n";
161 Simulator::Stop (finishTime);
162 // Simulator::Schedule (Seconds (1.0), PrintTime);
163 Simulator::Run ();
164 Simulator::Destroy ();
165 cout << "Done.\n";
166 }
167
168 UniformVariable m_rand;
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800169 RocketfuelWeightsReader reader;
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800170};
171
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800172int
173main (int argc, char *argv[])
174{
175 cout << "Begin congestion-pop scenario\n";
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800176 Packet::EnableChecking();
177 Packet::EnablePrinting();
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800178
179 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
180 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800181 Config::SetDefault ("ns3::TcpSocket::SegmentSize", StringValue ("1040"));
182
183 Config::SetDefault ("ns3::BulkSendApplication::SendSize", StringValue ("1040"));
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800184
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800185 // Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("attributes.xml"));
186 // Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
187 // Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
188
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800189 uint32_t maxRuns = 1;
190 uint32_t startRun = 0;
191 CommandLine cmd;
192 cmd.AddValue ("start", "Initial run number", startRun);
193 cmd.AddValue ("runs", "Number of runs", maxRuns);
194 cmd.Parse (argc, argv);
195
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800196 // ConfigStore config;
197 // config.ConfigureDefaults ();
198
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800199 for (uint32_t run = startRun; run < startRun + maxRuns; run++)
200 {
201 Config::SetGlobal ("RngRun", IntegerValue (run));
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800202 cout << "seed = " << SeedManager::GetSeed () << ", run = " << SeedManager::GetRun () << endl;
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800203
204 Experiment experiment;
205 cout << "Run " << run << endl;
206
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800207 experiment.ConfigureIpv4Topology ();
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800208 ApplicationContainer apps = experiment.AddTcpRandomApplications (20);
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800209 experiment.ConfigureRouting ();
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800210
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800211 string prefix = "run-tcp-" + lexical_cast<string> (run) + "-";
212
213 ofstream of_nodes ((prefix + "apps.log").c_str ());
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800214 for (uint32_t i = 0; i < apps.GetN () / 2; i++)
215 {
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800216 of_nodes << "From " << apps.Get (i*2)->GetNode ()->GetId ()
217 << " to " << apps.Get (i*2 + 1)->GetNode ()->GetId ();
218 of_nodes << "\n";
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800219 }
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800220
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800221 CcnxTraceHelper traceHelper;
222 traceHelper.EnableIpv4SeqsAppAll (prefix + "consumers-seqs.log");
223
224 // config.ConfigureAttributes ();
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800225
226 experiment.Run (Seconds (200.0));
227 }
228
229 // cout << "Finish congestion-pop scenario\n";
230 return 0;
231}