Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Add DuplicateDevice (#33) #71

wants to merge 2 commits into from

Conversation

un-lock-able
Copy link
Contributor

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 bound Clone at the moment.

@un-lock-able un-lock-able requested a review from BobAnkh July 3, 2024 03:29
@BobAnkh BobAnkh requested review from Centaurus99 and removed request for BobAnkh July 3, 2024 03:51
@BobAnkh
Copy link
Member

BobAnkh commented Jul 3, 2024

@minhuw Shall we accept this or wait for Clone trait bound on Packet trait?

@minhuw
Copy link
Member

minhuw commented Jul 3, 2024

I prefer to wait for the Clone trait since we don't need DuplicateDevice currently.

Comment on lines +72 to +78
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);
}

Copy link
Member

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?

Copy link
Contributor Author

@un-lock-able un-lock-able Jul 3, 2024

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.

Copy link
Member

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.

@minhuw minhuw force-pushed the main branch 2 times, most recently from fae9cd4 to acb2cb6 Compare November 20, 2024 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants