Saurav Das
Committed by Gerrit Code Review

Fixes NPE in CLI when user enters non-existent DPID in "flows any <dpid>" command.

Sorts flows according to table-id first, and then flow-id, so all flows
from the same table print together.

Change-Id: I4a811a00a1dc0e1e2f2855c06f5f7f9851152c0d
...@@ -71,7 +71,10 @@ public final class Comparators { ...@@ -71,7 +71,10 @@ public final class Comparators {
71 public static final Comparator<FlowRule> FLOW_RULE_COMPARATOR = new Comparator<FlowRule>() { 71 public static final Comparator<FlowRule> FLOW_RULE_COMPARATOR = new Comparator<FlowRule>() {
72 @Override 72 @Override
73 public int compare(FlowRule f1, FlowRule f2) { 73 public int compare(FlowRule f1, FlowRule f2) {
74 - return Long.valueOf(f1.id().value()).compareTo(f2.id().value()); 74 + int tableCompare = Integer.valueOf(f1.tableId()).compareTo(f2.tableId());
75 + return (tableCompare == 0)
76 + ? Long.valueOf(f1.id().value()).compareTo(f2.id().value())
77 + : tableCompare;
75 } 78 }
76 }; 79 };
77 80
......
...@@ -123,8 +123,14 @@ public class FlowsListCommand extends AbstractShellCommand { ...@@ -123,8 +123,14 @@ public class FlowsListCommand extends AbstractShellCommand {
123 if (state != null && !state.equals("any")) { 123 if (state != null && !state.equals("any")) {
124 s = FlowEntryState.valueOf(state.toUpperCase()); 124 s = FlowEntryState.valueOf(state.toUpperCase());
125 } 125 }
126 - Iterable<Device> devices = uri == null ? deviceService.getDevices() : 126 + Iterable<Device> devices = null;
127 - Collections.singletonList(deviceService.getDevice(DeviceId.deviceId(uri))); 127 + if (uri == null) {
128 + devices = deviceService.getDevices();
129 + } else {
130 + Device dev = deviceService.getDevice(DeviceId.deviceId(uri));
131 + devices = (dev == null) ? deviceService.getDevices()
132 + : Collections.singletonList(dev);
133 + }
128 for (Device d : devices) { 134 for (Device d : devices) {
129 if (s == null) { 135 if (s == null) {
130 rules = newArrayList(service.getFlowEntries(d.id())); 136 rules = newArrayList(service.getFlowEntries(d.id()));
......