Commit Graph

1611 Commits

Author SHA1 Message Date
Lorenzo Colitti
365b803fac Fix a race condition in upstream selection. am: 491999292b am: bf8a7b622d am: 6033471338
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1662400

Change-Id: Ic99e65a5e24cc497fb00a8f0969e97aaf120ac8d
2021-04-06 05:29:42 +00:00
Lorenzo Colitti
035bde8ae5 Add unit tests for race conditions in upstream selection. am: 6748e62ef2 am: afb685e650 am: 48cd598f81
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1662399

Change-Id: Id16999b1c4659b7c44b24a2deef8fdeb37803d42
2021-04-06 05:29:41 +00:00
Lorenzo Colitti
6033471338 Fix a race condition in upstream selection. am: 491999292b am: bf8a7b622d
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1662400

Change-Id: Ie771aba579b10a742b14d598dfcc50eee6baf4df
2021-04-06 04:42:30 +00:00
Lorenzo Colitti
48cd598f81 Add unit tests for race conditions in upstream selection. am: 6748e62ef2 am: afb685e650
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1662399

Change-Id: I08b9b57734374ab12634ea8ba20c718c6e7c3280
2021-04-06 04:42:29 +00:00
Lorenzo Colitti
491999292b Fix a race condition in upstream selection.
Current upstream selection code suffers from a race where if the
CONNECTIVITY_ACTION broadcast for a given network switch is
received and processed before the NetworkCallbacks for that
network switch, upstream selection just re-selects the same
upstream it had before. The incorrect upstream persists until
another CONNECTIVITY_ACTION is received.

Fix this by defining a new EVENT_DEFAULT_SWITCHED message code
communicated from UpstreamNetworkMonitor to Tethering, and send
that whenever the default network switches.

The message is sent in onLinkPropertiesChanged, because the
tethering code stores all information about networks in an
UpstreamNetworkState structure that contains Network,
LinkProperties and NetworkCapabilities. When a network switch
occurs, onLinkPropertiesChanged always follows onAvailable and
onCapabilitiesChanged, and thus marks the first point in time
when all the information is available.

This CL tries not to change existing codepaths too much, but
it does move the update of mDefaultInternetNetwork from
onCapabilitiesChanged to onLinkPropertiesChanged. This should
not be a problem because the only thing that reads
mDefaultInternetNetwork is getCurrentPreferredUpstream, which,
in the case of a default network switch, will be run by the
onLinkPropertiesChanged which will immediately follow.

Bug: 173068192
Test: changes to existing unit tests show bug is fixed
Change-Id: Ic9196bc92892811b25bda463ffd839ee5c19d294
2021-04-05 22:52:13 +09:00
Lorenzo Colitti
6748e62ef2 Add unit tests for race conditions in upstream selection.
In the current tethering code, upstream selection is only
triggered by CONNECTIVITY_ACTION. But in automatic mode, the
upstream network is selected by listening to a NetworkCallback
that tracks the default network.

This causes a race where if the CONNECTIVITY_ACTION for a network
switch is received and processed before the callbacks for that
network switch, upstream selection just re-selects the upstream
currently in use.

Make it possible to test this by giving TestConnectivityManager
the ability to choose the ordering between NetworkCallbacks and
CONNECTIVITY_ACTION, and to run an arbitrary Runnable between
calling one and calling the other. TetheringTest passes a
Runnable that calls mLooper.dispatchAll(), which ensures that
the tethering code fully processes the first set of information
it receives (either the broadcast (or the callbacks) before
receiving any more information.

Add test coverage to testAutomaticUpstreamSelection that
exercises various orderings, and make the test pass by expecting
the buggy behaviour of the current code.

An upcoming CL will fix the bug and update the tests.

Bug: 173068192
Test: test-only change
Change-Id: I7805444dcf59f6d5f8517fbcf2f2b1641783d50b
2021-04-05 14:51:53 +09:00
Lorenzo Colitti
a8402cec06 Dump the input destination MAC address for IPv4 flows. am: e9bc8c9db7 am: a16ca88456 am: cf257bb217
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1662403

Change-Id: I6c92f144be4979bdfa6c98462f56c86ef006eedc
2021-04-02 10:50:22 +00:00
Lorenzo Colitti
6ca408f317 Dump the input destination MAC address for IPv4 flows. am: e9bc8c9db7 am: a16ca88456
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1662403

Change-Id: Ib095466f92872d50cc751b34cc870df31dc8e345
2021-04-02 10:06:09 +00:00
Lorenzo Colitti
cf257bb217 Dump the input destination MAC address for IPv4 flows. am: e9bc8c9db7 am: a16ca88456
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1662403

Change-Id: I6725ba6f2d2fb07b05f85ac1cacd2ea22e6a5d84
2021-04-02 10:01:25 +00:00
Lorenzo Colitti
e9bc8c9db7 Dump the input destination MAC address for IPv4 flows.
This is needed for forwarding to work, so it should be dumped.

New output:

  Forwarding rules:
    29(29) -> 14(rmnet2) 86dd 00:00:00:00:00:00 00:00:00:00:00:00
    [ap_br_wlan2]: iif(iface) oif(iface) v6addr srcmac dstmac
      14(rmnet2) 29(ap_br_wlan2) 2001:240:2423:13fa:3c21:e35a:6a59:ff8a da:17:fd:70:3d:14 26:5b:b2:ee:bc:ba
    IPv4: [inDstMac] iif(iface) src -> nat -> dst
      [da:17:fd:70:3d:14] 29(29) 192.168.222.151:39208 -> 14(rmnet2) 100.102.14.231:39208 -> 172.217.175.3:80
      [da:17:fd:70:3d:14] 29(29) 192.168.222.151:47386 -> 14(rmnet2) 100.102.14.231:47386 -> 216.58.197.196:443

Also add a call to getHostAddress() to remove the / on IPv6
forwarding rules.

Test: manual
Change-Id: I347ea5a3fd88c51f1fae0c76c75dfa30c68a55ad
2021-04-02 05:42:22 +00:00
Remi NGUYEN VAN
9980f77bc2 Merge "Allow connectivity tests to use hidden APIs" into sc-dev 2021-04-02 02:18:51 +00:00
Aaron Huang
b3cc853814 Merge "Update import class of TAG_SYSTEM_NEIGHBOR" am: 5316e1ff18 am: 9c3cfaa9b8
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1626079

Change-Id: Ic491a32bbc6bb8173f15f491adb31a942eb7e773
2021-04-01 16:45:23 +00:00
Aaron Huang
985a17dfae Merge "Update import class of TAG_SYSTEM_NEIGHBOR" am: 5316e1ff18 am: 9c3cfaa9b8
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1626079

Change-Id: I11f5bf7f264d48d6ad0dab63aace39fc85251cf0
2021-04-01 16:45:13 +00:00
Aaron Huang
5316e1ff18 Merge "Update import class of TAG_SYSTEM_NEIGHBOR" 2021-04-01 15:59:39 +00:00
Lorenzo Colitti
daab695c62 Rename members in TestConnectivityManager. am: 9bbdac6275 am: a6d9d23180 am: cece10d4e0
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1659938

Change-Id: I3aefc96deeb0cbed9bc608c3435e18cda174b391
2021-04-01 09:26:23 +00:00
Lorenzo Colitti
7ba849ee98 Add the ability to affect ordering in the tethering unit tests. am: 3e09f80e8a am: bdb012f733 am: a116b7f370
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1635021

Change-Id: I1ebce83cee60c2b5adc2102a7bda23b9c06460e2
2021-04-01 09:26:22 +00:00
Lorenzo Colitti
cfe964feac Make Tethering file NetworkRequests only if needed. am: 2bcde0fd97 am: cce64f0dd7 am: bd868cd5d0
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1556199

Change-Id: I5e1059993a86ec1fdd5bb9a7001683af5dcd6b57
2021-04-01 09:26:21 +00:00
Lorenzo Colitti
a403fd6c1a Expose upstream requirements to UpstreamNetworkMonitor. am: 0e7e32ab2c am: 9dcd8587ed am: 9902d8c14f
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1556198

Change-Id: Ie3d1ea858e3582ff84a409efb4403bac0b609993
2021-04-01 09:26:19 +00:00
Lorenzo Colitti
4a5ef290d1 Rename members in TestConnectivityManager. am: 9bbdac6275 am: a6d9d23180
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1659938

Change-Id: I71d41b70504eee31bd7ab235e1325e7f689a60c5
2021-04-01 08:39:18 +00:00
Lorenzo Colitti
cf5967991b Add the ability to affect ordering in the tethering unit tests. am: 3e09f80e8a am: bdb012f733
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1635021

Change-Id: Id3a48f7092e0bed9f28cd4896a7d62ad82239758
2021-04-01 08:39:17 +00:00
Lorenzo Colitti
cece10d4e0 Rename members in TestConnectivityManager. am: 9bbdac6275 am: a6d9d23180
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1659938

Change-Id: If02ce4eed9804d705a575fe7171459dafba216c9
2021-04-01 08:39:16 +00:00
Lorenzo Colitti
ef85c9dcc4 Make Tethering file NetworkRequests only if needed. am: 2bcde0fd97 am: cce64f0dd7
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1556199

Change-Id: Id07332dfcdd7f3430a67fc7a7dcade4139c7c4ab
2021-04-01 08:39:16 +00:00
Lorenzo Colitti
a116b7f370 Add the ability to affect ordering in the tethering unit tests. am: 3e09f80e8a am: bdb012f733
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1635021

Change-Id: Iee27da6e7f6972564ee062e789905197e8994aa9
2021-04-01 08:39:15 +00:00
Lorenzo Colitti
bd868cd5d0 Make Tethering file NetworkRequests only if needed. am: 2bcde0fd97 am: cce64f0dd7
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1556199

Change-Id: I66b565a18a850c020f1289566c646bdda1b6bd94
2021-04-01 08:39:15 +00:00
Lorenzo Colitti
ce664ec1cf Expose upstream requirements to UpstreamNetworkMonitor. am: 0e7e32ab2c am: 9dcd8587ed
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1556198

Change-Id: I285334ac1096dcbd3102961f4d9bd7f44f2dcded
2021-04-01 08:39:15 +00:00
Lorenzo Colitti
9902d8c14f Expose upstream requirements to UpstreamNetworkMonitor. am: 0e7e32ab2c am: 9dcd8587ed
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1556198

Change-Id: I47a5bdced72c17ecc5182f57623de1ae21f29036
2021-04-01 08:39:14 +00:00
Remi NGUYEN VAN
eeeed136e0 Allow connectivity tests to use hidden APIs
The tests have been building against hidden APIs to provide additional
coverage.

Test: m TetheringCoverageTests CtsNetTestCases
Bug: 182859030
Ignore-AOSP-First: needs manual cherry-picks
Change-Id: I37d748411a34f25834214a2412c49aed1423e526
2021-04-01 06:37:53 +00:00
Lorenzo Colitti
9bbdac6275 Rename members in TestConnectivityManager.
These members are public mutable and their names are confusing.
Make them package-private and final.

Bug: 173068192
Test: test-only change
Change-Id: I87131c48f67b6614c25aa99e1cbc53196f49aa7c
2021-03-31 20:23:20 +09:00
Lorenzo Colitti
3e09f80e8a Add the ability to affect ordering in the tethering unit tests.
Currently, TestConnectivityManager immediately sends all
callbacks and broadcasts to the Tethering code as soon as the
test code makes any change.

This makes it impossible to affect the order in which those
events are delivered to the Tethering code, so it is not possible
to test for races.

Fix some of this as follows:
1. Make TestConnectivityManager post all its callbacks to the
   handlers that Tethering registered them with.
2. In TetheringTest, use the existing TestLooper object to
   advance time manually. Also use setUseRegisteredHandlers to
   ensure that the broadcasts are sent in order. This requires
   calling dispatchAll() after sending the broadcast to preserve
   the existing synchronous behaviour. Take advantage of that to
   remove lots of existing dispatchAll calls.
3. Add a TestLooper to UpstreamNetworkMonitorTest and use it.
   Keep the test passing by adding lots of mLooper.dispatchAll(),
   which is a bit ugly but probably acceptable given the
   additional coverage it provides.

This exposes an existing bug in the code where if upstream
selection is in automatic mode, and all CONNECTIVITY_ACTION
broadcasts are received before all NetworkCallbacks, the code
does not switch upstream.

In order to make the tests pass, re-order the CONNECTIVITY_ACTION
broadcasts with the NetworkCallbacks in TestConnectivityManager
so as not to trigger the bug. A future CL will make the order
configurable.

While I'm at it, switch TestConnectivityManager from HashMap to
ArrayMap, which is generally preferred for maps that do not
contain too many elements.

Bug: 173068192
Test: test-only change
Change-Id: I964f365c691fbc396ab0a87f292bd32b123011fe
2021-03-31 20:17:11 +09:00
Lorenzo Colitti
2bcde0fd97 Make Tethering file NetworkRequests only if needed.
Currently, Tethering files NetworkRequests even when
config_tether_upstream_automatic is enabled. This is incorrect:
when the automatic upstream selection is enabled, the tethering
upstream should always follow the default network and there is
no need to file any requests.

These requests are harmful when tethering is not using cellular
as its upstream, because:

- If the device does not use mobile data always on, the request
  causes the cellular network to be brought up, causing power
  draw.
- Even if the device does use mobile data always on, the request
  causes the cellular network to come to the foreground, which
  allows all apps to access it, causing potential data usage.

Amend the existing testGetCurrentPreferredUpstream to cover these
changes, by making that test case always set automatic upstream
mode. This does not result in any loss of meaningful test
coverage, because getCurrentPreferredUpstream is only ever called
when chooseUpstreamAutomatically is enabled.

Bug: 173068192
Test: atest TetheringTests
Change-Id: I068a5338699a3ed04f24f97f785ea89ff5890e50
2021-03-31 19:27:17 +09:00
Lorenzo Colitti
0e7e32ab2c Expose upstream requirements to UpstreamNetworkMonitor.
UpstreamNetworkMonitor is the part of tethering that files
NetworkRequests for upstream netwoks, but it currently does not
know all the requirements for upstream selection. For example, it
does not know whether automatic upstream selection is in use.
This forces the upstream selection code to be split between
UpstreamNetworkMonitor and Tethering. This makes it difficult to
follow.

This CL ensures that all information about upstream requirements
(DUN required, automatic upstream selection, tryCell) is passed
to UpstreamNetworkMonitor so it can be aware of it.

This CL also removes the ability for UpstreamNetworkMonitor's
callers to call registerMobileNetworkRequest or
releaseMobileNetworkRequest. In a future CL, this will be
automatically done by UpstreamNetworkMonitor depending on the
upstream requirements.

This CL is a no-op refactoring with no behaviour changes.

Bug: 173068192
Test: atest TetheringTests
Change-Id: I174f765c616e0dbe2aa493c12613e6131cff0666
2021-03-31 19:27:17 +09:00
Remi NGUYEN VAN
6d575cace8 Add framework-connectivity to the Tethering APEX
Add framework-connectivity and its jni library dependency to the APEX.

Bug: 171540887
Test: device boots, has connectivity
Ignore-AOSP-First: Merge conflicts, will cherry-pick

Change-Id: I72fc7fee7bfcd909cbc79b4c34e8b3f29055d378
2021-03-24 23:05:29 +09:00
Remi NGUYEN VAN
02b94faf80 Reference framework-connectivity stubs explicitly
To merge the framework-connectivity and framework-connectivity.impl
targets, framework-connectivity stubs need to be referenced explicitly
in java_sdk_libraries, otherwise the build system will currently see
dependency cycles.

Bug: 183600168
Test: m
Ignore-AOSP-First: Needs manual cherry-picks
Change-Id: I556747f9ba934f8b44b6ea9a518adbccc84ac2a9
2021-03-24 23:05:13 +09:00
Remi NGUYEN VAN
836e3e1276 Merge "Add framework-connectivity to tethering tests" into sc-dev 2021-03-22 04:19:31 +00:00
Remi NGUYEN VAN
34d197bc2d Add framework-connectivity to tethering tests
This is necessary for tethering tests to build against hidden
framework-connectivity APIs after it is moved out of
framework-minus-apex.

Bug: 179229316
Test: atest TetheringTests
Ignore-AOSP-First: Need manual cherry-picks
Change-Id: I912fcd19bacb75a5944409b07d8e014032657d4a
2021-03-19 13:16:01 +00:00
Maciej Żenczykowski
3f3743eb65 bpf_progs - remove unused dependencies am: b1ffd2ce9b am: 2f780deb38 am: d65201b5a1
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1646235

Change-Id: Ie77273c3c40707d4324c1930a5be715968c0c2f8
2021-03-19 10:50:04 +00:00
Maciej Żenczykowski
d65201b5a1 bpf_progs - remove unused dependencies am: b1ffd2ce9b am: 2f780deb38
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1646235

Change-Id: I7fbb943db076cf3a70686a9c208bc82798a02cf1
2021-03-19 09:58:37 +00:00
Maciej Żenczykowski
b40575e832 bpf_progs - remove unused dependencies am: b1ffd2ce9b am: 2f780deb38
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1646235

Change-Id: I3b51769d1bb88d5febc1800d93cd7fcc6f6c13b3
2021-03-19 09:57:58 +00:00
Maciej Żenczykowski
b1ffd2ce9b bpf_progs - remove unused dependencies
Test: builds, atest, TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I9414bde566bb73b696593587db854de3fb14cdcc
2021-03-19 03:39:42 +00:00
Maciej Żenczykowski
13218831c5 Merge changes Ibe325714,I44f3dc9e am: 63be468bf4 am: 3828871130 am: cfd48295b3
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1644628

Change-Id: I9641a9838fb5d5a970e869530ab7399d23dc89da
2021-03-18 23:08:04 +00:00
Maciej Żenczykowski
cfd48295b3 Merge changes Ibe325714,I44f3dc9e am: 63be468bf4 am: 3828871130
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1644628

Change-Id: I456582e52c4991fb5e1c53e772ef14621d5434d6
2021-03-18 22:42:04 +00:00
Maciej Żenczykowski
5066bb74a5 Merge changes Ibe325714,I44f3dc9e am: 63be468bf4 am: 3828871130
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1644628

Change-Id: I1636d12476f44d6b1e92ecc6d5335626cc07ea76
2021-03-18 22:41:56 +00:00
Maciej Żenczykowski
3f32a83207 fix whitespace in offload.c macro
Test: atest, TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ibe325714f95a1accce8add16220a31ca15913816
2021-03-18 02:34:01 -07:00
Maciej Żenczykowski
af1f314cbd change PRIO_CLAT into a comment
Test: atest, TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I44f3dc9e3a3462f275a04ed5601370f664b985a2
2021-03-18 02:33:56 -07:00
Aaron Huang
e931b159dd Update import class of TAG_SYSTEM_NEIGHBOR
TrafficStatsConstants.TAG_SYSTEM_NEIGHBOR is moved to
NetworkStackConstants so update the import class name for it.

Bug: 182349970
Test: FrameworksNetTests
      NetworkStackTests
      TetheringTests
Change-Id: I8fcd2772ed873d318233d3029184e4352245d4cd
Merged-In: I8fcd2772ed873d318233d3029184e4352245d4cd
2021-03-17 14:03:07 +08:00
Kimberly Kreider
38e41e4404 Merge "Enable networking tests to be included in partial MTS files as well as full mts." am: 6f4d35119f am: 8266302ee7 am: 17eae52145
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1531141

Change-Id: Ic16ee449e5eec1e947ac215d5aa27845c0e2e675
2021-03-17 03:48:42 +00:00
Aaron Huang
517cfad3e6 Merge "Update import class of TAG_SYSTEM_NEIGHBOR" into sc-dev 2021-03-17 03:16:56 +00:00
Kimberly Kreider
56c0b8c40a Merge "Enable networking tests to be included in partial MTS files as well as full mts." am: 6f4d35119f am: 8266302ee7
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1531141

Change-Id: Ida996c15aeed86febda6a44aa3625f53a882fda0
2021-03-17 03:07:45 +00:00
Kimberly Kreider
17eae52145 Merge "Enable networking tests to be included in partial MTS files as well as full mts." am: 6f4d35119f am: 8266302ee7
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1531141

Change-Id: Id1fc29e6bfcc8422a2a2b8b0f609035b6ab9ae09
2021-03-17 03:07:27 +00:00
Kimberly Kreider
6f4d35119f Merge "Enable networking tests to be included in partial MTS files as well as full mts." 2021-03-17 02:23:54 +00:00