Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.connectivity.tethering; |
| 18 | |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 19 | import static android.net.NetworkStats.SET_DEFAULT; |
Lorenzo Colitti | f1912ca | 2017-08-17 19:23:08 +0900 | [diff] [blame] | 20 | import static android.net.NetworkStats.STATS_PER_IFACE; |
| 21 | import static android.net.NetworkStats.STATS_PER_UID; |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 22 | import static android.net.NetworkStats.TAG_NONE; |
Lorenzo Colitti | f1912ca | 2017-08-17 19:23:08 +0900 | [diff] [blame] | 23 | import static android.net.NetworkStats.UID_ALL; |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 24 | import static android.net.TrafficStats.UID_TETHERING; |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 25 | import static android.provider.Settings.Global.TETHER_OFFLOAD_DISABLED; |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 26 | import static com.android.server.connectivity.tethering.OffloadHardwareInterface.ForwardedStats; |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 27 | import static org.junit.Assert.assertEquals; |
| 28 | import static org.junit.Assert.assertTrue; |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 29 | import static org.junit.Assert.fail; |
| 30 | import static org.mockito.Matchers.any; |
Lorenzo Colitti | 50b60fc | 2017-08-11 13:47:49 +0900 | [diff] [blame] | 31 | import static org.mockito.Matchers.anyLong; |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 32 | import static org.mockito.Matchers.anyObject; |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 33 | import static org.mockito.Matchers.anyString; |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 34 | import static org.mockito.Matchers.eq; |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 35 | import static org.mockito.Mockito.doNothing; |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 36 | import static org.mockito.Mockito.inOrder; |
| 37 | import static org.mockito.Mockito.never; |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 38 | import static org.mockito.Mockito.reset; |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 39 | import static org.mockito.Mockito.times; |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 40 | import static org.mockito.Mockito.verify; |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 41 | import static org.mockito.Mockito.when; |
| 42 | |
| 43 | import android.content.Context; |
Erik Kline | ec37275 | 2017-06-07 16:33:19 +0900 | [diff] [blame] | 44 | import android.content.pm.ApplicationInfo; |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 45 | import android.net.ITetheringStatsProvider; |
Erik Kline | 5acb4e3 | 2017-07-04 18:28:11 +0900 | [diff] [blame] | 46 | import android.net.IpPrefix; |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 47 | import android.net.LinkAddress; |
| 48 | import android.net.LinkProperties; |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 49 | import android.net.NetworkStats; |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 50 | import android.net.RouteInfo; |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 51 | import android.net.util.SharedLog; |
Lorenzo Colitti | 50b60fc | 2017-08-11 13:47:49 +0900 | [diff] [blame] | 52 | import android.os.ConditionVariable; |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 53 | import android.os.Handler; |
| 54 | import android.os.Looper; |
| 55 | import android.os.INetworkManagementService; |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 56 | import android.provider.Settings; |
| 57 | import android.provider.Settings.SettingNotFoundException; |
| 58 | |
| 59 | import android.support.test.filters.SmallTest; |
| 60 | import android.support.test.runner.AndroidJUnit4; |
| 61 | import android.test.mock.MockContentResolver; |
| 62 | import com.android.internal.util.test.FakeSettingsProvider; |
| 63 | |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 64 | import java.net.InetAddress; |
| 65 | import java.util.ArrayList; |
Erik Kline | 5acb4e3 | 2017-07-04 18:28:11 +0900 | [diff] [blame] | 66 | import java.util.HashSet; |
| 67 | import java.util.Set; |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 68 | |
Erik Kline | 5eaa7ed | 2017-07-07 17:38:30 +0900 | [diff] [blame] | 69 | import org.junit.After; |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 70 | import org.junit.Before; |
| 71 | import org.junit.runner.RunWith; |
| 72 | import org.junit.Test; |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 73 | import org.mockito.ArgumentCaptor; |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 74 | import org.mockito.InOrder; |
| 75 | import org.mockito.Mock; |
| 76 | import org.mockito.MockitoAnnotations; |
| 77 | |
| 78 | |
| 79 | @RunWith(AndroidJUnit4.class) |
| 80 | @SmallTest |
| 81 | public class OffloadControllerTest { |
| 82 | |
| 83 | @Mock private OffloadHardwareInterface mHardware; |
Erik Kline | ec37275 | 2017-06-07 16:33:19 +0900 | [diff] [blame] | 84 | @Mock private ApplicationInfo mApplicationInfo; |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 85 | @Mock private Context mContext; |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 86 | @Mock private INetworkManagementService mNMService; |
Erik Kline | dd4d582 | 2017-06-12 18:20:08 +0900 | [diff] [blame] | 87 | private final ArgumentCaptor<ArrayList> mStringArrayCaptor = |
| 88 | ArgumentCaptor.forClass(ArrayList.class); |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 89 | private final ArgumentCaptor<ITetheringStatsProvider.Stub> mTetherStatsProviderCaptor = |
| 90 | ArgumentCaptor.forClass(ITetheringStatsProvider.Stub.class); |
Lorenzo Colitti | 9f0baa9 | 2017-08-15 19:25:51 +0900 | [diff] [blame] | 91 | private final ArgumentCaptor<OffloadHardwareInterface.ControlCallback> mControlCallbackCaptor = |
| 92 | ArgumentCaptor.forClass(OffloadHardwareInterface.ControlCallback.class); |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 93 | private MockContentResolver mContentResolver; |
| 94 | |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 95 | @Before public void setUp() { |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 96 | MockitoAnnotations.initMocks(this); |
Erik Kline | ec37275 | 2017-06-07 16:33:19 +0900 | [diff] [blame] | 97 | when(mContext.getApplicationInfo()).thenReturn(mApplicationInfo); |
| 98 | when(mContext.getPackageName()).thenReturn("OffloadControllerTest"); |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 99 | mContentResolver = new MockContentResolver(mContext); |
| 100 | mContentResolver.addProvider(Settings.AUTHORITY, new FakeSettingsProvider()); |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 101 | when(mContext.getContentResolver()).thenReturn(mContentResolver); |
Erik Kline | 5eaa7ed | 2017-07-07 17:38:30 +0900 | [diff] [blame] | 102 | // TODO: call this when available. |
| 103 | // FakeSettingsProvider.clearSettingsProvider(); |
| 104 | } |
| 105 | |
| 106 | @After public void tearDown() throws Exception { |
| 107 | // TODO: call this when available. |
| 108 | // FakeSettingsProvider.clearSettingsProvider(); |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | private void setupFunctioningHardwareInterface() { |
| 112 | when(mHardware.initOffloadConfig()).thenReturn(true); |
Lorenzo Colitti | 9f0baa9 | 2017-08-15 19:25:51 +0900 | [diff] [blame] | 113 | when(mHardware.initOffloadControl(mControlCallbackCaptor.capture())) |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 114 | .thenReturn(true); |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 115 | when(mHardware.getForwardedStats(any())).thenReturn(new ForwardedStats()); |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 116 | } |
| 117 | |
Erik Kline | 5eaa7ed | 2017-07-07 17:38:30 +0900 | [diff] [blame] | 118 | private void enableOffload() { |
| 119 | Settings.Global.putInt(mContentResolver, TETHER_OFFLOAD_DISABLED, 0); |
| 120 | } |
| 121 | |
Lorenzo Colitti | 50b60fc | 2017-08-11 13:47:49 +0900 | [diff] [blame] | 122 | private void waitForIdle() { |
| 123 | ConditionVariable cv = new ConditionVariable(); |
| 124 | new Handler(Looper.getMainLooper()).post(() -> { cv.open(); }); |
| 125 | cv.block(); |
| 126 | } |
| 127 | |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 128 | private OffloadController makeOffloadController() throws Exception { |
| 129 | OffloadController offload = new OffloadController(new Handler(Looper.getMainLooper()), |
| 130 | mHardware, mContentResolver, mNMService, new SharedLog("test")); |
| 131 | verify(mNMService).registerTetheringStatsProvider( |
| 132 | mTetherStatsProviderCaptor.capture(), anyString()); |
| 133 | return offload; |
| 134 | } |
| 135 | |
Erik Kline | 5eaa7ed | 2017-07-07 17:38:30 +0900 | [diff] [blame] | 136 | // TODO: Restore when FakeSettingsProvider.clearSettingsProvider() is available. |
| 137 | // @Test |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 138 | public void testNoSettingsValueDefaultDisabledDoesNotStart() throws Exception { |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 139 | setupFunctioningHardwareInterface(); |
Erik Kline | 5eaa7ed | 2017-07-07 17:38:30 +0900 | [diff] [blame] | 140 | when(mHardware.getDefaultTetherOffloadDisabled()).thenReturn(1); |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 141 | try { |
| 142 | Settings.Global.getInt(mContentResolver, TETHER_OFFLOAD_DISABLED); |
| 143 | fail(); |
| 144 | } catch (SettingNotFoundException expected) {} |
| 145 | |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 146 | final OffloadController offload = makeOffloadController(); |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 147 | offload.start(); |
| 148 | |
| 149 | final InOrder inOrder = inOrder(mHardware); |
Erik Kline | 5eaa7ed | 2017-07-07 17:38:30 +0900 | [diff] [blame] | 150 | inOrder.verify(mHardware, times(1)).getDefaultTetherOffloadDisabled(); |
| 151 | inOrder.verify(mHardware, never()).initOffloadConfig(); |
| 152 | inOrder.verify(mHardware, never()).initOffloadControl( |
| 153 | any(OffloadHardwareInterface.ControlCallback.class)); |
| 154 | inOrder.verifyNoMoreInteractions(); |
| 155 | } |
| 156 | |
| 157 | // TODO: Restore when FakeSettingsProvider.clearSettingsProvider() is available. |
| 158 | // @Test |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 159 | public void testNoSettingsValueDefaultEnabledDoesStart() throws Exception { |
Erik Kline | 5eaa7ed | 2017-07-07 17:38:30 +0900 | [diff] [blame] | 160 | setupFunctioningHardwareInterface(); |
| 161 | when(mHardware.getDefaultTetherOffloadDisabled()).thenReturn(0); |
| 162 | try { |
| 163 | Settings.Global.getInt(mContentResolver, TETHER_OFFLOAD_DISABLED); |
| 164 | fail(); |
| 165 | } catch (SettingNotFoundException expected) {} |
| 166 | |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 167 | final OffloadController offload = makeOffloadController(); |
Erik Kline | 5eaa7ed | 2017-07-07 17:38:30 +0900 | [diff] [blame] | 168 | offload.start(); |
| 169 | |
| 170 | final InOrder inOrder = inOrder(mHardware); |
| 171 | inOrder.verify(mHardware, times(1)).getDefaultTetherOffloadDisabled(); |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 172 | inOrder.verify(mHardware, times(1)).initOffloadConfig(); |
| 173 | inOrder.verify(mHardware, times(1)).initOffloadControl( |
| 174 | any(OffloadHardwareInterface.ControlCallback.class)); |
| 175 | inOrder.verifyNoMoreInteractions(); |
| 176 | } |
| 177 | |
| 178 | @Test |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 179 | public void testSettingsAllowsStart() throws Exception { |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 180 | setupFunctioningHardwareInterface(); |
| 181 | Settings.Global.putInt(mContentResolver, TETHER_OFFLOAD_DISABLED, 0); |
| 182 | |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 183 | final OffloadController offload = makeOffloadController(); |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 184 | offload.start(); |
| 185 | |
| 186 | final InOrder inOrder = inOrder(mHardware); |
Erik Kline | 5eaa7ed | 2017-07-07 17:38:30 +0900 | [diff] [blame] | 187 | inOrder.verify(mHardware, times(1)).getDefaultTetherOffloadDisabled(); |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 188 | inOrder.verify(mHardware, times(1)).initOffloadConfig(); |
| 189 | inOrder.verify(mHardware, times(1)).initOffloadControl( |
| 190 | any(OffloadHardwareInterface.ControlCallback.class)); |
| 191 | inOrder.verifyNoMoreInteractions(); |
| 192 | } |
| 193 | |
| 194 | @Test |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 195 | public void testSettingsDisablesStart() throws Exception { |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 196 | setupFunctioningHardwareInterface(); |
| 197 | Settings.Global.putInt(mContentResolver, TETHER_OFFLOAD_DISABLED, 1); |
| 198 | |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 199 | final OffloadController offload = makeOffloadController(); |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 200 | offload.start(); |
| 201 | |
| 202 | final InOrder inOrder = inOrder(mHardware); |
Erik Kline | 5eaa7ed | 2017-07-07 17:38:30 +0900 | [diff] [blame] | 203 | inOrder.verify(mHardware, times(1)).getDefaultTetherOffloadDisabled(); |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 204 | inOrder.verify(mHardware, never()).initOffloadConfig(); |
| 205 | inOrder.verify(mHardware, never()).initOffloadControl(anyObject()); |
| 206 | inOrder.verifyNoMoreInteractions(); |
| 207 | } |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 208 | |
| 209 | @Test |
| 210 | public void testSetUpstreamLinkPropertiesWorking() throws Exception { |
| 211 | setupFunctioningHardwareInterface(); |
Erik Kline | 5eaa7ed | 2017-07-07 17:38:30 +0900 | [diff] [blame] | 212 | enableOffload(); |
| 213 | |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 214 | final OffloadController offload = makeOffloadController(); |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 215 | offload.start(); |
| 216 | |
| 217 | final InOrder inOrder = inOrder(mHardware); |
Erik Kline | 5eaa7ed | 2017-07-07 17:38:30 +0900 | [diff] [blame] | 218 | inOrder.verify(mHardware, times(1)).getDefaultTetherOffloadDisabled(); |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 219 | inOrder.verify(mHardware, times(1)).initOffloadConfig(); |
| 220 | inOrder.verify(mHardware, times(1)).initOffloadControl( |
| 221 | any(OffloadHardwareInterface.ControlCallback.class)); |
| 222 | inOrder.verifyNoMoreInteractions(); |
| 223 | |
Erik Kline | 5acb4e3 | 2017-07-04 18:28:11 +0900 | [diff] [blame] | 224 | // In reality, the UpstreamNetworkMonitor would have passed down to us |
| 225 | // a covering set of local prefixes representing a minimum essential |
| 226 | // set plus all the prefixes on networks with network agents. |
| 227 | // |
| 228 | // We simulate that there, and then add upstream elements one by one |
| 229 | // and watch what happens. |
| 230 | final Set<IpPrefix> minimumLocalPrefixes = new HashSet<>(); |
| 231 | for (String s : new String[]{ |
| 232 | "127.0.0.0/8", "192.0.2.0/24", "fe80::/64", "2001:db8::/64"}) { |
| 233 | minimumLocalPrefixes.add(new IpPrefix(s)); |
| 234 | } |
| 235 | offload.setLocalPrefixes(minimumLocalPrefixes); |
| 236 | inOrder.verify(mHardware, times(1)).setLocalPrefixes(mStringArrayCaptor.capture()); |
| 237 | ArrayList<String> localPrefixes = mStringArrayCaptor.getValue(); |
| 238 | assertEquals(4, localPrefixes.size()); |
| 239 | assertTrue(localPrefixes.contains("127.0.0.0/8")); |
| 240 | assertTrue(localPrefixes.contains("192.0.2.0/24")); |
| 241 | assertTrue(localPrefixes.contains("fe80::/64")); |
| 242 | assertTrue(localPrefixes.contains("2001:db8::/64")); |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 243 | inOrder.verifyNoMoreInteractions(); |
Erik Kline | 5acb4e3 | 2017-07-04 18:28:11 +0900 | [diff] [blame] | 244 | |
| 245 | offload.setUpstreamLinkProperties(null); |
| 246 | // No change in local addresses means no call to setLocalPrefixes(). |
| 247 | inOrder.verify(mHardware, never()).setLocalPrefixes(mStringArrayCaptor.capture()); |
| 248 | // This LinkProperties value does not differ from the default upstream. |
| 249 | // There should be no extraneous call to setUpstreamParameters(). |
| 250 | inOrder.verify(mHardware, never()).setUpstreamParameters( |
| 251 | anyObject(), anyObject(), anyObject(), anyObject()); |
| 252 | inOrder.verifyNoMoreInteractions(); |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 253 | |
| 254 | final LinkProperties lp = new LinkProperties(); |
| 255 | |
| 256 | final String testIfName = "rmnet_data17"; |
| 257 | lp.setInterfaceName(testIfName); |
| 258 | offload.setUpstreamLinkProperties(lp); |
Erik Kline | 5acb4e3 | 2017-07-04 18:28:11 +0900 | [diff] [blame] | 259 | // No change in local addresses means no call to setLocalPrefixes(). |
| 260 | inOrder.verify(mHardware, never()).setLocalPrefixes(mStringArrayCaptor.capture()); |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 261 | inOrder.verify(mHardware, times(1)).setUpstreamParameters( |
Erik Kline | 664d208 | 2017-06-15 18:06:34 +0900 | [diff] [blame] | 262 | eq(testIfName), eq(null), eq(null), eq(null)); |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 263 | inOrder.verifyNoMoreInteractions(); |
| 264 | |
| 265 | final String ipv4Addr = "192.0.2.5"; |
| 266 | final String linkAddr = ipv4Addr + "/24"; |
| 267 | lp.addLinkAddress(new LinkAddress(linkAddr)); |
Erik Kline | 5acb4e3 | 2017-07-04 18:28:11 +0900 | [diff] [blame] | 268 | lp.addRoute(new RouteInfo(new IpPrefix("192.0.2.0/24"))); |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 269 | offload.setUpstreamLinkProperties(lp); |
Erik Kline | 5acb4e3 | 2017-07-04 18:28:11 +0900 | [diff] [blame] | 270 | // IPv4 prefixes and addresses on the upstream are simply left as whole |
| 271 | // prefixes (already passed in from UpstreamNetworkMonitor code). If a |
| 272 | // tethering client sends traffic to the IPv4 default router or other |
| 273 | // clients on the upstream this will not be hardware-forwarded, and that |
| 274 | // should be fine for now. Ergo: no change in local addresses, no call |
| 275 | // to setLocalPrefixes(). |
| 276 | inOrder.verify(mHardware, never()).setLocalPrefixes(mStringArrayCaptor.capture()); |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 277 | inOrder.verify(mHardware, times(1)).setUpstreamParameters( |
Erik Kline | 664d208 | 2017-06-15 18:06:34 +0900 | [diff] [blame] | 278 | eq(testIfName), eq(ipv4Addr), eq(null), eq(null)); |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 279 | inOrder.verify(mHardware, times(1)).getForwardedStats(eq(testIfName)); |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 280 | inOrder.verifyNoMoreInteractions(); |
| 281 | |
| 282 | final String ipv4Gateway = "192.0.2.1"; |
| 283 | lp.addRoute(new RouteInfo(InetAddress.getByName(ipv4Gateway))); |
| 284 | offload.setUpstreamLinkProperties(lp); |
Erik Kline | 5acb4e3 | 2017-07-04 18:28:11 +0900 | [diff] [blame] | 285 | // No change in local addresses means no call to setLocalPrefixes(). |
| 286 | inOrder.verify(mHardware, never()).setLocalPrefixes(mStringArrayCaptor.capture()); |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 287 | inOrder.verify(mHardware, times(1)).setUpstreamParameters( |
Erik Kline | 664d208 | 2017-06-15 18:06:34 +0900 | [diff] [blame] | 288 | eq(testIfName), eq(ipv4Addr), eq(ipv4Gateway), eq(null)); |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 289 | inOrder.verify(mHardware, times(1)).getForwardedStats(eq(testIfName)); |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 290 | inOrder.verifyNoMoreInteractions(); |
| 291 | |
| 292 | final String ipv6Gw1 = "fe80::cafe"; |
| 293 | lp.addRoute(new RouteInfo(InetAddress.getByName(ipv6Gw1))); |
| 294 | offload.setUpstreamLinkProperties(lp); |
Erik Kline | 5acb4e3 | 2017-07-04 18:28:11 +0900 | [diff] [blame] | 295 | // No change in local addresses means no call to setLocalPrefixes(). |
| 296 | inOrder.verify(mHardware, never()).setLocalPrefixes(mStringArrayCaptor.capture()); |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 297 | inOrder.verify(mHardware, times(1)).setUpstreamParameters( |
| 298 | eq(testIfName), eq(ipv4Addr), eq(ipv4Gateway), mStringArrayCaptor.capture()); |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 299 | inOrder.verify(mHardware, times(1)).getForwardedStats(eq(testIfName)); |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 300 | ArrayList<String> v6gws = mStringArrayCaptor.getValue(); |
| 301 | assertEquals(1, v6gws.size()); |
| 302 | assertTrue(v6gws.contains(ipv6Gw1)); |
| 303 | inOrder.verifyNoMoreInteractions(); |
| 304 | |
| 305 | final String ipv6Gw2 = "fe80::d00d"; |
| 306 | lp.addRoute(new RouteInfo(InetAddress.getByName(ipv6Gw2))); |
| 307 | offload.setUpstreamLinkProperties(lp); |
Erik Kline | 5acb4e3 | 2017-07-04 18:28:11 +0900 | [diff] [blame] | 308 | // No change in local addresses means no call to setLocalPrefixes(). |
| 309 | inOrder.verify(mHardware, never()).setLocalPrefixes(mStringArrayCaptor.capture()); |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 310 | inOrder.verify(mHardware, times(1)).setUpstreamParameters( |
| 311 | eq(testIfName), eq(ipv4Addr), eq(ipv4Gateway), mStringArrayCaptor.capture()); |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 312 | inOrder.verify(mHardware, times(1)).getForwardedStats(eq(testIfName)); |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 313 | v6gws = mStringArrayCaptor.getValue(); |
| 314 | assertEquals(2, v6gws.size()); |
| 315 | assertTrue(v6gws.contains(ipv6Gw1)); |
| 316 | assertTrue(v6gws.contains(ipv6Gw2)); |
| 317 | inOrder.verifyNoMoreInteractions(); |
| 318 | |
| 319 | final LinkProperties stacked = new LinkProperties(); |
| 320 | stacked.setInterfaceName("stacked"); |
| 321 | stacked.addLinkAddress(new LinkAddress("192.0.2.129/25")); |
| 322 | stacked.addRoute(new RouteInfo(InetAddress.getByName("192.0.2.254"))); |
| 323 | stacked.addRoute(new RouteInfo(InetAddress.getByName("fe80::bad:f00"))); |
| 324 | assertTrue(lp.addStackedLink(stacked)); |
| 325 | offload.setUpstreamLinkProperties(lp); |
Erik Kline | 5acb4e3 | 2017-07-04 18:28:11 +0900 | [diff] [blame] | 326 | // No change in local addresses means no call to setLocalPrefixes(). |
| 327 | inOrder.verify(mHardware, never()).setLocalPrefixes(mStringArrayCaptor.capture()); |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 328 | inOrder.verify(mHardware, times(1)).setUpstreamParameters( |
| 329 | eq(testIfName), eq(ipv4Addr), eq(ipv4Gateway), mStringArrayCaptor.capture()); |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 330 | inOrder.verify(mHardware, times(1)).getForwardedStats(eq(testIfName)); |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 331 | v6gws = mStringArrayCaptor.getValue(); |
| 332 | assertEquals(2, v6gws.size()); |
| 333 | assertTrue(v6gws.contains(ipv6Gw1)); |
| 334 | assertTrue(v6gws.contains(ipv6Gw2)); |
| 335 | inOrder.verifyNoMoreInteractions(); |
Erik Kline | 5acb4e3 | 2017-07-04 18:28:11 +0900 | [diff] [blame] | 336 | |
| 337 | // Add in some IPv6 upstream info. When there is a tethered downstream |
| 338 | // making use of the IPv6 prefix we would expect to see the /64 route |
| 339 | // removed from "local prefixes" and /128s added for the upstream IPv6 |
| 340 | // addresses. This is not yet implemented, and for now we simply |
| 341 | // expect to see these /128s. |
| 342 | lp.addRoute(new RouteInfo(new IpPrefix("2001:db8::/64"))); |
| 343 | // "2001:db8::/64" plus "assigned" ASCII in hex |
| 344 | lp.addLinkAddress(new LinkAddress("2001:db8::6173:7369:676e:6564/64")); |
| 345 | // "2001:db8::/64" plus "random" ASCII in hex |
| 346 | lp.addLinkAddress(new LinkAddress("2001:db8::7261:6e64:6f6d/64")); |
| 347 | offload.setUpstreamLinkProperties(lp); |
| 348 | inOrder.verify(mHardware, times(1)).setLocalPrefixes(mStringArrayCaptor.capture()); |
| 349 | localPrefixes = mStringArrayCaptor.getValue(); |
| 350 | assertEquals(6, localPrefixes.size()); |
| 351 | assertTrue(localPrefixes.contains("127.0.0.0/8")); |
| 352 | assertTrue(localPrefixes.contains("192.0.2.0/24")); |
| 353 | assertTrue(localPrefixes.contains("fe80::/64")); |
| 354 | assertTrue(localPrefixes.contains("2001:db8::/64")); |
| 355 | assertTrue(localPrefixes.contains("2001:db8::6173:7369:676e:6564/128")); |
| 356 | assertTrue(localPrefixes.contains("2001:db8::7261:6e64:6f6d/128")); |
| 357 | // The relevant parts of the LinkProperties have not changed, but at the |
| 358 | // moment we do not de-dup upstream LinkProperties this carefully. |
| 359 | inOrder.verify(mHardware, times(1)).setUpstreamParameters( |
| 360 | eq(testIfName), eq(ipv4Addr), eq(ipv4Gateway), mStringArrayCaptor.capture()); |
| 361 | v6gws = mStringArrayCaptor.getValue(); |
| 362 | assertEquals(2, v6gws.size()); |
| 363 | assertTrue(v6gws.contains(ipv6Gw1)); |
| 364 | assertTrue(v6gws.contains(ipv6Gw2)); |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 365 | inOrder.verify(mHardware, times(1)).getForwardedStats(eq(testIfName)); |
Erik Kline | 5acb4e3 | 2017-07-04 18:28:11 +0900 | [diff] [blame] | 366 | inOrder.verifyNoMoreInteractions(); |
| 367 | |
| 368 | // Completely identical LinkProperties updates are de-duped. |
| 369 | offload.setUpstreamLinkProperties(lp); |
| 370 | // This LinkProperties value does not differ from the default upstream. |
| 371 | // There should be no extraneous call to setUpstreamParameters(). |
| 372 | inOrder.verify(mHardware, never()).setUpstreamParameters( |
| 373 | anyObject(), anyObject(), anyObject(), anyObject()); |
| 374 | inOrder.verifyNoMoreInteractions(); |
Erik Kline | 7990aef | 2017-06-01 20:11:25 +0900 | [diff] [blame] | 375 | } |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 376 | |
| 377 | private void assertNetworkStats(String iface, ForwardedStats stats, NetworkStats.Entry entry) { |
| 378 | assertEquals(iface, entry.iface); |
| 379 | assertEquals(stats.rxBytes, entry.rxBytes); |
| 380 | assertEquals(stats.txBytes, entry.txBytes); |
| 381 | assertEquals(SET_DEFAULT, entry.set); |
| 382 | assertEquals(TAG_NONE, entry.tag); |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | @Test |
| 386 | public void testGetForwardedStats() throws Exception { |
| 387 | setupFunctioningHardwareInterface(); |
| 388 | enableOffload(); |
| 389 | |
| 390 | final OffloadController offload = makeOffloadController(); |
| 391 | offload.start(); |
| 392 | |
| 393 | final String ethernetIface = "eth1"; |
| 394 | final String mobileIface = "rmnet_data0"; |
| 395 | |
| 396 | ForwardedStats ethernetStats = new ForwardedStats(); |
| 397 | ethernetStats.rxBytes = 12345; |
| 398 | ethernetStats.txBytes = 54321; |
| 399 | |
| 400 | ForwardedStats mobileStats = new ForwardedStats(); |
| 401 | mobileStats.rxBytes = 999; |
| 402 | mobileStats.txBytes = 99999; |
| 403 | |
| 404 | when(mHardware.getForwardedStats(eq(ethernetIface))).thenReturn(ethernetStats); |
| 405 | when(mHardware.getForwardedStats(eq(mobileIface))).thenReturn(mobileStats); |
| 406 | |
Hugo Benichi | 752c128 | 2017-08-22 13:57:41 +0900 | [diff] [blame^] | 407 | InOrder inOrder = inOrder(mHardware); |
| 408 | |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 409 | final LinkProperties lp = new LinkProperties(); |
| 410 | lp.setInterfaceName(ethernetIface); |
| 411 | offload.setUpstreamLinkProperties(lp); |
Hugo Benichi | 752c128 | 2017-08-22 13:57:41 +0900 | [diff] [blame^] | 412 | // Previous upstream was null, so no stats are fetched. |
| 413 | inOrder.verify(mHardware, never()).getForwardedStats(any()); |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 414 | |
| 415 | lp.setInterfaceName(mobileIface); |
| 416 | offload.setUpstreamLinkProperties(lp); |
Hugo Benichi | 752c128 | 2017-08-22 13:57:41 +0900 | [diff] [blame^] | 417 | // Expect that we fetch stats from the previous upstream. |
| 418 | inOrder.verify(mHardware, times(1)).getForwardedStats(eq(ethernetIface)); |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 419 | |
| 420 | lp.setInterfaceName(ethernetIface); |
| 421 | offload.setUpstreamLinkProperties(lp); |
Hugo Benichi | 752c128 | 2017-08-22 13:57:41 +0900 | [diff] [blame^] | 422 | // Expect that we fetch stats from the previous upstream. |
| 423 | inOrder.verify(mHardware, times(1)).getForwardedStats(eq(mobileIface)); |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 424 | |
Hugo Benichi | 752c128 | 2017-08-22 13:57:41 +0900 | [diff] [blame^] | 425 | ethernetStats = new ForwardedStats(); |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 426 | ethernetStats.rxBytes = 100000; |
| 427 | ethernetStats.txBytes = 100000; |
Hugo Benichi | 752c128 | 2017-08-22 13:57:41 +0900 | [diff] [blame^] | 428 | when(mHardware.getForwardedStats(eq(ethernetIface))).thenReturn(ethernetStats); |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 429 | offload.setUpstreamLinkProperties(null); |
Hugo Benichi | 752c128 | 2017-08-22 13:57:41 +0900 | [diff] [blame^] | 430 | // Expect that we fetch stats from the previous upstream. |
| 431 | inOrder.verify(mHardware, times(1)).getForwardedStats(eq(ethernetIface)); |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 432 | |
Lorenzo Colitti | f1912ca | 2017-08-17 19:23:08 +0900 | [diff] [blame] | 433 | ITetheringStatsProvider provider = mTetherStatsProviderCaptor.getValue(); |
| 434 | NetworkStats stats = provider.getTetherStats(STATS_PER_IFACE); |
| 435 | NetworkStats perUidStats = provider.getTetherStats(STATS_PER_UID); |
Hugo Benichi | 752c128 | 2017-08-22 13:57:41 +0900 | [diff] [blame^] | 436 | waitForIdle(); |
| 437 | // There is no current upstream, so no stats are fetched. |
| 438 | inOrder.verify(mHardware, never()).getForwardedStats(eq(ethernetIface)); |
| 439 | inOrder.verifyNoMoreInteractions(); |
Lorenzo Colitti | f1912ca | 2017-08-17 19:23:08 +0900 | [diff] [blame] | 440 | |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 441 | assertEquals(2, stats.size()); |
Lorenzo Colitti | f1912ca | 2017-08-17 19:23:08 +0900 | [diff] [blame] | 442 | assertEquals(2, perUidStats.size()); |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 443 | |
| 444 | NetworkStats.Entry entry = null; |
Lorenzo Colitti | f1912ca | 2017-08-17 19:23:08 +0900 | [diff] [blame] | 445 | for (int i = 0; i < stats.size(); i++) { |
| 446 | assertEquals(UID_ALL, stats.getValues(i, entry).uid); |
| 447 | assertEquals(UID_TETHERING, perUidStats.getValues(i, entry).uid); |
| 448 | } |
| 449 | |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 450 | int ethernetPosition = ethernetIface.equals(stats.getValues(0, entry).iface) ? 0 : 1; |
| 451 | int mobilePosition = 1 - ethernetPosition; |
| 452 | |
| 453 | entry = stats.getValues(mobilePosition, entry); |
| 454 | assertNetworkStats(mobileIface, mobileStats, entry); |
Lorenzo Colitti | f1912ca | 2017-08-17 19:23:08 +0900 | [diff] [blame] | 455 | entry = perUidStats.getValues(mobilePosition, entry); |
| 456 | assertNetworkStats(mobileIface, mobileStats, entry); |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 457 | |
| 458 | ethernetStats.rxBytes = 12345 + 100000; |
| 459 | ethernetStats.txBytes = 54321 + 100000; |
| 460 | entry = stats.getValues(ethernetPosition, entry); |
| 461 | assertNetworkStats(ethernetIface, ethernetStats, entry); |
Lorenzo Colitti | f1912ca | 2017-08-17 19:23:08 +0900 | [diff] [blame] | 462 | entry = perUidStats.getValues(ethernetPosition, entry); |
| 463 | assertNetworkStats(ethernetIface, ethernetStats, entry); |
Lorenzo Colitti | 4ca0ba8 | 2017-07-12 15:48:07 +0900 | [diff] [blame] | 464 | } |
Lorenzo Colitti | 50b60fc | 2017-08-11 13:47:49 +0900 | [diff] [blame] | 465 | |
| 466 | @Test |
| 467 | public void testSetInterfaceQuota() throws Exception { |
| 468 | setupFunctioningHardwareInterface(); |
| 469 | enableOffload(); |
| 470 | |
| 471 | final OffloadController offload = makeOffloadController(); |
| 472 | offload.start(); |
| 473 | |
| 474 | final String ethernetIface = "eth1"; |
| 475 | final String mobileIface = "rmnet_data0"; |
| 476 | final long ethernetLimit = 12345; |
| 477 | final long mobileLimit = 12345678; |
| 478 | |
| 479 | final LinkProperties lp = new LinkProperties(); |
| 480 | lp.setInterfaceName(ethernetIface); |
| 481 | offload.setUpstreamLinkProperties(lp); |
| 482 | |
| 483 | ITetheringStatsProvider provider = mTetherStatsProviderCaptor.getValue(); |
| 484 | final InOrder inOrder = inOrder(mHardware); |
| 485 | when(mHardware.setUpstreamParameters(any(), any(), any(), any())).thenReturn(true); |
| 486 | when(mHardware.setDataLimit(anyString(), anyLong())).thenReturn(true); |
| 487 | |
| 488 | // Applying an interface quota to the current upstream immediately sends it to the hardware. |
| 489 | provider.setInterfaceQuota(ethernetIface, ethernetLimit); |
| 490 | waitForIdle(); |
| 491 | inOrder.verify(mHardware).setDataLimit(ethernetIface, ethernetLimit); |
| 492 | inOrder.verifyNoMoreInteractions(); |
| 493 | |
| 494 | // Applying an interface quota to another upstream does not take any immediate action. |
| 495 | provider.setInterfaceQuota(mobileIface, mobileLimit); |
| 496 | waitForIdle(); |
| 497 | inOrder.verify(mHardware, never()).setDataLimit(anyString(), anyLong()); |
| 498 | |
| 499 | // Switching to that upstream causes the quota to be applied if the parameters were applied |
| 500 | // correctly. |
| 501 | lp.setInterfaceName(mobileIface); |
| 502 | offload.setUpstreamLinkProperties(lp); |
| 503 | waitForIdle(); |
| 504 | inOrder.verify(mHardware).setDataLimit(mobileIface, mobileLimit); |
| 505 | |
| 506 | // Setting a limit of ITetheringStatsProvider.QUOTA_UNLIMITED causes the limit to be set |
| 507 | // to Long.MAX_VALUE. |
| 508 | provider.setInterfaceQuota(mobileIface, ITetheringStatsProvider.QUOTA_UNLIMITED); |
| 509 | waitForIdle(); |
| 510 | inOrder.verify(mHardware).setDataLimit(mobileIface, Long.MAX_VALUE); |
| 511 | |
| 512 | // If setting upstream parameters fails, then the data limit is not set. |
| 513 | when(mHardware.setUpstreamParameters(any(), any(), any(), any())).thenReturn(false); |
| 514 | lp.setInterfaceName(ethernetIface); |
| 515 | offload.setUpstreamLinkProperties(lp); |
| 516 | provider.setInterfaceQuota(mobileIface, mobileLimit); |
| 517 | waitForIdle(); |
| 518 | inOrder.verify(mHardware, never()).setDataLimit(anyString(), anyLong()); |
| 519 | |
| 520 | // If setting the data limit fails while changing upstreams, offload is stopped. |
| 521 | when(mHardware.setUpstreamParameters(any(), any(), any(), any())).thenReturn(true); |
| 522 | when(mHardware.setDataLimit(anyString(), anyLong())).thenReturn(false); |
| 523 | lp.setInterfaceName(mobileIface); |
| 524 | offload.setUpstreamLinkProperties(lp); |
| 525 | provider.setInterfaceQuota(mobileIface, mobileLimit); |
| 526 | waitForIdle(); |
| 527 | inOrder.verify(mHardware).stopOffloadControl(); |
| 528 | } |
Lorenzo Colitti | 9f0baa9 | 2017-08-15 19:25:51 +0900 | [diff] [blame] | 529 | |
| 530 | @Test |
| 531 | public void testDataLimitCallback() throws Exception { |
| 532 | setupFunctioningHardwareInterface(); |
| 533 | enableOffload(); |
| 534 | |
| 535 | final OffloadController offload = makeOffloadController(); |
| 536 | offload.start(); |
| 537 | |
| 538 | OffloadHardwareInterface.ControlCallback callback = mControlCallbackCaptor.getValue(); |
| 539 | callback.onStoppedLimitReached(); |
| 540 | verify(mNMService, times(1)).tetherLimitReached(mTetherStatsProviderCaptor.getValue()); |
| 541 | } |
Erik Kline | 92c4db0 | 2017-05-31 10:21:32 +0900 | [diff] [blame] | 542 | } |