Create concrete classes for O-RAN Nodes
[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, Dict
22
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, Point
27 from model.python.o_ran_spiral_radius_profile import SpiralRadiusProfile
28 from model.python.type_definitions import (
29     AddressType,
30 )
31
32
33 # Define the "IORanObject" interface
34 class IORanNode(IORanObject):
35     def __init__(
36         self,
37         address: AddressType = None,
38         geoLocation: GeoLocation = None,
39         url: str = None,
40         position: Hex = None,
41         layout: Layout = None,
42         spiralRadiusProfile: SpiralRadiusProfile = None,
43         parent  = None,
44         **kwargs
45     ):
46         super().__init__(**kwargs)
47         self.address = address
48         self.geoLocation = geoLocation
49         self.url = url
50         self.position = position
51         self.layout = layout
52         self.spiralRadiusProfile  = spiralRadiusProfile,
53         self.parent  = parent
54
55 # Define an abstract O-RAN Node class
56 class ORanNode(ORanObject, IORanNode):
57     def __init__(self, of: IORanNode = None, **kwargs):
58         super().__init__(of, **kwargs)
59         self.address = of["address"] if of and "address" in of else None
60         self.geoLocation = (
61             of["geoLocation"] if of and "geoLocation" in of else GeoLocation()
62         )
63         self.url = of["url"] if of and "url" in of else self.id
64         self.position = of["position"] if of and "position" in of else Hex(0,0,0)
65         self.layout = of["layout"] if of and "layout" in of else Layout(Hexagon.layout_flat, Point(1,1), Point(0,0))
66         self.spiralRadiusProfile = of["spiralRadiusProfile"] if of and "spiralRadiusProfile" in of else SpiralRadiusProfile()
67         self.parent = of["parent"] if of and "parent" in of else None
68         self._terminationPoints = []
69
70     @property
71     def address(self):
72         return self._address
73
74     @address.setter
75     def address(self, value):
76         self._address = value
77
78     @property
79     def geoLocation(self):
80         return self._geographicalLocation
81
82     @geoLocation.setter
83     def geoLocation(self, value):
84         self._geographicalLocation = value
85
86     @property
87     def url(self):
88         return self._url
89
90     @url.setter
91     def url(self, value):
92         self._url = value
93
94     @property
95     def position(self):
96         return self._position
97
98     @position.setter
99     def position(self, value):
100         self._position = value
101
102     @property
103     def layout(self):
104         return self._layout
105
106     @layout.setter
107     def layout(self, value):
108         self._layout = value
109
110     @property
111     def spiralRadiusProfile(self):
112         return self._spiralRadiusProfile
113
114     @spiralRadiusProfile.setter
115     def spiralRadiusProfile(self, value):
116         self._spiralRadiusProfile = value
117
118     @property
119     def parent(self):
120         return self._parent
121
122     @parent.setter
123     def parent(self, value):
124         self._parent = value
125
126     @property
127     def terminationPoints(self):
128         return self._terminationPoints
129
130     def json(self):
131         result: Dict = super().json()
132         result["address"] = self.address
133         result["geoLocation"] = self.geoLocation
134         result["url"] = self.url
135         result["layout"] = self.layout
136         result["spiralRadiusProfile"] = self.spiralRadiusProfile
137         result["parent"] = self.parent
138         return result
139
140     def toTopology(self):
141         result:Dict[str, Any] = {
142             "node-id": self.name,
143             "ietf-network-topology:termination-point": self.terminationPoints
144         }
145         return result
146
147     @abstractmethod
148     def toKml(self):
149         pass
150
151     @abstractmethod
152     def toSvg(self):
153         pass