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 SMO as TAPI Node.
19 from typing import List
20 from lxml import etree
21 from model.python.tapi_node import TapiNode
22 from model.python.tapi_node_edge_point import TapiNodeEdgePoint
25 class TapiNodeSmo(TapiNode):
27 Class representing a SMO as TAPI Node
32 def __init__(self, parent: TapiNode, config):
33 super().__init__(parent, config)
35 # add O2 consumer interface
37 "parent": self.identifier(),
39 "interface": "o2", "cep": [{"protocol": "REST", "role": "consumer"}]
42 self.add(TapiNodeEdgePoint(nep_configuration))
44 # add A1 consumer interface
46 "parent": self.identifier(),
48 "interface": "a1", "cep": [{"protocol": "REST", "role": "consumer"}]
51 self.add(TapiNodeEdgePoint(nep_configuration))
53 # add O1/OAM NetConf Consumer interface
55 "parent": self.identifier(),
57 "interface": "oam", "cep": [{"protocol": "NETCONF", "role": "consumer"}]
60 self.add(TapiNodeEdgePoint(nep_configuration))
62 # add O1 VES Provider interface
64 "parent": self.identifier(),
66 "interface": "o1", "cep": [{"protocol": "VES", "role": "provider"}]
69 self.add(TapiNodeEdgePoint(nep_configuration))
71 # add O1 File Transfer Consumer interface
73 "parent": self.identifier(),
75 "interface": "o1", "cep": [{"protocol": "FILE", "role": "consumer"}]
78 self.add(TapiNodeEdgePoint(nep_configuration))
80 def __smo_component(self, x: int, y: int, label: str) -> etree.Element:
81 group = etree.Element("g")
82 group.attrib["class"] = " ".join(["node", label])
84 width = (2 + 2) * (2.2*self.FONTSIZE)
85 height = 2 * (2*self.FONTSIZE)
87 rect = etree.Element("rect")
88 rect.attrib["x"] = str(int(x - width/2))
89 rect.attrib["y"] = str(int(y - height/2))
90 rect.attrib["width"] = str(int(width))
91 rect.attrib["height"] = str(int(height))
92 rect.attrib["rx"] = str(self.FONTSIZE)
93 rect.attrib["class"] = " ".join(["node", label])
96 labelElement = etree.Element('text')
97 labelElement.attrib['x'] = str(x)
98 # +4px for font-size 14px (think of chars like 'gjy')
99 labelElement.attrib['y'] = str(y + 4)
100 labelElement.attrib['class'] = " ".join(["node", label])
101 labelElement.text = label.upper()
102 group.append(labelElement)
105 def svg(self, x: int, y: int) -> etree.Element:
107 Getter for a xml Element object representing the TAPI Node.
108 :return TAPI Node as svg object.
112 components = ["o2-controller", "non-rt-ric", "oam-controller",
113 "ves-collector", "file-server"]
115 group = etree.Element("g")
116 group.attrib["class"] = "node"
117 title = etree.Element("title")
118 title.text = "\n TAPI Node\n id: " + \
119 self.identifier() + "\n name: " + self.name()
122 width = (len(components)*5 +1) * (2.2*self.FONTSIZE)
123 height = 2 * (2.2*self.FONTSIZE)
125 rect = etree.Element("rect")
126 rect.attrib["x"] = str(int(x - width/2))
127 rect.attrib["y"] = str(int(y - height/2))
128 rect.attrib["width"] = str(int(width))
129 rect.attrib["height"] = str(int(height))
130 rect.attrib["rx"] = str(self.FONTSIZE)
131 rect.attrib["class"] = " ".join(
132 ["node", self.function_label().lower()])
135 label = etree.Element('text')
136 label.attrib['x'] = str(x)
137 # +4px for font-size 14px (think of chars like 'gjy')
138 label.attrib['y'] = str(y + 4)
139 label.attrib['class'] = " ".join(
140 ["node", self.function_label().lower()])
141 label.text = self.function_label()
144 for component in components:
146 "o2-controller": -4*6*self.FONTSIZE,
147 "non-rt-ric": -2*6*self.FONTSIZE,
148 "oam-controller": -0*6*self.FONTSIZE,
149 "ves-collector": +2*6*self.FONTSIZE,
150 "file-server": +4*6*self.FONTSIZE
152 comp_x = x + x_mapping[component]
153 comp_y = y-0*self.FONTSIZE
154 group.append(self.__smo_component(comp_x, comp_y, component))
156 for nep in self.data()['owned-node-edge-point']:
158 super().x_offset_by_cep_name(
159 nep.connection_edge_points()[0].name(), 0)
161 super().y_offset_by_cep_name(
162 nep.connection_edge_points()[0].name())
163 group.append(nep.svg(nep_x, nep_y))