1 # Copyright 2023 highstreet technologies GmbH
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 A Class representing an O-RAN distributed unit (ORanDu)
20 import xml.etree.ElementTree as ET
21 from typing import Any, cast
23 from network_generation.model.python.o_ran_node import IORanNode, ORanNode
24 from network_generation.model.python.o_ran_termination_point import (
29 # Define the "IORanDu" interface
30 class IORanDu(IORanNode):
34 default_value: IORanDu = cast(
43 # Define an abstract O-RAN Node class
44 class ORanDu(ORanNode):
47 data: dict[str, Any] = cast(dict[str, Any], default_value),
48 **kwargs: dict[str, Any]
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
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():
62 result[key] = data[key] # type: ignore
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()])
73 {"id": id, "name": id, "supporter": phy_tp, "parent": self}
78 def to_topology_nodes(self) -> list[dict[str, Any]]:
79 result: list[dict[str, Any]] = super().to_topology_nodes()
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]
88 source_tp: str = "-".join([self.name, interface.upper()])
89 dest_tp: str = "-".join([self.parent.name, interface.upper()])
94 "source-node": self.name,
95 "source-tp": source_tp,
98 "dest-node": self.parent.name,
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")
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())
115 def toSvg(self) -> ET.Element:
116 return ET.Element("to-be-implemented")