blob: d8ed725af584d0407811b7af04a2fb891a972fe4 [file] [log] [blame]
Yanbiao Li7cec7ea2015-08-19 16:30:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ju Pan6eb1ac92018-10-26 16:26:15 +00002/*
Davide Pesaventoae430302023-05-11 01:42:46 -04003 * Copyright (c) 2014-2023, Regents of the University of California,
Yanbiao Li7cec7ea2015-08-19 16:30:16 -07004 * 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 Shi9f5b01d2016-08-05 03:54:28 +000028#include "core/version.hpp"
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070029
30namespace nfd {
31
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070032ForwarderStatusManager::ForwarderStatusManager(Forwarder& forwarder, Dispatcher& dispatcher)
33 : m_forwarder(forwarder)
34 , m_dispatcher(dispatcher)
35 , m_startTimestamp(time::system_clock::now())
36{
Junxiao Shid8205102016-09-22 18:08:45 +000037 m_dispatcher.addStatusDataset("status/general", ndn::mgmt::makeAcceptAllAuthorization(),
Davide Pesaventoae430302023-05-11 01:42:46 -040038 [this] (auto&&, auto&&, auto&& ctx) { listGeneralStatus(std::forward<decltype(ctx)>(ctx)); });
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070039}
40
Junxiao Shi498373d2015-12-29 17:51:26 -070041ndn::nfd::ForwarderStatus
42ForwarderStatusManager::collectGeneralStatus()
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070043{
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 Pesavento86644d32021-04-02 15:20:16 -040056 const auto& counters = m_forwarder.getCounters();
Junxiao Shida93f1f2015-11-11 06:13:16 -070057 status.setNInInterests(counters.nInInterests)
58 .setNOutInterests(counters.nOutInterests)
Junxiao Shif03d4792017-04-06 16:41:22 +000059 .setNInData(counters.nInData)
60 .setNOutData(counters.nOutData)
Junxiao Shida93f1f2015-11-11 06:13:16 -070061 .setNInNacks(counters.nInNacks)
Ju Pan6eb1ac92018-10-26 16:26:15 +000062 .setNOutNacks(counters.nOutNacks)
63 .setNSatisfiedInterests(counters.nSatisfiedInterests)
64 .setNUnsatisfiedInterests(counters.nUnsatisfiedInterests);
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070065
Junxiao Shi498373d2015-12-29 17:51:26 -070066 return status;
67}
68
69void
Davide Pesaventoae430302023-05-11 01:42:46 -040070ForwarderStatusManager::listGeneralStatus(ndn::mgmt::StatusDatasetContext& context)
Junxiao Shi498373d2015-12-29 17:51:26 -070071{
Junxiao Shi498373d2015-12-29 17:51:26 -070072 auto status = this->collectGeneralStatus();
Davide Pesavento86644d32021-04-02 15:20:16 -040073 const auto& wire = status.wireEncode();
Junxiao Shid8205102016-09-22 18:08:45 +000074 wire.parse();
75 for (const auto& subblock : wire.elements()) {
Alexander Afanasyevecbf5842015-09-08 17:25:23 -070076 context.append(subblock);
77 }
Yanbiao Li7cec7ea2015-08-19 16:30:16 -070078 context.end();
79}
80
81} // namespace nfd