[icmp] Add test to verify no duplicated icmp echo reply on mesh-local

addresses.

Bug: 333493455

Test: atest ThreadNetworkIntegrationTests:android.net.thread.ThreadIntegrationTest#edPingsMeshLocalAddresses_oneReplyPerRequest

Change-Id: I07aefa1311f15d3f801de64c0342694296f09469
This commit is contained in:
Yang Sun 2024-04-23 16:21:48 +08:00
commit d722a997bd
2 changed files with 46 additions and 2 deletions

View file

@ -31,6 +31,7 @@ import static com.android.server.thread.openthread.IOtDaemon.TUN_IF_NAME;
import static com.google.common.io.BaseEncoding.base16;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import android.content.Context;
import android.net.InetAddresses;
@ -237,6 +238,21 @@ public class ThreadIntegrationTest {
assertTunInterfaceMemberOfGroup(GROUP_ADDR_ALL_ROUTERS);
}
@Test
public void edPingsMeshLocalAddresses_oneReplyPerRequest() throws Exception {
mController.joinAndWait(DEFAULT_DATASET);
startFtdChild(mFtd, DEFAULT_DATASET);
List<Inet6Address> meshLocalAddresses = mOtCtl.getMeshLocalAddresses();
for (Inet6Address address : meshLocalAddresses) {
assertWithMessage(
"There may be duplicated replies of ping request to "
+ address.getHostAddress())
.that(mFtd.ping(address, 2))
.isEqualTo(2);
}
}
// TODO (b/323300829): add more tests for integration with linux platform and
// ConnectivityService

View file

@ -422,7 +422,21 @@ public final class FullThreadDevice {
PING_TIMEOUT_SECONDS);
}
private void ping(
/** Returns the number of ping reply packets received. */
public int ping(Inet6Address address, int count) {
List<String> output =
ping(
address,
null,
PING_SIZE,
count,
PING_INTERVAL,
HOP_LIMIT,
PING_TIMEOUT_SECONDS);
return getReceivedPacketsCount(output);
}
private List<String> ping(
Inet6Address address,
Inet6Address source,
int size,
@ -445,7 +459,21 @@ public final class FullThreadDevice {
+ hopLimit
+ " "
+ timeout;
executeCommand(cmd);
return executeCommand(cmd);
}
private int getReceivedPacketsCount(List<String> stringList) {
Pattern pattern = Pattern.compile("([\\d]+) packets received");
for (String message : stringList) {
Matcher matcher = pattern.matcher(message);
if (matcher.find()) {
String packetCountStr = matcher.group(1);
return Integer.parseInt(packetCountStr);
}
}
// No match found
return -1;
}
@FormatMethod