blob: bb2d7db837ffcab91af5187d811f90f1945dc016 [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 *
42 * Consumer requests data from producer with frequency 10 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 *
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 Afanasyevc39f0b42011-11-28 12:51:12 -080059 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
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;
72 ccnxHelper.InstallAll ();
Alexander Afanasyev176ed062011-11-15 23:49:22 -080073
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080074 // Installing global routing interface on all nodes
75 ndn::GlobalRoutingHelper ccnxGlobalRoutingHelper;
76 ccnxGlobalRoutingHelper.InstallAll ();
77
Alexander Afanasyevd8599792012-04-17 22:26:29 -070078 // Getting containers for the consumer/producer
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080079 Ptr<Node> producer = grid.GetNode (2, 2);
Alexander Afanasyev176ed062011-11-15 23:49:22 -080080 NodeContainer consumerNodes;
81 consumerNodes.Add (grid.GetNode (0,0));
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080082
83 // Install CCNx applications
Alexander Afanasyevd8599792012-04-17 22:26:29 -070084 std::string prefix = "/prefix";
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080085
Alexander Afanasyevcf6dc922012-08-10 16:55:27 -070086 ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr");
Alexander Afanasyevd8599792012-04-17 22:26:29 -070087 consumerHelper.SetPrefix (prefix);
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080088 consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 10 interests a second
89 consumerHelper.Install (consumerNodes);
90
Alexander Afanasyevcf6dc922012-08-10 16:55:27 -070091 ndn::AppHelper producerHelper ("ns3::ndn::Producer");
Alexander Afanasyevd8599792012-04-17 22:26:29 -070092 producerHelper.SetPrefix (prefix);
Alexander Afanasyev4975f732011-12-20 17:52:19 -080093 producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080094 producerHelper.Install (producer);
Alexander Afanasyevd8599792012-04-17 22:26:29 -070095
Alexander Afanasyevcf6dc922012-08-10 16:55:27 -070096 // Add /prefix origins to ndn::GlobalRouter
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080097 ccnxGlobalRoutingHelper.AddOrigins (prefix, producer);
Alexander Afanasyevd8599792012-04-17 22:26:29 -070098
99 // Calculate and install FIBs
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800100 ccnxGlobalRoutingHelper.CalculateRoutes ();
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700101
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800102 Simulator::Stop (Seconds (20.0));
103
104 Simulator::Run ();
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800105 Simulator::Destroy ();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800106
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800107 return 0;
Alexander Afanasyev3ba44e52011-11-10 16:38:10 -0800108}