Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2015, Regents of the University of California, |
| 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" |
| 28 | #include "version.hpp" |
| 29 | |
| 30 | namespace nfd { |
| 31 | |
| 32 | const time::milliseconds STATUS_SERVER_DEFAULT_FRESHNESS = time::milliseconds(5000); |
| 33 | |
| 34 | ForwarderStatusManager::ForwarderStatusManager(Forwarder& forwarder, Dispatcher& dispatcher) |
| 35 | : m_forwarder(forwarder) |
| 36 | , m_dispatcher(dispatcher) |
| 37 | , m_startTimestamp(time::system_clock::now()) |
| 38 | { |
| 39 | m_dispatcher.addStatusDataset("status", ndn::mgmt::makeAcceptAllAuthorization(), |
| 40 | bind(&ForwarderStatusManager::listStatus, this, _1, _2, _3)); |
| 41 | } |
| 42 | |
| 43 | void |
| 44 | ForwarderStatusManager::listStatus(const Name& topPrefix, const Interest& interest, |
| 45 | ndn::mgmt::StatusDatasetContext& context) |
| 46 | { |
| 47 | ndn::nfd::ForwarderStatus status; |
| 48 | |
| 49 | status.setNfdVersion(NFD_VERSION_BUILD_STRING); |
| 50 | status.setStartTimestamp(m_startTimestamp); |
| 51 | status.setCurrentTimestamp(time::system_clock::now()); |
| 52 | |
| 53 | status.setNNameTreeEntries(m_forwarder.getNameTree().size()); |
| 54 | status.setNFibEntries(m_forwarder.getFib().size()); |
| 55 | status.setNPitEntries(m_forwarder.getPit().size()); |
| 56 | status.setNMeasurementsEntries(m_forwarder.getMeasurements().size()); |
| 57 | status.setNCsEntries(m_forwarder.getCs().size()); |
| 58 | |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 59 | const ForwarderCounters& counters = m_forwarder.getCounters(); |
| 60 | status.setNInInterests(counters.nInInterests) |
| 61 | .setNOutInterests(counters.nOutInterests) |
| 62 | .setNInDatas(counters.nInData) |
| 63 | .setNOutDatas(counters.nOutData) |
| 64 | .setNInNacks(counters.nInNacks) |
| 65 | .setNOutNacks(counters.nOutNacks); |
Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 66 | |
| 67 | context.setExpiry(STATUS_SERVER_DEFAULT_FRESHNESS); |
Alexander Afanasyev | ecbf584 | 2015-09-08 17:25:23 -0700 | [diff] [blame] | 68 | |
| 69 | status.wireEncode().parse(); |
| 70 | for (const auto& subblock : status.wireEncode().elements()) { |
| 71 | context.append(subblock); |
| 72 | } |
Yanbiao Li | 7cec7ea | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 73 | context.end(); |
| 74 | } |
| 75 | |
| 76 | } // namespace nfd |