/** * 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; default: //handled below } 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; }
public static OFControllerRole niciraToOFRole(OFNiciraControllerRoleReply roleReply) { switch(roleReply.getRole()) { case ROLE_MASTER: return OFControllerRole.ROLE_MASTER; case ROLE_OTHER: return OFControllerRole.ROLE_EQUAL; case ROLE_SLAVE: return OFControllerRole.ROLE_SLAVE; default: throw new IllegalArgumentException("unknown Nicira role value: " + roleReply.getRole()); } }
@Override protected OFMessage getRoleReply(long xid, OFControllerRole role) { OFNiciraControllerRoleReply roleReply = factory.buildNiciraControllerRoleReply() .setXid(xid) .setRole(NiciraRoleUtils.ofRoleToNiciraRole(role)) .build(); return roleReply; }
/** * 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 h The channel handler receiving the message * @param vendorMessage The vendor message to parse. * @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. */ protected Role extractNiciraRoleReply(OFChannelHandler h, OFExperimenter experimenterMsg) throws SwitchStateException { int vendor = (int) experimenterMsg.getExperimenter(); if (vendor != 0x2320) // magic number representing nicira return null; OFNiciraControllerRoleReply nrr = (OFNiciraControllerRoleReply) experimenterMsg; Role role = null; OFNiciraControllerRole ncr = nrr.getRole(); switch (ncr) { case ROLE_MASTER: role = Role.MASTER; break; case ROLE_OTHER: role = Role.EQUAL; break; case ROLE_SLAVE: role = Role.SLAVE; break; default: // handled below } if (role == null) { String msg = String.format("Switch: [%s], State: [%s], " + "received NX_ROLE_REPLY with invalid role " + "value %d", h.getSwitchInfoString(), this.toString(), nrr.getRole()); throw new SwitchStateException(msg); } return role; }
/** * Test dispatch of messages while in Complete state */ @Test public void testMessageDispatchComplete() throws Exception { moveToComplete(); newConnection.getValue().setListener(connectionListener); resetChannel(); expect(channel.writeAndFlush(capture(writeCapture))).andReturn(null).atLeastOnce(); replay(channel); // Send echo request. expect reply OFMessage echoRequest = factory.buildEchoRequest().build(); sendMessageToHandlerWithControllerReset(ImmutableList.<OFMessage>of(echoRequest)); List<OFMessage> msgs = getMessagesFromCapture(); assertEquals(1, msgs.size()); assertEquals(OFType.ECHO_REPLY, msgs.get(0).getType()); // Send barrier reply. expect dispatch OFBarrierReply barrierReply = factory.buildBarrierReply() .build(); resetAndExpectConnectionListener(barrierReply); // Send packet in. expect dispatch OFFlowRemoved flowRemoved = factory.buildFlowRemoved() .build(); resetAndExpectConnectionListener(flowRemoved); // Send get config reply. expect dispatch OFGetConfigReply getConfigReply = factory.buildGetConfigReply() .build(); resetAndExpectConnectionListener(getConfigReply); // Send packet in. expect dispatch OFPacketIn pi = factory.buildPacketIn() .setReason(OFPacketInReason.NO_MATCH) .build(); resetAndExpectConnectionListener(pi); // Send port status. expect dispatch OFPortStatus portStatus = factory.buildPortStatus() .setReason(OFPortReason.DELETE) .setDesc(portDesc) .build(); resetAndExpectConnectionListener(portStatus); // Send queue reply. expect dispatch OFQueueGetConfigReply queueReply = factory.buildQueueGetConfigReply() .build(); resetAndExpectConnectionListener(queueReply); // Send stat reply. expect dispatch OFFlowStatsReply statReply = factory.buildFlowStatsReply() .build(); resetAndExpectConnectionListener(statReply); // Send role reply. expect dispatch OFNiciraControllerRoleReply roleReply = factory.buildNiciraControllerRoleReply() .setRole(OFNiciraControllerRole.ROLE_MASTER) .build(); resetAndExpectConnectionListener(roleReply); }
/** * Test dispatch of messages while in Complete state */ @Test public void testMessageDispatchComplete() throws Exception { moveToComplete(); newConnection.getValue().setListener(connectionListener); resetChannel(); channel.write(capture(writeCapture)); expectLastCall().andReturn(null).atLeastOnce(); replay(channel); // Send echo request. expect reply OFMessage echoRequest = factory.buildEchoRequest().build(); sendMessageToHandlerWithControllerReset(ImmutableList.<OFMessage>of(echoRequest)); List<OFMessage> msgs = getMessagesFromCapture(); assertEquals(1, msgs.size()); assertEquals(OFType.ECHO_REPLY, msgs.get(0).getType()); // Send barrier reply. expect dispatch OFBarrierReply barrierReply = factory.buildBarrierReply() .build(); resetAndExpectConnectionListener(barrierReply); // Send packet in. expect dispatch OFFlowRemoved flowRemoved = factory.buildFlowRemoved() .build(); resetAndExpectConnectionListener(flowRemoved); // Send get config reply. expect dispatch OFGetConfigReply getConfigReply = factory.buildGetConfigReply() .build(); resetAndExpectConnectionListener(getConfigReply); // Send packet in. expect dispatch OFPacketIn pi = factory.buildPacketIn() .setReason(OFPacketInReason.NO_MATCH) .build(); resetAndExpectConnectionListener(pi); // Send port status. expect dispatch OFPortStatus portStatus = factory.buildPortStatus() .setReason(OFPortReason.DELETE) .setDesc(portDesc) .build(); resetAndExpectConnectionListener(portStatus); // Send queue reply. expect dispatch OFQueueGetConfigReply queueReply = factory.buildQueueGetConfigReply() .build(); resetAndExpectConnectionListener(queueReply); // Send stat reply. expect dispatch OFFlowStatsReply statReply = factory.buildFlowStatsReply() .build(); resetAndExpectConnectionListener(statReply); // Send role reply. expect dispatch OFNiciraControllerRoleReply roleReply = factory.buildNiciraControllerRoleReply() .setRole(OFNiciraControllerRole.ROLE_MASTER) .build(); resetAndExpectConnectionListener(roleReply); }
/** * 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 h The channel handler receiving the message * @param vendorMessage The vendor message to parse. * @return The role in the message if the message is a Nicira role * reply, null otherwise. */ protected OFControllerRole extractNiciraRoleReply(OFMessage vendorMessage) { if (!(vendorMessage instanceof OFNiciraControllerRoleReply)) return null; OFNiciraControllerRoleReply roleReply = (OFNiciraControllerRoleReply) vendorMessage; return NiciraRoleUtils.niciraToOFRole(roleReply); }