Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2011-2015 Regents of the University of California. |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 5 | * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and |
| 6 | * contributors. |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 8 | * ndnSIM is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 11 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 12 | * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 15 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | **/ |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 19 | |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 20 | // ndn-tree-cs-tracers.cpp |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 21 | |
| 22 | #include "ns3/core-module.h" |
| 23 | #include "ns3/network-module.h" |
| 24 | #include "ns3/ndnSIM-module.h" |
| 25 | |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 26 | namespace ns3 { |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * This scenario simulates a tree topology (using topology reader module) |
| 30 | * |
| 31 | * /------\ /------\ /------\ /------\ |
| 32 | * |leaf-1| |leaf-2| |leaf-3| |leaf-4| |
| 33 | * \------/ \------/ \------/ \------/ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 34 | * ^ ^ ^ ^ |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 35 | * | | | | |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 36 | * \ / \ / |
| 37 | * \ / \ / 10Mbps / 1ms |
| 38 | * \ / \ / |
| 39 | * | | | | |
| 40 | * v v v v |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 41 | * /-------\ /-------\ |
| 42 | * | rtr-1 | | rtr-2 | |
| 43 | * \-------/ \-------/ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 44 | * ^ ^ |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 45 | * | | |
| 46 | * \ / 10 Mpbs / 1ms |
| 47 | * +--------+ +--------+ |
| 48 | * | | |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 49 | * v v |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 50 | * /--------\ |
| 51 | * | root | |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 52 | * \--------/ |
| 53 | * |
| 54 | * |
| 55 | * To run scenario and see what is happening, use the following command: |
| 56 | * |
| 57 | * ./waf --run=ndn-tree-cs-tracers |
| 58 | */ |
| 59 | |
| 60 | int |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 61 | main(int argc, char* argv[]) |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 62 | { |
| 63 | CommandLine cmd; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 64 | cmd.Parse(argc, argv); |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 65 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 66 | AnnotatedTopologyReader topologyReader("", 1); |
| 67 | topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-tree.txt"); |
| 68 | topologyReader.Read(); |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 69 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 70 | // Install NDN stack on all nodes |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 71 | ndn::StackHelper ndnHelper; |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 72 | ndnHelper.SetOldContentStore("ns3::ndn::cs::Lru", "MaxSize", |
| 73 | "100"); // default ContentStore parameters |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 74 | ndnHelper.InstallAll(); |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 75 | |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 76 | // Choosing forwarding strategy |
| 77 | ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/best-route"); |
| 78 | |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 79 | // Installing global routing interface on all nodes |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 80 | ndn::GlobalRoutingHelper ndnGlobalRoutingHelper; |
| 81 | ndnGlobalRoutingHelper.InstallAll(); |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 82 | |
| 83 | // Getting containers for the consumer/producer |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 84 | Ptr<Node> consumers[4] = {Names::Find<Node>("leaf-1"), Names::Find<Node>("leaf-2"), |
| 85 | Names::Find<Node>("leaf-3"), Names::Find<Node>("leaf-4")}; |
| 86 | Ptr<Node> producer = Names::Find<Node>("root"); |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 87 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 88 | for (int i = 0; i < 4; i++) { |
| 89 | ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); |
| 90 | consumerHelper.SetAttribute("Frequency", StringValue("10")); // 100 interests a second |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 91 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 92 | // Each consumer will express the same data /root/<seq-no> |
| 93 | consumerHelper.SetPrefix("/root"); |
| 94 | ApplicationContainer app = consumerHelper.Install(consumers[i]); |
| 95 | app.Start(Seconds(0.01 * i)); |
| 96 | } |
| 97 | |
| 98 | ndn::AppHelper producerHelper("ns3::ndn::Producer"); |
| 99 | producerHelper.SetAttribute("PayloadSize", StringValue("1024")); |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 100 | |
| 101 | // Register /root prefix with global routing controller and |
| 102 | // install producer that will satisfy Interests in /root namespace |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 103 | ndnGlobalRoutingHelper.AddOrigins("/root", producer); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 104 | producerHelper.SetPrefix("/root"); |
| 105 | producerHelper.Install(producer); |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 106 | |
| 107 | // Calculate and install FIBs |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 108 | ndn::GlobalRoutingHelper::CalculateRoutes(); |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 109 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 110 | Simulator::Stop(Seconds(20.0)); |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 111 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 112 | ndn::CsTracer::InstallAll("cs-trace.txt", Seconds(1)); |
| 113 | |
| 114 | Simulator::Run(); |
| 115 | Simulator::Destroy(); |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 116 | |
| 117 | return 0; |
| 118 | } |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 119 | |
| 120 | } // namespace ns3 |
| 121 | |
| 122 | int |
| 123 | main(int argc, char* argv[]) |
| 124 | { |
| 125 | return ns3::main(argc, argv); |
| 126 | } |