use of org.onosproject.openflow.controller.driver.RoleReplyInfo in project onos by opennetworkinglab.
the class RoleManager method extractOFRoleReply.
/**
* Extract the role information from an OF1.3 Role Reply Message.
*
* @param rrmsg the role message
* @return RoleReplyInfo object
* @throws SwitchStateException if the role information could not be extracted.
*/
@Override
public RoleReplyInfo extractOFRoleReply(OFRoleReply rrmsg) throws SwitchStateException {
OFControllerRole cr = rrmsg.getRole();
RoleState role = null;
switch(cr) {
case ROLE_EQUAL:
role = RoleState.EQUAL;
break;
case ROLE_MASTER:
role = RoleState.MASTER;
break;
case ROLE_SLAVE:
role = RoleState.SLAVE;
break;
// switch should send current role
case ROLE_NOCHANGE:
default:
String msg = String.format("Unknown controller role %s " + "received from switch %s", cr, sw);
throw new SwitchStateException(msg);
}
return new RoleReplyInfo(role, rrmsg.getGenerationId(), rrmsg.getXid());
}
use of org.onosproject.openflow.controller.driver.RoleReplyInfo in project onos by opennetworkinglab.
the class RoleManagerTest method deliverRoleReply.
@Test
public void deliverRoleReply() {
RoleRecvStatus status;
RoleReplyInfo asserted = new RoleReplyInfo(MASTER, GID, XID);
RoleReplyInfo unasserted = new RoleReplyInfo(SLAVE, GID, XID);
try {
// call without sendRoleReq() for requestPending = false
// first, sw.role == null
status = manager.deliverRoleReply(asserted);
assertEquals("expectation wrong", OTHER_EXPECTATION, status);
sw.setRole(MASTER);
assertEquals("expectation wrong", OTHER_EXPECTATION, status);
sw.setRole(SLAVE);
// match to pendingRole = MASTER, requestPending = true
manager.sendRoleRequest(MASTER, MATCHED_CURRENT_ROLE);
status = manager.deliverRoleReply(asserted);
assertEquals("expectation wrong", MATCHED_CURRENT_ROLE, status);
// requestPending never gets reset -- this might be a bug.
status = manager.deliverRoleReply(unasserted);
assertEquals("expectation wrong", OTHER_EXPECTATION, status);
assertEquals("pending role mismatch", MASTER, ((TestSwitchDriver) sw).failed);
} catch (IOException | SwitchStateException e) {
assertEquals("unexpected error thrown", SwitchStateException.class, e.getClass());
}
}
Aggregations