1
2
3
4
5
6
7
8 package org.opendaylight.lispflowmapping.southbound;
9
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MessageType;
11
12
13
14
15
16
17
18 public class LispSouthboundStats {
19 public final static int MAX_LISP_TYPES = getMaxMessageTypeValue();
20
21 private long rx[] = new long[MAX_LISP_TYPES + 1];
22 private long tx[] = new long[MAX_LISP_TYPES + 1];
23 private long rxUnknown = 0;
24 private long txErrors = 0;
25
26 public LispSouthboundStats() {
27 resetStats();
28 }
29
30 public void resetStats() {
31 for (int i = 0; i <= MAX_LISP_TYPES; i++) {
32 rx[i] = 0;
33 tx[i] = 0;
34 }
35 }
36
37 public long[] getRx() {
38 return rx;
39 }
40
41 public void incrementRx(int type) {
42 this.rx[type] = incrementWithWrap(rx[type]);
43 }
44
45 public long[] getTx() {
46 return tx;
47 }
48
49 public void incrementTx(int type) {
50 this.tx[type] = incrementWithWrap(tx[type]);
51 }
52
53 public long getRxUnknown() {
54 return rxUnknown;
55 }
56
57 public void incrementRxUnknown() {
58 this.rxUnknown = incrementWithWrap(rxUnknown);
59 }
60
61 public long getTxErrors() {
62 return txErrors;
63 }
64
65 public void incrementTxErrors() {
66 this.txErrors = incrementWithWrap(txErrors);
67 }
68
69 private static long incrementWithWrap(long value) {
70 if (value == Long.MAX_VALUE) {
71 return 0;
72 } else {
73 return value + 1;
74 }
75 }
76
77
78 public static int getMaxMessageTypeValue() {
79 int max = 0;
80 for (MessageType mt : MessageType.values()) {
81 if (mt.getIntValue() > max) {
82 max = mt.getIntValue();
83 }
84 }
85 return max;
86 }
87 }