public void verifyPortChangedUpdateInQueue(IOFSwitch sw) throws Exception { assertEquals(1, controller.updates.size()); IUpdate update = controller.updates.take(); assertEquals(true, update instanceof SwitchUpdate); SwitchUpdate swUpdate = (SwitchUpdate)update; assertEquals(sw, swUpdate.sw); assertEquals(SwitchUpdateType.PORTCHANGED, swUpdate.switchUpdateType); }
private void doTestUpdateQueueWithUpdate(long dpid, SwitchUpdateType type, DummySwitchListener listener) throws InterruptedException { controller.updates.put(controller.new SwitchUpdate(dpid, type)); synchronized (listener) { listener.wait(500); } // Test that the update was seen by the listener 1 time assertEquals(1, listener.getSwitchUpdateCount(type)); }
private void doTestUpdateQueueWithPortUpdate(long dpid, OFPortDesc port, PortChangeType type, DummySwitchListener listener) throws InterruptedException { controller.updates.put(controller.new SwitchUpdate(dpid, SwitchUpdateType.PORTCHANGED, port, type)); synchronized (listener) { listener.wait(500); } // Test that the update was seen by the listener 1 time assertEquals(1, listener.getPortUpdateCount(type)); }
private void doTestNotifyPortChanged(long dpid, OFPortDesc port, PortChangeType changeType) throws InterruptedException { controller.notifyPortChanged(dpid, port, changeType); assertEquals(1, controller.updates.size()); IUpdate update = controller.updates.take(); assertEquals(true, update instanceof SwitchUpdate); SwitchUpdate swUpdate = (SwitchUpdate) update; assertEquals(dpid, swUpdate.getSwId()); assertEquals(SwitchUpdateType.PORTCHANGED, swUpdate.getSwitchUpdateType()); assertEquals(changeType, swUpdate.getPortChangeType()); }
@Override public synchronized void switchActivatedMaster(long swId) { updateCount.add(SwitchUpdateType.ACTIVATED_MASTER); notifyAll(); }
@Override public synchronized void switchActivatedEqual(long swId) { updateCount.add(SwitchUpdateType.ACTIVATED_EQUAL); notifyAll(); }
@Override public synchronized void switchMasterToEqual(long swId) { updateCount.add(SwitchUpdateType.MASTER_TO_EQUAL); notifyAll(); }
@Override public synchronized void switchEqualToMaster(long swId) { updateCount.add(SwitchUpdateType.EQUAL_TO_MASTER); notifyAll(); }
@Override public synchronized void switchDisconnected(long swId) { updateCount.add(SwitchUpdateType.DISCONNECTED); notifyAll(); }
/** * Tests that updates sent into the Controller updates queue are dispatched * to the listeners correctly. * * @throws InterruptedException */ @Test public void testUpdateQueue() throws InterruptedException { // No difference between OpenFlow versions here OFVersion version = OFVersion.OF_10; OFPortDesc port = OFFactories.getFactory(version) .buildPortDesc().build(); long dpid = 1L; DummySwitchListener switchListener = new DummySwitchListener(); IOFSwitch sw = createMockSwitch(dpid, version); replay(sw); ControllerRunThread t = new ControllerRunThread(); t.start(); controller.addOFSwitchListener(switchListener); // Switch updates doTestUpdateQueueWithUpdate(dpid, SwitchUpdateType.ACTIVATED_MASTER, switchListener); doTestUpdateQueueWithUpdate(dpid, SwitchUpdateType.ACTIVATED_EQUAL, switchListener); doTestUpdateQueueWithUpdate(dpid, SwitchUpdateType.EQUAL_TO_MASTER, switchListener); doTestUpdateQueueWithUpdate(dpid, SwitchUpdateType.MASTER_TO_EQUAL, switchListener); doTestUpdateQueueWithUpdate(dpid, SwitchUpdateType.DISCONNECTED, switchListener); // Port updates doTestUpdateQueueWithPortUpdate(dpid, port, PortChangeType.ADD, switchListener); doTestUpdateQueueWithPortUpdate(dpid, port, PortChangeType.OTHER_UPDATE, switchListener); doTestUpdateQueueWithPortUpdate(dpid, port, PortChangeType.DELETE, switchListener); doTestUpdateQueueWithPortUpdate(dpid, port, PortChangeType.UP, switchListener); doTestUpdateQueueWithPortUpdate(dpid, port, PortChangeType.DOWN, switchListener); }
/** * Gets the number of times a switch update event of the specified type * has been received. * * @param type SwitchUpdateType to get the count for * @return number of times the event has been received */ public int getSwitchUpdateCount(SwitchUpdateType type) { return updateCount.count(type); }