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" |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame^] | 28 | #include "ns3/animation-interface.h" |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 29 | |
| 30 | #include <iostream> |
| 31 | #include <sstream> |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 32 | #include "ns3/annotated-topology-reader.h" |
| 33 | |
| 34 | using namespace ns3; |
| 35 | using namespace std; |
| 36 | |
| 37 | NS_LOG_COMPONENT_DEFINE ("CcnxAbileneTopology"); |
| 38 | |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame^] | 39 | void PrintTime () |
| 40 | { |
| 41 | NS_LOG_INFO (Simulator::Now ()); |
| 42 | |
| 43 | Simulator::Schedule (Seconds (10.0), PrintTime); |
| 44 | } |
| 45 | |
| 46 | void PrintFIBs () |
| 47 | { |
| 48 | NS_LOG_INFO ("Outputing FIBs into [fibs.log]"); |
| 49 | Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("fibs.log", std::ios::out); |
| 50 | for (NodeList::Iterator node = NodeList::Begin (); |
| 51 | node != NodeList::End (); |
| 52 | node++) |
| 53 | { |
| 54 | // *routingStream->GetStream () << "Node " << (*node)->GetId () << "\n"; |
| 55 | |
| 56 | Ptr<CcnxFib> fib = (*node)->GetObject<CcnxFib> (); |
| 57 | NS_ASSERT_MSG (fib != 0, "Fire alarm"); |
| 58 | *routingStream->GetStream () << *fib << "\n\n"; |
| 59 | } |
| 60 | } |
| 61 | |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 62 | int |
| 63 | main (int argc, char *argv[]) |
| 64 | { |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 65 | // Packet::EnableChecking(); |
| 66 | // Packet::EnablePrinting(); |
| 67 | string input ("./src/NDNabstraction/examples/abilene-topology.txt"); |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 68 | |
| 69 | Time finishTime = Seconds (20.0); |
| 70 | string animationFile; |
| 71 | string strategy = "ns3::CcnxFloodingStrategy"; |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 72 | CommandLine cmd; |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 73 | cmd.AddValue ("finish", "Finish time", finishTime); |
| 74 | cmd.AddValue ("netanim", "NetAnim filename", animationFile); |
| 75 | cmd.AddValue ("strategy", "CCNx forwarding strategy", strategy); |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 76 | cmd.Parse (argc, argv); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 77 | |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 78 | // ------------------------------------------------------------ |
| 79 | // -- Read topology data. |
| 80 | // -------------------------------------------- |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 81 | |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame^] | 82 | AnnotatedTopologyReader reader ("/abilene"); |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 83 | reader.SetFileName (input); |
| 84 | reader.SetBoundingBox (100.0, 100.0, 400.0, 400.0); |
| 85 | |
| 86 | NodeContainer nodes = reader.Read (); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 87 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 88 | if (reader.LinksSize () == 0) |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 89 | { |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 90 | NS_LOG_ERROR ("Problems reading the topology file. Failing."); |
| 91 | return -1; |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 92 | } |
| 93 | |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 94 | NS_LOG_INFO("Nodes = " << nodes.GetN()); |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 95 | NS_LOG_INFO("Links = " << reader.LinksSize ()); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 96 | |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 97 | // Install CCNx stack |
| 98 | NS_LOG_INFO ("Installing CCNx stack"); |
| 99 | CcnxStackHelper ccnxHelper; |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame^] | 100 | ccnxHelper.SetForwardingStrategy (strategy); |
| 101 | ccnxHelper.EnableLimits (false, Seconds(0.1)); |
| 102 | ccnxHelper.SetDefaultRoutes (true); |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 103 | ccnxHelper.InstallAll (); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 104 | |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame^] | 105 | NS_LOG_INFO ("Installing Applications"); |
| 106 | CcnxConsumerHelper consumerHelper ("tralala"); |
| 107 | ApplicationContainer consumers = consumerHelper.Install (Names::Find<Node> ("/abilene", "1")); |
| 108 | |
| 109 | CcnxProducerHelper producerHelper ("tralala",1024); |
| 110 | ApplicationContainer producers = producerHelper.Install (Names::Find<Node> ("/abilene", "6")); |
| 111 | |
| 112 | // Simulator::Schedule (Seconds (1.0), PrintFIBs); |
| 113 | PrintFIBs (); |
| 114 | |
| 115 | Simulator::Schedule (Seconds (10.0), PrintTime); |
| 116 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 117 | Simulator::Stop (finishTime); |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame^] | 118 | |
| 119 | AnimationInterface *anim = 0; |
| 120 | if (animationFile != "") |
| 121 | { |
| 122 | anim = new AnimationInterface (animationFile); |
| 123 | anim->SetMobilityPollInterval (Seconds (1)); |
| 124 | } |
| 125 | |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 126 | NS_LOG_INFO ("Run Simulation."); |
| 127 | Simulator::Run (); |
| 128 | Simulator::Destroy (); |
| 129 | NS_LOG_INFO ("Done."); |
| 130 | return 0; |
| 131 | } |