Move all business logic code under template folder
[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 typing import overload
23 from model.python.o_ran_object import IORanObject
24 from model.python.o_ran_ru import ORanRu
25 from model.python.o_ran_node import ORanNode
26 from model.python.o_ran_termination_point import ORanTerminationPoint
27 import xml.etree.ElementTree as ET
28
29
30 # Define the "IORanDu" interface
31 class ITower(IORanObject):
32     def __init__(self, o_ran_ru_count: int, **kwargs):
33         super().__init__(**kwargs)
34         self._o_ran_ru_count = o_ran_ru_count
35
36
37 # Implement a concrete O-RAN Node class
38 class Tower(ORanNode):
39     def __init__(self, tower_data: ITower = None, **kwargs):
40         super().__init__(tower_data, **kwargs)
41         self._o_ran_ru_count = (
42             tower_data["oRanRuCount"]
43             if tower_data and "oRanRuCount" in tower_data
44             else 3
45         )
46         self._o_ran_rus: list[ORanRu] = self._create_o_ran_rus()
47
48     def _create_o_ran_rus(self) -> list[ORanRu]:
49         result: list[ORanRu] = []
50         for index in range(self._o_ran_ru_count):
51             s: str = "00" + str(index)
52             name: str = "-".join(
53                 [self.name.replace("Tower", "RU"), s[len(s) - 2 : len(s)]]
54             )
55             cell_count: int = self.parent.parent.parent.parent.parent.configuration()[
56                 "pattern"
57             ]["o-ran-ru"]["nr-cell-du-count"]
58             cell_angle : int = self.parent.parent.parent.parent.parent.configuration()[
59                 "pattern"
60             ]["nr-cell-du"]["cell-angle"]
61             ru_angle: int = cell_count * cell_angle
62             ru_azimuth: int = index * ru_angle
63             result.append(
64                 ORanRu(
65                     {
66                         "name": name,
67                         "geoLocation": self.geoLocation,
68                         "position": self.position,
69                         "layout": self.layout,
70                         "spiralRadiusProfile": self.spiralRadiusProfile,
71                         "parent": self,
72                         "cellCount": cell_count,
73                         "ruAngle": ru_angle,
74                         "ruAzimuth": ru_azimuth,
75                     }
76                 )
77             )
78         return result
79
80     @property
81     def o_ran_rus(self) -> list[ORanRu]:
82         return self._o_ran_rus
83
84     @property
85     def termination_points(self) -> list[ORanTerminationPoint]:
86         result: list[ORanTerminationPoint] = super().termination_points
87         phy_tp: str = "-".join([self.name, "phy".upper()])
88         result.append({"tp-id": phy_tp})
89         for interface in ["e2", "o1", "ofhm", "ofhc", "ofhu","ofhs"]:
90             result.append(              {
91                 "tp-id": "-".join([self.name, interface.upper()]),
92                 "supporting-termination-point": [
93                   {
94                     "network-ref": type(self.parent.parent.parent.parent),
95                     "node-ref":self.name,
96                     "tp-ref": phy_tp
97                   }
98                 ]
99               })
100         return result
101
102     def to_topology_nodes(self) -> list[dict[str, dict]]:
103         result: list[dict[str, dict]] = super().to_topology_nodes()
104         for o_ran_ru in self.o_ran_rus:
105             result.extend(o_ran_ru.to_topology_nodes())    
106         return result
107
108     def to_topology_links(self) -> list[dict[str, dict]]:
109         result: list[dict[str, dict]] = super().to_topology_links()
110         for o_ran_ru in self.o_ran_rus:
111             result.extend(o_ran_ru.to_topology_links())    
112         return result
113     
114     def toKml(self) -> ET.Element:
115         tower: ET.Element = ET.Element("Folder")
116         open: ET.Element = ET.SubElement(tower, "open")
117         open.text = "1"
118         name: ET.Element = ET.SubElement(tower, "name")
119         name.text = self.name
120         for o_ran_ru in self.o_ran_rus:
121             tower.append(o_ran_ru.toKml())
122         return tower
123
124
125     def toSvg(self) -> None:
126         return None