tom

Enhanced the CLIs.

...@@ -38,7 +38,7 @@ public class DevicePortsListCommand extends DevicesListCommand { ...@@ -38,7 +38,7 @@ public class DevicePortsListCommand extends DevicesListCommand {
38 protected Object doExecute() throws Exception { 38 protected Object doExecute() throws Exception {
39 DeviceService service = getService(DeviceService.class); 39 DeviceService service = getService(DeviceService.class);
40 if (uri == null) { 40 if (uri == null) {
41 - for (Device device : service.getDevices()) { 41 + for (Device device : getSortedDevices(service)) {
42 printDevicePorts(service, device); 42 printDevicePorts(service, device);
43 } 43 }
44 } else { 44 } else {
......
...@@ -5,6 +5,12 @@ import org.onlab.onos.cli.AbstractShellCommand; ...@@ -5,6 +5,12 @@ import org.onlab.onos.cli.AbstractShellCommand;
5 import org.onlab.onos.net.Device; 5 import org.onlab.onos.net.Device;
6 import org.onlab.onos.net.device.DeviceService; 6 import org.onlab.onos.net.device.DeviceService;
7 7
8 +import java.util.Collections;
9 +import java.util.Comparator;
10 +import java.util.List;
11 +
12 +import static com.google.common.collect.Lists.newArrayList;
13 +
8 /** 14 /**
9 * Lists all infrastructure devices. 15 * Lists all infrastructure devices.
10 */ 16 */
...@@ -15,16 +21,35 @@ public class DevicesListCommand extends AbstractShellCommand { ...@@ -15,16 +21,35 @@ public class DevicesListCommand extends AbstractShellCommand {
15 private static final String FMT = 21 private static final String FMT =
16 "id=%s, available=%s, type=%s, mfr=%s, hw=%s, sw=%s, serial=%s"; 22 "id=%s, available=%s, type=%s, mfr=%s, hw=%s, sw=%s, serial=%s";
17 23
24 + protected static final Comparator<Device> ID_COMPARATOR = new Comparator<Device>() {
25 + @Override
26 + public int compare(Device d1, Device d2) {
27 + return d1.id().uri().toString().compareTo(d2.id().uri().toString());
28 + }
29 + };
30 +
18 @Override 31 @Override
19 protected Object doExecute() throws Exception { 32 protected Object doExecute() throws Exception {
20 DeviceService service = getService(DeviceService.class); 33 DeviceService service = getService(DeviceService.class);
21 - for (Device device : service.getDevices()) { 34 + for (Device device : getSortedDevices(service)) {
22 printDevice(device, service.isAvailable(device.id())); 35 printDevice(device, service.isAvailable(device.id()));
23 } 36 }
24 return null; 37 return null;
25 } 38 }
26 39
27 /** 40 /**
41 + * Returns the list of devices sorted using the device ID URIs.
42 + *
43 + * @param service device service
44 + * @return sorted device list
45 + */
46 + protected List<Device> getSortedDevices(DeviceService service) {
47 + List<Device> devices = newArrayList(service.getDevices());
48 + Collections.sort(devices, ID_COMPARATOR);
49 + return devices;
50 + }
51 +
52 + /**
28 * Prints information about the specified device. 53 * Prints information about the specified device.
29 * 54 *
30 * @param device infrastructure device 55 * @param device infrastructure device
......