Revision ed87a801

View differences:

conf/peerstreamer.ini
1
[PSConf1]
2

  
3
testModule = peerstreamer
4
testClass = PSHostsTest
5
source_name = h0_0
6
peer_names = h1_1 h1_1 h2_2
7
duration = 600
8

  
9

  
10
graphDefinition = data/toy.edges
11

  
12
[PSConfWrong]
13

  
14
xx = 2
test_code/peerstreamer.py
59 59
        self.killAll()
60 60

  
61 61
class PSHostsTest(PSTest):
62
    def __init__(self, mininet, source_name, peer_names, 
63
            duration=300, name=None):
64
        super(PSHostsTest,self).__init__(mininet, duration = duration)
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)
65 67
        self.source = mininet.get(source_name)
66
        for n in peer_names:
68
        for n in peer_names.split():
67 69
            self.hosts.append(mininet.get(n))
68 70
        self.setPrefix(name)
69 71

  
70 72
class PSRandomTest(PSTest):
71
    def __init__(self,mininet,duration=300,num_peers=5,name=None):
73
    def __init__(self, mininet, name, args):
74
        num_peers = int(args["num_peers"])
75
        duration = int(args["duration"])
72 76
        super(PSRandomTest,self).__init__(mininet,duration)
73 77
        self.hosts = self.getHostSample(num_peers)
74 78
        if len(self.hosts) > 0:
wcn_simulator.py
1 1
#!/usr/bin/env python
2 2
import sys
3
import ConfigParser
4
import inspect
3 5

  
4 6
sys.path.append('test_code')
5 7

  
6
from network_builder import *
7
from test_code import *
8

  
9 8
from os import path
10 9
from time import time
11 10

  
12

  
13 11
from parameters_parser import parameters
12
from network_builder import *
13
from test_code import *
14

  
14 15

  
15 16

  
16 17
class conf(parameters):
......
18 19
        self.checkNeededParams()
19 20
        return True
20 21

  
22
class configurationFile():
23

  
24
    mandatoryOptions = {"testModule":None
25
            , "testClass":None}
26
    confParams = {}
27
    className = None
28
    def __init__(self, fileName, stanza):
29
        # check if filename esists
30
        try:
31
            fd =  open(fileName, "r")
32
        except IOError:
33
            error("Can not open the configuration file: " + fileName\
34
                + "\n")
35
            sys.exit(1)
36
        self.parser = ConfigParser.SafeConfigParser()
37
        self.parser.read(fileName)
38

  
39
        self.testName = stanza 
40
        if stanza not in self.parser.sections():
41
            error("Can not find configuration " + stanza \
42
                    + " in file " + fileName + "\n")
43
            sys.exit(1)
44
        for o in self.mandatoryOptions:
45
            self.mandatoryOptions[o] = \
46
                self.getConfigurations(o, raiseError=True)
47

  
48
        moduleName = "test_code." + self.mandatoryOptions['testModule']
49
        if moduleName not in sys.modules:
50
            errorString = "ERROR: no " \
51
                + self.mandatoryOptions['testModule'] \
52
                + " module  has been loaded!\n"
53
            error(errorString)
54
            sys.exit(1)
55

  
56
        if self.mandatoryOptions['testClass'] not in \
57
                zip(*inspect.getmembers(sys.modules[moduleName]))[0]:
58
            errorString = "ERROR: no " \
59
                + self.mandatoryOptions['testClass'] \
60
                + " simulation class is present in "\
61
                + moduleName + "\n"
62
            error(errorString)
63
            sys.exit(1)
64

  
65
        self.className = getattr(sys.modules[moduleName],
66
            self.mandatoryOptions['testClass'])
67

  
68
        for name, value in self.parser.items(self.testName):
69
            self.confParams[name] = value
70

  
71
    def getConfigurations(self, name, raiseError=False):
72
        try:
73
            r = self.parser.get(self.testName, name)
74
        except ConfigParser.NoOptionError:
75
            if raiseError:
76
                error("No option \'" + name + "\' found!\n")
77
                sys.exit()
78
            else:
79
                return None
80
        return r
81

  
21 82
if __name__ == '__main__':
22 83
    setLogLevel('info')
23 84
    need = [
24
            ("-f", ["graphDefinition", True, "", "path of the graph definition", str]),
25
            ("-t", ["testName", True, "", "base name for test output", str])
85
            ("-f", ["configFile", True, "",
86
                "file with the available configurations", str]),
87
            ("-t", ["testName", True, "",
88
                "base name for test output", str])
26 89
           ]
27 90
    opt = [
28
            ("-d", ["drawGraph", False, False, 
29
                "draw the graph before you run the test", int])
91
            ("-d", ["drawGraph", False, False,
92
                "draw the graph before you run the test", int]),
93
            ("-g", ["graphFile", True, "",
94
                "file with the topology (overrides configuration)", str])
30 95
          ]
31 96

  
32 97
    P = conf(path.basename(__file__),need, opt)
33 98
    P.parseArgs()
34
    drawGraph = P.getParam("drawGraph")
35 99
    if P.checkCorrectness() == False:
36 100
        P.printUsage()
37 101
        sys.exit(1)
38
    net = GraphNet(P.getParam("graphDefinition"), draw = drawGraph)
102

  
103
    configFile = P.getParam("configFile")
104
    testName = P.getParam("testName")
105
    C = configurationFile(configFile, testName)
106
    #import code
107
    #code.interact(local=locals())
108
    # parse the conf file
109
    networkGraph = P.getParam("graphFile")
110
    if networkGraph == "":
111
        networkGraph = C.getConfigurations("graphDefinition")
112
        if networkGraph == None:
113
            error("No graph topology specified in config file or command " + \
114
                "line!\n")
115
            sys.exit(1)
116
    drawGraph = P.getParam("drawGraph")
117

  
118
    net = GraphNet(networkGraph, draw = drawGraph)
39 119
    net.start()
40 120
    net.enableForwarding()
41 121
    net.setShortestRoutes()
42 122
#    CLI(net)
43
    test_name = P.getParam("testName")+"_"+str(int(time()))
123
    testPath = testName+"_"+str(int(time()))
44 124
    for i in range(1):
125
        c = "peerstreamer.PSHostsTest"
45 126
        info("+++++++ Round: "+str(i+1) + '\n')
46 127
        #test = PSRandomTest(net,duration=6,name=test_name,num_peers=2)
47
        test = peerstreamer.PSHostsTest(net, 'h0_0', ['h1_1','h1_1','h2_2'],
48
                duration = 600, name = test_name)
128
        test = C.className(net, testPath, C.confParams)
49 129
        test.runTest()
50
      #  sleep(60)
51 130
    net.stop()
52 131
    test.changePermissions()
53 132
    info("*** Done with experiment: "+test_name+"\n")

Also available in: Unified diff