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