public static OFBadActionCode ofWireValue(short val) { switch(val) { case BAD_TYPE_VAL: return OFBadActionCode.BAD_TYPE; case BAD_LEN_VAL: return OFBadActionCode.BAD_LEN; case BAD_EXPERIMENTER_VAL: return OFBadActionCode.BAD_EXPERIMENTER; case BAD_EXPERIMENTER_TYPE_VAL: return OFBadActionCode.BAD_EXPERIMENTER_TYPE; case BAD_OUT_PORT_VAL: return OFBadActionCode.BAD_OUT_PORT; case BAD_ARGUMENT_VAL: return OFBadActionCode.BAD_ARGUMENT; case EPERM_VAL: return OFBadActionCode.EPERM; case TOO_MANY_VAL: return OFBadActionCode.TOO_MANY; case BAD_QUEUE_VAL: return OFBadActionCode.BAD_QUEUE; default: throw new IllegalArgumentException("Illegal wire value for type OFBadActionCode in version 1.0: " + val); } }
public static short toWireValue(OFBadActionCode e) { switch(e) { case BAD_TYPE: return BAD_TYPE_VAL; case BAD_LEN: return BAD_LEN_VAL; case BAD_EXPERIMENTER: return BAD_EXPERIMENTER_VAL; case BAD_EXPERIMENTER_TYPE: return BAD_EXPERIMENTER_TYPE_VAL; case BAD_OUT_PORT: return BAD_OUT_PORT_VAL; case BAD_ARGUMENT: return BAD_ARGUMENT_VAL; case EPERM: return EPERM_VAL; case TOO_MANY: return TOO_MANY_VAL; case BAD_QUEUE: return BAD_QUEUE_VAL; default: throw new IllegalArgumentException("Illegal enum value for type OFBadActionCode in version 1.0: " + e); } }
/** Return a bad action error message with the given xid/code */ private OFMessage getBadActionErrorMessage(OFBadActionCode code, long xid) { OFErrorMsg msg = factory.errorMsgs().buildBadActionErrorMsg() .setXid(xid) .setCode(code) .build(); return msg; }
/** Move the channel from scratch to SLAVE state * Builds on doMoveToWaitInitialRole() * adds testing for WAIT_INITAL_ROLE state * * This method tests the case that the switch does NOT support roles. * The channel handler still needs to send the initial request to find * out that whether the switch supports roles. * */ @Test public void testInitialMoveToSlaveNoRole() throws Exception { // first, move us to WAIT_INITIAL_ROLE_STATE moveToWaitInitialRole(); assertThat(switchHandler.getStateForTesting(), CoreMatchers.instanceOf(OFSwitchHandshakeHandler.WaitInitialRoleState.class)); // Set the role long xid = setupSwitchSendRoleRequestAndVerify(null, OFControllerRole.ROLE_SLAVE); assertThat(switchHandler.getStateForTesting(), CoreMatchers.instanceOf(OFSwitchHandshakeHandler.WaitInitialRoleState.class)); // prepare mocks and inject the role reply message reset(sw); sw.setAttribute(IOFSwitch.SWITCH_SUPPORTS_NX_ROLE, false); expectLastCall().once(); sw.setControllerRole(OFControllerRole.ROLE_SLAVE); expectLastCall().once(); sw.disconnect(); // Make sure we disconnect expectLastCall().once(); replay(sw); // FIXME: shouldn't use ordinal(), but OFError is broken // Error with incorrect xid and type. Should be ignored. OFMessage err = getBadActionErrorMessage(OFBadActionCode.BAD_TYPE, xid+1); // sendMessageToHandler will verify and rest controller mock switchHandler.processOFMessage(err); assertThat(switchHandler.getStateForTesting(), CoreMatchers.instanceOf(OFSwitchHandshakeHandler.WaitInitialRoleState.class)); // Error with correct xid. Should trigger state transition err = getBadRequestErrorMessage(OFBadRequestCode.BAD_EXPERIMENTER, xid); // sendMessageToHandler will verify and rest controller mock switchHandler.processOFMessage(err); }
/** Start from scratch and reply with an unexpected error to the role * change request * Builds on doMoveToWaitInitialRole() * adds testing for WAIT_INITAL_ROLE state */ @Test public void testInitialRoleChangeOtherError() throws Exception { // first, move us to WAIT_INITIAL_ROLE_STATE moveToWaitInitialRole(); assertThat(switchHandler.getStateForTesting(), CoreMatchers.instanceOf(OFSwitchHandshakeHandler.WaitInitialRoleState.class)); // Set the role long xid = setupSwitchSendRoleRequestAndVerify(null, OFControllerRole.ROLE_MASTER); assertThat(switchHandler.getStateForTesting(), CoreMatchers.instanceOf(OFSwitchHandshakeHandler.WaitInitialRoleState.class)); OFMessage err = getBadActionErrorMessage(OFBadActionCode.BAD_TYPE, xid); verifyExceptionCaptured(err, SwitchStateException.class); }
public static OFBadActionCode readFrom(ChannelBuffer bb) throws OFParseError { try { return ofWireValue(bb.readShort()); } catch (IllegalArgumentException e) { throw new OFParseError(e); } }
public static OFBadActionCode ofWireValue(short val) { switch(val) { case BAD_TYPE_VAL: return OFBadActionCode.BAD_TYPE; case BAD_LEN_VAL: return OFBadActionCode.BAD_LEN; case BAD_EXPERIMENTER_VAL: return OFBadActionCode.BAD_EXPERIMENTER; case BAD_EXPERIMENTER_TYPE_VAL: return OFBadActionCode.BAD_EXPERIMENTER_TYPE; case BAD_OUT_PORT_VAL: return OFBadActionCode.BAD_OUT_PORT; case BAD_ARGUMENT_VAL: return OFBadActionCode.BAD_ARGUMENT; case EPERM_VAL: return OFBadActionCode.EPERM; case TOO_MANY_VAL: return OFBadActionCode.TOO_MANY; case BAD_QUEUE_VAL: return OFBadActionCode.BAD_QUEUE; case BAD_OUT_GROUP_VAL: return OFBadActionCode.BAD_OUT_GROUP; case MATCH_INCONSISTENT_VAL: return OFBadActionCode.MATCH_INCONSISTENT; case UNSUPPORTED_ORDER_VAL: return OFBadActionCode.UNSUPPORTED_ORDER; case BAD_TAG_VAL: return OFBadActionCode.BAD_TAG; case BAD_SET_TYPE_VAL: return OFBadActionCode.BAD_SET_TYPE; case BAD_SET_LEN_VAL: return OFBadActionCode.BAD_SET_LEN; case BAD_SET_ARGUMENT_VAL: return OFBadActionCode.BAD_SET_ARGUMENT; default: throw new IllegalArgumentException("Illegal wire value for type OFBadActionCode in version 1.2: " + val); } }
public static short toWireValue(OFBadActionCode e) { switch(e) { case BAD_TYPE: return BAD_TYPE_VAL; case BAD_LEN: return BAD_LEN_VAL; case BAD_EXPERIMENTER: return BAD_EXPERIMENTER_VAL; case BAD_EXPERIMENTER_TYPE: return BAD_EXPERIMENTER_TYPE_VAL; case BAD_OUT_PORT: return BAD_OUT_PORT_VAL; case BAD_ARGUMENT: return BAD_ARGUMENT_VAL; case EPERM: return EPERM_VAL; case TOO_MANY: return TOO_MANY_VAL; case BAD_QUEUE: return BAD_QUEUE_VAL; case BAD_OUT_GROUP: return BAD_OUT_GROUP_VAL; case MATCH_INCONSISTENT: return MATCH_INCONSISTENT_VAL; case UNSUPPORTED_ORDER: return UNSUPPORTED_ORDER_VAL; case BAD_TAG: return BAD_TAG_VAL; case BAD_SET_TYPE: return BAD_SET_TYPE_VAL; case BAD_SET_LEN: return BAD_SET_LEN_VAL; case BAD_SET_ARGUMENT: return BAD_SET_ARGUMENT_VAL; default: throw new IllegalArgumentException("Illegal enum value for type OFBadActionCode in version 1.2: " + e); } }