0392d2cf002d48f9f3248b8b42e2489ef3bdd897
[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 Any, cast
22
23 from network_generation.model.python.o_ran_node import IORanNode, ORanNode
24 from network_generation.model.python.o_ran_termination_point import (
25     ORanTerminationPoint,
26 )
27
28
29 # Define the "IORanDu" interface
30 class IORanDu(IORanNode):
31     o_ran_ru_count: int
32
33
34 default_value: IORanDu = cast(
35     IORanDu,
36     {
37         **ORanNode.default(),
38         **{"oRanRuCount": 1},
39     },
40 )
41
42
43 # Define an abstract O-RAN Node class
44 class ORanDu(ORanNode):
45     def __init__(
46         self,
47         data: dict[str, Any] = cast(dict[str, Any], default_value),
48         **kwargs: dict[str, Any]
49     ) -> None:
50         o_ran_du_data: IORanDu = self._to_o_ran_du_data(data)
51         super().__init__(cast(dict[str, Any], o_ran_du_data), **kwargs)
52         self._o_ran_ru_count = (
53             o_ran_du_data["oRanRuCount"]
54             if o_ran_du_data and "oRanRuCount" in o_ran_du_data
55             else 1
56         )
57
58     def _to_o_ran_du_data(self, data: dict[str, Any]) -> IORanDu:
59         result: IORanDu = default_value
60         for key, key_type in IORanDu.__annotations__.items():
61             if key in data:
62                 result[key] = data[key]  # type: ignore
63         return result
64
65     def termination_points(self) -> list[ORanTerminationPoint]:
66         result: list[ORanTerminationPoint] = super().termination_points()
67         phy_tp: str = "-".join([self.name, "phy".upper()])
68         result.append(ORanTerminationPoint({"id": phy_tp, "name": phy_tp}))
69         for interface in ["e2", "o1", "ofhm", "ofhc", "ofhu", "ofhs"]:
70             id: str = "-".join([self.name, interface.upper()])
71             result.append(
72                 ORanTerminationPoint(
73                     {"id": id, "name": id, "supporter": phy_tp, "parent": self}
74                 )
75             )
76         return result
77
78     def to_topology_nodes(self) -> list[dict[str, Any]]:
79         result: list[dict[str, Any]] = super().to_topology_nodes()
80         return result
81
82     def to_topology_links(self) -> list[dict[str, Any]]:
83         result: list[dict[str, Any]] = super().to_topology_links()
84         for interface in ["e2", "o1"]:
85             link_id: str = "".join(
86                 [interface, ":", self.name, "<->", self.parent.name]
87             )
88             source_tp: str = "-".join([self.name, interface.upper()])
89             dest_tp: str = "-".join([self.parent.name, interface.upper()])
90             result.append(
91                 {
92                     "link-id": link_id,
93                     "source": {
94                         "source-node": self.name,
95                         "source-tp": source_tp,
96                     },
97                     "destination": {
98                         "dest-node": self.parent.name,
99                         "dest-tp": dest_tp,
100                     },
101                 }
102             )
103         return result
104
105     def toKml(self) -> ET.Element:
106         o_ran_du: ET.Element = ET.Element("Folder")
107         open: ET.Element = ET.SubElement(o_ran_du, "open")
108         open.text = "1"
109         name: ET.Element = ET.SubElement(o_ran_du, "name")
110         name.text = self.name
111         # for tower in self.towers:
112         #     o_ran_du.append(tower.toKml())
113         return o_ran_du
114
115     def toSvg(self) -> ET.Element:
116         return ET.Element("to-be-implemented")