[Thread] add an integration test case for NAT64
This CL adds an integration test case for NAT64. Because the feature is not fully ready, we need some extra setup steps to make the feature work. That is, specifying a CIDR for NAT64. Also, this test case is based on `ot-ctl` but eventually the test should be based on API. This CL requires https://github.com/openthread/openthread/pull/10566. Bug: 356770473 Test: atest ThreadNetworkIntegrationTests Change-Id: Idfb5ad848f7b2369591e47558ea67017c0b31e19
This commit is contained in:
parent
09e71714fb
commit
d38b7cb30f
2 changed files with 47 additions and 5 deletions
|
|
@ -619,17 +619,36 @@ public class BorderRoutingTest {
|
|||
ICMPV6_ECHO_REQUEST_TYPE, ftdOmr, GROUP_ADDR_SCOPE_4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nat64_threadDevicePingIpv4InfraDevice_outboundPacketIsForwarded() throws Exception {
|
||||
FullThreadDevice ftd = mFtds.get(0);
|
||||
joinNetworkAndWaitForOmr(ftd, DEFAULT_DATASET);
|
||||
// TODO: enable NAT64 via ThreadNetworkController API instead of ot-ctl
|
||||
mOtCtl.setNat64Cidr(NAT64_CIDR);
|
||||
mOtCtl.setNat64Enabled(true);
|
||||
waitFor(() -> mOtCtl.hasNat64PrefixInNetdata(), Duration.ofSeconds(10));
|
||||
|
||||
ftd.ping(IPV4_SERVER_ADDR);
|
||||
|
||||
assertNotNull(pollForIcmpPacketOnInfraNetwork(ICMP_ECHO, null, IPV4_SERVER_ADDR));
|
||||
}
|
||||
|
||||
private void setUpInfraNetwork() throws Exception {
|
||||
LinkProperties lp = new LinkProperties();
|
||||
// NAT64 feature requires the infra network to have an IPv4 default route.
|
||||
lp.addRoute(
|
||||
new RouteInfo(
|
||||
new IpPrefix("0.0.0.0/0") /* destination */,
|
||||
null /* gateway */,
|
||||
null,
|
||||
RouteInfo.RTN_UNICAST,
|
||||
1500 /* mtu */));
|
||||
mInfraNetworkTracker =
|
||||
runAsShell(
|
||||
MANAGE_TEST_NETWORKS,
|
||||
() ->
|
||||
initTestNetwork(
|
||||
mContext, new LinkProperties(), 5000 /* timeoutMs */));
|
||||
mController.setTestNetworkAsUpstreamAndWait(
|
||||
mInfraNetworkTracker.getTestIface().getInterfaceName());
|
||||
() -> initTestNetwork(mContext, lp, 5000 /* timeoutMs */));
|
||||
String infraNetworkName = mInfraNetworkTracker.getTestIface().getInterfaceName();
|
||||
mController.setTestNetworkAsUpstreamAndWait(infraNetworkName);
|
||||
}
|
||||
|
||||
private void tearDownInfraNetwork() {
|
||||
|
|
|
|||
|
|
@ -105,6 +105,29 @@ public final class OtDaemonController {
|
|||
return prefixes.isEmpty() ? null : prefixes.get(0);
|
||||
}
|
||||
|
||||
/** Enables/Disables NAT64 feature. */
|
||||
public void setNat64Enabled(boolean enabled) {
|
||||
executeCommand("nat64 " + (enabled ? "enable" : "disable"));
|
||||
}
|
||||
|
||||
/** Sets the NAT64 CIDR. */
|
||||
public void setNat64Cidr(String cidr) {
|
||||
executeCommand("nat64 cidr " + cidr);
|
||||
}
|
||||
|
||||
/** Returns whether there's a NAT64 prefix in network data */
|
||||
public boolean hasNat64PrefixInNetdata() {
|
||||
// Example (in the 'Routes' section):
|
||||
// fdb2:bae3:5b59:2:0:0::/96 sn low c000
|
||||
List<String> outputLines = executeCommandAndParse("netdata show");
|
||||
for (String line : outputLines) {
|
||||
if (line.contains(" sn")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String executeCommand(String cmd) {
|
||||
return SystemUtil.runShellCommand(OT_CTL + " " + cmd);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue