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
21 from typing import Any, cast
23 import network_generation.model.python.hexagon as Hexagon
24 from network_generation.model.python.geo_location import (
28 from network_generation.model.python.hexagon import Layout
29 from network_generation.model.python.o_ran_object import (
33 from network_generation.model.python.o_ran_smo import ORanSmo
34 from network_generation.model.python.o_ran_spiral_radius_profile import (
37 from network_generation.model.python.point import Point
39 # Define the "IORanNetwork" interface
40 IORanNetwork = IORanObject
43 class ORanNetwork(ORanObject):
45 Class representing an O-RAN Network object.
48 __my_default_value: IORanNetwork = cast(IORanNetwork, ORanObject.default())
53 configuration: dict[str, dict],
54 data: dict[str, Any] = cast(dict[str, Any], __my_default_value),
55 **kwargs: dict[str, Any]
57 o_ran_network_data: IORanNetwork = self._to_o_ran_network_data(data)
58 super().__init__(cast(dict[str, Any], o_ran_network_data), **kwargs)
59 self.__configuration = configuration
61 self.name = str(configuration["name"])
62 self._center: IGeoLocation = cast(
63 IGeoLocation, configuration["center"]
67 int(configuration["pattern"]["nrCellDu"]["maxReach"])
71 configuration["pattern"]["nrCellDu"][
72 "cellScaleFactorForHandoverArea"
79 Hexagon.layout_flat, Point(size, size), Point(0, 0)
81 self._spiral_radius_profile: SpiralRadiusProfile = SpiralRadiusProfile(
83 "oRanSmoSpiralRadiusOfNearRtRics": configuration["pattern"][
85 ]["nearRtRicSpiralRadius"],
86 "oRanNearRtRicSpiralRadiusOfOCus": configuration["pattern"][
88 ]["oRanCuSpiralRadius"],
89 "oRanCuSpiralRadiusOfODus": configuration["pattern"][
91 ]["oRanDuSpiralRadius"],
92 "oRanDuSpiralRadiusOfTowers": configuration["pattern"][
94 ]["towerSpiralRadius"],
97 self._o_ran_smo = ORanSmo(
100 "geoLocation": self.center,
106 def _to_o_ran_network_data(self, data: dict[str, Any]) -> IORanNetwork:
107 result: IORanNetwork = self.__my_default_value
108 for key, key_type in IORanNetwork.__annotations__.items():
110 result[key] = data[key] # type: ignore
114 def center(self) -> GeoLocation:
116 Getter for a json object representing the O-RAN Network.
117 :return O-RAN Network as json object.
119 return GeoLocation(self._center)
122 def spiral_radius_profile(self) -> SpiralRadiusProfile:
124 Getter for a json object representing the SpiralRadiusProfile.
125 :return SpiralRadiusProfile.
127 return self._spiral_radius_profile
130 def configuration(self) -> dict[str, Any]:
132 Getter for a json object representing the O-RAN Network.
133 :return O-RAN Network as json object.
135 return self.__configuration
137 def to_topology(self) -> dict[str, Any]:
138 nodes: list[dict[str, Any]] = self._o_ran_smo.to_topology_nodes()
139 links: list[dict[str, Any]] = self._o_ran_smo.to_topology_links()
141 "ietf-network:networks": {
144 "network-id": self.id,
146 "ietf-network-topology:link": links,
152 def to_directory(self, parent_dir: str) -> None:
153 self._o_ran_smo.to_directory(os.path.join(parent_dir, self.id))
155 def toKml(self) -> ET.Element:
156 root: ET.Element = ET.Element(
157 "kml", xmlns="http://www.opengis.net/kml/2.2"
159 document = ET.SubElement(root, "Document")
160 open: ET.Element = ET.SubElement(document, "open")
162 name: ET.Element = ET.SubElement(document, "name")
163 name.text = self.name
165 document.append(self._o_ran_smo.toKml())
169 def toSvg(self) -> ET.Element:
171 Getter for a xml/svg Element object representing the Network.
172 :return Network as SVG object.
174 root: ET.Element = ET.Element(
176 # width=str(self.__svg_width()),
177 # height=str(self.__svg_height()),
179 # str(-3*self.FONTSIZE),
180 # str(-3*self.FONTSIZE),
181 # str(self.__svg_width()),
182 # str(self.__svg_height())]
184 xmlns="http://www.w3.org/2000/svg",
186 desc = ET.Element("desc")
187 desc.text = "\n context: " + self.id + "\n name: " + self.name
190 title = ET.Element("title")
191 title.text = str(self.configuration["name"])
194 # root.append(self.__context.svg(x, y))
197 def json(self) -> dict[str, Any]:
198 return super().json()