package org.opendaylight.netvirt.vpnmanager;
+import static java.util.Collections.emptyList;
import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
import com.google.common.base.Optional;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
+import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Predicate;
import java.util.stream.Collectors;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
import javax.inject.Singleton;
+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.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.genius.mdsalutil.matches.MatchEthernetDestination;
import org.opendaylight.genius.mdsalutil.matches.MatchEthernetType;
import org.opendaylight.genius.mdsalutil.matches.MatchMetadata;
+import org.opendaylight.genius.utils.JvmGlobalLocks;
import org.opendaylight.genius.utils.ServiceIndex;
import org.opendaylight.genius.utils.SystemPropertyReader;
import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
import org.opendaylight.netvirt.vpnmanager.api.VpnExtraRouteHelper;
import org.opendaylight.netvirt.vpnmanager.api.VpnHelper;
import org.opendaylight.netvirt.vpnmanager.iplearn.model.MacEntry;
-import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnAfConfig;
-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.VpnInterfaceBuilder;
import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey;
import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames;
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.IpAddressBuilder;
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.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.VpnInterfaceOpData;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.VpnToExtraroutes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency.AdjacencyType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.AdjacencyKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPortBuilder;
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.napt.switches.RouterToNaptSwitch;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitchKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.VpnAfConfig;
+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.vpn.instances.VpnInstance;
+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.rev150602.NetworkAttributes.NetworkType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NetworkMaps;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NeutronVpnPortipPortData;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMap;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMapKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPort;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPortBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPortKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey;
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.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
import org.opendaylight.yangtools.yang.data.api.schema.tree.ModifiedNodeDoesNotExistException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger LOG = LoggerFactory.getLogger(VpnUtil.class);
public static final int SINGLE_TRANSACTION_BROKER_NO_RETRY = 1;
+ private static Boolean arpLearningEnabled = Boolean.TRUE;
private final DataBroker dataBroker;
private final IdManagerService idManager;
.child(VpnInstance.class, new VpnInstanceKey(vpnName)).build();
}
+ @Nullable
VpnInterface getVpnInterface(String vpnInterfaceName) {
InstanceIdentifier<VpnInterface> id = getVpnInterfaceIdentifier(vpnInterfaceName);
Optional<VpnInterface> vpnInterface = read(LogicalDatastoreType.CONFIGURATION, id);
}
static VpnInterfaceOpDataEntry getVpnInterfaceOpDataEntry(String intfName, String vpnName, AdjacenciesOp aug,
- BigInteger dpnId, long lportTag,
- String gwMac) {
+ Uint64 dpnId, long lportTag,
+ String gwMac, String gwIp) {
return new VpnInterfaceOpDataEntryBuilder().withKey(new VpnInterfaceOpDataEntryKey(intfName, vpnName))
- .setDpnId(dpnId).addAugmentation(AdjacenciesOp.class, aug)
- .setLportTag(lportTag).setGatewayMacAddress(gwMac).build();
+ .setDpnId(dpnId).addAugmentation(AdjacenciesOp.class, aug)
+ .setLportTag(lportTag).setGatewayMacAddress(gwMac).setGatewayIpAddress(gwIp).build();
}
Optional<VpnInterfaceOpDataEntry> getVpnInterfaceOpDataEntry(String vpnInterfaceName, String vpnName) {
return vpnInterfaceOpDataEntry;
}
- static InstanceIdentifier<Prefixes> getPrefixToInterfaceIdentifier(long vpnId, String ipPrefix) {
+ static InstanceIdentifier<Prefixes> getPrefixToInterfaceIdentifier(Uint32 vpnId, String ipPrefix) {
return InstanceIdentifier.builder(PrefixToInterface.class).child(VpnIds.class, new VpnIdsKey(vpnId))
.child(Prefixes.class, new PrefixesKey(ipPrefix)).build();
}
- static InstanceIdentifier<VpnIds> getPrefixToInterfaceIdentifier(long vpnId) {
+ static InstanceIdentifier<VpnIds> getPrefixToInterfaceIdentifier(Uint32 vpnId) {
return InstanceIdentifier.builder(PrefixToInterface.class).child(VpnIds.class, new VpnIdsKey(vpnId)).build();
}
- static Prefixes getPrefixToInterface(BigInteger dpId, String vpnInterfaceName, String ipPrefix,
+ static Prefixes getPrefixToInterface(Uint64 dpId, String vpnInterfaceName, String ipPrefix,
Uuid networkId, NetworkType networkType, Long segmentationId, Prefixes.PrefixCue prefixCue) {
return new PrefixesBuilder().setDpnId(dpId).setVpnInterfaceName(
vpnInterfaceName).setIpAddress(ipPrefix)//.setSubnetId(subnetId)
.setPrefixCue(prefixCue).build();
}
- static Prefixes getPrefixToInterface(BigInteger dpId, String vpnInterfaceName, String ipPrefix,
+ static Prefixes getPrefixToInterface(Uint64 dpId, String vpnInterfaceName, String ipPrefix,
Prefixes.PrefixCue prefixCue) {
return new PrefixesBuilder().setDpnId(dpId).setVpnInterfaceName(vpnInterfaceName).setIpAddress(ipPrefix)
.setPrefixCue(prefixCue).build();
}
- Optional<Prefixes> getPrefixToInterface(long vpnId, String ipPrefix) {
+ Optional<Prefixes> getPrefixToInterface(Uint32 vpnId, String ipPrefix) {
return read(LogicalDatastoreType.OPERATIONAL, getPrefixToInterfaceIdentifier(vpnId, getIpPrefix(ipPrefix)));
}
* @param rd Route-Distinguisher
* @return VrfTables that holds the list of VrfEntries of the specified rd
*/
+ @Nullable
VrfTables getVrfTable(String rd) {
InstanceIdentifier<VrfTables> id = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class,
new VrfTablesKey(rd)).build();
*/
public List<VrfEntry> getAllVrfEntries(String rd) {
VrfTables vrfTables = getVrfTable(rd);
- return vrfTables != null ? vrfTables.getVrfEntry() : new ArrayList<>();
+ if (vrfTables != null && vrfTables.getVrfEntry() != null) {
+ return vrfTables.getVrfEntry();
+ }
+ return emptyList();
}
//FIXME: Implement caches for DS reads
+ @Nullable
public VpnInstance getVpnInstance(String vpnInstanceName) {
InstanceIdentifier<VpnInstance> id = InstanceIdentifier.builder(VpnInstances.class).child(VpnInstance.class,
new VpnInstanceKey(vpnInstanceName)).build();
return vpnInstance.isPresent() ? vpnInstance.get() : null;
}
+ @NonNull
+ @SuppressWarnings("checkstyle:IllegalCatch")
List<VpnInstanceOpDataEntry> getAllVpnInstanceOpData() {
- InstanceIdentifier<VpnInstanceOpData> id = InstanceIdentifier.builder(VpnInstanceOpData.class).build();
- Optional<VpnInstanceOpData> vpnInstanceOpDataOptional = read(LogicalDatastoreType.OPERATIONAL, id);
- return vpnInstanceOpDataOptional.isPresent() ? vpnInstanceOpDataOptional.get().getVpnInstanceOpDataEntry()
- : Collections.emptyList();
+ try {
+ InstanceIdentifier<VpnInstanceOpData> id = InstanceIdentifier.builder(VpnInstanceOpData.class).build();
+ Optional<VpnInstanceOpData> vpnInstanceOpDataOptional = read(LogicalDatastoreType.OPERATIONAL, id);
+ return
+ vpnInstanceOpDataOptional.isPresent() && vpnInstanceOpDataOptional.get()
+ .getVpnInstanceOpDataEntry() != null ? vpnInstanceOpDataOptional.get()
+ .getVpnInstanceOpDataEntry() : emptyList();
+ } catch (Exception e) {
+ LOG.error("getAllVpnInstanceOpData: Could not retrieve all vpn instance op data subtree...", e);
+ return emptyList();
+ }
}
+ @NonNull
List<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data
.vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfaces> getDpnVpnInterfaces(VpnInstance vpnInstance,
- BigInteger dpnId) {
+ Uint64 dpnId) {
String primaryRd = getPrimaryRd(vpnInstance);
InstanceIdentifier<VpnToDpnList> dpnToVpnId = VpnHelper.getVpnToDpnListIdentifier(primaryRd, dpnId);
Optional<VpnToDpnList> dpnInVpn = read(LogicalDatastoreType.OPERATIONAL, dpnToVpnId);
- return dpnInVpn.isPresent() ? dpnInVpn.get().getVpnInterfaces() : Collections.emptyList();
+ return dpnInVpn.isPresent() && dpnInVpn.get().getVpnInterfaces() != null ? dpnInVpn.get().getVpnInterfaces()
+ : emptyList();
}
+ @NonNull
static List<String> getListOfRdsFromVpnInstance(VpnInstance vpnInstance) {
VpnAfConfig vpnConfig = vpnInstance.getIpv4Family();
LOG.trace("vpnConfig {}", vpnConfig);
- return vpnConfig.getRouteDistinguisher() != null ? vpnConfig.getRouteDistinguisher() : Collections.emptyList();
+ return vpnConfig.getRouteDistinguisher() != null && vpnConfig.getRouteDistinguisher() != null
+ ? vpnConfig.getRouteDistinguisher() : emptyList();
}
+ @Nullable
VrfEntry getVrfEntry(String rd, String ipPrefix) {
VrfTables vrfTable = getVrfTable(rd);
// TODO: why check VrfTables if we later go for the specific VrfEntry?
return null;
}
+ @Nullable
public List<Adjacency> getAdjacenciesForVpnInterfaceFromConfig(String intfName) {
final InstanceIdentifier<VpnInterface> identifier = getVpnInterfaceIdentifier(intfName);
InstanceIdentifier<Adjacencies> path = identifier.augmentation(Adjacencies.class);
Optional<Adjacencies> adjacencies = read(LogicalDatastoreType.CONFIGURATION, path);
if (adjacencies.isPresent()) {
- List<Adjacency> nextHops = adjacencies.get().getAdjacency();
- return nextHops;
+ return adjacencies.get().getAdjacency();
}
return null;
}
return new RoutesBuilder().setPrefix(ipPrefix).setNexthopIpList(nextHopList).build();
}
- String getVpnInterfaceName(BigInteger metadata) throws InterruptedException, ExecutionException {
+ @Nullable
+ String getVpnInterfaceName(Uint64 metadata) throws InterruptedException, ExecutionException {
GetInterfaceFromIfIndexInputBuilder ifIndexInputBuilder = new GetInterfaceFromIfIndexInputBuilder();
- BigInteger lportTag = MetaDataUtil.getLportFromMetadata(metadata);
+ Uint64 lportTag = MetaDataUtil.getLportFromMetadata(metadata);
ifIndexInputBuilder.setIfIndex(lportTag.intValue());
GetInterfaceFromIfIndexInput input = ifIndexInputBuilder.build();
Future<RpcResult<GetInterfaceFromIfIndexOutput>> interfaceFromIfIndex =
new InterfaceKey(interfaceName)).build();
}
- public static BigInteger getCookieL3(int vpnId) {
- return VpnConstants.COOKIE_L3_BASE.add(new BigInteger("0610000", 16)).add(BigInteger.valueOf(vpnId));
+ public static Uint64 getCookieL3(int vpnId) {
+ return Uint64.valueOf(VpnConstants.COOKIE_L3_BASE.toJava().add(new BigInteger("0610000", 16))
+ .add(BigInteger.valueOf(vpnId)));
}
- public int getUniqueId(String poolName, String idKey) {
+ public Uint32 getUniqueId(String poolName, String idKey) {
AllocateIdInput getIdInput = new AllocateIdInputBuilder().setPoolName(poolName).setIdKey(idKey).build();
try {
Future<RpcResult<AllocateIdOutput>> result = idManager.allocateId(getIdInput);
RpcResult<AllocateIdOutput> rpcResult = result.get();
if (rpcResult.isSuccessful()) {
- return rpcResult.getResult().getIdValue().intValue();
+ return rpcResult.getResult().getIdValue();
} else {
LOG.error("getUniqueId: RPC Call to Get Unique Id from pool {} with key {} returned with Errors {}",
poolName, idKey, rpcResult.getErrors());
} catch (InterruptedException | ExecutionException e) {
LOG.error("getUniqueId: Exception when getting Unique Id from pool {} for key {}", poolName, idKey, e);
}
- return 0;
+ return Uint32.ZERO;
}
void releaseId(String poolName, String idKey) {
* @param vpnName Name of the VPN
* @return the dataplane identifier of the VPN, the VrfTag.
*/
- public long getVpnId(String vpnName) {
+ public Uint32 getVpnId(String vpnName) {
if (vpnName == null) {
return VpnConstants.INVALID_ID;
}
return read(LogicalDatastoreType.CONFIGURATION, VpnOperDsUtils.getVpnInstanceToVpnIdIdentifier(vpnName))
.toJavaUtil().map(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911
- .vpn.instance.to.vpn.id.VpnInstance::getVpnId).orElse(VpnConstants.INVALID_ID);
+ .vpn.instance.to.vpn.id.VpnInstance::getVpnId)
+ .orElse(VpnConstants.INVALID_ID);
}
/**
ListenableFutures.addErrorLogging(
new ManagedNewTransactionRunnerImpl(dataBroker).callWithNewWriteOnlyTransactionAndSubmit(
Datastore.CONFIGURATION, tx -> {
- for (VrfEntry vrfEntry : vrfTables.getVrfEntry()) {
+ for (VrfEntry vrfEntry : vrfTables.nonnullVrfEntry()) {
if (origin == RouteOrigin.value(vrfEntry.getOrigin())) {
tx.delete(vpnVrfTableIid.child(VrfEntry.class, vrfEntry.key()));
}
List<VrfEntry> matches = new ArrayList<>();
if (vrfTablesOpc.isPresent()) {
VrfTables vrfTables = vrfTablesOpc.get();
- for (VrfEntry vrfEntry : vrfTables.getVrfEntry()) {
- vrfEntry.getRoutePaths().stream()
+ for (VrfEntry vrfEntry : vrfTables.nonnullVrfEntry()) {
+ vrfEntry.nonnullRoutePaths().stream()
.filter(routePath -> routePath.getNexthopAddress() != null && routePath.getNexthopAddress()
.equals(nexthop)).findFirst().ifPresent(routePath -> matches.add(vrfEntry));
}
MDSALUtil.syncDelete(dataBroker,
LogicalDatastoreType.CONFIGURATION, VpnExtraRouteHelper.getUsedRdsIdentifier(getVpnId(vpnName),
prefix, nextHop));
- LOG.debug("removeOrUpdateDSForExtraRoute: Removed vpn-to-extraroute with rd {} prefix {} nexthop {}",
+ LOG.info("removeOrUpdateDSForExtraRoute: Removed vpn-to-extraroute with rd {} prefix {} nexthop {}",
extraRouteRd, prefix, nextHop);
fibManager.refreshVrfEntry(primaryRd, prefix);
operTx.delete(VpnUtil.getVpnInterfaceOpDataEntryAdjacencyIdentifier(vpnInterfaceName, vpnName, prefix));
}
static org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance
- getVpnInstanceToVpnId(String vpnName, long vpnId, String rd) {
+ getVpnInstanceToVpnId(String vpnName, Uint32 vpnId, String rd) {
return new VpnInstanceBuilder().setVpnId(vpnId).setVpnInstanceName(vpnName).setVrfId(rd).build();
}
static org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.id.to.vpn.instance.VpnIds
- getVpnIdToVpnInstance(long vpnId, String vpnName, String rd, boolean isExternalVpn) {
+ getVpnIdToVpnInstance(Uint32 vpnId, String vpnName, String rd, boolean isExternalVpn) {
return new org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.id.to.vpn.instance
.VpnIdsBuilder().setVpnId(vpnId).setVpnInstanceName(vpnName).setVrfId(rd).setExternalVpn(isExternalVpn)
.build();
}
static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.id.to
- .vpn.instance.VpnIds> getVpnIdToVpnInstanceIdentifier(long vpnId) {
+ .vpn.instance.VpnIds> getVpnIdToVpnInstanceIdentifier(Uint32 vpnId) {
return InstanceIdentifier.builder(VpnIdToVpnInstance.class).child(org.opendaylight.yang.gen.v1.urn
.opendaylight.netvirt.l3vpn.rev130911.vpn.id.to.vpn.instance.VpnIds.class,
new org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.id.to.vpn.instance
* @param vpnId Dataplane identifier of the VPN
* @return the Vpn instance name
*/
- String getVpnName(long vpnId) {
+ @Nullable
+ String getVpnName(Uint32 vpnId) {
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.id.to.vpn
.instance.VpnIds> id = getVpnIdToVpnInstanceIdentifier(vpnId);
.child(VpnInstanceOpDataEntry.class, new VpnInstanceOpDataEntryKey(rd)).build();
}
+ @Nullable
public VpnInstanceOpDataEntry getVpnInstanceOpData(String rd) {
- InstanceIdentifier<VpnInstanceOpDataEntry> id = getVpnInstanceOpDataIdentifier(rd);
- return read(LogicalDatastoreType.OPERATIONAL, id).orNull();
+ return read(LogicalDatastoreType.OPERATIONAL, getVpnInstanceOpDataIdentifier(rd)).orNull();
}
+ @Nullable
VpnInterface getConfiguredVpnInterface(String interfaceName) {
InstanceIdentifier<VpnInterface> interfaceId = getVpnInterfaceIdentifier(interfaceName);
Optional<VpnInterface> configuredVpnInterface = read(LogicalDatastoreType.CONFIGURATION, interfaceId);
}
public static String getIpPrefix(String prefix) {
- String[] prefixValues = prefix.split("/");
- if (prefixValues.length == 1) {
- prefix = NWUtil.toIpPrefix(prefix);
- }
- return prefix;
+ return prefix.indexOf('/') != -1 ? prefix : NWUtil.toIpPrefix(prefix);
}
static final FutureCallback<Void> DEFAULT_CALLBACK =
}
// interface-index-tag operational container
+ @Nullable
IfIndexInterface getInterfaceInfoByInterfaceTag(long interfaceTag) {
InstanceIdentifier<IfIndexInterface> interfaceId = getInterfaceInfoEntriesOperationalDataPath(interfaceTag);
Optional<IfIndexInterface> existingInterfaceInfo = read(LogicalDatastoreType.OPERATIONAL, interfaceId);
new IfIndexInterfaceKey((int) interfaceTag)).build();
}
+ @Nullable
ElanTagName getElanInfoByElanTag(long elanTag) {
InstanceIdentifier<ElanTagName> elanId = getElanInfoEntriesOperationalDataPath(elanTag);
Optional<ElanTagName> existingElanInfo = read(LogicalDatastoreType.OPERATIONAL, elanId);
new ElanTagNameKey(elanTag)).build();
}
- static void removePrefixToInterfaceForVpnId(long vpnId, @Nonnull TypedWriteTransaction<Operational> operTx) {
+ static void removePrefixToInterfaceForVpnId(Uint32 vpnId, @NonNull TypedWriteTransaction<Operational> operTx) {
// Clean up PrefixToInterface Operational DS
operTx.delete(InstanceIdentifier.builder(
PrefixToInterface.class).child(VpnIds.class, new VpnIdsKey(vpnId)).build());
}
- static void removeVpnExtraRouteForVpn(String vpnName, @Nonnull TypedWriteTransaction<Operational> operTx) {
+ static void removeVpnExtraRouteForVpn(String vpnName, @NonNull TypedWriteTransaction<Operational> operTx) {
// Clean up VPNExtraRoutes Operational DS
operTx.delete(InstanceIdentifier.builder(VpnToExtraroutes.class).child(Vpn.class, new VpnKey(vpnName)).build());
}
@SuppressWarnings("checkstyle:IllegalCatch")
- static void removeVpnOpInstance(String vpnName, @Nonnull TypedWriteTransaction<Operational> operTx) {
+ static void removeVpnOpInstance(String vpnName, @NonNull TypedWriteTransaction<Operational> operTx) {
// Clean up VPNInstanceOpDataEntry
operTx.delete(getVpnInstanceOpDataIdentifier(vpnName));
}
- static void removeVpnInstanceToVpnId(String vpnName, @Nonnull TypedWriteTransaction<Configuration> confTx) {
+ static void removeVpnInstanceToVpnId(String vpnName, @NonNull TypedWriteTransaction<Configuration> confTx) {
confTx.delete(VpnOperDsUtils.getVpnInstanceToVpnIdIdentifier(vpnName));
}
- static void removeVpnIdToVpnInstance(long vpnId, @Nonnull TypedWriteTransaction<Configuration> confTx) {
+ static void removeVpnIdToVpnInstance(Uint32 vpnId, @NonNull TypedWriteTransaction<Configuration> confTx) {
confTx.delete(getVpnIdToVpnInstanceIdentifier(vpnId));
}
- static void removeL3nexthopForVpnId(long vpnId, @Nonnull TypedWriteTransaction<Operational> operTx) {
+ static void removeL3nexthopForVpnId(Uint32 vpnId, @NonNull TypedWriteTransaction<Operational> operTx) {
// Clean up L3NextHop Operational DS
operTx.delete(InstanceIdentifier.builder(L3nexthop.class).child(
VpnNexthops.class, new VpnNexthopsKey(vpnId)).build());
}
- void scheduleVpnInterfaceForRemoval(String interfaceName, BigInteger dpnId, String vpnInstanceName,
- TypedWriteTransaction<Operational> writeOperTxn) {
+ void scheduleVpnInterfaceForRemoval(String interfaceName, Uint64 dpnId, String vpnInstanceName,
+ @Nullable TypedWriteTransaction<Operational> writeOperTxn) {
InstanceIdentifier<VpnInterfaceOpDataEntry> interfaceId =
getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnInstanceName);
VpnInterfaceOpDataEntry interfaceToUpdate =
public void createLearntVpnVipToPort(String vpnName, String fixedIp, String portName, String macAddress,
TypedWriteTransaction<Operational> writeOperTxn) {
- synchronized ((vpnName + fixedIp).intern()) {
- InstanceIdentifier<LearntVpnVipToPort> id = buildLearntVpnVipToPortIdentifier(vpnName, fixedIp);
+ final InstanceIdentifier<LearntVpnVipToPort> id = buildLearntVpnVipToPortIdentifier(vpnName, fixedIp);
+ final ReentrantLock lock = lockFor(vpnName, fixedIp);
+ lock.lock();
+ try {
LearntVpnVipToPortBuilder builder =
new LearntVpnVipToPortBuilder().withKey(new LearntVpnVipToPortKey(fixedIp, vpnName)).setVpnName(
vpnName).setPortFixedip(fixedIp).setPortName(portName)
}
LOG.debug("createLearntVpnVipToPort: ARP/NA learned for fixedIp: {}, vpn {}, interface {}, mac {},"
+ " added to LearntVpnVipToPort DS", fixedIp, vpnName, portName, macAddress);
+ } finally {
+ lock.unlock();
}
}
}
void removeLearntVpnVipToPort(String vpnName, String fixedIp,
- TypedWriteTransaction<Operational> writeOperTxn) {
- synchronized ((vpnName + fixedIp).intern()) {
- InstanceIdentifier<LearntVpnVipToPort> id = buildLearntVpnVipToPortIdentifier(vpnName, fixedIp);
+ @Nullable TypedWriteTransaction<Operational> writeOperTxn) {
+ final InstanceIdentifier<LearntVpnVipToPort> id = buildLearntVpnVipToPortIdentifier(vpnName, fixedIp);
+ final ReentrantLock lock = lockFor(vpnName, fixedIp);
+ lock.lock();
+ try {
if (writeOperTxn != null) {
writeOperTxn.delete(id);
} else {
}
LOG.debug("removeLearntVpnVipToPort: Deleted LearntVpnVipToPort entry for fixedIp: {}, vpn {}",
fixedIp, vpnName);
+ } finally {
+ lock.unlock();
}
}
protected static void removeVpnPortFixedIpToPort(DataBroker broker, String vpnName, String fixedIp,
- TypedWriteTransaction<Configuration> writeConfigTxn) {
- synchronized ((vpnName + fixedIp).intern()) {
- InstanceIdentifier<VpnPortipToPort> id = buildVpnPortipToPortIdentifier(vpnName, fixedIp);
+ @Nullable TypedWriteTransaction<Configuration> writeConfigTxn) {
+ final InstanceIdentifier<VpnPortipToPort> id = buildVpnPortipToPortIdentifier(vpnName, fixedIp);
+ final ReentrantLock lock = lockFor(vpnName, fixedIp);
+ lock.lock();
+ try {
if (writeConfigTxn != null) {
writeConfigTxn.delete(id);
} else {
}
LOG.debug("removeVpnPortFixedIpToPort: Deleted VpnPortipToPort entry for fixedIp: {}, vpn {}",
fixedIp, vpnName);
+ } finally {
+ lock.unlock();
}
}
return id;
}
- public void removeLearntVpnVipToPortEvent(String eventId, TypedWriteTransaction<Operational> writeOperTxn) {
+ public void removeLearntVpnVipToPortEvent(String eventId,
+ @Nullable TypedWriteTransaction<Operational> writeOperTxn) {
InstanceIdentifier<LearntVpnVipToPortEvent> id = buildLearntVpnVipToPortEventIdentifier(eventId);
if (writeOperTxn != null) {
writeOperTxn.delete(id);
}
+ // TODO Clean up the exception handling
+ @SuppressWarnings("checkstyle:IllegalCatch")
public void removeMipAdjAndLearntIp(String vpnName, String vpnInterface, String prefix) {
- synchronized ((vpnName + prefix).intern()) {
- InstanceIdentifier<LearntVpnVipToPort> id = buildLearntVpnVipToPortIdentifier(vpnName, prefix);
- MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
- LOG.info("removeMipAdjAndLearntIp: Delete learned ARP for fixedIp: {}, vpn {} removed from"
- + "VpnPortipToPort DS", prefix, vpnName);
+ final ReentrantLock lock = lockFor(vpnName, prefix);
+ lock.lock();
+ try {
String ip = VpnUtil.getIpPrefix(prefix);
InstanceIdentifier<VpnInterfaceOpDataEntry> vpnInterfaceOpId = VpnUtil
.getVpnInterfaceOpDataEntryIdentifier(vpnInterface, vpnName);
Optional<AdjacenciesOp> adjacenciesOp = read(LogicalDatastoreType.OPERATIONAL, path);
if (adjacenciesOp.isPresent()) {
InstanceIdentifier<Adjacency> adjacencyIdentifier = InstanceIdentifier.builder(VpnInterfaces.class)
- .child(VpnInterface.class, new VpnInterfaceKey(vpnInterface)).augmentation(Adjacencies.class)
- .child(Adjacency.class, new AdjacencyKey(ip)).build();
+ .child(VpnInterface.class, new VpnInterfaceKey(vpnInterface))
+ .augmentation(Adjacencies.class).child(Adjacency.class, new AdjacencyKey(ip)).build();
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, adjacencyIdentifier);
LOG.info("removeMipAdjAndLearntIp: Successfully Deleted Adjacency {} from interface {} vpn {}", ip,
- vpnInterface, vpnName);
+ vpnInterface, vpnName);
}
+ InstanceIdentifier<LearntVpnVipToPort> id = buildLearntVpnVipToPortIdentifier(vpnName, prefix);
+ MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
+ LOG.info("removeMipAdjAndLearntIp: Delete learned ARP for fixedIp: {}, vpn {} removed from"
+ + "VpnPortipToPort DS", prefix, vpnName);
+ } catch (Exception e) {
+ LOG.error("removeMipAdjAndLearntIp: Exception Deleting learned Ip: {} interface {} vpn {} from "
+ + "LearntVpnPortipToPort DS", prefix, vpnInterface, vpnName, e);
+ } finally {
+ lock.unlock();
}
+ VpnUtil.removeVpnPortFixedIpToPort(dataBroker, vpnName, prefix, null);
}
public void removeMipAdjacency(String vpnInterface, String ipAddress) {
new VpnPortipToPortKey(fixedIp, vpnName)).build();
}
+ @Nullable
public VpnPortipToPort getNeutronPortFromVpnPortFixedIp(String vpnName, String fixedIp) {
InstanceIdentifier<VpnPortipToPort> id = buildVpnPortipToPortIdentifier(vpnName, fixedIp);
Optional<VpnPortipToPort> vpnPortipToPortData = read(LogicalDatastoreType.CONFIGURATION, id);
return null;
}
+ @Nullable
public static VpnPortipToPort getNeutronPortFromVpnPortFixedIp(TypedReadTransaction<Configuration> confTx,
String vpnName, String fixedIp) {
InstanceIdentifier<VpnPortipToPort> id = buildVpnPortipToPortIdentifier(vpnName, fixedIp);
}
}
+ @Nullable
public LearntVpnVipToPort getLearntVpnVipToPort(String vpnName, String fixedIp) {
InstanceIdentifier<LearntVpnVipToPort> id = buildLearntVpnVipToPortIdentifier(vpnName, fixedIp);
Optional<LearntVpnVipToPort> learntVpnVipToPort = read(LogicalDatastoreType.OPERATIONAL, id);
return null;
}
- @Nonnull
- List<BigInteger> getDpnsOnVpn(String vpnInstanceName) {
- List<BigInteger> result = new ArrayList<>();
+ @NonNull
+ List<Uint64> getDpnsOnVpn(String vpnInstanceName) {
+ List<Uint64> result = new ArrayList<>();
String rd = getVpnRd(vpnInstanceName);
if (rd == null) {
LOG.debug("getDpnsOnVpn: Could not find Route-Distinguisher for VpnName={}", vpnInstanceName);
return result;
}
+ @Nullable
String getAssociatedExternalRouter(String extIp) {
InstanceIdentifier<ExtRouters> extRouterInstanceIndentifier =
InstanceIdentifier.builder(ExtRouters.class).build();
Optional<ExtRouters> extRouterData = read(LogicalDatastoreType.CONFIGURATION, extRouterInstanceIndentifier);
- if (extRouterData.isPresent()) {
- for (Routers routerData : extRouterData.get().getRouters()) {
- List<ExternalIps> externalIps = routerData.getExternalIps();
+ if (!extRouterData.isPresent()) {
+ return null;
+ }
+
+ // We need to find the router associated with the src ip of this packet.
+ // This case is either SNAT, in which case the src ip is the same as the
+ // router's external ip, or FIP in which case the src ip is in the router's
+ // external leg's subnet. We first check the SNAT case because it is much
+ // cheaper to do so because it does not require (potentially, there is a
+ // cache) an datastore read of the neutron subnet for each external IP.
+
+ String routerName = null;
+
+ for (Routers routerData : extRouterData.get().nonnullRouters()) {
+ List<ExternalIps> externalIps = routerData.nonnullExternalIps();
+ for (ExternalIps externalIp : externalIps) {
+ if (Objects.equals(externalIp.getIpAddress(), extIp)) {
+ routerName = routerData.getRouterName();
+ break;
+ }
+ }
+ }
+
+ if (routerName != null) {
+ return routerName;
+ }
+
+ for (Routers routerData : extRouterData.get().nonnullRouters()) {
+ List<ExternalIps> externalIps = routerData.nonnullExternalIps();
+ for (ExternalIps externalIp : externalIps) {
+ Subnet neutronSubnet = neutronVpnService.getNeutronSubnet(externalIp.getSubnetId());
+ if (neutronSubnet == null) {
+ LOG.warn("Failed to retrieve subnet {} referenced by router {}",
+ externalIp.getSubnetId(), routerData);
+ continue;
+ }
+ if (NWUtil.isIpAddressInRange(IpAddressBuilder.getDefaultInstance(extIp), neutronSubnet.getCidr())) {
+ routerName = routerData.getRouterName();
+ break;
+ }
+ }
+ }
+
+ return routerName;
+ }
+
+ @Nullable
+ public String getAssociatedExternalSubnet(String extIp) {
+ InstanceIdentifier<ExtRouters> extRouterInstanceIndentifier =
+ InstanceIdentifier.builder(ExtRouters.class).build();
+ Optional<ExtRouters> extRouterData = read(LogicalDatastoreType.CONFIGURATION, extRouterInstanceIndentifier);
+ if (!extRouterData.isPresent() || extRouterData.get().getRouters() == null) {
+ return null;
+ }
+ for (Routers routerData : extRouterData.get().getRouters()) {
+ List<ExternalIps> externalIps = routerData.getExternalIps();
+ if (externalIps != null) {
for (ExternalIps externalIp : externalIps) {
- if (externalIp.getIpAddress().equals(extIp)) {
- return routerData.getRouterName();
+ Subnet neutronSubnet = neutronVpnService.getNeutronSubnet(externalIp.getSubnetId());
+ if (neutronSubnet == null) {
+ LOG.warn("Failed to retrieve subnet {} referenced by router {}",
+ externalIp.getSubnetId(), routerData);
+ continue;
+ }
+ if (NWUtil.isIpAddressInRange(IpAddressBuilder.getDefaultInstance(extIp),
+ neutronSubnet.getCidr())) {
+ return neutronSubnet.getUuid().getValue();
}
}
}
return InstanceIdentifier.builder(ExtRouters.class).child(Routers.class, new RoutersKey(routerId)).build();
}
+ @Nullable
Networks getExternalNetwork(Uuid networkId) {
InstanceIdentifier<Networks> netsIdentifier = InstanceIdentifier.builder(ExternalNetworks.class)
.child(Networks.class, new NetworksKey(networkId)).build();
return optionalNets.isPresent() ? optionalNets.get() : null;
}
+ @Nullable
Uuid getExternalNetworkVpnId(Uuid networkId) {
Networks extNetwork = getExternalNetwork(networkId);
return extNetwork != null ? extNetwork.getVpnid() : null;
}
+ @NonNull
public List<Uuid> getExternalNetworkRouterIds(Uuid networkId) {
Networks extNetwork = getExternalNetwork(networkId);
- return extNetwork != null ? extNetwork.getRouterIds() : Collections.emptyList();
+ return extNetwork != null && extNetwork.getRouterIds() != null ? extNetwork.getRouterIds() : emptyList();
}
+ @Nullable
Routers getExternalRouter(String routerId) {
InstanceIdentifier<Routers> id = InstanceIdentifier.builder(ExtRouters.class).child(Routers.class,
new RoutersKey(routerId)).build();
return InstanceIdentifier.create(Subnetmaps.class);
}
- FlowEntity buildL3vpnGatewayFlow(BigInteger dpId, String gwMacAddress, long vpnId,
- long subnetVpnId) {
+ FlowEntity buildL3vpnGatewayFlow(Uint64 dpId, String gwMacAddress, Uint32 vpnId,
+ Uint32 subnetVpnId) {
List<MatchInfo> mkMatches = new ArrayList<>();
Subnetmap smap = null;
- mkMatches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
+ mkMatches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId.longValue()),
+ MetaDataUtil.METADATA_MASK_VRFID));
mkMatches.add(new MatchEthernetDestination(new MacAddress(gwMacAddress)));
List<InstructionInfo> mkInstructions = new ArrayList<>();
mkInstructions.add(new InstructionGotoTable(NwConstants.L3_FIB_TABLE));
- if (subnetVpnId != VpnConstants.INVALID_ID) {
+ if (!VpnConstants.INVALID_ID.equals(subnetVpnId)) {
String vpnName = getVpnName(subnetVpnId);
if (vpnName != null) {
smap = getSubnetmapFromItsUuid(Uuid.getDefaultInstance(vpnName));
}
}
}
- BigInteger subnetIdMetaData = MetaDataUtil.getVpnIdMetadata(subnetVpnId);
+ Uint64 subnetIdMetaData = MetaDataUtil.getVpnIdMetadata(subnetVpnId.longValue());
mkInstructions.add(new InstructionWriteMetadata(subnetIdMetaData, MetaDataUtil.METADATA_MASK_VRFID));
}
String flowId = getL3VpnGatewayFlowRef(NwConstants.L3_GW_MAC_TABLE, dpId, vpnId, gwMacAddress, subnetVpnId);
return MDSALUtil.buildFlowEntity(dpId, NwConstants.L3_GW_MAC_TABLE,
- flowId, 20, flowId, 0, 0, NwConstants.COOKIE_L3_GW_MAC_TABLE, mkMatches, mkInstructions);
+ flowId, 20, flowId, 0, 0, NwConstants.COOKIE_L3_GW_MAC_TABLE,
+ mkMatches, mkInstructions);
}
- static String getL3VpnGatewayFlowRef(short l3GwMacTable, BigInteger dpId, long vpnId, String gwMacAddress,
- long subnetVpnId) {
+ static String getL3VpnGatewayFlowRef(short l3GwMacTable, Uint64 dpId, Uint32 vpnId, String gwMacAddress,
+ Uint32 subnetVpnId) {
return gwMacAddress + NwConstants.FLOWID_SEPARATOR + vpnId + NwConstants.FLOWID_SEPARATOR + dpId
+ NwConstants.FLOWID_SEPARATOR + l3GwMacTable + NwConstants.FLOWID_SEPARATOR + subnetVpnId;
}
}
private boolean doesInterfaceAndHiddenIpAddressTypeMatch(InetAddress hiddenIp, FixedIps portIp) {
- return (hiddenIp instanceof Inet4Address && portIp.getIpAddress().getIpv4Address() != null)
+ return hiddenIp instanceof Inet4Address && portIp.getIpAddress().getIpv4Address() != null
|| hiddenIp instanceof Inet6Address && portIp.getIpAddress().getIpv6Address() != null;
}
public Optional<String> getGWMacAddressFromInterface(MacEntry macEntry, IpAddress gatewayIp) {
Optional<String> gatewayMac = Optional.absent();
- long vpnId = getVpnId(macEntry.getVpnName());
+ Uint32 vpnId = getVpnId(macEntry.getVpnName());
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.id.to.vpn
.instance.VpnIds>
vpnIdsInstanceIdentifier = VpnUtil.getVpnIdToVpnInstanceIdentifier(vpnId);
return gatewayMac;
}
- void setupGwMacIfExternalVpn(BigInteger dpnId, String interfaceName, long vpnId,
+ void setupGwMacIfExternalVpn(Uint64 dpnId, String interfaceName, Uint32 vpnId,
TypedReadWriteTransaction<Configuration> writeInvTxn, int addOrRemove, String gwMac)
throws ExecutionException, InterruptedException {
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.id.to.vpn.instance
interfaceName, dpnId.toString(), vpnIdsOptional.get().getVpnInstanceName());
return;
}
- FlowEntity flowEntity = buildL3vpnGatewayFlow(dpnId, gwMac, vpnId, VpnConstants.INVALID_ID);
+ FlowEntity flowEntity = buildL3vpnGatewayFlow(dpnId, gwMac, vpnId,VpnConstants.INVALID_ID);
if (addOrRemove == NwConstants.ADD_FLOW) {
mdsalManager.addFlow(writeInvTxn, flowEntity);
} else if (addOrRemove == NwConstants.DEL_FLOW) {
final Optional<Subnet> subnet = read(LogicalDatastoreType.CONFIGURATION, subnetidentifier);
if (subnet.isPresent()) {
Class<? extends IpVersionBase> ipVersionBase = subnet.get().getIpVersion();
- if (ipVersionBase.equals(IpVersionV4.class)) {
+ if (IpVersionV4.class.equals(ipVersionBase)) {
Subnetmap subnetmap = getSubnetmapFromItsUuid(subnetUuid);
if (subnetmap != null && subnetmap.getRouterInterfaceFixedIp() != null) {
LOG.trace("getVpnSubnetGatewayIp: Obtained subnetMap {} for vpn interface",
return gwIpAddress;
}
+ @Nullable
RouterToNaptSwitch getRouterToNaptSwitch(String routerName) {
InstanceIdentifier<RouterToNaptSwitch> id = InstanceIdentifier.builder(NaptSwitches.class)
.child(RouterToNaptSwitch.class, new RouterToNaptSwitchKey(routerName)).build();
}
- BigInteger getPrimarySwitchForRouter(String routerName) {
+ @Nullable
+ Uint64 getPrimarySwitchForRouter(String routerName) {
RouterToNaptSwitch routerToNaptSwitch = getRouterToNaptSwitch(routerName);
return routerToNaptSwitch != null ? routerToNaptSwitch.getPrimarySwitchId() : null;
}
- static boolean isL3VpnOverVxLan(Long l3Vni) {
- return l3Vni != null && l3Vni != 0;
+ static boolean isL3VpnOverVxLan(Uint32 l3Vni) {
+ return l3Vni != null && l3Vni.longValue() != 0;
}
/**
return !vpnName.equals(primaryRd);
}
- java.util.Optional<String> allocateRdForExtraRouteAndUpdateUsedRdsMap(long vpnId, @Nullable Long parentVpnId,
+ java.util.Optional<String> allocateRdForExtraRouteAndUpdateUsedRdsMap(Uint32 vpnId, @Nullable Uint32 parentVpnId,
String prefix, String vpnName,
- String nextHop, BigInteger dpnId) {
+ String nextHop, Uint64 dpnId) {
//Check if rd is already allocated for this extraroute behind the same VM. If yes, reuse it.
//This is particularly useful during reboot scenarios.
java.util.Optional<String> allocatedRd = VpnExtraRouteHelper
} else {
LOG.trace("Removing used rds {} from available rds {} vpnid {} . prefix is {} , vpname- {}, dpnId- {}",
usedRds, availableRds, vpnId, prefix, vpnName, dpnId);
- availableRds.removeAll(usedRds);
+ if (!usedRds.isEmpty()) {
+ availableRds.removeAll(usedRds);
+ }
if (availableRds.isEmpty()) {
LOG.error("No rd available from VpnInstance to allocate for prefix {}", prefix);
return java.util.Optional.empty();
.augmentation(Adjacencies.class).child(Adjacency.class, new AdjacencyKey(ipAddress)).build();
}
- static InstanceIdentifier<Adjacency> getVpnInterfaceOpDataEntryAdjacencyIdentifier(String intfName, String vpnName,
- String ipAddress) {
+ static InstanceIdentifier<Adjacency> getVpnInterfaceOpDataEntryAdjacencyIdentifier(String intfName,
+ String vpnName,
+ String ipAddress) {
+ LOG.debug("getVpnInterfaceOpDataEntryAdjacencyIdentifier intfName {}, vpnName {}, ipAddress {}",
+ intfName, vpnName, ipAddress);
return InstanceIdentifier.builder(VpnInterfaceOpData.class)
- .child(VpnInterfaceOpDataEntry.class, new VpnInterfaceOpDataEntryKey(intfName, vpnName))
- .augmentation(AdjacenciesOp.class).child(Adjacency.class, new AdjacencyKey(ipAddress)).build();
+ .child(VpnInterfaceOpDataEntry.class, new VpnInterfaceOpDataEntryKey(intfName, vpnName))
+ .augmentation(AdjacenciesOp.class).child(Adjacency.class, new AdjacencyKey(ipAddress)).build();
}
public static List<String> getIpsListFromExternalIps(List<ExternalIps> externalIps) {
if (externalIps == null) {
- return Collections.emptyList();
+ return emptyList();
}
return externalIps.stream().map(ExternalIps::getIpAddress).collect(Collectors.toList());
BoundServices getBoundServicesForVpnInterface(String vpnName, String interfaceName) {
List<Instruction> instructions = new ArrayList<>();
int instructionKey = 0;
- final long vpnId = getVpnId(vpnName);
+ final Uint32 vpnId = getVpnId(vpnName);
List<Action> actions = Collections.singletonList(
- new ActionRegLoad(0, VpnConstants.VPN_REG_ID, 0, VpnConstants.VPN_ID_LENGTH, vpnId).buildAction());
+ new ActionRegLoad(0, VpnConstants.VPN_REG_ID, 0, VpnConstants.VPN_ID_LENGTH, vpnId.longValue())
+ .buildAction());
instructions.add(MDSALUtil.buildApplyActionsInstruction(actions, ++instructionKey));
instructions.add(
- MDSALUtil.buildAndGetWriteMetadaInstruction(MetaDataUtil.getVpnIdMetadata(vpnId),
+ MDSALUtil.buildAndGetWriteMetadaInstruction(MetaDataUtil.getVpnIdMetadata(vpnId.longValue()),
MetaDataUtil.METADATA_MASK_VRFID, ++instructionKey));
instructions.add(MDSALUtil.buildAndGetGotoTableInstruction(NwConstants.L3_GW_MAC_TABLE,
++instructionKey));
}
}
- static FlowEntity buildFlowEntity(BigInteger dpnId, short tableId, String flowId) {
+ static FlowEntity buildFlowEntity(Uint64 dpnId, short tableId, String flowId) {
return new FlowEntityBuilder().setDpnId(dpnId).setTableId(tableId).setFlowId(flowId).build();
}
return isVxLan ? VrfEntryBase.EncapType.Vxlan : VrfEntryBase.EncapType.Mplsgre;
}
- org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.Subnets
+ org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.@Nullable Subnets
getExternalSubnet(Uuid subnetId) {
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets
.Subnets> subnetsIdentifier = InstanceIdentifier.builder(ExternalSubnets.class)
return optionalSubnets.isPresent() ? optionalSubnets.get() : null;
}
+ @Nullable
public Uuid getSubnetFromExternalRouterByIp(Uuid routerId, String ip) {
Routers externalRouter = getExternalRouter(routerId.getValue());
if (externalRouter != null && externalRouter.getExternalIps() != null) {
for (ExternalIps externalIp : externalRouter.getExternalIps()) {
- if (externalIp.getIpAddress().equals(ip)) {
+ if (Objects.equals(externalIp.getIpAddress(), ip)) {
return externalIp.getSubnetId();
}
}
}
@SuppressWarnings("checkstyle:linelength")
+ @Nullable
Network getNeutronNetwork(Uuid networkId) {
- Network network = null;
LOG.debug("getNeutronNetwork for {}", networkId.getValue());
InstanceIdentifier<Network> inst = InstanceIdentifier.create(Neutron.class).child(
org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.Networks.class).child(
Network.class, new NetworkKey(networkId));
- Optional<Network> net = read(LogicalDatastoreType.CONFIGURATION, inst);
- if (net.isPresent()) {
- network = net.get();
- }
- return network;
+ return read(LogicalDatastoreType.CONFIGURATION, inst).orNull();
}
- public static boolean isEligibleForBgp(String rd, String vpnName, BigInteger dpnId, String networkName) {
+ public static boolean isEligibleForBgp(@Nullable String rd, @Nullable String vpnName, @Nullable Uint64 dpnId,
+ @Nullable String networkName) {
if (rd != null) {
- if (vpnName != null && rd.equals(vpnName)) {
+ if (rd.equals(vpnName)) {
return false;
}
if (dpnId != null && rd.equals(dpnId.toString())) {
return false;
}
- if (networkName != null && rd.equals(networkName)) {
+ if (rd.equals(networkName)) {
return false;
}
return true;
return false;
}
- static String getFibFlowRef(BigInteger dpnId, short tableId, String vpnName, int priority) {
+ static String getFibFlowRef(Uint64 dpnId, short tableId, String vpnName, int priority) {
return VpnConstants.FLOWID_PREFIX + dpnId + NwConstants.FLOWID_SEPARATOR + tableId
+ NwConstants.FLOWID_SEPARATOR + vpnName + NwConstants.FLOWID_SEPARATOR + priority;
}
void removeExternalTunnelDemuxFlows(String vpnName) {
LOG.info("Removing external tunnel flows for vpn {}", vpnName);
- for (BigInteger dpnId: NWUtil.getOperativeDPNs(dataBroker)) {
+ for (Uint64 dpnId: NWUtil.getOperativeDPNs(dataBroker)) {
LOG.debug("Removing external tunnel flows for vpn {} from dpn {}", vpnName, dpnId);
String flowRef = getFibFlowRef(dpnId, NwConstants.L3VNI_EXTERNAL_TUNNEL_DEMUX_TABLE,
vpnName, VpnConstants.DEFAULT_FLOW_PRIORITY);
public boolean isVpnPendingDelete(String rd) {
VpnInstanceOpDataEntry vpnInstanceOpData = getVpnInstanceOpData(rd);
boolean isVpnPendingDelete = false;
- if (vpnInstanceOpData == null
- || vpnInstanceOpData.getVpnState() == VpnInstanceOpDataEntry.VpnState.PendingDelete) {
+ if (vpnInstanceOpData == null) {
+ LOG.error("isVpnPendingDelete: unable to read vpn instance op data for vpn with rd {}", rd);
+ isVpnPendingDelete = true;
+ }
+ else if (vpnInstanceOpData.getVpnState() == VpnInstanceOpDataEntry.VpnState.PendingDelete) {
isVpnPendingDelete = true;
}
return isVpnPendingDelete;
}
+ @SuppressWarnings("checkstyle:IllegalCatch")
public List<VpnInstanceOpDataEntry> getVpnsImportingMyRoute(final String vpnName) {
List<VpnInstanceOpDataEntry> vpnsToImportRoute = new ArrayList<>();
+ final VpnInstanceOpDataEntry vpnInstanceOpDataEntry;
final String vpnRd = getVpnRd(vpnName);
if (vpnRd == null) {
LOG.error("getVpnsImportingMyRoute: vpn {} not present in config DS.", vpnName);
return vpnsToImportRoute;
}
- final VpnInstanceOpDataEntry vpnInstanceOpDataEntry = getVpnInstanceOpData(vpnRd);
- if (vpnInstanceOpDataEntry == null) {
- LOG.error("getVpnsImportingMyRoute: Could not retrieve vpn instance op data for {}"
- + " to check for vpns importing the routes", vpnName);
+ if (vpnRd.equals(vpnName)) {
+ LOG.error("getVpnsImportingMyRoute: Internal vpn {} do not export/import routes", vpnName);
+ return vpnsToImportRoute;
+ }
+ try {
+ final VpnInstanceOpDataEntry opDataEntry = getVpnInstanceOpData(vpnRd);
+ if (opDataEntry == null) {
+ LOG.error("getVpnsImportingMyRoute: Could not retrieve vpn instance op data for vpn {} rd {}"
+ + " to check for vpns importing the routes", vpnName, vpnRd);
+ return vpnsToImportRoute;
+ }
+ vpnInstanceOpDataEntry = opDataEntry;
+ } catch (Exception e) {
+ LOG.error("getVpnsImportingMyRoute: DSException when retrieving vpn instance op data for vpn {} rd {}"
+ + " to check for vpns importing the routes", vpnName, vpnRd);
return vpnsToImportRoute;
}
Predicate<VpnInstanceOpDataEntry> excludeVpn = input -> {
List<String> rts = new ArrayList<>();
VpnTargets targets = vpnInstance.getVpnTargets();
if (targets == null) {
- LOG.info("getRts: vpn targets not available for {}", name);
+ LOG.debug("getRts: vpn targets not available for {}", name);
return rts;
}
List<VpnTarget> vpnTargets = targets.getVpnTarget();
if (vpnTargets == null) {
- LOG.info("getRts: vpnTarget values not available for {}", name);
+ LOG.debug("getRts: vpnTarget values not available for {}", name);
return rts;
}
for (VpnTarget target : vpnTargets) {
* @param subnetUuid the subnet's Uuid
* @return the Subnetmap of Uuid or null if it is not found
*/
+ @Nullable
public Subnetmap getSubnetmapFromItsUuid(Uuid subnetUuid) {
- Subnetmap sn = null;
InstanceIdentifier<Subnetmap> id = buildSubnetmapIdentifier(subnetUuid);
- Optional<Subnetmap> optionalSn = read(LogicalDatastoreType.CONFIGURATION, id);
- if (optionalSn.isPresent()) {
- sn = optionalSn.get();
- }
- return sn;
+ return read(LogicalDatastoreType.CONFIGURATION, id).orNull();
}
boolean isAdjacencyEligibleToVpnInternet(Adjacency adjacency) {
return adjacencyEligible;
}
+ @Nullable
String getInternetVpnFromVpnInstanceList(List<VpnInstanceNames> vpnInstanceList) {
for (VpnInstanceNames vpnInstance : vpnInstanceList) {
String vpnName = vpnInstance.getVpnName();
* @return the IpVersionChoice of the version or IpVersionChoice.UNDEFINED otherwise
*/
public static IpVersionChoice getIpVersionFromString(String ipAddress) {
- IpVersionChoice ipchoice = IpVersionChoice.UNDEFINED;
int indexIpAddress = ipAddress.indexOf('/');
if (indexIpAddress >= 0) {
ipAddress = ipAddress.substring(0, indexIpAddress);
return IpVersionChoice.IPV6;
}
} catch (UnknownHostException | SecurityException e) {
- ipchoice = IpVersionChoice.UNDEFINED;
+ return IpVersionChoice.UNDEFINED;
}
- return ipchoice;
+ return IpVersionChoice.UNDEFINED;
}
ListenableFuture<Void> unsetScheduledToRemoveForVpnInterface(String interfaceName) {
* @param vpnName the vpnName
* @param dpnId the DPN id
*/
- void addRouterPortToElanForVlanInDpn(String vpnName, BigInteger dpnId) {
+ void addRouterPortToElanForVlanInDpn(String vpnName, Uint64 dpnId) {
Map<String,String> elanInstanceRouterPortMap = getElanInstanceRouterPortMap(vpnName);
for (Entry<String, String> elanInstanceRouterEntry : elanInstanceRouterPortMap.entrySet()) {
addRouterPortToElanDpn(elanInstanceRouterEntry.getKey(), elanInstanceRouterEntry.getValue(), dpnId);
* @param vpnName the vpn name
* @param dpnId the DPN id
*/
- void removeRouterPortFromElanForVlanInDpn(String vpnName, BigInteger dpnId) {
+ void removeRouterPortFromElanForVlanInDpn(String vpnName, Uint64 dpnId) {
Map<String,String> elanInstanceRouterPortMap = getElanInstanceRouterPortMap(vpnName);
for (Entry<String, String> elanInstanceRouterEntry : elanInstanceRouterPortMap.entrySet()) {
removeRouterPortFromElanDpn(elanInstanceRouterEntry.getKey(), elanInstanceRouterEntry.getValue(),
*/
void addRouterPortToElanDpnListForVlaninAllDpn(String vpnName) {
Map<String,String> elanInstanceRouterPortMap = getElanInstanceRouterPortMap(vpnName);
- Set<BigInteger> dpnList = getDpnInElan(elanInstanceRouterPortMap);
- for (BigInteger dpnId : dpnList) {
+ Set<Uint64> dpnList = getDpnInElan(elanInstanceRouterPortMap);
+ for (Uint64 dpnId : dpnList) {
for (Entry<String, String> elanInstanceRouterEntry : elanInstanceRouterPortMap.entrySet()) {
addRouterPortToElanDpn(elanInstanceRouterEntry.getKey(), elanInstanceRouterEntry.getValue(), dpnId);
}
String routerInterfacePortId, String vpnName) {
Map<String,String> elanInstanceRouterPortMap = getElanInstanceRouterPortMap(vpnName);
elanInstanceRouterPortMap.put(elanInstanceName, routerInterfacePortId);
- Set<BigInteger> dpnList = getDpnInElan(elanInstanceRouterPortMap);
- for (BigInteger dpnId : dpnList) {
+ Set<Uint64> dpnList = getDpnInElan(elanInstanceRouterPortMap);
+ for (Uint64 dpnId : dpnList) {
for (Entry<String, String> elanInstanceRouterEntry : elanInstanceRouterPortMap.entrySet()) {
removeRouterPortFromElanDpn(elanInstanceRouterEntry.getKey(), elanInstanceRouterEntry.getValue(),
vpnName, dpnId);
}
- Set<BigInteger> getDpnInElan(Map<String,String> elanInstanceRouterPortMap) {
- Set<BigInteger> dpnIdSet = new HashSet<>();
+ Set<Uint64> getDpnInElan(Map<String,String> elanInstanceRouterPortMap) {
+ Set<Uint64> dpnIdSet = new HashSet<>();
for (String elanInstanceName : elanInstanceRouterPortMap.keySet()) {
InstanceIdentifier<ElanDpnInterfacesList> elanDpnInterfaceId = getElanDpnOperationalDataPath(
elanInstanceName);
Optional<ElanDpnInterfacesList> dpnInElanInterfaces = read(LogicalDatastoreType.OPERATIONAL,
elanDpnInterfaceId);
if (dpnInElanInterfaces.isPresent()) {
- List<DpnInterfaces> dpnInterfaces = dpnInElanInterfaces.get().getDpnInterfaces();
+ List<DpnInterfaces> dpnInterfaces = dpnInElanInterfaces.get().nonnullDpnInterfaces();
for (DpnInterfaces dpnInterface : dpnInterfaces) {
dpnIdSet.add(dpnInterface.getDpId());
}
return dpnIdSet;
}
- void addRouterPortToElanDpn(String elanInstanceName, String routerInterfacePortId, BigInteger dpnId) {
+ void addRouterPortToElanDpn(String elanInstanceName, String routerInterfacePortId, Uint64 dpnId) {
InstanceIdentifier<DpnInterfaces> elanDpnInterfaceId = getElanDpnInterfaceOperationalDataPath(
elanInstanceName,dpnId);
- synchronized (elanInstanceName.intern()) {
+ final ReentrantLock lock = JvmGlobalLocks.getLockForString(elanInstanceName);
+ lock.lock();
+ try {
Optional<DpnInterfaces> dpnInElanInterfaces = read(LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId);
- List<String> elanInterfaceList;
+ List<String> elanInterfaceList = new ArrayList<>();
DpnInterfaces dpnInterface;
if (!dpnInElanInterfaces.isPresent()) {
elanInterfaceList = new ArrayList<>();
} else {
dpnInterface = dpnInElanInterfaces.get();
- elanInterfaceList = dpnInterface.getInterfaces();
+ elanInterfaceList = (dpnInterface.getInterfaces() != null && !dpnInterface.getInterfaces().isEmpty())
+ ? new ArrayList<>(dpnInterface.getInterfaces()) : elanInterfaceList;
}
if (!elanInterfaceList.contains(routerInterfacePortId)) {
elanInterfaceList.add(routerInterfacePortId);
.withKey(new DpnInterfacesKey(dpnId)).build();
syncWrite(LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId, dpnInterface);
}
+ } finally {
+ lock.unlock();
}
-
}
void removeRouterPortFromElanDpn(String elanInstanceName, String routerInterfacePortId,
- String vpnName, BigInteger dpnId) {
+ String vpnName, Uint64 dpnId) {
InstanceIdentifier<DpnInterfaces> elanDpnInterfaceId = getElanDpnInterfaceOperationalDataPath(
elanInstanceName,dpnId);
- synchronized (elanInstanceName.intern()) {
+ final ReentrantLock lock = JvmGlobalLocks.getLockForString(elanInstanceName);
+ lock.lock();
+ try {
Optional<DpnInterfaces> dpnInElanInterfaces = read(LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId);
- List<String> elanInterfaceList;
+ List<String> elanInterfaceList = new ArrayList<>();
DpnInterfaces dpnInterface;
if (!dpnInElanInterfaces.isPresent()) {
LOG.info("No interface in any dpn for {}", vpnName);
return;
} else {
dpnInterface = dpnInElanInterfaces.get();
- elanInterfaceList = dpnInterface.getInterfaces();
+ elanInterfaceList = (dpnInterface.getInterfaces() != null && !dpnInterface.getInterfaces().isEmpty())
+ ? new ArrayList<>(dpnInterface.getInterfaces()) : elanInterfaceList;
}
if (!elanInterfaceList.contains(routerInterfacePortId)) {
LOG.info("Router port not present in DPN {} for VPN {}", dpnId, vpnName);
dpnInterface = new DpnInterfacesBuilder().setDpId(dpnId).setInterfaces(elanInterfaceList)
.withKey(new DpnInterfacesKey(dpnId)).build();
syncWrite(LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId, dpnInterface);
+ } finally {
+ lock.unlock();
}
}
+ @Nullable
ElanInterface getElanInterfaceByElanInterfaceName(String elanInterfaceName) {
InstanceIdentifier<ElanInterface> elanInterfaceId = getElanInterfaceConfigurationDataPathId(elanInterfaceName);
return read(LogicalDatastoreType.CONFIGURATION, elanInterfaceId).orNull();
.child(ElanInterface.class, new ElanInterfaceKey(interfaceName)).build();
}
- DpnInterfaces getElanInterfaceInfoByElanDpn(String elanInstanceName, BigInteger dpId) {
+ @Nullable
+ DpnInterfaces getElanInterfaceInfoByElanDpn(String elanInstanceName, Uint64 dpId) {
InstanceIdentifier<DpnInterfaces> elanDpnInterfacesId = getElanDpnInterfaceOperationalDataPath(elanInstanceName,
dpId);
return read(LogicalDatastoreType.OPERATIONAL, elanDpnInterfacesId).orNull();
}
- String getExternalElanInterface(String elanInstanceName, BigInteger dpnId) {
+ @Nullable
+ String getExternalElanInterface(String elanInstanceName, Uint64 dpnId) {
DpnInterfaces dpnInterfaces = getElanInterfaceInfoByElanDpn(elanInstanceName, dpnId);
if (dpnInterfaces == null || dpnInterfaces.getInterfaces() == null) {
LOG.info("Elan {} does not have interfaces in DPN {}", elanInstanceName, dpnId);
static boolean isVlan(ElanInstance elanInstance) {
return elanInstance != null && elanInstance.getSegmentType() != null
&& elanInstance.getSegmentType().isAssignableFrom(SegmentTypeVlan.class)
- && elanInstance.getSegmentationId() != null && elanInstance.getSegmentationId() != 0;
+ && elanInstance.getSegmentationId() != null && elanInstance.getSegmentationId().toJava() != 0;
}
boolean isVlan(String interfaceName) {
return isVlan(elanInstance);
}
+ @Nullable
ElanInstance getElanInstanceByName(String elanInstanceName) {
InstanceIdentifier<ElanInstance> elanIdentifierId =
ElanHelper.getElanInstanceConfigurationDataPath(elanInstanceName);
return read(LogicalDatastoreType.CONFIGURATION, elanIdentifierId).orNull();
}
+ @Nullable
String getVpnNameFromElanIntanceName(String elanInstanceName) {
Optional<Subnetmaps> subnetMapsData = read(LogicalDatastoreType.CONFIGURATION, buildSubnetMapsWildCardPath());
if (subnetMapsData.isPresent()) {
Map<String, String> elanInstanceRouterPortMap = new HashMap<>();
Optional<Subnetmaps> subnetMapsData = read(LogicalDatastoreType.CONFIGURATION, buildSubnetMapsWildCardPath());
if (subnetMapsData.isPresent()) {
- List<Subnetmap> subnetMapList = subnetMapsData.get().getSubnetmap();
+ List<Subnetmap> subnetMapList = new ArrayList<>();
+ Subnetmaps subnetMaps = subnetMapsData.get();
+ subnetMapList = (subnetMaps.getSubnetmap() != null && !subnetMaps.getSubnetmap().isEmpty())
+ ? new ArrayList<>(subnetMaps.getSubnetmap()) : subnetMapList;
+
if (subnetMapList != null && !subnetMapList.isEmpty()) {
for (Subnetmap subnet : subnetMapList) {
if (subnet.getVpnId() != null && subnet.getVpnId().getValue().equals(vpnName)
- && subnet.getNetworkType().equals(NetworkType.VLAN)) {
+ && NetworkType.VLAN.equals(subnet.getNetworkType())) {
if (subnet.getRouterInterfacePortId() == null || subnet.getNetworkId() == null) {
LOG.warn("The RouterInterfacePortId or NetworkId is null");
continue;
return elanInstanceRouterPortMap;
}
+ @Nullable
String getRouterPordIdFromElanInstance(String elanInstanceName) {
Optional<Subnetmaps> subnetMapsData = read(LogicalDatastoreType.CONFIGURATION, buildSubnetMapsWildCardPath());
if (subnetMapsData.isPresent()) {
return null;
}
- boolean shouldPopulateFibForVlan(String vpnName, String elanInstanceName, BigInteger dpnId) {
+ boolean shouldPopulateFibForVlan(String vpnName, @Nullable String elanInstanceName, Uint64 dpnId) {
Map<String,String> elanInstanceRouterPortMap = getElanInstanceRouterPortMap(vpnName);
boolean shouldPopulateFibForVlan = false;
if (!elanInstanceRouterPortMap.isEmpty()) {
}
public static InstanceIdentifier<DpnInterfaces> getElanDpnInterfaceOperationalDataPath(String elanInstanceName,
- BigInteger dpId) {
+ Uint64 dpId) {
return InstanceIdentifier.builder(ElanDpnInterfaces.class)
.child(ElanDpnInterfacesList.class, new ElanDpnInterfacesListKey(elanInstanceName))
.child(DpnInterfaces.class, new DpnInterfacesKey(dpId)).build();
}
public static void sendNeighborSolicationToOfGroup(Ipv6NdUtilService ipv6NdUtilService, Ipv6Address srcIpv6Address,
- MacAddress srcMac, Ipv6Address dstIpv6Address, Long ofGroupId, BigInteger dpId) {
+ MacAddress srcMac, Ipv6Address dstIpv6Address, Long ofGroupId, Uint64 dpId) {
SendNeighborSolicitationToOfGroupInput input = new SendNeighborSolicitationToOfGroupInputBuilder()
.setSourceIpv6(srcIpv6Address).setSourceLlAddress(srcMac).setTargetIpAddress(dstIpv6Address)
.setOfGroupId(ofGroupId).setDpId(dpId).build();
}
}
- Set<org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.vpntargets.VpnTarget>
- getRtListForVpn(String vpnName) {
- Set<org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.vpntargets
+ Set<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.af.config
+ .vpntargets.VpnTarget> getRtListForVpn(String vpnName) {
+ Set<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.af.config.vpntargets
.VpnTarget> rtList = new HashSet<>();
InstanceIdentifier<VpnInstance> vpnInstanceId = InstanceIdentifier.builder(VpnInstances.class)
.child(VpnInstance.class, new VpnInstanceKey(vpnName)).build();
Optional<VpnInstance> vpnInstanceOptional = read(LogicalDatastoreType.CONFIGURATION, vpnInstanceId);
if (vpnInstanceOptional.isPresent()) {
- org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.VpnTargets
+ org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.af.config.VpnTargets
vpnTargets = vpnInstanceOptional.get().getIpv4Family().getVpnTargets();
if (vpnTargets != null && vpnTargets.getVpnTarget() != null) {
rtList.addAll(vpnTargets.getVpnTarget());
.child(RouteTarget.class, new RouteTargetKey(rt, rtType)).build();
}
- Set<RouteTarget> getRouteTargetSet(Set<org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815
- .vpn.af.config.vpntargets.VpnTarget> vpnTargets) {
+ Set<RouteTarget> getRouteTargetSet(Set<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn
+ .rev200204.vpn.af.config.vpntargets.VpnTarget> vpnTargets) {
Set<RouteTarget> routeTargetSet = new HashSet<>();
- for (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.vpntargets
+ for (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.af.config.vpntargets
.VpnTarget rt : vpnTargets) {
String rtValue = rt.getVrfRTValue();
switch (rt.getVrfRTType()) {
Also the Subnet overlap in a VPN detection logic to be addressed for router-based-l3vpns.
*/
static boolean areSubnetsOverlapping(String cidr1, String cidr2) {
- String[] ipaddressValues1 = cidr1.split("/");
- int address1 = InetAddresses.coerceToInteger(InetAddresses.forString(ipaddressValues1[0]));
- int cidrPart1 = Integer.parseInt(ipaddressValues1[1]);
- String[] ipaddressValues2 = cidr2.split("/");
- int address2 = InetAddresses.coerceToInteger(InetAddresses.forString(ipaddressValues2[0]));
- int cidrPart2 = Integer.parseInt(ipaddressValues2[1]);
- int comparedValue = 0;
+ final int slash1 = cidr1.indexOf('/');
+ final int address1 = addressForCidr(cidr1, slash1);
+ final int cidrPart1 = maskForCidr(cidr1, slash1);
+
+ final int slash2 = cidr2.indexOf('/');
+ final int address2 = addressForCidr(cidr2, slash2);
+ final int cidrPart2 = maskForCidr(cidr2, slash2);
+
+ final int comparedValue = cidrPart1 <= cidrPart2 ? compare(address1, cidrPart1, address2)
+ : compare(address2, cidrPart2, address1);
+ return comparedValue == 0;
+ }
+
+ private static int addressForCidr(String cidr, int slash) {
+ return InetAddresses.coerceToInteger(InetAddresses.forString(cidr.substring(0, slash)));
+ }
+
+ private static int maskForCidr(String cidr, int slash) {
+ return Integer.parseInt(cidr.substring(slash + 1));
+ }
+
+ private static int compare(int address, int cidrPart, int address2) {
+ int prefix = address2 & computeNetmask(cidrPart);
+ return address ^ prefix;
+ }
+
+ private static int computeNetmask(int cidrPart) {
int netmask = 0;
- if (cidrPart1 <= cidrPart2) {
- for (int j = 0; j < cidrPart1; ++j) {
- netmask |= (1 << 31 - j);
- }
- int prefix = address2 & netmask;
- comparedValue = address1 ^ prefix;
- } else {
- for (int j = 0; j < cidrPart2; ++j) {
- netmask |= (1 << 31 - j);
- }
- int prefix = address1 & netmask;
- comparedValue = address2 ^ prefix;
- }
- if (comparedValue == 0) {
- return true;
- } else {
- return false;
+ for (int j = 0; j < cidrPart; ++j) {
+ netmask |= 1 << 31 - j;
}
+ return netmask;
}
public static String buildIpMonitorJobKey(String ip, String vpnName) {
return VpnConstants.IP_MONITOR_JOB_PREFIX_KEY + "-" + vpnName + "-" + ip;
}
- public List<String> getVpnListForVpnInterface(VpnInterface vpnInter) {
- return vpnInter.getVpnInstanceNames().stream()
+ public static List<String> getVpnListForVpnInterface(VpnInterface vpnInter) {
+ return vpnInter.nonnullVpnInstanceNames().stream()
.map(VpnInstanceNames::getVpnName).collect(Collectors.toList());
}
return;
}
jobCoordinator.enqueueJob("VPN-" + vpnName, () -> {
- VpnInstanceOpDataEntryBuilder builder = new VpnInstanceOpDataEntryBuilder();
+ VpnInstanceOpDataEntryBuilder builder = new VpnInstanceOpDataEntryBuilder().setVrfId(primaryRd);
builder.setRd(updatedRdList);
return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
OPERATIONAL, tx -> {
}));
});
}
+
+ public static RouteOrigin getRouteOrigin(AdjacencyType adjacencyType) {
+ RouteOrigin origin = RouteOrigin.LOCAL;
+ switch (adjacencyType) {
+ case PrimaryAdjacency:
+ origin = RouteOrigin.LOCAL;
+ break;
+ case ExtraRoute:
+ origin = RouteOrigin.STATIC;
+ break;
+ case LearntIp:
+ origin = RouteOrigin.DYNAMIC;
+ break;
+ default:
+ LOG.warn("Unknown adjacencyType={}", adjacencyType);
+ }
+ return origin;
+ }
+
+ public static boolean isDualRouterVpnUpdate(List<String> oldVpnListCopy, List<String> newVpnListCopy) {
+ return oldVpnListCopy.size() == 2 && newVpnListCopy.size() == 3
+ || oldVpnListCopy.size() == 3 && newVpnListCopy.size() == 2;
+ }
+
+ // TODO Clean up the exception handling
+ @SuppressWarnings("checkstyle:IllegalCatch")
+ public void createVpnPortFixedIpToPort(String vpnName, String fixedIp,
+ String portName, boolean isLearntIp, String macAddress,
+ WriteTransaction writeConfigTxn) {
+ InstanceIdentifier<VpnPortipToPort> id = buildVpnPortipToPortIdentifier(vpnName, fixedIp);
+ VpnPortipToPortBuilder builder = new VpnPortipToPortBuilder().withKey(new VpnPortipToPortKey(fixedIp, vpnName))
+ .setVpnName(vpnName).setPortFixedip(fixedIp).setPortName(portName)
+ .setLearntIp(isLearntIp).setSubnetIp(false).setMacAddress(macAddress.toLowerCase(Locale.getDefault()));
+ try {
+ if (writeConfigTxn != null) {
+ writeConfigTxn.put(LogicalDatastoreType.CONFIGURATION, id, builder.build());
+ } else {
+ syncWrite(LogicalDatastoreType.CONFIGURATION, id, builder.build());
+ }
+ LOG.trace("Port with Ip: {}, vpn {}, interface {}, learntIp {} added to VpnPortipToPort DS",
+ fixedIp, vpnName, portName, isLearntIp);
+ } catch (Exception e) {
+ LOG.error("Failure while creating VpnPortIpToPort map for vpn {} learnIp{}", vpnName, fixedIp, e);
+ }
+ }
+
+ protected VpnPortipToPort getVpnPortipToPort(String vpnName, String fixedIp) {
+ InstanceIdentifier<VpnPortipToPort> id = buildVpnPortipToPortIdentifier(vpnName, fixedIp);
+ Optional<VpnPortipToPort> vpnPortipToPortData = read(LogicalDatastoreType.CONFIGURATION, id);
+ if (vpnPortipToPortData.isPresent()) {
+ return vpnPortipToPortData.get();
+ }
+ LOG.error("getVpnPortipToPort: Failed as vpnPortipToPortData DS is absent for VPN {} and fixed IP {}",
+ vpnName, fixedIp);
+ return null;
+ }
+
+ public static void enableArpLearning(Boolean isArpLearningEnabled) {
+ arpLearningEnabled = isArpLearningEnabled;
+ }
+
+ public static Boolean isArpLearningEnabled() {
+ return arpLearningEnabled;
+ }
+
+ private static ReentrantLock lockFor(String vpnName, String fixedIp) {
+ // FIXME: is there some identifier we can use? LearntVpnVipToPortKey perhaps?
+ return JvmGlobalLocks.getLockForString(vpnName + fixedIp);
+ }
}