Ensure that only Cells cover a geographical area
[oam.git] / code / network-generator / model / python / tower.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 a Tower to mount O-RAN RUs
19 It can be interpreted as 'resource pool' for physical network
20 functions.
21 """
22 from model.python.o_ran_object import IORanObject
23 from model.python.o_ran_ru import ORanRu
24 from model.python.o_ran_node import ORanNode
25 import xml.etree.ElementTree as ET
26
27
28 # Define the "IORanDu" interface
29 class ITower(IORanObject):
30     def __init__(self, o_ran_ru_count: int, **kwargs):
31         super().__init__(**kwargs)
32         self._o_ran_ru_count = o_ran_ru_count
33
34
35 # Implement a concrete O-RAN Node class
36 class Tower(ORanNode):
37     def __init__(self, tower_data: ITower = None, **kwargs):
38         super().__init__(tower_data, **kwargs)
39         self._o_ran_ru_count = (
40             tower_data["oRanRuCount"]
41             if tower_data and "oRanRuCount" in tower_data
42             else 3
43         )
44         self._o_ran_rus: list[ORanRu] = self._create_o_ran_rus()
45
46     def _create_o_ran_rus(self) -> list[ORanRu]:
47         result: list[ORanRu] = []
48         for index in range(self._o_ran_ru_count):
49             s: str = "00" + str(index)
50             name: str = "-".join(
51                 [self.name.replace("Tower", "RU"), s[len(s) - 2 : len(s)]]
52             )
53             cell_count: int = self.parent.parent.parent.parent.parent.configuration()[
54                 "pattern"
55             ]["o-ran-ru"]["nr-cell-du-count"]
56             cell_angle : int = self.parent.parent.parent.parent.parent.configuration()[
57                 "pattern"
58             ]["nr-cell-du"]["cell-angle"]
59             ru_angle: int = cell_count * cell_angle
60             ru_azimuth: int = index * ru_angle
61             result.append(
62                 ORanRu(
63                     {
64                         "name": name,
65                         "geoLocation": self.geoLocation,
66                         "position": self.position,
67                         "layout": self.layout,
68                         "spiralRadiusProfile": self.spiralRadiusProfile,
69                         "parent": self,
70                         "cellCount": cell_count,
71                         "ruAngle": ru_angle,
72                         "ruAzimuth": ru_azimuth,
73                     }
74                 )
75             )
76         return result
77
78     @property
79     def o_ran_rus(self) -> list[ORanRu]:
80         return self._o_ran_rus
81
82     def toKml(self) -> ET.Element:
83         tower: ET.Element = ET.Element("Folder")
84         open: ET.Element = ET.SubElement(tower, "open")
85         open.text = "1"
86         name: ET.Element = ET.SubElement(tower, "name")
87         name.text = self.name
88         for o_ran_ru in self.o_ran_rus:
89             tower.append(o_ran_ru.toKml())
90         return tower
91
92
93     def toSvg(self) -> None:
94         return None