Search in sources :

Example 91 with VlanVO

use of com.cloud.dc.VlanVO in project cloudstack by apache.

the class NetworkModelImpl method isIP6AddressAvailableInVlan.

@Override
public boolean isIP6AddressAvailableInVlan(long vlanId) {
    VlanVO vlan = _vlanDao.findById(vlanId);
    if (vlan.getIp6Range() == null) {
        return false;
    }
    long existedCount = _ipv6Dao.countExistedIpsInVlan(vlanId);
    BigInteger existedInt = BigInteger.valueOf(existedCount);
    BigInteger rangeInt = NetUtils.countIp6InRange(vlan.getIp6Range());
    return (existedInt.compareTo(rangeInt) < 0);
}
Also used : BigInteger(java.math.BigInteger) VlanVO(com.cloud.dc.VlanVO)

Example 92 with VlanVO

use of com.cloud.dc.VlanVO in project cloudstack by apache.

the class NetworkModelImpl method checkRequestedIpAddresses.

@Override
public void checkRequestedIpAddresses(long networkId, IpAddresses ips) throws InvalidParameterValueException {
    String ip4 = ips.getIp4Address();
    String ip6 = ips.getIp6Address();
    String mac = ips.getMacAddress();
    if (ip4 != null) {
        if (!NetUtils.isValidIp4(ip4)) {
            throw new InvalidParameterValueException("Invalid specified IPv4 address " + ip4);
        }
    // Other checks for ipv4 are done in assignPublicIpAddress()
    }
    if (ip6 != null) {
        if (!NetUtils.isValidIp6(ip6)) {
            throw new InvalidParameterValueException("Invalid specified IPv6 address " + ip6);
        }
        if (_ipv6Dao.findByNetworkIdAndIp(networkId, ip6) != null) {
            throw new InvalidParameterValueException("The requested IP is already taken!");
        }
        List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(networkId);
        if (vlans == null) {
            throw new CloudRuntimeException("Cannot find related vlan attached to network " + networkId);
        }
        Vlan ipVlan = null;
        for (Vlan vlan : vlans) {
            if (NetUtils.isIp6InRange(ip6, vlan.getIp6Range())) {
                ipVlan = vlan;
                break;
            }
        }
        if (ipVlan == null) {
            throw new InvalidParameterValueException("Requested IPv6 is not in the predefined range!");
        }
    }
    if (mac != null) {
        if (!NetUtils.isValidMac(mac)) {
            throw new InvalidParameterValueException("Invalid specified MAC address " + mac);
        }
        if (_nicDao.findByNetworkIdAndMacAddress(networkId, mac) != null) {
            throw new InvalidParameterValueException("The requested Mac address is already taken! " + mac);
        }
    }
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Vlan(com.cloud.dc.Vlan) VlanVO(com.cloud.dc.VlanVO)

Example 93 with VlanVO

use of com.cloud.dc.VlanVO in project cloudstack by apache.

the class IpAddressManagerImpl method transferPortableIP.

@DB
@Override
public void transferPortableIP(final long ipAddrId, long currentNetworkId, long newNetworkId) throws ResourceAllocationException, ResourceUnavailableException, InsufficientAddressCapacityException, ConcurrentOperationException {
    Network srcNetwork = _networksDao.findById(currentNetworkId);
    if (srcNetwork == null) {
        throw new InvalidParameterValueException("Invalid source network id " + currentNetworkId + " is given");
    }
    final Network dstNetwork = _networksDao.findById(newNetworkId);
    if (dstNetwork == null) {
        throw new InvalidParameterValueException("Invalid source network id " + newNetworkId + " is given");
    }
    final IPAddressVO ip = _ipAddressDao.findById(ipAddrId);
    if (ip == null) {
        throw new InvalidParameterValueException("Invalid portable ip address id is given");
    }
    assert (isPortableIpTransferableFromNetwork(ipAddrId, currentNetworkId));
    // disassociate portable IP with current network/VPC network
    if (srcNetwork.getVpcId() != null) {
        _vpcMgr.unassignIPFromVpcNetwork(ipAddrId, currentNetworkId);
    } else {
        disassociatePortableIPToGuestNetwork(ipAddrId, currentNetworkId);
    }
    // in user_ip_address and vlan tables so as to emulate portable IP as provisioned in destination data center
    if (srcNetwork.getDataCenterId() != dstNetwork.getDataCenterId()) {
        Transaction.execute(new TransactionCallbackNoReturn() {

            @Override
            public void doInTransactionWithoutResult(TransactionStatus status) {
                long physicalNetworkId = _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(dstNetwork.getDataCenterId(), TrafficType.Public).getId();
                long publicNetworkId = _networkModel.getSystemNetworkByZoneAndTrafficType(dstNetwork.getDataCenterId(), TrafficType.Public).getId();
                ip.setDataCenterId(dstNetwork.getDataCenterId());
                ip.setPhysicalNetworkId(physicalNetworkId);
                ip.setSourceNetworkId(publicNetworkId);
                _ipAddressDao.update(ipAddrId, ip);
                VlanVO vlan = _vlanDao.findById(ip.getVlanId());
                vlan.setPhysicalNetworkId(physicalNetworkId);
                vlan.setNetworkId(publicNetworkId);
                vlan.setDataCenterId(dstNetwork.getDataCenterId());
                _vlanDao.update(ip.getVlanId(), vlan);
            }
        });
    }
    // associate portable IP with new network/VPC network
    associatePortableIPToGuestNetwork(ipAddrId, newNetworkId, false);
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) {
            if (dstNetwork.getVpcId() != null) {
                ip.setVpcId(dstNetwork.getVpcId());
            } else {
                ip.setVpcId(null);
            }
            _ipAddressDao.update(ipAddrId, ip);
        }
    });
    // trigger an action event for the transfer of portable IP across the networks, so that external entities
    // monitoring for this event can initiate the route advertisement for the availability of IP from the zoe
    ActionEventUtils.onActionEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, Domain.ROOT_DOMAIN, EventTypes.EVENT_PORTABLE_IP_TRANSFER, "Portable IP associated is transferred from network " + currentNetworkId + " to " + newNetworkId);
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) TransactionStatus(com.cloud.utils.db.TransactionStatus) IPAddressVO(com.cloud.network.dao.IPAddressVO) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) VlanVO(com.cloud.dc.VlanVO) DB(com.cloud.utils.db.DB)

Example 94 with VlanVO

use of com.cloud.dc.VlanVO in project cloudstack by apache.

the class NetworkServiceImpl method deletePhysicalNetwork.

@Override
@ActionEvent(eventType = EventTypes.EVENT_PHYSICAL_NETWORK_DELETE, eventDescription = "deleting physical network", async = true)
@DB
public boolean deletePhysicalNetwork(final Long physicalNetworkId) {
    // verify input parameters
    PhysicalNetworkVO pNetwork = _physicalNetworkDao.findById(physicalNetworkId);
    if (pNetwork == null) {
        throwInvalidIdException("Physical Network with specified id doesn't exist in the system", physicalNetworkId.toString(), "physicalNetworkId");
    }
    checkIfPhysicalNetworkIsDeletable(physicalNetworkId);
    return Transaction.execute(new TransactionCallback<Boolean>() {

        @Override
        public Boolean doInTransaction(TransactionStatus status) {
            // delete vlans for this zone
            List<VlanVO> vlans = _vlanDao.listVlansByPhysicalNetworkId(physicalNetworkId);
            for (VlanVO vlan : vlans) {
                _vlanDao.remove(vlan.getId());
            }
            // Delete networks
            List<NetworkVO> networks = _networksDao.listByPhysicalNetwork(physicalNetworkId);
            if (networks != null && !networks.isEmpty()) {
                for (NetworkVO network : networks) {
                    _networksDao.remove(network.getId());
                }
            }
            // delete vnets
            _dcDao.deleteVnet(physicalNetworkId);
            // delete service providers
            List<PhysicalNetworkServiceProviderVO> providers = _pNSPDao.listBy(physicalNetworkId);
            for (PhysicalNetworkServiceProviderVO provider : providers) {
                try {
                    deleteNetworkServiceProvider(provider.getId());
                } catch (ResourceUnavailableException e) {
                    s_logger.warn("Unable to complete destroy of the physical network provider: " + provider.getProviderName() + ", id: " + provider.getId(), e);
                    return false;
                } catch (ConcurrentOperationException e) {
                    s_logger.warn("Unable to complete destroy of the physical network provider: " + provider.getProviderName() + ", id: " + provider.getId(), e);
                    return false;
                }
            }
            // delete traffic types
            _pNTrafficTypeDao.deleteTrafficTypes(physicalNetworkId);
            return _physicalNetworkDao.remove(physicalNetworkId);
        }
    });
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) TransactionStatus(com.cloud.utils.db.TransactionStatus) ArrayList(java.util.ArrayList) List(java.util.List) VlanVO(com.cloud.dc.VlanVO) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 95 with VlanVO

use of com.cloud.dc.VlanVO in project cloudstack by apache.

the class DirectPodBasedNetworkGuru method getIp.

@DB
protected void getIp(final NicProfile nic, final Pod pod, final VirtualMachineProfile vm, final Network network) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException {
    final DataCenter dc = _dcDao.findById(pod.getDataCenterId());
    Transaction.execute(new TransactionCallbackWithExceptionNoReturn<InsufficientAddressCapacityException>() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) throws InsufficientAddressCapacityException {
            PublicIp ip = null;
            List<PodVlanMapVO> podRefs = _podVlanDao.listPodVlanMapsByPod(pod.getId());
            VlanVO vlan = _vlanDao.findById(podRefs.get(0).getVlanDbId());
            if (nic.getIPv4Address() == null) {
                String podRangeGateway = null;
                if (!podRefs.isEmpty()) {
                    podRangeGateway = vlan.getVlanGateway();
                }
                // Get ip address from the placeholder and don't allocate a new one
                if (vm.getType() == VirtualMachine.Type.DomainRouter) {
                    Nic placeholderNic = _networkModel.getPlaceholderNicForRouter(network, pod.getId());
                    if (placeholderNic != null) {
                        IPAddressVO userIp = _ipAddressDao.findByIpAndSourceNetworkId(network.getId(), placeholderNic.getIPv4Address());
                        ip = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
                        s_logger.debug("Nic got an ip address " + placeholderNic.getIPv4Address() + " stored in placeholder nic for the network " + network + " and gateway " + podRangeGateway);
                    }
                }
                if (ip == null) {
                    ip = _ipAddrMgr.assignPublicIpAddress(dc.getId(), pod.getId(), vm.getOwner(), VlanType.DirectAttached, network.getId(), null, false, false);
                }
                nic.setIPv4Address(ip.getAddress().toString());
                nic.setFormat(AddressFormat.Ip4);
                nic.setIPv4Gateway(ip.getGateway());
                nic.setIPv4Netmask(ip.getNetmask());
                if (ip.getVlanTag() != null && ip.getVlanTag().equalsIgnoreCase(Vlan.UNTAGGED)) {
                    nic.setIsolationUri(IsolationType.Ec2.toUri(Vlan.UNTAGGED));
                    nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(Vlan.UNTAGGED));
                    nic.setBroadcastType(BroadcastDomainType.Native);
                }
                nic.setReservationId(String.valueOf(ip.getVlanTag()));
                nic.setMacAddress(ip.getMacAddress());
                // save the placeholder nic if the vm is the Virtual router
                if (vm.getType() == VirtualMachine.Type.DomainRouter) {
                    Nic placeholderNic = _networkModel.getPlaceholderNicForRouter(network, pod.getId());
                    if (placeholderNic == null) {
                        s_logger.debug("Saving placeholder nic with ip4 address " + nic.getIPv4Address() + " for the network " + network);
                        _networkMgr.savePlaceholderNic(network, nic.getIPv4Address(), null, VirtualMachine.Type.DomainRouter);
                    }
                }
            }
            /**
             * Calculate the IPv6 Address the Instance will obtain using SLAAC and IPv6 EUI-64
             *
             * Linux, FreeBSD and Windows all calculate the same IPv6 address when configured properly.
             *
             * Using Router Advertisements the routers in the network should announce the IPv6 CIDR which is configured
             * in in the vlan table in the database.
             *
             * This way the NIC will be populated with a IPv6 address on which the Instance is reachable.
             */
            if (vlan.getIp6Cidr() != null) {
                if (nic.getIPv6Address() == null) {
                    s_logger.debug("Found IPv6 CIDR " + vlan.getIp6Cidr() + " for VLAN " + vlan.getId());
                    nic.setIPv6Cidr(vlan.getIp6Cidr());
                    nic.setIPv6Gateway(vlan.getIp6Gateway());
                    IPv6Address ipv6addr = NetUtils.EUI64Address(vlan.getIp6Cidr(), nic.getMacAddress());
                    s_logger.info("Calculated IPv6 address " + ipv6addr + " using EUI-64 for NIC " + nic.getUuid());
                    nic.setIPv6Address(ipv6addr.toString());
                }
            } else {
                s_logger.debug("No IPv6 CIDR configured for VLAN " + vlan.getId());
            }
        }
    });
    nic.setIPv4Dns1(dc.getDns1());
    nic.setIPv4Dns2(dc.getDns2());
}
Also used : DataCenter(com.cloud.dc.DataCenter) PublicIp(com.cloud.network.addr.PublicIp) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) IPv6Address(com.googlecode.ipv6.IPv6Address) TransactionStatus(com.cloud.utils.db.TransactionStatus) Nic(com.cloud.vm.Nic) List(java.util.List) IPAddressVO(com.cloud.network.dao.IPAddressVO) VlanVO(com.cloud.dc.VlanVO) DB(com.cloud.utils.db.DB)

Aggregations

VlanVO (com.cloud.dc.VlanVO)103 ArrayList (java.util.ArrayList)39 IPAddressVO (com.cloud.network.dao.IPAddressVO)25 DB (com.cloud.utils.db.DB)25 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)23 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)21 TransactionStatus (com.cloud.utils.db.TransactionStatus)18 Network (com.cloud.network.Network)17 Account (com.cloud.user.Account)17 AccountVlanMapVO (com.cloud.dc.AccountVlanMapVO)15 List (java.util.List)15 DomainVlanMapVO (com.cloud.dc.DomainVlanMapVO)12 ActionEvent (com.cloud.event.ActionEvent)12 HostVO (com.cloud.host.HostVO)12 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)12 Vlan (com.cloud.dc.Vlan)11 NetworkVO (com.cloud.network.dao.NetworkVO)11 DataCenter (com.cloud.dc.DataCenter)10 DataCenterVO (com.cloud.dc.DataCenterVO)10 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)10