--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.lispflowmapping.southbound;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MessageType;
+
+/**
+ * Object to hold statistics about LISP southbound events.
+ *
+ * @author Lorand Jakab
+ *
+ */
+public class ConcurrentLispSouthboundStats {
+ public static final int MAX_LISP_TYPES = getMaxMessageTypeValue();
+
+ private long[] rx = new long[MAX_LISP_TYPES + 1];
+ private long[] tx = new long[MAX_LISP_TYPES + 1];
+ private long rxUnknown = 0;
+ private long txErrors = 0;
+ private long cacheHits = 0;
+ private long cacheMisses = 0;
+
+ public ConcurrentLispSouthboundStats() {
+ resetStats();
+ }
+
+ public synchronized void resetStats() {
+ for (int i = 0; i <= MAX_LISP_TYPES; i++) {
+ rx[i] = 0;
+ tx[i] = 0;
+ }
+ }
+
+ public synchronized long[] getRx() {
+ return rx;
+ }
+
+ public synchronized void incrementRx(int type) {
+ this.rx[type] = incrementWithWrap(rx[type]);
+ }
+
+ public synchronized long[] getTx() {
+ return tx;
+ }
+
+ public synchronized void incrementTx(int type) {
+ this.tx[type] = incrementWithWrap(tx[type]);
+ }
+
+ public synchronized long getRxUnknown() {
+ return rxUnknown;
+ }
+
+ public synchronized void incrementRxUnknown() {
+ this.rxUnknown = incrementWithWrap(rxUnknown);
+ }
+
+ public synchronized long getTxErrors() {
+ return txErrors;
+ }
+
+ public synchronized void incrementTxErrors() {
+ this.txErrors = incrementWithWrap(txErrors);
+ }
+
+ public synchronized long getCacheHits() {
+ return cacheHits;
+ }
+
+ public synchronized void incrementCacheHits() {
+ this.cacheHits = incrementWithWrap(cacheHits);
+ }
+
+ public synchronized long getCacheMisses() {
+ return cacheMisses;
+ }
+
+ public synchronized void incrementCacheMisses() {
+ this.cacheMisses = incrementWithWrap(cacheMisses);
+ }
+
+ private static synchronized long incrementWithWrap(long value) {
+ if (value == Long.MAX_VALUE) {
+ return 0;
+ } else {
+ return value + 1;
+ }
+ }
+
+ // TODO move this method to the appropriate helper class if we start using MessageType in other places
+ public static synchronized int getMaxMessageTypeValue() {
+ int max = 0;
+ for (MessageType mt : MessageType.values()) {
+ if (mt.getIntValue() > max) {
+ max = mt.getIntValue();
+ }
+ }
+ return max;
+ }
+}
private Class channelType;
private volatile int xtrPort = LispMessage.XTR_PORT_NUM;
private volatile boolean listenOnXtrPort = false;
- private LispSouthboundStats statistics = new LispSouthboundStats();
+ private ConcurrentLispSouthboundStats statistics = new ConcurrentLispSouthboundStats();
private Bootstrap bootstrap = new Bootstrap();
private Bootstrap xtrBootstrap = new Bootstrap();
private ThreadFactory threadFactory = new DefaultThreadFactory("lisp-sb");
return null;
}
- public LispSouthboundStats getStats() {
+ public ConcurrentLispSouthboundStats getStats() {
return statistics;
}
RpcResultBuilder<GetStatsOutput> rpcResultBuilder;
- LispSouthboundStats stats = lispSbPlugin.getStats();
+ ConcurrentLispSouthboundStats stats = lispSbPlugin.getStats();
if (stats == null) {
rpcResultBuilder = RpcResultBuilder.<GetStatsOutput>failed()
public Future<RpcResult<Void>> resetStats() {
LOG.trace("resetStats called!!");
- LispSouthboundStats stats = lispSbPlugin.getStats();
+ ConcurrentLispSouthboundStats stats = lispSbPlugin.getStats();
if (stats == null) {
return Futures.immediateFuture(RpcResultBuilder.<Void>failed()
}
}
- private static GetStatsOutput createGetStatsOutput(LispSouthboundStats stats) {
+ private static GetStatsOutput createGetStatsOutput(ConcurrentLispSouthboundStats stats) {
long[] rxStats = stats.getRx();
long[] txStats = stats.getTx();
cmsb.setTxErrors(stats.getTxErrors());
List<ControlMessage> messages = new ArrayList<ControlMessage>();
- for (int i = 0; i <= LispSouthboundStats.MAX_LISP_TYPES; i++) {
+ for (int i = 0; i <= ConcurrentLispSouthboundStats.MAX_LISP_TYPES; i++) {
if (MessageType.forValue(i) == null) {
continue;
}
import org.opendaylight.lispflowmapping.lisp.util.LispAddressStringifier;
import org.opendaylight.lispflowmapping.lisp.util.MapRequestUtil;
import org.opendaylight.lispflowmapping.mapcache.SimpleMapCache;
+import org.opendaylight.lispflowmapping.southbound.ConcurrentLispSouthboundStats;
import org.opendaylight.lispflowmapping.southbound.LispSouthboundPlugin;
-import org.opendaylight.lispflowmapping.southbound.LispSouthboundStats;
import org.opendaylight.lispflowmapping.southbound.lisp.cache.MapRegisterCache;
import org.opendaylight.lispflowmapping.southbound.lisp.cache.MapRegisterPartialDeserializer;
import org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException;
//TODO: think whether this field can be accessed through mappingservice or some other configuration parameter
private boolean authenticationEnabled = true;
private final LispSouthboundPlugin lispSbPlugin;
- private LispSouthboundStats lispSbStats = null;
+ private ConcurrentLispSouthboundStats lispSbStats = null;
private SimpleMapCache smc;
private AuthenticationKeyDataListener authenticationKeyDataListener;
private DataStoreBackEnd dsbe;
private void handleStats(int type) {
if (lispSbStats != null) {
- if (type <= LispSouthboundStats.MAX_LISP_TYPES) {
+ if (type <= ConcurrentLispSouthboundStats.MAX_LISP_TYPES) {
lispSbStats.incrementRx(type);
} else {
lispSbStats.incrementRxUnknown();
this.dsbe = dsbe;
}
- public void setStats(LispSouthboundStats lispSbStats) {
+ public void setStats(ConcurrentLispSouthboundStats lispSbStats) {
this.lispSbStats = lispSbStats;
}
*/
@Test
public void getStatsTest() throws ExecutionException, InterruptedException {
- final LispSouthboundStats stats = new LispSouthboundStats();
+ final ConcurrentLispSouthboundStats stats = new ConcurrentLispSouthboundStats();
incrementAll(stats);
Mockito.when(lispSouthboundPlugin.getStats()).thenReturn(stats);
*/
@Test
public void resetStatsTest() throws ExecutionException, InterruptedException {
- final LispSouthboundStats stats = new LispSouthboundStats();
+ final ConcurrentLispSouthboundStats stats = new ConcurrentLispSouthboundStats();
incrementAll(stats);
Mockito.when(lispSouthboundPlugin.getStats()).thenReturn(stats);
.setMappingRecordItem(Lists.newArrayList(getDefaultMappingRecordItem()));
}
- private static void incrementAll(LispSouthboundStats stats) {
+ private static void incrementAll(ConcurrentLispSouthboundStats stats) {
for (MessageType type : MessageType.values()) {
stats.incrementRx(type.getIntValue());
}
import org.opendaylight.lispflowmapping.lisp.util.MapNotifyBuilderHelper;
import org.opendaylight.lispflowmapping.lisp.util.MaskUtil;
import org.opendaylight.lispflowmapping.mapcache.SimpleMapCache;
+import org.opendaylight.lispflowmapping.southbound.ConcurrentLispSouthboundStats;
import org.opendaylight.lispflowmapping.southbound.LispSouthboundPlugin;
-import org.opendaylight.lispflowmapping.southbound.LispSouthboundStats;
import org.opendaylight.lispflowmapping.southbound.lisp.cache.MapRegisterCache;
import org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException;
import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
private MappingRecordBuilder mappingRecordBuilder;
private MapRegisterCache mapRegisterCache;
private LispSouthboundPlugin mockLispSouthboundPlugin;
- private LispSouthboundStats lispSouthboundStats;
+ private ConcurrentLispSouthboundStats lispSouthboundStats;
private static final long CACHE_RECORD_TIMEOUT = 90000;
private static SimpleMapCache smc;
// mapResolver = context.mock(IMapResolver.class);
// mapServer = context.mock(IMapServer.class);
mockLispSouthboundPlugin = mock(LispSouthboundPlugin.class);
- Mockito.when(mockLispSouthboundPlugin.getStats()).thenReturn(Mockito.mock(LispSouthboundStats.class));
Mockito.when(mockLispSouthboundPlugin.isMapRegisterCacheEnabled()).thenReturn(true);
testedLispService = new LispSouthboundHandler(mockLispSouthboundPlugin);
testedLispService.setMapRegisterCacheTimeout(90000);
testedLispService.setDataStoreBackEnd(Mockito.mock(DataStoreBackEnd.class));
nps = context.mock(NotificationPublishService.class);
testedLispService.setNotificationProvider(nps);
- lispSouthboundStats = new LispSouthboundStats();
+ lispSouthboundStats = new ConcurrentLispSouthboundStats();
testedLispService.setStats(lispSouthboundStats);
lispNotificationSaver = new ValueSaverAction<Notification>();
// mapRegisterSaver = new ValueSaverAction<MapRegister>();