package org.opendaylight.netvirt.vpnmanager;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
import java.math.BigInteger;
import java.util.List;
import java.util.Objects;
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.NwConstants;
import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
import org.opendaylight.netvirt.vpnmanager.api.IVpnManager;
@Override
protected void remove(InstanceIdentifier<RouterToNaptSwitch> key, RouterToNaptSwitch routerToNaptSwitch) {
LOG.debug("Removing {}", routerToNaptSwitch);
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx ->
- setupRouterGwFlows(routerToNaptSwitch, tx, NwConstants.DEL_FLOW)), LOG,
- "Error processing switch removal for {}", routerToNaptSwitch);
+ ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx ->
+ setupRouterGwFlows(routerToNaptSwitch, tx, NwConstants.DEL_FLOW)), LOG,
+ "Error processing switch removal for {}", routerToNaptSwitch);
}
@Override
LOG.debug("Updating old {} new {}", origRouterToNaptSwitch, updatedRouterToNaptSwitch);
if (!Objects.equals(updatedRouterToNaptSwitch.getPrimarySwitchId(),
origRouterToNaptSwitch.getPrimarySwitchId())) {
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+ ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
setupRouterGwFlows(origRouterToNaptSwitch, tx, NwConstants.DEL_FLOW);
setupRouterGwFlows(updatedRouterToNaptSwitch, tx, NwConstants.ADD_FLOW);
}), LOG, "Error updating switch {} to {}", origRouterToNaptSwitch, updatedRouterToNaptSwitch);
@Override
protected void add(InstanceIdentifier<RouterToNaptSwitch> key, RouterToNaptSwitch routerToNaptSwitch) {
LOG.debug("Adding {}", routerToNaptSwitch);
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx ->
+ ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx ->
setupRouterGwFlows(routerToNaptSwitch, tx, NwConstants.ADD_FLOW)), LOG,
"Error processing switch addition for {}", routerToNaptSwitch);
}
return this;
}
- private void setupRouterGwFlows(RouterToNaptSwitch routerToNaptSwitch, WriteTransaction writeTx, int addOrRemove)
- throws ExecutionException, InterruptedException {
+ private void setupRouterGwFlows(RouterToNaptSwitch routerToNaptSwitch,
+ TypedReadWriteTransaction<Configuration> confTx, int addOrRemove)
+ throws ExecutionException, InterruptedException {
Routers router = null;
if (addOrRemove == NwConstants.ADD_FLOW) {
router = vpnUtil.getExternalRouter(routerToNaptSwitch.getRouterName());
Uuid subnetVpnName = extIp.getSubnetId();
if (addOrRemove == NwConstants.ADD_FLOW) {
vpnManager.addRouterGwMacFlow(routerName, extGwMacAddress, primarySwitchId, extNetworkId,
- subnetVpnName.getValue(), writeTx);
+ subnetVpnName.getValue(), confTx);
externalRouterDataUtil.addtoRouterMap(router);
} else {
vpnManager.removeRouterGwMacFlow(routerName, extGwMacAddress, primarySwitchId, extNetworkId,
- subnetVpnName.getValue(), writeTx);
+ subnetVpnName.getValue(), confTx);
externalRouterDataUtil.removeFromRouterMap(router);
}
}
if (addOrRemove == NwConstants.ADD_FLOW) {
vpnManager.addArpResponderFlowsToExternalNetworkIps(routerName,
VpnUtil.getIpsListFromExternalIps(router.getExternalIps()),
- extGwMacAddress, primarySwitchId, extNetworkId, writeTx);
+ extGwMacAddress, primarySwitchId, extNetworkId);
} else {
vpnManager.removeArpResponderFlowsToExternalNetworkIps(routerName,
VpnUtil.getIpsListFromExternalIps(router.getExternalIps()),