host_reservation_parser.h 7.4 KB

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