Search in sources :

Example 1 with SwitchStateException

use of org.onosproject.openflow.controller.driver.SwitchStateException 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 SwitchStateException

use of org.onosproject.openflow.controller.driver.SwitchStateException in project onos by opennetworkinglab.

the class RoleManager method deliverRoleReply.

@Override
public synchronized RoleRecvStatus deliverRoleReply(RoleReplyInfo rri) throws SwitchStateException {
    long xid = rri.getXid();
    RoleState receivedRole = rri.getRole();
    RoleState expectedRole = pendingReplies.getIfPresent(xid);
    if (expectedRole == null) {
        RoleState currentRole = (sw != null) ? sw.getRole() : null;
        if (currentRole != null) {
            if (currentRole == rri.getRole()) {
                // Don't disconnect if the role reply we received is
                // for the same role we are already in.
                // FIXME: but we do from the caller anyways.
                log.debug("Received unexpected RoleReply from " + "Switch: {}. " + "Role in reply is same as current role of this " + "controller for this sw. Ignoring ...", sw.getStringId());
                return RoleRecvStatus.OTHER_EXPECTATION;
            } else {
                String msg = String.format("Switch: [%s], " + "received unexpected RoleReply[%s]. " + "No roles are pending, and this controller's " + "current role:[%s] does not match reply. " + "Disconnecting switch ... ", sw.getStringId(), rri, currentRole);
                throw new SwitchStateException(msg);
            }
        }
        log.debug("Received unexpected RoleReply {} from " + "Switch: {}. " + "This controller has no current role for this sw. " + "Ignoring ...", rri, sw == null ? "(null)" : sw.getStringId());
        return RoleRecvStatus.OTHER_EXPECTATION;
    }
    // XXX Should check generation id meaningfully and other cases of expectations
    // if (pendingXid != xid) {
    // log.info("Received older role reply from " +
    // "switch {} ({}). Ignoring. " +
    // "Waiting for {}, xid={}",
    // new Object[] {sw.getStringId(), rri,
    // pendingRole, pendingXid });
    // return RoleRecvStatus.OLD_REPLY;
    // }
    sw.returnRoleReply(expectedRole, receivedRole);
    if (expectedRole == receivedRole) {
        log.debug("Received role reply message from {} that matched " + "expected role-reply {} with expectations {}", sw.getStringId(), receivedRole, expectation);
        // Done with this RoleReply; Invalidate
        pendingReplies.invalidate(xid);
        if (expectation == RoleRecvStatus.MATCHED_CURRENT_ROLE || expectation == RoleRecvStatus.MATCHED_SET_ROLE) {
            return expectation;
        } else {
            return RoleRecvStatus.OTHER_EXPECTATION;
        }
    }
    pendingReplies.invalidate(xid);
    // if xids match but role's don't, perhaps its a query (OF1.3)
    if (expectation == RoleRecvStatus.REPLY_QUERY) {
        return expectation;
    }
    return RoleRecvStatus.OTHER_EXPECTATION;
}
Also used : RoleState(org.onosproject.openflow.controller.RoleState) SwitchStateException(org.onosproject.openflow.controller.driver.SwitchStateException)

Example 3 with SwitchStateException

use of org.onosproject.openflow.controller.driver.SwitchStateException in project onos by opennetworkinglab.

the class RoleManager method extractNiciraRoleReply.

/**
 * Extract the role from an OFVendor message.
 *
 * Extract the role from an OFVendor message if the message is a
 * Nicira role reply. Otherwise return null.
 *
 * @param experimenterMsg message
 * @return The role in the message if the message is a Nicira role
 * reply, null otherwise.
 * @throws SwitchStateException If the message is a Nicira role reply
 * but the numeric role value is unknown.
 */
@Override
public RoleState extractNiciraRoleReply(OFExperimenter experimenterMsg) throws SwitchStateException {
    int vendor = (int) experimenterMsg.getExperimenter();
    if (vendor != 0x2320) {
        return null;
    }
    OFNiciraControllerRoleReply nrr = (OFNiciraControllerRoleReply) experimenterMsg;
    RoleState role = null;
    OFNiciraControllerRole ncr = nrr.getRole();
    switch(ncr) {
        case ROLE_MASTER:
            role = RoleState.MASTER;
            break;
        case ROLE_OTHER:
            role = RoleState.EQUAL;
            break;
        case ROLE_SLAVE:
            role = RoleState.SLAVE;
            break;
        // handled below
        default:
    }
    if (role == null) {
        String msg = String.format("Switch: [%s], " + "received NX_ROLE_REPLY with invalid role " + "value %s", sw.getStringId(), nrr.getRole());
        throw new SwitchStateException(msg);
    }
    return role;
}
Also used : OFNiciraControllerRoleReply(org.projectfloodlight.openflow.protocol.OFNiciraControllerRoleReply) OFNiciraControllerRole(org.projectfloodlight.openflow.protocol.OFNiciraControllerRole) RoleState(org.onosproject.openflow.controller.RoleState) SwitchStateException(org.onosproject.openflow.controller.driver.SwitchStateException)

Example 4 with SwitchStateException

use of org.onosproject.openflow.controller.driver.SwitchStateException 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

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