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