forwarder-status-manager.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
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 
66  return status;
67 }
68 
69 void
70 ForwarderStatusManager::listGeneralStatus(const Name& topPrefix, const Interest& interest,
71  ndn::mgmt::StatusDatasetContext& context)
72 {
73  context.setExpiry(STATUS_FRESHNESS);
74 
75  auto status = this->collectGeneralStatus();
76  const Block& wire = status.wireEncode();
77  wire.parse();
78  for (const auto& subblock : wire.elements()) {
79  context.append(subblock);
80  }
81  context.end();
82 }
83 
84 } // namespace nfd
main class of NFD
Definition: forwarder.hpp:52
static const time::milliseconds STATUS_FRESHNESS(5000)
Fib & getFib()
Definition: forwarder.hpp:144
ForwarderStatusManager(Forwarder &forwarder, Dispatcher &dispatcher)
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
Pit & getPit()
Definition: forwarder.hpp:150
NameTree & getNameTree()
Definition: forwarder.hpp:138
counters provided by Forwarder
const ForwarderCounters & getCounters() const
Definition: forwarder.hpp:61
Measurements & getMeasurements()
Definition: forwarder.hpp:162