forked from wineslab/ns-o-ran-ns3-mmwave
-
Notifications
You must be signed in to change notification settings - Fork 4
/
sim_data_pusher.py
253 lines (224 loc) · 8.59 KB
/
sim_data_pusher.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
import os
import time
from influxdb import InfluxDBClient
def read_and_clear_csv(file_path):
with open(file_path, 'r') as file:
lines = file.readlines()
headers = lines[0].strip()
data = [line.strip() for line in lines[1:]]
result = [headers] + data
with open(file_path, 'w') as file:
file.write(headers + '\n')
return result
def push_data_to_influx(
file_path,
db_name,
core_files,
influx_host='localhost',
influx_port=8086,
influx_user='root',
influx_password='root'):
data = read_and_clear_csv(file_path)
ue_fields = {
'l3 serving id(m_cellid)',
'drb.estabsucc.5qi.ueid',
'l3 neigh id 1 (cellid)',
'l3 neigh id 2 (cellid)',
'l3 neigh id 3 (cellid)',
'l3 neigh id 4 (cellid)',
'l3 neigh id 5 (cellid)',
'l3 neigh id 6 (cellid)',
'l3 neigh id 7 (cellid)',
'l3 neigh id 8 (cellid)',
'l3 serving sinr',
'l3 neigh sinr 1',
'l3 neigh sinr 2',
'l3 neigh sinr 3',
'l3 neigh sinr 4',
'l3 neigh sinr 5',
'l3 neigh sinr 6',
'l3 neigh sinr 7',
'l3 neigh sinr 8',
'tb.errtotalnbrdl.1.ueid',
'drb.buffersize.qos.ueid',
'drb.uethpdl.ueid',
'rru.prbuseddl',
'drb.uethpdlpdcpbased.ueid',
'qosflow.pdcppduvolumedl_filter',
'tb.totnbrdlinitial',
'tb.totnbrdlinitial.16qam',
'tb.totnbrdlinitial.64qam',
'tb.totnbrdlinitial.qpsk.ueid',
'tb.totnbrdl.1.ueid',
'dlprbusage',
'qosflow_pdcppduvolumedl_filter_ueid(txpdcppdubytesnrrlc)',
'drb.pdcpsdudelaydl.ueid(pdcp latency)',
'drb_pdcppdunbrdl_qos_ueid(txpdcppdunrrlc)',
'tot_pdcpsdunbrdl_ueid(txdlpackets)',
'drb.pdcpsdubitratedl.ueid(pdcpthroughput)',
'drb.pdcpsduvolumedl_filter.ueid(txbytes)'
}
cell_fields = {
'tb.errtotalnbrdl.1.ueid',
'drb.buffersize.qos.ueid',
'rru.prbuseddl',
'drb.meanactiveuedl',
'qosflow.pdcppduvolumedl_filter',
'tb.totnbrdlinitial',
'tb.totnbrdlinitial.16qam',
'tb.totnbrdlinitial.64qam',
'tb.totnbrdlinitial.qpsk.ueid',
'tb.totnbrdl.1.ueid',
'drb.pdcpsdudelaydl (cellaveragelatency)',
'm_pdcpbytesdl (celldltxvolume)',
'dlprbusage'
}
client = InfluxDBClient(
host=influx_host,
port=influx_port,
username=influx_user,
password=influx_password,
database=db_name)
client.create_database(db_name)
headers = data[0].split(',')
headers = [header.strip().lower() for header in headers]
records = data[1:]
id_column = None
possible_id_columns = ["imsi", "id", "ueimsicomplete", "ueImsiComplete"]
for possible_id in possible_id_columns:
if possible_id in headers:
id_column = possible_id
break
influx_points = []
filename = os.path.splitext(os.path.basename(file_path))[0]
for record in records:
fields = record.split(',')
if file_path in core_files:
if id_column is None:
print(f"Error: Neither 'imsi', 'id', nor 'ueImsiComplete' found in the headers of {file_path}")
return
id_index = headers.index(id_column)
record_id = fields[id_index]
for i, field in enumerate(fields):
if i == id_index or headers[i] == "timestamp":
continue
try:
value = float(field) if field.replace('.', '', 1).isdigit() else field
except ValueError:
print(f"Skipping invalid value in file '{file_path}' for field '{headers[i]}': {field}")
continue
measurement = f"{filename}_{headers[i]}_{record_id}"
influx_point = {
"measurement": measurement,
"tags": {
id_column: record_id
},
"fields": {
"value": value
}
}
influx_points.append(influx_point)
else:
for i, field in enumerate(fields):
if headers[i] == "timestamp":
continue
try:
if headers[i] == 'l3 serving sinr':
value = str(field)
else:
value = float(field) if field.replace('.', '', 1).isdigit() else field
except ValueError:
print(f"Skipping invalid value in file '{file_path}' for field '{headers[i]}': {field}")
continue
if headers[i] in ue_fields and headers[i] not in cell_fields:
if headers[i] in ('l3 neigh id 1 (cellid)', 'l3 neigh id 2 (cellid)', 'l3 neigh id 3 (cellid)',
'l3 neigh id 4 (cellid)', 'l3 neigh id 5 (cellid)', 'l3 neigh id 6 (cellid)',
'l3 neigh id 7 (cellid)', 'l3 neigh id 8 (cellid)'):
if value != '':
value = int(value)
else:
value = 0
if headers[i] in ('l3 neigh sinr 1', 'l3 neigh sinr 2', 'l3 neigh sinr 3', 'l3 neigh sinr 4'
'l3 neigh sinr 5', 'l3 neigh sinr 6', 'l3 neigh sinr 7', 'l3 neigh sinr 8'):
if value == '':
value = -999
measurement = f"ue_{int(fields[1])}_{headers[i]}"
influx_point = {
"measurement": measurement,
"fields": {
"value": value
}
}
influx_points.append(influx_point)
elif headers[i] in cell_fields and headers[i] not in ue_fields:
measurement = f"{filename}_{headers[i]}"
influx_point = {
"measurement": measurement,
"fields": {
"value": value
}
}
influx_points.append(influx_point)
elif headers[i] in cell_fields and headers[i] in ue_fields:
measurement = f"ue_{int(fields[1])}_{headers[i]}"
influx_point = {
"measurement": measurement,
"fields": {
"value": value
}
}
influx_points.append(influx_point)
measurement = f"{filename}_{headers[i]}"
influx_point = {
"measurement": measurement,
"fields": {
"value": value
}
}
influx_points.append(influx_point)
try:
if influx_points:
client.write_points(influx_points)
print(f"Successfully pushed data to InfluxDB for {len(influx_points)} points from {file_path}.")
else:
print(f"No valid data to push for file {file_path}.")
influx_point = {
"measurement": f"{filename}_drb.meanactiveuedl",
"fields": {
"value": float(0)
}
}
influx_points = [influx_point]
client.write_points(influx_points)
except Exception as e:
print(f"Failed to write data from {file_path} to InfluxDB: {e}")
def main():
influx_host = 'localhost'
influx_port = 8086
influx_user = 'root'
influx_password = 'root'
db_name = 'influx'
core_files = [
"ue_position.txt",
"gnbs.txt",
"enbs.txt"
]
while True:
additional_files = [
file for file in os.listdir('.')
if file.startswith(('cu-cp-cell-', 'cu-up-cell-', 'du-cell-')) and file.endswith('.txt')
]
files_to_process = core_files + additional_files
for file_path in files_to_process:
if os.path.exists(file_path):
push_data_to_influx(
file_path,
db_name,
core_files,
influx_host,
influx_port,
influx_user,
influx_password)
time.sleep(3)
if __name__ == "__main__":
main()