/* -------------------------------------------------------------------------- */ /* Copyright 2002-2020, 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 VIRTUAL_NETWORK_H_ #define VIRTUAL_NETWORK_H_ #include "PoolSQL.h" #include "VirtualNetworkTemplate.h" #include "Clusterable.h" #include "AddressRangePool.h" #include "ObjectCollection.h" #include #include class VirtualMachineNic; /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ /** * The Virtual Network class. It represents a Virtual Network at manages its * leases. One lease is formed by one IP and one MAC address. * MAC address are derived from IP addresses. */ 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, VCENTER = 7, OVSWITCH_VXLAN = 8, BRIDGE = 9 }; enum BridgeType { UNDEFINED = 0, LINUX = 1, OPENVSWITCH = 2, OPENVSWITCH_DPDK = 3, VCENTER_PORT_GROUPS = 4, BRNONE = 5 }; static std::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 "ovswitch"; case VXLAN: return "vxlan"; case VCENTER: return "vcenter"; case OVSWITCH_VXLAN: return "ovswitch_vxlan"; case BRIDGE: return "bridge"; default: return ""; } }; static VirtualNetworkDriver str_to_driver(const std::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 == "ovswitch" ) { return OVSWITCH; } else if ( ob == "vxlan" ) { return VXLAN; } else if ( ob == "vcenter" ) { return VCENTER; } else if ( ob == "ovswitch_vxlan" ) { return OVSWITCH_VXLAN; } else if ( ob == "bridge" ) { return BRIDGE; } else { return NONE; } }; static std::string bridge_type_to_str(BridgeType ob) { switch (ob) { case UNDEFINED: case LINUX: return "linux"; case OPENVSWITCH: return "openvswitch"; case OPENVSWITCH_DPDK: return "openvswitch_dpdk"; case VCENTER_PORT_GROUPS: return "vcenter_port_groups"; case BRNONE: return "none"; default: return "none"; } }; static BridgeType str_to_bridge_type(const std::string& ob) { if ( ob == "linux" ) { return LINUX; } else if ( ob == "openvswitch" ) { return OPENVSWITCH; } else if ( ob == "openvswitch_dpdk" ) { return OPENVSWITCH_DPDK; } else if ( ob == "vcenter_port_groups" ) { return VCENTER_PORT_GROUPS; } else if (ob == "none") { return BRNONE; } else { return UNDEFINED; } }; /** * Check consistency of PHYDEV, BRIDGE and VLAN attributes depending on * the network driver * @param error_str describing the error * @return 0 on success -1 otherwise */ static int parse_phydev_vlans(const Template* tmpl, const std::string& vn_mad, const std::string& phydev, const std::string& bridge, const bool auto_id, const std::string& vlan_id, const bool auto_outer, const std::string& outer_id, std::string& estr); // ************************************************************************* // Virtual Network Public Methods // ************************************************************************* virtual ~VirtualNetwork() = default; /** * Factory method for virtual network templates */ std::unique_ptr