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