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 | |
| 38 | @Override |
| 39 | protected void execute() { |
| 40 | InterfaceService interfaceService = get(InterfaceService.class); |
| 41 | |
| 42 | List<Interface> interfaces = Lists.newArrayList(interfaceService.getInterfaces()); |
| 43 | |
| 44 | Collections.sort(interfaces, Comparators.INTERFACES_COMPARATOR); |
| 45 | |
| 46 | for (Interface intf : interfaces) { |
| 47 | print(FORMAT, intf.connectPoint().deviceId(), intf.connectPoint().port(), |
| 48 | intf.ipAddresses(), intf.mac(), intf.vlan()); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | } |