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;
}
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);
}
}
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);
}
}
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);
}
}
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);
}
Aggregations