blob: c217dbb706bdf4c84997ee09e14dd3f280db05ac [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -08003 * Copyright (c) 2011-2016 Regents of the University of California.
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -08004 *
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 Afanasyevc9d5c1a2012-11-21 18:00:26 -08007 *
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 Afanasyevc9d5c1a2012-11-21 18:00:26 -080011 *
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 Afanasyevc9d5c1a2012-11-21 18:00:26 -080015 *
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 **/
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080019
Alexander Afanasyev0c395372014-12-20 15:54:02 -080020#include "ndn-l3-rate-tracer.hpp"
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080021#include "ns3/node.h"
22#include "ns3/packet.h"
23#include "ns3/config.h"
24#include "ns3/callback.h"
25#include "ns3/simulator.h"
26#include "ns3/log.h"
27#include "ns3/node-list.h"
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -080028#include "ns3/ndnSIM/model/ndn-l3-protocol.hpp"
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080029
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -080030#include "daemon/table/pit-entry.hpp"
31
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080032#include <fstream>
33#include <boost/lexical_cast.hpp>
34
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080035NS_LOG_COMPONENT_DEFINE("ndn.L3RateTracer");
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080036
37namespace ns3 {
38namespace ndn {
39
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080040static std::list<std::tuple<shared_ptr<std::ostream>, std::list<Ptr<L3RateTracer>>>>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080041 g_tracers;
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070042
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070043void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080044L3RateTracer::Destroy()
Alexander Afanasyevdb5f3b62013-08-09 17:42:12 -070045{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080046 g_tracers.clear();
Alexander Afanasyevdb5f3b62013-08-09 17:42:12 -070047}
48
49void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080050L3RateTracer::InstallAll(const std::string& file, Time averagingPeriod /* = Seconds (0.5)*/)
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080051{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080052 std::list<Ptr<L3RateTracer>> tracers;
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080053 shared_ptr<std::ostream> outputStream;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080054 if (file != "-") {
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080055 shared_ptr<std::ofstream> os(new std::ofstream());
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080056 os->open(file.c_str(), std::ios_base::out | std::ios_base::trunc);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080057
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080058 if (!os->is_open()) {
59 NS_LOG_ERROR("File " << file << " cannot be opened for writing. Tracing disabled");
60 return;
Alexander Afanasyev5352af32013-07-15 09:51:28 -070061 }
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080062
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080063 outputStream = os;
64 }
65 else {
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080066 outputStream = shared_ptr<std::ostream>(&std::cout, std::bind([]{}));
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080067 }
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080068
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080069 for (NodeList::Iterator node = NodeList::Begin(); node != NodeList::End(); node++) {
70 Ptr<L3RateTracer> trace = Install(*node, outputStream, averagingPeriod);
71 tracers.push_back(trace);
72 }
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080073
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080074 if (tracers.size() > 0) {
75 // *m_l3RateTrace << "# "; // not necessary for R's read.table
76 tracers.front()->PrintHeader(*outputStream);
77 *outputStream << "\n";
78 }
79
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080080 g_tracers.push_back(std::make_tuple(outputStream, tracers));
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080081}
82
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070083void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080084L3RateTracer::Install(const NodeContainer& nodes, const std::string& file,
85 Time averagingPeriod /* = Seconds (0.5)*/)
Alexander Afanasyev5352af32013-07-15 09:51:28 -070086{
87 using namespace boost;
88 using namespace std;
89
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080090 std::list<Ptr<L3RateTracer>> tracers;
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080091 shared_ptr<std::ostream> outputStream;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080092 if (file != "-") {
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080093 shared_ptr<std::ofstream> os(new std::ofstream());
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080094 os->open(file.c_str(), std::ios_base::out | std::ios_base::trunc);
Alexander Afanasyev5352af32013-07-15 09:51:28 -070095
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080096 if (!os->is_open()) {
97 NS_LOG_ERROR("File " << file << " cannot be opened for writing. Tracing disabled");
98 return;
Alexander Afanasyev5352af32013-07-15 09:51:28 -070099 }
100
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800101 outputStream = os;
102 }
103 else {
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800104 outputStream = shared_ptr<std::ostream>(&std::cout, std::bind([]{}));
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800105 }
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700106
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800107 for (NodeContainer::Iterator node = nodes.Begin(); node != nodes.End(); node++) {
108 Ptr<L3RateTracer> trace = Install(*node, outputStream, averagingPeriod);
109 tracers.push_back(trace);
110 }
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700111
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800112 if (tracers.size() > 0) {
113 // *m_l3RateTrace << "# "; // not necessary for R's read.table
114 tracers.front()->PrintHeader(*outputStream);
115 *outputStream << "\n";
116 }
117
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800118 g_tracers.push_back(std::make_tuple(outputStream, tracers));
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700119}
120
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -0700121void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800122L3RateTracer::Install(Ptr<Node> node, const std::string& file,
123 Time averagingPeriod /* = Seconds (0.5)*/)
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700124{
125 using namespace boost;
126 using namespace std;
127
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800128 std::list<Ptr<L3RateTracer>> tracers;
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800129 shared_ptr<std::ostream> outputStream;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800130 if (file != "-") {
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800131 shared_ptr<std::ofstream> os(new std::ofstream());
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800132 os->open(file.c_str(), std::ios_base::out | std::ios_base::trunc);
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700133
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800134 if (!os->is_open()) {
135 NS_LOG_ERROR("File " << file << " cannot be opened for writing. Tracing disabled");
136 return;
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700137 }
138
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800139 outputStream = os;
140 }
141 else {
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800142 outputStream = shared_ptr<std::ostream>(&std::cout, std::bind([]{}));
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800143 }
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700144
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800145 Ptr<L3RateTracer> trace = Install(node, outputStream, averagingPeriod);
146 tracers.push_back(trace);
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700147
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800148 if (tracers.size() > 0) {
149 // *m_l3RateTrace << "# "; // not necessary for R's read.table
150 tracers.front()->PrintHeader(*outputStream);
151 *outputStream << "\n";
152 }
153
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800154 g_tracers.push_back(std::make_tuple(outputStream, tracers));
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700155}
156
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700157Ptr<L3RateTracer>
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800158L3RateTracer::Install(Ptr<Node> node, shared_ptr<std::ostream> outputStream,
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800159 Time averagingPeriod /* = Seconds (0.5)*/)
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700160{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800161 NS_LOG_DEBUG("Node: " << node->GetId());
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700162
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800163 Ptr<L3RateTracer> trace = Create<L3RateTracer>(outputStream, node);
164 trace->SetAveragingPeriod(averagingPeriod);
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700165
166 return trace;
167}
168
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800169L3RateTracer::L3RateTracer(shared_ptr<std::ostream> os, Ptr<Node> node)
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800170 : L3Tracer(node)
171 , m_os(os)
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800172{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800173 SetAveragingPeriod(Seconds(1.0));
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800174}
175
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800176L3RateTracer::L3RateTracer(shared_ptr<std::ostream> os, const std::string& node)
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800177 : L3Tracer(node)
178 , m_os(os)
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800179{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800180 SetAveragingPeriod(Seconds(1.0));
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800181}
182
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800183L3RateTracer::~L3RateTracer()
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800184{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800185 m_printEvent.Cancel();
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800186}
187
188void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800189L3RateTracer::SetAveragingPeriod(const Time& period)
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800190{
191 m_period = period;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800192 m_printEvent.Cancel();
193 m_printEvent = Simulator::Schedule(m_period, &L3RateTracer::PeriodicPrinter, this);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800194}
195
196void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800197L3RateTracer::PeriodicPrinter()
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800198{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800199 Print(*m_os);
200 Reset();
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700201
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800202 m_printEvent = Simulator::Schedule(m_period, &L3RateTracer::PeriodicPrinter, this);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800203}
204
205void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800206L3RateTracer::PrintHeader(std::ostream& os) const
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800207{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800208 os << "Time"
209 << "\t"
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800210
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800211 << "Node"
212 << "\t"
213 << "FaceId"
214 << "\t"
215 << "FaceDescr"
216 << "\t"
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800217
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800218 << "Type"
219 << "\t"
220 << "Packets"
221 << "\t"
222 << "Kilobytes"
223 << "\t"
224 << "PacketRaw"
225 << "\t"
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800226 << "KilobytesRaw";
227}
228
229void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800230L3RateTracer::Reset()
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800231{
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800232 for (auto& stats : m_stats) {
233 std::get<0>(stats.second).Reset();
234 std::get<1>(stats.second).Reset();
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800235 }
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800236}
237
238const double alpha = 0.8;
239
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800240#define STATS(INDEX) std::get<INDEX>(stats.second)
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800241#define RATE(INDEX, fieldName) STATS(INDEX).fieldName / m_period.ToDouble(Time::S)
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800242
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800243#define PRINTER(printName, fieldName) \
244 STATS(2).fieldName = \
245 /*new value*/ alpha * RATE(0, fieldName) + /*old value*/ (1 - alpha) * STATS(2).fieldName; \
246 STATS(3).fieldName = /*new value*/ alpha * RATE(1, fieldName) / 1024.0 \
247 + /*old value*/ (1 - alpha) * STATS(3).fieldName; \
248 \
249 os << time.ToDouble(Time::S) << "\t" << m_node << "\t"; \
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -0800250 if (stats.first != nfd::face::INVALID_FACEID) { \
251 os << stats.first << "\t"; \
252 NS_ASSERT(m_faceInfos.find(stats.first) != m_faceInfos.end()); \
253 os << m_faceInfos.find(stats.first)->second << "\t"; \
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800254 } \
255 else { \
256 os << "-1\tall\t"; \
257 } \
258 os << printName << "\t" << STATS(2).fieldName << "\t" << STATS(3).fieldName << "\t" \
259 << STATS(0).fieldName << "\t" << STATS(1).fieldName / 1024.0 << "\n";
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800260
261void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800262L3RateTracer::Print(std::ostream& os) const
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800263{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800264 Time time = Simulator::Now();
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700265
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800266 for (auto& stats : m_stats) {
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -0800267 if (stats.first == nfd::face::INVALID_FACEID)
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800268 continue;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800269
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800270 PRINTER("InInterests", m_inInterests);
271 PRINTER("OutInterests", m_outInterests);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800272
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800273 PRINTER("InData", m_inData);
274 PRINTER("OutData", m_outData);
Alexander Afanasyevbf939292013-07-15 10:10:01 -0700275
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -0800276 PRINTER("InNacks", m_inNack);
277 PRINTER("OutNacks", m_outNack);
278
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800279 PRINTER("InSatisfiedInterests", m_satisfiedInterests);
280 PRINTER("InTimedOutInterests", m_timedOutInterests);
Alexander Afanasyevbf939292013-07-15 10:10:01 -0700281
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800282 PRINTER("OutSatisfiedInterests", m_outSatisfiedInterests);
283 PRINTER("OutTimedOutInterests", m_outTimedOutInterests);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800284 }
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700285
286 {
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -0800287 auto i = m_stats.find(nfd::face::INVALID_FACEID);
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800288 if (i != m_stats.end()) {
289 auto& stats = *i;
290 PRINTER("SatisfiedInterests", m_satisfiedInterests);
291 PRINTER("TimedOutInterests", m_timedOutInterests);
292 }
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700293 }
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800294}
295
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800296void
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800297L3RateTracer::OutInterests(const Interest& interest, const Face& face)
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800298{
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -0800299 AddInfo(face);
300 std::get<0>(m_stats[face.getId()]).m_outInterests++;
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800301 if (interest.hasWire()) {
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -0800302 std::get<1>(m_stats[face.getId()]).m_outInterests +=
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800303 interest.wireEncode().size();
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800304 }
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800305}
306
307void
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800308L3RateTracer::InInterests(const Interest& interest, const Face& face)
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800309{
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -0800310 AddInfo(face);
311 std::get<0>(m_stats[face.getId()]).m_inInterests++;
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800312 if (interest.hasWire()) {
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -0800313 std::get<1>(m_stats[face.getId()]).m_inInterests +=
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800314 interest.wireEncode().size();
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800315 }
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800316}
317
318void
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800319L3RateTracer::OutData(const Data& data, const Face& face)
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800320{
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -0800321 AddInfo(face);
322 std::get<0>(m_stats[face.getId()]).m_outData++;
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800323 if (data.hasWire()) {
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -0800324 std::get<1>(m_stats[face.getId()]).m_outData +=
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800325 data.wireEncode().size();
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800326 }
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800327}
328
329void
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800330L3RateTracer::InData(const Data& data, const Face& face)
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800331{
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -0800332 AddInfo(face);
333 std::get<0>(m_stats[face.getId()]).m_inData++;
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800334 if (data.hasWire()) {
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -0800335 std::get<1>(m_stats[face.getId()]).m_inData +=
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800336 data.wireEncode().size();
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800337 }
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800338}
339
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800340void
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -0800341L3RateTracer::OutNack(const lp::Nack& nack, const Face& face)
342{
343 AddInfo(face);
344 std::get<0>(m_stats[face.getId()]).m_outNack++;
345 if (nack.getInterest().hasWire()) {
346 std::get<1>(m_stats[face.getId()]).m_outNack +=
347 nack.getInterest().wireEncode().size();
348 }
349}
350
351void
352L3RateTracer::InNack(const lp::Nack& nack, const Face& face)
353{
354 AddInfo(face);
355 std::get<0>(m_stats[face.getId()]).m_inNack++;
356 if (nack.getInterest().hasWire()) {
357 std::get<1>(m_stats[face.getId()]).m_inNack +=
358 nack.getInterest().wireEncode().size();
359 }
360}
361
362void
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800363L3RateTracer::SatisfiedInterests(const nfd::pit::Entry& entry, const Face&, const Data&)
364{
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -0800365 std::get<0>(m_stats[nfd::face::INVALID_FACEID]).m_satisfiedInterests++;
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800366 // no "size" stats
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800367
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800368 for (const auto& in : entry.getInRecords()) {
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -0800369 AddInfo(in.getFace());
370 std::get<0>(m_stats[(in.getFace()).getId()]).m_satisfiedInterests ++;
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800371 }
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800372
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800373 for (const auto& out : entry.getOutRecords()) {
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -0800374 AddInfo(out.getFace());
375 std::get<0>(m_stats[(out.getFace()).getId()]).m_outSatisfiedInterests ++;
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800376 }
377}
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800378
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800379void
380L3RateTracer::TimedOutInterests(const nfd::pit::Entry& entry)
381{
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -0800382 std::get<0>(m_stats[nfd::face::INVALID_FACEID]).m_timedOutInterests++;
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800383 // no "size" stats
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800384
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800385 for (const auto& in : entry.getInRecords()) {
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -0800386 AddInfo(in.getFace());
387 std::get<0>(m_stats[(in.getFace()).getId()]).m_timedOutInterests++;
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800388 }
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800389
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800390 for (const auto& out : entry.getOutRecords()) {
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -0800391 AddInfo(out.getFace());
392 std::get<0>(m_stats[(out.getFace()).getId()]).m_outTimedOutInterests++;
393 }
394}
395
396void
397L3RateTracer::AddInfo(const Face& face)
398{
399 if (m_faceInfos.find(face.getId()) == m_faceInfos.end()) {
400 m_faceInfos.insert(make_pair(face.getId(), boost::lexical_cast<std::string>(face.getLocalUri())));
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800401 }
402}
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700403
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800404} // namespace ndn
405} // namespace ns3