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
22 from typing import Any, cast
24 from network_generation.model.python.o_ran_node import IORanNode, ORanNode
25 from network_generation.model.python.o_ran_termination_point import (
30 # Define the "IORanDu" interface
31 class IORanDu(IORanNode):
35 default_value: IORanDu = cast(
44 # Define an abstract O-RAN Node class
45 class ORanDu(ORanNode):
48 data: dict[str, Any] = cast(dict[str, Any], default_value),
49 **kwargs: dict[str, Any]
51 o_ran_du_data: IORanDu = self._to_o_ran_du_data(data)
52 super().__init__(cast(dict[str, Any], o_ran_du_data), **kwargs)
53 self._o_ran_ru_count = (
54 o_ran_du_data["oRanRuCount"]
55 if o_ran_du_data and "oRanRuCount" in o_ran_du_data
58 self.type = "ntsim-ng-o-du"
60 def _to_o_ran_du_data(self, data: dict[str, Any]) -> IORanDu:
61 result: IORanDu = default_value
62 for key, key_type in IORanDu.__annotations__.items():
64 result[key] = data[key] # type: ignore
67 def termination_points(self) -> list[ORanTerminationPoint]:
68 result: list[ORanTerminationPoint] = super().termination_points()
69 phy_tp: str = "-".join([self.name, "phy".upper()])
70 result.append(ORanTerminationPoint({"id": phy_tp, "name": phy_tp}))
71 for interface in ["e2", "o1", "ofhm", "ofhc", "ofhu", "ofhs"]:
72 id: str = "-".join([self.name, interface.upper()])
75 {"id": id, "name": id, "supporter": phy_tp, "parent": self}
80 def to_topology_nodes(self) -> list[dict[str, Any]]:
81 result: list[dict[str, Any]] = super().to_topology_nodes()
84 def to_topology_links(self) -> list[dict[str, Any]]:
85 result: list[dict[str, Any]] = super().to_topology_links()
86 for interface in ["e2", "o1"]:
87 link_id: str = "".join(
88 [interface, ":", self.name, "<->", self.parent.name]
90 source_tp: str = "-".join([self.name, interface.upper()])
91 dest_tp: str = "-".join([self.parent.name, interface.upper()])
96 "source-node": self.name,
97 "source-tp": source_tp,
100 "dest-node": self.parent.name,
107 def toKml(self) -> ET.Element:
108 o_ran_du: ET.Element = ET.Element("Folder")
109 open: ET.Element = ET.SubElement(o_ran_du, "open")
111 name: ET.Element = ET.SubElement(o_ran_du, "name")
112 name.text = self.name
113 # for tower in self.towers:
114 # o_ran_du.append(tower.toKml())
117 def toSvg(self) -> ET.Element:
118 return ET.Element("to-be-implemented")
120 def to_directory(self, parent_dir: str) -> None:
121 parent_path = os.path.join(parent_dir, self.type)
122 path = os.path.join(parent_path, self.name)
123 if not os.path.exists(parent_path):
124 os.makedirs(parent_path, exist_ok=True)
125 if not os.path.exists(path):