X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=neutronvpn%2Fimpl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetvirt%2Fneutronvpn%2FNeutronvpnUtils.java;h=1b784a2fee4d70d98763563ce42132385942dfd5;hb=cf1ea9172b94fc17e45391b62bf4ca24ac5c5fe0;hp=ac4fd13cf04b613f57b32e92ff4906526d17a8c2;hpb=748ef665214300a3ae561fce84a1fca90a757610;p=netvirt.git diff --git a/neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnUtils.java b/neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnUtils.java index ac4fd13cf0..1b784a2fee 100644 --- a/neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnUtils.java +++ b/neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnUtils.java @@ -5,20 +5,19 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - 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 com.google.common.base.Optional; import com.google.common.collect.ImmutableBiMap; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.SettableFuture; -import java.math.BigInteger; import java.net.Inet4Address; import java.net.Inet6Address; import java.net.InetAddress; @@ -26,24 +25,21 @@ import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; 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.apache.commons.lang3.StringUtils; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker; import org.opendaylight.genius.infra.Datastore; import org.opendaylight.genius.infra.ManagedNewTransactionRunner; @@ -54,14 +50,12 @@ import org.opendaylight.genius.utils.JvmGlobalLocks; import org.opendaylight.infrautils.jobcoordinator.JobCoordinator; import org.opendaylight.infrautils.utils.concurrent.ListenableFutures; import org.opendaylight.infrautils.utils.concurrent.LoggingFutures; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.ReadTransaction; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; 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; @@ -75,6 +69,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406. import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.Dhcpv6Base; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.InterfaceAcl; import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.InterfaceAclBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.IpPrefixOrAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.IpVersionBase; @@ -110,6 +105,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev16011 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; @@ -128,6 +130,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev15060 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpn.instance.RouterIdsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap; import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMapKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap.RouterIdsKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.ext.rev150712.NetworkL3Extension; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.Routers; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router; @@ -142,6 +145,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712. import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.NetworkKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps; +import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIpsKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port; import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.PortKey; @@ -159,6 +163,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt. import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.common.Uint64; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -175,14 +180,25 @@ public class NeutronvpnUtils { .put(NetworkTypeVxlan.class, SegmentTypeVxlan.class) .build(); - private static final Set> SUPPORTED_NETWORK_TYPES = new HashSet<>(); - - static { - SUPPORTED_NETWORK_TYPES.add(NetworkTypeFlat.class); - SUPPORTED_NETWORK_TYPES.add(NetworkTypeVlan.class); - SUPPORTED_NETWORK_TYPES.add(NetworkTypeVxlan.class); - SUPPORTED_NETWORK_TYPES.add(NetworkTypeGre.class); - } + private static final ImmutableSet> SUPPORTED_NETWORK_TYPES = ImmutableSet.of( + NetworkTypeFlat.class, + NetworkTypeVlan.class, + NetworkTypeVxlan.class, + NetworkTypeGre.class); + + + private static final InstanceIdentifier VPN_INSTANCE_OP_DATA_IID = + InstanceIdentifier.create(VpnInstanceOpData.class); + private static final InstanceIdentifier VPN_MAPS_IID = InstanceIdentifier.create(VpnMaps.class); + private static final InstanceIdentifier SUBNETMAPS_IID = InstanceIdentifier.create(Subnetmaps.class); + private static final InstanceIdentifier NEUTRON_NETWORKS_IID = InstanceIdentifier.builder(Neutron.class) + .child(Networks.class).build(); + private static final InstanceIdentifier NEUTRON_PORTS_IID = InstanceIdentifier.builder(Neutron.class) + .child(Ports.class).build(); + private static final InstanceIdentifier NEUTRON_ROUTERS_IID = InstanceIdentifier.builder(Neutron.class) + .child(Routers.class).build(); + private static final InstanceIdentifier NEUTRON_SUBNETS_IID = InstanceIdentifier.builder(Neutron.class) + .child(Subnets.class).build(); private final ConcurrentMap networkMap = new ConcurrentHashMap<>(); private final ConcurrentMap routerMap = new ConcurrentHashMap<>(); @@ -221,9 +237,7 @@ public class NeutronvpnUtils { @Nullable public VpnMap getVpnMap(Uuid id) { - InstanceIdentifier vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, - new VpnMapKey(id)).build(); - Optional optionalVpnMap = read(LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier); + Optional optionalVpnMap = read(LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier(id)); if (optionalVpnMap.isPresent()) { return optionalVpnMap.get(); } @@ -233,10 +247,9 @@ public class NeutronvpnUtils { @Nullable protected Uuid getVpnForNetwork(Uuid network) { - InstanceIdentifier vpnMapsIdentifier = InstanceIdentifier.builder(VpnMaps.class).build(); - Optional optionalVpnMaps = read(LogicalDatastoreType.CONFIGURATION, vpnMapsIdentifier); - if (optionalVpnMaps.isPresent() && optionalVpnMaps.get().getVpnMap() != null) { - for (VpnMap vpnMap : optionalVpnMaps.get().nonnullVpnMap()) { + Optional optionalVpnMaps = read(LogicalDatastoreType.CONFIGURATION, VPN_MAPS_IID); + if (optionalVpnMaps.isPresent() && optionalVpnMaps.get().nonnullVpnMap() != null) { + for (VpnMap vpnMap : new ArrayList<>(optionalVpnMaps.get().nonnullVpnMap().values())) { List netIds = vpnMap.getNetworkIds(); if (netIds != null && netIds.contains(network)) { return vpnMap.getVpnId(); @@ -278,25 +291,20 @@ public class NeutronvpnUtils { return null; } - InstanceIdentifier vpnMapsIdentifier = InstanceIdentifier.builder(VpnMaps.class).build(); - Optional optionalVpnMaps = read(LogicalDatastoreType.CONFIGURATION, vpnMapsIdentifier); - if (optionalVpnMaps.isPresent() && optionalVpnMaps.get().getVpnMap() != null) { - for (VpnMap vpnMap : optionalVpnMaps.get().nonnullVpnMap()) { - List routerIdsList = vpnMap.getRouterIds(); - if (routerIdsList == null || routerIdsList.isEmpty()) { + Optional optionalVpnMaps = read(LogicalDatastoreType.CONFIGURATION, VPN_MAPS_IID); + if (optionalVpnMaps.isPresent() && optionalVpnMaps.get().nonnullVpnMap() != null) { + for (VpnMap vpnMap : new ArrayList<>(optionalVpnMaps.get().nonnullVpnMap().values())) { + Map keyRouterIdsMap = vpnMap.getRouterIds(); + if (keyRouterIdsMap == null || keyRouterIdsMap.isEmpty()) { 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()))) { + if (keyRouterIdsMap.values().stream().anyMatch(routerIds -> routerId.equals(routerIds.getRouterId()))) { if (externalVpn) { if (!routerId.equals(vpnMap.getVpnId())) { return vpnMap.getVpnId(); @@ -313,14 +321,33 @@ public class NeutronvpnUtils { 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 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 getRouterIdListforVpn(Uuid vpnId) { - InstanceIdentifier vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, - new VpnMapKey(vpnId)).build(); - Optional optionalVpnMap = read(LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier); + Optional optionalVpnMap = read(LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier(vpnId)); if (optionalVpnMap.isPresent()) { VpnMap vpnMap = optionalVpnMap.get(); - return NeutronUtils.getVpnMapRouterIdsListUuid(vpnMap.getRouterIds()); + return NeutronUtils.getVpnMapRouterIdsListUuid(new ArrayList(vpnMap.getRouterIds().values())); } LOG.error("getRouterIdListforVpn: Failed as VPNMaps DS is absent for VPN {}", vpnId.getValue()); return null; @@ -328,12 +355,14 @@ public class NeutronvpnUtils { @Nullable protected List getNetworksForVpn(Uuid vpnId) { - InstanceIdentifier vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, - new VpnMapKey(vpnId)).build(); - Optional optionalVpnMap = read(LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier); + Optional optionalVpnMap = read(LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier(vpnId)); if (optionalVpnMap.isPresent()) { VpnMap vpnMap = optionalVpnMap.get(); - return vpnMap.getNetworkIds(); + if (vpnMap.getNetworkIds() != null && !vpnMap.getNetworkIds().isEmpty()) { + return new ArrayList<>(vpnMap.getNetworkIds()); + } else { + return null; + } } LOG.error("getNetworksforVpn: Failed as VPNMaps DS is absent for VPN {}", vpnId.getValue()); return null; @@ -342,11 +371,10 @@ public class NeutronvpnUtils { protected List getSubnetsforVpn(Uuid vpnid) { List subnets = new ArrayList<>(); // read subnetmaps - InstanceIdentifier subnetmapsid = InstanceIdentifier.builder(Subnetmaps.class).build(); - Optional subnetmaps = read(LogicalDatastoreType.CONFIGURATION, subnetmapsid); + Optional subnetmaps = read(LogicalDatastoreType.CONFIGURATION, SUBNETMAPS_IID); if (subnetmaps.isPresent() && subnetmaps.get().getSubnetmap() != null) { - List subnetMapList = subnetmaps.get().getSubnetmap(); - for (Subnetmap candidateSubnetMap : subnetMapList) { + Map keySubnetmapMap = subnetmaps.get().getSubnetmap(); + for (Subnetmap candidateSubnetMap : keySubnetmapMap.values()) { if (candidateSubnetMap.getVpnId() != null && candidateSubnetMap.getVpnId().equals(vpnid)) { subnets.add(candidateSubnetMap.getId()); } @@ -383,9 +411,7 @@ public class NeutronvpnUtils { if (router != null) { return router; } - InstanceIdentifier inst = InstanceIdentifier.create(Neutron.class).child(Routers.class).child(Router - .class, new RouterKey(routerId)); - Optional rtr = read(LogicalDatastoreType.CONFIGURATION, inst); + Optional rtr = read(LogicalDatastoreType.CONFIGURATION, getNeutronRouterIid(routerId)); if (rtr.isPresent()) { router = rtr.get(); } @@ -393,40 +419,27 @@ public class NeutronvpnUtils { } public InstanceIdentifier 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 inst = InstanceIdentifier.create(Neutron.class).child(Networks.class) - .child(Network.class, new NetworkKey(networkId)); - Optional net = read(LogicalDatastoreType.CONFIGURATION, inst); - if (net.isPresent()) { - network = net.get(); - } - return network; + InstanceIdentifier inst = NEUTRON_NETWORKS_IID.child(Network.class, new NetworkKey(networkId)); + return read(LogicalDatastoreType.CONFIGURATION, inst).orElse(null); } - 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 inst = InstanceIdentifier.create(Neutron.class).child(Ports.class).child(Port.class, - new PortKey(portId)); - Optional port = read(LogicalDatastoreType.CONFIGURATION, inst); - if (port.isPresent()) { - prt = port.get(); - } - return prt; + InstanceIdentifier inst = NEUTRON_PORTS_IID.child(Port.class, new PortKey(portId)); + return read(LogicalDatastoreType.CONFIGURATION, inst).orElse(null); } public PortIdToSubport getPortIdToSubport(Uuid portId) { @@ -440,6 +453,20 @@ public class NeutronvpnUtils { return null; } + protected static boolean isDhcpServerPort(Port port) { + return port.getDeviceOwner().equals("network:dhcp"); + } + + protected InterfaceAcl getDhcpInterfaceAcl(Port port) { + InterfaceAclBuilder interfaceAclBuilder = new InterfaceAclBuilder(); + interfaceAclBuilder.setPortSecurityEnabled(false); + interfaceAclBuilder.setInterfaceType(InterfaceAcl.InterfaceType.DhcpService); + List aclAllowedAddressPairs = NeutronvpnUtils.getAllowedAddressPairsForAclService( + port.getMacAddress(), new ArrayList(port.getFixedIps().values())); + interfaceAclBuilder.setAllowedAddressPairs(aclAllowedAddressPairs); + return interfaceAclBuilder.build(); + } + /** * Returns port_security_enabled status with the port. * @@ -671,9 +698,11 @@ public class NeutronvpnUtils { */ protected static List getAllowedAddressPairsForFixedIps( List aclInterfaceAllowedAddressPairs, MacAddress portMacAddress, - List origFixedIps, List newFixedIps) { - List addedFixedIps = getFixedIpsDelta(newFixedIps, origFixedIps); - List deletedFixedIps = getFixedIpsDelta(origFixedIps, newFixedIps); + @Nullable Map origFixedIps, Collection newFixedIps) { + List addedFixedIps = getFixedIpsDelta(new ArrayList(newFixedIps), + new ArrayList(origFixedIps.values())); + List deletedFixedIps = getFixedIpsDelta(new ArrayList(origFixedIps.values()), + new ArrayList(newFixedIps)); List updatedAllowedAddressPairs = aclInterfaceAllowedAddressPairs != null ? new ArrayList<>(aclInterfaceAllowedAddressPairs) : new ArrayList<>(); @@ -697,13 +726,19 @@ public class NeutronvpnUtils { protected static List getUpdatedAllowedAddressPairs( List aclInterfaceAllowedAddressPairs, List origAllowedAddressPairs, + .AllowedAddressPairs> origAllowedAddressPairs, List newAllowedAddressPairs) { + .AllowedAddressPairs> newAllowedAddressPairs) { List addedAllowedAddressPairs = - getAllowedAddressPairsDelta(newAllowedAddressPairs,origAllowedAddressPairs); + getAllowedAddressPairsDelta(new ArrayList(newAllowedAddressPairs), + new ArrayList(origAllowedAddressPairs)); List deletedAllowedAddressPairs = - getAllowedAddressPairsDelta(origAllowedAddressPairs, newAllowedAddressPairs); + getAllowedAddressPairsDelta(new ArrayList(origAllowedAddressPairs), + new ArrayList(newAllowedAddressPairs)); List updatedAllowedAddressPairs = aclInterfaceAllowedAddressPairs != null ? new ArrayList<>(aclInterfaceAllowedAddressPairs) : new ArrayList<>(); @@ -729,16 +764,17 @@ public class NeutronvpnUtils { interfaceAclBuilder.setSecurityGroups(securityGroups); } List aclAllowedAddressPairs = NeutronvpnUtils.getAllowedAddressPairsForAclService( - port.getMacAddress(), port.getFixedIps()); + port.getMacAddress(), new ArrayList(port.getFixedIps().values())); // Update the allowed address pair with the IPv6 LLA that is auto configured on the port. aclAllowedAddressPairs.add(NeutronvpnUtils.updateIPv6LinkLocalAddressForAclService(port.getMacAddress())); List - portAllowedAddressPairs = port.getAllowedAddressPairs(); + portAllowedAddressPairs = new ArrayList(port.getAllowedAddressPairs().values()); if (portAllowedAddressPairs != null) { aclAllowedAddressPairs.addAll(NeutronvpnUtils.getAllowedAddressPairsForAclService(portAllowedAddressPairs)); } interfaceAclBuilder.setAllowedAddressPairs(aclAllowedAddressPairs); - + interfaceAclBuilder.setInterfaceType(InterfaceAcl.InterfaceType.AccessPort); populateSubnetInfo(interfaceAclBuilder, port); } @@ -751,20 +787,20 @@ public class NeutronvpnUtils { @Nullable protected List getSubnetInfo(Port port) { - List portFixedIps = port.getFixedIps(); - if (portFixedIps == null) { + Map keyFixedIpsMap = port.getFixedIps(); + if (keyFixedIpsMap == null) { LOG.error("Failed to get Fixed IPs for the port {}", port.getName()); return null; } List subnetInfoList = new ArrayList<>(); - for (FixedIps portFixedIp : portFixedIps) { + for (FixedIps portFixedIp : keyFixedIpsMap.values()) { Uuid subnetId = portFixedIp.getSubnetId(); Subnet subnet = getNeutronSubnet(subnetId); if (subnet != null) { Class ipVersion = - NeutronSecurityRuleConstants.IP_VERSION_MAP.get(subnet.getIpVersion()); + NeutronSecurityGroupConstants.IP_VERSION_MAP.get(subnet.getIpVersion()); Class 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(); @@ -779,8 +815,7 @@ public class NeutronvpnUtils { if (subnet != null) { return subnet; } - InstanceIdentifier inst = InstanceIdentifier.create(Neutron.class).child(Subnets.class).child(Subnet - .class, new SubnetKey(subnetId)); + InstanceIdentifier inst = NEUTRON_SUBNETS_IID.child(Subnet.class, new SubnetKey(subnetId)); Optional sn = read(LogicalDatastoreType.CONFIGURATION, inst); if (sn.isPresent()) { @@ -792,10 +827,9 @@ public class NeutronvpnUtils { protected List getNeutronRouterSubnetMapList(Uuid routerId) { List subnetMapList = new ArrayList<>(); - Optional subnetMaps = read(LogicalDatastoreType.CONFIGURATION, - InstanceIdentifier.builder(Subnetmaps.class).build()); + Optional subnetMaps = read(LogicalDatastoreType.CONFIGURATION, SUBNETMAPS_IID); if (subnetMaps.isPresent() && subnetMaps.get().getSubnetmap() != null) { - for (Subnetmap subnetmap : subnetMaps.get().getSubnetmap()) { + for (Subnetmap subnetmap : subnetMaps.get().getSubnetmap().values()) { if (routerId.equals(subnetmap.getRouterId())) { subnetMapList.add(subnetmap); } @@ -809,10 +843,9 @@ public class NeutronvpnUtils { protected List getNeutronRouterSubnetIds(Uuid routerId) { LOG.debug("getNeutronRouterSubnetIds for {}", routerId.getValue()); List subnetIdList = new ArrayList<>(); - Optional subnetMaps = read(LogicalDatastoreType.CONFIGURATION, - InstanceIdentifier.builder(Subnetmaps.class).build()); + Optional subnetMaps = read(LogicalDatastoreType.CONFIGURATION, SUBNETMAPS_IID); if (subnetMaps.isPresent() && subnetMaps.get().getSubnetmap() != null) { - for (Subnetmap subnetmap : subnetMaps.get().getSubnetmap()) { + for (Subnetmap subnetmap : subnetMaps.get().getSubnetmap().values()) { if (routerId.equals(subnetmap.getRouterId())) { subnetIdList.add(subnetmap.getId()); } @@ -827,11 +860,10 @@ public class NeutronvpnUtils { @Nullable protected Short getIPPrefixFromPort(Port port) { try { - Uuid subnetUUID = port.getFixedIps().get(0).getSubnetId(); - SubnetKey subnetkey = new SubnetKey(subnetUUID); - InstanceIdentifier subnetidentifier = InstanceIdentifier.create(Neutron.class).child(Subnets - .class).child(Subnet.class, subnetkey); - Optional subnet = read(LogicalDatastoreType.CONFIGURATION, subnetidentifier); + // FIXME: why are we not using getNeutronSubnet() here? it does caching for us... + Optional subnet = read(LogicalDatastoreType.CONFIGURATION, + NEUTRON_SUBNETS_IID.child(Subnet.class, new SubnetKey( + new ArrayList(port.getFixedIps().values()).get(0).getSubnetId()))); if (subnet.isPresent()) { String cidr = subnet.get().getCidr().stringValue(); // Extract the prefix length from cidr @@ -869,8 +901,8 @@ public class NeutronvpnUtils { 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); } } @@ -999,8 +1031,8 @@ public class NeutronvpnUtils { } 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 buildNetworkMapIdentifier(Uuid networkId) { @@ -1016,9 +1048,7 @@ public class NeutronvpnUtils { } static InstanceIdentifier buildSubnetMapIdentifier(Uuid subnetId) { - InstanceIdentifier 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 buildVlanInterfaceIdentifier(String interfaceName) { @@ -1052,7 +1082,7 @@ public class NeutronvpnUtils { private Optional read(LogicalDatastoreType datastoreType, InstanceIdentifier path) { try { return SingleTransactionDataBroker.syncReadOptional(dataBroker, datastoreType, path); - } catch (ReadFailedException e) { + } catch (ExecutionException | InterruptedException e) { throw new RuntimeException(e); } } @@ -1085,22 +1115,23 @@ public class NeutronvpnUtils { static boolean isNetworkTypeSupported(Network network) { NetworkProviderExtension npe = network.augmentation(NetworkProviderExtension.class); - return npe != null && npe.getNetworkType() != null && SUPPORTED_NETWORK_TYPES.contains(npe.getNetworkType()); + return npe != null && SUPPORTED_NETWORK_TYPES.contains(npe.getNetworkType()); } - static boolean isNetworkOfType(Network network, Class 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 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 type) { return type.isAssignableFrom(NetworkTypeVxlan.class) || type.isAssignableFrom(NetworkTypeVlan.class); } @@ -1125,32 +1156,40 @@ public class NeutronvpnUtils { */ public Optional getInterVpnLinkByEndpointIp(String endpointIp) { InstanceIdentifier interVpnLinksIid = InstanceIdentifier.builder(InterVpnLinks.class).build(); - Optional interVpnLinksOpData = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, - interVpnLinksIid); - if (interVpnLinksOpData.isPresent()) { - for (InterVpnLink interVpnLink : interVpnLinksOpData.get().nonnullInterVpnLink()) { - if (interVpnLink.getFirstEndpoint().getIpAddress().getValue().equals(endpointIp) - || interVpnLink.getSecondEndpoint().getIpAddress().getValue().equals(endpointIp)) { - return Optional.of(interVpnLink); + Optional interVpnLinksOpData = null; + try { + interVpnLinksOpData = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, + interVpnLinksIid); + if (interVpnLinksOpData.isPresent()) { + for (InterVpnLink interVpnLink : interVpnLinksOpData.get().nonnullInterVpnLink().values()) { + if (interVpnLink.getFirstEndpoint().getIpAddress().getValue().equals(endpointIp) + || interVpnLink.getSecondEndpoint().getIpAddress().getValue().equals(endpointIp)) { + return Optional.of(interVpnLink); + } } } + } catch (ExecutionException | InterruptedException e) { + LOG.error("getInterVpnLinkByEndpointIp: Exception when reading intervpn Links for endpoint Ip {} ", + endpointIp, e); } - return Optional.absent(); + return Optional.empty(); } - 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 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> 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) { @@ -1200,11 +1239,8 @@ public class NeutronvpnUtils { InstanceIdentifier path = InstanceIdentifier.builder(VpnInstances.class).build(); Optional vpnInstancesOptional = read(LogicalDatastoreType.CONFIGURATION, path); if (vpnInstancesOptional.isPresent() && vpnInstancesOptional.get().getVpnInstance() != null) { - for (VpnInstance vpnInstance : vpnInstancesOptional.get().getVpnInstance()) { - if (vpnInstance.getIpv4Family() == null) { - continue; - } - List rds = vpnInstance.getIpv4Family().getRouteDistinguisher(); + for (VpnInstance vpnInstance : vpnInstancesOptional.get().getVpnInstance().values()) { + List rds = vpnInstance.getRouteDistinguisher(); if (rds != null) { existingRDs.addAll(rds); } @@ -1214,9 +1250,7 @@ public class NeutronvpnUtils { } protected boolean doesVpnExist(Uuid vpnId) { - InstanceIdentifier 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 buildStaticMacEntry(Port port) { PhysAddress physAddress = new PhysAddress(port.getMacAddress().getValue()); - List fixedIps = port.getFixedIps(); + Map keyFixedIpsMap = port.getFixedIps(); IpAddress ipAddress = null; - if (isNotEmpty(fixedIps)) { - ipAddress = port.getFixedIps().get(0).getIpAddress(); + if (isNotEmpty(keyFixedIpsMap.values())) { + ipAddress = new ArrayList(port.getFixedIps().values()).get(0).getIpAddress(); } StaticMacEntriesBuilder staticMacEntriesBuilder = new StaticMacEntriesBuilder(); List staticMacEntries = new ArrayList<>(); @@ -1288,10 +1322,9 @@ public class NeutronvpnUtils { */ protected List getNeutronRouterSubnetMaps(Uuid routerId) { List subnetIdList = new ArrayList<>(); - Optional subnetMaps = read(LogicalDatastoreType.CONFIGURATION, - InstanceIdentifier.builder(Subnetmaps.class).build()); + Optional subnetMaps = read(LogicalDatastoreType.CONFIGURATION, SUBNETMAPS_IID); if (subnetMaps.isPresent() && subnetMaps.get().getSubnetmap() != null) { - for (Subnetmap subnetmap : subnetMaps.get().getSubnetmap()) { + for (Subnetmap subnetmap : subnetMaps.get().getSubnetmap().values()) { if (routerId.equals(subnetmap.getRouterId())) { subnetIdList.add(subnetmap); } @@ -1320,7 +1353,7 @@ public class NeutronvpnUtils { InstanceIdentifier id = getVpnInstanceToVpnIdIdentifier(vpnName); return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, - LogicalDatastoreType.CONFIGURATION, id).toJavaUtil().map( + LogicalDatastoreType.CONFIGURATION, id).map( org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id .VpnInstance::getVrfId).orElse(null); } @@ -1376,8 +1409,7 @@ public class NeutronvpnUtils { } protected InstanceIdentifier 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) { @@ -1409,11 +1441,10 @@ public class NeutronvpnUtils { if (sm == null) { return false; } - InstanceIdentifier subnetMapsId = InstanceIdentifier.builder(Subnetmaps.class).build(); - Optional allSubnetMaps = read(LogicalDatastoreType.CONFIGURATION, subnetMapsId); + Optional allSubnetMaps = read(LogicalDatastoreType.CONFIGURATION, SUBNETMAPS_IID); // calculate and store in list IpVersion for each subnetMap, belonging to current VpnInstance List snIpVersions = new ArrayList<>(); - for (Subnetmap snMap : allSubnetMaps.get().nonnullSubnetmap()) { + for (Subnetmap snMap : allSubnetMaps.get().nonnullSubnetmap().values()) { if (snMap.getId().equals(sm.getId())) { continue; } @@ -1448,13 +1479,13 @@ public class NeutronvpnUtils { 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) { @@ -1462,26 +1493,32 @@ public class NeutronvpnUtils { + "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 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 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.mergeParentStructureMerge(vpnIdentifier, builder.build()))); }); + return; } /** @@ -1586,7 +1623,7 @@ public class NeutronvpnUtils { LOG.error("updateVpnInstanceWithFallback: vpnInstanceOpDataEntry not found for vpn {}", vpnName); return; } - Long internetBgpVpnId = vpnInstanceOpDataEntry.getVpnId(); + Long internetBgpVpnId = vpnInstanceOpDataEntry.getVpnId().toJava(); List routerIds = new ArrayList<>(); //Handle router specific V6 internet fallback flow else handle all V6 external routers if (routerId != null) { @@ -1603,12 +1640,12 @@ public class NeutronvpnUtils { if (rtrId == null) { continue; } - List dpnIds = getDpnsForRouter(rtrId.getValue()); + List dpnIds = getDpnsForRouter(rtrId.getValue()); if (dpnIds.isEmpty()) { continue; } VpnInstanceOpDataEntry vpnOpDataEntry = getVpnInstanceOpDataEntryFromVpnId(rtrId.getValue()); - Long routerIdAsLong = vpnOpDataEntry.getVpnId(); + Long routerIdAsLong = vpnOpDataEntry.getVpnId().toJava(); long vpnId; Uuid rtrVpnId = getVpnForRouter(rtrId, true); if (rtrVpnId == null) { @@ -1617,17 +1654,17 @@ public class NeutronvpnUtils { } else { vpnId = getVpnId(rtrVpnId.getValue()); } - for (BigInteger dpnId : dpnIds) { + for (Uint64 dpnId : dpnIds) { if (add) { LoggingFutures.addErrorLogging( txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION, - tx -> ipV6InternetDefRt.installDefaultRoute(tx, dpnId, rtrId.getValue(), internetBgpVpnId, - vpnId)), LOG, "Error adding default route"); + tx -> ipV6InternetDefRt.installDefaultRoute(tx, dpnId, rtrId.getValue(), + internetBgpVpnId, vpnId)), LOG, "Error adding default route"); } else { LoggingFutures.addErrorLogging( txRunner.callWithNewReadWriteTransactionAndSubmit(Datastore.CONFIGURATION, - tx -> ipV6InternetDefRt.removeDefaultRoute(tx, dpnId, rtrId.getValue(), internetBgpVpnId, - vpnId)), LOG, + tx -> ipV6InternetDefRt.removeDefaultRoute(tx, dpnId, rtrId.getValue(), + internetBgpVpnId, vpnId)), LOG, "Error removing default route"); } } @@ -1641,8 +1678,7 @@ public class NeutronvpnUtils { + "Primary RD not found", choice, vpn.getValue()); return; } - InstanceIdentifier id = InstanceIdentifier.builder(VpnInstanceOpData.class) - .child(VpnInstanceOpDataEntry.class, new VpnInstanceOpDataEntryKey(primaryRd)).build(); + InstanceIdentifier id = getVpnOpDataIdentifier(primaryRd); Optional vpnInstanceOpDataEntryOptional = read(LogicalDatastoreType.OPERATIONAL, id); @@ -1660,7 +1696,7 @@ public class NeutronvpnUtils { VpnInstanceOpDataEntryBuilder builder = new VpnInstanceOpDataEntryBuilder(vpnInstanceOpDataEntry); builder.setBgpvpnType(choice); ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> { - tx.merge(id, builder.build(), false); + tx.merge(id, builder.build()); LOG.debug("updateVpnInstanceOpWithType: sent merge to operDS BgpvpnType {} for {}", choice, vpn.getValue()); }), LOG, "Error updating VPN instance op {} with type {}", vpn, choice); } @@ -1679,15 +1715,16 @@ public class NeutronvpnUtils { } @NonNull - public List getDpnsForRouter(String routerUuid) { + public List getDpnsForRouter(String routerUuid) { InstanceIdentifier id = InstanceIdentifier.builder(NeutronRouterDpns.class) .child(RouterDpnList.class, new RouterDpnListKey(routerUuid)).build(); Optional routerDpnListData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, id); - List dpns = new ArrayList<>(); + List dpns = new ArrayList<>(); if (routerDpnListData.isPresent()) { - for (DpnVpninterfacesList dpnVpnInterface : routerDpnListData.get().nonnullDpnVpninterfacesList()) { + for (DpnVpninterfacesList dpnVpnInterface + : routerDpnListData.get().nonnullDpnVpninterfacesList().values()) { dpns.add(dpnVpnInterface.getDpnId()); } } @@ -1720,9 +1757,9 @@ public class NeutronvpnUtils { InstanceIdentifier id = getVpnInstanceToVpnIdIdentifier(vpnName); return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, - LogicalDatastoreType.CONFIGURATION, id).toJavaUtil().map( + LogicalDatastoreType.CONFIGURATION, id).map( org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id - .VpnInstance::getVpnId).orElse(null); + .VpnInstance::getVpnId).orElse(null).toJava(); } protected boolean isV6SubnetPartOfRouter(Uuid routerId) { @@ -1747,7 +1784,7 @@ public class NeutronvpnUtils { jobCoordinator.enqueueJob(jobKey, () -> { SettableFuture> settableFuture = SettableFuture.create(); List futures = Collections.singletonList(settableFuture); - try (ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction()) { + try (ReadTransaction tx = dataBroker.newReadOnlyTransaction()) { Futures.addCallback(tx.read(datastoreType, iid), new SettableFutureCallback>(settableFuture) { @Override @@ -1762,6 +1799,10 @@ public class NeutronvpnUtils { }, JOB_MAX_RETRIES); } + private static InstanceIdentifier vpnMapIdentifier(Uuid uuid) { + return VPN_MAPS_IID.child(VpnMap.class, new VpnMapKey(uuid)); + } + private class SettableFutureCallback implements FutureCallback { private final SettableFuture settableFuture;