Create concrete classes for O-RAN Nodes
[oam.git] / code / network-generator / model / python / o_ran_spiral_radius_profile.py
1 # Copyright 2023 highstreet technologies GmbH
2 #
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
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 #!/usr/bin/python
16
17 from dataclasses import dataclass
18 from typing import List
19 from model.python.hexagon import Hex
20
21 class SpiralRadiusProfile:
22     def __init__(self, data=None):
23         self._oRanSmoSpiralRadiusOfNearRtRics = data.get("oRanSmoSpiralRadiusOfNearRtRics", 1) if data else 1
24         self._oRanNearRtRicSpiralRadiusOfOCus = data.get("oRanNearRtRicSpiralRadiusOfOCus", 1) if data else 1
25         self._oRanCuSpiralRadiusOfODus = data.get("oRanCuSpiralRadiusOfODus", 1) if data else 1
26         self._oRanDuSpiralRadiusOfTowers = data.get("oRanDuSpiralRadiusOfTowers", 1) if data else 1
27
28     @property
29     def id(self):
30         return f"{self._oRanDuSpiralRadiusOfTowers}{self._oRanCuSpiralRadiusOfODus}{self._oRanNearRtRicSpiralRadiusOfOCus}{self._oRanSmoSpiralRadiusOfNearRtRics}"
31
32     @property
33     def count(self):
34         towers = 1
35         dus = 1
36         cus = 1
37         rics = 1
38
39         for ru in range(self._oRanDuSpiralRadiusOfTowers + 1):
40             towers = towers + 6 * ru
41
42         for du in range(self._oRanCuSpiralRadiusOfODus + 1):
43             dus = dus + 6 * du
44
45         for cu in range(self._oRanNearRtRicSpiralRadiusOfOCus + 1):
46             cus = cus + 6 * cu
47
48         for ric in range(self._oRanSmoSpiralRadiusOfNearRtRics + 1):
49             rics = rics + 6 * ric
50
51         return towers * dus * cus * rics
52
53     @property
54     def oRanSmoSpiralRadiusOfNearRtRics(self):
55         return self._oRanSmoSpiralRadiusOfNearRtRics
56
57     @oRanSmoSpiralRadiusOfNearRtRics.setter
58     def oRanSmoSpiralRadiusOfNearRtRics(self, value):
59         self._oRanSmoSpiralRadiusOfNearRtRics = value
60
61     @property
62     def oRanNearRtRicSpiralRadiusOfOCus(self):
63         return self._oRanNearRtRicSpiralRadiusOfOCus
64
65     @oRanNearRtRicSpiralRadiusOfOCus.setter
66     def oRanNearRtRicSpiralRadiusOfOCus(self, value):
67         self._oRanNearRtRicSpiralRadiusOfOCus = value
68
69     @property
70     def oRanCuSpiralRadiusOfODus(self):
71         return self._oRanCuSpiralRadiusOfODus
72
73     @oRanCuSpiralRadiusOfODus.setter
74     def oRanCuSpiralRadiusOfODus(self, value):
75         self._oRanCuSpiralRadiusOfODus = value
76
77     @property
78     def oRanDuSpiralRadiusOfTowers(self):
79         return self._oRanDuSpiralRadiusOfTowers
80
81     @oRanDuSpiralRadiusOfTowers.setter
82     def oRanDuSpiralRadiusOfTowers(self, value):
83         self._oRanDuSpiralRadiusOfTowers = value
84
85     @property
86     def sectors(self):
87         return self._sectors
88
89     @sectors.setter
90     def sectors(self, value):
91         self._sectors = value
92
93     @property
94     def nrDuCellsPerSector(self):
95         return self._nrDuCellsPerSector
96
97     @nrDuCellsPerSector.setter
98     def nrDuCellsPerSector(self, value):
99         self._nrDuCellsPerSector = value
100
101     def oRanDuDirections(self):
102         q = 2 * self._oRanDuSpiralRadiusOfTowers + 1
103         r = - self._oRanDuSpiralRadiusOfTowers - 1
104         s = -q - r
105         return [
106             Hex(q, r, s), Hex(-s, -q, -r), Hex(r, s, q),
107             Hex(-q, -r, -s), Hex(s, q, r), Hex(-r, -s, -q)
108         ]
109
110     def oRanDuNeighbor(self, cube, direction):
111         return Hex.add(cube, self.oRanDuDirections[direction])
112
113     def oRanDuRing(self, center, radius):
114         if radius <= 0:
115             raise ValueError('Invalid radius. The radius around the hex center must be greater than 0 rings.')
116         results = []
117         hex = Hex.add(center, Hex.scale(self.oRanDuDirections[4], radius))
118         for i in range(6):
119             for j in range(radius):
120                 results.append(hex)
121                 hex = self.oRanDuNeighbor(hex, i)
122         return results
123
124     def oRanDuSpiral(self, center, radius):
125         result = [center]
126         for k in range(1, radius + 1):
127             result.extend(self.oRanDuRing(center, k))
128         return result
129
130     def oRanCuDirections(self):
131         q0 = 2 * self._oRanCuSpiralRadiusOfODus + 3 * self._oRanCuSpiralRadiusOfODus * self._oRanDuSpiralRadiusOfTowers + self._oRanDuSpiralRadiusOfTowers + 1
132         r0 = self._oRanDuSpiralRadiusOfTowers - self._oRanCuSpiralRadiusOfODus
133         q = 3 * q0 - self._oRanNearRtRicSpiralRadiusOfOCus
134         r = -r0 - self._oRanNearRtRicSpiralRadiusOfOCus
135         switch_id = self.id[2:-1]
136         if switch_id in ("111", "112", "113", "114"):
137             q = 21 + 14