blob: c020a36e8e728da23e6fb715ccafc17a9a5fe52d [file] [log] [blame]
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2012 University of California, Los Angeles
4 *
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 *
18 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 * : Saran Tarnoi <saran.tarnoi@gmail.com>
20 */
21// ndn-simple-with-link-failure.cc
22#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
Alexander Afanasyev0c395372014-12-20 15:54:02 -080028#include "ns3/ndn-link-control-helper.hpp"
Alexander Afanasyev0fb80b92013-07-20 08:20:50 -070029
30using namespace ns3;
31
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 *
49 * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-simple
50 */
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"));
58 Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));
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}