Loading...
Searching...
No Matches
statistics.cpp
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2020, The University of Memphis,
4 * Regents of the University of California,
5 * Arizona Board of Regents.
6 *
7 * This file is part of NLSR (Named-data Link State Routing).
8 * See AUTHORS.md for complete list of NLSR authors and contributors.
9 *
10 * NLSR is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
20 **/
21
22#include "statistics.hpp"
23#include "nlsr.hpp"
25
26namespace nlsr {
27
28size_t
30{
31 auto it = m_packetCounter.find(type);
32 if (it != m_packetCounter.end()) {
33 return it->second;
34 }
35 else {
36 return 0;
37 }
38}
39
40void
42{
43 m_packetCounter[type]++;
44}
45
46void
48{
49 for (auto& it : m_packetCounter) {
50 it.second = 0;
51 }
52}
53
54std::ostream&
55operator<<(std::ostream& os, const Statistics& stats)
56{
57 using PacketType = Statistics::PacketType;
58
59 os << "++++++++++++++++++++++++++++++++++++++++\n"
60 << "+ +\n"
61 << "+ Statistics +\n"
62 << "+ +\n"
63 << "++++++++++++++++++++++++++++++++++++++++\n"
64 << "HELLO PROTOCOL\n"
65 << " Sent Hello Interests: " << stats.get(PacketType::SENT_HELLO_INTEREST) << "\n"
66 << " Sent Hello Data: " << stats.get(PacketType::SENT_HELLO_DATA) << "\n"
67 << "\n"
68 << " Received Hello Interests: " << stats.get(PacketType::RCV_HELLO_INTEREST) << "\n"
69 << " Received Hello Data: " << stats.get(PacketType::RCV_HELLO_DATA) << "\n"
70 << "\n"
71 << "LSDB\n"
72 << " Total Sent LSA Interests: " << stats.get(PacketType::SENT_LSA_INTEREST) << "\n"
73 << " Total Received LSA Interests: " << stats.get(PacketType::RCV_LSA_INTEREST) << "\n"
74 << "\n"
75 << " Total Sent LSA Data: " << stats.get(PacketType::SENT_LSA_DATA) << "\n"
76 << " Total Received LSA Data: " << stats.get(PacketType::RCV_LSA_DATA) << "\n"
77 << "\n"
78 << " Sent Adjacency LSA Interests: " << stats.get(PacketType::SENT_ADJ_LSA_INTEREST) << "\n"
79 << " Sent Coordinate LSA Interests: " << stats.get(PacketType::SENT_COORD_LSA_INTEREST) << "\n"
80 << " Sent Name LSA Interests: " << stats.get(PacketType::SENT_NAME_LSA_INTEREST) << "\n"
81 << "\n"
82 << " Received Adjacency LSA Interests: " << stats.get(PacketType::RCV_ADJ_LSA_INTEREST) << "\n"
83 << " Received Coordinate LSA Interests: " << stats.get(PacketType::RCV_COORD_LSA_INTEREST) << "\n"
84 << " Received Name LSA Interests: " << stats.get(PacketType::RCV_NAME_LSA_INTEREST) << "\n"
85 << "\n"
86 << " Sent Adjacency LSA Data: " << stats.get(PacketType::SENT_ADJ_LSA_DATA) << "\n"
87 << " Sent Coordinate LSA Data: " << stats.get(PacketType::SENT_COORD_LSA_DATA) << "\n"
88 << " Sent Name LSA Data: " << stats.get(PacketType::SENT_NAME_LSA_DATA) << "\n"
89 << "\n"
90 << " Received Adjacency LSA Data: " << stats.get(PacketType::RCV_ADJ_LSA_DATA) << "\n"
91 << " Received Coordinate LSA Data: " << stats.get(PacketType::RCV_COORD_LSA_DATA) << "\n"
92 << " Received Name LSA Data: " << stats.get(PacketType::RCV_NAME_LSA_DATA) << "\n"
93 << "++++++++++++++++++++++++++++++++++++++++\n";
94
95 return os;
96}
97
98} // namespace nlsr
void increment(PacketType)
size_t get(PacketType) const
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California.
std::ostream & operator<<(std::ostream &os, const Adjacent &adjacent)
Definition adjacent.cpp:176