Search in sources :

Example 1 with GroupEntity

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

the class ExternalRoutersListener method installSnatMissEntry.

protected void installSnatMissEntry(BigInteger dpnId, List<BucketInfo> bucketInfo, String routerName, long routerId) {
    LOG.debug("installSnatMissEntry : called for dpnId {} with primaryBucket {} ", dpnId, bucketInfo.get(0));
    // Install the select group
    long groupId = createGroupId(getGroupIdKey(routerName));
    GroupEntity groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName, GroupTypes.GroupAll, bucketInfo);
    LOG.debug("installSnatMissEntry : installing the SNAT to NAPT GroupEntity:{}", groupEntity);
    mdsalManager.syncInstallGroup(groupEntity);
    // Install miss entry pointing to group
    FlowEntity flowEntity = buildSnatFlowEntity(dpnId, routerName, routerId, groupId);
    if (flowEntity == null) {
        LOG.error("installSnatMissEntry : Flow entity received as NULL. " + "Cannot proceed with installation of SNAT Flow in table {} which is pointing to Group " + "on Non NAPT DPN {} for router {}", NwConstants.PSNAT_TABLE, dpnId, routerName);
        return;
    }
    mdsalManager.installFlow(flowEntity);
}
Also used : GroupEntity(org.opendaylight.genius.mdsalutil.GroupEntity) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Example 2 with GroupEntity

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

the class ExternalRoutersListener method installGroup.

long installGroup(BigInteger dpnId, String routerName, List<BucketInfo> bucketInfo) {
    long groupId = createGroupId(getGroupIdKey(routerName));
    GroupEntity groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName, GroupTypes.GroupAll, bucketInfo);
    LOG.debug("installGroup : installing the SNAT to NAPT GroupEntity:{}", groupEntity);
    mdsalManager.syncInstallGroup(groupEntity);
    return groupId;
}
Also used : GroupEntity(org.opendaylight.genius.mdsalutil.GroupEntity)

Example 3 with GroupEntity

use of org.opendaylight.genius.mdsalutil.GroupEntity 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 4 with GroupEntity

use of org.opendaylight.genius.mdsalutil.GroupEntity 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 5 with GroupEntity

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

the class VxlanGreConntrackBasedSnatService method installSnatMissEntry.

protected void installSnatMissEntry(BigInteger dpnId, Long routerId, String routerName, BigInteger primarySwitchId, int addOrRemove) {
    LOG.debug("installSnatMissEntry : Installing SNAT miss entry in switch {}", dpnId);
    List<ActionInfo> listActionInfoPrimary = new ArrayList<>();
    String ifNamePrimary = getTunnelInterfaceName(dpnId, primarySwitchId);
    List<BucketInfo> listBucketInfo = new ArrayList<>();
    if (ifNamePrimary != null) {
        LOG.debug("installSnatMissEntry : On Non- Napt switch , Primary Tunnel interface is {}", ifNamePrimary);
        listActionInfoPrimary = NatUtil.getEgressActionsForInterface(interfaceManager, ifNamePrimary, routerId);
    }
    BucketInfo bucketPrimary = new BucketInfo(listActionInfoPrimary);
    listBucketInfo.add(0, bucketPrimary);
    LOG.debug("installSnatMissEntry : installSnatMissEntry called for dpnId {} with primaryBucket {} ", dpnId, listBucketInfo.get(0));
    // Install the select group
    long groupId = createGroupId(getGroupIdKey(routerName));
    GroupEntity groupEntity = MDSALUtil.buildGroupEntity(dpnId, groupId, routerName, GroupTypes.GroupAll, listBucketInfo);
    LOG.debug("installSnatMissEntry : installing the SNAT to NAPT GroupEntity:{}", groupEntity);
    mdsalManager.installGroup(groupEntity);
    // Install miss entry pointing to group
    LOG.debug("installSnatMissEntry : buildSnatFlowEntity is called for dpId {}, routerName {} and groupId {}", dpnId, routerName, groupId);
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(new MatchEthernetType(0x0800L));
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(routerId), MetaDataUtil.METADATA_MASK_VRFID));
    List<ActionInfo> actionsInfo = new ArrayList<>();
    BigInteger tunnelId = BigInteger.valueOf(routerId);
    if (elanManager.isOpenStackVniSemanticsEnforced()) {
        tunnelId = NatOverVxlanUtil.getRouterVni(idManager, routerName, routerId);
    }
    actionsInfo.add(new ActionSetFieldTunnelId(tunnelId));
    LOG.debug("AbstractSnatService : Setting the tunnel to the list of action infos {}", actionsInfo);
    actionsInfo.add(new ActionGroup(groupId));
    List<InstructionInfo> instructions = new ArrayList<>();
    instructions.add(new InstructionApplyActions(actionsInfo));
    String flowRef = getFlowRef(dpnId, NwConstants.PSNAT_TABLE, routerId);
    syncFlow(dpnId, NwConstants.PSNAT_TABLE, flowRef, NatConstants.DEFAULT_PSNAT_FLOW_PRIORITY, flowRef, NwConstants.COOKIE_SNAT_TABLE, matches, instructions, addOrRemove);
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) ActionSetFieldTunnelId(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId) MatchEthernetType(org.opendaylight.genius.mdsalutil.matches.MatchEthernetType) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) ActionGroup(org.opendaylight.genius.mdsalutil.actions.ActionGroup) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) GroupEntity(org.opendaylight.genius.mdsalutil.GroupEntity) BigInteger(java.math.BigInteger) BucketInfo(org.opendaylight.genius.mdsalutil.BucketInfo) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)

Aggregations

GroupEntity (org.opendaylight.genius.mdsalutil.GroupEntity)17 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)5 BigInteger (java.math.BigInteger)4 ArrayList (java.util.ArrayList)4 BucketInfo (org.opendaylight.genius.mdsalutil.BucketInfo)4 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)3 ExecutionException (java.util.concurrent.ExecutionException)2 Test (org.junit.Test)2 AbstractConcurrentDataBrokerTest (org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest)2 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)2 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)2 ActionGroup (org.opendaylight.genius.mdsalutil.actions.ActionGroup)2 ActionSetFieldTunnelId (org.opendaylight.genius.mdsalutil.actions.ActionSetFieldTunnelId)2 InstructionApplyActions (org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)2 MatchEthernetType (org.opendaylight.genius.mdsalutil.matches.MatchEthernetType)2 MatchMetadata (org.opendaylight.genius.mdsalutil.matches.MatchMetadata)2 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)2 VpnNexthop (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthop)2 VpnNexthopBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthopBuilder)2 VpnNexthopKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.vpnnexthops.VpnNexthopKey)2