034c49a6513efcf9a76f36d88a7a31496a647f53
[oam.git] / code / network-generator / network_generation / model / python / o_ran_termination_point.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 An abstract Class for O-RAN TerminationPoint
19 """
20 from typing import Any, cast
21
22 from network_generation.model.python.o_ran_object import (
23     IORanObject,
24     ORanObject,
25 )
26
27
28 # Define the "IORanObject" interface
29 class IORanTerminationPoint(IORanObject):
30     supporter: str
31     parent: Any
32
33
34 default_value: IORanTerminationPoint = cast(
35     IORanTerminationPoint,
36     {
37         **ORanObject.default(),
38         **{
39             "supporter": "TerminationPointLayer",
40             "parent": None,
41         },
42     },
43 )
44
45
46 # Define an O-RAN Termination Point
47 # (ietf-interface, onf:logical-termination-point) class
48 class ORanTerminationPoint(ORanObject):
49     @staticmethod
50     def default() -> dict[str, Any]:
51         return cast(dict[str, Any], default_value)
52
53     def __init__(
54         self, data: dict[str, Any] = default(), **kwargs: dict[str, Any]
55     ) -> None:
56         itp: IORanTerminationPoint = self._to_itp_data(data)
57         super().__init__(cast(dict[str, Any], itp), **kwargs)
58         self._supporter: str = str(itp["supporter"])
59         self._parent: Any = itp["parent"]
60
61     def _to_itp_data(self, data: dict[str, Any]) -> IORanTerminationPoint:
62         result: IORanTerminationPoint = default_value
63         for key, key_type in IORanTerminationPoint.__annotations__.items():
64             if key in data:
65                 result[key] = data[key]  # type: ignore
66         return result
67
68     @property
69     def supporter(self) -> str:
70         return self._supporter
71
72     @supporter.setter
73     def supporter(self, value: str) -> None:
74         self._supporter = value
75
76     @property
77     def parent(self) -> Any:
78         return self._utilization
79
80     @parent.setter
81     def parent(self, value: Any) -> None:
82         self._parent = value
83
84     def to_topology(self) -> dict[str, Any]:
85         result: dict[str, Any] = {"tp-id": self.name}
86         # TODO
87         # if self.supporter:
88         #     network_ref: str = ""
89         #     match self.parent.__qualname__:
90         #         case ORanSmo.__qualname__:
91         #             network_ref = self.parent.parent.id
92         # case "<class 'model.python.o_ran_smo.ORanSmo'>":
93         #     network_ref = self.parent.parent.id
94         # case "<class 'model.python.o_ran_near_rt_ric.ORanNearRtRic'>":
95         #     network_ref = self.parent.parent.parent.id
96         # case "<class 'model.python.o_ran_cu.ORanCu'>":
97         #     network_ref = self.parent.parent.parent.parent.id
98         # case "<class 'model.python.o_ran_du.ORanDu'>":
99         #     network_ref = self.parent.parent.parent.parent.parent.id
100         # case "<class 'model.python.o_ran_cloud_du.ORanCloudDu'>":
101         #     network_ref = self.parent.parent.parent.parent.parent.id
102         # case "<class 'model.python.o_ran_ru.ORanRu'>":
103         #     network_ref = (
104         #         self.parent.parent.parent.parent.parent.parent.id
105         #     )
106         #     case _:
107         #         print("unknown: implement " + str(type(self.parent)))
108         #         network_ref = "unknown: implement " + str(
109         #             type(self.parent)
110         #         )
111
112         # result["supporting-termination-point"] = [
113         #     {
114         #         "network-ref": network_ref,
115         #         "node-ref": self.parent.name,
116         #         "tp-ref": self.supporter,
117         #     }
118         # ]
119         return result