Fix the issue that border routing is unavailable when ot-daemon restarts
Bug: 325771342 Test: atest ThreadNetworkIntegrationTests:android.net.thread.BorderRoutingTest Change-Id: I60f41ef079167955d29d5e6f809ad2dd343c188b
This commit is contained in:
parent
978b3f2d9b
commit
aac3ef4da9
2 changed files with 64 additions and 20 deletions
|
|
@ -489,7 +489,14 @@ final class ThreadNetworkControllerService extends IThreadNetworkController.Stub
|
|||
@Override
|
||||
public void onAvailable(@NonNull Network network) {
|
||||
checkOnHandlerThread();
|
||||
Log.i(TAG, "Thread network available: " + network);
|
||||
Log.i(TAG, "Thread network is available: " + network);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLost(@NonNull Network network) {
|
||||
checkOnHandlerThread();
|
||||
Log.i(TAG, "Thread network is lost: " + network);
|
||||
disableBorderRouting();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -504,7 +511,7 @@ final class ThreadNetworkControllerService extends IThreadNetworkController.Stub
|
|||
+ localNetworkInfo
|
||||
+ "}");
|
||||
if (localNetworkInfo.getUpstreamNetwork() == null) {
|
||||
mUpstreamNetwork = null;
|
||||
disableBorderRouting();
|
||||
return;
|
||||
}
|
||||
if (!localNetworkInfo.getUpstreamNetwork().equals(mUpstreamNetwork)) {
|
||||
|
|
@ -936,23 +943,22 @@ final class ThreadNetworkControllerService extends IThreadNetworkController.Stub
|
|||
mBorderRouterConfig.isBorderRoutingEnabled = true;
|
||||
|
||||
mOtDaemon.configureBorderRouter(
|
||||
mBorderRouterConfig,
|
||||
new IOtStatusReceiver.Stub() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
Log.i(TAG, "configure border router successfully");
|
||||
}
|
||||
mBorderRouterConfig, new ConfigureBorderRouterStatusReceiver());
|
||||
} catch (RemoteException | IOException e) {
|
||||
Log.w(TAG, "Failed to enable border routing", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(int i, String s) {
|
||||
Log.w(
|
||||
TAG,
|
||||
String.format(
|
||||
"failed to configure border router: %d %s", i, s));
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "enableBorderRouting failed: " + e);
|
||||
private void disableBorderRouting() {
|
||||
mUpstreamNetwork = null;
|
||||
mBorderRouterConfig.infraInterfaceName = null;
|
||||
mBorderRouterConfig.infraInterfaceIcmp6Socket = null;
|
||||
mBorderRouterConfig.isBorderRoutingEnabled = false;
|
||||
try {
|
||||
mOtDaemon.configureBorderRouter(
|
||||
mBorderRouterConfig, new ConfigureBorderRouterStatusReceiver());
|
||||
} catch (RemoteException e) {
|
||||
Log.w(TAG, "Failed to disable border routing", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1073,6 +1079,20 @@ final class ThreadNetworkControllerService extends IThreadNetworkController.Stub
|
|||
}
|
||||
}
|
||||
|
||||
private static final class ConfigureBorderRouterStatusReceiver extends IOtStatusReceiver.Stub {
|
||||
public ConfigureBorderRouterStatusReceiver() {}
|
||||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
Log.i(TAG, "Configured border router successfully");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(int i, String s) {
|
||||
Log.w(TAG, String.format("Failed to configure border router: %d %s", i, s));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles and forwards Thread daemon callbacks. This class must be accessed from the thread of
|
||||
* {@code mHandler}.
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ public class BorderRoutingTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void unicastRouting_infraDevicePingTheadDeviceOmr_replyReceived() throws Exception {
|
||||
public void unicastRouting_infraDevicePingThreadDeviceOmr_replyReceived() throws Exception {
|
||||
/*
|
||||
* <pre>
|
||||
* Topology:
|
||||
|
|
@ -198,6 +198,30 @@ public class BorderRoutingTest {
|
|||
assertNotNull(pollForPacketOnInfraNetwork(ICMPV6_ECHO_REPLY_TYPE, null /* srcAddress */));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unicastRouting_afterFactoryResetInfraDevicePingThreadDeviceOmr_replyReceived()
|
||||
throws Exception {
|
||||
/*
|
||||
* <pre>
|
||||
* Topology:
|
||||
* infra network Thread
|
||||
* infra device -------------------- Border Router -------------- Full Thread device
|
||||
* (Cuttlefish)
|
||||
* </pre>
|
||||
*/
|
||||
|
||||
// Form the network.
|
||||
mOtCtl.factoryReset();
|
||||
startBrLeader();
|
||||
startInfraDevice();
|
||||
FullThreadDevice ftd = mFtds.get(0);
|
||||
startFtdChild(ftd);
|
||||
|
||||
mInfraDevice.sendEchoRequest(ftd.getOmrAddress());
|
||||
|
||||
assertNotNull(pollForPacketOnInfraNetwork(ICMPV6_ECHO_REPLY_TYPE, ftd.getOmrAddress()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unicastRouting_borderRouterSendsUdpToThreadDevice_datagramReceived()
|
||||
throws Exception {
|
||||
|
|
|
|||
Loading…
Reference in a new issue