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. |
| 4 | * |
| 5 | * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and |
| 6 | * contributors. |
| 7 | * |
| 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. |
| 11 | * |
| 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. |
| 15 | * |
| 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 | **/ |
| 19 | |
Spyridon Mastorakis | a879e02 | 2017-10-16 17:12:14 -0700 | [diff] [blame] | 20 | // ndn-different-strategy-per-prefix.cpp |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 21 | |
Spyridon Mastorakis | 4909d0a | 2014-11-27 22:17:41 -0800 | [diff] [blame] | 22 | #include "ns3/core-module.h" |
| 23 | #include "ns3/network-module.h" |
| 24 | #include "ns3/point-to-point-module.h" |
| 25 | #include "ns3/point-to-point-layout-module.h" |
| 26 | #include "ns3/ndnSIM-module.h" |
| 27 | |
| 28 | using namespace ns3; |
| 29 | using ns3::ndn::StackHelper; |
| 30 | using ns3::ndn::AppHelper; |
| 31 | using ns3::ndn::GlobalRoutingHelper; |
| 32 | using ns3::ndn::StrategyChoiceHelper; |
Spyridon Mastorakis | 4909d0a | 2014-11-27 22:17:41 -0800 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * This scenario simulates a grid topology (using PointToPointGrid module) |
| 36 | * |
| 37 | * In this scenario, thanks to NFD, we can choose a different forwarding |
| 38 | * strategy for each prefix in each node. |
| 39 | * |
| 40 | * (consumer) -- ( ) -- (producer) |
| 41 | * | | | |
| 42 | * ( ) ------ ( ) ----- ( ) |
| 43 | * | | | |
| 44 | * (consumer) -- ( ) -- (producer) |
| 45 | * |
| 46 | * All links are 1Mbps with propagation 10ms delay. |
| 47 | * |
| 48 | * FIB is populated using NdnGlobalRoutingHelper. |
| 49 | * |
| 50 | * Consumer requests data from producer with frequency 100 interests per second |
| 51 | * (interests contain constantly increasing sequence number). |
| 52 | * |
| 53 | * For every received interest, producer replies with a data packet, containing |
| 54 | * 1024 bytes of virtual payload. |
| 55 | * |
| 56 | * To run scenario and see what is happening, use the following command: |
| 57 | * |
| 58 | * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-different-strategy-per-prefix |
| 59 | */ |
| 60 | |
| 61 | int |
| 62 | main(int argc, char* argv[]) |
| 63 | { |
| 64 | // Setting default parameters for PointToPoint links and channels |
| 65 | Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps")); |
| 66 | Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms")); |
Alexander Afanasyev | 77f84c6 | 2018-10-08 13:37:42 -0400 | [diff] [blame] | 67 | Config::SetDefault("ns3::QueueBase::MaxSize", StringValue("10p")); |
Spyridon Mastorakis | 4909d0a | 2014-11-27 22:17:41 -0800 | [diff] [blame] | 68 | |
| 69 | // Read optional command-line parameters |
| 70 | CommandLine cmd; |
| 71 | cmd.Parse(argc, argv); |
| 72 | |
| 73 | // Creating 3x3 topology |
| 74 | PointToPointHelper p2p; |
| 75 | PointToPointGridHelper grid(3, 3, p2p); |
| 76 | grid.BoundingBox(100, 100, 200, 200); |
| 77 | |
| 78 | // Install NDN stack on all nodes |
| 79 | StackHelper ndnHelper; |
| 80 | ndnHelper.InstallAll(); |
| 81 | |
| 82 | // Installing global routing interface on all nodes |
| 83 | GlobalRoutingHelper ndnGlobalRoutingHelper; |
| 84 | ndnGlobalRoutingHelper.InstallAll(); |
| 85 | |
| 86 | // Getting pointers to the producer/consumer nodes |
| 87 | Ptr<Node> producer1 = grid.GetNode(2, 2); |
| 88 | Ptr<Node> producer2 = grid.GetNode(0, 2); |
| 89 | Ptr<Node> consumer1 = grid.GetNode(0, 0); |
| 90 | Ptr<Node> consumer2 = grid.GetNode(2, 0); |
| 91 | |
| 92 | // Define two name prefixes |
| 93 | std::string prefix1 = "/prefix1"; |
| 94 | std::string prefix2 = "/prefix2"; |
| 95 | |
| 96 | // Install different forwarding strategies for prefix1, prefix2 |
Alexander Afanasyev | c3c7f04 | 2015-08-21 11:38:00 -0700 | [diff] [blame] | 97 | StrategyChoiceHelper::InstallAll(prefix1, "/localhost/nfd/strategy/multicast"); |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 98 | StrategyChoiceHelper::InstallAll(prefix2, "/localhost/nfd/strategy/best-route"); |
Spyridon Mastorakis | 4909d0a | 2014-11-27 22:17:41 -0800 | [diff] [blame] | 99 | |
| 100 | // Install NDN applications |
| 101 | AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); |
| 102 | consumerHelper.SetPrefix(prefix1); |
| 103 | consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second |
| 104 | consumerHelper.Install(consumer1); |
| 105 | |
| 106 | consumerHelper.SetPrefix(prefix2); |
| 107 | consumerHelper.Install(consumer2); |
| 108 | |
| 109 | AppHelper producerHelper("ns3::ndn::Producer"); |
| 110 | producerHelper.SetPrefix(prefix1); |
| 111 | producerHelper.SetAttribute("PayloadSize", StringValue("1024")); |
| 112 | producerHelper.Install(producer1); |
| 113 | |
| 114 | producerHelper.SetPrefix(prefix2); |
| 115 | producerHelper.Install(producer2); |
| 116 | |
| 117 | // Add /prefix1 and /prefix2 origins to ndn::GlobalRouter |
| 118 | ndnGlobalRoutingHelper.AddOrigins(prefix1, producer1); |
| 119 | ndnGlobalRoutingHelper.AddOrigins(prefix2, producer2); |
| 120 | |
| 121 | // Calculate and install FIBs |
| 122 | GlobalRoutingHelper::CalculateRoutes(); |
| 123 | |
| 124 | Simulator::Stop(Seconds(20.0)); |
| 125 | Simulator::Run(); |
| 126 | Simulator::Destroy(); |
| 127 | |
| 128 | return 0; |
| 129 | } |