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 from abc import abstractmethod, abstractproperty
21 from typing import Any
22 import xml.etree.ElementTree as ET
24 from model.python.geo_location import GeoLocation
25 from model.python.o_ran_object import IORanObject, ORanObject
26 import model.python.hexagon as Hexagon
27 from model.python.hexagon import Hex, Layout
28 from model.python.point import Point
29 from model.python.o_ran_spiral_radius_profile import SpiralRadiusProfile
30 from model.python.o_ran_termination_point import ORanTerminationPoint
31 from model.python.type_definitions import (
36 # Define the "IORanObject" interface
37 class IORanNode(IORanObject):
40 address: AddressType = None,
41 geoLocation: GeoLocation = None,
44 layout: Layout = None,
45 spiralRadiusProfile: SpiralRadiusProfile = None,
49 super().__init__(**kwargs)
50 self.address = address
51 self.geoLocation = geoLocation
53 self.position = position
55 self.spiralRadiusProfile = (spiralRadiusProfile,)
59 # Define an abstract O-RAN Node class
60 class ORanNode(ORanObject, IORanNode):
61 def __init__(self, of: IORanNode = None, **kwargs):
62 super().__init__(of, **kwargs)
63 self.address = of["address"] if of and "address" in of else None
65 of["geoLocation"] if of and "geoLocation" in of else GeoLocation()
67 self.url = of["url"] if of and "url" in of else self.id
68 self.position = of["position"] if of and "position" in of else Hex(0, 0, 0)
71 if of and "layout" in of
72 else Layout(Hexagon.layout_flat, Point(1, 1), Point(0, 0))
74 self.spiralRadiusProfile = (
75 of["spiralRadiusProfile"]
76 if of and "spiralRadiusProfile" in of
77 else SpiralRadiusProfile()
79 self.parent = of["parent"] if of and "parent" in of else None
80 self._termination_points: list[ORanTerminationPoint] = []
83 def address(self) -> str:
87 def address(self, value: str):
91 def geoLocation(self) -> GeoLocation:
92 return self._geographicalLocation
95 def geoLocation(self, value: GeoLocation):
96 self._geographicalLocation = value
103 def url(self, value: str):
107 def position(self) -> Hex:
108 return self._position
111 def position(self, value: Hex):
112 self._position = value
115 def layout(self) -> Layout:
119 def layout(self, value: Layout):
123 def spiralRadiusProfile(self) -> SpiralRadiusProfile:
124 return self._spiralRadiusProfile
126 @spiralRadiusProfile.setter
127 def spiralRadiusProfile(self, value: SpiralRadiusProfile):
128 self._spiralRadiusProfile = value
131 def parent(self) -> Any: # expected are ORanNodes and all inherits for ORanNode
135 def parent(self, value: Any):
139 def termination_points(self) -> list[ORanTerminationPoint]:
140 return self._termination_points
142 def json(self) -> dict[str, dict]:
143 result: dict = super().json()
144 result["address"] = self.address
145 result["geoLocation"] = self.geoLocation
146 result["url"] = self.url
147 result["layout"] = self.layout
148 result["spiralRadiusProfile"] = self.spiralRadiusProfile
149 result["parent"] = self.parent
153 def to_topology_nodes(self) -> list[dict[str, dict]]:
154 tps: list[dict[str, dict]] = []
155 for tp in self.termination_points:
156 if str(type(tp)) == "<class 'model.python.o_ran_termination_point.ORanTerminationPoint'>":
157 tps.append(tp.to_topology())
159 result: list[dict[str, dict]] = []
161 "node-id": self.name,
162 "ietf-network-topology:termination-point": tps,
167 def to_topology_links(self) -> list[dict[str, dict]]:
168 result: list[dict[str, dict]] = []
169 source_tp: str = "-".join([self.name, "phy".upper()])
170 dest_tp: str = "-".join([self.parent.name, "phy".upper()])
171 if self.parent and not "Tower" in source_tp and not "Tower" in dest_tp:
172 link_id: str = "".join(["phy", ":", self.name, "<->", self.parent.name])
175 "source": {"source-node": self.name, "source-tp": source_tp},
176 "destination": {"dest-node": self.parent.name, "dest-tp": dest_tp},
182 def toKml(self) -> ET.Element | None:
186 def toSvg(self) -> ET.Element | None: