blob: 8ebeccd73fc80dab4009fe64d7ee25dafca502ba [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Shockb0f83152012-12-25 14:16:47 +08004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Shockb0f83152012-12-25 14:16:47 +08007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * ndnSIM is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
Shockb0f83152012-12-25 14:16:47 +080011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Shockb0f83152012-12-25 14:16:47 +080015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * You should have received a copy of the GNU General Public License along with
17 * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
19
20// ndn-grid.cpp
21
Shockb0f83152012-12-25 14:16:47 +080022#include "ns3/core-module.h"
23#include "ns3/network-module.h"
24#include "ns3/point-to-point-module.h"
25#include "ns3/point-to-point-layout-module.h"
26#include "ns3/ndnSIM-module.h"
27
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080028namespace ns3 {
Shockb0f83152012-12-25 14:16:47 +080029
30/**
31 * This scenario simulates a grid topology (using PointToPointGrid module)
32 *
33 * (consumer) -- ( ) ----- ( )
34 * | | |
35 * ( ) ------ ( ) ----- ( )
36 * | | |
37 * ( ) ------ ( ) -- (producer)(2,2)
38 *
39 * All links are 1Mbps with propagation 10ms delay.
40 *
41 * FIB is populated using NdnGlobalRoutingHelper.
42 *
43 * Consumer requests data from producer with frequency 100 interests per second
44 * (interests contain constantly increasing sequence number).
45 *
46 * For every received interest, producer replies with a data packet, containing
47 * 1024 bytes of virtual payload.
48 *
49 * To run scenario and see what is happening, use the following command:
50 *
Alexander Afanasyev13800102012-12-25 00:30:31 -080051 * NS_LOG=ndn.Consumer:ndn.ConsumerZipfMandelbrot:ndn.Producer ./waf --run=ndn-zipf-mandelbrot
Shockb0f83152012-12-25 14:16:47 +080052 */
53
54int
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080055main(int argc, char* argv[])
Shockb0f83152012-12-25 14:16:47 +080056{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080057 // LogComponentEnable("ndn.CbisGlobalRoutingHelper", LOG_LEVEL_INFO);
Shockb0f83152012-12-25 14:16:47 +080058 // Setting default parameters for PointToPoint links and channels
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080059 Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps"));
60 Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("1ms"));
Spyridon Mastorakisf98a3412017-10-30 11:47:58 -070061 Config::SetDefault("ns3::QueueBase::MaxPackets", UintegerValue(10));
Shockb0f83152012-12-25 14:16:47 +080062
63 // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
64 CommandLine cmd;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080065 cmd.Parse(argc, argv);
Shockb0f83152012-12-25 14:16:47 +080066
67 // Creating 3x3 topology
68 PointToPointHelper p2p;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080069 PointToPointGridHelper grid(3, 3, p2p);
70 grid.BoundingBox(100, 100, 200, 200);
Shockb0f83152012-12-25 14:16:47 +080071
72 // Install CCNx stack on all nodes
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080073 ndn::StackHelper ndnHelper;
74 // ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::SmartFlooding");
75 // ndnHelper.SetContentStore ("ns3::ndn::cs::Lru", "MaxSize", "10");
76 ndnHelper.InstallAll();
77
78 // Choosing forwarding strategy
79 ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/ncc");
Shockb0f83152012-12-25 14:16:47 +080080
81 // Installing global routing interface on all nodes
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080082 // ndn::CbisGlobalRoutingHelper ndnGlobalRoutingHelper;
83 ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
84 ndnGlobalRoutingHelper.InstallAll();
Shockb0f83152012-12-25 14:16:47 +080085
86 // Getting containers for the consumer/producer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080087 Ptr<Node> producer = grid.GetNode(2, 2);
Shockb0f83152012-12-25 14:16:47 +080088 NodeContainer consumerNodes;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080089 consumerNodes.Add(grid.GetNode(0, 0));
Shockb0f83152012-12-25 14:16:47 +080090
91 // Install CCNx applications
92 std::string prefix = "/prefix";
93
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080094 ndn::AppHelper consumerHelper("ns3::ndn::ConsumerZipfMandelbrot");
95 // ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr");
96 consumerHelper.SetPrefix(prefix);
97 consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second
98 consumerHelper.SetAttribute("NumberOfContents", StringValue("100")); // 10 different contents
99 // consumerHelper.SetAttribute ("Randomize", StringValue ("uniform")); // 100 interests a second
100 consumerHelper.Install(consumerNodes);
Shockb0f83152012-12-25 14:16:47 +0800101
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800102 ndn::AppHelper producerHelper("ns3::ndn::Producer");
103 producerHelper.SetPrefix(prefix);
104 producerHelper.SetAttribute("PayloadSize", StringValue("100"));
105 producerHelper.Install(producer);
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800106 ndnGlobalRoutingHelper.AddOrigins(prefix, producer);
Shockb0f83152012-12-25 14:16:47 +0800107
Shockb0f83152012-12-25 14:16:47 +0800108 // Calculate and install FIBs
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800109 ndn::GlobalRoutingHelper::CalculateRoutes();
Shockb0f83152012-12-25 14:16:47 +0800110
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800111 Simulator::Stop(Seconds(1.0));
Shockb0f83152012-12-25 14:16:47 +0800112
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800113 Simulator::Run();
114 Simulator::Destroy();
Shockb0f83152012-12-25 14:16:47 +0800115
116 return 0;
117}
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800118
119} // namespace ns3
120
121int
122main(int argc, char* argv[])
123{
124 return ns3::main(argc, argv);
125}