trigger device query after mastership reelection
Change-Id: Ibf8b32ed1de2a904289731596a28bd5524d6ea25 Conflicts: core/net/src/main/java/org/onlab/onos/net/device/impl/DeviceManager.java
Showing
6 changed files
with
45 additions
and
9 deletions
| ... | @@ -13,7 +13,7 @@ public interface DeviceProvider extends Provider { | ... | @@ -13,7 +13,7 @@ public interface DeviceProvider extends Provider { |
| 13 | 13 | ||
| 14 | /** | 14 | /** |
| 15 | * Triggers an asynchronous probe of the specified device, intended to | 15 | * Triggers an asynchronous probe of the specified device, intended to |
| 16 | - * determine whether the host is present or not. An indirect result of this | 16 | + * determine whether the device is present or not. An indirect result of this |
| 17 | * should be invocation of | 17 | * should be invocation of |
| 18 | * {@link org.onlab.onos.net.device.DeviceProviderService#deviceConnected} )} or | 18 | * {@link org.onlab.onos.net.device.DeviceProviderService#deviceConnected} )} or |
| 19 | * {@link org.onlab.onos.net.device.DeviceProviderService#deviceDisconnected} | 19 | * {@link org.onlab.onos.net.device.DeviceProviderService#deviceDisconnected} | ... | ... |
| ... | @@ -161,6 +161,17 @@ public class DeviceManager | ... | @@ -161,6 +161,17 @@ public class DeviceManager |
| 161 | } | 161 | } |
| 162 | } | 162 | } |
| 163 | 163 | ||
| 164 | + // Queries a device for port information. | ||
| 165 | + private void queryPortInfo(DeviceId deviceId) { | ||
| 166 | + Device device = store.getDevice(deviceId); | ||
| 167 | + // FIXME: Device might not be there yet. (eventual consistent) | ||
| 168 | + if (device == null) { | ||
| 169 | + return; | ||
| 170 | + } | ||
| 171 | + DeviceProvider provider = getProvider(device.providerId()); | ||
| 172 | + provider.triggerProbe(device); | ||
| 173 | + } | ||
| 174 | + | ||
| 164 | @Override | 175 | @Override |
| 165 | public void removeDevice(DeviceId deviceId) { | 176 | public void removeDevice(DeviceId deviceId) { |
| 166 | checkNotNull(deviceId, DEVICE_ID_NULL); | 177 | checkNotNull(deviceId, DEVICE_ID_NULL); |
| ... | @@ -210,8 +221,6 @@ public class DeviceManager | ... | @@ -210,8 +221,6 @@ public class DeviceManager |
| 210 | log.info("Device {} connected", deviceId); | 221 | log.info("Device {} connected", deviceId); |
| 211 | // check my Role | 222 | // check my Role |
| 212 | MastershipRole role = mastershipService.requestRoleFor(deviceId); | 223 | MastershipRole role = mastershipService.requestRoleFor(deviceId); |
| 213 | - log.info("## - our role for {} is {} [master is {}]", deviceId, role, | ||
| 214 | - mastershipService.getMasterFor(deviceId)); | ||
| 215 | if (role != MastershipRole.MASTER) { | 224 | if (role != MastershipRole.MASTER) { |
| 216 | // TODO: Do we need to explicitly tell the Provider that | 225 | // TODO: Do we need to explicitly tell the Provider that |
| 217 | // this instance is no longer the MASTER? probably not | 226 | // this instance is no longer the MASTER? probably not |
| ... | @@ -265,7 +274,6 @@ public class DeviceManager | ... | @@ -265,7 +274,6 @@ public class DeviceManager |
| 265 | // but if I was the last STANDBY connection, etc. and no one else | 274 | // but if I was the last STANDBY connection, etc. and no one else |
| 266 | // was there to mark the device offline, this instance may need to | 275 | // was there to mark the device offline, this instance may need to |
| 267 | // temporarily request for Master Role and mark offline. | 276 | // temporarily request for Master Role and mark offline. |
| 268 | - log.info("## for {} role is {}", deviceId, mastershipService.getLocalRole(deviceId)); | ||
| 269 | if (!mastershipService.getLocalRole(deviceId).equals(MastershipRole.MASTER)) { | 277 | if (!mastershipService.getLocalRole(deviceId).equals(MastershipRole.MASTER)) { |
| 270 | log.debug("Device {} disconnected, but I am not the master", deviceId); | 278 | log.debug("Device {} disconnected, but I am not the master", deviceId); |
| 271 | //let go of ability to be backup | 279 | //let go of ability to be backup |
| ... | @@ -373,7 +381,6 @@ public class DeviceManager | ... | @@ -373,7 +381,6 @@ public class DeviceManager |
| 373 | final DeviceId did = event.subject(); | 381 | final DeviceId did = event.subject(); |
| 374 | final NodeId myNodeId = clusterService.getLocalNode().id(); | 382 | final NodeId myNodeId = clusterService.getLocalNode().id(); |
| 375 | 383 | ||
| 376 | - log.info("## got Mastershipevent for dev {}", did); | ||
| 377 | if (myNodeId.equals(event.roleInfo().master())) { | 384 | if (myNodeId.equals(event.roleInfo().master())) { |
| 378 | MastershipTerm term = termService.getMastershipTerm(did); | 385 | MastershipTerm term = termService.getMastershipTerm(did); |
| 379 | 386 | ||
| ... | @@ -384,7 +391,6 @@ public class DeviceManager | ... | @@ -384,7 +391,6 @@ public class DeviceManager |
| 384 | return; | 391 | return; |
| 385 | } | 392 | } |
| 386 | 393 | ||
| 387 | - log.info("## setting term for CPS as new master for {}", did); | ||
| 388 | // only set the new term if I am the master | 394 | // only set the new term if I am the master |
| 389 | deviceClockProviderService.setMastershipTerm(did, term); | 395 | deviceClockProviderService.setMastershipTerm(did, term); |
| 390 | 396 | ||
| ... | @@ -404,6 +410,7 @@ public class DeviceManager | ... | @@ -404,6 +410,7 @@ public class DeviceManager |
| 404 | device.serialNumber(), device.chassisId())); | 410 | device.serialNumber(), device.chassisId())); |
| 405 | } | 411 | } |
| 406 | //TODO re-collect device information to fix potential staleness | 412 | //TODO re-collect device information to fix potential staleness |
| 413 | + queryPortInfo(did); | ||
| 407 | applyRole(did, MastershipRole.MASTER); | 414 | applyRole(did, MastershipRole.MASTER); |
| 408 | } else if (event.roleInfo().backups().contains(myNodeId)) { | 415 | } else if (event.roleInfo().backups().contains(myNodeId)) { |
| 409 | applyRole(did, MastershipRole.STANDBY); | 416 | applyRole(did, MastershipRole.STANDBY); | ... | ... |
| ... | @@ -110,8 +110,7 @@ public interface OpenFlowSwitch { | ... | @@ -110,8 +110,7 @@ public interface OpenFlowSwitch { |
| 110 | * | 110 | * |
| 111 | * @param role the failed role | 111 | * @param role the failed role |
| 112 | */ | 112 | */ |
| 113 | - void returnRoleAssertFailure(RoleState role); | 113 | + public void returnRoleAssertFailure(RoleState role); |
| 114 | - | ||
| 115 | 114 | ||
| 116 | /** | 115 | /** |
| 117 | * Indicates if this switch is optical. | 116 | * Indicates if this switch is optical. |
| ... | @@ -120,5 +119,4 @@ public interface OpenFlowSwitch { | ... | @@ -120,5 +119,4 @@ public interface OpenFlowSwitch { |
| 120 | */ | 119 | */ |
| 121 | public boolean isOptical(); | 120 | public boolean isOptical(); |
| 122 | 121 | ||
| 123 | - | ||
| 124 | } | 122 | } | ... | ... |
| ... | @@ -608,6 +608,12 @@ class OFChannelHandler extends IdleStateAwareChannelHandler { | ... | @@ -608,6 +608,12 @@ class OFChannelHandler extends IdleStateAwareChannelHandler { |
| 608 | h.dispatchMessage(m); | 608 | h.dispatchMessage(m); |
| 609 | } | 609 | } |
| 610 | 610 | ||
| 611 | + @Override | ||
| 612 | + void processOFFeaturesReply(OFChannelHandler h, OFFeaturesReply m) { | ||
| 613 | + // TODO verify this leads to right behavior. | ||
| 614 | + h.dispatchMessage(m); | ||
| 615 | + } | ||
| 616 | + | ||
| 611 | }; | 617 | }; |
| 612 | 618 | ||
| 613 | private final boolean handshakeComplete; | 619 | private final boolean handshakeComplete; | ... | ... |
| ... | @@ -142,6 +142,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -142,6 +142,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
| 142 | public void processPacket(Dpid dpid, OFMessage msg) { | 142 | public void processPacket(Dpid dpid, OFMessage msg) { |
| 143 | switch (msg.getType()) { | 143 | switch (msg.getType()) { |
| 144 | case PORT_STATUS: | 144 | case PORT_STATUS: |
| 145 | + case FEATURES_REPLY: | ||
| 145 | for (OpenFlowSwitchListener l : ofSwitchListener) { | 146 | for (OpenFlowSwitchListener l : ofSwitchListener) { |
| 146 | l.portChanged(dpid, (OFPortStatus) msg); | 147 | l.portChanged(dpid, (OFPortStatus) msg); |
| 147 | } | 148 | } | ... | ... |
| ... | @@ -23,7 +23,9 @@ import org.onlab.onos.openflow.controller.OpenFlowController; | ... | @@ -23,7 +23,9 @@ import org.onlab.onos.openflow.controller.OpenFlowController; |
| 23 | import org.onlab.onos.openflow.controller.OpenFlowSwitch; | 23 | import org.onlab.onos.openflow.controller.OpenFlowSwitch; |
| 24 | import org.onlab.onos.openflow.controller.OpenFlowSwitchListener; | 24 | import org.onlab.onos.openflow.controller.OpenFlowSwitchListener; |
| 25 | import org.onlab.onos.openflow.controller.RoleState; | 25 | import org.onlab.onos.openflow.controller.RoleState; |
| 26 | +import org.onlab.onos.openflow.controller.driver.OpenFlowSwitchDriver; | ||
| 26 | import org.onlab.packet.ChassisId; | 27 | import org.onlab.packet.ChassisId; |
| 28 | +import org.projectfloodlight.openflow.protocol.OFFactory; | ||
| 27 | import org.projectfloodlight.openflow.protocol.OFPortConfig; | 29 | import org.projectfloodlight.openflow.protocol.OFPortConfig; |
| 28 | import org.projectfloodlight.openflow.protocol.OFPortDesc; | 30 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
| 29 | import org.projectfloodlight.openflow.protocol.OFPortState; | 31 | import org.projectfloodlight.openflow.protocol.OFPortState; |
| ... | @@ -89,6 +91,28 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr | ... | @@ -89,6 +91,28 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr |
| 89 | @Override | 91 | @Override |
| 90 | public void triggerProbe(Device device) { | 92 | public void triggerProbe(Device device) { |
| 91 | LOG.info("Triggering probe on device {}", device.id()); | 93 | LOG.info("Triggering probe on device {}", device.id()); |
| 94 | + | ||
| 95 | + // 1. check device liveness | ||
| 96 | + // FIXME if possible, we might want this to be part of | ||
| 97 | + // OpenFlowSwitch interface so the driver interface isn't misused. | ||
| 98 | + OpenFlowSwitch sw = controller.getSwitch(dpid(device.id().uri())); | ||
| 99 | + if (!((OpenFlowSwitchDriver) sw).isConnected()) { | ||
| 100 | + providerService.deviceDisconnected(device.id()); | ||
| 101 | + return; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + // 2. Prompt an update of port information. Do we have an XID for this? | ||
| 105 | + OFFactory fact = sw.factory(); | ||
| 106 | + switch (fact.getVersion()) { | ||
| 107 | + case OF_10: | ||
| 108 | + sw.sendMsg(fact.buildFeaturesRequest().setXid(0).build()); | ||
| 109 | + break; | ||
| 110 | + case OF_13: | ||
| 111 | + sw.sendMsg(fact.buildPortDescStatsRequest().setXid(0).build()); | ||
| 112 | + break; | ||
| 113 | + default: | ||
| 114 | + LOG.warn("Unhandled protocol version"); | ||
| 115 | + } | ||
| 92 | } | 116 | } |
| 93 | 117 | ||
| 94 | @Override | 118 | @Override | ... | ... |
-
Please register or login to post a comment