Wei-Yu Chen | ad55cb8 | 2022-02-15 20:07:01 +0800 | [diff] [blame^] | 1 | # SPDX-FileCopyrightText: 2020 The Magma Authors. |
| 2 | # SPDX-FileCopyrightText: 2022 Open Networking Foundation <support@opennetworking.org> |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 5 | |
| 6 | import re |
| 7 | |
| 8 | from exceptions import UnrecognizedEnodebError |
| 9 | from logger import EnodebdLogger as logger |
| 10 | |
| 11 | |
| 12 | class EnodebDeviceName: |
| 13 | """ |
| 14 | This exists only to break a circular dependency. Otherwise there's no |
| 15 | point of having these names for the devices |
| 16 | """ |
| 17 | |
| 18 | BAICELLS = "Baicells" |
| 19 | BAICELLS_OLD = "Baicells Old" |
| 20 | BAICELLS_QAFA = "Baicells QAFA" |
| 21 | BAICELLS_QAFB = "Baicells QAFB" |
| 22 | BAICELLS_RTS = "Baicells RTS" |
| 23 | CAVIUM = "Cavium" |
| 24 | FREEDOMFI_ONE = "FREEDOMFI ONE" |
| 25 | |
| 26 | |
| 27 | def get_device_name(device_oui: str, sw_version: str,) -> str: |
| 28 | """ |
| 29 | Use the manufacturer organization unique identifier read during INFORM |
| 30 | to select the TR data model used for configuration and status reports |
| 31 | |
| 32 | Qualcomm-based Baicells eNodeBs use a TR098-based model different |
| 33 | from the Intel units. The software version on the Qualcomm models |
| 34 | also further limits the model usable by that device. |
| 35 | |
| 36 | Args: |
| 37 | device_oui: string, OUI representing device vendor |
| 38 | sw_version: string, firmware version of eNodeB device |
| 39 | |
| 40 | Returns: |
| 41 | DataModel |
| 42 | """ |
| 43 | if device_oui in {"34ED0B", "48BF74"}: |
| 44 | if sw_version.startswith("BaiBS_QAFB"): |
| 45 | return EnodebDeviceName.BAICELLS_QAFB |
| 46 | elif sw_version.startswith("BaiBS_QAFA"): |
| 47 | return EnodebDeviceName.BAICELLS_QAFA |
| 48 | elif sw_version.startswith("BaiStation_"): |
| 49 | # Note: to disable flag inversion completely (for all builds), |
| 50 | # set to BaiStation_V000R000C00B000SPC000 |
| 51 | # Note: to force flag inversion always (for all builds), |
| 52 | # set to BaiStation_V999R999C99B999SPC999 |
| 53 | invert_before_version = _parse_sw_version( |
| 54 | "BaiStation_V100R001C00B110SPC003" |
| 55 | ) |
| 56 | if _parse_sw_version(sw_version) < invert_before_version: |
| 57 | return EnodebDeviceName.BAICELLS_OLD |
| 58 | return EnodebDeviceName.BAICELLS |
| 59 | elif sw_version.startswith("BaiBS_RTS_"): |
| 60 | return EnodebDeviceName.BAICELLS_RTS |
| 61 | elif sw_version.startswith("BaiBS_RTSH_"): |
| 62 | return EnodebDeviceName.BAICELLS_RTS |
| 63 | else: |
| 64 | raise UnrecognizedEnodebError( |
| 65 | "Device %s unsupported: Software (%s)" % (device_oui, sw_version), |
| 66 | ) |
| 67 | elif device_oui in {"000FB7", "744D28"}: |
| 68 | return EnodebDeviceName.CAVIUM |
| 69 | elif device_oui == "000E8F": |
| 70 | return EnodebDeviceName.FREEDOMFI_ONE |
| 71 | else: |
| 72 | raise UnrecognizedEnodebError("Device %s unsupported" % device_oui) |
| 73 | |
| 74 | |
| 75 | def _parse_sw_version(version_str): |
| 76 | """ |
| 77 | Parse SW version string. |
| 78 | Expects format: BaiStation_V100R001C00B110SPC003 |
| 79 | For the above version string, returns: [100, 1, 0, 110, 3] |
| 80 | Note: trailing characters (for dev builds) are ignored. Null is returned |
| 81 | for version strings that don't match the above format. |
| 82 | """ |
| 83 | logger.debug("Got firmware version: %s", version_str) |
| 84 | |
| 85 | version = re.findall( |
| 86 | r"BaiStation_V(\d{3})R(\d{3})C(\d{2})B(\d{3})SPC(\d{3})", version_str, |
| 87 | ) |
| 88 | if not version: |
| 89 | return None |
| 90 | elif len(version) > 1: |
| 91 | logger.warning( |
| 92 | "SW version (%s) not formatted as expected", version_str, |
| 93 | ) |
| 94 | version_int = [] |
| 95 | for num in version[0]: |
| 96 | try: |
| 97 | version_int.append(int(num)) |
| 98 | except ValueError: |
| 99 | logger.warning( |
| 100 | "SW version (%s) not formatted as expected", version_str, |
| 101 | ) |
| 102 | return None |
| 103 | |
| 104 | logger.debug("Parsed firmware version: %s", version_int) |
| 105 | |
| 106 | return version_int |