forwarder-status-manager.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2023, 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 
27 #include "fw/forwarder.hpp"
28 #include "core/version.hpp"
29 
30 namespace nfd {
31 
32 ForwarderStatusManager::ForwarderStatusManager(Forwarder& forwarder, Dispatcher& dispatcher)
33  : m_forwarder(forwarder)
34  , m_dispatcher(dispatcher)
35  , m_startTimestamp(time::system_clock::now())
36 {
37  m_dispatcher.addStatusDataset("status/general", ndn::mgmt::makeAcceptAllAuthorization(),
38  [this] (auto&&, auto&&, auto&& ctx) { listGeneralStatus(std::forward<decltype(ctx)>(ctx)); });
39 }
40 
41 ndn::nfd::ForwarderStatus
42 ForwarderStatusManager::collectGeneralStatus()
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 
56  const auto& counters = m_forwarder.getCounters();
57  status.setNInInterests(counters.nInInterests)
58  .setNOutInterests(counters.nOutInterests)
59  .setNInData(counters.nInData)
60  .setNOutData(counters.nOutData)
61  .setNInNacks(counters.nInNacks)
62  .setNOutNacks(counters.nOutNacks)
63  .setNSatisfiedInterests(counters.nSatisfiedInterests)
64  .setNUnsatisfiedInterests(counters.nUnsatisfiedInterests);
65 
66  return status;
67 }
68 
69 void
70 ForwarderStatusManager::listGeneralStatus(ndn::mgmt::StatusDatasetContext& context)
71 {
72  auto status = this->collectGeneralStatus();
73  const auto& wire = status.wireEncode();
74  wire.parse();
75  for (const auto& subblock : wire.elements()) {
76  context.append(subblock);
77  }
78  context.end();
79 }
80 
81 } // namespace nfd
Main class of NFD's forwarding engine.
Definition: forwarder.hpp:54
Fib & getFib() noexcept
Definition: forwarder.hpp:90
Cs & getCs() noexcept
Definition: forwarder.hpp:102
NameTree & getNameTree() noexcept
Definition: forwarder.hpp:84
Measurements & getMeasurements() noexcept
Definition: forwarder.hpp:108
const ForwarderCounters & getCounters() const noexcept
Definition: forwarder.hpp:65
Pit & getPit() noexcept
Definition: forwarder.hpp:96
ForwarderStatusManager(Forwarder &forwarder, Dispatcher &dispatcher)
size_t size() const
Get number of stored packets.
Definition: cs.hpp:94
size_t size() const noexcept
Definition: fib.hpp:57
size_t size() const
Definition: name-tree.hpp:59
size_t size() const
Returns the number of entries.
Definition: pit.hpp:94
-status-http-server
Definition: common.hpp:71
const char NFD_VERSION_BUILD_STRING[]
NFD version string, including git commit information if NFD is build from a specific git commit.