[SEBA-719] Display counters in onos cli and reset counters
Change-Id: Ia9fc1865d13a366c9a7cd3e7ae11c39dcc284fd9
diff --git a/app/src/main/java/org/opencord/aaa/impl/AaaResetCountersCommand.java b/app/src/main/java/org/opencord/aaa/impl/AaaResetCountersCommand.java
new file mode 100644
index 0000000..79ada3b
--- /dev/null
+++ b/app/src/main/java/org/opencord/aaa/impl/AaaResetCountersCommand.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2016-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.opencord.aaa.impl;
+
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.opencord.aaa.AuthenticationStatisticsService;
+
+/**
+ * Reset value of all aaa statistics counters to 0.
+ */
+@Command(scope = "onos", name = "reset-aaa-counters", description = "Reset value of all aaa statistics counters to 0 ")
+public class AaaResetCountersCommand extends AbstractShellCommand {
+
+ @Override
+ protected void execute() {
+ AuthenticationStatisticsService aaaStatisticsManager = AbstractShellCommand
+ .get(AuthenticationStatisticsService.class);
+ aaaStatisticsManager.resetAllCounters();
+ }
+}
diff --git a/app/src/main/java/org/opencord/aaa/impl/AaaShowCountersCommand.java b/app/src/main/java/org/opencord/aaa/impl/AaaShowCountersCommand.java
new file mode 100644
index 0000000..0717f9a
--- /dev/null
+++ b/app/src/main/java/org/opencord/aaa/impl/AaaShowCountersCommand.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2016-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.opencord.aaa.impl;
+
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.opencord.aaa.AaaStatistics;
+import org.opencord.aaa.AuthenticationStatisticsService;
+
+/**
+ * Display current value of all aaa statistics counters.
+ */
+@Command(scope = "onos", name = "show-aaa-counters",
+description = "Display current value of all aaa statistics counters")
+public class AaaShowCountersCommand extends AbstractShellCommand {
+ @Override
+ protected void execute() {
+
+ AaaStatistics aaaStats = new AaaStatistics();
+
+ AuthenticationStatisticsService aaaStatisticsManager =
+ AbstractShellCommand.get(AuthenticationStatisticsService.class);
+ aaaStats = aaaStatisticsManager.getAaaStats();
+
+ System.out.format("%30s %10d\n", "AccessRequestsTx", aaaStats.getAccessRequestsTx());
+ System.out.format("%30s %10d\n", "ChallengeResponsesRx", aaaStats.getChallengeResponsesRx());
+ System.out.format("%30s %10d\n", "RequestReTx", aaaStats.getRequestReTx());
+ System.out.format("%30s %10d\n", "AcceptResponsesRx", aaaStats.getAcceptResponsesRx());
+ System.out.format("%30s %10d\n", "RejectResponsesRx", aaaStats.getRejectResponsesRx());
+ System.out.format("%30s %10d\n", "PendingRequests", aaaStats.getPendingRequests());
+ System.out.format("%30s %10d\n", "DroppedResponsesRx", aaaStats.getDroppedResponsesRx());
+ System.out.format("%30s %10d\n", "InvalidValidatorsRx", aaaStats.getInvalidValidatorsRx());
+ System.out.format("%30s %10d\n", "MalformedResponsesRx", aaaStats.getMalformedResponsesRx());
+ System.out.format("%30s %10d\n", "UnknownServerRx", aaaStats.getUnknownServerRx());
+ System.out.format("%30s %10d\n", "UnknownTypeRx", aaaStats.getUnknownTypeRx());
+ System.out.format("%30s %10d\n", "RequestRttMillis", aaaStats.getRequestRttMilis());
+
+ }
+}
diff --git a/app/src/main/java/org/opencord/aaa/impl/AaaStatisticsManager.java b/app/src/main/java/org/opencord/aaa/impl/AaaStatisticsManager.java
index b28d53e..31aad5b 100644
--- a/app/src/main/java/org/opencord/aaa/impl/AaaStatisticsManager.java
+++ b/app/src/main/java/org/opencord/aaa/impl/AaaStatisticsManager.java
@@ -19,7 +19,6 @@
import static org.slf4j.LoggerFactory.getLogger;
import java.util.HashMap;
-import java.util.LinkedList;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
@@ -39,21 +38,22 @@
@Service
@Component(immediate = true)
public class AaaStatisticsManager
- extends AbstractListenerManager<AuthenticationStatisticsEvent, AuthenticationStatisticsEventListener>
- implements AuthenticationStatisticsService {
+extends AbstractListenerManager<AuthenticationStatisticsEvent, AuthenticationStatisticsEventListener>
+implements AuthenticationStatisticsService {
private AuthenticationStatisticsDelegate statsDelegate;
+ @Override
public AuthenticationStatisticsDelegate getStatsDelegate() {
return statsDelegate;
}
private final Logger log = getLogger(getClass());
private AaaStatistics aaaStats;
- private LinkedList<Long> packetRoundTripTimeList = new LinkedList<Long>();
public Map<Byte, Long> outgoingPacketMap = new HashMap<Byte, Long>();
private static final int PACKET_COUNT_FOR_AVERAGE_RTT_CALCULATION = 5;
+ @Override
public AaaStatistics getAaaStats() {
return aaaStats;
}
@@ -71,23 +71,31 @@
eventDispatcher.removeSink(AuthenticationStatisticsEvent.class);
}
+ @Override
public void handleRoundtripTime(byte inPacketIdentifier) {
long inTimeInMilis = System.currentTimeMillis();
if (outgoingPacketMap.containsKey(inPacketIdentifier)) {
- if (packetRoundTripTimeList.size() > PACKET_COUNT_FOR_AVERAGE_RTT_CALCULATION) {
- packetRoundTripTimeList.removeFirst();
+ if (aaaStats.getPacketRoundTripTimeListSize() > PACKET_COUNT_FOR_AVERAGE_RTT_CALCULATION) {
+ aaaStats.getPacketRoundTripTimeListRemoveFirst();
}
- packetRoundTripTimeList.add(inTimeInMilis - outgoingPacketMap.get(inPacketIdentifier));
+ aaaStats.getPacketRoundTripTimeListAdd(inTimeInMilis - outgoingPacketMap.get(inPacketIdentifier));
}
}
+ @Override
+ public void resetAllCounters() {
+ aaaStats.resetAllCounters();
+ }
+
+ @Override
public void calculatePacketRoundtripTime() {
- if (packetRoundTripTimeList.size() > 0) {
- long avg = (long) packetRoundTripTimeList.stream().mapToLong(i -> i).average().getAsDouble();
+ if (aaaStats.getPacketRoundTripTimeListSize() > 0) {
+ long avg = (long) aaaStats.getPacketRoundTripTimeList().stream().mapToLong(i -> i).average().getAsDouble();
aaaStats.setRequestRttMilis(new AtomicLong(avg));
}
}
+ @Override
public void putOutgoingIdentifierToMap(byte outPacketIdentifier) {
outgoingPacketMap.put(outPacketIdentifier, System.currentTimeMillis());
}