*/
package org.opendaylight.netvirt.elan.l2gw.utils;
-import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION;
-import com.google.common.base.Optional;
import com.google.common.collect.Lists;
+import com.google.common.util.concurrent.FluentFuture;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
-import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
+import java.util.Locale;
+import java.util.Map;
import java.util.Objects;
+import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
-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.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
-import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
-import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
-import org.opendaylight.genius.mdsalutil.MDSALUtil;
import org.opendaylight.genius.utils.SystemPropertyReader;
import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundConstants;
import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
import org.opendaylight.genius.utils.hwvtep.HwvtepUtils;
import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
-import org.opendaylight.infrautils.utils.concurrent.JdkFutures;
+import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner;
+import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.mdsal.common.api.CommitInfo;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
import org.opendaylight.netvirt.elan.cache.ElanInstanceDpnsCache;
import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetDpidFromInterfaceOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVteps;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.DeviceVteps;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.AddL2GwDeviceInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.AddL2GwDeviceOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacs;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacsKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacsKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.locator.set.attributes.LocatorSet;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.port.attributes.VlanBindings;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yangtools.util.concurrent.FluentFutures;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.Uint64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public long getLogicalSwitchDeleteDelaySecs() {
return elanConfig.getL2gwLogicalSwitchDelaySecs() != null
- ? elanConfig.getL2gwLogicalSwitchDelaySecs() : DEFAULT_LOGICAL_SWITCH_DELETE_DELAY_SECS;
+ ? elanConfig.getL2gwLogicalSwitchDelaySecs().toJava() : DEFAULT_LOGICAL_SWITCH_DELETE_DELAY_SECS;
}
/**
List<PhysAddress> result = new ArrayList<>();
for (String interfaceName : lstElanInterfaceNames) {
ElanInterfaceMac elanInterfaceMac = ElanUtils.getElanInterfaceMacByInterfaceName(broker, interfaceName);
- if (elanInterfaceMac != null && elanInterfaceMac.getMacEntry() != null) {
- for (MacEntry macEntry : elanInterfaceMac.getMacEntry()) {
+ if (elanInterfaceMac != null && elanInterfaceMac.nonnullMacEntry() != null) {
+ for (MacEntry macEntry : new ArrayList<>(elanInterfaceMac.nonnullMacEntry().values())) {
result.add(macEntry.getMacAddress());
}
}
.createLogicalSwitchesInstanceIdentifier(nodeId, new HwvtepNodeName(logicalSwitchName));
RemoteMcastMacsKey remoteMcastMacsKey = new RemoteMcastMacsKey(new HwvtepLogicalSwitchRef(logicalSwitch),
new MacAddress(ElanConstants.UNKNOWN_DMAC));
- return HwvtepUtils.getRemoteMcastMac(broker, datastoreType, nodeId, remoteMcastMacsKey);
+ try {
+ return HwvtepUtils.getRemoteMcastMac(broker, datastoreType, nodeId, remoteMcastMacsKey);
+ } catch (ExecutionException | InterruptedException e) {
+ LOG.error("readRemoteMcastMac: Exception while reading LogicalSwitches DS for the nodeId {}, "
+ + "logicalSwitchName {}", nodeId.getValue(), logicalSwitch, e);
+ }
+ return null;
}
/**
* the elan instance
* @param macAddresses
* the mac addresses
+ * @return Future which completes once the removal is done.
*/
- public void removeMacsFromElanExternalDevices(ElanInstance elanInstance, List<PhysAddress> macAddresses) {
- ConcurrentMap<String, L2GatewayDevice> elanL2GwDevices = ElanL2GwCacheUtils
- .getInvolvedL2GwDevices(elanInstance.getElanInstanceName());
- for (L2GatewayDevice l2GatewayDevice : elanL2GwDevices.values()) {
- removeRemoteUcastMacsFromExternalDevice(l2GatewayDevice.getHwvtepNodeId(),
- elanInstance.getElanInstanceName(), macAddresses);
+ public FluentFuture<?> removeMacsFromElanExternalDevices(ElanInstance elanInstance,
+ List<PhysAddress> macAddresses) {
+ final String elanName = elanInstance.getElanInstanceName();
+ final Collection<L2GatewayDevice> devices = ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanName);
+ if (devices.isEmpty()) {
+ return FluentFutures.immediateNullFluentFuture();
}
- }
- /**
- * Removes the given MAC Addresses from the specified External Device.
- *
- * @param deviceNodeId
- * the device node id
- * @param macAddresses
- * the mac addresses
- * @return the listenable future
- */
- private ListenableFuture<Void> removeRemoteUcastMacsFromExternalDevice(String deviceNodeId,
- String logicalSwitchName, List<PhysAddress> macAddresses) {
- NodeId nodeId = new NodeId(deviceNodeId);
-
- // TODO (eperefr)
- List<MacAddress> lstMac = macAddresses.stream().filter(Objects::nonNull).map(
- physAddress -> new MacAddress(physAddress.getValue())).collect(Collectors.toList());
- return HwvtepUtils.deleteRemoteUcastMacs(broker, nodeId, logicalSwitchName, lstMac);
- }
-
- @Nullable
- public ElanInstance getElanInstanceForUcastLocalMac(LocalUcastMacs localUcastMac) {
- Optional<LogicalSwitches> lsOpc = ElanUtils.read(broker, LogicalDatastoreType.OPERATIONAL,
- (InstanceIdentifier<LogicalSwitches>) localUcastMac.getLogicalSwitchRef().getValue());
- if (lsOpc.isPresent()) {
- LogicalSwitches ls = lsOpc.get();
- // Logical switch name is Elan name
- String elanName = getElanFromLogicalSwitch(ls.getHwvtepNodeName().getValue());
- return elanInstanceCache.get(elanName).orNull();
+ final List<MacAddress> lstMac = macAddresses.stream()
+ .filter(Objects::nonNull)
+ .map(physAddress -> new MacAddress(physAddress.getValue()))
+ .collect(Collectors.toList());
+ if (lstMac.isEmpty()) {
+ return FluentFutures.immediateNullFluentFuture();
}
- return null;
+
+ return txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, transaction -> {
+ for (L2GatewayDevice l2GatewayDevice : devices) {
+ final NodeId nodeId = new NodeId(l2GatewayDevice.getHwvtepNodeId());
+ for (MacAddress mac : lstMac) {
+ HwvtepUtils.deleteRemoteUcastMac(transaction, nodeId, elanName, mac);
+ }
+ }
+ });
}
/**
* @param interfaceName
* the interface name
*/
- public void installL2gwDeviceMacsInDpn(BigInteger dpnId, NodeId l2gwDeviceNodeId, ElanInstance elan,
+ public void installL2gwDeviceMacsInDpn(Uint64 dpnId, NodeId l2gwDeviceNodeId, ElanInstance elan,
String interfaceName) {
L2GatewayDevice l2gwDevice = ElanL2GwCacheUtils.getL2GatewayDeviceFromCache(elan.getElanInstanceName(),
l2gwDeviceNodeId.getValue());
* @param interfaceName
* the interface name
*/
- public void installDmacFlowsOnDpn(BigInteger dpnId, L2GatewayDevice l2gwDevice, ElanInstance elan,
- String interfaceName) {
+ public List<ListenableFuture<Void>> installDmacFlowsOnDpn(Uint64 dpnId, L2GatewayDevice l2gwDevice,
+ ElanInstance elan, String interfaceName) {
String elanName = elan.getElanInstanceName();
-
+ List<ListenableFuture<Void>> fts = new ArrayList<>();
Collection<LocalUcastMacs> l2gwDeviceLocalMacs = l2gwDevice.getUcastLocalMacs();
if (!l2gwDeviceLocalMacs.isEmpty()) {
for (LocalUcastMacs localUcastMac : l2gwDeviceLocalMacs) {
- elanDmacUtils.installDmacFlowsToExternalRemoteMacInBatch(dpnId, l2gwDevice.getHwvtepNodeId(),
- elan.getElanTag(), ElanUtils.getVxlanSegmentationId(elan),
- localUcastMac.getMacEntryKey().getValue(), elanName, interfaceName);
+ fts.addAll(elanDmacUtils.installDmacFlowsToExternalRemoteMacInBatch(dpnId, l2gwDevice.getHwvtepNodeId(),
+ elan.getElanTag().toJava(), ElanUtils.getVxlanSegmentationId(elan).longValue(),
+ localUcastMac.getMacEntryKey().getValue(), elanName, interfaceName));
}
LOG.debug("Installing L2gw device [{}] local macs [size: {}] in dpn [{}] for elan [{}]",
l2gwDevice.getHwvtepNodeId(), l2gwDeviceLocalMacs.size(), dpnId, elanName);
}
+ return fts;
}
/**
* @param interfaceName
* the interface name
*/
- public void installElanL2gwDevicesLocalMacsInDpn(BigInteger dpnId, ElanInstance elan, String interfaceName) {
- ConcurrentMap<String, L2GatewayDevice> elanL2GwDevicesFromCache = ElanL2GwCacheUtils
- .getInvolvedL2GwDevices(elan.getElanInstanceName());
- if (elanL2GwDevicesFromCache != null) {
- for (L2GatewayDevice l2gwDevice : elanL2GwDevicesFromCache.values()) {
- installDmacFlowsOnDpn(dpnId, l2gwDevice, elan, interfaceName);
- }
- } else {
- LOG.debug("No Elan l2 gateway devices in cache for [{}] ", elan.getElanInstanceName());
+ public void installElanL2gwDevicesLocalMacsInDpn(Uint64 dpnId, ElanInstance elan, String interfaceName) {
+ for (L2GatewayDevice l2gwDevice : ElanL2GwCacheUtils.getInvolvedL2GwDevices(elan.getElanInstanceName())) {
+ installDmacFlowsOnDpn(dpnId, l2gwDevice, elan, interfaceName);
}
}
final String extDeviceNodeId = extL2GwDevice.getHwvtepNodeId();
final String elanInstanceName = elan.getElanInstanceName();
final Collection<DpnInterfaces> elanDpns = getElanDpns(elanInstanceName);
- ConcurrentMap<String, L2GatewayDevice> elanL2GwDevices = ElanL2GwCacheUtils
- .getInvolvedL2GwDevices(elanInstanceName);
+ Collection<L2GatewayDevice> elanL2GwDevices = ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanInstanceName);
// Retrieve all participating DPNs in this Elan. Populate this MAC in
// DMAC table.
// Looping through all DPNs in order to add/remove mac flows in their
// DMAC table
- if (elanDpns.size() > 0 || elanL2GwDevices.values().size() > 0) {
+ if (elanDpns.size() > 0 || elanL2GwDevices.size() > 0) {
String jobKey = elanInstanceName + ":" + macToBeAdded;
IpAddress extL2GwDeviceTepIp = extL2GwDevice.getTunnelIp();
List<PhysAddress> macList = Lists.newArrayList(new PhysAddress(macToBeAdded));
if (doesLocalUcastMacExistsInCache(extL2GwDevice, localUcastMacs)) {
List<ListenableFuture<Void>> futures = new ArrayList<>();
for (DpnInterfaces elanDpn : elanDpns) {
- futures.addAll(elanDmacUtils.installDmacFlowsToExternalRemoteMacInBatch(elanDpn.getDpId(),
- extDeviceNodeId, elan.getElanTag(), ElanUtils.getVxlanSegmentationId(elan),
+ futures.addAll(elanDmacUtils.installDmacFlowsToExternalRemoteMacInBatch(
+ elanDpn.getDpId(),
+ extDeviceNodeId, elan.getElanTag().toJava(),
+ ElanUtils.getVxlanSegmentationId(elan).longValue(),
macToBeAdded, elanInstanceName, interfaceName));
}
- for (L2GatewayDevice otherDevice : elanL2GwDevices.values()) {
+ for (L2GatewayDevice otherDevice : elanL2GwDevices) {
if (!otherDevice.getHwvtepNodeId().equals(extDeviceNodeId)
&& !areMLAGDevices(extL2GwDevice, otherDevice)) {
final String hwvtepId = otherDevice.getHwvtepNodeId();
final String logicalSwitchName = elanInstanceName;
- futures.add(HwvtepUtils.installUcastMacs(
- broker, hwvtepId, macList, logicalSwitchName, extL2GwDeviceTepIp));
+ HwvtepUtils.installUcastMacs(broker, hwvtepId, macList, logicalSwitchName,
+ extL2GwDeviceTepIp);
}
}
return futures;
elanClusterUtils.runOnlyInOwnerNode(elan.getElanInstanceName() + ":" + mac.getValue(),
"delete remote ucast macs in elan DPNs", () -> {
for (DpnInterfaces elanDpn : elanDpns) {
- BigInteger dpnId = elanDpn.getDpId();
- result.addAll(elanDmacUtils.deleteDmacFlowsToExternalMac(elan.getElanTag(), dpnId,
+ Uint64 dpnId = elanDpn.getDpId();
+ result.addAll(elanDmacUtils.deleteDmacFlowsToExternalMac(elan.getElanTag().toJava(), dpnId,
l2GwDevice.getHwvtepNodeId(),
IetfYangUtil.INSTANCE.canonizeMacAddress(mac).getValue()));
}
* @param dpnId
* the dpn id
*/
- public void deleteElanL2GwDevicesUcastLocalMacsFromDpn(final String elanName, final BigInteger dpnId) {
- ConcurrentMap<String, L2GatewayDevice> elanL2GwDevices = ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanName);
- if (elanL2GwDevices == null || elanL2GwDevices.isEmpty()) {
+ public void deleteElanL2GwDevicesUcastLocalMacsFromDpn(final String elanName, final Uint64 dpnId) {
+ Collection<L2GatewayDevice> elanL2GwDevices = ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanName);
+ if (elanL2GwDevices.isEmpty()) {
LOG.trace("No L2 gateway devices in Elan [{}] cache.", elanName);
return;
}
- final ElanInstance elan = elanInstanceCache.get(elanName).orNull();
+ final ElanInstance elan = elanInstanceCache.get(elanName).orElse(null);
if (elan == null) {
LOG.error("Could not find Elan by name: {}", elanName);
return;
}
LOG.info("Deleting Elan [{}] L2GatewayDevices UcastLocalMacs from Dpn [{}]", elanName, dpnId);
- final Long elanTag = elan.getElanTag();
- for (final L2GatewayDevice l2GwDevice : elanL2GwDevices.values()) {
+ final Long elanTag = elan.getElanTag().toJava();
+ for (final L2GatewayDevice l2GwDevice : elanL2GwDevices) {
getL2GwDeviceLocalMacsAndRunCallback(elan.getElanInstanceName(), l2GwDevice, (localMacs) -> {
for (MacAddress mac : localMacs) {
String jobKey = elanName + ":" + mac.getValue();
Collection<LocalUcastMacs> lstUcastLocalMacs = l2gwDevice.getUcastLocalMacs();
if (!lstUcastLocalMacs.isEmpty()) {
macs.addAll(lstUcastLocalMacs.stream().filter(Objects::nonNull)
- .map(mac -> new MacAddress(mac.getMacEntryKey().getValue().toLowerCase()))
+ .map(mac -> new MacAddress(mac.getMacEntryKey().getValue().toLowerCase(Locale.ENGLISH)))
.collect(Collectors.toList()));
}
if (configNode != null && configNode.isPresent()) {
HwvtepGlobalAugmentation augmentation = configNode.get().augmentation(
HwvtepGlobalAugmentation.class);
- if (augmentation != null && augmentation.getLocalUcastMacs() != null) {
- macs.addAll(augmentation.getLocalUcastMacs().stream()
+ if (augmentation != null && augmentation.nonnullLocalUcastMacs() != null) {
+ macs.addAll(new ArrayList<>(augmentation
+ .nonnullLocalUcastMacs().values()).stream()
.filter(mac -> getLogicalSwitchName(mac).equals(elanName))
.map(HwvtepMacTableGenericAttributes::getMacEntryKey)
.collect(Collectors.toSet()));
}, MoreExecutors.directExecutor());
}
- private String getLogicalSwitchName(LocalUcastMacs mac) {
+ private static String getLogicalSwitchName(LocalUcastMacs mac) {
return ((InstanceIdentifier<LogicalSwitches>)mac.getLogicalSwitchRef().getValue())
.firstKeyOf(LogicalSwitches.class).getHwvtepNodeName().getValue();
}
* the elan name
* @return the listenable future
*/
- public ListenableFuture<Void> deleteElanMacsFromL2GatewayDevice(String hwvtepNodeId, String elanName) {
+ public FluentFuture<? extends CommitInfo> deleteElanMacsFromL2GatewayDevice(String hwvtepNodeId, String elanName) {
String logicalSwitch = getLogicalSwitchFromElan(elanName);
List<MacAddress> lstElanMacs = getRemoteUcastMacs(new NodeId(hwvtepNodeId), logicalSwitch,
LogicalDatastoreType.CONFIGURATION);
- ListenableFuture<Void> future = HwvtepUtils.deleteRemoteUcastMacs(broker, new NodeId(hwvtepNodeId),
+ FluentFuture<? extends CommitInfo> future = HwvtepUtils.deleteRemoteUcastMacs(broker, new NodeId(hwvtepNodeId),
logicalSwitch, lstElanMacs);
- Futures.addCallback(future, new FutureCallback<Void>() {
+ Futures.addCallback(future, new FutureCallback<CommitInfo>() {
@Override
- public void onSuccess(Void noarg) {
+ public void onSuccess(CommitInfo noarg) {
LOG.trace("Successful in batch deletion of elan [{}] macs from l2gw device [{}]", elanName,
hwvtepNodeId);
}
public List<MacAddress> getRemoteUcastMacs(NodeId hwvtepNodeId, String logicalSwitch,
LogicalDatastoreType datastoreType) {
List<MacAddress> lstMacs = Collections.emptyList();
- Node hwvtepNode = HwvtepUtils.getHwVtepNode(broker, datastoreType, hwvtepNodeId);
+ Node hwvtepNode;
+ try {
+ hwvtepNode = HwvtepUtils.getHwVtepNode(broker, datastoreType, hwvtepNodeId);
+ } catch (ExecutionException | InterruptedException e) {
+ LOG.error("getRemoteUcastMacs: Exception while reading hwvtepNodeId DS for the hwvtepNodeId {}",
+ hwvtepNodeId.getValue(), e);
+ return Collections.emptyList();
+ }
if (hwvtepNode != null) {
- List<RemoteUcastMacs> remoteUcastMacs = hwvtepNode.augmentation(HwvtepGlobalAugmentation.class)
- .getRemoteUcastMacs();
- if (remoteUcastMacs != null && !remoteUcastMacs.isEmpty()) {
- // Filtering remoteUcastMacs based on the logical switch and
+ Map<RemoteUcastMacsKey, RemoteUcastMacs> keyRemoteUcastMacsMap
+ = hwvtepNode.augmentation(HwvtepGlobalAugmentation.class)
+ .nonnullRemoteUcastMacs();
+ if (keyRemoteUcastMacsMap != null && !keyRemoteUcastMacsMap.isEmpty()) {
+ // Filtering keyRemoteUcastMacsMap based on the logical switch and
// forming a list of MacAddress
- lstMacs = remoteUcastMacs.stream()
+ lstMacs = keyRemoteUcastMacsMap.values().stream()
.filter(mac -> logicalSwitch.equals(mac.getLogicalSwitchRef().getValue()
.firstKeyOf(LogicalSwitches.class).getHwvtepNodeName().getValue()))
.map(HwvtepMacTableGenericAttributes::getMacEntryKey).collect(Collectors.toList());
* the l2 gateway device which has to be configured
* @return the listenable future
*/
- public ListenableFuture<Void> installElanMacsInL2GatewayDevice(String elanName,
- L2GatewayDevice l2GatewayDevice) {
+ public FluentFuture<? extends CommitInfo> installElanMacsInL2GatewayDevice(String elanName,
+ L2GatewayDevice l2GatewayDevice) {
String logicalSwitchName = getLogicalSwitchFromElan(elanName);
NodeId hwVtepNodeId = new NodeId(l2GatewayDevice.getHwvtepNodeId());
List<RemoteUcastMacs> lstRemoteUcastMacs = new ArrayList<>(lstL2GatewayDevicesMacs);
lstRemoteUcastMacs.addAll(lstElanMacTableEntries);
- ListenableFuture<Void> future = HwvtepUtils.addRemoteUcastMacs(broker, hwVtepNodeId, lstRemoteUcastMacs);
+ FluentFuture<? extends CommitInfo> future = HwvtepUtils.addRemoteUcastMacs(broker, hwVtepNodeId,
+ lstRemoteUcastMacs);
LOG.info("Added RemoteUcastMacs entries [{}] in config DS. NodeID: {}, LogicalSwitch: {}",
lstRemoteUcastMacs.size(), hwVtepNodeId.getValue(), logicalSwitchName);
public static List<RemoteUcastMacs> getOtherDevicesMacs(String elanName,
L2GatewayDevice l2GatewayDeviceToBeConfigured, NodeId hwVtepNodeId, String logicalSwitchName) {
List<RemoteUcastMacs> lstRemoteUcastMacs = new ArrayList<>();
- ConcurrentMap<String, L2GatewayDevice> elanL2GwDevicesFromCache = ElanL2GwCacheUtils
- .getInvolvedL2GwDevices(elanName);
- if (elanL2GwDevicesFromCache != null) {
- for (L2GatewayDevice otherDevice : elanL2GwDevicesFromCache.values()) {
- if (l2GatewayDeviceToBeConfigured.getHwvtepNodeId().equals(otherDevice.getHwvtepNodeId())) {
- continue;
- }
- if (!areMLAGDevices(l2GatewayDeviceToBeConfigured, otherDevice)) {
- for (LocalUcastMacs localUcastMac : otherDevice.getUcastLocalMacs()) {
- HwvtepPhysicalLocatorAugmentation physLocatorAug = HwvtepSouthboundUtils
- .createHwvtepPhysicalLocatorAugmentation(otherDevice.getTunnelIp());
- RemoteUcastMacs remoteUcastMac = HwvtepSouthboundUtils.createRemoteUcastMac(hwVtepNodeId,
- IetfYangUtil.INSTANCE.canonizeMacAddress(localUcastMac.getMacEntryKey()).getValue(),
- localUcastMac.getIpaddr(), logicalSwitchName, physLocatorAug);
- lstRemoteUcastMacs.add(remoteUcastMac);
- }
+ for (L2GatewayDevice otherDevice : ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanName)) {
+ if (l2GatewayDeviceToBeConfigured.getHwvtepNodeId().equals(otherDevice.getHwvtepNodeId())) {
+ continue;
+ }
+ if (!areMLAGDevices(l2GatewayDeviceToBeConfigured, otherDevice)) {
+ for (LocalUcastMacs localUcastMac : otherDevice.getUcastLocalMacs()) {
+ HwvtepPhysicalLocatorAugmentation physLocatorAug = HwvtepSouthboundUtils
+ .createHwvtepPhysicalLocatorAugmentation(otherDevice.getTunnelIp());
+ RemoteUcastMacs remoteUcastMac = HwvtepSouthboundUtils.createRemoteUcastMac(hwVtepNodeId,
+ IetfYangUtil.INSTANCE.canonizeMacAddress(localUcastMac.getMacEntryKey()).getValue(),
+ localUcastMac.getIpaddr(), logicalSwitchName, physLocatorAug);
+ lstRemoteUcastMacs.add(remoteUcastMac);
}
}
}
return lstRemoteUcastMacs;
}
- for (MacEntry macEntry : macTable.getMacEntry()) {
- BigInteger dpnId = getDpidFromInterface(macEntry.getInterface());
+ for (MacEntry macEntry : new ArrayList<>(macTable.nonnullMacEntry().values())) {
+ Uint64 dpnId = getDpidFromInterface(macEntry.getInterface());
if (dpnId == null) {
LOG.error("DPN ID not found for interface {}", macEntry.getInterface());
continue;
* @return the dpid from interface
*/
@Nullable
- public BigInteger getDpidFromInterface(String interfaceName) {
- BigInteger dpId = null;
+ public Uint64 getDpidFromInterface(String interfaceName) {
+ Uint64 dpId = null;
Future<RpcResult<GetDpidFromInterfaceOutput>> output = interfaceManagerRpcService
.getDpidFromInterface(new GetDpidFromInterfaceInputBuilder().setIntfName(interfaceName).build());
try {
* the default vlan id
* @return the listenable future
*/
- public ListenableFuture<Void> updateVlanBindingsInL2GatewayDevice(NodeId nodeId, String logicalSwitchName,
+ public ListenableFuture<?> updateVlanBindingsInL2GatewayDevice(NodeId nodeId, String logicalSwitchName,
Devices hwVtepDevice, Integer defaultVlanId) {
if (hwVtepDevice == null || hwVtepDevice.getInterfaces() == null || hwVtepDevice.getInterfaces().isEmpty()) {
String errMsg = "HwVtepDevice is null or interfaces are empty.";
return txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
for (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712
- .l2gateway.attributes.devices.Interfaces deviceInterface : hwVtepDevice.getInterfaces()) {
+ .l2gateway.attributes.devices.Interfaces deviceInterface : new ArrayList<>(hwVtepDevice
+ .nonnullInterfaces().values())) {
//Removed the check for checking terminationPoint present in OP or not
//for coniguring vlan bindings
//As we are not any more dependent on it , plugin takes care of this
* the vlan bindings to be configured
* @return the listenable future
*/
- public ListenableFuture<Void> updateVlanBindingsInL2GatewayDevice(NodeId nodeId, String psName,
+ public ListenableFuture<?> updateVlanBindingsInL2GatewayDevice(NodeId nodeId, String psName,
String interfaceName, List<VlanBindings> vlanBindings) {
return txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
HwvtepUtils.mergeVlanBindings(tx, nodeId, psName, interfaceName, vlanBindings);
* the default vlan id
* @return the listenable future
*/
- public ListenableFuture<Void> deleteVlanBindingsFromL2GatewayDevice(NodeId nodeId, Devices hwVtepDevice,
+ public ListenableFuture<?> deleteVlanBindingsFromL2GatewayDevice(NodeId nodeId, Devices hwVtepDevice,
Integer defaultVlanId) {
if (hwVtepDevice == null || hwVtepDevice.getInterfaces() == null || hwVtepDevice.getInterfaces().isEmpty()) {
String errMsg = "HwVtepDevice is null or interfaces are empty.";
return txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
for (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712
- .l2gateway.attributes.devices.Interfaces deviceInterface : hwVtepDevice.getInterfaces()) {
+ .l2gateway.attributes.devices.Interfaces deviceInterface : new ArrayList<>(hwVtepDevice
+ .nonnullInterfaces().values())) {
String phyPortName = deviceInterface.getInterfaceName();
if (deviceInterface.getSegmentationIds() != null && !deviceInterface.getSegmentationIds().isEmpty()) {
for (Integer vlanId : deviceInterface.getSegmentationIds()) {
});
}
- /**
- * Gets the elan name from logical switch name.
- *
- * @param logicalSwitchName
- * the logical switch name
- * @return the elan name from logical switch name
- */
- public static String getElanFromLogicalSwitch(String logicalSwitchName) {
- // Assuming elan name is same as logical switch name
- String elanName = logicalSwitchName;
- return elanName;
- }
-
/**
* Gets the logical switch name from elan name.
*
InstanceIdentifier<Interface> interfaceId = getInterfaceIdentifier(interfaceKey);
try {
return SingleTransactionDataBroker
- .syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, interfaceId).orNull();
- } catch (ReadFailedException e) {
+ .syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, interfaceId).orElse(null);
+ } catch (InterruptedException | ExecutionException e) {
// TODO remove this, and propagate ReadFailedException instead of re-throw RuntimeException
LOG.error("getInterfaceFromConfigDS({}) failed", interfaceKey, e);
throw new RuntimeException(e);
LOG.info("Deleting L2GatewayDevice [{}] UcastLocalMacs from elan [{}]", l2GatewayDevice.getHwvtepNodeId(),
elanName);
- ElanInstance elan = elanInstanceCache.get(elanName).orNull();
+ ElanInstance elan = elanInstanceCache.get(elanName).orElse(null);
if (elan == null) {
LOG.error("Could not find Elan by name: {}", elanName);
return;
}
String psNodeId = globalNodeId + HwvtepHAUtil.PHYSICALSWITCH + psName;
tzonesoptional.get().nonnullTransportZone().stream()
- .filter(transportZone -> transportZone.getSubnets() != null)
- .flatMap(transportZone -> transportZone.getSubnets().stream())
- .filter(subnet -> subnet.getDeviceVteps() != null)
- .flatMap(subnet -> subnet.getDeviceVteps().stream())
+ .filter(zone -> zone.getDeviceVteps() != null)
+ .flatMap(zone -> new ArrayList<>(zone.nonnullDeviceVteps().values()).stream())
.filter(deviceVteps -> Objects.equals(getPsName(deviceVteps), psName)) //get device with same ps name
.filter(deviceVteps -> !Objects.equals(psNodeId, deviceVteps.getNodeId())
|| !Objects.equals(tunnelIp, deviceVteps.getIpAddress()))//node id or tunnel ip is changed
.forEach(deviceVteps -> deleteStaleL2gwTep(dataBroker, itmRpcService, deviceVteps));
- } catch (ReadFailedException e) {
+ } catch (ExecutionException | InterruptedException e) {
LOG.error("Failed delete stale tunnels for {}", globalNodeId);
}
}
- private static Optional<TransportZones> readTransportZone(DataBroker dataBroker) throws ReadFailedException {
+ private static Optional<TransportZones> readTransportZone(DataBroker dataBroker) throws ExecutionException,
+ InterruptedException {
return new SingleTransactionDataBroker(dataBroker).syncReadOptional(LogicalDatastoreType.CONFIGURATION,
InstanceIdentifier.builder(TransportZones.class).build());
}
- private static Optional<ElanInstances> readElanInstances(DataBroker dataBroker) throws ReadFailedException {
+ private static Optional<ElanInstances> readElanInstances(DataBroker dataBroker) throws ExecutionException,
+ InterruptedException {
return new SingleTransactionDataBroker(dataBroker).syncReadOptional(LogicalDatastoreType.CONFIGURATION,
InstanceIdentifier.builder(ElanInstances.class).build());
}
if (!optionalElan.isPresent()) {
return;
}
- JdkFutures.addErrorLogging(
+ LoggingFutures.addErrorLogging(
new ManagedNewTransactionRunnerImpl(dataBroker).callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
- tx -> optionalElan.get().nonnullElanInstance().stream()
- .flatMap(elan -> elan.nonnullExternalTeps().stream()
+ tx -> optionalElan.get().nonnullElanInstance().values().stream()
+ .flatMap(elan -> elan.nonnullExternalTeps().values().stream()
.map(externalTep -> ElanL2GatewayMulticastUtils.buildExternalTepPath(
elan.getElanInstanceName(), externalTep.getTepIp())))
.filter(externalTepIid -> Objects.equals(
.forEach(tx::delete)), LOG,
"Failed to delete stale external teps {}", deviceVteps);
Thread.sleep(10000);//TODO remove the sleep currently it waits for interfacemgr to finish the cleanup
- } catch (ReadFailedException | InterruptedException e) {
+ } catch (ExecutionException | InterruptedException e) {
LOG.error("Failed to delete stale l2gw tep {}", deviceVteps, e);
}
}
- public static String getNodeIdFromDpnId(BigInteger dpnId) {
- return MDSALUtil.NODE_PREFIX + MDSALUtil.SEPARATOR + dpnId.toString();
- }
-
- public void scheduleAddDpnMacInExtDevices(String elanName, BigInteger dpId,
+ public void scheduleAddDpnMacInExtDevices(String elanName, Uint64 dpId,
List<PhysAddress> staticMacAddresses) {
- ConcurrentMap<String, L2GatewayDevice> elanDevices = ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanName);
- for (final L2GatewayDevice externalDevice : elanDevices.values()) {
+ for (final L2GatewayDevice externalDevice : ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanName)) {
scheduleAddDpnMacsInExtDevice(elanName, dpId, staticMacAddresses, externalDevice);
}
}
- public void scheduleAddDpnMacsInExtDevice(final String elanName, BigInteger dpId,
+ public void scheduleAddDpnMacsInExtDevice(final String elanName, Uint64 dpId,
final List<PhysAddress> staticMacAddresses, final L2GatewayDevice externalDevice) {
NodeId nodeId = new NodeId(externalDevice.getHwvtepNodeId());
final IpAddress dpnTepIp = elanItmUtils.getSourceDpnTepIp(dpId, nodeId);
}
}
- @Nonnull
+ @NonNull
public Collection<DpnInterfaces> getElanDpns(String elanName) {
Collection<DpnInterfaces> dpnInterfaces = elanInstanceDpnsCache.get(elanName);
if (!dpnInterfaces.isEmpty()) {
Set<MacAddress> macs = new HashSet<>();
if (!lstUcastLocalMacs.isEmpty()) {
macs.addAll(lstUcastLocalMacs.stream().filter(Objects::nonNull)
- .map(mac -> new MacAddress(mac.getMacEntryKey().getValue().toLowerCase()))
+ .map(mac -> new MacAddress(mac.getMacEntryKey().getValue().toLowerCase(Locale.ENGLISH)))
.collect(Collectors.toList()));
}
- Optional<Node> configNode = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION,
- HwvtepSouthboundUtils.createInstanceIdentifier(new NodeId(l2gwDevice.getHwvtepNodeId())));
+ Optional<Node> configNode;
+ try {
+ configNode = SingleTransactionDataBroker.syncReadOptional(broker, LogicalDatastoreType.CONFIGURATION,
+ HwvtepSouthboundUtils.createInstanceIdentifier(new NodeId(l2gwDevice.getHwvtepNodeId())));
+ } catch (ExecutionException | InterruptedException e) {
+ LOG.error("getL2GwDeviceLocalMacs: Exception while reading l2gwDevice DS for the elan {}, l2gwDevice {}",
+ elanName, l2gwDevice, e);
+ return Collections.emptyList();
+ }
if (configNode.isPresent()) {
HwvtepGlobalAugmentation augmentation = configNode.get().augmentation(HwvtepGlobalAugmentation.class);
if (augmentation != null && augmentation.getLocalUcastMacs() != null) {
- macs.addAll(augmentation.getLocalUcastMacs().stream()
+ macs.addAll(augmentation.nonnullLocalUcastMacs().values().stream()
.filter(mac -> getLogicalSwitchName(mac).equals(elanName))
.map(HwvtepMacTableGenericAttributes::getMacEntryKey)
.collect(Collectors.toSet()));