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
Showing
6 changed files
with
56 additions
and
13 deletions
... | @@ -25,6 +25,14 @@ import org.onlab.onos.net.DeviceId; | ... | @@ -25,6 +25,14 @@ import org.onlab.onos.net.DeviceId; |
25 | public interface DeviceClockProviderService { | 25 | public interface DeviceClockProviderService { |
26 | 26 | ||
27 | /** | 27 | /** |
28 | + * Checks if this service can issue Timestamp for specified device. | ||
29 | + * | ||
30 | + * @param deviceId device identifier. | ||
31 | + * @return true if timestamp can be issued for specified device | ||
32 | + */ | ||
33 | + public boolean isTimestampAvailable(DeviceId deviceId); | ||
34 | + | ||
35 | + /** | ||
28 | * Updates the mastership term for the specified deviceId. | 36 | * Updates the mastership term for the specified deviceId. |
29 | * | 37 | * |
30 | * @param deviceId device identifier. | 38 | * @param deviceId device identifier. | ... | ... |
... | @@ -24,7 +24,16 @@ import org.onlab.onos.store.Timestamp; | ... | @@ -24,7 +24,16 @@ import org.onlab.onos.store.Timestamp; |
24 | public interface DeviceClockService { | 24 | public interface DeviceClockService { |
25 | 25 | ||
26 | /** | 26 | /** |
27 | + * Checks if this service can issue Timestamp for specified device. | ||
28 | + * | ||
29 | + * @param deviceId device identifier. | ||
30 | + * @return true if timestamp can be issued for specified device | ||
31 | + */ | ||
32 | + public boolean isTimestampAvailable(DeviceId deviceId); | ||
33 | + | ||
34 | + /** | ||
27 | * Returns a new timestamp for the specified deviceId. | 35 | * Returns a new timestamp for the specified deviceId. |
36 | + * | ||
28 | * @param deviceId device identifier. | 37 | * @param deviceId device identifier. |
29 | * @return timestamp. | 38 | * @return timestamp. |
30 | */ | 39 | */ | ... | ... |
... | @@ -343,6 +343,13 @@ public class DeviceManager | ... | @@ -343,6 +343,13 @@ public class DeviceManager |
343 | "Port descriptions list cannot be null"); | 343 | "Port descriptions list cannot be null"); |
344 | checkValidity(); | 344 | checkValidity(); |
345 | 345 | ||
346 | + if (!deviceClockProviderService.isTimestampAvailable(deviceId)) { | ||
347 | + // Never been a master for this device | ||
348 | + // any update will be ignored. | ||
349 | + log.trace("Ignoring {} port updates on standby node. {}", deviceId, portDescriptions); | ||
350 | + return; | ||
351 | + } | ||
352 | + | ||
346 | List<DeviceEvent> events = store.updatePorts(this.provider().id(), | 353 | List<DeviceEvent> events = store.updatePorts(this.provider().id(), |
347 | deviceId, portDescriptions); | 354 | deviceId, portDescriptions); |
348 | for (DeviceEvent event : events) { | 355 | for (DeviceEvent event : events) { |
... | @@ -357,6 +364,13 @@ public class DeviceManager | ... | @@ -357,6 +364,13 @@ public class DeviceManager |
357 | checkNotNull(portDescription, PORT_DESCRIPTION_NULL); | 364 | checkNotNull(portDescription, PORT_DESCRIPTION_NULL); |
358 | checkValidity(); | 365 | checkValidity(); |
359 | 366 | ||
367 | + if (!deviceClockProviderService.isTimestampAvailable(deviceId)) { | ||
368 | + // Never been a master for this device | ||
369 | + // any update will be ignored. | ||
370 | + log.trace("Ignoring {} port update on standby node. {}", deviceId, portDescription); | ||
371 | + return; | ||
372 | + } | ||
373 | + | ||
360 | final DeviceEvent event = store.updatePortStatus(this.provider().id(), | 374 | final DeviceEvent event = store.updatePortStatus(this.provider().id(), |
361 | deviceId, portDescription); | 375 | deviceId, portDescription); |
362 | if (event != null) { | 376 | if (event != null) { | ... | ... |
... | @@ -19,7 +19,6 @@ import com.google.common.collect.Sets; | ... | @@ -19,7 +19,6 @@ import com.google.common.collect.Sets; |
19 | 19 | ||
20 | import org.junit.After; | 20 | import org.junit.After; |
21 | import org.junit.Before; | 21 | import org.junit.Before; |
22 | -import org.junit.Ignore; | ||
23 | import org.junit.Test; | 22 | import org.junit.Test; |
24 | import org.onlab.onos.cluster.ClusterEventListener; | 23 | import org.onlab.onos.cluster.ClusterEventListener; |
25 | import org.onlab.onos.cluster.ClusterService; | 24 | import org.onlab.onos.cluster.ClusterService; |
... | @@ -181,16 +180,6 @@ public class DeviceManagerTest { | ... | @@ -181,16 +180,6 @@ public class DeviceManagerTest { |
181 | assertEquals("incorrect role", MastershipRole.MASTER, service.getRole(DID1)); | 180 | assertEquals("incorrect role", MastershipRole.MASTER, service.getRole(DID1)); |
182 | } | 181 | } |
183 | 182 | ||
184 | - @Ignore("disabled until we settle the device-mastership wiring") | ||
185 | - @Test | ||
186 | - public void setRole() throws InterruptedException { | ||
187 | - connectDevice(DID1, SW1); | ||
188 | - validateEvents(DEVICE_ADDED, DEVICE_MASTERSHIP_CHANGED); | ||
189 | - assertEquals("incorrect role", MastershipRole.STANDBY, service.getRole(DID1)); | ||
190 | - assertEquals("incorrect device", DID1, provider.deviceReceived.id()); | ||
191 | - assertEquals("incorrect role", MastershipRole.STANDBY, provider.roleReceived); | ||
192 | - } | ||
193 | - | ||
194 | @Test | 183 | @Test |
195 | public void updatePorts() { | 184 | public void updatePorts() { |
196 | connectDevice(DID1, SW1); | 185 | connectDevice(DID1, SW1); |
... | @@ -360,9 +349,16 @@ public class DeviceManagerTest { | ... | @@ -360,9 +349,16 @@ public class DeviceManagerTest { |
360 | private final class TestClockProviderService implements | 349 | private final class TestClockProviderService implements |
361 | DeviceClockProviderService { | 350 | DeviceClockProviderService { |
362 | 351 | ||
352 | + private Set<DeviceId> registerdBefore = Sets.newConcurrentHashSet(); | ||
353 | + | ||
363 | @Override | 354 | @Override |
364 | public void setMastershipTerm(DeviceId deviceId, MastershipTerm term) { | 355 | public void setMastershipTerm(DeviceId deviceId, MastershipTerm term) { |
365 | - // TODO Auto-generated method stub | 356 | + registerdBefore.add(deviceId); |
357 | + } | ||
358 | + | ||
359 | + @Override | ||
360 | + public boolean isTimestampAvailable(DeviceId deviceId) { | ||
361 | + return registerdBefore.contains(deviceId); | ||
366 | } | 362 | } |
367 | } | 363 | } |
368 | } | 364 | } | ... | ... |
... | @@ -72,4 +72,9 @@ public class DeviceClockManager implements DeviceClockService, DeviceClockProvid | ... | @@ -72,4 +72,9 @@ public class DeviceClockManager implements DeviceClockService, DeviceClockProvid |
72 | log.info("adding term info {} {}", deviceId, term.master()); | 72 | log.info("adding term info {} {}", deviceId, term.master()); |
73 | deviceMastershipTerms.put(deviceId, term); | 73 | deviceMastershipTerms.put(deviceId, term); |
74 | } | 74 | } |
75 | + | ||
76 | + @Override | ||
77 | + public boolean isTimestampAvailable(DeviceId deviceId) { | ||
78 | + return deviceMastershipTerms.containsKey(deviceId); | ||
79 | + } | ||
75 | } | 80 | } | ... | ... |
... | @@ -15,13 +15,16 @@ | ... | @@ -15,13 +15,16 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.onos.store.trivial.impl; | 16 | package org.onlab.onos.store.trivial.impl; |
17 | 17 | ||
18 | +import java.util.Set; | ||
19 | + | ||
18 | import org.apache.felix.scr.annotations.Component; | 20 | import org.apache.felix.scr.annotations.Component; |
19 | import org.apache.felix.scr.annotations.Service; | 21 | import org.apache.felix.scr.annotations.Service; |
20 | import org.onlab.onos.mastership.MastershipTerm; | 22 | import org.onlab.onos.mastership.MastershipTerm; |
21 | import org.onlab.onos.net.DeviceId; | 23 | import org.onlab.onos.net.DeviceId; |
22 | import org.onlab.onos.net.device.DeviceClockProviderService; | 24 | import org.onlab.onos.net.device.DeviceClockProviderService; |
23 | 25 | ||
24 | -//FIXME: Code clone in onos-core-trivial, onos-core-hz-net | 26 | +import com.google.common.collect.Sets; |
27 | + | ||
25 | /** | 28 | /** |
26 | * Dummy implementation of {@link DeviceClockProviderService}. | 29 | * Dummy implementation of {@link DeviceClockProviderService}. |
27 | */ | 30 | */ |
... | @@ -29,7 +32,15 @@ import org.onlab.onos.net.device.DeviceClockProviderService; | ... | @@ -29,7 +32,15 @@ import org.onlab.onos.net.device.DeviceClockProviderService; |
29 | @Service | 32 | @Service |
30 | public class NoOpClockProviderService implements DeviceClockProviderService { | 33 | public class NoOpClockProviderService implements DeviceClockProviderService { |
31 | 34 | ||
35 | + private Set<DeviceId> registerdBefore = Sets.newConcurrentHashSet(); | ||
36 | + | ||
32 | @Override | 37 | @Override |
33 | public void setMastershipTerm(DeviceId deviceId, MastershipTerm term) { | 38 | public void setMastershipTerm(DeviceId deviceId, MastershipTerm term) { |
39 | + registerdBefore.add(deviceId); | ||
40 | + } | ||
41 | + | ||
42 | + @Override | ||
43 | + public boolean isTimestampAvailable(DeviceId deviceId) { | ||
44 | + return registerdBefore.contains(deviceId); | ||
34 | } | 45 | } |
35 | } | 46 | } | ... | ... |
-
Please register or login to post a comment