2024-07-03 16:05:41 +08:00
|
|
|
# Copyright (C) 2024 The Android Open Source Project
|
|
|
|
|
#
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
|
#
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
#
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
2025-05-28 09:33:18 +00:00
|
|
|
import time
|
2024-08-23 23:09:43 +08:00
|
|
|
from absl.testing import parameterized
|
Check APF version, VSR API level, and Android version
This commit introduces checks for APF version, VSR API level,
and Android version to decide whether an APFv4 test should be
run, skipped, or fail:
* If Android version is less than V, skip the test
* If VSR API level is greater than or equal to 14 and APF
version is less than 4, fail the test
* Otherwise, if APF version is less than 4, skip the test
Test: m connectivity_multi_devices_snippet && \
atest CtsConnectivityMultiDevicesTestCases:ConnectivityMultiDevicesTest
Fix: 352132428
Change-Id: I023164fb59ad40f489abea2e0c45761efc39699b
2024-07-11 17:00:29 +08:00
|
|
|
from mobly import asserts
|
|
|
|
|
from net_tests_utils.host.python import apf_test_base, apf_utils
|
2025-03-21 01:36:18 +00:00
|
|
|
from scapy.layers.l2 import Ether
|
2024-07-03 16:05:41 +08:00
|
|
|
|
2024-07-04 15:34:30 +08:00
|
|
|
# Constants.
|
2025-05-28 09:33:18 +00:00
|
|
|
COUNTER_DROPPED_ETHERTYPE_NOT_ALLOWED = 'DROPPED_ETHERTYPE_NOT_ALLOWED'
|
|
|
|
|
ETHER_BROADCAST_ADDR = 'FFFFFFFFFFFF'
|
2025-03-21 01:36:18 +00:00
|
|
|
MIN_PACKET_SIZE = 60
|
2024-07-03 16:05:41 +08:00
|
|
|
|
|
|
|
|
|
2024-08-23 23:09:43 +08:00
|
|
|
class ApfV4Test(apf_test_base.ApfTestBase, parameterized.TestCase):
|
2025-05-28 09:33:18 +00:00
|
|
|
|
Check APF version, VSR API level, and Android version
This commit introduces checks for APF version, VSR API level,
and Android version to decide whether an APFv4 test should be
run, skipped, or fail:
* If Android version is less than V, skip the test
* If VSR API level is greater than or equal to 14 and APF
version is less than 4, fail the test
* Otherwise, if APF version is less than 4, skip the test
Test: m connectivity_multi_devices_snippet && \
atest CtsConnectivityMultiDevicesTestCases:ConnectivityMultiDevicesTest
Fix: 352132428
Change-Id: I023164fb59ad40f489abea2e0c45761efc39699b
2024-07-11 17:00:29 +08:00
|
|
|
def setup_class(self):
|
|
|
|
|
super().setup_class()
|
|
|
|
|
# Check apf version preconditions.
|
|
|
|
|
caps = apf_utils.get_apf_capabilities(
|
|
|
|
|
self.clientDevice, self.client_iface_name
|
|
|
|
|
)
|
|
|
|
|
if self.client.getVsrApiLevel() >= 34:
|
|
|
|
|
# Enforce APFv4 support for Android 14+ VSR.
|
|
|
|
|
asserts.assert_true(
|
|
|
|
|
caps.apf_version_supported >= 4,
|
2025-05-28 09:33:18 +00:00
|
|
|
'APFv4 became mandatory in Android 14 VSR.',
|
Check APF version, VSR API level, and Android version
This commit introduces checks for APF version, VSR API level,
and Android version to decide whether an APFv4 test should be
run, skipped, or fail:
* If Android version is less than V, skip the test
* If VSR API level is greater than or equal to 14 and APF
version is less than 4, fail the test
* Otherwise, if APF version is less than 4, skip the test
Test: m connectivity_multi_devices_snippet && \
atest CtsConnectivityMultiDevicesTestCases:ConnectivityMultiDevicesTest
Fix: 352132428
Change-Id: I023164fb59ad40f489abea2e0c45761efc39699b
2024-07-11 17:00:29 +08:00
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
# Skip tests for APF version < 4 before Android 14 VSR.
|
|
|
|
|
apf_utils.assume_apf_version_support_at_least(
|
|
|
|
|
self.clientDevice, self.client_iface_name, 4
|
|
|
|
|
)
|
2024-07-03 16:05:41 +08:00
|
|
|
|
2024-08-23 23:09:43 +08:00
|
|
|
# APF L2 packet filtering on V+ Android allows only specific
|
|
|
|
|
# types: IPv4, ARP, IPv6, EAPOL, WAPI.
|
|
|
|
|
# Tests can use any disallowed packet type. Currently,
|
|
|
|
|
# several ethertypes from the legacy ApfFilter denylist are used.
|
|
|
|
|
@parameterized.parameters(
|
2025-05-28 09:33:18 +00:00
|
|
|
0x88A2, # ATA over Ethernet
|
|
|
|
|
0x88A4, # EtherCAT
|
|
|
|
|
0x88B8, # GOOSE (Generic Object Oriented Substation event)
|
|
|
|
|
0x88CD, # SERCOS III
|
|
|
|
|
0x88E3, # Media Redundancy Protocol (IEC62439-2)
|
2024-08-23 23:09:43 +08:00
|
|
|
) # Declare inputs for state_str and expected_result.
|
|
|
|
|
def test_apf_drop_ethertype_not_allowed(self, blocked_ether_type):
|
2025-05-28 09:33:18 +00:00
|
|
|
eth = Ether(
|
|
|
|
|
src=self.server_mac_address,
|
|
|
|
|
dst=self.client_mac_address,
|
|
|
|
|
type=blocked_ether_type,
|
|
|
|
|
)
|
2025-03-21 01:36:18 +00:00
|
|
|
packet = bytes(eth).hex()
|
2024-07-03 16:05:41 +08:00
|
|
|
|
2025-03-21 01:36:18 +00:00
|
|
|
# Add zero padding up to minimum ethernet frame length
|
2025-05-28 09:33:18 +00:00
|
|
|
packet = packet.ljust(MIN_PACKET_SIZE * 2, '0')
|
2025-04-02 03:07:56 +00:00
|
|
|
|
|
|
|
|
# Pause packet sending between tests to avoid APF disablement due to high throughput.
|
|
|
|
|
time.sleep(3)
|
2024-07-04 15:34:30 +08:00
|
|
|
self.send_packet_and_expect_counter_increased(
|
|
|
|
|
packet, COUNTER_DROPPED_ETHERTYPE_NOT_ALLOWED
|
2024-07-04 11:09:52 +08:00
|
|
|
)
|