Search in sources :

Example 6 with SwitchId

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);
}
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) RegionMappingRemove(org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingRemove) Instant(java.time.Instant) SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) SwitchId(org.openkilda.model.SwitchId) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) Test(org.junit.Test)

Example 7 with SwitchId

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);
}
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) RegionMappingRemove(org.openkilda.wfm.topology.floodlightrouter.model.RegionMappingRemove) Instant(java.time.Instant) SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) SwitchId(org.openkilda.model.SwitchId) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) Test(org.junit.Test)

Example 8 with SwitchId

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;
}
Also used : HashSet(java.util.HashSet) SwitchId(org.openkilda.model.SwitchId) Map(java.util.Map) Set(java.util.Set) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) SwitchId(org.openkilda.model.SwitchId) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 9 with SwitchId

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);
}
Also used : SwitchId(org.openkilda.model.SwitchId)

Example 10 with 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);
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashSet(java.util.HashSet) Instant(java.time.Instant) SwitchId(org.openkilda.model.SwitchId) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

SwitchId (org.openkilda.model.SwitchId)339 Test (org.junit.Test)149 Flow (org.openkilda.model.Flow)73 Switch (org.openkilda.model.Switch)69 List (java.util.List)59 FlowPath (org.openkilda.model.FlowPath)49 ArrayList (java.util.ArrayList)44 Collectors (java.util.stream.Collectors)37 PathId (org.openkilda.model.PathId)36 PathComputer (org.openkilda.pce.PathComputer)35 Set (java.util.Set)34 YFlow (org.openkilda.model.YFlow)33 Map (java.util.Map)30 GetPathsResult (org.openkilda.pce.GetPathsResult)30 InfoMessage (org.openkilda.messaging.info.InfoMessage)29 String.format (java.lang.String.format)28 HashSet (java.util.HashSet)27 Optional (java.util.Optional)27 Collection (java.util.Collection)26 Collections (java.util.Collections)26