blob: a5ba5402fe68d8b1a202645afdb31d39716e5990 [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
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080027namespace ns3 {
Shockb0f83152012-12-25 14:16:47 +080028
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
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080072 ndn::StackHelper ndnHelper;
73 // ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::SmartFlooding");
74 // ndnHelper.SetContentStore ("ns3::ndn::cs::Lru", "MaxSize", "10");
75 ndnHelper.InstallAll();
76
77 // Choosing forwarding strategy
78 ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/ncc");
Shockb0f83152012-12-25 14:16:47 +080079
80 // Installing global routing interface on all nodes
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080081 // ndn::CbisGlobalRoutingHelper ndnGlobalRoutingHelper;
82 ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
83 ndnGlobalRoutingHelper.InstallAll();
Shockb0f83152012-12-25 14:16:47 +080084
85 // Getting containers for the consumer/producer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080086 Ptr<Node> producer = grid.GetNode(2, 2);
Shockb0f83152012-12-25 14:16:47 +080087 NodeContainer consumerNodes;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080088 consumerNodes.Add(grid.GetNode(0, 0));
Shockb0f83152012-12-25 14:16:47 +080089
90 // Install CCNx applications
91 std::string prefix = "/prefix";
92
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080093 ndn::AppHelper consumerHelper("ns3::ndn::ConsumerZipfMandelbrot");
94 // ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr");
95 consumerHelper.SetPrefix(prefix);
96 consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second
97 consumerHelper.SetAttribute("NumberOfContents", StringValue("100")); // 10 different contents
98 // consumerHelper.SetAttribute ("Randomize", StringValue ("uniform")); // 100 interests a second
99 consumerHelper.Install(consumerNodes);
Shockb0f83152012-12-25 14:16:47 +0800100
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800101 ndn::AppHelper producerHelper("ns3::ndn::Producer");
102 producerHelper.SetPrefix(prefix);
103 producerHelper.SetAttribute("PayloadSize", StringValue("100"));
104 producerHelper.Install(producer);
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800105 ndnGlobalRoutingHelper.AddOrigins(prefix, producer);
Shockb0f83152012-12-25 14:16:47 +0800106
Shockb0f83152012-12-25 14:16:47 +0800107 // Calculate and install FIBs
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800108 ndn::GlobalRoutingHelper::CalculateRoutes();
Shockb0f83152012-12-25 14:16:47 +0800109
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800110 Simulator::Stop(Seconds(1.0));
Shockb0f83152012-12-25 14:16:47 +0800111
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800112 Simulator::Run();
113 Simulator::Destroy();
Shockb0f83152012-12-25 14:16:47 +0800114
115 return 0;
116}
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800117
118} // namespace ns3
119
120int
121main(int argc, char* argv[])
122{
123 return ns3::main(argc, argv);
124}