blob: 9fc6a681810c47086d9772e991d3f06101ca3533 [file] [log] [blame]
Junxiao Shi38f4ce92016-08-04 10:01:52 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shib347b7f2017-07-23 14:01:58 +00002/*
3 * Copyright (c) 2014-2017, Regents of the University of California,
Junxiao Shi38f4ce92016-08-04 10:01:52 +00004 * 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
Junxiao Shib347b7f2017-07-23 14:01:58 +000048 void
Junxiao Shi38f4ce92016-08-04 10:01:52 +000049 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
Junxiao Shib347b7f2017-07-23 14:01:58 +000060 void
Junxiao Shi38f4ce92016-08-04 10:01:52 +000061 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
Junxiao Shib347b7f2017-07-23 14:01:58 +000071 void
Junxiao Shi38f4ce92016-08-04 10:01:52 +000072 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.
Junxiao Shib347b7f2017-07-23 14:01:58 +000097 *
98 * \todo #4089 re-implement as v2 ValidationPolicy
Junxiao Shi38f4ce92016-08-04 10:01:52 +000099 */
100class NfdIdCollector : public ndn::Validator
101{
102public:
103 explicit
104 NfdIdCollector(unique_ptr<ndn::Validator> inner);
105
106 bool
107 hasNfdId() const
108 {
109 return m_hasNfdId;
110 }
111
112 const Name&
113 getNfdId() const;
114
115protected:
Junxiao Shib347b7f2017-07-23 14:01:58 +0000116 void
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000117 checkPolicy(const Interest& interest, int nSteps,
118 const ndn::OnInterestValidated& accept,
119 const ndn::OnInterestValidationFailed& reject,
120 std::vector<shared_ptr<ndn::ValidationRequest>>& nextSteps) override
121 {
122 BOOST_ASSERT(nSteps == 0);
123 m_inner->validate(interest, accept, reject);
124 }
125
Junxiao Shib347b7f2017-07-23 14:01:58 +0000126 void
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000127 checkPolicy(const Data& data, int nSteps,
128 const ndn::OnDataValidated& accept,
129 const ndn::OnDataValidationFailed& reject,
130 std::vector<shared_ptr<ndn::ValidationRequest>>& nextSteps) override;
131
132private:
133 unique_ptr<ndn::Validator> m_inner;
134 bool m_hasNfdId;
135 Name m_nfdId;
136};
137
Junxiao Shi331ade72016-08-19 14:07:19 +0000138} // namespace nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000139} // namespace tools
140} // namespace nfd
141
Junxiao Shi331ade72016-08-19 14:07:19 +0000142#endif // NFD_TOOLS_NFDC_FORWARDER_GENERAL_MODULE_HPP