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 {
public static final Comparator<FlowRule> FLOW_RULE_COMPARATOR = new Comparator<FlowRule>() {
@Override
public int compare(FlowRule f1, FlowRule f2) {
return Long.valueOf(f1.id().value()).compareTo(f2.id().value());
int tableCompare = Integer.valueOf(f1.tableId()).compareTo(f2.tableId());
return (tableCompare == 0)
? Long.valueOf(f1.id().value()).compareTo(f2.id().value())
: tableCompare;
}
};
......
......@@ -123,8 +123,14 @@ public class FlowsListCommand extends AbstractShellCommand {
if (state != null && !state.equals("any")) {
s = FlowEntryState.valueOf(state.toUpperCase());
}
Iterable<Device> devices = uri == null ? deviceService.getDevices() :
Collections.singletonList(deviceService.getDevice(DeviceId.deviceId(uri)));
Iterable<Device> devices = null;
if (uri == null) {
devices = deviceService.getDevices();
} else {
Device dev = deviceService.getDevice(DeviceId.deviceId(uri));
devices = (dev == null) ? deviceService.getDevices()
: Collections.singletonList(dev);
}
for (Device d : devices) {
if (s == null) {
rules = newArrayList(service.getFlowEntries(d.id()));
......