blob: 148061cb67e2a38323bc18b6095651e148fded52 [file] [log] [blame]
Junxiao Shiea48d8b2014-03-16 13:53:47 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -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 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
Junxiao Shiea48d8b2014-03-16 13:53:47 -070024
25#include "status-server.hpp"
26#include "fw/forwarder.hpp"
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070027#include "version.hpp"
Junxiao Shiea48d8b2014-03-16 13:53:47 -070028
29namespace nfd {
30
31const Name StatusServer::DATASET_PREFIX = "ndn:/localhost/nfd/status";
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070032const time::milliseconds StatusServer::RESPONSE_FRESHNESS = time::milliseconds(5000);
Junxiao Shiea48d8b2014-03-16 13:53:47 -070033
34StatusServer::StatusServer(shared_ptr<AppFace> face, Forwarder& forwarder)
35 : m_face(face)
36 , m_forwarder(forwarder)
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070037 , m_startTimestamp(time::system_clock::now())
Junxiao Shiea48d8b2014-03-16 13:53:47 -070038{
39 m_face->setInterestFilter(DATASET_PREFIX, bind(&StatusServer::onInterest, this, _2));
40}
41
42void
43StatusServer::onInterest(const Interest& interest) const
44{
45 Name name(DATASET_PREFIX);
Alexander Afanasyev06ae9072014-03-22 23:42:08 -070046 name.appendVersion();
47 name.appendSegment(0);
Junxiao Shiea48d8b2014-03-16 13:53:47 -070048
49 shared_ptr<Data> data = make_shared<Data>(name);
50 data->setFreshnessPeriod(RESPONSE_FRESHNESS);
51
Junxiao Shi88d69372014-03-28 11:52:39 -070052 shared_ptr<ndn::nfd::ForwarderStatus> status = this->collectStatus();
53 data->setContent(status->wireEncode());
Junxiao Shiea48d8b2014-03-16 13:53:47 -070054
55 m_face->sign(*data);
56 m_face->put(*data);
57}
58
Junxiao Shi88d69372014-03-28 11:52:39 -070059shared_ptr<ndn::nfd::ForwarderStatus>
Junxiao Shiea48d8b2014-03-16 13:53:47 -070060StatusServer::collectStatus() const
61{
Junxiao Shi88d69372014-03-28 11:52:39 -070062 shared_ptr<ndn::nfd::ForwarderStatus> status = make_shared<ndn::nfd::ForwarderStatus>();
Junxiao Shiea48d8b2014-03-16 13:53:47 -070063
64 status->setNfdVersion(NFD_VERSION);
65 status->setStartTimestamp(m_startTimestamp);
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070066 status->setCurrentTimestamp(time::system_clock::now());
Junxiao Shiea48d8b2014-03-16 13:53:47 -070067
68 status->setNNameTreeEntries(m_forwarder.getNameTree().size());
69 status->setNFibEntries(m_forwarder.getFib().size());
70 status->setNPitEntries(m_forwarder.getPit().size());
71 status->setNMeasurementsEntries(m_forwarder.getMeasurements().size());
72 status->setNCsEntries(m_forwarder.getCs().size());
73
74 const ForwarderCounters& counters = m_forwarder.getCounters();
Junxiao Shi6e694322014-04-03 10:27:13 -070075 status->setNInInterests(counters.getNInInterests());
76 status->setNInDatas(counters.getNInDatas());
77 status->setNOutInterests(counters.getNOutInterests());
78 status->setNOutDatas(counters.getNOutDatas());
Junxiao Shiea48d8b2014-03-16 13:53:47 -070079
80 return status;
81}
82
83} // namespace nfd