Ayaka Koshibe

role assertion failure is returned to DeviceProvider

Change-Id: Ic5189327c85fa37b3bbfa07d0e285cabae363712
......@@ -233,6 +233,8 @@ public class DeviceManager
@Override
public void unableToAssertRole(DeviceId deviceId, MastershipRole role) {
// FIXME: implement response to this notification
log.warn("Falied to assert role [{}] onto Device {}",
role, deviceId);
}
}
......
......@@ -11,7 +11,6 @@ import org.onlab.onos.net.DefaultDevice;
import org.onlab.onos.net.DefaultPort;
import org.onlab.onos.net.Device;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.MastershipRole;
import org.onlab.onos.net.Port;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.device.DeviceDescription;
......@@ -54,7 +53,6 @@ public class SimpleDeviceStore
public static final String DEVICE_NOT_FOUND = "Device with ID %s not found";
private final Map<DeviceId, DefaultDevice> devices = new ConcurrentHashMap<>();
private final Map<DeviceId, MastershipRole> roles = new ConcurrentHashMap<>();
private final Set<DeviceId> availableDevices = new HashSet<>();
private final Map<DeviceId, Map<PortNumber, Port>> devicePorts = new HashMap<>();
......@@ -257,7 +255,6 @@ public class SimpleDeviceStore
@Override
public DeviceEvent removeDevice(DeviceId deviceId) {
synchronized (this) {
roles.remove(deviceId);
Device device = devices.remove(deviceId);
return device == null ? null :
new DeviceEvent(DEVICE_REMOVED, device, null);
......
......@@ -105,4 +105,11 @@ public interface OpenFlowSwitch {
*/
public void disconnectSwitch();
/**
* Notifies the controller that role assertion has failed.
*
* @param role the failed role
*/
void returnRoleAssertFailure(RoleState role);
}
......
......@@ -25,4 +25,12 @@ public interface OpenFlowSwitchListener {
* @param status the new state of the port.
*/
public void portChanged(Dpid dpid, OFPortStatus status);
/**
* Notify that a role imposed on a switch failed to take hold.
*
* @param dpid the switch that failed role assertion
* @param role the role imposed by the controller
*/
public void roleAssertFailed(Dpid dpid, RoleState role);
}
......
......@@ -213,6 +213,11 @@ public abstract class AbstractOpenFlowSwitch implements OpenFlowSwitchDriver {
}
@Override
public void returnRoleAssertFailure(RoleState role) {
this.agent.returnRoleAssertFailed(dpid, role);
}
@Override
public abstract void startDriverHandshake();
@Override
......
......@@ -2,6 +2,7 @@ package org.onlab.onos.openflow.controller.driver;
import org.onlab.onos.openflow.controller.Dpid;
import org.onlab.onos.openflow.controller.OpenFlowSwitch;
import org.onlab.onos.openflow.controller.RoleState;
import org.projectfloodlight.openflow.protocol.OFMessage;
/**
......@@ -74,4 +75,12 @@ public interface OpenFlowAgent {
* @param m the message to process
*/
public void processMessage(Dpid dpid, OFMessage m);
/**
* Notifies the controller that role assertion has failed.
*
* @param dpid the switch that failed role assertion
* @param role the failed role
*/
public void returnRoleAssertFailed(Dpid dpid, RoleState role);
}
......
......@@ -313,6 +313,13 @@ public class OpenFlowControllerImpl implements OpenFlowController {
public void processMessage(Dpid dpid, OFMessage m) {
processPacket(dpid, m);
}
@Override
public void returnRoleAssertFailed(Dpid dpid, RoleState role) {
for (OpenFlowSwitchListener l : ofSwitchListener) {
l.roleAssertFailed(dpid, role);
}
}
}
private final class OFMessageHandler implements Runnable {
......
......@@ -232,6 +232,8 @@ class RoleManager implements RoleHandler {
} else {
return RoleRecvStatus.OTHER_EXPECTATION;
}
} else {
sw.returnRoleAssertFailure(pendingRole);
}
// if xids match but role's don't, perhaps its a query (OF1.3)
......
......@@ -142,6 +142,26 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
providerService.portStatusChanged(deviceId(uri(dpid)), portDescription);
}
@Override
public void roleAssertFailed(Dpid dpid, RoleState role) {
MastershipRole failed;
switch (role) {
case MASTER:
failed = MastershipRole.MASTER;
break;
case EQUAL:
failed = MastershipRole.STANDBY;
break;
case SLAVE:
failed = MastershipRole.NONE;
break;
default:
LOG.warn("unknown role {}", role);
return;
}
providerService.unableToAssertRole(deviceId(uri(dpid)), failed);
}
/**
* Builds a list of port descriptions for a given list of ports.
*
......@@ -169,6 +189,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
!port.getConfig().contains(OFPortConfig.PORT_DOWN);
return new DefaultPortDescription(portNo, enabled);
}
}
}
......
......@@ -344,6 +344,10 @@ public class OpenFlowDeviceProviderTest {
public void disconnectSwitch() {
}
@Override
public void returnRoleAssertFailure(RoleState role) {
}
}
}
......
......@@ -23,6 +23,7 @@ import org.onlab.onos.openflow.controller.OpenFlowController;
import org.onlab.onos.openflow.controller.OpenFlowEventListener;
import org.onlab.onos.openflow.controller.OpenFlowSwitch;
import org.onlab.onos.openflow.controller.OpenFlowSwitchListener;
import org.onlab.onos.openflow.controller.RoleState;
import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry;
import org.projectfloodlight.openflow.protocol.OFFlowStatsReply;
......@@ -162,6 +163,12 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
}
@Override
public void roleAssertFailed(Dpid dpid, RoleState role) {
// TODO Auto-generated method stub
}
private synchronized void pushFlowMetrics(Dpid dpid, OFStatsReply stats) {
if (stats.getStatsType() != OFStatsType.FLOW) {
return;
......
......@@ -22,6 +22,7 @@ import org.onlab.onos.openflow.controller.OpenFlowPacketContext;
import org.onlab.onos.openflow.controller.OpenFlowSwitch;
import org.onlab.onos.openflow.controller.OpenFlowSwitchListener;
import org.onlab.onos.openflow.controller.PacketListener;
import org.onlab.onos.openflow.controller.RoleState;
import org.projectfloodlight.openflow.protocol.OFPortConfig;
import org.projectfloodlight.openflow.protocol.OFPortDesc;
import org.projectfloodlight.openflow.protocol.OFPortState;
......@@ -135,6 +136,11 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid
}
@Override
public void roleAssertFailed(Dpid dpid, RoleState role) {
// TODO Auto-generated method stub
}
}
}
......
......@@ -394,6 +394,10 @@ public class OpenFlowPacketProviderTest {
public void disconnectSwitch() {
}
@Override
public void returnRoleAssertFailure(RoleState role) {
}
}
}
......