Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 29 | #include "ns3/internet-module.h" |
| 30 | #include "ns3/applications-module.h" |
Alexander Afanasyev | e4c2ece | 2012-01-11 10:44:40 -0800 | [diff] [blame] | 31 | #include "ns3/config-store.h" |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 32 | |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 33 | #include <boost/lexical_cast.hpp> |
| 34 | #include <boost/foreach.hpp> |
| 35 | |
| 36 | using namespace ns3; |
| 37 | using namespace std; |
| 38 | using namespace boost; |
| 39 | |
| 40 | NS_LOG_COMPONENT_DEFINE ("Scenario"); |
| 41 | |
Alexander Afanasyev | f9d8fbe | 2012-01-10 02:03:15 -0800 | [diff] [blame] | 42 | // void PrintTime () |
| 43 | // { |
| 44 | // cout << "Progress: " << Simulator::Now ().ToDouble (Time::S) << "s" << endl; |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 45 | |
Alexander Afanasyev | f9d8fbe | 2012-01-10 02:03:15 -0800 | [diff] [blame] | 46 | // Simulator::Schedule (Seconds (1.0), PrintTime); |
| 47 | // } |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 48 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 49 | #include "base-experiment.h" |
| 50 | |
| 51 | class Experiment : public BaseExperiment |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 52 | { |
| 53 | public: |
Alexander Afanasyev | f9d8fbe | 2012-01-10 02:03:15 -0800 | [diff] [blame] | 54 | 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 Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 63 | |
| 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 Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 67 | CcnxAppHelper consumerHelper ("ns3::CcnxConsumerWindow"); |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 68 | consumerHelper.SetPrefix ("/" + lexical_cast<string> (node2->GetId ())); |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 69 | // consumerHelper.SetAttribute ("MeanRate", StringValue ("2Mbps")); |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 70 | consumerHelper.SetAttribute ("Size", StringValue ("1.983642578125")); //to make sure max seq # is 2000 |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 71 | |
| 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 Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | return apps; |
| 83 | } |
| 84 | |
Alexander Afanasyev | f9d8fbe | 2012-01-10 02:03:15 -0800 | [diff] [blame] | 85 | 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 Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | |
| 126 | int |
| 127 | main (int argc, char *argv[]) |
| 128 | { |
| 129 | cout << "Begin congestion-pop scenario\n"; |
| 130 | |
| 131 | Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps")); |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 132 | Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("60")); |
Alexander Afanasyev | f9d8fbe | 2012-01-10 02:03:15 -0800 | [diff] [blame] | 133 | Config::SetDefault ("ns3::TcpSocket::SegmentSize", StringValue ("1040")); |
| 134 | |
| 135 | Config::SetDefault ("ns3::BulkSendApplication::SendSize", StringValue ("1040")); |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 136 | |
Alexander Afanasyev | e4c2ece | 2012-01-11 10:44:40 -0800 | [diff] [blame] | 137 | 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 Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 141 | uint32_t maxRuns = 1; |
| 142 | uint32_t startRun = 0; |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 143 | CommandLine cmd; |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 144 | cmd.AddValue ("start", "Initial run number", startRun); |
| 145 | cmd.AddValue ("runs", "Number of runs", maxRuns); |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 146 | cmd.Parse (argc, argv); |
| 147 | |
Alexander Afanasyev | e4c2ece | 2012-01-11 10:44:40 -0800 | [diff] [blame] | 148 | // ConfigStore config; |
| 149 | // config.ConfigureDefaults (); |
| 150 | |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 151 | for (uint32_t run = startRun; run < startRun + maxRuns; run++) |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 152 | { |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 153 | Config::SetGlobal ("RngRun", IntegerValue (run)); |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 154 | cout << "seed = " << SeedManager::GetSeed () << ", run = " << SeedManager::GetRun () << endl; |
| 155 | |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 156 | Experiment experiment; |
| 157 | cout << "Run " << run << endl; |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 158 | string prefix = "run-" + lexical_cast<string> (run) + "-"; |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 159 | |
Alexander Afanasyev | f9d8fbe | 2012-01-10 02:03:15 -0800 | [diff] [blame] | 160 | experiment.GenerateRandomPairs (20); |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 161 | ofstream of_nodes ((prefix + "apps.log").c_str ()); |
Alexander Afanasyev | f9d8fbe | 2012-01-10 02:03:15 -0800 | [diff] [blame] | 162 | for (list<tuple<uint32_t,uint32_t> >::iterator i = experiment.m_pairs.begin (); i != experiment.m_pairs.end (); i++) |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 163 | { |
Alexander Afanasyev | f9d8fbe | 2012-01-10 02:03:15 -0800 | [diff] [blame] | 164 | of_nodes << "From " << i->get<0> () |
| 165 | << " to " << i->get<1> (); |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 166 | of_nodes << "\n"; |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 167 | } |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 168 | of_nodes.close (); |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 169 | |
Alexander Afanasyev | f9d8fbe | 2012-01-10 02:03:15 -0800 | [diff] [blame] | 170 | cout << "NDN experiment\n"; |
| 171 | // NDN |
| 172 | { |
| 173 | experiment.ConfigureTopology (); |
| 174 | experiment.InstallCcnxStack (); |
| 175 | ApplicationContainer apps = experiment.AddCcnxApplications (); |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 176 | |
Alexander Afanasyev | f9d8fbe | 2012-01-10 02:03:15 -0800 | [diff] [blame] | 177 | for (uint32_t i = 0; i < apps.GetN () / 2; i++) |
| 178 | { |
Alexander Afanasyev | 06b42ec | 2012-01-11 19:05:36 -0800 | [diff] [blame] | 179 | apps.Get (i*2)->SetStartTime (Seconds (1+i)); |
| 180 | apps.Get (i*2 + 1)->SetStartTime (Seconds (1+i)); |
Alexander Afanasyev | f9d8fbe | 2012-01-10 02:03:15 -0800 | [diff] [blame] | 181 | } |
| 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 Afanasyev | e4c2ece | 2012-01-11 10:44:40 -0800 | [diff] [blame] | 187 | traceHelper.EnableWindowsAll (prefix + "windows.log"); |
Alexander Afanasyev | f9d8fbe | 2012-01-10 02:03:15 -0800 | [diff] [blame] | 188 | |
Alexander Afanasyev | e4c2ece | 2012-01-11 10:44:40 -0800 | [diff] [blame] | 189 | // config.ConfigureAttributes (); |
Alexander Afanasyev | f9d8fbe | 2012-01-10 02:03:15 -0800 | [diff] [blame] | 190 | 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 Afanasyev | f9d8fbe | 2012-01-10 02:03:15 -0800 | [diff] [blame] | 200 | CcnxTraceHelper traceHelper; |
| 201 | traceHelper.EnableIpv4SeqsAppAll (prefix + "tcp-consumers-seqs.log"); |
Alexander Afanasyev | 06b42ec | 2012-01-11 19:05:36 -0800 | [diff] [blame] | 202 | 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 Afanasyev | f9d8fbe | 2012-01-10 02:03:15 -0800 | [diff] [blame] | 218 | |
| 219 | experiment.Run (Seconds (200.0)); |
| 220 | } |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 221 | } |
| 222 | |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 223 | // cout << "Finish congestion-pop scenario\n"; |
Alexander Afanasyev | 1d2642a | 2012-01-02 16:20:05 -0800 | [diff] [blame] | 224 | return 0; |
| 225 | } |