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" |
| 25 | #include "ns3/NDNabstraction-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 | #include "ns3/ipv4-global-routing-helper.h" |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 28 | |
| 29 | using namespace ns3; |
| 30 | |
| 31 | NS_LOG_COMPONENT_DEFINE ("CcnxGrid"); |
| 32 | |
Alexander Afanasyev | a514d63 | 2012-02-14 18:54:14 -0800 | [diff] [blame] | 33 | /** |
| 34 | * This scenario simulates a grid topology (using PointToPointGrid module) |
| 35 | * |
| 36 | * (consumer) -- ( ) ----- ( ) |
| 37 | * | | | |
| 38 | * ( ) ------ ( ) ----- ( ) |
| 39 | * | | | |
| 40 | * ( ) ------ ( ) -- (producer) |
| 41 | * |
| 42 | * Grid size could be specified using --nGrid parameter (default 3) |
| 43 | * |
| 44 | * All links are 1Mbps with propagation 10ms delay. |
| 45 | * |
| 46 | * FIB is populated based on hacks of GlobalRoutingController: in |
| 47 | * addition to normal assignment of IP addresses for every NetDevice |
| 48 | * interface, every node is assigned an IP address that numerically |
| 49 | * equals to node id (i.e., if node id is 15, the special address is |
| 50 | * 0.0.0.15/255.255.255.255). |
| 51 | * |
| 52 | * Consumer requests data from producer with frequency 10 interests per second |
| 53 | * (interests contain constantly increasing sequence number). |
| 54 | * |
| 55 | * For every received interest, producer replies with a data packet, containing |
| 56 | * 1024 bytes of virtual payload. |
| 57 | * |
| 58 | * Simulation time is 20 seconds, unless --finish parameter is specified |
| 59 | * |
| 60 | * To run scenario and see what is happening, use the following command: |
| 61 | * |
| 62 | * NS_LOG=CcnxSimple:CcnxConsumer ./waf --run=ccnx-grid |
| 63 | */ |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 64 | |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 65 | |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 66 | int |
| 67 | main (int argc, char *argv[]) |
| 68 | { |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 69 | Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps")); |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 70 | Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms")); |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 71 | Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20")); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 72 | |
Alexander Afanasyev | a514d63 | 2012-02-14 18:54:14 -0800 | [diff] [blame] | 73 | // Set maximum number of packets that will be cached (default 100) |
| 74 | Config::SetDefault ("ns3::CcnxContentStore::Size", StringValue ("1000")); |
| 75 | |
| 76 | uint32_t nGrid = 3; |
| 77 | Time finishTime = Seconds (20.0); |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 78 | |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 79 | CommandLine cmd; |
| 80 | cmd.AddValue ("nGrid", "Number of grid nodes", nGrid); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 81 | cmd.AddValue ("finish", "Finish time", finishTime); |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 82 | cmd.Parse (argc, argv); |
| 83 | |
| 84 | PointToPointHelper p2p; |
| 85 | |
| 86 | InternetStackHelper stack; |
| 87 | Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops"); |
| 88 | stack.SetRoutingHelper (ipv4RoutingHelper); |
Alexander Afanasyev | a514d63 | 2012-02-14 18:54:14 -0800 | [diff] [blame] | 89 | |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 90 | PointToPointGridHelper grid (nGrid, nGrid, p2p); |
| 91 | grid.BoundingBox(100,100,200,200); |
| 92 | |
| 93 | // Install CCNx stack |
| 94 | NS_LOG_INFO ("Installing CCNx stack"); |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 95 | CcnxStackHelper ccnxHelper; |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 96 | ccnxHelper.InstallAll (); |
| 97 | |
| 98 | // Install IP stack (necessary to populate FIB) |
| 99 | NS_LOG_INFO ("Installing IP stack"); |
| 100 | grid.InstallStack (stack); |
| 101 | grid.AssignIpv4Addresses ( |
| 102 | Ipv4AddressHelper("10.1.0.0", "255.255.255.0"), |
| 103 | Ipv4AddressHelper("10.2.0.0", "255.255.255.0") |
| 104 | ); |
| 105 | |
| 106 | Ptr<Node> producer = grid.GetNode (nGrid-1, nGrid-1); |
| 107 | NodeContainer consumerNodes; |
| 108 | consumerNodes.Add (grid.GetNode (0,0)); |
| 109 | |
| 110 | // Populate FIB based on IPv4 global routing controller |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 111 | ccnxHelper.InstallFakeGlobalRoutes (); |
| 112 | ccnxHelper.InstallRouteTo (producer); |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 113 | |
| 114 | NS_LOG_INFO ("Installing Applications"); |
| 115 | std::ostringstream prefix; |
| 116 | prefix << "/" << producer->GetId (); |
| 117 | |
Alexander Afanasyev | e1a065d | 2012-01-10 15:55:14 -0800 | [diff] [blame] | 118 | CcnxAppHelper consumerHelper ("ns3::CcnxConsumerCbr"); |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 119 | consumerHelper.SetPrefix (prefix.str ()); |
Alexander Afanasyev | a514d63 | 2012-02-14 18:54:14 -0800 | [diff] [blame] | 120 | consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 10 interests a second |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 121 | ApplicationContainer consumers = consumerHelper.Install (consumerNodes); |
| 122 | |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 123 | CcnxAppHelper producerHelper ("ns3::CcnxProducer"); |
| 124 | producerHelper.SetPrefix (prefix.str ()); |
| 125 | producerHelper.SetAttribute ("PayloadSize", StringValue("1024")); |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 126 | ApplicationContainer producers = producerHelper.Install (producer); |
| 127 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 128 | Simulator::Stop (finishTime); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 129 | |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 130 | NS_LOG_INFO ("Run Simulation."); |
| 131 | Simulator::Run (); |
| 132 | Simulator::Destroy (); |
| 133 | NS_LOG_INFO ("Done!"); |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 134 | |
Alexander Afanasyev | 176ed06 | 2011-11-15 23:49:22 -0800 | [diff] [blame] | 135 | return 0; |
Alexander Afanasyev | 3ba44e5 | 2011-11-10 16:38:10 -0800 | [diff] [blame] | 136 | } |