Fix duplicate payload detection over unicast links

This commit is contained in:
Jeremy Lakeman 2014-06-26 17:20:06 +09:30
parent a9545ea004
commit 63f02607e6
3 changed files with 24 additions and 26 deletions

View File

@ -238,13 +238,10 @@ int parseMdpPacketHeader(struct decode_context *context, struct overlay_frame *f
int seq = ob_get(buffer);
if (seq == -1)
RETURN(WHY("Unable to read packet seq"));
// TODO unicast
if ((flags & PAYLOAD_FLAG_ONE_HOP) || !(flags & PAYLOAD_FLAG_TO_BROADCAST)){
if (link_received_duplicate(context->sender, seq)){
if (config.debug.verbose && config.debug.overlayframes)
DEBUG("Don't process or forward duplicate payloads");
forward=process=0;
}
if (link_received_duplicate(context->sender, seq)){
if (config.debug.verbose && config.debug.overlayframes)
DEBUG("Don't process or forward duplicate payloads");
forward=process=0;
}
}
frame->modifiers=flags;

View File

@ -1137,25 +1137,26 @@ int link_received_duplicate(struct subscriber *subscriber, int payload_seq)
if (!neighbour)
return 0;
if (neighbour->mdp_ack_sequence != -1){
if (neighbour->mdp_ack_sequence == payload_seq){
if (neighbour->mdp_ack_sequence == -1){
neighbour->mdp_ack_sequence = payload_seq;
return 0;
}
if (neighbour->mdp_ack_sequence == payload_seq)
return 1;
int offset = (neighbour->mdp_ack_sequence - 1 - payload_seq)&0xFF;
if (offset < 64){
if (neighbour->mdp_ack_mask & (1<<offset)){
return 1;
}
int offset = (neighbour->mdp_ack_sequence - 1 - payload_seq)&0xFF;
if (offset < 64){
if (neighbour->mdp_ack_mask & (1<<offset)){
return 1;
}
neighbour->mdp_ack_mask |= (1<<offset);
}else{
int offset = (payload_seq - neighbour->mdp_ack_sequence - 1)&0xFF;
neighbour->mdp_ack_mask = (neighbour->mdp_ack_mask << 1) | 1;
neighbour->mdp_ack_mask = neighbour->mdp_ack_mask << offset;
neighbour->mdp_ack_sequence = payload_seq;
}
}else
neighbour->mdp_ack_mask |= (1<<offset);
}else{
int offset = (payload_seq - neighbour->mdp_ack_sequence - 1)&0xFF;
neighbour->mdp_ack_mask = (neighbour->mdp_ack_mask << 1) | 1;
neighbour->mdp_ack_mask = neighbour->mdp_ack_mask << offset;
neighbour->mdp_ack_sequence = payload_seq;
}
return 0;
}

View File

@ -746,7 +746,7 @@ test_ping_unreliable_2hop() {
received=$(sed -n -e 's/.*\<\([0-9]\+\) packets received.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
duplicates=$(sed -n -e 's/.*\<\([0-9]\+\) duplicates.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
assert [ "$received" -ge 98 ]
assert [ "$duplicates" -le 5 ]
assert [ "$duplicates" -le 2 ]
}
finally_ping_unreliable_2hop() {
simulator_quit
@ -829,7 +829,7 @@ test_unreliable_links() {
received=$(sed -n -e 's/.*\<\([0-9]\+\) packets received.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
duplicates=$(sed -n -e 's/.*\<\([0-9]\+\) duplicates.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
assert [ "$received" -ge 98 ]
assert [ "$duplicates" -le 5 ]
assert [ "$duplicates" -le 2 ]
# make sure the path is still there.
wait_until path_exists +A +B +C
wait_until path_exists +C +B +A
@ -874,7 +874,7 @@ test_unreliable_links2() {
received=$(sed -n -e 's/.*\<\([0-9]\+\) packets received.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
duplicates=$(sed -n -e 's/.*\<\([0-9]\+\) duplicates.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
assert [ "$received" -ge 98 ]
assert [ "$duplicates" -le 5 ]
assert [ "$duplicates" -le 2 ]
wait_until --timeout=20 path_exists +A +B +C +D
wait_until --timeout=20 path_exists +D +C +B +A
}