BUG5764: Hwvtep tunnel update/delete not reflected correctly 93/38293/1
authorVishal Thapar <vishal.thapar@ericsson.com>
Wed, 20 Apr 2016 07:44:21 +0000 (13:14 +0530)
committerSam Hague <shague@redhat.com>
Mon, 2 May 2016 20:02:52 +0000 (20:02 +0000)
1. Adds HwvtepTunnelUpdate/Delete command patterns
2. Removes tunnel handling from PhysicalSwitchUpdate
3. Adds PhysicalSwitch and locator information to HwvtepDeviceInfo
4. Reorders Aggregator to take care of dependencies
5. Renames classes to distinguish from ones in transact. This makes easier
to troubleshoot.

Change-Id: I1269127118c11961f552df286292ed8f5b4ef50d
Signed-off-by: Vishal Thapar <vishal.thapar@ericsson.com>
18 files changed:
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepDeviceInfo.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundMapper.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepLogicalSwitchRemoveCommand.java [moved from hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/LogicalSwitchRemoveCommand.java with 91% similarity]
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepLogicalSwitchUpdateCommand.java [moved from hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/LogicalSwitchUpdateCommand.java with 95% similarity]
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepMacEntriesRemoveCommand.java [moved from hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/MacEntriesRemoveCommand.java with 96% similarity]
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepMcastMacsLocalUpdateCommand.java [moved from hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/McastMacsLocalUpdateCommand.java with 97% similarity]
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepMcastMacsRemoteUpdateCommand.java [moved from hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/McastMacsRemoteUpdateCommand.java with 97% similarity]
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepOperationalCommandAggregator.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepPhysicalLocatorRemoveCommand.java [moved from hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/PhysicalLocatorRemoveCommand.java with 82% similarity]
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepPhysicalLocatorUpdateCommand.java [moved from hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/PhysicalLocatorUpdateCommand.java with 92% similarity]
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepPhysicalPortRemoveCommand.java [moved from hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/PhysicalPortRemoveCommand.java with 91% similarity]
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepPhysicalPortUpdateCommand.java [moved from hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/PhysicalPortUpdateCommand.java with 97% similarity]
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepPhysicalSwitchRemoveCommand.java [moved from hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/PhysicalSwitchRemoveCommand.java with 89% similarity]
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepPhysicalSwitchUpdateCommand.java [moved from hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/PhysicalSwitchUpdateCommand.java with 57% similarity]
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepTunnelRemoveCommand.java [new file with mode: 0644]
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepTunnelUpdateCommand.java [new file with mode: 0644]
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepUcastMacsLocalUpdateCommand.java [moved from hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/UcastMacsLocalUpdateCommand.java with 96% similarity]
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepUcastMacsRemoteUpdateCommand.java [moved from hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/UcastMacsRemoteUpdateCommand.java with 96% similarity]

index 1cadd9d0b5c791f69b73fe4404b304614c08fd47..6ac4a94dc2d446935ba811e97285f04bafe57535 100644 (file)
@@ -13,30 +13,38 @@ import java.util.Map;
 
 import org.opendaylight.ovsdb.lib.notation.UUID;
 import org.opendaylight.ovsdb.schema.hardwarevtep.LogicalSwitch;
+import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalLocator;
+import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalSwitch;
 
 /*
  * HwvtepDeviceInfo is used to store some of the table entries received
  * in updates from a Hwvtep device. There will be one instance of this per
  * Hwvtep device connected. Table entries are stored in a map keyed by
  * uuids of respective rows.
- * 
+ *
  * Purpose of this class is to provide data present in tables which
  * were updated in a previous transaction and are not available in
  * current updatedRows. This allows us to handle updates for Tables
  * which reference other tables and need information in those tables
  * to add data to Operational data store.
- * 
+ *
  * e.g. Mac-entries in data store use logical-switch-ref as one of the
  * keys. Mac-entry updates from switch rarely contain Logical_Switch
  * table entries. To add mac-entries we need table entries from
  * Logical_Switch table which were created in an earlier update.
- * 
+ *
  */
 public class HwvtepDeviceInfo {
     private Map<UUID, LogicalSwitch> logicalSwitches = null;
+    private Map<UUID, PhysicalSwitch> physicalSwitches = null;
+    private Map<UUID, PhysicalLocator> physicalLocators = null;
+    private Map<UUID, UUID> mapTunnelToPhysicalSwitch = null;
 
     public HwvtepDeviceInfo() {
         this.logicalSwitches = new HashMap<>();
+        this.physicalSwitches = new HashMap<>();
+        this.physicalLocators = new HashMap<>();
+        this.mapTunnelToPhysicalSwitch = new HashMap<>();
     }
 
     public void putLogicalSwitch(UUID uuid, LogicalSwitch lSwitch) {
@@ -54,4 +62,53 @@ public class HwvtepDeviceInfo {
     public Map<UUID, LogicalSwitch> getLogicalSwitches() {
         return logicalSwitches;
     }
+
+    public void putPhysicalSwitch(UUID uuid, PhysicalSwitch pSwitch) {
+        physicalSwitches.put(uuid, pSwitch);
+    }
+
+    public PhysicalSwitch getPhysicalSwitch(UUID uuid) {
+        return physicalSwitches.get(uuid);
+    }
+
+    public PhysicalSwitch removePhysicalSwitch(UUID uuid) {
+        return physicalSwitches.remove(uuid);
+    }
+
+    public Map<UUID, PhysicalSwitch> getPhysicalSwitches() {
+        return physicalSwitches;
+    }
+
+    public void putPhysicalLocator(UUID uuid, PhysicalLocator pLocator) {
+        physicalLocators.put(uuid, pLocator);
+    }
+
+    public PhysicalLocator getPhysicalLocator(UUID uuid) {
+        return physicalLocators.get(uuid);
+    }
+
+    public PhysicalLocator removePhysicalLocator(UUID uuid) {
+        return physicalLocators.remove(uuid);
+    }
+
+    public Map<UUID, PhysicalLocator> getPhysicalLocators() {
+        return physicalLocators;
+    }
+
+    public void putPhysicalSwitchForTunnel(UUID uuid, UUID psUUID) {
+        mapTunnelToPhysicalSwitch.put(uuid, psUUID);
+    }
+
+    public PhysicalSwitch getPhysicalSwitchForTunnel(UUID uuid) {
+        return physicalSwitches.get(mapTunnelToPhysicalSwitch.get(uuid));
+    }
+
+    public void removePhysicalSwitchForTunnel(UUID uuid) {
+        mapTunnelToPhysicalSwitch.remove(uuid);
+    }
+
+    public Map<UUID, UUID> getPhysicalSwitchesForTunnels() {
+        return mapTunnelToPhysicalSwitch;
+    }
+
 }
index 6b76159984b6415cb687a2a1ebbb7bd777599c04..402ebb9587967794a20df46a5c44ddb4e229722c 100644 (file)
@@ -27,13 +27,17 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.ConnectionInfo;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitchesKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.Tunnels;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.TunnelsKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.port.attributes.VlanBindings;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.port.attributes.VlanBindingsKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.EncapsulationTypeBase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.EncapsulationTypeVxlanOverIpv4;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalPortAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.ConnectionInfoBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
@@ -178,6 +182,16 @@ public class HwvtepSouthboundMapper {
         return iid;
     }
 
+    public static InstanceIdentifier<Tunnels> createInstanceIdentifier( InstanceIdentifier<Node> nodeIid,
+                    InstanceIdentifier<TerminationPoint> localTpIid, InstanceIdentifier<TerminationPoint> remoteTpIid) {
+
+        TunnelsKey tunnelsKey = new TunnelsKey(new HwvtepPhysicalLocatorRef(localTpIid),
+                                               new HwvtepPhysicalLocatorRef(remoteTpIid));
+        InstanceIdentifier<Tunnels> tunnelInstanceId = nodeIid.builder().augmentation(PhysicalSwitchAugmentation.class)
+                                                       .child(Tunnels.class, tunnelsKey).build();
+        return tunnelInstanceId;
+    }
+
     public static Class<? extends EncapsulationTypeBase> createEncapsulationType(String type) {
         Preconditions.checkNotNull(type);
         if (type.isEmpty()) {
@@ -23,9 +23,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hw
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitchesKey;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-public class LogicalSwitchRemoveCommand extends AbstractTransactionCommand {
+public class HwvtepLogicalSwitchRemoveCommand extends AbstractTransactionCommand {
 
-    public LogicalSwitchRemoveCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
+    public HwvtepLogicalSwitchRemoveCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
         super(key, updates, dbSchema);
     }
 
@@ -35,11 +35,11 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 import com.google.common.base.Optional;
 
-public class LogicalSwitchUpdateCommand extends AbstractTransactionCommand {
+public class HwvtepLogicalSwitchUpdateCommand extends AbstractTransactionCommand {
 
     private Map<UUID, LogicalSwitch> updatedLSRows;
 
-    public LogicalSwitchUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
+    public HwvtepLogicalSwitchUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
         super(key, updates, dbSchema);
         updatedLSRows = TyperUtils.extractRowsUpdated(LogicalSwitch.class, getUpdates(), getDbSchema());
     }
@@ -39,11 +39,11 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class MacEntriesRemoveCommand extends AbstractTransactionCommand {
+public class HwvtepMacEntriesRemoveCommand extends AbstractTransactionCommand {
 
-    private static final Logger LOG = LoggerFactory.getLogger(MacEntriesRemoveCommand.class);
+    private static final Logger LOG = LoggerFactory.getLogger(HwvtepMacEntriesRemoveCommand.class);
 
-    public MacEntriesRemoveCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
+    public HwvtepMacEntriesRemoveCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
         super(key, updates, dbSchema);
     }
 
@@ -44,13 +44,13 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-public class McastMacsLocalUpdateCommand extends AbstractTransactionCommand {
+public class HwvtepMcastMacsLocalUpdateCommand extends AbstractTransactionCommand {
 
     private Map<UUID, McastMacsLocal> updatedMMacsLocalRows;
     private Map<UUID, PhysicalLocatorSet> updatedPLocSetRows;
     private Map<UUID, PhysicalLocator> updatedPLocRows;
 
-    public McastMacsLocalUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
+    public HwvtepMcastMacsLocalUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
         super(key, updates, dbSchema);
         updatedMMacsLocalRows = TyperUtils.extractRowsUpdated(McastMacsLocal.class, getUpdates(), getDbSchema());
         updatedPLocSetRows = TyperUtils.extractRowsUpdated(PhysicalLocatorSet.class, getUpdates(), getDbSchema());
@@ -46,13 +46,13 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-public class McastMacsRemoteUpdateCommand extends AbstractTransactionCommand {
+public class HwvtepMcastMacsRemoteUpdateCommand extends AbstractTransactionCommand {
 
     private Map<UUID, McastMacsRemote> updatedMMacsRemoteRows;
     private Map<UUID, PhysicalLocatorSet> updatedPLocSetRows;
     private Map<UUID, PhysicalLocator> updatedPLocRows;
 
-    public McastMacsRemoteUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
+    public HwvtepMcastMacsRemoteUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
         super(key, updates, dbSchema);
         updatedMMacsRemoteRows = TyperUtils.extractRowsUpdated(McastMacsRemote.class, getUpdates(), getDbSchema());
         updatedPLocSetRows = TyperUtils.extractRowsUpdated(PhysicalLocatorSet.class, getUpdates(), getDbSchema());
index 2f8d65cb5410ae612bd898d3d8ad32381a442387..f8eabbcd5d36221bcad651bd3c064a71ca54d63e 100644 (file)
@@ -23,21 +23,23 @@ public class HwvtepOperationalCommandAggregator implements TransactionCommand {
     public HwvtepOperationalCommandAggregator(HwvtepConnectionInstance key,TableUpdates updates,
             DatabaseSchema dbSchema) {
         commands.add(new GlobalUpdateCommand(key, updates, dbSchema));
-        commands.add(new PhysicalSwitchUpdateCommand(key, updates, dbSchema));
-        commands.add(new PhysicalSwitchRemoveCommand(key, updates, dbSchema));
+        commands.add(new HwvtepPhysicalSwitchUpdateCommand(key, updates, dbSchema));
+        commands.add(new HwvtepPhysicalSwitchRemoveCommand(key, updates, dbSchema));
         commands.add(new HwvtepManagerUpdateCommand(key, updates, dbSchema));
         commands.add(new HwvtepManagerRemoveCommand(key, updates, dbSchema));
-        commands.add(new LogicalSwitchUpdateCommand(key, updates, dbSchema));
-        commands.add(new LogicalSwitchRemoveCommand(key, updates, dbSchema));
-        commands.add(new PhysicalPortUpdateCommand(key, updates, dbSchema));
-        commands.add(new PhysicalPortRemoveCommand(key, updates, dbSchema));
-        commands.add(new PhysicalLocatorUpdateCommand(key, updates, dbSchema));
-        commands.add(new PhysicalLocatorRemoveCommand(key, updates, dbSchema));
-        commands.add(new UcastMacsLocalUpdateCommand(key, updates, dbSchema));
-        commands.add(new UcastMacsRemoteUpdateCommand(key, updates, dbSchema));
-        commands.add(new McastMacsLocalUpdateCommand(key, updates, dbSchema));
-        commands.add(new McastMacsRemoteUpdateCommand(key, updates, dbSchema));
-        commands.add(new MacEntriesRemoveCommand(key, updates, dbSchema));
+        commands.add(new HwvtepLogicalSwitchUpdateCommand(key, updates, dbSchema));
+        commands.add(new HwvtepLogicalSwitchRemoveCommand(key, updates, dbSchema));
+        commands.add(new HwvtepPhysicalPortUpdateCommand(key, updates, dbSchema));
+        commands.add(new HwvtepPhysicalPortRemoveCommand(key, updates, dbSchema));
+        commands.add(new HwvtepPhysicalLocatorUpdateCommand(key, updates, dbSchema));
+        commands.add(new HwvtepTunnelUpdateCommand(key, updates, dbSchema));
+        commands.add(new HwvtepTunnelRemoveCommand(key, updates, dbSchema));
+        commands.add(new HwvtepPhysicalLocatorRemoveCommand(key, updates, dbSchema));
+        commands.add(new HwvtepUcastMacsLocalUpdateCommand(key, updates, dbSchema));
+        commands.add(new HwvtepUcastMacsRemoteUpdateCommand(key, updates, dbSchema));
+        commands.add(new HwvtepMcastMacsLocalUpdateCommand(key, updates, dbSchema));
+        commands.add(new HwvtepMcastMacsRemoteUpdateCommand(key, updates, dbSchema));
+        commands.add(new HwvtepMacEntriesRemoveCommand(key, updates, dbSchema));
     }
 
     @Override
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -22,9 +22,9 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-public class PhysicalLocatorRemoveCommand extends AbstractTransactionCommand {
+public class HwvtepPhysicalLocatorRemoveCommand extends AbstractTransactionCommand {
 
-    public PhysicalLocatorRemoveCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
+    public HwvtepPhysicalLocatorRemoveCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
         super(key, updates, dbSchema);
     }
 
@@ -37,6 +37,7 @@ public class PhysicalLocatorRemoveCommand extends AbstractTransactionCommand {
             final InstanceIdentifier<TerminationPoint> nodePath = HwvtepSouthboundMapper
                     .createInstanceIdentifier(connectionIId, pLoc);
             transaction.delete(LogicalDatastoreType.OPERATIONAL, nodePath);
+            getOvsdbConnectionInstance().getDeviceInfo().removePhysicalLocator(pLoc.getUuid());
             //TODO: Check if any cleanup is required
         }
     }
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -33,12 +33,12 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 import com.google.common.base.Optional;
 
-public class PhysicalLocatorUpdateCommand extends AbstractTransactionCommand {
+public class HwvtepPhysicalLocatorUpdateCommand extends AbstractTransactionCommand {
 
     private Map<UUID, PhysicalLocator> updatedPLocRows;
     private Map<UUID, PhysicalLocator> oldPLocRows;
 
-    public PhysicalLocatorUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
+    public HwvtepPhysicalLocatorUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
         super(key, updates, dbSchema);
         updatedPLocRows = TyperUtils.extractRowsUpdated(PhysicalLocator.class, getUpdates(), getDbSchema());
         oldPLocRows = TyperUtils.extractRowsOld(PhysicalLocator.class, getUpdates(), getDbSchema());
@@ -79,6 +79,7 @@ public class PhysicalLocatorUpdateCommand extends AbstractTransactionCommand {
                 } else {
                     transaction.put(LogicalDatastoreType.OPERATIONAL,
                             tpPath, tpBuilder.build());
+                    getOvsdbConnectionInstance().getDeviceInfo().putPhysicalLocator(pLoc.getUuid(), pLoc);
                 }
             }
         }
@@ -28,11 +28,11 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class PhysicalPortRemoveCommand extends AbstractTransactionCommand {
+public class HwvtepPhysicalPortRemoveCommand extends AbstractTransactionCommand {
 
-    private static final Logger LOG = LoggerFactory.getLogger(PhysicalPortRemoveCommand.class);
+    private static final Logger LOG = LoggerFactory.getLogger(HwvtepPhysicalPortRemoveCommand.class);
 
-    public PhysicalPortRemoveCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
+    public HwvtepPhysicalPortRemoveCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
         super(key, updates, dbSchema);
     }
 
@@ -50,14 +50,14 @@ import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Optional;
 
-public class PhysicalPortUpdateCommand extends AbstractTransactionCommand {
+public class HwvtepPhysicalPortUpdateCommand extends AbstractTransactionCommand {
 
-    private static final Logger LOG = LoggerFactory.getLogger(PhysicalPortUpdateCommand.class);
+    private static final Logger LOG = LoggerFactory.getLogger(HwvtepPhysicalPortUpdateCommand.class);
     private Map<UUID, PhysicalPort> updatedPPRows;
     private Map<UUID, PhysicalPort> oldPPRows;
     private Map<UUID, PhysicalSwitch> switchUpdatedRows;
 
-    public PhysicalPortUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
+    public HwvtepPhysicalPortUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
         super(key, updates, dbSchema);
         updatedPPRows = TyperUtils.extractRowsUpdated(PhysicalPort.class, getUpdates(), getDbSchema());
         oldPPRows = TyperUtils.extractRowsOld(PhysicalPort.class, getUpdates(), getDbSchema());
@@ -24,9 +24,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hw
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-public class PhysicalSwitchRemoveCommand extends AbstractTransactionCommand {
+public class HwvtepPhysicalSwitchRemoveCommand extends AbstractTransactionCommand {
 
-    public PhysicalSwitchRemoveCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
+    public HwvtepPhysicalSwitchRemoveCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
         super(key, updates, dbSchema);
     }
 
@@ -43,6 +43,7 @@ public class PhysicalSwitchRemoveCommand extends AbstractTransactionCommand {
             // TODO handle removal of reference to managed switch from model
             transaction.delete(LogicalDatastoreType.OPERATIONAL, nodeIid);
             transaction.delete(LogicalDatastoreType.OPERATIONAL, switchIid);
+            getOvsdbConnectionInstance().getDeviceInfo().removePhysicalSwitch(pSwitch.getUuid());
         }
     }
 
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -11,7 +11,6 @@ package org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -22,7 +21,6 @@ import org.opendaylight.ovsdb.lib.message.TableUpdates;
 import org.opendaylight.ovsdb.lib.notation.UUID;
 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
-import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalLocator;
 import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalSwitch;
 import org.opendaylight.ovsdb.schema.hardwarevtep.Tunnel;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
@@ -31,7 +29,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hw
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalSwitchRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentationBuilder;
@@ -43,16 +40,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hw
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.TunnelIps;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.TunnelIpsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.TunnelIpsKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.Tunnels;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.TunnelsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.tunnel.attributes.BfdLocalConfigs;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.tunnel.attributes.BfdLocalConfigsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.tunnel.attributes.BfdParams;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.tunnel.attributes.BfdParamsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.tunnel.attributes.BfdRemoteConfigs;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.tunnel.attributes.BfdRemoteConfigsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.tunnel.attributes.BfdStatus;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.tunnel.attributes.BfdStatusBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
@@ -63,17 +50,15 @@ import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Optional;
 
-public class PhysicalSwitchUpdateCommand extends AbstractTransactionCommand {
+public class HwvtepPhysicalSwitchUpdateCommand extends AbstractTransactionCommand {
 
-    private static final Logger LOG = LoggerFactory.getLogger(PhysicalSwitchUpdateCommand.class);
+    private static final Logger LOG = LoggerFactory.getLogger(HwvtepPhysicalSwitchUpdateCommand.class);
     private Map<UUID, PhysicalSwitch> updatedPSRows;
     private Map<UUID, Tunnel> updatedTunnelRows;
-    private Map<UUID, PhysicalLocator> updatedPLocRows;
 
-    public PhysicalSwitchUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
+    public HwvtepPhysicalSwitchUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
         super(key, updates, dbSchema);
         updatedPSRows = TyperUtils.extractRowsUpdated(PhysicalSwitch.class, getUpdates(), getDbSchema());
-        updatedPLocRows = TyperUtils.extractRowsUpdated(PhysicalLocator.class, getUpdates(), getDbSchema());
         try {
             updatedTunnelRows = TyperUtils.extractRowsUpdated(Tunnel.class, getUpdates(), getDbSchema());
         } catch (IllegalArgumentException e) {
@@ -102,6 +87,7 @@ public class PhysicalSwitchUpdateCommand extends AbstractTransactionCommand {
             InstanceIdentifier<Node> psIid = getInstanceIdentifier(pSwitch);
             Node psNode = buildPhysicalSwitchNode(connection.get(), pSwitch);
             transaction.merge(LogicalDatastoreType.OPERATIONAL, psIid, psNode);
+            getOvsdbConnectionInstance().getDeviceInfo().putPhysicalSwitch(pSwitch.getUuid(), pSwitch);
             // TODO: Delete entries that are no longer needed
             // TODO: Deletion of tunnels
             // TODO: Deletion of Tunnel BFD config and params
@@ -118,7 +104,7 @@ public class PhysicalSwitchUpdateCommand extends AbstractTransactionCommand {
         setPhysicalSwitchId(psAugmentationBuilder, pSwitch);
         setManagementIps(psAugmentationBuilder, pSwitch);
         setTunnelIps(psAugmentationBuilder, pSwitch);
-        setTunnels(node, psAugmentationBuilder, pSwitch);
+        setTunnels(psAugmentationBuilder, pSwitch);
 
         psNodeBuilder.addAugmentation(PhysicalSwitchAugmentation.class, psAugmentationBuilder.build());
 
@@ -126,116 +112,13 @@ public class PhysicalSwitchUpdateCommand extends AbstractTransactionCommand {
         return psNodeBuilder.build();
     }
 
-    private void setTunnels(Node node, PhysicalSwitchAugmentationBuilder psAugmentationBuilder,
-            PhysicalSwitch pSwitch) {
+    private void setTunnels(PhysicalSwitchAugmentationBuilder psAugmentationBuilder, PhysicalSwitch pSwitch) {
         if (updatedTunnelRows != null && pSwitch.getTunnels() != null && pSwitch.getTunnels().getData() != null
                 && !pSwitch.getTunnels().getData().isEmpty()) {
-            Set<UUID> uuidList = pSwitch.getTunnels().getData();
-            List<Tunnels> tunnelList = new ArrayList<>();
-            TunnelsBuilder tBuilder = new TunnelsBuilder();
-            for (UUID uuid : uuidList) {
-                Tunnel tunnel = updatedTunnelRows.get(uuid);
-                if (tunnel.getLocalColumn().getData() != null) {
-                    PhysicalLocator pLoc = updatedPLocRows.get(tunnel.getLocalColumn().getData());
-                    InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint> tpPath =
-                            HwvtepSouthboundMapper.createInstanceIdentifier(
-                                    HwvtepSouthboundMapper.createInstanceIdentifier(node.getNodeId()), pLoc);
-                    tBuilder.setLocalLocatorRef(new HwvtepPhysicalLocatorRef(tpPath));
-                }
-                tBuilder.setTunnelUuid(new Uuid(uuid.toString()));
-                setBfdLocalConfigs(tBuilder, tunnel);
-                setBfdRemoteConfigs(tBuilder, tunnel);
-                setBfdParams(tBuilder, tunnel);
-                setBfdStatus(tBuilder, tunnel);
-
-                if (tunnel.getRemoteColumn().getData() != null) {
-                    PhysicalLocator pLoc = updatedPLocRows.get(tunnel.getRemoteColumn().getData());
-                    InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint> tpPath =
-                            HwvtepSouthboundMapper.createInstanceIdentifier(
-                                    HwvtepSouthboundMapper.createInstanceIdentifier(node.getNodeId()), pLoc);
-                    tBuilder.setRemoteLocatorRef(new HwvtepPhysicalLocatorRef(tpPath));
-                }
-                tunnelList.add(tBuilder.build());
-            }
-            psAugmentationBuilder.setTunnels(tunnelList);
-        }
-
-    }
-
-    private void setBfdLocalConfigs(TunnelsBuilder tBuilder, Tunnel tunnel) {
-        Map<String, String> localConfigs = tunnel.getBfdConfigLocalColumn().getData();
-        if(localConfigs != null && !localConfigs.isEmpty()) {
-            Set<String> localConfigKeys = localConfigs.keySet();
-            List<BfdLocalConfigs> localConfigsList = new ArrayList<>();
-            String localConfigValue = null;
-            for(String localConfigKey: localConfigKeys) {
-                localConfigValue = localConfigs.get(localConfigKey);
-                if(localConfigValue != null && localConfigKey != null) {
-                    localConfigsList.add(new BfdLocalConfigsBuilder()
-                        .setBfdLocalConfigKey(localConfigKey)
-                        .setBfdLocalConfigValue(localConfigValue)
-                        .build());
-                }
-            }
-            tBuilder.setBfdLocalConfigs(localConfigsList);
-        }
-    }
-
-    private void setBfdRemoteConfigs(TunnelsBuilder tBuilder, Tunnel tunnel) {
-        Map<String, String> remoteConfigs = tunnel.getBfdConfigRemoteColumn().getData();
-        if(remoteConfigs != null && !remoteConfigs.isEmpty()) {
-            Set<String> remoteConfigKeys = remoteConfigs.keySet();
-            List<BfdRemoteConfigs> remoteConfigsList = new ArrayList<>();
-            String remoteConfigValue = null;
-            for(String remoteConfigKey: remoteConfigKeys) {
-                remoteConfigValue = remoteConfigs.get(remoteConfigKey);
-                if(remoteConfigValue != null && remoteConfigKey != null) {
-                    remoteConfigsList.add(new BfdRemoteConfigsBuilder()
-                        .setBfdRemoteConfigKey(remoteConfigKey)
-                        .setBfdRemoteConfigValue(remoteConfigValue)
-                        .build());
-                }
+            // Nothing to do but update deviceInfo cache
+            for(UUID uuid: pSwitch.getTunnels().getData()) {
+                getOvsdbConnectionInstance().getDeviceInfo().putPhysicalSwitchForTunnel(uuid, pSwitch.getUuid());
             }
-            tBuilder.setBfdRemoteConfigs(remoteConfigsList);
-        }
-    }
-
-
-    private void setBfdParams(TunnelsBuilder tBuilder, Tunnel tunnel) {
-        Map<String, String> params = tunnel.getBfdParamsColumn().getData();
-        if(params != null && !params.isEmpty()) {
-            Set<String> paramKeys = params.keySet();
-            List<BfdParams> paramsList = new ArrayList<>();
-            String paramValue = null;
-            for(String paramKey: paramKeys) {
-                paramValue = params.get(paramKey);
-                if(paramValue != null && paramKey != null) {
-                    paramsList.add(new BfdParamsBuilder()
-                        .setBfdParamKey(paramKey)
-                        .setBfdParamValue(paramValue)
-                        .build());
-                }
-            }
-            tBuilder.setBfdParams(paramsList);
-        }
-    }
-
-    private void setBfdStatus(TunnelsBuilder tBuilder, Tunnel tunnel) {
-        Map<String, String> status = tunnel.getBfdStatusColumn().getData();
-        if(status != null && !status.isEmpty()) {
-            Set<String> paramKeys = status.keySet();
-            List<BfdStatus> statusList = new ArrayList<>();
-            String paramValue = null;
-            for(String paramKey: paramKeys) {
-                paramValue = status.get(paramKey);
-                if(paramValue != null && paramKey != null) {
-                    statusList.add(new BfdStatusBuilder()
-                        .setBfdStatusKey(paramKey)
-                        .setBfdStatusValue(paramValue)
-                        .build());
-                }
-            }
-            tBuilder.setBfdStatus(statusList);
         }
     }
 
@@ -305,4 +188,5 @@ public class PhysicalSwitchUpdateCommand extends AbstractTransactionCommand {
         NodeKey nodeKey = getInstanceIdentifier(pSwitch).firstKeyOf(Node.class);
         return nodeKey.getNodeId();
     }
+
 }
diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepTunnelRemoveCommand.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepTunnelRemoveCommand.java
new file mode 100644 (file)
index 0000000..d9d7af3
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md;
+
+import java.util.Collection;
+
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundMapper;
+import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
+import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalLocator;
+import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalSwitch;
+import org.opendaylight.ovsdb.schema.hardwarevtep.Tunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.Tunnels;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class HwvtepTunnelRemoveCommand extends AbstractTransactionCommand {
+
+    private static final Logger LOG = LoggerFactory.getLogger(HwvtepTunnelRemoveCommand.class);
+    Collection<Tunnel> deletedTunnelRows = null;
+
+    public HwvtepTunnelRemoveCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
+        super(key, updates, dbSchema);
+        try {
+            deletedTunnelRows = TyperUtils.extractRowsRemoved(Tunnel.class, getUpdates(), getDbSchema()).values();
+        } catch (IllegalArgumentException e) {
+            LOG.debug("Tunnel Table not supported on this HWVTEP device", e.getMessage());
+        }
+    }
+
+    @Override
+    public void execute(ReadWriteTransaction transaction) {
+        for (Tunnel tunnel : deletedTunnelRows) {
+            try {
+                InstanceIdentifier<Tunnels> tunnelIid = getInstanceIdentifier(getOvsdbConnectionInstance(), tunnel);
+                if(tunnelIid != null) {
+                    transaction.delete(LogicalDatastoreType.OPERATIONAL, tunnelIid);
+                    LOG.trace("Deleting tunnel {}", tunnelIid);
+                }
+                getOvsdbConnectionInstance().getDeviceInfo().removePhysicalSwitchForTunnel(tunnel.getUuid());
+            } catch (Exception e) {
+                LOG.warn("Failed to delete tunnel {}", tunnel, e);
+            }
+        }
+    }
+
+    private InstanceIdentifier<Tunnels> getInstanceIdentifier(HwvtepConnectionInstance client, Tunnel tunnel) {
+        InstanceIdentifier<Tunnels> result = null;
+
+        PhysicalSwitch pSwitch = client.getDeviceInfo().getPhysicalSwitchForTunnel(tunnel.getUuid());
+        if(pSwitch == null){
+            //PhysicalSwitch has already been removed, nothing to do here
+            return null;
+        }
+        InstanceIdentifier<Node> psIid = HwvtepSouthboundMapper.createInstanceIdentifier(client, pSwitch);
+        PhysicalLocator plLocal = getPhysicalLocatorFromUUID((tunnel.getLocalColumn().getData()));
+        PhysicalLocator plRemote = getPhysicalLocatorFromUUID((tunnel.getRemoteColumn().getData()));
+        if(plLocal != null && plRemote != null) {
+            InstanceIdentifier<TerminationPoint> localTpPath = HwvtepSouthboundMapper.createInstanceIdentifier(
+                                                                client.getInstanceIdentifier(), plLocal);
+            InstanceIdentifier<TerminationPoint> remoteTpPath = HwvtepSouthboundMapper.createInstanceIdentifier(
+                                                                client.getInstanceIdentifier(), plRemote);
+            result = HwvtepSouthboundMapper.createInstanceIdentifier(psIid, localTpPath, remoteTpPath);
+        }
+        return result;
+    }
+
+    private PhysicalLocator getPhysicalLocatorFromUUID(UUID uuid) {
+        PhysicalLocator pLoc = getOvsdbConnectionInstance().getDeviceInfo().getPhysicalLocator(uuid);
+        if(pLoc == null) {
+            LOG.trace("Available PhysicalLocators: ",
+                            getOvsdbConnectionInstance().getDeviceInfo().getPhysicalLocators());
+        }
+        return pLoc;
+    }
+
+}
diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepTunnelUpdateCommand.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepTunnelUpdateCommand.java
new file mode 100644 (file)
index 0000000..f3fc4a3
--- /dev/null
@@ -0,0 +1,208 @@
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundMapper;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundUtil;
+import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
+import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalLocator;
+import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalSwitch;
+import org.opendaylight.ovsdb.schema.hardwarevtep.Tunnel;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.Tunnels;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.TunnelsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.tunnel.attributes.BfdLocalConfigs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.tunnel.attributes.BfdLocalConfigsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.tunnel.attributes.BfdParams;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.tunnel.attributes.BfdParamsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.tunnel.attributes.BfdRemoteConfigs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.tunnel.attributes.BfdRemoteConfigsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.tunnel.attributes.BfdStatus;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.tunnel.attributes.BfdStatusBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+
+public class HwvtepTunnelUpdateCommand extends AbstractTransactionCommand {
+
+    private static final Logger LOG = LoggerFactory.getLogger(HwvtepTunnelUpdateCommand.class);
+    private Map<UUID, Tunnel> updatedTunnelRows;
+
+    public HwvtepTunnelUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
+        super(key, updates, dbSchema);
+        try {
+            updatedTunnelRows = TyperUtils.extractRowsUpdated(Tunnel.class, getUpdates(), getDbSchema());
+        } catch (IllegalArgumentException e) {
+            LOG.debug("Tunnel Table not supported on this HWVTEP device", e.getMessage());
+        }
+    }
+
+    @Override
+    public void execute(ReadWriteTransaction transaction) {
+        if(updatedTunnelRows != null && !updatedTunnelRows.isEmpty()) {
+            for (Tunnel tunnel : updatedTunnelRows.values()) {
+                try {
+                    updateTunnel(transaction, tunnel);
+                } catch (Exception e) {
+                    LOG.warn("Exception updating tunnel {}", tunnel, e);
+                }
+            }
+        }
+    }
+
+    private void updateTunnel(ReadWriteTransaction transaction, Tunnel tunnel) {
+        Preconditions.checkNotNull(tunnel.getLocalColumn().getData());
+        Preconditions.checkNotNull(tunnel.getRemoteColumn().getData());
+        final InstanceIdentifier<Node> connectionIId = getOvsdbConnectionInstance().getInstanceIdentifier();
+        Optional<Node> connection = HwvtepSouthboundUtil.readNode(transaction, connectionIId);
+        PhysicalSwitch pSwitch =
+                        getOvsdbConnectionInstance().getDeviceInfo().getPhysicalSwitchForTunnel(tunnel.getUuid());
+        InstanceIdentifier<Node> psIid =
+                        HwvtepSouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance(), pSwitch);
+        InstanceIdentifier<Tunnels> tunnelIid = getInstanceIdentifier(psIid, tunnel);
+        if (connection.isPresent() && pSwitch != null && tunnelIid != null) {
+            TunnelsBuilder tBuilder = new TunnelsBuilder();
+            tBuilder.setLocalLocatorRef(new HwvtepPhysicalLocatorRef(
+                            getPhysicalLocatorRefFromUUID(psIid, (tunnel.getLocalColumn().getData()))));
+            tBuilder.setRemoteLocatorRef(new HwvtepPhysicalLocatorRef(
+                            getPhysicalLocatorRefFromUUID(psIid, (tunnel.getRemoteColumn().getData()))));
+            tBuilder.setTunnelUuid(new Uuid(tunnel.getUuid().toString()));
+            setBfdLocalConfigs(tBuilder, tunnel);
+            setBfdRemoteConfigs(tBuilder, tunnel);
+            setBfdParams(tBuilder, tunnel);
+            setBfdStatus(tBuilder, tunnel);
+            Tunnels updatedTunnel = tBuilder.build();
+            LOG.trace("Built with the intent to store tunnel data {}", updatedTunnel);
+            transaction.merge(LogicalDatastoreType.OPERATIONAL, tunnelIid, updatedTunnel);
+            // TODO: Deletion of Tunnel BFD config and params
+        } else {
+            LOG.warn("Insuficient information. Unable to update tunnel {}", tunnel.getUuid());
+        }
+    }
+
+    private void setBfdLocalConfigs(TunnelsBuilder tBuilder, Tunnel tunnel) {
+        Map<String, String> localConfigs = tunnel.getBfdConfigLocalColumn().getData();
+        if(localConfigs != null && !localConfigs.isEmpty()) {
+            Set<String> localConfigKeys = localConfigs.keySet();
+            List<BfdLocalConfigs> localConfigsList = new ArrayList<>();
+            String localConfigValue = null;
+            for(String localConfigKey: localConfigKeys) {
+                localConfigValue = localConfigs.get(localConfigKey);
+                if(localConfigValue != null && localConfigKey != null) {
+                    localConfigsList.add(new BfdLocalConfigsBuilder()
+                        .setBfdLocalConfigKey(localConfigKey)
+                        .setBfdLocalConfigValue(localConfigValue)
+                        .build());
+                }
+            }
+            tBuilder.setBfdLocalConfigs(localConfigsList);
+        }
+    }
+
+    private void setBfdRemoteConfigs(TunnelsBuilder tBuilder, Tunnel tunnel) {
+        Map<String, String> remoteConfigs = tunnel.getBfdConfigRemoteColumn().getData();
+        if(remoteConfigs != null && !remoteConfigs.isEmpty()) {
+            Set<String> remoteConfigKeys = remoteConfigs.keySet();
+            List<BfdRemoteConfigs> remoteConfigsList = new ArrayList<>();
+            String remoteConfigValue = null;
+            for(String remoteConfigKey: remoteConfigKeys) {
+                remoteConfigValue = remoteConfigs.get(remoteConfigKey);
+                if(remoteConfigValue != null && remoteConfigKey != null) {
+                    remoteConfigsList.add(new BfdRemoteConfigsBuilder()
+                        .setBfdRemoteConfigKey(remoteConfigKey)
+                        .setBfdRemoteConfigValue(remoteConfigValue)
+                        .build());
+                }
+            }
+            tBuilder.setBfdRemoteConfigs(remoteConfigsList);
+        }
+    }
+
+
+    private void setBfdParams(TunnelsBuilder tBuilder, Tunnel tunnel) {
+        Map<String, String> params = tunnel.getBfdParamsColumn().getData();
+        if(params != null && !params.isEmpty()) {
+            Set<String> paramKeys = params.keySet();
+            List<BfdParams> paramsList = new ArrayList<>();
+            String paramValue = null;
+            for(String paramKey: paramKeys) {
+                paramValue = params.get(paramKey);
+                if(paramValue != null && paramKey != null) {
+                    paramsList.add(new BfdParamsBuilder()
+                        .setBfdParamKey(paramKey)
+                        .setBfdParamValue(paramValue)
+                        .build());
+                }
+            }
+            tBuilder.setBfdParams(paramsList);
+        }
+    }
+
+    private void setBfdStatus(TunnelsBuilder tBuilder, Tunnel tunnel) {
+        Map<String, String> status = tunnel.getBfdStatusColumn().getData();
+        if(status != null && !status.isEmpty()) {
+            Set<String> paramKeys = status.keySet();
+            List<BfdStatus> statusList = new ArrayList<>();
+            String paramValue = null;
+            for(String paramKey: paramKeys) {
+                paramValue = status.get(paramKey);
+                if(paramValue != null && paramKey != null) {
+                    statusList.add(new BfdStatusBuilder()
+                        .setBfdStatusKey(paramKey)
+                        .setBfdStatusValue(paramValue)
+                        .build());
+                }
+            }
+            tBuilder.setBfdStatus(statusList);
+        }
+    }
+
+    private InstanceIdentifier<Tunnels> getInstanceIdentifier(InstanceIdentifier<Node> psIid, Tunnel tunnel) {
+        InstanceIdentifier<Tunnels> result = null;
+        InstanceIdentifier<TerminationPoint> localTpPath =
+                        getPhysicalLocatorRefFromUUID(getOvsdbConnectionInstance().getInstanceIdentifier(),
+                                                        (tunnel.getLocalColumn().getData()));
+        InstanceIdentifier<TerminationPoint> remoteTpPath =
+                        getPhysicalLocatorRefFromUUID(getOvsdbConnectionInstance().getInstanceIdentifier(),
+                                                        (tunnel.getRemoteColumn().getData()));
+        if(remoteTpPath != null && localTpPath != null ) {
+            result = HwvtepSouthboundMapper.createInstanceIdentifier(psIid, localTpPath, remoteTpPath);
+        }
+        return result;
+    }
+
+    private InstanceIdentifier<TerminationPoint> getPhysicalLocatorRefFromUUID(InstanceIdentifier<Node> nodeIid,
+                                                                               UUID uuid) {
+        PhysicalLocator pLoc = getOvsdbConnectionInstance().getDeviceInfo().getPhysicalLocator(uuid);
+        if(pLoc == null) {
+            LOG.trace("Available PhysicalLocators: ",
+                            getOvsdbConnectionInstance().getDeviceInfo().getPhysicalLocators());
+            return null;
+        }
+        return HwvtepSouthboundMapper.createInstanceIdentifier(nodeIid, pLoc);
+    }
+
+}
@@ -41,12 +41,12 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-public class UcastMacsLocalUpdateCommand extends AbstractTransactionCommand {
+public class HwvtepUcastMacsLocalUpdateCommand extends AbstractTransactionCommand {
 
     private Map<UUID, UcastMacsLocal> updatedUMacsLocalRows;
     private Map<UUID, PhysicalLocator> updatedPLocRows;
 
-    public UcastMacsLocalUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
+    public HwvtepUcastMacsLocalUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
         super(key, updates, dbSchema);
         updatedUMacsLocalRows = TyperUtils.extractRowsUpdated(UcastMacsLocal.class, getUpdates(), getDbSchema());
         updatedPLocRows = TyperUtils.extractRowsUpdated(PhysicalLocator.class, getUpdates(), getDbSchema());
@@ -41,12 +41,12 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 import com.google.common.base.Optional;
 
-public class UcastMacsRemoteUpdateCommand extends AbstractTransactionCommand {
+public class HwvtepUcastMacsRemoteUpdateCommand extends AbstractTransactionCommand {
 
     private final Map<UUID, UcastMacsRemote> updatedUMacsRemoteRows;
     private final Map<UUID, PhysicalLocator> updatedPLocRows;
 
-    public UcastMacsRemoteUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
+    public HwvtepUcastMacsRemoteUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
         super(key, updates, dbSchema);
         updatedUMacsRemoteRows = TyperUtils.extractRowsUpdated(UcastMacsRemote.class, getUpdates(), getDbSchema());
         updatedPLocRows = TyperUtils.extractRowsUpdated(PhysicalLocator.class, getUpdates(), getDbSchema());