Move all business logic code under template folder
[oam.git] / code / network-generator / model / python / o_ran_smo.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 Service Management and Orchestration Framework (SMO)
19 """
20 from typing import overload
21 from model.python.tower import Tower
22 from model.python.o_ran_near_rt_ric import ORanNearRtRic
23 from model.python.o_ran_object import IORanObject
24 from model.python.o_ran_node import ORanNode
25 from model.python.hexagon import Hex
26 from model.python.o_ran_termination_point import ORanTerminationPoint
27 import model.python.hexagon as Hexagon
28 import xml.etree.ElementTree as ET
29
30
31 # Define the "IORanSmo" interface
32 class IORanSmo(IORanObject):
33     def __init__(self, **kwargs):
34         super().__init__(**kwargs)
35
36
37 # Define an abstract O-RAN Node class
38 class ORanSmo(ORanNode, IORanSmo):
39     def __init__(self, o_ran_smo_data: IORanSmo = None, **kwargs):
40         super().__init__(o_ran_smo_data, **kwargs)
41         self._o_ran_near_rt_rics: list[ORanNearRtRic] = self._calculate_near_rt_rics()
42
43     def _calculate_near_rt_rics(self) -> list[ORanNearRtRic]:
44         hex_ring_radius: int = self.spiralRadiusProfile.oRanSmoSpiralRadiusOfNearRtRics
45         hex_list: list[Hex] = self.spiralRadiusProfile.oRanNearRtRicSpiral(
46             self.position, hex_ring_radius
47         )
48         result: list[ORanNearRtRic] = []
49         for index, hex in enumerate(hex_list):
50             s: str = "00" + str(index)
51             name: str = "-".join(
52                 [self.name.replace("SMO", "NearRtRic"), s[len(s) - 2 : len(s)]]
53             )
54             network_center: dict = self.parent.center
55             newGeo = Hexagon.hex_to_geo_location(
56                 self.layout, hex, network_center
57             ).json()
58             result.append(
59                 ORanNearRtRic(
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_near_rt_rics(self) -> list[ORanNearRtRic]:
75         return self._o_ran_near_rt_rics
76
77     @property
78     def termination_points(self) -> list[ORanTerminationPoint]:
79         result: list[ORanTerminationPoint] = super().termination_points
80         phy_tp: str = "-".join([self.name, "phy".upper()])
81         result.append(ORanTerminationPoint({"id": phy_tp, "name": phy_tp}))
82         for interface in ["a1", "o1", "o2"]:
83             id:str = "-".join([self.name, interface.upper()])
84             result.append(ORanTerminationPoint({"id": id, "name":id, "supporter": phy_tp, "parent":self}))
85         return result
86
87     @property
88     def towers(self) -> list[Tower]:
89         result: list[Tower] = []
90         for ric in self.o_ran_near_rt_rics:
91             for tower in ric.towers:
92                 result.append(tower)
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 ric in self.o_ran_near_rt_rics:
98             result.extend(ric.to_topology_nodes())
99         return result
100
101     def to_topology_links(self) -> list[dict[str, dict]]:
102         result: list[dict[str, dict]] = [] # super().to_topology_links()
103         for ric in self.o_ran_near_rt_rics:
104             result.extend(ric.to_topology_links())
105         return result
106
107     def toKml(self) -> ET.Element:
108         smo: ET.Element = ET.Element("Folder")
109         open: ET.Element = ET.SubElement(smo, "open")
110         open.text = "1"
111         name: ET.Element = ET.SubElement(smo, "name")
112         name.text = self.name
113         for ric in self.o_ran_near_rt_rics:
114             smo.append(ric.toKml())
115         return smo
116
117     def toSvg(self) -> None:
118         return None