-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmtu_process.py
83 lines (79 loc) · 2.23 KB
/
mtu_process.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
import subprocess
import asyncio
import traceback
import json
from log_settings import getStreamLogger
from datetime import datetime
from constants import *
from utilities import server_utils
'''
Starts a "plpmtu_reverse" subproc instance
and returns the subproc object
@PARAMS:
ofile : the output file for the reverse
mtu function
@RETURN:
plpmtu_process : process object of the reverse mtu
measurer
'''
def start_mtu_reverse(ofile):
try:
plpmtu_process = subprocess.Popen(["./plpmtu_reverse"],stdout = ofile, stderr = ofile)
print("PLPMTU REVERSE started")
except:
print("FAILED TO START PLPMTU REVERSE")
try:
plpmtu_process.kill()
except:
pass
raise
return plpmtu_process
'''
Parses mtu subprocess output from a file
@PARAMS:
ofile : the output filename of the reverse mtu process
@RETURN:
mtu_results : mtu value
'''
def end_mtu_reverse(ofile):
mtu_results = None
try:
mtu_results = server_utils.parse_mtu(ofile)
print("mtu done")
except:
print("mtu parsing error")
raise
return mtu_results
'''
wrapper for the entire reverse mtu measurement process
and returns the json string value of the
Maximum Transmission Unit
@PARAMS:
websocket : websocket object
path :
'''
async def measure_mtu(websocket, path):
go_signal = await websocket.recv()
mtu = None
filename = "tempfiles/reverse_mode/mtu_reverse_temp"
mtu_reverse_proc = None
try:
ofile = open(filename, "w+")
mtu_reverse_proc = start_mtu_reverse(ofile)
await websocket.send("plpmtu started")
mtu_reverse_proc.wait(timeout=20)
ofile.close()
mtu = end_mtu_reverse(filename)
except:
print("plpmtu failed")
traceback.print_exc()
try:
mtu_reverse_proc.kill()
except:
pass
try:
ret_dict = {"MTU":mtu}
await websocket.send(json.dumps(ret_dict))
except:
await websocket.close()
# done