-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DuplicateDevice (#33) #71
base: main
Are you sure you want to change the base?
Conversation
@minhuw Shall we accept this or wait for |
I prefer to wait for the |
async fn dequeue(&mut self) -> Option<P> { | ||
// Simply return previously duplicated packet, if any | ||
let buffer = self.duplicated_buffer.take(); | ||
if let Some(packet) = buffer { | ||
return Some(packet); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to result in a package being duplicated at most once. Perhaps the duplicated package should be allowed to be duplicated again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had come across this question when working with this issue.
Two ways of implementing this device come to my mind at first glance. The first one is, for example, in the ingress queue there are packets A, B, and C, and the pattern is [0.2, 0.1]
. Assume that the device decides that packet A should be duplicated, so it copies A and gives out a copy of A when dequeue()
is called, but the ingress is still A, B and C. When dequeue()
is called again, the device determines whether A should be duplicated with probability 0.1. If it is duplicated again, then it will copy A again, so the ingress queue will always be A, B and C, until A is decided not duplicated and the queue will change to B, C. However, this means that for two consecutive packets (A and B), the probability at which it is duplicated for the first time is always 0.2. On the contrary, in LossDevice
, for two consecutive packets (A and B), if the former one is decided to be loss (in this example, at probability 0.2), then the probability at which the latter is lost is different (in this example, at probability 0.1).
The second one is what I wrote in this PR, and I decided that if one wants to duplicate a packet more than once, one can chain two DuplicateDevice
so that the packets has the chance of being copied multiple times.
What I have just come up with is that, maybe we should design a new structure for the DuplicatePattern
, for example
[[0.3, 0.4, 0.5],
[0.1, 0.2, 0.3],
[0.2, 0.3, 0.4]]
where every row of the matrix represents the probability of duplicating the packet for the first time, second time, ..., just as described in the "first way". A packet will follow the pattern in the first row when the previous packet is not duplicated, and when the a packet is decided to be duplicated for at least once, then the duplicate pattern of the second packet is the second row of the matrix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, it might be acceptable to have DuplicatePattern
as a matrix. But we must discuss its meaning thoroughly before we implement it.
fae9cd4
to
acb2cb6
Compare
Add
DuplicateDevice
.For now, the device will explicitly copy the buffer and the timestamp of a packet since the
Packet
trait does not have the trait boundClone
at the moment.