1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-23 17:33:56 +03:00
one/include/IPAMManager.h
2021-02-09 16:07:56 +01:00

154 lines
4.6 KiB
C++

/* -------------------------------------------------------------------------- */
/* Copyright 2002-2021, OpenNebula Project, OpenNebula Systems */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
#ifndef IPAM_MANAGER_H_
#define IPAM_MANAGER_H_
#include <time.h>
#include "ProtocolMessages.h"
#include "DriverManager.h"
#include "Listener.h"
#include "NebulaLog.h"
//Forward definitions
class IPAMRequest;
class VectorAttribute;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
class IPAMManager :
public DriverManager<Driver<ipam_msg_t>>,
public Listener
{
public:
IPAMManager(time_t timer, const std::string mad_location)
: DriverManager(mad_location)
, Listener("IPAM Manager")
, timer_thread(timer, [this](){timer_action();})
{
}
~IPAMManager() = default;
/**
* This functions starts the associated listener thread, and creates a
* new thread for the IPAMManager. This thread will wait in
* an action loop till it receives ACTION_FINALIZE.
* @return 0 on success.
*/
int start();
/**
* Loads IPAM Manager Mads defined in configuration file
* @param _mads configuration of drivers
*/
int load_drivers(const std::vector<const VectorAttribute*>& _mads);
/**
* Register (or requests) a new address range to the IPAM.
*/
void trigger_register_address_range(IPAMRequest& ir);
/**
* Unregisters an address range.
*/
void trigger_unregister_address_range(IPAMRequest& ir);
/**
* Requests the IPAM a free address (or range)
*/
void trigger_get_address(IPAMRequest& ir);
/**
* Requests to set an address (or range) as used
*/
void trigger_allocate_address(IPAMRequest& ir);
/**
* Free an address in the IPAM
*/
void trigger_free_address(IPAMRequest& ir);
private:
/**
* Timer action async execution
*/
Timer timer_thread;
/**
* Generic name for the IPAM driver
*/
static const char * ipam_driver_name;
/**
* Returns a pointer to a IPAM Manager driver. The driver is
* searched by its name.
* @param name the name of the driver
* @return the IPAM driver owned by uid with attribute name equal to value
* or 0 in not found
*/
const Driver<ipam_msg_t> * get() const
{
return DriverManager::get_driver(ipam_driver_name);
}
/**
* This function initializes a request to call the IPAM driver
* @param ir the IPAM request
* @return pointer to the IPAM driver to use, 0 on failure
*/
void send_request(IPAMManagerMessages type, IPAMRequest& ir);
// -------------------------------------------------------------------------
// Protocol implementation, procesing messages from driver
// -------------------------------------------------------------------------
/**
*
*/
static void _undefined(std::unique_ptr<ipam_msg_t> msg);
/**
*
*/
void _notify_request(std::unique_ptr<ipam_msg_t> msg);
/**
*
*/
static void _log(std::unique_ptr<ipam_msg_t> msg);
// -------------------------------------------------------------------------
// Action Listener interface
// -------------------------------------------------------------------------
void timer_action()
{
check_time_outs_action();
}
static const int drivers_timeout = 10;
void finalize_action() override
{
DriverManager::stop(drivers_timeout);
}
};
#endif /*IPAM_MANAGER_H*/