/** * Send NX role request message to the switch requesting the specified * role. * * @param role role to request */ private int sendNxRoleRequest(RoleState role) throws IOException { // Convert the role enum to the appropriate role to send OFNiciraControllerRole roleToSend = OFNiciraControllerRole.ROLE_OTHER; switch (role) { case MASTER: roleToSend = OFNiciraControllerRole.ROLE_MASTER; break; case SLAVE: case EQUAL: default: // ensuring that the only two roles sent to 1.0 switches with // Nicira role support, are MASTER and SLAVE roleToSend = OFNiciraControllerRole.ROLE_OTHER; log.debug("Sending Nx Role.SLAVE to switch {}.", sw); } int xid = sw.getNextTransactionId(); OFExperimenter roleRequest = OFFactories.getFactory(OFVersion.OF_10) .buildNiciraControllerRoleRequest() .setXid(xid) .setRole(roleToSend) .build(); sw.sendRoleRequest(roleRequest); return xid; }
/** * Send NX role request message to the switch requesting the specified * role. * * @param role role to request */ private int sendNxRoleRequest(RoleState role) throws IOException { // Convert the role enum to the appropriate role to send OFNiciraControllerRole roleToSend = OFNiciraControllerRole.ROLE_OTHER; switch (role) { case MASTER: roleToSend = OFNiciraControllerRole.ROLE_MASTER; break; case SLAVE: case EQUAL: default: // ensuring that the only two roles sent to 1.0 switches with // Nicira role support, are MASTER and SLAVE roleToSend = OFNiciraControllerRole.ROLE_OTHER; log.warn("Sending Nx Role.SLAVE to switch {}.", sw); } int xid = sw.getNextTransactionId(); OFExperimenter roleRequest = OFFactories.getFactory(OFVersion.OF_10) .buildNiciraControllerRoleRequest() .setXid(xid) .setRole(roleToSend) .build(); sw.write(Collections.<OFMessage>singletonList(roleRequest)); return xid; }
/** * Send NX role request message to the switch requesting the specified * role. * * @param sw switch to send the role request message to * @param role role to request */ private int sendNxRoleRequest(Role role) throws IOException { // Convert the role enum to the appropriate role to send OFNiciraControllerRole roleToSend = OFNiciraControllerRole.ROLE_OTHER; switch (role) { case MASTER: roleToSend = OFNiciraControllerRole.ROLE_MASTER; break; case SLAVE: case EQUAL: default: // ensuring that the only two roles sent to 1.0 switches with // Nicira role support, are MASTER and SLAVE roleToSend = OFNiciraControllerRole.ROLE_SLAVE; log.warn("Sending Nx Role.SLAVE to switch {}.", sw); } int xid = sw.getNextTransactionId(); OFExperimenter roleRequest = factory10 .buildNiciraControllerRoleRequest() .setXid(xid) .setRole(roleToSend) .build(); sw.write(Collections.<OFMessage>singletonList(roleRequest), new FloodlightContext()); return xid; }
private OFMessage getRoleReply(long xid, Role role) { OFNiciraControllerRole nr = null; switch(role) { case MASTER: nr = OFNiciraControllerRole.ROLE_MASTER; break; case EQUAL: nr = OFNiciraControllerRole.ROLE_SLAVE; break; case SLAVE: nr = OFNiciraControllerRole.ROLE_SLAVE; break; default: //handled below } OFMessage m = factory10.buildNiciraControllerRoleReply() .setRole(nr) .setXid(xid) .build(); return m; }
/** * 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 OFNiciraControllerRole ofRoleToNiciraRole(OFControllerRole role) { switch(role) { case ROLE_EQUAL: return OFNiciraControllerRole.ROLE_OTHER; case ROLE_MASTER: return OFNiciraControllerRole.ROLE_MASTER; case ROLE_SLAVE: return OFNiciraControllerRole.ROLE_SLAVE; default: throw new IllegalArgumentException("Unknown role: " + role); } }
public static OFNiciraControllerRole readFrom(ChannelBuffer bb) throws OFParseError { try { return ofWireValue(bb.readInt()); } catch (IllegalArgumentException e) { throw new OFParseError(e); } }
public static OFNiciraControllerRole ofWireValue(int val) { switch(val) { case ROLE_OTHER_VAL: return OFNiciraControllerRole.ROLE_OTHER; case ROLE_MASTER_VAL: return OFNiciraControllerRole.ROLE_MASTER; case ROLE_SLAVE_VAL: return OFNiciraControllerRole.ROLE_SLAVE; default: throw new IllegalArgumentException("Illegal wire value for type OFNiciraControllerRole in version 1.0: " + val); } }
public static int toWireValue(OFNiciraControllerRole e) { switch(e) { case ROLE_OTHER: return ROLE_OTHER_VAL; case ROLE_MASTER: return ROLE_MASTER_VAL; case ROLE_SLAVE: return ROLE_SLAVE_VAL; default: throw new IllegalArgumentException("Illegal enum value for type OFNiciraControllerRole in version 1.0: " + e); } }
/** * 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; }
public static OFNiciraControllerRole readFrom(ByteBuf bb) throws OFParseError { try { return ofWireValue(bb.readInt()); } catch (IllegalArgumentException e) { throw new OFParseError(e); } }
/** * 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); }
public static void writeTo(ChannelBuffer bb, OFNiciraControllerRole e) { bb.writeInt(toWireValue(e)); }
public static void putTo(OFNiciraControllerRole e, PrimitiveSink sink) { sink.putInt(toWireValue(e)); }
public static void writeTo(ByteBuf bb, OFNiciraControllerRole e) { bb.writeInt(toWireValue(e)); }