3 # Copyright 2022 highstreet technologies GmbH
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
19 Module for a class representing a TAPI Common Context
21 from typing import Dict, Union
23 from xml.dom.minidom import Element
24 from lxml import etree
25 from model.python.tapi_topology_context import TapiTopologyContext
26 from model.python.top import Top
29 class TapiCommonContext(Top):
31 Class representing a TAPI Common Context object.
34 __configuration: dict = {}
35 __context: TapiTopologyContext = None
37 "tapi-common:context": {
38 "uuid": str(uuid.uuid4()),
39 "name": [{"value-name": "context-name",
40 "value": "Generated Topology"}]}}
43 def __init__(self, configuration: Dict[str, Union[str, Dict[str, int]]]):
44 super().__init__(configuration)
45 self.__configuration = configuration
46 self.__context = TapiTopologyContext(configuration)
49 def configuration(self) -> Dict[str, Dict]:
51 Getter for a json object representing the TAPI Common Context.
52 :return TAPI Common Context as json object.
54 return self.__configuration
56 def data(self) -> Dict:
58 Getter for a json object representing the TAPI Common Context.
59 :return TAPI Common Context as json object.
63 def json(self) -> Dict:
65 Getter for a json object representing the TAPI Topology Context.
66 :return TAPI Common Context as json object.
68 result = self.data().copy()
69 if self.__context is not None:
70 result["tapi-common:context"].update(self.__context.json())
73 def identifier(self) -> str:
75 Getter returning the TAPI common context identifier.
76 :return Object identifier as string
78 return self.__data["tapi-common:context"]["uuid"]
80 def name(self) -> str:
82 Getter for object name.
83 :return Human readable string as name.
85 return self.data()["tapi-common:context"]["name"][0]["value"]
87 def __svg_width(self) -> int:
88 p = self.configuration()['network']['pattern']
89 return (p['smo'] * p['near-rt-ric'] * p['o-cu'] * p['o-du'] * p['fronthaul-gateway'] * p['o-ru'] * p['user-equipment'] + 1) * 4*2*self.FONTSIZE
91 def __svg_height(self) -> int:
92 return (8 * 11 + 6) * self.FONTSIZE
94 def svg(self, x, y) -> etree.Element:
96 Getter for a xml/svg Element object representing the TAPI Topology Context.
97 :return TAPI Common Context as SVG object.
99 root: Element = etree.Element(
101 width=str(self.__svg_width()),
102 height=str(self.__svg_height()),
104 str(-3*self.FONTSIZE),
105 str(-3*self.FONTSIZE),
106 str(self.__svg_width()),
107 str(self.__svg_height())]
109 xmlns="http://www.w3.org/2000/svg"
111 desc=etree.Element("desc")
112 desc.text="\n context: " + self.identifier() + "\n name: " + self.name()
115 title=etree.Element("title")
116 title.text=self.configuration()["network"]["name"]
119 root.append(self.__context.svg(x, y))
122 def topology_context(self) -> TapiTopologyContext:
124 Getter for next level object (TapiTopologyContext).
125 :return TAPI Topology Context
127 return self.__context