Refactoring to move code to right locations. Attempt at breaking dependency cycles.
diff --git a/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipService.java b/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipService.java
new file mode 100644
index 0000000..a44abfd
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipService.java
@@ -0,0 +1,82 @@
+package org.onlab.onos.net.device;
+
+import java.util.Set;
+
+import org.onlab.onos.cluster.NodeId;
+import org.onlab.onos.net.DeviceId;
+import org.onlab.onos.net.MastershipRole;
+
+/**
+ * Service responsible for determining the controller instance mastership of
+ * a device in a clustered environment. This is the central authority for
+ * determining mastership, but is not responsible for actually applying it
+ * to the devices; this falls on the device service.
+ */
+public interface DeviceMastershipService {
+
+    /**
+     * Returns the role of the local node for the specified device, without
+     * triggering master selection.
+     *
+     * @param deviceId the the identifier of the device
+     * @return role of the current node
+     */
+    MastershipRole getLocalRole(DeviceId deviceId);
+
+    /**
+     * Returns the mastership status of the local controller for a given
+     * device forcing master selection if necessary.
+     *
+     * @param deviceId the the identifier of the device
+     * @return the role of this controller instance
+     */
+    MastershipRole requestRoleFor(DeviceId deviceId);
+
+    /**
+     * Abandons mastership of the specified device on the local node thus
+     * forcing selection of a new master. If the local node is not a master
+     * for this device, no master selection will occur.
+     *
+     * @param deviceId the identifier of the device
+     */
+    void relinquishMastership(DeviceId deviceId);
+
+    /**
+     * Returns the current master for a given device.
+     *
+     * @param deviceId the identifier of the device
+     * @return the ID of the master controller for the device
+     */
+    NodeId getMasterFor(DeviceId deviceId);
+
+    /**
+     * Returns the devices for which a controller is master.
+     *
+     * @param nodeId the ID of the controller
+     * @return a set of device IDs
+     */
+    Set<DeviceId> getDevicesOf(NodeId nodeId);
+
+    /**
+     * Returns the mastership term service for getting read-only
+     * term information.
+     *
+     * @return the MastershipTermService for this mastership manager
+     */
+    DeviceMastershipTermService requestTermService();
+
+    /**
+     * Adds the specified mastership change listener.
+     *
+     * @param listener the mastership listener
+     */
+    void addListener(DeviceMastershipListener listener);
+
+    /**
+     * Removes the specified mastership change listener.
+     *
+     * @param listener the mastership listener
+     */
+    void removeListener(DeviceMastershipListener listener);
+
+}