Search in sources :

Example 1 with RegionMappingAdd

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

Example 2 with RegionMappingAdd

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

the class ControllerToSpeakerProxyServiceTest method verifyStatsPreferRoRegions.

@Test
public void verifyStatsPreferRoRegions() {
    ControllerToSpeakerProxyService subject = makeSubject();
    // stats/RO only region
    subject.switchMappingUpdate(new RegionMappingAdd(SWITCH_ALPHA, REGION_STATS, false));
    subject.switchMappingUpdate(new RegionMappingAdd(SWITCH_BETA, REGION_STATS, false));
    // management/RW region
    subject.switchMappingUpdate(new RegionMappingAdd(SWITCH_BETA, REGION_MANAGEMENT, false));
    subject.switchMappingUpdate(new RegionMappingAdd(SWITCH_BETA, REGION_MANAGEMENT, true));
    subject.switchMappingUpdate(new RegionMappingAdd(SWITCH_GAMMA, REGION_MANAGEMENT, false));
    subject.switchMappingUpdate(new RegionMappingAdd(SWITCH_GAMMA, REGION_MANAGEMENT, true));
    verifyZeroInteractions(carrier);
    String correlationId = "dummy-request";
    StatsRequest request = new StatsRequest();
    subject.statsRequest(request, correlationId);
    // RO only region
    verify(carrier).sendToSpeaker(makeStatsRegionRequest(request, ImmutableSet.of(SWITCH_ALPHA, SWITCH_BETA), correlationId), REGION_STATS);
    verify(carrier).sendToSpeaker(makeStatsRegionRequest(request, ImmutableSet.of(SWITCH_GAMMA), correlationId), REGION_MANAGEMENT);
    verifyNoMoreInteractions(carrier);
}
Also used : RegionMappingAdd(org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingAdd) StatsRequest(org.openkilda.messaging.command.stats.StatsRequest) Test(org.junit.Test)

Example 3 with RegionMappingAdd

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

the class SwitchMonitor method acquireReadOnlyRegion.

private void acquireReadOnlyRegion(String region) {
    carrier.regionUpdateNotification(new RegionMappingAdd(switchId, region, false));
    carrier.sendSwitchAvailabilityUpdateNotification(switchId, makeDump());
}
Also used : RegionMappingAdd(org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingAdd)

Aggregations

RegionMappingAdd (org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingAdd)3 Test (org.junit.Test)2 Duration (java.time.Duration)1 Instant (java.time.Instant)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 Assert (org.junit.Assert)1 RunWith (org.junit.runner.RunWith)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)1 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)1 Mock (org.mockito.Mock)1 Mockito.reset (org.mockito.Mockito.reset)1 Mockito.times (org.mockito.Mockito.times)1 Mockito.verify (org.mockito.Mockito.verify)1 Mockito.verifyNoMoreInteractions (org.mockito.Mockito.verifyNoMoreInteractions)1 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)1 StatsRequest (org.openkilda.messaging.command.stats.StatsRequest)1