Search in sources :

Example 16 with Table

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table in project netvirt by opendaylight.

the class NatUtil method isFloatingIpPresentForDpn.

public static Boolean isFloatingIpPresentForDpn(DataBroker dataBroker, BigInteger dpnId, String rd, String vpnName, String externalIp, Boolean isMoreThanOneFipCheckOnDpn) {
    InstanceIdentifier<VpnToDpnList> id = getVpnToDpnListIdentifier(rd, dpnId);
    Optional<VpnToDpnList> dpnInVpn = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
    if (dpnInVpn.isPresent()) {
        LOG.debug("isFloatingIpPresentForDpn : vpn-to-dpn-list is not empty for vpnName {}, dpn id {}, " + "rd {} and floatingIp {}", vpnName, dpnId, rd, externalIp);
        try {
            List<IpAddresses> ipAddressList = dpnInVpn.get().getIpAddresses();
            if (ipAddressList != null && !ipAddressList.isEmpty()) {
                int floatingIpPresentCount = 0;
                for (IpAddresses ipAddress : ipAddressList) {
                    if (!ipAddress.getIpAddress().equals(externalIp) && IpAddresses.IpAddressSource.FloatingIP.equals(ipAddress.getIpAddressSource())) {
                        floatingIpPresentCount++;
                        // Add tunnel table check
                        if (isMoreThanOneFipCheckOnDpn && floatingIpPresentCount > 1) {
                            return Boolean.TRUE;
                        }
                        // Remove tunnel table check
                        if (!isMoreThanOneFipCheckOnDpn) {
                            return Boolean.TRUE;
                        }
                    }
                }
            } else {
                LOG.debug("isFloatingIpPresentForDpn : vpn-to-dpn-list does not contain any floating IP for DPN {}", dpnId);
                return Boolean.FALSE;
            }
        } catch (NullPointerException e) {
            LOG.error("isFloatingIpPresentForDpn: Exception occurred on getting external IP address from " + "vpn-to-dpn-list on Dpn {}", dpnId, e);
            return Boolean.FALSE;
        }
    }
    return Boolean.FALSE;
}
Also used : IpAddresses(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.IpAddresses) VpnToDpnList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList)

Example 17 with Table

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table in project netvirt by opendaylight.

the class RouterDpnChangeListener method add.

@Override
protected void add(final InstanceIdentifier<DpnVpninterfacesList> identifier, final DpnVpninterfacesList dpnInfo) {
    LOG.trace("add : key: {}, value: {}", dpnInfo.getKey(), dpnInfo);
    final String routerUuid = identifier.firstKeyOf(RouterDpnList.class).getRouterId();
    BigInteger dpnId = dpnInfo.getDpnId();
    // check router is associated to external network
    InstanceIdentifier<Routers> id = NatUtil.buildRouterIdentifier(routerUuid);
    Optional<Routers> routerData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
    if (routerData.isPresent()) {
        Routers router = routerData.get();
        Uuid networkId = router.getNetworkId();
        if (networkId != null) {
            if (natMode == NatMode.Conntrack) {
                BigInteger naptSwitch = NatUtil.getPrimaryNaptfromRouterName(dataBroker, router.getRouterName());
                if (naptSwitch == null || naptSwitch.equals(BigInteger.ZERO)) {
                    LOG.warn("add : NAPT switch is not selected.");
                    return;
                }
                // If it is for NAPT switch skip as the flows would be already programmed.
                if (naptSwitch.equals(dpnId)) {
                    LOG.debug("Skipping the notification recived for NAPT switch {}", routerUuid);
                    return;
                }
                natServiceManager.notify(router, naptSwitch, dpnId, SnatServiceManager.Action.SNAT_ROUTER_ENBL);
            } else {
                coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + dpnInfo.getKey(), () -> {
                    WriteTransaction writeFlowInvTx = dataBroker.newWriteOnlyTransaction();
                    WriteTransaction removeFlowInvTx = dataBroker.newWriteOnlyTransaction();
                    LOG.debug("add : Router {} is associated with ext nw {}", routerUuid, networkId);
                    Uuid vpnName = NatUtil.getVpnForRouter(dataBroker, routerUuid);
                    Long routerId = NatUtil.getVpnId(dataBroker, routerUuid);
                    List<ListenableFuture<Void>> futures = new ArrayList<>();
                    if (routerId == NatConstants.INVALID_ID) {
                        LOG.error("add : Invalid routerId returned for routerName {}", routerUuid);
                        writeFlowInvTx.cancel();
                        removeFlowInvTx.cancel();
                        return futures;
                    }
                    extNetGroupInstaller.installExtNetGroupEntries(networkId, dpnId);
                    Long vpnId;
                    if (vpnName == null) {
                        LOG.debug("add : Internal vpn associated to router {}", routerUuid);
                        vpnId = routerId;
                        if (vpnId == NatConstants.INVALID_ID) {
                            LOG.error("add : Invalid vpnId returned for routerName {}", routerUuid);
                            writeFlowInvTx.cancel();
                            removeFlowInvTx.cancel();
                            return futures;
                        }
                        LOG.debug("add : Retrieved vpnId {} for router {}", vpnId, routerUuid);
                        // Install default entry in FIB to SNAT table
                        LOG.info("add : Installing default route in FIB on dpn {} for router {} with vpn {}", dpnId, routerUuid, vpnId);
                        installDefaultNatRouteForRouterExternalSubnets(dpnId, NatUtil.getExternalSubnetIdsFromExternalIps(router.getExternalIps()));
                        snatDefaultRouteProgrammer.installDefNATRouteInDPN(dpnId, vpnId, writeFlowInvTx);
                    } else {
                        LOG.debug("add : External BGP vpn associated to router {}", routerUuid);
                        vpnId = NatUtil.getVpnId(dataBroker, vpnName.getValue());
                        if (vpnId == NatConstants.INVALID_ID) {
                            LOG.error("add : Invalid vpnId returned for routerName {}", routerUuid);
                            writeFlowInvTx.cancel();
                            removeFlowInvTx.cancel();
                            return futures;
                        }
                        LOG.debug("add : Retrieved vpnId {} for router {}", vpnId, routerUuid);
                        // Install default entry in FIB to SNAT table
                        LOG.debug("add : Installing default route in FIB on dpn {} for routerId {} with " + "vpnId {}...", dpnId, routerUuid, vpnId);
                        installDefaultNatRouteForRouterExternalSubnets(dpnId, NatUtil.getExternalSubnetIdsFromExternalIps(router.getExternalIps()));
                        snatDefaultRouteProgrammer.installDefNATRouteInDPN(dpnId, vpnId, routerId, writeFlowInvTx);
                    }
                    if (router.isEnableSnat()) {
                        LOG.info("add : SNAT enabled for router {}", routerUuid);
                        ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerUuid, networkId);
                        if (extNwProvType == null) {
                            LOG.error("add : External Network Provider Type missing");
                            writeFlowInvTx.cancel();
                            removeFlowInvTx.cancel();
                            return futures;
                        }
                        handleSNATForDPN(dpnId, routerUuid, routerId, vpnId, writeFlowInvTx, removeFlowInvTx, extNwProvType);
                    } else {
                        LOG.info("add : SNAT is not enabled for router {} to handle addDPN event {}", routerUuid, dpnId);
                    }
                    futures.add(NatUtil.waitForTransactionToComplete(writeFlowInvTx));
                    futures.add(NatUtil.waitForTransactionToComplete(removeFlowInvTx));
                    return futures;
                }, NatConstants.NAT_DJC_MAX_RETRIES);
            }
        // end of controller based SNAT
        }
    } else {
        LOG.debug("add : Router {} is not associated with External network", routerUuid);
    }
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) ArrayList(java.util.ArrayList) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) BigInteger(java.math.BigInteger) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) RouterDpnList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.RouterDpnList)

Example 18 with Table

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table in project netvirt by opendaylight.

the class RouterDpnChangeListener method removeSNATFromDPN.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
void removeSNATFromDPN(BigInteger dpnId, String routerName, long routerId, long routerVpnId, Uuid extNetworkId, WriteTransaction removeFlowInvTx) {
    // irrespective of naptswitch or non-naptswitch, SNAT default miss entry need to be removed
    // remove miss entry to NAPT switch
    // if naptswitch elect new switch and install Snat flows and remove those flows in oldnaptswitch
    Collection<String> externalIpCache = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
    ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, extNetworkId);
    if (extNwProvType == null) {
        return;
    }
    // Get the external IP labels other than VXLAN provider type. Since label is not applicable for VXLAN
    Map<String, Long> externalIpLabel;
    if (extNwProvType == ProviderTypes.VXLAN) {
        externalIpLabel = null;
    } else {
        externalIpLabel = NatUtil.getExternalIpsLabelForRouter(dataBroker, routerId);
    }
    BigInteger naptSwitch = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
    if (naptSwitch == null || naptSwitch.equals(BigInteger.ZERO)) {
        LOG.error("removeSNATFromDPN : No naptSwitch is selected for router {}", routerName);
        return;
    }
    try {
        boolean naptStatus = naptSwitchHA.isNaptSwitchDown(routerName, routerId, dpnId, naptSwitch, routerVpnId, externalIpCache, removeFlowInvTx);
        if (!naptStatus) {
            LOG.debug("removeSNATFromDPN: Switch with DpnId {} is not naptSwitch for router {}", dpnId, routerName);
            long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(routerName), idManager);
            FlowEntity flowEntity = null;
            try {
                flowEntity = naptSwitchHA.buildSnatFlowEntity(dpnId, routerName, groupId, routerVpnId, NatConstants.DEL_FLOW);
                if (flowEntity == null) {
                    LOG.error("removeSNATFromDPN : Failed to populate flowentity for router:{} " + "with dpnId:{} groupId:{}", routerName, dpnId, groupId);
                    return;
                }
                LOG.debug("removeSNATFromDPN : Removing default SNAT miss entry flow entity {}", flowEntity);
                mdsalManager.removeFlowToTx(flowEntity, removeFlowInvTx);
            } catch (Exception ex) {
                LOG.error("removeSNATFromDPN : Failed to remove default SNAT miss entry flow entity {}", flowEntity, ex);
                return;
            }
            LOG.debug("removeSNATFromDPN : Removed default SNAT miss entry flow for dpnID {} with routername {}", dpnId, routerName);
            // remove group
            GroupEntity groupEntity = null;
            try {
                groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName, GroupTypes.GroupAll, Collections.emptyList());
                LOG.info("removeSNATFromDPN : Removing NAPT GroupEntity:{}", groupEntity);
                mdsalManager.removeGroup(groupEntity);
            } catch (Exception ex) {
                LOG.error("removeSNATFromDPN : Failed to remove group entity {}", groupEntity, ex);
                return;
            }
            LOG.debug("removeSNATFromDPN : Removed default SNAT miss entry flow for dpnID {} with routerName {}", dpnId, routerName);
        } else {
            naptSwitchHA.removeSnatFlowsInOldNaptSwitch(routerName, routerId, naptSwitch, externalIpLabel, removeFlowInvTx);
            // remove table 26 flow ppointing to table46
            FlowEntity flowEntity = null;
            try {
                flowEntity = naptSwitchHA.buildSnatFlowEntityForNaptSwitch(dpnId, routerName, routerVpnId, NatConstants.DEL_FLOW);
                if (flowEntity == null) {
                    LOG.error("removeSNATFromDPN : Failed to populate flowentity for router {} with dpnId {}", routerName, dpnId);
                    return;
                }
                LOG.debug("removeSNATFromDPN : Removing default SNAT miss entry flow entity for router {} with " + "dpnId {} in napt switch {}", routerName, dpnId, naptSwitch);
                mdsalManager.removeFlowToTx(flowEntity, removeFlowInvTx);
            } catch (Exception ex) {
                LOG.error("removeSNATFromDPN : Failed to remove default SNAT miss entry flow entity {}", flowEntity, ex);
                return;
            }
            LOG.debug("removeSNATFromDPN : Removed default SNAT miss entry flow for dpnID {} with routername {}", dpnId, routerName);
            // best effort to check IntExt model
            naptSwitchHA.bestEffortDeletion(routerId, routerName, externalIpLabel, removeFlowInvTx);
        }
    } catch (Exception ex) {
        LOG.error("removeSNATFromDPN : Exception while handling naptSwitch down for router {}", routerName, ex);
    }
}
Also used : ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) GroupEntity(org.opendaylight.genius.mdsalutil.GroupEntity) BigInteger(java.math.BigInteger) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Example 19 with Table

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table 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 20 with Table

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table 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)

Aggregations

ArrayList (java.util.ArrayList)71 BigInteger (java.math.BigInteger)63 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)51 Test (org.junit.Test)38 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)27 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)27 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)26 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)25 List (java.util.List)25 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)25 Table (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table)23 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)22 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)22 FlowId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId)20 ByteBuf (io.netty.buffer.ByteBuf)18 FlowBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder)18 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)17 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)17 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)17 FlowKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey)17