/*
- * Copyright © 2015, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright © 2015, 2018 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
package org.opendaylight.netvirt.neutronvpn;
import static java.util.Collections.singletonList;
-import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
-import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL;
import static org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker.syncReadOptional;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils.requireNonNullElse;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Consumer;
-import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.PreDestroy;
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
-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.OptimisticLockFailedException;
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.ManagedNewTransactionRunner;
import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
+import org.opendaylight.genius.mdsalutil.NwConstants;
+import org.opendaylight.genius.utils.JvmGlobalLocks;
import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
import org.opendaylight.infrautils.utils.concurrent.KeyedLocks;
import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry.BgpvpnType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.GetL3VPNOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NetworkAttributes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NeutronvpnService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.RouterAssociatedToVpn;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.RouterAssociatedToVpnBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.RouterDisassociatedFromVpn;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.RouterDisassociatedFromVpnBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.RouterInterfacesMap;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.VpnMaps;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.RemoveStaticRouteInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.RemoveStaticRouteInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.VpnRpcService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.extensions.rev160617.BgpvpnVni;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.extensions.rev160617.OperationalPortStatus;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.extensions.rev160617.service.provider.features.attributes.Features;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.extensions.rev160617.service.provider.features.attributes.features.Feature;
private final NeutronEvpnUtils neutronEvpnUtils;
private final JobCoordinator jobCoordinator;
private final NeutronvpnUtils neutronvpnUtils;
+ private final IVpnManager vpnManager;
private final ConcurrentHashMap<Uuid, Uuid> unprocessedPortsMap = new ConcurrentHashMap<>();
private final NeutronvpnAlarms neutronvpnAlarm = new NeutronvpnAlarms();
private final KeyedLocks<Uuid> vpnLock = new KeyedLocks<>();
final VpnRpcService vpnRpcSrv, final IElanService elanService,
final NeutronFloatingToFixedIpMappingChangeListener neutronFloatingToFixedIpMappingChangeListener,
final NeutronvpnConfig neutronvpnConfig, final IVpnManager vpnManager,
- final JobCoordinator jobCoordinator, final NeutronvpnUtils neutronvpnUtils) {
+ final JobCoordinator jobCoordinator,
+ final NeutronvpnUtils neutronvpnUtils) throws TransactionCommitFailedException {
this.dataBroker = dataBroker;
this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
notificationPublishService = notiPublishService;
neutronEvpnUtils = new NeutronEvpnUtils(dataBroker, vpnManager, jobCoordinator);
this.jobCoordinator = jobCoordinator;
this.neutronvpnUtils = neutronvpnUtils;
+ this.vpnManager = vpnManager;
configureFeatures();
}
LOG.info("{} close", getClass().getSimpleName());
}
- private void configureFeatures() {
+ private void configureFeatures() throws TransactionCommitFailedException {
InstanceIdentifier<Feature> iid = InstanceIdentifier.builder(
Neutron.class).child(Features.class).child(
Feature.class, new FeatureKey(OperationalPortStatus.class)).build();
Feature feature = new FeatureBuilder().withKey(new FeatureKey(OperationalPortStatus.class)).build();
try {
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, iid, feature);
- } catch (TransactionCommitFailedException e) {
- LOG.warn("Error configuring feature {}", feature, e);
+ } catch (OptimisticLockFailedException e) {
+ LOG.debug("Optimistic lock failed exception while configuring feature {}", feature, e);
+ }
+ InstanceIdentifier<Feature> bgpvpnVniIid = InstanceIdentifier.builder(
+ Neutron.class).child(Features.class).child(
+ Feature.class, new FeatureKey(BgpvpnVni.class)).build();
+ Feature bgpvpnVniFeature = new FeatureBuilder().withKey(new FeatureKey(BgpvpnVni.class)).build();
+ try {
+ SingleTransactionDataBroker.syncWrite(
+ dataBroker, LogicalDatastoreType.OPERATIONAL, bgpvpnVniIid, bgpvpnVniFeature);
+ } catch (OptimisticLockFailedException e) {
+ LOG.debug("Optimistic lock failed exception while configuring feature {}", bgpvpnVniFeature, e);
}
}
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void createSubnetmapNode(Uuid subnetId, String subnetIp, Uuid tenantId, Uuid networkId,
- NetworkAttributes.NetworkType networkType, long segmentationId) {
+ @Nullable NetworkAttributes.NetworkType networkType, long segmentationId) {
try {
InstanceIdentifier<Subnetmap> subnetMapIdentifier = NeutronvpnUtils.buildSubnetMapIdentifier(subnetId);
- synchronized (subnetId.getValue().intern()) {
+ final ReentrantLock lock = lockForUuid(subnetId);
+ lock.lock();
+ try {
LOG.info("createSubnetmapNode: subnet ID {}", subnetId.toString());
Optional<Subnetmap> sn = SingleTransactionDataBroker.syncReadOptional(dataBroker,
LogicalDatastoreType.CONFIGURATION, subnetMapIdentifier);
subnetId.getValue());
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
subnetMapIdentifier, subnetmapBuilder.build());
+ } finally {
+ lock.unlock();
}
} catch (TransactionCommitFailedException | ReadFailedException e) {
LOG.error("createSubnetmapNode: Creating subnetmap node failed for subnet {}", subnetId.getValue());
}
}
- protected Subnetmap updateSubnetNode(Uuid subnetId, Uuid routerId, Uuid vpnId, Uuid internetvpnId) {
- Subnetmap subnetmap = null;
- SubnetmapBuilder builder = null;
+ @Nullable
+ protected Subnetmap updateSubnetNode(Uuid subnetId, @Nullable Uuid routerId, Uuid vpnId,
+ @Nullable Uuid internetvpnId) {
InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class)
.child(Subnetmap.class, new SubnetmapKey(subnetId))
.build();
+ final ReentrantLock lock = lockForUuid(subnetId);
+ lock.lock();
try {
- synchronized (subnetId.getValue().intern()) {
- Optional<Subnetmap> sn =
- SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
- id);
- if (sn.isPresent()) {
- builder = new SubnetmapBuilder(sn.get());
- LOG.debug("updating existing subnetmap node for subnet ID {}", subnetId.getValue());
- } else {
- LOG.error("subnetmap node for subnet {} does not exist, returning", subnetId.getValue());
- return null;
- }
- if (routerId != null) {
- builder.setRouterId(routerId);
- }
- if (vpnId != null) {
- builder.setVpnId(vpnId);
- }
+ Optional<Subnetmap> sn =
+ SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
+ if (!sn.isPresent()) {
+ LOG.error("subnetmap node for subnet {} does not exist, returning", subnetId.getValue());
+ return null;
+ }
+ LOG.debug("updating existing subnetmap node for subnet ID {}", subnetId.getValue());
+ SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
+ if (routerId != null) {
+ builder.setRouterId(routerId);
+ }
+ if (vpnId != null) {
+ builder.setVpnId(vpnId);
+ }
+ if (NeutronvpnUtils.getIpVersionFromString(sn.get().getSubnetIp()) == IpVersionChoice.IPV6) {
builder.setInternetVpnId(internetvpnId);
-
- subnetmap = builder.build();
- LOG.debug("Creating/Updating subnetMap node: {} ", subnetId.getValue());
- SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
}
+ Subnetmap subnetmap = builder.build();
+ LOG.debug("Creating/Updating subnetMap node: {} ", subnetId.getValue());
+ SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
+ return subnetmap;
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("Subnet map update failed for node {}", subnetId.getValue(), e);
+ return null;
+ } finally {
+ lock.unlock();
}
- return subnetmap;
}
- protected void updateSubnetNodeWithFixedIp(Uuid subnetId, Uuid routerId,
- Uuid routerInterfacePortId, String fixedIp,
- String routerIntfMacAddress, Uuid vpnId) {
- Subnetmap subnetmap = null;
- SubnetmapBuilder builder = null;
+ protected void updateSubnetNodeWithFixedIp(Uuid subnetId, @Nullable Uuid routerId,
+ @Nullable Uuid routerInterfacePortId, @Nullable String fixedIp,
+ @Nullable String routerIntfMacAddress, @Nullable Uuid vpnId) {
InstanceIdentifier<Subnetmap> id =
- InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
+ InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
+ final ReentrantLock lock = lockForUuid(subnetId);
+ lock.lock();
try {
- synchronized (subnetId.getValue().intern()) {
- Optional<Subnetmap> sn =
- SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
- id);
- if (sn.isPresent()) {
- builder = new SubnetmapBuilder(sn.get());
- LOG.debug("WithRouterFixedIP: Updating existing subnetmap node for subnet ID {}",
- subnetId.getValue());
- } else {
- LOG.error("WithRouterFixedIP: subnetmap node for subnet {} does not exist, returning ",
- subnetId.getValue());
- return;
- }
- builder.setRouterId(routerId);
- builder.setRouterInterfacePortId(routerInterfacePortId);
- builder.setRouterIntfMacAddress(routerIntfMacAddress);
- builder.setRouterInterfaceFixedIp(fixedIp);
- if (vpnId != null) {
- builder.setVpnId(vpnId);
- }
- subnetmap = builder.build();
- LOG.debug("WithRouterFixedIP Creating/Updating subnetMap node for Router FixedIp: {} ",
+ Optional<Subnetmap> sn =
+ SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
+ if (!sn.isPresent()) {
+ LOG.error("WithRouterFixedIP: subnetmap node for subnet {} does not exist, returning ",
subnetId.getValue());
- SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
+ return;
}
+ LOG.debug("WithRouterFixedIP: Updating existing subnetmap node for subnet ID {}",
+ subnetId.getValue());
+ SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
+ builder.setRouterId(routerId);
+ builder.setRouterInterfacePortId(routerInterfacePortId);
+ builder.setRouterIntfMacAddress(routerIntfMacAddress);
+ builder.setRouterInterfaceFixedIp(fixedIp);
+ if (vpnId != null) {
+ builder.setVpnId(vpnId);
+ }
+ Subnetmap subnetmap = builder.build();
+ LOG.debug("WithRouterFixedIP Creating/Updating subnetMap node for Router FixedIp: {} ",
+ subnetId.getValue());
+ SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("WithRouterFixedIP: subnet map for Router FixedIp failed for node {}",
subnetId.getValue(), e);
+ } finally {
+ lock.unlock();
}
}
- protected Subnetmap updateSubnetmapNodeWithPorts(Uuid subnetId, Uuid portId, Uuid directPortId) {
+ protected Subnetmap updateSubnetmapNodeWithPorts(Uuid subnetId, @Nullable Uuid portId,
+ @Nullable Uuid directPortId) {
Subnetmap subnetmap = null;
InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class,
new SubnetmapKey(subnetId)).build();
LOG.info("updateSubnetmapNodeWithPorts : subnetId {}, subnetMapId {}", subnetId.toString(), id.toString());
+ final ReentrantLock lock = lockForUuid(subnetId);
+ lock.lock();
try {
- synchronized (subnetId.getValue().intern()) {
- Optional<Subnetmap> sn =
- SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
- id);
- if (sn.isPresent()) {
- SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
- if (null != portId) {
- List<Uuid> portList = builder.getPortList();
- if (null == portList) {
- portList = new ArrayList<>();
- }
- portList.add(portId);
- builder.setPortList(portList);
- LOG.debug("updateSubnetmapNodeWithPorts: Updating existing subnetmap node {} with port {}",
- subnetId.getValue(), portId.getValue());
+ Optional<Subnetmap> sn =
+ SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ id);
+ if (sn.isPresent()) {
+ SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
+ if (null != portId) {
+ List<Uuid> portList = builder.getPortList();
+ if (null == portList) {
+ portList = new ArrayList<>();
}
- if (null != directPortId) {
- List<Uuid> directPortList = builder.getDirectPortList();
- if (null == directPortList) {
- directPortList = new ArrayList<>();
- }
- directPortList.add(directPortId);
- builder.setDirectPortList(directPortList);
- LOG.debug("Updating existing subnetmap node {} with port {}", subnetId.getValue(),
- directPortId.getValue());
+ portList.add(portId);
+ builder.setPortList(portList);
+ LOG.debug("updateSubnetmapNodeWithPorts: Updating existing subnetmap node {} with port {}",
+ subnetId.getValue(), portId.getValue());
+ }
+ if (null != directPortId) {
+ List<Uuid> directPortList = builder.getDirectPortList();
+ if (null == directPortList) {
+ directPortList = new ArrayList<>();
}
- subnetmap = builder.build();
- SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id,
- subnetmap);
- } else {
- LOG.info("updateSubnetmapNodeWithPorts: Subnetmap node is not ready {}, put port {} in unprocessed "
- + "cache ", subnetId.getValue(), portId.getValue());
- unprocessedPortsMap.put(portId, subnetId);
+ directPortList.add(directPortId);
+ builder.setDirectPortList(directPortList);
+ LOG.debug("Updating existing subnetmap node {} with port {}", subnetId.getValue(),
+ directPortId.getValue());
}
+ subnetmap = builder.build();
+ SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id,
+ subnetmap);
+ } else {
+ LOG.info("updateSubnetmapNodeWithPorts: Subnetmap node is not ready {}, put port {} in unprocessed "
+ + "cache ", subnetId.getValue(), portId.getValue());
+ unprocessedPortsMap.put(portId, subnetId);
}
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("Updating port list of a given subnetMap failed for node: {}", subnetId.getValue(), e);
+ } finally {
+ lock.unlock();
}
return subnetmap;
}
- protected Subnetmap removeFromSubnetNode(Uuid subnetId, Uuid networkId, Uuid routerId,
- Uuid vpnId, Uuid portId) {
+ protected Subnetmap removeFromSubnetNode(Uuid subnetId, @Nullable Uuid networkId, @Nullable Uuid routerId,
+ Uuid vpnId, @Nullable Uuid portId) {
Subnetmap subnetmap = null;
InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class)
.child(Subnetmap.class, new SubnetmapKey(subnetId))
.build();
+ final ReentrantLock lock = lockForUuid(subnetId);
+ lock.lock();
try {
- synchronized (subnetId.getValue().intern()) {
- Optional<Subnetmap> sn =
- SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
- id);
- if (sn.isPresent()) {
- SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
- if (routerId != null) {
- builder.setRouterId(null);
- }
- if (networkId != null) {
- builder.setNetworkId(null);
- }
- if (vpnId != null) {
- builder.setVpnId(null);
- }
- builder.setInternetVpnId(null);
- if (portId != null && builder.getPortList() != null) {
- List<Uuid> portList = builder.getPortList();
- portList.remove(portId);
- builder.setPortList(portList);
- }
-
- subnetmap = builder.build();
- LOG.debug("Removing from existing subnetmap node: {} ", subnetId.getValue());
- SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id,
- subnetmap);
- } else {
- LOG.warn("removing from non-existing subnetmap node: {} ", subnetId.getValue());
+ Optional<Subnetmap> sn =
+ SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ id);
+ if (sn.isPresent()) {
+ SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
+ if (routerId != null) {
+ builder.setRouterId(null);
}
+ if (networkId != null) {
+ builder.setNetworkId(null);
+ }
+ if (vpnId != null) {
+ builder.setVpnId(null);
+ }
+ builder.setInternetVpnId(null);
+ if (portId != null && builder.getPortList() != null) {
+ List<Uuid> portList = builder.getPortList();
+ portList.remove(portId);
+ builder.setPortList(portList);
+ }
+
+ subnetmap = builder.build();
+ LOG.debug("Removing from existing subnetmap node: {} ", subnetId.getValue());
+ SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id,
+ subnetmap);
+ } else {
+ LOG.warn("removing from non-existing subnetmap node: {} ", subnetId.getValue());
}
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("Removal from subnetmap failed for node: {}", subnetId.getValue());
+ } finally {
+ lock.unlock();
}
return subnetmap;
}
- protected Subnetmap removePortsFromSubnetmapNode(Uuid subnetId, Uuid portId, Uuid directPortId) {
+ @Nullable
+ protected Subnetmap removePortsFromSubnetmapNode(Uuid subnetId, @Nullable Uuid portId,
+ @Nullable Uuid directPortId) {
Subnetmap subnetmap = null;
InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class,
new SubnetmapKey(subnetId)).build();
+ final ReentrantLock lock = lockForUuid(subnetId);
+ lock.lock();
try {
- synchronized (subnetId.getValue().intern()) {
- Optional<Subnetmap> sn =
- SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
- id);
- if (sn.isPresent()) {
- SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
- if (null != portId && null != builder.getPortList()) {
- List<Uuid> portList = builder.getPortList();
- portList.remove(portId);
- builder.setPortList(portList);
- LOG.debug("Removing port {} from existing subnetmap node: {} ", portId.getValue(),
- subnetId.getValue());
- }
- if (null != directPortId && null != builder.getDirectPortList()) {
- List<Uuid> directPortList = builder.getDirectPortList();
- directPortList.remove(directPortId);
- builder.setDirectPortList(directPortList);
- LOG.debug("Removing direct port {} from existing subnetmap node: {} ", directPortId
- .getValue(), subnetId.getValue());
- }
- subnetmap = builder.build();
- SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id,
- subnetmap);
- } else {
- LOG.info("Trying to remove port from non-existing subnetmap node {}", subnetId.getValue());
+ Optional<Subnetmap> sn =
+ SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ id);
+ if (sn.isPresent()) {
+ SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
+ if (null != portId && null != builder.getPortList()) {
+ List<Uuid> portList = builder.getPortList();
+ portList.remove(portId);
+ builder.setPortList(portList);
+ LOG.debug("Removing port {} from existing subnetmap node: {} ", portId.getValue(),
+ subnetId.getValue());
}
+ if (null != directPortId && null != builder.getDirectPortList()) {
+ List<Uuid> directPortList = builder.getDirectPortList();
+ directPortList.remove(directPortId);
+ builder.setDirectPortList(directPortList);
+ LOG.debug("Removing direct port {} from existing subnetmap node: {} ", directPortId
+ .getValue(), subnetId.getValue());
+ }
+ subnetmap = builder.build();
+ SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id,
+ subnetmap);
+ } else {
+ LOG.info("Trying to remove port from non-existing subnetmap node {}", subnetId.getValue());
}
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("Removing a port from port list of a subnetmap failed for node: {}",
subnetId.getValue(), e);
+ } finally {
+ lock.unlock();
}
return subnetmap;
}
InstanceIdentifier<Subnetmap> subnetMapIdentifier =
InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
LOG.debug("removing subnetMap node: {} ", subnetId.getValue());
+ final ReentrantLock lock = lockForUuid(subnetId);
+ lock.lock();
try {
- synchronized (subnetId.getValue().intern()) {
- SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION,
- subnetMapIdentifier);
- }
+ SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetMapIdentifier);
} catch (TransactionCommitFailedException e) {
LOG.error("Delete subnetMap node failed for subnet : {} ", subnetId.getValue());
+ } finally {
+ lock.unlock();
}
}
}
}
- private void updateVpnMaps(Uuid vpnId, String name, Uuid router, Uuid tenantId, List<Uuid> networks) {
+ protected void updateVpnMaps(Uuid vpnId, @Nullable String name, @Nullable Uuid router, @Nullable Uuid tenantId,
+ @Nullable List<Uuid> networks) {
VpnMapBuilder builder;
boolean isLockAcquired = false;
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class)
}
}
- private void clearFromVpnMaps(Uuid vpnId, Uuid routerId, List<Uuid> networkIds) {
+ private void clearFromVpnMaps(Uuid vpnId, @Nullable Uuid routerId, @Nullable List<Uuid> networkIds) {
boolean isLockAcquired = false;
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class)
.child(VpnMap.class, new VpnMapKey(vpnId))
}
protected Adjacencies createPortIpAdjacencies(Port port, Boolean isRouterInterface,
- WriteTransaction wrtConfigTxn, Subnetmap sn, VpnInterface vpnIface) {
+ TypedWriteTransaction<Configuration> wrtConfigTxn,
+ @Nullable Subnetmap sn, @Nullable VpnInterface vpnIface) {
List<Adjacency> adjList = new ArrayList<>();
if (vpnIface != null) {
adjList = vpnIface.augmentation(Adjacencies.class).getAdjacency();
}
String infName = port.getUuid().getValue();
LOG.trace("neutronVpnManager: create config adjacencies for Port: {}", infName);
- for (FixedIps ip : port.getFixedIps()) {
- String ipValue = String.valueOf(ip.getIpAddress().getValue());
+ for (FixedIps ip : requireNonNullElse(port.getFixedIps(), Collections.<FixedIps>emptyList())) {
+ String ipValue = ip.getIpAddress().stringValue();
String ipPrefix = ip.getIpAddress().getIpv4Address() != null ? ipValue + "/32" : ipValue + "/128";
if (sn != null && !FibHelper.doesPrefixBelongToSubnet(ipPrefix, sn.getSubnetIp(), false)) {
continue;
return new AdjacenciesBuilder().setAdjacency(adjList).build();
}
- protected void createVpnInterface(Collection<Uuid> vpnIds, Port port, WriteTransaction wrtConfigTxn) {
+ protected void createVpnInterface(Collection<Uuid> vpnIds, Port port,
+ @Nullable TypedWriteTransaction<Configuration> wrtConfigTxn) {
boolean isRouterInterface = false;
if (port.getDeviceOwner() != null) {
isRouterInterface = NeutronConstants.DEVICE_OWNER_ROUTER_INF.equals(port.getDeviceOwner());
}
- Adjacencies adjs = createPortIpAdjacencies(port, isRouterInterface, wrtConfigTxn, null, null);
String infName = port.getUuid().getValue();
+ // Handling cluster reboot scenario where VpnInterface already exists in datastore.
+ VpnInterface vpnIface = VpnHelper.getVpnInterface(dataBroker, infName);
+ Adjacencies adjs = createPortIpAdjacencies(port, isRouterInterface, wrtConfigTxn, null, vpnIface);
LOG.trace("createVpnInterface for Port: {}, isRouterInterface: {}", infName, isRouterInterface);
- writeVpnInterfaceToDs(vpnIds, infName, adjs, isRouterInterface, wrtConfigTxn);
+ writeVpnInterfaceToDs(vpnIds, infName, adjs, port.getNetworkId(), isRouterInterface, wrtConfigTxn);
}
protected void withdrawPortIpFromVpnIface(Uuid vpnId, Uuid internetVpnId,
- Port port, Subnetmap sn, WriteTransaction wrtConfigTxn) {
+ Port port, Subnetmap sn, TypedWriteTransaction<Configuration> wrtConfigTxn) {
String infName = port.getUuid().getValue();
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
Optional<VpnInterface> optionalVpnInterface = null;
}
LOG.trace("withdraw adjacencies for Port: {} subnet {}", port.getUuid().getValue(),
sn != null ? sn.getSubnetIp() : "null");
- List<Adjacency> vpnAdjsList = optionalVpnInterface.get().augmentation(Adjacencies.class).getAdjacency();
+ List<Adjacency> vpnAdjsList =
+ requireNonNullElse(optionalVpnInterface.get().augmentation(Adjacencies.class).getAdjacency(),
+ Collections.emptyList());
List<Adjacency> updatedAdjsList = new ArrayList<>();
boolean isIpFromAnotherSubnet = false;
for (Adjacency adj : vpnAdjsList) {
String.valueOf(adjString), wrtConfigTxn);
}
} else {
- if (port.getDeviceOwner()
- .equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF) && sn.getRouterId() != null) {
+ if (NeutronConstants.DEVICE_OWNER_ROUTER_INF.equals(port.getDeviceOwner())
+ && sn.getRouterId() != null) {
Router rtr = neutronvpnUtils.getNeutronRouter(sn.getRouterId());
if (rtr != null && rtr.getRoutes() != null) {
List<Routes> extraRoutesToRemove = new ArrayList<>();
if (vpnId != null) {
updateVpnInterfaceWithAdjacencies(vpnId, infName, adjacencies, wrtConfigTxn);
}
- if (internetVpnId != null) {
- updateVpnInterfaceWithAdjacencies(internetVpnId, infName, adjacencies, wrtConfigTxn);
- }
if (!isIpFromAnotherSubnet) {
// no more subnetworks for neutron port
if (sn != null && sn.getRouterId() != null) {
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
- protected void deleteVpnInterface(String infName, @Nullable String vpnId, WriteTransaction wrtConfigTxn) {
+ protected void deleteVpnInterface(String infName, @Nullable String vpnId,
+ @Nullable TypedWriteTransaction<Configuration> wrtConfigTxn) {
if (wrtConfigTxn == null) {
ListenableFutures.addErrorLogging(
- txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> deleteVpnInterface(infName, vpnId, tx)),
+ txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+ tx -> deleteVpnInterface(infName, vpnId, tx)),
LOG, "Error deleting VPN interface {} {}", infName, vpnId);
return;
}
}
VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get())
.setVpnInstanceNames(vpnList);
- wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIfBuilder
+ wrtConfigTxn.put(vpnIfIdentifier, vpnIfBuilder
.build());
}
}
LOG.debug("Deleting vpn interface {}", infName);
- wrtConfigTxn.delete(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
+ wrtConfigTxn.delete(vpnIfIdentifier);
}
- protected void removeVpnFromVpnInterface(Uuid vpnId, Port port,
- WriteTransaction writeConfigTxn, Subnetmap sm) {
+ protected void removeInternetVpnFromVpnInterface(Uuid vpnId, Port port,
+ TypedWriteTransaction<Configuration> writeConfigTxn,
+ Subnetmap sm) {
if (vpnId == null || port == null) {
return;
}
mipToQuery, infName, vpnId.getValue());
}
}
- List<FixedIps> ips = port.getFixedIps();
- for (FixedIps ip : ips) {
- String ipValue = String.valueOf(ip.getIpAddress().getValue());
+ for (FixedIps ip : requireNonNullElse(port.getFixedIps(), Collections.<FixedIps>emptyList())) {
+ String ipValue = ip.getIpAddress().stringValue();
+ //skip IPv4 address
+ if (!NeutronvpnUtils.getIpVersionFromString(ipValue).isIpVersionChosen(IpVersionChoice.IPV6)) {
+ continue;
+ }
neutronvpnUtils.removeVpnPortFixedIpToPort(vpnId.getValue(),
ipValue, writeConfigTxn);
}
}
deleteVpnInterface(port.getUuid().getValue(), null /* vpn-id */, writeConfigTxn);
} else {
- writeConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIfBuilder
- .build());
+ writeConfigTxn.put(vpnIfIdentifier, vpnIfBuilder.build());
}
} else {
LOG.info("removeVpnFromVpnInterface: VPN Interface {} not found", infName);
}
}
- protected void updateVpnInterface(Uuid vpnId, Uuid oldVpnId, Port port, boolean isBeingAssociated,
- boolean isSubnetIp, WriteTransaction writeConfigTxn) {
+ protected void updateVpnInterface(Uuid vpnId, @Nullable Uuid oldVpnId, Port port, boolean isBeingAssociated,
+ boolean isSubnetIp,
+ TypedWriteTransaction<Configuration> writeConfigTxn,
+ boolean isInternetVpn) {
if (vpnId == null || port == null) {
return;
}
Adjacencies adjacencies = new AdjacenciesBuilder().setAdjacency(adjacencyList).build();
vpnIfBuilder.addAugmentation(Adjacencies.class, adjacencies);
}
- List<FixedIps> ips = port.getFixedIps();
- for (FixedIps ip : ips) {
- String ipValue = String.valueOf(ip.getIpAddress().getValue());
+ for (FixedIps ip : requireNonNullElse(port.getFixedIps(), Collections.<FixedIps>emptyList())) {
+ String ipValue = ip.getIpAddress().stringValue();
if (oldVpnId != null) {
neutronvpnUtils.removeVpnPortFixedIpToPort(oldVpnId.getValue(),
ipValue, writeConfigTxn);
}
+ if ((NeutronvpnUtils.getIpVersionFromString(ipValue) != IpVersionChoice.IPV6)
+ && (isInternetVpn == true)) {
+ continue;
+ }
+
neutronvpnUtils.createVpnPortFixedIpToPort(vpnId.getValue(), ipValue, infName, port
.getMacAddress().getValue(), isSubnetIp, writeConfigTxn);
}
- writeConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIfBuilder
- .build());
+ writeConfigTxn.put(vpnIfIdentifier, vpnIfBuilder.build());
} else {
LOG.error("VPN Interface {} not found", infName);
}
}
}
- public void createL3InternalVpn(Uuid vpn, String name, Uuid tenant, List<String> rd, List<String> irt,
- List<String> ert, Uuid router, List<Uuid> networks) {
+ public void createL3InternalVpn(Uuid vpn, @Nullable String name, @Nullable Uuid tenant, @Nullable List<String> rd,
+ @Nullable List<String> irt, @Nullable List<String> ert, @Nullable Uuid router,
+ @Nullable List<Uuid> networks) {
IpVersionChoice ipVersChoices = neutronvpnUtils.getIpVersionChoicesFromRouterUuid(router);
* @throws Exception if association of L3VPN failed
*/
public void createVpn(Uuid vpnId, String name, Uuid tenantId, List<String> rdList, List<String> irtList,
- List<String> ertList, @Nullable List<Uuid> routerIdsList, List<Uuid> networkList,
+ List<String> ertList, @Nullable List<Uuid> routerIdsList, @Nullable List<Uuid> networkList,
VpnInstance.Type type, long l3vni) throws Exception {
IpVersionChoice ipVersChoices = IpVersionChoice.UNDEFINED;
SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
vpnsIdentifier);
if (optionalVpns.isPresent() && !optionalVpns.get().getVpnInstance().isEmpty()) {
- for (VpnInstance vpn : optionalVpns.get().getVpnInstance()) {
+ for (VpnInstance vpn : requireNonNullElse(optionalVpns.get().getVpnInstance(),
+ Collections.<VpnInstance>emptyList())) {
// eliminating implicitly created (router and VLAN provider external network specific) VPNs
// from getL3VPN output
if (vpn.getIpv4Family().getRouteDistinguisher() != null) {
vpnIdentifier);
// eliminating implicitly created (router or VLAN provider external network specific) VPN from
// getL3VPN output
- if (optionalVpn.isPresent() && (optionalVpn.get().getIpv4Family().getRouteDistinguisher() != null)
- || (optionalVpn.get().getIpv6Family().getRouteDistinguisher() != null)) {
+ if (optionalVpn.isPresent() && optionalVpn.get().getIpv4Family().getRouteDistinguisher() != null
+ || optionalVpn.get().getIpv6Family().getRouteDistinguisher() != null) {
vpns.add(optionalVpn.get());
} else {
result.set(
int failurecount = 0;
int warningcount = 0;
- List<Uuid> vpns = input.getId();
+ List<Uuid> vpns = requireNonNullElse(input.getId(), Collections.emptyList());
for (Uuid vpn : vpns) {
- RpcError error;
- String msg;
try {
LOG.debug("L3VPN delete RPC: VpnID {}", vpn.getValue());
InstanceIdentifier<VpnInstance> vpnIdentifier =
final Boolean isRouterInterface = port.getDeviceOwner()
.equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF) ? true : false;
jobCoordinator.enqueueJob("PORT-" + portId.getValue(), () -> singletonList(
- txRunner.callWithNewWriteOnlyTransactionAndSubmit(wrtConfigTxn -> {
+ txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, wrtConfigTxn -> {
Adjacencies portAdj = createPortIpAdjacencies(port, isRouterInterface, wrtConfigTxn, sn,
vpnIface);
if (vpnIface == null) {
listVpn.add(internetId);
}
writeVpnInterfaceToDs(listVpn,
- vpnInfName, portAdj, isRouterInterface, wrtConfigTxn);
+ vpnInfName, portAdj, port.getNetworkId(), isRouterInterface, wrtConfigTxn);
if (sn.getRouterId() != null) {
addToNeutronRouterInterfacesMap(sn.getRouterId(), portId.getValue());
}
}
}
- protected void removeSubnetFromVpn(final Uuid vpnId, Uuid subnet, Uuid internetVpnId) {
+ protected void removeSubnetFromVpn(final Uuid vpnId, Uuid subnet, @Nullable Uuid internetVpnId) {
Preconditions.checkArgument(vpnId != null || internetVpnId != null,
"removeSubnetFromVpn: at least one VPN must be not null");
LOG.debug("Removing subnet {} from vpn {}/{}", subnet.getValue(),
LOG.debug("withdrawing subnet IP {} from vpn-interface {}", sn.getSubnetIp(), portId.getValue());
final Port port = neutronvpnUtils.getNeutronPort(portId);
jobCoordinator.enqueueJob("PORT-" + portId.getValue(),
- () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
- if (port != null) {
- withdrawPortIpFromVpnIface(vpnId, internetId, port, sn, tx);
- } else {
- LOG.warn(
- "Cannot proceed with withdrawPortIpFromVpnIface for port {} in subnet {} since "
- + "port is absent in Neutron config DS", portId.getValue(),
- subnet.getValue());
- }
- })));
+ () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+ CONFIGURATION, tx -> {
+ if (port != null) {
+ withdrawPortIpFromVpnIface(vpnId, internetId, port, sn, tx);
+ } else {
+ LOG.warn(
+ "Cannot proceed with withdrawPortIpFromVpnIface for port {} in subnet {} since "
+ + "port is absent in Neutron config DS", portId.getValue(),
+ subnet.getValue());
+ }
+ })));
}
}
//update subnet-vpn association
}
jobCoordinator.enqueueJob("VPN-" + vpn.getValue(), () -> singletonList(
- txRunner.callWithNewWriteOnlyTransactionAndSubmit(wrtConfigTxn -> {
+ txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, wrtConfigTxn -> {
if (isBeingAssociated) {
updateVpnInterface(vpn, null, neutronvpnUtils.getNeutronPort(
- sm.getRouterInterfacePortId()), true, true, wrtConfigTxn);
+ sm.getRouterInterfacePortId()), true, true, wrtConfigTxn, true);
} else {
- removeVpnFromVpnInterface(vpn, neutronvpnUtils.getNeutronPort(sm.getRouterInterfacePortId()),
- wrtConfigTxn, sm);
+ removeInternetVpnFromVpnInterface(vpn,
+ neutronvpnUtils.getNeutronPort(sm.getRouterInterfacePortId()), wrtConfigTxn, sm);
}
}
)));
LOG.debug("Updating vpn-interface for port {} isBeingAssociated {}",
port.getValue(), isBeingAssociated);
jobCoordinator.enqueueJob("PORT-" + port.getValue(),
- () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
- if (isBeingAssociated) {
- updateVpnInterface(vpn, null, neutronvpnUtils.getNeutronPort(port),
- true, false, tx);
- } else {
- removeVpnFromVpnInterface(vpn, neutronvpnUtils.getNeutronPort(port), tx, sm);
- }
- })));
+ () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+ tx -> {
+ if (isBeingAssociated) {
+ updateVpnInterface(vpn, null, neutronvpnUtils.getNeutronPort(port),
+ true, false, tx, true);
+ } else {
+ removeInternetVpnFromVpnInterface(vpn, neutronvpnUtils.getNeutronPort(port), tx, sm);
+ }
+ })));
}
}
}
+ @Nullable
private Subnetmap updateVpnForSubnet(Uuid oldVpnId, Uuid newVpnId, Uuid subnet, boolean isBeingAssociated) {
LOG.debug("Moving subnet {} from oldVpn {} to newVpn {} ", subnet.getValue(),
oldVpnId.getValue(), newVpnId.getValue());
LOG.error("Updating subnet {} with newVpn {} failed", subnet.getValue(), newVpnId.getValue());
return sn;
}
-
+ /* vpnExtUuid will contain the value only on if the subnet is V6 and it is already been
+ * associated with internet BGP-VPN.
+ */
+ if (vpnExtUuid != null) {
+ /* Update V6 Internet default route match with new VPN metadata.
+ * isBeingAssociated = true means oldVpnId is same as routerId
+ * isBeingAssociated = false means newVpnId is same as routerId
+ */
+ if (isBeingAssociated) {
+ neutronvpnUtils.updateVpnInstanceWithFallback(oldVpnId, vpnExtUuid, true);
+ } else {
+ neutronvpnUtils.updateVpnInstanceWithFallback(newVpnId, vpnExtUuid, true);
+ }
+ }
//Update Router Interface first synchronously.
//CAUTION: Please DONOT make the router interface VPN Movement as an asynchronous commit again !
ListenableFuture<Void> future =
- txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> updateVpnInterface(newVpnId, oldVpnId,
+ txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+ tx -> updateVpnInterface(newVpnId, oldVpnId,
neutronvpnUtils.getNeutronPort(sn.getRouterInterfacePortId()),
- isBeingAssociated, true, tx));
+ isBeingAssociated, true, tx, false));
Futures.addCallback(future, new FutureCallback<Void>() {
@Override
public void onSuccess(Void result) {
LOG.debug("Updating vpn-interface for port {} isBeingAssociated {}",
port.getValue(), isBeingAssociated);
jobCoordinator.enqueueJob("PORT-" + port.getValue(), () -> Collections.singletonList(
- txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+ txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
tx -> updateVpnInterface(newVpnId, oldVpnId,
neutronvpnUtils.getNeutronPort(port), isBeingAssociated, false,
- tx))));
+ tx, false))));
}
}
}
}
protected void addToNeutronRouterInterfacesMap(Uuid routerId, String interfaceName) {
- synchronized (routerId.getValue().intern()) {
- InstanceIdentifier<RouterInterfaces> routerInterfacesId = getRouterInterfacesId(routerId);
- try {
- Optional<RouterInterfaces> optRouterInterfaces =
- SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
- routerInterfacesId);
- Interfaces routerInterface = new InterfacesBuilder().withKey(new InterfacesKey(interfaceName))
+ final InstanceIdentifier<RouterInterfaces> routerInterfacesId = getRouterInterfacesId(routerId);
+ final ReentrantLock lock = lockForUuid(routerId);
+ lock.lock();
+ try {
+ Optional<RouterInterfaces> optRouterInterfaces =
+ SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ routerInterfacesId);
+ Interfaces routerInterface = new InterfacesBuilder().withKey(new InterfacesKey(interfaceName))
.setInterfaceId(interfaceName).build();
- if (optRouterInterfaces.isPresent()) {
- SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
- routerInterfacesId.child(Interfaces.class, new InterfacesKey(interfaceName)),
- routerInterface);
- } else {
- // TODO Shouldn't we be doing something with builder and interfaces?
-// RouterInterfacesBuilder builder = new RouterInterfacesBuilder().setRouterId(routerId);
-// List<Interfaces> interfaces = new ArrayList<>();
-// interfaces.add(routerInterface);
+ if (optRouterInterfaces.isPresent()) {
+ SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ routerInterfacesId.child(Interfaces.class, new InterfacesKey(interfaceName)), routerInterface);
+ } else {
+ // TODO Shouldn't we be doing something with builder and interfaces?
+ // RouterInterfacesBuilder builder = new RouterInterfacesBuilder().setRouterId(routerId);
+ // List<Interfaces> interfaces = new ArrayList<>();
+ // interfaces.add(routerInterface);
- SingleTransactionDataBroker.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION,
- routerInterfacesId.child(Interfaces.class, new InterfacesKey(interfaceName)),
- routerInterface);
- }
- } catch (ReadFailedException | TransactionCommitFailedException e) {
- LOG.error("Error reading router interfaces for {}", routerInterfacesId, e);
+ SingleTransactionDataBroker.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ routerInterfacesId.child(Interfaces.class, new InterfacesKey(interfaceName)), routerInterface);
}
+ } catch (ReadFailedException | TransactionCommitFailedException e) {
+ LOG.error("Error reading router interfaces for {}", routerInterfacesId, e);
+ } finally {
+ lock.unlock();
}
}
protected void removeFromNeutronRouterInterfacesMap(Uuid routerId, String interfaceName) {
- synchronized (routerId.getValue().intern()) {
- InstanceIdentifier<RouterInterfaces> routerInterfacesId = getRouterInterfacesId(routerId);
- try {
- Optional<RouterInterfaces> optRouterInterfaces =
- SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
- routerInterfacesId);
- Interfaces routerInterface = new InterfacesBuilder().withKey(new InterfacesKey(interfaceName))
+ final InstanceIdentifier<RouterInterfaces> routerInterfacesId = getRouterInterfacesId(routerId);
+ final ReentrantLock lock = lockForUuid(routerId);
+ lock.lock();
+ try {
+ Optional<RouterInterfaces> optRouterInterfaces =
+ SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ routerInterfacesId);
+ Interfaces routerInterface = new InterfacesBuilder().withKey(new InterfacesKey(interfaceName))
.setInterfaceId(interfaceName).build();
- if (optRouterInterfaces.isPresent()) {
- RouterInterfaces routerInterfaces = optRouterInterfaces.get();
- List<Interfaces> interfaces = routerInterfaces.getInterfaces();
- if (interfaces != null && interfaces.remove(routerInterface)) {
- if (interfaces.isEmpty()) {
- SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION,
- routerInterfacesId);
- } else {
- SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION,
- routerInterfacesId.child(Interfaces.class, new InterfacesKey(interfaceName)));
- }
+ if (optRouterInterfaces.isPresent()) {
+ RouterInterfaces routerInterfaces = optRouterInterfaces.get();
+ List<Interfaces> interfaces = routerInterfaces.getInterfaces();
+ if (interfaces != null && interfaces.remove(routerInterface)) {
+ if (interfaces.isEmpty()) {
+ SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ routerInterfacesId);
+ } else {
+ SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ routerInterfacesId.child(Interfaces.class, new InterfacesKey(interfaceName)));
}
}
- } catch (ReadFailedException | TransactionCommitFailedException e) {
- LOG.error("Error reading the router interfaces for {}", routerInterfacesId, e);
}
+ } catch (ReadFailedException | TransactionCommitFailedException e) {
+ LOG.error("Error reading the router interfaces for {}", routerInterfacesId, e);
+ } finally {
+ lock.unlock();
}
}
public void addInterVpnRoutes(Uuid vpnName, List<Routes> interVpnLinkRoutes,
HashMap<String, InterVpnLink> nexthopsXinterVpnLinks) {
for (Routes route : interVpnLinkRoutes) {
- String nexthop = String.valueOf(route.getNexthop().getValue());
- String destination = String.valueOf(route.getDestination().getValue());
+ String nexthop = route.getNexthop().stringValue();
+ String destination = route.getDestination().stringValue();
InterVpnLink interVpnLink = nexthopsXinterVpnLinks.get(nexthop);
if (isNexthopTheOtherVpnLinkEndpoint(nexthop, vpnName.getValue(), interVpnLink)) {
AddStaticRouteInput rpcInput =
} else {
// Any other case is a fault.
LOG.warn("route with destination {} and nexthop {} does not apply to any InterVpnLink",
- String.valueOf(route.getDestination().getValue()), nexthop);
+ route.getDestination().stringValue(), nexthop);
continue;
}
}
public void removeInterVpnRoutes(Uuid vpnName, List<Routes> interVpnLinkRoutes,
HashMap<String, InterVpnLink> nexthopsXinterVpnLinks) {
for (Routes route : interVpnLinkRoutes) {
- String nexthop = String.valueOf(route.getNexthop().getValue());
- String destination = String.valueOf(route.getDestination().getValue());
+ String nexthop = route.getNexthop().stringValue();
+ String destination = route.getDestination().stringValue();
InterVpnLink interVpnLink = nexthopsXinterVpnLinks.get(nexthop);
if (isNexthopTheOtherVpnLinkEndpoint(nexthop, vpnName.getValue(), interVpnLink)) {
RemoveStaticRouteInput rpcInput =
} else {
// Any other case is a fault.
LOG.warn("route with destination {} and nexthop {} does not apply to any InterVpnLink",
- String.valueOf(route.getDestination().getValue()), nexthop);
+ route.getDestination().stringValue(), nexthop);
continue;
}
}
if (route == null || route.getNexthop() == null || route.getDestination() == null) {
LOG.error("Incorrect input received for extra route. {}", route);
} else {
- String nextHop = String.valueOf(route.getNexthop().getValue());
- String destination = String.valueOf(route.getDestination().getValue());
+ String nextHop = route.getNexthop().stringValue();
+ String destination = route.getDestination().stringValue();
if (!nextHop.equals(fixedIp)) {
LOG.trace("FixedIP {} is not extra route nexthop for destination {}", fixedIp, destination);
continue;
if (route == null || route.getNexthop() == null || route.getDestination() == null) {
LOG.error("Incorrect input received for extra route. {}", route);
} else {
- String nextHop = String.valueOf(route.getNexthop().getValue());
- String destination = String.valueOf(route.getDestination().getValue());
+ String nextHop = route.getNexthop().stringValue();
+ String destination = route.getDestination().stringValue();
String infName = neutronvpnUtils.getNeutronPortNameFromVpnPortFixedIp(vpnId.getValue(),
nextHop);
if (infName != null) {
}
for (Routes route : routeList) {
// count the number of nexthops for each same route.getDestingation().getValue()
- String destination = String.valueOf(route.getDestination().getValue());
- String nextHop = String.valueOf(route.getNexthop().getValue());
- List<String> nextHopList = new ArrayList();
+ String destination = route.getDestination().stringValue();
+ String nextHop = route.getNexthop().stringValue();
+ List<String> nextHopList = new ArrayList<>();
nextHopList.add(nextHop);
int nbNextHops = 0;
for (Routes routeTmp : routeList) {
- String routeDest = String.valueOf(routeTmp.getDestination().getValue());
+ String routeDest = routeTmp.getDestination().stringValue();
if (!destination.equals(routeDest)) {
continue;
}
- String routeNextH = String.valueOf(routeTmp.getNexthop().getValue());
+ String routeNextH = routeTmp.getNexthop().stringValue();
if (nextHop.equals(routeNextH)) {
continue;
}
nbNextHops++;
- nextHopList.add(new String(routeTmp.getNexthop().getValue()));
+ nextHopList.add(routeTmp.getNexthop().stringValue());
}
final List<String> rdList = new ArrayList<>();
if (vpnInstance.getIpv4Family() != null
// 4. Prefix in question
detailsAlarm.append(" for prefix: ");
- detailsAlarm.append(route.getDestination().getValue());
+ detailsAlarm.append(route.getDestination().stringValue());
// 5. List of NHs for the prefix
detailsAlarm.append(" for nextHops: ");
for (Routes route : routeList) {
if (route != null && route.getNexthop() != null && route.getDestination() != null) {
boolean isLockAcquired = false;
- String nextHop = String.valueOf(route.getNexthop().getValue());
- String destination = String.valueOf(route.getDestination().getValue());
+ String nextHop = route.getNexthop().stringValue();
+ String destination = route.getDestination().stringValue();
String infName = neutronvpnUtils.getNeutronPortNameFromVpnPortFixedIp(vpnId.getValue(),
nextHop);
if (infName == null) {
// read VPNMaps
VpnMap vpnMap = neutronvpnUtils.getVpnMap(vpnId);
List<RouterIds> routerIdsList = vpnMap != null ? vpnMap.getRouterIds() : null;
+ List<Uuid> routerUuidList = new ArrayList<>();
// dissociate router
if (routerIdsList != null && !routerIdsList.isEmpty()) {
- for (RouterIds routerId : routerIdsList) {
- dissociateRouterFromVpn(vpnId, routerId.getRouterId());
- }
- List<Uuid> rtrIdsList = routerIdsList.stream().map(routerId -> routerId.getRouterId())
- .collect(Collectors.toList());
- if (rtrIdsList.contains(vpnId) && vpnMap.getNetworkIds() != null) {
- // dissociate networks
- dissociateNetworksFromVpn(vpnId, vpnMap.getNetworkIds());
+ for (RouterIds router : routerIdsList) {
+ Uuid routerId = router.getRouterId();
+ routerUuidList.add(routerId);
+ dissociateRouterFromVpn(vpnId, routerId);
}
}
+ if (!routerUuidList.contains(vpnId) && vpnMap.getNetworkIds() != null) {
+ dissociateNetworksFromVpn(vpnId, vpnMap.getNetworkIds());
+ }
// remove entire vpnMaps node
deleteVpnMapsNode(vpnId);
@SuppressWarnings("checkstyle:IllegalCatch")
protected void associateRouterToVpn(Uuid vpnId, Uuid routerId) {
updateVpnMaps(vpnId, null, routerId, null, null);
- LOG.debug("Updating association of subnets to external vpn {}", vpnId.getValue());
- List<Uuid> routerSubnets = neutronvpnUtils.getNeutronRouterSubnetIds(routerId);
- for (Uuid subnetId : routerSubnets) {
- Subnetmap sn = updateVpnForSubnet(routerId, vpnId, subnetId, true);
- if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToAdd(sn, vpnId)) {
- neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(),
- NeutronvpnUtils.getIpVersionFromString(sn.getSubnetIp()), true);
+ LOG.debug("associateRouterToVpn: Updating association of subnets to external vpn {}", vpnId.getValue());
+ List<Subnetmap> subMapList = neutronvpnUtils.getNeutronRouterSubnetMapList(routerId);
+ IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
+ for (Subnetmap sn : subMapList) {
+ IpVersionChoice ipVers = neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp());
+ if (!ipVersion.isIpVersionChosen(ipVers)) {
+ ipVersion = ipVersion.addVersion(ipVers);
}
}
-
- try {
- checkAndPublishRouterAssociatedtoVpnNotification(routerId, vpnId);
- LOG.debug("notification upon association of router {} to VPN {} published", routerId.getValue(),
- vpnId.getValue());
- } catch (Exception e) {
- LOG.error("publishing of notification upon association of router {} to VPN {} failed : ", routerId
- .getValue(), vpnId.getValue(), e);
+ if (ipVersion != IpVersionChoice.UNDEFINED) {
+ LOG.debug("associateRouterToVpn: Updating vpnInstanceOpDataEntrywith ip address family {} for VPN {} ",
+ ipVersion, vpnId);
+ neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion, true);
+ }
+ for (Subnetmap sn : subMapList) {
+ updateVpnForSubnet(routerId, vpnId, sn.getId(), true);
}
}
@SuppressWarnings("checkstyle:IllegalCatch")
protected void dissociateRouterFromVpn(Uuid vpnId, Uuid routerId) {
- List<Uuid> routerSubnets = neutronvpnUtils.getNeutronRouterSubnetIds(routerId);
- boolean vpnInstanceIpVersionsRemoved = false;
- IpVersionChoice vpnInstanceIpVersionsToRemove = IpVersionChoice.UNDEFINED;
- for (Uuid subnetId : routerSubnets) {
- Subnetmap sn = neutronvpnUtils.getSubnetmap(subnetId);
- if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sn, vpnId)) {
- vpnInstanceIpVersionsToRemove = vpnInstanceIpVersionsToRemove.addVersion(NeutronvpnUtils
- .getIpVersionFromString(sn.getSubnetIp()));
- vpnInstanceIpVersionsRemoved = true;
+ clearFromVpnMaps(vpnId, routerId, null);
+ List<Subnetmap> subMapList = neutronvpnUtils.getNeutronRouterSubnetMapList(routerId);
+ IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
+ for (Subnetmap sn : subMapList) {
+ IpVersionChoice ipVers = NeutronvpnUtils.getIpVersionFromString(sn.getSubnetIp());
+ if (ipVersion.isIpVersionChosen(ipVers)) {
+ ipVersion = ipVersion.addVersion(ipVers);
}
- LOG.debug("Updating association of subnets to internal vpn {}", routerId.getValue());
- updateVpnForSubnet(vpnId, routerId, subnetId, false);
+ LOG.debug("dissociateRouterFromVpn: Updating association of subnets to internal vpn {}",
+ routerId.getValue());
+ updateVpnForSubnet(vpnId, routerId, sn.getId(), false);
}
-
- if (vpnInstanceIpVersionsRemoved) {
- neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), vpnInstanceIpVersionsToRemove, false);
- }
- clearFromVpnMaps(vpnId, routerId, null);
- try {
- checkAndPublishRouterDisassociatedFromVpnNotification(routerId, vpnId);
- LOG.debug("notification upon disassociation of router {} from VPN {} published", routerId.getValue(),
- vpnId.getValue());
- } catch (Exception e) {
- LOG.error("publishing of notification upon disassociation of router {} from VPN {} failed : ", routerId
- .getValue(), vpnId.getValue(), e);
+ if (ipVersion != IpVersionChoice.UNDEFINED) {
+ LOG.debug("dissociateRouterFromVpn; Updating vpnInstanceOpDataEntry with ip address family {} for VPN {} ",
+ ipVersion, vpnId);
+ neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion,
+ false);
}
}
protected List<String> associateNetworksToVpn(@Nonnull Uuid vpnId, @Nonnull List<Uuid> networkList) {
List<String> failedNwList = new ArrayList<>();
HashSet<Uuid> passedNwList = new HashSet<>();
+ boolean isExternalNetwork = false;
if (networkList.isEmpty()) {
LOG.error("associateNetworksToVpn: Failed as given networks list is empty, VPN Id: {}", vpnId.getValue());
failedNwList.add(String.format("Failed to associate networks with VPN %s as given networks list is empty",
+ "associated with", vpnId.getValue()));
return failedNwList;
}
+ Set<VpnTarget> routeTargets = vpnManager.getRtListForVpn(vpnId.getValue());
for (Uuid nw : networkList) {
Network network = neutronvpnUtils.getNeutronNetwork(nw);
if (network == null) {
+ "another VPN %s", nw.getValue(), networkVpnId.getValue()));
continue;
}
- if (neutronvpnUtils.getIsExternal(network) && !associateExtNetworkToVpn(vpnId, network)) {
+ if (NeutronvpnUtils.getIsExternal(network) && !associateExtNetworkToVpn(vpnId, network)) {
LOG.error("associateNetworksToVpn: Failed to associate Provider Network {} with VPN {}",
nw.getValue(), vpnId.getValue());
failedNwList.add(String.format("Failed to associate Provider Network %s with VPN %s",
nw.getValue(), vpnId.getValue()));
continue;
}
- List<Uuid> networkSubnets = neutronvpnUtils.getSubnetIdsFromNetworkId(nw);
- if (networkSubnets == null) {
+ if (NeutronvpnUtils.getIsExternal(network)) {
+ isExternalNetwork = true;
+ }
+ List<Subnetmap> subnetmapList = neutronvpnUtils.getSubnetmapListFromNetworkId(nw);
+ if (subnetmapList == null || subnetmapList.isEmpty()) {
passedNwList.add(nw);
continue;
}
- for (Uuid subnet : networkSubnets) {
- Uuid subnetVpnId = neutronvpnUtils.getVpnForSubnet(subnet);
+ if (vpnManager.checkForOverlappingSubnets(nw, subnetmapList, vpnId, routeTargets, failedNwList)) {
+ continue;
+ }
+ IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
+ for (Subnetmap subnetmap : subnetmapList) {
+ IpVersionChoice ipVers = neutronvpnUtils.getIpVersionFromString(subnetmap.getSubnetIp());
+ if (!ipVersion.isIpVersionChosen(ipVers)) {
+ ipVersion = ipVersion.addVersion(ipVers);
+ }
+ }
+ if (ipVersion != IpVersionChoice.UNDEFINED) {
+ LOG.debug("associateNetworksToVpn: Updating vpnInstanceOpDataEntry with ip address family {}"
+ + " for VPN {} ", ipVersion, vpnId);
+ neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion, true);
+ }
+ for (Subnetmap subnetmap : subnetmapList) {
+ Uuid subnetId = subnetmap.getId();
+ Uuid subnetVpnId = neutronvpnUtils.getVpnForSubnet(subnetId);
if (subnetVpnId != null) {
- LOG.error("associateNetworksToVpn: Failed to associate subnet {} with VPN {} as it is already "
- + "associated", subnet.getValue(), subnetVpnId.getValue());
- failedNwList.add(String.format("Failed to associate subnet %s with VPN %s as it is already "
- + "associated", subnet.getValue(), vpnId.getValue()));
+ LOG.error("associateNetworksToVpn: Failed to associate subnet {} with VPN {}"
+ + " as it is already associated", subnetId.getValue(), subnetVpnId.getValue());
+ failedNwList.add(String.format("Failed to associate subnet %s with VPN %s"
+ + " as it is already associated", subnetId.getValue(), vpnId.getValue()));
continue;
}
- Subnetmap sm = neutronvpnUtils.getSubnetmap(subnet);
- if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToAdd(sm, vpnId)) {
- neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(),
- NeutronvpnUtils.getIpVersionFromString(sm.getSubnetIp()), true);
- }
- if (!neutronvpnUtils.getIsExternal(network)) {
- LOG.debug("associateNetworksToVpn: Add subnet {} to VPN {}", subnet.getValue(),
+ if (!NeutronvpnUtils.getIsExternal(network)) {
+ LOG.debug("associateNetworksToVpn: Add subnet {} to VPN {}", subnetId.getValue(),
vpnId.getValue());
- addSubnetToVpn(vpnId, subnet, null);
+ addSubnetToVpn(vpnId, subnetId, null);
+ vpnManager.updateRouteTargetsToSubnetAssociation(routeTargets, subnetmap.getSubnetIp(),
+ vpnId.getValue());
+ passedNwList.add(nw);
}
}
passedNwList.add(nw);
failedNwList.add(String.format("Failed to associate VPN %s with networks %s: %s", vpnId.getValue(),
networkList, e));
}
- updateVpnMaps(vpnId, null, null, null, new ArrayList<>(passedNwList));
+ //VpnMap update for ext-nw is already done in associateExtNetworkToVpn() method.
+ if (!isExternalNetwork) {
+ updateVpnMaps(vpnId, null, null, null, new ArrayList<>(passedNwList));
+ }
LOG.info("Network(s) {} associated to L3VPN {} successfully", passedNwList.toString(), vpnId.getValue());
return failedNwList;
}
private boolean associateExtNetworkToVpn(@Nonnull Uuid vpnId, @Nonnull Network extNet) {
+ if (!addExternalNetworkToVpn(extNet, vpnId)) {
+ return false;
+ }
VpnInstanceOpDataEntry vpnOpDataEntry = neutronvpnUtils.getVpnInstanceOpDataEntryFromVpnId(vpnId.getValue());
if (vpnOpDataEntry == null) {
LOG.error("associateExtNetworkToVpn: can not find VpnOpDataEntry for VPN {}", vpnId.getValue());
return false;
}
- if (!addExternalNetworkToVpn(extNet, vpnId)) {
- return false;
- }
if (!vpnOpDataEntry.getBgpvpnType().equals(BgpvpnType.BGPVPNInternet)) {
LOG.info("associateExtNetworkToVpn: set type {} for VPN {}", BgpvpnType.BGPVPNInternet, vpnId.getValue());
neutronvpnUtils.updateVpnInstanceOpWithType(BgpvpnType.BGPVPNInternet, vpnId);
}
- for (Uuid snId: neutronvpnUtils.getPrivateSubnetsToExport(extNet)) {
+ //Update VpnMap with ext-nw is needed first before processing V6 internet default fallback flows
+ List<Uuid> extNwList = Collections.singletonList(extNet.key().getUuid());
+ updateVpnMaps(vpnId, null, null, null, extNwList);
+ IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
+ for (Uuid snId: neutronvpnUtils.getPrivateSubnetsToExport(extNet, vpnId)) {
Subnetmap sm = neutronvpnUtils.getSubnetmap(snId);
if (sm == null) {
LOG.error("associateExtNetworkToVpn: can not find subnet with Id {} in ConfigDS", snId.getValue());
continue;
}
- updateVpnInternetForSubnet(sm, vpnId, true);
- if (!vpnOpDataEntry.isIpv6Configured()
- && NeutronvpnUtils.getIpVersionFromString(sm.getSubnetIp()) == IpVersionChoice.IPV6) {
- LOG.info("associateExtNetworkToVpn: add IPv6 Internet default route in VPN {}", vpnId.getValue());
- neutronvpnUtils.updateVpnInstanceWithFallback(vpnId.getValue(), true);
+ IpVersionChoice ipVers = NeutronvpnUtils.getIpVersionFromString(sm.getSubnetIp());
+ if (ipVers.isIpVersionChosen(IpVersionChoice.IPV4)) {
+ continue;
+ }
+ if (ipVers.isIpVersionChosen(IpVersionChoice.IPV6)) {
+ updateVpnInternetForSubnet(sm, vpnId, true);
}
+ if (!ipVersion.isIpVersionChosen(ipVers)) {
+ ipVersion = ipVersion.addVersion(ipVers);
+ }
+ }
+ if (ipVersion != IpVersionChoice.UNDEFINED) {
+ neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), IpVersionChoice.IPV6, true);
+ LOG.info("associateExtNetworkToVpn: add IPv6 Internet default route in VPN {}", vpnId.getValue());
+ neutronvpnUtils.updateVpnInstanceWithFallback(/*routerId*/ null, vpnId, true);
}
return true;
}
return failedNwList;
}
for (Uuid nw : networkList) {
+ List<Uuid> networkSubnets = neutronvpnUtils.getSubnetIdsFromNetworkId(nw);
+ if (networkSubnets == null) {
+ passedNwList.add(nw);
+ continue;
+ }
Network network = neutronvpnUtils.getNeutronNetwork(nw);
if (network == null) {
LOG.error("dissociateNetworksFromVpn: Network {} not found in ConfigDS");
if (NeutronvpnUtils.getIsExternal(network)) {
if (disassociateExtNetworkFromVpn(vpnId, network)) {
passedNwList.add(nw);
- continue;
} else {
LOG.error("dissociateNetworksFromVpn: Failed to withdraw Provider Network {} from VPN {}",
nw.getValue(), vpnId.getValue());
continue;
}
}
- List<Uuid> networkSubnets = neutronvpnUtils.getSubnetIdsFromNetworkId(nw);
- if (networkSubnets == null) {
- passedNwList.add(nw);
- continue;
- }
+ IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
for (Uuid subnet : networkSubnets) {
- Subnetmap sm = neutronvpnUtils.getSubnetmap(subnet);
- if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sm, vpnId)) {
- IpVersionChoice ipVersionsToRemove = IpVersionChoice.UNDEFINED;
- IpVersionChoice ipVersion = NeutronvpnUtils.getIpVersionFromString(sm.getSubnetIp());
- neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(),
- ipVersionsToRemove.addVersion(ipVersion), false);
- }
- LOG.debug("dissociateNetworksFromVpn: Withdraw subnet {} from VPN {}", subnet.getValue(),
- vpnId.getValue());
- removeSubnetFromVpn(vpnId, subnet, null);
- passedNwList.add(nw);
+ Subnetmap subnetmap = neutronvpnUtils.getSubnetmap(subnet);
+ IpVersionChoice ipVers = NeutronvpnUtils.getIpVersionFromString(subnetmap.getSubnetIp());
+ if (!ipVersion.isIpVersionChosen(ipVers)) {
+ ipVersion = ipVersion.addVersion(ipVers);
+ }
+ if (!NeutronvpnUtils.getIsExternal(network)) {
+ LOG.debug("dissociateNetworksFromVpn: Withdraw subnet {} from VPN {}", subnet.getValue(),
+ vpnId.getValue());
+ removeSubnetFromVpn(vpnId, subnet, null);
+ Set<VpnTarget> routeTargets = vpnManager.getRtListForVpn(vpnId.getValue());
+ vpnManager.removeRouteTargetsToSubnetAssociation(routeTargets, subnetmap.getSubnetIp(),
+ vpnId.getValue());
+ passedNwList.add(nw);
+ }
+ }
+ if (ipVersion != IpVersionChoice.UNDEFINED) {
+ LOG.debug("dissociateNetworksFromVpn: Updating vpnInstanceOpDataEntryupdate with ip address family {}"
+ + " for VPN {}", ipVersion, vpnId);
+ neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), ipVersion, false);
}
}
clearFromVpnMaps(vpnId, null, new ArrayList<>(passedNwList));
- LOG.info("Network(s) {} disassociated from L3VPN {} successfully", passedNwList.toString(),
- vpnId.getValue());
+ LOG.info("dissociateNetworksFromVpn: Network(s) {} disassociated from L3VPN {} successfully",
+ passedNwList.toString(), vpnId.getValue());
return failedNwList;
}
// check, if there is another Provider Networks associated with given VPN
List<Uuid> vpnNets = getNetworksForVpn(vpnId);
if (vpnNets != null) {
+ //Remove currently disassociated network from the list
+ vpnNets.remove(extNet.getUuid());
for (Uuid netId : vpnNets) {
if (NeutronvpnUtils.getIsExternal(getNeutronNetwork(netId))) {
LOG.error("dissociateExtNetworkFromVpn: Internet VPN {} is still associated with Provider Network "
}
}
}
+ //Set VPN Type is BGPVPNExternal from BGPVPNInternet
LOG.info("disassociateExtNetworkFromVpn: set type {} for VPN {}",
VpnInstanceOpDataEntry.BgpvpnType.BGPVPNExternal, vpnId.getValue());
neutronvpnUtils.updateVpnInstanceOpWithType(VpnInstanceOpDataEntry.BgpvpnType.BGPVPNExternal, vpnId);
- for (Uuid snId : neutronvpnUtils.getPrivateSubnetsToExport(extNet)) {
+ IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
+ for (Uuid snId : neutronvpnUtils.getPrivateSubnetsToExport(extNet, vpnId)) {
Subnetmap sm = neutronvpnUtils.getSubnetmap(snId);
if (sm == null) {
LOG.error("disassociateExtNetworkFromVpn: can not find subnet with Id {} in ConfigDS", snId.getValue());
continue;
}
- updateVpnInternetForSubnet(sm, vpnId, false);
+ IpVersionChoice ipVers = NeutronvpnUtils.getIpVersionFromString(sm.getSubnetIp());
+ if (ipVers.isIpVersionChosen(IpVersionChoice.IPV4)) {
+ continue;
+ }
+ if (ipVers.isIpVersionChosen(IpVersionChoice.IPV6)) {
+ updateVpnInternetForSubnet(sm, vpnId, false);
+ }
+ if (!ipVersion.isIpVersionChosen(ipVers)) {
+ ipVersion = ipVersion.addVersion(ipVers);
+ }
+ }
+ if (ipVersion != IpVersionChoice.UNDEFINED) {
+ neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), IpVersionChoice.IPV6, false);
+ LOG.info("disassociateExtNetworkFromVpn: withdraw IPv6 Internet default route from VPN {}",
+ vpnId.getValue());
+ neutronvpnUtils.updateVpnInstanceWithFallback(/*routerId*/ null, vpnId, false);
}
- neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), IpVersionChoice.IPV6, false);
- LOG.info("disassociateExtNetworkFromVpn: withdraw IPv6 Internet default route from VPN {}", vpnId.getValue());
- neutronvpnUtils.updateVpnInstanceWithFallback(vpnId.getValue(), false);
return true;
}
List<String> fixedIPList = new ArrayList<>();
Port port = neutronvpnUtils.getNeutronPort(portId);
if (port != null) {
- List<FixedIps> fixedIPs = port.getFixedIps();
- for (FixedIps ip : fixedIPs) {
- fixedIPList.add(String.valueOf(ip.getIpAddress().getValue()));
+ for (FixedIps ip : requireNonNullElse(port.getFixedIps(), Collections.<FixedIps>emptyList())) {
+ fixedIPList.add(ip.getIpAddress().stringValue());
}
} else {
returnMsg.append("neutron port: ").append(portId.getValue()).append(" not found");
return neutronvpnUtils.getNeutronSubnet(subnetId);
}
+ @Nullable
protected IpAddress getNeutronSubnetGateway(Uuid subnetId) {
Subnet sn = neutronvpnUtils.getNeutronSubnet(subnetId);
if (null != sn) {
result.add("-------------------------------------------------------------------------------------------");
InstanceIdentifier<Ports> portidentifier = InstanceIdentifier.create(Neutron.class).child(Ports.class);
- Optional<Ports> ports = syncReadOptional(dataBroker, CONFIGURATION, portidentifier);
+ Optional<Ports> ports = syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, portidentifier);
if (ports.isPresent() && ports.get().getPort() != null) {
- for (Port port : ports.get().getPort()) {
+ for (Port port : requireNonNullElse(ports.get().getPort(), Collections.<Port>emptyList())) {
List<FixedIps> fixedIPs = port.getFixedIps();
if (fixedIPs != null && !fixedIPs.isEmpty()) {
List<String> ipList = new ArrayList<>();
result.add("");
result.add("------------------------------------------------------------------------------------");
result.add("");
- List<L3vpnInstances> vpnList = rpcResult.getResult().getL3vpnInstances();
- for (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn
- .rev150602.VpnInstance vpn : vpnList) {
+ for (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.VpnInstance vpn :
+ requireNonNullElse(rpcResult.getResult().getL3vpnInstances(),
+ Collections.<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602
+ .VpnInstance>emptyList())) {
String tenantId = vpn.getTenantId() != null ? vpn.getTenantId().getValue()
: "\" " + " \"";
result.add(String.format(" %-37s %-37s %-7s ", vpn.getId().getValue(), tenantId,
return;
}
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+ ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
for (String elanInterface : extElanInterfaces) {
createExternalVpnInterface(extNetId, elanInterface, tx);
}
LOG.error("No external ports attached for external network {}", extNetId.getValue());
return;
}
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+ ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
for (String elanInterface : extElanInterfaces) {
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils
.buildVpnInterfaceIdentifier(elanInterface);
LOG.info("Removing vpn interface {}", elanInterface);
- tx.delete(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
+ tx.delete(vpnIfIdentifier);
}
}), LOG, "Error removing external VPN interfaces for {}", extNetId);
}
- private void createExternalVpnInterface(Uuid vpnId, String infName, WriteTransaction wrtConfigTxn) {
- writeVpnInterfaceToDs(Collections.singletonList(vpnId), infName, null,
+ private void createExternalVpnInterface(Uuid vpnId, String infName,
+ TypedWriteTransaction<Configuration> wrtConfigTxn) {
+ writeVpnInterfaceToDs(Collections.singletonList(vpnId), infName, null, vpnId /* external network id */,
false /* not a router iface */, wrtConfigTxn);
}
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
- private void writeVpnInterfaceToDs(@Nonnull Collection<Uuid> vpnIdList, String infName, Adjacencies adjacencies,
- Boolean isRouterInterface, WriteTransaction wrtConfigTxn) {
+ private void writeVpnInterfaceToDs(@Nonnull Collection<Uuid> vpnIdList, String infName,
+ @Nullable Adjacencies adjacencies, Uuid networkUuid, Boolean isRouterInterface,
+ TypedWriteTransaction<Configuration> wrtConfigTxn) {
if (vpnIdList.isEmpty() || infName == null) {
- LOG.error("vpn id or interface is null");
+ LOG.error("vpnid is empty or interface({}) is null", infName);
return;
}
if (wrtConfigTxn == null) {
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
- tx -> writeVpnInterfaceToDs(vpnIdList, infName, adjacencies, isRouterInterface, tx)), LOG,
+ ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+ tx -> writeVpnInterfaceToDs(vpnIdList, infName, adjacencies, networkUuid, isRouterInterface, tx)), LOG,
"Error writing VPN interface");
return;
}
.setName(infName)
.setVpnInstanceNames(vpnIdListStruct)
.setRouterInterface(isRouterInterface);
+ LOG.info("Network Id is {}", networkUuid);
+ if (networkUuid != null) {
+ Network portNetwork = neutronvpnUtils.getNeutronNetwork(networkUuid);
+ ProviderTypes providerType = NeutronvpnUtils.getProviderNetworkType(portNetwork);
+ NetworkAttributes.NetworkType networkType = providerType != null
+ ? NetworkAttributes.NetworkType.valueOf(providerType.getName()) : null;
+ String segmentationId = NeutronvpnUtils.getSegmentationIdFromNeutronNetwork(portNetwork);
+ vpnb.setNetworkId(networkUuid).setNetworkType(networkType)
+ .setSegmentationId(segmentationId != null ? Long.parseLong(segmentationId) : 0L);
+ }
+
if (adjacencies != null) {
vpnb.addAugmentation(Adjacencies.class, adjacencies);
}
VpnInterface vpnIf = vpnb.build();
try {
LOG.info("Creating vpn interface {}", vpnIf);
- wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIf);
+ wrtConfigTxn.put(vpnIfIdentifier, vpnIf);
} catch (Exception ex) {
LOG.error("Creation of vpninterface {} failed", infName, ex);
}
}
private void updateVpnInterfaceWithAdjacencies(Uuid vpnId, String infName, Adjacencies adjacencies,
- WriteTransaction wrtConfigTxn) {
+ TypedWriteTransaction<Configuration> wrtConfigTxn) {
if (vpnId == null || infName == null) {
LOG.error("vpn id or interface is null");
return;
}
if (wrtConfigTxn == null) {
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+ LOG.error("updateVpnInterfaceWithAdjancies called with wrtConfigTxn as null");
+ ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
updateVpnInterfaceWithAdjacencies(vpnId, infName, adjacencies, tx);
}), LOG, "Error updating VPN interface with adjacencies");
return;
vpnIfBuilder.setVpnInstanceNames(listVpnInstances);
}
LOG.info("Updating vpn interface {} with new adjacencies", infName);
- wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIfBuilder.build());
+ wrtConfigTxn.put(vpnIfIdentifier, vpnIfBuilder.build());
}
} catch (IllegalStateException | ReadFailedException ex) {
LOG.error("Update of vpninterface {} failed", infName, ex);
return help.toString();
}
- private void checkAndPublishRouterAssociatedtoVpnNotification(Uuid routerId, Uuid vpnId) throws
- InterruptedException {
- RouterAssociatedToVpn routerAssociatedToVpn = new RouterAssociatedToVpnBuilder().setRouterId(routerId)
- .setVpnId(vpnId).build();
- LOG.info("publishing notification upon association of router to VPN");
- notificationPublishService.putNotification(routerAssociatedToVpn);
- }
-
- private void checkAndPublishRouterDisassociatedFromVpnNotification(Uuid routerId, Uuid vpnId) throws
- InterruptedException {
- RouterDisassociatedFromVpn routerDisassociatedFromVpn =
- new RouterDisassociatedFromVpnBuilder().setRouterId(routerId).setVpnId(vpnId).build();
- LOG.info("publishing notification upon disassociation of router from VPN");
- notificationPublishService.putNotification(routerDisassociatedFromVpn);
- }
-
protected void dissociatefixedIPFromFloatingIP(String fixedNeutronPortName) {
floatingIpMapListener.dissociatefixedIPFromFloatingIP(fixedNeutronPortName);
}
Optional<VpnInstanceOpDataEntry> vpnInstanceOpDataOptional;
try {
vpnInstanceOpDataOptional = SingleTransactionDataBroker
- .syncReadOptional(dataBroker, OPERATIONAL, neutronvpnUtils.getVpnOpDataIdentifier(primaryRd));
+ .syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL,
+ neutronvpnUtils.getVpnOpDataIdentifier(primaryRd));
} catch (ReadFailedException e) {
LOG.error("getExistingOperationalVpn: Exception while checking operational status of vpn with rd {}",
primaryRd, e);
return existingVpnName;
}
- private String formatAndLog(Consumer<String> logger, String template, Object arg) {
+ private static String formatAndLog(Consumer<String> logger, String template, Object arg) {
return logAndReturnMessage(logger, MessageFormatter.format(template, arg));
}
- private String formatAndLog(Consumer<String> logger, String template, Object arg1, Object arg2) {
+ private static String formatAndLog(Consumer<String> logger, String template, Object arg1, Object arg2) {
return logAndReturnMessage(logger, MessageFormatter.format(template, arg1, arg2));
}
- private String formatAndLog(Consumer<String> logger, String template, Object... args) {
+ private static String formatAndLog(Consumer<String> logger, String template, Object... args) {
return logAndReturnMessage(logger, MessageFormatter.arrayFormat(template, args));
}
- private String logAndReturnMessage(Consumer<String> logger, FormattingTuple tuple) {
+ private static String logAndReturnMessage(Consumer<String> logger, FormattingTuple tuple) {
String message = tuple.getMessage();
logger.accept(message);
return message;
}
+
+ protected void addV6PrivateSubnetToExtNetwork(@Nonnull Uuid routerId, @Nonnull Uuid internetVpnId,
+ @Nonnull Subnetmap subnetMap) {
+ updateVpnInternetForSubnet(subnetMap, internetVpnId, true);
+ neutronvpnUtils.updateVpnInstanceWithFallback(routerId, internetVpnId, true);
+ if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChange(IpVersionChoice.IPV6, routerId, true)) {
+ neutronvpnUtils.updateVpnInstanceWithIpFamily(internetVpnId.getValue(), IpVersionChoice.IPV6, true);
+ LOG.info("addV6PrivateSubnetToExtNetwork: Advertise IPv6 Private Subnet {} to Internet VPN {}",
+ subnetMap.getId().getValue(), internetVpnId.getValue());
+ }
+ }
+
+ protected void removeV6PrivateSubnetToExtNetwork(@Nonnull Uuid routerId, @Nonnull Uuid internetVpnId,
+ @Nonnull Subnetmap subnetMap) {
+ updateVpnInternetForSubnet(subnetMap, internetVpnId, false);
+ neutronvpnUtils.updateVpnInstanceWithFallback(routerId, internetVpnId, false);
+ }
+
+ protected void programV6InternetFallbackFlow(Uuid routerId, Uuid internetVpnId, int addOrRemove) {
+ if (neutronvpnUtils.isV6SubnetPartOfRouter(routerId)) {
+ LOG.debug("processV6InternetFlowsForRtr: Successfully {} V6 internet vpn {} default fallback rule "
+ + "for the router {}", addOrRemove == NwConstants.ADD_FLOW ? "added" : "removed",
+ internetVpnId.getValue(), routerId.getValue());
+ neutronvpnUtils.updateVpnInstanceWithFallback(routerId, internetVpnId, addOrRemove == NwConstants.ADD_FLOW
+ ? true : false);
+ }
+ }
+
+ private static ReentrantLock lockForUuid(Uuid uuid) {
+ // FIXME: prove that this locks only on Uuids and not some other entity or create a separate lock domain
+ return JvmGlobalLocks.getLockForString(uuid.getValue());
+ }
}