Search in sources :

Example 1 with RoleReplyInfo

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());
}
Also used : OFControllerRole(org.projectfloodlight.openflow.protocol.OFControllerRole) RoleReplyInfo(org.onosproject.openflow.controller.driver.RoleReplyInfo) RoleState(org.onosproject.openflow.controller.RoleState) SwitchStateException(org.onosproject.openflow.controller.driver.SwitchStateException)

Example 2 with RoleReplyInfo

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());
    }
}
Also used : RoleReplyInfo(org.onosproject.openflow.controller.driver.RoleReplyInfo) IOException(java.io.IOException) SwitchStateException(org.onosproject.openflow.controller.driver.SwitchStateException) RoleRecvStatus(org.onosproject.openflow.controller.driver.RoleRecvStatus) Test(org.junit.Test)

Aggregations

RoleReplyInfo (org.onosproject.openflow.controller.driver.RoleReplyInfo)2 SwitchStateException (org.onosproject.openflow.controller.driver.SwitchStateException)2 IOException (java.io.IOException)1 Test (org.junit.Test)1 RoleState (org.onosproject.openflow.controller.RoleState)1 RoleRecvStatus (org.onosproject.openflow.controller.driver.RoleRecvStatus)1 OFControllerRole (org.projectfloodlight.openflow.protocol.OFControllerRole)1