Search in sources :

Example 91 with FlowEntity

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

the class FloatingIPListener method buildPreSNATFlowEntity.

private FlowEntity buildPreSNATFlowEntity(BigInteger dpId, String internalIp, String externalIp, long vpnId, long routerId, long associatedVpn) {
    LOG.debug("buildPreSNATFlowEntity : Building PSNAT Flow entity for ip {} ", internalIp);
    long 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), 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), 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)

Example 92 with FlowEntity

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

the class FloatingIPListener method removeDNATTblEntry.

private void removeDNATTblEntry(BigInteger dpnId, String internalIp, String externalIp, long routerId, WriteTransaction removeFlowInvTx) {
    FlowEntity preFlowEntity = buildPreDNATDeleteFlowEntity(dpnId, externalIp, routerId);
    mdsalManager.removeFlowToTx(preFlowEntity, removeFlowInvTx);
    FlowEntity flowEntity = buildDNATDeleteFlowEntity(dpnId, internalIp, routerId);
    if (flowEntity != null) {
        mdsalManager.removeFlowToTx(flowEntity, removeFlowInvTx);
    }
}
Also used : FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Example 93 with FlowEntity

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

the class FloatingIPListener method createSNATTblEntry.

private void createSNATTblEntry(BigInteger dpnId, InternalToExternalPortMap mapping, long vpnId, long routerId, long associatedVpnId, Uuid externalNetworkId, WriteTransaction writeFlowInvTx) {
    FlowEntity preFlowEntity = buildPreSNATFlowEntity(dpnId, mapping.getInternalIp(), mapping.getExternalIp(), vpnId, routerId, associatedVpnId);
    mdsalManager.addFlowToTx(preFlowEntity, writeFlowInvTx);
    FlowEntity flowEntity = buildSNATFlowEntity(dpnId, mapping, vpnId, externalNetworkId);
    if (flowEntity != null) {
        mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
    }
}
Also used : FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Example 94 with FlowEntity

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

the class FloatingIPListener method createNATOnlyFlowEntries.

void createNATOnlyFlowEntries(BigInteger dpnId, String routerName, String associatedVPN, Uuid externalNetworkId, InternalToExternalPortMap mapping) {
    String internalIp = mapping.getInternalIp();
    // String segmentId = associatedVPN == null ? routerName : associatedVPN;
    LOG.debug("createNATOnlyFlowEntries : Retrieving vpn id for VPN {} to proceed with create NAT Flows", routerName);
    long routerId = NatUtil.getVpnId(dataBroker, routerName);
    if (routerId == NatConstants.INVALID_ID) {
        LOG.error("createNATOnlyFlowEntries : Could not retrieve vpn id for {} to create NAT Flow entries", routerName);
        return;
    }
    long associatedVpnId = NatUtil.getVpnId(dataBroker, associatedVPN);
    LOG.debug("createNATOnlyFlowEntries : Associated VPN Id {} for router {}", associatedVpnId, routerName);
    long vpnId = getVpnId(externalNetworkId, mapping.getExternalId());
    if (vpnId < 0) {
        LOG.error("createNATOnlyFlowEntries : Unable to create SNAT table entry for fixed ip {}", internalIp);
        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, null, true);
    }
    // Create the DNAT and SNAT table entries
    FlowEntity preFlowEntity = buildPreDNATFlowEntity(dpnId, mapping, routerId, associatedVpnId);
    mdsalManager.installFlow(preFlowEntity);
    FlowEntity flowEntity = buildDNATFlowEntity(dpnId, mapping, routerId, associatedVpnId);
    mdsalManager.installFlow(flowEntity);
    String externalIp = mapping.getExternalIp();
    preFlowEntity = buildPreSNATFlowEntity(dpnId, internalIp, externalIp, vpnId, routerId, associatedVpnId);
    mdsalManager.installFlow(preFlowEntity);
    flowEntity = buildSNATFlowEntity(dpnId, mapping, vpnId, externalNetworkId);
    if (flowEntity != null) {
        mdsalManager.installFlow(flowEntity);
    }
}
Also used : FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Example 95 with FlowEntity

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

the class NaptEventHandler method removeNatFlows.

void removeNatFlows(BigInteger dpnId, short tableId, long segmentId, String ip, int port) {
    if (dpnId == null || dpnId.equals(BigInteger.ZERO)) {
        LOG.error("removeNatFlows : DPN ID {} is invalid", dpnId);
        return;
    }
    LOG.debug("removeNatFlows : Remove NAPT flows for dpnId {}, segmentId {}, ip {} and port {} ", dpnId, segmentId, ip, port);
    // Build the flow with the port IP and port as the match info.
    String switchFlowRef = NatUtil.getNaptFlowRef(dpnId, tableId, String.valueOf(segmentId), ip, port);
    FlowEntity snatFlowEntity = NatUtil.buildFlowEntity(dpnId, tableId, switchFlowRef);
    LOG.debug("removeNatFlows : Remove the flow in the table {} for the switch with the DPN ID {}", NwConstants.INBOUND_NAPT_TABLE, dpnId);
    long startTime = System.currentTimeMillis();
    mdsalManager.removeFlow(snatFlowEntity);
    LOG.trace("removeNatFlows : Time Elapsed for removing table-{} flow from switch with DPN ID:{} " + "for SNAT ({}:{}) session:{}ms", tableId, dpnId, ip, port, System.currentTimeMillis() - startTime);
}
Also used : 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