1 # Copyright 2022 highstreet technologies GmbH
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 Module containing a class representing a TAPI Node Edge Point
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
27 class TapiNodeEdgePoint(Top):
29 Class representing a TAPI Node Edge Point object
33 __configuration: Dict = {
36 "interface": "unknown-interface",
37 "protocol": "unknown-protocol",
41 __ceps: List[TapiConnectionEdgePoint] = []
44 def __init__(self, configuration: dict):
45 super().__init__(configuration)
46 self.__configuration = configuration
49 "uuid": str(uuid.uuid4()),
51 "value-name": "interface-name",
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"
62 "link-port-direction": "BIDIRECTIONAL",
63 "termination-state": self.termination_state(),
64 "termination-direction": self.termination_direction()
66 for cep in configuration['nodeEdgePoint']['cep']:
68 "node": self.parent(),
69 "node-local-id": self.local_id(),
70 "node-edge-point": self.__data["uuid"],
71 "interface": self.interface()
73 self.__ceps.append(TapiConnectionEdgePoint(cep))
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,
84 "o2-rest-provider": 0*self.FONTSIZE,
85 "a1-rest-provider": 0*self.FONTSIZE,
86 "e2-rest-consumer": 0*self.FONTSIZE,
88 "f1-c-unknown-consumer": 0*self.FONTSIZE,
89 "f1-u-unknown-consumer": 0*self.FONTSIZE,
91 "e1-unknown-provider": +2.5*self.FONTSIZE,
92 "e1-unknown-consumer": -2.5*self.FONTSIZE,
94 "e2-rest-provider": 0*self.FONTSIZE,
95 "f1-c-unknown-provider": 0*self.FONTSIZE,
96 "f1-u-unknown-provider": 0*self.FONTSIZE,
97 "f1-unknown-provider": 0*self.FONTSIZE,
98 "o1-netconf-provider": -4*self.FONTSIZE,
99 "o1-ves-consumer": 0*self.FONTSIZE,
100 "o1-file-provider": +4*self.FONTSIZE,
101 "ofh-netconf-consumer": 0*self.FONTSIZE,
103 "eth-ofh-provider": 0*self.FONTSIZE,
104 "oam-netconf-provider": 0*self.FONTSIZE,
105 "eth-ofh-consumer": 0*self.FONTSIZE,
107 "ofh-netconf-provider": 0*self.FONTSIZE,
108 "uu-unknown-provider": 0*self.FONTSIZE,
110 "uu-unknown-consumer": 0*self.FONTSIZE
115 print(" NEP: CEP name", name, "for x postion calculation not found")
118 def __y_offset_by_cep_name(self, name: str) -> int:
119 mapping: Dict[str, int] = {
120 "o2-rest-consumer": -1.5*self.FONTSIZE,
121 "a1-rest-consumer": -1.5*self.FONTSIZE,
122 "oam-netconf-consumer": -1.5*self.FONTSIZE,
123 "o1-ves-provider": -1.5*self.FONTSIZE,
124 "o1-file-consumer": -1.5*self.FONTSIZE,
126 "o2-rest-provider": +1.5*self.FONTSIZE,
127 "a1-rest-provider": +1.5*self.FONTSIZE,
128 "e2-rest-consumer": -1.5*self.FONTSIZE,
130 "e1-unknown-provider": 0*self.FONTSIZE,
131 "e1-unknown-consumer": 0*self.FONTSIZE,
133 "f1-c-unknown-consumer": -1.5*self.FONTSIZE,
134 "f1-u-unknown-consumer": -1.5*self.FONTSIZE,
136 "e2-rest-provider": +1.5*self.FONTSIZE,
137 "f1-c-unknown-provider": +1.5*self.FONTSIZE,
138 "f1-u-unknown-provider": +1.5*self.FONTSIZE,
139 "f1-unknown-provider": +1.5*self.FONTSIZE,
140 "o1-netconf-provider": +1.5*self.FONTSIZE,
141 "o1-ves-consumer": +1.5*self.FONTSIZE,
142 "o1-file-provider": +1.5*self.FONTSIZE,
143 "ofh-netconf-consumer": -1.5*self.FONTSIZE,
145 "eth-ofh-provider": +1.5*self.FONTSIZE,
146 "oam-netconf-provider": +1.5*self.FONTSIZE,
147 "eth-ofh-consumer": -1.5*self.FONTSIZE,
149 "ofh-netconf-provider": +1.5*self.FONTSIZE,
150 "uu-unknown-provider": -1.5*self.FONTSIZE,
152 "uu-unknown-consumer": +1.5*self.FONTSIZE
157 print(" NEP: CEP name", name, "for y postion calculation not found")
160 def configuration(self) -> dict:
162 Getter for a json object representing the TAPI Node Edge Point intiail
164 :return TAPI Node Edge Point configuration as json object.
166 return self.__configuration
168 def data(self) -> dict:
170 Getter for a json object representing the TAPI Node Edge Point.
171 :return TAPI Node Edge Point as json object.
175 def identifier(self) -> str:
177 Getter returning the TAPI Node Edge Point identifier.
178 :return Object identifier as UUID.
180 return self.__data["uuid"]
182 def json(self) -> dict:
184 Getter for a json object representing the TAPI Node Edge Point.
185 :return TAPI Node Edge Point as json object.
187 result = self.__data.copy()
188 result['tapi-connectivity:cep-list'] = {}
189 result['tapi-connectivity:cep-list']['connection-end-point'] = []
190 for cep in self.connection_edge_points():
191 result['tapi-connectivity:cep-list']['connection-end-point'].append(
195 def local_id(self) -> int:
196 if "local-id" in self.configuration()["nodeEdgePoint"]:
197 return self.configuration()["nodeEdgePoint"]["local-id"]
200 def name(self) -> str:
202 Getter a human readable identifier of the TAPI Node Edge Point.
203 :return TAPI Node Edge Point name as String.
205 result = self.interface().lower()
206 if "local-id" in self.configuration()["nodeEdgePoint"]:
208 [result, str(self.configuration()["nodeEdgePoint"]["local-id"])])
211 def interface(self) -> str:
213 Getter a human readable identifier of the TAPI Node Edge Point interface.
214 :return Interface label.
216 return self.__configuration['nodeEdgePoint']['interface'].lower()
218 def connection_edge_points(self) -> List[TapiConnectionEdgePoint]:
220 Getter a human readable identifier of the TAPI Node Edge Point interface.
221 :return Interface label.
225 def parent(self) -> str:
227 Getter returning the identifier the the TAPI Node hosting the Node
229 :return Identifier of the TAPI Node containing this NEP.
231 return self.__configuration["parent"]
233 def svg_x(self) -> int:
236 def svg_y(self) -> int:
239 def svg(self, x: int, y: int) -> etree.Element:
241 Getter for a xml Element object representing the TAPI Node Edge Point.
242 :return TAPI Node Edge Point as SVG object.
247 svg_nep = NodeEdgePoint(self, x, y)
248 group: etree.Element = svg_nep.svg_element()
250 for cep in self.connection_edge_points():
251 cep_x = x + self.__x_offset_by_cep_name(cep.name())
252 cep_y = y + self.__y_offset_by_cep_name(cep.name())
253 group.append(cep.svg(cep_x, cep_y))
256 def termination_direction(self) -> str:
258 Getter returning the TAPI Node Edge Point direction.
259 :return TAPI Node Edge Point direction as String.
261 value = "BIDIRECTIONAL"
266 if self.__configuration['nodeEdgePoint']['cep'][0]['role'].lower() in mapping:
267 return mapping[self.__configuration['nodeEdgePoint']['cep'][0]['role'].lower()]
270 def termination_state(self) -> str:
272 Getter returning the TAPI Node Edge Point state.
273 :return TAPI Node Edge Point state as String.
275 return "LT_PERMENANTLY_TERMINATED"