use of org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice in project netvirt by opendaylight.
the class ElanL2GatewayUtils method getL2GwDeviceLocalMacsAndRunCallback.
public void getL2GwDeviceLocalMacsAndRunCallback(String elanName, L2GatewayDevice l2gwDevice, Function<Collection<MacAddress>, Void> function) {
if (l2gwDevice == null) {
return;
}
Set<MacAddress> macs = new HashSet<>();
Collection<LocalUcastMacs> lstUcastLocalMacs = l2gwDevice.getUcastLocalMacs();
if (!lstUcastLocalMacs.isEmpty()) {
macs.addAll(lstUcastLocalMacs.stream().filter(Objects::nonNull).map(mac -> new MacAddress(mac.getMacEntryKey().getValue().toLowerCase())).collect(Collectors.toList()));
}
InstanceIdentifier<Node> nodeIid = HwvtepSouthboundUtils.createInstanceIdentifier(new NodeId(l2gwDevice.getHwvtepNodeId()));
Futures.addCallback(broker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, nodeIid), new FutureCallback<Optional<Node>>() {
@Override
public void onSuccess(Optional<Node> configNode) {
if (configNode != null && configNode.isPresent()) {
HwvtepGlobalAugmentation augmentation = configNode.get().getAugmentation(HwvtepGlobalAugmentation.class);
if (augmentation != null && augmentation.getLocalUcastMacs() != null) {
macs.addAll(augmentation.getLocalUcastMacs().stream().filter(mac -> getLogicalSwitchName(mac).equals(elanName)).map(mac -> mac.getMacEntryKey()).collect(Collectors.toSet()));
}
function.apply(macs);
}
}
@Override
public void onFailure(Throwable throwable) {
LOG.error("Failed to read config topology node {}", nodeIid);
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice in project netvirt by opendaylight.
the class ElanL2GatewayUtils method installL2GwUcastMacInElan.
public void installL2GwUcastMacInElan(final ElanInstance elan, final L2GatewayDevice extL2GwDevice, final String macToBeAdded, final LocalUcastMacs localUcastMacs, String interfaceName) {
final String extDeviceNodeId = extL2GwDevice.getHwvtepNodeId();
final String elanInstanceName = elan.getElanInstanceName();
final Collection<DpnInterfaces> elanDpns = getElanDpns(elanInstanceName);
ConcurrentMap<String, L2GatewayDevice> elanL2GwDevices = ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanInstanceName);
// DMAC table
if (elanDpns.size() > 0 || elanL2GwDevices.values().size() > 0) {
String jobKey = elanInstanceName + ":" + macToBeAdded;
IpAddress extL2GwDeviceTepIp = extL2GwDevice.getTunnelIp();
List<PhysAddress> macList = Lists.newArrayList(new PhysAddress(macToBeAdded));
elanClusterUtils.runOnlyInOwnerNode(jobKey, "install l2gw macs in dmac table", () -> {
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), macToBeAdded, elanInstanceName, interfaceName));
}
for (L2GatewayDevice otherDevice : elanL2GwDevices.values()) {
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));
}
}
return futures;
} else {
LOG.trace("Skipping install of dmac flows for mac {} as it is not found in cache", macToBeAdded);
}
return Collections.emptyList();
});
}
}
use of org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice in project netvirt by opendaylight.
the class L2GatewayConnectionUtils method addL2DeviceToElanL2GwCache.
public L2GatewayDevice addL2DeviceToElanL2GwCache(String elanName, L2GatewayDevice l2GatewayDevice, Uuid l2GwConnId, Devices l2Device) {
String l2gwDeviceNodeId = l2GatewayDevice.getHwvtepNodeId();
L2GatewayDevice elanL2GwDevice = ElanL2GwCacheUtils.getL2GatewayDeviceFromCache(elanName, l2gwDeviceNodeId);
if (elanL2GwDevice == null) {
elanL2GwDevice = new L2GatewayDevice(l2GatewayDevice.getDeviceName());
elanL2GwDevice.setHwvtepNodeId(l2gwDeviceNodeId);
elanL2GwDevice.setTunnelIps(l2GatewayDevice.getTunnelIps());
ElanL2GwCacheUtils.addL2GatewayDeviceToCache(elanName, elanL2GwDevice);
LOG.debug("Elan L2GwConn cache created for hwvtep id {}", l2gwDeviceNodeId);
} else {
LOG.debug("Elan L2GwConn cache already exists for hwvtep id {}; updating L2GwConn id {} to it", l2gwDeviceNodeId, l2GwConnId);
}
elanL2GwDevice.addL2GatewayId(l2GwConnId);
elanL2GwDevice.addL2gwConnectionIdToDevice(l2GwConnId, l2Device);
// incase of cluster reboot scenario southbound device would have added more macs
// while odl is down, pull them now
readAndCopyLocalUcastMacsToCache(elanName, l2GatewayDevice);
LOG.trace("Elan L2GwConn cache updated with below details: {}", elanL2GwDevice);
return elanL2GwDevice;
}
use of org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice in project netvirt by opendaylight.
the class L2GatewayConnectionUtils method associateHwvtepsToElan.
private void associateHwvtepsToElan(ElanInstance elanInstance, L2gateway l2Gateway, L2gatewayConnection input, String l2GwDeviceName) {
String elanName = elanInstance.getElanInstanceName();
Integer defaultVlan = input.getSegmentId();
Uuid l2GwConnId = input.getKey().getUuid();
List<Devices> l2Devices = l2Gateway.getDevices();
LOG.trace("Associating ELAN {} with L2Gw Conn Id {} having below L2Gw devices {}", elanName, l2GwConnId, l2Devices);
for (Devices l2Device : l2Devices) {
String l2DeviceName = l2Device.getDeviceName();
// preprovisioning/re-provisioning
if (l2GwDeviceName != null && !l2GwDeviceName.equals(l2DeviceName)) {
LOG.debug("Associating Hwvtep to ELAN is not been processed for {}; as only {} got connected now!", l2DeviceName, l2GwDeviceName);
continue;
}
L2GatewayDevice l2GatewayDevice = l2GatewayCache.get(l2DeviceName);
if (isL2GwDeviceConnected(l2GatewayDevice)) {
NodeId hwvtepNodeId = new NodeId(l2GatewayDevice.getHwvtepNodeId());
// Delete pending delete logical switch task if scheduled
elanL2GatewayUtils.cancelDeleteLogicalSwitch(hwvtepNodeId, ElanL2GatewayUtils.getLogicalSwitchFromElan(elanName));
// Add L2 Gateway device to 'ElanL2GwDevice' cache
boolean createLogicalSwitch;
LogicalSwitches logicalSwitch = HwvtepUtils.getLogicalSwitch(broker, LogicalDatastoreType.CONFIGURATION, hwvtepNodeId, elanName);
if (logicalSwitch == null) {
HwvtepLogicalSwitchListener hwVTEPLogicalSwitchListener = new HwvtepLogicalSwitchListener(elanInstanceCache, elanL2GatewayUtils, elanClusterUtils, elanL2GatewayMulticastUtils, this, l2GatewayDevice, elanName, l2Device, defaultVlan, l2GwConnId);
hwVTEPLogicalSwitchListener.registerListener(LogicalDatastoreType.OPERATIONAL, broker);
closeables.add(hwVTEPLogicalSwitchListener);
createLogicalSwitch = true;
} else {
addL2DeviceToElanL2GwCache(elanName, l2GatewayDevice, l2GwConnId, l2Device);
createLogicalSwitch = false;
}
AssociateHwvtepToElanJob associateHwvtepToElanJob = new AssociateHwvtepToElanJob(broker, elanL2GatewayUtils, elanL2GatewayMulticastUtils, elanInstanceCache, l2GatewayDevice, elanInstance, l2Device, defaultVlan, createLogicalSwitch);
elanClusterUtils.runOnlyInOwnerNode(associateHwvtepToElanJob.getJobKey(), "create logical switch in hwvtep topo", associateHwvtepToElanJob);
} else {
LOG.info("L2GwConn create is not handled for device with id {} as it's not connected", l2DeviceName);
}
}
}
use of org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice in project netvirt by opendaylight.
the class StaleVlanBindingsCleaner method scheduleStaleCleanup.
public void scheduleStaleCleanup(final String deviceName, final InstanceIdentifier<Node> globalNodeIid, final InstanceIdentifier<Node> psNodeIid) {
NodeId psNodeId = psNodeIid.firstKeyOf(Node.class).getNodeId();
cleanupTasks.compute(psNodeId, (key, ft) -> {
if (ft != null) {
ft.cancel(false);
}
return scheduler.getScheduledExecutorService().schedule(() -> {
L2GatewayDevice l2GwDevice = l2GatewayCache.get(deviceName);
NodeId globalNodeId = globalNodeIid.firstKeyOf(Node.class).getNodeId();
Node configNode = MDSALUtil.read(broker, CONFIGURATION, globalNodeIid).or(defaultNode(globalNodeId));
Node configPsNode = MDSALUtil.read(broker, CONFIGURATION, psNodeIid).or(defaultNode(psNodeId));
cleanupStaleLogicalSwitches(l2GwDevice, configNode, configPsNode);
cleanupTasks.remove(psNodeIid.firstKeyOf(Node.class).getNodeId());
}, getCleanupDelay(), TimeUnit.SECONDS);
});
}
Aggregations