Use python file name conventions
[oam.git] / code / network-generator / model / python / o_ran_network.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 Module for a class representing a O-RAN Network
18 """
19 from typing import Any, Dict, List
20 from model.python.tower import Tower
21 from model.python.o_ran_object import IORanObject, ORanObject
22 import xml.etree.ElementTree as ET
23
24
25 class ORanNetwork(ORanObject):
26     """
27     Class representing an O-RAN Network object.
28     """
29
30     # constructor
31     def __init__(self, configuration: Dict[str, Any], of: IORanObject = None, **kwargs):
32         super().__init__(of, **kwargs)
33         self.__configuration = configuration
34         self.__towers: List[Tower] = []
35
36         center = configuration["center"]
37         self.__towers.append(Tower(center))
38
39     # getter
40     def configuration(self) -> Dict[str, Dict]:
41         """
42         Getter for a json object representing the O-RAN Network.
43         :return O-RAN Network as json object.
44         """
45         return self.__configuration
46
47     def __appendNodes(self):
48         result: List[Dict[str, Any]] = []
49         for tower in self.__towers:
50             result.append(tower.toTopology())
51         return result
52
53     def toTopology(self):
54         return {
55             "ietf-network:networks": {
56                 "network": [
57                     {
58                         "network-id": self.id,
59                         "node": self.__appendNodes(),
60                         "ietf-network-topology:link": [],
61                     }
62                 ],
63             }
64         }
65
66     def toKml(self):
67         root: Element = ET.Element("kml", xmlns="http://www.opengis.net/kml/2.2")
68         document = ET.SubElement(root, "Document")
69         open = ET.SubElement(document, "open")
70         open.text = "1"
71         return root
72
73     def toSvg(self):
74         """
75         Getter for a xml/svg Element object representing the Network.
76         :return Network as SVG object.
77         """
78         root: Element = ET.Element(
79             "svg",
80             # width=str(self.__svg_width()),
81             # height=str(self.__svg_height()),
82             # viewBox=" ".join([
83             #     str(-3*self.FONTSIZE),
84             #     str(-3*self.FONTSIZE),
85             #     str(self.__svg_width()),
86             #     str(self.__svg_height())]
87             # ),
88             xmlns="http://www.w3.org/2000/svg",
89         )
90         desc = ET.Element("desc")
91         # desc.text="\n context: " + str(self.id()) + "\n name: " + str(self.name())
92         root.append(desc)
93
94         title = ET.Element("title")
95         title.text = self.configuration()["name"]
96         root.append(title)
97
98         # root.append(self.__context.svg(x, y))
99         return root