617827ad3a9d89ee9618dea3391719a89b0ea7e3
[oam.git] / code / network-generator / 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 model.python.hexagon as Hexagon
24 from model.python.hexagon import Hex
25 from model.python.cube import Cube
26 from model.python.tower import Tower
27 from model.python.o_ran_object import IORanObject
28 from model.python.o_ran_node import ORanNode
29 import xml.etree.ElementTree as ET
30
31
32 # Define the "IORanDu" interface
33 class IORanCloudDu(IORanObject):
34     def __init__(self, **kwargs):
35         super().__init__(**kwargs)
36
37
38 # Implements a concrete O-RAN Node class
39 class ORanCloudDu(ORanNode, IORanCloudDu):
40     def __init__(self, o_ran_du_data: IORanCloudDu = None, **kwargs):
41         super().__init__(o_ran_du_data, **kwargs)
42         self._towers: list[Tower] = self._calculate_towers()
43
44     def _calculate_towers(self) -> list[Tower]:
45         hex_ring_radius: int = self.spiralRadiusProfile.oRanDuSpiralRadiusOfTowers
46         hex_list: list[Hex] = Cube.spiral(self.position, hex_ring_radius)
47         result: list[Tower] = []
48         for index, hex in enumerate(hex_list):
49             s: str = "00" + str(index)
50             name: str = "-".join(
51                 [self.name.replace("O-Cloud-DU", "Tower"), s[len(s) - 2 : len(s)]]
52             )
53             network_center: dict = self.parent.parent.parent.parent.center
54             newGeo = Hexagon.hex_to_geo_location(
55                 self.layout, hex, network_center
56             ).json()
57             result.append(
58                 Tower(
59                     {
60                         "name": name,
61                         "geoLocation": newGeo,
62                         "position": hex,
63                         "layout": self.layout,
64                         "spiralRadiusProfile": self.spiralRadiusProfile,
65                         "parent": self,
66                     }
67                 )
68             )
69         return result
70
71     @property
72     def towers(self) -> list[Tower]:
73         return self._towers
74
75     def toKml(self) -> ET.Element:
76         o_ran_cloud_du: ET.Element = ET.Element("Folder")
77         open: ET.Element = ET.SubElement(o_ran_cloud_du, "open")
78         open.text = "1"
79         name: ET.Element = ET.SubElement(o_ran_cloud_du, "name")
80         name.text = self.name
81         for tower in self.towers:
82             o_ran_cloud_du.append(tower.toKml())
83         return o_ran_cloud_du
84
85     def toSvg(self) -> None:
86         return None