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
20 import xml.etree.ElementTree as ET
21 from abc import abstractmethod
22 from typing import Any, cast
24 import network_generation.model.python.hexagon as Hexagon
25 from network_generation.model.python.countries import Country
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):
45 geoLocation: GeoLocation
49 spiralRadiusProfile: SpiralRadiusProfile
53 default_address: AddressType = {
54 "street": "highstreet",
60 "country": Country.Germany,
62 default_value: IORanNode = cast(
65 **ORanObject.default(),
67 "address": default_address,
68 "geoLocation": GeoLocation(),
70 "position": Hex(0, 0, 0),
71 "layout": Layout(Hexagon.layout_flat, Point(1, 1), Point(0, 0)),
72 "spiralRadiusProfile": SpiralRadiusProfile(),
79 # Define an abstract O-RAN Node class
80 class ORanNode(ORanObject):
82 def default() -> dict[str, Any]:
83 return cast(dict[str, Any], default_value)
87 data: dict[str, Any] = cast(dict[str, Any], default_value),
88 **kwargs: dict[str, Any]
90 o_ran_node_data: IORanNode = self._to_o_ran_node_data(data)
91 super().__init__(cast(dict[str, Any], data), **kwargs)
92 self._address: AddressType = cast(
93 AddressType, o_ran_node_data["address"]
95 self._geo_location: GeoLocation = cast(
96 GeoLocation, o_ran_node_data["geoLocation"]
98 self._url: str = str(o_ran_node_data["url"])
99 self._position: Hex = cast(Hex, o_ran_node_data["position"])
100 self._layout: Layout = cast(Layout, o_ran_node_data["layout"])
101 self._spiral_radius_profile: SpiralRadiusProfile = cast(
102 SpiralRadiusProfile, o_ran_node_data["spiralRadiusProfile"]
104 self._parent: Any = o_ran_node_data["parent"]
105 self._termination_points: list[ORanTerminationPoint] = []
107 def _to_o_ran_node_data(self, data: dict[str, Any]) -> IORanNode:
108 result: IORanNode = default_value
109 for key, key_type in IORanNode.__annotations__.items():
111 result[key] = data[key] # type: ignore
115 def address(self) -> AddressType:
119 def address(self, value: AddressType) -> None:
120 self._address = value
123 def geo_location(self) -> GeoLocation:
124 return self._geo_location
127 def geo_location(self, value: GeoLocation) -> None:
128 self._geo_location = value
131 def url(self) -> str:
135 def url(self, value: str) -> None:
139 def position(self) -> Hex:
140 return self._position
143 def position(self, value: Hex) -> None:
144 self._position = value
147 def layout(self) -> Layout:
151 def layout(self, value: Layout) -> None:
155 def spiral_radius_profile(self) -> SpiralRadiusProfile:
156 return self._spiral_radius_profile
158 @spiral_radius_profile.setter
159 def spiral_radius_profile(self, value: SpiralRadiusProfile) -> None:
160 self._spiral_radius_profile = value
165 ) -> Any: # expected are ORanNodes and all inherits for ORanNode
169 def parent(self, value: Any) -> None:
174 def termination_points(self) -> list[ORanTerminationPoint]:
175 return self._termination_points
178 def to_topology_nodes(self) -> list[dict[str, Any]]:
179 tps: list[dict[str, Any]] = []
180 for tp in self.termination_points():
181 tps.append(tp.to_topology())
183 result: list[dict[str, Any]] = []
186 "node-id": self.name,
187 "ietf-network-topology:termination-point": tps,
193 def to_topology_links(self) -> list[dict[str, Any]]:
194 result: list[dict[str, Any]] = []
195 source_tp: str = "-".join([self.name, "phy".upper()])
196 dest_tp: str = "-".join([self.parent.name, "phy".upper()])
197 if self.parent and "Tower" not in source_tp and "Tower" not in dest_tp:
198 link_id: str = "".join(
199 ["phy", ":", self.name, "<->", self.parent.name]
203 "source": {"source-node": self.name, "source-tp": source_tp},
205 "dest-node": self.parent.name,
213 def toKml(self) -> ET.Element | None:
217 def toSvg(self) -> ET.Element: