*/
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;
+import java.util.concurrent.ExecutionException;
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.infra.ManagedNewTransactionRunner;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
import org.opendaylight.genius.mdsalutil.MDSALUtil;
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.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService;
public class RouterToVpnListener implements NeutronvpnListener {
private static final Logger LOG = LoggerFactory.getLogger(RouterToVpnListener.class);
private final DataBroker dataBroker;
+ private final ManagedNewTransactionRunner txRunner;
private final FloatingIPListener floatingIpListener;
private final OdlInterfaceRpcService interfaceManager;
private final ExternalRoutersListener externalRoutersListener;
final OdlInterfaceRpcService interfaceManager,
final ExternalRoutersListener externalRoutersListener) {
this.dataBroker = dataBroker;
+ this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
this.floatingIpListener = floatingIpListener;
this.interfaceManager = interfaceManager;
this.externalRoutersListener = externalRoutersListener;
public void onRouterAssociatedToVpn(RouterAssociatedToVpn notification) {
String routerName = notification.getRouterId().getValue();
String vpnName = notification.getVpnId().getValue();
- WriteTransaction writeFlowInvTx = dataBroker.newWriteOnlyTransaction();
//check router is associated to external network
String extNetwork = NatUtil.getAssociatedExternalNetwork(dataBroker, routerName);
if (extNetwork != null) {
- LOG.debug("onRouterAssociatedToVpn : Router {} is associated with ext nw {}", routerName, extNetwork);
- handleDNATConfigurationForRouterAssociation(routerName, vpnName, extNetwork);
- Uuid extNetworkUuid = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
- if (extNetworkUuid == null) {
- LOG.error("onRouterAssociatedToVpn : Unable to retrieve external network Uuid for router {}",
+ try {
+ LOG.debug("onRouterAssociatedToVpn : Router {} is associated with ext nw {}", routerName, extNetwork);
+ handleDNATConfigurationForRouterAssociation(routerName, vpnName, extNetwork);
+ Uuid extNetworkUuid = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
+ if (extNetworkUuid == null) {
+ LOG.error("onRouterAssociatedToVpn : Unable to retrieve external network Uuid for router {}",
routerName);
- return;
- }
- ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName,
+ return;
+ }
+ ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName,
extNetworkUuid);
- if (extNwProvType == null) {
- LOG.error("onRouterAssociatedToVpn : External Network Provider Type missing");
- return;
+ if (extNwProvType == null) {
+ LOG.error("onRouterAssociatedToVpn : External Network Provider Type missing");
+ return;
+ }
+ long routerId = NatUtil.getVpnId(dataBroker, routerName);
+ txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+ tx -> externalRoutersListener.changeLocalVpnIdToBgpVpnId(routerName, routerId, vpnName, tx,
+ extNwProvType)).get();
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Error changling local VPN identifier to BGP VPN identifier", e);
}
- long routerId = NatUtil.getVpnId(dataBroker, routerName);
- externalRoutersListener.changeLocalVpnIdToBgpVpnId(routerName, routerId, vpnName, writeFlowInvTx,
- extNwProvType);
} else {
LOG.debug("onRouterAssociatedToVpn : Ignoring the Router {} association with VPN {} "
+ "since it is not external router", routerName, vpnName);
}
-
- NatUtil.waitForTransactionToComplete(writeFlowInvTx);
}
/**
public void onRouterDisassociatedFromVpn(RouterDisassociatedFromVpn notification) {
String routerName = notification.getRouterId().getValue();
String vpnName = notification.getVpnId().getValue();
- WriteTransaction writeFlowInvTx = dataBroker.newWriteOnlyTransaction();
//check router is associated to external network
String extNetwork = NatUtil.getAssociatedExternalNetwork(dataBroker, routerName);
if (extNetwork != null) {
- LOG.debug("onRouterDisassociatedFromVpn : Router {} is associated with ext nw {}", routerName, extNetwork);
- handleDNATConfigurationForRouterDisassociation(routerName, vpnName, extNetwork);
- Uuid extNetworkUuid = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
- if (extNetworkUuid == null) {
- LOG.error("onRouterDisassociatedFromVpn : Unable to retrieve external network Uuid for router {}",
- routerName);
- return;
+ try {
+ LOG.debug("onRouterDisassociatedFromVpn : Router {} is associated with ext nw {}", routerName,
+ extNetwork);
+ handleDNATConfigurationForRouterDisassociation(routerName, vpnName, extNetwork);
+ Uuid extNetworkUuid = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
+ if (extNetworkUuid == null) {
+ LOG.error("onRouterDisassociatedFromVpn : Unable to retrieve external network Uuid for router {}",
+ routerName);
+ return;
+ }
+ ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName,
+ extNetworkUuid);
+ if (extNwProvType == null) {
+ LOG.error("onRouterDisassociatedFromVpn : External Network Provider Type missing");
+ return;
+ }
+ long routerId = NatUtil.getVpnId(dataBroker, routerName);
+ txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+ tx -> externalRoutersListener.changeBgpVpnIdToLocalVpnId(routerName, routerId, vpnName, tx,
+ extNwProvType)).get();
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Error changing BGP VPN identifier to local VPN identifier", e);
}
- ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName,
- extNetworkUuid);
- if (extNwProvType == null) {
- LOG.error("onRouterDisassociatedFromVpn : External Network Provider Type missing");
- return;
- }
- long routerId = NatUtil.getVpnId(dataBroker, routerName);
- externalRoutersListener.changeBgpVpnIdToLocalVpnId(routerName, routerId, vpnName, writeFlowInvTx,
- extNwProvType);
} else {
LOG.debug("onRouterDisassociatedFromVpn : Ignoring the Router {} association with VPN {} "
+ "since it is not external router", routerName, vpnName);
}
-
- NatUtil.waitForTransactionToComplete(writeFlowInvTx);
}
- void handleDNATConfigurationForRouterAssociation(String routerName, String vpnName, String externalNetwork) {
+ void handleDNATConfigurationForRouterAssociation(String routerName, String vpnName, String externalNetwork)
+ throws ExecutionException, InterruptedException {
InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerName);
Optional<RouterPorts> optRouterPorts =
MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
}
}
- void handleDNATConfigurationForRouterDisassociation(String routerName, String vpnName, String externalNetwork) {
+ void handleDNATConfigurationForRouterDisassociation(String routerName, String vpnName, String externalNetwork)
+ throws ExecutionException, InterruptedException {
InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerName);
Optional<RouterPorts> optRouterPorts =
MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);