Revert "Refactoring to move code to right locations. Attempt at breaking dependency cycles."

This reverts commit 58819b4dcc697f63872bee9f3ddd41a0c4d8fca5.
diff --git a/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipAdminService.java b/core/api/src/main/java/org/onlab/onos/cluster/MastershipAdminService.java
similarity index 78%
rename from core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipAdminService.java
rename to core/api/src/main/java/org/onlab/onos/cluster/MastershipAdminService.java
index 78c9c39..907b3f8 100644
--- a/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipAdminService.java
+++ b/core/api/src/main/java/org/onlab/onos/cluster/MastershipAdminService.java
@@ -1,13 +1,12 @@
-package org.onlab.onos.net.device;
+package org.onlab.onos.cluster;
 
-import org.onlab.onos.cluster.NodeId;
 import org.onlab.onos.net.DeviceId;
 import org.onlab.onos.net.MastershipRole;
 
 /**
  * Service for administering the inventory of device masterships.
  */
-public interface DeviceMastershipAdminService {
+public interface MastershipAdminService {
 
     /**
      * Applies the current mastership role for the specified device.
diff --git a/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipEvent.java b/core/api/src/main/java/org/onlab/onos/cluster/MastershipEvent.java
similarity index 78%
rename from core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipEvent.java
rename to core/api/src/main/java/org/onlab/onos/cluster/MastershipEvent.java
index 1232d9c..15811fb 100644
--- a/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipEvent.java
+++ b/core/api/src/main/java/org/onlab/onos/cluster/MastershipEvent.java
@@ -1,13 +1,12 @@
-package org.onlab.onos.net.device;
+package org.onlab.onos.cluster;
 
-import org.onlab.onos.cluster.NodeId;
 import org.onlab.onos.event.AbstractEvent;
 import org.onlab.onos.net.DeviceId;
 
 /**
  * Describes a device mastership event.
  */
-public class DeviceMastershipEvent extends AbstractEvent<DeviceMastershipEvent.Type, DeviceId> {
+public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceId> {
 
     //do we worry about explicitly setting slaves/equals? probably not,
     //to keep it simple
@@ -31,7 +30,7 @@
      * @param device event device subject
      * @param master master ID subject
      */
-    public DeviceMastershipEvent(Type type, DeviceId device, NodeId master) {
+    public MastershipEvent(Type type, DeviceId device, NodeId master) {
         super(type, device);
         this.master = master;
     }
@@ -45,7 +44,7 @@
      * @param master master ID subject
      * @param time   occurrence time
      */
-    public DeviceMastershipEvent(Type type, DeviceId device, NodeId master, long time) {
+    public MastershipEvent(Type type, DeviceId device, NodeId master, long time) {
         super(type, device, time);
         this.master = master;
     }
diff --git a/core/api/src/main/java/org/onlab/onos/cluster/MastershipListener.java b/core/api/src/main/java/org/onlab/onos/cluster/MastershipListener.java
new file mode 100644
index 0000000..71d65be
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/cluster/MastershipListener.java
@@ -0,0 +1,9 @@
+package org.onlab.onos.cluster;
+
+import org.onlab.onos.event.EventListener;
+
+/**
+ * Entity capable of receiving device mastership-related events.
+ */
+public interface MastershipListener extends EventListener<MastershipEvent> {
+}
diff --git a/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipService.java b/core/api/src/main/java/org/onlab/onos/cluster/MastershipService.java
similarity index 88%
rename from core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipService.java
rename to core/api/src/main/java/org/onlab/onos/cluster/MastershipService.java
index a44abfd..51b6f6a 100644
--- a/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipService.java
+++ b/core/api/src/main/java/org/onlab/onos/cluster/MastershipService.java
@@ -1,8 +1,7 @@
-package org.onlab.onos.net.device;
+package org.onlab.onos.cluster;
 
 import java.util.Set;
 
-import org.onlab.onos.cluster.NodeId;
 import org.onlab.onos.net.DeviceId;
 import org.onlab.onos.net.MastershipRole;
 
@@ -12,7 +11,7 @@
  * determining mastership, but is not responsible for actually applying it
  * to the devices; this falls on the device service.
  */
-public interface DeviceMastershipService {
+public interface MastershipService {
 
     /**
      * Returns the role of the local node for the specified device, without
@@ -63,20 +62,20 @@
      *
      * @return the MastershipTermService for this mastership manager
      */
-    DeviceMastershipTermService requestTermService();
+    MastershipTermService requestTermService();
 
     /**
      * Adds the specified mastership change listener.
      *
      * @param listener the mastership listener
      */
-    void addListener(DeviceMastershipListener listener);
+    void addListener(MastershipListener listener);
 
     /**
      * Removes the specified mastership change listener.
      *
      * @param listener the mastership listener
      */
-    void removeListener(DeviceMastershipListener listener);
+    void removeListener(MastershipListener listener);
 
 }
diff --git a/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipStore.java b/core/api/src/main/java/org/onlab/onos/cluster/MastershipStore.java
similarity index 84%
rename from core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipStore.java
rename to core/api/src/main/java/org/onlab/onos/cluster/MastershipStore.java
index ee9b253..dc5603f 100644
--- a/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipStore.java
+++ b/core/api/src/main/java/org/onlab/onos/cluster/MastershipStore.java
@@ -1,8 +1,7 @@
-package org.onlab.onos.net.device;
+package org.onlab.onos.cluster;
 
 import java.util.Set;
 
-import org.onlab.onos.cluster.NodeId;
 import org.onlab.onos.net.DeviceId;
 import org.onlab.onos.net.MastershipRole;
 import org.onlab.onos.store.Store;
@@ -11,7 +10,7 @@
  * Manages inventory of mastership roles for devices, across controller
  * instances; not intended for direct use.
  */
-public interface DeviceMastershipStore extends Store<DeviceMastershipEvent, DeviceMastershipStoreDelegate> {
+public interface MastershipStore extends Store<MastershipEvent, MastershipStoreDelegate> {
 
     // three things to map: NodeId, DeviceId, MastershipRole
 
@@ -55,7 +54,7 @@
      * @param deviceId device identifier
      * @return a mastership event
      */
-    DeviceMastershipEvent setMaster(NodeId nodeId, DeviceId deviceId);
+    MastershipEvent setMaster(NodeId nodeId, DeviceId deviceId);
 
     /**
      * Returns the current master and number of past mastership hand-offs
@@ -64,7 +63,7 @@
      * @param deviceId the device identifier
      * @return the current master's ID and the term value for device, or null
      */
-    DeviceMastershipTerm getTermFor(DeviceId deviceId);
+    MastershipTerm getTermFor(DeviceId deviceId);
 
     /**
      * Sets a controller instance's mastership role to STANDBY for a device.
@@ -75,7 +74,7 @@
      * @param deviceId device to revoke mastership role for
      * @return a mastership event
      */
-    DeviceMastershipEvent setStandby(NodeId nodeId, DeviceId deviceId);
+    MastershipEvent setStandby(NodeId nodeId, DeviceId deviceId);
 
     /**
      * Allows a controller instance to give up its current role for a device.
@@ -86,6 +85,6 @@
      * @param deviceId device to revoke mastership role for
      * @return a mastership event
      */
-    DeviceMastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId);
+    MastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId);
 
 }
diff --git a/core/api/src/main/java/org/onlab/onos/cluster/MastershipStoreDelegate.java b/core/api/src/main/java/org/onlab/onos/cluster/MastershipStoreDelegate.java
new file mode 100644
index 0000000..b4d923c
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/cluster/MastershipStoreDelegate.java
@@ -0,0 +1,9 @@
+package org.onlab.onos.cluster;
+
+import org.onlab.onos.store.StoreDelegate;
+
+/**
+ * Mastership store delegate abstraction.
+ */
+public interface MastershipStoreDelegate extends StoreDelegate<MastershipEvent> {
+}
diff --git a/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipTerm.java b/core/api/src/main/java/org/onlab/onos/cluster/MastershipTerm.java
similarity index 64%
rename from core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipTerm.java
rename to core/api/src/main/java/org/onlab/onos/cluster/MastershipTerm.java
index f05a3d2..71d08f2 100644
--- a/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipTerm.java
+++ b/core/api/src/main/java/org/onlab/onos/cluster/MastershipTerm.java
@@ -1,21 +1,19 @@
-package org.onlab.onos.net.device;
+package org.onlab.onos.cluster;
 
 import java.util.Objects;
 
-import org.onlab.onos.cluster.NodeId;
-
-public final class DeviceMastershipTerm {
+public final class MastershipTerm {
 
     private final NodeId master;
     private final int termNumber;
 
-    private DeviceMastershipTerm(NodeId master, int term) {
+    private MastershipTerm(NodeId master, int term) {
         this.master = master;
         this.termNumber = term;
     }
 
-    public static DeviceMastershipTerm of(NodeId master, int term) {
-        return new DeviceMastershipTerm(master, term);
+    public static MastershipTerm of(NodeId master, int term) {
+        return new MastershipTerm(master, term);
     }
 
     public NodeId master() {
@@ -36,8 +34,8 @@
         if (this == other) {
             return true;
         }
-        if (other instanceof DeviceMastershipTerm) {
-            DeviceMastershipTerm that = (DeviceMastershipTerm) other;
+        if (other instanceof MastershipTerm) {
+            MastershipTerm that = (MastershipTerm) other;
             if (!this.master.equals(that.master)) {
                 return false;
             }
diff --git a/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipTermService.java b/core/api/src/main/java/org/onlab/onos/cluster/MastershipTermService.java
similarity index 74%
rename from core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipTermService.java
rename to core/api/src/main/java/org/onlab/onos/cluster/MastershipTermService.java
index 7a0c063..b03ed81 100644
--- a/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipTermService.java
+++ b/core/api/src/main/java/org/onlab/onos/cluster/MastershipTermService.java
@@ -1,4 +1,4 @@
-package org.onlab.onos.net.device;
+package org.onlab.onos.cluster;
 
 import org.onlab.onos.net.DeviceId;
 
@@ -6,7 +6,7 @@
 /**
  * Service to obtain mastership term information.
  */
-public interface DeviceMastershipTermService {
+public interface MastershipTermService {
 
     // TBD: manage/increment per device mastership change
     //      or increment on any change
@@ -16,5 +16,5 @@
      * @param deviceId the identifier of the device
      * @return current master's term.
      */
-    DeviceMastershipTerm getMastershipTerm(DeviceId deviceId);
+    MastershipTerm getMastershipTerm(DeviceId deviceId);
 }
diff --git a/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipListener.java b/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipListener.java
deleted file mode 100644
index 0c7c8d9..0000000
--- a/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipListener.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.onlab.onos.net.device;
-
-import org.onlab.onos.event.EventListener;
-
-/**
- * Entity capable of receiving device mastership-related events.
- */
-public interface DeviceMastershipListener extends EventListener<DeviceMastershipEvent> {
-}
diff --git a/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipStoreDelegate.java b/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipStoreDelegate.java
deleted file mode 100644
index f654d85..0000000
--- a/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipStoreDelegate.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.onlab.onos.net.device;
-
-import org.onlab.onos.store.StoreDelegate;
-
-/**
- * DeviceMastership store delegate abstraction.
- */
-public interface DeviceMastershipStoreDelegate extends StoreDelegate<DeviceMastershipEvent> {
-}
diff --git a/core/api/src/main/java/org/onlab/onos/store/ClockProviderService.java b/core/api/src/main/java/org/onlab/onos/store/ClockProviderService.java
index fff6d15..a5f81c7 100644
--- a/core/api/src/main/java/org/onlab/onos/store/ClockProviderService.java
+++ b/core/api/src/main/java/org/onlab/onos/store/ClockProviderService.java
@@ -1,7 +1,7 @@
 package org.onlab.onos.store;
 
+import org.onlab.onos.cluster.MastershipTerm;
 import org.onlab.onos.net.DeviceId;
-import org.onlab.onos.net.device.DeviceMastershipTerm;
 
 //TODO: Consider renaming to DeviceClockProviderService?
 /**
@@ -16,5 +16,5 @@
      * @param deviceId device identifier.
      * @param term mastership term.
      */
-    public void setMastershipTerm(DeviceId deviceId, DeviceMastershipTerm term);
+    public void setMastershipTerm(DeviceId deviceId, MastershipTerm term);
 }
diff --git a/core/api/src/main/java/org/onlab/onos/store/Timestamped.java b/core/api/src/main/java/org/onlab/onos/store/Timestamped.java
deleted file mode 100644
index 9de7b0d..0000000
--- a/core/api/src/main/java/org/onlab/onos/store/Timestamped.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package org.onlab.onos.store;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.util.Objects;
-
-import com.google.common.base.MoreObjects;
-
-/**
- * Wrapper class to store Timestamped value.
- * @param <T>
- */
-public final class Timestamped<T> {
-
-    private final Timestamp timestamp;
-    private final T value;
-
-    /**
-     * Creates a time stamped value.
-     *
-     * @param value to be timestamp
-     * @param timestamp the timestamp
-     */
-    public Timestamped(T value, Timestamp timestamp) {
-        this.value = checkNotNull(value);
-        this.timestamp = checkNotNull(timestamp);
-    }
-
-    /**
-     * Returns the value.
-     * @return value
-     */
-    public T value() {
-        return value;
-    }
-
-    /**
-     * Returns the time stamp.
-     * @return time stamp
-     */
-    public Timestamp timestamp() {
-        return timestamp;
-    }
-
-    /**
-     * Tests if this timestamped value is newer than the other.
-     *
-     * @param other timestamped value
-     * @return true if this instance is newer.
-     */
-    public boolean isNewer(Timestamped<T> other) {
-        return this.timestamp.compareTo(checkNotNull(other).timestamp()) > 0;
-    }
-
-    @Override
-    public int hashCode() {
-        return timestamp.hashCode();
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (!(obj instanceof Timestamped)) {
-            return false;
-        }
-        @SuppressWarnings("unchecked")
-        Timestamped<T> that = (Timestamped<T>) obj;
-        return Objects.equals(this.timestamp, that.timestamp);
-    }
-
-    @Override
-    public String toString() {
-        return MoreObjects.toStringHelper(getClass())
-                    .add("timestamp", timestamp)
-                    .add("value", value)
-                    .toString();
-    }
-
-    // Default constructor for serialization
-    @Deprecated
-    private Timestamped() {
-        this.value = null;
-        this.timestamp = null;
-    }
-}
diff --git a/core/api/src/main/java/org/onlab/onos/store/VersionedValue.java b/core/api/src/main/java/org/onlab/onos/store/VersionedValue.java
deleted file mode 100644
index 70602f6..0000000
--- a/core/api/src/main/java/org/onlab/onos/store/VersionedValue.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package org.onlab.onos.store;
-
-import java.util.Objects;
-
-/**
- * Wrapper class for a entity that is versioned
- * and can either be up or down.
- *
- * @param <T> type of the value.
- */
-public class VersionedValue<T> {
-    private final T entity;
-    private final Timestamp timestamp;
-    private final boolean isUp;
-
-    public VersionedValue(T entity, boolean isUp, Timestamp timestamp) {
-        this.entity = entity;
-        this.isUp = isUp;
-        this.timestamp = timestamp;
-    }
-
-    /**
-     * Returns the value.
-     * @return value.
-     */
-    public T entity() {
-        return entity;
-    }
-
-    /**
-     * Tells whether the entity is up or down.
-     * @return true if up, false otherwise.
-     */
-    public boolean isUp() {
-        return isUp;
-    }
-
-    /**
-     * Returns the timestamp (version) associated with this entity.
-     * @return timestamp.
-     */
-    public Timestamp timestamp() {
-        return timestamp;
-    }
-
-
-    @Override
-    public int hashCode() {
-        return Objects.hash(entity, timestamp, isUp);
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        @SuppressWarnings("unchecked")
-        VersionedValue<T> that = (VersionedValue<T>) obj;
-        return Objects.equals(this.entity, that.entity) &&
-                Objects.equals(this.timestamp, that.timestamp) &&
-                Objects.equals(this.isUp, that.isUp);
-    }
-
-    // Default constructor for serializer
-    protected VersionedValue() {
-        this.entity = null;
-        this.isUp = false;
-        this.timestamp = null;
-    }
-}