Search in sources :

Example 6 with AssociatedVpn

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnets.associated.to.route.targets.route.target.associated.subnet.AssociatedVpn in project netvirt by opendaylight.

the class FloatingIPListener method addOrDelDefaultFibRouteForDnat.

private void addOrDelDefaultFibRouteForDnat(Uint64 dpnId, String routerName, Uint32 routerId, @Nullable TypedReadWriteTransaction<Configuration> confTx, boolean create) throws ExecutionException, InterruptedException {
    if (confTx == null) {
        LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, newTx -> addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, newTx, create)), LOG, "Error handling default FIB route for DNAT");
        return;
    }
    // Check if the router to bgp-vpn association is present
    Uint32 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, confTx);
        } else {
            LOG.debug("addOrDelDefaultFibRouteForDnat: Install NAT default route on DPN {} for the router {} with " + "vpn-id {}", dpnId, routerName, routerId);
            defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, routerId, confTx);
        }
    } 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, confTx);
        } else {
            LOG.debug("addOrDelDefaultFibRouteForDnat: Remove NAT default route on DPN {} for the router {} " + "with vpn-id {}", dpnId, routerName, routerId);
            defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, routerId, confTx);
        }
    }
}
Also used : CONFIGURATION(org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION) SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) MatchIpv4Source(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Source) Networks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap) LoggerFactory(org.slf4j.LoggerFactory) ActionNxResubmit(org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit) 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) ExternalNetworks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks) MatchEthernetDestination(org.opendaylight.genius.mdsalutil.matches.MatchEthernetDestination) InetAddress(java.net.InetAddress) NatSwitchCache(org.opendaylight.netvirt.natservice.api.NatSwitchCache) RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) PreDestroy(javax.annotation.PreDestroy) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) ActionSetSourceIp(org.opendaylight.genius.mdsalutil.actions.ActionSetSourceIp) Nullable(org.eclipse.jdt.annotation.Nullable) BigInteger(java.math.BigInteger) LoggingFutures(org.opendaylight.infrautils.utils.concurrent.LoggingFutures) MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) VpnInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance) ActionSetDestinationIp(org.opendaylight.genius.mdsalutil.actions.ActionSetDestinationIp) Configuration(org.opendaylight.mdsal.binding.util.Datastore.Configuration) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) ActionNxLoadInPort(org.opendaylight.genius.mdsalutil.actions.ActionNxLoadInPort) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) List(java.util.List) FloatingIpInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.FloatingIpInfo) ManagedNewTransactionRunnerImpl(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl) Optional(java.util.Optional) TypedReadWriteTransaction(org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction) Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports) PortsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.PortsKey) Uint64(org.opendaylight.yangtools.yang.common.Uint64) OdlInterfaceRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService) Executors(org.opendaylight.infrautils.utils.concurrent.Executors) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) Singleton(javax.inject.Singleton) InstructionWriteMetadata(org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata) ActionSetFieldEthernetSource(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetSource) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) MatchEthernetType(org.opendaylight.genius.mdsalutil.matches.MatchEthernetType) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Logger(org.slf4j.Logger) AbstractAsyncDataTreeChangeListener(org.opendaylight.serviceutils.tools.listener.AbstractAsyncDataTreeChangeListener) NetworksKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) UnknownHostException(java.net.UnknownHostException) InternalToExternalPortMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMapKey) ExecutionException(java.util.concurrent.ExecutionException) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) CentralizedSwitchScheduler(org.opendaylight.netvirt.natservice.api.CentralizedSwitchScheduler) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) IMdsalApiManager(org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) PortsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.PortsBuilder) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) Collections(java.util.Collections) MetaDataUtil(org.opendaylight.genius.mdsalutil.MetaDataUtil) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) InternalToExternalPortMapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMapBuilder) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Example 7 with AssociatedVpn

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnets.associated.to.route.targets.route.target.associated.subnet.AssociatedVpn in project netvirt by opendaylight.

the class FloatingIPListener method createNATFlowEntries.

void createNATFlowEntries(String interfaceName, final InternalToExternalPortMap mapping, final InstanceIdentifier<RouterPorts> portIid, final String routerName, @Nullable Uint64 dpnId, TypedReadWriteTransaction<Configuration> confTx) throws ExecutionException, InterruptedException {
    if (!validateIpMapping(mapping)) {
        LOG.error("createNATFlowEntries : Not a valid ip addresses in the mapping {}", mapping);
        return;
    }
    Uuid extNwId = getExtNetworkId(portIid, LogicalDatastoreType.CONFIGURATION);
    if (extNwId == null) {
        LOG.error("createNATFlowEntries : External network associated with interface {} could not be retrieved", interfaceName);
        return;
    }
    // For Overlay Networks, get the DPN on which this interface resides.
    // For FLAT/VLAN Networks, get the DPN with provider_mappings for external network.
    dpnId = getAssociatedDpnWithExternalInterface(routerName, extNwId, dpnId, interfaceName);
    if (dpnId == null || dpnId.equals(Uint64.ZERO)) {
        LOG.warn("createNATFlowEntries : No DPN for interface {}. NAT flow entries for ip mapping {} will " + "not be installed", interfaceName, mapping);
        return;
    }
    Uint32 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);
    Uint32 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 vpnUuid = getVpnUuid(extNwId, mapping.getExternalId());
    LOG.trace("createNATFlowEntries : vpnUuid {} for External Network {}", vpnUuid, extNwId);
    if (vpnUuid == null) {
        LOG.error("createNATFlowEntries : No VPN associated with Ext nw {}. Unable to create SNAT table entry " + "for fixed ip {}", extNwId, mapping.getInternalIp());
        return;
    }
    VpnInstance vpnInstance = NatUtil.getVpnIdToVpnInstance(dataBroker, vpnUuid.getValue());
    if (vpnInstance == null || vpnInstance.getVpnId() == null) {
        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, confTx, true);
    }
    // Create the DNAT and SNAT table entries
    Uint32 vpnId = vpnInstance.getVpnId();
    String vrfId = vpnInstance.getVrfId();
    createDNATTblEntry(dpnId, mapping, routerId, associatedVpnId, confTx);
    createSNATTblEntry(dpnId, mapping, vpnId, routerId, associatedVpnId, extNwId, confTx);
    floatingIPHandler.onAddFloatingIp(dpnId, routerName, routerId, extNwId, interfaceName, mapping, vrfId, confTx);
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)6 ArrayList (java.util.ArrayList)4 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)3 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)3 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)3 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)3 ActionSetDestinationIp (org.opendaylight.genius.mdsalutil.actions.ActionSetDestinationIp)3 InstructionApplyActions (org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)3 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)3 InstructionWriteMetadata (org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata)3 MatchEthernetDestination (org.opendaylight.genius.mdsalutil.matches.MatchEthernetDestination)3 MatchIpv4Destination (org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination)3 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)3 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)3 BigInteger (java.math.BigInteger)2 Nullable (org.eclipse.jdt.annotation.Nullable)2 VpnInstance (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance)2 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 Collections (java.util.Collections)1