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 "n1-nas-provider": 0*self.FONTSIZE,
89 "n2-nas-provider": 0*self.FONTSIZE,
90 "n3-nas-provider": 0*self.FONTSIZE,
92 "f1-c-unknown-consumer": 0*self.FONTSIZE,
93 "f1-u-unknown-consumer": 0*self.FONTSIZE,
95 "e1-unknown-provider": +2.5*self.FONTSIZE,
96 "e1-unknown-consumer": -2.5*self.FONTSIZE,
98 "e2-rest-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,
109 "eth-ofh-provider": 0*self.FONTSIZE,
110 "oam-netconf-provider": 0*self.FONTSIZE,
111 "eth-ofh-consumer": 0*self.FONTSIZE,
113 "ofh-netconf-provider": 0*self.FONTSIZE,
114 "uu-radio-provider": 0*self.FONTSIZE,
116 "uu-radio-consumer": 0*self.FONTSIZE,
117 "n1-nas-consumer": 0*self.FONTSIZE
122 print(" NEP: CEP name", name, "for x postion calculation not found")
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,
133 "o2-rest-provider": +1.5*self.FONTSIZE,
134 "a1-rest-provider": +1.5*self.FONTSIZE,
135 "e2-rest-consumer": -1.5*self.FONTSIZE,
137 "n1-nas-provider": -1.5*self.FONTSIZE,
138 "n2-nas-provider": -1.5*self.FONTSIZE,
139 "n3-nas-provider": -1.5*self.FONTSIZE,
141 "e1-unknown-provider": 0*self.FONTSIZE,
142 "e1-unknown-consumer": 0*self.FONTSIZE,
144 "f1-c-unknown-consumer": -1.5*self.FONTSIZE,
145 "f1-u-unknown-consumer": -1.5*self.FONTSIZE,
147 "e2-rest-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,
158 "eth-ofh-provider": +1.5*self.FONTSIZE,
159 "oam-netconf-provider": +1.5*self.FONTSIZE,
160 "eth-ofh-consumer": -1.5*self.FONTSIZE,
162 "ofh-netconf-provider": +1.5*self.FONTSIZE,
163 "uu-radio-provider": -1.5*self.FONTSIZE,
165 "uu-radio-consumer": +1.5*self.FONTSIZE,
166 "n1-nas-consumer": +1.5*self.FONTSIZE
171 print(" NEP: CEP name", name, "for y postion calculation not found")
174 def configuration(self) -> dict:
176 Getter for a json object representing the TAPI Node Edge Point intiail
178 :return TAPI Node Edge Point configuration as json object.
180 return self.__configuration
182 def data(self) -> dict:
184 Getter for a json object representing the TAPI Node Edge Point.
185 :return TAPI Node Edge Point as json object.
189 def identifier(self) -> str:
191 Getter returning the TAPI Node Edge Point identifier.
192 :return Object identifier as UUID.
194 return self.__data["uuid"]
196 def json(self) -> dict:
198 Getter for a json object representing the TAPI Node Edge Point.
199 :return TAPI Node Edge Point as json object.
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(
209 def local_id(self) -> int:
210 if "local-id" in self.configuration()["nodeEdgePoint"]:
211 return self.configuration()["nodeEdgePoint"]["local-id"]
214 def name(self) -> str:
216 Getter a human readable identifier of the TAPI Node Edge Point.
217 :return TAPI Node Edge Point name as String.
219 result = self.interface().lower()
220 if "local-id" in self.configuration()["nodeEdgePoint"]:
222 [result, str(self.configuration()["nodeEdgePoint"]["local-id"])])
225 def interface(self) -> str:
227 Getter a human readable identifier of the TAPI Node Edge Point interface.
228 :return Interface label.
230 return self.__configuration['nodeEdgePoint']['interface'].lower()
232 def connection_edge_points(self) -> List[TapiConnectionEdgePoint]:
234 Getter a human readable identifier of the TAPI Node Edge Point interface.
235 :return Interface label.
239 def parent(self) -> str:
241 Getter returning the identifier the the TAPI Node hosting the Node
243 :return Identifier of the TAPI Node containing this NEP.
245 return self.__configuration["parent"]
247 def svg_x(self) -> int:
250 def svg_y(self) -> int:
253 def svg(self, x: int, y: int) -> etree.Element:
255 Getter for a xml Element object representing the TAPI Node Edge Point.
256 :return TAPI Node Edge Point as SVG object.
261 svg_nep = NodeEdgePoint(self, x, y)
262 group: etree.Element = svg_nep.svg_element()
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))
270 def termination_direction(self) -> str:
272 Getter returning the TAPI Node Edge Point direction.
273 :return TAPI Node Edge Point direction as String.
275 value = "BIDIRECTIONAL"
280 if self.__configuration['nodeEdgePoint']['cep'][0]['role'].lower() in mapping:
281 return mapping[self.__configuration['nodeEdgePoint']['cep'][0]['role'].lower()]
284 def termination_state(self) -> str:
286 Getter returning the TAPI Node Edge Point state.
287 :return TAPI Node Edge Point state as String.
289 return "LT_PERMENANTLY_TERMINATED"