Ayaka Koshibe

trigger device query after mastership reelection

Change-Id: Ibf8b32ed1de2a904289731596a28bd5524d6ea25

Conflicts:
	core/net/src/main/java/org/onlab/onos/net/device/impl/DeviceManager.java
......@@ -13,7 +13,7 @@ public interface DeviceProvider extends Provider {
/**
* Triggers an asynchronous probe of the specified device, intended to
* determine whether the host is present or not. An indirect result of this
* determine whether the device is present or not. An indirect result of this
* should be invocation of
* {@link org.onlab.onos.net.device.DeviceProviderService#deviceConnected} )} or
* {@link org.onlab.onos.net.device.DeviceProviderService#deviceDisconnected}
......
......@@ -161,6 +161,17 @@ public class DeviceManager
}
}
// Queries a device for port information.
private void queryPortInfo(DeviceId deviceId) {
Device device = store.getDevice(deviceId);
// FIXME: Device might not be there yet. (eventual consistent)
if (device == null) {
return;
}
DeviceProvider provider = getProvider(device.providerId());
provider.triggerProbe(device);
}
@Override
public void removeDevice(DeviceId deviceId) {
checkNotNull(deviceId, DEVICE_ID_NULL);
......@@ -210,8 +221,6 @@ public class DeviceManager
log.info("Device {} connected", deviceId);
// check my Role
MastershipRole role = mastershipService.requestRoleFor(deviceId);
log.info("## - our role for {} is {} [master is {}]", deviceId, role,
mastershipService.getMasterFor(deviceId));
if (role != MastershipRole.MASTER) {
// TODO: Do we need to explicitly tell the Provider that
// this instance is no longer the MASTER? probably not
......@@ -265,7 +274,6 @@ public class DeviceManager
// but if I was the last STANDBY connection, etc. and no one else
// was there to mark the device offline, this instance may need to
// temporarily request for Master Role and mark offline.
log.info("## for {} role is {}", deviceId, mastershipService.getLocalRole(deviceId));
if (!mastershipService.getLocalRole(deviceId).equals(MastershipRole.MASTER)) {
log.debug("Device {} disconnected, but I am not the master", deviceId);
//let go of ability to be backup
......@@ -373,7 +381,6 @@ public class DeviceManager
final DeviceId did = event.subject();
final NodeId myNodeId = clusterService.getLocalNode().id();
log.info("## got Mastershipevent for dev {}", did);
if (myNodeId.equals(event.roleInfo().master())) {
MastershipTerm term = termService.getMastershipTerm(did);
......@@ -384,7 +391,6 @@ public class DeviceManager
return;
}
log.info("## setting term for CPS as new master for {}", did);
// only set the new term if I am the master
deviceClockProviderService.setMastershipTerm(did, term);
......@@ -404,6 +410,7 @@ public class DeviceManager
device.serialNumber(), device.chassisId()));
}
//TODO re-collect device information to fix potential staleness
queryPortInfo(did);
applyRole(did, MastershipRole.MASTER);
} else if (event.roleInfo().backups().contains(myNodeId)) {
applyRole(did, MastershipRole.STANDBY);
......
......@@ -110,8 +110,7 @@ public interface OpenFlowSwitch {
*
* @param role the failed role
*/
void returnRoleAssertFailure(RoleState role);
public void returnRoleAssertFailure(RoleState role);
/**
* Indicates if this switch is optical.
......@@ -120,5 +119,4 @@ public interface OpenFlowSwitch {
*/
public boolean isOptical();
}
......
......@@ -608,6 +608,12 @@ class OFChannelHandler extends IdleStateAwareChannelHandler {
h.dispatchMessage(m);
}
@Override
void processOFFeaturesReply(OFChannelHandler h, OFFeaturesReply m) {
// TODO verify this leads to right behavior.
h.dispatchMessage(m);
}
};
private final boolean handshakeComplete;
......
......@@ -142,6 +142,7 @@ public class OpenFlowControllerImpl implements OpenFlowController {
public void processPacket(Dpid dpid, OFMessage msg) {
switch (msg.getType()) {
case PORT_STATUS:
case FEATURES_REPLY:
for (OpenFlowSwitchListener l : ofSwitchListener) {
l.portChanged(dpid, (OFPortStatus) msg);
}
......
......@@ -23,7 +23,9 @@ import org.onlab.onos.openflow.controller.OpenFlowController;
import org.onlab.onos.openflow.controller.OpenFlowSwitch;
import org.onlab.onos.openflow.controller.OpenFlowSwitchListener;
import org.onlab.onos.openflow.controller.RoleState;
import org.onlab.onos.openflow.controller.driver.OpenFlowSwitchDriver;
import org.onlab.packet.ChassisId;
import org.projectfloodlight.openflow.protocol.OFFactory;
import org.projectfloodlight.openflow.protocol.OFPortConfig;
import org.projectfloodlight.openflow.protocol.OFPortDesc;
import org.projectfloodlight.openflow.protocol.OFPortState;
......@@ -89,6 +91,28 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
@Override
public void triggerProbe(Device device) {
LOG.info("Triggering probe on device {}", device.id());
// 1. check device liveness
// FIXME if possible, we might want this to be part of
// OpenFlowSwitch interface so the driver interface isn't misused.
OpenFlowSwitch sw = controller.getSwitch(dpid(device.id().uri()));
if (!((OpenFlowSwitchDriver) sw).isConnected()) {
providerService.deviceDisconnected(device.id());
return;
}
// 2. Prompt an update of port information. Do we have an XID for this?
OFFactory fact = sw.factory();
switch (fact.getVersion()) {
case OF_10:
sw.sendMsg(fact.buildFeaturesRequest().setXid(0).build());
break;
case OF_13:
sw.sendMsg(fact.buildPortDescStatsRequest().setXid(0).build());
break;
default:
LOG.warn("Unhandled protocol version");
}
}
@Override
......