Fix failure to display Cake Tins in web UI

Cake Diff functions now use "checked_sub" to ensure that an overflow
doesn't mess up data.

Web UI includes checks that Cake data is available on each history
tick.
This commit is contained in:
Herbert Wolverson 2023-01-16 14:30:48 +00:00
parent 5be5111954
commit 05bb1ee959
2 changed files with 22 additions and 7 deletions

View File

@ -262,8 +262,16 @@
if (tin == 0) {
qlenX1.push(counter);
qlenX2.push(counter);
qlenY1.push(data.history[i][0].Cake.qlen);
qlenY2.push(0.0 - data.history[i][1].Cake.qlen);
if (data.history[i][0].Cake) {
qlenY1.push(data.history[i][0].Cake.qlen);
} else {
qlenY1.push(0);
}
if (data.history[i][1].Cake) {
qlenY2.push(0.0 - data.history[i][1].Cake.qlen);
} else {
qlenY2.push(0.0);
}
}
counter++;
}
@ -273,8 +281,16 @@
if (tin == 0) {
qlenX1.push(counter);
qlenX2.push(counter);
qlenY1.push(data.history[i][0].Cake.qlen);
qlenY2.push(0.0 - data.history[i][1].Cake.qlen);
if (data.history[i][0].Cake) {
qlenY1.push(data.history[i][0].Cake.qlen);
} else {
qlenY1.push(0.0);
}
if (data.history[i][1].Cake) {
qlenY2.push(0.0 - data.history[i][1].Cake.qlen);
} else {
qlenY2.push(0.0);
}
}
counter++;
}

View File

@ -48,12 +48,11 @@ fn cake_diff(previous: &QueueType, current: &QueueType) -> Result<QueueDiff> {
.iter()
.zip(prev.tins.iter())
.map(|(new, prev)| {
//println!("{} - {} = {}", new.sent_bytes, prev.sent_bytes, new.sent_bytes -prev.sent_bytes);
CakeDiffTin {
sent_bytes: new.sent_bytes - prev.sent_bytes,
sent_bytes: new.sent_bytes.checked_sub(prev.sent_bytes).unwrap_or(0),
backlog_bytes: new.backlog_bytes,
drops: new.drops - prev.drops,
marks: new.ecn_marks - prev.ecn_marks,
marks: new.ecn_marks.checked_sub(prev.ecn_marks).unwrap_or(0),
avg_delay_us: new.avg_delay_us,
}
})