Search in sources :

Example 41 with Uint32

use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.

the class ExternalRoutersListener method remove.

@Override
public void remove(InstanceIdentifier<Routers> identifier, Routers router) {
    if (natMode != NatMode.Controller) {
        return;
    }
    LOG.trace("remove : Router delete method");
    if (identifier == null || router == null) {
        LOG.error("remove : returning without processing since routers is null");
        return;
    }
    String routerName = router.getRouterName();
    coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + router.key(), () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
        LOG.info("remove : Removing default NAT route from FIB on all dpns part of router {} ", routerName);
        Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
        if (routerId == NatConstants.INVALID_ID) {
            LOG.error("remove : Remove external router event - Invalid routerId for routerName {}", routerName);
            return;
        }
        Uint32 bgpVpnId = NatConstants.INVALID_ID;
        Uuid bgpVpnUuid = NatUtil.getVpnForRouter(dataBroker, routerName);
        if (bgpVpnUuid != null) {
            bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnUuid.getValue());
        }
        addOrDelDefFibRouteToSNAT(routerName, routerId, bgpVpnId, bgpVpnUuid, false, tx);
        Uuid networkUuid = router.getNetworkId();
        Uint64 primarySwitchId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
        if (primarySwitchId == null || primarySwitchId.equals(Uint64.ZERO)) {
            // No NAPT switch for external router, probably because the router is not attached to
            // any
            // internal networks
            LOG.debug("No NAPT switch for router {}, check if router is attached to any internal " + "network", routerName);
            return;
        } else {
            Collection<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
            final String vpnName = NatUtil.getAssociatedVPN(dataBroker, networkUuid);
            handleDisableSnat(router, networkUuid, externalIps, true, vpnName, primarySwitchId, routerId, tx);
        }
        if (NatUtil.releaseId(idManager, NatConstants.ODL_VNI_POOL_NAME, routerName) == NatConstants.INVALID_ID) {
            LOG.error("remove: Unable to release VNI for router - {}", routerName);
        }
    })), NatConstants.NAT_DJC_MAX_RETRIES);
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 42 with Uint32

use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.

the class FloatingIPListener method createNATFlowEntries.

void createNATFlowEntries(Uint64 dpnId, String interfaceName, String routerName, Uuid externalNetworkId, InternalToExternalPortMap mapping, TypedReadWriteTransaction<Configuration> confTx) throws ExecutionException, InterruptedException {
    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
    Uint32 associatedVpnId = NatUtil.getAssociatedVpn(dataBroker, routerName);
    if (associatedVpnId == NatConstants.INVALID_ID) {
        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, associatedVpnId);
    // routerId = associatedVpnId;
    }
    Uuid vpnUuid = getVpnUuid(externalNetworkId, mapping.getExternalId());
    LOG.trace("createNATFlowEntries : vpnUuid {} for External Network {}", vpnUuid, externalNetworkId);
    if (vpnUuid == null) {
        LOG.error("createNATFlowEntries : No vpnUuid associated with Ext nw {}. Unable to create SNAT table entry" + " for fixed ip {}", externalNetworkId, mapping.getInternalIp());
        return;
    }
    VpnInstance vpnInstance = NatUtil.getVpnIdToVpnInstance(dataBroker, vpnUuid.getValue());
    if (vpnInstance == null || vpnInstance.getVpnId() == null) {
        LOG.error("createNATFlowEntries: VpnInstance associated with Ext nw {}. Unable to create SNAT table entry" + " for fixed ip {}", externalNetworkId, 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, externalNetworkId, confTx);
    floatingIPHandler.onAddFloatingIp(dpnId, routerName, routerId, externalNetworkId, 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)

Example 43 with Uint32

use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.

the class FloatingIPListener method buildPreSNATFlowEntity.

private FlowEntity buildPreSNATFlowEntity(Uint64 dpId, String internalIp, String externalIp, Uint32 vpnId, Uint32 routerId, Uint32 associatedVpn) {
    LOG.debug("buildPreSNATFlowEntity : Building PSNAT Flow entity for ip {} ", internalIp);
    Uint32 segmentId = associatedVpn == NatConstants.INVALID_ID ? routerId : associatedVpn;
    LOG.debug("buildPreSNATFlowEntity : Segment id {} in build preSNAT flow", segmentId);
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(MatchEthernetType.IPV4);
    matches.add(new MatchIpv4Source(internalIp, "32"));
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(segmentId.longValue()), MetaDataUtil.METADATA_MASK_VRFID));
    List<ActionInfo> actionsInfos = new ArrayList<>();
    actionsInfos.add(new ActionSetSourceIp(externalIp, "32"));
    List<InstructionInfo> instructions = new ArrayList<>();
    instructions.add(new InstructionWriteMetadata(MetaDataUtil.getVpnIdMetadata(vpnId.longValue()), MetaDataUtil.METADATA_MASK_VRFID));
    instructions.add(new InstructionApplyActions(actionsInfos));
    instructions.add(new InstructionGotoTable(NwConstants.SNAT_TABLE));
    String flowRef = NatUtil.getFlowRef(dpId, NwConstants.PSNAT_TABLE, routerId, internalIp);
    FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.PSNAT_TABLE, flowRef, NatConstants.DEFAULT_DNAT_FLOW_PRIORITY, flowRef, 0, 0, NwConstants.COOKIE_DNAT_TABLE, matches, instructions);
    return flowEntity;
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) ArrayList(java.util.ArrayList) ActionSetSourceIp(org.opendaylight.genius.mdsalutil.actions.ActionSetSourceIp) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) MatchIpv4Source(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Source) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) InstructionWriteMetadata(org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Example 44 with Uint32

use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.

the class FloatingIPListener method removeNATFlowEntries.

void removeNATFlowEntries(String interfaceName, final InternalToExternalPortMap mapping, InstanceIdentifier<RouterPorts> portIid, final String routerName, @Nullable Uint64 dpnId, TypedReadWriteTransaction<Configuration> removeFlowInvTx) throws ExecutionException, InterruptedException {
    Uuid extNwId = getExtNetworkId(portIid, LogicalDatastoreType.OPERATIONAL);
    if (extNwId == null) {
        LOG.error("removeNATFlowEntries : External network associated with interface {} could not be retrieved", interfaceName);
        return;
    }
    // For FLAT/VLAN Networks, get the DPN with provider_mappings for external network.
    if (dpnId == null) {
        dpnId = getAssociatedDpnWithExternalInterface(routerName, extNwId, NatUtil.getDpnForInterface(interfaceManager, interfaceName), interfaceName);
        if (dpnId == null || dpnId.equals(Uint64.ZERO)) {
            LOG.warn("removeNATFlowEntries: Abort processing Floating ip configuration. No DPN for port: {}", interfaceName);
            return;
        }
    }
    Uint32 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;
    }
    String internalIp = mapping.getInternalIp();
    String externalIp = mapping.getExternalIp();
    // Delete the DNAT and SNAT table entries
    removeDNATTblEntry(dpnId, internalIp, externalIp, routerId, removeFlowInvTx);
    Uuid vpnUuid = getVpnUuid(extNwId, mapping.getExternalId());
    if (vpnUuid == null) {
        LOG.error("removeNATFlowEntries : No VPN associated with Ext nw {}. Unable to remove 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("removeNATFlowEntries: No VPN associated with Ext nw {}. Unable to create SNAT table entry " + "for fixed ip {}", extNwId, mapping.getInternalIp());
        return;
    }
    Uint32 vpnId = vpnInstance.getVpnId();
    String vrfId = vpnInstance.getVrfId();
    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, vrfId, removeFlowInvTx);
        removeOperationalDS(routerName, interfaceName, internalIp);
        return;
    }
    Uint32 label = getOperationalIpMapping(routerName, interfaceName, internalIp);
    if (label.longValue() < 0) {
        LOG.error("removeNATFlowEntries : Could not retrieve label for prefix {} in router {}", internalIp, routerId);
        return;
    }
    floatingIPHandler.onRemoveFloatingIp(dpnId, routerName, routerId, extNwId, mapping, label, vrfId, 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) VpnInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Example 45 with Uint32

use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.

the class FloatingIPListener method buildPreDNATFlowEntity.

@Nullable
private FlowEntity buildPreDNATFlowEntity(Uint64 dpId, InternalToExternalPortMap mapping, Uint32 routerId, Uint32 associatedVpn) {
    String externalIp = mapping.getExternalIp();
    Uuid floatingIpId = mapping.getExternalId();
    // Get the FIP MAC address for DNAT
    String floatingIpPortMacAddress = NatUtil.getFloatingIpPortMacFromFloatingIpId(dataBroker, floatingIpId);
    if (floatingIpPortMacAddress == null) {
        LOG.error("buildPreDNATFlowEntity : Unable to retrieve floatingIpPortMacAddress from floating IP UUID {} " + "for floating IP {}", floatingIpId, externalIp);
        return null;
    }
    LOG.debug("buildPreDNATFlowEntity : Bulding DNAT Flow entity for ip {} ", externalIp);
    Uint32 segmentId = associatedVpn == NatConstants.INVALID_ID ? routerId : associatedVpn;
    LOG.debug("buildPreDNATFlowEntity : Segment id {} in build preDNAT Flow", segmentId);
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(MatchEthernetType.IPV4);
    matches.add(new MatchIpv4Destination(externalIp, "32"));
    // Match Destination Floating IP MAC Address on table = 25 (PDNAT_TABLE)
    matches.add(new MatchEthernetDestination(new MacAddress(floatingIpPortMacAddress)));
    // matches.add(new MatchMetadata(
    // BigInteger.valueOf(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
    List<ActionInfo> actionsInfos = new ArrayList<>();
    String internalIp = mapping.getInternalIp();
    actionsInfos.add(new ActionSetDestinationIp(internalIp, "32"));
    List<InstructionInfo> instructions = new ArrayList<>();
    instructions.add(new InstructionWriteMetadata(MetaDataUtil.getVpnIdMetadata(segmentId.longValue()), MetaDataUtil.METADATA_MASK_VRFID));
    instructions.add(new InstructionApplyActions(actionsInfos));
    instructions.add(new InstructionGotoTable(NwConstants.DNAT_TABLE));
    String flowRef = NatUtil.getFlowRef(dpId, NwConstants.PDNAT_TABLE, routerId, externalIp);
    FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.PDNAT_TABLE, flowRef, NatConstants.DEFAULT_DNAT_FLOW_PRIORITY, flowRef, 0, 0, NwConstants.COOKIE_DNAT_TABLE, matches, instructions);
    return flowEntity;
}
Also used : InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) ArrayList(java.util.ArrayList) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) MatchEthernetDestination(org.opendaylight.genius.mdsalutil.matches.MatchEthernetDestination) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) ActionSetDestinationIp(org.opendaylight.genius.mdsalutil.actions.ActionSetDestinationIp) InstructionWriteMetadata(org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

Uint32 (org.opendaylight.yangtools.yang.common.Uint32)216 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)98 ArrayList (java.util.ArrayList)77 ExecutionException (java.util.concurrent.ExecutionException)68 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)68 DataBroker (org.opendaylight.mdsal.binding.api.DataBroker)44 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)44 Logger (org.slf4j.Logger)44 LoggerFactory (org.slf4j.LoggerFactory)44 ManagedNewTransactionRunner (org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner)42 ManagedNewTransactionRunnerImpl (org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl)42 Inject (javax.inject.Inject)41 Singleton (javax.inject.Singleton)41 LogicalDatastoreType (org.opendaylight.mdsal.common.api.LogicalDatastoreType)41 List (java.util.List)40 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)38 Optional (java.util.Optional)37 VpnInstanceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry)36 VrfEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry)35 Collections (java.util.Collections)34