duid_config_parser.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright (C) 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 DUID_CONFIG_PARSER_H
  15. #define DUID_CONFIG_PARSER_H
  16. #include <cc/data.h>
  17. #include <dhcpsrv/parsers/dhcp_config_parser.h>
  18. #include <stdint.h>
  19. #include <string>
  20. namespace isc {
  21. namespace dhcp {
  22. /// @brief Parser for server DUID configuration.
  23. ///
  24. /// This parser currently supports the following DUID types:
  25. /// - DUID-LLT,
  26. /// - DUID-EN
  27. /// - DUID-LL
  28. ///
  29. /// @todo Add support for DUID-UUID in the parser.
  30. class DUIDConfigParser : public DhcpConfigParser {
  31. public:
  32. /// @brief Constructor.
  33. DUIDConfigParser();
  34. /// @brief Parses DUID configuration.
  35. ///
  36. /// @param duid_configuration Data element holding a map representing
  37. /// DUID configuration.
  38. ///
  39. /// @throw DhcpConfigError If the configuration is invalid.
  40. virtual void build(isc::data::ConstElementPtr duid_configuration);
  41. /// @brief Commit, unused.
  42. virtual void commit() { }
  43. private:
  44. /// @brief Validate and set DUID type.
  45. ///
  46. /// @param duid_type DUID type in textfual format.
  47. void setType(const std::string& duid_type) const;
  48. /// @brief Validate and set identifier.
  49. ///
  50. /// @param identifier Identifier.
  51. void setIdentifier(const std::string& identifier) const;
  52. /// @brief Validate and set hardware type.
  53. ///
  54. /// @param htype Hardware type.
  55. void setHType(const int64_t htype) const;
  56. /// @brief Validate and set time value.
  57. ///
  58. /// @param new_time Time value to be used for DUID.
  59. void setTime(const int64_t new_time) const;
  60. /// @brief Validate and set enterprise id.
  61. ///
  62. /// @param enterprise_id Enterprise id.
  63. void setEnterpriseId(const int64_t enterprise_id) const;
  64. /// @brief Verifies if the specified parameter is in range.
  65. ///
  66. /// Each numeric value must be in range of [0 .. max_value], where
  67. /// max_value is a maximum value for the numeric type used for this
  68. /// parameter.
  69. ///
  70. /// @param parameter_name Parameter name.
  71. /// @tparam Numeric type of the specified parameter.
  72. template<typename NumericType>
  73. void checkRange(const std::string& parameter_name,
  74. const int64_t parameter_value) const;
  75. };
  76. }
  77. } // end of namespace isc
  78. #endif // DUID_CONFIG_PARSER_H