Search in sources :

Example 1 with FlowLatencyMonitoringFsm

use of org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm in project open-kilda by telstra.

the class ActionServiceTest method shouldUpdateFlowInfo.

@Test
public void shouldUpdateFlowInfo() {
    service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, NANOSECOND);
    service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, NANOSECOND);
    FlowPathDto path = FlowPathDto.builder().forwardPath(Arrays.asList(new PathNodePayload(SRC_SWITCH, 1, 2), new PathNodePayload(DST_SWITCH, 3, 4))).reversePath(Arrays.asList(new PathNodePayload(DST_SWITCH, 4, 3), new PathNodePayload(SRC_SWITCH, 2, 1))).build();
    long maxLatency = flow.getMaxLatency() / 2;
    long maxLatencyTier2 = flow.getMaxLatencyTier2() / 2;
    UpdateFlowCommand info = new UpdateFlowCommand(flow.getFlowId(), path, maxLatency, maxLatencyTier2);
    service.updateFlowInfo(info);
    assertEquals(2, service.fsms.values().size());
    FlowLatencyMonitoringFsm fsm = service.fsms.values().stream().findAny().orElseThrow(() -> new IllegalStateException("Fsm not found"));
    assertEquals(maxLatency, fsm.getMaxLatency());
    assertEquals(maxLatencyTier2, fsm.getMaxLatencyTier2());
    verifyNoMoreInteractions(carrier);
}
Also used : UpdateFlowCommand(org.openkilda.messaging.info.flow.UpdateFlowCommand) FlowPathDto(org.openkilda.messaging.model.FlowPathDto) PathNodePayload(org.openkilda.messaging.payload.flow.PathNodePayload) FlowLatencyMonitoringFsm(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 2 with FlowLatencyMonitoringFsm

use of org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm in project open-kilda by telstra.

the class ActionService method processFlowLatencyMeasurement.

/**
 * Check flow SLA is violated.
 */
public void processFlowLatencyMeasurement(String flowId, FlowDirection direction, Duration latency) {
    String key = getFsmKey(flowId, direction);
    FlowLatencyMonitoringFsm fsm = fsms.get(key);
    if (fsm == null) {
        Flow flow = flowRepository.findById(flowId).orElseThrow(() -> new IllegalStateException(format("Flow %s not found.", flowId)));
        long maxLatency = flow.getMaxLatency() == null || flow.getMaxLatency() == 0 ? Long.MAX_VALUE : flow.getMaxLatency();
        long maxLatencyTier2 = flow.getMaxLatencyTier2() == null || flow.getMaxLatencyTier2() == 0 ? Long.MAX_VALUE : flow.getMaxLatencyTier2();
        fsm = fsmFactory.produce(flowId, direction.name().toLowerCase(), maxLatency, maxLatencyTier2);
        fsms.put(key, fsm);
    }
    Context context = Context.builder().latency(latency.toNanos()).carrier(this).build();
    fsm.processLatencyMeasurement(context);
}
Also used : Context(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.Context) FlowLatencyMonitoringFsm(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm) Flow(org.openkilda.model.Flow)

Aggregations

FlowLatencyMonitoringFsm (org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm)2 Test (org.junit.Test)1 UpdateFlowCommand (org.openkilda.messaging.info.flow.UpdateFlowCommand)1 FlowPathDto (org.openkilda.messaging.model.FlowPathDto)1 PathNodePayload (org.openkilda.messaging.payload.flow.PathNodePayload)1 Flow (org.openkilda.model.Flow)1 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)1 Context (org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.Context)1