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