| /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| /** |
| * Copyright (c) 2014-2017, The University of Memphis, |
| * Regents of the University of California, |
| * Arizona Board of Regents. |
| * |
| * This file is part of NLSR (Named-data Link State Routing). |
| * See AUTHORS.md for complete list of NLSR authors and contributors. |
| * |
| * NLSR is free software: you can redistribute it and/or modify it under the terms |
| * of the GNU General Public License as published by the Free Software Foundation, |
| * either version 3 of the License, or (at your option) any later version. |
| * |
| * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| * PURPOSE. See the GNU General Public License for more details. |
| * |
| * You should have received a copy of the GNU General Public License along with |
| * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| **/ |
| |
| #ifndef UPDATE_NFD_RIB_COMMAND_PROCESSOR_HPP |
| #define UPDATE_NFD_RIB_COMMAND_PROCESSOR_HPP |
| |
| #include "route/fib.hpp" |
| #include "nfd-rib-commands.hpp" |
| #include "name-prefix-list.hpp" |
| #include "lsdb.hpp" |
| #include "communication/sync-logic-handler.hpp" |
| |
| #include <ndn-cxx/mgmt/nfd/control-command.hpp> |
| #include <ndn-cxx/mgmt/nfd/control-parameters.hpp> |
| #include <ndn-cxx/encoding/tlv-nfd.hpp> |
| |
| #include <boost/noncopyable.hpp> |
| #include <typeinfo> |
| |
| namespace nlsr { |
| namespace update { |
| |
| class NfdRibCommandProcessor : boost::noncopyable |
| { |
| public: |
| class Error : public std::runtime_error |
| { |
| public: |
| explicit |
| Error(const std::string& what) |
| : std::runtime_error(what) |
| { |
| } |
| }; |
| |
| public: |
| NfdRibCommandProcessor(ndn::mgmt::Dispatcher& dispatcher, |
| NamePrefixList& namePrefixes, |
| Lsdb& lsdb, |
| SyncLogicHandler& sync); |
| |
| /*! \brief Registers an Interest filter with face |
| |
| Registers with face an Interest filter that reacts to any |
| interests on COMMAND_PREFIX. |
| */ |
| void |
| startListening(); |
| |
| PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| |
| /*! \brief inserts a prefix into the FIB if parameters is valid. |
| |
| We consider parameters to be valid if origin is set to CLIENT and |
| a name is present. |
| */ |
| void |
| insertPrefix(const ndn::mgmt::ControlParameters& parameters); |
| |
| /*! \brief remove a prefix from the FIB if parameters is valid. |
| |
| We consider parameters to be valid if origin is set to CLIENT and |
| a name is present. |
| */ |
| void |
| removePrefix(const ndn::mgmt::ControlParameters& parameters); |
| |
| /*! \brief uses command's validator to check that parameters is valid. |
| |
| The command's validator's behavior is defined per command. |
| */ |
| template<typename T> |
| bool |
| validateParameters(const ndn::mgmt::ControlParameters& parameters) |
| { |
| BOOST_ASSERT(dynamic_cast<const ndn::nfd::ControlParameters*>(¶meters) != nullptr); |
| const ndn::nfd::ControlParameters& castParams = |
| static_cast<const ndn::nfd::ControlParameters&>(parameters); |
| T command; |
| try { |
| command.validateRequest(castParams); |
| } |
| catch (const ndn::nfd::ControlCommand::ArgumentError& ae) { |
| throw ae; |
| } |
| catch (...) { |
| return false; |
| } |
| return true; |
| } |
| |
| private: |
| template<typename T> |
| bool |
| validate(const ndn::mgmt::ControlParameters& parameters, const ndn::PartialName& command); |
| |
| ndn::mgmt::Dispatcher& m_dispatcher; |
| NamePrefixList& m_namePrefixList; |
| Lsdb& m_lsdb; |
| SyncLogicHandler& m_sync; |
| }; |
| |
| } // namespace update |
| } // namespace nlsr |
| |
| #endif // UPDATE_NFD_RIB_COMMAND_PROCESSOR_HPP |