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 for the class representing a TAPI Link
19 from typing import Dict, Union
21 from lxml import etree
22 from model.python.link_config import LinkConfig
23 from model.python.top import Top
28 Class representing a TAPI Link object.
32 __configuration: dict = {}
35 def __init__(self, configuration: dict):
36 super().__init__(configuration)
37 self.__configuration = configuration
38 self.__link_configuration = LinkConfig(
39 topology_reference=configuration["topology_reference"],
40 name_prefix=configuration["name_prefix"],
41 provider=configuration["provider"],
42 consumer=configuration["consumer"]
44 link_data = self.__link_configuration.json()
46 "uuid": str(uuid.uuid4()),
48 "value-name": "topology-link-name",
49 "value": link_data['link']['name']
51 "transitioned-layer-protocol-name": ["inETH", "outETH"],
52 "administrative-state": "LOCKED",
53 "operational-state": "ENABLED",
54 "direction": "BIDIRECTIONAL",
55 "lifecycle-state": "INSTALLED",
57 link_data['link']['a'],
58 link_data['link']['z']
60 "latency-characteristic": [{
61 "traffic-property-name": "property-1",
62 "queing-latency-characteristic": "queue-1",
63 "fixed-latency-characteristic": "latency-1",
64 "jitter-characteristic": "jitter-1",
65 "wander-characteristic": "wander-1"
67 "layer-protocol-name": ["ETH"],
68 "risk-characteristic": [{
69 "risk-characteristic-name": "risk-name",
70 "risk-identifier-list": [
72 "validation-mechanism": [{
73 "validation-mechanism": "mechanism-1",
74 "validation-robustness": "very-robust",
75 "layer-protocol-adjacency-validated": "validated"}],
76 "cost-characteristic": [{
78 "cost-algorithm": "alg1",
79 "cost-value": "value-1"}]}
82 def configuration(self) -> Dict[str, Dict]:
84 Getter for a json object representing the initial configuration of a TAPI Link.
85 :return TAPI Link configuration as json object.
87 return self.__configuration
89 def data(self) -> dict:
91 Getter for a json object representing the TAPI Link.
92 :return TAPI Link as json object.
96 def json(self) -> dict:
98 Getter for a json object representing the TAPI Link.
99 :return TAPI Link as json object.
103 def identifier(self) -> str:
105 Getter returning the TAPI Link identifier.
106 :return Object identifier as UUID.
108 return self.__data["uuid"]
110 def name(self) -> str:
112 Getter for TAPI Link name.
113 :return TAPI Link as json object.
115 return self.__link_configuration.json()['link']['name']
117 def svg(self, svg_x: int, svg_y: int) -> etree.Element:
119 Getter for a xml Element object representing the TAPI Link.
120 :return TAPI Link as svg object.
123 group = etree.Element("g")
124 class_name = self.name().split("-")[0].lower()
125 group.attrib["class"] = " ".join(["link", class_name])
126 title = etree.Element("title")
127 title.text = "\n TAPI Link\n id: " + \
128 self.identifier() + "\n name: " + self.name()
131 # cubic bezier curves
132 source_x = self.__link_configuration.consumer_node_edge_point().svg_x()
133 source_y = self.__link_configuration.consumer_node_edge_point().svg_y()
134 target_x = self.__link_configuration.provider_node_edge_point().svg_x()
135 target_y = self.__link_configuration.provider_node_edge_point().svg_y()
137 path = etree.Element("path")
138 path.attrib["d"] = " ".join(["M", str(source_x), str(source_y),
139 "C", str(source_x), str(target_y),
140 str(target_x), str(source_y),
141 str(target_x), str(target_y)])
142 path.attrib["class"] = "link"