Adding QoS display command 24/89924/10
authorMeenakshi C <meenakshi.c@ericsson.com>
Sat, 23 May 2020 22:26:08 +0000 (03:56 +0530)
committerKarthikeyan Krishnan <karthikeyangceb007@gmail.com>
Tue, 21 Jul 2020 13:00:57 +0000 (13:00 +0000)
Signed-off-by: Meenakshi C <meenakshi.c@ericsson.com>
Change-Id: Ie694ce0d7c6d403a9f2e2fc50b72831f7f614274

qosservice/impl/pom.xml
qosservice/impl/src/main/java/org/opendaylight/netvirt/qosservice/QosAlertConfigCLI.java [new file with mode: 0644]
qosservice/impl/src/main/java/org/opendaylight/netvirt/qosservice/QosAlertManager.java
qosservice/impl/src/main/java/org/opendaylight/netvirt/qosservice/QosAlertPortData.java
qosservice/impl/src/main/java/org/opendaylight/netvirt/qosservice/QosNeutronUtils.java
qosservice/impl/src/main/resources/OSGI-INF/blueprint/qosservice.xml

index dd9abeabaf88bae17fdc8435ae55d4f5652c9c72..cb2e3df7ebcd444c428f19a22d1254e8304c3ab7 100644 (file)
@@ -71,6 +71,10 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
             <artifactId>truth</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>com.google.code.gson</groupId>
+            <artifactId>gson</artifactId>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/qosservice/impl/src/main/java/org/opendaylight/netvirt/qosservice/QosAlertConfigCLI.java b/qosservice/impl/src/main/java/org/opendaylight/netvirt/qosservice/QosAlertConfigCLI.java
new file mode 100644 (file)
index 0000000..6de629e
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2018 Ericsson India Global Services Pvt Ltd. 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.netvirt.qosservice;
+import org.apache.felix.service.command.CommandSession;
+import org.apache.karaf.shell.commands.Command;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Command(scope = "qos", name = "display-alert-config",
+        description = "display qos alert configurations")
+public class QosAlertConfigCLI implements org.apache.karaf.shell.commands.Action {
+    private QosAlertManager qosAlertManager;
+    private QosNeutronUtils qosNeutronUtils;
+    private static final Logger LOG = LoggerFactory.getLogger(QosAlertConfigCLI.class);
+
+    public void setQosAlertManager(QosAlertManager qosAlertManager) {
+        LOG.trace("Qos manager:{} set", qosAlertManager);
+        this.qosAlertManager = qosAlertManager;
+    }
+
+    public void setQosNeutronUtils(QosNeutronUtils qosNeutronUtils) {
+        LOG.debug("Qos neutron utils :{} set", qosNeutronUtils);
+        this.qosNeutronUtils = qosNeutronUtils;
+    }
+
+    @Override
+    public Object execute(CommandSession session) throws Exception {
+        qosAlertManager.displayConfig(session);
+        qosNeutronUtils.displayConfig(session);
+        return null;
+    }
+}
+
index 6c5645141b918f3dad8f1e511ba0e7ba6b81f824..95d8bb84c02129b56354e02ccdaf9b79e01b3511 100644 (file)
@@ -10,6 +10,10 @@ package org.opendaylight.netvirt.qosservice;
 
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
@@ -22,6 +26,7 @@ import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
+import org.apache.felix.service.command.CommandSession;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
 import org.opendaylight.genius.interfacemanager.globals.IfmConstants;
@@ -204,6 +209,43 @@ public final class QosAlertManager implements Runnable {
         }
     }
 
+    public void displayConfig(CommandSession session) {
+
+        session.getConsole().println("Qos Alert Configuration Details");
+        session.getConsole().println("Threshold: " + alertThresholdSupplier.get().shortValue());
+        session.getConsole().println("AlertEnabled: " + alertEnabled);
+        session.getConsole().println("Poll Interval: " + pollInterval);
+
+        Uint64 dpnId;
+        String portData;
+        Gson gson = new GsonBuilder().setPrettyPrinting().create();
+        if (qosAlertDpnPortNumberMap.isEmpty()) {
+            session.getConsole().println("\nQosAlert Cache not found\n");
+            return;
+        } else {
+            session.getConsole().println("\nDPN Map");
+            JsonObject jsonObject;
+            JsonArray jsonArray;
+            JsonArray jsonArrayOuter = new JsonArray();
+            for (Entry<Uint64, ConcurrentMap<String, QosAlertPortData>> dpnEntry
+                    : qosAlertDpnPortNumberMap.entrySet()) {
+                dpnId = dpnEntry.getKey();
+                jsonObject = new JsonObject();
+                jsonObject.addProperty("DpnId", dpnId.toString());
+                ConcurrentMap<String, QosAlertPortData> portInnerMap = qosAlertDpnPortNumberMap.get(dpnId);
+                jsonArray = new JsonArray();
+                for (ConcurrentMap.Entry<String, QosAlertPortData> portEntry : portInnerMap.entrySet()) {
+                    portData = "Port_number: " + portEntry.getKey() + ", " + portEntry.getValue();
+                    jsonArray.add(portData);
+                }
+                jsonObject.add("QosAlertPortData Cache", jsonArray);
+                jsonArrayOuter.add(jsonObject);
+            }
+            session.getConsole().println(gson.toJson(jsonArrayOuter));
+            session.getConsole().println();
+        }
+    }
+
     public void processInterfaceUpEvent(String ifaceId) {
         LOG.trace("processInterfaceUpEvent {}", ifaceId);
         if (unprocessedInterfaceIds.remove(ifaceId)) {
index d76736c77f3973f90b5c99195339f1c22f82b4db..d1011c0ad616f8533f1428f52448fb5c0271de11 100644 (file)
@@ -42,6 +42,11 @@ public class QosAlertPortData {
         statsDataInit = false;
     }
 
+    public String toString() {
+        return "Uuid: " + this.port.getUuid().getValue() + ", rx_packets: " + rxPackets
+                + ", rx_dropped_packets: " + rxDroppedPackets;
+    }
+
     public void updatePortStatistics(NodeConnectorStatisticsAndPortNumberMap statsData) {
         LOG.trace("Port {} rx-packets {} tx-packets {} rx-dropped {} tx-dropped {}", port.getUuid().getValue(),
                            statsData.getPackets().getReceived(), statsData.getPackets().getTransmitted(),
index 0346c68cc3ddf2f14c8e87fd712c41cc4aed7f97..61edeb983f6523d6fb700ee3503a8fcb32a9b94a 100644 (file)
@@ -10,6 +10,10 @@ package org.opendaylight.netvirt.qosservice;
 import static java.util.Collections.emptyList;
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -23,6 +27,7 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import javax.inject.Inject;
 import javax.inject.Singleton;
+import org.apache.felix.service.command.CommandSession;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
@@ -176,6 +181,169 @@ public class QosNeutronUtils {
         }
     }
 
+    public void displayConfig(CommandSession session) {
+
+        session.getConsole().println("QosClusterOwner: " + qosEosHandler.isQosClusterOwner());
+        Gson gson = new GsonBuilder().setPrettyPrinting().create();
+
+        if (qosPolicyMap.isEmpty() && qosPortsMap.isEmpty() && qosNetworksMap.isEmpty()) {
+            session.getConsole().println("No cache found");
+            return;
+        }
+        if (!(qosPolicyMap.isEmpty())) {
+            displayQosPolicyMap(session, gson);
+        }
+        if (!(qosPortsMap.isEmpty())) {
+            displayQosPortsMap(session, gson);
+        }
+        if (!(qosNetworksMap.isEmpty())) {
+            displayQosNetworksMap(session, gson);
+        }
+    }
+
+    private void displayQosPolicyMap(CommandSession session, Gson gson) {
+        session.getConsole().println("\nQOS Policy Map");
+
+        String uuid;
+        String policyName;
+        String dscpUuid;
+        String bandwidthUuid;
+        Long maxRate;
+        Long maxBurstRate;
+        String dscpValue;
+        Uuid policyUuid;
+
+        JsonObject jsonObject;
+        JsonArray jsonArray = new JsonArray();
+        for (ConcurrentMap.Entry<Uuid, QosPolicy> policyEntry : qosPolicyMap.entrySet()) {
+            jsonObject = new JsonObject();
+            dscpUuid = "null";
+            bandwidthUuid = "null";
+            maxRate = 0L;
+            maxBurstRate = 0L;
+            dscpValue = "null";
+            policyUuid = policyEntry.getKey();
+            uuid = policyEntry.getKey().getValue();
+            policyName = qosPolicyMap.get(policyUuid).getName();
+
+            if (qosPolicyMap.get(policyUuid).getBandwidthLimitRules() != null) {
+                BandwidthLimitRules bandwidthLimitRules =
+                        qosPolicyMap.get(policyUuid).getBandwidthLimitRules().values().iterator().next();
+                if (bandwidthLimitRules.getUuid() != null) {
+                    bandwidthUuid = bandwidthLimitRules.getUuid().getValue();
+                }
+                if (bandwidthLimitRules.getMaxKbps() != null) {
+                    maxRate = bandwidthLimitRules.getMaxKbps().longValue();
+                }
+                if (bandwidthLimitRules.getMaxBurstKbps() != null) {
+                    maxBurstRate = bandwidthLimitRules.getMaxBurstKbps().longValue();
+                }
+            }
+            if (qosPolicyMap.get(policyUuid).getDscpmarkingRules() != null) {
+                DscpmarkingRules dscp = qosPolicyMap.get(policyUuid).getDscpmarkingRules().values().iterator().next();
+                if (dscp.getUuid() != null) {
+                    dscpUuid = dscp.getUuid().getValue();
+                }
+                if (dscp.getDscpMark() != null) {
+                    dscpValue = dscp.getDscpMark().toString();
+                }
+            }
+            jsonObject.addProperty("Policy Uuid", uuid);
+            jsonObject.addProperty("Policy Name", policyName);
+            jsonObject.addProperty("Bandwidth Uuid", bandwidthUuid);
+            jsonObject.addProperty("max kbps", maxRate);
+            jsonObject.addProperty("max burst kbps", maxBurstRate);
+            jsonObject.addProperty("Dscp Uuid", dscpUuid);
+            jsonObject.addProperty("Dscp Value", dscpValue);
+            jsonArray.add(jsonObject);
+        }
+        session.getConsole().println(gson.toJson(jsonArray));
+    }
+
+    private void displayQosPortsMap(CommandSession session, Gson gson) {
+        session.getConsole().println("\nQOS Ports Map");
+
+        String policyId;
+        String policyName;
+        String portUuid;
+        String portName;
+        String portDetails;
+        Uuid policyUuid;
+        Uuid portId;
+
+        JsonObject jsonObject;
+        JsonArray jsonArrayOuter = new JsonArray();
+        JsonArray jsonArray;
+        for (ConcurrentMap.Entry<Uuid, ConcurrentMap<Uuid, Port>> policyEntry : qosPortsMap.entrySet()) {
+            policyUuid = policyEntry.getKey();
+            policyId = policyUuid.getValue();
+            policyName = qosPolicyMap.get(policyUuid).getName();
+            jsonObject = new JsonObject();
+            jsonArray = new JsonArray();
+            jsonObject.addProperty("Policy Uuid", policyId);
+            jsonObject.addProperty("Policy Name", policyName);
+            ConcurrentMap<Uuid, Port> portInnerMap = qosPortsMap.get(policyUuid);
+            for (ConcurrentMap.Entry<Uuid, Port> portEntry : portInnerMap.entrySet()) {
+                portId = portEntry.getKey();
+                if (portId != null) {
+                    portUuid = portInnerMap.get(portId).getUuid().getValue();
+                    portName = portInnerMap.get(portId).getName();
+                    if (portName == null) {
+                        portName = "null";
+                    }
+                    portDetails = portUuid + " : " + portName;
+                    jsonArray.add(portDetails);
+                }
+            }
+            jsonObject.add("Port Details", jsonArray);
+            jsonArrayOuter.add(jsonObject);
+        }
+        session.getConsole().println(gson.toJson(jsonArrayOuter));
+    }
+
+    private void displayQosNetworksMap(CommandSession session, Gson gson) {
+        session.getConsole().println("\nQos Networks Map");
+
+        String policyId;
+        String policyName;
+        String networkId;
+        String networkName;
+        String networkDetails;
+        Uuid policyUuid;
+        Uuid networkUuid;
+
+        JsonObject jsonObject;
+        JsonArray jsonArrayOuter = new JsonArray();
+        JsonArray jsonArray;
+        for (ConcurrentMap.Entry<Uuid, ConcurrentMap<Uuid, Network>> policyEntry: qosNetworksMap.entrySet()) {
+            policyUuid = policyEntry.getKey();
+            policyId = policyUuid.getValue();
+            policyName = qosPolicyMap.get(policyUuid).getName();
+            jsonObject = new JsonObject();
+            jsonArray = new JsonArray();
+            jsonObject.addProperty("Policy Uuid", policyId);
+            jsonObject.addProperty("Policy Name", policyName);
+            ConcurrentMap<Uuid, Network> networkInnerMap = qosNetworksMap.get(policyUuid);
+
+            for (ConcurrentMap.Entry<Uuid, Network> networkEntry : networkInnerMap.entrySet()) {
+                networkUuid = networkEntry.getKey();
+                if (networkUuid != null) {
+                    networkId = networkInnerMap.get(networkUuid).getUuid().getValue();
+                    networkName = networkInnerMap.get(networkUuid).getName();
+                    if (networkName == null) {
+                        networkName = "null";
+                    }
+                    networkDetails = networkId + " : " + networkName;
+                    jsonArray.add(networkDetails);
+                }
+            }
+            jsonObject.add("Network Details", jsonArray);
+            jsonArrayOuter.add(jsonObject);
+
+        }
+        session.getConsole().println(gson.toJson(jsonArrayOuter));
+    }
+
     @NonNull
     public Collection<Network> getQosNetworks(Uuid qosUuid) {
         final ConcurrentMap<Uuid, Network> networkMap = qosNetworksMap.get(qosUuid);
index def8d3ef87f03fb2d1c046d59464054725106241..65e05de375f19ee0956a3d945b086eb4eff07685 100644 (file)
@@ -57,6 +57,12 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
                 <property name="qosAlertManager" ref="qosAlertManager"/>
             </action>
         </command>
+        <command>
+            <action class="org.opendaylight.netvirt.qosservice.QosAlertConfigCLI">
+                <property name="qosAlertManager" ref="qosAlertManager"/>
+                <property name="qosNeutronUtils" ref="qosNeutronUtils"/>
+            </action>
+        </command>
 
     </command-bundle>