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. |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 5 | * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and |
| 6 | * contributors. |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 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. |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 11 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 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. |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 15 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 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-grid.cpp |
| 21 | |
Shock | b0f8315 | 2012-12-25 14:16:47 +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 | |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 28 | namespace ns3 { |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * This scenario simulates a grid topology (using PointToPointGrid module) |
| 32 | * |
| 33 | * (consumer) -- ( ) ----- ( ) |
| 34 | * | | | |
| 35 | * ( ) ------ ( ) ----- ( ) |
| 36 | * | | | |
| 37 | * ( ) ------ ( ) -- (producer)(2,2) |
| 38 | * |
| 39 | * All links are 1Mbps with propagation 10ms delay. |
| 40 | * |
| 41 | * FIB is populated using NdnGlobalRoutingHelper. |
| 42 | * |
| 43 | * Consumer requests data from producer with frequency 100 interests per second |
| 44 | * (interests contain constantly increasing sequence number). |
| 45 | * |
| 46 | * For every received interest, producer replies with a data packet, containing |
| 47 | * 1024 bytes of virtual payload. |
| 48 | * |
| 49 | * To run scenario and see what is happening, use the following command: |
| 50 | * |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 51 | * NS_LOG=ndn.Consumer:ndn.ConsumerZipfMandelbrot:ndn.Producer ./waf --run=ndn-zipf-mandelbrot |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 52 | */ |
| 53 | |
| 54 | int |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 55 | main(int argc, char* argv[]) |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 56 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 57 | // LogComponentEnable("ndn.CbisGlobalRoutingHelper", LOG_LEVEL_INFO); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 58 | // Setting default parameters for PointToPoint links and channels |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 59 | Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps")); |
| 60 | Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("1ms")); |
Spyridon Mastorakis | f98a341 | 2017-10-30 11:47:58 -0700 | [diff] [blame] | 61 | Config::SetDefault("ns3::QueueBase::MaxPackets", UintegerValue(10)); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 62 | |
| 63 | // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize |
| 64 | CommandLine cmd; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 65 | cmd.Parse(argc, argv); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 66 | |
| 67 | // Creating 3x3 topology |
| 68 | PointToPointHelper p2p; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 69 | PointToPointGridHelper grid(3, 3, p2p); |
| 70 | grid.BoundingBox(100, 100, 200, 200); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 71 | |
| 72 | // Install CCNx stack on all nodes |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 73 | ndn::StackHelper ndnHelper; |
| 74 | // ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::SmartFlooding"); |
| 75 | // ndnHelper.SetContentStore ("ns3::ndn::cs::Lru", "MaxSize", "10"); |
| 76 | ndnHelper.InstallAll(); |
| 77 | |
| 78 | // Choosing forwarding strategy |
| 79 | ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/ncc"); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 80 | |
| 81 | // Installing global routing interface on all nodes |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 82 | // ndn::CbisGlobalRoutingHelper ndnGlobalRoutingHelper; |
| 83 | ndn::GlobalRoutingHelper ndnGlobalRoutingHelper; |
| 84 | ndnGlobalRoutingHelper.InstallAll(); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 85 | |
| 86 | // Getting containers for the consumer/producer |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 87 | Ptr<Node> producer = grid.GetNode(2, 2); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 88 | NodeContainer consumerNodes; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 89 | consumerNodes.Add(grid.GetNode(0, 0)); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 90 | |
| 91 | // Install CCNx applications |
| 92 | std::string prefix = "/prefix"; |
| 93 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 94 | ndn::AppHelper consumerHelper("ns3::ndn::ConsumerZipfMandelbrot"); |
| 95 | // ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr"); |
| 96 | consumerHelper.SetPrefix(prefix); |
| 97 | consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second |
| 98 | consumerHelper.SetAttribute("NumberOfContents", StringValue("100")); // 10 different contents |
| 99 | // consumerHelper.SetAttribute ("Randomize", StringValue ("uniform")); // 100 interests a second |
| 100 | consumerHelper.Install(consumerNodes); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 101 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 102 | ndn::AppHelper producerHelper("ns3::ndn::Producer"); |
| 103 | producerHelper.SetPrefix(prefix); |
| 104 | producerHelper.SetAttribute("PayloadSize", StringValue("100")); |
| 105 | producerHelper.Install(producer); |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 106 | ndnGlobalRoutingHelper.AddOrigins(prefix, producer); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 107 | |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 108 | // Calculate and install FIBs |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 109 | ndn::GlobalRoutingHelper::CalculateRoutes(); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 110 | |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 111 | Simulator::Stop(Seconds(1.0)); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 112 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 113 | Simulator::Run(); |
| 114 | Simulator::Destroy(); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 115 | |
| 116 | return 0; |
| 117 | } |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 118 | |
| 119 | } // namespace ns3 |
| 120 | |
| 121 | int |
| 122 | main(int argc, char* argv[]) |
| 123 | { |
| 124 | return ns3::main(argc, argv); |
| 125 | } |