Reporting test details for all tests
[samplevnf.git] / VNFs / DPPD-PROX / helper-scripts / demo-scripts / tx_rate.py
1 #!/bin/env python2.7
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 prox import *
20 from decimal import *
21 from time import *
22
23 class data_point:
24     value = 0;
25     tsc = 0;
26     def __init__(self, value, tsc):
27         self.value = value;
28         self.tsc = tsc;
29
30 def measure_tx(prox_instance, port_id):
31     port_tx_pkt = "port(" + str(port_id) + ").tx.packets"
32     port_tsc = "port(" + str(port_id) + ").tsc";
33     cmd = "stats " + port_tx_pkt + "," + port_tsc;
34     reply = prox_instance.send(cmd).recv().split(",");
35
36     return data_point(int(reply[0]), int(reply[1]));
37
38 def get_rate(first, second, hz):
39     tsc_diff = second.tsc - first.tsc;
40     value_diff = second.value - first.value;
41
42     return int(Decimal(value_diff * hz) / tsc_diff)
43
44 # make sure that prox has been started with the -t parameter
45 prox_instance = prox("127.0.0.1")
46 print "Connected to prox"
47
48 hz = int(prox_instance.send("stats hz").recv());
49
50 print "System is running at " + str(hz) + " Hz"
51
52 print "Showing TX pps on port 0"
53
54 update_interval = 0.1
55
56 print "Requesting new data every " + str(update_interval) + "s"
57
58 measure = measure_tx(prox_instance, 0);
59 while (True):
60     sleep(update_interval)
61     measure2 = measure_tx(prox_instance, 0);
62
63     # since PROX takes measurements at a configured rate (through
64     # update interval command or throw -r command line parameter), it
65     # might be possible that two consecutive measurements report the
66     # same. To get updates at a frequency higher than 1 Hz,
67     # reconfigure prox as mentioned above.
68
69     if (measure.tsc == measure2.tsc):
70         continue;
71
72     print get_rate(measure, measure2, hz);
73
74     measure = measure2;