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