Decide about "list-case" or "camelCase" in schema.
[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         if self.supporter and type(self.parent) is not int:
87             network_ref: str = ""
88             match str(type(self.parent)):
89                 case "<class 'model.python.o_ran_smo.ORanSmo'>":
90                     network_ref = self.parent.parent.id
91                 case "<class 'model.python.o_ran_near_rt_ric.ORanNearRtRic'>":
92                     network_ref = self.parent.parent.parent.id
93                 case "<class 'model.python.o_ran_cu.ORanCu'>":
94                     network_ref = self.parent.parent.parent.parent.id
95                 case "<class 'model.python.o_ran_du.ORanDu'>":
96                     network_ref = self.parent.parent.parent.parent.parent.id
97                 case "<class 'model.python.o_ran_cloud_du.ORanCloudDu'>":
98                     network_ref = self.parent.parent.parent.parent.parent.id
99                 case "<class 'model.python.o_ran_ru.ORanRu'>":
100                     network_ref = (
101                         self.parent.parent.parent.parent.parent.parent.id
102                     )
103                 case _:
104                     print("unknown: implement " + str(type(self.parent)))
105                     network_ref = "unknown: implement " + str(
106                         type(self.parent))
107
108             result["supporting-termination-point"] = [
109                 {
110                     "network-ref": network_ref,
111                     "node-ref": self.parent.name,
112                     "tp-ref": self.supporter,
113                 }
114             ]
115         return result