tor_multipath_voip/scripts/links_parse.py

44 lines
1 KiB
Python
Raw Normal View History

2019-09-16 16:00:15 +00:00
#!/usr/bin/python3
import sys,re
2019-09-16 17:20:38 +00:00
acc = []
previous=None
2019-09-16 16:00:15 +00:00
for line in sys.stdin:
res = re.match(r"\[(\d+)\] Blacklisted links: ([_U]+)", line)
if not res: continue
ts,l = res.groups()
2019-09-16 17:20:38 +00:00
ts = int(ts)
2019-09-16 16:00:15 +00:00
l2 = [(i, 'up' if l[i] == "U" else 'down') for i in range(len(l))]
2019-09-16 17:20:38 +00:00
acc.append((ts,l2))
l2 = None
if len(acc) <= 0: sys.exit(0)
ts_first, l_first = acc[0]
ts_last, l_last = acc[len(acc) - 1]
xp_time = ts_last - ts_first
2019-09-16 20:53:34 +00:00
2019-09-16 17:20:38 +00:00
durations = [0 for i,v in l_first]
2019-09-16 20:53:34 +00:00
durations_link_config = 0
2019-09-16 17:20:38 +00:00
for j in range(len(acc)):
ts, l = acc[j]
ts_next, l_next = acc[j]
if j+1 < len(acc): ts_next, l_next = acc[j+1]
delta = ts_next - ts
2019-09-16 20:53:34 +00:00
durations_link_config += delta
will_change_duration = l != l_next
2019-09-16 17:20:38 +00:00
for i,v in l:
durations[i] += delta
i_next,v_next = l_next[i]
will_change = v != v_next or j+1 == len(acc)
2019-09-16 20:53:34 +00:00
print(f"{sys.argv[1]},{ts},{i},{v},{delta},{durations[i]},{will_change},{xp_time},{durations_link_config},{will_change_duration}")
2019-09-16 17:20:38 +00:00
if will_change: durations[i] = 0
2019-09-16 20:53:34 +00:00
if will_change_duration: durations_link_config = 0
2019-09-16 16:00:15 +00:00