Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | f8d9a53 | 2021-07-03 16:04:12 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | b3570c6 | 2022-02-19 19:19:00 -0500 | [diff] [blame^] | 3 | * Copyright (c) 2015-2022, Arizona Board of Regents. |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 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 | * |
Davide Pesavento | f8d9a53 | 2021-07-03 16:04:12 -0400 | [diff] [blame] | 19 | * @author Eric Newberry <enewberry@email.arizona.edu> |
| 20 | * @author Teng Liang <philoliang@email.arizona.edu> |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #include "tracer.hpp" |
| 24 | |
Davide Pesavento | b3570c6 | 2022-02-19 19:19:00 -0500 | [diff] [blame^] | 25 | namespace ndn::ping::client { |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 26 | |
| 27 | Tracer::Tracer(Ping& ping, const Options& options) |
| 28 | : m_options(options) |
| 29 | { |
Davide Pesavento | f8d9a53 | 2021-07-03 16:04:12 -0400 | [diff] [blame] | 30 | ping.afterData.connect(FORWARD_TO_MEM_FN(onData)); |
| 31 | ping.afterNack.connect(FORWARD_TO_MEM_FN(onNack)); |
| 32 | ping.afterTimeout.connect(FORWARD_TO_MEM_FN(onTimeout)); |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | void |
Teng Liang | 6288486 | 2016-03-31 18:15:36 -0700 | [diff] [blame] | 36 | Tracer::onData(uint64_t seq, Rtt rtt) |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 37 | { |
| 38 | if (m_options.shouldPrintTimestamp) { |
| 39 | std::cout << time::toIsoString(time::system_clock::now()) << " - "; |
| 40 | } |
| 41 | |
| 42 | std::cout << "content from " << m_options.prefix << ": seq=" << seq << " time=" |
Davide Pesavento | f8d9a53 | 2021-07-03 16:04:12 -0400 | [diff] [blame] | 43 | << rtt.count() << " ms\n"; |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | void |
Teng Liang | 6288486 | 2016-03-31 18:15:36 -0700 | [diff] [blame] | 47 | Tracer::onNack(uint64_t seq, Rtt rtt, const lp::NackHeader& header) |
| 48 | { |
| 49 | if (m_options.shouldPrintTimestamp) { |
| 50 | std::cout << time::toIsoString(time::system_clock::now()) << " - "; |
| 51 | } |
| 52 | |
| 53 | std::cout << "nack from " << m_options.prefix << ": seq=" << seq << " time=" |
Davide Pesavento | f8d9a53 | 2021-07-03 16:04:12 -0400 | [diff] [blame] | 54 | << rtt.count() << " ms" << " reason=" << header.getReason() << "\n"; |
Teng Liang | 6288486 | 2016-03-31 18:15:36 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | void |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 58 | Tracer::onTimeout(uint64_t seq) |
| 59 | { |
| 60 | if (m_options.shouldPrintTimestamp) { |
| 61 | std::cout << time::toIsoString(time::system_clock::now()) << " - "; |
| 62 | } |
| 63 | |
Davide Pesavento | f8d9a53 | 2021-07-03 16:04:12 -0400 | [diff] [blame] | 64 | std::cout << "timeout from " << m_options.prefix << ": seq=" << seq << "\n"; |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | void |
Davide Pesavento | f8d9a53 | 2021-07-03 16:04:12 -0400 | [diff] [blame] | 68 | Tracer::onError(const std::string& msg) |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 69 | { |
Davide Pesavento | f8d9a53 | 2021-07-03 16:04:12 -0400 | [diff] [blame] | 70 | std::cerr << "ERROR: " << msg << "\n"; |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Davide Pesavento | b3570c6 | 2022-02-19 19:19:00 -0500 | [diff] [blame^] | 73 | } // namespace ndn::ping::client |