ctrl_dhcp6_srv.h 6.47 KB
Newer Older
Stephen Morris's avatar
Stephen Morris committed
1
// Copyright (C) 2012-2013  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 21
#include <cc/session.h>
#include <config/ccsession.h>
22
#include <dhcp6/dhcp6_srv.h>
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

namespace isc {
namespace dhcp {

/// @brief Controlled version of the DHCPv6 server
///
/// This is a class that is responsible for establishing connection
/// with msqg (receving commands and configuration). This is an extended
/// version of Dhcpv6Srv class that is purely a DHCPv6 server, without
/// external control. ControlledDhcpv6Srv should be used in typical BIND10
/// (i.e. featuring msgq) environment, while Dhcpv6Srv should be used in
/// embedded environments.
///
/// For detailed explanation or relations between main(), ControlledDhcpv6Srv,
/// Dhcpv6Srv and other classes, see \ref dhcpv6Session.
class ControlledDhcpv6Srv : public isc::dhcp::Dhcpv6Srv {
public:

    /// @brief Constructor
    ///
    /// @param port UDP port to be opened for DHCP traffic
44
    ControlledDhcpv6Srv(uint16_t port = DHCP6_SERVER_PORT);
45 46

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

49
    /// @brief Initializes the server.
50
    ///
51 52 53
    /// 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
54
    /// *_backend.cc
55 56 57
    ///
    /// @return true if initialization was successful, false if it failed
    bool init(const std::string& config_file);
58

Tomek Mrugalski's avatar
Tomek Mrugalski committed
59
    /// @brief Performs cleanup, immediately before termination
60
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
61 62 63
    /// This method performs final clean up, just before the Dhcpv6Srv object
    /// is destroyed. The actual behavior is backend dependent. For Bundy
    /// backend, it terminates existing session with msgq. After calling
64
    /// it, no further messages over msgq (commands or configuration updates)
Tomek Mrugalski's avatar
Tomek Mrugalski committed
65
    /// may be received. For JSON backend, it is no-op.
66
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
67
    /// For specific details, see actual implementation in *_backend.cc
68
    void cleanup();
69 70 71 72

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

Tomek Mrugalski's avatar
Tomek Mrugalski committed
73 74 75 76 77 78 79 80
    /// @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.
    ///
    /// @note It never throws.
81
    ///
82 83
    /// @param command Text represenation of the command (e.g. "shutdown")
    /// @param args Optional parameters
84 85 86
    ///
    /// @return status of the command
    static isc::data::ConstElementPtr
Tomek Mrugalski's avatar
Tomek Mrugalski committed
87
    processCommand(const std::string& command, isc::data::ConstElementPtr args);
88

Tomek Mrugalski's avatar
Tomek Mrugalski committed
89
    /// @brief configuration processor
90
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
91 92 93
    /// This is a callback for handling incoming configuration updates.
    /// This method should be called by all configuration backends when the
    /// server is starting up or when configuration has changed.
94 95 96 97 98 99 100 101
    ///
    /// 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
102
    processConfig(isc::data::ConstElementPtr new_config);
103

Tomek Mrugalski's avatar
Tomek Mrugalski committed
104
    /// @brief returns pointer to the sole instance of Dhcpv6Srv
105
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
106 107 108 109 110 111 112
    /// @note may return NULL, if called before server is spawned
    static ControlledDhcpv6Srv* getInstance() {
        return (server_);
    }

protected:
    /// @brief Static pointer to the sole instance of the DHCP server.
113
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
114 115 116
    /// 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_;
117

Tomek Mrugalski's avatar
Tomek Mrugalski committed
118 119
    /// @brief Callback that will be called from iface_mgr when data
    /// is received over control socket.
120 121
    ///
    /// This static callback method is called from IfaceMgr::receive6() method,
Tomek Mrugalski's avatar
Tomek Mrugalski committed
122 123 124
    /// when there is a new command or configuration sent over control socket
    /// (that was sent from msgq if backend is Bundy, or some yet unspecified
    /// sender if the backend is JSON file).
125 126 127 128 129
    static void sessionReader(void);

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

Tomek Mrugalski's avatar
Tomek Mrugalski committed
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
    /// @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);
154

Tomek Mrugalski's avatar
Tomek Mrugalski committed
155 156 157 158 159 160 161 162 163 164 165 166
    /// @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);
167 168 169 170 171 172
};

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

#endif