wcn_emulator / test_code / peerstreamer.py @ c09f8d98
History | View | Annotate | Download (2.78 KB)
1 |
|
---|---|
2 |
import sys |
3 |
sys.path.append('../')
|
4 |
from network_builder import * |
5 |
from os import kill, path, makedirs |
6 |
from matplotlib.pyplot import ion |
7 |
from random import sample, randint |
8 |
|
9 |
from test_generic import * |
10 |
|
11 |
class PSTest(MininetTest): |
12 |
def __init__(self,mininet,duration=300): |
13 |
super(PSTest,self).__init__(mininet) |
14 |
self.source = None |
15 |
self.hosts = []
|
16 |
self.duration = duration
|
17 |
self.prefix = '' |
18 |
|
19 |
def setPrefix(self,name): |
20 |
self.prefix = str(name)+'_'+str(self.duration)+'_'+str(len(self.hosts)+1)+'hosts/' |
21 |
if not path.exists(self.prefix): |
22 |
makedirs(self.prefix)
|
23 |
|
24 |
def launchPS(self,host,params,stdout,stderr): |
25 |
cmd = "./streamer"
|
26 |
params['-c'] = '38' |
27 |
# params['-M'] = '5'
|
28 |
# params['-O'] = '3'
|
29 |
params['--chunk_log'] = '' |
30 |
params['>'] = stdout
|
31 |
params['2>'] = stderr
|
32 |
return self.bgCmd(host,True,cmd,*reduce(lambda x, y: x + y, params.items())) |
33 |
|
34 |
def launchPeer(self,host,source,source_port=7000): |
35 |
idps = randint(0,100) |
36 |
logfile = self.prefix+host.name.split('_')[0]+"-"+str(idps)+"_peerstreamer_normal_$(date +%s).log" |
37 |
params = {} |
38 |
params['-i'] = source.defaultIntf().ip
|
39 |
params['-p'] = str(source_port) |
40 |
params['-P'] = str(randint(4000,8000)) |
41 |
return self.launchPS(host,params,'/dev/null',logfile) |
42 |
|
43 |
def launchSource(self,host,chunk_mult=1,source_port=7000): |
44 |
idps = randint(0,100) |
45 |
video_file = "bunny.ts,loop=1"
|
46 |
logfile = self.prefix+host.name.split('_')[0]+"-"+str(idps)+"_source_normal_$(date +%s).log" |
47 |
params = {} |
48 |
params['-I'] = host.defaultIntf().name
|
49 |
params['-P'] = str(source_port) |
50 |
params['-f'] = video_file
|
51 |
params['-m'] = str(chunk_mult) |
52 |
return self.launchPS(host,params,'/dev/null',logfile) |
53 |
|
54 |
def runTest(self): |
55 |
info("*** Launching PeerStreamer test\n")
|
56 |
info("Data folder: "+self.prefix+"\n") |
57 |
if self.source: |
58 |
self.launchSource(self.source) |
59 |
|
60 |
for h in self.hosts: |
61 |
self.launchPeer(h,self.source) |
62 |
info("Waiting completion...\n")
|
63 |
sleep(self.duration)
|
64 |
|
65 |
self.killAll()
|
66 |
|
67 |
class PSHostsTest(PSTest): |
68 |
def __init__(self,mininet,source_name,peer_names,duration=300,name=None): |
69 |
super(PSHostsTest,self).__init__(mininet,duration=duration) |
70 |
self.source = mininet.get(source_name)
|
71 |
for n in peer_names: |
72 |
self.hosts.append(mininet.get(n))
|
73 |
self.setPrefix(name)
|
74 |
|
75 |
class PSRandomTest(PSTest): |
76 |
def __init__(self,mininet,duration=300,num_peers=5,name=None): |
77 |
super(PSRandomTest,self).__init__(mininet,duration) |
78 |
self.hosts = self.getHostSample(num_peers) |
79 |
if len(self.hosts) > 0: |
80 |
self.source = self.hosts.pop() |
81 |
self.setPrefix(name)
|
82 |
|
83 |
|