blob: ae28ad841f4a07856a1a0c2159535f3e1c548fea [file] [log] [blame]
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -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"
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -080029#include "ns3/internet-module.h"
30#include "ns3/applications-module.h"
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -080031#include "ns3/config-store.h"
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -080032
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -080033#include <boost/lexical_cast.hpp>
34#include <boost/foreach.hpp>
35
36using namespace ns3;
37using namespace std;
38using namespace boost;
39
40NS_LOG_COMPONENT_DEFINE ("Scenario");
41
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -080042// void PrintTime ()
43// {
44// cout << "Progress: " << Simulator::Now ().ToDouble (Time::S) << "s" << endl;
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -080045
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -080046// Simulator::Schedule (Seconds (1.0), PrintTime);
47// }
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -080048
Alexander Afanasyevb7626842012-01-12 13:43:33 -080049#include "base-experiment.h"
50
51class Experiment : public BaseExperiment
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -080052{
53public:
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -080054 ApplicationContainer
55 AddCcnxApplications ()
56 {
57 ApplicationContainer apps;
58
59 for (list<tuple<uint32_t,uint32_t> >::iterator i = m_pairs.begin (); i != m_pairs.end (); i++)
60 {
61 uint32_t node1_num = i->get<0> ();
62 uint32_t node2_num = i->get<1> ();
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -080063
64 Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (node1_num));
65 Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (node2_num));
66
Alexander Afanasyev359bfb72012-01-09 18:42:50 -080067 CcnxAppHelper consumerHelper ("ns3::CcnxConsumerWindow");
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -080068 consumerHelper.SetPrefix ("/" + lexical_cast<string> (node2->GetId ()));
Alexander Afanasyev359bfb72012-01-09 18:42:50 -080069 // consumerHelper.SetAttribute ("MeanRate", StringValue ("2Mbps"));
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -080070 consumerHelper.SetAttribute ("Size", StringValue ("1.983642578125")); //to make sure max seq # is 2000
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -080071
72 CcnxAppHelper producerHelper ("ns3::CcnxProducer");
73 producerHelper.SetPrefix ("/" + lexical_cast<string> (node2->GetId ()));
74
75 apps.Add
76 (consumerHelper.Install (node1));
77
78 apps.Add
79 (producerHelper.Install (node2));
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -080080 }
81
82 return apps;
83 }
84
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -080085 ApplicationContainer
86 AddTcpApplications ()
87 {
88 ApplicationContainer apps;
89
90 uint32_t streamId = 0;
91 const static uint32_t base_port = 10;
92 for (list<tuple<uint32_t,uint32_t> >::iterator i = m_pairs.begin (); i != m_pairs.end (); i++)
93 {
94 uint32_t node1_num = i->get<0> ();
95 uint32_t node2_num = i->get<1> ();
96
97 Ptr<Node> node1 = Names::Find<Node> ("/sprint", lexical_cast<string> (node2_num));
98 Ptr<Node> node2 = Names::Find<Node> ("/sprint", lexical_cast<string> (node1_num));
99
100 Ptr<Ipv4> ipv4 = node1->GetObject<Ipv4> ();
101 // ipv4->GetAddress (0, 0);
102
103 // to make sure we don't reuse the same port numbers for different flows, just make all port numbers unique
104 PacketSinkHelper consumerHelper ("ns3::TcpSocketFactory",
105 InetSocketAddress (Ipv4Address::GetAny (), base_port + streamId));
106
107 BulkSendHelper producerHelper ("ns3::TcpSocketFactory",
108 InetSocketAddress (ipv4->GetAddress (1, 0).GetLocal (), base_port + streamId));
109 // cout << "SendTo: " << ipv4->GetAddress (1, 0).GetLocal () << endl;
110 producerHelper.SetAttribute ("MaxBytes", UintegerValue (2081040)); // equal to 2001 ccnx packets
111
112 apps.Add
113 (consumerHelper.Install (node1));
114
115 apps.Add
116 (producerHelper.Install (node2));
117
118 streamId++;
119 }
120
121 return apps;
122 }
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800123};
124
125
126int
127main (int argc, char *argv[])
128{
129 cout << "Begin congestion-pop scenario\n";
130
131 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800132 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("60"));
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800133 Config::SetDefault ("ns3::TcpSocket::SegmentSize", StringValue ("1040"));
134
135 Config::SetDefault ("ns3::BulkSendApplication::SendSize", StringValue ("1040"));
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800136
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -0800137 Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("attributes.xml"));
138 Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
139 Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
140
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800141 uint32_t maxRuns = 1;
142 uint32_t startRun = 0;
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800143 CommandLine cmd;
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800144 cmd.AddValue ("start", "Initial run number", startRun);
145 cmd.AddValue ("runs", "Number of runs", maxRuns);
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800146 cmd.Parse (argc, argv);
147
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -0800148 // ConfigStore config;
149 // config.ConfigureDefaults ();
150
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800151 for (uint32_t run = startRun; run < startRun + maxRuns; run++)
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800152 {
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800153 Config::SetGlobal ("RngRun", IntegerValue (run));
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800154 cout << "seed = " << SeedManager::GetSeed () << ", run = " << SeedManager::GetRun () << endl;
155
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800156 Experiment experiment;
157 cout << "Run " << run << endl;
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800158 string prefix = "run-" + lexical_cast<string> (run) + "-";
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800159
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800160 experiment.GenerateRandomPairs (20);
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800161 ofstream of_nodes ((prefix + "apps.log").c_str ());
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800162 for (list<tuple<uint32_t,uint32_t> >::iterator i = experiment.m_pairs.begin (); i != experiment.m_pairs.end (); i++)
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800163 {
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800164 of_nodes << "From " << i->get<0> ()
165 << " to " << i->get<1> ();
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800166 of_nodes << "\n";
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800167 }
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800168 of_nodes.close ();
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800169
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800170 cout << "NDN experiment\n";
171 // NDN
172 {
173 experiment.ConfigureTopology ();
174 experiment.InstallCcnxStack ();
175 ApplicationContainer apps = experiment.AddCcnxApplications ();
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800176
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800177 for (uint32_t i = 0; i < apps.GetN () / 2; i++)
178 {
Alexander Afanasyev06b42ec2012-01-11 19:05:36 -0800179 apps.Get (i*2)->SetStartTime (Seconds (1+i));
180 apps.Get (i*2 + 1)->SetStartTime (Seconds (1+i));
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800181 }
182
183 CcnxTraceHelper traceHelper;
184 // traceHelper.EnableRateL3All (prefix + "rate-trace.log");
185 // traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumerCbr", prefix + "consumers-seqs.log");
186 traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumerWindow", prefix + "consumers-seqs.log");
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -0800187 traceHelper.EnableWindowsAll (prefix + "windows.log");
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800188
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -0800189 // config.ConfigureAttributes ();
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800190 experiment.Run (Seconds (200.0));
191 }
192
193 cout << "TCP experiment\n";
194 // TCP
195 {
196 experiment.ConfigureTopology ();
197 experiment.InstallIpStack ();
198 ApplicationContainer apps = experiment.AddTcpApplications ();
199
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800200 CcnxTraceHelper traceHelper;
201 traceHelper.EnableIpv4SeqsAppAll (prefix + "tcp-consumers-seqs.log");
Alexander Afanasyev06b42ec2012-01-11 19:05:36 -0800202 traceHelper.EnableWindowsTcpAll (prefix + "tcp-windows.log");
203
204 for (uint32_t i = 0; i < apps.GetN () / 2; i++)
205 {
206 apps.Get (i*2)->SetStartTime (Seconds (1+i));
207
208 apps.Get (i*2 + 1)->SetStartTime (Seconds (1+i));
209
210 // cout << "Node: " << apps.Get (i*2 + 1)->GetNode ()->GetId () << "\n";
211 // care only about BulkSender
212 Simulator::Schedule (Seconds (1+i+0.01),
213 &CcnxTraceHelper::TcpConnect, &traceHelper, apps.Get (i*2)->GetNode ());
214
215 Simulator::Schedule (Seconds (1+i+0.01),
216 &CcnxTraceHelper::TcpConnect, &traceHelper, apps.Get (i*2 + 1)->GetNode ());
217 }
Alexander Afanasyevf9d8fbe2012-01-10 02:03:15 -0800218
219 experiment.Run (Seconds (200.0));
220 }
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800221 }
222
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800223 // cout << "Finish congestion-pop scenario\n";
Alexander Afanasyev1d2642a2012-01-02 16:20:05 -0800224 return 0;
225}