Reformat files according to template
[oam.git] / code / network-generator / network_generation / model / python / o_ran_network.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 Module for a class representing a O-RAN Network
18 """
19 import xml.etree.ElementTree as ET
20
21 import network_generation.model.python.hexagon as Hexagon
22 from network_generation.model.python.hexagon import Layout
23 from network_generation.model.python.o_ran_object import (
24     IORanObject,
25     ORanObject,
26 )
27 from network_generation.model.python.o_ran_smo import ORanSmo
28 from network_generation.model.python.o_ran_spiral_radius_profile import (
29     SpiralRadiusProfile,
30 )
31 from network_generation.model.python.point import Point
32
33
34 class ORanNetwork(ORanObject):
35     """
36     Class representing an O-RAN Network object.
37     """
38
39     # constructor
40     def __init__(
41         self, configuration: dict[str, dict], of: IORanObject = None, **kwargs
42     ):
43         super().__init__(of, **kwargs)
44         self.__configuration = configuration
45         self.name = configuration["name"]
46         self.center = configuration["center"]
47         size = configuration["pattern"]["nr-cell-du"]["max-reach"]
48         layout = Layout(
49             Hexagon.layout_flat, Point(size, size), Point(0, 0)
50         )  # 1 pixel = 1 meter
51         spiral_radius_profile = SpiralRadiusProfile(
52             {
53                 "oRanSmoSpiralRadiusOfNearRtRics": configuration["pattern"][
54                     "smo"
55                 ]["near-rt-ric-spiral-radius"],
56                 "oRanNearRtRicSpiralRadiusOfOCus": configuration["pattern"][
57                     "near-rt-ric"
58                 ]["o-ran-cu-spiral-radius"],
59                 "oRanCuSpiralRadiusOfODus": configuration["pattern"][
60                     "o-ran-cu"
61                 ]["o-ran-du-spiral-radius"],
62                 "oRanDuSpiralRadiusOfTowers": configuration["pattern"][
63                     "o-ran-du"
64                 ]["tower-spiral-radius"],
65             }
66         )
67         self._o_ran_smo = ORanSmo(
68             {
69                 "name": "O-RAN-SMO",
70                 "geoLocation": self.center,
71                 "layout": layout,
72                 "spiralRadiusProfile": spiral_radius_profile,
73                 "parent": self,
74             }
75         )
76
77     # getter
78     def configuration(self) -> dict[str, dict]:
79         """
80         Getter for a json object representing the O-RAN Network.
81         :return O-RAN Network as json object.
82         """
83         return self.__configuration
84
85     def to_topology(self) -> dict[str, dict]:
86         nodes: dict[str, dict] = self._o_ran_smo.to_topology_nodes()
87         links: dict[str, dict] = self._o_ran_smo.to_topology_links()
88         return {
89             "ietf-network:networks": {
90                 "network": [
91                     {
92                         "network-id": self.id,
93                         "node": nodes,
94                         "ietf-network-topology:link": links,
95                     }
96                 ],
97             }
98         }
99
100     def toKml(self) -> ET.Element:
101         root: ET.Element = ET.Element(
102             "kml", xmlns="http://www.opengis.net/kml/2.2"
103         )
104         document = ET.SubElement(root, "Document")
105         open: ET.Element = ET.SubElement(document, "open")
106         open.text = "1"
107         name: ET.Element = ET.SubElement(document, "name")
108         name.text = self.name
109
110         document.append(self._o_ran_smo.toKml())
111
112         return root
113
114     def toSvg(self) -> ET.Element:
115         """
116         Getter for a xml/svg Element object representing the Network.
117         :return Network as SVG object.
118         """
119         root: ET.Element = ET.Element(
120             "svg",
121             # width=str(self.__svg_width()),
122             # height=str(self.__svg_height()),
123             # viewBox=" ".join([
124             #     str(-3*self.FONTSIZE),
125             #     str(-3*self.FONTSIZE),
126             #     str(self.__svg_width()),
127             #     str(self.__svg_height())]
128             # ),
129             xmlns="http://www.w3.org/2000/svg",
130         )
131         desc = ET.Element("desc")
132         # desc.text="\n context: " + str(self.id()) + "\n name: " + str(self.name())
133         root.append(desc)
134
135         title = ET.Element("title")
136         title.text = self.configuration()["name"]
137         root.append(title)
138
139         # root.append(self.__context.svg(x, y))
140         return root