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