Search in sources :

Example 6 with L2gateway

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);
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)

Example 7 with L2gateway

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);
    }
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) L2gatewayConnections(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.L2gatewayConnections) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) Devices(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices) L2gatewayConnection(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.l2gatewayconnections.L2gatewayConnection)

Example 8 with L2gateway

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());
}
Also used : HwvtepSouthboundConstants(org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundConstants) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) IL2gwService(org.opendaylight.netvirt.elanmanager.api.IL2gwService) L2gatewayConnection(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.l2gatewayconnections.L2gatewayConnection) Interfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.devices.Interfaces) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) L2gateways(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.L2gateways) L2gateway(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gateway) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) EntityOwnershipService(org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService) Neutron(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron) HwvtepUtils(org.opendaylight.genius.utils.hwvtep.HwvtepUtils) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) AsyncClusteredDataTreeChangeListenerBase(org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) Map(java.util.Map) MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) HwvtepSouthboundUtils(org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils) Devices(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices) Logger(org.slf4j.Logger) EntityOwnershipUtils(org.opendaylight.genius.utils.clustering.EntityOwnershipUtils) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) Set(java.util.Set) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) SystemPropertyReader(org.opendaylight.genius.utils.SystemPropertyReader) Sets(com.google.common.collect.Sets) FutureCallback(com.google.common.util.concurrent.FutureCallback) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) PostConstruct(javax.annotation.PostConstruct) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) L2gatewayConnections(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.L2gatewayConnections) L2GatewayCache(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache) L2GatewayDevice(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) ItmRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService) ArrayList(java.util.ArrayList) L2GatewayDevice(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) L2gatewayConnection(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.l2gatewayconnections.L2gatewayConnection)

Example 9 with L2gateway

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();
}
Also used : L2gatewayKey(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gatewayKey) L2gateway(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gateway) L2gateways(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.L2gateways)

Example 10 with L2gateway

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);
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) L2gateway(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gateway) Devices(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices) L2GatewayDevice(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice) DisAssociateHwvtepFromElanJob(org.opendaylight.netvirt.elan.l2gw.jobs.DisAssociateHwvtepFromElanJob)

Aggregations

L2GatewayDevice (org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice)7 Devices (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices)7 NodeId (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId)7 L2gateway (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gateway)6 L2gatewayConnection (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.l2gatewayconnections.L2gatewayConnection)5 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)4 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)4 ArrayList (java.util.ArrayList)3 ReadWriteTransaction (org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)2 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)2 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)2 Interfaces (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.devices.Interfaces)2 L2gatewayConnections (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.L2gatewayConnections)2 VlanBindings (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.port.attributes.VlanBindings)2 Sets (com.google.common.collect.Sets)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 HashMap (java.util.HashMap)1