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-2018, 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 static const time::milliseconds STATUS_FRESHNESS(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/general", ndn::mgmt::makeAcceptAllAuthorization(),
40  bind(&ForwarderStatusManager::listGeneralStatus, this, _1, _2, _3));
41 }
42 
43 ndn::nfd::ForwarderStatus
44 ForwarderStatusManager::collectGeneralStatus()
45 {
46  ndn::nfd::ForwarderStatus status;
47 
48  status.setNfdVersion(NFD_VERSION_BUILD_STRING);
49  status.setStartTimestamp(m_startTimestamp);
50  status.setCurrentTimestamp(time::system_clock::now());
51 
52  status.setNNameTreeEntries(m_forwarder.getNameTree().size());
53  status.setNFibEntries(m_forwarder.getFib().size());
54  status.setNPitEntries(m_forwarder.getPit().size());
55  status.setNMeasurementsEntries(m_forwarder.getMeasurements().size());
56  status.setNCsEntries(m_forwarder.getCs().size());
57 
58  const ForwarderCounters& counters = m_forwarder.getCounters();
59  status.setNInInterests(counters.nInInterests)
60  .setNOutInterests(counters.nOutInterests)
61  .setNInData(counters.nInData)
62  .setNOutData(counters.nOutData)
63  .setNInNacks(counters.nInNacks)
64  .setNOutNacks(counters.nOutNacks)
65  .setNSatisfiedInterests(counters.nSatisfiedInterests)
66  .setNUnsatisfiedInterests(counters.nUnsatisfiedInterests);
67 
68  return status;
69 }
70 
71 void
72 ForwarderStatusManager::listGeneralStatus(const Name& topPrefix, const Interest& interest,
73  ndn::mgmt::StatusDatasetContext& context)
74 {
75  context.setExpiry(STATUS_FRESHNESS);
76 
77  auto status = this->collectGeneralStatus();
78  const Block& wire = status.wireEncode();
79  wire.parse();
80  for (const auto& subblock : wire.elements()) {
81  context.append(subblock);
82  }
83  context.end();
84 }
85 
86 } // namespace nfd
Main class of NFD&#39;s forwarding engine.
Definition: forwarder.hpp:51
static const time::milliseconds STATUS_FRESHNESS(5000)
PacketCounter nUnsatisfiedInterests
Fib & getFib()
Definition: forwarder.hpp:127
ForwarderStatusManager(Forwarder &forwarder, Dispatcher &dispatcher)
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
const char NFD_VERSION_BUILD_STRING[]
NFD version string, including git commit information, if NFD is build from specific git commit...
Pit & getPit()
Definition: forwarder.hpp:133
NameTree & getNameTree()
Definition: forwarder.hpp:121
counters provided by Forwarder
const ForwarderCounters & getCounters() const
Definition: forwarder.hpp:61
Measurements & getMeasurements()
Definition: forwarder.hpp:145