blob: 0aa129d8ad6eca4f545bc9298389236f62e7367d [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.
Alexander Afanasyevf04d4512012-02-14 18:42: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.
Alexander Afanasyevf04d4512012-02-14 18:42: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.
Alexander Afanasyevf04d4512012-02-14 18:42: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.
Alexander Afanasyevf04d4512012-02-14 18:42: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-simple.cpp
21
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080022#include "ns3/core-module.h"
23#include "ns3/network-module.h"
24#include "ns3/point-to-point-module.h"
Alexander Afanasyev4885eea2012-06-01 12:28:15 -070025#include "ns3/ndnSIM-module.h"
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080026
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080027namespace ns3 {
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080028
29/**
30 * This scenario simulates a very simple network topology:
31 *
32 *
33 * +----------+ 1Mbps +--------+ 1Mbps +----------+
34 * | consumer | <------------> | router | <------------> | producer |
35 * +----------+ 10ms +--------+ 10ms +----------+
36 *
37 *
38 * Consumer requests data from producer with frequency 10 interests per second
39 * (interests contain constantly increasing sequence number).
40 *
41 * For every received interest, producer replies with a data packet, containing
42 * 1024 bytes of virtual payload.
43 *
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080044 * To run scenario and see what is happening, use the following command:
45 *
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080046 * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-simple
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080047 */
48
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080049int
50main(int argc, char* argv[])
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080051{
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080052 // setting default parameters for PointToPoint links and channels
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080053 Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps"));
54 Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
Alexander Afanasyevf007a992022-05-05 15:57:08 -040055 Config::SetDefault("ns3::DropTailQueue<Packet>::MaxSize", StringValue("20p"));
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080056
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080057 // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080058 CommandLine cmd;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080059 cmd.Parse(argc, argv);
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080060
61 // Creating nodes
62 NodeContainer nodes;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080063 nodes.Create(3);
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080064
65 // Connecting nodes using two links
66 PointToPointHelper p2p;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080067 p2p.Install(nodes.Get(0), nodes.Get(1));
68 p2p.Install(nodes.Get(1), nodes.Get(2));
Alexander Afanasyevf04d4512012-02-14 18:42:47 -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.SetDefaultRoutes(true);
73 ndnHelper.InstallAll();
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080074
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080075 // Choosing forwarding strategy
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -070076 ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/multicast");
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080077
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080078 // Installing applications
79
80 // Consumer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080081 ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080082 // Consumer will request /prefix/0, /prefix/1, ...
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080083 consumerHelper.SetPrefix("/prefix");
84 consumerHelper.SetAttribute("Frequency", StringValue("10")); // 10 interests a second
Alexander Afanasyev6995bb72019-02-23 15:53:26 -050085 auto apps = consumerHelper.Install(nodes.Get(0)); // first node
86 apps.Stop(Seconds(10.0)); // stop the consumer app at 10 seconds mark
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080087
88 // Producer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080089 ndn::AppHelper producerHelper("ns3::ndn::Producer");
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080090 // Producer will reply to all requests starting with /prefix
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080091 producerHelper.SetPrefix("/prefix");
92 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
93 producerHelper.Install(nodes.Get(2)); // last node
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080094
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080095 Simulator::Stop(Seconds(20.0));
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080096
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080097 Simulator::Run();
98 Simulator::Destroy();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080099
Alexander Afanasyevf04d4512012-02-14 18:42:47 -0800100 return 0;
101}
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800102
103} // namespace ns3
104
105int
106main(int argc, char* argv[])
107{
108 return ns3::main(argc, argv);
109}