<commit_before>package org.openkilda.functionaltests.spec.flows

import static org.junit.jupiter.api.Assumptions.assumeTrue
import static org.openkilda.functionaltests.extension.tags.Tag.LOW_PRIORITY
import static org.openkilda.functionaltests.helpers.FlowHistoryConstants.REROUTE_SUCCESS
import static org.openkilda.functionaltests.helpers.Wrappers.wait
import static org.openkilda.messaging.info.event.IslChangeType.DISCOVERED
import static org.openkilda.testing.Constants.WAIT_OFFSET

import org.openkilda.functionaltests.HealthCheckSpecification
import org.openkilda.functionaltests.extension.failfast.Tidy
import org.openkilda.functionaltests.extension.tags.Tags
import org.openkilda.functionaltests.helpers.model.SwitchPair
import org.openkilda.messaging.error.MessageError
import org.openkilda.messaging.info.event.IslChangeType
import org.openkilda.messaging.info.event.PathNode
import org.openkilda.messaging.payload.flow.FlowState
import org.openkilda.model.PathComputationStrategy
import org.openkilda.testing.model.topology.TopologyDefinition.Isl

import org.springframework.http.HttpStatus
import org.springframework.web.client.HttpClientErrorException
import spock.lang.Narrative
import spock.lang.See
import spock.lang.Shared

@See("https://github.com/telstra/open-kilda/blob/develop/docs/design/pce/design.md")
@Narrative("""
A flow with LATENCY strategy:
    - system tries to find the path with best latency, mL/mlT2 is not used during finding a path
    - system doesn't allow to create a flow in case flowPathLatency > max_latency_tier2
    - system moves flow to DOWN state after attempt to reroute in case flowPathLatency > max_latency_tier2
    - `max_latency` and `max_latency_tier2` fields are used for setting the status of the flow
    (for example: two paths with 11 and 15 latency and two flows flow_1: mL=10, mlT2=12; flow_2: mL=14, mlT2=16
     Both flows are build via the path with 11 latency, but the status is different: flow_1 - degraded, flow_2-up)
    - flowPathLatency <= max_latency - flow is in UP state after creating
    - flowPathLatency > max_latency - flow is in DEGRADED state after creating
    - max_latency_tier2 < max_latency - it is wrong, but the system allows it. In this case the system will consider
    that max_latency_tier2 = max_latency and inform us via kibana by warning message:
    log.warn("Bad flow params found: maxLatencyTier2 ({}) should be greater than maxLatency ({}). "
    + "Put maxLatencyTier2 = maxLatency during path calculation.", flow.getMaxLatencyTier2(), flow.getMaxLatency());
""")
class MaxLatencySpec extends HealthCheckSpecification {
    @Shared
    List<PathNode> mainPath, alternativePath
    @Shared
    List<Isl> mainIsls, alternativeIsls, islsToBreak
    @Shared
    SwitchPair switchPair

    def setupSpec() {
        //setup: Two active switches with two diverse paths
        List<List<PathNode>> paths
        switchPair = topologyHelper.switchPairs.find {<commit_msg>[tests] update "Narrative" in MaxLatencySpec<commit_after>package org.openkilda.functionaltests.spec.flows

import static org.junit.jupiter.api.Assumptions.assumeTrue
import static org.openkilda.functionaltests.extension.tags.Tag.LOW_PRIORITY
import static org.openkilda.functionaltests.helpers.FlowHistoryConstants.REROUTE_SUCCESS
import static org.openkilda.functionaltests.helpers.Wrappers.wait
import static org.openkilda.messaging.info.event.IslChangeType.DISCOVERED
import static org.openkilda.testing.Constants.WAIT_OFFSET

import org.openkilda.functionaltests.HealthCheckSpecification
import org.openkilda.functionaltests.extension.failfast.Tidy
import org.openkilda.functionaltests.extension.tags.Tags
import org.openkilda.functionaltests.helpers.model.SwitchPair
import org.openkilda.messaging.error.MessageError
import org.openkilda.messaging.info.event.IslChangeType
import org.openkilda.messaging.info.event.PathNode
import org.openkilda.messaging.payload.flow.FlowState
import org.openkilda.model.PathComputationStrategy
import org.openkilda.testing.model.topology.TopologyDefinition.Isl

import org.springframework.http.HttpStatus
import org.springframework.web.client.HttpClientErrorException
import spock.lang.Narrative
import spock.lang.See
import spock.lang.Shared

@See(["https://github.com/telstra/open-kilda/blob/develop/docs/design/pce/design.md",
        "https://github.com/telstra/open-kilda/blob/develop/docs/design/pce/max-latency-issue/README.md"])
@Narrative("""
A flow with LATENCY strategy:
    - system tries to find the path with best latency, mL/mlT2 is not used during finding a path
    - system doesn't allow to create a flow in case flowPathLatency > max_latency_tier2
    - system moves flow to DOWN state after attempt to reroute in case flowPathLatency > max_latency_tier2
    - `max_latency` and `max_latency_tier2` fields are used for setting the status of the flow
    (for example: two paths with 11 and 15 latency and two flows flow_1: mL=10, mlT2=12; flow_2: mL=14, mlT2=16
     Both flows are build via the path with 11 latency, but the status is different: flow_1 - degraded, flow_2-up)
    - flowPathLatency <= max_latency - flow is in UP state after creating
    - flowPathLatency > max_latency - flow is in DEGRADED state after creating
    - max_latency_tier2 < max_latency - it is wrong, but the system allows it. In this case the system will consider
    that max_latency_tier2 = max_latency and inform us via kibana by warning message:
    log.warn("Bad flow params found: maxLatencyTier2 ({}) should be greater than maxLatency ({}). "
    + "Put maxLatencyTier2 = maxLatency during path calculation.", flow.getMaxLatencyTier2(), flow.getMaxLatency());

    Special cases(covered by unit tests('MaxLatencyPathComputationStrategyBaseTest.java')):
    - flow with MAX_LATENCY strategy and 'max-latency' set to 0 should pick path with least latency.
    - flow with MAX_LATENCY strategy and 'max-latency' being unset(null) should pick path with least latency.
""")
class MaxLatencySpec extends HealthCheckSpecification {
    @Shared
    List<PathNode> mainPath, alternativePath
    @Shared
    List<Isl> mainIsls, alternativeIsls, islsToBreak
    @Shared
    SwitchPair switchPair

    def setupSpec() {
        //setup: Two active switches with two diverse paths
        List<List<PathNode>> paths
        switchPair = topologyHelper.switchPairs.find {
{'fraction_non_alphanumeric': 0.07753884790456757, 'fraction_numerical': 0.009260712603986814, 'mean_word_length': 4.824497257769653, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4746167', 'n_tokens_mistral': 1983, 'n_tokens_neox': 1895, 'n_words': 523}