VCN: Explicitly handle IAE from updating underlying network

IpSecTunnelInterface#setUnderlyingNetwork will throw IAE when the
underlying network is not functional and has null LinkProperties.
This commit updates VCN to explicitly handle this exception, instead
relying on the mechanism for handling all uncaught exceptions.

Bug: 240112879
Test: atest CtsVcnTestCases & FrameworksVcnTests
Change-Id: I2fdf1da542eb04d56a04e04c762f8c2c19828071
This commit is contained in:
Yan Yan
2023-06-16 22:23:41 +00:00
parent 232000e8b8
commit 947aaa4ab8
2 changed files with 29 additions and 1 deletions

View File

@@ -1889,7 +1889,7 @@ public class VcnGatewayConnection extends StateMachine {
mIpSecManager.applyTunnelModeTransform(
tunnelIface, IpSecManager.DIRECTION_FWD, transform);
}
} catch (IOException e) {
} catch (IOException | IllegalArgumentException e) {
logInfo("Transform application failed for network " + token, e);
sessionLost(token, e);
}

View File

@@ -42,6 +42,7 @@ import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.argThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
@@ -345,6 +346,33 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection
verify(mConnMgr).reportNetworkConnectivity(eq(mNetworkAgent.getNetwork()), eq(false));
}
@Test
public void testMigrationHandleFailure() throws Exception {
triggerChildOpened();
mTestLooper.dispatchAll();
assertEquals(mIkeConnectionInfo, mGatewayConnection.getIkeConnectionInfo());
mGatewayConnection
.getUnderlyingNetworkControllerCallback()
.onSelectedUnderlyingNetworkChanged(TEST_UNDERLYING_NETWORK_RECORD_2);
final IkeSessionConnectionInfo newIkeConnectionInfo =
new IkeSessionConnectionInfo(
TEST_ADDR_V4, TEST_ADDR_V4_2, TEST_UNDERLYING_NETWORK_RECORD_2.network);
getIkeSessionCallback().onIkeSessionConnectionInfoChanged(newIkeConnectionInfo);
getChildSessionCallback()
.onIpSecTransformsMigrated(makeDummyIpSecTransform(), makeDummyIpSecTransform());
doThrow(new IllegalArgumentException("testMigrationHandleFailure"))
.when(mIpSecSvc)
.setNetworkForTunnelInterface(anyInt(), any(), any());
mTestLooper.dispatchAll();
assertEquals(mGatewayConnection.mDisconnectingState, mGatewayConnection.getCurrentState());
verify(mIkeSession).close();
}
private void triggerChildOpened() {
triggerChildOpened(Collections.singletonList(TEST_INTERNAL_ADDR), TEST_DNS_ADDR);
}