Jonathan Hart
Committed by Gerrit Code Review

Cosmetic improvements to the way interfaces are printed

Change-Id: I30af7ed2f4aa9b52f6e26284e3fb4b8adfdeb326
...@@ -17,6 +17,8 @@ package org.onosproject.cli.net; ...@@ -17,6 +17,8 @@ package org.onosproject.cli.net;
17 17
18 import com.google.common.collect.Lists; 18 import com.google.common.collect.Lists;
19 import org.apache.karaf.shell.commands.Command; 19 import org.apache.karaf.shell.commands.Command;
20 +import org.onlab.packet.MacAddress;
21 +import org.onlab.packet.VlanId;
20 import org.onosproject.cli.AbstractShellCommand; 22 import org.onosproject.cli.AbstractShellCommand;
21 import org.onosproject.cli.Comparators; 23 import org.onosproject.cli.Comparators;
22 import org.onosproject.incubator.net.intf.Interface; 24 import org.onosproject.incubator.net.intf.Interface;
...@@ -32,11 +34,12 @@ import java.util.List; ...@@ -32,11 +34,12 @@ import java.util.List;
32 description = "Lists all configured interfaces.") 34 description = "Lists all configured interfaces.")
33 public class InterfacesListCommand extends AbstractShellCommand { 35 public class InterfacesListCommand extends AbstractShellCommand {
34 36
35 - private static final String FORMAT = 37 + private static final String FORMAT = "%s: port=%s/%s";
36 - "port=%s/%s, ips=%s, mac=%s, vlan=%s"; 38 + private static final String IP_FORMAT = " ips=";
39 + private static final String MAC_FORMAT = " mac=";
40 + private static final String VLAN_FORMAT = " vlan=";
37 41
38 - private static final String NAME_FORMAT = 42 + private static final String NO_NAME = "(unamed)";
39 - "%s: port=%s/%s, ips=%s, mac=%s, vlan=%s";
40 43
41 @Override 44 @Override
42 protected void execute() { 45 protected void execute() {
...@@ -46,16 +49,32 @@ public class InterfacesListCommand extends AbstractShellCommand { ...@@ -46,16 +49,32 @@ public class InterfacesListCommand extends AbstractShellCommand {
46 49
47 Collections.sort(interfaces, Comparators.INTERFACES_COMPARATOR); 50 Collections.sort(interfaces, Comparators.INTERFACES_COMPARATOR);
48 51
49 - for (Interface intf : interfaces) { 52 + interfaces.forEach(this::printInterface);
50 - if (intf.name().equals(Interface.NO_INTERFACE_NAME)) { 53 + }
51 - print(FORMAT, intf.connectPoint().deviceId(), intf.connectPoint().port(), 54 +
52 - intf.ipAddresses(), intf.mac(), intf.vlan()); 55 + private void printInterface(Interface intf) {
53 - } else { 56 + StringBuilder formatStringBuilder = new StringBuilder(FORMAT);
54 - print(NAME_FORMAT, intf.name(), intf.connectPoint().deviceId(), 57 +
55 - intf.connectPoint().port(), intf.ipAddresses(), 58 + if (!intf.ipAddresses().isEmpty()) {
56 - intf.mac(), intf.vlan()); 59 + formatStringBuilder.append(IP_FORMAT);
57 - } 60 + formatStringBuilder.append(intf.ipAddresses().toString());
61 + }
62 +
63 + if (!intf.mac().equals(MacAddress.NONE)) {
64 + formatStringBuilder.append(MAC_FORMAT);
65 + formatStringBuilder.append(intf.mac().toString());
58 } 66 }
67 +
68 + if (!intf.vlan().equals(VlanId.NONE)) {
69 + formatStringBuilder.append(VLAN_FORMAT);
70 + formatStringBuilder.append(intf.vlan().toString());
71 + }
72 +
73 + String name = (intf.name().equals(Interface.NO_INTERFACE_NAME)) ?
74 + NO_NAME : intf.name();
75 +
76 + print(formatStringBuilder.toString(), name, intf.connectPoint().deviceId(),
77 + intf.connectPoint().port());
59 } 78 }
60 79
61 } 80 }
......