Enhanced the CLIs.
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/DevicePortsListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/DevicePortsListCommand.java
index 58dba4b..03fc555 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/DevicePortsListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/DevicePortsListCommand.java
@@ -14,15 +14,15 @@
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 @@
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");
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/DeviceRemoveCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/DeviceRemoveCommand.java
new file mode 100644
index 0000000..b4f2385
--- /dev/null
+++ b/cli/src/main/java/org/onlab/onos/cli/net/DeviceRemoveCommand.java
@@ -0,0 +1,26 @@
+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;
+ }
+
+}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/DevicesListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/DevicesListCommand.java
index 650e6a0..1cbeb6b 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/DevicesListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/DevicesListCommand.java
@@ -19,7 +19,7 @@
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 @@
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 @@
/**
* 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());
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/LinksListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/LinksListCommand.java
index 7197361..cb6fcb1 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/LinksListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/LinksListCommand.java
@@ -17,15 +17,15 @@
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());
diff --git a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
index f7fc371..7aa67be 100644
--- a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
+++ b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -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"/>