2 * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md;
11 import java.util.Collection;
13 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
16 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundMapper;
17 import org.opendaylight.ovsdb.lib.message.TableUpdates;
18 import org.opendaylight.ovsdb.lib.notation.UUID;
19 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
20 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
21 import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalLocator;
22 import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalSwitch;
23 import org.opendaylight.ovsdb.schema.hardwarevtep.Tunnel;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.Tunnels;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
26 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 public class HwvtepTunnelRemoveCommand extends AbstractTransactionCommand {
33 private static final Logger LOG = LoggerFactory.getLogger(HwvtepTunnelRemoveCommand.class);
34 Collection<Tunnel> deletedTunnelRows = null;
36 public HwvtepTunnelRemoveCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
37 super(key, updates, dbSchema);
39 deletedTunnelRows = TyperUtils.extractRowsRemoved(Tunnel.class, getUpdates(), getDbSchema()).values();
40 } catch (IllegalArgumentException e) {
41 LOG.debug("Tunnel Table not supported on this HWVTEP device", e.getMessage());
46 public void execute(ReadWriteTransaction transaction) {
47 for (Tunnel tunnel : deletedTunnelRows) {
49 InstanceIdentifier<Tunnels> tunnelIid = getInstanceIdentifier(getOvsdbConnectionInstance(), tunnel);
50 if(tunnelIid != null) {
51 transaction.delete(LogicalDatastoreType.OPERATIONAL, tunnelIid);
52 LOG.trace("Deleting tunnel {}", tunnelIid);
54 getOvsdbConnectionInstance().getDeviceInfo().removePhysicalSwitchForTunnel(tunnel.getUuid());
55 } catch (Exception e) {
56 LOG.warn("Failed to delete tunnel {}", tunnel, e);
61 private InstanceIdentifier<Tunnels> getInstanceIdentifier(HwvtepConnectionInstance client, Tunnel tunnel) {
62 InstanceIdentifier<Tunnels> result = null;
64 PhysicalSwitch pSwitch = client.getDeviceInfo().getPhysicalSwitchForTunnel(tunnel.getUuid());
66 //PhysicalSwitch has already been removed, nothing to do here
69 InstanceIdentifier<Node> psIid = HwvtepSouthboundMapper.createInstanceIdentifier(client, pSwitch);
70 PhysicalLocator plLocal = getPhysicalLocatorFromUUID((tunnel.getLocalColumn().getData()));
71 PhysicalLocator plRemote = getPhysicalLocatorFromUUID((tunnel.getRemoteColumn().getData()));
72 if(plLocal != null && plRemote != null) {
73 InstanceIdentifier<TerminationPoint> localTpPath = HwvtepSouthboundMapper.createInstanceIdentifier(
74 client.getInstanceIdentifier(), plLocal);
75 InstanceIdentifier<TerminationPoint> remoteTpPath = HwvtepSouthboundMapper.createInstanceIdentifier(
76 client.getInstanceIdentifier(), plRemote);
77 result = HwvtepSouthboundMapper.createInstanceIdentifier(psIid, localTpPath, remoteTpPath);
82 private PhysicalLocator getPhysicalLocatorFromUUID(UUID uuid) {
83 PhysicalLocator pLoc = getOvsdbConnectionInstance().getDeviceInfo().getPhysicalLocator(uuid);
85 LOG.trace("Available PhysicalLocators: ",
86 getOvsdbConnectionInstance().getDeviceInfo().getPhysicalLocators());