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, running: bool) -> 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 and running is False:
70 result["tapi-common:context"].update(self.__context.json())
72 if running is True and "tapi-topology:topology-context" in result["tapi-common:context"]:
73 result["tapi-common:context"].pop("tapi-topology:topology-context")
77 def identifier(self) -> str:
79 Getter returning the TAPI common context identifier.
80 :return Object identifier as string
82 return self.__data["tapi-common:context"]["uuid"]
84 def name(self) -> str:
86 Getter for object name.
87 :return Human readable string as name.
89 return self.data()["tapi-common:context"]["name"][0]["value"]
91 def __svg_width(self) -> int:
92 p = self.configuration()['network']['pattern']
93 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
95 def __svg_height(self) -> int:
96 return (8 * 11 + 6) * self.FONTSIZE
98 def svg(self, x, y) -> etree.Element:
100 Getter for a xml/svg Element object representing the TAPI Topology Context.
101 :return TAPI Common Context as SVG object.
103 root: Element = etree.Element(
105 width=str(self.__svg_width()),
106 height=str(self.__svg_height()),
108 str(-3*self.FONTSIZE),
109 str(-3*self.FONTSIZE),
110 str(self.__svg_width()),
111 str(self.__svg_height())]
113 xmlns="http://www.w3.org/2000/svg"
115 desc=etree.Element("desc")
116 desc.text="\n context: " + self.identifier() + "\n name: " + self.name()
119 title=etree.Element("title")
120 if "name" in self.configuration()["network"]:
121 title.text=self.configuration()["network"]["name"]
123 title.text="o-ran-sc-topology-view"
126 root.append(self.__context.svg(x, y))
129 def topology_context(self) -> TapiTopologyContext:
131 Getter for next level object (TapiTopologyContext).
132 :return TAPI Topology Context
134 return self.__context