Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -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 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame^] | 21 | |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 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" |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame^] | 28 | #include "ns3/random-variable.h" |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 29 | |
| 30 | #include <iostream> |
| 31 | #include <sstream> |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame^] | 32 | #include <map> |
| 33 | #include <list> |
| 34 | #include <set> |
| 35 | #include "ns3/rocketfuel-topology-reader.h" |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 36 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame^] | 37 | #include <boost/lexical_cast.hpp> |
| 38 | #include <boost/foreach.hpp> |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 39 | |
| 40 | using namespace ns3; |
| 41 | using namespace std; |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame^] | 42 | using namespace boost; |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 43 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame^] | 44 | NS_LOG_COMPONENT_DEFINE ("LinkFailureSprint"); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 45 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame^] | 46 | void PrintTime () |
| 47 | { |
| 48 | cout << "Progress: " << Simulator::Now ().ToDouble (Time::S) << "s" << endl; |
| 49 | |
| 50 | Simulator::Schedule (Seconds (1.0), PrintTime); |
| 51 | } |
| 52 | |
| 53 | |
| 54 | class Experiment |
| 55 | { |
| 56 | public: |
| 57 | Experiment () |
| 58 | : m_reader ("/abilene", 2.0) { } |
| 59 | |
| 60 | void |
| 61 | ConfigureTopology () |
| 62 | { |
| 63 | string input ("./src/NDNabstraction/examples/abilene-topology.txt"); |
| 64 | string strategy ("ns3::CcnxBestRouteStrategy"); |
| 65 | // string strategy ("ns3::CcnxFloodingStrategy"); |
| 66 | |
| 67 | |
| 68 | m_reader.SetFileName (input); |
| 69 | |
| 70 | NodeContainer nodes = m_reader.Read (); |
| 71 | |
| 72 | if (m_reader.LinksSize () == 0) |
| 73 | { |
| 74 | NS_LOG_ERROR ("Problems reading the topology file. Failing."); |
| 75 | return; |
| 76 | } |
| 77 | |
| 78 | NS_ASSERT_MSG (m_reader.LinksSize () != 0, "Problems reading the topology file. Failing."); |
| 79 | NS_LOG_INFO("Nodes = " << m_reader.GetNodes ().GetN()); |
| 80 | NS_LOG_INFO("Links = " << m_reader.LinksSize ()); |
| 81 | |
| 82 | // ------------------------------------------------------------ |
| 83 | // -- Read topology data. |
| 84 | // -------------------------------------------- |
| 85 | |
| 86 | InternetStackHelper stack; |
| 87 | Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops"); |
| 88 | stack.SetRoutingHelper (ipv4RoutingHelper); |
| 89 | stack.Install (m_reader.GetNodes ()); |
| 90 | |
| 91 | m_reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0")); |
| 92 | |
| 93 | // Install CCNx stack |
| 94 | NS_LOG_INFO ("Installing CCNx stack"); |
| 95 | CcnxStackHelper ccnxHelper; |
| 96 | ccnxHelper.SetForwardingStrategy (strategy); |
| 97 | ccnxHelper.EnableLimits (true, Seconds(0.1)); |
| 98 | ccnxHelper.SetDefaultRoutes (false); |
| 99 | ccnxHelper.InstallAll (); |
| 100 | |
| 101 | // // Populate FIB based on IPv4 global routing controller |
| 102 | ccnxHelper.InstallFakeGlobalRoutes (); |
| 103 | ccnxHelper.InstallRoutesToAll (); |
| 104 | |
| 105 | m_rand = UniformVariable (0, m_reader.GetNodes ().GetN()); |
| 106 | m_linkRand = UniformVariable(0, m_reader.LinksSize()); |
| 107 | } |
| 108 | |
| 109 | public: |
| 110 | void |
| 111 | Run (const Time &finishTime) |
| 112 | { |
| 113 | cout << "Run Simulation.\n"; |
| 114 | Simulator::Stop (finishTime); |
| 115 | Simulator::Schedule (Seconds (1.0), PrintTime); |
| 116 | Simulator::Run (); |
| 117 | Simulator::Destroy (); |
| 118 | cout << "Done.\n"; |
| 119 | } |
| 120 | |
| 121 | //We are creating "everybody-to-everybody" usage pattern |
| 122 | ApplicationContainer |
| 123 | AddApplications() |
| 124 | { |
| 125 | ApplicationContainer apps; |
| 126 | for(uint32_t i =0; i<m_reader.GetNodes().GetN(); i++) |
| 127 | { |
| 128 | Ptr<Node> node1 = Names::Find<Node> ("/abilene", lexical_cast<string> (i)); |
| 129 | CcnxAppHelper producerHelper ("ns3::CcnxProducer"); |
| 130 | producerHelper.SetPrefix ("/" + lexical_cast<string> (i)); |
| 131 | |
| 132 | apps.Add(producerHelper.Install (node1)); |
| 133 | |
| 134 | for(uint32_t j = 0; j<m_reader.GetNodes().GetN();j++) |
| 135 | { |
| 136 | if(i==j) |
| 137 | continue; |
| 138 | |
| 139 | Ptr<Node> node2 = Names::Find<Node> ("/abilene", lexical_cast<string> (j)); |
| 140 | |
| 141 | CcnxAppHelper consumerHelper ("ns3::CcnxConsumer"); |
| 142 | consumerHelper.SetPrefix ("/" + lexical_cast<string> (i)); |
| 143 | consumerHelper.SetAttribute ("MeanRate", StringValue ("1Mbps")); |
| 144 | consumerHelper.SetAttribute ("Size", StringValue ("2")); |
| 145 | |
| 146 | apps.Add(consumerHelper.Install (node2)); |
| 147 | } |
| 148 | } |
| 149 | return apps; |
| 150 | } |
| 151 | |
| 152 | UniformVariable m_rand; |
| 153 | UniformVariable m_linkRand; |
| 154 | |
| 155 | private: |
| 156 | AnnotatedTopologyReader m_reader; |
| 157 | }; |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 158 | |
| 159 | int |
| 160 | main (int argc, char *argv[]) |
| 161 | { |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame^] | 162 | cout << "Begin link failure scenario\n"; |
| 163 | |
| 164 | Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("2Mbps")); |
| 165 | Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("100")); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 166 | |
| 167 | Time finishTime = Seconds (20.0); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame^] | 168 | |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 169 | CommandLine cmd; |
| 170 | cmd.AddValue ("finish", "Finish time", finishTime); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 171 | cmd.Parse (argc, argv); |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame^] | 172 | |
| 173 | Experiment experiment; |
| 174 | |
| 175 | for (uint32_t i = 0; i < 100; i++) |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 176 | { |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame^] | 177 | |
| 178 | experiment.ConfigureTopology (); |
| 179 | ApplicationContainer apps = experiment.AddApplications (); |
| 180 | |
| 181 | for (uint32_t i = 0; i < apps.GetN () / 2; i++) |
| 182 | { |
| 183 | cout << "From " << apps.Get (i*2)->GetNode ()->GetId () |
| 184 | << " to " << apps.Get (i*2 + 1)->GetNode ()->GetId (); |
| 185 | cout << "\n"; |
| 186 | } |
| 187 | |
| 188 | CcnxTraceHelper traceHelper; |
| 189 | // traceHelper.EnableAggregateAppAll ("ns3::CcnxConsumer"); |
| 190 | // traceHelper.EnableAggregateAppAll ("ns3::CcnxProducer"); |
| 191 | // traceHelper.EnableAggregateL3All (); |
| 192 | // traceHelper.SetL3TraceFile ("trace-l3.log"); |
| 193 | // traceHelper.SetAppTraceFile ("trace-app.log"); |
| 194 | // traceHelper.EnableRateL3All ("rate-trace.log"); |
| 195 | traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumer", "consumers-seqs.log"); |
| 196 | |
| 197 | experiment.Run (finishTime); |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 198 | } |
| 199 | |
Ilya Moiseenko | 2063c88 | 2012-01-11 19:59:32 -0800 | [diff] [blame^] | 200 | cout << "Finish link failure scenario\n"; |
Ilya Moiseenko | 46bdc7c | 2012-01-09 14:44:15 -0800 | [diff] [blame] | 201 | return 0; |
| 202 | } |