Statistics
| Branch: | Revision:

wcn_emulator / test_code / peerstreamer.py @ ed87a801

History | View | Annotate | Download (2.7 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, path, duration)
14
        self.source = None
15
        self.hosts = []
16

    
17

    
18
    def launchPS(self,host,params,stdout,stderr):
19
        cmd = "./streamer"
20
        params['-c'] = '38'
21
#        params['-M'] = '5'
22
#        params['-O'] = '3'
23
        params['--chunk_log'] = ''
24
        params['>'] = stdout
25
        params['2>'] = stderr
26
        return self.bgCmd(host,True,cmd,*reduce(lambda x, y: x + y, params.items()))
27

    
28
    def launchPeer(self,host,source,source_port=7000):
29
        idps = randint(0,100)
30
        logfile = self.prefix+host.name.split('_')[0]+"-"+str(idps)+"_peerstreamer_normal_$(date +%s).log"
31
        params = {}
32
        params['-i'] = source.defaultIntf().ip
33
        params['-p'] = str(source_port)
34
        params['-P'] = str(randint(4000,8000))
35
        return self.launchPS(host,params,'/dev/null',logfile)
36

    
37
    def launchSource(self,host,chunk_mult=1,source_port=7000):
38
        idps = randint(0,100)
39
        video_file = "bunny.ts,loop=1"
40
        logfile = self.prefix+host.name.split('_')[0]+"-"+str(idps)+"_source_normal_$(date +%s).log"
41
        params = {}
42
        params['-I'] = host.defaultIntf().name
43
        params['-P'] = str(source_port)
44
        params['-f'] = video_file
45
        params['-m'] = str(chunk_mult)
46
        return self.launchPS(host,params,'/dev/null',logfile)
47

    
48
    def runTest(self):
49
        info("*** Launching PeerStreamer test\n")
50
        info("Data folder: "+self.prefix+"\n")
51
        if self.source:
52
            self.launchSource(self.source)
53

    
54
        for h in self.hosts:
55
            self.launchPeer(h,self.source)
56
        info("Waiting completion...\n")
57
        sleep(self.duration)
58

    
59
        self.killAll()
60

    
61
class PSHostsTest(PSTest):
62
    def __init__(self, mininet, name, args):
63
        source_name = args["source_name"]
64
        peer_names = args["peer_names"]
65
        duration = int(args["duration"])
66
        super(PSHostsTest, self).__init__(mininet, duration = duration)
67
        self.source = mininet.get(source_name)
68
        for n in peer_names.split():
69
            self.hosts.append(mininet.get(n))
70
        self.setPrefix(name)
71

    
72
class PSRandomTest(PSTest):
73
    def __init__(self, mininet, name, args):
74
        num_peers = int(args["num_peers"])
75
        duration = int(args["duration"])
76
        super(PSRandomTest,self).__init__(mininet,duration)
77
        self.hosts = self.getHostSample(num_peers)
78
        if len(self.hosts) > 0:
79
            self.source = self.hosts.pop()
80
        self.setPrefix(name)
81

    
82