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.
18 An abstract Class for O-RAN Node
21 import xml.etree.ElementTree as ET
22 from abc import abstractmethod, abstractproperty
23 from typing import Any
25 import network_generation.model.python.hexagon as Hexagon
26 from network_generation.model.python.geo_location import GeoLocation
27 from network_generation.model.python.hexagon import Hex, Layout
28 from network_generation.model.python.o_ran_object import (
32 from network_generation.model.python.o_ran_spiral_radius_profile import (
35 from network_generation.model.python.o_ran_termination_point import (
38 from network_generation.model.python.point import Point
39 from network_generation.model.python.type_definitions import AddressType
42 # Define the "IORanObject" interface
43 class IORanNode(IORanObject):
46 address: AddressType = None,
47 geoLocation: GeoLocation = None,
50 layout: Layout = None,
51 spiralRadiusProfile: SpiralRadiusProfile = None,
55 super().__init__(**kwargs)
56 self.address = address
57 self.geoLocation = geoLocation
59 self.position = position
61 self.spiralRadiusProfile = (spiralRadiusProfile,)
65 # Define an abstract O-RAN Node class
66 class ORanNode(ORanObject, IORanNode):
67 def __init__(self, of: IORanNode = None, **kwargs):
68 super().__init__(of, **kwargs)
69 self.address = of["address"] if of and "address" in of else None
71 of["geoLocation"] if of and "geoLocation" in of else GeoLocation()
73 self.url = of["url"] if of and "url" in of else self.id
75 of["position"] if of and "position" in of else Hex(0, 0, 0)
79 if of and "layout" in of
80 else Layout(Hexagon.layout_flat, Point(1, 1), Point(0, 0))
82 self.spiralRadiusProfile = (
83 of["spiralRadiusProfile"]
84 if of and "spiralRadiusProfile" in of
85 else SpiralRadiusProfile()
87 self.parent = of["parent"] if of and "parent" in of else None
88 self._termination_points: list[ORanTerminationPoint] = []
91 def address(self) -> str:
95 def address(self, value: str):
99 def geoLocation(self) -> GeoLocation:
100 return self._geographicalLocation
103 def geoLocation(self, value: GeoLocation):
104 self._geographicalLocation = value
107 def url(self) -> str:
111 def url(self, value: str):
115 def position(self) -> Hex:
116 return self._position
119 def position(self, value: Hex):
120 self._position = value
123 def layout(self) -> Layout:
127 def layout(self, value: Layout):
131 def spiralRadiusProfile(self) -> SpiralRadiusProfile:
132 return self._spiralRadiusProfile
134 @spiralRadiusProfile.setter
135 def spiralRadiusProfile(self, value: SpiralRadiusProfile):
136 self._spiralRadiusProfile = value
141 ) -> Any: # expected are ORanNodes and all inherits for ORanNode
145 def parent(self, value: Any):
149 def termination_points(self) -> list[ORanTerminationPoint]:
150 return self._termination_points
152 def json(self) -> dict[str, dict]:
153 result: dict = super().json()
154 result["address"] = self.address
155 result["geoLocation"] = self.geoLocation
156 result["url"] = self.url
157 result["layout"] = self.layout
158 result["spiralRadiusProfile"] = self.spiralRadiusProfile
159 result["parent"] = self.parent
163 def to_topology_nodes(self) -> list[dict[str, dict]]:
164 tps: list[dict[str, dict]] = []
165 for tp in self.termination_points:
168 == "<class 'model.python.o_ran_termination_point.ORanTerminationPoint'>"
170 tps.append(tp.to_topology())
172 result: list[dict[str, dict]] = []
175 "node-id": self.name,
176 "ietf-network-topology:termination-point": tps,
182 def to_topology_links(self) -> list[dict[str, dict]]:
183 result: list[dict[str, dict]] = []
184 source_tp: str = "-".join([self.name, "phy".upper()])
185 dest_tp: str = "-".join([self.parent.name, "phy".upper()])
186 if self.parent and not "Tower" in source_tp and not "Tower" in dest_tp:
187 link_id: str = "".join(
188 ["phy", ":", self.name, "<->", self.parent.name]
192 "source": {"source-node": self.name, "source-tp": source_tp},
194 "dest-node": self.parent.name,
202 def toKml(self) -> ET.Element | None:
206 def toSvg(self) -> ET.Element | None: