Merge "BUG-5737: enable OVSDB Maven site"
authorSam Hague <shague@redhat.com>
Mon, 2 May 2016 21:33:36 +0000 (21:33 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 2 May 2016 21:33:36 +0000 (21:33 +0000)
25 files changed:
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionInstance.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepDeviceInfo.java [new file with mode: 0644]
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundMapper.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/McastMacsLocalRemoveCommand.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/McastMacsRemoteRemoveCommand.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/UcastMacsLocalRemoveCommand.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/UcastMacsRemoteRemoveCommand.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 84% 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 93% 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 92% 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 94% 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 95% 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 94% 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 93% 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 93% similarity]
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbPortUpdateCommand.java
southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbPortUpdateCommandTest.java

index db05b9a1dbab1d8113dc70880a676274199c678b..e3b124a9bab4a2b433042cc96fb68b6927c84e58 100644 (file)
@@ -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,
@@ -65,6 +65,7 @@ public class HwvtepConnectionInstance implements OvsdbClient{
     private Entity connectedEntity;
     private EntityOwnershipCandidateRegistration deviceOwnershipCandidateRegistration;
     private HwvtepGlobalAugmentation initialCreatedData = null;
+    private HwvtepDeviceInfo deviceInfo;
 
 
     HwvtepConnectionInstance (ConnectionInfo key,OvsdbClient client,
@@ -73,6 +74,7 @@ public class HwvtepConnectionInstance implements OvsdbClient{
         this.client = client;
         this.instanceIdentifier = iid;
         this.txInvoker = txInvoker;
+        this.deviceInfo = new HwvtepDeviceInfo();
     }
 
     public void transact(TransactCommand command) {
@@ -293,4 +295,9 @@ public class HwvtepConnectionInstance implements OvsdbClient{
     public void setHwvtepGlobalAugmentation(HwvtepGlobalAugmentation hwvtepGlobalData) {
         this.initialCreatedData = hwvtepGlobalData;
     }
+
+    public HwvtepDeviceInfo getDeviceInfo() {
+        return this.deviceInfo;
+    }
+
 }
diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepDeviceInfo.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepDeviceInfo.java
new file mode 100644 (file)
index 0000000..6ac4a94
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * 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;
+
+import java.util.HashMap;
+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) {
+        logicalSwitches.put(uuid, lSwitch);
+    }
+
+    public LogicalSwitch getLogicalSwitch(UUID uuid) {
+        return logicalSwitches.get(uuid);
+    }
+
+    public LogicalSwitch removeLogicalSwitch(UUID uuid) {
+        return logicalSwitches.remove(uuid);
+    }
+
+    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()) {
index 109914e11fee0d5f0e694b08e11a09d20d998d42..9490371119fe312b7c9ecd17334722eb6b239178 100644 (file)
@@ -119,7 +119,7 @@ public class McastMacsLocalRemoveCommand extends AbstractTransactCommand {
                         for (LocalMcastMacs macBefore: macListBefore) {
                             int i = 0;
                             for(; i < macListUpdated.size(); i++) {
-                                if (macBefore.getMacEntryKey().equals(macListUpdated.get(i).getMacEntryKey())) {
+                                if (macBefore.getKey().equals(macListUpdated.get(i).getKey())) {
                                     break;
                                 }
                             }
index 78fe8e657c0681ab840fe947f0a9c87764319d3f..a02eae68f7fead7ddfb2a85df32cfef307eadd44 100644 (file)
@@ -119,7 +119,7 @@ public class McastMacsRemoteRemoveCommand extends AbstractTransactCommand {
                         for (RemoteMcastMacs macBefore: macListBefore) {
                             int i = 0;
                             for(; i < macListUpdated.size(); i++) {
-                                if (macBefore.getMacEntryKey().equals(macListUpdated.get(i).getMacEntryKey())) {
+                                if (macBefore.getKey().equals(macListUpdated.get(i).getKey())) {
                                     break;
                                 }
                             }
index 85e175d7253b9540579b38d86071093f2487bfdb..c563c675ab2d35057329d90241f19086fc538d0d 100644 (file)
@@ -118,7 +118,7 @@ public class UcastMacsLocalRemoveCommand extends AbstractTransactCommand {
                         for (LocalUcastMacs macBefore: macListBefore) {
                             int i = 0;
                             for(; i < macListUpdated.size(); i++) {
-                                if (macBefore.getMacEntryKey().equals(macListUpdated.get(i).getMacEntryKey())) {
+                                if (macBefore.getKey().equals(macListUpdated.get(i).getKey())) {
                                     break;
                                 }
                             }
index 482c0d7f2ed97ebddaafa22c746f6b9033a83654..3126431b9696ce459e3570a9a74c50a8cfa39d31 100644 (file)
@@ -118,7 +118,7 @@ public class UcastMacsRemoteRemoveCommand extends AbstractTransactCommand {
                         for (RemoteUcastMacs macBefore: macListBefore) {
                             int i = 0;
                             for(; i < macListUpdated.size(); i++) {
-                                if (macBefore.getMacEntryKey().equals(macListUpdated.get(i).getMacEntryKey())) {
+                                if (macBefore.getKey().equals(macListUpdated.get(i).getKey())) {
                                     break;
                                 }
                             }
@@ -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,
@@ -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);
     }
 
@@ -39,6 +39,7 @@ public class LogicalSwitchRemoveCommand extends AbstractTransactionCommand {
                     .child(LogicalSwitches.class, new LogicalSwitchesKey(new HwvtepNodeName(lSwitch.getName())));
             // TODO Delete any references
             transaction.delete(LogicalDatastoreType.OPERATIONAL, switchIid);
+            getOvsdbConnectionInstance().getDeviceInfo().removeLogicalSwitch(lSwitch.getUuid());
         }
     }
 
@@ -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());
     }
@@ -57,6 +57,7 @@ public class LogicalSwitchUpdateCommand extends AbstractTransactionCommand {
         if (connection.isPresent()) {
             Node connectionNode = buildConnectionNode(lSwitch);
             transaction.merge(LogicalDatastoreType.OPERATIONAL, connectionIId, connectionNode);
+            getOvsdbConnectionInstance().getDeviceInfo().putLogicalSwitch(lSwitch.getUuid(), lSwitch);
             // TODO: Delete entries that are no longer needed
         }
     }
@@ -9,8 +9,6 @@
 package org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md;
 
 import java.util.Collection;
-import java.util.Map;
-
 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;
@@ -41,14 +39,12 @@ 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);
-    Map<UUID, LogicalSwitch> lSwitchUpdatedRows;
+    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);
-        lSwitchUpdatedRows = TyperUtils.extractRowsUpdated(LogicalSwitch.class, getUpdates(), getDbSchema());
     }
 
 
@@ -131,12 +127,15 @@ public class MacEntriesRemoveCommand extends AbstractTransactionCommand {
     }
 
     private HwvtepLogicalSwitchRef getLogicalSwitchRef(UUID switchUUID) {
-        LogicalSwitch logicalSwitch = lSwitchUpdatedRows.get(switchUUID);
+        LogicalSwitch logicalSwitch = getOvsdbConnectionInstance().getDeviceInfo().getLogicalSwitch(switchUUID);
         if (logicalSwitch != null) {
             InstanceIdentifier<LogicalSwitches> lSwitchIid =
                     HwvtepSouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance(), logicalSwitch);
             return new HwvtepLogicalSwitchRef(lSwitchIid);
         }
+        LOG.debug("Failed to get LogicalSwitch {}", switchUUID);
+        LOG.trace("Available LogicalSwitches: {}",
+                        getOvsdbConnectionInstance().getDeviceInfo().getLogicalSwitches().values());
         return null;
     }
 
@@ -13,8 +13,6 @@ import com.google.common.base.Optional;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
-
 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;
@@ -46,19 +44,17 @@ 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;
-    private Map<UUID, LogicalSwitch> updatedLSRows;
 
-    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());
         updatedPLocRows = TyperUtils.extractRowsUpdated(PhysicalLocator.class, getUpdates(), getDbSchema());
-        updatedLSRows = TyperUtils.extractRowsUpdated(LogicalSwitch.class, getUpdates(), getDbSchema());
     }
 
     @Override
@@ -104,7 +100,7 @@ public class McastMacsLocalUpdateCommand extends AbstractTransactionCommand {
     private void setLogicalSwitch(LocalMcastMacsBuilder mMacLocalBuilder, McastMacsLocal mMacLocal) {
         if (mMacLocal.getLogicalSwitchColumn() != null && mMacLocal.getLogicalSwitchColumn().getData() != null) {
             UUID lsUUID = mMacLocal.getLogicalSwitchColumn().getData();
-            LogicalSwitch lSwitch = updatedLSRows.get(lsUUID);
+            LogicalSwitch lSwitch = getOvsdbConnectionInstance().getDeviceInfo().getLogicalSwitch(lsUUID);
             if (lSwitch != null) {
                 InstanceIdentifier<LogicalSwitches> lSwitchIid =
                         HwvtepSouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance(), lSwitch);
@@ -46,19 +46,17 @@ 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;
-    private Map<UUID, LogicalSwitch> updatedLSRows;
 
-    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());
         updatedPLocRows = TyperUtils.extractRowsUpdated(PhysicalLocator.class, getUpdates(), getDbSchema());
-        updatedLSRows = TyperUtils.extractRowsUpdated(LogicalSwitch.class, getUpdates(), getDbSchema());
     }
 
     @Override
@@ -104,7 +102,7 @@ public class McastMacsRemoteUpdateCommand extends AbstractTransactionCommand {
     private void setLogicalSwitch(RemoteMcastMacsBuilder mMacRemoteBuilder, McastMacsRemote mMacRemote) {
         if (mMacRemote.getLogicalSwitchColumn() != null && mMacRemote.getLogicalSwitchColumn().getData() != null) {
             UUID lsUUID = mMacRemote.getLogicalSwitchColumn().getData();
-            LogicalSwitch lSwitch = updatedLSRows.get(lsUUID);
+            LogicalSwitch lSwitch = getOvsdbConnectionInstance().getDeviceInfo().getLogicalSwitch(lsUUID);
             if (lSwitch != null) {
                 InstanceIdentifier<LogicalSwitches> lSwitchIid =
                         HwvtepSouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance(), lSwitch);
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);
     }
 
@@ -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,
@@ -50,20 +50,18 @@ 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;
-    private Map<UUID, LogicalSwitch> lSwitchUpdatedRows;
 
-    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());
         switchUpdatedRows = TyperUtils.extractRowsUpdated(PhysicalSwitch.class, getUpdates(), getDbSchema());
-        lSwitchUpdatedRows = TyperUtils.extractRowsUpdated(LogicalSwitch.class, getUpdates(), getDbSchema());
     }
 
     @Override
@@ -181,12 +179,15 @@ public class PhysicalPortUpdateCommand extends AbstractTransactionCommand {
     }
 
     private HwvtepLogicalSwitchRef getLogicalSwitchRef(UUID switchUUID) {
-        LogicalSwitch logicalSwitch = lSwitchUpdatedRows.get(switchUUID);
+        LogicalSwitch logicalSwitch = getOvsdbConnectionInstance().getDeviceInfo().getLogicalSwitch(switchUUID);
         if (logicalSwitch != null) {
             InstanceIdentifier<LogicalSwitches> lSwitchIid =
                     HwvtepSouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance(), logicalSwitch);
             return new HwvtepLogicalSwitchRef(lSwitchIid);
         }
+        LOG.debug("Failed to get LogicalSwitch {}", switchUUID);
+        LOG.trace("Available LogicalSwitches: {}",
+                        getOvsdbConnectionInstance().getDeviceInfo().getLogicalSwitches().values());
         return null;
     }
 
@@ -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,17 +41,15 @@ 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;
-    private Map<UUID, LogicalSwitch> updatedLSRows;
 
-    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());
-        updatedLSRows = TyperUtils.extractRowsUpdated(LogicalSwitch.class, getUpdates(), getDbSchema());
     }
 
     @Override
@@ -95,7 +93,7 @@ public class UcastMacsLocalUpdateCommand extends AbstractTransactionCommand {
         }
         if (ucml.getLogicalSwitchColumn() != null && ucml.getLogicalSwitchColumn().getData() != null) {
             UUID lsUUID = ucml.getLogicalSwitchColumn().getData();
-            LogicalSwitch logicalSwitch = updatedLSRows.get(lsUUID);
+            LogicalSwitch logicalSwitch = getOvsdbConnectionInstance().getDeviceInfo().getLogicalSwitch(lsUUID);
             if (logicalSwitch != null) {
                 InstanceIdentifier<LogicalSwitches> lSwitchIid =
                         HwvtepSouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance(), logicalSwitch);
@@ -41,17 +41,15 @@ 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;
-    private final Map<UUID, LogicalSwitch> updatedLSRows;
 
-    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());
-        updatedLSRows = TyperUtils.extractRowsUpdated(LogicalSwitch.class, getUpdates(), getDbSchema());
     }
 
     @Override
@@ -96,7 +94,7 @@ public class UcastMacsRemoteUpdateCommand extends AbstractTransactionCommand {
         if (uMacRemote.getLogicalSwitchColumn() != null
                 && uMacRemote.getLogicalSwitchColumn().getData() != null) {
             UUID lsUUID = uMacRemote.getLogicalSwitchColumn().getData();
-            final LogicalSwitch logicalSwitch = updatedLSRows.get(lsUUID);
+            final LogicalSwitch logicalSwitch = getOvsdbConnectionInstance().getDeviceInfo().getLogicalSwitch(lsUUID);
             if (logicalSwitch != null) {
                 InstanceIdentifier<LogicalSwitches> lSwitchIid =
                         HwvtepSouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance(), logicalSwitch);
index 0bfb3e22cecd573f850e7a5ffbf25d00985b1f14..97d52d6197f83dc35d15c447c84c495786bc9c3c 100644 (file)
@@ -220,13 +220,10 @@ public class OvsdbPortUpdateCommand extends AbstractTransactionCommand {
             @SuppressWarnings("unchecked")
             Node managedNode = readNode(transaction
                     ,(InstanceIdentifier<Node>)managedNodeEntry.getBridgeRef().getValue()).get();
-            TerminationPointBuilder tpBuilder = new TerminationPointBuilder();
-            TerminationPointKey tpKey = new TerminationPointKey(new TpId(tpName));
-            tpBuilder.setKey(tpKey);
-            if (managedNode.getTerminationPoint().contains(tpBuilder.build())) {
-                OvsdbBridgeAugmentation ovsdbNodeAugment
-                    = managedNode.getAugmentation(OvsdbBridgeAugmentation.class);
-                return Optional.of((InstanceIdentifier<Node>)managedNodeEntry.getBridgeRef().getValue());
+            for (TerminationPoint tpEntry : managedNode.getTerminationPoint()) {
+                if (tpEntry.getTpId().equals(new TpId(tpName))) {
+                    return Optional.of((InstanceIdentifier<Node>)managedNodeEntry.getBridgeRef().getValue());
+                }
             }
         }
         return Optional.absent();
index 2f26fd3dc05e06a9dcd4a9e539a70d63bd8d98eb..ab067cdbb669be94690de778b9900167fbca846f 100644 (file)
@@ -344,9 +344,12 @@ import com.google.common.util.concurrent.CheckedFuture;
         when(managedNode.getTerminationPoint()).thenReturn(terminationPointList);
 
         when(managedNode.getAugmentation(OvsdbBridgeAugmentation.class)).thenReturn(mock(OvsdbBridgeAugmentation.class));
+        TpId tpId = new TpId(TP_NAME);
+        when(terminationPoint.getTpId()).thenReturn(tpId);
 
         Optional<InstanceIdentifier<Node>> testResult = Optional.of(iidNode);
         Optional<InstanceIdentifier<Node>>  result = Whitebox.invokeMethod(ovsdbPortUpdateCommand, "getTerminationPointBridge", transaction, node, TP_NAME);
+
         assertEquals(testResult, result);
     }