ONOS-7815 create new cli to query registered pipeconfs

Change-Id: Ie7286509bde782794d1c0870ad31e5e99584a62d
diff --git a/cli/src/main/java/org/onosproject/cli/net/PipeconfCommand.java b/cli/src/main/java/org/onosproject/cli/net/PipeconfCommand.java
new file mode 100644
index 0000000..39381be
--- /dev/null
+++ b/cli/src/main/java/org/onosproject/cli/net/PipeconfCommand.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2018-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.onosproject.cli.net;
+
+
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.driver.Behaviour;
+import org.onosproject.net.pi.model.PiPipeconf;
+import org.onosproject.net.pi.service.PiPipeconfService;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+
+/**
+ * Query registered pipeconfs.
+ */
+@Command(scope = "onos", name = "pipeconfs",
+        description = "Query registered pipeconfs.")
+public class PipeconfCommand extends AbstractShellCommand {
+
+    protected PiPipeconfService piPipeconfService;
+
+    @Option(name = "-s", aliases = "--short",
+            description = "Print more succinct output for each pipeconf",
+            required = false, multiValued = false)
+    private boolean shortOutput = false;
+
+    @Override
+    protected void execute() {
+        piPipeconfService = get(PiPipeconfService.class);
+
+        for (PiPipeconf piPipeconf : piPipeconfService.getPipeconfs()) {
+            if (shortOutput) {
+                print("id=%s", piPipeconf.id().toString());
+            } else {
+                print("id=%s, behaviors=%s, extensions=%s", piPipeconf.id().toString(),
+                      getBehaviors(piPipeconf), getExtensions(piPipeconf));
+            }
+        }
+    }
+
+    /**
+     * Get all behaviour of a pipeconf and converts a list of behaviour name to string.
+     *
+     * @param piPipeconf    query PiPipeconf
+     *
+     * @return string of behaviour name list
+     */
+    private String getBehaviors(PiPipeconf piPipeconf) {
+        Collection<Class<? extends Behaviour>> behaviours = piPipeconf.behaviours();
+        ArrayList<String> result = new ArrayList<>();
+
+        for (Class<? extends Behaviour> behaviour:behaviours) {
+            result.add(behaviour.getSimpleName());
+        }
+
+        return result.toString();
+    }
+
+    /**
+     * Get all extension of a pipeconf and converts a list of extension
+     * name to string.
+     *
+     * @param piPipeconf    query PiPipeconf
+     *
+     * @return string of extension name list
+     */
+    private String getExtensions(PiPipeconf piPipeconf) {
+        ArrayList<String> result = new ArrayList<>();
+
+        for (PiPipeconf.ExtensionType extensionType : PiPipeconf.ExtensionType.values()
+             ) {
+            if (piPipeconf.extension(extensionType).isPresent()) {
+                result.add(extensionType.name());
+            }
+        }
+
+        return result.toString();
+    }
+}
diff --git a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
index 99a458d..e67a8fb 100644
--- a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
+++ b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -718,6 +718,10 @@
         </command>
         -->
 
+        <command>
+            <action class="org.onosproject.cli.net.PipeconfCommand"/>
+        </command>
+
         <!--virtual network commands -->
         <command>
             <action class="org.onosproject.cli.net.vnet.TenantListCommand"/>