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 | |
| 20 | // ndn-multiple-strategies.cpp |
| 21 | |
Spyridon Mastorakis | 41fbfe1 | 2014-11-24 23:26:09 -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 | 41fbfe1 | 2014-11-24 23:26:09 -0800 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * This scenario simulates a grid topology (using PointToPointGrid module) |
| 36 | * |
| 37 | * The first six nodes use the best route forwarding strategy, whereas |
Alexander Afanasyev | c3c7f04 | 2015-08-21 11:38:00 -0700 | [diff] [blame^] | 38 | * the three remaining nodes use the multicast forwarding strategy. |
Spyridon Mastorakis | 41fbfe1 | 2014-11-24 23:26:09 -0800 | [diff] [blame] | 39 | * |
| 40 | * (consumer) -- ( ) ----- ( ) |
| 41 | * | | | |
| 42 | * ( ) ------ ( ) ----- ( ) |
| 43 | * | | | |
| 44 | * ( ) ------ ( ) -- (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-multiple-strategies |
| 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")); |
| 67 | Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("10")); |
| 68 | |
| 69 | // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize |
| 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 containers for the consumer/producer |
| 87 | Ptr<Node> producer = grid.GetNode(2, 2); |
| 88 | NodeContainer consumerNodes; |
| 89 | consumerNodes.Add(grid.GetNode(0, 0)); |
| 90 | |
| 91 | // Install NDN applications |
| 92 | std::string prefix = "/prefix"; |
| 93 | |
| 94 | // Install different forwarding strategies |
Spyridon Mastorakis | 41fbfe1 | 2014-11-24 23:26:09 -0800 | [diff] [blame] | 95 | for (int row = 0; row < 3; row++) { |
| 96 | for (int column = 0; column < 3; column++) { |
| 97 | if (row < 2) |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 98 | StrategyChoiceHelper::Install(grid.GetNode(row, column), "/prefix", |
| 99 | "/localhost/nfd/strategy/best-route"); |
Spyridon Mastorakis | 41fbfe1 | 2014-11-24 23:26:09 -0800 | [diff] [blame] | 100 | else |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 101 | StrategyChoiceHelper::Install(grid.GetNode(row, column), "/prefix", |
Alexander Afanasyev | c3c7f04 | 2015-08-21 11:38:00 -0700 | [diff] [blame^] | 102 | "/localhost/nfd/strategy/multicast"); |
Spyridon Mastorakis | 41fbfe1 | 2014-11-24 23:26:09 -0800 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
| 106 | AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); |
| 107 | consumerHelper.SetPrefix(prefix); |
| 108 | consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second |
| 109 | consumerHelper.Install(consumerNodes); |
| 110 | |
| 111 | AppHelper producerHelper("ns3::ndn::Producer"); |
| 112 | producerHelper.SetPrefix(prefix); |
| 113 | producerHelper.SetAttribute("PayloadSize", StringValue("1024")); |
| 114 | producerHelper.Install(producer); |
| 115 | |
| 116 | // Add /prefix origins to ndn::GlobalRouter |
| 117 | ndnGlobalRoutingHelper.AddOrigins(prefix, producer); |
| 118 | |
| 119 | // Calculate and install FIBs |
| 120 | GlobalRoutingHelper::CalculateRoutes(); |
| 121 | |
| 122 | Simulator::Stop(Seconds(20.0)); |
| 123 | Simulator::Run(); |
| 124 | Simulator::Destroy(); |
| 125 | |
| 126 | return 0; |
| 127 | } |