Commit graph android_packages_modules_Co.../Tethering/tests/privileged
Message SHA1
Rename TapPacketReader to PollPacketReader for broader applicability
* Renamed TapPacketReader to PollPacketReader to better reflect its
  functionality beyond TAP interface interaction.
* The class includes general logic for polling and sending packets to
  file descriptors, making it suitable for wider use cases.

Test: TH
Change-Id: Icdf9a9d7ef6f49b589ed9cdbd05159ab95e7e5d9

Yuyang Huang   commited 2024-10-15 13:42:05 +09:00
eb3c631b89
Enforce min_sdk_version=30
These tests are run as part of the MTS suite, setting min_sdk_version
ensures that these tests can be installed on an older device and test
the corresponding mainline module.

Test: atest [<mod_name>...]
Bug: 156476221
Change-Id: Ic94b00ee1818063fc9f13e4ecffaca88f58c30c3

Spandan Das   commited 2024-07-01 17:50:35 +00:00
a9fd04cbb9
SingleWriterBpfMap - introduce getSingleton with caching
Test: TreeHugger, atest BpfMapTest finally happy!
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia4ddcbb4994bb0fd5df7d36e0d306ca5061d8963

Maciej Żenczykowski   commited 2024-06-15 14:04:03 -07:00
52d6c5587f
BpfMapTest: fixes for testGetFd
Test: TreeHugger, atest BpfMapTest happier
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ib2915d48fab2c1e90300f1d4aa5d2cb2f69741f9

Maciej Żenczykowski   commited 2024-06-15 14:04:03 -07:00
878aae0856
use a second map for SingleWriterBpfMap test
because the shared r/w lock on the first
conflicts with the exclusive r/w lock on the second

This fixes roughly *half* the BpfMapTest tests.

Test: TreeHugger, atest BpfMapTest less broken
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I9d500597cad16bb7756df3e6feb9a7aa762e59d9

Maciej Żenczykowski   commited 2024-06-15 14:04:03 -07:00
45e9372733
Use /proc/self instead of calling Os.getPid().
Change-Id: I181a490bea05bf62d1a854a4882a0969de280439
Test: test-only change

Lorenzo Colitti   commited 2024-06-06 05:52:55 +00:00
5e005cf421
Add a microbenchmark test for BpfMap.
Bug: 343166906
Test: Test-only change
Change-Id: I4bd5fbdfd4736885f0533b892b089a1c5c1a4b49

Lorenzo Colitti   commited 2024-06-05 06:48:38 +00:00
f5ebe1aafa
Add a SingleWriterBpfMap class that caches reads.
This should speed up BPF map reads by returning the cached value
without needing a system call.

Bug: 343166906
Test: added parameterization to BpfMapTest
Change-Id: Ifc0c5baa80f6d46356434c249749e87fe2f9ec6c

Lorenzo Colitti   commited 2024-06-05 06:48:27 +00:00
05be2f52fd
Deflake BpfMapTest#testNoFdLeaks.
When running locally, this occasionally fails due to unrelated fds
being opened or closed while the test is running.

Bug: 343166906
Test: test-only change
Change-Id: I437e66077f0471572ec2b215db63a000a4622af5

Lorenzo Colitti   commited 2024-06-05 06:48:15 +00:00
05a3e88e62
[DON'T BLOCK] Test ownership migration rules
This CL is created as a best effort to migrate test targets
to the new android ownership model. If you find incorrect or unnecessary
attribution in this CL, please create a separate CL to fix that.

For more details please refer to the link below,
<add g3 doc link>

Bug: 304529413
Test: N/A
Change-Id: I243f17b3f0ad7af9ffa15ca242456e36688733f5
Merged-In: I243f17b3f0ad7af9ffa15ca242456e36688733f5

Aditya Choudhary   commited 2024-01-31 12:34:50 +00:00
01b5ede2b2
BpfMap - add R/W constructor alias
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I7cef2b19f55e6e056b46bb1b28f85c7f7376f6f4

Maciej Żenczykowski   commited 2024-01-23 16:16:44 -08:00
06155c8040
Replace HashSet with ArraySet in RaParams
ArraySet is designed to be more memory afficient than HashSet. It is
suitable to store small numbers of items.

Test: atest TetheringPrivilegedTests TetheringIntegrationTests \
      TetheringTests
Bug: 261923493
Change-Id: I2bd2eded801cc05ce53ef9f9486b13faf1772d22

KH Shi   commited 2023-11-13 03:12:53 +00:00
ff1400be4b
Reapply "Simplify addRoutesToLocalNetwork calls"
This reverts commit 316346be6e.

Change-Id: I86977f6e7a5451d037c7ea6fee5c4bc7082935ff

Chalard Jean   commited 2023-10-18 15:50:02 +09:00
7f2b3dabcd
Revert "Simplify addRoutesToLocalNetwork calls"
Revert submission 2777667

Reason for revert: DroidMonitor-triggered revert due to breakage, bug b/305187495

Reverted changes: /q/submissionid:2777667

Bug: 305187495

Change-Id: I516d40b20d775e9c61b2f825bc094329d016d0c3

Anton Kulakov   commited 2023-10-13 15:15:50 +00:00
316346be6e
Simplify addRoutesToLocalNetwork calls
There are only three calls to this method, and two of them
are with a list of 1 address which means it's simpler inlined.

The last call will be replaced with calls to RouteController
in a followup, meaning we addRoutesToLocalNetwork can be removed.

Test: RouterAdvertisementDaemonTest
      NetdUtilsTest
Change-Id: I3b6ee1db40f09954b336321000735a66306bf000

Chalard Jean   commited 2023-10-13 16:19:25 +09:00
cf70df3e9b
Stop the created handler threads on the tests
The created handler thread will stay there for a while until
all the tests are finished. This is considered as a leakage
which will take the resource from the devices. In low end
devices, this may possibly impact the performance. The created
threads should be closed explicitly.

Test: atest ConnectivityCoverageTests ConntrackSocketTest
Change-Id: Ic1beb2a210e7c8c80c66fc9e0727c47599150672

Paul Hu   commited 2023-10-12 10:25:03 +08:00
ebbbf8f470
Add null check for tupleOrig in ConntrackMessage
ConntrackSocketTest#testIpv4ConntrackSocket always fail in cuttlefish
because it gets NullPointerException when accessing tupleOrig in
ConntrackMessage. tupleOrig can be null if it doesn't have source IP.

This situation happens when dumping the following conntrack entry:
vsoc_x86_64:/ # cat /proc/net/nf_conntrack
ipv4     2 unknown  2 570 src=0.0.0.0 dst=224.0.0.22 [UNREPLIED] \
src=224.0.0.22 dst=0.0.0.0 mark=0 secctx=u:object_r:unlabeled:s0 use=2

Bug: 280203901
Test: atest TetheringPrivilegedTests (on cuttlefish)
Change-Id: Iddc8cb390a4369190d535f4694e0e5fa4b6e590f

KH Shi   commited 2023-05-02 22:57:24 +08:00
9dfbb45bb6
Add Tetheroffload AIDL interface support
Add the AIDL HAL service interface support and abstract the HIDL/AIDL
interface implementations to allow OffloadController to talk to both
interfaces.

Bug: b/205762647
Test: atest com.android.networkstack.tethering
      atest ConnectivityCoverageTests
      atest ConntrackSocketTest
Change-Id: If7634a298d03668ed70b328f1ad6ca0ac0fe170b

KH Shi   commited 2023-03-17 16:56:47 +08:00
3d5e65cb48
Replace NetlinkSocket with NetlinkUtils
Those static method and constants are better to fit in
NetlinkUitls. Replace the usage.

Test: m
Test: atest FrameworksNetTests NetworkStackTests
Change-Id: I81e27b8264e39764a44a4ba87344e9ac940d920a

chiachangwang   commited 2022-12-19 06:39:31 +00:00
e97aed4847
Fix ConntrackSocketTest#testIpv4ConntrackSocket flaky
If we run an iterations test, TCP connections opened by previous tests
won't be closed immediately. They will stay in the TIME_WAIT state for
120 seconds before closed. Netfilter socket listens to both
NF_NETLINK_CONNTRACK_NEW and NF_NETLINK_CONNTRACK_DESTROY groups.

There is a tiny time gap between socket creation and sending dump
request to kernel. If an old TCP connection happened to be closed in
this time gap, listening socket would see a DESTROY message before
seeing the NEW messages triggered by dump request.

The current test only parsing the first contrack message in the read
buffer, so it will only find the DESTROY message and ignore all of the
following NEW messages. It does a netfilter socket dump, but does not
check whether the dump produces reasonable output. Now that we have
the ability to parse conntrack messages, do more in-depth checking.

Bug: 254608655
Test: atest ConntrackSocketTest --iteration 500
Change-Id: Icf95adb9d9390d598e9c6bdb4e245c5fce764e3e

KH Shi   commited 2022-12-05 22:26:52 +08:00
09eb7631fa
replace U32 ifindex with S32
These are allocated in order by the kernel, if we go
over 2 billion, we've got other problems... besides
U32 to S32 conversion will work just fine anyway.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ifbb7139e9118dd2d0c52e83c5874132e03760b30

Maciej Żenczykowski   commited 2022-08-18 01:07:11 +00:00
09813ced3e
BpfMapTest: add fd leak test
Test that there is no fd leak with persistent fd cache.

Bug: 236320567
Test: atest BpfMapTest#testNoFdLeaks (cached fd) [PASSED]
Test: atest BpfMapTest#testNoFdLeaks (noncached fd) [FAILED] (as expected)
[8/14] com.android.networkstack.tethering.BpfMapTest#testNoFdLeaks: FAILED (241ms)

STACKTRACE:
java.lang.AssertionError: Fd leak after 1000 iterations:  expected:<89> but was:<1089>
	at org.junit.Assert.fail(Assert.java:89)
	at org.junit.Assert.failNotEquals(Assert.java:835)
	at org.junit.Assert.assertEquals(Assert.java:647)
	at com.android.networkstack.tethering.BpfMapTest.testNoFdLeaks(BpfMapTest.java:420)

Test Code:
fd noncached BpfMap
frameworks/libs/net/common/device/com/android/net/module/util/BpfMap.java
@@ -97,7 +97,7 @@ public class BpfMap<K extends Struct, V extends Struct> implements IBpfMap<K, V>
      */
     public BpfMap(@NonNull final String path, final int flag, final Class<K> key,
             final Class<V> value) throws ErrnoException, NullPointerException {
-        mMapFd = cachedBpfFdGet(path, flag);
+        mMapFd = ParcelFileDescriptor.adoptFd(nativeBpfFdGet(path, flag));

Change-Id: I66f477fd1c291c56bccc97d385b2a554c2367b5a

Hungming Chen   authored and   Nucca Chen   commited 2022-07-26 14:23:29 +00:00
a81f1251dd
Use frameworks/libs/net version of SharedLog
Test: m
Bug: 235901424
Change-Id: Ibfa7821c68c41036a47e765f15078cd5d195afb8

Patrick Rohr   commited 2022-07-07 12:52:58 -07:00
b873e25ab4
fix BpfMapTest
to account for close() becoming a no-op

Bug: 230880517
Test: TreeHugger, atest com.android.networkstack.tethering.BpfMapTest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I69f25ff168c1cf0f13434dd1d842ed81a6a03f2f

Maciej Żenczykowski   commited 2022-05-13 14:59:13 +00:00
4426a84111
Catch new exceptions from BpfMap
Bug: 230880517
Test: atest FrameworksNetTests
Change-Id: I9eff2589f83ac109fb6e8b9906da05890daa9bd9

Hungming Chen   commited 2022-05-12 14:13:01 +08:00
374107963a
Deduplicate InterfaceParams
CS should use InterfaceParams from frameworks/libs/net.

Test: builds
Bug: 222448728
Change-Id: I1f45d3171b265461a8724b4be7b212c030b63fe9

Patrick Rohr   commited 2022-03-04 16:53:51 +01:00
9f371f024b
BpfBitmap Test
Privileged test case for BpfBitmap.

Test: atest BpfBitmapTest
Bug: 179733303
Change-Id: I9c32d8843176815a725eccfd1f0400ec129cd94d

Tyler Wear   commited 2022-02-15 22:19:58 +00:00
c23ffbdf7e
Merge "[NETD-BPF#3] Relocate Tethering/bpf_progs and rename bpf_tethering_headers"
Ken Chen   authored and   Gerrit Code Review   commited 2021-12-02 12:54:01 +00:00
5fabfd8dd0
Add defaults to enable/disable connectivity/tethering next
The defaults can be used to enable/disable connectivity next targets
depending on the branch, while minimizing merge conflicts.

The "next" target may use unstable APIs. It need to be disabled in the
branch which only have the last stable SDK available.

Also correct TetheringTestsLatestSdkLib which should use stable API.

Test: TH
Change-Id: I00d91bbd513277c1cedf67d18ac9f56cc4037309

markchien   commited 2021-11-24 12:20:23 +08:00
598a75ba8c
[NETD-BPF#3] Relocate Tethering/bpf_progs and rename bpf_tethering_headers
The folder is currently used by tether offload only. Because we will
move netd.c and clatd.c to it, the folder should be moved to the upper
tier.

Also, rename bpf_tethering_headers to bpf_connectivity_headers so that
other connectivity code besides to tethering are justified to use it.

Bug: 202086915
Test: atest FrameworksNetTests
Change-Id: I95943c6e909f1fdca12604ef0c55d67c39ca686b

Ken Chen   commited 2021-11-20 18:31:08 +08:00
bb57fa9eec
Rename tethering jni and get the jni by its package name
tetherutiljni is renamed to com_android_networkstack_tethering_jni_util

Bug: 205088391
Test: atest TetheringTests
      atest CtsTetheringTest
      atest TetheringPrivilegedTests
Change-Id: Ifd1f4473625e33d3ebe190c9f8a2b5d54aa1ff49

markchien   commited 2021-11-10 14:07:24 +08:00
f967b11087
Rename tethering util folder and its package name
Move tethering util files from android.net.util into
com.android.networkstack.tethering.util. The goal is move all of
tethering internal files into its own namespace
com.android.networkstack.tethering.util.

Bug: 205088391
Test: atest TetheringTests
      atest CtsTetheringTest
      atest TetheringPrivilegedTests

Change-Id: I6559fb4f873b3cad5b210b10e49df1b6c6914a70

markchien   commited 2021-11-09 17:02:47 +08:00
d02f9af918
Fix TetheringPrivilegedTests crash
After separat BpfMap to a library, its package name is jarjar to
com.android.network.stack.util*. Also jarjar BpfMap of
TetheringPrivilegedTests to fix crash in jni registered.

Bug: 179733303
Test: atest TetheringPrivilegedTests
Change-Id: Ia9bc819a44fe26bf2ff7a46351ea60f2eeb02933

markchien   commited 2021-11-04 16:40:18 +08:00
45dc794fb4
Merge "bpfmap: Move to Common Location"
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2021-11-04 01:50:15 +00:00
bb4c6073ec
Merge "Replace "mts" with "mts-tethering"."
Kimberly Kreider   authored and   Gerrit Code Review   commited 2021-11-01 23:43:53 +00:00
200e42063c
bpfmap: Move to Common Location
Move bpfmap to frameworks/libs/net/common/native.

Bug: 179733303
Change-Id: Id08b216ec6a64968d66d7990f91ea7ce222a1154

Tyler Wear   commited 2021-10-29 09:05:33 -07:00
e8043ca762
Move to f/l/n instead of RouteUtils
Test: TetheringTests
Change-Id: I35b36538463a7fc2f02e142719c898d1694b2d6b

Chalard Jean   commited 2021-10-29 16:05:46 +09:00
adcec9ebbe
Replace "mts" with "mts-tethering".
Bug: 203466102
Test: build locally and verified contents
Change-Id: I7cccb54c0ad1a3bd8da0bcb7ad6474aa1e734299

Kimberly Kreider   commited 2021-10-20 18:16:59 +00:00
c5b3f34831
Merge "Import net-utils-device-common-netlink instead of netlink-client."
Xiao Ma   authored and   Gerrit Code Review   commited 2021-08-04 07:27:18 +00:00
609e71a46c
Throw an errno exception when open BPF map failed
Needed because an invalid file descriptor should notify the caller to
stop using the object.

Bug: 190523685

Test: atest BpfMaptest
Change-Id: I70fb08b54b1c0caa4be4e3f07b59bf4f2397f39d

Hungming Chen   authored and   Nucca Chen   commited 2021-08-03 08:38:16 +00:00
1257e9bfff
Add TetheringPrivilegedTests to postsubmit
Also ignore DadProxyTest before S because it is only enabled from S.

To using ignore test rule, replace AndroidJunit with DevSdkIgnoreRunner.
It is fine because the we don't use the test UI (e.g. running test in UI
thread).

Test: atest TetheringPrivilegedTests
Change-Id: I701ee877520f78ded2394adbae1f4d9dd612d700

markchien   authored and   Mark Chien   commited 2021-07-26 02:17:19 +00:00
911cf8fecd
Import net-utils-device-common-netlink instead of netlink-client.
After moving all netlink-client stuff to frameworks/libs/net/common
and build it as an individual library, deprecate the netlink-client
lib and use net-utils-device-common-netlink instead.

Due to that the package name of netlink lib has changed, also update the
package name used in Tethering and ConnectivityService module.

Bug: 192535368
Test: atest TetheringTests TetheringIntegrationTests
Change-Id: Ic2078caf67a640836d98c5a2e4ca89939adcb896

Xiao Ma   commited 2021-07-21 09:10:22 +00:00
09c0727e9e
Merge "Improve RouterAdvertisementDaemonTest."
Treehugger Robot   authored and   Gerrit Code Review   commited 2021-04-08 04:07:14 +00:00
662237f2f8
Improve RouterAdvertisementDaemonTest.
Add separate testing for unicast and multicast RAs.
Make the test more realistic by:
- Enabling forwarding. This ensures that the daemon actually
  receives the RS.
- Adding a link-local route. This ensures that the daemon is
  actually able to send a unicast response.

Bug: 154669942
Test: atest TetheringPrivilegedTests
Change-Id: Ibb1f51b5b1871657d7feff39335d3c71586cf64f

Xiao Ma   authored and   Lorenzo Colitti   commited 2021-04-08 11:02:02 +09:00
597d253f18
Merge changes I515be275,Ied159454,I5a29bdd1
* changes:
  bpf_progs - adjust for dstMac addition
  Populate the key destination mac address
  Set the limit whenever any IPv4 or IPv6 rule exists.

Nucca Chen   authored and   Gerrit Code Review   commited 2021-04-07 14:08:37 +00:00
8ba40704f3
Merge "implement insertOrReplace()"
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2021-04-06 08:17:42 +00:00
47851fc01b
implement insertOrReplace()
Test: atest com.android.networkstack.tethering.BpfMapTest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I4a40898f03293d6d79b57c35f743271c669a8ea7

Maciej Żenczykowski   commited 2021-04-06 04:38:46 +00:00
a36ea6fb19
Fix DadProxyTest when forwarding is on.
When forwarding is on, DadProxyTest fails because forwarding
disables optimistic addresses. This results in the DAD proxy
getting EADDRNOTAVAIL.

Forwarding is on quite often on real hardware because many
solutions for wifi calling use forwarding.

Fix the test to retry after two seconds if the packet is not
forwarded on the first attempt.

It would also be possible to make this work more reliably in the
test by simply disabling DAD or disabling forwarding. However,
because DAD does happen in real usage (downstream interfaces
always disable DAD, but upstream interfaces don't), that seems
risky. For example, if the test disabled DAD, it would not catch
bugs where the DAD proxy crashed or stopped forwarding if it got
EADDRNOTAVAIL.

Test: atest TetheringPrivilegedTests on coral, which has forwarding on
Change-Id: I58280ef7c0e40371cd770ead4c8baa7190c288fd

Lorenzo Colitti   commited 2021-04-05 23:42:29 +09:00
b6bffbca95
Populate the key destination mac address
Required because XDP offload needs input interface mac address
to be a part of the key. The mac address is used for checking
packets which are received from exceped input interface.

Test: atest TetheringCoverageTests, TetheringPrivilegedTests
Change-Id: Ied159454b516c0d70efe0a85744d1bb606892f2d

Hungming Chen   commited 2021-04-01 18:30:43 +08:00
9b8c60629f
Add test for RouterAdvertisementDaemon.
bug: 154669942
Test: atest TetheringPrivilegedTests
Change-Id: I2bbea720c486d6bb47a8d86375847894e2b2f390

markchien   authored and   Xiao Ma   commited 2021-03-15 08:20:57 +00:00
2af32e475f