Yuta HIGUCHI

Changed argument from Device -> DeviceId

- roleChanged(), isReachable()
   Eventually consistent nature of Device store was
  interfering with mastership control.

Change-Id: I9c0dd846a4e30863f922f6706c6cb62fd7c83f29
...@@ -368,12 +368,12 @@ public class OpticalConfigProvider extends AbstractProvider implements DevicePro ...@@ -368,12 +368,12 @@ public class OpticalConfigProvider extends AbstractProvider implements DevicePro
368 } 368 }
369 369
370 @Override 370 @Override
371 - public void roleChanged(Device device, MastershipRole newRole) { 371 + public void roleChanged(DeviceId device, MastershipRole newRole) {
372 // TODO Auto-generated method stub. 372 // TODO Auto-generated method stub.
373 } 373 }
374 374
375 @Override 375 @Override
376 - public boolean isReachable(Device device) { 376 + public boolean isReachable(DeviceId device) {
377 return false; 377 return false;
378 } 378 }
379 } 379 }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 package org.onlab.onos.net.device; 16 package org.onlab.onos.net.device;
17 17
18 import org.onlab.onos.net.Device; 18 import org.onlab.onos.net.Device;
19 +import org.onlab.onos.net.DeviceId;
19 import org.onlab.onos.net.MastershipRole; 20 import org.onlab.onos.net.MastershipRole;
20 import org.onlab.onos.net.provider.Provider; 21 import org.onlab.onos.net.provider.Provider;
21 22
...@@ -42,16 +43,16 @@ public interface DeviceProvider extends Provider { ...@@ -42,16 +43,16 @@ public interface DeviceProvider extends Provider {
42 * Notifies the provider of a mastership role change for the specified 43 * Notifies the provider of a mastership role change for the specified
43 * device as decided by the core. 44 * device as decided by the core.
44 * 45 *
45 - * @param device affected device 46 + * @param deviceId device identifier
46 * @param newRole newly determined mastership role 47 * @param newRole newly determined mastership role
47 */ 48 */
48 - void roleChanged(Device device, MastershipRole newRole); 49 + void roleChanged(DeviceId deviceId, MastershipRole newRole);
49 50
50 /** 51 /**
51 * Checks the reachability (connectivity) of a device from this provider. 52 * Checks the reachability (connectivity) of a device from this provider.
52 * 53 *
53 - * @param device device to check 54 + * @param deviceId device identifier
54 * @return true if reachable, false otherwise 55 * @return true if reachable, false otherwise
55 */ 56 */
56 - boolean isReachable(Device device); 57 + boolean isReachable(DeviceId deviceId);
57 } 58 }
......
...@@ -159,13 +159,14 @@ public class DeviceManager ...@@ -159,13 +159,14 @@ public class DeviceManager
159 } 159 }
160 160
161 // Check a device for control channel connectivity. 161 // Check a device for control channel connectivity.
162 - private boolean isReachable(Device device) { 162 + private boolean isReachable(DeviceId deviceId) {
163 - // FIXME: Device might not be there yet. (eventual consistent) 163 + DeviceProvider provider = getProvider(deviceId);
164 - if (device == null) { 164 + if (provider != null) {
165 + return provider.isReachable(deviceId);
166 + } else {
167 + log.error("Provider not found for {}", deviceId);
165 return false; 168 return false;
166 } 169 }
167 - DeviceProvider provider = getProvider(device.providerId());
168 - return provider.isReachable(device);
169 } 170 }
170 171
171 @Override 172 @Override
...@@ -226,15 +227,9 @@ public class DeviceManager ...@@ -226,15 +227,9 @@ public class DeviceManager
226 log.warn("Provider for {} was not found. Cannot apply role {}", deviceId, newRole); 227 log.warn("Provider for {} was not found. Cannot apply role {}", deviceId, newRole);
227 return false; 228 return false;
228 } 229 }
229 - // FIXME roleChanged should take DeviceId instead of Device 230 + provider.roleChanged(deviceId, newRole);
230 - Device device = store.getDevice(deviceId); 231 + // not triggering probe when triggered by provider service event
231 - if (device == null) {
232 - log.warn("{} was not there. Cannot apply role {}", deviceId, newRole);
233 - return false;
234 - }
235 - provider.roleChanged(device, newRole);
236 232
237 - // not triggering prove when triggered by provider service
238 return true; 233 return true;
239 } 234 }
240 235
...@@ -442,6 +437,7 @@ public class DeviceManager ...@@ -442,6 +437,7 @@ public class DeviceManager
442 437
443 Device device = store.getDevice(deviceId); 438 Device device = store.getDevice(deviceId);
444 // FIXME: Device might not be there yet. (eventual consistent) 439 // FIXME: Device might not be there yet. (eventual consistent)
440 + // FIXME relinquish role
445 if (device == null) { 441 if (device == null) {
446 log.warn("{} was not there. Cannot apply role {}", deviceId, newRole); 442 log.warn("{} was not there. Cannot apply role {}", deviceId, newRole);
447 return false; 443 return false;
...@@ -452,8 +448,7 @@ public class DeviceManager ...@@ -452,8 +448,7 @@ public class DeviceManager
452 log.warn("Provider for {} was not found. Cannot apply role {}", deviceId, newRole); 448 log.warn("Provider for {} was not found. Cannot apply role {}", deviceId, newRole);
453 return false; 449 return false;
454 } 450 }
455 - // FIXME roleChanged should take DeviceId instead of Device 451 + provider.roleChanged(deviceId, newRole);
456 - provider.roleChanged(device, newRole);
457 452
458 if (newRole.equals(MastershipRole.MASTER)) { 453 if (newRole.equals(MastershipRole.MASTER)) {
459 // only trigger event when request was sent to provider 454 // only trigger event when request was sent to provider
...@@ -495,8 +490,7 @@ public class DeviceManager ...@@ -495,8 +490,7 @@ public class DeviceManager
495 } 490 }
496 491
497 492
498 - final Device device = getDevice(did); 493 + final boolean isReachable = isReachable(did);
499 - final boolean isReachable = isReachable(device);
500 if (!isReachable) { 494 if (!isReachable) {
501 // device is not connected to this node 495 // device is not connected to this node
502 if (myNextRole != NONE) { 496 if (myNextRole != NONE) {
...@@ -505,6 +499,7 @@ public class DeviceManager ...@@ -505,6 +499,7 @@ public class DeviceManager
505 + "Relinquishing role. ", 499 + "Relinquishing role. ",
506 myNextRole, did); 500 myNextRole, did);
507 mastershipService.relinquishMastership(did); 501 mastershipService.relinquishMastership(did);
502 + // FIXME disconnect?
508 } 503 }
509 return; 504 return;
510 } 505 }
...@@ -523,6 +518,7 @@ public class DeviceManager ...@@ -523,6 +518,7 @@ public class DeviceManager
523 518
524 switch (myNextRole) { 519 switch (myNextRole) {
525 case MASTER: 520 case MASTER:
521 + final Device device = getDevice(did);
526 if ((device != null) && !isAvailable(did)) { 522 if ((device != null) && !isAvailable(did)) {
527 //flag the device as online. Is there a better way to do this? 523 //flag the device as online. Is there a better way to do this?
528 DefaultDeviceDescription deviceDescription 524 DefaultDeviceDescription deviceDescription
......
...@@ -251,7 +251,7 @@ public class DeviceManagerTest { ...@@ -251,7 +251,7 @@ public class DeviceManagerTest {
251 251
252 252
253 private class TestProvider extends AbstractProvider implements DeviceProvider { 253 private class TestProvider extends AbstractProvider implements DeviceProvider {
254 - private Device deviceReceived; 254 + private DeviceId deviceReceived;
255 private MastershipRole roleReceived; 255 private MastershipRole roleReceived;
256 256
257 public TestProvider() { 257 public TestProvider() {
...@@ -263,13 +263,13 @@ public class DeviceManagerTest { ...@@ -263,13 +263,13 @@ public class DeviceManagerTest {
263 } 263 }
264 264
265 @Override 265 @Override
266 - public void roleChanged(Device device, MastershipRole newRole) { 266 + public void roleChanged(DeviceId device, MastershipRole newRole) {
267 deviceReceived = device; 267 deviceReceived = device;
268 roleReceived = newRole; 268 roleReceived = newRole;
269 } 269 }
270 270
271 @Override 271 @Override
272 - public boolean isReachable(Device device) { 272 + public boolean isReachable(DeviceId device) {
273 return false; 273 return false;
274 } 274 }
275 } 275 }
......
...@@ -111,8 +111,8 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr ...@@ -111,8 +111,8 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
111 111
112 112
113 @Override 113 @Override
114 - public boolean isReachable(Device device) { 114 + public boolean isReachable(DeviceId deviceId) {
115 - OpenFlowSwitch sw = controller.getSwitch(dpid(device.id().uri())); 115 + OpenFlowSwitch sw = controller.getSwitch(dpid(deviceId.uri()));
116 if (sw == null || !sw.isConnected()) { 116 if (sw == null || !sw.isConnected()) {
117 return false; 117 return false;
118 } 118 }
...@@ -170,22 +170,22 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr ...@@ -170,22 +170,22 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
170 // } 170 // }
171 171
172 @Override 172 @Override
173 - public void roleChanged(Device device, MastershipRole newRole) { 173 + public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
174 switch (newRole) { 174 switch (newRole) {
175 case MASTER: 175 case MASTER:
176 - controller.setRole(dpid(device.id().uri()), RoleState.MASTER); 176 + controller.setRole(dpid(deviceId.uri()), RoleState.MASTER);
177 break; 177 break;
178 case STANDBY: 178 case STANDBY:
179 - controller.setRole(dpid(device.id().uri()), RoleState.EQUAL); 179 + controller.setRole(dpid(deviceId.uri()), RoleState.EQUAL);
180 break; 180 break;
181 case NONE: 181 case NONE:
182 - controller.setRole(dpid(device.id().uri()), RoleState.SLAVE); 182 + controller.setRole(dpid(deviceId.uri()), RoleState.SLAVE);
183 break; 183 break;
184 default: 184 default:
185 LOG.error("Unknown Mastership state : {}", newRole); 185 LOG.error("Unknown Mastership state : {}", newRole);
186 186
187 } 187 }
188 - LOG.info("Accepting mastership role change for device {}", device.id()); 188 + LOG.info("Accepting mastership role change for device {}", deviceId);
189 } 189 }
190 190
191 private class InternalDeviceProvider implements OpenFlowSwitchListener { 191 private class InternalDeviceProvider implements OpenFlowSwitchListener {
......
...@@ -105,11 +105,11 @@ public class OpenFlowDeviceProviderTest { ...@@ -105,11 +105,11 @@ public class OpenFlowDeviceProviderTest {
105 105
106 @Test 106 @Test
107 public void roleChanged() { 107 public void roleChanged() {
108 - provider.roleChanged(DEV1, MASTER); 108 + provider.roleChanged(DID1, MASTER);
109 assertEquals("Should be MASTER", RoleState.MASTER, controller.roleMap.get(DPID1)); 109 assertEquals("Should be MASTER", RoleState.MASTER, controller.roleMap.get(DPID1));
110 - provider.roleChanged(DEV1, STANDBY); 110 + provider.roleChanged(DID1, STANDBY);
111 assertEquals("Should be EQUAL", RoleState.EQUAL, controller.roleMap.get(DPID1)); 111 assertEquals("Should be EQUAL", RoleState.EQUAL, controller.roleMap.get(DPID1));
112 - provider.roleChanged(DEV1, NONE); 112 + provider.roleChanged(DID1, NONE);
113 assertEquals("Should be SLAVE", RoleState.SLAVE, controller.roleMap.get(DPID1)); 113 assertEquals("Should be SLAVE", RoleState.SLAVE, controller.roleMap.get(DPID1));
114 } 114 }
115 115
......
...@@ -244,7 +244,7 @@ class ConfigProvider implements DeviceProvider, LinkProvider, HostProvider { ...@@ -244,7 +244,7 @@ class ConfigProvider implements DeviceProvider, LinkProvider, HostProvider {
244 } 244 }
245 245
246 @Override 246 @Override
247 - public void roleChanged(Device device, MastershipRole newRole) { 247 + public void roleChanged(DeviceId device, MastershipRole newRole) {
248 } 248 }
249 249
250 @Override 250 @Override
...@@ -257,7 +257,7 @@ class ConfigProvider implements DeviceProvider, LinkProvider, HostProvider { ...@@ -257,7 +257,7 @@ class ConfigProvider implements DeviceProvider, LinkProvider, HostProvider {
257 } 257 }
258 258
259 @Override 259 @Override
260 - public boolean isReachable(Device device) { 260 + public boolean isReachable(DeviceId device) {
261 return false; 261 return false;
262 } 262 }
263 } 263 }
......