Search in sources :

Example 41 with LinkProperties

use of android.net.LinkProperties in project android_frameworks_base by ResurrectionRemix.

the class LinkPropertiesTest method testEqualsNull.

@SmallTest
public void testEqualsNull() {
    LinkProperties source = new LinkProperties();
    LinkProperties target = new LinkProperties();
    assertFalse(source == target);
    assertLinkPropertiesEqual(source, target);
}
Also used : LinkProperties(android.net.LinkProperties) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 42 with LinkProperties

use of android.net.LinkProperties in project android_frameworks_base by ResurrectionRemix.

the class LinkPropertiesTest method testIsProvisioned.

@SmallTest
public void testIsProvisioned() {
    LinkProperties lp4 = new LinkProperties();
    assertFalse("v4only:empty", lp4.isProvisioned());
    lp4.addLinkAddress(LINKADDRV4);
    assertFalse("v4only:addr-only", lp4.isProvisioned());
    lp4.addDnsServer(DNS1);
    assertFalse("v4only:addr+dns", lp4.isProvisioned());
    lp4.addRoute(new RouteInfo(GATEWAY1));
    assertTrue("v4only:addr+dns+route", lp4.isProvisioned());
    assertTrue("v4only:addr+dns+route", lp4.isIPv4Provisioned());
    assertFalse("v4only:addr+dns+route", lp4.isIPv6Provisioned());
    LinkProperties lp6 = new LinkProperties();
    assertFalse("v6only:empty", lp6.isProvisioned());
    lp6.addLinkAddress(LINKADDRV6LINKLOCAL);
    assertFalse("v6only:fe80-only", lp6.isProvisioned());
    lp6.addDnsServer(DNS6);
    assertFalse("v6only:fe80+dns", lp6.isProvisioned());
    lp6.addRoute(new RouteInfo(GATEWAY61));
    assertFalse("v6only:fe80+dns+route", lp6.isProvisioned());
    lp6.addLinkAddress(LINKADDRV6);
    assertTrue("v6only:fe80+global+dns+route", lp6.isIPv6Provisioned());
    assertTrue("v6only:fe80+global+dns+route", lp6.isProvisioned());
    lp6.removeLinkAddress(LINKADDRV6LINKLOCAL);
    assertFalse("v6only:global+dns+route", lp6.isIPv4Provisioned());
    assertTrue("v6only:global+dns+route", lp6.isIPv6Provisioned());
    assertTrue("v6only:global+dns+route", lp6.isProvisioned());
    LinkProperties lp46 = new LinkProperties();
    lp46.addLinkAddress(LINKADDRV4);
    lp46.addLinkAddress(LINKADDRV6);
    lp46.addDnsServer(DNS1);
    lp46.addDnsServer(DNS6);
    assertFalse("dualstack:missing-routes", lp46.isProvisioned());
    lp46.addRoute(new RouteInfo(GATEWAY1));
    assertTrue("dualstack:v4-provisioned", lp46.isIPv4Provisioned());
    assertFalse("dualstack:v4-provisioned", lp46.isIPv6Provisioned());
    assertTrue("dualstack:v4-provisioned", lp46.isProvisioned());
    lp46.addRoute(new RouteInfo(GATEWAY61));
    assertTrue("dualstack:both-provisioned", lp46.isIPv4Provisioned());
    assertTrue("dualstack:both-provisioned", lp46.isIPv6Provisioned());
    assertTrue("dualstack:both-provisioned", lp46.isProvisioned());
    // A link with an IPv6 address and default route, but IPv4 DNS server.
    LinkProperties mixed = new LinkProperties();
    mixed.addLinkAddress(LINKADDRV6);
    mixed.addDnsServer(DNS1);
    mixed.addRoute(new RouteInfo(GATEWAY61));
    assertFalse("mixed:addr6+route6+dns4", mixed.isIPv4Provisioned());
    assertFalse("mixed:addr6+route6+dns4", mixed.isIPv6Provisioned());
    assertFalse("mixed:addr6+route6+dns4", mixed.isProvisioned());
}
Also used : RouteInfo(android.net.RouteInfo) LinkProperties(android.net.LinkProperties) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 43 with LinkProperties

use of android.net.LinkProperties in project android_frameworks_base by ResurrectionRemix.

the class LinkPropertiesTest method testStackedInterfaces.

@SmallTest
public void testStackedInterfaces() {
    LinkProperties rmnet0 = new LinkProperties();
    rmnet0.setInterfaceName("rmnet0");
    rmnet0.addLinkAddress(LINKADDRV6);
    LinkProperties clat4 = new LinkProperties();
    clat4.setInterfaceName("clat4");
    clat4.addLinkAddress(LINKADDRV4);
    assertEquals(0, rmnet0.getStackedLinks().size());
    assertEquals(1, rmnet0.getAddresses().size());
    assertEquals(1, rmnet0.getLinkAddresses().size());
    assertEquals(1, rmnet0.getAllAddresses().size());
    assertEquals(1, rmnet0.getAllLinkAddresses().size());
    rmnet0.addStackedLink(clat4);
    assertEquals(1, rmnet0.getStackedLinks().size());
    assertEquals(1, rmnet0.getAddresses().size());
    assertEquals(1, rmnet0.getLinkAddresses().size());
    assertEquals(2, rmnet0.getAllAddresses().size());
    assertEquals(2, rmnet0.getAllLinkAddresses().size());
    rmnet0.addStackedLink(clat4);
    assertEquals(1, rmnet0.getStackedLinks().size());
    assertEquals(1, rmnet0.getAddresses().size());
    assertEquals(1, rmnet0.getLinkAddresses().size());
    assertEquals(2, rmnet0.getAllAddresses().size());
    assertEquals(2, rmnet0.getAllLinkAddresses().size());
    assertEquals(0, clat4.getStackedLinks().size());
    // Modify an item in the returned collection to see what happens.
    for (LinkProperties link : rmnet0.getStackedLinks()) {
        if (link.getInterfaceName().equals("clat4")) {
            link.setInterfaceName("newname");
        }
    }
    for (LinkProperties link : rmnet0.getStackedLinks()) {
        assertFalse("newname".equals(link.getInterfaceName()));
    }
    assertTrue(rmnet0.removeStackedLink("clat4"));
    assertEquals(0, rmnet0.getStackedLinks().size());
    assertEquals(1, rmnet0.getAddresses().size());
    assertEquals(1, rmnet0.getLinkAddresses().size());
    assertEquals(1, rmnet0.getAllAddresses().size());
    assertEquals(1, rmnet0.getAllLinkAddresses().size());
    assertFalse(rmnet0.removeStackedLink("clat4"));
}
Also used : LinkProperties(android.net.LinkProperties) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 44 with LinkProperties

use of android.net.LinkProperties in project android_frameworks_base by ResurrectionRemix.

the class Nat464Xlat method interfaceLinkStateChanged.

@Override
public void interfaceLinkStateChanged(String iface, boolean up) {
    // Called by the InterfaceObserver on its own thread, so can race with stop().
    if (isStarted() && up && mIface.equals(iface)) {
        Slog.i(TAG, "interface " + iface + " is up, mIsRunning " + mIsRunning + "->true");
        if (!mIsRunning) {
            LinkAddress clatAddress = getLinkAddress(iface);
            if (clatAddress == null) {
                return;
            }
            mIsRunning = true;
            maybeSetIpv6NdOffload(mBaseIface, false);
            LinkProperties lp = new LinkProperties(mNetwork.linkProperties);
            lp.addStackedLink(makeLinkProperties(clatAddress));
            Slog.i(TAG, "Adding stacked link " + mIface + " on top of " + mBaseIface);
            updateConnectivityService(lp);
        }
    }
}
Also used : LinkAddress(android.net.LinkAddress) LinkProperties(android.net.LinkProperties)

Example 45 with LinkProperties

use of android.net.LinkProperties in project android_frameworks_base by ResurrectionRemix.

the class Nat464Xlat method interfaceRemoved.

@Override
public void interfaceRemoved(String iface) {
    if (isStarted() && mIface.equals(iface)) {
        Slog.i(TAG, "interface " + iface + " removed, mIsRunning " + mIsRunning + "->false");
        if (mIsRunning) {
            // stopClatd() will just throw IllegalStateException, which we'll ignore.
            try {
                mNMService.unregisterObserver(this);
                mNMService.stopClatd(mBaseIface);
            } catch (RemoteException | IllegalStateException e) {
            // Well, we tried.
            }
            maybeSetIpv6NdOffload(mBaseIface, true);
            LinkProperties lp = new LinkProperties(mNetwork.linkProperties);
            lp.removeStackedLink(mIface);
            clear();
            updateConnectivityService(lp);
        }
    }
}
Also used : RemoteException(android.os.RemoteException) LinkProperties(android.net.LinkProperties)

Aggregations

LinkProperties (android.net.LinkProperties)330 LinkAddress (android.net.LinkAddress)78 RouteInfo (android.net.RouteInfo)73 SmallTest (android.test.suitebuilder.annotation.SmallTest)68 InetAddress (java.net.InetAddress)56 Network (android.net.Network)43 NetworkInfo (android.net.NetworkInfo)40 NetworkAgentInfo (com.android.server.connectivity.NetworkAgentInfo)40 RemoteException (android.os.RemoteException)37 NetworkState (android.net.NetworkState)36 NetworkCapabilities (android.net.NetworkCapabilities)25 NetworkRequest (android.net.NetworkRequest)22 ArrayList (java.util.ArrayList)22 ProvisioningChange (android.net.LinkProperties.ProvisioningChange)20 Test (org.junit.Test)19 ConnectivityManager (android.net.ConnectivityManager)17 IpPrefix (android.net.IpPrefix)15 Inet6Address (java.net.Inet6Address)15 UnknownHostException (java.net.UnknownHostException)13 ApfFilter (android.net.apf.ApfFilter)12