Commit Graph

272 Commits

Author SHA1 Message Date
Maciej Żenczykowski
90d41b22a4 Merge "IpUtils - make checksum work with empty/zero buffer" 2023-04-19 19:39:53 +00:00
Maciej Żenczykowski
5f95a67eef IpUtils - make checksum work with empty/zero buffer
also:
- document buffer endianness assumption
- simplify fold logic - it cannot overflow

Test: TreeHugger, atest NetworkStaticLibTests
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I521a7377d1310c0e9c46a5dff95dca451e5f889e
2023-04-19 08:17:29 +00:00
Igor Chernyshev
810be2b456 Add async BufferedFile and StreamingPacketFile impls
Bug: 245971639

Change-Id: Ief1719262c2cb68819f6feb955e97793f3638ec0
2023-04-17 21:26:58 +00:00
Treehugger Robot
021e3178b2 Merge changes Ief507b3f,I45256bb1
* changes:
  Add InetDiagMessage.inetDiagReqV2 with different args
  Fix StructInetDiagSockId parsing for v4-mapped v6 address
2023-04-10 12:14:07 +00:00
Treehugger Robot
6ba46f963a Merge "Add util to compare getAllAddresses" 2023-04-10 10:38:42 +00:00
Motomu Utsumi
95681172a9 Add InetDiagMessage.inetDiagReqV2 with different args
This CL also adds SOCK_DESTROY constants.
These changes will be used by upcoming CLs that implement socket destroy
in ConnectivityService.

Bug: 270298713
Test: atest NetworkStaticLibTests
Change-Id: Ief507b3f8cc4fe23c08699e7fc8f3f62e5acfcdc
2023-04-10 18:09:43 +09:00
Motomu Utsumi
64a711a618 Fix StructInetDiagSockId parsing for v4-mapped v6 address
Before this CL, StructInetDiagSockId.parse convert v4-mapped v6 address
to Inet4Address that is inconsistent with the value in
inet_diag_msg.idiag_family.
Also, due to this behavior, input of parse and output of pack could be
different.
This is the issue specifically when SOCK_DESTROY request is populated
based on the InetDiagMessage from the kernel.

Bug: 270298713
Test: atest NetworkStaticLibTests
Change-Id: I45256bb1069cfc4e01662b3a533077933f3f019a
2023-04-10 18:01:17 +09:00
Treehugger Robot
68783d0260 Merge "Remove pollOrThrow" 2023-04-10 04:58:22 +00:00
Motomu Utsumi
80c53fa4fd Update StructInetDiagMsg to parse all the fields
Bug: 270298713
Test: atest NetworkStaticLibTests
Change-Id: I782eca50b6db6dca88ee933edb5d5d19223886dd
2023-04-06 11:03:52 +09:00
Chalard Jean
b56b9f2dcc Add util to compare getAllAddresses
Bug: 269715746
Test: New test in this patch
Change-Id: I243940df693d984a8adfa5c55b49088f7d8bc5ff
2023-03-31 21:35:44 +09:00
Motomu Utsumi
b0c6afda18 Merge "Fix StructInetDiagMsg#parse bug" 2023-03-24 08:44:55 +00:00
Motomu Utsumi
06e615e3ce Fix StructInetDiagMsg#parse bug
StructInetDiagMsg#parse used absolute position to parse id and idiag_uid
fields.
This causes an issue when byte buffer contains multiple netlink messages
and parsed netlink message starts from the middle of byte buffer.

This CL fixes above issue and adds test for the case that single byte
buffer contains multiple netlink messages.

Test: atest NetworkStaticLibTests
Change-Id: I771daf17b4a606915d5edefd9f0e90ef01abf168
2023-03-24 12:34:04 +09:00
Xiao Ma
9a1359b46c Support NLM_F_REPLACE flag when sending a RTM_NEWADDR message.
NLM_F_REPLACE is helpful when we only want to update the preferred and
valid lifetime for a specific IPv6 address. DHCPv6 prefix delegation
gives a concrete example, once client refreshes the delegated prefix
successfully in RENEW or REBIND state, it also needs to extend the
preferred and valid lifetime of an IPv6 address, otherwise, it becomes
depreacated when the lifetime expires. Add the NLM_F_REPLACE flag to
replace the existing matching address object with updated fields.

Bug: 260934173
Test: atest NetworkStaticLibsTests
Change-Id: Ic001ddf9cfb031a586bbe177819e7666eaf7cde0
2023-03-23 15:59:40 +09:00
Chalard Jean
c2cf7eb82d Remove pollOrThrow
This method is better removed, because it doesn't follow the
naming conventions we want to keep in this file. It also isn't
useful :
• There is only one use of it outside tests, and it's in the
  same file. It's trivial to inline it.
• The method has a unit test, which becomes useless once the
  method is inlined.
• There is a corresponding command in the interpreter, but it's
  only used by the unit test and therefore can be removed once
  the unit test is removed.

Test: TH
Bug: 157405399
Change-Id: Ib5b1369ac28e4577adc98204e42ff2f27729e64c
2023-03-07 21:48:24 +09:00
Junyu Lai
ff5ee31314 Merge "Revert "Return default value when getModuleVersion throwed"" 2023-02-21 07:47:51 +00:00
Chalard Jean
2695fdf6ce Bubble up exceptions in visibleOnHandlerThread
Test: NetworkStaticLibTests
Fixes: 269390906
Change-Id: I3c2d330dd719869562f437c1995e85abd32dbd68
2023-02-17 07:19:22 +00:00
Junyu Lai
1236b9e809 Revert "Return default value when getModuleVersion throwed"
This reverts commit 76a97e81f51cb28e9c2b9eaf039e4186029989a3.

Reason for revert: b/269391238

Fix: 269391238
Change-Id: Ic1fbe09c341f147350e64357f9f647ec61d7e828
2023-02-16 02:30:08 +00:00
Chalard Jean
36e8ff3f87 Remove expectLinkPropertiesThat
expect() is simply better

Bug: 157405399
Test: ConnectivityServiceTest NetworkStaticLibTests
Change-Id: If8da940e378722f4cde2a4e7ea3eaef3b1380f18
2023-02-09 16:19:09 +09:00
Chalard Jean
ab521cf49d Remove expectCapabilitiesWith and without
This is not clearer than using the base method.

Test: ConnectivityServiceTest NetworkStaticLibTests
Bug: 157405399
Change-Id: Iac9aeffb563d0a1cb6c1287b46b9bbfffc0c75ca
2023-02-06 13:49:52 +09:00
Chalard Jean
c0ba521f79 Replace expectCapabilitiesThat with expectCaps
Add all the necessary overloads too.

Bug: 157405399
Test: ConnectivityServiceTest NetworkStaticLibTests
Change-Id: Idea768934182d4e2226c273fda0189942dcbf62e
2023-02-06 13:49:51 +09:00
Chalard Jean
60b95c4090 Factorize describeDifferences
Fixes: 259479229
Test: new test for this in this patch
Change-Id: Iecbccd10b04ada49f3485097dfcf3511c26c0925
2023-01-27 08:02:10 +00:00
Treehugger Robot
ccc7d37685 Merge "Cleanup TestableNetworkCallback#assertNoCallback" 2023-01-13 07:41:06 +00:00
Treehugger Robot
b2e37305d9 Merge "Return default value when getModuleVersion throwed" 2023-01-13 05:06:57 +00:00
Junyu Lai
b4ecb5e750 Return default value when getModuleVersion throwed
In aosp, getModuleVersion would always throw since there is
no meta-info for modules. Currently it would make
isFeatureEnabled method return false, which is not
a right thing for features are default enabled.
Change it to return default value when throwed.

Test: atest NetworkStaticLibTests
Bug: 263219497
Change-Id: Iadcdcedac1f1da7d894e03b76b3e985f87ca8b0e
2023-01-12 15:04:06 +08:00
Chalard Jean
5987fc4fbe Cleanup TestableNetworkCallback#assertNoCallback
Test: FrameworksNetTests
      CtsNetTestCases
      FrameworksNetIntegrationTests
      NetworkStackTests
      NetworkStaticLibTests
      TetheringTests
      MtsTetheringTestLatestSdk
      TetheringIntegrationTests
Bug: 157405399
Change-Id: I43eb47bbcf947899c18fcd9498c9064edceb0ecf
2023-01-06 16:50:08 +09:00
Igor Chernyshev
a25f1091c5 Add wear tethering util classes
Bug: 245971639

Change-Id: I97655ece334ca93743896e89e12f8501f4e24776
2023-01-03 06:55:23 +00:00
Treehugger Robot
2529234f69 Merge "Introduce visibleOnHandlerThread" 2022-12-29 10:25:13 +00:00
Maciej Żenczykowski
463f211a76 convert BpfDumpTest from U32 to S32
no need to use U32, of which uses I'd like to eliminate wherever possible

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I8c0a2df73c4153b21d33ee7a8f5d434f0fc80103
2022-12-22 12:06:35 +00:00
Chalard Jean
9f7d45203f Introduce visibleOnHandlerThread
This is a helper function that lets a caller make sure the
side effects of a piece of code are visible both on a handler
thread and in the caller thread before continuing.

Also move HandlerUtilsTests to the tests directory of
frameworks/libs/net from the NetworkStack where it used to be

Test: NetworkStaticLibTests
Change-Id: Icf1bd8bbe1216777c52b73cfbd0a46b647b72260
2022-12-22 16:17:22 +09:00
Chiachang Wang
da152d63b4 Merge "Add common netlink operation and definition for TCP socket polling" 2022-12-19 12:40:41 +00:00
chiachangwang
29bbf2dace Add common netlink operation and definition for TCP socket polling
Move code to common lib to support coming TCP socket polling
design in connectivity module to prevent code duplication.

Bug: 259000745
Test: atest FrameworksNetTests
Change-Id: I89ca1c19122c3b4306b93a6a253e0ea67259eb77
2022-12-19 09:11:00 +00:00
Junyu Lai
7e3cdf9ef2 Merge changes from topic "st03"
* changes:
  Interrupt thread before closing socket
  [ST03] Add test dns server for integration tests
2022-12-19 02:34:33 +00:00
Junyu Lai
3d4eb94be5 [ST03] Add test dns server for integration tests
This is re-upload of aosp/1390056, CL that fixes test is separated
in a follow-up CL that submit at the same time.

Bug: 139774492
Test: atest DnsAnswerProviderTest TestDnsServerTest
Change-Id: Ia72975f3044f009ebb0f4564a527830268a4a157
2022-12-13 16:15:46 +08:00
Xiao Ma
d03464df21 Address comments left from aosp/2324894.
- address flags preferrence, support u32 flags
    - assert IP address should not be null
    - add unit tests for the update.

Bug: 260934173
Test: atest NetworkStaticLibTests
Change-Id: I18b3a717a9602748617cad279f65c0fefd5dec48
2022-12-12 18:40:30 +09:00
Xiao Ma
0937911c41 Add a method helper to create RTM_NEWADDR message in user space.
Bug: 260934173
Test: atest NetworkStaticLibTests
Change-Id: I39a53a3d8b0cd10437aeed502657dd34d8b7775d
2022-12-07 12:53:55 +09:00
Treehugger Robot
8228246ad0 Merge "Revert "[ST03] Add test dns server for integration tests"" 2022-11-16 05:13:03 +00:00
Jean Chalard
55de7e4c84 Merge "Add useful utils to CollectionUtils" 2022-11-15 08:50:19 +00:00
Junyu Lai
88c48e18e4 Revert "[ST03] Add test dns server for integration tests"
Revert "[ST03.1] Add DnsAnswerProviderTest"

Revert submission 1390056-st03

Reason for revert: test failed in presubmit, still under checking.
Reverted Changes:
Ia5039a47f:[ST03] Add test dns server for integration tests
I9157e030c:[ST03.1] Add DnsAnswerProviderTest

Change-Id: I1ff291ca62e2209343ed5c5e4aa3bf3e93229f47
2022-11-15 05:55:27 +00:00
Treehugger Robot
40b76e8bac Merge "[ST03] Add test dns server for integration tests" 2022-11-14 14:01:12 +00:00
Chalard Jean
43bb172e82 Add useful utils to CollectionUtils
Test: new tests in this patch
Change-Id: I9cca999f9235d4d6508533230afcd8ee0c1c54c1
2022-11-14 20:47:59 +09:00
Junyu Lai
be99103196 [ST03] Add test dns server for integration tests
Bug: 139774492
Test: atest DnsAnswerProviderTest TestDnsServerTest
Change-Id: Ia5039a47f4b818efb09aab8174beb9d921339c3d
2022-11-02 11:18:48 +08:00
Paul Hu
281e7a2587 Merge "Add ByteUtils for byte utility functions" 2022-10-26 01:05:55 +00:00
Paul Hu
528e675fdd Add ByteUtils for byte utility functions
Bug: 254155029
Test: atest NetworkStaticLibTests
Change-Id: I996ead6f23698313828e844672de5917efdfce69
2022-10-25 05:40:00 +00:00
Chalard Jean
6f8bcae7d0 [CC07] Add build tests for expect* versions
Also address some comments left on a previous patchset.

Test: NetworkStaticLibTests
Change-Id: I3ea16bb54aec31ddb0368af980483109a1bdb49b
2022-10-24 18:54:45 +09:00
Chalard Jean
3ad176b03a [CC06] Move usage of expectCallback* to expect
See CC03 (aosp/2255619) for details

Test: NettworkStaticLibTests
Change-Id: Id15560f5744024ff2ac2acbaf4de83818ce6efc5
2022-10-21 11:53:13 +09:00
Chalard Jean
347dd8ded4 Increase the timeout for eventuallyExpect
Sometimes the tests are run under high load, e.g. immediately
after boot while all apps that listen for the boot completed
broadcast run their listeners. Under these circumstances,
40ms of leeway is tight ; on recent Android devices HZ is
commonly 100 too, meaning a general time unit of 60 will give
a little bit of air.

The drawback in this is that the test is less stringent on
TrackRecord, which as a multi-thread primitive should have
really tight tests to make sure that a non-threading primitive
(e.g. a polling implementation) doesn't pass. This patch makes
the testing on that front a little bit less reliable.

Note that this patch won't actually fix all flakes in that it
isn't really possible to guarantee the device will have any
CPU time to run the test at all anyway, but this should make
most failures go away.

Also, the argument for the time unit is never used, and can
be removed ; at least, the possibility of the timeArg() func
not using the same value as the sleep directive is scary, so
that possibility should be removed. If the time unit argument
is ever needed it can be added back, but considering the arg
has been available for years and never used, it's unlikely.

Test: NetworkStaticLibTests
Fixes: 254188131
Change-Id: Ia7a4fe775942484dcd7dc223c7710e82a8329beb
2022-10-20 16:42:16 +09:00
Chalard Jean
70c62e594a [CC01] Remove the confusing pollForNextCallback
In Java, "poll" methods return null when the collection is
empty. Respect this convention.

Bug: 157405399
Test: FrameworksNetTests
Change-Id: I3b17908f9ce1f60b18908605a645da3199c010b9
2022-10-17 14:51:53 +09:00
Jean Chalard
4152f83b27 Merge "Move bit utility methods to a new BitUtils class." 2022-10-14 04:55:25 +00:00
Chalard Jean
5c6f7809e2 Save one minute in executing NetworkStaticLibTests
The default timeout for expectEventually is 30 seconds, so this
test used to take one minute. With this change, it now only takes
50ms, with virtually no change in safety.

Test: NetworkStaticLibTests
Change-Id: Id8d6a738ea6a70f7d901a7659b2160c2f3d7d2c0
2022-10-13 16:41:29 +09:00
Chalard Jean
cd0fc3d71b Move TestableNetworkCallbackTest to f/l/n
This tests a utility in f/l/n, so it should live together with
it and not in the network stack tests

Test: NetworkStaticLibTests NetworkStackTests
Change-Id: I90d12933e3a82eba4b565022d3df1e7c1d503f56
2022-10-13 16:41:28 +09:00