blob: d94d547cd581f73fa270144eb2a62d1b252c7571 [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
20 @Argument(index = 0, name = "deviceId", description = "Device ID",
21 required = false, multiValued = false)
22 String deviceId = null;
23
tom6d2a43e2014-09-08 01:50:20 -070024 @Override
25 protected Object doExecute() throws Exception {
26 LinkService service = getService(LinkService.class);
27 Iterable<Link> links = deviceId != null ?
28 service.getDeviceLinks(deviceId(deviceId)) : service.getLinks();
29 for (Link link : links) {
tom9b836db2014-09-08 02:05:34 -070030 print(FMT, link.src().deviceId().uri(), link.src().port(),
31 link.dst().deviceId().uri(), link.dst().port(), link.type());
tom6d2a43e2014-09-08 01:50:20 -070032 }
33 return null;
34 }
35}