Implement kml function for smo, near-rt-ric, o-cu
[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 model.python.tower import Tower
21 from model.python.o_ran_near_rt_ric import ORanNearRtRic
22 from model.python.o_ran_object import IORanObject
23 from model.python.o_ran_node import ORanNode
24 from model.python.hexagon import Hex
25 import model.python.hexagon as Hexagon
26 import xml.etree.ElementTree as ET
27
28
29 # Define the "IORanSmo" interface
30 class IORanSmo(IORanObject):
31     def __init__(self, **kwargs):
32         super().__init__(**kwargs)
33
34
35 # Define an abstract O-RAN Node class
36 class ORanSmo(ORanNode, IORanSmo):
37     def __init__(self, o_ran_smo_data: IORanSmo = None, **kwargs):
38         super().__init__(o_ran_smo_data, **kwargs)
39         self._o_ran_near_rt_rics: list[ORanNearRtRic] = self._calculate_near_rt_rics()
40
41     def _calculate_near_rt_rics(self) -> list[ORanNearRtRic]:
42         hex_ring_radius: int = self.spiralRadiusProfile.oRanSmoSpiralRadiusOfNearRtRics
43         hex_list: list[Hex] = self.spiralRadiusProfile.oRanNearRtRicSpiral(
44             self.position, hex_ring_radius
45         )
46         result: list[ORanNearRtRic] = []
47         for index, hex in enumerate(hex_list):
48             s: str = "00" + str(index)
49             name: str = "-".join(
50                 [self.name.replace("SMO", "NearRtRic"), s[len(s) - 2 : len(s)]]
51             )
52             network_center: dict = self.parent.center
53             newGeo = Hexagon.hex_to_geo_location(
54                 self.layout, hex, network_center
55             ).json()
56             result.append(
57                 ORanNearRtRic(
58                     {
59                         "name": name,
60                         "geoLocation": newGeo,
61                         "position": hex,
62                         "layout": self.layout,
63                         "spiralRadiusProfile": self.spiralRadiusProfile,
64                         "parent": self,
65                     }
66                 )
67             )
68         return result
69
70     @property
71     def o_ran_near_rt_rics(self) -> list[ORanNearRtRic]:
72         return self._o_ran_near_rt_rics
73
74     @property
75     def towers(self) -> list[Tower]:
76         result: list[Tower] = []
77         for ric in self.o_ran_near_rt_rics:
78             for tower in ric.towers:
79                 result.append(tower)
80         return result
81
82     def toKml(self) -> ET.Element:
83         smo: ET.Element = ET.Element("Folder")
84         open: ET.Element = ET.SubElement(smo, "open")
85         open.text = "1"
86         name: ET.Element = ET.SubElement(smo, "name")
87         name.text = self.name
88         for ric in self.o_ran_near_rt_rics:
89             smo.append(ric.toKml())
90         return smo
91
92     def toSvg(self) -> None:
93         return None