Showing
5 changed files
with
57 additions
and
22 deletions
... | @@ -14,15 +14,15 @@ import java.util.List; | ... | @@ -14,15 +14,15 @@ import java.util.List; |
14 | import static org.onlab.onos.net.DeviceId.deviceId; | 14 | import static org.onlab.onos.net.DeviceId.deviceId; |
15 | 15 | ||
16 | /** | 16 | /** |
17 | - * Lists all infrastructure links. | 17 | + * Lists all ports or all ports of a device. |
18 | */ | 18 | */ |
19 | @Command(scope = "onos", name = "ports", | 19 | @Command(scope = "onos", name = "ports", |
20 | - description = "Lists all ports of a device") | 20 | + description = "Lists all ports or all ports of a device") |
21 | public class DevicePortsListCommand extends DevicesListCommand { | 21 | public class DevicePortsListCommand extends DevicesListCommand { |
22 | 22 | ||
23 | private static final String FMT = " port=%s, state=%s"; | 23 | private static final String FMT = " port=%s, state=%s"; |
24 | 24 | ||
25 | - @Argument(index = 0, name = "deviceId", description = "Device ID", | 25 | + @Argument(index = 0, name = "uri", description = "Device ID", |
26 | required = false, multiValued = false) | 26 | required = false, multiValued = false) |
27 | String uri = null; | 27 | String uri = null; |
28 | 28 | ||
... | @@ -39,18 +39,19 @@ public class DevicePortsListCommand extends DevicesListCommand { | ... | @@ -39,18 +39,19 @@ public class DevicePortsListCommand extends DevicesListCommand { |
39 | DeviceService service = getService(DeviceService.class); | 39 | DeviceService service = getService(DeviceService.class); |
40 | if (uri == null) { | 40 | if (uri == null) { |
41 | for (Device device : getSortedDevices(service)) { | 41 | for (Device device : getSortedDevices(service)) { |
42 | - printDevicePorts(service, device); | 42 | + printDevice(service, device); |
43 | } | 43 | } |
44 | } else { | 44 | } else { |
45 | - printDevicePorts(service, service.getDevice(deviceId(uri))); | 45 | + printDevice(service, service.getDevice(deviceId(uri))); |
46 | } | 46 | } |
47 | return null; | 47 | return null; |
48 | } | 48 | } |
49 | 49 | ||
50 | - private void printDevicePorts(DeviceService service, Device device) { | 50 | + @Override |
51 | + protected void printDevice(DeviceService service, Device device) { | ||
52 | + super.printDevice(service, device); | ||
51 | List<Port> ports = new ArrayList<>(service.getPorts(device.id())); | 53 | List<Port> ports = new ArrayList<>(service.getPorts(device.id())); |
52 | Collections.sort(ports, PORT_COMPARATOR); | 54 | Collections.sort(ports, PORT_COMPARATOR); |
53 | - printDevice(device, service.isAvailable(device.id())); | ||
54 | for (Port port : ports) { | 55 | for (Port port : ports) { |
55 | print(FMT, port.number(), port.isEnabled() ? "enabled" : "disabled"); | 56 | print(FMT, port.number(), port.isEnabled() ? "enabled" : "disabled"); |
56 | } | 57 | } | ... | ... |
1 | +package org.onlab.onos.cli.net; | ||
2 | + | ||
3 | +import org.apache.karaf.shell.commands.Argument; | ||
4 | +import org.apache.karaf.shell.commands.Command; | ||
5 | +import org.onlab.onos.cli.AbstractShellCommand; | ||
6 | +import org.onlab.onos.net.DeviceId; | ||
7 | +import org.onlab.onos.net.device.DeviceAdminService; | ||
8 | + | ||
9 | +/** | ||
10 | + * Removes an infrastructure device. | ||
11 | + */ | ||
12 | +@Command(scope = "onos", name = "device-remove", | ||
13 | + description = "Removes an infrastructure device") | ||
14 | +public class DeviceRemoveCommand extends AbstractShellCommand { | ||
15 | + | ||
16 | + @Argument(index = 0, name = "uri", description = "Device ID", | ||
17 | + required = true, multiValued = false) | ||
18 | + String uri = null; | ||
19 | + | ||
20 | + @Override | ||
21 | + protected Object doExecute() throws Exception { | ||
22 | + getService(DeviceAdminService.class).removeDevice(DeviceId.deviceId(uri)); | ||
23 | + return null; | ||
24 | + } | ||
25 | + | ||
26 | +} |
... | @@ -19,7 +19,7 @@ import static com.google.common.collect.Lists.newArrayList; | ... | @@ -19,7 +19,7 @@ import static com.google.common.collect.Lists.newArrayList; |
19 | public class DevicesListCommand extends AbstractShellCommand { | 19 | public class DevicesListCommand extends AbstractShellCommand { |
20 | 20 | ||
21 | private static final String FMT = | 21 | private static final String FMT = |
22 | - "id=%s, available=%s, type=%s, mfr=%s, hw=%s, sw=%s, serial=%s"; | 22 | + "id=%s, available=%s, role=%s, type=%s, mfr=%s, hw=%s, sw=%s, serial=%s"; |
23 | 23 | ||
24 | protected static final Comparator<Device> ID_COMPARATOR = new Comparator<Device>() { | 24 | protected static final Comparator<Device> ID_COMPARATOR = new Comparator<Device>() { |
25 | @Override | 25 | @Override |
... | @@ -32,7 +32,7 @@ public class DevicesListCommand extends AbstractShellCommand { | ... | @@ -32,7 +32,7 @@ public class DevicesListCommand extends AbstractShellCommand { |
32 | protected Object doExecute() throws Exception { | 32 | protected Object doExecute() throws Exception { |
33 | DeviceService service = getService(DeviceService.class); | 33 | DeviceService service = getService(DeviceService.class); |
34 | for (Device device : getSortedDevices(service)) { | 34 | for (Device device : getSortedDevices(service)) { |
35 | - printDevice(device, service.isAvailable(device.id())); | 35 | + printDevice(service, device); |
36 | } | 36 | } |
37 | return null; | 37 | return null; |
38 | } | 38 | } |
... | @@ -52,11 +52,12 @@ public class DevicesListCommand extends AbstractShellCommand { | ... | @@ -52,11 +52,12 @@ public class DevicesListCommand extends AbstractShellCommand { |
52 | /** | 52 | /** |
53 | * Prints information about the specified device. | 53 | * Prints information about the specified device. |
54 | * | 54 | * |
55 | + * @param service device service | ||
55 | * @param device infrastructure device | 56 | * @param device infrastructure device |
56 | - * @param isAvailable true of device is available | ||
57 | */ | 57 | */ |
58 | - protected void printDevice(Device device, boolean isAvailable) { | 58 | + protected void printDevice(DeviceService service, Device device) { |
59 | - print(FMT, device.id(), isAvailable, device.type(), | 59 | + print(FMT, device.id(), service.isAvailable(device.id()), |
60 | + service.getRole(device.id()), device.type(), | ||
60 | device.manufacturer(), device.hwVersion(), device.swVersion(), | 61 | device.manufacturer(), device.hwVersion(), device.swVersion(), |
61 | device.serialNumber()); | 62 | device.serialNumber()); |
62 | } | 63 | } | ... | ... |
... | @@ -17,15 +17,15 @@ public class LinksListCommand extends AbstractShellCommand { | ... | @@ -17,15 +17,15 @@ public class LinksListCommand extends AbstractShellCommand { |
17 | 17 | ||
18 | private static final String FMT = "src=%s/%s, dst=%s/%s, type=%s"; | 18 | private static final String FMT = "src=%s/%s, dst=%s/%s, type=%s"; |
19 | 19 | ||
20 | - @Argument(index = 0, name = "deviceId", description = "Device ID", | 20 | + @Argument(index = 0, name = "uri", description = "Device ID", |
21 | required = false, multiValued = false) | 21 | required = false, multiValued = false) |
22 | - String deviceId = null; | 22 | + String uri = null; |
23 | 23 | ||
24 | @Override | 24 | @Override |
25 | protected Object doExecute() throws Exception { | 25 | protected Object doExecute() throws Exception { |
26 | LinkService service = getService(LinkService.class); | 26 | LinkService service = getService(LinkService.class); |
27 | - Iterable<Link> links = deviceId != null ? | 27 | + Iterable<Link> links = uri != null ? |
28 | - service.getDeviceLinks(deviceId(deviceId)) : service.getLinks(); | 28 | + service.getDeviceLinks(deviceId(uri)) : service.getLinks(); |
29 | for (Link link : links) { | 29 | for (Link link : links) { |
30 | print(FMT, link.src().deviceId(), link.src().port(), | 30 | print(FMT, link.src().deviceId(), link.src().port(), |
31 | link.dst().deviceId(), link.dst().port(), link.type()); | 31 | link.dst().deviceId(), link.dst().port(), link.type()); | ... | ... |
... | @@ -11,18 +11,25 @@ | ... | @@ -11,18 +11,25 @@ |
11 | </completers> | 11 | </completers> |
12 | </command> | 12 | </command> |
13 | <command> | 13 | <command> |
14 | + <action class="org.onlab.onos.cli.net.DeviceRemoveCommand"/> | ||
15 | + <completers> | ||
16 | + <ref component-id="deviceIdCompleter"/> | ||
17 | + </completers> | ||
18 | + </command> | ||
19 | + | ||
20 | + <command> | ||
14 | <action class="org.onlab.onos.cli.net.LinksListCommand"/> | 21 | <action class="org.onlab.onos.cli.net.LinksListCommand"/> |
15 | <completers> | 22 | <completers> |
16 | <ref component-id="deviceIdCompleter"/> | 23 | <ref component-id="deviceIdCompleter"/> |
17 | </completers> | 24 | </completers> |
18 | </command> | 25 | </command> |
19 | 26 | ||
20 | - <!--<command>--> | 27 | + <command> |
21 | - <!--<action class="org.onlab.onos.cli.GreetCommand"/>--> | 28 | + <action class="org.onlab.onos.cli.GreetCommand"/> |
22 | - <!--<completers>--> | 29 | + <completers> |
23 | - <!--<ref component-id="nameCompleter"/>--> | 30 | + <ref component-id="nameCompleter"/> |
24 | - <!--</completers>--> | 31 | + </completers> |
25 | - <!--</command>--> | 32 | + </command> |
26 | </command-bundle> | 33 | </command-bundle> |
27 | 34 | ||
28 | <bean id="deviceIdCompleter" class="org.onlab.onos.cli.net.DeviceIdCompleter"/> | 35 | <bean id="deviceIdCompleter" class="org.onlab.onos.cli.net.DeviceIdCompleter"/> | ... | ... |
-
Please register or login to post a comment