use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.l2gatewayconnections.L2gatewayConnection in project netvirt by opendaylight.
the class L2GatewayListener method remove.
@Override
protected void remove(final InstanceIdentifier<L2gateway> identifier, final L2gateway input) {
LOG.info("Removing L2gateway with ID: {}", input.getUuid());
List<L2gatewayConnection> connections = l2gwService.getL2GwConnectionsByL2GatewayId(input.getUuid());
try {
ReadWriteTransaction tx = this.dataBroker.newReadWriteTransaction();
for (L2gatewayConnection connection : connections) {
InstanceIdentifier<L2gatewayConnection> iid = InstanceIdentifier.create(Neutron.class).child(L2gatewayConnections.class).child(L2gatewayConnection.class, connection.getKey());
tx.delete(LogicalDatastoreType.CONFIGURATION, iid);
}
tx.submit().checkedGet();
} catch (TransactionCommitFailedException e) {
LOG.error("Failed to delete associated l2gwconnection while deleting l2gw {} with id beacause of {}", input.getUuid(), e.getLocalizedMessage());
// TODO :retry
}
List<Devices> l2Devices = input.getDevices();
for (Devices l2Device : l2Devices) {
LOG.trace("Removing L2gateway device: {}", l2Device);
removeL2Device(l2Device, input);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.l2gatewayconnections.L2gatewayConnection in project netvirt by opendaylight.
the class L2GatewayListener method update.
@Override
protected void update(InstanceIdentifier<L2gateway> identifier, L2gateway original, L2gateway update) {
LOG.trace("Updating L2gateway : key: {}, original value={}, update value={}", identifier, original, update);
List<L2gatewayConnection> connections = l2gwService.getAssociatedL2GwConnections(Sets.newHashSet(update.getUuid()));
if (connections == null) {
LOG.warn("There are no connections associated with l2 gateway uuid {} name {}", update.getUuid(), update.getName());
return;
}
if (original.getDevices() == null) {
connections.forEach((connection) -> l2gwService.addL2GatewayConnection(connection));
return;
}
jobCoordinator.enqueueJob("l2gw.update", () -> {
ReadWriteTransaction transaction = dataBroker.newReadWriteTransaction();
DeviceInterfaces updatedDeviceInterfaces = new DeviceInterfaces(update);
List<ListenableFuture<Void>> fts = new ArrayList<>();
original.getDevices().stream().filter((originalDevice) -> originalDevice.getInterfaces() != null).forEach((originalDevice) -> {
String deviceName = originalDevice.getDeviceName();
L2GatewayDevice l2GwDevice = l2GatewayCache.get(deviceName);
NodeId physicalSwitchNodeId = HwvtepSouthboundUtils.createManagedNodeId(new NodeId(l2GwDevice.getHwvtepNodeId()), deviceName);
originalDevice.getInterfaces().stream().filter((intf) -> !updatedDeviceInterfaces.containsInterface(deviceName, intf.getInterfaceName())).forEach((intf) -> {
connections.forEach((connection) -> {
Integer vlanId = connection.getSegmentId();
if (intf.getSegmentationIds() != null && !intf.getSegmentationIds().isEmpty()) {
for (Integer vlan : intf.getSegmentationIds()) {
HwvtepUtils.deleteVlanBinding(transaction, physicalSwitchNodeId, intf.getInterfaceName(), vlan);
}
} else {
LOG.debug("Deleting vlan binding {} {} {}", physicalSwitchNodeId, intf.getInterfaceName(), vlanId);
HwvtepUtils.deleteVlanBinding(transaction, physicalSwitchNodeId, intf.getInterfaceName(), vlanId);
}
});
});
});
fts.add(transaction.submit());
Futures.addCallback(fts.get(0), new FutureCallback<Void>() {
@Override
public void onSuccess(Void success) {
LOG.debug("Successfully deleted vlan bindings for l2gw update {}", update);
connections.forEach((l2GwConnection) -> l2gwService.addL2GatewayConnection(l2GwConnection, null, update));
}
@Override
public void onFailure(Throwable throwable) {
LOG.error("Failed to delete vlan bindings as part of l2gw udpate {}", update);
}
}, MoreExecutors.directExecutor());
return fts;
}, SystemPropertyReader.getDataStoreJobCoordinatorMaxRetries());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.l2gatewayconnections.L2gatewayConnection in project netvirt by opendaylight.
the class ElanL2GatewayUtils method updateVlanBindingsInL2GatewayDevice.
/**
* Update vlan bindings in l2 gateway device.
*
* @param nodeId
* the node id
* @param logicalSwitchName
* the logical switch name
* @param hwVtepDevice
* the hardware device
* @param defaultVlanId
* the default vlan id
* @return the listenable future
*/
public ListenableFuture<Void> 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.";
LOG.error(errMsg);
return Futures.immediateFailedFuture(new RuntimeException(errMsg));
}
return txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
for (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.devices.Interfaces deviceInterface : hwVtepDevice.getInterfaces()) {
// 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
// with port reconcilation.
List<VlanBindings> vlanBindings = new ArrayList<>();
if (deviceInterface.getSegmentationIds() != null && !deviceInterface.getSegmentationIds().isEmpty()) {
for (Integer vlanId : deviceInterface.getSegmentationIds()) {
vlanBindings.add(HwvtepSouthboundUtils.createVlanBinding(nodeId, vlanId, logicalSwitchName));
}
} else {
// Use defaultVlanId (specified in L2GatewayConnection) if Vlan
// ID not specified at interface level.
vlanBindings.add(HwvtepSouthboundUtils.createVlanBinding(nodeId, defaultVlanId, logicalSwitchName));
}
HwvtepUtils.mergeVlanBindings(tx, nodeId, hwVtepDevice.getDeviceName(), deviceInterface.getInterfaceName(), vlanBindings);
}
LOG.info("Updated Hwvtep VlanBindings in config DS. NodeID: {}, LogicalSwitch: {}", nodeId.getValue(), logicalSwitchName);
});
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.l2gatewayconnections.L2gatewayConnection in project netvirt by opendaylight.
the class L2GatewayConnectionUtils method getL2GwConnectionsByL2GatewayId.
/**
* Gets the associated l2 gw connections.
*
* @param l2GatewayId the l2 gateway id
*
* @return the associated l2 gw connections
*/
public List<L2gatewayConnection> getL2GwConnectionsByL2GatewayId(Uuid l2GatewayId) {
List<L2gatewayConnection> l2GwConnections = new ArrayList<>();
List<L2gatewayConnection> allL2GwConns = getAllL2gatewayConnections(broker);
for (L2gatewayConnection l2GwConn : allL2GwConns) {
if (l2GwConn.getL2gatewayId().equals(l2GatewayId)) {
l2GwConnections.add(l2GwConn);
}
}
return l2GwConnections;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.l2gatewayconnections.L2gatewayConnection in project netvirt by opendaylight.
the class L2GatewayConnectionUtils method disAssociateHwvtepsFromElan.
private void disAssociateHwvtepsFromElan(String elanName, L2gatewayConnection input) {
Integer defaultVlan = input.getSegmentId();
List<L2GatewayDevice> l2Devices = ElanL2GwCacheUtils.getAllElanDevicesFromCache();
List<Devices> l2gwDevicesToBeDeleted = new ArrayList<>();
for (L2GatewayDevice elanL2gwDevice : l2Devices) {
if (elanL2gwDevice.getL2GatewayIds().contains(input.getKey().getUuid())) {
l2gwDevicesToBeDeleted.addAll(elanL2gwDevice.getDevicesForL2gwConnectionId(input.getKey().getUuid()));
}
}
if (l2gwDevicesToBeDeleted.isEmpty()) {
// delete logical switch
Uuid l2GatewayId = input.getL2gatewayId();
L2gateway l2Gateway = L2GatewayConnectionUtils.getNeutronL2gateway(broker, l2GatewayId);
if (l2Gateway == null) {
LOG.error("Failed to find the l2gateway for the connection {}", input.getUuid());
return;
} else {
l2gwDevicesToBeDeleted.addAll(l2Gateway.getDevices());
}
}
for (Devices l2Device : l2gwDevicesToBeDeleted) {
String l2DeviceName = l2Device.getDeviceName();
L2GatewayDevice l2GatewayDevice = l2GatewayCache.get(l2DeviceName);
String hwvtepNodeId = l2GatewayDevice.getHwvtepNodeId();
boolean isLastL2GwConnDeleted = false;
L2GatewayDevice elanL2GwDevice = ElanL2GwCacheUtils.getL2GatewayDeviceFromCache(elanName, hwvtepNodeId);
if (elanL2GwDevice != null && isLastL2GwConnBeingDeleted(elanL2GwDevice)) {
// Delete L2 Gateway device from 'ElanL2GwDevice' cache
LOG.debug("Elan L2Gw Conn cache removed for id {}", hwvtepNodeId);
ElanL2GwCacheUtils.removeL2GatewayDeviceFromCache(elanName, hwvtepNodeId);
isLastL2GwConnDeleted = true;
} else {
Uuid l2GwConnId = input.getKey().getUuid();
LOG.debug("Elan L2Gw Conn cache with id {} is being referred by other L2Gw Conns; so only " + "L2 Gw Conn {} reference is removed", hwvtepNodeId, l2GwConnId);
if (elanL2GwDevice != null) {
elanL2GwDevice.removeL2GatewayId(l2GwConnId);
} else {
isLastL2GwConnDeleted = true;
}
}
DisAssociateHwvtepFromElanJob disAssociateHwvtepToElanJob = new DisAssociateHwvtepFromElanJob(elanL2GatewayUtils, elanL2GatewayMulticastUtils, elanL2GwDevice, elanName, () -> elanInstanceCache.get(elanName).orNull(), l2Device, defaultVlan, hwvtepNodeId, isLastL2GwConnDeleted);
elanClusterUtils.runOnlyInOwnerNode(disAssociateHwvtepToElanJob.getJobKey(), "remove l2gw connection job", disAssociateHwvtepToElanJob);
}
}
Aggregations