use of org.onosproject.openflow.controller.RoleState 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.RoleState 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;
}
use of org.onosproject.openflow.controller.RoleState in project onos by opennetworkinglab.
the class AbstractOpenFlowSwitch method handleNiciraRole.
@Override
public void handleNiciraRole(OFMessage m) throws SwitchStateException {
RoleState r = this.roleMan.extractNiciraRoleReply((OFExperimenter) m);
if (r == null) {
// The message wasn't really a Nicira role reply. We just
// dispatch it to the OFMessage listeners in this case.
this.handleMessage(m);
return;
}
RoleRecvStatus rrs = this.roleMan.deliverRoleReply(new RoleReplyInfo(r, null, m.getXid()));
if (rrs == RoleRecvStatus.MATCHED_SET_ROLE) {
if (r == RoleState.MASTER) {
this.transitionToMasterSwitch();
} else if (r == RoleState.EQUAL || r == RoleState.SLAVE) {
this.transitionToEqualSwitch();
}
} else {
this.disconnectSwitch();
}
}
use of org.onosproject.openflow.controller.RoleState 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;
}
use of org.onosproject.openflow.controller.RoleState in project onos by opennetworkinglab.
the class RoleManager method sendRoleRequest.
@Override
public synchronized boolean sendRoleRequest(RoleState role, RoleRecvStatus exp) throws IOException {
this.expectation = exp;
if (sw.factory().getVersion() == OFVersion.OF_10) {
Boolean supportsNxRole = sw.supportNxRole();
if (!supportsNxRole) {
log.debug("Switch driver indicates no support for Nicira " + "role request messages. Not sending ...");
handleUnsentRoleMessage(role, expectation);
return false;
}
// OF1.0 switch with support for NX_ROLE_REQUEST vendor extn.
// make Role.EQUAL become Role.SLAVE
RoleState roleToSend = (role == RoleState.EQUAL) ? RoleState.SLAVE : role;
pendingReplies.put(sendNxRoleRequest(roleToSend), role);
} else {
// OF1.3 switch, use OFPT_ROLE_REQUEST message
pendingReplies.put(sendOF13RoleRequest(role), role);
}
return true;
}
Aggregations