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