blob: 2ced8203f96f51e67938f903a9872e2db2338c0d [file] [log] [blame]
Eric Newberry4164b8e2015-04-23 17:29:18 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2015, Arizona Board of Regents.
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>
21 */
22
23#ifndef NDN_TOOLS_PING_CLIENT_STATISTICS_COLLECTOR_HPP
24#define NDN_TOOLS_PING_CLIENT_STATISTICS_COLLECTOR_HPP
25
26#include "core/common.hpp"
27
28#include "ping.hpp"
29
30namespace ndn {
31namespace ping {
32namespace client {
33
34/**
35 * @brief statistics data
36 */
37struct Statistics
38{
39 Name prefix; //!< prefix pinged
40 int nSent; //!< number of pings sent
41 int nReceived; //!< number of pings received
42 time::steady_clock::TimePoint pingStartTime; //!< time pings started
43 double minRtt; //!< minimum round trip time
44 double maxRtt; //!< maximum round trip time
45 double packetLossRate; //!< packet loss rate
46 double sumRtt; //!< sum of round trip times
47 double avgRtt; //!< average round trip time
48 double stdDevRtt; //!< std dev of round trip time
Eric Newberrydce5a532015-05-06 10:46:52 -070049
50 std::ostream&
51 printSummary(std::ostream& os) const;
Eric Newberry4164b8e2015-04-23 17:29:18 -070052};
53
54/**
Alexander Afanasyev1e7a7b22015-08-26 15:35:26 -070055 * @brief Statistics collector from ping client
Eric Newberry4164b8e2015-04-23 17:29:18 -070056 */
57class StatisticsCollector : noncopyable
58{
59public:
60 /**
61 * @param ping NDN ping client
62 * @param options ping client options
63 */
64 StatisticsCollector(Ping& ping, const Options& options);
65
66 /**
Alexander Afanasyev1e7a7b22015-08-26 15:35:26 -070067 * @brief Compute ping statistics as structure
Junxiao Shi2713a3b2015-06-22 16:19:05 -070068 */
69 Statistics
70 computeStatistics();
71
72PUBLIC_WITH_TESTS_ELSE_PRIVATE:
73 /**
Alexander Afanasyev1e7a7b22015-08-26 15:35:26 -070074 * @brief Called on ping response received
75 *
Eric Newberry4164b8e2015-04-23 17:29:18 -070076 * @param rtt round trip time
77 */
78 void
79 recordResponse(Rtt rtt);
80
81 /**
Alexander Afanasyev1e7a7b22015-08-26 15:35:26 -070082 * @brief Called on ping timeout
Eric Newberry4164b8e2015-04-23 17:29:18 -070083 */
84 void
85 recordTimeout();
86
Eric Newberry4164b8e2015-04-23 17:29:18 -070087private:
88 Ping& m_ping;
89 const Options& m_options;
90 int m_nSent;
91 int m_nReceived;
92 time::steady_clock::TimePoint m_pingStartTime;
93 double m_minRtt;
94 double m_maxRtt;
95 double m_sumRtt;
96 double m_sumRttSquared;
97};
98
99std::ostream&
100operator<<(std::ostream& os, const Statistics& statistics);
101
102} // namespace client
103} // namespace ping
104} // namespace ndn
105
106#endif // NDN_TOOLS_PING_CLIENT_STATISTICS_COLLECTOR_HPP