Ilya Moiseenko | 6f5e8fa | 2011-12-16 15:20:19 -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 | #include "ns3/animation-interface.h" |
| 29 | // #include "ns3/ccnx-l3-protocol.h" |
| 30 | |
| 31 | #include <iostream> |
| 32 | #include <sstream> |
| 33 | #include "ns3/annotated-topology-reader.h" |
| 34 | #include "../utils/spring-mobility-helper.h" |
| 35 | |
| 36 | #include "ns3/config-store.h" |
| 37 | |
| 38 | using namespace ns3; |
| 39 | using namespace std; |
| 40 | |
| 41 | NS_LOG_COMPONENT_DEFINE ("CcnxSyntheticTopology"); |
| 42 | |
| 43 | // int transmittedInterests = 0; |
| 44 | // int receivedInterests = 0; |
| 45 | // int droppedInterests = 0; |
| 46 | |
| 47 | // int transmittedData = 0; |
| 48 | // int receivedData = 0; |
| 49 | // int droppedData = 0; |
| 50 | |
| 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 | |
| 74 | |
| 75 | struct AggregateTrace |
| 76 | { |
| 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; |
| 141 | } |
| 142 | |
| 143 | // static void OnTransmittedInterest (std::string context, Ptr<const CcnxInterestHeader> header, |
| 144 | // Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face) |
| 145 | // { |
| 146 | // transmittedInterests++; |
| 147 | // } |
| 148 | |
| 149 | // static void OnReceivedInterest (std::string context, Ptr<const CcnxInterestHeader> header, |
| 150 | // Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face) |
| 151 | // { |
| 152 | // receivedInterests++; |
| 153 | // } |
| 154 | |
| 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 | // } |
| 160 | |
| 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 | // } |
| 166 | |
| 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 | // } |
| 178 | |
| 179 | int |
| 180 | main (int argc, char *argv[]) |
| 181 | { |
| 182 | // Packet::EnableChecking(); |
| 183 | // Packet::EnablePrinting(); |
| 184 | string input ("./src/NDNabstraction/examples/synthetic-topology.txt"); |
| 185 | |
| 186 | Time finishTime = Seconds (20.0); |
| 187 | string animationFile; |
| 188 | string strategy = "ns3::CcnxFloodingStrategy"; |
| 189 | CommandLine cmd; |
| 190 | cmd.AddValue ("finish", "Finish time", finishTime); |
| 191 | cmd.AddValue ("netanim", "NetAnim filename", animationFile); |
| 192 | cmd.AddValue ("strategy", "CCNx forwarding strategy", strategy); |
| 193 | cmd.Parse (argc, argv); |
| 194 | |
| 195 | ConfigStore config; |
| 196 | config.ConfigureDefaults (); |
| 197 | |
| 198 | // ------------------------------------------------------------ |
| 199 | // -- Read topology data. |
| 200 | // -------------------------------------------- |
| 201 | |
| 202 | AnnotatedTopologyReader reader ("/synthetic"); |
| 203 | //reader.SetMobilityModel ("ns3::SpringMobilityModel"); |
| 204 | reader.SetFileName (input); |
| 205 | |
| 206 | NodeContainer nodes = reader.Read (); |
| 207 | |
| 208 | if (reader.LinksSize () == 0) |
| 209 | { |
| 210 | NS_LOG_ERROR ("Problems reading the topology file. Failing."); |
| 211 | return -1; |
| 212 | } |
| 213 | |
| 214 | //SpringMobilityHelper::InstallSprings (reader.LinksBegin (), reader.LinksEnd ()); |
| 215 | |
| 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 | */ |
| 223 | NS_LOG_INFO("Nodes = " << nodes.GetN()); |
| 224 | NS_LOG_INFO("Links = " << reader.LinksSize ()); |
| 225 | |
| 226 | // Install CCNx stack |
| 227 | NS_LOG_INFO ("Installing CCNx stack"); |
| 228 | CcnxStackHelper ccnxHelper; |
| 229 | ccnxHelper.SetForwardingStrategy (strategy); |
| 230 | ccnxHelper.EnableLimits (false, Seconds(0.1)); |
| 231 | ccnxHelper.SetDefaultRoutes (true); |
| 232 | ccnxHelper.InstallAll (); |
| 233 | |
| 234 | NS_LOG_INFO ("Installing Applications"); |
| 235 | CcnxConsumerHelper consumerHelper ("/5"); |
| 236 | ApplicationContainer consumers = consumerHelper.Install (Names::Find<Node> ("/synthetic", "NODE2")); |
| 237 | |
| 238 | consumers.Start (Seconds (0.0)); |
| 239 | consumers.Stop (finishTime); |
| 240 | |
| 241 | CcnxConsumerHelper consumerHelper2("/6"); |
| 242 | ApplicationContainer consumers2 = consumerHelper2.Install(Names::Find<Node> ("/synthetic", "NODE6")); |
| 243 | |
| 244 | consumers2.Start (Seconds (0.0)); |
| 245 | consumers2.Stop (finishTime); |
| 246 | |
| 247 | CcnxProducerHelper producerHelper ("/5",1024); |
| 248 | ApplicationContainer producers = producerHelper.Install (Names::Find<Node> ("/synthetic", "NODE7")); |
| 249 | |
| 250 | producers.Start (Seconds (0.0)); |
| 251 | producers.Stop (finishTime); |
| 252 | |
| 253 | CcnxProducerHelper producerHelper2 ("/6",1024); |
| 254 | ApplicationContainer producers2 = producerHelper2.Install (Names::Find<Node> ("/synthetic", "NODE1")); |
| 255 | |
| 256 | producers2.Start (Seconds (0.0)); |
| 257 | producers2.Stop (finishTime); |
| 258 | |
| 259 | // Populate FIB based on IPv4 global routing controller |
| 260 | //ccnxHelper.InstallFakeGlobalRoutes (); |
| 261 | //ccnxHelper.InstallRouteTo (Names::Find<Node> ("/synthetic", "NODE1")); |
| 262 | //ccnxHelper.InstallRouteTo (Names::Find<Node> ("/synthetic", "NODE7")); |
| 263 | |
| 264 | Simulator::Schedule (Seconds (1.0), PrintFIBs); |
| 265 | PrintFIBs (); |
| 266 | |
| 267 | Simulator::Schedule (Seconds (10.0), PrintTime); |
| 268 | |
| 269 | Simulator::Stop (finishTime); |
| 270 | |
| 271 | AnimationInterface *anim = 0; |
| 272 | if (animationFile != "") |
| 273 | { |
| 274 | anim = new AnimationInterface (animationFile); |
| 275 | anim->SetMobilityPollInterval (Seconds (1)); |
| 276 | } |
| 277 | |
| 278 | // NS_LOG_INFO ("Configure Tracing."); |
| 279 | AggregateTrace trace; |
| 280 | Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::CcnxConsumer/TransmittedInterests", |
| 281 | MakeCallback (&AggregateTrace::TransmittedInterests, &trace)); |
| 282 | |
| 283 | Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::CcnxConsumer/ReceivedNacks", |
| 284 | MakeCallback (&AggregateTrace::ReceivedNacks, &trace)); |
| 285 | |
| 286 | Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::CcnxProducer/ReceivedInterests", |
| 287 | MakeCallback (&AggregateTrace::ReceivedInterests, &trace)); |
| 288 | |
| 289 | Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::CcnxProducer/TransmittedContentObjects", |
| 290 | MakeCallback (&AggregateTrace::TransmittedData, &trace)); |
| 291 | |
| 292 | Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::CcnxConsumer/ReceivedContentObjects", |
| 293 | MakeCallback (&AggregateTrace::ReceivedData, &trace)); |
| 294 | |
| 295 | // Config::Connect("/NodeList/*/ns3::CcnxL3Protocol/TransmittedInterestTrace", |
| 296 | // MakeCallback (&OnTransmittedInterest)); |
| 297 | // Config::Connect ("/NodeList/*/ns3::CcnxL3Protocol/ReceivedInterestTrace", |
| 298 | // MakeCallback (&OnReceivedInterest)); |
| 299 | // Config::Connect ("/NodeList/*/ns3::CcnxL3Protocol/DroppedInterestTrace", |
| 300 | // MakeCallback (&OnDroppedInterest)); |
| 301 | |
| 302 | // Config::Connect ("/NodeList/*/ns3::CcnxL3Protocol/ReceivedDataTrace", |
| 303 | // MakeCallback (&OnReceivedData)); |
| 304 | // Config::Connect ("/NodeList/*/ns3::CcnxL3Protocol/TransmittedDataTrace", |
| 305 | // MakeCallback (&OnTransmittedData)); |
| 306 | // Config::Connect ("/NodeList/*/ns3::CcnxL3Protocol/DroppedDataTrace", |
| 307 | // MakeCallback (&OnDroppedData)); |
| 308 | |
| 309 | config.ConfigureAttributes (); |
| 310 | |
| 311 | NS_LOG_INFO ("Run Simulation."); |
| 312 | Simulator::Run (); |
| 313 | Simulator::Destroy (); |
| 314 | NS_LOG_INFO ("Done."); |
| 315 | |
| 316 | // NS_LOG_INFO("Total received interests = " << receivedInterests); |
| 317 | // NS_LOG_INFO("Total transmitted interests = " << transmittedInterests); |
| 318 | // NS_LOG_INFO("Total dropped interests = " << droppedInterests); |
| 319 | // NS_LOG_INFO("Total received data = " << receivedData); |
| 320 | // NS_LOG_INFO("Total transmitted data = " << transmittedData); |
| 321 | // NS_LOG_INFO("Total dropped data = " << droppedData); |
| 322 | NS_LOG_INFO (trace); |
| 323 | return 0; |
| 324 | } |