# See the License for the specific language governing permissions and
# limitations under the License.
-#!/usr/bin/python
+# !/usr/bin/python
"""
A Class representing a Tower to mount O-RAN RUs
functions.
"""
import xml.etree.ElementTree as ET
-from typing import overload
+from typing import Any, cast
-from network_generation.model.python.o_ran_node import ORanNode
-from network_generation.model.python.o_ran_object import IORanObject
+from network_generation.model.python.o_ran_node import IORanNode, ORanNode
from network_generation.model.python.o_ran_ru import ORanRu
from network_generation.model.python.o_ran_termination_point import (
ORanTerminationPoint,
)
-# Define the "IORanDu" interface
-class ITower(IORanObject):
- def __init__(self, o_ran_ru_count: int, **kwargs):
- super().__init__(**kwargs)
- self._o_ran_ru_count = o_ran_ru_count
+# Define the "IoRanDu" interface
+class ITower(IORanNode):
+ o_ran_ru_count: int
+
+
+default_value: ITower = cast(
+ ITower,
+ {
+ **ORanNode.default(),
+ **{
+ "o_ran_ru_count": 1,
+ },
+ },
+)
# Implement a concrete O-RAN Node class
class Tower(ORanNode):
- def __init__(self, tower_data: ITower = None, **kwargs):
- super().__init__(tower_data, **kwargs)
- self._o_ran_ru_count = (
- tower_data["oRanRuCount"]
+ def __init__(
+ self,
+ data: dict[str, Any] = cast(dict[str, Any], default_value),
+ **kwargs: dict[str, Any]
+ ) -> None:
+ tower_data: ITower = self._to_tower_data(data)
+ super().__init__(cast(dict[str, Any], tower_data), **kwargs)
+ self._o_ran_ru_count: int = (
+ int(str(tower_data["oRanRuCount"]))
if tower_data and "oRanRuCount" in tower_data
else 3
)
self._o_ran_rus: list[ORanRu] = self._create_o_ran_rus()
+ def _to_tower_data(self, data: dict[str, Any]) -> ITower:
+ result: ITower = default_value
+ for key, key_type in ITower.__annotations__.items():
+ if key in data:
+ result[key] = data[key] # type: ignore
+ return result
+
def _create_o_ran_rus(self) -> list[ORanRu]:
result: list[ORanRu] = []
for index in range(self._o_ran_ru_count):
s: str = "00" + str(index)
name: str = "-".join(
- [self.name.replace("Tower", "RU"), s[len(s) - 2 : len(s)]]
+ [self.name.replace("Tower", "RU"), s[len(s) - 2: len(s)]]
)
cell_count: int = (
- self.parent.parent.parent.parent.parent.configuration()[
+ self.parent.parent.parent.parent.parent.configuration[
"pattern"
- ]["o-ran-ru"]["nr-cell-du-count"]
+ ]["oRanRu"]["nrCellDuCount"]
)
cell_angle: int = (
- self.parent.parent.parent.parent.parent.configuration()[
+ self.parent.parent.parent.parent.parent.configuration[
"pattern"
- ]["nr-cell-du"]["cell-angle"]
+ ]["nrCellDu"]["cellAngle"]
)
ru_angle: int = cell_count * cell_angle
ru_azimuth: int = index * ru_angle
ORanRu(
{
"name": name,
- "geoLocation": self.geoLocation,
+ "geoLocation": self.geo_location,
"position": self.position,
"layout": self.layout,
- "spiralRadiusProfile": self.spiralRadiusProfile,
"parent": self,
"cellCount": cell_count,
"ruAngle": ru_angle,
def o_ran_rus(self) -> list[ORanRu]:
return self._o_ran_rus
- @property
def termination_points(self) -> list[ORanTerminationPoint]:
- result: list[ORanTerminationPoint] = super().termination_points
+ result: list[ORanTerminationPoint] = super().termination_points()
phy_tp: str = "-".join([self.name, "phy".upper()])
- result.append({"tp-id": phy_tp})
+ result.append(ORanTerminationPoint({"tp-id": phy_tp}))
for interface in ["e2", "o1", "ofhm", "ofhc", "ofhu", "ofhs"]:
result.append(
- {
- "tp-id": "-".join([self.name, interface.upper()]),
- "supporting-termination-point": [
- {
- "network-ref": type(
- self.parent.parent.parent.parent
- ),
- "node-ref": self.name,
- "tp-ref": phy_tp,
- }
- ],
- }
+ ORanTerminationPoint(
+ {
+ "tp-id": "-".join([self.name, interface.upper()]),
+ "supporting-termination-point": [
+ {
+ "network-ref": type(
+ self.parent.parent.parent.parent
+ ),
+ "node-ref": self.name,
+ "tp-ref": phy_tp,
+ }
+ ],
+ }
+ )
)
return result
- def to_topology_nodes(self) -> list[dict[str, dict]]:
- result: list[dict[str, dict]] = super().to_topology_nodes()
+ def to_topology_nodes(self) -> list[dict[str, Any]]:
+ result: list[dict[str, Any]] = super().to_topology_nodes()
for o_ran_ru in self.o_ran_rus:
result.extend(o_ran_ru.to_topology_nodes())
return result
- def to_topology_links(self) -> list[dict[str, dict]]:
- result: list[dict[str, dict]] = super().to_topology_links()
+ def to_topology_links(self) -> list[dict[str, Any]]:
+ result: list[dict[str, Any]] = super().to_topology_links()
for o_ran_ru in self.o_ran_rus:
result.extend(o_ran_ru.to_topology_links())
return result
tower.append(o_ran_ru.toKml())
return tower
- def toSvg(self) -> None:
- return None
+ def toSvg(self) -> ET.Element:
+ return ET.Element("to-be-implemented")
+
+ def to_directory(self, parent_dir: str) -> None:
+ for o_ran_ru in self.o_ran_rus:
+ o_ran_ru.to_directory(parent_dir)