[CORD-2486] Improve Mcast CLI APIs

It adds following commands:
- sr-mcast-tree which shows the mapping group-tree
- sr-mcast-next which shows the mapping device-next
- mcast-routes which is similar to the unicast command (routes)

It improve following commands:
- mcast-join adds completer and improves output
- mcast-delete adds completer and improves output
- mcast-show improves output and adds completer

Change-Id: I4e273ac23b05142026b6b77317b0c9b7af76c3ec
diff --git a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/McastHandler.java b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/McastHandler.java
index a5ef34c..fff2c92 100644
--- a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/McastHandler.java
+++ b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/McastHandler.java
@@ -1351,4 +1351,103 @@
 
         }
     }
+
+    public Map<McastStoreKey, Integer> getMcastNextIds(IpAddress mcastIp) {
+        // If mcast ip is present
+        if (mcastIp != null) {
+            return mcastNextObjStore.entrySet().stream()
+                    .filter(mcastEntry -> mcastIp.equals(mcastEntry.getKey().mcastIp()))
+                    .collect(Collectors.toMap(Map.Entry::getKey,
+                                              entry -> entry.getValue().value().id()));
+        }
+        // Otherwise take all the groups
+        return mcastNextObjStore.entrySet().stream()
+                .collect(Collectors.toMap(Map.Entry::getKey,
+                                          entry -> entry.getValue().value().id()));
+    }
+
+    public Map<McastStoreKey, McastHandler.McastRole> getMcastRoles(IpAddress mcastIp) {
+        // If mcast ip is present
+        if (mcastIp != null) {
+            return mcastRoleStore.entrySet().stream()
+                    .filter(mcastEntry -> mcastIp.equals(mcastEntry.getKey().mcastIp()))
+                    .collect(Collectors.toMap(Map.Entry::getKey,
+                                              entry -> entry.getValue().value()));
+        }
+        // Otherwise take all the groups
+        return mcastRoleStore.entrySet().stream()
+                .collect(Collectors.toMap(Map.Entry::getKey,
+                                          entry -> entry.getValue().value()));
+    }
+
+    public Map<ConnectPoint, List<ConnectPoint>> getMcastPaths(IpAddress mcastIp) {
+        Map<ConnectPoint, List<ConnectPoint>> mcastPaths = Maps.newHashMap();
+        // Get the source
+        ConnectPoint source = getSource(mcastIp);
+        // Source cannot be null, we don't know the starting point
+        if (source != null) {
+            // Init steps
+            Set<DeviceId> visited = Sets.newHashSet();
+            List<ConnectPoint> currentPath = Lists.newArrayList(
+                    source
+            );
+            // Build recursively the mcast paths
+            buildMcastPaths(source.deviceId(), visited, mcastPaths, currentPath, mcastIp);
+        }
+        return mcastPaths;
+    }
+
+    private void buildMcastPaths(DeviceId toVisit, Set<DeviceId> visited,
+                                 Map<ConnectPoint, List<ConnectPoint>> mcastPaths,
+                                 List<ConnectPoint> currentPath, IpAddress mcastIp) {
+        // If we have visited the node to visit
+        // there is a loop
+        if (visited.contains(toVisit)) {
+            return;
+        }
+        // Visit next-hop
+        visited.add(toVisit);
+        McastStoreKey mcastStoreKey = new McastStoreKey(mcastIp, toVisit);
+        // Looking for next-hops
+        if (mcastNextObjStore.containsKey(mcastStoreKey)) {
+            // Build egress connectpoints
+            NextObjective nextObjective = mcastNextObjStore.get(mcastStoreKey).value();
+            // Get Ports
+            Set<PortNumber> outputPorts = getPorts(nextObjective.next());
+            // Build relative cps
+            ImmutableSet.Builder<ConnectPoint> cpBuilder = ImmutableSet.builder();
+            outputPorts.forEach(portNumber -> cpBuilder.add(new ConnectPoint(toVisit, portNumber)));
+            Set<ConnectPoint> egressPoints = cpBuilder.build();
+            // Define other variables for the next steps
+            Set<Link> egressLinks;
+            List<ConnectPoint> newCurrentPath;
+            Set<DeviceId> newVisited;
+            DeviceId newToVisit;
+            for (ConnectPoint egressPoint : egressPoints) {
+                egressLinks = srManager.linkService.getEgressLinks(egressPoint);
+                // If it does not have egress links, stop
+                if (egressLinks.isEmpty()) {
+                    // Add the connect points to the path
+                    newCurrentPath = Lists.newArrayList(currentPath);
+                    newCurrentPath.add(0, egressPoint);
+                    // Save in the map
+                    mcastPaths.put(egressPoint, newCurrentPath);
+                } else {
+                    newVisited = Sets.newHashSet(visited);
+                    // Iterate over the egress links for the next hops
+                    for (Link egressLink : egressLinks) {
+                        // Update to visit
+                        newToVisit = egressLink.dst().deviceId();
+                        // Add the connect points to the path
+                        newCurrentPath = Lists.newArrayList(currentPath);
+                        newCurrentPath.add(0, egressPoint);
+                        newCurrentPath.add(0, egressLink.dst());
+                        // Go to the next hop
+                        buildMcastPaths(newToVisit, newVisited, mcastPaths, newCurrentPath, mcastIp);
+                    }
+                }
+            }
+        }
+    }
+
 }
diff --git a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
index 4f85368..525f84a 100644
--- a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
+++ b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
@@ -105,6 +105,7 @@
 import org.onosproject.segmentrouting.pwaas.DefaultL2TunnelPolicy;
 import org.onosproject.segmentrouting.pwaas.L2TunnelHandler;
 import org.onosproject.segmentrouting.storekey.DestinationSetNextObjectiveStoreKey;
+import org.onosproject.segmentrouting.storekey.McastStoreKey;
 import org.onosproject.segmentrouting.storekey.PortNextObjectiveStoreKey;
 import org.onosproject.segmentrouting.storekey.VlanNextObjectiveStoreKey;
 import org.onosproject.segmentrouting.storekey.XConnectStoreKey;
@@ -662,6 +663,21 @@
         return linkHandler.getDownedPorts();
     }
 
+    @Override
+    public Map<McastStoreKey, Integer> getMcastNextIds(IpAddress mcastIp) {
+        return mcastHandler.getMcastNextIds(mcastIp);
+    }
+
+    @Override
+    public Map<McastStoreKey, McastHandler.McastRole> getMcastRoles(IpAddress mcastIp) {
+        return mcastHandler.getMcastRoles(mcastIp);
+    }
+
+    @Override
+    public Map<ConnectPoint, List<ConnectPoint>> getMcastPaths(IpAddress mcastIp) {
+        return mcastHandler.getMcastPaths(mcastIp);
+    }
+
     /**
      * Extracts the application ID from the manager.
      *
diff --git a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingService.java b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingService.java
index 3269657..00e7a6a 100644
--- a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingService.java
+++ b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingService.java
@@ -15,7 +15,9 @@
  */
 package org.onosproject.segmentrouting;
 
+import org.onlab.packet.IpAddress;
 import org.onlab.packet.IpPrefix;
+import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.Link;
 import org.onosproject.net.PortNumber;
@@ -26,6 +28,7 @@
 import org.onosproject.segmentrouting.storekey.DestinationSetNextObjectiveStoreKey;
 
 import com.google.common.collect.ImmutableMap;
+import org.onosproject.segmentrouting.storekey.McastStoreKey;
 
 import java.util.List;
 import java.util.Map;
@@ -207,4 +210,31 @@
      *         ports. Does not include ports manually disabled by the operator.
      */
     ImmutableMap<DeviceId, Set<PortNumber>> getDownedPortState();
+
+   /**
+     * Returns the associated next ids to the mcast groups or to the single
+     * group if mcastIp is present.
+     *
+     * @param mcastIp the group ip
+     * @return the mapping mcastIp-device to next id
+     */
+    Map<McastStoreKey, Integer> getMcastNextIds(IpAddress mcastIp);
+
+    /**
+     * Returns the associated roles to the mcast groups or to the single
+     * group if mcastIp is present.
+     *
+     * @param mcastIp the group ip
+     * @return the mapping mcastIp-device to mcast role
+     */
+    Map<McastStoreKey, McastHandler.McastRole> getMcastRoles(IpAddress mcastIp);
+
+    /**
+     * Returns the associated paths to the mcast group.
+     *
+     * @param mcastIp the group ip
+     * @return the mapping egress point to mcast path
+     */
+    Map<ConnectPoint, List<ConnectPoint>> getMcastPaths(IpAddress mcastIp);
+
 }
diff --git a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/cli/McastNextListCommand.java b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/cli/McastNextListCommand.java
new file mode 100644
index 0000000..341c87d
--- /dev/null
+++ b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/cli/McastNextListCommand.java
@@ -0,0 +1,81 @@
+/*
+ * 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.segmentrouting.cli;
+
+import com.google.common.collect.Maps;
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onlab.packet.IpAddress;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.DeviceId;
+import org.onosproject.segmentrouting.SegmentRoutingService;
+import org.onosproject.segmentrouting.storekey.McastStoreKey;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static com.google.common.base.Strings.isNullOrEmpty;
+
+/**
+ * Command to show the list of mcast nextids.
+ */
+@Command(scope = "onos", name = "sr-mcast-next",
+        description = "Lists all mcast nextids")
+public class McastNextListCommand extends AbstractShellCommand {
+
+    // Format for group line
+    private static final String FORMAT_MAPPING = "group=%s, deviceIds-nextIds=%s";
+
+    @Argument(index = 0, name = "mcastIp", description = "mcast Ip",
+            required = false, multiValued = false)
+    String mcastIp;
+
+    @Override
+    protected void execute() {
+        // Verify mcast group
+        IpAddress mcastGroup = null;
+        if (!isNullOrEmpty(mcastIp)) {
+            mcastGroup = IpAddress.valueOf(mcastIp);
+
+        }
+        // Get SR service
+        SegmentRoutingService srService = get(SegmentRoutingService.class);
+        // Get the mapping
+        Map<McastStoreKey, Integer> keyToNextId = srService.getMcastNextIds(mcastGroup);
+        // Reduce to the set of mcast groups
+        Set<IpAddress> mcastGroups = keyToNextId.keySet().stream()
+                .map(McastStoreKey::mcastIp)
+                .collect(Collectors.toSet());
+        // Print the nextids for each group
+        mcastGroups.forEach(group -> {
+            // Create a new map for the group
+            Map<DeviceId, Integer> deviceIdNextMap = Maps.newHashMap();
+            keyToNextId.entrySet()
+                    .stream()
+                    // Filter only the elements related to this group
+                    .filter(entry -> entry.getKey().mcastIp().equals(group))
+                    // For each create a new entry in the group related map
+                    .forEach(entry -> deviceIdNextMap.put(entry.getKey().deviceId(), entry.getValue()));
+            // Print the map
+            printMcastNext(group, deviceIdNextMap);
+        });
+    }
+
+    private void printMcastNext(IpAddress mcastGroup, Map<DeviceId, Integer> deviceIdNextMap) {
+        print(FORMAT_MAPPING, mcastGroup, deviceIdNextMap);
+    }
+}
diff --git a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/cli/McastTreeListCommand.java b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/cli/McastTreeListCommand.java
new file mode 100644
index 0000000..73cbb1a
--- /dev/null
+++ b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/cli/McastTreeListCommand.java
@@ -0,0 +1,107 @@
+/*
+ * 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.segmentrouting.cli;
+
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onlab.packet.IpAddress;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DeviceId;
+import org.onosproject.segmentrouting.McastHandler.McastRole;
+import org.onosproject.segmentrouting.SegmentRoutingService;
+import org.onosproject.segmentrouting.storekey.McastStoreKey;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static com.google.common.base.Strings.isNullOrEmpty;
+import static org.onosproject.segmentrouting.McastHandler.McastRole.EGRESS;
+import static org.onosproject.segmentrouting.McastHandler.McastRole.INGRESS;
+import static org.onosproject.segmentrouting.McastHandler.McastRole.TRANSIT;
+
+/**
+ * Command to show the list of mcast trees.
+ */
+@Command(scope = "onos", name = "sr-mcast-tree",
+        description = "Lists all mcast trees")
+public class McastTreeListCommand extends AbstractShellCommand {
+
+    // Format for group line
+    private static final String G_FORMAT_MAPPING = "group=%s, ingress=%s, transit=%s, egress=%s";
+    // Format for sink line
+    private static final String S_FORMAT_MAPPING = "\tsink=%s\tpath=%s";
+
+    @Argument(index = 0, name = "mcastIp", description = "mcast Ip",
+            required = false, multiValued = false)
+    String mcastIp;
+
+    @Override
+    protected void execute() {
+        // Verify mcast group
+        IpAddress mcastGroup = null;
+        if (!isNullOrEmpty(mcastIp)) {
+            mcastGroup = IpAddress.valueOf(mcastIp);
+
+        }
+        // Get SR service
+        SegmentRoutingService srService = get(SegmentRoutingService.class);
+        // Get the mapping
+        Map<McastStoreKey, McastRole> keyToRole = srService.getMcastRoles(mcastGroup);
+        // Reduce to the set of mcast groups
+        Set<IpAddress> mcastGroups = keyToRole.keySet().stream()
+                .map(McastStoreKey::mcastIp)
+                .collect(Collectors.toSet());
+        // Print the trees for each group
+        mcastGroups.forEach(group -> {
+            // Create a new map for the group
+            Multimap<McastRole, DeviceId> roleDeviceIdMap = ArrayListMultimap.create();
+            keyToRole.entrySet()
+                    .stream()
+                    // Filter only the elements related to this group
+                    .filter(entry -> entry.getKey().mcastIp().equals(group))
+                    // For each create a new entry in the group related map
+                    .forEach(entry -> roleDeviceIdMap.put(entry.getValue(), entry.getKey().deviceId()));
+            // Print the map
+            printMcastRole(group,
+                           roleDeviceIdMap.get(INGRESS),
+                           roleDeviceIdMap.get(TRANSIT),
+                           roleDeviceIdMap.get(EGRESS)
+            );
+            // Get sinks paths
+            Map<ConnectPoint, List<ConnectPoint>> mcastPaths = srService.getMcastPaths(group);
+            // Print the paths
+            mcastPaths.forEach(this::printMcastSink);
+        });
+    }
+
+    private void printMcastRole(IpAddress mcastGroup,
+                                Collection<DeviceId> ingress,
+                                Collection<DeviceId> transit,
+                                Collection<DeviceId> egress) {
+        print(G_FORMAT_MAPPING, mcastGroup, ingress, transit, egress);
+    }
+
+    private void printMcastSink(ConnectPoint sink, List<ConnectPoint> path) {
+        print(S_FORMAT_MAPPING, sink, path);
+    }
+}
diff --git a/apps/segmentrouting/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/apps/segmentrouting/src/main/resources/OSGI-INF/blueprint/shell-config.xml
index 56b6f43..cfd7502 100644
--- a/apps/segmentrouting/src/main/resources/OSGI-INF/blueprint/shell-config.xml
+++ b/apps/segmentrouting/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -69,10 +69,26 @@
         <command>
             <action class="org.onosproject.segmentrouting.cli.LinkStateCommand"/>
         </command>
+        <command>
+            <action class="org.onosproject.segmentrouting.cli.McastNextListCommand"/>
+            <completers>
+                <ref component-id="mcastGroupCompleter"/>
+                <ref component-id="nullCompleter"/>
+            </completers>
+        </command>
+        <command>
+            <action class="org.onosproject.segmentrouting.cli.McastTreeListCommand"/>
+            <completers>
+                <ref component-id="mcastGroupCompleter"/>
+                <ref component-id="nullCompleter"/>
+            </completers>
+        </command>
     </command-bundle>
 
+    <bean id="nullCompleter" class="org.apache.karaf.shell.console.completer.NullCompleter"/>
     <bean id="deviceIdCompleter" class="org.onosproject.cli.net.DeviceIdCompleter"/>
     <bean id="pseudowireIdCompleter" class="org.onosproject.segmentrouting.cli.PseudowireIdCompleter"/>
+    <bean id="mcastGroupCompleter" class="org.onosproject.cli.net.McastGroupCompleter"/>
 
 </blueprint>
 
diff --git a/cli/src/main/java/org/onosproject/cli/net/McastDeleteCommand.java b/cli/src/main/java/org/onosproject/cli/net/McastDeleteCommand.java
index 5c34f9e..26dbfde 100644
--- a/cli/src/main/java/org/onosproject/cli/net/McastDeleteCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/McastDeleteCommand.java
@@ -30,6 +30,14 @@
         description = "Delete a multicast route flow")
 public class McastDeleteCommand extends AbstractShellCommand {
 
+    // Delete format for group line
+    private static final String D_FORMAT_MAPPING = "Deleted the mcast route: " +
+            "origin=%s, group=%s, source=%s";
+
+    // Update format for group line
+    private static final String U_FORMAT_MAPPING = "Updated the mcast route: " +
+            "origin=%s, group=%s, source=%s";
+
     @Argument(index = 0, name = "sAddr",
             description = "IP Address of the multicast source. '*' can be used for any source (*, G) entry",
             required = true, multiValued = false)
@@ -61,12 +69,14 @@
 
         if (egressList == null) {
             mcastRouteManager.remove(mRoute);
+            print(D_FORMAT_MAPPING, mRoute.type(), mRoute.group(), mRoute.source());
         } else {
             // check list for validity before we begin to delete.
             for (String egress : egressList) {
                 ConnectPoint eCp = ConnectPoint.deviceConnectPoint(egress);
                 mcastRouteManager.removeSink(mRoute, eCp);
             }
+            print(U_FORMAT_MAPPING, mRoute.type(), mRoute.group(), mRoute.source());
         }
     }
 }
diff --git a/cli/src/main/java/org/onosproject/cli/net/McastGroupCompleter.java b/cli/src/main/java/org/onosproject/cli/net/McastGroupCompleter.java
new file mode 100644
index 0000000..6700b97
--- /dev/null
+++ b/cli/src/main/java/org/onosproject/cli/net/McastGroupCompleter.java
@@ -0,0 +1,44 @@
+/*
+ * 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.onlab.packet.IpAddress;
+import org.onlab.util.Tools;
+import org.onosproject.cli.AbstractChoicesCompleter;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.mcast.McastRoute;
+import org.onosproject.net.mcast.MulticastRouteService;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * Mcast group Completer.
+ */
+public class McastGroupCompleter extends AbstractChoicesCompleter {
+
+    @Override
+    protected List<String> choices() {
+        MulticastRouteService service = AbstractShellCommand.get(MulticastRouteService.class);
+
+        return Tools.stream(service.getRoutes())
+            .map(McastRoute::group)
+            .map(IpAddress::toString)
+            .collect(Collectors.toList());
+    }
+
+}
diff --git a/cli/src/main/java/org/onosproject/cli/net/McastJoinCommand.java b/cli/src/main/java/org/onosproject/cli/net/McastJoinCommand.java
index f0dc33e..83969a8 100644
--- a/cli/src/main/java/org/onosproject/cli/net/McastJoinCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/McastJoinCommand.java
@@ -30,6 +30,10 @@
          description = "Installs a source, multicast group flow")
 public class McastJoinCommand extends AbstractShellCommand {
 
+    // Format for group line
+    private static final String FORMAT_MAPPING = "Added the mcast route: " +
+            "origin=%s, group=%s, source=%s";
+
     @Argument(index = 0, name = "sAddr",
               description = "IP Address of the multicast source. '*' can be used for any source (*, G) entry",
               required = true, multiValued = false)
@@ -54,7 +58,6 @@
     protected void execute() {
         MulticastRouteService mcastRouteManager = get(MulticastRouteService.class);
 
-        //McastRoute mRoute = McastForwarding.createStaticRoute(sAddr, gAddr);
         McastRoute mRoute = new McastRoute(IpAddress.valueOf(sAddr),
                 IpAddress.valueOf(gAddr), McastRoute.Type.STATIC);
         mcastRouteManager.add(mRoute);
@@ -66,12 +69,15 @@
 
         if (ports != null) {
             for (String egCP : ports) {
-                log.debug("Egress port provided: " + egCP);
                 ConnectPoint egress = ConnectPoint.deviceConnectPoint(egCP);
                 mcastRouteManager.addSink(mRoute, egress);
 
             }
         }
-        print("Added the mcast route: %s", mRoute);
+        printMcastRoute(mRoute);
+    }
+
+    private void printMcastRoute(McastRoute mcastRoute) {
+        print(FORMAT_MAPPING, mcastRoute.type(), mcastRoute.group(), mcastRoute.source());
     }
 }
diff --git a/cli/src/main/java/org/onosproject/cli/net/McastRoutesListCommand.java b/cli/src/main/java/org/onosproject/cli/net/McastRoutesListCommand.java
new file mode 100644
index 0000000..003e53c
--- /dev/null
+++ b/cli/src/main/java/org/onosproject/cli/net/McastRoutesListCommand.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.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.mcast.McastRoute;
+import org.onosproject.net.mcast.MulticastRouteService;
+
+import java.util.Comparator;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Displays the source, multicast group flows entries.
+ */
+@Command(scope = "onos", name = "mcast-routes",
+        description = "Lists routes in the mcast route store")
+public class McastRoutesListCommand extends AbstractShellCommand {
+
+    // Format for total
+    private static final String FORMAT_TOTAL = "   Total: %d";
+
+    // Format for ipv4
+    private static final String FORMAT_ROUTE = "%-1s   %-18s %-15s %s   %s";
+    // Format for ipv6
+    private static final String FORMAT_ROUTE6 = "%-1s   %-40s %-36s %s   %s";
+
+    // Table header
+    private static final String FORMAT_TABLE = "Table: %s";
+    private static final String GROUP = "Group";
+    private static final String SOURCE = "Source";
+    private static final String ORIGIN = "Origin";
+    private static final String SINKS = "Sinks";
+
+    @Override
+    protected void execute() {
+        // Get the service
+        MulticastRouteService mcastService = get(MulticastRouteService.class);
+        // Get the routes
+        Set<McastRoute> routes = mcastService.getRoutes();
+        // Filter ipv4
+        Set<McastRoute> ipv4Routes = routes.stream()
+                .filter(mcastRoute -> mcastRoute.group().isIp4())
+                .collect(Collectors.toSet());
+        // Filter ipv6
+        Set<McastRoute> ipv6Routes = routes.stream()
+                .filter(mcastRoute -> mcastRoute.group().isIp6())
+                .collect(Collectors.toSet());
+        // Print header
+        print(FORMAT_TABLE, "ipv4");
+        print(FORMAT_ROUTE, "", GROUP, SOURCE, ORIGIN, SINKS);
+        // Print ipv4 mcast routing entries
+        ipv4Routes.stream()
+                .sorted(Comparator.comparing(McastRoute::group))
+                .forEach(route -> {
+                    // Get sinks
+                    Set<ConnectPoint> sinks = mcastService.fetchSinks(route);
+                    print(FORMAT_ROUTE, "", route.group(), route.source(),
+                          route.type(), sinks.size());
+                });
+        print(FORMAT_TOTAL, ipv4Routes.size());
+        print("");
+
+        // Print header
+        print(FORMAT_TABLE, "ipv6");
+        print(FORMAT_ROUTE6, "", GROUP, SOURCE, ORIGIN, SINKS);
+        // Print ipv6 mcast routing entries
+        ipv6Routes.stream()
+                .sorted(Comparator.comparing(McastRoute::group))
+                .forEach(route -> {
+                    // Get sinks
+                    Set<ConnectPoint> sinks = mcastService.fetchSinks(route);
+                    print(FORMAT_ROUTE6, "", route.group(), route.source(),
+                          route.type(), sinks.size());
+                });
+        print(FORMAT_TOTAL, ipv6Routes.size());
+        print("");
+    }
+
+
+
+}
diff --git a/cli/src/main/java/org/onosproject/cli/net/McastShowCommand.java b/cli/src/main/java/org/onosproject/cli/net/McastShowCommand.java
index cae0bd5..91ab0c4 100644
--- a/cli/src/main/java/org/onosproject/cli/net/McastShowCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/McastShowCommand.java
@@ -15,13 +15,19 @@
  */
 package org.onosproject.cli.net;
 
+import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
+import org.onlab.packet.IpAddress;
 import org.onosproject.cli.AbstractShellCommand;
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.mcast.McastRoute;
 import org.onosproject.net.mcast.MulticastRouteService;
 
+import java.util.Comparator;
 import java.util.Set;
+import java.util.stream.Collectors;
+
+import static com.google.common.base.Strings.isNullOrEmpty;
 
 /**
  * Displays the source, multicast group flows entries.
@@ -29,20 +35,61 @@
 @Command(scope = "onos", name = "mcast-show", description = "Displays the source, multicast group flows")
 public class McastShowCommand extends AbstractShellCommand {
 
-    private static final String FORMAT = "route=%s, source=%s, sinks=%s";
+    // Format for group line
+    private static final String FORMAT_MAPPING = "origin=%s, group=%s, source=%s, sinks=%s";
+
+    @Argument(index = 0, name = "mcastIp", description = "mcast Ip",
+            required = false, multiValued = false)
+    String mcastIp;
 
     @Override
     protected void execute() {
+        // Get the service
         MulticastRouteService mcastService = get(MulticastRouteService.class);
-
+        // Get the routes
         Set<McastRoute> routes = mcastService.getRoutes();
-
-        for (McastRoute route : routes) {
-            Set<ConnectPoint> sinks = mcastService.fetchSinks(route);
-            ConnectPoint source = mcastService.fetchSource(route);
-
-            print(FORMAT, route, source, sinks);
+        // Verify mcast group
+        if (!isNullOrEmpty(mcastIp)) {
+            // Let's find the group
+            IpAddress mcastGroup = IpAddress.valueOf(mcastIp);
+            McastRoute mcastRoute = routes.stream()
+                    .filter(route -> route.group().equals(mcastGroup))
+                    .findAny().orElse(null);
+            // If it exists
+            if (mcastRoute != null) {
+                // Get the sinks and print info
+                Set<ConnectPoint> sinks = mcastService.fetchSinks(mcastRoute);
+                print(FORMAT_MAPPING, mcastRoute.type(), mcastRoute.group(),
+                      mcastRoute.source(), sinks);
+            }
+            return;
         }
+        // Filter ipv4
+        Set<McastRoute> ipv4Routes = routes.stream()
+                .filter(mcastRoute -> mcastRoute.group().isIp4())
+                .collect(Collectors.toSet());
+        // Print ipv4 first
+        ipv4Routes.stream()
+                .sorted(Comparator.comparing(McastRoute::group))
+                .forEach(route -> {
+                    // Get sinks
+                    Set<ConnectPoint> sinks = mcastService.fetchSinks(route);
+                    print(FORMAT_MAPPING, route.type(), route.group(),
+                          route.source(), sinks);
+                });
+        // Filter ipv6
+        Set<McastRoute> ipv6Routes = routes.stream()
+                .filter(mcastRoute -> mcastRoute.group().isIp6())
+                .collect(Collectors.toSet());
+        // Then print ipv6
+        ipv6Routes.stream()
+                .sorted(Comparator.comparing(McastRoute::group))
+                .forEach(route -> {
+                    // Get sinks
+                    Set<ConnectPoint> sinks = mcastService.fetchSinks(route);
+                    print(FORMAT_MAPPING, route.type(), route.group(),
+                          route.source(), sinks);
+                });
     }
 
 }
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 9033d43..3fab2f9 100644
--- a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
+++ b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -116,12 +116,31 @@
 
         <command>
             <action class="org.onosproject.cli.net.McastShowCommand"/>
+            <completers>
+                <ref component-id="mcastGroupCompleter"/>
+            </completers>
+        </command>
+        <command>
+            <action class="org.onosproject.cli.net.McastRoutesListCommand"/>
+            <completers>
+                <ref component-id="mcastGroupCompleter"/>
+            </completers>
         </command>
         <command>
             <action class="org.onosproject.cli.net.McastJoinCommand"/>
+            <completers>
+                <ref component-id="placeholderCompleter"/>
+                <ref component-id="mcastGroupCompleter"/>
+                <ref component-id="connectPointCompleter"/>
+            </completers>
         </command>
         <command>
             <action class="org.onosproject.cli.net.McastDeleteCommand"/>
+            <completers>
+                <ref component-id="placeholderCompleter"/>
+                <ref component-id="mcastGroupCompleter"/>
+                <ref component-id="connectPointCompleter"/>
+            </completers>
         </command>
 
         <command>
@@ -968,4 +987,6 @@
 
     <bean id="domainIdCompleter" class="org.onosproject.cli.net.DomainIdCompleter" />
 
+    <bean id="mcastGroupCompleter" class="org.onosproject.cli.net.McastGroupCompleter"/>
+
 </blueprint>