-
Notifications
You must be signed in to change notification settings - Fork 1
/
info_cell.chart.py
161 lines (134 loc) · 6.88 KB
/
info_cell.chart.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
from bases.FrameworkServices.SimpleService import SimpleService
priority = 90000
#those two imports are required to connect thous websockets
import websocket
#we tranform the result into json for easier manipulation
import json
#debug
from pprint import pprint
#update_every=2
ORDER = [
'random',
]
CHARTS = {
'random': {
'options': [None, 'A random number', 'random number', 'random', 'random', 'line'],
'lines': [
['random1']
]
}
}
class Service(SimpleService):
def __init__(self, configuration=None, name=None):
SimpleService.__init__(self, configuration=configuration, name=name)
self.order = ORDER
self.definitions = CHARTS
self.num_lines = self.configuration.get('num_lines', 1)
self.lower = self.configuration.get('lower', 0)
self.upper = self.configuration.get('upper', 100)
self.wsapp_gNodeB = websocket.WebSocket()
self.wsapp_mme = websocket.WebSocket()
while True:
self.wsapp_gNodeB.connect("ws://172.16.10.208:9001")
self.debug("check connection")
if self.wsapp_gNodeB.connected:
break
self.data = dict()
@staticmethod
def check():
return True
def gNodeB_WS(self):
msg_to_send_mme="{\"message\":\"stats\",\"rf\":true}"
self.wsapp_gNodeB.send(msg_to_send_mme)
res=self.wsapp_gNodeB.recv()
return res
def get_data(self):
data = dict()
if(self.wsapp_gNodeB):
gNodeB_res=self.gNodeB_WS()
#self.debug("gNB res: ", gNodeB_res)
res_json=json.loads(gNodeB_res)
###################################################################
# Create charts
self.cell_bitrate(res_json)
self.cell_transmissions(res_json)
self.cell_retransmissions(res_json)
for i in range(0, self.num_lines):
dimension_id = ''.join(['random', str(i)])
if dimension_id not in self.charts['random']:
self.charts['random'].add_dimension([dimension_id])
data[dimension_id] = 10
data=self.data
return data
#########################################################################
def cell_bitrate(self, res_json):
if "cells" in res_json:
for i in range(1, len(res_json["cells"]) + 1):
chart_name='_'.join(["cell", str(i), "bitrate"])
if chart_name not in ORDER:
ORDER.append(chart_name)
if chart_name not in self.charts:
CHARTS[chart_name]={\
'options': [None, '_'.join(["cell", str(i), "bitrate"]), "bps", "bitrate", "STATS_GNODEB", 'line']}#,\
#Now we add the newly created chart to the charts to be displayed.
params = [chart_name] + CHARTS[chart_name]['options']
self.charts.add_chart(params)
#Once the chart has been created we populate it with dimensions (i.e. data to be displayed)
dimension_id = '_'.join(["cell", str(i), "dl_bitrate"])
if dimension_id not in self.charts[chart_name]:
self.charts[chart_name].add_dimension([dimension_id,"downlink bitrate",None,None,None])
self.data[dimension_id] = res_json["cells"][str(i)]["dl_bitrate"]
dimension_id ='_'.join(["cell", str(i),"ul_bitrate"])
if dimension_id not in self.charts[chart_name]:
self.charts[chart_name].add_dimension([dimension_id,"uplink bitrate",None,None,None])
self.data[dimension_id] = res_json["cells"][str(i)]["ul_bitrate"]
else:
self.debug("=> cell list is Empty !")
def cell_transmissions(self, res_json):
if "cells" in res_json:
for i in range(1, len(res_json["cells"]) + 1):
chart_name='_'.join(["cell", str(i),"tx"])
if chart_name not in ORDER:
ORDER.append(chart_name)
if chart_name not in self.charts:
CHARTS[chart_name]={\
'options': [None, '_'.join(["cell", str(i),"tx"]), "# of Transport blocks", "Transmissions", "STATS_GNODEB", 'line']}#,\
#Now we add the newly created chart to the charts to be displayed.
params = [chart_name] + CHARTS[chart_name]['options']
self.charts.add_chart(params)
for i in range(1, len(res_json["cells"]) + 1):
#Once the chart has been created we populate it with dimensions (i.e. data to be displayed)
dimension_id = '_'.join(["cell", str(i),"dl_tx"])
if dimension_id not in self.charts[chart_name]:
self.charts[chart_name].add_dimension([dimension_id,"downlink tx",None,None,None])
self.data[dimension_id] = res_json["cells"][str(i)]["dl_tx"]
dimension_id ='_'.join(["cell", str(i),"ul_tx"])
if dimension_id not in self.charts[chart_name]:
self.charts[chart_name].add_dimension([dimension_id,"uplink tx",None,None,None])
self.data[dimension_id] = res_json["cells"][str(i)]["ul_tx"]
else:
self.debug("=> cell list is Empty !")
def cell_retransmissions(self, res_json):
if "cells" in res_json:
for i in range(1, len(res_json["cells"]) + 1):
chart_name='_'.join(["cell", str(i),"retx"])
if chart_name not in ORDER:
ORDER.append(chart_name)
if chart_name not in self.charts:
CHARTS[chart_name]={\
'options': [None,'_'.join(["cell", str(i),"retx"]), "# of Transport blocks", "Retransmissions", "STATS_GNODEB", 'line']}#,\
#Now we add the newly created chart to the charts to be displayed.
params = [chart_name] + CHARTS[chart_name]['options']
self.charts.add_chart(params)
for i in range(1, len(res_json["cells"]) + 1):
#Once the chart has been created we populate it with dimensions (i.e. data to be displayed)
dimension_id = '_'.join(["cell", str(i),"dl_retx"])
if dimension_id not in self.charts[chart_name]:
self.charts[chart_name].add_dimension([dimension_id,"downlink retx",None,None,None])
self.data[dimension_id] = res_json["cells"][str(i)]["dl_retx"]
dimension_id ='_'.join(["cell", str(i),"ul_tx"])
if dimension_id not in self.charts[chart_name]:
self.charts[chart_name].add_dimension([dimension_id,"uplink retx",None,None,None])
self.data[dimension_id] = res_json["cells"][str(i)]["ul_retx"]
else:
self.debug("=> cell list is Empty !")