Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.pceweb; |
| 18 | |
| 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 20 | import com.google.common.collect.ImmutableSet; |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 21 | |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 22 | import org.onlab.osgi.ServiceDirectory; |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 23 | import org.onlab.packet.IpAddress; |
| 24 | import org.onlab.util.DataRateUnit; |
| 25 | import org.onosproject.net.Device; |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 26 | import org.onosproject.net.DeviceId; |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 27 | import org.onosproject.net.ElementId; |
| 28 | import org.onosproject.net.HostId; |
| 29 | import org.onosproject.net.Link; |
| 30 | import org.onosproject.net.Path; |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 31 | import org.onosproject.net.topology.TopologyService; |
| 32 | import org.onosproject.ui.RequestHandler; |
| 33 | import org.onosproject.ui.UiConnection; |
| 34 | import org.onosproject.ui.UiMessageHandler; |
| 35 | import org.onosproject.ui.topo.DeviceHighlight; |
| 36 | import org.onosproject.ui.topo.Highlights; |
Mahesh Raju-Huawei | d8eaf97 | 2016-06-16 19:08:24 +0530 | [diff] [blame] | 37 | import org.onosproject.ui.topo.LinkHighlight; |
| 38 | import org.onosproject.ui.topo.Mod; |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 39 | import org.onosproject.ui.topo.NodeBadge; |
| 40 | import org.onosproject.ui.topo.TopoJson; |
Mahesh Raju-Huawei | d8eaf97 | 2016-06-16 19:08:24 +0530 | [diff] [blame] | 41 | import org.onosproject.ui.topo.TopoUtils; |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 42 | import org.onosproject.net.device.DeviceService; |
| 43 | import org.onosproject.net.intent.Constraint; |
| 44 | import org.onosproject.pce.pceservice.LspType; |
| 45 | import org.onosproject.pce.pceservice.api.PceService; |
| 46 | import org.onosproject.pce.pceservice.constraint.CostConstraint; |
| 47 | import org.onosproject.net.intent.constraint.BandwidthConstraint; |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 48 | import org.slf4j.Logger; |
| 49 | import org.slf4j.LoggerFactory; |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 50 | import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; |
| 51 | import org.onosproject.incubator.net.tunnel.Tunnel; |
MaheshRaju-Huawei | 4bf9f2d | 2016-07-01 19:03:18 +0530 | [diff] [blame] | 52 | import static org.onosproject.incubator.net.tunnel.Tunnel.State.ACTIVE; |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 53 | import org.onosproject.incubator.net.tunnel.TunnelEndPoint; |
| 54 | import org.onosproject.incubator.net.tunnel.TunnelEvent; |
| 55 | import org.onosproject.incubator.net.tunnel.TunnelId; |
| 56 | import org.onosproject.incubator.net.tunnel.TunnelListener; |
| 57 | import org.onosproject.incubator.net.tunnel.TunnelService; |
Mahesh Raju-Huawei | d8eaf97 | 2016-06-16 19:08:24 +0530 | [diff] [blame] | 58 | import static org.onosproject.ui.topo.LinkHighlight.Flavor.*; |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 59 | import static org.onosproject.incubator.net.tunnel.Tunnel.Type.MPLS; |
| 60 | |
| 61 | import com.fasterxml.jackson.databind.node.ArrayNode; |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 62 | |
| 63 | import java.util.Collection; |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 64 | import java.util.LinkedList; |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 65 | import java.util.List; |
| 66 | import java.util.Set; |
| 67 | |
| 68 | /** |
| 69 | * ONOS UI PCE WEB Topology-Overlay message handler. |
| 70 | */ |
| 71 | public class PceWebTopovMessageHandler extends UiMessageHandler { |
| 72 | |
| 73 | private static final String PCEWEB_CLEAR = "pceTopovClear"; |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 74 | private static final String PCEWEB_SET_PATH = "pceTopovSetMode"; |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 75 | 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-Huawei | d8eaf97 | 2016-06-16 19:08:24 +0530 | [diff] [blame] | 82 | private static final String PCEWEB_TUNNEL_UPDATE_INFO = "updatePathmsgInfo"; |
| 83 | private static final String PCEWEB_TUNNEL_UPDATE_INFO_REPLY = "pceTopovShowTunnelsUpdate"; |
MaheshRaju-Huawei | 4bf9f2d | 2016-07-01 19:03:18 +0530 | [diff] [blame] | 84 | private static final String PCEWEB_TUNNEL_QUERY_INFO = "pceTopovShowTunnelsQuery"; |
| 85 | private static final String PCEWEB_TUNNEL_QUERY_INFO_SHOW = "pceTopovshowTunnelHighlightMsg"; |
Mahesh Raju-Huawei | d8eaf97 | 2016-06-16 19:08:24 +0530 | [diff] [blame] | 86 | private static final String DST = "DST"; |
| 87 | private static final String SRC = "SRC"; |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 88 | 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-Huawei | fc9f8bc | 2016-07-14 12:33:22 +0530 | [diff] [blame] | 99 | private static final String BANDWIDTH_TYPE_MBPS = "mbps"; |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 100 | 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-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 106 | // Delay for showHighlights event processing on GUI client side to |
| 107 | // account for addLink animation. |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 108 | 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-Huawei | d8eaf97 | 2016-06-16 19:08:24 +0530 | [diff] [blame] | 111 | 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-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 115 | private Set<Link> allPathLinks; |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 116 | private ElementId src, dst; |
Mahesh Raju-Huawei | 0f977ef | 2016-06-14 17:26:22 +0530 | [diff] [blame] | 117 | private List<Path> paths = new LinkedList<>(); |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 118 | private int pathIndex; |
| 119 | |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 120 | private final Logger log = LoggerFactory.getLogger(getClass()); |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 121 | private final TunnelListener tunnelListener = new InnerPceWebTunnelListener(); |
| 122 | |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 123 | protected TopologyService topologyService; |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 124 | protected TunnelService tunnelService; |
| 125 | protected PceService pceService; |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 126 | protected DeviceService deviceService; |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 127 | @Override |
| 128 | public void init(UiConnection connection, ServiceDirectory directory) { |
| 129 | |
| 130 | super.init(connection, directory); |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 131 | tunnelService = directory.get(TunnelService.class); |
| 132 | pceService = directory.get(PceService.class); |
| 133 | deviceService = directory.get(DeviceService.class); |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 134 | tunnelService.addListener(tunnelListener); |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | @Override |
| 138 | protected Collection<RequestHandler> createRequestHandlers() { |
| 139 | return ImmutableSet.of( |
| 140 | new ClearHandler(), |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 141 | new SetPathHandler(), |
| 142 | new UpdatePathQueryHandler(), |
| 143 | new UpdatePathHandler(), |
| 144 | new RemovePathQueryHandler(), |
| 145 | new RemovePathHandler(), |
Mahesh Raju-Huawei | d8eaf97 | 2016-06-16 19:08:24 +0530 | [diff] [blame] | 146 | new UpdatePathInfoHandler(), |
MaheshRaju-Huawei | 4bf9f2d | 2016-07-01 19:03:18 +0530 | [diff] [blame] | 147 | new ShowTunnelHandler(), |
| 148 | new ShowTunnelHighlight()); |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | @Override |
| 152 | public void destroy() { |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 153 | tunnelService.removeListener(tunnelListener); |
| 154 | super.destroy(); |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 155 | } |
| 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-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 176 | * Handles the 'path calculation' event received from the client. |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 177 | */ |
| 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-Huawei | 0f977ef | 2016-06-14 17:26:22 +0530 | [diff] [blame] | 186 | 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-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 194 | 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-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 199 | |
Priyanka B | f97e13d | 2016-07-28 10:57:15 +0530 | [diff] [blame] | 200 | if (tunnelName == null || tunnelName.equals(STRING_NULL)) { |
| 201 | log.error("tunnel name should not be empty"); |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 202 | return; |
| 203 | } |
Priyanka B | f97e13d | 2016-07-28 10:57:15 +0530 | [diff] [blame] | 204 | //Validating tunnel name, duplicated tunnel names not allowed |
| 205 | Collection<Tunnel> existingTunnels = tunnelService.queryTunnel(Tunnel.Type.MPLS); |
| 206 | if (existingTunnels != null) { |
| 207 | for (Tunnel t : existingTunnels) { |
| 208 | if (t.tunnelName().toString().equals(tunnelName)) { |
| 209 | log.error("Path creation failed, Tunnel name already exists"); |
| 210 | return; |
| 211 | } |
| 212 | } |
| 213 | } |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 214 | |
| 215 | if (pceService == null) { |
| 216 | log.error("PCE service is not active"); |
| 217 | return; |
| 218 | } |
| 219 | |
MaheshRaju-Huawei | aec67f8 | 2016-07-18 16:39:25 +0530 | [diff] [blame] | 220 | if (lspType == null || lspType.equals(STRING_NULL)) { |
| 221 | log.error("PCE setup path is failed as LSP type is mandatory"); |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | if ((src != null) && (dst != null)) { |
| 225 | findAndSendPaths(src, dst, bandWidth, bandWidthType, costType, lspType, tunnelName); |
| 226 | } |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 230 | /** |
| 231 | * Handles the 'update path query' event received from the client. |
| 232 | */ |
| 233 | private final class UpdatePathQueryHandler extends RequestHandler { |
| 234 | |
| 235 | public UpdatePathQueryHandler() { |
| 236 | super(PCEWEB_UPDATE_PATH_QUERY); |
| 237 | } |
| 238 | |
| 239 | @Override |
| 240 | public void process(long sid, ObjectNode payload) { |
| 241 | String srcId = string(payload, SRCID); |
| 242 | ElementId src = elementId(srcId); |
| 243 | String dstId = string(payload, DSTID); |
| 244 | ElementId dst = elementId(dstId); |
| 245 | Device srcDevice = deviceService.getDevice((DeviceId) src); |
| 246 | Device dstDevice = deviceService.getDevice((DeviceId) dst); |
| 247 | |
| 248 | TunnelEndPoint tunSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress |
| 249 | .valueOf(srcDevice.annotations().value("lsrId"))); |
| 250 | TunnelEndPoint tunDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress |
| 251 | .valueOf(dstDevice.annotations().value("lsrId"))); |
| 252 | |
| 253 | Collection<Tunnel> tunnelSet = tunnelService.queryTunnel(tunSrc, tunDst); |
Mahesh Raju-Huawei | 2cfa535 | 2016-05-27 20:09:51 +0530 | [diff] [blame] | 254 | ObjectNode result = objectNode(); |
| 255 | ArrayNode arrayNode = arrayNode(); |
| 256 | for (Tunnel tunnel : tunnelSet) { |
| 257 | if (tunnel.type() == MPLS) { |
MaheshRaju-Huawei | 4bf9f2d | 2016-07-01 19:03:18 +0530 | [diff] [blame] | 258 | if (tunnel.state().equals(ACTIVE)) { |
| 259 | arrayNode.add(tunnel.tunnelId().toString()); |
| 260 | arrayNode.add(tunnel.tunnelName().toString()); |
| 261 | } |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 262 | } |
Mahesh Raju-Huawei | 2cfa535 | 2016-05-27 20:09:51 +0530 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | result.putArray(BUFFER_ARRAY).addAll(arrayNode); |
| 266 | sendMessage(PCEWEB_SHOW_TUNNEL, sid, result); |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * Handles the 'update path' event received from the client. |
| 272 | */ |
| 273 | private final class UpdatePathHandler extends RequestHandler { |
| 274 | |
| 275 | public UpdatePathHandler() { |
| 276 | super(PCEWEB_UPDATE_PATH); |
| 277 | } |
| 278 | |
| 279 | @Override |
| 280 | public void process(long sid, ObjectNode payload) { |
| 281 | String bandWidth = string(payload, BANDWIDTH); |
| 282 | String bandWidthType = string(payload, BANDWIDTHTYPE); |
| 283 | String costType = string(payload, COSTTYPE); |
| 284 | String tunnelId = string(payload, TUNNEL_ID); |
| 285 | |
| 286 | if (tunnelId == null) { |
| 287 | log.error("PCE update path is failed."); |
| 288 | } |
| 289 | |
| 290 | findAndSendPathsUpdate(bandWidth, bandWidthType, costType, tunnelId); |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | /** |
Mahesh Raju-Huawei | d8eaf97 | 2016-06-16 19:08:24 +0530 | [diff] [blame] | 295 | * Handles the 'update path' event received from the client. |
| 296 | */ |
| 297 | private final class UpdatePathInfoHandler extends RequestHandler { |
| 298 | |
| 299 | public UpdatePathInfoHandler() { |
| 300 | super(PCEWEB_TUNNEL_UPDATE_INFO); |
| 301 | } |
| 302 | |
| 303 | @Override |
| 304 | public void process(long sid, ObjectNode payload) { |
| 305 | String tunnelIdStr = string(payload, TUNNEL_ID); |
| 306 | |
| 307 | if (tunnelIdStr == null) { |
| 308 | log.error("PCE update path is failed."); |
MaheshRaju-Huawei | 4bf9f2d | 2016-07-01 19:03:18 +0530 | [diff] [blame] | 309 | return; |
Mahesh Raju-Huawei | d8eaf97 | 2016-06-16 19:08:24 +0530 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | if (tunnelIdStr.equals(STRING_NULL)) { |
| 313 | log.error("PCE update path is failed."); |
| 314 | return; |
| 315 | } |
| 316 | |
| 317 | if (pceService == null) { |
| 318 | log.error("PCE service is not active"); |
| 319 | return; |
| 320 | } |
| 321 | |
| 322 | TunnelId tunnelId = TunnelId.valueOf(tunnelIdStr); |
| 323 | Tunnel tunnel = tunnelService.queryTunnel(tunnelId); |
| 324 | ObjectNode result = objectNode(); |
| 325 | ArrayNode arrayNode = arrayNode(); |
| 326 | |
| 327 | arrayNode.add("Tunnel"); |
| 328 | arrayNode.add(tunnelIdStr); |
| 329 | arrayNode.add("BandWidth"); |
| 330 | arrayNode.add(tunnel.annotations().value("bandwidth")); |
| 331 | arrayNode.add("CostType"); |
| 332 | arrayNode.add(tunnel.annotations().value("costType")); |
| 333 | |
| 334 | result.putArray(BUFFER_ARRAY).addAll(arrayNode); |
| 335 | sendMessage(PCEWEB_TUNNEL_UPDATE_INFO_REPLY, sid, result); |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | /** |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 340 | * Handles the 'remove path query' event received from the client. |
| 341 | */ |
| 342 | private final class RemovePathQueryHandler extends RequestHandler { |
| 343 | |
| 344 | public RemovePathQueryHandler() { |
| 345 | super(PCEWEB_REMOVE_PATH_QUERY); |
| 346 | } |
| 347 | |
| 348 | @Override |
| 349 | public void process(long sid, ObjectNode payload) { |
| 350 | String srcId = string(payload, SRCID); |
| 351 | ElementId src = elementId(srcId); |
| 352 | String dstId = string(payload, DSTID); |
| 353 | ElementId dst = elementId(dstId); |
| 354 | |
| 355 | Device srcDevice = deviceService.getDevice((DeviceId) src); |
| 356 | Device dstDevice = deviceService.getDevice((DeviceId) dst); |
| 357 | |
| 358 | TunnelEndPoint tunSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress |
| 359 | .valueOf(srcDevice.annotations().value("lsrId"))); |
| 360 | TunnelEndPoint tunDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress |
| 361 | .valueOf(dstDevice.annotations().value("lsrId"))); |
| 362 | |
| 363 | Collection<Tunnel> tunnelSet = tunnelService.queryTunnel(tunSrc, tunDst); |
Mahesh Raju-Huawei | 2cfa535 | 2016-05-27 20:09:51 +0530 | [diff] [blame] | 364 | ObjectNode result = objectNode(); |
| 365 | ArrayNode arrayNode = arrayNode(); |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 366 | |
Mahesh Raju-Huawei | 2cfa535 | 2016-05-27 20:09:51 +0530 | [diff] [blame] | 367 | for (Tunnel tunnel : tunnelSet) { |
| 368 | if (tunnel.type() == MPLS) { |
MaheshRaju-Huawei | 4bf9f2d | 2016-07-01 19:03:18 +0530 | [diff] [blame] | 369 | if (tunnel.state().equals(ACTIVE)) { |
| 370 | arrayNode.add(tunnel.tunnelId().toString()); |
| 371 | arrayNode.add(tunnel.tunnelName().toString()); |
| 372 | } |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 373 | } |
Mahesh Raju-Huawei | 2cfa535 | 2016-05-27 20:09:51 +0530 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | result.putArray(BUFFER_ARRAY).addAll(arrayNode); |
| 377 | sendMessage(PCEWEB_SHOW_TUNNEL_REMOVE, sid, result); |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 378 | } |
| 379 | } |
| 380 | |
| 381 | /** |
| 382 | * Handles the 'remove path' event received from the client. |
| 383 | */ |
| 384 | private final class RemovePathHandler extends RequestHandler { |
| 385 | |
| 386 | public RemovePathHandler() { |
| 387 | super(PCEWEB_REMOVE_PATH); |
| 388 | } |
| 389 | |
| 390 | @Override |
| 391 | public void process(long sid, ObjectNode payload) { |
| 392 | String tunnelId = string(payload, TUNNEL_ID); |
| 393 | |
| 394 | if (tunnelId == null) { |
| 395 | log.error("PCE update path is failed."); |
| 396 | } |
| 397 | |
| 398 | findAndSendPathsRemove(tunnelId); |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | /** |
| 403 | * Handles the 'show the existed tunnels' event received from the client. |
| 404 | */ |
| 405 | private final class ShowTunnelHandler extends RequestHandler { |
| 406 | |
| 407 | public ShowTunnelHandler() { |
| 408 | super(PCEWEB_QUERY_TUNNELS); |
| 409 | } |
| 410 | |
| 411 | @Override |
| 412 | public void process(long sid, ObjectNode payload) { |
MaheshRaju-Huawei | 4bf9f2d | 2016-07-01 19:03:18 +0530 | [diff] [blame] | 413 | ObjectNode result = objectNode(); |
| 414 | ArrayNode arrayNode = arrayNode(); |
| 415 | Collection<Tunnel> tunnelSet = null; |
| 416 | |
| 417 | tunnelSet = tunnelService.queryTunnel(MPLS); |
| 418 | for (Tunnel tunnel : tunnelSet) { |
| 419 | if (tunnel.state().equals(ACTIVE)) { |
| 420 | arrayNode.add(tunnel.tunnelId().toString()); |
| 421 | arrayNode.add(tunnel.tunnelName().toString()); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | result.putArray(BUFFER_ARRAY).addAll(arrayNode); |
| 426 | sendMessage(PCEWEB_TUNNEL_QUERY_INFO, sid, result); |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | /** |
| 431 | * Handles the 'show the existed tunnels' event received from the client. |
| 432 | */ |
| 433 | private final class ShowTunnelHighlight extends RequestHandler { |
| 434 | |
| 435 | public ShowTunnelHighlight() { |
| 436 | super(PCEWEB_TUNNEL_QUERY_INFO_SHOW); |
| 437 | } |
| 438 | |
| 439 | @Override |
| 440 | public void process(long sid, ObjectNode payload) { |
| 441 | String tunnelIdStr = string(payload, TUNNEL_ID); |
| 442 | |
| 443 | if (tunnelIdStr == null) { |
| 444 | log.error("Tunnel Id is NULL."); |
| 445 | return; |
| 446 | } |
| 447 | |
| 448 | if (tunnelIdStr.equals(STRING_NULL)) { |
| 449 | log.error("Tunnel Id is NULL."); |
| 450 | return; |
| 451 | } |
| 452 | |
| 453 | if (pceService == null) { |
| 454 | log.error("PCE service is not active"); |
| 455 | return; |
| 456 | } |
| 457 | |
| 458 | TunnelId tunnelId = TunnelId.valueOf(tunnelIdStr); |
| 459 | Tunnel tunnel = tunnelService.queryTunnel(tunnelId); |
| 460 | if (tunnel != null) { |
| 461 | highlightsForTunnel(tunnel); |
| 462 | } |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 463 | } |
| 464 | } |
| 465 | |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 466 | /** |
| 467 | * provides the element id. |
| 468 | */ |
| 469 | private ElementId elementId(String id) { |
| 470 | try { |
| 471 | return DeviceId.deviceId(id); |
| 472 | } catch (IllegalArgumentException e) { |
| 473 | return HostId.hostId(id); |
| 474 | } |
| 475 | } |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 476 | |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 477 | /** |
| 478 | * Handles the setup path and highlights the path. |
| 479 | * |
| 480 | * @param bandWidth |
| 481 | * @param bandWidthType is the kbps or mbps |
| 482 | * @param costType is igp or te |
| 483 | * @param lspType is WITH_SIGNALLING,WITHOUT_SIGNALLING_AND_WITHOUT_SR or SR_WITHOUT_SIGNALLING |
| 484 | * @param tunnelName tunnel id |
| 485 | */ |
| 486 | private void findAndSendPaths(ElementId src, ElementId dst, String bandWidth, String bandWidthType, |
| 487 | String costType, String lspType, String tunnelName) { |
| 488 | log.debug("src={}; dst={};", src, dst); |
| 489 | boolean path; |
| 490 | List<Constraint> listConstrnt; |
| 491 | |
| 492 | listConstrnt = addBandwidthCostTypeConstraints(bandWidth, bandWidthType, costType); |
| 493 | |
| 494 | //LSP type |
| 495 | LspType lspTypeVal = null; |
| 496 | switch (lspType) { |
| 497 | case LSP_TYPE_CR: |
| 498 | lspTypeVal = LspType.WITH_SIGNALLING; |
| 499 | break; |
| 500 | case LSP_TYPE_SRBE: |
| 501 | lspTypeVal = LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR; |
| 502 | break; |
| 503 | case LSP_TYPE_SRTE: |
| 504 | lspTypeVal = LspType.SR_WITHOUT_SIGNALLING; |
| 505 | break; |
| 506 | default: |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 507 | break; |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 508 | } |
| 509 | |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame] | 510 | //TODO: need to get explicit paths [temporarily using null as the value] |
| 511 | path = pceService.setupPath((DeviceId) src, (DeviceId) dst, tunnelName, listConstrnt, lspTypeVal, |
| 512 | null); |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 513 | if (!path) { |
| 514 | log.error("setup path is failed"); |
| 515 | return; |
| 516 | } |
| 517 | |
| 518 | return; |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 519 | } |
| 520 | |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 521 | /** |
| 522 | * Handles the update path and highlights the path. |
| 523 | * |
| 524 | * @param bandWidth bandWidth |
| 525 | * @param bandWidthType is the kbps or mbps |
| 526 | * @param costType is igp or te |
MaheshRaju-Huawei | 4bf9f2d | 2016-07-01 19:03:18 +0530 | [diff] [blame] | 527 | * @param tunnelIdStr tunnel id |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 528 | */ |
| 529 | private void findAndSendPathsUpdate(String bandWidth, String bandWidthType, String costType, String tunnelIdStr) { |
| 530 | if (tunnelIdStr != null) { |
| 531 | List<Constraint> listConstrnt; |
| 532 | |
| 533 | if (tunnelIdStr.equals(STRING_NULL)) { |
| 534 | log.error("update path is failed"); |
| 535 | return; |
| 536 | } |
| 537 | |
| 538 | if (pceService == null) { |
| 539 | log.error("PCE service is not active"); |
| 540 | return; |
| 541 | } |
| 542 | |
| 543 | listConstrnt = addBandwidthCostTypeConstraints(bandWidth, bandWidthType, costType); |
| 544 | TunnelId tunnelId = TunnelId.valueOf(tunnelIdStr); |
| 545 | boolean path = pceService.updatePath(tunnelId, listConstrnt); |
| 546 | |
| 547 | if (!path) { |
| 548 | log.error("update path is failed"); |
| 549 | return; |
| 550 | } |
| 551 | } |
| 552 | return; |
| 553 | } |
| 554 | |
| 555 | /** |
| 556 | * Handles the remove path and highlights the paths if existed. |
| 557 | * |
MaheshRaju-Huawei | 4bf9f2d | 2016-07-01 19:03:18 +0530 | [diff] [blame] | 558 | * @param tunnelIdStr tunnelId |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 559 | */ |
| 560 | private void findAndSendPathsRemove(String tunnelIdStr) { |
| 561 | if (tunnelIdStr != null) { |
| 562 | if (pceService == null) { |
| 563 | log.error("PCE service is not active"); |
| 564 | return; |
| 565 | } |
| 566 | |
| 567 | TunnelId tunnelId = TunnelId.valueOf(tunnelIdStr); |
| 568 | boolean path = pceService.releasePath(tunnelId); |
| 569 | if (!path) { |
| 570 | log.error("remove path is failed"); |
| 571 | return; |
| 572 | } |
| 573 | } |
| 574 | return; |
| 575 | } |
| 576 | |
| 577 | private ImmutableSet.Builder<Link> buildPaths(ImmutableSet.Builder<Link> pathBuilder) { |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 578 | paths.forEach(path -> path.links().forEach(pathBuilder::add)); |
| 579 | return pathBuilder; |
| 580 | } |
| 581 | |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 582 | /** |
| 583 | * Handles the preparation of constraints list with given bandwidth and cost-type. |
| 584 | * |
| 585 | * @param bandWidth bandWidth |
| 586 | * @param bandWidthType is the kbps or mbps |
| 587 | * @param costType is igp or te |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 588 | * @return |
| 589 | */ |
| 590 | private List<Constraint> addBandwidthCostTypeConstraints(String bandWidth, |
| 591 | String bandWidthType, |
| 592 | String costType) { |
| 593 | List<Constraint> listConstrnt = new LinkedList<>(); |
| 594 | //bandwidth |
| 595 | double bwValue = 0.0; |
| 596 | if (!bandWidth.equals(STRING_NULL)) { |
| 597 | bwValue = Double.parseDouble(bandWidth); |
| 598 | } |
| 599 | if (bandWidthType.equals(BANDWIDTH_TYPE_KBPS)) { |
| 600 | bwValue = bwValue * BANDWIDTH_KBPS; |
Mahesh Raju-Huawei | d8eaf97 | 2016-06-16 19:08:24 +0530 | [diff] [blame] | 601 | } else if (bandWidthType.equals(BANDWIDTH_TYPE_MBPS)) { |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 602 | bwValue = bwValue * BANDWIDTH_MBPS; |
| 603 | } |
| 604 | |
| 605 | //Cost type |
| 606 | CostConstraint.Type costTypeVal = null; |
| 607 | switch (costType) { |
| 608 | case COST_TYPE_IGP: |
| 609 | costTypeVal = CostConstraint.Type.COST; |
| 610 | break; |
| 611 | case COST_TYPE_TE: |
| 612 | costTypeVal = CostConstraint.Type.TE_COST; |
| 613 | break; |
| 614 | default: |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 615 | break; |
| 616 | } |
| 617 | |
| 618 | if (bwValue != 0.0) { |
| 619 | listConstrnt.add(BandwidthConstraint.of(bwValue, DataRateUnit.valueOf(BANDWIDTH_BPS))); |
| 620 | } |
| 621 | |
| 622 | if (costTypeVal != null) { |
| 623 | listConstrnt.add(CostConstraint.of(costTypeVal)); |
| 624 | } |
| 625 | |
| 626 | return listConstrnt; |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 627 | } |
| 628 | |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 629 | /** |
| 630 | * Handles the highlights of selected path. |
| 631 | */ |
Mahesh Raju-Huawei | 0f977ef | 2016-06-14 17:26:22 +0530 | [diff] [blame] | 632 | private void hilightAndSendPaths(Highlights highlights) { |
Mahesh Raju-Huawei | d8eaf97 | 2016-06-16 19:08:24 +0530 | [diff] [blame] | 633 | LinkHighlight lh; |
| 634 | int linkclr = 0; |
| 635 | for (Path path : paths) { |
| 636 | for (Link link : path.links()) { |
| 637 | lh = new LinkHighlight(TopoUtils.compactLinkString(link), PRIMARY_HIGHLIGHT) |
| 638 | .addMod(new Mod(linkColor[linkclr])); |
| 639 | highlights.add(lh); |
| 640 | } |
| 641 | linkclr = linkclr + 1; |
| 642 | if (linkclr == LINK_COLOR_MAX) { |
| 643 | linkclr = 0; |
| 644 | } |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 645 | } |
Mahesh Raju-Huawei | d8eaf97 | 2016-06-16 19:08:24 +0530 | [diff] [blame] | 646 | |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 647 | sendMessage(TopoJson.highlightsMessage(highlights)); |
| 648 | } |
| 649 | |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 650 | /** |
| 651 | * Handles the addition of badge and highlights. |
| 652 | * |
| 653 | * @param highlights highlights |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 654 | * @param elemId device to be add badge |
| 655 | * @param src device to be add badge |
| 656 | * @return |
| 657 | */ |
Mahesh Raju-Huawei | 0f977ef | 2016-06-14 17:26:22 +0530 | [diff] [blame] | 658 | private Highlights addBadge(Highlights highlights, |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 659 | String elemId, String src) { |
Mahesh Raju-Huawei | 0f977ef | 2016-06-14 17:26:22 +0530 | [diff] [blame] | 660 | highlights = addDeviceBadge(highlights, elemId, src); |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 661 | return highlights; |
| 662 | } |
| 663 | |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 664 | /** |
| 665 | * Handles the badge add and highlights. |
| 666 | * |
| 667 | * @param h highlights |
| 668 | * @param elemId device to be add badge |
Mahesh Raju-Huawei | 0f977ef | 2016-06-14 17:26:22 +0530 | [diff] [blame] | 669 | * @param type device badge value |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 670 | * @return highlights |
| 671 | */ |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 672 | private Highlights addDeviceBadge(Highlights h, String elemId, String type) { |
| 673 | DeviceHighlight dh = new DeviceHighlight(elemId); |
| 674 | dh.setBadge(createBadge(type)); |
| 675 | h.add(dh); |
| 676 | return h; |
| 677 | } |
| 678 | |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 679 | /** |
| 680 | * Handles the node badge add and highlights. |
| 681 | * |
Mahesh Raju-Huawei | 0f977ef | 2016-06-14 17:26:22 +0530 | [diff] [blame] | 682 | * @param type device badge value |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 683 | * @return badge of given node |
| 684 | */ |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 685 | private NodeBadge createBadge(String type) { |
| 686 | return NodeBadge.text(type); |
| 687 | } |
| 688 | |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 689 | /** |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 690 | * Handles the event of tunnel listeners. |
| 691 | */ |
| 692 | private class InnerPceWebTunnelListener implements TunnelListener { |
| 693 | @Override |
| 694 | public void event(TunnelEvent event) { |
| 695 | Tunnel tunnel = event.subject(); |
| 696 | if (tunnel.type() == MPLS) { |
MaheshRaju-Huawei | 4bf9f2d | 2016-07-01 19:03:18 +0530 | [diff] [blame] | 697 | highlightsForTunnel(tunnel); |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 698 | } |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | /** |
| 703 | * Handles the event of topology listeners. |
| 704 | */ |
| 705 | private void findTunnelAndHighlights() { |
| 706 | Collection<Tunnel> tunnelSet = null; |
Mahesh Raju-Huawei | d8eaf97 | 2016-06-16 19:08:24 +0530 | [diff] [blame] | 707 | Highlights highlights = new Highlights(); |
| 708 | paths.removeAll(paths); |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 709 | tunnelSet = tunnelService.queryTunnel(MPLS); |
Mahesh Raju-Huawei | 31d31c0 | 2016-06-04 17:20:57 +0530 | [diff] [blame] | 710 | if (tunnelSet.size() == 0) { |
| 711 | log.warn("Tunnel does not exist"); |
Mahesh Raju-Huawei | d8eaf97 | 2016-06-16 19:08:24 +0530 | [diff] [blame] | 712 | sendMessage(TopoJson.highlightsMessage(highlights)); |
Mahesh Raju-Huawei | 31d31c0 | 2016-06-04 17:20:57 +0530 | [diff] [blame] | 713 | return; |
| 714 | } |
| 715 | |
Mahesh Raju-Huawei | 0f977ef | 2016-06-14 17:26:22 +0530 | [diff] [blame] | 716 | for (Tunnel tunnel : tunnelSet) { |
| 717 | if (tunnel.path() == null) { |
| 718 | log.error("path does not exist"); |
Mahesh Raju-Huawei | d8eaf97 | 2016-06-16 19:08:24 +0530 | [diff] [blame] | 719 | sendMessage(TopoJson.highlightsMessage(highlights)); |
Mahesh Raju-Huawei | 0f977ef | 2016-06-14 17:26:22 +0530 | [diff] [blame] | 720 | return; |
| 721 | } |
MaheshRaju-Huawei | 4bf9f2d | 2016-07-01 19:03:18 +0530 | [diff] [blame] | 722 | if (!tunnel.state().equals(ACTIVE)) { |
| 723 | log.debug("Tunnel state is not active"); |
| 724 | sendMessage(TopoJson.highlightsMessage(highlights)); |
| 725 | return; |
| 726 | } |
Mahesh Raju-Huawei | 0f977ef | 2016-06-14 17:26:22 +0530 | [diff] [blame] | 727 | Link firstLink = tunnel.path().links().get(0); |
| 728 | if (firstLink != null) { |
| 729 | if (firstLink.src() != null) { |
| 730 | highlights = addBadge(highlights, firstLink.src().deviceId().toString(), SRC); |
| 731 | } |
| 732 | } |
| 733 | Link lastLink = tunnel.path().links().get(tunnel.path().links().size() - 1); |
| 734 | if (lastLink != null) { |
| 735 | if (lastLink.dst() != null) { |
| 736 | highlights = addBadge(highlights, lastLink.dst().deviceId().toString(), DST); |
| 737 | } |
| 738 | } |
| 739 | paths.add(tunnel.path()); |
| 740 | } |
| 741 | |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 742 | ImmutableSet.Builder<Link> builder = ImmutableSet.builder(); |
| 743 | allPathLinks = buildPaths(builder).build(); |
Mahesh Raju-Huawei | 0f977ef | 2016-06-14 17:26:22 +0530 | [diff] [blame] | 744 | hilightAndSendPaths(highlights); |
Mahesh Raju-Huawei | 5b0453a | 2016-05-27 11:54:27 +0530 | [diff] [blame] | 745 | } |
MaheshRaju-Huawei | 4bf9f2d | 2016-07-01 19:03:18 +0530 | [diff] [blame] | 746 | |
| 747 | /** |
| 748 | * Handles the event of topology listeners. |
| 749 | */ |
| 750 | private void highlightsForTunnel(Tunnel tunnel) { |
| 751 | Highlights highlights = new Highlights(); |
| 752 | paths.removeAll(paths); |
| 753 | if (tunnel.path() == null) { |
| 754 | log.error("path does not exist"); |
| 755 | sendMessage(TopoJson.highlightsMessage(highlights)); |
| 756 | return; |
| 757 | } |
| 758 | if (!tunnel.state().equals(ACTIVE)) { |
| 759 | log.debug("Tunnel state is not active"); |
| 760 | sendMessage(TopoJson.highlightsMessage(highlights)); |
| 761 | return; |
| 762 | } |
| 763 | |
| 764 | Link firstLink = tunnel.path().links().get(0); |
| 765 | if (firstLink != null) { |
| 766 | if (firstLink.src() != null) { |
| 767 | highlights = addBadge(highlights, firstLink.src().deviceId().toString(), SRC); |
| 768 | } |
| 769 | } |
| 770 | Link lastLink = tunnel.path().links().get(tunnel.path().links().size() - 1); |
| 771 | if (lastLink != null) { |
| 772 | if (lastLink.dst() != null) { |
| 773 | highlights = addBadge(highlights, lastLink.dst().deviceId().toString(), DST); |
| 774 | } |
| 775 | } |
| 776 | paths.add(tunnel.path()); |
| 777 | |
| 778 | ImmutableSet.Builder<Link> builder = ImmutableSet.builder(); |
| 779 | allPathLinks = buildPaths(builder).build(); |
| 780 | hilightAndSendPaths(highlights); |
| 781 | } |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 782 | } |