fc112da759d8c732a5ffaebf305bbee9ba2041ce
[oam.git] / code / network-generator / model / python / o_ran_object.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 Objects
19 """
20 from abc import ABC, abstractmethod
21 from typing import Dict
22
23 import model.python.hexagon as Hexagon
24 from model.python.hexagon import Hex, Layout, Point
25 from model.python.o_ran_spiral_radius_profile import SpiralRadiusProfile
26 from model.python.top import ITop, Top
27 from model.python.type_definitions import (
28     AddressType,
29 )
30 from model.python.geo_location import GeoLocation
31
32
33 # Define the "IORanObject" interface
34 class IORanObject(ITop):
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
56 # Define an abstract O-RAN Object class
57 class ORanObject(Top, IORanObject):
58     def __init__(self, of: IORanObject = None, **kwargs):
59         super().__init__(**kwargs)
60         self.address = of["address"] if of and "address" in of else None
61         self.geoLocation = (
62             of["geoLocation"] if of and "geoLocation" in of else GeoLocation()
63         )
64         self.url = of["url"] if of and "url" in of else self.id
65         self.position = of["position"] if of and "position" in of else Hex(0,0,0)
66         self.layout = of["layout"] if of and "layout" in of else Layout(Hexagon.layout_flat, Point(1,1), Point(0,0))
67         self.spiralRadiusProfile = of["spiralRadiusProfile"] if of and "spiralRadiusProfile" in of else SpiralRadiusProfile()
68         self.parent = of["parent"] if of and "parent" in of else None
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     def json(self):
127         result :Dict = super().json()
128         result['address'] = self.address
129         result['geoLocation'] = self.geoLocation
130         result['url'] = self.url
131         result['layout'] = self.layout
132         result['spiralRadiusProfile'] = self.spiralRadiusProfile
133         result['parent'] = self.parent
134         return result
135
136     def __str__(self):
137         return str(self.json())
138     
139     @abstractmethod
140     def toTopology(self):
141         pass
142
143     @abstractmethod
144     def toKml(self):
145         pass
146
147     @abstractmethod
148     def toSvg(self):
149         pass