blob: 9622717e0b1b2ba89c9c07d873a9f358a95bccc4 [file] [log] [blame]
Eric Newberry4164b8e2015-04-23 17:29:18 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventof8d9a532021-07-03 16:04:12 -04002/*
3 * Copyright (c) 2015-2021, Arizona Board of Regents.
Eric Newberry4164b8e2015-04-23 17:29:18 -07004 *
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 Pesaventof8d9a532021-07-03 16:04:12 -040019 * @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 Newberry4164b8e2015-04-23 17:29:18 -070022 */
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
31namespace ndn {
32namespace ping {
33namespace client {
34
35/**
36 * @brief statistics data
37 */
38struct Statistics
39{
40 Name prefix; //!< prefix pinged
41 int nSent; //!< number of pings sent
42 int nReceived; //!< number of pings received
Teng Liang62884862016-03-31 18:15:36 -070043 int nNacked; //!< number of nacks received
Davide Pesaventof8d9a532021-07-03 16:04:12 -040044 time::steady_clock::time_point pingStartTime; //!< time pings started
Eric Newberry4164b8e2015-04-23 17:29:18 -070045 double minRtt; //!< minimum round trip time
46 double maxRtt; //!< maximum round trip time
47 double packetLossRate; //!< packet loss rate
Teng Liang62884862016-03-31 18:15:36 -070048 double packetNackedRate; //!< packet nacked rate
Eric Newberry4164b8e2015-04-23 17:29:18 -070049 double sumRtt; //!< sum of round trip times
50 double avgRtt; //!< average round trip time
51 double stdDevRtt; //!< std dev of round trip time
Eric Newberrydce5a532015-05-06 10:46:52 -070052
53 std::ostream&
54 printSummary(std::ostream& os) const;
Eric Newberry4164b8e2015-04-23 17:29:18 -070055};
56
57/**
Alexander Afanasyev1e7a7b22015-08-26 15:35:26 -070058 * @brief Statistics collector from ping client
Eric Newberry4164b8e2015-04-23 17:29:18 -070059 */
60class StatisticsCollector : noncopyable
61{
62public:
63 /**
64 * @param ping NDN ping client
65 * @param options ping client options
66 */
67 StatisticsCollector(Ping& ping, const Options& options);
68
69 /**
Davide Pesaventof8d9a532021-07-03 16:04:12 -040070 * @brief Compute and return ping statistics as structure
Junxiao Shi2713a3b2015-06-22 16:19:05 -070071 */
72 Statistics
Davide Pesaventof8d9a532021-07-03 16:04:12 -040073 computeStatistics() const;
Junxiao Shi2713a3b2015-06-22 16:19:05 -070074
75PUBLIC_WITH_TESTS_ELSE_PRIVATE:
76 /**
Teng Liang62884862016-03-31 18:15:36 -070077 * @brief Called when a Data packet is received
Eric Newberry4164b8e2015-04-23 17:29:18 -070078 */
79 void
Teng Liang62884862016-03-31 18:15:36 -070080 recordData(Rtt rtt);
81
82 /**
83 * @brief Called when a Nack is received
84 */
85 void
86 recordNack();
Eric Newberry4164b8e2015-04-23 17:29:18 -070087
88 /**
Alexander Afanasyev1e7a7b22015-08-26 15:35:26 -070089 * @brief Called on ping timeout
Eric Newberry4164b8e2015-04-23 17:29:18 -070090 */
91 void
92 recordTimeout();
93
Eric Newberry4164b8e2015-04-23 17:29:18 -070094private:
95 Ping& m_ping;
96 const Options& m_options;
97 int m_nSent;
98 int m_nReceived;
Teng Liang62884862016-03-31 18:15:36 -070099 int m_nNacked;
Davide Pesaventof8d9a532021-07-03 16:04:12 -0400100 time::steady_clock::time_point m_pingStartTime;
Eric Newberry4164b8e2015-04-23 17:29:18 -0700101 double m_minRtt;
102 double m_maxRtt;
103 double m_sumRtt;
104 double m_sumRttSquared;
105};
106
107std::ostream&
108operator<<(std::ostream& os, const Statistics& statistics);
109
110} // namespace client
111} // namespace ping
112} // namespace ndn
113
114#endif // NDN_TOOLS_PING_CLIENT_STATISTICS_COLLECTOR_HPP