ctrl_agent_cfg_mgr.h 7.4 KB
Newer Older
1
// Copyright (C) 2016-2017 Internet Systems Consortium, Inc. ("ISC")
2
3
4
5
6
7
8
9
//
// 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/.

#ifndef CTRL_AGENT_CFG_MGR_H
#define CTRL_AGENT_CFG_MGR_H

10
#include <cc/data.h>
11
#include <process/d_cfg_mgr.h>
12
#include <boost/pointer_cast.hpp>
13
#include <hooks/libinfo.h>
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

namespace isc {
namespace agent {

class CtrlAgentCfgContext;
/// @brief Pointer to a configuration context.
typedef boost::shared_ptr<CtrlAgentCfgContext> CtrlAgentCfgContextPtr;

/// @brief Control Agent Configuration Context.
///
/// Implement the storage container for configuration context.
/// It provides a single enclosure for the storage of configuration parameters
/// and any other Control Agent specific information that needs to be accessible
/// during configuration parsing as well as to the application as a whole.
/// It is derived from the context base class, DCfgContextBase.
class CtrlAgentCfgContext : public process::DCfgContextBase {
public:
31
32
33
34
35
36
37
38
39
40
41
42
43
44

    /// @brief Default constructor
    CtrlAgentCfgContext();

    /// @brief Specifies type of the server being controlled.
    enum ServerType {
        TYPE_DHCP4 = 0, ///< kea-dhcp4
        TYPE_DHCP6 = 1, ///< kea-dhcp6
        TYPE_D2 = 2     ///< kea-dhcp-ddns
    };

    /// @brief Used check that specified ServerType is within valid range.
    static const uint32_t MAX_TYPE_SUPPORTED = TYPE_D2;

45
46
    /// @brief Creates a clone of this context object.
    ///
47
48
49
    /// Note this method does not do deep copy the information about control sockets.
    /// That data is stored as ConstElementPtr (a shared pointer) to the actual data.
    ///
50
51
52
53
54
    /// @return A pointer to the new clone.
    virtual process::DCfgContextBasePtr clone() {
        return (process::DCfgContextBasePtr(new CtrlAgentCfgContext(*this)));
    }

55
56
    /// @brief Returns information about control socket
    ///
57
58
59
60
61
    /// This method returns Element tree structure that describes the control
    /// socket (or null pointer if the socket is not defined for a particular
    /// server type). This information is expected to be compatible with
    /// data passed to @ref isc::config::CommandMgr::openCommandSocket.
    ///
62
    /// @param type type of the server being controlled
63
64
    /// @return pointer to the Element that holds control-socket map (or NULL)
    const data::ConstElementPtr getControlSocketInfo(ServerType type) const;
65
66
67

    /// @brief Sets information about the control socket
    ///
68
69
70
71
    /// This method stores Element tree structure that describes the control
    /// socket. This information is expected to be compatible with
    /// data passed to @ref isc::config::CommandMgr::openCommandSocket.
    ///
72
73
74
    /// @param control_socket Element that holds control-socket map
    /// @param type type of the server being controlled
    void setControlSocketInfo(const isc::data::ConstElementPtr& control_socket,
75
                              ServerType type);
76

77
    /// @brief Sets http-host parameter
78
    ///
79
80
    /// @param host Hostname or IP address where the agent's HTTP service
    /// will be available.
81
    void setHttpHost(const std::string& host) {
82
83
84
        http_host_ = host;
    }

85
    /// @brief Returns http-host parameter
86
    ///
87
88
    /// @return Hostname or IP address where the agent's HTTP service is
    /// available.
89
    std::string getHttpHost() const {
90
91
92
93
94
        return (http_host_);
    }

    /// @brief Sets http port
    ///
95
    /// @param port sets the TCP port the HTTP server will listen on
96
    void setHttpPort(const uint16_t port) {
97
98
99
        http_port_ = port;
    }

100
    /// @brief Returns the TCP post the HTTP server will listen on
101
    uint16_t getHttpPort() const {
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
        return (http_port_);
    }

    /// @brief Returns a list of hook libraries
    /// @return a list of hook libraries
    const hooks::HookLibsCollection& getLibraries() const {
        return (libraries_);
    }

    /// @brief Sets the list of hook libraries
    ///
    /// @params libs a coolection of libraries to remember.
    void setLibraries(const hooks::HookLibsCollection& libs) {
        libraries_ = libs;
    }


119
private:
120
121
122
123
124
125
126
127
128

    /// @brief Private copy constructor
    ///
    /// It is private to forbid anyone outside of this class to make copies.
    /// The only legal way to copy a context is to call @ref clone().
    ///
    /// @param orig the original context to copy from
    CtrlAgentCfgContext(const CtrlAgentCfgContext& orig);

129
    /// @brief Private assignment operator to avoid potential for slicing.
130
131
    ///
    /// @param rhs Context to be assigned.
132
    CtrlAgentCfgContext& operator=(const CtrlAgentCfgContext& rhs);
133
134
135
136
137
138
139
140
141
142
143
144

    /// Socket information will be stored here (for all supported servers)
    data::ConstElementPtr ctrl_sockets_[MAX_TYPE_SUPPORTED + 1];

    /// Hostname the CA should listen on.
    std::string http_host_;

    /// TCP port the CA should listen on.
    uint16_t http_port_;

    /// List of hook libraries.
    hooks::HookLibsCollection libraries_;
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
};

/// @brief Ctrl Agent Configuration Manager.
///
/// Provides the mechanisms for managing the Control Agent application's
/// configuration.
class CtrlAgentCfgMgr : public process::DCfgMgrBase {
public:

    /// @brief Constructor.
    CtrlAgentCfgMgr();

    /// @brief Destructor
    virtual ~CtrlAgentCfgMgr();

    /// @brief Convenience method that returns the Control Agent configuration
    /// context.
    ///
    /// @return returns a pointer to the configuration context.
    CtrlAgentCfgContextPtr getCtrlAgentCfgContext() {
        return (boost::dynamic_pointer_cast<CtrlAgentCfgContext>(getContext()));
    }

    /// @brief Returns configuration summary in the textual format.
    ///
    /// @param selection Bitfield which describes the parts of the configuration
    /// to be returned. This parameter is ignored for the Control Agent.
    ///
    /// @return Summary of the configuration in the textual format.
    virtual std::string getConfigSummary(const uint32_t selection);

protected:

178
179
180
181
182
183
    /// @brief Parses configuration of the Control Agent.
    ///
    /// @param config Pointer to a configuration specified for the agent.
    /// @param check_only Boolean flag indicating if this method should
    /// only verify correctness of the provided conifiguration.
    /// @return Pointer to a result of configuration parsing.
184
185
186
187
    virtual isc::data::ConstElementPtr
    parse(isc::data::ConstElementPtr config, bool check_only);

    /// @brief This is no longer used.
188
    ///
189
190
    /// @throw NotImplemented
    /// @return nothing, always throws
191
    virtual isc::dhcp::ParserPtr
192
193
    createConfigParser(const std::string&,
                       const isc::data::Element::Position& pos);
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214

    /// @brief Creates a new, blank CtrlAgentCfgContext context.
    ///
    ///
    /// This method is used at the beginning of configuration process to
    /// create a fresh, empty copy of a CtrlAgentCfgContext. This new context
    /// will be populated during the configuration process and will replace the
    /// existing context provided the configuration process completes without
    /// error.
    ///
    /// @return Returns a DCfgContextBasePtr to the new context instance.
    virtual process::DCfgContextBasePtr createNewContext();
};

/// @brief Defines a shared pointer to CtrlAgentCfgMgr.
typedef boost::shared_ptr<CtrlAgentCfgMgr> CtrlAgentCfgMgrPtr;

} // namespace isc::agent
} // namespace isc

#endif // CTRL_AGENT_CFG_MGR_H