Reformat files according to template
[oam.git] / code / network-generator / network_generation / model / python / o_ran_cu.py
1 # Copyright 2023 highstreet technologies GmbH
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
15 #!/usr/bin/python
16
17 """
18 A Class representing an O-RAN centralized unit (ORanCu)
19 and at the same time a location for an O-Cloud resource pool
20 """
21 import xml.etree.ElementTree as ET
22 from typing import overload
23
24 import network_generation.model.python.hexagon as Hexagon
25 from network_generation.model.python.cube import Cube
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 ORanNode
29 from network_generation.model.python.o_ran_object import IORanObject
30 from network_generation.model.python.o_ran_termination_point import (
31     ORanTerminationPoint,
32 )
33 from network_generation.model.python.tower import Tower
34
35
36 # Define the "IORanCu" interface
37 class IORanCu(IORanObject):
38     def __init__(self, **kwargs):
39         super().__init__(**kwargs)
40
41
42 # Define an abstract O-RAN Node class
43 class ORanCu(ORanNode, IORanCu):
44     def __init__(self, o_ran_cu_data: IORanCu = None, **kwargs):
45         super().__init__(o_ran_cu_data, **kwargs)
46         self._o_ran_cloud_dus: list[ORanCu] = self._calculate_o_ran_dus()
47
48     def _calculate_o_ran_dus(self) -> list[ORanCloudDu]:
49         hex_ring_radius: int = (
50             self.spiralRadiusProfile.oRanCuSpiralRadiusOfODus
51         )
52         hex_list: list[Hex] = self.spiralRadiusProfile.oRanDuSpiral(
53             self.position, hex_ring_radius
54         )
55         result: list[ORanCloudDu] = []
56         for index, hex in enumerate(hex_list):
57             s: str = "00" + str(index)
58             name: str = "-".join(
59                 [self.name.replace("CU", "O-Cloud-DU"), s[len(s) - 2 : len(s)]]
60             )
61             network_center: dict = self.parent.parent.parent.center
62             newGeo = Hexagon.hex_to_geo_location(
63                 self.layout, hex, network_center
64             ).json()
65             result.append(
66                 ORanCloudDu(
67                     {
68                         "name": name,
69                         "geoLocation": newGeo,
70                         "position": hex,
71                         "layout": self.layout,
72                         "spiralRadiusProfile": self.spiralRadiusProfile,
73                         "parent": self,
74                     }
75                 )
76             )
77         return result
78
79     @property
80     def o_ran_cloud_dus(self) -> list[ORanCloudDu]:
81         return self._o_ran_cloud_dus
82
83     @property
84     def towers(self) -> list[Tower]:
85         result: list[Tower] = []
86         for du in self.o_ran_cloud_dus:
87             for tower in du.towers:
88                 result.append(tower)
89         return result
90
91     @property
92     def termination_points(self) -> list[ORanTerminationPoint]:
93         result: list[ORanTerminationPoint] = super().termination_points
94         phy_tp: str = "-".join([self.name, "phy".upper()])
95         result.append({"tp-id": phy_tp, "name": phy_tp})
96         for interface in ["e2", "o1"]:
97             id: str = "-".join([self.name, interface.upper()])
98             result.append(
99                 ORanTerminationPoint(
100                     {"id": id, "name": id, "supporter": phy_tp, "parent": self}
101                 )
102             )
103         return result
104
105     def to_topology_nodes(self) -> list[dict[str, dict]]:
106         result: list[dict[str, dict]] = super().to_topology_nodes()
107         # for o_ran_du in self.o_ran_dus: # TODO
108         #     result.extend(o_ran_du.to_topology_nodes())
109         for o_ran_cloud_du in self.o_ran_cloud_dus:
110             result.extend(o_ran_cloud_du.to_topology_nodes())
111         return result
112
113     def to_topology_links(self) -> list[dict[str, dict]]:
114         result: list[dict[str, dict]] = super().to_topology_links()
115         # for o_ran_du in self.o_ran_dus:
116         # result.extend(o_ran_du.to_topology_links())
117         for o_ran_cloud_du in self.o_ran_cloud_dus:
118             result.extend(o_ran_cloud_du.to_topology_links())
119         return result
120
121     def toKml(self) -> ET.Element:
122         o_ran_cu: ET.Element = ET.Element("Folder")
123         open: ET.Element = ET.SubElement(o_ran_cu, "open")
124         open.text = "1"
125         name: ET.Element = ET.SubElement(o_ran_cu, "name")
126         name.text = self.name
127         for o_ran_cloud_du in self.o_ran_cloud_dus:
128             o_ran_cu.append(o_ran_cloud_du.toKml())
129         return o_ran_cu
130
131     def toSvg(self) -> None:
132         return None