Search in sources :

Example 6 with Flow

use of org.openkilda.server42.control.messaging.flowrtt.FlowRttControl.Flow in project open-kilda by telstra.

the class ActionServiceTest method shouldFailTier1AndDoNotSendRerouteRequestWhenToggleIsFalse.

@Test
public void shouldFailTier1AndDoNotSendRerouteRequestWhenToggleIsFalse() {
    transactionManager.doInTransaction(() -> {
        KildaFeatureToggles featureToggles = featureTogglesRepository.find().orElseThrow(() -> new IllegalStateException("Feature toggle not found"));
        featureToggles.setFlowLatencyMonitoringReactions(false);
    });
    service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, NANOSECOND);
    service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, NANOSECOND);
    Duration latency = Duration.ofNanos((long) (flow.getMaxLatency() * (1 + THRESHOLD)) + 5);
    for (int i = 0; i < 10; i++) {
        clock.adjust(Duration.ofSeconds(10));
        service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, latency);
        service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, latency.minus(NANOSECOND));
        service.processTick();
        if (i == 0) {
            assertTrue(service.fsms.values().stream().allMatch(fsm -> UNSTABLE.equals(fsm.getCurrentState())));
        }
    }
    assertEquals(2, service.fsms.values().size());
    assertTrue(service.fsms.values().stream().allMatch(fsm -> TIER_1_FAILED.equals(fsm.getCurrentState())));
    FlowStats actual = flowStatsRepository.findByFlowId(flow.getFlowId()).orElseThrow(() -> new IllegalStateException("Flow not found"));
    assertEquals(latency.getNano(), actual.getForwardLatency().intValue());
    assertEquals(latency.minus(NANOSECOND).getNano(), actual.getReverseLatency().intValue());
    verifyNoMoreInteractions(carrier);
}
Also used : FlowDirection(org.openkilda.server42.messaging.FlowDirection) Arrays(java.util.Arrays) FlowStats(org.openkilda.model.FlowStats) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) HEALTHY(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.HEALTHY) Mock(org.mockito.Mock) FlowStatsRepository(org.openkilda.persistence.repositories.FlowStatsRepository) RunWith(org.junit.runner.RunWith) KildaFeatureTogglesRepository(org.openkilda.persistence.repositories.KildaFeatureTogglesRepository) PathNodePayload(org.openkilda.messaging.payload.flow.PathNodePayload) TIER_2_FAILED(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.TIER_2_FAILED) TIER_1_FAILED(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.TIER_1_FAILED) FlowLatencyMonitoringFsm(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm) Flow(org.openkilda.model.Flow) KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) UNSTABLE(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.UNSTABLE) FlowDefaults(org.openkilda.persistence.dummy.FlowDefaults) Duration(java.time.Duration) FlowPathDto(org.openkilda.messaging.model.FlowPathDto) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) PersistenceDummyEntityFactory(org.openkilda.persistence.dummy.PersistenceDummyEntityFactory) Before(org.junit.Before) FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowOperationsCarrier(org.openkilda.wfm.topology.flowmonitoring.bolt.FlowOperationsCarrier) PathComputationStrategy(org.openkilda.model.PathComputationStrategy) ManualClock(org.openkilda.stubs.ManualClock) UpdateFlowCommand(org.openkilda.messaging.info.flow.UpdateFlowCommand) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.verify(org.mockito.Mockito.verify) SwitchId(org.openkilda.model.SwitchId) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) FlowStats(org.openkilda.model.FlowStats) KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) Duration(java.time.Duration) FlowEndpoint(org.openkilda.model.FlowEndpoint) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 7 with Flow

use of org.openkilda.server42.control.messaging.flowrtt.FlowRttControl.Flow in project open-kilda by telstra.

the class ActionServiceTest method shouldFailTier1AndDoNotSendRerouteRequestForCostStrategy.

@Test
public void shouldFailTier1AndDoNotSendRerouteRequestForCostStrategy() {
    transactionManager.doInTransaction(() -> {
        Flow flowSetup = flowRepository.findById(flow.getFlowId()).orElseThrow(() -> new IllegalStateException("Flow not found"));
        flowSetup.setPathComputationStrategy(PathComputationStrategy.COST);
    });
    service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, NANOSECOND);
    service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, NANOSECOND);
    Duration latency = Duration.ofNanos((long) (flow.getMaxLatency() * (1 + THRESHOLD)) + 5);
    for (int i = 0; i < 10; i++) {
        clock.adjust(Duration.ofSeconds(10));
        service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, latency);
        service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, latency.minus(NANOSECOND));
        service.processTick();
        if (i == 0) {
            assertTrue(service.fsms.values().stream().allMatch(fsm -> UNSTABLE.equals(fsm.getCurrentState())));
        }
    }
    assertEquals(2, service.fsms.values().size());
    assertTrue(service.fsms.values().stream().allMatch(fsm -> TIER_1_FAILED.equals(fsm.getCurrentState())));
    FlowStats actual = flowStatsRepository.findByFlowId(flow.getFlowId()).orElseThrow(() -> new IllegalStateException("Flow not found"));
    assertEquals(latency.getNano(), actual.getForwardLatency().intValue());
    assertEquals(latency.minus(NANOSECOND).getNano(), actual.getReverseLatency().intValue());
    verifyNoMoreInteractions(carrier);
}
Also used : FlowDirection(org.openkilda.server42.messaging.FlowDirection) Arrays(java.util.Arrays) FlowStats(org.openkilda.model.FlowStats) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) HEALTHY(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.HEALTHY) Mock(org.mockito.Mock) FlowStatsRepository(org.openkilda.persistence.repositories.FlowStatsRepository) RunWith(org.junit.runner.RunWith) KildaFeatureTogglesRepository(org.openkilda.persistence.repositories.KildaFeatureTogglesRepository) PathNodePayload(org.openkilda.messaging.payload.flow.PathNodePayload) TIER_2_FAILED(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.TIER_2_FAILED) TIER_1_FAILED(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.TIER_1_FAILED) FlowLatencyMonitoringFsm(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm) Flow(org.openkilda.model.Flow) KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) UNSTABLE(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.UNSTABLE) FlowDefaults(org.openkilda.persistence.dummy.FlowDefaults) Duration(java.time.Duration) FlowPathDto(org.openkilda.messaging.model.FlowPathDto) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) PersistenceDummyEntityFactory(org.openkilda.persistence.dummy.PersistenceDummyEntityFactory) Before(org.junit.Before) FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowOperationsCarrier(org.openkilda.wfm.topology.flowmonitoring.bolt.FlowOperationsCarrier) PathComputationStrategy(org.openkilda.model.PathComputationStrategy) ManualClock(org.openkilda.stubs.ManualClock) UpdateFlowCommand(org.openkilda.messaging.info.flow.UpdateFlowCommand) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.verify(org.mockito.Mockito.verify) SwitchId(org.openkilda.model.SwitchId) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) FlowStats(org.openkilda.model.FlowStats) Duration(java.time.Duration) FlowEndpoint(org.openkilda.model.FlowEndpoint) Flow(org.openkilda.model.Flow) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 8 with Flow

use of org.openkilda.server42.control.messaging.flowrtt.FlowRttControl.Flow in project open-kilda by telstra.

the class ActionServiceTest method shouldFailTier2AndSendRerouteRequest.

@Test
public void shouldFailTier2AndSendRerouteRequest() {
    transactionManager.doInTransaction(() -> {
        Flow flowSetup = flowRepository.findById(flow.getFlowId()).orElseThrow(() -> new IllegalStateException("Flow not found"));
        flowSetup.setPathComputationStrategy(PathComputationStrategy.MAX_LATENCY);
    });
    service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, NANOSECOND);
    service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, NANOSECOND);
    Duration latency = Duration.ofNanos((long) (flow.getMaxLatencyTier2() * (1 + THRESHOLD)) + 5);
    for (int i = 0; i < 10; i++) {
        clock.adjust(Duration.ofSeconds(10));
        service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, latency);
        service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, latency.minus(NANOSECOND));
        service.processTick();
        if (i == 0) {
            assertTrue(service.fsms.values().stream().allMatch(fsm -> UNSTABLE.equals(fsm.getCurrentState())));
        }
    }
    assertEquals(2, service.fsms.values().size());
    assertTrue(service.fsms.values().stream().allMatch(fsm -> TIER_2_FAILED.equals(fsm.getCurrentState())));
    FlowStats actual = flowStatsRepository.findByFlowId(flow.getFlowId()).orElseThrow(() -> new IllegalStateException("Flow not found"));
    assertEquals(latency.getNano(), actual.getForwardLatency().intValue());
    assertEquals(latency.minus(NANOSECOND).getNano(), actual.getReverseLatency().intValue());
    verify(carrier, times(2)).sendFlowRerouteRequest(flow.getFlowId());
    verifyNoMoreInteractions(carrier);
}
Also used : FlowDirection(org.openkilda.server42.messaging.FlowDirection) Arrays(java.util.Arrays) FlowStats(org.openkilda.model.FlowStats) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) HEALTHY(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.HEALTHY) Mock(org.mockito.Mock) FlowStatsRepository(org.openkilda.persistence.repositories.FlowStatsRepository) RunWith(org.junit.runner.RunWith) KildaFeatureTogglesRepository(org.openkilda.persistence.repositories.KildaFeatureTogglesRepository) PathNodePayload(org.openkilda.messaging.payload.flow.PathNodePayload) TIER_2_FAILED(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.TIER_2_FAILED) TIER_1_FAILED(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.TIER_1_FAILED) FlowLatencyMonitoringFsm(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm) Flow(org.openkilda.model.Flow) KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) UNSTABLE(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.UNSTABLE) FlowDefaults(org.openkilda.persistence.dummy.FlowDefaults) Duration(java.time.Duration) FlowPathDto(org.openkilda.messaging.model.FlowPathDto) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) PersistenceDummyEntityFactory(org.openkilda.persistence.dummy.PersistenceDummyEntityFactory) Before(org.junit.Before) FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowOperationsCarrier(org.openkilda.wfm.topology.flowmonitoring.bolt.FlowOperationsCarrier) PathComputationStrategy(org.openkilda.model.PathComputationStrategy) ManualClock(org.openkilda.stubs.ManualClock) UpdateFlowCommand(org.openkilda.messaging.info.flow.UpdateFlowCommand) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.verify(org.mockito.Mockito.verify) SwitchId(org.openkilda.model.SwitchId) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) FlowStats(org.openkilda.model.FlowStats) Duration(java.time.Duration) FlowEndpoint(org.openkilda.model.FlowEndpoint) Flow(org.openkilda.model.Flow) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 9 with Flow

use of org.openkilda.server42.control.messaging.flowrtt.FlowRttControl.Flow in project open-kilda by telstra.

the class ActionServiceTest method shouldFailTier2AndDoNotSendRerouteRequestForCostStrategy.

@Test
public void shouldFailTier2AndDoNotSendRerouteRequestForCostStrategy() {
    transactionManager.doInTransaction(() -> {
        Flow flowSetup = flowRepository.findById(flow.getFlowId()).orElseThrow(() -> new IllegalStateException("Flow not found"));
        flowSetup.setPathComputationStrategy(PathComputationStrategy.COST);
    });
    service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, NANOSECOND);
    service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, NANOSECOND);
    Duration latency = Duration.ofNanos((long) (flow.getMaxLatencyTier2() * (1 + THRESHOLD)) + 5);
    for (int i = 0; i < 10; i++) {
        clock.adjust(Duration.ofSeconds(10));
        service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, latency);
        service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, latency.minus(NANOSECOND));
        service.processTick();
        if (i == 0) {
            assertTrue(service.fsms.values().stream().allMatch(fsm -> UNSTABLE.equals(fsm.getCurrentState())));
        }
    }
    assertEquals(2, service.fsms.values().size());
    assertTrue(service.fsms.values().stream().allMatch(fsm -> TIER_2_FAILED.equals(fsm.getCurrentState())));
    FlowStats actual = flowStatsRepository.findByFlowId(flow.getFlowId()).orElseThrow(() -> new IllegalStateException("Flow not found"));
    assertEquals(latency.getNano(), actual.getForwardLatency().intValue());
    assertEquals(latency.minus(NANOSECOND).getNano(), actual.getReverseLatency().intValue());
    verifyNoMoreInteractions(carrier);
}
Also used : FlowDirection(org.openkilda.server42.messaging.FlowDirection) Arrays(java.util.Arrays) FlowStats(org.openkilda.model.FlowStats) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) HEALTHY(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.HEALTHY) Mock(org.mockito.Mock) FlowStatsRepository(org.openkilda.persistence.repositories.FlowStatsRepository) RunWith(org.junit.runner.RunWith) KildaFeatureTogglesRepository(org.openkilda.persistence.repositories.KildaFeatureTogglesRepository) PathNodePayload(org.openkilda.messaging.payload.flow.PathNodePayload) TIER_2_FAILED(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.TIER_2_FAILED) TIER_1_FAILED(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.TIER_1_FAILED) FlowLatencyMonitoringFsm(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm) Flow(org.openkilda.model.Flow) KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) UNSTABLE(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.UNSTABLE) FlowDefaults(org.openkilda.persistence.dummy.FlowDefaults) Duration(java.time.Duration) FlowPathDto(org.openkilda.messaging.model.FlowPathDto) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) PersistenceDummyEntityFactory(org.openkilda.persistence.dummy.PersistenceDummyEntityFactory) Before(org.junit.Before) FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowOperationsCarrier(org.openkilda.wfm.topology.flowmonitoring.bolt.FlowOperationsCarrier) PathComputationStrategy(org.openkilda.model.PathComputationStrategy) ManualClock(org.openkilda.stubs.ManualClock) UpdateFlowCommand(org.openkilda.messaging.info.flow.UpdateFlowCommand) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.verify(org.mockito.Mockito.verify) SwitchId(org.openkilda.model.SwitchId) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) FlowStats(org.openkilda.model.FlowStats) Duration(java.time.Duration) FlowEndpoint(org.openkilda.model.FlowEndpoint) Flow(org.openkilda.model.Flow) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 10 with Flow

use of org.openkilda.server42.control.messaging.flowrtt.FlowRttControl.Flow in project open-kilda by telstra.

the class CalculateFlowLatencyService method handleGetLinkLatencyResponse.

/**
 * Handle get link latency response. Send check flow latency request if ready.
 */
public void handleGetLinkLatencyResponse(String requestId, Link link, Duration latency) {
    log.debug("Get link latency response for link {} with {} and requestId {}", link, latency, requestId);
    FlowLatencyRequest flowLatencyRequest = requests.get(requestId);
    if (flowLatencyRequest == null) {
        log.warn("Link latency response for unknown request found {}", link);
        return;
    }
    flowLatencyRequest.handleResponse(link, latency);
    if (flowLatencyRequest.isFulfilled()) {
        log.debug("Process calculated latency for requestId {}", requestId);
        String flowId = flowLatencyRequest.getFlowId();
        FlowDirection direction = flowLatencyRequest.getDirection();
        Duration result = flowLatencyRequest.getResult();
        carrier.emitCheckFlowLatencyRequest(flowId, direction, result);
        carrier.emitLatencyStats(flowId, direction, result);
        requests.remove(requestId);
    }
}
Also used : FlowLatencyRequest(org.openkilda.wfm.topology.flowmonitoring.model.FlowLatencyRequest) FlowDirection(org.openkilda.server42.messaging.FlowDirection) Duration(java.time.Duration)

Aggregations

Test (org.junit.Test)11 SwitchId (org.openkilda.model.SwitchId)10 InfoMessage (org.openkilda.messaging.info.InfoMessage)9 FlowDirection (org.openkilda.server42.messaging.FlowDirection)9 Duration (java.time.Duration)8 Values (org.apache.storm.tuple.Values)8 RunWith (org.junit.runner.RunWith)8 Mockito.verify (org.mockito.Mockito.verify)8 Message (org.openkilda.messaging.Message)8 CommandMessage (org.openkilda.messaging.command.CommandMessage)8 Arrays (java.util.Arrays)7 Assert.assertEquals (org.junit.Assert.assertEquals)7 Assert.assertTrue (org.junit.Assert.assertTrue)7 Before (org.junit.Before)7 Mock (org.mockito.Mock)7 Mockito.times (org.mockito.Mockito.times)7 Mockito.verifyNoMoreInteractions (org.mockito.Mockito.verifyNoMoreInteractions)7 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)7 UpdateFlowCommand (org.openkilda.messaging.info.flow.UpdateFlowCommand)7 FlowPathDto (org.openkilda.messaging.model.FlowPathDto)7