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