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