blob: 4bec18ea4dc555106bb8eb7a810a6bd1bf08597f [file] [log] [blame]
Shockb0f83152012-12-25 14:16:47 +08001/* -*- 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
27using 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 *
Alexander Afanasyev13800102012-12-25 00:30:31 -080050 * NS_LOG=ndn.Consumer:ndn.ConsumerZipfMandelbrot:ndn.Producer ./waf --run=ndn-zipf-mandelbrot
Shockb0f83152012-12-25 14:16:47 +080051 */
52
53int
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080054main(int argc, char* argv[])
Shockb0f83152012-12-25 14:16:47 +080055{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080056 // LogComponentEnable("ndn.CbisGlobalRoutingHelper", LOG_LEVEL_INFO);
Shockb0f83152012-12-25 14:16:47 +080057 // Setting default parameters for PointToPoint links and channels
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080058 Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps"));
59 Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("1ms"));
60 Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("10"));
Shockb0f83152012-12-25 14:16:47 +080061
62 // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
63 CommandLine cmd;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080064 cmd.Parse(argc, argv);
Shockb0f83152012-12-25 14:16:47 +080065
66 // Creating 3x3 topology
67 PointToPointHelper p2p;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080068 PointToPointGridHelper grid(3, 3, p2p);
69 grid.BoundingBox(100, 100, 200, 200);
Shockb0f83152012-12-25 14:16:47 +080070
71 // Install CCNx stack on all nodes
72 ndn::StackHelper ccnxHelper;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080073 ccnxHelper.SetForwardingStrategy("ns3::ndn::fw::SmartFlooding");
74 ccnxHelper.SetContentStore("ns3::ndn::cs::Lru", "MaxSize", "10");
75 ccnxHelper.InstallAll();
Shockb0f83152012-12-25 14:16:47 +080076
77 // Installing global routing interface on all nodes
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080078 // ndn::CbisGlobalRoutingHelper ccnxGlobalRoutingHelper;
Shockb0f83152012-12-25 14:16:47 +080079 ndn::GlobalRoutingHelper ccnxGlobalRoutingHelper;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080080 ccnxGlobalRoutingHelper.InstallAll();
Shockb0f83152012-12-25 14:16:47 +080081
82 // Getting containers for the consumer/producer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080083 Ptr<Node> producer = grid.GetNode(2, 2);
Shockb0f83152012-12-25 14:16:47 +080084 NodeContainer consumerNodes;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080085 consumerNodes.Add(grid.GetNode(0, 0));
Shockb0f83152012-12-25 14:16:47 +080086
87 // Install CCNx applications
88 std::string prefix = "/prefix";
89
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080090 ndn::AppHelper consumerHelper("ns3::ndn::ConsumerZipfMandelbrot");
91 // ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr");
92 consumerHelper.SetPrefix(prefix);
93 consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second
94 consumerHelper.SetAttribute("NumberOfContents", StringValue("100")); // 10 different contents
95 // consumerHelper.SetAttribute ("Randomize", StringValue ("uniform")); // 100 interests a second
96 consumerHelper.Install(consumerNodes);
Shockb0f83152012-12-25 14:16:47 +080097
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080098 ndn::AppHelper producerHelper("ns3::ndn::Producer");
99 producerHelper.SetPrefix(prefix);
100 producerHelper.SetAttribute("PayloadSize", StringValue("100"));
101 producerHelper.Install(producer);
102 ccnxGlobalRoutingHelper.AddOrigins(prefix, producer);
Shockb0f83152012-12-25 14:16:47 +0800103
Shockb0f83152012-12-25 14:16:47 +0800104 // Calculate and install FIBs
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800105 ccnxGlobalRoutingHelper.CalculateRoutes();
Shockb0f83152012-12-25 14:16:47 +0800106
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800107 Simulator::Stop(Seconds(10.0));
Shockb0f83152012-12-25 14:16:47 +0800108
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800109 Simulator::Run();
110 Simulator::Destroy();
Shockb0f83152012-12-25 14:16:47 +0800111
112 return 0;
113}