Search in sources :

Example 16 with TrafficType

use of com.cloud.network.Networks.TrafficType in project cloudstack by apache.

the class SecondaryStorageManagerImpl method getDefaultNetworkForBasicZone.

/**
     * Get default network for secondary storage VM for starting up in a basic zone. Basic zones select
     * the Guest network whether or not the zone is SG-enabled.
     * @param dc - The zone.
     * @return The default network according to the zone's network selection rules.
     * @throws CloudRuntimeException - If the zone is not a valid choice or a network couldn't be found.
     */
protected NetworkVO getDefaultNetworkForBasicZone(DataCenter dc) {
    if (dc.getNetworkType() != NetworkType.Basic) {
        throw new CloudRuntimeException("Zone " + dc + "is not basic.");
    }
    TrafficType defaultTrafficType = TrafficType.Guest;
    List<NetworkVO> defaultNetworks = _networkDao.listByZoneAndTrafficType(dc.getId(), defaultTrafficType);
    // api should never allow this situation to happen
    if (defaultNetworks.size() != 1) {
        throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type " + defaultTrafficType + " when expect to find 1");
    }
    return defaultNetworks.get(0);
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) TrafficType(com.cloud.network.Networks.TrafficType)

Example 17 with TrafficType

use of com.cloud.network.Networks.TrafficType in project cloudstack by apache.

the class LibvirtVifDriverTest method testOverrideSomeTrafficTypes.

@Test
public void testOverrideSomeTrafficTypes() throws ConfigurationException {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put(LibVirtVifDriver + "." + "Public", FakeVifDriverClassName);
    params.put(LibVirtVifDriver + "." + "Guest", LibvirtComputingResource.DEFAULT_OVS_VIF_DRIVER_CLASS_NAME);
    res._bridgeType = BridgeType.NATIVE;
    configure(params);
    // Initially, set all traffic types to use default
    for (TrafficType trafficType : TrafficType.values()) {
        assertions.put(trafficType, bridgeVifDriver);
    }
    assertions.put(TrafficType.Public, fakeVifDriver);
    assertions.put(TrafficType.Guest, ovsVifDriver);
    checkAssertions();
}
Also used : HashMap(java.util.HashMap) TrafficType(com.cloud.network.Networks.TrafficType) Test(org.junit.Test)

Example 18 with TrafficType

use of com.cloud.network.Networks.TrafficType in project cloudstack by apache.

the class LibvirtVifDriverTest method testEmptyTrafficType.

@Test
public void testEmptyTrafficType() throws ConfigurationException {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put(LibVirtVifDriver + ".", FakeVifDriverClassName);
    res._bridgeType = BridgeType.NATIVE;
    configure(params);
    // Set all traffic types to use default, because bad traffic type should be ignored
    for (TrafficType trafficType : TrafficType.values()) {
        assertions.put(trafficType, bridgeVifDriver);
    }
    checkAssertions();
}
Also used : HashMap(java.util.HashMap) TrafficType(com.cloud.network.Networks.TrafficType) Test(org.junit.Test)

Example 19 with TrafficType

use of com.cloud.network.Networks.TrafficType in project cloudstack by apache.

the class LibvirtComputingResource method configureVifDrivers.

protected void configureVifDrivers(final Map<String, Object> params) throws ConfigurationException {
    final String LIBVIRT_VIF_DRIVER = "libvirt.vif.driver";
    _trafficTypeVifDrivers = new HashMap<TrafficType, VifDriver>();
    // Load the default vif driver
    String defaultVifDriverName = (String) params.get(LIBVIRT_VIF_DRIVER);
    if (defaultVifDriverName == null) {
        if (_bridgeType == BridgeType.OPENVSWITCH) {
            s_logger.info("No libvirt.vif.driver specified. Defaults to OvsVifDriver.");
            defaultVifDriverName = DEFAULT_OVS_VIF_DRIVER_CLASS_NAME;
        } else {
            s_logger.info("No libvirt.vif.driver specified. Defaults to BridgeVifDriver.");
            defaultVifDriverName = DEFAULT_BRIDGE_VIF_DRIVER_CLASS_NAME;
        }
    }
    _defaultVifDriver = getVifDriverClass(defaultVifDriverName, params);
    // Load any per-traffic-type vif drivers
    for (final Map.Entry<String, Object> entry : params.entrySet()) {
        final String k = entry.getKey();
        final String vifDriverPrefix = LIBVIRT_VIF_DRIVER + ".";
        if (k.startsWith(vifDriverPrefix)) {
            // Get trafficType
            final String trafficTypeSuffix = k.substring(vifDriverPrefix.length());
            // Does this suffix match a real traffic type?
            final TrafficType trafficType = TrafficType.getTrafficType(trafficTypeSuffix);
            if (!trafficType.equals(TrafficType.None)) {
                // Get vif driver class name
                final String vifDriverClassName = (String) entry.getValue();
                // if value is null, ignore
                if (vifDriverClassName != null) {
                    // add traffic type to vif driver mapping to Map
                    _trafficTypeVifDrivers.put(trafficType, getVifDriverClass(vifDriverClassName, params));
                }
            }
        }
    }
}
Also used : Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TrafficType(com.cloud.network.Networks.TrafficType)

Example 20 with TrafficType

use of com.cloud.network.Networks.TrafficType in project cloudstack by apache.

the class NetworkServiceImpl method addTrafficTypeToPhysicalNetwork.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_TRAFFIC_TYPE_CREATE, eventDescription = "Creating Physical Network TrafficType", create = true)
public PhysicalNetworkTrafficType addTrafficTypeToPhysicalNetwork(Long physicalNetworkId, String trafficTypeStr, String isolationMethod, String xenLabel, String kvmLabel, String vmwareLabel, String simulatorLabel, String vlan, String hypervLabel, String ovm3Label) {
    // verify input parameters
    PhysicalNetworkVO network = _physicalNetworkDao.findById(physicalNetworkId);
    if (network == null) {
        throw new InvalidParameterValueException("Physical Network id=" + physicalNetworkId + "doesn't exist in the system");
    }
    Networks.TrafficType trafficType = null;
    if (trafficTypeStr != null && !trafficTypeStr.isEmpty()) {
        try {
            trafficType = Networks.TrafficType.valueOf(trafficTypeStr);
        } catch (IllegalArgumentException ex) {
            throw new InvalidParameterValueException("Unable to resolve trafficType '" + trafficTypeStr + "' to a supported value");
        }
    }
    if (_pNTrafficTypeDao.isTrafficTypeSupported(physicalNetworkId, trafficType)) {
        throw new CloudRuntimeException("This physical network already supports the traffic type: " + trafficType);
    }
    if (TrafficType.isSystemNetwork(trafficType) || TrafficType.Public.equals(trafficType) || TrafficType.Storage.equals(trafficType)) {
        if (!_physicalNetworkDao.listByZoneAndTrafficType(network.getDataCenterId(), trafficType).isEmpty()) {
            throw new CloudRuntimeException("Fail to add the traffic type to physical network because Zone already has a physical network with this traffic type: " + trafficType);
        }
    }
    if (TrafficType.Storage.equals(trafficType)) {
        List<SecondaryStorageVmVO> ssvms = _stnwMgr.getSSVMWithNoStorageNetwork(network.getDataCenterId());
        if (!ssvms.isEmpty()) {
            StringBuilder sb = new StringBuilder("Cannot add " + trafficType + " traffic type as there are below secondary storage vm still running. Please stop them all and add Storage traffic type again, then destory them all to allow CloudStack recreate them with storage network(If you have added storage network ip range)");
            sb.append("SSVMs:");
            for (SecondaryStorageVmVO ssvm : ssvms) {
                sb.append(ssvm.getInstanceName()).append(":").append(ssvm.getState());
            }
            throw new CloudRuntimeException(sb.toString());
        }
    }
    try {
        // Create the new traffic type in the database
        if (xenLabel == null) {
            xenLabel = getDefaultXenNetworkLabel(trafficType);
        }
        PhysicalNetworkTrafficTypeVO pNetworktrafficType = new PhysicalNetworkTrafficTypeVO(physicalNetworkId, trafficType, xenLabel, kvmLabel, vmwareLabel, simulatorLabel, vlan, hypervLabel, ovm3Label);
        pNetworktrafficType = _pNTrafficTypeDao.persist(pNetworktrafficType);
        // each broadcast type will individually need to be qualified for support of public traffic
        if (TrafficType.Public.equals(trafficType)) {
            List<String> isolationMethods = network.getIsolationMethods();
            if ((isolationMethods.size() == 1 && isolationMethods.get(0).toLowerCase().equals("vxlan")) || (isolationMethod != null && isolationMethods.contains(isolationMethod) && isolationMethod.toLowerCase().equals("vxlan"))) {
                // find row in networks table that is defined as 'Public', created when zone was deployed
                NetworkVO publicNetwork = _networksDao.listByZoneAndTrafficType(network.getDataCenterId(), TrafficType.Public).get(0);
                if (publicNetwork != null) {
                    s_logger.debug("setting public network " + publicNetwork + " to broadcast type vxlan");
                    publicNetwork.setBroadcastDomainType(BroadcastDomainType.Vxlan);
                    _networksDao.persist(publicNetwork);
                }
            }
        }
        return pNetworktrafficType;
    } catch (Exception ex) {
        s_logger.warn("Exception: ", ex);
        throw new CloudRuntimeException("Fail to add a traffic type to physical network");
    }
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkTrafficTypeVO(com.cloud.network.dao.PhysicalNetworkTrafficTypeVO) InvalidParameterException(java.security.InvalidParameterException) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) UnknownHostException(java.net.UnknownHostException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) TrafficType(com.cloud.network.Networks.TrafficType) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Aggregations

TrafficType (com.cloud.network.Networks.TrafficType)26 NetworkVO (com.cloud.network.dao.NetworkVO)13 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)6 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 Pair (com.cloud.utils.Pair)3 ConfigurationException (javax.naming.ConfigurationException)3 Test (org.junit.Test)3 ActionEvent (com.cloud.event.ActionEvent)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 NetworkOffering (com.cloud.offering.NetworkOffering)2 DB (com.cloud.utils.db.DB)2 IOException (java.io.IOException)2 Map (java.util.Map)2 NicResponse (org.apache.cloudstack.api.response.NicResponse)2 ListResponse (com.cloud.api.response.ListResponse)1 TrafficTypeImplementorResponse (com.cloud.api.response.TrafficTypeImplementorResponse)1 DataCenterVO (com.cloud.dc.DataCenterVO)1 CloudException (com.cloud.exception.CloudException)1