import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.concurrent.atomic.LongAdder;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.NotThreadSafe;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier;
import org.opendaylight.protocol.bgp.rib.impl.spi.Codecs;
import org.opendaylight.protocol.bgp.rib.impl.spi.CodecsRegistry;
-import org.opendaylight.protocol.bgp.rib.impl.stats.UnsignedInt32Counter;
import org.opendaylight.protocol.bgp.rib.spi.IdentifierUtils;
import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
import org.opendaylight.protocol.bgp.rib.spi.RibSupportUtils;
private final RIBSupport support;
private final boolean mpSupport;
private final ListenerRegistration<AdjRibOutListener> registerDataTreeChangeListener;
- private final UnsignedInt32Counter routeCounter;
+ private final LongAdder routeCounter;
private AdjRibOutListener(final PeerId peerId, final TablesKey tablesKey, final YangInstanceIdentifier ribId,
final CodecsRegistry registry, final RIBSupport support, final DOMDataTreeChangeService service,
- final ChannelOutputLimiter session, final boolean mpSupport, final UnsignedInt32Counter routeCounter) {
+ final ChannelOutputLimiter session, final boolean mpSupport, final LongAdder routeCounter) {
this.session = Preconditions.checkNotNull(session);
this.support = Preconditions.checkNotNull(support);
this.codecs = registry.getCodecs(this.support);
static AdjRibOutListener create(@Nonnull final PeerId peerId, @Nonnull final TablesKey tablesKey, @Nonnull final YangInstanceIdentifier ribId,
@Nonnull final CodecsRegistry registry, @Nonnull final RIBSupport support, @Nonnull final DOMDataTreeChangeService service,
- @Nonnull final ChannelOutputLimiter session, @Nonnull final boolean mpSupport, @Nonnull final UnsignedInt32Counter routeCounter
+ @Nonnull final ChannelOutputLimiter session, @Nonnull final boolean mpSupport, @Nonnull final LongAdder routeCounter
) {
return new AdjRibOutListener(peerId, tablesKey, ribId, registry, support, service, session, mpSupport, routeCounter);
}
}
private Update withdraw(final MapEntryNode route) {
- this.routeCounter.decreaseCount();
+ this.routeCounter.decrement();
if (!this.mpSupport) {
return buildUpdate(Collections.<MapEntryNode>emptyList(), Collections.singleton(route), routeAttributes(route));
}
}
private Update advertise(final MapEntryNode route) {
- this.routeCounter.increaseCount();
+ this.routeCounter.increment();
if (!this.mpSupport) {
return buildUpdate(Collections.singleton(route), Collections.<MapEntryNode>emptyList(), routeAttributes(route));
}
};
this.adjRibInWriter = this.adjRibInWriter.transform(peerId, context, localTables, Collections.emptyMap(),
registerAppPeerListener);
- this.peerStats = new BGPPeerStatsImpl(this.name, localTables);
+ this.peerStats = new BGPPeerStatsImpl(localTables);
this.effectiveRibInWriter = EffectiveRibInWriter.create(this.rib.getService(), this.rib.createPeerChain(this), this.peerIId,
this.rib.getImportPolicyPeerTracker(), context, PeerRole.Internal, this.peerStats.getEffectiveRibInRouteCounters(),
this.peerStats.getAdjRibInRouteCounters());
private final String name;
private BGPPeerRuntimeRegistrator registrator;
private BGPPeerRuntimeRegistration runtimeReg;
- private final Map<TablesKey, AdjRibOutListener> adjRibOutListenerSet = new HashMap();
+ private final Map<TablesKey, AdjRibOutListener> adjRibOutListenerSet = new HashMap<>();
private final RpcProviderRegistry rpcRegistry;
private RoutedRpcRegistration<BgpPeerRpcService> rpcRegistration;
private final PeerRole peerRole;
this.rib = Preconditions.checkNotNull(rib);
this.name = name;
this.rpcRegistry = rpcRegistry;
- this.peerStats = new BGPPeerStatsImpl(this.name, this.tables);
+ this.peerStats = new BGPPeerStatsImpl(this.tables);
this.chain = rib.createPeerChain(this);
}
public void instantiateServiceInstance() {
// add current peer to "configured BGP peer" stats
- this.rib.getRenderStats().getConfiguredPeerCounter().increaseCount();
+ this.rib.getRenderStats().getConfiguredPeerCounter().increment();
this.ribWriter = AdjRibInWriter.create(rib.getYangRibId(), this.peerRole, this.simpleRoutingPolicy, this.chain);
}
this.ribWriter = this.ribWriter.transform(peerId, this.rib.getRibSupportContext(), this.tables, addPathTableMaps);
// register BGP Peer stats
- this.peerStats.getSessionEstablishedCounter().increaseCount();
+ this.peerStats.getSessionEstablishedCounter().increment();
if (this.registrator != null) {
this.runtimeReg = this.registrator.register(this);
}
this.rpcRegistration.registerPath(PeerContext.class, path);
}
- this.rib.getRenderStats().getConnectedPeerCounter().increaseCount();
+ this.rib.getRenderStats().getConnectedPeerCounter().increment();
}
private void createAdjRibOutListener(final PeerId peerId) {
}
this.session = null;
- this.rib.getRenderStats().getConnectedPeerCounter().decreaseCount();
+ this.rib.getRenderStats().getConnectedPeerCounter().decrement();
}
}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. 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.protocol.bgp.rib.impl;
+
+import java.util.concurrent.atomic.LongAdder;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.ZeroBasedCounter32;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Provides util for increment/decrement counters whenever is not null
+ * Otherwise prints an informative warn.
+ */
+public final class CountersUtil {
+ private static final Logger LOG = LoggerFactory.getLogger(CountersUtil.class);
+
+ private CountersUtil() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Increments counter by 1 if supported, otherwise produce a warn
+ *
+ * @param counter counter
+ * @param tablesKey tablesKey Type
+ */
+ static void increment(@Nullable final LongAdder counter, @Nonnull TablesKey tablesKey) {
+ if (counter != null) {
+ counter.increment();
+ return;
+ }
+ LOG.warn("Family {} not supported", tablesKey);
+ }
+
+ /**
+ * Increments counter by 1 if supported, otherwise produce a warn
+ * @param counter counter
+ * @param tablesKey tablesKey Type
+ */
+ static void decrement(@Nullable final LongAdder counter, @Nonnull TablesKey tablesKey) {
+ if (counter != null) {
+ counter.decrement();
+ return;
+ }
+ LOG.warn("Family {} not supported", tablesKey);
+ }
+
+ public static ZeroBasedCounter32 toZeroBasedCounter32(final LongAdder longAdder){
+ return new ZeroBasedCounter32(longAdder.longValue());
+ }
+}
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.LongAdder;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.NotThreadSafe;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
*/
@Deprecated
AdjInTracker(final DOMDataTreeChangeService service, final RIBSupportContextRegistry registry, final DOMTransactionChain chain, final YangInstanceIdentifier peerIId) {
- this(service, registry, chain, peerIId, new PerTableTypeRouteCounter("effective-rib-in"), new PerTableTypeRouteCounter("adj-rib-in"));
+ this(service, registry, chain, peerIId, new PerTableTypeRouteCounter(), new PerTableTypeRouteCounter());
}
private void updateRoute(@Nonnull final PerTableTypeRouteCounter counter, @Nonnull final Map<TablesKey, Set<YangInstanceIdentifier>> routeMap,
private void updateRouteCounter(@Nonnull final PerTableTypeRouteCounter counter, @Nonnull final Map<TablesKey, Set<YangInstanceIdentifier>> routeMap,
@Nonnull final TablesKey tablesKey) {
- counter.getCounterOrSetDefault(tablesKey)
- .setCount(routeMap.getOrDefault(tablesKey, new HashSet<>()).size());
+ final LongAdder tableCounter = counter.getCounterOrSetDefault(tablesKey);
+ tableCounter.reset();
+ tableCounter.add(routeMap.getOrDefault(tablesKey, new HashSet<>()).size());
}
private void processRoute(final DOMDataWriteTransaction tx, final RIBSupport ribSupport, final AbstractImportPolicy policy, final YangInstanceIdentifier routesPath, final DataTreeCandidateNode route) {
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.atomic.LongAdder;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.NotThreadSafe;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
import org.opendaylight.protocol.bgp.mode.api.RouteEntry;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContextRegistry;
-import org.opendaylight.protocol.bgp.rib.impl.stats.UnsignedInt32Counter;
import org.opendaylight.protocol.bgp.rib.spi.ExportPolicyPeerTracker;
import org.opendaylight.protocol.bgp.rib.spi.IdentifierUtils;
import org.opendaylight.protocol.bgp.rib.spi.PeerExportGroup;
private final TablesKey localTablesKey;
private final ListenerRegistration<LocRibWriter> reg;
private final PathSelectionMode pathSelectionMode;
- private final UnsignedInt32Counter routeCounter;
+ private final LongAdder routeCounter;
private LocRibWriter(final RIBSupportContextRegistry registry, final DOMTransactionChain chain, final YangInstanceIdentifier target,
final Long ourAs, final DOMDataTreeChangeService service, final ExportPolicyPeerTracker exportPolicyPeerTracker, final TablesKey tablesKey,
- @Nonnull final PathSelectionMode pathSelectionMode, final UnsignedInt32Counter routeCounter) {
+ @Nonnull final PathSelectionMode pathSelectionMode, final LongAdder routeCounter) {
this.chain = Preconditions.checkNotNull(chain);
final NodeIdentifierWithPredicates tableKey = RibSupportUtils.toYangTablesKey(tablesKey);
this.localTablesKey = tablesKey;
public static LocRibWriter create(@Nonnull final RIBSupportContextRegistry registry, @Nonnull final TablesKey tablesKey, @Nonnull final DOMTransactionChain chain,
@Nonnull final YangInstanceIdentifier target, @Nonnull final AsNumber ourAs, @Nonnull final DOMDataTreeChangeService service, @Nonnull final ExportPolicyPeerTracker ep,
- @Nonnull final PathSelectionMode pathSelectionStrategy, @Nonnull final UnsignedInt32Counter routeCounter) {
+ @Nonnull final PathSelectionMode pathSelectionStrategy, @Nonnull final LongAdder routeCounter) {
return new LocRibWriter(registry, chain, target, ourAs.getValue(), service, ep, tablesKey, pathSelectionStrategy, routeCounter);
}
* Update the statistic of loc-rib route
*/
private void updateRouteCounter() {
- routeCounter.setCount(this.routeEntries.size());
+ this.routeCounter.reset();
+ this.routeCounter.add(this.routeEntries.size());
}
private void walkThrough(final DOMDataWriteTransaction tx, final Set<Map.Entry<RouteUpdateKey, RouteEntry>> toUpdate) {
+++ /dev/null
-/*
- * Copyright (c) 2016 Brocade Communications Systems, Inc. and others. 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.protocol.bgp.rib.impl.stats;
-
-import com.google.common.base.Preconditions;
-import java.util.concurrent.atomic.AtomicLong;
-import javax.annotation.Nonnull;
-import javax.annotation.concurrent.ThreadSafe;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.ZeroBasedCounter32;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * @author Kevin Wang
- */
-@ThreadSafe
-public class UnsignedInt32Counter {
- private static final Logger LOG = LoggerFactory.getLogger(UnsignedInt32Counter.class);
- private static final long MAX_VALUE = 4294967295L;
-
- private final String counterName;
- private final AtomicLong count = new AtomicLong();
-
- public UnsignedInt32Counter(@Nonnull final String counterName) {
- this.counterName = Preconditions.checkNotNull(counterName);
- }
-
- private static long safetyCheck(final long value) {
- return Math.min(Math.max(0L, value), MAX_VALUE);
- }
-
- public long increaseCount(final long change) {
- final long result;
- if (change == 0) {
- result = getCount();
- } else {
- Preconditions.checkArgument(change > 0, "Count number %s must be a positive number.", change);
- result = this.count.addAndGet(change);
- LOG.debug("Counter [{}] is increased by {}. Current count: {}", this.counterName, change, result);
- if (result > MAX_VALUE) {
- LOG.warn("Counter [{}] has exceeded the max allowed value {}. Counter's current value {} is invalid.", this.counterName, MAX_VALUE, result);
- }
- }
- return result;
- }
-
- public long increaseCount() {
- return this.increaseCount(1);
- }
-
- public long decreaseCount(final long change) {
- final long result;
- if (change == 0) {
- result = getCount();
- } else {
- Preconditions.checkArgument(change > 0, "Count number %s must be a positive number.", change);
- result = this.count.addAndGet(-change);
- LOG.debug("Counter [{}] is decreased by {}. Current count: {}", this.counterName, change, result);
- if (result < 0) {
- // In most case, we do not want the BGP session get into trouble due to an ERROR in counter
- // so here we print ERROR log instead of throwing out exception
- LOG.warn("Counter {} must not be less than 0. Counter's current value {} is invalid.", this.counterName, result);
- }
- }
- return result;
- }
-
- public long decreaseCount() {
- return this.decreaseCount(1);
- }
-
- public long getCount() {
- return this.count.get();
- }
-
- public void setCount(final long count) {
- final long result = getCount();
- if (count != result) {
- LOG.debug("Value of counter [{}] changes to {} (previous value is {})", this.counterName, count, result);
- this.count.set(count);
- }
- }
-
- public void resetCount() {
- LOG.debug("Value of counter [{}] is reset to 0.", this.counterName);
- setCount(0L);
- }
-
- public ZeroBasedCounter32 getCountAsZeroBasedCounter32() {
- return new ZeroBasedCounter32(safetyCheck(getCount()));
- }
-}
*/
package org.opendaylight.protocol.bgp.rib.impl.stats.peer;
+import java.util.concurrent.atomic.LongAdder;
import org.opendaylight.controller.config.yang.bgp.rib.impl.BgpPeerState;
-import org.opendaylight.protocol.bgp.rib.impl.stats.UnsignedInt32Counter;
import org.opendaylight.protocol.bgp.rib.impl.stats.peer.route.PerTableTypeRouteCounter;
-/**
- * @author Kevin Wang
- */
public interface BGPPeerStats {
BgpPeerState getBgpPeerState();
PerTableTypeRouteCounter getEffectiveRibInRouteCounters();
- UnsignedInt32Counter getSessionEstablishedCounter();
+ LongAdder getSessionEstablishedCounter();
}
*/
package org.opendaylight.protocol.bgp.rib.impl.stats.peer;
+import static org.opendaylight.protocol.bgp.rib.impl.CountersUtil.toZeroBasedCounter32;
+
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.atomic.LongAdder;
import javax.annotation.Nonnull;
import org.opendaylight.controller.config.api.IdentityAttributeRef;
import org.opendaylight.controller.config.yang.bgp.rib.impl.BgpPeerState;
import org.opendaylight.controller.config.yang.bgp.rib.impl.RouteTable;
-import org.opendaylight.protocol.bgp.rib.impl.stats.UnsignedInt32Counter;
import org.opendaylight.protocol.bgp.rib.impl.stats.peer.route.PerTableTypeRouteCounter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
private final PerTableTypeRouteCounter adjRibInRouteCounters;
private final PerTableTypeRouteCounter adjRibOutRouteCounters;
private final PerTableTypeRouteCounter effectiveRibInRouteCounters;
- private final UnsignedInt32Counter sessionEstablishedCounter = new UnsignedInt32Counter("SESSION ESTABLISHED");
- private final String peerName;
+ private final LongAdder sessionEstablishedCounter = new LongAdder();
- public BGPPeerStatsImpl(@Nonnull final String peerName, @Nonnull final Set<TablesKey> tablesKeySet) {
- this.peerName = Preconditions.checkNotNull(peerName);
+ public BGPPeerStatsImpl(@Nonnull final Set<TablesKey> tablesKeySet) {
this.tablesKeySet = Preconditions.checkNotNull(tablesKeySet);
- this.adjRibInRouteCounters = new PerTableTypeRouteCounter("["+ this.peerName +"] adj-rib-in route", tablesKeySet);
- this.adjRibOutRouteCounters = new PerTableTypeRouteCounter("["+ this.peerName +"] adj-rib-out route", tablesKeySet);
- this.effectiveRibInRouteCounters = new PerTableTypeRouteCounter("["+ this.peerName +"] effective-rib-in route", tablesKeySet);
+ this.adjRibInRouteCounters = new PerTableTypeRouteCounter(tablesKeySet);
+ this.adjRibOutRouteCounters = new PerTableTypeRouteCounter(tablesKeySet);
+ this.effectiveRibInRouteCounters = new PerTableTypeRouteCounter(tablesKeySet);
}
public PerTableTypeRouteCounter getAdjRibInRouteCounters() {
routeTable.setAfi(new IdentityAttributeRef(afiQName.toString()));
routeTable.setSafi(new IdentityAttributeRef(safiQName.toString()));
// we want to get default counter in case particular route table is not initialized (e.g. adj-rib-out is not initialized in some cases)
- routeTable.setAdjRibInRoutesCount(adjRibInRouteCounters.getCounterOrDefault(tablesKey).getCountAsZeroBasedCounter32());
- routeTable.setAdjRibOutRoutesCount(adjRibOutRouteCounters.getCounterOrDefault(tablesKey).getCountAsZeroBasedCounter32());
- routeTable.setEffectiveRibInRoutesCount(effectiveRibInRouteCounters.getCounterOrDefault(tablesKey).getCountAsZeroBasedCounter32());
+ routeTable.setAdjRibInRoutesCount(toZeroBasedCounter32(this.adjRibInRouteCounters.getCounterOrDefault(tablesKey)));
+ routeTable.setAdjRibOutRoutesCount(toZeroBasedCounter32(this.adjRibOutRouteCounters.getCounterOrDefault(tablesKey)));
+ routeTable.setEffectiveRibInRoutesCount(toZeroBasedCounter32(this.effectiveRibInRouteCounters.getCounterOrDefault(tablesKey)));
return routeTable;
}
public BgpPeerState getBgpPeerState() {
final BgpPeerState peerState = new BgpPeerState();
final List<RouteTable> routes = Lists.newArrayList();
- this.tablesKeySet.stream().forEach(tablesKey -> routes.add(createRouteTable(tablesKey)));
+ this.tablesKeySet.forEach(tablesKey -> routes.add(createRouteTable(tablesKey)));
peerState.setRouteTable(routes);
- peerState.setSessionEstablishedCount(this.sessionEstablishedCounter.getCountAsZeroBasedCounter32());
+ peerState.setSessionEstablishedCount(toZeroBasedCounter32(this.sessionEstablishedCounter));
return peerState;
}
@Override
- public UnsignedInt32Counter getSessionEstablishedCounter() {
+ public LongAdder getSessionEstablishedCounter() {
return this.sessionEstablishedCounter;
}
}
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.LongAdder;
import javax.annotation.Nonnull;
-import org.opendaylight.protocol.bgp.rib.impl.stats.UnsignedInt32Counter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class PerTableTypeRouteCounter {
private static final Logger LOG = LoggerFactory.getLogger(PerTableTypeRouteCounter.class);
- private final Map<TablesKey, UnsignedInt32Counter> counters = new ConcurrentHashMap<>();
- private final String counterName;
+ private final Map<TablesKey, LongAdder> counters = new ConcurrentHashMap<>();
- private final UnsignedInt32Counter createCounter(@Nonnull final TablesKey tablesKey) {
- return new UnsignedInt32Counter(this.counterName + tablesKey.toString());
- }
-
- public PerTableTypeRouteCounter(@Nonnull final String counterName) {
- this.counterName = Preconditions.checkNotNull(counterName);
+ public PerTableTypeRouteCounter(@Nonnull final Set<TablesKey> tablesKeySet) {
+ init(tablesKeySet);
}
- public PerTableTypeRouteCounter(@Nonnull final String counterName, @Nonnull final Set<TablesKey> tablesKeySet) {
- this(counterName);
- init(tablesKeySet);
+ public PerTableTypeRouteCounter() {
}
- public final synchronized void init(@Nonnull Set<TablesKey> tablesKeySet) {
- tablesKeySet.stream().forEach(tablesKey -> init(tablesKey));
+ private synchronized void init(@Nonnull Set<TablesKey> tablesKeySet) {
+ tablesKeySet.forEach(this::init);
}
- public final synchronized UnsignedInt32Counter init(@Nonnull final TablesKey tablesKey) {
- UnsignedInt32Counter counter = this.counters.get(Preconditions.checkNotNull(tablesKey));
+ public final synchronized LongAdder init(@Nonnull final TablesKey tablesKey) {
+ LongAdder counter = this.counters.get(Preconditions.checkNotNull(tablesKey));
if (counter == null) {
- this.counters.put(tablesKey, counter = createCounter(tablesKey));
+ counter = new LongAdder();
+ this.counters.put(tablesKey, counter);
}
LOG.debug("Initializing route counter for tablesKey {}", tablesKey);
- counter.resetCount();
+ counter.reset();
return counter;
}
* @param tablesKey
* @return
*/
- @Nonnull public final UnsignedInt32Counter getCounterOrDefault(@Nonnull final TablesKey tablesKey) {
- return this.counters.getOrDefault(Preconditions.checkNotNull(tablesKey), createCounter(tablesKey));
+ @Nonnull public final LongAdder getCounterOrDefault(@Nonnull final TablesKey tablesKey) {
+ return this.counters.getOrDefault(Preconditions.checkNotNull(tablesKey), new LongAdder());
}
/**
* @param tablesKey
* @return
*/
- public final UnsignedInt32Counter getCounterOrSetDefault(@Nonnull final TablesKey tablesKey) {
+ public final LongAdder getCounterOrSetDefault(@Nonnull final TablesKey tablesKey) {
if (!this.counters.containsKey(tablesKey)) {
return init(tablesKey);
} else {
}
}
- public final Map<TablesKey, UnsignedInt32Counter> getCounters() {
+ public final Map<TablesKey, LongAdder> getCounters() {
return this.counters;
}
public final void resetAll() {
LOG.debug("Resetting all route counters..");
- this.counters.values().stream().forEach(v -> v.resetCount());
+ this.counters.values().forEach(LongAdder::reset);
}
}
*/
package org.opendaylight.protocol.bgp.rib.impl.stats.rib.impl;
+import java.util.concurrent.atomic.LongAdder;
import org.opendaylight.controller.config.yang.bgp.rib.impl.RIBImplRuntimeMXBean;
-import org.opendaylight.protocol.bgp.rib.impl.stats.UnsignedInt32Counter;
import org.opendaylight.protocol.bgp.rib.impl.stats.peer.route.PerTableTypeRouteCounter;
-/**
- * @author Kevin Wang
- */
public interface BGPRenderStats extends RIBImplRuntimeMXBean {
PerTableTypeRouteCounter getLocRibRouteCounter();
- UnsignedInt32Counter getConfiguredPeerCounter();
+ LongAdder getConfiguredPeerCounter();
- UnsignedInt32Counter getConnectedPeerCounter();
+ LongAdder getConnectedPeerCounter();
}
*/
package org.opendaylight.protocol.bgp.rib.impl.stats.rib.impl;
+import static org.opendaylight.protocol.bgp.rib.impl.CountersUtil.toZeroBasedCounter32;
+
import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.atomic.LongAdder;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opendaylight.controller.config.api.IdentityAttributeRef;
import org.opendaylight.controller.config.yang.bgp.rib.impl.BgpRenderState;
import org.opendaylight.controller.config.yang.bgp.rib.impl.LocRibRouteTable;
-import org.opendaylight.protocol.bgp.rib.impl.stats.UnsignedInt32Counter;
import org.opendaylight.protocol.bgp.rib.impl.stats.peer.route.PerTableTypeRouteCounter;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.RibId;
import org.opendaylight.yangtools.yang.common.QName;
public class BGPRenderStatsImpl implements BGPRenderStats {
- private final PerTableTypeRouteCounter locRibRouteCounter = new PerTableTypeRouteCounter("loc-rib route");
+ private final PerTableTypeRouteCounter locRibRouteCounter = new PerTableTypeRouteCounter();
private final BgpId bgpId;
private final RibId ribId;
private final ClusterIdentifier clusterId;
private final AsNumber localAs;
- private final UnsignedInt32Counter configuredPeerCounter;
- private final UnsignedInt32Counter connectedPeerCounter;
+ private final LongAdder configuredPeerCounter;
+ private final LongAdder connectedPeerCounter;
public BGPRenderStatsImpl(@Nonnull final BgpId bgpId, @Nonnull final RibId ribId, @Nonnull final AsNumber localAs, @Nullable final ClusterIdentifier clusterId) {
this.bgpId = Preconditions.checkNotNull(bgpId);
this.ribId = Preconditions.checkNotNull(ribId);
this.localAs = localAs;
this.clusterId = clusterId;
- this.configuredPeerCounter = new UnsignedInt32Counter("Configured Peer of BGP-RIB " + this.ribId.getValue());
- this.connectedPeerCounter = new UnsignedInt32Counter("Connected Peer of BGP-RIB " + this.ribId.getValue());
+ this.configuredPeerCounter = new LongAdder();
+ this.connectedPeerCounter = new LongAdder();
}
@Override
renderState.setBgpRibId(this.bgpId);
renderState.setClusterId(this.clusterId);
renderState.setLocalAs(this.localAs);
- renderState.setConfiguredPeerCount(this.configuredPeerCounter.getCountAsZeroBasedCounter32());
- renderState.setConnectedPeerCount(this.connectedPeerCounter.getCountAsZeroBasedCounter32());
+ renderState.setConfiguredPeerCount(toZeroBasedCounter32(this.configuredPeerCounter));
+ renderState.setConnectedPeerCount(toZeroBasedCounter32(this.connectedPeerCounter));
// fill in the the statistic part
- final UnsignedInt32Counter totalRouteCount = new UnsignedInt32Counter("Total Loc-Rib Route Count");
+ final LongAdder totalRouteCount = new LongAdder();
final List<LocRibRouteTable> locRibRouteTableList = new ArrayList<>();
- this.locRibRouteCounter.getCounters().entrySet().stream().forEach(e -> generateCounters(e, locRibRouteTableList, totalRouteCount));
+ this.locRibRouteCounter.getCounters().entrySet().forEach(e -> generateCounters(e, locRibRouteTableList, totalRouteCount));
renderState.setLocRibRouteTable(locRibRouteTableList);
- renderState.setLocRibRoutesCount(totalRouteCount.getCountAsZeroBasedCounter32());
+ renderState.setLocRibRoutesCount(toZeroBasedCounter32(totalRouteCount));
return renderState;
}
- private void generateCounters(final Map.Entry<TablesKey, UnsignedInt32Counter> e, final List<LocRibRouteTable> locRibRouteTableList,
- final UnsignedInt32Counter totalRouteCount) {
+ private void generateCounters(final Map.Entry<TablesKey, LongAdder> e, final List<LocRibRouteTable> locRibRouteTableList,
+ final LongAdder totalRouteCount) {
final LocRibRouteTable table = new LocRibRouteTable();
final QName afi = BindingReflections.getQName(e.getKey().getAfi()).intern();
final QName safi = BindingReflections.getQName(e.getKey().getSafi()).intern();
table.setAfi(new IdentityAttributeRef(afi.toString()));
table.setSafi(new IdentityAttributeRef(safi.toString()));
- table.setRoutesCount(e.getValue().getCountAsZeroBasedCounter32());
+ table.setRoutesCount(toZeroBasedCounter32(e.getValue()));
locRibRouteTableList.add(table);
- totalRouteCount.increaseCount(e.getValue().getCount());
+ totalRouteCount.add(e.getValue().longValue());
}
}
@Override
- public UnsignedInt32Counter getConfiguredPeerCounter() {
+ public LongAdder getConfiguredPeerCounter() {
return this.configuredPeerCounter;
}
@Override
- public UnsignedInt32Counter getConnectedPeerCounter() {
+ public LongAdder getConnectedPeerCounter() {
return this.connectedPeerCounter;
}
}
*/
package org.opendaylight.protocol.bgp.rib.impl.stats.rib.impl;
+import java.util.concurrent.atomic.LongAdder;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opendaylight.controller.config.yang.bgp.rib.impl.BgpRenderState;
-import org.opendaylight.protocol.bgp.rib.impl.stats.UnsignedInt32Counter;
import org.opendaylight.protocol.bgp.rib.impl.stats.peer.route.PerTableTypeRouteCounter;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.RibId;
}
@Override
- public UnsignedInt32Counter getConfiguredPeerCounter() {
+ public LongAdder getConfiguredPeerCounter() {
return this.renderStats.getConfiguredPeerCounter();
}
@Override
- public UnsignedInt32Counter getConnectedPeerCounter() {
+ public LongAdder getConnectedPeerCounter() {
return this.renderStats.getConnectedPeerCounter();
}
}
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.concurrent.atomic.LongAdder;
import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
import javax.management.ObjectName;
import org.opendaylight.protocol.bgp.rib.impl.spi.ImportPolicyPeerTracker;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContextRegistry;
-import org.opendaylight.protocol.bgp.rib.impl.stats.UnsignedInt32Counter;
import org.opendaylight.protocol.bgp.rib.impl.stats.rib.impl.BGPRenderStats;
import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext;
import org.opendaylight.protocol.bgp.rib.spi.SimpleRIBExtensionProviderContext;
doReturn(new AsNumber(123456l)).when(this.mockedRIB).getLocalAs();
doReturn(BGP_ID).when(this.mockedRIB).getBgpIdentifier();
final BGPRenderStats mockedRenderStats = mock(BGPRenderStats.class);
- doReturn(new UnsignedInt32Counter("counter")).when(mockedRenderStats).getConfiguredPeerCounter();
+ doReturn(new LongAdder()).when(mockedRenderStats).getConfiguredPeerCounter();
doReturn(mockedRenderStats).when(this.mockedRIB).getRenderStats();
final DOMDataTreeChangeService mockedTreeChangeService = mock(DOMDataTreeChangeService.class);
final ListenerRegistration<?> mockedListenerReg = mock(ListenerRegistration.class);
import java.net.InetSocketAddress;
import java.util.Collections;
import java.util.concurrent.Executor;
+import java.util.concurrent.atomic.LongAdder;
import org.junit.Before;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.opendaylight.protocol.bgp.rib.impl.spi.ImportPolicyPeerTracker;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContextRegistry;
-import org.opendaylight.protocol.bgp.rib.impl.stats.UnsignedInt32Counter;
import org.opendaylight.protocol.bgp.rib.impl.stats.rib.impl.BGPRenderStats;
import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
this.singletonService = (ClusterSingletonService) invocationOnMock.getArguments()[0];
return this.singletonServiceRegistration;
}).when(this.rib).registerClusterSingletonService(any(ClusterSingletonService.class));
- Mockito.doReturn(new UnsignedInt32Counter("counter")).when(this.render).getConfiguredPeerCounter();
+ Mockito.doReturn(new LongAdder()).when(this.render).getConfiguredPeerCounter();
Mockito.doReturn(this.render).when(this.rib).getRenderStats();
Mockito.doReturn(this.domTx).when(this.rib).createPeerChain(any(TransactionChainListener.class));
Mockito.doReturn(AS).when(this.rib).getLocalAs();
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.atomic.LongAdder;
import org.junit.Test;
import org.opendaylight.controller.config.yang.bgp.rib.impl.BgpRenderState;
import org.opendaylight.controller.config.yang.bgp.rib.impl.LocRibRouteTable;
renderStateExpected.setLocRibRoutesCount(COUTER);
assertEquals(renderStateExpected, render.getBgpRenderState());
- assertEquals(1L, render.getLocRibRouteCounter().init(new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class)).increaseCount());
- assertEquals(1L, render.getConfiguredPeerCounter().increaseCount());
- assertEquals(1L, render.getConnectedPeerCounter().increaseCount());
+ LongAdder counter = render.getLocRibRouteCounter().init(new TablesKey(Ipv4AddressFamily.class,
+ UnicastSubsequentAddressFamily.class));
+ counter.increment();
+ assertEquals(1L, counter.longValue());
+ counter = render.getConfiguredPeerCounter();
+ counter.increment();
+ assertEquals(1L, counter.longValue());
+ counter = render.getConnectedPeerCounter();
+ counter.increment();
+ assertEquals(1L, counter.longValue());
}
}
\ No newline at end of file