Statistics
| Branch: | Revision:

nepatest_popbabel / test_code / validation.py @ cafb67a9

History | View | Annotate | Download (3.41 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

    
10
from test_generic import *
11

    
12
class ValidationTest(MininetTest):
13

    
14
    def __init__(self, mininet, name, args):
15
        duration = int(args["duration"])
16
        super(ValidationTest, self).__init__(mininet, None, duration)
17
        self.setPrefix(name)
18

    
19
    def launchBabel(self, host):
20

    
21
        hostname=host.name.split('_')[0]
22
        idps = randint(0,100)
23

    
24
        logfile = self.prefix + "log" + hostname + ".log"
25
        exportCentFolder = self.prefix + hostname
26
        topofile = self.prefix + "topo" + hostname + ".json"
27
        neighfile = self.prefix + "neigh" + hostname + ".json"
28

    
29
        iflist=host.intfList()
30
        intf_list = ' '.join(["\"" + i.name + "\"" for i in iflist])
31

    
32
        cmd = "babeld "+ intf_list
33
        params = {}
34
        params['-h'] = "1"
35
        params['-H'] = "1"
36
        params['-d'] = "0"
37
        params['-I']= self.prefix+hostname+"_"+str(idps)+"pf.pid"
38
        params['-L'] = logfile
39
        params['-e'] = exportCentFolder+"_cdump.csv"
40
        params['-n'] = topofile
41
        params['-N'] = neighfile
42
        params['-w'] = " "
43
        info("### Launching babel on "+hostname+" ###\n")
44
        return self.bgCmd(host, True, cmd,
45
            *reduce(lambda x, y: x + y, params.items()) )
46

    
47
    def dumpRoutingTable(self, host):
48
        hostname = host.name.split('_')[0]
49
        idps = randint(0,100)
50
        logfile = self.prefix + hostname + \
51
            "-iprtdump" + str(idps) + ".log"
52

    
53
        cmd = "ip route show"
54
        params = {}
55
        #params['table'] = "254"
56
        params['>']=logfile
57
        info("ip command on main routing table for host"+hostname+"\n")
58
        return self.bgCmd(host, True, cmd,
59
            *reduce(lambda x, y: x + y, params.items()) )
60

    
61
    def dumpRoutingTable2(self, host):
62

    
63
        hostname=host.name.split('_')[0]
64
        idps = randint(0,100)
65
        logfile = self.prefix + hostname + \
66
            "-route_rtdump" + str(idps) + ".log"
67
        info("Dumping routing table of host: "+hostname+"via route\n")
68

    
69
        cmd = "route"
70
        params = {}
71
        params['-n'] = ""
72
        params['>']=logfile
73
        info("\nroute command on main routing table for host"+hostname+"\n")
74
        return self.bgCmd(host, True, cmd,
75
            *reduce(lambda x, y: x + y, params.items()) )
76

    
77
    def dumpRoutingTable3(self, host):
78

    
79
        hostname=host.name.split('_')[0]
80
        idps = randint(0,100)
81
        logfile = self.prefix + hostname + \
82
            "-PYroute_rtdump" + str(idps) + ".log"
83
        info("Dumping routing table of host: "+hostname+"via PYroute\n")
84

    
85
        cmd = "python ./scripts/pyroutescript.py "+hostname
86
        params = {}
87
        params['>']=logfile
88
        info("\nPYroute script run on host"+hostname+"\n")
89
        return self.bgCmd(host, True, cmd,
90
            *reduce(lambda x, y: x + y, params.items()) )
91

    
92
    def runTest(self):
93
        info("*** Launching Validation test\n")
94
        info("Data folder: "+self.prefix+"\n")
95

    
96
        for h in self.getAllHosts():
97
            self.launchBabel(h)
98
        for pid in self.pendingProc:
99
                self.sendSig(pid, sig=signal.SIGUSR1)
100

    
101
        info("Waiting completion...\n")
102
        #self.wait(self.duration, log_resources={'net': 'netusage.csv'})
103
        self.wait(self.duration)
104
        self.killAll()
105
        #sleep(1)
106
        #self.killAll(sig=signal.SIGKILL)