7f1e5c62ee2d0417c2fac4b41cbf5f15b2a91e0d
[oam.git] / code / network-generator / model / python / o_ran_du.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 A Class representing an O-RAN distributed unit (ORanDu)
19 """
20 from typing import overload
21 from model.python.o_ran_object import IORanObject
22 from model.python.o_ran_node import ORanNode
23 from model.python.o_ran_termination_point import ORanTerminationPoint
24 import xml.etree.ElementTree as ET
25
26
27 # Define the "IORanDu" interface
28 class IORanDu(IORanObject):
29     def __init__(self, o_ran_ru_count: int, **kwargs):
30         super().__init__(**kwargs)
31         self._o_ran_ru_count = o_ran_ru_count
32
33
34 # Define an abstract O-RAN Node class
35 class ORanDu(ORanNode, IORanDu):
36     def __init__(self, o_ran_du_data: IORanDu = None, **kwargs):
37         super().__init__(o_ran_du_data, **kwargs)
38         self._o_ran_ru_count = (
39             o_ran_du_data["oRanRuCount"] if o_ran_du_data and "oRanRuCount" in o_ran_du_data else 1
40         )
41
42     @property
43     def termination_points(self) -> list[ORanTerminationPoint]:
44         result: list[ORanTerminationPoint] = super().termination_points
45         phy_tp: str = "-".join([self.name, "phy".upper()])
46         result.append(ORanTerminationPoint({"id": phy_tp, "name": phy_tp}))
47         for interface in ["e2", "o1", "ofhm", "ofhc", "ofhu","ofhs"]:
48             id:str = "-".join([self.name, interface.upper()])
49             result.append(ORanTerminationPoint({"id": id, "name":id, "supporter": phy_tp, "parent":self}))
50         return result
51
52     def to_topology_nodes(self) -> list[dict[str, dict]]:
53         result: list[dict[str, dict]] = super().to_topology_nodes()
54         return result
55
56     def to_topology_links(self) -> list[dict[str, dict]]:
57         result: list[dict[str, dict]] = super().to_topology_links()
58         for interface in ["e2", "o1"]:
59             link_id: str = "".join([interface, ":", self.name, "<->", self.parent.name])
60             source_tp: str = "-".join([self.name, interface.upper()])
61             dest_tp: str = "-".join([self.parent.name, interface.upper()])
62             result.append(
63                 {
64                     "link-id": link_id,
65                     "source": {"source-node": self.name, "source-tp": source_tp},
66                     "destination": {"dest-node": self.parent.name, "dest-tp": dest_tp},
67                 }
68             )
69         return result
70     
71     def toKml(self) -> ET.Element:
72         o_ran_du: ET.Element = ET.Element("Folder")
73         open: ET.Element = ET.SubElement(o_ran_du, "open")
74         open.text = "1"
75         name: ET.Element = ET.SubElement(o_ran_du, "name")
76         name.text = self.name
77         for tower in self.towers:
78             o_ran_du.append(tower.toKml())
79         return o_ran_du
80
81     def toSvg(self) -> None:
82         return None