Correct E2 protocol
[oam.git] / code / network-topology-instance-generator / model / python / tapi_node_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 Node Edge Point
18 """
19 import uuid
20 from typing import Dict, List, Union
21 from lxml import etree
22 from model.python.svg.node_edge_point import NodeEdgePoint
23 from model.python.tapi_connection_edge_point import TapiConnectionEdgePoint
24 from model.python.top import Top
25
26
27 class TapiNodeEdgePoint(Top):
28     """
29     Class representing a TAPI Node Edge Point object
30     """
31
32     __data: Dict = {}
33     __configuration: Dict = {
34         "parent": "unknown",
35         "nodeEdgePoint": {
36             "interface": "unknown-interface",
37             "protocol": "unknown-protocol",
38             "role": "consumer"
39         }
40     }
41     __ceps: List[TapiConnectionEdgePoint] = []
42
43     # constructor
44     def __init__(self, configuration: dict):
45         super().__init__(configuration)
46         self.__configuration = configuration
47         self.__ceps = []
48         self.__data = {
49             "uuid": str(uuid.uuid4()),
50             "name": [{
51                 "value-name": "interface-name",
52                 "value": self.name()
53             }],
54             "administrative-state": "LOCKED",
55             "operational-state": "ENABLED",
56             "lifecycle-state": "INSTALLED",
57             "link-port-role": "SYMMETRIC",
58             "layer-protocol-name": "ETH",
59             "supported-cep-layer-protocol-qualifier": [
60                 "tapi-dsr:DIGITAL_SIGNAL_TYPE_GigE"
61             ],
62             "link-port-direction": "BIDIRECTIONAL",
63             "termination-state": self.termination_state(),
64             "termination-direction": self.termination_direction()
65         }
66         for cep in configuration['nodeEdgePoint']['cep']:
67             cep["parent"] = {
68                 "node": self.parent(),
69                 "node-local-id": self.local_id(),
70                 "node-edge-point": self.__data["uuid"],
71                 "interface": self.interface()
72             }
73             self.__ceps.append(TapiConnectionEdgePoint(cep))
74
75     # getter
76     def __x_offset_by_cep_name(self, name) -> int:
77         mapping: Dict[str, int] = {
78             "o2-rest-consumer": 0*self.FONTSIZE,
79             "a1-rest-consumer": 0*self.FONTSIZE,
80             "oam-netconf-consumer": 0*self.FONTSIZE,
81             "o1-ves-provider": 0*self.FONTSIZE,
82             "o1-file-consumer": 0*self.FONTSIZE,
83
84             "o2-rest-provider": 0*self.FONTSIZE,
85             "a1-rest-provider": 0*self.FONTSIZE,
86             "e2-sctp-consumer": 0*self.FONTSIZE,
87
88             "n1-nas-provider": 0*self.FONTSIZE,
89             "n2-nas-provider": 0*self.FONTSIZE,
90             "n3-nas-provider": 0*self.FONTSIZE,
91
92             "f1-c-unknown-consumer": 0*self.FONTSIZE,
93             "f1-u-unknown-consumer": 0*self.FONTSIZE,
94
95             "e1-unknown-provider": +2.5*self.FONTSIZE,
96             "e1-unknown-consumer": -2.5*self.FONTSIZE,
97
98             "e2-sctp-provider": 0*self.FONTSIZE,
99             "n2-nas-consumer": 0*self.FONTSIZE,
100             "n3-nas-consumer": 0*self.FONTSIZE,
101             "f1-c-unknown-provider": 0*self.FONTSIZE,
102             "f1-u-unknown-provider": 0*self.FONTSIZE,
103             "f1-unknown-provider": 0*self.FONTSIZE,
104             "o1-netconf-provider": -4*self.FONTSIZE,
105             "o1-ves-consumer": 0*self.FONTSIZE,
106             "o1-file-provider": +4*self.FONTSIZE,
107             "ofh-netconf-consumer": 0*self.FONTSIZE,
108
109             "eth-ofh-provider": 0*self.FONTSIZE,
110             "oam-netconf-provider": 0*self.FONTSIZE,
111             "eth-ofh-consumer": 0*self.FONTSIZE,
112
113             "ofh-netconf-provider": 0*self.FONTSIZE,
114             "uu-radio-provider": 0*self.FONTSIZE,
115
116             "uu-radio-consumer": 0*self.FONTSIZE,
117             "n1-nas-consumer": 0*self.FONTSIZE
118         }
119         if name in mapping:
120             return mapping[name]
121
122         print(" NEP: CEP name", name, "for x postion calculation not found")
123         return 0
124
125     def __y_offset_by_cep_name(self, name: str) -> int:
126         mapping: Dict[str, int] = {
127             "o2-rest-consumer": -1.5*self.FONTSIZE,
128             "a1-rest-consumer": -1.5*self.FONTSIZE,
129             "oam-netconf-consumer": -1.5*self.FONTSIZE,
130             "o1-ves-provider": -1.5*self.FONTSIZE,
131             "o1-file-consumer": -1.5*self.FONTSIZE,
132
133             "o2-rest-provider": +1.5*self.FONTSIZE,
134             "a1-rest-provider": +1.5*self.FONTSIZE,
135             "e2-sctp-consumer": -1.5*self.FONTSIZE,
136
137             "n1-nas-provider": -1.5*self.FONTSIZE,
138             "n2-nas-provider": -1.5*self.FONTSIZE,
139             "n3-nas-provider": -1.5*self.FONTSIZE,
140
141             "e1-unknown-provider": 0*self.FONTSIZE,
142             "e1-unknown-consumer": 0*self.FONTSIZE,
143
144             "f1-c-unknown-consumer": -1.5*self.FONTSIZE,
145             "f1-u-unknown-consumer": -1.5*self.FONTSIZE,
146
147             "e2-sctp-provider": +1.5*self.FONTSIZE,
148             "n2-nas-consumer": +1.5*self.FONTSIZE,
149             "n3-nas-consumer": +1.5*self.FONTSIZE,
150             "f1-c-unknown-provider": +1.5*self.FONTSIZE,
151             "f1-u-unknown-provider": +1.5*self.FONTSIZE,
152             "f1-unknown-provider": +1.5*self.FONTSIZE,
153             "o1-netconf-provider": +1.5*self.FONTSIZE,
154             "o1-ves-consumer": +1.5*self.FONTSIZE,
155             "o1-file-provider": +1.5*self.FONTSIZE,
156             "ofh-netconf-consumer": -1.5*self.FONTSIZE,
157
158             "eth-ofh-provider": +1.5*self.FONTSIZE,
159             "oam-netconf-provider": +1.5*self.FONTSIZE,
160             "eth-ofh-consumer": -1.5*self.FONTSIZE,
161
162             "ofh-netconf-provider": +1.5*self.FONTSIZE,
163             "uu-radio-provider": -1.5*self.FONTSIZE,
164
165             "uu-radio-consumer": +1.5*self.FONTSIZE,
166             "n1-nas-consumer": +1.5*self.FONTSIZE
167         }
168         if name in mapping:
169             return mapping[name]
170
171         print(" NEP: CEP name", name, "for y postion calculation not found")
172         return 0
173
174     def configuration(self) -> dict:
175         """
176         Getter for a json object representing the TAPI Node Edge Point intiail
177         configuration.
178         :return TAPI Node Edge Point configuration as json object.
179         """
180         return self.__configuration
181
182     def data(self) -> dict:
183         """
184         Getter for a json object representing the TAPI Node Edge Point.
185         :return TAPI Node Edge Point as json object.
186         """
187         return self.__data
188
189     def identifier(self) -> str:
190         """
191         Getter returning the TAPI Node Edge Point identifier.
192         :return Object identifier as UUID.
193         """
194         return self.__data["uuid"]
195
196     def json(self) -> dict:
197         """
198         Getter for a json object representing the TAPI Node Edge Point.
199         :return TAPI Node Edge Point as json object.
200         """
201         result = self.__data.copy()
202         result['tapi-connectivity:cep-list'] = {}
203         result['tapi-connectivity:cep-list']['connection-end-point'] = []
204         for cep in self.connection_edge_points():
205             result['tapi-connectivity:cep-list']['connection-end-point'].append(
206                 cep.json())
207         return result
208
209     def local_id(self) -> int:
210         if "local-id" in self.configuration()["nodeEdgePoint"]:
211             return self.configuration()["nodeEdgePoint"]["local-id"]
212         return 0
213
214     def name(self) -> str:
215         """
216         Getter a human readable identifier of the TAPI Node Edge Point.
217         :return TAPI Node Edge Point name as String.
218         """
219         result = self.interface().lower()
220         if "local-id" in self.configuration()["nodeEdgePoint"]:
221             result = "#".join(
222                 [result, str(self.configuration()["nodeEdgePoint"]["local-id"])])
223         return result
224
225     def interface(self) -> str:
226         """
227         Getter a human readable identifier of the TAPI Node Edge Point interface.
228         :return Interface label.
229         """
230         return self.__configuration['nodeEdgePoint']['interface'].lower()
231
232     def connection_edge_points(self) -> List[TapiConnectionEdgePoint]:
233         """
234         Getter a human readable identifier of the TAPI Node Edge Point interface.
235         :return Interface label.
236         """
237         return self.__ceps
238
239     def parent(self) -> str:
240         """
241         Getter returning the identifier the the TAPI Node hosting the Node
242         Edge Point.
243         :return Identifier of the TAPI Node containing this NEP.
244         """
245         return self.__configuration["parent"]
246
247     def svg_x(self) -> int:
248         return self.__svg_x
249
250     def svg_y(self) -> int:
251         return self.__svg_y
252
253     def svg(self, x: int, y: int) -> etree.Element:
254         """
255         Getter for a xml Element object representing the TAPI Node Edge Point.
256         :return TAPI Node Edge Point as SVG object.
257         """
258         self.__svg_x = x
259         self.__svg_y = y
260
261         svg_nep = NodeEdgePoint(self, x, y)
262         group: etree.Element = svg_nep.svg_element()
263
264         for cep in self.connection_edge_points():
265             cep_x = x + self.__x_offset_by_cep_name(cep.name())
266             cep_y = y + self.__y_offset_by_cep_name(cep.name())
267             group.append(cep.svg(cep_x, cep_y))
268         return group
269
270     def termination_direction(self) -> str:
271         """
272         Getter returning the TAPI Node Edge Point direction.
273         :return TAPI Node Edge Point direction as String.
274         """
275         value = "BIDIRECTIONAL"
276         mapping = {
277             "consumer": "SINK",
278             "provider": "SOURCE"
279         }
280         if self.__configuration['nodeEdgePoint']['cep'][0]['role'].lower() in mapping:
281             return mapping[self.__configuration['nodeEdgePoint']['cep'][0]['role'].lower()]
282         return value
283
284     def termination_state(self) -> str:
285         """
286         Getter returning the TAPI Node Edge Point state.
287         :return TAPI Node Edge Point state as String.
288         """
289         return "LT_PERMENANTLY_TERMINATED"