Add a new API to get the network ID range of IPSec tunnel interface
- Add a new API to get the network ID range of IPSec tunnel interface. - Use the new API in IpSecServiceTest to make sure the result is the same. Follow-up commit will change the logic in IpSecService#reserveNetId(), the modified test can ensure the correctness of the new change. Bug: 172183305 Test: atest FrameworksNetTests:IpSecServiceTest Change-Id: Ic605e48941fc9d6482cdcd01a8adcdc9b6d586a6
This commit is contained in:
@@ -35,6 +35,7 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.INetd;
|
||||
import android.net.IpSecAlgorithm;
|
||||
import android.net.IpSecConfig;
|
||||
@@ -47,6 +48,7 @@ import android.os.Process;
|
||||
import android.system.ErrnoException;
|
||||
import android.system.Os;
|
||||
import android.system.StructStat;
|
||||
import android.util.Range;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
@@ -647,9 +649,9 @@ public class IpSecServiceTest {
|
||||
|
||||
@Test
|
||||
public void testReserveNetId() {
|
||||
int start = mIpSecService.TUN_INTF_NETID_START;
|
||||
for (int i = 0; i < mIpSecService.TUN_INTF_NETID_RANGE; i++) {
|
||||
assertEquals(start + i, mIpSecService.reserveNetId());
|
||||
final Range<Integer> netIdRange = ConnectivityManager.getIpSecNetIdRange();
|
||||
for (int netId = netIdRange.getLower(); netId <= netIdRange.getUpper(); netId++) {
|
||||
assertEquals(netId, mIpSecService.reserveNetId());
|
||||
}
|
||||
|
||||
// Check that resource exhaustion triggers an exception
|
||||
@@ -661,7 +663,7 @@ public class IpSecServiceTest {
|
||||
|
||||
// Now release one and try again
|
||||
int releasedNetId =
|
||||
mIpSecService.TUN_INTF_NETID_START + mIpSecService.TUN_INTF_NETID_RANGE / 2;
|
||||
netIdRange.getLower() + (netIdRange.getUpper() - netIdRange.getLower()) / 2;
|
||||
mIpSecService.releaseNetId(releasedNetId);
|
||||
assertEquals(releasedNetId, mIpSecService.reserveNetId());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user