blob: 7db5085161e22a7a38fadae31565df8a4fdc2a27 [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 Teng Liang <philoliang@email.arizona.edu>
Eric Newberry4164b8e2015-04-23 17:29:18 -070021 */
22
23#include "tracer.hpp"
24
25namespace ndn {
26namespace ping {
27namespace client {
28
29Tracer::Tracer(Ping& ping, const Options& options)
30 : m_options(options)
31{
Davide Pesaventof8d9a532021-07-03 16:04:12 -040032 ping.afterData.connect(FORWARD_TO_MEM_FN(onData));
33 ping.afterNack.connect(FORWARD_TO_MEM_FN(onNack));
34 ping.afterTimeout.connect(FORWARD_TO_MEM_FN(onTimeout));
Eric Newberry4164b8e2015-04-23 17:29:18 -070035}
36
37void
Teng Liang62884862016-03-31 18:15:36 -070038Tracer::onData(uint64_t seq, Rtt rtt)
Eric Newberry4164b8e2015-04-23 17:29:18 -070039{
40 if (m_options.shouldPrintTimestamp) {
41 std::cout << time::toIsoString(time::system_clock::now()) << " - ";
42 }
43
44 std::cout << "content from " << m_options.prefix << ": seq=" << seq << " time="
Davide Pesaventof8d9a532021-07-03 16:04:12 -040045 << rtt.count() << " ms\n";
Eric Newberry4164b8e2015-04-23 17:29:18 -070046}
47
48void
Teng Liang62884862016-03-31 18:15:36 -070049Tracer::onNack(uint64_t seq, Rtt rtt, const lp::NackHeader& header)
50{
51 if (m_options.shouldPrintTimestamp) {
52 std::cout << time::toIsoString(time::system_clock::now()) << " - ";
53 }
54
55 std::cout << "nack from " << m_options.prefix << ": seq=" << seq << " time="
Davide Pesaventof8d9a532021-07-03 16:04:12 -040056 << rtt.count() << " ms" << " reason=" << header.getReason() << "\n";
Teng Liang62884862016-03-31 18:15:36 -070057}
58
59void
Eric Newberry4164b8e2015-04-23 17:29:18 -070060Tracer::onTimeout(uint64_t seq)
61{
62 if (m_options.shouldPrintTimestamp) {
63 std::cout << time::toIsoString(time::system_clock::now()) << " - ";
64 }
65
Davide Pesaventof8d9a532021-07-03 16:04:12 -040066 std::cout << "timeout from " << m_options.prefix << ": seq=" << seq << "\n";
Eric Newberry4164b8e2015-04-23 17:29:18 -070067}
68
69void
Davide Pesaventof8d9a532021-07-03 16:04:12 -040070Tracer::onError(const std::string& msg)
Eric Newberry4164b8e2015-04-23 17:29:18 -070071{
Davide Pesaventof8d9a532021-07-03 16:04:12 -040072 std::cerr << "ERROR: " << msg << "\n";
Eric Newberry4164b8e2015-04-23 17:29:18 -070073}
74
75} // namespace client
76} // namespace ping
77} // namespace ndn