Java 类net.floodlightcontroller.core.HARole 实例源码

项目:fresco_floodlight    文件:TopologyManager.java   
@Override
public void run() {
    try {
        if (ldUpdates.peek() != null) {
            updateTopology();
        }
        handleMiscellaneousPeriodicEvents();
    }
    catch (Exception e) {
        log.error("Error in topology instance task thread", e);
    } finally {
        if (floodlightProviderService.getRole() != HARole.STANDBY) {
            newInstanceTask.reschedule(TOPOLOGY_COMPUTE_INTERVAL_MS, TimeUnit.MILLISECONDS);
        }
    }
}
项目:fresco_floodlight    文件:TopologyManager.java   
@Override
public void startUp(FloodlightModuleContext context) {
    clearCurrentTopology();
    // Initialize role to floodlight provider role.
    this.role = floodlightProviderService.getRole();

    ScheduledExecutorService ses = threadPoolService.getScheduledExecutor();
    newInstanceTask = new SingletonTask(ses, new UpdateTopologyWorker());

    if (role != HARole.STANDBY) {
        newInstanceTask.reschedule(TOPOLOGY_COMPUTE_INTERVAL_MS, TimeUnit.MILLISECONDS);
    }

    linkDiscoveryService.addListener(this);
    floodlightProviderService.addOFMessageListener(OFType.PACKET_IN, this);
    floodlightProviderService.addHAListener(this.haListener);
    addRestletRoutable();
}
项目:fresco_floodlight    文件:RoleManager.java   
/**
 * @param role initial role
 * @param roleChangeDescription initial value of the change description
 * @throws NullPointerException if role or roleChangeDescription is null
 */
public RoleManager(@Nonnull Controller controller,
        @Nonnull IShutdownService shutdownService,
        @Nonnull HARole role,
        @Nonnull String roleChangeDescription) {
    Preconditions.checkNotNull(controller, "controller must not be null");
    Preconditions.checkNotNull(role, "role must not be null");
    Preconditions.checkNotNull(roleChangeDescription, "roleChangeDescription must not be null");
    Preconditions.checkNotNull(shutdownService, "shutdownService must not be null");

    this.currentRoleInfo = new RoleInfo(role,
                                   roleChangeDescription,
                                   new Date());
    this.controller = controller;
    this.shutdownService = shutdownService;
    this.counters = new RoleManagerCounters(controller.getDebugCounter());
}
项目:fresco_floodlight    文件:OFSwitchManager.java   
/**
 * Called when we receive a store notification about a new or updated
 * switch.
 * @param sw
 */
private synchronized void switchAddedToStore(IOFSwitch sw) {
    if (floodlightProvider.getRole() != HARole.STANDBY) {
        return; // only read from store if slave
    }
    DatapathId dpid = sw.getId();

    IOFSwitch oldSw = syncedSwitches.put(dpid, sw);
    if (oldSw == null)  {
        addUpdateToQueue(new SwitchUpdate(dpid, SwitchUpdateType.ADDED));
    } else {
        // The switch already exists in storage, see if anything
        // has changed
        sendNotificationsIfSwitchDiffers(oldSw, sw);
    }
}
项目:fresco_floodlight    文件:OFSwitchManagerTest.java   
/**
 * Test switchActivated for a new switch while in slave: disconnect the switch
 */
@Test
public void testNewSwitchActivatedWhileSlave() throws Exception {
    doSetUp(HARole.STANDBY);
    IOFSwitchBackend sw = createMock(IOFSwitchBackend.class);

    IOFSwitchListener listener = createMock(IOFSwitchListener.class);
    switchManager.addOFSwitchListener(listener);

    expect(sw.getId()).andReturn(DATAPATH_ID_0).anyTimes();
    expect(sw.getStatus()).andReturn(SwitchStatus.MASTER).anyTimes();
    sw.disconnect();
    expectLastCall().once();
    expect(sw.getOFFactory()).andReturn(factory).once();
    replay(sw, listener); // nothing recorded
    switchManager.switchAdded(sw);
    switchManager.switchStatusChanged(sw, SwitchStatus.HANDSHAKE, SwitchStatus.MASTER);
    verify(sw);
    controller.processUpdateQueueForTesting();
    verify(listener);
}
项目:fresco_floodlight    文件:ControllerTest.java   
/**
 * 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);
}
项目:fresco_floodlight    文件:ControllerTest.java   
/** Test other setRole cases: re-setting role to the current role,
 * setting role to equal, etc.
 */
@Test
public void testSetRoleOthercases() throws Exception {
    doSetUp(HARole.STANDBY);

    // Create and add the HA listener
    IHAListener listener = createMock(IHAListener.class);
    expect(listener.getName()).andReturn("foo").anyTimes();
    setupListenerOrdering(listener);
    replay(listener);
    controller.addHAListener(listener);

    // Set role to slave again. Nothing should happen
    controller.setRole(HARole.STANDBY, "FooBar");
    controller.processUpdateQueueForTesting();
    verify(listener);

    reset(listener);
    expect(listener.getName()).andReturn("foo").anyTimes();
    listener.transitionToActive();
    expectLastCall().once();
    replay(listener);
}
项目:fresco_floodlight    文件:RoleManagerTest.java   
private void doSetUp(HARole role) {
    controller = createMock(Controller.class);

    // Mock controller behavior
    reset(controller);
    IDebugCounterService counterService = new MockDebugCounterService();
    expect(controller.getDebugCounter()).andReturn(counterService).anyTimes();
    replay(controller);


    IShutdownService shutdownService = createMock(IShutdownService.class);
    roleManager = new RoleManager(controller, shutdownService , role, "test");

    // Make sure the desired role is set
    assertTrue(roleManager.getRole().equals(role));
}
项目:fresco_floodlight    文件:OFSwitchHandlerTestBase.java   
/**
 * Test re-assert MASTER
 *
 */
@Test
public void testReassertMaster() throws Exception {
    testInitialMoveToMasterWithRole();

    OFMessage err = getBadRequestErrorMessage(OFBadRequestCode.EPERM, 42);

    reset(roleManager);
    roleManager.reassertRole(switchHandler, HARole.ACTIVE);
    expectLastCall().once();
    replay(roleManager);

    reset(switchManager);
    switchManager.handleMessage(sw, err, null);
    expectLastCall().once();
    replay(switchManager);

    switchHandler.processOFMessage(err);

    verify(sw);
}
项目:iTAP-controller    文件:TopologyManager.java   
@Override
public void startUp(FloodlightModuleContext context) {
    clearCurrentTopology();
    // Initialize role to floodlight provider role.
    this.role = floodlightProviderService.getRole();

    ScheduledExecutorService ses = threadPoolService.getScheduledExecutor();
    newInstanceTask = new SingletonTask(ses, new UpdateTopologyWorker());

    if (role != HARole.STANDBY)
        newInstanceTask.reschedule(TOPOLOGY_COMPUTE_INTERVAL_MS,
                TimeUnit.MILLISECONDS);

    linkDiscoveryService.addListener(this);
    floodlightProviderService.addOFMessageListener(OFType.PACKET_IN, this);
    floodlightProviderService.addHAListener(this.haListener);
    addRestletRoutable();
}
项目:iTAP-controller    文件:RoleManager.java   
/**
 * @param role initial role
 * @param roleChangeDescription initial value of the change description
 * @throws NullPointerException if role or roleChangeDescription is null
 */
public RoleManager(@Nonnull Controller controller,
        @Nonnull IShutdownService shutdownService,
        @Nonnull HARole role,
        @Nonnull String roleChangeDescription) {
    Preconditions.checkNotNull(controller, "controller must not be null");
    Preconditions.checkNotNull(role, "role must not be null");
    Preconditions.checkNotNull(roleChangeDescription, "roleChangeDescription must not be null");
    Preconditions.checkNotNull(shutdownService, "shutdownService must not be null");

    this.currentRoleInfo = new RoleInfo(role,
                                   roleChangeDescription,
                                   new Date());
    this.controller = controller;
    this.shutdownService = shutdownService;
    this.counters = new RoleManagerCounters(controller.getDebugCounter());
}
项目:iTAP-controller    文件:Controller.java   
@LogMessageDocs({
    @LogMessageDoc(message="Controller role set to {role}",
            explanation="Setting the initial HA role to "),
    @LogMessageDoc(level="ERROR",
            message="Invalid current role value: {role}",
            explanation="An invalid HA role value was read from the " +
                        "properties file",
            recommendation=LogMessageDoc.CHECK_CONTROLLER)
})
protected HARole getInitialRole(Map<String, String> configParams) {
    HARole role = HARole.STANDBY;
    String roleString = configParams.get("role");
    if (roleString != null) {
        try {
            role = HARole.valueOfBackwardsCompatible(roleString);
        }
        catch (IllegalArgumentException exc) {
            log.error("Invalid current role value: {}", roleString);
        }
    }

    log.info("Controller role set to {}", role);
    return role;
}
项目:iTAP-controller    文件:Controller.java   
/**
 * Initialize internal data structures
 */
public void init(Map<String, String> configParams) throws FloodlightModuleException {

    this.moduleLoaderState = ModuleLoaderState.INIT;

    // These data structures are initialized here because other
    // module's startUp() might be called before ours        
    this.messageListeners = new ConcurrentHashMap<OFType, ListenerDispatcher<OFType, IOFMessageListener>>();
    this.haListeners = new ListenerDispatcher<HAListenerTypeMarker, IHAListener>();
    this.controllerNodeIPsCache = new HashMap<String, String>();
    this.updates = new LinkedBlockingQueue<IUpdate>();
    this.providerMap = new HashMap<String, List<IInfoProvider>>();

    setConfigParams(configParams);

    HARole initialRole = getInitialRole(configParams);
    this.notifiedRole = initialRole;
    this.shutdownService = new ShutdownServiceImpl();

    this.roleManager = new RoleManager(this, this.shutdownService,
                                       this.notifiedRole,
                                       INITIAL_ROLE_CHANGE_DESCRIPTION);
    this.timer = new HashedWheelTimer();

    // Switch Service Startup
    this.switchService.registerLogicalOFMessageCategory(LogicalOFMessageCategory.MAIN);
    this.switchService.addOFSwitchListener(new NotificationSwitchListener());

    this.counters = new ControllerCounters(debugCounterService);
 }
项目:iTAP-controller    文件:OFSwitchManager.java   
/**
 * Called when we receive a store notification about a new or updated
 * switch.
 * @param sw
 */
private synchronized void switchAddedToStore(IOFSwitch sw) {
    if (floodlightProvider.getRole() != HARole.STANDBY) {
        return; // only read from store if slave
    }
    DatapathId dpid = sw.getId();

    IOFSwitch oldSw = syncedSwitches.put(dpid, sw);
    if (oldSw == null)  {
        addUpdateToQueue(new SwitchUpdate(dpid, SwitchUpdateType.ADDED));
    } else {
        // The switch already exists in storage, see if anything
        // has changed
        sendNotificationsIfSwitchDiffers(oldSw, sw);
    }
}
项目:iTAP-controller    文件:OFSwitchManagerTest.java   
/**
 * Test switchActivated for a new switch while in slave: disconnect the switch
 */
@Test
public void testNewSwitchActivatedWhileSlave() throws Exception {
    doSetUp(HARole.STANDBY);
    IOFSwitchBackend sw = createMock(IOFSwitchBackend.class);

    IOFSwitchListener listener = createMock(IOFSwitchListener.class);
    switchManager.addOFSwitchListener(listener);

    expect(sw.getId()).andReturn(DATAPATH_ID_0).anyTimes();
    expect(sw.getStatus()).andReturn(SwitchStatus.MASTER).anyTimes();
    sw.disconnect();
    expectLastCall().once();
    replay(sw, listener); // nothing recorded
    switchManager.switchAdded(sw);
    switchManager.switchStatusChanged(sw, SwitchStatus.HANDSHAKE, SwitchStatus.MASTER);
    verify(sw);
    controller.processUpdateQueueForTesting();
    verify(listener);
}
项目:iTAP-controller    文件:ControllerTest.java   
/**
 * 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);
}
项目:iTAP-controller    文件:ControllerTest.java   
/** Test other setRole cases: re-setting role to the current role,
 * setting role to equal, etc.
 */
@Test
public void testSetRoleOthercases() throws Exception {
    doSetUp(HARole.STANDBY);

    // Create and add the HA listener
    IHAListener listener = createMock(IHAListener.class);
    expect(listener.getName()).andReturn("foo").anyTimes();
    setupListenerOrdering(listener);
    replay(listener);
    controller.addHAListener(listener);

    // Set role to slave again. Nothing should happen
    controller.setRole(HARole.STANDBY, "FooBar");
    controller.processUpdateQueueForTesting();
    verify(listener);

    reset(listener);
    expect(listener.getName()).andReturn("foo").anyTimes();
    listener.transitionToActive();
    expectLastCall().once();
    replay(listener);
}
项目:iTAP-controller    文件:RoleManagerTest.java   
private void doSetUp(HARole role) {
    controller = createMock(Controller.class);

    // Mock controller behavior
    reset(controller);
    IDebugCounterService counterService = new MockDebugCounterService();
    expect(controller.getDebugCounter()).andReturn(counterService).anyTimes();
    replay(controller);


    IShutdownService shutdownService = createMock(IShutdownService.class);
    roleManager = new RoleManager(controller, shutdownService , role, "test");

    // Make sure the desired role is set
    assertTrue(roleManager.getRole().equals(role));
}
项目:iTAP-controller    文件:OFSwitchHandlerTestBase.java   
/**
 * Test re-assert MASTER
 *
 */
@Test
public void testReassertMaster() throws Exception {
    testInitialMoveToMasterWithRole();

    OFMessage err = getBadRequestErrorMessage(OFBadRequestCode.EPERM, 42);

    reset(roleManager);
    roleManager.reassertRole(switchHandler, HARole.ACTIVE);
    expectLastCall().once();
    replay(roleManager);

    reset(switchManager);
    switchManager.handleMessage(sw, err, null);
    expectLastCall().once();
    replay(switchManager);

    switchHandler.processOFMessage(err);

    verify(sw);
}
项目:SDN-Multicast    文件:TopologyManager.java   
@Override
public void startUp(FloodlightModuleContext context) {
    clearCurrentTopology();
    // Initialize role to floodlight provider role.
    this.role = floodlightProviderService.getRole();

    ScheduledExecutorService ses = threadPoolService.getScheduledExecutor();
    newInstanceTask = new SingletonTask(ses, new UpdateTopologyWorker());

    if (role != HARole.STANDBY) {
        newInstanceTask.reschedule(TOPOLOGY_COMPUTE_INTERVAL_MS, TimeUnit.MILLISECONDS);
    }

    linkDiscoveryService.addListener(this);
    floodlightProviderService.addOFMessageListener(OFType.PACKET_IN, this);
    floodlightProviderService.addHAListener(this.haListener);
    addRestletRoutable();
}
项目:ACAMPController    文件:ControllerTest.java   
/**
 * 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);
}
项目:SDN-Multicast    文件:RoleManager.java   
/**
 * @param role initial role
 * @param roleChangeDescription initial value of the change description
 * @throws NullPointerException if role or roleChangeDescription is null
 */
public RoleManager(@Nonnull Controller controller,
        @Nonnull IShutdownService shutdownService,
        @Nonnull HARole role,
        @Nonnull String roleChangeDescription) {
    Preconditions.checkNotNull(controller, "controller must not be null");
    Preconditions.checkNotNull(role, "role must not be null");
    Preconditions.checkNotNull(roleChangeDescription, "roleChangeDescription must not be null");
    Preconditions.checkNotNull(shutdownService, "shutdownService must not be null");

    this.currentRoleInfo = new RoleInfo(role,
                                   roleChangeDescription,
                                   new Date());
    this.controller = controller;
    this.shutdownService = shutdownService;
    this.counters = new RoleManagerCounters(controller.getDebugCounter());
}
项目:floodlight1.2-delay    文件:OFSwitchHandlerTestBase.java   
/**
 * Test re-assert MASTER
 *
 */
@Test
public void testReassertMaster() throws Exception {
    testInitialMoveToMasterWithRole();

    OFMessage err = getBadRequestErrorMessage(OFBadRequestCode.EPERM, 42);

    reset(roleManager);
    roleManager.reassertRole(switchHandler, HARole.ACTIVE);
    expectLastCall().once();
    replay(roleManager);

    reset(switchManager);
    switchManager.handleMessage(sw, err, null);
    expectLastCall().once();
    replay(switchManager);

    switchHandler.processOFMessage(err);

    verify(sw);
}
项目:floodlight1.2-delay    文件:OFSwitchManagerTest.java   
/**
 * Test switchActivated for a new switch while in slave: disconnect the switch
 */
@Test
public void testNewSwitchActivatedWhileSlave() throws Exception {
    doSetUp(HARole.STANDBY);
    IOFSwitchBackend sw = createMock(IOFSwitchBackend.class);

    IOFSwitchListener listener = createMock(IOFSwitchListener.class);
    switchManager.addOFSwitchListener(listener);

    expect(sw.getId()).andReturn(DATAPATH_ID_0).anyTimes();
    expect(sw.getStatus()).andReturn(SwitchStatus.MASTER).anyTimes();
    sw.disconnect();
    expectLastCall().once();
    expect(sw.getOFFactory()).andReturn(factory).once();
    replay(sw, listener); // nothing recorded
    switchManager.switchAdded(sw);
    switchManager.switchStatusChanged(sw, SwitchStatus.HANDSHAKE, SwitchStatus.MASTER);
    verify(sw);
    controller.processUpdateQueueForTesting();
    verify(listener);
}
项目:floodlight1.2-delay    文件:RoleManagerTest.java   
private void doSetUp(HARole role) {
    controller = createMock(Controller.class);

    // Mock controller behavior
    reset(controller);
    IDebugCounterService counterService = new MockDebugCounterService();
    expect(controller.getDebugCounter()).andReturn(counterService).anyTimes();
    replay(controller);


    IShutdownService shutdownService = createMock(IShutdownService.class);
    roleManager = new RoleManager(controller, shutdownService , role, "test");

    // Make sure the desired role is set
    assertTrue(roleManager.getRole().equals(role));
}
项目:SDN-Multicast    文件:OFSwitchManager.java   
/**
 * Called when we receive a store notification about a new or updated
 * switch.
 * @param sw
 */
private synchronized void switchAddedToStore(IOFSwitch sw) {
    if (floodlightProvider.getRole() != HARole.STANDBY) {
        return; // only read from store if slave
    }
    DatapathId dpid = sw.getId();

    IOFSwitch oldSw = syncedSwitches.put(dpid, sw);
    if (oldSw == null)  {
        addUpdateToQueue(new SwitchUpdate(dpid, SwitchUpdateType.ADDED));
    } else {
        // The switch already exists in storage, see if anything
        // has changed
        sendNotificationsIfSwitchDiffers(oldSw, sw);
    }
}
项目:floodlight-hardware    文件:TopologyManager.java   
@Override
public void run() {
    try {
        if (ldUpdates.peek() != null) {
            updateTopology();
        }
        handleMiscellaneousPeriodicEvents();
    }
    catch (Exception e) {
        log.error("Error in topology instance task thread", e);
    } finally {
        if (floodlightProviderService.getRole() != HARole.STANDBY) {
            newInstanceTask.reschedule(TOPOLOGY_COMPUTE_INTERVAL_MS, TimeUnit.MILLISECONDS);
        }
    }
}
项目:SDN-Multicast    文件:RoleManagerTest.java   
private void doSetUp(HARole role) {
    controller = createMock(Controller.class);

    // Mock controller behavior
    reset(controller);
    IDebugCounterService counterService = new MockDebugCounterService();
    expect(controller.getDebugCounter()).andReturn(counterService).anyTimes();
    replay(controller);


    IShutdownService shutdownService = createMock(IShutdownService.class);
    roleManager = new RoleManager(controller, shutdownService , role, "test");

    // Make sure the desired role is set
    assertTrue(roleManager.getRole().equals(role));
}
项目:SDN-Multicast    文件:OFSwitchHandlerTestBase.java   
/**
 * Test re-assert MASTER
 *
 */
@Test
public void testReassertMaster() throws Exception {
    testInitialMoveToMasterWithRole();

    OFMessage err = getBadRequestErrorMessage(OFBadRequestCode.EPERM, 42);

    reset(roleManager);
    roleManager.reassertRole(switchHandler, HARole.ACTIVE);
    expectLastCall().once();
    replay(roleManager);

    reset(switchManager);
    switchManager.handleMessage(sw, err, null);
    expectLastCall().once();
    replay(switchManager);

    switchHandler.processOFMessage(err);

    verify(sw);
}
项目:ACAMPController    文件:RoleManager.java   
/**
 * @param role initial role
 * @param roleChangeDescription initial value of the change description
 * @throws NullPointerException if role or roleChangeDescription is null
 */
public RoleManager(@Nonnull Controller controller,
        @Nonnull IShutdownService shutdownService,
        @Nonnull HARole role,
        @Nonnull String roleChangeDescription) {
    Preconditions.checkNotNull(controller, "controller must not be null");
    Preconditions.checkNotNull(role, "role must not be null");
    Preconditions.checkNotNull(roleChangeDescription, "roleChangeDescription must not be null");
    Preconditions.checkNotNull(shutdownService, "shutdownService must not be null");

    this.currentRoleInfo = new RoleInfo(role,
                                   roleChangeDescription,
                                   new Date());
    this.controller = controller;
    this.shutdownService = shutdownService;
    this.counters = new RoleManagerCounters(controller.getDebugCounter());
}
项目:floodlight1.2-delay    文件:TopologyManager.java   
@Override
public void startUp(FloodlightModuleContext context) {
    clearCurrentTopology();
    // Initialize role to floodlight provider role.
    this.role = floodlightProviderService.getRole();

    ScheduledExecutorService ses = threadPoolService.getScheduledExecutor();
    newInstanceTask = new SingletonTask(ses, new UpdateTopologyWorker());

    if (role != HARole.STANDBY) {
        newInstanceTask.reschedule(TOPOLOGY_COMPUTE_INTERVAL_MS, TimeUnit.MILLISECONDS);
    }

    linkDiscoveryService.addListener(this);
    floodlightProviderService.addOFMessageListener(OFType.PACKET_IN, this);
    floodlightProviderService.addHAListener(this.haListener);
    addRestletRoutable();
}
项目:floodlight-hardware    文件:OFSwitchManager.java   
/**
 * Called when we receive a store notification about a new or updated
 * switch.
 * @param sw
 */
private synchronized void switchAddedToStore(IOFSwitch sw) {
    if (floodlightProvider.getRole() != HARole.STANDBY) {
        return; // only read from store if slave
    }
    DatapathId dpid = sw.getId();

    IOFSwitch oldSw = syncedSwitches.put(dpid, sw);
    if (oldSw == null)  {
        addUpdateToQueue(new SwitchUpdate(dpid, SwitchUpdateType.ADDED));
    } else {
        // The switch already exists in storage, see if anything
        // has changed
        sendNotificationsIfSwitchDiffers(oldSw, sw);
    }
}
项目:floodlight-hardware    文件:ControllerTest.java   
/** Test other setRole cases: re-setting role to the current role,
 * setting role to equal, etc.
 */
@Test
public void testSetRoleOthercases() throws Exception {
    doSetUp(HARole.STANDBY);

    // Create and add the HA listener
    IHAListener listener = createMock(IHAListener.class);
    expect(listener.getName()).andReturn("foo").anyTimes();
    setupListenerOrdering(listener);
    replay(listener);
    controller.addHAListener(listener);

    // Set role to slave again. Nothing should happen
    controller.setRole(HARole.STANDBY, "FooBar");
    controller.processUpdateQueueForTesting();
    verify(listener);

    reset(listener);
    expect(listener.getName()).andReturn("foo").anyTimes();
    listener.transitionToActive();
    expectLastCall().once();
    replay(listener);
}
项目:floodlight1.2-delay    文件:RoleManager.java   
/**
 * @param role initial role
 * @param roleChangeDescription initial value of the change description
 * @throws NullPointerException if role or roleChangeDescription is null
 */
public RoleManager(@Nonnull Controller controller,
        @Nonnull IShutdownService shutdownService,
        @Nonnull HARole role,
        @Nonnull String roleChangeDescription) {
    Preconditions.checkNotNull(controller, "controller must not be null");
    Preconditions.checkNotNull(role, "role must not be null");
    Preconditions.checkNotNull(roleChangeDescription, "roleChangeDescription must not be null");
    Preconditions.checkNotNull(shutdownService, "shutdownService must not be null");

    this.currentRoleInfo = new RoleInfo(role,
                                   roleChangeDescription,
                                   new Date());
    this.controller = controller;
    this.shutdownService = shutdownService;
    this.counters = new RoleManagerCounters(controller.getDebugCounter());
}
项目:arscheduler    文件:OFSwitchManager.java   
/**
 * Called when we receive a store notification about a new or updated
 * switch.
 * @param sw
 */
private synchronized void switchAddedToStore(IOFSwitch sw) {
    if (floodlightProvider.getRole() != HARole.STANDBY) {
        return; // only read from store if slave
    }
    DatapathId dpid = sw.getId();

    IOFSwitch oldSw = syncedSwitches.put(dpid, sw);
    if (oldSw == null)  {
        addUpdateToQueue(new SwitchUpdate(dpid, SwitchUpdateType.ADDED));
    } else {
        // The switch already exists in storage, see if anything
        // has changed
        sendNotificationsIfSwitchDiffers(oldSw, sw);
    }
}
项目:arscheduler    文件:OFSwitchManagerTest.java   
/**
 * Test switchActivated for a new switch while in slave: disconnect the switch
 */
@Test
public void testNewSwitchActivatedWhileSlave() throws Exception {
    doSetUp(HARole.STANDBY);
    IOFSwitchBackend sw = createMock(IOFSwitchBackend.class);

    IOFSwitchListener listener = createMock(IOFSwitchListener.class);
    switchManager.addOFSwitchListener(listener);

    expect(sw.getId()).andReturn(DATAPATH_ID_0).anyTimes();
    expect(sw.getStatus()).andReturn(SwitchStatus.MASTER).anyTimes();
    sw.disconnect();
    expectLastCall().once();
    expect(sw.getOFFactory()).andReturn(factory).once();
    replay(sw, listener); // nothing recorded
    switchManager.switchAdded(sw);
    switchManager.switchStatusChanged(sw, SwitchStatus.HANDSHAKE, SwitchStatus.MASTER);
    verify(sw);
    controller.processUpdateQueueForTesting();
    verify(listener);
}
项目:arscheduler    文件:ControllerTest.java   
/**
 * 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);
}
项目:arscheduler    文件:ControllerTest.java   
/** Test other setRole cases: re-setting role to the current role,
 * setting role to equal, etc.
 */
@Test
public void testSetRoleOthercases() throws Exception {
    doSetUp(HARole.STANDBY);

    // Create and add the HA listener
    IHAListener listener = createMock(IHAListener.class);
    expect(listener.getName()).andReturn("foo").anyTimes();
    setupListenerOrdering(listener);
    replay(listener);
    controller.addHAListener(listener);

    // Set role to slave again. Nothing should happen
    controller.setRole(HARole.STANDBY, "FooBar");
    controller.processUpdateQueueForTesting();
    verify(listener);

    reset(listener);
    expect(listener.getName()).andReturn("foo").anyTimes();
    listener.transitionToActive();
    expectLastCall().once();
    replay(listener);
}
项目:floodlight-hardware    文件:TopologyManager.java   
@Override
public void startUp(FloodlightModuleContext context) {
    clearCurrentTopology();
    // Initialize role to floodlight provider role.
    this.role = floodlightProviderService.getRole();

    ScheduledExecutorService ses = threadPoolService.getScheduledExecutor();
    newInstanceTask = new SingletonTask(ses, new UpdateTopologyWorker());

    if (role != HARole.STANDBY) {
        newInstanceTask.reschedule(TOPOLOGY_COMPUTE_INTERVAL_MS, TimeUnit.MILLISECONDS);
    }

    linkDiscoveryService.addListener(this);
    floodlightProviderService.addOFMessageListener(OFType.PACKET_IN, this);
    floodlightProviderService.addHAListener(this.haListener);
    addRestletRoutable();
}
项目:open-kilda    文件:MockFloodlightProvider.java   
@Override
public HARole getRole() {
    /* DISABLE THIS CHECK FOR NOW. OTHER UNIT TESTS NEED TO BE UPDATED
     * FIRST
    if (this.role == null)
        throw new IllegalStateException("You need to call setRole on "
                   + "MockFloodlightProvider before calling startUp on "
                   + "other modules");
    */
    return this.role;
}