Ilya Moiseenko | 6f5e8fa | 2011-12-16 15:20:19 -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" |
Alexander Afanasyev | 8f5a9bb | 2011-12-18 19:49:02 -0800 | [diff] [blame] | 28 | #include "../utils/spring-mobility-helper.h" |
Alexander Afanasyev | c86c283 | 2011-12-23 02:56:22 -0800 | [diff] [blame] | 29 | #include "../helper/ccnx-trace-helper.h" |
Ilya Moiseenko | 6f5e8fa | 2011-12-16 15:20:19 -0800 | [diff] [blame] | 30 | |
Ilya Moiseenko | 6f5e8fa | 2011-12-16 15:20:19 -0800 | [diff] [blame] | 31 | #include <sstream> |
| 32 | #include "ns3/annotated-topology-reader.h" |
Ilya Moiseenko | 6f5e8fa | 2011-12-16 15:20:19 -0800 | [diff] [blame] | 33 | |
| 34 | #include "ns3/config-store.h" |
| 35 | |
| 36 | using namespace ns3; |
| 37 | using namespace std; |
| 38 | |
| 39 | NS_LOG_COMPONENT_DEFINE ("CcnxSyntheticTopology"); |
| 40 | |
Ilya Moiseenko | 6f5e8fa | 2011-12-16 15:20:19 -0800 | [diff] [blame] | 41 | void PrintTime () |
| 42 | { |
Alexander Afanasyev | 8f5a9bb | 2011-12-18 19:49:02 -0800 | [diff] [blame] | 43 | NS_LOG_INFO (Simulator::Now ()); |
Ilya Moiseenko | 6f5e8fa | 2011-12-16 15:20:19 -0800 | [diff] [blame] | 44 | |
Alexander Afanasyev | 8f5a9bb | 2011-12-18 19:49:02 -0800 | [diff] [blame] | 45 | Simulator::Schedule (Seconds (10.0), PrintTime); |
Ilya Moiseenko | 6f5e8fa | 2011-12-16 15:20:19 -0800 | [diff] [blame] | 46 | } |
| 47 | |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 48 | int |
Ilya Moiseenko | 6f5e8fa | 2011-12-16 15:20:19 -0800 | [diff] [blame] | 49 | main (int argc, char *argv[]) |
| 50 | { |
Alexander Afanasyev | 8f5a9bb | 2011-12-18 19:49:02 -0800 | [diff] [blame] | 51 | string input ("./src/NDNabstraction/examples/synthetic-topology.txt"); |
Ilya Moiseenko | 6f5e8fa | 2011-12-16 15:20:19 -0800 | [diff] [blame] | 52 | |
Alexander Afanasyev | 8f5a9bb | 2011-12-18 19:49:02 -0800 | [diff] [blame] | 53 | Time finishTime = Seconds (20.0); |
| 54 | string strategy = "ns3::CcnxFloodingStrategy"; |
| 55 | CommandLine cmd; |
| 56 | cmd.AddValue ("finish", "Finish time", finishTime); |
| 57 | cmd.AddValue ("strategy", "CCNx forwarding strategy", strategy); |
| 58 | cmd.Parse (argc, argv); |
Ilya Moiseenko | 6f5e8fa | 2011-12-16 15:20:19 -0800 | [diff] [blame] | 59 | |
Alexander Afanasyev | 8f5a9bb | 2011-12-18 19:49:02 -0800 | [diff] [blame] | 60 | ConfigStore config; |
| 61 | config.ConfigureDefaults (); |
Ilya Moiseenko | 6f5e8fa | 2011-12-16 15:20:19 -0800 | [diff] [blame] | 62 | |
Alexander Afanasyev | 8f5a9bb | 2011-12-18 19:49:02 -0800 | [diff] [blame] | 63 | // ------------------------------------------------------------ |
| 64 | // -- Read topology data. |
| 65 | // -------------------------------------------- |
Ilya Moiseenko | 6f5e8fa | 2011-12-16 15:20:19 -0800 | [diff] [blame] | 66 | |
Alexander Afanasyev | 8f5a9bb | 2011-12-18 19:49:02 -0800 | [diff] [blame] | 67 | AnnotatedTopologyReader reader ("/synthetic"); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 68 | // reader.SetMobilityModel ("ns3::SpringMobilityModel"); |
Alexander Afanasyev | 8f5a9bb | 2011-12-18 19:49:02 -0800 | [diff] [blame] | 69 | reader.SetFileName (input); |
| 70 | NodeContainer nodes = reader.Read (); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 71 | // SpringMobilityHelper::InstallSprings (reader.LinksBegin (), reader.LinksEnd ()); |
Ilya Moiseenko | 6f5e8fa | 2011-12-16 15:20:19 -0800 | [diff] [blame] | 72 | |
Alexander Afanasyev | 8f5a9bb | 2011-12-18 19:49:02 -0800 | [diff] [blame] | 73 | InternetStackHelper stack; |
| 74 | Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops"); |
| 75 | stack.SetRoutingHelper (ipv4RoutingHelper); |
| 76 | stack.Install (nodes); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 77 | |
| 78 | reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0")); |
| 79 | |
Alexander Afanasyev | 8f5a9bb | 2011-12-18 19:49:02 -0800 | [diff] [blame] | 80 | NS_LOG_INFO("Nodes = " << nodes.GetN()); |
| 81 | NS_LOG_INFO("Links = " << reader.LinksSize ()); |
Ilya Moiseenko | 6f5e8fa | 2011-12-16 15:20:19 -0800 | [diff] [blame] | 82 | |
Alexander Afanasyev | 8f5a9bb | 2011-12-18 19:49:02 -0800 | [diff] [blame] | 83 | // Install CCNx stack |
| 84 | NS_LOG_INFO ("Installing CCNx stack"); |
| 85 | CcnxStackHelper ccnxHelper; |
| 86 | ccnxHelper.SetForwardingStrategy (strategy); |
| 87 | ccnxHelper.EnableLimits (true, Seconds(0.1)); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 88 | ccnxHelper.SetDefaultRoutes (false); |
Alexander Afanasyev | 8f5a9bb | 2011-12-18 19:49:02 -0800 | [diff] [blame] | 89 | ccnxHelper.InstallAll (); |
Ilya Moiseenko | 6f5e8fa | 2011-12-16 15:20:19 -0800 | [diff] [blame] | 90 | |
Alexander Afanasyev | 8f5a9bb | 2011-12-18 19:49:02 -0800 | [diff] [blame] | 91 | NS_LOG_INFO ("Installing Applications"); |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 92 | CcnxAppHelper consumerHelper ("ns3::CcnxConsumer"); |
| 93 | |
| 94 | consumerHelper.SetPrefix ("/6"); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame^] | 95 | consumerHelper.SetAttribute ("MeanRate", StringValue ("2Mbps")); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 96 | ApplicationContainer consumers = consumerHelper.Install (Names::Find<Node> ("/synthetic", "c1")); |
Ilya Moiseenko | 6f5e8fa | 2011-12-16 15:20:19 -0800 | [diff] [blame] | 97 | |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 98 | consumerHelper.SetPrefix ("/7"); |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 99 | consumerHelper.SetAttribute ("MeanRate", StringValue ("2Mbps")); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 100 | ApplicationContainer consumers2 = consumerHelper.Install(Names::Find<Node> ("/synthetic", "c2")); |
| 101 | |
| 102 | consumerHelper.SetPrefix ("/8"); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame^] | 103 | consumerHelper.SetAttribute ("MeanRate", StringValue ("2Mbps")); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 104 | ApplicationContainer consumers3 = consumerHelper.Install(Names::Find<Node> ("/synthetic", "c3")); |
| 105 | |
| 106 | consumerHelper.SetPrefix ("/10"); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame^] | 107 | consumerHelper.SetAttribute ("MeanRate", StringValue ("2Mbps")); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 108 | ApplicationContainer consumers4 = consumerHelper.Install(Names::Find<Node> ("/synthetic", "c4")); |
| 109 | |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 110 | consumers.Start (Seconds (0)); |
| 111 | consumers2.Start (Seconds (10)); |
| 112 | consumers3.Start (Seconds (20)); |
| 113 | consumers4.Start (Seconds (30)); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 114 | |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 115 | ///////////////////////////////////////////// |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 116 | |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 117 | CcnxAppHelper producerHelper ("ns3::CcnxProducer"); |
| 118 | producerHelper.SetAttribute ("PayloadSize", StringValue("1024")); |
| 119 | |
| 120 | producerHelper.SetPrefix ("/6"); |
| 121 | producerHelper.Install (Names::Find<Node> ("/synthetic", "p1")); |
| 122 | |
| 123 | producerHelper.SetPrefix ("/7"); |
| 124 | producerHelper.Install (Names::Find<Node> ("/synthetic", "p2")); |
| 125 | |
| 126 | producerHelper.SetPrefix ("/8"); |
| 127 | producerHelper.Install (Names::Find<Node> ("/synthetic", "p3")); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 128 | |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 129 | producerHelper.SetPrefix ("/10"); |
| 130 | producerHelper.Install (Names::Find<Node> ("/synthetic", "p4")); |
Ilya Moiseenko | 6f5e8fa | 2011-12-16 15:20:19 -0800 | [diff] [blame] | 131 | |
Alexander Afanasyev | 8f5a9bb | 2011-12-18 19:49:02 -0800 | [diff] [blame] | 132 | // Populate FIB based on IPv4 global routing controller |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 133 | ccnxHelper.InstallFakeGlobalRoutes (); |
| 134 | ccnxHelper.InstallRouteTo (Names::Find<Node> ("/synthetic", "p1")); |
| 135 | ccnxHelper.InstallRouteTo (Names::Find<Node> ("/synthetic", "p2")); |
| 136 | ccnxHelper.InstallRouteTo (Names::Find<Node> ("/synthetic", "p3")); |
| 137 | ccnxHelper.InstallRouteTo (Names::Find<Node> ("/synthetic", "p4")); |
| 138 | |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 139 | Simulator::Schedule (Seconds (10.0), PrintTime); |
| 140 | |
Alexander Afanasyev | 8f5a9bb | 2011-12-18 19:49:02 -0800 | [diff] [blame] | 141 | Simulator::Stop (finishTime); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 142 | |
Alexander Afanasyev | c86c283 | 2011-12-23 02:56:22 -0800 | [diff] [blame] | 143 | CcnxTraceHelper traceHelper; |
| 144 | // traceHelper.EnableAggregateAppAll ("ns3::CcnxConsumer"); |
| 145 | // traceHelper.EnableAggregateAppAll ("ns3::CcnxProducer"); |
| 146 | // traceHelper.EnableAggregateL3All (); |
| 147 | // traceHelper.SetL3TraceFile ("trace-l3.log"); |
| 148 | // traceHelper.SetAppTraceFile ("trace-app.log"); |
| 149 | traceHelper.EnableRateL3All ("rate-trace.log"); |
| 150 | |
Alexander Afanasyev | 8f5a9bb | 2011-12-18 19:49:02 -0800 | [diff] [blame] | 151 | NS_LOG_INFO ("Run Simulation."); |
| 152 | Simulator::Run (); |
| 153 | Simulator::Destroy (); |
| 154 | NS_LOG_INFO ("Done."); |
| 155 | |
| 156 | return 0; |
Ilya Moiseenko | 6f5e8fa | 2011-12-16 15:20:19 -0800 | [diff] [blame] | 157 | } |