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