70e1e442262f5dacabbd2ecc9c69b480b411a17a
[oam.git] / code / network-generator / 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 """
20 from model.python.cube import Cube
21 from model.python.hexagon import Hex
22 import model.python.hexagon as Hexagon
23 from model.python.o_ran_du import ORanDu
24 from model.python.tower import Tower
25 from model.python.o_ran_object import IORanObject
26 from model.python.o_ran_node import ORanNode
27 import xml.etree.ElementTree as ET
28
29
30 # Define the "IORanCu" interface
31 class IORanCu(IORanObject):
32     def __init__(self, **kwargs):
33         super().__init__(**kwargs)
34
35
36 # Define an abstract O-RAN Node class
37 class ORanCu(ORanNode, IORanCu):
38     def __init__(self, o_ran_cu_data: IORanCu = None, **kwargs):
39         super().__init__(o_ran_cu_data, **kwargs)
40         self._o_ran_dus: list[ORanCu] = self._calculate_o_ran_dus()
41
42     def _calculate_o_ran_dus(self) -> list[ORanDu]:
43         hex_ring_radius: int = self.spiralRadiusProfile.oRanCuSpiralRadiusOfODus
44         hex_list: list[Hex] = self.spiralRadiusProfile.oRanDuSpiral(self.position, hex_ring_radius)
45         result: list[ORanDu] = []
46         for index, hex in enumerate(hex_list):
47             s: str = "00" + str(index)
48             name: str = "-".join(
49                 [self.name.replace("CU", "DU"), s[len(s) - 2 : len(s)]]
50             )
51             network_center: dict = self.parent.parent.parent.center
52             newGeo = Hexagon.hex_to_geo_location(
53                 self.layout, hex, network_center
54             ).json()
55             result.append(
56                 ORanDu(
57                     {
58                         "name": name,
59                         "geoLocation": newGeo,
60                         "position": hex,
61                         "layout": self.layout,
62                         "spiralRadiusProfile": self.spiralRadiusProfile,
63                         "parent": self,
64                     }
65                 )
66             )
67         return result
68
69
70     @property
71     def o_ran_dus(self) -> list[ORanDu]:
72         return self._o_ran_dus
73
74     @property
75     def towers(self) -> list[Tower]:
76         result: list[Tower] = []
77         for du in self.o_ran_dus:
78             for tower in du.towers:
79                 result.append(tower)
80         return result
81
82     def toKml(self) -> ET.Element:
83         o_ran_cu: ET.Element = ET.Element("Folder")
84         open: ET.Element = ET.SubElement(o_ran_cu, "open")
85         open.text = "1"
86         name: ET.Element = ET.SubElement(o_ran_cu, "name")
87         name.text = self.name
88         for o_ran_du in self.o_ran_dus:
89             o_ran_cu.append(o_ran_du.toKml())
90         return o_ran_cu
91
92
93     def toSvg(self) -> None:
94         return None