blob: 9622717e0b1b2ba89c9c07d873a9f358a95bccc4 [file] [log] [blame]
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2015-2021, Arizona Board of Regents.
*
* This file is part of ndn-tools (Named Data Networking Essential Tools).
* See AUTHORS.md for complete list of ndn-tools authors and contributors.
*
* ndn-tools is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*
* @author Eric Newberry <enewberry@email.arizona.edu>
* @author Jerald Paul Abraham <jeraldabraham@email.arizona.edu>
* @author Teng Liang <philoliang@email.arizona.edu>
*/
#ifndef NDN_TOOLS_PING_CLIENT_STATISTICS_COLLECTOR_HPP
#define NDN_TOOLS_PING_CLIENT_STATISTICS_COLLECTOR_HPP
#include "core/common.hpp"
#include "ping.hpp"
namespace ndn {
namespace ping {
namespace client {
/**
* @brief statistics data
*/
struct Statistics
{
Name prefix; //!< prefix pinged
int nSent; //!< number of pings sent
int nReceived; //!< number of pings received
int nNacked; //!< number of nacks received
time::steady_clock::time_point pingStartTime; //!< time pings started
double minRtt; //!< minimum round trip time
double maxRtt; //!< maximum round trip time
double packetLossRate; //!< packet loss rate
double packetNackedRate; //!< packet nacked rate
double sumRtt; //!< sum of round trip times
double avgRtt; //!< average round trip time
double stdDevRtt; //!< std dev of round trip time
std::ostream&
printSummary(std::ostream& os) const;
};
/**
* @brief Statistics collector from ping client
*/
class StatisticsCollector : noncopyable
{
public:
/**
* @param ping NDN ping client
* @param options ping client options
*/
StatisticsCollector(Ping& ping, const Options& options);
/**
* @brief Compute and return ping statistics as structure
*/
Statistics
computeStatistics() const;
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
/**
* @brief Called when a Data packet is received
*/
void
recordData(Rtt rtt);
/**
* @brief Called when a Nack is received
*/
void
recordNack();
/**
* @brief Called on ping timeout
*/
void
recordTimeout();
private:
Ping& m_ping;
const Options& m_options;
int m_nSent;
int m_nReceived;
int m_nNacked;
time::steady_clock::time_point m_pingStartTime;
double m_minRtt;
double m_maxRtt;
double m_sumRtt;
double m_sumRttSquared;
};
std::ostream&
operator<<(std::ostream& os, const Statistics& statistics);
} // namespace client
} // namespace ping
} // namespace ndn
#endif // NDN_TOOLS_PING_CLIENT_STATISTICS_COLLECTOR_HPP