-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathof-diff
More file actions
executable file
·55 lines (47 loc) · 1.26 KB
/
of-diff
File metadata and controls
executable file
·55 lines (47 loc) · 1.26 KB
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
#!/usr/bin/env python
import sys
import subprocess
import re
import time
import json
br = sys.argv[1]
keys = ('table', 'priority', 'actions', 'NXST_FLOW', 'cookie', 'ip', 'zone', 'ipv6', 'reg5')
values = ('n_packets', 'n_bytes')
skips = ('idle_age', 'duration')
stats = {}
while True:
p = subprocess.Popen("ovs-ofctl dump-flows %s" % (br),
shell=True,
stdout=subprocess.PIPE)
for l in p.stdout:
key = {}
value = {}
for e in l.strip().split(', '):
try:
k, v = e.split('=', 1)
except:
k = e
v = None
if k in keys:
key[k] = v
elif k in values:
value[k] = int(v)
elif k in skips:
pass
else:
pass
jkey = json.dumps(key)
prev_stats = stats.get(jkey, {})
diff = False
for k in value:
if value[k] != prev_stats.get(k, 0):
diff = True
break
if diff:
delta = {}
for k in value:
delta[k] = value[k] - prev_stats.get(k, 0)
print key, delta
stats[jkey] = value
print
time.sleep(1)