ca_cfg_mgr.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. // Copyright (C) 2016-2017 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. #ifndef CTRL_AGENT_CFG_MGR_H
  7. #define CTRL_AGENT_CFG_MGR_H
  8. #include <cc/data.h>
  9. #include <hooks/hooks_config.h>
  10. #include <process/d_cfg_mgr.h>
  11. #include <boost/pointer_cast.hpp>
  12. #include <string>
  13. namespace isc {
  14. namespace agent {
  15. class CtrlAgentCfgContext;
  16. /// @brief Pointer to a configuration context.
  17. typedef boost::shared_ptr<CtrlAgentCfgContext> CtrlAgentCfgContextPtr;
  18. /// @brief Control Agent Configuration Context.
  19. ///
  20. /// Implement the storage container for configuration context.
  21. /// It provides a single enclosure for the storage of configuration parameters
  22. /// and any other Control Agent specific information that needs to be accessible
  23. /// during configuration parsing as well as to the application as a whole.
  24. /// It is derived from the context base class, DCfgContextBase.
  25. class CtrlAgentCfgContext : public process::DCfgContextBase {
  26. public:
  27. /// @brief Default constructor
  28. CtrlAgentCfgContext();
  29. /// @brief Specifies type of the server being controlled.
  30. enum ServerType {
  31. TYPE_DHCP4 = 0, ///< kea-dhcp4
  32. TYPE_DHCP6 = 1, ///< kea-dhcp6
  33. TYPE_D2 = 2 ///< kea-dhcp-ddns
  34. };
  35. /// @brief Used check that specified ServerType is within valid range.
  36. static const uint32_t MAX_TYPE_SUPPORTED = TYPE_D2;
  37. /// @brief Converts service specified as a string to ServerType.
  38. ///
  39. /// @param service Service value as a string: 'dhcp4', 'dhcp6', 'd2'.
  40. static ServerType toServerType(const std::string& service);
  41. /// @brief Creates a clone of this context object.
  42. ///
  43. /// Note this method does not do deep copy the information about control sockets.
  44. /// That data is stored as ConstElementPtr (a shared pointer) to the actual data.
  45. ///
  46. /// @return A pointer to the new clone.
  47. virtual process::DCfgContextBasePtr clone() {
  48. return (process::DCfgContextBasePtr(new CtrlAgentCfgContext(*this)));
  49. }
  50. /// @brief Returns information about control socket
  51. ///
  52. /// This method returns Element tree structure that describes the control
  53. /// socket (or null pointer if the socket is not defined for a particular
  54. /// server type). This information is expected to be compatible with
  55. /// data passed to @ref isc::config::CommandMgr::openCommandSocket.
  56. ///
  57. /// @param type type of the server being controlled
  58. /// @return pointer to the Element that holds control-socket map (or NULL)
  59. const isc::data::ConstElementPtr getControlSocketInfo(ServerType type) const;
  60. /// @brief Sets information about the control socket
  61. ///
  62. /// This method stores Element tree structure that describes the control
  63. /// socket. This information is expected to be compatible with
  64. /// data passed to @ref isc::config::CommandMgr::openCommandSocket.
  65. ///
  66. /// @param control_socket Element that holds control-socket map
  67. /// @param type type of the server being controlled
  68. void setControlSocketInfo(const isc::data::ConstElementPtr& control_socket,
  69. ServerType type);
  70. /// @brief Sets http-host parameter
  71. ///
  72. /// @param host Hostname or IP address where the agent's HTTP service
  73. /// will be available.
  74. void setHttpHost(const std::string& host) {
  75. http_host_ = host;
  76. }
  77. /// @brief Returns http-host parameter
  78. ///
  79. /// @return Hostname or IP address where the agent's HTTP service is
  80. /// available.
  81. std::string getHttpHost() const {
  82. return (http_host_);
  83. }
  84. /// @brief Sets http port
  85. ///
  86. /// @param port sets the TCP port the HTTP server will listen on
  87. void setHttpPort(const uint16_t port) {
  88. http_port_ = port;
  89. }
  90. /// @brief Returns the TCP post the HTTP server will listen on
  91. uint16_t getHttpPort() const {
  92. return (http_port_);
  93. }
  94. /// @brief Returns non-const reference to configured hooks libraries.
  95. ///
  96. /// @return non-const reference to configured hooks libraries.
  97. isc::hooks::HooksConfig& getHooksConfig() {
  98. return (hooks_config_);
  99. }
  100. /// @brief Returns const reference to configured hooks libraries.
  101. ///
  102. /// @return const reference to configured hooks libraries.
  103. const isc::hooks::HooksConfig& getHooksConfig() const {
  104. return (hooks_config_);
  105. }
  106. /// @brief Unparse a configuration object
  107. ///
  108. /// Returns an element which must parse into the same object, i.e.
  109. /// @code
  110. /// for all valid config C parse(parse(C)->toElement()) == parse(C)
  111. /// @endcode
  112. ///
  113. /// @return a pointer to a configuration which can be parsed into
  114. /// the initial configuration object
  115. virtual isc::data::ElementPtr toElement() const;
  116. private:
  117. /// @brief Private copy constructor
  118. ///
  119. /// It is private to forbid anyone outside of this class to make copies.
  120. /// The only legal way to copy a context is to call @ref clone().
  121. ///
  122. /// @param orig the original context to copy from
  123. CtrlAgentCfgContext(const CtrlAgentCfgContext& orig);
  124. /// @brief Private assignment operator to avoid potential for slicing.
  125. ///
  126. /// @param rhs Context to be assigned.
  127. CtrlAgentCfgContext& operator=(const CtrlAgentCfgContext& rhs);
  128. /// Socket information will be stored here (for all supported servers)
  129. isc::data::ConstElementPtr ctrl_sockets_[MAX_TYPE_SUPPORTED + 1];
  130. /// Hostname the CA should listen on.
  131. std::string http_host_;
  132. /// TCP port the CA should listen on.
  133. uint16_t http_port_;
  134. /// @brief Configured hooks libraries.
  135. isc::hooks::HooksConfig hooks_config_;
  136. };
  137. /// @brief Ctrl Agent Configuration Manager.
  138. ///
  139. /// Provides the mechanisms for managing the Control Agent application's
  140. /// configuration.
  141. class CtrlAgentCfgMgr : public process::DCfgMgrBase {
  142. public:
  143. /// @brief Constructor.
  144. CtrlAgentCfgMgr();
  145. /// @brief Destructor
  146. virtual ~CtrlAgentCfgMgr();
  147. /// @brief Convenience method that returns the Control Agent configuration
  148. /// context.
  149. ///
  150. /// @return returns a pointer to the configuration context.
  151. CtrlAgentCfgContextPtr getCtrlAgentCfgContext() {
  152. return (boost::dynamic_pointer_cast<CtrlAgentCfgContext>(getContext()));
  153. }
  154. /// @brief Returns configuration summary in the textual format.
  155. ///
  156. /// @param selection Bitfield which describes the parts of the configuration
  157. /// to be returned. This parameter is ignored for the Control Agent.
  158. ///
  159. /// @return Summary of the configuration in the textual format.
  160. virtual std::string getConfigSummary(const uint32_t selection);
  161. protected:
  162. /// @brief Parses configuration of the Control Agent.
  163. ///
  164. /// @param config Pointer to a configuration specified for the agent.
  165. /// @param check_only Boolean flag indicating if this method should
  166. /// only verify correctness of the provided conifiguration.
  167. /// @return Pointer to a result of configuration parsing.
  168. virtual isc::data::ConstElementPtr
  169. parse(isc::data::ConstElementPtr config, bool check_only);
  170. /// @brief This is no longer used.
  171. ///
  172. /// @throw NotImplemented
  173. /// @return nothing, always throws
  174. virtual isc::dhcp::ParserPtr
  175. createConfigParser(const std::string&,
  176. const isc::data::Element::Position& pos);
  177. /// @brief Creates a new, blank CtrlAgentCfgContext context.
  178. ///
  179. ///
  180. /// This method is used at the beginning of configuration process to
  181. /// create a fresh, empty copy of a CtrlAgentCfgContext. This new context
  182. /// will be populated during the configuration process and will replace the
  183. /// existing context provided the configuration process completes without
  184. /// error.
  185. ///
  186. /// @return Returns a DCfgContextBasePtr to the new context instance.
  187. virtual process::DCfgContextBasePtr createNewContext();
  188. };
  189. /// @brief Defines a shared pointer to CtrlAgentCfgMgr.
  190. typedef boost::shared_ptr<CtrlAgentCfgMgr> CtrlAgentCfgMgrPtr;
  191. } // namespace isc::agent
  192. } // namespace isc
  193. #endif // CTRL_AGENT_CFG_MGR_H