Search in sources :

Example 56 with Uuid

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid in project netvirt by opendaylight.

the class RouterToVpnListener method onRouterDisassociatedFromVpn.

/**
 * router disassociation from vpn.
 */
@Override
public void onRouterDisassociatedFromVpn(RouterDisassociatedFromVpn notification) {
    String routerName = notification.getRouterId().getValue();
    String vpnName = notification.getVpnId().getValue();
    WriteTransaction writeFlowInvTx = dataBroker.newWriteOnlyTransaction();
    // check router is associated to external network
    String extNetwork = NatUtil.getAssociatedExternalNetwork(dataBroker, routerName);
    if (extNetwork != null) {
        LOG.debug("onRouterDisassociatedFromVpn : Router {} is associated with ext nw {}", routerName, extNetwork);
        handleDNATConfigurationForRouterDisassociation(routerName, vpnName, extNetwork);
        Uuid extNetworkUuid = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
        if (extNetworkUuid == null) {
            LOG.error("onRouterDisassociatedFromVpn : Unable to retrieve external network Uuid for router {}", routerName);
            return;
        }
        ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, extNetworkUuid);
        if (extNwProvType == null) {
            LOG.error("onRouterDisassociatedFromVpn : External Network Provider Type missing");
            return;
        }
        long routerId = NatUtil.getVpnId(dataBroker, routerName);
        externalRoutersListener.changeBgpVpnIdToLocalVpnId(routerName, routerId, vpnName, writeFlowInvTx, extNwProvType);
    } else {
        LOG.debug("onRouterDisassociatedFromVpn : Ignoring the Router {} association with VPN {} " + "since it is not external router", routerName, vpnName);
    }
    NatUtil.waitForTransactionToComplete(writeFlowInvTx);
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)

Example 57 with Uuid

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid in project netvirt by opendaylight.

the class FloatingIPListener method addOrDelDefaultFibRouteForDnat.

private void addOrDelDefaultFibRouteForDnat(BigInteger dpnId, String routerName, long routerId, WriteTransaction tx, boolean create) {
    Boolean wrTxPresent = true;
    if (tx == null) {
        wrTxPresent = false;
        tx = dataBroker.newWriteOnlyTransaction();
    }
    // Check if the router to bgp-vpn association is present
    long associatedVpnId = NatConstants.INVALID_ID;
    Uuid associatedVpn = NatUtil.getVpnForRouter(dataBroker, routerName);
    if (associatedVpn != null) {
        associatedVpnId = NatUtil.getVpnId(dataBroker, associatedVpn.getValue());
    }
    if (create) {
        if (associatedVpnId != NatConstants.INVALID_ID) {
            LOG.debug("addOrDelDefaultFibRouteForDnat: Install NAT default route on DPN {} for the router {} with " + "vpn-id {}", dpnId, routerName, associatedVpnId);
            defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, associatedVpnId, routerId, tx);
        } else {
            LOG.debug("addOrDelDefaultFibRouteForDnat: Install NAT default route on DPN {} for the router {} with " + "vpn-id {}", dpnId, routerName, routerId);
            defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, routerId, tx);
        }
    } else {
        if (associatedVpnId != NatConstants.INVALID_ID) {
            LOG.debug("addOrDelDefaultFibRouteForDnat: Remove NAT default route on DPN {} for the router {} " + "with vpn-id {}", dpnId, routerName, associatedVpnId);
            defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, associatedVpnId, routerId, tx);
        } else {
            LOG.debug("addOrDelDefaultFibRouteForDnat: Remove NAT default route on DPN {} for the router {} " + "with vpn-id {}", dpnId, routerName, routerId);
            defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, routerId, tx);
        }
    }
    if (!wrTxPresent) {
        tx.submit();
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)

Example 58 with Uuid

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid in project netvirt by opendaylight.

the class FloatingIPListener method removeNATFlowEntries.

void removeNATFlowEntries(String interfaceName, final InternalToExternalPortMap mapping, InstanceIdentifier<RouterPorts> portIid, final String routerName, BigInteger dpnId, WriteTransaction removeFlowInvTx) {
    String internalIp = mapping.getInternalIp();
    String externalIp = mapping.getExternalIp();
    // Get the DPN on which this interface resides
    if (dpnId == null) {
        dpnId = NatUtil.getDpnForInterface(interfaceManager, interfaceName);
        if (dpnId.equals(BigInteger.ZERO)) {
            LOG.warn("removeNATFlowEntries: Abort processing Floating ip configuration. No DPN for port: {}", interfaceName);
            return;
        }
    }
    long routerId = NatUtil.getVpnId(dataBroker, routerName);
    if (routerId == NatConstants.INVALID_ID) {
        LOG.error("removeNATFlowEntries : Could not retrieve router id for {} to remove NAT Flow entries", routerName);
        return;
    }
    // Delete the DNAT and SNAT table entries
    removeDNATTblEntry(dpnId, internalIp, externalIp, routerId, removeFlowInvTx);
    Uuid extNwId = getExtNetworkId(portIid, LogicalDatastoreType.OPERATIONAL);
    if (extNwId == null) {
        LOG.error("removeNATFlowEntries : External network associated with interface {} could not be retrieved", interfaceName);
        return;
    }
    long vpnId = getVpnId(extNwId, mapping.getExternalId());
    if (vpnId < 0) {
        LOG.error("removeNATFlowEntries : No VPN associated with ext nw {}. Unable to delete SNAT table " + "entry for fixed ip {}", extNwId, internalIp);
        return;
    }
    removeSNATTblEntry(dpnId, internalIp, externalIp, routerId, vpnId, removeFlowInvTx);
    // Remove the DNAT default FIB flow L3_FIB_TABLE (21) -> PSNAT_TABLE (26) if SNAT is disabled
    boolean isSnatEnabled = NatUtil.isSnatEnabledForRouterId(dataBroker, routerName);
    if (!isSnatEnabled) {
        addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, removeFlowInvTx, false);
    }
    ProviderTypes provType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, extNwId);
    if (provType == null) {
        LOG.error("removeNATFlowEntries : External Network Provider Type missing");
        return;
    }
    if (provType == ProviderTypes.VXLAN) {
        floatingIPHandler.onRemoveFloatingIp(dpnId, routerName, routerId, extNwId, mapping, NatConstants.DEFAULT_L3VNI_VALUE, removeFlowInvTx);
        removeOperationalDS(routerName, interfaceName, internalIp);
        return;
    }
    long label = getOperationalIpMapping(routerName, interfaceName, internalIp);
    if (label < 0) {
        LOG.error("removeNATFlowEntries : Could not retrieve label for prefix {} in router {}", internalIp, routerId);
        return;
    }
    floatingIPHandler.onRemoveFloatingIp(dpnId, routerName, routerId, extNwId, mapping, (int) label, removeFlowInvTx);
    removeOperationalDS(routerName, interfaceName, internalIp);
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)

Example 59 with Uuid

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid in project netvirt by opendaylight.

the class FloatingIPListener method createNATFlowEntries.

void createNATFlowEntries(String interfaceName, final InternalToExternalPortMap mapping, final InstanceIdentifier<RouterPorts> portIid, final String routerName, WriteTransaction writeFlowInvTx) {
    if (!validateIpMapping(mapping)) {
        LOG.error("createNATFlowEntries : Not a valid ip addresses in the mapping {}", mapping);
        return;
    }
    // Get the DPN on which this interface resides
    BigInteger dpnId = NatUtil.getDpnForInterface(interfaceManager, interfaceName);
    if (dpnId.equals(BigInteger.ZERO)) {
        LOG.warn("createNATFlowEntries : No DPN for interface {}. NAT flow entries for ip mapping {} will " + "not be installed", interfaceName, mapping);
        return;
    }
    long routerId = NatUtil.getVpnId(dataBroker, routerName);
    if (routerId == NatConstants.INVALID_ID) {
        LOG.error("createNATFlowEntries : Could not retrieve router id for {} to create NAT Flow entries", routerName);
        return;
    }
    // Check if the router to vpn association is present
    // long associatedVpnId = NatUtil.getAssociatedVpn(dataBroker, routerName);
    Uuid associatedVpn = NatUtil.getVpnForRouter(dataBroker, routerName);
    long associatedVpnId = NatConstants.INVALID_ID;
    if (associatedVpn == null) {
        LOG.debug("createNATFlowEntries : Router {} is not assicated with any BGP VPN instance", routerName);
    } else {
        LOG.debug("createNATFlowEntries : Router {} is associated with VPN Instance with Id {}", routerName, associatedVpn);
        associatedVpnId = NatUtil.getVpnId(dataBroker, associatedVpn.getValue());
        LOG.debug("createNATFlowEntries : vpninstance Id is {} for VPN {}", associatedVpnId, associatedVpn);
    // routerId = associatedVpnId;
    }
    Uuid extNwId = getExtNetworkId(portIid, LogicalDatastoreType.CONFIGURATION);
    if (extNwId == null) {
        LOG.error("createNATFlowEntries : External network associated with interface {} could not be retrieved", interfaceName);
        return;
    }
    long vpnId = getVpnId(extNwId, mapping.getExternalId());
    if (vpnId < 0) {
        LOG.error("createNATFlowEntries : No VPN associated with Ext nw {}. Unable to create SNAT table entry " + "for fixed ip {}", extNwId, mapping.getInternalIp());
        return;
    }
    // Install the DNAT default FIB flow L3_FIB_TABLE (21) -> PSNAT_TABLE (26) if SNAT is disabled
    boolean isSnatEnabled = NatUtil.isSnatEnabledForRouterId(dataBroker, routerName);
    if (!isSnatEnabled) {
        addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, writeFlowInvTx, true);
    }
    // Create the DNAT and SNAT table entries
    createDNATTblEntry(dpnId, mapping, routerId, associatedVpnId, writeFlowInvTx);
    createSNATTblEntry(dpnId, mapping, vpnId, routerId, associatedVpnId, extNwId, writeFlowInvTx);
    floatingIPHandler.onAddFloatingIp(dpnId, routerName, routerId, extNwId, interfaceName, mapping, writeFlowInvTx);
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) BigInteger(java.math.BigInteger)

Example 60 with Uuid

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid in project netvirt by opendaylight.

the class InterfaceStateEventListener method getFixedIpsForPort.

private List<String> getFixedIpsForPort(String interfname) {
    LOG.debug("getFixedIpsForPort : getFixedIpsForPort method is called for interface {}", interfname);
    try {
        Future<RpcResult<GetFixedIPsForNeutronPortOutput>> result = neutronVpnService.getFixedIPsForNeutronPort(new GetFixedIPsForNeutronPortInputBuilder().setPortId(new Uuid(interfname)).build());
        RpcResult<GetFixedIPsForNeutronPortOutput> rpcResult = result.get();
        if (!rpcResult.isSuccessful()) {
            LOG.error("getFixedIpsForPort : RPC Call to GetFixedIPsForNeutronPortOutput returned with Errors {}", rpcResult.getErrors());
        } else {
            return rpcResult.getResult().getFixedIPs();
        }
    } catch (InterruptedException | ExecutionException | NullPointerException ex) {
        LOG.error("getFixedIpsForPort : Exception while receiving fixedIps for port {}", interfname, ex);
    }
    return null;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) GetFixedIPsForNeutronPortOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetFixedIPsForNeutronPortOutput) ExecutionException(java.util.concurrent.ExecutionException) GetFixedIPsForNeutronPortInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetFixedIPsForNeutronPortInputBuilder)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)283 ArrayList (java.util.ArrayList)114 BigInteger (java.math.BigInteger)79 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)55 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)53 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)52 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)48 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)40 ExecutionException (java.util.concurrent.ExecutionException)35 Port (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port)32 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)29 Network (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network)27 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)25 HashSet (java.util.HashSet)23 List (java.util.List)23 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)23 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)22 VpnInterface (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface)19 Optional (com.google.common.base.Optional)17 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)17