Search in sources :

Example 26 with FlowEntity

use of org.opendaylight.genius.mdsalutil.FlowEntity in project netvirt by opendaylight.

the class ExternalRoutersListener method removeNaptFibExternalOutputFlows.

protected void removeNaptFibExternalOutputFlows(long routerId, BigInteger dpnId, Uuid networkId, @Nonnull Collection<String> externalIps, WriteTransaction writeFlowInvTx) {
    long extVpnId = NatConstants.INVALID_ID;
    if (networkId != null) {
        Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
        if (vpnUuid != null) {
            extVpnId = NatUtil.getVpnId(dataBroker, vpnUuid.getValue());
        } else {
            LOG.debug("removeNaptFibExternalOutputFlows : vpnUuid is null");
        }
    } else {
        LOG.debug("removeNaptFibExternalOutputFlows : networkId is null");
        extVpnId = NatUtil.getNetworkVpnIdFromRouterId(dataBroker, routerId);
    }
    if (extVpnId == NatConstants.INVALID_ID) {
        LOG.warn("removeNaptFibExternalOutputFlows : extVpnId not found for routerId {}", routerId);
        extVpnId = routerId;
    }
    for (String ip : externalIps) {
        String extIp = removeMaskFromIp(ip);
        String naptFlowRef = getFlowRefNaptPreFib(dpnId, NwConstants.NAPT_PFIB_TABLE, extVpnId);
        LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in table {} for the active switch" + " with the DPN ID {} and router ID {} and IP {} flowRef {}", NwConstants.NAPT_PFIB_TABLE, dpnId, routerId, extIp, naptFlowRef);
        FlowEntity natPfibVpnFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.NAPT_PFIB_TABLE, naptFlowRef);
        mdsalManager.removeFlowToTx(natPfibVpnFlowEntity, writeFlowInvTx);
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Example 27 with FlowEntity

use of org.opendaylight.genius.mdsalutil.FlowEntity in project netvirt by opendaylight.

the class NatTunnelInterfaceStateListener method hndlTepAddOnNonNaptSwitch.

private boolean hndlTepAddOnNonNaptSwitch(BigInteger srcDpnId, BigInteger primaryDpnId, String tunnelType, String srcTepIp, String destTepIp, String tunnelName, String routerName, long routerId, Uuid vpnName, WriteTransaction writeFlowInvTx) {
    /*
        1) Install default NAT rule from table 21 to 26
        2) Install the group which forward packet to the tunnel port for the NAPT switch.
        3) Install the flow 26 which forwards the packet to the group.
        */
    LOG.debug("hndlTepAddOnNonNaptSwitch : SNAT -> Processing TEP add for the DPN {} having the router {} since " + "its THE NON NAPT switch for the TUNNEL TYPE {} b/w SRC IP {} and DST IP {} " + "and TUNNEL NAME {} ", srcDpnId, routerName, tunnelType, srcTepIp, destTepIp, tunnelName);
    LOG.debug("hndlTepAddOnNonNaptSwitch : SNAT -> Install default NAT rule from table 21 to 26");
    Long vpnId;
    if (vpnName == null) {
        LOG.debug("hndlTepAddOnNonNaptSwitch : SNAT -> Internal VPN associated to router {}", routerId);
        vpnId = routerId;
        if (vpnId == NatConstants.INVALID_ID) {
            LOG.error("hndlTepAddOnNonNaptSwitch : SNAT -> Invalid Internal VPN ID returned for routerName {}", routerId);
            return false;
        }
        LOG.debug("hndlTepAddOnNonNaptSwitch : SNAT -> Retrieved vpnId {} for router {}", vpnId, routerName);
        // Install default entry in FIB to SNAT table
        LOG.debug("hndlTepAddOnNonNaptSwitch : Installing default route in FIB on DPN {} for router {} with" + " vpn {}...", srcDpnId, routerName, vpnId);
        defaultRouteProgrammer.installDefNATRouteInDPN(srcDpnId, vpnId, writeFlowInvTx);
        LOG.debug("hndlTepAddOnNonNaptSwitch : SNAT -> Install the group which forward packet to the tunnel port " + "for the NAPT switch {} and the flow 26 which forwards to group", primaryDpnId);
        externalRouterListner.handleSwitches(srcDpnId, routerName, routerId, primaryDpnId);
    } else {
        LOG.debug("hndlTepAddOnNonNaptSwitch : SNAT -> External BGP VPN (Private BGP) associated to router {}", routerId);
        vpnId = NatUtil.getVpnId(dataBroker, vpnName.getValue());
        if (vpnId == NatConstants.INVALID_ID) {
            LOG.error("hndlTepAddOnNonNaptSwitch : SNAT -> Invalid Private BGP VPN ID returned for routerName {}", routerId);
            return false;
        }
        if (routerId == NatConstants.INVALID_ID) {
            LOG.error("hndlTepAddOnNonNaptSwitch : SNAT -> Invalid routId returned for routerName {}", routerId);
            return false;
        }
        LOG.debug("hndlTepAddOnNonNaptSwitch : SNAT -> Retrieved vpnId {} for router {}", vpnId, routerId);
        // Install default entry in FIB to SNAT table
        LOG.debug("hndlTepAddOnNonNaptSwitch : Installing default route in FIB on dpn {} for routerId {} " + "with vpnId {}...", srcDpnId, routerId, vpnId);
        defaultRouteProgrammer.installDefNATRouteInDPN(srcDpnId, vpnId, routerId, writeFlowInvTx);
        LOG.debug("hndlTepAddOnNonNaptSwitch : Install group in non NAPT switch {} for router {}", srcDpnId, routerName);
        List<BucketInfo> bucketInfoForNonNaptSwitches = externalRouterListner.getBucketInfoForNonNaptSwitches(srcDpnId, primaryDpnId, routerName, routerId);
        long groupId = externalRouterListner.installGroup(srcDpnId, routerName, bucketInfoForNonNaptSwitches);
        LOG.debug("hndlTepAddOnNonNaptSwitch : SNAT -> in the SNAT miss entry pointing to group {} " + "in the non NAPT switch {}", groupId, srcDpnId);
        FlowEntity flowEntity = externalRouterListner.buildSnatFlowEntityWithUpdatedVpnId(srcDpnId, routerName, groupId, vpnId);
        mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
    }
    return true;
}
Also used : BucketInfo(org.opendaylight.genius.mdsalutil.BucketInfo) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Example 28 with FlowEntity

use of org.opendaylight.genius.mdsalutil.FlowEntity in project netvirt by opendaylight.

the class NatTunnelInterfaceStateListener method removeSNATFromDPN.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
void removeSNATFromDPN(BigInteger dpnId, String routerName, long routerId, long routerVpnId, Uuid networkId, ProviderTypes extNwProvType, WriteTransaction writeFlowInvTx) {
    if (routerId == NatConstants.INVALID_ID) {
        LOG.error("removeSNATFromDPN : SNAT -> Invalid routerId returned for routerName {}", routerName);
        return;
    }
    Collection<String> externalIpCache = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
    if (extNwProvType == null) {
        return;
    }
    Map<String, Long> externalIpLabel;
    if (extNwProvType == ProviderTypes.VXLAN) {
        externalIpLabel = null;
    } else {
        externalIpLabel = NatUtil.getExternalIpsLabelForRouter(dataBroker, routerId);
    }
    try {
        final String externalVpnName = NatUtil.getAssociatedVPN(dataBroker, networkId);
        if (externalVpnName == null) {
            LOG.error("removeSNATFromDPN : SNAT -> No VPN associated with ext nw {} in router {}", networkId, routerId);
            return;
        }
        BigInteger naptSwitch = dpnId;
        boolean naptStatus = naptSwitchHA.isNaptSwitchDown(routerName, routerId, dpnId, naptSwitch, routerVpnId, externalIpCache, false, writeFlowInvTx);
        if (!naptStatus) {
            LOG.debug("removeSNATFromDPN:SNAT->NaptSwitchDown: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 : SNAT -> Failed to populate flowentity for " + "router {} with dpnId {} groupIs {}", routerName, dpnId, groupId);
                    return;
                }
                LOG.debug("removeSNATFromDPN : SNAT->Removing default SNAT miss entry flow entity {}", flowEntity);
                mdsalManager.removeFlowToTx(flowEntity, writeFlowInvTx);
            } catch (Exception ex) {
                LOG.error("removeSNATFromDPN : SNAT->Failed to remove default SNAT miss entry flow entity {}", flowEntity, ex);
                return;
            }
            LOG.debug("removeSNATFromDPN:SNAT->Removed default SNAT miss entry flow for dpnID {}, routername {}", dpnId, routerName);
            // remove group
            GroupEntity groupEntity = null;
            try {
                groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName, GroupTypes.GroupAll, Collections.emptyList());
                LOG.info("removeSNATFromDPN : SNAT->Removing NAPT GroupEntity:{} on Dpn {}", groupEntity, dpnId);
                mdsalManager.removeGroup(groupEntity);
            } catch (Exception ex) {
                LOG.error("removeSNATFromDPN : SNAT->Failed to remove group entity {}", groupEntity, ex);
                return;
            }
            LOG.debug("removeSNATFromDPN : SNAT->Removed default SNAT miss entry flow for dpnID {}, routerName {}", dpnId, routerName);
        } else {
            naptSwitchHA.removeSnatFlowsInOldNaptSwitch(routerName, routerId, dpnId, externalIpLabel, writeFlowInvTx);
            // 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 : SNAT->Failed to populate flowentity for router {} with dpnId {}", routerName, dpnId);
                    return;
                }
                LOG.debug("removeSNATFromDPN : SNAT->Removing default SNAT miss entry flow entity for " + "router {} with dpnId {} in napt switch {}", routerName, dpnId, naptSwitch);
                mdsalManager.removeFlowToTx(flowEntity, writeFlowInvTx);
            } catch (Exception ex) {
                LOG.error("removeSNATFromDPN : SNAT->Failed to remove default SNAT miss entry flow entity {}", flowEntity, ex);
                return;
            }
            LOG.debug("removeSNATFromDPN : SNAT->Removed default SNAT miss entry flow for dpnID {} " + "with routername {}", dpnId, routerName);
            // best effort to check IntExt model
            naptSwitchHA.bestEffortDeletion(routerId, routerName, externalIpLabel, writeFlowInvTx);
        }
    } catch (Exception ex) {
        LOG.error("removeSNATFromDPN : SNAT->Exception while handling naptSwitch down for router {}", routerName, ex);
    }
}
Also used : GroupEntity(org.opendaylight.genius.mdsalutil.GroupEntity) BigInteger(java.math.BigInteger) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Example 29 with FlowEntity

use of org.opendaylight.genius.mdsalutil.FlowEntity in project netvirt by opendaylight.

the class NatUtil method buildDefaultNATFlowEntityForExternalSubnet.

static FlowEntity buildDefaultNATFlowEntityForExternalSubnet(BigInteger dpId, long vpnId, String subnetId, IdManagerService idManager) {
    InetAddress defaultIP = null;
    try {
        defaultIP = InetAddress.getByName("0.0.0.0");
    } catch (UnknownHostException e) {
        LOG.error("buildDefaultNATFlowEntityForExternalSubnet : Failed to build FIB Table Flow for " + "Default Route to NAT.", e);
        return null;
    }
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(MatchEthernetType.IPV4);
    // add match for vrfid
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
    List<InstructionInfo> instructions = new ArrayList<>();
    List<ActionInfo> actionsInfo = new ArrayList<>();
    long groupId = createGroupId(NatUtil.getGroupIdKey(subnetId), idManager);
    actionsInfo.add(new ActionGroup(groupId));
    String flowRef = getFlowRef(dpId, NwConstants.L3_FIB_TABLE, defaultIP, vpnId);
    instructions.add(new InstructionApplyActions(actionsInfo));
    FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.L3_FIB_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) UnknownHostException(java.net.UnknownHostException) ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) ActionGroup(org.opendaylight.genius.mdsalutil.actions.ActionGroup) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) InetAddress(java.net.InetAddress)

Example 30 with FlowEntity

use of org.opendaylight.genius.mdsalutil.FlowEntity 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)

Aggregations

FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)119 ArrayList (java.util.ArrayList)56 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)52 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)50 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)37 InstructionApplyActions (org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)37 BigInteger (java.math.BigInteger)23 MatchMetadata (org.opendaylight.genius.mdsalutil.matches.MatchMetadata)22 ActionNxResubmit (org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit)17 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)14 ActionPuntToController (org.opendaylight.genius.mdsalutil.actions.ActionPuntToController)12 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)9 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)9 MatchTunnelId (org.opendaylight.genius.mdsalutil.matches.MatchTunnelId)7 Test (org.junit.Test)6 ActionGroup (org.opendaylight.genius.mdsalutil.actions.ActionGroup)6 InstructionWriteMetadata (org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata)6 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)6 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)6 BucketInfo (org.opendaylight.genius.mdsalutil.BucketInfo)5