blob: 1ca72101fb87e80331f6c751f721173b4142f44d [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.
Ilya Moiseenkoc9266042011-11-02 17:49:21 -07004 *
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.
Ilya Moiseenkoc9266042011-11-02 17:49:21 -07007 *
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.
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070011 *
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.
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070015 *
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 **/
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080019
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080020// ndn-grid.cpp
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080021
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070022#include "ns3/core-module.h"
23#include "ns3/network-module.h"
24#include "ns3/point-to-point-module.h"
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080025#include "ns3/point-to-point-layout-module.h"
Alexander Afanasyev4885eea2012-06-01 12:28:15 -070026#include "ns3/ndnSIM-module.h"
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070027
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080028namespace ns3 {
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070029
Alexander Afanasyeva514d632012-02-14 18:54:14 -080030/**
31 * This scenario simulates a grid topology (using PointToPointGrid module)
32 *
33 * (consumer) -- ( ) ----- ( )
34 * | | |
35 * ( ) ------ ( ) ----- ( )
36 * | | |
37 * ( ) ------ ( ) -- (producer)
38 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080039 * All links are 1Mbps with propagation 10ms delay.
Alexander Afanasyeva514d632012-02-14 18:54:14 -080040 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070041 * FIB is populated using NdnGlobalRoutingHelper.
Alexander Afanasyeva514d632012-02-14 18:54:14 -080042 *
Alexander Afanasyeve095f0f2012-11-21 17:43:32 -080043 * Consumer requests data from producer with frequency 100 interests per second
Alexander Afanasyeva514d632012-02-14 18:54:14 -080044 * (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 *
Alexander Afanasyeva514d632012-02-14 18:54:14 -080049 * To run scenario and see what is happening, use the following command:
50 *
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080051 * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-grid
Alexander Afanasyeva514d632012-02-14 18:54:14 -080052 */
Alexander Afanasyev176ed062011-11-15 23:49:22 -080053
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080054int
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080055main(int argc, char* argv[])
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070056{
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -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("10ms"));
60 Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("10"));
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080061
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080062 // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
Alexander Afanasyev176ed062011-11-15 23:49:22 -080063 CommandLine cmd;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080064 cmd.Parse(argc, argv);
Alexander Afanasyev176ed062011-11-15 23:49:22 -080065
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080066 // Creating 3x3 topology
Alexander Afanasyev176ed062011-11-15 23:49:22 -080067 PointToPointHelper p2p;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080068 PointToPointGridHelper grid(3, 3, p2p);
69 grid.BoundingBox(100, 100, 200, 200);
Alexander Afanasyev176ed062011-11-15 23:49:22 -080070
Alexander Afanasyev9fb2e3d2013-03-30 21:11:07 -070071 // Install NDN stack on all nodes
72 ndn::StackHelper ndnHelper;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080073 ndnHelper.InstallAll();
Alexander Afanasyev176ed062011-11-15 23:49:22 -080074
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080075 // Set BestRoute strategy
76 ndn::StrategyChoiceHelper::InstallAll("/", "/localhost/nfd/strategy/best-route");
77
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080078 // Installing global routing interface on all nodes
Alexander Afanasyev9fb2e3d2013-03-30 21:11:07 -070079 ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080080 ndnGlobalRoutingHelper.InstallAll();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080081
Alexander Afanasyevd8599792012-04-17 22:26:29 -070082 // Getting containers for the consumer/producer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080083 Ptr<Node> producer = grid.GetNode(2, 2);
Alexander Afanasyev176ed062011-11-15 23:49:22 -080084 NodeContainer consumerNodes;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080085 consumerNodes.Add(grid.GetNode(0, 0));
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080086
Alexander Afanasyev9fb2e3d2013-03-30 21:11:07 -070087 // Install NDN applications
Alexander Afanasyevd8599792012-04-17 22:26:29 -070088 std::string prefix = "/prefix";
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080089
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080090 ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
91 consumerHelper.SetPrefix(prefix);
92 consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second
93 consumerHelper.Install(consumerNodes);
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080094
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080095 ndn::AppHelper producerHelper("ns3::ndn::Producer");
96 producerHelper.SetPrefix(prefix);
97 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
98 producerHelper.Install(producer);
Alexander Afanasyevd8599792012-04-17 22:26:29 -070099
Alexander Afanasyevcf6dc922012-08-10 16:55:27 -0700100 // Add /prefix origins to ndn::GlobalRouter
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800101 ndnGlobalRoutingHelper.AddOrigins(prefix, producer);
Alexander Afanasyevd8599792012-04-17 22:26:29 -0700102
103 // Calculate and install FIBs
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800104 ndn::GlobalRoutingHelper::CalculateRoutes();
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700105
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800106 Simulator::Stop(Seconds(20.0));
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800107
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800108 Simulator::Run();
109 Simulator::Destroy();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800110
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800111 return 0;
Alexander Afanasyev3ba44e52011-11-10 16:38:10 -0800112}
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800113
114} // namespace ns3
115
116int
117main(int argc, char* argv[])
118{
119 return ns3::main(argc, argv);
120}