Search in sources :

Example 11 with BroadcastDomainType

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

the class CitrixResourceBase method getNetwork.

public Network getNetwork(final Connection conn, final NicTO nic) throws XenAPIException, XmlRpcException {
    final String name = nic.getName();
    final XsLocalNetwork network = getNativeNetworkForTraffic(conn, nic.getType(), name);
    if (network == null) {
        s_logger.error("Network is not configured on the backend for nic " + nic.toString());
        throw new CloudRuntimeException("Network for the backend is not configured correctly for network broadcast domain: " + nic.getBroadcastUri());
    }
    final URI uri = nic.getBroadcastUri();
    final BroadcastDomainType type = nic.getBroadcastType();
    if (uri != null && uri.toString().contains("untagged")) {
        return network.getNetwork();
    } else if (uri != null && type == BroadcastDomainType.Vlan) {
        assert BroadcastDomainType.getSchemeValue(uri) == BroadcastDomainType.Vlan;
        final long vlan = Long.parseLong(BroadcastDomainType.getValue(uri));
        return enableVlanNetwork(conn, vlan, network);
    } else if (type == BroadcastDomainType.Native || type == BroadcastDomainType.LinkLocal || type == BroadcastDomainType.Vsp) {
        return network.getNetwork();
    } else if (uri != null && type == BroadcastDomainType.Vswitch) {
        final String header = uri.toString().substring(Networks.BroadcastDomainType.Vswitch.scheme().length() + "://".length());
        if (header.startsWith("vlan")) {
            _isOvs = true;
            return setupvSwitchNetwork(conn);
        } else {
            return findOrCreateTunnelNetwork(conn, getOvsTunnelNetworkName(uri.getAuthority()));
        }
    } else if (type == BroadcastDomainType.Storage) {
        if (uri == null) {
            return network.getNetwork();
        } else {
            final long vlan = Long.parseLong(BroadcastDomainType.getValue(uri));
            return enableVlanNetwork(conn, vlan, network);
        }
    } else if (type == BroadcastDomainType.Lswitch) {
        // Nicira Logical Switch
        return network.getNetwork();
    } else if (uri != null && type == BroadcastDomainType.Pvlan) {
        assert BroadcastDomainType.getSchemeValue(uri) == BroadcastDomainType.Pvlan;
        // should we consider moving this NetUtils method to
        // BroadcastDomainType?
        final long vlan = Long.parseLong(NetUtils.getPrimaryPvlanFromUri(uri));
        return enableVlanNetwork(conn, vlan, network);
    }
    throw new CloudRuntimeException("Unable to support this type of network broadcast domain: " + nic.getBroadcastUri());
}
Also used : BroadcastDomainType(com.cloud.network.Networks.BroadcastDomainType) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) URI(java.net.URI)

Example 12 with BroadcastDomainType

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

the class NetworksTest method otherTypesTest.

@Test
public void otherTypesTest() throws URISyntaxException {
    String bogeyUri = "lswitch://0";
    String uri1 = "lswitch:1";
    String uri2 = "mido://2";
    BroadcastDomainType type = BroadcastDomainType.getTypeOf(bogeyUri);
    String id = BroadcastDomainType.getValue(bogeyUri);
    Assert.assertEquals("uri0 should be of broadcasttype vlan", BroadcastDomainType.Lswitch, type);
    Assert.assertEquals("id0 should be \"//0\"", "//0", id);
    type = BroadcastDomainType.getTypeOf(uri1);
    id = BroadcastDomainType.getValue(uri1);
    Assert.assertEquals("uri1 should be of broadcasttype vlan", BroadcastDomainType.Lswitch, type);
    Assert.assertEquals("id1 should be \"1\"", "1", id);
    type = BroadcastDomainType.getTypeOf(uri2);
    id = BroadcastDomainType.getValue(uri2);
    Assert.assertEquals("uri2 should be of broadcasttype vlan", BroadcastDomainType.Mido, type);
    Assert.assertEquals("id2 should be \"2\"", "2", id);
}
Also used : BroadcastDomainType(com.cloud.network.Networks.BroadcastDomainType) Test(org.junit.Test)

Example 13 with BroadcastDomainType

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

the class NetworksTest method vlanValueTest.

@Test
public void vlanValueTest() throws URISyntaxException {
    String uri1 = "vlan://1";
    String uri2 = "1";
    String vtag = BroadcastDomainType.Vlan.getValueFrom(BroadcastDomainType.fromString(uri1));
    Assert.assertEquals("vtag should be \"1\"", "1", vtag);
    BroadcastDomainType tiep1 = BroadcastDomainType.getTypeOf(uri1);
    Assert.assertEquals("the type of uri1 should be 'Vlan'", BroadcastDomainType.Vlan, tiep1);
    BroadcastDomainType tiep2 = BroadcastDomainType.getTypeOf(uri2);
    Assert.assertEquals("the type of uri1 should be 'Undecided'", BroadcastDomainType.UnDecided, tiep2);
    BroadcastDomainType tiep3 = BroadcastDomainType.getTypeOf(Vlan.UNTAGGED);
    Assert.assertEquals("the type of uri1 should be 'vlan'", BroadcastDomainType.Native, tiep3);
}
Also used : BroadcastDomainType(com.cloud.network.Networks.BroadcastDomainType) Test(org.junit.Test)

Aggregations

BroadcastDomainType (com.cloud.network.Networks.BroadcastDomainType)13 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)7 Test (org.junit.Test)5 DataCenterVO (com.cloud.dc.DataCenterVO)3 NetworkVO (com.cloud.network.dao.NetworkVO)3 NetworkOfferingVO (com.cloud.offerings.NetworkOfferingVO)3 Account (com.cloud.user.Account)3 URISyntaxException (java.net.URISyntaxException)3 InvalidParameterException (java.security.InvalidParameterException)3 CloudException (com.cloud.exception.CloudException)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 Pair (com.cloud.utils.Pair)2 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)2 IOException (java.io.IOException)2 URI (java.net.URI)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 TransformerException (javax.xml.transform.TransformerException)2 SAXException (org.xml.sax.SAXException)2 CreateLogicalRouterAnswer (com.cloud.agent.api.CreateLogicalRouterAnswer)1 CreateLogicalRouterCommand (com.cloud.agent.api.CreateLogicalRouterCommand)1