use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gateway in project netvirt by opendaylight.
the class L2GatewayConnectionUtils method deleteL2GatewayConnection.
public void deleteL2GatewayConnection(L2gatewayConnection input) {
LOG.info("Deleting L2gateway Connection with ID: {}", input.getKey().getUuid());
Uuid networkUuid = input.getNetworkId();
String elanName = networkUuid.getValue();
disAssociateHwvtepsFromElan(elanName, input);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gateway 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.l2gateways.attributes.l2gateways.L2gateway 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.l2gateways.attributes.l2gateways.L2gateway in project netvirt by opendaylight.
the class L2GatewayConnectionUtils method getNeutronL2gateway.
public static L2gateway getNeutronL2gateway(DataBroker broker, Uuid l2GatewayId) {
LOG.debug("getNeutronL2gateway for {}", l2GatewayId.getValue());
InstanceIdentifier<L2gateway> inst = InstanceIdentifier.create(Neutron.class).child(L2gateways.class).child(L2gateway.class, new L2gatewayKey(l2GatewayId));
return MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, inst).orNull();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gateway 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