Search in sources :

Example 16 with DVSTrafficShapingPolicy

use of com.vmware.vim25.DVSTrafficShapingPolicy in project cloudstack by apache.

the class HypervisorHostHelper method getDVSShapingPolicy.

public static DVSTrafficShapingPolicy getDVSShapingPolicy(Integer networkRateMbps) {
    DVSTrafficShapingPolicy shapingPolicy = new DVSTrafficShapingPolicy();
    BoolPolicy isEnabled = new BoolPolicy();
    if (networkRateMbps == null || networkRateMbps.intValue() <= 0) {
        isEnabled.setValue(false);
        shapingPolicy.setEnabled(isEnabled);
        return shapingPolicy;
    }
    LongPolicy averageBandwidth = new LongPolicy();
    LongPolicy peakBandwidth = new LongPolicy();
    LongPolicy burstSize = new LongPolicy();
    isEnabled.setValue(true);
    averageBandwidth.setValue(networkRateMbps.intValue() * 1024L * 1024L);
    // We chose 50% higher allocation than average bandwidth.
    // TODO(sateesh): Also let user specify the peak coefficient
    peakBandwidth.setValue((long) (averageBandwidth.getValue() * 1.5));
    // TODO(sateesh): Also let user specify the burst coefficient
    burstSize.setValue(5 * averageBandwidth.getValue() / 8);
    shapingPolicy.setEnabled(isEnabled);
    shapingPolicy.setAverageBandwidth(averageBandwidth);
    shapingPolicy.setPeakBandwidth(peakBandwidth);
    shapingPolicy.setBurstSize(burstSize);
    return shapingPolicy;
}
Also used : LongPolicy(com.vmware.vim25.LongPolicy) DVSTrafficShapingPolicy(com.vmware.vim25.DVSTrafficShapingPolicy) BoolPolicy(com.vmware.vim25.BoolPolicy)

Example 17 with DVSTrafficShapingPolicy

use of com.vmware.vim25.DVSTrafficShapingPolicy in project cloudstack by apache.

the class HypervisorHostHelper method createPortGroup.

private static void createPortGroup(String physicalNetwork, String networkName, String vlanRange, Integer vid, Integer spvlanid, DatacenterMO dataCenterMo, DVSTrafficShapingPolicy shapingPolicy, DVSSecurityPolicy secPolicy, DVSMacManagementPolicy macManagementPolicy, VMwareDVSPortgroupPolicy portGroupPolicy, DistributedVirtualSwitchMO dvSwitchMo, int numPorts, boolean autoExpandSupported, boolean dvSwitchSupportNewPolicies) throws Exception {
    VmwareDistributedVirtualSwitchVlanSpec vlanSpec = null;
    VmwareDistributedVirtualSwitchPvlanSpec pvlanSpec = null;
    VMwareDVSPortSetting dvsPortSetting = null;
    DVPortgroupConfigSpec newDvPortGroupSpec;
    // NOTE - VmwareDistributedVirtualSwitchPvlanSpec extends VmwareDistributedVirtualSwitchVlanSpec.
    if (vid == null || spvlanid == null) {
        vlanSpec = createDVPortVlanSpec(vid, vlanRange);
        dvsPortSetting = createVmwareDVPortSettingSpec(shapingPolicy, secPolicy, macManagementPolicy, vlanSpec, dvSwitchSupportNewPolicies);
    } else if (spvlanid != null) {
        // Create a pvlan spec. The pvlan spec is different from the pvlan config spec
        // that we created earlier. The pvlan config spec is used to configure the switch
        // with a <primary vlanId, secondary vlanId> tuple. The pvlan spec is used
        // to configure a port group (i.e., a network) with a secondary vlan id. We don't
        // need to mention more than the secondary vlan id because one secondary vlan id
        // can be associated with only one primary vlan id. Give vCenter the secondary vlan id,
        // and it will find out the associated primary vlan id and do the rest of the
        // port group configuration.
        pvlanSpec = createDVPortPvlanIdSpec(spvlanid);
        dvsPortSetting = createVmwareDVPortSettingSpec(shapingPolicy, secPolicy, macManagementPolicy, pvlanSpec, dvSwitchSupportNewPolicies);
    }
    newDvPortGroupSpec = createDvPortGroupSpec(networkName, dvsPortSetting, autoExpandSupported);
    if (portGroupPolicy != null) {
        newDvPortGroupSpec.setPolicy(portGroupPolicy);
    }
    if (!dataCenterMo.hasDvPortGroup(networkName)) {
        s_logger.info("Distributed Virtual Port group " + networkName + " not found.");
        // TODO(sateesh): Handle Exceptions
        try {
            newDvPortGroupSpec.setNumPorts(numPorts);
            dvSwitchMo.createDVPortGroup(newDvPortGroupSpec);
        } catch (Exception e) {
            String msg = "Failed to create distributed virtual port group " + networkName + " on dvSwitch " + physicalNetwork;
            msg += ". " + VmwareHelper.getExceptionMessage(e);
            throw new Exception(msg);
        }
    } else {
        s_logger.info("Found Distributed Virtual Port group " + networkName);
        DVPortgroupConfigInfo currentDvPortgroupInfo = dataCenterMo.getDvPortGroupSpec(networkName);
        if (!isSpecMatch(currentDvPortgroupInfo, newDvPortGroupSpec, dvSwitchSupportNewPolicies)) {
            s_logger.info("Updating Distributed Virtual Port group " + networkName);
            newDvPortGroupSpec.setDefaultPortConfig(dvsPortSetting);
            newDvPortGroupSpec.setConfigVersion(currentDvPortgroupInfo.getConfigVersion());
            ManagedObjectReference morDvPortGroup = dataCenterMo.getDvPortGroupMor(networkName);
            try {
                dvSwitchMo.updateDvPortGroup(morDvPortGroup, newDvPortGroupSpec);
            } catch (Exception e) {
                String msg = "Failed to update distributed virtual port group " + networkName + " on dvSwitch " + physicalNetwork;
                msg += ". " + VmwareHelper.getExceptionMessage(e);
                throw new Exception(msg);
            }
        }
    }
}
Also used : VMwareDVSPortSetting(com.vmware.vim25.VMwareDVSPortSetting) VmwareDistributedVirtualSwitchPvlanSpec(com.vmware.vim25.VmwareDistributedVirtualSwitchPvlanSpec) VmwareDistributedVirtualSwitchVlanSpec(com.vmware.vim25.VmwareDistributedVirtualSwitchVlanSpec) DVPortgroupConfigSpec(com.vmware.vim25.DVPortgroupConfigSpec) InvalidParameterException(java.security.InvalidParameterException) CloudException(com.cloud.exception.CloudException) TransformerException(javax.xml.transform.TransformerException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) SAXException(org.xml.sax.SAXException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DVPortgroupConfigInfo(com.vmware.vim25.DVPortgroupConfigInfo) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 18 with DVSTrafficShapingPolicy

use of com.vmware.vim25.DVSTrafficShapingPolicy in project cloudstack by apache.

the class HypervisorHostHelperTest method testIsSpecMatchConfigSpecWithMoreDvPortsAndAutoExpandEnabled.

@Test
public void testIsSpecMatchConfigSpecWithMoreDvPortsAndAutoExpandEnabled() throws Exception {
    int currentNumPorts = 512;
    int currentvlanId = 100;
    boolean currentAutoExpand = true;
    DVSTrafficShapingPolicy currentTrafficShapingPolicy = new DVSTrafficShapingPolicy();
    BoolPolicy currentIsEnabled = new BoolPolicy();
    currentIsEnabled.setValue(true);
    LongPolicy currentAvgBw = new LongPolicy();
    currentAvgBw.setValue(200L);
    LongPolicy currentBurstSize = new LongPolicy();
    currentBurstSize.setValue(400L);
    LongPolicy currentPeakBw = new LongPolicy();
    currentPeakBw.setValue(2000L);
    VMwareDVSPortSetting currentVmwareDvsPortSetting = new VMwareDVSPortSetting();
    VmwareDistributedVirtualSwitchVlanIdSpec currentVlanIdSpec = new VmwareDistributedVirtualSwitchVlanIdSpec();
    currentVlanIdSpec.setVlanId(currentvlanId);
    currentVmwareDvsPortSetting.setVlan(currentVlanIdSpec);
    currentTrafficShapingPolicy.setAverageBandwidth(currentAvgBw);
    currentTrafficShapingPolicy.setBurstSize(currentBurstSize);
    currentTrafficShapingPolicy.setPeakBandwidth(currentPeakBw);
    currentTrafficShapingPolicy.setEnabled(currentIsEnabled);
    currentVmwareDvsPortSetting.setInShapingPolicy(currentTrafficShapingPolicy);
    when(currentDvPortgroupInfo.getNumPorts()).thenReturn(currentNumPorts);
    when(currentDvPortgroupInfo.isAutoExpand()).thenReturn(currentAutoExpand);
    when(currentDvPortgroupInfo.getDefaultPortConfig()).thenReturn(currentVmwareDvsPortSetting);
    int newNumPorts = 256;
    int newvlanId = 100;
    boolean newAutoExpand = true;
    DVSTrafficShapingPolicy newTrafficShapingPolicy = new DVSTrafficShapingPolicy();
    BoolPolicy newIsEnabled = new BoolPolicy();
    newIsEnabled.setValue(true);
    LongPolicy newAvgBw = new LongPolicy();
    newAvgBw.setValue(200L);
    LongPolicy newBurstSize = new LongPolicy();
    newBurstSize.setValue(400L);
    LongPolicy newPeakBw = new LongPolicy();
    newPeakBw.setValue(2000L);
    VMwareDVSPortSetting newVmwareDvsPortSetting = new VMwareDVSPortSetting();
    VmwareDistributedVirtualSwitchVlanIdSpec newVlanIdSpec = new VmwareDistributedVirtualSwitchVlanIdSpec();
    newVlanIdSpec.setVlanId(newvlanId);
    newVmwareDvsPortSetting.setVlan(newVlanIdSpec);
    newTrafficShapingPolicy.setAverageBandwidth(newAvgBw);
    newTrafficShapingPolicy.setBurstSize(newBurstSize);
    newTrafficShapingPolicy.setPeakBandwidth(newPeakBw);
    newTrafficShapingPolicy.setEnabled(newIsEnabled);
    newVmwareDvsPortSetting.setInShapingPolicy(newTrafficShapingPolicy);
    when(dvPortgroupConfigSpec.getNumPorts()).thenReturn(newNumPorts);
    when(dvPortgroupConfigSpec.isAutoExpand()).thenReturn(newAutoExpand);
    when(dvPortgroupConfigSpec.getDefaultPortConfig()).thenReturn(newVmwareDvsPortSetting);
    boolean specCompareResult = HypervisorHostHelper.isSpecMatch(currentDvPortgroupInfo, dvPortgroupConfigSpec, false);
    assertTrue(specCompareResult);
}
Also used : LongPolicy(com.vmware.vim25.LongPolicy) VMwareDVSPortSetting(com.vmware.vim25.VMwareDVSPortSetting) DVSTrafficShapingPolicy(com.vmware.vim25.DVSTrafficShapingPolicy) BoolPolicy(com.vmware.vim25.BoolPolicy) VmwareDistributedVirtualSwitchVlanIdSpec(com.vmware.vim25.VmwareDistributedVirtualSwitchVlanIdSpec) Test(org.junit.Test)

Example 19 with DVSTrafficShapingPolicy

use of com.vmware.vim25.DVSTrafficShapingPolicy in project cloudstack by apache.

the class HypervisorHostHelperTest method testIsSpecMatchConfigSpecWithCurrentShapingPolicyDisabled.

@Test
public void testIsSpecMatchConfigSpecWithCurrentShapingPolicyDisabled() throws Exception {
    int currentNumPorts = 512;
    int currentvlanId = 100;
    boolean currentAutoExpand = true;
    DVSTrafficShapingPolicy currentTrafficShapingPolicy = new DVSTrafficShapingPolicy();
    BoolPolicy currentIsEnabled = new BoolPolicy();
    currentIsEnabled.setValue(false);
    VMwareDVSPortSetting currentVmwareDvsPortSetting = new VMwareDVSPortSetting();
    VmwareDistributedVirtualSwitchVlanIdSpec currentVlanIdSpec = new VmwareDistributedVirtualSwitchVlanIdSpec();
    currentVlanIdSpec.setVlanId(currentvlanId);
    currentVmwareDvsPortSetting.setVlan(currentVlanIdSpec);
    currentTrafficShapingPolicy.setEnabled(currentIsEnabled);
    currentVmwareDvsPortSetting.setInShapingPolicy(currentTrafficShapingPolicy);
    when(currentDvPortgroupInfo.getNumPorts()).thenReturn(currentNumPorts);
    when(currentDvPortgroupInfo.isAutoExpand()).thenReturn(currentAutoExpand);
    when(currentDvPortgroupInfo.getDefaultPortConfig()).thenReturn(currentVmwareDvsPortSetting);
    int newNumPorts = 256;
    int newvlanId = 100;
    boolean newAutoExpand = true;
    DVSTrafficShapingPolicy newTrafficShapingPolicy = new DVSTrafficShapingPolicy();
    BoolPolicy newIsEnabled = new BoolPolicy();
    newIsEnabled.setValue(true);
    LongPolicy newAvgBw = new LongPolicy();
    newAvgBw.setValue(200L);
    LongPolicy newBurstSize = new LongPolicy();
    newBurstSize.setValue(400L);
    LongPolicy newPeakBw = new LongPolicy();
    newPeakBw.setValue(2000L);
    VMwareDVSPortSetting newVmwareDvsPortSetting = new VMwareDVSPortSetting();
    VmwareDistributedVirtualSwitchVlanIdSpec newVlanIdSpec = new VmwareDistributedVirtualSwitchVlanIdSpec();
    newVlanIdSpec.setVlanId(newvlanId);
    newVmwareDvsPortSetting.setVlan(newVlanIdSpec);
    newTrafficShapingPolicy.setAverageBandwidth(newAvgBw);
    newTrafficShapingPolicy.setBurstSize(newBurstSize);
    newTrafficShapingPolicy.setPeakBandwidth(newPeakBw);
    newTrafficShapingPolicy.setEnabled(newIsEnabled);
    newVmwareDvsPortSetting.setInShapingPolicy(newTrafficShapingPolicy);
    when(dvPortgroupConfigSpec.getNumPorts()).thenReturn(newNumPorts);
    when(dvPortgroupConfigSpec.isAutoExpand()).thenReturn(newAutoExpand);
    when(dvPortgroupConfigSpec.getDefaultPortConfig()).thenReturn(newVmwareDvsPortSetting);
    boolean specCompareResult = HypervisorHostHelper.isSpecMatch(currentDvPortgroupInfo, dvPortgroupConfigSpec, false);
    assertFalse(specCompareResult);
}
Also used : LongPolicy(com.vmware.vim25.LongPolicy) VMwareDVSPortSetting(com.vmware.vim25.VMwareDVSPortSetting) DVSTrafficShapingPolicy(com.vmware.vim25.DVSTrafficShapingPolicy) BoolPolicy(com.vmware.vim25.BoolPolicy) VmwareDistributedVirtualSwitchVlanIdSpec(com.vmware.vim25.VmwareDistributedVirtualSwitchVlanIdSpec) Test(org.junit.Test)

Aggregations

DVSTrafficShapingPolicy (com.vmware.vim25.DVSTrafficShapingPolicy)14 BoolPolicy (com.vmware.vim25.BoolPolicy)12 VMwareDVSPortSetting (com.vmware.vim25.VMwareDVSPortSetting)12 LongPolicy (com.vmware.vim25.LongPolicy)11 VmwareDistributedVirtualSwitchVlanIdSpec (com.vmware.vim25.VmwareDistributedVirtualSwitchVlanIdSpec)8 Test (org.junit.Test)7 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)5 URISyntaxException (java.net.URISyntaxException)5 CloudException (com.cloud.exception.CloudException)4 IOException (java.io.IOException)4 InvalidParameterException (java.security.InvalidParameterException)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 TransformerException (javax.xml.transform.TransformerException)4 SAXException (org.xml.sax.SAXException)4 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)3 Pair (com.cloud.utils.Pair)3 DVPortgroupConfigInfo (com.vmware.vim25.DVPortgroupConfigInfo)3 BroadcastDomainType (com.cloud.network.Networks.BroadcastDomainType)2 DVPortgroupConfigSpec (com.vmware.vim25.DVPortgroupConfigSpec)2