blob: c8ce5b4b0f6cc81ac42490fdc22a5429e2a0a250 [file] [log] [blame]
Junxiao Shiea48d8b2014-03-16 13:53:47 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi632a6202014-07-20 01:14:30 -07003 * Copyright (c) 2014, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Junxiao Shi632a6202014-07-20 01:14:30 -070024 */
Junxiao Shiea48d8b2014-03-16 13:53:47 -070025
26#include "status-server.hpp"
27#include "fw/forwarder.hpp"
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070028#include "version.hpp"
Junxiao Shiea48d8b2014-03-16 13:53:47 -070029
30namespace nfd {
31
32const Name StatusServer::DATASET_PREFIX = "ndn:/localhost/nfd/status";
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070033const time::milliseconds StatusServer::RESPONSE_FRESHNESS = time::milliseconds(5000);
Junxiao Shiea48d8b2014-03-16 13:53:47 -070034
Vince Lehman5144f822014-07-23 15:12:56 -070035StatusServer::StatusServer(shared_ptr<AppFace> face, Forwarder& forwarder, ndn::KeyChain& keyChain)
Junxiao Shiea48d8b2014-03-16 13:53:47 -070036 : m_face(face)
37 , m_forwarder(forwarder)
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070038 , m_startTimestamp(time::system_clock::now())
Vince Lehman5144f822014-07-23 15:12:56 -070039 , m_keyChain(keyChain)
Junxiao Shiea48d8b2014-03-16 13:53:47 -070040{
41 m_face->setInterestFilter(DATASET_PREFIX, bind(&StatusServer::onInterest, this, _2));
42}
43
44void
45StatusServer::onInterest(const Interest& interest) const
46{
47 Name name(DATASET_PREFIX);
Alexander Afanasyev06ae9072014-03-22 23:42:08 -070048 name.appendVersion();
49 name.appendSegment(0);
Junxiao Shiea48d8b2014-03-16 13:53:47 -070050
51 shared_ptr<Data> data = make_shared<Data>(name);
52 data->setFreshnessPeriod(RESPONSE_FRESHNESS);
53
Junxiao Shi88d69372014-03-28 11:52:39 -070054 shared_ptr<ndn::nfd::ForwarderStatus> status = this->collectStatus();
55 data->setContent(status->wireEncode());
Junxiao Shiea48d8b2014-03-16 13:53:47 -070056
Vince Lehman5144f822014-07-23 15:12:56 -070057 m_keyChain.sign(*data);
Junxiao Shiea48d8b2014-03-16 13:53:47 -070058 m_face->put(*data);
59}
60
Junxiao Shi88d69372014-03-28 11:52:39 -070061shared_ptr<ndn::nfd::ForwarderStatus>
Junxiao Shiea48d8b2014-03-16 13:53:47 -070062StatusServer::collectStatus() const
63{
Junxiao Shi88d69372014-03-28 11:52:39 -070064 shared_ptr<ndn::nfd::ForwarderStatus> status = make_shared<ndn::nfd::ForwarderStatus>();
Junxiao Shiea48d8b2014-03-16 13:53:47 -070065
Hila Ben Abraham2ef99572014-12-02 02:45:51 -060066 status->setNfdVersion(NFD_VERSION_BUILD_STRING);
Junxiao Shiea48d8b2014-03-16 13:53:47 -070067 status->setStartTimestamp(m_startTimestamp);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070068 status->setCurrentTimestamp(time::system_clock::now());
Junxiao Shiea48d8b2014-03-16 13:53:47 -070069
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
Junxiao Shi632a6202014-07-20 01:14:30 -070076 m_forwarder.getCounters().copyTo(*status);
Junxiao Shiea48d8b2014-03-16 13:53:47 -070077
78 return status;
79}
80
81} // namespace nfd