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 | 816de83 | 2011-12-15 16:32:24 -0800 | [diff] [blame^] | 29 | #include "ns3/ccnx-l3-protocol.h" |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 30 | |
| 31 | #include <iostream> |
| 32 | #include <sstream> |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 33 | #include "ns3/annotated-topology-reader.h" |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 34 | #include "../utils/spring-mobility-helper.h" |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 35 | |
| 36 | using namespace ns3; |
| 37 | using namespace std; |
| 38 | |
| 39 | NS_LOG_COMPONENT_DEFINE ("CcnxAbileneTopology"); |
| 40 | |
Ilya Moiseenko | 816de83 | 2011-12-15 16:32:24 -0800 | [diff] [blame^] | 41 | int transmittedInterests = 0; |
| 42 | int receivedInterests = 0; |
| 43 | int droppedInterests = 0; |
| 44 | |
| 45 | int transmittedData = 0; |
| 46 | int receivedData = 0; |
| 47 | int droppedData = 0; |
| 48 | |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 49 | void PrintTime () |
| 50 | { |
| 51 | NS_LOG_INFO (Simulator::Now ()); |
| 52 | |
| 53 | Simulator::Schedule (Seconds (10.0), PrintTime); |
| 54 | } |
| 55 | |
| 56 | void PrintFIBs () |
| 57 | { |
| 58 | NS_LOG_INFO ("Outputing FIBs into [fibs.log]"); |
| 59 | Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("fibs.log", std::ios::out); |
| 60 | for (NodeList::Iterator node = NodeList::Begin (); |
| 61 | node != NodeList::End (); |
| 62 | node++) |
| 63 | { |
| 64 | // *routingStream->GetStream () << "Node " << (*node)->GetId () << "\n"; |
| 65 | |
| 66 | Ptr<CcnxFib> fib = (*node)->GetObject<CcnxFib> (); |
| 67 | NS_ASSERT_MSG (fib != 0, "Fire alarm"); |
| 68 | *routingStream->GetStream () << *fib << "\n\n"; |
| 69 | } |
| 70 | } |
| 71 | |
Ilya Moiseenko | 816de83 | 2011-12-15 16:32:24 -0800 | [diff] [blame^] | 72 | static void OnTransmittedInterest (std::string context, Ptr<const CcnxInterestHeader> header, |
| 73 | Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face) |
| 74 | { |
| 75 | transmittedInterests++; |
| 76 | } |
| 77 | |
| 78 | static void OnReceivedInterest (std::string context, Ptr<const CcnxInterestHeader> header, |
| 79 | Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face) |
| 80 | { |
| 81 | receivedInterests++; |
| 82 | } |
| 83 | |
| 84 | static void OnDroppedInterest (std::string context, Ptr<const CcnxInterestHeader> header, CcnxL3Protocol::DropReason reason, |
| 85 | Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face) |
| 86 | { |
| 87 | droppedInterests++; |
| 88 | } |
| 89 | |
| 90 | static void OnTransmittedData (std::string context, Ptr<const CcnxContentObjectHeader> header, Ptr<const Packet> packet, |
| 91 | CcnxL3Protocol::ContentObjectSource source, Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face) |
| 92 | { |
| 93 | transmittedData++; |
| 94 | } |
| 95 | |
| 96 | static void OnReceivedData (std::string context, Ptr<const CcnxContentObjectHeader> header, Ptr<const Packet> packet, |
| 97 | Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face) |
| 98 | { |
| 99 | receivedData++; |
| 100 | } |
| 101 | |
| 102 | static void OnDroppedData (std::string context, Ptr<const CcnxContentObjectHeader> header, Ptr<const Packet> packet, |
| 103 | CcnxL3Protocol::DropReason reason, Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face ) |
| 104 | { |
| 105 | droppedData++; |
| 106 | } |
| 107 | |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 108 | int |
| 109 | main (int argc, char *argv[]) |
| 110 | { |
Ilya Moiseenko | 816de83 | 2011-12-15 16:32:24 -0800 | [diff] [blame^] | 111 | Packet::EnableChecking(); |
| 112 | Packet::EnablePrinting(); |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 113 | string input ("./src/NDNabstraction/examples/abilene-topology.txt"); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 114 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 115 | Time finishTime = Seconds (20.0); |
| 116 | string animationFile; |
| 117 | string strategy = "ns3::CcnxFloodingStrategy"; |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 118 | CommandLine cmd; |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 119 | cmd.AddValue ("finish", "Finish time", finishTime); |
| 120 | cmd.AddValue ("netanim", "NetAnim filename", animationFile); |
| 121 | cmd.AddValue ("strategy", "CCNx forwarding strategy", strategy); |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 122 | cmd.Parse (argc, argv); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 123 | |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 124 | // ------------------------------------------------------------ |
| 125 | // -- Read topology data. |
| 126 | // -------------------------------------------- |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 127 | |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 128 | AnnotatedTopologyReader reader ("/abilene"); |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 129 | reader.SetMobilityModel ("ns3::SpringMobilityModel"); |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 130 | reader.SetFileName (input); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 131 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 132 | NodeContainer nodes = reader.Read (); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 133 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 134 | if (reader.LinksSize () == 0) |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 135 | { |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 136 | NS_LOG_ERROR ("Problems reading the topology file. Failing."); |
| 137 | return -1; |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 138 | } |
| 139 | |
Ilya Moiseenko | 816de83 | 2011-12-15 16:32:24 -0800 | [diff] [blame^] | 140 | int droppedInterests[nodes.GetN()]; |
| 141 | int congestedInterests[nodes.GetN()]; |
| 142 | int sentInterests[nodes.GetN()]; |
| 143 | (void)droppedInterests; |
| 144 | (void)sentInterests; |
| 145 | (void)congestedInterests; |
| 146 | |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 147 | SpringMobilityHelper::InstallSprings (reader.LinksBegin (), reader.LinksEnd ()); |
| 148 | |
Alexander Afanasyev | a174aa5 | 2011-12-13 01:30:32 -0800 | [diff] [blame] | 149 | // InternetStackHelper stack; |
| 150 | // Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops"); |
| 151 | // stack.SetRoutingHelper (ipv4RoutingHelper); |
| 152 | // stack.Install (nodes); |
| 153 | |
| 154 | // reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0")); |
| 155 | |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 156 | NS_LOG_INFO("Nodes = " << nodes.GetN()); |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 157 | NS_LOG_INFO("Links = " << reader.LinksSize ()); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 158 | |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 159 | // Install CCNx stack |
| 160 | NS_LOG_INFO ("Installing CCNx stack"); |
| 161 | CcnxStackHelper ccnxHelper; |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 162 | ccnxHelper.SetForwardingStrategy (strategy); |
| 163 | ccnxHelper.EnableLimits (false, Seconds(0.1)); |
| 164 | ccnxHelper.SetDefaultRoutes (true); |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 165 | ccnxHelper.InstallAll (); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 166 | |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 167 | NS_LOG_INFO ("Installing Applications"); |
Alexander Afanasyev | a174aa5 | 2011-12-13 01:30:32 -0800 | [diff] [blame] | 168 | CcnxConsumerHelper consumerHelper ("/5"); |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 169 | ApplicationContainer consumers = consumerHelper.Install (Names::Find<Node> ("/abilene", "ATLAng")); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 170 | |
Alexander Afanasyev | a174aa5 | 2011-12-13 01:30:32 -0800 | [diff] [blame] | 171 | CcnxProducerHelper producerHelper ("/5",1024); |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 172 | ApplicationContainer producers = producerHelper.Install (Names::Find<Node> ("/abilene", "IPLSng")); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 173 | |
Alexander Afanasyev | a174aa5 | 2011-12-13 01:30:32 -0800 | [diff] [blame] | 174 | // // Populate FIB based on IPv4 global routing controller |
| 175 | // ccnxHelper.InstallFakeGlobalRoutes (); |
| 176 | // ccnxHelper.InstallRouteTo (Names::Find<Node> ("/abilene", "IPLSng")); |
| 177 | |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 178 | // Simulator::Schedule (Seconds (1.0), PrintFIBs); |
Alexander Afanasyev | a174aa5 | 2011-12-13 01:30:32 -0800 | [diff] [blame] | 179 | // PrintFIBs (); |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 180 | |
| 181 | Simulator::Schedule (Seconds (10.0), PrintTime); |
| 182 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 183 | Simulator::Stop (finishTime); |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 184 | |
| 185 | AnimationInterface *anim = 0; |
| 186 | if (animationFile != "") |
| 187 | { |
| 188 | anim = new AnimationInterface (animationFile); |
| 189 | anim->SetMobilityPollInterval (Seconds (1)); |
| 190 | } |
| 191 | |
Ilya Moiseenko | 816de83 | 2011-12-15 16:32:24 -0800 | [diff] [blame^] | 192 | NS_LOG_INFO ("Configure Tracing."); |
| 193 | // first, pcap tracing in non-promiscuous mode |
| 194 | //ccnxHelper.EnablePcapAll ("csma-ping", false); |
| 195 | // then, print what the packet sink receives. |
| 196 | //Config::ConnectWithoutContext ("/NodeList/3/ApplicationList/0/$ns3::PacketSink/Rx", |
| 197 | // MakeCallback (&SinkRx)); |
| 198 | // finally, print the ping rtts. |
| 199 | //Packet::EnablePrinting (); |
| 200 | Config::Connect("/NodeList/*/ns3::CcnxL3Protocol/TransmittedInterestTrace", |
| 201 | MakeCallback (&OnTransmittedInterest)); |
| 202 | Config::Connect ("/NodeList/*/ns3::CcnxL3Protocol/ReceivedInterestTrace", |
| 203 | MakeCallback (&OnReceivedInterest)); |
| 204 | Config::Connect ("/NodeList/*/ns3::CcnxL3Protocol/DroppedInterestTrace", |
| 205 | MakeCallback (&OnDroppedInterest)); |
| 206 | |
| 207 | Config::Connect ("/NodeList/*/ns3::CcnxL3Protocol/ReceivedDataTrace", |
| 208 | MakeCallback (&OnReceivedData)); |
| 209 | Config::Connect ("/NodeList/*/ns3::CcnxL3Protocol/TransmittedDataTrace", |
| 210 | MakeCallback (&OnTransmittedData)); |
| 211 | Config::Connect ("/NodeList/*/ns3::CcnxL3Protocol/DroppedDataTrace", |
| 212 | MakeCallback (&OnDroppedData)); |
| 213 | |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 214 | NS_LOG_INFO ("Run Simulation."); |
| 215 | Simulator::Run (); |
| 216 | Simulator::Destroy (); |
| 217 | NS_LOG_INFO ("Done."); |
Ilya Moiseenko | 816de83 | 2011-12-15 16:32:24 -0800 | [diff] [blame^] | 218 | |
| 219 | NS_LOG_INFO("Total received interests = " << receivedInterests); |
| 220 | NS_LOG_INFO("Total transmitted interests = " << transmittedInterests); |
| 221 | NS_LOG_INFO("Total dropped interests = " << droppedInterests); |
| 222 | NS_LOG_INFO("Total received data = " << receivedData); |
| 223 | NS_LOG_INFO("Total transmitted data = " << transmittedData); |
| 224 | NS_LOG_INFO("Total dropped data = " << droppedData); |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 225 | return 0; |
| 226 | } |