*/
package org.opendaylight.netvirt.neutronvpn;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
import com.google.common.base.Function;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
import java.util.concurrent.locks.ReentrantLock;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
import org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice;
+import org.opendaylight.netvirt.neutronvpn.api.utils.NeutronConstants;
import org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInstances;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInterfaces;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstanceKey;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.SubnetsKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.port.info.FloatingIpIdToPortMapping;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.port.info.FloatingIpIdToPortMappingKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.VpnInstances;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.VpnInterfaces;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstance;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstanceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.instances.VpnInstanceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterfaceKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NetworkMaps;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NeutronVpnPortIdSubportData;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NeutronVpnPortipPortData;
NetworkTypeVxlan.class,
NetworkTypeGre.class);
+
+ private static final InstanceIdentifier<VpnInstanceOpData> VPN_INSTANCE_OP_DATA_IID =
+ InstanceIdentifier.create(VpnInstanceOpData.class);
+ private static final InstanceIdentifier<VpnMaps> VPN_MAPS_IID = InstanceIdentifier.create(VpnMaps.class);
+ private static final InstanceIdentifier<Subnetmaps> SUBNETMAPS_IID = InstanceIdentifier.create(Subnetmaps.class);
+ private static final InstanceIdentifier<Networks> NEUTRON_NETWORKS_IID = InstanceIdentifier.builder(Neutron.class)
+ .child(Networks.class).build();
+ private static final InstanceIdentifier<Ports> NEUTRON_PORTS_IID = InstanceIdentifier.builder(Neutron.class)
+ .child(Ports.class).build();
+ private static final InstanceIdentifier<Routers> NEUTRON_ROUTERS_IID = InstanceIdentifier.builder(Neutron.class)
+ .child(Routers.class).build();
+ private static final InstanceIdentifier<Subnets> NEUTRON_SUBNETS_IID = InstanceIdentifier.builder(Neutron.class)
+ .child(Subnets.class).build();
+
private final ConcurrentMap<Uuid, Network> networkMap = new ConcurrentHashMap<>();
private final ConcurrentMap<Uuid, Router> routerMap = new ConcurrentHashMap<>();
private final ConcurrentMap<Uuid, Port> portMap = new ConcurrentHashMap<>();
@Nullable
public VpnMap getVpnMap(Uuid id) {
- InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class,
- new VpnMapKey(id)).build();
- Optional<VpnMap> optionalVpnMap = read(LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
+ Optional<VpnMap> optionalVpnMap = read(LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier(id));
if (optionalVpnMap.isPresent()) {
return optionalVpnMap.get();
}
@Nullable
protected Uuid getVpnForNetwork(Uuid network) {
- InstanceIdentifier<VpnMaps> vpnMapsIdentifier = InstanceIdentifier.builder(VpnMaps.class).build();
- Optional<VpnMaps> optionalVpnMaps = read(LogicalDatastoreType.CONFIGURATION, vpnMapsIdentifier);
+ Optional<VpnMaps> optionalVpnMaps = read(LogicalDatastoreType.CONFIGURATION, VPN_MAPS_IID);
if (optionalVpnMaps.isPresent() && optionalVpnMaps.get().nonnullVpnMap() != null) {
for (VpnMap vpnMap : new ArrayList<>(optionalVpnMaps.get().nonnullVpnMap())) {
List<Uuid> netIds = vpnMap.getNetworkIds();
return null;
}
- InstanceIdentifier<VpnMaps> vpnMapsIdentifier = InstanceIdentifier.builder(VpnMaps.class).build();
- Optional<VpnMaps> optionalVpnMaps = read(LogicalDatastoreType.CONFIGURATION, vpnMapsIdentifier);
+ Optional<VpnMaps> optionalVpnMaps = read(LogicalDatastoreType.CONFIGURATION, VPN_MAPS_IID);
if (optionalVpnMaps.isPresent() && optionalVpnMaps.get().nonnullVpnMap() != null) {
for (VpnMap vpnMap : new ArrayList<>(optionalVpnMaps.get().nonnullVpnMap())) {
List<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap
continue;
}
// Skip router vpnId fetching from internet BGP-VPN
- if (vpnMap.getNetworkIds() != null && !vpnMap.getNetworkIds().isEmpty()) {
- // We only need to check the first network; if it’s not an external network there’s no
- // need to check the rest of the VPN’s network list
- if (getIsExternal(getNeutronNetwork(vpnMap.getNetworkIds().iterator().next()))) {
- continue;
- }
+ if (hasExternalNetwork(vpnMap.getNetworkIds())) {
+ continue;
}
// FIXME: NETVIRT-1503: this check can be replaced by a ReadOnlyTransaction.exists()
if (routerIdsList.stream().anyMatch(routerIds -> routerId.equals(routerIds.getRouterId()))) {
return null;
}
+ // We only need to check the first network; if it’s not an external network there’s no
+ // need to check the rest of the VPN’s network list. Note that some UUIDs may point to unknown networks, in which
+ // case we check more and assume false.
+ private boolean hasExternalNetwork(List<Uuid> uuids) {
+ if (uuids != null) {
+ for (Uuid uuid : uuids) {
+ final Network network = getNeutronNetwork(uuid);
+ if (network != null) {
+ if (Boolean.TRUE.equals(getIsExternal(network))) {
+ return true;
+ }
+ } else {
+ LOG.debug("hasExternalNetwork: cannot find network for {}", uuid);
+ }
+ }
+ }
+ return false;
+ }
+
+
@Nullable
protected List<Uuid> getRouterIdListforVpn(Uuid vpnId) {
- InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class,
- new VpnMapKey(vpnId)).build();
- Optional<VpnMap> optionalVpnMap = read(LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
+ Optional<VpnMap> optionalVpnMap = read(LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier(vpnId));
if (optionalVpnMap.isPresent()) {
VpnMap vpnMap = optionalVpnMap.get();
return NeutronUtils.getVpnMapRouterIdsListUuid(vpnMap.getRouterIds());
@Nullable
protected List<Uuid> getNetworksForVpn(Uuid vpnId) {
- InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class,
- new VpnMapKey(vpnId)).build();
- Optional<VpnMap> optionalVpnMap = read(LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
+ Optional<VpnMap> optionalVpnMap = read(LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier(vpnId));
if (optionalVpnMap.isPresent()) {
VpnMap vpnMap = optionalVpnMap.get();
if (vpnMap.getNetworkIds() != null && !vpnMap.getNetworkIds().isEmpty()) {
protected List<Uuid> getSubnetsforVpn(Uuid vpnid) {
List<Uuid> subnets = new ArrayList<>();
// read subnetmaps
- InstanceIdentifier<Subnetmaps> subnetmapsid = InstanceIdentifier.builder(Subnetmaps.class).build();
- Optional<Subnetmaps> subnetmaps = read(LogicalDatastoreType.CONFIGURATION, subnetmapsid);
+ Optional<Subnetmaps> subnetmaps = read(LogicalDatastoreType.CONFIGURATION, SUBNETMAPS_IID);
if (subnetmaps.isPresent() && subnetmaps.get().getSubnetmap() != null) {
List<Subnetmap> subnetMapList = subnetmaps.get().getSubnetmap();
for (Subnetmap candidateSubnetMap : subnetMapList) {
if (router != null) {
return router;
}
- InstanceIdentifier<Router> inst = InstanceIdentifier.create(Neutron.class).child(Routers.class).child(Router
- .class, new RouterKey(routerId));
- Optional<Router> rtr = read(LogicalDatastoreType.CONFIGURATION, inst);
+ Optional<Router> rtr = read(LogicalDatastoreType.CONFIGURATION, getNeutronRouterIid(routerId));
if (rtr.isPresent()) {
router = rtr.get();
}
}
public InstanceIdentifier<Router> getNeutronRouterIid(Uuid routerId) {
- return InstanceIdentifier.create(Neutron.class).child(Routers.class).child(Router
- .class, new RouterKey(routerId));
-
+ return NEUTRON_ROUTERS_IID.child(Router.class, new RouterKey(routerId));
}
- protected Network getNeutronNetwork(Uuid networkId) {
- Network network = null;
- network = networkMap.get(networkId);
+ protected @Nullable Network getNeutronNetwork(Uuid networkId) {
+ Network network = networkMap.get(networkId);
if (network != null) {
return network;
}
LOG.debug("getNeutronNetwork for {}", networkId.getValue());
- InstanceIdentifier<Network> inst = InstanceIdentifier.create(Neutron.class).child(Networks.class)
- .child(Network.class, new NetworkKey(networkId));
- Optional<Network> net = read(LogicalDatastoreType.CONFIGURATION, inst);
- if (net.isPresent()) {
- network = net.get();
- }
- return network;
+ InstanceIdentifier<Network> inst = NEUTRON_NETWORKS_IID.child(Network.class, new NetworkKey(networkId));
+ return read(LogicalDatastoreType.CONFIGURATION, inst).orNull();
}
- protected Port getNeutronPort(Uuid portId) {
+ protected @Nullable Port getNeutronPort(Uuid portId) {
Port prt = portMap.get(portId);
if (prt != null) {
return prt;
}
LOG.debug("getNeutronPort for {}", portId.getValue());
- InstanceIdentifier<Port> inst = InstanceIdentifier.create(Neutron.class).child(Ports.class).child(Port.class,
- new PortKey(portId));
- Optional<Port> port = read(LogicalDatastoreType.CONFIGURATION, inst);
- if (port.isPresent()) {
- prt = port.get();
- }
- return prt;
+ InstanceIdentifier<Port> inst = NEUTRON_PORTS_IID.child(Port.class, new PortKey(portId));
+ return read(LogicalDatastoreType.CONFIGURATION, inst).orNull();
}
public PortIdToSubport getPortIdToSubport(Uuid portId) {
Subnet subnet = getNeutronSubnet(subnetId);
if (subnet != null) {
Class<? extends IpVersionBase> ipVersion =
- NeutronSecurityRuleConstants.IP_VERSION_MAP.get(subnet.getIpVersion());
+ NeutronSecurityGroupConstants.IP_VERSION_MAP.get(subnet.getIpVersion());
Class<? extends Dhcpv6Base> raMode = subnet.getIpv6RaMode() == null ? null
- : NeutronSecurityRuleConstants.RA_MODE_MAP.get(subnet.getIpv6RaMode());
+ : NeutronSecurityGroupConstants.RA_MODE_MAP.get(subnet.getIpv6RaMode());
SubnetInfo subnetInfo = new SubnetInfoBuilder().withKey(new SubnetInfoKey(subnetId))
.setIpVersion(ipVersion).setIpPrefix(new IpPrefixOrAddress(subnet.getCidr()))
.setIpv6RaMode(raMode).setGatewayIp(subnet.getGatewayIp()).build();
if (subnet != null) {
return subnet;
}
- InstanceIdentifier<Subnet> inst = InstanceIdentifier.create(Neutron.class).child(Subnets.class).child(Subnet
- .class, new SubnetKey(subnetId));
+ InstanceIdentifier<Subnet> inst = NEUTRON_SUBNETS_IID.child(Subnet.class, new SubnetKey(subnetId));
Optional<Subnet> sn = read(LogicalDatastoreType.CONFIGURATION, inst);
if (sn.isPresent()) {
protected List<Subnetmap> getNeutronRouterSubnetMapList(Uuid routerId) {
List<Subnetmap> subnetMapList = new ArrayList<>();
- Optional<Subnetmaps> subnetMaps = read(LogicalDatastoreType.CONFIGURATION,
- InstanceIdentifier.builder(Subnetmaps.class).build());
+ Optional<Subnetmaps> subnetMaps = read(LogicalDatastoreType.CONFIGURATION, SUBNETMAPS_IID);
if (subnetMaps.isPresent() && subnetMaps.get().getSubnetmap() != null) {
for (Subnetmap subnetmap : subnetMaps.get().getSubnetmap()) {
if (routerId.equals(subnetmap.getRouterId())) {
protected List<Uuid> getNeutronRouterSubnetIds(Uuid routerId) {
LOG.debug("getNeutronRouterSubnetIds for {}", routerId.getValue());
List<Uuid> subnetIdList = new ArrayList<>();
- Optional<Subnetmaps> subnetMaps = read(LogicalDatastoreType.CONFIGURATION,
- InstanceIdentifier.builder(Subnetmaps.class).build());
+ Optional<Subnetmaps> subnetMaps = read(LogicalDatastoreType.CONFIGURATION, SUBNETMAPS_IID);
if (subnetMaps.isPresent() && subnetMaps.get().getSubnetmap() != null) {
for (Subnetmap subnetmap : subnetMaps.get().getSubnetmap()) {
if (routerId.equals(subnetmap.getRouterId())) {
@Nullable
protected Short getIPPrefixFromPort(Port port) {
try {
- Uuid subnetUUID = port.getFixedIps().get(0).getSubnetId();
- SubnetKey subnetkey = new SubnetKey(subnetUUID);
- InstanceIdentifier<Subnet> subnetidentifier = InstanceIdentifier.create(Neutron.class).child(Subnets
- .class).child(Subnet.class, subnetkey);
- Optional<Subnet> subnet = read(LogicalDatastoreType.CONFIGURATION, subnetidentifier);
+ // FIXME: why are we not using getNeutronSubnet() here? it does caching for us...
+ Optional<Subnet> subnet = read(LogicalDatastoreType.CONFIGURATION,
+ NEUTRON_SUBNETS_IID.child(Subnet.class, new SubnetKey(port.getFixedIps().get(0).getSubnetId())));
if (subnet.isPresent()) {
String cidr = subnet.get().getCidr().stringValue();
// Extract the prefix length from cidr
LOG.trace("Neutron port with fixedIp: {}, vpn {}, interface {}, mac {}, isSubnetIp {} added to "
+ "VpnPortipToPort DS", fixedIp, vpnName, portName, macAddress, isSubnetIp);
} catch (Exception e) {
- LOG.error("Failure while creating VPNPortFixedIpToPort map for vpn {} - fixedIP {}", vpnName, fixedIp,
- e);
+ LOG.error("Failure while creating VPNPortFixedIpToPort map for vpn {} - fixedIP {} for port {} with "
+ + "macAddress {}", vpnName, fixedIp, portName, macAddress, e);
}
}
}
static Boolean getIsExternal(Network network) {
- return network.augmentation(NetworkL3Extension.class) != null
- && network.augmentation(NetworkL3Extension.class).isExternal();
+ NetworkL3Extension ext = network.augmentation(NetworkL3Extension.class);
+ return ext != null && ext.isExternal();
}
static InstanceIdentifier<NetworkMap> buildNetworkMapIdentifier(Uuid networkId) {
}
static InstanceIdentifier<Subnetmap> buildSubnetMapIdentifier(Uuid subnetId) {
- InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new
- SubnetmapKey(subnetId)).build();
- return id;
+ return SUBNETMAPS_IID.child(Subnetmap.class, new SubnetmapKey(subnetId));
}
static InstanceIdentifier<Interface> buildVlanInterfaceIdentifier(String interfaceName) {
return npe != null && SUPPORTED_NETWORK_TYPES.contains(npe.getNetworkType());
}
- static boolean isNetworkOfType(Network network, Class<? extends NetworkTypeBase> type) {
- NetworkProviderExtension npe = network.augmentation(NetworkProviderExtension.class);
- if (npe != null && npe.getNetworkType() != null) {
- return type.isAssignableFrom(npe.getNetworkType());
+ static boolean isFlatOrVlanNetwork(Network network) {
+ if (network != null) {
+ NetworkProviderExtension npe = network.augmentation(NetworkProviderExtension.class);
+ if (npe != null) {
+ Class<? extends NetworkTypeBase> npeType = npe.getNetworkType();
+ if (npeType != null) {
+ return NetworkTypeVlan.class.isAssignableFrom(npeType)
+ || NetworkTypeFlat.class.isAssignableFrom(npeType);
+ }
+ }
}
return false;
}
- static boolean isFlatOrVlanNetwork(Network network) {
- return network != null
- && (isNetworkOfType(network, NetworkTypeVlan.class) || isNetworkOfType(network, NetworkTypeFlat.class));
- }
-
static boolean isVlanOrVxlanNetwork(Class<? extends NetworkTypeBase> type) {
return type.isAssignableFrom(NetworkTypeVxlan.class) || type.isAssignableFrom(NetworkTypeVlan.class);
}
return Optional.absent();
}
- protected void releaseRDId(String poolName, String idKey) {
+ protected Integer releaseId(String poolName, String idKey) {
ReleaseIdInput idInput = new ReleaseIdInputBuilder().setPoolName(poolName).setIdKey(idKey).build();
try {
- RpcResult<ReleaseIdOutput> rpcResult = idManager.releaseId(idInput).get();
- if (!rpcResult.isSuccessful()) {
- LOG.error("RPC Call to Get Unique Id returned with errors for poolname {} and ID Key {}: {}",
- poolName, idKey, rpcResult.getErrors());
+ Future<RpcResult<ReleaseIdOutput>> result = idManager.releaseId(idInput);
+ if (result == null || result.get() == null || !result.get().isSuccessful()) {
+ LOG.error("releaseId: RPC Call to release Id from pool {} with key {} returned with Errors {}",
+ poolName, idKey, (result != null && result.get() != null) ? result.get().getErrors() :
+ "RpcResult is null");
} else {
- LOG.info("ID {} for RD released successfully", idKey);
+ return result.get().getResult().getIdValues().get(0).intValue();
}
} catch (InterruptedException | ExecutionException e) {
- LOG.error("Exception when trying to release ID for poolname {} and ID Key {}", poolName, idKey, e);
+ LOG.error("releaseId: Exception when releasing Id for key {} from pool {}", idKey, poolName, e);
}
+ return NeutronConstants.INVALID_ID;
}
protected static IpAddress getIpv6LinkLocalAddressFromMac(MacAddress mac) {
Optional<VpnInstances> vpnInstancesOptional = read(LogicalDatastoreType.CONFIGURATION, path);
if (vpnInstancesOptional.isPresent() && vpnInstancesOptional.get().getVpnInstance() != null) {
for (VpnInstance vpnInstance : vpnInstancesOptional.get().getVpnInstance()) {
- if (vpnInstance.getIpv4Family() == null) {
- continue;
- }
- List<String> rds = vpnInstance.getIpv4Family().getRouteDistinguisher();
+ List<String> rds = vpnInstance.getRouteDistinguisher();
if (rds != null) {
existingRDs.addAll(rds);
}
}
protected boolean doesVpnExist(Uuid vpnId) {
- InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class,
- new VpnMapKey(vpnId)).build();
- return read(LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier).isPresent();
+ return read(LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier(vpnId)).isPresent();
}
protected Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external
*/
protected List<Subnetmap> getNeutronRouterSubnetMaps(Uuid routerId) {
List<Subnetmap> subnetIdList = new ArrayList<>();
- Optional<Subnetmaps> subnetMaps = read(LogicalDatastoreType.CONFIGURATION,
- InstanceIdentifier.builder(Subnetmaps.class).build());
+ Optional<Subnetmaps> subnetMaps = read(LogicalDatastoreType.CONFIGURATION, SUBNETMAPS_IID);
if (subnetMaps.isPresent() && subnetMaps.get().getSubnetmap() != null) {
for (Subnetmap subnetmap : subnetMaps.get().getSubnetmap()) {
if (routerId.equals(subnetmap.getRouterId())) {
}
protected InstanceIdentifier<VpnInstanceOpDataEntry> getVpnOpDataIdentifier(String primaryRd) {
- return InstanceIdentifier.builder(VpnInstanceOpData.class)
- .child(VpnInstanceOpDataEntry.class, new VpnInstanceOpDataEntryKey(primaryRd)).build();
+ return VPN_INSTANCE_OP_DATA_IID.child(VpnInstanceOpDataEntry.class, new VpnInstanceOpDataEntryKey(primaryRd));
}
public boolean shouldVpnHandleIpVersionChoiceChange(IpVersionChoice ipVersion, Uuid routerId, boolean add) {
if (sm == null) {
return false;
}
- InstanceIdentifier<Subnetmaps> subnetMapsId = InstanceIdentifier.builder(Subnetmaps.class).build();
- Optional<Subnetmaps> allSubnetMaps = read(LogicalDatastoreType.CONFIGURATION, subnetMapsId);
+ Optional<Subnetmaps> allSubnetMaps = read(LogicalDatastoreType.CONFIGURATION, SUBNETMAPS_IID);
// calculate and store in list IpVersion for each subnetMap, belonging to current VpnInstance
List<IpVersionChoice> snIpVersions = new ArrayList<>();
for (Subnetmap snMap : allSubnetMaps.get().nonnullSubnetmap()) {
public void updateVpnInstanceWithIpFamily(String vpnName, IpVersionChoice ipVersion, boolean add) {
jobCoordinator.enqueueJob("VPN-" + vpnName, () -> {
- VpnInstanceOpDataEntry vpnInstanceOpDataEntry = getVpnInstanceOpDataEntryFromVpnId(vpnName);
- if (vpnInstanceOpDataEntry == null) {
+ VpnInstance vpnInstance = getVpnInstance(dataBroker, new Uuid(vpnName));
+ if (vpnInstance == null) {
return Collections.emptyList();
}
- if (vpnInstanceOpDataEntry.getType() == VpnInstanceOpDataEntry.Type.L2) {
+ if (vpnInstance.isL2vpn()) {
LOG.debug("updateVpnInstanceWithIpFamily: Update VpnInstance {} with ipFamily {}."
- + "VpnInstanceOpDataEntry is L2 instance. Do nothing.", vpnName, ipVersion);
+ + "VpnInstance is L2 instance. Do nothing.", vpnName, ipVersion);
return Collections.emptyList();
}
if (ipVersion == IpVersionChoice.UNDEFINED) {
+ "is not allowed. Do nothing", vpnName);
return Collections.emptyList();
}
- VpnInstanceOpDataEntryBuilder builder = new VpnInstanceOpDataEntryBuilder(vpnInstanceOpDataEntry);
+ VpnInstanceBuilder builder = new VpnInstanceBuilder(vpnInstance);
boolean ipConfigured = add;
- if (ipVersion.isIpVersionChosen(IpVersionChoice.IPV4AND6)) {
- builder.setIpv4Configured(ipConfigured);
- builder.setIpv6Configured(ipConfigured);
- } else if (ipVersion.isIpVersionChosen(IpVersionChoice.IPV4)) {
- builder.setIpv4Configured(ipConfigured);
- } else if (ipVersion.isIpVersionChosen(IpVersionChoice.IPV6)) {
- builder.setIpv6Configured(ipConfigured);
+
+ int originalValue = vpnInstance.getIpAddressFamilyConfigured().getIntValue();
+ int updatedValue = ipVersion.choice;
+
+ if (originalValue != updatedValue) {
+ if (ipConfigured) {
+ originalValue = originalValue == 0 ? updatedValue : updatedValue + originalValue;
+ } else {
+ originalValue = 10 - updatedValue;
+ }
+ } else if (!ipConfigured) {
+ originalValue = 0;
}
+
+ builder.setIpAddressFamilyConfigured(VpnInstance.IpAddressFamilyConfigured.forValue(originalValue));
+
+ InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class)
+ .child(VpnInstance.class, new VpnInstanceKey(vpnName)).build();
+ LOG.info("updateVpnInstanceWithIpFamily: Successfully {} IP family {} to Vpn {}",
+ add == true ? "added" : "removed", ipVersion, vpnName);
return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
- OPERATIONAL, tx -> {
- InstanceIdentifier<VpnInstanceOpDataEntry> id = InstanceIdentifier
- .builder(VpnInstanceOpData.class).child(VpnInstanceOpDataEntry.class,
- new VpnInstanceOpDataEntryKey(vpnInstanceOpDataEntry.getVrfId())).build();
- tx.merge(id, builder.build(), false);
- LOG.info("updateVpnInstanceWithIpFamily: Successfully {} {} to Vpn {}",
- add == true ? "added" : "removed", ipVersion, vpnName);
- }));
+ CONFIGURATION, tx -> tx.merge(vpnIdentifier, builder.build(), false)));
});
+ return;
}
/**
+ "Primary RD not found", choice, vpn.getValue());
return;
}
- InstanceIdentifier<VpnInstanceOpDataEntry> id = InstanceIdentifier.builder(VpnInstanceOpData.class)
- .child(VpnInstanceOpDataEntry.class, new VpnInstanceOpDataEntryKey(primaryRd)).build();
+ InstanceIdentifier<VpnInstanceOpDataEntry> id = getVpnOpDataIdentifier(primaryRd);
Optional<VpnInstanceOpDataEntry> vpnInstanceOpDataEntryOptional =
read(LogicalDatastoreType.OPERATIONAL, id);
}, JOB_MAX_RETRIES);
}
+ private static InstanceIdentifier<VpnMap> vpnMapIdentifier(Uuid uuid) {
+ return VPN_MAPS_IID.child(VpnMap.class, new VpnMapKey(uuid));
+ }
+
private class SettableFutureCallback<T> implements FutureCallback<T> {
private final SettableFuture<T> settableFuture;