Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011-2012 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: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | // ndn-tree-cs-tracers.cc |
| 22 | |
| 23 | #include "ns3/core-module.h" |
| 24 | #include "ns3/network-module.h" |
| 25 | #include "ns3/ndnSIM-module.h" |
| 26 | |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame^] | 27 | namespace ns3 { |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * This scenario simulates a tree topology (using topology reader module) |
| 31 | * |
| 32 | * /------\ /------\ /------\ /------\ |
| 33 | * |leaf-1| |leaf-2| |leaf-3| |leaf-4| |
| 34 | * \------/ \------/ \------/ \------/ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 35 | * ^ ^ ^ ^ |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 36 | * | | | | |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame^] | 37 | * \ / \ / |
| 38 | * \ / \ / 10Mbps / 1ms |
| 39 | * \ / \ / |
| 40 | * | | | | |
| 41 | * v v v v |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 42 | * /-------\ /-------\ |
| 43 | * | rtr-1 | | rtr-2 | |
| 44 | * \-------/ \-------/ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 45 | * ^ ^ |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame^] | 46 | * | | |
| 47 | * \ / 10 Mpbs / 1ms |
| 48 | * +--------+ +--------+ |
| 49 | * | | |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 50 | * v v |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame^] | 51 | * /--------\ |
| 52 | * | root | |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 53 | * \--------/ |
| 54 | * |
| 55 | * |
| 56 | * To run scenario and see what is happening, use the following command: |
| 57 | * |
| 58 | * ./waf --run=ndn-tree-cs-tracers |
| 59 | */ |
| 60 | |
| 61 | int |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 62 | main(int argc, char* argv[]) |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 63 | { |
| 64 | CommandLine cmd; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 65 | cmd.Parse(argc, argv); |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 66 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 67 | AnnotatedTopologyReader topologyReader("", 1); |
| 68 | topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-tree.txt"); |
| 69 | topologyReader.Read(); |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 70 | |
| 71 | // Install CCNx stack on all nodes |
| 72 | ndn::StackHelper ndnHelper; |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame^] | 73 | ndnHelper.SetContentStoreChoice(false); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 74 | ndnHelper.SetContentStore("ns3::ndn::cs::Lru", "MaxSize", |
| 75 | "100"); // default ContentStore parameters |
| 76 | ndnHelper.InstallAll(); |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 77 | |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame^] | 78 | // Choosing forwarding strategy |
| 79 | ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/best-route"); |
| 80 | |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 81 | // Installing global routing interface on all nodes |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame^] | 82 | ndn::GlobalRoutingHelper ndnGlobalRoutingHelper; |
| 83 | ndnGlobalRoutingHelper.InstallAll(); |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 84 | |
| 85 | // Getting containers for the consumer/producer |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 86 | Ptr<Node> consumers[4] = {Names::Find<Node>("leaf-1"), Names::Find<Node>("leaf-2"), |
| 87 | Names::Find<Node>("leaf-3"), Names::Find<Node>("leaf-4")}; |
| 88 | Ptr<Node> producer = Names::Find<Node>("root"); |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 89 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 90 | for (int i = 0; i < 4; i++) { |
| 91 | ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); |
| 92 | consumerHelper.SetAttribute("Frequency", StringValue("10")); // 100 interests a second |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 93 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 94 | // Each consumer will express the same data /root/<seq-no> |
| 95 | consumerHelper.SetPrefix("/root"); |
| 96 | ApplicationContainer app = consumerHelper.Install(consumers[i]); |
| 97 | app.Start(Seconds(0.01 * i)); |
| 98 | } |
| 99 | |
| 100 | ndn::AppHelper producerHelper("ns3::ndn::Producer"); |
| 101 | producerHelper.SetAttribute("PayloadSize", StringValue("1024")); |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 102 | |
| 103 | // Register /root prefix with global routing controller and |
| 104 | // install producer that will satisfy Interests in /root namespace |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame^] | 105 | ndnGlobalRoutingHelper.AddOrigins("/root", producer); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 106 | producerHelper.SetPrefix("/root"); |
| 107 | producerHelper.Install(producer); |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 108 | |
| 109 | // Calculate and install FIBs |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame^] | 110 | ndn::GlobalRoutingHelper::CalculateRoutes(); |
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 | Simulator::Stop(Seconds(20.0)); |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 113 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 114 | ndn::CsTracer::InstallAll("cs-trace.txt", Seconds(1)); |
| 115 | |
| 116 | Simulator::Run(); |
| 117 | Simulator::Destroy(); |
Alexander Afanasyev | f4a0359 | 2012-12-10 16:12:34 -0800 | [diff] [blame] | 118 | |
| 119 | return 0; |
| 120 | } |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame^] | 121 | |
| 122 | } // namespace ns3 |
| 123 | |
| 124 | int |
| 125 | main(int argc, char* argv[]) |
| 126 | { |
| 127 | return ns3::main(argc, argv); |
| 128 | } |