Committed by
Gerrit Code Review
ONOS-3182 Modify mode and Icons
Change-Id: Ibcfc1ffb5e91856899b10e7d156b8108653b047a
Showing
3 changed files
with
136 additions
and
33 deletions
| ... | @@ -18,6 +18,7 @@ package org.onosproject.pathpainter; | ... | @@ -18,6 +18,7 @@ package org.onosproject.pathpainter; |
| 18 | import com.fasterxml.jackson.databind.node.ObjectNode; | 18 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 19 | import com.google.common.collect.ImmutableList; | 19 | import com.google.common.collect.ImmutableList; |
| 20 | import com.google.common.collect.ImmutableSet; | 20 | import com.google.common.collect.ImmutableSet; |
| 21 | +import com.google.common.collect.Sets; | ||
| 21 | import org.onlab.osgi.ServiceDirectory; | 22 | import org.onlab.osgi.ServiceDirectory; |
| 22 | import org.onosproject.net.DeviceId; | 23 | import org.onosproject.net.DeviceId; |
| 23 | import org.onosproject.net.ElementId; | 24 | import org.onosproject.net.ElementId; |
| ... | @@ -33,6 +34,7 @@ import org.onosproject.ui.topo.TopoJson; | ... | @@ -33,6 +34,7 @@ import org.onosproject.ui.topo.TopoJson; |
| 33 | import org.slf4j.Logger; | 34 | import org.slf4j.Logger; |
| 34 | import org.slf4j.LoggerFactory; | 35 | import org.slf4j.LoggerFactory; |
| 35 | 36 | ||
| 37 | +import java.util.ArrayList; | ||
| 36 | import java.util.Collection; | 38 | import java.util.Collection; |
| 37 | import java.util.List; | 39 | import java.util.List; |
| 38 | import java.util.Set; | 40 | import java.util.Set; |
| ... | @@ -54,6 +56,7 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler { | ... | @@ -54,6 +56,7 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler { |
| 54 | private static final String MODE = "mode"; | 56 | private static final String MODE = "mode"; |
| 55 | 57 | ||
| 56 | private Set<Link> allPathLinks; | 58 | private Set<Link> allPathLinks; |
| 59 | + private Set<Link> selectedPathLinks; | ||
| 57 | 60 | ||
| 58 | private enum Mode { | 61 | private enum Mode { |
| 59 | SHORTEST, DISJOINT, SRLG | 62 | SHORTEST, DISJOINT, SRLG |
| ... | @@ -63,9 +66,8 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler { | ... | @@ -63,9 +66,8 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler { |
| 63 | 66 | ||
| 64 | private PathService pathService; | 67 | private PathService pathService; |
| 65 | 68 | ||
| 66 | - private Mode currentMode = Mode.SHORTEST; | ||
| 67 | private ElementId src, dst; | 69 | private ElementId src, dst; |
| 68 | - private Mode mode = Mode.SHORTEST; | 70 | + private Mode currentMode = Mode.SHORTEST; |
| 69 | private List<Path> paths; | 71 | private List<Path> paths; |
| 70 | private int pathIndex; | 72 | private int pathIndex; |
| 71 | 73 | ||
| ... | @@ -86,7 +88,8 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler { | ... | @@ -86,7 +88,8 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler { |
| 86 | new SetDstHandler(), | 88 | new SetDstHandler(), |
| 87 | new SwapSrcDstHandler(), | 89 | new SwapSrcDstHandler(), |
| 88 | new NextPathHandler(), | 90 | new NextPathHandler(), |
| 89 | - new PrevPathHandler() | 91 | + new PrevPathHandler(), |
| 92 | + new SetModeHandler() | ||
| 90 | ); | 93 | ); |
| 91 | } | 94 | } |
| 92 | 95 | ||
| ... | @@ -163,6 +166,26 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler { | ... | @@ -163,6 +166,26 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler { |
| 163 | } | 166 | } |
| 164 | } | 167 | } |
| 165 | 168 | ||
| 169 | + private final class SetModeHandler extends RequestHandler { | ||
| 170 | + public SetModeHandler() { | ||
| 171 | + super(PAINTER_SET_MODE); | ||
| 172 | + } | ||
| 173 | + | ||
| 174 | + @Override | ||
| 175 | + public void process(long sid, ObjectNode payload) { | ||
| 176 | + String mode = string(payload, MODE); | ||
| 177 | + currentMode = (mode.equals("shortest") ? | ||
| 178 | + Mode.SHORTEST : (mode.equals("disjoint") ? | ||
| 179 | + Mode.DISJOINT : Mode.SRLG)); | ||
| 180 | + //TODO: add support for SRLG | ||
| 181 | + if (currentMode.equals(Mode.SHORTEST)) { | ||
| 182 | + findAndSendPaths(); | ||
| 183 | + } else { | ||
| 184 | + findAndSendDisjointPaths(); | ||
| 185 | + } | ||
| 186 | + } | ||
| 187 | + } | ||
| 188 | + | ||
| 166 | // === ------------ | 189 | // === ------------ |
| 167 | 190 | ||
| 168 | private ElementId elementId(String id) { | 191 | private ElementId elementId(String id) { |
| ... | @@ -174,7 +197,6 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler { | ... | @@ -174,7 +197,6 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler { |
| 174 | } | 197 | } |
| 175 | 198 | ||
| 176 | private void findAndSendPaths() { | 199 | private void findAndSendPaths() { |
| 177 | - log.info("src={}; dst={}; mode={}", src, dst, mode); | ||
| 178 | if (src != null && dst != null) { | 200 | if (src != null && dst != null) { |
| 179 | paths = ImmutableList.copyOf(pathService.getPaths(src, dst)); | 201 | paths = ImmutableList.copyOf(pathService.getPaths(src, dst)); |
| 180 | pathIndex = 0; | 202 | pathIndex = 0; |
| ... | @@ -189,15 +211,43 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler { | ... | @@ -189,15 +211,43 @@ public class PathPainterTopovMessageHandler extends UiMessageHandler { |
| 189 | hilightAndSendPaths(); | 211 | hilightAndSendPaths(); |
| 190 | } | 212 | } |
| 191 | 213 | ||
| 214 | + private void findAndSendDisjointPaths() { | ||
| 215 | + log.info("src={}; dst={}; mode={}", src, dst, currentMode); | ||
| 216 | + if (src != null && dst != null) { | ||
| 217 | + log.info("test" + src + dst); | ||
| 218 | + paths = null; | ||
| 219 | + paths = new ArrayList<>(); | ||
| 220 | + pathService.getDisjointPaths(src, dst).forEach(djp -> { | ||
| 221 | + paths.add(djp.primary()); | ||
| 222 | + paths.add(djp.backup()); | ||
| 223 | + }); | ||
| 224 | + pathIndex = 0; | ||
| 225 | + | ||
| 226 | + ImmutableSet.Builder<Link> builder = ImmutableSet.builder(); | ||
| 227 | + paths.forEach(path -> path.links().forEach(builder::add)); | ||
| 228 | + allPathLinks = builder.build(); | ||
| 229 | + } else { | ||
| 230 | + paths = ImmutableList.of(); | ||
| 231 | + allPathLinks = ImmutableSet.of(); | ||
| 232 | + } | ||
| 233 | + hilightAndSendPaths(); | ||
| 234 | + } | ||
| 235 | + | ||
| 192 | private void hilightAndSendPaths() { | 236 | private void hilightAndSendPaths() { |
| 193 | PathLinkMap linkMap = new PathLinkMap(); | 237 | PathLinkMap linkMap = new PathLinkMap(); |
| 194 | allPathLinks.forEach(linkMap::add); | 238 | allPathLinks.forEach(linkMap::add); |
| 195 | 239 | ||
| 196 | // Prepare two working sets; one containing selected path links and | 240 | // Prepare two working sets; one containing selected path links and |
| 197 | // the other containing all paths links. | 241 | // the other containing all paths links. |
| 198 | - Set<Link> selectedPathLinks = paths.isEmpty() ? | 242 | + if (currentMode.equals(Mode.DISJOINT)) { |
| 199 | - ImmutableSet.of() : ImmutableSet.copyOf(paths.get(pathIndex).links()); | 243 | + //FIXME: find a way to skip 2 paths for disjoint |
| 200 | - | 244 | + selectedPathLinks = paths.isEmpty() ? |
| 245 | + ImmutableSet.of() : Sets.newHashSet(paths.get(pathIndex * 2).links()); | ||
| 246 | + selectedPathLinks.addAll(Sets.newHashSet(paths.get(pathIndex * 2 + 1).links())); | ||
| 247 | + } else { | ||
| 248 | + selectedPathLinks = paths.isEmpty() ? | ||
| 249 | + ImmutableSet.of() : Sets.newHashSet(paths.get(pathIndex).links()); | ||
| 250 | + } | ||
| 201 | Highlights highlights = new Highlights(); | 251 | Highlights highlights = new Highlights(); |
| 202 | for (PathLink plink : linkMap.biLinks()) { | 252 | for (PathLink plink : linkMap.biLinks()) { |
| 203 | plink.computeHilight(selectedPathLinks, allPathLinks); | 253 | plink.computeHilight(selectedPathLinks, allPathLinks); | ... | ... |
| ... | @@ -76,6 +76,7 @@ | ... | @@ -76,6 +76,7 @@ |
| 76 | function setMode(mode) { | 76 | function setMode(mode) { |
| 77 | if (currentMode === mode) { | 77 | if (currentMode === mode) { |
| 78 | $log.debug('(in mode', mode, 'already)'); | 78 | $log.debug('(in mode', mode, 'already)'); |
| 79 | + flash.flash('Already in ' + mode + ' mode'); | ||
| 79 | } else { | 80 | } else { |
| 80 | currentMode = mode; | 81 | currentMode = mode; |
| 81 | wss.sendEvent(modeMessage, { | 82 | wss.sendEvent(modeMessage, { | ... | ... |
| ... | @@ -20,18 +20,46 @@ | ... | @@ -20,18 +20,46 @@ |
| 20 | tooltip: 'Path Painter Topo Overlay', | 20 | tooltip: 'Path Painter Topo Overlay', |
| 21 | 21 | ||
| 22 | // These glyphs get installed using the overlayId as a prefix. | 22 | // These glyphs get installed using the overlayId as a prefix. |
| 23 | - // e.g. 'star4' is installed as 'meowster-overlay-star4' | 23 | + // e.g. 'src' is installed as 'pp-overlay-src' |
| 24 | - // They can be referenced (from this overlay) as '*star4' | 24 | + // They can be referenced (from this overlay) as '*src' |
| 25 | - // That is, the '*' prefix stands in for 'meowster-overlay-' | 25 | + // That is, the '*' prefix stands in for 'pp-overlay-' |
| 26 | glyphs: { | 26 | glyphs: { |
| 27 | - star4: { | 27 | + src: { |
| 28 | - vb: '0 0 8 8', | 28 | + vb: '0 0 110 110', |
| 29 | - d: 'M1,4l2,-1l1,-2l1,2l2,1l-2,1l-1,2l-1,-2z' | 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' + |
| 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' + | ||
| 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' + | ||
| 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' + | ||
| 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' + | ||
| 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' + | ||
| 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' + | ||
| 36 | + 'C101,33.6,87.3,24.2,87.3,28.1z' | ||
| 37 | + }, | ||
| 38 | + dst: { | ||
| 39 | + 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' + | ||
| 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' + | ||
| 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' + | ||
| 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' + | ||
| 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' + | ||
| 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' + | ||
| 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' | ||
| 30 | }, | 48 | }, |
| 31 | - banner: { | 49 | + jp: { |
| 32 | - vb: '0 0 6 6', | 50 | + vb: '0 0 110 110', |
| 33 | - d: 'M1,1v4l2,-2l2,2v-4z' | 51 | + d: 'M27,26.8H7.4V7.6H27V26.8z M102.1,79.5H82.6v19.2h19.5V79.5z M59.3,47.1H39.8v19.2' + |
| 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' | ||
| 53 | + }, | ||
| 54 | + djp: { | ||
| 55 | + 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' + | ||
| 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' + | ||
| 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' + | ||
| 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' | ||
| 34 | } | 61 | } |
| 62 | + | ||
| 35 | }, | 63 | }, |
| 36 | 64 | ||
| 37 | activate: function () { | 65 | activate: function () { |
| ... | @@ -45,7 +73,7 @@ | ... | @@ -45,7 +73,7 @@ |
| 45 | // FIXME: new icons for src/dst | 73 | // FIXME: new icons for src/dst |
| 46 | buttons: { | 74 | buttons: { |
| 47 | src: { | 75 | src: { |
| 48 | - gid: 'triangleUp', | 76 | + gid: '*src', |
| 49 | tt: 'Set source node', | 77 | tt: 'Set source node', |
| 50 | cb: function (data) { | 78 | cb: function (data) { |
| 51 | $log.debug('Set src action invoked with data:', data); | 79 | $log.debug('Set src action invoked with data:', data); |
| ... | @@ -53,7 +81,7 @@ | ... | @@ -53,7 +81,7 @@ |
| 53 | } | 81 | } |
| 54 | }, | 82 | }, |
| 55 | dst: { | 83 | dst: { |
| 56 | - gid: 'triangleDown', | 84 | + gid: '*dst', |
| 57 | tt: 'Set destination node', | 85 | tt: 'Set destination node', |
| 58 | cb: function (data) { | 86 | cb: function (data) { |
| 59 | $log.debug('Set dst action invoked with data:', data); | 87 | $log.debug('Set dst action invoked with data:', data); |
| ... | @@ -66,36 +94,60 @@ | ... | @@ -66,36 +94,60 @@ |
| 66 | // NOTE: fully qual. button ID is derived from overlay-id and key-name | 94 | // NOTE: fully qual. button ID is derived from overlay-id and key-name |
| 67 | // FIXME: use into [ and ] instead of 1 and 2 | 95 | // FIXME: use into [ and ] instead of 1 and 2 |
| 68 | // FIXME: new icons for src/dst | 96 | // FIXME: new icons for src/dst |
| 69 | - // TODO: add keys for shortest paths & disjoint paths modes | 97 | + // FIXME: find better keys for shortest paths & disjoint paths modes |
| 70 | keyBindings: { | 98 | keyBindings: { |
| 71 | 1: { | 99 | 1: { |
| 72 | - cb: function () { pps.setSrc(selection); }, | 100 | + cb: function () { |
| 101 | + pps.setSrc(selection); | ||
| 102 | + }, | ||
| 73 | tt: 'Set source node', | 103 | tt: 'Set source node', |
| 74 | - gid: 'triangleUp' | 104 | + gid: '*src' |
| 75 | }, | 105 | }, |
| 76 | 2: { | 106 | 2: { |
| 77 | - cb: function () { pps.setDst(selection); }, | 107 | + cb: function () { |
| 108 | + pps.setDst(selection); | ||
| 109 | + }, | ||
| 78 | tt: 'Set destination node', | 110 | tt: 'Set destination node', |
| 79 | - gid: 'triangleDown' | 111 | + gid: '*dst' |
| 80 | }, | 112 | }, |
| 81 | 3: { | 113 | 3: { |
| 82 | - cb: function () { pps.swapSrcDst(); }, | 114 | + cb: function () { |
| 115 | + pps.swapSrcDst(); | ||
| 116 | + }, | ||
| 83 | tt: 'Swap source and destination nodes', | 117 | tt: 'Swap source and destination nodes', |
| 84 | gid: 'refresh' | 118 | gid: 'refresh' |
| 85 | }, | 119 | }, |
| 120 | + 4: { | ||
| 121 | + cb: function () { | ||
| 122 | + pps.setMode("shortest"); | ||
| 123 | + }, | ||
| 124 | + tt: 'Set shortest paths mode', | ||
| 125 | + gid: '*jp' | ||
| 126 | + }, | ||
| 127 | + 5: { | ||
| 128 | + cb: function () { | ||
| 129 | + pps.setMode("disjoint"); | ||
| 130 | + }, | ||
| 131 | + tt: 'Set disjoint paths mode', | ||
| 132 | + gid: '*djp' | ||
| 133 | + }, | ||
| 86 | leftArrow: { | 134 | leftArrow: { |
| 87 | - cb: function () { pps.prevPath(); }, | 135 | + cb: function () { |
| 136 | + pps.prevPath(); | ||
| 137 | + }, | ||
| 88 | tt: 'Highlight previous path', | 138 | tt: 'Highlight previous path', |
| 89 | gid: 'prevIntent' | 139 | gid: 'prevIntent' |
| 90 | }, | 140 | }, |
| 91 | rightArrow: { | 141 | rightArrow: { |
| 92 | - cb: function () { pps.nextPath(); }, | 142 | + cb: function () { |
| 143 | + pps.nextPath(); | ||
| 144 | + }, | ||
| 93 | tt: 'Highlight next path', | 145 | tt: 'Highlight next path', |
| 94 | gid: 'nextIntent' | 146 | gid: 'nextIntent' |
| 95 | }, | 147 | }, |
| 96 | 148 | ||
| 97 | _keyOrder: [ | 149 | _keyOrder: [ |
| 98 | - '1', '2', '3', 'leftArrow', 'rightArrow' | 150 | + '1', '2', '3', '4', '5', 'leftArrow', 'rightArrow' |
| 99 | ] | 151 | ] |
| 100 | }, | 152 | }, |
| 101 | 153 | ||
| ... | @@ -132,11 +184,11 @@ | ... | @@ -132,11 +184,11 @@ |
| 132 | angular.module('ovPpTopov') | 184 | angular.module('ovPpTopov') |
| 133 | .run(['$log', 'TopoOverlayService', 'PathPainterTopovService', | 185 | .run(['$log', 'TopoOverlayService', 'PathPainterTopovService', |
| 134 | 186 | ||
| 135 | - function (_$log_, _tov_, _pps_) { | 187 | + function (_$log_, _tov_, _pps_) { |
| 136 | - $log = _$log_; | 188 | + $log = _$log_; |
| 137 | - tov = _tov_; | 189 | + tov = _tov_; |
| 138 | - pps = _pps_; | 190 | + pps = _pps_; |
| 139 | - tov.register(overlay); | 191 | + tov.register(overlay); |
| 140 | - }]); | 192 | + }]); |
| 141 | 193 | ||
| 142 | }()); | 194 | }()); | ... | ... |
-
Please register or login to post a comment