NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
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 
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 
44 ForwarderStatusManager::collectGeneralStatus()
45 {
47 
48  status.setNfdVersion(NFD_VERSION_BUILD_STRING);
49  status.setStartTimestamp(m_startTimestamp);
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)
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,
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
const ForwarderCounters & getCounters() const
Definition: forwarder.hpp:63
represents NFD General Status dataset
StatusDatasetContext & setExpiry(const time::milliseconds &expiry)
set expiration duration
size_t wireEncode(EncodingImpl< TAG > &encoder) const
prepend ForwarderStatus as a Content block to the encoder
ForwarderStatus & setNFibEntries(size_t nFibEntries)
static const time::milliseconds STATUS_FRESHNESS(5000)
counters provided by Forwarder
ForwarderStatus & setNOutNacks(uint64_t nOutNacks)
represents a dispatcher on server side of NFD Management protocol
Definition: dispatcher.hpp:129
Fib & getFib()
Definition: forwarder.hpp:146
ForwarderStatus & setNInData(uint64_t nInData)
ForwarderStatus & setNOutData(uint64_t nOutData)
ForwarderStatus & setNInNacks(uint64_t nInNacks)
main class of NFD
Definition: forwarder.hpp:54
ForwarderStatus & setNCsEntries(size_t nCsEntries)
static time_point now() noexcept
Definition: time.cpp:46
Authorization makeAcceptAllAuthorization()
Definition: dispatcher.cpp:34
ForwarderStatus & setNNameTreeEntries(size_t nNameTreeEntries)
size_t size() const
get number of stored packets
Definition: cs.hpp:91
ForwarderStatus & setNInInterests(uint64_t nInInterests)
ForwarderStatus & setStartTimestamp(const time::system_clock::TimePoint &startTimestamp)
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
void end()
end the response successfully after appending zero or more blocks
ForwarderStatus & setNfdVersion(const std::string &nfdVersion)
ForwarderStatus & setNOutInterests(uint64_t nOutInterests)
ForwarderStatus & setNPitEntries(size_t nPitEntries)
size_t size() const
Definition: pit.hpp:55
void addStatusDataset(const PartialName &relPrefix, const Authorization &authorization, const StatusDatasetHandler &handler)
register a StatusDataset or a prefix under which StatusDatasets can be requested
Definition: dispatcher.cpp:257
Measurements & getMeasurements()
Definition: forwarder.hpp:164
Pit & getPit()
Definition: forwarder.hpp:152
void append(const Block &block)
append a Block to the response
size_t size() const
Definition: name-tree.hpp:62
size_t size() const
Definition: fib.hpp:56
provides a context for generating response to a StatusDataset request
ForwarderStatus & setNMeasurementsEntries(size_t nMeasurementsEntries)
ForwarderStatus & setCurrentTimestamp(const time::system_clock::TimePoint &currentTimestamp)
NameTree & getNameTree()
Definition: forwarder.hpp:140
ForwarderStatusManager(Forwarder &forwarder, Dispatcher &dispatcher)