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