code review comments and PROX commit ID
[samplevnf.git] / VNFs / DPPD-PROX / helper-scripts / dpi / dpi2.py
1 #!/bin/env python
2
3 ##
4 ## Copyright (c) 2010-2017 Intel Corporation
5 ##
6 ## Licensed under the Apache License, Version 2.0 (the "License");
7 ## you may not use this file except in compliance with the License.
8 ## You may obtain a copy of the License at
9 ##
10 ##     http://www.apache.org/licenses/LICENSE-2.0
11 ##
12 ## Unless required by applicable law or agreed to in writing, software
13 ## distributed under the License is distributed on an "AS IS" BASIS,
14 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 ## See the License for the specific language governing permissions and
16 ## limitations under the License.
17 ##
18
19 from testerset import *
20 from proxdpisut import *
21 from statsconsfile import *
22 from time import sleep
23 from time import time
24 from decimal import *
25 import copy
26 from os import system
27 import socket
28 from itertools import chain
29 from math import *
30 from csvwriter import *
31 from csvreader import *
32 from config import *
33 from progress import *
34 from resultprocessor import *
35
36 def runTest(coreCount, testParam):
37     print "Running test with following parameters:"
38     print testParam.toString();
39
40
41     testers = testerSet(config._test_systems, config._max_port_rate, testParam);
42
43     ret = TestResult(testers.getCount());
44     thresh = testParam.getConnections() * config._threshold;
45     converged = False;
46
47     sut = ProxDpiSut(config._sut, coreCount);
48
49     testers.startFork();
50     sut.startFork();
51     testers.startJoin();
52     sut.startJoin();
53     testers.wait_links_up();
54     sut.startAllCores();
55     sut.waitCmdFinished();
56     testers.start_cores();
57
58     ret.addTimeTS(testers.getTsc());
59     ret.addTimeSUT(sut.getTsc());
60
61     print "Running until convergence (%s connections)" % str(thresh)
62     p = Progress(thresh, ["connections", "setup rate", "reTX"], False);
63     while (not converged):
64         sleep(config._interCheckDuration)
65         testers.update_stats();
66
67         tot = testers.get_total_connections();
68         tot_retx = testers.get_total_retx();
69         rates = testers.get_rates();
70         cur_setup_rate = testers.get_setup_rate();
71         ierrors = testers.getIerrors();
72         converged = tot >= thresh;
73
74         if (not converged and not testers.conditionsGood()):
75             print "conditions are bad: " + testers.getReason();
76             sut.forceQuit();
77             sut.killProx();
78             testers.killProx();
79             return None;
80
81         if (sut.getIerrors() != 0):
82             testers.killProx();
83             print "Sending quit"
84             try:
85                 sut.forceQuit();
86             except:
87                 print "Sending quit failed"
88             sut.killProx();
89             return None;
90
91         if (config._debug):
92             p.setProgress(tot, [tot, cur_setup_rate, tot_retx]);
93             print p.toString();
94
95     skipTime = config._skipTime
96     print "Connection threshold reached, waiting for " + str(skipTime) + "s, conditions checked = " + str(config._checkConditions)
97     while (skipTime > 0):
98         skipTime -= config._interCheckDuration
99         sleep(config._interCheckDuration)
100         testers.update_stats();
101         if (config._checkConditions and not testers.conditionsGood()):
102             print "conditions are bad: " + testers.getReason();
103             sut.forceQuit();
104             sut.killProx();
105             testers.killProx();
106             return False, [];
107
108     ret.addTimeTS(testers.getTsc());
109     ret.addTimeSUT(sut.getTsc());
110
111     testers.tx_rate_meassurement();
112
113     testLength = config._testLength
114     print "Waiting final " + str(testLength) + "s"
115     while (testLength > 0):
116         testLength -= config._interCheckDuration
117         testers.update_stats();
118         if (not testers.conditionsGood()):
119             print "conditions are bad: " + testers.getReason();
120             sut.forceQuit();
121             sut.killProx();
122             testers.killProx();
123             return None;
124
125         if (sut.getIerrors() != 0):
126             testers.killProx();
127             print "Sending quit"
128             try:
129                 sut.forceQuit();
130             except:
131                 print "Sending quit failed"
132             sut.killProx();
133             return None;
134
135         sleep(config._interCheckDuration)
136
137     rates = testers.tx_rate_meassurement();
138     ret.addTimeTS(testers.getTsc());
139     ret.addTimeSUT(sut.getTsc());
140
141     print "Quiting Prox on SUT"
142     # make sure stats are flushed
143     sut.quitProx();
144     print "Quiting Prox on test system(s)"
145     testers.quitProx()
146
147     ret.rates = rates
148
149     sutStatsDump = "stats_dump_sut"
150     tsStatsDumpBaseName = "stats_dump_ts"
151
152     sut.scpStatsDump(sutStatsDump);
153     tsStatsDump = testers.scpStatsDump(tsStatsDumpBaseName);
154
155     ret.setTSStatsDump(tsStatsDump);
156     ret.setSUTStatsDump(sutStatsDump);
157     return ret
158
159 def meassurePerf(coreCount, maxSetupRate, total_connections, ss_hi):
160     iterationCount = 0;
161     accuracy = 10**config._accuracy
162     ss_lo = 1
163     ss_hi = int(round(ss_hi * accuracy, 0))
164     success = True;
165
166     downrate = float(0)
167     highest_ss = 0
168     iterationOverride = [ss_hi, ss_lo];
169     while (ss_lo <= ss_hi):
170         if (iterationCount < len(iterationOverride)):
171             ss = iterationOverride[iterationCount]
172         else:
173             ss = (ss_lo + ss_hi)/2;
174
175         testParam = TestParameters(maxSetupRate, total_connections, float(ss)/accuracy);
176
177         result = runTest(coreCount, testParam);
178
179         if (result is None):
180             success = False
181         else:
182             rp = ResultProcessor(result)
183             rp.process();
184             success = rp.percentHandled() > 0.99999
185
186         print "test result = " + str(success)
187         if (success):
188             ss_lo = ss + 1;
189             highest_ss = max(highest_ss, ss);
190             print result.rates
191             downrate = sum(result.rates)/len(result.rates)
192         else:
193             ss_hi = ss - 1;
194         iterationCount += 1
195
196     return downrate, float(highest_ss)/accuracy
197
198 config = Config();
199 config.parse(sys.argv[0], sys.argv[1:])
200
201 err = config.getErrorTestTwo();
202 if (err is not None):
203     print "Invalid configuration: " + err;
204     exit(-1);
205 else:
206     print config.toString()
207
208 infileFields = []
209 infileFields += [("msr", "int")]
210 infileFields += [("conn", "int")]
211 infileFields += [("ss", "Decimal")]
212 infileFields += [("bw", "Decimal")]
213
214 infile = CsvReader(infileFields);
215 infile.open(config.getInputFileName())
216 inputs = infile.readAll()
217 infile.close();
218
219 summary = CsvWriter();
220 summary.open(config._output_file_name);
221
222 print "Will test up SUT config with " + str(config._dpiCoreList) + " DPI cores"
223
224 for a in inputs:
225     for coreCount in config._dpiCoreList:
226         downrate, ss = meassurePerf(coreCount, a["msr"], a["conn"], a["ss"]);
227         summary.write([coreCount, a["msr"], a["conn"], ss, downrate]);
228
229 summary.close()