tom

Enhanced the CLIs.

......@@ -14,15 +14,15 @@ import java.util.List;
import static org.onlab.onos.net.DeviceId.deviceId;
/**
* Lists all infrastructure links.
* Lists all ports or all ports of a device.
*/
@Command(scope = "onos", name = "ports",
description = "Lists all ports of a device")
description = "Lists all ports or all ports of a device")
public class DevicePortsListCommand extends DevicesListCommand {
private static final String FMT = " port=%s, state=%s";
@Argument(index = 0, name = "deviceId", description = "Device ID",
@Argument(index = 0, name = "uri", description = "Device ID",
required = false, multiValued = false)
String uri = null;
......@@ -39,18 +39,19 @@ public class DevicePortsListCommand extends DevicesListCommand {
DeviceService service = getService(DeviceService.class);
if (uri == null) {
for (Device device : getSortedDevices(service)) {
printDevicePorts(service, device);
printDevice(service, device);
}
} else {
printDevicePorts(service, service.getDevice(deviceId(uri)));
printDevice(service, service.getDevice(deviceId(uri)));
}
return null;
}
private void printDevicePorts(DeviceService service, Device device) {
@Override
protected void printDevice(DeviceService service, Device device) {
super.printDevice(service, device);
List<Port> ports = new ArrayList<>(service.getPorts(device.id()));
Collections.sort(ports, PORT_COMPARATOR);
printDevice(device, service.isAvailable(device.id()));
for (Port port : ports) {
print(FMT, port.number(), port.isEnabled() ? "enabled" : "disabled");
}
......
package org.onlab.onos.cli.net;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onlab.onos.cli.AbstractShellCommand;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.device.DeviceAdminService;
/**
* Removes an infrastructure device.
*/
@Command(scope = "onos", name = "device-remove",
description = "Removes an infrastructure device")
public class DeviceRemoveCommand extends AbstractShellCommand {
@Argument(index = 0, name = "uri", description = "Device ID",
required = true, multiValued = false)
String uri = null;
@Override
protected Object doExecute() throws Exception {
getService(DeviceAdminService.class).removeDevice(DeviceId.deviceId(uri));
return null;
}
}
......@@ -19,7 +19,7 @@ import static com.google.common.collect.Lists.newArrayList;
public class DevicesListCommand extends AbstractShellCommand {
private static final String FMT =
"id=%s, available=%s, type=%s, mfr=%s, hw=%s, sw=%s, serial=%s";
"id=%s, available=%s, role=%s, type=%s, mfr=%s, hw=%s, sw=%s, serial=%s";
protected static final Comparator<Device> ID_COMPARATOR = new Comparator<Device>() {
@Override
......@@ -32,7 +32,7 @@ public class DevicesListCommand extends AbstractShellCommand {
protected Object doExecute() throws Exception {
DeviceService service = getService(DeviceService.class);
for (Device device : getSortedDevices(service)) {
printDevice(device, service.isAvailable(device.id()));
printDevice(service, device);
}
return null;
}
......@@ -52,11 +52,12 @@ public class DevicesListCommand extends AbstractShellCommand {
/**
* Prints information about the specified device.
*
* @param device infrastructure device
* @param isAvailable true of device is available
* @param service device service
* @param device infrastructure device
*/
protected void printDevice(Device device, boolean isAvailable) {
print(FMT, device.id(), isAvailable, device.type(),
protected void printDevice(DeviceService service, Device device) {
print(FMT, device.id(), service.isAvailable(device.id()),
service.getRole(device.id()), device.type(),
device.manufacturer(), device.hwVersion(), device.swVersion(),
device.serialNumber());
}
......
......@@ -17,15 +17,15 @@ public class LinksListCommand extends AbstractShellCommand {
private static final String FMT = "src=%s/%s, dst=%s/%s, type=%s";
@Argument(index = 0, name = "deviceId", description = "Device ID",
@Argument(index = 0, name = "uri", description = "Device ID",
required = false, multiValued = false)
String deviceId = null;
String uri = null;
@Override
protected Object doExecute() throws Exception {
LinkService service = getService(LinkService.class);
Iterable<Link> links = deviceId != null ?
service.getDeviceLinks(deviceId(deviceId)) : service.getLinks();
Iterable<Link> links = uri != null ?
service.getDeviceLinks(deviceId(uri)) : service.getLinks();
for (Link link : links) {
print(FMT, link.src().deviceId(), link.src().port(),
link.dst().deviceId(), link.dst().port(), link.type());
......
......@@ -11,18 +11,25 @@
</completers>
</command>
<command>
<action class="org.onlab.onos.cli.net.DeviceRemoveCommand"/>
<completers>
<ref component-id="deviceIdCompleter"/>
</completers>
</command>
<command>
<action class="org.onlab.onos.cli.net.LinksListCommand"/>
<completers>
<ref component-id="deviceIdCompleter"/>
</completers>
</command>
<!--<command>-->
<!--<action class="org.onlab.onos.cli.GreetCommand"/>-->
<!--<completers>-->
<!--<ref component-id="nameCompleter"/>-->
<!--</completers>-->
<!--</command>-->
<command>
<action class="org.onlab.onos.cli.GreetCommand"/>
<completers>
<ref component-id="nameCompleter"/>
</completers>
</command>
</command-bundle>
<bean id="deviceIdCompleter" class="org.onlab.onos.cli.net.DeviceIdCompleter"/>
......