blob: 0469109595959711fc1819f60b87ba5ab1f6ebb9 [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 */
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080020
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080021// ndn-grid.cc
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080022
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070023#include "ns3/core-module.h"
24#include "ns3/network-module.h"
25#include "ns3/point-to-point-module.h"
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080026#include "ns3/point-to-point-layout-module.h"
Alexander Afanasyev4885eea2012-06-01 12:28:15 -070027#include "ns3/ndnSIM-module.h"
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070028
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080029namespace ns3 {
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070030
Alexander Afanasyeva514d632012-02-14 18:54:14 -080031/**
32 * This scenario simulates a grid topology (using PointToPointGrid module)
33 *
34 * (consumer) -- ( ) ----- ( )
35 * | | |
36 * ( ) ------ ( ) ----- ( )
37 * | | |
38 * ( ) ------ ( ) -- (producer)
39 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080040 * All links are 1Mbps with propagation 10ms delay.
Alexander Afanasyeva514d632012-02-14 18:54:14 -080041 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070042 * FIB is populated using NdnGlobalRoutingHelper.
Alexander Afanasyeva514d632012-02-14 18:54:14 -080043 *
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080044 * Consumer requests data from producer with frequency 100 interests per second
Alexander Afanasyeva514d632012-02-14 18:54:14 -080045 * (interests contain constantly increasing sequence number).
46 *
47 * For every received interest, producer replies with a data packet, containing
48 * 1024 bytes of virtual payload.
49 *
Alexander Afanasyeva514d632012-02-14 18:54:14 -080050 * To run scenario and see what is happening, use the following command:
51 *
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080052 * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-grid
Alexander Afanasyeva514d632012-02-14 18:54:14 -080053 */
Alexander Afanasyev176ed062011-11-15 23:49:22 -080054
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080055int
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080056main(int argc, char* argv[])
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070057{
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -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("10ms"));
61 Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("10"));
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080062
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080063 // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
Alexander Afanasyev176ed062011-11-15 23:49:22 -080064 CommandLine cmd;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080065 cmd.Parse(argc, argv);
Alexander Afanasyev176ed062011-11-15 23:49:22 -080066
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080067 // Creating 3x3 topology
Alexander Afanasyev176ed062011-11-15 23:49:22 -080068 PointToPointHelper p2p;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080069 PointToPointGridHelper grid(3, 3, p2p);
70 grid.BoundingBox(100, 100, 200, 200);
Alexander Afanasyev176ed062011-11-15 23:49:22 -080071
Alexander Afanasyev9fb2e3d2013-03-30 21:11:07 -070072 // Install NDN stack on all nodes
73 ndn::StackHelper ndnHelper;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080074 ndnHelper.InstallAll();
Alexander Afanasyev176ed062011-11-15 23:49:22 -080075
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080076 // Set BestRoute strategy
77 ndn::StrategyChoiceHelper::InstallAll("/", "/localhost/nfd/strategy/best-route");
78
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080079 // Installing global routing interface on all nodes
Alexander Afanasyev9fb2e3d2013-03-30 21:11:07 -070080 ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080081 ndnGlobalRoutingHelper.InstallAll();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080082
Alexander Afanasyevd8599792012-04-17 22:26:29 -070083 // Getting containers for the consumer/producer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080084 Ptr<Node> producer = grid.GetNode(2, 2);
Alexander Afanasyev176ed062011-11-15 23:49:22 -080085 NodeContainer consumerNodes;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080086 consumerNodes.Add(grid.GetNode(0, 0));
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080087
Alexander Afanasyev9fb2e3d2013-03-30 21:11:07 -070088 // Install NDN applications
Alexander Afanasyevd8599792012-04-17 22:26:29 -070089 std::string prefix = "/prefix";
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080090
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080091 ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
92 consumerHelper.SetPrefix(prefix);
93 consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second
94 consumerHelper.Install(consumerNodes);
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080095
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080096 ndn::AppHelper producerHelper("ns3::ndn::Producer");
97 producerHelper.SetPrefix(prefix);
98 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
99 producerHelper.Install(producer);
Alexander Afanasyevd8599792012-04-17 22:26:29 -0700100
Alexander Afanasyevcf6dc922012-08-10 16:55:27 -0700101 // Add /prefix origins to ndn::GlobalRouter
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800102 ndnGlobalRoutingHelper.AddOrigins(prefix, producer);
Alexander Afanasyevd8599792012-04-17 22:26:29 -0700103
104 // Calculate and install FIBs
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800105 ndn::GlobalRoutingHelper::CalculateRoutes();
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700106
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800107 Simulator::Stop(Seconds(20.0));
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800108
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800109 Simulator::Run();
110 Simulator::Destroy();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800111
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800112 return 0;
Alexander Afanasyev3ba44e52011-11-10 16:38:10 -0800113}
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800114
115} // namespace ns3
116
117int
118main(int argc, char* argv[])
119{
120 return ns3::main(argc, argv);
121}