Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | e4edb39 | 2020-12-06 14:05:45 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2020, The University of Memphis, |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 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" |
| 24 | #include "utility/name-helper.hpp" |
| 25 | |
| 26 | namespace nlsr { |
| 27 | |
| 28 | size_t |
| 29 | Statistics::get(PacketType type) const |
| 30 | { |
Davide Pesavento | e4edb39 | 2020-12-06 14:05:45 -0500 | [diff] [blame] | 31 | auto it = m_packetCounter.find(type); |
| 32 | if (it != m_packetCounter.end()) { |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 33 | return it->second; |
| 34 | } |
Davide Pesavento | e4edb39 | 2020-12-06 14:05:45 -0500 | [diff] [blame] | 35 | else { |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 36 | return 0; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | void |
| 41 | Statistics::increment(PacketType type) |
| 42 | { |
| 43 | m_packetCounter[type]++; |
| 44 | } |
| 45 | |
| 46 | void |
| 47 | Statistics::resetAll() |
| 48 | { |
Davide Pesavento | e4edb39 | 2020-12-06 14:05:45 -0500 | [diff] [blame] | 49 | for (auto& it : m_packetCounter) { |
Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame] | 50 | it.second = 0; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | std::ostream& |
| 55 | operator<<(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 |