//** update or delete the vrfs with the rest of AddressFamilies already present in the last list
AddressFamiliesVrf adfToDel = adfBuilder.build();
- List<AddressFamiliesVrf> adfListOriginal = vrfOriginal.getAddressFamiliesVrf() == null
- ? new ArrayList<>() : vrfOriginal.getAddressFamiliesVrf();
+ List<AddressFamiliesVrf> adfListOriginal = new ArrayList<>(vrfOriginal.nonnullAddressFamiliesVrf());
List<AddressFamiliesVrf> adfListToRemoveFromOriginal = new ArrayList<>();
adfListOriginal.forEach(adf -> {
if (adf.equals(adfToDel)) {
String DEFAULT_DOMAIN_NAME = "openstacklocal";
Uint64 COOKIE_VM_INGRESS_TABLE = Uint64.valueOf("6800001", 16).intern();
- Uint64 INVALID_DPID = Uint64.valueOf("-1").intern();
+ Uint64 INVALID_DPID = Uint64.ZERO;
String DHCP_JOB_KEY_PREFIX = "DHCP_";
int RETRY_COUNT = 6;
}
import javax.inject.Singleton;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
tunnelIpElanNameToVmMacCache.remove(tunnelIpElanNamePair);
}
- @Nullable
+ @NonNull
public Uint64 readDesignatedSwitchesForExternalTunnel(IpAddress tunnelIp, String elanInstanceName) {
if (tunnelIp == null || elanInstanceName == null || elanInstanceName.isEmpty()) {
- return null;
+ return Uint64.ZERO;
}
InstanceIdentifier<DesignatedSwitchForTunnel> instanceIdentifier =
InstanceIdentifier.builder(DesignatedSwitchesForExternalTunnels.class)
if (designatedSwitchForTunnelOptional.isPresent()) {
return Uint64.valueOf(designatedSwitchForTunnelOptional.get().getDpId());
}
- return null;
+ return Uint64.ZERO;
}
public void writeDesignatedSwitchForExternalTunnel(Uint64 dpnId, IpAddress tunnelIp,
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
-import org.opendaylight.genius.mdsalutil.MDSALUtil;
import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
import org.opendaylight.netvirt.dhcpservice.api.DhcpMConstants;
import org.opendaylight.netvirt.dhcpservice.jobs.DhcpInterfaceAddJob;
return;
}
NodeConnectorId nodeConnectorId = new NodeConnectorId(ofportIds.get(0));
- Uint64 dpnId = Uint64.valueOf(MDSALUtil.getDpnIdFromPortName(nodeConnectorId));
+ Uint64 dpnId = DhcpServiceUtils.getDpnIdFromNodeConnectorId(nodeConnectorId);
+
DhcpInterfaceRemoveJob job = new DhcpInterfaceRemoveJob(dhcpManager, dhcpExternalTunnelManager,
dataBroker, del, dpnId, interfaceManager, elanService, port);
jobCoordinator.enqueueJob(DhcpServiceUtils.getJobKey(interfaceName), job, DhcpMConstants.RETRY_COUNT);
return;
}
NodeConnectorId nodeConnectorId = new NodeConnectorId(ofportIds.get(0));
- Uint64 dpnId = Uint64.valueOf(MDSALUtil.getDpnIdFromPortName(nodeConnectorId));
+ Uint64 dpnId = DhcpServiceUtils.getDpnIdFromNodeConnectorId(nodeConnectorId);
String interfaceName = update.getName();
OperStatus updatedOperStatus = update.getOperStatus();
if (original.getOperStatus().equals(OperStatus.Up) && updatedOperStatus.equals(OperStatus.Unknown)) {
dhcpPortCache.put(interfaceName, port);
}
NodeConnectorId nodeConnectorId = new NodeConnectorId(ofportIds.get(0));
- Uint64 dpnId = Uint64.valueOf(MDSALUtil.getDpnIdFromPortName(nodeConnectorId));
+ Uint64 dpnId = DhcpServiceUtils.getDpnIdFromNodeConnectorId(nodeConnectorId);
DhcpInterfaceAddJob job = new DhcpInterfaceAddJob(dhcpManager, dhcpExternalTunnelManager, dataBroker,
add, dpnId, interfaceManager, elanService, itmRpcService);
jobCoordinator.enqueueJob(DhcpServiceUtils.getJobKey(interfaceName), job, DhcpMConstants.RETRY_COUNT);
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServices;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServicesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServicesKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanDpnInterfaces;
connectedDpnIds.remove(dpnId);
}
+ public static Uint64 getDpnIdFromNodeConnectorId(NodeConnectorId nodeConnectorId) {
+ Long dpIdLong = MDSALUtil.getDpnIdFromPortName(nodeConnectorId);
+ return dpIdLong < 0 ? Uint64.ZERO : Uint64.valueOf(dpIdLong);
+ }
}
LOG.trace("DhcpSubnetListener installNeutronPortEntries : portList: {}", portList);
for (Uuid portIntf : portList) {
NodeConnectorId nodeConnectorId = getNodeConnectorIdForPortIntf(portIntf);
- Uint64 dpId = Uint64.valueOf(MDSALUtil.getDpnIdFromPortName(nodeConnectorId));
+ Uint64 dpId = DhcpServiceUtils.getDpnIdFromNodeConnectorId(nodeConnectorId);
String interfaceName = portIntf.getValue();
Port port = dhcpManager.getNeutronPort(interfaceName);
String vmMacAddress = port.getMacAddress().getValue();
LOG.trace("DhcpSubnetListener uninstallNeutronPortEntries : portList: {}", portList);
for (Uuid portIntf : portList) {
NodeConnectorId nodeConnectorId = getNodeConnectorIdForPortIntf(portIntf);
- Uint64 dpId = Uint64.valueOf(MDSALUtil.getDpnIdFromPortName(nodeConnectorId));
+ Uint64 dpId = DhcpServiceUtils.getDpnIdFromNodeConnectorId(nodeConnectorId);
String interfaceName = portIntf.getValue();
Port port = dhcpManager.getNeutronPort(interfaceName);
String vmMacAddress = port.getMacAddress().getValue();
*/
package org.opendaylight.netvirt.dhcpservice;
-import java.math.BigInteger;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
LOG.warn("Unexpected nodeId {}", nodeId.getValue());
return;
}
- Uint64 dpId = Uint64.valueOf(new BigInteger(node[1]));
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION,
- tx -> dhcpManager.setupDefaultDhcpFlows(tx, dpId)), LOG, "Error handling node addition for {}", add);
- dhcpExternalTunnelManager.installDhcpDropActionOnDpn(dpId);
+ try {
+ if (node[1] != null) {
+ Uint64 dpId = Uint64.valueOf(node[1]);
+ ListenableFutures.addErrorLogging(
+ txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION,
+ tx -> dhcpManager.setupDefaultDhcpFlows(tx, dpId)),
+ LOG, "Error handling node addition for {}", add);
+ dhcpExternalTunnelManager.installDhcpDropActionOnDpn(dpId);
+ } else {
+ LOG.error("Unexpected nodeId {} found", nodeId.getValue());
+ }
+ } catch (NumberFormatException ex) {
+ LOG.error("Unexpected nodeId {} found with Exception {} ", nodeId.getValue(),ex.getMessage());
+ }
}
@Override
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
+
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
this.southboundUtils = southboundUtils;
this.random = new Random(System.currentTimeMillis());
this.maxBackoff = elanConfig.getControllerMaxBackoff() != null
- ? elanConfig.getControllerMaxBackoff().toJava() : 0L;
+ ? elanConfig.getControllerMaxBackoff().toJava() : 1000L;
this.inactivityProbe = elanConfig.getControllerInactivityProbe() != null
? elanConfig.getControllerInactivityProbe().toJava() : 0L;
}
return;
}
- List<ManagedNodeEntry> originalManagedNodes = getManagedNodeEntries(originalNode);
- if (originalManagedNodes == null) {
- return;
- }
- List<ManagedNodeEntry> updatedManagedNodes = getManagedNodeEntries(updatedNode);
- if (updatedManagedNodes == null) {
- return;
- }
+ List<ManagedNodeEntry> originalManagedNodes = new ArrayList<>(getManagedNodeEntries(originalNode));
+ List<ManagedNodeEntry> updatedManagedNodes = new ArrayList<>(getManagedNodeEntries(updatedNode));
+
updatedManagedNodes.removeAll(originalManagedNodes);
if (updatedManagedNodes.isEmpty()) {
return;
return null;
}
- return ovsdbNode.getManagedNodeEntry();
+ return ovsdbNode.nonnullManagedNodeEntry();
}
private void prepareIntegrationBridge(Node ovsdbNode, Node brIntNode) {
}
List<String> existingElanInterfaces = elanState.getElanInterfaces();
List<String> elanInterfaces = new ArrayList<>();
- existingElanInterfaces.forEach(iface -> elanInterfaces.add(iface));
- boolean isRemoved = elanInterfaces != null && elanInterfaces.remove(interfaceName);
+ if (existingElanInterfaces != null) {
+ elanInterfaces.addAll(existingElanInterfaces);
+ }
+ boolean isRemoved = elanInterfaces.remove(interfaceName);
if (!isRemoved) {
return elanState;
}
try {
DpnInterfaces dpnInterfaces = elanUtils.getElanInterfaceInfoByElanDpn(elanName, dpId);
if (dpnInterfaces != null) {
- List<String> interfaceLists = dpnInterfaces.getInterfaces();
+ List<String> interfaceLists = null;
+ if (dpnInterfaces.getInterfaces() != null) {
+ interfaceLists = new ArrayList<>(dpnInterfaces.getInterfaces());
+ }
if (interfaceLists != null) {
interfaceLists.remove(interfaceName);
}
return;
}
NodeConnectorId nodeConnectorId = new NodeConnectorId(delIf.getLowerLayerIf().get(0));
- Uint64 dpId = Uint64.valueOf(MDSALUtil.getDpnIdFromPortName(nodeConnectorId));
+ Long dpIdLong = MDSALUtil.getDpnIdFromPortName(nodeConnectorId);
+ Uint64 dpId = dpIdLong < 0 ? Uint64.ZERO : Uint64.valueOf(dpIdLong);
InterfaceInfo interfaceInfo = new InterfaceInfo(dpId, nodeConnectorId.getValue());
interfaceInfo.setInterfaceName(interfaceName);
interfaceInfo.setInterfaceType(InterfaceInfo.InterfaceType.VLAN_INTERFACE);
}
private static boolean isInternalTunnel(StateTunnelList stateTunnelList) {
- return stateTunnelList.getDstInfo().getTepDeviceType() == TepTypeInternal.class;
+ return stateTunnelList.getDstInfo() != null
+ ? stateTunnelList.getDstInfo().getTepDeviceType() == TepTypeInternal.class : false;
}
}
LocatorSet tobeDeleted = buildLocatorSet(dstNodeId, removedDstTep);
RemoteMcastMacsBuilder newMacBuilder = new RemoteMcastMacsBuilder(existingMac);
- List<LocatorSet> existingLocatorList = newMacBuilder.getLocatorSet();
- List<LocatorSet> locatorList = new ArrayList<>();
- existingLocatorList.forEach(locatorSet -> locatorList.add(locatorSet));
+ List<LocatorSet> locatorList = new ArrayList<>(existingMac.nonnullLocatorSet());
locatorList.remove(tobeDeleted);
newMacBuilder.setLocatorSet(locatorList);
RemoteMcastMacs mac = newMacBuilder.build();
.child(LabelRouteInfo.class, new LabelRouteInfoKey(lri.getLabel())).build();
List<String> vpnInstancesList = lri.getVpnInstanceList() != null
- ? lri.getVpnInstanceList() : new ArrayList<>();
+ ? new ArrayList<>(lri.getVpnInstanceList()) : new ArrayList<>();
if (vpnInstancesList.contains(vpnInstanceName)) {
LOG.debug("vpninstance {} name is present", vpnInstanceName);
vpnInstancesList.remove(vpnInstanceName);
MDSALUtil.buildFlowEntity(destDpId, NwConstants.INTERNAL_TUNNEL_TABLE,
getTableMissFlowRef(destDpId, NwConstants.INTERNAL_TUNNEL_TABLE, label),
FibConstants.DEFAULT_VPN_INTERNAL_TUNNEL_TABLE_PRIORITY,
- String.format("%s:%d", "TST Flow Entry ", label), 0, 0,
+ String.format("%s:%s", "TST Flow Entry ", label), 0, 0,
Uint64.valueOf(COOKIE_TUNNEL.longValue() + label.longValue()),
mkMatches, mkInstructions);
NwConstants.INTERNAL_TUNNEL_TABLE,
getTableMissFlowRef(dpId, NwConstants.INTERNAL_TUNNEL_TABLE, label),
FibConstants.DEFAULT_VPN_INTERNAL_TUNNEL_TABLE_PRIORITY,
- String.format("%s:%d", "TST Flow Entry ", label), 0, 0,
+ String.format("%s:%s", "TST Flow Entry ", label), 0, 0,
Uint64.valueOf(COOKIE_TUNNEL.longValue() + label.longValue()), mkMatches, null);
Node nodeDpn = FibUtil.buildDpnNode(flowEntity.getDpnId());
FlowKey flowKey = new FlowKey(new FlowId(flowEntity.getFlowId()));
if (null != iface) {
LOG.debug("Port {} is a Neutron port", iface.getName());
NodeConnectorId nodeConnectorId = new NodeConnectorId(ofportIds.get(0));
- Uint64 dpId = Uint64.valueOf(MDSALUtil.getDpnIdFromPortName(nodeConnectorId));
+ Uint64 dpId = Ipv6ServiceUtils.getDpnIdFromNodeConnectorId(nodeConnectorId);
if (!dpId.equals(Ipv6ServiceConstants.INVALID_DPID)) {
Uuid portId = new Uuid(iface.getName());
short DEFAULT_FLOW_PRIORITY = 50;
short PUNT_NA_FLOW_PRIORITY = 40;
- Uint64 INVALID_DPID = Uint64.valueOf("-1").intern();
+ Uint64 INVALID_DPID = Uint64.ZERO;
String FLOWID_PREFIX = "IPv6.";
String FLOWID_SEPARATOR = ".";
List<String> ofportIds = interfaceState.getLowerLayerIf();
if (ofportIds != null && !ofportIds.isEmpty()) {
NodeConnectorId nodeConnectorId = new NodeConnectorId(ofportIds.get(0));
- dpId = Uint64.valueOf(MDSALUtil.getDpnIdFromPortName(nodeConnectorId));
+ dpId = getDpnIdFromNodeConnectorId(nodeConnectorId);
}
return dpId;
}
+ public static Uint64 getDpnIdFromNodeConnectorId(NodeConnectorId nodeConnectorId) {
+ Long dpIdLong = MDSALUtil.getDpnIdFromPortName(nodeConnectorId);
+ return dpIdLong < 0 ? Uint64.ZERO : Uint64.valueOf(dpIdLong);
+ }
+
public static long getRemoteBCGroup(long elanTag) {
return Ipv6ServiceConstants.ELAN_GID_MIN + elanTag % Ipv6ServiceConstants.ELAN_GID_MIN * 2;
}
Flow terminatingServiceTableFlowEntity = MDSALUtil.buildFlowNew(NwConstants.INTERNAL_TUNNEL_TABLE,
NatEvpnUtil.getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, l3Vni, NatConstants.DNAT_FLOW_NAME),
NatConstants.DEFAULT_VPN_INTERNAL_TUNNEL_TABLE_PRIORITY + 1,
- String.format("%s:%d", "TST Flow Entry ", l3Vni),
+ String.format("%s:%s", "TST Flow Entry ", l3Vni),
0, 0,
Uint64.valueOf(COOKIE_TUNNEL.toJava().add(BigInteger.valueOf(l3Vni.longValue()))),
mkMatches, customInstructions);
Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.INTERNAL_TUNNEL_TABLE,
NatEvpnUtil.getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, l3Vni, NatConstants.DNAT_FLOW_NAME),
NatConstants.DEFAULT_VPN_INTERNAL_TUNNEL_TABLE_PRIORITY + 1,
- String.format("%s:%d", "TST Flow Entry ", l3Vni), 0, 0,
+ String.format("%s:%s", "TST Flow Entry ", l3Vni), 0, 0,
Uint64.valueOf(COOKIE_TUNNEL.toJava().add(BigInteger.valueOf(l3Vni.longValue()))),
mkMatches, null);
mdsalManager.removeFlow(confTx, dpnId, flowEntity);
Flow terminatingServiceTableFlowEntity = MDSALUtil.buildFlowNew(NwConstants.INTERNAL_TUNNEL_TABLE,
NatEvpnUtil.getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, l3Vni, NatConstants.SNAT_FLOW_NAME),
NatConstants.DEFAULT_VPN_INTERNAL_TUNNEL_TABLE_PRIORITY,
- String.format("%s:%d", "TST Flow Entry ", l3Vni),
+ String.format("%s:%s", "TST Flow Entry ", l3Vni),
0, 0, Uint64.valueOf(COOKIE_TUNNEL.toJava().add(BigInteger.valueOf(l3Vni.longValue()))),
mkMatches, customInstructions);
mdsalManager.addFlow(confTx, dpnId, terminatingServiceTableFlowEntity);
Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.INTERNAL_TUNNEL_TABLE,
NatEvpnUtil.getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, l3Vni, NatConstants.SNAT_FLOW_NAME),
NatConstants.DEFAULT_VPN_INTERNAL_TUNNEL_TABLE_PRIORITY,
- String.format("%s:%d", "TST Flow Entry ", l3Vni), 0, 0,
+ String.format("%s:%s", "TST Flow Entry ", l3Vni), 0, 0,
Uint64.valueOf(COOKIE_TUNNEL.toJava().add(BigInteger.valueOf(l3Vni.longValue()))), mkMatches, null);
mdsalManager.removeFlow(confTx, dpnId, flowEntity);
LOG.debug("removeTunnelTableEntry : Successfully removed terminating service table flow {} on DpnId {}",
Flow terminatingServiceTableFlowEntity = MDSALUtil.buildFlowNew(NwConstants.INTERNAL_TUNNEL_TABLE,
getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, serviceId, ""),
NatConstants.DEFAULT_VPN_INTERNAL_TUNNEL_TABLE_PRIORITY,
- String.format("%s:%d", "TST Flow Entry ", serviceId), 0, 0,
+ String.format("%s:%s", "TST Flow Entry ", serviceId), 0, 0,
Uint64.valueOf(COOKIE_TUNNEL.toJava().add(BigInteger.valueOf(serviceId.longValue()))),
mkMatches, customInstructions);
}
private void hndlTepEvntsForDpn(StateTunnelList stateTunnelList, TunnelAction tunnelAction) {
- final Uint64 srcDpnId = Uint64.valueOf(stateTunnelList.getSrcInfo().getTepDeviceId());
- final String srcTepIp = stateTunnelList.getSrcInfo().getTepIp().stringValue();
- final String destTepIp = stateTunnelList.getDstInfo().getTepIp().stringValue();
+ LOG.trace("hndlTepEvntsForDpn : stateTunnelList {}", stateTunnelList);
+ final Uint64 srcDpnId = stateTunnelList.getSrcInfo() != null
+ ? Uint64.valueOf(stateTunnelList.getSrcInfo().getTepDeviceId()) : Uint64.ZERO;
+ final String srcTepIp = stateTunnelList.getSrcInfo() != null
+ ? stateTunnelList.getSrcInfo().getTepIp().stringValue() : null;
+ final String destTepIp = stateTunnelList.getDstInfo() != null
+ ? stateTunnelList.getDstInfo().getTepIp().stringValue() : null;
LOG.trace("hndlTepEvntsForDpn : Handle tunnel event for srcDpn {} SrcTepIp {} DestTepIp {} ",
srcDpnId, srcTepIp, destTepIp);
+ if (srcDpnId == Uint64.ZERO || srcTepIp == null || destTepIp == null) {
+ LOG.error("hndlTepEvntsForDpn invalid srcDpnId {}, srcTepIp {}, destTepIp {}",
+ srcDpnId, srcTepIp, destTepIp);
+ return;
+ }
int tunTypeVal = getTunnelType(stateTunnelList);
LOG.trace("hndlTepEvntsForDpn : tunTypeVal is {}", tunTypeVal);
- String srcTepId = stateTunnelList.getSrcInfo().getTepDeviceId();
- String tunnelType = stateTunnelList.getTransportType().toString();
+ String srcTepId = stateTunnelList.getSrcInfo().getTepDeviceId() != null
+ ? stateTunnelList.getSrcInfo().getTepDeviceId() : "0";
+ String tunnelType = stateTunnelList.getTransportType() != null
+ ? stateTunnelList.getTransportType().toString() : null;
String tunnelName = stateTunnelList.getTunnelInterfaceName();
- if (tunTypeVal == NatConstants.ITMTunnelLocType.Invalid.getValue()) {
+ if (tunTypeVal == NatConstants.ITMTunnelLocType.Invalid.getValue() || srcDpnId.equals(Uint64.ZERO)
+ || srcTepIp == null || destTepIp == null) {
LOG.warn("hndlTepEvntsForDpn : Ignoring TEP event {} for the DPN {} "
+ "since its a INVALID TUNNEL TYPE {} b/w SRC IP {} and DST IP {} and " + "TUNNEL NAME {} ",
tunnelAction, srcTepId, tunnelType, srcTepIp, destTepIp, tunnelName);
@NonNull
public static List<Uint16> getInternalIpPortListInfo(DataBroker dataBroker, Uint32 routerId,
String internalIpAddress, ProtocolTypes protocolType) {
- return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
+ List<Uint16> portList = SingleTransactionDataBroker
+ .syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
LogicalDatastoreType.CONFIGURATION,
- buildSnatIntIpPortIdentifier(routerId, internalIpAddress, protocolType)).toJavaUtil().map(
+ buildSnatIntIpPortIdentifier(routerId, internalIpAddress, protocolType)).toJavaUtil().map(
IntIpProtoType::getPorts).orElse(emptyList());
+
+ if (!portList.isEmpty()) {
+ portList = new ArrayList<>(portList);
+ }
+ return portList;
}
public static InstanceIdentifier<IntIpProtoType> buildSnatIntIpPortIdentifier(Uint32 routerId,
if (optionalRouterDpnList.isPresent()) {
List<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns
.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces> routerInterfaces =
- optionalRouterDpnList.get().getRouterInterfaces();
+ new ArrayList<>(optionalRouterDpnList.get().nonnullRouterInterfaces());
org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn
.list.dpn.vpninterfaces.list.RouterInterfaces routerInterface =
new RouterInterfacesBuilder().withKey(new RouterInterfacesKey(vpnInterfaceName))
public static List<Uuid> getSubnetIdsFromNetworkId(DataBroker broker, Uuid networkId) {
InstanceIdentifier<NetworkMap> id = InstanceIdentifier.builder(NetworkMaps.class)
.child(NetworkMap.class, new NetworkMapKey(networkId)).build();
- return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
- LogicalDatastoreType.CONFIGURATION, id).toJavaUtil().map(NetworkMap::getSubnetIdList).orElse(
+ List<Uuid> subnetIdList = SingleTransactionDataBroker
+ .syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
+ LogicalDatastoreType.CONFIGURATION, id).toJavaUtil().map(NetworkMap::getSubnetIdList).orElse(
emptyList());
+ if (!subnetIdList.isEmpty()) {
+ subnetIdList = new ArrayList<>(subnetIdList);
+ }
+
+ return subnetIdList;
}
@Nullable
@NonNull
public static List<Ports> getFloatingIpPortsForRouter(DataBroker broker, Uuid routerUuid) {
InstanceIdentifier<RouterPorts> routerPortsIdentifier = getRouterPortsId(routerUuid.getValue());
- return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker,
- LogicalDatastoreType.CONFIGURATION,
+ List<Ports> portsList = SingleTransactionDataBroker
+ .syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.CONFIGURATION,
routerPortsIdentifier).toJavaUtil().map(RouterPorts::getPorts).orElse(emptyList());
+ if (!portsList.isEmpty()) {
+ portsList = new ArrayList<>(portsList);
+ }
+ return portsList;
}
@NonNull
for (Networks externalNw : externalNwData.get().nonnullNetworks()) {
if (externalNw.getVpnid() != null && externalNw.getVpnid().equals(vpnUuid)) {
@Nullable List<Uuid> routerIds = externalNw.getRouterIds();
- return routerIds != null ? routerIds : emptyList();
+ return routerIds != null ? new ArrayList<>(routerIds) : emptyList();
}
}
}
try {
Optional<DpnInterfaces> dpnInElanInterfaces = SingleTransactionDataBroker.syncReadOptional(dataBroker,
LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId);
- List<String> elanInterfaceList;
+ List<String> elanInterfaceList = new ArrayList<>();
DpnInterfaces dpnInterface;
- if (!dpnInElanInterfaces.isPresent()) {
- elanInterfaceList = new ArrayList<>();
- } else {
+ if (dpnInElanInterfaces.isPresent()) {
dpnInterface = dpnInElanInterfaces.get();
- elanInterfaceList = dpnInterface.getInterfaces();
+
+ elanInterfaceList = (dpnInterface.getInterfaces() != null && !dpnInterface.getInterfaces().isEmpty())
+ ? new ArrayList<>(dpnInterface.getInterfaces()) : elanInterfaceList;
}
if (!elanInterfaceList.contains(pseudoPortId)) {
elanInterfaceList.add(pseudoPortId);
try {
Optional<DpnInterfaces> dpnInElanInterfaces = SingleTransactionDataBroker.syncReadOptional(dataBroker,
LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId);
- List<String> elanInterfaceList;
+ List<String> elanInterfaceList = new ArrayList<>();
DpnInterfaces dpnInterface;
if (!dpnInElanInterfaces.isPresent()) {
LOG.info("No interface in any dpn for {}", elanInstanceName);
}
dpnInterface = dpnInElanInterfaces.get();
- elanInterfaceList = dpnInterface.getInterfaces();
+ elanInterfaceList = (dpnInterface.getInterfaces() != null && !dpnInterface.getInterfaces().isEmpty())
+ ? new ArrayList<>(dpnInterface.getInterfaces()) : elanInterfaceList;
if (!elanInterfaceList.contains(pseudoPortId)) {
LOG.info("Router port not present in DPN {} for VPN {}", dpnId, elanInstanceName);
return;
Flow terminatingServiceTableFlowEntity = MDSALUtil.buildFlowNew(NwConstants.INTERNAL_TUNNEL_TABLE,
getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, serviceId, ""), flowPriority,
- String.format("%s:%d", "TST Flow Entry ", serviceId),
+ String.format("%s:%s", "TST Flow Entry ", serviceId),
0, 0, Uint64.valueOf(COOKIE_TUNNEL.add(BigInteger.valueOf(serviceId.longValue()))),
mkMatches, customInstructions);
importRouteTargets.addAll(inputImportRouteSet);
exportRouteTargets.addAll(inputExportRouteSet);
- List<String> rd = input.getRouteDistinguishers();
+ List<String> rd = input.getRouteDistinguishers() != null
+ ? input.getRouteDistinguishers() : new ArrayList<>();
if (rd == null || rd.isEmpty()) {
// generate new RD
routerPortsBuilder.setExternalNetworkId(extNetworkId);
}
if (fixedNeutronPortName != null) {
- List<Ports> portsList = routerPortsBuilder.getPorts();
- if (portsList == null) {
- portsList = new ArrayList<>();
- }
+ List<Ports> portsList = routerPortsBuilder.getPorts() != null
+ ? new ArrayList<>(routerPortsBuilder.getPorts()) : new ArrayList<>();
PortsBuilder fixedNeutronPortBuilder = null;
for (Ports neutronPort : portsList) {
if (neutronPort.getPortName().equals(fixedNeutronPortName)) {
}
InternalToExternalPortMap intExtPortMap = new InternalToExternalPortMapBuilder().withKey(new
InternalToExternalPortMapKey(fixedIpAddress)).setInternalIp(fixedIpAddress)
- .setExternalIp(floatingIpAddress).setExternalId(floatingIpId).setLabel(0L).build();
+ .setExternalIp(floatingIpAddress).setExternalId(floatingIpId).build();
intExtPortMapList.add(intExtPortMap);
fixedNeutronPortBuilder.setInternalToExternalPortMap(intExtPortMapList);
}
if (vpnId == null) {
vpnId = routerId;
}
- List<Routes> oldRoutes = original.getRoutes() != null ? original.getRoutes() : new ArrayList<>();
- List<Routes> newRoutes = update.getRoutes() != null ? update.getRoutes() : new ArrayList<>();
+ List<Routes> oldRoutes = new ArrayList<>(original.nonnullRoutes());
+ List<Routes> newRoutes = new ArrayList<>(update.nonnullRoutes());
if (!oldRoutes.equals(newRoutes)) {
Iterator<Routes> iterator = newRoutes.iterator();
while (iterator.hasNext()) {
if (sn.isPresent()) {
SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
if (null != portId) {
- List<Uuid> portList = builder.getPortList();
- if (null == portList) {
- portList = new ArrayList<>();
+ List<Uuid> existingPortList = builder.getPortList();
+ List<Uuid> portList = new ArrayList<>();
+ if (null != existingPortList) {
+ portList.addAll(existingPortList);
}
portList.add(portId);
builder.setPortList(portList);
}
builder.setInternetVpnId(null);
if (portId != null && builder.getPortList() != null) {
- List<Uuid> portList = builder.getPortList();
+ List<Uuid> portList = new ArrayList<>(builder.getPortList());
portList.remove(portId);
builder.setPortList(portList);
}
id);
if (sn.isPresent()) {
SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
- if (null != portId && null != builder.getPortList()) {
- List<Uuid> portList = builder.getPortList();
+ if (null != portId && null != builder.getPortList() && !builder.getPortList().isEmpty()) {
+ List<Uuid> portList = new ArrayList<>(builder.getPortList());
portList.remove(portId);
builder.setPortList(portList);
LOG.debug("Removing port {} from existing subnetmap node: {} ", portId.getValue(),
subnetId.getValue());
}
- if (null != directPortId && null != builder.getDirectPortList()) {
- List<Uuid> directPortList = builder.getDirectPortList();
+ if (null != directPortId && null != builder.getDirectPortList()
+ && !builder.getDirectPortList().isEmpty()) {
+ List<Uuid> directPortList = new ArrayList<>(builder.getDirectPortList());
directPortList.remove(directPortId);
builder.setDirectPortList(directPortList);
LOG.debug("Removing direct port {} from existing subnetmap node: {} ", directPortId
}
if (router != null) {
RouterIds vpnRouterId = new RouterIdsBuilder().setRouterId(router).build();
- List<RouterIds> rtrIds = builder.getRouterIds();
+ List<RouterIds> rtrIds = builder.getRouterIds() != null
+ ? new ArrayList<>(builder.getRouterIds()) : null;
if (rtrIds == null) {
rtrIds = Collections.singletonList(vpnRouterId);
} else {
builder.setRouterIds(rtrIds);
}
if (networks != null) {
- List<Uuid> nwList = builder.getNetworkIds();
- if (nwList == null) {
- nwList = new ArrayList<>();
- }
+ List<Uuid> nwList = builder.getNetworkIds() != null
+ ? new ArrayList<>(builder.getNetworkIds()) : new ArrayList<>();
nwList.addAll(networks);
builder.setNetworkIds(nwList);
}
if (optionalVpnMap.isPresent()) {
VpnMap vpnMap = optionalVpnMap.get();
VpnMapBuilder vpnMapBuilder = new VpnMapBuilder(vpnMap);
- List<RouterIds> rtrIds = vpnMap.getRouterIds();
+ List<RouterIds> rtrIds = new ArrayList<>(vpnMap.nonnullRouterIds());
if (rtrIds == null) {
rtrIds = new ArrayList<>();
}
}
}
if (networkIds != null) {
- List<Uuid> vpnNw = vpnMap.getNetworkIds();
+ List<Uuid> vpnNw = vpnMap.getNetworkIds() != null
+ ? new ArrayList<>(vpnMap.getNetworkIds()) : new ArrayList<>();
vpnNw.removeAll(networkIds);
if (vpnNw.isEmpty()) {
LOG.debug("setting networks null in vpnMaps node: {} ", vpnId.getValue());
+ "routerIdList {}, networksList {}", vpn.getId().getValue(), vpn.getName(),
vpn.getTenantId(), vpn.getRouteDistinguisher().toString(), vpn.getImportRT().toString(),
vpn.getExportRT().toString(), rtrIdsList, vpn.getNetworkIds());
- createVpn(vpn.getId(), vpn.getName(), vpn.getTenantId(), vpn.getRouteDistinguisher(),
- vpn.getImportRT(), vpn.getExportRT(), rtrIdsList, vpn.getNetworkIds(),
- vpnInstanceType, l3vni);
+
+ List<String> rdList = vpn.getRouteDistinguisher() != null
+ ? new ArrayList<>(vpn.getRouteDistinguisher()) : new ArrayList<>();
+ List<String> importRdList = vpn.getImportRT() != null
+ ? new ArrayList<>(vpn.getImportRT()) : new ArrayList<>();
+ List<String> exportRdList = vpn.getExportRT() != null
+ ? new ArrayList<>(vpn.getExportRT()) : new ArrayList<>();
+
+ createVpn(vpn.getId(), vpn.getName(), vpn.getTenantId(), rdList,
+ importRdList, exportRdList, rtrIdsList, vpn.getNetworkIds(), vpnInstanceType, l3vni);
} catch (Exception ex) {
+ LOG.error("VPN Creation exception :", ex);
errorList.add(RpcResultBuilder.newError(ErrorType.APPLICATION,
formatAndLog(LOG::error, "Creation of VPN failed for VPN {}", vpn.getId().getValue(), ex),
ex.getMessage()));
vpnIdentifier);
// eliminating implicitly created (router or VLAN provider external network specific) VPN from
// getL3VPN output
- if (optionalVpn.isPresent() && optionalVpn.get().getIpv4Family().getRouteDistinguisher() != null
- || optionalVpn.get().getIpv6Family().getRouteDistinguisher() != null) {
+ if (optionalVpn.isPresent() && (optionalVpn.get().getIpv4Family().getRouteDistinguisher() != null
+ || optionalVpn.get().getIpv6Family().getRouteDistinguisher() != null)) {
vpns.add(optionalVpn.get());
} else {
result.set(
.setInterfaceId(interfaceName).build();
if (optRouterInterfaces.isPresent()) {
RouterInterfaces routerInterfaces = optRouterInterfaces.get();
- List<Interfaces> interfaces = routerInterfaces.getInterfaces();
+ List<Interfaces> interfaces = new ArrayList<>(routerInterfaces.nonnullInterfaces());
if (interfaces != null && interfaces.remove(routerInterface)) {
if (interfaces.isEmpty()) {
SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION,
result.set(RpcResultBuilder.<AssociateNetworksOutput>success().build());
}
} catch (Exception ex) {
+ LOG.error("associate Networks to vpn failed {}", input.getVpnId().getValue(), ex);
result.set(RpcResultBuilder.<AssociateNetworksOutput>failed().withError(ErrorType.APPLICATION,
formatAndLog(LOG::error, "associate Networks to vpn {} failed due to {}",
input.getVpnId().getValue(), ex.getMessage(), ex)).build());
if (origExtGw.getExternalFixedIps() != null) {
if (!origExtGw.getExternalFixedIps().isEmpty()) {
if (newExtGw.getExternalFixedIps() != null && !newExtGw.getExternalFixedIps().isEmpty()) {
- List<ExternalFixedIps> origExtFixedIps = origExtGw.getExternalFixedIps();
+ List<ExternalFixedIps> origExtFixedIps = new ArrayList<>(origExtGw.nonnullExternalFixedIps());
HashSet<String> origFixedIpSet = new HashSet<>();
for (ExternalFixedIps fixedIps : origExtFixedIps) {
origFixedIpSet.add(fixedIps.getIpAddress().stringValue());
}
- List<ExternalFixedIps> newExtFixedIps = newExtGw.getExternalFixedIps();
+ List<ExternalFixedIps> newExtFixedIps = new ArrayList<>(newExtGw.nonnullExternalFixedIps());
HashSet<String> updFixedIpSet = new HashSet<>();
for (ExternalFixedIps fixedIps : newExtFixedIps) {
updFixedIpSet.add(fixedIps.getIpAddress().stringValue());
return;
}
NetworksBuilder builder = new NetworksBuilder(optionalNets.get());
- List<Uuid> rtrList = builder.getRouterIds();
- if (rtrList == null) {
- rtrList = new ArrayList<>();
- }
+ List<Uuid> rtrList = (builder.getRouterIds() != null && !builder.getRouterIds().isEmpty())
+ ? new ArrayList<>(builder.getRouterIds()) : new ArrayList<>();
rtrList.add(routerId);
builder.setRouterIds(rtrList);
if (NeutronvpnUtils.isFlatOrVlanNetwork(input)) {
Networks nets = optionalNets.get();
try {
NetworksBuilder builder = new NetworksBuilder(nets);
- List<Uuid> rtrList = builder.getRouterIds();
+ List<Uuid> rtrList = new ArrayList<>();
+ rtrList = builder.getRouterIds() != null ? new ArrayList<>(builder.getRouterIds()) : rtrList;
if (rtrList != null) {
rtrList.remove(routerId);
builder.setRouterIds(rtrList);
if (optionalExternalSubnets.isPresent()) {
Subnets subnets = optionalExternalSubnets.get();
List<Uuid> routerIds;
- if (subnets.getRouterIds() != null) {
- routerIds = subnets.getRouterIds();
+ if (subnets.getRouterIds() != null && !subnets.getRouterIds().isEmpty()) {
+ routerIds = new ArrayList<>(subnets.getRouterIds());
} else {
routerIds = new ArrayList<>();
}
List<Subnets> fixedIpsSubnets = getSubnets(getExternalSubnetsUuidsSetForFixedIps(externalFixedIps));
for (Subnets subnets : fixedIpsSubnets) {
Uuid subnetId = subnets.getId();
- List<Uuid> routerIds = subnets.getRouterIds();
+ List<Uuid> routerIds = new ArrayList<>();
+ routerIds = subnets.getRouterIds() != null ? new ArrayList<>(subnets.getRouterIds()) : routerIds;
if (routerIds != null) {
if (subnets.getExternalNetworkId() != null
&& subnets.getExternalNetworkId().equals(externalNetworkId)
protected Uuid getVpnForNetwork(Uuid network) {
InstanceIdentifier<VpnMaps> vpnMapsIdentifier = InstanceIdentifier.builder(VpnMaps.class).build();
Optional<VpnMaps> optionalVpnMaps = read(LogicalDatastoreType.CONFIGURATION, vpnMapsIdentifier);
- if (optionalVpnMaps.isPresent() && optionalVpnMaps.get().getVpnMap() != null) {
- for (VpnMap vpnMap : optionalVpnMaps.get().nonnullVpnMap()) {
+ if (optionalVpnMaps.isPresent() && optionalVpnMaps.get().nonnullVpnMap() != null) {
+ for (VpnMap vpnMap : new ArrayList<>(optionalVpnMaps.get().nonnullVpnMap())) {
List<Uuid> netIds = vpnMap.getNetworkIds();
if (netIds != null && netIds.contains(network)) {
return vpnMap.getVpnId();
InstanceIdentifier<VpnMaps> vpnMapsIdentifier = InstanceIdentifier.builder(VpnMaps.class).build();
Optional<VpnMaps> optionalVpnMaps = read(LogicalDatastoreType.CONFIGURATION, vpnMapsIdentifier);
- if (optionalVpnMaps.isPresent() && optionalVpnMaps.get().getVpnMap() != null) {
- for (VpnMap vpnMap : optionalVpnMaps.get().nonnullVpnMap()) {
+ if (optionalVpnMaps.isPresent() && optionalVpnMaps.get().nonnullVpnMap() != null) {
+ for (VpnMap vpnMap : new ArrayList<>(optionalVpnMaps.get().nonnullVpnMap())) {
List<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap
.RouterIds> routerIdsList = vpnMap.getRouterIds();
if (routerIdsList == null || routerIdsList.isEmpty()) {
Optional<VpnMap> optionalVpnMap = read(LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
if (optionalVpnMap.isPresent()) {
VpnMap vpnMap = optionalVpnMap.get();
- return vpnMap.getNetworkIds();
+ if (vpnMap.getNetworkIds() != null && !vpnMap.getNetworkIds().isEmpty()) {
+ return new ArrayList<>(vpnMap.getNetworkIds());
+ } else {
+ return null;
+ }
}
LOG.error("getNetworksforVpn: Failed as VPNMaps DS is absent for VPN {}", vpnId.getValue());
return null;
continue;
}
try {
- neutronvpnManager.createVpn(vpn.getId(), vpn.getName(), vpn.getTenantId(), vpn.getRouteDistinguisher(),
- vpn.getImportRT(), vpn.getExportRT(), null /*router-id*/, null /*network-id*/,
+ List<String> rdList = vpn.getRouteDistinguisher() != null
+ ? new ArrayList<>(vpn.getRouteDistinguisher()) : new ArrayList<>();
+ List<String> importRdList = vpn.getImportRT() != null
+ ? new ArrayList<>(vpn.getImportRT()) : new ArrayList<>();
+ List<String> exportRdList = vpn.getExportRT() != null
+ ? new ArrayList<>(vpn.getExportRT()) : new ArrayList<>();
+ neutronvpnManager.createVpn(vpn.getId(), vpn.getName(), vpn.getTenantId(), rdList,
+ importRdList, exportRdList, null /*router-id*/, null /*network-id*/,
vpnInstanceType, 0 /*l2vni*/);
} catch (Exception ex) {
errorList.add(RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION,
.interfaces.rev140508.interfaces.state.Interface ifState) {
String lowerLayerIf = ifState.getLowerLayerIf().get(0);
NodeConnectorId nodeConnectorId = new NodeConnectorId(lowerLayerIf);
- return Uint64.valueOf(MDSALUtil.getDpnIdFromPortName(nodeConnectorId));
+ Long dpIdLong = MDSALUtil.getDpnIdFromPortName(nodeConnectorId);
+ Uint64 dpnId = dpIdLong < 0 ? Uint64.ZERO : Uint64.valueOf(dpIdLong);
+ return dpnId;
}
public Uint64 getDpnForInterface(String ifName) {
subDpn = optionalSubDpn.get();
}
SubnetToDpnBuilder subDpnBuilder = new SubnetToDpnBuilder(subDpn);
- List<VpnInterfaces> vpnIntfList = subDpnBuilder.getVpnInterfaces();
+ List<VpnInterfaces> vpnIntfList = new ArrayList<>();
+ vpnIntfList = subDpnBuilder.getVpnInterfaces() != null ? new ArrayList<>(subDpnBuilder.getVpnInterfaces())
+ : vpnIntfList;
+
VpnInterfaces vpnIntfs =
new VpnInterfacesBuilder().withKey(new VpnInterfacesKey(intfName)).setInterfaceName(intfName).build();
vpnIntfList.add(vpnIntfs);
listSubnet.add(subnetId);
portOpBuilder.setSubnetIds(listSubnet);
} else {
- List<Uuid> listSubnet = optionalPortOp.get().getSubnetIds();
+ PortOpDataEntry portEntry = optionalPortOp.get();
+ List<Uuid> listSubnet = new ArrayList<>();
+ listSubnet = (portEntry.getSubnetIds() != null && !portEntry.getSubnetIds().isEmpty())
+ ? new ArrayList<>(portEntry.getSubnetIds()) : listSubnet;
portOpBuilder = new PortOpDataEntryBuilder(optionalPortOp.get());
if (listSubnet == null) {
listSubnet = new ArrayList<>();
}
SubnetToDpnBuilder subDpnBuilder = new SubnetToDpnBuilder(optionalSubDpn.get());
- List<VpnInterfaces> vpnIntfList = subDpnBuilder.getVpnInterfaces();
+ List<VpnInterfaces> vpnIntfList = new ArrayList<>();
+ vpnIntfList = (subDpnBuilder.getVpnInterfaces() != null && !subDpnBuilder.getVpnInterfaces().isEmpty())
+ ? new ArrayList<>(subDpnBuilder.getVpnInterfaces()) : vpnIntfList;
VpnInterfaces vpnIntfs =
new VpnInterfacesBuilder().withKey(new VpnInterfacesKey(intfName)).setInterfaceName(intfName).build();
vpnIntfList.remove(vpnIntfs);
intfName);
} else {
portOpEntry = optionalPortOp.get();
- List<Uuid> listSubnet = portOpEntry.getSubnetIds();
+ List<Uuid> listSubnet = new ArrayList<>();
+ listSubnet = (portOpEntry.getSubnetIds() != null && !portOpEntry.getSubnetIds().isEmpty())
+ ? new ArrayList<>(portOpEntry.getSubnetIds()) : listSubnet;
if (listSubnet == null) {
listSubnet = new ArrayList<>();
}
programDcGwLoadBalancingGroup(add, NwConstants.ADD_FLOW, isTunnelUp);
}
LOG.info("add: ITM Tunnel ,type {} ,added between src: {} and dest: {}",
- fibManager.getTransportTypeStr(add.getTransportType().toString()),
- add.getSrcInfo().getTepDeviceId(), add.getDstInfo().getTepDeviceId());
+ fibManager.getTransportTypeStr(add.getTransportType() != null
+ ? add.getTransportType().toString() : "Invalid"),
+ add.getSrcInfo() != null ? add.getSrcInfo().getTepDeviceId() : "0",
+ add.getDstInfo() != null ? add.getDstInfo().getTepDeviceId() : "0");
handleTunnelEventForDPN(add, TunnelAction.TUNNEL_EP_ADD);
}
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void handleTunnelEventForDPN(StateTunnelList stateTunnelList, TunnelAction tunnelAction) {
- final Uint64 srcDpnId = Uint64.valueOf(stateTunnelList.getSrcInfo().getTepDeviceId()).intern();
- final String srcTepIp = stateTunnelList.getSrcInfo().getTepIp().stringValue();
- String destTepIp = stateTunnelList.getDstInfo().getTepIp().stringValue();
+ final Uint64 srcDpnId = stateTunnelList.getSrcInfo() != null
+ ? Uint64.valueOf(stateTunnelList.getSrcInfo().getTepDeviceId()).intern() : Uint64.ZERO;
+ final String srcTepIp = stateTunnelList.getSrcInfo() != null
+ ? stateTunnelList.getSrcInfo().getTepIp().stringValue() : "0";
+ String destTepIp = stateTunnelList.getDstInfo() != null
+ ? stateTunnelList.getDstInfo().getTepIp().stringValue() : "0";
String rd;
Uint64 remoteDpnId = null;
boolean isTepDeletedOnDpn = false;
}
// Get the list of VpnInterfaces from Intf Mgr for a destDPN only for internal tunnel.
if (tunTypeVal == VpnConstants.ITMTunnelLocType.Internal.getValue()) {
- remoteDpnId = Uint64.valueOf(stateTunnelList.getDstInfo().getTepDeviceId()).intern();
+ remoteDpnId = Uint64.valueOf(stateTunnelList.getDstInfo() != null
+ ? stateTunnelList.getDstInfo().getTepDeviceId() : "0").intern();
try {
result = intfRpcService.getDpnInterfaceList(
new GetDpnInterfaceListInputBuilder().setDpid(remoteDpnId).build());
VpnInterface cfgVpnInterface) {
String rd;
String intfName = cfgVpnInterface.getName();
- final Uint64 srcDpnId = Uint64.valueOf(stateTunnelList.getSrcInfo().getTepDeviceId()).intern();
- String destTepIp = stateTunnelList.getDstInfo().getTepIp().stringValue();
- String srcTepIp = stateTunnelList.getSrcInfo().getTepIp().stringValue();
+ final Uint64 srcDpnId = Uint64.valueOf(stateTunnelList.getSrcInfo() != null
+ ? stateTunnelList.getSrcInfo().getTepDeviceId() : "0").intern();
+ String destTepIp = stateTunnelList.getDstInfo() != null ? stateTunnelList.getDstInfo().getTepIp().stringValue()
+ : null;
+ String srcTepIp = stateTunnelList.getSrcInfo() != null ? stateTunnelList.getSrcInfo().getTepIp().stringValue()
+ : null;
int tunTypeVal = getTunnelType(stateTunnelList);
Uint64 remoteDpnId = null;
if (tunTypeVal == VpnConstants.ITMTunnelLocType.Internal.getValue()) {
- remoteDpnId = Uint64.valueOf(stateTunnelList.getDstInfo().getTepDeviceId()).intern();
+ remoteDpnId = Uint64.valueOf(stateTunnelList.getDstInfo() != null
+ ? stateTunnelList.getDstInfo().getTepDeviceId() : "0").intern();
}
if (cfgVpnInterface.getVpnInstanceNames() == null) {
LOG.warn("handleTunnelEventForDpn: no vpnName found for interface {}", intfName);
private int getTunnelType(StateTunnelList stateTunnelList) {
int tunTypeVal = 0;
+ if (stateTunnelList.getDstInfo() == null) {
+ return VpnConstants.ITMTunnelLocType.Invalid.getValue();
+ }
if (stateTunnelList.getDstInfo().getTepDeviceType() == TepTypeInternal.class) {
tunTypeVal = VpnConstants.ITMTunnelLocType.Internal.getValue();
} else if (stateTunnelList.getDstInfo().getTepDeviceType() == TepTypeExternal.class) {
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg3;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.common.Uint64;
public interface VpnConstants {
short DEFAULT_FLOW_PRIORITY = 10;
int DEFAULT_LPORT_DISPATCHER_FLOW_PRIORITY = 1;
int VPN_ID_LENGTH = 24;
- long INVALID_ID = -1;
+ Uint32 INVALID_ID = Uint32.ZERO;
String SEPARATOR = ".";
Uint64 COOKIE_L3_BASE = Uint64.valueOf("8000000", 16).intern();
String FLOWID_PREFIX = "L3.";
// Considering the possibility of VpnInstanceOpData not being ready yet cause
// the VPN is
// still in its creation process
- if (vpnId.longValue() == VpnConstants.INVALID_ID) {
+ if (VpnConstants.INVALID_ID.equals(vpnId)) {
LOG.error("updateVpnToDpnMapping: Operational data for vpn not ready. Waiting to update vpn"
+ " footprint for vpn {} on dpn {} interface {}", vpnName, dpId, interfaceName);
vpnOpDataSyncer.waitForVpnDataReady(VpnOpDataSyncer.VpnOpDataType.vpnInstanceToId, vpnName,
Optional<VpnToDpnList> dpnInVpn = tx.read(LogicalDatastoreType.OPERATIONAL, id).checkedGet();
if (dpnInVpn.isPresent()) {
VpnToDpnList vpnToDpnList = dpnInVpn.get();
- List<VpnInterfaces> vpnInterfaces = vpnToDpnList.getVpnInterfaces();
- if (vpnInterfaces == null) {
- vpnInterfaces = new ArrayList<>();
- }
+ List<VpnInterfaces> vpnInterfaces = new ArrayList<>(vpnToDpnList.nonnullVpnInterfaces());
vpnInterfaces.add(vpnInterface);
VpnToDpnListBuilder vpnToDpnListBuilder = new VpnToDpnListBuilder(vpnToDpnList);
vpnToDpnListBuilder.setDpnState(VpnToDpnList.DpnState.Active).setVpnInterfaces(vpnInterfaces);
Optional<VpnToDpnList> dpnInVpn = tx.read(LogicalDatastoreType.OPERATIONAL, id).checkedGet();
if (dpnInVpn.isPresent()) {
VpnToDpnList vpnToDpnList = dpnInVpn.get();
- List<IpAddresses> ipAddresses = vpnToDpnList.getIpAddresses();
- if (ipAddresses == null) {
- ipAddresses = new ArrayList<>();
- }
+ List<IpAddresses> ipAddresses = new ArrayList<>(vpnToDpnList.nonnullIpAddresses());
ipAddresses.add(ipAddressesBldr.build());
VpnToDpnListBuilder vpnToDpnListBuilder = new VpnToDpnListBuilder(vpnToDpnList);
vpnToDpnListBuilder.setDpnState(VpnToDpnList.DpnState.Active).setIpAddresses(ipAddresses);
return;
}
VpnToDpnList dpnInVpn = dpnInVpnOpt.get();
- List<VpnInterfaces> vpnInterfaces = dpnInVpn.getVpnInterfaces();
+ List<VpnInterfaces> vpnInterfaces = new ArrayList<>(dpnInVpn.nonnullVpnInterfaces());
if (vpnInterfaces == null) {
LOG.error("Could not find vpnInterfaces for DpnInVpn map for VPN=[name={} rd={} id={}] and "
+ "dpnId={}", vpnName, rd, id, dpnId);
return;
}
VpnToDpnList dpnInVpn = dpnInVpnOpt.get();
- List<IpAddresses> ipAddresses = dpnInVpn.getIpAddresses();
+ List<IpAddresses> ipAddresses = new ArrayList<>(dpnInVpn.nonnullIpAddresses());
if (ipAddresses == null) {
LOG.info("Could not find ipAddresses for DpnInVpn map for VPN=[name={} rd={} id={}] "
+ "and dpnId={}", vpnName, rd, id, dpnId);
LOG.info("processVpnInterfaceUp: Binding vpn service to interface {} onto dpn {} for vpn {}",
interfaceName, dpId, vpnName);
Uint32 vpnId = vpnUtil.getVpnId(vpnName);
- if (vpnId.longValue() == VpnConstants.INVALID_ID) {
+ if (VpnConstants.INVALID_ID.equals(vpnId)) {
LOG.warn("processVpnInterfaceUp: VpnInstance to VPNId mapping not available for VpnName {}"
+ " processing vpninterface {} on dpn {}, bailing out now.", vpnName, interfaceName,
dpId);
Optional<String> gwMac = Optional.absent();
String vpnInterfaceSubnetGwMacAddress = null;
VpnInstanceOpDataEntry vpnInstanceOpData = vpnUtil.getVpnInstanceOpData(primaryRd);
- Uint32 l3vni = vpnInstanceOpData.getL3vni();
+ Uint32 l3vni = vpnInstanceOpData.getL3vni() != null ? vpnInstanceOpData.getL3vni() : Uint32.ZERO;
boolean isL3VpnOverVxLan = VpnUtil.isL3VpnOverVxLan(l3vni);
VrfEntry.EncapType encapType = isL3VpnOverVxLan ? VrfEntry.EncapType.Vxlan : VrfEntry.EncapType.Mplsgre;
VpnPopulator registeredPopulator = L3vpnRegistry.getRegisteredPopulator(encapType);
VpnUtil.getAssociatedSubnetIdentifier(rt, rtType, cidr)).get();
boolean deleteParent = false;
if (associatedSubnet.isPresent()) {
- List<AssociatedVpn> associatedVpns = associatedSubnet.get().getAssociatedVpn();
+ List<AssociatedVpn> associatedVpns = new ArrayList<>(associatedSubnet.get().nonnullAssociatedVpn());
if (associatedVpns == null || associatedVpns.isEmpty()) {
deleteParent = true;
} else {
Optional<RouteTarget> rtToSubnetsAssociation = tx.read(LogicalDatastoreType.OPERATIONAL,
rtIdentifier).get();
if (rtToSubnetsAssociation.isPresent()) {
- List<AssociatedSubnet> associatedSubnets = rtToSubnetsAssociation.get().getAssociatedSubnet();
+ List<AssociatedSubnet> associatedSubnets = new ArrayList<>(rtToSubnetsAssociation.get()
+ .nonnullAssociatedSubnet());
if (associatedSubnets != null && !associatedSubnets.isEmpty()) {
for (Iterator<AssociatedSubnet> iterator = associatedSubnets.iterator(); iterator.hasNext(); ) {
if (Objects.equals(iterator.next().getCidr(), cidr)) {
}
String vpnName = subnetmap.getVpnId().getValue();
Uint32 vpnId = waitAndGetVpnIdIfInvalid(vpnName);
- if (vpnId.longValue() == VpnConstants.INVALID_ID) {
+ if (VpnConstants.INVALID_ID.equals(vpnId)) {
LOG.error(
"{} onSubnetAddedToVpn: VpnInstance to VPNId mapping not yet available for VpnName {} "
+ "processing subnet {} with IP {}, bailing out now.",
subOpBuilder.setSubnetToDpn(new ArrayList<>());
subOpBuilder.setRouteAdvState(TaskState.Idle);
subOpBuilder.setElanTag(elanTag);
- Long l3Vni = vpnInstanceOpData.getL3vni().toJava();
+ Long l3Vni = vpnInstanceOpData.getL3vni() != null ? vpnInstanceOpData.getL3vni().toJava() : 0L;
subOpBuilder.setL3vni(l3Vni);
subOpEntry = subOpBuilder.build();
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier,
private Uint32 waitAndGetVpnIdIfInvalid(String vpnName) {
Uint32 vpnId = vpnUtil.getVpnId(vpnName);
- if (vpnId.longValue() == VpnConstants.INVALID_ID) {
+ if (VpnConstants.INVALID_ID.equals(vpnId)) {
LOG.debug("VpnId is invalid, waiting to fetch again: vpnName={}, vpnId={}", vpnName, vpnId);
vpnOpDataSyncer.waitForVpnDataReady(VpnOpDataType.vpnInstanceToId, vpnName,
VpnConstants.PER_VPN_INSTANCE_MAX_WAIT_TIME_IN_MILLISECONDS);
subOpBuilder.getRouteAdvState(), subOpBuilder.getLastAdvState());
boolean isExternalSubnetVpn = VpnUtil.isExternalSubnetVpn(subnetOpDataEntry.getVpnName(),
subnetId.getValue());
- List<SubnetToDpn> subDpnList = subOpBuilder.getSubnetToDpn();
+ List<SubnetToDpn> subDpnList = new ArrayList<>();
+ subDpnList = subOpBuilder.getSubnetToDpn() != null ? new ArrayList<>(subOpBuilder.getSubnetToDpn())
+ : subDpnList;
subDpnList.add(subDpn);
subOpBuilder.setSubnetToDpn(subDpnList);
if (subOpBuilder.getRouteAdvState() != TaskState.Advertised) {
Uuid subnetId, Uuid networkId, boolean isBgpVpn) {
List<SubnetToDpn> subDpnList = null;
boolean isRouteAdvertised = false;
- subDpnList = subOpBuilder.getSubnetToDpn();
+ subDpnList = new ArrayList<>();
+ subDpnList = subOpBuilder.getSubnetToDpn() != null ? new ArrayList<>(subOpBuilder.getSubnetToDpn())
+ : subDpnList;
String rd = subOpBuilder.getVrfId();
String subnetIp = subOpBuilder.getSubnetCidr();
String vpnName = subOpBuilder.getVpnName();
*/
public Uint32 getVpnId(String vpnName) {
if (vpnName == null) {
- return Uint32.valueOf(VpnConstants.INVALID_ID);
+ return VpnConstants.INVALID_ID;
}
return read(LogicalDatastoreType.CONFIGURATION, VpnOperDsUtils.getVpnInstanceToVpnIdIdentifier(vpnName))
.toJavaUtil().map(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911
.vpn.instance.to.vpn.id.VpnInstance::getVpnId)
- .orElse(Uint32.valueOf(VpnConstants.INVALID_ID));
+ .orElse(VpnConstants.INVALID_ID);
}
/**
mkMatches.add(new MatchEthernetDestination(new MacAddress(gwMacAddress)));
List<InstructionInfo> mkInstructions = new ArrayList<>();
mkInstructions.add(new InstructionGotoTable(NwConstants.L3_FIB_TABLE));
- if (subnetVpnId.longValue() != VpnConstants.INVALID_ID) {
+ if (!VpnConstants.INVALID_ID.equals(subnetVpnId)) {
String vpnName = getVpnName(subnetVpnId);
if (vpnName != null) {
smap = getSubnetmapFromItsUuid(Uuid.getDefaultInstance(vpnName));
interfaceName, dpnId.toString(), vpnIdsOptional.get().getVpnInstanceName());
return;
}
- FlowEntity flowEntity = buildL3vpnGatewayFlow(dpnId, gwMac, vpnId,
- Uint32.valueOf(VpnConstants.INVALID_ID));
+ FlowEntity flowEntity = buildL3vpnGatewayFlow(dpnId, gwMac, vpnId,VpnConstants.INVALID_ID);
if (addOrRemove == NwConstants.ADD_FLOW) {
mdsalManager.addFlow(writeInvTxn, flowEntity);
} else if (addOrRemove == NwConstants.DEL_FLOW) {
lock.lock();
try {
Optional<DpnInterfaces> dpnInElanInterfaces = read(LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId);
- List<String> elanInterfaceList;
+ List<String> elanInterfaceList = new ArrayList<>();
DpnInterfaces dpnInterface;
if (!dpnInElanInterfaces.isPresent()) {
elanInterfaceList = new ArrayList<>();
} else {
dpnInterface = dpnInElanInterfaces.get();
- elanInterfaceList = dpnInterface.getInterfaces();
+ elanInterfaceList = (dpnInterface.getInterfaces() != null && !dpnInterface.getInterfaces().isEmpty())
+ ? new ArrayList<>(dpnInterface.getInterfaces()) : elanInterfaceList;
}
if (!elanInterfaceList.contains(routerInterfacePortId)) {
elanInterfaceList.add(routerInterfacePortId);
lock.lock();
try {
Optional<DpnInterfaces> dpnInElanInterfaces = read(LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId);
- List<String> elanInterfaceList;
+ List<String> elanInterfaceList = new ArrayList<>();
DpnInterfaces dpnInterface;
if (!dpnInElanInterfaces.isPresent()) {
LOG.info("No interface in any dpn for {}", vpnName);
return;
} else {
dpnInterface = dpnInElanInterfaces.get();
- elanInterfaceList = dpnInterface.getInterfaces();
+ elanInterfaceList = (dpnInterface.getInterfaces() != null && !dpnInterface.getInterfaces().isEmpty())
+ ? new ArrayList<>(dpnInterface.getInterfaces()) : elanInterfaceList;
}
if (!elanInterfaceList.contains(routerInterfacePortId)) {
LOG.info("Router port not present in DPN {} for VPN {}", dpnId, vpnName);
Map<String, String> elanInstanceRouterPortMap = new HashMap<>();
Optional<Subnetmaps> subnetMapsData = read(LogicalDatastoreType.CONFIGURATION, buildSubnetMapsWildCardPath());
if (subnetMapsData.isPresent()) {
- List<Subnetmap> subnetMapList = subnetMapsData.get().getSubnetmap();
+ List<Subnetmap> subnetMapList = new ArrayList<>();
+ Subnetmaps subnetMaps = subnetMapsData.get();
+ subnetMapList = (subnetMaps.getSubnetmap() != null && !subnetMaps.getSubnetmap().isEmpty())
+ ? new ArrayList<>(subnetMaps.getSubnetmap()) : subnetMapList;
+
if (subnetMapList != null && !subnetMapList.isEmpty()) {
for (Subnetmap subnet : subnetMapList) {
if (subnet.getVpnId() != null && subnet.getVpnId().getValue().equals(vpnName)
// Wait for VPN Operational data ready
Uint32 vpn1Id = vpnUtil.getVpnId(vpn1Name);
- if (vpn1Id.longValue() == VpnConstants.INVALID_ID) {
+ if (VpnConstants.INVALID_ID.equals(vpn1Id)) {
boolean vpn1Ready =
vpnOpDataSyncer.waitForVpnDataReady(VpnOpDataSyncer.VpnOpDataType.vpnInstanceToId, vpn1Name,
VpnConstants.PER_VPN_INSTANCE_MAX_WAIT_TIME_IN_MILLISECONDS);
}
}
Uint32 vpn2Id = vpnUtil.getVpnId(vpn2Name);
- if (vpn2Id.longValue() == VpnConstants.INVALID_ID) {
+ if (VpnConstants.INVALID_ID.equals(vpn2Id)) {
boolean vpn1Ready =
vpnOpDataSyncer.waitForVpnDataReady(VpnOpDataSyncer.VpnOpDataType.vpnInstanceToId,vpn2Name,
VpnConstants.PER_VPN_INSTANCE_MAX_WAIT_TIME_IN_MILLISECONDS);
}
Adjacencies configAdjacencies = optVpnInterface.get().augmentation(Adjacencies.class);
List<Adjacency> adjacencyList = configAdjacencies == null ? new ArrayList<>()
- : configAdjacencies.getAdjacency();
+ : new ArrayList<>(configAdjacencies.getAdjacency());
String ip = VpnUtil.getIpPrefix(srcPrefix);
AdjacencyBuilder newAdjBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpnBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpnKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.subnet.to.dpn.VpnInterfaces;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.subnet.to.dpn.VpnInterfacesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.subnet.to.dpn.VpnInterfacesKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.Uint64;
public void testAddInterfaceToDpn() {
subOpDpnManager.addInterfaceToDpn(subnetId, dpId, infName);
-
- verify(mockWriteTx).put(LogicalDatastoreType.OPERATIONAL, dpnOpId, subnetToDpn,
+ List<VpnInterfaces> vpnIntfList = new ArrayList<>();
+ VpnInterfaces vpnIntfs =
+ new VpnInterfacesBuilder().withKey(new VpnInterfacesKey(infName)).setInterfaceName(infName).build();
+ vpnIntfList.add(vpnIntfs);
+ SubnetToDpn subnetToDpnLocal = new SubnetToDpnBuilder().setDpnId(dpId).withKey(new SubnetToDpnKey(dpId))
+ .setVpnInterfaces(vpnIntfList).build();
+ verify(mockWriteTx).put(LogicalDatastoreType.OPERATIONAL, dpnOpId, subnetToDpnLocal,
WriteTransaction.CREATE_MISSING_PARENTS);
}