Merge "Add test coverage for ICMP echo constants." am: 718025ed2c

am: 0f6be092bb

Change-Id: I337e4723ed1af668067148a479b9b21f9f29c330
This commit is contained in:
Lorenzo Colitti
2019-04-01 08:41:45 -07:00
committed by android-build-merger
2 changed files with 17 additions and 6 deletions

View File

@@ -16,6 +16,11 @@
package com.android.cts.net.hostside;
import static android.system.OsConstants.ICMP6_ECHO_REPLY;
import static android.system.OsConstants.ICMP6_ECHO_REQUEST;
import static android.system.OsConstants.ICMP_ECHO;
import static android.system.OsConstants.ICMP_ECHOREPLY;
import android.system.ErrnoException;
import android.system.Os;
import android.util.Log;
@@ -47,8 +52,6 @@ public class PacketReflector extends Thread {
private static final byte ICMP_ECHO = 8;
private static final byte ICMP_ECHOREPLY = 0;
private static final byte ICMPV6_ECHO_REQUEST = (byte) 128;
private static final byte ICMPV6_ECHO_REPLY = (byte) 129;
private static String TAG = "PacketReflector";
@@ -125,7 +128,7 @@ public class PacketReflector extends Thread {
byte type = buf[hdrLen];
if (!(version == 4 && type == ICMP_ECHO) &&
!(version == 6 && type == ICMPV6_ECHO_REQUEST)) {
!(version == 6 && type == (byte) ICMP6_ECHO_REQUEST)) {
return;
}
@@ -145,10 +148,18 @@ public class PacketReflector extends Thread {
return;
}
byte replyType = buf[hdrLen];
if ((type == ICMP_ECHO && replyType != ICMP_ECHOREPLY)
|| (type == (byte) ICMP6_ECHO_REQUEST && replyType != (byte) ICMP6_ECHO_REPLY)) {
Log.i(TAG, "Received unexpected ICMP reply: original " + type
+ ", reply " + replyType);
return;
}
// Compare the response we got with the original packet.
// The only thing that should have changed are addresses, type and checksum.
// Overwrite them with the received bytes and see if the packet is otherwise identical.
request[hdrLen] = buf[hdrLen]; // Type.
request[hdrLen] = buf[hdrLen]; // Type
request[hdrLen + 2] = buf[hdrLen + 2]; // Checksum byte 1.
request[hdrLen + 3] = buf[hdrLen + 3]; // Checksum byte 2.

View File

@@ -61,7 +61,7 @@ public class PingTest extends AndroidTestCase {
/** The beginning of an ICMPv6 echo request: type, code, and uninitialized checksum. */
private static final byte[] PING_HEADER = new byte[] {
(byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x00
(byte) ICMP6_ECHO_REQUEST, (byte) 0x00, (byte) 0x00, (byte) 0x00
};
/**
@@ -135,7 +135,7 @@ public class PingTest extends AndroidTestCase {
byte[] response = new byte[bytesRead];
responseBuffer.flip();
responseBuffer.get(response, 0, bytesRead);
assertEquals((byte) 0x81, response[0]);
assertEquals((byte) ICMP6_ECHO_REPLY, response[0]);
// Find out what ICMP ID was used in the packet that was sent.
int id = ((InetSocketAddress) Os.getsockname(s)).getPort();