Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011 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: Ilya Moiseenko <iliamo@cs.ucla.edu> |
Alexander Afanasyev | a514d63 | 2012-02-14 18:54:14 -0800 | [diff] [blame] | 19 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include "ns3/core-module.h" |
| 23 | #include "ns3/network-module.h" |
| 24 | #include "ns3/point-to-point-module.h" |
Alexander Afanasyev | 4885eea | 2012-06-01 12:28:15 -0700 | [diff] [blame] | 25 | #include "ns3/ndnSIM-module.h" |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 26 | #include "ns3/point-to-point-grid.h" |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 27 | |
| 28 | using namespace ns3; |
| 29 | |
| 30 | NS_LOG_COMPONENT_DEFINE ("CcnxGrid"); |
| 31 | |
Alexander Afanasyev | a514d63 | 2012-02-14 18:54:14 -0800 | [diff] [blame] | 32 | /** |
| 33 | * This scenario simulates a grid topology (using PointToPointGrid module) |
| 34 | * |
| 35 | * (consumer) -- ( ) ----- ( ) |
| 36 | * | | | |
| 37 | * ( ) ------ ( ) ----- ( ) |
| 38 | * | | | |
| 39 | * ( ) ------ ( ) -- (producer) |
| 40 | * |
| 41 | * Grid size could be specified using --nGrid parameter (default 3) |
| 42 | * |
| 43 | * All links are 1Mbps with propagation 10ms delay. |
| 44 | * |
Alexander Afanasyev | 07b0063 | 2012-06-01 23:46:47 -0700 | [diff] [blame] | 45 | * FIB is populated using CcnxGlobalRoutingHelper. |
Alexander Afanasyev | a514d63 | 2012-02-14 18:54:14 -0800 | [diff] [blame] | 46 | * |
| 47 | * Consumer requests data from producer with frequency 10 interests per second |
| 48 | * (interests contain constantly increasing sequence number). |
| 49 | * |
| 50 | * For every received interest, producer replies with a data packet, containing |
| 51 | * 1024 bytes of virtual payload. |
| 52 | * |
| 53 | * Simulation time is 20 seconds, unless --finish parameter is specified |
| 54 | * |
| 55 | * To run scenario and see what is happening, use the following command: |
| 56 | * |
| 57 | * NS_LOG=CcnxSimple:CcnxConsumer ./waf --run=ccnx-grid |
| 58 | */ |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 59 | |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 60 | |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 61 | int |
| 62 | main (int argc, char *argv[]) |
| 63 | { |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 64 | Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps")); |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 65 | Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms")); |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 66 | Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20")); |
Alexander Afanasyev | a514d63 | 2012-02-14 18:54:14 -0800 | [diff] [blame] | 67 | |
| 68 | uint32_t nGrid = 3; |
| 69 | Time finishTime = Seconds (20.0); |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 70 | |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 71 | CommandLine cmd; |
| 72 | cmd.AddValue ("nGrid", "Number of grid nodes", nGrid); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 73 | cmd.AddValue ("finish", "Finish time", finishTime); |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 74 | cmd.Parse (argc, argv); |
| 75 | |
| 76 | PointToPointHelper p2p; |
| 77 | |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 78 | PointToPointGridHelper grid (nGrid, nGrid, p2p); |
| 79 | grid.BoundingBox(100,100,200,200); |
| 80 | |
Alexander Afanasyev | d859979 | 2012-04-17 22:26:29 -0700 | [diff] [blame] | 81 | // Install CCNx stack on all nodes |
| 82 | NS_LOG_INFO ("Installing CCNx stack on all nodes"); |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 83 | CcnxStackHelper ccnxHelper; |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 84 | ccnxHelper.SetContentStore ("ns3::CcnxContentStoreRandom", |
| 85 | "Size", "10"); |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 86 | ccnxHelper.InstallAll (); |
| 87 | |
Alexander Afanasyev | d859979 | 2012-04-17 22:26:29 -0700 | [diff] [blame] | 88 | CcnxGlobalRoutingHelper ccnxGlobalRoutingHelper; |
| 89 | ccnxGlobalRoutingHelper.InstallAll (); |
| 90 | |
| 91 | // Getting containers for the consumer/producer |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 92 | Ptr<Node> producer = grid.GetNode (nGrid-1, nGrid-1); |
| 93 | NodeContainer consumerNodes; |
| 94 | consumerNodes.Add (grid.GetNode (0,0)); |
| 95 | |
Alexander Afanasyev | d859979 | 2012-04-17 22:26:29 -0700 | [diff] [blame] | 96 | // Install CCNx applications |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 97 | NS_LOG_INFO ("Installing Applications"); |
Alexander Afanasyev | d859979 | 2012-04-17 22:26:29 -0700 | [diff] [blame] | 98 | std::string prefix = "/prefix"; |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 99 | |
Alexander Afanasyev | e1a065d | 2012-01-10 15:55:14 -0800 | [diff] [blame] | 100 | CcnxAppHelper consumerHelper ("ns3::CcnxConsumerCbr"); |
Alexander Afanasyev | d859979 | 2012-04-17 22:26:29 -0700 | [diff] [blame] | 101 | consumerHelper.SetPrefix (prefix); |
Alexander Afanasyev | a514d63 | 2012-02-14 18:54:14 -0800 | [diff] [blame] | 102 | consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 10 interests a second |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 103 | ApplicationContainer consumers = consumerHelper.Install (consumerNodes); |
| 104 | |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 105 | CcnxAppHelper producerHelper ("ns3::CcnxProducer"); |
Alexander Afanasyev | d859979 | 2012-04-17 22:26:29 -0700 | [diff] [blame] | 106 | producerHelper.SetPrefix (prefix); |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 107 | producerHelper.SetAttribute ("PayloadSize", StringValue("1024")); |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 108 | ApplicationContainer producers = producerHelper.Install (producer); |
Alexander Afanasyev | d859979 | 2012-04-17 22:26:29 -0700 | [diff] [blame] | 109 | |
| 110 | // Add /prefix origins to CcnxGlobalRouter |
| 111 | ccnxGlobalRoutingHelper.AddOrigins (prefix, producer); |
| 112 | |
| 113 | // Calculate and install FIBs |
| 114 | ccnxGlobalRoutingHelper.CalculateRoutes (); |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 115 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 116 | Simulator::Stop (finishTime); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 117 | |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 118 | NS_LOG_INFO ("Run Simulation."); |
| 119 | Simulator::Run (); |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 120 | |
| 121 | for (NodeList::Iterator node = NodeList::Begin (); |
| 122 | node != NodeList::End (); |
| 123 | node ++) |
| 124 | { |
| 125 | std::cout << "Node #" << (*node)->GetId () << std::endl; |
| 126 | (*node)->GetObject<CcnxContentStore> ()->Print (std::cout); |
| 127 | std::cout << std::endl; |
| 128 | } |
| 129 | |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 130 | Simulator::Destroy (); |
| 131 | NS_LOG_INFO ("Done!"); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 132 | |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 133 | return 0; |
Alexander Afanasyev | 3ba44e5 | 2011-11-10 16:38:10 -0800 | [diff] [blame] | 134 | } |