use of org.openkilda.wfm.topology.isllatency.model.LatencyRecord in project open-kilda by telstra.
the class IslStatsServiceTest method handleRoundTripLatencyForReverseIslTest.
@Test
public void handleRoundTripLatencyForReverseIslTest() {
// RTL: ...........................
// Reverse RTL: ...X.X.X.X.X.X.X.X.X.X.....
// OneWay: ..X.X.X.X.X.X.X.X.X.X......
List<LatencyRecord> buffer = new ArrayList<>();
Instant time = Instant.now();
for (int i = 0; i < 10; i++) {
sendForwardOneWayLatency(i + 10000, time);
time = time.plusMillis(10);
sendReverseRoundTripLatency(i, time);
time = time.plusSeconds(1);
// next one way packet will get latency from reverse ISL. but we will get timestamp for one way packet
buffer.add(new LatencyRecord(i, time.toEpochMilli()));
}
// we must emit reverse RTL on each one way packet. Last RTL packet was received after last one way packet
// so we wouldn't emit it.
buffer.remove(buffer.size() - 1);
assertEmitLatency(buffer);
}
use of org.openkilda.wfm.topology.isllatency.model.LatencyRecord in project open-kilda by telstra.
the class IslStatsServiceTest method handleOneWayLatencyEmitOnEachIslDownTest.
@Test
public void handleOneWayLatencyEmitOnEachIslDownTest() throws InterruptedException {
// RTL: ............................
// OneWay: ..X.X.X.X........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);
}
buffer.remove(0);
islStatsService.handleIstStatusUpdateNotification(new IslStatusUpdateNotification(SWITCH_ID_1, PORT_1, SWITCH_ID_2, PORT_2, INACTIVE));
time = Instant.now();
int secondPartOfPacketsSize = 4;
for (int i = 0; i < secondPartOfPacketsSize; i++) {
sendForwardOneWayLatency(i + secondPartOfPacketsSize, time);
buffer.add(new LatencyRecord(i + secondPartOfPacketsSize, time.toEpochMilli()));
time = time.plusMillis(500);
// need to real shift of system clock
sleep(50);
}
islStatsService.handleIstStatusUpdateNotification(new IslStatusUpdateNotification(SWITCH_ID_1, PORT_1, SWITCH_ID_2, PORT_2, INACTIVE));
assertEmitLatency(buffer);
}
use of org.openkilda.wfm.topology.isllatency.model.LatencyRecord in project open-kilda by telstra.
the class IslStatsServiceTest method handleRoundTripLatencyAndOneWayLatencyTest.
@Test
public void handleRoundTripLatencyAndOneWayLatencyTest() {
// RTL: ...X.X.X.X.X.X.X.X.X.X.....
// OneWay: ..X.X.X.X.X.X.X.X.X.X......
List<LatencyRecord> buffer = new ArrayList<>();
Instant time = Instant.now();
for (int i = 0; i < 10; i++) {
sendForwardOneWayLatency(i + 10000, time);
time = time.plusMillis(10);
sendForwardRoundTripLatency(i, time);
buffer.add(new LatencyRecord(i, time.toEpochMilli()));
time = time.plusSeconds(LATENCY_TIMEOUT / 2);
}
assertEmitLatency(buffer);
}
use of org.openkilda.wfm.topology.isllatency.model.LatencyRecord 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.LatencyRecord 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);
}
}
Aggregations