Reformat files according to template
[oam.git] / code / network-generator / network_generation / model / python / o_ran_cloud_du.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 O-Cloud resource pool for O-RAN distributed units (ORanDu)
19 By default all O-RAN-DUs associated with the towers around  are deployed here.
20 Maybe dedicated hardware is required to host O-DUs, but it is expected 
21 that the O-Cloud mechanism and concepts can be applied here.
22 """
23 import xml.etree.ElementTree as ET
24 from typing import overload
25
26 import network_generation.model.python.hexagon as Hexagon
27 from network_generation.model.python.cube import Cube
28 from network_generation.model.python.hexagon import Hex
29 from network_generation.model.python.o_ran_node import ORanNode
30 from network_generation.model.python.o_ran_object import IORanObject
31 from network_generation.model.python.o_ran_termination_point import (
32     ORanTerminationPoint,
33 )
34 from network_generation.model.python.tower import Tower
35
36
37 # Define the "IORanDu" interface
38 class IORanCloudDu(IORanObject):
39     def __init__(self, **kwargs):
40         super().__init__(**kwargs)
41
42
43 # Implements a concrete O-RAN Node class
44 class ORanCloudDu(ORanNode, IORanCloudDu):
45     def __init__(self, o_ran_du_data: IORanCloudDu = None, **kwargs):
46         super().__init__(o_ran_du_data, **kwargs)
47         self._towers: list[Tower] = self._calculate_towers()
48
49     def _calculate_towers(self) -> list[Tower]:
50         hex_ring_radius: int = (
51             self.spiralRadiusProfile.oRanDuSpiralRadiusOfTowers
52         )
53         hex_list: list[Hex] = Cube.spiral(self.position, hex_ring_radius)
54         result: list[Tower] = []
55         for index, hex in enumerate(hex_list):
56             s: str = "00" + str(index)
57             name: str = "-".join(
58                 [
59                     self.name.replace("O-Cloud-DU", "Tower"),
60                     s[len(s) - 2 : len(s)],
61                 ]
62             )
63             network_center: dict = self.parent.parent.parent.parent.center
64             newGeo = Hexagon.hex_to_geo_location(
65                 self.layout, hex, network_center
66             ).json()
67             result.append(
68                 Tower(
69                     {
70                         "name": name,
71                         "geoLocation": newGeo,
72                         "position": hex,
73                         "layout": self.layout,
74                         "spiralRadiusProfile": self.spiralRadiusProfile,
75                         "parent": self,
76                     }
77                 )
78             )
79         return result
80
81     @property
82     def towers(self) -> list[Tower]:
83         return self._towers
84
85     @property
86     def termination_points(self) -> list[ORanTerminationPoint]:
87         result: list[ORanTerminationPoint] = super().termination_points
88         phy_tp: str = "-".join([self.name, "phy".upper()])
89         result.append(ORanTerminationPoint({"id": phy_tp, "name": phy_tp}))
90         for interface in ["o2"]:
91             id: str = "-".join([self.name, interface.upper()])
92             result.append(
93                 ORanTerminationPoint(
94                     {"id": id, "name": id, "supporter": phy_tp, "parent": self}
95                 )
96             )
97         return result
98
99     def to_topology_nodes(self) -> list[dict[str, dict]]:
100         result: list[dict[str, dict]] = super().to_topology_nodes()
101         for tower in self.towers:
102             result.extend(tower.to_topology_nodes())
103         return result
104
105     def to_topology_links(self) -> list[dict[str, dict]]:
106         result: list[dict[str, dict]] = super().to_topology_links()
107         for tower in self.towers:
108             result.extend(tower.to_topology_links())
109         return result
110
111     def toKml(self) -> ET.Element:
112         o_ran_cloud_du: ET.Element = ET.Element("Folder")
113         open: ET.Element = ET.SubElement(o_ran_cloud_du, "open")
114         open.text = "1"
115         name: ET.Element = ET.SubElement(o_ran_cloud_du, "name")
116         name.text = self.name
117         for tower in self.towers:
118             o_ran_cloud_du.append(tower.toKml())
119         return o_ran_cloud_du
120
121     def toSvg(self) -> None:
122         return None