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" |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -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 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 36 | #include "ns3/config-store.h" |
| 37 | |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 38 | using namespace ns3; |
| 39 | using namespace std; |
| 40 | |
| 41 | NS_LOG_COMPONENT_DEFINE ("CcnxAbileneTopology"); |
| 42 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 43 | // int transmittedInterests = 0; |
| 44 | // int receivedInterests = 0; |
| 45 | // int droppedInterests = 0; |
Ilya Moiseenko | 816de83 | 2011-12-15 16:32:24 -0800 | [diff] [blame] | 46 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 47 | // int transmittedData = 0; |
| 48 | // int receivedData = 0; |
| 49 | // int droppedData = 0; |
Ilya Moiseenko | 816de83 | 2011-12-15 16:32:24 -0800 | [diff] [blame] | 50 | |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 51 | void PrintTime () |
| 52 | { |
| 53 | NS_LOG_INFO (Simulator::Now ()); |
| 54 | |
| 55 | Simulator::Schedule (Seconds (10.0), PrintTime); |
| 56 | } |
| 57 | |
| 58 | void PrintFIBs () |
| 59 | { |
| 60 | NS_LOG_INFO ("Outputing FIBs into [fibs.log]"); |
| 61 | Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("fibs.log", std::ios::out); |
| 62 | for (NodeList::Iterator node = NodeList::Begin (); |
| 63 | node != NodeList::End (); |
| 64 | node++) |
| 65 | { |
| 66 | // *routingStream->GetStream () << "Node " << (*node)->GetId () << "\n"; |
| 67 | |
| 68 | Ptr<CcnxFib> fib = (*node)->GetObject<CcnxFib> (); |
| 69 | NS_ASSERT_MSG (fib != 0, "Fire alarm"); |
| 70 | *routingStream->GetStream () << *fib << "\n\n"; |
| 71 | } |
| 72 | } |
| 73 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 74 | |
| 75 | struct AggregateTrace |
Ilya Moiseenko | 816de83 | 2011-12-15 16:32:24 -0800 | [diff] [blame] | 76 | { |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 77 | AggregateTrace () |
| 78 | : m_transmittedInterests (0) |
| 79 | , m_transmittedData (0) |
| 80 | , m_receivedInterests (0) |
| 81 | , m_receivedNacks (0) |
| 82 | , m_receivedData (0) |
| 83 | { |
| 84 | } |
| 85 | |
| 86 | void |
| 87 | TransmittedInterests (std::string context, |
| 88 | Ptr<const CcnxInterestHeader>, Ptr<CcnxApp>, Ptr<CcnxFace>) |
| 89 | { |
| 90 | m_transmittedInterests++; |
| 91 | } |
| 92 | |
| 93 | void |
| 94 | TransmittedData (std::string context, |
| 95 | Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>, |
| 96 | Ptr<CcnxApp>, Ptr<CcnxFace>) |
| 97 | { |
| 98 | m_transmittedData++; |
| 99 | } |
| 100 | |
| 101 | void |
| 102 | ReceivedInterests (std::string context, |
| 103 | Ptr<const CcnxInterestHeader>, |
| 104 | Ptr<CcnxApp>, Ptr<CcnxFace>) |
| 105 | { |
| 106 | m_receivedInterests++; |
| 107 | } |
| 108 | |
| 109 | void |
| 110 | ReceivedNacks (std::string context, |
| 111 | Ptr<const CcnxInterestHeader>, |
| 112 | Ptr<CcnxApp>, Ptr<CcnxFace>) |
| 113 | { |
| 114 | m_receivedNacks++; |
| 115 | } |
| 116 | |
| 117 | void |
| 118 | ReceivedData (std::string context, |
| 119 | Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>, |
| 120 | Ptr<CcnxApp>, Ptr<CcnxFace>) |
| 121 | { |
| 122 | m_receivedData++; |
| 123 | } |
| 124 | |
| 125 | uint64_t m_transmittedInterests; |
| 126 | uint64_t m_transmittedData; |
| 127 | uint64_t m_receivedInterests; |
| 128 | uint64_t m_receivedNacks; |
| 129 | uint64_t m_receivedData; |
| 130 | }; |
| 131 | |
| 132 | ostream& |
| 133 | operator << (ostream &os, const AggregateTrace &trace) |
| 134 | { |
| 135 | os << ">> (i): " << trace.m_transmittedInterests << "\n"; |
| 136 | os << ">> (d): " << trace.m_transmittedData << "\n"; |
| 137 | os << "<< (i): " << trace.m_receivedInterests << "\n"; |
| 138 | os << "<< (d): " << trace.m_receivedData << "\n"; |
| 139 | os << "<< (n): " << trace.m_receivedNacks << "\n"; |
| 140 | return os; |
Ilya Moiseenko | 816de83 | 2011-12-15 16:32:24 -0800 | [diff] [blame] | 141 | } |
| 142 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 143 | // static void OnTransmittedInterest (std::string context, Ptr<const CcnxInterestHeader> header, |
| 144 | // Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face) |
| 145 | // { |
| 146 | // transmittedInterests++; |
| 147 | // } |
Ilya Moiseenko | 816de83 | 2011-12-15 16:32:24 -0800 | [diff] [blame] | 148 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 149 | // static void OnReceivedInterest (std::string context, Ptr<const CcnxInterestHeader> header, |
| 150 | // Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face) |
| 151 | // { |
| 152 | // receivedInterests++; |
| 153 | // } |
Ilya Moiseenko | 816de83 | 2011-12-15 16:32:24 -0800 | [diff] [blame] | 154 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 155 | // static void OnDroppedInterest (std::string context, Ptr<const CcnxInterestHeader> header, CcnxL3Protocol::DropReason reason, |
| 156 | // Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face) |
| 157 | // { |
| 158 | // droppedInterests++; |
| 159 | // } |
Ilya Moiseenko | 816de83 | 2011-12-15 16:32:24 -0800 | [diff] [blame] | 160 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 161 | // static void OnTransmittedData (std::string context, Ptr<const CcnxContentObjectHeader> header, Ptr<const Packet> packet, |
| 162 | // CcnxL3Protocol::ContentObjectSource source, Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face) |
| 163 | // { |
| 164 | // transmittedData++; |
| 165 | // } |
Ilya Moiseenko | 816de83 | 2011-12-15 16:32:24 -0800 | [diff] [blame] | 166 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 167 | // static void OnReceivedData (std::string context, Ptr<const CcnxContentObjectHeader> header, Ptr<const Packet> packet, |
| 168 | // Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face) |
| 169 | // { |
| 170 | // receivedData++; |
| 171 | // } |
| 172 | |
| 173 | // static void OnDroppedData (std::string context, Ptr<const CcnxContentObjectHeader> header, Ptr<const Packet> packet, |
| 174 | // CcnxL3Protocol::DropReason reason, Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face ) |
| 175 | // { |
| 176 | // droppedData++; |
| 177 | // } |
Ilya Moiseenko | 816de83 | 2011-12-15 16:32:24 -0800 | [diff] [blame] | 178 | |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 179 | int |
| 180 | main (int argc, char *argv[]) |
| 181 | { |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 182 | // Packet::EnableChecking(); |
| 183 | // Packet::EnablePrinting(); |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 184 | string input ("./src/NDNabstraction/examples/abilene-topology.txt"); |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 185 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 186 | Time finishTime = Seconds (20.0); |
| 187 | string animationFile; |
| 188 | string strategy = "ns3::CcnxFloodingStrategy"; |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 189 | CommandLine cmd; |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 190 | cmd.AddValue ("finish", "Finish time", finishTime); |
| 191 | cmd.AddValue ("netanim", "NetAnim filename", animationFile); |
| 192 | cmd.AddValue ("strategy", "CCNx forwarding strategy", strategy); |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 193 | cmd.Parse (argc, argv); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 194 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 195 | ConfigStore config; |
| 196 | config.ConfigureDefaults (); |
| 197 | |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 198 | // ------------------------------------------------------------ |
| 199 | // -- Read topology data. |
| 200 | // -------------------------------------------- |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 201 | |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 202 | AnnotatedTopologyReader reader ("/abilene"); |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 203 | reader.SetMobilityModel ("ns3::SpringMobilityModel"); |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 204 | reader.SetFileName (input); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 205 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 206 | NodeContainer nodes = reader.Read (); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 207 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 208 | if (reader.LinksSize () == 0) |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 209 | { |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 210 | NS_LOG_ERROR ("Problems reading the topology file. Failing."); |
| 211 | return -1; |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 212 | } |
| 213 | |
Alexander Afanasyev | 7dbdcaf | 2011-12-13 21:40:37 -0800 | [diff] [blame] | 214 | SpringMobilityHelper::InstallSprings (reader.LinksBegin (), reader.LinksEnd ()); |
| 215 | |
Alexander Afanasyev | a174aa5 | 2011-12-13 01:30:32 -0800 | [diff] [blame] | 216 | // InternetStackHelper stack; |
| 217 | // Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops"); |
| 218 | // stack.SetRoutingHelper (ipv4RoutingHelper); |
| 219 | // stack.Install (nodes); |
| 220 | |
| 221 | // reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0")); |
| 222 | |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 223 | NS_LOG_INFO("Nodes = " << nodes.GetN()); |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 224 | NS_LOG_INFO("Links = " << reader.LinksSize ()); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 225 | |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 226 | // Install CCNx stack |
| 227 | NS_LOG_INFO ("Installing CCNx stack"); |
| 228 | CcnxStackHelper ccnxHelper; |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 229 | ccnxHelper.SetForwardingStrategy (strategy); |
| 230 | ccnxHelper.EnableLimits (false, Seconds(0.1)); |
| 231 | ccnxHelper.SetDefaultRoutes (true); |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 232 | ccnxHelper.InstallAll (); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 233 | |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 234 | NS_LOG_INFO ("Installing Applications"); |
Alexander Afanasyev | a174aa5 | 2011-12-13 01:30:32 -0800 | [diff] [blame] | 235 | CcnxConsumerHelper consumerHelper ("/5"); |
Alexander Afanasyev | 66e6fd7 | 2011-12-12 21:34:51 -0800 | [diff] [blame] | 236 | ApplicationContainer consumers = consumerHelper.Install (Names::Find<Node> ("/abilene", "ATLAng")); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 237 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 238 | // CcnxProducerHelper producerHelper ("/5",1024); |
| 239 | // ApplicationContainer producers = producerHelper.Install (Names::Find<Node> ("/abilene", "IPLSng")); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 240 | |
Alexander Afanasyev | a174aa5 | 2011-12-13 01:30:32 -0800 | [diff] [blame] | 241 | // // Populate FIB based on IPv4 global routing controller |
| 242 | // ccnxHelper.InstallFakeGlobalRoutes (); |
| 243 | // ccnxHelper.InstallRouteTo (Names::Find<Node> ("/abilene", "IPLSng")); |
| 244 | |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 245 | // Simulator::Schedule (Seconds (1.0), PrintFIBs); |
Alexander Afanasyev | a174aa5 | 2011-12-13 01:30:32 -0800 | [diff] [blame] | 246 | // PrintFIBs (); |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 247 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 248 | // Simulator::Schedule (Seconds (10.0), PrintTime); |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 249 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 250 | Simulator::Stop (finishTime); |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 251 | |
| 252 | AnimationInterface *anim = 0; |
| 253 | if (animationFile != "") |
| 254 | { |
| 255 | anim = new AnimationInterface (animationFile); |
| 256 | anim->SetMobilityPollInterval (Seconds (1)); |
| 257 | } |
| 258 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 259 | // NS_LOG_INFO ("Configure Tracing."); |
| 260 | AggregateTrace trace; |
| 261 | Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::CcnxConsumer/TransmittedInterests", |
| 262 | MakeCallback (&AggregateTrace::TransmittedInterests, &trace)); |
Ilya Moiseenko | 816de83 | 2011-12-15 16:32:24 -0800 | [diff] [blame] | 263 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 264 | Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::CcnxConsumer/ReceivedNacks", |
| 265 | MakeCallback (&AggregateTrace::ReceivedNacks, &trace)); |
| 266 | |
| 267 | Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::CcnxProducer/ReceivedInterests", |
| 268 | MakeCallback (&AggregateTrace::ReceivedInterests, &trace)); |
| 269 | |
| 270 | Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::CcnxProducer/TransmittedContentObjects", |
| 271 | MakeCallback (&AggregateTrace::TransmittedData, &trace)); |
| 272 | |
| 273 | Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::CcnxConsumer/ReceivedContentObjects", |
| 274 | MakeCallback (&AggregateTrace::ReceivedData, &trace)); |
| 275 | |
| 276 | // Config::Connect("/NodeList/*/ns3::CcnxL3Protocol/TransmittedInterestTrace", |
| 277 | // MakeCallback (&OnTransmittedInterest)); |
| 278 | // Config::Connect ("/NodeList/*/ns3::CcnxL3Protocol/ReceivedInterestTrace", |
| 279 | // MakeCallback (&OnReceivedInterest)); |
| 280 | // Config::Connect ("/NodeList/*/ns3::CcnxL3Protocol/DroppedInterestTrace", |
| 281 | // MakeCallback (&OnDroppedInterest)); |
| 282 | |
| 283 | // Config::Connect ("/NodeList/*/ns3::CcnxL3Protocol/ReceivedDataTrace", |
| 284 | // MakeCallback (&OnReceivedData)); |
| 285 | // Config::Connect ("/NodeList/*/ns3::CcnxL3Protocol/TransmittedDataTrace", |
| 286 | // MakeCallback (&OnTransmittedData)); |
| 287 | // Config::Connect ("/NodeList/*/ns3::CcnxL3Protocol/DroppedDataTrace", |
| 288 | // MakeCallback (&OnDroppedData)); |
| 289 | |
| 290 | config.ConfigureAttributes (); |
| 291 | |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 292 | NS_LOG_INFO ("Run Simulation."); |
| 293 | Simulator::Run (); |
| 294 | Simulator::Destroy (); |
| 295 | NS_LOG_INFO ("Done."); |
Ilya Moiseenko | 816de83 | 2011-12-15 16:32:24 -0800 | [diff] [blame] | 296 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 297 | // NS_LOG_INFO("Total received interests = " << receivedInterests); |
| 298 | // NS_LOG_INFO("Total transmitted interests = " << transmittedInterests); |
| 299 | // NS_LOG_INFO("Total dropped interests = " << droppedInterests); |
| 300 | // NS_LOG_INFO("Total received data = " << receivedData); |
| 301 | // NS_LOG_INFO("Total transmitted data = " << transmittedData); |
| 302 | // NS_LOG_INFO("Total dropped data = " << droppedData); |
| 303 | NS_LOG_INFO (trace); |
Alexander Afanasyev | 3406f3e | 2011-12-08 14:11:31 -0800 | [diff] [blame] | 304 | return 0; |
| 305 | } |