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 | * |
| 50 | * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-grid |
| 51 | */ |
| 52 | |
| 53 | int |
| 54 | main (int argc, char *argv[]) |
| 55 | { |
| 56 | LogComponentEnable("ndn.ConsumerZipfMandelbrot", LOG_LEVEL_DEBUG); |
| 57 | LogComponentEnable("ndn.ConsumerCbr", LOG_LEVEL_INFO); |
| 58 | LogComponentEnable("ndn.Producer", LOG_LEVEL_INFO); |
| 59 | LogComponentEnable("ndn.Consumer", LOG_LEVEL_INFO); |
| 60 | //LogComponentEnable("ndn.CbisGlobalRoutingHelper", LOG_LEVEL_INFO); |
| 61 | // Setting default parameters for PointToPoint links and channels |
| 62 | Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps")); |
| 63 | Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("1ms")); |
| 64 | Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("10")); |
| 65 | |
| 66 | // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize |
| 67 | CommandLine cmd; |
| 68 | cmd.Parse (argc, argv); |
| 69 | |
| 70 | // Creating 3x3 topology |
| 71 | PointToPointHelper p2p; |
| 72 | PointToPointGridHelper grid (3, 3, p2p); |
| 73 | grid.BoundingBox(100,100,200,200); |
| 74 | |
| 75 | // Install CCNx stack on all nodes |
| 76 | ndn::StackHelper ccnxHelper; |
| 77 | ccnxHelper.SetForwardingStrategy ("ns3::ndn::fw::SmartFlooding"); |
| 78 | ccnxHelper.SetContentStore ("ns3::ndn::cs::Lru", "MaxSize", "10"); |
| 79 | ccnxHelper.InstallAll (); |
| 80 | |
| 81 | // Installing global routing interface on all nodes |
| 82 | //ndn::CbisGlobalRoutingHelper ccnxGlobalRoutingHelper; |
| 83 | ndn::GlobalRoutingHelper ccnxGlobalRoutingHelper; |
| 84 | ccnxGlobalRoutingHelper.InstallAll (); |
| 85 | |
| 86 | // Getting containers for the consumer/producer |
| 87 | Ptr<Node> producer = grid.GetNode (2, 2); |
| 88 | NodeContainer consumerNodes; |
| 89 | consumerNodes.Add (grid.GetNode (0,0)); |
| 90 | |
| 91 | // Install CCNx applications |
| 92 | std::string prefix = "/prefix"; |
| 93 | |
| 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 ("Randomize", StringValue ("uniform")); // 100 interests a second |
| 99 | consumerHelper.Install (consumerNodes); |
| 100 | |
| 101 | ndn::AppHelper producerHelper ("ns3::ndn::Producer"); |
| 102 | producerHelper.SetPrefix (prefix); |
| 103 | producerHelper.SetAttribute ("PayloadSize", StringValue("100")); |
| 104 | producerHelper.Install (producer); |
| 105 | ccnxGlobalRoutingHelper.AddOrigins (prefix, producer); |
| 106 | |
| 107 | //Ptr<Node> producer2 = grid.GetNode(1,2); |
| 108 | //producerHelper.Install (producer2); |
| 109 | // Add /prefix origins to ndn::GlobalRouter |
| 110 | //ccnxGlobalRoutingHelper.AddOrigins (prefix, producer2); |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | // Add /prefix origins to ndn::GlobalRouter |
| 116 | //ccnxGlobalRoutingHelper.AddOrigins (prefix, producer); |
| 117 | |
| 118 | |
| 119 | // Calculate and install FIBs |
| 120 | ccnxGlobalRoutingHelper.CalculateRoutes (); |
| 121 | |
| 122 | //ccnxGlobalRoutingHelper.CalculateRoutes2 (); |
| 123 | |
| 124 | Simulator::Stop (Seconds (10.0)); |
| 125 | |
| 126 | Simulator::Run (); |
| 127 | Simulator::Destroy (); |
| 128 | |
| 129 | return 0; |
| 130 | } |