summaryrefslogtreecommitdiffstats
path: root/VNFs/DPPD-PROX/helper-scripts/dpi/testerset.py
blob: fe3dce72a98decbd82345206589d02ebc3a2c1c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/bin/env python

##
## Copyright (c) 2010-2017 Intel Corporation
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
##     http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##

from proxdpitester import *

class testerSet:
    def __init__(self, test_systems, maxRate, testParam):
        self._test_systems = [];
        self._reason = ""
        self._maxRate = maxRate

        testParamPerSystem = testParam.getPerSystem(len(test_systems));

        for i in range(len(test_systems)):
            ts = test_systems[i];
            to_add = ProxDpiTester(ts, testParamPerSystem, i);
            self.add_test_system(to_add);

    def getCount(self):
        return len(self._test_systems);

    def add_test_system(self, test_system):
        self._test_systems.append(test_system);

    def startFork(self):
        print "Starting test systems:"
        for ts in self._test_systems:
            print "\t" + str(ts.getIP())
            ts.startFork();

    def startJoin(self):
        for ts in self._test_systems:
            elapsed = ts.startJoin();
            if (elapsed == None):
                print "Failed to start on " + str(ts.getIP())
            else:
                print "Started on " + str(ts.getIP())
        sleep(1);

    def startForkJoin(self):
        self.startFork();
        self.startJoin();

    def update_stats(self):
        for ts in self._test_systems:
            ts.update_stats();

    def wait_links_up(self):
        for ts in self._test_systems:
            ts.waitAllLinksUp();
        sleep(1);

    def start_cores(self):
        for ts in self._test_systems:
            ts.start_all_ld();
            ts.waitCmdFinished();
        for ts in self._test_systems:
            ts.start_all_workers();
        for ts in self._test_systems:
            ts.waitCmdFinished();

    def stop_cores(self):
        for ts in self._test_systems:
            ts.stop_all_workers();
            ts.stop_all_ld();

        for ts in self._test_systems:
            ts.waitCmdFinished();

    def getTsc(self):
        ret = []
        for ts in self._test_systems:
            ret += [ts.getTsc()]
        return ret;

    def get_setup_rate(self):
        total = 0;
        for ts in self._test_systems:
            total += ts.getCurrentSetupRate();
        return total

    def get_total_connections(self):
        total = 0;
        for ts in self._test_systems:
            ts_tot_conn = ts.get_total_connections();
            total += ts_tot_conn

        return total;

    def get_total_retx(self):
        total = 0;
        for ts in self._test_systems:
            total += ts.get_total_retx();
        return total;

    def getIerrors(self):
        total = 0;
        for ts in self._test_systems:
            total += ts.getIerrorsCached();
        return total;

    def get_rates(self):
        rates = [];
        for ts in self._test_systems:
            rates += ts.get_rates_client_ports();
        return rates;

    def tx_rate_meassurement(self):
        rates = []
        for ts in self._test_systems:
            rates += ts.tx_rate_meassurement();
        return rates;

    def scpStatsDump(self, dst):
        ret = []
        for i in range(len(self._test_systems)):
            dstFileName = dst + str(i);
            ret.append(dstFileName);
            self._test_systems[i].scpStatsDump(dstFileName)
        return ret;

    def conditionsGood(self):
        tot_retx = self.get_total_retx();
        rates = self.get_rates();
        ierrors = self.getIerrors();

        if (tot_retx > 100):
            self._reason = "Too many reTX (" + str(tot_retx) + ")"
            return False;
        if (ierrors > 0):
            self._reason = "Too many ierrors (" + str(ierrors) + ")"
            return False;
        for i in range(0, len(rates)):
            if (rates[i] > self._maxRate):
                self._setReason(i, rates)
                return False;
        return True;

    def _setReason(self, port, rates):
        portStr = str(port);
        rateStr = str(rates[port])
        maxRateStr = str(self._maxRate);
        allRatesStr = str(rates);

        fmt = "Rate on port %s = %s > %s, rate on all = %s"
        self._reason = fmt % (portStr, rateStr, maxRateStr, allRatesStr)

    def getReason(self):
        return self._reason;

    def quitProx(self):
        for ts in self._test_systems:
            ts.quitProx();

    def killProx(self):
        for ts in self._test_systems:
            ts.stop_all_workers();
        for ts in self._test_systems:
            ts.stop_all_ld();
        for ts in self._test_systems:
            ts.killProx();