host_reservation_parser.h 5.53 KB
Newer Older
1
// Copyright (C) 2014-2016 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 11

#ifndef HOST_RESERVATION_PARSER_H
#define HOST_RESERVATION_PARSER_H

#include <cc/data.h>
#include <dhcpsrv/host.h>
12
#include <dhcpsrv/parsers/dhcp_config_parser.h>
13 14 15 16 17 18 19 20

namespace isc {
namespace dhcp {

/// @brief Parser for a single host reservation entry.
class HostReservationParser : public DhcpConfigParser {
public:

21 22 23 24 25
    /// @brief Constructor.
    ///
    /// @param subnet_id Identifier of the subnet that the host is
    /// connected to.
    HostReservationParser(const SubnetID& subnet_id);
26 27 28 29 30 31 32 33 34 35 36 37 38 39

    /// @brief Parses a single entry for host reservation.
    ///
    /// @param reservation_data Data element holding map with a host
    /// reservation configuration.
    ///
    /// @throw DhcpConfigError If the configuration is invalid.
    virtual void build(isc::data::ConstElementPtr reservation_data);

    /// @brief Commit, unused.
    virtual void commit() { }

protected:

40 41 42 43 44 45 46 47 48 49 50
    /// @brief Inserts @c host_ object to the staging configuration.
    ///
    /// This method should be called by derived classes to insert the fully
    /// parsed host reservation configuration to the @c CfgMgr.
    ///
    /// @param reservation_data Data element holding host reservation. It
    /// used by this method to append the line number to the error string.
    ///
    /// @throw DhcpConfigError When operation to add a configured host fails.
    void addHost(isc::data::ConstElementPtr reservation_data);

51 52 53 54 55 56 57 58
    /// @brief Checks if the specified parameter is a host identifier.
    ///
    /// @param param_name Parameter name.
    ///
    /// @return true if the parameter specifies host identifier, false
    /// otherwise.
    virtual bool isIdentifierParameter(const std::string& param_name) const = 0;

59 60 61 62 63
    /// @brief Checks if the specified parameter is supported by the parser.
    ///
    /// @param param_name Parameter name.
    ///
    /// @return true if the parameter is supported, false otherwise.
64 65 66 67 68 69 70 71 72 73 74
    virtual bool isSupportedParameter(const std::string& param_name) const;

    /// @brief Returns set of the supported parameters.
    ///
    /// @param identifiers_only Indicates if the function should only
    /// return supported host identifiers (if true) or all supported
    /// parameters (if false).
    ///
    /// @return Set of supported parameter names.
    virtual const std::set<std::string>&
    getSupportedParameters(const bool identifiers_only) const = 0;
75

76 77 78
    /// @brief Identifier of the subnet that the host is connected to.
    SubnetID subnet_id_;

79 80 81 82 83 84
    /// @brief Holds a pointer to @c Host object representing a parsed
    /// host reservation configuration.
    HostPtr host_;

};

85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
/// @brief Parser for a single host reservation for DHCPv4.
class HostReservationParser4 : public HostReservationParser {
public:

    /// @brief Constructor.
    ///
    /// @param subnet_id Identifier of the subnet that the host is
    /// connected to.
    HostReservationParser4(const SubnetID& subnet_id);

    /// @brief Parses a single host reservation for DHCPv4.
    ///
    /// @param reservation_data Data element holding map with a host
    /// reservation configuration.
    ///
    /// @throw DhcpConfigError If the configuration is invalid.
    virtual void build(isc::data::ConstElementPtr reservation_data);
102 103 104

protected:

105
    /// @brief Checks if the specified parameter is a host identifier.
106 107 108
    ///
    /// @param param_name Parameter name.
    ///
109 110 111 112 113 114 115 116 117 118 119 120 121 122
    /// @return true if the parameter specifies host identifier, false
    /// otherwise.
    virtual bool isIdentifierParameter(const std::string& param_name) const;

    /// @brief Returns set of the supported parameters for DHCPv4.
    ///
    /// @param identifiers_only Indicates if the function should only
    /// return supported host identifiers (if true) or all supported
    /// parameters (if false).
    ///
    /// @return Set of supported parameter names.
    virtual const std::set<std::string>&
    getSupportedParameters(const bool identifiers_only) const;

123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
};

/// @brief Parser for a single host reservation for DHCPv6.
class HostReservationParser6 : public HostReservationParser {
public:

    /// @brief Constructor.
    ///
    /// @param subnet_id Identifier of the subnet that the host is
    /// connected to.
    HostReservationParser6(const SubnetID& subnet_id);

    /// @brief Parses a single host reservation for DHCPv6.
    ///
    /// @param reservation_data Data element holding map with a host
    /// reservation configuration.
    ///
    /// @throw DhcpConfigError If the configuration is invalid.
    virtual void build(isc::data::ConstElementPtr reservation_data);
142 143 144

protected:

145
    /// @brief Checks if the specified parameter is a host identifier.
146 147 148
    ///
    /// @param param_name Parameter name.
    ///
149 150 151 152 153 154 155 156 157 158 159 160 161 162
    /// @return true if the parameter specifies host identifier, false
    /// otherwise.
    virtual bool isIdentifierParameter(const std::string& param_name) const;

    /// @brief Returns set of the supported parameters for DHCPv6.
    ///
    /// @param identifiers_only Indicates if the function should only
    /// return supported host identifiers (if true) or all supported
    /// parameters (if false).
    ///
    /// @return Set of supported parameter names.
    virtual const std::set<std::string>&
    getSupportedParameters(const bool identifiers_only) const;

163 164 165
};


166 167 168 169
}
} // end of namespace isc

#endif // HOST_RESERVATION_PARSER_H