ctrl_dhcp6_srv.h 5.87 KB
Newer Older
Francis Dupont's avatar
Francis Dupont committed
1
// Copyright (C) 2012-2015  Internet Systems Consortium, Inc. ("ISC")
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
//
// 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.

#ifndef CTRL_DHCPV6_SRV_H
#define CTRL_DHCPV6_SRV_H

#include <asiolink/asiolink.h>
19
#include <cc/data.h>
20
#include <cc/command_interpreter.h>
21
#include <dhcp6/dhcp6_srv.h>
22 23 24 25 26 27

namespace isc {
namespace dhcp {

/// @brief Controlled version of the DHCPv6 server
///
28 29
/// This is a class that is responsible for DHCPv6 server being controllable,
/// by reading configuration file from disk.
30 31 32 33 34 35
class ControlledDhcpv6Srv : public isc::dhcp::Dhcpv6Srv {
public:

    /// @brief Constructor
    ///
    /// @param port UDP port to be opened for DHCP traffic
36
    ControlledDhcpv6Srv(uint16_t port = DHCP6_SERVER_PORT);
37 38

    /// @brief Destructor.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
39
    virtual ~ControlledDhcpv6Srv();
40

41
    /// @brief Initializes the server.
42
    ///
43 44 45
    /// Depending on the configuration backend, it establishes msgq session,
    /// reads the JSON file from disk or may perform any other setup
    /// operation. For specific details, see actual implementation in
Tomek Mrugalski's avatar
Tomek Mrugalski committed
46
    /// *_backend.cc
47
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
48 49
    /// This method may throw if initialization fails. Exception types may be
    /// specific to used configuration backend.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
50
    void init(const std::string& config_file);
51

Tomek Mrugalski's avatar
Tomek Mrugalski committed
52
    /// @brief Performs cleanup, immediately before termination
53
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
54
    /// This method performs final clean up, just before the Dhcpv6Srv object
55
    /// is destroyed. Currently it is a no-op.
56
    void cleanup();
57 58 59 60

    /// @brief Initiates shutdown procedure for the whole DHCPv6 server.
    void shutdown();

Tomek Mrugalski's avatar
Tomek Mrugalski committed
61 62 63 64 65 66 67
    /// @brief command processor
    ///
    /// This method is uniform for all config backends. It processes received
    /// command (as a string + JSON arguments). Internally, it's just a
    /// wrapper that calls process*Command() methods and catches exceptions
    /// in them.
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
68 69 70 71 72
    /// Currently supported commands are:
    /// - shutdown
    /// - libreload
    /// - config-reload
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
73
    /// @note It never throws.
74
    ///
75
    /// @param command Text representation of the command (e.g. "shutdown")
76
    /// @param args Optional parameters
77 78 79
    ///
    /// @return status of the command
    static isc::data::ConstElementPtr
Tomek Mrugalski's avatar
Tomek Mrugalski committed
80
    processCommand(const std::string& command, isc::data::ConstElementPtr args);
81

Tomek Mrugalski's avatar
Tomek Mrugalski committed
82
    /// @brief configuration processor
83
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
84
    /// This is a method for handling incoming configuration updates.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
85 86
    /// This method should be called by all configuration backends when the
    /// server is starting up or when configuration has changed.
87 88 89 90 91 92 93 94
    ///
    /// As pointer to this method is used a callback in ASIO used in
    /// ModuleCCSession, it has to be static.
    ///
    /// @param new_config textual representation of the new configuration
    ///
    /// @return status of the config update
    static isc::data::ConstElementPtr
Tomek Mrugalski's avatar
Tomek Mrugalski committed
95
    processConfig(isc::data::ConstElementPtr new_config);
96

Tomek Mrugalski's avatar
Tomek Mrugalski committed
97
    /// @brief returns pointer to the sole instance of Dhcpv6Srv
98
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
99
    /// @return server instance (may return NULL, if called before server is spawned)
Tomek Mrugalski's avatar
Tomek Mrugalski committed
100 101 102 103 104 105
    static ControlledDhcpv6Srv* getInstance() {
        return (server_);
    }

protected:
    /// @brief Static pointer to the sole instance of the DHCP server.
106
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
107 108 109
    /// This is required for config and command handlers to gain access to
    /// the server. Some of them need to be static methods.
    static ControlledDhcpv6Srv* server_;
110

Tomek Mrugalski's avatar
Tomek Mrugalski committed
111 112
    /// @brief Callback that will be called from iface_mgr when data
    /// is received over control socket.
113 114
    ///
    /// This static callback method is called from IfaceMgr::receive6() method,
Tomek Mrugalski's avatar
Tomek Mrugalski committed
115
    /// when there is a new command or configuration sent over control socket
116
    /// (that was sent from some yet unspecified sender).
117 118 119 120 121
    static void sessionReader(void);

    /// @brief IOService object, used for all ASIO operations.
    isc::asiolink::IOService io_service_;

Tomek Mrugalski's avatar
Tomek Mrugalski committed
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
    /// @brief handler for processing 'shutdown' command
    ///
    /// This handler processes shutdown command, which initializes shutdown
    /// procedure.
    /// @param command (parameter ignored)
    /// @param args (parameter ignored)
    ///
    /// @return status of the command
    isc::data::ConstElementPtr
    commandShutdownHandler(const std::string& command,
                           isc::data::ConstElementPtr args);

    /// @brief handler for processing 'libreload' command
    ///
    /// This handler processes libreload command, which unloads all hook
    /// libraries and reloads them.
    ///
    /// @param command (parameter ignored)
    /// @param args (parameter ignored)
    ///
    /// @return status of the command
    isc::data::ConstElementPtr
    commandLibReloadHandler(const std::string& command,
                            isc::data::ConstElementPtr args);
146

Tomek Mrugalski's avatar
Tomek Mrugalski committed
147 148 149 150 151 152 153 154 155 156 157 158
    /// @brief handler for processing 'config-reload' command
    ///
    /// This handler processes config-reload command, which processes
    /// configuration specified in args parameter.
    ///
    /// @param command (parameter ignored)
    /// @param args configuration to be processed
    ///
    /// @return status of the command
    isc::data::ConstElementPtr
    commandConfigReloadHandler(const std::string& command,
                               isc::data::ConstElementPtr args);
159 160 161 162 163 164
};

}; // namespace isc::dhcp
}; // namespace isc

#endif