package org.opendaylight.netvirt.vpnmanager.api;
import java.math.BigInteger;
+import javax.annotation.Nullable;
/**
* ICentralizedSwitchProvider allows to create or interrogate centralized
* @param routerName The router's name.
* @return The primary switch id.
*/
+ @Nullable
BigInteger getPrimarySwitchForRouter(String routerName);
}
package org.opendaylight.netvirt.vpnmanager.api;
import java.math.BigInteger;
+import javax.annotation.Nullable;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.IpAddresses;
* @param interfaceName Name of the VPN interface to be added/removed to/from the specified DPN
* @param add true for addition, false for removal
*/
- void updateVpnToDpnMapping(BigInteger dpId, String vpnName, String primaryRd, String interfaceName,
+ void updateVpnToDpnMapping(BigInteger dpId, String vpnName, String primaryRd, @Nullable String interfaceName,
ImmutablePair<IpAddresses.IpAddressSource, String> ipAddressSourceValuePair, boolean add);
}
import java.util.Set;
import java.util.concurrent.ExecutionException;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.genius.infra.Datastore.Configuration;
import org.opendaylight.genius.infra.Datastore.Operational;
public interface IVpnManager {
- void addExtraRoute(String vpnName, String destination, String nextHop, String rd, String routerID,
- Long l3vni, RouteOrigin origin, String intfName, Adjacency operationalAdj,
- VrfEntry.EncapType encapType, TypedWriteTransaction<Configuration> confTx);
+ void addExtraRoute(String vpnName, String destination, String nextHop, String rd, @Nullable String routerID,
+ Long l3vni, RouteOrigin origin, @Nullable String intfName, @Nullable Adjacency operationalAdj,
+ VrfEntry.EncapType encapType, @Nonnull TypedWriteTransaction<Configuration> confTx);
- void delExtraRoute(String vpnName, String destination, String nextHop, String rd, String routerID,
- String intfName, TypedWriteTransaction<Configuration> confTx, TypedWriteTransaction<Operational> operTx);
+ void delExtraRoute(String vpnName, String destination, String nextHop, String rd, @Nullable String routerID,
+ @Nullable String intfName, @Nonnull TypedWriteTransaction<Configuration> confTx,
+ @Nonnull TypedWriteTransaction<Operational> operTx);
void removePrefixFromBGP(String vpnName, String primaryRd, String extraRouteRd, String vpnInterfaceName,
String prefix, String nextHop, String nextHopTunnelIp, BigInteger dpnId,
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
+import javax.annotation.Nullable;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
return id;
}
+ @Nullable
public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state
.Interface getInterfaceStateFromOperDS(
DataBroker dataBroker, String interfaceName) {
return null;
}
+ @Nullable
public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces
.Interface getInterface(
DataBroker broker, String interfaceName) {
import static java.util.stream.Collectors.toList;
import com.google.common.base.Optional;
-
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
-
+import javax.annotation.Nullable;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.genius.infra.Datastore.Configuration;
private VpnExtraRouteHelper() { }
- public static List<Routes> getVpnExtraroutes(DataBroker broker, String vpnName, String vpnRd) {
- InstanceIdentifier<ExtraRoutes> vpnExtraRoutesId = getVpnToExtrarouteIdentifier(vpnName, vpnRd);
- Optional<ExtraRoutes> vpnOpc = MDSALUtil.read(broker, LogicalDatastoreType.OPERATIONAL, vpnExtraRoutesId);
- return vpnOpc.isPresent() ? vpnOpc.get().getRoutes() : new ArrayList<>();
- }
-
public static Optional<Routes> getVpnExtraroutes(DataBroker broker, String vpnName,
String vpnRd, String destPrefix) {
InstanceIdentifier<Routes> vpnExtraRoutesId = getVpnToExtrarouteVrfIdIdentifier(vpnName, vpnRd, destPrefix);
new ExtraRoutesKey(vrfId)).child(Routes.class, new RoutesKey(ipPrefix)).build();
}
- public static InstanceIdentifier<ExtraRoutes> getVpnToExtrarouteIdentifier(String vpnName, String vrfId) {
- return InstanceIdentifier.builder(VpnToExtraroutes.class)
- .child(Vpn.class, new VpnKey(vpnName)).child(ExtraRoutes.class,
- new ExtraRoutesKey(vrfId)).build();
- }
-
public static InstanceIdentifier<Vpn> getVpnToExtrarouteVpnIdentifier(String vpnName) {
return InstanceIdentifier.builder(VpnToExtraroutes.class)
.child(Vpn.class, new VpnKey(vpnName)).build();
public static List<String> getUsedRds(DataBroker broker, long vpnId, String destPrefix) {
InstanceIdentifier<DestPrefixes> usedRdsId = getUsedRdsIdentifier(vpnId, destPrefix);
Optional<DestPrefixes> usedRds = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, usedRdsId);
- return usedRds.isPresent() ? usedRds.get().getAllocatedRds().stream()
+ return usedRds.isPresent() && usedRds.get().getAllocatedRds() != null ? usedRds.get().getAllocatedRds().stream()
.map(AllocatedRds::getRd).distinct().collect(toList()) : new ArrayList<>();
}
public static List<String> getUsedRds(TypedReadTransaction<Configuration> confTx, long vpnId, String destPrefix)
throws ExecutionException, InterruptedException {
Optional<DestPrefixes> usedRds = confTx.read(getUsedRdsIdentifier(vpnId, destPrefix)).get();
- return usedRds.isPresent() ? usedRds.get().getAllocatedRds().stream()
+ return usedRds.isPresent() && usedRds.get().getAllocatedRds() != null ? usedRds.get().getAllocatedRds().stream()
.map(AllocatedRds::getRd).distinct().collect(toList()) : new ArrayList<>();
}
.child(AllocatedRds.class, new AllocatedRdsKey(nh)).build();
}
- public static List<Routes> getAllExtraRoutes(DataBroker broker, String vpnName, String vrfId) {
- Optional<ExtraRoutes> extraRoutes = MDSALUtil.read(broker,LogicalDatastoreType.OPERATIONAL,
- getVpnToExtrarouteIdentifier(vpnName, vrfId));
- List<Routes> extraRoutesList = new ArrayList<>();
- if (extraRoutes.isPresent()) {
- extraRoutesList = extraRoutes.get().getRoutes();
- }
- return extraRoutesList;
- }
-
+ @Nullable
public static Class<? extends TunnelTypeBase> getTunnelType(ItmRpcService itmRpcService, String ifName) {
try {
Future<RpcResult<GetTunnelTypeOutput>> result =
}
public static List<DestPrefixes> getExtraRouteDestPrefixes(DataBroker broker, Long vpnId) {
- Optional<ExtrarouteRds> extraRoutes = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION,
+ Optional<ExtrarouteRds> optionalExtraRoutes = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION,
getUsedRdsIdentifier(vpnId));
- return extraRoutes.isPresent() ? extraRoutes.get().getDestPrefixes() : new ArrayList<>();
+ List<DestPrefixes> prefixes =
+ optionalExtraRoutes.isPresent() ? optionalExtraRoutes.get().getDestPrefixes() : null;
+ return prefixes == null ? Collections.emptyList() : prefixes;
}
}
import java.util.List;
import java.util.concurrent.ExecutionException;
+import javax.annotation.Nonnull;
+import javax.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;
private VpnHelper() { }
//FIXME: Implement caches for DS reads
+ @Nullable
public static VpnInstance getVpnInstance(DataBroker broker, String vpnInstanceName) {
InstanceIdentifier<VpnInstance> id = InstanceIdentifier.builder(VpnInstances.class).child(VpnInstance.class,
new VpnInstanceKey(vpnInstanceName)).build();
public static List<VpnInstance> getAllVpnInstances(DataBroker broker) {
InstanceIdentifier<VpnInstances> id = InstanceIdentifier.builder(VpnInstances.class).build();
Optional<VpnInstances> optVpnInstances = read(broker, LogicalDatastoreType.CONFIGURATION, id);
- if (optVpnInstances.isPresent()) {
+ if (optVpnInstances.isPresent() && optVpnInstances.get().getVpnInstance() != null) {
return optVpnInstances.get().getVpnInstance();
} else {
return Collections.emptyList();
.VpnInstanceKey(vpnName)).build();
}
+ @Nullable
public static VpnInterface getVpnInterface(DataBroker broker, String vpnInterfaceName) {
InstanceIdentifier<VpnInterface> id = getVpnInterfaceIdentifier(vpnInterfaceName);
Optional<VpnInterface> vpnInterface = read(broker, LogicalDatastoreType.CONFIGURATION, id);
.child(VpnInterface.class, new VpnInterfaceKey(vpnInterfaceName)).build();
}
+ @Nullable
public static String getFirstVpnNameFromVpnInterface(final VpnInterface original) {
List<VpnInstanceNames> optList = original.getVpnInstanceNames();
if (optList != null && !optList.isEmpty()) {
}
}
- public static List<String> getVpnInterfaceVpnInstanceNamesString(List<VpnInstanceNames> vpnInstanceList) {
- List listVpn = new ArrayList<String>();
- for (VpnInstanceNames vpnInterfaceVpnInstance : vpnInstanceList) {
- listVpn.add(vpnInterfaceVpnInstance.getVpnName());
+ @Nonnull
+ public static List<String> getVpnInterfaceVpnInstanceNamesString(@Nullable List<VpnInstanceNames> vpnInstanceList) {
+ List<String> listVpn = new ArrayList<>();
+ if (vpnInstanceList != null) {
+ for (VpnInstanceNames vpnInterfaceVpnInstance : vpnInstanceList) {
+ listVpn.add(vpnInterfaceVpnInstance.getVpnName());
+ }
}
return listVpn;
}
public static void removeVpnInterfaceVpnInstanceNamesFromList(String vpnName,
List<VpnInstanceNames> vpnInstanceList) {
- vpnInstanceList.removeIf(instance -> instance.getVpnName().equals(vpnName));
+ if (vpnInstanceList != null) {
+ vpnInstanceList.removeIf(instance -> vpnName.equals(instance.getVpnName()));
+ }
}
public static boolean doesVpnInterfaceBelongToVpnInstance(String vpnName,
List<VpnInstanceNames> vpnInstanceList) {
- for (VpnInstanceNames vpnInstance : vpnInstanceList) {
- if (vpnInstance.getVpnName().equals(vpnName)) {
- return true;
+ if (vpnInstanceList != null) {
+ for (VpnInstanceNames vpnInstance : vpnInstanceList) {
+ if (vpnName.equals(vpnInstance.getVpnName())) {
+ return true;
+ }
}
}
return false;
* @param subnetUuid the subnet's Uuid
* @return the Subnetmap of Uuid or null if it is not found
*/
+ @Nullable
public static Subnetmap getSubnetmapFromItsUuid(DataBroker broker, Uuid subnetUuid) {
Subnetmap sn = null;
InstanceIdentifier<Subnetmap> id = buildSubnetmapIdentifier(subnetUuid);
package org.opendaylight.netvirt.vpnmanager.api.intervpnlink;
+import static java.util.Collections.emptyList;
+
import com.google.common.base.Optional;
import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import java.util.Objects;
+import javax.annotation.Nullable;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkState;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.InterVpnLink;
import org.slf4j.Logger;
&& ipAddr.equals(getFirstEndpointIpAddr().orNull()));
}
+ @Nullable
public String getInterVpnLinkName() {
return (interVpnLinkCfg != null) ? interVpnLinkCfg.getName() : interVpnLinkState.getInterVpnLinkName();
}
public List<BigInteger> getFirstEndpointDpns() {
return (!isComplete() || this.interVpnLinkState.getFirstEndpointState().getDpId() == null)
- ? Collections.emptyList()
+ ? emptyList()
: this.interVpnLinkState.getFirstEndpointState().getDpId();
}
public List<BigInteger> getSecondEndpointDpns() {
return (!isComplete() || this.interVpnLinkState.getSecondEndpointState().getDpId() == null)
- ? Collections.emptyList()
+ ? emptyList()
: this.interVpnLinkState.getSecondEndpointState().getDpId();
}
+ @Nullable
public String getVpnNameByIpAddress(String endpointIpAddr) {
if (!isFirstEndpointIpAddr(endpointIpAddr) && !isSecondEndpointIpAddr(endpointIpAddr)) {
LOG.debug("Endpoint IpAddress {} does not participate in InterVpnLink {}",
endpointIpAddr, getInterVpnLinkName());
return null;
}
- return isFirstEndpointIpAddr(endpointIpAddr) ? getFirstEndpointVpnUuid().get()
- : getSecondEndpointVpnUuid().get();
+ return isFirstEndpointIpAddr(endpointIpAddr) ? getFirstEndpointVpnUuid().orNull()
+ : getSecondEndpointVpnUuid().orNull();
}
+ @Nullable
public String getOtherEndpoint(String vpnUuid) {
if (!isFirstEndpointVpnName(vpnUuid) && !isSecondEndpointVpnName(vpnUuid)) {
LOG.debug("VPN {} does not participate in InterVpnLink {}", vpnUuid, getInterVpnLinkName());
return null;
}
- Optional<String> optEndpointIpAddr = isFirstEndpointVpnName(vpnUuid) ? getSecondEndpointIpAddr()
- : getFirstEndpointIpAddr();
- return optEndpointIpAddr.orNull();
+ return isFirstEndpointVpnName(vpnUuid) ? getSecondEndpointIpAddr().orNull()
+ : getFirstEndpointIpAddr().orNull();
}
+ @Nullable
public String getOtherVpnNameByIpAddress(String endpointIpAddr) {
if (!isFirstEndpointIpAddr(endpointIpAddr) && !isSecondEndpointIpAddr(endpointIpAddr)) {
LOG.debug("Endpoint IpAddress {} does not participate in InterVpnLink {}",
endpointIpAddr, getInterVpnLinkName());
return null;
}
- return isFirstEndpointIpAddr(endpointIpAddr) ? getSecondEndpointVpnUuid().get()
- : getFirstEndpointVpnUuid().get();
+ return isFirstEndpointIpAddr(endpointIpAddr) ? getSecondEndpointVpnUuid().orNull()
+ : getFirstEndpointVpnUuid().orNull();
}
public Optional<Long> getEndpointLportTagByVpnName(String vpnName) {
: Optional.of(interVpnLinkState.getFirstEndpointState().getLportTag());
}
+ @Nullable
public String getOtherVpnName(String vpnName) {
if (!isFirstEndpointVpnName(vpnName) && !isSecondEndpointVpnName(vpnName)) {
LOG.debug("VPN {} does not participate in InterVpnLink {}", vpnName, getInterVpnLinkName());
return null;
}
- Optional<String> optOtherVpnName = isFirstEndpointVpnName(vpnName) ? getSecondEndpointVpnUuid()
- : getFirstEndpointVpnUuid();
- return optOtherVpnName.orNull();
+ return isFirstEndpointVpnName(vpnName) ? getSecondEndpointVpnUuid().orNull()
+ : getFirstEndpointVpnUuid().orNull();
}
+ @Nullable
public String getOtherEndpointIpAddr(String vpnUuid) {
if (!isFirstEndpointVpnName(vpnUuid) && !isSecondEndpointVpnName(vpnUuid)) {
LOG.debug("VPN {} does not participate in InterVpnLink {}", vpnUuid, getInterVpnLinkName());
return null;
}
- Optional<String> optEndpointIpAddr = isFirstEndpointVpnName(vpnUuid) ? getSecondEndpointIpAddr()
- : getFirstEndpointIpAddr();
- return optEndpointIpAddr.orNull();
+ return isFirstEndpointVpnName(vpnUuid) ? getSecondEndpointIpAddr().orNull()
+ : getFirstEndpointIpAddr().orNull();
}
+ @Nullable
public String getEndpointIpAddr(String vpnUuid) {
if (!isFirstEndpointVpnName(vpnUuid) && !isSecondEndpointVpnName(vpnUuid)) {
LOG.debug("VPN {} does not participate in InterVpnLink {}", vpnUuid, getInterVpnLinkName());
return null;
}
- Optional<String> optEndpointIpAddr = isFirstEndpointVpnName(vpnUuid) ? getFirstEndpointIpAddr()
- : getSecondEndpointIpAddr();
- return optEndpointIpAddr.orNull();
+ return isFirstEndpointVpnName(vpnUuid) ? getFirstEndpointIpAddr().orNull()
+ : getSecondEndpointIpAddr().orNull();
}
public List<BigInteger> getEndpointDpnsByVpnName(String vpnUuid) {
if (!isComplete()) {
- return new ArrayList<>();
+ return emptyList();
}
- return isFirstEndpointVpnName(vpnUuid) ? interVpnLinkState.getFirstEndpointState().getDpId()
- : interVpnLinkState.getSecondEndpointState().getDpId();
+ List<BigInteger> dpns = isFirstEndpointVpnName(vpnUuid) ? interVpnLinkState.getFirstEndpointState().getDpId()
+ : interVpnLinkState.getSecondEndpointState().getDpId();
+ return dpns == null ? emptyList() : dpns;
}
public List<BigInteger> getOtherEndpointDpnsByVpnName(String vpnUuid) {
- List<BigInteger> result = new ArrayList<>();
if (!isComplete()) {
- return result;
+ return emptyList();
}
- return isFirstEndpointVpnName(vpnUuid) ? interVpnLinkState.getSecondEndpointState().getDpId()
- : interVpnLinkState.getFirstEndpointState().getDpId();
+ List<BigInteger> dpns = isFirstEndpointVpnName(vpnUuid) ? interVpnLinkState.getSecondEndpointState().getDpId()
+ : interVpnLinkState.getFirstEndpointState().getDpId();
+ return dpns == null ? emptyList() : dpns;
}
public List<BigInteger> getEndpointDpnsByIpAddr(String endpointIp) {
- List<BigInteger> result = new ArrayList<>();
if (!isComplete()) {
- return result;
+ return emptyList();
}
- return isFirstEndpointIpAddr(endpointIp) ? this.interVpnLinkState.getFirstEndpointState().getDpId()
- : this.interVpnLinkState.getSecondEndpointState().getDpId();
+ List<BigInteger> dpns =
+ isFirstEndpointIpAddr(endpointIp) ? this.interVpnLinkState.getFirstEndpointState().getDpId()
+ : this.interVpnLinkState.getSecondEndpointState().getDpId();
+ return dpns == null ? emptyList() : dpns;
}
public List<BigInteger> getOtherEndpointDpnsByIpAddr(String endpointIp) {
- List<BigInteger> result = new ArrayList<>();
if (!isComplete()) {
- return result;
+ return emptyList();
}
- return isFirstEndpointIpAddr(endpointIp) ? this.interVpnLinkState.getSecondEndpointState().getDpId()
- : this.interVpnLinkState.getFirstEndpointState().getDpId();
+ List<BigInteger> dpns =
+ isFirstEndpointIpAddr(endpointIp) ? this.interVpnLinkState.getSecondEndpointState().getDpId()
+ : this.interVpnLinkState.getFirstEndpointState().getDpId();
+ return dpns == null ? emptyList() : dpns;
}
@Override
package org.opendaylight.netvirt.vpnmanager;
import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.netvirt.vpnmanager.VpnUtil.requireNonNullElse;
import java.math.BigInteger;
+import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
return;
}
- for (ExternalIps extIp: router.getExternalIps()) {
+ for (ExternalIps extIp : requireNonNullElse(router.getExternalIps(), Collections.<ExternalIps>emptyList())) {
Uuid subnetVpnName = extIp.getSubnetId();
if (addOrRemove == NwConstants.ADD_FLOW) {
vpnManager.addRouterGwMacFlow(routerName, extGwMacAddress, primarySwitchId, extNetworkId,
package org.opendaylight.netvirt.vpnmanager;
import java.math.BigInteger;
+import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.netvirt.vpnmanager.api.ICentralizedSwitchProvider;
}
@Override
+ @Nullable
public BigInteger getPrimarySwitchForRouter(String routerName) {
return vpnUtil.getPrimarySwitchForRouter(routerName);
}
*/
package org.opendaylight.netvirt.vpnmanager;
+import static java.util.Collections.emptyList;
import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
+import static org.opendaylight.netvirt.vpnmanager.VpnUtil.requireNonNullElse;
import com.google.common.base.Optional;
import java.math.BigInteger;
SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (vpnOpValue.isPresent()) {
VpnInstanceOpDataEntry vpnInstOpData = vpnOpValue.get();
- List<VpnToDpnList> vpnToDpnList = vpnInstOpData.getVpnToDpnList();
+ List<VpnToDpnList> vpnToDpnList = requireNonNullElse(vpnInstOpData.getVpnToDpnList(), emptyList());
boolean flushDpnsOnVpn = true;
for (VpnToDpnList dpn : vpnToDpnList) {
if (dpn.getDpnState() == VpnToDpnList.DpnState.Active) {
import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
+import static org.opendaylight.netvirt.vpnmanager.VpnUtil.requireNonNullElse;
import com.google.common.base.Optional;
import com.google.common.collect.HashBasedTable;
import com.google.common.util.concurrent.ListenableFuture;
import java.math.BigInteger;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
final VpnInterface vpnIf = vpnUtil.getConfiguredVpnInterface(interfaceName);
if (vpnIf != null) {
for (VpnInstanceNames vpnInterfaceVpnInstance :
- vpnIf.getVpnInstanceNames()) {
+ requireNonNullElse(vpnIf.getVpnInstanceNames(),
+ Collections.<VpnInstanceNames>emptyList())) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
String primaryRd = vpnUtil.getPrimaryRd(vpnName);
if (!vpnInterfaceManager.isVpnInstanceReady(vpnName)) {
return;
}
for (VpnInstanceNames vpnInterfaceVpnInstance :
- cfgVpnInterface.getVpnInstanceNames()) {
+ requireNonNullElse(cfgVpnInterface.getVpnInstanceNames(),
+ Collections.<VpnInstanceNames>emptyList())) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
Optional<VpnInterfaceOpDataEntry> optVpnInterface =
vpnUtil.getVpnInterfaceOpDataEntry(ifName, vpnName);
}
if (state.equals(IntfTransitionState.STATE_UP)) {
for (VpnInstanceNames vpnInterfaceVpnInstance :
- vpnIf.getVpnInstanceNames()) {
+ requireNonNullElse(vpnIf.getVpnInstanceNames(),
+ Collections.<VpnInstanceNames>emptyList())) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
String primaryRd = vpnUtil.getPrimaryRd(vpnName);
if (!vpnInterfaceManager.isVpnInstanceReady(vpnName)) {
}
} else if (state.equals(IntfTransitionState.STATE_DOWN)) {
for (VpnInstanceNames vpnInterfaceVpnInstance :
- vpnIf.getVpnInstanceNames()) {
+ requireNonNullElse(vpnIf.getVpnInstanceNames(),
+ Collections.<VpnInstanceNames>emptyList())) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
LOG.info("VPN Interface update event - intfName {} onto vpnName {}"
+ " running oper-driven DOWN", vpnIf.getName(), vpnName);
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
+import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
broker = db;
}
+ @Nullable
private SubnetToDpn addDpnToSubnet(Uuid subnetId, BigInteger dpnId) {
try {
InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier =
return subDpn;
}
- public void addPortOpDataEntry(String intfName, Uuid subnetId, BigInteger dpnId) {
+ public void addPortOpDataEntry(String intfName, Uuid subnetId, @Nullable BigInteger dpnId) {
try {
// Add to PortOpData as well.
PortOpDataEntryBuilder portOpBuilder = null;
*/
package org.opendaylight.netvirt.vpnmanager;
+import static org.opendaylight.netvirt.vpnmanager.VpnUtil.requireNonNullElse;
+
import com.google.common.base.Optional;
import com.google.common.util.concurrent.ListenableFuture;
import java.math.BigInteger;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.PostConstruct;
LOG.trace("{} add: Received interface {} up event", LOGGING_PREFIX, intrf);
if (L2vlan.class.equals(intrf.getType())) {
LOG.trace("SubnetRouteInterfaceListener add: Received interface {} up event", intrf);
- if (intrf.getOperStatus().equals(Interface.OperStatus.Up)) {
+ if (Interface.OperStatus.Up.equals(intrf.getOperStatus())) {
List<Uuid> subnetIdList = getSubnetId(intrf);
if (subnetIdList.isEmpty()) {
LOG.trace("SubnetRouteInterfaceListener add: Port {} doesn't exist in configDS",
return futures;
}
boolean interfaceDownEligible = false;
- for (VpnInstanceNames vpnInterfaceVpnInstance
- : cfgVpnInterface.get().getVpnInstanceNames()) {
+ for (VpnInstanceNames vpnInterfaceVpnInstance : requireNonNullElse(
+ cfgVpnInterface.get().getVpnInstanceNames(),
+ Collections.<VpnInstanceNames>emptyList())) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
InstanceIdentifier<VpnInterfaceOpDataEntry> idOper = VpnUtil
.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, idOper);
if (optVpnInterface.isPresent()) {
BigInteger dpnIdLocal = dpnId;
- if (dpnIdLocal.equals(BigInteger.ZERO)) {
+ if (BigInteger.ZERO.equals(dpnIdLocal)) {
dpnIdLocal = optVpnInterface.get().getDpnId();
}
- if (!dpnIdLocal.equals(BigInteger.ZERO)) {
+ if (!BigInteger.ZERO.equals(dpnIdLocal)) {
interfaceDownEligible = true;
break;
}
return futures;
}
boolean interfaceChangeEligible = false;
- for (VpnInstanceNames vpnInterfaceVpnInstance
- : cfgVpnInterface.get().getVpnInstanceNames()) {
+ for (VpnInstanceNames vpnInterfaceVpnInstance : requireNonNullElse(
+ cfgVpnInterface.get().getVpnInstanceNames(),
+ Collections.<VpnInstanceNames>emptyList())) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
InstanceIdentifier<VpnInterfaceOpDataEntry> idOper = VpnUtil
.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, idOper);
if (optVpnInterface.isPresent()) {
BigInteger dpnIdLocal = dpnId;
- if (dpnIdLocal.equals(BigInteger.ZERO)) {
+ if (BigInteger.ZERO.equals(dpnIdLocal)) {
dpnIdLocal = optVpnInterface.get().getDpnId();
}
- if (!dpnIdLocal.equals(BigInteger.ZERO)) {
+ if (!BigInteger.ZERO.equals(dpnIdLocal)) {
interfaceChangeEligible = true;
break;
}
}
}
if (interfaceChangeEligible) {
- if (update.getOperStatus().equals(Interface.OperStatus.Up)) {
+ if (Interface.OperStatus.Up.equals(update.getOperStatus())) {
LOG.info("{} update: Received port UP event for interface {} in subnet {}",
LOGGING_PREFIX, update.getName(), subnetId);
vpnSubnetRouteHandler.onInterfaceUp(dpnId, update.getName(), subnetId);
- } else if (update.getOperStatus().equals(Interface.OperStatus.Down)
- || update.getOperStatus().equals(Interface.OperStatus.Unknown)) {
+ } else if (Interface.OperStatus.Down.equals(update.getOperStatus())
+ || Interface.OperStatus.Unknown.equals(update.getOperStatus())) {
/*
* If the interface went down voluntarily (or) if the interface is not
* reachable from control-path involuntarily, trigger subnetRoute election
*/
LOG.info("{} update: Received port {} event for interface {} in subnet {} ",
- LOGGING_PREFIX, update.getOperStatus()
- .equals(Interface.OperStatus.Unknown)
+ LOGGING_PREFIX, Interface.OperStatus.Unknown.equals(update.getOperStatus())
? "UNKNOWN" : "DOWN", update.getName(), subnetId);
vpnSubnetRouteHandler.onInterfaceDown(dpnId, update.getName(), subnetId);
}
return listSubnetIds;
}
List<FixedIps> portIps = port.getFixedIps();
- if (port.getFixedIps() != null) {
+ if (portIps != null) {
for (FixedIps portIp : portIps) {
listSubnetIds.add(portIp.getSubnetId());
}
*/
package org.opendaylight.netvirt.vpnmanager;
+import static java.util.Collections.emptyList;
+import static org.opendaylight.netvirt.vpnmanager.VpnUtil.requireNonNullElse;
+
import com.google.common.base.Optional;
import com.google.common.primitives.Ints;
import java.math.BigInteger;
import java.net.UnknownHostException;
import java.util.List;
import java.util.concurrent.ExecutionException;
+import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
}
// return only the first VPN subnetopdataentry
+ @Nullable
private SubnetOpDataEntry getTargetSubnetForPacketOut(long elanTag, String ipAddress) {
ElanTagName elanInfo = vpnUtil.getElanInfoByElanTag(elanTag);
if (elanInfo == null) {
elanInfo.getName());
return null;
}
- List<Uuid> subnetList = optionalNetworkMap.get().getSubnetIdList();
+ List<Uuid> subnetList = requireNonNullElse(optionalNetworkMap.get().getSubnetIdList(), emptyList());
LOG.debug("{} getTargetDpnForPacketOut: Obtained subnetList as {} for network {}", LOGGING_PREFIX,
subnetList, elanInfo.getName());
for (Uuid subnetId : subnetList) {
}
public boolean isTunnel(String interfaceName) {
- org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
- .ietf.interfaces.rev140508.interfaces.Interface configIface =
- interfaceManager.getInterfaceInfoFromConfigDataStore(interfaceName);
- return configIface.augmentation(IfTunnel.class) != null;
+ return interfaceManager.getInterfaceInfoFromConfigDataStore(interfaceName).augmentation(IfTunnel.class) != null;
}
}
return;
}
if (subnetmap.getVpnId() != null) {
- if (subnetmap.getNetworkType().equals(NetworkType.VLAN)) {
+ if (NetworkType.VLAN.equals(subnetmap.getNetworkType())) {
vpnUtil.addRouterPortToElanDpnListForVlaninAllDpn(subnetmap.getVpnId().getValue());
}
}
return;
}
updateVlanDataEntry(subnetmapOriginal.getVpnId(), subnetmapUpdate.getVpnId(), subnetmapUpdate,
- subnetmapOriginal, elanTag, elanInstanceName);
+ subnetmapOriginal, elanInstanceName);
if (VpnUtil.getIsExternal(network)) {
LOG.debug("SubnetMapChangeListener:update: provider subnetwork {} is handling in "
+ "ExternalSubnetVpnInstanceListener", subnetId.getValue());
}
private void updateVlanDataEntry(Uuid vpnIdOld, Uuid vpnIdNew, Subnetmap subnetmapUpdate,
- Subnetmap subnetmapOriginal, Long elanTag, String elanInstanceName) {
+ Subnetmap subnetmapOriginal, String elanInstanceName) {
if (vpnIdNew != null && vpnIdOld == null) {
- if (elanInstanceName != null && subnetmapUpdate.getNetworkType().equals(NetworkType.VLAN)) {
+ if (elanInstanceName != null && NetworkType.VLAN.equals(subnetmapUpdate.getNetworkType())) {
vpnUtil.addRouterPortToElanDpnListForVlaninAllDpn(vpnIdNew.getValue());
}
}
if (vpnIdOld != null && vpnIdNew == null) {
- if (subnetmapOriginal.getNetworkType().equals(NetworkType.VLAN)) {
+ if (NetworkType.VLAN.equals(subnetmapOriginal.getNetworkType())) {
vpnUtil.removeRouterPortFromElanDpnListForVlanInAllDpn(elanInstanceName, subnetmapOriginal
.getRouterInterfacePortId().getValue(), vpnIdOld.getValue());
}
*/
package org.opendaylight.netvirt.vpnmanager;
+import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.toList;
import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
+import static org.opendaylight.netvirt.vpnmanager.VpnUtil.requireNonNullElse;
import com.google.common.base.Optional;
import com.google.common.base.Strings;
import com.google.common.util.concurrent.ListenableFuture;
import java.math.BigInteger;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
vpnInstanceOpData.stream()
.filter(opData -> opData.getVpnToDpnList() != null
&& opData.getVpnToDpnList().stream().anyMatch(
- vpnToDpn -> vpnToDpn.getDpnId().equals(srcDpnId)))
+ vpnToDpn -> Objects.equals(vpnToDpn.getDpnId(), srcDpnId)))
.forEach(opData -> {
List<DestPrefixes> prefixes = VpnExtraRouteHelper.getExtraRouteDestPrefixes(dataBroker,
opData.getVpnId());
}
List<RoutePaths> routePaths = vrfEntry.getRoutePaths();
routePaths.forEach(routePath -> {
- if (routePath.getNexthopAddress().equals(srcTepIp)) {
+ if (Objects.equals(routePath.getNexthopAddress(), srcTepIp)) {
String prefix = destPrefix.getDestPrefix();
String vpnPrefixKey = VpnUtil.getVpnNamePrefixKey(opData.getVpnInstanceName(),
prefix);
// Update the adj for the vpninterfaces for a DPN on which TEP is deleted.
// Update the adj & VRF for the vpninterfaces for a DPN on which TEP is deleted.
// Dont update the adj & VRF for vpninterfaces for a DPN on which TEP is not deleted.
- String endpointIpForDPN = null;
+ String endpointIpForDPN;
try {
endpointIpForDPN = InterfaceUtils.getEndpointIpAddressForDPN(dataBroker, srcDpnId);
} catch (Exception e) {
+ " destTepIP {} returned with Errors {}", srcDpnId, srcTepIp, destTepIp,
rpcResult.getErrors());
} else {
- srcDpninterfacelist = rpcResult.getResult().getInterfaces();
+ srcDpninterfacelist = requireNonNullElse(rpcResult.getResult().getInterfaces(), emptyList());
}
} catch (Exception e) {
LOG.error("handleTunnelEventForDPN: Exception when querying for GetDpnInterfaceList for srcDpnid {}"
+ " srcTepIP {} destTepIp {} returned with Errors {}", remoteDpnId, srcTepIp,
destTepIp, rpcResult.getErrors());
} else {
- destDpninterfacelist = rpcResult.getResult().getInterfaces();
+ destDpninterfacelist = requireNonNullElse(rpcResult.getResult().getInterfaces(), emptyList());
}
} catch (Exception e) {
LOG.error("handleTunnelEventForDPN: Exception when querying for GetDpnInterfaceList"
* Iterate over the list of VpnInterface for a SrcDpn on which TEP is added or deleted and read the adj.
* Update the adjacencies with the updated nexthop.
*/
- Iterator<Interfaces> interfacelistIter = srcDpninterfacelist.iterator();
- Interfaces interfaces = null;
- String intfName = null;
List<Uuid> subnetList = new ArrayList<>();
Map<Long, String> vpnIdRdMap = new HashMap<>();
Set<String> listVpnName = new HashSet<>();
- while (interfacelistIter.hasNext()) {
- interfaces = interfacelistIter.next();
+ for (Interfaces interfaces : srcDpninterfacelist) {
if (!L2vlan.class.equals(interfaces.getInterfaceType())) {
LOG.info("handleTunnelEventForDPN: Interface {} not of type L2Vlan", interfaces.getInterfaceName());
continue;
}
- intfName = interfaces.getInterfaceName();
+ String intfName = interfaces.getInterfaceName();
VpnInterface vpnInterface =
vpnUtil.getConfiguredVpnInterface(intfName);
if (vpnInterface != null) {
* Iterate over the list of VpnInterface for destDPN and get the prefix .
* Create remote rule for each of those prefix on srcDPN.
*/
- interfacelistIter = destDpninterfacelist.iterator();
- while (interfacelistIter.hasNext()) {
- interfaces = interfacelistIter.next();
+ for (Interfaces interfaces : destDpninterfacelist) {
if (!L2vlan.class.equals(interfaces.getInterfaceType())) {
LOG.info("handleTunnelEventForDPN: Interface {} not of type L2Vlan", interfaces.getInterfaceName());
continue;
}
- intfName = interfaces.getInterfaceName();
+ String intfName = interfaces.getInterfaceName();
VpnInterface vpnInterface =
vpnUtil.getConfiguredVpnInterface(intfName);
if (vpnInterface != null) {
if (opVpnInterface.isPresent()) {
VpnInterfaceOpDataEntry vpnInterface = opVpnInterface.get();
AdjacenciesOp adjacencies = vpnInterface.augmentation(AdjacenciesOp.class);
- List<Adjacency> adjList = adjacencies != null ? adjacencies.getAdjacency()
- : Collections.emptyList();
+ List<Adjacency> adjList =
+ adjacencies != null && adjacencies.getAdjacency() != null ? adjacencies.getAdjacency()
+ : emptyList();
String prefix = null;
long vpnId = vpnUtil.getVpnId(vpnInterface.getVpnInstanceName());
if (vpnIdRdMap.containsKey(vpnId)) {
DcGatewayIpList dcGatewayIpListConfig =
MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, dcGatewayIpListid).orNull();
if (dcGatewayIpListConfig == null) {
- return Collections.emptyList();
+ return emptyList();
}
return dcGatewayIpListConfig.getDcGatewayIp()
.stream()
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicBoolean;
+import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.apache.commons.lang3.tuple.ImmutablePair;
}
@Override
- public void updateVpnToDpnMapping(BigInteger dpId, String vpnName, String primaryRd, String interfaceName,
- ImmutablePair<IpAddresses.IpAddressSource, String> ipAddressSourceValuePair, boolean add) {
+ public void updateVpnToDpnMapping(BigInteger dpId, String vpnName, String primaryRd, @Nullable String interfaceName,
+ @Nullable ImmutablePair<IpAddresses.IpAddressSource, String> ipAddressSourceValuePair, boolean add) {
long vpnId = vpnUtil.getVpnId(vpnName);
if (!dpId.equals(BigInteger.ZERO)) {
if (add) {
*/
package org.opendaylight.netvirt.vpnmanager;
+import static java.util.Collections.emptyList;
import static org.opendaylight.controller.md.sal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
+import static org.opendaylight.netvirt.vpnmanager.VpnUtil.requireNonNullElse;
import com.google.common.base.Optional;
import com.google.common.util.concurrent.FutureCallback;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
+import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Singleton;
VpnInstance original, VpnInstance update) {
LOG.trace("VPN-UPDATE: update: VPN event key: {}, value: {}.", identifier, update);
String vpnName = update.getVpnInstanceName();
- if ((original.getIpv4Family() != null && update.getIpv4Family() != null)
+ if (original.getIpv4Family() != null && update.getIpv4Family() != null
+ && original.getIpv4Family().getRouteDistinguisher() != null
+ && update.getIpv4Family().getRouteDistinguisher() != null
&& original.getIpv4Family().getRouteDistinguisher().size()
!= update.getIpv4Family().getRouteDistinguisher().size()) {
LOG.debug("VPN-UPDATE: VpnInstance:{} updated with new RDs: {} from old RDs: {}", vpnName,
}
}
+ @Nullable
protected VpnInstanceOpDataEntry getVpnInstanceOpData(String rd) {
InstanceIdentifier<VpnInstanceOpDataEntry> id = VpnUtil.getVpnInstanceOpDataIdentifier(rd);
try {
LOG.info("No DC gateways configured.");
return tunnelInterfaceNameList;
}
- List<DcGatewayIp> dcGatewayIps = dcGatewayIpListOptional.get().getDcGatewayIp();
+ List<DcGatewayIp> dcGatewayIps =
+ requireNonNullElse(dcGatewayIpListOptional.get().getDcGatewayIp(), emptyList());
InstanceIdentifier<ExternalTunnelList> externalTunnelListId = InstanceIdentifier
.create(ExternalTunnelList.class);
Optional<ExternalTunnelList> externalTunnelListOptional = SingleTransactionDataBroker.syncReadOptional(
dataBroker, LogicalDatastoreType.OPERATIONAL, externalTunnelListId);
if (externalTunnelListOptional.isPresent()) {
- List<ExternalTunnel> externalTunnels = externalTunnelListOptional.get().getExternalTunnel();
+ List<ExternalTunnel> externalTunnels =
+ requireNonNullElse(externalTunnelListOptional.get().getExternalTunnel(), emptyList());
List<String> externalTunnelIpList = new ArrayList<>();
for (ExternalTunnel externalTunnel: externalTunnels) {
externalTunnelIpList.add(externalTunnel.getDestinationDevice());
*/
package org.opendaylight.netvirt.vpnmanager;
+import static java.util.Collections.emptyList;
import static org.opendaylight.controller.md.sal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
+import static org.opendaylight.netvirt.vpnmanager.VpnUtil.requireNonNullElse;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;
+import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.label.route.map.LabelRouteInfoBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.label.route.map.LabelRouteInfoKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentrybase.RoutePaths;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.Adjacencies;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.NeutronRouterDpns;
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void addVpnInterface(final InstanceIdentifier<VpnInterface> identifier, final VpnInterface vpnInterface,
- final List<Adjacency> oldAdjs, final List<Adjacency> newAdjs) {
- for (VpnInstanceNames vpnInterfaceVpnInstance : vpnInterface.getVpnInstanceNames()) {
+ final @Nullable List<Adjacency> oldAdjs, final @Nullable List<Adjacency> newAdjs) {
+ for (VpnInstanceNames vpnInterfaceVpnInstance : requireNonNullElse(vpnInterface.getVpnInstanceNames(),
+ Collections.<VpnInstanceNames>emptyList())) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
addVpnInterfaceCall(identifier, vpnInterface, oldAdjs, newAdjs, vpnName);
}
}
private void addVpnInterfaceToVpn(final InstanceIdentifier<VpnInterfaceOpDataEntry> vpnInterfaceOpIdentifier,
- final VpnInterface vpnInterface, final List<Adjacency> oldAdjs,
- final List<Adjacency> newAdjs,
+ final VpnInterface vpnInterface, final @Nullable List<Adjacency> oldAdjs,
+ final @Nullable List<Adjacency> newAdjs,
final InstanceIdentifier<VpnInterface> identifier, String vpnName) {
final VpnInterfaceKey key = identifier.firstKeyOf(VpnInterface.class, VpnInterfaceKey.class);
final String interfaceName = key.getName();
if (opVpnInterface != null) {
String opVpnName = opVpnInterface.getVpnInstanceName();
String primaryInterfaceIp = null;
- if (opVpnName.equals(vpnName)) {
+ if (Objects.equals(opVpnName, vpnName)) {
// Please check if the primary VRF Entry does not exist for VPNInterface
// If so, we have to process ADD, as this might be a DPN Restart with Remove and Add triggered
// back to back
LOG.trace("No config adjacencies present for vpninterface {}", vpnInterface);
return;
}
- List<Adjacency> adjacencies = optAdjacencies.get().getAdjacency();
+ List<Adjacency> adjacencies = requireNonNullElse(optAdjacencies.get().getAdjacency(), emptyList());
for (Adjacency adjacency : adjacencies) {
if (adjacency.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
continue;
LogicalDatastoreType.OPERATIONAL, path);
if (adjacencies.isPresent()) {
List<Adjacency> nextHops = adjacencies.get().getAdjacency();
- if (!nextHops.isEmpty()) {
+ if (nextHops != null && !nextHops.isEmpty()) {
LOG.debug("advertiseAdjacenciesForVpnToBgp: NextHops are {} for interface {} on dpn {} for vpn {}"
+ " rd {}", nextHops, interfaceName, dpnId, vpnName, rd);
VpnInstanceOpDataEntry vpnInstanceOpData = vpnUtil.getVpnInstanceOpData(rd);
if (adjacencies.isPresent()) {
List<Adjacency> nextHops = adjacencies.get().getAdjacency();
- if (!nextHops.isEmpty()) {
+ if (nextHops != null && !nextHops.isEmpty()) {
LOG.trace("withdrawAdjacenciesForVpnFromBgp: NextHops are {} for interface {} in vpn {} rd {}",
nextHops, interfaceName, vpnName, rd);
for (Adjacency nextHop : nextHops) {
} else {
// Perform similar operation as interface delete event for extraroutes.
String allocatedRd = nextHop.getVrfId();
- for (String nh : nextHop.getNextHopIpList()) {
+ for (String nh : requireNonNullElse(nextHop.getNextHopIpList(),
+ Collections.<String>emptyList())) {
deleteExtraRouteFromCurrentAndImportingVpns(
vpnName, nextHop.getIpAddress(), nh, allocatedRd, interfaceName, writeConfigTxn,
writeOperTx);
boolean isL3VpnOverVxLan = VpnUtil.isL3VpnOverVxLan(l3vni);
VrfEntry.EncapType encapType = isL3VpnOverVxLan ? VrfEntry.EncapType.Vxlan : VrfEntry.EncapType.Mplsgre;
VpnPopulator registeredPopulator = L3vpnRegistry.getRegisteredPopulator(encapType);
- List<Adjacency> nextHops = (adjacencies != null) ? adjacencies.getAdjacency() : Collections.emptyList();
+ List<Adjacency> nextHops = (adjacencies != null) ? adjacencies.getAdjacency() : emptyList();
List<Adjacency> value = new ArrayList<>();
for (Adjacency nextHop : nextHops) {
String rd = primaryRd;
String srcTepIp = stateTunnelList.getSrcInfo().getTepIp().stringValue();
BigInteger srcDpnId = new BigInteger(stateTunnelList.getSrcInfo().getTepDeviceId());
AdjacenciesOp adjacencies = vpnInterface.augmentation(AdjacenciesOp.class);
- List<Adjacency> adjList = adjacencies != null ? adjacencies.getAdjacency() : new ArrayList<>();
+ List<Adjacency> adjList =
+ adjacencies != null && adjacencies.getAdjacency() != null ? adjacencies.getAdjacency() : emptyList();
if (adjList.isEmpty()) {
LOG.trace("updateVpnInterfaceOnTepAdd: Adjacencies are empty for vpnInterface {} on dpn {}",
vpnInterface, srcDpnId);
List<String> nextHopList = adj.getNextHopIpList();
// If TEP is added , update the nexthop of primary adjacency.
// Secondary adj nexthop is already pointing to primary adj IP address.
- if (nextHopList != null && !nextHopList.isEmpty()) {
- /* everything right already */
- } else {
+ if (nextHopList == null || nextHopList.isEmpty()) {
isNextHopAddReqd = true;
}
}
String prefix = vrfEntry.getDestPrefix();
String gwMac = vrfEntry.getGatewayMacAddress();
- vrfEntry.getRoutePaths().forEach(routePath -> {
- String nh = routePath.getNexthopAddress();
- int label = routePath.getLabel().intValue();
- if (FibHelper.isControllerManagedVpnInterfaceRoute(RouteOrigin.value(
- vrfEntry.getOrigin()))) {
- LOG.info(
- "handleVpnsExportingRoutesImporting: Importing fib entry rd {} prefix {}"
- + " nexthop {} label {} to vpn {} vpnRd {}",
- vpn.getVrfId(), prefix, nh, label, vpnName, vpnRd);
- fibManager.addOrUpdateFibEntry(vpnRd, null /*macAddress*/, prefix,
- Collections.singletonList(nh), VrfEntry.EncapType.Mplsgre, label,
- 0 /*l3vni*/, gwMac, vpn.getVrfId(), RouteOrigin.SELF_IMPORTED,
- confTx);
- } else {
- LOG.info("handleVpnsExportingRoutes: Importing subnet route fib entry rd {} "
- + "prefix {} nexthop {} label {} to vpn {} vpnRd {}",
- vpn.getVrfId(), prefix, nh, label, vpnName, vpnRd);
- SubnetRoute route = vrfEntry.augmentation(SubnetRoute.class);
- importSubnetRouteForNewVpn(vpnRd, prefix, nh, label, route, vpn.getVrfId(),
- confTx);
- }
- });
+ requireNonNullElse(vrfEntry.getRoutePaths(),
+ Collections.<RoutePaths>emptyList()).forEach(routePath -> {
+ String nh = routePath.getNexthopAddress();
+ int label = routePath.getLabel().intValue();
+ if (FibHelper.isControllerManagedVpnInterfaceRoute(RouteOrigin.value(
+ vrfEntry.getOrigin()))) {
+ LOG.info(
+ "handleVpnsExportingRoutesImporting: Importing fib entry rd {}"
+ + " prefix {} nexthop {} label {} to vpn {} vpnRd {}",
+ vpn.getVrfId(), prefix, nh, label, vpnName, vpnRd);
+ fibManager.addOrUpdateFibEntry(vpnRd, null /*macAddress*/, prefix,
+ Collections.singletonList(nh), VrfEntry.EncapType.Mplsgre, label,
+ 0 /*l3vni*/, gwMac, vpn.getVrfId(), RouteOrigin.SELF_IMPORTED,
+ confTx);
+ } else {
+ LOG.info("handleVpnsExportingRoutes: Importing subnet route fib entry"
+ + " rd {} prefix {} nexthop {} label {} to vpn {} vpnRd {}",
+ vpn.getVrfId(), prefix, nh, label, vpnName, vpnRd);
+ SubnetRoute route = vrfEntry.augmentation(SubnetRoute.class);
+ importSubnetRouteForNewVpn(vpnRd, prefix, nh, label, route, vpn.getVrfId(),
+ confTx);
+ }
+ });
} catch (RuntimeException e) {
LOG.error("getNextHopAddressList: Exception occurred while importing route with rd {}"
+ " prefix {} routePaths {} to vpn {} vpnRd {}", vpn.getVrfId(),
public void remove(InstanceIdentifier<VpnInterface> identifier, VpnInterface vpnInterface) {
final VpnInterfaceKey key = identifier.firstKeyOf(VpnInterface.class, VpnInterfaceKey.class);
final String interfaceName = key.getName();
- for (VpnInstanceNames vpnInterfaceVpnInstance : vpnInterface.getVpnInstanceNames()) {
+ for (VpnInstanceNames vpnInterfaceVpnInstance : requireNonNullElse(vpnInterface.getVpnInstanceNames(),
+ Collections.<VpnInstanceNames>emptyList())) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
removeVpnInterfaceCall(identifier, vpnInterface, vpnName, interfaceName);
}
txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, writeInvTxn -> {
LOG.info("remove: - intfName {} onto vpnName {} running config-driven",
interfaceName, vpnName);
- BigInteger dpId = BigInteger.ZERO;
- int ifIndex = 0;
- String gwMacAddress = null;
+ BigInteger dpId;
+ int ifIndex;
+ String gwMacAddress;
InstanceIdentifier<VpnInterfaceOpDataEntry> interfaceId =
VpnUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
- Optional<VpnInterfaceOpDataEntry> optVpnInterface = Optional.absent();
+ Optional<VpnInterfaceOpDataEntry> optVpnInterface;
try {
optVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker,
LogicalDatastoreType.OPERATIONAL, interfaceId);
String primaryRd = vpnUtil.getVpnRd(vpnName);
LOG.info("removeAdjacenciesFromVpn: For interface {} on dpn {} RD recovered for vpn {} as rd {}",
interfaceName, dpnId, vpnName, primaryRd);
- if (adjacencies.isPresent() && !adjacencies.get().getAdjacency().isEmpty()) {
+ if (adjacencies.isPresent() && adjacencies.get().getAdjacency() != null
+ && !adjacencies.get().getAdjacency().isEmpty()) {
List<Adjacency> nextHops = adjacencies.get().getAdjacency();
LOG.info("removeAdjacenciesFromVpn: NextHops for interface {} on dpn {} for vpn {} are {}",
interfaceName, dpnId, vpnName, nextHops);
} else {
// This is a primary adjacency
nhList = nextHop.getNextHopIpList() != null ? nextHop.getNextHopIpList()
- : Collections.emptyList();
+ : emptyList();
removeGwMacAndArpResponderFlows(nextHop, vpnId, dpnId, lportTag, gwMac,
interfaceName, writeInvTxn);
}
if (!nhList.isEmpty()) {
- if (rd.equals(vpnName)) {
+ if (Objects.equals(rd, vpnName)) {
//this is an internal vpn - the rd is assigned to the vpn instance name;
//remove from FIB directly
nhList.forEach(removeAdjacencyFromInternalVpn(nextHop, vpnName,
+ " extra-route/learned-route in rd {} prefix {} interface {} on dpn {}"
+ " for vpn {}", nextHop.getVrfId(), nextHop.getIpAddress(), interfaceName, dpnId,
vpnName);
- nhList = Collections.emptyList();
+ nhList = emptyList();
} else {
nhList = Collections.singletonList(nextHopIp);
}
original.getName(), dpnId,
VpnHelper.getVpnInterfaceVpnInstanceNamesString(original.getVpnInstanceNames()),
VpnHelper.getVpnInterfaceVpnInstanceNamesString(update.getVpnInstanceNames()));
- return Collections.emptyList();
+ return emptyList();
}
updateVpnInstanceAdjChange(original, update, vpnInterfaceName, futures);
return futures;
!= null ? updateAdjs.getAdjacency() : new ArrayList<>();
final BigInteger dpnId = InterfaceUtils.getDpnForInterface(ifaceMgrRpcService, vpnInterfaceName);
- for (VpnInstanceNames vpnInterfaceVpnInstance : update.getVpnInstanceNames()) {
+ for (VpnInstanceNames vpnInterfaceVpnInstance : requireNonNullElse(update.getVpnInstanceNames(),
+ Collections.<VpnInstanceNames>emptyList())) {
String newVpnName = vpnInterfaceVpnInstance.getVpnName();
List<Adjacency> copyNewAdjs = new ArrayList<>(newAdjs);
List<Adjacency> copyOldAdjs = new ArrayList<>(oldAdjs);
VrfEntry.EncapType encapType = VpnUtil.getEncapType(isL3VpnOverVxLan);
long l3vni = vpnInstanceOpData.getL3vni() == null ? 0L : vpnInstanceOpData.getL3vni();
VpnPopulator populator = L3vpnRegistry.getRegisteredPopulator(encapType);
- List<Adjacency> adjacencies;
- if (optAdjacencies.isPresent()) {
- adjacencies = optAdjacencies.get().getAdjacency();
- } else {
- // This code will be hit in case of first PNF adjacency
- adjacencies = new ArrayList<>();
+ List<Adjacency> adjacencies = new ArrayList<>();
+ if (optAdjacencies.isPresent() && optAdjacencies.get().getAdjacency() != null) {
+ adjacencies.addAll(optAdjacencies.get().getAdjacency());
}
long vpnId = vpnUtil.getVpnId(vpnName);
L3vpnInput input = new L3vpnInput().setNextHop(adj).setVpnName(vpnName)
prefix), pnfPrefix, true);
fibManager.addOrUpdateFibEntry(adj.getSubnetId().getValue(), adj.getMacAddress(),
- adj.getIpAddress(), Collections.emptyList(), null /* EncapType */, 0 /* label */,
+ adj.getIpAddress(), emptyList(), null /* EncapType */, 0 /* label */,
0 /*l3vni*/, null /* gw-mac */, parentVpnRd, RouteOrigin.LOCAL, writeConfigTxn);
input.setRd(adj.getVrfId());
}
}
+ @Nullable
private String getParentVpnRdForExternalSubnet(Adjacency adj) {
Subnets subnets = vpnUtil.getExternalSubnet(adj.getSubnetId());
return subnets != null ? subnets.getExternalNetworkId().getValue() : null;
if (optAdjacencies.isPresent()) {
List<Adjacency> adjacencies = optAdjacencies.get().getAdjacency();
- if (!adjacencies.isEmpty()) {
+ if (adjacencies != null && !adjacencies.isEmpty()) {
LOG.trace("delAdjFromVpnInterface: Adjacencies are {}", adjacencies);
- Iterator<Adjacency> adjIt = adjacencies.iterator();
- while (adjIt.hasNext()) {
- Adjacency adjElem = adjIt.next();
- if (adjElem.getIpAddress().equals(adj.getIpAddress())) {
- String rd = adjElem.getVrfId();
+ for (Adjacency adjacency : adjacencies) {
+ if (Objects.equals(adjacency.getIpAddress(), adj.getIpAddress())) {
+ String rd = adjacency.getVrfId();
if (adj.getNextHopIpList() != null) {
for (String nh : adj.getNextHopIpList()) {
deleteExtraRouteFromCurrentAndImportingVpns(
Adjacencies adjs = vpnInterface.augmentation(Adjacencies.class);
String rd = vpnUtil.getVpnRd(vpnName);
if (adjs != null) {
- List<Adjacency> adjsList = adjs.getAdjacency();
+ List<Adjacency> adjsList = requireNonNullElse(adjs.getAdjacency(), emptyList());
for (Adjacency adj : adjsList) {
if (adj.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
String primaryInterfaceIp = adj.getIpAddress();
.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
addVpnInterfaceToVpn(vpnInterfaceOpIdentifier, intefaceData.vpnInterface, null, null,
intefaceData.identifier, vpnName);
- return;
}
private void addToUnprocessedVpnInterfaces(InstanceIdentifier<VpnInterface> identifier,
LOG.debug("There is no adjacency available for vpnInterface:{}", vpnInterface);
return;
}
- List<Adjacency> operationVpnAdjacencies = vpnInterfaceOptional.get()
- .augmentation(AdjacenciesOp.class).getAdjacency();
+ List<Adjacency> operationVpnAdjacencies = requireNonNullElse(vpnInterfaceOptional.get()
+ .augmentation(AdjacenciesOp.class).getAdjacency(), emptyList());
// Due to insufficient rds, some of the extra route wont get processed when it is added.
// The unprocessed adjacencies will be present in config vpn interface DS but will be missing
// in operational DS. These unprocessed adjacencies will be handled below.
configVpnAdjacencies.stream()
.filter(adjacency -> operationVpnAdjacencies.stream()
.noneMatch(operationalAdjacency ->
- operationalAdjacency.getIpAddress().equals(adjacency.getIpAddress())))
+ Objects.equals(operationalAdjacency.getIpAddress(), adjacency.getIpAddress())))
.forEach(adjacency -> {
LOG.debug("Processing the vpnInterface{} for the Ajacency:{}", vpnInterface, adjacency);
jobCoordinator.enqueueJob("VPNINTERFACE-" + vpnInterface.getInterfaceName(),
.getDpnId(), operTx, confTx, confTx)))));
return futures;
} else {
- return Collections.emptyList();
+ return emptyList();
}
});
});
*/
package org.opendaylight.netvirt.vpnmanager;
+import static org.opendaylight.netvirt.vpnmanager.VpnUtil.requireNonNullElse;
+
import com.google.common.base.Optional;
import java.util.ArrayList;
import java.util.Collections;
prefixToInterfaceLocal.add(prefix.get());
}
if (prefixToInterfaceLocal.isEmpty()) {
- for (String nh : adjacency.getNextHopIpList()) {
+ for (String nh : requireNonNullElse(adjacency.getNextHopIpList(),
+ Collections.<String>emptyList())) {
prefix = SingleTransactionDataBroker.syncReadOptional(dataBroker,
LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(
vpnInstOp.getVpnId(), VpnUtil.getIpPrefix(nh)));
*/
package org.opendaylight.netvirt.vpnmanager;
+import static org.opendaylight.netvirt.vpnmanager.VpnUtil.requireNonNullElse;
+
import com.google.common.base.Optional;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.math.BigInteger;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Singleton;
}
@Override
- public void addExtraRoute(String vpnName, String destination, String nextHop, String rd, String routerID,
- Long l3vni, RouteOrigin origin, String intfName, Adjacency operationalAdj, VrfEntry.EncapType encapType,
- @Nonnull TypedWriteTransaction<Configuration> confTx) {
+ public void addExtraRoute(String vpnName, String destination, String nextHop, String rd, @Nullable String routerID,
+ Long l3vni, RouteOrigin origin, @Nullable String intfName, @Nullable Adjacency operationalAdj,
+ VrfEntry.EncapType encapType, @Nonnull TypedWriteTransaction<Configuration> confTx) {
//add extra route to vpn mapping; advertise with nexthop as tunnel ip
vpnUtil.syncUpdate(LogicalDatastoreType.OPERATIONAL,
VpnExtraRouteHelper.getVpnToExtrarouteVrfIdIdentifier(vpnName, rd != null ? rd : routerID,
}
@Override
- public void delExtraRoute(String vpnName, String destination, String nextHop, String rd, String routerID,
- String intfName, @Nonnull TypedWriteTransaction<Configuration> confTx,
+ public void delExtraRoute(String vpnName, String destination, String nextHop, String rd, @Nullable String routerID,
+ @Nullable String intfName, @Nonnull TypedWriteTransaction<Configuration> confTx,
@Nonnull TypedWriteTransaction<Operational> operTx) {
BigInteger dpnId = null;
String tunnelIp = nextHop;
}
String extIfc = null;
- for (String dpnInterface : dpnInterfaces.getInterfaces()) {
+ for (String dpnInterface : requireNonNullElse(dpnInterfaces.getInterfaces(),
+ Collections.<String>emptyList())) {
if (interfaceManager.isExternalInterface(dpnInterface)) {
extIfc = dpnInterface;
break;
}
@Override
+ @Nullable
public VpnInstance getVpnInstance(DataBroker broker, String vpnInstanceName) {
return vpnUtil.getVpnInstance(vpnInstanceName);
}
@Override
public VpnPortipToPort getNeutronPortFromVpnPortFixedIp(TypedReadTransaction<Configuration> confTx, String vpnName,
String fixedIp) {
- return vpnUtil.getNeutronPortFromVpnPortFixedIp(confTx, vpnName, fixedIp);
+ return VpnUtil.getNeutronPortFromVpnPortFixedIp(confTx, vpnName, fixedIp);
}
@Override
+ @Nullable
public VpnPortipToPort getNeutronPortFromVpnPortFixedIp(DataBroker broker, String vpnName, String fixedIp) {
return vpnUtil.getNeutronPortFromVpnPortFixedIp(vpnName, fixedIp);
}
Optional<RouteTarget> indirectRts = SingleTransactionDataBroker.syncReadOptional(dataBroker,
LogicalDatastoreType.OPERATIONAL, VpnUtil.getRouteTargetsIdentifier(
routerTarget.getRt(), RouteTarget.RtType.ERT));
- if (indirectRts.isPresent() && routerTarget.getAssociatedSubnet() != null) {
+ if (indirectRts.isPresent() && indirectRts.get().getAssociatedSubnet() != null
+ && routerTarget.getAssociatedSubnet() != null) {
for (AssociatedSubnet associatedSubnet : indirectRts.get().getAssociatedSubnet()) {
if (VpnUtil.areSubnetsOverlapping(associatedSubnet.getCidr(), subnetCidr)) {
LOG.error("doesExistingVpnsHaveConflictingSubnet: There is an indirect overlap for"
} else {
for (Iterator<AssociatedVpn> iterator = associatedVpns.iterator(); iterator.hasNext();) {
AssociatedVpn associatedVpn = iterator.next();
- if (associatedVpn.getName().equals(vpnName)) {
+ if (Objects.equals(associatedVpn.getName(), vpnName)) {
iterator.remove();
break;
}
List<AssociatedSubnet> associatedSubnets = rtToSubnetsAssociation.get().getAssociatedSubnet();
if (associatedSubnets != null && !associatedSubnets.isEmpty()) {
for (Iterator<AssociatedSubnet> iterator = associatedSubnets.iterator(); iterator.hasNext(); ) {
- if (iterator.next().getCidr().equals(cidr)) {
+ if (Objects.equals(iterator.next().getCidr(), cidr)) {
iterator.remove();
break;
}
*/
package org.opendaylight.netvirt.vpnmanager;
+import static java.util.Collections.emptyList;
+import static org.opendaylight.netvirt.vpnmanager.VpnUtil.requireNonNullElse;
+
import com.google.common.base.Optional;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
&& vpnFootprintService.isVpnFootPrintCleared(update)) {
//Cleanup VPN data
final String vpnName = update.getVpnInstanceName();
- final List<String> rds = update.getRd();
+ final List<String> rds = requireNonNullElse(update.getRd(), emptyList());
String primaryRd = update.getVrfId();
final long vpnId = vpnUtil.getVpnId(vpnName);
jobCoordinator.enqueueJob("VPN-" + update.getVpnInstanceName(), () -> {
}
jobCoordinator.enqueueJob("VPN-" + update.getVpnInstanceName(), () -> {
//RD update case get only updated RD list
- List<String> rds = update.getRd();
- if (original.getRd().size() != update.getRd().size()) {
- List<String> oldRds = original.getRd();
- rds.removeAll(oldRds);
+ List<String> rds = update.getRd() != null ? new ArrayList<>(update.getRd()) : new ArrayList<>();
+ if (original.getRd() != null && original.getRd().size() != rds.size()) {
+ rds.removeAll(original.getRd());
}
rds.parallelStream().forEach(rd -> {
try {
- List<String> importRTList = rd.equals(primaryRd) ? irtList : Collections.emptyList();
+ List<String> importRTList = rd.equals(primaryRd) ? irtList : emptyList();
LOG.info("VpnOpStatusListener.update: updating BGPVPN for vpn {} with RD {}"
+ " Type is {}, IPv4 is {}, IPv6 is {}, iRT {}", vpnName, primaryRd, update.getType(),
update.isIpv4Configured(), update.isIpv6Configured(), importRTList);
+ " for vpn {} rd {}", vpnName, rd);
}
});
- return Collections.emptyList();
+ return emptyList();
});
}
}
import java.util.List;
import java.util.Map;
import java.util.Objects;
+import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
- private void electNewDpnForSubnetRoute(SubnetOpDataEntryBuilder subOpBuilder, BigInteger oldDpnId, Uuid subnetId,
- Uuid networkId, boolean isBgpVpn) {
+ private void electNewDpnForSubnetRoute(SubnetOpDataEntryBuilder subOpBuilder, @Nullable BigInteger oldDpnId,
+ Uuid subnetId, Uuid networkId, boolean isBgpVpn) {
List<SubnetToDpn> subDpnList = null;
boolean isRouteAdvertised = false;
subDpnList = subOpBuilder.getSubnetToDpn();
package org.opendaylight.netvirt.vpnmanager;
+import static java.util.Collections.emptyList;
+import static java.util.Objects.requireNonNull;
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 org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntryKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentrybase.RoutePaths;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.L3nexthop;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.VpnNexthops;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3nexthop.rev150409.l3nexthop.VpnNexthopsKey;
.child(VpnInstance.class, new VpnInstanceKey(vpnName)).build();
}
+ @Nullable
VpnInterface getVpnInterface(String vpnInterfaceName) {
InstanceIdentifier<VpnInterface> id = getVpnInterfaceIdentifier(vpnInterfaceName);
Optional<VpnInterface> vpnInterface = read(LogicalDatastoreType.CONFIGURATION, id);
* @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
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();
+ return
+ vpnInstanceOpDataOptional.isPresent() && vpnInstanceOpDataOptional.get().getVpnInstanceOpDataEntry() != null
+ ? vpnInstanceOpDataOptional.get().getVpnInstanceOpDataEntry()
+ : 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) {
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();
}
+ @Nullable
String getVpnInterfaceName(BigInteger metadata) throws InterruptedException, ExecutionException {
GetInterfaceFromIfIndexInputBuilder ifIndexInputBuilder = new GetInterfaceFromIfIndexInputBuilder();
BigInteger lportTag = MetaDataUtil.getLportFromMetadata(metadata);
ListenableFutures.addErrorLogging(
new ManagedNewTransactionRunnerImpl(dataBroker).callWithNewWriteOnlyTransactionAndSubmit(
Datastore.CONFIGURATION, tx -> {
- for (VrfEntry vrfEntry : vrfTables.getVrfEntry()) {
+ for (VrfEntry vrfEntry : requireNonNullElse(vrfTables.getVrfEntry(),
+ Collections.<VrfEntry>emptyList())) {
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 : requireNonNullElse(vrfTables.getVrfEntry(), Collections.<VrfEntry>emptyList())) {
+ requireNonNullElse(vrfEntry.getRoutePaths(), Collections.<RoutePaths>emptyList()).stream()
.filter(routePath -> routePath.getNexthopAddress() != null && routePath.getNexthopAddress()
.equals(nexthop)).findFirst().ifPresent(routePath -> matches.add(vrfEntry));
}
* @param vpnId Dataplane identifier of the VPN
* @return the Vpn instance name
*/
+ @Nullable
String getVpnName(long vpnId) {
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.id.to.vpn
.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);
}
// 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);
}
void scheduleVpnInterfaceForRemoval(String interfaceName, BigInteger dpnId, String vpnInstanceName,
- TypedWriteTransaction<Operational> writeOperTxn) {
+ @Nullable TypedWriteTransaction<Operational> writeOperTxn) {
InstanceIdentifier<VpnInterfaceOpDataEntry> interfaceId =
getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnInstanceName);
VpnInterfaceOpDataEntry interfaceToUpdate =
}
void removeLearntVpnVipToPort(String vpnName, String fixedIp,
- TypedWriteTransaction<Operational> writeOperTxn) {
+ @Nullable TypedWriteTransaction<Operational> writeOperTxn) {
synchronized ((vpnName + fixedIp).intern()) {
InstanceIdentifier<LearntVpnVipToPort> id = buildLearntVpnVipToPortIdentifier(vpnName, fixedIp);
if (writeOperTxn != null) {
}
protected static void removeVpnPortFixedIpToPort(DataBroker broker, String vpnName, String fixedIp,
- TypedWriteTransaction<Configuration> writeConfigTxn) {
+ @Nullable TypedWriteTransaction<Configuration> writeConfigTxn) {
synchronized ((vpnName + fixedIp).intern()) {
InstanceIdentifier<VpnPortipToPort> id = buildVpnPortipToPortIdentifier(vpnName, fixedIp);
if (writeConfigTxn != null) {
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);
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 result;
}
+ @Nullable
String getAssociatedExternalRouter(String extIp) {
InstanceIdentifier<ExtRouters> extRouterInstanceIndentifier =
InstanceIdentifier.builder(ExtRouters.class).build();
String routerName = null;
- for (Routers routerData : extRouterData.get().getRouters()) {
- List<ExternalIps> externalIps = routerData.getExternalIps();
+ for (Routers routerData : requireNonNullElse(extRouterData.get().getRouters(),
+ Collections.<Routers>emptyList())) {
+ List<ExternalIps> externalIps = requireNonNullElse(routerData.getExternalIps(), emptyList());
for (ExternalIps externalIp : externalIps) {
- if (externalIp.getIpAddress().equals(extIp)) {
+ if (Objects.equals(externalIp.getIpAddress(), extIp)) {
routerName = routerData.getRouterName();
break;
}
return routerName;
}
- for (Routers routerData : extRouterData.get().getRouters()) {
- List<ExternalIps> externalIps = routerData.getExternalIps();
+ for (Routers routerData : requireNonNullElse(extRouterData.get().getRouters(),
+ Collections.<Routers>emptyList())) {
+ List<ExternalIps> externalIps = requireNonNullElse(routerData.getExternalIps(), emptyList());
for (ExternalIps externalIp : externalIps) {
Subnet neutronSubnet = neutronVpnService.getNeutronSubnet(externalIp.getSubnetId());
if (neutronSubnet == null) {
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();
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();
}
+ @Nullable
BigInteger getPrimarySwitchForRouter(String routerName) {
RouterToNaptSwitch routerToNaptSwitch = getRouterToNaptSwitch(routerName);
return routerToNaptSwitch != null ? routerToNaptSwitch.getPrimarySwitchId() : null;
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());
return isVxLan ? VrfEntryBase.EncapType.Vxlan : VrfEntryBase.EncapType.Mplsgre;
}
+ @Nullable
org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.Subnets
getExternalSubnet(Uuid subnetId) {
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets
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 BigInteger 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;
* @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) {
Optional<ElanDpnInterfacesList> dpnInElanInterfaces = read(LogicalDatastoreType.OPERATIONAL,
elanDpnInterfaceId);
if (dpnInElanInterfaces.isPresent()) {
- List<DpnInterfaces> dpnInterfaces = dpnInElanInterfaces.get().getDpnInterfaces();
+ List<DpnInterfaces> dpnInterfaces =
+ requireNonNullElse(dpnInElanInterfaces.get().getDpnInterfaces(), emptyList());
for (DpnInterfaces dpnInterface : dpnInterfaces) {
dpnIdSet.add(dpnInterface.getDpId());
}
}
+ @Nullable
ElanInterface getElanInterfaceByElanInterfaceName(String elanInterfaceName) {
InstanceIdentifier<ElanInterface> elanInterfaceId = getElanInterfaceConfigurationDataPathId(elanInterfaceName);
return read(LogicalDatastoreType.CONFIGURATION, elanInterfaceId).orNull();
.child(ElanInterface.class, new ElanInterfaceKey(interfaceName)).build();
}
+ @Nullable
DpnInterfaces getElanInterfaceInfoByElanDpn(String elanInstanceName, BigInteger dpId) {
InstanceIdentifier<DpnInterfaces> elanDpnInterfacesId = getElanDpnInterfaceOperationalDataPath(elanInstanceName,
dpId);
return read(LogicalDatastoreType.OPERATIONAL, elanDpnInterfacesId).orNull();
}
+ @Nullable
String getExternalElanInterface(String elanInstanceName, BigInteger dpnId) {
DpnInterfaces dpnInterfaces = getElanInterfaceInfoByElanDpn(elanInstanceName, dpnId);
if (dpnInterfaces == null || dpnInterfaces.getInterfaces() == null) {
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()) {
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, BigInteger dpnId) {
Map<String,String> elanInstanceRouterPortMap = getElanInstanceRouterPortMap(vpnName);
boolean shouldPopulateFibForVlan = false;
if (!elanInstanceRouterPortMap.isEmpty()) {
}
public List<String> getVpnListForVpnInterface(VpnInterface vpnInter) {
- return vpnInter.getVpnInstanceNames().stream()
+ return requireNonNullElse(vpnInter.getVpnInstanceNames(), Collections.<VpnInstanceNames>emptyList()).stream()
.map(VpnInstanceNames::getVpnName).collect(Collectors.toList());
}
}));
});
}
+
+ // Use Objects.requireNonNullElse instead with JDK9+
+ @Nonnull
+ public static <T> T requireNonNullElse(@Nullable T obj, @Nonnull T defaultObj) {
+ return obj != null ? obj : requireNonNull(defaultObj);
+ }
}
*/
package org.opendaylight.netvirt.vpnmanager.intervpnlink;
+import static java.util.Collections.emptyList;
import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.netvirt.vpnmanager.VpnUtil.requireNonNullElse;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.stream.Collectors;
+import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntryBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntryKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentrybase.RoutePaths;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.VpnMaps;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes;
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public void leakRoute(InterVpnLinkDataComposite interVpnLink, String srcVpnUuid, String dstVpnUuid,
- String prefix, Long label, RouteOrigin forcedOrigin) {
+ String prefix, Long label, @Nullable RouteOrigin forcedOrigin) {
String ivpnLinkName = interVpnLink.getInterVpnLinkName();
// The source VPN must participate in the InterVpnLink
Preconditions.checkArgument(interVpnLink.isVpnLinked(srcVpnUuid),
String vpn2Endpoint = vpnLink.getOtherEndpointIpAddr(vpn2Uuid);
List<VrfEntry> allVpnVrfEntries = vpnUtil.getAllVrfEntries(vpn1Rd);
for (VrfEntry vrfEntry : allVpnVrfEntries) {
- vrfEntry.getRoutePaths().stream()
- .filter(routePath -> routePath.getNexthopAddress().equals(vpn2Endpoint))
+ requireNonNullElse(vrfEntry.getRoutePaths(), Collections.<RoutePaths>emptyList()).stream()
+ .filter(routePath -> Objects.equals(routePath.getNexthopAddress(), vpn2Endpoint))
.forEach(routePath -> {
// Vpn1 has a route pointing to Vpn2's endpoint. Forcing the leaking of the route will update
// the BGP accordingly
return new HashMap<>();
}
Map<String,String> vmap = new HashMap<>();
- final List<VpnMap> VpnMapList = optVpnMaps.get().getVpnMap();
+ final List<VpnMap> VpnMapList = requireNonNullElse(optVpnMaps.get().getVpnMap(), emptyList());
for (VpnMap map : VpnMapList) {
if (map.getRouterIds() == null) {
continue;
return;
}
- List<Router> routers = routerOpData.get().getRouter();
+ List<Router> routers = requireNonNullElse(routerOpData.get().getRouter(), emptyList());
for (Router router : routers) {
String vpnId = routerXL3VpnMap.get(router.getUuid().getValue());
if (vpnId == null) {
package org.opendaylight.netvirt.vpnmanager.intervpnlink;
+import static org.opendaylight.netvirt.vpnmanager.VpnUtil.requireNonNullElse;
+
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
+import java.util.Collections;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Singleton;
return; // Nothing to be added to cache
}
InterVpnLinks interVpnLinks = optIVpnLinksOpData.get();
- for (InterVpnLink interVpnLink : interVpnLinks.getInterVpnLink()) {
+ for (InterVpnLink interVpnLink : requireNonNullElse(interVpnLinks.getInterVpnLink(),
+ Collections.<InterVpnLink>emptyList())) {
addInterVpnLinkToCaches(interVpnLink);
}
return;
}
InterVpnLinkStates interVpnLinkStates = optIVpnLinkStateOpData.get();
- for (InterVpnLinkState interVpnLinkState : interVpnLinkStates.getInterVpnLinkState()) {
+ for (InterVpnLinkState interVpnLinkState : requireNonNullElse(interVpnLinkStates.getInterVpnLinkState(),
+ Collections.<InterVpnLinkState>emptyList())) {
addInterVpnLinkStateToCaches(interVpnLinkState);
}
}
return ImmutableList.copyOf(nameToInterVpnLinkCache.values());
}
- private <T> void safeRemove(ConcurrentMap<T, ?> fromMap, T key) {
+ private <T> void safeRemove(ConcurrentMap<T, ?> fromMap, @Nullable T key) {
if (key != null) {
fromMap.remove(key);
}
}
- private <K, V> V safeGet(ConcurrentMap<K, V> fromMap, K key) {
+ @Nullable
+ private <K, V> V safeGet(ConcurrentMap<K, V> fromMap, @Nullable K key) {
return key != null ? fromMap.get(key) : null;
}
- private <K, V> void safePut(ConcurrentMap<K, V> toMap, K key, V value) {
+ private <K, V> void safePut(ConcurrentMap<K, V> toMap, @Nullable K key, V value) {
if (key != null) {
toMap.put(key, value);
}
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
+import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
+import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
int pendingDPNs = numberOfDpns - result.size();
List<BigInteger> dpnsToAvoid = findDpnsWithSimilarIVpnLinks(interVpnLink, allInterVpnLinks);
- result.addAll(dpnIdPool.stream().filter(dpId -> dpnsToAvoid == null || !dpnsToAvoid.contains(dpId))
+ result.addAll(dpnIdPool.stream().filter(dpId -> !dpnsToAvoid.contains(dpId))
.limit(pendingDPNs).collect(Collectors.toList()));
int currentNbrOfItems = result.size();
* @return the list of dpnIds where the specified InterVpnLink should not
* be installed
*/
+ @Nonnull
private List<BigInteger> findDpnsWithSimilarIVpnLinks(InterVpnLink interVpnLink,
List<InterVpnLinkDataComposite> allInterVpnLinks) {
List<InterVpnLinkDataComposite> sameGroupInterVpnLinks = findInterVpnLinksSameGroup(interVpnLink,
return new ArrayList<>();
}
return vpnTargets.stream()
- .filter(target -> target.getVrfRTType().equals(rtType)
- || target.getVrfRTType().equals(VpnTarget.VrfRTType.Both))
+ .filter(target -> Objects.equals(target.getVrfRTType(), rtType)
+ || Objects.equals(target.getVrfRTType(), VpnTarget.VrfRTType.Both))
.map(VpnTarget::getVrfRTValue)
.collect(Collectors.toList());
}
if (irts1 == null && irts2 == null) {
return true;
}
- if (irts1 == null && irts2 != null || irts1 != null && irts2 == null) {
+ if (irts1 == null || irts2 == null) {
return false;
}
package org.opendaylight.netvirt.vpnmanager.iplearn;
import com.google.common.util.concurrent.ListenableFuture;
+import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import org.opendaylight.netvirt.vpnmanager.iplearn.model.MacEntry;
@Override
public List<ListenableFuture<Void>> call() {
alivenessMonitorUtils.startIpMonitoring(macEntry, arpMonitorProfileId);
- return null;
+ return Collections.emptyList();
}
}
import com.google.common.util.concurrent.ListenableFuture;
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
import java.util.concurrent.Callable;
import org.opendaylight.netvirt.vpnmanager.VpnUtil;
import org.opendaylight.netvirt.vpnmanager.iplearn.model.MacEntry;
public List<ListenableFuture<Void>> call() {
final List<ListenableFuture<Void>> futures = new ArrayList<>();
java.util.Optional<Long> monitorIdOptional = AlivenessMonitorUtils.getMonitorIdFromInterface(macEntry);
- monitorIdOptional.ifPresent(monitorId -> {
- alivenessMonitorUtils.stopIpMonitoring(monitorId);
- });
+ monitorIdOptional.ifPresent(alivenessMonitorUtils::stopIpMonitoring);
String learntIp = macEntry.getIpAddress().getHostAddress();
if (this.isRemoveMipAdjAndLearntIp) {
String vpnName = macEntry.getVpnName();
LearntVpnVipToPort vpnVipToPort = vpnUtil.getLearntVpnVipToPort(vpnName, learntIp);
- if (vpnVipToPort != null && !vpnVipToPort.getCreationTime().equals(macEntry.getCreatedTime())) {
+ if (vpnVipToPort != null && !Objects.equals(vpnVipToPort.getCreationTime(), macEntry.getCreatedTime())) {
LOG.warn("The MIP {} over vpn {} has been learnt again and processed. "
+ "Ignoring this remove event.", learntIp, vpnName);
return futures;
*/
package org.opendaylight.netvirt.vpnmanager.iplearn;
+import static java.util.Collections.emptyList;
+import static org.opendaylight.netvirt.vpnmanager.VpnUtil.requireNonNullElse;
+
import com.google.common.base.Optional;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Objects;
import java.util.concurrent.Callable;
+import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.Adjacencies;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacencyList;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.LearntVpnVipToPortEventAction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.LearntVpnVipToPortEventData;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency;
.withKey(new AdjacencyKey(ip)).setAdjacencyType(AdjacencyType.PrimaryAdjacency)
.setMacAddress(mipMacAddress).setSubnetId(new Uuid(subnetId)).setPhysNetworkFunc(true);
- List<Adjacency> adjacencyList = adjacencies.isPresent()
- ? adjacencies.get().getAdjacency() : new ArrayList<>();
+ List<Adjacency> adjacencyList = new ArrayList<>(requireNonNullElse(
+ adjacencies.toJavaUtil().map(AdjacencyList::getAdjacency).orElse(null), emptyList()));
adjacencyList.add(newAdjBuilder.build());
}
if (adjacencies.isPresent()) {
- List<Adjacency> adjacencyList = adjacencies.get().getAdjacency();
+ List<Adjacency> adjacencyList =
+ requireNonNullElse(adjacencies.get().getAdjacency(), emptyList());
ip = VpnUtil.getIpPrefix(ip);
for (Adjacency adjacs : adjacencyList) {
if (adjacs.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
- if (adjacs.getIpAddress().equals(ip)) {
+ if (Objects.equals(adjacs.getIpAddress(), ip)) {
LOG.error("The MIP {} is already present as a primary adjacency for interface {}"
+ "vpn {} Skipping adjacency addition.", ip, vpnInterface, vpnInstName);
return;
}
}
+ @Nullable
private String getSubnetId(String vpnInstName, String ip) {
// Check if this IP belongs to a router_interface
VpnPortipToPort vpnPortipToPort =
vpnUtil.getNeutronPortFromVpnPortFixedIp(vpnInstName, ip);
if (vpnPortipToPort != null && vpnPortipToPort.isSubnetIp()) {
- List<Adjacency> adjacecnyList = vpnUtil.getAdjacenciesForVpnInterfaceFromConfig(
- vpnPortipToPort.getPortName());
- for (Adjacency adjacency : adjacecnyList) {
+ List<Adjacency> adjacencies = requireNonNullElse(vpnUtil.getAdjacenciesForVpnInterfaceFromConfig(
+ vpnPortipToPort.getPortName()), emptyList());
+ for (Adjacency adjacency : adjacencies) {
if (adjacency.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
return adjacency.getSubnetId().getValue();
}
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
+import javax.annotation.Nullable;
import org.opendaylight.genius.mdsalutil.ActionInfo;
import org.opendaylight.genius.mdsalutil.MDSALUtil;
import org.opendaylight.genius.mdsalutil.NWUtil;
ingress, lstActionInfo);
}
+ @Nullable
public static TransmitPacketInput createArpRequestInput(BigInteger dpnId, Long groupId, byte[] abySenderMAC,
byte[] abyTargetMAC, byte[] abySenderIpAddress, byte[] abyTargetIpAddress, NodeConnectorRef ingress,
List<ActionInfo> lstActionInfo) {
*/
package org.opendaylight.netvirt.vpnmanager.populator.impl;
+import static java.util.Collections.singletonList;
+
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
if (VpnUtil.isEligibleForBgp(primaryRd, input.getVpnName(), input.getDpnId(), input.getNetworkName())) {
// the DpnId is set as rd in case of extra routes present in router based VPN
addToLabelMapper(label, input.getDpnId(), nextHopIpAddress,
- Arrays.asList(nextHopIp), vpnId, input.getInterfaceName(), null,false,
+ singletonList(nextHopIp), vpnId, input.getInterfaceName(), null,false,
primaryRd);
Objects.requireNonNull(input.getRouteOrigin(), "RouteOrigin is mandatory");
addPrefixToBGP(rd, primaryRd, null /*macAddress*/, nextHopIpAddress, nextHopIp, encapType,
throw new NullPointerException(error);
}
List<String> nextHopList = adjNextHop != null && !adjNextHop.isEmpty() ? adjNextHop
- : nextHopIp == null ? Collections.emptyList() : Collections.singletonList(nextHopIp);
+ : nextHopIp == null ? Collections.emptyList() : singletonList(nextHopIp);
return new AdjacencyBuilder(nextHop).setLabel(label).setNextHopIpList(nextHopList)
.setIpAddress(prefix).setVrfId(rd).withKey(new AdjacencyKey(prefix))
import java.math.BigInteger;
import java.util.Collections;
import java.util.List;
+import javax.annotation.Nullable;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.genius.infra.Datastore.Configuration;
}
public void addToLabelMapper(Long label, BigInteger dpnId, String prefix, List<String> nextHopIpList, Long vpnId,
- String vpnInterfaceName, Long elanTag, boolean isSubnetRoute, String rd) {
+ @Nullable String vpnInterfaceName, @Nullable Long elanTag, boolean isSubnetRoute, String rd) {
Preconditions.checkNotNull(label, "addToLabelMapper: label cannot be null or empty!");
Preconditions.checkNotNull(prefix, "addToLabelMapper: prefix cannot be null or empty!");
Preconditions.checkNotNull(vpnId, "addToLabelMapper: vpnId cannot be null or empty!");
}
@SuppressWarnings("checkstyle:IllegalCatch")
- protected void addPrefixToBGP(String rd, String primaryRd, String macAddress, String prefix, String nextHopIp,
- VrfEntry.EncapType encapType, long label, long l3vni, String gatewayMac,
- RouteOrigin origin, TypedWriteTransaction<Configuration> writeConfigTxn) {
+ protected void addPrefixToBGP(String rd, String primaryRd, @Nullable String macAddress, String prefix,
+ String nextHopIp, VrfEntry.EncapType encapType, long label, long l3vni,
+ String gatewayMac, RouteOrigin origin,
+ TypedWriteTransaction<Configuration> writeConfigTxn) {
try {
List<String> nextHopList = Collections.singletonList(nextHopIp);
LOG.info("ADD: addPrefixToBGP: Adding Fib entry rd {} prefix {} nextHop {} label {} gwMac {}", rd, prefix,
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ExecutionException;
+import javax.annotation.Nullable;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.commands.Option;
import org.apache.karaf.shell.console.OsgiCommandSupport;
}
@Override
+ @Nullable
protected Object doExecute() {
Map<String, Integer> vpnNameToConfigInterfaceMap = new HashMap<>();
Map<String, Integer> vpnNameToOperInterfaceMap = new HashMap<>();
if (detail == null) {
showVpn();
- Set<String> vpnInstances = new HashSet();
+ Set<String> vpnInstances = new HashSet<>();
for (VpnInterface vpnInterface : vpnInterfaceConfigList) {
- for (VpnInstanceNames vpnInterfaceVpnInstance : vpnInterface.getVpnInstanceNames()) {
- String vpnName = vpnInterfaceVpnInstance.getVpnName();
- if (vpnName != null) {
- vpnInstances.add(vpnName);
+ if (vpnInterface.getVpnInstanceNames() != null) {
+ for (VpnInstanceNames vpnInterfaceVpnInstance : vpnInterface.getVpnInstanceNames()) {
+ String vpnName = vpnInterfaceVpnInstance.getVpnName();
+ if (vpnName != null) {
+ vpnInstances.add(vpnName);
+ }
}
}
}
}
session.getConsole().println("Present Oper VpnInterfaces are:");
for (VpnInterfaceOpDataEntry vpnInterfaceOp : vpnInterfaceOpList) {
- if (vpnInterfaceOp.getVpnInstanceName().equals(detail)) {
+ if (Objects.equals(vpnInterfaceOp.getVpnInstanceName(), detail)) {
session.getConsole().println(vpnInterfaceOp.getName());
}
}
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
+import javax.annotation.Nullable;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.commands.Option;
import org.apache.karaf.shell.console.OsgiCommandSupport;
}
@Override
+ @Nullable
protected Object doExecute() {
if (detail == null) {
getVpnInstanceOpData();