blob: 725da662784bdb4b7335a2c5e9d1fce8d52201d9 [file] [log] [blame]
Alexander Afanasyevb5e77d82013-04-10 15:55:26 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2012-2013 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 */
20// ndn-simple-with-pit-count-stats.cc
21#include "ns3/core-module.h"
22#include "ns3/network-module.h"
23#include "ns3/point-to-point-module.h"
24#include "ns3/ndnSIM-module.h"
25
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 *
43 * To run scenario and see what is happening, use the following command:
44 *
45 * ./waf --run=ndn-simple-with-pit-count-stats
46 */
47
48void
49PeriodicStatsPrinter (Ptr<Node> node, Time next)
50{
51 Ptr<ndn::Pit> pit = node->GetObject<ndn::Pit> ();
52
53 std::cout << Simulator::Now ().ToDouble (Time::S) << "\t"
54 << node->GetId () << "\t"
55 << Names::FindName (node) << "\t"
56 << pit->GetSize () << "\n";
57
58 Simulator::Schedule (next, PeriodicStatsPrinter, node, next);
59}
60
61int
62main (int argc, char *argv[])
63{
64 // setting default parameters for PointToPoint links and channels
65 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
66 Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms"));
67 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
68
69 // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
70 CommandLine cmd;
71 cmd.Parse (argc, argv);
72
73 // Creating nodes
74 NodeContainer nodes;
75 nodes.Create (3);
76
77 // Connecting nodes using two links
78 PointToPointHelper p2p;
79 p2p.Install (nodes.Get (0), nodes.Get (1));
80 p2p.Install (nodes.Get (1), nodes.Get (2));
81
82 // see more http://www.nsnam.org/doxygen/classns3_1_1_names.html
83 Names::Add ("consumer", nodes.Get (0));
84 Names::Add ("router", nodes.Get (1));
85 Names::Add ("producer", nodes.Get (2));
86
87 // Install CCNx stack on all nodes
88 ndn::StackHelper ndnHelper;
89 ndnHelper.SetDefaultRoutes (true);
90 ndnHelper.SetPit ("ns3::ndn::pit::Persistent::AggregateStats");
91 ndnHelper.InstallAll ();
92
93 // set up periodic PIT stats printer on node 1
94 std::cout << "Time" << "\t"
95 << "NodeId" << "\t"
96 << "NodeName" << "\t"
Alexander Afanasyevb5e77d82013-04-10 15:55:26 -070097 << "NumberOfPitEntries" << "\n";
98 Simulator::Schedule (Seconds (1), PeriodicStatsPrinter, nodes.Get (0), Seconds (1));
99 Simulator::Schedule (Seconds (1), PeriodicStatsPrinter, nodes.Get (1), Seconds (1));
100 Simulator::Schedule (Seconds (1), PeriodicStatsPrinter, nodes.Get (2), Seconds (1));
101
102 // Installing applications
103
104 // Consumer
105 ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr");
106 // Consumer will request /prefix/0, /prefix/1, ...
107 consumerHelper.SetPrefix ("/prefix");
108 consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 10 interests a second
109 consumerHelper.Install (nodes.Get (0)); // first node
110
Alexander Afanasyevee762552013-07-10 22:29:22 -0700111 // // Producer
Alexander Afanasyevb5e77d82013-04-10 15:55:26 -0700112 ndn::AppHelper producerHelper ("ns3::ndn::Producer");
113 // Producer will reply to all requests starting with /prefix
114 producerHelper.SetPrefix ("/prefix");
115 producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
116 producerHelper.Install (nodes.Get (2)); // last node
117
118 Simulator::Stop (Seconds (20.0));
119
120 Simulator::Run ();
121 Simulator::Destroy ();
122
123 return 0;
124}