summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormukesh agrawal <quiche@google.com>2016-04-01 11:27:30 -0700
committermukesh agrawal <quiche@google.com>2016-04-06 11:22:35 -0700
commit09b1d0786d05436d524d7556c269e665a0962ee6 (patch)
treed3f21b1e5b7291572c57742f33b4133d37b9b42e
parent3592af2adb0c30244a46db03164ca0f7e6d3b613 (diff)
WifiNative: add infrastructure for packet fates
1) Define the Java classes that the C++ code will copy packet fate information into. 2) Define the constants that will be used to represent fates. (This is needed to write readable tests for item 1.) 3) Declare the native methods on the Java side. (This is required for registerNatives to continue to work, after we add the new methods on the C++ side.) BUG=27528124 TEST=unit tests Change-Id: If0930f645f95e60c8cb471b10fcb740273159e05
-rw-r--r--service/java/com/android/server/wifi/WifiLoggerHal.java49
-rw-r--r--service/java/com/android/server/wifi/WifiNative.java43
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java39
3 files changed, 131 insertions, 0 deletions
diff --git a/service/java/com/android/server/wifi/WifiLoggerHal.java b/service/java/com/android/server/wifi/WifiLoggerHal.java
new file mode 100644
index 000000000..1d542b87d
--- /dev/null
+++ b/service/java/com/android/server/wifi/WifiLoggerHal.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.wifi;
+
+class WifiLoggerHal {
+ // Must match wifi_logger.h
+ static final int MAX_FATE_LOG_LEN = 32;
+
+ static final byte FRAME_TYPE_UNKNOWN = 0;
+ static final byte FRAME_TYPE_ETHERNET_II = 1;
+ static final byte FRAME_TYPE_80211_MGMT = 2;
+
+ static final byte TX_PKT_FATE_ACKED = 0;
+ static final byte TX_PKT_FATE_SENT = 1;
+ static final byte TX_PKT_FATE_FW_QUEUED = 2;
+ static final byte TX_PKT_FATE_FW_DROP_INVALID = 3;
+ static final byte TX_PKT_FATE_FW_DROP_NOBUFS = 4;
+ static final byte TX_PKT_FATE_FW_DROP_OTHER = 5;
+ static final byte TX_PKT_FATE_DRV_QUEUED = 6;
+ static final byte TX_PKT_FATE_DRV_DROP_INVALID = 7;
+ static final byte TX_PKT_FATE_DRV_DROP_NOBUFS = 9;
+ static final byte TX_PKT_FATE_DRV_DROP_OTHER = 10;
+
+ static final byte RX_PKT_FATE_SUCCESS = 0;
+ static final byte RX_PKT_FATE_FW_QUEUED = 1;
+ static final byte RX_PKT_FATE_FW_DROP_FILTER = 2;
+ static final byte RX_PKT_FATE_FW_DROP_INVALID = 3;
+ static final byte RX_PKT_FATE_FW_DROP_NOBUFS = 4;
+ static final byte RX_PKT_FATE_FW_DROP_OTHER = 5;
+ static final byte RX_PKT_FATE_DRV_QUEUED = 6;
+ static final byte RX_PKT_FATE_DRV_DROP_FILTER = 7;
+ static final byte RX_PKT_FATE_DRV_DROP_INVALID = 8;
+ static final byte RX_PKT_FATE_DRV_DROP_NOBUFS = 9;
+ static final byte RX_PKT_FATE_DRV_DROP_OTHER = 10;
+}
diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java
index 2c659ba3e..be77b9adb 100644
--- a/service/java/com/android/server/wifi/WifiNative.java
+++ b/service/java/com/android/server/wifi/WifiNative.java
@@ -44,6 +44,7 @@ import android.text.TextUtils;
import android.util.LocalLog;
import android.util.Log;
+import com.android.internal.annotations.Immutable;
import com.android.server.connectivity.KeepalivePacketData;
import com.android.server.wifi.hotspot2.NetworkDetail;
import com.android.server.wifi.hotspot2.SupplicantBridge;
@@ -2772,6 +2773,48 @@ public class WifiNative {
}
//---------------------------------------------------------------------------------
+ /* Packet fate API */
+
+ @Immutable
+ abstract static class FateReport {
+ final byte mFate;
+ final long mDriverTimestampUSec;
+ final byte mFrameType;
+ final byte[] mFrameBytes;
+
+ FateReport(byte fate, long driverTimestampUSec, byte frameType, byte[] frameBytes) {
+ mFate = fate;
+ mDriverTimestampUSec = driverTimestampUSec;
+ mFrameType = frameType;
+ mFrameBytes = frameBytes;
+ }
+ }
+
+ /**
+ * Represents the fate information for one outbound packet.
+ */
+ @Immutable
+ public static final class TxFateReport extends FateReport {
+ TxFateReport(byte fate, long driverTimestampUSec, byte frameType, byte[] frameBytes) {
+ super(fate, driverTimestampUSec, frameType, frameBytes);
+ }
+ }
+
+ /**
+ * Represents the fate information for one inbound packet.
+ */
+ @Immutable
+ public static final class RxFateReport extends FateReport {
+ RxFateReport(byte fate, long driverTimestampUSec, byte frameType, byte[] frameBytes) {
+ super(fate, driverTimestampUSec, frameType, frameBytes);
+ }
+ }
+
+ private static native int startPktFateMonitoringNative(int iface);
+ private static native int getTxPktFatesNative(int iface, TxFateReport[] reportBufs);
+ private static native int getRxPktFatesNative(int iface, RxFateReport[] reportBufs);
+
+ //---------------------------------------------------------------------------------
/* Configure ePNO/PNO */
private static PnoEventHandler sPnoEventHandler;
private static int sPnoCmdId = 0;
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java
index 4c94bc524..afcc73e2b 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java
@@ -16,6 +16,7 @@
package com.android.server.wifi;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.anyInt;
@@ -81,4 +82,42 @@ public class WifiNativeTest {
mWifiNative.getNetworkExtra(NETWORK_ID, NETWORK_EXTRAS_VARIABLE);
assertEquals(NETWORK_EXTRAS_VALUES, actualValues);
}
+
+ /**
+ * Verifies that TxFateReport's constructor sets all of the TxFateReport fields.
+ */
+ @Test
+ public void testTxFateReportCtorSetsFields() {
+ long driverTimestampUSec = 12345;
+ byte[] frameBytes = new byte[] {'a', 'b', 0, 'c'};
+ WifiNative.TxFateReport fateReport = new WifiNative.TxFateReport(
+ WifiLoggerHal.TX_PKT_FATE_SENT, // non-zero value
+ driverTimestampUSec,
+ WifiLoggerHal.FRAME_TYPE_ETHERNET_II, // non-zero value
+ frameBytes
+ );
+ assertEquals(WifiLoggerHal.TX_PKT_FATE_SENT, fateReport.mFate);
+ assertEquals(driverTimestampUSec, fateReport.mDriverTimestampUSec);
+ assertEquals(WifiLoggerHal.FRAME_TYPE_ETHERNET_II, fateReport.mFrameType);
+ assertArrayEquals(frameBytes, fateReport.mFrameBytes);
+ }
+
+ /**
+ * Verifies that RxFateReport's constructor sets all of the RxFateReport fields.
+ */
+ @Test
+ public void testRxFateReportCtorSetsFields() {
+ long driverTimestampUSec = 12345;
+ byte[] frameBytes = new byte[] {'a', 'b', 0, 'c'};
+ WifiNative.RxFateReport fateReport = new WifiNative.RxFateReport(
+ WifiLoggerHal.RX_PKT_FATE_FW_DROP_INVALID, // non-zero value
+ driverTimestampUSec,
+ WifiLoggerHal.FRAME_TYPE_ETHERNET_II, // non-zero value
+ frameBytes
+ );
+ assertEquals(WifiLoggerHal.RX_PKT_FATE_FW_DROP_INVALID, fateReport.mFate);
+ assertEquals(driverTimestampUSec, fateReport.mDriverTimestampUSec);
+ assertEquals(WifiLoggerHal.FRAME_TYPE_ETHERNET_II, fateReport.mFrameType);
+ assertArrayEquals(frameBytes, fateReport.mFrameBytes);
+ }
}