base for mastership term implementation

Change-Id: Ie354096ad8835536839e3c1504e19a2cbff866c1
diff --git a/core/api/src/main/java/org/onlab/onos/cluster/MastershipService.java b/core/api/src/main/java/org/onlab/onos/cluster/MastershipService.java
index 31b4bcc..be91609 100644
--- a/core/api/src/main/java/org/onlab/onos/cluster/MastershipService.java
+++ b/core/api/src/main/java/org/onlab/onos/cluster/MastershipService.java
@@ -56,6 +56,13 @@
     Set<DeviceId> getDevicesOf(NodeId nodeId);
 
     /**
+     * Returns the mastership term service for getting term information.
+     *
+     * @return the MastershipTermService for this mastership manager
+     */
+    MastershipTermService requestTermService();
+
+    /**
      * Adds the specified mastership change listener.
      *
      * @param listener the mastership listener
diff --git a/core/api/src/main/java/org/onlab/onos/cluster/MastershipStore.java b/core/api/src/main/java/org/onlab/onos/cluster/MastershipStore.java
index 5c0c207..be5d873 100644
--- a/core/api/src/main/java/org/onlab/onos/cluster/MastershipStore.java
+++ b/core/api/src/main/java/org/onlab/onos/cluster/MastershipStore.java
@@ -55,4 +55,13 @@
      * @return a mastership event
      */
     MastershipEvent setMaster(NodeId nodeId, DeviceId deviceId);
+
+    /**
+     * Returns the current master and number of past mastership hand-offs
+     * (terms) for a device.
+     *
+     * @param deviceId the device identifier
+     * @return the current master's ID and the term value for device, or null
+     */
+    MastershipTerm getTermFor(DeviceId deviceId);
 }
diff --git a/core/api/src/main/java/org/onlab/onos/cluster/MastershipTerm.java b/core/api/src/main/java/org/onlab/onos/cluster/MastershipTerm.java
index 5c3c424..f11dafd 100644
--- a/core/api/src/main/java/org/onlab/onos/cluster/MastershipTerm.java
+++ b/core/api/src/main/java/org/onlab/onos/cluster/MastershipTerm.java
@@ -1,6 +1,46 @@
 package org.onlab.onos.cluster;
 
-public class MastershipTerm {
-    private final NodeId master = null;
+import java.util.Objects;
+
+public final class MastershipTerm {
+
+    private final NodeId master;
     private int termNumber;
+
+    private MastershipTerm(NodeId master, int term) {
+        this.master = master;
+        this.termNumber = term;
+    }
+
+    public static MastershipTerm of(NodeId master, int term) {
+        return new MastershipTerm(master, term);
+    }
+
+    public NodeId master() {
+        return master;
+    }
+
+    public int termNumber() {
+        return termNumber;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(master, termNumber);
+    }
+
+    @Override
+    public boolean equals(Object other) {
+        if (other instanceof MastershipTerm) {
+            MastershipTerm that = (MastershipTerm) other;
+            if (!this.master.equals(that.master)) {
+                return false;
+            }
+            if (this.termNumber != that.termNumber) {
+                return false;
+            }
+            return true;
+        }
+        return false;
+    }
 }
diff --git a/core/api/src/test/java/org/onlab/onos/cluster/MastershipServiceAdapter.java b/core/api/src/test/java/org/onlab/onos/cluster/MastershipServiceAdapter.java
index 4b3b7dc..2e92f5b 100644
--- a/core/api/src/test/java/org/onlab/onos/cluster/MastershipServiceAdapter.java
+++ b/core/api/src/test/java/org/onlab/onos/cluster/MastershipServiceAdapter.java
@@ -40,4 +40,9 @@
     @Override
     public void removeListener(MastershipListener listener) {
     }
+
+    @Override
+    public MastershipTermService requestTermService() {
+        return null;
+    }
 }