Search in sources :

Example 6 with NetworkDumpSwitchData

use of org.openkilda.messaging.info.discovery.NetworkDumpSwitchData in project open-kilda by telstra.

the class SwitchMonitorServiceTest method testSerialUpdate.

@Test
public void testSerialUpdate() {
    SwitchMonitorService subject = makeSubject();
    Instant t0 = clock.instant();
    SwitchInfoData swAlphaActivate = makeSwitchActivateNotification(SWITCH_ALPHA, 1);
    subject.handleStatusUpdateNotification(swAlphaActivate, REGION_ALPHA);
    verify(carrier).regionUpdateNotification(eq(new RegionMappingSet(swAlphaActivate.getSwitchId(), REGION_ALPHA, true)));
    verify(carrier).sendSwitchConnectNotification(eq(swAlphaActivate.getSwitchId()), eq(swAlphaActivate.getSwitchView()), any(SwitchAvailabilityData.class));
    verifyNoMoreInteractions(carrier);
    reset(carrier);
    NetworkDumpSwitchData dump = new NetworkDumpSwitchData(swAlphaActivate.getSwitchView(), NETWORK_DUMP_CORRELATION_ID, true);
    for (int i = 0; i < 5; i++) {
        clock.adjust(Duration.ofSeconds(60));
        subject.handleNetworkDumpResponse(dump, REGION_ALPHA);
        verify(carrier, times(i + 1)).sendOtherNotification(eq(dump.getSwitchId()), eq(dump));
        verifyNoMoreInteractions(carrier);
    }
    reset(carrier);
    // to ensure correct value of connectedAt field for REGION_ALPHA force sending of
    // SwitchAvailabilityUpdateNotification
    Instant t1 = clock.instant();
    SwitchInfoData swBetaActivate = makeSwitchActivateNotification(swAlphaActivate.getSwitchId(), 2);
    subject.handleStatusUpdateNotification(swBetaActivate, REGION_BETA);
    verify(carrier).sendSwitchAvailabilityUpdateNotification(eq(swBetaActivate.getSwitchId()), argThat(arg -> matchAvailabilityData(SwitchAvailabilityData.builder().connection(SwitchAvailabilityEntry.builder().regionName(REGION_ALPHA).connectMode(SwitchConnectMode.READ_WRITE).master(true).connectedAt(t0).switchAddress(swAlphaActivate.getSwitchView().getSwitchSocketAddress()).speakerAddress(swAlphaActivate.getSwitchView().getSpeakerSocketAddress()).build()).connection(SwitchAvailabilityEntry.builder().regionName(REGION_BETA).connectMode(SwitchConnectMode.READ_WRITE).master(false).connectedAt(t1).switchAddress(swBetaActivate.getSwitchView().getSwitchSocketAddress()).speakerAddress(swBetaActivate.getSwitchView().getSpeakerSocketAddress()).build()).build(), arg)));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) RegionMappingRemove(org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingRemove) SwitchAvailabilityData(org.openkilda.messaging.model.SwitchAvailabilityData) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) SwitchChangeType(org.openkilda.messaging.info.event.SwitchChangeType) SwitchConnectMode(org.openkilda.model.SwitchConnectMode) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) SpeakerSwitchDescription(org.openkilda.messaging.model.SpeakerSwitchDescription) Duration(java.time.Duration) SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) RegionMappingSet(org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingSet) SwitchMonitorCarrier(org.openkilda.wfm.topology.floodlightrouter.service.SwitchMonitorCarrier) State(org.openkilda.messaging.model.SpeakerSwitchPortView.State) SwitchAvailabilityEntry(org.openkilda.messaging.model.SwitchAvailabilityEntry) RegionMappingAdd(org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingAdd) SpeakerSwitchPortView(org.openkilda.messaging.model.SpeakerSwitchPortView) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) NetworkDumpSwitchData(org.openkilda.messaging.info.discovery.NetworkDumpSwitchData) IpSocketAddress(org.openkilda.model.IpSocketAddress) ManualClock(org.openkilda.stubs.ManualClock) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Objects(java.util.Objects) SwitchId(org.openkilda.model.SwitchId) Assert(org.junit.Assert) Comparator(java.util.Comparator) Mockito.reset(org.mockito.Mockito.reset) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Collections(java.util.Collections) RegionMappingSet(org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingSet) SwitchAvailabilityData(org.openkilda.messaging.model.SwitchAvailabilityData) Instant(java.time.Instant) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) NetworkDumpSwitchData(org.openkilda.messaging.info.discovery.NetworkDumpSwitchData) Test(org.junit.Test)

Example 7 with NetworkDumpSwitchData

use of org.openkilda.messaging.info.discovery.NetworkDumpSwitchData in project open-kilda by telstra.

the class SwitchTrackingService method dumpAllSwitchesAction.

private void dumpAllSwitchesAction(String dumpId) {
    Collection<IOFSwitch> iofSwitches = switchManager.getAllSwitchMap(true).values();
    for (IOFSwitch sw : iofSwitches) {
        NetworkDumpSwitchData payload = null;
        try {
            payload = new NetworkDumpSwitchData(buildSwitch(sw), dumpId, sw.getControllerRole() != OFControllerRole.ROLE_SLAVE);
            emitDiscoveryEvent(sw.getId(), payload);
        } catch (SwitchOperationException e) {
            log.error("Exclude {} from dump switches response - {}", sw.getId(), e.getMessage(), e);
        }
    }
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) IOFSwitch(net.floodlightcontroller.core.IOFSwitch) NetworkDumpSwitchData(org.openkilda.messaging.info.discovery.NetworkDumpSwitchData)

Aggregations

NetworkDumpSwitchData (org.openkilda.messaging.info.discovery.NetworkDumpSwitchData)7 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)5 Test (org.junit.Test)4 SpeakerSwitchDescription (org.openkilda.messaging.model.SpeakerSwitchDescription)4 SpeakerSwitchPortView (org.openkilda.messaging.model.SpeakerSwitchPortView)4 SpeakerSwitchView (org.openkilda.messaging.model.SpeakerSwitchView)4 IpSocketAddress (org.openkilda.model.IpSocketAddress)4 SwitchId (org.openkilda.model.SwitchId)4 Duration (java.time.Duration)3 Instant (java.time.Instant)3 Collections (java.util.Collections)3 Comparator (java.util.Comparator)3 Objects (java.util.Objects)3 Collectors (java.util.stream.Collectors)3 Assert (org.junit.Assert)3 RunWith (org.junit.runner.RunWith)3 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)3 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)3 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)3 Mock (org.mockito.Mock)3