blob: 4f08bc72a13d8e15e6fb0fd74b6450653ded33f6 [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;
42class SyncLogicHandler;
43
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050044namespace security {
45 class CertificateStore;
Nick G97e34942016-07-11 14:46:27 -050046} // namespace security
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050047
alvy297f4162015-03-03 17:15:33 -060048namespace update {
49
50typedef boost::property_tree::ptree ConfigSection;
51
52class PrefixUpdateProcessor : boost::noncopyable
53{
54public:
55 class Error : public std::runtime_error
56 {
57 public:
58 explicit
59 Error(const std::string& what)
60 : std::runtime_error(what)
61 {
62 }
63 };
64
65public:
66 PrefixUpdateProcessor(ndn::Face& face,
67 NamePrefixList& namePrefixList,
68 Lsdb& lsdb,
69 SyncLogicHandler& sync,
70 const ndn::Name broadcastPrefix,
71 ndn::KeyChain& keyChain,
dmcoomes9f936662017-03-02 10:33:09 -060072 std::shared_ptr<ndn::CertificateCacheTtl> certificateCache,
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050073 security::CertificateStore& certStore);
alvy297f4162015-03-03 17:15:33 -060074
75 void
76 loadValidator(ConfigSection section, const std::string& filename);
77
78 void
79 startListening();
80
Vince Lehmand33e5bc2015-06-22 15:27:50 -050081 void
82 enable()
83 {
84 m_isEnabled = true;
85 }
86
alvy297f4162015-03-03 17:15:33 -060087private:
88 void
89 onInterest(const ndn::Interest& request);
90
91 void
Vince Lehmand33e5bc2015-06-22 15:27:50 -050092 sendNack(const ndn::Interest& request);
93
94 void
alvy297f4162015-03-03 17:15:33 -060095 sendResponse(const std::shared_ptr<const ndn::Interest>& request,
96 uint32_t code,
97 const std::string& text);
98
Nick G97e34942016-07-11 14:46:27 -050099 /*! \brief adds desired name prefix to the advertised name prefix list
alvy297f4162015-03-03 17:15:33 -0600100 */
101 void
102 advertise(const std::shared_ptr<const ndn::Interest>& request,
103 const ndn::nfd::ControlParameters& parameters);
104
Nick G97e34942016-07-11 14:46:27 -0500105 /*! \brief removes desired name prefix from the advertised name prefix list
alvy297f4162015-03-03 17:15:33 -0600106 */
107 void
108 withdraw(const std::shared_ptr<const ndn::Interest>& request,
109 const ndn::nfd::ControlParameters& parameters);
110
111 void
112 onCommandValidated(const std::shared_ptr<const ndn::Interest>& request);
113
114 void
115 onCommandValidationFailed(const std::shared_ptr<const ndn::Interest>& request,
116 const std::string& failureInfo);
117
118 static bool
119 extractParameters(const ndn::name::Component& parameterComponent,
120 ndn::nfd::ControlParameters& extractedParameters);
121
122 bool
123 validateParameters(const ndn::nfd::ControlCommand& command,
124 const ndn::nfd::ControlParameters& parameters);
125
126PUBLIC_WITH_TESTS_ELSE_PRIVATE:
127 Validator&
128 getValidator()
129 {
130 return m_validator;
131 }
132
133private:
134 ndn::Face& m_face;
135 NamePrefixList& m_namePrefixList;
136 Lsdb& m_lsdb;
137 SyncLogicHandler& m_sync;
138 ndn::KeyChain& m_keyChain;
139 Validator m_validator;
Vince Lehmand33e5bc2015-06-22 15:27:50 -0500140 bool m_isEnabled;
alvy297f4162015-03-03 17:15:33 -0600141
142 const ndn::Name COMMAND_PREFIX; // /localhost/nlsr/prefix-update
143
144 static const ndn::Name::Component MODULE_COMPONENT;
145 static const ndn::Name::Component ADVERTISE_VERB;
146 static const ndn::Name::Component WITHDRAW_VERB;
147};
148
149} // namespace update
150} // namespace nlsr
151
dmcoomese689dd62017-03-29 11:05:12 -0500152#endif // NLSR_UPDATE_PREFIX_UPDATE_PROCESSOR_HPP