-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathClient.py
More file actions
67 lines (57 loc) · 1.65 KB
/
Client.py
File metadata and controls
67 lines (57 loc) · 1.65 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
56
57
58
59
60
61
62
63
64
65
66
67
import subprocess
class Client:
""" A network testing client built on iperf3 that can initiate
multiple TCP or UDP tests with multiple servers. """
def __init__(self, host, addr):
self.host = host
self.addr = addr
self.targets = []
self.test = ""
# UDP specific options
self.bandwidth = ""
self.packetlen = ""
def setTarget(self,addr,port):
self.targets.append((addr,port))
def setType(self, test):
self.test = test.lower()
def setUdpOptions(self, bandwidth, packetlen=""):
self.bandwidth = bandwidth
self.packetlen = packetlen
def setTcpOptions(self, packetlen=""):
self.packetlen = packetlen
def run(self, runtime):
procs = []
for target in self.targets:
command = [ 'ssh', '-n', self.host, 'iperf3', '-c', target[0], '-p', target[1] ]
# logstring = '-J > ' + self.host + '.json\"'
command.append('-i')
command.append('0')
if self.test == 'udp':
command.append('-t')
command.append(str(runtime))
command.append('-u')
command.append('-b')
command.append(str(self.bandwidth))
if self.packetlen:
command.append('-l')
command.append(self.packetlen)
else: ## tcp
command.append('-t')
command.append(str(runtime + 2))
command.append('-O')
command.append(str(2))
if self.packetlen:
command.append('-M')
command.append(self.packetlen)
command.append('-C')
command.append('cubic')
command.append('-l')
command.append('1400')
# command.append('\"')
# command.append(logstring)
# print " ".join(map(str, command))
p = subprocess.Popen(command)
procs.append(p)
# wait for all subprocesses to finish
for p in procs:
p.wait()