Add API in DeviceClock*Service to check if Timestamp can be issued.

- check local DeviceClockProviderService before trying to
  store Port update information.

Change-Id: I22c94cb712d7001a227497b723780b6db3fbdf04
diff --git a/core/net/src/main/java/org/onlab/onos/net/device/impl/DeviceManager.java b/core/net/src/main/java/org/onlab/onos/net/device/impl/DeviceManager.java
index 740a110..33200b9 100644
--- a/core/net/src/main/java/org/onlab/onos/net/device/impl/DeviceManager.java
+++ b/core/net/src/main/java/org/onlab/onos/net/device/impl/DeviceManager.java
@@ -343,6 +343,13 @@
                          "Port descriptions list cannot be null");
             checkValidity();
 
+            if (!deviceClockProviderService.isTimestampAvailable(deviceId)) {
+                // Never been a master for this device
+                // any update will be ignored.
+                log.trace("Ignoring {} port updates on standby node. {}", deviceId, portDescriptions);
+                return;
+            }
+
             List<DeviceEvent> events = store.updatePorts(this.provider().id(),
                                                          deviceId, portDescriptions);
             for (DeviceEvent event : events) {
@@ -357,6 +364,13 @@
             checkNotNull(portDescription, PORT_DESCRIPTION_NULL);
             checkValidity();
 
+            if (!deviceClockProviderService.isTimestampAvailable(deviceId)) {
+                // Never been a master for this device
+                // any update will be ignored.
+                log.trace("Ignoring {} port update on standby node. {}", deviceId, portDescription);
+                return;
+            }
+
             final DeviceEvent event = store.updatePortStatus(this.provider().id(),
                                                              deviceId, portDescription);
             if (event != null) {
diff --git a/core/net/src/test/java/org/onlab/onos/net/device/impl/DeviceManagerTest.java b/core/net/src/test/java/org/onlab/onos/net/device/impl/DeviceManagerTest.java
index 25fa922..79e2f10 100644
--- a/core/net/src/test/java/org/onlab/onos/net/device/impl/DeviceManagerTest.java
+++ b/core/net/src/test/java/org/onlab/onos/net/device/impl/DeviceManagerTest.java
@@ -19,7 +19,6 @@
 
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.onlab.onos.cluster.ClusterEventListener;
 import org.onlab.onos.cluster.ClusterService;
@@ -181,16 +180,6 @@
         assertEquals("incorrect role", MastershipRole.MASTER, service.getRole(DID1));
     }
 
-    @Ignore("disabled until we settle the device-mastership wiring")
-    @Test
-    public void setRole() throws InterruptedException {
-        connectDevice(DID1, SW1);
-        validateEvents(DEVICE_ADDED, DEVICE_MASTERSHIP_CHANGED);
-        assertEquals("incorrect role", MastershipRole.STANDBY, service.getRole(DID1));
-        assertEquals("incorrect device", DID1, provider.deviceReceived.id());
-        assertEquals("incorrect role", MastershipRole.STANDBY, provider.roleReceived);
-    }
-
     @Test
     public void updatePorts() {
         connectDevice(DID1, SW1);
@@ -360,9 +349,16 @@
     private final class TestClockProviderService implements
             DeviceClockProviderService {
 
+        private Set<DeviceId> registerdBefore = Sets.newConcurrentHashSet();
+
         @Override
         public void setMastershipTerm(DeviceId deviceId, MastershipTerm term) {
-            // TODO Auto-generated method stub
+            registerdBefore.add(deviceId);
+        }
+
+        @Override
+        public boolean isTimestampAvailable(DeviceId deviceId) {
+            return registerdBefore.contains(deviceId);
         }
     }
 }