blob: 971d8fa38db88f57ddf93bd891e70accc6dc45fd [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 Afanasyev0fb80b92013-07-20 08:20:50 -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.
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -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.
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -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.
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -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 **/
19
20// ndn-simple-with-link-failure.cpp
21
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -070022#include "ns3/core-module.h"
23#include "ns3/network-module.h"
24#include "ns3/point-to-point-module.h"
25#include "ns3/ndnSIM-module.h"
26
27// for LinkStatusControl::FailLinks and LinkStatusControl::UpLinks
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080028#include "ns3/ndnSIM/helper/ndn-link-control-helper.hpp"
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -070029
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080030namespace ns3 {
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -070031
32/**
33 * This scenario simulates a very simple network topology:
34 *
35 *
36 * +----------+ 1Mbps +--------+ 1Mbps +----------+
37 * | consumer | <------------> | router | <------------> | producer |
38 * +----------+ 10ms +--------+ 10ms +----------+
39 *
40 *
41 * Consumer requests data from producer with frequency 10 interests per second
42 * (interests contain constantly increasing sequence number).
43 *
44 * For every received interest, producer replies with a data packet, containing
45 * 1024 bytes of virtual payload.
46 *
47 * To run scenario and see what is happening, use the following command:
48 *
Alexander Afanasyevafe47fe2015-01-06 18:29:39 -080049 * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-simple-with-link-failure
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -070050 */
51
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080052int
53main(int argc, char* argv[])
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -070054{
55 // setting default parameters for PointToPoint links and channels
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080056 Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps"));
57 Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
Alexander Afanasyevf007a992022-05-05 15:57:08 -040058 Config::SetDefault("ns3::DropTailQueue<Packet>::MaxSize", StringValue("20p"));
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -070059
60 // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
61 CommandLine cmd;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080062 cmd.Parse(argc, argv);
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -070063
64 // Creating nodes
65 NodeContainer nodes;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066 nodes.Create(3);
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -070067
68 // Connecting nodes using two links
69 PointToPointHelper p2p;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080070 p2p.Install(nodes.Get(0), nodes.Get(1));
71 p2p.Install(nodes.Get(1), nodes.Get(2));
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -070072
73 // Install NDN stack on all nodes
74 ndn::StackHelper ndnHelper;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080075 ndnHelper.SetDefaultRoutes(true);
76 ndnHelper.InstallAll();
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -070077
78 // Installing applications
79
80 // Consumer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080081 ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -070082 // 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
85 consumerHelper.Install(nodes.Get(0)); // first node
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -070086
87 // Producer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080088 ndn::AppHelper producerHelper("ns3::ndn::Producer");
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -070089 // Producer will reply to all requests starting with /prefix
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080090 producerHelper.SetPrefix("/prefix");
91 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
92 producerHelper.Install(nodes.Get(2)); // last node
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -070093
94 // The failure of the link connecting consumer and router will start from seconds 10.0 to 15.0
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080095 Simulator::Schedule(Seconds(10.0), ndn::LinkControlHelper::FailLink, nodes.Get(0), nodes.Get(1));
96 Simulator::Schedule(Seconds(15.0), ndn::LinkControlHelper::UpLink, nodes.Get(0), nodes.Get(1));
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -070097
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080098 Simulator::Stop(Seconds(20.0));
99
100 Simulator::Run();
101 Simulator::Destroy();
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -0700102
103 return 0;
104}
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800105
106} // namespace ns3
107
108int
109main(int argc, char* argv[])
110{
111 return ns3::main(argc, argv);
112}