Skip to content

UDPSOCKET_ECHOTEST change to tolerate duplicate packets #11693

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

Merged
merged 1 commit into from
Nov 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion TESTS/netsocket/udp/udpsocket_echotest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ static const int pkt_sizes[PKTS] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, \
100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, \
1100, 1200
};
static bool pkt_received[PKTS] = {false, false, false, false, false, false, false, false, false, false, \
false, false, false, false, false, false, false, false, false, false, \
false, false
};

Timer tc_exec_time;
int time_allotted;
}
Expand All @@ -68,6 +73,7 @@ void UDPSOCKET_ECHOTEST()
int sent;
int packets_sent = 0;
int packets_recv = 0;
bool received_duplicate_packet = false;
for (unsigned int s_idx = 0; s_idx < sizeof(pkt_sizes) / sizeof(*pkt_sizes); ++s_idx) {
int pkt_s = pkt_sizes[s_idx];

Expand All @@ -85,7 +91,20 @@ void UDPSOCKET_ECHOTEST()
printf("[Round#%02d - Sender] error, returned %d\n", s_idx, sent);
continue;
}
recvd = sock.recvfrom(NULL, rx_buffer, pkt_s);

do {
received_duplicate_packet = false;
recvd = sock.recvfrom(NULL, rx_buffer, pkt_s);
//Check if received duplicated packet
for (unsigned int d_idx = 0; d_idx < PKTS; ++d_idx) {
if (pkt_received[d_idx] && d_idx != s_idx && recvd == pkt_sizes[d_idx]) {
printf("[Round#%02d - Receiver] info, received duplicate packet %d\n", s_idx, d_idx);
received_duplicate_packet = true;
break;
}
}
} while (received_duplicate_packet);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this logic.

You assume that all duplicates will be received in order.

This might be true for ECHOTEST, but might not be true for ECHOTEST_BURST.

So while re-working this, can you change logic so that it tolerates re-ordering as well.

I would assume this kind of logic might work:

// List of packet sizes to send
static const int pkt_sizes[PKTS] = {...);
// List of boolean flags to mark each size as "received"
static bool pkt_received[PKTS] = {false};

// ... in the test case
for (int retry_cnt = 0; retry_cnt <= 2; retry_cnt++) {
    ...
    sent = sock.sendto(udp_addr, tx_buffer, pkt_s);
    if (...) {
        // errors..
    }
    do {
        recvd = sock.recvfrom(...);
        // Check that packet is what we sent
        if (recvd == pkt_sizes[s_idx] && memcmp(rx_last, rx_buffer, recvd) == 0)
            pkt_received[s_idx] = true;
        }
    } while(pkt_received[s_idx] == false);
}

So just accept what we were waiting for, ignore the rest.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed logic. Now responses for all sends and duplicates of this responses are accepted. Other packets with incorrect size are interpreted as error.

if (recvd == pkt_s) {
break;
} else {
Expand All @@ -94,6 +113,7 @@ void UDPSOCKET_ECHOTEST()
}
if (memcmp(tx_buffer, rx_buffer, pkt_s) == 0) {
packets_recv++;
pkt_received[s_idx] = true;
}
// Make sure that at least one packet of every size was sent.
TEST_ASSERT_TRUE(packets_sent > packets_sent_prev);
Expand Down