Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 3 | * 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 Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 24 | |
| 25 | #include "status-server.hpp" |
| 26 | #include "fw/forwarder.hpp" |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 27 | #include "version.hpp" |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 28 | |
| 29 | namespace nfd { |
| 30 | |
| 31 | const Name StatusServer::DATASET_PREFIX = "ndn:/localhost/nfd/status"; |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 32 | const time::milliseconds StatusServer::RESPONSE_FRESHNESS = time::milliseconds(5000); |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 33 | |
| 34 | StatusServer::StatusServer(shared_ptr<AppFace> face, Forwarder& forwarder) |
| 35 | : m_face(face) |
| 36 | , m_forwarder(forwarder) |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 37 | , m_startTimestamp(time::system_clock::now()) |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 38 | { |
| 39 | m_face->setInterestFilter(DATASET_PREFIX, bind(&StatusServer::onInterest, this, _2)); |
| 40 | } |
| 41 | |
| 42 | void |
| 43 | StatusServer::onInterest(const Interest& interest) const |
| 44 | { |
| 45 | Name name(DATASET_PREFIX); |
Alexander Afanasyev | 06ae907 | 2014-03-22 23:42:08 -0700 | [diff] [blame] | 46 | name.appendVersion(); |
| 47 | name.appendSegment(0); |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 48 | |
| 49 | shared_ptr<Data> data = make_shared<Data>(name); |
| 50 | data->setFreshnessPeriod(RESPONSE_FRESHNESS); |
| 51 | |
Junxiao Shi | 88d6937 | 2014-03-28 11:52:39 -0700 | [diff] [blame] | 52 | shared_ptr<ndn::nfd::ForwarderStatus> status = this->collectStatus(); |
| 53 | data->setContent(status->wireEncode()); |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 54 | |
| 55 | m_face->sign(*data); |
| 56 | m_face->put(*data); |
| 57 | } |
| 58 | |
Junxiao Shi | 88d6937 | 2014-03-28 11:52:39 -0700 | [diff] [blame] | 59 | shared_ptr<ndn::nfd::ForwarderStatus> |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 60 | StatusServer::collectStatus() const |
| 61 | { |
Junxiao Shi | 88d6937 | 2014-03-28 11:52:39 -0700 | [diff] [blame] | 62 | shared_ptr<ndn::nfd::ForwarderStatus> status = make_shared<ndn::nfd::ForwarderStatus>(); |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 63 | |
| 64 | status->setNfdVersion(NFD_VERSION); |
| 65 | status->setStartTimestamp(m_startTimestamp); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 66 | status->setCurrentTimestamp(time::system_clock::now()); |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 67 | |
| 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 Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 75 | status->setNInInterests(counters.getNInInterests()); |
| 76 | status->setNInDatas(counters.getNInDatas()); |
| 77 | status->setNOutInterests(counters.getNOutInterests()); |
| 78 | status->setNOutDatas(counters.getNOutDatas()); |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 79 | |
| 80 | return status; |
| 81 | } |
| 82 | |
| 83 | } // namespace nfd |