Committed by
Gerrit Code Review
Add an option to flows/groups command that print flow/group count only
Change-Id: Iaf66eac2fffbb14756d48164f8469e4afa1b9fb8
Showing
2 changed files
with
17 additions
and
1 deletions
... | @@ -78,6 +78,11 @@ public class FlowsListCommand extends AbstractShellCommand { | ... | @@ -78,6 +78,11 @@ public class FlowsListCommand extends AbstractShellCommand { |
78 | required = false, multiValued = false) | 78 | required = false, multiValued = false) |
79 | private boolean shortOutput = false; | 79 | private boolean shortOutput = false; |
80 | 80 | ||
81 | + @Option(name = "-c", aliases = "--count", | ||
82 | + description = "Print flow count only", | ||
83 | + required = false, multiValued = false) | ||
84 | + private boolean countOnly = false; | ||
85 | + | ||
81 | private Predicate<FlowEntry> predicate = TRUE_PREDICATE; | 86 | private Predicate<FlowEntry> predicate = TRUE_PREDICATE; |
82 | 87 | ||
83 | @Override | 88 | @Override |
... | @@ -193,7 +198,7 @@ public class FlowsListCommand extends AbstractShellCommand { | ... | @@ -193,7 +198,7 @@ public class FlowsListCommand extends AbstractShellCommand { |
193 | CoreService coreService) { | 198 | CoreService coreService) { |
194 | boolean empty = flows == null || flows.isEmpty(); | 199 | boolean empty = flows == null || flows.isEmpty(); |
195 | print("deviceId=%s, flowRuleCount=%d", d.id(), empty ? 0 : flows.size()); | 200 | print("deviceId=%s, flowRuleCount=%d", d.id(), empty ? 0 : flows.size()); |
196 | - if (empty) { | 201 | + if (empty || countOnly) { |
197 | return; | 202 | return; |
198 | } | 203 | } |
199 | 204 | ... | ... |
... | @@ -23,6 +23,7 @@ import java.util.TreeMap; | ... | @@ -23,6 +23,7 @@ import java.util.TreeMap; |
23 | 23 | ||
24 | import org.apache.karaf.shell.commands.Argument; | 24 | import org.apache.karaf.shell.commands.Argument; |
25 | import org.apache.karaf.shell.commands.Command; | 25 | import org.apache.karaf.shell.commands.Command; |
26 | +import org.apache.karaf.shell.commands.Option; | ||
26 | import org.onosproject.cli.AbstractShellCommand; | 27 | import org.onosproject.cli.AbstractShellCommand; |
27 | import org.onosproject.cli.Comparators; | 28 | import org.onosproject.cli.Comparators; |
28 | import org.onosproject.net.Device; | 29 | import org.onosproject.net.Device; |
... | @@ -60,6 +61,11 @@ public class GroupsListCommand extends AbstractShellCommand { | ... | @@ -60,6 +61,11 @@ public class GroupsListCommand extends AbstractShellCommand { |
60 | required = false, multiValued = false) | 61 | required = false, multiValued = false) |
61 | String state; | 62 | String state; |
62 | 63 | ||
64 | + @Option(name = "-c", aliases = "--count", | ||
65 | + description = "Print group count only", | ||
66 | + required = false, multiValued = false) | ||
67 | + private boolean countOnly = false; | ||
68 | + | ||
63 | private JsonNode json(Map<Device, List<Group>> sortedGroups) { | 69 | private JsonNode json(Map<Device, List<Group>> sortedGroups) { |
64 | ArrayNode result = mapper().createArrayNode(); | 70 | ArrayNode result = mapper().createArrayNode(); |
65 | 71 | ||
... | @@ -122,6 +128,11 @@ public class GroupsListCommand extends AbstractShellCommand { | ... | @@ -122,6 +128,11 @@ public class GroupsListCommand extends AbstractShellCommand { |
122 | 128 | ||
123 | private void printGroups(DeviceId deviceId, List<Group> groups) { | 129 | private void printGroups(DeviceId deviceId, List<Group> groups) { |
124 | print("deviceId=%s, groupCount=%s", deviceId, groups.size()); | 130 | print("deviceId=%s, groupCount=%s", deviceId, groups.size()); |
131 | + | ||
132 | + if (countOnly) { | ||
133 | + return; | ||
134 | + } | ||
135 | + | ||
125 | for (Group group : groups) { | 136 | for (Group group : groups) { |
126 | print(FORMAT, Integer.toHexString(group.id().id()), group.state(), group.type(), | 137 | print(FORMAT, Integer.toHexString(group.id().id()), group.state(), group.type(), |
127 | group.bytes(), group.packets(), group.appId().name()); | 138 | group.bytes(), group.packets(), group.appId().name()); | ... | ... |
-
Please register or login to post a comment