1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-22 22:03:39 +03:00

Merge branch 'bug-4376' into remove-xen

This commit is contained in:
Ruben S. Montero 2016-04-06 18:23:56 +02:00
commit 7816a7912b
8 changed files with 461 additions and 152 deletions

View File

@ -45,6 +45,66 @@ class VirtualNetwork : public PoolObjectSQL, public Clusterable
{
public:
/**
* Defines the Virtual Network type based on its associated driver
*/
enum VirtualNetworkDriver
{
NONE = 0,
DUMMY = 1,
VLAN = 2,
EBTABLES = 3,
FW = 4,
OVSWITCH = 5,
VXLAN = 6
};
static string driver_to_str(VirtualNetworkDriver ob)
{
switch (ob)
{
case NONE: return "";
case DUMMY: return "dummy";
case VLAN: return "802.1Q";
case EBTABLES: return "ebtables";
case FW: return "fw";
case OVSWITCH: return "ovswtich";
case VXLAN: return "vxlan";
}
};
static VirtualNetworkDriver str_to_driver(const string& ob)
{
if ( ob == "dummy" )
{
return DUMMY;
}
else if ( ob == "802.1Q" )
{
return VLAN;
}
else if ( ob == "ebtables" )
{
return EBTABLES;
}
else if ( ob == "fw" )
{
return FW;
}
else if ( ob == "ovswtich" )
{
return OVSWITCH;
}
else if ( ob == "vxlan" )
{
return VXLAN;
}
else
{
return NONE;
}
};
// *************************************************************************
// Virtual Network Public Methods
// *************************************************************************

View File

@ -19,6 +19,7 @@
#include "PoolSQL.h"
#include "VirtualNetwork.h"
#include "BitMap.h"
#include <time.h>
@ -36,10 +37,14 @@ public:
VirtualNetworkPool(SqlDB * db, const string& str_mac_prefix, int default_size,
vector<const SingleAttribute *>& restricted_attrs,
vector<const VectorAttribute *>& hook_mads, const string& remotes_location,
const vector<const SingleAttribute *>& _inherit_attrs);
const vector<const SingleAttribute *>& _inherit_attrs,
const VectorAttribute * vlan_conf, const VectorAttribute * vxlan_conf);
~VirtualNetworkPool(){};
//--------------------------------------------------------------------------
// Virtual Network DB access functions
//--------------------------------------------------------------------------
/**
* Function to allocate a new VNET object
* @param uid user identifier
@ -65,6 +70,16 @@ public:
const set<int> &cluster_ids,
string& error_str);
/**
* Drops a Virtual Network and the associated VLAN_ID if needed
*/
int drop(VirtualNetwork * vn, string& error_msg)
{
release_vlan_id(vn);
return PoolSQL::drop(vn, error_msg);
};
/**
* Function to get a VN from the pool, if the object is not in memory
* it is loaded from the DB
@ -91,48 +106,20 @@ public:
return static_cast<VirtualNetwork *>(PoolSQL::get(name,uid,lock));
};
//--------------------------------------------------------------------------
// Virtual Network DB access functions
//--------------------------------------------------------------------------
/**
* Generates a NIC attribute for VM templates using the VirtualNetwork
* metadata
* @param nic the nic attribute to be generated
* @param nic_id the id for this NIC
* @param uid of the VM owner
* @param vid of the VM requesting the lease
* @param error_str string describing the error
* @return 0 on success,
* -1 error,
* -2 not using the pool
*/
int nic_attribute(
PoolObjectSQL::ObjectType ot,
VectorAttribute* nic,
int nic_id,
int uid,
int vid,
string& error_str);
/**
* Generates an Authorization token for a NIC attribute
* @param nic the nic to be authorized
* @param ar the AuthRequest
*/
void authorize_nic(
PoolObjectSQL::ObjectType ot,
VectorAttribute * nic,
int uid,
AuthRequest * ar);
/**
* Bootstraps the database table(s) associated to the VirtualNetwork pool
* @return 0 on success
*/
static int bootstrap(SqlDB * _db)
{
return VirtualNetwork::bootstrap(_db);
ostringstream oss;
int rc;
rc = VirtualNetwork::bootstrap(_db);
rc += _db->exec(BitMap<0>::bootstrap(vlan_table, oss));
return rc;
};
/**
@ -179,22 +166,113 @@ public:
return PoolSQL::search(oids, VirtualNetwork::table, where);
};
//--------------------------------------------------------------------------
// NIC Attribute build functions
//--------------------------------------------------------------------------
/**
* Generates a NIC attribute for VM templates using the VirtualNetwork
* metadata
* @param nic the nic attribute to be generated
* @param nic_id the id for this NIC
* @param uid of the VM owner
* @param vid of the VM requesting the lease
* @param error_str string describing the error
* @return 0 on success,
* -1 error,
* -2 not using the pool
*/
int nic_attribute(
PoolObjectSQL::ObjectType ot,
VectorAttribute* nic,
int nic_id,
int uid,
int vid,
string& error_str);
/**
* Generates an Authorization token for a NIC attribute
* @param nic the nic to be authorized
* @param ar the AuthRequest
*/
void authorize_nic(
PoolObjectSQL::ObjectType ot,
VectorAttribute * nic,
int uid,
AuthRequest * ar);
private:
/**
* Holds the system-wide MAC prefix
*/
static unsigned int _mac_prefix;
static unsigned int _mac_prefix;
/**
* Default size for Virtual Networks
*/
static unsigned int _default_size;
static unsigned int _default_size;
/**
* VNet attributes to be injected into the VM nic
*/
vector<string> inherit_attrs;
/**
* Configuration attributes for the vlan_id pool
*/
const VectorAttribute vlan_conf;
/**
* Bitmap with vlan_id in use for the 802.1Q driver
*/
BitMap<4096> vlan_id_bitmap;
/**
* ID for the VLAN_BITMAP, to store it in the DB
*/
static const int VLAN_BITMAP_ID;
/**
* Configuration attributes for the vxlan_id pool
*/
const VectorAttribute vxlan_conf;
/**
* Virtual Network bitmap pool for VLANs table
*/
static const char * vlan_table;
//--------------------------------------------------------------------------
// NIC Attribute build functions
//--------------------------------------------------------------------------
/**
* Function to get a VirtualNetwork by its name, as provided by a VM
* template
*/
VirtualNetwork * get_nic_by_name(VectorAttribute * nic,
const string& name,
int _uidi,
string& error);
/**
* Function to get a VirtualNetwork by its id, as provided by a VM template
*/
VirtualNetwork * get_nic_by_id(const string& id_s, string& error);
//--------------------------------------------------------------------------
// VLAN ID management functions
//--------------------------------------------------------------------------
/**
* Gets a free VLAN_ID, if not set by the user, and for VXLAN, VLAN and
* OVSWTICH networks.
* @param vn pointer to the network
* @return 0 on success
*/
int set_vlan_id(VirtualNetwork * vn);
/**
* Free a previously allocated VLAN ID if needed
* @param vn pointer to the network
*/
void release_vlan_id(VirtualNetwork *vn);
/**
* Factory method to produce VN objects
* @return a pointer to the new VN
@ -204,20 +282,6 @@ private:
set <int> empty;
return new VirtualNetwork(-1,-1,"","",0,-1,empty,0);
};
/**
* Function to get a VirtualNetwork by its name, as provided by a VM
* template
*/
VirtualNetwork * get_nic_by_name(VectorAttribute * nic,
const string& name,
int _uidi,
string& error);
/**
* Function to get a VirtualNetwork by its id, as provided by a VM template
*/
VirtualNetwork * get_nic_by_id(const string& id_s, string& error);
};
#endif /*VIRTUAL_NETWORK_POOL_H_*/

View File

@ -56,8 +56,8 @@
#*******************************************************************************
LOG = [
system = "file",
debug_level = 3
SYSTEM = "file",
DEBUG_LEVEL = 3
]
#MANAGER_TIMER = 15
@ -78,19 +78,19 @@ PORT = 2633
LISTEN_ADDRESS = "0.0.0.0"
DB = [ backend = "sqlite" ]
DB = [ BACKEND = "sqlite" ]
# Sample configuration for MySQL
# DB = [ backend = "mysql",
# server = "localhost",
# port = 0,
# user = "oneadmin",
# passwd = "oneadmin",
# db_name = "opennebula" ]
# DB = [ BACKEND = "mysql",
# SERVER = "localhost",
# PORT = 0,
# USER = "oneadmin",
# PASSWD = "oneadmin",
# DB_NAME = "opennebula" ]
VNC_PORTS = [
start = 5900
# reserved = "6800, 6801, 9869"
START = 5900
# RESERVED = "6800, 6801, 9869"
]
#VM_SUBMIT_ON_HOLD = "NO"
@ -112,9 +112,9 @@ VNC_PORTS = [
#*******************************************************************************
FEDERATION = [
mode = "STANDALONE",
zone_id = 0,
master_oned = ""
MODE = "STANDALONE",
ZONE_ID = 0,
MASTER_ONED = ""
]
#*******************************************************************************
@ -188,12 +188,32 @@ DEFAULT_COST = [
# MAC_PREFIX: Default MAC prefix to be used to create the auto-generated MAC
# addresses is defined here (this can be overrided by the Virtual Network
# template)
#
# VLAN_IDS: VLAN ID pool for the automatic VLAN_ID assigment. This pool
# is for 802.1Q networks (Open vSwitch and 802.1Q drivers). The driver
# will try first to allocate VLAN_IDS[START] + VNET_ID
# start: First VLAN_ID to use
# reserved: Comma separated list of VLAN_IDs
#
# VXLAN_IDS: Automatic VXLAN Network ID (VNI) assigment. This is used
# for vxlan networks.
# start: First VNI to use
# NOTE: reserved is not supported by this pool
#*******************************************************************************
NETWORK_SIZE = 254
MAC_PREFIX = "02:00"
VLAN_IDS = [
START = 2,
RESERVED = "0, 4095"
]
VXLAN_IDS = [
START = 2
]
#*******************************************************************************
# DataStore Configuration
#*******************************************************************************
@ -265,9 +285,9 @@ DEFAULT_CDROM_DEVICE_PREFIX = "hd"
# not be effective.
#-------------------------------------------------------------------------------
IM_MAD = [
name = "collectd",
executable = "collectd",
arguments = "-p 4124 -f 5 -t 50 -i 20" ]
NAME = "collectd",
EXECUTABLE = "collectd",
ARGUMENTS = "-p 4124 -f 5 -t 50 -i 20" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
@ -276,9 +296,9 @@ IM_MAD = [
# -t number of threads, i.e. number of hosts monitored at the same time
#-------------------------------------------------------------------------------
IM_MAD = [
name = "kvm",
executable = "one_im_ssh",
arguments = "-r 3 -t 15 kvm" ]
NAME = "kvm",
EXECUTABLE = "one_im_ssh",
ARGUMENTS = "-r 3 -t 15 kvm" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
@ -287,12 +307,11 @@ IM_MAD = [
# -t number of threads, i.e. number of hosts monitored at the same time
#-------------------------------------------------------------------------------
# IM_MAD = [
# name = "kvm",
# executable = "one_im_ssh",
# arguments = "-r 3 -t 15 kvm-probes" ]
# NAME = "kvm",
# EXECUTABLE = "one_im_ssh",
# ARGUMENTS = "-r 3 -t 15 kvm-probes" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# VMware Information Driver Manager Configuration
@ -300,9 +319,9 @@ IM_MAD = [
# -t number of threads, i.e. number of hosts monitored at the same time
#-------------------------------------------------------------------------------
#IM_MAD = [
# name = "vmware",
# executable = "one_im_sh",
# arguments = "-c -t 15 -r 0 vmware" ]
# NAME = "vmware",
# EXECUTABLE = "one_im_sh",
# ARGUMENTS = "-c -t 15 -r 0 vmware" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
@ -311,9 +330,9 @@ IM_MAD = [
# -t number of threads, i.e. number of hosts monitored at the same time
#-------------------------------------------------------------------------------
#IM_MAD = [
# name = "vcenter",
# executable = "one_im_sh",
# arguments = "-c -t 15 -r 0 vcenter" ]
# NAME = "vcenter",
# EXECUTABLE = "one_im_sh",
# ARGUMENTS = "-c -t 15 -r 0 vcenter" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
@ -322,9 +341,9 @@ IM_MAD = [
# -t number of threads, i.e. number of hosts monitored at the same time
#-------------------------------------------------------------------------------
#IM_MAD = [
# name = "ec2",
# executable = "one_im_sh",
# arguments = "-c -t 1 -r 0 ec2" ]
# NAME = "ec2",
# EXECUTABLE = "one_im_sh",
# ARGUMENTS = "-c -t 1 -r 0 ec2" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
@ -333,9 +352,9 @@ IM_MAD = [
# -t number of threads, i.e. number of hosts monitored at the same time
#-------------------------------------------------------------------------------
#IM_MAD = [
# name = "sl",
# executable = "one_im_sh",
# arguments = "-c -t 1 -r 0 sl" ]
# NAME = "sl",
# EXECUTABLE = "one_im_sh",
# ARGUMENTS = "-c -t 1 -r 0 sl" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
@ -344,15 +363,15 @@ IM_MAD = [
# -t number of threads, i.e. number of hosts monitored at the same time
#-------------------------------------------------------------------------------
#IM_MAD = [
# name = "az",
# executable = "one_im_sh",
# arguments = "-c -t 1 -r 0 az" ]
# NAME = "az",
# EXECUTABLE = "one_im_sh",
# ARGUMENTS = "-c -t 1 -r 0 az" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Dummy Information Driver Manager Configuration
#-------------------------------------------------------------------------------
#IM_MAD = [ name="dummy", executable="one_im_dummy"]
#IM_MAD = [ NAME="dummy", EXECUTABLE="one_im_dummy"]
#-------------------------------------------------------------------------------
#*******************************************************************************
@ -419,12 +438,12 @@ IM_MAD = [
# CPU does not have virtualization extensions or use nested Qemu-KVM hosts
#-------------------------------------------------------------------------------
VM_MAD = [
name = "kvm",
executable = "one_vmm_exec",
arguments = "-t 15 -r 0 kvm",
default = "vmm_exec/vmm_exec_kvm.conf",
type = "kvm",
imported_vms_actions = "shutdown, shutdown-hard, hold, release, suspend,
NAME = "kvm",
EXECUTABLE = "one_vmm_exec",
ARGUMENTS = "-t 15 -r 0 kvm",
DEFAULT = "vmm_exec/vmm_exec_kvm.conf",
TYPE = "kvm",
IMPORTED_VMS_ACTIONS = "shutdown, shutdown-hard, hold, release, suspend,
resume, delete, reboot, reboot-hard, resched, unresched, disk-attach,
disk-detach, nic-attach, nic-detach, snap-create, snap-delete"
]
@ -441,12 +460,12 @@ VM_MAD = [
# defaults to 'suspend'.
#-------------------------------------------------------------------------------
#VM_MAD = [
# name = "vmware",
# executable = "one_vmm_sh",
# arguments = "-t 15 -r 0 vmware -s sh",
# default = "vmm_exec/vmm_exec_vmware.conf",
# type = "vmware",
# imported_vms_actions = "shutdown, shutdown-hard, hold, release, suspend,
# NAME = "vmware",
# EXECUTABLE = "one_vmm_sh",
# ARGUMENTS = "-t 15 -r 0 vmware -s sh",
# DEFAULT = "vmm_exec/vmm_exec_vmware.conf",
# TYPE = "vmware",
# IMPORTED_VMS_ACTIONS = "shutdown, shutdown-hard, hold, release, suspend,
# resume, delete, reboot, reboot-hard, resched, unresched, disk-attach,
# disk-detach, nic-attach, nic-detach, snap-create, snap-delete"
# ]
@ -462,12 +481,12 @@ VM_MAD = [
# defaults to 'suspend'.
#-------------------------------------------------------------------------------
#VM_MAD = [
# name = "vcenter",
# executable = "one_vmm_sh",
# arguments = "-p -t 15 -r 0 vcenter -s sh",
# default = "vmm_exec/vmm_exec_vcenter.conf",
# type = "xml",
# imported_vms_actions = "shutdown, shutdown-hard, hold, release, suspend,
# NAME = "vcenter",
# EXECUTABLE = "one_vmm_sh",
# ARGUMENTS = "-p -t 15 -r 0 vcenter -s sh",
# DEFAULT = "vmm_exec/vmm_exec_vcenter.conf",
# TYPE = "xml",
# IMPORTED_VMS_ACTIONS = "shutdown, shutdown-hard, hold, release, suspend,
# resume, delete, reboot, reboot-hard, resched, unresched, poweroff,
# poweroff-hard, disk-attach, disk-detach, nic-attach, nic-detach,
# snap-create, snap-delete"
@ -480,11 +499,11 @@ VM_MAD = [
# -t number of threads, i.e. number of actions performed at the same time
#-------------------------------------------------------------------------------
#VM_MAD = [
# name = "ec2",
# executable = "one_vmm_sh",
# arguments = "-t 15 -r 0 ec2",
# type = "xml",
# imported_vms_actions = "shutdown, shutdown-hard, hold, release, suspend,
# NAME = "ec2",
# EXECUTABLE = "one_vmm_sh",
# ARGUMENTS = "-t 15 -r 0 ec2",
# TYPE = "xml",
# IMPORTED_VMS_ACTIONS = "shutdown, shutdown-hard, hold, release, suspend,
# resume, delete, reboot, reboot-hard, resched, unresched, poweroff,
# poweroff-hard, disk-attach, disk-detach, nic-attach, nic-detach,
# snap-create, snap-delete"
@ -497,11 +516,11 @@ VM_MAD = [
# -t number of threads, i.e. number of actions performed at the same time
#-------------------------------------------------------------------------------
#VM_MAD = [
# name = "sl",
# executable = "one_vmm_sh",
# arguments = "-t 15 -r 0 sl",
# type = "xml",
# imported_vms_actions = "shutdown, shutdown-hard, hold, release, suspend,
# NAME = "sl",
# EXECUTABLE = "one_vmm_sh",
# ARGUMENTS = "-t 15 -r 0 sl",
# TYPE = "xml",
# IMPORTED_VMS_ACTIONS = "shutdown, shutdown-hard, hold, release, suspend,
# resume, delete, reboot, reboot-hard, resched, unresched, poweroff,
# poweroff-hard, disk-attach, disk-detach, nic-attach, nic-detach,
# snap-create, snap-delete"
@ -514,11 +533,11 @@ VM_MAD = [
# -t number of threads, i.e. number of actions performed at the same time
#-------------------------------------------------------------------------------
#VM_MAD = [
# name = "az",
# executable = "one_vmm_sh",
# arguments = "-t 15 -r 0 az",
# type = "xml",
# imported_vms_actions = "shutdown, shutdown-hard, hold, release, suspend,
# NAME = "az",
# EXECUTABLE = "one_vmm_sh",
# ARGUMENTS = "-t 15 -r 0 az",
# TYPE = "xml",
# IMPORTED_VMS_ACTIONS = "shutdown, shutdown-hard, hold, release, suspend,
# resume, delete, reboot, reboot-hard, resched, unresched, poweroff,
# poweroff-hard, disk-attach, disk-detach, nic-attach, nic-detach,
# snap-create, snap-delete"
@ -528,7 +547,7 @@ VM_MAD = [
#-------------------------------------------------------------------------------
# Dummy Virtualization Driver Configuration
#-------------------------------------------------------------------------------
#VM_MAD = [ name="dummy", executable="one_vmm_dummy", type="xml" ]
#VM_MAD = [ NAME="dummy", EXECUTABLE="one_vmm_dummy", TYPE="xml" ]
#-------------------------------------------------------------------------------
#*******************************************************************************
@ -548,8 +567,8 @@ VM_MAD = [
#*******************************************************************************
TM_MAD = [
executable = "one_tm",
arguments = "-t 15 -d dummy,lvm,shared,fs_lvm,qcow2,ssh,vmfs,ceph,dev,vcenter,iscsi"
EXECUTABLE = "one_tm",
ARGUMENTS = "-t 15 -d dummy,lvm,shared,fs_lvm,qcow2,ssh,vmfs,ceph,dev,vcenter,iscsi"
]
#*******************************************************************************
@ -567,8 +586,8 @@ TM_MAD = [
#*******************************************************************************
DATASTORE_MAD = [
executable = "one_datastore",
arguments = "-t 15 -d dummy,fs,vmfs,lvm,ceph,dev,iscsi,vcenter -s shared,ssh,ceph"
EXECUTABLE = "one_datastore",
ARGUMENTS = "-t 15 -d dummy,fs,vmfs,lvm,ceph,dev,iscsi,vcenter -s shared,ssh,ceph"
]
#*******************************************************************************
@ -585,8 +604,8 @@ DATASTORE_MAD = [
#*******************************************************************************
MARKET_MAD = [
executable = "one_market",
arguments = "-t 15 -m http,s3,one"
EXECUTABLE = "one_market",
ARGUMENTS = "-t 15 -m http,s3,one"
]
#*******************************************************************************
@ -692,7 +711,7 @@ MARKET_MAD = [
# the master OpenNebula.
#-------------------------------------------------------------------------------
HM_MAD = [
executable = "one_hm" ]
EXECUTABLE = "one_hm" ]
#*******************************************************************************
# Fault Tolerance Hooks
@ -710,11 +729,11 @@ HM_MAD = [
#*******************************************************************************
#
#HOST_HOOK = [
# name = "error",
# on = "ERROR",
# command = "ft/host_error.rb",
# arguments = "$ID -m -p 5",
# remote = "no" ]
# NAME = "error",
# ON = "ERROR",
# COMMAND = "ft/host_error.rb",
# ARGUMENTS = "$ID -m -p 5",
# REMOTE = "no" ]
#-------------------------------------------------------------------------------
#*******************************************************************************
@ -753,8 +772,8 @@ HM_MAD = [
#*******************************************************************************
AUTH_MAD = [
executable = "one_auth_mad",
authn = "ssh,x509,ldap,server_cipher,server_x509"
EXECUTABLE = "one_auth_mad",
AUTHN = "ssh,x509,ldap,server_cipher,server_x509"
]
#DEFAULT_AUTH = "default"

View File

@ -46,7 +46,7 @@ const char * Cluster::network_db_bootstrap =
"CREATE TABLE IF NOT EXISTS cluster_network_relation ("
"cid INTEGER, oid INTEGER, PRIMARY KEY(cid, oid))";
const char * Cluster::bitmap_table = "vm_bitmap";
const char * Cluster::bitmap_table = "cluster_vnc_bitmap";
/* ************************************************************************** */
/* Cluster :: Constructor/Destructor */

View File

@ -517,6 +517,9 @@ void Nebula::start(bool bootstrap_only)
vector<const SingleAttribute *> vnet_restricted_attrs;
vector<const VectorAttribute *> vnet_hooks;
const VectorAttribute * vlan_id;
const VectorAttribute * vxlan_id;
nebula_configuration->get("MAC_PREFIX", mac_prefix);
nebula_configuration->get("NETWORK_SIZE", size);
@ -527,8 +530,12 @@ void Nebula::start(bool bootstrap_only)
nebula_configuration->get("INHERIT_VNET_ATTR", inherit_vnet_attrs);
vlan_id = nebula_configuration->get("VLAN_ID");
vxlan_id = nebula_configuration->get("VXLAN_ID");
vnpool = new VirtualNetworkPool(db, mac_prefix, size, vnet_restricted_attrs,
vnet_hooks, remotes_location, inherit_vnet_attrs);
vnet_hooks, remotes_location, inherit_vnet_attrs, vlan_id, vxlan_id);
/* ----------------------- Group/User Pool -------------------------- */
vector<const VectorAttribute *> user_hooks;

View File

@ -342,7 +342,7 @@ void OpenNebulaTemplate::set_conf_default()
vattribute = new VectorAttribute("LOG",vvalue);
conf_default.insert(make_pair(vattribute->name(),vattribute));
// LOG CONFIGURATION
// VNC CONFIGURATION
vvalue.clear();
vvalue.insert(make_pair("RESERVED",""));
vvalue.insert(make_pair("START","5900"));
@ -411,12 +411,25 @@ void OpenNebulaTemplate::set_conf_default()
#*******************************************************************************
# NETWORK_SIZE
# MAC_PREFIX
# VLAN_ID
# VXLAN_ID
#*******************************************************************************
*/
set_conf_single("MAC_PREFIX", "02:00");
set_conf_single("NETWORK_SIZE", "254");
vvalue.clear();
vvalue.insert(make_pair("RESERVED","0, 4095"));
vvalue.insert(make_pair("START","2"));
vattribute = new VectorAttribute("VLAN_ID",vvalue);
conf_default.insert(make_pair(vattribute->name(),vattribute));
vvalue.clear();
vvalue.insert(make_pair("START","2"));
vattribute = new VectorAttribute("VXLAN_ID",vvalue);
conf_default.insert(make_pair(vattribute->name(),vattribute));
/*
#*******************************************************************************
# Datastore Configuration

View File

@ -105,7 +105,7 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str)
vector<VectorAttribute *> ars;
ostringstream ose;
string sg_str;
string sg_str, vis;
int rc, num_ars;
@ -126,6 +126,11 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str)
erase_template_attribute("VN_MAD", vn_mad);
if (vn_mad.empty())
{
goto error_vn_mad;
}
add_template_attribute("VN_MAD", vn_mad);
// ------------ PHYDEV --------------------
@ -134,11 +139,14 @@ int VirtualNetwork::insert(SqlDB * db, string& error_str)
add_template_attribute("PHYDEV", phydev);
// ------------ VLAN_ID -------------------
// ---- VLAN_ID if not set allocated in VirtualNetworkPool, if needed -----
erase_template_attribute("VLAN_ID", vlan_id);
if (PoolObjectSQL::get_template_attribute("VLAN_ID", vis) && !vis.empty())
{
erase_template_attribute("VLAN_ID", vlan_id);
add_template_attribute("VLAN_ID", vlan_id);
add_template_attribute("VLAN_ID", vlan_id);
}
// ------------ BRIDGE --------------------
@ -226,6 +234,10 @@ error_name:
ose << "No NAME in template for Virtual Network.";
goto error_common;
error_vn_mad:
ose << "No VN_MAD in template for Virtual Network.";
goto error_common;
error_bridge:
ose << "No BRIDGE in template for Virtual Network.";
goto error_common;

View File

@ -21,6 +21,7 @@
#include "PoolObjectAuth.h"
#include "AuthManager.h"
#include "AddressRange.h"
#include <sstream>
#include <ctype.h>
@ -28,9 +29,15 @@
/* -------------------------------------------------------------------------- */
unsigned int VirtualNetworkPool::_mac_prefix;
unsigned int VirtualNetworkPool::_default_size;
const char * VirtualNetworkPool::vlan_table = "network_vlan_bitmap";
const int VirtualNetworkPool::VLAN_BITMAP_ID = 0;
/* -------------------------------------------------------------------------- */
VirtualNetworkPool::VirtualNetworkPool(
SqlDB * db,
const string& prefix,
@ -38,8 +45,12 @@ VirtualNetworkPool::VirtualNetworkPool(
vector<const SingleAttribute *>& restricted_attrs,
vector<const VectorAttribute *>& hook_mads,
const string& remotes_location,
const vector<const SingleAttribute *>& _inherit_attrs):
PoolSQL(db, VirtualNetwork::table, true, true)
const vector<const SingleAttribute *>& _inherit_attrs,
const VectorAttribute * _vlan_conf,
const VectorAttribute * _vxlan_conf):
PoolSQL(db, VirtualNetwork::table, true, true), vlan_conf(_vlan_conf),
vlan_id_bitmap(vlan_conf, VLAN_BITMAP_ID, vlan_table),
vxlan_conf(_vxlan_conf)
{
istringstream iss;
size_t pos = 0;
@ -53,6 +64,11 @@ VirtualNetworkPool::VirtualNetworkPool(
_mac_prefix = 0;
_default_size = __default_size;
if ( vlan_id_bitmap.select(VLAN_BITMAP_ID, db) != 0 )
{
vlan_id_bitmap.insert(VLAN_BITMAP_ID, db);
}
while ( (pos = mac.find(':')) != string::npos )
{
mac.replace(pos,1," ");
@ -126,8 +142,25 @@ int VirtualNetworkPool::allocate (
goto error_duplicated;
}
// Insert the VN in the DB
*oid = PoolSQL::allocate(vn, error_str);
// Get a free VLAN_ID from the pool if needed
if ( *oid != -1 )
{
vn = get(*oid, true);
if ( set_vlan_id(vn) != 0 )
{
error_str = "Cannot automatically assign VLAN_ID to network.";
drop(vn, error_str);
*oid = -1;
};
vn->unlock();
}
return *oid;
@ -283,7 +316,8 @@ int VirtualNetworkPool::nic_attribute(
else
{
ostringstream oss;
oss << "Cannot get IP/MAC lease from virtual network " << vnet->get_oid() << ".";
oss << "Cannot get IP/MAC lease from virtual network "
<< vnet->get_oid() << ".";
error = oss.str();
}
@ -337,3 +371,103 @@ void VirtualNetworkPool::authorize_nic(
ar->add_auth(AuthRequest::USE, perm);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VirtualNetworkPool::set_vlan_id(VirtualNetwork * vn)
{
string vn_mad;
unsigned int start_vlan, hint_vlan;
unsigned int vlan_id;
if ( vn->PoolObjectSQL::get_template_attribute("VLAN_ID", vlan_id) )
{
return 0;
}
if ( !vn->PoolObjectSQL::get_template_attribute("VN_MAD", vn_mad) )
{
return 0;
}
switch (VirtualNetwork::str_to_driver(vn_mad))
{
case VirtualNetwork::VXLAN:
if (vxlan_conf.vector_value("START", start_vlan) != 0)
{
start_vlan = 2; //default in oned.conf
}
vlan_id = start_vlan + vn->get_oid();
vn->add_template_attribute("VLAN_ID", vlan_id);
update(vn);
break;
case VirtualNetwork::VLAN:
case VirtualNetwork::OVSWITCH:
start_vlan = vlan_id_bitmap.get_start_bit();
hint_vlan = start_vlan + (vn->get_oid() % (4095 -start_vlan ));
if ( vlan_id_bitmap.get(hint_vlan, vlan_id) != 0 )
{
return -1;
}
vn->add_template_attribute("VLAN_ID", vlan_id);
vn->add_template_attribute("VLAN_ID_AUTOMATIC", true);
vlan_id_bitmap.update(db);
update(vn);
break;
default:
break;
}
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualNetworkPool::release_vlan_id(VirtualNetwork *vn)
{
string vn_mad;
unsigned int vlan_id;
bool vlan_auto;
if ( !vn->PoolObjectSQL::get_template_attribute("VLAN_ID_AUTOMATIC",
vlan_auto) || vlan_auto == false )
{
return;
}
if ( !vn->PoolObjectSQL::get_template_attribute("VLAN_ID", vlan_id) )
{
return;
}
if ( !vn->PoolObjectSQL::get_template_attribute("VN_MAD", vn_mad) )
{
return;
}
switch (VirtualNetwork::str_to_driver(vn_mad))
{
case VirtualNetwork::VLAN:
case VirtualNetwork::OVSWITCH:
vlan_id_bitmap.reset(vlan_id);
vlan_id_bitmap.update(db);
break;
default:
break;
}
}