Add to_directory method to relevant object classes
[oam.git] / code / network-topology-instance-generator / model / python / tapi_connection_edge_point.py
1 # Copyright 2022 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 Module containing a class representing a TAPI Connection Node Edge Point
18 """
19 import uuid
20 from typing import Dict, Union
21 from lxml import etree
22 from model.python.svg.connection_edge_point import ConnectionEdgePoint
23 from model.python.svg.svg import Svg
24 from model.python.top import Top
25
26
27 class TapiConnectionEdgePoint(Top):
28     """
29     Class representing a TAPI Connection Node Edge Point object
30     """
31
32     __data: Dict = {}
33     __configuration = {
34         "protocol": "unknown",
35         "role": "consumer",
36         "parent": {
37             "node": "unknown",
38             "node-edge-point": "unknown",
39             "interface": "unknown"
40         }
41     }
42
43     # constructor
44     def __init__(self, configuration: Dict[str, str]):
45         super().__init__(configuration)
46         self.__configuration = configuration
47         self.__data = {
48             "uuid": str(uuid.uuid4()),
49             "name": [{
50                 "value-name": "connection-edge-point-name",
51                 "value": self.name()
52             }],
53             "operational-state": "ENABLED",
54             "lifecycle-state": "INSTALLED",
55             "termination-state": self.termination_state(),
56             "termination-direction": self.termination_direction(),
57             "layer-protocol-name": "ETH",
58             "layer-protocol-qualifier": self.protocol(),
59
60             "connection-port-role": "SYMMETRIC",
61             "connection-port-direction": "BIDIRECTIONAL",
62
63             "parent-node-edge-point": {
64                 #  TODO              "topology-uuid": "?",
65                 "node-uuid": self.parent()["node"],
66                 "node-edge-point-uuid": self.parent()["node-edge-point"]
67             }
68         }
69
70     # getter
71     def configuration(self) -> dict:
72         """
73         Getter for a json object representing the TAPI Node Edge Point intiail
74         configuration.
75         :return TAPI Node Edge Point configuration as json object.
76         """
77         return self.__configuration
78
79     def data(self) -> dict:
80         """
81         Getter for a json object representing the TAPI Node Edge Point.
82         :return TAPI Node Edge Point as json object.
83         """
84         return self.__data
85
86     def identifier(self) -> str:
87         """
88         Getter returning the TAPI Node Edge Point identifier.
89         :return Object identifier as UUID.
90         """
91         return self.__data["uuid"]
92
93     def json(self) -> dict:
94         """
95         Getter for a json object representing the TAPI Node Edge Point.
96         :return TAPI Node Edge Point as json object.
97         """
98         return self.data()
99
100     def name(self) -> str:
101         """
102         Getter a human readable identifier of the TAPI Node Edge Point.
103         :return TAPI Node Edge Point name as String.
104         """
105         items = (self.parent()["interface"],
106                  self.protocol().split(":")[1],
107                  self.role())
108         return "-".join(items).lower()
109
110     def protocol(self) -> str:
111         """
112         Getter a human readable identifier of the TAPI Connection Edge Point protocol.
113         :return protocol label.
114         """
115         protocol = self.__configuration['protocol'].lower()
116         if protocol == "otf":
117             protocol = "fronthaul-gateway"
118         return ":".join(["o-ran-sc-topology-common", self.__configuration['protocol'].lower()])
119
120     def role(self) -> str:
121         """
122         Getter a human readable identifier of the TAPI Node Edge Point role.
123         :return role label.
124         """
125         return self.__configuration['role'].lower()
126
127     def parent(self) -> Dict:
128         """
129         Getter returning the identifier the the TAPI Node hosting the Node
130         Edge Point.
131         :return Identifier of the TAPI Node containing this NEP.
132         """
133         return self.__configuration["parent"]
134
135     def svg(self, x: int, y: int) -> etree.Element:
136         """
137         Getter for a xml Element object representing the TAPI Node Edge Point.
138         :return TAPI Node Edge Point as SVG object.
139         """
140         return ConnectionEdgePoint(self, x, y).svg_element()
141
142     def termination_direction(self) -> str:
143         """
144         Getter returning the TAPI Node Edge Point direction.
145         :return TAPI Node Edge Point direction as String.
146         """
147         mapping = {
148             "consumer": "SINK",
149             "provider": "SOURCE"
150         }
151         if self.__configuration['role'].lower() in mapping:
152             return mapping[self.__configuration['role'].lower()]
153         return "BIDIRECTIONAL"
154
155     def termination_state(self) -> str:
156         """
157         Getter returning the TAPI Node Edge Point state.
158         :return TAPI Node Edge Point state as String.
159         """
160         return "LT_PERMENANTLY_TERMINATED"