Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 3 | * Copyright (c) 2011-2012 University of California, Los Angeles |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 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 | * |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 19 | */ |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 20 | |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 21 | // ndn-grid.cc |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 22 | |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 23 | #include "ns3/core-module.h" |
| 24 | #include "ns3/network-module.h" |
| 25 | #include "ns3/point-to-point-module.h" |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 26 | #include "ns3/point-to-point-layout-module.h" |
Alexander Afanasyev | 4885eea | 2012-06-01 12:28:15 -0700 | [diff] [blame] | 27 | #include "ns3/ndnSIM-module.h" |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 28 | |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 29 | namespace ns3 { |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 30 | |
Alexander Afanasyev | a514d63 | 2012-02-14 18:54:14 -0800 | [diff] [blame] | 31 | /** |
| 32 | * This scenario simulates a grid topology (using PointToPointGrid module) |
| 33 | * |
| 34 | * (consumer) -- ( ) ----- ( ) |
| 35 | * | | | |
| 36 | * ( ) ------ ( ) ----- ( ) |
| 37 | * | | | |
| 38 | * ( ) ------ ( ) -- (producer) |
| 39 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 40 | * All links are 1Mbps with propagation 10ms delay. |
Alexander Afanasyev | a514d63 | 2012-02-14 18:54:14 -0800 | [diff] [blame] | 41 | * |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 42 | * FIB is populated using NdnGlobalRoutingHelper. |
Alexander Afanasyev | a514d63 | 2012-02-14 18:54:14 -0800 | [diff] [blame] | 43 | * |
Alexander Afanasyev | e095f0f | 2012-11-21 17:43:32 -0800 | [diff] [blame] | 44 | * Consumer requests data from producer with frequency 100 interests per second |
Alexander Afanasyev | a514d63 | 2012-02-14 18:54:14 -0800 | [diff] [blame] | 45 | * (interests contain constantly increasing sequence number). |
| 46 | * |
| 47 | * For every received interest, producer replies with a data packet, containing |
| 48 | * 1024 bytes of virtual payload. |
| 49 | * |
Alexander Afanasyev | a514d63 | 2012-02-14 18:54:14 -0800 | [diff] [blame] | 50 | * To run scenario and see what is happening, use the following command: |
| 51 | * |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 52 | * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-grid |
Alexander Afanasyev | a514d63 | 2012-02-14 18:54:14 -0800 | [diff] [blame] | 53 | */ |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 54 | |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 55 | int |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 56 | main(int argc, char* argv[]) |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 57 | { |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -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("10ms")); |
| 61 | Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("10")); |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 62 | |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 63 | // 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] | 64 | CommandLine cmd; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 65 | cmd.Parse(argc, argv); |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 66 | |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 67 | // Creating 3x3 topology |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 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); |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 71 | |
Alexander Afanasyev | 9fb2e3d | 2013-03-30 21:11:07 -0700 | [diff] [blame] | 72 | // Install NDN stack on all nodes |
| 73 | ndn::StackHelper ndnHelper; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 74 | ndnHelper.InstallAll(); |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 75 | |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 76 | // Set BestRoute strategy |
| 77 | ndn::StrategyChoiceHelper::InstallAll("/", "/localhost/nfd/strategy/best-route"); |
| 78 | |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 79 | // Installing global routing interface on all nodes |
Alexander Afanasyev | 9fb2e3d | 2013-03-30 21:11:07 -0700 | [diff] [blame] | 80 | ndn::GlobalRoutingHelper ndnGlobalRoutingHelper; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 81 | ndnGlobalRoutingHelper.InstallAll(); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 82 | |
Alexander Afanasyev | d859979 | 2012-04-17 22:26:29 -0700 | [diff] [blame] | 83 | // Getting containers for the consumer/producer |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 84 | Ptr<Node> producer = grid.GetNode(2, 2); |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 85 | NodeContainer consumerNodes; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 86 | consumerNodes.Add(grid.GetNode(0, 0)); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 87 | |
Alexander Afanasyev | 9fb2e3d | 2013-03-30 21:11:07 -0700 | [diff] [blame] | 88 | // Install NDN applications |
Alexander Afanasyev | d859979 | 2012-04-17 22:26:29 -0700 | [diff] [blame] | 89 | std::string prefix = "/prefix"; |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 90 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 91 | ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); |
| 92 | consumerHelper.SetPrefix(prefix); |
| 93 | consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second |
| 94 | consumerHelper.Install(consumerNodes); |
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 | ndn::AppHelper producerHelper("ns3::ndn::Producer"); |
| 97 | producerHelper.SetPrefix(prefix); |
| 98 | producerHelper.SetAttribute("PayloadSize", StringValue("1024")); |
| 99 | producerHelper.Install(producer); |
Alexander Afanasyev | d859979 | 2012-04-17 22:26:29 -0700 | [diff] [blame] | 100 | |
Alexander Afanasyev | cf6dc92 | 2012-08-10 16:55:27 -0700 | [diff] [blame] | 101 | // Add /prefix origins to ndn::GlobalRouter |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 102 | ndnGlobalRoutingHelper.AddOrigins(prefix, producer); |
Alexander Afanasyev | d859979 | 2012-04-17 22:26:29 -0700 | [diff] [blame] | 103 | |
| 104 | // Calculate and install FIBs |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 105 | ndn::GlobalRoutingHelper::CalculateRoutes(); |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 106 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 107 | Simulator::Stop(Seconds(20.0)); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 108 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 109 | Simulator::Run(); |
| 110 | Simulator::Destroy(); |
Alexander Afanasyev | aa1c4c3 | 2012-11-21 16:17:03 -0800 | [diff] [blame] | 111 | |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 112 | return 0; |
Alexander Afanasyev | 3ba44e5 | 2011-11-10 16:38:10 -0800 | [diff] [blame] | 113 | } |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 114 | |
| 115 | } // namespace ns3 |
| 116 | |
| 117 | int |
| 118 | main(int argc, char* argv[]) |
| 119 | { |
| 120 | return ns3::main(argc, argv); |
| 121 | } |