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