blob: 9aedae38fd13f690a27a7b572f3e58a21af70639 [file] [log] [blame]
alvy297f4162015-03-03 17:15:33 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Saurab Dulal7526cee2018-01-31 18:14:10 +00003 * Copyright (c) 2014-2019, 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
Laqin Fan54a43f02017-03-08 12:31:30 -060025#include "manager-base.hpp"
26#include "prefix-update-commands.hpp"
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050027#include <ndn-cxx/util/io.hpp>
alvy297f4162015-03-03 17:15:33 -060028#include <ndn-cxx/security/key-chain.hpp>
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050029#include <ndn-cxx/util/io.hpp>
alvy297f4162015-03-03 17:15:33 -060030#include <boost/property_tree/ptree.hpp>
Saurab Dulal7526cee2018-01-31 18:14:10 +000031#include <boost/property_tree/info_parser.hpp>
alvy297f4162015-03-03 17:15:33 -060032
33namespace nlsr {
34
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050035namespace security {
36 class CertificateStore;
Nick G97e34942016-07-11 14:46:27 -050037} // namespace security
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050038
alvy297f4162015-03-03 17:15:33 -060039namespace update {
40
41typedef boost::property_tree::ptree ConfigSection;
42
Laqin Fan54a43f02017-03-08 12:31:30 -060043class PrefixUpdateProcessor : public CommandManagerBase
alvy297f4162015-03-03 17:15:33 -060044{
45public:
Laqin Fan54a43f02017-03-08 12:31:30 -060046 PrefixUpdateProcessor(ndn::mgmt::Dispatcher& dispatcher,
Ashlesh Gawande85998a12017-12-07 22:22:13 -060047 ndn::security::ValidatorConfig& validator,
alvy297f4162015-03-03 17:15:33 -060048 NamePrefixList& namePrefixList,
Saurab Dulal7526cee2018-01-31 18:14:10 +000049 Lsdb& lsdb, const std::string& configFileName);
Nick Gordond0a7df32017-05-30 16:44:34 -050050
51 /*! \brief Load the validator's configuration from a section of a
52 * configuration file.
53 * \sa ConfFileProcessor::processConfFile
54 * \sa ConfFileProcessor::processConfSectionSecurity
55 *
56 * Loads the state of the validator for prefix update commands by
57 * reading a section from a configuration file. This function is
58 * expecting the section to be from a Boost property tree object.
59 *
60 * \throws PrefixUpdateProcessor::Error If configuration fails to load successfully
61 */
alvy297f4162015-03-03 17:15:33 -060062 void
63 loadValidator(ConfigSection section, const std::string& filename);
64
Saurab Dulal7526cee2018-01-31 18:14:10 +000065 /*! \brief Add or delete an advertise or withdrawn prefix to the nlsr
66 * configuration file
67 */
68 bool
69 addOrDeletePrefix(const ndn::Name& prefix, bool addPrefix);
70
71 ndn::optional<bool>
72 afterAdvertise(const ndn::Name& prefix);
73
74 ndn::optional<bool>
75 afterWithdraw(const ndn::Name& prefix);
76
77 /*! \brief Check if a prefix exists in the nlsr configuration file */
78 bool
79 checkForPrefixInFile(const std::string prefix);
80
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -050081 ndn::security::ValidatorConfig&
alvy297f4162015-03-03 17:15:33 -060082 getValidator()
83 {
84 return m_validator;
85 }
86
87private:
Laqin Fan54a43f02017-03-08 12:31:30 -060088 /*! \brief an authorization function for prefix-update module and verb(advertise/withdraw)
89 * accept if the verb is advertise/withdraw
90 * reject if the verb is not advertise/withdraw
91 \retval an Authorization function
92 \sa Nlsr::getDispatcher()
93 */
94 ndn::mgmt::Authorization
95 makeAuthorization();
96
97private:
Ashlesh Gawande85998a12017-12-07 22:22:13 -060098 ndn::security::ValidatorConfig& m_validator;
dulalsaurab82a34c22019-02-04 17:31:21 +000099 const std::string& m_confFileNameDynamic;
alvy297f4162015-03-03 17:15:33 -0600100};
101
102} // namespace update
103} // namespace nlsr
104
dmcoomese689dd62017-03-29 11:05:12 -0500105#endif // NLSR_UPDATE_PREFIX_UPDATE_PROCESSOR_HPP