a02db29b95bb8d1d583a8726838e4aac681a5ccc
[oam.git] / code / network-generator / model / python / o_ran_ru.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 radio unit (ORanRu)
19 """
20 from model.python.nr_cell_du import NrCellDu
21 from model.python.o_ran_object import IORanObject
22 from model.python.o_ran_node import ORanNode
23 import xml.etree.ElementTree as ET
24
25
26 # Define the "IORanRu" interface
27 class IORanRu(IORanObject):
28     def __init__(self, cell_count: int, ru_angle:int, ru_azimuth:int, **kwargs):
29         super().__init__(**kwargs)
30         self._cell_count = cell_count
31         self._ru_angle = ru_angle
32         self._ru_azimuth = ru_azimuth
33
34
35 # Define an abstract O-RAN Node class
36 class ORanRu(ORanNode, IORanRu):
37     def __init__(self, o_ran_ru_data: IORanRu = None, **kwargs):
38         super().__init__(o_ran_ru_data, **kwargs)
39         self._cell_count = o_ran_ru_data["cellCount"] if o_ran_ru_data and "cellCount" in o_ran_ru_data else 1
40         self._ru_angle = o_ran_ru_data["ruAngle"] if o_ran_ru_data and "ruAngle" in o_ran_ru_data else 120
41         self._ru_azimuth = o_ran_ru_data["ruAzimuth"] if o_ran_ru_data and "ruAzimuth" in o_ran_ru_data else 0
42         self._cells: list[NrCellDu] = self._create_cells()
43
44
45     def _create_cells(self) -> list[NrCellDu]:
46         result: list[NrCellDu] = []
47         cell_angle : int = self.parent.parent.parent.parent.parent.parent.configuration()[
48             "pattern"
49         ]["nr-cell-du"]["cell-angle"]
50         for index in range(self._cell_count):
51             s: str = "00" + str(index)
52             name: str = "-".join(
53                 [self.name.replace("RU", "NRCellDu"), s[len(s) - 2 : len(s)]]
54             )
55             azimuth: int = index * cell_angle +self._ru_azimuth
56             result.append(
57                 NrCellDu(
58                     {
59                         "name": name,
60                         "geoLocation": self.geoLocation,
61                         "position": self.position,
62                         "layout": self.layout,
63                         "spiralRadiusProfile": self.spiralRadiusProfile,
64                         "parent": self,
65                         "cellAngle": cell_angle,
66                         "azimuth": azimuth,
67                     }
68                 )
69             )
70         return result
71
72     @property
73     def cells(self) -> list[NrCellDu]:
74         return self._cells
75
76     def toKml(self) -> ET.Element:
77         print("ru-tower", self.position, self.parent.position) if self.position.q is not self.parent.position.q else "ok"
78         o_ran_ru: ET.Element = ET.Element("Folder")
79         open: ET.Element = ET.SubElement(o_ran_ru, "open")
80         open.text = "1"
81         name: ET.Element = ET.SubElement(o_ran_ru, "name")
82         name.text = self.name
83         for cell in self.cells:
84             o_ran_ru.append(cell.toKml())
85         return o_ran_ru
86
87     def toSvg(self) -> None:
88         return None