blob: 395d161a15ddf72d45196e8d11365062d8305781 [file] [log] [blame]
alvy297f4162015-03-03 17:15:33 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2015, The University of Memphis,
4 * 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
22#ifndef UPDATE_PREFIX_UPDATE_PROCESSOR_HPP
23#define UPDATE_PREFIX_UPDATE_PROCESSOR_HPP
24
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>
31#include <ndn-cxx/management/nfd-control-command.hpp>
32#include <ndn-cxx/management/nfd-control-parameters.hpp>
33#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;
46}
47
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,
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050072 ndn::shared_ptr<ndn::CertificateCacheTtl> certificateCache,
73 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
99 /** \brief adds desired name prefix to the advertised name prefix list
100 */
101 void
102 advertise(const std::shared_ptr<const ndn::Interest>& request,
103 const ndn::nfd::ControlParameters& parameters);
104
105 /** \brief removes desired name prefix from the advertised name prefix list
106 */
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
152#endif // UPDATE_PREFIX_UPDATE_PROCESSOR_HPP