/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
 * Copyright (c) 2015,  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>
 */

#include "statistics-collector.hpp"

namespace ndn {
namespace ping {
namespace client {

StatisticsCollector::StatisticsCollector(Ping& ping, const Options& options)
  : m_ping(ping)
  , m_options(options)
  , m_nSent(0)
  , m_nReceived(0)
  , m_pingStartTime(time::steady_clock::now())
  , m_minRtt(std::numeric_limits<double>::max())
  , m_maxRtt(0.0)
  , m_sumRtt(0.0)
  , m_sumRttSquared(0.0)
{
  m_ping.afterResponse.connect(bind(&StatisticsCollector::recordResponse, this, _2));
  m_ping.afterTimeout.connect(bind(&StatisticsCollector::recordTimeout, this));
}

void
StatisticsCollector::recordResponse(Rtt rtt)
{
  m_nSent++;
  m_nReceived++;

  double rttMs = rtt.count();

  m_minRtt = std::min(m_minRtt, rttMs);

  m_maxRtt = std::max(m_maxRtt, rttMs);

  m_sumRtt += rttMs;
  m_sumRttSquared += rttMs * rttMs;
}

void
StatisticsCollector::recordTimeout()
{
  m_nSent++;
}

Statistics
StatisticsCollector::computeStatistics()
{
  Statistics statistics;

  statistics.prefix = m_options.prefix;
  statistics.nSent = m_nSent;
  statistics.nReceived = m_nReceived;
  statistics.pingStartTime = m_pingStartTime;
  statistics.minRtt = m_minRtt;
  statistics.maxRtt = m_maxRtt;
  statistics.packetLossRate = (double)(m_nSent - m_nReceived) / (double)m_nSent;
  statistics.sumRtt = m_sumRtt;
  statistics.avgRtt = m_sumRtt / m_nReceived;
  statistics.stdDevRtt = std::sqrt((m_sumRttSquared / m_nReceived) - (statistics.avgRtt * statistics.avgRtt));

  return statistics;
}

std::ostream&
Statistics::printSummary(std::ostream& os) const
{
  os << nReceived << "/" << nSent << " packets, " << packetLossRate * 100.0
     << "% loss, min/avg/max/mdev = " << minRtt << "/" << avgRtt << "/" << maxRtt << "/"
     << stdDevRtt << " ms" << std::endl;

  return os;
}

std::ostream&
operator<<(std::ostream& os, const Statistics& statistics)
{
  os << "\n";
  os << "--- " << statistics.prefix <<" ping statistics ---\n";
  os << statistics.nSent << " packets transmitted";
  os << ", " << statistics.nReceived << " received";
  os << ", " << statistics.packetLossRate * 100.0 << "% packet loss";
  os << ", time " << statistics.sumRtt << " ms";
  if (statistics.nReceived > 0) {
    os << "\n";
    os << "rtt min/avg/max/mdev = ";
    os << statistics.minRtt << "/";
    os << statistics.avgRtt << "/";
    os << statistics.maxRtt << "/";
    os << statistics.stdDevRtt << " ms";
  }

  return os;
}

} // namespace client
} // namespace ping
} // namespace ndn
