*/
package org.opendaylight.netvirt.elan.l2gw.utils;
-import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.FutureCallback;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
-import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
* It gathers a set of utility methods that handle ELAN configuration in
* external Devices (where external means "not-CSS". As of now: TORs).
*
- * It makes use of HwvtepUtils class located under ovsdb/hwvtepsouthbound
+ * <p>It makes use of HwvtepUtils class located under ovsdb/hwvtepsouthbound
* project for low-level mdsal operations
*
* @author eperefr
- *
*/
public class ElanL2GatewayUtils {
private static final Logger LOG = LoggerFactory.getLogger(ElanL2GatewayUtils.class);
}
/**
- * gets the macs addresses for elan interfaces
+ * gets the macs addresses for elan interfaces.
*
* @param lstElanInterfaceNames
* the lst elan interface names
*
* @param deviceNodeId
* the device node id
- * @param logicalSwitchName
* @param macAddresses
* the mac addresses
* @return the listenable future
NodeId nodeId = new NodeId(deviceNodeId);
// TODO (eperefr)
- List<MacAddress> lstMac = Lists.transform(macAddresses, new Function<PhysAddress, MacAddress>() {
- @Override
- public MacAddress apply(PhysAddress physAddress) {
- return (physAddress != null) ? new MacAddress(physAddress.getValue()) : null;
- }
- });
+ List<MacAddress> lstMac = Lists.transform(macAddresses,
+ physAddress -> physAddress != null ? new MacAddress(physAddress.getValue()) : null);
return HwvtepUtils.deleteRemoteUcastMacs(broker, nodeId, logicalSwitchName, lstMac);
}
if (ls != null) {
// Logical switch name is Elan name
String elanName = getElanFromLogicalSwitch(ls.getHwvtepNodeName().getValue());
- return elanUtils.getElanInstanceByName(elanName);
+ return ElanUtils.getElanInstanceByName(broker, elanName);
} else {
String macAddress = localUcastMac.getMacEntryKey().getValue();
LOG.error("Could not find logical_switch for {} being added/deleted", macAddress);
* @param elan
* the elan
* @param interfaceName
+ * the interface name
*/
public void installL2gwDeviceMacsInDpn(BigInteger dpnId, NodeId l2gwDeviceNodeId, ElanInstance elan,
String interfaceName) {
* @param elan
* the elan
* @param interfaceName
+ * the interface name
*/
public void installDmacFlowsOnDpn(BigInteger dpnId, L2GatewayDevice l2gwDevice, ElanInstance elan,
String interfaceName) {
* @param elan
* the elan
* @param interfaceName
+ * the interface name
*/
public void installElanL2gwDevicesLocalMacsInDpn(BigInteger dpnId, ElanInstance elan, String interfaceName) {
ConcurrentMap<String, L2GatewayDevice> elanL2GwDevicesFromCache = ElanL2GwCacheUtils
if (elanDpns != null && elanDpns.size() > 0) {
String jobKey = elan.getElanInstanceName() + ":" + macToBeAdded;
ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService, jobKey, "install l2gw macs in dmac table",
- new Callable<List<ListenableFuture<Void>>>() {
- @Override
- public List<ListenableFuture<Void>> call() throws Exception {
- List<ListenableFuture<Void>> fts = Lists.newArrayList();
- if (doesLocalUcastMacExistsInCache(extL2GwDevice, macToBeAdded)) {
- for (DpnInterfaces elanDpn : elanDpns) {
- // TODO batch the below call
- fts.addAll(elanUtils.installDmacFlowsToExternalRemoteMac(elanDpn.getDpId(),
- extDeviceNodeId, elan.getElanTag(), elan.getSegmentationId(), macToBeAdded,
- elanInstanceName, interfaceName));
- }
- } else {
- LOG.trace("Skipping install of dmac flows for mac {} as it is not found in cache",
- macToBeAdded);
- }
- return fts;
+ () -> {
+ List<ListenableFuture<Void>> fts = Lists.newArrayList();
+ if (doesLocalUcastMacExistsInCache(extL2GwDevice, macToBeAdded)) {
+ for (DpnInterfaces elanDpn : elanDpns) {
+ // TODO batch the below call
+ fts.addAll(elanUtils.installDmacFlowsToExternalRemoteMac(elanDpn.getDpId(),
+ extDeviceNodeId, elan.getElanTag(), elan.getSegmentationId(), macToBeAdded,
+ elanInstanceName, interfaceName));
}
- });
+ } else {
+ LOG.trace("Skipping install of dmac flows for mac {} as it is not found in cache",
+ macToBeAdded);
+ }
+ return fts;
+ });
}
final IpAddress extL2GwDeviceTepIp = extL2GwDevice.getTunnelIp();
final List<PhysAddress> macList = new ArrayList<>();
String jobKey = "hwvtep:" + elan.getElanInstanceName() + ":" + macToBeAdded;
ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService, jobKey, "install remote ucast macs in l2gw device",
- new Callable<List<ListenableFuture<Void>>>() {
- @Override
- public List<ListenableFuture<Void>> call() throws Exception {
- List<ListenableFuture<Void>> fts = Lists.newArrayList();
- if (!doesLocalUcastMacExistsInCache(extL2GwDevice, macToBeAdded)) {
- LOG.trace(
- "Skipping install of remote ucast macs {} in l2gw device as it is not found in cache",
- macToBeAdded);
- return fts;
- }
- ConcurrentMap<String, L2GatewayDevice> elanL2GwDevices = ElanL2GwCacheUtils
- .getInvolvedL2GwDevices(elanInstanceName);
- for (L2GatewayDevice otherDevice : elanL2GwDevices.values()) {
- if (!otherDevice.getHwvtepNodeId().equals(extDeviceNodeId)
- && !areMLAGDevices(extL2GwDevice, otherDevice)) {
- final String hwvtepId = otherDevice.getHwvtepNodeId();
- InstanceIdentifier<Node> iid = HwvtepSouthboundUtils
- .createInstanceIdentifier(new NodeId(hwvtepId));
- final String logicalSwitchName = elanInstanceName;
-
- ListenableFuture<Void> ft = HwvtepUtils.installUcastMacs(broker, hwvtepId, macList,
- logicalSwitchName, extL2GwDeviceTepIp);
- // TODO batch the above call
- Futures.addCallback(ft, new FutureCallback<Void>() {
- @Override
- public void onSuccess(Void noarg) {
- LOG.trace("Successful in initiating ucast_remote_macs addition"
- + "related to {} in {}", logicalSwitchName, hwvtepId);
- }
-
- @Override
- public void onFailure(Throwable error) {
- LOG.error(String.format(
- "Failed adding ucast_remote_macs related to " + "%s in %s",
- logicalSwitchName, hwvtepId), error);
- }
- });
- fts.add(ft);
+ () -> {
+ List<ListenableFuture<Void>> fts = Lists.newArrayList();
+ if (!doesLocalUcastMacExistsInCache(extL2GwDevice, macToBeAdded)) {
+ LOG.trace(
+ "Skipping install of remote ucast macs {} in l2gw device as it is not found in cache",
+ macToBeAdded);
+ return fts;
+ }
+ ConcurrentMap<String, L2GatewayDevice> elanL2GwDevices = ElanL2GwCacheUtils
+ .getInvolvedL2GwDevices(elanInstanceName);
+ for (L2GatewayDevice otherDevice : elanL2GwDevices.values()) {
+ if (!otherDevice.getHwvtepNodeId().equals(extDeviceNodeId)
+ && !areMLAGDevices(extL2GwDevice, otherDevice)) {
+ final String hwvtepId = otherDevice.getHwvtepNodeId();
+ InstanceIdentifier<Node> iid = HwvtepSouthboundUtils
+ .createInstanceIdentifier(new NodeId(hwvtepId));
+ final String logicalSwitchName = elanInstanceName;
+
+ ListenableFuture<Void> ft = HwvtepUtils.installUcastMacs(broker, hwvtepId, macList,
+ logicalSwitchName, extL2GwDeviceTepIp);
+ // TODO batch the above call
+ Futures.addCallback(ft, new FutureCallback<Void>() {
+ @Override
+ public void onSuccess(Void noarg) {
+ LOG.trace("Successful in initiating ucast_remote_macs addition"
+ + "related to {} in {}", logicalSwitchName, hwvtepId);
}
- }
- return fts;
+
+ @Override
+ public void onFailure(Throwable error) {
+ LOG.error(String.format(
+ "Failed adding ucast_remote_macs related to " + "%s in %s",
+ logicalSwitchName, hwvtepId), error);
+ }
+ });
+ fts.add(ft);
}
- });
+ }
+ return fts;
+ });
}
/**
if (elanDpns != null && !elanDpns.isEmpty()) {
String jobKey = elanName + ":" + mac.getValue();
ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService, jobKey, "delete l2gw macs from dmac table",
- new Callable<List<ListenableFuture<Void>>>() {
- @Override
- public List<ListenableFuture<Void>> call() {
- List<ListenableFuture<Void>> fts = Lists.newArrayList();
- for (DpnInterfaces elanDpn : elanDpns) {
- BigInteger dpnId = elanDpn.getDpId();
- // never batch deletes
- fts.addAll(elanUtils.deleteDmacFlowsToExternalMac(elan.getElanTag(), dpnId,
- l2GwDevice.getHwvtepNodeId(), mac.getValue()));
- }
- return fts;
- }
- });
+ () -> {
+ List<ListenableFuture<Void>> fts = Lists.newArrayList();
+ for (DpnInterfaces elanDpn : elanDpns) {
+ BigInteger dpnId = elanDpn.getDpId();
+ // never batch deletes
+ fts.addAll(elanUtils.deleteDmacFlowsToExternalMac(elan.getElanTag(), dpnId,
+ l2GwDevice.getHwvtepNodeId(), mac.getValue()));
+ }
+ return fts;
+ });
}
}
DeleteL2GwDeviceMacsFromElanJob job = new DeleteL2GwDeviceMacsFromElanJob(broker, elanName, l2GwDevice,
macAddresses);
- ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService, job.getJobKey(), "delete remote ucast macs in l2gw devices", job);
+ ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService, job.getJobKey(),
+ "delete remote ucast macs in l2gw devices", job);
}
/**
LOG.trace("No L2 gateway devices in Elan [{}] cache.", elanName);
return;
}
- final ElanInstance elan = elanUtils.getElanInstanceByName(elanName);
+ final ElanInstance elan = ElanUtils.getElanInstanceByName(broker, elanName);
if (elan == null) {
LOG.error("Could not find Elan by name: {}", elanName);
return;
if (localMacs != null && !localMacs.isEmpty()) {
for (final MacAddress mac : localMacs) {
String jobKey = elanName + ":" + mac.getValue();
- ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService, jobKey, "delete l2gw macs from dmac table",
- new Callable<List<ListenableFuture<Void>>>() {
- @Override
- public List<ListenableFuture<Void>> call() {
- List<ListenableFuture<Void>> futures = Lists.newArrayList();
-
- futures.addAll(elanUtils.deleteDmacFlowsToExternalMac(elanTag, dpnId,
- l2GwDevice.getHwvtepNodeId(), mac.getValue()));
- return futures;
- }
- });
+ ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService, jobKey,
+ "delete l2gw macs from dmac table", () -> {
+ List<ListenableFuture<Void>> futures = Lists.newArrayList();
+
+ futures.addAll(elanUtils.deleteDmacFlowsToExternalMac(elanTag, dpnId,
+ l2GwDevice.getHwvtepNodeId(), mac.getValue()));
+ return futures;
+ });
}
}
}
}
List<LocalUcastMacs> lstUcastLocalMacs = l2gwDevice.getUcastLocalMacs();
if (lstUcastLocalMacs != null && !lstUcastLocalMacs.isEmpty()) {
- macs = Lists.transform(lstUcastLocalMacs, new Function<LocalUcastMacs, MacAddress>() {
- @Override
- public MacAddress apply(LocalUcastMacs localUcastMac) {
- return (localUcastMac != null) ? localUcastMac.getMacEntryKey() : null;
- }
- });
+ macs = Lists.transform(lstUcastLocalMacs,
+ localUcastMac -> localUcastMac != null ? localUcastMac.getMacEntryKey() : null);
}
return macs;
}
@Override
public void onFailure(Throwable error) {
- LOG.warn(String.format(
- "Failed during batch delete of elan [%s] macs from l2gw device [%s]. Retrying with sequential deletes.",
- elanName, hwvtepNodeId), error);
+ LOG.warn(String.format("Failed during batch delete of elan [%s] macs from l2gw device [%s]. "
+ + "Retrying with sequential deletes.", elanName, hwvtepNodeId), error);
if (lstElanMacs != null && !lstElanMacs.isEmpty()) {
for (MacAddress mac : lstElanMacs) {
HwvtepUtils.deleteRemoteUcastMac(broker, new NodeId(hwvtepNodeId), logicalSwitch, mac);
}
}
- };
+ }
});
if (LOG.isDebugEnabled()) {
}
WriteTransaction transaction = broker.newWriteOnlyTransaction();
- for (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.devices.Interfaces deviceInterface : hwVtepDevice
+ for (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712
+ .l2gateway.attributes.devices.Interfaces deviceInterface : hwVtepDevice
.getInterfaces()) {
NodeId physicalSwitchNodeId = HwvtepSouthboundUtils.createManagedNodeId(nodeId,
hwVtepDevice.getDeviceName());
NodeId physicalSwitchNodeId = HwvtepSouthboundUtils.createManagedNodeId(nodeId, hwVtepDevice.getDeviceName());
WriteTransaction transaction = broker.newWriteOnlyTransaction();
- for (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.devices.Interfaces deviceInterface : hwVtepDevice
- .getInterfaces()) {
+ for (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712
+ .l2gateway.attributes.devices.Interfaces deviceInterface : hwVtepDevice.getInterfaces()) {
String phyPortName = deviceInterface.getInterfaceName();
if (deviceInterface.getSegmentationIds() != null && !deviceInterface.getSegmentationIds().isEmpty()) {
for (Integer vlanId : deviceInterface.getSegmentationIds()) {
elanName);
List<ListenableFuture<Void>> futures = new ArrayList<>();
- ElanInstance elan = elanUtils.getElanInstanceByName(elanName);
+ ElanInstance elan = ElanUtils.getElanInstanceByName(broker, elanName);
if (elan == null) {
LOG.error("Could not find Elan by name: {}", elanName);
return futures;
TerminationPointKey tpKey = HwvtepSouthboundUtils.getTerminationPointKey(dpnTepIp.getIpv4Address().getValue());
InstanceIdentifier<TerminationPoint> tpPath = HwvtepSouthboundUtils.createTerminationPointId(nodeId, tpKey);
- HwvtepTerminationPointListener.runJobAfterPhysicalLocatorIsAvialable(tpPath, new Runnable() {
- @Override
- public void run() {
- HwvtepUtils.installUcastMacs(broker, externalDevice.getHwvtepNodeId(), staticMacAddresses, elanName,
- dpnTepIp);
- }
- });
+ HwvtepTerminationPointListener.runJobAfterPhysicalLocatorIsAvialable(tpPath, () -> HwvtepUtils
+ .installUcastMacs(broker, externalDevice.getHwvtepNodeId(), staticMacAddresses, elanName, dpnTepIp));
}
public void scheduleDeleteLogicalSwitch(final NodeId hwvtepNodeId, final String lsName) {
TimerTask logicalSwitchDeleteTask = new TimerTask() {
@Override
public void run() {
- Pair<NodeId, String> nodeIdLogicalSwitchNamePair = new ImmutablePair<NodeId, String>(hwvtepNodeId,
+ Pair<NodeId, String> nodeIdLogicalSwitchNamePair = new ImmutablePair<>(hwvtepNodeId,
lsName);
logicalSwitchDeletedTasks.remove(nodeIdLogicalSwitchNamePair);