Fix testTetherClatBpfOffloadUdp test failure
In some cases, the test device may already have an existing CLAT
interface, causing the test to fail because it assumes no CLAT
interface exists before running the test. This change fixes the issue
by retrieving the correct test CLAT interface by its name.
Bug: 361219545
Test: atest EthernetTetheringTest#testTetherClatBpfOffloadUdp
Change-Id: Ie2cdd9c9a6fd143c8419636a448297b36f3c1c40
diff --git a/Tethering/tests/integration/base/android/net/EthernetTetheringTestBase.java b/Tethering/tests/integration/base/android/net/EthernetTetheringTestBase.java
index 1eb6255..d5c6a8e 100644
--- a/Tethering/tests/integration/base/android/net/EthernetTetheringTestBase.java
+++ b/Tethering/tests/integration/base/android/net/EthernetTetheringTestBase.java
@@ -568,6 +568,12 @@
return nif.getMTU();
}
+ protected int getIndexByName(String ifaceName) throws SocketException {
+ NetworkInterface nif = NetworkInterface.getByName(ifaceName);
+ assertNotNull("Can't get NetworkInterface object for " + ifaceName, nif);
+ return nif.getIndex();
+ }
+
protected TapPacketReader makePacketReader(final TestNetworkInterface iface) throws Exception {
FileDescriptor fd = iface.getFileDescriptor().getFileDescriptor();
return makePacketReader(fd, getMTU(iface));
@@ -968,6 +974,11 @@
return Struct.parse(Ipv6Header.class, ByteBuffer.wrap(expectedPacket)).srcIp;
}
+ protected String getUpstreamInterfaceName() {
+ if (mUpstreamReader == null) return null;
+ return mUpstreamTracker.getTestIface().getInterfaceName();
+ }
+
protected <T> List<T> toList(T... array) {
return Arrays.asList(array);
}
diff --git a/Tethering/tests/integration/src/android/net/EthernetTetheringTest.java b/Tethering/tests/integration/src/android/net/EthernetTetheringTest.java
index 049f5f0..32b2f3e 100644
--- a/Tethering/tests/integration/src/android/net/EthernetTetheringTest.java
+++ b/Tethering/tests/integration/src/android/net/EthernetTetheringTest.java
@@ -1066,24 +1066,34 @@
runUdp4Test();
}
- private ClatEgress4Value getClatEgress4Value() throws Exception {
+ private ClatEgress4Value getClatEgress4Value(int clatIfaceIndex) throws Exception {
// Command: dumpsys connectivity clatEgress4RawBpfMap
final String[] args = new String[] {DUMPSYS_CLAT_RAWMAP_EGRESS4_ARG};
final HashMap<ClatEgress4Key, ClatEgress4Value> egress4Map = pollRawMapFromDump(
ClatEgress4Key.class, ClatEgress4Value.class, Context.CONNECTIVITY_SERVICE, args);
assertNotNull(egress4Map);
- assertEquals(1, egress4Map.size());
- return egress4Map.entrySet().iterator().next().getValue();
+ for (Map.Entry<ClatEgress4Key, ClatEgress4Value> entry : egress4Map.entrySet()) {
+ ClatEgress4Key key = entry.getKey();
+ if (key.iif == clatIfaceIndex) {
+ return entry.getValue();
+ }
+ }
+ return null;
}
- private ClatIngress6Value getClatIngress6Value() throws Exception {
+ private ClatIngress6Value getClatIngress6Value(int ifaceIndex) throws Exception {
// Command: dumpsys connectivity clatIngress6RawBpfMap
final String[] args = new String[] {DUMPSYS_CLAT_RAWMAP_INGRESS6_ARG};
final HashMap<ClatIngress6Key, ClatIngress6Value> ingress6Map = pollRawMapFromDump(
ClatIngress6Key.class, ClatIngress6Value.class, Context.CONNECTIVITY_SERVICE, args);
assertNotNull(ingress6Map);
- assertEquals(1, ingress6Map.size());
- return ingress6Map.entrySet().iterator().next().getValue();
+ for (Map.Entry<ClatIngress6Key, ClatIngress6Value> entry : ingress6Map.entrySet()) {
+ ClatIngress6Key key = entry.getKey();
+ if (key.iif == ifaceIndex) {
+ return entry.getValue();
+ }
+ }
+ return null;
}
/**
@@ -1115,8 +1125,13 @@
final Inet6Address clatIp6 = getClatIpv6Address(tester, tethered);
// Get current values before sending packets.
- final ClatEgress4Value oldEgress4 = getClatEgress4Value();
- final ClatIngress6Value oldIngress6 = getClatIngress6Value();
+ final String ifaceName = getUpstreamInterfaceName();
+ final int ifaceIndex = getIndexByName(ifaceName);
+ final int clatIfaceIndex = getIndexByName("v4-" + ifaceName);
+ final ClatEgress4Value oldEgress4 = getClatEgress4Value(clatIfaceIndex);
+ final ClatIngress6Value oldIngress6 = getClatIngress6Value(ifaceIndex);
+ assertNotNull(oldEgress4);
+ assertNotNull(oldIngress6);
// Send an IPv4 UDP packet in original direction.
// IPv4 packet -- CLAT translation --> IPv6 packet
@@ -1145,8 +1160,10 @@
ByteBuffer.wrap(payload), l2mtu);
// After sending test packets, get stats again to verify their differences.
- final ClatEgress4Value newEgress4 = getClatEgress4Value();
- final ClatIngress6Value newIngress6 = getClatIngress6Value();
+ final ClatEgress4Value newEgress4 = getClatEgress4Value(clatIfaceIndex);
+ final ClatIngress6Value newIngress6 = getClatIngress6Value(ifaceIndex);
+ assertNotNull(newEgress4);
+ assertNotNull(newIngress6);
assertEquals(RX_UDP_PACKET_COUNT + fragPktCnt, newIngress6.packets - oldIngress6.packets);
assertEquals(RX_UDP_PACKET_COUNT * RX_UDP_PACKET_SIZE + fragRxBytes,