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