package org.opendaylight.netvirt.natservice.ha;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
+
import java.math.BigInteger;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
LOG.debug("addToDpnMaps no subnets associated with {}", routerName);
return;
}
- ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(tx -> {
- for (Uuid subnetUuid : addedSubnetIds) {
- String primaryRd = NatUtil.getPrimaryRd(routerName, tx);
- Subnetmap subnetMapEntry = tx.read(LogicalDatastoreType.CONFIGURATION,
- getSubnetMapIdentifier(subnetUuid)).checkedGet().orNull();
- Uuid routerPortUuid = subnetMapEntry.getRouterInterfacePortId();
- subnetIdToRouterPortMap.put(subnetUuid.getValue(), routerPortUuid.getValue());
- vpnFootprintService.updateVpnToDpnMapping(primarySwitchId, routerName, primaryRd,
- routerPortUuid.getValue(), null, true);
- NatUtil.addToNeutronRouterDpnsMap(dataBroker, routerName, routerPortUuid.getValue(),
- primarySwitchId, tx);
- NatUtil.addToDpnRoutersMap(dataBroker, routerName, routerPortUuid.getValue(),
- primarySwitchId, tx);
- if (subnetMapEntry.getNetworkType().equals(NetworkAttributes.NetworkType.VLAN)) {
- String elanInstanceName = subnetMapEntry.getNetworkId().getValue();
- subnetIdToElanInstanceMap.put(subnetUuid.getValue(), elanInstanceName);
- NatUtil.addPseudoPortToElanDpn(elanInstanceName, elanInstanceName, primarySwitchId, dataBroker);
+ Map<Uuid, Subnetmap> subnetMapEntries = new HashMap<>();
+ try {
+ String primaryRd = txRunner.applyWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
+ for (Uuid subnetUuid : addedSubnetIds) {
+ Subnetmap subnetMapEntry = tx.read(getSubnetMapIdentifier(subnetUuid)).get().orNull();
+ subnetMapEntries.put(subnetUuid, subnetMapEntry);
+ Uuid routerPortUuid = subnetMapEntry.getRouterInterfacePortId();
+ subnetIdToRouterPortMap.put(subnetUuid.getValue(), routerPortUuid.getValue());
}
- }
- }), LOG, "Error adding subnets to DPN maps for {}", routerName);
+ return NatUtil.getPrimaryRd(routerName, tx);
+ }).get();
+ ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, tx -> {
+ for (Uuid subnetUuid : addedSubnetIds) {
+ Subnetmap subnetMapEntry = subnetMapEntries.get(subnetUuid);
+ Uuid routerPortUuid = subnetMapEntry.getRouterInterfacePortId();
+ vpnFootprintService.updateVpnToDpnMapping(primarySwitchId, routerName, primaryRd,
+ routerPortUuid.getValue(), null, true);
+ NatUtil.addToNeutronRouterDpnsMap(routerName, routerPortUuid.getValue(), primarySwitchId, tx);
+ NatUtil.addToDpnRoutersMap(routerName, routerPortUuid.getValue(), primarySwitchId, tx);
+ if (subnetMapEntry.getNetworkType().equals(NetworkAttributes.NetworkType.VLAN)) {
+ String elanInstanceName = subnetMapEntry.getNetworkId().getValue();
+ subnetIdToElanInstanceMap.put(subnetUuid.getValue(), elanInstanceName);
+ NatUtil.addPseudoPortToElanDpn(elanInstanceName, elanInstanceName, primarySwitchId, dataBroker);
+ }
+ }
+ }), LOG, "Error adding subnets to DPN maps for {}", routerName);
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Error adding subnets to DPN maps for {}", routerName);
+ }
}
LOG.debug("deleteFromDpnMaps no subnets associated with {}", routerName);
return;
}
- ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(tx -> {
- String primaryRd = NatUtil.getPrimaryRd(routerName, tx);
- for (Uuid subnetUuid : deletedSubnetIds) {
- String routerPort = subnetIdToRouterPortMap.remove(subnetUuid.getValue());
- if (routerPort == null) {
- LOG.error("The router port was not found for {}", subnetUuid.getValue());
- continue;
- }
- vpnFootprintService.updateVpnToDpnMapping(primarySwitchId, routerName, primaryRd,
- routerPort, null, false);
- NatUtil.removeFromNeutronRouterDpnsMap(dataBroker, routerName, primarySwitchId, tx);
- NatUtil.removeFromDpnRoutersMap(dataBroker, routerName, routerName, interfaceManager, tx);
- if (subnetIdToElanInstanceMap.containsKey(subnetUuid.getValue())) {
- String elanInstanceName = subnetIdToElanInstanceMap.remove(subnetUuid.getValue());
- NatUtil.removePseudoPortFromElanDpn(elanInstanceName, elanInstanceName, primarySwitchId,
- dataBroker);
+ try {
+ String primaryRd = txRunner.applyWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
+ tx -> NatUtil.getPrimaryRd(routerName, tx)).get();
+ ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, tx -> {
+ for (Uuid subnetUuid : deletedSubnetIds) {
+ String routerPort = subnetIdToRouterPortMap.remove(subnetUuid.getValue());
+ if (routerPort == null) {
+ LOG.error("The router port was not found for {}", subnetUuid.getValue());
+ continue;
+ }
+ vpnFootprintService.updateVpnToDpnMapping(primarySwitchId, routerName, primaryRd,
+ routerPort, null, false);
+ NatUtil.removeFromNeutronRouterDpnsMap(routerName, primarySwitchId, tx);
+ NatUtil.removeFromDpnRoutersMap(dataBroker, routerName, routerName, interfaceManager, tx);
+ if (subnetIdToElanInstanceMap.containsKey(subnetUuid.getValue())) {
+ String elanInstanceName = subnetIdToElanInstanceMap.remove(subnetUuid.getValue());
+ NatUtil.removePseudoPortFromElanDpn(elanInstanceName, elanInstanceName, primarySwitchId,
+ dataBroker);
+ }
}
- }
- }), LOG, "Error deleting subnets from DPN maps for {}", routerName);
+ }), LOG, "Error deleting subnets from DPN maps for {}", routerName);
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Error deleting subnets from DPN maps for {}", routerName, e);
+ }
}
@Override
package org.opendaylight.netvirt.natservice.internal;
+import static org.opendaylight.controller.md.sal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
+
import com.google.common.base.Optional;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
+import org.opendaylight.genius.infra.Datastore.Configuration;
import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
import org.opendaylight.genius.mdsalutil.ActionInfo;
import org.opendaylight.genius.mdsalutil.MDSALUtil;
import org.opendaylight.genius.mdsalutil.MatchInfo;
final String floatingIpInterface,
final String floatingIpPortMacAddress,
final String rd,
- final String nextHopIp, final WriteTransaction writeFlowInvTx) {
+ final String nextHopIp, final TypedReadWriteTransaction<Configuration> confTx) {
/*
* 1) Install the flow INTERNAL_TUNNEL_TABLE (table=36)-> PDNAT_TABLE (table=25) (SNAT VM on DPN1 is
* responding back to FIP VM on DPN2) {SNAT to DNAT traffic on different Hypervisor}
String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
//Inform to FIB and BGP
NatEvpnUtil.addRoutesForVxLanProvType(dataBroker, bgpManager, fibManager, vpnName, rd, fibExternalIp,
- nextHopIp, l3Vni, floatingIpInterface, floatingIpPortMacAddress,
- writeFlowInvTx, RouteOrigin.STATIC, dpnId);
+ nextHopIp, l3Vni, floatingIpInterface, floatingIpPortMacAddress, confTx, RouteOrigin.STATIC, dpnId);
/* Install the flow table L3_FIB_TABLE (table=21)-> PDNAT_TABLE (table=25)
* (SNAT to DNAT reverse traffic: If the DPN has both SNAT and DNAT configured )
@Override
public void onSuccess(@Nonnull RpcResult<CreateFibEntryOutput> result) {
if (result.isSuccessful()) {
- LOG.info("onAddFloatingIp : Successfully installed custom FIB routes for Floating "
- + "IP Prefix {} on DPN {}", externalIp, dpnId);
- List<Instruction> instructions = new ArrayList<>();
- List<ActionInfo> actionsInfos = new ArrayList<>();
- List<Instruction> customInstructions = new ArrayList<>();
- customInstructions.add(new InstructionGotoTable(NwConstants.PDNAT_TABLE).buildInstruction(0));
- actionsInfos.add(new ActionNxResubmit(NwConstants.PDNAT_TABLE));
- instructions.add(new InstructionApplyActions(actionsInfos).buildInstruction(0));
- /* If more than one floatingIp is available in vpn-to-dpn-list for given dpn id, do not call for
- * installing INTERNAL_TUNNEL_TABLE (table=36) -> PDNAT_TABLE (table=25) flow entry with same tunnel_id
- * again and again.
- */
- if (!NatUtil.isFloatingIpPresentForDpn(dataBroker, dpnId, rd, vpnName, externalIp, true)) {
- makeTunnelTableEntry(dpnId, finalL3Vni, instructions, writeFlowInvTx);
- }
- /* Install the flow L3_GW_MAC_TABLE (table=19)-> PDNAT_TABLE (table=25)
- * (DNAT reverse traffic: If the traffic is Initiated from DC-GW to FIP VM (DNAT forward traffic))
- */
- NatEvpnUtil.makeL3GwMacTableEntry(dpnId, vpnId, floatingIpPortMacAddress, customInstructions,
- mdsalManager, writeFlowInvTx);
- NatUtil.waitForTransactionToComplete(writeFlowInvTx);
+ ListenableFutures.addErrorLogging(
+ txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, innerConfTx -> {
+ LOG.info("onAddFloatingIp : Successfully installed custom FIB routes for Floating "
+ + "IP Prefix {} on DPN {}", externalIp, dpnId);
+ List<Instruction> instructions = new ArrayList<>();
+ List<ActionInfo> actionsInfos = new ArrayList<>();
+ List<Instruction> customInstructions = new ArrayList<>();
+ customInstructions.add(
+ new InstructionGotoTable(NwConstants.PDNAT_TABLE).buildInstruction(0));
+ actionsInfos.add(new ActionNxResubmit(NwConstants.PDNAT_TABLE));
+ instructions.add(new InstructionApplyActions(actionsInfos).buildInstruction(0));
+ /* If more than one floatingIp is available in vpn-to-dpn-list for given dpn id, do not
+ call for
+ * installing INTERNAL_TUNNEL_TABLE (table=36) -> PDNAT_TABLE (table=25) flow entry with
+ * same tunnel_id
+ * again and again.
+ */
+ if (!NatUtil.isFloatingIpPresentForDpn(dataBroker, dpnId, rd, vpnName, externalIp, true)) {
+ makeTunnelTableEntry(dpnId, finalL3Vni, instructions, innerConfTx);
+ }
+ /* Install the flow L3_GW_MAC_TABLE (table=19)-> PDNAT_TABLE (table=25)
+ * (DNAT reverse traffic: If the traffic is Initiated from DC-GW to FIP VM (DNAT forward
+ * traffic))
+ */
+ NatEvpnUtil.makeL3GwMacTableEntry(dpnId, vpnId, floatingIpPortMacAddress,
+ customInstructions,
+ mdsalManager, innerConfTx);
+ }), LOG, "Error installing DNAT flows");
} else {
LOG.error("onAddFloatingIp : Error {} in rpc call to create custom Fib entries for Floating "
+ "IP Prefix {} on DPN {}", result.getErrors(), externalIp, dpnId);
SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
if (optionalVpnInterface.isPresent()) {
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+ ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> {
for (VpnInstanceNames vpnInstance : optionalVpnInterface.get().getVpnInstanceNames()) {
if (!vpnName.equals(vpnInstance.getVpnName())) {
continue;
floatingIpInterface);
InstanceIdentifier<VpnInterfaceOpDataEntry> vpnIfIdentifierOpDataEntry =
NatUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
- tx.put(LogicalDatastoreType.OPERATIONAL, vpnIfIdentifierOpDataEntry,
- vpnIfOpDataEntryBuilder.build(), WriteTransaction.CREATE_MISSING_PARENTS);
+ tx.put(vpnIfIdentifierOpDataEntry, vpnIfOpDataEntryBuilder.build(), CREATE_MISSING_PARENTS);
break;
}
}), LOG, "onAddFloatingIp : Could not write Interface {}, vpnName {}", interfaceName, vpnName);
public void onRemoveFloatingIp(final BigInteger dpnId, final String vpnName, final String externalIp,
final String floatingIpInterface, final String floatingIpPortMacAddress,
- final long routerId, WriteTransaction removeFlowInvTx) {
+ final long routerId, TypedReadWriteTransaction<Configuration> confTx) {
/*
* 1) Remove the flow INTERNAL_TUNNEL_TABLE (table=36)-> PDNAT_TABLE (table=25) (SNAT VM on DPN1 is
* responding back to FIP VM on DPN2) {SNAT to DNAT traffic on different Hypervisor}
@Override
public void onSuccess(@Nonnull RpcResult<RemoveFibEntryOutput> result) {
if (result.isSuccessful()) {
- LOG.info("onRemoveFloatingIp : Successfully removed custom FIB routes for Floating "
- + "IP Prefix {} on DPN {}", externalIp, dpnId);
- /* check if any floating IP information is available in vpn-to-dpn-list for given dpn id.
- * If exist any floating IP then do not remove
- * INTERNAL_TUNNEL_TABLE (table=36) -> PDNAT_TABLE (table=25) flow entry.
- */
- if (!NatUtil.isFloatingIpPresentForDpn(dataBroker, dpnId, rd, vpnName, externalIp, false)) {
- //Remove the flow for INTERNAL_TUNNEL_TABLE (table=36)-> PDNAT_TABLE (table=25)
- removeTunnelTableEntry(dpnId, finalL3Vni, removeFlowInvTx);
- }
- //Remove the flow for L3_GW_MAC_TABLE (table=19)-> PDNAT_TABLE (table=25)
- NatEvpnUtil.removeL3GwMacTableEntry(dpnId, vpnId, floatingIpPortMacAddress, mdsalManager,
- removeFlowInvTx);
- NatUtil.waitForTransactionToComplete(removeFlowInvTx);
+ ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
+ innerConfTx -> {
+ LOG.info("onRemoveFloatingIp : Successfully removed custom FIB routes for Floating "
+ + "IP Prefix {} on DPN {}", externalIp, dpnId);
+ /* check if any floating IP information is available in vpn-to-dpn-list for given dpn id.
+ * If exist any floating IP then do not remove
+ * INTERNAL_TUNNEL_TABLE (table=36) -> PDNAT_TABLE (table=25) flow entry.
+ */
+ if (!NatUtil.isFloatingIpPresentForDpn(dataBroker, dpnId, rd, vpnName, externalIp, false)) {
+ //Remove the flow for INTERNAL_TUNNEL_TABLE (table=36)-> PDNAT_TABLE (table=25)
+ removeTunnelTableEntry(dpnId, finalL3Vni, innerConfTx);
+ }
+ //Remove the flow for L3_GW_MAC_TABLE (table=19)-> PDNAT_TABLE (table=25)
+ NatEvpnUtil.removeL3GwMacTableEntry(dpnId, vpnId, floatingIpPortMacAddress, mdsalManager,
+ innerConfTx);
+ }), LOG, "Error removing flows");
} else {
LOG.error("onRemoveFloatingIp : Error {} in rpc call to remove custom Fib entries for Floating "
+ "IP Prefix {} on DPN {}", result.getErrors(), externalIp, dpnId);
SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
if (optionalVpnInterface.isPresent()) {
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+ ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> {
for (VpnInstanceNames vpnInstance : optionalVpnInterface.get().getVpnInstanceNames()) {
if (!vpnName.equals(vpnInstance.getVpnName())) {
continue;
}
InstanceIdentifier<VpnInterfaceOpDataEntry> vpnOpIfIdentifier = NatUtil
.getVpnInterfaceOpDataEntryIdentifier(floatingIpInterface, vpnName);
- tx.delete(LogicalDatastoreType.OPERATIONAL, vpnOpIfIdentifier);
+ tx.delete(vpnOpIfIdentifier);
break;
}
}), LOG, "onRemoveFloatingIp : Could not remove vpnInterface {}, vpnName {} from Operational "
}
private void makeTunnelTableEntry(BigInteger dpnId, long l3Vni, List<Instruction> customInstructions,
- WriteTransaction writeFlowInvTx) {
+ TypedWriteTransaction<Configuration> confTx) {
LOG.debug("makeTunnelTableEntry : Create terminating service table {} --> table {} flow on DpnId {} "
+ "with l3Vni {} as matching parameter", NwConstants.INTERNAL_TUNNEL_TABLE, NwConstants.PDNAT_TABLE,
dpnId, l3Vni);
NatEvpnUtil.getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, l3Vni, NatConstants.DNAT_FLOW_NAME), 6,
String.format("%s:%d", "TST Flow Entry ", l3Vni),
0, 0, COOKIE_TUNNEL.add(BigInteger.valueOf(l3Vni)), mkMatches, customInstructions);
- mdsalManager.addFlowToTx(dpnId, terminatingServiceTableFlowEntity, writeFlowInvTx);
+ mdsalManager.addFlow(confTx, dpnId, terminatingServiceTableFlowEntity);
LOG.debug("makeTunnelTableEntry : Successfully installed terminating service table flow {} on DpnId {}",
terminatingServiceTableFlowEntity, dpnId);
}
- private void removeTunnelTableEntry(BigInteger dpnId, long l3Vni, WriteTransaction removeFlowInvTx) {
+ private void removeTunnelTableEntry(BigInteger dpnId, long l3Vni, TypedReadWriteTransaction<Configuration> confTx) {
LOG.debug("removeTunnelTableEntry : Remove terminating service table {} --> table {} flow on DpnId {} "
+ "with l3Vni {} as matching parameter", NwConstants.INTERNAL_TUNNEL_TABLE, NwConstants.PDNAT_TABLE,
dpnId, l3Vni);
NatEvpnUtil.getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, l3Vni, NatConstants.DNAT_FLOW_NAME),
6, String.format("%s:%d", "TST Flow Entry ", l3Vni), 0, 0,
COOKIE_TUNNEL.add(BigInteger.valueOf(l3Vni)), mkMatches, null);
- mdsalManager.removeFlowToTx(dpnId, flowEntity, removeFlowInvTx);
+ mdsalManager.removeFlow(confTx, dpnId, flowEntity);
LOG.debug("removeTunnelTableEntry : Successfully removed terminating service table flow {} on DpnId {}",
flowEntity, dpnId);
}
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.genius.infra.Datastore.Configuration;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
import org.opendaylight.genius.mdsalutil.FlowEntity;
import org.opendaylight.genius.mdsalutil.NwConstants;
import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
}
public void evpnRemoveSnatFlowsInOldNaptSwitch(String routerName, long routerId, String vpnName,
- BigInteger naptSwitch, WriteTransaction removeFlowInvTx) {
+ BigInteger naptSwitch, TypedReadWriteTransaction<Configuration> confTx) {
//Handling VXLAN Provider type flow removal from old NAPT switch
Long vpnId = NatUtil.getNetworkVpnIdFromRouterId(dataBroker, routerId);
if (vpnId == NatConstants.INVALID_ID) {
return;
}
//Remove the L3_GW_MAC_TABLE which forwards the packet to Inbound NAPT Table (table19->44)
- NatEvpnUtil.removeL3GwMacTableEntry(naptSwitch, vpnId, gwMacAddress, mdsalManager, removeFlowInvTx);
+ NatEvpnUtil.removeL3GwMacTableEntry(naptSwitch, vpnId, gwMacAddress, mdsalManager, confTx);
//Remove the PDNAT_TABLE which forwards the packet to Inbound NAPT Table (table25->44)
- NatUtil.removePreDnatToSnatTableEntry(mdsalManager, naptSwitch, removeFlowInvTx);
+ NatUtil.removePreDnatToSnatTableEntry(confTx, mdsalManager, naptSwitch);
//Remove the PSNAT_TABLE which forwards the packet to Outbound NAPT Table (table26->46)
String flowRef = getFlowRefSnat(naptSwitch, NwConstants.PSNAT_TABLE, routerName);
LOG.info("evpnRemoveSnatFlowsInOldNaptSwitch: Remove the flow (table26->46) in table {} "
+ "for the old napt switch with the DPN ID {} and router ID {}",
NwConstants.PSNAT_TABLE, naptSwitch, routerId);
- mdsalManager.removeFlowToTx(flowEntity, removeFlowInvTx);
+ mdsalManager.removeFlow(confTx, flowEntity);
//Remove the Terminating Service table entry which forwards the packet to Inbound NAPT Table (table36->44)
LOG.info("evpnRemoveSnatFlowsInOldNaptSwitch : Remove the flow (table36->44) in table {} "
+ "for the old napt switch with the DPN ID {} and router ID {}",
NwConstants.INTERNAL_TUNNEL_TABLE, naptSwitch, routerId);
- evpnSnatFlowProgrammer.removeTunnelTableEntry(naptSwitch, l3Vni, removeFlowInvTx);
+ evpnSnatFlowProgrammer.removeTunnelTableEntry(naptSwitch, l3Vni, confTx);
//Remove the INTERNAL_TUNNEL_TABLE entry which forwards the packet to Outbound NAPT Table (table36->46)
long tunnelId = NatEvpnUtil.getTunnelIdForRouter(idManager, dataBroker, routerName, routerId);
FlowEntity tsNatFlowEntity = NatUtil.buildFlowEntity(naptSwitch, NwConstants.INTERNAL_TUNNEL_TABLE, tsFlowRef);
LOG.info("evpnRemoveSnatFlowsInOldNaptSwitch : Remove the flow in the {} for the active switch "
+ "with the DPN ID {} and router ID {}", NwConstants.INTERNAL_TUNNEL_TABLE, naptSwitch, routerId);
- mdsalManager.removeFlowToTx(tsNatFlowEntity, removeFlowInvTx);
+ mdsalManager.removeFlow(confTx, tsNatFlowEntity);
}
package org.opendaylight.netvirt.natservice.internal;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.genius.infra.Datastore.Configuration;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
import org.opendaylight.genius.mdsalutil.MDSALUtil;
import org.opendaylight.genius.mdsalutil.MatchInfo;
import org.opendaylight.genius.mdsalutil.NwConstants;
import org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable;
import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
import org.opendaylight.genius.mdsalutil.matches.MatchTunnelId;
+import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
import org.opendaylight.netvirt.bgpmanager.api.IBgpManager;
import org.opendaylight.netvirt.fibmanager.api.IFibManager;
import org.opendaylight.netvirt.fibmanager.api.RouteOrigin;
private static final BigInteger COOKIE_TUNNEL = new BigInteger("9000000", 16);
private final DataBroker dataBroker;
+ private final ManagedNewTransactionRunner txRunner;
private final IMdsalApiManager mdsalManager;
private final IBgpManager bgpManager;
private final IFibManager fibManager;
final FibRpcService fibService,
final IdManagerService idManager) {
this.dataBroker = dataBroker;
+ this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
this.mdsalManager = mdsalManager;
this.bgpManager = bgpManager;
this.fibManager = fibManager;
}
public void evpnAdvToBgpAndInstallFibAndTsFlows(final BigInteger dpnId, final short tableId,
- final String externalIp, final String vpnName, final String rd,
- final String nextHopIp, final WriteTransaction writeTx,
- final long routerId, final String routerName,
- WriteTransaction writeFlowInvTx) {
+ final String externalIp, final String vpnName, final String rd, final String nextHopIp,
+ final long routerId, final String routerName, TypedWriteTransaction<Configuration> confTx) {
/*
* 1) Install the flow INTERNAL_TUNNEL_TABLE (table=36)-> INBOUND_NAPT_TABLE (table=44)
* (FIP VM on DPN1 is responding back to external fixed IP on DPN2) {DNAT to SNAT traffic on
*/
//Inform to BGP
NatEvpnUtil.addRoutesForVxLanProvType(dataBroker, bgpManager, fibManager, vpnName, rd, externalIp,
- nextHopIp, l3Vni, null /*InterfaceName*/, gwMacAddress, writeTx, RouteOrigin.STATIC, dpnId);
+ nextHopIp, l3Vni, null /*InterfaceName*/, gwMacAddress, confTx, RouteOrigin.STATIC, dpnId);
//Install custom FIB routes - FIB table.
List<Instruction> customInstructions = new ArrayList<>();
/* Install the flow INTERNAL_TUNNEL_TABLE (table=36)-> INBOUND_NAPT_TABLE (table=44)
* (SNAT to DNAT reverse Traffic: If traffic is Initiated from NAPT to FIP VM on different Hypervisor)
*/
- makeTunnelTableEntry(dpnId, finalL3Vni, customInstructions, tableId, writeFlowInvTx);
+ makeTunnelTableEntry(dpnId, finalL3Vni, customInstructions, tableId, confTx);
/* Install the flow L3_GW_MAC_TABLE (table=19)-> INBOUND_NAPT_TABLE (table=44)
* (SNAT reverse traffic: If the traffic is Initiated from DC-GW to VM (SNAT Reverse traffic))
*/
NatEvpnUtil.makeL3GwMacTableEntry(dpnId, vpnId, gwMacAddress, customInstructions, mdsalManager,
- writeFlowInvTx);
+ confTx);
/* Install the flow PDNAT_TABLE (table=25)-> INBOUND_NAPT_TABLE (table=44)
* If there is no FIP Match on table 25 (PDNAT_TABLE)
*/
- NatUtil.makePreDnatToSnatTableEntry(mdsalManager, dpnId, tableId, writeFlowInvTx);
+ NatUtil.makePreDnatToSnatTableEntry(mdsalManager, dpnId, tableId, confTx);
}
}
}, MoreExecutors.directExecutor());
}
public void evpnDelFibTsAndReverseTraffic(final BigInteger dpnId, final long routerId, final String externalIp,
- final String vpnName, String extGwMacAddress,
- WriteTransaction removeFlowInvTx) {
+ final String vpnName, String extGwMacAddress) {
/*
* 1) Remove the flow INTERNAL_TUNNEL_TABLE (table=36)-> INBOUND_NAPT_TABLE (table=44)
* (FIP VM on DPN1 is responding back to external fixed IP on DPN2) {DNAT to SNAT traffic on
@Override
public void onSuccess(@Nonnull RpcResult<RemoveFibEntryOutput> result) {
if (result.isSuccessful()) {
- LOG.info("evpnDelFibTsAndReverseTraffic : Successfully removed custom FIB routes for "
- + "External Fixed IP {} on DPN {} with l3Vni {}, ExternalVpnName {} for "
- + "RouterId {}", externalIp, dpnId, finalL3Vni, vpnName, routerId);
+ ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
+ innerConfTx -> {
+ LOG.info("evpnDelFibTsAndReverseTraffic : Successfully removed custom FIB routes for "
+ + "External Fixed IP {} on DPN {} with l3Vni {}, ExternalVpnName {} for "
+ + "RouterId {}", externalIp, dpnId, finalL3Vni, vpnName, routerId);
- //remove INTERNAL_TUNNEL_TABLE (table=36)-> INBOUND_NAPT_TABLE (table=44) flow
- removeTunnelTableEntry(dpnId, finalL3Vni, removeFlowInvTx);
- //remove L3_GW_MAC_TABLE (table=19)-> INBOUND_NAPT_TABLE (table=44) flow
- NatUtil.removePreDnatToSnatTableEntry(mdsalManager, dpnId, removeFlowInvTx);
- //remove PDNAT_TABLE (table=25)-> INBOUND_NAPT_TABLE (table=44) flow
- NatEvpnUtil.removeL3GwMacTableEntry(dpnId, vpnId, extGwMacAddress, mdsalManager, removeFlowInvTx);
+ //remove INTERNAL_TUNNEL_TABLE (table=36)-> INBOUND_NAPT_TABLE (table=44) flow
+ removeTunnelTableEntry(dpnId, finalL3Vni, innerConfTx);
+ //remove L3_GW_MAC_TABLE (table=19)-> INBOUND_NAPT_TABLE (table=44) flow
+ NatUtil.removePreDnatToSnatTableEntry(innerConfTx, mdsalManager, dpnId);
+ //remove PDNAT_TABLE (table=25)-> INBOUND_NAPT_TABLE (table=44) flow
+ NatEvpnUtil.removeL3GwMacTableEntry(dpnId, vpnId, extGwMacAddress, mdsalManager,
+ innerConfTx);
+ }), LOG, "Error removing EVPN SNAT table entries");
}
}
}, MoreExecutors.directExecutor());
}
public void makeTunnelTableEntry(BigInteger dpnId, long l3Vni, List<Instruction> customInstructions,
- short tableId, WriteTransaction writeFlowTx) {
+ short tableId, TypedWriteTransaction<Configuration> confTx) {
LOG.debug("makeTunnelTableEntry : Create terminating service table {} --> table {} flow on NAPT DpnId {} "
+ "with l3Vni {} as matching parameter", NwConstants.INTERNAL_TUNNEL_TABLE, tableId, dpnId, l3Vni);
List<MatchInfo> mkMatches = new ArrayList<>();
NatEvpnUtil.getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, l3Vni, NatConstants.SNAT_FLOW_NAME), 5,
String.format("%s:%d", "TST Flow Entry ", l3Vni),
0, 0, COOKIE_TUNNEL.add(BigInteger.valueOf(l3Vni)), mkMatches, customInstructions);
- mdsalManager.addFlowToTx(dpnId, terminatingServiceTableFlowEntity, writeFlowTx);
+ mdsalManager.addFlow(confTx, dpnId, terminatingServiceTableFlowEntity);
LOG.debug("makeTunnelTableEntry : Successfully installed terminating service table flow {} on DpnId {}",
terminatingServiceTableFlowEntity, dpnId);
}
- public void removeTunnelTableEntry(BigInteger dpnId, long l3Vni, WriteTransaction removeFlowInvTx) {
+ public void removeTunnelTableEntry(BigInteger dpnId, long l3Vni, TypedReadWriteTransaction<Configuration> confTx) {
LOG.debug("removeTunnelTableEntry : Remove terminating service table {} --> table {} flow on NAPT DpnId {} "
+ "with l3Vni {} as matching parameter", NwConstants.INTERNAL_TUNNEL_TABLE,
NwConstants.INBOUND_NAPT_TABLE, dpnId, l3Vni);
NatEvpnUtil.getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, l3Vni, NatConstants.SNAT_FLOW_NAME),
5, String.format("%s:%d", "TST Flow Entry ", l3Vni), 0, 0,
COOKIE_TUNNEL.add(BigInteger.valueOf(l3Vni)), mkMatches, null);
- mdsalManager.removeFlowToTx(dpnId, flowEntity, removeFlowInvTx);
+ mdsalManager.removeFlow(confTx, dpnId, flowEntity);
LOG.debug("removeTunnelTableEntry : Successfully removed terminating service table flow {} on DpnId {}",
flowEntity, dpnId);
}
*/
package org.opendaylight.netvirt.natservice.internal;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
import com.google.common.base.Optional;
import java.math.BigInteger;
import java.util.Collection;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
+import org.opendaylight.genius.infra.Datastore.Configuration;
import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
import org.opendaylight.genius.mdsalutil.MDSALUtil;
import org.opendaylight.genius.mdsalutil.NwConstants;
import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
Uuid originalVpn = original.getVpnid();
Uuid updatedVpn = update.getVpnid();
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + update.key(),
- () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+ () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
if (originalVpn == null && updatedVpn != null) {
//external network is dis-associated from L3VPN instance
associateExternalNetworkWithVPN(update, tx);
})), NatConstants.NAT_DJC_MAX_RETRIES);
}
- private void removeSnatEntries(Networks original, Uuid networkUuid, WriteTransaction writeFlowInvTx) {
+ private void removeSnatEntries(Networks original, Uuid networkUuid,
+ TypedReadWriteTransaction<Configuration> writeFlowInvTx) {
List<Uuid> routerUuids = original.getRouterIds();
for (Uuid routerUuid : routerUuids) {
Long routerId = NatUtil.getVpnId(dataBroker, routerUuid.getValue());
}
}
- private void associateExternalNetworkWithVPN(Networks network, WriteTransaction writeFlowInvTx) {
+ private void associateExternalNetworkWithVPN(Networks network, TypedReadWriteTransaction<Configuration> confTx) {
List<Uuid> routerIds = network.getRouterIds();
for (Uuid routerId : routerIds) {
//long router = NatUtil.getVpnId(dataBroker, routerId.getValue());
for (InternalToExternalPortMap ipMap : intExtPortMapList) {
//remove all VPN related entries
floatingIpListener.createNATFlowEntries(dpnId, portName, routerId.getValue(), network.getId(),
- ipMap, writeFlowInvTx);
+ ipMap, confTx);
}
}
}
externalRouterListener.advToBgpAndInstallFibAndTsFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE,
vpnName, routerIdentifier, routerId.getValue(),
externalIp, network.getId(), null /* external-router */,
- writeFlowInvTx);
+ confTx);
}
}
} else {
// Install 47 entry to point to 21
if (natMode == NatMode.Controller) {
externalRouterListener.installNaptPfibEntriesForExternalSubnets(routerId.getValue(), dpnId,
- writeFlowInvTx);
+ confTx);
if (vpnId != -1) {
LOG.debug("associateExternalNetworkWithVPN : Calling externalRouterListener installNaptPfibEntry "
+ "for dpnId {} and vpnId {}", dpnId, vpnId);
- externalRouterListener.installNaptPfibEntry(dpnId, vpnId, writeFlowInvTx);
+ externalRouterListener.installNaptPfibEntry(dpnId, vpnId, confTx);
}
}
}
RouterPorts routerPorts = optRouterPorts.get();
List<Ports> interfaces = routerPorts.getPorts();
try {
- txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+ txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
for (Ports port : interfaces) {
String portName = port.getPortName();
BigInteger dpnId = NatUtil.getDpnForInterface(interfaceManager, portName);
*/
package org.opendaylight.netvirt.natservice.internal;
+import static org.opendaylight.controller.md.sal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
import com.google.common.base.Optional;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
+import org.opendaylight.genius.infra.Datastore.Configuration;
import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
import org.opendaylight.genius.mdsalutil.ActionInfo;
import org.opendaylight.genius.mdsalutil.BucketInfo;
import org.opendaylight.genius.mdsalutil.matches.MatchMplsLabel;
import org.opendaylight.genius.mdsalutil.matches.MatchTunnelId;
import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
-import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
import org.opendaylight.netvirt.bgpmanager.api.IBgpManager;
import org.opendaylight.netvirt.elanmanager.api.IElanService;
import org.opendaylight.netvirt.fibmanager.api.IFibManager;
Uuid bgpVpnUuid = NatUtil.getVpnForRouter(dataBroker, routerName);
try {
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + routers.key(),
- () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
- LOG.info("add : Installing NAT default route on all dpns part of router {}", routerName);
- long bgpVpnId = NatConstants.INVALID_ID;
- if (bgpVpnUuid != null) {
- bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnUuid.getValue());
- }
- addOrDelDefFibRouteToSNAT(routerName, routerId, bgpVpnId, bgpVpnUuid, true, tx);
- // Allocate Primary Napt Switch for this router
- BigInteger primarySwitchId = getPrimaryNaptSwitch(routerName);
- if (primarySwitchId != null && !primarySwitchId.equals(BigInteger.ZERO)) {
- if (!routers.isEnableSnat()) {
- LOG.info("add : SNAT is disabled for external router {} ", routerName);
- /* If SNAT is disabled on ext-router though L3_FIB_TABLE(21) -> PSNAT_TABLE(26) flow
- * is required for DNAT. Hence writeFlowInvTx object submit is required.
- */
- return;
+ () -> Collections.singletonList(
+ txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> {
+ LOG.info("add : Installing NAT default route on all dpns part of router {}", routerName);
+ long bgpVpnId = NatConstants.INVALID_ID;
+ if (bgpVpnUuid != null) {
+ bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnUuid.getValue());
}
- handleEnableSnat(routers, routerId, primarySwitchId, bgpVpnId, tx);
- }
- })), NatConstants.NAT_DJC_MAX_RETRIES);
+ addOrDelDefFibRouteToSNAT(routerName, routerId, bgpVpnId, bgpVpnUuid, true, confTx);
+ // Allocate Primary Napt Switch for this router
+ BigInteger primarySwitchId = getPrimaryNaptSwitch(routerName);
+ if (primarySwitchId != null && !primarySwitchId.equals(BigInteger.ZERO)) {
+ if (!routers.isEnableSnat()) {
+ LOG.info("add : SNAT is disabled for external router {} ", routerName);
+ /* If SNAT is disabled on ext-router though L3_FIB_TABLE(21) -> PSNAT_TABLE(26) flow
+ * is required for DNAT. Hence writeFlowInvTx object submit is required.
+ */
+ return;
+ }
+ handleEnableSnat(routers, routerId, primarySwitchId, bgpVpnId, confTx);
+ }
+ })), NatConstants.NAT_DJC_MAX_RETRIES);
} catch (Exception ex) {
LOG.error("add : Exception while Installing NAT flows on all dpns as part of router {}",
routerName, ex);
}
public void handleEnableSnat(Routers routers, long routerId, BigInteger primarySwitchId, long bgpVpnId,
- WriteTransaction writeFlowInvTx) {
+ TypedWriteTransaction<Configuration> confTx) {
String routerName = routers.getRouterName();
LOG.info("handleEnableSnat : Handling SNAT for router {}", routerName);
}
if (bgpVpnId != NatConstants.INVALID_ID) {
- installFlowsWithUpdatedVpnId(primarySwitchId, routerName, bgpVpnId, routerId, false, writeFlowInvTx,
+ installFlowsWithUpdatedVpnId(primarySwitchId, routerName, bgpVpnId, routerId, false, confTx,
extNwProvType);
} else {
// write metadata and punt
- installOutboundMissEntry(routerName, routerId, primarySwitchId, writeFlowInvTx);
+ installOutboundMissEntry(routerName, routerId, primarySwitchId, confTx);
// Now install entries in SNAT tables to point to Primary for each router
List<BigInteger> switches = naptSwitchSelector.getDpnsForVpn(routerName);
for (BigInteger dpnId : switches) {
handleSwitches(dpnId, routerName, routerId, primarySwitchId);
} else {
LOG.debug("handleEnableSnat : Handle NAPT switch");
- handlePrimaryNaptSwitch(dpnId, routerName, routerId, writeFlowInvTx);
+ handlePrimaryNaptSwitch(dpnId, routerName, routerId, confTx);
}
}
}
for (String externalIpAddrPrefix : externalIps) {
LOG.debug("handleEnableSnat : Calling handleSnatReverseTraffic for primarySwitchId {}, "
+ "routerName {} and externalIpAddPrefix {}", primarySwitchId, routerName, externalIpAddrPrefix);
- handleSnatReverseTraffic(primarySwitchId, routers, routerId, routerName, externalIpAddrPrefix,
- writeFlowInvTx);
+ handleSnatReverseTraffic(confTx, primarySwitchId, routers, routerId, routerName, externalIpAddrPrefix
+ );
}
}
LOG.debug("handleEnableSnat : Exit");
}
protected void installNaptPfibExternalOutputFlow(String routerName, Long routerId, BigInteger dpnId,
- WriteTransaction writeFlowInvTx) {
+ TypedWriteTransaction<Configuration> confTx) {
Long extVpnId = NatUtil.getNetworkVpnIdFromRouterId(dataBroker, routerId);
if (extVpnId == NatConstants.INVALID_ID) {
LOG.error("installNaptPfibExternalOutputFlow - not found extVpnId for router {}", routerId);
LOG.debug("installNaptPfibExternalOutputFlow - dpnId {} extVpnId {} subnetId {}",
dpnId, extVpnId, subnetId);
FlowEntity postNaptFlowEntity = buildNaptPfibFlowEntity(dpnId, extVpnId);
- mdsalManager.addFlowToTx(postNaptFlowEntity, writeFlowInvTx);
+ mdsalManager.addFlow(confTx, postNaptFlowEntity);
}
}
}
+ @Nullable
private Uuid getSubnetIdForFixedIp(String ip) {
if (ip != null) {
IpAddress externalIpv4Address = new IpAddress(new Ipv4Address(ip));
Port port = NatUtil.getNeutronPortForRouterGetewayIp(dataBroker, externalIpv4Address);
- Uuid subnetId = NatUtil.getSubnetIdForFloatingIp(port, externalIpv4Address);
- return subnetId;
+ return NatUtil.getSubnetIdForFloatingIp(port, externalIpv4Address);
}
LOG.error("getSubnetIdForFixedIp : ip is null");
return null;
}
protected void subnetRegisterMapping(Routers routerEntry, Long segmentId) {
- List<Uuid> subnetList = null;
- List<String> externalIps = null;
LOG.debug("subnetRegisterMapping : Fetching values from extRouters model");
- subnetList = routerEntry.getSubnetIds();
- externalIps = NatUtil.getIpsListFromExternalIps(routerEntry.getExternalIps());
+ List<Uuid> subnetList = routerEntry.getSubnetIds();
+ List<String> externalIps = NatUtil.getIpsListFromExternalIps(routerEntry.getExternalIps());
int counter = 0;
int extIpCounter = externalIps.size();
LOG.debug("subnetRegisterMapping : counter values before looping counter {} and extIpCounter {}",
}
private void addOrDelDefFibRouteToSNAT(String routerName, long routerId, long bgpVpnId,
- Uuid bgpVpnUuid, boolean create, WriteTransaction writeFlowInvTx) {
+ Uuid bgpVpnUuid, boolean create, TypedReadWriteTransaction<Configuration> confTx) {
//Check if BGP VPN exists. If exists then invoke the new method.
if (bgpVpnId != NatConstants.INVALID_ID) {
if (bgpVpnUuid != null) {
bgpVpnId, bgpVpnName);
RouterIds rtrs = new RouterIdsBuilder().withKey(new RouterIdsKey(bgpVpnId))
.setRouterId(bgpVpnId).setRouterName(bgpVpnName).build();
- MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
- getRoutersIdentifier(bgpVpnId), rtrs);
+ confTx.put(getRoutersIdentifier(bgpVpnId), rtrs, CREATE_MISSING_PARENTS);
+ }
+ if (create) {
+ addDefaultFibRouteForSnatWithBgpVpn(routerName, routerId, bgpVpnId, confTx);
+ } else {
+ removeDefaultFibRouteForSnatWithBgpVpn(routerName, routerId, bgpVpnId, confTx);
}
- addOrDelDefaultFibRouteForSnatWithBgpVpn(routerName, routerId, bgpVpnId, create, writeFlowInvTx);
return;
}
//Router ID is used as the internal VPN's name, hence the vrf-id in VpnInstance Op DataStore
- addOrDelDefaultFibRouteForSNAT(routerName, routerId, create, writeFlowInvTx);
+ addOrDelDefaultFibRouteForSNAT(routerName, routerId, create, confTx);
}
private void addOrDelDefaultFibRouteForSNAT(String routerName, long routerId, boolean create,
- WriteTransaction writeFlowInvTx) {
+ TypedReadWriteTransaction<Configuration> confTx) {
List<BigInteger> switches = naptSwitchSelector.getDpnsForVpn(routerName);
if (switches.isEmpty()) {
LOG.info("addOrDelDefaultFibRouteForSNAT : No switches found for router {}", routerName);
if (create) {
LOG.debug("addOrDelDefaultFibRouteForSNAT : installing default NAT route for router {} in dpn {} "
+ "for the internal vpn-id {}", routerId, dpnId, routerId);
- defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, routerId, writeFlowInvTx);
+ defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, routerId, confTx);
} else {
LOG.debug("addOrDelDefaultFibRouteForSNAT : removing default NAT route for router {} in dpn {} "
+ "for the internal vpn-id {}", routerId, dpnId, routerId);
- defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, routerId, writeFlowInvTx);
+ defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, routerId, confTx);
}
}
}
- private void addOrDelDefaultFibRouteForSnatWithBgpVpn(String routerName, long routerId,
- long bgpVpnId, boolean create,WriteTransaction writeFlowInvTx) {
+ private void addDefaultFibRouteForSnatWithBgpVpn(String routerName, long routerId,
+ long bgpVpnId, TypedWriteTransaction<Configuration> confTx) {
List<BigInteger> dpnIds = NatUtil.getDpnsForRouter(dataBroker, routerName);
if (dpnIds.isEmpty()) {
LOG.error("addOrDelDefaultFibRouteForSNATWIthBgpVpn: No dpns are part of router {} to program "
- + "default NAT flows for BGP-VPN {}", routerName, bgpVpnId);
+ + "default NAT flows for BGP-VPN {}", routerName, bgpVpnId);
return;
}
for (BigInteger dpnId : dpnIds) {
- if (create) {
- if (bgpVpnId != NatConstants.INVALID_ID) {
- LOG.debug("addOrDelDefaultFibRouteForSnatWithBgpVpn : installing default NAT route for router {} "
- + "in dpn {} for the BGP vpnID {}", routerId, dpnId, bgpVpnId);
- defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, bgpVpnId, routerId, writeFlowInvTx);
- } else {
- LOG.debug("addOrDelDefaultFibRouteForSnatWithBgpVpn : installing default NAT route for router {} "
- + "in dpn {} for the internal vpn", routerId, dpnId);
- defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, routerId,writeFlowInvTx);
- }
+ if (bgpVpnId != NatConstants.INVALID_ID) {
+ LOG.debug("addOrDelDefaultFibRouteForSnatWithBgpVpn : installing default NAT route for router {} "
+ + "in dpn {} for the BGP vpnID {}", routerId, dpnId, bgpVpnId);
+ defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, bgpVpnId, routerId, confTx);
} else {
- if (bgpVpnId != NatConstants.INVALID_ID) {
- LOG.debug("addOrDelDefaultFibRouteForSnatWithBgpVpn : removing default NAT route for router {} "
- + "in dpn {} for the BGP vpnID {}", routerId, dpnId, bgpVpnId);
- defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, bgpVpnId, routerId, writeFlowInvTx);
- } else {
- LOG.debug("addOrDelDefaultFibRouteForSnatWithBgpVpn : removing default NAT route for router {} "
- + "in dpn {} for the internal vpn", routerId, dpnId);
- defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, routerId, writeFlowInvTx);
- }
+ LOG.debug("addOrDelDefaultFibRouteForSnatWithBgpVpn : installing default NAT route for router {} "
+ + "in dpn {} for the internal vpn", routerId, dpnId);
+ defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, routerId, confTx);
+ }
+ }
+ }
+
+ private void removeDefaultFibRouteForSnatWithBgpVpn(String routerName, long routerId,
+ long bgpVpnId, TypedReadWriteTransaction<Configuration> confTx) {
+ List<BigInteger> dpnIds = NatUtil.getDpnsForRouter(dataBroker, routerName);
+ if (dpnIds.isEmpty()) {
+ LOG.error("addOrDelDefaultFibRouteForSNATWIthBgpVpn: No dpns are part of router {} to program "
+ + "default NAT flows for BGP-VPN {}", routerName, bgpVpnId);
+ return;
+ }
+ for (BigInteger dpnId : dpnIds) {
+ if (bgpVpnId != NatConstants.INVALID_ID) {
+ LOG.debug("addOrDelDefaultFibRouteForSnatWithBgpVpn : removing default NAT route for router {} "
+ + "in dpn {} for the BGP vpnID {}", routerId, dpnId, bgpVpnId);
+ defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, bgpVpnId, routerId, confTx);
+ } else {
+ LOG.debug("addOrDelDefaultFibRouteForSnatWithBgpVpn : removing default NAT route for router {} "
+ + "in dpn {} for the internal vpn", routerId, dpnId);
+ defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, routerId, confTx);
}
}
}
}
protected void installOutboundMissEntry(String routerName, long routerId, BigInteger primarySwitchId,
- WriteTransaction writeFlowInvTx) {
+ TypedWriteTransaction<Configuration> confTx) {
LOG.debug("installOutboundMissEntry : Router ID from getVpnId {}", routerId);
if (routerId != NatConstants.INVALID_ID) {
LOG.debug("installOutboundMissEntry : Creating miss entry on primary {}, for router {}",
primarySwitchId, routerId);
- createOutboundTblEntry(primarySwitchId, routerId, writeFlowInvTx);
+ createOutboundTblEntry(primarySwitchId, routerId, confTx);
} else {
LOG.error("installOutboundMissEntry : Unable to fetch Router Id for RouterName {}, failed to "
+ "createAndInstallMissEntry", routerName);
return flowEntity;
}
- public void createOutboundTblEntry(BigInteger dpnId, long routerId, WriteTransaction writeFlowInvTx) {
+ public void createOutboundTblEntry(BigInteger dpnId, long routerId, TypedWriteTransaction<Configuration> confTx) {
LOG.debug("createOutboundTblEntry : called for dpId {} and routerId {}", dpnId, routerId);
FlowEntity tcpflowEntity = buildOutboundFlowEntity(dpnId, routerId, NwConstants.IP_PROT_TCP);
LOG.debug("createOutboundTblEntry : Installing tcp flow {}", tcpflowEntity);
- mdsalManager.addFlowToTx(tcpflowEntity, writeFlowInvTx);
+ mdsalManager.addFlow(confTx, tcpflowEntity);
FlowEntity udpflowEntity = buildOutboundFlowEntity(dpnId, routerId, NwConstants.IP_PROT_UDP);
LOG.debug("createOutboundTblEntry : Installing udp flow {}", udpflowEntity);
- mdsalManager.addFlowToTx(udpflowEntity, writeFlowInvTx);
+ mdsalManager.addFlow(confTx, udpflowEntity);
FlowEntity icmpDropFlow = buildIcmpDropFlow(dpnId, routerId, routerId);
LOG.debug("createOutboundTblEntry: Installing icmp drop flow {}", icmpDropFlow);
- mdsalManager.addFlowToTx(icmpDropFlow, writeFlowInvTx);
+ mdsalManager.addFlow(confTx, icmpDropFlow);
}
protected String getTunnelInterfaceName(BigInteger srcDpId, BigInteger dstDpId) {
}
protected void installSnatMissEntryForPrimrySwch(BigInteger dpnId, String routerName, long routerId,
- WriteTransaction writeFlowInvTx) {
+ TypedWriteTransaction<Configuration> confTx) {
+
LOG.debug("installSnatMissEntry : called for for the primary NAPT switch dpnId {} ", dpnId);
// Install miss entry pointing to group
FlowEntity flowEntity = buildSnatFlowEntityForPrmrySwtch(dpnId, routerName, routerId);
- mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
+ mdsalManager.addFlow(confTx, flowEntity);
}
protected void installSnatMissEntry(BigInteger dpnId, List<BucketInfo> bucketInfo,
// TODO : Replace this with ITM Rpc once its available with full functionality
protected void installTerminatingServiceTblEntry(BigInteger dpnId, String routerName, long routerId,
- WriteTransaction writeFlowInvTx) {
+ TypedWriteTransaction<Configuration> confTx) {
+
LOG.debug("installTerminatingServiceTblEntry : for switch {}, routerName {}",
dpnId, routerName);
FlowEntity flowEntity = buildTsFlowEntity(dpnId, routerName, routerId);
dpnId, routerName);
return;
}
- mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
+ mdsalManager.addFlow(confTx, flowEntity);
}
}
protected void handlePrimaryNaptSwitch(BigInteger dpnId, String routerName, long routerId,
- WriteTransaction writeFlowInvTx) {
+ TypedWriteTransaction<Configuration> confTx) {
+
/*
* Primary NAPT Switch – bucket Should always point back to its own Outbound Table
*/
listBucketInfo.add(0, bucketPrimary);
*/
- installSnatMissEntryForPrimrySwch(dpnId, routerName, routerId, writeFlowInvTx);
- installTerminatingServiceTblEntry(dpnId, routerName, routerId, writeFlowInvTx);
+ installSnatMissEntryForPrimrySwch(dpnId, routerName, routerId, confTx);
+ installTerminatingServiceTblEntry(dpnId, routerName, routerId, confTx);
//Install the NAPT PFIB TABLE which forwards the outgoing packet to FIB Table matching on the router ID.
- installNaptPfibEntry(dpnId, routerId, writeFlowInvTx);
+ installNaptPfibEntry(dpnId, routerId, confTx);
Uuid networkId = NatUtil.getNetworkIdFromRouterId(dataBroker, routerId);
if (networkId != null) {
Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
return listBucketInfo;
}
- public void installNaptPfibEntry(BigInteger dpnId, long segmentId, WriteTransaction writeFlowInvTx) {
+ public void installNaptPfibEntry(BigInteger dpnId, long segmentId, TypedWriteTransaction<Configuration> confTx) {
LOG.debug("installNaptPfibEntry : called for dpnId {} and segmentId {} ", dpnId, segmentId);
FlowEntity naptPfibFlowEntity = buildNaptPfibFlowEntity(dpnId, segmentId);
- if (writeFlowInvTx != null) {
- mdsalManager.addFlowToTx(naptPfibFlowEntity, writeFlowInvTx);
+ if (confTx != null) {
+ mdsalManager.addFlow(confTx, naptPfibFlowEntity);
} else {
mdsalManager.installFlow(naptPfibFlowEntity);
}
return flowEntity;
}
- public void handleSnatReverseTraffic(BigInteger dpnId, Routers router, long routerId, String routerName,
- String externalIp, WriteTransaction writeFlowInvTx) {
+ public void handleSnatReverseTraffic(TypedWriteTransaction<Configuration> confTx, BigInteger dpnId, Routers router,
+ long routerId, String routerName, String externalIp) {
LOG.debug("handleSnatReverseTraffic : entry for DPN ID {}, routerId {}, externalIp: {}",
dpnId, routerId, externalIp);
Uuid networkId = router.getNetworkId();
return;
}
advToBgpAndInstallFibAndTsFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE, vpnName, routerId, routerName,
- externalIp, networkId, router, writeFlowInvTx);
+ externalIp, networkId, router, confTx);
LOG.debug("handleSnatReverseTraffic : exit for DPN ID {}, routerId {}, externalIp : {}",
dpnId, routerId, externalIp);
}
public void advToBgpAndInstallFibAndTsFlows(final BigInteger dpnId, final short tableId, final String vpnName,
final long routerId, final String routerName, final String externalIp,
final Uuid extNetworkId, final Routers router,
- final WriteTransaction writeFlowInvTx) {
+ final TypedWriteTransaction<Configuration> confTx) {
LOG.debug("advToBgpAndInstallFibAndTsFlows : entry for DPN ID {}, tableId {}, vpnname {} "
+ "and externalIp {}", dpnId, tableId, vpnName, externalIp);
String nextHopIp = NatUtil.getEndpointIpAddressForDPN(dataBroker, dpnId);
return;
}
if (extNwProvType == ProviderTypes.VXLAN) {
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
- tx -> evpnSnatFlowProgrammer.evpnAdvToBgpAndInstallFibAndTsFlows(dpnId, tableId, externalIp,
- vpnName, rd, nextHopIp, tx, routerId, routerName, writeFlowInvTx)), LOG,
- "Error installing FIB and TS flows");
+ evpnSnatFlowProgrammer.evpnAdvToBgpAndInstallFibAndTsFlows(dpnId, tableId, externalIp, vpnName, rd,
+ nextHopIp, routerId, routerName, confTx);
return;
}
//Generate VPN label for the external IP
//Install custom FIB routes
List<Instruction> tunnelTableCustomInstructions = new ArrayList<>();
tunnelTableCustomInstructions.add(new InstructionGotoTable(tableId).buildInstruction(0));
- makeTunnelTableEntry(dpnId, label, l3vni, tunnelTableCustomInstructions, writeFlowInvTx,
+ makeTunnelTableEntry(dpnId, label, l3vni, tunnelTableCustomInstructions, confTx,
extNwProvType);
- makeLFibTableEntry(dpnId, label, tableId, writeFlowInvTx);
+ makeLFibTableEntry(dpnId, label, tableId, confTx);
//Install custom FIB routes - FIB table.
List<Instruction> fibTableCustomInstructions = createFibTableCustomInstructions(tableId,
routerName, externalIp);
if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
//Install the flow table 25->44 If there is no FIP Match on table 25 (PDNAT_TABLE)
- NatUtil.makePreDnatToSnatTableEntry(mdsalManager, dpnId,
- NwConstants.INBOUND_NAPT_TABLE,writeFlowInvTx);
+ NatUtil.makePreDnatToSnatTableEntry(mdsalManager, dpnId, NwConstants.INBOUND_NAPT_TABLE, confTx);
}
String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
Optional<Subnets> externalSubnet = NatUtil.getOptionalExternalSubnets(dataBroker,
return fibTableCustomInstructions;
}
- private void makeLFibTableEntry(BigInteger dpId, long serviceId, short tableId, WriteTransaction writeFlowInvTx) {
+ private void makeLFibTableEntry(BigInteger dpId, long serviceId, short tableId,
+ TypedWriteTransaction<Configuration> confTx) {
List<MatchInfo> matches = new ArrayList<>();
matches.add(MatchEthernetType.MPLS_UNICAST);
matches.add(new MatchMplsLabel(serviceId));
10, flowRef, 0, 0,
COOKIE_VM_LFIB_TABLE, matches, instructions);
- mdsalManager.addFlowToTx(dpId, flowEntity, writeFlowInvTx);
+ mdsalManager.addFlow(confTx, dpId, flowEntity);
LOG.debug("makeLFibTableEntry : LFIB Entry for dpID {} : label : {} modified successfully", dpId, serviceId);
}
private void makeTunnelTableEntry(BigInteger dpnId, long serviceId, long l3Vni,
- List<Instruction> customInstructions, WriteTransaction writeFlowInvTx, ProviderTypes extNwProvType) {
+ List<Instruction> customInstructions, TypedWriteTransaction<Configuration> confTx,
+ ProviderTypes extNwProvType) {
+
List<MatchInfo> mkMatches = new ArrayList<>();
LOG.debug("makeTunnelTableEntry : DpnId = {} and serviceId = {} and actions = {}",
String.format("%s:%d", "TST Flow Entry ", serviceId),
0, 0, COOKIE_TUNNEL.add(BigInteger.valueOf(serviceId)), mkMatches, customInstructions);
- mdsalManager.addFlowToTx(dpnId, terminatingServiceTableFlowEntity, writeFlowInvTx);
+ mdsalManager.addFlow(confTx, dpnId, terminatingServiceTableFlowEntity);
}
protected InstanceIdentifier<RouterIds> getRoutersIdentifier(long routerId) {
- InstanceIdentifier<RouterIds> id = InstanceIdentifier.builder(
- RouterIdName.class).child(RouterIds.class, new RouterIdsKey(routerId)).build();
- return id;
+ return InstanceIdentifier.builder(RouterIdName.class).child(RouterIds.class,
+ new RouterIdsKey(routerId)).build();
}
private String getFlowRef(BigInteger dpnId, short tableId, long id, String ipAddress) {
final long finalBgpVpnId = bgpVpnId;
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + update.key(), () -> {
List<ListenableFuture<Void>> futures = new ArrayList<>();
- futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeFlowInvTx -> {
- futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(removeFlowInvTx -> {
+ futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, writeFlowInvTx -> {
+ futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, removeFlowInvTx -> {
Uuid networkId = original.getNetworkId();
if (originalSNATEnabled != updatedSNATEnabled) {
if (originalSNATEnabled) {
}
private void allocateExternalIp(BigInteger dpnId, Routers router, long routerId, String routerName,
- Uuid networkId, String subnetIp, WriteTransaction writeFlowInvTx) {
+ Uuid networkId, String subnetIp, TypedWriteTransaction<Configuration> writeFlowInvTx) {
String[] subnetIpParts = NatUtil.getSubnetIpAndPrefix(subnetIp);
try {
InetAddress address = InetAddress.getByName(subnetIpParts[0]);
String routerName = router.getRouterName();
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + router.key(),
- () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+ () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
LOG.info("remove : Removing default NAT route from FIB on all dpns part of router {} ",
routerName);
- List<ListenableFuture<Void>> futures = new ArrayList<>();
Long routerId = NatUtil.getVpnId(dataBroker, routerName);
if (routerId == NatConstants.INVALID_ID) {
LOG.error("remove : Remove external router event - Invalid routerId for routerName {}",
@SuppressWarnings("checkstyle:IllegalCatch")
public void handleDisableSnat(Routers router, Uuid networkUuid, @Nonnull Collection<String> externalIps,
boolean routerFlag, String vpnName, BigInteger naptSwitchDpnId,
- long routerId, WriteTransaction removeFlowInvTx) {
+ long routerId, TypedReadWriteTransaction<Configuration> removeFlowInvTx) {
LOG.info("handleDisableSnat : Entry");
String routerName = router.getRouterName();
try {
@SuppressWarnings("checkstyle:IllegalCatch")
public void handleDisableSnatInternetVpn(String routerName, long routerId, Uuid networkUuid,
@Nonnull Collection<String> externalIps,
- String vpnId, WriteTransaction writeFlowInvTx) {
+ String vpnId, TypedReadWriteTransaction<Configuration> writeFlowInvTx) {
LOG.debug("handleDisableSnatInternetVpn: Started to process handle disable snat for router {} "
+ "with internet vpn {}", routerName, vpnId);
try {
BigInteger dpnId, Uuid networkId, String vpnName,
@Nonnull Collection<String> externalIps,
Collection<Uuid> externalSubnetList,
- WriteTransaction removeFlowInvTx, ProviderTypes extNwProvType) {
+ TypedReadWriteTransaction<Configuration> confTx,
+ ProviderTypes extNwProvType) {
LOG.debug("removeNaptFlowsFromActiveSwitch : Remove NAPT flows from Active switch");
BigInteger cookieSnatFlow = NatUtil.getCookieNaptFlow(routerId);
LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active switch with the DPN ID {} "
+ "and router ID {}", NwConstants.PSNAT_TABLE, dpnId, routerId);
- mdsalManager.removeFlowToTx(preSnatFlowEntity, removeFlowInvTx);
+ mdsalManager.removeFlow(confTx, preSnatFlowEntity);
//Remove the Terminating Service table entry which forwards the packet to Outbound NAPT Table (For the
// traffic which comes from the VMs of the non NAPT switches)
FlowEntity tsNatFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, tsFlowRef);
LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active switch with the DPN ID {} "
+ "and router ID {}", NwConstants.INTERNAL_TUNNEL_TABLE, dpnId, routerId);
- mdsalManager.removeFlowToTx(tsNatFlowEntity, removeFlowInvTx);
+ mdsalManager.removeFlow(confTx, tsNatFlowEntity);
//Remove the flow table 25->44 from NAPT Switch
if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
- NatUtil.removePreDnatToSnatTableEntry(mdsalManager, dpnId, removeFlowInvTx);
+ NatUtil.removePreDnatToSnatTableEntry(confTx, mdsalManager, dpnId);
}
//Remove the Outbound flow entry which forwards the packet to FIB Table
NwConstants.IP_PROT_TCP);
FlowEntity outboundTcpNatFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.OUTBOUND_NAPT_TABLE,
outboundTcpNatFlowRef);
- mdsalManager.removeFlowToTx(outboundTcpNatFlowEntity, removeFlowInvTx);
+ mdsalManager.removeFlow(confTx, outboundTcpNatFlowEntity);
String outboundUdpNatFlowRef = getFlowRefOutbound(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId,
NwConstants.IP_PROT_UDP);
FlowEntity outboundUdpNatFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.OUTBOUND_NAPT_TABLE,
outboundUdpNatFlowRef);
- mdsalManager.removeFlowToTx(outboundUdpNatFlowEntity, removeFlowInvTx);
+ mdsalManager.removeFlow(confTx, outboundUdpNatFlowEntity);
String icmpDropFlowRef = getFlowRefOutbound(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId,
NwConstants.IP_PROT_ICMP);
FlowEntity icmpDropFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.OUTBOUND_NAPT_TABLE,
icmpDropFlowRef);
- mdsalManager.removeFlowToTx(icmpDropFlowEntity, removeFlowInvTx);
+ mdsalManager.removeFlow(confTx, icmpDropFlowEntity);
- removeNaptFibExternalOutputFlows(routerId, dpnId, networkId, externalIps, removeFlowInvTx);
+ removeNaptFibExternalOutputFlows(routerId, dpnId, networkId, externalIps, confTx);
//Remove the NAPT PFIB TABLE (47->21) which forwards the incoming packet to FIB Table matching on the
// External Subnet Vpn Id.
for (Uuid externalSubnetId : externalSubnetList) {
String natPfibSubnetFlowRef = getFlowRefTs(dpnId, NwConstants.NAPT_PFIB_TABLE, subnetVpnId);
FlowEntity natPfibFlowEntity = NatUtil.buildFlowEntity(dpnId, NwConstants.NAPT_PFIB_TABLE,
natPfibSubnetFlowRef);
- mdsalManager.removeFlowToTx(natPfibFlowEntity, removeFlowInvTx);
+ mdsalManager.removeFlow(confTx, natPfibFlowEntity);
LOG.debug("removeNaptFlowsFromActiveSwitch : Removed the flow in table {} with external subnet "
+ "Vpn Id {} as metadata on Napt Switch {}", NwConstants.NAPT_PFIB_TABLE,
subnetVpnId, dpnId);
LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active switch with the DPN ID {} "
+ "and router ID {}", NwConstants.NAPT_PFIB_TABLE, dpnId, routerId);
- mdsalManager.removeFlowToTx(natPfibFlowEntity, removeFlowInvTx);
+ mdsalManager.removeFlow(confTx, natPfibFlowEntity);
// Long vpnId = NatUtil.getVpnId(dataBroker, routerId);
// - This does not work since ext-routers is deleted already - no network info
NatUtil.buildFlowEntity(dpnId, NwConstants.NAPT_PFIB_TABLE, natPfibVpnFlowRef);
LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in {} for the active switch with the DPN ID {} "
+ "and VPN ID {}", NwConstants.NAPT_PFIB_TABLE, dpnId, vpnId);
- mdsalManager.removeFlowToTx(natPfibVpnFlowEntity, removeFlowInvTx);
+ mdsalManager.removeFlow(confTx, natPfibVpnFlowEntity);
}
//For the router ID get the internal IP , internal port and the corresponding external IP and external Port.
LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active switch "
+ "with the DPN ID {} and router ID {}", NwConstants.OUTBOUND_NAPT_TABLE, dpnId, routerId);
- mdsalManager.removeFlowToTx(outboundNaptFlowEntity, removeFlowInvTx);
+ mdsalManager.removeFlow(confTx, outboundNaptFlowEntity);
IpPortExternal ipPortExternal = ipPortMap.getIpPortExternal();
String externalIp = ipPortExternal.getIpAddress();
LOG.info("removeNaptFlowsFromActiveSwitch : Remove the flow in the {} for the active active switch "
+ "with the DPN ID {} and router ID {}", NwConstants.INBOUND_NAPT_TABLE, dpnId, routerId);
- mdsalManager.removeFlowToTx(inboundNaptFlowEntity, removeFlowInvTx);
+ mdsalManager.removeFlow(confTx, inboundNaptFlowEntity);
}
}
}
protected void removeNaptFibExternalOutputFlows(long routerId, BigInteger dpnId, Uuid networkId,
@Nonnull Collection<String> externalIps,
- WriteTransaction writeFlowInvTx) {
+ TypedReadWriteTransaction<Configuration> writeFlowInvTx) {
long extVpnId = NatConstants.INVALID_ID;
if (networkId != null) {
Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
+ " 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);
+ mdsalManager.removeFlow(writeFlowInvTx, natPfibVpnFlowEntity);
}
}
public void removeNaptFlowsFromActiveSwitchInternetVpn(long routerId, String routerName,
BigInteger dpnId, Uuid networkId, String vpnName,
- WriteTransaction writeFlowInvTx) {
+ TypedReadWriteTransaction<Configuration> writeFlowInvTx) {
LOG.debug("removeNaptFlowsFromActiveSwitchInternetVpn : Remove NAPT flows from Active switch Internet Vpn");
BigInteger cookieSnatFlow = NatUtil.getCookieNaptFlow(routerId);
NatUtil.buildFlowEntity(dpnId, NwConstants.NAPT_PFIB_TABLE, natPfibVpnFlowRef);
LOG.info("removeNaptFlowsFromActiveSwitchInternetVpn : Remove the flow in the {} for the active switch "
+ "with the DPN ID {} and VPN ID {}", NwConstants.NAPT_PFIB_TABLE, dpnId, vpnId);
- mdsalManager.removeFlowToTx(natPfibVpnFlowEntity, writeFlowInvTx);
+ mdsalManager.removeFlow(writeFlowInvTx, natPfibVpnFlowEntity);
// Remove IP-PORT active NAPT entries and release port from IdManager
// For the router ID get the internal IP , internal port and the corresponding
LOG.info("removeNaptFlowsFromActiveSwitchInternetVpn : Remove the flow in the {} for the "
+ "active switch with the DPN ID {} and router ID {}",
NwConstants.OUTBOUND_NAPT_TABLE, dpnId, routerId);
- mdsalManager.removeFlowToTx(outboundNaptFlowEntity, writeFlowInvTx);
+ mdsalManager.removeFlow(writeFlowInvTx, outboundNaptFlowEntity);
IpPortExternal ipPortExternal = ipPortMap.getIpPortExternal();
String externalIp = ipPortExternal.getIpAddress();
LOG.info("removeNaptFlowsFromActiveSwitchInternetVpn : Remove the flow in the {} for the "
+ "active active switch with the DPN ID {} and router ID {}",
NwConstants.INBOUND_NAPT_TABLE, dpnId, routerId);
- mdsalManager.removeFlowToTx(inboundNaptFlowEntity, writeFlowInvTx);
+ mdsalManager.removeFlow(writeFlowInvTx, inboundNaptFlowEntity);
// Finally release port from idmanager
String internalIpPort = internalIp + ":" + internalPort;
}
public void removeFlowsFromNonActiveSwitches(long routerId, String routerName,
- BigInteger naptSwitchDpnId, WriteTransaction removeFlowInvTx) {
+ BigInteger naptSwitchDpnId, TypedReadWriteTransaction<Configuration> removeFlowInvTx) {
LOG.debug("removeFlowsFromNonActiveSwitches : Remove NAPT related flows from non active switches");
// Remove the flows from the other switches which points to the primary and secondary switches
LOG.info("removeFlowsFromNonActiveSwitches : Remove the flow in the {} for the non active switch "
+ "with the DPN ID {} and router ID {}", NwConstants.PSNAT_TABLE, dpnId, routerId);
- mdsalManager.removeFlowToTx(preSnatFlowEntity, removeFlowInvTx);
+ mdsalManager.removeFlow(removeFlowInvTx, preSnatFlowEntity);
//Remove the group entry which forwards the traffic to the out port (VXLAN tunnel).
long groupId = createGroupId(getGroupIdKey(routerName));
LOG.info("removeFlowsFromNonActiveSwitches : Remove the group {} for the non active switch with "
+ "the DPN ID {} and router ID {}", groupId, dpnId, routerId);
- mdsalManager.removeGroup(preSnatGroupEntity);
+ mdsalManager.removeGroup(removeFlowInvTx, preSnatGroupEntity);
}
}
public void clrRtsFromBgpAndDelFibTs(final BigInteger dpnId, Long routerId, Uuid networkUuid,
@Nonnull Collection<String> externalIps, String vpnName,
- String extGwMacAddress, WriteTransaction removeFlowInvTx) {
+ String extGwMacAddress, TypedReadWriteTransaction<Configuration> confTx) {
//Withdraw the corresponding routes from the BGP.
//Get the network ID using the router ID.
LOG.debug("clrRtsFromBgpAndDelFibTs : Advertise to BGP and remove routes for externalIps {} with routerId {},"
//Remove custom FIB routes
//Future<RpcResult<java.lang.Void>> removeFibEntry(RemoveFibEntryInput input);
for (String extIp : externalIps) {
- clrRtsFromBgpAndDelFibTs(dpnId, routerId, extIp, vpnName, networkUuid, extGwMacAddress, removeFlowInvTx);
+ clrRtsFromBgpAndDelFibTs(dpnId, routerId, extIp, vpnName, networkUuid, extGwMacAddress, confTx);
}
}
protected void clrRtsFromBgpAndDelFibTs(final BigInteger dpnId, long routerId, String extIp, final String vpnName,
final Uuid networkUuid, String extGwMacAddress,
- WriteTransaction removeFlowInvTx) {
+ TypedReadWriteTransaction<Configuration> removeFlowInvTx) {
clearBgpRoutes(extIp, vpnName);
delFibTsAndReverseTraffic(dpnId, routerId, extIp, vpnName, networkUuid, extGwMacAddress, false,
removeFlowInvTx);
protected void delFibTsAndReverseTraffic(final BigInteger dpnId, long routerId, String extIp,
final String vpnName, Uuid extNetworkId, long tempLabel,
String gwMacAddress, boolean switchOver,
- WriteTransaction removeFlowInvTx) {
+ TypedReadWriteTransaction<Configuration> removeFlowInvTx) {
LOG.debug("delFibTsAndReverseTraffic : Removing fib entry for externalIp {} in routerId {}", extIp, routerId);
String routerName = NatUtil.getRouterName(dataBroker,routerId);
if (routerName == null) {
* external network provided type is VxLAN
*/
if (extNwProvType == ProviderTypes.VXLAN) {
- evpnSnatFlowProgrammer.evpnDelFibTsAndReverseTraffic(dpnId, routerId, extIp, vpnName, gwMacAddress,
- removeFlowInvTx);
+ evpnSnatFlowProgrammer.evpnDelFibTsAndReverseTraffic(dpnId, routerId, extIp, vpnName, gwMacAddress
+ );
return;
}
if (tempLabel < 0) {
removeLFibTableEntry(dpnId, label, removeFlowInvTx);
if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
//Remove the flow table 25->44 If there is no FIP Match on table 25 (PDNAT_TABLE)
- NatUtil.removePreDnatToSnatTableEntry(mdsalManager, dpnId, removeFlowInvTx);
+ NatUtil.removePreDnatToSnatTableEntry(removeFlowInvTx, mdsalManager, dpnId);
}
if (!switchOver) {
ListenableFuture<RpcResult<RemoveVpnLabelOutput>> labelFuture =
- Futures.transformAsync(future, result -> {
- //Release label
- if (result.isSuccessful()) {
- NatUtil.removePreDnatToSnatTableEntry(mdsalManager, dpnId, removeFlowInvTx);
- RemoveVpnLabelInput labelInput = new RemoveVpnLabelInputBuilder()
- .setVpnName(vpnName).setIpPrefix(externalIp).build();
- return vpnService.removeVpnLabel(labelInput);
- } else {
- String errMsg =
- String.format("RPC call to remove custom FIB entries on dpn %s for "
- + "prefix %s Failed - %s", dpnId, externalIp, result.getErrors());
- LOG.error(errMsg);
- return Futures.immediateFailedFuture(new RuntimeException(errMsg));
- }
- }, MoreExecutors.directExecutor());
+ Futures.transformAsync(future, result -> {
+ //Release label
+ if (result.isSuccessful()) {
+ NatUtil.removePreDnatToSnatTableEntry(removeFlowInvTx, mdsalManager, dpnId);
+ RemoveVpnLabelInput labelInput = new RemoveVpnLabelInputBuilder()
+ .setVpnName(vpnName).setIpPrefix(externalIp).build();
+ return vpnService.removeVpnLabel(labelInput);
+ } else {
+ String errMsg =
+ String.format("RPC call to remove custom FIB entries on dpn %s for "
+ + "prefix %s Failed - %s", dpnId, externalIp, result.getErrors());
+ LOG.error(errMsg);
+ return Futures.immediateFailedFuture(new RuntimeException(errMsg));
+ }
+ }, MoreExecutors.directExecutor());
Futures.addCallback(labelFuture, new FutureCallback<RpcResult<RemoveVpnLabelOutput>>() {
private void delFibTsAndReverseTraffic(final BigInteger dpnId, long routerId, String extIp, final String vpnName,
final Uuid networkUuid, String extGwMacAddress, boolean switchOver,
- WriteTransaction removeFlowInvTx) {
+ TypedReadWriteTransaction<Configuration> removeFlowInvTx) {
LOG.debug("delFibTsAndReverseTraffic : Removing fib entry for externalIp {} in routerId {}", extIp, routerId);
String routerName = NatUtil.getRouterName(dataBroker,routerId);
if (routerName == null) {
* external network provided type is VxLAN
*/
if (extNwProvType == ProviderTypes.VXLAN) {
- evpnSnatFlowProgrammer.evpnDelFibTsAndReverseTraffic(dpnId, routerId, extIp, vpnName, extGwMacAddress,
- removeFlowInvTx);
+ evpnSnatFlowProgrammer.evpnDelFibTsAndReverseTraffic(dpnId, routerId, extIp, vpnName, extGwMacAddress);
return;
}
//Get IPMaps from the DB for the router ID
removeLFibTableEntry(dpnId, label, removeFlowInvTx);
if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
//Remove the flow table 25->44 If there is no FIP Match on table 25 (PDNAT_TABLE)
- NatUtil.removePreDnatToSnatTableEntry(mdsalManager, dpnId, removeFlowInvTx);
+ NatUtil.removePreDnatToSnatTableEntry(removeFlowInvTx, mdsalManager, dpnId);
}
if (!switchOver) {
ListenableFuture<RpcResult<RemoveVpnLabelOutput>> labelFuture =
protected void clearFibTsAndReverseTraffic(final BigInteger dpnId, Long routerId, Uuid networkUuid,
List<String> externalIps, String vpnName, String extGwMacAddress,
- WriteTransaction writeFlowInvTx) {
+ TypedReadWriteTransaction<Configuration> writeFlowInvTx) {
//Withdraw the corresponding routes from the BGP.
//Get the network ID using the router ID.
LOG.debug("clearFibTsAndReverseTraffic : for externalIps {} with routerId {},"
NatUtil.removePrefixFromBGP(bgpManager, fibManager, rd, externalIp, vpnName, LOG);
}
- private void removeTunnelTableEntry(BigInteger dpnId, long serviceId, WriteTransaction writeFlowInvTx) {
+ private void removeTunnelTableEntry(BigInteger dpnId, long serviceId,
+ TypedReadWriteTransaction<Configuration> writeFlowInvTx) {
LOG.info("removeTunnelTableEntry : called with DpnId = {} and label = {}", dpnId, serviceId);
List<MatchInfo> mkMatches = new ArrayList<>();
// Matching metadata
getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, serviceId, ""),
5, String.format("%s:%d", "TST Flow Entry ", serviceId), 0, 0,
COOKIE_TUNNEL.add(BigInteger.valueOf(serviceId)), mkMatches, null);
- mdsalManager.removeFlowToTx(dpnId, flowEntity, writeFlowInvTx);
+ mdsalManager.removeFlow(writeFlowInvTx, dpnId, flowEntity);
LOG.debug("removeTunnelTableEntry : dpID {} : label : {} removed successfully", dpnId, serviceId);
}
- private void removeLFibTableEntry(BigInteger dpnId, long serviceId, WriteTransaction writeFlowInvTx) {
+ private void removeLFibTableEntry(BigInteger dpnId, long serviceId,
+ TypedReadWriteTransaction<Configuration> writeFlowInvTx) {
List<MatchInfo> matches = new ArrayList<>();
matches.add(MatchEthernetType.MPLS_UNICAST);
matches.add(new MatchMplsLabel(serviceId));
10, flowRef, 0, 0,
COOKIE_VM_LFIB_TABLE, matches, null);
- mdsalManager.removeFlowToTx(dpnId, flowEntity, writeFlowInvTx);
+ mdsalManager.removeFlow(writeFlowInvTx, dpnId, flowEntity);
LOG.debug("removeLFibTableEntry : dpID : {} label : {} removed successfully", dpnId, serviceId);
}
* @param bgpVpnName BGP VPN name
*/
public void changeLocalVpnIdToBgpVpnId(String routerName, long routerId, String bgpVpnName,
- WriteTransaction writeFlowInvTx, ProviderTypes extNwProvType) {
+ TypedWriteTransaction<Configuration> writeFlowInvTx, ProviderTypes extNwProvType) {
LOG.debug("changeLocalVpnIdToBgpVpnId : Router associated to BGP VPN");
if (chkExtRtrAndSnatEnbl(new Uuid(routerName))) {
long bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnName);
LOG.debug("changeLocalVpnIdToBgpVpnId : Update the Router ID {} to the BGP VPN ID {} ",
routerId, bgpVpnId);
- addOrDelDefaultFibRouteForSnatWithBgpVpn(routerName, routerId, bgpVpnId, true, writeFlowInvTx);
+ addDefaultFibRouteForSnatWithBgpVpn(routerName, routerId, bgpVpnId, writeFlowInvTx);
// Get the group ID
BigInteger primarySwitchId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
* @param bgpVpnName BGP VPN name
*/
public void changeBgpVpnIdToLocalVpnId(String routerName, long routerId, String bgpVpnName,
- WriteTransaction writeFlowInvTx, ProviderTypes extNwProvType) {
+ TypedWriteTransaction<Configuration> writeFlowInvTx, ProviderTypes extNwProvType) {
LOG.debug("changeBgpVpnIdToLocalVpnId : Router dissociated from BGP VPN");
if (chkExtRtrAndSnatEnbl(new Uuid(routerName))) {
long bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnName);
LOG.debug("changeBgpVpnIdToLocalVpnId : Router ID value {} ", routerId);
LOG.debug("changeBgpVpnIdToLocalVpnId : Update the BGP VPN ID {} to the Router ID {}", bgpVpnId, routerId);
- addOrDelDefaultFibRouteForSnatWithBgpVpn(routerName, routerId, NatConstants.INVALID_ID,
- true, writeFlowInvTx);
+ addDefaultFibRouteForSnatWithBgpVpn(routerName, routerId, NatConstants.INVALID_ID, writeFlowInvTx);
// Get the group ID
createGroupId(getGroupIdKey(routerName));
}
public void installFlowsWithUpdatedVpnId(BigInteger primarySwitchId, String routerName, long bgpVpnId,
- long routerId, boolean isSnatCfgd, WriteTransaction writeFlowInvTx,
- ProviderTypes extNwProvType) {
+ long routerId, boolean isSnatCfgd, TypedWriteTransaction<Configuration> confTx, ProviderTypes extNwProvType) {
+
long changedVpnId = bgpVpnId;
String idType = "BGP VPN";
if (bgpVpnId == NatConstants.INVALID_ID) {
"installFlowsWithUpdatedVpnId : Update the {} ID {} in the SNAT miss entry pointing to group "
+ "{} in the non NAPT switch {}", idType, changedVpnId, groupId, dpnId);
FlowEntity flowEntity = buildSnatFlowEntityWithUpdatedVpnId(dpnId, routerName, groupId, changedVpnId);
- mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
+ mdsalManager.addFlow(confTx, flowEntity);
} else {
LOG.debug(
"installFlowsWithUpdatedVpnId : Update the {} ID {} in the SNAT miss entry pointing to group "
+ "in the primary switch {}", idType, changedVpnId, primarySwitchId);
FlowEntity flowEntity =
buildSnatFlowEntityWithUpdatedVpnIdForPrimrySwtch(primarySwitchId, routerName, changedVpnId);
- mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
+ mdsalManager.addFlow(confTx, flowEntity);
LOG.debug(
"installFlowsWithUpdatedVpnId : Update the {} ID {} in the Terminating Service table (table "
+ "ID 36) which forwards the packet to the table 46 in the Primary switch {}",
idType, changedVpnId, primarySwitchId);
installTerminatingServiceTblEntryWithUpdatedVpnId(primarySwitchId, routerName, routerId,
- changedVpnId, writeFlowInvTx, extNwProvType);
+ changedVpnId, confTx, extNwProvType);
LOG.debug(
"installFlowsWithUpdatedVpnId : Update the {} ID {} in the Outbound NAPT table (table ID 46) "
+ "which punts the packet to the controller in the Primary switch {}",
idType, changedVpnId, primarySwitchId);
- createOutboundTblEntryWithBgpVpn(primarySwitchId, routerId, changedVpnId, writeFlowInvTx);
+ createOutboundTblEntryWithBgpVpn(primarySwitchId, routerId, changedVpnId, confTx);
LOG.debug(
"installFlowsWithUpdatedVpnId : Update the {} ID {} in the NAPT PFIB TABLE which forwards the"
+ " outgoing packet to FIB Table in the Primary switch {}",
idType, changedVpnId, primarySwitchId);
- installNaptPfibEntryWithBgpVpn(primarySwitchId, routerId, changedVpnId, writeFlowInvTx);
+ installNaptPfibEntryWithBgpVpn(primarySwitchId, routerId, changedVpnId, confTx);
LOG.debug(
"installFlowsWithUpdatedVpnId : Update the {} ID {} in the NAPT flows for the Outbound NAPT "
Long vpnId = NatUtil.getNetworkVpnIdFromRouterId(dataBroker, routerId);
//Install the NAPT PFIB TABLE which forwards the outgoing packet to FIB Table matching on the VPN ID.
if (vpnId != NatConstants.INVALID_ID) {
- installNaptPfibEntry(primarySwitchId, vpnId, writeFlowInvTx);
+ installNaptPfibEntry(primarySwitchId, vpnId, confTx);
}
}
}
// TODO : Replace this with ITM Rpc once its available with full functionality
protected void installTerminatingServiceTblEntryWithUpdatedVpnId(BigInteger dpnId, String routerName,
- long routerId, long changedVpnId, WriteTransaction writeFlowInvTx, ProviderTypes extNwProvType) {
+ long routerId, long changedVpnId, TypedWriteTransaction<Configuration> confTx, ProviderTypes extNwProvType) {
+
LOG.debug("installTerminatingServiceTblEntryWithUpdatedVpnId : called for switch {}, "
+ "routerName {}, BGP VPN ID {}", dpnId, routerName, changedVpnId);
FlowEntity flowEntity = buildTsFlowEntityWithUpdatedVpnId(dpnId, routerName, routerId, changedVpnId,
extNwProvType);
- mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
+ mdsalManager.addFlow(confTx, flowEntity);
}
private FlowEntity buildTsFlowEntityWithUpdatedVpnId(BigInteger dpId, String routerName,
}
public void createOutboundTblEntryWithBgpVpn(BigInteger dpnId, long routerId, long changedVpnId,
- WriteTransaction writeFlowInvTx) {
+ TypedWriteTransaction<Configuration> writeFlowInvTx) {
LOG.debug("createOutboundTblEntryWithBgpVpn : called for dpId {} and routerId {}, BGP VPN ID {}",
dpnId, routerId, changedVpnId);
FlowEntity tcpFlowEntity = buildOutboundFlowEntityWithBgpVpn(dpnId, routerId, changedVpnId,
NwConstants.IP_PROT_TCP);
LOG.debug("createOutboundTblEntryWithBgpVpn : Installing tcp flow {}", tcpFlowEntity);
- mdsalManager.addFlowToTx(tcpFlowEntity, writeFlowInvTx);
+ mdsalManager.addFlow(writeFlowInvTx, tcpFlowEntity);
FlowEntity udpFlowEntity = buildOutboundFlowEntityWithBgpVpn(dpnId, routerId, changedVpnId,
NwConstants.IP_PROT_UDP);
LOG.debug("createOutboundTblEntryWithBgpVpn : Installing udp flow {}", udpFlowEntity);
- mdsalManager.addFlowToTx(udpFlowEntity, writeFlowInvTx);
+ mdsalManager.addFlow(writeFlowInvTx, udpFlowEntity);
FlowEntity icmpDropFlow = buildIcmpDropFlow(dpnId, routerId, changedVpnId);
LOG.debug("createOutboundTblEntry: Installing icmp drop flow {}", icmpDropFlow);
- mdsalManager.addFlowToTx(icmpDropFlow, writeFlowInvTx);
+ mdsalManager.addFlow(writeFlowInvTx, icmpDropFlow);
}
protected FlowEntity buildOutboundFlowEntityWithBgpVpn(BigInteger dpId, long routerId,
}
public void installNaptPfibEntryWithBgpVpn(BigInteger dpnId, long segmentId, long changedVpnId,
- WriteTransaction writeFlowInvTx) {
+ TypedWriteTransaction<Configuration> writeFlowInvTx) {
LOG.debug("installNaptPfibEntryWithBgpVpn : called for dpnId {} and segmentId {} ,BGP VPN ID {}",
dpnId, segmentId, changedVpnId);
FlowEntity naptPfibFlowEntity = buildNaptPfibFlowEntityWithUpdatedVpnId(dpnId, segmentId, changedVpnId);
- mdsalManager.addFlowToTx(naptPfibFlowEntity, writeFlowInvTx);
+ mdsalManager.addFlow(writeFlowInvTx, naptPfibFlowEntity);
}
public FlowEntity buildNaptPfibFlowEntityWithUpdatedVpnId(BigInteger dpId, long segmentId, long changedVpnId) {
}
protected void installNaptPfibEntriesForExternalSubnets(String routerName, BigInteger dpnId,
- WriteTransaction writeFlowInvTx) {
+ TypedWriteTransaction<Configuration> writeFlowInvTx) {
Collection<Uuid> externalSubnetIdsForRouter = NatUtil.getExternalSubnetIdsForRouter(dataBroker,
routerName);
for (Uuid externalSubnetId : externalSubnetIdsForRouter) {
import java.math.BigInteger;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.genius.infra.Datastore.Configuration;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap;
public interface FloatingIPHandler {
void onAddFloatingIp(BigInteger dpnId, String routerUuid, long routerId, Uuid networkId, String interfaceName,
- InternalToExternalPortMap mapping, WriteTransaction writeFlowInvTx);
+ InternalToExternalPortMap mapping, TypedReadWriteTransaction<Configuration> confTx);
void onRemoveFloatingIp(BigInteger dpnId, String routerUuid, long routerId, Uuid networkId,
- InternalToExternalPortMap mapping, long label, WriteTransaction removeFlowInvTx);
+ InternalToExternalPortMap mapping, long label,
+ TypedReadWriteTransaction<Configuration> confTx);
void cleanupFibEntries(BigInteger dpnId, String vpnName, String externalIp, long label,
- WriteTransaction removeFlowInvTx, ProviderTypes provType);
+ TypedReadWriteTransaction<Configuration> confTx, ProviderTypes provType);
}
*/
package org.opendaylight.netvirt.natservice.internal;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
import com.google.common.base.Optional;
import java.math.BigInteger;
import java.net.InetAddress;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
+import org.opendaylight.genius.infra.Datastore.Configuration;
import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
import org.opendaylight.genius.mdsalutil.ActionInfo;
import org.opendaylight.genius.mdsalutil.FlowEntity;
import org.opendaylight.genius.mdsalutil.InstructionInfo;
}
private void createDNATTblEntry(BigInteger dpnId, InternalToExternalPortMap mapping, long routerId,
- long associatedVpnId, WriteTransaction writeFlowInvTx) {
+ long associatedVpnId, TypedReadWriteTransaction<Configuration> confTx) {
FlowEntity preFlowEntity = buildPreDNATFlowEntity(dpnId, mapping, routerId, associatedVpnId);
if (preFlowEntity == null) {
LOG.error("createDNATTblEntry : Flow entity received as NULL. "
+ "Cannot proceed with installation of Pre-DNAT flow table {} --> table {} on DpnId {}",
NwConstants.PDNAT_TABLE, NwConstants.DNAT_TABLE, dpnId);
} else {
- mdsalManager.addFlowToTx(preFlowEntity, writeFlowInvTx);
+ mdsalManager.addFlow(confTx, preFlowEntity);
FlowEntity flowEntity = buildDNATFlowEntity(dpnId, mapping, routerId, associatedVpnId);
if (flowEntity != null) {
- mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
+ mdsalManager.addFlow(confTx, flowEntity);
}
}
}
private void removeDNATTblEntry(BigInteger dpnId, String internalIp, String externalIp, long routerId,
- WriteTransaction removeFlowInvTx) {
+ TypedReadWriteTransaction<Configuration> confTx) {
FlowEntity preFlowEntity = buildPreDNATDeleteFlowEntity(dpnId, externalIp, routerId);
- mdsalManager.removeFlowToTx(preFlowEntity, removeFlowInvTx);
+ mdsalManager.removeFlow(confTx, preFlowEntity);
FlowEntity flowEntity = buildDNATDeleteFlowEntity(dpnId, internalIp, routerId);
if (flowEntity != null) {
- mdsalManager.removeFlowToTx(flowEntity, removeFlowInvTx);
+ mdsalManager.removeFlow(confTx, flowEntity);
}
}
private void createSNATTblEntry(BigInteger dpnId, InternalToExternalPortMap mapping, long vpnId, long routerId,
- long associatedVpnId, Uuid externalNetworkId, WriteTransaction writeFlowInvTx) {
+ long associatedVpnId, Uuid externalNetworkId, TypedReadWriteTransaction<Configuration> confTx) {
FlowEntity preFlowEntity = buildPreSNATFlowEntity(dpnId, mapping.getInternalIp(), mapping.getExternalIp(),
vpnId, routerId, associatedVpnId);
- mdsalManager.addFlowToTx(preFlowEntity, writeFlowInvTx);
+ mdsalManager.addFlow(confTx, preFlowEntity);
FlowEntity flowEntity = buildSNATFlowEntity(dpnId, mapping, vpnId, externalNetworkId);
if (flowEntity != null) {
- mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
+ mdsalManager.addFlow(confTx, flowEntity);
}
}
private void removeSNATTblEntry(BigInteger dpnId, String internalIp, String externalIp, long routerId, long vpnId,
- WriteTransaction removeFlowInvTx) {
+ TypedReadWriteTransaction<Configuration> removeFlowInvTx) {
FlowEntity preFlowEntity = buildPreSNATDeleteFlowEntity(dpnId, internalIp, routerId);
- mdsalManager.removeFlowToTx(preFlowEntity, removeFlowInvTx);
+ mdsalManager.removeFlow(removeFlowInvTx, preFlowEntity);
FlowEntity flowEntity = buildSNATDeleteFlowEntity(dpnId, externalIp, vpnId);
if (flowEntity != null) {
- mdsalManager.removeFlowToTx(flowEntity, removeFlowInvTx);
+ mdsalManager.removeFlow(removeFlowInvTx, flowEntity);
}
}
InstanceIdentifier<RouterPorts> portIid = identifier.firstIdentifierOf(RouterPorts.class);
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + mapping.key(), () -> Collections.singletonList(
- txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+ txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
tx -> createNATFlowEntries(interfaceName, mapping, portIid, routerId, tx))),
NatConstants.NAT_DJC_MAX_RETRIES);
}
InstanceIdentifier<RouterPorts> portIid = identifier.firstIdentifierOf(RouterPorts.class);
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + mapping.key(), () -> Collections.singletonList(
- txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+ txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
tx -> removeNATFlowEntries(interfaceName, mapping, portIid, routerId, null, tx))),
NatConstants.NAT_DJC_MAX_RETRIES);
}
void createNATFlowEntries(String interfaceName, final InternalToExternalPortMap mapping,
final InstanceIdentifier<RouterPorts> portIid, final String routerName,
- WriteTransaction writeFlowInvTx) {
+ TypedReadWriteTransaction<Configuration> confTx) {
if (!validateIpMapping(mapping)) {
LOG.error("createNATFlowEntries : Not a valid ip addresses in the mapping {}", mapping);
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);
+ addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, confTx, 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);
+ createDNATTblEntry(dpnId, mapping, routerId, associatedVpnId, confTx);
+ createSNATTblEntry(dpnId, mapping, vpnId, routerId, associatedVpnId, extNwId, confTx);
+ floatingIPHandler.onAddFloatingIp(dpnId, routerName, routerId, extNwId, interfaceName, mapping, confTx);
}
void createNATFlowEntries(BigInteger dpnId, String interfaceName, String routerName, Uuid externalNetworkId,
- InternalToExternalPortMap mapping, WriteTransaction writeFlowInvTx) {
+ InternalToExternalPortMap mapping, TypedReadWriteTransaction<Configuration> confTx) {
String internalIp = mapping.getInternalIp();
long routerId = NatUtil.getVpnId(dataBroker, routerName);
if (routerId == NatConstants.INVALID_ID) {
//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);
+ addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, confTx, true);
}
//Create the DNAT and SNAT table entries
- createDNATTblEntry(dpnId, mapping, routerId, associatedVpnId, writeFlowInvTx);
- createSNATTblEntry(dpnId, mapping, vpnId, routerId, associatedVpnId, externalNetworkId, writeFlowInvTx);
+ createDNATTblEntry(dpnId, mapping, routerId, associatedVpnId, confTx);
+ createSNATTblEntry(dpnId, mapping, vpnId, routerId, associatedVpnId, externalNetworkId, confTx);
floatingIPHandler.onAddFloatingIp(dpnId, routerName, routerId, externalNetworkId, interfaceName, mapping,
- writeFlowInvTx);
+ confTx);
}
void createNATOnlyFlowEntries(BigInteger dpnId, String routerName, String associatedVPN,
void removeNATFlowEntries(String interfaceName, final InternalToExternalPortMap mapping,
InstanceIdentifier<RouterPorts> portIid, final String routerName, BigInteger dpnId,
- WriteTransaction removeFlowInvTx) {
+ TypedReadWriteTransaction<Configuration> removeFlowInvTx) {
String internalIp = mapping.getInternalIp();
String externalIp = mapping.getExternalIp();
//Get the DPN on which this interface resides
}
void removeNATFlowEntries(BigInteger dpnId, String interfaceName, String vpnName, String routerName,
- InternalToExternalPortMap mapping, WriteTransaction removeFlowInvTx) {
+ InternalToExternalPortMap mapping, TypedReadWriteTransaction<Configuration> confTx) {
String internalIp = mapping.getInternalIp();
String externalIp = mapping.getExternalIp();
long routerId = NatUtil.getVpnId(dataBroker, routerName);
}
//Delete the DNAT and SNAT table entries
- removeDNATTblEntry(dpnId, internalIp, externalIp, routerId, removeFlowInvTx);
- removeSNATTblEntry(dpnId, internalIp, externalIp, routerId, vpnId, removeFlowInvTx);
+ removeDNATTblEntry(dpnId, internalIp, externalIp, routerId, confTx);
+ removeSNATTblEntry(dpnId, internalIp, externalIp, routerId, vpnId, confTx);
//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);
+ addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, confTx, false);
}
Uuid externalNetworkId = NatUtil.getNetworkIdFromRouterName(dataBroker,routerName);
ProviderTypes provType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, externalNetworkId);
}
if (provType == ProviderTypes.VXLAN) {
floatingIPHandler.cleanupFibEntries(dpnId, vpnName, externalIp, NatConstants.DEFAULT_L3VNI_VALUE,
- removeFlowInvTx, provType);
+ confTx, provType);
removeOperationalDS(routerName, interfaceName, internalIp);
return;
}
internalIp, routerId);
return;
}
- floatingIPHandler.cleanupFibEntries(dpnId, vpnName, externalIp, label, removeFlowInvTx, provType);
+ floatingIPHandler.cleanupFibEntries(dpnId, vpnName, externalIp, label, confTx, provType);
removeOperationalDS(routerName, interfaceName, internalIp);
}
return flowEntity;
}
- private void addOrDelDefaultFibRouteForDnat(BigInteger dpnId, String routerName,
- long routerId, WriteTransaction tx, boolean create) {
- if (tx == null) {
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+ private void addOrDelDefaultFibRouteForDnat(BigInteger dpnId, String routerName, long routerId,
+ TypedReadWriteTransaction<Configuration> confTx, boolean create) {
+ if (confTx == null) {
+ ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
newTx -> addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, newTx, create)), LOG,
"Error handling default FIB route for DNAT");
return;
if (associatedVpnId != NatConstants.INVALID_ID) {
LOG.debug("addOrDelDefaultFibRouteForDnat: Install NAT default route on DPN {} for the router {} with "
+ "vpn-id {}", dpnId, routerName, associatedVpnId);
- defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, associatedVpnId, routerId, tx);
+ defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, associatedVpnId, routerId, confTx);
} else {
LOG.debug("addOrDelDefaultFibRouteForDnat: Install NAT default route on DPN {} for the router {} with "
+ "vpn-id {}", dpnId, routerName, routerId);
- defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, routerId, tx);
+ defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, routerId, confTx);
}
} else {
if (associatedVpnId != NatConstants.INVALID_ID) {
LOG.debug("addOrDelDefaultFibRouteForDnat: Remove NAT default route on DPN {} for the router {} "
+ "with vpn-id {}", dpnId, routerName, associatedVpnId);
- defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, associatedVpnId, routerId, tx);
+ defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, associatedVpnId, routerId, confTx);
} else {
LOG.debug("addOrDelDefaultFibRouteForDnat: Remove NAT default route on DPN {} for the router {} "
+ "with vpn-id {}", dpnId, routerName, routerId);
- defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, routerId, tx);
+ defaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, routerId, confTx);
}
}
}
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
import org.opendaylight.genius.infra.Datastore.Configuration;
-import org.opendaylight.genius.infra.TransactionAdapter;
import org.opendaylight.genius.infra.TypedReadWriteTransaction;
import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
import org.opendaylight.genius.mdsalutil.ActionInfo;
protected void removeSnatFlowsInOldNaptSwitch(String routerName, Long routerId, BigInteger naptSwitch,
Map<String, Long> externalIpmap,
TypedReadWriteTransaction<Configuration> confTx) {
- WriteTransaction removeFlowInvTx = TransactionAdapter.toWriteTransaction(confTx);
//remove SNAT flows in old NAPT SWITCH
Uuid networkId = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
return;
}
if (extNwProvType == ProviderTypes.VXLAN) {
- evpnNaptSwitchHA.evpnRemoveSnatFlowsInOldNaptSwitch(routerName, routerId, vpnName, naptSwitch,
- removeFlowInvTx);
+ evpnNaptSwitchHA.evpnRemoveSnatFlowsInOldNaptSwitch(routerName, routerId, vpnName, naptSwitch, confTx);
} else {
//Remove the Terminating Service table entry which forwards the packet to Outbound NAPT Table
long tunnelId = NatUtil.getTunnelIdForNonNaptToNaptFlow(dataBroker, elanManager, idManager, routerId,
}
if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
//Remove the flow table 25->44 If there is no FIP Match on table 25 (PDNAT_TABLE)
- NatUtil.removePreDnatToSnatTableEntry(mdsalManager, naptSwitch, removeFlowInvTx);
+ NatUtil.removePreDnatToSnatTableEntry(confTx, mdsalManager, naptSwitch);
}
//Remove the Outbound flow entry which forwards the packet to Outbound NAPT Table
LOG.info("Remove the flow in table {} for the old napt switch with the DPN ID {} and router ID {}",
String externalIp = entry.getKey();
Long label = entry.getValue();
externalRouterListener.delFibTsAndReverseTraffic(naptSwitch, routerId, externalIp, vpnName,
- extNetworkId, label, gwMacAddress, true, removeFlowInvTx);
+ extNetworkId, label, gwMacAddress, true, confTx);
LOG.debug("removeSnatFlowsInOldNaptSwitch : Successfully removed fib entries in old naptswitch {} "
+ "for router {} and externalIps {} label {}", naptSwitch, routerId, externalIp, label);
}
List<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerName);
if (networkId != null) {
externalRouterListener.clearFibTsAndReverseTraffic(naptSwitch, routerId, networkId,
- externalIps, null, gwMacAddress, removeFlowInvTx);
+ externalIps, null, gwMacAddress, confTx);
LOG.debug("removeSnatFlowsInOldNaptSwitch : Successfully removed fib entries in old naptswitch {} for "
+ "router {} with networkId {} and externalIps {}", naptSwitch, routerId, networkId,
externalIps);
LOG.debug("removeSnatFlowsInOldNaptSwitch : External network not associated to router {}", routerId);
}
externalRouterListener.removeNaptFibExternalOutputFlows(routerId, naptSwitch, extNetworkId,
- externalIps, removeFlowInvTx);
+ externalIps, confTx);
}
//For the router ID get the internal IP , internal port and the corresponding external IP and external Port.
protected void installSnatFlows(String routerName, Long routerId, BigInteger naptSwitch, Long routerVpnId,
TypedReadWriteTransaction<Configuration> confTx) {
- WriteTransaction writeFlowInvTx = TransactionAdapter.toWriteTransaction(confTx);
if (routerId.equals(routerVpnId)) {
LOG.debug("installSnatFlows : Installing flows for router with internalvpnId");
//36 -> 46 ..Install flow forwarding packet to table46 from table36
LOG.debug("installSnatFlows : installTerminatingServiceTblEntry in naptswitch with dpnId {} for "
+ "routerName {} with routerId {}", naptSwitch, routerName, routerId);
- externalRouterListener.installTerminatingServiceTblEntry(naptSwitch, routerName, routerId, writeFlowInvTx);
+ externalRouterListener.installTerminatingServiceTblEntry(naptSwitch, routerName, routerId, confTx);
//Install default flows punting to controller in table 46(OutBoundNapt table)
LOG.debug("installSnatFlows : installOutboundMissEntry in naptswitch with dpnId {} for "
+ "routerName {} with routerId {}", naptSwitch, routerName, routerId);
- externalRouterListener.createOutboundTblEntry(naptSwitch, routerId, writeFlowInvTx);
+ externalRouterListener.createOutboundTblEntry(naptSwitch, routerId, confTx);
//Table 47 point to table 21 for inbound traffic
LOG.debug("installSnatFlows : installNaptPfibEntry in naptswitch with dpnId {} for router {}",
naptSwitch, routerId);
- externalRouterListener.installNaptPfibEntry(naptSwitch, routerId, writeFlowInvTx);
+ externalRouterListener.installNaptPfibEntry(naptSwitch, routerId, confTx);
//Table 47 point to group
LOG.debug("installSnatFlows : installNaptPfibExternalOutputFlow in naptswitch with dpnId {} for router {}",
naptSwitch, routerId);
- externalRouterListener.installNaptPfibExternalOutputFlow(routerName, routerId, naptSwitch, writeFlowInvTx);
+ externalRouterListener.installNaptPfibExternalOutputFlow(routerName, routerId, naptSwitch, confTx);
} else {
Uuid extNetworkUuid = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
if (extNetworkUuid == null) {
+ "routerName {} with BgpVpnId {}", naptSwitch, routerName, routerVpnId);
externalRouterListener
.installTerminatingServiceTblEntryWithUpdatedVpnId(naptSwitch, routerName, routerId,
- routerVpnId, writeFlowInvTx, extNwProvType);
+ routerVpnId, confTx, extNwProvType);
//Install default flows punting to controller in table 46(OutBoundNapt table)
LOG.debug("installSnatFlows : installOutboundMissEntry in naptswitch with dpnId {} for "
+ "routerName {} with BgpVpnId {}", naptSwitch, routerName, routerVpnId);
- externalRouterListener.createOutboundTblEntryWithBgpVpn(naptSwitch, routerId, routerVpnId, writeFlowInvTx);
+ externalRouterListener.createOutboundTblEntryWithBgpVpn(naptSwitch, routerId, routerVpnId, confTx);
//Table 47 point to table 21 for inbound traffic
LOG.debug("installSnatFlows : installNaptPfibEntry in naptswitch with dpnId {} for router {} "
+ "with BgpVpnId {}", naptSwitch, routerId, routerVpnId);
- externalRouterListener.installNaptPfibEntryWithBgpVpn(naptSwitch, routerId, routerVpnId, writeFlowInvTx);
+ externalRouterListener.installNaptPfibEntryWithBgpVpn(naptSwitch, routerId, routerVpnId, confTx);
}
Uuid networkId = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
shouldInstallNaptPfibWithExtNetworkVpnId = false;
LOG.debug("installSnatFlows : installNaptPfibEntry fin naptswitch with dpnId {} for "
+ "BgpVpnId {}", naptSwitch, externalSubnetVpnId);
- externalRouterListener.installNaptPfibEntry(naptSwitch, externalSubnetVpnId, writeFlowInvTx);
+ externalRouterListener.installNaptPfibEntry(naptSwitch, externalSubnetVpnId, confTx);
}
}
}
//NAPT PFIB table point to FIB table for outbound traffic - using external networkID as vpnID.
LOG.debug("installSnatFlows : installNaptPfibEntry fin naptswitch with dpnId {} for "
+ "BgpVpnId {}", naptSwitch, vpnId);
- externalRouterListener.installNaptPfibEntry(naptSwitch, vpnId, writeFlowInvTx);
+ externalRouterListener.installNaptPfibEntry(naptSwitch, vpnId, confTx);
} else if (vpnId != NatConstants.INVALID_ID) {
LOG.debug("installSnatFlows : Associated BgpvpnId not found for router {}", routerId);
}
LOG.debug("installSnatFlows : advToBgpAndInstallFibAndTsFlows in naptswitch id {} "
+ "with vpnName {} and externalIp {}", naptSwitch, vpnName, externalIp);
externalRouterListener.advToBgpAndInstallFibAndTsFlows(naptSwitch, NwConstants.INBOUND_NAPT_TABLE,
- vpnName, routerId, routerName, externalIp, networkId, null /* external-router */,
- writeFlowInvTx);
+ vpnName, routerId, routerName, externalIp, networkId, null /* external-router */, confTx);
LOG.debug("installSnatFlows : Successfully added fib entries in naptswitch {} for "
+ "router {} with external IP {}", naptSwitch, routerId, externalIp);
}
for (String externalIp : removedExternalIps) {
externalRouterListener.clearBgpRoutes(externalIp, vpnName);
externalRouterListener.delFibTsAndReverseTraffic(naptSwitch, routerId, externalIp, vpnName,
- networkId, NatConstants.DEFAULT_LABEL_VALUE, gwMacAddress, true,
- TransactionAdapter.toWriteTransaction(confTx));
+ networkId, NatConstants.DEFAULT_LABEL_VALUE, gwMacAddress, true, confTx);
LOG.debug("bestEffortDeletion : Successfully removed fib entry for externalIp {} for routerId {} "
+ "on NAPT switch {} ", externalIp, routerId, naptSwitch);
}
}
externalRouterListener.clearBgpRoutes(externalIp, vpnName);
externalRouterListener.delFibTsAndReverseTraffic(naptSwitch, routerId, externalIp, vpnName,
- networkId, label, gwMacAddress, true, TransactionAdapter.toWriteTransaction(confTx));
+ networkId, label, gwMacAddress, true, confTx);
LOG.debug("bestEffortDeletion : Successfully removed fib entries in switch {} for router {} "
+ "and externalIps {}", naptSwitch, routerId, externalIp);
}
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
+import org.opendaylight.genius.infra.Datastore.Configuration;
+import org.opendaylight.genius.infra.TransactionAdapter;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
import org.opendaylight.genius.interfacemanager.globals.IfmConstants;
import org.opendaylight.genius.mdsalutil.MDSALUtil;
import org.opendaylight.genius.mdsalutil.MatchInfo;
long l3Vni,
String interfaceName,
String gwMacAddress,
- WriteTransaction writeTx,
+ TypedWriteTransaction<Configuration> writeTx,
RouteOrigin origin, BigInteger dpId) {
try {
LOG.info("addRoutesForVxLanProvType : Adding Fib entry rd {} prefix {} nextHop {} l3Vni {}",
fibManager.addOrUpdateFibEntry(rd, null /*macAddress*/, prefix,
Collections.singletonList(nextHopIp), VrfEntry.EncapType.Vxlan, NatConstants.DEFAULT_LABEL_VALUE,
- l3Vni, gwMacAddress, null /* parent-vpn-rd */, origin, writeTx);
+ l3Vni, gwMacAddress, null /* parent-vpn-rd */, origin, TransactionAdapter.toWriteTransaction(writeTx));
/* Publish to Bgp only if its an INTERNET VPN */
if (rd != null && !rd.equalsIgnoreCase(vpnName)) {
bgpManager.advertisePrefix(rd, null /*macAddress*/, prefix, Collections.singletonList(nextHopIp),
}
static void makeL3GwMacTableEntry(final BigInteger dpnId, final long vpnId, String macAddress,
- List<Instruction> customInstructions, IMdsalApiManager mdsalManager,
- WriteTransaction writeFlowTx) {
+ List<Instruction> customInstructions, IMdsalApiManager mdsalManager,
+ TypedWriteTransaction<Configuration> confTx) {
+
List<MatchInfo> matchInfo = new ArrayList<>();
matchInfo.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
matchInfo.add(new MatchEthernetDestination(new MacAddress(macAddress)));
Flow l3GwMacTableFlowEntity = MDSALUtil.buildFlowNew(NwConstants.L3_GW_MAC_TABLE,
flowRef, 21, flowRef, 0, 0, NwConstants.COOKIE_L3_GW_MAC_TABLE, matchInfo, customInstructions);
- mdsalManager.addFlowToTx(dpnId, l3GwMacTableFlowEntity, writeFlowTx);
+ mdsalManager.addFlow(confTx, dpnId, l3GwMacTableFlowEntity);
LOG.debug("makeL3GwMacTableEntry : Successfully created flow entity {} on DPN = {}",
l3GwMacTableFlowEntity, dpnId);
}
static void removeL3GwMacTableEntry(final BigInteger dpnId, final long vpnId, final String macAddress,
- IMdsalApiManager mdsalManager, WriteTransaction removeFlowInvTx) {
+ IMdsalApiManager mdsalManager, TypedReadWriteTransaction<Configuration> confTx) {
List<MatchInfo> matchInfo = new ArrayList<>();
matchInfo.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
matchInfo.add(new MatchEthernetSource(new MacAddress(macAddress)));
Flow l3GwMacTableFlowEntity = MDSALUtil.buildFlowNew(NwConstants.L3_GW_MAC_TABLE,
flowRef, 21, flowRef, 0, 0, NwConstants.COOKIE_L3_GW_MAC_TABLE, matchInfo, null);
- mdsalManager.removeFlowToTx(dpnId, l3GwMacTableFlowEntity, removeFlowInvTx);
+ mdsalManager.removeFlow(confTx, dpnId, l3GwMacTableFlowEntity);
LOG.debug("removeL3GwMacTableEntry : Successfully removed flow entity {} on DPN = {}",
l3GwMacTableFlowEntity, dpnId);
}
*/
package org.opendaylight.netvirt.natservice.internal;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
+
import com.google.common.base.Optional;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
+import org.opendaylight.genius.infra.Datastore.Operational;
import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
import org.opendaylight.genius.mdsalutil.FlowEntity;
import org.opendaylight.genius.mdsalutil.NwConstants;
import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
}
void handleRouterInterfacesUpEvent(String routerName, String interfaceName, BigInteger dpId,
- WriteTransaction writeOperTxn) {
+ TypedReadWriteTransaction<Operational> operTx) throws ExecutionException, InterruptedException {
LOG.debug("handleRouterInterfacesUpEvent : Handling UP event for router interface {} in Router {} on Dpn {}",
interfaceName, routerName, dpId);
- NatUtil.addToNeutronRouterDpnsMap(dataBroker, routerName, interfaceName, dpId, writeOperTxn);
- NatUtil.addToDpnRoutersMap(dataBroker, routerName, interfaceName, dpId, writeOperTxn);
+ NatUtil.addToNeutronRouterDpnsMap(routerName, interfaceName, dpId, operTx);
+ NatUtil.addToDpnRoutersMap(routerName, interfaceName, dpId, operTx);
}
void handleRouterInterfacesDownEvent(String routerName, String interfaceName, BigInteger dpnId,
- WriteTransaction writeOperTxn) {
+ TypedReadWriteTransaction<Operational> operTx)
+ throws ExecutionException, InterruptedException {
LOG.debug("handleRouterInterfacesDownEvent : Handling DOWN event for router Interface {} in Router {}",
interfaceName, routerName);
- NatUtil.removeFromNeutronRouterDpnsMap(dataBroker, routerName, interfaceName, dpnId, writeOperTxn);
+ NatUtil.removeFromNeutronRouterDpnsMap(routerName, dpnId, operTx);
NatUtil.removeFromDpnRoutersMap(dataBroker, routerName, interfaceName, dpnId, odlInterfaceRpcService,
- writeOperTxn);
+ operTx);
}
private IntfTransitionState getTransitionState(Interface.OperStatus original , Interface.OperStatus updated) {
List<ListenableFuture<Void>> futures = new ArrayList<>();
try {
LOG.trace("call : Received interface {} PORT UP OR ADD event ", interfaceName);
- futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx ->
+ futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, tx ->
handleRouterInterfacesUpEvent(routerName, interfaceName, intfDpnId, tx)));
} catch (Exception e) {
LOG.error("call : Exception caught in Interface {} Operational State Up event",
List<ListenableFuture<Void>> futures = new ArrayList<>();
try {
LOG.trace("call : Received interface {} PORT DOWN or REMOVE event", interfaceName);
- futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx ->
+ futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, tx ->
handleRouterInterfacesDownEvent(routerName, interfaceName, intfDpnId, tx)));
} catch (Exception e) {
LOG.error("call : Exception observed in handling deletion of VPN Interface {}.", interfaceName, e);
interfaceName, original.getOperStatus(), update.getOperStatus());
return futures;
}
- futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+ futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, tx -> {
if (state.equals(IntfTransitionState.STATE_DOWN)) {
LOG.debug("call : DPN {} connnected to the interface {} has gone down."
+ "Hence clearing the dpn-vpninterfaces-list entry from the"
+ " neutron-router-dpns model in the ODL:L3VPN", intfDpnId, interfaceName);
// If the interface state is unknown, it means that the corresponding DPN has gone down.
// So remove the dpn-vpninterfaces-list from the neutron-router-dpns model.
- NatUtil.removeFromNeutronRouterDpnsMap(dataBroker, routerName, intfDpnId, tx);
+ NatUtil.removeFromNeutronRouterDpnsMap(routerName, intfDpnId, tx);
} else if (state.equals(IntfTransitionState.STATE_UP)) {
LOG.debug("call : DPN {} connnected to the interface {} has come up. Hence adding"
+ " the dpn-vpninterfaces-list entry from the neutron-router-dpns model"
return;
}
InstanceIdentifier<RouterPorts> portIid = NatUtil.buildRouterPortsIdentifier(routerId);
- ListenableFuture<Void> future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+ ListenableFuture<Void> future = txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
for (InternalToExternalPortMap intExtPortMap : intExtPortMapList) {
floatingIPListener.createNATFlowEntries(portName, intExtPortMap, portIid, routerId, tx);
}
return;
}
InstanceIdentifier<RouterPorts> portIid = NatUtil.buildRouterPortsIdentifier(routerId);
- ListenableFuture<Void> future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+ ListenableFuture<Void> future = txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
for (InternalToExternalPortMap intExtPortMap : intExtPortMapList) {
LOG.trace("processInterfaceRemoved : Removing DNAT Flow entries for dpnId {} ", dpnId);
floatingIPListener.removeNATFlowEntries(portName, intExtPortMap, portIid, routerId, dpnId, tx);
*/
package org.opendaylight.netvirt.natservice.internal;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
+
import java.math.BigInteger;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
interfaceName, routerId);
return;
}
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(operTx -> {
- NatUtil.addToNeutronRouterDpnsMap(dataBroker, routerId, interfaceName, dpId, operTx);
- NatUtil.addToDpnRoutersMap(dataBroker, routerId, interfaceName, dpId, operTx);
+ ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, operTx -> {
+ NatUtil.addToNeutronRouterDpnsMap(routerId, interfaceName, dpId, operTx);
+ NatUtil.addToDpnRoutersMap(routerId, interfaceName, dpId, operTx);
}), LOG, "Error processing NAT router interface addition");
} else {
LOG.info("add : Interface {} not yet operational to handle router interface add event in router {}",
final String interfaceName = interfaceInfo.getInterfaceId();
//Delete the RouterInterfaces maintained in the ODL:L3VPN configuration model
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(confTx -> {
- confTx.delete(LogicalDatastoreType.CONFIGURATION, NatUtil.getRouterInterfaceId(interfaceName));
- }), LOG, "Error handling NAT router interface removal");
+ ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+ confTx -> confTx.delete(NatUtil.getRouterInterfaceId(interfaceName))), LOG,
+ "Error handling NAT router interface removal");
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(operTx -> {
+ ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, operTx -> {
//Delete the NeutronRouterDpnMap from the ODL:L3VPN operational model
- NatUtil.removeFromNeutronRouterDpnsMap(dataBroker, routerId, interfaceName, interfaceManager, operTx);
+ NatUtil.removeFromNeutronRouterDpnsMap(routerId, interfaceName, interfaceManager, operTx);
//Delete the DpnRouterMap from the ODL:L3VPN operational model
NatUtil.removeFromDpnRoutersMap(dataBroker, routerId, interfaceName, interfaceManager, operTx);
import org.opendaylight.genius.infra.Datastore.Configuration;
import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
-import org.opendaylight.genius.infra.TransactionAdapter;
import org.opendaylight.genius.infra.TypedReadWriteTransaction;
import org.opendaylight.genius.infra.TypedWriteTransaction;
import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
//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,
- TransactionAdapter.toWriteTransaction(confTx));
+ defaultRouteProgrammer.installDefNATRouteInDPN(srcDpnId, vpnId, confTx);
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);
//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,
- TransactionAdapter.toWriteTransaction(confTx));
+ defaultRouteProgrammer.installDefNATRouteInDPN(srcDpnId, vpnId, routerId, confTx);
LOG.debug("hndlTepAddOnNonNaptSwitch : Install group in non NAPT switch {} for router {}",
srcDpnId, routerName);
LOG.debug("hndlTepAddOnNaptSwitch : SNAT -> Advertise the route to the externalIp {} "
+ "having nextHopIp {}", externalIp, nextHopIp);
NatEvpnUtil.addRoutesForVxLanProvType(dataBroker, bgpManager, fibManager, externalVpnName, rd,
- externalIp, nextHopIp, l3Vni, tunnelName, gwMacAddress,
- TransactionAdapter.toWriteTransaction(confTx), RouteOrigin.STATIC, srcDpnId);
+ externalIp, nextHopIp, l3Vni, tunnelName, gwMacAddress, confTx, RouteOrigin.STATIC, srcDpnId);
serviceId = l3Vni;
} else {
LOG.debug("hndlTepAddForDnatInEachRtr : DNAT -> Advertise the route to the externalIp {} "
+ "having nextHopIp {}", externalIp, nextHopIp);
NatEvpnUtil.addRoutesForVxLanProvType(dataBroker, bgpManager, fibManager, vpnName, rd,
- externalIp, nextHopIp, l3Vni, interfaceName, gwMacAddress,
- TransactionAdapter.toWriteTransaction(confTx), RouteOrigin.STATIC, fipCfgdDpnId);
+ externalIp, nextHopIp, l3Vni, interfaceName, gwMacAddress, confTx, RouteOrigin.STATIC,
+ fipCfgdDpnId);
serviceId = l3Vni;
} else {
long label = floatingIPListener.getOperationalIpMapping(routerName, interfaceName, internalIp);
//Install default entry in FIB to SNAT table
LOG.debug("hndlTepDelForSnatInEachRtr : Installing default route in FIB on DPN {} for router {} with"
+ " vpn {}...", dpnId, routerName, bgpVpnId);
- defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, bgpVpnId,
- TransactionAdapter.toWriteTransaction(confTx));
+ defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, bgpVpnId, confTx);
} else {
bgpVpnId = NatUtil.getVpnId(dataBroker, bgpVpnUuid.getValue());
if (bgpVpnId == NatConstants.INVALID_ID) {
//Install default entry in FIB to SNAT table
LOG.debug("hndlTepDelForSnatInEachRtr : Installing default route in FIB on dpn {} for routerId {} "
+ "with vpnId {}...", dpnId, routerId, bgpVpnId);
- defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, bgpVpnId, routerId,
- TransactionAdapter.toWriteTransaction(confTx));
+ defaultRouteProgrammer.installDefNATRouteInDPN(dpnId, bgpVpnId, routerId, confTx);
}
if (routerData.get().isEnableSnat()) {
package org.opendaylight.netvirt.natservice.internal;
+import static org.opendaylight.controller.md.sal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
+
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.CheckedFuture;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.math.BigInteger;
import java.net.InetAddress;
import javax.annotation.Nullable;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
import org.opendaylight.genius.infra.Datastore.Configuration;
+import org.opendaylight.genius.infra.Datastore.Operational;
import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
import org.opendaylight.genius.infra.TypedReadTransaction;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
import org.opendaylight.genius.mdsalutil.ActionInfo;
import org.opendaylight.genius.mdsalutil.FlowEntity;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.NxRegLoad;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
.RouterInterfaceKey(interfaceName)).build();
}
- public static void addToNeutronRouterDpnsMap(DataBroker broker, String routerName, String interfaceName,
- BigInteger dpId , WriteTransaction writeOperTxn) {
+ public static void addToNeutronRouterDpnsMap(String routerName, String interfaceName, BigInteger dpId,
+ TypedReadWriteTransaction<Operational> operTx) throws ExecutionException, InterruptedException {
if (dpId.equals(BigInteger.ZERO)) {
LOG.warn("addToNeutronRouterDpnsMap : Could not retrieve dp id for interface {} "
+ "ODL-L3VPN : NeutronRouterDpn map", routerName, dpId, interfaceName);
InstanceIdentifier<DpnVpninterfacesList> dpnVpnInterfacesListIdentifier = getRouterDpnId(routerName, dpId);
- Optional<DpnVpninterfacesList> optionalDpnVpninterfacesList =
- SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
- LogicalDatastoreType.OPERATIONAL, dpnVpnInterfacesListIdentifier);
+ Optional<DpnVpninterfacesList> optionalDpnVpninterfacesList = operTx.read(dpnVpnInterfacesListIdentifier).get();
org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns
.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces routerInterface =
new RouterInterfacesBuilder().withKey(new RouterInterfacesKey(interfaceName))
if (optionalDpnVpninterfacesList.isPresent()) {
LOG.debug("addToNeutronRouterDpnsMap : RouterDpnList already present for the Router {} and DPN {} for the "
+ "Interface {} in the ODL-L3VPN : NeutronRouterDpn map", routerName, dpId, interfaceName);
- writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL, dpnVpnInterfacesListIdentifier
+ operTx.merge(dpnVpnInterfacesListIdentifier
.child(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router
.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces.class,
- new RouterInterfacesKey(interfaceName)), routerInterface, true);
+ new RouterInterfacesKey(interfaceName)), routerInterface, CREATE_MISSING_PARENTS);
} else {
LOG.debug("addToNeutronRouterDpnsMap : Building new RouterDpnList for the Router {} and DPN {} for the "
+ "Interface {} in the ODL-L3VPN : NeutronRouterDpn map", routerName, dpId, interfaceName);
routerInterfaces.add(routerInterface);
dpnVpnList.setRouterInterfaces(routerInterfaces);
routerDpnListBuilder.setDpnVpninterfacesList(Collections.singletonList(dpnVpnList.build()));
- writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL,
- getRouterId(routerName),
- routerDpnListBuilder.build(), true);
+ operTx.merge(getRouterId(routerName), routerDpnListBuilder.build(), CREATE_MISSING_PARENTS);
}
}
- public static void addToDpnRoutersMap(DataBroker broker, String routerName, String interfaceName,
- BigInteger dpId, WriteTransaction writeOperTxn) {
+ public static void addToDpnRoutersMap(String routerName, String interfaceName, BigInteger dpId,
+ TypedReadWriteTransaction<Operational> operTx) throws ExecutionException, InterruptedException {
if (dpId.equals(BigInteger.ZERO)) {
LOG.error("addToDpnRoutersMap : Could not retrieve dp id for interface {} to handle router {} "
+ "association model", interfaceName, routerName);
+ "DPNRouters map", dpId, routerName, interfaceName);
InstanceIdentifier<DpnRoutersList> dpnRoutersListIdentifier = getDpnRoutersId(dpId);
- Optional<DpnRoutersList> optionalDpnRoutersList =
- SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
- LogicalDatastoreType.OPERATIONAL, dpnRoutersListIdentifier);
+ Optional<DpnRoutersList> optionalDpnRoutersList = operTx.read(dpnRoutersListIdentifier).get();
if (optionalDpnRoutersList.isPresent()) {
RoutersList routersList = new RoutersListBuilder().withKey(new RoutersListKey(routerName))
if (!routersListFromDs.contains(routersList)) {
LOG.debug("addToDpnRoutersMap : Router {} not present for the DPN {}"
+ " in the ODL-L3VPN : DPNRouters map", routerName, dpId);
- writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL,
- dpnRoutersListIdentifier
- .child(RoutersList.class, new RoutersListKey(routerName)), routersList, true);
+ operTx.merge(dpnRoutersListIdentifier
+ .child(RoutersList.class, new RoutersListKey(routerName)), routersList, CREATE_MISSING_PARENTS);
} else {
LOG.debug("addToDpnRoutersMap : Router {} already mapped to the DPN {} in the ODL-L3VPN : "
+ "DPNRouters map", routerName, dpId);
RoutersListBuilder routersListBuilder = new RoutersListBuilder();
routersListBuilder.setRouter(routerName);
dpnRoutersListBuilder.setRoutersList(Collections.singletonList(routersListBuilder.build()));
- writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL,
- getDpnRoutersId(dpId),
- dpnRoutersListBuilder.build(), true);
+ operTx.merge(getDpnRoutersId(dpId), dpnRoutersListBuilder.build(), CREATE_MISSING_PARENTS);
}
}
-
- public static void removeFromNeutronRouterDpnsMap(DataBroker broker, String routerName, String interfaceName,
- BigInteger dpId, WriteTransaction writeOperTxn) {
- if (dpId.equals(BigInteger.ZERO)) {
- LOG.error("removeFromNeutronRouterDpnsMap : Could not retrieve dp id for interface {} to handle router {} "
- + "dissociation model", interfaceName, routerName);
- return;
- }
- InstanceIdentifier<DpnVpninterfacesList> routerDpnListIdentifier = getRouterDpnId(routerName, dpId);
- Optional<DpnVpninterfacesList> optionalRouterDpnList =
- SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
- LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier);
- if (optionalRouterDpnList.isPresent()) {
- List<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router
- .dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces> routerInterfaces =
- optionalRouterDpnList.get().getRouterInterfaces();
- org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router
- .dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces routerInterface =
- new RouterInterfacesBuilder().withKey(new RouterInterfacesKey(interfaceName))
- .setInterface(interfaceName).build();
- if (routerInterfaces != null && routerInterfaces.remove(routerInterface)) {
- if (routerInterfaces.isEmpty()) {
- writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier);
- } else {
- writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier.child(
- org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router
- .dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces.class,
- new RouterInterfacesKey(interfaceName)));
- }
- }
- }
- }
-
- public static void removeFromNeutronRouterDpnsMap(DataBroker broker, String routerName,
- BigInteger dpId, WriteTransaction writeOperTxn) {
+ public static void removeFromNeutronRouterDpnsMap(String routerName, BigInteger dpId,
+ TypedReadWriteTransaction<Operational> operTx) throws ExecutionException, InterruptedException {
if (dpId.equals(BigInteger.ZERO)) {
LOG.warn("removeFromNeutronRouterDpnsMap : DPN ID is invalid for the router {} ", routerName);
return;
}
InstanceIdentifier<DpnVpninterfacesList> routerDpnListIdentifier = getRouterDpnId(routerName, dpId);
- Optional<DpnVpninterfacesList> optionalRouterDpnList =
- SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
- LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier);
+ Optional<DpnVpninterfacesList> optionalRouterDpnList = operTx.read(routerDpnListIdentifier).get();
if (optionalRouterDpnList.isPresent()) {
LOG.debug("removeFromNeutronRouterDpnsMap : Removing the dpn-vpninterfaces-list from the "
+ "odl-l3vpn:neutron-router-dpns model for the router {}", routerName);
- writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier);
+ operTx.delete(routerDpnListIdentifier);
} else {
LOG.debug("removeFromNeutronRouterDpnsMap : dpn-vpninterfaces-list does not exist in the "
+ "odl-l3vpn:neutron-router-dpns model for the router {}", routerName);
}
}
- public static void removeFromNeutronRouterDpnsMap(DataBroker broker, String routerName, String vpnInterfaceName,
- OdlInterfaceRpcService ifaceMgrRpcService,
- WriteTransaction writeOperTxn) {
+ public static void removeFromNeutronRouterDpnsMap(String routerName, String vpnInterfaceName,
+ OdlInterfaceRpcService ifaceMgrRpcService, @Nonnull TypedReadWriteTransaction<Operational> operTx) {
BigInteger dpId = getDpnForInterface(ifaceMgrRpcService, vpnInterfaceName);
if (dpId.equals(BigInteger.ZERO)) {
LOG.debug("removeFromNeutronRouterDpnsMap : Could not retrieve dp id for interface {} to handle router {}"
return;
}
InstanceIdentifier<DpnVpninterfacesList> routerDpnListIdentifier = getRouterDpnId(routerName, dpId);
- Optional<DpnVpninterfacesList> optionalRouterDpnList =
- SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
- LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier);
+ Optional<DpnVpninterfacesList> optionalRouterDpnList;
+ try {
+ optionalRouterDpnList = operTx.read(routerDpnListIdentifier).get();
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Error reading the router DPN list for {}", routerDpnListIdentifier, e);
+ optionalRouterDpnList = Optional.absent();
+ }
if (optionalRouterDpnList.isPresent()) {
List<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns
.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces> routerInterfaces =
if (routerInterfaces != null && routerInterfaces.remove(routerInterface)) {
if (routerInterfaces.isEmpty()) {
- if (writeOperTxn != null) {
- writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier);
- } else {
- MDSALUtil.syncDelete(broker, LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier);
- }
+ operTx.delete(routerDpnListIdentifier);
} else {
- if (writeOperTxn != null) {
- writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier.child(
- org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router
- .dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces.class,
- new RouterInterfacesKey(vpnInterfaceName)));
- } else {
- MDSALUtil.syncDelete(broker, LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier.child(
- org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron
- .router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces.class,
- new RouterInterfacesKey(vpnInterfaceName)));
- }
+ operTx.delete(routerDpnListIdentifier.child(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router
+ .dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces.class,
+ new RouterInterfacesKey(vpnInterfaceName)));
}
}
}
}
public static void removeFromDpnRoutersMap(DataBroker broker, String routerName, String vpnInterfaceName,
- OdlInterfaceRpcService ifaceMgrRpcService, WriteTransaction writeOperTxn) {
+ OdlInterfaceRpcService ifaceMgrRpcService, TypedReadWriteTransaction<Operational> operTx)
+ throws ExecutionException, InterruptedException {
BigInteger dpId = getDpnForInterface(ifaceMgrRpcService, vpnInterfaceName);
if (dpId.equals(BigInteger.ZERO)) {
LOG.debug("removeFromDpnRoutersMap : removeFromDpnRoutersMap() : "
vpnInterfaceName, routerName);
return;
}
- removeFromDpnRoutersMap(broker, routerName, vpnInterfaceName, dpId, ifaceMgrRpcService, writeOperTxn);
+ removeFromDpnRoutersMap(broker, routerName, vpnInterfaceName, dpId, ifaceMgrRpcService, operTx);
}
static void removeFromDpnRoutersMap(DataBroker broker, String routerName, String vpnInterfaceName,
- BigInteger curDpnId,
- OdlInterfaceRpcService ifaceMgrRpcService, WriteTransaction writeOperTxn) {
+ BigInteger curDpnId, OdlInterfaceRpcService ifaceMgrRpcService, TypedReadWriteTransaction<Operational> operTx)
+ throws ExecutionException, InterruptedException {
/*
1) Get the DpnRoutersList for the DPN.
2) Get the RoutersList identifier for the DPN and router.
//Get the dpn-routers-list instance for the current DPN.
InstanceIdentifier<DpnRoutersList> dpnRoutersListIdentifier = getDpnRoutersId(curDpnId);
- Optional<DpnRoutersList> dpnRoutersListData =
- SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
- LogicalDatastoreType.OPERATIONAL, dpnRoutersListIdentifier);
+ Optional<DpnRoutersList> dpnRoutersListData = operTx.read(dpnRoutersListIdentifier).get();
if (dpnRoutersListData == null || !dpnRoutersListData.isPresent()) {
LOG.error("removeFromDpnRoutersMap : dpn-routers-list is not present for DPN {} "
//Get the routers-list instance for the router on the current DPN only
InstanceIdentifier<RoutersList> routersListIdentifier = getRoutersList(curDpnId, routerName);
- Optional<RoutersList> routersListData =
- SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
- LogicalDatastoreType.OPERATIONAL, routersListIdentifier);
+ Optional<RoutersList> routersListData = operTx.read(routersListIdentifier).get();
if (routersListData == null || !routersListData.isPresent()) {
LOG.error("removeFromDpnRoutersMap : routers-list is not present for the DPN {} "
LOG.debug("removeFromDpnRoutersMap : Unable to get the routers list for the DPN {}. Possibly all subnets "
+ "removed from router {} OR Router {} has been deleted. Hence DPN router model WILL be cleared ",
curDpnId, routerName, routerName);
- writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routersListIdentifier);
+ operTx.delete(routersListIdentifier);
return;
}
LOG.debug("removeFromDpnRoutersMap : Router {} is present in the DPN {} only through the interface {} "
+ "Hence DPN router model WILL be cleared. Possibly last VM for the router "
+ "deleted in the DPN", routerName, curDpnId, vpnInterfaceName);
- writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routersListIdentifier);
+ operTx.delete(routersListIdentifier);
}
private static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn
FloatingIpIdToPortMapping::getFloatingIpPortMacAddress).orElse(null);
}
+ protected static String getFloatingIpPortMacFromFloatingIpId(TypedReadTransaction<Configuration> confTx,
+ Uuid floatingIpId) {
+ try {
+ return confTx.read(buildfloatingIpIdToPortMappingIdentifier(floatingIpId)).get().toJavaUtil().map(
+ FloatingIpIdToPortMapping::getFloatingIpPortMacAddress).orElse(null);
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Error reading the floating IP port MAC for {}", floatingIpId, e);
+ return null;
+ }
+ }
+
protected static Uuid getFloatingIpPortSubnetIdFromFloatingIpId(DataBroker broker, Uuid floatingIpId) {
InstanceIdentifier<FloatingIpIdToPortMapping> id = buildfloatingIpIdToPortMappingIdentifier(floatingIpId);
return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
FloatingIpIdToPortMapping::getFloatingIpPortSubnetId).orElse(null);
}
+ @Nullable
+ protected static Uuid getFloatingIpPortSubnetIdFromFloatingIpId(TypedReadTransaction<Configuration> confTx,
+ Uuid floatingIpId) {
+ try {
+ return confTx.read(buildfloatingIpIdToPortMappingIdentifier(floatingIpId)).get().toJavaUtil().map(
+ FloatingIpIdToPortMapping::getFloatingIpPortSubnetId).orElse(null);
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Error reading the floating IP port subnet for {}", floatingIpId, e);
+ return null;
+ }
+ }
+
static InstanceIdentifier<FloatingIpIdToPortMapping> buildfloatingIpIdToPortMappingIdentifier(Uuid floatingIpId) {
return InstanceIdentifier.builder(FloatingIpPortInfo.class).child(FloatingIpIdToPortMapping.class, new
FloatingIpIdToPortMappingKey(floatingIpId)).build();
}
public static void makePreDnatToSnatTableEntry(IMdsalApiManager mdsalManager, BigInteger naptDpnId,
- short tableId, WriteTransaction writeFlowTx) {
+ short tableId, TypedWriteTransaction<Configuration> confTx) {
LOG.debug("makePreDnatToSnatTableEntry : Create Pre-DNAT table {} --> table {} flow on NAPT DpnId {} ",
NwConstants.PDNAT_TABLE, tableId, naptDpnId);
5, flowRef, 0, 0, NwConstants.COOKIE_DNAT_TABLE,
matches, preDnatToSnatInstructions);
- mdsalManager.addFlowToTx(naptDpnId, preDnatToSnatTableFlowEntity, writeFlowTx);
+ mdsalManager.addFlow(confTx, naptDpnId, preDnatToSnatTableFlowEntity);
LOG.debug("makePreDnatToSnatTableEntry : Successfully installed Pre-DNAT flow {} on NAPT DpnId {} ",
preDnatToSnatTableFlowEntity, naptDpnId);
}
- public static void removePreDnatToSnatTableEntry(IMdsalApiManager mdsalManager, BigInteger naptDpnId,
- WriteTransaction removeFlowInvTx) {
+ public static void removePreDnatToSnatTableEntry(TypedReadWriteTransaction<Configuration> confTx,
+ IMdsalApiManager mdsalManager, BigInteger naptDpnId) {
LOG.debug("removePreDnatToSnatTableEntry : Remove Pre-DNAT table {} --> table {} flow on NAPT DpnId {} ",
NwConstants.PDNAT_TABLE, NwConstants.INBOUND_NAPT_TABLE, naptDpnId);
String flowRef = getFlowRefPreDnatToSnat(naptDpnId, NwConstants.PDNAT_TABLE, "PreDNATToSNAT");
Flow preDnatToSnatTableFlowEntity = MDSALUtil.buildFlowNew(NwConstants.PDNAT_TABLE,flowRef,
5, flowRef, 0, 0, NwConstants.COOKIE_DNAT_TABLE, null, null);
- mdsalManager.removeFlowToTx(naptDpnId, preDnatToSnatTableFlowEntity, removeFlowInvTx);
+ mdsalManager.removeFlow(confTx, naptDpnId, preDnatToSnatTableFlowEntity);
LOG.debug("removePreDnatToSnatTableEntry: Successfully removed Pre-DNAT flow {} on NAPT DpnId = {}",
preDnatToSnatTableFlowEntity, naptDpnId);
}
}
@Nullable
- public static String getPrimaryRd(String vpnName, ReadTransaction tx) throws ReadFailedException {
- return tx.read(LogicalDatastoreType.CONFIGURATION,
- getVpnInstanceIdentifier(vpnName)).checkedGet().toJavaUtil().map(NatUtil::getPrimaryRd).orElse(null);
+ public static String getPrimaryRd(String vpnName, TypedReadTransaction<Configuration> tx)
+ throws ExecutionException, InterruptedException {
+ return tx.read(getVpnInstanceIdentifier(vpnName)).get().toJavaUtil().map(NatUtil::getPrimaryRd).orElse(null);
}
public static String getPrimaryRd(DataBroker dataBroker, String vpnName) {
}), LOG, "Error installing router gateway flows");
}
- public static CheckedFuture<Void, TransactionCommitFailedException> waitForTransactionToComplete(
- WriteTransaction tx) {
- CheckedFuture<Void, TransactionCommitFailedException> futures = tx.submit();
- try {
- futures.get();
- } catch (InterruptedException | ExecutionException e) {
- LOG.error("Error writing to datastore {}", e);
- }
- return futures;
- }
-
public static Boolean isOpenStackVniSemanticsEnforcedForGreAndVxlan(IElanService elanManager,
ProviderTypes extNwProvType) {
if (elanManager.isOpenStackVniSemanticsEnforced() && (extNwProvType == ProviderTypes.GRE
import org.opendaylight.genius.infra.Datastore.Configuration;
import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
-import org.opendaylight.genius.infra.TransactionAdapter;
import org.opendaylight.genius.infra.TypedReadWriteTransaction;
import org.opendaylight.genius.mdsalutil.BucketInfo;
import org.opendaylight.genius.mdsalutil.FlowEntity;
LOG.info(
"add : Installing default route in FIB on dpn {} for router {} with vpn {}",
dpnId, routerUuid, vpnId);
- snatDefaultRouteProgrammer.installDefNATRouteInDPN(dpnId, vpnId,
- TransactionAdapter.toWriteTransaction(confTx));
+ snatDefaultRouteProgrammer.installDefNATRouteInDPN(dpnId, vpnId, confTx);
} else {
LOG.debug("add : External BGP vpn associated to router {}", routerUuid);
vpnId = NatUtil.getVpnId(dataBroker, vpnName.getValue());
//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);
- snatDefaultRouteProgrammer.installDefNATRouteInDPN(dpnId, vpnId, routerId,
- TransactionAdapter.toWriteTransaction(confTx));
+ snatDefaultRouteProgrammer.installDefNATRouteInDPN(dpnId, vpnId, routerId, confTx);
}
if (router.isEnableSnat()) {
LOG.info("add : SNAT enabled for router {}", routerUuid);
//Remove default entry in FIB
LOG.debug("remove : Removing default route in FIB on dpn {} for vpn {} ...", dpnId,
vpnName);
- snatDefaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, vpnId,
- TransactionAdapter.toWriteTransaction(confTx));
+ snatDefaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, vpnId, confTx);
} else {
LOG.debug("remove : External vpn associated to router {}", routerUuid);
vpnId = NatUtil.getVpnId(dataBroker, vpnName.getValue());
//Remove default entry in FIB
LOG.debug("remove : Removing default route in FIB on dpn {} for vpn {} ...", dpnId,
vpnName);
- snatDefaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, vpnId, routerId,
- TransactionAdapter.toWriteTransaction(confTx));
+ snatDefaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, vpnId, routerId, confTx);
}
if (router.isEnableSnat()) {
*/
package org.opendaylight.netvirt.natservice.internal;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
import com.google.common.base.Optional;
import java.math.BigInteger;
import java.util.List;
}
long routerId = NatUtil.getVpnId(dataBroker, routerName);
try {
- txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+ txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
tx -> externalRoutersListener.changeLocalVpnIdToBgpVpnId(routerName, routerId, vpnName, tx,
extNwProvType)).get();
} catch (InterruptedException | ExecutionException e) {
}
long routerId = NatUtil.getVpnId(dataBroker, routerName);
try {
- txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+ txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
tx -> externalRoutersListener.changeBgpVpnIdToLocalVpnId(routerName, routerId, vpnName, tx,
extNwProvType)).get();
} catch (InterruptedException | ExecutionException e) {
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
+import org.opendaylight.genius.infra.Datastore.Configuration;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
import org.opendaylight.genius.mdsalutil.FlowEntity;
import org.opendaylight.genius.mdsalutil.InstructionInfo;
import org.opendaylight.genius.mdsalutil.MDSALUtil;
}
- void installDefNATRouteInDPN(BigInteger dpnId, long vpnId, WriteTransaction writeFlowInvTx) {
+ void installDefNATRouteInDPN(BigInteger dpnId, long vpnId, TypedWriteTransaction<Configuration> confTx) {
FlowEntity flowEntity = buildDefNATFlowEntity(dpnId, vpnId);
if (flowEntity == null) {
LOG.error("installDefNATRouteInDPN : Flow entity received is NULL."
return;
}
natServiceCounters.installDefaultNatFlow();
- mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
+ mdsalManager.addFlow(confTx, flowEntity);
}
- void installDefNATRouteInDPN(BigInteger dpnId, long bgpVpnId, long routerId, WriteTransaction writeFlowInvTx) {
+ void installDefNATRouteInDPN(BigInteger dpnId, long bgpVpnId, long routerId,
+ TypedWriteTransaction<Configuration> confTx) {
FlowEntity flowEntity = buildDefNATFlowEntity(dpnId, bgpVpnId, routerId);
if (flowEntity == null) {
LOG.error("installDefNATRouteInDPN : Flow entity received is NULL."
return;
}
natServiceCounters.installDefaultNatFlow();
- mdsalManager.addFlowToTx(flowEntity, writeFlowInvTx);
+ mdsalManager.addFlow(confTx, flowEntity);
}
void installDefNATRouteInDPN(BigInteger dpnId, long vpnId, String subnetId) {
mdsalManager.installFlow(flowEntity);
}
- void removeDefNATRouteInDPN(BigInteger dpnId, long vpnId, WriteTransaction writeFlowInvTx) {
+ void removeDefNATRouteInDPN(BigInteger dpnId, long vpnId, TypedReadWriteTransaction<Configuration> confTx) {
FlowEntity flowEntity = buildDefNATFlowEntity(dpnId, vpnId);
if (flowEntity == null) {
LOG.error("removeDefNATRouteInDPN : Flow entity received is NULL."
return;
}
natServiceCounters.removeDefaultNatFlow();
- mdsalManager.removeFlowToTx(flowEntity, writeFlowInvTx);
+ mdsalManager.removeFlow(confTx, flowEntity);
}
- void removeDefNATRouteInDPN(BigInteger dpnId, long bgpVpnId, long routerId, WriteTransaction writeFlowInvTx) {
+ void removeDefNATRouteInDPN(BigInteger dpnId, long bgpVpnId, long routerId,
+ TypedReadWriteTransaction<Configuration> confTx) {
FlowEntity flowEntity = buildDefNATFlowEntity(dpnId, bgpVpnId, routerId);
if (flowEntity == null) {
LOG.error("removeDefNATRouteInDPN : Flow entity received is NULL."
return;
}
natServiceCounters.removeDefaultNatFlow();
- mdsalManager.removeFlowToTx(flowEntity, writeFlowInvTx);
+ mdsalManager.removeFlow(confTx, flowEntity);
}
void addOrDelDefaultFibRouteToSNATForSubnet(Subnets subnet, String networkId, int flowAction, long vpnId) {
*/
package org.opendaylight.netvirt.natservice.internal;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
import static org.opendaylight.netvirt.natservice.internal.NatUtil.buildfloatingIpIdToPortMappingIdentifier;
import com.google.common.base.Optional;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
+import org.opendaylight.genius.infra.Datastore.Configuration;
import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
import org.opendaylight.genius.mdsalutil.ActionInfo;
import org.opendaylight.genius.mdsalutil.MDSALUtil;
import org.opendaylight.genius.mdsalutil.MatchInfo;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.OdlArputilService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.SendArpRequestInput;
@Override
public void onAddFloatingIp(final BigInteger dpnId, final String routerUuid, final long routerId,
final Uuid networkId, final String interfaceName,
- final InternalToExternalPortMap mapping, WriteTransaction writeFlowInvTx) {
+ final InternalToExternalPortMap mapping,
+ TypedReadWriteTransaction<Configuration> confTx) {
String externalIp = mapping.getExternalIp();
String internalIp = mapping.getInternalIp();
Uuid floatingIpId = mapping.getExternalId();
Uuid floatingIpInterface = NatEvpnUtil.getFloatingIpInterfaceIdFromFloatingIpId(dataBroker, floatingIpId);
evpnDnatFlowProgrammer.onAddFloatingIp(dpnId, routerUuid, routerId, vpnName, internalIp,
externalIp, networkId, interfaceName, floatingIpInterface.getValue(), floatingIpPortMacAddress,
- rd, nextHopIp, writeFlowInvTx);
+ rd, nextHopIp, confTx);
return;
}
/*
List<ActionInfo> actionsInfos = new ArrayList<>();
actionsInfos.add(new ActionNxResubmit(NwConstants.PDNAT_TABLE));
instructions.add(new InstructionApplyActions(actionsInfos).buildInstruction(0));
- makeTunnelTableEntry(vpnName, dpnId, label, instructions, writeFlowInvTx, provType);
- //Install custom FIB routes
List<ActionInfo> actionInfoFib = new ArrayList<>();
List<Instruction> customInstructions = new ArrayList<>();
actionInfoFib.add(new ActionSetFieldEthernetDestination(new MacAddress(floatingIpPortMacAddress)));
customInstructions.add(new InstructionApplyActions(actionInfoFib).buildInstruction(0));
customInstructions.add(new InstructionGotoTable(NwConstants.PDNAT_TABLE).buildInstruction(1));
- makeLFibTableEntry(dpnId, label, floatingIpPortMacAddress, NwConstants.PDNAT_TABLE, writeFlowInvTx);
+ ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
+ innerConfTx -> {
+ makeTunnelTableEntry(vpnName, dpnId, label, instructions, innerConfTx, provType);
+ makeLFibTableEntry(dpnId, label, floatingIpPortMacAddress, NwConstants.PDNAT_TABLE,
+ innerConfTx);
+ }), LOG, "Error adding tunnel or FIB table entries");
+
CreateFibEntryInput input = new CreateFibEntryInputBuilder().setVpnName(vpnName)
.setSourceDpid(dpnId).setInstruction(customInstructions)
.setIpAddress(fibExternalIp).setServiceId(label)
@Override
public void onRemoveFloatingIp(final BigInteger dpnId, String routerUuid, long routerId, final Uuid networkId,
InternalToExternalPortMap mapping, final long label,
- WriteTransaction removeFlowInvTx) {
+ TypedReadWriteTransaction<Configuration> confTx) {
String externalIp = mapping.getExternalIp();
Uuid floatingIpId = mapping.getExternalId();
- Uuid subnetId = NatUtil.getFloatingIpPortSubnetIdFromFloatingIpId(dataBroker, floatingIpId);
- Optional<Subnets> externalSubnet = NatUtil.getOptionalExternalSubnets(dataBroker, subnetId);
+ Uuid subnetId = NatUtil.getFloatingIpPortSubnetIdFromFloatingIpId(confTx, floatingIpId);
+ Optional<Subnets> externalSubnet = NatUtil.getOptionalExternalSubnets(confTx, subnetId);
final String vpnName = externalSubnet.isPresent() ? subnetId.getValue() :
NatUtil.getAssociatedVPN(dataBroker, networkId);
if (vpnName == null) {
//Remove floating mac from mymac table
LOG.debug("onRemoveFloatingIp: Removing FloatingIp {}", externalIp);
- String floatingIpPortMacAddress = NatUtil.getFloatingIpPortMacFromFloatingIpId(dataBroker, floatingIpId);
+ String floatingIpPortMacAddress = NatUtil.getFloatingIpPortMacFromFloatingIpId(confTx, floatingIpId);
if (floatingIpPortMacAddress == null) {
LOG.error("onRemoveFloatingIp: Unable to retrieve floatingIp port MAC address from floatingIpId {} for "
+ "router {} to remove floatingIp {}", floatingIpId, routerUuid, externalIp);
if (provType == ProviderTypes.VXLAN) {
Uuid floatingIpInterface = NatEvpnUtil.getFloatingIpInterfaceIdFromFloatingIpId(dataBroker, floatingIpId);
evpnDnatFlowProgrammer.onRemoveFloatingIp(dpnId, vpnName, externalIp, floatingIpInterface.getValue(),
- floatingIpPortMacAddress, routerId, removeFlowInvTx);
+ floatingIpPortMacAddress, routerId, confTx);
return;
}
- cleanupFibEntries(dpnId, vpnName, externalIp, label, removeFlowInvTx, provType);
+ cleanupFibEntries(dpnId, vpnName, externalIp, label, confTx, provType);
}
@Override
- public void cleanupFibEntries(final BigInteger dpnId, final String vpnName, final String externalIp,
- final long label, WriteTransaction removeFlowInvTx, ProviderTypes provType) {
+ public void cleanupFibEntries(BigInteger dpnId, String vpnName, String externalIp,
+ long label, TypedReadWriteTransaction<Configuration> confTx, ProviderTypes provType) {
//Remove Prefix from BGP
- String rd = NatUtil.getVpnRd(dataBroker, vpnName);
+ String rd = NatUtil.getVpnRd(confTx, vpnName);
String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
NatUtil.removePrefixFromBGP(bgpManager, fibManager, rd, fibExternalIp, vpnName, LOG);
}
}
if (removeTunnelFlow) {
- removeTunnelTableEntry(dpnId, label, removeFlowInvTx);
+ removeTunnelTableEntry(dpnId, label, confTx);
}
- removeLFibTableEntry(dpnId, label, removeFlowInvTx);
+ removeLFibTableEntry(dpnId, label, confTx);
RemoveVpnLabelInput labelInput = new RemoveVpnLabelInputBuilder()
.setVpnName(vpnName).setIpPrefix(externalIp).build();
return vpnService.removeVpnLabel(labelInput);
+ NwConstants.FLOWID_SEPARATOR + ipAddress;
}
- private void removeTunnelTableEntry(BigInteger dpnId, long serviceId, WriteTransaction removeFlowInvTx) {
+ private void removeTunnelTableEntry(BigInteger dpnId, long serviceId,
+ TypedReadWriteTransaction<Configuration> confTx) {
+
LOG.debug("removeTunnelTableEntry : called with DpnId = {} and label = {}", dpnId, serviceId);
- List<MatchInfo> mkMatches = new ArrayList<>();
- // Matching metadata
- mkMatches.add(new MatchTunnelId(BigInteger.valueOf(serviceId)));
- Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.INTERNAL_TUNNEL_TABLE,
- getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, serviceId, ""),
- 5, String.format("%s:%d", "TST Flow Entry ", serviceId), 0, 0,
- COOKIE_TUNNEL.add(BigInteger.valueOf(serviceId)), mkMatches, null);
- mdsalManager.removeFlowToTx(dpnId, flowEntity, removeFlowInvTx);
+ mdsalManager.removeFlow(confTx, dpnId,
+ new FlowKey(new FlowId(getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, serviceId, ""))),
+ NwConstants.INTERNAL_TUNNEL_TABLE);
LOG.debug("removeTunnelTableEntry : Terminating service Entry for dpID {} : label : {} removed successfully",
dpnId, serviceId);
}
private void makeTunnelTableEntry(String vpnName, BigInteger dpnId, long serviceId,
- List<Instruction> customInstructions, WriteTransaction writeFlowInvTx, ProviderTypes provType) {
+ List<Instruction> customInstructions, TypedWriteTransaction<Configuration> confTx, ProviderTypes provType) {
List<MatchInfo> mkMatches = new ArrayList<>();
LOG.info("makeTunnelTableEntry on DpnId = {} and serviceId = {}", dpnId, serviceId);
String.format("%s:%d", "TST Flow Entry ", serviceId),
0, 0, COOKIE_TUNNEL.add(BigInteger.valueOf(serviceId)), mkMatches, customInstructions);
- mdsalManager.addFlowToTx(dpnId, terminatingServiceTableFlowEntity, writeFlowInvTx);
+ mdsalManager.addFlow(confTx, dpnId, terminatingServiceTableFlowEntity);
}
private void makeLFibTableEntry(BigInteger dpId, long serviceId, String floatingIpPortMacAddress, short tableId,
- WriteTransaction writeFlowInvTx) {
+ TypedWriteTransaction<Configuration> confTx) {
List<MatchInfo> matches = new ArrayList<>();
matches.add(MatchEthernetType.MPLS_UNICAST);
matches.add(new MatchMplsLabel(serviceId));
10, flowRef, 0, 0,
NwConstants.COOKIE_VM_LFIB_TABLE, matches, instructions);
- mdsalManager.addFlowToTx(dpId, flowEntity, writeFlowInvTx);
+ mdsalManager.addFlow(confTx, dpId, flowEntity);
LOG.debug("makeLFibTableEntry : LFIB Entry for dpID {} : label : {} modified successfully", dpId, serviceId);
}
- private void removeLFibTableEntry(BigInteger dpnId, long serviceId, WriteTransaction removeFlowInvTx) {
- List<MatchInfo> matches = new ArrayList<>();
- matches.add(MatchEthernetType.MPLS_UNICAST);
- matches.add(new MatchMplsLabel(serviceId));
+ private void removeLFibTableEntry(BigInteger dpnId, long serviceId,
+ TypedReadWriteTransaction<Configuration> confTx) {
String flowRef = getFlowRef(dpnId, NwConstants.L3_LFIB_TABLE, serviceId, "");
LOG.debug("removeLFibTableEntry : removing LFib entry with flow ref {}", flowRef);
- Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.L3_LFIB_TABLE, flowRef,
- 10, flowRef, 0, 0,
- NwConstants.COOKIE_VM_LFIB_TABLE, matches, null);
-
- mdsalManager.removeFlowToTx(dpnId, flowEntity, removeFlowInvTx);
+ mdsalManager.removeFlow(confTx, dpnId, new FlowKey(new FlowId(flowRef)), NwConstants.L3_LFIB_TABLE);
LOG.debug("removeLFibTableEntry : LFIB Entry for dpID : {} label : {} removed successfully",
dpnId, serviceId);
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.genius.infra.Datastore.Configuration;
-import org.opendaylight.genius.infra.TransactionAdapter;
import org.opendaylight.genius.infra.TypedReadWriteTransaction;
import org.opendaylight.genius.infra.TypedWriteTransaction;
import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
}
//The logic now handle only one external IP per router, others if present will be ignored.
String externalIp = NatUtil.validateAndAddNetworkMask(externalIps.get(0).getIpAddress());
- externalRouterListener.handleSnatReverseTraffic(dpnId, routers, routerId, routerName, externalIp,
- TransactionAdapter.toWriteTransaction(confTx));
+ externalRouterListener.handleSnatReverseTraffic(confTx, dpnId, routers, routerId, routerName, externalIp);
}
@Override
//The logic now handle only one external IP per router, others if present will be ignored.
String externalIp = NatUtil.validateAndAddNetworkMask(externalIps.get(0).getIpAddress());
externalRouterListener.clearFibTsAndReverseTraffic(dpnId, routerId, routers.getNetworkId(),
- Collections.singletonList(externalIp), null, routers.getExtGwMacAddress(),
- TransactionAdapter.toWriteTransaction(confTx));
+ Collections.singletonList(externalIp), null, routers.getExtGwMacAddress(), confTx);
}
protected void addOutboundTblTrackEntryForVxlanGre(TypedWriteTransaction<Configuration> confTx, BigInteger dpnId,