manager-base.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NLSR_MANAGER_BASE_HPP
23 #define NLSR_MANAGER_BASE_HPP
24 
25 #include "name-prefix-list.hpp"
26 #include "test-access-control.hpp"
27 #include "lsdb.hpp"
28 #include "nfd-rib-commands.hpp"
30 #include "logger.hpp"
31 
32 #include <ndn-cxx/face.hpp>
33 #include <ndn-cxx/interest.hpp>
34 #include <ndn-cxx/mgmt/nfd/control-command.hpp>
35 #include <ndn-cxx/mgmt/dispatcher.hpp>
36 #include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
37 #include <ndn-cxx/mgmt/nfd/control-response.hpp>
38 
39 #include <boost/noncopyable.hpp>
40 
41 namespace nlsr {
42 
43 class Lsdb;
44 
45 namespace update {
46 
47 enum { PREFIX_FLAG = 1 };
48 
49 class ManagerBase : boost::noncopyable
50 {
51 public:
52  class Error : public std::runtime_error
53  {
54  public:
55  explicit
56  Error(const std::string& what)
57  : std::runtime_error(what)
58  {
59  }
60  };
61 
62 public:
63  ManagerBase(ndn::mgmt::Dispatcher& m_dispatcher,
64  const std::string& module);
65 
66 protected:
69  ndn::PartialName
70  makeRelPrefix(const std::string& verb) const;
71 
75  template<typename T>
76  bool
77  validateParameters(const ndn::mgmt::ControlParameters& parameters)
78  {
79  const ndn::nfd::ControlParameters* castParams =
80  dynamic_cast<const ndn::nfd::ControlParameters*>(&parameters);
81 
82  BOOST_ASSERT(castParams != nullptr);
83  T command;
84  try {
85  command.validateRequest(*castParams);
86  }
87  catch (const ndn::nfd::ControlCommand::ArgumentError& ae) {
88  throw ae;
89  }
90  catch (const std::exception& e) {
91  std::cerr << e.what() << std::endl;
92  return false;
93  }
94  return true;
95  }
96 
97 protected:
98  ndn::mgmt::Dispatcher& m_dispatcher;
99 
100 private:
101  std::string m_module;
102 };
103 
105 {
106 public:
107  CommandManagerBase(ndn::mgmt::Dispatcher& m_dispatcher,
108  NamePrefixList& m_namePrefixList,
109  Lsdb& lsdb,
110  const std::string& module);
111 
112  virtual ~CommandManagerBase() {}
113 
117  void
118  advertiseAndInsertPrefix(const ndn::Name& prefix,
119  const ndn::Interest& interest,
120  const ndn::mgmt::ControlParameters& parameters,
121  const ndn::mgmt::CommandContinuation& done);
122 
126  void
127  withdrawAndRemovePrefix(const ndn::Name& prefix,
128  const ndn::Interest& interest,
129  const ndn::mgmt::ControlParameters& parameters,
130  const ndn::mgmt::CommandContinuation& done);
131 
135  virtual ndn::optional<bool>
136  afterAdvertise(const ndn::Name& prefix) { return ndn::nullopt; }
137 
141  virtual ndn::optional<bool>
142  afterWithdraw(const ndn::Name& prefix) { return ndn::nullopt; }
143 
144 protected:
147 };
148 
149 } // namespace update
150 } // namespace nlsr
151 
152 #endif // NLSR_MANAGER_BASE_HPP
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
bool validateParameters(const ndn::mgmt::ControlParameters &parameters)
validate the parameters for a given command
STL namespace.
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
Error(const std::string &what)
ManagerBase(ndn::mgmt::Dispatcher &m_dispatcher, const std::string &module)
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
Copyright (c) 2014-2019, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
virtual ndn::optional< bool > afterAdvertise(const ndn::Name &prefix)
save an advertised prefix to the nlsr configuration file returns bool from the overridden function wh...
virtual ndn::optional< bool > afterWithdraw(const ndn::Name &prefix)
save an advertised prefix to the nlsr configuration file returns bool from the overridden function wh...
#define PUBLIC_WITH_TESTS_ELSE_PROTECTED
ndn::PartialName makeRelPrefix(const std::string &verb) const
generate the relative prefix for a handler by appending the verb name to the module name ...
ndn::mgmt::Dispatcher & m_dispatcher