blob: f8c30d8483b83433a15b096272e8c76533fb31ef [file] [log] [blame]
Junxiao Shi38f4ce92016-08-04 10:01:52 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2016, 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.
10 *
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/>.
24 */
25
Junxiao Shi331ade72016-08-19 14:07:19 +000026#ifndef NFD_TOOLS_NFDC_FORWARDER_GENERAL_MODULE_HPP
27#define NFD_TOOLS_NFDC_FORWARDER_GENERAL_MODULE_HPP
Junxiao Shi38f4ce92016-08-04 10:01:52 +000028
29#include "module.hpp"
30#include <ndn-cxx/security/validator.hpp>
31
32namespace nfd {
33namespace tools {
Junxiao Shi331ade72016-08-19 14:07:19 +000034namespace nfdc {
Junxiao Shi38f4ce92016-08-04 10:01:52 +000035
36using ndn::nfd::ForwarderStatus;
37
38class NfdIdCollector;
39
40/** \brief provides access to NFD forwarder general status
41 * \sa https://redmine.named-data.net/projects/nfd/wiki/ForwarderStatus
42 */
43class ForwarderGeneralModule : public Module, noncopyable
44{
45public:
46 ForwarderGeneralModule();
47
48 virtual void
49 fetchStatus(Controller& controller,
50 const function<void()>& onSuccess,
Junxiao Shi29b41282016-08-22 03:47:02 +000051 const Controller::DatasetFailCallback& onFailure,
Junxiao Shi38f4ce92016-08-04 10:01:52 +000052 const CommandOptions& options) override;
53
54 void
55 setNfdIdCollector(const NfdIdCollector& nfdIdCollector)
56 {
57 m_nfdIdCollector = &nfdIdCollector;
58 }
59
60 virtual void
61 formatStatusXml(std::ostream& os) const override;
62
63 /** \brief format a single status item as XML
64 * \param os output stream
65 * \param item status item
66 * \param nfdId NFD's signing certificate name
67 */
68 void
69 formatItemXml(std::ostream& os, const ForwarderStatus& item, const Name& nfdId) const;
70
71 virtual void
72 formatStatusText(std::ostream& os) const override;
73
74 /** \brief format a single status item as text
75 * \param os output stream
76 * \param item status item
77 * \param nfdId NFD's signing certificate name
78 */
79 void
80 formatItemText(std::ostream& os, const ForwarderStatus& item, const Name& nfdId) const;
81
82private:
83 const Name&
84 getNfdId() const;
85
86private:
87 const NfdIdCollector* m_nfdIdCollector;
88 ForwarderStatus m_status;
89};
90
91
92/** \brief a validator that can collect NFD's signing certificate name
93 *
94 * This validator redirects all validation requests to an inner validator.
95 * For the first Data packet accepted by the inner validator that has a Name in KeyLocator,
96 * this Name is collected as NFD's signing certificate name.
97 */
98class NfdIdCollector : public ndn::Validator
99{
100public:
101 explicit
102 NfdIdCollector(unique_ptr<ndn::Validator> inner);
103
104 bool
105 hasNfdId() const
106 {
107 return m_hasNfdId;
108 }
109
110 const Name&
111 getNfdId() const;
112
113protected:
114 virtual void
115 checkPolicy(const Interest& interest, int nSteps,
116 const ndn::OnInterestValidated& accept,
117 const ndn::OnInterestValidationFailed& reject,
118 std::vector<shared_ptr<ndn::ValidationRequest>>& nextSteps) override
119 {
120 BOOST_ASSERT(nSteps == 0);
121 m_inner->validate(interest, accept, reject);
122 }
123
124 virtual void
125 checkPolicy(const Data& data, int nSteps,
126 const ndn::OnDataValidated& accept,
127 const ndn::OnDataValidationFailed& reject,
128 std::vector<shared_ptr<ndn::ValidationRequest>>& nextSteps) override;
129
130private:
131 unique_ptr<ndn::Validator> m_inner;
132 bool m_hasNfdId;
133 Name m_nfdId;
134};
135
Junxiao Shi331ade72016-08-19 14:07:19 +0000136} // namespace nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000137} // namespace tools
138} // namespace nfd
139
Junxiao Shi331ade72016-08-19 14:07:19 +0000140#endif // NFD_TOOLS_NFDC_FORWARDER_GENERAL_MODULE_HPP