blob: 7592cdfdaffec74a94f345abbeac36561d1af1f8 [file] [log] [blame]
Aaron Kruglikova2b59152015-06-24 14:01:41 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Aaron Kruglikova2b59152015-06-24 14:01:41 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.cli.net;
17
Ray Milkeyd84f89b2018-08-17 14:54:17 -070018import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
20import org.apache.karaf.shell.api.action.lifecycle.Service;
Aaron Kruglikova2b59152015-06-24 14:01:41 -070021import org.onosproject.cli.AbstractShellCommand;
Jonathan Hart6ff6ffe2016-09-09 11:55:50 -070022import org.onosproject.net.ConnectPoint;
Aaron Kruglikova2b59152015-06-24 14:01:41 -070023import org.onosproject.net.edge.EdgePortService;
Jonathan Hart6ff6ffe2016-09-09 11:55:50 -070024import org.onosproject.utils.Comparators;
Aaron Kruglikova2b59152015-06-24 14:01:41 -070025
Jonathan Hart6ff6ffe2016-09-09 11:55:50 -070026import java.util.Collections;
27import java.util.List;
28
29import static com.google.common.collect.Lists.newArrayList;
Aaron Kruglikova2b59152015-06-24 14:01:41 -070030import static org.onosproject.net.DeviceId.deviceId;
31
32/**
33 * Lists all edge ports.
34 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070035@Service
Aaron Kruglikova2b59152015-06-24 14:01:41 -070036@Command(scope = "onos", name = "edge-ports",
37 description = "Lists all edge ports.")
38public class EdgePortsListCommand extends AbstractShellCommand {
39
40 private static final String FMT = "%s/%s";
41
42 @Argument(index = 0, name = "uri", description = "Device ID",
43 required = false, multiValued = false)
44 String uri = null;
45
Aaron Kruglikova2b59152015-06-24 14:01:41 -070046 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070047 protected void doExecute() {
Aaron Kruglikova2b59152015-06-24 14:01:41 -070048 EdgePortService service = get(EdgePortService.class);
49 if (uri == null) {
Jonathan Hart6ff6ffe2016-09-09 11:55:50 -070050 printEdgePoints(service.getEdgePoints());
Aaron Kruglikova2b59152015-06-24 14:01:41 -070051 } else {
Jonathan Hart6ff6ffe2016-09-09 11:55:50 -070052 printEdgePoints(service.getEdgePoints(deviceId(uri)));
Aaron Kruglikova2b59152015-06-24 14:01:41 -070053 }
54 }
55
Jonathan Hart6ff6ffe2016-09-09 11:55:50 -070056 private void printEdgePoints(Iterable<ConnectPoint> edgePoints) {
57 sort(edgePoints).forEach(e -> print(FMT, e.deviceId(), e.port()));
58 }
59
60 private static List<ConnectPoint> sort(Iterable<ConnectPoint> connectPoints) {
61 List<ConnectPoint> edgePoints = newArrayList(connectPoints);
62 Collections.sort(edgePoints, Comparators.CONNECT_POINT_COMPARATOR);
63 return edgePoints;
64 }
65
Aaron Kruglikova2b59152015-06-24 14:01:41 -070066}