Search in sources :

Example 1 with RegionMappingSet

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

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

the class SwitchMonitor method acquireReadWriteRegion.

private void acquireReadWriteRegion(SpeakerSwitchView speakerData, String region, SwitchConnect entry) {
    if (entry.isActive()) {
        log.info("Set {} active region for {} to \"{}\"", SwitchConnectMode.READ_WRITE, switchId, region);
        carrier.regionUpdateNotification(new RegionMappingSet(switchId, region, true));
        carrier.sendSwitchConnectNotification(switchId, speakerData, makeDump());
    } else {
        carrier.sendSwitchAvailabilityUpdateNotification(switchId, makeDump());
    }
}
Also used : RegionMappingSet(org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingSet)

Example 3 with RegionMappingSet

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

the class ControllerToSpeakerProxyBoltTest method verifyHappyPath.

@Test
public void verifyHappyPath() {
    injectLifecycleEventUpdate(START_SIGNAL);
    ArgumentCaptor<Values> outputCaptor = ArgumentCaptor.forClass(Values.class);
    verify(outputCollector).emit(anyString(), any(Tuple.class), outputCaptor.capture());
    Values output = outputCaptor.getValue();
    assertEquals(START_SIGNAL, ((LifecycleEvent) output.get(0)).getSignal());
    injectRegionUpdate(new RegionMappingSet(switchAlpha, REGION_ONE, true));
    final CommandMessage request = injectDiscoveryRequest(switchAlpha);
    verify(outputCollector).emit(any(Tuple.class), outputCaptor.capture());
    assertEquals(switchAlpha.toString(), outputCaptor.getValue().get(0));
    output = outputCaptor.getValue();
    // key
    assertEquals(switchAlpha.toString(), output.get(0));
    // value
    assertEquals(request, output.get(1));
    // topic
    assertEquals(TARGET_TOPIC, output.get(2));
    // region
    assertEquals(REGION_ONE, output.get(3));
    verifyNoMoreInteractions(outputCollector);
}
Also used : RegionMappingSet(org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingSet) Values(org.apache.storm.tuple.Values) Tuple(org.apache.storm.tuple.Tuple) CommandMessage(org.openkilda.messaging.command.CommandMessage) Test(org.junit.Test)

Example 4 with RegionMappingSet

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

the class SwitchMonitorServiceTest method testLoseActiveRegion.

@Test
public void testLoseActiveRegion() {
    SwitchMonitorService subject = makeSubject();
    Instant t0 = clock.instant();
    SwitchId targetSw = SWITCH_ALPHA;
    makeConnectInRegions(subject, targetSw, REGION_ALPHA, REGION_BETA);
    clock.adjust(Duration.ofSeconds(1));
    subject.handleRegionOfflineNotification(REGION_ALPHA);
    verify(carrier).regionUpdateNotification(eq(new RegionMappingSet(targetSw, REGION_BETA, true)));
    SpeakerSwitchView suggestedBetaSpeakerData = makeSwitchActivateNotification(targetSw, 2).getSwitchView();
    verify(carrier).sendSwitchAvailabilityUpdateNotification(eq(targetSw), argThat(arg -> matchAvailabilityData(SwitchAvailabilityData.builder().connection(SwitchAvailabilityEntry.builder().regionName(REGION_BETA).connectMode(SwitchConnectMode.READ_WRITE).master(true).connectedAt(t0).switchAddress(suggestedBetaSpeakerData.getSwitchSocketAddress()).speakerAddress(suggestedBetaSpeakerData.getSpeakerSocketAddress()).build()).build(), arg)));
    verifyNoMoreInteractions(carrier);
    reset(carrier);
    clock.adjust(Duration.ofSeconds(1));
    Instant t1 = clock.instant();
    SpeakerSwitchView suggestedAlphaSpeakerData = makeSwitchActivateNotification(targetSw, 1).getSwitchView();
    NetworkDumpSwitchData dumpBeta = new NetworkDumpSwitchData(suggestedAlphaSpeakerData, NETWORK_DUMP_CORRELATION_ID, true);
    subject.handleNetworkDumpResponse(dumpBeta, REGION_ALPHA);
    verify(carrier).sendSwitchAvailabilityUpdateNotification(eq(targetSw), argThat(arg -> matchAvailabilityData(SwitchAvailabilityData.builder().connection(SwitchAvailabilityEntry.builder().regionName(REGION_ALPHA).connectMode(SwitchConnectMode.READ_WRITE).master(false).connectedAt(t1).switchAddress(suggestedAlphaSpeakerData.getSwitchSocketAddress()).speakerAddress(suggestedAlphaSpeakerData.getSpeakerSocketAddress()).build()).connection(SwitchAvailabilityEntry.builder().regionName(REGION_BETA).connectMode(SwitchConnectMode.READ_WRITE).master(true).connectedAt(t0).switchAddress(suggestedBetaSpeakerData.getSwitchSocketAddress()).speakerAddress(suggestedBetaSpeakerData.getSpeakerSocketAddress()).build()).build(), arg)));
    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) Instant(java.time.Instant) SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) SwitchId(org.openkilda.model.SwitchId) NetworkDumpSwitchData(org.openkilda.messaging.info.discovery.NetworkDumpSwitchData) Test(org.junit.Test)

Example 5 with RegionMappingSet

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

the class SwitchMonitorServiceTest method regularTwoSpeakersSwitchConnectSequence.

@Test
public void regularTwoSpeakersSwitchConnectSequence() {
    SwitchMonitorService subject = makeSubject();
    final Instant t0 = clock.instant();
    // read-only connect ALPHA
    SwitchInfoData swAdd = new SwitchInfoData(SWITCH_ALPHA, SwitchChangeType.ADDED);
    subject.handleStatusUpdateNotification(swAdd, REGION_ALPHA);
    verify(carrier).regionUpdateNotification(eq(new RegionMappingAdd(swAdd.getSwitchId(), REGION_ALPHA, false)));
    verify(carrier).sendSwitchAvailabilityUpdateNotification(eq(swAdd.getSwitchId()), argThat(arg -> matchAvailabilityData(SwitchAvailabilityData.builder().connection(SwitchAvailabilityEntry.builder().regionName(REGION_ALPHA).connectMode(SwitchConnectMode.READ_ONLY).master(false).connectedAt(t0).build()).build(), arg)));
    verifyNoMoreInteractions(carrier);
    // read-write connect ALPHA
    clock.adjust(Duration.ofSeconds(1));
    final Instant t1 = clock.instant();
    SwitchInfoData swActivateAlpha = makeSwitchActivateNotification(swAdd.getSwitchId(), 1);
    subject.handleStatusUpdateNotification(swActivateAlpha, REGION_ALPHA);
    verify(carrier).sendSwitchConnectNotification(eq(swActivateAlpha.getSwitchId()), eq(swActivateAlpha.getSwitchView()), argThat(arg -> matchAvailabilityData(SwitchAvailabilityData.builder().connection(SwitchAvailabilityEntry.builder().regionName(REGION_ALPHA).connectMode(SwitchConnectMode.READ_WRITE).master(true).connectedAt(t1).switchAddress(swActivateAlpha.getSwitchView().getSwitchSocketAddress()).speakerAddress(swActivateAlpha.getSwitchView().getSpeakerSocketAddress()).build()).build(), arg)));
    verify(carrier).regionUpdateNotification(eq(new RegionMappingSet(swActivateAlpha.getSwitchId(), REGION_ALPHA, true)));
    verifyNoMoreInteractions(carrier);
    reset(carrier);
    clock.adjust(Duration.ofSeconds(1));
    final Instant t2 = clock.instant();
    // read-only connect BETA
    subject.handleStatusUpdateNotification(swAdd, REGION_BETA);
    verify(carrier).regionUpdateNotification(eq(new RegionMappingAdd(swAdd.getSwitchId(), REGION_BETA, false)));
    verify(carrier).sendSwitchAvailabilityUpdateNotification(eq(swActivateAlpha.getSwitchId()), argThat(arg -> matchAvailabilityData(SwitchAvailabilityData.builder().connection(SwitchAvailabilityEntry.builder().regionName(REGION_ALPHA).connectMode(SwitchConnectMode.READ_WRITE).master(true).connectedAt(t1).switchAddress(swActivateAlpha.getSwitchView().getSwitchSocketAddress()).speakerAddress(swActivateAlpha.getSwitchView().getSpeakerSocketAddress()).build()).connection(SwitchAvailabilityEntry.builder().regionName(REGION_BETA).connectMode(SwitchConnectMode.READ_ONLY).master(false).connectedAt(t2).build()).build(), arg)));
    verifyNoMoreInteractions(carrier);
    reset(carrier);
    clock.adjust(Duration.ofSeconds(1));
    final Instant t3 = clock.instant();
    // read-write connect BETA
    SwitchInfoData swActivateBeta = makeSwitchActivateNotification(swAdd.getSwitchId(), 2);
    subject.handleStatusUpdateNotification(swActivateBeta, REGION_BETA);
    verify(carrier).sendSwitchAvailabilityUpdateNotification(eq(swActivateAlpha.getSwitchId()), argThat(arg -> matchAvailabilityData(SwitchAvailabilityData.builder().connection(SwitchAvailabilityEntry.builder().regionName(REGION_ALPHA).connectMode(SwitchConnectMode.READ_WRITE).master(true).connectedAt(t1).switchAddress(swActivateAlpha.getSwitchView().getSwitchSocketAddress()).speakerAddress(swActivateAlpha.getSwitchView().getSpeakerSocketAddress()).build()).connection(SwitchAvailabilityEntry.builder().regionName(REGION_BETA).connectMode(SwitchConnectMode.READ_WRITE).switchAddress(swActivateBeta.getSwitchView().getSwitchSocketAddress()).speakerAddress(swActivateBeta.getSwitchView().getSpeakerSocketAddress()).master(false).connectedAt(t3).build()).build(), arg)));
    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) Instant(java.time.Instant) RegionMappingAdd(org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingAdd) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) 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