python 3.10 type definitions
[oam.git] / code / network-generator / model / python / o_ran_node.py
1 # Copyright 2023 highstreet technologies GmbH
2 #
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
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 #!/usr/bin/python
16
17 """
18 An abstract Class for O-RAN Node
19 """
20 from abc import abstractmethod
21 from typing import Any
22 import xml.etree.ElementTree as ET
23 from model.python.geo_location import GeoLocation
24 from model.python.o_ran_object import IORanObject, ORanObject
25 import model.python.hexagon as Hexagon
26 from model.python.hexagon import Hex, Layout
27 from model.python.point import Point
28 from model.python.o_ran_spiral_radius_profile import SpiralRadiusProfile
29 from model.python.o_ran_termination_point import ORanTerminationPoint
30 from model.python.type_definitions import (
31     AddressType,
32 )
33
34
35 # Define the "IORanObject" interface
36 class IORanNode(IORanObject):
37     def __init__(
38         self,
39         address: AddressType = None,
40         geoLocation: GeoLocation = None,
41         url: str = None,
42         position: Hex = None,
43         layout: Layout = None,
44         spiralRadiusProfile: SpiralRadiusProfile = None,
45         parent=None,
46         **kwargs
47     ):
48         super().__init__(**kwargs)
49         self.address = address
50         self.geoLocation = geoLocation
51         self.url = url
52         self.position = position
53         self.layout = layout
54         self.spiralRadiusProfile = (spiralRadiusProfile,)
55         self.parent = parent
56
57
58 # Define an abstract O-RAN Node class
59 class ORanNode(ORanObject, IORanNode):
60     def __init__(self, of: IORanNode = None, **kwargs):
61         super().__init__(of, **kwargs)
62         self.address = of["address"] if of and "address" in of else None
63         self.geoLocation = (
64             of["geoLocation"] if of and "geoLocation" in of else GeoLocation()
65         )
66         self.url = of["url"] if of and "url" in of else self.id
67         self.position = of["position"] if of and "position" in of else Hex(0, 0, 0)
68         self.layout = (
69             of["layout"]
70             if of and "layout" in of
71             else Layout(Hexagon.layout_flat, Point(1, 1), Point(0, 0))
72         )
73         self.spiralRadiusProfile = (
74             of["spiralRadiusProfile"]
75             if of and "spiralRadiusProfile" in of
76             else SpiralRadiusProfile()
77         )
78         self.parent = of["parent"] if of and "parent" in of else None
79         self._terminationPoints = []
80
81     @property
82     def address(self) -> str:
83         return self._address
84
85     @address.setter
86     def address(self, value: str):
87         self._address = value
88
89     @property
90     def geoLocation(self) -> GeoLocation:
91         return self._geographicalLocation
92
93     @geoLocation.setter
94     def geoLocation(self, value: GeoLocation):
95         self._geographicalLocation = value
96
97     @property
98     def url(self) -> str:
99         return self._url
100
101     @url.setter
102     def url(self, value: str):
103         self._url = value
104
105     @property
106     def position(self) -> Hex:
107         return self._position
108
109     @position.setter
110     def position(self, value: Hex):
111         self._position = value
112
113     @property
114     def layout(self) -> Layout:
115         return self._layout
116
117     @layout.setter
118     def layout(self, value: Layout):
119         self._layout = value
120
121     @property
122     def spiralRadiusProfile(self) -> SpiralRadiusProfile:
123         return self._spiralRadiusProfile
124
125     @spiralRadiusProfile.setter
126     def spiralRadiusProfile(self, value: SpiralRadiusProfile):
127         self._spiralRadiusProfile = value
128
129     @property
130     def parent(self) -> Any:  # expected are ORanNodes and all inherits for ORanNode
131         return self._parent
132
133     @parent.setter
134     def parent(self, value: Any):
135         self._parent = value
136
137     @property
138     def terminationPoints(self) -> list[ORanTerminationPoint]:
139         return self._terminationPoints
140
141     def json(self) -> dict[str, Any]:
142         result: dict = super().json()
143         result["address"] = self.address
144         result["geoLocation"] = self.geoLocation
145         result["url"] = self.url
146         result["layout"] = self.layout
147         result["spiralRadiusProfile"] = self.spiralRadiusProfile
148         result["parent"] = self.parent
149         return result
150
151     def toTopology(self) -> dict[str, Any]:
152         result: dict[str, Any] = {
153             "node-id": self.name,
154             "ietf-network-topology:termination-point": self.terminationPoints,
155         }
156         return result
157
158     @abstractmethod
159     def toKml(self) -> ET.Element | None:
160         pass
161
162     @abstractmethod
163     def toSvg(self) -> ET.Element | None:
164         pass