本文整理汇总了Java中org.projectfloodlight.openflow.protocol.OFControllerRole类的典型用法代码示例。如果您正苦于以下问题:Java OFControllerRole类的具体用法?Java OFControllerRole怎么用?Java OFControllerRole使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OFControllerRole类属于org.projectfloodlight.openflow.protocol包,在下文中一共展示了OFControllerRole类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractOFRoleReply
import org.projectfloodlight.openflow.protocol.OFControllerRole; //导入依赖的package包/类
/**
* 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;
case ROLE_NOCHANGE: // switch should send current role
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());
}
示例2: moveToWaitInitialRole
import org.projectfloodlight.openflow.protocol.OFControllerRole; //导入依赖的package包/类
@Override
@Test
public void moveToWaitInitialRole() throws Exception {
moveToWaitAppHandshakeState();
assertThat(switchHandler.getStateForTesting(), CoreMatchers.instanceOf(WaitAppHandshakeState.class));
reset(sw);
expect(sw.getAttribute(IOFSwitchBackend.SWITCH_SUPPORTS_NX_ROLE)).andReturn(true).anyTimes();
replay(sw);
reset(roleManager);
expect(roleManager.getOFControllerRole()).andReturn(OFControllerRole.ROLE_MASTER).anyTimes();
roleManager.notifyControllerConnectionUpdate();
expectLastCall().once();
replay(roleManager);
WaitAppHandshakeState state = (WaitAppHandshakeState) switchHandler.getStateForTesting();
state.enterNextPlugin();
// Expect wait initial role's enterState message to be written
OFMessage msg = connection.retrieveMessage();
assertThat(msg, CoreMatchers.instanceOf(OFRoleRequest.class));
verifyUniqueXids(msg);
assertThat(switchHandler.getStateForTesting(), CoreMatchers.instanceOf(OFSwitchHandshakeHandler.WaitInitialRoleState.class));
}
示例3: sendRoleRequestIfNotPending
import org.projectfloodlight.openflow.protocol.OFControllerRole; //导入依赖的package包/类
/**
* Send a role request for the given role only if no other role
* request is currently pending.
* @param role The role to send to the switch.
* @throws IOException
*/
synchronized void sendRoleRequestIfNotPending(OFControllerRole role, long xid)
throws IOException {
long now = System.nanoTime();
if (now - lastAssertTimeNs < assertTimeIntervalNs) {
return;
}
lastAssertTimeNs = now;
if (assertTimeIntervalNs < MAX_ASSERT_TIME_INTERVAL_NS) { // 2 minutes max
assertTimeIntervalNs <<= 1;
} else if (role == OFControllerRole.ROLE_MASTER){
log.warn("Reasserting master role on switch {}, " +
"likely a switch config error with multiple masters",
role, sw);
}
if (!requestPending)
sendRoleRequest(role, xid);
else
switchManagerCounters.roleNotResentBecauseRolePending.increment();
}
示例4: sendRoleRequest
import org.projectfloodlight.openflow.protocol.OFControllerRole; //导入依赖的package包/类
/**
* Send a role request with the given role to the switch.
*
* Send a role request with the given role to the switch and update
* the pending request and timestamp.
*
* @param role
* @throws IOException
*/
synchronized void sendRoleRequest(OFControllerRole role, long xid) throws IOException {
/*
* There are three cases to consider for SUPPORTS_NX_ROLE:
*
* 1) unset. We have neither received a role reply from the
* switch nor has a request timed out. Send a request.
* 2) TRUE: We've already send a request earlier and received
* a reply. The switch supports role and we should send one.
* 3) FALSE: We have already send a role and received an error.
* The switch does not support roles. Don't send a role request,
* set the switch's role directly.
*/
Boolean supportsNxRole = (Boolean)
sw.getAttribute(IOFSwitch.SWITCH_SUPPORTS_NX_ROLE);
if ((supportsNxRole != null) && !supportsNxRole) {
setSwitchRole(role, RoleRecvStatus.UNSUPPORTED);
} else {
pendingXid = sendNiciraRoleRequest(role, xid);
pendingRole = role;
this.roleSubmitTimeNs = System.nanoTime();
requestPending = true;
}
}
示例5: setSwitchRole
import org.projectfloodlight.openflow.protocol.OFControllerRole; //导入依赖的package包/类
/**
* Set the role for this switch / channel.
*
* If the status indicates that we received a reply we set the role.
* If the status indicates otherwise we disconnect the switch if
* the role is SLAVE.
*
* "Setting a role" means setting the appropriate ChannelState,
* setting the flags on the switch and
* notifying Controller.java about new role of the switch
*
* @param role The role to set.
* @param status How we derived at the decision to set this status.
*/
synchronized private void setSwitchRole(OFControllerRole role, RoleRecvStatus status) {
requestPending = false;
if (status == RoleRecvStatus.RECEIVED_REPLY)
sw.setAttribute(IOFSwitch.SWITCH_SUPPORTS_NX_ROLE, true);
else
sw.setAttribute(IOFSwitch.SWITCH_SUPPORTS_NX_ROLE, false);
sw.setControllerRole(role);
if (role != OFControllerRole.ROLE_SLAVE) {
OFSwitchHandshakeHandler.this.setState(new MasterState());
} else {
if (status != RoleRecvStatus.RECEIVED_REPLY) {
if (log.isDebugEnabled()) {
log.debug("Disconnecting switch {}. Doesn't support role"
+ "({}) request and controller is now SLAVE",
getSwitchInfoString(), status);
}
// the disconnect will trigger a switch removed to
// controller so no need to signal anything else
sw.disconnect();
} else {
OFSwitchHandshakeHandler.this.setState(new SlaveState());
}
}
}
示例6: enterState
import org.projectfloodlight.openflow.protocol.OFControllerRole; //导入依赖的package包/类
@Override
void enterState() {
if (OFSwitchManager.clearTablesOnEachTransitionToMaster) {
log.info("Clearing flow tables of {} on upcoming transition to MASTER.", sw.getId().toString());
clearAllTables();
} else if (OFSwitchManager.clearTablesOnInitialConnectAsMaster && initialRole == null) { /* don't do it if we were slave first */
initialRole = OFControllerRole.ROLE_MASTER;
log.info("Clearing flow tables of {} on upcoming initial role as MASTER.", sw.getId().toString());
clearAllTables();
}
sendBarrier(); /* Need to make sure the tables are clear before adding default flows */
addDefaultFlows();
/*
* We also need a barrier between adding flows and notifying modules of the
* transition to master. Some modules might modify the flow tables and expect
* the clear/default flow operations above to have completed.
*/
sendBarrier();
setSwitchStatus(SwitchStatus.MASTER);
}
示例7: notifyPortChanged
import org.projectfloodlight.openflow.protocol.OFControllerRole; //导入依赖的package包/类
@Override
public synchronized void notifyPortChanged(IOFSwitchBackend sw,
OFPortDesc port,
PortChangeType changeType) {
Preconditions.checkNotNull(sw, "switch must not be null");
Preconditions.checkNotNull(port, "port must not be null");
Preconditions.checkNotNull(changeType, "changeType must not be null");
if (role != OFControllerRole.ROLE_MASTER) {
counters.invalidPortsChanged.increment();
return;
}
if (!this.switches.containsKey(sw.getId())) {
counters.invalidPortsChanged.increment();
return;
}
if(sw.getStatus().isVisible()) {
// no need to count here. SwitchUpdate.dispatch will count
// the portchanged
SwitchUpdate update = new SwitchUpdate(sw.getId(),
SwitchUpdateType.PORTCHANGED,
port, changeType);
addUpdateToQueue(update);
}
}
示例8: testHasAnotherMaster
import org.projectfloodlight.openflow.protocol.OFControllerRole; //导入依赖的package包/类
/**
* This test ensures that the switch accurately determined if another master
* exists in the cluster by examining the controller connections it has.
*/
@Test
public void testHasAnotherMaster() {
URI cokeUri = URIUtil.createURI("1.2.3.4", 6653);
InetSocketAddress address = (InetSocketAddress) sw.getConnection(OFAuxId.MAIN).getLocalInetAddress();
URI pepsiUri = URIUtil.createURI(address.getHostName(), address.getPort());
updateControllerConnections(sw, OFControllerRole.ROLE_SLAVE, OFBsnControllerConnectionState.BSN_CONTROLLER_CONNECTION_STATE_CONNECTED, cokeUri.toString(),
OFControllerRole.ROLE_MASTER, OFBsnControllerConnectionState.BSN_CONTROLLER_CONNECTION_STATE_CONNECTED, pepsiUri.toString());
// From the perspective of pepsi, the cluster currently does NOT have another master controller
assertFalse(sw.hasAnotherMaster());
// Switch the controller connections so that pepsi is no longer master
updateControllerConnections(sw, OFControllerRole.ROLE_MASTER, OFBsnControllerConnectionState.BSN_CONTROLLER_CONNECTION_STATE_CONNECTED, cokeUri.toString(),
OFControllerRole.ROLE_SLAVE, OFBsnControllerConnectionState.BSN_CONTROLLER_CONNECTION_STATE_CONNECTED, pepsiUri.toString());
// From the perspective of pepsi, the cluster currently has another master controller
assertTrue(sw.hasAnotherMaster());
}
示例9: setupSwitchSendRoleRequestAndVerify
import org.projectfloodlight.openflow.protocol.OFControllerRole; //导入依赖的package包/类
/**
* Setup the mock switch and write capture for a role request, set the
* role and verify mocks.
* @param supportsNxRole whether the switch supports role request messages
* to setup the attribute. This must be null (don't yet know if roles
* supported: send to check) or true.
* @param role The role to send
* @throws IOException
*/
private long setupSwitchSendRoleRequestAndVerify(Boolean supportsNxRole,
OFControllerRole role) throws IOException {
assertTrue("This internal test helper method most not be called " +
"with supportsNxRole==false. Test setup broken",
supportsNxRole == null || supportsNxRole == true);
reset(sw);
expect(sw.getAttribute(IOFSwitch.SWITCH_SUPPORTS_NX_ROLE))
.andReturn(supportsNxRole).atLeastOnce();
replay(sw);
switchHandler.sendRoleRequest(role);
OFMessage msg = connection.retrieveMessage();
verifyRoleRequest(msg, role);
verify(sw);
return msg.getXid();
}
示例10: moveToWaitInitialRole
import org.projectfloodlight.openflow.protocol.OFControllerRole; //导入依赖的package包/类
@Override
@Test
public void moveToWaitInitialRole()
throws Exception {
moveToWaitAppHandshakeState();
assertThat(switchHandler.getStateForTesting(),
CoreMatchers.instanceOf(WaitAppHandshakeState.class));
reset(sw);
expect(sw.getAttribute(IOFSwitchBackend.SWITCH_SUPPORTS_NX_ROLE)).andReturn(true).anyTimes();
replay(sw);
reset(roleManager);
expect(roleManager.getOFControllerRole()).andReturn(OFControllerRole.ROLE_MASTER).anyTimes();
replay(roleManager);
WaitAppHandshakeState state = (WaitAppHandshakeState) switchHandler.getStateForTesting();
PluginResult result = new PluginResult(PluginResultType.CONTINUE);
state.exitPlugin(result);
assertThat(connection.retrieveMessage(), instanceOf(getRoleRequestClass()));
assertThat(switchHandler.getStateForTesting(), CoreMatchers.instanceOf(OFSwitchHandshakeHandler.WaitInitialRoleState.class));
}
示例11: parseRole
import org.projectfloodlight.openflow.protocol.OFControllerRole; //导入依赖的package包/类
private static OFControllerRole parseRole(String role) {
if (role == null || role.isEmpty()) {
return OFControllerRole.ROLE_NOCHANGE;
}
role = role.toUpperCase();
if (role.contains(STR_ROLE_MASTER)) {
return OFControllerRole.ROLE_MASTER;
} else if (role.contains(STR_ROLE_SLAVE)) {
return OFControllerRole.ROLE_SLAVE;
} else if (role.contains(STR_ROLE_EQUAL) || role.contains(STR_ROLE_OTHER)) {
return OFControllerRole.ROLE_EQUAL;
} else {
return OFControllerRole.ROLE_NOCHANGE;
}
}
示例12: testChannelHandlerMaster
import org.projectfloodlight.openflow.protocol.OFControllerRole; //导入依赖的package包/类
/**
* Test interaction with OFChannelHandler when the current role is
* master.
*/
@Test
public void testChannelHandlerMaster() {
OFSwitchHandshakeHandler h = createMock(OFSwitchHandshakeHandler.class);
// Reassert the role.
reset(h);
h.sendRoleRequestIfNotPending(OFControllerRole.ROLE_MASTER);
replay(h);
controller.reassertRole(h, HARole.ACTIVE);
verify(h);
// reassert a different role: no-op
reset(h);
replay(h);
controller.reassertRole(h, HARole.STANDBY);
verify(h);
}
示例13: processOFPacketIn
import org.projectfloodlight.openflow.protocol.OFControllerRole; //导入依赖的package包/类
@Override
@LogMessageDoc(level="WARN",
message="Received PacketIn from switch {} while" +
"being slave. Reasserting slave role.",
explanation="The switch has receive a PacketIn despite being " +
"in slave role indicating inconsistent controller roles",
recommendation="This situation can occurs transiently during role" +
" changes. If, however, the condition persists or happens" +
" frequently this indicates a role inconsistency. " +
LogMessageDoc.CHECK_CONTROLLER )
void processOFPacketIn(OFPacketIn m) {
// we don't expect packetIn while slave, reassert we are slave
switchManagerCounters.packetInWhileSwitchIsSlave.increment();
log.warn("Received PacketIn from switch {} while" +
"being slave. Reasserting slave role.", sw);
reassertRole(OFControllerRole.ROLE_SLAVE);
}
示例14: testHasAnotherMaster
import org.projectfloodlight.openflow.protocol.OFControllerRole; //导入依赖的package包/类
/**
* This test ensures that the switch accurately determined if another master
* exists in the cluster by examining the controller connections it has.
*/
@Test
public void testHasAnotherMaster() {
URI cokeUri = URIUtil.createURI("1.2.3.4", 6653);
InetSocketAddress address = (InetSocketAddress) sw.getConnection(OFAuxId.MAIN).getLocalInetAddress();
URI pepsiUri = URIUtil.createURI(address.getHostName(), address.getPort());
updateControllerConnections(sw, OFControllerRole.ROLE_SLAVE, OFBsnControllerConnectionState.BSN_CONTROLLER_CONNECTION_STATE_CONNECTED, cokeUri.toString(),
OFControllerRole.ROLE_MASTER, OFBsnControllerConnectionState.BSN_CONTROLLER_CONNECTION_STATE_CONNECTED, pepsiUri.toString());
// From the perspective of pepsi, the cluster currently does NOT have another master controller
assertFalse(sw.hasAnotherMaster());
// Switch the controller connections so that pepsi is no longer master
updateControllerConnections(sw, OFControllerRole.ROLE_MASTER, OFBsnControllerConnectionState.BSN_CONTROLLER_CONNECTION_STATE_CONNECTED, cokeUri.toString(),
OFControllerRole.ROLE_SLAVE, OFBsnControllerConnectionState.BSN_CONTROLLER_CONNECTION_STATE_CONNECTED, pepsiUri.toString());
// From the perspective of pepsi, the cluster currently has another master controller
assertTrue(sw.hasAnotherMaster());
}
示例15: sendOF13RoleRequest
import org.projectfloodlight.openflow.protocol.OFControllerRole; //导入依赖的package包/类
private int sendOF13RoleRequest(RoleState role) throws IOException {
// Convert the role enum to the appropriate role to send
OFControllerRole roleToSend = OFControllerRole.ROLE_NOCHANGE;
switch (role) {
case EQUAL:
roleToSend = OFControllerRole.ROLE_EQUAL;
break;
case MASTER:
roleToSend = OFControllerRole.ROLE_MASTER;
break;
case SLAVE:
roleToSend = OFControllerRole.ROLE_SLAVE;
break;
default:
log.warn("Sending default role.noChange to switch {}."
+ " Should only be used for queries.", sw);
}
int xid = sw.getNextTransactionId();
OFRoleRequest rrm = OFFactories.getFactory(OFVersion.OF_13)
.buildRoleRequest()
.setRole(roleToSend)
.setXid(xid)
//FIXME fix below when we actually use generation ids
.setGenerationId(U64.ZERO)
.build();
sw.sendRoleRequest(rrm);
return xid;
}