duid_config_parser.h 3.09 KB
Newer Older
1
// Copyright (C) 2015,2017 Internet Systems Consortium, Inc. ("ISC")
2
//
3
4
5
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7
8
9
10

#ifndef DUID_CONFIG_PARSER_H
#define DUID_CONFIG_PARSER_H

#include <cc/data.h>
11
#include <cc/simple_parser.h>
12
13
14
15
16
17
#include <stdint.h>
#include <string>

namespace isc {
namespace dhcp {

18
19
20
21
22
23
24
25
/// @brief Parser for server DUID configuration.
///
/// This parser currently supports the following DUID types:
/// - DUID-LLT,
/// - DUID-EN
/// - DUID-LL
///
/// @todo Add support for DUID-UUID in the parser.
26
class DUIDConfigParser : public isc::data::SimpleParser {
27
28
29
public:
    /// @brief Parses DUID configuration.
    ///
30
    /// @param cfg parsed DUID configuration will be stored here
31
32
33
34
    /// @param duid_configuration Data element holding a map representing
    /// DUID configuration.
    ///
    /// @throw DhcpConfigError If the configuration is invalid.
35
    void parse(const CfgDUIDPtr& cfg, isc::data::ConstElementPtr duid_configuration);
36
37
38
39
private:

    /// @brief Validate and set DUID type.
    ///
40
    /// @param cfg parsed information will be stored here
Francis Dupont's avatar
Francis Dupont committed
41
    /// @param duid_type DUID type in textual format.
42
    void setType(const CfgDUIDPtr& cfg, const std::string& duid_type) const;
43
44
45

    /// @brief Validate and set identifier.
    ///
46
    /// @param cfg parsed information will be stored here
47
    /// @param identifier Identifier.
48
    void setIdentifier(const CfgDUIDPtr& cfg, const std::string& identifier) const;
49
50
51

    /// @brief Validate and set hardware type.
    ///
52
    /// @param cfg parsed information will be stored here
53
    /// @param htype Hardware type.
54
    void setHType(const CfgDUIDPtr& cfg, const int64_t htype) const;
55
56
57

    /// @brief Validate and set time value.
    ///
58
    /// @param cfg parsed information will be stored here
59
    /// @param new_time Time value to be used for DUID.
60
    void setTime(const CfgDUIDPtr& cfg, const int64_t new_time) const;
61
62
63

    /// @brief Validate and set enterprise id.
    ///
64
    /// @param cfg parsed information will be stored here
65
    /// @param enterprise_id Enterprise id.
66
    void setEnterpriseId(const CfgDUIDPtr& cfg, const int64_t enterprise_id) const;
67

68
69
    /// @brief Set persistence flag.
    ///
70
    /// @param cfg parsed information will be stored here
71
72
73
    /// @param persist A boolean value indicating if the server
    /// identifier should be stored on the disk (if true) or
    /// not (if false).
74
    void setPersist(const CfgDUIDPtr& cfg, const bool persist);
75

76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
    /// @brief Verifies if the specified parameter is in range.
    ///
    /// Each numeric value must be in range of [0 .. max_value], where
    /// max_value is a maximum value for the numeric type used for this
    /// parameter.
    ///
    /// @param parameter_name Parameter name.
    /// @tparam Numeric type of the specified parameter.
    template<typename NumericType>
    void checkRange(const std::string& parameter_name,
                    const int64_t parameter_value) const;
};

}
} // end of namespace isc

#endif // DUID_CONFIG_PARSER_H