blob: 0651e22cb614c0bbb573f3535d3836b2ec55712c [file] [log] [blame]
Ilya Moiseenkoc9266042011-11-02 17:49:21 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -08003 * Copyright (c) 2011-2012 University of California, Los Angeles
Ilya Moiseenkoc9266042011-11-02 17:49:21 -07004 *
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 Afanasyevaa1c4c32012-11-21 16:17:03 -080018 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070019 */
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080020// ndn-grid.cc
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070021#include "ns3/core-module.h"
22#include "ns3/network-module.h"
23#include "ns3/point-to-point-module.h"
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080024#include "ns3/point-to-point-layout-module.h"
Alexander Afanasyev4885eea2012-06-01 12:28:15 -070025#include "ns3/ndnSIM-module.h"
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070026
27using namespace ns3;
28
Alexander Afanasyeva514d632012-02-14 18:54:14 -080029/**
30 * This scenario simulates a grid topology (using PointToPointGrid module)
31 *
32 * (consumer) -- ( ) ----- ( )
33 * | | |
34 * ( ) ------ ( ) ----- ( )
35 * | | |
36 * ( ) ------ ( ) -- (producer)
37 *
Alexander Afanasyeva514d632012-02-14 18:54:14 -080038 * All links are 1Mbps with propagation 10ms delay.
39 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070040 * FIB is populated using NdnGlobalRoutingHelper.
Alexander Afanasyeva514d632012-02-14 18:54:14 -080041 *
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080042 * Consumer requests data from producer with frequency 100 interests per second
Alexander Afanasyeva514d632012-02-14 18:54:14 -080043 * (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 Afanasyeva514d632012-02-14 18:54:14 -080048 * To run scenario and see what is happening, use the following command:
49 *
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080050 * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-grid
Alexander Afanasyeva514d632012-02-14 18:54:14 -080051 */
Alexander Afanasyev176ed062011-11-15 23:49:22 -080052
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080053int
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070054main (int argc, char *argv[])
55{
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080056 // Setting default parameters for PointToPoint links and channels
Alexander Afanasyev176ed062011-11-15 23:49:22 -080057 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -080058 Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms"));
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080059 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("10"));
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080060
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080061 // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
Alexander Afanasyev176ed062011-11-15 23:49:22 -080062 CommandLine cmd;
Alexander Afanasyev176ed062011-11-15 23:49:22 -080063 cmd.Parse (argc, argv);
64
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080065 // Creating 3x3 topology
Alexander Afanasyev176ed062011-11-15 23:49:22 -080066 PointToPointHelper p2p;
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080067 PointToPointGridHelper grid (3, 3, p2p);
Alexander Afanasyev176ed062011-11-15 23:49:22 -080068 grid.BoundingBox(100,100,200,200);
69
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080070 // Install CCNx stack on all nodes
71 ndn::StackHelper ccnxHelper;
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080072 ccnxHelper.SetForwardingStrategy ("ns3::ndn::fw::BestRoute");
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080073 ccnxHelper.InstallAll ();
Alexander Afanasyev176ed062011-11-15 23:49:22 -080074
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080075 // Installing global routing interface on all nodes
76 ndn::GlobalRoutingHelper ccnxGlobalRoutingHelper;
77 ccnxGlobalRoutingHelper.InstallAll ();
78
Alexander Afanasyevd8599792012-04-17 22:26:29 -070079 // Getting containers for the consumer/producer
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080080 Ptr<Node> producer = grid.GetNode (2, 2);
Alexander Afanasyev176ed062011-11-15 23:49:22 -080081 NodeContainer consumerNodes;
82 consumerNodes.Add (grid.GetNode (0,0));
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080083
84 // Install CCNx applications
Alexander Afanasyevd8599792012-04-17 22:26:29 -070085 std::string prefix = "/prefix";
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080086
Alexander Afanasyevcf6dc922012-08-10 16:55:27 -070087 ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr");
Alexander Afanasyevd8599792012-04-17 22:26:29 -070088 consumerHelper.SetPrefix (prefix);
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080089 consumerHelper.SetAttribute ("Frequency", StringValue ("100")); // 100 interests a second
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080090 consumerHelper.Install (consumerNodes);
91
Alexander Afanasyevcf6dc922012-08-10 16:55:27 -070092 ndn::AppHelper producerHelper ("ns3::ndn::Producer");
Alexander Afanasyevd8599792012-04-17 22:26:29 -070093 producerHelper.SetPrefix (prefix);
Alexander Afanasyev4975f732011-12-20 17:52:19 -080094 producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080095 producerHelper.Install (producer);
Alexander Afanasyevd8599792012-04-17 22:26:29 -070096
Alexander Afanasyevcf6dc922012-08-10 16:55:27 -070097 // Add /prefix origins to ndn::GlobalRouter
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080098 ccnxGlobalRoutingHelper.AddOrigins (prefix, producer);
Alexander Afanasyevd8599792012-04-17 22:26:29 -070099
100 // Calculate and install FIBs
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800101 ccnxGlobalRoutingHelper.CalculateRoutes ();
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700102
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800103 Simulator::Stop (Seconds (20.0));
104
105 Simulator::Run ();
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800106 Simulator::Destroy ();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800107
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800108 return 0;
Alexander Afanasyev3ba44e52011-11-10 16:38:10 -0800109}