Search in sources :

Example 1 with IslKey

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

the class IslLatencyService method handleOneWayIslLatency.

/**
 * Handle one way latency metric.
 *
 * @param data isl one way latency info data
 * @param timestamp latency timestamp
 */
public void handleOneWayIslLatency(IslOneWayLatency data, long timestamp) {
    log.debug("Received one way latency {} for ISL {}_{} ===> {}_{}, Packet Id: {}", data.getLatency(), data.getSrcSwitchId(), data.getSrcPortNo(), data.getDstSwitchId(), data.getDstPortNo(), data.getPacketId());
    IslKey islKey = new IslKey(data);
    oneWayLatencyStorage.putIfAbsent(islKey, new LinkedList<>());
    oneWayLatencyStorage.get(islKey).add(new LatencyRecord(data.getLatency(), timestamp));
    if (isUpdateRequired(islKey)) {
        updateOneWayLatencyIfNeeded(data, islKey);
    }
}
Also used : IslKey(org.openkilda.wfm.topology.isllatency.model.IslKey) LatencyRecord(org.openkilda.wfm.topology.isllatency.model.LatencyRecord)

Example 2 with IslKey

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

the class IslLatencyService method updateOneWayLatencyIfNeeded.

private void updateOneWayLatencyIfNeeded(IslOneWayLatency data, IslKey islKey) {
    Queue<LatencyRecord> oneWayRecords = oneWayLatencyStorage.get(islKey);
    pollExpiredRecords(oneWayRecords);
    Queue<LatencyRecord> roundTripRecords = roundTripLatencyStorage.get(islKey);
    pollExpiredRecords(roundTripRecords);
    if (roundTripRecords != null && !roundTripRecords.isEmpty()) {
        // next round trip latency packet will update ISL latency
        return;
    }
    IslKey reverseIslKey = islKey.getReverse();
    Queue<LatencyRecord> reverseRoundTripRecords = roundTripLatencyStorage.get(reverseIslKey);
    pollExpiredRecords(reverseRoundTripRecords);
    boolean updated;
    if (reverseRoundTripRecords != null && !reverseRoundTripRecords.isEmpty()) {
        // reverse ISL has round trip latency records. We can use them for forward ISL
        long averageReverseLatency = calculateAverageLatency(reverseRoundTripRecords);
        updated = updateLatencyInDataBase(data, averageReverseLatency);
    } else {
        // There are no round trip latency records for both ISL direction. We have to use one way latency records
        if (oneWayRecords.isEmpty()) {
            log.warn("Couldn't update round trip latency {} for ISL {}_{} === {}_{}. " + "There is no valid latency records. Packet Id: {}", data.getLatency(), data.getSrcSwitchId(), data.getSrcPortNo(), data.getDstSwitchId(), data.getDstPortNo(), data.getPacketId());
            return;
        }
        long averageOneWayLatency = calculateAverageLatency(oneWayRecords);
        updated = updateLatencyInDataBase(data, averageOneWayLatency);
    }
    if (updated) {
        nextUpdateTimeMap.put(islKey, getNextUpdateTime());
        roundTripLatencyIsSet.remove(islKey);
    }
}
Also used : IslKey(org.openkilda.wfm.topology.isllatency.model.IslKey) LatencyRecord(org.openkilda.wfm.topology.isllatency.model.LatencyRecord)

Example 3 with IslKey

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

the class IslLatencyServiceTest method handleRoundTripIslLatencyNonExistentIslTest.

@Test
public void handleRoundTripIslLatencyNonExistentIslTest() {
    int fakePort = 998;
    IslKey islKey = new IslKey(SWITCH_ID_1, fakePort, SWITCH_ID_2, fakePort);
    assertTrue(islLatencyService.isUpdateRequired(islKey));
    IslRoundTripLatency nonExistent = new IslRoundTripLatency(SWITCH_ID_1, fakePort, 4, PACKET_ID);
    islLatencyService.handleRoundTripIslLatency(nonExistent, Endpoint.of(SWITCH_ID_2, fakePort), System.currentTimeMillis());
    assertTrue(islLatencyService.isUpdateRequired(islKey));
}
Also used : IslKey(org.openkilda.wfm.topology.isllatency.model.IslKey) IslRoundTripLatency(org.openkilda.messaging.info.event.IslRoundTripLatency) Endpoint(org.openkilda.wfm.share.model.Endpoint) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 4 with IslKey

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

the class IslStatsService method handleIstStatusUpdateNotification.

/**
 * Handle ISL status update notification.
 *
 * @param notification notification with new ISL status
 */
public void handleIstStatusUpdateNotification(IslStatusUpdateNotification notification) {
    IslKey key = new IslKey(notification.getSrcSwitchId(), notification.getSrcPortNo(), notification.getDstSwitchId(), notification.getDstPortNo());
    if (notification.getStatus() == IslStatus.MOVED) {
        handleIslMoved(key);
        handleIslMoved(key.getReverse());
    } else if (notification.getStatus() == IslStatus.INACTIVE) {
        handleIslDown(key);
        handleIslDown(key.getReverse());
    }
}
Also used : IslKey(org.openkilda.wfm.topology.isllatency.model.IslKey)

Example 5 with IslKey

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

the class IslStatsService method handleOneWayLatencyMetric.

/**
 * Handle one way latency metric.
 *
 * @param timestamp timestamp of metric
 * @param data isl one way latency info data
 */
public void handleOneWayLatencyMetric(long timestamp, IslOneWayLatency data) {
    log.debug("Received one way latency {} for ISL {}_{} ===> {}_{}, Packet Id: {}", data.getLatency(), data.getSrcSwitchId(), data.getSrcPortNo(), data.getDstSwitchId(), data.getDstPortNo(), data.getPacketId());
    IslKey forward = new IslKey(data);
    if (haveValidRoundTripLatencyRecord(forward)) {
        // metric was emitted by round trip latency handler
        return;
    }
    IslKey reverse = forward.getReverse();
    if (haveValidRoundTripLatencyRecord(reverse)) {
        // get RTL metric from reverse ISL and emit it
        emitReverseRoundTripLatency(forward, reverse, timestamp);
        return;
    }
    // there is no RTL records during latency timeout so we have to use one way latency
    oneWayLatencyStorage.putIfAbsent(forward, new TreeMap<>());
    oneWayLatencyStorage.get(forward).put(timestamp, data.getLatency());
    if (!oneWayLatencyEmitTimeoutMap.containsKey(forward)) {
        Instant emitTimeout = Instant.ofEpochMilli(timestamp).plusSeconds(latencyTimeout);
        oneWayLatencyEmitTimeoutMap.put(forward, emitTimeout);
        return;
    }
    Instant emitTimeout = oneWayLatencyEmitTimeoutMap.get(forward);
    if (emitTimeout.isBefore(Instant.ofEpochMilli(timestamp))) {
        // we waited enough to be sure that we wouldn't get a round trip latency packet
        emitValidOneWayRecords(forward);
        clearOneWayRecords(forward);
    }
// else still waiting for RTL and collecting one way records
}
Also used : IslKey(org.openkilda.wfm.topology.isllatency.model.IslKey) Instant(java.time.Instant)

Aggregations

IslKey (org.openkilda.wfm.topology.isllatency.model.IslKey)8 LatencyRecord (org.openkilda.wfm.topology.isllatency.model.LatencyRecord)4 Test (org.junit.Test)2 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)2 Endpoint (org.openkilda.wfm.share.model.Endpoint)2 Instant (java.time.Instant)1 IslOneWayLatency (org.openkilda.messaging.info.event.IslOneWayLatency)1 IslRoundTripLatency (org.openkilda.messaging.info.event.IslRoundTripLatency)1