Andrea Campanella
Committed by Gerrit Code Review

ONOS-3182 Adding device badges and bug fixes

Change-Id: I84a0e8ec4e968ad80d08d086fa951cc4800aa70b
...@@ -30,7 +30,10 @@ import org.onosproject.net.topology.PathService; ...@@ -30,7 +30,10 @@ import org.onosproject.net.topology.PathService;
30 import org.onosproject.ui.RequestHandler; 30 import org.onosproject.ui.RequestHandler;
31 import org.onosproject.ui.UiConnection; 31 import org.onosproject.ui.UiConnection;
32 import org.onosproject.ui.UiMessageHandler; 32 import org.onosproject.ui.UiMessageHandler;
33 +import org.onosproject.ui.topo.DeviceHighlight;
33 import org.onosproject.ui.topo.Highlights; 34 import org.onosproject.ui.topo.Highlights;
35 +import org.onosproject.ui.topo.HostHighlight;
36 +import org.onosproject.ui.topo.NodeBadge;
34 import org.onosproject.ui.topo.TopoJson; 37 import org.onosproject.ui.topo.TopoJson;
35 import org.slf4j.Logger; 38 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory; 39 import org.slf4j.LoggerFactory;
...@@ -54,6 +57,11 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler { ...@@ -54,6 +57,11 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler {
54 57
55 private static final String ID = "id"; 58 private static final String ID = "id";
56 private static final String MODE = "mode"; 59 private static final String MODE = "mode";
60 + private static final String TYPE = "type";
61 + private static final String SWITCH = "switch";
62 + private static final String ENDSTATION = "endstation";
63 + public static final String DST = "Dst";
64 + public static final String SRC = "Src";
57 65
58 private Set<Link> allPathLinks; 66 private Set<Link> allPathLinks;
59 67
...@@ -66,6 +74,7 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler { ...@@ -66,6 +74,7 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler {
66 private PathService pathService; 74 private PathService pathService;
67 75
68 private ElementId src, dst; 76 private ElementId src, dst;
77 + private String srcType, dstType;
69 private Mode currentMode = Mode.SHORTEST; 78 private Mode currentMode = Mode.SHORTEST;
70 private List<Path> paths; 79 private List<Path> paths;
71 private int pathIndex; 80 private int pathIndex;
...@@ -96,6 +105,7 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler { ...@@ -96,6 +105,7 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler {
96 // === Handler classes 105 // === Handler classes
97 106
98 private final class SetSrcHandler extends RequestHandler { 107 private final class SetSrcHandler extends RequestHandler {
108 +
99 public SetSrcHandler() { 109 public SetSrcHandler() {
100 super(PAINTER_SET_SRC); 110 super(PAINTER_SET_SRC);
101 } 111 }
...@@ -104,10 +114,15 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler { ...@@ -104,10 +114,15 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler {
104 public void process(long sid, ObjectNode payload) { 114 public void process(long sid, ObjectNode payload) {
105 String id = string(payload, ID); 115 String id = string(payload, ID);
106 src = elementId(id); 116 src = elementId(id);
117 + srcType = string(payload, TYPE);
107 if (src.equals(dst)) { 118 if (src.equals(dst)) {
108 dst = null; 119 dst = null;
109 } 120 }
110 - findAndSendPaths(); 121 + sendMessage(TopoJson.highlightsMessage(addBadge(new Highlights(),
122 + srcType,
123 + src.toString(),
124 + SRC)));
125 + findAndSendPaths(currentMode);
111 } 126 }
112 } 127 }
113 128
...@@ -120,10 +135,16 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler { ...@@ -120,10 +135,16 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler {
120 public void process(long sid, ObjectNode payload) { 135 public void process(long sid, ObjectNode payload) {
121 String id = string(payload, ID); 136 String id = string(payload, ID);
122 dst = elementId(id); 137 dst = elementId(id);
138 + dstType = string(payload, TYPE);
123 if (src.equals(dst)) { 139 if (src.equals(dst)) {
124 src = null; 140 src = null;
125 } 141 }
126 - findAndSendPaths(); 142 +
143 + sendMessage(TopoJson.highlightsMessage(addBadge(new Highlights(),
144 + dstType,
145 + dst.toString(),
146 + DST)));
147 + findAndSendPaths(currentMode);
127 } 148 }
128 } 149 }
129 150
...@@ -137,7 +158,10 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler { ...@@ -137,7 +158,10 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler {
137 ElementId temp = src; 158 ElementId temp = src;
138 src = dst; 159 src = dst;
139 dst = temp; 160 dst = temp;
140 - findAndSendPaths(); 161 + String s = srcType;
162 + srcType = dstType;
163 + dstType = s;
164 + findAndSendPaths(currentMode);
141 } 165 }
142 } 166 }
143 167
...@@ -177,11 +201,7 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler { ...@@ -177,11 +201,7 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler {
177 Mode.SHORTEST : (mode.equals("disjoint") ? 201 Mode.SHORTEST : (mode.equals("disjoint") ?
178 Mode.DISJOINT : Mode.SRLG)); 202 Mode.DISJOINT : Mode.SRLG));
179 //TODO: add support for SRLG 203 //TODO: add support for SRLG
180 - if (currentMode.equals(Mode.SHORTEST)) { 204 + findAndSendPaths(currentMode);
181 - findAndSendPaths();
182 - } else {
183 - findAndSendDisjointPaths();
184 - }
185 } 205 }
186 } 206 }
187 207
...@@ -195,40 +215,40 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler { ...@@ -195,40 +215,40 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler {
195 } 215 }
196 } 216 }
197 217
198 - private void findAndSendPaths() { 218 + private void findAndSendPaths(Mode mode) {
219 + log.info("src={}; dst={}; mode={}", src, dst, currentMode);
199 if (src != null && dst != null) { 220 if (src != null && dst != null) {
200 - paths = ImmutableList.copyOf(pathService.getPaths(src, dst));
201 pathIndex = 0; 221 pathIndex = 0;
202 -
203 ImmutableSet.Builder<Link> builder = ImmutableSet.builder(); 222 ImmutableSet.Builder<Link> builder = ImmutableSet.builder();
204 - paths.forEach(path -> path.links().forEach(builder::add)); 223 + if (mode.equals(Mode.SHORTEST)) {
205 - allPathLinks = builder.build(); 224 + paths = ImmutableList.copyOf(pathService.getPaths(src, dst));
225 + allPathLinks = buildPaths(builder).build();
226 + } else if (mode.equals(Mode.DISJOINT)) {
227 + paths = ImmutableList.copyOf(pathService.getDisjointPaths(src, dst));
228 + allPathLinks = buildDisjointPaths(builder).build();
229 + } else {
230 + log.info("Unsupported MODE");
231 + }
206 } else { 232 } else {
207 paths = ImmutableList.of(); 233 paths = ImmutableList.of();
208 allPathLinks = ImmutableSet.of(); 234 allPathLinks = ImmutableSet.of();
209 } 235 }
210 hilightAndSendPaths(); 236 hilightAndSendPaths();
237 +
211 } 238 }
212 239
213 - private void findAndSendDisjointPaths() { 240 + private ImmutableSet.Builder<Link> buildPaths(ImmutableSet.Builder<Link> pathBuilder) {
214 - log.info("src={}; dst={}; mode={}", src, dst, currentMode); 241 + paths.forEach(path -> path.links().forEach(pathBuilder::add));
215 - if (src != null && dst != null) { 242 + return pathBuilder;
216 - log.info("test" + src + dst); 243 + }
217 - paths = ImmutableList.copyOf(pathService.getDisjointPaths(src, dst));
218 - pathIndex = 0;
219 244
220 - ImmutableSet.Builder<Link> builder = ImmutableSet.builder(); 245 + private ImmutableSet.Builder<Link> buildDisjointPaths(ImmutableSet.Builder<Link> pathBuilder) {
221 - paths.forEach(path -> { 246 + paths.forEach(path -> {
222 - DisjointPath dp = (DisjointPath) path; 247 + DisjointPath dp = (DisjointPath) path;
223 - builder.addAll(dp.primary().links()); 248 + pathBuilder.addAll(dp.primary().links());
224 - builder.addAll(dp.backup().links()); 249 + pathBuilder.addAll(dp.backup().links());
225 - }); 250 + });
226 - allPathLinks = builder.build(); 251 + return pathBuilder;
227 - } else {
228 - paths = ImmutableList.of();
229 - allPathLinks = ImmutableSet.of();
230 - }
231 - hilightAndSendPaths();
232 } 252 }
233 253
234 private void hilightAndSendPaths() { 254 private void hilightAndSendPaths() {
...@@ -240,9 +260,9 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler { ...@@ -240,9 +260,9 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler {
240 // Prepare two working sets; one containing selected path links and 260 // Prepare two working sets; one containing selected path links and
241 // the other containing all paths links. 261 // the other containing all paths links.
242 if (currentMode.equals(Mode.DISJOINT)) { 262 if (currentMode.equals(Mode.DISJOINT)) {
243 - DisjointPath dp = (DisjointPath) paths.get(pathIndex); 263 + DisjointPath dp = (DisjointPath) paths.get(pathIndex);
244 selectedPathLinks = paths.isEmpty() ? 264 selectedPathLinks = paths.isEmpty() ?
245 - ImmutableSet.of() : Sets.newHashSet(dp.primary().links()); 265 + ImmutableSet.of() : Sets.newHashSet(dp.primary().links());
246 selectedPathLinks.addAll(dp.backup().links()); 266 selectedPathLinks.addAll(dp.backup().links());
247 } else { 267 } else {
248 selectedPathLinks = paths.isEmpty() ? 268 selectedPathLinks = paths.isEmpty() ?
...@@ -253,23 +273,40 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler { ...@@ -253,23 +273,40 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler {
253 plink.computeHilight(selectedPathLinks, allPathLinks); 273 plink.computeHilight(selectedPathLinks, allPathLinks);
254 highlights.add(plink.highlight(null)); 274 highlights.add(plink.highlight(null));
255 } 275 }
256 - 276 + if (src != null) {
277 + highlights = addBadge(highlights, srcType, src.toString(), SRC);
278 + }
279 + if (dst != null) {
280 + highlights = addBadge(highlights, dstType, dst.toString(), DST);
281 + }
257 sendMessage(TopoJson.highlightsMessage(highlights)); 282 sendMessage(TopoJson.highlightsMessage(highlights));
258 } 283 }
259 284
260 - /* 285 + private Highlights addBadge(Highlights highlights, String type, String elemId, String src) {
261 - private void addDeviceBadge(Highlights h, DeviceId devId, int n) { 286 + if (SWITCH.equals(type)) {
262 - DeviceHighlight dh = new DeviceHighlight(devId.toString()); 287 + highlights = addDeviceBadge(highlights, elemId, src);
263 - dh.setBadge(createBadge(n)); 288 + } else if (ENDSTATION.equals(type)) {
289 + highlights = addHostBadge(highlights, elemId, src);
290 + }
291 + return highlights;
292 + }
293 +
294 + private Highlights addDeviceBadge(Highlights h, String elemId, String type) {
295 + DeviceHighlight dh = new DeviceHighlight(elemId);
296 + dh.setBadge(createBadge(type));
264 h.add(dh); 297 h.add(dh);
298 + return h;
299 + }
300 +
301 + private Highlights addHostBadge(Highlights h, String elemId, String type) {
302 + HostHighlight hh = new HostHighlight(elemId);
303 + hh.setBadge(createBadge(type));
304 + h.add(hh);
305 + return h;
265 } 306 }
266 307
267 - private NodeBadge createBadge(int n) { 308 + private NodeBadge createBadge(String type) {
268 - Status status = n > 3 ? Status.ERROR : Status.WARN; 309 + return NodeBadge.text(type);
269 - String noun = n > 3 ? "(critical)" : "(problematic)";
270 - String msg = "Egress links: " + n + " " + noun;
271 - return NodeBadge.number(status, n, msg);
272 } 310 }
273 - */
274 311
275 } 312 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -47,14 +47,16 @@ ...@@ -47,14 +47,16 @@
47 47
48 function setSrc(node) { 48 function setSrc(node) {
49 wss.sendEvent(srcMessage, { 49 wss.sendEvent(srcMessage, {
50 - id: node.id 50 + id: node.id,
51 + type: node.type
51 }); 52 });
52 flash.flash('Source node: ' + node.id); 53 flash.flash('Source node: ' + node.id);
53 } 54 }
54 55
55 function setDst(node) { 56 function setDst(node) {
56 wss.sendEvent(dstMessage, { 57 wss.sendEvent(dstMessage, {
57 - id: node.id 58 + id: node.id,
59 + type: node.type
58 }); 60 });
59 flash.flash('Destination node: ' + node.id); 61 flash.flash('Destination node: ' + node.id);
60 } 62 }
......
...@@ -26,38 +26,33 @@ ...@@ -26,38 +26,33 @@
26 glyphs: { 26 glyphs: {
27 src: { 27 src: {
28 vb: '0 0 110 110', 28 vb: '0 0 110 110',
29 - d: 'M26.9,57 M27,86c0.5-9.6,5.8-25.3,13.6-35.2c4.2-5.4,6.2-10.6,6.2-13.8' + 29 + d: 'M28.7,59.3 M14.9,53 M8.7,39 M32.4,92.5H25l-0.2-3.6' +
30 - 'c0-11-8.9-20-19.9-20h0C15.9,17,7,26,7,37c0,3.2,1.9,8.4,6.2,13.8c7.8,9.9,13.1,25.5,13.6,35.2H27z M27.7,86.7l0-0.7' + 30 + 'c-0.5-9-5.4-23.9-12.9-33.5c-5.2-6.6-7-12.8-7-16.3c0-13.3,10.7-24,23.8-24c13.1,0,23.8,10.8,23.8,24c0,3.5-1.8,9.7-7,16.3' +
31 - 'c0.5-9.3,5.6-24.8,13.4-34.7c4.7-5.9,6.3-11.3,6.3-14.3c0-11.4-9.3-20.7-20.6-20.7C15.5,16.3,6.2,25.6,6.2,37c0,3,1.7,8.3,6.3,14.3' + 31 + 'C38,65,33.1,80,32.6,88.9L32.4,92.5z M27.9,89.5h1.7l0-0.7c0.5-9.4,5.7-25.2,13.5-35.2c4.7-6,6.4-11.4,6.4-14.5' +
32 - 'c7.8,9.9,13,25.5,13.4,34.7l0,0.7H27.7L27.7,86.7z M26.9,17.8C37.4,17.8,46,26.4,46,37c0,2.6-1.6,7.7-6,13.3' + 32 + 'c0-11.6-9.3-21-20.8-21C17.3,18,7.9,27.5,7.9,39c0,3,1.7,8.4,6.4,14.5c7.9,10.1,13.1,25.8,13.5,35.2L27.9,89.5z M28.7,83.2' +
33 - 'c-6.6,8.4-11.4,20.8-13.1,30.2c-1.7-9.4-6.5-21.8-13.1-30.2c-4.4-5.6-6-10.7-6-13.3C7.7,26.4,16.3,17.8,26.9,17.8L26.9,17.8z' + 33 + 'M28.6,29.8c-4.7,0-8.5,3.8-8.5,8.5c0,4.7,3.8,8.5,8.5,8.5s8.5-3.8,8.5-8.5C37.1,33.6,33.3,29.8,28.6,29.8z M89.6,47 M89.6,29.5' +
34 - 'M87.3,35.5H46.9v2h40.4V35.5z M26.8,27.9c-4.7,0-8.4,3.8-8.4,8.4c0,4.6,3.8,8.4,8.4,8.4s8.4-3.7,8.4-8.4' + 34 + 'c-0.1,3.1-0.1,12.8,0,17c0.1,4.2,14.1-5.5,13.9-8.5C103.4,35.1,89.6,25.6,89.6,29.5z M51,38.1L89.5,38 M89.5,39.5l0-3L51,36.5l0,3' +
35 - 'C35.2,31.6,31.4,27.9,26.8,27.9z M87.3,44.9 M87.3,28.1c-0.1,3.1-0.1,12.6,0,16.7c0.1,4.1,13.9-5.5,13.8-8.4' + 35 + 'L89.5,39.5z'
36 - 'C101,33.6,87.3,24.2,87.3,28.1z'
37 }, 36 },
38 dst: { 37 dst: {
39 vb: '0 0 110 110', 38 vb: '0 0 110 110',
40 - d: 'M80.6,57 M80.7,86c0.5-9.6,5.8-25.3,13.5-35.2c4.2-5.4,6.1-10.6,6.1-13.8' + 39 + d: 'M80.3,59.8 M85.8,92.5h-7.2L78.4,89c-0.4-8.8-5.2-23.6-12.3-33' +
41 - 'c0-11-8.8-20-19.7-20h0C69.7,17,60.8,26,60.8,37c0,3.2,1.9,8.4,6.1,13.8c7.7,9.9,13,25.5,13.5,35.2H80.7z M81.4,86.7l0-0.7' + 40 + 'c-4.9-6.5-6.7-12.5-6.7-16c0-13,10.2-23.7,22.7-23.7c12.5,0,22.7,10.6,22.7,23.7c0,3.5-1.8,9.5-6.7,16C91.2,65.4,86.4,80.1,86,89' +
42 - 'c0.5-9.3,5.6-24.8,13.4-34.7c4.6-5.9,6.3-11.3,6.3-14.3c0-11.4-9.2-20.7-20.5-20.7S60.1,25.6,60.1,37c0,3,1.7,8.3,6.3,14.3' + 41 + 'L85.8,92.5z M81.4,89.5H83l0-0.7c0.5-9.3,5.4-24.8,12.9-34.7c4.5-5.9,6.1-11.2,6.1-14.2c0-11.4-8.9-20.7-19.8-20.7' +
43 - 'c7.8,9.9,12.9,25.5,13.4,34.7l0,0.7H81.4L81.4,86.7z M80.6,17.8c10.5,0,19,8.6,19,19.2c0,2.6-1.6,7.7-6,13.3' + 42 + 'c-10.9,0-19.8,9.3-19.8,20.7c0,3,1.6,8.3,6.1,14.2C76,64,80.9,79.5,81.4,88.8L81.4,89.5z M82.1,30.8c-4.5,0-8.1,3.7-8.1,8.4' +
44 - 'c-6.6,8.4-11.3,20.8-13,30.2c-1.7-9.4-6.4-21.8-13-30.2c-4.4-5.6-6-10.7-6-13.3C61.6,26.4,70.1,17.8,80.6,17.8L80.6,17.8z' + 43 + 's3.6,8.4,8.1,8.4c4.5,0,8.1-3.7,8.1-8.4S86.6,30.8,82.1,30.8z M47.2,47.5 M45.2,30.8c-0.1,3.1-0.1,12.6,0,16.7' +
45 - 'M46.3,35.2H6.2v2h40.1V35.2z M80.5,27.9c-4.6,0-8.4,3.7-8.4,8.4c0,4.6,3.7,8.4,8.4,8.4s8.4-3.7,8.4-8.4' + 44 + 'c0.1,4.1,13.4-5.4,13.3-8.4C58.4,36.2,45.2,26.9,45.2,30.8z M45.2,39.1L6.7,39.2 M45.2,40.6l0-3L6.7,37.7l0,3L45.2,40.6z'
46 - 'C88.9,31.6,85.1,27.9,80.5,27.9z M46.3,44.6 M46.3,27.9c-0.1,3.1-0.1,12.6,0,16.7c0.1,4.1,13.9-5.5,13.7-8.4' +
47 - 'C60,33.3,46.3,24,46.3,27.9z'
48 }, 45 },
49 jp: { 46 jp: {
50 vb: '0 0 110 110', 47 vb: '0 0 110 110',
51 - d: 'M27,26.8H7.4V7.6H27V26.8z M102.1,79.5H82.6v19.2h19.5V79.5z M59.3,47.1H39.8v19.2' + 48 + d: 'M84.3,89.3L58.9,64.2l-1.4,1.4L83,90.7L84.3,89.3z M27,7.6H7.4v19.2H27V7.6z' +
52 - 'h19.5V47.1z M41.7,47.5L17.1,25.2l-1.3,1.4l24.6,22.3L41.7,47.5z M84.5,89.5L59,64.3l-1.4,1.4l25.4,25.2L84.5,89.5z' 49 + 'M59.3,47.1H39.8v19.2h19.5V47.1z M102.1,79.5H82.6v19.2h19.5V79.5z M41.7,47.6L19,25.1l-1.2,1.2l22.7,22.5L41.7,47.6z'
53 }, 50 },
54 djp: { 51 djp: {
55 vb: '0 0 110 110', 52 vb: '0 0 110 110',
56 - d: 'M27.6,28.8H7.7V9h19.9V28.8z M103,37.2H83.1V57H103V37.2z M36.2,84.5H16.3v19.9' + 53 + d: 'M25.8,84l-9.2-57 M27.3,83.8l-9.2-57l-3,0.5l9.2,57L27.3,83.8z M83.2,37.7L26.8,15.5 M83.7,36.1L26.6,14' +
57 - 'h19.9V84.5z M27.9,85.7L18.7,28l-2,0.3L25.9,86L27.9,85.7z M92.2,59.1L91,57.4L34.6,96.8l1.1,1.6L92.2,59.1z M28.5,80.7' + 54 + 'l-1,3.2l57,22.1L83.7,36.1z M34.1,95l61.4-40.6 M96.4,55.7l-1.9-2.5L33.2,93.8l1.9,2.5L96.4,55.7z M26.6,27.6H6.7V7.7h19.9V27.6z' +
58 - 'c-0.8,0.2-3.5,0.7-4.6,1c-1.1,0.3,2.2,3.1,3,2.9S29.6,80.5,28.5,80.7z M88.8,57.5c0.5,0.7,2,2.9,2.7,3.8c0.7,0.9,2-3.2,1.5-3.9' + 55 + 'M102.1,36H82.2v19.9h19.9V36z M35.3,83.5H15.3v19.9h19.9V83.5z'
59 - 'C92.5,56.8,88.2,56.6,88.8,57.5z M97.7,42.5L27.2,17.9l-0.7,1.9l70.5,24.6L97.7,42.5z M30.7,22.6c0.3-0.8,1.2-3.3,1.5-4.4' +
60 - 'c0.4-1.1-3.8,0.3-4,1.1C27.9,20.1,30.3,23.7,30.7,22.6z'
61 } 56 }
62 57
63 }, 58 },
...@@ -70,7 +65,6 @@ ...@@ -70,7 +65,6 @@
70 }, 65 },
71 66
72 // detail panel button definitions 67 // detail panel button definitions
73 - // FIXME: new icons for src/dst
74 buttons: { 68 buttons: {
75 src: { 69 src: {
76 gid: '*src', 70 gid: '*src',
...@@ -93,7 +87,6 @@ ...@@ -93,7 +87,6 @@
93 // Key bindings for traffic overlay buttons 87 // Key bindings for traffic overlay buttons
94 // NOTE: fully qual. button ID is derived from overlay-id and key-name 88 // NOTE: fully qual. button ID is derived from overlay-id and key-name
95 // FIXME: use into [ and ] instead of 1 and 2 89 // FIXME: use into [ and ] instead of 1 and 2
96 - // FIXME: new icons for src/dst
97 // FIXME: find better keys for shortest paths & disjoint paths modes 90 // FIXME: find better keys for shortest paths & disjoint paths modes
98 keyBindings: { 91 keyBindings: {
99 1: { 92 1: {
......