OpenFlowControllerImpl implements OpenFlowController { @Override public void setRole(Dpid dpid, RoleState role) { final OpenFlowSwitch sw = getSwitch(dpid); if (sw == null) { log.debug("Switch not connected. Ignoring setRole({}, {})", dpid, role); return; } sw.setRole(role); }  @Activate void activate(ComponentContext context); @Deactivate void deactivate(); @Modified void modified(ComponentContext context); @Override Iterable<OpenFlowSwitch> getSwitches(); @Override Iterable<OpenFlowSwitch> getMasterSwitches(); @Override Iterable<OpenFlowSwitch> getEqualSwitches(); @Override OpenFlowSwitch getSwitch(Dpid dpid); @Override OpenFlowSwitch getMasterSwitch(Dpid dpid); @Override OpenFlowSwitch getEqualSwitch(Dpid dpid); @Override void addListener(OpenFlowSwitchListener listener); @Override void removeListener(OpenFlowSwitchListener listener); @Override void addMessageListener(OpenFlowMessageListener listener); @Override void removeMessageListener(OpenFlowMessageListener listener); @Override void addPacketListener(int priority, PacketListener listener); @Override void removePacketListener(PacketListener listener); @Override void addEventListener(OpenFlowEventListener listener); @Override void removeEventListener(OpenFlowEventListener listener); @Override void write(Dpid dpid, OFMessage msg); @Override void processPacket(Dpid dpid, OFMessage msg); @Override void setRole(Dpid dpid, RoleState role); @Override void addStatisticsListener(int priority, OpenFlowStatisticsListener listener); @Override void removeStatisticsListener(OpenFlowStatisticsListener listener); @Override void addAsynchronousListener(int priority, OpenFlowAsynchronousEventListener listener); @Override void removeAsynchronousListener(OpenFlowAsynchronousEventListener listener); public long packetIn; }
@Test public void testRoleSetting() { agent.addConnectedSwitch(dpid2, switch2); assertThat(switch2.getRole(), is(RoleState.MASTER)); controller.setRole(dpid2, RoleState.EQUAL); assertThat(switch2.getRole(), is(RoleState.EQUAL)); controller.setRole(dpid3, RoleState.SLAVE); }