NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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 "version.hpp"
29 
30 namespace nfd {
31 
32 const time::milliseconds STATUS_SERVER_DEFAULT_FRESHNESS = time::milliseconds(5000);
33 
35  : m_forwarder(forwarder)
36  , m_dispatcher(dispatcher)
37  , m_startTimestamp(time::system_clock::now())
38 {
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  .setNInDatas(counters.nInData)
62  .setNOutDatas(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  static const PartialName PREFIX_STATUS("status");
74  static const PartialName PREFIX_STATUS_GENERAL("status/general");
75 
76  PartialName subPrefix = interest.getName().getSubName(topPrefix.size());
77  if (subPrefix == PREFIX_STATUS_GENERAL || subPrefix == PREFIX_STATUS) {
78  context.setPrefix(Name(topPrefix).append(PREFIX_STATUS_GENERAL));
79  }
80  else {
81  context.reject(ndn::mgmt::ControlResponse().setCode(404));
82  return;
83  }
84  // TODO#3379 register the dataset at status/general, and delete these conditions
85 
86  context.setExpiry(STATUS_SERVER_DEFAULT_FRESHNESS);
87 
88  auto status = this->collectGeneralStatus();
89  status.wireEncode().parse();
90  for (const auto& subblock : status.wireEncode().elements()) {
91  context.append(subblock);
92  }
93  context.end();
94 }
95 
96 } // namespace nfd
void reject(const ControlResponse &resp=ControlResponse().setCode(400))
declare the non-existence of a response
ForwarderStatus & setNOutDatas(uint64_t nOutDatas)
represents NFD Forwarder Status
size_t size() const
StatusDatasetContext & setExpiry(const time::milliseconds &expiry)
set expiration duration
ForwarderStatus & setNFibEntries(size_t nFibEntries)
counters provided by Forwarder
ForwarderStatus & setNOutNacks(uint64_t nOutNacks)
represents a dispatcher on server side of NFD Management protocol
Definition: dispatcher.hpp:129
ForwarderStatus & setNInNacks(uint64_t nInNacks)
main class of NFD
Definition: forwarder.hpp:55
represents an Interest packet
Definition: interest.hpp:45
ForwarderStatus & setNCsEntries(size_t nCsEntries)
static time_point now() noexcept
Definition: time.cpp:45
Authorization makeAcceptAllAuthorization()
Definition: dispatcher.cpp:34
size_t size() const
Get the number of occupied entries in the Name Tree.
Definition: name-tree.hpp:355
ForwarderStatus & setNNameTreeEntries(size_t nNameTreeEntries)
size_t size() const
Definition: cs.hpp:124
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
Measurements & getMeasurements()
Definition: forwarder.hpp:319
ForwarderStatus & setNfdVersion(const std::string &nfdVersion)
ForwarderStatus & setNOutInterests(uint64_t nOutInterests)
Fib & getFib()
Definition: forwarder.hpp:301
Name abstraction to represent an absolute name.
Definition: name.hpp:46
ForwarderStatus & setNPitEntries(size_t nPitEntries)
size_t size() const
Definition: fib.hpp:166
size_t size() const
Get the number of components.
Definition: name.hpp:408
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:259
const time::milliseconds STATUS_SERVER_DEFAULT_FRESHNESS
const ForwarderCounters & getCounters() const
Definition: forwarder.hpp:271
ForwarderStatus & setNInDatas(uint64_t nInDatas)
StatusDatasetContext & setPrefix(const Name &prefix)
change prefix of Data packets
void append(const Block &block)
append a Block to the response
Name PartialName
Partial name abstraction to represent an arbitrary sequence of name components.
Definition: name.hpp:36
ControlCommand response.
provides a context for generating response to a StatusDataset request
ForwarderStatus & setNMeasurementsEntries(size_t nMeasurementsEntries)
ForwarderStatus & setCurrentTimestamp(const time::system_clock::TimePoint &currentTimestamp)
ForwarderStatusManager(Forwarder &forwarder, Dispatcher &dispatcher)
size_t size() const
Definition: pit.hpp:160
PartialName getSubName(ssize_t iStartComponent, size_t nComponents=npos) const
Extract a sub-name (PartialName) of nComponents components starting from iStartComponent.
Definition: name.cpp:274
NameTree & getNameTree()
Definition: forwarder.hpp:295
const Name & getName() const
Definition: interest.hpp:218
Pit & getPit()
Definition: forwarder.hpp:307