Alejandro Gil Torres | e0d2048 | 2016-03-06 23:56:19 -0600 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2017, 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" |
| 24 | #include "utility/name-helper.hpp" |
| 25 | |
| 26 | namespace nlsr { |
| 27 | |
| 28 | size_t |
| 29 | Statistics::get(PacketType type) const |
| 30 | { |
| 31 | std::map<PacketType,int>::const_iterator it = m_packetCounter.find(type); |
| 32 | if(it != m_packetCounter.end()) |
| 33 | { |
| 34 | return it->second; |
| 35 | } |
| 36 | else |
| 37 | { |
| 38 | return 0; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | void |
| 43 | Statistics::increment(PacketType type) |
| 44 | { |
| 45 | m_packetCounter[type]++; |
| 46 | } |
| 47 | |
| 48 | void |
| 49 | Statistics::resetAll() |
| 50 | { |
| 51 | for (auto&& it : m_packetCounter ) |
| 52 | { |
| 53 | it.second = 0; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | std::ostream& |
| 58 | operator<<(std::ostream& os, const Statistics& stats) |
| 59 | { |
| 60 | using PacketType = Statistics::PacketType; |
| 61 | |
| 62 | os << "++++++++++++++++++++++++++++++++++++++++\n" |
| 63 | << "+ +\n" |
| 64 | << "+ Statistics +\n" |
| 65 | << "+ +\n" |
| 66 | << "++++++++++++++++++++++++++++++++++++++++\n" |
| 67 | << "HELLO PROTOCOL\n" |
| 68 | << " Sent Hello Interests: " << stats.get(PacketType::SENT_HELLO_INTEREST) << "\n" |
| 69 | << " Sent Hello Data: " << stats.get(PacketType::SENT_HELLO_DATA) << "\n" |
| 70 | << "\n" |
| 71 | << " Received Hello Interests: " << stats.get(PacketType::RCV_HELLO_INTEREST) << "\n" |
| 72 | << " Received Hello Data: " << stats.get(PacketType::RCV_HELLO_DATA) << "\n" |
| 73 | << "\n" |
| 74 | << "LSDB\n" |
| 75 | << " Total Sent LSA Interests: " << stats.get(PacketType::SENT_LSA_INTEREST) << "\n" |
| 76 | << " Total Received LSA Interests: " << stats.get(PacketType::RCV_LSA_INTEREST) << "\n" |
| 77 | << "\n" |
| 78 | << " Total Sent LSA Data: " << stats.get(PacketType::SENT_LSA_DATA) << "\n" |
| 79 | << " Total Received LSA Data: " << stats.get(PacketType::RCV_LSA_DATA) << "\n" |
| 80 | << "\n" |
| 81 | << " Sent Adjacency LSA Interests: " << stats.get(PacketType::SENT_ADJ_LSA_INTEREST) << "\n" |
| 82 | << " Sent Coordinate LSA Interests: " << stats.get(PacketType::SENT_COORD_LSA_INTEREST) << "\n" |
| 83 | << " Sent Name LSA Interests: " << stats.get(PacketType::SENT_NAME_LSA_INTEREST) << "\n" |
| 84 | << "\n" |
| 85 | << " Received Adjacency LSA Interests: " << stats.get(PacketType::RCV_ADJ_LSA_INTEREST) << "\n" |
| 86 | << " Received Coordinate LSA Interests: " << stats.get(PacketType::RCV_COORD_LSA_INTEREST) << "\n" |
| 87 | << " Received Name LSA Interests: " << stats.get(PacketType::RCV_NAME_LSA_INTEREST) << "\n" |
| 88 | << "\n" |
| 89 | << " Sent Adjacency LSA Data: " << stats.get(PacketType::SENT_ADJ_LSA_DATA) << "\n" |
| 90 | << " Sent Coordinate LSA Data: " << stats.get(PacketType::SENT_COORD_LSA_DATA) << "\n" |
| 91 | << " Sent Name LSA Data: " << stats.get(PacketType::SENT_NAME_LSA_DATA) << "\n" |
| 92 | << "\n" |
| 93 | << " Received Adjacency LSA Data: " << stats.get(PacketType::RCV_ADJ_LSA_DATA) << "\n" |
| 94 | << " Received Coordinate LSA Data: " << stats.get(PacketType::RCV_COORD_LSA_DATA) << "\n" |
| 95 | << " Received Name LSA Data: " << stats.get(PacketType::RCV_NAME_LSA_DATA) << "\n" |
| 96 | << "++++++++++++++++++++++++++++++++++++++++\n"; |
| 97 | |
| 98 | return os; |
| 99 | } |
| 100 | |
| 101 | } // namespace nlsr |