Committed by
Gerrit Code Review
Modified flows command to only output flows for specified device
for ONOS-1003 Change-Id: Ibbb313b80618bd9db806c2c63c50a6b45ccf800e
Showing
1 changed file
with
9 additions
and
10 deletions
... | @@ -19,7 +19,7 @@ import com.fasterxml.jackson.databind.JsonNode; | ... | @@ -19,7 +19,7 @@ import com.fasterxml.jackson.databind.JsonNode; |
19 | import com.fasterxml.jackson.databind.ObjectMapper; | 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
20 | import com.fasterxml.jackson.databind.node.ArrayNode; | 20 | import com.fasterxml.jackson.databind.node.ArrayNode; |
21 | import com.fasterxml.jackson.databind.node.ObjectNode; | 21 | import com.fasterxml.jackson.databind.node.ObjectNode; |
22 | -import com.google.common.collect.Maps; | 22 | + |
23 | import org.apache.karaf.shell.commands.Argument; | 23 | import org.apache.karaf.shell.commands.Argument; |
24 | import org.apache.karaf.shell.commands.Command; | 24 | import org.apache.karaf.shell.commands.Command; |
25 | import org.onosproject.core.CoreService; | 25 | import org.onosproject.core.CoreService; |
... | @@ -37,9 +37,10 @@ import org.onosproject.net.flow.instructions.Instruction; | ... | @@ -37,9 +37,10 @@ import org.onosproject.net.flow.instructions.Instruction; |
37 | import java.util.Collections; | 37 | import java.util.Collections; |
38 | import java.util.List; | 38 | import java.util.List; |
39 | import java.util.Map; | 39 | import java.util.Map; |
40 | +import java.util.SortedMap; | ||
41 | +import java.util.TreeMap; | ||
40 | 42 | ||
41 | import static com.google.common.collect.Lists.newArrayList; | 43 | import static com.google.common.collect.Lists.newArrayList; |
42 | -import static org.onosproject.cli.net.DevicesListCommand.getSortedDevices; | ||
43 | 44 | ||
44 | /** | 45 | /** |
45 | * Lists all currently-known hosts. | 46 | * Lists all currently-known hosts. |
... | @@ -68,14 +69,12 @@ public class FlowsListCommand extends AbstractShellCommand { | ... | @@ -68,14 +69,12 @@ public class FlowsListCommand extends AbstractShellCommand { |
68 | CoreService coreService = get(CoreService.class); | 69 | CoreService coreService = get(CoreService.class); |
69 | DeviceService deviceService = get(DeviceService.class); | 70 | DeviceService deviceService = get(DeviceService.class); |
70 | FlowRuleService service = get(FlowRuleService.class); | 71 | FlowRuleService service = get(FlowRuleService.class); |
71 | - Map<Device, List<FlowEntry>> flows = getSortedFlows(deviceService, service); | 72 | + SortedMap<Device, List<FlowEntry>> flows = getSortedFlows(deviceService, service); |
72 | 73 | ||
73 | if (outputJson()) { | 74 | if (outputJson()) { |
74 | - print("%s", json(coreService, getSortedDevices(deviceService), flows)); | 75 | + print("%s", json(coreService, flows.keySet(), flows)); |
75 | } else { | 76 | } else { |
76 | - for (Device d : getSortedDevices(deviceService)) { | 77 | + flows.forEach((device, flow) -> printFlows(device, flow, coreService)); |
77 | - printFlows(d, flows.get(d), coreService); | ||
78 | - } | ||
79 | } | 78 | } |
80 | } | 79 | } |
81 | 80 | ||
... | @@ -145,9 +144,9 @@ public class FlowsListCommand extends AbstractShellCommand { | ... | @@ -145,9 +144,9 @@ public class FlowsListCommand extends AbstractShellCommand { |
145 | * @param service flow rule service | 144 | * @param service flow rule service |
146 | * @return sorted device list | 145 | * @return sorted device list |
147 | */ | 146 | */ |
148 | - protected Map<Device, List<FlowEntry>> getSortedFlows(DeviceService deviceService, | 147 | + protected SortedMap<Device, List<FlowEntry>> getSortedFlows(DeviceService deviceService, |
149 | FlowRuleService service) { | 148 | FlowRuleService service) { |
150 | - Map<Device, List<FlowEntry>> flows = Maps.newHashMap(); | 149 | + SortedMap<Device, List<FlowEntry>> flows = new TreeMap<>(Comparators.ELEMENT_COMPARATOR); |
151 | List<FlowEntry> rules; | 150 | List<FlowEntry> rules; |
152 | FlowEntryState s = null; | 151 | FlowEntryState s = null; |
153 | if (state != null && !state.equals("any")) { | 152 | if (state != null && !state.equals("any")) { |
... | @@ -166,7 +165,7 @@ public class FlowsListCommand extends AbstractShellCommand { | ... | @@ -166,7 +165,7 @@ public class FlowsListCommand extends AbstractShellCommand { |
166 | } | 165 | } |
167 | } | 166 | } |
168 | } | 167 | } |
169 | - Collections.sort(rules, Comparators.FLOW_RULE_COMPARATOR); | 168 | + rules.sort(Comparators.FLOW_RULE_COMPARATOR); |
170 | flows.put(d, rules); | 169 | flows.put(d, rules); |
171 | } | 170 | } |
172 | return flows; | 171 | return flows; | ... | ... |
-
Please register or login to post a comment