1 # Copyright 2023 highstreet technologies GmbH
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 Module for a class representing a O-RAN Network
19 import xml.etree.ElementTree as ET
20 from typing import Any, cast
22 import network_generation.model.python.hexagon as Hexagon
23 from network_generation.model.python.geo_location import (
27 from network_generation.model.python.hexagon import Layout
28 from network_generation.model.python.o_ran_object import (
32 from network_generation.model.python.o_ran_smo import ORanSmo
33 from network_generation.model.python.o_ran_spiral_radius_profile import (
36 from network_generation.model.python.point import Point
38 # Define the "IORanNetwork" interface
39 IORanNetwork = IORanObject
42 class ORanNetwork(ORanObject):
44 Class representing an O-RAN Network object.
47 __my_default_value: IORanNetwork = cast(IORanNetwork, ORanObject.default())
52 configuration: dict[str, dict],
53 data: dict[str, Any] = cast(dict[str, Any], __my_default_value),
54 **kwargs: dict[str, Any]
56 o_ran_network_data: IORanNetwork = self._to_o_ran_network_data(data)
57 super().__init__(cast(dict[str, Any], o_ran_network_data), **kwargs)
58 self.__configuration = configuration
60 self.name = str(configuration["name"])
61 self._center: IGeoLocation = cast(
62 IGeoLocation, configuration["center"]
65 size: int = int(configuration["pattern"]["nr-cell-du"]["max-reach"])
67 Hexagon.layout_flat, Point(size, size), Point(0, 0)
69 self._spiral_radius_profile: SpiralRadiusProfile = SpiralRadiusProfile(
71 "oRanSmoSpiralRadiusOfNearRtRics": configuration["pattern"][
73 ]["near-rt-ric-spiral-radius"],
74 "oRanNearRtRicSpiralRadiusOfOCus": configuration["pattern"][
76 ]["o-ran-cu-spiral-radius"],
77 "oRanCuSpiralRadiusOfODus": configuration["pattern"][
79 ]["o-ran-du-spiral-radius"],
80 "oRanDuSpiralRadiusOfTowers": configuration["pattern"][
82 ]["tower-spiral-radius"],
85 self._o_ran_smo = ORanSmo(
88 "geoLocation": self.center,
94 def _to_o_ran_network_data(self, data: dict[str, Any]) -> IORanNetwork:
95 result: IORanNetwork = self.__my_default_value
96 for key, key_type in IORanNetwork.__annotations__.items():
98 result[key] = data[key] # type: ignore
102 def center(self) -> GeoLocation:
104 Getter for a json object representing the O-RAN Network.
105 :return O-RAN Network as json object.
107 return GeoLocation(self._center)
110 def spiral_radius_profile(self) -> SpiralRadiusProfile:
112 Getter for a json object representing the SpiralRadiusProfile.
113 :return SpiralRadiusProfile.
115 return self._spiral_radius_profile
118 def configuration(self) -> dict[str, Any]:
120 Getter for a json object representing the O-RAN Network.
121 :return O-RAN Network as json object.
123 return self.__configuration
125 def to_topology(self) -> dict[str, Any]:
126 nodes: list[dict[str, Any]] = self._o_ran_smo.to_topology_nodes()
127 links: list[dict[str, Any]] = self._o_ran_smo.to_topology_links()
129 "ietf-network:networks": {
132 "network-id": self.id,
134 "ietf-network-topology:link": links,
140 def toKml(self) -> ET.Element:
141 root: ET.Element = ET.Element(
142 "kml", xmlns="http://www.opengis.net/kml/2.2"
144 document = ET.SubElement(root, "Document")
145 open: ET.Element = ET.SubElement(document, "open")
147 name: ET.Element = ET.SubElement(document, "name")
148 name.text = self.name
150 document.append(self._o_ran_smo.toKml())
154 def toSvg(self) -> ET.Element:
156 Getter for a xml/svg Element object representing the Network.
157 :return Network as SVG object.
159 root: ET.Element = ET.Element(
161 # width=str(self.__svg_width()),
162 # height=str(self.__svg_height()),
164 # str(-3*self.FONTSIZE),
165 # str(-3*self.FONTSIZE),
166 # str(self.__svg_width()),
167 # str(self.__svg_height())]
169 xmlns="http://www.w3.org/2000/svg",
171 desc = ET.Element("desc")
172 desc.text = "\n context: " + self.id + "\n name: " + self.name
175 title = ET.Element("title")
176 title.text = str(self.configuration["name"])
179 # root.append(self.__context.svg(x, y))
182 def json(self) -> dict[str, Any]:
183 return super().json()