Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2011-2015 Regents of the University of California. |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame^] | 5 | * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and |
| 6 | * contributors. |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame^] | 8 | * 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 Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 11 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame^] | 12 | * 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 Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 15 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame^] | 16 | * 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 Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 19 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 20 | #include "ndn-l3-rate-tracer.hpp" |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 21 | #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" |
| 28 | |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 29 | #include <fstream> |
| 30 | #include <boost/lexical_cast.hpp> |
| 31 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 32 | NS_LOG_COMPONENT_DEFINE("ndn.L3RateTracer"); |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 33 | |
| 34 | namespace ns3 { |
| 35 | namespace ndn { |
| 36 | |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 37 | static std::list<std::tuple<shared_ptr<std::ostream>, std::list<Ptr<L3RateTracer>>>> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 38 | g_tracers; |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 39 | |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 40 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 41 | L3RateTracer::Destroy() |
Alexander Afanasyev | db5f3b6 | 2013-08-09 17:42:12 -0700 | [diff] [blame] | 42 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 43 | g_tracers.clear(); |
Alexander Afanasyev | db5f3b6 | 2013-08-09 17:42:12 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 47 | L3RateTracer::InstallAll(const std::string& file, Time averagingPeriod /* = Seconds (0.5)*/) |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 48 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 49 | std::list<Ptr<L3RateTracer>> tracers; |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 50 | shared_ptr<std::ostream> outputStream; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 51 | if (file != "-") { |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 52 | shared_ptr<std::ofstream> os(new std::ofstream()); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 53 | os->open(file.c_str(), std::ios_base::out | std::ios_base::trunc); |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 54 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 55 | if (!os->is_open()) { |
| 56 | NS_LOG_ERROR("File " << file << " cannot be opened for writing. Tracing disabled"); |
| 57 | return; |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 58 | } |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 59 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 60 | outputStream = os; |
| 61 | } |
| 62 | else { |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 63 | outputStream = shared_ptr<std::ostream>(&std::cout, std::bind([]{})); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 64 | } |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 65 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 66 | for (NodeList::Iterator node = NodeList::Begin(); node != NodeList::End(); node++) { |
| 67 | Ptr<L3RateTracer> trace = Install(*node, outputStream, averagingPeriod); |
| 68 | tracers.push_back(trace); |
| 69 | } |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 70 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 71 | if (tracers.size() > 0) { |
| 72 | // *m_l3RateTrace << "# "; // not necessary for R's read.table |
| 73 | tracers.front()->PrintHeader(*outputStream); |
| 74 | *outputStream << "\n"; |
| 75 | } |
| 76 | |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 77 | g_tracers.push_back(std::make_tuple(outputStream, tracers)); |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 78 | } |
| 79 | |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 80 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 81 | L3RateTracer::Install(const NodeContainer& nodes, const std::string& file, |
| 82 | Time averagingPeriod /* = Seconds (0.5)*/) |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 83 | { |
| 84 | using namespace boost; |
| 85 | using namespace std; |
| 86 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 87 | std::list<Ptr<L3RateTracer>> tracers; |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 88 | shared_ptr<std::ostream> outputStream; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 89 | if (file != "-") { |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 90 | shared_ptr<std::ofstream> os(new std::ofstream()); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 91 | os->open(file.c_str(), std::ios_base::out | std::ios_base::trunc); |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 92 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 93 | if (!os->is_open()) { |
| 94 | NS_LOG_ERROR("File " << file << " cannot be opened for writing. Tracing disabled"); |
| 95 | return; |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 98 | outputStream = os; |
| 99 | } |
| 100 | else { |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 101 | outputStream = shared_ptr<std::ostream>(&std::cout, std::bind([]{})); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 102 | } |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 103 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 104 | for (NodeContainer::Iterator node = nodes.Begin(); node != nodes.End(); node++) { |
| 105 | Ptr<L3RateTracer> trace = Install(*node, outputStream, averagingPeriod); |
| 106 | tracers.push_back(trace); |
| 107 | } |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 108 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 109 | if (tracers.size() > 0) { |
| 110 | // *m_l3RateTrace << "# "; // not necessary for R's read.table |
| 111 | tracers.front()->PrintHeader(*outputStream); |
| 112 | *outputStream << "\n"; |
| 113 | } |
| 114 | |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 115 | g_tracers.push_back(std::make_tuple(outputStream, tracers)); |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 118 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 119 | L3RateTracer::Install(Ptr<Node> node, const std::string& file, |
| 120 | Time averagingPeriod /* = Seconds (0.5)*/) |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 121 | { |
| 122 | using namespace boost; |
| 123 | using namespace std; |
| 124 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 125 | std::list<Ptr<L3RateTracer>> tracers; |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 126 | shared_ptr<std::ostream> outputStream; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 127 | if (file != "-") { |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 128 | shared_ptr<std::ofstream> os(new std::ofstream()); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 129 | os->open(file.c_str(), std::ios_base::out | std::ios_base::trunc); |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 130 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 131 | if (!os->is_open()) { |
| 132 | NS_LOG_ERROR("File " << file << " cannot be opened for writing. Tracing disabled"); |
| 133 | return; |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 136 | outputStream = os; |
| 137 | } |
| 138 | else { |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 139 | outputStream = shared_ptr<std::ostream>(&std::cout, std::bind([]{})); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 140 | } |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 141 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 142 | Ptr<L3RateTracer> trace = Install(node, outputStream, averagingPeriod); |
| 143 | tracers.push_back(trace); |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 144 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 145 | if (tracers.size() > 0) { |
| 146 | // *m_l3RateTrace << "# "; // not necessary for R's read.table |
| 147 | tracers.front()->PrintHeader(*outputStream); |
| 148 | *outputStream << "\n"; |
| 149 | } |
| 150 | |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 151 | g_tracers.push_back(std::make_tuple(outputStream, tracers)); |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 154 | Ptr<L3RateTracer> |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 155 | L3RateTracer::Install(Ptr<Node> node, shared_ptr<std::ostream> outputStream, |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 156 | Time averagingPeriod /* = Seconds (0.5)*/) |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 157 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 158 | NS_LOG_DEBUG("Node: " << node->GetId()); |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 159 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 160 | Ptr<L3RateTracer> trace = Create<L3RateTracer>(outputStream, node); |
| 161 | trace->SetAveragingPeriod(averagingPeriod); |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 162 | |
| 163 | return trace; |
| 164 | } |
| 165 | |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 166 | L3RateTracer::L3RateTracer(shared_ptr<std::ostream> os, Ptr<Node> node) |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 167 | : L3Tracer(node) |
| 168 | , m_os(os) |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 169 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 170 | SetAveragingPeriod(Seconds(1.0)); |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 171 | } |
| 172 | |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 173 | L3RateTracer::L3RateTracer(shared_ptr<std::ostream> os, const std::string& node) |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 174 | : L3Tracer(node) |
| 175 | , m_os(os) |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 176 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 177 | SetAveragingPeriod(Seconds(1.0)); |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 178 | } |
| 179 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 180 | L3RateTracer::~L3RateTracer() |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 181 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 182 | m_printEvent.Cancel(); |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 186 | L3RateTracer::SetAveragingPeriod(const Time& period) |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 187 | { |
| 188 | m_period = period; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 189 | m_printEvent.Cancel(); |
| 190 | m_printEvent = Simulator::Schedule(m_period, &L3RateTracer::PeriodicPrinter, this); |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 194 | L3RateTracer::PeriodicPrinter() |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 195 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 196 | Print(*m_os); |
| 197 | Reset(); |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 198 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 199 | m_printEvent = Simulator::Schedule(m_period, &L3RateTracer::PeriodicPrinter, this); |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 203 | L3RateTracer::PrintHeader(std::ostream& os) const |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 204 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 205 | os << "Time" |
| 206 | << "\t" |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 207 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 208 | << "Node" |
| 209 | << "\t" |
| 210 | << "FaceId" |
| 211 | << "\t" |
| 212 | << "FaceDescr" |
| 213 | << "\t" |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 214 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 215 | << "Type" |
| 216 | << "\t" |
| 217 | << "Packets" |
| 218 | << "\t" |
| 219 | << "Kilobytes" |
| 220 | << "\t" |
| 221 | << "PacketRaw" |
| 222 | << "\t" |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 223 | << "KilobytesRaw"; |
| 224 | } |
| 225 | |
| 226 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 227 | L3RateTracer::Reset() |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 228 | { |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 229 | for (std::map<shared_ptr<const Face>, std::tuple<Stats, Stats, Stats, Stats>>::iterator stats = |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 230 | m_stats.begin(); |
| 231 | stats != m_stats.end(); stats++) { |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 232 | std::get<0>(stats->second).Reset(); |
| 233 | std::get<1>(stats->second).Reset(); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 234 | } |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | const double alpha = 0.8; |
| 238 | |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 239 | #define STATS(INDEX) std::get<INDEX>(stats->second) |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 240 | #define RATE(INDEX, fieldName) STATS(INDEX).fieldName / m_period.ToDouble(Time::S) |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 241 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 242 | #define PRINTER(printName, fieldName) \ |
| 243 | STATS(2).fieldName = \ |
| 244 | /*new value*/ alpha * RATE(0, fieldName) + /*old value*/ (1 - alpha) * STATS(2).fieldName; \ |
| 245 | STATS(3).fieldName = /*new value*/ alpha * RATE(1, fieldName) / 1024.0 \ |
| 246 | + /*old value*/ (1 - alpha) * STATS(3).fieldName; \ |
| 247 | \ |
| 248 | os << time.ToDouble(Time::S) << "\t" << m_node << "\t"; \ |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 249 | if (stats->first != nullptr) { \ |
| 250 | os << stats->first->getId() << "\t" << stats->first->getLocalUri() << "\t"; \ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 251 | } \ |
| 252 | else { \ |
| 253 | os << "-1\tall\t"; \ |
| 254 | } \ |
| 255 | os << printName << "\t" << STATS(2).fieldName << "\t" << STATS(3).fieldName << "\t" \ |
| 256 | << STATS(0).fieldName << "\t" << STATS(1).fieldName / 1024.0 << "\n"; |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 257 | |
| 258 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 259 | L3RateTracer::Print(std::ostream& os) const |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 260 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 261 | Time time = Simulator::Now(); |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 262 | |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 263 | for (std::map<shared_ptr<const Face>, std::tuple<Stats, Stats, Stats, Stats>>::iterator stats = |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 264 | m_stats.begin(); |
| 265 | stats != m_stats.end(); stats++) { |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 266 | if (stats->first == nullptr) |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 267 | continue; |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 268 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 269 | PRINTER("InInterests", m_inInterests); |
| 270 | PRINTER("OutInterests", m_outInterests); |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 271 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 272 | PRINTER("InData", m_inData); |
| 273 | PRINTER("OutData", m_outData); |
Alexander Afanasyev | bf93929 | 2013-07-15 10:10:01 -0700 | [diff] [blame] | 274 | |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 275 | // PRINTER("InSatisfiedInterests", m_satisfiedInterests); |
| 276 | // PRINTER("InTimedOutInterests", m_timedOutInterests); |
Alexander Afanasyev | bf93929 | 2013-07-15 10:10:01 -0700 | [diff] [blame] | 277 | |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 278 | // PRINTER("OutSatisfiedInterests", m_outSatisfiedInterests); |
| 279 | // PRINTER("OutTimedOutInterests", m_outTimedOutInterests); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 280 | } |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 281 | |
| 282 | { |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 283 | // std::map<shared_ptr<const Face>, boost::tuple<Stats, Stats, Stats, Stats>>::iterator stats = |
| 284 | // m_stats.find(shared_ptr<const Face>(0)); |
| 285 | // if (stats != m_stats.end()) { |
| 286 | // PRINTER("SatisfiedInterests", m_satisfiedInterests); |
| 287 | // PRINTER("TimedOutInterests", m_timedOutInterests); |
| 288 | // } |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 289 | } |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 290 | } |
| 291 | |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 292 | void |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 293 | L3RateTracer::OutInterests(const Interest& interest, const Face& face) |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 294 | { |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 295 | std::get<0>(m_stats[(const_cast<Face*>(&face))->shared_from_this()]).m_outInterests++; |
| 296 | if (interest.hasWire()) { |
| 297 | std::get<1>(m_stats[(const_cast<Face*>(&face))->shared_from_this()]).m_outInterests += |
| 298 | interest.wireEncode().size(); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 299 | } |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | void |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 303 | L3RateTracer::InInterests(const Interest& interest, const Face& face) |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 304 | { |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 305 | std::get<0>(m_stats[(const_cast<Face*>(&face))->shared_from_this()]).m_inInterests++; |
| 306 | if (interest.hasWire()) { |
| 307 | std::get<1>(m_stats[(const_cast<Face*>(&face))->shared_from_this()]).m_inInterests += |
| 308 | interest.wireEncode().size(); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 309 | } |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | void |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 313 | L3RateTracer::OutData(const Data& data, const Face& face) |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 314 | { |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 315 | std::get<0>(m_stats[(const_cast<Face*>(&face))->shared_from_this()]).m_outData++; |
| 316 | if (data.hasWire()) { |
| 317 | std::get<1>(m_stats[(const_cast<Face*>(&face))->shared_from_this()]).m_outData += |
| 318 | data.wireEncode().size(); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 319 | } |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | void |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 323 | L3RateTracer::InData(const Data& data, const Face& face) |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 324 | { |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 325 | std::get<0>(m_stats[(const_cast<Face*>(&face))->shared_from_this()]).m_inData++; |
| 326 | if (data.hasWire()) { |
| 327 | std::get<1>(m_stats[(const_cast<Face*>(&face))->shared_from_this()]).m_inData += |
| 328 | data.wireEncode().size(); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 329 | } |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 330 | } |
| 331 | |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 332 | // void |
| 333 | // L3RateTracer::SatisfiedInterests (Ptr<const pit::Entry> entry) |
| 334 | // { |
| 335 | // m_stats[0].std::get<0> ().m_satisfiedInterests ++; |
| 336 | // // no "size" stats |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 337 | |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 338 | // for (::nfd::pit::Entry::in_container::const_iterator i = entry->GetIncoming ().begin (); |
| 339 | // i != entry->GetIncoming ().end (); |
| 340 | // i++) |
| 341 | // { |
| 342 | // m_stats[i->m_face].std::get<0> ().m_satisfiedInterests ++; |
| 343 | // } |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 344 | |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 345 | // for (::nfd::pit::Entry::out_container::const_iterator i = entry->GetOutgoing ().begin (); |
| 346 | // i != entry->GetOutgoing ().end (); |
| 347 | // i++) |
| 348 | // { |
| 349 | // m_stats[i->m_face].std::get<0> ().m_outSatisfiedInterests ++; |
| 350 | // } |
| 351 | // } |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 352 | |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 353 | // void |
| 354 | // L3RateTracer::TimedOutInterests (Ptr<const pit::Entry> entry) |
| 355 | // { |
| 356 | // m_stats[0].std::get<0> ().m_timedOutInterests ++; |
| 357 | // // no "size" stats |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 358 | |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 359 | // for (pit::Entry::in_container::const_iterator i = entry->GetIncoming ().begin (); |
| 360 | // i != entry->GetIncoming ().end (); |
| 361 | // i++) |
| 362 | // { |
| 363 | // m_stats[i->m_face].std::get<0> ().m_timedOutInterests ++; |
| 364 | // } |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 365 | |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame] | 366 | // for (pit::Entry::out_container::const_iterator i = entry->GetOutgoing ().begin (); |
| 367 | // i != entry->GetOutgoing ().end (); |
| 368 | // i++) |
| 369 | // { |
| 370 | // m_stats[i->m_face].std::get<0> ().m_outTimedOutInterests ++; |
| 371 | // } |
| 372 | // } |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 373 | |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 374 | } // namespace ndn |
| 375 | } // namespace ns3 |