blob: aa93eb94e794d6f38883c286dfe9fad9956fb6ba [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
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}