Reformat files according to template
[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 abc import abstractmethod
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 IORanTerminationPointData(IORanObject):
30     def __init__(self, supporter: str = None, parent=None, **kwargs):
31         super().__init__(**kwargs)
32         self.supporter = supporter
33         self.parent = parent
34
35
36 # Define an O-RAN Termination Point (ietf-interface, onf:logical-termination-point) class
37 class ORanTerminationPoint(ORanObject, IORanTerminationPointData):
38     def __init__(self, tp: IORanTerminationPointData = None, **kwargs):
39         super().__init__(tp, **kwargs)
40         self.supporter = tp["supporter"] if tp and "supporter" in tp else None
41         self.parent = tp["parent"] if tp and "parent" in tp else None
42
43     def to_topology(self):
44         result: dict[str, dict] = {"tp-id": self.name}
45         if self.supporter:
46             network_ref: str = ""
47             match str(type(self.parent)):
48                 case "<class 'model.python.o_ran_smo.ORanSmo'>":
49                     network_ref = self.parent.parent.id
50                 case "<class 'model.python.o_ran_near_rt_ric.ORanNearRtRic'>":
51                     network_ref = self.parent.parent.parent.id
52                 case "<class 'model.python.o_ran_cu.ORanCu'>":
53                     network_ref = self.parent.parent.parent.parent.id
54                 case "<class 'model.python.o_ran_du.ORanDu'>":
55                     network_ref = self.parent.parent.parent.parent.parent.id
56                 case "<class 'model.python.o_ran_cloud_du.ORanCloudDu'>":
57                     network_ref = self.parent.parent.parent.parent.parent.id
58                 case "<class 'model.python.o_ran_ru.ORanRu'>":
59                     network_ref = (
60                         self.parent.parent.parent.parent.parent.parent.id
61                     )
62                 case _:
63                     print("unknown: implement " + str(type(self.parent)))
64                     network_ref = "unknown: implement " + str(
65                         type(self.parent)
66                     )
67
68             result["supporting-termination-point"] = [
69                 {
70                     "network-ref": network_ref,
71                     "node-ref": self.parent.name,
72                     "tp-ref": self.supporter,
73                 }
74             ]
75         return result