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);
}
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);
}
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());
}
Aggregations