blob: cb6fcb1e6744af63abcbdce0b4a6812514bac976 [file] [log] [blame]
tom6d2a43e2014-09-08 01:50:20 -07001package org.onlab.onos.cli.net;
2
3import org.apache.karaf.shell.commands.Argument;
4import org.apache.karaf.shell.commands.Command;
5import org.onlab.onos.cli.AbstractShellCommand;
6import org.onlab.onos.net.Link;
7import org.onlab.onos.net.link.LinkService;
8
9import static org.onlab.onos.net.DeviceId.deviceId;
10
11/**
12 * Lists all infrastructure links.
13 */
14@Command(scope = "onos", name = "links",
15 description = "Lists all infrastructure links")
16public class LinksListCommand extends AbstractShellCommand {
17
18 private static final String FMT = "src=%s/%s, dst=%s/%s, type=%s";
19
tomc290a122014-09-08 14:27:13 -070020 @Argument(index = 0, name = "uri", description = "Device ID",
tom6d2a43e2014-09-08 01:50:20 -070021 required = false, multiValued = false)
tomc290a122014-09-08 14:27:13 -070022 String uri = null;
tom6d2a43e2014-09-08 01:50:20 -070023
tom6d2a43e2014-09-08 01:50:20 -070024 @Override
25 protected Object doExecute() throws Exception {
26 LinkService service = getService(LinkService.class);
tomc290a122014-09-08 14:27:13 -070027 Iterable<Link> links = uri != null ?
28 service.getDeviceLinks(deviceId(uri)) : service.getLinks();
tom6d2a43e2014-09-08 01:50:20 -070029 for (Link link : links) {
tomff7eb7c2014-09-08 12:49:03 -070030 print(FMT, link.src().deviceId(), link.src().port(),
31 link.dst().deviceId(), link.dst().port(), link.type());
tom6d2a43e2014-09-08 01:50:20 -070032 }
33 return null;
34 }
35}