Junyu Lai | 32a2d15 | 2024-07-03 16:05:41 +0800 | [diff] [blame] | 1 | # Copyright (C) 2024 The Android Open Source Project |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
Junyu Lai | 9418634 | 2024-08-23 23:09:43 +0800 | [diff] [blame] | 15 | from absl.testing import parameterized |
Junyu Lai | 73711f7 | 2024-07-11 17:00:29 +0800 | [diff] [blame] | 16 | from mobly import asserts |
| 17 | from net_tests_utils.host.python import apf_test_base, apf_utils |
Junyu Lai | 32a2d15 | 2024-07-03 16:05:41 +0800 | [diff] [blame] | 18 | |
Junyu Lai | 6f6b1a4 | 2024-07-04 15:34:30 +0800 | [diff] [blame] | 19 | # Constants. |
Junyu Lai | 32a2d15 | 2024-07-03 16:05:41 +0800 | [diff] [blame] | 20 | COUNTER_DROPPED_ETHERTYPE_NOT_ALLOWED = "DROPPED_ETHERTYPE_NOT_ALLOWED" |
Junyu Lai | 6f6b1a4 | 2024-07-04 15:34:30 +0800 | [diff] [blame] | 21 | ETHER_BROADCAST_ADDR = "FFFFFFFFFFFF" |
Junyu Lai | 32a2d15 | 2024-07-03 16:05:41 +0800 | [diff] [blame] | 22 | |
| 23 | |
Junyu Lai | 9418634 | 2024-08-23 23:09:43 +0800 | [diff] [blame] | 24 | class ApfV4Test(apf_test_base.ApfTestBase, parameterized.TestCase): |
Junyu Lai | 73711f7 | 2024-07-11 17:00:29 +0800 | [diff] [blame] | 25 | def setup_class(self): |
| 26 | super().setup_class() |
| 27 | # Check apf version preconditions. |
| 28 | caps = apf_utils.get_apf_capabilities( |
| 29 | self.clientDevice, self.client_iface_name |
| 30 | ) |
| 31 | if self.client.getVsrApiLevel() >= 34: |
| 32 | # Enforce APFv4 support for Android 14+ VSR. |
| 33 | asserts.assert_true( |
| 34 | caps.apf_version_supported >= 4, |
| 35 | "APFv4 became mandatory in Android 14 VSR.", |
| 36 | ) |
| 37 | else: |
| 38 | # Skip tests for APF version < 4 before Android 14 VSR. |
| 39 | apf_utils.assume_apf_version_support_at_least( |
| 40 | self.clientDevice, self.client_iface_name, 4 |
| 41 | ) |
Junyu Lai | 32a2d15 | 2024-07-03 16:05:41 +0800 | [diff] [blame] | 42 | |
Junyu Lai | 9418634 | 2024-08-23 23:09:43 +0800 | [diff] [blame] | 43 | # APF L2 packet filtering on V+ Android allows only specific |
| 44 | # types: IPv4, ARP, IPv6, EAPOL, WAPI. |
| 45 | # Tests can use any disallowed packet type. Currently, |
| 46 | # several ethertypes from the legacy ApfFilter denylist are used. |
| 47 | @parameterized.parameters( |
| 48 | "88a2", # ATA over Ethernet |
| 49 | "88a4", # EtherCAT |
| 50 | "88b8", # GOOSE (Generic Object Oriented Substation event) |
| 51 | "88cd", # SERCOS III |
| 52 | "88e3", # Media Redundancy Protocol (IEC62439-2) |
| 53 | ) # Declare inputs for state_str and expected_result. |
| 54 | def test_apf_drop_ethertype_not_allowed(self, blocked_ether_type): |
Junyu Lai | 6f6b1a4 | 2024-07-04 15:34:30 +0800 | [diff] [blame] | 55 | # Ethernet header (14 bytes). |
Maciej Żenczykowski | c3eccf9 | 2024-09-26 18:11:41 +0000 | [diff] [blame] | 56 | packet = ETHER_BROADCAST_ADDR # Destination MAC (broadcast) |
Junyu Lai | 6f6b1a4 | 2024-07-04 15:34:30 +0800 | [diff] [blame] | 57 | packet += self.server_mac_address.replace(":", "") # Source MAC |
Junyu Lai | 9418634 | 2024-08-23 23:09:43 +0800 | [diff] [blame] | 58 | packet += blocked_ether_type |
Junyu Lai | 32a2d15 | 2024-07-03 16:05:41 +0800 | [diff] [blame] | 59 | |
Junyu Lai | 9418634 | 2024-08-23 23:09:43 +0800 | [diff] [blame] | 60 | # Pad with zeroes to minimum ethernet frame length. |
Junyu Lai | 6f6b1a4 | 2024-07-04 15:34:30 +0800 | [diff] [blame] | 61 | packet += "00" * 46 |
| 62 | self.send_packet_and_expect_counter_increased( |
| 63 | packet, COUNTER_DROPPED_ETHERTYPE_NOT_ALLOWED |
Junyu Lai | cf65586 | 2024-07-04 11:09:52 +0800 | [diff] [blame] | 64 | ) |