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