d9b119df75154fea9ab9547e8518ea77dce6bba0
[oam.git] / code / network-generator / network_generation / 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 import xml.etree.ElementTree as ET
21 from typing import overload
22
23 from network_generation.model.python.nr_cell_du import NrCellDu
24 from network_generation.model.python.o_ran_du import ORanDu
25 from network_generation.model.python.o_ran_node import ORanNode
26 from network_generation.model.python.o_ran_object import IORanObject
27 from network_generation.model.python.o_ran_termination_point import (
28     ORanTerminationPoint,
29 )
30
31
32 # Define the "IORanRu" interface
33 class IORanRu(IORanObject):
34     def __init__(
35         self, cell_count: int, ru_angle: int, ru_azimuth: int, **kwargs
36     ):
37         super().__init__(**kwargs)
38         self._cell_count = cell_count
39         self._ru_angle = ru_angle
40         self._ru_azimuth = ru_azimuth
41
42
43 # Define an abstract O-RAN Node class
44 class ORanRu(ORanNode, IORanRu):
45     def __init__(self, o_ran_ru_data: IORanRu = None, **kwargs):
46         super().__init__(o_ran_ru_data, **kwargs)
47         self._cell_count = (
48             o_ran_ru_data["cellCount"]
49             if o_ran_ru_data and "cellCount" in o_ran_ru_data
50             else 1
51         )
52         self._ru_angle = (
53             o_ran_ru_data["ruAngle"]
54             if o_ran_ru_data and "ruAngle" in o_ran_ru_data
55             else 120
56         )
57         self._ru_azimuth = (
58             o_ran_ru_data["ruAzimuth"]
59             if o_ran_ru_data and "ruAzimuth" in o_ran_ru_data
60             else 0
61         )
62         self._cells: list[NrCellDu] = self._create_cells()
63         name: str = self.name.replace("RU", "DU")
64         self._oRanDu: ORanDu = ORanDu(
65             {
66                 "name": name,
67                 "geoLocation": self.parent.geoLocation,
68                 "position": self.parent.position,
69                 "layout": self.layout,
70                 "parent": self.parent.parent.parent,
71             }
72         )
73
74     def _create_cells(self) -> list[NrCellDu]:
75         result: list[NrCellDu] = []
76         cell_angle: int = (
77             self.parent.parent.parent.parent.parent.parent.configuration()[
78                 "pattern"
79             ]["nr-cell-du"]["cell-angle"]
80         )
81         for index in range(self._cell_count):
82             s: str = "00" + str(index)
83             name: str = "-".join(
84                 [self.name.replace("RU", "NRCellDu"), s[len(s) - 2 : len(s)]]
85             )
86             azimuth: int = index * cell_angle + self._ru_azimuth
87             result.append(
88                 NrCellDu(
89                     {
90                         "name": name,
91                         "geoLocation": self.geoLocation,
92                         "position": self.position,
93                         "layout": self.layout,
94                         "spiralRadiusProfile": self.spiralRadiusProfile,
95                         "parent": self,
96                         "cellAngle": cell_angle,
97                         "azimuth": azimuth,
98                     }
99                 )
100             )
101         return result
102
103     @property
104     def cells(self) -> list[NrCellDu]:
105         return self._cells
106
107     @property
108     def oRanDu(self) -> ORanDu:
109         return self._oRanDu
110
111     @property
112     def termination_points(self) -> list[ORanTerminationPoint]:
113         result: list[ORanTerminationPoint] = super().termination_points
114         phy_tp: str = "-".join([self.name, "phy".upper()])
115         result.append(ORanTerminationPoint({"id": phy_tp, "name": phy_tp}))
116         for interface in ["ofhm", "ofhc", "ofhu", "ofhs"]:
117             id: str = "-".join([self.name, interface.upper()])
118             result.append(
119                 ORanTerminationPoint(
120                     {"id": id, "name": id, "supporter": phy_tp, "parent": self}
121                 )
122             )
123         for cell in self.cells:
124             result.extend(cell.termination_points)
125         return result
126
127     def to_topology_nodes(self) -> list[dict[str, dict]]:
128         result: list[dict[str, dict]] = super().to_topology_nodes()
129         result.extend(self.oRanDu.to_topology_nodes())
130         return result
131
132     def to_topology_links(self) -> list[dict[str, dict]]:
133         result: list[dict[str, dict]] = super().to_topology_links()
134         result.extend(self.oRanDu.to_topology_links())
135         for interface in ["phy", "ofhm", "ofhc", "ofhu", "ofhs"]:
136             link_id: str = "".join(
137                 [interface, ":", self.name, "<->", self.oRanDu.name]
138             )
139             source_tp: str = "-".join([self.name, interface.upper()])
140             dest_tp: str = "-".join([self.oRanDu.name, interface.upper()])
141             result.append(
142                 {
143                     "link-id": link_id,
144                     "source": {
145                         "source-node": self.name,
146                         "source-tp": source_tp,
147                     },
148                     "destination": {
149                         "dest-node": self.oRanDu.name,
150                         "dest-tp": dest_tp,
151                     },
152                 }
153             )
154         return result
155
156     def toKml(self) -> ET.Element:
157         o_ran_ru: ET.Element = ET.Element("Folder")
158         open: ET.Element = ET.SubElement(o_ran_ru, "open")
159         open.text = "1"
160         name: ET.Element = ET.SubElement(o_ran_ru, "name")
161         name.text = self.name
162         for cell in self.cells:
163             o_ran_ru.append(cell.toKml())
164         return o_ran_ru
165
166     def toSvg(self) -> None:
167         return None