Merge "Make the Nat464Xlat tests more realistic." am: 6ce7a2aeee am: 3da6384b41
Change-Id: Ib8d91c81af3d2e5d03c0fd47f415ff93fee5e2aa
This commit is contained in:
@@ -58,6 +58,7 @@ public class Nat464XlatTest {
|
||||
|
||||
static final String BASE_IFACE = "test0";
|
||||
static final String STACKED_IFACE = "v4-test0";
|
||||
static final LinkAddress V6ADDR = new LinkAddress("2001:db8:1::f00/64");
|
||||
static final LinkAddress ADDR = new LinkAddress("192.0.2.5/29");
|
||||
static final String NAT64_PREFIX = "64:ff9b::/96";
|
||||
static final String OTHER_NAT64_PREFIX = "2001:db8:0:64::/96";
|
||||
@@ -82,6 +83,14 @@ public class Nat464XlatTest {
|
||||
};
|
||||
}
|
||||
|
||||
private void markNetworkConnected() {
|
||||
mNai.networkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, "", "");
|
||||
}
|
||||
|
||||
private void markNetworkDisconnected() {
|
||||
mNai.networkInfo.setDetailedState(NetworkInfo.DetailedState.DISCONNECTED, "", "");
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mLooper = new TestLooper();
|
||||
@@ -93,6 +102,7 @@ public class Nat464XlatTest {
|
||||
mNai.linkProperties.setInterfaceName(BASE_IFACE);
|
||||
mNai.networkInfo = new NetworkInfo(null);
|
||||
mNai.networkInfo.setType(ConnectivityManager.TYPE_WIFI);
|
||||
markNetworkConnected();
|
||||
when(mNai.connService()).thenReturn(mConnectivity);
|
||||
when(mNai.netAgentConfig()).thenReturn(mAgentConfig);
|
||||
when(mNai.handler()).thenReturn(mHandler);
|
||||
@@ -177,11 +187,20 @@ public class Nat464XlatTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalStartAndStop() throws Exception {
|
||||
private void makeClatUnnecessary(boolean dueToDisconnect) {
|
||||
if (dueToDisconnect) {
|
||||
markNetworkDisconnected();
|
||||
} else {
|
||||
mNai.linkProperties.addLinkAddress(ADDR);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkNormalStartAndStop(boolean dueToDisconnect) throws Exception {
|
||||
Nat464Xlat nat = makeNat464Xlat();
|
||||
ArgumentCaptor<LinkProperties> c = ArgumentCaptor.forClass(LinkProperties.class);
|
||||
|
||||
mNai.linkProperties.addLinkAddress(V6ADDR);
|
||||
|
||||
nat.setNat64PrefixFromDns(new IpPrefix(NAT64_PREFIX));
|
||||
|
||||
// Start clat.
|
||||
@@ -201,6 +220,7 @@ public class Nat464XlatTest {
|
||||
assertRunning(nat);
|
||||
|
||||
// Stop clat (Network disconnects, IPv4 addr appears, ...).
|
||||
makeClatUnnecessary(dueToDisconnect);
|
||||
nat.stop();
|
||||
|
||||
verify(mNetd).clatdStop(eq(BASE_IFACE));
|
||||
@@ -218,11 +238,23 @@ public class Nat464XlatTest {
|
||||
verifyNoMoreInteractions(mNetd, mNms, mConnectivity);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalStartAndStopDueToDisconnect() throws Exception {
|
||||
checkNormalStartAndStop(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalStartAndStopDueToIpv4Addr() throws Exception {
|
||||
checkNormalStartAndStop(false);
|
||||
}
|
||||
|
||||
private void checkStartStopStart(boolean interfaceRemovedFirst) throws Exception {
|
||||
Nat464Xlat nat = makeNat464Xlat();
|
||||
ArgumentCaptor<LinkProperties> c = ArgumentCaptor.forClass(LinkProperties.class);
|
||||
InOrder inOrder = inOrder(mNetd, mConnectivity);
|
||||
|
||||
mNai.linkProperties.addLinkAddress(V6ADDR);
|
||||
|
||||
nat.setNat64PrefixFromDns(new IpPrefix(NAT64_PREFIX));
|
||||
|
||||
nat.start();
|
||||
@@ -345,10 +377,11 @@ public class Nat464XlatTest {
|
||||
verifyNoMoreInteractions(mNetd, mNms, mConnectivity);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStopBeforeClatdStarts() throws Exception {
|
||||
private void checkStopBeforeClatdStarts(boolean dueToDisconnect) throws Exception {
|
||||
Nat464Xlat nat = makeNat464Xlat();
|
||||
|
||||
mNai.linkProperties.addLinkAddress(new LinkAddress("2001:db8::1/64"));
|
||||
|
||||
nat.setNat64PrefixFromDns(new IpPrefix(NAT64_PREFIX));
|
||||
|
||||
nat.start();
|
||||
@@ -357,6 +390,7 @@ public class Nat464XlatTest {
|
||||
verify(mNetd).clatdStart(eq(BASE_IFACE), eq(NAT64_PREFIX));
|
||||
|
||||
// ConnectivityService immediately stops clat (Network disconnects, IPv4 addr appears, ...)
|
||||
makeClatUnnecessary(dueToDisconnect);
|
||||
nat.stop();
|
||||
|
||||
verify(mNetd).clatdStop(eq(BASE_IFACE));
|
||||
@@ -378,9 +412,20 @@ public class Nat464XlatTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStopAndClatdNeverStarts() throws Exception {
|
||||
public void testStopDueToDisconnectBeforeClatdStarts() throws Exception {
|
||||
checkStopBeforeClatdStarts(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStopDueToIpv4AddrBeforeClatdStarts() throws Exception {
|
||||
checkStopBeforeClatdStarts(false);
|
||||
}
|
||||
|
||||
private void checkStopAndClatdNeverStarts(boolean dueToDisconnect) throws Exception {
|
||||
Nat464Xlat nat = makeNat464Xlat();
|
||||
|
||||
mNai.linkProperties.addLinkAddress(new LinkAddress("2001:db8::1/64"));
|
||||
|
||||
nat.setNat64PrefixFromDns(new IpPrefix(NAT64_PREFIX));
|
||||
|
||||
nat.start();
|
||||
@@ -389,6 +434,7 @@ public class Nat464XlatTest {
|
||||
verify(mNetd).clatdStart(eq(BASE_IFACE), eq(NAT64_PREFIX));
|
||||
|
||||
// ConnectivityService immediately stops clat (Network disconnects, IPv4 addr appears, ...)
|
||||
makeClatUnnecessary(dueToDisconnect);
|
||||
nat.stop();
|
||||
|
||||
verify(mNetd).clatdStop(eq(BASE_IFACE));
|
||||
@@ -399,6 +445,16 @@ public class Nat464XlatTest {
|
||||
verifyNoMoreInteractions(mNetd, mNms, mConnectivity);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStopDueToDisconnectAndClatdNeverStarts() throws Exception {
|
||||
checkStopAndClatdNeverStarts(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStopDueToIpv4AddressAndClatdNeverStarts() throws Exception {
|
||||
checkStopAndClatdNeverStarts(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNat64PrefixPreference() throws Exception {
|
||||
final IpPrefix prefixFromDns = new IpPrefix(NAT64_PREFIX);
|
||||
|
||||
Reference in New Issue
Block a user