Search in sources :

Example 1 with NiciraNvpRouterMappingVO

use of com.cloud.network.NiciraNvpRouterMappingVO 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 2 with NiciraNvpRouterMappingVO

use of com.cloud.network.NiciraNvpRouterMappingVO in project cloudstack by apache.

the class NiciraNvpElement method applyPFRules.

/**
     * From interface PortForwardingServiceProvider
     */
@Override
public boolean applyPFRules(Network network, List<PortForwardingRule> rules) throws ResourceUnavailableException {
    if (!canHandle(network, Service.PortForwarding)) {
        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());
    NiciraNvpRouterMappingVO routermapping = niciraNvpRouterMappingDao.findByNetworkId(network.getId());
    if (routermapping == null) {
        s_logger.error("No logical router uuid found for network " + network.getDisplayText());
        return false;
    }
    List<PortForwardingRuleTO> portForwardingRules = new ArrayList<PortForwardingRuleTO>();
    for (PortForwardingRule rule : rules) {
        IpAddress sourceIp = networkModel.getIp(rule.getSourceIpAddressId());
        Vlan vlan = vlanDao.findById(sourceIp.getVlanId());
        PortForwardingRuleTO ruleTO = new PortForwardingRuleTO(rule, vlan.getVlanTag(), sourceIp.getAddress().addr());
        portForwardingRules.add(ruleTO);
    }
    ConfigurePortForwardingRulesOnLogicalRouterCommand cmd = new ConfigurePortForwardingRulesOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), portForwardingRules);
    ConfigurePortForwardingRulesOnLogicalRouterAnswer answer = (ConfigurePortForwardingRulesOnLogicalRouterAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
    return answer.getResult();
}
Also used : PortForwardingRuleTO(com.cloud.agent.api.to.PortForwardingRuleTO) NiciraNvpRouterMappingVO(com.cloud.network.NiciraNvpRouterMappingVO) ConfigurePortForwardingRulesOnLogicalRouterCommand(com.cloud.agent.api.ConfigurePortForwardingRulesOnLogicalRouterCommand) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) ArrayList(java.util.ArrayList) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) Vlan(com.cloud.dc.Vlan) PortForwardingRule(com.cloud.network.rules.PortForwardingRule) ConfigurePortForwardingRulesOnLogicalRouterAnswer(com.cloud.agent.api.ConfigurePortForwardingRulesOnLogicalRouterAnswer) HostVO(com.cloud.host.HostVO)

Example 3 with NiciraNvpRouterMappingVO

use of com.cloud.network.NiciraNvpRouterMappingVO in project cloudstack by apache.

the class NiciraNvpElement method applyIps.

/**
     * From interface IpDeployer
     *
     * @param network
     * @param ipAddress
     * @param services
     * @return
     * @throws ResourceUnavailableException
     */
@Override
public boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddress, Set<Service> services) throws ResourceUnavailableException {
    if (services.contains(Service.SourceNat)) {
        // Only if we need to provide SourceNat we need to configure the logical router
        // SourceNat is required for StaticNat and PortForwarding
        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);
        NiciraNvpRouterMappingVO routermapping = niciraNvpRouterMappingDao.findByNetworkId(network.getId());
        if (routermapping == null) {
            s_logger.error("No logical router uuid found for network " + network.getDisplayText());
            return false;
        }
        List<String> cidrs = new ArrayList<String>();
        for (PublicIpAddress ip : ipAddress) {
            if (ip.getState() == IpAddress.State.Releasing) {
                // the Logical Router
                continue;
            }
            cidrs.add(ip.getAddress().addr() + "/" + NetUtils.getCidrSize(ip.getNetmask()));
        }
        ConfigurePublicIpsOnLogicalRouterCommand cmd = new ConfigurePublicIpsOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), niciraNvpHost.getDetail("l3gatewayserviceuuid"), cidrs);
        ConfigurePublicIpsOnLogicalRouterAnswer answer = (ConfigurePublicIpsOnLogicalRouterAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
        //FIXME answer can be null if the host is down
        return answer.getResult();
    } else {
        s_logger.debug("No need to provision ip addresses as we are not providing L3 services.");
    }
    return true;
}
Also used : PublicIpAddress(com.cloud.network.PublicIpAddress) NiciraNvpRouterMappingVO(com.cloud.network.NiciraNvpRouterMappingVO) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) ArrayList(java.util.ArrayList) ConfigurePublicIpsOnLogicalRouterAnswer(com.cloud.agent.api.ConfigurePublicIpsOnLogicalRouterAnswer) HostVO(com.cloud.host.HostVO) ConfigurePublicIpsOnLogicalRouterCommand(com.cloud.agent.api.ConfigurePublicIpsOnLogicalRouterCommand)

Example 4 with NiciraNvpRouterMappingVO

use of com.cloud.network.NiciraNvpRouterMappingVO in project cloudstack by apache.

the class NiciraNvpGuestNetworkGuru method trash.

@Override
public boolean trash(final Network network, final NetworkOffering offering) {
    //Since NVP Plugin supports Shared networks, remove mapping when deleting network implemented or allocated
    if (network.getGuestType() == GuestType.Shared && niciraNvpRouterMappingDao.existsMappingForNetworkId(network.getId())) {
        NiciraNvpRouterMappingVO mappingVO = niciraNvpRouterMappingDao.findByNetworkId(network.getId());
        niciraNvpRouterMappingDao.remove(mappingVO.getId());
    }
    return super.trash(network, offering);
}
Also used : NiciraNvpRouterMappingVO(com.cloud.network.NiciraNvpRouterMappingVO)

Example 5 with NiciraNvpRouterMappingVO

use of com.cloud.network.NiciraNvpRouterMappingVO in project cloudstack by apache.

the class NiciraNvpGuestNetworkGuru method sharedNetworksCleanup.

private void sharedNetworksCleanup(NetworkVO networkObject, String logicalSwitchUuid, HostVO niciraNvpHost) {
    NiciraNvpRouterMappingVO routermapping = niciraNvpRouterMappingDao.findByNetworkId(networkObject.getId());
    if (routermapping == null) {
        // Case 1: Numerical Vlan Provided -> No lrouter used.
        s_logger.info("Shared Network " + networkObject.getDisplayText() + " didn't use Logical Router");
    } else {
        //Case 2: Logical Router's UUID provided as Vlan id -> Remove lrouter port but not lrouter.
        String lRouterUuid = routermapping.getLogicalRouterUuid();
        s_logger.debug("Finding Logical Router Port on Logical Router " + lRouterUuid + " with attachment_lswitch_uuid=" + logicalSwitchUuid + " to delete it");
        final FindLogicalRouterPortCommand cmd = new FindLogicalRouterPortCommand(lRouterUuid, logicalSwitchUuid);
        final FindLogicalRouterPortAnswer answer = (FindLogicalRouterPortAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
        if (answer != null && answer.getResult()) {
            String logicalRouterPortUuid = answer.getLogicalRouterPortUuid();
            s_logger.debug("Found Logical Router Port " + logicalRouterPortUuid + ", deleting it");
            final DeleteLogicalRouterPortCommand cmdDeletePort = new DeleteLogicalRouterPortCommand(lRouterUuid, logicalRouterPortUuid);
            final DeleteLogicalRouterPortAnswer answerDelete = (DeleteLogicalRouterPortAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmdDeletePort);
            if (answerDelete != null && answerDelete.getResult()) {
                s_logger.info("Successfully deleted Logical Router Port " + logicalRouterPortUuid);
            } else {
                s_logger.error("Could not delete Logical Router Port " + logicalRouterPortUuid);
            }
        } else {
            s_logger.error("Find Logical Router Port failed");
        }
    }
}
Also used : DeleteLogicalRouterPortAnswer(com.cloud.agent.api.DeleteLogicalRouterPortAnswer) NiciraNvpRouterMappingVO(com.cloud.network.NiciraNvpRouterMappingVO) FindLogicalRouterPortAnswer(com.cloud.agent.api.FindLogicalRouterPortAnswer) FindLogicalRouterPortCommand(com.cloud.agent.api.FindLogicalRouterPortCommand) DeleteLogicalRouterPortCommand(com.cloud.agent.api.DeleteLogicalRouterPortCommand)

Aggregations

NiciraNvpRouterMappingVO (com.cloud.network.NiciraNvpRouterMappingVO)11 HostVO (com.cloud.host.HostVO)7 NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)7 PublicIpAddress (com.cloud.network.PublicIpAddress)4 ArrayList (java.util.ArrayList)4 ConfigurePublicIpsOnLogicalRouterAnswer (com.cloud.agent.api.ConfigurePublicIpsOnLogicalRouterAnswer)2 ConfigurePublicIpsOnLogicalRouterCommand (com.cloud.agent.api.ConfigurePublicIpsOnLogicalRouterCommand)2 ConfigureSharedNetworkUuidAnswer (com.cloud.agent.api.ConfigureSharedNetworkUuidAnswer)2 IpAddress (com.cloud.network.IpAddress)2 Network (com.cloud.network.Network)2 PublicIp (com.cloud.network.addr.PublicIp)2 NetworkOffering (com.cloud.offering.NetworkOffering)2 Account (com.cloud.user.Account)2 Test (org.junit.Test)2 ConfigurePortForwardingRulesOnLogicalRouterAnswer (com.cloud.agent.api.ConfigurePortForwardingRulesOnLogicalRouterAnswer)1 ConfigurePortForwardingRulesOnLogicalRouterCommand (com.cloud.agent.api.ConfigurePortForwardingRulesOnLogicalRouterCommand)1 ConfigureSharedNetworkUuidCommand (com.cloud.agent.api.ConfigureSharedNetworkUuidCommand)1 ConfigureStaticNatRulesOnLogicalRouterAnswer (com.cloud.agent.api.ConfigureStaticNatRulesOnLogicalRouterAnswer)1 ConfigureStaticNatRulesOnLogicalRouterCommand (com.cloud.agent.api.ConfigureStaticNatRulesOnLogicalRouterCommand)1 CreateLogicalRouterAnswer (com.cloud.agent.api.CreateLogicalRouterAnswer)1