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 { ...@@ -76,6 +76,12 @@ public final class AnnotationKeys {
76 public static final String OPTICAL_WAVES = "optical.waves"; 76 public static final String OPTICAL_WAVES = "optical.waves";
77 77
78 /** 78 /**
79 + * Annotation key for the port name.
80 + */
81 + public static final String PORT_NAME = "portName";
82 +
83 +
84 + /**
79 * Returns the value annotated object for the specified annotation key. 85 * Returns the value annotated object for the specified annotation key.
80 * The annotated value is expected to be String that can be parsed as double. 86 * The annotated value is expected to be String that can be parsed as double.
81 * If parsing fails, the returned value will be 1.0. 87 * If parsing fails, the returned value will be 1.0.
......
...@@ -22,6 +22,7 @@ import org.apache.felix.scr.annotations.Component; ...@@ -22,6 +22,7 @@ import org.apache.felix.scr.annotations.Component;
22 import org.apache.felix.scr.annotations.Deactivate; 22 import org.apache.felix.scr.annotations.Deactivate;
23 import org.apache.felix.scr.annotations.Reference; 23 import org.apache.felix.scr.annotations.Reference;
24 import org.apache.felix.scr.annotations.ReferenceCardinality; 24 import org.apache.felix.scr.annotations.ReferenceCardinality;
25 +import org.onosproject.net.AnnotationKeys;
25 import org.onosproject.net.DefaultAnnotations; 26 import org.onosproject.net.DefaultAnnotations;
26 import org.onosproject.net.Device; 27 import org.onosproject.net.Device;
27 import org.onosproject.net.DeviceId; 28 import org.onosproject.net.DeviceId;
...@@ -352,7 +353,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr ...@@ -352,7 +353,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
352 String portName = Strings.emptyToNull(port.getName()); 353 String portName = Strings.emptyToNull(port.getName());
353 if (portName != null) { 354 if (portName != null) {
354 annotations = DefaultAnnotations.builder() 355 annotations = DefaultAnnotations.builder()
355 - .set("portName", portName).build(); 356 + .set(AnnotationKeys.PORT_NAME, portName).build();
356 } 357 }
357 return annotations; 358 return annotations;
358 } 359 }
......
...@@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode; ...@@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
20 import com.fasterxml.jackson.databind.node.ObjectNode; 20 import com.fasterxml.jackson.databind.node.ObjectNode;
21 import com.google.common.collect.ImmutableSet; 21 import com.google.common.collect.ImmutableSet;
22 import org.onosproject.mastership.MastershipService; 22 import org.onosproject.mastership.MastershipService;
23 +import org.onosproject.net.AnnotationKeys;
23 import org.onosproject.net.ConnectPoint; 24 import org.onosproject.net.ConnectPoint;
24 import org.onosproject.net.Device; 25 import org.onosproject.net.Device;
25 import org.onosproject.net.DeviceId; 26 import org.onosproject.net.DeviceId;
...@@ -30,6 +31,7 @@ import org.onosproject.net.link.LinkService; ...@@ -30,6 +31,7 @@ import org.onosproject.net.link.LinkService;
30 31
31 import java.util.ArrayList; 32 import java.util.ArrayList;
32 import java.util.Arrays; 33 import java.util.Arrays;
34 +import java.util.Collections;
33 import java.util.List; 35 import java.util.List;
34 import java.util.Set; 36 import java.util.Set;
35 37
...@@ -56,6 +58,7 @@ public class DeviceViewMessageHandler extends AbstractTabularViewMessageHandler ...@@ -56,6 +58,7 @@ public class DeviceViewMessageHandler extends AbstractTabularViewMessageHandler
56 private static final String PORTS = "ports"; 58 private static final String PORTS = "ports";
57 private static final String ENABLED = "enabled"; 59 private static final String ENABLED = "enabled";
58 private static final String SPEED = "speed"; 60 private static final String SPEED = "speed";
61 + private static final String NAME = "name";
59 62
60 private static final ObjectMapper MAPPER = new ObjectMapper(); 63 private static final ObjectMapper MAPPER = new ObjectMapper();
61 64
...@@ -118,7 +121,14 @@ public class DeviceViewMessageHandler extends AbstractTabularViewMessageHandler ...@@ -118,7 +121,14 @@ public class DeviceViewMessageHandler extends AbstractTabularViewMessageHandler
118 data.put(PROTOCOL, device.annotations().value(PROTOCOL)); 121 data.put(PROTOCOL, device.annotations().value(PROTOCOL));
119 122
120 ArrayNode ports = MAPPER.createArrayNode(); 123 ArrayNode ports = MAPPER.createArrayNode();
121 - for (Port p : service.getPorts(deviceId)) { 124 +
125 + List<Port> portList = new ArrayList<>(service.getPorts(deviceId));
126 + Collections.sort(portList, (p1, p2) -> {
127 + long delta = p1.number().toLong() - p2.number().toLong();
128 + return delta == 0 ? 0 : (delta < 0 ? -1 : +1);
129 + });
130 +
131 + for (Port p : portList) {
122 ports.add(portData(p, deviceId)); 132 ports.add(portData(p, deviceId));
123 } 133 }
124 data.set(PORTS, ports); 134 data.set(PORTS, ports);
...@@ -142,11 +152,13 @@ public class DeviceViewMessageHandler extends AbstractTabularViewMessageHandler ...@@ -142,11 +152,13 @@ public class DeviceViewMessageHandler extends AbstractTabularViewMessageHandler
142 private ObjectNode portData(Port p, DeviceId id) { 152 private ObjectNode portData(Port p, DeviceId id) {
143 ObjectNode port = MAPPER.createObjectNode(); 153 ObjectNode port = MAPPER.createObjectNode();
144 LinkService ls = get(LinkService.class); 154 LinkService ls = get(LinkService.class);
155 + String name = p.annotations().value(AnnotationKeys.PORT_NAME);
145 156
146 port.put(ID, p.number().toString()); 157 port.put(ID, p.number().toString());
147 port.put(TYPE, p.type().toString()); 158 port.put(TYPE, p.type().toString());
148 port.put(SPEED, p.portSpeed()); 159 port.put(SPEED, p.portSpeed());
149 port.put(ENABLED, p.isEnabled()); 160 port.put(ENABLED, p.isEnabled());
161 + port.put(NAME, name != null ? name : "");
150 162
151 Set<Link> links = ls.getEgressLinks(new ConnectPoint(id, p.number())); 163 Set<Link> links = ls.getEgressLinks(new ConnectPoint(id, p.number()));
152 if (!links.isEmpty()) { 164 if (!links.isEmpty()) {
......
...@@ -184,7 +184,7 @@ public class TopologyViewWebSocket ...@@ -184,7 +184,7 @@ public class TopologyViewWebSocket
184 184
185 @Override 185 @Override
186 public void onOpen(Connection connection) { 186 public void onOpen(Connection connection) {
187 - log.info("GUI client connected"); 187 + log.info("Legacy GUI client connected");
188 this.connection = connection; 188 this.connection = connection;
189 this.control = (FrameConnection) connection; 189 this.control = (FrameConnection) connection;
190 addListeners(); 190 addListeners();
...@@ -199,7 +199,7 @@ public class TopologyViewWebSocket ...@@ -199,7 +199,7 @@ public class TopologyViewWebSocket
199 public synchronized void onClose(int closeCode, String message) { 199 public synchronized void onClose(int closeCode, String message) {
200 removeListeners(); 200 removeListeners();
201 timer.cancel(); 201 timer.cancel();
202 - log.info("GUI client disconnected"); 202 + log.info("Legacy GUI client disconnected");
203 } 203 }
204 204
205 @Override 205 @Override
......
...@@ -50,10 +50,10 @@ ...@@ -50,10 +50,10 @@
50 'Vendor', 'H/W Version', 'S/W Version', 'Protocol', 'Serial #' 50 'Vendor', 'H/W Version', 'S/W Version', 'Protocol', 'Serial #'
51 ], 51 ],
52 portCols = [ 52 portCols = [
53 - 'enabled', 'id', 'speed', 'type', 'elinks_dest' 53 + 'enabled', 'id', 'speed', 'type', 'elinks_dest', 'name'
54 ], 54 ],
55 friendlyPortCols = [ 55 friendlyPortCols = [
56 - 'Enabled', 'ID', 'Speed', 'Type', 'Egress Links' 56 + 'Enabled', 'ID', 'Speed', 'Type', 'Egress Links', 'Name'
57 ]; 57 ];
58 58
59 function addCloseBtn(div) { 59 function addCloseBtn(div) {
......