Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Teng Liang | 6288486 | 2016-03-31 18:15:36 -0700 | [diff] [blame] | 3 | * Copyright (c) 2015-2016, 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 | * |
| 19 | * @author: Eric Newberry <enewberry@email.arizona.edu> |
| 20 | * @author: Jerald Paul Abraham <jeraldabraham@email.arizona.edu> |
Teng Liang | 6288486 | 2016-03-31 18:15:36 -0700 | [diff] [blame] | 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" |
| 28 | |
| 29 | #include "ping.hpp" |
| 30 | |
| 31 | namespace ndn { |
| 32 | namespace ping { |
| 33 | namespace client { |
| 34 | |
| 35 | /** |
| 36 | * @brief statistics data |
| 37 | */ |
| 38 | struct Statistics |
| 39 | { |
| 40 | Name prefix; //!< prefix pinged |
| 41 | int nSent; //!< number of pings sent |
| 42 | int nReceived; //!< number of pings received |
Teng Liang | 6288486 | 2016-03-31 18:15:36 -0700 | [diff] [blame] | 43 | int nNacked; //!< number of nacks received |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 44 | time::steady_clock::TimePoint pingStartTime; //!< time pings started |
| 45 | double minRtt; //!< minimum round trip time |
| 46 | double maxRtt; //!< maximum round trip time |
| 47 | double packetLossRate; //!< packet loss rate |
Teng Liang | 6288486 | 2016-03-31 18:15:36 -0700 | [diff] [blame] | 48 | double packetNackedRate; //!< packet nacked rate |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 49 | double sumRtt; //!< sum of round trip times |
| 50 | double avgRtt; //!< average round trip time |
| 51 | double stdDevRtt; //!< std dev of round trip time |
Eric Newberry | dce5a53 | 2015-05-06 10:46:52 -0700 | [diff] [blame] | 52 | |
| 53 | std::ostream& |
| 54 | printSummary(std::ostream& os) const; |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | /** |
Alexander Afanasyev | 1e7a7b2 | 2015-08-26 15:35:26 -0700 | [diff] [blame] | 58 | * @brief Statistics collector from ping client |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 59 | */ |
| 60 | class StatisticsCollector : noncopyable |
| 61 | { |
| 62 | public: |
| 63 | /** |
| 64 | * @param ping NDN ping client |
| 65 | * @param options ping client options |
| 66 | */ |
| 67 | StatisticsCollector(Ping& ping, const Options& options); |
| 68 | |
| 69 | /** |
Alexander Afanasyev | 1e7a7b2 | 2015-08-26 15:35:26 -0700 | [diff] [blame] | 70 | * @brief Compute ping statistics as structure |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 71 | */ |
| 72 | Statistics |
| 73 | computeStatistics(); |
| 74 | |
| 75 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 76 | /** |
Teng Liang | 6288486 | 2016-03-31 18:15:36 -0700 | [diff] [blame] | 77 | * @brief Called when a Data packet is received |
Alexander Afanasyev | 1e7a7b2 | 2015-08-26 15:35:26 -0700 | [diff] [blame] | 78 | * |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 79 | * @param rtt round trip time |
| 80 | */ |
| 81 | void |
Teng Liang | 6288486 | 2016-03-31 18:15:36 -0700 | [diff] [blame] | 82 | recordData(Rtt rtt); |
| 83 | |
| 84 | /** |
| 85 | * @brief Called when a Nack is received |
| 86 | */ |
| 87 | void |
| 88 | recordNack(); |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 89 | |
| 90 | /** |
Alexander Afanasyev | 1e7a7b2 | 2015-08-26 15:35:26 -0700 | [diff] [blame] | 91 | * @brief Called on ping timeout |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 92 | */ |
| 93 | void |
| 94 | recordTimeout(); |
| 95 | |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 96 | private: |
| 97 | Ping& m_ping; |
| 98 | const Options& m_options; |
| 99 | int m_nSent; |
| 100 | int m_nReceived; |
Teng Liang | 6288486 | 2016-03-31 18:15:36 -0700 | [diff] [blame] | 101 | int m_nNacked; |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 102 | time::steady_clock::TimePoint m_pingStartTime; |
| 103 | double m_minRtt; |
| 104 | double m_maxRtt; |
| 105 | double m_sumRtt; |
| 106 | double m_sumRttSquared; |
| 107 | }; |
| 108 | |
| 109 | std::ostream& |
| 110 | operator<<(std::ostream& os, const Statistics& statistics); |
| 111 | |
| 112 | } // namespace client |
| 113 | } // namespace ping |
| 114 | } // namespace ndn |
| 115 | |
| 116 | #endif // NDN_TOOLS_PING_CLIENT_STATISTICS_COLLECTOR_HPP |