Added use case "Forwaring Rate At Maximum Offered Load"
[samplevnf.git] / VNFs / DPPD-PROX / helper-scripts / dpi / tsstatsconsfile.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 statsconsfile import *
20 from decimal import *
21
22 class TSStatsConsFile:
23     def __init__(self, fileName, offset):
24         self.offset = offset;
25         self.statsConsFile = StatsConsFile(fileName)
26
27     def readNext(self):
28         entry = self._readNextEntry();
29         if (entry is None):
30             return None;
31
32         while (entry is not None and entry[-1] <= 0):
33             entry = self._readNextEntry();
34
35         return entry;
36
37     def _readNextEntry(self):
38         entry = self.statsConsFile.readNext();
39         if (entry is None):
40             return None;
41
42         rx = 0;
43         tx = 0;
44         active = 0;
45         created = 0;
46         last_tsc = 0;
47         for i in range(0, len(entry), 2):
48             active += entry[i][2]
49             created += entry[i][3]
50             rx += entry[i][4]
51             tx += entry[i][5]
52             last_tsc = entry[i][6]
53
54         last_tsc -= self.offset;
55         last_tsc = Decimal(last_tsc) / self.statsConsFile.getHz();
56
57         return [active, created, rx, tx, last_tsc];
58
59     def close(self):
60         self.statsConsFile.close();