blob: d475dfd48855a5307ace5aae2874c9e6c5d465d3 [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 Afanasyevbe55cf62014-12-20 17:51:09 -080038 * All links are 1Mbps with propagation 10ms delay.
Alexander Afanasyeva514d632012-02-14 18:54:14 -080039 *
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
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080054main(int argc, char* argv[])
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070055{
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080056 // Setting default parameters for PointToPoint links and channels
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080057 Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps"));
58 Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
59 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 Afanasyevbe55cf62014-12-20 17:51:09 -080063 cmd.Parse(argc, argv);
Alexander Afanasyev176ed062011-11-15 23:49:22 -080064
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080065 // Creating 3x3 topology
Alexander Afanasyev176ed062011-11-15 23:49:22 -080066 PointToPointHelper p2p;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080067 PointToPointGridHelper grid(3, 3, p2p);
68 grid.BoundingBox(100, 100, 200, 200);
Alexander Afanasyev176ed062011-11-15 23:49:22 -080069
Alexander Afanasyev9fb2e3d2013-03-30 21:11:07 -070070 // Install NDN stack on all nodes
71 ndn::StackHelper ndnHelper;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080072 ndnHelper.SetForwardingStrategy("ns3::ndn::fw::BestRoute");
73 ndnHelper.InstallAll();
Alexander Afanasyev176ed062011-11-15 23:49:22 -080074
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080075 // Installing global routing interface on all nodes
Alexander Afanasyev9fb2e3d2013-03-30 21:11:07 -070076 ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080077 ndnGlobalRoutingHelper.InstallAll();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080078
Alexander Afanasyevd8599792012-04-17 22:26:29 -070079 // Getting containers for the consumer/producer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080080 Ptr<Node> producer = grid.GetNode(2, 2);
Alexander Afanasyev176ed062011-11-15 23:49:22 -080081 NodeContainer consumerNodes;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080082 consumerNodes.Add(grid.GetNode(0, 0));
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080083
Alexander Afanasyev9fb2e3d2013-03-30 21:11:07 -070084 // Install NDN applications
Alexander Afanasyevd8599792012-04-17 22:26:29 -070085 std::string prefix = "/prefix";
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080086
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080087 ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
88 consumerHelper.SetPrefix(prefix);
89 consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second
90 consumerHelper.Install(consumerNodes);
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080091
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080092 ndn::AppHelper producerHelper("ns3::ndn::Producer");
93 producerHelper.SetPrefix(prefix);
94 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
95 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 Afanasyevbe55cf62014-12-20 17:51:09 -080098 ndnGlobalRoutingHelper.AddOrigins(prefix, producer);
Alexander Afanasyevd8599792012-04-17 22:26:29 -070099
100 // Calculate and install FIBs
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800101 ndn::GlobalRoutingHelper::CalculateRoutes();
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700102
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800103 Simulator::Stop(Seconds(20.0));
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800104
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800105 Simulator::Run();
106 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}