Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -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 | // ndn-congestion-topo-plugin.cc |
| 21 | #include "ns3/core-module.h" |
| 22 | #include "ns3/network-module.h" |
| 23 | #include "ns3/ndnSIM-module.h" |
| 24 | |
| 25 | using namespace ns3; |
| 26 | |
| 27 | /** |
| 28 | * This scenario simulates a grid topology (using topology reader module) |
| 29 | * |
| 30 | * /------\ /------\ |
| 31 | * | Src1 |<--+ +-->| Dst1 | |
| 32 | * \------/ \ / \------/ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 33 | * \ / |
| 34 | * +-->/------\ "bottleneck" /------\<-+ |
| 35 | * | Rtr1 |<===============>| Rtr2 | |
| 36 | * +-->\------/ \------/<-+ |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 37 | * / \ |
| 38 | * /------\ / \ /------\ |
| 39 | * | Src2 |<--+ +-->| Dst2 | |
| 40 | * \------/ \------/ |
| 41 | * |
| 42 | * To run scenario and see what is happening, use the following command: |
| 43 | * |
| 44 | * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-congestion-topo-plugin |
| 45 | */ |
| 46 | |
| 47 | int |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 48 | main(int argc, char* argv[]) |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 49 | { |
| 50 | CommandLine cmd; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 51 | cmd.Parse(argc, argv); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 52 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 53 | AnnotatedTopologyReader topologyReader("", 25); |
| 54 | topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-6-node.txt"); |
| 55 | topologyReader.Read(); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 56 | |
Alexander Afanasyev | 9fb2e3d | 2013-03-30 21:11:07 -0700 | [diff] [blame] | 57 | // Install NDN stack on all nodes |
| 58 | ndn::StackHelper ndnHelper; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 59 | ndnHelper.SetForwardingStrategy("ns3::ndn::fw::BestRoute"); |
| 60 | ndnHelper.SetContentStore("ns3::ndn::cs::Lru", "MaxSize", "10000"); |
| 61 | ndnHelper.InstallAll(); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 62 | |
| 63 | // Installing global routing interface on all nodes |
Alexander Afanasyev | 9fb2e3d | 2013-03-30 21:11:07 -0700 | [diff] [blame] | 64 | ndn::GlobalRoutingHelper ndnGlobalRoutingHelper; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 65 | ndnGlobalRoutingHelper.InstallAll(); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 66 | |
| 67 | // Getting containers for the consumer/producer |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 68 | Ptr<Node> consumer1 = Names::Find<Node>("Src1"); |
| 69 | Ptr<Node> consumer2 = Names::Find<Node>("Src2"); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 70 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 71 | Ptr<Node> producer1 = Names::Find<Node>("Dst1"); |
| 72 | Ptr<Node> producer2 = Names::Find<Node>("Dst2"); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 73 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 74 | ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); |
| 75 | consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 76 | |
| 77 | // on the first consumer node install a Consumer application |
| 78 | // that will express interests in /dst1 namespace |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 79 | consumerHelper.SetPrefix("/dst1"); |
| 80 | consumerHelper.Install(consumer1); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 81 | |
| 82 | // on the second consumer node install a Consumer application |
| 83 | // that will express interests in /dst2 namespace |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 84 | consumerHelper.SetPrefix("/dst2"); |
| 85 | consumerHelper.Install(consumer2); |
| 86 | |
| 87 | ndn::AppHelper producerHelper("ns3::ndn::Producer"); |
| 88 | producerHelper.SetAttribute("PayloadSize", StringValue("1024")); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 89 | |
| 90 | // Register /dst1 prefix with global routing controller and |
| 91 | // install producer that will satisfy Interests in /dst1 namespace |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 92 | ndnGlobalRoutingHelper.AddOrigins("/dst1", producer1); |
| 93 | producerHelper.SetPrefix("/dst1"); |
| 94 | producerHelper.Install(producer1); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 95 | |
| 96 | // Register /dst2 prefix with global routing controller and |
| 97 | // install producer that will satisfy Interests in /dst2 namespace |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 98 | ndnGlobalRoutingHelper.AddOrigins("/dst2", producer2); |
| 99 | producerHelper.SetPrefix("/dst2"); |
| 100 | producerHelper.Install(producer2); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 101 | |
| 102 | // Calculate and install FIBs |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 103 | ndn::GlobalRoutingHelper::CalculateRoutes(); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 104 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 105 | Simulator::Stop(Seconds(20.0)); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 106 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 107 | Simulator::Run(); |
| 108 | Simulator::Destroy(); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 109 | |
| 110 | return 0; |
| 111 | } |