Charles Chan
Committed by Gerrit Code Review

Add an option to flows/groups command that print flow/group count only

Change-Id: Iaf66eac2fffbb14756d48164f8469e4afa1b9fb8
......@@ -78,6 +78,11 @@ public class FlowsListCommand extends AbstractShellCommand {
required = false, multiValued = false)
private boolean shortOutput = false;
@Option(name = "-c", aliases = "--count",
description = "Print flow count only",
required = false, multiValued = false)
private boolean countOnly = false;
private Predicate<FlowEntry> predicate = TRUE_PREDICATE;
@Override
......@@ -193,7 +198,7 @@ public class FlowsListCommand extends AbstractShellCommand {
CoreService coreService) {
boolean empty = flows == null || flows.isEmpty();
print("deviceId=%s, flowRuleCount=%d", d.id(), empty ? 0 : flows.size());
if (empty) {
if (empty || countOnly) {
return;
}
......
......@@ -23,6 +23,7 @@ import java.util.TreeMap;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.commands.Option;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.cli.Comparators;
import org.onosproject.net.Device;
......@@ -60,6 +61,11 @@ public class GroupsListCommand extends AbstractShellCommand {
required = false, multiValued = false)
String state;
@Option(name = "-c", aliases = "--count",
description = "Print group count only",
required = false, multiValued = false)
private boolean countOnly = false;
private JsonNode json(Map<Device, List<Group>> sortedGroups) {
ArrayNode result = mapper().createArrayNode();
......@@ -122,6 +128,11 @@ public class GroupsListCommand extends AbstractShellCommand {
private void printGroups(DeviceId deviceId, List<Group> groups) {
print("deviceId=%s, groupCount=%s", deviceId, groups.size());
if (countOnly) {
return;
}
for (Group group : groups) {
print(FORMAT, Integer.toHexString(group.id().id()), group.state(), group.type(),
group.bytes(), group.packets(), group.appId().name());
......