blob: 2c2ff0fb13e9b678ea4129aca2d6b049133f3850 [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-Huawei85930052016-04-26 21:09:57 +053031import org.onosproject.net.topology.TopologyService;
32import org.onosproject.ui.RequestHandler;
33import org.onosproject.ui.UiConnection;
34import org.onosproject.ui.UiMessageHandler;
35import org.onosproject.ui.topo.DeviceHighlight;
36import org.onosproject.ui.topo.Highlights;
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +053037import org.onosproject.ui.topo.LinkHighlight;
38import org.onosproject.ui.topo.Mod;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053039import org.onosproject.ui.topo.NodeBadge;
40import org.onosproject.ui.topo.TopoJson;
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +053041import org.onosproject.ui.topo.TopoUtils;
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +053042import org.onosproject.net.device.DeviceService;
43import org.onosproject.net.intent.Constraint;
44import org.onosproject.pce.pceservice.LspType;
45import org.onosproject.pce.pceservice.api.PceService;
46import org.onosproject.pce.pceservice.constraint.CostConstraint;
47import org.onosproject.net.intent.constraint.BandwidthConstraint;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053048import org.slf4j.Logger;
49import org.slf4j.LoggerFactory;
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +053050import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
51import org.onosproject.incubator.net.tunnel.Tunnel;
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +053052import static org.onosproject.incubator.net.tunnel.Tunnel.State.ACTIVE;
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +053053import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
54import org.onosproject.incubator.net.tunnel.TunnelEvent;
55import org.onosproject.incubator.net.tunnel.TunnelId;
56import org.onosproject.incubator.net.tunnel.TunnelListener;
57import org.onosproject.incubator.net.tunnel.TunnelService;
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +053058import static org.onosproject.ui.topo.LinkHighlight.Flavor.*;
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +053059import static org.onosproject.incubator.net.tunnel.Tunnel.Type.MPLS;
60
61import com.fasterxml.jackson.databind.node.ArrayNode;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053062
63import java.util.Collection;
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +053064import java.util.LinkedList;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053065import java.util.List;
66import java.util.Set;
67
68/**
69 * ONOS UI PCE WEB Topology-Overlay message handler.
70 */
71public class PceWebTopovMessageHandler extends UiMessageHandler {
72
73 private static final String PCEWEB_CLEAR = "pceTopovClear";
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053074 private static final String PCEWEB_SET_PATH = "pceTopovSetMode";
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +053075 private static final String PCEWEB_UPDATE_PATH_QUERY = "pceTopovUpdateQuery";
76 private static final String PCEWEB_UPDATE_PATH = "pceTopovUpdate";
77 private static final String PCEWEB_REMOVE_PATH_QUERY = "pceTopovRemQuery";
78 private static final String PCEWEB_REMOVE_PATH = "pceTopovRem";
79 private static final String PCEWEB_QUERY_TUNNELS = "pceTopovTunnelDisplay";
80 private static final String PCEWEB_SHOW_TUNNEL = "pceTopovShowTunnels";
81 private static final String PCEWEB_SHOW_TUNNEL_REMOVE = "pceTopovShowTunnelsRem";
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +053082 private static final String PCEWEB_TUNNEL_UPDATE_INFO = "updatePathmsgInfo";
83 private static final String PCEWEB_TUNNEL_UPDATE_INFO_REPLY = "pceTopovShowTunnelsUpdate";
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +053084 private static final String PCEWEB_TUNNEL_QUERY_INFO = "pceTopovShowTunnelsQuery";
85 private static final String PCEWEB_TUNNEL_QUERY_INFO_SHOW = "pceTopovshowTunnelHighlightMsg";
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +053086 private static final String DST = "DST";
87 private static final String SRC = "SRC";
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +053088 private static final String BANDWIDTH = "bw";
89 private static final String BANDWIDTHTYPE = "bwtype";
90 private static final String COSTTYPE = "ctype";
91 private static final String LSPTYPE = "lsptype";
92 private static final String SRCID = "srid";
93 private static final String DSTID = "dsid";
94 private static final String TUNNEL_ID = "tunnelid";
95 private static final String TUNNEL_NAME = "tunnelname";
96 private static final String COST_TYPE_IGP = "igp";
97 private static final String COST_TYPE_TE = "te";
98 private static final String BANDWIDTH_TYPE_KBPS = "kbps";
MaheshRaju-Huaweifc9f8bc2016-07-14 12:33:22 +053099 private static final String BANDWIDTH_TYPE_MBPS = "mbps";
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530100 private static final String BUFFER_ARRAY = "a";
101 private static final String BANDWIDTH_BPS = "BPS";
102 private static final String LSP_TYPE_CR = "cr";
103 private static final String LSP_TYPE_SRBE = "srbe";
104 private static final String LSP_TYPE_SRTE = "srte";
105 private static final String STRING_NULL = "null";
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530106 // Delay for showHighlights event processing on GUI client side to
107 // account for addLink animation.
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530108 private static final int DELAY_MS = 1100;
109 private static final double BANDWIDTH_KBPS = 1_000;
110 private static final double BANDWIDTH_MBPS = 1_000_000;
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530111 private static String[] linkColor = {"pCol1", "pCol2", "pCol3", "pCol4", "pCol5",
112 "pCol6", "pCol7", "pCol8", "pCol9", "pCol10",
113 "pCol11", "pCol12", "pCol13", "pCol14", "pCol15"};
114 private static final int LINK_COLOR_MAX = 15;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530115 private Set<Link> allPathLinks;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530116 private ElementId src, dst;
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530117 private List<Path> paths = new LinkedList<>();
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530118 private int pathIndex;
119
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530120 private final Logger log = LoggerFactory.getLogger(getClass());
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530121 private final TunnelListener tunnelListener = new InnerPceWebTunnelListener();
122
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530123 protected TopologyService topologyService;
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530124 protected TunnelService tunnelService;
125 protected PceService pceService;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530126 protected DeviceService deviceService;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530127 @Override
128 public void init(UiConnection connection, ServiceDirectory directory) {
129
130 super.init(connection, directory);
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530131 tunnelService = directory.get(TunnelService.class);
132 pceService = directory.get(PceService.class);
133 deviceService = directory.get(DeviceService.class);
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530134 tunnelService.addListener(tunnelListener);
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530135 }
136
137 @Override
138 protected Collection<RequestHandler> createRequestHandlers() {
139 return ImmutableSet.of(
140 new ClearHandler(),
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530141 new SetPathHandler(),
142 new UpdatePathQueryHandler(),
143 new UpdatePathHandler(),
144 new RemovePathQueryHandler(),
145 new RemovePathHandler(),
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530146 new UpdatePathInfoHandler(),
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530147 new ShowTunnelHandler(),
148 new ShowTunnelHighlight());
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530149 }
150
151 @Override
152 public void destroy() {
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530153 tunnelService.removeListener(tunnelListener);
154 super.destroy();
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530155 }
156
157 // Handler classes
158 /**
159 * Handles the 'clear' event received from the client.
160 */
161 private final class ClearHandler extends RequestHandler {
162
163 public ClearHandler() {
164 super(PCEWEB_CLEAR);
165 }
166
167 @Override
168 public void process(long sid, ObjectNode payload) {
169 src = null;
170 dst = null;
171 sendMessage(TopoJson.highlightsMessage(new Highlights()));
172 }
173 }
174
175 /**
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530176 * Handles the 'path calculation' event received from the client.
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530177 */
178 private final class SetPathHandler extends RequestHandler {
179
180 public SetPathHandler() {
181 super(PCEWEB_SET_PATH);
182 }
183
184 @Override
185 public void process(long sid, ObjectNode payload) {
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530186 String srcId = string(payload, SRCID);
187 src = elementId(srcId);
188 String dstId = string(payload, DSTID);
189 dst = elementId(dstId);
190 if (src.equals(dst)) {
191 src = null;
192 }
193
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530194 String bandWidth = string(payload, BANDWIDTH);
195 String bandWidthType = string(payload, BANDWIDTHTYPE);
196 String costType = string(payload, COSTTYPE);
197 String lspType = string(payload, LSPTYPE);
198 String tunnelName = string(payload, TUNNEL_NAME);
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530199
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530200 if (tunnelName.equals(STRING_NULL)) {
MaheshRaju-Huaweiaec67f82016-07-18 16:39:25 +0530201 log.error("PCE setup path is failed as tunnel name should not be empty");
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530202 return;
203 }
204
205 if (pceService == null) {
206 log.error("PCE service is not active");
207 return;
208 }
209
MaheshRaju-Huaweiaec67f82016-07-18 16:39:25 +0530210 if (lspType == null || lspType.equals(STRING_NULL)) {
211 log.error("PCE setup path is failed as LSP type is mandatory");
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530212 }
213
214 if ((src != null) && (dst != null)) {
215 findAndSendPaths(src, dst, bandWidth, bandWidthType, costType, lspType, tunnelName);
216 }
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530217 }
218 }
219
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530220 /**
221 * Handles the 'update path query' event received from the client.
222 */
223 private final class UpdatePathQueryHandler extends RequestHandler {
224
225 public UpdatePathQueryHandler() {
226 super(PCEWEB_UPDATE_PATH_QUERY);
227 }
228
229 @Override
230 public void process(long sid, ObjectNode payload) {
231 String srcId = string(payload, SRCID);
232 ElementId src = elementId(srcId);
233 String dstId = string(payload, DSTID);
234 ElementId dst = elementId(dstId);
235 Device srcDevice = deviceService.getDevice((DeviceId) src);
236 Device dstDevice = deviceService.getDevice((DeviceId) dst);
237
238 TunnelEndPoint tunSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress
239 .valueOf(srcDevice.annotations().value("lsrId")));
240 TunnelEndPoint tunDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress
241 .valueOf(dstDevice.annotations().value("lsrId")));
242
243 Collection<Tunnel> tunnelSet = tunnelService.queryTunnel(tunSrc, tunDst);
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530244 ObjectNode result = objectNode();
245 ArrayNode arrayNode = arrayNode();
246 for (Tunnel tunnel : tunnelSet) {
247 if (tunnel.type() == MPLS) {
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530248 if (tunnel.state().equals(ACTIVE)) {
249 arrayNode.add(tunnel.tunnelId().toString());
250 arrayNode.add(tunnel.tunnelName().toString());
251 }
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530252 }
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530253 }
254
255 result.putArray(BUFFER_ARRAY).addAll(arrayNode);
256 sendMessage(PCEWEB_SHOW_TUNNEL, sid, result);
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530257 }
258 }
259
260 /**
261 * Handles the 'update path' event received from the client.
262 */
263 private final class UpdatePathHandler extends RequestHandler {
264
265 public UpdatePathHandler() {
266 super(PCEWEB_UPDATE_PATH);
267 }
268
269 @Override
270 public void process(long sid, ObjectNode payload) {
271 String bandWidth = string(payload, BANDWIDTH);
272 String bandWidthType = string(payload, BANDWIDTHTYPE);
273 String costType = string(payload, COSTTYPE);
274 String tunnelId = string(payload, TUNNEL_ID);
275
276 if (tunnelId == null) {
277 log.error("PCE update path is failed.");
278 }
279
280 findAndSendPathsUpdate(bandWidth, bandWidthType, costType, tunnelId);
281 }
282 }
283
284 /**
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530285 * Handles the 'update path' event received from the client.
286 */
287 private final class UpdatePathInfoHandler extends RequestHandler {
288
289 public UpdatePathInfoHandler() {
290 super(PCEWEB_TUNNEL_UPDATE_INFO);
291 }
292
293 @Override
294 public void process(long sid, ObjectNode payload) {
295 String tunnelIdStr = string(payload, TUNNEL_ID);
296
297 if (tunnelIdStr == null) {
298 log.error("PCE update path is failed.");
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530299 return;
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530300 }
301
302 if (tunnelIdStr.equals(STRING_NULL)) {
303 log.error("PCE update path is failed.");
304 return;
305 }
306
307 if (pceService == null) {
308 log.error("PCE service is not active");
309 return;
310 }
311
312 TunnelId tunnelId = TunnelId.valueOf(tunnelIdStr);
313 Tunnel tunnel = tunnelService.queryTunnel(tunnelId);
314 ObjectNode result = objectNode();
315 ArrayNode arrayNode = arrayNode();
316
317 arrayNode.add("Tunnel");
318 arrayNode.add(tunnelIdStr);
319 arrayNode.add("BandWidth");
320 arrayNode.add(tunnel.annotations().value("bandwidth"));
321 arrayNode.add("CostType");
322 arrayNode.add(tunnel.annotations().value("costType"));
323
324 result.putArray(BUFFER_ARRAY).addAll(arrayNode);
325 sendMessage(PCEWEB_TUNNEL_UPDATE_INFO_REPLY, sid, result);
326 }
327 }
328
329 /**
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530330 * Handles the 'remove path query' event received from the client.
331 */
332 private final class RemovePathQueryHandler extends RequestHandler {
333
334 public RemovePathQueryHandler() {
335 super(PCEWEB_REMOVE_PATH_QUERY);
336 }
337
338 @Override
339 public void process(long sid, ObjectNode payload) {
340 String srcId = string(payload, SRCID);
341 ElementId src = elementId(srcId);
342 String dstId = string(payload, DSTID);
343 ElementId dst = elementId(dstId);
344
345 Device srcDevice = deviceService.getDevice((DeviceId) src);
346 Device dstDevice = deviceService.getDevice((DeviceId) dst);
347
348 TunnelEndPoint tunSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress
349 .valueOf(srcDevice.annotations().value("lsrId")));
350 TunnelEndPoint tunDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress
351 .valueOf(dstDevice.annotations().value("lsrId")));
352
353 Collection<Tunnel> tunnelSet = tunnelService.queryTunnel(tunSrc, tunDst);
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530354 ObjectNode result = objectNode();
355 ArrayNode arrayNode = arrayNode();
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530356
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530357 for (Tunnel tunnel : tunnelSet) {
358 if (tunnel.type() == MPLS) {
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530359 if (tunnel.state().equals(ACTIVE)) {
360 arrayNode.add(tunnel.tunnelId().toString());
361 arrayNode.add(tunnel.tunnelName().toString());
362 }
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530363 }
Mahesh Raju-Huawei2cfa5352016-05-27 20:09:51 +0530364 }
365
366 result.putArray(BUFFER_ARRAY).addAll(arrayNode);
367 sendMessage(PCEWEB_SHOW_TUNNEL_REMOVE, sid, result);
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530368 }
369 }
370
371 /**
372 * Handles the 'remove path' event received from the client.
373 */
374 private final class RemovePathHandler extends RequestHandler {
375
376 public RemovePathHandler() {
377 super(PCEWEB_REMOVE_PATH);
378 }
379
380 @Override
381 public void process(long sid, ObjectNode payload) {
382 String tunnelId = string(payload, TUNNEL_ID);
383
384 if (tunnelId == null) {
385 log.error("PCE update path is failed.");
386 }
387
388 findAndSendPathsRemove(tunnelId);
389 }
390 }
391
392 /**
393 * Handles the 'show the existed tunnels' event received from the client.
394 */
395 private final class ShowTunnelHandler extends RequestHandler {
396
397 public ShowTunnelHandler() {
398 super(PCEWEB_QUERY_TUNNELS);
399 }
400
401 @Override
402 public void process(long sid, ObjectNode payload) {
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530403 ObjectNode result = objectNode();
404 ArrayNode arrayNode = arrayNode();
405 Collection<Tunnel> tunnelSet = null;
406
407 tunnelSet = tunnelService.queryTunnel(MPLS);
408 for (Tunnel tunnel : tunnelSet) {
409 if (tunnel.state().equals(ACTIVE)) {
410 arrayNode.add(tunnel.tunnelId().toString());
411 arrayNode.add(tunnel.tunnelName().toString());
412 }
413 }
414
415 result.putArray(BUFFER_ARRAY).addAll(arrayNode);
416 sendMessage(PCEWEB_TUNNEL_QUERY_INFO, sid, result);
417 }
418 }
419
420 /**
421 * Handles the 'show the existed tunnels' event received from the client.
422 */
423 private final class ShowTunnelHighlight extends RequestHandler {
424
425 public ShowTunnelHighlight() {
426 super(PCEWEB_TUNNEL_QUERY_INFO_SHOW);
427 }
428
429 @Override
430 public void process(long sid, ObjectNode payload) {
431 String tunnelIdStr = string(payload, TUNNEL_ID);
432
433 if (tunnelIdStr == null) {
434 log.error("Tunnel Id is NULL.");
435 return;
436 }
437
438 if (tunnelIdStr.equals(STRING_NULL)) {
439 log.error("Tunnel Id is NULL.");
440 return;
441 }
442
443 if (pceService == null) {
444 log.error("PCE service is not active");
445 return;
446 }
447
448 TunnelId tunnelId = TunnelId.valueOf(tunnelIdStr);
449 Tunnel tunnel = tunnelService.queryTunnel(tunnelId);
450 if (tunnel != null) {
451 highlightsForTunnel(tunnel);
452 }
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530453 }
454 }
455
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530456 /**
457 * provides the element id.
458 */
459 private ElementId elementId(String id) {
460 try {
461 return DeviceId.deviceId(id);
462 } catch (IllegalArgumentException e) {
463 return HostId.hostId(id);
464 }
465 }
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530466
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530467 /**
468 * Handles the setup path and highlights the path.
469 *
470 * @param bandWidth
471 * @param bandWidthType is the kbps or mbps
472 * @param costType is igp or te
473 * @param lspType is WITH_SIGNALLING,WITHOUT_SIGNALLING_AND_WITHOUT_SR or SR_WITHOUT_SIGNALLING
474 * @param tunnelName tunnel id
475 */
476 private void findAndSendPaths(ElementId src, ElementId dst, String bandWidth, String bandWidthType,
477 String costType, String lspType, String tunnelName) {
478 log.debug("src={}; dst={};", src, dst);
479 boolean path;
480 List<Constraint> listConstrnt;
481
482 listConstrnt = addBandwidthCostTypeConstraints(bandWidth, bandWidthType, costType);
483
484 //LSP type
485 LspType lspTypeVal = null;
486 switch (lspType) {
487 case LSP_TYPE_CR:
488 lspTypeVal = LspType.WITH_SIGNALLING;
489 break;
490 case LSP_TYPE_SRBE:
491 lspTypeVal = LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
492 break;
493 case LSP_TYPE_SRTE:
494 lspTypeVal = LspType.SR_WITHOUT_SIGNALLING;
495 break;
496 default:
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530497 break;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530498 }
499
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530500 path = pceService.setupPath((DeviceId) src, (DeviceId) dst, tunnelName, listConstrnt, lspTypeVal);
501 if (!path) {
502 log.error("setup path is failed");
503 return;
504 }
505
506 return;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530507 }
508
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530509 /**
510 * Handles the update path and highlights the path.
511 *
512 * @param bandWidth bandWidth
513 * @param bandWidthType is the kbps or mbps
514 * @param costType is igp or te
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530515 * @param tunnelIdStr tunnel id
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530516 */
517 private void findAndSendPathsUpdate(String bandWidth, String bandWidthType, String costType, String tunnelIdStr) {
518 if (tunnelIdStr != null) {
519 List<Constraint> listConstrnt;
520
521 if (tunnelIdStr.equals(STRING_NULL)) {
522 log.error("update path is failed");
523 return;
524 }
525
526 if (pceService == null) {
527 log.error("PCE service is not active");
528 return;
529 }
530
531 listConstrnt = addBandwidthCostTypeConstraints(bandWidth, bandWidthType, costType);
532 TunnelId tunnelId = TunnelId.valueOf(tunnelIdStr);
533 boolean path = pceService.updatePath(tunnelId, listConstrnt);
534
535 if (!path) {
536 log.error("update path is failed");
537 return;
538 }
539 }
540 return;
541 }
542
543 /**
544 * Handles the remove path and highlights the paths if existed.
545 *
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530546 * @param tunnelIdStr tunnelId
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530547 */
548 private void findAndSendPathsRemove(String tunnelIdStr) {
549 if (tunnelIdStr != null) {
550 if (pceService == null) {
551 log.error("PCE service is not active");
552 return;
553 }
554
555 TunnelId tunnelId = TunnelId.valueOf(tunnelIdStr);
556 boolean path = pceService.releasePath(tunnelId);
557 if (!path) {
558 log.error("remove path is failed");
559 return;
560 }
561 }
562 return;
563 }
564
565 private ImmutableSet.Builder<Link> buildPaths(ImmutableSet.Builder<Link> pathBuilder) {
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530566 paths.forEach(path -> path.links().forEach(pathBuilder::add));
567 return pathBuilder;
568 }
569
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530570 /**
571 * Handles the preparation of constraints list with given bandwidth and cost-type.
572 *
573 * @param bandWidth bandWidth
574 * @param bandWidthType is the kbps or mbps
575 * @param costType is igp or te
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530576 * @return
577 */
578 private List<Constraint> addBandwidthCostTypeConstraints(String bandWidth,
579 String bandWidthType,
580 String costType) {
581 List<Constraint> listConstrnt = new LinkedList<>();
582 //bandwidth
583 double bwValue = 0.0;
584 if (!bandWidth.equals(STRING_NULL)) {
585 bwValue = Double.parseDouble(bandWidth);
586 }
587 if (bandWidthType.equals(BANDWIDTH_TYPE_KBPS)) {
588 bwValue = bwValue * BANDWIDTH_KBPS;
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530589 } else if (bandWidthType.equals(BANDWIDTH_TYPE_MBPS)) {
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530590 bwValue = bwValue * BANDWIDTH_MBPS;
591 }
592
593 //Cost type
594 CostConstraint.Type costTypeVal = null;
595 switch (costType) {
596 case COST_TYPE_IGP:
597 costTypeVal = CostConstraint.Type.COST;
598 break;
599 case COST_TYPE_TE:
600 costTypeVal = CostConstraint.Type.TE_COST;
601 break;
602 default:
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530603 break;
604 }
605
606 if (bwValue != 0.0) {
607 listConstrnt.add(BandwidthConstraint.of(bwValue, DataRateUnit.valueOf(BANDWIDTH_BPS)));
608 }
609
610 if (costTypeVal != null) {
611 listConstrnt.add(CostConstraint.of(costTypeVal));
612 }
613
614 return listConstrnt;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530615 }
616
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530617 /**
618 * Handles the highlights of selected path.
619 */
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530620 private void hilightAndSendPaths(Highlights highlights) {
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530621 LinkHighlight lh;
622 int linkclr = 0;
623 for (Path path : paths) {
624 for (Link link : path.links()) {
625 lh = new LinkHighlight(TopoUtils.compactLinkString(link), PRIMARY_HIGHLIGHT)
626 .addMod(new Mod(linkColor[linkclr]));
627 highlights.add(lh);
628 }
629 linkclr = linkclr + 1;
630 if (linkclr == LINK_COLOR_MAX) {
631 linkclr = 0;
632 }
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530633 }
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530634
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530635 sendMessage(TopoJson.highlightsMessage(highlights));
636 }
637
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530638 /**
639 * Handles the addition of badge and highlights.
640 *
641 * @param highlights highlights
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530642 * @param elemId device to be add badge
643 * @param src device to be add badge
644 * @return
645 */
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530646 private Highlights addBadge(Highlights highlights,
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530647 String elemId, String src) {
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530648 highlights = addDeviceBadge(highlights, elemId, src);
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530649 return highlights;
650 }
651
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530652 /**
653 * Handles the badge add and highlights.
654 *
655 * @param h highlights
656 * @param elemId device to be add badge
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530657 * @param type device badge value
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530658 * @return highlights
659 */
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530660 private Highlights addDeviceBadge(Highlights h, String elemId, String type) {
661 DeviceHighlight dh = new DeviceHighlight(elemId);
662 dh.setBadge(createBadge(type));
663 h.add(dh);
664 return h;
665 }
666
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530667 /**
668 * Handles the node badge add and highlights.
669 *
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530670 * @param type device badge value
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530671 * @return badge of given node
672 */
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530673 private NodeBadge createBadge(String type) {
674 return NodeBadge.text(type);
675 }
676
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530677 /**
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530678 * Handles the event of tunnel listeners.
679 */
680 private class InnerPceWebTunnelListener implements TunnelListener {
681 @Override
682 public void event(TunnelEvent event) {
683 Tunnel tunnel = event.subject();
684 if (tunnel.type() == MPLS) {
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530685 highlightsForTunnel(tunnel);
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530686 }
687 }
688 }
689
690 /**
691 * Handles the event of topology listeners.
692 */
693 private void findTunnelAndHighlights() {
694 Collection<Tunnel> tunnelSet = null;
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530695 Highlights highlights = new Highlights();
696 paths.removeAll(paths);
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530697 tunnelSet = tunnelService.queryTunnel(MPLS);
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530698 if (tunnelSet.size() == 0) {
699 log.warn("Tunnel does not exist");
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530700 sendMessage(TopoJson.highlightsMessage(highlights));
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530701 return;
702 }
703
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530704 for (Tunnel tunnel : tunnelSet) {
705 if (tunnel.path() == null) {
706 log.error("path does not exist");
Mahesh Raju-Huaweid8eaf972016-06-16 19:08:24 +0530707 sendMessage(TopoJson.highlightsMessage(highlights));
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530708 return;
709 }
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530710 if (!tunnel.state().equals(ACTIVE)) {
711 log.debug("Tunnel state is not active");
712 sendMessage(TopoJson.highlightsMessage(highlights));
713 return;
714 }
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530715 Link firstLink = tunnel.path().links().get(0);
716 if (firstLink != null) {
717 if (firstLink.src() != null) {
718 highlights = addBadge(highlights, firstLink.src().deviceId().toString(), SRC);
719 }
720 }
721 Link lastLink = tunnel.path().links().get(tunnel.path().links().size() - 1);
722 if (lastLink != null) {
723 if (lastLink.dst() != null) {
724 highlights = addBadge(highlights, lastLink.dst().deviceId().toString(), DST);
725 }
726 }
727 paths.add(tunnel.path());
728 }
729
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530730 ImmutableSet.Builder<Link> builder = ImmutableSet.builder();
731 allPathLinks = buildPaths(builder).build();
Mahesh Raju-Huawei0f977ef2016-06-14 17:26:22 +0530732 hilightAndSendPaths(highlights);
Mahesh Raju-Huawei5b0453a2016-05-27 11:54:27 +0530733 }
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530734
735 /**
736 * Handles the event of topology listeners.
737 */
738 private void highlightsForTunnel(Tunnel tunnel) {
739 Highlights highlights = new Highlights();
740 paths.removeAll(paths);
741 if (tunnel.path() == null) {
742 log.error("path does not exist");
743 sendMessage(TopoJson.highlightsMessage(highlights));
744 return;
745 }
746 if (!tunnel.state().equals(ACTIVE)) {
747 log.debug("Tunnel state is not active");
748 sendMessage(TopoJson.highlightsMessage(highlights));
749 return;
750 }
751
752 Link firstLink = tunnel.path().links().get(0);
753 if (firstLink != null) {
754 if (firstLink.src() != null) {
755 highlights = addBadge(highlights, firstLink.src().deviceId().toString(), SRC);
756 }
757 }
758 Link lastLink = tunnel.path().links().get(tunnel.path().links().size() - 1);
759 if (lastLink != null) {
760 if (lastLink.dst() != null) {
761 highlights = addBadge(highlights, lastLink.dst().deviceId().toString(), DST);
762 }
763 }
764 paths.add(tunnel.path());
765
766 ImmutableSet.Builder<Link> builder = ImmutableSet.builder();
767 allPathLinks = buildPaths(builder).build();
768 hilightAndSendPaths(highlights);
769 }
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530770}