blob: 174586762663e4a9b6930032d15d024b6acafba2 [file] [log] [blame]
Wei-Yu Chenad55cb82022-02-15 20:07:01 +08001# 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 Chen49950b92021-11-08 19:19:18 +08005
6import re
7
8from exceptions import UnrecognizedEnodebError
9from logger import EnodebdLogger as logger
10
11
12class 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"
Wei-Yu Chenb91af852022-03-15 22:24:49 +080024 SERCOMM = "Sercomm"
Wei-Yu Chen49950b92021-11-08 19:19:18 +080025
26
27def 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":
Wei-Yu Chenb91af852022-03-15 22:24:49 +080070 return EnodebDeviceName.SERCOMM
Wei-Yu Chen49950b92021-11-08 19:19:18 +080071 else:
72 raise UnrecognizedEnodebError("Device %s unsupported" % device_oui)
73
74
75def _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