Search in sources :

Example 1 with RegionMappingRemove

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

the class SwitchMonitor method swapActiveReadWriteRegion.

private void swapActiveReadWriteRegion(String currentRegion, boolean isRegionOffline) {
    Iterator<String> iter = readWriteConnects.listRegions().iterator();
    if (iter.hasNext()) {
        String targetRegion = iter.next();
        log.info("Change {} active region for {} from \"{}\" to \"{}\"", SwitchConnectMode.READ_WRITE, switchId, currentRegion, targetRegion);
        SwitchConnect target = readWriteConnects.get(targetRegion);
        if (target == null) {
            // it must never happen, but if it happen better throw something meaningful
            throw new IllegalStateException(String.format("Switch %s availability data for %s corrupted", SwitchConnectMode.READ_WRITE, switchId));
        }
        readWriteConnects.put(targetRegion, target.buildActiveVariant());
        carrier.regionUpdateNotification(new RegionMappingSet(switchId, targetRegion, true));
        carrier.sendSwitchAvailabilityUpdateNotification(switchId, makeDump());
    } else {
        log.info("All {} connection to the switch {} have lost", SwitchConnectMode.READ_WRITE, switchId);
        carrier.regionUpdateNotification(new RegionMappingRemove(switchId, currentRegion, true));
        carrier.sendSwitchDisconnectNotification(switchId, makeDump(), isRegionOffline);
    }
}
Also used : RegionMappingSet(org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingSet) RegionMappingRemove(org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingRemove) SwitchConnect(org.openkilda.wfm.topology.floodlightrouter.model.SwitchConnect)

Example 2 with RegionMappingRemove

use of org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingRemove 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 3 with RegionMappingRemove

use of org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingRemove 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 4 with RegionMappingRemove

use of org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingRemove 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 5 with RegionMappingRemove

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

the class SwitchMonitorServiceTest method testDisconnectPassiveActive.

@Test
public void testDisconnectPassiveActive() {
    SwitchMonitorService subject = makeSubject();
    Instant t0 = clock.instant();
    SwitchId targetSw = SWITCH_ALPHA;
    makeConnectInRegions(subject, targetSw, REGION_ALPHA, REGION_BETA);
    // disconnect beta
    SwitchInfoData swDisconnect = new SwitchInfoData(targetSw, SwitchChangeType.DEACTIVATED);
    subject.handleStatusUpdateNotification(swDisconnect, REGION_BETA);
    SpeakerSwitchView suggestedSpeakerData = makeSwitchActivateNotification(swDisconnect.getSwitchId(), 1).getSwitchView();
    verify(carrier).sendSwitchAvailabilityUpdateNotification(eq(swDisconnect.getSwitchId()), argThat(arg -> matchAvailabilityData(SwitchAvailabilityData.builder().connection(SwitchAvailabilityEntry.builder().regionName(REGION_ALPHA).connectMode(SwitchConnectMode.READ_WRITE).master(true).connectedAt(t0).switchAddress(suggestedSpeakerData.getSwitchSocketAddress()).speakerAddress(suggestedSpeakerData.getSpeakerSocketAddress()).build()).build(), arg)));
    verifyNoMoreInteractions(carrier);
    reset(carrier);
    // disconnect alpha (the only RW region)
    subject.handleStatusUpdateNotification(swDisconnect, REGION_ALPHA);
    verify(carrier).regionUpdateNotification(eq(new RegionMappingRemove(swDisconnect.getSwitchId(), REGION_ALPHA, 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) 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)

Aggregations

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