Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -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 | |
| 29 | #include <iostream> |
| 30 | #include <sstream> |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 31 | #include "ns3/rocketfuel-topology-reader.h" |
| 32 | |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 33 | using namespace ns3; |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 34 | using namespace std; |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 35 | |
| 36 | NS_LOG_COMPONENT_DEFINE ("CcnxSprintTopology"); |
| 37 | |
Alexander Afanasyev | 5beb35a | 2011-12-21 16:45:13 -0800 | [diff] [blame^] | 38 | void PrintTime () |
| 39 | { |
| 40 | NS_LOG_INFO (Simulator::Now ()); |
| 41 | |
| 42 | Simulator::Schedule (Seconds (1.0), PrintTime); |
| 43 | } |
| 44 | |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 45 | int |
| 46 | main (int argc, char *argv[]) |
| 47 | { |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 48 | // Packet::EnableChecking(); |
| 49 | // Packet::EnablePrinting(); |
| 50 | string weights ("./src/NDNabstraction/examples/sprint.weights"); |
| 51 | string latencies ("./src/NDNabstraction/examples/sprint.latencies"); |
Alexander Afanasyev | 5beb35a | 2011-12-21 16:45:13 -0800 | [diff] [blame^] | 52 | string positions; |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 53 | |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 54 | Time finishTime = Seconds (2.0); |
| 55 | string animationFile; |
| 56 | string strategy = "ns3::CcnxFloodingStrategy"; |
Alexander Afanasyev | 5beb35a | 2011-12-21 16:45:13 -0800 | [diff] [blame^] | 57 | string save; |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 58 | CommandLine cmd; |
| 59 | cmd.AddValue ("finish", "Finish time", finishTime); |
| 60 | cmd.AddValue ("netanim", "NetAnim filename", animationFile); |
| 61 | cmd.AddValue ("strategy", "CCNx forwarding strategy", strategy); |
| 62 | cmd.AddValue ("weights", "Weights file", weights); |
| 63 | cmd.AddValue ("latencies", "Latencies file", latencies); |
Alexander Afanasyev | 5beb35a | 2011-12-21 16:45:13 -0800 | [diff] [blame^] | 64 | cmd.AddValue ("positions", "Positions files", positions); |
| 65 | cmd.AddValue ("save", "Save positions to a file", save); |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 66 | cmd.Parse (argc, argv); |
Alexander Afanasyev | ae3b7c3 | 2011-12-13 13:20:06 -0800 | [diff] [blame] | 67 | |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 68 | // ------------------------------------------------------------ |
| 69 | // -- Read topology data. |
| 70 | // -------------------------------------------- |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 71 | |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 72 | RocketfuelWeightsReader reader ("/sprint"); |
| 73 | reader.SetBoundingBox (0, 0, 400, 250); |
| 74 | |
Alexander Afanasyev | 5beb35a | 2011-12-21 16:45:13 -0800 | [diff] [blame^] | 75 | if (!positions.empty()) |
| 76 | { |
| 77 | reader.SetFileName (positions); |
| 78 | reader.SetFileType (RocketfuelWeightsReader::POSITIONS); |
| 79 | reader.Read (); |
| 80 | } |
| 81 | |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 82 | reader.SetFileName (weights); |
| 83 | reader.SetFileType (RocketfuelWeightsReader::WEIGHTS); |
Alexander Afanasyev | 5beb35a | 2011-12-21 16:45:13 -0800 | [diff] [blame^] | 84 | reader.Read (); |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 85 | |
| 86 | reader.SetFileName (latencies); |
| 87 | reader.SetFileType (RocketfuelWeightsReader::LATENCIES); |
| 88 | reader.Read (); |
| 89 | |
| 90 | reader.Commit (); |
| 91 | if (reader.LinksSize () == 0) |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 92 | { |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 93 | NS_LOG_ERROR ("Problems reading the topology file. Failing."); |
| 94 | return -1; |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 95 | } |
| 96 | |
Alexander Afanasyev | 5beb35a | 2011-12-21 16:45:13 -0800 | [diff] [blame^] | 97 | NS_LOG_INFO("Nodes = " << reader.GetNodes ().GetN()); |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 98 | NS_LOG_INFO("Links = " << reader.LinksSize ()); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 99 | |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 100 | InternetStackHelper stack; |
| 101 | Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops"); |
| 102 | stack.SetRoutingHelper (ipv4RoutingHelper); |
Alexander Afanasyev | 5beb35a | 2011-12-21 16:45:13 -0800 | [diff] [blame^] | 103 | stack.Install (reader.GetNodes ()); |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 104 | |
| 105 | reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0")); |
| 106 | |
| 107 | // Install CCNx stack |
| 108 | NS_LOG_INFO ("Installing CCNx stack"); |
| 109 | CcnxStackHelper ccnxHelper; |
| 110 | ccnxHelper.SetForwardingStrategy (strategy); |
| 111 | ccnxHelper.EnableLimits (false, Seconds(0.1)); |
| 112 | ccnxHelper.SetDefaultRoutes (true); |
| 113 | ccnxHelper.InstallAll (); |
| 114 | |
| 115 | // // Populate FIB based on IPv4 global routing controller |
| 116 | // ccnxHelper.InstallFakeGlobalRoutes (); |
| 117 | // ccnxHelper.InstallRouteTo (Names::Find<Node> ("/sprint", "San+Jose,+CA4062")); |
| 118 | |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 119 | Simulator::Stop (finishTime); |
Alexander Afanasyev | 5beb35a | 2011-12-21 16:45:13 -0800 | [diff] [blame^] | 120 | Simulator::Schedule (Seconds (1.0), PrintTime); |
| 121 | |
| 122 | // reader.SavePositions (save+".debug"); |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 123 | |
| 124 | NS_LOG_INFO ("Run Simulation."); |
| 125 | Simulator::Run (); |
| 126 | Simulator::Destroy (); |
| 127 | NS_LOG_INFO ("Done."); |
Alexander Afanasyev | 5beb35a | 2011-12-21 16:45:13 -0800 | [diff] [blame^] | 128 | |
| 129 | if (!save.empty ()) |
| 130 | { |
| 131 | NS_LOG_INFO ("Saving positions."); |
| 132 | reader.SavePositions (save); |
| 133 | } |
| 134 | |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 135 | return 0; |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 136 | } |