blob: 26c3f8e6760ff5a7e37c01682e25ffa7b1aebe0f [file] [log] [blame]
Alexander Afanasyev4ebe07e2013-03-26 13:27:55 -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-operation-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
26#include "ns3/ndnSIM/model/pit/ndn-pit-impl.h"
27#include "ns3/ndnSIM/utils/trie/persistent-policy.h"
28// #include "ns3/ndnSIM/utils/trie/random-policy.h"
29// #include "ns3/ndnSIM/utils/trie/lru-policy.h"
30#include "ns3/ndnSIM/utils/trie/multi-policy.h"
31#include "ns3/ndnSIM/utils/trie/aggregate-stats-policy.h"
32
33using namespace ns3;
34
35/**
36 * This scenario simulates a very simple network topology:
37 *
38 *
39 * +----------+ 1Mbps +--------+ 1Mbps +----------+
40 * | consumer | <------------> | router | <------------> | producer |
41 * +----------+ 10ms +--------+ 10ms +----------+
42 *
43 *
44 * Consumer requests data from producer with frequency 10 interests per second
45 * (interests contain constantly increasing sequence number).
46 *
47 * For every received interest, producer replies with a data packet, containing
48 * 1024 bytes of virtual payload.
49 *
50 * To run scenario and see what is happening, use the following command:
51 *
52 * ./waf --run=ndn-simple-with-pit-operation-stats
53 */
54
55typedef ndn::ndnSIM::multi_policy_traits< boost::mpl::vector2< ndn::ndnSIM::persistent_policy_traits,
56 ndn::ndnSIM::aggregate_stats_policy_traits > > PersistentWithCountsTraits;
57// typedef ndn::ndnSIM::multi_policy_traits< boost::mpl::vector2< ndn::ndnSIM::random_policy_traits,
58// ndn::ndnSIM::aggregate_stats_policy_traits > > RandomWithCountsTraits;
59// typedef ndn::ndnSIM::multi_policy_traits< boost::mpl::vector2< ndn::ndnSIM::lru_policy_traits,
60// ndn::ndnSIM::aggregate_stats_policy_traits > > LruWithCountsTraits;
61
62void
63PeriodicStatsPrinter (Ptr<Node> node, Time next)
64{
65 if (DynamicCast<ndn::pit::PitImpl<PersistentWithCountsTraits> > (node->GetObject<ndn::Pit> ()) == 0)
66 {
67 std::cerr << "Invalid PIT class, please correct the scenario" << std::endl;
68 return;
69 }
70
71 // "ns3::ndn::pit::Persistent::AggregateStats"
72 ndn::pit::PitImpl<PersistentWithCountsTraits>::super::policy_container &policy =
73 DynamicCast<ndn::pit::PitImpl<PersistentWithCountsTraits> > (node->GetObject<ndn::Pit> ())->GetPolicy ();
74
75 std::cout << Simulator::Now ().ToDouble (Time::S) << "\t"
76 << node->GetId () << "\t"
77 << policy.get<1> ().GetUpdates () << "\t"
78 << policy.get<1> ().GetInserts () << "\t"
79 << policy.get<1> ().GetLookups () << "\t"
80 << policy.get<1> ().GetErases () << "\n";
81
82 policy.get<1> ().ResetStats ();
83
84 Simulator::Schedule (next, PeriodicStatsPrinter, node, next);
85}
86
87int
88main (int argc, char *argv[])
89{
90 // setting default parameters for PointToPoint links and channels
91 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
92 Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms"));
93 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
94
95 // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
96 CommandLine cmd;
97 cmd.Parse (argc, argv);
98
99 // Creating nodes
100 NodeContainer nodes;
101 nodes.Create (3);
102
103 // Connecting nodes using two links
104 PointToPointHelper p2p;
105 p2p.Install (nodes.Get (0), nodes.Get (1));
106 p2p.Install (nodes.Get (1), nodes.Get (2));
107
108 // Install CCNx stack on all nodes
109 ndn::StackHelper ndnHelper;
110 ndnHelper.SetDefaultRoutes (true);
111 ndnHelper.SetPit ("ns3::ndn::pit::Persistent::AggregateStats");
112 ndnHelper.InstallAll ();
113
114 // set up periodic PIT stats printer on node 1
115 std::cout << "Time" << "\t"
116 << "NodeId" << "\t"
117 << "Updates" << "\t"
118 << "Inserts" << "\t"
119 << "Lookups" << "\t"
120 << "Erases" << "\n";
121 Simulator::Schedule (Seconds (1), PeriodicStatsPrinter, nodes.Get (1), Seconds (1));
122
123 // Installing applications
124
125 // Consumer
126 ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr");
127 // Consumer will request /prefix/0, /prefix/1, ...
128 consumerHelper.SetPrefix ("/prefix");
129 consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 10 interests a second
130 consumerHelper.Install (nodes.Get (0)); // first node
131
132 // Producer
133 ndn::AppHelper producerHelper ("ns3::ndn::Producer");
134 // Producer will reply to all requests starting with /prefix
135 producerHelper.SetPrefix ("/prefix");
136 producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
137 producerHelper.Install (nodes.Get (2)); // last node
138
139 Simulator::Stop (Seconds (20.0));
140
141 Simulator::Run ();
142 Simulator::Destroy ();
143
144 return 0;
145}