use of org.openkilda.model.SwitchId 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);
}
use of org.openkilda.model.SwitchId 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);
}
use of org.openkilda.model.SwitchId in project open-kilda by telstra.
the class OneToManyMapping method makeReversedMapping.
public Map<String, Set<SwitchId>> makeReversedMapping() {
Map<String, Set<SwitchId>> result = new HashMap<>();
for (Map.Entry<SwitchId, Set<String>> entry : mapping.entrySet()) {
for (String region : entry.getValue()) {
SwitchId switchId = entry.getKey();
result.computeIfAbsent(region, key -> new HashSet<>()).add(switchId);
}
}
return result;
}
use of org.openkilda.model.SwitchId in project open-kilda by telstra.
the class ControllerToSpeakerProxyService method unicastRequest.
public void unicastRequest(Message message) {
SwitchId switchId = RouterUtils.lookupSwitchId(message);
proxyUnicastRequest(new ProxyMessageWrapper(message), switchId);
}
use of org.openkilda.model.SwitchId in project open-kilda by telstra.
the class ControllerToSpeakerProxyService method statsRequest.
/**
* Route {@link StatsRequest}. Prefer to RO only regions.
*/
public void statsRequest(StatsRequest request, String correlationId) {
Map<String, Set<SwitchId>> rwPopulation = switchMapping.organizeReadWritePopulationPerRegion();
Map<String, Set<SwitchId>> roPopulation = switchMapping.organizeReadOnlyPopulationPerRegion();
Set<String> roRegions = new HashSet<>(roPopulation.keySet());
roRegions.removeAll(rwPopulation.keySet());
Instant now = clock.instant();
Set<SwitchId> processed = new HashSet<>();
for (String region : roRegions) {
sendStatsRequest(now, region, roPopulation.get(region), request, correlationId, processed);
}
for (Map.Entry<String, Set<SwitchId>> entry : rwPopulation.entrySet()) {
sendStatsRequest(now, entry.getKey(), entry.getValue(), request, correlationId, processed);
}
}
Aggregations