blob: bac3aed8eb7545fe9ee243596295757994e6fe89 [file] [log] [blame]
Jonathan Harteb8c9472015-08-05 07:43:13 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
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
18import com.google.common.collect.Lists;
19import org.apache.karaf.shell.commands.Command;
20import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.cli.Comparators;
22import org.onosproject.incubator.net.intf.Interface;
23import org.onosproject.incubator.net.intf.InterfaceService;
24
25import java.util.Collections;
26import java.util.List;
27
28/**
29 * Lists all configured interfaces.
30 */
31@Command(scope = "onos", name = "interfaces",
32 description = "Lists all configured interfaces.")
33public class InterfacesListCommand extends AbstractShellCommand {
34
35 private static final String FORMAT =
36 "port=%s/%s, ips=%s, mac=%s, vlan=%s";
37
Jonathan Hart7dbe6292015-11-10 08:33:17 -080038 private static final String NAME_FORMAT =
39 "%s: port=%s/%s, ips=%s, mac=%s, vlan=%s";
40
Jonathan Harteb8c9472015-08-05 07:43:13 -070041 @Override
42 protected void execute() {
43 InterfaceService interfaceService = get(InterfaceService.class);
44
45 List<Interface> interfaces = Lists.newArrayList(interfaceService.getInterfaces());
46
47 Collections.sort(interfaces, Comparators.INTERFACES_COMPARATOR);
48
49 for (Interface intf : interfaces) {
Jonathan Hart7dbe6292015-11-10 08:33:17 -080050 if (intf.name().equals(Interface.NO_INTERFACE_NAME)) {
51 print(FORMAT, intf.connectPoint().deviceId(), intf.connectPoint().port(),
52 intf.ipAddresses(), intf.mac(), intf.vlan());
53 } else {
54 print(NAME_FORMAT, intf.name(), intf.connectPoint().deviceId(),
55 intf.connectPoint().port(), intf.ipAddresses(),
56 intf.mac(), intf.vlan());
57 }
Jonathan Harteb8c9472015-08-05 07:43:13 -070058 }
59 }
60
61}