2016-08-18 14:30:31 +03:00
/* -------------------------------------------------------------------------- */
2023-01-09 14:23:19 +03:00
/* Copyright 2002-2023, OpenNebula Project, OpenNebula Systems */
2016-08-18 14:30:31 +03:00
/* */
/* 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>
2020-06-29 13:14:00 +03:00
# include "ProtocolMessages.h"
# include "DriverManager.h"
2020-07-24 17:00:59 +03:00
# include "Listener.h"
2016-08-18 14:30:31 +03:00
//Forward definitions
class IPAMRequest ;
2020-06-29 13:14:00 +03:00
class VectorAttribute ;
2016-08-18 14:30:31 +03:00
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
2020-06-29 13:14:00 +03:00
class IPAMManager :
public DriverManager < Driver < ipam_msg_t > > ,
2020-07-24 17:00:59 +03:00
public Listener
2016-08-18 14:30:31 +03:00
{
public :
2023-01-31 15:46:09 +03:00
IPAMManager ( time_t timer , const std : : string & mad_location )
2020-07-24 17:00:59 +03:00
: DriverManager ( mad_location )
, Listener ( " IPAM Manager " )
, timer_thread ( timer , [ this ] ( ) { timer_action ( ) ; } )
2016-08-18 14:30:31 +03:00
{
2017-02-03 16:19:15 +03:00
}
2016-08-18 14:30:31 +03:00
2020-07-24 17:00:59 +03:00
~ IPAMManager ( ) = default ;
2016-08-18 14:30:31 +03:00
/**
* 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
2020-06-29 13:14:00 +03:00
* @ param _mads configuration of drivers
2016-08-18 14:30:31 +03:00
*/
2020-06-29 13:14:00 +03:00
int load_drivers ( const std : : vector < const VectorAttribute * > & _mads ) ;
2016-08-18 14:30:31 +03:00
/**
2020-07-24 17:00:59 +03:00
* Register ( or requests ) a new address range to the IPAM .
2016-08-18 14:30:31 +03:00
*/
2020-07-24 17:00:59 +03:00
void trigger_register_address_range ( IPAMRequest & ir ) ;
2016-08-18 14:30:31 +03:00
/**
2020-07-24 17:00:59 +03:00
* Unregisters an address range .
2016-08-18 14:30:31 +03:00
*/
2020-07-24 17:00:59 +03:00
void trigger_unregister_address_range ( IPAMRequest & ir ) ;
2016-08-18 14:30:31 +03:00
/**
2020-07-24 17:00:59 +03:00
* Requests the IPAM a free address ( or range )
2016-08-18 14:30:31 +03:00
*/
2020-07-24 17:00:59 +03:00
void trigger_get_address ( IPAMRequest & ir ) ;
2016-08-18 14:30:31 +03:00
/**
2020-07-24 17:00:59 +03:00
* Requests to set an address ( or range ) as used
2016-08-18 14:30:31 +03:00
*/
2020-07-24 17:00:59 +03:00
void trigger_allocate_address ( IPAMRequest & ir ) ;
2016-08-18 14:30:31 +03:00
/**
2020-07-24 17:00:59 +03:00
* Free an address in the IPAM
2016-08-18 14:30:31 +03:00
*/
2020-07-24 17:00:59 +03:00
void trigger_free_address ( IPAMRequest & ir ) ;
2022-04-09 15:48:15 +03:00
/**
* Call vnet_create action
*/
void trigger_vnet_create ( int vnid , const std : : string & xml64 ) ;
/**
* Call vnet_create action
*/
void trigger_vnet_delete ( int vnid , const std : : string & xml64 ) ;
2020-07-24 17:00:59 +03:00
private :
/**
* Timer action async execution
*/
Timer timer_thread ;
2016-08-18 14:30:31 +03:00
/**
* Generic name for the IPAM driver
*/
2020-07-24 17:00:59 +03:00
static const char * ipam_driver_name ;
2016-08-18 14:30:31 +03:00
/**
* 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
*/
2020-07-05 23:01:32 +03:00
const Driver < ipam_msg_t > * get ( ) const
2016-08-18 14:30:31 +03:00
{
2020-06-29 13:14:00 +03:00
return DriverManager : : get_driver ( ipam_driver_name ) ;
2020-07-24 17:00:59 +03:00
}
2016-08-18 14:30:31 +03:00
/**
* This function initializes a request to call the IPAM driver
2022-04-09 15:48:15 +03:00
* @ param type Message type
2016-08-18 14:30:31 +03:00
* @ param ir the IPAM request
*/
2020-07-24 17:00:59 +03:00
void send_request ( IPAMManagerMessages type , IPAMRequest & ir ) ;
2017-02-03 16:19:15 +03:00
2022-04-09 15:48:15 +03:00
/**
* This function send an action message to IPAM driver
* @ param type Message type
* @ param oid Object ID
* @ param xml Object xml data
*/
void send_message ( IPAMManagerMessages type ,
int oid ,
const std : : string & xml ) ;
2020-06-29 13:14:00 +03:00
// -------------------------------------------------------------------------
// Protocol implementation, procesing messages from driver
// -------------------------------------------------------------------------
/**
*
*/
2020-07-02 23:42:10 +03:00
static void _undefined ( std : : unique_ptr < ipam_msg_t > msg ) ;
2020-06-29 13:14:00 +03:00
/**
*
*/
2020-07-02 23:42:10 +03:00
void _notify_request ( std : : unique_ptr < ipam_msg_t > msg ) ;
2020-06-29 13:14:00 +03:00
2022-04-09 15:48:15 +03:00
void _vnet_create ( std : : unique_ptr < ipam_msg_t > msg ) ;
void _vnet_delete ( std : : unique_ptr < ipam_msg_t > msg ) ;
2020-06-29 13:14:00 +03:00
/**
*
*/
2020-07-02 23:42:10 +03:00
static void _log ( std : : unique_ptr < ipam_msg_t > msg ) ;
2020-06-29 13:14:00 +03:00
2017-02-03 16:19:15 +03:00
// -------------------------------------------------------------------------
// Action Listener interface
// -------------------------------------------------------------------------
2020-07-24 17:00:59 +03:00
void timer_action ( )
2017-02-03 16:19:15 +03:00
{
check_time_outs_action ( ) ;
2020-07-24 17:00:59 +03:00
}
2017-02-03 16:19:15 +03:00
2020-06-29 13:14:00 +03:00
static const int drivers_timeout = 10 ;
2020-07-24 17:00:59 +03:00
void finalize_action ( ) override
2017-02-03 16:19:15 +03:00
{
2020-06-29 13:14:00 +03:00
DriverManager : : stop ( drivers_timeout ) ;
2020-07-24 17:00:59 +03:00
}
2016-08-18 14:30:31 +03:00
} ;
# endif /*IPAM_MANAGER_H*/