Move all business logic code under template folder
[oam.git] / code / network-generator / network_generation / model / python / o_ran_cu.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 centralized unit (ORanCu)
19 and at the same time a location for an O-Cloud resource pool
20 """
21 from typing import overload
22 from network_generation.model.python.cube import Cube
23 from network_generation.model.python.hexagon import Hex
24 import network_generation.model.python.hexagon as Hexagon
25 from network_generation.model.python.o_ran_cloud_du import ORanCloudDu
26 from network_generation.model.python.tower import Tower
27 from network_generation.model.python.o_ran_object import IORanObject
28 from network_generation.model.python.o_ran_node import ORanNode
29 from network_generation.model.python.o_ran_termination_point import ORanTerminationPoint
30 import xml.etree.ElementTree as ET
31
32
33 # Define the "IORanCu" interface
34 class IORanCu(IORanObject):
35     def __init__(self, **kwargs):
36         super().__init__(**kwargs)
37
38
39 # Define an abstract O-RAN Node class
40 class ORanCu(ORanNode, IORanCu):
41     def __init__(self, o_ran_cu_data: IORanCu = None, **kwargs):
42         super().__init__(o_ran_cu_data, **kwargs)
43         self._o_ran_cloud_dus: list[ORanCu] = self._calculate_o_ran_dus()
44
45     def _calculate_o_ran_dus(self) -> list[ORanCloudDu]:
46         hex_ring_radius: int = self.spiralRadiusProfile.oRanCuSpiralRadiusOfODus
47         hex_list: list[Hex] = self.spiralRadiusProfile.oRanDuSpiral(self.position, hex_ring_radius)
48         result: list[ORanCloudDu] = []
49         for index, hex in enumerate(hex_list):
50             s: str = "00" + str(index)
51             name: str = "-".join(
52                 [self.name.replace("CU", "O-Cloud-DU"), s[len(s) - 2 : len(s)]]
53             )
54             network_center: dict = self.parent.parent.parent.center
55             newGeo = Hexagon.hex_to_geo_location(
56                 self.layout, hex, network_center
57             ).json()
58             result.append(
59                 ORanCloudDu(
60                     {
61                         "name": name,
62                         "geoLocation": newGeo,
63                         "position": hex,
64                         "layout": self.layout,
65                         "spiralRadiusProfile": self.spiralRadiusProfile,
66                         "parent": self,
67                     }
68                 )
69             )
70         return result
71
72
73     @property
74     def o_ran_cloud_dus(self) -> list[ORanCloudDu]:
75         return self._o_ran_cloud_dus
76
77     @property
78     def towers(self) -> list[Tower]:
79         result: list[Tower] = []
80         for du in self.o_ran_cloud_dus:
81             for tower in du.towers:
82                 result.append(tower)
83         return result
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({"tp-id": phy_tp, "name": phy_tp})
90         for interface in ["e2", "o1"]:
91             id:str = "-".join([self.name, interface.upper()])
92             result.append(ORanTerminationPoint({"id": id, "name":id, "supporter": phy_tp, "parent":self}))
93         return result
94
95     def to_topology_nodes(self) -> list[dict[str, dict]]:
96         result: list[dict[str, dict]] = super().to_topology_nodes()
97         # for o_ran_du in self.o_ran_dus: # TODO
98         #     result.extend(o_ran_du.to_topology_nodes())
99         for o_ran_cloud_du in self.o_ran_cloud_dus:
100             result.extend(o_ran_cloud_du.to_topology_nodes())    
101         return result
102
103     def to_topology_links(self) -> list[dict[str, dict]]:
104         result: list[dict[str, dict]] = super().to_topology_links()
105         # for o_ran_du in self.o_ran_dus:
106             # result.extend(o_ran_du.to_topology_links())
107         for o_ran_cloud_du in self.o_ran_cloud_dus:
108             result.extend(o_ran_cloud_du.to_topology_links())    
109         return result
110
111     def toKml(self) -> ET.Element:
112         o_ran_cu: ET.Element = ET.Element("Folder")
113         open: ET.Element = ET.SubElement(o_ran_cu, "open")
114         open.text = "1"
115         name: ET.Element = ET.SubElement(o_ran_cu, "name")
116         name.text = self.name
117         for o_ran_cloud_du in self.o_ran_cloud_dus:
118             o_ran_cu.append(o_ran_cloud_du.toKml())
119         return o_ran_cu
120
121
122     def toSvg(self) -> None:
123         return None