configuration.h 7.24 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

Tomek Mrugalski's avatar
Tomek Mrugalski committed
15 16
#ifndef DHCPSRV_CONFIGURATION_H
#define DHCPSRV_CONFIGURATION_H
17

18
#include <dhcpsrv/cfg_iface.h>
19
#include <dhcpsrv/logging_info.h>
20
#include <boost/shared_ptr.hpp>
21 22
#include <vector>
#include <stdint.h>
23 24 25 26

namespace isc {
namespace dhcp {

27 28
class CfgMgr;

29 30 31 32

/// @brief Specifies current DHCP configuration
///
/// @todo Migrate all other configuration parameters from cfgmgr.h here
33 34
class Configuration {
public:
35 36 37
    /// @name Constants for selection of parameters returned by @c getConfigSummary
    ///
    //@{
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
    /// Nothing selected
    static const uint32_t CFGSEL_NONE    = 0x00000000;
    /// Number of IPv4 subnets
    static const uint32_t CFGSEL_SUBNET4 = 0x00000001;
    /// Number of IPv6 subnets
    static const uint32_t CFGSEL_SUBNET6 = 0x00000002;
    /// Number of enabled ifaces
    static const uint32_t CFGSEL_IFACE4  = 0x00000004;
    /// Number of v6 ifaces
    static const uint32_t CFGSEL_IFACE6  = 0x00000008;
    /// DDNS enabled/disabled
    static const uint32_t CFGSEL_DDNS    = 0x00000010;
    /// Number of all subnets
    static const uint32_t CFGSEL_SUBNET  = 0x00000003;
    /// IPv4 related config
    static const uint32_t CFGSEL_ALL4    = 0x00000015;
    /// IPv6 related config
    static const uint32_t CFGSEL_ALL6    = 0x0000001A;
    /// Whole config
    static const uint32_t CFGSEL_ALL     = 0xFFFFFFFF;
58
    //@}
59

60
    /// @brief Default constructor.
61
    ///
62 63 64 65 66 67 68
    /// This constructor sets configuration sequence number to 0.
    Configuration();

    /// @brief Constructor.
    ///
    /// Sets arbitrary configuration sequence number.
    Configuration(uint32_t sequence);
69

70 71 72
    /// @brief Returns summary of the configuration in the textual format.
    ///
    /// This method returns the brief text describing the current configuration.
73
    /// It may be used for logging purposes, e.g. when the new configuration is
74 75 76 77 78 79
    /// committed to notify a user about the changes in configuration.
    ///
    /// @todo Currently this method uses @c CfgMgr accessors to get the
    /// configuration parameters. Once these parameters are migrated from the
    /// @c CfgMgr this method will have to be modified accordingly.
    ///
80 81 82 83
    /// @todo Implement reporting a summary of interfaces being used for
    /// receiving and sending DHCP messages. This will be implemented with
    /// ticket #3512.
    ///
84 85 86 87 88
    /// @param selection Is a bitfield which describes the parts of the
    /// configuration to be returned.
    ///
    /// @return Summary of the configuration in the textual format.
    std::string getConfigSummary(const uint32_t selection) const;
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106

    /// @brief Returns configuration sequence number.
    uint32_t getSequence() const {
        return (sequence_);
    }

    /// @brief Compares configuration sequence with other sequence.
    ///
    /// This method compares sequence numbers of two configurations for
    /// equality. The sequence numbers are meant to be unique, so if
    /// they are equal it means that they point to the same configuration.
    ///
    /// @param other Configuration which sequence number should be
    /// compared with the sequence number of this configuration.
    ///
    /// @return true if sequence numbers are equal.
    bool sequenceEquals(const Configuration& other);

107 108 109 110 111 112 113 114 115 116 117 118
    /// @brief Returns logging specific configuration.
    const LoggingInfoStorage& getLoggingInfo() const {
        return (logging_info_);
    }

    /// @brief Sets logging specific configuration.
    ///
    /// @param logging_info New logging configuration.
    void addLoggingInfo(const LoggingInfo& logging_info) {
        logging_info_.push_back(logging_info);
    }

119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
    /// @brief Returns object which represents selection of interfaces.
    ///
    /// This function returns a reference to the object which represents the
    /// set of interfaces being used to receive DHCP traffic.
    ///
    /// @return Object representing selection of interfaces.
    const CfgIface& getCfgIface() const {
        return (cfg_iface_);
    }

    /// @brief Sets the object representing selection of interfaces.
    ///
    /// @param cfg_iface Object representing selection of interfaces.
    void setCfgIface(const CfgIface& cfg_iface) {
        cfg_iface_ = cfg_iface;
    }

136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
    /// @name Methods and operators used to compare configurations.
    ///
    //@{
    ///
    /// @brief Compares two objects for equality.
    ///
    /// It ignores the configuration sequence number when checking for
    /// equality of objects.
    ///
    /// @param other An object to be compared with this object.
    ///
    /// @return true if two objects are equal, false otherwise.
    bool equals(const Configuration& other) const;

    /// @brief Compares two objects for inequality.
    ///
    /// It ignores the configuration sequence number when checking for
    /// inequality of objects.
    ///
    /// @param other An object to be compared with this object.
    ///
    /// @return true if two objects are not equal, false otherwise.
    bool nequals(const Configuration& other) const {
        return (!equals(other));
    }

    /// @brief Equality operator.
    ///
    /// It ignores the configuration sequence number when checking for
    /// equality of objects.
    ///
    /// @param other An object to be compared with this object.
    ///
    /// @return true if two objects are equal, false otherwise.
    bool operator==(const Configuration& other) const {
        return (equals(other));
    }

    /// @param other An object to be compared with this object.
    ///
    /// It ignores the configuration sequence number when checking for
    /// inequality of objects.
    ///
    /// @param other An object to be compared with this object.
    ///
    /// @return true if two objects are not equal, false otherwise.
    bool operator!=(const Configuration& other) const {
        return (nequals(other));
    }

    //@}

188 189 190 191 192
private:

    /// @brief Sequence number identifying the configuration.
    uint32_t sequence_;

193 194 195
    /// @brief Logging specific information.
    LoggingInfoStorage logging_info_;

196 197 198 199 200 201
    /// @brief Interface configuration.
    ///
    /// Used to select interfaces on which the DHCP server will listen to
    /// queries.
    CfgIface cfg_iface_;

202 203
};

204 205 206 207
/// @name Pointers to the @c Configuration object.
///
//@{
/// @brief Non-const pointer to the @ Configuration.
208 209
typedef boost::shared_ptr<Configuration> ConfigurationPtr;

210 211 212 213
/// @brief Const pointer to the @c Configuration.
typedef boost::shared_ptr<const Configuration> ConstConfigurationPtr;
//@}

214 215 216
} // namespace isc::dhcp
} // namespace isc

Tomek Mrugalski's avatar
Tomek Mrugalski committed
217
#endif // DHCPSRV_CONFIGURATION_H