host_reservation_parser.h 7.9 KB

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