X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=code%2Fnetwork-generator%2Fnetwork_generation%2Fmodel%2Fpython%2Fo_ran_network.py;h=3f816b3c9a712f7951859f0fac2dcfc2af995dc3;hb=c55c6dd77a4a206ec792ab6ad1a4cc53b916a3e0;hp=be6179648c6eb043a30c91f97c418adef38f7a3b;hpb=7004840bca352043aec43d36df79436b90bcbd5a;p=oam.git diff --git a/code/network-generator/network_generation/model/python/o_ran_network.py b/code/network-generator/network_generation/model/python/o_ran_network.py index be61796..3f816b3 100644 --- a/code/network-generator/network_generation/model/python/o_ran_network.py +++ b/code/network-generator/network_generation/model/python/o_ran_network.py @@ -12,17 +12,31 @@ # See the License for the specific language governing permissions and # limitations under the License. -#!/usr/bin/python +# !/usr/bin/python """ Module for a class representing a O-RAN Network """ -from network_generation.model.python.o_ran_smo import ORanSmo -from network_generation.model.python.o_ran_spiral_radius_profile import SpiralRadiusProfile -from network_generation.model.python.o_ran_object import IORanObject, ORanObject +import xml.etree.ElementTree as ET +from typing import Any, cast + import network_generation.model.python.hexagon as Hexagon +from network_generation.model.python.geo_location import ( + GeoLocation, + IGeoLocation, +) from network_generation.model.python.hexagon import Layout +from network_generation.model.python.o_ran_object import ( + IORanObject, + ORanObject, +) +from network_generation.model.python.o_ran_smo import ORanSmo +from network_generation.model.python.o_ran_spiral_radius_profile import ( + SpiralRadiusProfile, +) from network_generation.model.python.point import Point -import xml.etree.ElementTree as ET + +# Define the "IORanNetwork" interface +IORanNetwork = IORanObject class ORanNetwork(ORanObject): @@ -30,30 +44,42 @@ class ORanNetwork(ORanObject): Class representing an O-RAN Network object. """ + __my_default_value: IORanNetwork = cast(IORanNetwork, ORanObject.default()) + # constructor - def __init__(self, configuration: dict[str, dict], of: IORanObject = None, **kwargs): - super().__init__(of, **kwargs) + def __init__( + self, + configuration: dict[str, dict], + data: dict[str, Any] = cast(dict[str, Any], __my_default_value), + **kwargs: dict[str, Any] + ) -> None: + o_ran_network_data: IORanNetwork = self._to_o_ran_network_data(data) + super().__init__(cast(dict[str, Any], o_ran_network_data), **kwargs) self.__configuration = configuration - self.name = configuration["name"] - self.center = configuration["center"] - size = configuration["pattern"]["nr-cell-du"]["max-reach"] + + self.name = str(configuration["name"]) + self._center: IGeoLocation = cast( + IGeoLocation, configuration["center"] + ) + + size: int = int(configuration["pattern"]["nr-cell-du"]["max-reach"]) layout = Layout( Hexagon.layout_flat, Point(size, size), Point(0, 0) ) # 1 pixel = 1 meter - spiral_radius_profile = SpiralRadiusProfile( + self._spiral_radius_profile: SpiralRadiusProfile = SpiralRadiusProfile( { - "oRanSmoSpiralRadiusOfNearRtRics": configuration["pattern"]["smo"][ - "near-rt-ric-spiral-radius" - ], + "oRanSmoSpiralRadiusOfNearRtRics": configuration["pattern"][ + "smo" + ]["near-rt-ric-spiral-radius"], "oRanNearRtRicSpiralRadiusOfOCus": configuration["pattern"][ "near-rt-ric" ]["o-ran-cu-spiral-radius"], - "oRanCuSpiralRadiusOfODus": configuration["pattern"]["o-ran-cu"][ - "o-ran-du-spiral-radius" - ], - "oRanDuSpiralRadiusOfTowers": configuration["pattern"]["o-ran-du"][ - "tower-spiral-radius" - ], + "oRanCuSpiralRadiusOfODus": configuration["pattern"][ + "o-ran-cu" + ]["o-ran-du-spiral-radius"], + "oRanDuSpiralRadiusOfTowers": configuration["pattern"][ + "o-ran-du" + ]["tower-spiral-radius"], } ) self._o_ran_smo = ORanSmo( @@ -61,22 +87,44 @@ class ORanNetwork(ORanObject): "name": "O-RAN-SMO", "geoLocation": self.center, "layout": layout, - "spiralRadiusProfile": spiral_radius_profile, "parent": self, } ) - # getter - def configuration(self) -> dict[str, dict]: + def _to_o_ran_network_data(self, data: dict[str, Any]) -> IORanNetwork: + result: IORanNetwork = self.__my_default_value + for key, key_type in IORanNetwork.__annotations__.items(): + if key in data: + result[key] = data[key] # type: ignore + return result + + @property + def center(self) -> GeoLocation: + """ + Getter for a json object representing the O-RAN Network. + :return O-RAN Network as json object. + """ + return GeoLocation(self._center) + + @property + def spiral_radius_profile(self) -> SpiralRadiusProfile: + """ + Getter for a json object representing the SpiralRadiusProfile. + :return SpiralRadiusProfile. + """ + return self._spiral_radius_profile + + @property + def configuration(self) -> dict[str, Any]: """ Getter for a json object representing the O-RAN Network. :return O-RAN Network as json object. """ return self.__configuration - def to_topology(self) -> dict[str, dict]: - nodes: dict[str, dict] = self._o_ran_smo.to_topology_nodes() - links: dict[str, dict] = self._o_ran_smo.to_topology_links() + def to_topology(self) -> dict[str, Any]: + nodes: list[dict[str, Any]] = self._o_ran_smo.to_topology_nodes() + links: list[dict[str, Any]] = self._o_ran_smo.to_topology_links() return { "ietf-network:networks": { "network": [ @@ -88,9 +136,11 @@ class ORanNetwork(ORanObject): ], } } - + def toKml(self) -> ET.Element: - root: ET.Element = ET.Element("kml", xmlns="http://www.opengis.net/kml/2.2") + root: ET.Element = ET.Element( + "kml", xmlns="http://www.opengis.net/kml/2.2" + ) document = ET.SubElement(root, "Document") open: ET.Element = ET.SubElement(document, "open") open.text = "1" @@ -119,12 +169,15 @@ class ORanNetwork(ORanObject): xmlns="http://www.w3.org/2000/svg", ) desc = ET.Element("desc") - # desc.text="\n context: " + str(self.id()) + "\n name: " + str(self.name()) + desc.text = "\n context: " + self.id + "\n name: " + self.name root.append(desc) title = ET.Element("title") - title.text = self.configuration()["name"] + title.text = str(self.configuration["name"]) root.append(title) # root.append(self.__context.svg(x, y)) return root + + def json(self) -> dict[str, Any]: + return super().json()