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