Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | f8d9a53 | 2021-07-03 16:04:12 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 5748e82 | 2024-01-26 18:40:22 -0500 | [diff] [blame] | 3 | * Copyright (c) 2015-2024, Arizona Board of Regents. |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-tools (Named Data Networking Essential Tools). |
| 6 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. |
| 7 | * |
| 8 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
Davide Pesavento | f8d9a53 | 2021-07-03 16:04:12 -0400 | [diff] [blame] | 19 | * @author Eric Newberry <enewberry@email.arizona.edu> |
| 20 | * @author Jerald Paul Abraham <jeraldabraham@email.arizona.edu> |
| 21 | * @author Teng Liang <philoliang@email.arizona.edu> |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | #ifndef NDN_TOOLS_PING_CLIENT_STATISTICS_COLLECTOR_HPP |
| 25 | #define NDN_TOOLS_PING_CLIENT_STATISTICS_COLLECTOR_HPP |
| 26 | |
| 27 | #include "core/common.hpp" |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 28 | #include "ping.hpp" |
| 29 | |
Davide Pesavento | 5748e82 | 2024-01-26 18:40:22 -0500 | [diff] [blame] | 30 | #include <limits> |
| 31 | |
Davide Pesavento | b3570c6 | 2022-02-19 19:19:00 -0500 | [diff] [blame] | 32 | namespace ndn::ping::client { |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 33 | |
Davide Pesavento | c8625bb | 2024-02-12 15:06:31 -0500 | [diff] [blame] | 34 | class Statistics |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 35 | { |
Davide Pesavento | c8625bb | 2024-02-12 15:06:31 -0500 | [diff] [blame] | 36 | public: |
| 37 | void |
| 38 | printSummary(std::ostream& os) const; |
| 39 | |
| 40 | void |
| 41 | printFull(std::ostream& os) const; |
| 42 | |
| 43 | public: |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 44 | Name prefix; //!< prefix pinged |
| 45 | int nSent; //!< number of pings sent |
| 46 | int nReceived; //!< number of pings received |
Teng Liang | 6288486 | 2016-03-31 18:15:36 -0700 | [diff] [blame] | 47 | int nNacked; //!< number of nacks received |
Davide Pesavento | f8d9a53 | 2021-07-03 16:04:12 -0400 | [diff] [blame] | 48 | time::steady_clock::time_point pingStartTime; //!< time pings started |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 49 | double minRtt; //!< minimum round trip time |
| 50 | double maxRtt; //!< maximum round trip time |
| 51 | double packetLossRate; //!< packet loss rate |
Teng Liang | 6288486 | 2016-03-31 18:15:36 -0700 | [diff] [blame] | 52 | double packetNackedRate; //!< packet nacked rate |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 53 | double sumRtt; //!< sum of round trip times |
| 54 | double avgRtt; //!< average round trip time |
| 55 | double stdDevRtt; //!< std dev of round trip time |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | /** |
Davide Pesavento | c8625bb | 2024-02-12 15:06:31 -0500 | [diff] [blame] | 59 | * @brief Statistics collector from ping client. |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 60 | */ |
| 61 | class StatisticsCollector : noncopyable |
| 62 | { |
| 63 | public: |
| 64 | /** |
| 65 | * @param ping NDN ping client |
| 66 | * @param options ping client options |
| 67 | */ |
| 68 | StatisticsCollector(Ping& ping, const Options& options); |
| 69 | |
| 70 | /** |
Davide Pesavento | f8d9a53 | 2021-07-03 16:04:12 -0400 | [diff] [blame] | 71 | * @brief Compute and return ping statistics as structure |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 72 | */ |
Davide Pesavento | b3570c6 | 2022-02-19 19:19:00 -0500 | [diff] [blame] | 73 | [[nodiscard]] Statistics |
Davide Pesavento | f8d9a53 | 2021-07-03 16:04:12 -0400 | [diff] [blame] | 74 | computeStatistics() const; |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 75 | |
| 76 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 77 | /** |
Teng Liang | 6288486 | 2016-03-31 18:15:36 -0700 | [diff] [blame] | 78 | * @brief Called when a Data packet is received |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 79 | */ |
| 80 | void |
Teng Liang | 6288486 | 2016-03-31 18:15:36 -0700 | [diff] [blame] | 81 | recordData(Rtt rtt); |
| 82 | |
| 83 | /** |
| 84 | * @brief Called when a Nack is received |
| 85 | */ |
| 86 | void |
| 87 | recordNack(); |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 88 | |
| 89 | /** |
Alexander Afanasyev | 1e7a7b2 | 2015-08-26 15:35:26 -0700 | [diff] [blame] | 90 | * @brief Called on ping timeout |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 91 | */ |
| 92 | void |
| 93 | recordTimeout(); |
| 94 | |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 95 | private: |
| 96 | Ping& m_ping; |
| 97 | const Options& m_options; |
Davide Pesavento | b3570c6 | 2022-02-19 19:19:00 -0500 | [diff] [blame] | 98 | time::steady_clock::time_point m_pingStartTime = time::steady_clock::now(); |
| 99 | int m_nSent = 0; |
| 100 | int m_nReceived = 0; |
| 101 | int m_nNacked = 0; |
| 102 | double m_minRtt = std::numeric_limits<double>::max(); |
| 103 | double m_maxRtt = 0.0; |
| 104 | double m_sumRtt = 0.0; |
| 105 | double m_sumRttSquared = 0.0; |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 106 | }; |
| 107 | |
Davide Pesavento | b3570c6 | 2022-02-19 19:19:00 -0500 | [diff] [blame] | 108 | } // namespace ndn::ping::client |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 109 | |
| 110 | #endif // NDN_TOOLS_PING_CLIENT_STATISTICS_COLLECTOR_HPP |