host_reservation_parser.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef HOST_RESERVATION_PARSER_H
  15. #define HOST_RESERVATION_PARSER_H
  16. #include <cc/data.h>
  17. #include <dhcpsrv/host.h>
  18. #include <dhcpsrv/parsers/dhcp_config_parser.h>
  19. namespace isc {
  20. namespace dhcp {
  21. /// @brief Parser for a single host reservation entry.
  22. class HostReservationParser : public DhcpConfigParser {
  23. public:
  24. /// @brief Constructor.
  25. ///
  26. /// @param subnet_id Identifier of the subnet that the host is
  27. /// connected to.
  28. HostReservationParser(const SubnetID& subnet_id);
  29. /// @brief Parses a single entry for host reservation.
  30. ///
  31. /// @param reservation_data Data element holding map with a host
  32. /// reservation configuration.
  33. ///
  34. /// @throw DhcpConfigError If the configuration is invalid.
  35. virtual void build(isc::data::ConstElementPtr reservation_data);
  36. /// @brief Commit, unused.
  37. virtual void commit() { }
  38. protected:
  39. /// @brief Inserts @c host_ object to the staging configuration.
  40. ///
  41. /// This method should be called by derived classes to insert the fully
  42. /// parsed host reservation configuration to the @c CfgMgr.
  43. ///
  44. /// @param reservation_data Data element holding host reservation. It
  45. /// used by this method to append the line number to the error string.
  46. ///
  47. /// @throw DhcpConfigError When operation to add a configured host fails.
  48. void addHost(isc::data::ConstElementPtr reservation_data);
  49. /// @brief Checks if the specified parameter is supported by the parser.
  50. ///
  51. /// @param param_name Parameter name.
  52. ///
  53. /// @return true if the parameter is supported, false otherwise.
  54. virtual bool isSupportedParameter(const std::string& param_name) const = 0;
  55. /// @brief Identifier of the subnet that the host is connected to.
  56. SubnetID subnet_id_;
  57. /// @brief Holds a pointer to @c Host object representing a parsed
  58. /// host reservation configuration.
  59. HostPtr host_;
  60. };
  61. /// @brief Parser for a single host reservation for DHCPv4.
  62. class HostReservationParser4 : public HostReservationParser {
  63. public:
  64. /// @brief Constructor.
  65. ///
  66. /// @param subnet_id Identifier of the subnet that the host is
  67. /// connected to.
  68. HostReservationParser4(const SubnetID& subnet_id);
  69. /// @brief Parses a single host reservation for DHCPv4.
  70. ///
  71. /// @param reservation_data Data element holding map with a host
  72. /// reservation configuration.
  73. ///
  74. /// @throw DhcpConfigError If the configuration is invalid.
  75. virtual void build(isc::data::ConstElementPtr reservation_data);
  76. protected:
  77. /// @brief Checks if the specified parameter is supported by the parser.
  78. ///
  79. /// @param param_name Parameter name.
  80. ///
  81. /// @return true if the parameter is supported, false otherwise.
  82. virtual bool isSupportedParameter(const std::string& param_name) const;
  83. };
  84. /// @brief Parser for a single host reservation for DHCPv6.
  85. class HostReservationParser6 : public HostReservationParser {
  86. public:
  87. /// @brief Constructor.
  88. ///
  89. /// @param subnet_id Identifier of the subnet that the host is
  90. /// connected to.
  91. HostReservationParser6(const SubnetID& subnet_id);
  92. /// @brief Parses a single host reservation for DHCPv6.
  93. ///
  94. /// @param reservation_data Data element holding map with a host
  95. /// reservation configuration.
  96. ///
  97. /// @throw DhcpConfigError If the configuration is invalid.
  98. virtual void build(isc::data::ConstElementPtr reservation_data);
  99. protected:
  100. /// @brief Checks if the specified parameter is supported by the parser.
  101. ///
  102. /// @param param_name Parameter name.
  103. ///
  104. /// @return true if the parameter is supported, false otherwise.
  105. virtual bool isSupportedParameter(const std::string& param_name) const;
  106. };
  107. }
  108. } // end of namespace isc
  109. #endif // HOST_RESERVATION_PARSER_H