blob: a1a9a251d8f052a9dc5ec0e19c70a323e011a54a [file] [log] [blame]
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +05303 *
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
Satish Kba1c9122017-04-05 15:27:23 +053019import com.fasterxml.jackson.databind.JsonNode;
Simon Hunt8a0429a2017-01-06 16:52:47 -080020import com.fasterxml.jackson.databind.node.ArrayNode;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053021import com.fasterxml.jackson.databind.node.ObjectNode;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053022import com.google.common.collect.ImmutableSet;
Satish Kba1c9122017-04-05 15:27:23 +053023import com.google.common.collect.Lists;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053024import org.onlab.osgi.ServiceDirectory;
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +053025import org.onlab.packet.IpAddress;
26import org.onlab.util.DataRateUnit;
Simon Hunt8a0429a2017-01-06 16:52:47 -080027import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
28import org.onosproject.incubator.net.tunnel.Tunnel;
29import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
30import org.onosproject.incubator.net.tunnel.TunnelEvent;
31import org.onosproject.incubator.net.tunnel.TunnelId;
32import org.onosproject.incubator.net.tunnel.TunnelListener;
33import org.onosproject.incubator.net.tunnel.TunnelService;
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +053034import org.onosproject.net.Device;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053035import org.onosproject.net.DeviceId;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053036import org.onosproject.net.ElementId;
37import org.onosproject.net.HostId;
38import org.onosproject.net.Link;
39import org.onosproject.net.Path;
Simon Hunt8a0429a2017-01-06 16:52:47 -080040import org.onosproject.net.device.DeviceService;
41import org.onosproject.net.intent.Constraint;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053042import org.onosproject.net.topology.TopologyService;
Simon Hunt8a0429a2017-01-06 16:52:47 -080043import org.onosproject.pce.pceservice.LspType;
44import org.onosproject.pce.pceservice.api.PceService;
45import org.onosproject.pce.pceservice.constraint.CostConstraint;
Satish K2eb5d842017-04-04 16:28:37 +053046import org.onosproject.pce.pceservice.constraint.PceBandwidthConstraint;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053047import org.onosproject.ui.RequestHandler;
48import org.onosproject.ui.UiConnection;
49import org.onosproject.ui.UiMessageHandler;
50import org.onosproject.ui.topo.DeviceHighlight;
51import org.onosproject.ui.topo.Highlights;
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +053052import org.onosproject.ui.topo.LinkHighlight;
53import org.onosproject.ui.topo.Mod;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053054import org.onosproject.ui.topo.NodeBadge;
Satish Kba1c9122017-04-05 15:27:23 +053055import org.onosproject.ui.topo.TopoJson;
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +053056import org.onosproject.ui.topo.TopoUtils;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053057import org.slf4j.Logger;
58import org.slf4j.LoggerFactory;
59
Satish Kba1c9122017-04-05 15:27:23 +053060import java.util.Arrays;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053061import java.util.Collection;
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +053062import java.util.LinkedList;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053063import java.util.List;
64import java.util.Set;
65
Simon Hunt8a0429a2017-01-06 16:52:47 -080066import static org.onosproject.incubator.net.tunnel.Tunnel.State.ACTIVE;
67import static org.onosproject.incubator.net.tunnel.Tunnel.Type.MPLS;
68import static org.onosproject.ui.topo.LinkHighlight.Flavor.PRIMARY_HIGHLIGHT;
69import static org.onosproject.ui.topo.TopoJson.highlightsMessage;
70
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053071/**
72 * ONOS UI PCE WEB Topology-Overlay message handler.
73 */
74public class PceWebTopovMessageHandler extends UiMessageHandler {
75
76 private static final String PCEWEB_CLEAR = "pceTopovClear";
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053077 private static final String PCEWEB_SET_PATH = "pceTopovSetMode";
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +053078 private static final String PCEWEB_UPDATE_PATH_QUERY = "pceTopovUpdateQuery";
79 private static final String PCEWEB_UPDATE_PATH = "pceTopovUpdate";
80 private static final String PCEWEB_REMOVE_PATH_QUERY = "pceTopovRemQuery";
81 private static final String PCEWEB_REMOVE_PATH = "pceTopovRem";
82 private static final String PCEWEB_QUERY_TUNNELS = "pceTopovTunnelDisplay";
83 private static final String PCEWEB_SHOW_TUNNEL = "pceTopovShowTunnels";
84 private static final String PCEWEB_SHOW_TUNNEL_REMOVE = "pceTopovShowTunnelsRem";
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +053085 private static final String PCEWEB_TUNNEL_UPDATE_INFO = "updatePathmsgInfo";
86 private static final String PCEWEB_TUNNEL_UPDATE_INFO_REPLY = "pceTopovShowTunnelsUpdate";
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +053087 private static final String PCEWEB_TUNNEL_QUERY_INFO = "pceTopovShowTunnelsQuery";
88 private static final String PCEWEB_TUNNEL_QUERY_INFO_SHOW = "pceTopovshowTunnelHighlightMsg";
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +053089 private static final String DST = "DST";
90 private static final String SRC = "SRC";
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +053091 private static final String BANDWIDTH = "bw";
Satish Kba1c9122017-04-05 15:27:23 +053092 private static final String LOADBALANCING = "lb";
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +053093 private static final String BANDWIDTHTYPE = "bwtype";
94 private static final String COSTTYPE = "ctype";
95 private static final String LSPTYPE = "lsptype";
96 private static final String SRCID = "srid";
97 private static final String DSTID = "dsid";
98 private static final String TUNNEL_ID = "tunnelid";
99 private static final String TUNNEL_NAME = "tunnelname";
100 private static final String COST_TYPE_IGP = "igp";
101 private static final String COST_TYPE_TE = "te";
102 private static final String BANDWIDTH_TYPE_KBPS = "kbps";
MaheshRaju-Huaweifc9f8bc2016-07-14 12:33:22 +0530103 private static final String BANDWIDTH_TYPE_MBPS = "mbps";
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530104 private static final String BUFFER_ARRAY = "a";
105 private static final String BANDWIDTH_BPS = "BPS";
106 private static final String LSP_TYPE_CR = "cr";
107 private static final String LSP_TYPE_SRBE = "srbe";
108 private static final String LSP_TYPE_SRTE = "srte";
109 private static final String STRING_NULL = "null";
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530110 // Delay for showHighlights event processing on GUI client side to
111 // account for addLink animation.
Simon Hunt8a0429a2017-01-06 16:52:47 -0800112 private static final int DELAY_MS = 1_100;
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530113 private static final double BANDWIDTH_KBPS = 1_000;
114 private static final double BANDWIDTH_MBPS = 1_000_000;
Simon Hunt8a0429a2017-01-06 16:52:47 -0800115 private static final String[] LINK_COLOR = {
116 "pCol1", "pCol2", "pCol3", "pCol4", "pCol5",
117 "pCol6", "pCol7", "pCol8", "pCol9", "pCol10",
118 "pCol11", "pCol12", "pCol13", "pCol14", "pCol15"
119 };
120
121 private static final int LINK_COLOR_MAX = LINK_COLOR.length;
122
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530123 private Set<Link> allPathLinks;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530124 private ElementId src, dst;
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530125 private List<Path> paths = new LinkedList<>();
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530126 private int pathIndex;
127
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530128 private final Logger log = LoggerFactory.getLogger(getClass());
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530129 private final TunnelListener tunnelListener = new InnerPceWebTunnelListener();
130
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530131 protected TopologyService topologyService;
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530132 protected TunnelService tunnelService;
133 protected PceService pceService;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530134 protected DeviceService deviceService;
Simon Hunt8a0429a2017-01-06 16:52:47 -0800135
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530136 @Override
137 public void init(UiConnection connection, ServiceDirectory directory) {
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530138 super.init(connection, directory);
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530139 tunnelService = directory.get(TunnelService.class);
140 pceService = directory.get(PceService.class);
141 deviceService = directory.get(DeviceService.class);
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530142 tunnelService.addListener(tunnelListener);
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530143 }
144
145 @Override
146 protected Collection<RequestHandler> createRequestHandlers() {
147 return ImmutableSet.of(
148 new ClearHandler(),
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530149 new SetPathHandler(),
150 new UpdatePathQueryHandler(),
151 new UpdatePathHandler(),
152 new RemovePathQueryHandler(),
153 new RemovePathHandler(),
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530154 new UpdatePathInfoHandler(),
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530155 new ShowTunnelHandler(),
156 new ShowTunnelHighlight());
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530157 }
158
159 @Override
160 public void destroy() {
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530161 tunnelService.removeListener(tunnelListener);
162 super.destroy();
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530163 }
164
165 // Handler classes
Simon Hunt8a0429a2017-01-06 16:52:47 -0800166
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530167 /**
168 * Handles the 'clear' event received from the client.
169 */
170 private final class ClearHandler extends RequestHandler {
171
172 public ClearHandler() {
173 super(PCEWEB_CLEAR);
174 }
175
176 @Override
Simon Hunt8a0429a2017-01-06 16:52:47 -0800177 public void process(ObjectNode payload) {
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530178 src = null;
179 dst = null;
Simon Hunt8a0429a2017-01-06 16:52:47 -0800180 sendMessage(highlightsMessage(new Highlights()));
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530181 }
182 }
183
184 /**
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530185 * Handles the 'path calculation' event received from the client.
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530186 */
187 private final class SetPathHandler extends RequestHandler {
188
189 public SetPathHandler() {
190 super(PCEWEB_SET_PATH);
191 }
192
193 @Override
Simon Hunt8a0429a2017-01-06 16:52:47 -0800194 public void process(ObjectNode payload) {
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530195 String srcId = string(payload, SRCID);
196 src = elementId(srcId);
197 String dstId = string(payload, DSTID);
198 dst = elementId(dstId);
199 if (src.equals(dst)) {
200 src = null;
201 }
202
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530203 String bandWidth = string(payload, BANDWIDTH);
204 String bandWidthType = string(payload, BANDWIDTHTYPE);
205 String costType = string(payload, COSTTYPE);
Satish Kba1c9122017-04-05 15:27:23 +0530206 String loadBalancing = string(payload, LOADBALANCING);
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530207 String lspType = string(payload, LSPTYPE);
208 String tunnelName = string(payload, TUNNEL_NAME);
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530209
Priyanka Bf97e13d2016-07-28 10:57:15 +0530210 if (tunnelName == null || tunnelName.equals(STRING_NULL)) {
211 log.error("tunnel name should not be empty");
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530212 return;
213 }
Priyanka Bf97e13d2016-07-28 10:57:15 +0530214 //Validating tunnel name, duplicated tunnel names not allowed
215 Collection<Tunnel> existingTunnels = tunnelService.queryTunnel(Tunnel.Type.MPLS);
216 if (existingTunnels != null) {
217 for (Tunnel t : existingTunnels) {
218 if (t.tunnelName().toString().equals(tunnelName)) {
219 log.error("Path creation failed, Tunnel name already exists");
220 return;
221 }
222 }
223 }
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530224
225 if (pceService == null) {
226 log.error("PCE service is not active");
227 return;
228 }
229
MaheshRaju-Huaweiaec67f82016-07-18 16:39:25 +0530230 if (lspType == null || lspType.equals(STRING_NULL)) {
231 log.error("PCE setup path is failed as LSP type is mandatory");
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530232 }
233
234 if ((src != null) && (dst != null)) {
Satish Kba1c9122017-04-05 15:27:23 +0530235 findAndSendPaths(src, dst, bandWidth, bandWidthType, costType, lspType, tunnelName, loadBalancing);
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530236 }
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530237 }
238 }
239
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530240 /**
241 * Handles the 'update path query' event received from the client.
242 */
243 private final class UpdatePathQueryHandler extends RequestHandler {
244
245 public UpdatePathQueryHandler() {
246 super(PCEWEB_UPDATE_PATH_QUERY);
247 }
248
249 @Override
Simon Hunt8a0429a2017-01-06 16:52:47 -0800250 public void process(ObjectNode payload) {
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530251 String srcId = string(payload, SRCID);
252 ElementId src = elementId(srcId);
253 String dstId = string(payload, DSTID);
254 ElementId dst = elementId(dstId);
255 Device srcDevice = deviceService.getDevice((DeviceId) src);
256 Device dstDevice = deviceService.getDevice((DeviceId) dst);
257
258 TunnelEndPoint tunSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress
259 .valueOf(srcDevice.annotations().value("lsrId")));
260 TunnelEndPoint tunDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress
261 .valueOf(dstDevice.annotations().value("lsrId")));
262
263 Collection<Tunnel> tunnelSet = tunnelService.queryTunnel(tunSrc, tunDst);
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530264 ObjectNode result = objectNode();
265 ArrayNode arrayNode = arrayNode();
266 for (Tunnel tunnel : tunnelSet) {
267 if (tunnel.type() == MPLS) {
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530268 if (tunnel.state().equals(ACTIVE)) {
269 arrayNode.add(tunnel.tunnelId().toString());
270 arrayNode.add(tunnel.tunnelName().toString());
271 }
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530272 }
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530273 }
274
275 result.putArray(BUFFER_ARRAY).addAll(arrayNode);
Simon Hunt8a0429a2017-01-06 16:52:47 -0800276 sendMessage(PCEWEB_SHOW_TUNNEL, result);
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530277 }
278 }
279
280 /**
281 * Handles the 'update path' event received from the client.
282 */
283 private final class UpdatePathHandler extends RequestHandler {
284
285 public UpdatePathHandler() {
286 super(PCEWEB_UPDATE_PATH);
287 }
288
289 @Override
Simon Hunt8a0429a2017-01-06 16:52:47 -0800290 public void process(ObjectNode payload) {
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530291 String bandWidth = string(payload, BANDWIDTH);
292 String bandWidthType = string(payload, BANDWIDTHTYPE);
293 String costType = string(payload, COSTTYPE);
294 String tunnelId = string(payload, TUNNEL_ID);
295
296 if (tunnelId == null) {
297 log.error("PCE update path is failed.");
298 }
299
300 findAndSendPathsUpdate(bandWidth, bandWidthType, costType, tunnelId);
301 }
302 }
303
304 /**
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530305 * Handles the 'update path' event received from the client.
306 */
307 private final class UpdatePathInfoHandler extends RequestHandler {
308
309 public UpdatePathInfoHandler() {
310 super(PCEWEB_TUNNEL_UPDATE_INFO);
311 }
312
313 @Override
Simon Hunt8a0429a2017-01-06 16:52:47 -0800314 public void process(ObjectNode payload) {
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530315 String tunnelIdStr = string(payload, TUNNEL_ID);
316
317 if (tunnelIdStr == null) {
318 log.error("PCE update path is failed.");
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530319 return;
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530320 }
321
322 if (tunnelIdStr.equals(STRING_NULL)) {
323 log.error("PCE update path is failed.");
324 return;
325 }
326
327 if (pceService == null) {
328 log.error("PCE service is not active");
329 return;
330 }
331
332 TunnelId tunnelId = TunnelId.valueOf(tunnelIdStr);
333 Tunnel tunnel = tunnelService.queryTunnel(tunnelId);
334 ObjectNode result = objectNode();
335 ArrayNode arrayNode = arrayNode();
336
337 arrayNode.add("Tunnel");
338 arrayNode.add(tunnelIdStr);
339 arrayNode.add("BandWidth");
340 arrayNode.add(tunnel.annotations().value("bandwidth"));
341 arrayNode.add("CostType");
342 arrayNode.add(tunnel.annotations().value("costType"));
343
344 result.putArray(BUFFER_ARRAY).addAll(arrayNode);
Simon Hunt8a0429a2017-01-06 16:52:47 -0800345 sendMessage(PCEWEB_TUNNEL_UPDATE_INFO_REPLY, result);
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530346 }
347 }
348
349 /**
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530350 * Handles the 'remove path query' event received from the client.
351 */
352 private final class RemovePathQueryHandler extends RequestHandler {
353
354 public RemovePathQueryHandler() {
355 super(PCEWEB_REMOVE_PATH_QUERY);
356 }
357
358 @Override
Simon Hunt8a0429a2017-01-06 16:52:47 -0800359 public void process(ObjectNode payload) {
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530360 String srcId = string(payload, SRCID);
361 ElementId src = elementId(srcId);
362 String dstId = string(payload, DSTID);
363 ElementId dst = elementId(dstId);
364
365 Device srcDevice = deviceService.getDevice((DeviceId) src);
366 Device dstDevice = deviceService.getDevice((DeviceId) dst);
367
368 TunnelEndPoint tunSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress
369 .valueOf(srcDevice.annotations().value("lsrId")));
370 TunnelEndPoint tunDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress
371 .valueOf(dstDevice.annotations().value("lsrId")));
372
373 Collection<Tunnel> tunnelSet = tunnelService.queryTunnel(tunSrc, tunDst);
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530374 ObjectNode result = objectNode();
375 ArrayNode arrayNode = arrayNode();
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530376
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530377 for (Tunnel tunnel : tunnelSet) {
378 if (tunnel.type() == MPLS) {
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530379 if (tunnel.state().equals(ACTIVE)) {
Satish Kba1c9122017-04-05 15:27:23 +0530380
381 if (tunnel.annotations().value("loadBalancingPathName") != null) {
382 boolean present = false;
383 if (!arrayNode.isNull()) {
384 for (JsonNode node : arrayNode) {
385 if (node.asText().equals(tunnel.annotations().value("loadBalancingPathName"))) {
386 present = true;
387 break;
388 }
389 }
390 if (!present) {
391 arrayNode.add("");
392 arrayNode.add(tunnel.annotations().value("loadBalancingPathName"));
393 }
394 }
395
396 } else {
397 arrayNode.add(tunnel.tunnelId().toString());
398 arrayNode.add(tunnel.tunnelName().toString());
399 }
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530400 }
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530401 }
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530402 }
403
404 result.putArray(BUFFER_ARRAY).addAll(arrayNode);
Simon Hunt8a0429a2017-01-06 16:52:47 -0800405 sendMessage(PCEWEB_SHOW_TUNNEL_REMOVE, result);
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530406 }
407 }
408
409 /**
410 * Handles the 'remove path' event received from the client.
411 */
412 private final class RemovePathHandler extends RequestHandler {
413
414 public RemovePathHandler() {
415 super(PCEWEB_REMOVE_PATH);
416 }
417
418 @Override
Simon Hunt8a0429a2017-01-06 16:52:47 -0800419 public void process(ObjectNode payload) {
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530420 String tunnelId = string(payload, TUNNEL_ID);
Satish Kba1c9122017-04-05 15:27:23 +0530421 String pathName = string(payload, "tunnelname");
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530422
Satish Kba1c9122017-04-05 15:27:23 +0530423 //TODO: if tunnel id null it is load banlanced path
424 if (tunnelId.equals("") && pathName != null) {
425 findAndSendPathsRemove(STRING_NULL, pathName);
426 /* List<TunnelId> tunnelIds = pceService.getLoadBalancedPath(pathName);
427 for (TunnelId id : tunnelIds) {
428 Tunnel tunnel = tunnelService.queryTunnel(id);
429 if (tunnel != null) {
430
431 }
432 }*/
433 } else {
434 findAndSendPathsRemove(tunnelId, null);
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530435 }
436
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530437 }
438 }
439
440 /**
441 * Handles the 'show the existed tunnels' event received from the client.
442 */
443 private final class ShowTunnelHandler extends RequestHandler {
444
445 public ShowTunnelHandler() {
446 super(PCEWEB_QUERY_TUNNELS);
447 }
448
449 @Override
Simon Hunt8a0429a2017-01-06 16:52:47 -0800450 public void process(ObjectNode payload) {
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530451 ObjectNode result = objectNode();
452 ArrayNode arrayNode = arrayNode();
453 Collection<Tunnel> tunnelSet = null;
454
455 tunnelSet = tunnelService.queryTunnel(MPLS);
456 for (Tunnel tunnel : tunnelSet) {
457 if (tunnel.state().equals(ACTIVE)) {
Satish Kba1c9122017-04-05 15:27:23 +0530458 //TODO: if it is load balancing need to check whether to send tunnel ID as null or some negative
459 //TODO;value
460 if (tunnel.annotations().value("loadBalancingPathName") != null) {
461 boolean present = false;
462 if (!arrayNode.isNull()) {
463 for (JsonNode node : arrayNode) {
464 if (node.asText().equals(tunnel.annotations().value("loadBalancingPathName"))) {
465 present = true;
466 break;
467 }
468 }
469 if (!present) {
470 arrayNode.add("");
471 arrayNode.add(tunnel.annotations().value("loadBalancingPathName"));
472 }
473 }
474
475 } else {
476 arrayNode.add(tunnel.tunnelId().toString());
477 arrayNode.add(tunnel.tunnelName().toString());
478 }
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530479 }
480 }
481
482 result.putArray(BUFFER_ARRAY).addAll(arrayNode);
Simon Hunt8a0429a2017-01-06 16:52:47 -0800483 sendMessage(PCEWEB_TUNNEL_QUERY_INFO, result);
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530484 }
485 }
486
487 /**
488 * Handles the 'show the existed tunnels' event received from the client.
489 */
490 private final class ShowTunnelHighlight extends RequestHandler {
491
492 public ShowTunnelHighlight() {
493 super(PCEWEB_TUNNEL_QUERY_INFO_SHOW);
494 }
495
496 @Override
Simon Hunt8a0429a2017-01-06 16:52:47 -0800497 public void process(ObjectNode payload) {
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530498 String tunnelIdStr = string(payload, TUNNEL_ID);
Satish Kba1c9122017-04-05 15:27:23 +0530499 String pathName = string(payload, "tunnelname");
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530500
Satish Kba1c9122017-04-05 15:27:23 +0530501 if (tunnelIdStr.equals("")) {
502 List<Tunnel> tunnels = Lists.newLinkedList();
503 List<TunnelId> tunnelIds = pceService.queryLoadBalancingPath(pathName);
504 for (TunnelId id : tunnelIds) {
505 Tunnel t = tunnelService.queryTunnel(id);
506 tunnels.add(t);
507 }
508 if (!tunnels.isEmpty()) {
509 highlightsForTunnel(tunnels);
510 }
511 } else {
512 TunnelId tunnelId = TunnelId.valueOf(tunnelIdStr);
513 Tunnel t = tunnelService.queryTunnel(tunnelId);
514 if (t != null) {
515 highlightsForTunnel(t);
516 }
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530517 }
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530518 }
519 }
520
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530521 /**
522 * provides the element id.
523 */
524 private ElementId elementId(String id) {
525 try {
526 return DeviceId.deviceId(id);
527 } catch (IllegalArgumentException e) {
528 return HostId.hostId(id);
529 }
530 }
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530531
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530532 /**
533 * Handles the setup path and highlights the path.
534 *
Simon Hunt8a0429a2017-01-06 16:52:47 -0800535 * @param src ID of source
536 * @param dst ID of destination
537 * @param bandWidth bandwidth
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530538 * @param bandWidthType is the kbps or mbps
Simon Hunt8a0429a2017-01-06 16:52:47 -0800539 * @param costType is igp or te
540 * @param lspType is WITH_SIGNALLING, WITHOUT_SIGNALLING_AND_WITHOUT_SR
541 * or SR_WITHOUT_SIGNALLING
542 * @param tunnelName tunnel id
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530543 */
Simon Hunt8a0429a2017-01-06 16:52:47 -0800544 private void findAndSendPaths(ElementId src, ElementId dst, String bandWidth,
545 String bandWidthType, String costType,
Satish Kba1c9122017-04-05 15:27:23 +0530546 String lspType, String tunnelName, String loadBalancing) {
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530547 log.debug("src={}; dst={};", src, dst);
548 boolean path;
549 List<Constraint> listConstrnt;
550
551 listConstrnt = addBandwidthCostTypeConstraints(bandWidth, bandWidthType, costType);
552
553 //LSP type
554 LspType lspTypeVal = null;
555 switch (lspType) {
556 case LSP_TYPE_CR:
557 lspTypeVal = LspType.WITH_SIGNALLING;
558 break;
559 case LSP_TYPE_SRBE:
560 lspTypeVal = LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
561 break;
562 case LSP_TYPE_SRTE:
563 lspTypeVal = LspType.SR_WITHOUT_SIGNALLING;
564 break;
565 default:
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530566 break;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530567 }
568
Satish Kba1c9122017-04-05 15:27:23 +0530569 boolean loadBalancingOpt = Boolean.parseBoolean(loadBalancing);
570
Priyanka Bbae0eeb12016-11-30 11:59:48 +0530571 //TODO: need to get explicit paths [temporarily using null as the value]
Satish Kba1c9122017-04-05 15:27:23 +0530572
573 if (loadBalancingOpt) {
574 path = pceService.setupPath((DeviceId) src, (DeviceId) dst, tunnelName, listConstrnt, lspTypeVal,
575 loadBalancingOpt);
576 } else {
577 path = pceService.setupPath((DeviceId) src, (DeviceId) dst, tunnelName, listConstrnt, lspTypeVal,
578 null);
579 }
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530580
Simon Hunt8a0429a2017-01-06 16:52:47 -0800581 if (!path) {
582 log.error("setup path is failed");
583 }
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530584 }
585
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530586 /**
587 * Handles the update path and highlights the path.
588 *
Simon Hunt8a0429a2017-01-06 16:52:47 -0800589 * @param bandWidth bandWidth
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530590 * @param bandWidthType is the kbps or mbps
Simon Hunt8a0429a2017-01-06 16:52:47 -0800591 * @param costType is igp or te
592 * @param tunnelIdStr tunnel id
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530593 */
Simon Hunt8a0429a2017-01-06 16:52:47 -0800594 private void findAndSendPathsUpdate(String bandWidth, String bandWidthType,
595 String costType, String tunnelIdStr) {
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530596 if (tunnelIdStr != null) {
597 List<Constraint> listConstrnt;
598
599 if (tunnelIdStr.equals(STRING_NULL)) {
600 log.error("update path is failed");
601 return;
602 }
603
604 if (pceService == null) {
605 log.error("PCE service is not active");
606 return;
607 }
608
609 listConstrnt = addBandwidthCostTypeConstraints(bandWidth, bandWidthType, costType);
610 TunnelId tunnelId = TunnelId.valueOf(tunnelIdStr);
611 boolean path = pceService.updatePath(tunnelId, listConstrnt);
612
613 if (!path) {
614 log.error("update path is failed");
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530615 }
616 }
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530617 }
618
619 /**
620 * Handles the remove path and highlights the paths if existed.
621 *
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530622 * @param tunnelIdStr tunnelId
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530623 */
Satish Kba1c9122017-04-05 15:27:23 +0530624 private void findAndSendPathsRemove(String tunnelIdStr, String pathName) {
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530625 if (pceService == null) {
626 log.error("PCE service is not active");
627 return;
628 }
Satish Kba1c9122017-04-05 15:27:23 +0530629 boolean path;
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530630
Satish Kba1c9122017-04-05 15:27:23 +0530631 if (tunnelIdStr.equals(STRING_NULL) && !pathName.equals(STRING_NULL)) {
632 path = pceService.releasePath(pathName);
633 } else {
634 TunnelId tunnelId = TunnelId.valueOf(tunnelIdStr);
635 path = pceService.releasePath(tunnelId);
636 }
637
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530638 if (!path) {
639 log.error("remove path is failed");
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530640 }
Satish Kba1c9122017-04-05 15:27:23 +0530641
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530642 }
643
644 private ImmutableSet.Builder<Link> buildPaths(ImmutableSet.Builder<Link> pathBuilder) {
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530645 paths.forEach(path -> path.links().forEach(pathBuilder::add));
646 return pathBuilder;
647 }
648
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530649 /**
650 * Handles the preparation of constraints list with given bandwidth and cost-type.
651 *
Simon Hunt8a0429a2017-01-06 16:52:47 -0800652 * @param bandWidth bandWidth
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530653 * @param bandWidthType is the kbps or mbps
Simon Hunt8a0429a2017-01-06 16:52:47 -0800654 * @param costType is igp or te
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530655 * @return
656 */
657 private List<Constraint> addBandwidthCostTypeConstraints(String bandWidth,
658 String bandWidthType,
659 String costType) {
660 List<Constraint> listConstrnt = new LinkedList<>();
661 //bandwidth
662 double bwValue = 0.0;
663 if (!bandWidth.equals(STRING_NULL)) {
664 bwValue = Double.parseDouble(bandWidth);
665 }
666 if (bandWidthType.equals(BANDWIDTH_TYPE_KBPS)) {
667 bwValue = bwValue * BANDWIDTH_KBPS;
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530668 } else if (bandWidthType.equals(BANDWIDTH_TYPE_MBPS)) {
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530669 bwValue = bwValue * BANDWIDTH_MBPS;
670 }
671
672 //Cost type
673 CostConstraint.Type costTypeVal = null;
674 switch (costType) {
Simon Hunt8a0429a2017-01-06 16:52:47 -0800675 case COST_TYPE_IGP:
676 costTypeVal = CostConstraint.Type.COST;
677 break;
678 case COST_TYPE_TE:
679 costTypeVal = CostConstraint.Type.TE_COST;
680 break;
681 default:
682 break;
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530683 }
684
685 if (bwValue != 0.0) {
Satish K2eb5d842017-04-04 16:28:37 +0530686 listConstrnt.add(PceBandwidthConstraint.of(bwValue, DataRateUnit.valueOf(BANDWIDTH_BPS)));
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530687 }
688
689 if (costTypeVal != null) {
690 listConstrnt.add(CostConstraint.of(costTypeVal));
691 }
692
693 return listConstrnt;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530694 }
695
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530696 /**
697 * Handles the highlights of selected path.
698 */
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530699 private void hilightAndSendPaths(Highlights highlights) {
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530700 LinkHighlight lh;
701 int linkclr = 0;
702 for (Path path : paths) {
703 for (Link link : path.links()) {
704 lh = new LinkHighlight(TopoUtils.compactLinkString(link), PRIMARY_HIGHLIGHT)
Simon Hunt8a0429a2017-01-06 16:52:47 -0800705 .addMod(new Mod(LINK_COLOR[linkclr]));
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530706 highlights.add(lh);
707 }
708 linkclr = linkclr + 1;
709 if (linkclr == LINK_COLOR_MAX) {
710 linkclr = 0;
711 }
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530712 }
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530713
Simon Hunt8a0429a2017-01-06 16:52:47 -0800714 sendMessage(highlightsMessage(highlights));
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530715 }
716
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530717 /**
Simon Hunt8a0429a2017-01-06 16:52:47 -0800718 * Handles the addition of badge and highlights.
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530719 *
720 * @param highlights highlights
Simon Hunt8a0429a2017-01-06 16:52:47 -0800721 * @param elemId device to be add badge
722 * @param src device to be add badge
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530723 * @return
724 */
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530725 private Highlights addBadge(Highlights highlights,
Simon Hunt8a0429a2017-01-06 16:52:47 -0800726 String elemId, String src) {
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530727 highlights = addDeviceBadge(highlights, elemId, src);
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530728 return highlights;
729 }
730
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530731 /**
732 * Handles the badge add and highlights.
733 *
Simon Hunt8a0429a2017-01-06 16:52:47 -0800734 * @param h highlights
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530735 * @param elemId device to be add badge
Simon Hunt8a0429a2017-01-06 16:52:47 -0800736 * @param type device badge value
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530737 * @return highlights
738 */
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530739 private Highlights addDeviceBadge(Highlights h, String elemId, String type) {
740 DeviceHighlight dh = new DeviceHighlight(elemId);
741 dh.setBadge(createBadge(type));
742 h.add(dh);
743 return h;
744 }
745
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530746 /**
747 * Handles the node badge add and highlights.
748 *
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530749 * @param type device badge value
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530750 * @return badge of given node
751 */
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530752 private NodeBadge createBadge(String type) {
753 return NodeBadge.text(type);
754 }
755
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530756 /**
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530757 * Handles the event of tunnel listeners.
758 */
759 private class InnerPceWebTunnelListener implements TunnelListener {
760 @Override
761 public void event(TunnelEvent event) {
762 Tunnel tunnel = event.subject();
763 if (tunnel.type() == MPLS) {
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530764 highlightsForTunnel(tunnel);
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530765 }
766 }
767 }
768
Satish K2eb5d842017-04-04 16:28:37 +0530769 /**
770 * Handles the event of topology listeners.
771 */
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530772 private void findTunnelAndHighlights() {
773 Collection<Tunnel> tunnelSet = null;
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530774 Highlights highlights = new Highlights();
Satish K2eb5d842017-04-04 16:28:37 +0530775 paths.removeAll(paths);
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530776 tunnelSet = tunnelService.queryTunnel(MPLS);
Satish K2eb5d842017-04-04 16:28:37 +0530777 if (tunnelSet.size() == 0) {
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530778 log.warn("Tunnel does not exist");
Simon Hunt8a0429a2017-01-06 16:52:47 -0800779 sendMessage(highlightsMessage(highlights));
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530780 return;
781 }
782
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530783 for (Tunnel tunnel : tunnelSet) {
784 if (tunnel.path() == null) {
785 log.error("path does not exist");
Simon Hunt8a0429a2017-01-06 16:52:47 -0800786 sendMessage(highlightsMessage(highlights));
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530787 return;
788 }
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530789 if (!tunnel.state().equals(ACTIVE)) {
790 log.debug("Tunnel state is not active");
Simon Hunt8a0429a2017-01-06 16:52:47 -0800791 sendMessage(highlightsMessage(highlights));
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530792 return;
793 }
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530794 Link firstLink = tunnel.path().links().get(0);
795 if (firstLink != null) {
796 if (firstLink.src() != null) {
Simon Hunt8a0429a2017-01-06 16:52:47 -0800797 highlights = addBadge(highlights, firstLink.src().deviceId().toString(), SRC);
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530798 }
799 }
800 Link lastLink = tunnel.path().links().get(tunnel.path().links().size() - 1);
801 if (lastLink != null) {
802 if (lastLink.dst() != null) {
Simon Hunt8a0429a2017-01-06 16:52:47 -0800803 highlights = addBadge(highlights, lastLink.dst().deviceId().toString(), DST);
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530804 }
805 }
806 paths.add(tunnel.path());
807 }
808
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530809 ImmutableSet.Builder<Link> builder = ImmutableSet.builder();
810 allPathLinks = buildPaths(builder).build();
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530811 hilightAndSendPaths(highlights);
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530812 }
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530813
Satish Kba1c9122017-04-05 15:27:23 +0530814 private void highlightsForTunnel(Tunnel... tunnels) {
815 highlightsForTunnel(Arrays.asList(tunnels));
816 }
Satish K2eb5d842017-04-04 16:28:37 +0530817 /**
818 * Handles the event of topology listeners.
819 */
Satish Kba1c9122017-04-05 15:27:23 +0530820 private void highlightsForTunnel(List<Tunnel> tunnels) {
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530821 Highlights highlights = new Highlights();
Satish K2eb5d842017-04-04 16:28:37 +0530822 paths.removeAll(paths);
Satish Kba1c9122017-04-05 15:27:23 +0530823
824 if (tunnels.isEmpty()) {
825 log.error("path does not exist");
826 sendMessage(TopoJson.highlightsMessage(highlights));
827 return;
828 }
829 for (Tunnel tunnel : tunnels) {
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530830 if (tunnel.path() == null) {
831 log.error("path does not exist");
Simon Hunt8a0429a2017-01-06 16:52:47 -0800832 sendMessage(highlightsMessage(highlights));
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530833 return;
834 }
835 if (!tunnel.state().equals(ACTIVE)) {
836 log.debug("Tunnel state is not active");
Simon Hunt8a0429a2017-01-06 16:52:47 -0800837 sendMessage(highlightsMessage(highlights));
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530838 return;
839 }
840
841 Link firstLink = tunnel.path().links().get(0);
842 if (firstLink != null) {
843 if (firstLink.src() != null) {
844 highlights = addBadge(highlights, firstLink.src().deviceId().toString(), SRC);
845 }
846 }
847 Link lastLink = tunnel.path().links().get(tunnel.path().links().size() - 1);
848 if (lastLink != null) {
849 if (lastLink.dst() != null) {
Simon Hunt8a0429a2017-01-06 16:52:47 -0800850 highlights = addBadge(highlights, lastLink.dst().deviceId().toString(), DST);
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530851 }
852 }
853 paths.add(tunnel.path());
Satish Kba1c9122017-04-05 15:27:23 +0530854 }
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530855
856 ImmutableSet.Builder<Link> builder = ImmutableSet.builder();
857 allPathLinks = buildPaths(builder).build();
858 hilightAndSendPaths(highlights);
859 }
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530860}