import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices;
*
* @return the tunnel ip
*/
+ @Nullable
public IpAddress getTunnelIp() {
if (!tunnelIps.isEmpty()) {
return tunnelIps.iterator().next();
package org.opendaylight.netvirt.neutronvpn.api.utils;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.base.Preconditions;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
+import javax.annotation.Nonnull;
+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.TransactionCommitFailedException;
}
}
- public static List<Uuid> getVpnMapRouterIdsListUuid(List<RouterIds> routerIds) {
+ @Nonnull
+ public static List<Uuid> getVpnMapRouterIdsListUuid(@Nullable List<RouterIds> routerIds) {
if (routerIds == null) {
return Collections.emptyList();
}
routerId -> routerId.getRouterId()).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);
+ }
}
import java.util.List;
+import javax.annotation.Nullable;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.inject.Singleton;
LOG.info("{} close", getClass().getSimpleName());
}
- public void handleExternalSubnetAdded(Network network, Uuid subnetId, List<Uuid> routerIds) {
+ public void handleExternalSubnetAdded(Network network, Uuid subnetId, @Nullable List<Uuid> routerIds) {
Uuid networkId = network.getUuid();
if (NeutronvpnUtils.getIsExternal(network) && NeutronvpnUtils.isFlatOrVlanNetwork(network)) {
LOG.info("Added external subnet {} part of external network {} will create NAT external subnet",
package org.opendaylight.netvirt.neutronvpn;
import static org.opendaylight.netvirt.neutronvpn.NeutronvpnUtils.buildfloatingIpIdToPortMappingIdentifier;
+import static org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils.requireNonNullElse;
import com.google.common.base.Optional;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
+import java.util.Objects;
import java.util.concurrent.TimeUnit;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
routerPortsIdentifierBuilder.build());
if (optionalRouterPorts.isPresent()) {
RouterPorts routerPorts = optionalRouterPorts.get();
- List<Ports> portsList = routerPorts.getPorts();
+ List<Ports> portsList = requireNonNullElse(routerPorts.getPorts(), Collections.emptyList());
List<InternalToExternalPortMap> intExtPortMap = new ArrayList<>();
for (Ports ports : portsList) {
- if (ports.getPortName().equals(fixedNeutronPortName)) {
- intExtPortMap = ports.getInternalToExternalPortMap();
+ if (Objects.equals(ports.getPortName(), fixedNeutronPortName)) {
+ intExtPortMap =
+ requireNonNullElse(ports.getInternalToExternalPortMap(), Collections.emptyList());
break;
}
}
fixedNeutronPortName, isLockAcquired);
} else {
for (InternalToExternalPortMap intToExtMap : intExtPortMap) {
- if (intToExtMap.getInternalIp().equals(fixedIpAddress)) {
+ if (Objects.equals(intToExtMap.getInternalIp(), fixedIpAddress)) {
InstanceIdentifier<InternalToExternalPortMap> intExtPortMapIdentifier =
routerPortsIdentifierBuilder.child(Ports
.class, new PortsKey(fixedNeutronPortName)).child(InternalToExternalPortMap.class,
List<Ports> portsList = routerPorts.getPorts();
if (portsList != null && !portsList.isEmpty()) {
for (Ports ports : portsList) {
- if (ports.getPortName().equals(fixedNeutronPortName)) {
+ if (Objects.equals(ports.getPortName(), fixedNeutronPortName)) {
String routerName = routerPorts.getRouterId();
InstanceIdentifier.InstanceIdentifierBuilder<RouterPorts>
routerPortsIdentifierBuilder = floatingIpInfoIdentifierBuilder
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
+import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Singleton;
return hostconfigBuilder.build();
}
+ @Nullable
private String getExternalId(Node node, String key) {
OvsdbNodeAugmentation ovsdbNode = getOvsdbNodeAugmentation(node);
if (ovsdbNode != null && ovsdbNode.getOpenvswitchExternalIds() != null) {
return null;
}
+ @Nullable
private OvsdbNodeAugmentation getOvsdbNodeAugmentation(Node node) {
OvsdbNodeAugmentation ovsdbNode = southboundUtils.extractOvsdbNode(node);
if (ovsdbNode == null) {
import java.util.Objects;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Singleton;
return 0L;
}
+ @Nullable
private Class<? extends SegmentTypeBase> elanSegmentTypeFromNetworkType(
- Class<? extends NetworkTypeBase> networkType) {
+ @Nullable Class<? extends NetworkTypeBase> networkType) {
if (networkType == null) {
return null;
}
package org.opendaylight.netvirt.neutronvpn;
import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils.requireNonNullElse;
import com.google.common.base.Optional;
import com.google.common.base.Strings;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
+import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
import javax.inject.Singleton;
import org.apache.commons.lang3.ObjectUtils;
}
}
- private void handleFloatingIpPortUpdated(Port original, Port update) {
- if ((original == null || original.getDeviceId().equals(NeutronConstants.FLOATING_IP_DEVICE_ID_PENDING))
- && !update.getDeviceId().equals(NeutronConstants.FLOATING_IP_DEVICE_ID_PENDING)) {
+ private void handleFloatingIpPortUpdated(@Nullable Port original, Port update) {
+ if ((original == null || NeutronConstants.FLOATING_IP_DEVICE_ID_PENDING.equals(original.getDeviceId()))
+ && !NeutronConstants.FLOATING_IP_DEVICE_ID_PENDING.equals(update.getDeviceId())) {
// populate floating-ip uuid and floating-ip port attributes (uuid, mac and subnet id for the ONLY
// fixed IP) to be used by NAT, depopulated in NATService once mac is retrieved in the removal path
addToFloatingIpPortInfo(new Uuid(update.getDeviceId()), update.getUuid(), update.getFixedIps().get(0)
listVpnIds.add(vpnId);
Uuid internetVpnId = neutronvpnUtils.getInternetvpnUuidBoundToRouterId(routerId);
List<Subnetmap> subnetMapList = new ArrayList<>();
- List<FixedIps> portIps = routerPort.getFixedIps();
boolean portIsIpv6 = false;
- for (FixedIps portIP : portIps) {
+ for (FixedIps portIP : requireNonNullElse(routerPort.getFixedIps(),
+ Collections.<FixedIps>emptyList())) {
// NOTE: Please donot change the order of calls to updateSubnetNodeWithFixedIP
// and addSubnetToVpn here
if (internetVpnId != null
nvpnManager.createVpnInterface(listVpnIds, routerPort, null);
}
IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
- for (FixedIps portIP : routerPort.getFixedIps()) {
+ for (FixedIps portIP : requireNonNullElse(routerPort.getFixedIps(),
+ Collections.<FixedIps>emptyList())) {
String ipValue = portIP.getIpAddress().stringValue();
ipVersion = NeutronvpnUtils.getIpVersionFromString(ipValue);
if (ipVersion.isIpVersionChosen(IpVersionChoice.IPV4)) {
elanService.removeKnownL3DmacAddress(routerPort.getMacAddress().getValue(), infNetworkId.getValue());
Uuid vpnId = ObjectUtils.defaultIfNull(neutronvpnUtils.getVpnForRouter(routerId, true),
routerId);
- List<FixedIps> portIps = routerPort.getFixedIps();
+ List<FixedIps> portIps = requireNonNullElse(routerPort.getFixedIps(), Collections.emptyList());
boolean vpnInstanceInternetIpVersionRemoved = false;
Uuid vpnInstanceInternetUuid = null;
for (FixedIps portIP : portIps) {
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersId, builder.build());
}
+ @Nullable
private String getPortHostId(final Port port) {
if (port != null) {
PortBindingExtension portBinding = port.augmentation(PortBindingExtension.class);
return null;
}
+ @Nullable
private Hostconfig getHostConfig(final Port port) {
String hostId = getPortHostId(port);
if (hostId == null) {
LOG.error("failed to read host config from host {}", hostId, e);
return null;
}
- return hostConfig.isPresent() ? hostConfig.get() : null;
+ return hostConfig.orNull();
}
private boolean isPortBound(final Port port) {
return false;
}
+ @Nullable
private Map<String, JsonElement> unmarshal(final String profile) {
if (null == profile) {
return null;
}
Gson gson = new Gson();
JsonObject jsonObject = gson.fromJson(profile, JsonObject.class);
- Map<String, JsonElement> map = new HashMap();
+ Map<String, JsonElement> map = new HashMap<>();
for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
map.put(entry.getKey(), entry.getValue());
}
private void handleNeutronPortCreated(final Port port) {
final String portName = port.getUuid().getValue();
final Uuid portId = port.getUuid();
- final List<FixedIps> portIpAddrsList = port.getFixedIps();
+ final List<FixedIps> portIpAddrsList = requireNonNullElse(port.getFixedIps(), Collections.emptyList());
if (NeutronConstants.IS_ODL_DHCP_PORT.test(port)) {
return;
}
private void handleNeutronPortDeleted(final Port port) {
final String portName = port.getUuid().getValue();
final Uuid portId = port.getUuid();
- final List<FixedIps> portIpsList = port.getFixedIps();
+ final List<FixedIps> portIpsList = requireNonNullElse(port.getFixedIps(), Collections.emptyList());
jobCoordinator.enqueueJob("PORT- " + portName,
() -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, confTx -> {
if (!(NeutronUtils.isPortVnicTypeNormal(port) || isPortTypeSwitchdev(port))) {
})));
}
+ @Nullable
private InterfaceAclBuilder handlePortSecurityUpdated(Port portOriginal,
Port portUpdated, boolean origSecurityEnabled, boolean updatedSecurityEnabled,
InterfaceBuilder interfaceBuilder) {
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
+import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
}
}
+ @Nullable
private Port getRouterExtGatewayPort(Router router) {
if (router == null) {
LOG.trace("Router is null");
return neutronvpnUtils.getNeutronPort(extPortId);
}
+ @Nullable
private String getExternalInterface(Router router) {
ExternalGatewayInfo extGatewayInfo = router.getExternalGatewayInfo();
String routerName = router.getUuid().getValue();
return elanService.getExternalElanInterface(extNetworkId.getValue(), primarySwitch);
}
+ @Nullable
private IpAddress getExternalGwIpAddress(Uuid subnetId) {
if (subnetId == null) {
LOG.error("Subnet id is null");
import static java.util.Collections.singletonList;
import static org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker.syncReadOptional;
import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils.requireNonNullElse;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
-import org.opendaylight.genius.infra.Datastore;
+import org.opendaylight.genius.infra.Datastore.Configuration;
import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
import org.opendaylight.genius.infra.TypedWriteTransaction;
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void createSubnetmapNode(Uuid subnetId, String subnetIp, Uuid tenantId, Uuid networkId,
- NetworkAttributes.NetworkType networkType, long segmentationId) {
+ @Nullable NetworkAttributes.NetworkType networkType, long segmentationId) {
try {
InstanceIdentifier<Subnetmap> subnetMapIdentifier = NeutronvpnUtils.buildSubnetMapIdentifier(subnetId);
synchronized (subnetId.getValue().intern()) {
}
}
- protected Subnetmap updateSubnetNode(Uuid subnetId, Uuid routerId, Uuid vpnId, Uuid internetvpnId) {
- Subnetmap subnetmap = null;
- SubnetmapBuilder builder = null;
+ @Nullable
+ protected Subnetmap updateSubnetNode(Uuid subnetId, @Nullable Uuid routerId, Uuid vpnId,
+ @Nullable Uuid internetvpnId) {
InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class)
.child(Subnetmap.class, new SubnetmapKey(subnetId))
.build();
Optional<Subnetmap> sn =
SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
id);
- if (sn.isPresent()) {
- builder = new SubnetmapBuilder(sn.get());
- LOG.debug("updating existing subnetmap node for subnet ID {}", subnetId.getValue());
- } else {
+ if (!sn.isPresent()) {
LOG.error("subnetmap node for subnet {} does not exist, returning", subnetId.getValue());
return null;
}
+ LOG.debug("updating existing subnetmap node for subnet ID {}", subnetId.getValue());
+ SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
if (routerId != null) {
builder.setRouterId(routerId);
}
}
builder.setInternetVpnId(internetvpnId);
- subnetmap = builder.build();
+ Subnetmap subnetmap = builder.build();
LOG.debug("Creating/Updating subnetMap node: {} ", subnetId.getValue());
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
+ return subnetmap;
}
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("Subnet map update failed for node {}", subnetId.getValue(), e);
+ return null;
}
- return subnetmap;
}
- protected void updateSubnetNodeWithFixedIp(Uuid subnetId, Uuid routerId,
- Uuid routerInterfacePortId, String fixedIp,
- String routerIntfMacAddress, Uuid vpnId) {
- Subnetmap subnetmap = null;
- SubnetmapBuilder builder = null;
+ protected void updateSubnetNodeWithFixedIp(Uuid subnetId, @Nullable Uuid routerId,
+ @Nullable Uuid routerInterfacePortId, @Nullable String fixedIp,
+ @Nullable String routerIntfMacAddress, @Nullable Uuid vpnId) {
InstanceIdentifier<Subnetmap> id =
InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
try {
Optional<Subnetmap> sn =
SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
id);
- if (sn.isPresent()) {
- builder = new SubnetmapBuilder(sn.get());
- LOG.debug("WithRouterFixedIP: Updating existing subnetmap node for subnet ID {}",
- subnetId.getValue());
- } else {
+ if (!sn.isPresent()) {
LOG.error("WithRouterFixedIP: subnetmap node for subnet {} does not exist, returning ",
subnetId.getValue());
return;
}
+ LOG.debug("WithRouterFixedIP: Updating existing subnetmap node for subnet ID {}",
+ subnetId.getValue());
+ SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
builder.setRouterId(routerId);
builder.setRouterInterfacePortId(routerInterfacePortId);
builder.setRouterIntfMacAddress(routerIntfMacAddress);
if (vpnId != null) {
builder.setVpnId(vpnId);
}
- subnetmap = builder.build();
+ Subnetmap subnetmap = builder.build();
LOG.debug("WithRouterFixedIP Creating/Updating subnetMap node for Router FixedIp: {} ",
subnetId.getValue());
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
}
}
- protected Subnetmap updateSubnetmapNodeWithPorts(Uuid subnetId, Uuid portId, Uuid directPortId) {
+ protected Subnetmap updateSubnetmapNodeWithPorts(Uuid subnetId, @Nullable Uuid portId,
+ @Nullable Uuid directPortId) {
Subnetmap subnetmap = null;
InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class,
new SubnetmapKey(subnetId)).build();
return subnetmap;
}
- protected Subnetmap removeFromSubnetNode(Uuid subnetId, Uuid networkId, Uuid routerId,
- Uuid vpnId, Uuid portId) {
+ protected Subnetmap removeFromSubnetNode(Uuid subnetId, @Nullable Uuid networkId, @Nullable Uuid routerId,
+ Uuid vpnId, @Nullable Uuid portId) {
Subnetmap subnetmap = null;
InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class)
.child(Subnetmap.class, new SubnetmapKey(subnetId))
return subnetmap;
}
- protected Subnetmap removePortsFromSubnetmapNode(Uuid subnetId, Uuid portId, Uuid directPortId) {
+ @Nullable
+ protected Subnetmap removePortsFromSubnetmapNode(Uuid subnetId, @Nullable Uuid portId,
+ @Nullable Uuid directPortId) {
Subnetmap subnetmap = null;
InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class,
new SubnetmapKey(subnetId)).build();
}
}
- protected void updateVpnMaps(Uuid vpnId, String name, Uuid router, Uuid tenantId, List<Uuid> networks) {
+ protected void updateVpnMaps(Uuid vpnId, @Nullable String name, @Nullable Uuid router, @Nullable Uuid tenantId,
+ @Nullable List<Uuid> networks) {
VpnMapBuilder builder;
boolean isLockAcquired = false;
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class)
}
}
- private void clearFromVpnMaps(Uuid vpnId, Uuid routerId, List<Uuid> networkIds) {
+ private void clearFromVpnMaps(Uuid vpnId, @Nullable Uuid routerId, @Nullable List<Uuid> networkIds) {
boolean isLockAcquired = false;
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class)
.child(VpnMap.class, new VpnMapKey(vpnId))
}
protected Adjacencies createPortIpAdjacencies(Port port, Boolean isRouterInterface,
- TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn,
- Subnetmap sn, VpnInterface vpnIface) {
+ TypedWriteTransaction<Configuration> wrtConfigTxn,
+ @Nullable Subnetmap sn, @Nullable VpnInterface vpnIface) {
List<Adjacency> adjList = new ArrayList<>();
if (vpnIface != null) {
adjList = vpnIface.augmentation(Adjacencies.class).getAdjacency();
}
String infName = port.getUuid().getValue();
LOG.trace("neutronVpnManager: create config adjacencies for Port: {}", infName);
- for (FixedIps ip : port.getFixedIps()) {
+ for (FixedIps ip : requireNonNullElse(port.getFixedIps(), Collections.<FixedIps>emptyList())) {
String ipValue = ip.getIpAddress().stringValue();
String ipPrefix = ip.getIpAddress().getIpv4Address() != null ? ipValue + "/32" : ipValue + "/128";
if (sn != null && !FibHelper.doesPrefixBelongToSubnet(ipPrefix, sn.getSubnetIp(), false)) {
}
protected void createVpnInterface(Collection<Uuid> vpnIds, Port port,
- TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn) {
+ @Nullable TypedWriteTransaction<Configuration> wrtConfigTxn) {
boolean isRouterInterface = false;
if (port.getDeviceOwner() != null) {
isRouterInterface = NeutronConstants.DEVICE_OWNER_ROUTER_INF.equals(port.getDeviceOwner());
}
protected void withdrawPortIpFromVpnIface(Uuid vpnId, Uuid internetVpnId,
- Port port, Subnetmap sn, TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn) {
+ Port port, Subnetmap sn, TypedWriteTransaction<Configuration> wrtConfigTxn) {
String infName = port.getUuid().getValue();
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
Optional<VpnInterface> optionalVpnInterface = null;
}
LOG.trace("withdraw adjacencies for Port: {} subnet {}", port.getUuid().getValue(),
sn != null ? sn.getSubnetIp() : "null");
- List<Adjacency> vpnAdjsList = optionalVpnInterface.get().augmentation(Adjacencies.class).getAdjacency();
+ List<Adjacency> vpnAdjsList =
+ requireNonNullElse(optionalVpnInterface.get().augmentation(Adjacencies.class).getAdjacency(),
+ Collections.emptyList());
List<Adjacency> updatedAdjsList = new ArrayList<>();
boolean isIpFromAnotherSubnet = false;
for (Adjacency adj : vpnAdjsList) {
String.valueOf(adjString), wrtConfigTxn);
}
} else {
- if (port.getDeviceOwner()
- .equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF) && sn.getRouterId() != null) {
+ if (NeutronConstants.DEVICE_OWNER_ROUTER_INF.equals(port.getDeviceOwner())
+ && sn.getRouterId() != null) {
Router rtr = neutronvpnUtils.getNeutronRouter(sn.getRouterId());
if (rtr != null && rtr.getRoutes() != null) {
List<Routes> extraRoutesToRemove = new ArrayList<>();
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void deleteVpnInterface(String infName, @Nullable String vpnId,
- TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn) {
+ @Nullable TypedWriteTransaction<Configuration> wrtConfigTxn) {
if (wrtConfigTxn == null) {
ListenableFutures.addErrorLogging(
txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
}
protected void removeInternetVpnFromVpnInterface(Uuid vpnId, Port port,
- TypedWriteTransaction<Datastore.Configuration> writeConfigTxn,
+ TypedWriteTransaction<Configuration> writeConfigTxn,
Subnetmap sm) {
if (vpnId == null || port == null) {
return;
mipToQuery, infName, vpnId.getValue());
}
}
- List<FixedIps> ips = port.getFixedIps();
- for (FixedIps ip : ips) {
+ for (FixedIps ip : requireNonNullElse(port.getFixedIps(), Collections.<FixedIps>emptyList())) {
String ipValue = ip.getIpAddress().stringValue();
//skip IPv4 address
if (!NeutronvpnUtils.getIpVersionFromString(ipValue).isIpVersionChosen(IpVersionChoice.IPV6)) {
}
}
- protected void updateVpnInterface(Uuid vpnId, Uuid oldVpnId, Port port, boolean isBeingAssociated,
+ protected void updateVpnInterface(Uuid vpnId, @Nullable Uuid oldVpnId, Port port, boolean isBeingAssociated,
boolean isSubnetIp,
- TypedWriteTransaction<Datastore.Configuration> writeConfigTxn) {
+ TypedWriteTransaction<Configuration> writeConfigTxn) {
if (vpnId == null || port == null) {
return;
}
Adjacencies adjacencies = new AdjacenciesBuilder().setAdjacency(adjacencyList).build();
vpnIfBuilder.addAugmentation(Adjacencies.class, adjacencies);
}
- List<FixedIps> ips = port.getFixedIps();
- for (FixedIps ip : ips) {
+ for (FixedIps ip : requireNonNullElse(port.getFixedIps(), Collections.<FixedIps>emptyList())) {
String ipValue = ip.getIpAddress().stringValue();
if (oldVpnId != null) {
neutronvpnUtils.removeVpnPortFixedIpToPort(oldVpnId.getValue(),
}
}
- public void createL3InternalVpn(Uuid vpn, String name, Uuid tenant, List<String> rd, List<String> irt,
- List<String> ert, Uuid router, List<Uuid> networks) {
+ public void createL3InternalVpn(Uuid vpn, @Nullable String name, @Nullable Uuid tenant, @Nullable List<String> rd,
+ @Nullable List<String> irt, @Nullable List<String> ert, @Nullable Uuid router,
+ @Nullable List<Uuid> networks) {
IpVersionChoice ipVersChoices = neutronvpnUtils.getIpVersionChoicesFromRouterUuid(router);
* @throws Exception if association of L3VPN failed
*/
public void createVpn(Uuid vpnId, String name, Uuid tenantId, List<String> rdList, List<String> irtList,
- List<String> ertList, @Nullable List<Uuid> routerIdsList, List<Uuid> networkList,
+ List<String> ertList, @Nullable List<Uuid> routerIdsList, @Nullable List<Uuid> networkList,
VpnInstance.Type type, long l3vni) throws Exception {
IpVersionChoice ipVersChoices = IpVersionChoice.UNDEFINED;
SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
vpnsIdentifier);
if (optionalVpns.isPresent() && !optionalVpns.get().getVpnInstance().isEmpty()) {
- for (VpnInstance vpn : optionalVpns.get().getVpnInstance()) {
+ for (VpnInstance vpn : requireNonNullElse(optionalVpns.get().getVpnInstance(),
+ Collections.<VpnInstance>emptyList())) {
// eliminating implicitly created (router and VLAN provider external network specific) VPNs
// from getL3VPN output
if (vpn.getIpv4Family().getRouteDistinguisher() != null) {
int failurecount = 0;
int warningcount = 0;
- List<Uuid> vpns = input.getId();
+ List<Uuid> vpns = requireNonNullElse(input.getId(), Collections.emptyList());
for (Uuid vpn : vpns) {
- RpcError error;
- String msg;
try {
LOG.debug("L3VPN delete RPC: VpnID {}", vpn.getValue());
InstanceIdentifier<VpnInstance> vpnIdentifier =
}
}
- protected void removeSubnetFromVpn(final Uuid vpnId, Uuid subnet, Uuid internetVpnId) {
+ protected void removeSubnetFromVpn(final Uuid vpnId, Uuid subnet, @Nullable Uuid internetVpnId) {
Preconditions.checkArgument(vpnId != null || internetVpnId != null,
"removeSubnetFromVpn: at least one VPN must be not null");
LOG.debug("Removing subnet {} from vpn {}/{}", subnet.getValue(),
}
}
+ @Nullable
private Subnetmap updateVpnForSubnet(Uuid oldVpnId, Uuid newVpnId, Uuid subnet, boolean isBeingAssociated) {
LOG.debug("Moving subnet {} from oldVpn {} to newVpn {} ", subnet.getValue(),
oldVpnId.getValue(), newVpnId.getValue());
List<String> fixedIPList = new ArrayList<>();
Port port = neutronvpnUtils.getNeutronPort(portId);
if (port != null) {
- List<FixedIps> fixedIPs = port.getFixedIps();
- for (FixedIps ip : fixedIPs) {
+ for (FixedIps ip : requireNonNullElse(port.getFixedIps(), Collections.<FixedIps>emptyList())) {
fixedIPList.add(ip.getIpAddress().stringValue());
}
} else {
return neutronvpnUtils.getNeutronSubnet(subnetId);
}
+ @Nullable
protected IpAddress getNeutronSubnetGateway(Uuid subnetId) {
Subnet sn = neutronvpnUtils.getNeutronSubnet(subnetId);
if (null != sn) {
Optional<Ports> ports = syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, portidentifier);
if (ports.isPresent() && ports.get().getPort() != null) {
- for (Port port : ports.get().getPort()) {
+ for (Port port : requireNonNullElse(ports.get().getPort(), Collections.<Port>emptyList())) {
List<FixedIps> fixedIPs = port.getFixedIps();
if (fixedIPs != null && !fixedIPs.isEmpty()) {
List<String> ipList = new ArrayList<>();
result.add("");
result.add("------------------------------------------------------------------------------------");
result.add("");
- List<L3vpnInstances> vpnList = rpcResult.getResult().getL3vpnInstances();
- for (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn
- .rev150602.VpnInstance vpn : vpnList) {
+ for (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.VpnInstance vpn :
+ requireNonNullElse(rpcResult.getResult().getL3vpnInstances(),
+ Collections.<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602
+ .VpnInstance>emptyList())) {
String tenantId = vpn.getTenantId() != null ? vpn.getTenantId().getValue()
: "\" " + " \"";
result.add(String.format(" %-37s %-37s %-7s ", vpn.getId().getValue(), tenantId,
}
private void createExternalVpnInterface(Uuid vpnId, String infName,
- TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn) {
+ TypedWriteTransaction<Configuration> wrtConfigTxn) {
writeVpnInterfaceToDs(Collections.singletonList(vpnId), infName, null, vpnId /* external network id */,
false /* not a router iface */, wrtConfigTxn);
}
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
- private void writeVpnInterfaceToDs(@Nonnull Collection<Uuid> vpnIdList, String infName, Adjacencies adjacencies,
- Uuid networkUuid, Boolean isRouterInterface, TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn) {
+ private void writeVpnInterfaceToDs(@Nonnull Collection<Uuid> vpnIdList, String infName,
+ @Nullable Adjacencies adjacencies, Uuid networkUuid, Boolean isRouterInterface,
+ TypedWriteTransaction<Configuration> wrtConfigTxn) {
if (vpnIdList.isEmpty() || infName == null) {
LOG.error("vpnid is empty or interface({}) is null", infName);
return;
}
private void updateVpnInterfaceWithAdjacencies(Uuid vpnId, String infName, Adjacencies adjacencies,
- TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn) {
+ TypedWriteTransaction<Configuration> wrtConfigTxn) {
if (vpnId == null || infName == null) {
LOG.error("vpn id or interface is null");
return;
*/
package org.opendaylight.netvirt.neutronvpn;
+import static org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils.requireNonNullElse;
+
import com.google.common.base.Optional;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Set;
+import javax.annotation.Nullable;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.inject.Singleton;
LOG.info("{} close", getClass().getSimpleName());
}
- public void handleExternalNetworkForRouter(Router original, Router update) {
+ public void handleExternalNetworkForRouter(@Nullable Router original, Router update) {
Uuid routerId = update.getUuid();
Uuid origExtNetId = null;
Uuid updExtNetId = null;
builder.setEnableSnat(update.getExternalGatewayInfo().isEnableSnat());
ArrayList<ExternalIps> externalIps = new ArrayList<>();
- for (ExternalFixedIps fixedIps : update.getExternalGatewayInfo().getExternalFixedIps()) {
+ for (ExternalFixedIps fixedIps : requireNonNullElse(update.getExternalGatewayInfo().getExternalFixedIps(),
+ Collections.<ExternalFixedIps>emptyList())) {
addExternalFixedIpToExternalIpsList(externalIps, fixedIps);
}
builder.setExternalIps(externalIps);
}
}
- public void updateOrAddExternalSubnet(Uuid networkId, Uuid subnetId, List<Uuid> routerIds) {
+ public void updateOrAddExternalSubnet(Uuid networkId, Uuid subnetId, @Nullable List<Uuid> routerIds) {
Optional<Subnets> optionalExternalSubnets = neutronvpnUtils.getOptionalExternalSubnets(subnetId);
if (optionalExternalSubnets.isPresent()) {
LOG.trace("Will update external subnet {} with networkId {} and routerIds {}",
}
}
- public void updateExternalSubnet(Uuid networkId, Uuid subnetId, List<Uuid> routerIds) {
+ public void updateExternalSubnet(Uuid networkId, Uuid subnetId, @Nullable List<Uuid> routerIds) {
InstanceIdentifier<Subnets> subnetsIdentifier = InstanceIdentifier.builder(ExternalSubnets.class)
.child(Subnets.class, new SubnetsKey(subnetId)).build();
try {
}
}
- private static Subnets createSubnets(Uuid subnetId, Uuid networkId, List<Uuid> routerIds) {
+ private static Subnets createSubnets(Uuid subnetId, Uuid networkId, @Nullable List<Uuid> routerIds) {
SubnetsBuilder subnetsBuilder = new SubnetsBuilder();
subnetsBuilder.withKey(new SubnetsKey(subnetId));
subnetsBuilder.setId(subnetId);
package org.opendaylight.netvirt.neutronvpn;
import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
+import static org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils.requireNonNullElse;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableBiMap;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.apache.commons.lang3.StringUtils;
this.ipV6InternetDefRt = ipV6InternetDefRt;
}
+ @Nullable
protected Subnetmap getSubnetmap(Uuid subnetId) {
InstanceIdentifier<Subnetmap> id = buildSubnetMapIdentifier(subnetId);
Optional<Subnetmap> sn = read(LogicalDatastoreType.CONFIGURATION, id);
return null;
}
+ @Nullable
public VpnMap getVpnMap(Uuid id) {
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class,
new VpnMapKey(id)).build();
return null;
}
+ @Nullable
protected Uuid getVpnForNetwork(Uuid network) {
InstanceIdentifier<VpnMaps> vpnMapsIdentifier = InstanceIdentifier.builder(VpnMaps.class).build();
Optional<VpnMaps> optionalVpnMaps = read(LogicalDatastoreType.CONFIGURATION, vpnMapsIdentifier);
if (optionalVpnMaps.isPresent() && optionalVpnMaps.get().getVpnMap() != null) {
- List<VpnMap> allMaps = optionalVpnMaps.get().getVpnMap();
- for (VpnMap vpnMap : allMaps) {
+ for (VpnMap vpnMap : requireNonNullElse(optionalVpnMaps.get().getVpnMap(),
+ Collections.<VpnMap>emptyList())) {
List<Uuid> netIds = vpnMap.getNetworkIds();
if (netIds != null && netIds.contains(network)) {
return vpnMap.getVpnId();
return null;
}
+ @Nullable
protected Uuid getVpnForSubnet(Uuid subnetId) {
InstanceIdentifier<Subnetmap> subnetmapIdentifier = buildSubnetMapIdentifier(subnetId);
Optional<Subnetmap> optionalSubnetMap = read(LogicalDatastoreType.CONFIGURATION,
return null;
}
+ @Nullable
protected Uuid getNetworkForSubnet(Uuid subnetId) {
InstanceIdentifier<Subnetmap> subnetmapIdentifier = buildSubnetMapIdentifier(subnetId);
Optional<Subnetmap> optionalSubnetMap = read(LogicalDatastoreType.CONFIGURATION,
}
// @param external vpn - true if external vpn being fetched, false for internal vpn
- protected Uuid getVpnForRouter(Uuid routerId, boolean externalVpn) {
+ @Nullable
+ protected Uuid getVpnForRouter(@Nullable Uuid routerId, boolean externalVpn) {
if (routerId == null) {
return null;
}
InstanceIdentifier<VpnMaps> vpnMapsIdentifier = InstanceIdentifier.builder(VpnMaps.class).build();
Optional<VpnMaps> optionalVpnMaps = read(LogicalDatastoreType.CONFIGURATION, vpnMapsIdentifier);
if (optionalVpnMaps.isPresent() && optionalVpnMaps.get().getVpnMap() != null) {
- List<VpnMap> allMaps = optionalVpnMaps.get().getVpnMap();
- for (VpnMap vpnMap : allMaps) {
+ for (VpnMap vpnMap : requireNonNullElse(optionalVpnMaps.get().getVpnMap(),
+ Collections.<VpnMap>emptyList())) {
List<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap
.RouterIds> routerIdsList = vpnMap.getRouterIds();
if (routerIdsList == null || routerIdsList.isEmpty()) {
continue;
}
- boolean isInternetBgpVpn = false;
- //Skip router vpnId fetching from internet BGP-VPN
+ // Skip router vpnId fetching from internet BGP-VPN
if (vpnMap.getNetworkIds() != null && !vpnMap.getNetworkIds().isEmpty()) {
- for (Uuid netId: vpnMap.getNetworkIds()) {
- Network network = getNeutronNetwork(netId);
- if (getIsExternal(network)) {
- isInternetBgpVpn = true;
- }
- /* If first network is not a external network then no need iterate
- * whole network list from the VPN
- */
- break;
+ // We only need to check the first network; if it’s not an external network there’s no
+ // need to check the rest of the VPN’s network list
+ if (getIsExternal(getNeutronNetwork(vpnMap.getNetworkIds().iterator().next()))) {
+ continue;
}
}
- if (isInternetBgpVpn) {
- //skip further processing
- continue;
- }
List<Uuid> rtrIdsList = routerIdsList.stream().map(routerIds -> routerIds.getRouterId())
.collect(Collectors.toList());
if (rtrIdsList.contains(routerId)) {
return null;
}
+ @Nullable
protected List<Uuid> getRouterIdListforVpn(Uuid vpnId) {
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class,
new VpnMapKey(vpnId)).build();
return null;
}
+ @Nullable
protected List<Uuid> getNetworksForVpn(Uuid vpnId) {
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class,
new VpnMapKey(vpnId)).build();
return subnets;
}
+ @Nullable
protected String getNeutronPortNameFromVpnPortFixedIp(String vpnName, String fixedIp) {
InstanceIdentifier<VpnPortipToPort> id = buildVpnPortipToPortIdentifier(vpnName, fixedIp);
Optional<VpnPortipToPort> vpnPortipToPortData = read(LogicalDatastoreType.CONFIGURATION, id);
return null;
}
+ @Nullable
protected List<Uuid> getSubnetIdsFromNetworkId(Uuid networkId) {
InstanceIdentifier<NetworkMap> id = buildNetworkMapIdentifier(networkId);
Optional<NetworkMap> optionalNetworkMap = read(LogicalDatastoreType.CONFIGURATION, id);
return null;
}
+ @Nullable
protected List<Uuid> getPortIdsFromSubnetId(Uuid subnetId) {
InstanceIdentifier<Subnetmap> id = buildSubnetMapIdentifier(subnetId);
Optional<Subnetmap> optionalSubnetmap = read(LogicalDatastoreType.CONFIGURATION, id);
* @param port2SecurityGroups the port 2 security groups
* @return the security groups delta
*/
- protected static List<Uuid> getSecurityGroupsDelta(List<Uuid> port1SecurityGroups,
- List<Uuid> port2SecurityGroups) {
+ @Nullable
+ protected static List<Uuid> getSecurityGroupsDelta(@Nullable List<Uuid> port1SecurityGroups,
+ @Nullable List<Uuid> port2SecurityGroups) {
if (port1SecurityGroups == null) {
return null;
}
* @param port2AllowedAddressPairs the port 2 allowed address pairs
* @return the allowed address pairs delta
*/
+ @Nullable
protected static List<AllowedAddressPairs> getAllowedAddressPairsDelta(
- List<org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes
+ @Nullable List<org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes
.AllowedAddressPairs> port1AllowedAddressPairs,
- List<org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes
+ @Nullable List<org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes
.AllowedAddressPairs> port2AllowedAddressPairs) {
if (port1AllowedAddressPairs == null) {
return null;
}
}
+ @Nullable
protected List<SubnetInfo> getSubnetInfo(Port port) {
List<FixedIps> portFixedIps = port.getFixedIps();
if (portFixedIps == null) {
// TODO Clean up the exception handling and the console output
@SuppressWarnings({"checkstyle:IllegalCatch", "checkstyle:RegexpSinglelineJava"})
+ @Nullable
protected Short getIPPrefixFromPort(Port port) {
try {
Uuid subnetUUID = port.getFixedIps().get(0).getSubnetId();
return providerExtension != null ? providerExtension.getNetworkType() : null;
}
+ @Nullable
static ProviderTypes getProviderNetworkType(Network network) {
if (network == null) {
LOG.error("Error in getting provider network type since network is null");
Optional<InterVpnLinks> interVpnLinksOpData = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION,
interVpnLinksIid);
if (interVpnLinksOpData.isPresent()) {
- List<InterVpnLink> allInterVpnLinks = interVpnLinksOpData.get().getInterVpnLink();
- for (InterVpnLink interVpnLink : allInterVpnLinks) {
+ for (InterVpnLink interVpnLink : requireNonNullElse(interVpnLinksOpData.get().getInterVpnLink(),
+ Collections.<InterVpnLink>emptyList())) {
if (interVpnLink.getFirstEndpoint().getIpAddress().getValue().equals(endpointIp)
|| interVpnLink.getSecondEndpoint().getIpAddress().getValue().equals(endpointIp)) {
return Optional.of(interVpnLink);
MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, routerDpnId);
if (neutronRouterDpnsOpt.isPresent()) {
NeutronRouterDpns neutronRouterDpns = neutronRouterDpnsOpt.get();
- List<RouterDpnList> routerDpnLists = neutronRouterDpns.getRouterDpnList();
- for (RouterDpnList routerDpnList : routerDpnLists) {
+ for (RouterDpnList routerDpnList : requireNonNullElse(neutronRouterDpns.getRouterDpnList(),
+ Collections.<RouterDpnList>emptyList())) {
if (routerDpnList.getDpnVpninterfacesList() != null) {
for (DpnVpninterfacesList dpnInterfaceList : routerDpnList.getDpnVpninterfacesList()) {
if (dpnInterfaceList.getDpnId().equals(dpid)) {
return ret;
}
+ @Nullable
protected Integer getUniqueRDId(String poolName, String idKey) {
AllocateIdInput getIdInput = new AllocateIdInputBuilder().setPoolName(poolName).setIdKey(idKey).build();
try {
*
* @return the route-distinguisher of the VPN
*/
+ @Nullable
public String getVpnRd(String vpnName) {
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn
.instance.to.vpn.id.VpnInstance> id = getVpnInstanceToVpnIdIdentifier(vpnName);
return IpVersionChoice.UNDEFINED;
}
+ @Nullable
public VpnInstanceOpDataEntry getVpnInstanceOpDataEntryFromVpnId(String vpnName) {
String primaryRd = getVpnRd(vpnName);
if (primaryRd == null) {
Optional<Subnetmaps> allSubnetMaps = read(LogicalDatastoreType.CONFIGURATION, subnetMapsId);
// calculate and store in list IpVersion for each subnetMap, belonging to current VpnInstance
List<IpVersionChoice> snIpVersions = new ArrayList<>();
- for (Subnetmap snMap: allSubnetMaps.get().getSubnetmap()) {
+ for (Subnetmap snMap : requireNonNullElse(allSubnetMaps.get().getSubnetmap(),
+ Collections.<Subnetmap>emptyList())) {
if (snMap.getId().equals(sm.getId())) {
continue;
}
* @param vpnId the Uuid of the VPN
* @return the VpnInstance or null if unfindable
*/
+ @Nullable
public VpnInstance getVpnInstance(DataBroker broker, Uuid vpnId) {
if (broker == null || vpnId == null) {
return null;
* @param subnetUuid Uuid of subnet where you are finding a link to an external network
* @return Uuid of externalVpn or null if it is not found
*/
+ @Nullable
public Uuid getInternetvpnUuidBoundToSubnetRouter(@Nonnull Uuid subnetUuid) {
Subnetmap subnetmap = getSubnetmap(subnetUuid);
Uuid routerUuid = subnetmap.getRouterId();
Uuid extNwVpnId = getVpnForNetwork(extNet.getUuid());
rtrList.addAll(getRouterIdListforVpn(extNwVpnId));
}
- if (rtrList == null || rtrList.isEmpty()) {
+ if (rtrList.isEmpty()) {
return subList;
}
for (Uuid rtrId: rtrList) {
LogicalDatastoreType.OPERATIONAL, id);
List<BigInteger> dpns = new ArrayList<>();
if (routerDpnListData.isPresent()) {
- List<DpnVpninterfacesList> dpnVpninterfacesList = routerDpnListData.get().getDpnVpninterfacesList();
- for (DpnVpninterfacesList dpnVpnInterface : dpnVpninterfacesList) {
+ for (DpnVpninterfacesList dpnVpnInterface : requireNonNullElse(
+ routerDpnListData.get().getDpnVpninterfacesList(), Collections.<DpnVpninterfacesList>emptyList())) {
dpns.add(dpnVpnInterface.getDpnId());
}
}
return dpns;
}
+ @Nullable
public List<Uuid> getRouterIdsfromVpnInstance(String vpnName) {
// returns only router, attached to IPv4 networks
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class)
return routerInstanceIdentifier;
}
+ @Nullable
List<Subnetmap> getSubnetmapListFromNetworkId(Uuid networkId) {
List<Uuid> subnetIdList = getSubnetIdsFromNetworkId(networkId);
if (subnetIdList != null) {
return null;
}
+ @Nullable
public long getVpnId(String vpnName) {
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn
.instance.to.vpn.id.VpnInstance> id = getVpnInstanceToVpnIdIdentifier(vpnName);
*/
package org.opendaylight.netvirt.neutronvpn.evpn.manager;
+import static org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils.requireNonNullElse;
+
import com.google.common.base.Optional;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
SettableFuture<RpcResult<CreateEVPNOutput>> result = SettableFuture.create();
List<RpcError> errorList = new ArrayList<>();
int failurecount = 0;
- int warningcount = 0;
List<String> existingRDs = neutronvpnUtils.getExistingRDs();
- List<Evpn> vpns = input.getEvpn();
- for (Evpn vpn : vpns) {
+ for (Evpn vpn : requireNonNullElse(input.getEvpn(), Collections.<Evpn>emptyList())) {
if (vpn.getRouteDistinguisher() == null || vpn.getImportRT() == null || vpn.getExportRT() == null) {
errorList.add(RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-input",
formatAndLog(LOG::warn, "Creation of EVPN failed for VPN {} due to absence of RD/iRT/eRT input",
vpn.getId().getValue())));
- warningcount++;
continue;
}
VpnInstance.Type vpnInstanceType = VpnInstance.Type.L2;
errorList.add(RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-input",
formatAndLog(LOG::warn, "Creation of EVPN failed for VPN {} due to multiple RD input {}",
vpn.getId().getValue(), vpn.getRouteDistinguisher())));
- warningcount++;
continue;
}
if (existingRDs.contains(vpn.getRouteDistinguisher().get(0))) {
"Creation of EVPN failed for VPN {} as another VPN with the same RD {} is already "
+ "configured",
vpn.getId().getValue(), vpn.getRouteDistinguisher().get(0))));
- warningcount++;
continue;
}
try {
.class, new VpnMapKey(vpnId)).build();
EvpnInstancesBuilder evpn = new EvpnInstancesBuilder();
List<String> rd = vpnInstance.getIpv4Family().getRouteDistinguisher();
- List<VpnTarget> vpnTargetList = vpnInstance.getIpv4Family().getVpnTargets().getVpnTarget();
List<String> ertList = new ArrayList<>();
List<String> irtList = new ArrayList<>();
- for (VpnTarget vpnTarget : vpnTargetList) {
+ for (VpnTarget vpnTarget : requireNonNullElse(vpnInstance.getIpv4Family().getVpnTargets().getVpnTarget(),
+ Collections.<VpnTarget>emptyList())) {
if (vpnTarget.getVrfRTType() == VpnTarget.VrfRTType.ExportExtcommunity) {
ertList.add(vpnTarget.getVrfRTValue());
}
}
public ListenableFuture<RpcResult<DeleteEVPNOutput>> deleteEVPN(DeleteEVPNInput input) {
- DeleteEVPNOutputBuilder opBuilder = new DeleteEVPNOutputBuilder();
- SettableFuture<RpcResult<DeleteEVPNOutput>> result = SettableFuture.create();
List<RpcError> errorList = new ArrayList<>();
- int failurecount = 0;
- int warningcount = 0;
- List<Uuid> vpns = input.getId();
- for (Uuid vpn : vpns) {
- RpcError error;
- String msg;
+ for (Uuid vpn : requireNonNullElse(input.getId(), Collections.<Uuid>emptyList())) {
VpnInstance vpnInstance = VpnHelper.getVpnInstance(dataBroker, vpn.getValue());
if (vpnInstance != null) {
neutronvpnManager.removeVpn(vpn);
} else {
errorList.add(RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-value",
formatAndLog(LOG::warn, "EVPN with vpnid: {} does not exist", vpn.getValue())));
- warningcount++;
}
}
- if (failurecount != 0) {
- result.set(RpcResultBuilder.<DeleteEVPNOutput>failed().withRpcErrors(errorList).build());
- } else {
- List<String> errorResponseList = new ArrayList<>();
- if (!errorList.isEmpty()) {
- for (RpcError rpcError : errorList) {
- errorResponseList.add("ErrorType: " + rpcError.getErrorType() + ", ErrorTag: " + rpcError.getTag()
- + ", ErrorMessage: " + rpcError.getMessage());
- }
- } else {
- errorResponseList.add("Deletion of EVPN operation successful");
+ List<String> errorResponseList = new ArrayList<>();
+ if (!errorList.isEmpty()) {
+ for (RpcError rpcError : errorList) {
+ errorResponseList.add("ErrorType: " + rpcError.getErrorType() + ", ErrorTag: " + rpcError.getTag()
+ + ", ErrorMessage: " + rpcError.getMessage());
}
- opBuilder.setResponse(errorResponseList);
- result.set(RpcResultBuilder.success(opBuilder.build()).build());
+ } else {
+ errorResponseList.add("Deletion of EVPN operation successful");
}
+ DeleteEVPNOutputBuilder opBuilder = new DeleteEVPNOutputBuilder();
+ opBuilder.setResponse(errorResponseList);
+ SettableFuture<RpcResult<DeleteEVPNOutput>> result = SettableFuture.create();
+ result.set(RpcResultBuilder.success(opBuilder.build()).build());
return result;
}
import com.google.common.base.Optional;
import java.util.Collections;
+import javax.annotation.Nullable;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
this.jobCoordinator = jobCoordinator;
}
+ @Nullable
public VpnInstance getVpnInstance(Uuid vpnId) {
return VpnHelper.getVpnInstance(dataBroker, vpnId.getValue());
}
package org.opendaylight.netvirt.neutronvpn.l2gw;
import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils.requireNonNullElse;
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.FutureCallback;
protected void add(final InstanceIdentifier<L2gateway> identifier, final L2gateway input) {
LOG.info("Adding L2gateway with ID: {}", input.getUuid());
- List<Devices> l2Devices = input.getDevices();
- for (Devices l2Device : l2Devices) {
+ for (Devices l2Device : requireNonNullElse(input.getDevices(), Collections.<Devices>emptyList())) {
LOG.trace("Adding L2gateway device: {}", l2Device);
addL2Device(l2Device, input);
}
}), new FutureCallback<Void>() {
@Override
public void onSuccess(Void result) {
- List<Devices> l2Devices = input.getDevices();
- for (Devices l2Device : l2Devices) {
+ for (Devices l2Device : requireNonNullElse(input.getDevices(), Collections.<Devices>emptyList())) {
LOG.trace("Removing L2gateway device: {}", l2Device);
removeL2Device(l2Device, input);
}
@Override
protected void add(InstanceIdentifier<TransportZone> key, TransportZone tzNew) {
LOG.trace("Received Transport Zone Add Event: {}", tzNew);
- if (tzNew.getTunnelType().equals(TunnelTypeVxlan.class)) {
+ if (TunnelTypeVxlan.class.equals(tzNew.getTunnelType())) {
AddL2GwDevicesToTransportZoneJob job =
new AddL2GwDevicesToTransportZoneJob(itmRpcService, tzNew, l2GatewayCache);
jobCoordinator.enqueueJob(job.getJobKey(), job);