Revision 0597ba9b

View differences:

conf/peerstreamer.ini
5 5
source_name = h0_0
6 6
peer_names = h1_1 h1_1 h2_2
7 7
duration = 600
8

  
9

  
10 8
graphDefinition = data/toy.edges
11

  
12
[PSConfWrong]
13

  
14
xx = 2
conf/ping.ini
1
[pingTest]
2

  
3
testModule = ping
4
testClass = pingRandomTest
5
duration = 10
6
graphDefinition = data/toy.edges
test_code/ping.py
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 pingTest(MininetTest):
12

  
13
    def __init__(self, mininet, duration=10):
14

  
15
        super(pingTest, self).__init__(mininet, path, duration)
16

  
17

  
18
    def launchPing(self, host):
19

  
20
        idps = randint(0,100)
21
        logfile = self.prefix + host.name.split('_')[0] + \
22
            "-" + str(idps) + "_ping_$(date +%s).log"
23

  
24
        cmd = "ping " + self.destination
25
        params = {}
26
        params['>'] = logfile
27
        params['2>'] = logfile
28

  
29
        return self.bgCmd(host, True, cmd,
30
            *reduce(lambda x, y: x + y, params.items()) )
31

  
32
    def runTest(self):
33
        info("*** Launching Ping test\n")
34
        info("Data folder: "+self.prefix+"\n")
35

  
36
        for h in self.getAllHosts():
37
            self.launchPing(h)
38

  
39
        info("Waiting completion...\n")
40
        sleep(self.duration)
41
        self.killAll()
42

  
43
class pingRandomTest(pingTest):
44

  
45
    def __init__(self, mininet, name, args):
46

  
47
        duration = int(args["duration"])
48
        super(pingRandomTest, self).__init__(mininet, duration)
49
        h =  self.getHostSample(1)
50
        self.destination = self.getHostSample(1)[0].defaultIntf().ip
51
        self.setPrefix(name)
52

  
53

  
test_generic.py
14 14
        self.duration = duration
15 15
        self.prefix = ''
16 16
    
17
    def getHostSample(self,num):
18
        hosts = sample(self.net.values(),num)
17
    def getHostSample(self, num):
18
        hosts = sample(self.net.values(), num)
19 19
        return hosts[:num]
20 20

  
21
    def getAllHosts(self):
22
        return self.net.values()
23

  
21 24
    def bgCmd(self,host,force_multiple_processes,*args):
22 25
        # here it's a little workaround for tracing the resulting pid
23 26
        # it launch the new process using the mininet interface
......
53 56
        self.pendingProc.clear()
54 57

  
55 58
    def setPrefix(self, name):
56
        self.prefix = str(name) + '_' + str(self.duration) + '_' + \
57
                str(len(self.hosts)+1) + 'hosts/' 
59
        self.prefix = str(name) + '_' + str(self.duration) + '/'
58 60
        if not os.path.exists(self.prefix):
59 61
                os.makedirs(self.prefix)
60 62

  
......
65 67
                os.chmod(os.path.join(root, dir), 0777)
66 68
            for file in files:
67 69
                os.chmod(os.path.join(root, file), 0777)
68
                print "XX", file
69 70

  
wcn_simulator.py
124 124
    for i in range(1):
125 125
        c = "peerstreamer.PSHostsTest"
126 126
        info("+++++++ Round: "+str(i+1) + '\n')
127
        #test = PSRandomTest(net,duration=6,name=test_name,num_peers=2)
128 127
        test = C.className(net, testPath, C.confParams)
129 128
        test.runTest()
130 129
    net.stop()
131 130
    test.changePermissions()
132
    info("*** Done with experiment: "+test_name+"\n")
131
    info("*** Done with experiment: " + testName + "\n")

Also available in: Unified diff