blob: f1a5b50d3a3513e83079d16782514688501dd234 [file] [log] [blame]
alvy297f4162015-03-03 17:15:33 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonc6a85222017-01-03 16:54:34 -06003 * Copyright (c) 2014-2017, The University of Memphis,
alvy297f4162015-03-03 17:15:33 -06004 * Regents of the University of California,
5 * Arizona Board of Regents.
6 *
7 * This file is part of NLSR (Named-data Link State Routing).
8 * See AUTHORS.md for complete list of NLSR authors and contributors.
9 *
10 * NLSR is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
20 **/
21
dmcoomese689dd62017-03-29 11:05:12 -050022#ifndef NLSR_UPDATE_PREFIX_UPDATE_PROCESSOR_HPP
23#define NLSR_UPDATE_PREFIX_UPDATE_PROCESSOR_HPP
alvy297f4162015-03-03 17:15:33 -060024
25#include "name-prefix-list.hpp"
26#include "test-access-control.hpp"
27#include "validator.hpp"
28
29#include <ndn-cxx/face.hpp>
30#include <ndn-cxx/interest.hpp>
Junxiao Shi3e5120c2016-09-10 16:58:34 +000031#include <ndn-cxx/mgmt/nfd/control-command.hpp>
32#include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
alvy297f4162015-03-03 17:15:33 -060033#include <ndn-cxx/security/certificate-cache-ttl.hpp>
34#include <ndn-cxx/security/key-chain.hpp>
35
36#include <boost/noncopyable.hpp>
37#include <boost/property_tree/ptree.hpp>
38
39namespace nlsr {
40
41class Lsdb;
alvy297f4162015-03-03 17:15:33 -060042
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050043namespace security {
44 class CertificateStore;
Nick G97e34942016-07-11 14:46:27 -050045} // namespace security
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050046
alvy297f4162015-03-03 17:15:33 -060047namespace update {
48
49typedef boost::property_tree::ptree ConfigSection;
50
51class PrefixUpdateProcessor : boost::noncopyable
52{
53public:
54 class Error : public std::runtime_error
55 {
56 public:
57 explicit
58 Error(const std::string& what)
59 : std::runtime_error(what)
60 {
61 }
62 };
63
64public:
65 PrefixUpdateProcessor(ndn::Face& face,
66 NamePrefixList& namePrefixList,
67 Lsdb& lsdb,
alvy297f4162015-03-03 17:15:33 -060068 const ndn::Name broadcastPrefix,
69 ndn::KeyChain& keyChain,
dmcoomes9f936662017-03-02 10:33:09 -060070 std::shared_ptr<ndn::CertificateCacheTtl> certificateCache,
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050071 security::CertificateStore& certStore);
alvy297f4162015-03-03 17:15:33 -060072
73 void
74 loadValidator(ConfigSection section, const std::string& filename);
75
76 void
77 startListening();
78
Vince Lehmand33e5bc2015-06-22 15:27:50 -050079 void
80 enable()
81 {
82 m_isEnabled = true;
83 }
84
alvy297f4162015-03-03 17:15:33 -060085private:
86 void
87 onInterest(const ndn::Interest& request);
88
89 void
Vince Lehmand33e5bc2015-06-22 15:27:50 -050090 sendNack(const ndn::Interest& request);
91
92 void
alvy297f4162015-03-03 17:15:33 -060093 sendResponse(const std::shared_ptr<const ndn::Interest>& request,
94 uint32_t code,
95 const std::string& text);
96
Nick G97e34942016-07-11 14:46:27 -050097 /*! \brief adds desired name prefix to the advertised name prefix list
alvy297f4162015-03-03 17:15:33 -060098 */
99 void
100 advertise(const std::shared_ptr<const ndn::Interest>& request,
101 const ndn::nfd::ControlParameters& parameters);
102
Nick G97e34942016-07-11 14:46:27 -0500103 /*! \brief removes desired name prefix from the advertised name prefix list
alvy297f4162015-03-03 17:15:33 -0600104 */
105 void
106 withdraw(const std::shared_ptr<const ndn::Interest>& request,
107 const ndn::nfd::ControlParameters& parameters);
108
109 void
110 onCommandValidated(const std::shared_ptr<const ndn::Interest>& request);
111
112 void
113 onCommandValidationFailed(const std::shared_ptr<const ndn::Interest>& request,
114 const std::string& failureInfo);
115
116 static bool
117 extractParameters(const ndn::name::Component& parameterComponent,
118 ndn::nfd::ControlParameters& extractedParameters);
119
120 bool
121 validateParameters(const ndn::nfd::ControlCommand& command,
122 const ndn::nfd::ControlParameters& parameters);
123
124PUBLIC_WITH_TESTS_ELSE_PRIVATE:
125 Validator&
126 getValidator()
127 {
128 return m_validator;
129 }
130
131private:
132 ndn::Face& m_face;
133 NamePrefixList& m_namePrefixList;
134 Lsdb& m_lsdb;
alvy297f4162015-03-03 17:15:33 -0600135 ndn::KeyChain& m_keyChain;
136 Validator m_validator;
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500137 bool m_isEnabled;
alvy297f4162015-03-03 17:15:33 -0600138
139 const ndn::Name COMMAND_PREFIX; // /localhost/nlsr/prefix-update
140
141 static const ndn::Name::Component MODULE_COMPONENT;
142 static const ndn::Name::Component ADVERTISE_VERB;
143 static const ndn::Name::Component WITHDRAW_VERB;
144};
145
146} // namespace update
147} // namespace nlsr
148
dmcoomese689dd62017-03-29 11:05:12 -0500149#endif // NLSR_UPDATE_PREFIX_UPDATE_PROCESSOR_HPP