2 * Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.lispflowmapping.southbound;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MessageType;
13 * Object to hold statistics about LISP southbound events.
15 * @author Lorand Jakab
18 public class ConcurrentLispSouthboundStats {
19 public static final int MAX_LISP_TYPES = getMaxMessageTypeValue();
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 private long cacheHits = 0;
26 private long cacheMisses = 0;
28 public ConcurrentLispSouthboundStats() {
32 public synchronized void resetStats() {
33 for (int i = 0; i <= MAX_LISP_TYPES; i++) {
39 public synchronized long[] getRx() {
43 public synchronized void incrementRx(int type) {
44 this.rx[type] = incrementWithWrap(rx[type]);
47 public synchronized long[] getTx() {
51 public synchronized void incrementTx(int type) {
52 this.tx[type] = incrementWithWrap(tx[type]);
55 public synchronized long getRxUnknown() {
59 public synchronized void incrementRxUnknown() {
60 this.rxUnknown = incrementWithWrap(rxUnknown);
63 public synchronized long getTxErrors() {
67 public synchronized void incrementTxErrors() {
68 this.txErrors = incrementWithWrap(txErrors);
71 public synchronized long getCacheHits() {
75 public synchronized void incrementCacheHits() {
76 this.cacheHits = incrementWithWrap(cacheHits);
79 public synchronized long getCacheMisses() {
83 public synchronized void incrementCacheMisses() {
84 this.cacheMisses = incrementWithWrap(cacheMisses);
87 private static long incrementWithWrap(long value) {
88 return value == Long.MAX_VALUE ? 0 : value + 1;
91 // TODO move this method to the appropriate helper class if we start using MessageType in other places
92 public static synchronized int getMaxMessageTypeValue() {
94 for (MessageType mt : MessageType.values()) {
95 if (mt.getIntValue() > max) {
96 max = mt.getIntValue();