tom | 6d2a43e | 2014-09-08 01:50:20 -0700 | [diff] [blame^] | 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.Link; |
| 7 | import org.onlab.onos.net.link.LinkService; |
| 8 | |
| 9 | import 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") |
| 16 | public 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 | |
| 24 | |
| 25 | @Override |
| 26 | protected Object doExecute() throws Exception { |
| 27 | LinkService service = getService(LinkService.class); |
| 28 | Iterable<Link> links = deviceId != null ? |
| 29 | service.getDeviceLinks(deviceId(deviceId)) : service.getLinks(); |
| 30 | for (Link link : links) { |
| 31 | print(FMT, link.src().deviceId(), link.src().port(), |
| 32 | link.dst().deviceId(), link.dst().port(), link.type()); |
| 33 | } |
| 34 | return null; |
| 35 | } |
| 36 | } |