@Test public void networkDumpTest() throws Exception { OFSwitch iofSwitch1 = mock(OFSwitch.class); OFSwitch iofSwitch2 = mock(OFSwitch.class); final DatapathId swAid = DatapathId.of(1); final DatapathId swBid = DatapathId.of(2); Map<DatapathId, IOFSwitch> switches = ImmutableMap.of( swAid, iofSwitch1, swBid, iofSwitch2 ); Map<DatapathId, InetSocketAddress> switchAddresses = ImmutableMap.of( swAid, new InetSocketAddress(Inet4Address.getByName("127.0.1.1"), 32768), swBid, new InetSocketAddress(Inet4Address.getByName("127.0.1.2"), 32768) ); SwitchDescription ofSwitchDescription = new SwitchDescription( switchDescription.getManufacturer(), switchDescription.getHardware(), switchDescription.getSoftware(), switchDescription.getSerialNumber(), switchDescription.getDatapath()); OFFactoryVer13 ofFactory = new OFFactoryVer13(); for (DatapathId swId : switches.keySet()) { IOFSwitch sw = switches.get(swId); expect(sw.getOFFactory()).andStubReturn(ofFactory); expect(sw.isActive()).andReturn(true).anyTimes(); expect(sw.getId()).andReturn(swId).anyTimes(); expect(sw.getSwitchDescription()).andReturn(ofSwitchDescription); expect(sw.getInetAddress()).andReturn(switchAddresses.get(swId)); expect(sw.getControllerRole()).andStubReturn(OFControllerRole.ROLE_EQUAL); OFConnection connect = createMock(OFConnection.class); expect(connect.getRemoteInetAddress()).andReturn(speakerSocketAddress); expect(sw.getConnectionByCategory(eq(LogicalOFMessageCategory.MAIN))).andReturn(connect); } expect(switchManager.getAllSwitchMap(true)).andReturn(switches); expect(switchManager.getPhysicalPorts(eq(iofSwitch1))).andReturn(ImmutableList.of( makePhysicalPortMock(1, true), makePhysicalPortMock(2, true) )); expect(switchManager.getPhysicalPorts(eq(iofSwitch2))).andReturn(ImmutableList.of( makePhysicalPortMock(3, true), makePhysicalPortMock(4, true), makePhysicalPortMock(5, false) )); expect(featureDetector.detectSwitch(iofSwitch1)) .andReturn(ImmutableSet.of(SwitchFeature.METERS)); expect(featureDetector.detectSwitch(iofSwitch2)) .andReturn(ImmutableSet.of(SwitchFeature.METERS, SwitchFeature.BFD)); ArrayList<Message> producedMessages = new ArrayList<>(); producerService.sendMessageAndTrack(eq(KAFKA_ISL_DISCOVERY_TOPIC), anyObject(), anyObject(InfoMessage.class)); expectLastCall().andAnswer(new IAnswer<Object>() { @Override public Object answer() { Message sentMessage = (Message) getCurrentArguments()[2]; sentMessage.setTimestamp(0); producedMessages.add(sentMessage); return null; } }).anyTimes(); replayAll(); String correlationId = "unit-test-correlation-id"; try (CorrelationContextClosable dummy = CorrelationContext.create(correlationId)) { service.dumpAllSwitches(); } verify(producerService); ArrayList<Message> expectedMessages = new ArrayList<>(); expectedMessages.add(new InfoMessage( new NetworkDumpSwitchData(new SpeakerSwitchView( new SwitchId(swAid.getLong()), new InetSocketAddress(Inet4Address.getByName("127.0.1.1"), 32768), new InetSocketAddress(Inet4Address.getByName("127.0.1.254"), 6653), "OF_13", switchDescription, ImmutableSet.of(SwitchFeature.METERS), ImmutableList.of( new SpeakerSwitchPortView(1, SpeakerSwitchPortView.State.UP), new SpeakerSwitchPortView(2, SpeakerSwitchPortView.State.UP))), true), 0, correlationId)); expectedMessages.add(new InfoMessage( new NetworkDumpSwitchData(new SpeakerSwitchView( new SwitchId(swBid.getLong()), new InetSocketAddress(Inet4Address.getByName("127.0.1.2"), 32768), new InetSocketAddress(Inet4Address.getByName("127.0.1.254"), 6653), "OF_13", switchDescription, ImmutableSet.of(SwitchFeature.METERS, SwitchFeature.BFD), ImmutableList.of( new SpeakerSwitchPortView(3, SpeakerSwitchPortView.State.UP), new SpeakerSwitchPortView(4, SpeakerSwitchPortView.State.UP), new SpeakerSwitchPortView(5, SpeakerSwitchPortView.State.DOWN))), true), 0, correlationId)); assertEquals(expectedMessages, producedMessages); }
public void dumpAllSwitches() { discoveryLock.writeLock().lock(); try { dumpAllSwitchesAction(); } finally { discoveryLock.writeLock().unlock(); } }
SwitchTrackingService implements IOFSwitchListener, IService { public void dumpAllSwitches() { discoveryLock.writeLock().lock(); try { dumpAllSwitchesAction(); } finally { discoveryLock.writeLock().unlock(); } } }
SwitchTrackingService implements IOFSwitchListener, IService { public void dumpAllSwitches() { discoveryLock.writeLock().lock(); try { dumpAllSwitchesAction(); } finally { discoveryLock.writeLock().unlock(); } }  }
SwitchTrackingService implements IOFSwitchListener, IService { public void dumpAllSwitches() { discoveryLock.writeLock().lock(); try { dumpAllSwitchesAction(); } finally { discoveryLock.writeLock().unlock(); } }  void dumpAllSwitches(); void completeSwitchActivation(DatapathId dpId); @Override @NewCorrelationContextRequired void switchAdded(final DatapathId switchId); @Override @NewCorrelationContextRequired void switchRemoved(final DatapathId switchId); @Override @NewCorrelationContextRequired void switchActivated(final DatapathId switchId); @Override @NewCorrelationContextRequired void switchDeactivated(final DatapathId switchId); @Override @NewCorrelationContextRequired void switchChanged(final DatapathId switchId); @Override @NewCorrelationContextRequired void switchPortChanged(final DatapathId switchId, final OFPortDesc portDesc, final PortChangeType type); @Override void setup(FloodlightModuleContext context); }
SwitchTrackingService implements IOFSwitchListener, IService { public void dumpAllSwitches() { discoveryLock.writeLock().lock(); try { dumpAllSwitchesAction(); } finally { discoveryLock.writeLock().unlock(); } }  void dumpAllSwitches(); void completeSwitchActivation(DatapathId dpId); @Override @NewCorrelationContextRequired void switchAdded(final DatapathId switchId); @Override @NewCorrelationContextRequired void switchRemoved(final DatapathId switchId); @Override @NewCorrelationContextRequired void switchActivated(final DatapathId switchId); @Override @NewCorrelationContextRequired void switchDeactivated(final DatapathId switchId); @Override @NewCorrelationContextRequired void switchChanged(final DatapathId switchId); @Override @NewCorrelationContextRequired void switchPortChanged(final DatapathId switchId, final OFPortDesc portDesc, final PortChangeType type); @Override void setup(FloodlightModuleContext context);  }