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