blob: 16ce224acfe6d224302b30722f1968a3c978e0ee [file] [log] [blame]
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +05301/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.pceweb;
18
19import com.fasterxml.jackson.databind.node.ObjectNode;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053020import com.google.common.collect.ImmutableSet;
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +053021
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053022import org.onlab.osgi.ServiceDirectory;
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +053023import org.onlab.packet.IpAddress;
24import org.onlab.util.DataRateUnit;
25import org.onosproject.net.Device;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053026import org.onosproject.net.DeviceId;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053027import org.onosproject.net.ElementId;
28import org.onosproject.net.HostId;
29import org.onosproject.net.Link;
30import org.onosproject.net.Path;
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +053031import org.onosproject.net.topology.TopologyEvent;
32import org.onosproject.net.topology.TopologyListener;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053033import org.onosproject.net.topology.TopologyService;
34import org.onosproject.ui.RequestHandler;
35import org.onosproject.ui.UiConnection;
36import org.onosproject.ui.UiMessageHandler;
37import org.onosproject.ui.topo.DeviceHighlight;
38import org.onosproject.ui.topo.Highlights;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053039import org.onosproject.ui.topo.NodeBadge;
40import org.onosproject.ui.topo.TopoJson;
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +053041import org.onosproject.net.device.DeviceService;
42import org.onosproject.net.intent.Constraint;
43import org.onosproject.pce.pceservice.LspType;
44import org.onosproject.pce.pceservice.api.PceService;
45import org.onosproject.pce.pceservice.constraint.CostConstraint;
46import org.onosproject.net.intent.constraint.BandwidthConstraint;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053047import org.slf4j.Logger;
48import org.slf4j.LoggerFactory;
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +053049import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
50import org.onosproject.incubator.net.tunnel.Tunnel;
51import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
52import org.onosproject.incubator.net.tunnel.TunnelEvent;
53import org.onosproject.incubator.net.tunnel.TunnelId;
54import org.onosproject.incubator.net.tunnel.TunnelListener;
55import org.onosproject.incubator.net.tunnel.TunnelService;
56import static org.onosproject.incubator.net.tunnel.Tunnel.Type.MPLS;
57
58import com.fasterxml.jackson.databind.node.ArrayNode;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053059
60import java.util.Collection;
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +053061import java.util.LinkedList;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053062import java.util.List;
63import java.util.Set;
64
65/**
66 * ONOS UI PCE WEB Topology-Overlay message handler.
67 */
68public class PceWebTopovMessageHandler extends UiMessageHandler {
69
70 private static final String PCEWEB_CLEAR = "pceTopovClear";
71 private static final String PCEWEB_SET_SRC = "pceTopovSetSrc";
72 private static final String PCEWEB_SET_DST = "pceTopovSetDst";
73 private static final String PCEWEB_SET_PATH = "pceTopovSetMode";
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +053074 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";
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053081 private static final String ID = "id";
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053082 private static final String TYPE = "type";
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +053083 private static final String ROUTER = "router";
84 private static final String DST = "Egress";
85 private static final String SRC = "Ingress";
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";
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530103 // Delay for showHighlights event processing on GUI client side to
104 // account for addLink animation.
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530105 private static final int DELAY_MS = 1100;
106 private static final double BANDWIDTH_KBPS = 1_000;
107 private static final double BANDWIDTH_MBPS = 1_000_000;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530108
109 private Set<Link> allPathLinks;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530110 private int highlightDelay;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530111 private ElementId src, dst;
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530112 private List<Path> paths = new LinkedList<>();
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530113 private int pathIndex;
114
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530115 private final Logger log = LoggerFactory.getLogger(getClass());
116 private final TopologyListener topologyListener = new InternalTopologyListener();
117 private final TunnelListener tunnelListener = new InnerPceWebTunnelListener();
118
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530119 protected TopologyService topologyService;
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530120 protected TunnelService tunnelService;
121 protected PceService pceService;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530122 protected DeviceService deviceService;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530123 @Override
124 public void init(UiConnection connection, ServiceDirectory directory) {
125
126 super.init(connection, directory);
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530127 topologyService = directory.get(TopologyService.class);
128 tunnelService = directory.get(TunnelService.class);
129 pceService = directory.get(PceService.class);
130 deviceService = directory.get(DeviceService.class);
131 topologyService.addListener(topologyListener);
132 tunnelService.addListener(tunnelListener);
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530133 }
134
135 @Override
136 protected Collection<RequestHandler> createRequestHandlers() {
137 return ImmutableSet.of(
138 new ClearHandler(),
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530139 new SetPathHandler(),
140 new UpdatePathQueryHandler(),
141 new UpdatePathHandler(),
142 new RemovePathQueryHandler(),
143 new RemovePathHandler(),
144 new ShowTunnelHandler());
145 }
146
147 @Override
148 public void destroy() {
149 topologyService.removeListener(topologyListener);
150 tunnelService.removeListener(tunnelListener);
151 super.destroy();
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530152 }
153
154 // Handler classes
155 /**
156 * Handles the 'clear' event received from the client.
157 */
158 private final class ClearHandler extends RequestHandler {
159
160 public ClearHandler() {
161 super(PCEWEB_CLEAR);
162 }
163
164 @Override
165 public void process(long sid, ObjectNode payload) {
166 src = null;
167 dst = null;
168 sendMessage(TopoJson.highlightsMessage(new Highlights()));
169 }
170 }
171
172 /**
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530173 * Handles the 'path calculation' event received from the client.
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530174 */
175 private final class SetPathHandler extends RequestHandler {
176
177 public SetPathHandler() {
178 super(PCEWEB_SET_PATH);
179 }
180
181 @Override
182 public void process(long sid, ObjectNode payload) {
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530183 String srcId = string(payload, SRCID);
184 src = elementId(srcId);
185 String dstId = string(payload, DSTID);
186 dst = elementId(dstId);
187 if (src.equals(dst)) {
188 src = null;
189 }
190
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530191 String bandWidth = string(payload, BANDWIDTH);
192 String bandWidthType = string(payload, BANDWIDTHTYPE);
193 String costType = string(payload, COSTTYPE);
194 String lspType = string(payload, LSPTYPE);
195 String tunnelName = string(payload, TUNNEL_NAME);
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530196
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530197 if (tunnelName.equals(STRING_NULL)) {
198 log.error("tunnel name should not be empty");
199 return;
200 }
201
202 if (pceService == null) {
203 log.error("PCE service is not active");
204 return;
205 }
206
207 if (lspType == null) {
208 log.error("PCE setup path is failed.");
209 }
210
211 if ((src != null) && (dst != null)) {
212 findAndSendPaths(src, dst, bandWidth, bandWidthType, costType, lspType, tunnelName);
213 }
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530214 }
215 }
216
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530217 /**
218 * Handles the 'update path query' event received from the client.
219 */
220 private final class UpdatePathQueryHandler extends RequestHandler {
221
222 public UpdatePathQueryHandler() {
223 super(PCEWEB_UPDATE_PATH_QUERY);
224 }
225
226 @Override
227 public void process(long sid, ObjectNode payload) {
228 String srcId = string(payload, SRCID);
229 ElementId src = elementId(srcId);
230 String dstId = string(payload, DSTID);
231 ElementId dst = elementId(dstId);
232 Device srcDevice = deviceService.getDevice((DeviceId) src);
233 Device dstDevice = deviceService.getDevice((DeviceId) dst);
234
235 TunnelEndPoint tunSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress
236 .valueOf(srcDevice.annotations().value("lsrId")));
237 TunnelEndPoint tunDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress
238 .valueOf(dstDevice.annotations().value("lsrId")));
239
240 Collection<Tunnel> tunnelSet = tunnelService.queryTunnel(tunSrc, tunDst);
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530241 ObjectNode result = objectNode();
242 ArrayNode arrayNode = arrayNode();
243 for (Tunnel tunnel : tunnelSet) {
244 if (tunnel.type() == MPLS) {
245 arrayNode.add(tunnel.tunnelId().toString());
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530246 }
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530247 }
248
249 result.putArray(BUFFER_ARRAY).addAll(arrayNode);
250 sendMessage(PCEWEB_SHOW_TUNNEL, sid, result);
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530251 }
252 }
253
254 /**
255 * Handles the 'update path' event received from the client.
256 */
257 private final class UpdatePathHandler extends RequestHandler {
258
259 public UpdatePathHandler() {
260 super(PCEWEB_UPDATE_PATH);
261 }
262
263 @Override
264 public void process(long sid, ObjectNode payload) {
265 String bandWidth = string(payload, BANDWIDTH);
266 String bandWidthType = string(payload, BANDWIDTHTYPE);
267 String costType = string(payload, COSTTYPE);
268 String tunnelId = string(payload, TUNNEL_ID);
269
270 if (tunnelId == null) {
271 log.error("PCE update path is failed.");
272 }
273
274 findAndSendPathsUpdate(bandWidth, bandWidthType, costType, tunnelId);
275 }
276 }
277
278 /**
279 * Handles the 'remove path query' event received from the client.
280 */
281 private final class RemovePathQueryHandler extends RequestHandler {
282
283 public RemovePathQueryHandler() {
284 super(PCEWEB_REMOVE_PATH_QUERY);
285 }
286
287 @Override
288 public void process(long sid, ObjectNode payload) {
289 String srcId = string(payload, SRCID);
290 ElementId src = elementId(srcId);
291 String dstId = string(payload, DSTID);
292 ElementId dst = elementId(dstId);
293
294 Device srcDevice = deviceService.getDevice((DeviceId) src);
295 Device dstDevice = deviceService.getDevice((DeviceId) dst);
296
297 TunnelEndPoint tunSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress
298 .valueOf(srcDevice.annotations().value("lsrId")));
299 TunnelEndPoint tunDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress
300 .valueOf(dstDevice.annotations().value("lsrId")));
301
302 Collection<Tunnel> tunnelSet = tunnelService.queryTunnel(tunSrc, tunDst);
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530303 ObjectNode result = objectNode();
304 ArrayNode arrayNode = arrayNode();
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530305
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530306 for (Tunnel tunnel : tunnelSet) {
307 if (tunnel.type() == MPLS) {
308 arrayNode.add(tunnel.tunnelId().toString());
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530309 }
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530310 }
311
312 result.putArray(BUFFER_ARRAY).addAll(arrayNode);
313 sendMessage(PCEWEB_SHOW_TUNNEL_REMOVE, sid, result);
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530314 }
315 }
316
317 /**
318 * Handles the 'remove path' event received from the client.
319 */
320 private final class RemovePathHandler extends RequestHandler {
321
322 public RemovePathHandler() {
323 super(PCEWEB_REMOVE_PATH);
324 }
325
326 @Override
327 public void process(long sid, ObjectNode payload) {
328 String tunnelId = string(payload, TUNNEL_ID);
329
330 if (tunnelId == null) {
331 log.error("PCE update path is failed.");
332 }
333
334 findAndSendPathsRemove(tunnelId);
335 }
336 }
337
338 /**
339 * Handles the 'show the existed tunnels' event received from the client.
340 */
341 private final class ShowTunnelHandler extends RequestHandler {
342
343 public ShowTunnelHandler() {
344 super(PCEWEB_QUERY_TUNNELS);
345 }
346
347 @Override
348 public void process(long sid, ObjectNode payload) {
349 findTunnelAndHighlights();
350 }
351 }
352
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530353 /**
354 * provides the element id.
355 */
356 private ElementId elementId(String id) {
357 try {
358 return DeviceId.deviceId(id);
359 } catch (IllegalArgumentException e) {
360 return HostId.hostId(id);
361 }
362 }
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530363
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530364 /**
365 * Handles the setup path and highlights the path.
366 *
367 * @param bandWidth
368 * @param bandWidthType is the kbps or mbps
369 * @param costType is igp or te
370 * @param lspType is WITH_SIGNALLING,WITHOUT_SIGNALLING_AND_WITHOUT_SR or SR_WITHOUT_SIGNALLING
371 * @param tunnelName tunnel id
372 */
373 private void findAndSendPaths(ElementId src, ElementId dst, String bandWidth, String bandWidthType,
374 String costType, String lspType, String tunnelName) {
375 log.debug("src={}; dst={};", src, dst);
376 boolean path;
377 List<Constraint> listConstrnt;
378
379 listConstrnt = addBandwidthCostTypeConstraints(bandWidth, bandWidthType, costType);
380
381 //LSP type
382 LspType lspTypeVal = null;
383 switch (lspType) {
384 case LSP_TYPE_CR:
385 lspTypeVal = LspType.WITH_SIGNALLING;
386 break;
387 case LSP_TYPE_SRBE:
388 lspTypeVal = LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
389 break;
390 case LSP_TYPE_SRTE:
391 lspTypeVal = LspType.SR_WITHOUT_SIGNALLING;
392 break;
393 default:
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530394 break;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530395 }
396
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530397 path = pceService.setupPath((DeviceId) src, (DeviceId) dst, tunnelName, listConstrnt, lspTypeVal);
398 if (!path) {
399 log.error("setup path is failed");
400 return;
401 }
402
403 return;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530404 }
405
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530406 /**
407 * Handles the update path and highlights the path.
408 *
409 * @param bandWidth bandWidth
410 * @param bandWidthType is the kbps or mbps
411 * @param costType is igp or te
412 * @param tunnelName tunnel id
413 */
414 private void findAndSendPathsUpdate(String bandWidth, String bandWidthType, String costType, String tunnelIdStr) {
415 if (tunnelIdStr != null) {
416 List<Constraint> listConstrnt;
417
418 if (tunnelIdStr.equals(STRING_NULL)) {
419 log.error("update path is failed");
420 return;
421 }
422
423 if (pceService == null) {
424 log.error("PCE service is not active");
425 return;
426 }
427
428 listConstrnt = addBandwidthCostTypeConstraints(bandWidth, bandWidthType, costType);
429 TunnelId tunnelId = TunnelId.valueOf(tunnelIdStr);
430 boolean path = pceService.updatePath(tunnelId, listConstrnt);
431
432 if (!path) {
433 log.error("update path is failed");
434 return;
435 }
436 }
437 return;
438 }
439
440 /**
441 * Handles the remove path and highlights the paths if existed.
442 *
443 * @param tunnelIdName tunnelId
444 */
445 private void findAndSendPathsRemove(String tunnelIdStr) {
446 if (tunnelIdStr != null) {
447 if (pceService == null) {
448 log.error("PCE service is not active");
449 return;
450 }
451
452 TunnelId tunnelId = TunnelId.valueOf(tunnelIdStr);
453 boolean path = pceService.releasePath(tunnelId);
454 if (!path) {
455 log.error("remove path is failed");
456 return;
457 }
458 }
459 return;
460 }
461
462 private ImmutableSet.Builder<Link> buildPaths(ImmutableSet.Builder<Link> pathBuilder) {
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530463 paths.forEach(path -> path.links().forEach(pathBuilder::add));
464 return pathBuilder;
465 }
466
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530467 /**
468 * Handles the preparation of constraints list with given bandwidth and cost-type.
469 *
470 * @param bandWidth bandWidth
471 * @param bandWidthType is the kbps or mbps
472 * @param costType is igp or te
473 * @param listConstrnt list of constraints
474 * @return
475 */
476 private List<Constraint> addBandwidthCostTypeConstraints(String bandWidth,
477 String bandWidthType,
478 String costType) {
479 List<Constraint> listConstrnt = new LinkedList<>();
480 //bandwidth
481 double bwValue = 0.0;
482 if (!bandWidth.equals(STRING_NULL)) {
483 bwValue = Double.parseDouble(bandWidth);
484 }
485 if (bandWidthType.equals(BANDWIDTH_TYPE_KBPS)) {
486 bwValue = bwValue * BANDWIDTH_KBPS;
487 } else {
488 bwValue = bwValue * BANDWIDTH_MBPS;
489 }
490
491 //Cost type
492 CostConstraint.Type costTypeVal = null;
493 switch (costType) {
494 case COST_TYPE_IGP:
495 costTypeVal = CostConstraint.Type.COST;
496 break;
497 case COST_TYPE_TE:
498 costTypeVal = CostConstraint.Type.TE_COST;
499 break;
500 default:
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530501 break;
502 }
503
504 if (bwValue != 0.0) {
505 listConstrnt.add(BandwidthConstraint.of(bwValue, DataRateUnit.valueOf(BANDWIDTH_BPS)));
506 }
507
508 if (costTypeVal != null) {
509 listConstrnt.add(CostConstraint.of(costTypeVal));
510 }
511
512 return listConstrnt;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530513 }
514
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530515 /**
516 * Handles the highlights of selected path.
517 */
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530518 private void hilightAndSendPaths(Highlights highlights) {
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530519 PceWebLinkMap linkMap = new PceWebLinkMap();
520 allPathLinks.forEach(linkMap::add);
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530521 Set<Link> selectedPathLinks;
522
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530523 selectedPathLinks = paths.isEmpty() ?
524 ImmutableSet.of() : ImmutableSet.copyOf(paths.get(pathIndex).links());
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530525
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530526 if (highlightDelay > 0) {
527 highlights.delay(highlightDelay);
528 }
529 for (PceWebLink plink : linkMap.biLinks()) {
530 plink.computeHilight(selectedPathLinks, allPathLinks);
531 highlights.add(plink.highlight(null));
532 }
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530533 sendMessage(TopoJson.highlightsMessage(highlights));
534 }
535
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530536 /**
537 * Handles the addition of badge and highlights.
538 *
539 * @param highlights highlights
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530540 * @param elemId device to be add badge
541 * @param src device to be add badge
542 * @return
543 */
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530544 private Highlights addBadge(Highlights highlights,
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530545 String elemId, String src) {
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530546 highlights = addDeviceBadge(highlights, elemId, src);
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530547 return highlights;
548 }
549
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530550 /**
551 * Handles the badge add and highlights.
552 *
553 * @param h highlights
554 * @param elemId device to be add badge
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530555 * @param type device badge value
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530556 * @return highlights
557 */
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530558 private Highlights addDeviceBadge(Highlights h, String elemId, String type) {
559 DeviceHighlight dh = new DeviceHighlight(elemId);
560 dh.setBadge(createBadge(type));
561 h.add(dh);
562 return h;
563 }
564
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530565 /**
566 * Handles the node badge add and highlights.
567 *
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530568 * @param type device badge value
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530569 * @return badge of given node
570 */
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530571 private NodeBadge createBadge(String type) {
572 return NodeBadge.text(type);
573 }
574
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530575 /**
576 * Handles the event of topology listeners.
577 */
578 private class InternalTopologyListener implements TopologyListener {
579 @Override
580 public void event(TopologyEvent event) {
581 highlightDelay = DELAY_MS;
582 findTunnelAndHighlights();
583 highlightDelay = 0;
584 }
585 }
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530586
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530587 /**
588 * Handles the event of tunnel listeners.
589 */
590 private class InnerPceWebTunnelListener implements TunnelListener {
591 @Override
592 public void event(TunnelEvent event) {
593 Tunnel tunnel = event.subject();
594 if (tunnel.type() == MPLS) {
595 highlightDelay = DELAY_MS;
596 findTunnelAndHighlights();
597 highlightDelay = 0;
598 }
599 }
600 }
601
602 /**
603 * Handles the event of topology listeners.
604 */
605 private void findTunnelAndHighlights() {
606 Collection<Tunnel> tunnelSet = null;
607 tunnelSet = tunnelService.queryTunnel(MPLS);
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530608 if (tunnelSet.size() == 0) {
609 log.warn("Tunnel does not exist");
610 return;
611 }
612
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530613 paths.removeAll(paths);
614 Highlights highlights = new Highlights();
615 for (Tunnel tunnel : tunnelSet) {
616 if (tunnel.path() == null) {
617 log.error("path does not exist");
618 return;
619 }
620 Link firstLink = tunnel.path().links().get(0);
621 if (firstLink != null) {
622 if (firstLink.src() != null) {
623 highlights = addBadge(highlights, firstLink.src().deviceId().toString(), SRC);
624 }
625 }
626 Link lastLink = tunnel.path().links().get(tunnel.path().links().size() - 1);
627 if (lastLink != null) {
628 if (lastLink.dst() != null) {
629 highlights = addBadge(highlights, lastLink.dst().deviceId().toString(), DST);
630 }
631 }
632 paths.add(tunnel.path());
633 }
634
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530635 ImmutableSet.Builder<Link> builder = ImmutableSet.builder();
636 allPathLinks = buildPaths(builder).build();
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530637 hilightAndSendPaths(highlights);
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530638 }
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530639}