Jonathan Hart | eb8c947 | 2015-08-05 07:43:13 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.cli.net; |
| 17 | |
| 18 | import com.google.common.collect.Lists; |
| 19 | import org.apache.karaf.shell.commands.Command; |
| 20 | import org.onosproject.cli.AbstractShellCommand; |
| 21 | import org.onosproject.cli.Comparators; |
| 22 | import org.onosproject.incubator.net.intf.Interface; |
| 23 | import org.onosproject.incubator.net.intf.InterfaceService; |
| 24 | |
| 25 | import java.util.Collections; |
| 26 | import java.util.List; |
| 27 | |
| 28 | /** |
| 29 | * Lists all configured interfaces. |
| 30 | */ |
| 31 | @Command(scope = "onos", name = "interfaces", |
| 32 | description = "Lists all configured interfaces.") |
| 33 | public class InterfacesListCommand extends AbstractShellCommand { |
| 34 | |
| 35 | private static final String FORMAT = |
| 36 | "port=%s/%s, ips=%s, mac=%s, vlan=%s"; |
| 37 | |
Jonathan Hart | 7dbe629 | 2015-11-10 08:33:17 -0800 | [diff] [blame^] | 38 | private static final String NAME_FORMAT = |
| 39 | "%s: port=%s/%s, ips=%s, mac=%s, vlan=%s"; |
| 40 | |
Jonathan Hart | eb8c947 | 2015-08-05 07:43:13 -0700 | [diff] [blame] | 41 | @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 Hart | 7dbe629 | 2015-11-10 08:33:17 -0800 | [diff] [blame^] | 50 | 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 Hart | eb8c947 | 2015-08-05 07:43:13 -0700 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | |
| 61 | } |