Search in sources :

Example 6 with RegionMappingSet

use of org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingSet in project open-kilda by telstra.

the class SwitchMonitorServiceTest method testDisconnectTheOnlyConnection.

@Test
public void testDisconnectTheOnlyConnection() {
    SwitchMonitorService subject = makeSubject();
    SwitchInfoData swActivate = makeSwitchActivateNotification(SWITCH_ALPHA, 1);
    subject.handleStatusUpdateNotification(swActivate, REGION_ALPHA);
    verify(carrier).regionUpdateNotification(eq(new RegionMappingSet(swActivate.getSwitchId(), REGION_ALPHA, true)));
    verify(carrier).sendSwitchConnectNotification(eq(swActivate.getSwitchId()), eq(swActivate.getSwitchView()), any(SwitchAvailabilityData.class));
    verifyNoMoreInteractions(carrier);
    reset(carrier);
    SwitchInfoData swDeactivate = new SwitchInfoData(swActivate.getSwitchId(), SwitchChangeType.DEACTIVATED);
    subject.handleStatusUpdateNotification(swDeactivate, REGION_ALPHA);
    verify(carrier).regionUpdateNotification(eq(new RegionMappingRemove(swActivate.getSwitchId(), REGION_ALPHA, true)));
    verify(carrier).sendSwitchDisconnectNotification(eq(swDeactivate.getSwitchId()), eq(SwitchAvailabilityData.builder().build()), eq(false));
    verifyNoMoreInteractions(carrier);
}
Also used : RegionMappingSet(org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingSet) RegionMappingRemove(org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingRemove) SwitchAvailabilityData(org.openkilda.messaging.model.SwitchAvailabilityData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) Test(org.junit.Test)

Example 7 with RegionMappingSet

use of org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingSet in project open-kilda by telstra.

the class SwitchMonitorServiceTest method testTheOnlyRegionLost.

@Test
public void testTheOnlyRegionLost() {
    SwitchMonitorService subject = makeSubject();
    SwitchInfoData swActivate = makeSwitchActivateNotification(SWITCH_ALPHA, 1);
    subject.handleStatusUpdateNotification(swActivate, REGION_ALPHA);
    verify(carrier).regionUpdateNotification(eq(new RegionMappingSet(swActivate.getSwitchId(), REGION_ALPHA, true)));
    verify(carrier).sendSwitchConnectNotification(eq(swActivate.getSwitchId()), eq(swActivate.getSwitchView()), any(SwitchAvailabilityData.class));
    verifyNoMoreInteractions(carrier);
    reset(carrier);
    clock.adjust(Duration.ofSeconds(1));
    subject.handleRegionOfflineNotification(REGION_ALPHA);
    verify(carrier).regionUpdateNotification(eq(new RegionMappingRemove(swActivate.getSwitchId(), REGION_ALPHA, true)));
    verify(carrier).sendSwitchDisconnectNotification(eq(swActivate.getSwitchId()), eq(SwitchAvailabilityData.builder().build()), eq(true));
    verifyNoMoreInteractions(carrier);
}
Also used : RegionMappingSet(org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingSet) RegionMappingRemove(org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingRemove) SwitchAvailabilityData(org.openkilda.messaging.model.SwitchAvailabilityData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) Test(org.junit.Test)

Example 8 with RegionMappingSet

use of org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingSet in project open-kilda by telstra.

the class SwitchMonitorServiceTest method testDisconnectActivePassive.

@Test
public void testDisconnectActivePassive() {
    SwitchMonitorService subject = makeSubject();
    Instant t0 = clock.instant();
    SwitchId targetSw = SWITCH_ALPHA;
    makeConnectInRegions(subject, targetSw, REGION_ALPHA, REGION_BETA);
    clock.adjust(Duration.ofSeconds(1));
    SwitchInfoData swDisconnect = new SwitchInfoData(targetSw, SwitchChangeType.DEACTIVATED);
    // disconnect active region (so it must be swapped)
    subject.handleStatusUpdateNotification(swDisconnect, REGION_ALPHA);
    verify(carrier).regionUpdateNotification(eq(new RegionMappingSet(swDisconnect.getSwitchId(), REGION_BETA, true)));
    SpeakerSwitchView suggestedSpeakerData = makeSwitchActivateNotification(swDisconnect.getSwitchId(), 2).getSwitchView();
    verify(carrier).sendSwitchAvailabilityUpdateNotification(eq(swDisconnect.getSwitchId()), argThat(arg -> matchAvailabilityData(SwitchAvailabilityData.builder().connection(SwitchAvailabilityEntry.builder().regionName(REGION_BETA).connectMode(SwitchConnectMode.READ_WRITE).master(true).connectedAt(t0).switchAddress(suggestedSpeakerData.getSwitchSocketAddress()).speakerAddress(suggestedSpeakerData.getSpeakerSocketAddress()).build()).build(), arg)));
    verifyNoMoreInteractions(carrier);
    reset(carrier);
    // disconnect last (active) region
    subject.handleStatusUpdateNotification(swDisconnect, REGION_BETA);
    verify(carrier).regionUpdateNotification(eq(new RegionMappingRemove(swDisconnect.getSwitchId(), REGION_BETA, true)));
    verify(carrier).sendSwitchDisconnectNotification(eq(swDisconnect.getSwitchId()), eq(SwitchAvailabilityData.builder().build()), eq(false));
    verifyNoMoreInteractions(carrier);
}
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) RegionMappingRemove(org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingRemove) Instant(java.time.Instant) SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) SwitchId(org.openkilda.model.SwitchId) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) Test(org.junit.Test)

Example 9 with RegionMappingSet

use of org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingSet in project open-kilda by telstra.

the class SwitchMonitorServiceTest method makeConnectInRegions.

private void makeConnectInRegions(SwitchMonitorService subject, SwitchId switchId, String... regions) {
    for (int i = 0; i < regions.length; i++) {
        SwitchInfoData activate = makeSwitchActivateNotification(switchId, i + 1);
        subject.handleStatusUpdateNotification(activate, regions[i]);
        if (i == 0) {
            verify(carrier).regionUpdateNotification(eq(new RegionMappingSet(activate.getSwitchId(), regions[i], true)));
            verify(carrier).sendSwitchConnectNotification(eq(activate.getSwitchId()), eq(activate.getSwitchView()), any(SwitchAvailabilityData.class));
        } else {
            verify(carrier).sendSwitchAvailabilityUpdateNotification(eq(switchId), any(SwitchAvailabilityData.class));
        }
        verifyNoMoreInteractions(carrier);
        reset(carrier);
    }
}
Also used : RegionMappingSet(org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingSet) SwitchAvailabilityData(org.openkilda.messaging.model.SwitchAvailabilityData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData)

Example 10 with RegionMappingSet

use of org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingSet 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)

Aggregations

RegionMappingSet (org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingSet)11 Test (org.junit.Test)8 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)7 SwitchAvailabilityData (org.openkilda.messaging.model.SwitchAvailabilityData)7 RegionMappingRemove (org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingRemove)7 Duration (java.time.Duration)4 Instant (java.time.Instant)4 Collections (java.util.Collections)4 Comparator (java.util.Comparator)4 Objects (java.util.Objects)4 Collectors (java.util.stream.Collectors)4 Assert (org.junit.Assert)4 RunWith (org.junit.runner.RunWith)4 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)4 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)4 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)4 Mock (org.mockito.Mock)4 Mockito.reset (org.mockito.Mockito.reset)4 Mockito.times (org.mockito.Mockito.times)4 Mockito.verify (org.mockito.Mockito.verify)4