forked from modong/pcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filemonitor.py
58 lines (56 loc) · 2.64 KB
/
filemonitor.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
import sys
import time
import logging
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import os
class NewSnapshotEventHandler(FileSystemEventHandler):
def __init__(self):
self.param = {}
self.param["Bandwidth"] = "100Mbit/s"
self.param["RTT"] = "30ms"
self.param["BufferSize"] = "50slots"
self.param["LossRate"] = "0"
self.is_start = False
def on_modified(self, event):
if event.is_directory is True:
return
with open("./parameters.txt", "r") as f:
param = f.read()
lines = param.split("\n")
tmp_param = {}
for line in lines:
if line == "stop" and self.is_start:
os.system("./stop_demo_compare_tcp_and_pcc.sh")
self.is_start = False
return
elif line == "start" and not self.is_start:
os.system("./run_demo_compare_tcp_and_pcc.sh")
self.is_start = True
elif line != "" and line !="start" and line != "stop":
tmp_param[line.split(" ")[0]] = line.split(" ")[1]
if tmp_param == self.param:
return
else:
self.param = tmp_param
if not self.is_start:
os.system("ssh -t -t -o StrictHostKeyChecking=no [email protected] \"killall iperf && ./setup.bash {}\"".format(self.param["protocol"]))
os.system("ssh -t -t -o StrictHostKeyChecking=no [email protected] \"nohup python ~/run_iperf.py &\"")
os.system("ssh -t -t -o StrictHostKeyChecking=no [email protected] \"killall iperf && ./setup.bash {}\"".format(self.param["protocol"]))
os.system("python ./tune_bw_rtt_loss.py -b {} -d {} -q {} -l {}".format(self.param["Bandwidth"],
self.param["RTT"],
self.param["BufferSize"],
self.param["LossRate"]))
if __name__ == "__main__":
path = '.'
event_handler = NewSnapshotEventHandler()
observer = Observer()
observer.daemon = True
observer.schedule(event_handler, path, recursive=False)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()