replace TetherStatsKey with S32
(mostly autogenerated, with minor tweaks to make it build) Test: TreeHugger Flag: EXEMPT mainline Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I5a5ba231cb38886b9b681b4c08d89a18ad418f23
This commit is contained in:
parent
79c5a7494b
commit
b5f97280d6
5 changed files with 25 additions and 59 deletions
|
|
@ -36,7 +36,6 @@ import com.android.net.module.util.SharedLog;
|
|||
import com.android.net.module.util.Struct.S32;
|
||||
import com.android.net.module.util.bpf.Tether4Key;
|
||||
import com.android.net.module.util.bpf.Tether4Value;
|
||||
import com.android.net.module.util.bpf.TetherStatsKey;
|
||||
import com.android.net.module.util.bpf.TetherStatsValue;
|
||||
import com.android.networkstack.tethering.BpfCoordinator.Dependencies;
|
||||
import com.android.networkstack.tethering.BpfCoordinator.Ipv6DownstreamRule;
|
||||
|
|
@ -83,7 +82,7 @@ public class BpfCoordinatorShimImpl
|
|||
|
||||
// BPF map of tethering statistics of the upstream interface since tethering startup.
|
||||
@Nullable
|
||||
private final IBpfMap<TetherStatsKey, TetherStatsValue> mBpfStatsMap;
|
||||
private final IBpfMap<S32, TetherStatsValue> mBpfStatsMap;
|
||||
|
||||
// BPF map of per-interface quota for tethering offload.
|
||||
@Nullable
|
||||
|
|
@ -250,7 +249,7 @@ public class BpfCoordinatorShimImpl
|
|||
try {
|
||||
// The reported tether stats are total data usage for all currently-active upstream
|
||||
// interfaces since tethering start.
|
||||
mBpfStatsMap.forEach((key, value) -> tetherStatsList.put((int) key.ifindex, value));
|
||||
mBpfStatsMap.forEach((key, value) -> tetherStatsList.put((int) key.val, value));
|
||||
} catch (ErrnoException e) {
|
||||
mLog.e("Fail to fetch tethering stats from BPF map: ", e);
|
||||
return null;
|
||||
|
|
@ -267,7 +266,7 @@ public class BpfCoordinatorShimImpl
|
|||
TetherStatsValue statsValue = null;
|
||||
|
||||
try {
|
||||
statsValue = mBpfStatsMap.getValue(new TetherStatsKey(ifIndex));
|
||||
statsValue = mBpfStatsMap.getValue(new S32(ifIndex));
|
||||
} catch (ErrnoException e) {
|
||||
// The BpfMap#getValue doesn't throw an errno ENOENT exception. Catch other error
|
||||
// while trying to get stats entry.
|
||||
|
|
@ -285,7 +284,7 @@ public class BpfCoordinatorShimImpl
|
|||
// This function is the *only* thing that can create entries.
|
||||
// BpfMap#insertEntry use BPF_NOEXIST to create the entry. The entry is created
|
||||
// if and only if it doesn't exist.
|
||||
mBpfStatsMap.insertEntry(new TetherStatsKey(ifIndex), new TetherStatsValue(
|
||||
mBpfStatsMap.insertEntry(new S32(ifIndex), new TetherStatsValue(
|
||||
0 /* rxPackets */, 0 /* rxBytes */, 0 /* rxErrors */, 0 /* txPackets */,
|
||||
0 /* txBytes */, 0 /* txErrors */));
|
||||
} catch (ErrnoException | IllegalArgumentException e) {
|
||||
|
|
@ -329,7 +328,7 @@ public class BpfCoordinatorShimImpl
|
|||
|
||||
TetherStatsValue statsValue = null;
|
||||
try {
|
||||
statsValue = mBpfStatsMap.getValue(new TetherStatsKey(ifIndex));
|
||||
statsValue = mBpfStatsMap.getValue(new S32(ifIndex));
|
||||
} catch (ErrnoException e) {
|
||||
mLog.e("Could not get stats entry for interface index " + ifIndex + ": ", e);
|
||||
return null;
|
||||
|
|
@ -341,7 +340,7 @@ public class BpfCoordinatorShimImpl
|
|||
}
|
||||
|
||||
try {
|
||||
mBpfStatsMap.deleteEntry(new TetherStatsKey(ifIndex));
|
||||
mBpfStatsMap.deleteEntry(new S32(ifIndex));
|
||||
} catch (ErrnoException e) {
|
||||
mLog.e("Could not delete stats entry for interface index " + ifIndex + ": ", e);
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -76,7 +76,6 @@ import com.android.net.module.util.SharedLog;
|
|||
import com.android.net.module.util.Struct.S32;
|
||||
import com.android.net.module.util.bpf.Tether4Key;
|
||||
import com.android.net.module.util.bpf.Tether4Value;
|
||||
import com.android.net.module.util.bpf.TetherStatsKey;
|
||||
import com.android.net.module.util.bpf.TetherStatsValue;
|
||||
import com.android.net.module.util.ip.ConntrackMonitor;
|
||||
import com.android.net.module.util.ip.ConntrackMonitor.ConntrackEventConsumer;
|
||||
|
|
@ -448,11 +447,11 @@ public class BpfCoordinator {
|
|||
}
|
||||
|
||||
/** Get stats BPF map. */
|
||||
@Nullable public IBpfMap<TetherStatsKey, TetherStatsValue> getBpfStatsMap() {
|
||||
@Nullable public IBpfMap<S32, TetherStatsValue> getBpfStatsMap() {
|
||||
if (!isAtLeastS()) return null;
|
||||
try {
|
||||
return new BpfMap<>(TETHER_STATS_MAP_PATH,
|
||||
TetherStatsKey.class, TetherStatsValue.class);
|
||||
S32.class, TetherStatsValue.class);
|
||||
} catch (ErrnoException e) {
|
||||
Log.e(TAG, "Cannot create stats map: " + e);
|
||||
return null;
|
||||
|
|
@ -1370,7 +1369,7 @@ public class BpfCoordinator {
|
|||
}
|
||||
}
|
||||
private void dumpBpfStats(@NonNull IndentingPrintWriter pw) {
|
||||
try (IBpfMap<TetherStatsKey, TetherStatsValue> map = mDeps.getBpfStatsMap()) {
|
||||
try (IBpfMap<S32, TetherStatsValue> map = mDeps.getBpfStatsMap()) {
|
||||
if (map == null) {
|
||||
pw.println("No BPF stats map");
|
||||
return;
|
||||
|
|
@ -1522,7 +1521,7 @@ public class BpfCoordinator {
|
|||
// expected argument order.
|
||||
// TODO: dump downstream4 map.
|
||||
if (CollectionUtils.contains(args, DUMPSYS_RAWMAP_ARG_STATS)) {
|
||||
try (IBpfMap<TetherStatsKey, TetherStatsValue> statsMap = mDeps.getBpfStatsMap()) {
|
||||
try (IBpfMap<S32, TetherStatsValue> statsMap = mDeps.getBpfStatsMap()) {
|
||||
BpfDump.dumpRawMap(statsMap, pw);
|
||||
} catch (IOException e) {
|
||||
pw.println("Error dumping stats map: " + e);
|
||||
|
|
|
|||
|
|
@ -75,13 +75,13 @@ import com.android.modules.utils.build.SdkLevel;
|
|||
import com.android.net.module.util.BpfDump;
|
||||
import com.android.net.module.util.Ipv6Utils;
|
||||
import com.android.net.module.util.Struct;
|
||||
import com.android.net.module.util.Struct.S32;
|
||||
import com.android.net.module.util.bpf.ClatEgress4Key;
|
||||
import com.android.net.module.util.bpf.ClatEgress4Value;
|
||||
import com.android.net.module.util.bpf.ClatIngress6Key;
|
||||
import com.android.net.module.util.bpf.ClatIngress6Value;
|
||||
import com.android.net.module.util.bpf.Tether4Key;
|
||||
import com.android.net.module.util.bpf.Tether4Value;
|
||||
import com.android.net.module.util.bpf.TetherStatsKey;
|
||||
import com.android.net.module.util.bpf.TetherStatsValue;
|
||||
import com.android.net.module.util.structs.Ipv4Header;
|
||||
import com.android.net.module.util.structs.UdpHeader;
|
||||
|
|
@ -1055,15 +1055,15 @@ public class EthernetTetheringTest extends EthernetTetheringTestBase {
|
|||
// Dump stats map to verify.
|
||||
final String[] statsArgs = new String[] {DUMPSYS_TETHERING_RAWMAP_ARG,
|
||||
DUMPSYS_RAWMAP_ARG_STATS};
|
||||
final HashMap<TetherStatsKey, TetherStatsValue> statsMap = pollRawMapFromDump(
|
||||
TetherStatsKey.class, TetherStatsValue.class, Context.TETHERING_SERVICE, statsArgs);
|
||||
final HashMap<S32, TetherStatsValue> statsMap = pollRawMapFromDump(
|
||||
S32.class, TetherStatsValue.class, Context.TETHERING_SERVICE, statsArgs);
|
||||
assertNotNull(statsMap);
|
||||
assertEquals(1, statsMap.size());
|
||||
|
||||
final Map.Entry<TetherStatsKey, TetherStatsValue> stats =
|
||||
final Map.Entry<S32, TetherStatsValue> stats =
|
||||
statsMap.entrySet().iterator().next();
|
||||
|
||||
// TODO: verify the upstream index in TetherStatsKey.
|
||||
// TODO: verify the upstream index in S32.
|
||||
|
||||
final TetherStatsValue statsValue = stats.getValue();
|
||||
assertEquals(RX_UDP_PACKET_COUNT, statsValue.rxPackets);
|
||||
|
|
|
|||
|
|
@ -124,7 +124,6 @@ import com.android.net.module.util.SharedLog;
|
|||
import com.android.net.module.util.Struct.S32;
|
||||
import com.android.net.module.util.bpf.Tether4Key;
|
||||
import com.android.net.module.util.bpf.Tether4Value;
|
||||
import com.android.net.module.util.bpf.TetherStatsKey;
|
||||
import com.android.net.module.util.bpf.TetherStatsValue;
|
||||
import com.android.net.module.util.ip.ConntrackMonitor;
|
||||
import com.android.net.module.util.ip.ConntrackMonitor.ConntrackEventConsumer;
|
||||
|
|
@ -480,8 +479,8 @@ public class BpfCoordinatorTest {
|
|||
spy(new TestBpfMap<>(TetherDownstream6Key.class, Tether6Value.class));
|
||||
private final IBpfMap<TetherUpstream6Key, Tether6Value> mBpfUpstream6Map =
|
||||
spy(new TestBpfMap<>(TetherUpstream6Key.class, Tether6Value.class));
|
||||
private final IBpfMap<TetherStatsKey, TetherStatsValue> mBpfStatsMap =
|
||||
spy(new TestBpfMap<>(TetherStatsKey.class, TetherStatsValue.class));
|
||||
private final IBpfMap<S32, TetherStatsValue> mBpfStatsMap =
|
||||
spy(new TestBpfMap<>(S32.class, TetherStatsValue.class));
|
||||
private final IBpfMap<S32, TetherLimitValue> mBpfLimitMap =
|
||||
spy(new TestBpfMap<>(S32.class, TetherLimitValue.class));
|
||||
private final IBpfMap<S32, S32> mBpfDevMap =
|
||||
|
|
@ -554,7 +553,7 @@ public class BpfCoordinatorTest {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
public IBpfMap<TetherStatsKey, TetherStatsValue> getBpfStatsMap() {
|
||||
public IBpfMap<S32, TetherStatsValue> getBpfStatsMap() {
|
||||
return mBpfStatsMap;
|
||||
}
|
||||
|
||||
|
|
@ -677,7 +676,7 @@ public class BpfCoordinatorTest {
|
|||
|
||||
// Update a stats entry or create if not exists.
|
||||
private void updateStatsEntryToStatsMap(@NonNull TetherStatsParcel stats) throws Exception {
|
||||
final TetherStatsKey key = new TetherStatsKey(stats.ifIndex);
|
||||
final S32 key = new S32(stats.ifIndex);
|
||||
final TetherStatsValue value = new TetherStatsValue(stats.rxPackets, stats.rxBytes,
|
||||
0L /* rxErrors */, stats.txPackets, stats.txBytes, 0L /* txErrors */);
|
||||
mBpfStatsMap.updateEntry(key, value);
|
||||
|
|
@ -925,7 +924,7 @@ public class BpfCoordinatorTest {
|
|||
private void verifyTetherOffloadSetInterfaceQuota(@Nullable InOrder inOrder, int ifIndex,
|
||||
long quotaBytes, boolean isInit) throws Exception {
|
||||
if (mDeps.isAtLeastS()) {
|
||||
final TetherStatsKey key = new TetherStatsKey(ifIndex);
|
||||
final S32 key = new S32(ifIndex);
|
||||
verifyWithOrder(inOrder, mBpfStatsMap).getValue(key);
|
||||
if (isInit) {
|
||||
verifyWithOrder(inOrder, mBpfStatsMap).insertEntry(key, new TetherStatsValue(
|
||||
|
|
@ -953,8 +952,8 @@ public class BpfCoordinatorTest {
|
|||
private void verifyTetherOffloadGetAndClearStats(@NonNull InOrder inOrder, int ifIndex)
|
||||
throws Exception {
|
||||
if (mDeps.isAtLeastS()) {
|
||||
inOrder.verify(mBpfStatsMap).getValue(new TetherStatsKey(ifIndex));
|
||||
inOrder.verify(mBpfStatsMap).deleteEntry(new TetherStatsKey(ifIndex));
|
||||
inOrder.verify(mBpfStatsMap).getValue(new S32(ifIndex));
|
||||
inOrder.verify(mBpfStatsMap).deleteEntry(new S32(ifIndex));
|
||||
inOrder.verify(mBpfLimitMap).deleteEntry(new S32(ifIndex));
|
||||
} else {
|
||||
inOrder.verify(mNetd).tetherOffloadGetAndClearStats(ifIndex);
|
||||
|
|
@ -2729,7 +2728,7 @@ public class BpfCoordinatorTest {
|
|||
|
||||
// dumpStats
|
||||
mBpfStatsMap.insertEntry(
|
||||
new TetherStatsKey(UPSTREAM_IFINDEX),
|
||||
new S32(UPSTREAM_IFINDEX),
|
||||
new TetherStatsValue(
|
||||
0L /* rxPackets */, 0L /* rxBytes */, 0L /* rxErrors */,
|
||||
0L /* txPackets */, 0L /* txBytes */, 0L /* txErrors */));
|
||||
|
|
@ -3010,8 +3009,8 @@ public class BpfCoordinatorTest {
|
|||
// When the last rule is removed, tetherOffloadGetAndClearStats will log a WTF (and
|
||||
// potentially crash the test) if the stats map is empty.
|
||||
final TetherStatsValue allZeros = new TetherStatsValue(0, 0, 0, 0, 0, 0);
|
||||
when(mBpfStatsMap.getValue(new TetherStatsKey(UPSTREAM_IFINDEX))).thenReturn(allZeros);
|
||||
when(mBpfStatsMap.getValue(new TetherStatsKey(UPSTREAM_IFINDEX2))).thenReturn(allZeros);
|
||||
when(mBpfStatsMap.getValue(new S32(UPSTREAM_IFINDEX))).thenReturn(allZeros);
|
||||
when(mBpfStatsMap.getValue(new S32(UPSTREAM_IFINDEX2))).thenReturn(allZeros);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2020 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.net.module.util.bpf;
|
||||
|
||||
import com.android.net.module.util.Struct;
|
||||
import com.android.net.module.util.Struct.Field;
|
||||
import com.android.net.module.util.Struct.Type;
|
||||
|
||||
/** The key of BpfMap which is used for tethering stats. */
|
||||
public class TetherStatsKey extends Struct {
|
||||
@Field(order = 0, type = Type.S32)
|
||||
public final int ifindex; // upstream interface index
|
||||
|
||||
public TetherStatsKey(final int ifindex) {
|
||||
this.ifindex = ifindex;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue