1 # Copyright 2023 highstreet technologies GmbH
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 A Class representing an O-RAN centralized unit (ORanCu)
19 and at the same time a location for an O-Cloud resource pool
21 import xml.etree.ElementTree as ET
22 from typing import Any, cast
24 import network_generation.model.python.hexagon as Hexagon
25 from network_generation.model.python.geo_location import GeoLocation
26 from network_generation.model.python.hexagon import Hex
27 from network_generation.model.python.o_ran_cloud_du import ORanCloudDu
28 from network_generation.model.python.o_ran_node import (
33 from network_generation.model.python.o_ran_termination_point import (
36 from network_generation.model.python.tower import Tower
38 # Define the "IORanCu" interface
42 # Define an abstract O-RAN Node class
43 class ORanCu(ORanNode):
46 data: dict[str, Any] = cast(dict[str, Any], default_value),
47 **kwargs: dict[str, Any]
49 o_ran_cu_data: IORanCu = self._to_o_ran_cu_data(data)
50 super().__init__(cast(dict[str, Any], o_ran_cu_data), **kwargs)
51 self._o_ran_cloud_dus: list[ORanCloudDu] = self._calculate_o_ran_dus()
53 def _to_o_ran_cu_data(self, data: dict[str, Any]) -> IORanCu:
54 result: IORanCu = default_value
55 for key, key_type in IORanCu.__annotations__.items():
57 result[key] = data[key] # type: ignore
60 def _calculate_o_ran_dus(self) -> list[ORanCloudDu]:
61 hex_ring_radius: int = (
62 self.parent.parent.parent
63 .spiral_radius_profile.oRanCuSpiralRadiusOfODus
67 ] = self.parent.parent.parent.spiral_radius_profile.oRanDuSpiral(
68 self.position, hex_ring_radius
70 result: list[ORanCloudDu] = []
71 for index, hex in enumerate(hex_list):
72 s: str = "00" + str(index)
74 [self.name.replace("CU", "O-Cloud-DU"), s[len(s) - 2: len(s)]]
76 network_center: GeoLocation = self.parent.parent.parent.center
77 newGeo = Hexagon.hex_to_geo_location(
78 self.layout, hex, network_center
84 "geoLocation": newGeo,
86 "layout": self.layout,
94 def o_ran_cloud_dus(self) -> list[ORanCloudDu]:
95 return self._o_ran_cloud_dus
98 def towers(self) -> list[Tower]:
99 result: list[Tower] = []
100 for du in self.o_ran_cloud_dus:
101 for tower in du.towers:
105 def termination_points(self) -> list[ORanTerminationPoint]:
106 result: list[ORanTerminationPoint] = super().termination_points()
107 phy_tp: str = "-".join([self.name, "phy".upper()])
108 result.append(ORanTerminationPoint({"tp-id": phy_tp, "name": phy_tp}))
109 for interface in ["e2", "o1"]:
110 id: str = "-".join([self.name, interface.upper()])
112 ORanTerminationPoint(
113 {"id": id, "name": id, "supporter": phy_tp, "parent": self}
118 def to_topology_nodes(self) -> list[dict[str, Any]]:
119 result: list[dict[str, Any]] = super().to_topology_nodes()
120 # for o_ran_du in self.o_ran_dus: # TODO
121 # result.extend(o_ran_du.to_topology_nodes())
122 for o_ran_cloud_du in self.o_ran_cloud_dus:
123 result.extend(o_ran_cloud_du.to_topology_nodes())
126 def to_topology_links(self) -> list[dict[str, Any]]:
127 result: list[dict[str, Any]] = super().to_topology_links()
128 # for o_ran_du in self.o_ran_dus:
129 # result.extend(o_ran_du.to_topology_links())
130 for o_ran_cloud_du in self.o_ran_cloud_dus:
131 result.extend(o_ran_cloud_du.to_topology_links())
134 def toKml(self) -> ET.Element:
135 o_ran_cu: ET.Element = ET.Element("Folder")
136 open: ET.Element = ET.SubElement(o_ran_cu, "open")
138 name: ET.Element = ET.SubElement(o_ran_cu, "name")
139 name.text = self.name
140 for o_ran_cloud_du in self.o_ran_cloud_dus:
141 o_ran_cu.append(o_ran_cloud_du.toKml())
144 def toSvg(self) -> ET.Element:
145 return ET.Element("to-be-implemented")
147 def to_directory(self, parent_dir: str) -> None:
148 for o_ran_cloud_du in self.o_ran_cloud_dus:
149 o_ran_cloud_du.to_directory(parent_dir)