host_reservation_parser.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. // Copyright (C) 2014-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 HOST_RESERVATION_PARSER_H
  7. #define HOST_RESERVATION_PARSER_H
  8. #include <cc/data.h>
  9. #include <cc/simple_parser.h>
  10. #include <dhcpsrv/host.h>
  11. namespace isc {
  12. namespace dhcp {
  13. /// @brief Parser for a single host reservation entry.
  14. class HostReservationParser : public isc::data::SimpleParser {
  15. public:
  16. /// @brief Constructor.
  17. ///
  18. /// @param subnet_id Identifier of the subnet that the host is
  19. /// connected to.
  20. explicit HostReservationParser(const SubnetID& subnet_id);
  21. /// @brief Destructor.
  22. virtual ~HostReservationParser() { }
  23. /// @brief Parses a single entry for host reservation.
  24. ///
  25. /// @param reservation_data Data element holding map with a host
  26. /// reservation configuration.
  27. ///
  28. /// @throw DhcpConfigError If the configuration is invalid.
  29. void parse(isc::data::ConstElementPtr reservation_data);
  30. protected:
  31. /// @brief Parses a single entry for host reservation.
  32. ///
  33. /// This method is called by @ref parse and it can be overriden in the
  34. /// derived classes to provide class specific parsing logic.
  35. ///
  36. /// @param reservation_data Data element holding map with a host
  37. /// reservation configuration.
  38. ///
  39. /// @throw DhcpConfigError If the configuration is invalid.
  40. virtual void parseInternal(isc::data::ConstElementPtr reservation_data);
  41. /// @brief Inserts @c host_ object to the staging configuration.
  42. ///
  43. /// This method should be called by derived classes to insert the fully
  44. /// parsed host reservation configuration to the @c CfgMgr.
  45. ///
  46. /// @param reservation_data Data element holding host reservation. It
  47. /// used by this method to append the line number to the error string.
  48. ///
  49. /// @throw DhcpConfigError When operation to add a configured host fails.
  50. void addHost(isc::data::ConstElementPtr reservation_data);
  51. /// @brief Checks if the specified parameter is a host identifier.
  52. ///
  53. /// @param param_name Parameter name.
  54. ///
  55. /// @return true if the parameter specifies host identifier, false
  56. /// otherwise.
  57. virtual bool isIdentifierParameter(const std::string& param_name) const;
  58. /// @brief Checks if the specified parameter is supported by the parser.
  59. ///
  60. /// @param param_name Parameter name.
  61. ///
  62. /// @return true if the parameter is supported, false otherwise.
  63. virtual bool isSupportedParameter(const std::string& param_name) const;
  64. /// @brief Returns set of the supported parameters.
  65. ///
  66. /// @param identifiers_only Indicates if the function should only
  67. /// return supported host identifiers (if true) or all supported
  68. /// parameters (if false).
  69. ///
  70. /// @return Set of supported parameter names.
  71. virtual const std::set<std::string>&
  72. getSupportedParameters(const bool identifiers_only) const = 0;
  73. /// @brief Identifier of the subnet that the host is connected to.
  74. SubnetID subnet_id_;
  75. /// @brief Holds a pointer to @c Host object representing a parsed
  76. /// host reservation configuration.
  77. HostPtr host_;
  78. };
  79. /// @brief Parser for a single host reservation for DHCPv4.
  80. class HostReservationParser4 : public HostReservationParser {
  81. public:
  82. /// @brief Constructor.
  83. ///
  84. /// @param subnet_id Identifier of the subnet that the host is
  85. /// connected to.
  86. HostReservationParser4(const SubnetID& subnet_id);
  87. protected:
  88. /// @brief Parses a single host reservation for DHCPv4.
  89. ///
  90. /// @param reservation_data Data element holding map with a host
  91. /// reservation configuration.
  92. ///
  93. /// @throw DhcpConfigError If the configuration is invalid.
  94. virtual void parseInternal(isc::data::ConstElementPtr reservation_data);
  95. /// @brief Returns set of the supported parameters for DHCPv4.
  96. ///
  97. /// @param identifiers_only Indicates if the function should only
  98. /// return supported host identifiers (if true) or all supported
  99. /// parameters (if false).
  100. ///
  101. /// @return Set of supported parameter names.
  102. virtual const std::set<std::string>&
  103. getSupportedParameters(const bool identifiers_only) const;
  104. };
  105. /// @brief Parser for a single host reservation for DHCPv6.
  106. class HostReservationParser6 : public HostReservationParser {
  107. public:
  108. /// @brief Constructor.
  109. ///
  110. /// @param subnet_id Identifier of the subnet that the host is
  111. /// connected to.
  112. HostReservationParser6(const SubnetID& subnet_id);
  113. protected:
  114. /// @brief Parses a single host reservation for DHCPv6.
  115. ///
  116. /// @param reservation_data Data element holding map with a host
  117. /// reservation configuration.
  118. ///
  119. /// @throw DhcpConfigError If the configuration is invalid.
  120. virtual void parseInternal(isc::data::ConstElementPtr reservation_data);
  121. /// @brief Returns set of the supported parameters for DHCPv6.
  122. ///
  123. /// @param identifiers_only Indicates if the function should only
  124. /// return supported host identifiers (if true) or all supported
  125. /// parameters (if false).
  126. ///
  127. /// @return Set of supported parameter names.
  128. virtual const std::set<std::string>&
  129. getSupportedParameters(const bool identifiers_only) const;
  130. };
  131. /// @brief Parser for a list of host identifiers.
  132. ///
  133. /// This is a parent parser class for parsing "host-reservation-identifiers"
  134. /// global configuration parmeter. The DHCPv4 and DHCPv6 specific parsers
  135. /// derive from this class.
  136. class HostReservationIdsParser : public isc::data::SimpleParser {
  137. public:
  138. /// @brief Constructor.
  139. HostReservationIdsParser();
  140. /// @brief Destructor.
  141. virtual ~HostReservationIdsParser() { }
  142. /// @brief Parses a list of host identifiers.
  143. ///
  144. /// @param ids_list Data element pointing to an ordered list of host
  145. /// identifier names.
  146. ///
  147. /// @throw DhcpConfigError If specified configuration is invalid.
  148. void parse(isc::data::ConstElementPtr ids_list);
  149. protected:
  150. /// @brief Parses a list of host identifiers.
  151. ///
  152. /// This method is called by @ref parse and it can be overriden in the
  153. /// derived classes to provide class specific parsing logic.
  154. ///
  155. /// @param ids_list Data element pointing to an ordered list of host
  156. /// identifier names.
  157. ///
  158. /// @throw DhcpConfigError If specified configuration is invalid.
  159. virtual void parseInternal(isc::data::ConstElementPtr ids_list);
  160. /// @brief Checks if specified identifier name is supported in the
  161. /// context of the parser.
  162. ///
  163. /// This is abstract method which must be implemented in the derived
  164. /// parser classes for DHCPv4 and DHCPv6.
  165. ///
  166. /// @param id_name Identifier name.
  167. /// @return true if the specified identifier is supported, false
  168. /// otherwise.
  169. virtual bool isSupportedIdentifier(const std::string& id_name) const = 0;
  170. /// @brief Pointer to the object holding configuration.
  171. CfgHostOperationsPtr staging_cfg_;
  172. };
  173. /// @brief Parser for a list of host identifiers for DHCPv4.
  174. class HostReservationIdsParser4 : public HostReservationIdsParser {
  175. public:
  176. /// @brief Constructor.
  177. ///
  178. /// Initializes staging configuration pointer to the one used for DHCPv4
  179. /// configuration.
  180. HostReservationIdsParser4();
  181. protected:
  182. /// @brief Checks if specified identifier name is supported for DHCPv4.
  183. ///
  184. /// @param id_name Identifier name.
  185. /// @return true if the specified identifier is supported, false
  186. /// otherwise.
  187. virtual bool isSupportedIdentifier(const std::string& id_name) const;
  188. };
  189. /// @brief Parser for a list of host identifiers for DHCPv6.
  190. class HostReservationIdsParser6 : public HostReservationIdsParser {
  191. public:
  192. /// @brief Constructor.
  193. ///
  194. /// Initializes staging configuration pointer to the one used for DHCPv6
  195. /// configuration.
  196. HostReservationIdsParser6();
  197. protected:
  198. /// @brief Checks if specified identifier name is supported for DHCPv6.
  199. ///
  200. /// @param id_name Identifier name.
  201. /// @return true if the specified identifier is supported, false
  202. /// otherwise.
  203. virtual bool isSupportedIdentifier(const std::string& id_name) const;
  204. };
  205. }
  206. } // end of namespace isc
  207. #endif // HOST_RESERVATION_PARSER_H