Search in sources :

Example 6 with BroadcastDomainType

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

the class NiciraNvpElement method implement.

@Override
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    s_logger.debug("entering NiciraNvpElement implement function for network " + network.getDisplayText() + " (state " + network.getState() + ")");
    if (!canHandle(network, Service.Connectivity)) {
        return false;
    }
    if (network.getBroadcastUri() == null) {
        s_logger.error("Nic has no broadcast Uri with the LSwitch Uuid");
        return false;
    }
    List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
    if (devices.isEmpty()) {
        s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId());
        return false;
    }
    NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
    HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
    hostDao.loadDetails(niciraNvpHost);
    Account owner = context.getAccount();
    if (network.getGuestType().equals(GuestType.Shared)) {
        //Support Shared Networks
        String lSwitchUuid = BroadcastDomainType.getValue(network.getBroadcastUri());
        String ownerName = context.getDomain().getName() + "-" + context.getAccount().getAccountName();
        return sharedNetworkSupport(network, lSwitchUuid, ownerName, niciraNvpHost);
    } else if (network.getGuestType().equals(GuestType.Isolated) && networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, Provider.NiciraNvp)) {
        // Implement SourceNat immediately as we have al the info already
        s_logger.debug("Apparently we are supposed to provide SourceNat on this network");
        PublicIp sourceNatIp = ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network);
        String publicCidr = sourceNatIp.getAddress().addr() + "/" + NetUtils.getCidrSize(sourceNatIp.getVlanNetmask());
        String internalCidr = network.getGateway() + "/" + network.getCidr().split("/")[1];
        // assuming a vlan:
        String vtag = sourceNatIp.getVlanTag();
        BroadcastDomainType tiep = null;
        try {
            tiep = BroadcastDomainType.getTypeOf(vtag);
        } catch (URISyntaxException use) {
            throw new CloudRuntimeException("vlantag for sourceNatIp is not valid: " + vtag, use);
        }
        if (tiep == BroadcastDomainType.Vlan) {
            vtag = BroadcastDomainType.Vlan.getValueFrom(BroadcastDomainType.fromString(vtag));
        } else if (!(tiep == BroadcastDomainType.UnDecided || tiep == BroadcastDomainType.Native)) {
            throw new CloudRuntimeException("only vlans are supported for sourceNatIp, at this moment: " + vtag);
        }
        long vlanid = (Vlan.UNTAGGED.equals(vtag)) ? 0 : Long.parseLong(vtag);
        CreateLogicalRouterCommand cmd = new CreateLogicalRouterCommand(niciraNvpHost.getDetail("l3gatewayserviceuuid"), vlanid, BroadcastDomainType.getValue(network.getBroadcastUri()), "router-" + network.getDisplayText(), publicCidr, sourceNatIp.getGateway(), internalCidr, context.getDomain().getName() + "-" + context.getAccount().getAccountName());
        CreateLogicalRouterAnswer answer = (CreateLogicalRouterAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
        if (answer.getResult() == false) {
            s_logger.error("Failed to create Logical Router for network " + network.getDisplayText());
            return false;
        }
        NiciraNvpRouterMappingVO routermapping = new NiciraNvpRouterMappingVO(answer.getLogicalRouterUuid(), network.getId());
        niciraNvpRouterMappingDao.persist(routermapping);
    }
    return true;
}
Also used : Account(com.cloud.user.Account) CreateLogicalRouterCommand(com.cloud.agent.api.CreateLogicalRouterCommand) BroadcastDomainType(com.cloud.network.Networks.BroadcastDomainType) PublicIp(com.cloud.network.addr.PublicIp) NiciraNvpRouterMappingVO(com.cloud.network.NiciraNvpRouterMappingVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) URISyntaxException(java.net.URISyntaxException) CreateLogicalRouterAnswer(com.cloud.agent.api.CreateLogicalRouterAnswer) HostVO(com.cloud.host.HostVO)

Example 7 with BroadcastDomainType

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

the class PrivateNetworkGuru method design.

@Override
public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
    DataCenter dc = _entityMgr.findById(DataCenter.class, plan.getDataCenterId());
    if (!canHandle(offering, dc)) {
        return null;
    }
    BroadcastDomainType broadcastType;
    if (userSpecified != null) {
        broadcastType = userSpecified.getBroadcastDomainType();
    } else {
        broadcastType = BroadcastDomainType.Vlan;
    }
    NetworkVO network = new NetworkVO(offering.getTrafficType(), Mode.Static, broadcastType, offering.getId(), State.Allocated, plan.getDataCenterId(), plan.getPhysicalNetworkId(), offering.getRedundantRouter());
    if (userSpecified != null) {
        if ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) || (userSpecified.getCidr() != null && userSpecified.getGateway() == null)) {
            throw new InvalidParameterValueException("cidr and gateway must be specified together.");
        }
        if (userSpecified.getCidr() != null) {
            network.setCidr(userSpecified.getCidr());
            network.setGateway(userSpecified.getGateway());
        } else {
            throw new InvalidParameterValueException("Can't design network " + network + "; netmask/gateway must be passed in");
        }
        if (offering.getSpecifyVlan()) {
            network.setBroadcastUri(userSpecified.getBroadcastUri());
            network.setState(State.Setup);
        }
    } else {
        throw new CloudRuntimeException("Can't design network " + network + "; netmask/gateway must be passed in");
    }
    return network;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) DataCenter(com.cloud.dc.DataCenter) BroadcastDomainType(com.cloud.network.Networks.BroadcastDomainType) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 8 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 9 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)

Example 10 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)

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