Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Teng Liang | 6288486 | 2016-03-31 18:15:36 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2015-2016, 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 | * |
| 19 | * @author: Eric Newberry <enewberry@email.arizona.edu> |
Teng Liang | 6288486 | 2016-03-31 18:15:36 -0700 | [diff] [blame^] | 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 | |
| 25 | namespace ndn { |
| 26 | namespace ping { |
| 27 | namespace client { |
| 28 | |
| 29 | Tracer::Tracer(Ping& ping, const Options& options) |
| 30 | : m_options(options) |
| 31 | { |
Teng Liang | 6288486 | 2016-03-31 18:15:36 -0700 | [diff] [blame^] | 32 | ping.afterData.connect(bind(&Tracer::onData, this, _1, _2)); |
| 33 | ping.afterNack.connect(bind(&Tracer::onNack, this, _1, _2, _3)); |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 34 | ping.afterTimeout.connect(bind(&Tracer::onTimeout, this, _1)); |
| 35 | } |
| 36 | |
| 37 | void |
Teng Liang | 6288486 | 2016-03-31 18:15:36 -0700 | [diff] [blame^] | 38 | Tracer::onData(uint64_t seq, Rtt rtt) |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 39 | { |
| 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=" |
| 45 | << rtt.count() << " ms" << std::endl; |
| 46 | } |
| 47 | |
| 48 | void |
Teng Liang | 6288486 | 2016-03-31 18:15:36 -0700 | [diff] [blame^] | 49 | Tracer::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=" |
| 56 | << rtt.count() << " ms" << " reason=" << header.getReason() << std::endl; |
| 57 | } |
| 58 | |
| 59 | void |
Eric Newberry | 4164b8e | 2015-04-23 17:29:18 -0700 | [diff] [blame] | 60 | Tracer::onTimeout(uint64_t seq) |
| 61 | { |
| 62 | if (m_options.shouldPrintTimestamp) { |
| 63 | std::cout << time::toIsoString(time::system_clock::now()) << " - "; |
| 64 | } |
| 65 | |
| 66 | std::cout << "timeout from " << m_options.prefix << ": seq=" << seq << std::endl; |
| 67 | } |
| 68 | |
| 69 | void |
| 70 | Tracer::onError(std::string msg) |
| 71 | { |
| 72 | std::cerr << "ERROR: " << msg << std::endl; |
| 73 | } |
| 74 | |
| 75 | } // namespace client |
| 76 | } // namespace ping |
| 77 | } // namespace ndn |