import java.math.BigInteger;
import java.util.concurrent.ExecutionException;
+import javax.annotation.Nullable;
import org.opendaylight.genius.infra.Datastore.Configuration;
import org.opendaylight.genius.infra.TypedReadWriteTransaction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers;
void removeNatServiceListener(SnatServiceListener aclServiceListner);
- void notify(TypedReadWriteTransaction<Configuration> confTx,
- Routers router, Routers oldRouter, BigInteger primarySwitchId, BigInteger dpnId, Action action)
+ void notify(TypedReadWriteTransaction<Configuration> confTx, Routers router, @Nullable Routers oldRouter,
+ BigInteger primarySwitchId, @Nullable BigInteger dpnId, Action action)
throws ExecutionException, InterruptedException;
}
import com.google.common.base.Optional;
import java.io.PrintStream;
import java.math.BigInteger;
+import java.util.Collections;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.console.OsgiCommandSupport;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
}
@Override
- protected Object doExecute() throws Exception {
+ @Nullable
+ protected Object doExecute() {
PrintStream ps = session.getConsole();
Optional<NaptSwitches> npatSwitches = NatUtil.getAllPrimaryNaptSwitches(dataBroker);
ps.printf(String.format(" %-36s %-20s %-20s %n", "Router Id ", "Datapath Node Id", "Managment Ip Address"));
ps.printf("-------------------------------------------------------------------------------------------%n");
if (npatSwitches.isPresent()) {
- for (RouterToNaptSwitch routerToNaptSwitch : npatSwitches.get().getRouterToNaptSwitch()) {
+ for (RouterToNaptSwitch routerToNaptSwitch : NatUtil.requireNonNullElse(
+ npatSwitches.get().getRouterToNaptSwitch(), Collections.<RouterToNaptSwitch>emptyList())) {
ps.printf(String.format(" %-36s %-20s %-20s %n", routerToNaptSwitch.getRouterName(),
routerToNaptSwitch.getPrimarySwitchId(), getDpnLocalIp(routerToNaptSwitch.getPrimarySwitchId())));
}
LogicalDatastoreType.OPERATIONAL, nodeId);
}
+ @Nullable
private String getDpnLocalIp(BigInteger dpId) {
return getPortsNode(dpId).toJavaUtil().map(node -> getOpenvswitchOtherConfig(node, LOCAL_IP)).orElse(null);
}
+ @Nullable
private String getOpenvswitchOtherConfig(Node node, String key) {
OvsdbNodeAugmentation ovsdbNode = node.augmentation(OvsdbNodeAugmentation.class);
if (ovsdbNode == null) {
if (ovsdbNode != null && ovsdbNode.getOpenvswitchOtherConfigs() != null) {
for (OpenvswitchOtherConfigs openvswitchOtherConfigs : ovsdbNode.getOpenvswitchOtherConfigs()) {
- if (openvswitchOtherConfigs.getOtherConfigKey().equals(key)) {
+ if (key.equals(openvswitchOtherConfigs.getOtherConfigKey())) {
return openvswitchOtherConfigs.getOtherConfigValue();
}
}
}
- private OvsdbBridgeAugmentation extractBridgeAugmentation(Node node) {
+ @Nullable
+ private OvsdbBridgeAugmentation extractBridgeAugmentation(@Nullable Node node) {
if (node == null) {
return null;
}
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
+import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
new SubnetmapKey(subnetId)).build();
}
+ @Nullable
public BigInteger getCentralizedSwitch(String routerName) {
try {
Optional<RouterToNaptSwitch> naptSwitches = SingleTransactionDataBroker
return false;
}
- public static List<Uuid> getUpdatedSubnetIds(
- List<Uuid> updatedSubnetIds,
- List<Uuid> currentSubnetIds) {
+ @Nullable
+ public static List<Uuid> getUpdatedSubnetIds(List<Uuid> updatedSubnetIds, List<Uuid> currentSubnetIds) {
if (updatedSubnetIds == null) {
return null;
}
package org.opendaylight.netvirt.natservice.internal;
import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.netvirt.natservice.internal.NatUtil.requireNonNullElse;
import java.math.BigInteger;
import java.time.Duration;
import java.util.Objects;
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;
import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInterfacesBuilder;
import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface;
import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput;
addDefaultFibRouteForSNAT(confTx, dpnId, routerId);
int elanId = NatUtil.getElanInstanceByName(routers.getNetworkId().getValue(), getDataBroker())
.getElanTag().intValue();
- for (ExternalIps externalIp : routers.getExternalIps()) {
+ for (ExternalIps externalIp : requireNonNullElse(routers.getExternalIps(),
+ Collections.<ExternalIps>emptyList())) {
if (!NWUtil.isIpv4Address(externalIp.getIpAddress())) {
// In this class we handle only IPv4 use-cases.
continue;
String routerName = routers.getRouterName();
Long routerId = NatUtil.getVpnId(dataBroker, routerName);
removeDefaultFibRouteForSNAT(confTx, dpnId, routerId);
- for (ExternalIps externalIp : routers.getExternalIps()) {
+ for (ExternalIps externalIp : requireNonNullElse(routers.getExternalIps(),
+ Collections.<ExternalIps>emptyList())) {
if (!NWUtil.isIpv4Address(externalIp.getIpAddress())) {
// In this class we handle only IPv4 use-cases.
continue;
String routerName = routers.getRouterName();
Long routerId = NatUtil.getVpnId(dataBroker, routerName);
String externalGwMac = routers.getExtGwMacAddress();
- for (ExternalIps externalIp : routers.getExternalIps()) {
+ for (ExternalIps externalIp : requireNonNullElse(routers.getExternalIps(),
+ Collections.<ExternalIps>emptyList())) {
if (!NWUtil.isIpv4Address(externalIp.getIpAddress())) {
// In this class we handle only IPv4 use-cases.
continue;
Routers routers, BigInteger dpnId) throws ExecutionException, InterruptedException {
String routerName = routers.getRouterName();
Long routerId = NatUtil.getVpnId(confTx, routerName);
- for (ExternalIps externalIp : routers.getExternalIps()) {
+ for (ExternalIps externalIp : requireNonNullElse(routers.getExternalIps(),
+ Collections.<ExternalIps>emptyList())) {
if (!NWUtil.isIpv4Address(externalIp.getIpAddress())) {
// In this class we handle only IPv4 use-cases.
continue;
String nextHopIp = NatUtil.getEndpointIpAddressForDPN(dataBroker, dpnId);
String ipPrefix = externalIp + "/32";
NatUtil.addPrefixToInterface(dataBroker, NatUtil.getVpnId(dataBroker, subNetId),
- null, ipPrefix, externalNetId, new Uuid(subNetId), dpnId, Prefixes.PrefixCue.Nat);
+ null, ipPrefix, externalNetId, dpnId, Prefixes.PrefixCue.Nat);
fibManager.addOrUpdateFibEntry(rd, routerMac, ipPrefix,
Collections.singletonList(nextHopIp), VrfEntry.EncapType.Mplsgre, extSubnetId,
return "snatmiss." + routerName;
}
+ @Nullable
protected String getTunnelInterfaceName(BigInteger srcDpId, BigInteger dstDpId) {
Class<? extends TunnelTypeBase> tunType = TunnelTypeVxlan.class;
RpcResult<GetTunnelInterfaceNameOutput> rpcResult;
protected void removeMipAdjacencies(Routers routers) {
LOG.info("removeMipAdjacencies for router {}", routers.getRouterName());
String externalSubNetId = null;
- for (ExternalIps externalIp : routers.getExternalIps()) {
+ for (ExternalIps externalIp : requireNonNullElse(routers.getExternalIps(),
+ Collections.<ExternalIps>emptyList())) {
if (!NWUtil.isIpv4Address(externalIp.getIpAddress())) {
// In this class we handle only IPv4 use-cases.
continue;
VpnInterfaces vpnInterfaces = SingleTransactionDataBroker.syncRead(dataBroker,
LogicalDatastoreType.CONFIGURATION, vpnInterfacesId);
List<VpnInterface> updatedVpnInterface = new ArrayList<>();
- for (VpnInterface vpnInterface : vpnInterfaces.getVpnInterface()) {
+ for (VpnInterface vpnInterface : requireNonNullElse(vpnInterfaces.getVpnInterface(),
+ Collections.<VpnInterface>emptyList())) {
List<Adjacency> updatedAdjacencies = new ArrayList<>();
Adjacencies adjacencies = vpnInterface.augmentation(Adjacencies.class);
if (null != adjacencies) {
- for (Adjacency adjacency : adjacencies.getAdjacency()) {
+ for (Adjacency adjacency : requireNonNullElse(adjacencies.getAdjacency(),
+ Collections.<Adjacency>emptyList())) {
if (!adjacency.getSubnetId().getValue().equals(externalSubNetId)) {
updatedAdjacencies.add(adjacency);
}
}
LearntVpnVipToPortDataBuilder learntVpnVipToPortDataBuilder = new LearntVpnVipToPortDataBuilder();
List<LearntVpnVipToPort> learntVpnVipToPortList = new ArrayList<>();
- for (LearntVpnVipToPort learntVpnVipToPort : learntVpnVipToPortData.getLearntVpnVipToPort()) {
- if (!learntVpnVipToPort.getVpnName().equals(networkId)) {
+ for (LearntVpnVipToPort learntVpnVipToPort : requireNonNullElse(learntVpnVipToPortData.getLearntVpnVipToPort(),
+ Collections.<LearntVpnVipToPort>emptyList())) {
+ if (!networkId.equals(learntVpnVipToPort.getVpnName())) {
LOG.info("The learned port belongs to Vpn {} hence not removing", learntVpnVipToPort.getVpnName());
learntVpnVipToPortList.add(learntVpnVipToPort);
} else {
String externalSubNetId = null;
- for (ExternalIps externalIp : routers.getExternalIps()) {
+ for (ExternalIps externalIp : requireNonNullElse(routers.getExternalIps(),
+ Collections.<ExternalIps>emptyList())) {
if (!NWUtil.isIpv4Address(externalIp.getIpAddress())) {
// In this class we handle only IPv4 use-cases.
continue;
*/
package org.opendaylight.netvirt.natservice.internal;
+import static org.opendaylight.netvirt.natservice.internal.NatUtil.requireNonNullElse;
+
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.concurrent.ExecutionException;
import org.apache.commons.lang3.tuple.ImmutablePair;
String extGwMacAddress = NatUtil.getExtGwMacAddFromRouterName(confTx, routerName);
addOutboundTblTrackEntry(confTx, dpnId, routerId, extGwMacAddress);
- for (ExternalIps externalIp : routers.getExternalIps()) {
+ for (ExternalIps externalIp : requireNonNullElse(routers.getExternalIps(),
+ Collections.<ExternalIps>emptyList())) {
if (!NWUtil.isIpv4Address(externalIp.getIpAddress())) {
// In this class we handle only IPv4 use-cases.
continue;
removeSnatMissEntryForPrimrySwch(confTx, dpnId, routerId);
removeOutboundTblTrackEntry(confTx, dpnId, routerId);
- for (ExternalIps externalIp : routers.getExternalIps()) {
+ for (ExternalIps externalIp : requireNonNullElse(routers.getExternalIps(),
+ Collections.<ExternalIps>emptyList())) {
if (!NWUtil.isIpv4Address(externalIp.getIpAddress())) {
// In this class we handle only IPv4 use-cases.
continue;
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.natservice.internal.NatUtil.requireNonNullElse;
import com.google.common.base.Optional;
import com.google.common.util.concurrent.FutureCallback;
LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
if (optionalVpnInterface.isPresent()) {
ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> {
- for (VpnInstanceNames vpnInstance : optionalVpnInterface.get().getVpnInstanceNames()) {
+ for (VpnInstanceNames vpnInstance : requireNonNullElse(optionalVpnInterface.get().getVpnInstanceNames(),
+ Collections.<VpnInstanceNames>emptyList())) {
if (!vpnName.equals(vpnInstance.getVpnName())) {
continue;
}
VpnInterfaceOpDataEntryBuilder vpnIfOpDataEntryBuilder = new VpnInterfaceOpDataEntryBuilder();
vpnIfOpDataEntryBuilder.withKey(new VpnInterfaceOpDataEntryKey(interfaceName, vpnName));
- List<Adjacency> adjacencyList = adjs != null ? adjs.getAdjacency() : new ArrayList<>();
+ List<Adjacency> adjacencyList =
+ adjs != null && adjs.getAdjacency() != null ? adjs.getAdjacency() : new ArrayList<>();
List<Adjacency> adjacencyListToImport = new ArrayList<>();
for (Adjacency adj : adjacencyList) {
Subnetmap sn = VpnHelper.getSubnetmapFromItsUuid(dataBroker, adj.getSubnetId());
LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
if (optionalVpnInterface.isPresent()) {
ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> {
- for (VpnInstanceNames vpnInstance : optionalVpnInterface.get().getVpnInstanceNames()) {
+ for (VpnInstanceNames vpnInstance : requireNonNullElse(optionalVpnInterface.get().getVpnInstanceNames(),
+ Collections.<VpnInstanceNames>emptyList())) {
if (!vpnName.equals(vpnInstance.getVpnName())) {
continue;
}
import java.util.Collection;
import java.util.Collections;
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;
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + subnetName + extInterface, () -> {
GroupEntity groupEntity = buildExtNetGroupEntity(macAddress, subnetName, groupId, extInterface, dpnId);
- if (groupEntity != null) {
- mdsalManager.syncInstallGroup(groupEntity);
- }
+ mdsalManager.syncInstallGroup(groupEntity);
return Collections.emptyList();
});
}
return MDSALUtil.buildGroupEntity(dpnId, groupId, subnetName, GroupTypes.GroupAll, listBucketInfo);
}
+ @Nullable
private GroupEntity buildEmptyExtNetGroupEntity(String subnetName, long groupId, String extInterface) {
BigInteger dpId = NatUtil.getDpnForInterface(odlInterfaceRpcService, extInterface);
if (BigInteger.ZERO.equals(dpId)) {
package org.opendaylight.netvirt.natservice.internal;
import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.netvirt.natservice.internal.NatUtil.requireNonNullElse;
import com.google.common.base.Optional;
import java.math.BigInteger;
@Override
protected void remove(InstanceIdentifier<Networks> identifier, Networks networks) {
- if (identifier == null || networks == null || networks.getRouterIds().isEmpty()) {
+ if (identifier == null || networks == null || networks.getRouterIds() == null
+ || networks.getRouterIds().isEmpty()) {
LOG.warn("remove : returning without processing since networks/identifier is null: "
+ "identifier: {}, networks: {}", identifier, networks);
return;
}
private void removeSnatEntries(Networks original, Uuid networkUuid) {
- List<Uuid> routerUuids = original.getRouterIds();
- for (Uuid routerUuid : routerUuids) {
- Long routerId = NatUtil.getVpnId(dataBroker, routerUuid.getValue());
+ for (Uuid routerUuid : requireNonNullElse(original.getRouterIds(), Collections.<Uuid>emptyList())) {
+ long routerId = NatUtil.getVpnId(dataBroker, routerUuid.getValue());
if (routerId == NatConstants.INVALID_ID) {
LOG.error("removeSnatEntries : Invalid routerId returned for routerName {}", routerUuid.getValue());
return;
if (natMode == NatMode.Controller) {
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + routerUuid.getValue(),
() -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
- tx -> {
- externalRouterListener.handleDisableSnatInternetVpn(routerUuid.getValue(), routerId,
- networkUuid, externalIps, original.getVpnid().getValue(), tx);
- })), NatConstants.NAT_DJC_MAX_RETRIES);
+ tx -> externalRouterListener.handleDisableSnatInternetVpn(routerUuid.getValue(), routerId,
+ networkUuid, externalIps, original.getVpnid().getValue(), tx))),
+ NatConstants.NAT_DJC_MAX_RETRIES);
}
}
}
private void associateExternalNetworkWithVPN(Networks network) {
- List<Uuid> routerIds = network.getRouterIds();
+ List<Uuid> routerIds = requireNonNullElse(network.getRouterIds(), Collections.emptyList());
for (Uuid routerId : routerIds) {
//long router = NatUtil.getVpnId(dataBroker, routerId.getValue());
continue;
}
RouterPorts routerPorts = optRouterPorts.get();
- List<Ports> interfaces = routerPorts.getPorts();
- for (Ports port : interfaces) {
+ for (Ports port : requireNonNullElse(routerPorts.getPorts(), Collections.<Ports>emptyList())) {
String portName = port.getPortName();
BigInteger dpnId = NatUtil.getDpnForInterface(interfaceManager, portName);
if (dpnId.equals(BigInteger.ZERO)) {
+ "skip handling of ext nw {} association", portName, network.getId());
continue;
}
- List<InternalToExternalPortMap> intExtPortMapList = port.getInternalToExternalPortMap();
- for (InternalToExternalPortMap ipMap : intExtPortMapList) {
+ for (InternalToExternalPortMap ipMap : requireNonNullElse(port.getInternalToExternalPortMap(),
+ Collections.<InternalToExternalPortMap>emptyList())) {
// remove all VPN related entries
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + ipMap.key(),
() -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
- tx -> {
- floatingIpListener.createNATFlowEntries(dpnId, portName, routerId.getValue(),
- network.getId(), ipMap, tx);
- })), NatConstants.NAT_DJC_MAX_RETRIES);
+ tx -> floatingIpListener.createNATFlowEntries(dpnId, portName, routerId.getValue(),
+ network.getId(), ipMap, tx))), NatConstants.NAT_DJC_MAX_RETRIES);
}
}
}
.intext.ip.map.IpMapping> ipMapping = MDSALUtil.read(dataBroker,
LogicalDatastoreType.OPERATIONAL, id);
if (ipMapping.isPresent()) {
- List<IpMap> ipMaps = ipMapping.get().getIpMap();
- for (IpMap ipMap : ipMaps) {
+ for (IpMap ipMap : requireNonNullElse(ipMapping.get().getIpMap(),
+ Collections.<IpMap>emptyList())) {
String externalIp = ipMap.getExternalIp();
LOG.debug("associateExternalNetworkWithVPN : Calling advToBgpAndInstallFibAndTsFlows "
+ "for dpnId {},vpnName {} and externalIp {}", finalDpnId, vpnName, externalIp);
}
private void disassociateExternalNetworkFromVPN(Networks network, String vpnName) {
- List<Uuid> routerIds = network.getRouterIds();
-
- for (Uuid routerId : routerIds) {
+ for (Uuid routerId : requireNonNullElse(network.getRouterIds(), Collections.<Uuid>emptyList())) {
InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerId.getValue());
Optional<RouterPorts> optRouterPorts = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION,
routerPortsId);
continue;
}
RouterPorts routerPorts = optRouterPorts.get();
- List<Ports> interfaces = routerPorts.getPorts();
- for (Ports port : interfaces) {
+ for (Ports port : requireNonNullElse(routerPorts.getPorts(), Collections.<Ports>emptyList())) {
String portName = port.getPortName();
BigInteger dpnId = NatUtil.getDpnForInterface(interfaceManager, portName);
if (dpnId.equals(BigInteger.ZERO)) {
+ "skip handling of ext nw {} disassociation", portName, network.getId());
continue;
}
- List<InternalToExternalPortMap> intExtPortMapList = port.getInternalToExternalPortMap();
- for (InternalToExternalPortMap intExtPortMap : intExtPortMapList) {
+ for (InternalToExternalPortMap intExtPortMap : requireNonNullElse(port.getInternalToExternalPortMap(),
+ Collections.<InternalToExternalPortMap>emptyList())) {
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + intExtPortMap.key(),
() -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
- tx -> {
- floatingIpListener.removeNATFlowEntries(dpnId, portName, vpnName, routerId.getValue(),
- intExtPortMap, tx);
- })), NatConstants.NAT_DJC_MAX_RETRIES);
+ tx -> floatingIpListener.removeNATFlowEntries(dpnId, portName, vpnName, routerId.getValue(),
+ intExtPortMap, tx))), NatConstants.NAT_DJC_MAX_RETRIES);
}
}
}
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.netvirt.natservice.internal.NatUtil.requireNonNullElse;
import com.google.common.base.Optional;
import com.google.common.util.concurrent.FutureCallback;
protected void subnetRegisterMapping(Routers routerEntry, Long segmentId) {
LOG.debug("subnetRegisterMapping : Fetching values from extRouters model");
- List<Uuid> subnetList = routerEntry.getSubnetIds();
List<String> externalIps = NatUtil.getIpsListFromExternalIps(routerEntry.getExternalIps());
int counter = 0;
int extIpCounter = externalIps.size();
LOG.debug("subnetRegisterMapping : counter values before looping counter {} and extIpCounter {}",
counter, extIpCounter);
- for (Uuid subnet : subnetList) {
+ for (Uuid subnet : requireNonNullElse(routerEntry.getSubnetIds(), Collections.<Uuid>emptyList())) {
LOG.debug("subnetRegisterMapping : Looping internal subnets for subnet {}", subnet);
InstanceIdentifier<Subnetmap> subnetmapId = InstanceIdentifier
.builder(Subnetmaps.class)
mdsalManager.addFlow(confTx, icmpDropFlow);
}
+ @Nullable
protected String getTunnelInterfaceName(BigInteger srcDpId, BigInteger dstDpId) {
Class<? extends TunnelTypeBase> tunType = TunnelTypeVxlan.class;
RpcResult<GetTunnelInterfaceNameOutput> rpcResult;
if (networkId != null) {
Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
if (vpnUuid != null) {
- Long vpnId = NatUtil.getVpnId(dataBroker, vpnUuid.getValue());
+ long vpnId = NatUtil.getVpnId(dataBroker, vpnUuid.getValue());
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + networkId, () -> {
installNaptPfibEntriesForExternalSubnets(routerName, dpnId, null);
//Install the NAPT PFIB TABLE which forwards outgoing packet to FIB Table matching on the VPN ID.
- if (vpnId != null && vpnId != NatConstants.INVALID_ID) {
+ if (vpnId != NatConstants.INVALID_ID) {
installNaptPfibEntry(dpnId, vpnId, null);
}
return Collections.emptyList();
return listBucketInfo;
}
- public void installNaptPfibEntry(BigInteger dpnId, long segmentId, TypedWriteTransaction<Configuration> confTx) {
+ public void installNaptPfibEntry(BigInteger dpnId, long segmentId,
+ @Nullable TypedWriteTransaction<Configuration> confTx) {
LOG.debug("installNaptPfibEntry : called for dpnId {} and segmentId {} ", dpnId, segmentId);
FlowEntity naptPfibFlowEntity = buildNaptPfibFlowEntity(dpnId, segmentId);
if (confTx != null) {
public void advToBgpAndInstallFibAndTsFlows(final BigInteger dpnId, final short tableId, final String vpnName,
final long routerId, final String routerName, final String externalIp,
- final Uuid extNetworkId, final Routers router,
+ final Uuid extNetworkId, @Nullable final Routers router,
final TypedWriteTransaction<Configuration> confTx) {
LOG.debug("advToBgpAndInstallFibAndTsFlows : entry for DPN ID {}, tableId {}, vpnname {} "
+ "and externalIp {}", dpnId, tableId, vpnName, externalIp);
int externalIpInDsFlag = 0;
//Get IPMaps from the DB for the router ID
List<IpMap> dbIpMaps = NaptManager.getIpMapList(dataBroker, routerId);
- if (dbIpMaps != null) {
- for (IpMap dbIpMap : dbIpMaps) {
- String dbExternalIp = dbIpMap.getExternalIp();
- //Select the IPMap, whose external IP is the IP for which FIB is installed
- if (dbExternalIp.contains(externalIp)) {
- String dbInternalIp = dbIpMap.getInternalIp();
- IpMapKey dbIpMapKey = dbIpMap.key();
- LOG.debug("advToBgpAndInstallFibAndTsFlows : Setting label {} for internalIp {} "
- + "and externalIp {}", label, dbInternalIp, externalIp);
- IpMap newIpm = new IpMapBuilder().withKey(dbIpMapKey).setInternalIp(dbInternalIp)
- .setExternalIp(dbExternalIp).setLabel(label).build();
- MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL,
- naptManager.getIpMapIdentifier(routerId, dbInternalIp), newIpm);
- externalIpInDsFlag++;
- }
- }
- if (externalIpInDsFlag <= 0) {
- LOG.debug("advToBgpAndInstallFibAndTsFlows : External Ip {} not found in DS, "
- + "Failed to update label {} for routerId {} in DS",
- externalIp, label, routerId);
- String errMsg = String.format("Failed to update label %s due to external Ip %s not"
- + " found in DS for router %s", label, externalIp, routerId);
- return Futures.immediateFailedFuture(new Exception(errMsg));
+ for (IpMap dbIpMap : dbIpMaps) {
+ String dbExternalIp = dbIpMap.getExternalIp();
+ //Select the IPMap, whose external IP is the IP for which FIB is installed
+ if (dbExternalIp.contains(externalIp)) {
+ String dbInternalIp = dbIpMap.getInternalIp();
+ IpMapKey dbIpMapKey = dbIpMap.key();
+ LOG.debug("advToBgpAndInstallFibAndTsFlows : Setting label {} for internalIp {} "
+ + "and externalIp {}", label, dbInternalIp, externalIp);
+ IpMap newIpm = new IpMapBuilder().withKey(dbIpMapKey).setInternalIp(dbInternalIp)
+ .setExternalIp(dbExternalIp).setLabel(label).build();
+ MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL,
+ naptManager.getIpMapIdentifier(routerId, dbInternalIp), newIpm);
+ externalIpInDsFlag++;
}
- } else {
- LOG.error("advToBgpAndInstallFibAndTsFlows : Failed to write label {} for externalIp {} for"
- + " routerId {} in DS", label, externalIp, routerId);
+ }
+ if (externalIpInDsFlag <= 0) {
+ LOG.debug("advToBgpAndInstallFibAndTsFlows : External Ip {} not found in DS, "
+ + "Failed to update label {} for routerId {} in DS",
+ externalIp, label, routerId);
+ String errMsg = String.format("Failed to update label %s due to external Ip %s not"
+ + " found in DS for router %s", label, externalIp, routerId);
+ return Futures.immediateFailedFuture(new Exception(errMsg));
}
//Inform BGP
long l3vni = 0;
}
Routers extRouter = router != null ? router :
NatUtil.getRoutersFromConfigDS(dataBroker, routerName);
- Uuid externalSubnetId = NatUtil.getExternalSubnetForRouterExternalIp(externalIp,
- extRouter);
- NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, vpnName, rd, externalSubnetId,
+ NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, vpnName, rd,
externalIp, nextHopIp, extRouter.getNetworkId().getValue(), null, label, l3vni,
RouteOrigin.STATIC, dpnId);
NatUtil.makePreDnatToSnatTableEntry(mdsalManager, dpnId, NwConstants.INBOUND_NAPT_TABLE, confTx);
}
String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
- Optional<Subnets> externalSubnet = NatUtil.getOptionalExternalSubnets(dataBroker,
- externalSubnetId);
- String externalVpn = vpnName;
- if (externalSubnet.isPresent()) {
- externalVpn = externalSubnetId.getValue();
- }
+ Uuid externalSubnetId = NatUtil.getExternalSubnetForRouterExternalIp(externalIp, extRouter);
+ Optional<Subnets> externalSubnet = NatUtil.getOptionalExternalSubnets(dataBroker, externalSubnetId);
+ String externalVpn = externalSubnet.isPresent() ? externalSubnetId.getValue() : vpnName;
CreateFibEntryInput input = new CreateFibEntryInputBuilder()
.setVpnName(externalVpn)
.setSourceDpid(dpnId).setIpAddress(fibExternalIp).setServiceId(label)
Optional<IpPortMapping> ipPortMapping =
MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, ipPortMappingId);
if (ipPortMapping.isPresent()) {
- List<IntextIpProtocolType> intextIpProtocolTypes = ipPortMapping.get()
- .getIntextIpProtocolType();
- for (IntextIpProtocolType intextIpProtocolType : intextIpProtocolTypes) {
+ for (IntextIpProtocolType intextIpProtocolType : requireNonNullElse(
+ ipPortMapping.get().getIntextIpProtocolType(),
+ Collections.<IntextIpProtocolType>emptyList())) {
ProtocolTypes protoType = intextIpProtocolType.getProtocol();
- List<IpPortMap> ipPortMaps = intextIpProtocolType.getIpPortMap();
- for (IpPortMap ipPortMap : ipPortMaps) {
+ for (IpPortMap ipPortMap : requireNonNullElse(intextIpProtocolType.getIpPortMap(),
+ Collections.<IpPortMap>emptyList())) {
IpPortExternal ipPortExternal = ipPortMap.getIpPortExternal();
if (ipPortExternal.getIpAddress().equals(externalIp)) {
externalPorts.add(ipPortExternal.getPortNum());
LOG.debug("update : Checking if this is update on subnets");
List<Uuid> originalSubnetIds = original.getSubnetIds();
List<Uuid> updatedSubnetIds = update.getSubnetIds();
- Set<Uuid> addedSubnetIds = new HashSet<>(updatedSubnetIds);
- addedSubnetIds.removeAll(originalSubnetIds);
+ Set<Uuid> addedSubnetIds =
+ updatedSubnetIds != null ? new HashSet<>(updatedSubnetIds) : new HashSet<>();
+ if (originalSubnetIds != null) {
+ addedSubnetIds.removeAll(originalSubnetIds);
+ }
//Check if the Subnet IDs are added during the update.
if (addedSubnetIds.size() != 0) {
MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (externalCountersData.isPresent()) {
ExternalIpsCounter externalIpsCounters = externalCountersData.get();
- List<ExternalCounters> externalCounters = externalIpsCounters.getExternalCounters();
- for (ExternalCounters ext : externalCounters) {
- for (ExternalIpCounter externalIpCount : ext.getExternalIpCounter()) {
+ for (ExternalCounters ext : requireNonNullElse(externalIpsCounters.getExternalCounters(),
+ Collections.<ExternalCounters>emptyList())) {
+ for (ExternalIpCounter externalIpCount : requireNonNullElse(ext.getExternalIpCounter(),
+ Collections.<ExternalIpCounter>emptyList())) {
if (externalIpCount.getExternalIp().equals(externalIp)) {
if (externalIpCount.getCounter() != 0) {
return true;
}
}
+ @Nullable
protected Long checkExternalIpLabel(long routerId, String externalIp) {
List<IpMap> ipMaps = naptManager.getIpMapList(dataBroker, routerId);
for (IpMap ipMap : ipMaps) {
}
public void handleDisableSnat(Routers router, Uuid networkUuid, @Nonnull Collection<String> externalIps,
- boolean routerFlag, String vpnName, BigInteger naptSwitchDpnId,
+ boolean routerFlag, @Nullable String vpnName, BigInteger naptSwitchDpnId,
long routerId, TypedReadWriteTransaction<Configuration> removeFlowInvTx) {
LOG.info("handleDisableSnat : Entry");
String routerName = router.getRouterName();
return;
}
- List<IntextIpProtocolType> intextIpProtocolTypes = ipPortMapping.getIntextIpProtocolType();
- for (IntextIpProtocolType intextIpProtocolType : intextIpProtocolTypes) {
- List<IpPortMap> ipPortMaps = intextIpProtocolType.getIpPortMap();
- for (IpPortMap ipPortMap : ipPortMaps) {
+ for (IntextIpProtocolType intextIpProtocolType : requireNonNullElse(ipPortMapping.getIntextIpProtocolType(),
+ Collections.<IntextIpProtocolType>emptyList())) {
+ for (IpPortMap ipPortMap : requireNonNullElse(intextIpProtocolType.getIpPortMap(),
+ Collections.<IpPortMap>emptyList())) {
String ipPortInternal = ipPortMap.getIpPortInternal();
String[] ipPortParts = ipPortInternal.split(":");
if (ipPortParts.length != 2) {
LOG.error("removeNaptFlowsFromActiveSwitchInternetVpn : Unable to retrieve the IpPortMapping");
return;
}
- List<IntextIpProtocolType> intextIpProtocolTypes = ipPortMapping.getIntextIpProtocolType();
- for (IntextIpProtocolType intextIpProtocolType : intextIpProtocolTypes) {
- List<IpPortMap> ipPortMaps = intextIpProtocolType.getIpPortMap();
- for (IpPortMap ipPortMap : ipPortMaps) {
+ for (IntextIpProtocolType intextIpProtocolType : requireNonNullElse(ipPortMapping.getIntextIpProtocolType(),
+ Collections.<IntextIpProtocolType>emptyList())) {
+ for (IpPortMap ipPortMap : requireNonNullElse(intextIpProtocolType.getIpPortMap(),
+ Collections.<IpPortMap>emptyList())) {
String ipPortInternal = ipPortMap.getIpPortInternal();
String[] ipPortParts = ipPortInternal.split(":");
if (ipPortParts.length != 2) {
}
}
- public void clrRtsFromBgpAndDelFibTs(final BigInteger dpnId, Long routerId, Uuid networkUuid,
- @Nonnull Collection<String> externalIps, String vpnName,
+ public void clrRtsFromBgpAndDelFibTs(final BigInteger dpnId, Long routerId, @Nullable Uuid networkUuid,
+ @Nonnull Collection<String> externalIps, @Nullable String vpnName,
String extGwMacAddress, TypedReadWriteTransaction<Configuration> confTx)
throws ExecutionException, InterruptedException {
//Withdraw the corresponding routes from the BGP.
}
protected void clearFibTsAndReverseTraffic(final BigInteger dpnId, Long routerId, Uuid networkUuid,
- List<String> externalIps, String vpnName, String extGwMacAddress,
- TypedReadWriteTransaction<Configuration> writeFlowInvTx)
- throws ExecutionException, InterruptedException {
+ List<String> externalIps, @Nullable String vpnName, String extGwMacAddress,
+ TypedReadWriteTransaction<Configuration> writeFlowInvTx) throws ExecutionException, InterruptedException {
//Withdraw the corresponding routes from the BGP.
//Get the network ID using the router ID.
LOG.debug("clearFibTsAndReverseTraffic : for externalIps {} with routerId {},"
routerId);
return;
}
- List<IntextIpProtocolType> intextIpProtocolTypes = ipPortMapping.getIntextIpProtocolType();
- for (IntextIpProtocolType intextIpProtocolType : intextIpProtocolTypes) {
- List<IpPortMap> ipPortMaps = intextIpProtocolType.getIpPortMap();
- for (IpPortMap ipPortMap : ipPortMaps) {
+ for (IntextIpProtocolType intextIpProtocolType : requireNonNullElse(ipPortMapping.getIntextIpProtocolType(),
+ Collections.<IntextIpProtocolType>emptyList())) {
+ for (IpPortMap ipPortMap : requireNonNullElse(intextIpProtocolType.getIpPortMap(),
+ Collections.<IpPortMap>emptyList())) {
String ipPortInternal = ipPortMap.getIpPortInternal();
String[] ipPortParts = ipPortInternal.split(":");
if (ipPortParts.length != 2) {
}
protected void installNaptPfibEntriesForExternalSubnets(String routerName, BigInteger dpnId,
- TypedWriteTransaction<Configuration> writeFlowInvTx) {
+ @Nullable TypedWriteTransaction<Configuration> writeFlowInvTx) {
Collection<Uuid> externalSubnetIdsForRouter = NatUtil.getExternalSubnetIdsForRouter(dataBroker,
routerName);
for (Uuid externalSubnetId : externalSubnetIdsForRouter) {
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutionException;
+import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Singleton;
update.key(), original, update);
}
+ @Nullable
private FlowEntity buildPreDNATFlowEntity(BigInteger dpId, InternalToExternalPortMap mapping, long routerId, long
associatedVpn) {
String externalIp = mapping.getExternalIp();
return flowEntity;
}
+ @Nullable
private FlowEntity buildSNATFlowEntity(BigInteger dpId, InternalToExternalPortMap mapping, long vpnId, Uuid
externalNetworkId) {
String internalIp = mapping.getInternalIp();
}
}
+ @Nullable
private Uuid getExtNetworkId(final InstanceIdentifier<RouterPorts> portIid,
LogicalDatastoreType dataStoreType) {
Optional<RouterPorts> rtrPort =
return null;
}
- Uuid extNwId = rtrPort.get().getExternalNetworkId();
- return extNwId;
+ return rtrPort.get().getExternalNetworkId();
}
private long getVpnId(Uuid extNwId, Uuid floatingIpExternalId) {
}
void createNATFlowEntries(String interfaceName, final InternalToExternalPortMap mapping,
- final InstanceIdentifier<RouterPorts> portIid, final String routerName, BigInteger dpnId,
+ final InstanceIdentifier<RouterPorts> portIid, final String routerName, @Nullable BigInteger dpnId,
TypedReadWriteTransaction<Configuration> confTx) throws ExecutionException, InterruptedException {
if (!validateIpMapping(mapping)) {
LOG.error("createNATFlowEntries : Not a valid ip addresses in the mapping {}", mapping);
confTx);
}
- void createNATOnlyFlowEntries(BigInteger dpnId, String routerName, String associatedVPN,
+ void createNATOnlyFlowEntries(BigInteger dpnId, String routerName, @Nullable String associatedVPN,
Uuid externalNetworkId, InternalToExternalPortMap mapping)
throws ExecutionException, InterruptedException {
String internalIp = mapping.getInternalIp();
}
void removeNATFlowEntries(String interfaceName, final InternalToExternalPortMap mapping,
- InstanceIdentifier<RouterPorts> portIid, final String routerName, BigInteger dpnId,
- TypedReadWriteTransaction<Configuration> removeFlowInvTx)
- throws ExecutionException, InterruptedException {
+ InstanceIdentifier<RouterPorts> portIid, final String routerName, @Nullable BigInteger dpnId,
+ TypedReadWriteTransaction<Configuration> removeFlowInvTx) throws ExecutionException, InterruptedException {
Uuid extNwId = getExtNetworkId(portIid, LogicalDatastoreType.OPERATIONAL);
if (extNwId == null) {
LOG.error("removeNATFlowEntries : External network associated with interface {} could not be retrieved",
}
private void addOrDelDefaultFibRouteForDnat(BigInteger dpnId, String routerName, long routerId,
- TypedReadWriteTransaction<Configuration> confTx, boolean create)
+ @Nullable TypedReadWriteTransaction<Configuration> confTx, boolean create)
throws ExecutionException, InterruptedException {
if (confTx == null) {
ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
package org.opendaylight.netvirt.natservice.internal;
+import javax.annotation.Nullable;
import org.opendaylight.netvirt.natservice.internal.NaptPacketInHandler.NatPacketProcessingState;
import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived;
private final NatPacketProcessingState state;
NAPTEntryEvent(String ipAddress, int portNumber, Long routerId, Operation op, Protocol protocol,
- PacketReceived packetReceived, boolean pktProcessed, NatPacketProcessingState state) {
+ @Nullable PacketReceived packetReceived, boolean pktProcessed, @Nullable NatPacketProcessingState state) {
this.ipAddress = ipAddress;
this.portNumber = portNumber;
this.routerId = routerId;
*/
package org.opendaylight.netvirt.natservice.internal;
+import static org.opendaylight.netvirt.natservice.internal.NatUtil.requireNonNullElse;
+
import com.google.common.base.Optional;
import java.math.BigInteger;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
if (optNaptSwitches.isPresent()) {
NaptSwitches naptSwitches = optNaptSwitches.get();
- List<RouterToNaptSwitch> routerToNaptSwitches = naptSwitches.getRouterToNaptSwitch();
- for (RouterToNaptSwitch naptSwitch : routerToNaptSwitches) {
+ for (RouterToNaptSwitch naptSwitch : requireNonNullElse(naptSwitches.getRouterToNaptSwitch(),
+ Collections.<RouterToNaptSwitch>emptyList())) {
BigInteger primarySwitch = naptSwitch.getPrimarySwitchId();
//update weight
Integer weight = switchWeights.get(primarySwitch);
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
return new FlowRef(flowInstanceId);
}
+ @Nullable
private static List<MatchInfo> buildAndGetMatchInfo(String ip, int port, short tableId,
NAPTEntryEvent.Protocol protocol, long segmentId) {
MatchInfo ipMatchInfo = null;
return matchInfo;
}
+ @Nonnull
private static List<InstructionInfo> buildAndGetSetActionInstructionInfo(String ipAddress, int port,
long segmentId, long vpnId,
short tableId,
default:
LOG.error("buildAndGetSetActionInstructionInfo : Neither OUTBOUND_NAPT_TABLE nor "
+ "INBOUND_NAPT_TABLE matches with input table id {}", tableId);
- return null;
+ return Collections.emptyList();
}
listActionInfo.add(ipActionInfo);
+ "for SNAT ({}:{}) session:{}ms", tableId, dpnId, ip, port, System.currentTimeMillis() - startTime);
}
+ @Nullable
@SuppressFBWarnings("PZLA_PREFER_ZERO_LENGTH_ARRAYS")
protected byte[] buildNaptPacketOut(Ethernet etherPkt) {
LOG.debug("removeNatFlows : About to build Napt Packet Out");
*/
package org.opendaylight.netvirt.natservice.internal;
+import static org.opendaylight.netvirt.natservice.internal.NatUtil.requireNonNullElse;
+
import com.google.common.base.Optional;
import com.google.common.util.concurrent.UncheckedExecutionException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.Objects;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.apache.commons.net.util.SubnetUtils;
*/
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
+ @Nullable
public SessionAddress getExternalAddressMapping(long segmentId, SessionAddress sourceAddress,
NAPTEntryEvent.Protocol protocol) {
LOG.debug("getExternalAddressMapping : called with segmentId {}, internalIp {} and port {}",
.child(IpPortMap.class, new IpPortMapKey(internal)).build();
}
+ @Nullable
private SessionAddress checkIpPortMap(long segmentId, String internalIpPort,
NAPTEntryEvent.Protocol protocol) {
LOG.debug("checkIpPortMap : called with segmentId {} and internalIpPort {}",
return null;
}
+ @Nullable
protected String checkIpMap(long segmentId, String internalIp) {
LOG.debug("checkIpMap : called with segmentId {} and internalIp {}", segmentId, internalIp);
String externalIp;
InstanceIdentifier<IpMapping> id = idBuilder.build();
Optional<IpMapping> ipMapping = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (ipMapping.isPresent()) {
- List<IpMap> ipMaps = ipMapping.get().getIpMap();
- for (IpMap ipMap : ipMaps) {
- if (ipMap.getInternalIp().equals(internalIp)) {
+ for (IpMap ipMap : requireNonNullElse(ipMapping.get().getIpMap(), Collections.<IpMap>emptyList())) {
+ if (Objects.equals(ipMap.getInternalIp(), internalIp)) {
LOG.debug("checkIpMap : IpMap : {}", ipMap);
externalIp = ipMap.getExternalIp();
LOG.debug("checkIpMap : successfully returning externalIp {}", externalIp);
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
}
+ @Nullable
protected String getExternalIpAllocatedForSubnet(long segmentId, String internalIp) {
InstanceIdentifierBuilder<IpMap> idBuilder = InstanceIdentifier.builder(IntextIpMap.class)
.child(IpMapping.class, new IpMappingKey(segmentId))
.child(IpMapping.class, new IpMappingKey(segmentId));
InstanceIdentifier<IpMapping> id = idBuilder.build();
// Get all externalIps and decrement their counters before deleting the ipmap
- String externalIp = null;
Optional<IpMapping> ipMapping = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (ipMapping.isPresent()) {
- List<IpMap> ipMaps = ipMapping.get().getIpMap();
- for (IpMap ipMap : ipMaps) {
- externalIp = ipMap.getExternalIp();
+ for (IpMap ipMap : requireNonNullElse(ipMapping.get().getIpMap(), Collections.<IpMap>emptyList())) {
+ String externalIp = ipMap.getExternalIp();
LOG.debug("removeIpMappingForRouterID : externalIP is {}", externalIp);
if (externalIp != null) {
updateCounter(segmentId, externalIp, false);
protected void initialiseExternalCounter(Routers routers, long routerId) {
LOG.debug("initialiseExternalCounter : Initialise External IPs counter");
- List<ExternalIps> externalIps = routers.getExternalIps();
//update the new counter value for this externalIp
- for (ExternalIps externalIp : externalIps) {
+ for (ExternalIps externalIp : requireNonNullElse(routers.getExternalIps(),
+ Collections.<ExternalIps>emptyList())) {
String[] ipSplit = externalIp.getIpAddress().split("/");
String extIp = ipSplit[0];
String extPrefix = Short.toString(NatConstants.DEFAULT_PREFIX);
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
}
protected void removeSnatFlowsInOldNaptSwitch(String routerName, Long routerId, BigInteger naptSwitch,
- Map<String, Long> externalIpmap,
+ @Nullable Map<String, Long> externalIpmap,
TypedReadWriteTransaction<Configuration> confTx)
throws ExecutionException, InterruptedException {
return true;
}
+ @Nullable
private String getExtNetworkVpnName(String routerName, Uuid networkId) {
if (networkId == null) {
LOG.error("getExtNetworkVpnName : networkId is null for the router ID {}", routerName);
LOG.debug("modifySnatGroupEntry : modified SnatMissEntry for dpnId {} of router {}", dpnId, routerName);
}
+ @Nullable
protected String getTunnelInterfaceName(BigInteger srcDpId, BigInteger dstDpId) {
Class<? extends TunnelTypeBase> tunType = TunnelTypeVxlan.class;
RpcResult<GetTunnelInterfaceNameOutput> rpcResult;
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.datastoreutils.SingleTransactionDataBroker;
String prefix,
String nextHopIp,
long l3Vni,
- String interfaceName,
+ @Nullable String interfaceName,
String gwMacAddress,
TypedWriteTransaction<Configuration> writeTx,
RouteOrigin origin, BigInteger dpId,
return;
}
NatUtil.addPrefixToInterface(broker, NatUtil.getVpnId(broker, vpnName), interfaceName, prefix,
- networkId.getValue(), null, dpId, Prefixes.PrefixCue.Nat);
+ networkId.getValue(), dpId, Prefixes.PrefixCue.Nat);
fibManager.addOrUpdateFibEntry(rd, null /*macAddress*/, prefix,
Collections.singletonList(nextHopIp), VrfEntry.EncapType.Vxlan, NatConstants.DEFAULT_LABEL_VALUE,
.FLOWID_SEPARATOR + l3Vni;
}
+ @Nullable
public static Uuid getFloatingIpInterfaceIdFromFloatingIpId(DataBroker broker, Uuid floatingIpId) {
InstanceIdentifier<FloatingIpIdToPortMapping> id =
NatUtil.buildfloatingIpIdToPortMappingIdentifier(floatingIpId);
*/
package org.opendaylight.netvirt.natservice.internal;
+import static org.opendaylight.netvirt.natservice.internal.NatUtil.requireNonNullElse;
+
import com.google.common.base.Optional;
import java.math.BigInteger;
+import java.util.Collections;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Singleton;
LOG.warn("remove : Interface {} is not a VPN Interface, ignoring.", interfaceName);
return;
}
- for (VpnInstanceNames vpnInterfaceVpnInstance : cfgVpnInterface.get().getVpnInstanceNames()) {
+ for (VpnInstanceNames vpnInterfaceVpnInstance : requireNonNullElse(
+ cfgVpnInterface.get().getVpnInstanceNames(), Collections.<VpnInstanceNames>emptyList())) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
InstanceIdentifier<VpnInterfaceOpDataEntry> idOper = NatUtil
.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
}
}
}
- if (intfDpnId.equals(BigInteger.ZERO)) {
+ if (BigInteger.ZERO.equals(intfDpnId)) {
LOG.warn("remove : Could not retrieve dpnid for interface {} ", interfaceName);
return;
}
LOG.warn("update : Interface {} is not a VPN Interface, ignoring.", interfaceName);
return;
}
- for (VpnInstanceNames vpnInterfaceVpnInstance : cfgVpnInterface.get().getVpnInstanceNames()) {
+ for (VpnInstanceNames vpnInterfaceVpnInstance : requireNonNullElse(
+ cfgVpnInterface.get().getVpnInstanceNames(), Collections.<VpnInstanceNames>emptyList())) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
InstanceIdentifier<VpnInterfaceOpDataEntry> idOper = NatUtil
.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
}
}
}
- if (intfDpnId.equals(BigInteger.ZERO)) {
+ if (BigInteger.ZERO.equals(intfDpnId)) {
LOG.warn("remove : Could not retrieve dpnid for interface {} ", interfaceName);
return;
}
import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
+import static org.opendaylight.netvirt.natservice.internal.NatUtil.requireNonNullElse;
import com.google.common.base.Optional;
import com.google.common.collect.HashBasedTable;
import com.google.common.util.concurrent.MoreExecutors;
import java.math.BigInteger;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
}
public void handleAdd(String interfaceName, BigInteger intfDpnId,
- RouterInterface routerInterface, VipState vipState) {
+ RouterInterface routerInterface, @Nullable VipState vipState) {
String routerName = routerInterface.getRouterName();
NatInterfaceStateAddWorker natIfaceStateAddWorker = new NatInterfaceStateAddWorker(interfaceName,
intfDpnId, routerName);
private void processInterfaceAdded(String portName, String routerId, BigInteger dpnId, VipState vipState) {
LOG.trace("processInterfaceAdded : Processing Interface Add Event for interface {}", portName);
List<InternalToExternalPortMap> intExtPortMapList = getIntExtPortMapListForPortName(portName, routerId);
- if (intExtPortMapList == null || intExtPortMapList.isEmpty()) {
+ if (intExtPortMapList.isEmpty()) {
LOG.debug("processInterfaceAdded : Ip Mapping list is empty/null for portname {}", portName);
return;
}
}, MoreExecutors.directExecutor());
}
+ @Nonnull
private List<InternalToExternalPortMap> getIntExtPortMapListForPortName(String portName, String routerId) {
InstanceIdentifier<Ports> portToIpMapIdentifier = NatUtil.buildPortToIpMapIdentifier(routerId, portName);
Optional<Ports> port =
if (!port.isPresent()) {
LOG.info("getIntExtPortMapListForPortName : Unable to read router port entry for router ID {} "
+ "and port name {}", routerId, portName);
- return null;
+ return Collections.emptyList();
}
- return port.get().getInternalToExternalPortMap();
+ return requireNonNullElse(port.get().getInternalToExternalPortMap(), Collections.emptyList());
}
+ @Nullable
private BigInteger getNaptSwitchforRouter(DataBroker broker, String routerName) {
InstanceIdentifier<RouterToNaptSwitch> rtrNaptSw = InstanceIdentifier.builder(NaptSwitches.class)
.child(RouterToNaptSwitch.class, new RouterToNaptSwitchKey(routerName)).build();
+ "router {} ip {} port {}", tableId, dpnId, routerId, ipAddress, ipPort);
}
+ @Nullable
private List<String> getFixedIpsForPort(String interfname) {
LOG.debug("getFixedIpsForPort : getFixedIpsForPort method is called for interface {}", interfname);
try {
LOG.trace("processInterfaceRemoved : Processing Interface Removed Event for interface {} on DPN ID {}",
portName, dpnId);
List<InternalToExternalPortMap> intExtPortMapList = getIntExtPortMapListForPortName(portName, routerId);
- if (intExtPortMapList == null || intExtPortMapList.isEmpty()) {
+ if (intExtPortMapList.isEmpty()) {
LOG.debug("processInterfaceRemoved : Ip Mapping list is empty/null for portName {}", portName);
return;
}
continue;
}
- for (IntIpProtoType protoType: ipPort.getIntIpProtoType()) {
+ for (IntIpProtoType protoType : requireNonNullElse(ipPort.getIntIpProtoType(),
+ Collections.<IntIpProtoType>emptyList())) {
ProtocolTypes protocol = protoType.getProtocol();
- for (Integer portnum : protoType.getPorts()) {
+ for (Integer portnum : requireNonNullElse(protoType.getPorts(), Collections.<Integer>emptyList())) {
//build and remove the flow in outbound table
try {
removeNatFlow(naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, routerId, internalIp, portnum);
package org.opendaylight.netvirt.natservice.internal;
import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.netvirt.natservice.internal.NatUtil.requireNonNullElse;
import com.google.common.base.Optional;
import com.google.common.base.Strings;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
} catch (Exception e) {
/* this dpn does not have the VTEP */
LOG.error("handleTepDelForAllRtrs : DPN {} does not have the VTEP", srcDpnId);
- endpointIpForDPN = null;
}
if (endpointIpForDPN != null) {
} else {
LOG.debug("hndlTepAddOnNaptSwitch : SNAT -> Private BGP VPN associated to router {}", routerId);
vpnId = NatUtil.getVpnId(dataBroker, vpnName.getValue());
- if (vpnId == null || vpnId == NatConstants.INVALID_ID) {
+ if (vpnId == NatConstants.INVALID_ID) {
LOG.error("hndlTepAddOnNaptSwitch : Invalid vpnId returned for routerName {}", routerName);
return false;
}
if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
l3vni = NatOverVxlanUtil.getInternetVpnVni(idManager, externalVpnName, l3vni).longValue();
}
- Uuid externalSubnetId = NatUtil.getExternalSubnetForRouterExternalIp(externalIp, router);
- NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, externalVpnName, rd, externalSubnetId,
- fibExternalIp, nextHopIp, networkId.getValue(), null /* mac-address */, label, l3vni,
+ NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, externalVpnName, rd,
+ fibExternalIp, nextHopIp, networkId.getValue(), null /* mac-address */, label, l3vni,
RouteOrigin.STATIC, srcDpnId);
serviceId = label;
}
l3Vni = NatOverVxlanUtil.getInternetVpnVni(idManager, vpnName, routerId).longValue();
}
}
- List<Ports> interfaces = routerPorts.getPorts();
- for (Ports port : interfaces) {
+ for (Ports port : requireNonNullElse(routerPorts.getPorts(), Collections.<Ports>emptyList())) {
//Get the DPN on which this interface resides
final String interfaceName = port.getPortName();
final BigInteger fipCfgdDpnId = NatUtil.getDpnForInterface(interfaceService, interfaceName);
tepAddedDpnId, fipCfgdDpnId, interfaceName);
continue;
}
- List<InternalToExternalPortMap> intExtPortMapList = port.getInternalToExternalPortMap();
- for (InternalToExternalPortMap intExtPortMap : intExtPortMapList) {
+ for (InternalToExternalPortMap intExtPortMap : requireNonNullElse(port.getInternalToExternalPortMap(),
+ Collections.<InternalToExternalPortMap>emptyList())) {
final String internalIp = intExtPortMap.getInternalIp();
final String externalIp = intExtPortMap.getExternalIp();
LOG.debug("hndlTepAddForDnatInEachRtr : DNAT -> Advertising the FIB route to the floating IP {} "
if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanManager, extNwProvType)) {
l3vni = NatOverVxlanUtil.getInternetVpnVni(idManager, vpnName, l3vni).longValue();
}
- NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, vpnName, rd, null,
- fibExternalIp, nextHopIp, null, null, label, l3vni, RouteOrigin.STATIC,
+ NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, vpnName, rd,
+ fibExternalIp, nextHopIp, null, null, label, l3vni, RouteOrigin.STATIC,
fipCfgdDpnId);
serviceId = label;
}
l3Vni = NatOverVxlanUtil.getInternetVpnVni(idManager, vpnName, routerId).longValue();
}
}
- List<Ports> interfaces = routerPorts.getPorts();
- for (Ports port : interfaces) {
+ for (Ports port : requireNonNullElse(routerPorts.getPorts(), Collections.<Ports>emptyList())) {
//Get the DPN on which this interface resides
String interfaceName = port.getPortName();
BigInteger fipCfgdDpnId = NatUtil.getDpnForInterface(interfaceService, interfaceName);
tepDeletedDpnId, fipCfgdDpnId, interfaceName);
continue;
}
- List<InternalToExternalPortMap> intExtPortMapList = port.getInternalToExternalPortMap();
- for (InternalToExternalPortMap intExtPortMap : intExtPortMapList) {
+ for (InternalToExternalPortMap intExtPortMap : requireNonNullElse(port.getInternalToExternalPortMap(),
+ Collections.<InternalToExternalPortMap>emptyList())) {
String internalIp = intExtPortMap.getInternalIp();
String externalIp = intExtPortMap.getExternalIp();
externalIp = NatUtil.validateAndAddNetworkMask(externalIp);
package org.opendaylight.netvirt.natservice.internal;
+import static java.util.Objects.requireNonNull;
import static org.opendaylight.controller.md.sal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
/*
getVpnId() returns the VPN ID from the VPN name
*/
- public static long getVpnId(DataBroker broker, String vpnName) {
+ public static long getVpnId(DataBroker broker, @Nullable String vpnName) {
if (vpnName == null) {
return NatConstants.INVALID_ID;
}
.instance.to.vpn.id.VpnInstanceKey(vpnName)).build();
}
+ @Nullable
static String getVpnInstanceFromVpnIdentifier(DataBroker broker, long vpnId) {
InstanceIdentifier<VpnIds> id = InstanceIdentifier.builder(VpnIdToVpnInstance.class)
.child(VpnIds.class, new VpnIdsKey(vpnId)).build();
+ port;
}
+ @Nullable
static Uuid getNetworkIdFromRouterId(DataBroker broker, long routerId) {
String routerName = getRouterName(broker, routerId);
if (routerName == null) {
return getNetworkIdFromRouterName(broker, routerName);
}
+ @Nullable
static Uuid getNetworkIdFromRouterName(DataBroker broker, String routerName) {
if (routerName == null) {
LOG.error("getNetworkIdFromRouterName - empty routerName received");
LogicalDatastoreType.CONFIGURATION, id).toJavaUtil().map(Routers::isEnableSnat).orElse(false);
}
+ @Nullable
public static Uuid getVpnIdfromNetworkId(DataBroker broker, Uuid networkId) {
InstanceIdentifier<Networks> id = buildNetworkIdentifier(networkId);
return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
}
}
+ @Nullable
public static ProviderTypes getProviderTypefromNetworkId(DataBroker broker, Uuid networkId) {
InstanceIdentifier<Networks> id = buildNetworkIdentifier(networkId);
return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
Collections.emptyList());
}
+ @Nullable
static String getAssociatedExternalNetwork(DataBroker dataBroker, String routerId) {
InstanceIdentifier<Routers> id = NatUtil.buildRouterIdentifier(routerId);
Optional<Routers> routerData =
.child(Networks.class, new NetworksKey(networkId)).build();
}
+ @Nullable
public static BigInteger getPrimaryNaptfromRouterId(DataBroker broker, Long routerId) {
// convert routerId to Name
String routerName = getRouterName(broker, routerId);
return getPrimaryNaptfromRouterName(broker, routerName);
}
+ @Nullable
public static BigInteger getPrimaryNaptfromRouterName(DataBroker broker, String routerName) {
if (routerName == null) {
LOG.error("getPrimaryNaptfromRouterName - empty routerName received");
}
public static InstanceIdentifier<RouterToNaptSwitch> buildNaptSwitchIdentifier(String routerId) {
- InstanceIdentifier<RouterToNaptSwitch> rtrNaptSw = InstanceIdentifier.builder(NaptSwitches.class)
- .child(RouterToNaptSwitch.class, new RouterToNaptSwitchKey(routerId)).build();
- return rtrNaptSw;
+ return InstanceIdentifier.builder(NaptSwitches.class).child(RouterToNaptSwitch.class,
+ new RouterToNaptSwitchKey(routerId)).build();
}
public static Optional<NaptSwitches> getAllPrimaryNaptSwitches(DataBroker broker) {
LogicalDatastoreType.CONFIGURATION, getNaptSwitchesIdentifier());
}
+ @Nullable
public static String getRouterName(DataBroker broker, Long routerId) {
return getVpnInstanceFromVpnIdentifier(broker, routerId);
}
+ ((rawIpAddress[2] & 0xFF) << 1 * 8) + (rawIpAddress[3] & 0xFF) & 0xffffffffL;
}
+ @Nullable
public static String getEndpointIpAddressForDPN(DataBroker broker, BigInteger dpnId) {
String nextHopIp = null;
InstanceIdentifier<DPNTEPsInfo> tunnelInfoId =
return nextHopIp;
}
+ @Nullable
public static String getVpnRd(DataBroker broker, String vpnName) {
-
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn
.instance.to.vpn.id.VpnInstance> id = getVpnInstanceToVpnIdIdentifier(vpnName);
return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
.VpnInstance::getVrfId).orElse(null);
}
+ @Nullable
public static String getVpnRd(TypedReadTransaction<Configuration> tx, String vpnName) {
try {
return tx.read(getVpnInstanceToVpnIdIdentifier(vpnName)).get().toJavaUtil().map(
}
}
+ @Nullable
public static IpPortExternal getExternalIpPortMap(DataBroker broker, Long routerId, String internalIpAddress,
String internalPort, NAPTEntryEvent.Protocol protocol) {
ProtocolTypes protocolType = NatUtil.getProtocolType(protocol);
.child(VpnInterface.class, new VpnInterfaceKey(vpnInterfaceName)).build();
}
+ @Nullable
static VpnInterface getConfiguredVpnInterface(DataBroker broker, String interfaceName) {
InstanceIdentifier<VpnInterface> interfaceId = getVpnInterfaceIdentifier(interfaceName);
return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
LogicalDatastoreType.CONFIGURATION, interfaceId).orNull();
}
+ @Nullable
public static String getDpnFromNodeConnectorId(NodeConnectorId portId) {
/*
* NodeConnectorId is of form 'openflow:dpnid:portnum'
return new BigInteger(getDpnFromNodeConnectorId(nodeConnectorId));
}
+ @Nullable
public static String getRouterIdfromVpnInstance(DataBroker broker, String vpnName) {
// returns only router, attached to IPv4 networks
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class)
return null;
}
+ @Nullable
static Uuid getVpnForRouter(DataBroker broker, String routerId) {
Preconditions.checkNotNull(routerId, "dissociateRouter: routerId not found!");
InstanceIdentifier<VpnMaps> vpnMapsIdentifier = InstanceIdentifier.builder(VpnMaps.class).build();
SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
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())) {
if (routerId.equals(vpnMap.getVpnId().getValue())) {
continue;
}
List<Uuid> routerIdsList = NeutronUtils.getVpnMapRouterIdsListUuid(vpnMap.getRouterIds());
- if (routerIdsList == null || routerIdsList.isEmpty()) {
+ if (routerIdsList.isEmpty()) {
return null;
}
- //Skip router vpnId fetching from internet BGP-VPN
- boolean isInternetBgpVpn = false;
+ // Skip router vpnId fetching from internet BGP-VPN
if (vpnMap.getNetworkIds() != null && !vpnMap.getNetworkIds().isEmpty()) {
- for (Uuid netId: vpnMap.getNetworkIds()) {
- if (isExternalNetwork(broker, netId)) {
- 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 (isExternalNetwork(broker, vpnMap.getNetworkIds().iterator().next())) {
+ continue;
}
}
- if (isInternetBgpVpn) {
- //skip further processing
- continue;
- }
if (routerIdsList.contains(new Uuid(routerId))) {
return vpnMap.getVpnId();
}
NatConstants.INVALID_ID);
}
+ @Nullable
public static String getAssociatedVPN(DataBroker dataBroker, Uuid networkId) {
Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
if (vpnUuid == null) {
return vpnUuid.getValue();
}
+ @Nullable
public static String getAssociatedVPN(TypedReadTransaction<Configuration> tx, Uuid networkId) {
Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(tx, networkId);
if (vpnUuid == null) {
IFibManager fibManager,
String vpnName,
String rd,
- Uuid subnetId,
String prefix,
String nextHopIp,
- String parentVpnRd,
- String macAddress,
+ @Nullable String parentVpnRd,
+ @Nullable String macAddress,
long label,
long l3vni,
RouteOrigin origin,
}
addPrefixToInterface(broker, getVpnId(broker, vpnName), null /*interfaceName*/,prefix, parentVpnRd,
- subnetId, dpId, Prefixes.PrefixCue.Nat);
+ dpId, Prefixes.PrefixCue.Nat);
fibManager.addOrUpdateFibEntry(rd, macAddress, prefix,
Collections.singletonList(nextHopIp), VrfEntry.EncapType.Mplsgre, (int)label, l3vni /*l3vni*/,
null /*gatewayMacAddress*/, parentVpnRd, origin, null /*writeTxn*/);
}
}
- static void addPrefixToInterface(DataBroker broker, long vpnId, String interfaceName, String ipPrefix,
- String networkId, Uuid subnetId, BigInteger dpId, Prefixes.PrefixCue prefixCue) {
+ static void addPrefixToInterface(DataBroker broker, long vpnId, @Nullable String interfaceName, String ipPrefix,
+ String networkId, BigInteger dpId, Prefixes.PrefixCue prefixCue) {
InstanceIdentifier<Prefixes> prefixId = InstanceIdentifier.builder(PrefixToInterface.class)
.child(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface
.VpnIds.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix
}
}
+ @Nullable
public static IpPortMapping getIportMapping(DataBroker broker, long routerId) {
return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
LogicalDatastoreType.CONFIGURATION, getIportMappingIdentifier(routerId)).orNull();
public static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt
.natservice.rev160111.intext.ip.map.IpMapping> getIpMappingBuilder(Long routerId) {
- InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111
- .intext.ip.map.IpMapping> idBuilder = InstanceIdentifier.builder(IntextIpMap.class)
+ return InstanceIdentifier.builder(IntextIpMap.class)
.child(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map
.IpMapping.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111
- .intext.ip.map.IpMappingKey(routerId)).build();
- return idBuilder;
+ .intext.ip.map.IpMappingKey(routerId))
+ .build();
}
@Nonnull
// Ensure there are no duplicates
Collection<String> externalIps = new HashSet<>();
if (ipMappingOptional.isPresent()) {
- List<IpMap> ipMaps = ipMappingOptional.get().getIpMap();
- for (IpMap ipMap : ipMaps) {
+ for (IpMap ipMap : requireNonNullElse(ipMappingOptional.get().getIpMap(), Collections.<IpMap>emptyList())) {
externalIps.add(ipMap.getExternalIp());
}
}
LogicalDatastoreType.OPERATIONAL, getIpMappingBuilder(routerId));
Map<String, Long> externalIpsLabel = new HashMap<>();
if (ipMappingOptional.isPresent()) {
- List<IpMap> ipMaps = ipMappingOptional.get().getIpMap();
- for (IpMap ipMap : ipMaps) {
+ for (IpMap ipMap : requireNonNullElse(ipMappingOptional.get().getIpMap(), Collections.<IpMap>emptyList())) {
externalIpsLabel.put(ipMap.getExternalIp(), ipMap.getLabel());
}
}
return externalIpsLabel;
}
+ @Nullable
public static String getLeastLoadedExternalIp(DataBroker dataBroker, long segmentId) {
String leastLoadedExternalIp = null;
InstanceIdentifier<ExternalCounters> id =
MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (externalCountersData.isPresent()) {
ExternalCounters externalCounter = externalCountersData.get();
- List<ExternalIpCounter> externalIpCounterList = externalCounter.getExternalIpCounter();
short countOfLstLoadExtIp = 32767;
- for (ExternalIpCounter externalIpCounter : externalIpCounterList) {
+ for (ExternalIpCounter externalIpCounter : requireNonNullElse(externalCounter.getExternalIpCounter(),
+ Collections.<ExternalIpCounter>emptyList())) {
String curExternalIp = externalIpCounter.getExternalIp();
short countOfCurExtIp = externalIpCounter.getCounter();
if (countOfCurExtIp < countOfLstLoadExtIp) {
}
@SuppressFBWarnings("PZLA_PREFER_ZERO_LENGTH_ARRAYS")
+ @Nullable
public static String[] getSubnetIpAndPrefix(DataBroker dataBroker, Uuid subnetId) {
String subnetIP = getSubnetIp(dataBroker, subnetId);
if (subnetIP != null) {
return null;
}
+ @Nonnull
public static String[] getSubnetIpAndPrefix(String subnetString) {
String[] subnetSplit = subnetString.split("/");
String subnetIp = subnetSplit[0];
return new String[] {subnetIp, subnetPrefix};
}
+ @Nullable
public static String getSubnetIp(DataBroker dataBroker, Uuid subnetId) {
InstanceIdentifier<Subnetmap> subnetmapId = InstanceIdentifier
.builder(Subnetmaps.class)
.build();
return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
LogicalDatastoreType.CONFIGURATION, subnetmapId).toJavaUtil().map(Subnetmap::getSubnetIp).orElse(null);
-
}
public static String[] getExternalIpAndPrefix(String leastLoadedExtIpAddr) {
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 bgpVpnId;
}
+ @Nullable
static org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.router.interfaces
.RouterInterface getConfiguredRouterInterface(DataBroker broker, String interfaceName) {
return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
public static List<ActionInfo> getEgressActionsForInterface(OdlInterfaceRpcService odlInterfaceRpcService,
ItmRpcService itmRpcService,
IInterfaceManager interfaceManager,
- String ifName, Long tunnelKey, int pos,
+ String ifName, @Nullable Long tunnelKey, int pos,
boolean internalTunnelInterface) {
LOG.debug("getEgressActionsForInterface : called for interface {}", ifName);
GetEgressActionsForInterfaceInputBuilder egressActionsIfmBuilder =
}
}
List<ActionInfo> listActionInfo = new ArrayList<>();
- for (Action action : actions) {
+ for (Action action : requireNonNullElse(actions, Collections.<Action>emptyList())) {
org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action
actionClass = action.getAction();
if (actionClass instanceof OutputActionCase) {
return Collections.emptyList();
}
+ @Nullable
public static Port getNeutronPortForRouterGetewayIp(DataBroker broker, IpAddress targetIP) {
return getNeutronPortForIp(broker, targetIP, NeutronConstants.DEVICE_OWNER_GATEWAY_INF);
}
return portsOptional.get().getPort();
}
- public static Port getNeutronPortForIp(DataBroker broker,
- IpAddress targetIP, String deviceType) {
+ @Nullable
+ public static Port getNeutronPortForIp(DataBroker broker, IpAddress targetIP, String deviceType) {
List<Port> ports = getNeutronPorts(
broker);
return null;
}
+ @Nullable
public static Uuid getSubnetIdForFloatingIp(Port port, IpAddress targetIP) {
if (port == null) {
LOG.error("getSubnetIdForFloatingIp : port is null");
return null;
}
- for (FixedIps ip : port.getFixedIps()) {
+ for (FixedIps ip : requireNonNullElse(port.getFixedIps(), Collections.<FixedIps>emptyList())) {
if (Objects.equals(ip.getIpAddress(), targetIP)) {
return ip.getSubnetId();
}
return null;
}
+ @Nullable
public static Subnetmap getSubnetMap(DataBroker broker, Uuid subnetId) {
InstanceIdentifier<Subnetmap> subnetmapId = InstanceIdentifier.builder(Subnetmaps.class)
.child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
Collections.emptyList());
}
+ @Nullable
public static String getSubnetGwMac(DataBroker broker, Uuid subnetId, String vpnName) {
if (subnetId == null) {
LOG.error("getSubnetGwMac : subnetID is null");
.child(RouterDpnList.class, new RouterDpnListKey(routerName)).build();
}
+ @Nullable
protected static String getFloatingIpPortMacFromFloatingIpId(DataBroker broker, Uuid floatingIpId) {
InstanceIdentifier<FloatingIpIdToPortMapping> id = buildfloatingIpIdToPortMappingIdentifier(floatingIpId);
return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
FloatingIpIdToPortMapping::getFloatingIpPortMacAddress).orElse(null);
}
+ @Nullable
protected static String getFloatingIpPortMacFromFloatingIpId(TypedReadTransaction<Configuration> confTx,
Uuid floatingIpId) {
try {
}
}
+ @Nullable
protected static Uuid getFloatingIpPortSubnetIdFromFloatingIpId(DataBroker broker, Uuid floatingIpId) {
InstanceIdentifier<FloatingIpIdToPortMapping> id = buildfloatingIpIdToPortMappingIdentifier(floatingIpId);
return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
FloatingIpIdToPortMappingKey(floatingIpId)).build();
}
+ @Nullable
static Interface getInterfaceStateFromOperDS(DataBroker dataBroker, String interfaceName) {
InstanceIdentifier<Interface> ifStateId =
buildStateInterfaceId(interfaceName);
.child(Interface.class,
new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508
.interfaces.state.InterfaceKey(interfaceName));
- InstanceIdentifier<Interface> id = idBuilder.build();
- return id;
+ return idBuilder.build();
}
+ @Nullable
public static Routers getRoutersFromConfigDS(DataBroker dataBroker, String routerName) {
InstanceIdentifier<Routers> routerIdentifier = NatUtil.buildRouterIdentifier(routerName);
return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, buildRouterIdentifier(routerId), rtrs);
}
+ @Nullable
static FlowEntity buildDefaultNATFlowEntityForExternalSubnet(BigInteger dpId, long vpnId, String subnetId,
IdManagerService idManager) {
InetAddress defaultIP = null;
actionsInfo.add(new ActionGroup(groupId));
String flowRef = getFlowRef(dpId, NwConstants.L3_FIB_TABLE, defaultIP, vpnId);
instructions.add(new InstructionApplyActions(actionsInfo));
- FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.L3_FIB_TABLE, flowRef,
+ return MDSALUtil.buildFlowEntity(dpId, NwConstants.L3_FIB_TABLE, flowRef,
NatConstants.DEFAULT_DNAT_FLOW_PRIORITY, flowRef, 0, 0,
NwConstants.COOKIE_DNAT_TABLE, matches, instructions);
- return flowEntity;
}
+ @Nullable
static String getExtGwMacAddFromRouterId(DataBroker broker, long routerId) {
String routerName = getRouterName(broker, routerId);
if (routerName == null) {
return getExtGwMacAddFromRouterName(broker, routerName);
}
+ @Nullable
static String getExtGwMacAddFromRouterName(DataBroker broker, String routerName) {
InstanceIdentifier<Routers> id = buildRouterIdentifier(routerName);
return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
return routerInstanceIdentifier;
}
+ @Nullable
public static String getNeutronRouterNamebyUuid(DataBroker broker, Uuid routerUuid) {
InstanceIdentifier<Router> neutronRouterIdentifier = NatUtil.buildNeutronRouterIdentifier(routerUuid);
return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
LogicalDatastoreType.CONFIGURATION, externalNwIdentifier);
if (externalNwData.isPresent()) {
- for (Networks externalNw : externalNwData.get().getNetworks()) {
+ for (Networks externalNw : requireNonNullElse(externalNwData.get().getNetworks(),
+ Collections.<Networks>emptyList())) {
if (externalNw.getVpnid() != null && externalNw.getVpnid().equals(vpnUuid)) {
- return externalNw.getRouterIds();
+ return requireNonNullElse(externalNw.getRouterIds(), Collections.emptyList());
}
}
}
}
@Nonnull
- public static Collection<Uuid> getExternalSubnetIdsFromExternalIps(List<ExternalIps> externalIps) {
+ public static Collection<Uuid> getExternalSubnetIdsFromExternalIps(@Nullable List<ExternalIps> externalIps) {
if (externalIps == null) {
return Collections.emptySet();
}
}
@Nonnull
- public static Collection<Uuid> getExternalSubnetIdsForRouter(DataBroker dataBroker, String routerName) {
+ public static Collection<Uuid> getExternalSubnetIdsForRouter(DataBroker dataBroker, @Nullable String routerName) {
if (routerName == null) {
LOG.error("getExternalSubnetIdsForRouter : empty routerName received");
return Collections.emptySet();
return NatConstants.INVALID_ID;
}
+ @Nullable
protected static Uuid getExternalSubnetForRouterExternalIp(String externalIpAddress, Routers router) {
externalIpAddress = validateAndAddNetworkMask(externalIpAddress);
- List<ExternalIps> externalIps = router.getExternalIps();
- for (ExternalIps extIp : externalIps) {
+ for (ExternalIps extIp : requireNonNullElse(router.getExternalIps(), Collections.<ExternalIps>emptyList())) {
String extIpString = validateAndAddNetworkMask(extIp.getIpAddress());
if (extIpString.equals(externalIpAddress)) {
return extIp.getSubnetId();
}
// elan-instances config container
+ @Nullable
public static ElanInstance getElanInstanceByName(String elanInstanceName, DataBroker broker) {
InstanceIdentifier<ElanInstance> elanIdentifierId = getElanInstanceConfigurationDataPath(elanInstanceName);
return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
+ NwConstants.FLOWID_SEPARATOR + uniqueId;
}
- public static Boolean isFloatingIpPresentForDpn(DataBroker dataBroker, BigInteger dpnId, String rd,
+ public static boolean isFloatingIpPresentForDpn(DataBroker dataBroker, BigInteger dpnId, String rd,
String vpnName, String externalIp,
Boolean isMoreThanOneFipCheckOnDpn) {
InstanceIdentifier<VpnToDpnList> id = getVpnToDpnListIdentifier(rd, dpnId);
if (ipAddressList != null && !ipAddressList.isEmpty()) {
int floatingIpPresentCount = 0;
for (IpAddresses ipAddress: ipAddressList) {
- if (!ipAddress.getIpAddress().equals(externalIp)
+ if (!Objects.equals(ipAddress.getIpAddress(), externalIp)
&& IpAddresses.IpAddressSource.FloatingIP.equals(ipAddress.getIpAddressSource())) {
floatingIpPresentCount++;
//Add tunnel table check
if (isMoreThanOneFipCheckOnDpn && floatingIpPresentCount > 1) {
- return Boolean.TRUE;
+ return true;
}
//Remove tunnel table check
if (!isMoreThanOneFipCheckOnDpn) {
- return Boolean.TRUE;
+ return true;
}
}
}
} else {
LOG.debug("isFloatingIpPresentForDpn : vpn-to-dpn-list does not contain any floating IP for DPN {}",
dpnId);
- return Boolean.FALSE;
+ return false;
}
} catch (NullPointerException e) {
LOG.error("isFloatingIpPresentForDpn: Exception occurred on getting external IP address from "
+ "vpn-to-dpn-list on Dpn {}", dpnId, e);
- return Boolean.FALSE;
+ return false;
}
}
- return Boolean.FALSE;
+ return false;
}
private static InstanceIdentifier<VpnToDpnList> getVpnToDpnListIdentifier(String rd, BigInteger dpnId) {
return vpnName;
}
- public static String getPrimaryRd(VpnInstance vpnInstance) {
- List<String> rds = null;
- if (vpnInstance != null) {
- rds = getListOfRdsFromVpnInstance(vpnInstance);
+ @Nullable
+ public static String getPrimaryRd(@Nullable VpnInstance vpnInstance) {
+ if (vpnInstance == null) {
+ return null;
}
- return rds == null || rds.isEmpty() ? vpnInstance.getVpnInstanceName() : rds.get(0);
+ List<String> rds = getListOfRdsFromVpnInstance(vpnInstance);
+ return rds.isEmpty() ? vpnInstance.getVpnInstanceName() : rds.get(0);
}
public static InstanceIdentifier<VpnInstance> getVpnInstanceIdentifier(String vpnName) {
new VpnInterfaceOpDataEntryKey(vpnInterfaceName, vpnName)).build();
}
+ @Nullable
public static VpnInstanceOpDataEntry getVpnInstanceOpData(DataBroker broker, String rd) {
InstanceIdentifier<VpnInstanceOpDataEntry> id = NatUtil.getVpnInstanceOpDataIdentifier(rd);
return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(
String sharedRouterName = routerUuid.getValue();
if (!routerName.equals(sharedRouterName)) {
BigInteger switchDpnId = NatUtil.getPrimaryNaptfromRouterName(broker, sharedRouterName);
- if (switchDpnId == null) {
- continue;
- } else if (switchDpnId.equals(dpnId)) {
+ if (switchDpnId != null && switchDpnId.equals(dpnId)) {
LOG.debug("checkForRoutersWithSameExtNetAndNaptSwitch: external-network {} is "
+ "associated with other active router {} on NAPT switch {}", networkId,
sharedRouterName, switchDpnId);
List<Uuid> routerUuidList = getOptionalExternalSubnets(broker, externalSubnetId).toJavaUtil()
.map(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external
.subnets.Subnets::getRouterIds).orElse(Collections.emptyList());
- if (routerUuidList != null && !routerUuidList.isEmpty()) {
+ if (!routerUuidList.isEmpty()) {
for (Uuid routerUuid : routerUuidList) {
String sharedRouterName = routerUuid.getValue();
if (!routerName.equals(sharedRouterName)) {
BigInteger switchDpnId = NatUtil.getPrimaryNaptfromRouterName(broker, sharedRouterName);
- if (switchDpnId == null) {
- continue;
- } else if (switchDpnId.equals(dpnId)) {
+ if (switchDpnId != null && switchDpnId.equals(dpnId)) {
LOG.debug("checkForRoutersWithSameExtSubnetAndNaptSwitch: external-subnetwork {} is "
+ "associated with other active router {} on NAPT switch {}", externalSubnetId,
sharedRouterName, switchDpnId);
List<ExternalIps> externalIps = router.getExternalIps();
List<String> externalIpsSting = new ArrayList<>();
- if (externalIps.isEmpty()) {
+ if (externalIps == null || externalIps.isEmpty()) {
LOG.error("installRouterGwFlows: setupRouterGwFlows no externalIP present");
return;
}
return extRouterInstanceIndentifier;
}
+ @Nullable
public static LearntVpnVipToPortData getLearntVpnVipToPortData(DataBroker dataBroker) {
- InstanceIdentifier<LearntVpnVipToPortData> learntVpnVipToPortDataId = getLearntVpnVipToPortDataId();
- LearntVpnVipToPortData learntVpnVipToPortData = null;
try {
- learntVpnVipToPortData = SingleTransactionDataBroker.syncRead(dataBroker,
- LogicalDatastoreType.OPERATIONAL, learntVpnVipToPortDataId);
+ return SingleTransactionDataBroker.syncRead(dataBroker,
+ LogicalDatastoreType.OPERATIONAL, getLearntVpnVipToPortDataId());
}
catch (ReadFailedException e) {
LOG.warn("Failed to read LearntVpnVipToPortData with error {}", e.getMessage());
+ return null;
}
- return learntVpnVipToPortData;
}
public static InstanceIdentifier<LearntVpnVipToPortData> getLearntVpnVipToPortDataId() {
Optional<Networks> networkData =
SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(
broker, LogicalDatastoreType.CONFIGURATION, id);
- if (networkData.isPresent()) {
- return true;
- }
- return false;
+ return networkData.isPresent();
}
+ @Nullable
public static String getElanInstancePhysicalNetwok(String elanInstanceName, DataBroker broker) {
-
ElanInstance elanInstance = getElanInstanceByName(elanInstanceName, broker);
if (null != elanInstance) {
return elanInstance.getPhysicalNetworkName();
LogicalDatastoreType.OPERATIONAL, nodeId);
}
+ @Nullable
public static String getProviderMappings(BigInteger dpId, DataBroker dataBroker) {
return getBridgeRefInfo(dpId, dataBroker).toJavaUtil().map(node -> getOpenvswitchOtherConfigs(node,
PROVIDER_MAPPINGS, dataBroker)).orElse(null);
}
+ @Nullable
public static String getOpenvswitchOtherConfigs(Node node, String key, DataBroker dataBroker) {
OvsdbNodeAugmentation ovsdbNode = node.augmentation(OvsdbNodeAugmentation.class);
if (ovsdbNode == null) {
if (ovsdbNode != null && ovsdbNode.getOpenvswitchOtherConfigs() != null) {
for (OpenvswitchOtherConfigs openvswitchOtherConfigs : ovsdbNode.getOpenvswitchOtherConfigs()) {
- if (openvswitchOtherConfigs.getOtherConfigKey().equals(key)) {
+ if (Objects.equals(openvswitchOtherConfigs.getOtherConfigKey(), key)) {
return openvswitchOtherConfigs.getOtherConfigValue();
}
}
}
+ @Nullable
public static OvsdbBridgeAugmentation extractBridgeAugmentation(Node node) {
if (node == null) {
return null;
}
return node.augmentation(OvsdbBridgeAugmentation.class);
}
+
+ // 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.natservice.internal;
import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.netvirt.natservice.internal.NatUtil.requireNonNullElse;
import com.google.common.base.Optional;
import java.math.BigInteger;
-import java.util.List;
+import java.util.Collections;
import java.util.concurrent.ExecutionException;
import javax.inject.Inject;
import javax.inject.Singleton;
return;
}
Uuid networkId = Uuid.getDefaultInstance(externalNetwork);
- RouterPorts routerPorts = optRouterPorts.get();
- List<Ports> interfaces = routerPorts.getPorts();
- for (Ports port : interfaces) {
+ for (Ports port : requireNonNullElse(optRouterPorts.get().getPorts(), Collections.<Ports>emptyList())) {
String portName = port.getPortName();
BigInteger dpnId = NatUtil.getDpnForInterface(interfaceManager, portName);
if (dpnId.equals(BigInteger.ZERO)) {
continue;
}
- List<InternalToExternalPortMap> intExtPortMapList = port.getInternalToExternalPortMap();
- for (InternalToExternalPortMap intExtPortMap : intExtPortMapList) {
+ for (InternalToExternalPortMap intExtPortMap : requireNonNullElse(port.getInternalToExternalPortMap(),
+ Collections.<InternalToExternalPortMap>emptyList())) {
//remove all NAT related entries with routerName
//floatingIpListener.removeNATOnlyFlowEntries(dpnId, portName, routerName, null,
// intExtPortMap.getInternalIp(), externalIp);
return;
}
Uuid networkId = Uuid.getDefaultInstance(externalNetwork);
- RouterPorts routerPorts = optRouterPorts.get();
- List<Ports> interfaces = routerPorts.getPorts();
- for (Ports port : interfaces) {
+ for (Ports port : requireNonNullElse(optRouterPorts.get().getPorts(), Collections.<Ports>emptyList())) {
String portName = port.getPortName();
BigInteger dpnId = NatUtil.getDpnForInterface(interfaceManager, portName);
if (dpnId.equals(BigInteger.ZERO)) {
+ "skip handling of router {} association with vpn {}", portName, routerName, vpnName);
continue;
}
- List<InternalToExternalPortMap> intExtPortMapList = port.getInternalToExternalPortMap();
- for (InternalToExternalPortMap intExtPortMap : intExtPortMapList) {
+ for (InternalToExternalPortMap intExtPortMap : requireNonNullElse(port.getInternalToExternalPortMap(),
+ Collections.<InternalToExternalPortMap>emptyList())) {
//remove all NAT related entries with routerName
//floatingIpListener.removeNATOnlyFlowEntries(dpnId, portName, routerName, vpnName,
// intExtPortMap.getInternalIp(), externalIp);
import java.util.List;
import java.util.concurrent.ExecutionException;
+import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
this.natServiceCounters = natServiceCounters;
}
+ @Nullable
private FlowEntity buildDefNATFlowEntity(BigInteger dpId, long vpnId) {
InetAddress defaultIP = null;
try {
return flowEntity;
}
+ @Nullable
private FlowEntity buildDefNATFlowEntity(BigInteger dpId, long bgpVpnId, long routerId) {
InetAddress defaultIP = null;
try {
*/
package org.opendaylight.netvirt.natservice.internal;
+import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
LOG.info("{} close", getClass().getSimpleName());
}
+ @Nullable
public AbstractSnatService createFlatVlanSnatServiceImpl() {
-
if (natMode == NatMode.Conntrack) {
return new FlatVlanConntrackBasedSnatService(dataBroker, mdsalManager, itmManager, odlInterfaceRpcService,
idManager, naptSwitchSelector, interfaceManager, vpnFootprintService, fibManager, natDataUtil,
return null;
}
+ @Nullable
public AbstractSnatService createVxlanGreSnatServiceImpl() {
-
if (natMode == NatMode.Conntrack) {
NatOverVxlanUtil.validateAndCreateVxlanVniPool(dataBroker, nvpnManager, idManager,
NatConstants.ODL_VNI_POOL_NAME);
}
return null;
}
-
-
}
package org.opendaylight.netvirt.natservice.internal;
import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.netvirt.natservice.internal.NatUtil.requireNonNullElse;
import com.google.common.base.Optional;
if (original.isUpgradeInProgress() && !updated.isUpgradeInProgress()) {
Optional<NaptSwitches> npatSwitches = NatUtil.getAllPrimaryNaptSwitches(dataBroker);
if (npatSwitches.isPresent()) {
- for (RouterToNaptSwitch routerToNaptSwitch : npatSwitches.get().getRouterToNaptSwitch()) {
+ for (RouterToNaptSwitch routerToNaptSwitch : requireNonNullElse(
+ npatSwitches.get().getRouterToNaptSwitch(), Collections.<RouterToNaptSwitch>emptyList())) {
BigInteger primaryNaptDpnId = routerToNaptSwitch.getPrimarySwitchId();
if (!NatUtil.getSwitchStatus(dataBroker, routerToNaptSwitch.getPrimarySwitchId())) {
String routerUuid = routerToNaptSwitch.getRouterName();
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + routerUuid,
() -> Collections.singletonList(
- txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> {
- reElectNewNaptSwitch(routerUuid, primaryNaptDpnId, confTx);
- }
+ txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
+ confTx -> reElectNewNaptSwitch(routerUuid, primaryNaptDpnId, confTx)
)), NatConstants.NAT_DJC_MAX_RETRIES);
}
}
return;
}
- for (Routers router : routers.getRouters()) {
+ for (Routers router : requireNonNullElse(routers.getRouters(), Collections.<Routers>emptyList())) {
List<ExternalIps> externalIps = router.getExternalIps();
if (router.isEnableSnat() && externalIps != null && !externalIps.isEmpty()) {
centralizedSwitchScheduler.scheduleCentralizedSwitch(router);
}
String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
//Inform BGP
- NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, vpnName, rd, subnetId,
- fibExternalIp, nextHopIp, networkId.getValue(), floatingIpPortMacAddress,
+ NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, vpnName, rd,
+ fibExternalIp, nextHopIp, networkId.getValue(), floatingIpPortMacAddress,
label, l3vni, RouteOrigin.STATIC, dpnId);
List<Instruction> instructions = new ArrayList<>();
*/
package org.opendaylight.netvirt.natservice.rpcservice;
+import static org.opendaylight.netvirt.natservice.internal.NatUtil.requireNonNullElse;
+
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
outerloop:
for (Uuid subnetUuid: subnetUuidList) {
subNet = nvpnManager.getNeutronSubnet(subnetUuid);
- for (AllocationPools allocationPool : subNet.getAllocationPools()) {
+ for (AllocationPools allocationPool : requireNonNullElse(subNet.getAllocationPools(),
+ Collections.<AllocationPools>emptyList())) {
if (NatUtil.isIpInSubnet(ipAddress,
allocationPool.getStart().stringValue(),
allocationPool.getEnd().stringValue())) {
LOG.warn("getNatTranslationsForNetworkAndIpaddress : No DNAT IP Mapping found for IP {}", ipAddress);
} else {
for (Ports fipPort : fipPorts) {
- List<InternalToExternalPortMap> ipMapping = fipPort.getInternalToExternalPortMap();
- for (InternalToExternalPortMap fipMap : ipMapping) {
+ for (InternalToExternalPortMap fipMap : requireNonNullElse(fipPort.getInternalToExternalPortMap(),
+ Collections.<InternalToExternalPortMap>emptyList())) {
if (fipMap.getInternalIp().equals(ipAddress)) {
output = new GetNatTranslationsForNetworkAndIpaddressOutputBuilder()
.setExternalIp(fipMap.getExternalIp())
if (ipPortMapping == null) {
LOG.warn("getNatTranslationsForNetworkAndIpaddress : No SNAT IP Mapping found for IP {}", ipAddress);
} else {
- for (IntextIpProtocolType protocolType : ipPortMapping.getIntextIpProtocolType()) {
- for (IpPortMap ipPortMap : protocolType.getIpPortMap()) {
+ for (IntextIpProtocolType protocolType : requireNonNullElse(ipPortMapping.getIntextIpProtocolType(),
+ Collections.<IntextIpProtocolType>emptyList())) {
+ for (IpPortMap ipPortMap : requireNonNullElse(protocolType.getIpPortMap(),
+ Collections.<IpPortMap>emptyList())) {
String[] internalIpPort = ipPortMap.getIpPortInternal().split(NwConstants.MACADDR_SEP);
if (ipAddress.equals(internalIpPort[0])) {
// Capturing SNAT information
List<SnatIpMapping> snatIpMapping = new ArrayList<>();
- for (IntextIpProtocolType protocolType : ipPortMapping.getIntextIpProtocolType()) {
- for (IpPortMap ipPortMap : protocolType.getIpPortMap()) {
+ for (IntextIpProtocolType protocolType : requireNonNullElse(ipPortMapping.getIntextIpProtocolType(),
+ Collections.<IntextIpProtocolType>emptyList())) {
+ for (IpPortMap ipPortMap : requireNonNullElse(protocolType.getIpPortMap(),
+ Collections.<IpPortMap>emptyList())) {
String[] internalPortMap = ipPortMap.getIpPortInternal().split(NwConstants.MACADDR_SEP);
SnatIpMappingBuilder natIpMappingBuilder = new SnatIpMappingBuilder()
.setInternalIp(internalPortMap[0]).setInternalPort(internalPortMap[1])
LOG.warn("constructNatInformation : No DNAT IP Mapping found for router-uuid {}", routerUuid.getValue());
} else {
for (Ports fipPort : fipPorts) {
- List<InternalToExternalPortMap> ipMapping = fipPort.getInternalToExternalPortMap();
- for (InternalToExternalPortMap fipMap : ipMapping) {
+ for (InternalToExternalPortMap fipMap : requireNonNullElse(fipPort.getInternalToExternalPortMap(),
+ Collections.<InternalToExternalPortMap>emptyList())) {
DnatIpMappingBuilder natIpMappingBuilder = new DnatIpMappingBuilder()
.setExternalIp(fipMap.getExternalIp()).setInternalIp(fipMap.getInternalIp());
dnatIpMapping.add(natIpMappingBuilder.build());