NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
status-server.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "status-server.hpp"
27 #include "fw/forwarder.hpp"
28 #include "version.hpp"
29 
30 namespace nfd {
31 
32 const Name StatusServer::DATASET_PREFIX = "ndn:/localhost/nfd/status";
33 const time::milliseconds StatusServer::RESPONSE_FRESHNESS = time::milliseconds(5000);
34 
35 StatusServer::StatusServer(shared_ptr<AppFace> face, Forwarder& forwarder, ndn::KeyChain& keyChain)
36  : m_face(face)
37  , m_forwarder(forwarder)
38  , m_startTimestamp(time::system_clock::now())
39  , m_keyChain(keyChain)
40 {
41  m_face->setInterestFilter(DATASET_PREFIX, bind(&StatusServer::onInterest, this, _2));
42 }
43 
44 void
45 StatusServer::onInterest(const Interest& interest) const
46 {
47  Name name(DATASET_PREFIX);
48  name.appendVersion();
49  name.appendSegment(0);
50 
51  shared_ptr<Data> data = make_shared<Data>(name);
52  data->setFreshnessPeriod(RESPONSE_FRESHNESS);
53 
54  shared_ptr<ndn::nfd::ForwarderStatus> status = this->collectStatus();
55  data->setContent(status->wireEncode());
56 
57  m_keyChain.sign(*data);
58  m_face->put(*data);
59 }
60 
61 shared_ptr<ndn::nfd::ForwarderStatus>
62 StatusServer::collectStatus() const
63 {
64  shared_ptr<ndn::nfd::ForwarderStatus> status = make_shared<ndn::nfd::ForwarderStatus>();
65 
66  status->setNfdVersion(NFD_VERSION_BUILD_STRING);
67  status->setStartTimestamp(m_startTimestamp);
68  status->setCurrentTimestamp(time::system_clock::now());
69 
70  status->setNNameTreeEntries(m_forwarder.getNameTree().size());
71  status->setNFibEntries(m_forwarder.getFib().size());
72  status->setNPitEntries(m_forwarder.getPit().size());
73  status->setNMeasurementsEntries(m_forwarder.getMeasurements().size());
74  status->setNCsEntries(m_forwarder.getCs().size());
75 
76  m_forwarder.getCounters().copyTo(*status);
77 
78  return status;
79 }
80 
81 } // namespace nfd
StatusServer(shared_ptr< AppFace > face, Forwarder &forwarder, ndn::KeyChain &keyChain)
size_t size() const
Definition: pit.hpp:143
main class of NFD
Definition: forwarder.hpp:54
void copyTo(R &recipient) const
copy current obseverations to a struct
size_t size() const
Definition: fib.hpp:166
size_t size() const
Get the number of occupied entries in the Name Tree.
Definition: name-tree.hpp:336
const ForwarderCounters & getCounters() const
Definition: forwarder.hpp:231
size_t size() const
returns current size of Content Store measured in packets
Definition: cs.cpp:89
Measurements & getMeasurements()
Definition: forwarder.hpp:291
Fib & getFib()
Definition: forwarder.hpp:273
size_t size() const
#define NFD_VERSION_BUILD_STRING
NFD version string, including git commit information, if NFD is build from specific git commit...
Definition: version.hpp:63
NameTree & getNameTree()
Definition: forwarder.hpp:267
Pit & getPit()
Definition: forwarder.hpp:279