Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011-2012 University of California, Los Angeles |
| 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 | * |
| 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | */ |
| 20 | // ndn-grid.cc |
| 21 | #include "ns3/core-module.h" |
| 22 | #include "ns3/network-module.h" |
| 23 | #include "ns3/point-to-point-module.h" |
| 24 | #include "ns3/point-to-point-layout-module.h" |
| 25 | #include "ns3/ndnSIM-module.h" |
| 26 | |
| 27 | using namespace ns3; |
| 28 | |
| 29 | /** |
| 30 | * This scenario simulates a grid topology (using PointToPointGrid module) |
| 31 | * |
| 32 | * (consumer) -- ( ) ----- ( ) |
| 33 | * | | | |
| 34 | * ( ) ------ ( ) ----- ( ) |
| 35 | * | | | |
| 36 | * ( ) ------ ( ) -- (producer)(2,2) |
| 37 | * |
| 38 | * All links are 1Mbps with propagation 10ms delay. |
| 39 | * |
| 40 | * FIB is populated using NdnGlobalRoutingHelper. |
| 41 | * |
| 42 | * Consumer requests data from producer with frequency 100 interests per second |
| 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 | * |
| 48 | * To run scenario and see what is happening, use the following command: |
| 49 | * |
Alexander Afanasyev | 1380010 | 2012-12-25 00:30:31 -0800 | [diff] [blame] | 50 | * NS_LOG=ndn.Consumer:ndn.ConsumerZipfMandelbrot:ndn.Producer ./waf --run=ndn-zipf-mandelbrot |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 51 | */ |
| 52 | |
| 53 | int |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 54 | main(int argc, char* argv[]) |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 55 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 56 | // LogComponentEnable("ndn.CbisGlobalRoutingHelper", LOG_LEVEL_INFO); |
Shock | b0f8315 | 2012-12-25 14:16:47 +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("1ms")); |
| 60 | Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("10")); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 61 | |
| 62 | // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize |
| 63 | CommandLine cmd; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 64 | cmd.Parse(argc, argv); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 65 | |
| 66 | // Creating 3x3 topology |
| 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); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 70 | |
| 71 | // Install CCNx stack on all nodes |
| 72 | ndn::StackHelper ccnxHelper; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 73 | ccnxHelper.SetForwardingStrategy("ns3::ndn::fw::SmartFlooding"); |
| 74 | ccnxHelper.SetContentStore("ns3::ndn::cs::Lru", "MaxSize", "10"); |
| 75 | ccnxHelper.InstallAll(); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 76 | |
| 77 | // Installing global routing interface on all nodes |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 78 | // ndn::CbisGlobalRoutingHelper ccnxGlobalRoutingHelper; |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 79 | ndn::GlobalRoutingHelper ccnxGlobalRoutingHelper; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 80 | ccnxGlobalRoutingHelper.InstallAll(); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 81 | |
| 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); |
Shock | b0f8315 | 2012-12-25 14:16:47 +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)); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 86 | |
| 87 | // Install CCNx applications |
| 88 | std::string prefix = "/prefix"; |
| 89 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 90 | ndn::AppHelper consumerHelper("ns3::ndn::ConsumerZipfMandelbrot"); |
| 91 | // ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr"); |
| 92 | consumerHelper.SetPrefix(prefix); |
| 93 | consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second |
| 94 | consumerHelper.SetAttribute("NumberOfContents", StringValue("100")); // 10 different contents |
| 95 | // consumerHelper.SetAttribute ("Randomize", StringValue ("uniform")); // 100 interests a second |
| 96 | consumerHelper.Install(consumerNodes); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 97 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 98 | ndn::AppHelper producerHelper("ns3::ndn::Producer"); |
| 99 | producerHelper.SetPrefix(prefix); |
| 100 | producerHelper.SetAttribute("PayloadSize", StringValue("100")); |
| 101 | producerHelper.Install(producer); |
| 102 | ccnxGlobalRoutingHelper.AddOrigins(prefix, producer); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 103 | |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 104 | // Calculate and install FIBs |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 105 | ccnxGlobalRoutingHelper.CalculateRoutes(); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 106 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 107 | Simulator::Stop(Seconds(10.0)); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 108 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 109 | Simulator::Run(); |
| 110 | Simulator::Destroy(); |
Shock | b0f8315 | 2012-12-25 14:16:47 +0800 | [diff] [blame] | 111 | |
| 112 | return 0; |
| 113 | } |