Merge "[TestOnly] Replace isRouterAdvertisement with isIcmpv6Type" am: 4fcf168399
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2116177 Change-Id: Idf8f6a064cd09a912c1b2e0e1e2cec5db33fee8d Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -28,7 +28,6 @@ import static android.net.TetheringManager.CONNECTIVITY_SCOPE_LOCAL;
|
|||||||
import static android.net.TetheringManager.TETHERING_ETHERNET;
|
import static android.net.TetheringManager.TETHERING_ETHERNET;
|
||||||
import static android.net.TetheringTester.RemoteResponder;
|
import static android.net.TetheringTester.RemoteResponder;
|
||||||
import static android.net.TetheringTester.isIcmpv6Type;
|
import static android.net.TetheringTester.isIcmpv6Type;
|
||||||
import static android.system.OsConstants.IPPROTO_ICMPV6;
|
|
||||||
import static android.system.OsConstants.IPPROTO_IP;
|
import static android.system.OsConstants.IPPROTO_IP;
|
||||||
import static android.system.OsConstants.IPPROTO_IPV6;
|
import static android.system.OsConstants.IPPROTO_IPV6;
|
||||||
import static android.system.OsConstants.IPPROTO_UDP;
|
import static android.system.OsConstants.IPPROTO_UDP;
|
||||||
@@ -85,7 +84,6 @@ import com.android.net.module.util.bpf.Tether4Value;
|
|||||||
import com.android.net.module.util.bpf.TetherStatsKey;
|
import com.android.net.module.util.bpf.TetherStatsKey;
|
||||||
import com.android.net.module.util.bpf.TetherStatsValue;
|
import com.android.net.module.util.bpf.TetherStatsValue;
|
||||||
import com.android.net.module.util.structs.EthernetHeader;
|
import com.android.net.module.util.structs.EthernetHeader;
|
||||||
import com.android.net.module.util.structs.Icmpv6Header;
|
|
||||||
import com.android.net.module.util.structs.Ipv4Header;
|
import com.android.net.module.util.structs.Ipv4Header;
|
||||||
import com.android.net.module.util.structs.Ipv6Header;
|
import com.android.net.module.util.structs.Ipv6Header;
|
||||||
import com.android.net.module.util.structs.UdpHeader;
|
import com.android.net.module.util.structs.UdpHeader;
|
||||||
@@ -146,6 +144,7 @@ public class EthernetTetheringTest {
|
|||||||
// Per TX UDP packet size: ethhdr (14) + iphdr (20) + udphdr (8) + payload (2) = 44 bytes.
|
// Per TX UDP packet size: ethhdr (14) + iphdr (20) + udphdr (8) + payload (2) = 44 bytes.
|
||||||
private static final int TX_UDP_PACKET_SIZE = 44;
|
private static final int TX_UDP_PACKET_SIZE = 44;
|
||||||
private static final int TX_UDP_PACKET_COUNT = 123;
|
private static final int TX_UDP_PACKET_COUNT = 123;
|
||||||
|
private static final long WAIT_RA_TIMEOUT_MS = 2000;
|
||||||
|
|
||||||
private static final LinkAddress TEST_IP4_ADDR = new LinkAddress("10.0.0.1/8");
|
private static final LinkAddress TEST_IP4_ADDR = new LinkAddress("10.0.0.1/8");
|
||||||
private static final LinkAddress TEST_IP6_ADDR = new LinkAddress("2001:db8:1::101/64");
|
private static final LinkAddress TEST_IP6_ADDR = new LinkAddress("2001:db8:1::101/64");
|
||||||
@@ -329,27 +328,13 @@ public class EthernetTetheringTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isRouterAdvertisement(byte[] pkt) {
|
private static void waitForRouterAdvertisement(TapPacketReader reader, String iface,
|
||||||
if (pkt == null) return false;
|
|
||||||
|
|
||||||
ByteBuffer buf = ByteBuffer.wrap(pkt);
|
|
||||||
|
|
||||||
final EthernetHeader ethHdr = Struct.parse(EthernetHeader.class, buf);
|
|
||||||
if (ethHdr.etherType != ETHER_TYPE_IPV6) return false;
|
|
||||||
|
|
||||||
final Ipv6Header ipv6Hdr = Struct.parse(Ipv6Header.class, buf);
|
|
||||||
if (ipv6Hdr.nextHeader != (byte) IPPROTO_ICMPV6) return false;
|
|
||||||
|
|
||||||
final Icmpv6Header icmpv6Hdr = Struct.parse(Icmpv6Header.class, buf);
|
|
||||||
return icmpv6Hdr.type == (short) ICMPV6_ROUTER_ADVERTISEMENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void expectRouterAdvertisement(TapPacketReader reader, String iface,
|
|
||||||
long timeoutMs) {
|
long timeoutMs) {
|
||||||
final long deadline = SystemClock.uptimeMillis() + timeoutMs;
|
final long deadline = SystemClock.uptimeMillis() + timeoutMs;
|
||||||
do {
|
do {
|
||||||
byte[] pkt = reader.popPacket(timeoutMs);
|
byte[] pkt = reader.popPacket(timeoutMs);
|
||||||
if (isRouterAdvertisement(pkt)) return;
|
if (isIcmpv6Type(pkt, true /* hasEth */, ICMPV6_ROUTER_ADVERTISEMENT)) return;
|
||||||
|
|
||||||
timeoutMs = deadline - SystemClock.uptimeMillis();
|
timeoutMs = deadline - SystemClock.uptimeMillis();
|
||||||
} while (timeoutMs > 0);
|
} while (timeoutMs > 0);
|
||||||
fail("Did not receive router advertisement on " + iface + " after "
|
fail("Did not receive router advertisement on " + iface + " after "
|
||||||
@@ -401,7 +386,7 @@ public class EthernetTetheringTest {
|
|||||||
// before the reader is started.
|
// before the reader is started.
|
||||||
mDownstreamReader = makePacketReader(mDownstreamIface);
|
mDownstreamReader = makePacketReader(mDownstreamIface);
|
||||||
|
|
||||||
expectRouterAdvertisement(mDownstreamReader, iface, 2000 /* timeoutMs */);
|
waitForRouterAdvertisement(mDownstreamReader, iface, WAIT_RA_TIMEOUT_MS);
|
||||||
expectLocalOnlyAddresses(iface);
|
expectLocalOnlyAddresses(iface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user