[SEBA-896] View SEBA-36 Statistics from ONOS CLI

Change-Id: I6682b174e4e57de50113f7f8b7144260e09bfa35
diff --git a/api/src/main/java/org/opencord/aaa/AuthenticationService.java b/api/src/main/java/org/opencord/aaa/AuthenticationService.java
index 3399966..4eb649b 100644
--- a/api/src/main/java/org/opencord/aaa/AuthenticationService.java
+++ b/api/src/main/java/org/opencord/aaa/AuthenticationService.java
@@ -40,4 +40,12 @@
      */
     boolean removeAuthenticationStateByMac(MacAddress mac);
 
+    /**
+     * Gets the machine stats based on machine session id.
+     *
+     * @param sessionID SessionID of machine
+     * @return AaaSupplicantMachineStats object
+     */
+    AaaSupplicantMachineStats getSupplicantMachineStats(String sessionID);
+
 }
diff --git a/app/src/main/java/org/opencord/aaa/cli/AaaShowPerMachineCountersCommand.java b/app/src/main/java/org/opencord/aaa/cli/AaaShowPerMachineCountersCommand.java
new file mode 100644
index 0000000..1a4d89f
--- /dev/null
+++ b/app/src/main/java/org/opencord/aaa/cli/AaaShowPerMachineCountersCommand.java
@@ -0,0 +1,65 @@
+/*
+ * 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.cli;
+
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+
+import org.apache.karaf.shell.api.action.Argument;
+import org.onosproject.cli.AbstractShellCommand;
+import org.apache.karaf.shell.api.action.Command;
+import org.opencord.aaa.AaaMachineStatisticsService;
+import org.opencord.aaa.AaaSupplicantMachineStats;
+import org.opencord.aaa.AuthenticationService;
+
+/**
+ * CLI command for displaying all the AaaMachine Counters.
+ */
+@Service
+@Command(scope = "onos", name = "show-aaa-machine-counters",
+description = "Display current value of all aaa statistics counters")
+public class AaaShowPerMachineCountersCommand extends AbstractShellCommand {
+
+    @Argument(index = 0, name = "deviceId",
+              description = "DeviceId of device from which packet is received",
+              required = true, multiValued = false)
+    private String deviceId;
+
+    @Argument(index = 1, name = "portNumber",
+             description = "Port no of device from which packet is received",
+             required = true, multiValued = false)
+    private String portNumber;
+
+    @Override
+    protected void doExecute() {
+
+        String sessionId = deviceId + portNumber;
+        AaaMachineStatisticsService aaaMachineStatsManager = get(AaaMachineStatisticsService.class);
+        AuthenticationService aaaManager = get(AuthenticationService.class);
+        AaaSupplicantMachineStats aaaSupplicantMachineStats = aaaManager.getSupplicantMachineStats(sessionId);
+        if (aaaSupplicantMachineStats != null) {
+            print("%30s %10d\n", "SessionDuration", aaaSupplicantMachineStats.getSessionDuration());
+            print("%30s %10d\n", "TotalOctetRecieved", aaaSupplicantMachineStats.getTotalOctetRecieved());
+            print("%30s %10d\n", "TotalFramesReceived", aaaSupplicantMachineStats.getTotalFramesReceived());
+            print("%30s %10d\n", "TotalFramesSent", aaaSupplicantMachineStats.getTotalFramesSent());
+            print("%30s %10d\n", "TotalOctetSent", aaaSupplicantMachineStats.getTotalOctetSent());
+            print("%30s %10d\n", "TotalPacketsRecieved", aaaSupplicantMachineStats.getTotalPacketsRecieved());
+            print("%30s %10d\n", "TotalPacketsSent", aaaSupplicantMachineStats.getTotalPacketsSent());
+        } else {
+            print("No such Device Found");
+        }
+    }
+
+}
diff --git a/app/src/main/java/org/opencord/aaa/impl/AaaManager.java b/app/src/main/java/org/opencord/aaa/impl/AaaManager.java
index e139b70..e3f5822 100644
--- a/app/src/main/java/org/opencord/aaa/impl/AaaManager.java
+++ b/app/src/main/java/org/opencord/aaa/impl/AaaManager.java
@@ -926,7 +926,6 @@
 
     private void handleStateMachineTimeout(ConnectPoint supplicantConnectPoint) {
         StateMachine stateMachine = stateMachines.remove(sessionId(supplicantConnectPoint));
-
         //pushing captured machine stats to kafka
         stateMachine.setSessionTerminateReason("Time out");
         AaaSupplicantMachineStats obj = aaaSupplicantStatsManager
@@ -1084,7 +1083,6 @@
             AaaSupplicantMachineStats obj = aaaSupplicantStatsManager.getSupplicantStats(stateMachine);
             aaaSupplicantStatsManager.getMachineStatsDelegate()
                    .notify(new AaaMachineStatisticsEvent(AaaMachineStatisticsEvent.Type.STATS_UPDATE, obj));
-
             StateMachine removed = stateMachines.remove(sessionId);
             if (removed != null) {
                 StateMachine.deleteStateMachineMapping(removed);
@@ -1106,4 +1104,14 @@
         }
 
     }
+
+    @Override
+    public AaaSupplicantMachineStats getSupplicantMachineStats(String sessionId) {
+        StateMachine aaaSupplicantMachine = stateMachines.get(sessionId);
+        if (aaaSupplicantMachine != null) {
+            return aaaSupplicantStatsManager.getSupplicantStats(aaaSupplicantMachine);
+        } else {
+            return null;
+        }
+    }
 }