Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ju Pan | 6eb1ac9 | 2018-10-26 16:26:15 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | 86644d3 | 2021-04-02 15:20:16 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2021, Regents of the University of California, |
Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #include "forwarder-status-manager.hpp" |
| 27 | #include "fw/forwarder.hpp" |
Junxiao Shi | 9f5b01d | 2016-08-05 03:54:28 +0000 | [diff] [blame] | 28 | #include "core/version.hpp" |
Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 29 | |
| 30 | namespace nfd { |
| 31 | |
Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 32 | ForwarderStatusManager::ForwarderStatusManager(Forwarder& forwarder, Dispatcher& dispatcher) |
| 33 | : m_forwarder(forwarder) |
| 34 | , m_dispatcher(dispatcher) |
| 35 | , m_startTimestamp(time::system_clock::now()) |
| 36 | { |
Junxiao Shi | d820510 | 2016-09-22 18:08:45 +0000 | [diff] [blame] | 37 | m_dispatcher.addStatusDataset("status/general", ndn::mgmt::makeAcceptAllAuthorization(), |
Junxiao Shi | 498373d | 2015-12-29 17:51:26 -0700 | [diff] [blame] | 38 | bind(&ForwarderStatusManager::listGeneralStatus, this, _1, _2, _3)); |
Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Junxiao Shi | 498373d | 2015-12-29 17:51:26 -0700 | [diff] [blame] | 41 | ndn::nfd::ForwarderStatus |
| 42 | ForwarderStatusManager::collectGeneralStatus() |
Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 43 | { |
| 44 | ndn::nfd::ForwarderStatus status; |
| 45 | |
| 46 | status.setNfdVersion(NFD_VERSION_BUILD_STRING); |
| 47 | status.setStartTimestamp(m_startTimestamp); |
| 48 | status.setCurrentTimestamp(time::system_clock::now()); |
| 49 | |
| 50 | status.setNNameTreeEntries(m_forwarder.getNameTree().size()); |
| 51 | status.setNFibEntries(m_forwarder.getFib().size()); |
| 52 | status.setNPitEntries(m_forwarder.getPit().size()); |
| 53 | status.setNMeasurementsEntries(m_forwarder.getMeasurements().size()); |
| 54 | status.setNCsEntries(m_forwarder.getCs().size()); |
| 55 | |
Davide Pesavento | 86644d3 | 2021-04-02 15:20:16 -0400 | [diff] [blame^] | 56 | const auto& counters = m_forwarder.getCounters(); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 57 | status.setNInInterests(counters.nInInterests) |
| 58 | .setNOutInterests(counters.nOutInterests) |
Junxiao Shi | f03d479 | 2017-04-06 16:41:22 +0000 | [diff] [blame] | 59 | .setNInData(counters.nInData) |
| 60 | .setNOutData(counters.nOutData) |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 61 | .setNInNacks(counters.nInNacks) |
Ju Pan | 6eb1ac9 | 2018-10-26 16:26:15 +0000 | [diff] [blame] | 62 | .setNOutNacks(counters.nOutNacks) |
| 63 | .setNSatisfiedInterests(counters.nSatisfiedInterests) |
| 64 | .setNUnsatisfiedInterests(counters.nUnsatisfiedInterests); |
Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 65 | |
Junxiao Shi | 498373d | 2015-12-29 17:51:26 -0700 | [diff] [blame] | 66 | return status; |
| 67 | } |
| 68 | |
| 69 | void |
Davide Pesavento | 86644d3 | 2021-04-02 15:20:16 -0400 | [diff] [blame^] | 70 | ForwarderStatusManager::listGeneralStatus(const Name&, const Interest&, |
Junxiao Shi | 498373d | 2015-12-29 17:51:26 -0700 | [diff] [blame] | 71 | ndn::mgmt::StatusDatasetContext& context) |
| 72 | { |
Junxiao Shi | 498373d | 2015-12-29 17:51:26 -0700 | [diff] [blame] | 73 | auto status = this->collectGeneralStatus(); |
Davide Pesavento | 86644d3 | 2021-04-02 15:20:16 -0400 | [diff] [blame^] | 74 | const auto& wire = status.wireEncode(); |
Junxiao Shi | d820510 | 2016-09-22 18:08:45 +0000 | [diff] [blame] | 75 | wire.parse(); |
| 76 | for (const auto& subblock : wire.elements()) { |
Alexander Afanasyev | ecbf584 | 2015-09-08 17:25:23 -0700 | [diff] [blame] | 77 | context.append(subblock); |
| 78 | } |
Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 79 | context.end(); |
| 80 | } |
| 81 | |
| 82 | } // namespace nfd |