blob: b7755e8603ff9031f3299dc782b219f21f58c9d3 [file] [log] [blame]
Alexander Afanasyevf04d4512012-02-14 18:42:47 -08001/* -*- 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 */
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080020// ndn-simple.cc
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080021#include "ns3/core-module.h"
22#include "ns3/network-module.h"
23#include "ns3/point-to-point-module.h"
Alexander Afanasyev4885eea2012-06-01 12:28:15 -070024#include "ns3/ndnSIM-module.h"
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080025
26using namespace ns3;
27
28/**
29 * This scenario simulates a very simple network topology:
30 *
31 *
32 * +----------+ 1Mbps +--------+ 1Mbps +----------+
33 * | consumer | <------------> | router | <------------> | producer |
34 * +----------+ 10ms +--------+ 10ms +----------+
35 *
36 *
37 * Consumer requests data from producer with frequency 10 interests per second
38 * (interests contain constantly increasing sequence number).
39 *
40 * For every received interest, producer replies with a data packet, containing
41 * 1024 bytes of virtual payload.
42 *
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080043 * To run scenario and see what is happening, use the following command:
44 *
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080045 * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-simple
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080046 */
47
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080048int
49main(int argc, char* argv[])
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080050{
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080051 // setting default parameters for PointToPoint links and channels
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080052 Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps"));
53 Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
54 Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080055
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080056 // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080057 CommandLine cmd;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080058 cmd.Parse(argc, argv);
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080059
60 // Creating nodes
61 NodeContainer nodes;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080062 nodes.Create(3);
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080063
64 // Connecting nodes using two links
65 PointToPointHelper p2p;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066 p2p.Install(nodes.Get(0), nodes.Get(1));
67 p2p.Install(nodes.Get(1), nodes.Get(2));
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080068
Alexander Afanasyev9fb2e3d2013-03-30 21:11:07 -070069 // Install NDN stack on all nodes
70 ndn::StackHelper ndnHelper;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080071 ndnHelper.SetDefaultRoutes(true);
72 ndnHelper.InstallAll();
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080073
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080074 // Installing applications
75
76 // Consumer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080077 ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080078 // Consumer will request /prefix/0, /prefix/1, ...
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080079 consumerHelper.SetPrefix("/prefix");
80 consumerHelper.SetAttribute("Frequency", StringValue("10")); // 10 interests a second
81 consumerHelper.Install(nodes.Get(0)); // first node
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080082
83 // Producer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080084 ndn::AppHelper producerHelper("ns3::ndn::Producer");
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080085 // Producer will reply to all requests starting with /prefix
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080086 producerHelper.SetPrefix("/prefix");
87 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
88 producerHelper.Install(nodes.Get(2)); // last node
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080089
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080090 Simulator::Stop(Seconds(20.0));
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080091
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080092 Simulator::Run();
93 Simulator::Destroy();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080094
Alexander Afanasyevf04d4512012-02-14 18:42:47 -080095 return 0;
96}