Add the NAT64 prefix to LinkProperties.

Currently we support exactly one NAT64 prefix. This matches what
other components in the system (Dns64Configuration, clatd, etc.)
support.

Test: atest FrameworksNetTests
Change-Id: I45a11cebe43a5e1c60d50eca7889cb317565b598
This commit is contained in:
Lorenzo Colitti
2019-01-08 09:58:59 +09:00
parent 6dd2486300
commit 981b34f6b8
2 changed files with 92 additions and 6 deletions

View File

@@ -18,6 +18,7 @@ package android.net;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -33,6 +34,9 @@ import android.support.test.runner.AndroidJUnit4;
import android.system.OsConstants;
import android.util.ArraySet;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Arrays;
@@ -41,9 +45,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Set;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class LinkPropertiesTest {
@@ -503,6 +504,40 @@ public class LinkPropertiesTest {
assertTrue(lp.equals(lp));
}
@Test
public void testNat64Prefix() throws Exception {
LinkProperties lp = new LinkProperties();
lp.addLinkAddress(LINKADDRV4);
lp.addLinkAddress(LINKADDRV6);
assertNull(lp.getNat64Prefix());
IpPrefix p = new IpPrefix("64:ff9b::/96");
lp.setNat64Prefix(p);
assertEquals(p, lp.getNat64Prefix());
p = new IpPrefix("2001:db8:a:b:1:2:3::/96");
lp.setNat64Prefix(p);
assertEquals(p, lp.getNat64Prefix());
p = new IpPrefix("2001:db8:a:b:1:2::/80");
try {
lp.setNat64Prefix(p);
} catch (IllegalArgumentException expected) {
}
p = new IpPrefix("64:ff9b::/64");
try {
lp.setNat64Prefix(p);
} catch (IllegalArgumentException expected) {
}
assertEquals(new IpPrefix("2001:db8:a:b:1:2:3::/96"), lp.getNat64Prefix());
lp.setNat64Prefix(null);
assertNull(lp.getNat64Prefix());
}
@Test
public void testIsProvisioned() {
LinkProperties lp4 = new LinkProperties();
@@ -815,7 +850,7 @@ public class LinkPropertiesTest {
}
@Test
public void testLinkPropertiesParcelable() {
public void testLinkPropertiesParcelable() throws Exception {
LinkProperties source = new LinkProperties();
source.setInterfaceName(NAME);
// set 2 link addresses
@@ -833,6 +868,8 @@ public class LinkPropertiesTest {
source.setMtu(MTU);
source.setNat64Prefix(new IpPrefix("2001:db8:1:2:64:64::/96"));
Parcel p = Parcel.obtain();
source.writeToParcel(p, /* flags */ 0);
p.setDataPosition(0);