import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import java.util.concurrent.ExecutionException;
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.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;
//Check for VPN disassociation
Uuid originalVpn = original.getVpnid();
Uuid updatedVpn = update.getVpnid();
- coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + update.key(),
- () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
- if (originalVpn == null && updatedVpn != null) {
- //external network is dis-associated from L3VPN instance
- associateExternalNetworkWithVPN(update, tx);
- } else if (originalVpn != null && updatedVpn == null) {
- //external network is associated with vpn
- disassociateExternalNetworkFromVPN(update, originalVpn.getValue());
- //Remove the SNAT entries
- removeSnatEntries(original, original.getId(), tx);
- }
- })), NatConstants.NAT_DJC_MAX_RETRIES);
+ if (originalVpn == null && updatedVpn != null) {
+ //external network is dis-associated from L3VPN instance
+ associateExternalNetworkWithVPN(update);
+ } else if (originalVpn != null && updatedVpn == null) {
+ //external network is associated with vpn
+ disassociateExternalNetworkFromVPN(update, originalVpn.getValue());
+ //Remove the SNAT entries
+ removeSnatEntries(original, original.getId());
+ }
}
- private void removeSnatEntries(Networks original, Uuid networkUuid,
- TypedReadWriteTransaction<Configuration> writeFlowInvTx) {
+ private void removeSnatEntries(Networks original, Uuid networkUuid) {
List<Uuid> routerUuids = original.getRouterIds();
for (Uuid routerUuid : routerUuids) {
Long routerId = NatUtil.getVpnId(dataBroker, routerUuid.getValue());
}
Collection<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker,routerId);
if (natMode == NatMode.Controller) {
- externalRouterListener.handleDisableSnatInternetVpn(routerUuid.getValue(), routerId, networkUuid,
- externalIps, original.getVpnid().getValue(), writeFlowInvTx);
+ coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + routerUuid.getValue(),
+ () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
+ tx -> {
+ externalRouterListener.handleDisableSnatInternetVpn(routerUuid.getValue(), routerId,
+ networkUuid, externalIps, original.getVpnid().getValue(), tx);
+ })), NatConstants.NAT_DJC_MAX_RETRIES);
}
}
}
- private void associateExternalNetworkWithVPN(Networks network, TypedReadWriteTransaction<Configuration> confTx)
- throws ExecutionException, InterruptedException {
+ private void associateExternalNetworkWithVPN(Networks network) {
List<Uuid> routerIds = network.getRouterIds();
for (Uuid routerId : routerIds) {
//long router = NatUtil.getVpnId(dataBroker, routerId.getValue());
}
List<InternalToExternalPortMap> intExtPortMapList = port.getInternalToExternalPortMap();
for (InternalToExternalPortMap ipMap : intExtPortMapList) {
- //remove all VPN related entries
- floatingIpListener.createNATFlowEntries(dpnId, portName, routerId.getValue(), network.getId(),
- ipMap, confTx);
+ // remove all VPN related entries
+ coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + ipMap.key(),
+ () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
+ tx -> {
+ floatingIpListener.createNATFlowEntries(dpnId, portName, routerId.getValue(),
+ network.getId(), ipMap, tx);
+ })), NatConstants.NAT_DJC_MAX_RETRIES);
}
}
}
routerId, dpnId);
return;
}
+ final BigInteger finalDpnId = dpnId;
+ coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + routerId.getValue(),
+ () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
+ confTx -> {
+ Long routerIdentifier = NatUtil.getVpnId(dataBroker, routerId.getValue());
+ InstanceIdentifierBuilder<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice
+ .rev160111.intext.ip.map.IpMapping> idBuilder =
+ InstanceIdentifier.builder(IntextIpMap.class)
+ .child(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111
+ .intext.ip.map.IpMapping.class,
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111
+ .intext.ip.map.IpMappingKey(routerIdentifier));
+ InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111
+ .intext.ip.map.IpMapping> id = idBuilder.build();
+ Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111
+ .intext.ip.map.IpMapping> ipMapping = MDSALUtil.read(dataBroker,
+ LogicalDatastoreType.OPERATIONAL, id);
+ if (ipMapping.isPresent()) {
+ List<IpMap> ipMaps = ipMapping.get().getIpMap();
+ for (IpMap ipMap : ipMaps) {
+ String externalIp = ipMap.getExternalIp();
+ LOG.debug("associateExternalNetworkWithVPN : Calling advToBgpAndInstallFibAndTsFlows "
+ + "for dpnId {},vpnName {} and externalIp {}", finalDpnId, vpnName, externalIp);
+ if (natMode == NatMode.Controller) {
+ externalRouterListener.advToBgpAndInstallFibAndTsFlows(finalDpnId,
+ NwConstants.INBOUND_NAPT_TABLE, vpnName, routerIdentifier,
+ routerId.getValue(), externalIp, network.getId(),
+ null /* external-router */, confTx);
+ }
+ }
+ } else {
+ LOG.warn("associateExternalNetworkWithVPN: No ipMapping present fot the routerId {}",
+ routerId);
+ }
- Long routerIdentifier = NatUtil.getVpnId(dataBroker, routerId.getValue());
- InstanceIdentifierBuilder<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice
- .rev160111.intext.ip.map.IpMapping> idBuilder =
- InstanceIdentifier.builder(IntextIpMap.class)
- .child(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111
- .intext.ip.map.IpMapping.class,
- new org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111
- .intext.ip.map.IpMappingKey(routerIdentifier));
- InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111
- .intext.ip.map.IpMapping> id = idBuilder.build();
- Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111
- .intext.ip.map.IpMapping> ipMapping = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
- if (ipMapping.isPresent()) {
- List<IpMap> ipMaps = ipMapping.get().getIpMap();
- for (IpMap ipMap : ipMaps) {
- String externalIp = ipMap.getExternalIp();
- LOG.debug("associateExternalNetworkWithVPN : Calling advToBgpAndInstallFibAndTsFlows for dpnId {},"
- + "vpnName {} and externalIp {}", dpnId, vpnName, externalIp);
- if (natMode == NatMode.Controller) {
- externalRouterListener.advToBgpAndInstallFibAndTsFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE,
- vpnName, routerIdentifier, routerId.getValue(),
- externalIp, network.getId(), null /* external-router */,
- confTx);
- }
- }
- } else {
- LOG.warn("associateExternalNetworkWithVPN : No ipMapping present fot the routerId {}", routerId);
- }
-
- long vpnId = NatUtil.getVpnId(dataBroker, vpnName);
- // Install 47 entry to point to 21
- if (natMode == NatMode.Controller) {
- externalRouterListener.installNaptPfibEntriesForExternalSubnets(routerId.getValue(), dpnId,
- confTx);
- if (vpnId != -1) {
- LOG.debug("associateExternalNetworkWithVPN : Calling externalRouterListener installNaptPfibEntry "
- + "for dpnId {} and vpnId {}", dpnId, vpnId);
- externalRouterListener.installNaptPfibEntry(dpnId, vpnId, confTx);
- }
- }
+ long vpnId = NatUtil.getVpnId(dataBroker, vpnName);
+ // Install 47 entry to point to 21
+ if (natMode == NatMode.Controller) {
+ externalRouterListener.installNaptPfibEntriesForExternalSubnets(routerId.getValue(),
+ finalDpnId, confTx);
+ if (vpnId != -1) {
+ LOG.debug("associateExternalNetworkWithVPN : Calling externalRouterListener "
+ + "installNaptPfibEntry for dpnId {} and vpnId {}", finalDpnId, vpnId);
+ externalRouterListener.installNaptPfibEntry(finalDpnId, vpnId, confTx);
+ }
+ }
+ })), NatConstants.NAT_DJC_MAX_RETRIES);
}
-
}
private void disassociateExternalNetworkFromVPN(Networks network, String vpnName) {
}
RouterPorts routerPorts = optRouterPorts.get();
List<Ports> interfaces = routerPorts.getPorts();
- try {
- txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
- for (Ports port : interfaces) {
- String portName = port.getPortName();
- BigInteger dpnId = NatUtil.getDpnForInterface(interfaceManager, portName);
- if (dpnId.equals(BigInteger.ZERO)) {
- LOG.debug("disassociateExternalNetworkFromVPN : DPN not found for {},"
- + "skip handling of ext nw {} disassociation", portName, network.getId());
- continue;
- }
- List<InternalToExternalPortMap> intExtPortMapList = port.getInternalToExternalPortMap();
- for (InternalToExternalPortMap intExtPortMap : intExtPortMapList) {
- floatingIpListener.removeNATFlowEntries(dpnId, portName, vpnName, routerId.getValue(),
+ for (Ports port : interfaces) {
+ String portName = port.getPortName();
+ BigInteger dpnId = NatUtil.getDpnForInterface(interfaceManager, portName);
+ if (dpnId.equals(BigInteger.ZERO)) {
+ LOG.debug("disassociateExternalNetworkFromVPN : DPN not found for {},"
+ + "skip handling of ext nw {} disassociation", portName, network.getId());
+ continue;
+ }
+ List<InternalToExternalPortMap> intExtPortMapList = port.getInternalToExternalPortMap();
+ for (InternalToExternalPortMap intExtPortMap : intExtPortMapList) {
+ coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + intExtPortMap.key(),
+ () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
+ tx -> {
+ floatingIpListener.removeNATFlowEntries(dpnId, portName, vpnName, routerId.getValue(),
intExtPortMap, tx);
- }
- }
- }).get();
- } catch (ExecutionException | InterruptedException e) {
- LOG.error("Error writing to datastore {}", e);
+ })), NatConstants.NAT_DJC_MAX_RETRIES);
+ }
}
}
}
List<ListenableFuture<Void>> futures = new ArrayList<>();
try {
LOG.trace("call : Received interface {} PORT UP OR ADD event ", interfaceName);
- futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, tx ->
- handleRouterInterfacesUpEvent(routerName, interfaceName, intfDpnId, tx)));
+ String dpnLock = NatConstants.NAT_DJC_PREFIX + intfDpnId;
+ synchronized (dpnLock.intern()) {
+ 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",
interfaceName, e);
List<ListenableFuture<Void>> futures = new ArrayList<>();
try {
LOG.trace("call : Received interface {} PORT DOWN or REMOVE event", interfaceName);
- futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, tx ->
+ String dpnLock = NatConstants.NAT_DJC_PREFIX + intfDpnId;
+ synchronized (dpnLock.intern()) {
+ 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);
}
final String interfaceName = update.getName();
LOG.trace("call : Received interface {} state change event", interfaceName);
LOG.debug("call : DPN ID {} for the interface {} ", intfDpnId, interfaceName);
- IntfTransitionState state = getTransitionState(original.getOperStatus(), update.getOperStatus());
- if (state.equals(IntfTransitionState.STATE_IGNORE)) {
- LOG.info("NAT Service: Interface {} state original {} updated {} not handled",
- interfaceName, original.getOperStatus(), update.getOperStatus());
- return futures;
- }
- 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(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"
- + " in the ODL:L3VPN", intfDpnId, interfaceName);
- handleRouterInterfacesUpEvent(routerName, interfaceName, intfDpnId, tx);
+ String dpnLock = NatConstants.NAT_DJC_PREFIX + intfDpnId;
+ synchronized (dpnLock.intern()) {
+ IntfTransitionState state = getTransitionState(original.getOperStatus(), update.getOperStatus());
+ if (state.equals(IntfTransitionState.STATE_IGNORE)) {
+ LOG.info("NAT Service: Interface {} state original {} updated {} not handled",
+ interfaceName, original.getOperStatus(), update.getOperStatus());
+ return futures;
}
- }));
+ 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(routerName, interfaceName,
+ 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"
+ + " in the ODL:L3VPN", intfDpnId, interfaceName);
+ handleRouterInterfacesUpEvent(routerName, interfaceName, intfDpnId, tx);
+ }
+ }));
+ }
} catch (Exception e) {
LOG.error("call : Exception observed in handling updation of VPN Interface {}.", update.getName(), e);
}
interfaceName, routerId);
return;
}
- 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");
+ String dpnLock = NatConstants.NAT_DJC_PREFIX + dpId;
+ synchronized (dpnLock.intern()) {
+ 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 {}",
interfaceName, routerId);
confTx -> confTx.delete(NatUtil.getRouterInterfaceId(interfaceName))), LOG,
"Error handling NAT router interface removal");
- ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, operTx -> {
- //Delete the NeutronRouterDpnMap from the ODL:L3VPN operational model
- NatUtil.removeFromNeutronRouterDpnsMap(routerId, interfaceName, interfaceManager, operTx);
-
- //Delete the DpnRouterMap from the ODL:L3VPN operational model
- NatUtil.removeFromDpnRoutersMap(dataBroker, routerId, interfaceName, interfaceManager, operTx);
- }), LOG, "Error handling NAT router interface removal");
+ BigInteger dpId = NatUtil.getDpnForInterface(interfaceManager, interfaceName);
+ if (dpId.equals(BigInteger.ZERO)) {
+ LOG.warn("REMOVE : Could not retrieve DPN ID for interface {} to handle router {} dissociation model",
+ interfaceName, routerId);
+ return;
+ }
+ String dpnLock = NatConstants.NAT_DJC_PREFIX + dpId;
+ synchronized (dpnLock.intern()) {
+ ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, operTx -> {
+ //Delete the NeutronRouterDpnMap from the ODL:L3VPN operational model
+ NatUtil.removeFromNeutronRouterDpnsMap(routerId, interfaceName, dpId, operTx);
+ //Delete the DpnRouterMap from the ODL:L3VPN operational model
+ NatUtil.removeFromDpnRoutersMap(dataBroker, routerId, interfaceName, dpId, interfaceManager, operTx);
+ }), LOG, "Error handling NAT router interface removal");
+ }
}
@Override
}
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 {}"
- + " dissociation model", vpnInterfaceName, routerName);
- return;
- }
+ BigInteger dpId, @Nonnull TypedReadWriteTransaction<Operational> operTx) {
InstanceIdentifier<DpnVpninterfacesList> routerDpnListIdentifier = getRouterDpnId(routerName, dpId);
Optional<DpnVpninterfacesList> optionalRouterDpnList;
try {
}
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();
+ .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(vpnInterfaceName))
- .setInterface(vpnInterfaceName).build();
+ .list.dpn.vpninterfaces.list.RouterInterfaces routerInterface =
+ new RouterInterfacesBuilder().withKey(new RouterInterfacesKey(vpnInterfaceName))
+ .setInterface(vpnInterfaceName).build();
if (routerInterfaces != null && routerInterfaces.remove(routerInterface)) {
if (routerInterfaces.isEmpty()) {
operTx.delete(routerDpnListIdentifier);
} else {
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)));
+ 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, TypedReadWriteTransaction<Operational> operTx)
- throws ExecutionException, InterruptedException {
- BigInteger dpId = getDpnForInterface(ifaceMgrRpcService, vpnInterfaceName);
- if (dpId.equals(BigInteger.ZERO)) {
- LOG.debug("removeFromDpnRoutersMap : removeFromDpnRoutersMap() : "
- + "Could not retrieve DPN ID for interface {} to handle router {} dissociation model",
- vpnInterfaceName, routerName);
- return;
- }
- removeFromDpnRoutersMap(broker, routerName, vpnInterfaceName, dpId, ifaceMgrRpcService, operTx);
- }
-
- static void removeFromDpnRoutersMap(DataBroker broker, String routerName, String vpnInterfaceName,
BigInteger curDpnId, OdlInterfaceRpcService ifaceMgrRpcService, TypedReadWriteTransaction<Operational> operTx)
throws ExecutionException, InterruptedException {
/*