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 | 6f6b1a4 | 2024-07-04 15:34:30 +0800 | [diff] [blame^] | 15 | from net_tests_utils.host.python import apf_test_base |
Junyu Lai | 32a2d15 | 2024-07-03 16:05:41 +0800 | [diff] [blame] | 16 | |
Junyu Lai | 6f6b1a4 | 2024-07-04 15:34:30 +0800 | [diff] [blame^] | 17 | # Constants. |
Junyu Lai | 32a2d15 | 2024-07-03 16:05:41 +0800 | [diff] [blame] | 18 | COUNTER_DROPPED_ETHERTYPE_NOT_ALLOWED = "DROPPED_ETHERTYPE_NOT_ALLOWED" |
Junyu Lai | 6f6b1a4 | 2024-07-04 15:34:30 +0800 | [diff] [blame^] | 19 | ETHER_BROADCAST_ADDR = "FFFFFFFFFFFF" |
| 20 | ETH_P_ETHERCAT = "88A4" |
Junyu Lai | 32a2d15 | 2024-07-03 16:05:41 +0800 | [diff] [blame] | 21 | |
| 22 | |
Junyu Lai | cf65586 | 2024-07-04 11:09:52 +0800 | [diff] [blame] | 23 | class ApfV4Test(apf_test_base.ApfTestBase): |
Junyu Lai | 32a2d15 | 2024-07-03 16:05:41 +0800 | [diff] [blame] | 24 | |
| 25 | def test_apf_drop_ethercat(self): |
Junyu Lai | 6f6b1a4 | 2024-07-04 15:34:30 +0800 | [diff] [blame^] | 26 | # Ethernet header (14 bytes). |
| 27 | packet = ETHER_BROADCAST_ADDR # Destination MAC (broadcast) |
| 28 | packet += self.server_mac_address.replace(":", "") # Source MAC |
| 29 | packet += ETH_P_ETHERCAT # EtherType (EtherCAT) |
Junyu Lai | 32a2d15 | 2024-07-03 16:05:41 +0800 | [diff] [blame] | 30 | |
Junyu Lai | 6f6b1a4 | 2024-07-04 15:34:30 +0800 | [diff] [blame^] | 31 | # EtherCAT header (2 bytes) + 44 bytes of zero padding. |
| 32 | packet += "00" * 46 |
| 33 | self.send_packet_and_expect_counter_increased( |
| 34 | packet, COUNTER_DROPPED_ETHERTYPE_NOT_ALLOWED |
Junyu Lai | cf65586 | 2024-07-04 11:09:52 +0800 | [diff] [blame] | 35 | ) |