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-grid-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 | * (consumer) -- ( ) ----- ( ) |
| 31 | * | | | |
| 32 | * ( ) ------ ( ) ----- ( ) |
| 33 | * | | | |
| 34 | * ( ) ------ ( ) -- (producer) |
| 35 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 36 | * All links are 1Mbps with propagation 10ms delay. |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 37 | * |
| 38 | * FIB is populated using NdnGlobalRoutingHelper. |
| 39 | * |
| 40 | * Consumer requests data from producer with frequency 10 interests per second |
| 41 | * (interests contain constantly increasing sequence number). |
| 42 | * |
| 43 | * For every received interest, producer replies with a data packet, containing |
| 44 | * 1024 bytes of virtual payload. |
| 45 | * |
| 46 | * To run scenario and see what is happening, use the following command: |
| 47 | * |
| 48 | * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-grid-topo-plugin |
| 49 | */ |
| 50 | |
| 51 | int |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 52 | main(int argc, char* argv[]) |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 53 | { |
| 54 | CommandLine cmd; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 55 | cmd.Parse(argc, argv); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 56 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 57 | AnnotatedTopologyReader topologyReader("", 25); |
| 58 | topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-grid-3x3.txt"); |
| 59 | topologyReader.Read(); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 60 | |
Alexander Afanasyev | 9fb2e3d | 2013-03-30 21:11:07 -0700 | [diff] [blame] | 61 | // Install NDN stack on all nodes |
| 62 | ndn::StackHelper ndnHelper; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 63 | ndnHelper.SetForwardingStrategy("ns3::ndn::fw::BestRoute"); |
| 64 | ndnHelper.InstallAll(); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 65 | |
| 66 | // Installing global routing interface on all nodes |
Alexander Afanasyev | 9fb2e3d | 2013-03-30 21:11:07 -0700 | [diff] [blame] | 67 | ndn::GlobalRoutingHelper ndnGlobalRoutingHelper; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 68 | ndnGlobalRoutingHelper.InstallAll(); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 69 | |
| 70 | // Getting containers for the consumer/producer |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 71 | Ptr<Node> producer = Names::Find<Node>("Node8"); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 72 | NodeContainer consumerNodes; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 73 | consumerNodes.Add(Names::Find<Node>("Node0")); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 74 | |
Alexander Afanasyev | 9fb2e3d | 2013-03-30 21:11:07 -0700 | [diff] [blame] | 75 | // Install NDN applications |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 76 | std::string prefix = "/prefix"; |
| 77 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 78 | ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); |
| 79 | consumerHelper.SetPrefix(prefix); |
| 80 | consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second |
| 81 | consumerHelper.Install(consumerNodes); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 82 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 83 | ndn::AppHelper producerHelper("ns3::ndn::Producer"); |
| 84 | producerHelper.SetPrefix(prefix); |
| 85 | producerHelper.SetAttribute("PayloadSize", StringValue("1024")); |
| 86 | producerHelper.Install(producer); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 87 | |
| 88 | // Add /prefix origins to ndn::GlobalRouter |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 89 | ndnGlobalRoutingHelper.AddOrigins(prefix, producer); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 90 | |
| 91 | // Calculate and install FIBs |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 92 | ndn::GlobalRoutingHelper::CalculateRoutes(); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 93 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 94 | Simulator::Stop(Seconds(20.0)); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 95 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame^] | 96 | Simulator::Run(); |
| 97 | Simulator::Destroy(); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 98 | |
| 99 | return 0; |
| 100 | } |