blob: 164bb4989a9c01526c6fccee76d934f8e77a05dd [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
44namespace update {
45
46typedef boost::property_tree::ptree ConfigSection;
47
48class PrefixUpdateProcessor : boost::noncopyable
49{
50public:
51 class Error : public std::runtime_error
52 {
53 public:
54 explicit
55 Error(const std::string& what)
56 : std::runtime_error(what)
57 {
58 }
59 };
60
61public:
62 PrefixUpdateProcessor(ndn::Face& face,
63 NamePrefixList& namePrefixList,
64 Lsdb& lsdb,
65 SyncLogicHandler& sync,
66 const ndn::Name broadcastPrefix,
67 ndn::KeyChain& keyChain,
68 ndn::shared_ptr<ndn::CertificateCacheTtl> certificateCache);
69
70 void
71 loadValidator(ConfigSection section, const std::string& filename);
72
73 void
74 startListening();
75
76private:
77 void
78 onInterest(const ndn::Interest& request);
79
80 void
81 sendResponse(const std::shared_ptr<const ndn::Interest>& request,
82 uint32_t code,
83 const std::string& text);
84
85 /** \brief adds desired name prefix to the advertised name prefix list
86 */
87 void
88 advertise(const std::shared_ptr<const ndn::Interest>& request,
89 const ndn::nfd::ControlParameters& parameters);
90
91 /** \brief removes desired name prefix from the advertised name prefix list
92 */
93 void
94 withdraw(const std::shared_ptr<const ndn::Interest>& request,
95 const ndn::nfd::ControlParameters& parameters);
96
97 void
98 onCommandValidated(const std::shared_ptr<const ndn::Interest>& request);
99
100 void
101 onCommandValidationFailed(const std::shared_ptr<const ndn::Interest>& request,
102 const std::string& failureInfo);
103
104 static bool
105 extractParameters(const ndn::name::Component& parameterComponent,
106 ndn::nfd::ControlParameters& extractedParameters);
107
108 bool
109 validateParameters(const ndn::nfd::ControlCommand& command,
110 const ndn::nfd::ControlParameters& parameters);
111
112PUBLIC_WITH_TESTS_ELSE_PRIVATE:
113 Validator&
114 getValidator()
115 {
116 return m_validator;
117 }
118
119private:
120 ndn::Face& m_face;
121 NamePrefixList& m_namePrefixList;
122 Lsdb& m_lsdb;
123 SyncLogicHandler& m_sync;
124 ndn::KeyChain& m_keyChain;
125 Validator m_validator;
126
127 const ndn::Name COMMAND_PREFIX; // /localhost/nlsr/prefix-update
128
129 static const ndn::Name::Component MODULE_COMPONENT;
130 static const ndn::Name::Component ADVERTISE_VERB;
131 static const ndn::Name::Component WITHDRAW_VERB;
132};
133
134} // namespace update
135} // namespace nlsr
136
137#endif // UPDATE_PREFIX_UPDATE_PROCESSOR_HPP