NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
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
represents an Interest packet
Definition: interest.hpp:45
static time_point now() noexcept
Definition: time.cpp:45
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:242
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:38
Name & appendSegment(uint64_t segmentNo)
Append segment number (sequential) using NDN naming conventions.
Definition: name.cpp:232
Measurements & getMeasurements()
Definition: forwarder.hpp:302
Fib & getFib()
Definition: forwarder.hpp:284
Name abstraction to represent an absolute name.
Definition: name.hpp:46
size_t size() const
NameTree & getNameTree()
Definition: forwarder.hpp:278
Name & appendVersion(uint64_t version)
Append version using NDN naming conventions.
Definition: name.cpp:218
Pit & getPit()
Definition: forwarder.hpp:290