blob: 2eb6cbe2043f488d63de03a70d57f63f45bf66b0 [file] [log] [blame]
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoe4edb392020-12-06 14:05:45 -05002/*
3 * Copyright (c) 2014-2020, The University of Memphis,
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -06004 * 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"
24#include "utility/name-helper.hpp"
25
26namespace nlsr {
27
28size_t
29Statistics::get(PacketType type) const
30{
Davide Pesaventoe4edb392020-12-06 14:05:45 -050031 auto it = m_packetCounter.find(type);
32 if (it != m_packetCounter.end()) {
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -060033 return it->second;
34 }
Davide Pesaventoe4edb392020-12-06 14:05:45 -050035 else {
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -060036 return 0;
37 }
38}
39
40void
41Statistics::increment(PacketType type)
42{
43 m_packetCounter[type]++;
44}
45
46void
47Statistics::resetAll()
48{
Davide Pesaventoe4edb392020-12-06 14:05:45 -050049 for (auto& it : m_packetCounter) {
Alejandro Gil Torrese0d20482016-03-06 23:56:19 -060050 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