-
Notifications
You must be signed in to change notification settings - Fork 1
/
map_parser.py
49 lines (41 loc) · 1.23 KB
/
map_parser.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
import json
import subprocess
import sys
def run_cmd(cmd):
print("Running: ",cmd)
status, output = subprocess.getstatusoutput(cmd)
if(status != 0):
print("Failed while running: ",cmd," Exiting...")
exit(1)
return output
def load_map_json(fname):
with open(fname, 'r') as f:
data = json.load(f)
return data
def get_umaps(maps):
global rate_map,port_map,recv_map,drop_map
for m in maps:
if m['type'] == 'xdp':
umaps = m['map_ids']
umaps.sort()
print(umaps)
rate_map = umaps[0]
port_map = umaps[4]
recv_map = umaps[2]
drop_map = umaps[3]
print("RateMap: ",rate_map,"port_map",port_map)
if __name__ == "__main__":
iface = sys.argv[1]
rate_map=""
port_map=""
recv_map=""
drop_map=""
cmd = "ip link set dev " + iface + " xdp obj ratelimiting_kern.o sec xdp_ratelimiting"
run_cmd(cmd)
cmd = "bpftool prog show -j > prog.json"
run_cmd(cmd)
fname="prog.json"
maps = load_map_json(fname)
get_umaps(maps)
cmd = "bash map_update.sh " +str(rate_map) + " " + str(port_map) + " " + str(recv_map) + " " + str(drop_map)
run_cmd(cmd)