Search in sources :

Example 11 with LatencyRecord

use of org.openkilda.wfm.topology.isllatency.model.LatencyRecord in project open-kilda by telstra.

the class IslStatsServiceTest method handleOneWayLatencyCollectsRecordsUntilTimeoutTest.

@Test
public void handleOneWayLatencyCollectsRecordsUntilTimeoutTest() {
    // RTL:     .....................
    // OneWay:  ..X.X.X.X.X.X.X.X....
    // Timeout: ...|_____________|...
    List<LatencyRecord> buffer = new ArrayList<>();
    Instant time = Instant.now().minusSeconds(LATENCY_TIMEOUT).minusMillis(500);
    for (int i = 0; i <= LATENCY_TIMEOUT; i++) {
        sendForwardOneWayLatency(i, time);
        // waiting for timeout and collecting one way records
        verifyNoMoreInteractions(carrier);
        buffer.add(new LatencyRecord(i, time.toEpochMilli()));
        time = time.plusSeconds(1);
    }
    // first record is outdated and we must not emit it
    buffer.remove(0);
    // first record after timeout
    // we received enough latency records and all stored records will be flushed
    sendForwardOneWayLatency(100, time);
    buffer.add(new LatencyRecord(100, time.toEpochMilli()));
    // ISL down notification must flush one way latency storage
    assertEmitLatency(buffer);
}
Also used : LatencyRecord(org.openkilda.wfm.topology.isllatency.model.LatencyRecord) Instant(java.time.Instant) ArrayList(java.util.ArrayList) Endpoint(org.openkilda.wfm.share.model.Endpoint) Test(org.junit.Test)

Example 12 with LatencyRecord

use of org.openkilda.wfm.topology.isllatency.model.LatencyRecord in project open-kilda by telstra.

the class IslStatsServiceTest method handleOneWayLatencyEmitOnIslDownTest.

@Test
public void handleOneWayLatencyEmitOnIslDownTest() {
    // RTL:      ...........................
    // OneWay:   ..X.X.X.X..................
    // Timeout:  ...|____________|..........
    // ISL down: .........^.................
    List<LatencyRecord> buffer = new ArrayList<>();
    Instant time = Instant.now().minusSeconds(LATENCY_TIMEOUT).minusMillis(500);
    for (int i = 0; i < 4; i++) {
        sendForwardOneWayLatency(i, time);
        // waiting for timeout and collecting one way records
        verifyNoMoreInteractions(carrier);
        buffer.add(new LatencyRecord(i, time.toEpochMilli()));
        time = time.plusSeconds(1);
    }
    // first record is outdated and we must not emit it
    buffer.remove(0);
    islStatsService.handleIstStatusUpdateNotification(new IslStatusUpdateNotification(SWITCH_ID_1, PORT_1, SWITCH_ID_2, PORT_2, INACTIVE));
    assertEmitLatency(buffer);
}
Also used : IslStatusUpdateNotification(org.openkilda.messaging.info.event.IslStatusUpdateNotification) LatencyRecord(org.openkilda.wfm.topology.isllatency.model.LatencyRecord) Instant(java.time.Instant) ArrayList(java.util.ArrayList) Endpoint(org.openkilda.wfm.share.model.Endpoint) Test(org.junit.Test)

Example 13 with LatencyRecord

use of org.openkilda.wfm.topology.isllatency.model.LatencyRecord in project open-kilda by telstra.

the class IslLatencyService method handleRoundTripIslLatency.

/**
 * Handle round trip latency.
 *
 * @param data round trip latency info data
 * @param destination isl destination endpoint
 * @param timestamp latency timestamp
 */
public void handleRoundTripIslLatency(IslRoundTripLatency data, Endpoint destination, long timestamp) {
    if (data.getLatency() < 0) {
        log.warn("Received invalid round trip latency {} for ISL {}_{} ===> {}_{}. Packet Id: {}. Origin: {}", data.getLatency(), data.getSrcSwitchId(), data.getSrcPortNo(), destination.getDatapath(), destination.getPortNumber(), data.getPacketId(), data.getOrigin());
        return;
    }
    log.debug("Received round trip latency {} for ISL {}_{} ===> {}_{}. Packet Id: {}. Origin: {}", data.getLatency(), data.getSrcSwitchId(), data.getSrcPortNo(), destination.getDatapath(), destination.getPortNumber(), data.getPacketId(), data.getOrigin());
    IslKey islKey = new IslKey(data, destination);
    roundTripLatencyStorage.putIfAbsent(islKey, new LinkedList<>());
    roundTripLatencyStorage.get(islKey).add(new LatencyRecord(data.getLatency(), timestamp));
    if (isUpdateRequired(islKey) || !roundTripLatencyIsSet.contains(islKey)) {
        updateRoundTripLatency(data, destination, islKey);
    }
}
Also used : IslKey(org.openkilda.wfm.topology.isllatency.model.IslKey) LatencyRecord(org.openkilda.wfm.topology.isllatency.model.LatencyRecord)

Example 14 with LatencyRecord

use of org.openkilda.wfm.topology.isllatency.model.LatencyRecord in project open-kilda by telstra.

the class IslLatencyServiceTest method pollExpiredRecordsTest.

@Test
public void pollExpiredRecordsTest() {
    Instant time = Instant.now().minusSeconds(LATENCY_UPDATE_TIME_RANGE * 2);
    Queue<LatencyRecord> latencyRecords = new LinkedList<>();
    for (int i = 0; i < 5; i++) {
        latencyRecords.add(new LatencyRecord(i, time.toEpochMilli()));
        time = time.plusSeconds(1);
    }
    time = Instant.now().minusSeconds(LATENCY_UPDATE_TIME_RANGE - 7);
    for (int i = 5; i < 10; i++) {
        latencyRecords.add(new LatencyRecord(i, time.toEpochMilli()));
        time = time.plusSeconds(1);
    }
    assertEquals(10, latencyRecords.size());
    islLatencyService.pollExpiredRecords(latencyRecords);
    assertEquals(5, latencyRecords.size());
    for (int i = 5; i < 10; i++) {
        assertEquals(i, latencyRecords.poll().getLatency());
    }
}
Also used : LatencyRecord(org.openkilda.wfm.topology.isllatency.model.LatencyRecord) Instant(java.time.Instant) LinkedList(java.util.LinkedList) Endpoint(org.openkilda.wfm.share.model.Endpoint) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Aggregations

LatencyRecord (org.openkilda.wfm.topology.isllatency.model.LatencyRecord)14 Test (org.junit.Test)10 Endpoint (org.openkilda.wfm.share.model.Endpoint)10 Instant (java.time.Instant)9 ArrayList (java.util.ArrayList)8 IslKey (org.openkilda.wfm.topology.isllatency.model.IslKey)4 IslStatusUpdateNotification (org.openkilda.messaging.info.event.IslStatusUpdateNotification)3 LinkedList (java.util.LinkedList)2 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)2