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. |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [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. |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [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. |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [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. |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [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 | **/ |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 19 | |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 20 | // ndn-grid.cpp |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 21 | |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 22 | #include "ns3/core-module.h" |
| 23 | #include "ns3/network-module.h" |
| 24 | #include "ns3/point-to-point-module.h" |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 25 | #include "ns3/point-to-point-layout-module.h" |
Alexander Afanasyev | 4885eea | 2012-06-01 12:28:15 -0700 | [diff] [blame] | 26 | #include "ns3/ndnSIM-module.h" |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 27 | |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 28 | namespace ns3 { |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 29 | |
Alexander Afanasyev | a514d63 | 2012-02-14 18:54:14 -0800 | [diff] [blame] | 30 | /** |
| 31 | * This scenario simulates a grid topology (using PointToPointGrid module) |
| 32 | * |
| 33 | * (consumer) -- ( ) ----- ( ) |
| 34 | * | | | |
| 35 | * ( ) ------ ( ) ----- ( ) |
| 36 | * | | | |
| 37 | * ( ) ------ ( ) -- (producer) |
| 38 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 39 | * All links are 1Mbps with propagation 10ms delay. |
Alexander Afanasyev | a514d63 | 2012-02-14 18:54:14 -0800 | [diff] [blame] | 40 | * |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 41 | * FIB is populated using NdnGlobalRoutingHelper. |
Alexander Afanasyev | a514d63 | 2012-02-14 18:54:14 -0800 | [diff] [blame] | 42 | * |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 43 | * Consumer requests data from producer with frequency 100 interests per second |
Alexander Afanasyev | a514d63 | 2012-02-14 18:54:14 -0800 | [diff] [blame] | 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 | * |
Alexander Afanasyev | a514d63 | 2012-02-14 18:54:14 -0800 | [diff] [blame] | 49 | * To run scenario and see what is happening, use the following command: |
| 50 | * |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 51 | * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-grid |
Alexander Afanasyev | a514d63 | 2012-02-14 18:54:14 -0800 | [diff] [blame] | 52 | */ |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 53 | |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 54 | int |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 55 | main(int argc, char* argv[]) |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 56 | { |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 57 | // Setting default parameters for PointToPoint links and channels |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 58 | Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps")); |
| 59 | Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms")); |
Spyridon Mastorakis | f98a341 | 2017-10-30 11:47:58 -0700 | [diff] [blame] | 60 | Config::SetDefault("ns3::QueueBase::MaxPackets", UintegerValue(10)); |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 61 | |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 62 | // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 63 | CommandLine cmd; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 64 | cmd.Parse(argc, argv); |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 65 | |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 66 | // Creating 3x3 topology |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 67 | PointToPointHelper p2p; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 68 | PointToPointGridHelper grid(3, 3, p2p); |
| 69 | grid.BoundingBox(100, 100, 200, 200); |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 70 | |
Alexander Afanasyev | 9fb2e3d | 2013-03-30 21:11:07 -0700 | [diff] [blame] | 71 | // Install NDN stack on all nodes |
| 72 | ndn::StackHelper ndnHelper; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 73 | ndnHelper.InstallAll(); |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 74 | |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 75 | // Set BestRoute strategy |
| 76 | ndn::StrategyChoiceHelper::InstallAll("/", "/localhost/nfd/strategy/best-route"); |
| 77 | |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 78 | // Installing global routing interface on all nodes |
Alexander Afanasyev | 9fb2e3d | 2013-03-30 21:11:07 -0700 | [diff] [blame] | 79 | ndn::GlobalRoutingHelper ndnGlobalRoutingHelper; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 80 | ndnGlobalRoutingHelper.InstallAll(); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 81 | |
Alexander Afanasyev | d859979 | 2012-04-17 22:26:29 -0700 | [diff] [blame] | 82 | // Getting containers for the consumer/producer |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 83 | Ptr<Node> producer = grid.GetNode(2, 2); |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 84 | NodeContainer consumerNodes; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 85 | consumerNodes.Add(grid.GetNode(0, 0)); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 86 | |
Alexander Afanasyev | 9fb2e3d | 2013-03-30 21:11:07 -0700 | [diff] [blame] | 87 | // Install NDN applications |
Alexander Afanasyev | d859979 | 2012-04-17 22:26:29 -0700 | [diff] [blame] | 88 | std::string prefix = "/prefix"; |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 89 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 90 | ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); |
| 91 | consumerHelper.SetPrefix(prefix); |
| 92 | consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second |
| 93 | consumerHelper.Install(consumerNodes); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 94 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 95 | ndn::AppHelper producerHelper("ns3::ndn::Producer"); |
| 96 | producerHelper.SetPrefix(prefix); |
| 97 | producerHelper.SetAttribute("PayloadSize", StringValue("1024")); |
| 98 | producerHelper.Install(producer); |
Alexander Afanasyev | d859979 | 2012-04-17 22:26:29 -0700 | [diff] [blame] | 99 | |
Alexander Afanasyev | cf6dc92 | 2012-08-10 16:55:27 -0700 | [diff] [blame] | 100 | // Add /prefix origins to ndn::GlobalRouter |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 101 | ndnGlobalRoutingHelper.AddOrigins(prefix, producer); |
Alexander Afanasyev | d859979 | 2012-04-17 22:26:29 -0700 | [diff] [blame] | 102 | |
| 103 | // Calculate and install FIBs |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 104 | ndn::GlobalRoutingHelper::CalculateRoutes(); |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 105 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 106 | Simulator::Stop(Seconds(20.0)); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 107 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 108 | Simulator::Run(); |
| 109 | Simulator::Destroy(); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 110 | |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 111 | return 0; |
Alexander Afanasyev | 3ba44e5 | 2011-11-10 16:38:10 -0800 | [diff] [blame] | 112 | } |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 113 | |
| 114 | } // namespace ns3 |
| 115 | |
| 116 | int |
| 117 | main(int argc, char* argv[]) |
| 118 | { |
| 119 | return ns3::main(argc, argv); |
| 120 | } |