Thomas Vachuska
Committed by Gerrit Code Review

GUI -- Added ability to display port names in the devices view detail.

Change-Id: Iffaf3b46099f868b7245fe0c7819d13e5bff76d3
......@@ -76,6 +76,12 @@ public final class AnnotationKeys {
public static final String OPTICAL_WAVES = "optical.waves";
/**
* Annotation key for the port name.
*/
public static final String PORT_NAME = "portName";
/**
* Returns the value annotated object for the specified annotation key.
* The annotated value is expected to be String that can be parsed as double.
* If parsing fails, the returned value will be 1.0.
......
......@@ -22,6 +22,7 @@ import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
......@@ -352,7 +353,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
String portName = Strings.emptyToNull(port.getName());
if (portName != null) {
annotations = DefaultAnnotations.builder()
.set("portName", portName).build();
.set(AnnotationKeys.PORT_NAME, portName).build();
}
return annotations;
}
......
......@@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableSet;
import org.onosproject.mastership.MastershipService;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
......@@ -30,6 +31,7 @@ import org.onosproject.net.link.LinkService;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
......@@ -56,6 +58,7 @@ public class DeviceViewMessageHandler extends AbstractTabularViewMessageHandler
private static final String PORTS = "ports";
private static final String ENABLED = "enabled";
private static final String SPEED = "speed";
private static final String NAME = "name";
private static final ObjectMapper MAPPER = new ObjectMapper();
......@@ -118,7 +121,14 @@ public class DeviceViewMessageHandler extends AbstractTabularViewMessageHandler
data.put(PROTOCOL, device.annotations().value(PROTOCOL));
ArrayNode ports = MAPPER.createArrayNode();
for (Port p : service.getPorts(deviceId)) {
List<Port> portList = new ArrayList<>(service.getPorts(deviceId));
Collections.sort(portList, (p1, p2) -> {
long delta = p1.number().toLong() - p2.number().toLong();
return delta == 0 ? 0 : (delta < 0 ? -1 : +1);
});
for (Port p : portList) {
ports.add(portData(p, deviceId));
}
data.set(PORTS, ports);
......@@ -142,11 +152,13 @@ public class DeviceViewMessageHandler extends AbstractTabularViewMessageHandler
private ObjectNode portData(Port p, DeviceId id) {
ObjectNode port = MAPPER.createObjectNode();
LinkService ls = get(LinkService.class);
String name = p.annotations().value(AnnotationKeys.PORT_NAME);
port.put(ID, p.number().toString());
port.put(TYPE, p.type().toString());
port.put(SPEED, p.portSpeed());
port.put(ENABLED, p.isEnabled());
port.put(NAME, name != null ? name : "");
Set<Link> links = ls.getEgressLinks(new ConnectPoint(id, p.number()));
if (!links.isEmpty()) {
......
......@@ -184,7 +184,7 @@ public class TopologyViewWebSocket
@Override
public void onOpen(Connection connection) {
log.info("GUI client connected");
log.info("Legacy GUI client connected");
this.connection = connection;
this.control = (FrameConnection) connection;
addListeners();
......@@ -199,7 +199,7 @@ public class TopologyViewWebSocket
public synchronized void onClose(int closeCode, String message) {
removeListeners();
timer.cancel();
log.info("GUI client disconnected");
log.info("Legacy GUI client disconnected");
}
@Override
......
......@@ -50,10 +50,10 @@
'Vendor', 'H/W Version', 'S/W Version', 'Protocol', 'Serial #'
],
portCols = [
'enabled', 'id', 'speed', 'type', 'elinks_dest'
'enabled', 'id', 'speed', 'type', 'elinks_dest', 'name'
],
friendlyPortCols = [
'Enabled', 'ID', 'Speed', 'Type', 'Egress Links'
'Enabled', 'ID', 'Speed', 'Type', 'Egress Links', 'Name'
];
function addCloseBtn(div) {
......