blob: a022b58efc1a3973fad9a0b378ae13bd5cfb8187 [file] [log] [blame]
Nick Gordon4d2c6c02017-01-20 13:18:46 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2017, 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_NFD_RIB_COMMAND_PROCESSOR_HPP
23#define UPDATE_NFD_RIB_COMMAND_PROCESSOR_HPP
24
25#include "route/fib.hpp"
26#include "nfd-rib-commands.hpp"
27#include "name-prefix-list.hpp"
28#include "lsdb.hpp"
29#include "communication/sync-logic-handler.hpp"
30
31#include <ndn-cxx/mgmt/nfd/control-command.hpp>
32#include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
Ashlesh Gawande6fa00d92017-05-19 19:31:44 -050033#include <ndn-cxx/mgmt/dispatcher.hpp>
Nick Gordon4d2c6c02017-01-20 13:18:46 -060034#include <ndn-cxx/encoding/tlv-nfd.hpp>
35
36#include <boost/noncopyable.hpp>
37#include <typeinfo>
38
39namespace nlsr {
40namespace update {
41
42class NfdRibCommandProcessor : boost::noncopyable
43{
44public:
45 class Error : public std::runtime_error
46 {
47 public:
48 explicit
49 Error(const std::string& what)
50 : std::runtime_error(what)
51 {
52 }
53 };
54
55public:
56 NfdRibCommandProcessor(ndn::mgmt::Dispatcher& dispatcher,
57 NamePrefixList& namePrefixes,
58 Lsdb& lsdb,
59 SyncLogicHandler& sync);
60
61 /*! \brief Registers an Interest filter with face
62
63 Registers with face an Interest filter that reacts to any
64 interests on COMMAND_PREFIX.
65 */
66 void
67 startListening();
68
69PUBLIC_WITH_TESTS_ELSE_PRIVATE:
70
71 /*! \brief inserts a prefix into the FIB if parameters is valid.
72
73 We consider parameters to be valid if origin is set to CLIENT and
74 a name is present.
75 */
76 void
77 insertPrefix(const ndn::mgmt::ControlParameters& parameters);
78
79 /*! \brief remove a prefix from the FIB if parameters is valid.
80
81 We consider parameters to be valid if origin is set to CLIENT and
82 a name is present.
83 */
84 void
85 removePrefix(const ndn::mgmt::ControlParameters& parameters);
86
87 /*! \brief uses command's validator to check that parameters is valid.
88
89 The command's validator's behavior is defined per command.
90 */
91 template<typename T>
92 bool
93 validateParameters(const ndn::mgmt::ControlParameters& parameters)
94 {
95 BOOST_ASSERT(dynamic_cast<const ndn::nfd::ControlParameters*>(&parameters) != nullptr);
96 const ndn::nfd::ControlParameters& castParams =
97 static_cast<const ndn::nfd::ControlParameters&>(parameters);
98 T command;
99 try {
100 command.validateRequest(castParams);
101 }
102 catch (const ndn::nfd::ControlCommand::ArgumentError& ae) {
103 throw ae;
104 }
105 catch (...) {
106 return false;
107 }
108 return true;
109 }
110
111private:
112 template<typename T>
113 bool
114 validate(const ndn::mgmt::ControlParameters& parameters, const ndn::PartialName& command);
115
116 ndn::mgmt::Dispatcher& m_dispatcher;
117 NamePrefixList& m_namePrefixList;
118 Lsdb& m_lsdb;
119 SyncLogicHandler& m_sync;
120};
121
122} // namespace update
123} // namespace nlsr
124
125#endif // UPDATE_NFD_RIB_COMMAND_PROCESSOR_HPP