@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);
    }
@Test
    public void testRoleSetting() {
        agent.addConnectedSwitch(dpid2, switch2);

        // check that state can be changed for a connected switch
        assertThat(switch2.getRole(), is(RoleState.MASTER));
        controller.setRole(dpid2, RoleState.EQUAL);
        assertThat(switch2.getRole(), is(RoleState.EQUAL));

        // check that changing state on an unconnected switch does not crash
        controller.setRole(dpid3, RoleState.SLAVE);
    }