Mahesh Raju-Huawei
Committed by Gerrit Code Review

[ONOS-4159] PCE Web GUI implementation:ServerSideChanges

Change-Id: Ief54166eb940952876e82003adfe215132c240ba
...@@ -43,6 +43,11 @@ ...@@ -43,6 +43,11 @@
43 <artifactId>onos-cli</artifactId> 43 <artifactId>onos-cli</artifactId>
44 <version>${project.version}</version> 44 <version>${project.version}</version>
45 </dependency> 45 </dependency>
46 + <dependency>
47 + <groupId>org.onosproject</groupId>
48 + <artifactId>onos-app-pce</artifactId>
49 + <version>${project.version}</version>
50 + </dependency>
46 </dependencies> 51 </dependencies>
47 52
48 <properties> 53 <properties>
......
...@@ -17,33 +17,48 @@ ...@@ -17,33 +17,48 @@
17 package org.onosproject.pceweb; 17 package org.onosproject.pceweb;
18 18
19 import com.fasterxml.jackson.databind.node.ObjectNode; 19 import com.fasterxml.jackson.databind.node.ObjectNode;
20 -
21 -
22 import com.google.common.collect.ImmutableSet; 20 import com.google.common.collect.ImmutableSet;
21 +
23 import org.onlab.osgi.ServiceDirectory; 22 import org.onlab.osgi.ServiceDirectory;
23 +import org.onlab.packet.IpAddress;
24 +import org.onlab.util.DataRateUnit;
25 +import org.onosproject.net.Device;
24 import org.onosproject.net.DeviceId; 26 import org.onosproject.net.DeviceId;
25 -import org.onosproject.net.DisjointPath;
26 import org.onosproject.net.ElementId; 27 import org.onosproject.net.ElementId;
27 import org.onosproject.net.HostId; 28 import org.onosproject.net.HostId;
28 import org.onosproject.net.Link; 29 import org.onosproject.net.Link;
29 import org.onosproject.net.Path; 30 import org.onosproject.net.Path;
30 -import org.onosproject.net.device.DeviceService; 31 +import org.onosproject.net.topology.TopologyEvent;
31 -import org.onosproject.net.topology.LinkWeight; 32 +import org.onosproject.net.topology.TopologyListener;
32 -import org.onosproject.net.topology.PathService;
33 import org.onosproject.net.topology.TopologyService; 33 import org.onosproject.net.topology.TopologyService;
34 import org.onosproject.ui.RequestHandler; 34 import org.onosproject.ui.RequestHandler;
35 import org.onosproject.ui.UiConnection; 35 import org.onosproject.ui.UiConnection;
36 import org.onosproject.ui.UiMessageHandler; 36 import org.onosproject.ui.UiMessageHandler;
37 import org.onosproject.ui.topo.DeviceHighlight; 37 import org.onosproject.ui.topo.DeviceHighlight;
38 import org.onosproject.ui.topo.Highlights; 38 import org.onosproject.ui.topo.Highlights;
39 -import org.onosproject.ui.topo.HostHighlight;
40 import org.onosproject.ui.topo.NodeBadge; 39 import org.onosproject.ui.topo.NodeBadge;
41 import org.onosproject.ui.topo.TopoJson; 40 import org.onosproject.ui.topo.TopoJson;
42 - 41 +import org.onosproject.net.device.DeviceService;
42 +import org.onosproject.net.intent.Constraint;
43 +import org.onosproject.pce.pceservice.LspType;
44 +import org.onosproject.pce.pceservice.api.PceService;
45 +import org.onosproject.pce.pceservice.constraint.CostConstraint;
46 +import org.onosproject.net.intent.constraint.BandwidthConstraint;
43 import org.slf4j.Logger; 47 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory; 48 import org.slf4j.LoggerFactory;
49 +import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
50 +import org.onosproject.incubator.net.tunnel.Tunnel;
51 +import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
52 +import org.onosproject.incubator.net.tunnel.TunnelEvent;
53 +import org.onosproject.incubator.net.tunnel.TunnelId;
54 +import org.onosproject.incubator.net.tunnel.TunnelListener;
55 +import org.onosproject.incubator.net.tunnel.TunnelService;
56 +import static org.onosproject.incubator.net.tunnel.Tunnel.Type.MPLS;
57 +
58 +import com.fasterxml.jackson.databind.node.ArrayNode;
45 59
46 import java.util.Collection; 60 import java.util.Collection;
61 +import java.util.LinkedList;
47 import java.util.List; 62 import java.util.List;
48 import java.util.Set; 63 import java.util.Set;
49 64
...@@ -56,47 +71,66 @@ public class PceWebTopovMessageHandler extends UiMessageHandler { ...@@ -56,47 +71,66 @@ public class PceWebTopovMessageHandler extends UiMessageHandler {
56 private static final String PCEWEB_SET_SRC = "pceTopovSetSrc"; 71 private static final String PCEWEB_SET_SRC = "pceTopovSetSrc";
57 private static final String PCEWEB_SET_DST = "pceTopovSetDst"; 72 private static final String PCEWEB_SET_DST = "pceTopovSetDst";
58 private static final String PCEWEB_SET_PATH = "pceTopovSetMode"; 73 private static final String PCEWEB_SET_PATH = "pceTopovSetMode";
59 - 74 + private static final String PCEWEB_UPDATE_PATH_QUERY = "pceTopovUpdateQuery";
75 + private static final String PCEWEB_UPDATE_PATH = "pceTopovUpdate";
76 + private static final String PCEWEB_REMOVE_PATH_QUERY = "pceTopovRemQuery";
77 + private static final String PCEWEB_REMOVE_PATH = "pceTopovRem";
78 + private static final String PCEWEB_QUERY_TUNNELS = "pceTopovTunnelDisplay";
79 + private static final String PCEWEB_SHOW_TUNNEL = "pceTopovShowTunnels";
80 + private static final String PCEWEB_SHOW_TUNNEL_REMOVE = "pceTopovShowTunnelsRem";
60 private static final String ID = "id"; 81 private static final String ID = "id";
61 - private static final String MODE = "mode";
62 private static final String TYPE = "type"; 82 private static final String TYPE = "type";
63 - private static final String SWITCH = "switch"; 83 + private static final String ROUTER = "router";
64 - private static final String ENDSTATION = "endstation"; 84 + private static final String DST = "Egress";
65 - public static final String DST = "Dst"; 85 + private static final String SRC = "Ingress";
66 - public static final String SRC = "Src"; 86 + private static final String BANDWIDTH = "bw";
87 + private static final String BANDWIDTHTYPE = "bwtype";
88 + private static final String COSTTYPE = "ctype";
89 + private static final String LSPTYPE = "lsptype";
90 + private static final String SRCID = "srid";
91 + private static final String DSTID = "dsid";
92 + private static final String TUNNEL_ID = "tunnelid";
93 + private static final String TUNNEL_NAME = "tunnelname";
94 + private static final String COST_TYPE_IGP = "igp";
95 + private static final String COST_TYPE_TE = "te";
96 + private static final String BANDWIDTH_TYPE_KBPS = "kbps";
97 + private static final String BUFFER_ARRAY = "a";
98 + private static final String BANDWIDTH_BPS = "BPS";
99 + private static final String LSP_TYPE_CR = "cr";
100 + private static final String LSP_TYPE_SRBE = "srbe";
101 + private static final String LSP_TYPE_SRTE = "srte";
102 + private static final String STRING_NULL = "null";
67 // Delay for showHighlights event processing on GUI client side to 103 // Delay for showHighlights event processing on GUI client side to
68 // account for addLink animation. 104 // account for addLink animation.
69 - public static final int DELAY_MS = 1100; 105 + private static final int DELAY_MS = 1100;
70 - 106 + private static final double BANDWIDTH_KBPS = 1_000;
71 - private static final String CLASS = "class"; 107 + private static final double BANDWIDTH_MBPS = 1_000_000;
72 - private static final String UNKNOWN = "unknown";
73 - private static final String DEVICE = "device";
74 108
75 private Set<Link> allPathLinks; 109 private Set<Link> allPathLinks;
76 - private boolean listenersRemoved;
77 - private LinkWeight linkData;
78 private int highlightDelay; 110 private int highlightDelay;
79 -
80 - private final Logger log = LoggerFactory.getLogger(getClass());
81 -
82 - private PathService pathService;
83 -
84 private ElementId src, dst; 111 private ElementId src, dst;
85 private String srcType, dstType; 112 private String srcType, dstType;
86 private List<Path> paths; 113 private List<Path> paths;
87 private int pathIndex; 114 private int pathIndex;
88 115
116 + private final Logger log = LoggerFactory.getLogger(getClass());
117 + private final TopologyListener topologyListener = new InternalTopologyListener();
118 + private final TunnelListener tunnelListener = new InnerPceWebTunnelListener();
119 +
89 protected TopologyService topologyService; 120 protected TopologyService topologyService;
121 + protected TunnelService tunnelService;
122 + protected PceService pceService;
90 protected DeviceService deviceService; 123 protected DeviceService deviceService;
91 -
92 -
93 @Override 124 @Override
94 public void init(UiConnection connection, ServiceDirectory directory) { 125 public void init(UiConnection connection, ServiceDirectory directory) {
95 126
96 super.init(connection, directory); 127 super.init(connection, directory);
97 - //TODO: Need add listeners. 128 + topologyService = directory.get(TopologyService.class);
98 - //topologyService = directory.get(TopologyService.class); 129 + tunnelService = directory.get(TunnelService.class);
99 - //addListeners(); 130 + pceService = directory.get(PceService.class);
131 + deviceService = directory.get(DeviceService.class);
132 + topologyService.addListener(topologyListener);
133 + tunnelService.addListener(tunnelListener);
100 } 134 }
101 135
102 @Override 136 @Override
...@@ -105,7 +139,19 @@ public class PceWebTopovMessageHandler extends UiMessageHandler { ...@@ -105,7 +139,19 @@ public class PceWebTopovMessageHandler extends UiMessageHandler {
105 new ClearHandler(), 139 new ClearHandler(),
106 new SetSrcHandler(), 140 new SetSrcHandler(),
107 new SetDstHandler(), 141 new SetDstHandler(),
108 - new SetPathHandler()); 142 + new SetPathHandler(),
143 + new UpdatePathQueryHandler(),
144 + new UpdatePathHandler(),
145 + new RemovePathQueryHandler(),
146 + new RemovePathHandler(),
147 + new ShowTunnelHandler());
148 + }
149 +
150 + @Override
151 + public void destroy() {
152 + topologyService.removeListener(topologyListener);
153 + tunnelService.removeListener(tunnelListener);
154 + super.destroy();
109 } 155 }
110 156
111 // Handler classes 157 // Handler classes
...@@ -137,7 +183,6 @@ public class PceWebTopovMessageHandler extends UiMessageHandler { ...@@ -137,7 +183,6 @@ public class PceWebTopovMessageHandler extends UiMessageHandler {
137 183
138 @Override 184 @Override
139 public void process(long sid, ObjectNode payload) { 185 public void process(long sid, ObjectNode payload) {
140 - log.info("PCE WEB Set source process method invoked");
141 String id = string(payload, ID); 186 String id = string(payload, ID);
142 src = elementId(id); 187 src = elementId(id);
143 srcType = string(payload, TYPE); 188 srcType = string(payload, TYPE);
...@@ -146,7 +191,6 @@ public class PceWebTopovMessageHandler extends UiMessageHandler { ...@@ -146,7 +191,6 @@ public class PceWebTopovMessageHandler extends UiMessageHandler {
146 } 191 }
147 sendMessage(TopoJson.highlightsMessage(addBadge(new Highlights(), 192 sendMessage(TopoJson.highlightsMessage(addBadge(new Highlights(),
148 srcType, src.toString(), SRC))); 193 srcType, src.toString(), SRC)));
149 -
150 } 194 }
151 } 195 }
152 196
...@@ -167,7 +211,6 @@ public class PceWebTopovMessageHandler extends UiMessageHandler { ...@@ -167,7 +211,6 @@ public class PceWebTopovMessageHandler extends UiMessageHandler {
167 if (src.equals(dst)) { 211 if (src.equals(dst)) {
168 src = null; 212 src = null;
169 } 213 }
170 -
171 sendMessage(TopoJson.highlightsMessage(addBadge(new Highlights(), 214 sendMessage(TopoJson.highlightsMessage(addBadge(new Highlights(),
172 dstType, dst.toString(), DST))); 215 dstType, dst.toString(), DST)));
173 216
...@@ -175,7 +218,7 @@ public class PceWebTopovMessageHandler extends UiMessageHandler { ...@@ -175,7 +218,7 @@ public class PceWebTopovMessageHandler extends UiMessageHandler {
175 } 218 }
176 219
177 /** 220 /**
178 - * Handles the 'patchcalculation' event received from the client. 221 + * Handles the 'path calculation' event received from the client.
179 */ 222 */
180 private final class SetPathHandler extends RequestHandler { 223 private final class SetPathHandler extends RequestHandler {
181 224
...@@ -185,15 +228,171 @@ public class PceWebTopovMessageHandler extends UiMessageHandler { ...@@ -185,15 +228,171 @@ public class PceWebTopovMessageHandler extends UiMessageHandler {
185 228
186 @Override 229 @Override
187 public void process(long sid, ObjectNode payload) { 230 public void process(long sid, ObjectNode payload) {
188 - String mode = string(payload, MODE); 231 + String bandWidth = string(payload, BANDWIDTH);
232 + String bandWidthType = string(payload, BANDWIDTHTYPE);
233 + String costType = string(payload, COSTTYPE);
234 + String lspType = string(payload, LSPTYPE);
235 + String tunnelName = string(payload, TUNNEL_NAME);
236 +
237 + if (tunnelName.equals(STRING_NULL)) {
238 + log.error("tunnel name should not be empty");
239 + return;
240 + }
241 +
242 + if (pceService == null) {
243 + log.error("PCE service is not active");
244 + return;
245 + }
246 +
247 + if (lspType == null) {
248 + log.error("PCE setup path is failed.");
249 + }
250 +
251 + if ((src != null) && (dst != null)) {
252 + findAndSendPaths(src, dst, bandWidth, bandWidthType, costType, lspType, tunnelName);
253 + }
254 + }
255 + }
256 +
257 + /**
258 + * Handles the 'update path query' event received from the client.
259 + */
260 + private final class UpdatePathQueryHandler extends RequestHandler {
261 +
262 + public UpdatePathQueryHandler() {
263 + super(PCEWEB_UPDATE_PATH_QUERY);
264 + }
265 +
266 + @Override
267 + public void process(long sid, ObjectNode payload) {
268 + String srcId = string(payload, SRCID);
269 + ElementId src = elementId(srcId);
270 + String dstId = string(payload, DSTID);
271 + ElementId dst = elementId(dstId);
272 + Device srcDevice = deviceService.getDevice((DeviceId) src);
273 + Device dstDevice = deviceService.getDevice((DeviceId) dst);
274 +
275 + TunnelEndPoint tunSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress
276 + .valueOf(srcDevice.annotations().value("lsrId")));
277 + TunnelEndPoint tunDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress
278 + .valueOf(dstDevice.annotations().value("lsrId")));
279 +
280 + Collection<Tunnel> tunnelSet = tunnelService.queryTunnel(tunSrc, tunDst);
281 + if (tunnelSet != null) {
282 + ObjectNode result = objectNode();
283 + ArrayNode arrayNode = arrayNode();
284 +
285 + for (Tunnel tunnel : tunnelSet) {
286 + if (tunnel.type() == MPLS) {
287 + arrayNode.add(tunnel.tunnelId().toString());
288 + }
289 + }
290 + result.putArray(BUFFER_ARRAY).addAll(arrayNode);
291 + sendMessage(PCEWEB_SHOW_TUNNEL, sid, result);
292 + }
293 + }
294 + }
295 +
296 + /**
297 + * Handles the 'update path' event received from the client.
298 + */
299 + private final class UpdatePathHandler extends RequestHandler {
300 +
301 + public UpdatePathHandler() {
302 + super(PCEWEB_UPDATE_PATH);
303 + }
304 +
305 + @Override
306 + public void process(long sid, ObjectNode payload) {
307 + String bandWidth = string(payload, BANDWIDTH);
308 + String bandWidthType = string(payload, BANDWIDTHTYPE);
309 + String costType = string(payload, COSTTYPE);
310 + String tunnelId = string(payload, TUNNEL_ID);
311 +
312 + if (tunnelId == null) {
313 + log.error("PCE update path is failed.");
314 + }
315 +
316 + findAndSendPathsUpdate(bandWidth, bandWidthType, costType, tunnelId);
317 + }
318 + }
319 +
320 + /**
321 + * Handles the 'remove path query' event received from the client.
322 + */
323 + private final class RemovePathQueryHandler extends RequestHandler {
324 +
325 + public RemovePathQueryHandler() {
326 + super(PCEWEB_REMOVE_PATH_QUERY);
327 + }
328 +
329 + @Override
330 + public void process(long sid, ObjectNode payload) {
331 + String srcId = string(payload, SRCID);
332 + ElementId src = elementId(srcId);
333 + String dstId = string(payload, DSTID);
334 + ElementId dst = elementId(dstId);
335 +
336 + Device srcDevice = deviceService.getDevice((DeviceId) src);
337 + Device dstDevice = deviceService.getDevice((DeviceId) dst);
338 +
339 + TunnelEndPoint tunSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress
340 + .valueOf(srcDevice.annotations().value("lsrId")));
341 + TunnelEndPoint tunDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress
342 + .valueOf(dstDevice.annotations().value("lsrId")));
343 +
344 + Collection<Tunnel> tunnelSet = tunnelService.queryTunnel(tunSrc, tunDst);
345 + if (tunnelSet != null) {
346 + ObjectNode result = objectNode();
347 + ArrayNode arrayNode = arrayNode();
348 +
349 + for (Tunnel tunnel : tunnelSet) {
350 + if (tunnel.type() == MPLS) {
351 + arrayNode.add(tunnel.tunnelId().toString());
352 + }
353 + }
354 + result.putArray(BUFFER_ARRAY).addAll(arrayNode);
355 + sendMessage(PCEWEB_SHOW_TUNNEL_REMOVE, sid, result);
356 + }
357 + }
358 + }
359 +
360 + /**
361 + * Handles the 'remove path' event received from the client.
362 + */
363 + private final class RemovePathHandler extends RequestHandler {
364 +
365 + public RemovePathHandler() {
366 + super(PCEWEB_REMOVE_PATH);
367 + }
368 +
369 + @Override
370 + public void process(long sid, ObjectNode payload) {
371 + String tunnelId = string(payload, TUNNEL_ID);
372 +
373 + if (tunnelId == null) {
374 + log.error("PCE update path is failed.");
375 + }
189 376
190 - // TODO: Read user input[constraints] and call the path calculation based on 377 + findAndSendPathsRemove(tunnelId);
191 - //given constrainsts. 378 + }
192 - findAndSendPaths(); 379 + }
380 +
381 + /**
382 + * Handles the 'show the existed tunnels' event received from the client.
383 + */
384 + private final class ShowTunnelHandler extends RequestHandler {
385 +
386 + public ShowTunnelHandler() {
387 + super(PCEWEB_QUERY_TUNNELS);
388 + }
389 +
390 + @Override
391 + public void process(long sid, ObjectNode payload) {
392 + findTunnelAndHighlights();
193 } 393 }
194 } 394 }
195 395
196 - // === ------------
197 /** 396 /**
198 * provides the element id. 397 * provides the element id.
199 */ 398 */
...@@ -204,45 +403,170 @@ public class PceWebTopovMessageHandler extends UiMessageHandler { ...@@ -204,45 +403,170 @@ public class PceWebTopovMessageHandler extends UiMessageHandler {
204 return HostId.hostId(id); 403 return HostId.hostId(id);
205 } 404 }
206 } 405 }
207 - //TODO: Need to pass constraints to this method
208 - private void findAndSendPaths() {
209 - log.info("src={}; dst={};", src, dst);
210 - if (src != null && dst != null) {
211 - //TBD: Need to call pathcalulation API here
212 - hilightAndSendPaths();
213 406
407 + /**
408 + * Handles the setup path and highlights the path.
409 + *
410 + * @param bandWidth
411 + * @param bandWidthType is the kbps or mbps
412 + * @param costType is igp or te
413 + * @param lspType is WITH_SIGNALLING,WITHOUT_SIGNALLING_AND_WITHOUT_SR or SR_WITHOUT_SIGNALLING
414 + * @param tunnelName tunnel id
415 + */
416 + private void findAndSendPaths(ElementId src, ElementId dst, String bandWidth, String bandWidthType,
417 + String costType, String lspType, String tunnelName) {
418 + log.debug("src={}; dst={};", src, dst);
419 + boolean path;
420 + List<Constraint> listConstrnt;
421 +
422 + listConstrnt = addBandwidthCostTypeConstraints(bandWidth, bandWidthType, costType);
423 +
424 + //LSP type
425 + LspType lspTypeVal = null;
426 + switch (lspType) {
427 + case LSP_TYPE_CR:
428 + lspTypeVal = LspType.WITH_SIGNALLING;
429 + break;
430 + case LSP_TYPE_SRBE:
431 + lspTypeVal = LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
432 + break;
433 + case LSP_TYPE_SRTE:
434 + lspTypeVal = LspType.SR_WITHOUT_SIGNALLING;
435 + break;
436 + default:
437 + log.error("Invalid LSP type");
438 + break;
439 + }
440 +
441 + path = pceService.setupPath((DeviceId) src, (DeviceId) dst, tunnelName, listConstrnt, lspTypeVal);
442 + if (!path) {
443 + log.error("setup path is failed");
444 + return;
445 + }
446 +
447 + return;
448 + }
449 +
450 + /**
451 + * Handles the update path and highlights the path.
452 + *
453 + * @param bandWidth bandWidth
454 + * @param bandWidthType is the kbps or mbps
455 + * @param costType is igp or te
456 + * @param tunnelName tunnel id
457 + */
458 + private void findAndSendPathsUpdate(String bandWidth, String bandWidthType, String costType, String tunnelIdStr) {
459 + if (tunnelIdStr != null) {
460 + List<Constraint> listConstrnt;
461 +
462 + if (tunnelIdStr.equals(STRING_NULL)) {
463 + log.error("update path is failed");
464 + return;
465 + }
466 +
467 + if (pceService == null) {
468 + log.error("PCE service is not active");
469 + return;
470 + }
471 +
472 + listConstrnt = addBandwidthCostTypeConstraints(bandWidth, bandWidthType, costType);
473 + TunnelId tunnelId = TunnelId.valueOf(tunnelIdStr);
474 + boolean path = pceService.updatePath(tunnelId, listConstrnt);
475 +
476 + if (!path) {
477 + log.error("update path is failed");
478 + return;
479 + }
480 + }
481 + return;
214 } 482 }
215 483
484 + /**
485 + * Handles the remove path and highlights the paths if existed.
486 + *
487 + * @param tunnelIdName tunnelId
488 + */
489 + private void findAndSendPathsRemove(String tunnelIdStr) {
490 + if (tunnelIdStr != null) {
491 + if (pceService == null) {
492 + log.error("PCE service is not active");
493 + return;
216 } 494 }
217 495
218 - //TODO: The below code is not used. Once get path from PCE app then below code will be use. 496 + TunnelId tunnelId = TunnelId.valueOf(tunnelIdStr);
219 - // the below code will get path and it will highlight the selected path. 497 + boolean path = pceService.releasePath(tunnelId);
220 - //Currently primary path in use, there is no use of secondary path. 498 + if (!path) {
221 - //secondary path need to remove based on path received by PCE app. 499 + log.error("remove path is failed");
222 - private ImmutableSet.Builder<Link> buildPaths( 500 + return;
223 - ImmutableSet.Builder<Link> pathBuilder) { 501 + }
502 + }
503 + return;
504 + }
505 +
506 + private ImmutableSet.Builder<Link> buildPaths(ImmutableSet.Builder<Link> pathBuilder) {
224 paths.forEach(path -> path.links().forEach(pathBuilder::add)); 507 paths.forEach(path -> path.links().forEach(pathBuilder::add));
225 return pathBuilder; 508 return pathBuilder;
226 } 509 }
227 510
228 - private ImmutableSet.Builder<Link> buildDisjointPaths( 511 + /**
229 - ImmutableSet.Builder<Link> pathBuilder) { 512 + * Handles the preparation of constraints list with given bandwidth and cost-type.
230 - paths.forEach(path -> { 513 + *
231 - DisjointPath dp = (DisjointPath) path; 514 + * @param bandWidth bandWidth
232 - pathBuilder.addAll(dp.primary().links()); 515 + * @param bandWidthType is the kbps or mbps
233 - pathBuilder.addAll(dp.backup().links()); 516 + * @param costType is igp or te
234 - }); 517 + * @param listConstrnt list of constraints
235 - return pathBuilder; 518 + * @return
519 + */
520 + private List<Constraint> addBandwidthCostTypeConstraints(String bandWidth,
521 + String bandWidthType,
522 + String costType) {
523 + List<Constraint> listConstrnt = new LinkedList<>();
524 + //bandwidth
525 + double bwValue = 0.0;
526 + if (!bandWidth.equals(STRING_NULL)) {
527 + bwValue = Double.parseDouble(bandWidth);
528 + }
529 + if (bandWidthType.equals(BANDWIDTH_TYPE_KBPS)) {
530 + bwValue = bwValue * BANDWIDTH_KBPS;
531 + } else {
532 + bwValue = bwValue * BANDWIDTH_MBPS;
533 + }
534 +
535 + //Cost type
536 + CostConstraint.Type costTypeVal = null;
537 + switch (costType) {
538 + case COST_TYPE_IGP:
539 + costTypeVal = CostConstraint.Type.COST;
540 + break;
541 + case COST_TYPE_TE:
542 + costTypeVal = CostConstraint.Type.TE_COST;
543 + break;
544 + default:
545 + log.error("Invalid cost type");
546 + break;
236 } 547 }
237 548
549 + if (bwValue != 0.0) {
550 + listConstrnt.add(BandwidthConstraint.of(bwValue, DataRateUnit.valueOf(BANDWIDTH_BPS)));
551 + }
552 +
553 + if (costTypeVal != null) {
554 + listConstrnt.add(CostConstraint.of(costTypeVal));
555 + }
556 +
557 + return listConstrnt;
558 + }
559 +
560 + /**
561 + * Handles the highlights of selected path.
562 + */
238 private void hilightAndSendPaths() { 563 private void hilightAndSendPaths() {
239 PceWebLinkMap linkMap = new PceWebLinkMap(); 564 PceWebLinkMap linkMap = new PceWebLinkMap();
240 allPathLinks.forEach(linkMap::add); 565 allPathLinks.forEach(linkMap::add);
241 -
242 Set<Link> selectedPathLinks; 566 Set<Link> selectedPathLinks;
243 567
244 - selectedPathLinks = paths.isEmpty() ? ImmutableSet.of() 568 + selectedPathLinks = paths.isEmpty() ?
245 - : ImmutableSet.copyOf(paths.get(pathIndex).links()); 569 + ImmutableSet.of() : ImmutableSet.copyOf(paths.get(pathIndex).links());
246 570
247 Highlights highlights = new Highlights(); 571 Highlights highlights = new Highlights();
248 if (highlightDelay > 0) { 572 if (highlightDelay > 0) {
...@@ -261,16 +585,32 @@ public class PceWebTopovMessageHandler extends UiMessageHandler { ...@@ -261,16 +585,32 @@ public class PceWebTopovMessageHandler extends UiMessageHandler {
261 sendMessage(TopoJson.highlightsMessage(highlights)); 585 sendMessage(TopoJson.highlightsMessage(highlights));
262 } 586 }
263 587
588 + /**
589 + * Handles the addition of badge and highlights.
590 + *
591 + * @param highlights highlights
592 + * @param type device type
593 + * @param elemId device to be add badge
594 + * @param src device to be add badge
595 + * @return
596 + */
264 private Highlights addBadge(Highlights highlights, String type, 597 private Highlights addBadge(Highlights highlights, String type,
265 String elemId, String src) { 598 String elemId, String src) {
266 - if (SWITCH.equals(type)) { 599 + if (ROUTER.equals(type)) {
267 highlights = addDeviceBadge(highlights, elemId, src); 600 highlights = addDeviceBadge(highlights, elemId, src);
268 - } else if (ENDSTATION.equals(type)) {
269 - highlights = addHostBadge(highlights, elemId, src);
270 } 601 }
602 +
271 return highlights; 603 return highlights;
272 } 604 }
273 605
606 + /**
607 + * Handles the badge add and highlights.
608 + *
609 + * @param h highlights
610 + * @param elemId device to be add badge
611 + * @param type device type
612 + * @return highlights
613 + */
274 private Highlights addDeviceBadge(Highlights h, String elemId, String type) { 614 private Highlights addDeviceBadge(Highlights h, String elemId, String type) {
275 DeviceHighlight dh = new DeviceHighlight(elemId); 615 DeviceHighlight dh = new DeviceHighlight(elemId);
276 dh.setBadge(createBadge(type)); 616 dh.setBadge(createBadge(type));
...@@ -278,18 +618,59 @@ public class PceWebTopovMessageHandler extends UiMessageHandler { ...@@ -278,18 +618,59 @@ public class PceWebTopovMessageHandler extends UiMessageHandler {
278 return h; 618 return h;
279 } 619 }
280 620
281 - private Highlights addHostBadge(Highlights h, String elemId, String type) { 621 + /**
282 - HostHighlight hh = new HostHighlight(elemId); 622 + * Handles the node badge add and highlights.
283 - hh.setBadge(createBadge(type)); 623 + *
284 - h.add(hh); 624 + * @param type device type
285 - return h; 625 + * @return badge of given node
286 - } 626 + */
287 -
288 private NodeBadge createBadge(String type) { 627 private NodeBadge createBadge(String type) {
289 return NodeBadge.text(type); 628 return NodeBadge.text(type);
290 } 629 }
291 630
292 - //TODO: Listeners need to add. 631 + /**
293 - //If topology changes then path need to be re calculate. 632 + * Handles the event of topology listeners.
633 + */
634 + private class InternalTopologyListener implements TopologyListener {
635 + @Override
636 + public void event(TopologyEvent event) {
637 + highlightDelay = DELAY_MS;
638 + findTunnelAndHighlights();
639 + highlightDelay = 0;
640 + }
641 + }
642 +
643 + /**
644 + * Handles the event of tunnel listeners.
645 + */
646 + private class InnerPceWebTunnelListener implements TunnelListener {
647 + @Override
648 + public void event(TunnelEvent event) {
649 + Tunnel tunnel = event.subject();
650 + if (tunnel.type() == MPLS) {
651 + highlightDelay = DELAY_MS;
652 + findTunnelAndHighlights();
653 + highlightDelay = 0;
654 + }
655 + }
656 + }
657 +
658 + /**
659 + * Handles the event of topology listeners.
660 + */
661 + private void findTunnelAndHighlights() {
662 + Collection<Tunnel> tunnelSet = null;
663 + tunnelSet = tunnelService.queryTunnel(MPLS);
664 + for (Tunnel tunnel : tunnelSet) {
665 + if (tunnel.path() == null) {
666 + log.info("path does not exist");
667 + return;
668 + }
669 + paths.add(tunnel.path());
670 + }
294 671
672 + ImmutableSet.Builder<Link> builder = ImmutableSet.builder();
673 + allPathLinks = buildPaths(builder).build();
674 + hilightAndSendPaths();
675 + }
295 } 676 }
......
...@@ -63,7 +63,6 @@ public class PceWebTopovOverlay extends UiTopoOverlay { ...@@ -63,7 +63,6 @@ public class PceWebTopovOverlay extends UiTopoOverlay {
63 public void modifyDeviceDetails(PropertyPanel pp, DeviceId deviceId) { 63 public void modifyDeviceDetails(PropertyPanel pp, DeviceId deviceId) {
64 64
65 pp.title(MY_TITLE); 65 pp.title(MY_TITLE);
66 - log.info("Modify device details called.");
67 66
68 DeviceService deviceService = AbstractShellCommand.get(DeviceService.class); 67 DeviceService deviceService = AbstractShellCommand.get(DeviceService.class);
69 68
......